* [PATCH v3] mailbox: add list of used channels to debugfs
@ 2026-04-13 12:00 Wolfram Sang
2026-04-14 13:12 ` Geert Uytterhoeven
0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2026-04-13 12:00 UTC (permalink / raw)
To: linux-renesas-soc; +Cc: linux-kernel, Sudeep Holla, Wolfram Sang, Jassi Brar
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:
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
Note that mailbox controllers currently can be instantiated at any
initcall stage. So, per-controller debugfs handling was discarded
because it is not clear when to create the root "mailbox"-debugfs entry.
A central file was chosen, similar to the GPIO subsystem, which is
independent of the initcall stage because it will be accessed only when
userspace is available anyhow.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Changes since v2:
* rebased on top of linux-next
(used the wrong branch previously, I am sorry about that!)
drivers/mailbox/mailbox.c | 57 +++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 138ffbcd4fde..d3a29e361f33 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);
@@ -633,3 +635,58 @@ 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);
+
+static int __init mbox_init(void)
+{
+ debugfs_create_file("mailbox_summary", 0444, NULL, NULL, &mbox_fops);
+ return 0;
+}
+subsys_initcall(mbox_init);
+#endif /* DEBUG_FS */
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] mailbox: add list of used channels to debugfs
2026-04-13 12:00 [PATCH v3] mailbox: add list of used channels to debugfs Wolfram Sang
@ 2026-04-14 13:12 ` Geert Uytterhoeven
2026-04-14 15:28 ` Wolfram Sang
0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2026-04-14 13:12 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-renesas-soc, linux-kernel, Sudeep Holla, Jassi Brar
Hi Wolfram,
On Mon, 13 Apr 2026 at 14:09, 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:
>
> 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
>
> Note that mailbox controllers currently can be instantiated at any
> initcall stage. So, per-controller debugfs handling was discarded
> because it is not clear when to create the root "mailbox"-debugfs entry.
> A central file was chosen, similar to the GPIO subsystem, which is
> independent of the initcall stage because it will be accessed only when
> userspace is available anyhow.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Thanks for your patch, which looks useful!
> --- a/drivers/mailbox/mailbox.c
> +++ b/drivers/mailbox/mailbox.c
> +static int __init mbox_init(void)
> +{
> + debugfs_create_file("mailbox_summary", 0444, NULL, NULL, &mbox_fops);
Can you please put it in a subdir, like all other summaries:
~ # ls /sys/kernel/debug/*/*summary
/sys/kernel/debug/clk/clk_orphan_summary
/sys/kernel/debug/clk/clk_summary
/sys/kernel/debug/devfreq/devfreq_summary
/sys/kernel/debug/dmaengine/summary
/sys/kernel/debug/pm_genpd/pm_genpd_summary
/sys/kernel/debug/regulator/regulator_summary
? More mailbox-related files might be added later.
(But more importantly, that way my summary grabbing script will save
it automatically ;-)
> + return 0;
> +}
> +subsys_initcall(mbox_init);
> +#endif /* DEBUG_FS */
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] mailbox: add list of used channels to debugfs
2026-04-14 13:12 ` Geert Uytterhoeven
@ 2026-04-14 15:28 ` Wolfram Sang
2026-04-14 16:03 ` Geert Uytterhoeven
0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2026-04-14 15:28 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: linux-renesas-soc, linux-kernel, Sudeep Holla, Jassi Brar
[-- Attachment #1: Type: text/plain, Size: 1043 bytes --]
Hi Geert,
> > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
>
> Thanks for your patch, which looks useful!
Glad you like it!
> Can you please put it in a subdir, like all other summaries:
Sadly not, because of the paragraph from above:
> > Note that mailbox controllers currently can be instantiated at any
> > initcall stage. So, per-controller debugfs handling was discarded
> > because it is not clear when to create the root "mailbox"-debugfs entry.
> > A central file was chosen, similar to the GPIO subsystem, which is
> > independent of the initcall stage because it will be accessed only when
> > userspace is available anyhow.
I would need to use core_initcall for the mailbox-subsys. debugfs itself
also uses core_initcall. Then, some drivers (e.g. hi3660-mailbox) use
core_initcall. I don't think the subdir is worth all the potential race
conditions and fragile solutions which usually come with it. Or do you
know a solid solution to this problem?
Happy hacking,
Wolfram
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] mailbox: add list of used channels to debugfs
2026-04-14 15:28 ` Wolfram Sang
@ 2026-04-14 16:03 ` Geert Uytterhoeven
0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2026-04-14 16:03 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-renesas-soc, linux-kernel, Sudeep Holla, Jassi Brar
Hi Wolfram,
On Tue, 14 Apr 2026 at 17:28, Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> > > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> >
> > Thanks for your patch, which looks useful!
>
> Glad you like it!
>
> > Can you please put it in a subdir, like all other summaries:
>
> Sadly not, because of the paragraph from above:
>
> > > Note that mailbox controllers currently can be instantiated at any
> > > initcall stage. So, per-controller debugfs handling was discarded
> > > because it is not clear when to create the root "mailbox"-debugfs entry.
> > > A central file was chosen, similar to the GPIO subsystem, which is
> > > independent of the initcall stage because it will be accessed only when
> > > userspace is available anyhow.
>
> I would need to use core_initcall for the mailbox-subsys. debugfs itself
> also uses core_initcall. Then, some drivers (e.g. hi3660-mailbox) use
> core_initcall. I don't think the subdir is worth all the potential race
> conditions and fragile solutions which usually come with it. Or do you
> know a solid solution to this problem?
I am not asking for a per-controller subdir, but a mailbox-specific
subdir. Surely you can do something like:
- debugfs_create_file("mailbox_summary", 0444, NULL, NULL, &mbox_fops);
+ mbox_debugfs = debugfs_create_dir("mailbox", NULL);
+ debugfs_create_file("mailbox_summary", 0444, mbox_debugfs,
+ NULL, &mbox_fops);
Cfr. https://elixir.bootlin.com/linux/v7.0/source/drivers/devfreq/devfreq.c#L2036
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-14 16:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-13 12:00 [PATCH v3] mailbox: add list of used channels to debugfs Wolfram Sang
2026-04-14 13:12 ` Geert Uytterhoeven
2026-04-14 15:28 ` Wolfram Sang
2026-04-14 16:03 ` Geert Uytterhoeven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox