efi.h 45 KB

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