efi.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_EFI_H
  3. #define _LINUX_EFI_H
  4. /*
  5. * Extensible Firmware Interface
  6. * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
  7. *
  8. * Copyright (C) 1999 VA Linux Systems
  9. * Copyright (C) 1999 Walt Drummond <[email protected]>
  10. * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
  11. * David Mosberger-Tang <[email protected]>
  12. * Stephane Eranian <[email protected]>
  13. */
  14. #include <linux/init.h>
  15. #include <linux/string.h>
  16. #include <linux/time.h>
  17. #include <linux/types.h>
  18. #include <linux/proc_fs.h>
  19. #include <linux/rtc.h>
  20. #include <linux/ioport.h>
  21. #include <linux/pfn.h>
  22. #include <linux/pstore.h>
  23. #include <linux/range.h>
  24. #include <linux/reboot.h>
  25. #include <linux/uuid.h>
  26. #include <linux/screen_info.h>
  27. #include <asm/page.h>
  28. #define EFI_SUCCESS 0
  29. #define EFI_LOAD_ERROR ( 1 | (1UL << (BITS_PER_LONG-1)))
  30. #define EFI_INVALID_PARAMETER ( 2 | (1UL << (BITS_PER_LONG-1)))
  31. #define EFI_UNSUPPORTED ( 3 | (1UL << (BITS_PER_LONG-1)))
  32. #define EFI_BAD_BUFFER_SIZE ( 4 | (1UL << (BITS_PER_LONG-1)))
  33. #define EFI_BUFFER_TOO_SMALL ( 5 | (1UL << (BITS_PER_LONG-1)))
  34. #define EFI_NOT_READY ( 6 | (1UL << (BITS_PER_LONG-1)))
  35. #define EFI_DEVICE_ERROR ( 7 | (1UL << (BITS_PER_LONG-1)))
  36. #define EFI_WRITE_PROTECTED ( 8 | (1UL << (BITS_PER_LONG-1)))
  37. #define EFI_OUT_OF_RESOURCES ( 9 | (1UL << (BITS_PER_LONG-1)))
  38. #define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG-1)))
  39. #define EFI_TIMEOUT (18 | (1UL << (BITS_PER_LONG-1)))
  40. #define EFI_ABORTED (21 | (1UL << (BITS_PER_LONG-1)))
  41. #define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG-1)))
  42. typedef unsigned long efi_status_t;
  43. typedef u8 efi_bool_t;
  44. typedef u16 efi_char16_t; /* UNICODE character */
  45. typedef u64 efi_physical_addr_t;
  46. typedef void *efi_handle_t;
  47. #if defined(CONFIG_X86_64)
  48. #define __efiapi __attribute__((ms_abi))
  49. #elif defined(CONFIG_X86_32)
  50. #define __efiapi __attribute__((regparm(0)))
  51. #else
  52. #define __efiapi
  53. #endif
  54. /*
  55. * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
  56. * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
  57. * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
  58. * this means that firmware services invoked by the kernel may assume that
  59. * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
  60. * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
  61. *
  62. * Note that the UEFI spec as well as some comments in the EDK2 code base
  63. * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
  64. * a mistake, given that no code seems to exist that actually enforces that
  65. * or relies on it.
  66. */
  67. typedef guid_t efi_guid_t __aligned(__alignof__(u32));
  68. #define EFI_GUID(a, b, c, d...) (efi_guid_t){ { \
  69. (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
  70. (b) & 0xff, ((b) >> 8) & 0xff, \
  71. (c) & 0xff, ((c) >> 8) & 0xff, d } }
  72. /*
  73. * Generic EFI table header
  74. */
  75. typedef struct {
  76. u64 signature;
  77. u32 revision;
  78. u32 headersize;
  79. u32 crc32;
  80. u32 reserved;
  81. } efi_table_hdr_t;
  82. /*
  83. * Memory map descriptor:
  84. */
  85. /* Memory types: */
  86. #define EFI_RESERVED_TYPE 0
  87. #define EFI_LOADER_CODE 1
  88. #define EFI_LOADER_DATA 2
  89. #define EFI_BOOT_SERVICES_CODE 3
  90. #define EFI_BOOT_SERVICES_DATA 4
  91. #define EFI_RUNTIME_SERVICES_CODE 5
  92. #define EFI_RUNTIME_SERVICES_DATA 6
  93. #define EFI_CONVENTIONAL_MEMORY 7
  94. #define EFI_UNUSABLE_MEMORY 8
  95. #define EFI_ACPI_RECLAIM_MEMORY 9
  96. #define EFI_ACPI_MEMORY_NVS 10
  97. #define EFI_MEMORY_MAPPED_IO 11
  98. #define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
  99. #define EFI_PAL_CODE 13
  100. #define EFI_PERSISTENT_MEMORY 14
  101. #define EFI_MAX_MEMORY_TYPE 15
  102. /* Attribute values: */
  103. #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
  104. #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
  105. #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
  106. #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
  107. #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
  108. #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
  109. #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
  110. #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
  111. #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
  112. #define EFI_MEMORY_MORE_RELIABLE \
  113. ((u64)0x0000000000010000ULL) /* higher reliability */
  114. #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
  115. #define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* soft reserved */
  116. #define EFI_MEMORY_CPU_CRYPTO ((u64)0x0000000000080000ULL) /* supports encryption */
  117. #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
  118. #define EFI_MEMORY_DESCRIPTOR_VERSION 1
  119. #define EFI_PAGE_SHIFT 12
  120. #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
  121. #define EFI_PAGES_MAX (U64_MAX >> EFI_PAGE_SHIFT)
  122. typedef struct {
  123. u32 type;
  124. u32 pad;
  125. u64 phys_addr;
  126. u64 virt_addr;
  127. u64 num_pages;
  128. u64 attribute;
  129. } efi_memory_desc_t;
  130. typedef struct {
  131. efi_guid_t guid;
  132. u32 headersize;
  133. u32 flags;
  134. u32 imagesize;
  135. } efi_capsule_header_t;
  136. /* EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER */
  137. struct efi_manage_capsule_header {
  138. u32 ver;
  139. u16 emb_drv_cnt;
  140. u16 payload_cnt;
  141. /*
  142. * Variable-size array of the size given by the sum of
  143. * emb_drv_cnt and payload_cnt.
  144. */
  145. u64 offset_list[];
  146. } __packed;
  147. /* EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER */
  148. struct efi_manage_capsule_image_header {
  149. u32 ver;
  150. efi_guid_t image_type_id;
  151. u8 image_index;
  152. u8 reserved_bytes[3];
  153. u32 image_size;
  154. u32 vendor_code_size;
  155. /* hw_ins was introduced in version 2 */
  156. u64 hw_ins;
  157. /* capsule_support was introduced in version 3 */
  158. u64 capsule_support;
  159. } __packed;
  160. /* WIN_CERTIFICATE */
  161. struct win_cert {
  162. u32 len;
  163. u16 rev;
  164. u16 cert_type;
  165. };
  166. /* WIN_CERTIFICATE_UEFI_GUID */
  167. struct win_cert_uefi_guid {
  168. struct win_cert hdr;
  169. efi_guid_t cert_type;
  170. u8 cert_data[];
  171. };
  172. /* EFI_FIRMWARE_IMAGE_AUTHENTICATION */
  173. struct efi_image_auth {
  174. u64 mon_count;
  175. struct win_cert_uefi_guid auth_info;
  176. };
  177. /*
  178. * EFI capsule flags
  179. */
  180. #define EFI_CAPSULE_PERSIST_ACROSS_RESET 0x00010000
  181. #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE 0x00020000
  182. #define EFI_CAPSULE_INITIATE_RESET 0x00040000
  183. struct capsule_info {
  184. efi_capsule_header_t header;
  185. efi_capsule_header_t *capsule;
  186. int reset_type;
  187. long index;
  188. size_t count;
  189. size_t total_size;
  190. struct page **pages;
  191. phys_addr_t *phys;
  192. size_t page_bytes_remain;
  193. };
  194. int efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff,
  195. size_t hdr_bytes);
  196. int __efi_capsule_setup_info(struct capsule_info *cap_info);
  197. /*
  198. * Types and defines for Time Services
  199. */
  200. #define EFI_TIME_ADJUST_DAYLIGHT 0x1
  201. #define EFI_TIME_IN_DAYLIGHT 0x2
  202. #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
  203. typedef struct {
  204. u16 year;
  205. u8 month;
  206. u8 day;
  207. u8 hour;
  208. u8 minute;
  209. u8 second;
  210. u8 pad1;
  211. u32 nanosecond;
  212. s16 timezone;
  213. u8 daylight;
  214. u8 pad2;
  215. } efi_time_t;
  216. typedef struct {
  217. u32 resolution;
  218. u32 accuracy;
  219. u8 sets_to_zero;
  220. } efi_time_cap_t;
  221. typedef union efi_boot_services efi_boot_services_t;
  222. /*
  223. * Types and defines for EFI ResetSystem
  224. */
  225. #define EFI_RESET_COLD 0
  226. #define EFI_RESET_WARM 1
  227. #define EFI_RESET_SHUTDOWN 2
  228. /*
  229. * EFI Runtime Services table
  230. */
  231. #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
  232. #define EFI_RUNTIME_SERVICES_REVISION 0x00010000
  233. typedef struct {
  234. efi_table_hdr_t hdr;
  235. u32 get_time;
  236. u32 set_time;
  237. u32 get_wakeup_time;
  238. u32 set_wakeup_time;
  239. u32 set_virtual_address_map;
  240. u32 convert_pointer;
  241. u32 get_variable;
  242. u32 get_next_variable;
  243. u32 set_variable;
  244. u32 get_next_high_mono_count;
  245. u32 reset_system;
  246. u32 update_capsule;
  247. u32 query_capsule_caps;
  248. u32 query_variable_info;
  249. } efi_runtime_services_32_t;
  250. typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
  251. typedef efi_status_t efi_set_time_t (efi_time_t *tm);
  252. typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
  253. efi_time_t *tm);
  254. typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
  255. typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
  256. unsigned long *data_size, void *data);
  257. typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
  258. efi_guid_t *vendor);
  259. typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
  260. u32 attr, unsigned long data_size,
  261. void *data);
  262. typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
  263. typedef void efi_reset_system_t (int reset_type, efi_status_t status,
  264. unsigned long data_size, efi_char16_t *data);
  265. typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
  266. unsigned long descriptor_size,
  267. u32 descriptor_version,
  268. efi_memory_desc_t *virtual_map);
  269. typedef efi_status_t efi_query_variable_info_t(u32 attr,
  270. u64 *storage_space,
  271. u64 *remaining_space,
  272. u64 *max_variable_size);
  273. typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
  274. unsigned long count,
  275. unsigned long sg_list);
  276. typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
  277. unsigned long count,
  278. u64 *max_size,
  279. int *reset_type);
  280. typedef efi_status_t efi_query_variable_store_t(u32 attributes,
  281. unsigned long size,
  282. bool nonblocking);
  283. typedef union {
  284. struct {
  285. efi_table_hdr_t hdr;
  286. efi_get_time_t __efiapi *get_time;
  287. efi_set_time_t __efiapi *set_time;
  288. efi_get_wakeup_time_t __efiapi *get_wakeup_time;
  289. efi_set_wakeup_time_t __efiapi *set_wakeup_time;
  290. efi_set_virtual_address_map_t __efiapi *set_virtual_address_map;
  291. void *convert_pointer;
  292. efi_get_variable_t __efiapi *get_variable;
  293. efi_get_next_variable_t __efiapi *get_next_variable;
  294. efi_set_variable_t __efiapi *set_variable;
  295. efi_get_next_high_mono_count_t __efiapi *get_next_high_mono_count;
  296. efi_reset_system_t __efiapi *reset_system;
  297. efi_update_capsule_t __efiapi *update_capsule;
  298. efi_query_capsule_caps_t __efiapi *query_capsule_caps;
  299. efi_query_variable_info_t __efiapi *query_variable_info;
  300. };
  301. efi_runtime_services_32_t mixed_mode;
  302. } efi_runtime_services_t;
  303. void efi_native_runtime_setup(void);
  304. /*
  305. * EFI Configuration Table and GUID definitions
  306. *
  307. * These are all defined in a single line to make them easier to
  308. * grep for and to see them at a glance - while still having a
  309. * similar structure to the definitions in the spec.
  310. *
  311. * Here's how they are structured:
  312. *
  313. * GUID: 12345678-1234-1234-1234-123456789012
  314. * Spec:
  315. * #define EFI_SOME_PROTOCOL_GUID \
  316. * {0x12345678,0x1234,0x1234,\
  317. * {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
  318. * Here:
  319. * #define SOME_PROTOCOL_GUID EFI_GUID(0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
  320. * ^ tabs ^extra space
  321. *
  322. * Note that the 'extra space' separates the values at the same place
  323. * where the UEFI SPEC breaks the line.
  324. */
  325. #define NULL_GUID EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
  326. #define MPS_TABLE_GUID EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  327. #define ACPI_TABLE_GUID EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  328. #define ACPI_20_TABLE_GUID EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
  329. #define SMBIOS_TABLE_GUID EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  330. #define SMBIOS3_TABLE_GUID EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
  331. #define SAL_SYSTEM_TABLE_GUID EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  332. #define HCDP_TABLE_GUID EFI_GUID(0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
  333. #define UGA_IO_PROTOCOL_GUID EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
  334. #define EFI_GLOBAL_VARIABLE_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
  335. #define UV_SYSTEM_TABLE_GUID EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
  336. #define LINUX_EFI_CRASH_GUID EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
  337. #define LOADED_IMAGE_PROTOCOL_GUID EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  338. #define LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf)
  339. #define EFI_DEVICE_PATH_PROTOCOL_GUID EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  340. #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID EFI_GUID(0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
  341. #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
  342. #define EFI_UGA_PROTOCOL_GUID EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
  343. #define EFI_PCI_IO_PROTOCOL_GUID EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
  344. #define EFI_FILE_INFO_ID EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  345. #define EFI_SYSTEM_RESOURCE_TABLE_GUID EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
  346. #define EFI_FILE_SYSTEM_GUID EFI_GUID(0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  347. #define DEVICE_TREE_GUID EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
  348. #define EFI_PROPERTIES_TABLE_GUID EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
  349. #define EFI_RNG_PROTOCOL_GUID EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
  350. #define EFI_RNG_ALGORITHM_RAW EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
  351. #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
  352. #define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  353. #define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
  354. #define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
  355. #define EFI_LOAD_FILE_PROTOCOL_GUID EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  356. #define EFI_LOAD_FILE2_PROTOCOL_GUID EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
  357. #define EFI_RT_PROPERTIES_TABLE_GUID EFI_GUID(0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9)
  358. #define EFI_DXE_SERVICES_TABLE_GUID EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
  359. #define EFI_SMBIOS_PROTOCOL_GUID EFI_GUID(0x03583ff6, 0xcb36, 0x4940, 0x94, 0x7e, 0xb9, 0xb3, 0x9f, 0x4a, 0xfa, 0xf7)
  360. #define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
  361. #define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
  362. #define EFI_CERT_SHA256_GUID EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)
  363. #define EFI_CERT_X509_GUID EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)
  364. #define EFI_CERT_X509_SHA256_GUID EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
  365. #define EFI_CC_BLOB_GUID EFI_GUID(0x067b1f5f, 0xcf26, 0x44c5, 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42)
  366. /*
  367. * This GUID is used to pass to the kernel proper the struct screen_info
  368. * structure that was populated by the stub based on the GOP protocol instance
  369. * associated with ConOut
  370. */
  371. #define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, 0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
  372. #define LINUX_EFI_ARM_CPU_STATE_TABLE_GUID EFI_GUID(0xef79e4aa, 0x3c3d, 0x4989, 0xb9, 0x02, 0x07, 0xa9, 0x43, 0xe5, 0x50, 0xd2)
  373. #define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
  374. #define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b)
  375. #define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa)
  376. #define LINUX_EFI_TPM_FINAL_LOG_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25)
  377. #define LINUX_EFI_MEMRESERVE_TABLE_GUID EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2)
  378. #define LINUX_EFI_INITRD_MEDIA_GUID EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
  379. #define LINUX_EFI_ZBOOT_MEDIA_GUID EFI_GUID(0xe565a30d, 0x47da, 0x4dbd, 0xb3, 0x54, 0x9b, 0xb5, 0xc8, 0x4f, 0x8b, 0xe2)
  380. #define LINUX_EFI_MOK_VARIABLE_TABLE_GUID EFI_GUID(0xc451ed2b, 0x9694, 0x45d3, 0xba, 0xba, 0xed, 0x9f, 0x89, 0x88, 0xa3, 0x89)
  381. #define LINUX_EFI_COCO_SECRET_AREA_GUID EFI_GUID(0xadf956ad, 0xe98c, 0x484c, 0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47)
  382. #define LINUX_EFI_BOOT_MEMMAP_GUID EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
  383. #define RISCV_EFI_BOOT_PROTOCOL_GUID EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf)
  384. /*
  385. * This GUID may be installed onto the kernel image's handle as a NULL protocol
  386. * to signal to the stub that the placement of the image should be respected,
  387. * and moving the image in physical memory is undesirable. To ensure
  388. * compatibility with 64k pages kernels with virtually mapped stacks, and to
  389. * avoid defeating physical randomization, this protocol should only be
  390. * installed if the image was placed at a randomized 128k aligned address in
  391. * memory.
  392. */
  393. #define LINUX_EFI_LOADED_IMAGE_FIXED_GUID EFI_GUID(0xf5a37b6d, 0x3344, 0x42a5, 0xb6, 0xbb, 0x97, 0x86, 0x48, 0xc1, 0x89, 0x0a)
  394. /* OEM GUIDs */
  395. #define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55)
  396. #define AMD_SEV_MEM_ENCRYPT_GUID EFI_GUID(0x0cf29b71, 0x9e51, 0x433a, 0xa3, 0xb7, 0x81, 0xf3, 0xab, 0x16, 0xb8, 0x75)
  397. typedef struct {
  398. efi_guid_t guid;
  399. u64 table;
  400. } efi_config_table_64_t;
  401. typedef struct {
  402. efi_guid_t guid;
  403. u32 table;
  404. } efi_config_table_32_t;
  405. typedef union {
  406. struct {
  407. efi_guid_t guid;
  408. void *table;
  409. };
  410. efi_config_table_32_t mixed_mode;
  411. } efi_config_table_t;
  412. typedef struct {
  413. efi_guid_t guid;
  414. unsigned long *ptr;
  415. const char name[16];
  416. } efi_config_table_type_t;
  417. #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
  418. #define EFI_DXE_SERVICES_TABLE_SIGNATURE ((u64)0x565245535f455844ULL)
  419. #define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
  420. #define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20))
  421. #define EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10))
  422. #define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00))
  423. #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10))
  424. #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02))
  425. typedef struct {
  426. efi_table_hdr_t hdr;
  427. u64 fw_vendor; /* physical addr of CHAR16 vendor string */
  428. u32 fw_revision;
  429. u32 __pad1;
  430. u64 con_in_handle;
  431. u64 con_in;
  432. u64 con_out_handle;
  433. u64 con_out;
  434. u64 stderr_handle;
  435. u64 stderr;
  436. u64 runtime;
  437. u64 boottime;
  438. u32 nr_tables;
  439. u32 __pad2;
  440. u64 tables;
  441. } efi_system_table_64_t;
  442. typedef struct {
  443. efi_table_hdr_t hdr;
  444. u32 fw_vendor; /* physical addr of CHAR16 vendor string */
  445. u32 fw_revision;
  446. u32 con_in_handle;
  447. u32 con_in;
  448. u32 con_out_handle;
  449. u32 con_out;
  450. u32 stderr_handle;
  451. u32 stderr;
  452. u32 runtime;
  453. u32 boottime;
  454. u32 nr_tables;
  455. u32 tables;
  456. } efi_system_table_32_t;
  457. typedef union efi_simple_text_input_protocol efi_simple_text_input_protocol_t;
  458. typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t;
  459. typedef union {
  460. struct {
  461. efi_table_hdr_t hdr;
  462. unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
  463. u32 fw_revision;
  464. unsigned long con_in_handle;
  465. efi_simple_text_input_protocol_t *con_in;
  466. unsigned long con_out_handle;
  467. efi_simple_text_output_protocol_t *con_out;
  468. unsigned long stderr_handle;
  469. unsigned long stderr;
  470. efi_runtime_services_t *runtime;
  471. efi_boot_services_t *boottime;
  472. unsigned long nr_tables;
  473. unsigned long tables;
  474. };
  475. efi_system_table_32_t mixed_mode;
  476. } efi_system_table_t;
  477. struct efi_boot_memmap {
  478. unsigned long map_size;
  479. unsigned long desc_size;
  480. u32 desc_ver;
  481. unsigned long map_key;
  482. unsigned long buff_size;
  483. efi_memory_desc_t map[];
  484. };
  485. /*
  486. * Architecture independent structure for describing a memory map for the
  487. * benefit of efi_memmap_init_early(), and for passing context between
  488. * efi_memmap_alloc() and efi_memmap_install().
  489. */
  490. struct efi_memory_map_data {
  491. phys_addr_t phys_map;
  492. unsigned long size;
  493. unsigned long desc_version;
  494. unsigned long desc_size;
  495. unsigned long flags;
  496. };
  497. struct efi_memory_map {
  498. phys_addr_t phys_map;
  499. void *map;
  500. void *map_end;
  501. int nr_map;
  502. unsigned long desc_version;
  503. unsigned long desc_size;
  504. #define EFI_MEMMAP_LATE (1UL << 0)
  505. #define EFI_MEMMAP_MEMBLOCK (1UL << 1)
  506. #define EFI_MEMMAP_SLAB (1UL << 2)
  507. unsigned long flags;
  508. };
  509. struct efi_mem_range {
  510. struct range range;
  511. u64 attribute;
  512. };
  513. typedef struct {
  514. u32 version;
  515. u32 length;
  516. u64 memory_protection_attribute;
  517. } efi_properties_table_t;
  518. #define EFI_PROPERTIES_TABLE_VERSION 0x00010000
  519. #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
  520. typedef struct {
  521. u16 version;
  522. u16 length;
  523. u32 runtime_services_supported;
  524. } efi_rt_properties_table_t;
  525. #define EFI_RT_PROPERTIES_TABLE_VERSION 0x1
  526. #define EFI_INVALID_TABLE_ADDR (~0UL)
  527. typedef struct {
  528. u32 version;
  529. u32 num_entries;
  530. u32 desc_size;
  531. u32 reserved;
  532. efi_memory_desc_t entry[0];
  533. } efi_memory_attributes_table_t;
  534. typedef struct {
  535. efi_guid_t signature_owner;
  536. u8 signature_data[];
  537. } efi_signature_data_t;
  538. typedef struct {
  539. efi_guid_t signature_type;
  540. u32 signature_list_size;
  541. u32 signature_header_size;
  542. u32 signature_size;
  543. u8 signature_header[];
  544. /* efi_signature_data_t signatures[][] */
  545. } efi_signature_list_t;
  546. typedef u8 efi_sha256_hash_t[32];
  547. typedef struct {
  548. efi_sha256_hash_t to_be_signed_hash;
  549. efi_time_t time_of_revocation;
  550. } efi_cert_x509_sha256_t;
  551. extern unsigned long __ro_after_init efi_rng_seed; /* RNG Seed table */
  552. /*
  553. * All runtime access to EFI goes through this structure:
  554. */
  555. extern struct efi {
  556. const efi_runtime_services_t *runtime; /* EFI runtime services table */
  557. unsigned int runtime_version; /* Runtime services version */
  558. unsigned int runtime_supported_mask;
  559. unsigned long acpi; /* ACPI table (IA64 ext 0.71) */
  560. unsigned long acpi20; /* ACPI table (ACPI 2.0) */
  561. unsigned long smbios; /* SMBIOS table (32 bit entry point) */
  562. unsigned long smbios3; /* SMBIOS table (64 bit entry point) */
  563. unsigned long esrt; /* ESRT table */
  564. unsigned long tpm_log; /* TPM2 Event Log table */
  565. unsigned long tpm_final_log; /* TPM2 Final Events Log table */
  566. unsigned long mokvar_table; /* MOK variable config table */
  567. unsigned long coco_secret; /* Confidential computing secret table */
  568. efi_get_time_t *get_time;
  569. efi_set_time_t *set_time;
  570. efi_get_wakeup_time_t *get_wakeup_time;
  571. efi_set_wakeup_time_t *set_wakeup_time;
  572. efi_get_variable_t *get_variable;
  573. efi_get_next_variable_t *get_next_variable;
  574. efi_set_variable_t *set_variable;
  575. efi_set_variable_t *set_variable_nonblocking;
  576. efi_query_variable_info_t *query_variable_info;
  577. efi_query_variable_info_t *query_variable_info_nonblocking;
  578. efi_update_capsule_t *update_capsule;
  579. efi_query_capsule_caps_t *query_capsule_caps;
  580. efi_get_next_high_mono_count_t *get_next_high_mono_count;
  581. efi_reset_system_t *reset_system;
  582. struct efi_memory_map memmap;
  583. unsigned long flags;
  584. } efi;
  585. #define EFI_RT_SUPPORTED_GET_TIME 0x0001
  586. #define EFI_RT_SUPPORTED_SET_TIME 0x0002
  587. #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
  588. #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008
  589. #define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010
  590. #define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME 0x0020
  591. #define EFI_RT_SUPPORTED_SET_VARIABLE 0x0040
  592. #define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP 0x0080
  593. #define EFI_RT_SUPPORTED_CONVERT_POINTER 0x0100
  594. #define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT 0x0200
  595. #define EFI_RT_SUPPORTED_RESET_SYSTEM 0x0400
  596. #define EFI_RT_SUPPORTED_UPDATE_CAPSULE 0x0800
  597. #define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES 0x1000
  598. #define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO 0x2000
  599. #define EFI_RT_SUPPORTED_ALL 0x3fff
  600. #define EFI_RT_SUPPORTED_TIME_SERVICES 0x0003
  601. #define EFI_RT_SUPPORTED_WAKEUP_SERVICES 0x000c
  602. #define EFI_RT_SUPPORTED_VARIABLE_SERVICES 0x0070
  603. extern struct mm_struct efi_mm;
  604. static inline int
  605. efi_guidcmp (efi_guid_t left, efi_guid_t right)
  606. {
  607. return memcmp(&left, &right, sizeof (efi_guid_t));
  608. }
  609. static inline char *
  610. efi_guid_to_str(efi_guid_t *guid, char *out)
  611. {
  612. sprintf(out, "%pUl", guid->b);
  613. return out;
  614. }
  615. extern void efi_init (void);
  616. #ifdef CONFIG_EFI
  617. extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
  618. #else
  619. static inline void efi_enter_virtual_mode (void) {}
  620. #endif
  621. #ifdef CONFIG_X86
  622. extern efi_status_t efi_query_variable_store(u32 attributes,
  623. unsigned long size,
  624. bool nonblocking);
  625. #else
  626. static inline efi_status_t efi_query_variable_store(u32 attributes,
  627. unsigned long size,
  628. bool nonblocking)
  629. {
  630. return EFI_SUCCESS;
  631. }
  632. #endif
  633. extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
  634. extern int __init efi_memmap_alloc(unsigned int num_entries,
  635. struct efi_memory_map_data *data);
  636. extern void __efi_memmap_free(u64 phys, unsigned long size,
  637. unsigned long flags);
  638. extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
  639. extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
  640. extern void __init efi_memmap_unmap(void);
  641. extern int __init efi_memmap_install(struct efi_memory_map_data *data);
  642. extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
  643. struct range *range);
  644. extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,
  645. void *buf, struct efi_mem_range *mem);
  646. #ifdef CONFIG_EFI_ESRT
  647. extern void __init efi_esrt_init(void);
  648. #else
  649. static inline void efi_esrt_init(void) { }
  650. #endif
  651. extern int efi_config_parse_tables(const efi_config_table_t *config_tables,
  652. int count,
  653. const efi_config_table_type_t *arch_tables);
  654. extern int efi_systab_check_header(const efi_table_hdr_t *systab_hdr,
  655. int min_major_version);
  656. extern void efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
  657. unsigned long fw_vendor);
  658. extern u64 efi_get_iobase (void);
  659. extern int efi_mem_type(unsigned long phys_addr);
  660. extern u64 efi_mem_attributes (unsigned long phys_addr);
  661. extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
  662. extern int __init efi_uart_console_only (void);
  663. extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
  664. extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
  665. extern void efi_mem_reserve(phys_addr_t addr, u64 size);
  666. extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size);
  667. extern void efi_initialize_iomem_resources(struct resource *code_resource,
  668. struct resource *data_resource, struct resource *bss_resource);
  669. extern u64 efi_get_fdt_params(struct efi_memory_map_data *data);
  670. extern struct kobject *efi_kobj;
  671. extern int efi_reboot_quirk_mode;
  672. extern bool efi_poweroff_required(void);
  673. #ifdef CONFIG_EFI_FAKE_MEMMAP
  674. extern void __init efi_fake_memmap(void);
  675. #else
  676. static inline void efi_fake_memmap(void) { }
  677. #endif
  678. extern unsigned long efi_mem_attr_table;
  679. /*
  680. * efi_memattr_perm_setter - arch specific callback function passed into
  681. * efi_memattr_apply_permissions() that updates the
  682. * mapping permissions described by the second
  683. * argument in the page tables referred to by the
  684. * first argument.
  685. */
  686. typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
  687. extern int efi_memattr_init(void);
  688. extern int efi_memattr_apply_permissions(struct mm_struct *mm,
  689. efi_memattr_perm_setter fn);
  690. /*
  691. * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
  692. * @map: the start of efi memmap
  693. * @desc_size: the size of space for each EFI memmap descriptor
  694. * @n: the index of efi memmap descriptor
  695. *
  696. * EFI boot service provides the GetMemoryMap() function to get a copy of the
  697. * current memory map which is an array of memory descriptors, each of
  698. * which describes a contiguous block of memory. It also gets the size of the
  699. * map, and the size of each descriptor, etc.
  700. *
  701. * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
  702. * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
  703. * since efi_memory_memdesc_t may be extended in the future. Thus the OS
  704. * MUST use the returned size of the descriptor to find the start of each
  705. * efi_memory_memdesc_t in the memory map array. This should only be used
  706. * during bootup since for_each_efi_memory_desc_xxx() is available after the
  707. * kernel initializes the EFI subsystem to set up struct efi_memory_map.
  708. */
  709. #define efi_early_memdesc_ptr(map, desc_size, n) \
  710. (efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
  711. /* Iterate through an efi_memory_map */
  712. #define for_each_efi_memory_desc_in_map(m, md) \
  713. for ((md) = (m)->map; \
  714. (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end; \
  715. (md) = (void *)(md) + (m)->desc_size)
  716. /**
  717. * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
  718. * @md: the efi_memory_desc_t * iterator
  719. *
  720. * Once the loop finishes @md must not be accessed.
  721. */
  722. #define for_each_efi_memory_desc(md) \
  723. for_each_efi_memory_desc_in_map(&efi.memmap, md)
  724. /*
  725. * Format an EFI memory descriptor's type and attributes to a user-provided
  726. * character buffer, as per snprintf(), and return the buffer.
  727. */
  728. char * __init efi_md_typeattr_format(char *buf, size_t size,
  729. const efi_memory_desc_t *md);
  730. typedef void (*efi_element_handler_t)(const char *source,
  731. const void *element_data,
  732. size_t element_size);
  733. extern int __init parse_efi_signature_list(
  734. const char *source,
  735. const void *data, size_t size,
  736. efi_element_handler_t (*get_handler_for_guid)(const efi_guid_t *));
  737. /**
  738. * efi_range_is_wc - check the WC bit on an address range
  739. * @start: starting kvirt address
  740. * @len: length of range
  741. *
  742. * Consult the EFI memory map and make sure it's ok to set this range WC.
  743. * Returns true or false.
  744. */
  745. static inline int efi_range_is_wc(unsigned long start, unsigned long len)
  746. {
  747. unsigned long i;
  748. for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
  749. unsigned long paddr = __pa(start + i);
  750. if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
  751. return 0;
  752. }
  753. /* The range checked out */
  754. return 1;
  755. }
  756. #ifdef CONFIG_EFI_PCDP
  757. extern int __init efi_setup_pcdp_console(char *);
  758. #endif
  759. /*
  760. * We play games with efi_enabled so that the compiler will, if
  761. * possible, remove EFI-related code altogether.
  762. */
  763. #define EFI_BOOT 0 /* Were we booted from EFI? */
  764. #define EFI_CONFIG_TABLES 2 /* Can we use EFI config tables? */
  765. #define EFI_RUNTIME_SERVICES 3 /* Can we use runtime services? */
  766. #define EFI_MEMMAP 4 /* Can we use EFI memory map? */
  767. #define EFI_64BIT 5 /* Is the firmware 64-bit? */
  768. #define EFI_PARAVIRT 6 /* Access is via a paravirt interface */
  769. #define EFI_ARCH_1 7 /* First arch-specific bit */
  770. #define EFI_DBG 8 /* Print additional debug info at runtime */
  771. #define EFI_NX_PE_DATA 9 /* Can runtime data regions be mapped non-executable? */
  772. #define EFI_MEM_ATTR 10 /* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
  773. #define EFI_MEM_NO_SOFT_RESERVE 11 /* Is the kernel configured to ignore soft reservations? */
  774. #define EFI_PRESERVE_BS_REGIONS 12 /* Are EFI boot-services memory segments available? */
  775. #ifdef CONFIG_EFI
  776. /*
  777. * Test whether the above EFI_* bits are enabled.
  778. */
  779. static inline bool efi_enabled(int feature)
  780. {
  781. return test_bit(feature, &efi.flags) != 0;
  782. }
  783. extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
  784. bool __pure __efi_soft_reserve_enabled(void);
  785. static inline bool __pure efi_soft_reserve_enabled(void)
  786. {
  787. return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE)
  788. && __efi_soft_reserve_enabled();
  789. }
  790. static inline bool efi_rt_services_supported(unsigned int mask)
  791. {
  792. return (efi.runtime_supported_mask & mask) == mask;
  793. }
  794. extern void efi_find_mirror(void);
  795. #else
  796. static inline bool efi_enabled(int feature)
  797. {
  798. return false;
  799. }
  800. static inline void
  801. efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
  802. static inline bool efi_soft_reserve_enabled(void)
  803. {
  804. return false;
  805. }
  806. static inline bool efi_rt_services_supported(unsigned int mask)
  807. {
  808. return false;
  809. }
  810. static inline void efi_find_mirror(void) {}
  811. #endif
  812. extern int efi_status_to_err(efi_status_t status);
  813. /*
  814. * Variable Attributes
  815. */
  816. #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
  817. #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
  818. #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
  819. #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
  820. #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
  821. #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
  822. #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
  823. #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
  824. EFI_VARIABLE_BOOTSERVICE_ACCESS | \
  825. EFI_VARIABLE_RUNTIME_ACCESS | \
  826. EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
  827. EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
  828. EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
  829. EFI_VARIABLE_APPEND_WRITE)
  830. /*
  831. * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
  832. * not including trailing NUL
  833. */
  834. #define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN
  835. /*
  836. * EFI Device Path information
  837. */
  838. #define EFI_DEV_HW 0x01
  839. #define EFI_DEV_PCI 1
  840. #define EFI_DEV_PCCARD 2
  841. #define EFI_DEV_MEM_MAPPED 3
  842. #define EFI_DEV_VENDOR 4
  843. #define EFI_DEV_CONTROLLER 5
  844. #define EFI_DEV_ACPI 0x02
  845. #define EFI_DEV_BASIC_ACPI 1
  846. #define EFI_DEV_EXPANDED_ACPI 2
  847. #define EFI_DEV_MSG 0x03
  848. #define EFI_DEV_MSG_ATAPI 1
  849. #define EFI_DEV_MSG_SCSI 2
  850. #define EFI_DEV_MSG_FC 3
  851. #define EFI_DEV_MSG_1394 4
  852. #define EFI_DEV_MSG_USB 5
  853. #define EFI_DEV_MSG_USB_CLASS 15
  854. #define EFI_DEV_MSG_I20 6
  855. #define EFI_DEV_MSG_MAC 11
  856. #define EFI_DEV_MSG_IPV4 12
  857. #define EFI_DEV_MSG_IPV6 13
  858. #define EFI_DEV_MSG_INFINIBAND 9
  859. #define EFI_DEV_MSG_UART 14
  860. #define EFI_DEV_MSG_VENDOR 10
  861. #define EFI_DEV_MEDIA 0x04
  862. #define EFI_DEV_MEDIA_HARD_DRIVE 1
  863. #define EFI_DEV_MEDIA_CDROM 2
  864. #define EFI_DEV_MEDIA_VENDOR 3
  865. #define EFI_DEV_MEDIA_FILE 4
  866. #define EFI_DEV_MEDIA_PROTOCOL 5
  867. #define EFI_DEV_MEDIA_REL_OFFSET 8
  868. #define EFI_DEV_BIOS_BOOT 0x05
  869. #define EFI_DEV_END_PATH 0x7F
  870. #define EFI_DEV_END_PATH2 0xFF
  871. #define EFI_DEV_END_INSTANCE 0x01
  872. #define EFI_DEV_END_ENTIRE 0xFF
  873. struct efi_generic_dev_path {
  874. u8 type;
  875. u8 sub_type;
  876. u16 length;
  877. } __packed;
  878. struct efi_acpi_dev_path {
  879. struct efi_generic_dev_path header;
  880. u32 hid;
  881. u32 uid;
  882. } __packed;
  883. struct efi_pci_dev_path {
  884. struct efi_generic_dev_path header;
  885. u8 fn;
  886. u8 dev;
  887. } __packed;
  888. struct efi_vendor_dev_path {
  889. struct efi_generic_dev_path header;
  890. efi_guid_t vendorguid;
  891. u8 vendordata[];
  892. } __packed;
  893. struct efi_rel_offset_dev_path {
  894. struct efi_generic_dev_path header;
  895. u32 reserved;
  896. u64 starting_offset;
  897. u64 ending_offset;
  898. } __packed;
  899. struct efi_mem_mapped_dev_path {
  900. struct efi_generic_dev_path header;
  901. u32 memory_type;
  902. u64 starting_addr;
  903. u64 ending_addr;
  904. } __packed;
  905. struct efi_dev_path {
  906. union {
  907. struct efi_generic_dev_path header;
  908. struct efi_acpi_dev_path acpi;
  909. struct efi_pci_dev_path pci;
  910. struct efi_vendor_dev_path vendor;
  911. struct efi_rel_offset_dev_path rel_offset;
  912. };
  913. } __packed;
  914. struct device *efi_get_device_by_path(const struct efi_dev_path **node,
  915. size_t *len);
  916. static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
  917. {
  918. *npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
  919. *addr &= PAGE_MASK;
  920. }
  921. /*
  922. * EFI Variable support.
  923. *
  924. * Different firmware drivers can expose their EFI-like variables using
  925. * the following.
  926. */
  927. struct efivar_operations {
  928. efi_get_variable_t *get_variable;
  929. efi_get_next_variable_t *get_next_variable;
  930. efi_set_variable_t *set_variable;
  931. efi_set_variable_t *set_variable_nonblocking;
  932. efi_query_variable_store_t *query_variable_store;
  933. };
  934. struct efivars {
  935. struct kset *kset;
  936. struct kobject *kobject;
  937. const struct efivar_operations *ops;
  938. };
  939. /*
  940. * The maximum size of VariableName + Data = 1024
  941. * Therefore, it's reasonable to save that much
  942. * space in each part of the structure,
  943. * and we use a page for reading/writing.
  944. */
  945. #define EFI_VAR_NAME_LEN 1024
  946. int efivars_register(struct efivars *efivars,
  947. const struct efivar_operations *ops,
  948. struct kobject *kobject);
  949. int efivars_unregister(struct efivars *efivars);
  950. struct kobject *efivars_kobject(void);
  951. int efivar_supports_writes(void);
  952. int efivar_lock(void);
  953. int efivar_trylock(void);
  954. void efivar_unlock(void);
  955. efi_status_t efivar_get_variable(efi_char16_t *name, efi_guid_t *vendor,
  956. u32 *attr, unsigned long *size, void *data);
  957. efi_status_t efivar_get_next_variable(unsigned long *name_size,
  958. efi_char16_t *name, efi_guid_t *vendor);
  959. efi_status_t efivar_set_variable_locked(efi_char16_t *name, efi_guid_t *vendor,
  960. u32 attr, unsigned long data_size,
  961. void *data, bool nonblocking);
  962. efi_status_t efivar_set_variable(efi_char16_t *name, efi_guid_t *vendor,
  963. u32 attr, unsigned long data_size, void *data);
  964. #if IS_ENABLED(CONFIG_EFI_CAPSULE_LOADER)
  965. extern bool efi_capsule_pending(int *reset_type);
  966. extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
  967. size_t size, int *reset);
  968. extern int efi_capsule_update(efi_capsule_header_t *capsule,
  969. phys_addr_t *pages);
  970. #else
  971. static inline bool efi_capsule_pending(int *reset_type) { return false; }
  972. #endif
  973. #ifdef CONFIG_EFI_RUNTIME_MAP
  974. int efi_runtime_map_init(struct kobject *);
  975. int efi_get_runtime_map_size(void);
  976. int efi_get_runtime_map_desc_size(void);
  977. int efi_runtime_map_copy(void *buf, size_t bufsz);
  978. #else
  979. static inline int efi_runtime_map_init(struct kobject *kobj)
  980. {
  981. return 0;
  982. }
  983. static inline int efi_get_runtime_map_size(void)
  984. {
  985. return 0;
  986. }
  987. static inline int efi_get_runtime_map_desc_size(void)
  988. {
  989. return 0;
  990. }
  991. static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
  992. {
  993. return 0;
  994. }
  995. #endif
  996. #ifdef CONFIG_EFI
  997. extern bool efi_runtime_disabled(void);
  998. #else
  999. static inline bool efi_runtime_disabled(void) { return true; }
  1000. #endif
  1001. extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
  1002. extern unsigned long efi_call_virt_save_flags(void);
  1003. enum efi_secureboot_mode {
  1004. efi_secureboot_mode_unset,
  1005. efi_secureboot_mode_unknown,
  1006. efi_secureboot_mode_disabled,
  1007. efi_secureboot_mode_enabled,
  1008. };
  1009. static inline
  1010. enum efi_secureboot_mode efi_get_secureboot_mode(efi_get_variable_t *get_var)
  1011. {
  1012. u8 secboot, setupmode = 0;
  1013. efi_status_t status;
  1014. unsigned long size;
  1015. size = sizeof(secboot);
  1016. status = get_var(L"SecureBoot", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size,
  1017. &secboot);
  1018. if (status == EFI_NOT_FOUND)
  1019. return efi_secureboot_mode_disabled;
  1020. if (status != EFI_SUCCESS)
  1021. return efi_secureboot_mode_unknown;
  1022. size = sizeof(setupmode);
  1023. get_var(L"SetupMode", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size, &setupmode);
  1024. if (secboot == 0 || setupmode == 1)
  1025. return efi_secureboot_mode_disabled;
  1026. return efi_secureboot_mode_enabled;
  1027. }
  1028. #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
  1029. void efi_check_for_embedded_firmwares(void);
  1030. #else
  1031. static inline void efi_check_for_embedded_firmwares(void) { }
  1032. #endif
  1033. #define arch_efi_call_virt(p, f, args...) ((p)->f(args))
  1034. /*
  1035. * Arch code can implement the following three template macros, avoiding
  1036. * reptition for the void/non-void return cases of {__,}efi_call_virt():
  1037. *
  1038. * * arch_efi_call_virt_setup()
  1039. *
  1040. * Sets up the environment for the call (e.g. switching page tables,
  1041. * allowing kernel-mode use of floating point, if required).
  1042. *
  1043. * * arch_efi_call_virt()
  1044. *
  1045. * Performs the call. The last expression in the macro must be the call
  1046. * itself, allowing the logic to be shared by the void and non-void
  1047. * cases.
  1048. *
  1049. * * arch_efi_call_virt_teardown()
  1050. *
  1051. * Restores the usual kernel environment once the call has returned.
  1052. */
  1053. #define efi_call_virt_pointer(p, f, args...) \
  1054. ({ \
  1055. efi_status_t __s; \
  1056. unsigned long __flags; \
  1057. \
  1058. arch_efi_call_virt_setup(); \
  1059. \
  1060. __flags = efi_call_virt_save_flags(); \
  1061. __s = arch_efi_call_virt(p, f, args); \
  1062. efi_call_virt_check_flags(__flags, __stringify(f)); \
  1063. \
  1064. arch_efi_call_virt_teardown(); \
  1065. \
  1066. __s; \
  1067. })
  1068. #define __efi_call_virt_pointer(p, f, args...) \
  1069. ({ \
  1070. unsigned long __flags; \
  1071. \
  1072. arch_efi_call_virt_setup(); \
  1073. \
  1074. __flags = efi_call_virt_save_flags(); \
  1075. arch_efi_call_virt(p, f, args); \
  1076. efi_call_virt_check_flags(__flags, __stringify(f)); \
  1077. \
  1078. arch_efi_call_virt_teardown(); \
  1079. })
  1080. #define EFI_RANDOM_SEED_SIZE 32U // BLAKE2S_HASH_SIZE
  1081. struct linux_efi_random_seed {
  1082. u32 size;
  1083. u8 bits[];
  1084. };
  1085. struct linux_efi_tpm_eventlog {
  1086. u32 size;
  1087. u32 final_events_preboot_size;
  1088. u8 version;
  1089. u8 log[];
  1090. };
  1091. extern int efi_tpm_eventlog_init(void);
  1092. struct efi_tcg2_final_events_table {
  1093. u64 version;
  1094. u64 nr_events;
  1095. u8 events[];
  1096. };
  1097. extern int efi_tpm_final_log_size;
  1098. extern unsigned long rci2_table_phys;
  1099. /*
  1100. * efi_runtime_service() function identifiers.
  1101. * "NONE" is used by efi_recover_from_page_fault() to check if the page
  1102. * fault happened while executing an efi runtime service.
  1103. */
  1104. enum efi_rts_ids {
  1105. EFI_NONE,
  1106. EFI_GET_TIME,
  1107. EFI_SET_TIME,
  1108. EFI_GET_WAKEUP_TIME,
  1109. EFI_SET_WAKEUP_TIME,
  1110. EFI_GET_VARIABLE,
  1111. EFI_GET_NEXT_VARIABLE,
  1112. EFI_SET_VARIABLE,
  1113. EFI_QUERY_VARIABLE_INFO,
  1114. EFI_GET_NEXT_HIGH_MONO_COUNT,
  1115. EFI_RESET_SYSTEM,
  1116. EFI_UPDATE_CAPSULE,
  1117. EFI_QUERY_CAPSULE_CAPS,
  1118. };
  1119. /*
  1120. * efi_runtime_work: Details of EFI Runtime Service work
  1121. * @arg<1-5>: EFI Runtime Service function arguments
  1122. * @status: Status of executing EFI Runtime Service
  1123. * @efi_rts_id: EFI Runtime Service function identifier
  1124. * @efi_rts_comp: Struct used for handling completions
  1125. */
  1126. struct efi_runtime_work {
  1127. void *arg1;
  1128. void *arg2;
  1129. void *arg3;
  1130. void *arg4;
  1131. void *arg5;
  1132. efi_status_t status;
  1133. struct work_struct work;
  1134. enum efi_rts_ids efi_rts_id;
  1135. struct completion efi_rts_comp;
  1136. };
  1137. extern struct efi_runtime_work efi_rts_work;
  1138. /* Workqueue to queue EFI Runtime Services */
  1139. extern struct workqueue_struct *efi_rts_wq;
  1140. struct linux_efi_memreserve {
  1141. int size; // allocated size of the array
  1142. atomic_t count; // number of entries used
  1143. phys_addr_t next; // pa of next struct instance
  1144. struct {
  1145. phys_addr_t base;
  1146. phys_addr_t size;
  1147. } entry[];
  1148. };
  1149. #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
  1150. / sizeof_field(struct linux_efi_memreserve, entry[0]))
  1151. void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size);
  1152. char *efi_systab_show_arch(char *str);
  1153. /*
  1154. * The LINUX_EFI_MOK_VARIABLE_TABLE_GUID config table can be provided
  1155. * to the kernel by an EFI boot loader. The table contains a packed
  1156. * sequence of these entries, one for each named MOK variable.
  1157. * The sequence is terminated by an entry with a completely NULL
  1158. * name and 0 data size.
  1159. */
  1160. struct efi_mokvar_table_entry {
  1161. char name[256];
  1162. u64 data_size;
  1163. u8 data[];
  1164. } __attribute((packed));
  1165. #ifdef CONFIG_LOAD_UEFI_KEYS
  1166. extern void __init efi_mokvar_table_init(void);
  1167. extern struct efi_mokvar_table_entry *efi_mokvar_entry_next(
  1168. struct efi_mokvar_table_entry **mokvar_entry);
  1169. extern struct efi_mokvar_table_entry *efi_mokvar_entry_find(const char *name);
  1170. #else
  1171. static inline void efi_mokvar_table_init(void) { }
  1172. static inline struct efi_mokvar_table_entry *efi_mokvar_entry_next(
  1173. struct efi_mokvar_table_entry **mokvar_entry)
  1174. {
  1175. return NULL;
  1176. }
  1177. static inline struct efi_mokvar_table_entry *efi_mokvar_entry_find(
  1178. const char *name)
  1179. {
  1180. return NULL;
  1181. }
  1182. #endif
  1183. extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
  1184. struct linux_efi_coco_secret_area {
  1185. u64 base_pa;
  1186. u64 size;
  1187. };
  1188. struct linux_efi_initrd {
  1189. unsigned long base;
  1190. unsigned long size;
  1191. };
  1192. /* Header of a populated EFI secret area */
  1193. #define EFI_SECRET_TABLE_HEADER_GUID EFI_GUID(0x1e74f542, 0x71dd, 0x4d66, 0x96, 0x3e, 0xef, 0x42, 0x87, 0xff, 0x17, 0x3b)
  1194. #endif /* _LINUX_EFI_H */