efi.h 44 KB

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