xref: /openbmc/linux/arch/x86/include/asm/efi.h (revision 5c12af0c41e3417e1939095325920463b5f8e726)
11965aae3SH. Peter Anvin #ifndef _ASM_X86_EFI_H
21965aae3SH. Peter Anvin #define _ASM_X86_EFI_H
3bb898558SAl Viro 
4d2f7cbe7SBorislav Petkov /*
5d2f7cbe7SBorislav Petkov  * We map the EFI regions needed for runtime services non-contiguously,
6d2f7cbe7SBorislav Petkov  * with preserved alignment on virtual addresses starting from -4G down
7d2f7cbe7SBorislav Petkov  * for a total max space of 64G. This way, we provide for stable runtime
8d2f7cbe7SBorislav Petkov  * services addresses across kernels so that a kexec'd kernel can still
9d2f7cbe7SBorislav Petkov  * use them.
10d2f7cbe7SBorislav Petkov  *
11d2f7cbe7SBorislav Petkov  * This is the main reason why we're doing stable VA mappings for RT
12d2f7cbe7SBorislav Petkov  * services.
13d2f7cbe7SBorislav Petkov  *
14d2f7cbe7SBorislav Petkov  * This flag is used in conjuction with a chicken bit called
15d2f7cbe7SBorislav Petkov  * "efi=old_map" which can be used as a fallback to the old runtime
16d2f7cbe7SBorislav Petkov  * services mapping method in case there's some b0rkage with a
17d2f7cbe7SBorislav Petkov  * particular EFI implementation (haha, it is hard to hold up the
18d2f7cbe7SBorislav Petkov  * sarcasm here...).
19d2f7cbe7SBorislav Petkov  */
20d2f7cbe7SBorislav Petkov #define EFI_OLD_MEMMAP		EFI_ARCH_1
21d2f7cbe7SBorislav Petkov 
22bb898558SAl Viro #ifdef CONFIG_X86_32
23bb898558SAl Viro 
24f7d7d01bSMatt Fleming #define EFI_LOADER_SIGNATURE	"EL32"
25f7d7d01bSMatt Fleming 
26bb898558SAl Viro extern unsigned long asmlinkage efi_call_phys(void *, ...);
27bb898558SAl Viro 
28bb898558SAl Viro #define efi_call_phys0(f)		efi_call_phys(f)
29bb898558SAl Viro #define efi_call_phys1(f, a1)		efi_call_phys(f, a1)
30bb898558SAl Viro #define efi_call_phys2(f, a1, a2)	efi_call_phys(f, a1, a2)
31bb898558SAl Viro #define efi_call_phys3(f, a1, a2, a3)	efi_call_phys(f, a1, a2, a3)
32bb898558SAl Viro #define efi_call_phys4(f, a1, a2, a3, a4)	\
33bb898558SAl Viro 	efi_call_phys(f, a1, a2, a3, a4)
34bb898558SAl Viro #define efi_call_phys5(f, a1, a2, a3, a4, a5)	\
35bb898558SAl Viro 	efi_call_phys(f, a1, a2, a3, a4, a5)
36bb898558SAl Viro #define efi_call_phys6(f, a1, a2, a3, a4, a5, a6)	\
37bb898558SAl Viro 	efi_call_phys(f, a1, a2, a3, a4, a5, a6)
38bb898558SAl Viro /*
39bb898558SAl Viro  * Wrap all the virtual calls in a way that forces the parameters on the stack.
40bb898558SAl Viro  */
41bb898558SAl Viro 
42bb898558SAl Viro #define efi_call_virt(f, args...) \
43bb898558SAl Viro 	((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
44bb898558SAl Viro 
45bb898558SAl Viro #define efi_call_virt0(f)		efi_call_virt(f)
46bb898558SAl Viro #define efi_call_virt1(f, a1)		efi_call_virt(f, a1)
47bb898558SAl Viro #define efi_call_virt2(f, a1, a2)	efi_call_virt(f, a1, a2)
48bb898558SAl Viro #define efi_call_virt3(f, a1, a2, a3)	efi_call_virt(f, a1, a2, a3)
49bb898558SAl Viro #define efi_call_virt4(f, a1, a2, a3, a4)	\
50bb898558SAl Viro 	efi_call_virt(f, a1, a2, a3, a4)
51bb898558SAl Viro #define efi_call_virt5(f, a1, a2, a3, a4, a5)	\
52bb898558SAl Viro 	efi_call_virt(f, a1, a2, a3, a4, a5)
53bb898558SAl Viro #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6)	\
54bb898558SAl Viro 	efi_call_virt(f, a1, a2, a3, a4, a5, a6)
55bb898558SAl Viro 
563e8fa263SMatt Fleming #define efi_ioremap(addr, size, type, attr)	ioremap_cache(addr, size)
57e1ad783bSKeith Packard 
58bb898558SAl Viro #else /* !CONFIG_X86_32 */
59bb898558SAl Viro 
60f7d7d01bSMatt Fleming #define EFI_LOADER_SIGNATURE	"EL64"
61f7d7d01bSMatt Fleming 
62bb898558SAl Viro extern u64 efi_call0(void *fp);
63bb898558SAl Viro extern u64 efi_call1(void *fp, u64 arg1);
64bb898558SAl Viro extern u64 efi_call2(void *fp, u64 arg1, u64 arg2);
65bb898558SAl Viro extern u64 efi_call3(void *fp, u64 arg1, u64 arg2, u64 arg3);
66bb898558SAl Viro extern u64 efi_call4(void *fp, u64 arg1, u64 arg2, u64 arg3, u64 arg4);
67bb898558SAl Viro extern u64 efi_call5(void *fp, u64 arg1, u64 arg2, u64 arg3,
68bb898558SAl Viro 		     u64 arg4, u64 arg5);
69bb898558SAl Viro extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,
70bb898558SAl Viro 		     u64 arg4, u64 arg5, u64 arg6);
71bb898558SAl Viro 
72bb898558SAl Viro #define efi_call_phys0(f)			\
7343ab0476SBorislav Petkov 	efi_call0((f))
74bb898558SAl Viro #define efi_call_phys1(f, a1)			\
7543ab0476SBorislav Petkov 	efi_call1((f), (u64)(a1))
76bb898558SAl Viro #define efi_call_phys2(f, a1, a2)			\
7743ab0476SBorislav Petkov 	efi_call2((f), (u64)(a1), (u64)(a2))
78bb898558SAl Viro #define efi_call_phys3(f, a1, a2, a3)				\
7943ab0476SBorislav Petkov 	efi_call3((f), (u64)(a1), (u64)(a2), (u64)(a3))
80bb898558SAl Viro #define efi_call_phys4(f, a1, a2, a3, a4)				\
8143ab0476SBorislav Petkov 	efi_call4((f), (u64)(a1), (u64)(a2), (u64)(a3),		\
82bb898558SAl Viro 		  (u64)(a4))
83bb898558SAl Viro #define efi_call_phys5(f, a1, a2, a3, a4, a5)				\
8443ab0476SBorislav Petkov 	efi_call5((f), (u64)(a1), (u64)(a2), (u64)(a3),		\
85bb898558SAl Viro 		  (u64)(a4), (u64)(a5))
86bb898558SAl Viro #define efi_call_phys6(f, a1, a2, a3, a4, a5, a6)			\
8743ab0476SBorislav Petkov 	efi_call6((f), (u64)(a1), (u64)(a2), (u64)(a3),		\
88bb898558SAl Viro 		  (u64)(a4), (u64)(a5), (u64)(a6))
89bb898558SAl Viro 
90d2f7cbe7SBorislav Petkov #define _efi_call_virtX(x, f, ...)					\
91d2f7cbe7SBorislav Petkov ({									\
92d2f7cbe7SBorislav Petkov 	efi_status_t __s;						\
93d2f7cbe7SBorislav Petkov 									\
94d2f7cbe7SBorislav Petkov 	efi_sync_low_kernel_mappings();					\
95d2f7cbe7SBorislav Petkov 	preempt_disable();						\
96d2f7cbe7SBorislav Petkov 	__s = efi_call##x((void *)efi.systab->runtime->f, __VA_ARGS__);	\
97d2f7cbe7SBorislav Petkov 	preempt_enable();						\
98d2f7cbe7SBorislav Petkov 	__s;								\
99d2f7cbe7SBorislav Petkov })
100d2f7cbe7SBorislav Petkov 
101bb898558SAl Viro #define efi_call_virt0(f)				\
102d2f7cbe7SBorislav Petkov 	_efi_call_virtX(0, f)
103bb898558SAl Viro #define efi_call_virt1(f, a1)				\
104d2f7cbe7SBorislav Petkov 	_efi_call_virtX(1, f, (u64)(a1))
105bb898558SAl Viro #define efi_call_virt2(f, a1, a2)			\
106d2f7cbe7SBorislav Petkov 	_efi_call_virtX(2, f, (u64)(a1), (u64)(a2))
107bb898558SAl Viro #define efi_call_virt3(f, a1, a2, a3)			\
108d2f7cbe7SBorislav Petkov 	_efi_call_virtX(3, f, (u64)(a1), (u64)(a2), (u64)(a3))
109bb898558SAl Viro #define efi_call_virt4(f, a1, a2, a3, a4)		\
110d2f7cbe7SBorislav Petkov 	_efi_call_virtX(4, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4))
111bb898558SAl Viro #define efi_call_virt5(f, a1, a2, a3, a4, a5)		\
112d2f7cbe7SBorislav Petkov 	_efi_call_virtX(5, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4), (u64)(a5))
113bb898558SAl Viro #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6)	\
114d2f7cbe7SBorislav Petkov 	_efi_call_virtX(6, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6))
115bb898558SAl Viro 
116e1ad783bSKeith Packard extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
1173e8fa263SMatt Fleming 				 u32 type, u64 attribute);
118e1ad783bSKeith Packard 
119bb898558SAl Viro #endif /* CONFIG_X86_32 */
120bb898558SAl Viro 
121cbafbc82SJaswinder Singh Rajput extern int add_efi_memmap;
12283e68189SMatt Fleming extern unsigned long x86_efi_facility;
123d2f7cbe7SBorislav Petkov extern struct efi_scratch efi_scratch;
1249cd2b07cSMatthew Garrett extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
1251adbfa35SOlof Johansson extern int efi_memblock_x86_reserve_range(void);
126bb898558SAl Viro extern void efi_call_phys_prelog(void);
127bb898558SAl Viro extern void efi_call_phys_epilog(void);
1285189c2a7SOlof Johansson extern void efi_unmap_memmap(void);
1293e8fa263SMatt Fleming extern void efi_memory_uc(u64 addr, unsigned long size);
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);
133d2f7cbe7SBorislav Petkov extern void efi_setup_page_tables(void);
134d2f7cbe7SBorislav Petkov extern void __init old_map_region(efi_memory_desc_t *md);
135bb898558SAl Viro 
1361fec0533SDave Young struct efi_setup_data {
1371fec0533SDave Young 	u64 fw_vendor;
1381fec0533SDave Young 	u64 runtime;
1391fec0533SDave Young 	u64 tables;
1401fec0533SDave Young 	u64 smbios;
1411fec0533SDave Young 	u64 reserved[8];
1421fec0533SDave Young };
1431fec0533SDave Young 
1441fec0533SDave Young extern u64 efi_setup;
1451fec0533SDave Young 
1466b59e366SSatoru Takeuchi #ifdef CONFIG_EFI
1476b59e366SSatoru Takeuchi 
1486b59e366SSatoru Takeuchi static inline bool efi_is_native(void)
1496b59e366SSatoru Takeuchi {
1506b59e366SSatoru Takeuchi 	return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
1516b59e366SSatoru Takeuchi }
1526b59e366SSatoru Takeuchi 
15372548e83SMatt Fleming extern struct console early_efi_console;
154*5c12af0cSDave Young extern void parse_efi_setup(u64 phys_addr, u32 data_len);
1556b59e366SSatoru Takeuchi #else
156bb898558SAl Viro /*
157bb898558SAl Viro  * IF EFI is not configured, have the EFI calls return -ENOSYS.
158bb898558SAl Viro  */
159bb898558SAl Viro #define efi_call0(_f)					(-ENOSYS)
160bb898558SAl Viro #define efi_call1(_f, _a1)				(-ENOSYS)
161bb898558SAl Viro #define efi_call2(_f, _a1, _a2)				(-ENOSYS)
162bb898558SAl Viro #define efi_call3(_f, _a1, _a2, _a3)			(-ENOSYS)
163bb898558SAl Viro #define efi_call4(_f, _a1, _a2, _a3, _a4)		(-ENOSYS)
164bb898558SAl Viro #define efi_call5(_f, _a1, _a2, _a3, _a4, _a5)		(-ENOSYS)
165bb898558SAl Viro #define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6)	(-ENOSYS)
166*5c12af0cSDave Young static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
167bb898558SAl Viro #endif /* CONFIG_EFI */
168bb898558SAl Viro 
1691965aae3SH. Peter Anvin #endif /* _ASM_X86_EFI_H */
170