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 34745e3ed8SKirill A. Shutemov #define EFI_UNACCEPTED_UNIT_SIZE PMD_SIZE 35745e3ed8SKirill A. Shutemov 3614b864f4SArvind Sankar /* 3714b864f4SArvind Sankar * The EFI services are called through variadic functions in many cases. These 3814b864f4SArvind Sankar * functions are implemented in assembler and support only a fixed number of 3914b864f4SArvind Sankar * arguments. The macros below allows us to check at build time that we don't 4014b864f4SArvind Sankar * try to call them with too many arguments. 4114b864f4SArvind Sankar * 4214b864f4SArvind Sankar * __efi_nargs() will return the number of arguments if it is 7 or less, and 4314b864f4SArvind Sankar * cause a BUILD_BUG otherwise. The limitations of the C preprocessor make it 4414b864f4SArvind Sankar * impossible to calculate the exact number of arguments beyond some 4514b864f4SArvind Sankar * pre-defined limit. The maximum number of arguments currently supported by 4614b864f4SArvind Sankar * any of the thunks is 7, so this is good enough for now and can be extended 4714b864f4SArvind Sankar * in the obvious way if we ever need more. 4814b864f4SArvind Sankar */ 4914b864f4SArvind Sankar 5014b864f4SArvind Sankar #define __efi_nargs(...) __efi_nargs_(__VA_ARGS__) 5114b864f4SArvind Sankar #define __efi_nargs_(...) __efi_nargs__(0, ##__VA_ARGS__, \ 5244f155b4SArd Biesheuvel __efi_arg_sentinel(9), __efi_arg_sentinel(8), \ 5314b864f4SArvind Sankar __efi_arg_sentinel(7), __efi_arg_sentinel(6), \ 5414b864f4SArvind Sankar __efi_arg_sentinel(5), __efi_arg_sentinel(4), \ 5514b864f4SArvind Sankar __efi_arg_sentinel(3), __efi_arg_sentinel(2), \ 5614b864f4SArvind Sankar __efi_arg_sentinel(1), __efi_arg_sentinel(0)) 5744f155b4SArd Biesheuvel #define __efi_nargs__(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, n, ...) \ 5814b864f4SArvind Sankar __take_second_arg(n, \ 5944f155b4SArd Biesheuvel ({ BUILD_BUG_ON_MSG(1, "__efi_nargs limit exceeded"); 10; })) 6014b864f4SArvind Sankar #define __efi_arg_sentinel(n) , n 6114b864f4SArvind Sankar 6214b864f4SArvind Sankar /* 6314b864f4SArvind Sankar * __efi_nargs_check(f, n, ...) will cause a BUILD_BUG if the ellipsis 6414b864f4SArvind Sankar * represents more than n arguments. 6514b864f4SArvind Sankar */ 6614b864f4SArvind Sankar 6714b864f4SArvind Sankar #define __efi_nargs_check(f, n, ...) \ 6814b864f4SArvind Sankar __efi_nargs_check_(f, __efi_nargs(__VA_ARGS__), n) 6914b864f4SArvind Sankar #define __efi_nargs_check_(f, p, n) __efi_nargs_check__(f, p, n) 7014b864f4SArvind Sankar #define __efi_nargs_check__(f, p, n) ({ \ 7114b864f4SArvind Sankar BUILD_BUG_ON_MSG( \ 7214b864f4SArvind Sankar (p) > (n), \ 7314b864f4SArvind Sankar #f " called with too many arguments (" #p ">" #n ")"); \ 7414b864f4SArvind Sankar }) 7514b864f4SArvind Sankar 76b0dc553cSAndy Lutomirski static inline void efi_fpu_begin(void) 77b0dc553cSAndy Lutomirski { 78b0dc553cSAndy Lutomirski /* 79b0dc553cSAndy Lutomirski * The UEFI calling convention (UEFI spec 2.3.2 and 2.3.4) requires 80b0dc553cSAndy Lutomirski * that FCW and MXCSR (64-bit) must be initialized prior to calling 81b0dc553cSAndy Lutomirski * UEFI code. (Oddly the spec does not require that the FPU stack 82b0dc553cSAndy Lutomirski * be empty.) 83b0dc553cSAndy Lutomirski */ 84b0dc553cSAndy Lutomirski kernel_fpu_begin_mask(KFPU_387 | KFPU_MXCSR); 85b0dc553cSAndy Lutomirski } 86b0dc553cSAndy Lutomirski 87b0dc553cSAndy Lutomirski static inline void efi_fpu_end(void) 88b0dc553cSAndy Lutomirski { 89b0dc553cSAndy Lutomirski kernel_fpu_end(); 90b0dc553cSAndy Lutomirski } 91b0dc553cSAndy Lutomirski 929788375dSMark Rutland #ifdef CONFIG_X86_32 93a1b87d54SArd Biesheuvel #define EFI_X86_KERNEL_ALLOC_LIMIT (SZ_512M - 1) 94bb898558SAl Viro #else /* !CONFIG_X86_32 */ 95a1b87d54SArd Biesheuvel #define EFI_X86_KERNEL_ALLOC_LIMIT EFI_ALLOC_LIMIT 96bb898558SAl Viro 9714b864f4SArvind Sankar extern asmlinkage u64 __efi_call(void *fp, ...); 9814b864f4SArvind Sankar 9993be2859SArd Biesheuvel extern bool efi_disable_ibt_for_runtime; 10093be2859SArd Biesheuvel 10114b864f4SArvind Sankar #define efi_call(...) ({ \ 10214b864f4SArvind Sankar __efi_nargs_check(efi_call, 7, __VA_ARGS__); \ 10314b864f4SArvind Sankar __efi_call(__VA_ARGS__); \ 10414b864f4SArvind Sankar }) 105bb898558SAl Viro 1068add9a3aSSudeep Holla #undef arch_efi_call_virt 107fe379fa4SPeter Zijlstra #define arch_efi_call_virt(p, f, args...) ({ \ 10893be2859SArd Biesheuvel u64 ret, ibt = ibt_save(efi_disable_ibt_for_runtime); \ 109fe379fa4SPeter Zijlstra ret = efi_call((void *)p->f, args); \ 110fe379fa4SPeter Zijlstra ibt_restore(ibt); \ 111fe379fa4SPeter Zijlstra ret; \ 112fe379fa4SPeter Zijlstra }) 113bc25f9dbSMark Rutland 114a523841eSAndrey Ryabinin #ifdef CONFIG_KASAN 115769a8089SAndrey Ryabinin /* 116769a8089SAndrey Ryabinin * CONFIG_KASAN may redefine memset to __memset. __memset function is present 117769a8089SAndrey Ryabinin * only in kernel binary. Since the EFI stub linked into a separate binary it 118769a8089SAndrey Ryabinin * doesn't have __memset(). So we should use standard memset from 119769a8089SAndrey Ryabinin * arch/x86/boot/compressed/string.c. The same applies to memcpy and memmove. 120769a8089SAndrey Ryabinin */ 121769a8089SAndrey Ryabinin #undef memcpy 122769a8089SAndrey Ryabinin #undef memset 123769a8089SAndrey Ryabinin #undef memmove 124a523841eSAndrey Ryabinin #endif 125769a8089SAndrey Ryabinin 126bb898558SAl Viro #endif /* CONFIG_X86_32 */ 127bb898558SAl Viro 1284e78eb05SMathias Krause extern int __init efi_memblock_x86_reserve_range(void); 1290bbea1ceSTaku Izumi extern void __init efi_print_memmap(void); 130d2f7cbe7SBorislav Petkov extern void __init efi_map_region(efi_memory_desc_t *md); 1313b266496SDave Young extern void __init efi_map_region_fixed(efi_memory_desc_t *md); 132d2f7cbe7SBorislav Petkov extern void efi_sync_low_kernel_mappings(void); 13367a9108eSMatt Fleming extern int __init efi_alloc_page_tables(void); 1344e78eb05SMathias Krause extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages); 1356d0cc887SSai Praneeth extern void __init efi_runtime_update_mappings(void); 13611cc8512SBorislav Petkov extern void __init efi_dump_pagetable(void); 137a5d90c92SBorislav Petkov extern void __init efi_apply_memmap_quirks(void); 138eeb9db09SSaurabh Tangri extern int __init efi_reuse_config(u64 tables, int nr_tables); 139eeb9db09SSaurabh Tangri extern void efi_delete_dummy_variable(void); 140c46f5223SAndy Lutomirski extern void efi_crash_gracefully_on_page_fault(unsigned long phys_addr); 14147c33a09SSai Praneeth Prakhya extern void efi_free_boot_services(void); 142bb898558SAl Viro 143*762f169fSArd Biesheuvel void arch_efi_call_virt_setup(void); 144*762f169fSArd Biesheuvel void arch_efi_call_virt_teardown(void); 145514b1a84SArd Biesheuvel 146a088b858SArd Biesheuvel /* kexec external ABI */ 1471fec0533SDave Young struct efi_setup_data { 1481fec0533SDave Young u64 fw_vendor; 149a088b858SArd Biesheuvel u64 __unused; 1501fec0533SDave Young u64 tables; 1511fec0533SDave Young u64 smbios; 1521fec0533SDave Young u64 reserved[8]; 1531fec0533SDave Young }; 1541fec0533SDave Young 1551fec0533SDave Young extern u64 efi_setup; 1561fec0533SDave Young 1576b59e366SSatoru Takeuchi #ifdef CONFIG_EFI 158a61962d8SArd Biesheuvel extern u64 __efi64_thunk(u32, ...); 15914b864f4SArvind Sankar 16014b864f4SArvind Sankar #define efi64_thunk(...) ({ \ 16144f155b4SArd Biesheuvel u64 __pad[3]; /* must have space for 3 args on the stack */ \ 16244f155b4SArd Biesheuvel __efi_nargs_check(efi64_thunk, 9, __VA_ARGS__); \ 16344f155b4SArd Biesheuvel __efi64_thunk(__VA_ARGS__, __pad); \ 16414b864f4SArvind Sankar }) 1656b59e366SSatoru Takeuchi 166a8147dbaSArd Biesheuvel static inline bool efi_is_mixed(void) 1676b59e366SSatoru Takeuchi { 168a8147dbaSArd Biesheuvel if (!IS_ENABLED(CONFIG_EFI_MIXED)) 169a8147dbaSArd Biesheuvel return false; 170a8147dbaSArd Biesheuvel return IS_ENABLED(CONFIG_X86_64) && !efi_enabled(EFI_64BIT); 1716b59e366SSatoru Takeuchi } 1726b59e366SSatoru Takeuchi 1737d453eeeSMatt Fleming static inline bool efi_runtime_supported(void) 1747d453eeeSMatt Fleming { 1756cfcd6f0SArd Biesheuvel if (IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT)) 1767d453eeeSMatt Fleming return true; 1777d453eeeSMatt Fleming 1781f299fadSArd Biesheuvel return IS_ENABLED(CONFIG_EFI_MIXED); 1797d453eeeSMatt Fleming } 1807d453eeeSMatt Fleming 1815c12af0cSDave Young extern void parse_efi_setup(u64 phys_addr, u32 data_len); 1824f9dbcfcSMatt Fleming 1834f9dbcfcSMatt Fleming extern void efi_thunk_runtime_setup(void); 18469829470SArd Biesheuvel efi_status_t efi_set_virtual_address_map(unsigned long memory_map_size, 18569829470SArd Biesheuvel unsigned long descriptor_size, 18669829470SArd Biesheuvel u32 descriptor_version, 18759f2a619SArd Biesheuvel efi_memory_desc_t *virtual_map, 18859f2a619SArd Biesheuvel unsigned long systab_phys); 189243b6754SArd Biesheuvel 190243b6754SArd Biesheuvel /* arch specific definitions used by the stub code */ 191243b6754SArd Biesheuvel 192de8c5520SArvind Sankar #ifdef CONFIG_EFI_MIXED 193de8c5520SArvind Sankar 194a1b87d54SArd Biesheuvel #define EFI_ALLOC_LIMIT (efi_is_64bit() ? ULONG_MAX : U32_MAX) 195a1b87d54SArd Biesheuvel 196de8c5520SArvind Sankar #define ARCH_HAS_EFISTUB_WRAPPERS 1970a755614SArd Biesheuvel 1980a755614SArd Biesheuvel static inline bool efi_is_64bit(void) 1990a755614SArd Biesheuvel { 200de8c5520SArvind Sankar extern const bool efi_is64; 201de8c5520SArvind Sankar 2020a755614SArd Biesheuvel return efi_is64; 2030a755614SArd Biesheuvel } 20427571616SLukas Wunner 205f958efe9SArd Biesheuvel static inline bool efi_is_native(void) 206f958efe9SArd Biesheuvel { 207f958efe9SArd Biesheuvel return efi_is_64bit(); 208f958efe9SArd Biesheuvel } 209f958efe9SArd Biesheuvel 21099ea8b1dSArd Biesheuvel #define efi_table_attr(inst, attr) \ 211a61962d8SArd Biesheuvel (efi_is_native() ? (inst)->attr \ 212a61962d8SArd Biesheuvel : efi_mixed_table_attr((inst), attr)) 213a61962d8SArd Biesheuvel 214a61962d8SArd Biesheuvel #define efi_mixed_table_attr(inst, attr) \ 215a61962d8SArd Biesheuvel (__typeof__(inst->attr)) \ 216a61962d8SArd Biesheuvel _Generic(inst->mixed_mode.attr, \ 217a61962d8SArd Biesheuvel u32: (unsigned long)(inst->mixed_mode.attr), \ 218a61962d8SArd Biesheuvel default: (inst->mixed_mode.attr)) 2193552fdf2SLukas Wunner 220ea7d87f9SArvind Sankar /* 221ea7d87f9SArvind Sankar * The following macros allow translating arguments if necessary from native to 222ea7d87f9SArvind Sankar * mixed mode. The use case for this is to initialize the upper 32 bits of 223ea7d87f9SArvind Sankar * output parameters, and where the 32-bit method requires a 64-bit argument, 224ea7d87f9SArvind Sankar * which must be split up into two arguments to be thunked properly. 225ea7d87f9SArvind Sankar * 226ea7d87f9SArvind Sankar * As examples, the AllocatePool boot service returns the address of the 227ea7d87f9SArvind Sankar * allocation, but it will not set the high 32 bits of the address. To ensure 228ea7d87f9SArvind Sankar * that the full 64-bit address is initialized, we zero-init the address before 229ea7d87f9SArvind Sankar * calling the thunk. 230ea7d87f9SArvind Sankar * 231ea7d87f9SArvind Sankar * The FreePages boot service takes a 64-bit physical address even in 32-bit 232ea7d87f9SArvind Sankar * mode. For the thunk to work correctly, a native 64-bit call of 233ea7d87f9SArvind Sankar * free_pages(addr, size) 234ea7d87f9SArvind Sankar * must be translated to 235ea7d87f9SArvind Sankar * efi64_thunk(free_pages, addr & U32_MAX, addr >> 32, size) 236ea7d87f9SArvind Sankar * so that the two 32-bit halves of addr get pushed onto the stack separately. 237ea7d87f9SArvind Sankar */ 238ea7d87f9SArvind Sankar 239ea7d87f9SArvind Sankar static inline void *efi64_zero_upper(void *p) 240ea7d87f9SArvind Sankar { 241ea7d87f9SArvind Sankar ((u32 *)p)[1] = 0; 242ea7d87f9SArvind Sankar return p; 243ea7d87f9SArvind Sankar } 244ea7d87f9SArvind Sankar 2453b8f44fcSArd Biesheuvel static inline u32 efi64_convert_status(efi_status_t status) 2463b8f44fcSArd Biesheuvel { 2473b8f44fcSArd Biesheuvel return (u32)(status | (u64)status >> 32); 2483b8f44fcSArd Biesheuvel } 2493b8f44fcSArd Biesheuvel 25031f1a0edSArd Biesheuvel #define __efi64_split(val) (val) & U32_MAX, (u64)(val) >> 32 25131f1a0edSArd Biesheuvel 252ea7d87f9SArvind Sankar #define __efi64_argmap_free_pages(addr, size) \ 253ea7d87f9SArvind Sankar ((addr), 0, (size)) 254ea7d87f9SArvind Sankar 255ea7d87f9SArvind Sankar #define __efi64_argmap_get_memory_map(mm_size, mm, key, size, ver) \ 256ea7d87f9SArvind Sankar ((mm_size), (mm), efi64_zero_upper(key), efi64_zero_upper(size), (ver)) 257ea7d87f9SArvind Sankar 258ea7d87f9SArvind Sankar #define __efi64_argmap_allocate_pool(type, size, buffer) \ 259ea7d87f9SArvind Sankar ((type), (size), efi64_zero_upper(buffer)) 260ea7d87f9SArvind Sankar 2619b47c527SArvind Sankar #define __efi64_argmap_create_event(type, tpl, f, c, event) \ 2629b47c527SArvind Sankar ((type), (tpl), (f), (c), efi64_zero_upper(event)) 2639b47c527SArvind Sankar 2649b47c527SArvind Sankar #define __efi64_argmap_set_timer(event, type, time) \ 2659b47c527SArvind Sankar ((event), (type), lower_32_bits(time), upper_32_bits(time)) 2669b47c527SArvind Sankar 2679b47c527SArvind Sankar #define __efi64_argmap_wait_for_event(num, event, index) \ 2689b47c527SArvind Sankar ((num), (event), efi64_zero_upper(index)) 2699b47c527SArvind Sankar 270ea7d87f9SArvind Sankar #define __efi64_argmap_handle_protocol(handle, protocol, interface) \ 271ea7d87f9SArvind Sankar ((handle), (protocol), efi64_zero_upper(interface)) 272ea7d87f9SArvind Sankar 273ea7d87f9SArvind Sankar #define __efi64_argmap_locate_protocol(protocol, reg, interface) \ 274ea7d87f9SArvind Sankar ((protocol), (reg), efi64_zero_upper(interface)) 275ea7d87f9SArvind Sankar 276abd26868SArd Biesheuvel #define __efi64_argmap_locate_device_path(protocol, path, handle) \ 277abd26868SArd Biesheuvel ((protocol), (path), efi64_zero_upper(handle)) 278abd26868SArd Biesheuvel 2793b8f44fcSArd Biesheuvel #define __efi64_argmap_exit(handle, status, size, data) \ 2803b8f44fcSArd Biesheuvel ((handle), efi64_convert_status(status), (size), (data)) 2813b8f44fcSArd Biesheuvel 2824444f854SMatthew Garrett /* PCI I/O */ 2834444f854SMatthew Garrett #define __efi64_argmap_get_location(protocol, seg, bus, dev, func) \ 2844444f854SMatthew Garrett ((protocol), efi64_zero_upper(seg), efi64_zero_upper(bus), \ 2854444f854SMatthew Garrett efi64_zero_upper(dev), efi64_zero_upper(func)) 2864444f854SMatthew Garrett 2872931d526SArd Biesheuvel /* LoadFile */ 2882931d526SArd Biesheuvel #define __efi64_argmap_load_file(protocol, path, policy, bufsize, buf) \ 2892931d526SArd Biesheuvel ((protocol), (path), (policy), efi64_zero_upper(bufsize), (buf)) 2902931d526SArd Biesheuvel 291b4b89a02SArvind Sankar /* Graphics Output Protocol */ 292b4b89a02SArvind Sankar #define __efi64_argmap_query_mode(gop, mode, size, info) \ 293b4b89a02SArvind Sankar ((gop), (mode), efi64_zero_upper(size), efi64_zero_upper(info)) 294b4b89a02SArvind Sankar 2954da87c51SArd Biesheuvel /* TCG2 protocol */ 2964da87c51SArd Biesheuvel #define __efi64_argmap_hash_log_extend_event(prot, fl, addr, size, ev) \ 2974da87c51SArd Biesheuvel ((prot), (fl), 0ULL, (u64)(addr), 0ULL, (u64)(size), 0ULL, ev) 2984da87c51SArd Biesheuvel 29931f1a0edSArd Biesheuvel /* DXE services */ 30031f1a0edSArd Biesheuvel #define __efi64_argmap_get_memory_space_descriptor(phys, desc) \ 30131f1a0edSArd Biesheuvel (__efi64_split(phys), (desc)) 30231f1a0edSArd Biesheuvel 303aa6d1ed1SEvgeniy Baskov #define __efi64_argmap_set_memory_space_attributes(phys, size, flags) \ 30431f1a0edSArd Biesheuvel (__efi64_split(phys), __efi64_split(size), __efi64_split(flags)) 30531f1a0edSArd Biesheuvel 306f8a31244SArd Biesheuvel /* file protocol */ 307f8a31244SArd Biesheuvel #define __efi64_argmap_open(prot, newh, fname, mode, attr) \ 308f8a31244SArd Biesheuvel ((prot), efi64_zero_upper(newh), (fname), __efi64_split(mode), \ 309f8a31244SArd Biesheuvel __efi64_split(attr)) 310f8a31244SArd Biesheuvel 311f8a31244SArd Biesheuvel #define __efi64_argmap_set_position(pos) (__efi64_split(pos)) 312f8a31244SArd Biesheuvel 313f8a31244SArd Biesheuvel /* file system protocol */ 314f8a31244SArd Biesheuvel #define __efi64_argmap_open_volume(prot, file) \ 315f8a31244SArd Biesheuvel ((prot), efi64_zero_upper(file)) 316f8a31244SArd Biesheuvel 31779729f26SEvgeniy Baskov /* Memory Attribute Protocol */ 31845d51654SArd Biesheuvel #define __efi64_argmap_get_memory_attributes(protocol, phys, size, flags) \ 31945d51654SArd Biesheuvel ((protocol), __efi64_split(phys), __efi64_split(size), (flags)) 32045d51654SArd Biesheuvel 32179729f26SEvgeniy Baskov #define __efi64_argmap_set_memory_attributes(protocol, phys, size, flags) \ 32279729f26SEvgeniy Baskov ((protocol), __efi64_split(phys), __efi64_split(size), __efi64_split(flags)) 32379729f26SEvgeniy Baskov 32479729f26SEvgeniy Baskov #define __efi64_argmap_clear_memory_attributes(protocol, phys, size, flags) \ 32579729f26SEvgeniy Baskov ((protocol), __efi64_split(phys), __efi64_split(size), __efi64_split(flags)) 32679729f26SEvgeniy Baskov 327ea7d87f9SArvind Sankar /* 328ea7d87f9SArvind Sankar * The macros below handle the plumbing for the argument mapping. To add a 329ea7d87f9SArvind Sankar * mapping for a specific EFI method, simply define a macro 330ea7d87f9SArvind Sankar * __efi64_argmap_<method name>, following the examples above. 331ea7d87f9SArvind Sankar */ 332ea7d87f9SArvind Sankar 333ea7d87f9SArvind Sankar #define __efi64_thunk_map(inst, func, ...) \ 334ea7d87f9SArvind Sankar efi64_thunk(inst->mixed_mode.func, \ 335ea7d87f9SArvind Sankar __efi64_argmap(__efi64_argmap_ ## func(__VA_ARGS__), \ 336ea7d87f9SArvind Sankar (__VA_ARGS__))) 337ea7d87f9SArvind Sankar 338ea7d87f9SArvind Sankar #define __efi64_argmap(mapped, args) \ 339ea7d87f9SArvind Sankar __PASTE(__efi64_argmap__, __efi_nargs(__efi_eat mapped))(mapped, args) 340ea7d87f9SArvind Sankar #define __efi64_argmap__0(mapped, args) __efi_eval mapped 341ea7d87f9SArvind Sankar #define __efi64_argmap__1(mapped, args) __efi_eval args 342ea7d87f9SArvind Sankar 343ea7d87f9SArvind Sankar #define __efi_eat(...) 344ea7d87f9SArvind Sankar #define __efi_eval(...) __VA_ARGS__ 345ea7d87f9SArvind Sankar 346a61962d8SArd Biesheuvel static inline efi_status_t __efi64_widen_efi_status(u64 status) 347a61962d8SArd Biesheuvel { 348a61962d8SArd Biesheuvel /* use rotate to move the value of bit #31 into position #63 */ 349a61962d8SArd Biesheuvel return ror64(rol32(status, 1), 1); 350a61962d8SArd Biesheuvel } 351ea7d87f9SArvind Sankar 352a61962d8SArd Biesheuvel /* The macro below handles dispatching via the thunk if needed */ 3533552fdf2SLukas Wunner 354a61962d8SArd Biesheuvel #define efi_fn_call(inst, func, ...) \ 355a61962d8SArd Biesheuvel (efi_is_native() ? (inst)->func(__VA_ARGS__) \ 356a61962d8SArd Biesheuvel : efi_mixed_call((inst), func, ##__VA_ARGS__)) 357243b6754SArd Biesheuvel 358a61962d8SArd Biesheuvel #define efi_mixed_call(inst, func, ...) \ 359a61962d8SArd Biesheuvel _Generic(inst->func(__VA_ARGS__), \ 360a61962d8SArd Biesheuvel efi_status_t: \ 361a61962d8SArd Biesheuvel __efi64_widen_efi_status( \ 362a61962d8SArd Biesheuvel __efi64_thunk_map(inst, func, ##__VA_ARGS__)), \ 363a61962d8SArd Biesheuvel u64: ({ BUILD_BUG(); ULONG_MAX; }), \ 364a61962d8SArd Biesheuvel default: \ 365a61962d8SArd Biesheuvel (__typeof__(inst->func(__VA_ARGS__))) \ 366a61962d8SArd Biesheuvel __efi64_thunk_map(inst, func, ##__VA_ARGS__)) 3673ba75c13SBaskov Evgeniy 368de8c5520SArvind Sankar #else /* CONFIG_EFI_MIXED */ 369de8c5520SArvind Sankar 370de8c5520SArvind Sankar static inline bool efi_is_64bit(void) 371de8c5520SArvind Sankar { 372de8c5520SArvind Sankar return IS_ENABLED(CONFIG_X86_64); 373de8c5520SArvind Sankar } 374de8c5520SArvind Sankar 375de8c5520SArvind Sankar #endif /* CONFIG_EFI_MIXED */ 376de8c5520SArvind Sankar 37744be28e9SMatt Fleming extern bool efi_reboot_required(void); 378e55f31a5SArd Biesheuvel extern bool efi_is_table_address(unsigned long phys_addr); 37944be28e9SMatt Fleming 3806950e31bSDan Williams extern void efi_reserve_boot_services(void); 3816b59e366SSatoru Takeuchi #else 3825c12af0cSDave Young static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {} 38344be28e9SMatt Fleming static inline bool efi_reboot_required(void) 38444be28e9SMatt Fleming { 38544be28e9SMatt Fleming return false; 38644be28e9SMatt Fleming } 387e55f31a5SArd Biesheuvel static inline bool efi_is_table_address(unsigned long phys_addr) 388e55f31a5SArd Biesheuvel { 389e55f31a5SArd Biesheuvel return false; 390e55f31a5SArd Biesheuvel } 3916950e31bSDan Williams static inline void efi_reserve_boot_services(void) 3926950e31bSDan Williams { 3936950e31bSDan Williams } 394bb898558SAl Viro #endif /* CONFIG_EFI */ 395bb898558SAl Viro 396199c8471SDan Williams #ifdef CONFIG_EFI_FAKE_MEMMAP 397199c8471SDan Williams extern void __init efi_fake_memmap_early(void); 3984059ba65SArd Biesheuvel extern void __init efi_fake_memmap(void); 399199c8471SDan Williams #else 400199c8471SDan Williams static inline void efi_fake_memmap_early(void) 401199c8471SDan Williams { 402199c8471SDan Williams } 4034059ba65SArd Biesheuvel 4044059ba65SArd Biesheuvel static inline void efi_fake_memmap(void) 4054059ba65SArd Biesheuvel { 4064059ba65SArd Biesheuvel } 407199c8471SDan Williams #endif 408199c8471SDan Williams 409fdc6d38dSArd Biesheuvel extern int __init efi_memmap_alloc(unsigned int num_entries, 410fdc6d38dSArd Biesheuvel struct efi_memory_map_data *data); 411fdc6d38dSArd Biesheuvel extern void __efi_memmap_free(u64 phys, unsigned long size, 412fdc6d38dSArd Biesheuvel unsigned long flags); 413fdc6d38dSArd Biesheuvel #define __efi_memmap_free __efi_memmap_free 414fdc6d38dSArd Biesheuvel 415fdc6d38dSArd Biesheuvel extern int __init efi_memmap_install(struct efi_memory_map_data *data); 416fdc6d38dSArd Biesheuvel extern int __init efi_memmap_split_count(efi_memory_desc_t *md, 417fdc6d38dSArd Biesheuvel struct range *range); 418fdc6d38dSArd Biesheuvel extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap, 419fdc6d38dSArd Biesheuvel void *buf, struct efi_mem_range *mem); 420fdc6d38dSArd Biesheuvel 42125519d68SChester Lin #define arch_ima_efi_boot_mode \ 42225519d68SChester Lin ({ extern struct boot_params boot_params; boot_params.secure_boot; }) 42325519d68SChester Lin 4241fff234dSArd Biesheuvel #ifdef CONFIG_EFI_RUNTIME_MAP 4251fff234dSArd Biesheuvel int efi_get_runtime_map_size(void); 4261fff234dSArd Biesheuvel int efi_get_runtime_map_desc_size(void); 4271fff234dSArd Biesheuvel int efi_runtime_map_copy(void *buf, size_t bufsz); 4281fff234dSArd Biesheuvel #else 4291fff234dSArd Biesheuvel static inline int efi_get_runtime_map_size(void) 4301fff234dSArd Biesheuvel { 4311fff234dSArd Biesheuvel return 0; 4321fff234dSArd Biesheuvel } 4331fff234dSArd Biesheuvel 4341fff234dSArd Biesheuvel static inline int efi_get_runtime_map_desc_size(void) 4351fff234dSArd Biesheuvel { 4361fff234dSArd Biesheuvel return 0; 4371fff234dSArd Biesheuvel } 4381fff234dSArd Biesheuvel 4391fff234dSArd Biesheuvel static inline int efi_runtime_map_copy(void *buf, size_t bufsz) 4401fff234dSArd Biesheuvel { 4411fff234dSArd Biesheuvel return 0; 4421fff234dSArd Biesheuvel } 4431fff234dSArd Biesheuvel 4441fff234dSArd Biesheuvel #endif 4451fff234dSArd Biesheuvel 4461965aae3SH. Peter Anvin #endif /* _ASM_X86_EFI_H */ 447