[PATCH v5] mailbox: add list of used channels to debugfs

Wolfram Sang posted 1 patch 1 month, 1 week ago
drivers/mailbox/mailbox.c | 65 +++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
[PATCH v5] mailbox: add list of used channels to debugfs
Posted by Wolfram Sang 1 month, 1 week ago
During development, it is useful to see which mailboxes are currently
obtained. Use a seq-file in debugfs to list the currently registered
controllers and their used channels. Example output from a Renesas R-Car
X5H based system:

 # cat /sys/kernel/debug/mailbox/mailbox_summary

189e0000.system-controller:
   0: c1000000.mailbox_test_send_to_recv
   1: c1000100.mailbox_test_recv_to_send
 128: c1000100.mailbox_test_recv_to_send
 129: c1000000.mailbox_test_send_to_recv
189e1000.system-controller:
   4: scmi_dev.1
   5: scmi_dev.2

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

This patch was created on top of "[PATCH v3] mailbox: don't free the
channel if the startup callback failed". It is no dependency, though.
The patch applies without it with just some line offsets.

Changes since v4:
* improved comment to explain the initcall situation
* rebased to v7.1-rc2

 drivers/mailbox/mailbox.c | 65 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 006ea5a5c320..3716b8ccbe7f 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/cleanup.h>
+#include <linux/debugfs.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/err.h>
@@ -16,6 +17,7 @@
 #include <linux/mutex.h>
 #include <linux/of.h>
 #include <linux/property.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 static LIST_HEAD(mbox_cons);
