efi.h 42 KB

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