1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21965aae3SH. Peter Anvin #ifndef _ASM_X86_EFI_H 31965aae3SH. Peter Anvin #define _ASM_X86_EFI_H 4bb898558SAl Viro 5df6b35f4SIngo Molnar #include <asm/fpu/api.h> 69788375dSMark Rutland #include <asm/processor-flags.h> 7c9f2a9a6SMatt Fleming #include <asm/tlb.h> 8dd84441aSDavid Woodhouse #include <asm/nospec-branch.h> 97e904a91SSai Praneeth #include <asm/mmu_context.h> 10fe379fa4SPeter Zijlstra #include <asm/ibt.h> 1114b864f4SArvind Sankar #include <linux/build_bug.h> 129b47c527SArvind Sankar #include <linux/kernel.h> 1365fddcfcSMike Rapoport #include <linux/pgtable.h> 14744937b0SIngo Molnar 159cd437acSArd Biesheuvel extern unsigned long efi_fw_vendor, efi_config_table; 163e1e00c0SArd Biesheuvel extern unsigned long efi_mixed_mode_stack_pa; 179cd437acSArd Biesheuvel 18d2f7cbe7SBorislav Petkov /* 19d2f7cbe7SBorislav Petkov * We map the EFI regions needed for runtime services non-contiguously, 20d2f7cbe7SBorislav Petkov * with preserved alignment on virtual addresses starting from -4G down 21d2f7cbe7SBorislav Petkov * for a total max space of 64G. This way, we provide for stable runtime 22d2f7cbe7SBorislav Petkov * services addresses across kernels so that a kexec'd kernel can still 23d2f7cbe7SBorislav Petkov * use them. 24d2f7cbe7SBorislav Petkov * 25d2f7cbe7SBorislav Petkov * This is the main reason why we're doing stable VA mappings for RT 26d2f7cbe7SBorislav Petkov * services. 27d2f7cbe7SBorislav Petkov */ 28d2f7cbe7SBorislav Petkov 29b8ff87a6SMatt Fleming #define EFI32_LOADER_SIGNATURE "EL32" 30b8ff87a6SMatt Fleming #define EFI64_LOADER_SIGNATURE "EL64" 31b8ff87a6SMatt Fleming 329788375dSMark Rutland #define ARCH_EFI_IRQ_FLAGS_MASK X86_EFLAGS_IF 33bb898558SAl Viro 3414b864f4SArvind Sankar /* 3514b864f4SArvind Sankar * The EFI services are called through variadic functions in many cases. These 3614b864f4SArvind Sankar * functions are implemented in assembler and support only a fixed number of 3714b864f4SArvind Sankar * arguments. The macros below allows us to check at build time that we don't 3814b864f4SArvind Sankar * try to call them with too many arguments. 3914b864f4SArvind Sankar * 4014b864f4SArvind Sankar * __efi_nargs() will return the number of arguments if it is 7 or less, and 4114b864f4SArvind Sankar * cause a BUILD_BUG otherwise. The limitations of the C preprocessor make it 4214b864f4SArvind Sankar * impossible to calculate the exact number of arguments beyond some 4314b864f4SArvind Sankar * pre-defined limit. The maximum number of arguments currently supported by 4414b864f4SArvind Sankar * any of the thunks is 7, so this is good enough for now and can be extended 4514b864f4SArvind Sankar * in the obvious way if we ever need more. 4614b864f4SArvind Sankar */ 4714b864f4SArvind Sankar 4814b864f4SArvind Sankar #define __efi_nargs(...) __efi_nargs_(__VA_ARGS__) 4914b864f4SArvind Sankar #define __efi_nargs_(...) __efi_nargs__(0, ##__VA_ARGS__, \ 5044f155b4SArd Biesheuvel __efi_arg_sentinel(9), __efi_arg_sentinel(8), \ 5114b864f4SArvind Sankar __efi_arg_sentinel(7), __efi_arg_sentinel(6), \ 5214b864f4SArvind Sankar __efi_arg_sentinel(5), __efi_arg_sentinel(4), \ 5314b864f4SArvind Sankar __efi_arg_sentinel(3), __efi_arg_sentinel(2), \ 5414b864f4SArvind Sankar __efi_arg_sentinel(1), __efi_arg_sentinel(0)) 5544f155b4SArd Biesheuvel #define __efi_nargs__(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, n, ...) \ 5614b864f4SArvind Sankar __take_second_arg(n, \ 5744f155b4SArd Biesheuvel ({ BUILD_BUG_ON_MSG(1, "__efi_nargs limit exceeded"); 10; })) 5814b864f4SArvind Sankar #define __efi_arg_sentinel(n) , n 5914b864f4SArvind Sankar 6014b864f4SArvind Sankar /* 6114b864f4SArvind Sankar * __efi_nargs_check(f, n, ...) will cause a BUILD_BUG if the ellipsis 6214b864f4SArvind Sankar * represents more than n arguments. 6314b864f4SArvind Sankar */ 6414b864f4SArvind Sankar 6514b864f4SArvind Sankar #define __efi_nargs_check(f, n, ...) \ 6614b864f4SArvind Sankar __efi_nargs_check_(f, __efi_nargs(__VA_ARGS__), n) 6714b864f4SArvind Sankar #define __efi_nargs_check_(f, p, n) __efi_nargs_check__(f, p, n) 6814b864f4SArvind Sankar #define __efi_nargs_check__(f, p, n) ({ \ 6914b864f4SArvind Sankar BUILD_BUG_ON_MSG( \ 7014b864f4SArvind Sankar (p) > (n), \ 7114b864f4SArvind Sankar #f " called with too many arguments (" #p ">" #n ")"); \ 7214b864f4SArvind Sankar }) 7314b864f4SArvind Sankar 74b0dc553cSAndy Lutomirski static inline void efi_fpu_begin(void) 75b0dc553cSAndy Lutomirski { 76b0dc553cSAndy Lutomirski /* 77b0dc553cSAndy Lutomirski * The UEFI calling convention (UEFI spec 2.3.2 and 2.3.4) requires 78b0dc553cSAndy Lutomirski * that FCW and MXCSR (64-bit) must be initialized prior to calling 79b0dc553cSAndy Lutomirski * UEFI code. (Oddly the spec does not require that the FPU stack 80b0dc553cSAndy Lutomirski * be empty.) 81b0dc553cSAndy Lutomirski */ 82b0dc553cSAndy Lutomirski kernel_fpu_begin_mask(KFPU_387 | KFPU_MXCSR); 83b0dc553cSAndy Lutomirski } 84b0dc553cSAndy Lutomirski 85b0dc553cSAndy Lutomirski static inline void efi_fpu_end(void) 86b0dc553cSAndy Lutomirski { 87b0dc553cSAndy Lutomirski kernel_fpu_end(); 88b0dc553cSAndy Lutomirski } 89b0dc553cSAndy Lutomirski 909788375dSMark Rutland #ifdef CONFIG_X86_32 91dd84441aSDavid Woodhouse #define arch_efi_call_virt_setup() \ 92dd84441aSDavid Woodhouse ({ \ 93b0dc553cSAndy Lutomirski efi_fpu_begin(); \ 94dd84441aSDavid Woodhouse firmware_restrict_branch_speculation_start(); \ 95dd84441aSDavid Woodhouse }) 96dd84441aSDavid Woodhouse 97dd84441aSDavid Woodhouse #define arch_efi_call_virt_teardown() \ 98dd84441aSDavid Woodhouse ({ \ 99dd84441aSDavid Woodhouse firmware_restrict_branch_speculation_end(); \ 100b0dc553cSAndy Lutomirski efi_fpu_end(); \ 101dd84441aSDavid Woodhouse }) 102dd84441aSDavid Woodhouse 10389ed4865SArd Biesheuvel #define arch_efi_call_virt(p, f, args...) p->f(args) 104982e239cSRicardo Neri 105bb898558SAl Viro #else /* !CONFIG_X86_32 */ 106bb898558SAl Viro 10762fa6e69SMatt Fleming #define EFI_LOADER_SIGNATURE "EL64" 108bb898558SAl Viro 10914b864f4SArvind Sankar extern asmlinkage u64 __efi_call(void *fp, ...); 11014b864f4SArvind Sankar 11114b864f4SArvind Sankar #define efi_call(...) ({ \ 11214b864f4SArvind Sankar __efi_nargs_check(efi_call, 7, __VA_ARGS__); \ 11314b864f4SArvind Sankar __efi_call(__VA_ARGS__); \ 11414b864f4SArvind Sankar }) 115bb898558SAl Viro 116bc25f9dbSMark Rutland #define arch_efi_call_virt_setup() \ 117d2f7cbe7SBorislav Petkov ({ \ 118d2f7cbe7SBorislav Petkov efi_sync_low_kernel_mappings(); \ 119b0dc553cSAndy Lutomirski efi_fpu_begin(); \ 120dd84441aSDavid Woodhouse firmware_restrict_branch_speculation_start(); \ 121514b1a84SArd Biesheuvel efi_enter_mm(); \ 122bc25f9dbSMark Rutland }) 123bc25f9dbSMark Rutland 124fe379fa4SPeter Zijlstra #define arch_efi_call_virt(p, f, args...) ({ \ 125fe379fa4SPeter Zijlstra u64 ret, ibt = ibt_save(); \ 126fe379fa4SPeter Zijlstra ret = efi_call((void *)p->f, args); \ 127fe379fa4SPeter Zijlstra ibt_restore(ibt); \ 128fe379fa4SPeter Zijlstra ret; \ 129fe379fa4SPeter Zijlstra }) 130bc25f9dbSMark Rutland 131bc25f9dbSMark Rutland #define arch_efi_call_virt_teardown() \ 132bc25f9dbSMark Rutland ({ \ 133514b1a84SArd Biesheuvel efi_leave_mm(); \ 134dd84441aSDavid Woodhouse firmware_restrict_branch_speculation_end(); \ 135b0dc553cSAndy Lutomirski efi_fpu_end(); \ 136d2f7cbe7SBorislav Petkov }) 137d2f7cbe7SBorislav Petkov 138a523841eSAndrey Ryabinin #ifdef CONFIG_KASAN 139769a8089SAndrey Ryabinin /* 140769a8089SAndrey Ryabinin * CONFIG_KASAN may redefine memset to __memset. __memset function is present 141769a8089SAndrey Ryabinin * only in kernel binary. Since the EFI stub linked into a separate binary it 142769a8089SAndrey Ryabinin * doesn't have __memset(). So we should use standard memset from 143769a8089SAndrey Ryabinin * arch/x86/boot/compressed/string.c. The same applies to memcpy and memmove. 144769a8089SAndrey Ryabinin */ 145769a8089SAndrey Ryabinin #undef memcpy 146769a8089SAndrey Ryabinin #undef memset 147769a8089SAndrey Ryabinin #undef memmove 148a523841eSAndrey Ryabinin #endif 149769a8089SAndrey Ryabinin 150bb898558SAl Viro #endif /* CONFIG_X86_32 */ 151bb898558SAl Viro 1524e78eb05SMathias Krause extern int __init efi_memblock_x86_reserve_range(void); 1530bbea1ceSTaku Izumi extern void __init efi_print_memmap(void); 154d2f7cbe7SBorislav Petkov extern void __init efi_map_region(efi_memory_desc_t *md); 1553b266496SDave Young extern void __init efi_map_region_fixed(efi_memory_desc_t *md); 156d2f7cbe7SBorislav Petkov extern void efi_sync_low_kernel_mappings(void); 15767a9108eSMatt Fleming extern int __init efi_alloc_page_tables(void); 1584e78eb05SMathias Krause extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages); 1596d0cc887SSai Praneeth extern void __init efi_runtime_update_mappings(void); 16011cc8512SBorislav Petkov extern void __init efi_dump_pagetable(void); 161a5d90c92SBorislav Petkov extern void __init efi_apply_memmap_quirks(void); 162eeb9db09SSaurabh Tangri extern int __init efi_reuse_config(u64 tables, int nr_tables); 163eeb9db09SSaurabh Tangri extern void efi_delete_dummy_variable(void); 164c46f5223SAndy Lutomirski extern void efi_crash_gracefully_on_page_fault(unsigned long phys_addr); 16547c33a09SSai Praneeth Prakhya extern void efi_free_boot_services(void); 166bb898558SAl Viro 167514b1a84SArd Biesheuvel void efi_enter_mm(void); 168514b1a84SArd Biesheuvel void efi_leave_mm(void); 169514b1a84SArd Biesheuvel 170a088b858SArd Biesheuvel /* kexec external ABI */ 1711fec0533SDave Young struct efi_setup_data { 1721fec0533SDave Young u64 fw_vendor; 173a088b858SArd Biesheuvel u64 __unused; 1741fec0533SDave Young u64 tables; 1751fec0533SDave Young u64 smbios; 1761fec0533SDave Young u64 reserved[8]; 1771fec0533SDave Young }; 1781fec0533SDave Young 1791fec0533SDave Young extern u64 efi_setup; 1801fec0533SDave Young 1816b59e366SSatoru Takeuchi #ifdef CONFIG_EFI 18214b864f4SArvind Sankar extern efi_status_t __efi64_thunk(u32, ...); 18314b864f4SArvind Sankar 18414b864f4SArvind Sankar #define efi64_thunk(...) ({ \ 18544f155b4SArd Biesheuvel u64 __pad[3]; /* must have space for 3 args on the stack */ \ 18644f155b4SArd Biesheuvel __efi_nargs_check(efi64_thunk, 9, __VA_ARGS__); \ 18744f155b4SArd Biesheuvel __efi64_thunk(__VA_ARGS__, __pad); \ 18814b864f4SArvind Sankar }) 1896b59e366SSatoru Takeuchi 190a8147dbaSArd Biesheuvel static inline bool efi_is_mixed(void) 1916b59e366SSatoru Takeuchi { 192a8147dbaSArd Biesheuvel if (!IS_ENABLED(CONFIG_EFI_MIXED)) 193a8147dbaSArd Biesheuvel return false; 194a8147dbaSArd Biesheuvel return IS_ENABLED(CONFIG_X86_64) && !efi_enabled(EFI_64BIT); 1956b59e366SSatoru Takeuchi } 1966b59e366SSatoru Takeuchi 1977d453eeeSMatt Fleming static inline bool efi_runtime_supported(void) 1987d453eeeSMatt Fleming { 1996cfcd6f0SArd Biesheuvel if (IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT)) 2007d453eeeSMatt Fleming return true; 2017d453eeeSMatt Fleming 2021f299fadSArd Biesheuvel return IS_ENABLED(CONFIG_EFI_MIXED); 2037d453eeeSMatt Fleming } 2047d453eeeSMatt Fleming 2055c12af0cSDave Young extern void parse_efi_setup(u64 phys_addr, u32 data_len); 2064f9dbcfcSMatt Fleming 2074f9dbcfcSMatt Fleming extern void efi_thunk_runtime_setup(void); 20869829470SArd Biesheuvel efi_status_t efi_set_virtual_address_map(unsigned long memory_map_size, 20969829470SArd Biesheuvel unsigned long descriptor_size, 21069829470SArd Biesheuvel u32 descriptor_version, 21159f2a619SArd Biesheuvel efi_memory_desc_t *virtual_map, 21259f2a619SArd Biesheuvel unsigned long systab_phys); 213243b6754SArd Biesheuvel 214243b6754SArd Biesheuvel /* arch specific definitions used by the stub code */ 215243b6754SArd Biesheuvel 216de8c5520SArvind Sankar #ifdef CONFIG_EFI_MIXED 217de8c5520SArvind Sankar 218de8c5520SArvind Sankar #define ARCH_HAS_EFISTUB_WRAPPERS 2190a755614SArd Biesheuvel 2200a755614SArd Biesheuvel static inline bool efi_is_64bit(void) 2210a755614SArd Biesheuvel { 222de8c5520SArvind Sankar extern const bool efi_is64; 223de8c5520SArvind Sankar 2240a755614SArd Biesheuvel return efi_is64; 2250a755614SArd Biesheuvel } 22627571616SLukas Wunner 227f958efe9SArd Biesheuvel static inline bool efi_is_native(void) 228f958efe9SArd Biesheuvel { 229f958efe9SArd Biesheuvel return efi_is_64bit(); 230f958efe9SArd Biesheuvel } 231f958efe9SArd Biesheuvel 232f958efe9SArd Biesheuvel #define efi_mixed_mode_cast(attr) \ 233f958efe9SArd Biesheuvel __builtin_choose_expr( \ 234f958efe9SArd Biesheuvel __builtin_types_compatible_p(u32, __typeof__(attr)), \ 235f958efe9SArd Biesheuvel (unsigned long)(attr), (attr)) 236f958efe9SArd Biesheuvel 23799ea8b1dSArd Biesheuvel #define efi_table_attr(inst, attr) \ 23899ea8b1dSArd Biesheuvel (efi_is_native() \ 23999ea8b1dSArd Biesheuvel ? inst->attr \ 24099ea8b1dSArd Biesheuvel : (__typeof__(inst->attr)) \ 24199ea8b1dSArd Biesheuvel efi_mixed_mode_cast(inst->mixed_mode.attr)) 2423552fdf2SLukas Wunner 243ea7d87f9SArvind Sankar /* 244ea7d87f9SArvind Sankar * The following macros allow translating arguments if necessary from native to 245ea7d87f9SArvind Sankar * mixed mode. The use case for this is to initialize the upper 32 bits of 246ea7d87f9SArvind Sankar * output parameters, and where the 32-bit method requires a 64-bit argument, 247ea7d87f9SArvind Sankar * which must be split up into two arguments to be thunked properly. 248ea7d87f9SArvind Sankar * 249ea7d87f9SArvind Sankar * As examples, the AllocatePool boot service returns the address of the 250ea7d87f9SArvind Sankar * allocation, but it will not set the high 32 bits of the address. To ensure 251ea7d87f9SArvind Sankar * that the full 64-bit address is initialized, we zero-init the address before 252ea7d87f9SArvind Sankar * calling the thunk. 253ea7d87f9SArvind Sankar * 254ea7d87f9SArvind Sankar * The FreePages boot service takes a 64-bit physical address even in 32-bit 255ea7d87f9SArvind Sankar * mode. For the thunk to work correctly, a native 64-bit call of 256ea7d87f9SArvind Sankar * free_pages(addr, size) 257ea7d87f9SArvind Sankar * must be translated to 258ea7d87f9SArvind Sankar * efi64_thunk(free_pages, addr & U32_MAX, addr >> 32, size) 259ea7d87f9SArvind Sankar * so that the two 32-bit halves of addr get pushed onto the stack separately. 260ea7d87f9SArvind Sankar */ 261ea7d87f9SArvind Sankar 262ea7d87f9SArvind Sankar static inline void *efi64_zero_upper(void *p) 263ea7d87f9SArvind Sankar { 264ea7d87f9SArvind Sankar ((u32 *)p)[1] = 0; 265ea7d87f9SArvind Sankar return p; 266ea7d87f9SArvind Sankar } 267ea7d87f9SArvind Sankar 2683b8f44fcSArd Biesheuvel static inline u32 efi64_convert_status(efi_status_t status) 2693b8f44fcSArd Biesheuvel { 2703b8f44fcSArd Biesheuvel return (u32)(status | (u64)status >> 32); 2713b8f44fcSArd Biesheuvel } 2723b8f44fcSArd Biesheuvel 273ea7d87f9SArvind Sankar #define __efi64_argmap_free_pages(addr, size) \ 274ea7d87f9SArvind Sankar ((addr), 0, (size)) 275ea7d87f9SArvind Sankar 276ea7d87f9SArvind Sankar #define __efi64_argmap_get_memory_map(mm_size, mm, key, size, ver) \ 277ea7d87f9SArvind Sankar ((mm_size), (mm), efi64_zero_upper(key), efi64_zero_upper(size), (ver)) 278ea7d87f9SArvind Sankar 279ea7d87f9SArvind Sankar #define __efi64_argmap_allocate_pool(type, size, buffer) \ 280ea7d87f9SArvind Sankar ((type), (size), efi64_zero_upper(buffer)) 281ea7d87f9SArvind Sankar 2829b47c527SArvind Sankar #define __efi64_argmap_create_event(type, tpl, f, c, event) \ 2839b47c527SArvind Sankar ((type), (tpl), (f), (c), efi64_zero_upper(event)) 2849b47c527SArvind Sankar 2859b47c527SArvind Sankar #define __efi64_argmap_set_timer(event, type, time) \ 2869b47c527SArvind Sankar ((event), (type), lower_32_bits(time), upper_32_bits(time)) 2879b47c527SArvind Sankar 2889b47c527SArvind Sankar #define __efi64_argmap_wait_for_event(num, event, index) \ 2899b47c527SArvind Sankar ((num), (event), efi64_zero_upper(index)) 2909b47c527SArvind Sankar 291ea7d87f9SArvind Sankar #define __efi64_argmap_handle_protocol(handle, protocol, interface) \ 292ea7d87f9SArvind Sankar ((handle), (protocol), efi64_zero_upper(interface)) 293ea7d87f9SArvind Sankar 294ea7d87f9SArvind Sankar #define __efi64_argmap_locate_protocol(protocol, reg, interface) \ 295ea7d87f9SArvind Sankar ((protocol), (reg), efi64_zero_upper(interface)) 296ea7d87f9SArvind Sankar 297abd26868SArd Biesheuvel #define __efi64_argmap_locate_device_path(protocol, path, handle) \ 298abd26868SArd Biesheuvel ((protocol), (path), efi64_zero_upper(handle)) 299abd26868SArd Biesheuvel 3003b8f44fcSArd Biesheuvel #define __efi64_argmap_exit(handle, status, size, data) \ 3013b8f44fcSArd Biesheuvel ((handle), efi64_convert_status(status), (size), (data)) 3023b8f44fcSArd Biesheuvel 3034444f854SMatthew Garrett /* PCI I/O */ 3044444f854SMatthew Garrett #define __efi64_argmap_get_location(protocol, seg, bus, dev, func) \ 3054444f854SMatthew Garrett ((protocol), efi64_zero_upper(seg), efi64_zero_upper(bus), \ 3064444f854SMatthew Garrett efi64_zero_upper(dev), efi64_zero_upper(func)) 3074444f854SMatthew Garrett 3082931d526SArd Biesheuvel /* LoadFile */ 3092931d526SArd Biesheuvel #define __efi64_argmap_load_file(protocol, path, policy, bufsize, buf) \ 3102931d526SArd Biesheuvel ((protocol), (path), (policy), efi64_zero_upper(bufsize), (buf)) 3112931d526SArd Biesheuvel 312b4b89a02SArvind Sankar /* Graphics Output Protocol */ 313b4b89a02SArvind Sankar #define __efi64_argmap_query_mode(gop, mode, size, info) \ 314b4b89a02SArvind Sankar ((gop), (mode), efi64_zero_upper(size), efi64_zero_upper(info)) 315b4b89a02SArvind Sankar 3164da87c51SArd Biesheuvel /* TCG2 protocol */ 3174da87c51SArd Biesheuvel #define __efi64_argmap_hash_log_extend_event(prot, fl, addr, size, ev) \ 3184da87c51SArd Biesheuvel ((prot), (fl), 0ULL, (u64)(addr), 0ULL, (u64)(size), 0ULL, ev) 3194da87c51SArd Biesheuvel 320ea7d87f9SArvind Sankar /* 321ea7d87f9SArvind Sankar * The macros below handle the plumbing for the argument mapping. To add a 322ea7d87f9SArvind Sankar * mapping for a specific EFI method, simply define a macro 323ea7d87f9SArvind Sankar * __efi64_argmap_<method name>, following the examples above. 324ea7d87f9SArvind Sankar */ 325ea7d87f9SArvind Sankar 326ea7d87f9SArvind Sankar #define __efi64_thunk_map(inst, func, ...) \ 327ea7d87f9SArvind Sankar efi64_thunk(inst->mixed_mode.func, \ 328ea7d87f9SArvind Sankar __efi64_argmap(__efi64_argmap_ ## func(__VA_ARGS__), \ 329ea7d87f9SArvind Sankar (__VA_ARGS__))) 330ea7d87f9SArvind Sankar 331ea7d87f9SArvind Sankar #define __efi64_argmap(mapped, args) \ 332ea7d87f9SArvind Sankar __PASTE(__efi64_argmap__, __efi_nargs(__efi_eat mapped))(mapped, args) 333ea7d87f9SArvind Sankar #define __efi64_argmap__0(mapped, args) __efi_eval mapped 334ea7d87f9SArvind Sankar #define __efi64_argmap__1(mapped, args) __efi_eval args 335ea7d87f9SArvind Sankar 336ea7d87f9SArvind Sankar #define __efi_eat(...) 337ea7d87f9SArvind Sankar #define __efi_eval(...) __VA_ARGS__ 338ea7d87f9SArvind Sankar 339ea7d87f9SArvind Sankar /* The three macros below handle dispatching via the thunk if needed */ 340ea7d87f9SArvind Sankar 34147c0fd39SArd Biesheuvel #define efi_call_proto(inst, func, ...) \ 342afc4cc71SArd Biesheuvel (efi_is_native() \ 34347c0fd39SArd Biesheuvel ? inst->func(inst, ##__VA_ARGS__) \ 344ea7d87f9SArvind Sankar : __efi64_thunk_map(inst, func, inst, ##__VA_ARGS__)) 3453552fdf2SLukas Wunner 346966291f6SArd Biesheuvel #define efi_bs_call(func, ...) \ 347afc4cc71SArd Biesheuvel (efi_is_native() \ 348ccc27ae7SArd Biesheuvel ? efi_system_table->boottime->func(__VA_ARGS__) \ 349ccc27ae7SArd Biesheuvel : __efi64_thunk_map(efi_table_attr(efi_system_table, \ 350ccc27ae7SArd Biesheuvel boottime), \ 351ccc27ae7SArd Biesheuvel func, __VA_ARGS__)) 352243b6754SArd Biesheuvel 353966291f6SArd Biesheuvel #define efi_rt_call(func, ...) \ 354afc4cc71SArd Biesheuvel (efi_is_native() \ 355ccc27ae7SArd Biesheuvel ? efi_system_table->runtime->func(__VA_ARGS__) \ 356ccc27ae7SArd Biesheuvel : __efi64_thunk_map(efi_table_attr(efi_system_table, \ 357ccc27ae7SArd Biesheuvel runtime), \ 358ccc27ae7SArd Biesheuvel func, __VA_ARGS__)) 359a2cd2f3fSDavid Howells 360*3ba75c13SBaskov Evgeniy #define efi_dxe_call(func, ...) \ 361*3ba75c13SBaskov Evgeniy (efi_is_native() \ 362*3ba75c13SBaskov Evgeniy ? efi_dxe_table->func(__VA_ARGS__) \ 363*3ba75c13SBaskov Evgeniy : __efi64_thunk_map(efi_dxe_table, func, __VA_ARGS__)) 364*3ba75c13SBaskov Evgeniy 365de8c5520SArvind Sankar #else /* CONFIG_EFI_MIXED */ 366de8c5520SArvind Sankar 367de8c5520SArvind Sankar static inline bool efi_is_64bit(void) 368de8c5520SArvind Sankar { 369de8c5520SArvind Sankar return IS_ENABLED(CONFIG_X86_64); 370de8c5520SArvind Sankar } 371de8c5520SArvind Sankar 372de8c5520SArvind Sankar #endif /* CONFIG_EFI_MIXED */ 373de8c5520SArvind Sankar 37444be28e9SMatt Fleming extern bool efi_reboot_required(void); 375e55f31a5SArd Biesheuvel extern bool efi_is_table_address(unsigned long phys_addr); 37644be28e9SMatt Fleming 3776950e31bSDan Williams extern void efi_find_mirror(void); 3786950e31bSDan Williams extern void efi_reserve_boot_services(void); 3796b59e366SSatoru Takeuchi #else 3805c12af0cSDave Young static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {} 38144be28e9SMatt Fleming static inline bool efi_reboot_required(void) 38244be28e9SMatt Fleming { 38344be28e9SMatt Fleming return false; 38444be28e9SMatt Fleming } 385e55f31a5SArd Biesheuvel static inline bool efi_is_table_address(unsigned long phys_addr) 386e55f31a5SArd Biesheuvel { 387e55f31a5SArd Biesheuvel return false; 388e55f31a5SArd Biesheuvel } 3896950e31bSDan Williams static inline void efi_find_mirror(void) 3906950e31bSDan Williams { 3916950e31bSDan Williams } 3926950e31bSDan Williams static inline void efi_reserve_boot_services(void) 3936950e31bSDan Williams { 3946950e31bSDan Williams } 395bb898558SAl Viro #endif /* CONFIG_EFI */ 396bb898558SAl Viro 397199c8471SDan Williams #ifdef CONFIG_EFI_FAKE_MEMMAP 398199c8471SDan Williams extern void __init efi_fake_memmap_early(void); 399199c8471SDan Williams #else 400199c8471SDan Williams static inline void efi_fake_memmap_early(void) 401199c8471SDan Williams { 402199c8471SDan Williams } 403199c8471SDan Williams #endif 404199c8471SDan Williams 40525519d68SChester Lin #define arch_ima_efi_boot_mode \ 40625519d68SChester Lin ({ extern struct boot_params boot_params; boot_params.secure_boot; }) 40725519d68SChester Lin 4081965aae3SH. Peter Anvin #endif /* _ASM_X86_EFI_H */ 409