linux/arch/x86/include/asm/efi.h
<<
>>
Prefs
   1#ifndef _ASM_X86_EFI_H
   2#define _ASM_X86_EFI_H
   3
   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
  22#ifdef CONFIG_X86_32
  23
  24#define EFI_LOADER_SIGNATURE    "EL32"
  25
  26extern 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...) \
  43        ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
  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)
  55
  56#define efi_ioremap(addr, size, type, attr)     ioremap_cache(addr, size)
  57
  58#else /* !CONFIG_X86_32 */
  59
  60#define EFI_LOADER_SIGNATURE    "EL64"
  61
  62extern 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)                       \
  73        efi_call0((f))
  74#define efi_call_phys1(f, a1)                   \
  75        efi_call1((f), (u64)(a1))
  76#define efi_call_phys2(f, a1, a2)                       \
  77        efi_call2((f), (u64)(a1), (u64)(a2))
  78#define efi_call_phys3(f, a1, a2, a3)                           \
  79        efi_call3((f), (u64)(a1), (u64)(a2), (u64)(a3))
  80#define efi_call_phys4(f, a1, a2, a3, a4)                               \
  81        efi_call4((f), (u64)(a1), (u64)(a2), (u64)(a3),         \
  82                  (u64)(a4))
  83#define efi_call_phys5(f, a1, a2, a3, a4, a5)                           \
  84        efi_call5((f), (u64)(a1), (u64)(a2), (u64)(a3),         \
  85                  (u64)(a4), (u64)(a5))
  86#define efi_call_phys6(f, a1, a2, a3, a4, a5, a6)                       \
  87        efi_call6((f), (u64)(a1), (u64)(a2), (u64)(a3),         \
  88                  (u64)(a4), (u64)(a5), (u64)(a6))
  89
  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
 101#define efi_call_virt0(f)                               \
 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))
 115
 116extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
 117                                 u32 type, u64 attribute);
 118
 119#endif /* CONFIG_X86_32 */
 120
 121extern int add_efi_memmap;
 122extern unsigned long x86_efi_facility;
 123extern struct efi_scratch efi_scratch;
 124extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
 125extern int efi_memblock_x86_reserve_range(void);
 126extern void efi_call_phys_prelog(void);
 127extern void efi_call_phys_epilog(void);
 128extern void efi_unmap_memmap(void);
 129extern void efi_memory_uc(u64 addr, unsigned long size);
 130extern void __init efi_map_region(efi_memory_desc_t *md);
 131extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
 132extern 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);
 135extern void __init runtime_code_page_mkexec(void);
 136extern void __init efi_runtime_mkexec(void);
 137extern void __init efi_apply_memmap_quirks(void);
 138
 139struct efi_setup_data {
 140        u64 fw_vendor;
 141        u64 runtime;
 142        u64 tables;
 143        u64 smbios;
 144        u64 reserved[8];
 145};
 146
 147extern u64 efi_setup;
 148
 149#ifdef CONFIG_EFI
 150
 151static inline bool efi_is_native(void)
 152{
 153        return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
 154}
 155
 156extern struct console early_efi_console;
 157extern void parse_efi_setup(u64 phys_addr, u32 data_len);
 158#else
 159/*
 160 * IF EFI is not configured, have the EFI calls return -ENOSYS.
 161 */
 162#define efi_call0(_f)                                   (-ENOSYS)
 163#define efi_call1(_f, _a1)                              (-ENOSYS)
 164#define efi_call2(_f, _a1, _a2)                         (-ENOSYS)
 165#define efi_call3(_f, _a1, _a2, _a3)                    (-ENOSYS)
 166#define efi_call4(_f, _a1, _a2, _a3, _a4)               (-ENOSYS)
 167#define efi_call5(_f, _a1, _a2, _a3, _a4, _a5)          (-ENOSYS)
 168#define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6)     (-ENOSYS)
 169static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
 170#endif /* CONFIG_EFI */
 171
 172#endif /* _ASM_X86_EFI_H */
 173