Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Echo Zhang <echo.zhang@mediatek.com>
To: Echo Zhang <echo.zhang@mediatek.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney+clk@redhat.com>,
	Jerome Brunet <jbrunet+clk@baylibre.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	MMDVFS Team <linux-mediatek@lists.infradead.org>,
	<kyrie.wu@mediatek.com>, <ming-fan.chen@mediatek.com>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-clk@vger.kernel.org>, <llvm@lists.linux.dev>
Subject: [PATCH 6/7] soc: mediatek: mmdvfs: add read-only status debug
Date: Wed, 25 Nov 2026 14:00:11 +0800	[thread overview]
Message-ID: <20261125060037.649659-7-echo.zhang@mediatek.com> (raw)
In-Reply-To: <20261125060037.649659-1-echo.zhang@mediatek.com>

Expose MMDVFS topology and software power references through a read-only
debugfs status file. Use seq_file so large topologies are not limited by
a PAGE_SIZE module parameter buffer. Firmware shared memory and SRAM
contents remain outside this diagnostic path.

Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
---
 drivers/soc/mediatek/mmdvfs/Makefile       |   1 +
 drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c | 200 +++++++++++++++++++++
 2 files changed, 201 insertions(+)
 create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c

diff --git a/drivers/soc/mediatek/mmdvfs/Makefile b/drivers/soc/mediatek/mmdvfs/Makefile
index d02ebd63e6ae..3d780b29efe7 100644
--- a/drivers/soc/mediatek/mmdvfs/Makefile
+++ b/drivers/soc/mediatek/mmdvfs/Makefile
@@ -7,3 +7,4 @@ mtk-mmdvfs-y += mmdvfs-clk.o
 mtk-mmdvfs-y += mmdvfs-up.o
 mtk-mmdvfs-y += mmdvfs-vcp.o
 mtk-mmdvfs-$(CONFIG_MTK_MMDVFS_MT8196) += mmdvfs-mt8196.o
