efi.h 40 KB

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