efi.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef _ASM_X86_EFI_H
  2. #define _ASM_X86_EFI_H
  3. /*
  4. * We map the EFI regions needed for runtime services non-contiguously,
  5. * with preserved alignment on virtual addresses starting from -4G down
  6. * for a total max space of 64G. This way, we provide for stable runtime
  7. * services addresses across kernels so that a kexec'd kernel can still
  8. * use them.
  9. *
  10. * This is the main reason why we're doing stable VA mappings for RT
  11. * services.
  12. *
  13. * This flag is used in conjuction with a chicken bit called
  14. * "efi=old_map" which can be used as a fallback to the old runtime
  15. * services mapping method in case there's some b0rkage with a
  16. * particular EFI implementation (haha, it is hard to hold up the
  17. * sarcasm here...).
  18. */
  19. #define EFI_OLD_MEMMAP EFI_ARCH_1
  20. #ifdef CONFIG_X86_32
  21. #define EFI_LOADER_SIGNATURE "EL32"
  22. extern unsigned long asmlinkage efi_call_phys(void *, ...);
  23. #define efi_call_phys0(f) efi_call_phys(f)
  24. #define efi_call_phys1(f, a1) efi_call_phys(f, a1)
  25. #define efi_call_phys2(f, a1, a2) efi_call_phys(f, a1, a2)
  26. #define efi_call_phys3(f, a1, a2, a3) efi_call_phys(f, a1, a2, a3)
  27. #define efi_call_phys4(f, a1, a2, a3, a4) \
  28. efi_call_phys(f, a1, a2, a3, a4)
  29. #define efi_call_phys5(f, a1, a2, a3, a4, a5) \
  30. efi_call_phys(f, a1, a2, a3, a4, a5)
  31. #define efi_call_phys6(f, a1, a2, a3, a4, a5, a6) \
  32. efi_call_phys(f, a1, a2, a3, a4, a5, a6)
  33. /*
  34. * Wrap all the virtual calls in a way that forces the parameters on the stack.
  35. */
  36. #define efi_call_virt(f, args...) \
  37. ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
  38. #define efi_call_virt0(f) efi_call_virt(f)
  39. #define efi_call_virt1(f, a1) efi_call_virt(f, a1)
  40. #define efi_call_virt2(f, a1, a2) efi_call_virt(f, a1, a2)
  41. #define efi_call_virt3(f, a1, a2, a3) efi_call_virt(f, a1, a2, a3)
  42. #define efi_call_virt4(f, a1, a2, a3, a4) \
  43. efi_call_virt(f, a1, a2, a3, a4)
  44. #define efi_call_virt5(f, a1, a2, a3, a4, a5) \
  45. efi_call_virt(f, a1, a2, a3, a4, a5)
  46. #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \
  47. efi_call_virt(f, a1, a2, a3, a4, a5, a6)
  48. #define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
  49. #else /* !CONFIG_X86_32 */
  50. #define EFI_LOADER_SIGNATURE "EL64"
  51. extern u64 efi_call0(void *fp);
  52. extern u64 efi_call1(void *fp, u64 arg1);
  53. extern u64 efi_call2(void *fp, u64 arg1, u64 arg2);
  54. extern u64 efi_call3(void *fp, u64 arg1, u64 arg2, u64 arg3);
  55. extern u64 efi_call4(void *fp, u64 arg1, u64 arg2, u64 arg3, u64 arg4);
  56. extern u64 efi_call5(void *fp, u64 arg1, u64 arg2, u64 arg3,
  57. u64 arg4, u64 arg5);
  58. extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3,
  59. u64 arg4, u64 arg5, u64 arg6);
  60. #define efi_call_phys0(f) \
  61. efi_call0((f))
  62. #define efi_call_phys1(f, a1) \
  63. efi_call1((f), (u64)(a1))
  64. #define efi_call_phys2(f, a1, a2) \
  65. efi_call2((f), (u64)(a1), (u64)(a2))
  66. #define efi_call_phys3(f, a1, a2, a3) \
  67. efi_call3((f), (u64)(a1), (u64)(a2), (u64)(a3))
  68. #define efi_call_phys4(f, a1, a2, a3, a4) \
  69. efi_call4((f), (u64)(a1), (u64)(a2), (u64)(a3), \
  70. (u64)(a4))
  71. #define efi_call_phys5(f, a1, a2, a3, a4, a5) \
  72. efi_call5((f), (u64)(a1), (u64)(a2), (u64)(a3), \
  73. (u64)(a4), (u64)(a5))
  74. #define efi_call_phys6(f, a1, a2, a3, a4, a5, a6) \
  75. efi_call6((f), (u64)(a1), (u64)(a2), (u64)(a3), \
  76. (u64)(a4), (u64)(a5), (u64)(a6))
  77. #define _efi_call_virtX(x, f, ...) \
  78. ({ \
  79. efi_status_t __s; \
  80. \
  81. efi_sync_low_kernel_mappings(); \
  82. preempt_disable(); \
  83. __s = efi_call##x((void *)efi.systab->runtime->f, __VA_ARGS__); \
  84. preempt_enable(); \
  85. __s; \
  86. })
  87. #define efi_call_virt0(f) \
  88. _efi_call_virtX(0, f)
  89. #define efi_call_virt1(f, a1) \
  90. _efi_call_virtX(1, f, (u64)(a1))
  91. #define efi_call_virt2(f, a1, a2) \
  92. _efi_call_virtX(2, f, (u64)(a1), (u64)(a2))
  93. #define efi_call_virt3(f, a1, a2, a3) \
  94. _efi_call_virtX(3, f, (u64)(a1), (u64)(a2), (u64)(a3))
  95. #define efi_call_virt4(f, a1, a2, a3, a4) \
  96. _efi_call_virtX(4, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4))
  97. #define efi_call_virt5(f, a1, a2, a3, a4, a5) \
  98. _efi_call_virtX(5, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4), (u64)(a5))
  99. #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \
  100. _efi_call_virtX(6, f, (u64)(a1), (u64)(a2), (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6))
  101. extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
  102. u32 type, u64 attribute);
  103. #endif /* CONFIG_X86_32 */
  104. extern int add_efi_memmap;
  105. extern unsigned long x86_efi_facility;
  106. extern struct efi_scratch efi_scratch;
  107. extern void efi_set_executable(efi_memory_desc_t *md, bool executable);
  108. extern int efi_memblock_x86_reserve_range(void);
  109. extern void efi_call_phys_prelog(void);
  110. extern void efi_call_phys_epilog(void);
  111. extern void efi_unmap_memmap(void);
  112. extern void efi_memory_uc(u64 addr, unsigned long size);
  113. extern void __init efi_map_region(efi_memory_desc_t *md);
  114. extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
  115. extern void efi_sync_low_kernel_mappings(void);
  116. extern void efi_setup_page_tables(void);
  117. extern void __init old_map_region(efi_memory_desc_t *md);
  118. extern void __init runtime_code_page_mkexec(void);
  119. extern void __init efi_runtime_mkexec(void);
  120. extern void __init efi_apply_memmap_quirks(void);
  121. struct efi_setup_data {
  122. u64 fw_vendor;
  123. u64 runtime;
  124. u64 tables;
  125. u64 smbios;
  126. u64 reserved[8];
  127. };
  128. extern u64 efi_setup;
  129. #ifdef CONFIG_EFI
  130. static inline bool efi_is_native(void)
  131. {
  132. return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
  133. }
  134. extern struct console early_efi_console;
  135. extern void parse_efi_setup(u64 phys_addr, u32 data_len);
  136. #else
  137. /*
  138. * IF EFI is not configured, have the EFI calls return -ENOSYS.
  139. */
  140. #define efi_call0(_f) (-ENOSYS)
  141. #define efi_call1(_f, _a1) (-ENOSYS)
  142. #define efi_call2(_f, _a1, _a2) (-ENOSYS)
  143. #define efi_call3(_f, _a1, _a2, _a3) (-ENOSYS)
  144. #define efi_call4(_f, _a1, _a2, _a3, _a4) (-ENOSYS)
  145. #define efi_call5(_f, _a1, _a2, _a3, _a4, _a5) (-ENOSYS)
  146. #define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6) (-ENOSYS)
  147. static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
  148. #endif /* CONFIG_EFI */
  149. #endif /* _ASM_X86_EFI_H */