Skip to content

Commit 26cf132

Browse files
Peter Ujfalusivinodkoul
authored andcommitted
dmaengine: Create debug directories for DMA devices
Create a placeholder directory for each registered DMA device. DMA drivers can use the dmaengine_get_debugfs_root() call to get their debugfs root and can populate with custom files to aim debugging. Signed-off-by: Peter Ujfalusi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent db8d9b4 commit 26cf132

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

drivers/dma/dmaengine.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ static long dmaengine_ref_count;
6262
#ifdef CONFIG_DEBUG_FS
6363
#include <linux/debugfs.h>
6464

65+
static struct dentry *rootdir;
66+
67+
static void dmaengine_debug_register(struct dma_device *dma_dev)
68+
{
69+
dma_dev->dbg_dev_root = debugfs_create_dir(dev_name(dma_dev->dev),
70+
rootdir);
71+
if (IS_ERR(dma_dev->dbg_dev_root))
72+
dma_dev->dbg_dev_root = NULL;
73+
}
74+
75+
static void dmaengine_debug_unregister(struct dma_device *dma_dev)
76+
{
77+
debugfs_remove_recursive(dma_dev->dbg_dev_root);
78+
dma_dev->dbg_dev_root = NULL;
79+
}
80+
6581
static void dmaengine_dbg_summary_show(struct seq_file *s,
6682
struct dma_device *dma_dev)
6783
{
@@ -107,14 +123,20 @@ DEFINE_SHOW_ATTRIBUTE(dmaengine_summary);
107123

108124
static void __init dmaengine_debugfs_init(void)
109125
{
110-
struct dentry *rootdir = debugfs_create_dir("dmaengine", NULL);
126+
rootdir = debugfs_create_dir("dmaengine", NULL);
111127

112128
/* /sys/kernel/debug/dmaengine/summary */
113129
debugfs_create_file("summary", 0444, rootdir, NULL,
114130
&dmaengine_summary_fops);
115131
}
116132
#else
117133
static inline void dmaengine_debugfs_init(void) { }
134+
static inline int dmaengine_debug_register(struct dma_device *dma_dev)
135+
{
136+
return 0;
137+
}
138+
139+
static inline void dmaengine_debug_unregister(struct dma_device *dma_dev) { }
118140
#endif /* DEBUG_FS */
119141

120142
/* --- sysfs implementation --- */
@@ -1265,6 +1287,8 @@ int dma_async_device_register(struct dma_device *device)
12651287
dma_channel_rebalance();
12661288
mutex_unlock(&dma_list_mutex);
12671289

1290+
dmaengine_debug_register(device);
1291+
12681292
return 0;
12691293

12701294
err_out:
@@ -1298,6 +1322,8 @@ void dma_async_device_unregister(struct dma_device *device)
12981322
{
12991323
struct dma_chan *chan, *n;
13001324

1325+
dmaengine_debug_unregister(device);
1326+
13011327
list_for_each_entry_safe(chan, n, &device->channels, device_node)
13021328
__dma_async_device_channel_unregister(device, chan);
13031329

drivers/dma/dmaengine.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,20 @@ dmaengine_desc_callback_valid(struct dmaengine_desc_callback *cb)
182182
struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
183183
struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
184184

185+
#ifdef CONFIG_DEBUG_FS
186+
#include <linux/debugfs.h>
187+
188+
static inline struct dentry *
189+
dmaengine_get_debugfs_root(struct dma_device *dma_dev) {
190+
return dma_dev->dbg_dev_root;
191+
}
192+
#else
193+
struct dentry;
194+
static inline struct dentry *
195+
dmaengine_get_debugfs_root(struct dma_device *dma_dev)
196+
{
197+
return NULL;
198+
}
199+
#endif /* CONFIG_DEBUG_FS */
200+
185201
#endif

include/linux/dmaengine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ struct dma_device {
902902
/* debugfs support */
903903
#ifdef CONFIG_DEBUG_FS
904904
void (*dbg_summary_show)(struct seq_file *s, struct dma_device *dev);
905+
struct dentry *dbg_dev_root;
905906
#endif
906907
};
907908

0 commit comments

Comments
 (0)