efi: merge x86 and ia64 code
PATCH 1/2 efi: merge x86 and ia64 code
We currently have two almost entirely independent EFI implementations in the kernel, with the x86 code having begun as a modified version of the ia64 code. Forthcoming ARM platforms will use EFI and there are experimental ports for some MIPS platforms, so continuing this "One EFI implementation per architecture" model is likely to result in massive bug duplication. This patch merges the common elements of the ia64 and x86 implementations, which should make adding any future platforms a simple matter of adding setup code and the appropriate stubs for accessing EFI resources and making calls.
--- arch/ia64/include/asm/efi.h | 26 ++ arch/ia64/include/asm/sal.h | 3 - arch/ia64/kernel/efi.c | 634 ++++---------------------------------- arch/ia64/kernel/efi_stub.S | 4 +- arch/x86/Kconfig | 4 + arch/x86/include/asm/efi.h | 37 +-- arch/x86/platform/efi/efi.c | 555 ++-------------------------------- arch/x86/platform/efi/efi_64.c | 44 ++- drivers/firmware/Makefile | 1 + drivers/firmware/efi/Makefile | 1 + drivers/firmware/efi/efi.c | 657 ++++++++++++++++++++++++++++++++++++++++ include/linux/efi.h | 57 ++++- init/main.c | 2 +- 13 files changed, 879 insertions(+), 1146 deletions(-) create mode 100644 arch/ia64/include/asm/efi.h create mode 100644 drivers/firmware/efi/Makefile create mode 100644 drivers/firmware/efi/efi.c
arch/ia64/include/asm/efi.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _ASM_X86_EFI_H +#define _ASM_X86_EFI_H + +#define EFI_DEBUG 0 + +#define efi_map (x, y) __va(x) +#define efi_unmap (x, y) + +extern efi_status_t efi_real_call_phys (void *, ...); + +#define efi_call_phys(f, args...) efi_real_call_phys(__va(f), args); +#define efi_call_virt(f, args...) \ +((efi_##f##_t *)efi.systab->runtime->f)(args) + +#define efi_phys_arg (arg) (arg ? ((__typeof__(arg)) ia64_tpa(arg)) : arg) + +void *efi_call_prelog (void ); +void efi_call_epilog (void *arg); + +#define efi_call_phys_prelog () efi_call_prelog() +#define efi_call_phys_epilog (x) efi_call_epilog(x) + +#define efi_call_virt_prelog () efi_call_prelog() +#define efi_call_virt_epilog (x) efi_call_epilog(x) + +#endif
arch/ia64/include/asm/sal.h +0 -3
@@ -296,9 +296,6 @@ enum { EFI_GUID(0xe429faf8, 0x3cb7, 0x11d4, 0xbc, 0xa7, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81)#define SAL_PLAT_BUS_ERR_SECT_GUID \ EFI_GUID(0xe429faf9, 0x3cb7, 0x11d4, 0xbc, 0xa7, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81) -#define PROCESSOR_ABSTRACTION_LAYER_OVERWRITE_GUID \ - EFI_GUID(0x6cb0a200, 0x893a, 0x11da, 0x96, 0xd2, 0x0, 0x10, 0x83, 0xff, \ - 0xca, 0x4d)#define MAX_CACHE_ERRORS 6#define MAX_TLB_ERRORS 6
arch/ia64/kernel/efi.c +62 -572
795 lines not on this page · raw message
arch/ia64/kernel/efi_stub.S +2 -2
@@ -42,7 +42,7 @@ * r8 = EFI_STATUS returned by called function */ -GLOBAL_ENTRY(efi_call_phys) +GLOBAL_ENTRY(efi_real_call_phys) .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(8) alloc loc1=ar.pfs,8,7,7,0 ld8 r2=[in0],8 // load EFI function's entry point
@@ -83,4 +83,4 @@ GLOBAL_ENTRY(efi_call_phys) mov rp=loc0 mov gp=loc2 br.ret.sptk.many rp -END(efi_call_phys) +END(efi_real_call_phys)
arch/x86/Kconfig +4 -0
@@ -1437,6 +1437,10 @@ config EFI resultant kernel should continue to boot on existing non-EFI platforms. +config EFI_THUNK_CALLS + def_bool y + depends on X86_64 && EFI + config SECCOMP def_bool y prompt "Enable seccomp to safely compute untrusted bytecode"
arch/x86/include/asm/efi.h +9 -28
@@ -1,20 +1,12 @@#ifndef _ASM_X86_EFI_H#define _ASM_X86_EFI_H +#define EFI_DEBUG 1 +#ifdef CONFIG_X86_32 extern unsigned long asmlinkage efi_call_phys (void *, ...); -#define efi_call_phys0 (f) efi_call_phys(f) -#define efi_call_phys1 (f, a1) efi_call_phys(f, a1) -#define efi_call_phys2 (f, a1, a2) efi_call_phys(f, a1, a2) -#define efi_call_phys3 (f, a1, a2, a3) efi_call_phys(f, a1, a2, a3) -#define efi_call_phys4 (f, a1, a2, a3, a4) \ - efi_call_phys(f, a1, a2, a3, a4) -#define efi_call_phys5 (f, a1, a2, a3, a4, a5) \ - efi_call_phys(f, a1, a2, a3, a4, a5) -#define efi_call_phys6 (f, a1, a2, a3, a4, a5, a6) \ - efi_call_phys(f, a1, a2, a3, a4, a5, a6)/* * Wrap all the virtual calls in a way that forces the parameters on the stack. */
@@ -22,21 +14,10 @@ extern unsigned long asmlinkage efi_call_phys(void *, ...); #define efi_call_virt(f, args...) \ ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args) -#define efi_call_virt0 (f) efi_call_virt(f) -#define efi_call_virt1 (f, a1) efi_call_virt(f, a1) -#define efi_call_virt2 (f, a1, a2) efi_call_virt(f, a1, a2) -#define efi_call_virt3 (f, a1, a2, a3) efi_call_virt(f, a1, a2, a3) -#define efi_call_virt4 (f, a1, a2, a3, a4) \ - efi_call_virt(f, a1, a2, a3, a4) -#define efi_call_virt5 (f, a1, a2, a3, a4, a5) \ - efi_call_virt(f, a1, a2, a3, a4, a5) -#define efi_call_virt6 (f, a1, a2, a3, a4, a5, a6) \ - efi_call_virt(f, a1, a2, a3, a4, a5, a6) - -#define efi_ioremap (addr, size, type) ioremap_cache(addr, size) -#else /* !CONFIG_X86_32 */ +#define efi_phys_arg (arg) (arg) +extern u64 efi_call0 (void *fp);extern u64 efi_call1 (void *fp,u64 arg1);extern u64 efi_call2 (void *fp,u64 arg1,u64 arg2);
@@ -84,16 +65,16 @@ extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,efi_call6 ((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6)) -extern void __iomem *efi_ioremap (unsigned long addr,unsigned long size, -u32 type); -#endif /* CONFIG_X86_32 */ 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 void efi_call_phys_prelog (void ); -extern void efi_call_phys_epilog (void ); +extern void *efi_call_phys_prelog (void ); +extern void efi_call_phys_epilog (void *opaque); + +#define efi_call_virt_prelog (x) NULL +#define efi_call_virt_epilog (x) {}#ifndef CONFIG_EFI /*
arch/x86/platform/efi/efi.c +27 -528
621 lines not on this page · raw message
arch/x86/platform/efi/efi_64.c +33 -11
68 lines not on this page · raw message
drivers/firmware/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o obj-$(CONFIG_SIGMA) += sigma.o obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ +obj-$(CONFIG_EFI) += efi/
drivers/firmware/efi/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_EFI) += efi.o
drivers/firmware/efi/efi.c new file +657 -0
657 lines not on this page · raw message
include/linux/efi.h +56 -1
99 lines not on this page · raw message
init/main.c +1 -1
@@ -596,7 +596,7 @@ asmlinkage void __init start_kernel(void)anon_vma_init ();#ifdef CONFIG_X86 if (efi_enabled) -efi_enter_virtual_mode (); +efi_enter_virtual_mode (true);#endif thread_info_cache_init ();cred_init ();
Signature · 1 line
1.7.6
PATCH 2/2 MAINTAINERS: Add a maintainer for EFI
Since people other than ia64 are actually trying to use this now, it should probably be maintained. Sigh.
--- MAINTAINERS | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
MAINTAINERS +6 -0
@@ -2421,6 +2421,12 @@ T: git git://git.alsa-project.org/alsa-kernel.git S: Maintained F: sound/usb/misc/ua101.c +EFI +M: Matthew Garrett <[email protected]> +L: [email protected] +S: Maintained +F: drivers/firmware/efi/ + EFIFB FRAMEBUFFER DRIVER L: [email protected] M: Peter Jones <[email protected]>
Signature · 1 line
1.7.6
Re: [PATCH 2/2] MAINTAINERS: Add a maintainer for EFI
MAINTAINERS
Quoted 3 lines · Matthew Garrett
Since people other than ia64 are actually trying to use this now, it should probably be maintained. Sigh.
MAINTAINERS +0
-0
[]
MAINTAINERS T: git git://git.alsa-project.org/alsa-kernel.git · line 2428
Quoted 5 lines
MAINTAINERS +5
-0+EFI +M: Matthew Garrett <[email protected]> +L: [email protected] +S: Maintained +F: drivers/firmware/efi/
Hi Matt.
Lucky you...
Please don't add an "L: lkml" entry.
It's the default. No other entry but
the last one uses it.
H. Peter Anvin
reviewerQuoted 11 lines · Matthew Garrett
We currently have two almost entirely independent EFI implementations in the kernel, with the x86 code having begun as a modified version of the ia64 code. Forthcoming ARM platforms will use EFI and there are experimental ports for some MIPS platforms, so continuing this "One EFI implementation per architecture" model is likely to result in massive bug duplication. This patch merges the common elements of the ia64 and x86 implementations, which should make adding any future platforms a simple matter of adding setup code and the appropriate stubs for accessing EFI resources and making calls.
Signed-off-by Matthew Garrett <[email protected]>
Hi Matt,
I get a build error on x86-32:
/home/hpa/kernel/linux-2.6-tip.efi/arch/x86/platform/efi/efi_32.c:43:
error: conflicting types for ‘efi_call_phys_prelog’ /home/hpa/kernel/linux-2.6-tip.efi/arch/x86/include/asm/efi.h:73: note:
previous declaration of ‘efi_call_phys_prelog’ was here /home/hpa/kernel/linux-2.6-tip.efi/arch/x86/platform/efi/efi_32.c:85:
error: conflicting types for ‘efi_call_phys_epilog’ /home/hpa/kernel/linux-2.6-tip.efi/arch/x86/include/asm/efi.h:74: note:
previous declaration of ‘efi_call_phys_epilog’ was here make[5]: *** [arch/x86/platform/efi/efi_32.o] Error 1
-hpa
Quoted 11 lines · H. Peter Anvin
I get a build error on x86-32:
/home/hpa/kernel/linux-2.6-tip.efi/arch/x86/platform/efi/efi_32.c:43:
error: conflicting types for ‘efi_call_phys_prelog’/home/hpa/kernel/linux-2.6-tip.efi/arch/x86/include/asm/efi.h:73: note:
previous declaration of ‘efi_call_phys_prelog’ was here/home/hpa/kernel/linux-2.6-tip.efi/arch/x86/platform/efi/efi_32.c:85:
error: conflicting types for ‘efi_call_phys_epilog’/home/hpa/kernel/linux-2.6-tip.efi/arch/x86/include/asm/efi.h:74: note:
previous declaration of ‘efi_call_phys_epilog’ was here make[5]: *** [arch/x86/platform/efi/efi_32.o] Error 1
Oops.
It's sadly much easier to test IA64 than it is to test 32-bit EFI booting, but this one should at least build and link.
Signature · 1 line
Matthew Garrett | [email protected]
PATCH v2 1/2 efi: merge x86 and ia64 code
In reply to H. Peter AnvinWe currently have two almost entirely independent EFI implementations in the kernel, with the x86 code having begun as a modified version of the ia64 code. Forthcoming ARM platforms will use EFI and there are experimental ports for some MIPS platforms, so continuing this "One EFI implementation per architecture" model is likely to result in massive bug duplication. This patch merges the common elements of the ia64 and x86 implementations, which should make adding any future platforms a simple matter of adding setup code and the appropriate stubs for accessing EFI resources and making calls.
--- arch/ia64/include/asm/efi.h | 26 ++ arch/ia64/include/asm/sal.h | 3 - arch/ia64/kernel/efi.c | 634 ++++---------------------------------- arch/ia64/kernel/efi_stub.S | 4 +- arch/x86/Kconfig | 4 + arch/x86/include/asm/efi.h | 39 +-- arch/x86/platform/efi/efi.c | 555 ++-------------------------------- arch/x86/platform/efi/efi_32.c | 6 +- arch/x86/platform/efi/efi_64.c | 44 ++- drivers/firmware/Makefile | 1 + drivers/firmware/efi/Makefile | 1 + drivers/firmware/efi/efi.c | 657 ++++++++++++++++++++++++++++++++++++++++ include/linux/efi.h | 57 ++++- init/main.c | 2 +- 14 files changed, 885 insertions(+), 1148 deletions(-) create mode 100644 arch/ia64/include/asm/efi.h create mode 100644 drivers/firmware/efi/Makefile create mode 100644 drivers/firmware/efi/efi.c
arch/ia64/include/asm/efi.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _ASM_X86_EFI_H +#define _ASM_X86_EFI_H + +#define EFI_DEBUG 0 + +#define efi_map (x, y) __va(x) +#define efi_unmap (x, y) + +extern efi_status_t efi_real_call_phys (void *, ...); + +#define efi_call_phys(f, args...) efi_real_call_phys(__va(f), args); +#define efi_call_virt(f, args...) \ +((efi_##f##_t *)efi.systab->runtime->f)(args) + +#define efi_phys_arg (arg) (arg ? ((__typeof__(arg)) ia64_tpa(arg)) : arg) + +void *efi_call_prelog (void ); +void efi_call_epilog (void *arg); + +#define efi_call_phys_prelog () efi_call_prelog() +#define efi_call_phys_epilog (x) efi_call_epilog(x) + +#define efi_call_virt_prelog () efi_call_prelog() +#define efi_call_virt_epilog (x) efi_call_epilog(x) + +#endif
arch/ia64/include/asm/sal.h +0 -3
@@ -296,9 +296,6 @@ enum { EFI_GUID(0xe429faf8, 0x3cb7, 0x11d4, 0xbc, 0xa7, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81)#define SAL_PLAT_BUS_ERR_SECT_GUID \ EFI_GUID(0xe429faf9, 0x3cb7, 0x11d4, 0xbc, 0xa7, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81) -#define PROCESSOR_ABSTRACTION_LAYER_OVERWRITE_GUID \ - EFI_GUID(0x6cb0a200, 0x893a, 0x11da, 0x96, 0xd2, 0x0, 0x10, 0x83, 0xff, \ - 0xca, 0x4d)#define MAX_CACHE_ERRORS 6#define MAX_TLB_ERRORS 6
arch/ia64/kernel/efi.c +62 -572
795 lines not on this page · raw message
arch/ia64/kernel/efi_stub.S +2 -2
@@ -42,7 +42,7 @@ * r8 = EFI_STATUS returned by called function */ -GLOBAL_ENTRY(efi_call_phys) +GLOBAL_ENTRY(efi_real_call_phys) .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(8) alloc loc1=ar.pfs,8,7,7,0 ld8 r2=[in0],8 // load EFI function's entry point
@@ -83,4 +83,4 @@ GLOBAL_ENTRY(efi_call_phys) mov rp=loc0 mov gp=loc2 br.ret.sptk.many rp -END(efi_call_phys) +END(efi_real_call_phys)
arch/x86/Kconfig +4 -0
@@ -1437,6 +1437,10 @@ config EFI resultant kernel should continue to boot on existing non-EFI platforms. +config EFI_THUNK_CALLS + def_bool y + depends on X86_64 && EFI + config SECCOMP def_bool y prompt "Enable seccomp to safely compute untrusted bytecode"
arch/x86/include/asm/efi.h +11 -28
@@ -1,20 +1,14 @@#ifndef _ASM_X86_EFI_H#define _ASM_X86_EFI_H +#define EFI_DEBUG 1 +#ifdef CONFIG_X86_32 +#define efi_ioremap (x) (u32) ioremap_cache(x->phys_addr, efi_md_size(x)) +extern unsigned long asmlinkage efi_call_phys (void *, ...); -#define efi_call_phys0 (f) efi_call_phys(f) -#define efi_call_phys1 (f, a1) efi_call_phys(f, a1) -#define efi_call_phys2 (f, a1, a2) efi_call_phys(f, a1, a2) -#define efi_call_phys3 (f, a1, a2, a3) efi_call_phys(f, a1, a2, a3) -#define efi_call_phys4 (f, a1, a2, a3, a4) \ - efi_call_phys(f, a1, a2, a3, a4) -#define efi_call_phys5 (f, a1, a2, a3, a4, a5) \ - efi_call_phys(f, a1, a2, a3, a4, a5) -#define efi_call_phys6 (f, a1, a2, a3, a4, a5, a6) \ - efi_call_phys(f, a1, a2, a3, a4, a5, a6)/* * Wrap all the virtual calls in a way that forces the parameters on the stack. */
@@ -22,19 +16,6 @@ extern unsigned long asmlinkage efi_call_phys(void *, ...); #define efi_call_virt(f, args...) \ ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args) -#define efi_call_virt0 (f) efi_call_virt(f) -#define efi_call_virt1 (f, a1) efi_call_virt(f, a1) -#define efi_call_virt2 (f, a1, a2) efi_call_virt(f, a1, a2) -#define efi_call_virt3 (f, a1, a2, a3) efi_call_virt(f, a1, a2, a3) -#define efi_call_virt4 (f, a1, a2, a3, a4) \ - efi_call_virt(f, a1, a2, a3, a4) -#define efi_call_virt5 (f, a1, a2, a3, a4, a5) \ - efi_call_virt(f, a1, a2, a3, a4, a5) -#define efi_call_virt6 (f, a1, a2, a3, a4, a5, a6) \ - efi_call_virt(f, a1, a2, a3, a4, a5, a6) - -#define efi_ioremap (addr, size, type) ioremap_cache(addr, size) -#else /* !CONFIG_X86_32 */ extern u64 efi_call0 (void *fp);
@@ -84,16 +65,18 @@ extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,efi_call6 ((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6)) -extern void __iomem *efi_ioremap (unsigned long addr,unsigned long size, -u32 type); -#endif /* CONFIG_X86_32 */ +#define efi_phys_arg (arg) arg +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 void efi_call_phys_prelog (void ); -extern void efi_call_phys_epilog (void ); +extern void *efi_call_phys_prelog (void ); +extern void efi_call_phys_epilog (void *opaque); + +#define efi_call_virt_prelog (x) NULL +#define efi_call_virt_epilog (x) {}#ifndef CONFIG_EFI /*
arch/x86/platform/efi/efi.c +27 -528
621 lines not on this page · raw message
arch/x86/platform/efi/efi_32.c +4 -2
@@ -40,7 +40,7 @@static unsigned long efi_rt_eflags;static pgd_t efi_bak_pg_dir_pointer[2 ]; -void efi_call_phys_prelog (void ) +void *efi_call_phys_prelog (void ) {unsigned long cr4;unsigned long temp;
@@ -80,9 +80,11 @@ void efi_call_phys_prelog(void) gdt_descr.address =__pa (get_cpu_gdt_table (0 )); gdt_descr.size =GDT_SIZE -1 ;load_gdt (&gdt_descr); + +return NULL ; } -void efi_call_phys_epilog (void ) +void efi_call_phys_epilog (void *opaque) {unsigned long cr4;struct desc_ptr gdt_descr;
arch/x86/platform/efi/efi_64.c +33 -11
68 lines not on this page · raw message
drivers/firmware/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o obj-$(CONFIG_SIGMA) += sigma.o obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ +obj-$(CONFIG_EFI) += efi/
drivers/firmware/efi/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_EFI) += efi.o
drivers/firmware/efi/efi.c new file +657 -0
657 lines not on this page · raw message
include/linux/efi.h +56 -1
99 lines not on this page · raw message
init/main.c +1 -1
@@ -596,7 +596,7 @@ asmlinkage void __init start_kernel(void)anon_vma_init ();#ifdef CONFIG_X86 if (efi_enabled) -efi_enter_virtual_mode (); +efi_enter_virtual_mode (true);#endif thread_info_cache_init ();cred_init ();
Signature · 1 line
1.7.6
PATCH v2 2/2 MAINTAINERS: Add a maintainer for EFI
Since people other than ia64 are actually trying to use this now, it should probably be maintained. Sigh.
--- MAINTAINERS | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
MAINTAINERS +5 -0
@@ -2421,6 +2421,11 @@ T: git git://git.alsa-project.org/alsa-kernel.git S: Maintained F: sound/usb/misc/ua101.c +EFI +M: Matthew Garrett <[email protected]> +S: Maintained +F: drivers/firmware/efi/ + EFIFB FRAMEBUFFER DRIVER L: [email protected] M: Peter Jones <[email protected]>
Signature · 1 line
1.7.6