blob: 8fd9e637629a0ab22d49eb0ef51ef4feb9aa3987 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_EFI_H
2#define _ASM_X86_EFI_H
Huang, Ying5b836832008-01-30 13:31:19 +01003
Ingo Molnardf6b35f2015-04-24 02:46:00 +02004#include <asm/fpu/api.h>
Ingo Molnar744937b2015-03-03 07:48:50 +01005#include <asm/pgtable.h>
Matt Flemingc9f2a9a2015-11-27 21:09:33 +00006#include <asm/tlb.h>
Ingo Molnar744937b2015-03-03 07:48:50 +01007
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +01008/*
9 * We map the EFI regions needed for runtime services non-contiguously,
10 * with preserved alignment on virtual addresses starting from -4G down
11 * for a total max space of 64G. This way, we provide for stable runtime
12 * services addresses across kernels so that a kexec'd kernel can still
13 * use them.
14 *
15 * This is the main reason why we're doing stable VA mappings for RT
16 * services.
17 *
18 * This flag is used in conjuction with a chicken bit called
19 * "efi=old_map" which can be used as a fallback to the old runtime
20 * services mapping method in case there's some b0rkage with a
21 * particular EFI implementation (haha, it is hard to hold up the
22 * sarcasm here...).
23 */
24#define EFI_OLD_MEMMAP EFI_ARCH_1
25
Matt Flemingb8ff87a2014-01-10 15:54:31 +000026#define EFI32_LOADER_SIGNATURE "EL32"
27#define EFI64_LOADER_SIGNATURE "EL64"
28
Huang, Ying5b836832008-01-30 13:31:19 +010029#ifdef CONFIG_X86_32
Huang, Yinge4297952008-01-30 13:31:19 +010030
Matt Flemingf7d7d012011-11-15 12:56:14 +000031
Huang, Yinge4297952008-01-30 13:31:19 +010032extern unsigned long asmlinkage efi_call_phys(void *, ...);
33
Huang, Yinge4297952008-01-30 13:31:19 +010034/*
35 * Wrap all the virtual calls in a way that forces the parameters on the stack.
36 */
37
Ricardo Neri982e2392014-03-27 15:10:41 -070038/* Use this macro if your virtual returns a non-void value */
Huang, Yinge4297952008-01-30 13:31:19 +010039#define efi_call_virt(f, args...) \
Ricardo Nerib738c6e2014-03-27 15:10:43 -070040({ \
41 efi_status_t __s; \
42 kernel_fpu_begin(); \
43 __s = ((efi_##f##_t __attribute__((regparm(0)))*) \
44 efi.systab->runtime->f)(args); \
45 kernel_fpu_end(); \
46 __s; \
47})
Huang, Yinge4297952008-01-30 13:31:19 +010048
Ricardo Neri982e2392014-03-27 15:10:41 -070049/* Use this macro if your virtual call does not return any value */
Ricardo Nerib738c6e2014-03-27 15:10:43 -070050#define __efi_call_virt(f, args...) \
51({ \
52 kernel_fpu_begin(); \
53 ((efi_##f##_t __attribute__((regparm(0)))*) \
54 efi.systab->runtime->f)(args); \
55 kernel_fpu_end(); \
56})
Ricardo Neri982e2392014-03-27 15:10:41 -070057
Matt Fleming3e8fa262012-10-19 13:25:46 +010058#define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
Keith Packarde1ad7832011-12-11 16:12:42 -080059
Huang, Ying5b836832008-01-30 13:31:19 +010060#else /* !CONFIG_X86_32 */
61
Matt Fleming62fa6e62014-03-27 15:10:39 -070062#define EFI_LOADER_SIGNATURE "EL64"
Huang, Ying5b836832008-01-30 13:31:19 +010063
Matt Fleming62fa6e62014-03-27 15:10:39 -070064extern u64 asmlinkage efi_call(void *fp, ...);
Huang, Ying5b836832008-01-30 13:31:19 +010065
Matt Fleming62fa6e62014-03-27 15:10:39 -070066#define efi_call_phys(f, args...) efi_call((f), args)
67
Matt Flemingc9f2a9a2015-11-27 21:09:33 +000068/*
69 * Scratch space used for switching the pagetable in the EFI stub
70 */
71struct efi_scratch {
72 u64 r15;
73 u64 prev_cr3;
74 pgd_t *efi_pgt;
75 bool use_pgd;
76 u64 phys_stack;
77} __packed;
78
Matt Fleming62fa6e62014-03-27 15:10:39 -070079#define efi_call_virt(f, ...) \
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010080({ \
81 efi_status_t __s; \
82 \
83 efi_sync_low_kernel_mappings(); \
84 preempt_disable(); \
Ricardo Neride057642014-03-27 15:10:42 -070085 __kernel_fpu_begin(); \
Matt Flemingc9f2a9a2015-11-27 21:09:33 +000086 \
87 if (efi_scratch.use_pgd) { \
88 efi_scratch.prev_cr3 = read_cr3(); \
89 write_cr3((unsigned long)efi_scratch.efi_pgt); \
90 __flush_tlb_all(); \
91 } \
92 \
Matt Fleming62fa6e62014-03-27 15:10:39 -070093 __s = efi_call((void *)efi.systab->runtime->f, __VA_ARGS__); \
Matt Flemingc9f2a9a2015-11-27 21:09:33 +000094 \
95 if (efi_scratch.use_pgd) { \
96 write_cr3(efi_scratch.prev_cr3); \
97 __flush_tlb_all(); \
98 } \
99 \
Ricardo Neride057642014-03-27 15:10:42 -0700100 __kernel_fpu_end(); \
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100101 preempt_enable(); \
102 __s; \
103})
104
Ricardo Neri982e2392014-03-27 15:10:41 -0700105/*
106 * All X86_64 virt calls return non-void values. Thus, use non-void call for
107 * virt calls that would be void on X86_32.
108 */
109#define __efi_call_virt(f, args...) efi_call_virt(f, args)
110
Mathias Krause4e78eb052014-09-07 19:42:17 +0200111extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,
112 u32 type, u64 attribute);
Keith Packarde1ad7832011-12-11 16:12:42 -0800113
Andrey Ryabinina5238412015-10-01 15:36:48 -0700114#ifdef CONFIG_KASAN
Andrey Ryabinin769a8082015-09-22 14:59:17 -0700115/*
116 * CONFIG_KASAN may redefine memset to __memset. __memset function is present
117 * only in kernel binary. Since the EFI stub linked into a separate binary it
118 * doesn't have __memset(). So we should use standard memset from
119 * arch/x86/boot/compressed/string.c. The same applies to memcpy and memmove.
120 */
121#undef memcpy
122#undef memset
123#undef memmove
Andrey Ryabinina5238412015-10-01 15:36:48 -0700124#endif
Andrey Ryabinin769a8082015-09-22 14:59:17 -0700125
Huang, Ying5b836832008-01-30 13:31:19 +0100126#endif /* CONFIG_X86_32 */
127
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100128extern struct efi_scratch efi_scratch;
Mathias Krause4e78eb052014-09-07 19:42:17 +0200129extern void __init efi_set_executable(efi_memory_desc_t *md, bool executable);
130extern int __init efi_memblock_x86_reserve_range(void);
Ingo Molnar744937b2015-03-03 07:48:50 +0100131extern pgd_t * __init efi_call_phys_prolog(void);
132extern void __init efi_call_phys_epilog(pgd_t *save_pgd);
Taku Izumi0bbea1c2015-09-30 19:20:00 +0900133extern void __init efi_print_memmap(void);
Mathias Krause4e78eb052014-09-07 19:42:17 +0200134extern void __init efi_unmap_memmap(void);
135extern void __init efi_memory_uc(u64 addr, unsigned long size);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100136extern void __init efi_map_region(efi_memory_desc_t *md);
Dave Young3b266492013-12-20 18:02:14 +0800137extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100138extern void efi_sync_low_kernel_mappings(void);
Matt Fleming67a91082015-11-27 21:09:34 +0000139extern int __init efi_alloc_page_tables(void);
Mathias Krause4e78eb052014-09-07 19:42:17 +0200140extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
141extern void __init efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100142extern void __init old_map_region(efi_memory_desc_t *md);
Borislav Petkovc55d0162014-02-14 08:24:24 +0100143extern void __init runtime_code_page_mkexec(void);
144extern void __init efi_runtime_mkexec(void);
Borislav Petkov11cc8512014-01-18 12:48:15 +0100145extern void __init efi_dump_pagetable(void);
Borislav Petkova5d90c92014-03-04 17:02:17 +0100146extern void __init efi_apply_memmap_quirks(void);
Saurabh Tangrieeb9db02014-06-02 05:18:35 -0700147extern int __init efi_reuse_config(u64 tables, int nr_tables);
148extern void efi_delete_dummy_variable(void);
Huang, Ying5b836832008-01-30 13:31:19 +0100149
Dave Young1fec0532013-12-20 18:02:19 +0800150struct efi_setup_data {
151 u64 fw_vendor;
152 u64 runtime;
153 u64 tables;
154 u64 smbios;
155 u64 reserved[8];
156};
157
158extern u64 efi_setup;
Dave Young1fec0532013-12-20 18:02:19 +0800159
Satoru Takeuchi6b59e362013-02-14 09:07:35 +0900160#ifdef CONFIG_EFI
161
162static inline bool efi_is_native(void)
163{
164 return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
165}
166
Matt Fleming7d453ee2014-01-10 18:52:06 +0000167static inline bool efi_runtime_supported(void)
168{
169 if (efi_is_native())
170 return true;
171
172 if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP))
173 return true;
174
175 return false;
176}
177
Matt Fleming72548e82013-10-04 09:36:56 +0100178extern struct console early_efi_console;
Dave Young5c12af02014-01-03 11:56:49 +0800179extern void parse_efi_setup(u64 phys_addr, u32 data_len);
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000180
181#ifdef CONFIG_EFI_MIXED
182extern void efi_thunk_runtime_setup(void);
183extern efi_status_t efi_thunk_set_virtual_address_map(
184 void *phys_set_virtual_address_map,
185 unsigned long memory_map_size,
186 unsigned long descriptor_size,
187 u32 descriptor_version,
188 efi_memory_desc_t *virtual_map);
189#else
190static inline void efi_thunk_runtime_setup(void) {}
191static inline efi_status_t efi_thunk_set_virtual_address_map(
192 void *phys_set_virtual_address_map,
193 unsigned long memory_map_size,
194 unsigned long descriptor_size,
195 u32 descriptor_version,
196 efi_memory_desc_t *virtual_map)
197{
198 return EFI_SUCCESS;
199}
200#endif /* CONFIG_EFI_MIXED */
Ard Biesheuvelf23cf8b2014-07-02 14:54:40 +0200201
Ard Biesheuvel243b6752014-11-05 17:00:56 +0100202
203/* arch specific definitions used by the stub code */
204
205struct efi_config {
206 u64 image_handle;
207 u64 table;
208 u64 allocate_pool;
209 u64 allocate_pages;
210 u64 get_memory_map;
211 u64 free_pool;
212 u64 free_pages;
213 u64 locate_handle;
214 u64 handle_protocol;
215 u64 exit_boot_services;
216 u64 text_output;
217 efi_status_t (*call)(unsigned long, ...);
218 bool is64;
219} __packed;
220
221__pure const struct efi_config *__efi_early(void);
222
223#define efi_call_early(f, ...) \
224 __efi_early()->call(__efi_early()->f, __VA_ARGS__);
225
Matt Fleming44be28e2014-06-13 12:39:55 +0100226extern bool efi_reboot_required(void);
227
Satoru Takeuchi6b59e362013-02-14 09:07:35 +0900228#else
Dave Young5c12af02014-01-03 11:56:49 +0800229static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
Matt Fleming44be28e2014-06-13 12:39:55 +0100230static inline bool efi_reboot_required(void)
231{
232 return false;
233}
Russ Anderson7f594232008-10-03 11:59:15 -0500234#endif /* CONFIG_EFI */
235
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700236#endif /* _ASM_X86_EFI_H */