From ce0c1fcc7357ef0ec93c5a1cd1a759729d27599a Mon Sep 17 00:00:00 2001 From: Aleksey Makarov Date: Mon, 20 Jun 2016 13:56:09 +0300 Subject: ACPI / tables: table upgrade: use cacheable map for tables The new memory allocated in acpi_table_initrd_init() is used to copy the upgraded tables to it. So it should be mapped with early_memunmap() instead of early_ioremap(). This is critical for ARM. Signed-off-by: Aleksey Makarov Acked-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/tables.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index a372f9eaa15d..f829e6a2e663 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -578,10 +578,10 @@ static void __init acpi_table_initrd_init(void *data, size_t size) clen = size; if (clen > MAP_CHUNK_SIZE - slop) clen = MAP_CHUNK_SIZE - slop; - dest_p = early_ioremap(dest_addr & PAGE_MASK, - clen + slop); + dest_p = early_memremap(dest_addr & PAGE_MASK, + clen + slop); memcpy(dest_p + slop, src_p, clen); - early_iounmap(dest_p, clen + slop); + early_memunmap(dest_p, clen + slop); src_p += clen; dest_addr += clen; size -= clen; -- cgit v1.2.3 From da3d3f98d28bc071a2d566aefc8c461bd564be35 Mon Sep 17 00:00:00 2001 From: Aleksey Makarov Date: Mon, 20 Jun 2016 13:56:10 +0300 Subject: ACPI / tables: table upgrade: refactor function definitions Refer initrd_start, initrd_end directly from drivers/acpi/tables.c. This allows to use the table upgrade feature in architectures other than x86. Also this simplifies header files. The patch renames acpi_table_initrd_init() to acpi_table_upgrade() (what reflects the purpose of the function) and removes the unneeded wraps early_acpi_table_init() and early_initrd_acpi_init(). Signed-off-by: Aleksey Makarov Acked-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- arch/x86/kernel/setup.c | 9 +-------- drivers/acpi/tables.c | 14 ++++---------- include/linux/acpi.h | 8 ++++++-- 3 files changed, 11 insertions(+), 20 deletions(-) (limited to 'drivers/acpi') diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index c4e7b3991b60..aac91beabf05 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -399,10 +399,6 @@ static void __init reserve_initrd(void) memblock_free(ramdisk_image, ramdisk_end - ramdisk_image); } -static void __init early_initrd_acpi_init(void) -{ - early_acpi_table_init((void *)initrd_start, initrd_end - initrd_start); -} #else static void __init early_reserve_initrd(void) { @@ -410,9 +406,6 @@ static void __init early_reserve_initrd(void) static void __init reserve_initrd(void) { } -static void __init early_initrd_acpi_init(void) -{ -} #endif /* CONFIG_BLK_DEV_INITRD */ static void __init parse_setup_data(void) @@ -1146,7 +1139,7 @@ void __init setup_arch(char **cmdline_p) reserve_initrd(); - early_initrd_acpi_init(); + acpi_table_upgrade(); vsmp_init(); diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index f829e6a2e663..b05df13bd79f 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "internal.h" #ifdef CONFIG_ACPI_CUSTOM_DSDT @@ -481,8 +482,10 @@ static DECLARE_BITMAP(acpi_initrd_installed, NR_ACPI_INITRD_TABLES); #define MAP_CHUNK_SIZE (NR_FIX_BTMAPS << PAGE_SHIFT) -static void __init acpi_table_initrd_init(void *data, size_t size) +void __init acpi_table_upgrade(void) { + void *data = (void *)initrd_start; + size_t size = initrd_end - initrd_start; int sig, no, table_nr = 0, total_offset = 0; long offset = 0; struct acpi_table_header *table; @@ -696,10 +699,6 @@ next_table: } } #else -static void __init acpi_table_initrd_init(void *data, size_t size) -{ -} - static acpi_status acpi_table_initrd_override(struct acpi_table_header *existing_table, acpi_physical_address *address, @@ -742,11 +741,6 @@ acpi_os_table_override(struct acpi_table_header *existing_table, return AE_OK; } -void __init early_acpi_table_init(void *data, size_t size) -{ - acpi_table_initrd_init(data, size); -} - /* * acpi_table_init() * diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 288fac5294f5..ef2ad26abede 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -208,7 +208,6 @@ void acpi_boot_table_init (void); int acpi_mps_check (void); int acpi_numa_init (void); -void early_acpi_table_init(void *data, size_t size); int acpi_table_init (void); int acpi_table_parse(char *id, acpi_tbl_table_handler handler); int __init acpi_parse_entries(char *id, unsigned long table_size, @@ -588,7 +587,6 @@ static inline const char *acpi_dev_name(struct acpi_device *adev) return NULL; } -static inline void early_acpi_table_init(void *data, size_t size) { } static inline void acpi_early_init(void) { } static inline void acpi_subsystem_init(void) { } @@ -997,4 +995,10 @@ static inline struct fwnode_handle *acpi_get_next_subnode(struct device *dev, #define acpi_probe_device_table(t) ({ int __r = 0; __r;}) #endif +#ifdef CONFIG_ACPI_TABLE_UPGRADE +void acpi_table_upgrade(void); +#else +static inline void acpi_table_upgrade(void) { } +#endif + #endif /*_LINUX_ACPI_H*/ -- cgit v1.2.3 From 84b06ca319dae15f40fd7ff2bfff4769ab8cc58d Mon Sep 17 00:00:00 2001 From: Aleksey Makarov Date: Mon, 20 Jun 2016 13:56:11 +0300 Subject: ACPI / tables: move arch-specific symbol to asm/acpi.h The constant that defines max phys address where the new upgraded ACPI table should be allocated is arch-specific. Move it to Signed-off-by: Aleksey Makarov Signed-off-by: Rafael J. Wysocki --- arch/x86/include/asm/acpi.h | 2 ++ drivers/acpi/tables.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers/acpi') diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h index 94c18ebfd68c..c24c07035609 100644 --- a/arch/x86/include/asm/acpi.h +++ b/arch/x86/include/asm/acpi.h @@ -170,4 +170,6 @@ static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) } #endif +#define ACPI_TABLE_UPGRADE_MAX_PHYS (max_low_pfn_mapped << PAGE_SHIFT) + #endif /* _ASM_X86_ACPI_H */ diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index b05df13bd79f..9f0ad6ebb368 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "internal.h" #ifdef CONFIG_ACPI_CUSTOM_DSDT @@ -543,7 +544,7 @@ void __init acpi_table_upgrade(void) return; acpi_tables_addr = - memblock_find_in_range(0, max_low_pfn_mapped << PAGE_SHIFT, + memblock_find_in_range(0, ACPI_TABLE_UPGRADE_MAX_PHYS, all_tables_size, PAGE_SIZE); if (!acpi_tables_addr) { WARN_ON(1); -- cgit v1.2.3 From 91dda51a115770fb9f24634fb09a502ad7bda5c6 Mon Sep 17 00:00:00 2001 From: Aleksey Makarov Date: Mon, 20 Jun 2016 13:56:12 +0300 Subject: ACPI / tables: introduce ARCH_HAS_ACPI_TABLE_UPGRADE We want to use the table upgrade feature in ARM64. Introduce a new configuration option that allows that. Signed-off-by: Aleksey Makarov Signed-off-by: Rafael J. Wysocki --- arch/x86/Kconfig | 1 + drivers/acpi/Kconfig | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers/acpi') diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index d9a94da0c29f..f1a62447928c 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -22,6 +22,7 @@ config X86 select ANON_INODES select ARCH_CLOCKSOURCE_DATA select ARCH_DISCARD_MEMBLOCK + select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select ARCH_HAS_DEVMEM_IS_ALLOWED diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index b7e2e776397d..0a8e41a52d09 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -311,9 +311,12 @@ config ACPI_CUSTOM_DSDT bool default ACPI_CUSTOM_DSDT_FILE != "" +config ARCH_HAS_ACPI_TABLE_UPGRADE + def_bool n + config ACPI_TABLE_UPGRADE bool "Allow upgrading ACPI tables via initrd" - depends on BLK_DEV_INITRD && X86 + depends on BLK_DEV_INITRD && ARCH_HAS_ACPI_TABLE_UPGRADE default y help This option provides functionality to upgrade arbitrary ACPI tables -- cgit v1.2.3 From 10c7e20b2ff3caa5a8c0e7d60aef5a9c86e60ce8 Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Fri, 8 Jul 2016 19:13:08 +0300 Subject: ACPI / scan: fix enumeration (visited) flags for bus rescans If the ACPI tables change as a result of a dinamically loaded table and a bus rescan is required the enumeration/visited flag are not consistent. I2C/SPI are not directly enumerated in acpi_bus_attach(), however the visited flag is set. This makes it impossible to check if an ACPI device has already been enumerated by the I2C and SPI subsystems. To fix this issue we only set the visited flags if the device is not I2C or SPI. With this change we also need to remove setting visited to false from acpi_bus_attach(), otherwise if we rescan already enumerated I2C/SPI devices we try to re-enumerate them. Note that I2C/SPI devices can be enumerated either via a scan handler (when using PRP0001) or via regular device_attach(). In either case the flow goes through acpi_default_enumeration() which makes it the ideal place to mark the ACPI device as enumerated. Signed-off-by: Octavian Purdila Reviewed-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 13 +++++++------ include/linux/acpi.h | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 5f28cf778349..f80f8a747294 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1406,7 +1406,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, acpi_bus_get_flags(device); device->flags.match_driver = false; device->flags.initialized = true; - device->flags.visited = false; + acpi_device_clear_enumerated(device); device_initialize(&device->dev); dev_set_uevent_suppress(&device->dev, true); acpi_init_coherency(device); @@ -1683,8 +1683,10 @@ static void acpi_default_enumeration(struct acpi_device *device) acpi_dev_get_resources(device, &resource_list, acpi_check_spi_i2c_slave, &is_spi_i2c_slave); acpi_dev_free_resource_list(&resource_list); - if (!is_spi_i2c_slave) + if (!is_spi_i2c_slave) { acpi_create_platform_device(device); + acpi_device_set_enumerated(device); + } } static const struct acpi_device_id generic_device_ids[] = { @@ -1751,7 +1753,7 @@ static void acpi_bus_attach(struct acpi_device *device) acpi_bus_get_status(device); /* Skip devices that are not present. */ if (!acpi_device_is_present(device)) { - device->flags.visited = false; + acpi_device_clear_enumerated(device); device->flags.power_manageable = 0; return; } @@ -1766,7 +1768,7 @@ static void acpi_bus_attach(struct acpi_device *device) device->flags.initialized = true; } - device->flags.visited = false; + ret = acpi_scan_attach_handler(device); if (ret < 0) return; @@ -1780,7 +1782,6 @@ static void acpi_bus_attach(struct acpi_device *device) if (!ret && device->pnp.type.platform_id) acpi_default_enumeration(device); } - device->flags.visited = true; ok: list_for_each_entry(child, &device->children, node) @@ -1872,7 +1873,7 @@ void acpi_bus_trim(struct acpi_device *adev) */ acpi_device_set_power(adev, ACPI_STATE_D3_COLD); adev->flags.initialized = false; - adev->flags.visited = false; + acpi_device_clear_enumerated(adev); } EXPORT_SYMBOL_GPL(acpi_bus_trim); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index ef2ad26abede..db680e8788c4 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -531,6 +531,16 @@ void acpi_walk_dep_device_list(acpi_handle handle); struct platform_device *acpi_create_platform_device(struct acpi_device *); #define ACPI_PTR(_ptr) (_ptr) +static inline void acpi_device_set_enumerated(struct acpi_device *adev) +{ + adev->flags.visited = true; +} + +static inline void acpi_device_clear_enumerated(struct acpi_device *adev) +{ + adev->flags.visited = false; +} + #else /* !CONFIG_ACPI */ #define acpi_disabled 1 @@ -676,6 +686,14 @@ static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) #define ACPI_PTR(_ptr) (NULL) +static inline void acpi_device_set_enumerated(struct acpi_device *adev) +{ +} + +static inline void acpi_device_clear_enumerated(struct acpi_device *adev) +{ +} + #endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI -- cgit v1.2.3 From 68bdb6773289f8c9a36633f9f6525b127c093258 Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Fri, 8 Jul 2016 19:13:09 +0300 Subject: ACPI: add support for ACPI reconfiguration notifiers Add support for ACPI reconfiguration notifiers to allow subsystems to react to changes in the ACPI tables that happen after the initial enumeration. This is similar with the way dynamic device tree notifications work. The reconfigure notifications supported for now are device add and device remove. Since ACPICA allows only one table notification handler, this patch makes the table notifier function generic and moves it out of the sysfs specific code. Signed-off-by: Octavian Purdila Reviewed-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki --- drivers/acpi/bus.c | 9 +++++++ drivers/acpi/internal.h | 3 +++ drivers/acpi/scan.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++- drivers/acpi/sysfs.c | 6 ++--- include/linux/acpi.h | 18 +++++++++++++ 5 files changed, 99 insertions(+), 5 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 262ca31b86d9..97e270e06653 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -990,6 +990,13 @@ void __init acpi_subsystem_init(void) } } +static acpi_status acpi_bus_table_handler(u32 event, void *table, void *context) +{ + acpi_scan_table_handler(event, table, context); + + return acpi_sysfs_table_handler(event, table, context); +} + static int __init acpi_bus_init(void) { int result; @@ -1043,6 +1050,8 @@ static int __init acpi_bus_init(void) * _PDC control method may load dynamic SSDT tables, * and we need to install the table handler before that. */ + status = acpi_install_table_handler(acpi_bus_table_handler, NULL); + acpi_sysfs_init(); acpi_early_processor_set_pdc(); diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 27cc7feabfe4..940218ff0193 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -87,6 +87,9 @@ bool acpi_queue_hotplug_work(struct work_struct *work); void acpi_device_hotplug(struct acpi_device *adev, u32 src); bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent); +acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context); +void acpi_scan_table_handler(u32 event, void *table, void *context); + /* -------------------------------------------------------------------------- Device Node Initialization / Removal -------------------------------------------------------------------------- */ diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index f80f8a747294..405056b95b05 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -494,6 +494,8 @@ static void acpi_device_del(struct acpi_device *device) device_del(&device->dev); } +static BLOCKING_NOTIFIER_HEAD(acpi_reconfig_chain); + static LIST_HEAD(acpi_device_del_list); static DEFINE_MUTEX(acpi_device_del_lock); @@ -514,6 +516,9 @@ static void acpi_device_del_work_fn(struct work_struct *work_not_used) mutex_unlock(&acpi_device_del_lock); + blocking_notifier_call_chain(&acpi_reconfig_chain, + ACPI_RECONFIG_DEVICE_REMOVE, adev); + acpi_device_del(adev); /* * Drop references to all power resources that might have been @@ -1676,7 +1681,7 @@ static void acpi_default_enumeration(struct acpi_device *device) bool is_spi_i2c_slave = false; /* - * Do not enemerate SPI/I2C slaves as they will be enuerated by their + * Do not enumerate SPI/I2C slaves as they will be enumerated by their * respective parents. */ INIT_LIST_HEAD(&resource_list); @@ -1686,6 +1691,9 @@ static void acpi_default_enumeration(struct acpi_device *device) if (!is_spi_i2c_slave) { acpi_create_platform_device(device); acpi_device_set_enumerated(device); + } else { + blocking_notifier_call_chain(&acpi_reconfig_chain, + ACPI_RECONFIG_DEVICE_ADD, device); } } @@ -1917,6 +1925,8 @@ static int acpi_bus_scan_fixed(void) return result < 0 ? result : 0; } +static bool acpi_scan_initialized; + int __init acpi_scan_init(void) { int result; @@ -1961,6 +1971,8 @@ int __init acpi_scan_init(void) acpi_update_all_gpes(); + acpi_scan_initialized = true; + out: mutex_unlock(&acpi_scan_lock); return result; @@ -2004,3 +2016,57 @@ int __init __acpi_probe_device_table(struct acpi_probe_entry *ap_head, int nr) return count; } + +struct acpi_table_events_work { + struct work_struct work; + void *table; + u32 event; +}; + +static void acpi_table_events_fn(struct work_struct *work) +{ + struct acpi_table_events_work *tew; + + tew = container_of(work, struct acpi_table_events_work, work); + + if (tew->event == ACPI_TABLE_EVENT_LOAD) { + acpi_scan_lock_acquire(); + acpi_bus_scan(ACPI_ROOT_OBJECT); + acpi_scan_lock_release(); + } + + kfree(tew); +} + +void acpi_scan_table_handler(u32 event, void *table, void *context) +{ + struct acpi_table_events_work *tew; + + if (!acpi_scan_initialized) + return; + + if (event != ACPI_TABLE_EVENT_LOAD) + return; + + tew = kmalloc(sizeof(*tew), GFP_KERNEL); + if (!tew) + return; + + INIT_WORK(&tew->work, acpi_table_events_fn); + tew->table = table; + tew->event = event; + + schedule_work(&tew->work); +} + +int acpi_reconfig_notifier_register(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&acpi_reconfig_chain, nb); +} +EXPORT_SYMBOL(acpi_reconfig_notifier_register); + +int acpi_reconfig_notifier_unregister(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&acpi_reconfig_chain, nb); +} +EXPORT_SYMBOL(acpi_reconfig_notifier_unregister); diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c index 4b3a9e27f1b6..358165e9f5b8 100644 --- a/drivers/acpi/sysfs.c +++ b/drivers/acpi/sysfs.c @@ -378,8 +378,7 @@ static void acpi_table_attr_init(struct acpi_table_attr *table_attr, return; } -static acpi_status -acpi_sysfs_table_handler(u32 event, void *table, void *context) +acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context) { struct acpi_table_attr *table_attr; @@ -452,9 +451,8 @@ static int acpi_tables_sysfs_init(void) kobject_uevent(tables_kobj, KOBJ_ADD); kobject_uevent(dynamic_tables_kobj, KOBJ_ADD); - status = acpi_install_table_handler(acpi_sysfs_table_handler, NULL); - return ACPI_FAILURE(status) ? -EINVAL : 0; + return 0; err_dynamic_tables: kobject_put(tables_kobj); err: diff --git a/include/linux/acpi.h b/include/linux/acpi.h index db680e8788c4..8b48de17e388 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -541,6 +541,14 @@ static inline void acpi_device_clear_enumerated(struct acpi_device *adev) adev->flags.visited = false; } +enum acpi_reconfig_event { + ACPI_RECONFIG_DEVICE_ADD = 0, + ACPI_RECONFIG_DEVICE_REMOVE, +}; + +int acpi_reconfig_notifier_register(struct notifier_block *nb); +int acpi_reconfig_notifier_unregister(struct notifier_block *nb); + #else /* !CONFIG_ACPI */ #define acpi_disabled 1 @@ -694,6 +702,16 @@ static inline void acpi_device_clear_enumerated(struct acpi_device *adev) { } +static inline int acpi_reconfig_notifier_register(struct notifier_block *nb) +{ + return -EINVAL; +} + +static inline int acpi_reconfig_notifier_unregister(struct notifier_block *nb) +{ + return -EINVAL; +} + #endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI -- cgit v1.2.3 From 0bf54fcd95042bd178cb25368422cf4474fc8492 Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Fri, 8 Jul 2016 19:13:13 +0300 Subject: ACPI: add support for configfs Register the ACPI subsystem with configfs. Signed-off-by: Octavian Purdila Reviewed-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki --- Documentation/ABI/testing/configfs-acpi | 7 +++++ MAINTAINERS | 1 + drivers/acpi/Kconfig | 8 +++++ drivers/acpi/Makefile | 1 + drivers/acpi/configfs.c | 53 +++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 Documentation/ABI/testing/configfs-acpi create mode 100644 drivers/acpi/configfs.c (limited to 'drivers/acpi') diff --git a/Documentation/ABI/testing/configfs-acpi b/Documentation/ABI/testing/configfs-acpi new file mode 100644 index 000000000000..17b19dc2822d --- /dev/null +++ b/Documentation/ABI/testing/configfs-acpi @@ -0,0 +1,7 @@ +What: /config/acpi +Date: July 2016 +KernelVersion: 4.8 +Contact: linux-acpi@vger.kernel.org +Description: + This represents the ACPI subsystem entry point directory. It + contains sub-groups corresponding to ACPI configurable options. diff --git a/MAINTAINERS b/MAINTAINERS index e1b090f86e0d..d01d8e2cf268 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -288,6 +288,7 @@ F: include/linux/acpi.h F: include/acpi/ F: Documentation/acpi/ F: Documentation/ABI/testing/sysfs-bus-acpi +F: Documentation/ABI/testing/configfs-acpi F: drivers/pci/*acpi* F: drivers/pci/*/*acpi* F: drivers/pci/*/*/*acpi* diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 0a8e41a52d09..b420e5dd8a56 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -524,4 +524,12 @@ config XPOWER_PMIC_OPREGION endif +config ACPI_CONFIGFS + tristate "ACPI configfs support" + select CONFIGFS_FS + help + Select this option to enable support for ACPI configuration from + userspace. The configurable ACPI groups will be visible under + /config/acpi, assuming configfs is mounted under /config. + endif # ACPI diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 251ce85a66fb..1dc2173ad8d0 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -99,5 +99,6 @@ obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o obj-$(CONFIG_PMIC_OPREGION) += pmic/intel_pmic.o obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o +obj-$(CONFIG_ACPI_CONFIGFS) += configfs.o video-objs += acpi_video.o video_detect.o diff --git a/drivers/acpi/configfs.c b/drivers/acpi/configfs.c new file mode 100644 index 000000000000..44b463f6fca5 --- /dev/null +++ b/drivers/acpi/configfs.c @@ -0,0 +1,53 @@ +/* + * ACPI configfs support + * + * Copyright (c) 2016 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include +#include +#include +#include + +static struct config_item_type acpi_root_group_type = { + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem acpi_configfs = { + .su_group = { + .cg_item = { + .ci_namebuf = "acpi", + .ci_type = &acpi_root_group_type, + }, + }, + .su_mutex = __MUTEX_INITIALIZER(acpi_configfs.su_mutex), +}; + +static int __init acpi_configfs_init(void) +{ + int ret; + struct config_group *root = &acpi_configfs.su_group; + + config_group_init(root); + + ret = configfs_register_subsystem(&acpi_configfs); + if (ret) + return ret; + + return 0; +} +module_init(acpi_configfs_init); + +static void __exit acpi_configfs_exit(void) +{ + configfs_unregister_subsystem(&acpi_configfs); +} +module_exit(acpi_configfs_exit); + +MODULE_AUTHOR("Octavian Purdila "); +MODULE_DESCRIPTION("ACPI configfs support"); +MODULE_LICENSE("GPL v2"); -- cgit v1.2.3 From 612bd01fc6e04c3ce9eb59587b4a7e4ebd6aff35 Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Fri, 8 Jul 2016 19:13:14 +0300 Subject: ACPI: add support for loading SSDTs via configfs New tables can be loaded by creating directories under /config/table/ and writing the AML code into the aml table attribute. Various table attributes will be readable once the table is successfully loaded. Unloading tables is not supported at the moment, but it can be easily implemented once ACPI loading functions provide a table handle to be used for unloading. Signed-off-by: Octavian Purdila Reviewed-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki --- Documentation/ABI/testing/configfs-acpi | 29 +++++ Documentation/acpi/ssdt-overlays.txt | 14 +++ drivers/acpi/configfs.c | 216 +++++++++++++++++++++++++++++++- 3 files changed, 258 insertions(+), 1 deletion(-) (limited to 'drivers/acpi') diff --git a/Documentation/ABI/testing/configfs-acpi b/Documentation/ABI/testing/configfs-acpi index 17b19dc2822d..4ab4e99aa863 100644 --- a/Documentation/ABI/testing/configfs-acpi +++ b/Documentation/ABI/testing/configfs-acpi @@ -5,3 +5,32 @@ Contact: linux-acpi@vger.kernel.org Description: This represents the ACPI subsystem entry point directory. It contains sub-groups corresponding to ACPI configurable options. + +What: /config/acpi/table +Date: July 2016 +KernelVersion: 4.8 +Description: + + This group contains the configuration for user defined ACPI + tables. The attributes of a user define table are: + + aml - a binary attribute that the user can use to + fill in the ACPI aml definitions. Once the aml + data is written to this file and the file is + closed the table will be loaded and ACPI devices + will be enumerated. To check if the operation is + successful the user must check the error code + for close(). If the operation is successful, + subsequent writes to this attribute will fail. + + The rest of the attributes are read-only and are valid only + after the table has been loaded by filling the aml entry: + + signature - ASCII table signature + length - length of table in bytes, including the header + revision - ACPI Specification minor version number + oem_id - ASCII OEM identification + oem_table_id - ASCII OEM table identification + oem_revision - OEM revision number + asl_compiler_id - ASCII ASL compiler vendor ID + asl_compiler_revision - ASL compiler version diff --git a/Documentation/acpi/ssdt-overlays.txt b/Documentation/acpi/ssdt-overlays.txt index c4b57badd0b7..5ae13f161ea2 100644 --- a/Documentation/acpi/ssdt-overlays.txt +++ b/Documentation/acpi/ssdt-overlays.txt @@ -156,3 +156,17 @@ tmp=$(mktemp) /bin/echo -ne "\007\000\000\000" | cat - $filename > $tmp dd if=$tmp of="$EFIVARFS/$name-$guid" bs=$(stat -c %s $tmp) rm $tmp + +== Loading ACPI SSDTs from configfs == + +This option allows loading of user defined SSDTs from userspace via the configfs +interface. The CONFIG_ACPI_CONFIGFS option must be select and configfs must be +mounted. In the following examples, we assume that configfs has been mounted in +/config. + +New tables can be loading by creating new directories in /config/acpi/table/ and +writing the SSDT aml code in the aml attribute: + +cd /config/acpi/table +mkdir my_ssdt +cat ~/ssdt.aml > my_ssdt/aml diff --git a/drivers/acpi/configfs.c b/drivers/acpi/configfs.c index 44b463f6fca5..146a77fb762d 100644 --- a/drivers/acpi/configfs.c +++ b/drivers/acpi/configfs.c @@ -8,11 +8,222 @@ * the Free Software Foundation. */ +#define pr_fmt(fmt) "ACPI configfs: " fmt + #include #include #include #include +static struct config_group *acpi_table_group; + +struct acpi_table { + struct config_item cfg; + struct acpi_table_header *header; +}; + +static ssize_t acpi_table_aml_write(struct config_item *cfg, + const void *data, size_t size) +{ + const struct acpi_table_header *header = data; + struct acpi_table *table; + int ret; + + table = container_of(cfg, struct acpi_table, cfg); + + if (table->header) { + pr_err("table already loaded\n"); + return -EBUSY; + } + + if (header->length != size) { + pr_err("invalid table length\n"); + return -EINVAL; + } + + if (memcmp(header->signature, ACPI_SIG_SSDT, 4)) { + pr_err("invalid table signature\n"); + return -EINVAL; + } + + table = container_of(cfg, struct acpi_table, cfg); + + table->header = kmemdup(header, header->length, GFP_KERNEL); + if (!table->header) + return -ENOMEM; + + ret = acpi_load_table(table->header); + if (ret) { + kfree(table->header); + table->header = NULL; + } + + return ret; +} + +static inline struct acpi_table_header *get_header(struct config_item *cfg) +{ + struct acpi_table *table = container_of(cfg, struct acpi_table, cfg); + + if (!table->header) + pr_err("table not loaded\n"); + + return table->header; +} + +static ssize_t acpi_table_aml_read(struct config_item *cfg, + void *data, size_t size) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + if (data) + memcpy(data, h, h->length); + + return h->length; +} + +#define MAX_ACPI_TABLE_SIZE (128 * 1024) + +CONFIGFS_BIN_ATTR(acpi_table_, aml, NULL, MAX_ACPI_TABLE_SIZE); + +struct configfs_bin_attribute *acpi_table_bin_attrs[] = { + &acpi_table_attr_aml, + NULL, +}; + +ssize_t acpi_table_signature_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%.*s\n", ACPI_NAME_SIZE, h->signature); +} + +ssize_t acpi_table_length_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%d\n", h->length); +} + +ssize_t acpi_table_revision_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%d\n", h->revision); +} + +ssize_t acpi_table_oem_id_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%.*s\n", ACPI_OEM_ID_SIZE, h->oem_id); +} + +ssize_t acpi_table_oem_table_id_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE, h->oem_table_id); +} + +ssize_t acpi_table_oem_revision_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%d\n", h->oem_revision); +} + +ssize_t acpi_table_asl_compiler_id_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%.*s\n", ACPI_NAME_SIZE, h->asl_compiler_id); +} + +ssize_t acpi_table_asl_compiler_revision_show(struct config_item *cfg, + char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%d\n", h->asl_compiler_revision); +} + +CONFIGFS_ATTR_RO(acpi_table_, signature); +CONFIGFS_ATTR_RO(acpi_table_, length); +CONFIGFS_ATTR_RO(acpi_table_, revision); +CONFIGFS_ATTR_RO(acpi_table_, oem_id); +CONFIGFS_ATTR_RO(acpi_table_, oem_table_id); +CONFIGFS_ATTR_RO(acpi_table_, oem_revision); +CONFIGFS_ATTR_RO(acpi_table_, asl_compiler_id); +CONFIGFS_ATTR_RO(acpi_table_, asl_compiler_revision); + +struct configfs_attribute *acpi_table_attrs[] = { + &acpi_table_attr_signature, + &acpi_table_attr_length, + &acpi_table_attr_revision, + &acpi_table_attr_oem_id, + &acpi_table_attr_oem_table_id, + &acpi_table_attr_oem_revision, + &acpi_table_attr_asl_compiler_id, + &acpi_table_attr_asl_compiler_revision, + NULL, +}; + +static struct config_item_type acpi_table_type = { + .ct_owner = THIS_MODULE, + .ct_bin_attrs = acpi_table_bin_attrs, + .ct_attrs = acpi_table_attrs, +}; + +static struct config_item *acpi_table_make_item(struct config_group *group, + const char *name) +{ + struct acpi_table *table; + + table = kzalloc(sizeof(*table), GFP_KERNEL); + if (!table) + return ERR_PTR(-ENOMEM); + + config_item_init_type_name(&table->cfg, name, &acpi_table_type); + return &table->cfg; +} + +struct configfs_group_operations acpi_table_group_ops = { + .make_item = acpi_table_make_item, +}; + +static struct config_item_type acpi_tables_type = { + .ct_owner = THIS_MODULE, + .ct_group_ops = &acpi_table_group_ops, +}; + static struct config_item_type acpi_root_group_type = { .ct_owner = THIS_MODULE, }; @@ -38,12 +249,15 @@ static int __init acpi_configfs_init(void) if (ret) return ret; - return 0; + acpi_table_group = configfs_register_default_group(root, "table", + &acpi_tables_type); + return PTR_ERR_OR_ZERO(acpi_table_group); } module_init(acpi_configfs_init); static void __exit acpi_configfs_exit(void) { + configfs_unregister_default_group(acpi_table_group); configfs_unregister_subsystem(&acpi_configfs); } module_exit(acpi_configfs_exit); -- cgit v1.2.3 From fafe5306f201ae3ad3f81f62d203c86952444e12 Mon Sep 17 00:00:00 2001 From: Mika Westerberg Date: Mon, 11 Jul 2016 15:13:36 +0200 Subject: ACPI: Rename configfs.c to acpi_configfs.c to prevent link error If we compile ACPI configfs.c as module it will confuse the linker as it hides symbols from the actual configfs: Kernel: arch/x86/boot/bzImage is ready (#1236) MODPOST 5739 modules ERROR: "configfs_unregister_subsystem" [samples/configfs/configfs_sample.ko] undefined! ERROR: "configfs_register_subsystem" [samples/configfs/configfs_sample.ko] undefined! ERROR: "config_group_init" [samples/configfs/configfs_sample.ko] undefined! ERROR: "config_item_init_type_name" [samples/configfs/configfs_sample.ko] undefined! ERROR: "config_group_init_type_name" [samples/configfs/configfs_sample.ko] undefined! ERROR: "configfs_undepend_item" [fs/ocfs2/cluster/ocfs2_nodemanager.ko] undefined! ... Prevent these by renaming the file to acpi_configfs.c instead. Reported-by: Scott Lawson Signed-off-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki --- drivers/acpi/Makefile | 2 +- drivers/acpi/acpi_configfs.c | 267 +++++++++++++++++++++++++++++++++++++++++++ drivers/acpi/configfs.c | 267 ------------------------------------------- 3 files changed, 268 insertions(+), 268 deletions(-) create mode 100644 drivers/acpi/acpi_configfs.c delete mode 100644 drivers/acpi/configfs.c (limited to 'drivers/acpi') diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 1dc2173ad8d0..f72a83df1cf3 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -99,6 +99,6 @@ obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o obj-$(CONFIG_PMIC_OPREGION) += pmic/intel_pmic.o obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o -obj-$(CONFIG_ACPI_CONFIGFS) += configfs.o +obj-$(CONFIG_ACPI_CONFIGFS) += acpi_configfs.o video-objs += acpi_video.o video_detect.o diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c new file mode 100644 index 000000000000..146a77fb762d --- /dev/null +++ b/drivers/acpi/acpi_configfs.c @@ -0,0 +1,267 @@ +/* + * ACPI configfs support + * + * Copyright (c) 2016 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#define pr_fmt(fmt) "ACPI configfs: " fmt + +#include +#include +#include +#include + +static struct config_group *acpi_table_group; + +struct acpi_table { + struct config_item cfg; + struct acpi_table_header *header; +}; + +static ssize_t acpi_table_aml_write(struct config_item *cfg, + const void *data, size_t size) +{ + const struct acpi_table_header *header = data; + struct acpi_table *table; + int ret; + + table = container_of(cfg, struct acpi_table, cfg); + + if (table->header) { + pr_err("table already loaded\n"); + return -EBUSY; + } + + if (header->length != size) { + pr_err("invalid table length\n"); + return -EINVAL; + } + + if (memcmp(header->signature, ACPI_SIG_SSDT, 4)) { + pr_err("invalid table signature\n"); + return -EINVAL; + } + + table = container_of(cfg, struct acpi_table, cfg); + + table->header = kmemdup(header, header->length, GFP_KERNEL); + if (!table->header) + return -ENOMEM; + + ret = acpi_load_table(table->header); + if (ret) { + kfree(table->header); + table->header = NULL; + } + + return ret; +} + +static inline struct acpi_table_header *get_header(struct config_item *cfg) +{ + struct acpi_table *table = container_of(cfg, struct acpi_table, cfg); + + if (!table->header) + pr_err("table not loaded\n"); + + return table->header; +} + +static ssize_t acpi_table_aml_read(struct config_item *cfg, + void *data, size_t size) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + if (data) + memcpy(data, h, h->length); + + return h->length; +} + +#define MAX_ACPI_TABLE_SIZE (128 * 1024) + +CONFIGFS_BIN_ATTR(acpi_table_, aml, NULL, MAX_ACPI_TABLE_SIZE); + +struct configfs_bin_attribute *acpi_table_bin_attrs[] = { + &acpi_table_attr_aml, + NULL, +}; + +ssize_t acpi_table_signature_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%.*s\n", ACPI_NAME_SIZE, h->signature); +} + +ssize_t acpi_table_length_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%d\n", h->length); +} + +ssize_t acpi_table_revision_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%d\n", h->revision); +} + +ssize_t acpi_table_oem_id_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%.*s\n", ACPI_OEM_ID_SIZE, h->oem_id); +} + +ssize_t acpi_table_oem_table_id_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE, h->oem_table_id); +} + +ssize_t acpi_table_oem_revision_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%d\n", h->oem_revision); +} + +ssize_t acpi_table_asl_compiler_id_show(struct config_item *cfg, char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%.*s\n", ACPI_NAME_SIZE, h->asl_compiler_id); +} + +ssize_t acpi_table_asl_compiler_revision_show(struct config_item *cfg, + char *str) +{ + struct acpi_table_header *h = get_header(cfg); + + if (!h) + return -EINVAL; + + return sprintf(str, "%d\n", h->asl_compiler_revision); +} + +CONFIGFS_ATTR_RO(acpi_table_, signature); +CONFIGFS_ATTR_RO(acpi_table_, length); +CONFIGFS_ATTR_RO(acpi_table_, revision); +CONFIGFS_ATTR_RO(acpi_table_, oem_id); +CONFIGFS_ATTR_RO(acpi_table_, oem_table_id); +CONFIGFS_ATTR_RO(acpi_table_, oem_revision); +CONFIGFS_ATTR_RO(acpi_table_, asl_compiler_id); +CONFIGFS_ATTR_RO(acpi_table_, asl_compiler_revision); + +struct configfs_attribute *acpi_table_attrs[] = { + &acpi_table_attr_signature, + &acpi_table_attr_length, + &acpi_table_attr_revision, + &acpi_table_attr_oem_id, + &acpi_table_attr_oem_table_id, + &acpi_table_attr_oem_revision, + &acpi_table_attr_asl_compiler_id, + &acpi_table_attr_asl_compiler_revision, + NULL, +}; + +static struct config_item_type acpi_table_type = { + .ct_owner = THIS_MODULE, + .ct_bin_attrs = acpi_table_bin_attrs, + .ct_attrs = acpi_table_attrs, +}; + +static struct config_item *acpi_table_make_item(struct config_group *group, + const char *name) +{ + struct acpi_table *table; + + table = kzalloc(sizeof(*table), GFP_KERNEL); + if (!table) + return ERR_PTR(-ENOMEM); + + config_item_init_type_name(&table->cfg, name, &acpi_table_type); + return &table->cfg; +} + +struct configfs_group_operations acpi_table_group_ops = { + .make_item = acpi_table_make_item, +}; + +static struct config_item_type acpi_tables_type = { + .ct_owner = THIS_MODULE, + .ct_group_ops = &acpi_table_group_ops, +}; + +static struct config_item_type acpi_root_group_type = { + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem acpi_configfs = { + .su_group = { + .cg_item = { + .ci_namebuf = "acpi", + .ci_type = &acpi_root_group_type, + }, + }, + .su_mutex = __MUTEX_INITIALIZER(acpi_configfs.su_mutex), +}; + +static int __init acpi_configfs_init(void) +{ + int ret; + struct config_group *root = &acpi_configfs.su_group; + + config_group_init(root); + + ret = configfs_register_subsystem(&acpi_configfs); + if (ret) + return ret; + + acpi_table_group = configfs_register_default_group(root, "table", + &acpi_tables_type); + return PTR_ERR_OR_ZERO(acpi_table_group); +} +module_init(acpi_configfs_init); + +static void __exit acpi_configfs_exit(void) +{ + configfs_unregister_default_group(acpi_table_group); + configfs_unregister_subsystem(&acpi_configfs); +} +module_exit(acpi_configfs_exit); + +MODULE_AUTHOR("Octavian Purdila "); +MODULE_DESCRIPTION("ACPI configfs support"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/acpi/configfs.c b/drivers/acpi/configfs.c deleted file mode 100644 index 146a77fb762d..000000000000 --- a/drivers/acpi/configfs.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * ACPI configfs support - * - * Copyright (c) 2016 Intel Corporation - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published by - * the Free Software Foundation. - */ - -#define pr_fmt(fmt) "ACPI configfs: " fmt - -#include -#include -#include -#include - -static struct config_group *acpi_table_group; - -struct acpi_table { - struct config_item cfg; - struct acpi_table_header *header; -}; - -static ssize_t acpi_table_aml_write(struct config_item *cfg, - const void *data, size_t size) -{ - const struct acpi_table_header *header = data; - struct acpi_table *table; - int ret; - - table = container_of(cfg, struct acpi_table, cfg); - - if (table->header) { - pr_err("table already loaded\n"); - return -EBUSY; - } - - if (header->length != size) { - pr_err("invalid table length\n"); - return -EINVAL; - } - - if (memcmp(header->signature, ACPI_SIG_SSDT, 4)) { - pr_err("invalid table signature\n"); - return -EINVAL; - } - - table = container_of(cfg, struct acpi_table, cfg); - - table->header = kmemdup(header, header->length, GFP_KERNEL); - if (!table->header) - return -ENOMEM; - - ret = acpi_load_table(table->header); - if (ret) { - kfree(table->header); - table->header = NULL; - } - - return ret; -} - -static inline struct acpi_table_header *get_header(struct config_item *cfg) -{ - struct acpi_table *table = container_of(cfg, struct acpi_table, cfg); - - if (!table->header) - pr_err("table not loaded\n"); - - return table->header; -} - -static ssize_t acpi_table_aml_read(struct config_item *cfg, - void *data, size_t size) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - if (data) - memcpy(data, h, h->length); - - return h->length; -} - -#define MAX_ACPI_TABLE_SIZE (128 * 1024) - -CONFIGFS_BIN_ATTR(acpi_table_, aml, NULL, MAX_ACPI_TABLE_SIZE); - -struct configfs_bin_attribute *acpi_table_bin_attrs[] = { - &acpi_table_attr_aml, - NULL, -}; - -ssize_t acpi_table_signature_show(struct config_item *cfg, char *str) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - return sprintf(str, "%.*s\n", ACPI_NAME_SIZE, h->signature); -} - -ssize_t acpi_table_length_show(struct config_item *cfg, char *str) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - return sprintf(str, "%d\n", h->length); -} - -ssize_t acpi_table_revision_show(struct config_item *cfg, char *str) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - return sprintf(str, "%d\n", h->revision); -} - -ssize_t acpi_table_oem_id_show(struct config_item *cfg, char *str) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - return sprintf(str, "%.*s\n", ACPI_OEM_ID_SIZE, h->oem_id); -} - -ssize_t acpi_table_oem_table_id_show(struct config_item *cfg, char *str) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - return sprintf(str, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE, h->oem_table_id); -} - -ssize_t acpi_table_oem_revision_show(struct config_item *cfg, char *str) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - return sprintf(str, "%d\n", h->oem_revision); -} - -ssize_t acpi_table_asl_compiler_id_show(struct config_item *cfg, char *str) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - return sprintf(str, "%.*s\n", ACPI_NAME_SIZE, h->asl_compiler_id); -} - -ssize_t acpi_table_asl_compiler_revision_show(struct config_item *cfg, - char *str) -{ - struct acpi_table_header *h = get_header(cfg); - - if (!h) - return -EINVAL; - - return sprintf(str, "%d\n", h->asl_compiler_revision); -} - -CONFIGFS_ATTR_RO(acpi_table_, signature); -CONFIGFS_ATTR_RO(acpi_table_, length); -CONFIGFS_ATTR_RO(acpi_table_, revision); -CONFIGFS_ATTR_RO(acpi_table_, oem_id); -CONFIGFS_ATTR_RO(acpi_table_, oem_table_id); -CONFIGFS_ATTR_RO(acpi_table_, oem_revision); -CONFIGFS_ATTR_RO(acpi_table_, asl_compiler_id); -CONFIGFS_ATTR_RO(acpi_table_, asl_compiler_revision); - -struct configfs_attribute *acpi_table_attrs[] = { - &acpi_table_attr_signature, - &acpi_table_attr_length, - &acpi_table_attr_revision, - &acpi_table_attr_oem_id, - &acpi_table_attr_oem_table_id, - &acpi_table_attr_oem_revision, - &acpi_table_attr_asl_compiler_id, - &acpi_table_attr_asl_compiler_revision, - NULL, -}; - -static struct config_item_type acpi_table_type = { - .ct_owner = THIS_MODULE, - .ct_bin_attrs = acpi_table_bin_attrs, - .ct_attrs = acpi_table_attrs, -}; - -static struct config_item *acpi_table_make_item(struct config_group *group, - const char *name) -{ - struct acpi_table *table; - - table = kzalloc(sizeof(*table), GFP_KERNEL); - if (!table) - return ERR_PTR(-ENOMEM); - - config_item_init_type_name(&table->cfg, name, &acpi_table_type); - return &table->cfg; -} - -struct configfs_group_operations acpi_table_group_ops = { - .make_item = acpi_table_make_item, -}; - -static struct config_item_type acpi_tables_type = { - .ct_owner = THIS_MODULE, - .ct_group_ops = &acpi_table_group_ops, -}; - -static struct config_item_type acpi_root_group_type = { - .ct_owner = THIS_MODULE, -}; - -static struct configfs_subsystem acpi_configfs = { - .su_group = { - .cg_item = { - .ci_namebuf = "acpi", - .ci_type = &acpi_root_group_type, - }, - }, - .su_mutex = __MUTEX_INITIALIZER(acpi_configfs.su_mutex), -}; - -static int __init acpi_configfs_init(void) -{ - int ret; - struct config_group *root = &acpi_configfs.su_group; - - config_group_init(root); - - ret = configfs_register_subsystem(&acpi_configfs); - if (ret) - return ret; - - acpi_table_group = configfs_register_default_group(root, "table", - &acpi_tables_type); - return PTR_ERR_OR_ZERO(acpi_table_group); -} -module_init(acpi_configfs_init); - -static void __exit acpi_configfs_exit(void) -{ - configfs_unregister_default_group(acpi_table_group); - configfs_unregister_subsystem(&acpi_configfs); -} -module_exit(acpi_configfs_exit); - -MODULE_AUTHOR("Octavian Purdila "); -MODULE_DESCRIPTION("ACPI configfs support"); -MODULE_LICENSE("GPL v2"); -- cgit v1.2.3