linux-efi.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. #pragma once
  2. #include <efidef.h>
  3. #include "compiler_attributes.h"
  4. #include "types.h"
  5. #include <efiapi.h>
  6. #include <efierr.h>
  7. #include "linux/pfn.h"
  8. #if defined(CONFIG_riscv64)
  9. #include "riscv64.h"
  10. #endif
  11. #define efi_table_hdr_t EFI_TABLE_HEADER
  12. #define efi_guid_t EFI_GUID
  13. #define efi_runtime_services_t EFI_RUNTIME_SERVICES
  14. #define efi_boot_services_t EFI_BOOT_SERVICES
  15. #define efi_memory_desc_t EFI_MEMORY_DESCRIPTOR
  16. #define efi_capsule_header_t EFI_CAPSULE_HEADER
  17. #define efi_time_t EFI_TIME
  18. #define efi_time_cap_t EFI_TIME_CAPABILITIES
  19. #define MAKE_EFI_GUID(a, b, c, d...) \
  20. (efi_guid_t) \
  21. { \
  22. a, b & 0xffff, c & 0xffff, \
  23. { \
  24. d \
  25. } \
  26. }
  27. /*
  28. * EFI Configuration Table and GUID definitions
  29. *
  30. * These are all defined in a single line to make them easier to
  31. * grep for and to see them at a glance - while still having a
  32. * similar structure to the definitions in the spec.
  33. *
  34. * Here's how they are structured:
  35. *
  36. * GUID: 12345678-1234-1234-1234-123456789012
  37. * Spec:
  38. * #define EFI_SOME_PROTOCOL_GUID \
  39. * {0x12345678,0x1234,0x1234,\
  40. * {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
  41. * Here:
  42. * #define SOME_PROTOCOL_GUID EFI_GUID(0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
  43. * ^ tabs ^extra space
  44. *
  45. * Note that the 'extra space' separates the values at the same place
  46. * where the UEFI SPEC breaks the line.
  47. */
  48. #define NULL_GUID \
  49. MAKE_EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \
  50. 0x00, 0x00, 0x00, 0x00)
  51. #ifndef MPS_TABLE_GUID
  52. #define MPS_TABLE_GUID \
  53. MAKE_EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, \
  54. 0x27, 0x3f, 0xc1, 0x4d)
  55. #endif
  56. #ifndef ACPI_TABLE_GUID
  57. #define ACPI_TABLE_GUID \
  58. MAKE_EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, \
  59. 0x27, 0x3f, 0xc1, 0x4d)
  60. #endif
  61. #ifndef ACPI_20_TABLE_GUID
  62. #define ACPI_20_TABLE_GUID \
  63. MAKE_EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, \
  64. 0xc7, 0x3c, 0x88, 0x81)
  65. #endif
  66. #ifndef SMBIOS_TABLE_GUID
  67. #define SMBIOS_TABLE_GUID \
  68. MAKE_EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, \
  69. 0x27, 0x3f, 0xc1, 0x4d)
  70. #endif
  71. #ifndef SMBIOS3_TABLE_GUID
  72. #define SMBIOS3_TABLE_GUID \
  73. MAKE_EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, \
  74. 0xcf, 0x20, 0xe3, 0x94)
  75. #endif
  76. #ifndef SAL_SYSTEM_TABLE_GUID
  77. #define SAL_SYSTEM_TABLE_GUID \
  78. MAKE_EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, \
  79. 0x27, 0x3f, 0xc1, 0x4d)
  80. #endif
  81. #define HCDP_TABLE_GUID \
  82. MAKE_EFI_GUID(0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, \
  83. 0x79, 0x61, 0x78, 0x98)
  84. #define UGA_IO_PROTOCOL_GUID \
  85. MAKE_EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, \
  86. 0xed, 0x0b, 0x07, 0xa2)
  87. #define EFI_GLOBAL_VARIABLE_GUID \
  88. MAKE_EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, \
  89. 0x98, 0x03, 0x2b, 0x8c)
  90. #define UV_SYSTEM_TABLE_GUID \
  91. MAKE_EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, \
  92. 0x56, 0xd8, 0x95, 0x93)
  93. #define LINUX_EFI_CRASH_GUID \
  94. MAKE_EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, \
  95. 0xbf, 0xe2, 0x98, 0xa0)
  96. #define LOADED_IMAGE_PROTOCOL_GUID \
  97. MAKE_EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, \
  98. 0xc9, 0x69, 0x72, 0x3b)
  99. #define LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \
  100. MAKE_EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, \
  101. 0x36, 0xd7, 0x50, 0xdf)
  102. #ifndef EFI_DEVICE_PATH_PROTOCOL_GUID
  103. #define EFI_DEVICE_PATH_PROTOCOL_GUID \
  104. MAKE_EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, \
  105. 0xc9, 0x69, 0x72, 0x3b)
  106. #endif
  107. #ifndef EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID
  108. #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
  109. MAKE_EFI_GUID(0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, \
  110. 0x4e, 0x4a, 0x7f, 0x1c)
  111. #endif
  112. #ifndef EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID
  113. #define EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID \
  114. MAKE_EFI_GUID(0x05c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, \
  115. 0x33, 0x43, 0xf5, 0x1e)
  116. #endif
  117. #ifndef EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
  118. #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
  119. MAKE_EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, \
  120. 0xd0, 0x80, 0x51, 0x6a)
  121. #endif
  122. #define EFI_UGA_PROTOCOL_GUID \
  123. MAKE_EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, \
  124. 0x68, 0x8f, 0xb8, 0x39)
  125. #ifndef EFI_PCI_IO_PROTOCOL_GUID
  126. #define EFI_PCI_IO_PROTOCOL_GUID \
  127. MAKE_EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, \
  128. 0x3f, 0x50, 0x02, 0x9a)
  129. #endif
  130. #ifndef EFI_FILE_INFO_ID
  131. #define EFI_FILE_INFO_ID \
  132. MAKE_EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, \
  133. 0xc9, 0x69, 0x72, 0x3b)
  134. #endif
  135. #define EFI_SYSTEM_RESOURCE_TABLE_GUID \
  136. MAKE_EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, \
  137. 0xb0, 0xd6, 0x21, 0x80)
  138. #define EFI_FILE_SYSTEM_GUID \
  139. MAKE_EFI_GUID(0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, \
  140. 0xc9, 0x69, 0x72, 0x3b)
  141. #define DEVICE_TREE_GUID \
  142. MAKE_EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, \
  143. 0x2c, 0x69, 0xaa, 0xe0)
  144. #define EFI_PROPERTIES_TABLE_GUID \
  145. MAKE_EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, \
  146. 0x34, 0x08, 0x25, 0xe5)
  147. #ifndef EFI_RNG_PROTOCOL_GUID
  148. #define EFI_RNG_PROTOCOL_GUID \
  149. MAKE_EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, \
  150. 0xdc, 0x29, 0x1f, 0x44)
  151. #endif
  152. #ifndef EFI_RNG_ALGORITHM_RAW
  153. #define EFI_RNG_ALGORITHM_RAW \
  154. MAKE_EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, \
  155. 0xc4, 0xb6, 0x85, 0x61)
  156. #endif
  157. #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID \
  158. MAKE_EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, \
  159. 0xdc, 0x46, 0x12, 0x20)
  160. #define EFI_CONSOLE_OUT_DEVICE_GUID \
  161. MAKE_EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, \
  162. 0x27, 0x3f, 0xc1, 0x4d)
  163. #define APPLE_PROPERTIES_PROTOCOL_GUID \
  164. MAKE_EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, \
  165. 0xab, 0x30, 0x3a, 0xe0)
  166. #define EFI_TCG2_PROTOCOL_GUID \
  167. MAKE_EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, \
  168. 0x6d, 0xb2, 0x72, 0x0f)
  169. #ifndef EFI_LOAD_FILE_PROTOCOL_GUID
  170. #define EFI_LOAD_FILE_PROTOCOL_GUID \
  171. MAKE_EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, \
  172. 0xc9, 0x69, 0x72, 0x3b)
  173. #endif
  174. #define EFI_LOAD_FILE2_PROTOCOL_GUID \
  175. MAKE_EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, \
  176. 0x87, 0x24, 0xe0, 0x6d)
  177. #define EFI_RT_PROPERTIES_TABLE_GUID \
  178. MAKE_EFI_GUID(0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, 0x93, 0x1d, \
  179. 0x21, 0xc3, 0x8a, 0xe9)
  180. #define EFI_DXE_SERVICES_TABLE_GUID \
  181. MAKE_EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, 0x4d, 0xa0, \
  182. 0x39, 0x8e, 0x2b, 0xb9)
  183. #define EFI_SMBIOS_PROTOCOL_GUID \
  184. MAKE_EFI_GUID(0x03583ff6, 0xcb36, 0x4940, 0x94, 0x7e, 0xb9, 0xb3, \
  185. 0x9f, 0x4a, 0xfa, 0xf7)
  186. #define EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID \
  187. MAKE_EFI_GUID(0xf4560cf6, 0x40ec, 0x4b4a, 0xa1, 0x92, 0xbf, 0x1d, \
  188. 0x57, 0xd0, 0xb1, 0x89)
  189. #define EFI_IMAGE_SECURITY_DATABASE_GUID \
  190. MAKE_EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, \
  191. 0x0e, 0x67, 0x65, 0x6f)
  192. #define EFI_SHIM_LOCK_GUID \
  193. MAKE_EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, \
  194. 0x10, 0xdd, 0x8b, 0x23)
  195. #define EFI_CERT_SHA256_GUID \
  196. MAKE_EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, \
  197. 0x36, 0x93, 0x43, 0x28)
  198. #define EFI_CERT_X509_GUID \
  199. MAKE_EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, \
  200. 0x5c, 0x2b, 0xf0, 0x72)
  201. #define EFI_CERT_X509_SHA256_GUID \
  202. MAKE_EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, \
  203. 0x8e, 0xf1, 0x03, 0xed)
  204. #define EFI_CC_BLOB_GUID \
  205. MAKE_EFI_GUID(0x067b1f5f, 0xcf26, 0x44c5, 0x85, 0x54, 0x93, 0xd7, \
  206. 0x77, 0x91, 0x2d, 0x42)
  207. /*
  208. * This GUID is used to pass to the kernel proper the struct screen_info
  209. * structure that was populated by the stub based on the GOP protocol instance
  210. * associated with ConOut
  211. */
  212. #define LINUX_EFI_SCREEN_INFO_TABLE_GUID \
  213. MAKE_EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, 0xb9, 0x0e, 0x4a, 0xb5, \
  214. 0x02, 0x37, 0x1d, 0x95)
  215. #define LINUX_EFI_ARM_CPU_STATE_TABLE_GUID \
  216. MAKE_EFI_GUID(0xef79e4aa, 0x3c3d, 0x4989, 0xb9, 0x02, 0x07, 0xa9, \
  217. 0x43, 0xe5, 0x50, 0xd2)
  218. #define LINUX_EFI_LOADER_ENTRY_GUID \
  219. MAKE_EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, \
  220. 0x29, 0xbb, 0x8c, 0x4f)
  221. #define LINUX_EFI_RANDOM_SEED_TABLE_GUID \
  222. MAKE_EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, \
  223. 0xf1, 0x80, 0xf5, 0x7b)
  224. #define LINUX_EFI_TPM_EVENT_LOG_GUID \
  225. MAKE_EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, \
  226. 0x07, 0xb7, 0x47, 0xfa)
  227. #define LINUX_EFI_TPM_FINAL_LOG_GUID \
  228. MAKE_EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, \
  229. 0xbe, 0xf8, 0x23, 0x25)
  230. #define LINUX_EFI_MEMRESERVE_TABLE_GUID \
  231. MAKE_EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, \
  232. 0x5c, 0xb9, 0x77, 0xc2)
  233. #define LINUX_EFI_INITRD_MEDIA_GUID \
  234. MAKE_EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, 0xca, 0x55, \
  235. 0x52, 0x31, 0xcc, 0x68)
  236. #define LINUX_EFI_MOK_VARIABLE_TABLE_GUID \
  237. MAKE_EFI_GUID(0xc451ed2b, 0x9694, 0x45d3, 0xba, 0xba, 0xed, 0x9f, \
  238. 0x89, 0x88, 0xa3, 0x89)
  239. #define LINUX_EFI_COCO_SECRET_AREA_GUID \
  240. MAKE_EFI_GUID(0xadf956ad, 0xe98c, 0x484c, 0xae, 0x11, 0xb5, 0x1c, \
  241. 0x7d, 0x33, 0x64, 0x47)
  242. #define LINUX_EFI_BOOT_MEMMAP_GUID \
  243. MAKE_EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, 0x96, 0x5c, \
  244. 0x3c, 0x6f, 0xe2, 0xb4)
  245. #define LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID \
  246. MAKE_EFI_GUID(0xd5d1de3c, 0x105c, 0x44f9, 0x9e, 0xa9, 0xbc, 0xef, \
  247. 0x98, 0x12, 0x00, 0x31)
  248. #define RISCV_EFI_BOOT_PROTOCOL_GUID \
  249. MAKE_EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, 0x95, 0x3e, 0x69, \
  250. 0xe4, 0xb9, 0x40, 0xbf)
  251. #if defined(CONFIG_X86_64)
  252. #define __efiapi __attribute__((ms_abi))
  253. #elif defined(CONFIG_X86_32)
  254. #define __efiapi __attribute__((regparm(0)))
  255. #elif defined(CONFIG_riscv64)
  256. #define __efiapi
  257. #elif defined(CONFIG_aarch64)
  258. #define __efiapi
  259. #else
  260. #error "Unsupported architecture"
  261. #endif
  262. /*
  263. * EFI Device Path information
  264. */
  265. #define EFI_DEV_HW 0x01
  266. #define EFI_DEV_PCI 1
  267. #define EFI_DEV_PCCARD 2
  268. #define EFI_DEV_MEM_MAPPED 3
  269. #define EFI_DEV_VENDOR 4
  270. #define EFI_DEV_CONTROLLER 5
  271. #define EFI_DEV_ACPI 0x02
  272. #define EFI_DEV_BASIC_ACPI 1
  273. #define EFI_DEV_EXPANDED_ACPI 2
  274. #define EFI_DEV_MSG 0x03
  275. #define EFI_DEV_MSG_ATAPI 1
  276. #define EFI_DEV_MSG_SCSI 2
  277. #define EFI_DEV_MSG_FC 3
  278. #define EFI_DEV_MSG_1394 4
  279. #define EFI_DEV_MSG_USB 5
  280. #define EFI_DEV_MSG_USB_CLASS 15
  281. #define EFI_DEV_MSG_I20 6
  282. #define EFI_DEV_MSG_MAC 11
  283. #define EFI_DEV_MSG_IPV4 12
  284. #define EFI_DEV_MSG_IPV6 13
  285. #define EFI_DEV_MSG_INFINIBAND 9
  286. #define EFI_DEV_MSG_UART 14
  287. #define EFI_DEV_MSG_VENDOR 10
  288. #define EFI_DEV_MEDIA 0x04
  289. #define EFI_DEV_MEDIA_HARD_DRIVE 1
  290. #define EFI_DEV_MEDIA_CDROM 2
  291. #define EFI_DEV_MEDIA_VENDOR 3
  292. #define EFI_DEV_MEDIA_FILE 4
  293. #define EFI_DEV_MEDIA_PROTOCOL 5
  294. #define EFI_DEV_MEDIA_REL_OFFSET 8
  295. #define EFI_DEV_BIOS_BOOT 0x05
  296. #define EFI_DEV_END_PATH 0x7F
  297. #define EFI_DEV_END_PATH2 0xFF
  298. #define EFI_DEV_END_INSTANCE 0x01
  299. #define EFI_DEV_END_ENTIRE 0xFF
  300. struct efi_generic_dev_path {
  301. u8 type;
  302. u8 sub_type;
  303. u16 length;
  304. } __packed;
  305. struct efi_acpi_dev_path {
  306. struct efi_generic_dev_path header;
  307. u32 hid;
  308. u32 uid;
  309. } __packed;
  310. struct efi_pci_dev_path {
  311. struct efi_generic_dev_path header;
  312. u8 fn;
  313. u8 dev;
  314. } __packed;
  315. struct efi_vendor_dev_path {
  316. struct efi_generic_dev_path header;
  317. efi_guid_t vendorguid;
  318. u8 vendordata[];
  319. } __packed;
  320. struct efi_rel_offset_dev_path {
  321. struct efi_generic_dev_path header;
  322. u32 reserved;
  323. u64 starting_offset;
  324. u64 ending_offset;
  325. } __packed;
  326. struct efi_mem_mapped_dev_path {
  327. struct efi_generic_dev_path header;
  328. u32 memory_type;
  329. u64 starting_addr;
  330. u64 ending_addr;
  331. } __packed;
  332. struct efi_file_path_dev_path {
  333. struct efi_generic_dev_path header;
  334. efi_char16_t filename[];
  335. } __packed;
  336. struct efi_dev_path {
  337. union {
  338. struct efi_generic_dev_path header;
  339. struct efi_acpi_dev_path acpi;
  340. struct efi_pci_dev_path pci;
  341. struct efi_vendor_dev_path vendor;
  342. struct efi_rel_offset_dev_path rel_offset;
  343. };
  344. } __packed;
  345. // struct device *efi_get_device_by_path(const struct efi_dev_path **node,
  346. // size_t *len);
  347. static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
  348. {
  349. *npages = PFN_UP(*addr + (*npages << EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
  350. *addr &= PAGE_MASK;
  351. }
  352. struct linux_efi_memreserve {
  353. int size; // allocated size of the array
  354. int count; // number of entries used
  355. phys_addr_t next; // pa of next struct instance
  356. struct {
  357. phys_addr_t base;
  358. phys_addr_t size;
  359. } entry[];
  360. };
  361. #define EFI_MEMRESERVE_COUNT(size) \
  362. (((size) - sizeof(struct linux_efi_memreserve)) / \
  363. sizeof_field(struct linux_efi_memreserve, entry[0]))
  364. enum efi_secureboot_mode {
  365. efi_secureboot_mode_unset,
  366. efi_secureboot_mode_unknown,
  367. efi_secureboot_mode_disabled,
  368. efi_secureboot_mode_enabled,
  369. };
  370. /// @brief 打印efi_secureboot_mode
  371. void print_efi_secureboot_mode(enum efi_secureboot_mode mode);
  372. typedef efi_status_t efi_get_time_t(efi_time_t *tm, efi_time_cap_t *tc);
  373. typedef efi_status_t efi_set_time_t(efi_time_t *tm);
  374. typedef efi_status_t efi_get_wakeup_time_t(efi_bool_t *enabled,
  375. efi_bool_t *pending, efi_time_t *tm);
  376. typedef efi_status_t efi_set_wakeup_time_t(efi_bool_t enabled, efi_time_t *tm);
  377. typedef efi_status_t efi_get_variable_t(efi_char16_t *name, efi_guid_t *vendor,
  378. u32 *attr, unsigned long *data_size,
  379. void *data);
  380. typedef efi_status_t efi_get_next_variable_t(unsigned long *name_size,
  381. efi_char16_t *name,
  382. efi_guid_t *vendor);
  383. typedef efi_status_t efi_set_variable_t(efi_char16_t *name, efi_guid_t *vendor,
  384. u32 attr, unsigned long data_size,
  385. void *data);
  386. typedef efi_status_t efi_get_next_high_mono_count_t(u32 *count);
  387. typedef void efi_reset_system_t(int reset_type, efi_status_t status,
  388. unsigned long data_size, efi_char16_t *data);
  389. typedef efi_status_t efi_set_virtual_address_map_t(
  390. unsigned long memory_map_size, unsigned long descriptor_size,
  391. u32 descriptor_version, efi_memory_desc_t *virtual_map);
  392. typedef efi_status_t efi_query_variable_info_t(u32 attr, u64 *storage_space,
  393. u64 *remaining_space,
  394. u64 *max_variable_size);
  395. typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
  396. unsigned long count,
  397. unsigned long sg_list);
  398. typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
  399. unsigned long count,
  400. u64 *max_size, int *reset_type);
  401. typedef efi_status_t efi_query_variable_store_t(u32 attributes,
  402. unsigned long size,
  403. bool nonblocking);
  404. static inline enum efi_secureboot_mode
  405. efi_get_secureboot_mode(efi_get_variable_t *get_var)
  406. {
  407. u8 secboot, setupmode = 0;
  408. efi_status_t status;
  409. unsigned long size;
  410. size = sizeof(secboot);
  411. status = get_var(L"SecureBoot", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size,
  412. &secboot);
  413. if (status == EFI_NOT_FOUND)
  414. return efi_secureboot_mode_disabled;
  415. if (status != EFI_SUCCESS)
  416. return efi_secureboot_mode_unknown;
  417. size = sizeof(setupmode);
  418. get_var(L"SetupMode", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size,
  419. &setupmode);
  420. if (secboot == 0 || setupmode == 1)
  421. return efi_secureboot_mode_disabled;
  422. return efi_secureboot_mode_enabled;
  423. }
  424. struct efi_boot_memmap {
  425. unsigned long map_size;
  426. unsigned long desc_size;
  427. u32 desc_ver;
  428. unsigned long map_key;
  429. unsigned long buff_size;
  430. efi_memory_desc_t map[];
  431. };
  432. #define EFI_RT_SUPPORTED_GET_TIME 0x0001
  433. #define EFI_RT_SUPPORTED_SET_TIME 0x0002
  434. #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
  435. #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008
  436. #define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010
  437. #define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME 0x0020
  438. #define EFI_RT_SUPPORTED_SET_VARIABLE 0x0040
  439. #define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP 0x0080
  440. #define EFI_RT_SUPPORTED_CONVERT_POINTER 0x0100
  441. #define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT 0x0200
  442. #define EFI_RT_SUPPORTED_RESET_SYSTEM 0x0400
  443. #define EFI_RT_SUPPORTED_UPDATE_CAPSULE 0x0800
  444. #define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES 0x1000
  445. #define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO 0x2000
  446. #define EFI_RT_SUPPORTED_ALL 0x3fff
  447. #define EFI_RT_SUPPORTED_TIME_SERVICES 0x0003
  448. #define EFI_RT_SUPPORTED_WAKEUP_SERVICES 0x000c
  449. #define EFI_RT_SUPPORTED_VARIABLE_SERVICES 0x0070
  450. typedef struct {
  451. u32 version;
  452. u32 length;
  453. u64 memory_protection_attribute;
  454. } efi_properties_table_t;
  455. #define EFI_PROPERTIES_TABLE_VERSION 0x00010000
  456. #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
  457. typedef struct {
  458. u16 version;
  459. u16 length;
  460. u32 runtime_services_supported;
  461. } efi_rt_properties_table_t;
  462. #define EFI_RT_PROPERTIES_TABLE_VERSION 0x1
  463. #define EFI_INVALID_TABLE_ADDR (~0UL)
  464. // BIT0 implies that Runtime code includes the forward control flow guard
  465. // instruction, such as X86 CET-IBT or ARM BTI.
  466. #define EFI_MEMORY_ATTRIBUTES_FLAGS_RT_FORWARD_CONTROL_FLOW_GUARD 0x1