efi.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #ifndef _ASM_X86_EFI_H
  2. #define _ASM_X86_EFI_H
  3. #include <asm/i387.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. #endif /* CONFIG_X86_32 */
  72. extern struct efi_scratch efi_scratch;
  73. extern void __init efi_set_executable(efi_memory_desc_t *md, bool executable);
  74. extern int __init efi_memblock_x86_reserve_range(void);
  75. extern pgd_t * __init efi_call_phys_prolog(void);
  76. extern void __init efi_call_phys_epilog(pgd_t *save_pgd);
  77. extern void __init efi_unmap_memmap(void);
  78. extern void __init efi_memory_uc(u64 addr, unsigned long size);
  79. extern void __init efi_map_region(efi_memory_desc_t *md);
  80. extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
  81. extern void efi_sync_low_kernel_mappings(void);
  82. extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
  83. extern void __init efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
  84. extern void __init old_map_region(efi_memory_desc_t *md);
  85. extern void __init runtime_code_page_mkexec(void);
  86. extern void __init efi_runtime_mkexec(void);
  87. extern void __init efi_dump_pagetable(void);
  88. extern void __init efi_apply_memmap_quirks(void);
  89. extern int __init efi_reuse_config(u64 tables, int nr_tables);
  90. extern void efi_delete_dummy_variable(void);
  91. struct efi_setup_data {
  92. u64 fw_vendor;
  93. u64 runtime;
  94. u64 tables;
  95. u64 smbios;
  96. u64 reserved[8];
  97. };
  98. extern u64 efi_setup;
  99. #ifdef CONFIG_EFI
  100. static inline bool efi_is_native(void)
  101. {
  102. return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
  103. }
  104. static inline bool efi_runtime_supported(void)
  105. {
  106. if (efi_is_native())
  107. return true;
  108. if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP))
  109. return true;
  110. return false;
  111. }
  112. extern struct console early_efi_console;
  113. extern void parse_efi_setup(u64 phys_addr, u32 data_len);
  114. #ifdef CONFIG_EFI_MIXED
  115. extern void efi_thunk_runtime_setup(void);
  116. extern efi_status_t efi_thunk_set_virtual_address_map(
  117. void *phys_set_virtual_address_map,
  118. unsigned long memory_map_size,
  119. unsigned long descriptor_size,
  120. u32 descriptor_version,
  121. efi_memory_desc_t *virtual_map);
  122. #else
  123. static inline void efi_thunk_runtime_setup(void) {}
  124. static inline efi_status_t efi_thunk_set_virtual_address_map(
  125. void *phys_set_virtual_address_map,
  126. unsigned long memory_map_size,
  127. unsigned long descriptor_size,
  128. u32 descriptor_version,
  129. efi_memory_desc_t *virtual_map)
  130. {
  131. return EFI_SUCCESS;
  132. }
  133. #endif /* CONFIG_EFI_MIXED */
  134. /* arch specific definitions used by the stub code */
  135. struct efi_config {
  136. u64 image_handle;
  137. u64 table;
  138. u64 allocate_pool;
  139. u64 allocate_pages;
  140. u64 get_memory_map;
  141. u64 free_pool;
  142. u64 free_pages;
  143. u64 locate_handle;
  144. u64 handle_protocol;
  145. u64 exit_boot_services;
  146. u64 text_output;
  147. efi_status_t (*call)(unsigned long, ...);
  148. bool is64;
  149. } __packed;
  150. __pure const struct efi_config *__efi_early(void);
  151. #define efi_call_early(f, ...) \
  152. __efi_early()->call(__efi_early()->f, __VA_ARGS__);
  153. extern bool efi_reboot_required(void);
  154. #else
  155. static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
  156. static inline bool efi_reboot_required(void)
  157. {
  158. return false;
  159. }
  160. #endif /* CONFIG_EFI */
  161. #endif /* _ASM_X86_EFI_H */