+mtk-mmdvfs-$(CONFIG_DEBUG_FS) += mmdvfs-debug.o
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c
new file mode 100644
index 000000000000..7d7324ff6577
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c
@@ -0,0 +1,200 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2026 MediaTek Inc. */
+
+#include <linux/debugfs.h>
+#include <linux/module.h>
+#include <linux/seq_file.h>
+
+#include "mmdvfs-internal.h"
+
+static const char *mmdvfs_status_rc_name(u8 id)
+{
+	switch (id) {
+	case MMDVFS_PWR_VCORE:
+		return "VCORE";
+	case MMDVFS_PWR_VMM:
+		return "VMM";
+	case MMDVFS_PWR_VDISP:
+		return "VDISP";
+	default:
+		return "UNKNOWN";
+	}
+}
+
+static const char *mmdvfs_status_power_user_name(int id)
+{
+	static const char *const names[VCP_PWR_USR_NUM] = {
+		[VCP_PWR_USR_MMDVFS_INIT] = "INIT",
+		[VCP_PWR_USR_MMDVFS_VOTE] = "VOTE",
+		[VCP_PWR_USR_MMDVFS_CCU] = "CCU",
+		[VCP_PWR_USR_MMDVFS_RST] = "RST",
+		[VCP_PWR_USR_MMQOS] = "MMQOS",
+		[VCP_PWR_USR_CAM] = "CAM",
+		[VCP_PWR_USR_IMG] = "IMG",
+		[VCP_PWR_USR_PDA] = "PDA",
+		[VCP_PWR_USR_SENIF] = "SENIF",
+		[VCP_PWR_USR_VDEC] = "VDEC",
+		[VCP_PWR_USR_VFMT] = "VFMT",
+		[VCP_PWR_USR_SMI] = "SMI",
+		[VCP_PWR_USR_DISP] = "DISP",
+		[VCP_PWR_USR_MDP] = "MDP",
+		[VCP_PWR_USR_MML] = "MML",
+		[VCP_PWR_USR_VENC] = "VENC",
+		[VCP_PWR_USR_JPEGDEC] = "JPEGDEC",
+		[VCP_PWR_USR_JPEGENC] = "JPEGENC",
+	};
+
+	return id >= 0 && (unsigned int)id < ARRAY_SIZE(names) && names[id] ?
+		       names[id] :
+		       "OTHER";
+}
+
+static int mmdvfs_status_show(struct seq_file *s, void *unused)
+{
+	struct mmdvfs_device *mmdvfs = s->private;
+	struct mmdvfs_data *data;
+	int pwr_usage[VCP_PWR_USR_NUM] = {};
+	int vcp_power = 0, active_power_users = 0, active_users = 0;
+	int ret, rc_idx, mux_idx, user_idx, i;
+
+	if (!mmdvfs || !mmdvfs->data) {
+		seq_puts(s, "ERROR: Device not ready\n");
+		return 0;
+	}
+
+	data = mmdvfs->data;
+	seq_puts(s, "=== MMDVFS Status ===\n\n");
+	seq_puts(s, "Version: ");
+	switch (data->version) {
+	case MMDVFS_VERSION_HWCCF_DVFS_VOTER:
+		seq_puts(s, "HWCCF DVFS Voter\n");
+		break;
+	case MMDVFS_VERSION_NONE:
+		seq_puts(s, "No hardware voter\n");
+		break;
+	default:
+		seq_printf(s, "Unknown (%u)\n", data->version);
+		break;
+	}
+	seq_printf(s, "Initialized: %s\n", data->init_done ? "yes" : "no");
+	seq_printf(s, "Total: %u RCs, %u MUXes, %u Users\n", data->rc_num,
+		   data->mux_num, data->user_num);
+
+	seq_puts(s, "\n--- Power Management ---\n");
+	ret = mmdvfs_vcp_get_power_info(mmdvfs, &vcp_power, pwr_usage);
+	if (ret)
+		seq_printf(s, "VCP Power Refcount: unavailable (%d)\n", ret);
+	else
+		seq_printf(s, "VCP Power Refcount: %d\n", vcp_power);
+	if (!ret) {
+		for (i = 0; i < VCP_PWR_USR_NUM; i++)
+			if (pwr_usage[i] > 0)
+				active_power_users++;
+		if (active_power_users) {
+			seq_printf(s, "VCP Power Users (%d active):\n",
+				   active_power_users);
+			for (i = 0; i < VCP_PWR_USR_NUM; i++) {
+				if (pwr_usage[i] > 0)
+					seq_printf(s, "  [%2d] %s: %d\n", i,
+						   mmdvfs_status_power_user_name(i),
+						   pwr_usage[i]);
+			}
+		}
+	}
+
+	seq_puts(s, "\n--- Active Users (level > 0) ---\n");
+	for (user_idx = 0; user_idx < data->user_num; user_idx++) {
+		struct mmdvfs_user *user = &data->user[user_idx];
+		struct mmdvfs_mux *mux;
+
+		if (user->level == 0 || user->level == 0xff ||
+		    user->mux >= data->mux_num)
+			continue;
+		mux = &data->mux[user->mux];
+		if (mux->rc >= data->rc_num)
+			continue;
+		seq_printf(s, "User[%2u] %-20s RC=%s MUX=%s lvl=%u\n", user->id,
+			   user->name ?: "(null)",
+			   mmdvfs_status_rc_name(data->rc[mux->rc].id),
+			   mux->name ?: "(null)", user->level);
+		active_users++;
+	}
+	if (!active_users)
+		seq_puts(s, "(No active users)\n");
+	else
+		seq_printf(s, "Total: %d active users\n", active_users);
+
+	seq_puts(s, "\n--- Resource Controllers ---\n");
+	for (rc_idx = 0; rc_idx < data->rc_num; rc_idx++) {
+		struct mmdvfs_rc *rc = &data->rc[rc_idx];
+		int mux_count = 0;
+		u8 freq_num = 0;
+
+		for (mux_idx = 0; mux_idx < data->mux_num; mux_idx++) {
+			struct mmdvfs_mux *mux = &data->mux[mux_idx];
+
+			if (mux->rc != rc_idx)
+				continue;
+			mux_count++;
+			if (!freq_num)
+				freq_num = mux->freq_num;
+		}
+		seq_printf(s, "RC[%u] %s (freq_num=%u, muxes=%u)\n", rc->id,
+			   mmdvfs_status_rc_name(rc->id), freq_num, mux_count);
+
+		for (mux_idx = 0; mux_idx < data->mux_num; mux_idx++) {
+			struct mmdvfs_mux *mux = &data->mux[mux_idx];
+			int user_count = 0;
+
+			if (mux->rc != rc_idx)
+				continue;
+			for (user_idx = 0; user_idx < data->user_num;
+			     user_idx++)
+				if (data->user[user_idx].mux == mux_idx)
+					user_count++;
+			seq_printf(s, "  +- MUX[%u] %s (users=%u)\n", mux->id,
+				   mux->name ?: "(null)", user_count);
+			for (user_idx = 0; user_idx < data->user_num;
+			     user_idx++) {
+				struct mmdvfs_user *user =
+					&data->user[user_idx];
+
+				if (user->mux != mux_idx)
+					continue;
+				seq_printf(s,
+					   "     |-- User[%2u] %s (level=%u)\n",
+					   user->id, user->name ?: "(null)",
+					   user->level);
+			}
+		}
+		seq_puts(s, "\n");
+	}
+
+	return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(mmdvfs_status);
+
+void mmdvfs_debug_init(struct mmdvfs_device *mmdvfs)
+{
+	struct dentry *dir, *file;
+
+	dir = debugfs_create_dir("mtk_mmdvfs", NULL);
+	if (IS_ERR_OR_NULL(dir))
+		return;
+
+	file = debugfs_create_file("status", 0444, dir, mmdvfs,
+				   &mmdvfs_status_fops);
+	if (IS_ERR_OR_NULL(file)) {
+		debugfs_remove(dir);
+		return;
+	}
+
+	mmdvfs->debugfs_dir = dir;
+}
+
+void mmdvfs_debug_exit(struct mmdvfs_device *mmdvfs)
+{
+	debugfs_remove_recursive(mmdvfs->debugfs_dir);
+	mmdvfs->debugfs_dir = NULL;
+}
-- 
2.45.2


  parent reply	other threads:[~2026-11-25  6:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
2026-11-25  6:00 ` [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs Echo Zhang
2026-11-25  6:00 ` [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding Echo Zhang
2026-11-25  6:00 ` [PATCH 3/7] soc: mediatek: add MMDVFS core driver Echo Zhang
2026-11-25  6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
2026-11-25  6:00 ` [PATCH 5/7] soc: mediatek: mmdvfs: add MT8196 support Echo Zhang
2026-11-25  6:00 ` Echo Zhang [this message]
2026-11-25  6:00 ` [PATCH 7/7] MAINTAINERS: add MediaTek MMDVFS entry Echo Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125060037.649659-7-echo.zhang@mediatek.com \
    --to=echo.zhang@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bmasney+clk@redhat.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jbrunet+clk@baylibre.com \
    --cc=justinstitt@google.com \
    --cc=krzk+dt@kernel.org \
    --cc=kyrie.wu@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=llvm@lists.linux.dev \
    --cc=matthias.bgg@gmail.com \
    --cc=ming-fan.chen@mediatek.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=robh@kernel.org \
    --cc=sboyd@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox