efi.h 36 KB

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