acpi/x86: introduce __apci_map_table, v4
authorYinghai Lu <yhlu.kernel@gmail.com>
Sat, 7 Feb 2009 23:39:41 +0000 (15:39 -0800)
committerIngo Molnar <mingo@elte.hu>
Mon, 9 Feb 2009 12:35:07 +0000 (13:35 +0100)
to prevent wrongly overwriting fixmap that still want to use.

ACPI used to rely on low mappings being all linearly mapped and
grew a habit: it never really unmapped certain kinds of tables
after use.

This can cause problems - for example the hypothetical case
when some spurious access still references it.

v2: remove prev_map and prev_size in __apci_map_table
v3: let acpi_os_unmap_memory() call early_iounmap too, so remove extral calling to
early_acpi_os_unmap_memory
v4: fix typo in one acpi_get_table_with_size calling

Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com>
Acked-by: Len Brown <len.brown@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/ia64/kernel/acpi.c
arch/x86/kernel/acpi/boot.c
drivers/acpi/acpica/tbxface.c
drivers/acpi/bus.c
drivers/acpi/osl.c
drivers/acpi/tables.c
include/acpi/acpiosxf.h
include/acpi/acpixf.h
include/linux/acpi.h

index d541671caf4a8d7e655ce5b9e811b25c8dd4777b..2363ed173198a2dcc52c5764f9dc1542c13dcb2e 100644 (file)
@@ -199,6 +199,10 @@ char *__init __acpi_map_table(unsigned long phys_addr, unsigned long size)
        return __va(phys_addr);
 }
 
+char *__init __acpi_unmap_table(unsigned long virt_addr, unsigned long size)
+{
+}
+
 /* --------------------------------------------------------------------------
                             Boot-time Table Parsing
    -------------------------------------------------------------------------- */
index 7217834f6b1dbc37d0f725059086cad01f612c80..4c2aaea42930e3fdd4ab755c1fec5f02cf1a8245 100644 (file)
@@ -121,21 +121,18 @@ enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
  */
 char *__init __acpi_map_table(unsigned long phys, unsigned long size)
 {
-       static char *prev_map;
-       static unsigned long prev_size;
-
-       if (prev_map) {
-               early_iounmap(prev_map, prev_size);
-               prev_map = NULL;
-       }
 
        if (!phys || !size)
                return NULL;
 
-       prev_size = size;
-       prev_map = early_ioremap(phys, size);
+       return early_ioremap(phys, size);
+}
+void __init __acpi_unmap_table(char *map, unsigned long size)
+{
+       if (!map || !size)
+               return;
 
-       return prev_map;
+       early_iounmap(map, size);
 }
 
 #ifdef CONFIG_PCI_MMCONFIG
index c3e841f3cde924239ce34f94a75818cfc194a211..ab0aff3c7d6a3672bd7dd778853a77108e111528 100644 (file)
@@ -365,7 +365,7 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_get_table
+ * FUNCTION:    acpi_get_table_with_size
  *
  * PARAMETERS:  Signature           - ACPI signature of needed table
  *              Instance            - Which instance (for SSDTs)
@@ -377,8 +377,9 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
  *
  *****************************************************************************/
 acpi_status
