efi.h 43 KB

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