Subject: [PATCH] [acpi driver model] Define interface for adding per-device sysfs files - Implement acpi_device_sysfs_{add,remove} that access the driver's sysfs structure and add/remove all the per-device attributes - Declare in drivers/acpi/drivers/core/sysfs.h Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/core/sysfs.c | 53 ++++++++++++++++++++++++++++++++++++- drivers/acpi/drivers/core/sysfs.h | 15 ++++++++++ 2 files changed, 67 insertions(+), 1 deletions(-) applies-to: 5fe8b14b3c26d56519846da6ff1149bb7163e85e a4d4adc548e0c197b96ed8c89c4e09824c863da9 diff --git a/drivers/acpi/drivers/core/sysfs.c b/drivers/acpi/drivers/core/sysfs.c index efd295e..8f115ad 100644 --- a/drivers/acpi/drivers/core/sysfs.c +++ b/drivers/acpi/drivers/core/sysfs.c @@ -8,7 +8,6 @@ * */ -#include #include "core.h" @@ -209,3 +208,55 @@ int acpi_sysfs_device_register(struct ac return ret; } + +/** + * acpi_device_sysfs_add - Add per-device driver sysfs files + * @ad: The ACPI Device + * + * Called when a device is bound to a driver, this will add all + * of the per-device sysfs files that the driver has defined. + * Similar to acpi_sysfs_device_register(), it loops over the + * attributes and calls create_one() for each. If one fails, it + * unwinds and removes the ones that we've added. + */ + +int acpi_device_sysfs_add(struct acpi_dev * ad) +{ + struct acpi_device_driver * adrv = to_acpi_driver(ad->dev.driver); + struct acpi_driver_sysfs * ads = adrv->d_sysfs; + int ret = 0; + int i; + + for (i = 0; i < ads->s_num_attrs; i++) { + ret = create_one(ad, &ads->s_attrs[i]); + if (ret) + goto Fail; + } + return 0; + + Fail: + while (--i > 0) + remove_one(ad, &ads->s_attrs[i]); + return ret; +} + + +/** + * acpi_device_sysfs_remove - Remove per-device driver sysfs files + * @ad: The ACPI device + * + * Called when a device is unbound from a driver, this will loop + * over the per-device sysfs files that the driver has defined and + * call remove_one() for each. + */ + +void acpi_device_sysfs_remove(struct acpi_dev * ad) +{ + struct acpi_device_driver * adrv = to_acpi_driver(ad->dev.driver); + struct acpi_driver_sysfs * ads = adrv->d_sysfs; + int i; + + for (i = 0; i < ads->s_num_attrs; i++) + remove_one(ad, &ads->s_attrs[i]); +} + diff --git a/drivers/acpi/drivers/core/sysfs.h b/drivers/acpi/drivers/core/sysfs.h index 0333fe7..efa809b 100644 --- a/drivers/acpi/drivers/core/sysfs.h +++ b/drivers/acpi/drivers/core/sysfs.h @@ -11,6 +11,9 @@ #ifdef CONFIG_ACPI_DM_SYSFS extern int acpi_sysfs_device_register(struct acpi_dev * ad); extern void acpi_sysfs_device_unregister(struct acpi_dev * ad); + +extern int acpi_device_sysfs_add(struct acpi_dev * ad); +extern void acpi_device_sysfs_remove(struct acpi_dev * ad); #else /* CONFIG_ACPI_DM_SYSFS */ static inline int acpi_sysfs_device_register(struct acpi_dev * ad) @@ -24,5 +27,17 @@ static inline void acpi_sysfs_device_unr } + +static inline int acpi_device_sysfs_add(struct acpi_dev * ad) +{ + return 0; +} + + +static inline void acpi_device_sysfs_remove(struct acpi_dev * ad) +{ + +} + #endif /* CONFIG_ACPI_DM_SYSFS */ --- 0.99.9.GIT