acpi/x86: introduce __apci_map_table v2
PATCH 2/3 acpi/x86: introduce __apci_map_table v2
to prevent wrongly overwriting fixmap that still want to use.
v2: remove prev_map and prev_size in __apci_map_table
Signed-off-by Yinghai Lu <[email protected]>
---
--- arch/ia64/kernel/acpi.c | 4 ++++ arch/x86/kernel/acpi/boot.c | 17 +++++++---------- arch/x86/kernel/early-quirks.c | 4 +++- drivers/acpi/osl.c | 9 +++++++-- drivers/acpi/tables.c | 20 ++++++++++++++------ drivers/acpi/tables/tbfadt.c | 1 + drivers/acpi/tables/tbutils.c | 7 +++++++ drivers/acpi/tables/tbxface.c | 20 +++++++++++++++++--- drivers/acpi/tables/tbxfroot.c | 3 +++ include/acpi/acpiosxf.h | 1 + include/acpi/acpixf.h | 4 ++++ include/linux/acpi.h | 1 + 12 files changed, 69 insertions(+), 22 deletions(-)
arch/ia64/kernel/acpi.c +4 -0
@@ -176,6 +176,10 @@ char *__init __acpi_map_table(unsigned lreturn __va (phys_addr); } +char *__init __acpi_unmap_table (unsigned long virt_addr,unsigned long size) +{ +} +/* -------------------------------------------------------------------------- Boot-time Table Parsing -------------------------------------------------------------------------- */
arch/x86/kernel/acpi/boot.c +7 -10
@@ -121,21 +121,18 @@ enum acpi_irq_model_id acpi_irq_model =*/ 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
arch/x86/kernel/early-quirks.c +3 -1
@@ -100,11 +100,13 @@ static void __init intel_g33_dmar(int nu {struct acpi_table_header *dmar_tbl;acpi_status status; +acpi_size *tbl_size; - status =acpi_get_table (ACPI_SIG_DMAR ,0 , &dmar_tbl); + status =acpi_get_table_with_size (ACPI_SIG_DMAR ,0 , &dmar_tbl, &tbl_size);if (ACPI_SUCCESS (status)) {printk (KERN_INFO "BIOS BUG: DMAR advertised on Intel G31/G33 chipset -- ignoring\n" ); dmar_disabled =1 ; +early_acpi_os_unmap_memory (dmar_tbl, tbl_size); } }#endif
drivers/acpi/osl.c +7 -2
@@ -285,12 +285,17 @@ 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); - } }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)
drivers/acpi/tables.c +14 -6
@@ -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_typint __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, acstatic 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(v"If \"acpi_apic_instance=%d\" works better, " "notify [email protected]\n" , acpi_apic_instance ? 0 : 2); +early_acpi_os_unmap_memory (table, tbl_size); }else acpi_apic_instance =0 ;
drivers/acpi/tables/tbfadt.c +1 -0
@@ -189,6 +189,7 @@ void acpi_tb_parse_fadt(u32 table_index,/* All done with the real FADT, unmap it */ acpi_os_unmap_memory (table, length); +early_acpi_os_unmap_memory (table, length);/* Obtain the DSDT and FACS tables via their addresses within the FADT */
drivers/acpi/tables/tbutils.c +7 -0
@@ -82,6 +82,7 @@ acpi_tb_check_xsdt(acpi_physical_address length = table->length;acpi_os_unmap_memory (table,sizeof (struct acpi_table_header )); +early_acpi_os_unmap_memory (table,sizeof (struct acpi_table_header ));if (length <sizeof (struct acpi_table_header ))return AE_INVALID_TABLE_LENGTH ;
@@ -104,6 +105,7 @@ acpi_tb_check_xsdt(acpi_physical_address table_entry +=sizeof (u64); }acpi_os_unmap_memory (table, length); +early_acpi_os_unmap_memory (table, length);if (i < table_count)return AE_NULL_ENTRY ;
@@ -316,6 +318,7 @@ acpi_tb_install_table(acpi_physical_addr unmap_and_exit:acpi_os_unmap_memory (table,sizeof (struct acpi_table_header )); +early_acpi_os_unmap_memory (table,sizeof (struct acpi_table_header )); }/*******************************************************************************
@@ -442,6 +445,7 @@ acpi_tb_parse_root_table(acpi_physical_a* so unmap the RSDP here before mapping other tables */ acpi_os_unmap_memory (rsdp,sizeof (struct acpi_table_rsdp )); +early_acpi_os_unmap_memory (rsdp,sizeof (struct acpi_table_rsdp ));if (table_entry_size ==sizeof (u64)) {if (acpi_tb_check_xsdt (address) ==AE_NULL_ENTRY ) {
@@ -465,6 +469,7 @@ acpi_tb_parse_root_table(acpi_physical_a length = table->length;acpi_os_unmap_memory (table,sizeof (struct acpi_table_header )); +early_acpi_os_unmap_memory (table,sizeof (struct acpi_table_header ));if (length <sizeof (struct acpi_table_header )) { ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
@@ -482,6 +487,7 @@ acpi_tb_parse_root_table(acpi_physical_a status =acpi_tb_verify_checksum (table, length);if (ACPI_FAILURE (status)) {acpi_os_unmap_memory (table, length); +early_acpi_os_unmap_memory (table, length);return_ACPI_STATUS (status); }
@@ -535,6 +541,7 @@ acpi_tb_parse_root_table(acpi_physical_a* so unmap the root table here before mapping other tables */ acpi_os_unmap_memory (table, length); +early_acpi_os_unmap_memory (table, length);/* * Complete the initialization of the root table array by examining
drivers/acpi/tables/tbxface.c +17 -3
@@ -307,6 +307,9 @@ acpi_get_table_header(char *signature,acpi_os_unmap_memory (header,sizeof (struct acpi_table_header )); +early_acpi_os_unmap_memory (header, +sizeof (struct +acpi_table_header )); }else {return AE_NOT_FOUND ; }
@@ -364,7 +367,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)
@@ -376,8 +379,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;
@@ -407,6 +411,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) {
@@ -419,6 +424,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)/*******************************************************************************
drivers/acpi/tables/tbxfroot.c +3 -0
@@ -145,6 +145,7 @@ acpi_status acpi_find_root_pointer(acpi_ physical_address <<=4 ;acpi_os_unmap_memory (table_ptr,ACPI_EBDA_PTR_LENGTH ); +early_acpi_os_unmap_memory (table_ptr,ACPI_EBDA_PTR_LENGTH );/* EBDA present? */
@@ -168,6 +169,7 @@ acpi_status acpi_find_root_pointer(acpi_acpi_tb_scan_memory_for_rsdp (table_ptr,ACPI_EBDA_WINDOW_SIZE );acpi_os_unmap_memory (table_ptr,ACPI_EBDA_WINDOW_SIZE ); +early_acpi_os_unmap_memory (table_ptr,ACPI_EBDA_WINDOW_SIZE );if (mem_rover) {
@@ -200,6 +202,7 @@ acpi_status acpi_find_root_pointer(acpi_ mem_rover =acpi_tb_scan_memory_for_rsdp (table_ptr,ACPI_HI_RSDP_WINDOW_SIZE );acpi_os_unmap_memory (table_ptr,ACPI_HI_RSDP_WINDOW_SIZE ); +early_acpi_os_unmap_memory (table_ptr,ACPI_HI_RSDP_WINDOW_SIZE );if (mem_rover) {
include/acpi/acpiosxf.h +1 -0
@@ -147,6 +147,7 @@ void __iomem *acpi_os_map_memory(acpi_ph 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
include/acpi/acpixf.h +4 -0
@@ -112,6 +112,10 @@ acpi_get_table_header(acpi_string signat 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);
include/linux/acpi.h +1 -0
@@ -79,6 +79,7 @@ typedef int (*acpi_table_handler) (structypedef 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 );
drivers/acpi/bus.c +0 -6
@@ -650,12 +650,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 ();
PATCH 1/3 x86: change early_ioremap to use slots instead of nesting
so could remove requirement that need to call early_ioremap in exactly revese order of early_iounmap
Signed-off-by Yinghai Lu <[email protected]>
--- arch/x86/mm/ioremap.c | 77 ++++++++++++++++++++++++++++++++------------ include/asm-x86/fixmap_32.h | 4 +- include/asm-x86/fixmap_64.h | 4 +- 3 files changed, 61 insertions(+), 24 deletions(-)
arch/x86/mm/ioremap.c +57 -20
@@ -565,16 +565,22 @@ static inline void __init early_clear_fi__early_set_fixmap (idx,0 ,__pgprot (0 )); } - -static int __initdata early_ioremap_nested; - +static void *prev_map[FIX_BTMAPS_SLOTS ]__initdata ; +static unsigned long prev_size[FIX_BTMAPS_SLOTS ]__initdata ;static int __init check_early_ioremap_leak (void ) { -if (!early_ioremap_nested) +int count =0 ; +int i; + +for (i =0 ; i <FIX_BTMAPS_SLOTS ; i++) +if (prev_map[i]) + count++; + +if (!count)return 0 ;WARN (1 ,KERN_WARNING "Debug warning: early ioremap leak of %d areas detected.\n" , - early_ioremap_nested); + count);printk (KERN_WARNING "please boot with early_ioremap_debug and report the dmesg.\n" );
@@ -585,15 +591,30 @@ late_initcall(check_early_ioremap_leak);static void __init *__early_ioremap (unsigned long phys_addr,unsigned long size,pgprot_t prot) {unsigned long offset, last_addr; -unsigned int nrpages, nesting; +unsigned int nrpages;enum fixed_addresses idx0, idx; +int i, slot;WARN_ON (system_state !=SYSTEM_BOOTING ); - nesting = early_ioremap_nested; + slot =-1 ; +for (i =0 ; i <FIX_BTMAPS_SLOTS ; i++) { +if (!prev_map[i]) { + slot = i; +break ; + } + } + +if (slot <0 ) { +printk (KERN_INFO "early_iomap(%08lx, %08lx) not found slot\n" , + phys_addr, size); +WARN_ON (1 ); +return NULL ; + } +if (early_ioremap_debug) {printk (KERN_INFO "early_ioremap(%08lx, %08lx) [%d] => " , - phys_addr, size, nesting); + phys_addr, size, slot);dump_stack (); }
@@ -604,11 +625,7 @@ static void __init *__early_ioremap(unsireturn NULL ; } -if (nesting >=FIX_BTMAPS_NESTING ) { -WARN_ON (1 ); -return NULL ; - } - early_ioremap_nested++; + prev_size[slot] = size;/* * Mappings have to be page-aligned */
@@ -628,7 +645,7 @@ static void __init *__early_ioremap(unsi/* * Ok, go for it.. */ - idx0 =FIX_BTMAP_BEGIN -NR_FIX_BTMAPS *nesting; + idx0 =FIX_BTMAP_BEGIN -NR_FIX_BTMAPS *slot; idx = idx0;while (nrpages >0 ) {early_set_fixmap (idx, phys_addr, prot);
@@ -639,7 +656,8 @@ static void __init *__early_ioremap(unsiif (early_ioremap_debug)printk (KERN_CONT "%08lx + %08lx\n" , offset,fix_to_virt (idx0)); -return (void *) (offset +fix_to_virt (idx0)); + prev_map[slot] = (void *) (offset +fix_to_virt (idx0)); +return prev_map[slot]; }/* Remap an IO device */
@@ -660,15 +678,33 @@ void __init early_iounmap(void *addr, ununsigned long offset;unsigned int nrpages;enum fixed_addresses idx; -int nesting; +int i, slot; - nesting = --early_ioremap_nested; -if (WARN_ON (nesting <0 )) + slot =-1 ; +for (i =0 ; i <FIX_BTMAPS_SLOTS ; i++) { +if (prev_map[i] == addr) { + slot = i; +break ; + } + } + +if (slot <0 ) { +printk (KERN_INFO "early_iounmap(%p, %08lx) not found slot\n" , + addr, size); +WARN_ON (1 );return ; + } + +if (prev_size[slot] != size) { +printk (KERN_INFO "early_iounmap(%p, %08lx) [%d] size not consistent %08lx\n" , + addr, size, slot, prev_size[slot]); +WARN_ON (1 ); +return ; + }if (early_ioremap_debug) {printk (KERN_INFO "early_iounmap(%p, %08lx) [%d]\n" , addr, - size, nesting); + size, slot);dump_stack (); }
@@ -680,12 +716,13 @@ void __init early_iounmap(void *addr, un offset = virt_addr & ~PAGE_MASK ; nrpages =PAGE_ALIGN (offset + size -1 ) >>PAGE_SHIFT ; - idx =FIX_BTMAP_BEGIN -NR_FIX_BTMAPS *nesting; + idx =FIX_BTMAP_BEGIN -NR_FIX_BTMAPS *slot;while (nrpages >0 ) {early_clear_fixmap (idx); --idx; --nrpages; } + prev_map[slot] =0 ; }void __this_fixmap_does_not_exist (void )
include/asm-x86/fixmap_32.h +2 -2
@@ -94,10 +94,10 @@ enum fixed_addresses {* can have a single pgd entry and a single pte table: */ #define NR_FIX_BTMAPS 64 -#define FIX_BTMAPS_NESTING 4 +#define FIX_BTMAPS_SLOTS 4FIX_BTMAP_END = __end_of_permanent_fixed_addresses +256 - (__end_of_permanent_fixed_addresses &255 ), -FIX_BTMAP_BEGIN =FIX_BTMAP_END +NR_FIX_BTMAPS *FIX_BTMAPS_NESTING -1 , +FIX_BTMAP_BEGIN =FIX_BTMAP_END +NR_FIX_BTMAPS *FIX_BTMAPS_SLOTS -1 ,FIX_WP_TEST , #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT FIX_OHCI1394_BASE,
include/asm-x86/fixmap_64.h +2 -2
@@ -61,10 +61,10 @@ enum fixed_addresses {* can have a single pgd entry and a single pte table: */ #define NR_FIX_BTMAPS 64 -#define FIX_BTMAPS_NESTING 4 +#define FIX_BTMAPS_SLOTS 4FIX_BTMAP_END = __end_of_permanent_fixed_addresses +256 - (__end_of_permanent_fixed_addresses &255 ), -FIX_BTMAP_BEGIN =FIX_BTMAP_END +NR_FIX_BTMAPS *FIX_BTMAPS_NESTING -1 , +FIX_BTMAP_BEGIN =FIX_BTMAP_END +NR_FIX_BTMAPS *FIX_BTMAPS_SLOTS -1 , __end_of_fixed_addresses };
PATCH 3/3 x86: check dsdt before find oem table for es7000 v2
In reply to Yinghai Luv2: use __acpi_unmap_table()
Signed-off-by Yinghai Lu <[email protected]>
--- arch/x86/kernel/es7000_32.c | 28 +++++++++++++++++++++++----- arch/x86/mach-generic/es7000.c | 20 +++++++++++++++----- include/asm-x86/es7000/mpparse.h | 1 + 3 files changed, 39 insertions(+), 10 deletions(-)
arch/x86/mach-generic/es7000.c +15 -5
@@ -47,16 +47,26 @@ static __init int mps_oem_check(struct m/* Hook from generic ACPI tables.c */ static int __init acpi_madt_oem_check (char *oem_id,char *oem_table_id) { -unsigned long oem_addr; +unsigned long oem_addr =0 ; +int check_dsdt; +int ret =0 ; + +/* check dsdt at first to avoid clear fix_map for oem_addr */ + check_dsdt =es7000_check_dsdt (); +if (!find_unisys_acpi_oem_table (&oem_addr)) { -if (es7000_check_dsdt ()) -return parse_unisys_oem ((char *)oem_addr); +if (check_dsdt) + ret =parse_unisys_oem ((char *)oem_addr);else {setup_unisys (); -return 1 ; + ret =1 ; } +/* +* we need to unmap it +*/ +unmap_unisys_acpi_oem_table (oem_addr); } -return 0 ; +return ret; }#else static int __init acpi_madt_oem_check (char *oem_id,char *oem_table_id)
arch/x86/kernel/es7000_32.c +23 -5
@@ -109,6 +109,7 @@ struct oem_table { };extern int find_unisys_acpi_oem_table (unsigned long *oem_addr); +extern void unmap_unisys_acpi_oem_table (unsigned long oem_addr);#endif struct mip_reg {
@@ -243,21 +244,38 @@ parse_unisys_oem (char *oemptr) }#ifdef CONFIG_ACPI -int __init -find_unisys_acpi_oem_table (unsigned long *oem_addr) +static unsigned long oem_addrX; +static unsigned long oem_size; +int __init find_unisys_acpi_oem_table (unsigned long *oem_addr) {struct acpi_table_header *header =NULL ;int i =0 ; -while (ACPI_SUCCESS (acpi_get_table ("OEM1" , i++, &header))) { +acpi_size tbl_size; + +while (ACPI_SUCCESS (acpi_get_table_with_size ("OEM1" , i++, &header, &tbl_size))) {if (!memcmp ((char *) &header->oem_id,"UNISYS" ,6 )) {struct oem_table *t = (struct oem_table *)header; - *oem_addr = (unsigned long )__acpi_map_table (t->OEMTableAddr, - t->OEMTableSize); + + oem_addrX = t->OEMTableAddr; + oem_size = t->OEMTableSize; +early_acpi_os_unmap_memory (header, tbl_size); + + *oem_addr = (unsigned long )__acpi_map_table (oem_addrX, + oem_size);return 0 ; } +early_acpi_os_unmap_memory (header, tbl_size); }return -1 ; } + +void __init unmap_unisys_acpi_oem_table (unsigned long oem_addr) +{ +if (!oem_addr) +return ; + +__acpi_unmap_table ((char *)oem_addr, oem_size); +}#endif static void
include/asm-x86/es7000/mpparse.h +1 -0
@@ -5,6 +5,7 @@extern int parse_unisys_oem (char *oemptr);extern int find_unisys_acpi_oem_table (unsigned long *oem_addr); +extern void unmap_unisys_acpi_oem_table (unsigned long oem_addr);extern void setup_unisys (void );#ifndef CONFIG_X86_GENERICARCH