blob: 3b978c472d08b51aa8ff33d7fab589a3205fc87a [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
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +01004/*
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
9 * use them.
10 *
11 * This is the main reason why we're doing stable VA mappings for RT
12 * services.
13 *
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
18 * sarcasm here...).
19 */
20#define EFI_OLD_MEMMAP EFI_ARCH_1
21
Huang, Ying5b836832008-01-30 13:31:19 +010022#ifdef CONFIG_X86_32
Huang, Yinge4297952008-01-30 13:31:19 +010023
Matt Flemingf7d7d012011-11-15 12:56:14 +000024#define EFI_LOADER_SIGNATURE "EL32"
25
Huang, Yinge4297952008-01-30 13:31:19 +010026extern unsigned long asmlinkage efi_call_phys(void *, ...);
27
28#define efi_call_phys0(f) efi_call_phys(f)
29#define efi_call_phys1(f, a1) efi_call_phys(f, a1)
30#define efi_call_phys2(f, a1, a2) efi_call_phys(f, a1, a2)
31#define efi_call_phys3(f, a1, a2, a3) efi_call_phys(f, a1, a2, a3)
32#define efi_call_phys4(f, a1, a2, a3, a4) \
33 efi_call_phys(f, a1, a2, a3, a4)
34#define efi_call_phys5(f, a1, a2, a3, a4, a5) \
35 efi_call_phys(f, a1, a2, a3, a4, a5)
36#define efi_call_phys6(f, a1, a2, a3, a4, a5, a6) \
37 efi_call_phys(f, a1, a2, a3, a4, a5, a6)
38/*
39 * Wrap all the virtual calls in a way that forces the parameters on the stack.
40 */
41
42#define efi_call_virt(f, args...) \
Joe Perches0c6f6ab2008-03-23 01:02:07 -070043 ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
Huang, Yinge4297952008-01-30 13:31:19 +010044
45#define efi_call_virt0(f) efi_call_virt(f)
46#define efi_call_virt1(f, a1) efi_call_virt(f, a1)
47#define efi_call_virt2(f, a1, a2) efi_call_virt(f, a1, a2)
48#define efi_call_virt3(f, a1, a2, a3) efi_call_virt(f, a1, a2, a3)
49#define efi_call_virt4(f, a1, a2, a3, a4) \
50 efi_call_virt(f, a1, a2, a3, a4)
51#define efi_call_virt5(f, a1, a2, a3, a4, a5) \
52 efi_call_virt(f, a1, a2, a3, a4, a5)
53#define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \
54 efi_call_virt(f, a1, a2, a3, a4, a5, a6)
Huang, Yinge4297952008-01-30 13:31:19 +010055
Matt Fleming3e8fa262012-10-19 13:25:46 +010056#define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
Keith Packarde1ad7832011-12-11 16:12:42 -080057
Huang, Ying5b836832008-01-30 13:31:19 +010058#else /* !CONFIG_X86_32 */
59
Matt Flemingf7d7d012011-11-15 12:56:14 +000060#define EFI_LOADER_SIGNATURE "EL64"
61
Huang, Ying5b836832008-01-30 13:31:19 +010062extern u64 efi_call0(void *fp);
63extern u64 efi_call1(void *fp, u64 arg1);
64extern u64 efi_call2(void *fp, u64 arg1, u64 arg2);
65extern u64 efi_call3(void *fp, u64 arg1, u64 arg2, u64 arg3);
66extern u64 efi_call4(void *fp, u64 arg1, u64 arg2, u64 arg3, u64 arg4);
67extern u64 efi_call5(void *fp, u64 arg1, u64 arg2, u64 arg3,
68 u64 arg4, u64 arg5);
69extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,
70 u64 arg4, u64 arg5, u64 arg6);
71
72#define efi_call_phys0(f) \
Borislav Petkov43ab0472013-06-02 14:56:07 +020073 efi_call0((f))
Huang, Ying5b836832008-01-30 13:31:19 +010074#define efi_call_phys1(f, a1) \
Borislav Petkov43ab0472013-06-02 14:56:07 +020075 efi_call1((f), (u64)(a1))
Huang, Ying5b836832008-01-30 13:31:19 +010076#define efi_call_phys2(f, a1, a2) \
Borislav Petkov43ab0472013-06-02 14:56:07 +020077 efi_call2((f), (u64)(a1), (u64)(a2))
Huang, Ying5b836832008-01-30 13:31:19 +010078#define efi_call_phys3(f, a1, a2, a3) \
Borislav Petkov43ab0472013-06-02 14:56:07 +020079 efi_call3((f), (u64)(a1), (u64)(a2), (u64)(a3))
Huang, Ying5b836832008-01-30 13:31:19 +010080#define efi_call_phys4(f, a1, a2, a3, a4) \
Borislav Petkov43ab0472013-06-02 14:56:07 +020081 efi_call4((f), (u64)(a1), (u64)(a2), (u64)(a3), \
Huang, Ying5b836832008-01-30 13:31:19 +010082 (u64)(a4))
83#define efi_call_phys5(f, a1, a2, a3, a4, a5) \
Borislav Petkov43ab0472013-06-02 14:56:07 +020084 efi_call5((f), (u64)(a1), (u64)(a2), (u64)(a3), \
Huang, Ying5b836832008-01-30 13:31:19 +010085 (u64)(a4), (u64)(a5))
86#define efi_call_phys6(f, a1, a2, a3, a4, a5, a6) \
Borislav Petkov43ab0472013-06-02 14:56:07 +020087 efi_call6((f), (u64)(a1), (u64)(a2), (u64)(a3), \
Huang, Ying5b836832008-01-30 13:31:19 +010088 (u64)(a4), (u64)(a5), (u64)(a6))
89
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010090#define _efi_call_virtX(x, f, ...) \
91({ \
92 efi_status_t __s; \
93 \
94 efi_sync_low_kernel_mappings(); \
95 preempt_disable(); \
96 __s = efi_call##x((void *)efi.systab->runtime->f, __VA_ARGS__); \
97 preempt_enable(); \
98 __s; \
99})
100
Huang, Ying5b836832008-01-30 13:31:19 +0100101#define efi_call_virt0(f) \
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100102 _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))
Huang, Ying5b836832008-01-30 13:31:19 +0100115
Keith Packarde1ad7832011-12-11 16:12:42 -0800116extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
Matt Fleming3e8fa262012-10-19 13:25:46 +0100117 u32 type, u64 attribute);
Keith Packarde1ad7832011-12-11 16:12:42 -0800118
Huang, Ying5b836832008-01-30 13:31:19 +0100119#endif /* CONFIG_X86_32 */
120
Jaswinder Singh Rajputcbafbc82008-12-29 20:36:40 +0530121extern int add_efi_memmap;
Matt Fleming83e68182012-11-14 09:42:35 +0000122extern unsigned long x86_efi_facility;
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100123extern struct efi_scratch efi_scratch;
Matthew Garrett9cd2b072011-05-05 15:19:43 -0400124extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
Olof Johansson1adbfa32012-02-12 13:24:29 -0800125extern int efi_memblock_x86_reserve_range(void);
Huang, Ying5b836832008-01-30 13:31:19 +0100126extern void efi_call_phys_prelog(void);
127extern void efi_call_phys_epilog(void);
Olof Johansson5189c2a2012-10-24 10:00:44 -0700128extern void efi_unmap_memmap(void);
Matt Fleming3e8fa262012-10-19 13:25:46 +0100129extern void efi_memory_uc(u64 addr, unsigned long size);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100130extern void __init efi_map_region(efi_memory_desc_t *md);
Dave Young3b266492013-12-20 18:02:14 +0800131extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100132extern void efi_sync_low_kernel_mappings(void);
133extern void efi_setup_page_tables(void);
134extern void __init old_map_region(efi_memory_desc_t *md);
Huang, Ying5b836832008-01-30 13:31:19 +0100135
Dave Young1fec0532013-12-20 18:02:19 +0800136struct efi_setup_data {
137 u64 fw_vendor;
138 u64 runtime;
139 u64 tables;
140 u64 smbios;
141 u64 reserved[8];
142};
143
144extern u64 efi_setup;
Dave Young1fec0532013-12-20 18:02:19 +0800145
Satoru Takeuchi6b59e362013-02-14 09:07:35 +0900146#ifdef CONFIG_EFI
147
148static inline bool efi_is_native(void)
149{
150 return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
151}
152
Matt Fleming72548e82013-10-04 09:36:56 +0100153extern struct console early_efi_console;
Dave Young5c12af02014-01-03 11:56:49 +0800154extern void parse_efi_setup(u64 phys_addr, u32 data_len);
Satoru Takeuchi6b59e362013-02-14 09:07:35 +0900155#else
Russ Anderson7f594232008-10-03 11:59:15 -0500156/*
157 * IF EFI is not configured, have the EFI calls return -ENOSYS.
158 */
159#define efi_call0(_f) (-ENOSYS)
160#define efi_call1(_f, _a1) (-ENOSYS)
161#define efi_call2(_f, _a1, _a2) (-ENOSYS)
162#define efi_call3(_f, _a1, _a2, _a3) (-ENOSYS)
163#define efi_call4(_f, _a1, _a2, _a3, _a4) (-ENOSYS)
164#define efi_call5(_f, _a1, _a2, _a3, _a4, _a5) (-ENOSYS)
165#define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6) (-ENOSYS)
Dave Young5c12af02014-01-03 11:56:49 +0800166static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
Russ Anderson7f594232008-10-03 11:59:15 -0500167#endif /* CONFIG_EFI */
168
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700169#endif /* _ASM_X86_EFI_H */