From 1a087c6ad975bcc193b4bab2e9d61f9c6c547138 Mon Sep 17 00:00:00 2001 From: Alessandro Rubini Date: Fri, 18 Nov 2011 14:50:21 +0100 Subject: debugfs: add tools to printk 32-bit registers Some debugfs file I deal with are mostly blocks of registers, i.e. lines of the form " = 0x". Some files are only registers, some include registers blocks among other material. This patch introduces data structures and functions to deal with both cases. I expect more users of this over time. Signed-off-by: Alessandro Rubini Acked-by: Giancarlo Asnaghi Cc: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- fs/debugfs/file.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'fs') diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 90f76575c056..f31a27c60fc6 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -525,3 +526,92 @@ struct dentry *debugfs_create_blob(const char *name, mode_t mode, return debugfs_create_file(name, mode, parent, blob, &fops_blob); } EXPORT_SYMBOL_GPL(debugfs_create_blob); + +/* + * The regset32 stuff is used to print 32-bit registers using the + * seq_file utilities. We offer printing a register set in an already-opened + * sequential file or create a debugfs file that only prints a regset32. + */ + +/** + * debugfs_print_regs32 - use seq_print to describe a set of registers + * @s: the seq_file structure being used to generate output + * @regs: an array if struct debugfs_reg32 structures + * @mregs: the length of the above array + * @base: the base address to be used in reading the registers + * @prefix: a string to be prefixed to every output line + * + * This function outputs a text block describing the current values of + * some 32-bit hardware registers. It is meant to be used within debugfs + * files based on seq_file that need to show registers, intermixed with other + * information. The prefix argument may be used to specify a leading string, + * because some peripherals have several blocks of identical registers, + * for example configuration of dma channels + */ +int debugfs_print_regs32(struct seq_file *s, struct debugfs_reg32 *regs, + int nregs, void __iomem *base, char *prefix) +{ + int i, ret = 0; + + for (i = 0; i < nregs; i++, regs++) { + if (prefix) + ret += seq_printf(s, "%s", prefix); + ret += seq_printf(s, "%s = 0x%08x\n", regs->name, + readl((void *)(base + regs->offset))); + } + return ret; +} +EXPORT_SYMBOL_GPL(debugfs_print_regs32); + +static int debugfs_show_regset32(struct seq_file *s, void *data) +{ + struct debugfs_regset32 *regset = s->private; + + debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, ""); + return 0; +} + +static int debugfs_open_regset32(struct inode *inode, struct file *file) +{ + return single_open(file, debugfs_show_regset32, inode->i_private); +} + +static const struct file_operations fops_regset32 = { + .open = debugfs_open_regset32, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +/** + * debugfs_create_regset32 - create a debugfs file that returns register values + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @regset: a pointer to a struct debugfs_regset32, which contains a pointer + * to an array of register definitions, the array size and the base + * address where the register bank is to be found. + * + * This function creates a file in debugfs with the given name that reports + * the names and values of a set of 32-bit registers. If the @mode variable + * is so set it can be read from. Writing is not supported. + * + * This function will return a pointer to a dentry if it succeeds. This + * pointer must be passed to the debugfs_remove() function when the file is + * to be removed (no automatic cleanup happens if your module is unloaded, + * you are responsible here.) If an error occurs, %NULL will be returned. + * + * If debugfs is not enabled in the kernel, the value -%ENODEV will be + * returned. It is not wise to check for this value, but rather, check for + * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling + * code. + */ +struct dentry *debugfs_create_regset32(const char *name, mode_t mode, + struct dentry *parent, + struct debugfs_regset32 *regset) +{ + return debugfs_create_file(name, mode, parent, regset, &fops_regset32); +} +EXPORT_SYMBOL_GPL(debugfs_create_regset32); -- cgit v1.2.3 From 8ee4dd9f063ce59c08f3ce283ca03306131aaf3a Mon Sep 17 00:00:00 2001 From: Alessandro Rubini Date: Fri, 18 Nov 2011 23:53:29 +0100 Subject: debugfs: print_regs32: make regs array a const pointer Signed-off-by: Alessandro Rubini Signed-off-by: Greg Kroah-Hartman --- fs/debugfs/file.c | 2 +- include/linux/debugfs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'fs') diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index f31a27c60fc6..fc98ec9e1d83 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -548,7 +548,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_blob); * because some peripherals have several blocks of identical registers, * for example configuration of dma channels */ -int debugfs_print_regs32(struct seq_file *s, struct debugfs_reg32 *regs, +int debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs, int nregs, void __iomem *base, char *prefix) { int i, ret = 0; diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index 5e6b01f6db4c..e8c3abc60811 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -90,7 +90,7 @@ struct dentry *debugfs_create_regset32(const char *name, mode_t mode, struct dentry *parent, struct debugfs_regset32 *regset); -int debugfs_print_regs32(struct seq_file *s, struct debugfs_reg32 *regs, +int debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs, int nregs, void __iomem *base, char *prefix); bool debugfs_initialized(void); -- cgit v1.2.3 From 03e099fbb0fbd8aaef9316e74790d9819c57c8ff Mon Sep 17 00:00:00 2001 From: Alessandro Rubini Date: Mon, 21 Nov 2011 10:01:40 +0100 Subject: debugfs: bugfix: include in file.c The regs32 machinery uses readl. I forgot the mandatory include and the code was not compiling on all archs. Reported-by: Stephen Rothwell Signed-off-by: Alessandro Rubini Signed-off-by: Greg Kroah-Hartman --- fs/debugfs/file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'fs') diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index fc98ec9e1d83..e0a3a59a6744 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -19,6 +19,7 @@ #include #include #include +#include static ssize_t default_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos) -- cgit v1.2.3 From 5858441c95587c6869950314742d99e6a03a2d16 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 24 Nov 2011 10:22:08 +0300 Subject: debugfs: remove unneeded cast in debugfs_print_regs32() The cast here causes a Sparse warning: fs/debugfs/file.c:561:42: warning: cast removes address space of expression fs/debugfs/file.c:561:42: warning: incorrect type in argument 1 (different address spaces) fs/debugfs/file.c:561:42: expected void const volatile [noderef] *addr fs/debugfs/file.c:561:42: got void * It's redundant to cast it to a (void *) anyway when it is already a (void __iomem *). Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman --- fs/debugfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index e0a3a59a6744..989f07fb86f7 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -558,7 +558,7 @@ int debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs, if (prefix) ret += seq_printf(s, "%s", prefix); ret += seq_printf(s, "%s = 0x%08x\n", regs->name, - readl((void *)(base + regs->offset))); + readl(base + regs->offset)); } return ret; } -- cgit v1.2.3 From 3b85e4ab2ec1dea29374f16205917b1b5589bc81 Mon Sep 17 00:00:00 2001 From: Heiko Carstens Date: Tue, 27 Dec 2011 15:08:28 +0100 Subject: debugfs: add missing #ifdef HAS_IOMEM "debugfs: add tools to printk 32-bit registers" adds new functions which rely on IOMEM functionality which is not present on all architectures and therefore result in compile errors: fs/debugfs/file.c: In function 'debugfs_print_regs32': fs/debugfs/file.c:561:7: error: implicit declaration of function 'readl' [-Werror=implicit-function-declaration] Add an #ifdef CONFIG_HAS_IOMEM to fix this Signed-off-by: Heiko Carstens Acked-by: Alessandro Rubini Signed-off-by: Greg Kroah-Hartman --- fs/debugfs/file.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'fs') diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 989f07fb86f7..ea62afa4fd57 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -528,6 +528,8 @@ struct dentry *debugfs_create_blob(const char *name, mode_t mode, } EXPORT_SYMBOL_GPL(debugfs_create_blob); +#ifdef CONFIG_HAS_IOMEM + /* * The regset32 stuff is used to print 32-bit registers using the * seq_file utilities. We offer printing a register set in an already-opened @@ -616,3 +618,5 @@ struct dentry *debugfs_create_regset32(const char *name, mode_t mode, return debugfs_create_file(name, mode, parent, regset, &fops_regset32); } EXPORT_SYMBOL_GPL(debugfs_create_regset32); + +#endif /* CONFIG_HAS_IOMEM */ -- cgit v1.2.3