@@ -636,3 +638,66 @@ int devm_mbox_controller_register(struct device *dev,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(devm_mbox_controller_register);
+
+#ifdef CONFIG_DEBUG_FS
+static void *mbox_seq_start(struct seq_file *s, loff_t *pos)
+{
+	mutex_lock(&con_mutex);
+	return seq_list_start(&mbox_cons, *pos);
+}
+
+static void *mbox_seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	return seq_list_next(v, &mbox_cons, pos);
+}
+
+static void mbox_seq_stop(struct seq_file *s, void *v)
+{
+	mutex_unlock(&con_mutex);
+}
+
+static int mbox_seq_show(struct seq_file *seq, void *v)
+{
+	const struct mbox_controller *mbox = list_entry(v, struct mbox_controller, node);
+
+	seq_printf(seq, "%s:\n", dev_name(mbox->dev));
+
+	for (unsigned int i = 0; i < mbox->num_chans; i++) {
+		struct mbox_chan *chan = &mbox->chans[i];
+
+		scoped_guard(spinlock_irqsave, &chan->lock) {
+			if (chan->cl) {
+				struct device *cl_dev = chan->cl->dev;
+
+				seq_printf(seq, " %3u: %s\n", i,
+					   cl_dev ? dev_name(cl_dev) : "NULL device");
+			}
+		}
+	}
+
+	return 0;
+}
+
+static const struct seq_operations mbox_sops = {
+	.start = mbox_seq_start,
+	.next = mbox_seq_next,
+	.stop = mbox_seq_stop,
+	.show = mbox_seq_show,
+};
+DEFINE_SEQ_ATTRIBUTE(mbox);
+
+/*
+ * subsys_initcall() is used here but controllers may already have been
+ * registered earlier or will be later. The rationale is that debugfs is
+ * accessed only late, i.e. from userspace. So, files created here must make no
+ * assumptions about initcall ordering.
+ */
+static int __init mbox_init(void)
+{
+	struct dentry *mbox_debugfs = debugfs_create_dir("mailbox", NULL);
+
+	debugfs_create_file("mailbox_summary", 0444, mbox_debugfs, NULL, &mbox_fops);
+	return 0;
+}
+subsys_initcall(mbox_init);
+#endif	/* DEBUG_FS */
-- 
2.51.0
Re: [PATCH v5] mailbox: add list of used channels to debugfs
Posted by Jassi Brar 3 weeks, 4 days ago
On Wed, May 6, 2026 at 2:20 AM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
>
> During development, it is useful to see which mailboxes are currently
> obtained. Use a seq-file in debugfs to list the currently registered
> controllers and their used channels. Example output from a Renesas R-Car
> X5H based system:
>
>  # cat /sys/kernel/debug/mailbox/mailbox_summary
>
> 189e0000.system-controller:
>    0: c1000000.mailbox_test_send_to_recv
>    1: c1000100.mailbox_test_recv_to_send
>  128: c1000100.mailbox_test_recv_to_send
>  129: c1000000.mailbox_test_send_to_recv
> 189e1000.system-controller:
>    4: scmi_dev.1
>    5: scmi_dev.2
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>
> This patch was created on top of "[PATCH v3] mailbox: don't free the
> channel if the startup callback failed". It is no dependency, though.
> The patch applies without it with just some line offsets.
>
> Changes since v4:
> * improved comment to explain the initcall situation
> * rebased to v7.1-rc2
>
>  drivers/mailbox/mailbox.c | 65 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 65 insertions(+)
>
> diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
> index 006ea5a5c320..3716b8ccbe7f 100644
> --- a/drivers/mailbox/mailbox.c
> +++ b/drivers/mailbox/mailbox.c
> @@ -7,6 +7,7 @@
>   */
>
>  #include <linux/cleanup.h>
> +#include <linux/debugfs.h>
>  #include <linux/delay.h>
>  #include <linux/device.h>
>  #include <linux/err.h>
> @@ -16,6 +17,7 @@
>  #include <linux/mutex.h>
>  #include <linux/of.h>
>  #include <linux/property.h>
> +#include <linux/seq_file.h>
>  #include <linux/spinlock.h>
>
>  static LIST_HEAD(mbox_cons);
> @@ -636,3 +638,66 @@ int devm_mbox_controller_register(struct device *dev,
>         return 0;
>  }
>  EXPORT_SYMBOL_GPL(devm_mbox_controller_register);
> +
> +#ifdef CONFIG_DEBUG_FS
> +static void *mbox_seq_start(struct seq_file *s, loff_t *pos)
> +{
> +       mutex_lock(&con_mutex);
> +       return seq_list_start(&mbox_cons, *pos);
> +}
> +
> +static void *mbox_seq_next(struct seq_file *s, void *v, loff_t *pos)
> +{
> +       return seq_list_next(v, &mbox_cons, pos);
> +}
> +
> +static void mbox_seq_stop(struct seq_file *s, void *v)
> +{
> +       mutex_unlock(&con_mutex);
> +}
> +
> +static int mbox_seq_show(struct seq_file *seq, void *v)
> +{
> +       const struct mbox_controller *mbox = list_entry(v, struct mbox_controller, node);
> +
> +       seq_printf(seq, "%s:\n", dev_name(mbox->dev));
> +
> +       for (unsigned int i = 0; i < mbox->num_chans; i++) {
> +               struct mbox_chan *chan = &mbox->chans[i];
> +
> +               scoped_guard(spinlock_irqsave, &chan->lock) {
> +                       if (chan->cl) {
> +                               struct device *cl_dev = chan->cl->dev;
> +
> +                               seq_printf(seq, " %3u: %s\n", i,
> +                                          cl_dev ? dev_name(cl_dev) : "NULL device");
> +                       }
> +               }
> +       }
> +
> +       return 0;
> +}
> +
> +static const struct seq_operations mbox_sops = {
> +       .start = mbox_seq_start,
> +       .next = mbox_seq_next,
> +       .stop = mbox_seq_stop,
> +       .show = mbox_seq_show,
> +};
> +DEFINE_SEQ_ATTRIBUTE(mbox);
> +
> +/*
> + * subsys_initcall() is used here but controllers may already have been
> + * registered earlier or will be later. The rationale is that debugfs is
> + * accessed only late, i.e. from userspace. So, files created here must make no
> + * assumptions about initcall ordering.
> + */
> +static int __init mbox_init(void)
> +{
> +       struct dentry *mbox_debugfs = debugfs_create_dir("mailbox", NULL);
> +
> +       debugfs_create_file("mailbox_summary", 0444, mbox_debugfs, NULL, &mbox_fops);
> +       return 0;
> +}
> +subsys_initcall(mbox_init);
> +#endif /* DEBUG_FS */
> --
> 2.51.0
>
Applied to mailbox/for-next
Thanks
Jassi