-acpi_get_table(char *signature,
-              u32 instance, struct acpi_table_header **out_table)
+acpi_get_table_with_size(char *signature,
+              u32 instance, struct acpi_table_header **out_table,
+              acpi_size *tbl_size)
 {
        u32 i;
        u32 j;
@@ -408,6 +409,7 @@ acpi_get_table(char *signature,
                    acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]);
                if (ACPI_SUCCESS(status)) {
                        *out_table = acpi_gbl_root_table_list.tables[i].pointer;
+                       *tbl_size = acpi_gbl_root_table_list.tables[i].length;
                }
 
                if (!acpi_gbl_permanent_mmap) {
@@ -420,6 +422,15 @@ acpi_get_table(char *signature,
        return (AE_NOT_FOUND);
 }
 
+acpi_status
+acpi_get_table(char *signature,
+              u32 instance, struct acpi_table_header **out_table)
+{
+       acpi_size tbl_size;
+
+       return acpi_get_table_with_size(signature,
+                      instance, out_table, &tbl_size);
+}
 ACPI_EXPORT_SYMBOL(acpi_get_table)
 
 /*******************************************************************************
index fb1be7b5dbc1077f3bbc206803a467dbb36bb5ea..765fd1c56cd66bc445ab5228f562177b9eb469e1 100644 (file)
@@ -694,12 +694,6 @@ void __init acpi_early_init(void)
        if (!acpi_strict)
                acpi_gbl_enable_interpreter_slack = TRUE;
 
-       /*
-        * Doing a zero-sized mapping will clear out the previous
-        * __acpi_map_table() mapping, if any.
-        */
-       __acpi_map_table(0, 0);
-
        acpi_gbl_permanent_mmap = 1;
 
        status = acpi_reallocate_root_table();
index b3193ec0a2ef36eae859111a525a1d5931590b78..d1dd5160daa9095239adadeee1140c701a819e8e 100644 (file)
@@ -274,12 +274,19 @@ EXPORT_SYMBOL_GPL(acpi_os_map_memory);
 
 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
 {
-       if (acpi_gbl_permanent_mmap) {
+       if (acpi_gbl_permanent_mmap)
                iounmap(virt);
-       }
+       else
+               __acpi_unmap_table(virt, size);
 }
 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
 
+void early_acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
+{
+       if (!acpi_gbl_permanent_mmap)
+               __acpi_unmap_table(virt, size);
+}
+
 #ifdef ACPI_FUTURE_USAGE
 acpi_status
 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
index a8852952fac409de6550b467d5d49b4f7e5ace07..fec1ae36d4310cadca89ff36c2e3174480c765dc 100644 (file)
@@ -181,14 +181,15 @@ acpi_table_parse_entries(char *id,
        struct acpi_subtable_header *entry;
        unsigned int count = 0;
        unsigned long table_end;
+       acpi_size tbl_size;
 
        if (!handler)
                return -EINVAL;
 
        if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
-               acpi_get_table(id, acpi_apic_instance, &table_header);
+               acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
        else
-               acpi_get_table(id, 0, &table_header);
+               acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
 
        if (!table_header) {
                printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
@@ -206,8 +207,10 @@ acpi_table_parse_entries(char *id,
               table_end) {
                if (entry->type == entry_id
                    && (!max_entries || count++ < max_entries))
-                       if (handler(entry, table_end))
+                       if (handler(entry, table_end)) {
+                               early_acpi_os_unmap_memory((char *)table_header, tbl_size);
                                return -EINVAL;
+                       }
 
                entry = (struct acpi_subtable_header *)
                    ((unsigned long)entry + entry->length);
@@ -217,6 +220,7 @@ acpi_table_parse_entries(char *id,
                       "%i found\n", id, entry_id, count - max_entries, count);
        }
 
+       early_acpi_os_unmap_memory((char *)table_header, tbl_size);
        return count;
 }
 
@@ -241,17 +245,19 @@ acpi_table_parse_madt(enum acpi_madt_type id,
 int __init acpi_table_parse(char *id, acpi_table_handler handler)
 {
        struct acpi_table_header *table = NULL;
+       acpi_size tbl_size;
 
        if (!handler)
                return -EINVAL;
 
        if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
-               acpi_get_table(id, acpi_apic_instance, &table);
+               acpi_get_table_with_size(id, acpi_apic_instance, &table, &tbl_size);
        else
-               acpi_get_table(id, 0, &table);
+               acpi_get_table_with_size(id, 0, &table, &tbl_size);
 
        if (table) {
                handler(table);
+               early_acpi_os_unmap_memory(table, tbl_size);
                return 0;
        } else
                return 1;
@@ -265,8 +271,9 @@ int __init acpi_table_parse(char *id, acpi_table_handler handler)
 static void __init check_multiple_madt(void)
 {
        struct acpi_table_header *table = NULL;
+       acpi_size tbl_size;
 
-       acpi_get_table(ACPI_SIG_MADT, 2, &table);
+       acpi_get_table_with_size(ACPI_SIG_MADT, 2, &table, &tbl_size);
        if (table) {
                printk(KERN_WARNING PREFIX
                       "BIOS bug: multiple APIC/MADT found,"
@@ -275,6 +282,7 @@ static void __init check_multiple_madt(void)
                       "If \"acpi_apic_instance=%d\" works better, "
                       "notify linux-acpi@vger.kernel.org\n",
                       acpi_apic_instance ? 0 : 2);
+               early_acpi_os_unmap_memory(table, tbl_size);
 
        } else
                acpi_apic_instance = 0;
index a62720a7edc0165b7b698a5d7a2d14841a78f27f..ab0b85cf21f38df08b0eb3a3b752b42e2453d8fa 100644 (file)
@@ -144,6 +144,7 @@ void __iomem *acpi_os_map_memory(acpi_physical_address where,
                                acpi_size length);
 
 void acpi_os_unmap_memory(void __iomem * logical_address, acpi_size size);
+void early_acpi_os_unmap_memory(void __iomem * virt, acpi_size size);
 
 #ifdef ACPI_FUTURE_USAGE
 acpi_status
index c8e8cf45830f6c5203f5d7e13f1531ff949d34ce..cc40102fe2f3568f262a23862da91010eddde864 100644 (file)
@@ -130,6 +130,10 @@ acpi_get_table_header(acpi_string signature,
                      struct acpi_table_header *out_table_header);
 
 acpi_status
+acpi_get_table_with_size(acpi_string signature,
+              u32 instance, struct acpi_table_header **out_table,
+              acpi_size *tbl_size);
+acpi_status
 acpi_get_table(acpi_string signature,
               u32 instance, struct acpi_table_header **out_table);
 
index 6fce2fc2d124bc184da9f10f40e31ed97254a7f5..d59f0fa4d77227828a43cd59c5a6d00a7b9161dc 100644 (file)
@@ -79,6 +79,7 @@ typedef int (*acpi_table_handler) (struct acpi_table_header *table);
 typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, const unsigned long end);
 
 char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
+void __init __acpi_unmap_table(char *map, unsigned long size);
 int early_acpi_boot_init(void);
 int acpi_boot_init (void);
 int acpi_boot_table_init (void);