efi.h 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  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. uint64_t romsize;
  368. void *romimage;
  369. } efi_pci_io_protocol_32;
  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. uint64_t romsize;
  387. void *romimage;
  388. } efi_pci_io_protocol_64;
  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;
  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 _efi_file_io_interface {
  826. u64 revision;
  827. int (*open_volume)(struct _efi_file_io_interface *,
  828. efi_file_handle_t **);
  829. } efi_file_io_interface_t;
  830. #define EFI_FILE_MODE_READ 0x0000000000000001
  831. #define EFI_FILE_MODE_WRITE 0x0000000000000002
  832. #define EFI_FILE_MODE_CREATE 0x8000000000000000
  833. typedef struct {
  834. u32 version;
  835. u32 length;
  836. u64 memory_protection_attribute;
  837. } efi_properties_table_t;
  838. #define EFI_PROPERTIES_TABLE_VERSION 0x00010000
  839. #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
  840. #define EFI_INVALID_TABLE_ADDR (~0UL)
  841. typedef struct {
  842. u32 version;
  843. u32 num_entries;
  844. u32 desc_size;
  845. u32 reserved;
  846. efi_memory_desc_t entry[0];
  847. } efi_memory_attributes_table_t;
  848. /*
  849. * All runtime access to EFI goes through this structure:
  850. */
  851. extern struct efi {
  852. efi_system_table_t *systab; /* EFI system table */
  853. unsigned int runtime_version; /* Runtime services version */
  854. unsigned long mps; /* MPS table */
  855. unsigned long acpi; /* ACPI table (IA64 ext 0.71) */
  856. unsigned long acpi20; /* ACPI table (ACPI 2.0) */
  857. unsigned long smbios; /* SMBIOS table (32 bit entry point) */
  858. unsigned long smbios3; /* SMBIOS table (64 bit entry point) */
  859. unsigned long sal_systab; /* SAL system table */
  860. unsigned long boot_info; /* boot info table */
  861. unsigned long hcdp; /* HCDP table */
  862. unsigned long uga; /* UGA table */
  863. unsigned long uv_systab; /* UV system table */
  864. unsigned long fw_vendor; /* fw_vendor */
  865. unsigned long runtime; /* runtime table */
  866. unsigned long config_table; /* config tables */
  867. unsigned long esrt; /* ESRT table */
  868. unsigned long properties_table; /* properties table */
  869. unsigned long mem_attr_table; /* memory attributes table */
  870. unsigned long rng_seed; /* UEFI firmware random seed */
  871. unsigned long tpm_log; /* TPM2 Event Log table */
  872. efi_get_time_t *get_time;
  873. efi_set_time_t *set_time;
  874. efi_get_wakeup_time_t *get_wakeup_time;
  875. efi_set_wakeup_time_t *set_wakeup_time;
  876. efi_get_variable_t *get_variable;
  877. efi_get_next_variable_t *get_next_variable;
  878. efi_set_variable_t *set_variable;
  879. efi_set_variable_t *set_variable_nonblocking;
  880. efi_query_variable_info_t *query_variable_info;
  881. efi_query_variable_info_t *query_variable_info_nonblocking;
  882. efi_update_capsule_t *update_capsule;
  883. efi_query_capsule_caps_t *query_capsule_caps;
  884. efi_get_next_high_mono_count_t *get_next_high_mono_count;
  885. efi_reset_system_t *reset_system;
  886. efi_set_virtual_address_map_t *set_virtual_address_map;
  887. struct efi_memory_map memmap;
  888. unsigned long flags;
  889. } efi;
  890. static inline int
  891. efi_guidcmp (efi_guid_t left, efi_guid_t right)
  892. {
  893. return memcmp(&left, &right, sizeof (efi_guid_t));
  894. }
  895. static inline char *
  896. efi_guid_to_str(efi_guid_t *guid, char *out)
  897. {
  898. sprintf(out, "%pUl", guid->b);
  899. return out;
  900. }
  901. extern void efi_init (void);
  902. extern void *efi_get_pal_addr (void);
  903. extern void efi_map_pal_code (void);
  904. extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
  905. extern void efi_gettimeofday (struct timespec64 *ts);
  906. extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
  907. #ifdef CONFIG_X86
  908. extern void efi_late_init(void);
  909. extern void efi_free_boot_services(void);
  910. extern efi_status_t efi_query_variable_store(u32 attributes,
  911. unsigned long size,
  912. bool nonblocking);
  913. extern void efi_find_mirror(void);
  914. #else
  915. static inline void efi_late_init(void) {}
  916. static inline void efi_free_boot_services(void) {}
  917. static inline efi_status_t efi_query_variable_store(u32 attributes,
  918. unsigned long size,
  919. bool nonblocking)
  920. {
  921. return EFI_SUCCESS;
  922. }
  923. #endif
  924. extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
  925. extern phys_addr_t __init efi_memmap_alloc(unsigned int num_entries);
  926. extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
  927. extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
  928. extern void __init efi_memmap_unmap(void);
  929. extern int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map);
  930. extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
  931. struct range *range);
  932. extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,
  933. void *buf, struct efi_mem_range *mem);
  934. extern int efi_config_init(efi_config_table_type_t *arch_tables);
  935. #ifdef CONFIG_EFI_ESRT
  936. extern void __init efi_esrt_init(void);
  937. #else
  938. static inline void efi_esrt_init(void) { }
  939. #endif
  940. extern int efi_config_parse_tables(void *config_tables, int count, int sz,
  941. efi_config_table_type_t *arch_tables);
  942. extern u64 efi_get_iobase (void);
  943. extern int efi_mem_type(unsigned long phys_addr);
  944. extern u64 efi_mem_attributes (unsigned long phys_addr);
  945. extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
  946. extern int __init efi_uart_console_only (void);
  947. extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
  948. extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
  949. extern void efi_mem_reserve(phys_addr_t addr, u64 size);
  950. extern void efi_initialize_iomem_resources(struct resource *code_resource,
  951. struct resource *data_resource, struct resource *bss_resource);
  952. extern void efi_reserve_boot_services(void);
  953. extern int efi_get_fdt_params(struct efi_fdt_params *params);
  954. extern struct kobject *efi_kobj;
  955. extern int efi_reboot_quirk_mode;
  956. extern bool efi_poweroff_required(void);
  957. #ifdef CONFIG_EFI_FAKE_MEMMAP
  958. extern void __init efi_fake_memmap(void);
  959. #else
  960. static inline void efi_fake_memmap(void) { }
  961. #endif
  962. /*
  963. * efi_memattr_perm_setter - arch specific callback function passed into
  964. * efi_memattr_apply_permissions() that updates the
  965. * mapping permissions described by the second
  966. * argument in the page tables referred to by the
  967. * first argument.
  968. */
  969. typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
  970. extern int efi_memattr_init(void);
  971. extern int efi_memattr_apply_permissions(struct mm_struct *mm,
  972. efi_memattr_perm_setter fn);
  973. /*
  974. * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
  975. * @map: the start of efi memmap
  976. * @desc_size: the size of space for each EFI memmap descriptor
  977. * @n: the index of efi memmap descriptor
  978. *
  979. * EFI boot service provides the GetMemoryMap() function to get a copy of the
  980. * current memory map which is an array of memory descriptors, each of
  981. * which describes a contiguous block of memory. It also gets the size of the
  982. * map, and the size of each descriptor, etc.
  983. *
  984. * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
  985. * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
  986. * since efi_memory_memdesc_t may be extended in the future. Thus the OS
  987. * MUST use the returned size of the descriptor to find the start of each
  988. * efi_memory_memdesc_t in the memory map array. This should only be used
  989. * during bootup since for_each_efi_memory_desc_xxx() is available after the
  990. * kernel initializes the EFI subsystem to set up struct efi_memory_map.
  991. */
  992. #define efi_early_memdesc_ptr(map, desc_size, n) \
  993. (efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
  994. /* Iterate through an efi_memory_map */
  995. #define for_each_efi_memory_desc_in_map(m, md) \
  996. for ((md) = (m)->map; \
  997. (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end; \
  998. (md) = (void *)(md) + (m)->desc_size)
  999. /**
  1000. * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
  1001. * @md: the efi_memory_desc_t * iterator
  1002. *
  1003. * Once the loop finishes @md must not be accessed.
  1004. */
  1005. #define for_each_efi_memory_desc(md) \
  1006. for_each_efi_memory_desc_in_map(&efi.memmap, md)
  1007. /*
  1008. * Format an EFI memory descriptor's type and attributes to a user-provided
  1009. * character buffer, as per snprintf(), and return the buffer.
  1010. */
  1011. char * __init efi_md_typeattr_format(char *buf, size_t size,
  1012. const efi_memory_desc_t *md);
  1013. /**
  1014. * efi_range_is_wc - check the WC bit on an address range
  1015. * @start: starting kvirt address
  1016. * @len: length of range
  1017. *
  1018. * Consult the EFI memory map and make sure it's ok to set this range WC.
  1019. * Returns true or false.
  1020. */
  1021. static inline int efi_range_is_wc(unsigned long start, unsigned long len)
  1022. {
  1023. unsigned long i;
  1024. for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
  1025. unsigned long paddr = __pa(start + i);
  1026. if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
  1027. return 0;
  1028. }
  1029. /* The range checked out */
  1030. return 1;
  1031. }
  1032. #ifdef CONFIG_EFI_PCDP
  1033. extern int __init efi_setup_pcdp_console(char *);
  1034. #endif
  1035. /*
  1036. * We play games with efi_enabled so that the compiler will, if
  1037. * possible, remove EFI-related code altogether.
  1038. */
  1039. #define EFI_BOOT 0 /* Were we booted from EFI? */
  1040. #define EFI_CONFIG_TABLES 2 /* Can we use EFI config tables? */
  1041. #define EFI_RUNTIME_SERVICES 3 /* Can we use runtime services? */
  1042. #define EFI_MEMMAP 4 /* Can we use EFI memory map? */
  1043. #define EFI_64BIT 5 /* Is the firmware 64-bit? */
  1044. #define EFI_PARAVIRT 6 /* Access is via a paravirt interface */
  1045. #define EFI_ARCH_1 7 /* First arch-specific bit */
  1046. #define EFI_DBG 8 /* Print additional debug info at runtime */
  1047. #define EFI_NX_PE_DATA 9 /* Can runtime data regions be mapped non-executable? */
  1048. #define EFI_MEM_ATTR 10 /* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
  1049. #ifdef CONFIG_EFI
  1050. /*
  1051. * Test whether the above EFI_* bits are enabled.
  1052. */
  1053. static inline bool efi_enabled(int feature)
  1054. {
  1055. return test_bit(feature, &efi.flags) != 0;
  1056. }
  1057. extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
  1058. extern bool efi_is_table_address(unsigned long phys_addr);
  1059. #else
  1060. static inline bool efi_enabled(int feature)
  1061. {
  1062. return false;
  1063. }
  1064. static inline void
  1065. efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
  1066. static inline bool
  1067. efi_capsule_pending(int *reset_type)
  1068. {
  1069. return false;
  1070. }
  1071. static inline bool efi_is_table_address(unsigned long phys_addr)
  1072. {
  1073. return false;
  1074. }
  1075. #endif
  1076. extern int efi_status_to_err(efi_status_t status);
  1077. /*
  1078. * Variable Attributes
  1079. */
  1080. #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
  1081. #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
  1082. #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
  1083. #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
  1084. #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
  1085. #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
  1086. #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
  1087. #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
  1088. EFI_VARIABLE_BOOTSERVICE_ACCESS | \
  1089. EFI_VARIABLE_RUNTIME_ACCESS | \
  1090. EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
  1091. EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
  1092. EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
  1093. EFI_VARIABLE_APPEND_WRITE)
  1094. /*
  1095. * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
  1096. * not including trailing NUL
  1097. */
  1098. #define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN
  1099. /*
  1100. * The type of search to perform when calling boottime->locate_handle
  1101. */
  1102. #define EFI_LOCATE_ALL_HANDLES 0
  1103. #define EFI_LOCATE_BY_REGISTER_NOTIFY 1
  1104. #define EFI_LOCATE_BY_PROTOCOL 2
  1105. /*
  1106. * EFI Device Path information
  1107. */
  1108. #define EFI_DEV_HW 0x01
  1109. #define EFI_DEV_PCI 1
  1110. #define EFI_DEV_PCCARD 2
  1111. #define EFI_DEV_MEM_MAPPED 3
  1112. #define EFI_DEV_VENDOR 4
  1113. #define EFI_DEV_CONTROLLER 5
  1114. #define EFI_DEV_ACPI 0x02
  1115. #define EFI_DEV_BASIC_ACPI 1
  1116. #define EFI_DEV_EXPANDED_ACPI 2
  1117. #define EFI_DEV_MSG 0x03
  1118. #define EFI_DEV_MSG_ATAPI 1
  1119. #define EFI_DEV_MSG_SCSI 2
  1120. #define EFI_DEV_MSG_FC 3
  1121. #define EFI_DEV_MSG_1394 4
  1122. #define EFI_DEV_MSG_USB 5
  1123. #define EFI_DEV_MSG_USB_CLASS 15
  1124. #define EFI_DEV_MSG_I20 6
  1125. #define EFI_DEV_MSG_MAC 11
  1126. #define EFI_DEV_MSG_IPV4 12
  1127. #define EFI_DEV_MSG_IPV6 13
  1128. #define EFI_DEV_MSG_INFINIBAND 9
  1129. #define EFI_DEV_MSG_UART 14
  1130. #define EFI_DEV_MSG_VENDOR 10
  1131. #define EFI_DEV_MEDIA 0x04
  1132. #define EFI_DEV_MEDIA_HARD_DRIVE 1
  1133. #define EFI_DEV_MEDIA_CDROM 2
  1134. #define EFI_DEV_MEDIA_VENDOR 3
  1135. #define EFI_DEV_MEDIA_FILE 4
  1136. #define EFI_DEV_MEDIA_PROTOCOL 5
  1137. #define EFI_DEV_BIOS_BOOT 0x05
  1138. #define EFI_DEV_END_PATH 0x7F
  1139. #define EFI_DEV_END_PATH2 0xFF
  1140. #define EFI_DEV_END_INSTANCE 0x01
  1141. #define EFI_DEV_END_ENTIRE 0xFF
  1142. struct efi_generic_dev_path {
  1143. u8 type;
  1144. u8 sub_type;
  1145. u16 length;
  1146. } __attribute ((packed));
  1147. struct efi_dev_path {
  1148. u8 type; /* can be replaced with unnamed */
  1149. u8 sub_type; /* struct efi_generic_dev_path; */
  1150. u16 length; /* once we've moved to -std=c11 */
  1151. union {
  1152. struct {
  1153. u32 hid;
  1154. u32 uid;
  1155. } acpi;
  1156. struct {
  1157. u8 fn;
  1158. u8 dev;
  1159. } pci;
  1160. };
  1161. } __attribute ((packed));
  1162. #if IS_ENABLED(CONFIG_EFI_DEV_PATH_PARSER)
  1163. struct device *efi_get_device_by_path(struct efi_dev_path **node, size_t *len);
  1164. #endif
  1165. static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
  1166. {
  1167. *npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
  1168. *addr &= PAGE_MASK;
  1169. }
  1170. /*
  1171. * EFI Variable support.
  1172. *
  1173. * Different firmware drivers can expose their EFI-like variables using
  1174. * the following.
  1175. */
  1176. struct efivar_operations {
  1177. efi_get_variable_t *get_variable;
  1178. efi_get_next_variable_t *get_next_variable;
  1179. efi_set_variable_t *set_variable;
  1180. efi_set_variable_t *set_variable_nonblocking;
  1181. efi_query_variable_store_t *query_variable_store;
  1182. };
  1183. struct efivars {
  1184. struct kset *kset;
  1185. struct kobject *kobject;
  1186. const struct efivar_operations *ops;
  1187. };
  1188. /*
  1189. * The maximum size of VariableName + Data = 1024
  1190. * Therefore, it's reasonable to save that much
  1191. * space in each part of the structure,
  1192. * and we use a page for reading/writing.
  1193. */
  1194. #define EFI_VAR_NAME_LEN 1024
  1195. struct efi_variable {
  1196. efi_char16_t VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
  1197. efi_guid_t VendorGuid;
  1198. unsigned long DataSize;
  1199. __u8 Data[1024];
  1200. efi_status_t Status;
  1201. __u32 Attributes;
  1202. } __attribute__((packed));
  1203. struct efivar_entry {
  1204. struct efi_variable var;
  1205. struct list_head list;
  1206. struct kobject kobj;
  1207. bool scanning;
  1208. bool deleting;
  1209. };
  1210. typedef struct {
  1211. u32 reset;
  1212. u32 output_string;
  1213. u32 test_string;
  1214. } efi_simple_text_output_protocol_32_t;
  1215. typedef struct {
  1216. u64 reset;
  1217. u64 output_string;
  1218. u64 test_string;
  1219. } efi_simple_text_output_protocol_64_t;
  1220. struct efi_simple_text_output_protocol {
  1221. void *reset;
  1222. efi_status_t (*output_string)(void *, void *);
  1223. void *test_string;
  1224. };
  1225. #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
  1226. #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
  1227. #define PIXEL_BIT_MASK 2
  1228. #define PIXEL_BLT_ONLY 3
  1229. #define PIXEL_FORMAT_MAX 4
  1230. struct efi_pixel_bitmask {
  1231. u32 red_mask;
  1232. u32 green_mask;
  1233. u32 blue_mask;
  1234. u32 reserved_mask;
  1235. };
  1236. struct efi_graphics_output_mode_info {
  1237. u32 version;
  1238. u32 horizontal_resolution;
  1239. u32 vertical_resolution;
  1240. int pixel_format;
  1241. struct efi_pixel_bitmask pixel_information;
  1242. u32 pixels_per_scan_line;
  1243. } __packed;
  1244. struct efi_graphics_output_protocol_mode_32 {
  1245. u32 max_mode;
  1246. u32 mode;
  1247. u32 info;
  1248. u32 size_of_info;
  1249. u64 frame_buffer_base;
  1250. u32 frame_buffer_size;
  1251. } __packed;
  1252. struct efi_graphics_output_protocol_mode_64 {
  1253. u32 max_mode;
  1254. u32 mode;
  1255. u64 info;
  1256. u64 size_of_info;
  1257. u64 frame_buffer_base;
  1258. u64 frame_buffer_size;
  1259. } __packed;
  1260. struct efi_graphics_output_protocol_mode {
  1261. u32 max_mode;
  1262. u32 mode;
  1263. unsigned long info;
  1264. unsigned long size_of_info;
  1265. u64 frame_buffer_base;
  1266. unsigned long frame_buffer_size;
  1267. } __packed;
  1268. struct efi_graphics_output_protocol_32 {
  1269. u32 query_mode;
  1270. u32 set_mode;
  1271. u32 blt;
  1272. u32 mode;
  1273. };
  1274. struct efi_graphics_output_protocol_64 {
  1275. u64 query_mode;
  1276. u64 set_mode;
  1277. u64 blt;
  1278. u64 mode;
  1279. };
  1280. struct efi_graphics_output_protocol {
  1281. unsigned long query_mode;
  1282. unsigned long set_mode;
  1283. unsigned long blt;
  1284. struct efi_graphics_output_protocol_mode *mode;
  1285. };
  1286. typedef efi_status_t (*efi_graphics_output_protocol_query_mode)(
  1287. struct efi_graphics_output_protocol *, u32, unsigned long *,
  1288. struct efi_graphics_output_mode_info **);
  1289. extern struct list_head efivar_sysfs_list;
  1290. static inline void
  1291. efivar_unregister(struct efivar_entry *var)
  1292. {
  1293. kobject_put(&var->kobj);
  1294. }
  1295. int efivars_register(struct efivars *efivars,
  1296. const struct efivar_operations *ops,
  1297. struct kobject *kobject);
  1298. int efivars_unregister(struct efivars *efivars);
  1299. struct kobject *efivars_kobject(void);
  1300. int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
  1301. void *data, bool duplicates, struct list_head *head);
  1302. int efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
  1303. int efivar_entry_remove(struct efivar_entry *entry);
  1304. int __efivar_entry_delete(struct efivar_entry *entry);
  1305. int efivar_entry_delete(struct efivar_entry *entry);
  1306. int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
  1307. int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
  1308. unsigned long *size, void *data);
  1309. int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
  1310. unsigned long *size, void *data);
  1311. int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
  1312. unsigned long size, void *data, struct list_head *head);
  1313. int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
  1314. unsigned long *size, void *data, bool *set);
  1315. int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
  1316. bool block, unsigned long size, void *data);
  1317. int efivar_entry_iter_begin(void);
  1318. void efivar_entry_iter_end(void);
  1319. int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
  1320. struct list_head *head, void *data,
  1321. struct efivar_entry **prev);
  1322. int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
  1323. struct list_head *head, void *data);
  1324. struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
  1325. struct list_head *head, bool remove);
  1326. bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
  1327. unsigned long data_size);
  1328. bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
  1329. size_t len);
  1330. extern struct work_struct efivar_work;
  1331. void efivar_run_worker(void);
  1332. #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
  1333. int efivars_sysfs_init(void);
  1334. #define EFIVARS_DATA_SIZE_MAX 1024
  1335. #endif /* CONFIG_EFI_VARS */
  1336. extern bool efi_capsule_pending(int *reset_type);
  1337. extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
  1338. size_t size, int *reset);
  1339. extern int efi_capsule_update(efi_capsule_header_t *capsule,
  1340. phys_addr_t *pages);
  1341. #ifdef CONFIG_EFI_RUNTIME_MAP
  1342. int efi_runtime_map_init(struct kobject *);
  1343. int efi_get_runtime_map_size(void);
  1344. int efi_get_runtime_map_desc_size(void);
  1345. int efi_runtime_map_copy(void *buf, size_t bufsz);
  1346. #else
  1347. static inline int efi_runtime_map_init(struct kobject *kobj)
  1348. {
  1349. return 0;
  1350. }
  1351. static inline int efi_get_runtime_map_size(void)
  1352. {
  1353. return 0;
  1354. }
  1355. static inline int efi_get_runtime_map_desc_size(void)
  1356. {
  1357. return 0;
  1358. }
  1359. static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
  1360. {
  1361. return 0;
  1362. }
  1363. #endif
  1364. /* prototypes shared between arch specific and generic stub code */
  1365. void efi_printk(efi_system_table_t *sys_table_arg, char *str);
  1366. void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
  1367. unsigned long addr);
  1368. char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
  1369. efi_loaded_image_t *image, int *cmd_line_len);
  1370. efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
  1371. struct efi_boot_memmap *map);
  1372. efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
  1373. unsigned long size, unsigned long align,
  1374. unsigned long *addr);
  1375. efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
  1376. unsigned long size, unsigned long align,
  1377. unsigned long *addr, unsigned long max);
  1378. efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
  1379. unsigned long *image_addr,
  1380. unsigned long image_size,
  1381. unsigned long alloc_size,
  1382. unsigned long preferred_addr,
  1383. unsigned long alignment);
  1384. efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
  1385. efi_loaded_image_t *image,
  1386. char *cmd_line, char *option_string,
  1387. unsigned long max_addr,
  1388. unsigned long *load_addr,
  1389. unsigned long *load_size);
  1390. efi_status_t efi_parse_options(char const *cmdline);
  1391. efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
  1392. struct screen_info *si, efi_guid_t *proto,
  1393. unsigned long size);
  1394. bool efi_runtime_disabled(void);
  1395. extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
  1396. enum efi_secureboot_mode {
  1397. efi_secureboot_mode_unset,
  1398. efi_secureboot_mode_unknown,
  1399. efi_secureboot_mode_disabled,
  1400. efi_secureboot_mode_enabled,
  1401. };
  1402. enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table);
  1403. #ifdef CONFIG_RESET_ATTACK_MITIGATION
  1404. void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg);
  1405. #else
  1406. static inline void
  1407. efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) { }
  1408. #endif
  1409. void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table);
  1410. /*
  1411. * Arch code can implement the following three template macros, avoiding
  1412. * reptition for the void/non-void return cases of {__,}efi_call_virt():
  1413. *
  1414. * * arch_efi_call_virt_setup()
  1415. *
  1416. * Sets up the environment for the call (e.g. switching page tables,
  1417. * allowing kernel-mode use of floating point, if required).
  1418. *
  1419. * * arch_efi_call_virt()
  1420. *
  1421. * Performs the call. The last expression in the macro must be the call
  1422. * itself, allowing the logic to be shared by the void and non-void
  1423. * cases.
  1424. *
  1425. * * arch_efi_call_virt_teardown()
  1426. *
  1427. * Restores the usual kernel environment once the call has returned.
  1428. */
  1429. #define efi_call_virt_pointer(p, f, args...) \
  1430. ({ \
  1431. efi_status_t __s; \
  1432. unsigned long __flags; \
  1433. \
  1434. arch_efi_call_virt_setup(); \
  1435. \
  1436. local_save_flags(__flags); \
  1437. __s = arch_efi_call_virt(p, f, args); \
  1438. efi_call_virt_check_flags(__flags, __stringify(f)); \
  1439. \
  1440. arch_efi_call_virt_teardown(); \
  1441. \
  1442. __s; \
  1443. })
  1444. #define __efi_call_virt_pointer(p, f, args...) \
  1445. ({ \
  1446. unsigned long __flags; \
  1447. \
  1448. arch_efi_call_virt_setup(); \
  1449. \
  1450. local_save_flags(__flags); \
  1451. arch_efi_call_virt(p, f, args); \
  1452. efi_call_virt_check_flags(__flags, __stringify(f)); \
  1453. \
  1454. arch_efi_call_virt_teardown(); \
  1455. })
  1456. typedef efi_status_t (*efi_exit_boot_map_processing)(
  1457. efi_system_table_t *sys_table_arg,
  1458. struct efi_boot_memmap *map,
  1459. void *priv);
  1460. efi_status_t efi_exit_boot_services(efi_system_table_t *sys_table,
  1461. void *handle,
  1462. struct efi_boot_memmap *map,
  1463. void *priv,
  1464. efi_exit_boot_map_processing priv_func);
  1465. #define EFI_RANDOM_SEED_SIZE 64U
  1466. struct linux_efi_random_seed {
  1467. u32 size;
  1468. u8 bits[];
  1469. };
  1470. struct linux_efi_tpm_eventlog {
  1471. u32 size;
  1472. u8 version;
  1473. u8 log[];
  1474. };
  1475. extern int efi_tpm_eventlog_init(void);
  1476. #endif /* _LINUX_EFI_H */