From 174cc7187e6f088942c8e74daa7baff7b44b33c9 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Wed, 14 Dec 2016 15:04:25 +0800 Subject: ACPICA: Tables: Back port acpi_get_table_with_size() and early_acpi_os_unmap_memory() from Linux kernel ACPICA commit cac6790954d4d752a083e6122220b8a22febcd07 This patch back ports Linux acpi_get_table_with_size() and early_acpi_os_unmap_memory() into ACPICA upstream to reduce divergences. The 2 APIs are used by Linux as table management APIs for long time, it contains a hidden logic that during the early stage, the mapped tables should be unmapped before the early stage ends. During the early stage, tables are handled by the following sequence: acpi_get_table_with_size(); parse the table early_acpi_os_unmap_memory(); During the late stage, tables are handled by the following sequence: acpi_get_table(); parse the table Linux uses acpi_gbl_permanent_mmap to distinguish the early stage and the late stage. The reasoning of introducing acpi_get_table_with_size() is: ACPICA will remember the early mapped pointer in acpi_get_table() and Linux isn't able to prevent ACPICA from using the wrong early mapped pointer during the late stage as there is no API provided from ACPICA to be an inverse of acpi_get_table() to forget the early mapped pointer. But how ACPICA can work with the early/late stage requirement? Inside of ACPICA, tables are ensured to be remained in "INSTALLED" state during the early stage, and they are carefully not transitioned to "VALIDATED" state until the late stage. So the same logic is in fact implemented inside of ACPICA in a different way. The gap is only that the feature is not provided to the OSPMs in an accessible external API style. It then is possible to fix the gap by providing an inverse of acpi_get_table() from ACPICA, so that the two Linux sequences can be combined: acpi_get_table(); parse the table acpi_put_table(); In order to work easier with the current Linux code, acpi_get_table() and acpi_put_table() is implemented in a usage counting based style: 1. When the usage count of the table is increased from 0 to 1, table is mapped and .Pointer is set with the mapping address (VALIDATED); 2. When the usage count of the table is decreased from 1 to 0, .Pointer is unset and the mapping address is unmapped (INVALIDATED). So that we can deploy the new APIs to Linux with minimal effort by just invoking acpi_get_table() in acpi_get_table_with_size() and invoking acpi_put_table() in early_acpi_os_unmap_memory(). Lv Zheng. Link: https://github.com/acpica/acpica/commit/cac67909 Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/osl.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'drivers/acpi/osl.c') diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 416953a42510..9316dfc19cea 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -433,10 +433,45 @@ void __ref acpi_os_unmap_memory(void *virt, acpi_size size) } EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); +/******************************************************************************* + * + * acpi_get_table_with_size()/early_acpi_os_unmap_memory(): + * + * These 2 functions are traditionally used by Linux to map/unmap physical + * addressed ACPI tables during the early stage. + * They are deprectated now. Do not use them in the new code, but use + * acpi_get_table()/acpi_put_table() instead. + * + ******************************************************************************/ +acpi_status +acpi_get_table_with_size(char *signature, + u32 instance, struct acpi_table_header **out_table, + acpi_size *tbl_size) +{ + acpi_status status; + + status = acpi_get_table(signature, instance, out_table); + if (ACPI_SUCCESS(status)) { + /* + * "tbl_size" is no longer used by + * early_acpi_os_unmap_memory(), but is still used by the + * ACPI table drivers. So sets it to the length of the + * table when the tbl_size is requested. + * "out_table" is not sanity checked as AE_BAD_PARAMETER + * is returned if it is NULL. + */ + if (tbl_size && *out_table) + *tbl_size = (*out_table)->length; + } + + return (status); +} + +ACPI_EXPORT_SYMBOL(acpi_get_table_with_size) + void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size) { - if (!acpi_gbl_permanent_mmap) - __acpi_unmap_table(virt, size); + acpi_put_table(ACPI_CAST_PTR(struct acpi_table_header, virt)); } int acpi_os_map_generic_address(struct acpi_generic_address *gas) -- cgit v1.2.3 From 8d3523fb3b727478ac528b307cb84460faa1c39e Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Wed, 14 Dec 2016 15:04:46 +0800 Subject: ACPI / osl: Remove deprecated acpi_get_table_with_size()/early_acpi_os_unmap_memory() Since all users are cleaned up, remove the 2 deprecated APIs due to no users. As a Linux variable rather than an ACPICA variable, acpi_gbl_permanent_mmap is renamed to acpi_permanent_mmap to have a consistent coding style across entire Linux ACPI subsystem. Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- arch/arm64/include/asm/acpi.h | 2 +- drivers/acpi/bus.c | 2 +- drivers/acpi/osl.c | 50 +++++-------------------------------------- include/acpi/acpi_io.h | 2 ++ include/acpi/acpixf.h | 13 ----------- 5 files changed, 9 insertions(+), 60 deletions(-) (limited to 'drivers/acpi/osl.c') diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index e517088d635f..8957ff8b3dd4 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -28,7 +28,7 @@ /* Basic configuration for ACPI */ #ifdef CONFIG_ACPI -/* ACPI table mapping after acpi_gbl_permanent_mmap is set */ +/* ACPI table mapping after acpi_permanent_mmap is set */ static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) { diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 56190d00fd87..77468be75b3c 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -964,7 +964,7 @@ void __init acpi_early_init(void) if (!acpi_strict) acpi_gbl_enable_interpreter_slack = TRUE; - acpi_gbl_permanent_mmap = 1; + acpi_permanent_mmap = true; /* * If the machine falls into the DMI check table, diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 9316dfc19cea..8a7cab06e271 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -76,6 +76,7 @@ static struct workqueue_struct *kacpi_notify_wq; static struct workqueue_struct *kacpi_hotplug_wq; static bool acpi_os_initialized; unsigned int acpi_sci_irq = INVALID_ACPI_IRQ; +bool acpi_permanent_mmap = false; /* * This list of permanent mappings is for memory that may be accessed from @@ -313,7 +314,7 @@ static void acpi_unmap(acpi_physical_address pg_off, void __iomem *vaddr) * virtual address). If not found, map it, add it to that list and return a * pointer to it. * - * During early init (when acpi_gbl_permanent_mmap has not been set yet) this + * During early init (when acpi_permanent_mmap has not been set yet) this * routine simply calls __acpi_map_table() to get the job done. */ void __iomem *__ref @@ -329,7 +330,7 @@ acpi_os_map_iomem(acpi_physical_address phys, acpi_size size) return NULL; } - if (!acpi_gbl_permanent_mmap) + if (!acpi_permanent_mmap) return __acpi_map_table((unsigned long)phys, size); mutex_lock(&acpi_ioremap_lock); @@ -399,7 +400,7 @@ static void acpi_os_map_cleanup(struct acpi_ioremap *map) * mappings, drop a reference to it and unmap it if there are no more active * references to it. * - * During early init (when acpi_gbl_permanent_mmap has not been set yet) this + * During early init (when acpi_permanent_mmap has not been set yet) this * routine simply calls __acpi_unmap_table() to get the job done. Since * __acpi_unmap_table() is an __init function, the __ref annotation is needed * here. @@ -408,7 +409,7 @@ void __ref acpi_os_unmap_iomem(void __iomem *virt, acpi_size size) { struct acpi_ioremap *map; - if (!acpi_gbl_permanent_mmap) { + if (!acpi_permanent_mmap) { __acpi_unmap_table(virt, size); return; } @@ -433,47 +434,6 @@ void __ref acpi_os_unmap_memory(void *virt, acpi_size size) } EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); -/******************************************************************************* - * - * acpi_get_table_with_size()/early_acpi_os_unmap_memory(): - * - * These 2 functions are traditionally used by Linux to map/unmap physical - * addressed ACPI tables during the early stage. - * They are deprectated now. Do not use them in the new code, but use - * acpi_get_table()/acpi_put_table() instead. - * - ******************************************************************************/ -acpi_status -acpi_get_table_with_size(char *signature, - u32 instance, struct acpi_table_header **out_table, - acpi_size *tbl_size) -{ - acpi_status status; - - status = acpi_get_table(signature, instance, out_table); - if (ACPI_SUCCESS(status)) { - /* - * "tbl_size" is no longer used by - * early_acpi_os_unmap_memory(), but is still used by the - * ACPI table drivers. So sets it to the length of the - * table when the tbl_size is requested. - * "out_table" is not sanity checked as AE_BAD_PARAMETER - * is returned if it is NULL. - */ - if (tbl_size && *out_table) - *tbl_size = (*out_table)->length; - } - - return (status); -} - -ACPI_EXPORT_SYMBOL(acpi_get_table_with_size) - -void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size) -{ - acpi_put_table(ACPI_CAST_PTR(struct acpi_table_header, virt)); -} - int acpi_os_map_generic_address(struct acpi_generic_address *gas) { u64 addr; diff --git a/include/acpi/acpi_io.h b/include/acpi/acpi_io.h index d7d0f495a34e..303315b9693f 100644 --- a/include/acpi/acpi_io.h +++ b/include/acpi/acpi_io.h @@ -13,6 +13,8 @@ static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys, } #endif +extern bool acpi_permanent_mmap; + void __iomem *__ref acpi_os_map_iomem(acpi_physical_address phys, acpi_size size); void __ref acpi_os_unmap_iomem(void __iomem *virt, acpi_size size); diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h index 33828dd97fc5..f5e10dd8e86b 100644 --- a/include/acpi/acpixf.h +++ b/include/acpi/acpixf.h @@ -967,19 +967,6 @@ void acpi_terminate_debugger(void); /* * Divergences */ -ACPI_GLOBAL(u8, acpi_gbl_permanent_mmap); - -ACPI_EXTERNAL_RETURN_STATUS(acpi_status - acpi_get_table_with_size(acpi_string signature, - u32 instance, - struct acpi_table_header - **out_table, - acpi_size *tbl_size)) - -ACPI_EXTERNAL_RETURN_VOID(void - early_acpi_os_unmap_memory(void __iomem * virt, - acpi_size size)) - ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_get_data_full(acpi_handle object, acpi_object_handler handler, -- cgit v1.2.3