Subject: [PATCH] [acpi driver model] Add definitions for new procfs interface - Create include/acpi/proc.h. - Add structures for per-device proc files and per-driver directory definitions. - Create macros for helping drivers define the structures. Signed-off-by: Patrick Mochel --- include/acpi/proc.h | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 156 insertions(+), 0 deletions(-) create mode 100644 include/acpi/proc.h applies-to: 446691fadc89a5dd2a2ad1a6ecb515615d4b2201 cfd7e622d7e8791ad44c020241baa12772655e7e diff --git a/include/acpi/proc.h b/include/acpi/proc.h new file mode 100644 index 0000000..cdb3dac --- /dev/null +++ b/include/acpi/proc.h @@ -0,0 +1,156 @@ +#include +#include + + +/** + * This structure describes a proc file to be added + * for each device. + */ + +struct acpi_proc_file { + char * name; + mode_t mode; + struct file_operations fops; +}; + + +/** + * These macros help simplify the definition of the files. + * Drivers should use these (and conform to the naming + * scheme) instead of doing all this by hand. + * + * To define a read-only file "foo" for a device, the driver + * needs to define this: + * + * static int read_foo(struct seq_file * seq, void * offset) + * { + * ... + * return 0; + * } + * + * And this: + * + * static int open_foo(struct inode * inode, struct file * file) + * { + * return single_open(file, read_foo, PDE(inode)->data); + * } + * + * And then declare this (assuming the name of the driver is 'ac'): + * + * static struct acpi_proc_file ac_files[] = { + * proc_file_ro(foo), + * }; + * + * + * Please use the same naming convention (e.g. "ac_files"), as + * the macros below rely on it being that way.. + */ + +#define proc_file_ro(__name) \ + { \ + .name = __stringify(__name), \ + .mode = S_IRUGO, \ + .fops = { \ + .open = open_##__name, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ + .owner = THIS_MODULE, \ + }, \ + } + +#define proc_file_rw(__name) \ + { \ + .name = __stringify(__name), \ + .mode = S_IRUGO | S_IWUSR, \ + .fops = { \ + .open = open_##__name, \ + .read = seq_read, \ + .write = write_##__name, \ + .llseek = seq_lseek, \ + .release = single_release, \ + .owner = THIS_MODULE, \ + }, \ + } + + +/** + * This structure defines the entire proc state for a + * driver. Some fields are filled in by the driver + * (p_owner, p_files, etc). + * + * Some fields are filled in by the ACPI driver core + * when the driver is registered (e.g. p_parent). + * + * You probably want to use the macros below to + * define this structure. + */ + +struct acpi_driver_proc { + char * p_name; + struct proc_dir_entry * p_parent; + struct module * p_owner; + struct acpi_proc_file * p_files; + int p_num_files; +}; + + +/** + * This is the standard macro for defining a proc structure. + * + * You want to use this, unless the proc directory name has + * always been something different than the driver name. + * + * For example, the thermal driver has a proc directory + * named "thermal_zone". In this case, use the next macro. + */ + +#define acpi_driver_proc(__name) \ +struct acpi_driver_proc __name##_proc = { \ + .p_name = __stringify(__name), \ + .p_owner = THIS_MODULE, \ + .p_files = __name##_files, \ + .p_num_files = ARRAY_SIZE(__name##_files), \ +} + + +/** + * This is a modifed proc definition macro. + * + * This allows a driver to define a proc directory with + * a name different than that of the driver. + * + * For example, the thermal driver has a proc directory + * named "thermal_zone". In this case, use this macro. + */ + +#define acpi_driver_proc_name(__name, dir_name) \ +struct acpi_driver_proc __name##_proc = { \ + .p_name = dir_name, \ + .p_owner = THIS_MODULE, \ + .p_files = __name##_files, \ + .p_num_files = ARRAY_SIZE(__name##_files), \ +} + +/* + * These macros are used by include/acpi/device.h to simplify the + * acpi driver declaration macro, and to provide for the case where + * the procfs interface is either enabled or disabled. + * + */ + +#ifdef CONFIG_ACPI_DM_PROC + +#define acpi_driver_proc_extern(__name) \ +extern struct acpi_driver_proc __name##_proc + +#define acpi_driver_proc_ref(__name) & __name##_proc + + +#else /* CONFIG_ACPI_DM_PROC */ + + +#define acpi_driver_proc_extern(__name) + +#define acpi_driver_proc_ref(__name) NULL +#endif /* CONFIG_ACPI_DM_PROC */ --- 0.99.9.GIT