x86: efi: cleanups and basic 32/64-bit support
Subsystems (3)
v5 cover x86: efi: cleanups and basic 32/64-bit support
This series allows basic booting of a 32-bit kernel on 64-bit EFI and vice versa. It's needed by Chrome OS, and we've been carrying a nasty hack to do it that I've cleaned up and made sure it works in both directions.
Being able to boot an upstream kernel on Chrome OS hardware is helpful for hobbyists and others who want to tinker with their Chrome OS machines, but it's also very helpful for our kernel developers who want to contribute and work close to upstream without carrying out-of-tree base patches.
V4 was tested on Chrome OS for 64-bit EFI 32-bit kernel and with an old MacBook for 32-bit EFI, 64-bit kernel.
Note that this is required, but not sufficient, for full platform support for EFI in a mixed environment. There is no handling of runtime services, and no thunking for going in and out of firmware in a different mode.
Resend of the last posted version. Matt has acked all but the last patch at this point, and Matthew seems to be OK with it as well (see
http://marc.info/?l=linux-kernel&m=132578786105542).
Please consider for 3.4 merge window. Thanks!
-Olof
Changelog is:
v5:
* Addressed review comments from Matt Fleming over some formatting/printk strings as well as some coding style changes.
* Fixed bug that printed out "runtime not initialized" when it was on non-mixed-wordsize setups.
v4:
* Removed bogus memdesc warning printout
* Fixed up printk formatting, removing redundant EFI output
* Some of the earlier cleanup was accidentally reverted by this patch, fixed.
* Reworded some messages to not have to line wrap printk strings
v3:
* Reorganized to a series of patches to make it easier to review, and do some of the cleanups I had left out before.
v2:
* Added graceful error handling for 32-bit kernel that gets passed EFI data above 4GB.
* Removed some warnings that were missed in first version.
PATCH v5 1/5 x86: efi: refactor efi_init() a bit
Break out some of the init steps into helper functions.
Only change to execution flow is the removal of the warning when the kernel memdesc structure differ in size from what firmware specifies since it's a bogus warning (it's a valid difference per spec).
v4:
* Removed memdesc warning as per above
--- arch/x86/platform/efi/efi.c | 89 ++++++++++++++++++++++++++----------------- 1 files changed, 54 insertions(+), 35 deletions(-)
arch/x86/platform/efi/efi.c +54 -35
@@ -436,23 +436,8 @@ static void __init efi_free_boot_services(void) } } -void __init efi_init (void ) +static void __init efi_systab_init (void *phys) { -efi_config_table_t *config_tables; -efi_runtime_services_t *runtime; -efi_char16_t *c16; -char vendor[100 ] ="unknown" ; -int i =0 ; -void *tmp; - -#ifdef CONFIG_X86_32 - efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab; -#else - efi_phys.systab = (efi_system_table_t *) - (boot_params.efi_info.efi_systab | - ((__u64 )boot_params.efi_info.efi_systab_hi<<32 )); -#endif - efi.systab =early_ioremap ((unsigned long )efi_phys.systab,sizeof (efi_system_table_t));if (efi.systab ==NULL )
@@ -471,22 +456,12 @@ void __init efi_init(void)"%d.%02d, expected 1.00 or greater!\n" , efi.systab->hdr.revision >>16 , efi.systab->hdr.revision & 0xffff); +} -/* -* Show what we know for posterity -*/ - c16 = tmp =early_ioremap (efi.systab->fw_vendor,2 ); -if (c16) { -for (i =0 ; i <sizeof (vendor) -1 && *c16; ++i) - vendor[i] = *c16++; - vendor[i] ='\0' ; - }else - printk(KERN_ERR PFX "Could not map the firmware vendor!\n"); -early_iounmap (tmp,2 ); - -printk (KERN_INFO "EFI v%u.%.02u by %s\n" , - efi.systab->hdr.revision >>16 , - efi.systab->hdr.revision &0xffff , vendor); +static void __init efi_config_init (u64 tables,int nr_tables) +{ +efi_config_table_t *config_tables; +int i;/* * Let's see what config tables the firmware passed to us.
@@ -533,6 +508,11 @@ void __init efi_init(void)printk ("\n" );early_iounmap (config_tables, efi.systab->nr_tables *sizeof (efi_config_table_t)); +} + +static void __init efi_runtime_init (void ) +{ +efi_runtime_services_t *runtime;/* * Check out the runtime services table. We need to map
@@ -561,7 +541,10 @@ void __init efi_init(void)printk (KERN_ERR "Could not map the EFI runtime service " "table!\n" );early_iounmap (runtime,sizeof (efi_runtime_services_t)); +} +static void __init efi_memmap_init (void ) +{/* Map the EFI memory map */ memmap.map =early_ioremap ((unsigned long )memmap.phys_map, memmap.nr_map * memmap.desc_size);
@@ -569,12 +552,48 @@ void __init efi_init(void)printk (KERN_ERR "Could not map the EFI memory map!\n" ); memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size); -if (memmap.desc_size !=sizeof (efi_memory_desc_t)) -printk (KERN_WARNING -"Kernel-defined memdesc doesn't match the one from EFI!\n" ); -if (add_efi_memmap)do_add_efi_memmap (); +} + +void __init efi_init (void ) +{ +efi_char16_t *c16; +char vendor[100 ] ="unknown" ; +int i =0 ; +void *tmp; + +#ifdef CONFIG_X86_32 + efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab; +#else + efi_phys.systab = (efi_system_table_t *) + (boot_params.efi_info.efi_systab | + ((__u64 )boot_params.efi_info.efi_systab_hi<<32 )); +#endif + +efi_systab_init (efi_phys.systab); + +/* +* Show what we know for posterity +*/ + c16 = tmp =early_ioremap (efi.systab->fw_vendor,2 ); +if (c16) { +for (i =0 ; i <sizeof (vendor) -1 && *c16; ++i) + vendor[i] = *c16++; + vendor[i] ='\0' ; + }else + printk(KERN_ERR PFX "Could not map the firmware vendor!\n"); +early_iounmap (tmp,2 ); + +printk (KERN_INFO "EFI v%u.%.02u by %s\n" , + efi.systab->hdr.revision >>16 , + efi.systab->hdr.revision &0xffff , vendor); + +efi_config_init (efi.systab->tables, efi.systab->nr_tables); + +efi_runtime_init (); + +efi_memmap_init ();#ifdef CONFIG_X86_32 x86_platform.get_wallclock = efi_get_time;
Signature · 1 line
1.7.9.209.gb6b3b
[tip:x86/eficross] x86, efi: Refactor efi_init() a bit
Commit-ID: 83e7ee6657dfcd6b0ee2406d11024b558064252a Gitweb: http://git.kernel.org/tip/83e7ee6657dfcd6b0ee2406d11024b558064252a Author: Olof Johansson <[email protected]> AuthorDate: Sun, 12 Feb 2012 13:24:25 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Thu, 23 Feb 2012 18:53:56 -0800
x86, efi: Refactor efi_init() a bit
Break out some of the init steps into helper functions.
Only change to execution flow is the removal of the warning when the kernel memdesc structure differ in size from what firmware specifies since it's a bogus warning (it's a valid difference per spec).
v4:
* Removed memdesc warning as per above
--- arch/x86/platform/efi/efi.c | 89 ++++++++++++++++++++++++++----------------- 1 files changed, 54 insertions(+), 35 deletions(-)
arch/x86/platform/efi/efi.c +54 -35
@@ -429,23 +429,8 @@ static void __init efi_free_boot_services(void) } } -void __init efi_init (void ) +static void __init efi_systab_init (void *phys) { -efi_config_table_t *config_tables; -efi_runtime_services_t *runtime; -efi_char16_t *c16; -char vendor[100 ] ="unknown" ; -int i =0 ; -void *tmp; - -#ifdef CONFIG_X86_32 - efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab; -#else - efi_phys.systab = (efi_system_table_t *) - (boot_params.efi_info.efi_systab | - ((__u64 )boot_params.efi_info.efi_systab_hi<<32 )); -#endif - efi.systab =early_ioremap ((unsigned long )efi_phys.systab,sizeof (efi_system_table_t));if (efi.systab ==NULL )
@@ -464,22 +449,12 @@ void __init efi_init(void)"%d.%02d, expected 1.00 or greater!\n" , efi.systab->hdr.revision >>16 , efi.systab->hdr.revision & 0xffff); +} -/* -* Show what we know for posterity -*/ - c16 = tmp =early_ioremap (efi.systab->fw_vendor,2 ); -if (c16) { -for (i =0 ; i <sizeof (vendor) -1 && *c16; ++i) - vendor[i] = *c16++; - vendor[i] ='\0' ; - }else - printk(KERN_ERR PFX "Could not map the firmware vendor!\n"); -early_iounmap (tmp,2 ); - -printk (KERN_INFO "EFI v%u.%.02u by %s\n" , - efi.systab->hdr.revision >>16 , - efi.systab->hdr.revision &0xffff , vendor); +static void __init efi_config_init (u64 tables,int nr_tables) +{ +efi_config_table_t *config_tables; +int i;/* * Let's see what config tables the firmware passed to us.
@@ -526,6 +501,11 @@ void __init efi_init(void)printk ("\n" );early_iounmap (config_tables, efi.systab->nr_tables *sizeof (efi_config_table_t)); +} + +static void __init efi_runtime_init (void ) +{ +efi_runtime_services_t *runtime;/* * Check out the runtime services table. We need to map
@@ -554,7 +534,10 @@ void __init efi_init(void)printk (KERN_ERR "Could not map the EFI runtime service " "table!\n" );early_iounmap (runtime,sizeof (efi_runtime_services_t)); +} +static void __init efi_memmap_init (void ) +{/* Map the EFI memory map */ memmap.map =early_ioremap ((unsigned long )memmap.phys_map, memmap.nr_map * memmap.desc_size);
@@ -562,12 +545,48 @@ void __init efi_init(void)printk (KERN_ERR "Could not map the EFI memory map!\n" ); memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size); -if (memmap.desc_size !=sizeof (efi_memory_desc_t)) -printk (KERN_WARNING -"Kernel-defined memdesc doesn't match the one from EFI!\n" ); -if (add_efi_memmap)do_add_efi_memmap (); +} + +void __init efi_init (void ) +{ +efi_char16_t *c16; +char vendor[100 ] ="unknown" ; +int i =0 ; +void *tmp; + +#ifdef CONFIG_X86_32 + efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab; +#else + efi_phys.systab = (efi_system_table_t *) + (boot_params.efi_info.efi_systab | + ((__u64 )boot_params.efi_info.efi_systab_hi<<32 )); +#endif + +efi_systab_init (efi_phys.systab); + +/* +* Show what we know for posterity +*/ + c16 = tmp =early_ioremap (efi.systab->fw_vendor,2 ); +if (c16) { +for (i =0 ; i <sizeof (vendor) -1 && *c16; ++i) + vendor[i] = *c16++; + vendor[i] ='\0' ; + }else + printk(KERN_ERR PFX "Could not map the firmware vendor!\n"); +early_iounmap (tmp,2 ); + +printk (KERN_INFO "EFI v%u.%.02u by %s\n" , + efi.systab->hdr.revision >>16 , + efi.systab->hdr.revision &0xffff , vendor); + +efi_config_init (efi.systab->tables, efi.systab->nr_tables); + +efi_runtime_init (); + +efi_memmap_init ();#ifdef CONFIG_X86_32 x86_platform.get_wallclock = efi_get_time;
PATCH v5 2/5 x86: efi: convert printk to pr_*()
In reply to Olof JohanssonAlright, I guess I'll go through and convert them, even though there's no net gain to speak of.
v4:
* Switched to pr_fmt and removed some redundant use of "EFI" in messages.
--- arch/x86/platform/efi/efi.c | 58 +++++++++++++++++++++--------------------- 1 files changed, 29 insertions(+), 29 deletions(-)
arch/x86/platform/efi/efi.c +29 -29
@@ -26,6 +26,8 @@* Skip non-WB memory and ignore empty memory ranges. */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/kernel.h> #include <linux/init.h> #include <linux/efi.h>
@@ -47,7 +49,6 @@#include <asm/x86_init.h> #define EFI_DEBUG 1 -#define PFX "EFI: "int efi_enabled;EXPORT_SYMBOL (efi_enabled);
@@ -254,7 +255,7 @@ int efi_set_rtc_mmss(unsigned long nowtime) status = efi.get_time (&eft, &cap);if (status !=EFI_SUCCESS ) { -printk (KERN_ERR "Oops: efitime: can't read time!\n" ); +pr_err ("Oops: efitime: can't read time!\n" );return -1 ; }
@@ -268,7 +269,7 @@ int efi_set_rtc_mmss(unsigned long nowtime) status = efi.set_time (&eft);if (status !=EFI_SUCCESS ) { -printk (KERN_ERR "Oops: efitime: can't write time!\n" ); +pr_err ("Oops: efitime: can't write time!\n" );return -1 ; }return 0 ;
@@ -282,7 +283,7 @@ unsigned long efi_get_time(void) status = efi.get_time (&eft, &cap);if (status !=EFI_SUCCESS ) -printk (KERN_ERR "Oops: efitime: can't read time!\n" ); +pr_err ("Oops: efitime: can't read time!\n" );return mktime (eft.year, eft.month, eft.day, eft.hour, eft.minute, eft.second);
@@ -374,7 +375,7 @@ static void __init print_efi_memmap(void) p < memmap.map_end; p += memmap.desc_size, i++) { md = p; - printk(KERN_INFO PFX "mem%02u: type=%u, attr=0x%llx, " + pr_info("mem%02u: type=%u, attr=0x%llx, " "range=[0x%016llx-0x%016llx) (%lluMB)\n", i, md->type, md->attribute, md->phys_addr, md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
@@ -407,7 +408,7 @@ void __init efi_reserve_boot_services(void) memblock_is_region_reserved(start, size)) {/* Could not reserve, skip it */ md->num_pages =0 ; -memblock_dbg (PFX "Could not reserve boot range " +memblock_dbg ("Could not reserve boot range " "[0x%010llx-0x%010llx]\n" , start, start+size-1 ); } else
@@ -441,7 +442,7 @@ static void __init efi_systab_init(void *phys) efi.systab =early_ioremap ((unsigned long )efi_phys.systab,sizeof (efi_system_table_t));if (efi.systab ==NULL ) -printk (KERN_ERR "Couldn't map the EFI system table!\n" ); +pr_err ("Couldn't map the system table!\n" );memcpy (&efi_systab, efi.systab,sizeof (efi_system_table_t));early_iounmap (efi.systab,sizeof (efi_system_table_t)); efi.systab = &efi_systab;
@@ -450,9 +451,9 @@ static void __init efi_systab_init(void *phys)* Verify the EFI Table */ if (efi.systab->hdr.signature !=EFI_SYSTEM_TABLE_SIGNATURE ) -printk (KERN_ERR "EFI system table signature incorrect!\n" ); +pr_err ("System table signature incorrect!\n" );if ((efi.systab->hdr.revision >>16 ) ==0 ) -printk (KERN_ERR "Warning: EFI system table version " +pr_err ("Warning: System table version " "%d.%02d, expected 1.00 or greater!\n" , efi.systab->hdr.revision >>16 , efi.systab->hdr.revision &0xffff );
@@ -470,42 +471,42 @@ static void __init efi_config_init(u64 tables, int nr_tables) efi.systab->tables, efi.systab->nr_tables * sizeof(efi_config_table_t));if (config_tables ==NULL ) -printk (KERN_ERR "Could not map EFI Configuration Table!\n" ); +pr_err ("Could not map Configuration table!\n" ); -printk (KERN_INFO ); +pr_info ("" );for (i =0 ; i < efi.systab->nr_tables; i++) {if (!efi_guidcmp (config_tables[i].guid,MPS_TABLE_GUID )) { efi.mps = config_tables[i].table; -printk (" MPS=0x%lx " , config_tables[i].table); +pr_cont (" MPS=0x%lx " , config_tables[i].table); }else if (!efi_guidcmp (config_tables[i].guid,ACPI_20_TABLE_GUID )) { efi.acpi20 = config_tables[i].table; -printk (" ACPI 2.0=0x%lx " , config_tables[i].table); +pr_cont (" ACPI 2.0=0x%lx " , config_tables[i].table); }else if (!efi_guidcmp (config_tables[i].guid,ACPI_TABLE_GUID )) { efi.acpi = config_tables[i].table; -printk (" ACPI=0x%lx " , config_tables[i].table); +pr_cont (" ACPI=0x%lx " , config_tables[i].table); }else if (!efi_guidcmp (config_tables[i].guid,SMBIOS_TABLE_GUID )) { efi.smbios = config_tables[i].table; -printk (" SMBIOS=0x%lx " , config_tables[i].table); +pr_cont (" SMBIOS=0x%lx " , config_tables[i].table); #ifdef CONFIG_X86_UV }else if (!efi_guidcmp (config_tables[i].guid,UV_SYSTEM_TABLE_GUID )) { efi.uv_systab = config_tables[i].table; -printk (" UVsystab=0x%lx " , config_tables[i].table); +pr_cont (" UVsystab=0x%lx " , config_tables[i].table);#endif }else if (!efi_guidcmp (config_tables[i].guid,HCDP_TABLE_GUID )) { efi.hcdp = config_tables[i].table; -printk (" HCDP=0x%lx " , config_tables[i].table); +pr_cont (" HCDP=0x%lx " , config_tables[i].table); }else if (!efi_guidcmp (config_tables[i].guid,UGA_IO_PROTOCOL_GUID )) { efi.uga = config_tables[i].table; -printk (" UGA=0x%lx " , config_tables[i].table); +pr_cont (" UGA=0x%lx " , config_tables[i].table); } } -printk ("\n" ); +pr_cont ("\n" );early_iounmap (config_tables, efi.systab->nr_tables *sizeof (efi_config_table_t)); }
@@ -538,8 +539,7 @@ static void __init efi_runtime_init(void)*/ efi.get_time = phys_efi_get_time; }else -printk (KERN_ERR "Could not map the EFI runtime service " -"table!\n" ); +pr_err ("Could not map the runtime service table!\n" );early_iounmap (runtime,sizeof (efi_runtime_services_t)); }
@@ -549,7 +549,7 @@ static void __init efi_memmap_init(void) memmap.map =early_ioremap ((unsigned long )memmap.phys_map, memmap.nr_map * memmap.desc_size);if (memmap.map ==NULL ) -printk (KERN_ERR "Could not map the EFI memory map!\n" ); +pr_err ("Could not map the memory map!\n" ); memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);if (add_efi_memmap)
@@ -582,12 +582,12 @@ void __init efi_init(void) vendor[i] = *c16++; vendor[i] ='\0' ; }else - printk(KERN_ERR PFX "Could not map the firmware vendor!\n"); +pr_err ("Could not map the firmware vendor!\n" );early_iounmap (tmp,2 ); -printk (KERN_INFO "EFI v%u.%.02u by %s\n" , - efi.systab->hdr.revision >>16 , - efi.systab->hdr.revision &0xffff , vendor); +pr_info ("EFI v%u.%.02u by %s\n" , + efi.systab->hdr.revision >>16 , + efi.systab->hdr.revision &0xffff , vendor);efi_config_init (efi.systab->tables, efi.systab->nr_tables);
@@ -714,7 +714,7 @@ void __init efi_enter_virtual_mode(void) md->virt_addr = (u64 ) (unsigned long ) va;if (!va) { - printk(KERN_ERR PFX "ioremap of 0x%llX failed!\n", +pr_err ("ioremap of 0x%llX failed!\n" , (unsigned long long )md->phys_addr);continue ; }
@@ -741,8 +741,8 @@ void __init efi_enter_virtual_mode(void) (efi_memory_desc_t *)__pa(new_memmap));if (status !=EFI_SUCCESS ) { -printk (KERN_ALERT "Unable to switch EFI into virtual mode " -"(status=%lx)!\n" , status); +pr_alert ("Unable to switch EFI into virtual mode " +"(status=%lx)!\n" , status);panic ("EFI call to SetVirtualAddressMap() failed!" ); }
Signature · 1 line
1.7.9.209.gb6b3b
PATCH 1/1 memblock: Make memblock_dbg macro safer
Allow this macro to be used in an if/else block.
Use do {} while (0) and pr_info. (perhaps this should be pr_debug)
--- include/linux/memblock.h | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
include/linux/memblock.h +5 -2
@@ -43,8 +43,11 @@ struct memblock {extern struct memblock memblock;extern int memblock_debug; -#define memblock_dbg (fmt, ...) \ - if (memblock_debug) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) +#define memblock_dbg (fmt, ...) \ +do { \ + if (memblock_debug) \ + pr_info(fmt, ##__VA_ARGS__); \ +} while (0)phys_addr_t memblock_find_in_range_node (phys_addr_t start,phys_addr_t end,phys_addr_t size,phys_addr_t align,int nid);
[tip:x86/eficross] x86, efi: Convert printk to pr_*()
In reply to Olof JohanssonCommit-ID: e3cb3f5a35997906f9b79bf860029c02a54cfae6 Gitweb: http://git.kernel.org/tip/e3cb3f5a35997906f9b79bf860029c02a54cfae6 Author: Olof Johansson <[email protected]> AuthorDate: Sun, 12 Feb 2012 13:24:26 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Thu, 23 Feb 2012 18:54:22 -0800
x86, efi: Convert printk to pr_*()
Alright, I guess I'll go through and convert them, even though there's no net gain to speak of.
v4:
* Switched to pr_fmt and removed some redundant use of "EFI" in messages.
--- arch/x86/platform/efi/efi.c | 58 +++++++++++++++++++++--------------------- 1 files changed, 29 insertions(+), 29 deletions(-)
arch/x86/platform/efi/efi.c +29 -29
@@ -26,6 +26,8 @@* Skip non-WB memory and ignore empty memory ranges. */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/kernel.h> #include <linux/init.h> #include <linux/efi.h>
@@ -47,7 +49,6 @@#include <asm/x86_init.h> #define EFI_DEBUG 1 -#define PFX "EFI: "int efi_enabled;EXPORT_SYMBOL (efi_enabled);
@@ -254,7 +255,7 @@ int efi_set_rtc_mmss(unsigned long nowtime) status = efi.get_time (&eft, &cap);if (status !=EFI_SUCCESS ) { -printk (KERN_ERR "Oops: efitime: can't read time!\n" ); +pr_err ("Oops: efitime: can't read time!\n" );return -1 ; }
@@ -268,7 +269,7 @@ int efi_set_rtc_mmss(unsigned long nowtime) status = efi.set_time (&eft);if (status !=EFI_SUCCESS ) { -printk (KERN_ERR "Oops: efitime: can't write time!\n" ); +pr_err ("Oops: efitime: can't write time!\n" );return -1 ; }return 0 ;
@@ -282,7 +283,7 @@ unsigned long efi_get_time(void) status = efi.get_time (&eft, &cap);if (status !=EFI_SUCCESS ) -printk (KERN_ERR "Oops: efitime: can't read time!\n" ); +pr_err ("Oops: efitime: can't read time!\n" );return mktime (eft.year, eft.month, eft.day, eft.hour, eft.minute, eft.second);
@@ -367,7 +368,7 @@ static void __init print_efi_memmap(void) p < memmap.map_end; p += memmap.desc_size, i++) { md = p; - printk(KERN_INFO PFX "mem%02u: type=%u, attr=0x%llx, " + pr_info("mem%02u: type=%u, attr=0x%llx, " "range=[0x%016llx-0x%016llx) (%lluMB)\n", i, md->type, md->attribute, md->phys_addr, md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
@@ -400,7 +401,7 @@ void __init efi_reserve_boot_services(void) memblock_is_region_reserved(start, size)) {/* Could not reserve, skip it */ md->num_pages =0 ; -memblock_dbg (PFX "Could not reserve boot range " +memblock_dbg ("Could not reserve boot range " "[0x%010llx-0x%010llx]\n" , start, start+size-1 ); } else
@@ -434,7 +435,7 @@ static void __init efi_systab_init(void *phys) efi.systab =early_ioremap ((unsigned long )efi_phys.systab,sizeof (efi_system_table_t));if (efi.systab ==NULL ) -printk (KERN_ERR "Couldn't map the EFI system table!\n" ); +pr_err ("Couldn't map the system table!\n" );memcpy (&efi_systab, efi.systab,sizeof (efi_system_table_t));early_iounmap (efi.systab,sizeof (efi_system_table_t)); efi.systab = &efi_systab;
@@ -443,9 +444,9 @@ static void __init efi_systab_init(void *phys)* Verify the EFI Table */ if (efi.systab->hdr.signature !=EFI_SYSTEM_TABLE_SIGNATURE ) -printk (KERN_ERR "EFI system table signature incorrect!\n" ); +pr_err ("System table signature incorrect!\n" );if ((efi.systab->hdr.revision >>16 ) ==0 ) -printk (KERN_ERR "Warning: EFI system table version " +pr_err ("Warning: System table version " "%d.%02d, expected 1.00 or greater!\n" , efi.systab->hdr.revision >>16 , efi.systab->hdr.revision &0xffff );
@@ -463,42 +464,42 @@ static void __init efi_config_init(u64 tables, int nr_tables) efi.systab->tables, efi.systab->nr_tables * sizeof(efi_config_table_t));if (config_tables ==NULL ) -printk (KERN_ERR "Could not map EFI Configuration Table!\n" ); +pr_err ("Could not map Configuration table!\n" ); -printk (KERN_INFO ); +pr_info ("" );for (i =0 ; i < efi.systab->nr_tables; i++) {if (!efi_guidcmp (config_tables[i].guid,MPS_TABLE_GUID )) { efi.mps = config_tables[i].table; -printk (" MPS=0x%lx " , config_tables[i].table); +pr_cont (" MPS=0x%lx " , config_tables[i].table); }else if (!efi_guidcmp (config_tables[i].guid,ACPI_20_TABLE_GUID )) { efi.acpi20 = config_tables[i].table; -printk (" ACPI 2.0=0x%lx " , config_tables[i].table); +pr_cont (" ACPI 2.0=0x%lx " , config_tables[i].table); }else if (!efi_guidcmp (config_tables[i].guid,ACPI_TABLE_GUID )) { efi.acpi = config_tables[i].table; -printk (" ACPI=0x%lx " , config_tables[i].table); +pr_cont (" ACPI=0x%lx " , config_tables[i].table); }else if (!efi_guidcmp (config_tables[i].guid,SMBIOS_TABLE_GUID )) { efi.smbios = config_tables[i].table; -printk (" SMBIOS=0x%lx " , config_tables[i].table); +pr_cont (" SMBIOS=0x%lx " , config_tables[i].table); #ifdef CONFIG_X86_UV }else if (!efi_guidcmp (config_tables[i].guid,UV_SYSTEM_TABLE_GUID )) { efi.uv_systab = config_tables[i].table; -printk (" UVsystab=0x%lx " , config_tables[i].table); +pr_cont (" UVsystab=0x%lx " , config_tables[i].table);#endif }else if (!efi_guidcmp (config_tables[i].guid,HCDP_TABLE_GUID )) { efi.hcdp = config_tables[i].table; -printk (" HCDP=0x%lx " , config_tables[i].table); +pr_cont (" HCDP=0x%lx " , config_tables[i].table); }else if (!efi_guidcmp (config_tables[i].guid,UGA_IO_PROTOCOL_GUID )) { efi.uga = config_tables[i].table; -printk (" UGA=0x%lx " , config_tables[i].table); +pr_cont (" UGA=0x%lx " , config_tables[i].table); } } -printk ("\n" ); +pr_cont ("\n" );early_iounmap (config_tables, efi.systab->nr_tables *sizeof (efi_config_table_t)); }
@@ -531,8 +532,7 @@ static void __init efi_runtime_init(void)*/ efi.get_time = phys_efi_get_time; }else -printk (KERN_ERR "Could not map the EFI runtime service " -"table!\n" ); +pr_err ("Could not map the runtime service table!\n" );early_iounmap (runtime,sizeof (efi_runtime_services_t)); }
@@ -542,7 +542,7 @@ static void __init efi_memmap_init(void) memmap.map =early_ioremap ((unsigned long )memmap.phys_map, memmap.nr_map * memmap.desc_size);if (memmap.map ==NULL ) -printk (KERN_ERR "Could not map the EFI memory map!\n" ); +pr_err ("Could not map the memory map!\n" ); memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);if (add_efi_memmap)
@@ -575,12 +575,12 @@ void __init efi_init(void) vendor[i] = *c16++; vendor[i] ='\0' ; }else - printk(KERN_ERR PFX "Could not map the firmware vendor!\n"); +pr_err ("Could not map the firmware vendor!\n" );early_iounmap (tmp,2 ); -printk (KERN_INFO "EFI v%u.%.02u by %s\n" , - efi.systab->hdr.revision >>16 , - efi.systab->hdr.revision &0xffff , vendor); +pr_info ("EFI v%u.%.02u by %s\n" , + efi.systab->hdr.revision >>16 , + efi.systab->hdr.revision &0xffff , vendor);efi_config_init (efi.systab->tables, efi.systab->nr_tables);
@@ -696,7 +696,7 @@ void __init efi_enter_virtual_mode(void) md->virt_addr = (u64 ) (unsigned long ) va;if (!va) { - printk(KERN_ERR PFX "ioremap of 0x%llX failed!\n", +pr_err ("ioremap of 0x%llX failed!\n" , (unsigned long long )md->phys_addr);continue ; }
@@ -730,8 +730,8 @@ void __init efi_enter_virtual_mode(void) (efi_memory_desc_t *)__pa(new_memmap));if (status !=EFI_SUCCESS ) { -printk (KERN_ALERT "Unable to switch EFI into virtual mode " -"(status=%lx)!\n" , status); +pr_alert ("Unable to switch EFI into virtual mode " +"(status=%lx)!\n" , status);panic ("EFI call to SetVirtualAddressMap() failed!" ); }
PATCH v5 3/5 x86: efi: cleanup config table walking
In reply to Olof JohanssonTrivial cleanup, move guid and table pointers to local copies to make the code cleaner.
--- arch/x86/platform/efi/efi.c | 61 +++++++++++++++++++----------------------- 1 files changed, 28 insertions(+), 33 deletions(-)
arch/x86/platform/efi/efi.c +28 -33
@@ -462,53 +462,48 @@ static void __init efi_systab_init(void *phys)static void __init efi_config_init (u64 tables,int nr_tables) {efi_config_table_t *config_tables; -int i; +int i, sz =sizeof (efi_config_table_t);/* * Let's see what config tables the firmware passed to us. */ - config_tables =early_ioremap ( - efi.systab->tables, - efi.systab->nr_tables *sizeof (efi_config_table_t)); + config_tables =early_ioremap (efi.systab->tables, + efi.systab->nr_tables * sz);if (config_tables ==NULL )pr_err ("Could not map Configuration table!\n" );pr_info ("" );for (i =0 ; i < efi.systab->nr_tables; i++) { -if (!efi_guidcmp (config_tables[i].guid,MPS_TABLE_GUID )) { - efi.mps = config_tables[i].table; -pr_cont (" MPS=0x%lx " , config_tables[i].table); - }else if (!efi_guidcmp (config_tables[i].guid, -ACPI_20_TABLE_GUID )) { - efi.acpi20 = config_tables[i].table; -pr_cont (" ACPI 2.0=0x%lx " , config_tables[i].table); - }else if (!efi_guidcmp (config_tables[i].guid, -ACPI_TABLE_GUID )) { - efi.acpi = config_tables[i].table; -pr_cont (" ACPI=0x%lx " , config_tables[i].table); - }else if (!efi_guidcmp (config_tables[i].guid, -SMBIOS_TABLE_GUID )) { - efi.smbios = config_tables[i].table; -pr_cont (" SMBIOS=0x%lx " , config_tables[i].table); +efi_guid_t guid = config_tables[i].guid; +unsigned long table = config_tables[i].table; + +if (!efi_guidcmp (guid,MPS_TABLE_GUID )) { + efi.mps = table; +pr_cont (" MPS=0x%lx " , table); + }else if (!efi_guidcmp (guid,ACPI_20_TABLE_GUID )) { + efi.acpi20 = table; +pr_cont (" ACPI 2.0=0x%lx " , table); + }else if (!efi_guidcmp (guid,ACPI_TABLE_GUID )) { + efi.acpi = table; +pr_cont (" ACPI=0x%lx " , table); + }else if (!efi_guidcmp (guid,SMBIOS_TABLE_GUID )) { + efi.smbios = table; +pr_cont (" SMBIOS=0x%lx " , table); #ifdef CONFIG_X86_UV - }else if (!efi_guidcmp (config_tables[i].guid, -UV_SYSTEM_TABLE_GUID )) { - efi.uv_systab = config_tables[i].table; -pr_cont (" UVsystab=0x%lx " , config_tables[i].table); + }else if (!efi_guidcmp (guid,UV_SYSTEM_TABLE_GUID )) { + efi.uv_systab = table; +pr_cont (" UVsystab=0x%lx " , table);#endif - }else if (!efi_guidcmp (config_tables[i].guid, -HCDP_TABLE_GUID )) { - efi.hcdp = config_tables[i].table; -pr_cont (" HCDP=0x%lx " , config_tables[i].table); - }else if (!efi_guidcmp (config_tables[i].guid, -UGA_IO_PROTOCOL_GUID )) { - efi.uga = config_tables[i].table; -pr_cont (" UGA=0x%lx " , config_tables[i].table); + }else if (!efi_guidcmp (guid,HCDP_TABLE_GUID )) { + efi.hcdp = table; +pr_cont (" HCDP=0x%lx " , table); + }else if (!efi_guidcmp (guid,UGA_IO_PROTOCOL_GUID )) { + efi.uga = table; +pr_cont (" UGA=0x%lx " , table); } }pr_cont ("\n" ); -early_iounmap (config_tables, - efi.systab->nr_tables *sizeof (efi_config_table_t)); +early_iounmap (config_tables, efi.systab->nr_tables * sz); }static void __init efi_runtime_init (void )
Signature · 1 line
1.7.9.209.gb6b3b
[tip:x86/eficross] x86, efi: Cleanup config table walking
Commit-ID: a6a46f415dca828a04a435ca1f67de0bc5b9ae30 Gitweb: http://git.kernel.org/tip/a6a46f415dca828a04a435ca1f67de0bc5b9ae30 Author: Olof Johansson <[email protected]> AuthorDate: Sun, 12 Feb 2012 13:24:27 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Thu, 23 Feb 2012 18:54:33 -0800
x86, efi: Cleanup config table walking
Trivial cleanup, move guid and table pointers to local copies to make the code cleaner.
--- arch/x86/platform/efi/efi.c | 61 +++++++++++++++++++----------------------- 1 files changed, 28 insertions(+), 33 deletions(-)
arch/x86/platform/efi/efi.c +28 -33
@@ -455,53 +455,48 @@ static void __init efi_systab_init(void *phys)static void __init efi_config_init (u64 tables,int nr_tables) {efi_config_table_t *config_tables; -int i; +int i, sz =sizeof (efi_config_table_t);/* * Let's see what config tables the firmware passed to us. */ - config_tables =early_ioremap ( - efi.systab->tables, - efi.systab->nr_tables *sizeof (efi_config_table_t)); + config_tables =early_ioremap (efi.systab->tables, + efi.systab->nr_tables * sz);if (config_tables ==NULL )pr_err ("Could not map Configuration table!\n" );pr_info ("" );for (i =0 ; i < efi.systab->nr_tables; i++) { -if (!efi_guidcmp (config_tables[i].guid,MPS_TABLE_GUID )) { - efi.mps = config_tables[i].table; -pr_cont (" MPS=0x%lx " , config_tables[i].table); - }else if (!efi_guidcmp (config_tables[i].guid, -ACPI_20_TABLE_GUID )) { - efi.acpi20 = config_tables[i].table; -pr_cont (" ACPI 2.0=0x%lx " , config_tables[i].table); - }else if (!efi_guidcmp (config_tables[i].guid, -ACPI_TABLE_GUID )) { - efi.acpi = config_tables[i].table; -pr_cont (" ACPI=0x%lx " , config_tables[i].table); - }else if (!efi_guidcmp (config_tables[i].guid, -SMBIOS_TABLE_GUID )) { - efi.smbios = config_tables[i].table; -pr_cont (" SMBIOS=0x%lx " , config_tables[i].table); +efi_guid_t guid = config_tables[i].guid; +unsigned long table = config_tables[i].table; + +if (!efi_guidcmp (guid,MPS_TABLE_GUID )) { + efi.mps = table; +pr_cont (" MPS=0x%lx " , table); + }else if (!efi_guidcmp (guid,ACPI_20_TABLE_GUID )) { + efi.acpi20 = table; +pr_cont (" ACPI 2.0=0x%lx " , table); + }else if (!efi_guidcmp (guid,ACPI_TABLE_GUID )) { + efi.acpi = table; +pr_cont (" ACPI=0x%lx " , table); + }else if (!efi_guidcmp (guid,SMBIOS_TABLE_GUID )) { + efi.smbios = table; +pr_cont (" SMBIOS=0x%lx " , table); #ifdef CONFIG_X86_UV - }else if (!efi_guidcmp (config_tables[i].guid, -UV_SYSTEM_TABLE_GUID )) { - efi.uv_systab = config_tables[i].table; -pr_cont (" UVsystab=0x%lx " , config_tables[i].table); + }else if (!efi_guidcmp (guid,UV_SYSTEM_TABLE_GUID )) { + efi.uv_systab = table; +pr_cont (" UVsystab=0x%lx " , table);#endif - }else if (!efi_guidcmp (config_tables[i].guid, -HCDP_TABLE_GUID )) { - efi.hcdp = config_tables[i].table; -pr_cont (" HCDP=0x%lx " , config_tables[i].table); - }else if (!efi_guidcmp (config_tables[i].guid, -UGA_IO_PROTOCOL_GUID )) { - efi.uga = config_tables[i].table; -pr_cont (" UGA=0x%lx " , config_tables[i].table); + }else if (!efi_guidcmp (guid,HCDP_TABLE_GUID )) { + efi.hcdp = table; +pr_cont (" HCDP=0x%lx " , table); + }else if (!efi_guidcmp (guid,UGA_IO_PROTOCOL_GUID )) { + efi.uga = table; +pr_cont (" UGA=0x%lx " , table); } }pr_cont ("\n" ); -early_iounmap (config_tables, - efi.systab->nr_tables *sizeof (efi_config_table_t)); +early_iounmap (config_tables, efi.systab->nr_tables * sz); }static void __init efi_runtime_init (void )
PATCH v5 4/5 x86: efi: add basic error handling
In reply to Olof JohanssonIt's not perfect, but way better than before. Mark efi_enabled as false in case of error and at least stop dereferencing pointers that are known to be invalid.
The only significant missing piece is the lack of undoing the memblock_reserve of the memory that efi marks as in use. On the other hand, it's not a large amount of memory, and leaving it unavailable for system use should be the safer choice anyway.
--- arch/x86/platform/efi/efi.c | 85 +++++++++++++++++++++++++++++-------------- 1 files changed, 57 insertions(+), 28 deletions(-)
arch/x86/platform/efi/efi.c +57 -28
@@ -437,12 +437,14 @@ static void __init efi_free_boot_services(void) } } -static void __init efi_systab_init (void *phys) +static int __init efi_systab_init (void *phys) { efi.systab =early_ioremap ((unsigned long )efi_phys.systab,sizeof (efi_system_table_t)); -if (efi.systab ==NULL ) +if (efi.systab ==NULL ) {pr_err ("Couldn't map the system table!\n" ); +return -ENOMEM ; + }memcpy (&efi_systab, efi.systab,sizeof (efi_system_table_t));early_iounmap (efi.systab,sizeof (efi_system_table_t)); efi.systab = &efi_systab;
@@ -450,16 +452,20 @@ static void __init efi_systab_init(void *phys)/* * Verify the EFI Table */ -if (efi.systab->hdr.signature !=EFI_SYSTEM_TABLE_SIGNATURE ) +if (efi.systab->hdr.signature !=EFI_SYSTEM_TABLE_SIGNATURE ) {pr_err ("System table signature incorrect!\n" ); +return -EINVAL ; + }if ((efi.systab->hdr.revision >>16 ) ==0 )pr_err ("Warning: System table version " "%d.%02d, expected 1.00 or greater!\n" , efi.systab->hdr.revision >>16 , efi.systab->hdr.revision &0xffff ); + +return 0 ; } -static void __init efi_config_init (u64 tables,int nr_tables) +static int __init efi_config_init (u64 tables,int nr_tables) {efi_config_table_t *config_tables;int i, sz =sizeof (efi_config_table_t);
@@ -469,8 +475,10 @@ static void __init efi_config_init(u64 tables, int nr_tables)*/ config_tables =early_ioremap (efi.systab->tables, efi.systab->nr_tables * sz); -if (config_tables ==NULL ) +if (config_tables ==NULL ) {pr_err ("Could not map Configuration table!\n" ); +return -ENOMEM ; + }pr_info ("" );for (i =0 ; i < efi.systab->nr_tables; i++) {
@@ -504,9 +512,11 @@ static void __init efi_config_init(u64 tables, int nr_tables) }pr_cont ("\n" );early_iounmap (config_tables, efi.systab->nr_tables * sz); + +return 0 ; } -static void __init efi_runtime_init (void ) +static int __init efi_runtime_init (void ) {efi_runtime_services_t *runtime;
@@ -518,37 +528,44 @@ static void __init efi_runtime_init(void)*/ runtime =early_ioremap ((unsigned long )efi.systab->runtime,sizeof (efi_runtime_services_t)); -if (runtime !=NULL ) { -/* -* We will only need *early* access to the following -* two EFI runtime services before set_virtual_address_map -* is invoked. -*/ - efi_phys.get_time = (efi_get_time_t *)runtime->get_time; - efi_phys.set_virtual_address_map = - (efi_set_virtual_address_map_t *) - runtime->set_virtual_address_map; -/* -* Make efi_get_time can be called before entering -* virtual mode. -*/ - efi.get_time = phys_efi_get_time; - }else +if (!runtime) {pr_err ("Could not map the runtime service table!\n" ); +return -ENOMEM ; + } +/* +* We will only need *early* access to the following +* two EFI runtime services before set_virtual_address_map +* is invoked. +*/ + efi_phys.get_time = (efi_get_time_t *)runtime->get_time; + efi_phys.set_virtual_address_map = + (efi_set_virtual_address_map_t *) + runtime->set_virtual_address_map; +/* +* Make efi_get_time can be called before entering +* virtual mode. +*/ + efi.get_time = phys_efi_get_time;early_iounmap (runtime,sizeof (efi_runtime_services_t)); + +return 0 ; } -static void __init efi_memmap_init (void ) +static int __init efi_memmap_init (void ) {/* Map the EFI memory map */ memmap.map =early_ioremap ((unsigned long )memmap.phys_map, memmap.nr_map * memmap.desc_size); -if (memmap.map ==NULL ) +if (memmap.map ==NULL ) {pr_err ("Could not map the memory map!\n" ); +return -ENOMEM ; + } memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);if (add_efi_memmap)do_add_efi_memmap (); + +return 0 ; }void __init efi_init (void )
@@ -566,7 +583,10 @@ void __init efi_init(void) ((__u64)boot_params.efi_info.efi_systab_hi<<32));#endif -efi_systab_init (efi_phys.systab); +if (efi_systab_init (efi_phys.systab)) { + efi_enabled =0 ; +return ; + }/* * Show what we know for posterity
@@ -584,11 +604,20 @@ void __init efi_init(void) efi.systab->hdr.revision >>16 , efi.systab->hdr.revision & 0xffff, vendor); -efi_config_init (efi.systab->tables, efi.systab->nr_tables); +if (efi_config_init (efi.systab->tables, efi.systab->nr_tables)) { + efi_enabled =0 ; +return ; + } -efi_runtime_init (); +if (efi_runtime_init ()) { + efi_enabled =0 ; +return ; + } -efi_memmap_init (); +if (efi_memmap_init ()) { + efi_enabled =0 ; +return ; + }#ifdef CONFIG_X86_32 x86_platform.get_wallclock = efi_get_time;
Signature · 1 line
1.7.9.209.gb6b3b
[tip:x86/eficross] x86, efi: Add basic error handling
Commit-ID: 140bf275d3e89e9b36851d5cf498dbbbecdf7ca8 Gitweb: http://git.kernel.org/tip/140bf275d3e89e9b36851d5cf498dbbbecdf7ca8 Author: Olof Johansson <[email protected]> AuthorDate: Sun, 12 Feb 2012 13:24:28 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Thu, 23 Feb 2012 18:54:39 -0800
x86, efi: Add basic error handling
It's not perfect, but way better than before. Mark efi_enabled as false in case of error and at least stop dereferencing pointers that are known to be invalid.
The only significant missing piece is the lack of undoing the memblock_reserve of the memory that efi marks as in use. On the other hand, it's not a large amount of memory, and leaving it unavailable for system use should be the safer choice anyway.
--- arch/x86/platform/efi/efi.c | 85 +++++++++++++++++++++++++++++-------------- 1 files changed, 57 insertions(+), 28 deletions(-)
arch/x86/platform/efi/efi.c +57 -28
@@ -430,12 +430,14 @@ static void __init efi_free_boot_services(void) } } -static void __init efi_systab_init (void *phys) +static int __init efi_systab_init (void *phys) { efi.systab =early_ioremap ((unsigned long )efi_phys.systab,sizeof (efi_system_table_t)); -if (efi.systab ==NULL ) +if (efi.systab ==NULL ) {pr_err ("Couldn't map the system table!\n" ); +return -ENOMEM ; + }memcpy (&efi_systab, efi.systab,sizeof (efi_system_table_t));early_iounmap (efi.systab,sizeof (efi_system_table_t)); efi.systab = &efi_systab;
@@ -443,16 +445,20 @@ static void __init efi_systab_init(void *phys)/* * Verify the EFI Table */ -if (efi.systab->hdr.signature !=EFI_SYSTEM_TABLE_SIGNATURE ) +if (efi.systab->hdr.signature !=EFI_SYSTEM_TABLE_SIGNATURE ) {pr_err ("System table signature incorrect!\n" ); +return -EINVAL ; + }if ((efi.systab->hdr.revision >>16 ) ==0 )pr_err ("Warning: System table version " "%d.%02d, expected 1.00 or greater!\n" , efi.systab->hdr.revision >>16 , efi.systab->hdr.revision &0xffff ); + +return 0 ; } -static void __init efi_config_init (u64 tables,int nr_tables) +static int __init efi_config_init (u64 tables,int nr_tables) {efi_config_table_t *config_tables;int i, sz =sizeof (efi_config_table_t);
@@ -462,8 +468,10 @@ static void __init efi_config_init(u64 tables, int nr_tables)*/ config_tables =early_ioremap (efi.systab->tables, efi.systab->nr_tables * sz); -if (config_tables ==NULL ) +if (config_tables ==NULL ) {pr_err ("Could not map Configuration table!\n" ); +return -ENOMEM ; + }pr_info ("" );for (i =0 ; i < efi.systab->nr_tables; i++) {
@@ -497,9 +505,11 @@ static void __init efi_config_init(u64 tables, int nr_tables) }pr_cont ("\n" );early_iounmap (config_tables, efi.systab->nr_tables * sz); + +return 0 ; } -static void __init efi_runtime_init (void ) +static int __init efi_runtime_init (void ) {efi_runtime_services_t *runtime;
@@ -511,37 +521,44 @@ static void __init efi_runtime_init(void)*/ runtime =early_ioremap ((unsigned long )efi.systab->runtime,sizeof (efi_runtime_services_t)); -if (runtime !=NULL ) { -/* -* We will only need *early* access to the following -* two EFI runtime services before set_virtual_address_map -* is invoked. -*/ - efi_phys.get_time = (efi_get_time_t *)runtime->get_time; - efi_phys.set_virtual_address_map = - (efi_set_virtual_address_map_t *) - runtime->set_virtual_address_map; -/* -* Make efi_get_time can be called before entering -* virtual mode. -*/ - efi.get_time = phys_efi_get_time; - }else +if (!runtime) {pr_err ("Could not map the runtime service table!\n" ); +return -ENOMEM ; + } +/* +* We will only need *early* access to the following +* two EFI runtime services before set_virtual_address_map +* is invoked. +*/ + efi_phys.get_time = (efi_get_time_t *)runtime->get_time; + efi_phys.set_virtual_address_map = + (efi_set_virtual_address_map_t *) + runtime->set_virtual_address_map; +/* +* Make efi_get_time can be called before entering +* virtual mode. +*/ + efi.get_time = phys_efi_get_time;early_iounmap (runtime,sizeof (efi_runtime_services_t)); + +return 0 ; } -static void __init efi_memmap_init (void ) +static int __init efi_memmap_init (void ) {/* Map the EFI memory map */ memmap.map =early_ioremap ((unsigned long )memmap.phys_map, memmap.nr_map * memmap.desc_size); -if (memmap.map ==NULL ) +if (memmap.map ==NULL ) {pr_err ("Could not map the memory map!\n" ); +return -ENOMEM ; + } memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);if (add_efi_memmap)do_add_efi_memmap (); + +return 0 ; }void __init efi_init (void )
@@ -559,7 +576,10 @@ void __init efi_init(void) ((__u64)boot_params.efi_info.efi_systab_hi<<32));#endif -efi_systab_init (efi_phys.systab); +if (efi_systab_init (efi_phys.systab)) { + efi_enabled =0 ; +return ; + }/* * Show what we know for posterity
@@ -577,11 +597,20 @@ void __init efi_init(void) efi.systab->hdr.revision >>16 , efi.systab->hdr.revision & 0xffff, vendor); -efi_config_init (efi.systab->tables, efi.systab->nr_tables); +if (efi_config_init (efi.systab->tables, efi.systab->nr_tables)) { + efi_enabled =0 ; +return ; + } -efi_runtime_init (); +if (efi_runtime_init ()) { + efi_enabled =0 ; +return ; + } -efi_memmap_init (); +if (efi_memmap_init ()) { + efi_enabled =0 ; +return ; + }#ifdef CONFIG_X86_32 x86_platform.get_wallclock = efi_get_time;
PATCH v5 5/5 x86: efi: allow basic init with mixed 32/64-bit efi/kernel
In reply to Olof JohanssonTraditionally the kernel has refused to setup EFI at all if there's been a mismatch in 32/64-bit mode between EFI and the kernel.
On some platforms that boot natively through EFI (Chrome OS being one), we still need to get at least some of the static data such as memory configuration out of EFI. Runtime services aren't as critical, and it's a significant amount of work to implement switching between the operating modes to call between kernel and firmware for thise cases. So I'm ignoring it for now.
v5:
* Fixed some printk strings based on feedback
* Renamed 32/64-bit specific types to not have _ prefix
* Fixed bug in printout of efi runtime disablement
v4:
* Some of the earlier cleanup was accidentally reverted by this patch, fixed.
* Reworded some messages to not have to line wrap printk strings
v3:
* Reorganized to a series of patches to make it easier to review, and do some of the cleanups I had left out before.
v2:
* Added graceful error handling for 32-bit kernel that gets passed EFI data above 4GB.
* Removed some warnings that were missed in first version.
--- arch/x86/include/asm/efi.h | 2 +- arch/x86/kernel/setup.c | 10 ++- arch/x86/platform/efi/efi.c | 164 +++++++++++++++++++++++++++++++++++++------ include/linux/efi.h | 45 ++++++++++++ 4 files changed, 196 insertions(+), 25 deletions(-)
arch/x86/include/asm/efi.h +1 -1
@@ -90,7 +90,7 @@ extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,extern int add_efi_memmap;extern void efi_set_executable (efi_memory_desc_t *md,bool executable); -extern void efi_memblock_x86_reserve_range (void ); +extern int efi_memblock_x86_reserve_range (void );extern void efi_call_phys_prelog (void );extern void efi_call_phys_epilog (void );
arch/x86/kernel/setup.c +8 -2
@@ -751,10 +751,16 @@ void __init setup_arch(char **cmdline_p)#endif #ifdef CONFIG_EFI if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, -EFI_LOADER_SIGNATURE ,4 )) { +"EL32" ,4 )) { efi_enabled =1 ; -efi_memblock_x86_reserve_range (); + efi_64bit = false; + }else if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, +"EL64" ,4 )) { + efi_enabled =1 ; + efi_64bit = true; } +if (efi_enabled &&efi_memblock_x86_reserve_range ()) + efi_enabled =0 ;#endif x86_init.oem.arch_setup ();
arch/x86/platform/efi/efi.c +142 -22
253 lines not on this page · raw message
include/linux/efi.h +45 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.9.209.gb6b3b
Re: [PATCH v5 5/5] x86: efi: allow basic init with mixed 32/64-bit efi/kernel
Quoted 28 lines · Olof Johansson
Traditionally the kernel has refused to setup EFI at all if there's been a mismatch in 32/64-bit mode between EFI and the kernel.
On some platforms that boot natively through EFI (Chrome OS being one), we still need to get at least some of the static data such as memory configuration out of EFI. Runtime services aren't as critical, and it's a significant amount of work to implement switching between the operating modes to call between kernel and firmware for thise cases. So I'm ignoring it for now.
v5:
* Fixed some printk strings based on feedback
* Renamed 32/64-bit specific types to not have _ prefix
* Fixed bug in printout of efi runtime disablementv4:
* Some of the earlier cleanup was accidentally reverted by this patch, fixed.
* Reworded some messages to not have to line wrap printk stringsv3:
* Reorganized to a series of patches to make it easier to review, and do some of the cleanups I had left out before.v2:
* Added graceful error handling for 32-bit kernel that gets passed EFI data above 4GB.
* Removed some warnings that were missed in first version.
Quoted 7 lines
Signed-off-by Olof Johansson <[email protected]>--- arch/x86/include/asm/efi.h | 2 +- arch/x86/kernel/setup.c | 10 ++- arch/x86/platform/efi/efi.c | 164 +++++++++++++++++++++++++++++++++++++------ include/linux/efi.h | 45 ++++++++++++ 4 files changed, 196 insertions(+), 25 deletions(-)
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
[tip:x86/eficross] x86, efi: Allow basic init with mixed 32/ 64-bit efi/kernel
In reply to Olof JohanssonCommit-ID: 1adbfa3511ee1c1118e16a9a0246870f12fef4e6 Gitweb: http://git.kernel.org/tip/1adbfa3511ee1c1118e16a9a0246870f12fef4e6 Author: Olof Johansson <[email protected]> AuthorDate: Sun, 12 Feb 2012 13:24:29 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Thu, 23 Feb 2012 18:54:51 -0800
x86, efi: Allow basic init with mixed 32/64-bit efi/kernel
Traditionally the kernel has refused to setup EFI at all if there's been a mismatch in 32/64-bit mode between EFI and the kernel.
On some platforms that boot natively through EFI (Chrome OS being one), we still need to get at least some of the static data such as memory configuration out of EFI. Runtime services aren't as critical, and it's a significant amount of work to implement switching between the operating modes to call between kernel and firmware for thise cases. So I'm ignoring it for now.
v5:
* Fixed some printk strings based on feedback
* Renamed 32/64-bit specific types to not have _ prefix
* Fixed bug in printout of efi runtime disablement
v4:
* Some of the earlier cleanup was accidentally reverted by this patch, fixed.
* Reworded some messages to not have to line wrap printk strings
v3:
* Reorganized to a series of patches to make it easier to review, and do some of the cleanups I had left out before.
v2:
* Added graceful error handling for 32-bit kernel that gets passed EFI data above 4GB.
* Removed some warnings that were missed in first version.
--- arch/x86/include/asm/efi.h | 2 +- arch/x86/kernel/setup.c | 10 ++- arch/x86/platform/efi/efi.c | 164 +++++++++++++++++++++++++++++++++++++------ include/linux/efi.h | 45 ++++++++++++ 4 files changed, 196 insertions(+), 25 deletions(-)
arch/x86/include/asm/efi.h +1 -1
@@ -95,7 +95,7 @@ extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,extern int add_efi_memmap;extern void efi_set_executable (efi_memory_desc_t *md,bool executable); -extern void efi_memblock_x86_reserve_range (void ); +extern int efi_memblock_x86_reserve_range (void );extern void efi_call_phys_prelog (void );extern void efi_call_phys_epilog (void );
arch/x86/kernel/setup.c +8 -2
@@ -749,10 +749,16 @@ void __init setup_arch(char **cmdline_p)#endif #ifdef CONFIG_EFI if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, -EFI_LOADER_SIGNATURE ,4 )) { +"EL32" ,4 )) { efi_enabled =1 ; -efi_memblock_x86_reserve_range (); + efi_64bit = false; + }else if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, +"EL64" ,4 )) { + efi_enabled =1 ; + efi_64bit = true; } +if (efi_enabled &&efi_memblock_x86_reserve_range ()) + efi_enabled =0 ;#endif x86_init.oem.arch_setup ();
arch/x86/platform/efi/efi.c +142 -22
253 lines not on this page · raw message
include/linux/efi.h +45 -0
63 lines not on this page · raw message
Re: [PATCH v5 5/5] x86: efi: allow basic init with mixed 32/64-bit efi/kernel
In reply to Olof JohanssonAs you say, this isn't a full solution - we'll need additional thunking to fix the general case. But it's a step in the right direction and it's better than what we have now, so ACK.
Signature · 1 line
Matthew Garrett | [email protected]