efi.h 42 KB

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