efi.h 45 KB

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