efi.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef _ASM_X86_EFI_H
  2. #define _ASM_X86_EFI_H
  3. #include <asm/i387.h>
  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. #define EFI32_LOADER_SIGNATURE "EL32"
  22. #define EFI64_LOADER_SIGNATURE "EL64"
  23. #ifdef CONFIG_X86_32
  24. extern unsigned long asmlinkage efi_call_phys(void *, ...);
  25. /*
  26. * Wrap all the virtual calls in a way that forces the parameters on the stack.
  27. */
  28. /* Use this macro if your virtual returns a non-void value */
  29. #define efi_call_virt(f, args...) \
  30. ({ \
  31. efi_status_t __s; \
  32. kernel_fpu_begin(); \
  33. __s = ((efi_##f##_t __attribute__((regparm(0)))*) \
  34. efi.systab->runtime->f)(args); \
  35. kernel_fpu_end(); \
  36. __s; \
  37. })
  38. /* Use this macro if your virtual call does not return any value */
  39. #define __efi_call_virt(f, args...) \
  40. ({ \
  41. kernel_fpu_begin(); \
  42. ((efi_##f##_t __attribute__((regparm(0)))*) \
  43. efi.systab->runtime->f)(args); \
  44. kernel_fpu_end(); \
  45. })
  46. #define efi_ioremap(addr, size, type, attr) ioremap_cache(addr, size)
  47. #else /* !CONFIG_X86_32 */
  48. #define EFI_LOADER_SIGNATURE "EL64"
  49. extern u64 asmlinkage efi_call(void *fp, ...);
  50. #define efi_call_phys(f, args...) efi_call((f), args)
  51. #define efi_call_virt(f, ...) \
  52. ({ \
  53. efi_status_t __s; \
  54. \
  55. efi_sync_low_kernel_mappings(); \
  56. preempt_disable(); \
  57. __kernel_fpu_begin(); \
  58. __s = efi_call((void *)efi.systab->runtime->f, __VA_ARGS__); \
  59. __kernel_fpu_end(); \
  60. preempt_enable(); \
  61. __s; \
  62. })
  63. /*
  64. * All X86_64 virt calls return non-void values. Thus, use non-void call for
  65. * virt calls that would be void on X86_32.
  66. */
  67. #define __efi_call_virt(f, args...) efi_call_virt(f, args)
  68. extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,
  69. u32 type, u64 attribute);
  70. #endif /* CONFIG_X86_32 */
  71. extern struct efi_scratch efi_scratch;
  72. extern void __init efi_set_executable(efi_memory_desc_t *md, bool executable);
  73. extern int __init efi_memblock_x86_reserve_range(void);
  74. extern void __init efi_call_phys_prolog(void);
  75. extern void __init efi_call_phys_epilog(void);
  76. extern void __init efi_unmap_memmap(void);
  77. extern void __init efi_memory_uc(u64 addr, unsigned long size);
  78. extern void __init efi_map_region(efi_memory_desc_t *md);
  79. extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
  80. extern void efi_sync_low_kernel_mappings(void);
  81. extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages);
  82. extern void __init efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages);
  83. extern void __init old_map_region(efi_memory_desc_t *md);
  84. extern void __init runtime_code_page_mkexec(void);
  85. extern void __init efi_runtime_mkexec(void);
  86. extern void __init efi_dump_pagetable(void);
  87. extern void __init efi_apply_memmap_quirks(void);
  88. extern int __init efi_reuse_config(u64 tables, int nr_tables);
  89. extern void efi_delete_dummy_variable(void);
  90. struct efi_setup_data {
  91. u64 fw_vendor;
  92. u64 runtime;
  93. u64 tables;
  94. u64 smbios;
  95. u64 reserved[8];
  96. };
  97. extern u64 efi_setup;
  98. #ifdef CONFIG_EFI
  99. static inline bool efi_is_native(void)
  100. {
  101. return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT);
  102. }
  103. static inline bool efi_runtime_supported(void)
  104. {
  105. if (efi_is_native())
  106. return true;
  107. if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP))
  108. return true;
  109. return false;
  110. }
  111. extern struct console early_efi_console;
  112. extern void parse_efi_setup(u64 phys_addr, u32 data_len);
  113. #ifdef CONFIG_EFI_MIXED
  114. extern void efi_thunk_runtime_setup(void);
  115. extern efi_status_t efi_thunk_set_virtual_address_map(
  116. void *phys_set_virtual_address_map,
  117. unsigned long memory_map_size,
  118. unsigned long descriptor_size,
  119. u32 descriptor_version,
  120. efi_memory_desc_t *virtual_map);
  121. #else
  122. static inline void efi_thunk_runtime_setup(void) {}
  123. static inline efi_status_t efi_thunk_set_virtual_address_map(
  124. void *phys_set_virtual_address_map,
  125. unsigned long memory_map_size,
  126. unsigned long descriptor_size,
  127. u32 descriptor_version,
  128. efi_memory_desc_t *virtual_map)
  129. {
  130. return EFI_SUCCESS;
  131. }
  132. #endif /* CONFIG_EFI_MIXED */
  133. extern bool efi_reboot_required(void);
  134. #else
  135. static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
  136. static inline bool efi_reboot_required(void)
  137. {
  138. return false;
  139. }
  140. #endif /* CONFIG_EFI */
  141. #endif /* _ASM_X86_EFI_H */