efi.h 5.9 KB
Newer Older
H
H. Peter Anvin 已提交
1 2
#ifndef _ASM_X86_EFI_H
#define _ASM_X86_EFI_H
H
Huang, Ying 已提交
3

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * We map the EFI regions needed for runtime services non-contiguously,
 * with preserved alignment on virtual addresses starting from -4G down
 * for a total max space of 64G. This way, we provide for stable runtime
 * services addresses across kernels so that a kexec'd kernel can still
 * use them.
 *
 * This is the main reason why we're doing stable VA mappings for RT
 * services.
 *
 * This flag is used in conjuction with a chicken bit called
 * "efi=old_map" which can be used as a fallback to the old runtime
 * services mapping method in case there's some b0rkage with a
 * particular EFI implementation (haha, it is hard to hold up the
 * sarcasm here...).
 */
#define EFI_OLD_MEMMAP		EFI_ARCH_1

H
Huang, Ying 已提交
22
#ifdef CONFIG_X86_32
23

24 25
#define EFI_LOADER_SIGNATURE	"EL32"

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
extern unsigned long asmlinkage efi_call_phys(void *, ...);

#define efi_call_phys0(f)		efi_call_phys(f)
#define efi_call_phys1(f, a1)		efi_call_phys(f, a1)
#define efi_call_phys2(f, a1, a2)	efi_call_phys(f, a1, a2)
#define efi_call_phys3(f, a1, a2, a3)	efi_call_phys(f, a1, a2, a3)
#define efi_call_phys4(f, a1, a2, a3, a4)	\
	efi_call_phys(f, a1, a2, a3, a4)
#define efi_call_phys5(f, a1, a2, a3, a4, a5)	\
	efi_call_phys(f, a1, a2, a3, a4, a5)
#define efi_call_phys6(f, a1, a2, a3, a4, a5, a6)	\
	efi_call_phys(f, a1, a2, a3, a4, a5, a6)
/*
 * Wrap all the virtual calls in a way that forces the parameters on the stack.
 */

#define efi_call_virt(f, args...) \
43
	((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
44 45 46 47 48 49 50 51 52 53 54 55

#define efi_call_virt0(f)		efi_call_virt(f)
#define efi_call_virt1(f, a1)		efi_call_virt(f, a1)
#define efi_call_virt2(f, a1, a2)	efi_call_virt(f, a1, a2)
#define efi_call_virt3(f, a1, a2, a3)	efi_call_virt(f, a1, a2, a3)
#define efi_call_virt4(f, a1, a2, a3, a4)	\
	efi_call_virt(f, a1, a2, a3, a4)
#define efi_call_virt5(f, a1, a2, a3, a4, a5)	\
	efi_call_virt(f, a1, a2, a3, a4, a5)
#define efi_call_virt6(f, a1, a2, a3, a4, a5, a6)	\
	efi_call_virt(f, a1, a2, a3, a4, a5, a6)

56
#define efi_ioremap(addr, size, type, attr)	ioremap_cache(addr, size)
57

H
Huang, Ying 已提交
58 59
#else /* !CONFIG_X86_32 */

60 61
#define EFI_LOADER_SIGNATURE	"EL64"

H
Huang, Ying 已提交
62 63 64 65 66 67 68 69 70 71 72
extern u64 efi_call0(void *fp);
extern u64 efi_call1(void *fp, u64 arg1);
extern u64 efi_call2(void *fp, u64 arg1, u64 arg2);
extern u64 efi_call3(void *fp, u64 arg1, u64 arg2, u64 arg3);
extern u64 efi_call4(void *fp, u64 arg1, u64 arg2, u64 arg3, u64 arg4);
extern u64 efi_call5(void *fp, u64 arg1, u64 arg2, u64 arg3,
		     u64 arg4, u64 arg5);
extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,
		     u64 arg4, u64 arg5, u64 arg6);

#define efi_call_phys0(f)			\
73
	efi_call0((f))
H
Huang, Ying 已提交
74
#define efi_call_phys1(f, a1)			\
75
	efi_call1((f), (u64)(a1))
H
Huang, Ying 已提交
76
#define efi_call_phys2(f, a1, a2)			\
77
	efi_call2((f), (u64)(a1), (u64)(a2))
H
Huang, Ying 已提交
78
#define efi_call_phys3(f, a1, a2, a3)				\
79
	efi_call3((f), (u64)(a1), (u64)(a2), (u64)(a3))
H
Huang, Ying 已提交
80
#define efi_call_phys4(f, a1, a2, a3, a4)				\
81
	efi_call4((f), (u64)(a1), (u64)(a2), (u64)(a3),		\
H
Huang, Ying 已提交
82 83
		  (u64)(a4))
#define efi_call_phys5(f, a1, a2, a3, a4, a5)				\
84
	efi_call5((f), (u64)(a1), (u64)(a2), (u64)(a3),		\
H
Huang, Ying 已提交
85 86
		  (u64)(a4), (u64)(a5))
#define efi_call_phys6(f, a1, a2, a3, a4, a5, a6)			\
87
	efi_call6((f), (u64)(a1), (u64)(a2), (u64)(a3),		\
H
Huang, Ying 已提交
88 89
		  (u64)(a4), (u64)(a5), (u64)(a6))

90 91 92 93 94 95 96 97 98 99 100
#define _efi_call_virtX(x, f, ...)					\
({									\
	efi_status_t __s;						\
									\
	efi_sync_low_kernel_mappings();					\
	preempt_disable();						\
	__s = efi_call##x((void *)efi.systab->runtime->f, __VA_ARGS__);	\
	preempt_enable();						\
	__s;								\
})

H
Huang, Ying 已提交
101
#define efi_call_virt0(f)				\
102 103 104 105 106 107 108 109 110 111 112 113 114
	_efi_call_virtX(0, f)
#define efi_call_virt1(f, a1)				\
	_efi_call_virtX(1, f, (u64)(a1))
#define efi_call_virt2(f, a1, a2)			\
	_efi_call_virtX(2, f, (u64)(a1), (u64)(a2))
#define efi_call_virt3(f, a1, a2, a3)			\
	_efi_call_virtX(3, f, (u64)(a1), (u64)(a2), (u64)(a3))
#define efi_call_virt4(f, a1, a2, a3, a4)		\
	_efi_call_virtX(4, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4))
