efi.h 5.7 KB

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