xref: /openbmc/linux/arch/x86/include/asm/efi.h (revision c46f52231e79af025e2c89e889d69ec20a4c024f)
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>
1014b864f4SArvind Sankar #include <linux/build_bug.h>
119b47c527SArvind Sankar #include <linux/kernel.h>
1265fddcfcSMike Rapoport #include <linux/pgtable.h>
13744937b0SIngo Molnar 
149cd437acSArd Biesheuvel extern unsigned long efi_fw_vendor, efi_config_table;
159cd437acSArd Biesheuvel 
16d2f7cbe7SBorislav Petkov /*
17d2f7cbe7SBorislav Petkov  * We map the EFI regions needed for runtime services non-contiguously,
18d2f7cbe7SBorislav Petkov  * with preserved alignment on virtual addresses starting from -4G down
19d2f7cbe7SBorislav Petkov  * for a total max space of 64G. This way, we provide for stable runtime
20d2f7cbe7SBorislav Petkov  * services addresses across kernels so that a kexec'd kernel can still
21d2f7cbe7SBorislav Petkov  * use them.
22d2f7cbe7SBorislav Petkov  *
23d2f7cbe7SBorislav Petkov  * This is the main reason why we're doing stable VA mappings for RT
24d2f7cbe7SBorislav Petkov  * services.
25d2f7cbe7SBorislav Petkov  */
26d2f7cbe7SBorislav Petkov 
27b8ff87a6SMatt Fleming #define EFI32_LOADER_SIGNATURE	"EL32"
28b8ff87a6SMatt Fleming #define EFI64_LOADER_SIGNATURE	"EL64"
29b8ff87a6SMatt Fleming 
309788375dSMark Rutland #define ARCH_EFI_IRQ_FLAGS_MASK	X86_EFLAGS_IF
31bb898558SAl Viro 
3214b864f4SArvind Sankar /*
3314b864f4SArvind Sankar  * The EFI services are called through variadic functions in many cases. These
3414b864f4SArvind Sankar  * functions are implemented in assembler and support only a fixed number of
3514b864f4SArvind Sankar  * arguments. The macros below allows us to check at build time that we don't
3614b864f4SArvind Sankar  * try to call them with too many arguments.
3714b864f4SArvind Sankar  *
3814b864f4SArvind Sankar  * __efi_nargs() will return the number of arguments if it is 7 or less, and
3914b864f4SArvind Sankar  * cause a BUILD_BUG otherwise. The limitations of the C preprocessor make it
4014b864f4SArvind Sankar  * impossible to calculate the exact number of arguments beyond some
4114b864f4SArvind Sankar  * pre-defined limit. The maximum number of arguments currently supported by
4214b864f4SArvind Sankar  * any of the thunks is 7, so this is good enough for now and can be extended
4314b864f4SArvind Sankar  * in the obvious way if we ever need more.
4414b864f4SArvind Sankar  */
4514b864f4SArvind Sankar 
4614b864f4SArvind Sankar #define __efi_nargs(...) __efi_nargs_(__VA_ARGS__)
4714b864f4SArvind Sankar #define __efi_nargs_(...) __efi_nargs__(0, ##__VA_ARGS__,	\
4814b864f4SArvind Sankar 	__efi_arg_sentinel(7), __efi_arg_sentinel(6),		\
4914b864f4SArvind Sankar 	__efi_arg_sentinel(5), __efi_arg_sentinel(4),		\
5014b864f4SArvind Sankar 	__efi_arg_sentinel(3), __efi_arg_sentinel(2),		\
5114b864f4SArvind Sankar 	__efi_arg_sentinel(1), __efi_arg_sentinel(0))
5214b864f4SArvind Sankar #define __efi_nargs__(_0, _1, _2, _3, _4, _5, _6, _7, n, ...)	\
5314b864f4SArvind Sankar 	__take_second_arg(n,					\
5414b864f4SArvind Sankar 		({ BUILD_BUG_ON_MSG(1, "__efi_nargs limit exceeded"); 8; }))
5514b864f4SArvind Sankar #define __efi_arg_sentinel(n) , n
5614b864f4SArvind Sankar 
5714b864f4SArvind Sankar /*
5814b864f4SArvind Sankar  * __efi_nargs_check(f, n, ...) will cause a BUILD_BUG if the ellipsis
5914b864f4SArvind Sankar  * represents more than n arguments.
6014b864f4SArvind Sankar  */
6114b864f4SArvind Sankar 
6214b864f4SArvind Sankar #define __efi_nargs_check(f, n, ...)					\
6314b864f4SArvind Sankar 	__efi_nargs_check_(f, __efi_nargs(__VA_ARGS__), n)
6414b864f4SArvind Sankar #define __efi_nargs_check_(f, p, n) __efi_nargs_check__(f, p, n)
6514b864f4SArvind Sankar #define __efi_nargs_check__(f, p, n) ({					\
6614b864f4SArvind Sankar 	BUILD_BUG_ON_MSG(						\
6714b864f4SArvind Sankar 		(p) > (n),						\
6814b864f4SArvind Sankar 		#f " called with too many arguments (" #p ">" #n ")");	\
6914b864f4SArvind Sankar })
7014b864f4SArvind Sankar 
719788375dSMark Rutland #ifdef CONFIG_X86_32
72dd84441aSDavid Woodhouse #define arch_efi_call_virt_setup()					\
73dd84441aSDavid Woodhouse ({									\
74dd84441aSDavid Woodhouse 	kernel_fpu_begin();						\
75dd84441aSDavid Woodhouse 	firmware_restrict_branch_speculation_start();			\
76dd84441aSDavid Woodhouse })
77dd84441aSDavid Woodhouse 
78dd84441aSDavid Woodhouse #define arch_efi_call_virt_teardown()					\
79dd84441aSDavid Woodhouse ({									\
80dd84441aSDavid Woodhouse 	firmware_restrict_branch_speculation_end();			\
81dd84441aSDavid Woodhouse 	kernel_fpu_end();						\
82dd84441aSDavid Woodhouse })
83dd84441aSDavid Woodhouse 
8489ed4865SArd Biesheuvel #define arch_efi_call_virt(p, f, args...)	p->f(args)
85982e239cSRicardo Neri 
86bb898558SAl Viro #else /* !CONFIG_X86_32 */
87bb898558SAl Viro 
8862fa6e69SMatt Fleming #define EFI_LOADER_SIGNATURE	"EL64"
89bb898558SAl Viro 
9014b864f4SArvind Sankar extern asmlinkage u64 __efi_call(void *fp, ...);
9114b864f4SArvind Sankar 
9214b864f4SArvind Sankar #define efi_call(...) ({						\
9314b864f4SArvind Sankar 	__efi_nargs_check(efi_call, 7, __VA_ARGS__);			\
9414b864f4SArvind Sankar 	__efi_call(__VA_ARGS__);					\
9514b864f4SArvind Sankar })
96bb898558SAl Viro 
97c9f2a9a6SMatt Fleming /*
9803781e40SSai Praneeth  * struct efi_scratch - Scratch space used while switching to/from efi_mm
9903781e40SSai Praneeth  * @phys_stack: stack used during EFI Mixed Mode
10003781e40SSai Praneeth  * @prev_mm:    store/restore stolen mm_struct while switching to/from efi_mm
101c9f2a9a6SMatt Fleming  */
102c9f2a9a6SMatt Fleming struct efi_scratch {
103c9f2a9a6SMatt Fleming 	u64			phys_stack;
10403781e40SSai Praneeth 	struct mm_struct	*prev_mm;
105c9f2a9a6SMatt Fleming } __packed;
106c9f2a9a6SMatt Fleming 
107bc25f9dbSMark Rutland #define arch_efi_call_virt_setup()					\
108d2f7cbe7SBorislav Petkov ({									\
109d2f7cbe7SBorislav Petkov 	efi_sync_low_kernel_mappings();					\
11012209993SSebastian Andrzej Siewior 	kernel_fpu_begin();						\
111dd84441aSDavid Woodhouse 	firmware_restrict_branch_speculation_start();			\
11203781e40SSai Praneeth 	efi_switch_mm(&efi_mm);						\
113bc25f9dbSMark Rutland })
114bc25f9dbSMark Rutland 
11580e75596SAlex Thorlton #define arch_efi_call_virt(p, f, args...)				\
11680e75596SAlex Thorlton 	efi_call((void *)p->f, args)					\
117bc25f9dbSMark Rutland 
118bc25f9dbSMark Rutland #define arch_efi_call_virt_teardown()					\
119bc25f9dbSMark Rutland ({									\
12003781e40SSai Praneeth 	efi_switch_mm(efi_scratch.prev_mm);				\
121dd84441aSDavid Woodhouse 	firmware_restrict_branch_speculation_end();			\
12212209993SSebastian Andrzej Siewior 	kernel_fpu_end();						\
123d2f7cbe7SBorislav Petkov })
124d2f7cbe7SBorislav Petkov 
125a523841eSAndrey Ryabinin #ifdef CONFIG_KASAN
126769a8089SAndrey Ryabinin /*
127769a8089SAndrey Ryabinin  * CONFIG_KASAN may redefine memset to __memset.  __memset function is present
128769a8089SAndrey Ryabinin  * only in kernel binary.  Since the EFI stub linked into a separate binary it
129769a8089SAndrey Ryabinin  * doesn't have __memset().  So we should use standard memset from
130769a8089SAndrey Ryabinin  * arch/x86/boot/compressed/string.c.  The same applies to memcpy and memmove.
131769a8089SAndrey Ryabinin  */
132769a8089SAndrey Ryabinin #undef memcpy
133769a8089SAndrey Ryabinin #undef memset
134769a8089SAndrey Ryabinin #undef memmove
135a523841eSAndrey Ryabinin #endif
136769a8089SAndrey Ryabinin 
137bb898558SAl Viro #endif /* CONFIG_X86_32 */
138bb898558SAl Viro 
139d2f7cbe7SBorislav Petkov extern struct efi_scratch efi_scratch;
1404e78eb05SMathias Krause extern int __init efi_memblock_x86_reserve_range(void);
1410bbea1ceSTaku Izumi extern void __init efi_print_memmap(void);
142d2f7cbe7SBorislav Petkov extern void __init efi_map_region(efi_memory_desc_t *md);
1433b266496SDave Young extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
144d2f7cbe7SBorislav Petkov extern void efi_sync_low_kernel_mappings(void);
14567a9108eSMatt Fleming extern int __init efi_alloc_page_tables(void);
1464e78eb05SMathias Krause extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
1476d0cc887SSai Praneeth extern void __init efi_runtime_update_mappings(void);
14811cc8512SBorislav Petkov extern void __init efi_dump_pagetable(void);
149a5d90c92SBorislav Petkov extern void __init efi_apply_memmap_quirks(void);
150eeb9db09SSaurabh Tangri extern int __init efi_reuse_config(u64 tables, int nr_tables);
151eeb9db09SSaurabh Tangri extern void efi_delete_dummy_variable(void);
15203781e40SSai Praneeth extern void efi_switch_mm(struct mm_struct *mm);
153*c46f5223SAndy Lutomirski extern void efi_crash_gracefully_on_page_fault(unsigned long phys_addr);
15447c33a09SSai Praneeth Prakhya extern void efi_free_boot_services(void);
155bb898558SAl Viro 
156a088b858SArd Biesheuvel /* kexec external ABI */
1571fec0533SDave Young struct efi_setup_data {
1581fec0533SDave Young 	u64 fw_vendor;
159a088b858SArd Biesheuvel 	u64 __unused;
1601fec0533SDave Young 	u64 tables;
1611fec0533SDave Young 	u64 smbios;
1621fec0533SDave Young 	u64 reserved[8];
1631fec0533SDave Young };
1641fec0533SDave Young 
1651fec0533SDave Young extern u64 efi_setup;
1661fec0533SDave Young 
1676b59e366SSatoru Takeuchi #ifdef CONFIG_EFI
16814b864f4SArvind Sankar extern efi_status_t __efi64_thunk(u32, ...);
16914b864f4SArvind Sankar 
17014b864f4SArvind Sankar #define efi64_thunk(...) ({						\
17114b864f4SArvind Sankar 	__efi_nargs_check(efi64_thunk, 6, __VA_ARGS__);			\
17214b864f4SArvind Sankar 	__efi64_thunk(__VA_ARGS__);					\
17314b864f4SArvind Sankar })
1746b59e366SSatoru Takeuchi 
175a8147dbaSArd Biesheuvel static inline bool efi_is_mixed(void)
1766b59e366SSatoru Takeuchi {
177a8147dbaSArd Biesheuvel 	if (!IS_ENABLED(CONFIG_EFI_MIXED))
178a8147dbaSArd Biesheuvel 		return false;
179a8147dbaSArd Biesheuvel 	return IS_ENABLED(CONFIG_X86_64) && !efi_enabled(EFI_64BIT);
1806b59e366SSatoru Takeuchi }
1816b59e366SSatoru Takeuchi 
1827d453eeeSMatt Fleming static inline bool efi_runtime_supported(void)
1837d453eeeSMatt Fleming {
1846cfcd6f0SArd Biesheuvel 	if (IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT))
1857d453eeeSMatt Fleming 		return true;
1867d453eeeSMatt Fleming 
1871f299fadSArd Biesheuvel 	return IS_ENABLED(CONFIG_EFI_MIXED);
1887d453eeeSMatt Fleming }
1897d453eeeSMatt Fleming 
1905c12af0cSDave Young extern void parse_efi_setup(u64 phys_addr, u32 data_len);
1914f9dbcfcSMatt Fleming 
19221289ec0SArd Biesheuvel extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
19321289ec0SArd Biesheuvel 
1944f9dbcfcSMatt Fleming extern void efi_thunk_runtime_setup(void);
19569829470SArd Biesheuvel efi_status_t efi_set_virtual_address_map(unsigned long memory_map_size,
19669829470SArd Biesheuvel 					 unsigned long descriptor_size,
19769829470SArd Biesheuvel 					 u32 descriptor_version,
19859f2a619SArd Biesheuvel 					 efi_memory_desc_t *virtual_map,
19959f2a619SArd Biesheuvel 					 unsigned long systab_phys);
200243b6754SArd Biesheuvel 
201243b6754SArd Biesheuvel /* arch specific definitions used by the stub code */
202243b6754SArd Biesheuvel 
203de8c5520SArvind Sankar #ifdef CONFIG_EFI_MIXED
204de8c5520SArvind Sankar 
205de8c5520SArvind Sankar #define ARCH_HAS_EFISTUB_WRAPPERS
2060a755614SArd Biesheuvel 
2070a755614SArd Biesheuvel static inline bool efi_is_64bit(void)
2080a755614SArd Biesheuvel {
209de8c5520SArvind Sankar 	extern const bool efi_is64;
210de8c5520SArvind Sankar 
2110a755614SArd Biesheuvel 	return efi_is64;
2120a755614SArd Biesheuvel }
21327571616SLukas Wunner 
214f958efe9SArd Biesheuvel static inline bool efi_is_native(void)
215f958efe9SArd Biesheuvel {
216f958efe9SArd Biesheuvel 	return efi_is_64bit();
217f958efe9SArd Biesheuvel }
218f958efe9SArd Biesheuvel 
219f958efe9SArd Biesheuvel #define efi_mixed_mode_cast(attr)					\
220f958efe9SArd Biesheuvel 	__builtin_choose_expr(						\
221f958efe9SArd Biesheuvel 		__builtin_types_compatible_p(u32, __typeof__(attr)),	\
222f958efe9SArd Biesheuvel 			(unsigned long)(attr), (attr))
223f958efe9SArd Biesheuvel 
22499ea8b1dSArd Biesheuvel #define efi_table_attr(inst, attr)					\
22599ea8b1dSArd Biesheuvel 	(efi_is_native()						\
22699ea8b1dSArd Biesheuvel 		? inst->attr						\
22799ea8b1dSArd Biesheuvel 		: (__typeof__(inst->attr))				\
22899ea8b1dSArd Biesheuvel 			efi_mixed_mode_cast(inst->mixed_mode.attr))
2293552fdf2SLukas Wunner 
230ea7d87f9SArvind Sankar /*
231ea7d87f9SArvind Sankar  * The following macros allow translating arguments if necessary from native to
232ea7d87f9SArvind Sankar  * mixed mode. The use case for this is to initialize the upper 32 bits of
233ea7d87f9SArvind Sankar  * output parameters, and where the 32-bit method requires a 64-bit argument,
234ea7d87f9SArvind Sankar  * which must be split up into two arguments to be thunked properly.
235ea7d87f9SArvind Sankar  *
236ea7d87f9SArvind Sankar  * As examples, the AllocatePool boot service returns the address of the
237ea7d87f9SArvind Sankar  * allocation, but it will not set the high 32 bits of the address. To ensure
238ea7d87f9SArvind Sankar  * that the full 64-bit address is initialized, we zero-init the address before
239ea7d87f9SArvind Sankar  * calling the thunk.
240ea7d87f9SArvind Sankar  *
241ea7d87f9SArvind Sankar  * The FreePages boot service takes a 64-bit physical address even in 32-bit
242ea7d87f9SArvind Sankar  * mode. For the thunk to work correctly, a native 64-bit call of
243ea7d87f9SArvind Sankar  * 	free_pages(addr, size)
244ea7d87f9SArvind Sankar  * must be translated to
245ea7d87f9SArvind Sankar  * 	efi64_thunk(free_pages, addr & U32_MAX, addr >> 32, size)
246ea7d87f9SArvind Sankar  * so that the two 32-bit halves of addr get pushed onto the stack separately.
247ea7d87f9SArvind Sankar  */
248ea7d87f9SArvind Sankar 
249ea7d87f9SArvind Sankar static inline void *efi64_zero_upper(void *p)
250ea7d87f9SArvind Sankar {
251ea7d87f9SArvind Sankar 	((u32 *)p)[1] = 0;
252ea7d87f9SArvind Sankar 	return p;
253ea7d87f9SArvind Sankar }
254ea7d87f9SArvind Sankar 
2553b8f44fcSArd Biesheuvel static inline u32 efi64_convert_status(efi_status_t status)
2563b8f44fcSArd Biesheuvel {
2573b8f44fcSArd Biesheuvel 	return (u32)(status | (u64)status >> 32);
2583b8f44fcSArd Biesheuvel }
2593b8f44fcSArd Biesheuvel 
260ea7d87f9SArvind Sankar #define __efi64_argmap_free_pages(addr, size)				\
261ea7d87f9SArvind Sankar 	((addr), 0, (size))
262ea7d87f9SArvind Sankar 
263ea7d87f9SArvind Sankar #define __efi64_argmap_get_memory_map(mm_size, mm, key, size, ver)	\
264ea7d87f9SArvind Sankar 	((mm_size), (mm), efi64_zero_upper(key), efi64_zero_upper(size), (ver))
265ea7d87f9SArvind Sankar 
266ea7d87f9SArvind Sankar #define __efi64_argmap_allocate_pool(type, size, buffer)		\
267ea7d87f9SArvind Sankar 	((type), (size), efi64_zero_upper(buffer))
268ea7d87f9SArvind Sankar 
2699b47c527SArvind Sankar #define __efi64_argmap_create_event(type, tpl, f, c, event)		\
2709b47c527SArvind Sankar 	((type), (tpl), (f), (c), efi64_zero_upper(event))
2719b47c527SArvind Sankar 
2729b47c527SArvind Sankar #define __efi64_argmap_set_timer(event, type, time)			\
2739b47c527SArvind Sankar 	((event), (type), lower_32_bits(time), upper_32_bits(time))
2749b47c527SArvind Sankar 
2759b47c527SArvind Sankar #define __efi64_argmap_wait_for_event(num, event, index)		\
2769b47c527SArvind Sankar 	((num), (event), efi64_zero_upper(index))
2779b47c527SArvind Sankar 
278ea7d87f9SArvind Sankar #define __efi64_argmap_handle_protocol(handle, protocol, interface)	\
279ea7d87f9SArvind Sankar 	((handle), (protocol), efi64_zero_upper(interface))
280ea7d87f9SArvind Sankar 
281ea7d87f9SArvind Sankar #define __efi64_argmap_locate_protocol(protocol, reg, interface)	\
282ea7d87f9SArvind Sankar 	((protocol), (reg), efi64_zero_upper(interface))
283ea7d87f9SArvind Sankar 
284abd26868SArd Biesheuvel #define __efi64_argmap_locate_device_path(protocol, path, handle)	\
285abd26868SArd Biesheuvel 	((protocol), (path), efi64_zero_upper(handle))
286abd26868SArd Biesheuvel 
2873b8f44fcSArd Biesheuvel #define __efi64_argmap_exit(handle, status, size, data)			\
2883b8f44fcSArd Biesheuvel 	((handle), efi64_convert_status(status), (size), (data))
2893b8f44fcSArd Biesheuvel 
2904444f854SMatthew Garrett /* PCI I/O */
2914444f854SMatthew Garrett #define __efi64_argmap_get_location(protocol, seg, bus, dev, func)	\
2924444f854SMatthew Garrett 	((protocol), efi64_zero_upper(seg), efi64_zero_upper(bus),	\
2934444f854SMatthew Garrett 	 efi64_zero_upper(dev), efi64_zero_upper(func))
2944444f854SMatthew Garrett 
2952931d526SArd Biesheuvel /* LoadFile */
2962931d526SArd Biesheuvel #define __efi64_argmap_load_file(protocol, path, policy, bufsize, buf)	\
2972931d526SArd Biesheuvel 	((protocol), (path), (policy), efi64_zero_upper(bufsize), (buf))
2982931d526SArd Biesheuvel 
299b4b89a02SArvind Sankar /* Graphics Output Protocol */
300b4b89a02SArvind Sankar #define __efi64_argmap_query_mode(gop, mode, size, info)		\
301b4b89a02SArvind Sankar 	((gop), (mode), efi64_zero_upper(size), efi64_zero_upper(info))
302b4b89a02SArvind Sankar 
303ea7d87f9SArvind Sankar /*
304ea7d87f9SArvind Sankar  * The macros below handle the plumbing for the argument mapping. To add a
305ea7d87f9SArvind Sankar  * mapping for a specific EFI method, simply define a macro
306ea7d87f9SArvind Sankar  * __efi64_argmap_<method name>, following the examples above.
307ea7d87f9SArvind Sankar  */
308ea7d87f9SArvind Sankar 
309ea7d87f9SArvind Sankar #define __efi64_thunk_map(inst, func, ...)				\
310ea7d87f9SArvind Sankar 	efi64_thunk(inst->mixed_mode.func,				\
311ea7d87f9SArvind Sankar 		__efi64_argmap(__efi64_argmap_ ## func(__VA_ARGS__),	\
312ea7d87f9SArvind Sankar 			       (__VA_ARGS__)))
313ea7d87f9SArvind Sankar 
314ea7d87f9SArvind Sankar #define __efi64_argmap(mapped, args)					\
315ea7d87f9SArvind Sankar 	__PASTE(__efi64_argmap__, __efi_nargs(__efi_eat mapped))(mapped, args)
316ea7d87f9SArvind Sankar #define __efi64_argmap__0(mapped, args) __efi_eval mapped
317ea7d87f9SArvind Sankar #define __efi64_argmap__1(mapped, args) __efi_eval args
318ea7d87f9SArvind Sankar 
319ea7d87f9SArvind Sankar #define __efi_eat(...)
320ea7d87f9SArvind Sankar #define __efi_eval(...) __VA_ARGS__
321ea7d87f9SArvind Sankar 
322ea7d87f9SArvind Sankar /* The three macros below handle dispatching via the thunk if needed */
323ea7d87f9SArvind Sankar 
32447c0fd39SArd Biesheuvel #define efi_call_proto(inst, func, ...)					\
325afc4cc71SArd Biesheuvel 	(efi_is_native()						\
32647c0fd39SArd Biesheuvel 		? inst->func(inst, ##__VA_ARGS__)			\
327ea7d87f9SArvind Sankar 		: __efi64_thunk_map(inst, func, inst, ##__VA_ARGS__))
3283552fdf2SLukas Wunner 
329966291f6SArd Biesheuvel #define efi_bs_call(func, ...)						\
330afc4cc71SArd Biesheuvel 	(efi_is_native()						\
331ccc27ae7SArd Biesheuvel 		? efi_system_table->boottime->func(__VA_ARGS__)		\
332ccc27ae7SArd Biesheuvel 		: __efi64_thunk_map(efi_table_attr(efi_system_table,	\
333ccc27ae7SArd Biesheuvel 						   boottime),		\
334ccc27ae7SArd Biesheuvel 				    func, __VA_ARGS__))
335243b6754SArd Biesheuvel 
336966291f6SArd Biesheuvel #define efi_rt_call(func, ...)						\
337afc4cc71SArd Biesheuvel 	(efi_is_native()						\
338ccc27ae7SArd Biesheuvel 		? efi_system_table->runtime->func(__VA_ARGS__)		\
339ccc27ae7SArd Biesheuvel 		: __efi64_thunk_map(efi_table_attr(efi_system_table,	\
340ccc27ae7SArd Biesheuvel 						   runtime),		\
341ccc27ae7SArd Biesheuvel 				    func, __VA_ARGS__))
342a2cd2f3fSDavid Howells 
343de8c5520SArvind Sankar #else /* CONFIG_EFI_MIXED */
344de8c5520SArvind Sankar 
345de8c5520SArvind Sankar static inline bool efi_is_64bit(void)
346de8c5520SArvind Sankar {
347de8c5520SArvind Sankar 	return IS_ENABLED(CONFIG_X86_64);
348de8c5520SArvind Sankar }
349de8c5520SArvind Sankar 
350de8c5520SArvind Sankar #endif /* CONFIG_EFI_MIXED */
351de8c5520SArvind Sankar 
35244be28e9SMatt Fleming extern bool efi_reboot_required(void);
353e55f31a5SArd Biesheuvel extern bool efi_is_table_address(unsigned long phys_addr);
35444be28e9SMatt Fleming 
3556950e31bSDan Williams extern void efi_find_mirror(void);
3566950e31bSDan Williams extern void efi_reserve_boot_services(void);
3576b59e366SSatoru Takeuchi #else
3585c12af0cSDave Young static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
35944be28e9SMatt Fleming static inline bool efi_reboot_required(void)
36044be28e9SMatt Fleming {
36144be28e9SMatt Fleming 	return false;
36244be28e9SMatt Fleming }
363e55f31a5SArd Biesheuvel static inline  bool efi_is_table_address(unsigned long phys_addr)
364e55f31a5SArd Biesheuvel {
365e55f31a5SArd Biesheuvel 	return false;
366e55f31a5SArd Biesheuvel }
3676950e31bSDan Williams static inline void efi_find_mirror(void)
3686950e31bSDan Williams {
3696950e31bSDan Williams }
3706950e31bSDan Williams static inline void efi_reserve_boot_services(void)
3716950e31bSDan Williams {
3726950e31bSDan Williams }
373bb898558SAl Viro #endif /* CONFIG_EFI */
374bb898558SAl Viro 
375199c8471SDan Williams #ifdef CONFIG_EFI_FAKE_MEMMAP
376199c8471SDan Williams extern void __init efi_fake_memmap_early(void);
377199c8471SDan Williams #else
378199c8471SDan Williams static inline void efi_fake_memmap_early(void)
379199c8471SDan Williams {
380199c8471SDan Williams }
381199c8471SDan Williams #endif
382199c8471SDan Williams 
38325519d68SChester Lin #define arch_ima_efi_boot_mode	\
38425519d68SChester Lin 	({ extern struct boot_params boot_params; boot_params.secure_boot; })
38525519d68SChester Lin 
3861965aae3SH. Peter Anvin #endif /* _ASM_X86_EFI_H */
387