#define efi_call_virt5(f, a1, a2, a3, a4, a5)		\
	_efi_call_virtX(5, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4), (u64)(a5))
#define efi_call_virt6(f, a1, a2, a3, a4, a5, a6)	\
	_efi_call_virtX(6, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6))
H
Huang, Ying 已提交
115

116
extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
117
				 u32 type, u64 attribute);
118

H
Huang, Ying 已提交
119 120
#endif /* CONFIG_X86_32 */

121
extern int add_efi_memmap;
122
extern unsigned long x86_efi_facility;
123
extern struct efi_scratch efi_scratch;
124
extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
125
extern int efi_memblock_x86_reserve_range(void);
H
Huang, Ying 已提交
126 127
extern void efi_call_phys_prelog(void);
extern void efi_call_phys_epilog(void);
128
extern void efi_unmap_memmap(void);
129
extern void efi_memory_uc(u64 addr, unsigned long size);
130
extern void __init efi_map_region(efi_memory_desc_t *md);
131
extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
132 133 134
extern void efi_sync_low_kernel_mappings(void);
extern void efi_setup_page_tables(void);
extern void __init old_map_region(efi_memory_desc_t *md);
B
Borislav Petkov 已提交
135 136
extern void __init runtime_code_page_mkexec(void);
extern void __init efi_runtime_mkexec(void);
H
Huang, Ying 已提交
137

138 139 140 141 142 143 144 145 146 147
struct efi_setup_data {
	u64 fw_vendor;
	u64 runtime;
	u64 tables;
	u64 smbios;
	u64 reserved[8];
};

extern u64 efi_setup;

148 149 150 151 152 153 154
#ifdef CONFIG_EFI

static inline bool efi_is_native(void)
{
	return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
}

155
extern struct console early_efi_console;
156
extern void parse_efi_setup(u64 phys_addr, u32 data_len);
157
#else
158 159 160 161 162 163 164 165 166 167
/*
 * IF EFI is not configured, have the EFI calls return -ENOSYS.
 */
#define efi_call0(_f)					(-ENOSYS)
#define efi_call1(_f, _a1)				(-ENOSYS)
#define efi_call2(_f, _a1, _a2)				(-ENOSYS)
#define efi_call3(_f, _a1, _a2, _a3)			(-ENOSYS)
#define efi_call4(_f, _a1, _a2, _a3, _a4)		(-ENOSYS)
#define efi_call5(_f, _a1, _a2, _a3, _a4, _a5)		(-ENOSYS)
#define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6)	(-ENOSYS)
168
static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
169 170
#endif /* CONFIG_EFI */

H
H. Peter Anvin 已提交
171
#endif /* _ASM_X86_EFI_H */