H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_EFI_H |
| 2 | #define _ASM_X86_EFI_H |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 3 | |
Borislav Petkov | d2f7cbe | 2013-10-31 17:25:08 +0100 | [diff] [blame] | 4 | /* |
| 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, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 22 | #ifdef CONFIG_X86_32 |
Huang, Ying | e429795 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 23 | |
Matt Fleming | f7d7d01 | 2011-11-15 12:56:14 +0000 | [diff] [blame] | 24 | #define EFI_LOADER_SIGNATURE "EL32" |
| 25 | |
Huang, Ying | e429795 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 26 | extern 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 Perches | 0c6f6ab | 2008-03-23 01:02:07 -0700 | [diff] [blame] | 43 | ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args) |
Huang, Ying | e429795 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 44 | |
| 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, Ying | e429795 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 55 | |
Matt Fleming | 3e8fa26 | 2012-10-19 13:25:46 +0100 | [diff] [blame] | 56 | #define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size) |
Keith Packard | e1ad783 | 2011-12-11 16:12:42 -0800 | [diff] [blame] | 57 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 58 | #else /* !CONFIG_X86_32 */ |
| 59 | |
Matt Fleming | f7d7d01 | 2011-11-15 12:56:14 +0000 | [diff] [blame] | 60 | #define EFI_LOADER_SIGNATURE "EL64" |
| 61 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 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, |
| 68 | u64 arg4, u64 arg5); |
| 69 | extern 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 Petkov | 43ab047 | 2013-06-02 14:56:07 +0200 | [diff] [blame] | 73 | efi_call0((f)) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 74 | #define efi_call_phys1(f, a1) \ |
Borislav Petkov | 43ab047 | 2013-06-02 14:56:07 +0200 | [diff] [blame] | 75 | efi_call1((f), (u64)(a1)) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 76 | #define efi_call_phys2(f, a1, a2) \ |
Borislav Petkov | 43ab047 | 2013-06-02 14:56:07 +0200 | [diff] [blame] | 77 | efi_call2((f), (u64)(a1), (u64)(a2)) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 78 | #define efi_call_phys3(f, a1, a2, a3) \ |
Borislav Petkov | 43ab047 | 2013-06-02 14:56:07 +0200 | [diff] [blame] | 79 | efi_call3((f), (u64)(a1), (u64)(a2), (u64)(a3)) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 80 | #define efi_call_phys4(f, a1, a2, a3, a4) \ |
Borislav Petkov | 43ab047 | 2013-06-02 14:56:07 +0200 | [diff] [blame] | 81 | efi_call4((f), (u64)(a1), (u64)(a2), (u64)(a3), \ |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 82 | (u64)(a4)) |
| 83 | #define efi_call_phys5(f, a1, a2, a3, a4, a5) \ |
Borislav Petkov | 43ab047 | 2013-06-02 14:56:07 +0200 | [diff] [blame] | 84 | efi_call5((f), (u64)(a1), (u64)(a2), (u64)(a3), \ |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 85 | (u64)(a4), (u64)(a5)) |
| 86 | #define efi_call_phys6(f, a1, a2, a3, a4, a5, a6) \ |
Borislav Petkov | 43ab047 | 2013-06-02 14:56:07 +0200 | [diff] [blame] | 87 | efi_call6((f), (u64)(a1), (u64)(a2), (u64)(a3), \ |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 88 | (u64)(a4), (u64)(a5), (u64)(a6)) |
| 89 | |
Borislav Petkov | d2f7cbe | 2013-10-31 17:25:08 +0100 | [diff] [blame] | 90 | #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, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 101 | #define efi_call_virt0(f) \ |
Borislav Petkov | d2f7cbe | 2013-10-31 17:25:08 +0100 | [diff] [blame] | 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)) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 115 | |
Keith Packard | e1ad783 | 2011-12-11 16:12:42 -0800 | [diff] [blame] | 116 | extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size, |
Matt Fleming | 3e8fa26 | 2012-10-19 13:25:46 +0100 | [diff] [blame] | 117 | u32 type, u64 attribute); |
Keith Packard | e1ad783 | 2011-12-11 16:12:42 -0800 | [diff] [blame] | 118 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 119 | #endif /* CONFIG_X86_32 */ |
| 120 | |
Jaswinder Singh Rajput | cbafbc8 | 2008-12-29 20:36:40 +0530 | [diff] [blame] | 121 | extern int add_efi_memmap; |
Borislav Petkov | d2f7cbe | 2013-10-31 17:25:08 +0100 | [diff] [blame] | 122 | extern struct efi_scratch efi_scratch; |
Matthew Garrett | 9cd2b07 | 2011-05-05 15:19:43 -0400 | [diff] [blame] | 123 | extern void efi_set_executable(efi_memory_desc_t *md, bool executable); |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 124 | extern int efi_memblock_x86_reserve_range(void); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 125 | extern void efi_call_phys_prelog(void); |
| 126 | extern void efi_call_phys_epilog(void); |
Olof Johansson | 5189c2a | 2012-10-24 10:00:44 -0700 | [diff] [blame] | 127 | extern void efi_unmap_memmap(void); |
Matt Fleming | 3e8fa26 | 2012-10-19 13:25:46 +0100 | [diff] [blame] | 128 | extern void efi_memory_uc(u64 addr, unsigned long size); |
Borislav Petkov | d2f7cbe | 2013-10-31 17:25:08 +0100 | [diff] [blame] | 129 | extern void __init efi_map_region(efi_memory_desc_t *md); |
Dave Young | 3b26649 | 2013-12-20 18:02:14 +0800 | [diff] [blame] | 130 | extern void __init efi_map_region_fixed(efi_memory_desc_t *md); |
Borislav Petkov | d2f7cbe | 2013-10-31 17:25:08 +0100 | [diff] [blame] | 131 | extern void efi_sync_low_kernel_mappings(void); |
| 132 | extern void efi_setup_page_tables(void); |
| 133 | extern void __init old_map_region(efi_memory_desc_t *md); |
Borislav Petkov | c55d016 | 2014-02-14 08:24:24 +0100 | [diff] [blame] | 134 | extern void __init runtime_code_page_mkexec(void); |
| 135 | extern void __init efi_runtime_mkexec(void); |
Borislav Petkov | 11cc851 | 2014-01-18 12:48:15 +0100 | [diff] [blame^] | 136 | extern void __init efi_dump_pagetable(void); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 137 | |
Dave Young | 1fec053 | 2013-12-20 18:02:19 +0800 | [diff] [blame] | 138 | struct efi_setup_data { |
| 139 | u64 fw_vendor; |
| 140 | u64 runtime; |
| 141 | u64 tables; |
| 142 | u64 smbios; |
| 143 | u64 reserved[8]; |
| 144 | }; |
| 145 | |
| 146 | extern u64 efi_setup; |
Dave Young | 1fec053 | 2013-12-20 18:02:19 +0800 | [diff] [blame] | 147 | |
Satoru Takeuchi | 6b59e36 | 2013-02-14 09:07:35 +0900 | [diff] [blame] | 148 | #ifdef CONFIG_EFI |
| 149 | |
| 150 | static inline bool efi_is_native(void) |
| 151 | { |
| 152 | return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT); |
| 153 | } |
| 154 | |
Matt Fleming | 72548e8 | 2013-10-04 09:36:56 +0100 | [diff] [blame] | 155 | extern struct console early_efi_console; |
Dave Young | 5c12af0 | 2014-01-03 11:56:49 +0800 | [diff] [blame] | 156 | extern void parse_efi_setup(u64 phys_addr, u32 data_len); |
Satoru Takeuchi | 6b59e36 | 2013-02-14 09:07:35 +0900 | [diff] [blame] | 157 | #else |
Russ Anderson | 7f59423 | 2008-10-03 11:59:15 -0500 | [diff] [blame] | 158 | /* |
| 159 | * IF EFI is not configured, have the EFI calls return -ENOSYS. |
| 160 | */ |
| 161 | #define efi_call0(_f) (-ENOSYS) |
| 162 | #define efi_call1(_f, _a1) (-ENOSYS) |
| 163 | #define efi_call2(_f, _a1, _a2) (-ENOSYS) |
| 164 | #define efi_call3(_f, _a1, _a2, _a3) (-ENOSYS) |
| 165 | #define efi_call4(_f, _a1, _a2, _a3, _a4) (-ENOSYS) |
| 166 | #define efi_call5(_f, _a1, _a2, _a3, _a4, _a5) (-ENOSYS) |
| 167 | #define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6) (-ENOSYS) |
Dave Young | 5c12af0 | 2014-01-03 11:56:49 +0800 | [diff] [blame] | 168 | static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {} |
Russ Anderson | 7f59423 | 2008-10-03 11:59:15 -0500 | [diff] [blame] | 169 | #endif /* CONFIG_EFI */ |
| 170 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 171 | #endif /* _ASM_X86_EFI_H */ |