diff options
Diffstat (limited to 'fs/debugfs/file.c')
| -rw-r--r-- | fs/debugfs/file.c | 117 | 
1 files changed, 106 insertions, 11 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 90f76575c05..f65d4455c5e 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -15,9 +15,11 @@  #include <linux/module.h>  #include <linux/fs.h> +#include <linux/seq_file.h>  #include <linux/pagemap.h>  #include <linux/namei.h>  #include <linux/debugfs.h> +#include <linux/io.h>  static ssize_t default_read_file(struct file *file, char __user *buf,  				 size_t count, loff_t *ppos) @@ -95,7 +97,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u8_wo, NULL, debugfs_u8_set, "%llu\n");   * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling   * code.   */ -struct dentry *debugfs_create_u8(const char *name, mode_t mode, +struct dentry *debugfs_create_u8(const char *name, umode_t mode,  				 struct dentry *parent, u8 *value)  {  	/* if there are no write bits set, make read only */ @@ -147,7 +149,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u16_wo, NULL, debugfs_u16_set, "%llu\n");   * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling   * code.   */ -struct dentry *debugfs_create_u16(const char *name, mode_t mode, +struct dentry *debugfs_create_u16(const char *name, umode_t mode,  				  struct dentry *parent, u16 *value)  {  	/* if there are no write bits set, make read only */ @@ -199,7 +201,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u32_wo, NULL, debugfs_u32_set, "%llu\n");   * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling   * code.   */ -struct dentry *debugfs_create_u32(const char *name, mode_t mode, +struct dentry *debugfs_create_u32(const char *name, umode_t mode,  				 struct dentry *parent, u32 *value)  {  	/* if there are no write bits set, make read only */ @@ -252,7 +254,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n");   * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling   * code.   */ -struct dentry *debugfs_create_u64(const char *name, mode_t mode, +struct dentry *debugfs_create_u64(const char *name, umode_t mode,  				 struct dentry *parent, u64 *value)  {  	/* if there are no write bits set, make read only */ @@ -298,7 +300,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set, "0x%016llx\n   * @value: a pointer to the variable that the file should read to and write   *         from.   */ -struct dentry *debugfs_create_x8(const char *name, mode_t mode, +struct dentry *debugfs_create_x8(const char *name, umode_t mode,  				 struct dentry *parent, u8 *value)  {  	/* if there are no write bits set, make read only */ @@ -322,7 +324,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_x8);   * @value: a pointer to the variable that the file should read to and write   *         from.   */ -struct dentry *debugfs_create_x16(const char *name, mode_t mode, +struct dentry *debugfs_create_x16(const char *name, umode_t mode,  				 struct dentry *parent, u16 *value)  {  	/* if there are no write bits set, make read only */ @@ -346,7 +348,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_x16);   * @value: a pointer to the variable that the file should read to and write   *         from.   */ -struct dentry *debugfs_create_x32(const char *name, mode_t mode, +struct dentry *debugfs_create_x32(const char *name, umode_t mode,  				 struct dentry *parent, u32 *value)  {  	/* if there are no write bits set, make read only */ @@ -370,7 +372,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_x32);   * @value: a pointer to the variable that the file should read to and write   *         from.   */ -struct dentry *debugfs_create_x64(const char *name, mode_t mode, +struct dentry *debugfs_create_x64(const char *name, umode_t mode,  				 struct dentry *parent, u64 *value)  {  	return debugfs_create_file(name, mode, parent, value, &fops_x64); @@ -401,7 +403,7 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_size_t, debugfs_size_t_get, debugfs_size_t_set,   * @value: a pointer to the variable that the file should read to and write   *         from.   */ -struct dentry *debugfs_create_size_t(const char *name, mode_t mode, +struct dentry *debugfs_create_size_t(const char *name, umode_t mode,  				     struct dentry *parent, size_t *value)  {  	return debugfs_create_file(name, mode, parent, value, &fops_size_t); @@ -473,7 +475,7 @@ static const struct file_operations fops_bool = {   * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling   * code.   */ -struct dentry *debugfs_create_bool(const char *name, mode_t mode, +struct dentry *debugfs_create_bool(const char *name, umode_t mode,  				   struct dentry *parent, u32 *value)  {  	return debugfs_create_file(name, mode, parent, value, &fops_bool); @@ -518,10 +520,103 @@ static const struct file_operations fops_blob = {   * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling   * code.   */ -struct dentry *debugfs_create_blob(const char *name, mode_t mode, +struct dentry *debugfs_create_blob(const char *name, umode_t mode,  				   struct dentry *parent,  				   struct debugfs_blob_wrapper *blob)  {  	return debugfs_create_file(name, mode, parent, blob, &fops_blob);  }  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 + * 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, const 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(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); + +#endif /* CONFIG_HAS_IOMEM */  | 
