5 * We map the EFI regions needed for runtime services non-contiguously,
6 * with preserved alignment on virtual addresses starting from -4G down
7 * for a total max space of 64G. This way, we provide for stable runtime
8 * services addresses across kernels so that a kexec'd kernel can still
11 * This is the main reason why we're doing stable VA mappings for RT
14 * This flag is used in conjuction with a chicken bit called
15 * "efi=old_map" which can be used as a fallback to the old runtime
16 * services mapping method in case there's some b0rkage with a
17 * particular EFI implementation (haha, it is hard to hold up the
20 #define EFI_OLD_MEMMAP EFI_ARCH_1
22 #define EFI32_LOADER_SIGNATURE "EL32"
23 #define EFI64_LOADER_SIGNATURE "EL64"
28 extern unsigned long asmlinkage efi_call_phys(void *, ...);
30 #define efi_call_phys0(f) efi_call_phys(f)
31 #define efi_call_phys1(f, a1) efi_call_phys(f, a1)
32 #define efi_call_phys2(f, a1, a2) efi_call_phys(f, a1, a2)
33 #define efi_call_phys3(f, a1, a2, a3) efi_call_phys(f, a1, a2, a3)
34 #define efi_call_phys4(f, a1, a2, a3, a4) \
35 efi_call_phys(f, a1, a2, a3, a4)
36 #define efi_call_phys5(f, a1, a2, a3, a4, a5) \
37 efi_call_phys(f, a1, a2, a3, a4, a5)
38 #define efi_call_phys6(f, a1, a2, a3, a4, a5, a6) \
39 efi_call_phys(f, a1, a2, a3, a4, a5, a6)
41 * Wrap all the virtual calls in a way that forces the parameters on the stack.
44 #define efi_call_virt(f, args...) \
45 ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
47 #define efi_call_virt0(f) efi_call_virt(f)
48 #define efi_call_virt1(f, a1) efi_call_virt(f, a1)
49 #define efi_call_virt2(f, a1, a2) efi_call_virt(f, a1, a2)
50 #define efi_call_virt3(f, a1, a2, a3) efi_call_virt(f, a1, a2, a3)
51 #define efi_call_virt4(f, a1, a2, a3, a4) \
52 efi_call_virt(f, a1, a2, a3, a4)
53 #define efi_call_virt5(f, a1, a2, a3, a4, a5) \
54 efi_call_virt(f, a1, a2, a3, a4, a5)
55 #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \
56 efi_call_virt(f, a1, a2, a3, a4, a5, a6)
58 #define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
60 #else /* !CONFIG_X86_32 */
62 extern u64 efi_call0(void *fp);
63 extern u64 efi_call1(void *fp, u64 arg1);
64 extern u64 efi_call2(void *fp, u64 arg1, u64 arg2);
65 extern u64 efi_call3(void *fp, u64 arg1, u64 arg2, u64 arg3);
66 extern u64 efi_call4(void *fp, u64 arg1, u64 arg2, u64 arg3, u64 arg4);
67 extern u64 efi_call5(void *fp, u64 arg1, u64 arg2, u64 arg3,
69 extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,
70 u64 arg4, u64 arg5, u64 arg6);
72 #define efi_call_phys0(f) \
74 #define efi_call_phys1(f, a1) \
75 efi_call1((f), (u64)(a1))
76 #define efi_call_phys2(f, a1, a2) \
77 efi_call2((f), (u64)(a1), (u64)(a2))
78 #define efi_call_phys3(f, a1, a2, a3) \
79 efi_call3((f), (u64)(a1), (u64)(a2), (u64)(a3))
80 #define efi_call_phys4(f, a1, a2, a3, a4) \
81 efi_call4((f), (u64)(a1), (u64)(a2), (u64)(a3), \
83 #define efi_call_phys5(f, a1, a2, a3, a4, a5) \
84 efi_call5((f), (u64)(a1), (u64)(a2), (u64)(a3), \
86 #define efi_call_phys6(f, a1, a2, a3, a4, a5, a6) \
87 efi_call6((f), (u64)(a1), (u64)(a2), (u64)(a3), \
88 (u64)(a4), (u64)(a5), (u64)(a6))
90 #define _efi_call_virtX(x, f, ...) \
94 efi_sync_low_kernel_mappings(); \
96 __s = efi_call##x((void *)efi.systab->runtime->f, __VA_ARGS__); \
101 #define efi_call_virt0(f) \
102 _efi_call_virtX(0, f)
103 #define efi_call_virt1(f, a1) \
104 _efi_call_virtX(1, f, (u64)(a1))
105 #define efi_call_virt2(f, a1, a2) \
106 _efi_call_virtX(2, f, (u64)(a1), (u64)(a2))
107 #define efi_call_virt3(f, a1, a2, a3) \
108 _efi_call_virtX(3, f, (u64)(a1), (u64)(a2), (u64)(a3))
109 #define efi_call_virt4(f, a1, a2, a3, a4) \
110 _efi_call_virtX(4, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4))
111 #define efi_call_virt5(f, a1, a2, a3, a4, a5) \
112 _efi_call_virtX(5, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4), (u64)(a5))
113 #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \
114 _efi_call_virtX(6, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6))
116 extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
117 u32 type, u64 attribute);
119 #endif /* CONFIG_X86_32 */
121 extern int add_efi_memmap;
122 extern struct efi_scratch efi_scratch;
123 extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
124 extern int efi_memblock_x86_reserve_range(void);
125 extern void efi_call_phys_prelog(void);
126 extern void efi_call_phys_epilog(void);
127 extern void efi_unmap_memmap(void);
128 extern void efi_memory_uc(u64 addr, unsigned long size);
129 extern void __init efi_map_region(efi_memory_desc_t *md);
130 extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
131 extern void efi_sync_low_kernel_mappings(void);
132 extern int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
133 extern void efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
134 extern void __init old_map_region(efi_memory_desc_t *md);
135 extern void __init runtime_code_page_mkexec(void);
136 extern void __init efi_runtime_mkexec(void);
137 extern void __init efi_dump_pagetable(void);
138 extern void __init efi_apply_memmap_quirks(void);
140 struct efi_setup_data {
148 extern u64 efi_setup;
152 static inline bool efi_is_native(void)
154 return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
157 static inline bool efi_runtime_supported(void)
162 if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP))
168 extern struct console early_efi_console;
169 extern void parse_efi_setup(u64 phys_addr, u32 data_len);
171 #ifdef CONFIG_EFI_MIXED
172 extern void efi_thunk_runtime_setup(void);
173 extern efi_status_t efi_thunk_set_virtual_address_map(
174 void *phys_set_virtual_address_map,
175 unsigned long memory_map_size,
176 unsigned long descriptor_size,
177 u32 descriptor_version,
178 efi_memory_desc_t *virtual_map);
180 static inline void efi_thunk_runtime_setup(void) {}
181 static inline efi_status_t efi_thunk_set_virtual_address_map(
182 void *phys_set_virtual_address_map,
183 unsigned long memory_map_size,
184 unsigned long descriptor_size,
185 u32 descriptor_version,
186 efi_memory_desc_t *virtual_map)
190 #endif /* CONFIG_EFI_MIXED */
193 * IF EFI is not configured, have the EFI calls return -ENOSYS.
195 #define efi_call0(_f) (-ENOSYS)
196 #define efi_call1(_f, _a1) (-ENOSYS)
197 #define efi_call2(_f, _a1, _a2) (-ENOSYS)
198 #define efi_call3(_f, _a1, _a2, _a3) (-ENOSYS)
199 #define efi_call4(_f, _a1, _a2, _a3, _a4) (-ENOSYS)
200 #define efi_call5(_f, _a1, _a2, _a3, _a4, _a5) (-ENOSYS)
201 #define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6) (-ENOSYS)
202 static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
203 #endif /* CONFIG_EFI */
205 #endif /* _ASM_X86_EFI_H */