blob: e3975597b28994383b92a1c92c8c11463b4d3d57 [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
Matt Flemingb8ff87a2014-01-10 15:54:31 +000022#define EFI32_LOADER_SIGNATURE "EL32"
23#define EFI64_LOADER_SIGNATURE "EL64"
24
Huang, Ying5b836832008-01-30 13:31:19 +010025#ifdef CONFIG_X86_32
Huang, Yinge4297952008-01-30 13:31:19 +010026
Matt Flemingf7d7d012011-11-15 12:56:14 +000027
Huang, Yinge4297952008-01-30 13:31:19 +010028extern unsigned long asmlinkage efi_call_phys(void *, ...);
29
Huang, Yinge4297952008-01-30 13:31:19 +010030/*
31 * Wrap all the virtual calls in a way that forces the parameters on the stack.
32 */
33
34#define efi_call_virt(f, args...) \
Joe Perches0c6f6ab2008-03-23 01:02:07 -070035 ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
Huang, Yinge4297952008-01-30 13:31:19 +010036
Matt Fleming3e8fa262012-10-19 13:25:46 +010037#define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
Keith Packarde1ad7832011-12-11 16:12:42 -080038
Huang, Ying5b836832008-01-30 13:31:19 +010039#else /* !CONFIG_X86_32 */
40
Matt Fleming62fa6e62014-03-27 15:10:39 -070041#define EFI_LOADER_SIGNATURE "EL64"
Huang, Ying5b836832008-01-30 13:31:19 +010042
Matt Fleming62fa6e62014-03-27 15:10:39 -070043extern u64 asmlinkage efi_call(void *fp, ...);
Huang, Ying5b836832008-01-30 13:31:19 +010044
Matt Fleming62fa6e62014-03-27 15:10:39 -070045#define efi_call_phys(f, args...) efi_call((f), args)
46
47#define efi_call_virt(f, ...) \
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010048({ \
49 efi_status_t __s; \
50 \
51 efi_sync_low_kernel_mappings(); \
52 preempt_disable(); \
Matt Fleming62fa6e62014-03-27 15:10:39 -070053 __s = efi_call((void *)efi.systab->runtime->f, __VA_ARGS__); \
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010054 preempt_enable(); \
55 __s; \
56})
57
Keith Packarde1ad7832011-12-11 16:12:42 -080058extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
Matt Fleming3e8fa262012-10-19 13:25:46 +010059 u32 type, u64 attribute);
Keith Packarde1ad7832011-12-11 16:12:42 -080060
Huang, Ying5b836832008-01-30 13:31:19 +010061#endif /* CONFIG_X86_32 */
62
Jaswinder Singh Rajputcbafbc82008-12-29 20:36:40 +053063extern int add_efi_memmap;
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010064extern struct efi_scratch efi_scratch;
Matthew Garrett9cd2b072011-05-05 15:19:43 -040065extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
Olof Johansson1adbfa32012-02-12 13:24:29 -080066extern int efi_memblock_x86_reserve_range(void);
Huang, Ying5b836832008-01-30 13:31:19 +010067extern void efi_call_phys_prelog(void);
68extern void efi_call_phys_epilog(void);
Olof Johansson5189c2a2012-10-24 10:00:44 -070069extern void efi_unmap_memmap(void);
Matt Fleming3e8fa262012-10-19 13:25:46 +010070extern void efi_memory_uc(u64 addr, unsigned long size);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010071extern void __init efi_map_region(efi_memory_desc_t *md);
Dave Young3b266492013-12-20 18:02:14 +080072extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010073extern void efi_sync_low_kernel_mappings(void);
Borislav Petkovb7b898a2014-01-18 12:48:17 +010074extern int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
75extern void efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010076extern void __init old_map_region(efi_memory_desc_t *md);
Borislav Petkovc55d0162014-02-14 08:24:24 +010077extern void __init runtime_code_page_mkexec(void);
78extern void __init efi_runtime_mkexec(void);
Borislav Petkov11cc8512014-01-18 12:48:15 +010079extern void __init efi_dump_pagetable(void);
Borislav Petkova5d90c92014-03-04 17:02:17 +010080extern void __init efi_apply_memmap_quirks(void);
Huang, Ying5b836832008-01-30 13:31:19 +010081
Dave Young1fec0532013-12-20 18:02:19 +080082struct efi_setup_data {
83 u64 fw_vendor;
84 u64 runtime;
85 u64 tables;
86 u64 smbios;
87 u64 reserved[8];
88};
89
90extern u64 efi_setup;
Dave Young1fec0532013-12-20 18:02:19 +080091
Satoru Takeuchi6b59e362013-02-14 09:07:35 +090092#ifdef CONFIG_EFI
93
94static inline bool efi_is_native(void)
95{
96 return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
97}
98
Matt Fleming7d453ee2014-01-10 18:52:06 +000099static inline bool efi_runtime_supported(void)
100{
101 if (efi_is_native())
102 return true;
103
104 if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP))
105 return true;
106
107 return false;
108}
109
Matt Fleming72548e82013-10-04 09:36:56 +0100110extern struct console early_efi_console;
Dave Young5c12af02014-01-03 11:56:49 +0800111extern void parse_efi_setup(u64 phys_addr, u32 data_len);
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000112
113#ifdef CONFIG_EFI_MIXED
114extern void efi_thunk_runtime_setup(void);
115extern efi_status_t efi_thunk_set_virtual_address_map(
116 void *phys_set_virtual_address_map,
117 unsigned long memory_map_size,
118 unsigned long descriptor_size,
119 u32 descriptor_version,
120 efi_memory_desc_t *virtual_map);
121#else
122static inline void efi_thunk_runtime_setup(void) {}
123static inline efi_status_t efi_thunk_set_virtual_address_map(
124 void *phys_set_virtual_address_map,
125 unsigned long memory_map_size,
126 unsigned long descriptor_size,
127 u32 descriptor_version,
128 efi_memory_desc_t *virtual_map)
129{
130 return EFI_SUCCESS;
131}
132#endif /* CONFIG_EFI_MIXED */
Satoru Takeuchi6b59e362013-02-14 09:07:35 +0900133#else
Russ Anderson7f594232008-10-03 11:59:15 -0500134/*
135 * IF EFI is not configured, have the EFI calls return -ENOSYS.
136 */
137#define efi_call0(_f) (-ENOSYS)
138#define efi_call1(_f, _a1) (-ENOSYS)
139#define efi_call2(_f, _a1, _a2) (-ENOSYS)
140#define efi_call3(_f, _a1, _a2, _a3) (-ENOSYS)
141#define efi_call4(_f, _a1, _a2, _a3, _a4) (-ENOSYS)
142#define efi_call5(_f, _a1, _a2, _a3, _a4, _a5) (-ENOSYS)
143#define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6) (-ENOSYS)
Dave Young5c12af02014-01-03 11:56:49 +0800144static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
Russ Anderson7f594232008-10-03 11:59:15 -0500145#endif /* CONFIG_EFI */
146
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700147#endif /* _ASM_X86_EFI_H */