Currently, we support mixed mode (64-bit Linux running on 32-bit firmware) by explicitly reasoning about pointer sizes for every call into the firmware: on x86, there are 32-bit and 64-bit versions of each protocol interface, and each call gets routed via one of the two, depending on the native size of the firmware. There is a lot of casting and pointer mangling involved in this, and as a result, we end up with much less coverage in terms of type checking by the compiler, due to the indirection via an anonymous, variadic thunking routine. This peculiarity of x86 is also leaking into generic EFI code, which is shared with ia64, arm64, ARM and likely RiscV in the future. So let's try to clean this up a bit. The approach taken by this series is to replace the 32/64 bit distinction with a distinction between native calls and mixed mode calls, where the former can be either 32 or 64 bit [depending on the platform] and use the ordinary native protocol definitions, while mixed mode calls retain the existing casting/thunking approach based on the 32-bit protocol definitions. Given that GCC now supports emitting function calls using the MS calling convention, we can get rid of all the wrapping and casting, and emit the indirect calls directly. Changes since v1: - Substantially more cleanup work to simplify and hide the mixed mode handling in generic EFI code. - Get rid of all the pointless passing around of sys_table_arg - Incorporate an updated version of Matthew's PCI DMA disable patch using EFI events to defer poking the busmaster bits until after all the ordinary ExitBootServices() callbacks have executed. Code can be found here https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=efistub-x86-cleanup-v2 Cc: Hans de Goede <hdegoede@xxxxxxxxxx> Cc: Matthew Garrett <matthewgarrett@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Andy Lutomirski <luto@xxxxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Arvind Sankar <nivedita@xxxxxxxxxxxx> Ard Biesheuvel (20): efi/libstub: remove unused __efi_call_early() macro efi/x86: rename efi_is_native() to efi_is_mixed() efi/libstub: use a helper to iterate over a EFI handle array efi/libstub: extend native protocol definitions with mixed_mode aliases efi/libstub: distinguish between native/mixed not 32/64 bit efi/libstub/x86: use mixed mode helpers to populate efi_config efi/libstub: drop explicit 32/64-bit protocol definitions efi/libstub: use stricter typing for firmware function pointers efi/libstub: annotate firmware routines as __efiapi efi/libstub/x86: avoid thunking for native firmware calls efi/libstub: get rid of 'sys_table_arg' macro parameter efi/libstub: unify the efi_char16_printk implementations efi/libstub/x86: drop __efi_early() export of efi_config struct efi/libstub: drop sys_table_arg from printk routines efi/libstub: remove 'sys_table_arg' from all function prototypes efi/libstub: drop protocol argument from efi_call_proto() macro efi/libstub: drop 'table' argument from efi_table_attr() macro efi/libstub: use 'func' not 'f' as macro parameter efi/libstub: tidy up types and names of global cmdline variables efi/libstub: import type definitions for creating and signalling events Matthew Garrett (1): efi: Allow disabling PCI busmastering on bridges during boot .../admin-guide/kernel-parameters.txt | 4 + arch/arm/include/asm/efi.h | 17 +- arch/arm64/include/asm/efi.h | 16 +- arch/x86/Kconfig | 1 + arch/x86/boot/compressed/Makefile | 2 +- arch/x86/boot/compressed/eboot.c | 180 ++-- arch/x86/boot/compressed/eboot.h | 30 +- arch/x86/boot/compressed/efi_stub_32.S | 87 -- arch/x86/boot/compressed/efi_stub_64.S | 5 - arch/x86/boot/compressed/head_32.S | 8 +- arch/x86/boot/compressed/head_64.S | 16 +- arch/x86/include/asm/efi.h | 76 +- arch/x86/platform/efi/efi.c | 12 +- arch/x86/platform/efi/efi_64.c | 6 +- arch/x86/platform/efi/quirks.c | 2 +- drivers/firmware/efi/Kconfig | 22 + drivers/firmware/efi/libstub/Makefile | 2 +- drivers/firmware/efi/libstub/arm-stub.c | 98 ++- drivers/firmware/efi/libstub/arm32-stub.c | 40 +- drivers/firmware/efi/libstub/arm64-stub.c | 24 +- .../firmware/efi/libstub/efi-stub-helper.c | 226 +++-- drivers/firmware/efi/libstub/efistub.h | 35 +- drivers/firmware/efi/libstub/fdt.c | 53 +- drivers/firmware/efi/libstub/gop.c | 30 +- drivers/firmware/efi/libstub/pci.c | 116 +++ drivers/firmware/efi/libstub/random.c | 54 +- drivers/firmware/efi/libstub/secureboot.c | 6 +- drivers/firmware/efi/libstub/tpm.c | 23 +- include/linux/efi.h | 816 +++++++++--------- 29 files changed, 980 insertions(+), 1027 deletions(-) delete mode 100644 arch/x86/boot/compressed/efi_stub_32.S delete mode 100644 arch/x86/boot/compressed/efi_stub_64.S create mode 100644 drivers/firmware/efi/libstub/pci.c -- 2.17.1