git: aa0370996eca - stable/13 - LinuxKPI,lindebugfs: add u8 base type and blob support
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 18 Jan 2023 16:24:49 UTC
The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=aa0370996eca5c8d4a8cd2c09888300bbb253994 commit aa0370996eca5c8d4a8cd2c09888300bbb253994 Author: Bjoern A. Zeeb <bz@FreeBSD.org> AuthorDate: 2022-10-22 18:12:16 +0000 Commit: Bjoern A. Zeeb <bz@FreeBSD.org> CommitDate: 2023-01-18 13:24:15 +0000 LinuxKPI,lindebugfs: add u8 base type and blob support Add debugfs_create_u8() based on other already present implementations. Add a read-only implementation for debugfs_create_blob(). Both are needed for iwlwifi debugfs support. Sponsored by: The FreeBSD Foundation OKed by: jfree (earlier version) Differential Revision: https://reviews.freebsd.org/D37090 (cherry picked from commit 0fce2dc1573019d0732f33fa7c26cc228655d3e8) --- sys/compat/lindebugfs/lindebugfs.c | 66 ++++++++++++++++++++++ sys/compat/linuxkpi/common/include/linux/debugfs.h | 11 +++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/sys/compat/lindebugfs/lindebugfs.c b/sys/compat/lindebugfs/lindebugfs.c index b88caf9c3140..b72ceb5e0be9 100644 --- a/sys/compat/lindebugfs/lindebugfs.c +++ b/sys/compat/lindebugfs/lindebugfs.c @@ -367,6 +367,35 @@ debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent, bool &fops_bool_ro, &fops_bool_wo); } + +static int +debugfs_u8_get(void *data, uint64_t *value) +{ + uint8_t *u8data = data; + *value = *u8data; + return (0); +} + +static int +debugfs_u8_set(void *data, uint64_t value) +{ + uint8_t *u8data = data; + *u8data = (uint8_t)value; + return (0); +} + +DEFINE_DEBUGFS_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%u\n"); +DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_ro, debugfs_u8_get, NULL, "%u\n"); +DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_wo, NULL, debugfs_u8_set, "%u\n"); + +void +debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent, uint8_t *value) +{ + debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u8, + &fops_u8_ro, &fops_u8_wo); +} + + static int debugfs_ulong_get(void *data, uint64_t *value) { @@ -394,6 +423,43 @@ debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent, unsi &fops_ulong_ro, &fops_ulong_wo); } + +static ssize_t +fops_blob_read(struct file *filp, char __user *ubuf, size_t read_size, loff_t *ppos) +{ + struct debugfs_blob_wrapper *blob; + + blob = filp->private_data; + if (blob == NULL) + return (-EINVAL); + if (blob->size == 0 || blob->data == NULL) + return (-EINVAL); + + return (simple_read_from_buffer(ubuf, read_size, ppos, blob->data, blob->size)); +} + +static int +fops_blob_open(struct inode *inode, struct file *filp) +{ + return (simple_open(inode, filp)); +} + +static const struct file_operations __fops_blob_ro = { + .owner = THIS_MODULE, + .open = fops_blob_open, + .read = fops_blob_read, + .llseek = no_llseek +}; + +struct dentry * +debugfs_create_blob(const char *name, umode_t mode, struct dentry *parent, + struct debugfs_blob_wrapper *value) +{ + /* Blobs are read-only. */ + return (debugfs_create_file(name, mode & 0444, parent, value, &__fops_blob_ro)); +} + + static int lindebugfs_init(PFS_INIT_ARGS) { diff --git a/sys/compat/linuxkpi/common/include/linux/debugfs.h b/sys/compat/linuxkpi/common/include/linux/debugfs.h index ba1fa009dc62..4c9f52a0bc0f 100644 --- a/sys/compat/linuxkpi/common/include/linux/debugfs.h +++ b/sys/compat/linuxkpi/common/include/linux/debugfs.h @@ -47,6 +47,11 @@ struct debugfs_regset32 { int nregs; }; +struct debugfs_blob_wrapper { + void *data; + size_t size; +}; + struct dentry *debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops); @@ -75,8 +80,12 @@ void debugfs_remove_recursive(struct dentry *dentry); void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent, bool *value); - +void debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent, + uint8_t *value); void debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent, unsigned long *value); +struct dentry *debugfs_create_blob(const char *name, umode_t mode, + struct dentry *parent, struct debugfs_blob_wrapper *value); + #endif /* _LINUXKPI_LINUX_DEBUGFS_H_ */