^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _ASM_X86_EFI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ASM_X86_EFI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <asm/fpu/api.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <asm/processor-flags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <asm/tlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <asm/nospec-branch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/build_bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) extern unsigned long efi_fw_vendor, efi_config_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * We map the EFI regions needed for runtime services non-contiguously,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * with preserved alignment on virtual addresses starting from -4G down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * for a total max space of 64G. This way, we provide for stable runtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * services addresses across kernels so that a kexec'd kernel can still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * use them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * This is the main reason why we're doing stable VA mappings for RT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * services.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define EFI32_LOADER_SIGNATURE "EL32"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define EFI64_LOADER_SIGNATURE "EL64"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define ARCH_EFI_IRQ_FLAGS_MASK X86_EFLAGS_IF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * The EFI services are called through variadic functions in many cases. These
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * functions are implemented in assembler and support only a fixed number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * arguments. The macros below allows us to check at build time that we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * try to call them with too many arguments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * __efi_nargs() will return the number of arguments if it is 7 or less, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * cause a BUILD_BUG otherwise. The limitations of the C preprocessor make it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * impossible to calculate the exact number of arguments beyond some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * pre-defined limit. The maximum number of arguments currently supported by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * any of the thunks is 7, so this is good enough for now and can be extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * in the obvious way if we ever need more.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define __efi_nargs(...) __efi_nargs_(__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define __efi_nargs_(...) __efi_nargs__(0, ##__VA_ARGS__, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) __efi_arg_sentinel(7), __efi_arg_sentinel(6), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) __efi_arg_sentinel(5), __efi_arg_sentinel(4), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) __efi_arg_sentinel(3), __efi_arg_sentinel(2), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) __efi_arg_sentinel(1), __efi_arg_sentinel(0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define __efi_nargs__(_0, _1, _2, _3, _4, _5, _6, _7, n, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) __take_second_arg(n, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ({ BUILD_BUG_ON_MSG(1, "__efi_nargs limit exceeded"); 8; }))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define __efi_arg_sentinel(n) , n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * __efi_nargs_check(f, n, ...) will cause a BUILD_BUG if the ellipsis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * represents more than n arguments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define __efi_nargs_check(f, n, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) __efi_nargs_check_(f, __efi_nargs(__VA_ARGS__), n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define __efi_nargs_check_(f, p, n) __efi_nargs_check__(f, p, n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define __efi_nargs_check__(f, p, n) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) BUILD_BUG_ON_MSG( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) (p) > (n), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #f " called with too many arguments (" #p ">" #n ")"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define arch_efi_call_virt_setup() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) kernel_fpu_begin(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) firmware_restrict_branch_speculation_start(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define arch_efi_call_virt_teardown() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) firmware_restrict_branch_speculation_end(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) kernel_fpu_end(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define arch_efi_call_virt(p, f, args...) p->f(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #else /* !CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define EFI_LOADER_SIGNATURE "EL64"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) extern asmlinkage u64 __efi_call(void *fp, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define efi_call(...) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) __efi_nargs_check(efi_call, 7, __VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) __efi_call(__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * struct efi_scratch - Scratch space used while switching to/from efi_mm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * @phys_stack: stack used during EFI Mixed Mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * @prev_mm: store/restore stolen mm_struct while switching to/from efi_mm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct efi_scratch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u64 phys_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct mm_struct *prev_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define arch_efi_call_virt_setup() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) efi_sync_low_kernel_mappings(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) kernel_fpu_begin(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) firmware_restrict_branch_speculation_start(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) efi_switch_mm(&efi_mm); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define arch_efi_call_virt(p, f, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) efi_call((void *)p->f, args) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define arch_efi_call_virt_teardown() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) efi_switch_mm(efi_scratch.prev_mm); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) firmware_restrict_branch_speculation_end(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) kernel_fpu_end(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #ifdef CONFIG_KASAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * CONFIG_KASAN may redefine memset to __memset. __memset function is present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * only in kernel binary. Since the EFI stub linked into a separate binary it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * doesn't have __memset(). So we should use standard memset from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * arch/x86/boot/compressed/string.c. The same applies to memcpy and memmove.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #undef memcpy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #undef memset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #undef memmove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif /* CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) extern struct efi_scratch efi_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) extern int __init efi_memblock_x86_reserve_range(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) extern void __init efi_print_memmap(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) extern void __init efi_map_region(efi_memory_desc_t *md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) extern void efi_sync_low_kernel_mappings(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) extern int __init efi_alloc_page_tables(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) extern void __init efi_runtime_update_mappings(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) extern void __init efi_dump_pagetable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) extern void __init efi_apply_memmap_quirks(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) extern int __init efi_reuse_config(u64 tables, int nr_tables);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) extern void efi_delete_dummy_variable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) extern void efi_switch_mm(struct mm_struct *mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) extern void efi_recover_from_page_fault(unsigned long phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) extern void efi_free_boot_services(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* kexec external ABI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct efi_setup_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) u64 fw_vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) u64 __unused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) u64 tables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) u64 smbios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) u64 reserved[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) extern u64 efi_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #ifdef CONFIG_EFI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) extern efi_status_t __efi64_thunk(u32, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define efi64_thunk(...) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) __efi_nargs_check(efi64_thunk, 6, __VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) __efi64_thunk(__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline bool efi_is_mixed(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (!IS_ENABLED(CONFIG_EFI_MIXED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return IS_ENABLED(CONFIG_X86_64) && !efi_enabled(EFI_64BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static inline bool efi_runtime_supported(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return IS_ENABLED(CONFIG_EFI_MIXED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) extern void parse_efi_setup(u64 phys_addr, u32 data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) extern void efi_thunk_runtime_setup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) efi_status_t efi_set_virtual_address_map(unsigned long memory_map_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) unsigned long descriptor_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) u32 descriptor_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) efi_memory_desc_t *virtual_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) unsigned long systab_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* arch specific definitions used by the stub code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #ifdef CONFIG_EFI_MIXED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define ARCH_HAS_EFISTUB_WRAPPERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static inline bool efi_is_64bit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) extern const bool efi_is64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return efi_is64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static inline bool efi_is_native(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!IS_ENABLED(CONFIG_X86_64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return efi_is_64bit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define efi_mixed_mode_cast(attr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) __builtin_choose_expr( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) __builtin_types_compatible_p(u32, __typeof__(attr)), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) (unsigned long)(attr), (attr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #define efi_table_attr(inst, attr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) (efi_is_native() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) ? inst->attr \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) : (__typeof__(inst->attr)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) efi_mixed_mode_cast(inst->mixed_mode.attr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * The following macros allow translating arguments if necessary from native to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * mixed mode. The use case for this is to initialize the upper 32 bits of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * output parameters, and where the 32-bit method requires a 64-bit argument,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * which must be split up into two arguments to be thunked properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * As examples, the AllocatePool boot service returns the address of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * allocation, but it will not set the high 32 bits of the address. To ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * that the full 64-bit address is initialized, we zero-init the address before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * calling the thunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * The FreePages boot service takes a 64-bit physical address even in 32-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * mode. For the thunk to work correctly, a native 64-bit call of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * free_pages(addr, size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * must be translated to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * efi64_thunk(free_pages, addr & U32_MAX, addr >> 32, size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * so that the two 32-bit halves of addr get pushed onto the stack separately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static inline void *efi64_zero_upper(void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ((u32 *)p)[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static inline u32 efi64_convert_status(efi_status_t status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return (u32)(status | (u64)status >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #define __efi64_argmap_free_pages(addr, size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ((addr), 0, (size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #define __efi64_argmap_get_memory_map(mm_size, mm, key, size, ver) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) ((mm_size), (mm), efi64_zero_upper(key), efi64_zero_upper(size), (ver))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #define __efi64_argmap_allocate_pool(type, size, buffer) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ((type), (size), efi64_zero_upper(buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #define __efi64_argmap_create_event(type, tpl, f, c, event) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ((type), (tpl), (f), (c), efi64_zero_upper(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #define __efi64_argmap_set_timer(event, type, time) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ((event), (type), lower_32_bits(time), upper_32_bits(time))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define __efi64_argmap_wait_for_event(num, event, index) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ((num), (event), efi64_zero_upper(index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define __efi64_argmap_handle_protocol(handle, protocol, interface) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ((handle), (protocol), efi64_zero_upper(interface))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #define __efi64_argmap_locate_protocol(protocol, reg, interface) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ((protocol), (reg), efi64_zero_upper(interface))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define __efi64_argmap_locate_device_path(protocol, path, handle) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ((protocol), (path), efi64_zero_upper(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #define __efi64_argmap_exit(handle, status, size, data) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ((handle), efi64_convert_status(status), (size), (data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* PCI I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #define __efi64_argmap_get_location(protocol, seg, bus, dev, func) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ((protocol), efi64_zero_upper(seg), efi64_zero_upper(bus), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) efi64_zero_upper(dev), efi64_zero_upper(func))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /* LoadFile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) #define __efi64_argmap_load_file(protocol, path, policy, bufsize, buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ((protocol), (path), (policy), efi64_zero_upper(bufsize), (buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* Graphics Output Protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #define __efi64_argmap_query_mode(gop, mode, size, info) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ((gop), (mode), efi64_zero_upper(size), efi64_zero_upper(info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * The macros below handle the plumbing for the argument mapping. To add a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * mapping for a specific EFI method, simply define a macro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * __efi64_argmap_<method name>, following the examples above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #define __efi64_thunk_map(inst, func, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) efi64_thunk(inst->mixed_mode.func, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) __efi64_argmap(__efi64_argmap_ ## func(__VA_ARGS__), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) (__VA_ARGS__)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) #define __efi64_argmap(mapped, args) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) __PASTE(__efi64_argmap__, __efi_nargs(__efi_eat mapped))(mapped, args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #define __efi64_argmap__0(mapped, args) __efi_eval mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #define __efi64_argmap__1(mapped, args) __efi_eval args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define __efi_eat(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #define __efi_eval(...) __VA_ARGS__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* The three macros below handle dispatching via the thunk if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #define efi_call_proto(inst, func, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) (efi_is_native() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) ? inst->func(inst, ##__VA_ARGS__) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) : __efi64_thunk_map(inst, func, inst, ##__VA_ARGS__))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #define efi_bs_call(func, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) (efi_is_native() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ? efi_system_table->boottime->func(__VA_ARGS__) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) : __efi64_thunk_map(efi_table_attr(efi_system_table, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) boottime), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) func, __VA_ARGS__))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #define efi_rt_call(func, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) (efi_is_native() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) ? efi_system_table->runtime->func(__VA_ARGS__) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) : __efi64_thunk_map(efi_table_attr(efi_system_table, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) runtime), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) func, __VA_ARGS__))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #else /* CONFIG_EFI_MIXED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static inline bool efi_is_64bit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return IS_ENABLED(CONFIG_X86_64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) #endif /* CONFIG_EFI_MIXED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) extern bool efi_reboot_required(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) extern bool efi_is_table_address(unsigned long phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) extern void efi_find_mirror(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) extern void efi_reserve_boot_services(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static inline bool efi_reboot_required(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static inline bool efi_is_table_address(unsigned long phys_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static inline void efi_find_mirror(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static inline void efi_reserve_boot_services(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) #endif /* CONFIG_EFI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #ifdef CONFIG_EFI_FAKE_MEMMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) extern void __init efi_fake_memmap_early(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static inline void efi_fake_memmap_early(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #endif /* _ASM_X86_EFI_H */