Subject: [PATCH] [acpi driver model] Update sysfs support - Create include/acpi/sysfs.h - Move struct acpi_dev_attr definition there - Add ad_show() and ad_store() methods, which take only a struct acpi_dev (instead of a struct device) - Update the show methods of the default attributes Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/core/sysfs.c | 36 ++++++------------ include/acpi/sysfs.h | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 include/acpi/sysfs.h applies-to: 8503921eb3c13b22404c1f73624d017b32910603 0a135a1292b541f0c9ec325629e96f1c8989e623 diff --git a/drivers/acpi/drivers/core/sysfs.c b/drivers/acpi/drivers/core/sysfs.c index ac3f08e..f442d50 100644 --- a/drivers/acpi/drivers/core/sysfs.c +++ b/drivers/acpi/drivers/core/sysfs.c @@ -8,27 +8,16 @@ * */ +#include #include "core.h" -struct acpi_dev_attr { - struct device_attribute attr; - int (*test)(struct acpi_dev * ad); -}; - -#define define_acpi_attr(__name) \ - { .attr = __ATTR_RO(__name), .test = __name##_test, } - - - /** * Default attributes for ACPI objects and devices */ -static ssize_t uid_show(struct device * d, struct device_attribute * a, char * buffer) +static ssize_t uid_show(struct acpi_dev * ad, char * buffer) { - struct acpi_dev * ad = to_acpi_dev(d); - return sprintf(buffer, "%s\n", acpi_dev_uid(ad)); } @@ -38,10 +27,8 @@ static int uid_test(struct acpi_dev * ad } -static ssize_t hid_show(struct device * d, struct device_attribute * a, char * buffer) +static ssize_t hid_show(struct acpi_dev * ad, char * buffer) { - struct acpi_dev * ad = to_acpi_dev(d); - return sprintf(buffer, "%s\n", acpi_dev_hid(ad)); } @@ -51,9 +38,8 @@ static int hid_test(struct acpi_dev * ad } -static ssize_t cid_show(struct device * d, struct device_attribute * a, char * buffer) +static ssize_t cid_show(struct acpi_dev * ad, char * buffer) { - struct acpi_dev * ad = to_acpi_dev(d); ssize_t remain = PAGE_SIZE; ssize_t ret = 0; char * s = buffer; @@ -87,9 +73,9 @@ static int cid_test(struct acpi_dev * ad static struct acpi_dev_attr acpi_dev_attrs[] = { - define_acpi_attr(uid), - define_acpi_attr(hid), - define_acpi_attr(cid), + acpi_dev_attr_ro_test(uid), + acpi_dev_attr_ro_test(hid), + acpi_dev_attr_ro_test(cid), }; @@ -99,8 +85,8 @@ void acpi_sysfs_device_unregister(struct int i; for (i = 0; i < num; i++) { - if (acpi_dev_attrs[i].test(ad)) - device_remove_file(&ad->dev, &acpi_dev_attrs[i].attr); + if (acpi_dev_attrs[i].ad_test(ad)) + device_remove_file(&ad->dev, &acpi_dev_attrs[i].ad_attr); } } @@ -111,8 +97,8 @@ int acpi_sysfs_device_register(struct ac int ret = 0; for (i = 0; i < num; i++) { - if (acpi_dev_attrs[i].test(ad)) { - ret = device_create_file(&ad->dev, &acpi_dev_attrs[i].attr); + if (acpi_dev_attrs[i].ad_test(ad)) { + ret = device_create_file(&ad->dev, &acpi_dev_attrs[i].ad_attr); if (ret) { acpi_sysfs_device_unregister(ad); break; diff --git a/include/acpi/sysfs.h b/include/acpi/sysfs.h new file mode 100644 index 0000000..c4dd447 --- /dev/null +++ b/include/acpi/sysfs.h @@ -0,0 +1,74 @@ +#include + +struct acpi_dev; + +/* + * This structure defines a sysfs file to be exported for an + * ACPI device. + * + * The macros below will help in declaring these. + * + * Note that the ->ad_test() function is optional. If it is there, + * it will be called when the file is to be added or removed, and + * only operated on if it returns a value != 0. + */ + +struct acpi_dev_attr { + struct device_attribute ad_attr; + ssize_t (*ad_show) (struct acpi_dev *, char *); + ssize_t (*ad_store) (struct acpi_dev *, const char *, size_t); + int (*ad_test) (struct acpi_dev * ad); +}; + + +/* + * These macros are helpers for defining arrays of attributes for + * ACPI devices. + * + * An example usage of them is like this: + * + * static struct acpi_dev_attr acpi_dev_attrs[] = { + * acpi_dev_attr_ro_test(uid), + * acpi_dev_attr_ro_test(hid), + * acpi_dev_attr_ro_test(cid), + * }; + * + * Which will define an array of 3 attributes named "uid", "hid" and + * "cid". It relies on the fact that a show and test function is + * defined for each file (e.g. uid_show() and uid_test()) and that + * they conform to the definitions above.. + * + * The acpi_dev_attr_rw{,_test} can be used to define read/write + * attributes (as long as a write function is defined). + * + * Note that the base attribute show/store methods are left NULL. + * They are filled in by the ACPI sysfs file registration code. + */ + +#define acpi_dev_attr_ro(__name) \ +{ \ + .ad_attr = __ATTR(__name, 0444, NULL, NULL), \ + .ad_show = __name##_show, \ +} + +#define acpi_dev_attr_ro_test(__name) \ +{ \ + .ad_attr = __ATTR(__name, 0444, NULL, NULL), \ + .ad_show = __name##_show, \ + .ad_test = __name##_test, \ +} + +#define acpi_dev_attr_rw(__name) \ +{ \ + .ad_attr = __ATTR(__name, 0644, NULL, NULL), \ + .ad_show = __name##_show, \ + .ad_store = __name##_store, \ +} + +#define acpi_dev_attr_rw_test(__name) \ +{ \ + .ad_attr = __ATTR(__name, 0644, NULL, NULL), \ + .ad_show = __name##_show, \ + .ad_store = __name##_store, \ + .ad_test = __name##_test, \ +} --- 0.99.9.GIT