x86/efi: Save and restore FPU context around efi_calls (x86_64)
[linux-2.6-block.git] / arch / x86 / include / asm / efi.h
CommitLineData
1965aae3
PA
1#ifndef _ASM_X86_EFI_H
2#define _ASM_X86_EFI_H
5b83683f 3
de05764e 4#include <asm/i387.h>
d2f7cbe7
BP
5/*
6 * We map the EFI regions needed for runtime services non-contiguously,
7 * with preserved alignment on virtual addresses starting from -4G down
8 * for a total max space of 64G. This way, we provide for stable runtime
9 * services addresses across kernels so that a kexec'd kernel can still
10 * use them.
11 *
12 * This is the main reason why we're doing stable VA mappings for RT
13 * services.
14 *
15 * This flag is used in conjuction with a chicken bit called
16 * "efi=old_map" which can be used as a fallback to the old runtime
17 * services mapping method in case there's some b0rkage with a
18 * particular EFI implementation (haha, it is hard to hold up the
19 * sarcasm here...).
20 */
21#define EFI_OLD_MEMMAP EFI_ARCH_1
22
b8ff87a6
MF
23#define EFI32_LOADER_SIGNATURE "EL32"
24#define EFI64_LOADER_SIGNATURE "EL64"
25
5b83683f 26#ifdef CONFIG_X86_32
e429795c 27
f7d7d01b 28
e429795c
HY
29extern unsigned long asmlinkage efi_call_phys(void *, ...);
30
e429795c
HY
31/*
32 * Wrap all the virtual calls in a way that forces the parameters on the stack.
33 */
34
982e239c 35/* Use this macro if your virtual returns a non-void value */
e429795c 36#define efi_call_virt(f, args...) \
0c6f6abf 37 ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
e429795c 38
982e239c
RN
39/* Use this macro if your virtual call does not return any value */
40#define __efi_call_virt(f, args...) efi_call_virt(f, args)
41
3e8fa263 42#define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
e1ad783b 43
5b83683f
HY
44#else /* !CONFIG_X86_32 */
45
62fa6e69
MF
46#define EFI_LOADER_SIGNATURE "EL64"
47
48extern u64 asmlinkage efi_call(void *fp, ...);
49
50#define efi_call_phys(f, args...) efi_call((f), args)
51
52#define efi_call_virt(f, ...) \
d2f7cbe7
BP
53({ \
54 efi_status_t __s; \
55 \
56 efi_sync_low_kernel_mappings(); \
57 preempt_disable(); \
de05764e 58 __kernel_fpu_begin(); \
62fa6e69 59 __s = efi_call((void *)efi.systab->runtime->f, __VA_ARGS__); \
de05764e 60 __kernel_fpu_end(); \
d2f7cbe7
BP
61 preempt_enable(); \
62 __s; \
63})
64
982e239c
RN
65/*
66 * All X86_64 virt calls return non-void values. Thus, use non-void call for
67 * virt calls that would be void on X86_32.
68 */
69#define __efi_call_virt(f, args...) efi_call_virt(f, args)
70
e1ad783b 71extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
3e8fa263 72 u32 type, u64 attribute);
e1ad783b 73
5b83683f
HY
74#endif /* CONFIG_X86_32 */
75
cbafbc82 76extern int add_efi_memmap;
d2f7cbe7 77extern struct efi_scratch efi_scratch;
9cd2b07c 78extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
1adbfa35 79extern int efi_memblock_x86_reserve_range(void);
5b83683f
HY
80extern void efi_call_phys_prelog(void);
81extern void efi_call_phys_epilog(void);
5189c2a7 82extern void efi_unmap_memmap(void);
3e8fa263 83extern void efi_memory_uc(u64 addr, unsigned long size);
d2f7cbe7 84extern void __init efi_map_region(efi_memory_desc_t *md);
3b266496 85extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
d2f7cbe7 86extern void efi_sync_low_kernel_mappings(void);
b7b898ae
BP
87extern int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
88extern void efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
d2f7cbe7 89extern void __init old_map_region(efi_memory_desc_t *md);
c55d016f
BP
90extern void __init runtime_code_page_mkexec(void);
91extern void __init efi_runtime_mkexec(void);
11cc8512 92extern void __init efi_dump_pagetable(void);
a5d90c92 93extern void __init efi_apply_memmap_quirks(void);
5b83683f 94
1fec0533
DY
95struct efi_setup_data {
96 u64 fw_vendor;
97 u64 runtime;
98 u64 tables;
99 u64 smbios;
100 u64 reserved[8];
101};
102
103extern u64 efi_setup;
1fec0533 104
6b59e366
ST
105#ifdef CONFIG_EFI
106
107static inline bool efi_is_native(void)
108{
109 return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
110}
111
7d453eee
MF
112static inline bool efi_runtime_supported(void)
113{
114 if (efi_is_native())
115 return true;
116
117 if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP))
118 return true;
119
120 return false;
121}
122
72548e83 123extern struct console early_efi_console;
5c12af0c 124extern void parse_efi_setup(u64 phys_addr, u32 data_len);
4f9dbcfc
MF
125
126#ifdef CONFIG_EFI_MIXED
127extern void efi_thunk_runtime_setup(void);
128extern efi_status_t efi_thunk_set_virtual_address_map(
129 void *phys_set_virtual_address_map,
130 unsigned long memory_map_size,
131 unsigned long descriptor_size,
132 u32 descriptor_version,
133 efi_memory_desc_t *virtual_map);
134#else
135static inline void efi_thunk_runtime_setup(void) {}
136static inline efi_status_t efi_thunk_set_virtual_address_map(
137 void *phys_set_virtual_address_map,
138 unsigned long memory_map_size,
139 unsigned long descriptor_size,
140 u32 descriptor_version,
141 efi_memory_desc_t *virtual_map)
142{
143 return EFI_SUCCESS;
144}
145#endif /* CONFIG_EFI_MIXED */
6b59e366 146#else
7f594232
RA
147/*
148 * IF EFI is not configured, have the EFI calls return -ENOSYS.
149 */
150#define efi_call0(_f) (-ENOSYS)
151#define efi_call1(_f, _a1) (-ENOSYS)
152#define efi_call2(_f, _a1, _a2) (-ENOSYS)
153#define efi_call3(_f, _a1, _a2, _a3) (-ENOSYS)
154#define efi_call4(_f, _a1, _a2, _a3, _a4) (-ENOSYS)
155#define efi_call5(_f, _a1, _a2, _a3, _a4, _a5) (-ENOSYS)
156#define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6) (-ENOSYS)
5c12af0c 157static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
7f594232
RA
158#endif /* CONFIG_EFI */
159
1965aae3 160#endif /* _ASM_X86_EFI_H */