efi.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  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 <drummond@valinux.com>
  10. * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
  11. * David Mosberger-Tang <davidm@hpl.hp.com>
  12. * Stephane Eranian <eranian@hpl.hp.com>
  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_ABORTED (21 | (1UL << (BITS_PER_LONG-1)))
  40. #define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG-1)))
  41. typedef unsigned long efi_status_t;
  42. typedef u8 efi_bool_t;
  43. typedef u16 efi_char16_t; /* UNICODE character */
  44. typedef u64 efi_physical_addr_t;
  45. typedef void *efi_handle_t;
  46. typedef guid_t efi_guid_t;
  47. #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
  48. GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
  49. /*
  50. * Generic EFI table header
  51. */
  52. typedef struct {
  53. u64 signature;
  54. u32 revision;
  55. u32 headersize;
  56. u32 crc32;
  57. u32 reserved;
  58. } efi_table_hdr_t;
  59. /*
  60. * Memory map descriptor:
  61. */
  62. /* Memory types: */
  63. #define EFI_RESERVED_TYPE 0
  64. #define EFI_LOADER_CODE 1
  65. #define EFI_LOADER_DATA 2
  66. #define EFI_BOOT_SERVICES_CODE 3
  67. #define EFI_BOOT_SERVICES_DATA 4
  68. #define EFI_RUNTIME_SERVICES_CODE 5
  69. #define EFI_RUNTIME_SERVICES_DATA 6
  70. #define EFI_CONVENTIONAL_MEMORY 7
  71. #define EFI_UNUSABLE_MEMORY 8
  72. #define EFI_ACPI_RECLAIM_MEMORY 9
  73. #define EFI_ACPI_MEMORY_NVS 10
  74. #define EFI_MEMORY_MAPPED_IO 11
  75. #define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
  76. #define EFI_PAL_CODE 13
  77. #define EFI_PERSISTENT_MEMORY 14
  78. #define EFI_MAX_MEMORY_TYPE 15
  79. /* Attribute values: */
  80. #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
  81. #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
  82. #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
  83. #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
  84. #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
  85. #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
  86. #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
  87. #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
  88. #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
  89. #define EFI_MEMORY_MORE_RELIABLE \
  90. ((u64)0x0000000000010000ULL) /* higher reliability */
  91. #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
  92. #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
  93. #define EFI_MEMORY_DESCRIPTOR_VERSION 1
  94. #define EFI_PAGE_SHIFT 12
  95. #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
  96. #define EFI_PAGES_MAX (U64_MAX >> EFI_PAGE_SHIFT)
  97. typedef struct {
  98. u32 type;
  99. u32 pad;
  100. u64 phys_addr;
  101. u64 virt_addr;
  102. u64 num_pages;
  103. u64 attribute;
  104. } efi_memory_desc_t;
  105. typedef struct {
  106. efi_guid_t guid;
  107. u32 headersize;
  108. u32 flags;
  109. u32 imagesize;
  110. } efi_capsule_header_t;
  111. struct efi_boot_memmap {
  112. efi_memory_desc_t **map;
  113. unsigned long *map_size;
  114. unsigned long *desc_size;
  115. u32 *desc_ver;
  116. unsigned long *key_ptr;
  117. unsigned long *buff_size;
  118. };
  119. /*
  120. * EFI capsule flags
  121. */
  122. #define EFI_CAPSULE_PERSIST_ACROSS_RESET 0x00010000
  123. #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE 0x00020000
  124. #define EFI_CAPSULE_INITIATE_RESET 0x00040000
  125. struct capsule_info {
  126. efi_capsule_header_t header;
  127. efi_capsule_header_t *capsule;
  128. int reset_type;
  129. long index;
  130. size_t count;
  131. size_t total_size;
  132. struct page **pages;
  133. phys_addr_t *phys;
  134. size_t page_bytes_remain;
  135. };
  136. int __efi_capsule_setup_info(struct capsule_info *cap_info);
  137. /*
  138. * Allocation types for calls to boottime->allocate_pages.
  139. */
  140. #define EFI_ALLOCATE_ANY_PAGES 0
  141. #define EFI_ALLOCATE_MAX_ADDRESS 1
  142. #define EFI_ALLOCATE_ADDRESS 2
  143. #define EFI_MAX_ALLOCATE_TYPE 3
  144. typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
  145. /*
  146. * Types and defines for Time Services
  147. */
  148. #define EFI_TIME_ADJUST_DAYLIGHT 0x1
  149. #define EFI_TIME_IN_DAYLIGHT 0x2
  150. #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
  151. typedef struct {
  152. u16 year;
  153. u8 month;
  154. u8 day;
  155. u8 hour;
  156. u8 minute;
  157. u8 second;
  158. u8 pad1;
  159. u32 nanosecond;
  160. s16 timezone;
  161. u8 daylight;
  162. u8 pad2;
  163. } efi_time_t;
  164. typedef struct {
  165. u32 resolution;
  166. u32 accuracy;
  167. u8 sets_to_zero;
  168. } efi_time_cap_t;
  169. typedef struct {
  170. efi_table_hdr_t hdr;
  171. u32 raise_tpl;
  172. u32 restore_tpl;
  173. u32 allocate_pages;
  174. u32 free_pages;
  175. u32 get_memory_map;
  176. u32 allocate_pool;
  177. u32 free_pool;
  178. u32 create_event;
  179. u32 set_timer;
  180. u32 wait_for_event;
  181. u32 signal_event;
  182. u32 close_event;
  183. u32 check_event;
  184. u32 install_protocol_interface;
  185. u32 reinstall_protocol_interface;
  186. u32 uninstall_protocol_interface;
  187. u32 handle_protocol;
  188. u32 __reserved;
  189. u32 register_protocol_notify;
  190. u32 locate_handle;
  191. u32 locate_device_path;
  192. u32 install_configuration_table;
  193. u32 load_image;
  194. u32 start_image;
  195. u32 exit;
  196. u32 unload_image;
  197. u32 exit_boot_services;
  198. u32 get_next_monotonic_count;
  199. u32 stall;
  200. u32 set_watchdog_timer;
  201. u32 connect_controller;
  202. u32 disconnect_controller;
  203. u32 open_protocol;
  204. u32 close_protocol;
  205. u32 open_protocol_information;
  206. u32 protocols_per_handle;
  207. u32 locate_handle_buffer;
  208. u32 locate_protocol;
  209. u32 install_multiple_protocol_interfaces;
  210. u32 uninstall_multiple_protocol_interfaces;
  211. u32 calculate_crc32;
  212. u32 copy_mem;
  213. u32 set_mem;
  214. u32 create_event_ex;
  215. } __packed efi_boot_services_32_t;
  216. typedef struct {
  217. efi_table_hdr_t hdr;
  218. u64 raise_tpl;
  219. u64 restore_tpl;
  220. u64 allocate_pages;
  221. u64 free_pages;
  222. u64 get_memory_map;
  223. u64 allocate_pool;
  224. u64 free_pool;
  225. u64 create_event;
  226. u64 set_timer;
  227. u64 wait_for_event;
  228. u64 signal_event;
  229. u64 close_event;
  230. u64 check_event;
  231. u64 install_protocol_interface;
  232. u64 reinstall_protocol_interface;
  233. u64 uninstall_protocol_interface;
  234. u64 handle_protocol;
  235. u64 __reserved;
  236. u64 register_protocol_notify;
  237. u64 locate_handle;
  238. u64 locate_device_path;
  239. u64 install_configuration_table;
  240. u64 load_image;
  241. u64 start_image;
  242. u64 exit;
  243. u64 unload_image;
  244. u64 exit_boot_services;
  245. u64 get_next_monotonic_count;
  246. u64 stall;
  247. u64 set_watchdog_timer;
  248. u64 connect_controller;
  249. u64 disconnect_controller;
  250. u64 open_protocol;
  251. u64 close_protocol;
  252. u64 open_protocol_information;
  253. u64 protocols_per_handle;
  254. u64 locate_handle_buffer;
  255. u64 locate_protocol;
  256. u64 install_multiple_protocol_interfaces;
  257. u64 uninstall_multiple_protocol_interfaces;
  258. u64 calculate_crc32;
  259. u64 copy_mem;
  260. u64 set_mem;
  261. u64 create_event_ex;
  262. } __packed efi_boot_services_64_t;
  263. /*
  264. * EFI Boot Services table
  265. */
  266. typedef struct {
  267. efi_table_hdr_t hdr;
  268. void *raise_tpl;
  269. void *restore_tpl;
  270. efi_status_t (*allocate_pages)(int, int, unsigned long,
  271. efi_physical_addr_t *);
  272. efi_status_t (*free_pages)(efi_physical_addr_t, unsigned long);
  273. efi_status_t (*get_memory_map)(unsigned long *, void *, unsigned long *,
  274. unsigned long *, u32 *);
  275. efi_status_t (*allocate_pool)(int, unsigned long, void **);
  276. efi_status_t (*free_pool)(void *);
  277. void *create_event;
  278. void *set_timer;
  279. void *wait_for_event;
  280. void *signal_event;
  281. void *close_event;
  282. void *check_event;
  283. void *install_protocol_interface;
  284. void *reinstall_protocol_interface;
  285. void *uninstall_protocol_interface;
  286. efi_status_t (*handle_protocol)(efi_handle_t, efi_guid_t *, void **);
  287. void *__reserved;
  288. void *register_protocol_notify;
  289. efi_status_t (*locate_handle)(int, efi_guid_t *, void *,
  290. unsigned long *, efi_handle_t *);
  291. void *locate_device_path;
  292. efi_status_t (*install_configuration_table)(efi_guid_t *, void *);
  293. void *load_image;
  294. void *start_image;
  295. void *exit;
  296. void *unload_image;
  297. efi_status_t (*exit_boot_services)(efi_handle_t, unsigned long);
  298. void *get_next_monotonic_count;
  299. void *stall;
  300. void *set_watchdog_timer;
  301. void *connect_controller;
  302. void *disconnect_controller;
  303. void *open_protocol;
  304. void *close_protocol;
  305. void *open_protocol_information;
  306. void *protocols_per_handle;
  307. void *locate_handle_buffer;
  308. efi_status_t (*locate_protocol)(efi_guid_t *, void *, void **);
  309. void *install_multiple_protocol_interfaces;
  310. void *uninstall_multiple_protocol_interfaces;
  311. void *calculate_crc32;
  312. void *copy_mem;
  313. void *set_mem;
  314. void *create_event_ex;
  315. } efi_boot_services_t;
  316. typedef enum {
  317. EfiPciIoWidthUint8,
  318. EfiPciIoWidthUint16,
  319. EfiPciIoWidthUint32,
  320. EfiPciIoWidthUint64,
  321. EfiPciIoWidthFifoUint8,
  322. EfiPciIoWidthFifoUint16,
  323. EfiPciIoWidthFifoUint32,
  324. EfiPciIoWidthFifoUint64,
  325. EfiPciIoWidthFillUint8,
  326. EfiPciIoWidthFillUint16,
  327. EfiPciIoWidthFillUint32,
  328. EfiPciIoWidthFillUint64,
  329. EfiPciIoWidthMaximum
  330. } EFI_PCI_IO_PROTOCOL_WIDTH;
  331. typedef enum {
  332. EfiPciIoAttributeOperationGet,
  333. EfiPciIoAttributeOperationSet,
  334. EfiPciIoAttributeOperationEnable,
  335. EfiPciIoAttributeOperationDisable,
  336. EfiPciIoAttributeOperationSupported,
  337. EfiPciIoAttributeOperationMaximum
  338. } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
  339. typedef struct {
  340. u32 read;
  341. u32 write;
  342. } efi_pci_io_protocol_access_32_t;
  343. typedef struct {
  344. u64 read;
  345. u64 write;
  346. } efi_pci_io_protocol_access_64_t;
  347. typedef struct {
  348. void *read;
  349. void *write;
  350. } efi_pci_io_protocol_access_t;
  351. typedef struct {
  352. u32 poll_mem;
  353. u32 poll_io;
  354. efi_pci_io_protocol_access_32_t mem;
  355. efi_pci_io_protocol_access_32_t io;
  356. efi_pci_io_protocol_access_32_t pci;
  357. u32 copy_mem;
  358. u32 map;
  359. u32 unmap;
  360. u32 allocate_buffer;
  361. u32 free_buffer;
  362. u32 flush;
  363. u32 get_location;
  364. u32 attributes;
  365. u32 get_bar_attributes;
  366. u32 set_bar_attributes;
  367. u64 romsize;
  368. u32 romimage;
  369. } efi_pci_io_protocol_32_t;
  370. typedef struct {
  371. u64 poll_mem;
  372. u64 poll_io;
  373. efi_pci_io_protocol_access_64_t mem;
  374. efi_pci_io_protocol_access_64_t io;
  375. efi_pci_io_protocol_access_64_t pci;
  376. u64 copy_mem;
  377. u64 map;
  378. u64 unmap;
  379. u64 allocate_buffer;
  380. u64 free_buffer;
  381. u64 flush;
  382. u64 get_location;
  383. u64 attributes;
  384. u64 get_bar_attributes;
  385. u64 set_bar_attributes;
  386. u64 romsize;
  387. u64 romimage;
  388. } efi_pci_io_protocol_64_t;
  389. typedef struct {
  390. void *poll_mem;
  391. void *poll_io;
  392. efi_pci_io_protocol_access_t mem;
  393. efi_pci_io_protocol_access_t io;
  394. efi_pci_io_protocol_access_t pci;
  395. void *copy_mem;
  396. void *map;
  397. void *unmap;
  398. void *allocate_buffer;
  399. void *free_buffer;
  400. void *flush;
  401. void *get_location;
  402. void *attributes;
  403. void *get_bar_attributes;
  404. void *set_bar_attributes;
  405. uint64_t romsize;
  406. void *romimage;
  407. } efi_pci_io_protocol_t;
  408. #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
  409. #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
  410. #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
  411. #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
  412. #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
  413. #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
  414. #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
  415. #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
  416. #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
  417. #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
  418. #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
  419. #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
  420. #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
  421. #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
  422. #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
  423. #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
  424. #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
  425. #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
  426. #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
  427. typedef struct {
  428. u32 version;
  429. u32 get;
  430. u32 set;
  431. u32 del;
  432. u32 get_all;
  433. } apple_properties_protocol_32_t;
  434. typedef struct {
  435. u64 version;
  436. u64 get;
  437. u64 set;
  438. u64 del;
  439. u64 get_all;
  440. } apple_properties_protocol_64_t;
  441. typedef struct {
  442. u32 get_capability;
  443. u32 get_event_log;
  444. u32 hash_log_extend_event;
  445. u32 submit_command;
  446. u32 get_active_pcr_banks;
  447. u32 set_active_pcr_banks;
  448. u32 get_result_of_set_active_pcr_banks;
  449. } efi_tcg2_protocol_32_t;
  450. typedef struct {
  451. u64 get_capability;
  452. u64 get_event_log;
  453. u64 hash_log_extend_event;
  454. u64 submit_command;
  455. u64 get_active_pcr_banks;
  456. u64 set_active_pcr_banks;
  457. u64 get_result_of_set_active_pcr_banks;
  458. } efi_tcg2_protocol_64_t;
  459. typedef u32 efi_tcg2_event_log_format;
  460. typedef struct {
  461. void *get_capability;
  462. efi_status_t (*get_event_log)(efi_handle_t, efi_tcg2_event_log_format,
  463. efi_physical_addr_t *, efi_physical_addr_t *, efi_bool_t *);
  464. void *hash_log_extend_event;
  465. void *submit_command;
  466. void *get_active_pcr_banks;
  467. void *set_active_pcr_banks;
  468. void *get_result_of_set_active_pcr_banks;
  469. } efi_tcg2_protocol_t;
  470. /*
  471. * Types and defines for EFI ResetSystem
  472. */
  473. #define EFI_RESET_COLD 0
  474. #define EFI_RESET_WARM 1
  475. #define EFI_RESET_SHUTDOWN 2
  476. /*
  477. * EFI Runtime Services table
  478. */
  479. #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
  480. #define EFI_RUNTIME_SERVICES_REVISION 0x00010000
  481. typedef struct {
  482. efi_table_hdr_t hdr;
  483. u32 get_time;
  484. u32 set_time;
  485. u32 get_wakeup_time;
  486. u32 set_wakeup_time;
  487. u32 set_virtual_address_map;
  488. u32 convert_pointer;
  489. u32 get_variable;
  490. u32 get_next_variable;
  491. u32 set_variable;
  492. u32 get_next_high_mono_count;
  493. u32 reset_system;
  494. u32 update_capsule;
  495. u32 query_capsule_caps;
  496. u32 query_variable_info;
  497. } efi_runtime_services_32_t;
  498. typedef struct {
  499. efi_table_hdr_t hdr;
  500. u64 get_time;
  501. u64 set_time;
  502. u64 get_wakeup_time;
  503. u64 set_wakeup_time;
  504. u64 set_virtual_address_map;
  505. u64 convert_pointer;
  506. u64 get_variable;
  507. u64 get_next_variable;
  508. u64 set_variable;
  509. u64 get_next_high_mono_count;
  510. u64 reset_system;
  511. u64 update_capsule;
  512. u64 query_capsule_caps;
  513. u64 query_variable_info;
  514. } efi_runtime_services_64_t;
  515. typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
  516. typedef efi_status_t efi_set_time_t (efi_time_t *tm);
  517. typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
  518. efi_time_t *tm);
  519. typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
  520. typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
  521. unsigned long *data_size, void *data);
  522. typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
  523. efi_guid_t *vendor);
  524. typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
  525. u32 attr, unsigned long data_size,
  526. void *data);
  527. typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
  528. typedef void efi_reset_system_t (int reset_type, efi_status_t status,
  529. unsigned long data_size, efi_char16_t *data);
  530. typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
  531. unsigned long descriptor_size,
  532. u32 descriptor_version,
  533. efi_memory_desc_t *virtual_map);
  534. typedef efi_status_t efi_query_variable_info_t(u32 attr,
  535. u64 *storage_space,
  536. u64 *remaining_space,
  537. u64 *max_variable_size);
  538. typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
  539. unsigned long count,
  540. unsigned long sg_list);
  541. typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
  542. unsigned long count,
  543. u64 *max_size,
  544. int *reset_type);
  545. typedef efi_status_t efi_query_variable_store_t(u32 attributes,
  546. unsigned long size,
  547. bool nonblocking);
  548. typedef struct {
  549. efi_table_hdr_t hdr;
  550. efi_get_time_t *get_time;
  551. efi_set_time_t *set_time;
  552. efi_get_wakeup_time_t *get_wakeup_time;
  553. efi_set_wakeup_time_t *set_wakeup_time;
  554. efi_set_virtual_address_map_t *set_virtual_address_map;
  555. void *convert_pointer;
  556. efi_get_variable_t *get_variable;
  557. efi_get_next_variable_t *get_next_variable;
  558. efi_set_variable_t *set_variable;
  559. efi_get_next_high_mono_count_t *get_next_high_mono_count;
  560. efi_reset_system_t *reset_system;
  561. efi_update_capsule_t *update_capsule;
  562. efi_query_capsule_caps_t *query_capsule_caps;
  563. efi_query_variable_info_t *query_variable_info;
  564. } efi_runtime_services_t;
  565. void efi_native_runtime_setup(void);
  566. /*
  567. * EFI Configuration Table and GUID definitions
  568. *
  569. * These are all defined in a single line to make them easier to
  570. * grep for and to see them at a glance - while still having a
  571. * similar structure to the definitions in the spec.
  572. *
  573. * Here's how they are structured:
  574. *
  575. * GUID: 12345678-1234-1234-1234-123456789012
  576. * Spec:
  577. * #define EFI_SOME_PROTOCOL_GUID \
  578. * {0x12345678,0x1234,0x1234,\
  579. * {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
  580. * Here:
  581. * #define SOME_PROTOCOL_GUID EFI_GUID(0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
  582. * ^ tabs ^extra space
  583. *
  584. * Note that the 'extra space' separates the values at the same place
  585. * where the UEFI SPEC breaks the line.
  586. */
  587. #define NULL_GUID EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
  588. #define MPS_TABLE_GUID EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  589. #define ACPI_TABLE_GUID EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  590. #define ACPI_20_TABLE_GUID EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
  591. #define SMBIOS_TABLE_GUID EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  592. #define SMBIOS3_TABLE_GUID EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
  593. #define SAL_SYSTEM_TABLE_GUID EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  594. #define HCDP_TABLE_GUID EFI_GUID(0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
  595. #define UGA_IO_PROTOCOL_GUID EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
  596. #define EFI_GLOBAL_VARIABLE_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
  597. #define UV_SYSTEM_TABLE_GUID EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
  598. #define LINUX_EFI_CRASH_GUID EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
  599. #define LOADED_IMAGE_PROTOCOL_GUID EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  600. #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
  601. #define EFI_UGA_PROTOCOL_GUID EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
  602. #define EFI_PCI_IO_PROTOCOL_GUID EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
  603. #define EFI_FILE_INFO_ID EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  604. #define EFI_SYSTEM_RESOURCE_TABLE_GUID EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
  605. #define EFI_FILE_SYSTEM_GUID EFI_GUID(0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  606. #define DEVICE_TREE_GUID EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
  607. #define EFI_PROPERTIES_TABLE_GUID EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
  608. #define EFI_RNG_PROTOCOL_GUID EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
  609. #define EFI_RNG_ALGORITHM_RAW EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
  610. #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
  611. #define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  612. #define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
  613. #define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
  614. #define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
  615. #define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
  616. /*
  617. * This GUID is used to pass to the kernel proper the struct screen_info
  618. * structure that was populated by the stub based on the GOP protocol instance
  619. * associated with ConOut
  620. */
  621. #define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, 0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
  622. #define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
  623. #define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b)
  624. #define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa)
  625. typedef struct {
  626. efi_guid_t guid;
  627. u64 table;
  628. } efi_config_table_64_t;
  629. typedef struct {
  630. efi_guid_t guid;
  631. u32 table;
  632. } efi_config_table_32_t;
  633. typedef struct {
  634. efi_guid_t guid;
  635. unsigned long table;
  636. } efi_config_table_t;
  637. typedef struct {
  638. efi_guid_t guid;
  639. const char *name;
  640. unsigned long *ptr;
  641. } efi_config_table_type_t;
  642. #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
  643. #define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
  644. #define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20))
  645. #define EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10))
  646. #define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00))
  647. #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10))
  648. #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02))
  649. typedef struct {
  650. efi_table_hdr_t hdr;
  651. u64 fw_vendor; /* physical addr of CHAR16 vendor string */
  652. u32 fw_revision;
  653. u32 __pad1;
  654. u64 con_in_handle;
  655. u64 con_in;
  656. u64 con_out_handle;
  657. u64 con_out;
  658. u64 stderr_handle;
  659. u64 stderr;
  660. u64 runtime;
  661. u64 boottime;
  662. u32 nr_tables;
  663. u32 __pad2;
  664. u64 tables;
  665. } efi_system_table_64_t;
  666. typedef struct {
  667. efi_table_hdr_t hdr;
  668. u32 fw_vendor; /* physical addr of CHAR16 vendor string */
  669. u32 fw_revision;
  670. u32 con_in_handle;
  671. u32 con_in;
  672. u32 con_out_handle;
  673. u32 con_out;
  674. u32 stderr_handle;
  675. u32 stderr;
  676. u32 runtime;
  677. u32 boottime;
  678. u32 nr_tables;
  679. u32 tables;
  680. } efi_system_table_32_t;
  681. typedef struct {
  682. efi_table_hdr_t hdr;
  683. unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
  684. u32 fw_revision;
  685. unsigned long con_in_handle;
  686. unsigned long con_in;
  687. unsigned long con_out_handle;
  688. unsigned long con_out;
  689. unsigned long stderr_handle;
  690. unsigned long stderr;
  691. efi_runtime_services_t *runtime;
  692. efi_boot_services_t *boottime;
  693. unsigned long nr_tables;
  694. unsigned long tables;
  695. } efi_system_table_t;
  696. /*
  697. * Architecture independent structure for describing a memory map for the
  698. * benefit of efi_memmap_init_early(), saving us the need to pass four
  699. * parameters.
  700. */
  701. struct efi_memory_map_data {
  702. phys_addr_t phys_map;
  703. unsigned long size;
  704. unsigned long desc_version;
  705. unsigned long desc_size;
  706. };
  707. struct efi_memory_map {
  708. phys_addr_t phys_map;
  709. void *map;
  710. void *map_end;
  711. int nr_map;
  712. unsigned long desc_version;
  713. unsigned long desc_size;
  714. bool late;
  715. };
  716. struct efi_mem_range {
  717. struct range range;
  718. u64 attribute;
  719. };
  720. struct efi_fdt_params {
  721. u64 system_table;
  722. u64 mmap;
  723. u32 mmap_size;
  724. u32 desc_size;
  725. u32 desc_ver;
  726. };
  727. typedef struct {
  728. u32 revision;
  729. u32 parent_handle;
  730. u32 system_table;
  731. u32 device_handle;
  732. u32 file_path;
  733. u32 reserved;
  734. u32 load_options_size;
  735. u32 load_options;
  736. u32 image_base;
  737. __aligned_u64 image_size;
  738. unsigned int image_code_type;
  739. unsigned int image_data_type;
  740. unsigned long unload;
  741. } efi_loaded_image_32_t;
  742. typedef struct {
  743. u32 revision;
  744. u64 parent_handle;
  745. u64 system_table;
  746. u64 device_handle;
  747. u64 file_path;
  748. u64 reserved;
  749. u32 load_options_size;
  750. u64 load_options;
  751. u64 image_base;
  752. __aligned_u64 image_size;
  753. unsigned int image_code_type;
  754. unsigned int image_data_type;
  755. unsigned long unload;
  756. } efi_loaded_image_64_t;
  757. typedef struct {
  758. u32 revision;
  759. void *parent_handle;
  760. efi_system_table_t *system_table;
  761. void *device_handle;
  762. void *file_path;
  763. void *reserved;
  764. u32 load_options_size;
  765. void *load_options;
  766. void *image_base;
  767. __aligned_u64 image_size;
  768. unsigned int image_code_type;
  769. unsigned int image_data_type;
  770. unsigned long unload;
  771. } efi_loaded_image_t;
  772. typedef struct {
  773. u64 size;
  774. u64 file_size;
  775. u64 phys_size;
  776. efi_time_t create_time;
  777. efi_time_t last_access_time;
  778. efi_time_t modification_time;
  779. __aligned_u64 attribute;
  780. efi_char16_t filename[1];
  781. } efi_file_info_t;
  782. typedef struct {
  783. u64 revision;
  784. u32 open;
  785. u32 close;
  786. u32 delete;
  787. u32 read;
  788. u32 write;
  789. u32 get_position;
  790. u32 set_position;
  791. u32 get_info;
  792. u32 set_info;
  793. u32 flush;
  794. } efi_file_handle_32_t;
  795. typedef struct {
  796. u64 revision;
  797. u64 open;
  798. u64 close;
  799. u64 delete;
  800. u64 read;
  801. u64 write;
  802. u64 get_position;
  803. u64 set_position;
  804. u64 get_info;
  805. u64 set_info;
  806. u64 flush;
  807. } efi_file_handle_64_t;
  808. typedef struct _efi_file_handle {
  809. u64 revision;
  810. efi_status_t (*open)(struct _efi_file_handle *,
  811. struct _efi_file_handle **,
  812. efi_char16_t *, u64, u64);
  813. efi_status_t (*close)(struct _efi_file_handle *);
  814. void *delete;
  815. efi_status_t (*read)(struct _efi_file_handle *, unsigned long *,
  816. void *);
  817. void *write;
  818. void *get_position;
  819. void *set_position;
  820. efi_status_t (*get_info)(struct _efi_file_handle *, efi_guid_t *,
  821. unsigned long *, void *);
  822. void *set_info;
  823. void *flush;
  824. } efi_file_handle_t;
  825. typedef struct {
  826. u64 revision;
  827. u32 open_volume;
  828. } efi_file_io_interface_32_t;
  829. typedef struct {
  830. u64 revision;
  831. u64 open_volume;
  832. } efi_file_io_interface_64_t;
  833. typedef struct _efi_file_io_interface {
  834. u64 revision;
  835. int (*open_volume)(struct _efi_file_io_interface *,
  836. efi_file_handle_t **);
  837. } efi_file_io_interface_t;
  838. #define EFI_FILE_MODE_READ 0x0000000000000001
  839. #define EFI_FILE_MODE_WRITE 0x0000000000000002
  840. #define EFI_FILE_MODE_CREATE 0x8000000000000000
  841. typedef struct {
  842. u32 version;
  843. u32 length;
  844. u64 memory_protection_attribute;
  845. } efi_properties_table_t;
  846. #define EFI_PROPERTIES_TABLE_VERSION 0x00010000
  847. #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
  848. #define EFI_INVALID_TABLE_ADDR (~0UL)
  849. typedef struct {
  850. u32 version;
  851. u32 num_entries;
  852. u32 desc_size;
  853. u32 reserved;
  854. efi_memory_desc_t entry[0];
  855. } efi_memory_attributes_table_t;
  856. /*
  857. * All runtime access to EFI goes through this structure:
  858. */
  859. extern struct efi {
  860. efi_system_table_t *systab; /* EFI system table */
  861. unsigned int runtime_version; /* Runtime services version */
  862. unsigned long mps; /* MPS table */
  863. unsigned long acpi; /* ACPI table (IA64 ext 0.71) */
  864. unsigned long acpi20; /* ACPI table (ACPI 2.0) */
  865. unsigned long smbios; /* SMBIOS table (32 bit entry point) */
  866. unsigned long smbios3; /* SMBIOS table (64 bit entry point) */
  867. unsigned long sal_systab; /* SAL system table */
  868. unsigned long boot_info; /* boot info table */
  869. unsigned long hcdp; /* HCDP table */
  870. unsigned long uga; /* UGA table */
  871. unsigned long uv_systab; /* UV system table */
  872. unsigned long fw_vendor; /* fw_vendor */
  873. unsigned long runtime; /* runtime table */
  874. unsigned long config_table; /* config tables */
  875. unsigned long esrt; /* ESRT table */
  876. unsigned long properties_table; /* properties table */
  877. unsigned long mem_attr_table; /* memory attributes table */
  878. unsigned long rng_seed; /* UEFI firmware random seed */
  879. unsigned long tpm_log; /* TPM2 Event Log table */
  880. efi_get_time_t *get_time;
  881. efi_set_time_t *set_time;
  882. efi_get_wakeup_time_t *get_wakeup_time;
  883. efi_set_wakeup_time_t *set_wakeup_time;
  884. efi_get_variable_t *get_variable;
  885. efi_get_next_variable_t *get_next_variable;
  886. efi_set_variable_t *set_variable;
  887. efi_set_variable_t *set_variable_nonblocking;
  888. efi_query_variable_info_t *query_variable_info;
  889. efi_query_variable_info_t *query_variable_info_nonblocking;
  890. efi_update_capsule_t *update_capsule;
  891. efi_query_capsule_caps_t *query_capsule_caps;
  892. efi_get_next_high_mono_count_t *get_next_high_mono_count;
  893. efi_reset_system_t *reset_system;
  894. efi_set_virtual_address_map_t *set_virtual_address_map;
  895. struct efi_memory_map memmap;
  896. unsigned long flags;
  897. } efi;
  898. extern struct mm_struct efi_mm;
  899. static inline int
  900. efi_guidcmp (efi_guid_t left, efi_guid_t right)
  901. {
  902. return memcmp(&left, &right, sizeof (efi_guid_t));
  903. }
  904. static inline char *
  905. efi_guid_to_str(efi_guid_t *guid, char *out)
  906. {
  907. sprintf(out, "%pUl", guid->b);
  908. return out;
  909. }
  910. extern void efi_init (void);
  911. extern void *efi_get_pal_addr (void);
  912. extern void efi_map_pal_code (void);
  913. extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
  914. extern void efi_gettimeofday (struct timespec64 *ts);
  915. extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
  916. #ifdef CONFIG_X86
  917. extern void efi_free_boot_services(void);
  918. extern efi_status_t efi_query_variable_store(u32 attributes,
  919. unsigned long size,
  920. bool nonblocking);
  921. extern void efi_find_mirror(void);
  922. #else
  923. static inline void efi_free_boot_services(void) {}
  924. static inline efi_status_t efi_query_variable_store(u32 attributes,
  925. unsigned long size,
  926. bool nonblocking)
  927. {
  928. return EFI_SUCCESS;
  929. }
  930. #endif
  931. extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
  932. extern phys_addr_t __init efi_memmap_alloc(unsigned int num_entries);
  933. extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
  934. extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
  935. extern void __init efi_memmap_unmap(void);
  936. extern int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map);
  937. extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
  938. struct range *range);
  939. extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,
  940. void *buf, struct efi_mem_range *mem);
  941. extern int efi_config_init(efi_config_table_type_t *arch_tables);
  942. #ifdef CONFIG_EFI_ESRT
  943. extern void __init efi_esrt_init(void);
  944. #else
  945. static inline void efi_esrt_init(void) { }
  946. #endif
  947. extern int efi_config_parse_tables(void *config_tables, int count, int sz,
  948. efi_config_table_type_t *arch_tables);
  949. extern u64 efi_get_iobase (void);
  950. extern int efi_mem_type(unsigned long phys_addr);
  951. extern u64 efi_mem_attributes (unsigned long phys_addr);
  952. extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
  953. extern int __init efi_uart_console_only (void);
  954. extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
  955. extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
  956. extern void efi_mem_reserve(phys_addr_t addr, u64 size);
  957. extern void efi_initialize_iomem_resources(struct resource *code_resource,
  958. struct resource *data_resource, struct resource *bss_resource);
  959. extern void efi_reserve_boot_services(void);
  960. extern int efi_get_fdt_params(struct efi_fdt_params *params);
  961. extern struct kobject *efi_kobj;
  962. extern int efi_reboot_quirk_mode;
  963. extern bool efi_poweroff_required(void);
  964. #ifdef CONFIG_EFI_FAKE_MEMMAP
  965. extern void __init efi_fake_memmap(void);
  966. #else
  967. static inline void efi_fake_memmap(void) { }
  968. #endif
  969. /*
  970. * efi_memattr_perm_setter - arch specific callback function passed into
  971. * efi_memattr_apply_permissions() that updates the
  972. * mapping permissions described by the second
  973. * argument in the page tables referred to by the
  974. * first argument.
  975. */
  976. typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
  977. extern int efi_memattr_init(void);
  978. extern int efi_memattr_apply_permissions(struct mm_struct *mm,
  979. efi_memattr_perm_setter fn);
  980. /*
  981. * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
  982. * @map: the start of efi memmap
  983. * @desc_size: the size of space for each EFI memmap descriptor
  984. * @n: the index of efi memmap descriptor
  985. *
  986. * EFI boot service provides the GetMemoryMap() function to get a copy of the
  987. * current memory map which is an array of memory descriptors, each of
  988. * which describes a contiguous block of memory. It also gets the size of the
  989. * map, and the size of each descriptor, etc.
  990. *
  991. * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
  992. * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
  993. * since efi_memory_memdesc_t may be extended in the future. Thus the OS
  994. * MUST use the returned size of the descriptor to find the start of each
  995. * efi_memory_memdesc_t in the memory map array. This should only be used
  996. * during bootup since for_each_efi_memory_desc_xxx() is available after the
  997. * kernel initializes the EFI subsystem to set up struct efi_memory_map.
  998. */
  999. #define efi_early_memdesc_ptr(map, desc_size, n) \
  1000. (efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
  1001. /* Iterate through an efi_memory_map */
  1002. #define for_each_efi_memory_desc_in_map(m, md) \
  1003. for ((md) = (m)->map; \
  1004. (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end; \
  1005. (md) = (void *)(md) + (m)->desc_size)
  1006. /**
  1007. * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
  1008. * @md: the efi_memory_desc_t * iterator
  1009. *
  1010. * Once the loop finishes @md must not be accessed.
  1011. */
  1012. #define for_each_efi_memory_desc(md) \
  1013. for_each_efi_memory_desc_in_map(&efi.memmap, md)
  1014. /*
  1015. * Format an EFI memory descriptor's type and attributes to a user-provided
  1016. * character buffer, as per snprintf(), and return the buffer.
  1017. */
  1018. char * __init efi_md_typeattr_format(char *buf, size_t size,
  1019. const efi_memory_desc_t *md);
  1020. /**
  1021. * efi_range_is_wc - check the WC bit on an address range
  1022. * @start: starting kvirt address
  1023. * @len: length of range
  1024. *
  1025. * Consult the EFI memory map and make sure it's ok to set this range WC.
  1026. * Returns true or false.
  1027. */
  1028. static inline int efi_range_is_wc(unsigned long start, unsigned long len)
  1029. {
  1030. unsigned long i;
  1031. for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
  1032. unsigned long paddr = __pa(start + i);
  1033. if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
  1034. return 0;
  1035. }
  1036. /* The range checked out */
  1037. return 1;
  1038. }
  1039. #ifdef CONFIG_EFI_PCDP
  1040. extern int __init efi_setup_pcdp_console(char *);
  1041. #endif
  1042. /*
  1043. * We play games with efi_enabled so that the compiler will, if
  1044. * possible, remove EFI-related code altogether.
  1045. */
  1046. #define EFI_BOOT 0 /* Were we booted from EFI? */
  1047. #define EFI_CONFIG_TABLES 2 /* Can we use EFI config tables? */
  1048. #define EFI_RUNTIME_SERVICES 3 /* Can we use runtime services? */
  1049. #define EFI_MEMMAP 4 /* Can we use EFI memory map? */
  1050. #define EFI_64BIT 5 /* Is the firmware 64-bit? */
  1051. #define EFI_PARAVIRT 6 /* Access is via a paravirt interface */
  1052. #define EFI_ARCH_1 7 /* First arch-specific bit */
  1053. #define EFI_DBG 8 /* Print additional debug info at runtime */
  1054. #define EFI_NX_PE_DATA 9 /* Can runtime data regions be mapped non-executable? */
  1055. #define EFI_MEM_ATTR 10 /* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
  1056. #ifdef CONFIG_EFI
  1057. /*
  1058. * Test whether the above EFI_* bits are enabled.
  1059. */
  1060. static inline bool efi_enabled(int feature)
  1061. {
  1062. return test_bit(feature, &efi.flags) != 0;
  1063. }
  1064. extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
  1065. extern bool efi_is_table_address(unsigned long phys_addr);
  1066. #else
  1067. static inline bool efi_enabled(int feature)
  1068. {
  1069. return false;
  1070. }
  1071. static inline void
  1072. efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
  1073. static inline bool
  1074. efi_capsule_pending(int *reset_type)
  1075. {
  1076. return false;
  1077. }
  1078. static inline bool efi_is_table_address(unsigned long phys_addr)
  1079. {
  1080. return false;
  1081. }
  1082. #endif
  1083. extern int efi_status_to_err(efi_status_t status);
  1084. /*
  1085. * Variable Attributes
  1086. */
  1087. #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
  1088. #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
  1089. #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
  1090. #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
  1091. #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
  1092. #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
  1093. #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
  1094. #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
  1095. EFI_VARIABLE_BOOTSERVICE_ACCESS | \
  1096. EFI_VARIABLE_RUNTIME_ACCESS | \
  1097. EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
  1098. EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
  1099. EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
  1100. EFI_VARIABLE_APPEND_WRITE)
  1101. /*
  1102. * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
  1103. * not including trailing NUL
  1104. */
  1105. #define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN
  1106. /*
  1107. * The type of search to perform when calling boottime->locate_handle
  1108. */
  1109. #define EFI_LOCATE_ALL_HANDLES 0
  1110. #define EFI_LOCATE_BY_REGISTER_NOTIFY 1
  1111. #define EFI_LOCATE_BY_PROTOCOL 2
  1112. /*
  1113. * EFI Device Path information
  1114. */
  1115. #define EFI_DEV_HW 0x01
  1116. #define EFI_DEV_PCI 1
  1117. #define EFI_DEV_PCCARD 2
  1118. #define EFI_DEV_MEM_MAPPED 3
  1119. #define EFI_DEV_VENDOR 4
  1120. #define EFI_DEV_CONTROLLER 5
  1121. #define EFI_DEV_ACPI 0x02
  1122. #define EFI_DEV_BASIC_ACPI 1
  1123. #define EFI_DEV_EXPANDED_ACPI 2
  1124. #define EFI_DEV_MSG 0x03
  1125. #define EFI_DEV_MSG_ATAPI 1
  1126. #define EFI_DEV_MSG_SCSI 2
  1127. #define EFI_DEV_MSG_FC 3
  1128. #define EFI_DEV_MSG_1394 4
  1129. #define EFI_DEV_MSG_USB 5
  1130. #define EFI_DEV_MSG_USB_CLASS 15
  1131. #define EFI_DEV_MSG_I20 6
  1132. #define EFI_DEV_MSG_MAC 11
  1133. #define EFI_DEV_MSG_IPV4 12
  1134. #define EFI_DEV_MSG_IPV6 13
  1135. #define EFI_DEV_MSG_INFINIBAND 9
  1136. #define EFI_DEV_MSG_UART 14
  1137. #define EFI_DEV_MSG_VENDOR 10
  1138. #define EFI_DEV_MEDIA 0x04
  1139. #define EFI_DEV_MEDIA_HARD_DRIVE 1
  1140. #define EFI_DEV_MEDIA_CDROM 2
  1141. #define EFI_DEV_MEDIA_VENDOR 3
  1142. #define EFI_DEV_MEDIA_FILE 4
  1143. #define EFI_DEV_MEDIA_PROTOCOL 5
  1144. #define EFI_DEV_BIOS_BOOT 0x05
  1145. #define EFI_DEV_END_PATH 0x7F
  1146. #define EFI_DEV_END_PATH2 0xFF
  1147. #define EFI_DEV_END_INSTANCE 0x01
  1148. #define EFI_DEV_END_ENTIRE 0xFF
  1149. struct efi_generic_dev_path {
  1150. u8 type;
  1151. u8 sub_type;
  1152. u16 length;
  1153. } __attribute ((packed));
  1154. struct efi_dev_path {
  1155. u8 type; /* can be replaced with unnamed */
  1156. u8 sub_type; /* struct efi_generic_dev_path; */
  1157. u16 length; /* once we've moved to -std=c11 */
  1158. union {
  1159. struct {
  1160. u32 hid;
  1161. u32 uid;
  1162. } acpi;
  1163. struct {
  1164. u8 fn;
  1165. u8 dev;
  1166. } pci;
  1167. };
  1168. } __attribute ((packed));
  1169. #if IS_ENABLED(CONFIG_EFI_DEV_PATH_PARSER)
  1170. struct device *efi_get_device_by_path(struct efi_dev_path **node, size_t *len);
  1171. #endif
  1172. static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
  1173. {
  1174. *npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
  1175. *addr &= PAGE_MASK;
  1176. }
  1177. /*
  1178. * EFI Variable support.
  1179. *
  1180. * Different firmware drivers can expose their EFI-like variables using
  1181. * the following.
  1182. */
  1183. struct efivar_operations {
  1184. efi_get_variable_t *get_variable;
  1185. efi_get_next_variable_t *get_next_variable;
  1186. efi_set_variable_t *set_variable;
  1187. efi_set_variable_t *set_variable_nonblocking;
  1188. efi_query_variable_store_t *query_variable_store;
  1189. };
  1190. struct efivars {
  1191. struct kset *kset;
  1192. struct kobject *kobject;
  1193. const struct efivar_operations *ops;
  1194. };
  1195. /*
  1196. * The maximum size of VariableName + Data = 1024
  1197. * Therefore, it's reasonable to save that much
  1198. * space in each part of the structure,
  1199. * and we use a page for reading/writing.
  1200. */
  1201. #define EFI_VAR_NAME_LEN 1024
  1202. struct efi_variable {
  1203. efi_char16_t VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
  1204. efi_guid_t VendorGuid;
  1205. unsigned long DataSize;
  1206. __u8 Data[1024];
  1207. efi_status_t Status;
  1208. __u32 Attributes;
  1209. } __attribute__((packed));
  1210. struct efivar_entry {
  1211. struct efi_variable var;
  1212. struct list_head list;
  1213. struct kobject kobj;
  1214. bool scanning;
  1215. bool deleting;
  1216. };
  1217. typedef struct {
  1218. u32 reset;
  1219. u32 output_string;
  1220. u32 test_string;
  1221. } efi_simple_text_output_protocol_32_t;
  1222. typedef struct {
  1223. u64 reset;
  1224. u64 output_string;
  1225. u64 test_string;
  1226. } efi_simple_text_output_protocol_64_t;
  1227. struct efi_simple_text_output_protocol {
  1228. void *reset;
  1229. efi_status_t (*output_string)(void *, void *);
  1230. void *test_string;
  1231. };
  1232. #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
  1233. #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
  1234. #define PIXEL_BIT_MASK 2
  1235. #define PIXEL_BLT_ONLY 3
  1236. #define PIXEL_FORMAT_MAX 4
  1237. struct efi_pixel_bitmask {
  1238. u32 red_mask;
  1239. u32 green_mask;
  1240. u32 blue_mask;
  1241. u32 reserved_mask;
  1242. };
  1243. struct efi_graphics_output_mode_info {
  1244. u32 version;
  1245. u32 horizontal_resolution;
  1246. u32 vertical_resolution;
  1247. int pixel_format;
  1248. struct efi_pixel_bitmask pixel_information;
  1249. u32 pixels_per_scan_line;
  1250. } __packed;
  1251. struct efi_graphics_output_protocol_mode_32 {
  1252. u32 max_mode;
  1253. u32 mode;
  1254. u32 info;
  1255. u32 size_of_info;
  1256. u64 frame_buffer_base;
  1257. u32 frame_buffer_size;
  1258. } __packed;
  1259. struct efi_graphics_output_protocol_mode_64 {
  1260. u32 max_mode;
  1261. u32 mode;
  1262. u64 info;
  1263. u64 size_of_info;
  1264. u64 frame_buffer_base;
  1265. u64 frame_buffer_size;
  1266. } __packed;
  1267. struct efi_graphics_output_protocol_mode {
  1268. u32 max_mode;
  1269. u32 mode;
  1270. unsigned long info;
  1271. unsigned long size_of_info;
  1272. u64 frame_buffer_base;
  1273. unsigned long frame_buffer_size;
  1274. } __packed;
  1275. struct efi_graphics_output_protocol_32 {
  1276. u32 query_mode;
  1277. u32 set_mode;
  1278. u32 blt;
  1279. u32 mode;
  1280. };
  1281. struct efi_graphics_output_protocol_64 {
  1282. u64 query_mode;
  1283. u64 set_mode;
  1284. u64 blt;
  1285. u64 mode;
  1286. };
  1287. struct efi_graphics_output_protocol {
  1288. unsigned long query_mode;
  1289. unsigned long set_mode;
  1290. unsigned long blt;
  1291. struct efi_graphics_output_protocol_mode *mode;
  1292. };
  1293. typedef efi_status_t (*efi_graphics_output_protocol_query_mode)(
  1294. struct efi_graphics_output_protocol *, u32, unsigned long *,
  1295. struct efi_graphics_output_mode_info **);
  1296. extern struct list_head efivar_sysfs_list;
  1297. static inline void
  1298. efivar_unregister(struct efivar_entry *var)
  1299. {
  1300. kobject_put(&var->kobj);
  1301. }
  1302. int efivars_register(struct efivars *efivars,
  1303. const struct efivar_operations *ops,
  1304. struct kobject *kobject);
  1305. int efivars_unregister(struct efivars *efivars);
  1306. struct kobject *efivars_kobject(void);
  1307. int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
  1308. void *data, bool duplicates, struct list_head *head);
  1309. int efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
  1310. int efivar_entry_remove(struct efivar_entry *entry);
  1311. int __efivar_entry_delete(struct efivar_entry *entry);
  1312. int efivar_entry_delete(struct efivar_entry *entry);
  1313. int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
  1314. int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
  1315. unsigned long *size, void *data);
  1316. int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
  1317. unsigned long *size, void *data);
  1318. int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
  1319. unsigned long size, void *data, struct list_head *head);
  1320. int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
  1321. unsigned long *size, void *data, bool *set);
  1322. int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
  1323. bool block, unsigned long size, void *data);
  1324. int efivar_entry_iter_begin(void);
  1325. void efivar_entry_iter_end(void);
  1326. int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
  1327. struct list_head *head, void *data,
  1328. struct efivar_entry **prev);
  1329. int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
  1330. struct list_head *head, void *data);
  1331. struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
  1332. struct list_head *head, bool remove);
  1333. bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
  1334. unsigned long data_size);
  1335. bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
  1336. size_t len);
  1337. extern struct work_struct efivar_work;
  1338. void efivar_run_worker(void);
  1339. #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
  1340. int efivars_sysfs_init(void);
  1341. #define EFIVARS_DATA_SIZE_MAX 1024
  1342. #endif /* CONFIG_EFI_VARS */
  1343. extern bool efi_capsule_pending(int *reset_type);
  1344. extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
  1345. size_t size, int *reset);
  1346. extern int efi_capsule_update(efi_capsule_header_t *capsule,
  1347. phys_addr_t *pages);
  1348. #ifdef CONFIG_EFI_RUNTIME_MAP
  1349. int efi_runtime_map_init(struct kobject *);
  1350. int efi_get_runtime_map_size(void);
  1351. int efi_get_runtime_map_desc_size(void);
  1352. int efi_runtime_map_copy(void *buf, size_t bufsz);
  1353. #else
  1354. static inline int efi_runtime_map_init(struct kobject *kobj)
  1355. {
  1356. return 0;
  1357. }
  1358. static inline int efi_get_runtime_map_size(void)
  1359. {
  1360. return 0;
  1361. }
  1362. static inline int efi_get_runtime_map_desc_size(void)
  1363. {
  1364. return 0;
  1365. }
  1366. static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
  1367. {
  1368. return 0;
  1369. }
  1370. #endif
  1371. /* prototypes shared between arch specific and generic stub code */
  1372. void efi_printk(efi_system_table_t *sys_table_arg, char *str);
  1373. void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
  1374. unsigned long addr);
  1375. char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
  1376. efi_loaded_image_t *image, int *cmd_line_len);
  1377. efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
  1378. struct efi_boot_memmap *map);
  1379. efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
  1380. unsigned long size, unsigned long align,
  1381. unsigned long *addr);
  1382. efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
  1383. unsigned long size, unsigned long align,
  1384. unsigned long *addr, unsigned long max);
  1385. efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
  1386. unsigned long *image_addr,
  1387. unsigned long image_size,
  1388. unsigned long alloc_size,
  1389. unsigned long preferred_addr,
  1390. unsigned long alignment);
  1391. efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
  1392. efi_loaded_image_t *image,
  1393. char *cmd_line, char *option_string,
  1394. unsigned long max_addr,
  1395. unsigned long *load_addr,
  1396. unsigned long *load_size);
  1397. efi_status_t efi_parse_options(char const *cmdline);
  1398. efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
  1399. struct screen_info *si, efi_guid_t *proto,
  1400. unsigned long size);
  1401. bool efi_runtime_disabled(void);
  1402. extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
  1403. enum efi_secureboot_mode {
  1404. efi_secureboot_mode_unset,
  1405. efi_secureboot_mode_unknown,
  1406. efi_secureboot_mode_disabled,
  1407. efi_secureboot_mode_enabled,
  1408. };
  1409. enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table);
  1410. #ifdef CONFIG_RESET_ATTACK_MITIGATION
  1411. void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg);
  1412. #else
  1413. static inline void
  1414. efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) { }
  1415. #endif
  1416. void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table);
  1417. /*
  1418. * Arch code can implement the following three template macros, avoiding
  1419. * reptition for the void/non-void return cases of {__,}efi_call_virt():
  1420. *
  1421. * * arch_efi_call_virt_setup()
  1422. *
  1423. * Sets up the environment for the call (e.g. switching page tables,
  1424. * allowing kernel-mode use of floating point, if required).
  1425. *
  1426. * * arch_efi_call_virt()
  1427. *
  1428. * Performs the call. The last expression in the macro must be the call
  1429. * itself, allowing the logic to be shared by the void and non-void
  1430. * cases.
  1431. *
  1432. * * arch_efi_call_virt_teardown()
  1433. *
  1434. * Restores the usual kernel environment once the call has returned.
  1435. */
  1436. #define efi_call_virt_pointer(p, f, args...) \
  1437. ({ \
  1438. efi_status_t __s; \
  1439. unsigned long __flags; \
  1440. \
  1441. arch_efi_call_virt_setup(); \
  1442. \
  1443. local_save_flags(__flags); \
  1444. __s = arch_efi_call_virt(p, f, args); \
  1445. efi_call_virt_check_flags(__flags, __stringify(f)); \
  1446. \
  1447. arch_efi_call_virt_teardown(); \
  1448. \
  1449. __s; \
  1450. })
  1451. #define __efi_call_virt_pointer(p, f, args...) \
  1452. ({ \
  1453. unsigned long __flags; \
  1454. \
  1455. arch_efi_call_virt_setup(); \
  1456. \
  1457. local_save_flags(__flags); \
  1458. arch_efi_call_virt(p, f, args); \
  1459. efi_call_virt_check_flags(__flags, __stringify(f)); \
  1460. \
  1461. arch_efi_call_virt_teardown(); \
  1462. })
  1463. typedef efi_status_t (*efi_exit_boot_map_processing)(
  1464. efi_system_table_t *sys_table_arg,
  1465. struct efi_boot_memmap *map,
  1466. void *priv);
  1467. efi_status_t efi_exit_boot_services(efi_system_table_t *sys_table,
  1468. void *handle,
  1469. struct efi_boot_memmap *map,
  1470. void *priv,
  1471. efi_exit_boot_map_processing priv_func);
  1472. #define EFI_RANDOM_SEED_SIZE 64U
  1473. struct linux_efi_random_seed {
  1474. u32 size;
  1475. u8 bits[];
  1476. };
  1477. struct linux_efi_tpm_eventlog {
  1478. u32 size;
  1479. u8 version;
  1480. u8 log[];
  1481. };
  1482. extern int efi_tpm_eventlog_init(void);
  1483. /* Workqueue to queue EFI Runtime Services */
  1484. extern struct workqueue_struct *efi_rts_wq;
  1485. #endif /* _LINUX_EFI_H */