efi.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #ifndef _ASM_X86_EFI_H
  2. #define _ASM_X86_EFI_H
  3. #include <asm/fpu/api.h>
  4. #include <asm/pgtable.h>
  5. #include <asm/processor-flags.h>
  6. #include <asm/tlb.h>
  7. /*
  8. * We map the EFI regions needed for runtime services non-contiguously,
  9. * with preserved alignment on virtual addresses starting from -4G down
  10. * for a total max space of 64G. This way, we provide for stable runtime
  11. * services addresses across kernels so that a kexec'd kernel can still
  12. * use them.
  13. *
  14. * This is the main reason why we're doing stable VA mappings for RT
  15. * services.
  16. *
  17. * This flag is used in conjuction with a chicken bit called
  18. * "efi=old_map" which can be used as a fallback to the old runtime
  19. * services mapping method in case there's some b0rkage with a
  20. * particular EFI implementation (haha, it is hard to hold up the
  21. * sarcasm here...).
  22. */
  23. #define EFI_OLD_MEMMAP EFI_ARCH_1
  24. #define EFI32_LOADER_SIGNATURE "EL32"
  25. #define EFI64_LOADER_SIGNATURE "EL64"
  26. #define MAX_CMDLINE_ADDRESS UINT_MAX
  27. #define ARCH_EFI_IRQ_FLAGS_MASK X86_EFLAGS_IF
  28. #ifdef CONFIG_X86_32
  29. extern unsigned long asmlinkage efi_call_phys(void *, ...);
  30. #define arch_efi_call_virt_setup() kernel_fpu_begin()
  31. #define arch_efi_call_virt_teardown() kernel_fpu_end()
  32. /*
  33. * Wrap all the virtual calls in a way that forces the parameters on the stack.
  34. */
  35. #define arch_efi_call_virt(p, f, args...) \
  36. ({ \
  37. ((efi_##f##_t __attribute__((regparm(0)))*) p->f)(args); \
  38. })
  39. #define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
  40. #else /* !CONFIG_X86_32 */
  41. #define EFI_LOADER_SIGNATURE "EL64"
  42. extern u64 asmlinkage efi_call(void *fp, ...);
  43. #define efi_call_phys(f, args...) efi_call((f), args)
  44. /*
  45. * Scratch space used for switching the pagetable in the EFI stub
  46. */
  47. struct efi_scratch {
  48. u64 r15;
  49. u64 prev_cr3;
  50. pgd_t *efi_pgt;
  51. bool use_pgd;
  52. u64 phys_stack;
  53. } __packed;
  54. #define arch_efi_call_virt_setup() \
  55. ({ \
  56. efi_sync_low_kernel_mappings(); \
  57. preempt_disable(); \
  58. __kernel_fpu_begin(); \
  59. \
  60. if (efi_scratch.use_pgd) { \
  61. efi_scratch.prev_cr3 = read_cr3(); \
  62. write_cr3((unsigned long)efi_scratch.efi_pgt); \
  63. __flush_tlb_all(); \
  64. } \
  65. })
  66. #define arch_efi_call_virt(p, f, args...) \
  67. efi_call((void *)p->f, args) \
  68. #define arch_efi_call_virt_teardown() \
  69. ({ \
  70. if (efi_scratch.use_pgd) { \
  71. write_cr3(efi_scratch.prev_cr3); \
  72. __flush_tlb_all(); \
  73. } \
  74. \
  75. __kernel_fpu_end(); \
  76. preempt_enable(); \
  77. })
  78. extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,
  79. u32 type, u64 attribute);
  80. #ifdef CONFIG_KASAN
  81. /*
  82. * CONFIG_KASAN may redefine memset to __memset. __memset function is present
  83. * only in kernel binary. Since the EFI stub linked into a separate binary it
  84. * doesn't have __memset(). So we should use standard memset from
  85. * arch/x86/boot/compressed/string.c. The same applies to memcpy and memmove.
  86. */
  87. #undef memcpy
  88. #undef memset
  89. #undef memmove
  90. #endif
  91. #endif /* CONFIG_X86_32 */
  92. extern struct efi_scratch efi_scratch;
  93. extern void __init efi_set_executable(efi_memory_desc_t *md, bool executable);
  94. extern int __init efi_memblock_x86_reserve_range(void);
  95. extern pgd_t * __init efi_call_phys_prolog(void);
  96. extern void __init efi_call_phys_epilog(pgd_t *save_pgd);
  97. extern void __init efi_print_memmap(void);
  98. extern void __init efi_memory_uc(u64 addr, unsigned long size);
  99. extern void __init efi_map_region(efi_memory_desc_t *md);
  100. extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
  101. extern void efi_sync_low_kernel_mappings(void);
  102. extern int __init efi_alloc_page_tables(void);
  103. extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
  104. extern void __init old_map_region(efi_memory_desc_t *md);
  105. extern void __init runtime_code_page_mkexec(void);
  106. extern void __init efi_runtime_update_mappings(void);
  107. extern void __init efi_dump_pagetable(void);
  108. extern void __init efi_apply_memmap_quirks(void);
  109. extern int __init efi_reuse_config(u64 tables, int nr_tables);
  110. extern void efi_delete_dummy_variable(void);
  111. struct efi_setup_data {
  112. u64 fw_vendor;
  113. u64 runtime;
  114. u64 tables;
  115. u64 smbios;
  116. u64 reserved[8];
  117. };
  118. extern u64 efi_setup;
  119. #ifdef CONFIG_EFI
  120. static inline bool efi_is_native(void)
  121. {
  122. return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
  123. }
  124. static inline bool efi_runtime_supported(void)
  125. {
  126. if (efi_is_native())
  127. return true;
  128. if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP))
  129. return true;
  130. return false;
  131. }
  132. extern struct console early_efi_console;
  133. extern void parse_efi_setup(u64 phys_addr, u32 data_len);
  134. extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
  135. #ifdef CONFIG_EFI_MIXED
  136. extern void efi_thunk_runtime_setup(void);
  137. extern efi_status_t efi_thunk_set_virtual_address_map(
  138. void *phys_set_virtual_address_map,
  139. unsigned long memory_map_size,
  140. unsigned long descriptor_size,
  141. u32 descriptor_version,
  142. efi_memory_desc_t *virtual_map);
  143. #else
  144. static inline void efi_thunk_runtime_setup(void) {}
  145. static inline efi_status_t efi_thunk_set_virtual_address_map(
  146. void *phys_set_virtual_address_map,
  147. unsigned long memory_map_size,
  148. unsigned long descriptor_size,
  149. u32 descriptor_version,
  150. efi_memory_desc_t *virtual_map)
  151. {
  152. return EFI_SUCCESS;
  153. }
  154. #endif /* CONFIG_EFI_MIXED */
  155. /* arch specific definitions used by the stub code */
  156. struct efi_config {
  157. u64 image_handle;
  158. u64 table;
  159. u64 boot_services;
  160. u64 text_output;
  161. efi_status_t (*call)(unsigned long, ...);
  162. bool is64;
  163. } __packed;
  164. __pure const struct efi_config *__efi_early(void);
  165. static inline bool efi_is_64bit(void)
  166. {
  167. if (!IS_ENABLED(CONFIG_X86_64))
  168. return false;
  169. if (!IS_ENABLED(CONFIG_EFI_MIXED))
  170. return true;
  171. return __efi_early()->is64;
  172. }
  173. #define efi_call_early(f, ...) \
  174. __efi_early()->call(efi_is_64bit() ? \
  175. ((efi_boot_services_64_t *)(unsigned long) \
  176. __efi_early()->boot_services)->f : \
  177. ((efi_boot_services_32_t *)(unsigned long) \
  178. __efi_early()->boot_services)->f, __VA_ARGS__)
  179. #define __efi_call_early(f, ...) \
  180. __efi_early()->call((unsigned long)f, __VA_ARGS__);
  181. extern bool efi_reboot_required(void);
  182. #else
  183. static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
  184. static inline bool efi_reboot_required(void)
  185. {
  186. return false;
  187. }
  188. #endif /* CONFIG_EFI */
  189. #endif /* _ASM_X86_EFI_H */