efistub.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
  3. #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
  4. #include <linux/compiler.h>
  5. #include <linux/efi.h>
  6. #include <linux/kernel.h>
  7. #include <linux/kern_levels.h>
  8. #include <linux/types.h>
  9. #include <asm/efi.h>
  10. /*
  11. * __init annotations should not be used in the EFI stub, since the code is
  12. * either included in the decompressor (x86, ARM) where they have no effect,
  13. * or the whole stub is __init annotated at the section level (arm64), by
  14. * renaming the sections, in which case the __init annotation will be
  15. * redundant, and will result in section names like .init.init.text, and our
  16. * linker script does not expect that.
  17. */
  18. #undef __init
  19. /*
  20. * Allow the platform to override the allocation granularity: this allows
  21. * systems that have the capability to run with a larger page size to deal
  22. * with the allocations for initrd and fdt more efficiently.
  23. */
  24. #ifndef EFI_ALLOC_ALIGN
  25. #define EFI_ALLOC_ALIGN EFI_PAGE_SIZE
  26. #endif
  27. extern bool efi_nochunk;
  28. extern bool efi_nokaslr;
  29. extern int efi_loglevel;
  30. extern bool efi_novamap;
  31. extern const efi_system_table_t *efi_system_table;
  32. typedef union efi_dxe_services_table efi_dxe_services_table_t;
  33. extern const efi_dxe_services_table_t *efi_dxe_table;
  34. efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
  35. efi_system_table_t *sys_table_arg);
  36. #ifndef ARCH_HAS_EFISTUB_WRAPPERS
  37. #define efi_is_native() (true)
  38. #define efi_bs_call(func, ...) efi_system_table->boottime->func(__VA_ARGS__)
  39. #define efi_rt_call(func, ...) efi_system_table->runtime->func(__VA_ARGS__)
  40. #define efi_dxe_call(func, ...) efi_dxe_table->func(__VA_ARGS__)
  41. #define efi_table_attr(inst, attr) (inst->attr)
  42. #define efi_call_proto(inst, func, ...) inst->func(inst, ##__VA_ARGS__)
  43. #endif
  44. #define efi_info(fmt, ...) \
  45. efi_printk(KERN_INFO fmt, ##__VA_ARGS__)
  46. #define efi_warn(fmt, ...) \
  47. efi_printk(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
  48. #define efi_err(fmt, ...) \
  49. efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
  50. #define efi_debug(fmt, ...) \
  51. efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
  52. #define efi_printk_once(fmt, ...) \
  53. ({ \
  54. static bool __print_once; \
  55. bool __ret_print_once = !__print_once; \
  56. \
  57. if (!__print_once) { \
  58. __print_once = true; \
  59. efi_printk(fmt, ##__VA_ARGS__); \
  60. } \
  61. __ret_print_once; \
  62. })
  63. #define efi_info_once(fmt, ...) \
  64. efi_printk_once(KERN_INFO fmt, ##__VA_ARGS__)
  65. #define efi_warn_once(fmt, ...) \
  66. efi_printk_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
  67. #define efi_err_once(fmt, ...) \
  68. efi_printk_once(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
  69. #define efi_debug_once(fmt, ...) \
  70. efi_printk_once(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
  71. /* Helper macros for the usual case of using simple C variables: */
  72. #ifndef fdt_setprop_inplace_var
  73. #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
  74. fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
  75. #endif
  76. #ifndef fdt_setprop_var
  77. #define fdt_setprop_var(fdt, node_offset, name, var) \
  78. fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
  79. #endif
  80. #define get_efi_var(name, vendor, ...) \
  81. efi_rt_call(get_variable, (efi_char16_t *)(name), \
  82. (efi_guid_t *)(vendor), __VA_ARGS__)
  83. #define set_efi_var(name, vendor, ...) \
  84. efi_rt_call(set_variable, (efi_char16_t *)(name), \
  85. (efi_guid_t *)(vendor), __VA_ARGS__)
  86. #define efi_get_handle_at(array, idx) \
  87. (efi_is_native() ? (array)[idx] \
  88. : (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
  89. #define efi_get_handle_num(size) \
  90. ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
  91. #define for_each_efi_handle(handle, array, size, i) \
  92. for (i = 0; \
  93. i < efi_get_handle_num(size) && \
  94. ((handle = efi_get_handle_at((array), i)) || true); \
  95. i++)
  96. static inline
  97. void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
  98. {
  99. *lo = lower_32_bits(data);
  100. *hi = upper_32_bits(data);
  101. }
  102. /*
  103. * Allocation types for calls to boottime->allocate_pages.
  104. */
  105. #define EFI_ALLOCATE_ANY_PAGES 0
  106. #define EFI_ALLOCATE_MAX_ADDRESS 1
  107. #define EFI_ALLOCATE_ADDRESS 2
  108. #define EFI_MAX_ALLOCATE_TYPE 3
  109. /*
  110. * The type of search to perform when calling boottime->locate_handle
  111. */
  112. #define EFI_LOCATE_ALL_HANDLES 0
  113. #define EFI_LOCATE_BY_REGISTER_NOTIFY 1
  114. #define EFI_LOCATE_BY_PROTOCOL 2
  115. /*
  116. * boottime->stall takes the time period in microseconds
  117. */
  118. #define EFI_USEC_PER_SEC 1000000
  119. /*
  120. * boottime->set_timer takes the time in 100ns units
  121. */
  122. #define EFI_100NSEC_PER_USEC ((u64)10)
  123. /*
  124. * An efi_boot_memmap is used by efi_get_memory_map() to return the
  125. * EFI memory map in a dynamically allocated buffer.
  126. *
  127. * The buffer allocated for the EFI memory map includes extra room for
  128. * a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.
  129. * This facilitates the reuse of the EFI memory map buffer when a second
  130. * call to ExitBootServices() is needed because of intervening changes to
  131. * the EFI memory map. Other related structures, e.g. x86 e820ext, need
  132. * to factor in this headroom requirement as well.
  133. */
  134. #define EFI_MMAP_NR_SLACK_SLOTS 8
  135. typedef struct efi_generic_dev_path efi_device_path_protocol_t;
  136. union efi_device_path_to_text_protocol {
  137. struct {
  138. efi_char16_t *(__efiapi *convert_device_node_to_text)(
  139. const efi_device_path_protocol_t *,
  140. bool, bool);
  141. efi_char16_t *(__efiapi *convert_device_path_to_text)(
  142. const efi_device_path_protocol_t *,
  143. bool, bool);
  144. };
  145. struct {
  146. u32 convert_device_node_to_text;
  147. u32 convert_device_path_to_text;
  148. } mixed_mode;
  149. };
  150. typedef union efi_device_path_to_text_protocol efi_device_path_to_text_protocol_t;
  151. typedef void *efi_event_t;
  152. /* Note that notifications won't work in mixed mode */
  153. typedef void (__efiapi *efi_event_notify_t)(efi_event_t, void *);
  154. #define EFI_EVT_TIMER 0x80000000U
  155. #define EFI_EVT_RUNTIME 0x40000000U
  156. #define EFI_EVT_NOTIFY_WAIT 0x00000100U
  157. #define EFI_EVT_NOTIFY_SIGNAL 0x00000200U
  158. /**
  159. * efi_set_event_at() - add event to events array
  160. *
  161. * @events: array of UEFI events
  162. * @ids: index where to put the event in the array
  163. * @event: event to add to the aray
  164. *
  165. * boottime->wait_for_event() takes an array of events as input.
  166. * Provide a helper to set it up correctly for mixed mode.
  167. */
  168. static inline
  169. void efi_set_event_at(efi_event_t *events, size_t idx, efi_event_t event)
  170. {
  171. if (efi_is_native())
  172. events[idx] = event;
  173. else
  174. ((u32 *)events)[idx] = (u32)(unsigned long)event;
  175. }
  176. #define EFI_TPL_APPLICATION 4
  177. #define EFI_TPL_CALLBACK 8
  178. #define EFI_TPL_NOTIFY 16
  179. #define EFI_TPL_HIGH_LEVEL 31
  180. typedef enum {
  181. EfiTimerCancel,
  182. EfiTimerPeriodic,
  183. EfiTimerRelative
  184. } EFI_TIMER_DELAY;
  185. /*
  186. * EFI Boot Services table
  187. */
  188. union efi_boot_services {
  189. struct {
  190. efi_table_hdr_t hdr;
  191. void *raise_tpl;
  192. void *restore_tpl;
  193. efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
  194. efi_physical_addr_t *);
  195. efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
  196. unsigned long);
  197. efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
  198. unsigned long *,
  199. unsigned long *, u32 *);
  200. efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
  201. void **);
  202. efi_status_t (__efiapi *free_pool)(void *);
  203. efi_status_t (__efiapi *create_event)(u32, unsigned long,
  204. efi_event_notify_t, void *,
  205. efi_event_t *);
  206. efi_status_t (__efiapi *set_timer)(efi_event_t,
  207. EFI_TIMER_DELAY, u64);
  208. efi_status_t (__efiapi *wait_for_event)(unsigned long,
  209. efi_event_t *,
  210. unsigned long *);
  211. void *signal_event;
  212. efi_status_t (__efiapi *close_event)(efi_event_t);
  213. void *check_event;
  214. void *install_protocol_interface;
  215. void *reinstall_protocol_interface;
  216. void *uninstall_protocol_interface;
  217. efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
  218. efi_guid_t *, void **);
  219. void *__reserved;
  220. void *register_protocol_notify;
  221. efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
  222. void *, unsigned long *,
  223. efi_handle_t *);
  224. efi_status_t (__efiapi *locate_device_path)(efi_guid_t *,
  225. efi_device_path_protocol_t **,
  226. efi_handle_t *);
  227. efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
  228. void *);
  229. efi_status_t (__efiapi *load_image)(bool, efi_handle_t,
  230. efi_device_path_protocol_t *,
  231. void *, unsigned long,
  232. efi_handle_t *);
  233. efi_status_t (__efiapi *start_image)(efi_handle_t, unsigned long *,
  234. efi_char16_t **);
  235. efi_status_t __noreturn (__efiapi *exit)(efi_handle_t,
  236. efi_status_t,
  237. unsigned long,
  238. efi_char16_t *);
  239. efi_status_t (__efiapi *unload_image)(efi_handle_t);
  240. efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
  241. unsigned long);
  242. void *get_next_monotonic_count;
  243. efi_status_t (__efiapi *stall)(unsigned long);
  244. void *set_watchdog_timer;
  245. void *connect_controller;
  246. efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,
  247. efi_handle_t,
  248. efi_handle_t);
  249. void *open_protocol;
  250. void *close_protocol;
  251. void *open_protocol_information;
  252. void *protocols_per_handle;
  253. void *locate_handle_buffer;
  254. efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
  255. void **);
  256. efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...);
  257. efi_status_t (__efiapi *uninstall_multiple_protocol_interfaces)(efi_handle_t, ...);
  258. void *calculate_crc32;
  259. void (__efiapi *copy_mem)(void *, const void *, unsigned long);
  260. void (__efiapi *set_mem)(void *, unsigned long, unsigned char);
  261. void *create_event_ex;
  262. };
  263. struct {
  264. efi_table_hdr_t hdr;
  265. u32 raise_tpl;
  266. u32 restore_tpl;
  267. u32 allocate_pages;
  268. u32 free_pages;
  269. u32 get_memory_map;
  270. u32 allocate_pool;
  271. u32 free_pool;
  272. u32 create_event;
  273. u32 set_timer;
  274. u32 wait_for_event;
  275. u32 signal_event;
  276. u32 close_event;
  277. u32 check_event;
  278. u32 install_protocol_interface;
  279. u32 reinstall_protocol_interface;
  280. u32 uninstall_protocol_interface;
  281. u32 handle_protocol;
  282. u32 __reserved;
  283. u32 register_protocol_notify;
  284. u32 locate_handle;
  285. u32 locate_device_path;
  286. u32 install_configuration_table;
  287. u32 load_image;
  288. u32 start_image;
  289. u32 exit;
  290. u32 unload_image;
  291. u32 exit_boot_services;
  292. u32 get_next_monotonic_count;
  293. u32 stall;
  294. u32 set_watchdog_timer;
  295. u32 connect_controller;
  296. u32 disconnect_controller;
  297. u32 open_protocol;
  298. u32 close_protocol;
  299. u32 open_protocol_information;
  300. u32 protocols_per_handle;
  301. u32 locate_handle_buffer;
  302. u32 locate_protocol;
  303. u32 install_multiple_protocol_interfaces;
  304. u32 uninstall_multiple_protocol_interfaces;
  305. u32 calculate_crc32;
  306. u32 copy_mem;
  307. u32 set_mem;
  308. u32 create_event_ex;
  309. } mixed_mode;
  310. };
  311. typedef enum {
  312. EfiGcdMemoryTypeNonExistent,
  313. EfiGcdMemoryTypeReserved,
  314. EfiGcdMemoryTypeSystemMemory,
  315. EfiGcdMemoryTypeMemoryMappedIo,
  316. EfiGcdMemoryTypePersistent,
  317. EfiGcdMemoryTypeMoreReliable,
  318. EfiGcdMemoryTypeMaximum
  319. } efi_gcd_memory_type_t;
  320. typedef struct {
  321. efi_physical_addr_t base_address;
  322. u64 length;
  323. u64 capabilities;
  324. u64 attributes;
  325. efi_gcd_memory_type_t gcd_memory_type;
  326. void *image_handle;
  327. void *device_handle;
  328. } efi_gcd_memory_space_desc_t;
  329. /*
  330. * EFI DXE Services table
  331. */
  332. union efi_dxe_services_table {
  333. struct {
  334. efi_table_hdr_t hdr;
  335. void *add_memory_space;
  336. void *allocate_memory_space;
  337. void *free_memory_space;
  338. void *remove_memory_space;
  339. efi_status_t (__efiapi *get_memory_space_descriptor)(efi_physical_addr_t,
  340. efi_gcd_memory_space_desc_t *);
  341. efi_status_t (__efiapi *set_memory_space_attributes)(efi_physical_addr_t,
  342. u64, u64);
  343. void *get_memory_space_map;
  344. void *add_io_space;
  345. void *allocate_io_space;
  346. void *free_io_space;
  347. void *remove_io_space;
  348. void *get_io_space_descriptor;
  349. void *get_io_space_map;
  350. void *dispatch;
  351. void *schedule;
  352. void *trust;
  353. void *process_firmware_volume;
  354. void *set_memory_space_capabilities;
  355. };
  356. struct {
  357. efi_table_hdr_t hdr;
  358. u32 add_memory_space;
  359. u32 allocate_memory_space;
  360. u32 free_memory_space;
  361. u32 remove_memory_space;
  362. u32 get_memory_space_descriptor;
  363. u32 set_memory_space_attributes;
  364. u32 get_memory_space_map;
  365. u32 add_io_space;
  366. u32 allocate_io_space;
  367. u32 free_io_space;
  368. u32 remove_io_space;
  369. u32 get_io_space_descriptor;
  370. u32 get_io_space_map;
  371. u32 dispatch;
  372. u32 schedule;
  373. u32 trust;
  374. u32 process_firmware_volume;
  375. u32 set_memory_space_capabilities;
  376. } mixed_mode;
  377. };
  378. typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
  379. union efi_uga_draw_protocol {
  380. struct {
  381. efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
  382. u32*, u32*, u32*, u32*);
  383. void *set_mode;
  384. void *blt;
  385. };
  386. struct {
  387. u32 get_mode;
  388. u32 set_mode;
  389. u32 blt;
  390. } mixed_mode;
  391. };
  392. typedef struct {
  393. u16 scan_code;
  394. efi_char16_t unicode_char;
  395. } efi_input_key_t;
  396. union efi_simple_text_input_protocol {
  397. struct {
  398. void *reset;
  399. efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,
  400. efi_input_key_t *);
  401. efi_event_t wait_for_key;
  402. };
  403. struct {
  404. u32 reset;
  405. u32 read_keystroke;
  406. u32 wait_for_key;
  407. } mixed_mode;
  408. };
  409. efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key);
  410. union efi_simple_text_output_protocol {
  411. struct {
  412. void *reset;
  413. efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
  414. efi_char16_t *);
  415. void *test_string;
  416. };
  417. struct {
  418. u32 reset;
  419. u32 output_string;
  420. u32 test_string;
  421. } mixed_mode;
  422. };
  423. #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
  424. #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
  425. #define PIXEL_BIT_MASK 2
  426. #define PIXEL_BLT_ONLY 3
  427. #define PIXEL_FORMAT_MAX 4
  428. typedef struct {
  429. u32 red_mask;
  430. u32 green_mask;
  431. u32 blue_mask;
  432. u32 reserved_mask;
  433. } efi_pixel_bitmask_t;
  434. typedef struct {
  435. u32 version;
  436. u32 horizontal_resolution;
  437. u32 vertical_resolution;
  438. int pixel_format;
  439. efi_pixel_bitmask_t pixel_information;
  440. u32 pixels_per_scan_line;
  441. } efi_graphics_output_mode_info_t;
  442. typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
  443. union efi_graphics_output_protocol_mode {
  444. struct {
  445. u32 max_mode;
  446. u32 mode;
  447. efi_graphics_output_mode_info_t *info;
  448. unsigned long size_of_info;
  449. efi_physical_addr_t frame_buffer_base;
  450. unsigned long frame_buffer_size;
  451. };
  452. struct {
  453. u32 max_mode;
  454. u32 mode;
  455. u32 info;
  456. u32 size_of_info;
  457. u64 frame_buffer_base;
  458. u32 frame_buffer_size;
  459. } mixed_mode;
  460. };
  461. typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
  462. union efi_graphics_output_protocol {
  463. struct {
  464. efi_status_t (__efiapi *query_mode)(efi_graphics_output_protocol_t *,
  465. u32, unsigned long *,
  466. efi_graphics_output_mode_info_t **);
  467. efi_status_t (__efiapi *set_mode) (efi_graphics_output_protocol_t *, u32);
  468. void *blt;
  469. efi_graphics_output_protocol_mode_t *mode;
  470. };
  471. struct {
  472. u32 query_mode;
  473. u32 set_mode;
  474. u32 blt;
  475. u32 mode;
  476. } mixed_mode;
  477. };
  478. typedef union {
  479. struct {
  480. u32 revision;
  481. efi_handle_t parent_handle;
  482. efi_system_table_t *system_table;
  483. efi_handle_t device_handle;
  484. void *file_path;
  485. void *reserved;
  486. u32 load_options_size;
  487. void *load_options;
  488. void *image_base;
  489. __aligned_u64 image_size;
  490. unsigned int image_code_type;
  491. unsigned int image_data_type;
  492. efi_status_t (__efiapi *unload)(efi_handle_t image_handle);
  493. };
  494. struct {
  495. u32 revision;
  496. u32 parent_handle;
  497. u32 system_table;
  498. u32 device_handle;
  499. u32 file_path;
  500. u32 reserved;
  501. u32 load_options_size;
  502. u32 load_options;
  503. u32 image_base;
  504. __aligned_u64 image_size;
  505. u32 image_code_type;
  506. u32 image_data_type;
  507. u32 unload;
  508. } mixed_mode;
  509. } efi_loaded_image_t;
  510. typedef struct {
  511. u64 size;
  512. u64 file_size;
  513. u64 phys_size;
  514. efi_time_t create_time;
  515. efi_time_t last_access_time;
  516. efi_time_t modification_time;
  517. __aligned_u64 attribute;
  518. efi_char16_t filename[];
  519. } efi_file_info_t;
  520. typedef struct efi_file_protocol efi_file_protocol_t;
  521. struct efi_file_protocol {
  522. u64 revision;
  523. efi_status_t (__efiapi *open) (efi_file_protocol_t *,
  524. efi_file_protocol_t **,
  525. efi_char16_t *, u64, u64);
  526. efi_status_t (__efiapi *close) (efi_file_protocol_t *);
  527. efi_status_t (__efiapi *delete) (efi_file_protocol_t *);
  528. efi_status_t (__efiapi *read) (efi_file_protocol_t *,
  529. unsigned long *, void *);
  530. efi_status_t (__efiapi *write) (efi_file_protocol_t *,
  531. unsigned long, void *);
  532. efi_status_t (__efiapi *get_position)(efi_file_protocol_t *, u64 *);
  533. efi_status_t (__efiapi *set_position)(efi_file_protocol_t *, u64);
  534. efi_status_t (__efiapi *get_info) (efi_file_protocol_t *,
  535. efi_guid_t *, unsigned long *,
  536. void *);
  537. efi_status_t (__efiapi *set_info) (efi_file_protocol_t *,
  538. efi_guid_t *, unsigned long,
  539. void *);
  540. efi_status_t (__efiapi *flush) (efi_file_protocol_t *);
  541. };
  542. typedef struct efi_simple_file_system_protocol efi_simple_file_system_protocol_t;
  543. struct efi_simple_file_system_protocol {
  544. u64 revision;
  545. int (__efiapi *open_volume)(efi_simple_file_system_protocol_t *,
  546. efi_file_protocol_t **);
  547. };
  548. #define EFI_FILE_MODE_READ 0x0000000000000001
  549. #define EFI_FILE_MODE_WRITE 0x0000000000000002
  550. #define EFI_FILE_MODE_CREATE 0x8000000000000000
  551. typedef enum {
  552. EfiPciIoWidthUint8,
  553. EfiPciIoWidthUint16,
  554. EfiPciIoWidthUint32,
  555. EfiPciIoWidthUint64,
  556. EfiPciIoWidthFifoUint8,
  557. EfiPciIoWidthFifoUint16,
  558. EfiPciIoWidthFifoUint32,
  559. EfiPciIoWidthFifoUint64,
  560. EfiPciIoWidthFillUint8,
  561. EfiPciIoWidthFillUint16,
  562. EfiPciIoWidthFillUint32,
  563. EfiPciIoWidthFillUint64,
  564. EfiPciIoWidthMaximum
  565. } EFI_PCI_IO_PROTOCOL_WIDTH;
  566. typedef enum {
  567. EfiPciIoAttributeOperationGet,
  568. EfiPciIoAttributeOperationSet,
  569. EfiPciIoAttributeOperationEnable,
  570. EfiPciIoAttributeOperationDisable,
  571. EfiPciIoAttributeOperationSupported,
  572. EfiPciIoAttributeOperationMaximum
  573. } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
  574. typedef struct {
  575. u32 read;
  576. u32 write;
  577. } efi_pci_io_protocol_access_32_t;
  578. typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
  579. typedef
  580. efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
  581. EFI_PCI_IO_PROTOCOL_WIDTH,
  582. u32 offset,
  583. unsigned long count,
  584. void *buffer);
  585. typedef struct {
  586. void *read;
  587. void *write;
  588. } efi_pci_io_protocol_access_t;
  589. typedef struct {
  590. efi_pci_io_protocol_cfg_t read;
  591. efi_pci_io_protocol_cfg_t write;
  592. } efi_pci_io_protocol_config_access_t;
  593. union efi_pci_io_protocol {
  594. struct {
  595. void *poll_mem;
  596. void *poll_io;
  597. efi_pci_io_protocol_access_t mem;
  598. efi_pci_io_protocol_access_t io;
  599. efi_pci_io_protocol_config_access_t pci;
  600. void *copy_mem;
  601. void *map;
  602. void *unmap;
  603. void *allocate_buffer;
  604. void *free_buffer;
  605. void *flush;
  606. efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
  607. unsigned long *segment_nr,
  608. unsigned long *bus_nr,
  609. unsigned long *device_nr,
  610. unsigned long *func_nr);
  611. void *attributes;
  612. void *get_bar_attributes;
  613. void *set_bar_attributes;
  614. uint64_t romsize;
  615. void *romimage;
  616. };
  617. struct {
  618. u32 poll_mem;
  619. u32 poll_io;
  620. efi_pci_io_protocol_access_32_t mem;
  621. efi_pci_io_protocol_access_32_t io;
  622. efi_pci_io_protocol_access_32_t pci;
  623. u32 copy_mem;
  624. u32 map;
  625. u32 unmap;
  626. u32 allocate_buffer;
  627. u32 free_buffer;
  628. u32 flush;
  629. u32 get_location;
  630. u32 attributes;
  631. u32 get_bar_attributes;
  632. u32 set_bar_attributes;
  633. u64 romsize;
  634. u32 romimage;
  635. } mixed_mode;
  636. };
  637. #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
  638. #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
  639. #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
  640. #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
  641. #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
  642. #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
  643. #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
  644. #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
  645. #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
  646. #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
  647. #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
  648. #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
  649. #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
  650. #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
  651. #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
  652. #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
  653. #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
  654. #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
  655. #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
  656. struct efi_dev_path;
  657. typedef union apple_properties_protocol apple_properties_protocol_t;
  658. union apple_properties_protocol {
  659. struct {
  660. unsigned long version;
  661. efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
  662. struct efi_dev_path *,
  663. efi_char16_t *, void *, u32 *);
  664. efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
  665. struct efi_dev_path *,
  666. efi_char16_t *, void *, u32);
  667. efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
  668. struct efi_dev_path *,
  669. efi_char16_t *);
  670. efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
  671. void *buffer, u32 *);
  672. };
  673. struct {
  674. u32 version;
  675. u32 get;
  676. u32 set;
  677. u32 del;
  678. u32 get_all;
  679. } mixed_mode;
  680. };
  681. typedef u32 efi_tcg2_event_log_format;
  682. #define INITRD_EVENT_TAG_ID 0x8F3B22ECU
  683. #define LOAD_OPTIONS_EVENT_TAG_ID 0x8F3B22EDU
  684. #define EV_EVENT_TAG 0x00000006U
  685. #define EFI_TCG2_EVENT_HEADER_VERSION 0x1
  686. struct efi_tcg2_event {
  687. u32 event_size;
  688. struct {
  689. u32 header_size;
  690. u16 header_version;
  691. u32 pcr_index;
  692. u32 event_type;
  693. } __packed event_header;
  694. /* u8[] event follows here */
  695. } __packed;
  696. struct efi_tcg2_tagged_event {
  697. u32 tagged_event_id;
  698. u32 tagged_event_data_size;
  699. /* u8 tagged event data follows here */
  700. } __packed;
  701. typedef struct efi_tcg2_event efi_tcg2_event_t;
  702. typedef struct efi_tcg2_tagged_event efi_tcg2_tagged_event_t;
  703. typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
  704. union efi_tcg2_protocol {
  705. struct {
  706. void *get_capability;
  707. efi_status_t (__efiapi *get_event_log)(efi_tcg2_protocol_t *,
  708. efi_tcg2_event_log_format,
  709. efi_physical_addr_t *,
  710. efi_physical_addr_t *,
  711. efi_bool_t *);
  712. efi_status_t (__efiapi *hash_log_extend_event)(efi_tcg2_protocol_t *,
  713. u64,
  714. efi_physical_addr_t,
  715. u64,
  716. const efi_tcg2_event_t *);
  717. void *submit_command;
  718. void *get_active_pcr_banks;
  719. void *set_active_pcr_banks;
  720. void *get_result_of_set_active_pcr_banks;
  721. };
  722. struct {
  723. u32 get_capability;
  724. u32 get_event_log;
  725. u32 hash_log_extend_event;
  726. u32 submit_command;
  727. u32 get_active_pcr_banks;
  728. u32 set_active_pcr_banks;
  729. u32 get_result_of_set_active_pcr_banks;
  730. } mixed_mode;
  731. };
  732. struct riscv_efi_boot_protocol {
  733. u64 revision;
  734. efi_status_t (__efiapi *get_boot_hartid)(struct riscv_efi_boot_protocol *,
  735. unsigned long *boot_hartid);
  736. };
  737. typedef union efi_load_file_protocol efi_load_file_protocol_t;
  738. typedef union efi_load_file_protocol efi_load_file2_protocol_t;
  739. union efi_load_file_protocol {
  740. struct {
  741. efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,
  742. efi_device_path_protocol_t *,
  743. bool, unsigned long *, void *);
  744. };
  745. struct {
  746. u32 load_file;
  747. } mixed_mode;
  748. };
  749. typedef struct {
  750. u32 attributes;
  751. u16 file_path_list_length;
  752. u8 variable_data[];
  753. // efi_char16_t description[];
  754. // efi_device_path_protocol_t file_path_list[];
  755. // u8 optional_data[];
  756. } __packed efi_load_option_t;
  757. #define EFI_LOAD_OPTION_ACTIVE 0x0001U
  758. #define EFI_LOAD_OPTION_FORCE_RECONNECT 0x0002U
  759. #define EFI_LOAD_OPTION_HIDDEN 0x0008U
  760. #define EFI_LOAD_OPTION_CATEGORY 0x1f00U
  761. #define EFI_LOAD_OPTION_CATEGORY_BOOT 0x0000U
  762. #define EFI_LOAD_OPTION_CATEGORY_APP 0x0100U
  763. #define EFI_LOAD_OPTION_BOOT_MASK \
  764. (EFI_LOAD_OPTION_ACTIVE|EFI_LOAD_OPTION_HIDDEN|EFI_LOAD_OPTION_CATEGORY)
  765. #define EFI_LOAD_OPTION_MASK (EFI_LOAD_OPTION_FORCE_RECONNECT|EFI_LOAD_OPTION_BOOT_MASK)
  766. typedef struct {
  767. u32 attributes;
  768. u16 file_path_list_length;
  769. const efi_char16_t *description;
  770. const efi_device_path_protocol_t *file_path_list;
  771. u32 optional_data_size;
  772. const void *optional_data;
  773. } efi_load_option_unpacked_t;
  774. void efi_pci_disable_bridge_busmaster(void);
  775. typedef efi_status_t (*efi_exit_boot_map_processing)(
  776. struct efi_boot_memmap *map,
  777. void *priv);
  778. efi_status_t efi_exit_boot_services(void *handle, void *priv,
  779. efi_exit_boot_map_processing priv_func);
  780. efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
  781. unsigned long kernel_addr, char *cmdline_ptr);
  782. void *get_fdt(unsigned long *fdt_size);
  783. efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,
  784. unsigned long *desc_size, u32 *desc_ver);
  785. void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
  786. unsigned long desc_size, efi_memory_desc_t *runtime_map,
  787. int *count);
  788. efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
  789. efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
  790. unsigned long *addr, unsigned long random_seed);
  791. efi_status_t efi_random_get_seed(void);
  792. efi_status_t check_platform_features(void);
  793. void *get_efi_config_table(efi_guid_t guid);
  794. /* NOTE: These functions do not print a trailing newline after the string */
  795. void efi_char16_puts(efi_char16_t *);
  796. void efi_puts(const char *str);
  797. __printf(1, 2) int efi_printk(char const *fmt, ...);
  798. void efi_free(unsigned long size, unsigned long addr);
  799. void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_options_size);
  800. char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len);
  801. efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,
  802. bool install_cfg_tbl);
  803. efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
  804. unsigned long max);
  805. efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
  806. unsigned long max, unsigned long align);
  807. efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
  808. unsigned long *addr, unsigned long min);
  809. efi_status_t efi_relocate_kernel(unsigned long *image_addr,
  810. unsigned long image_size,
  811. unsigned long alloc_size,
  812. unsigned long preferred_addr,
  813. unsigned long alignment,
  814. unsigned long min_addr);
  815. efi_status_t efi_parse_options(char const *cmdline);
  816. void efi_parse_option_graphics(char *option);
  817. efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
  818. unsigned long size);
  819. efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
  820. const efi_char16_t *optstr,
  821. int optstr_size,
  822. unsigned long soft_limit,
  823. unsigned long hard_limit,
  824. unsigned long *load_addr,
  825. unsigned long *load_size);
  826. static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,
  827. unsigned long *load_addr,
  828. unsigned long *load_size)
  829. {
  830. return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,
  831. ULONG_MAX, ULONG_MAX, load_addr, load_size);
  832. }
  833. efi_status_t efi_load_initrd(efi_loaded_image_t *image,
  834. unsigned long soft_limit,
  835. unsigned long hard_limit,
  836. const struct linux_efi_initrd **out);
  837. /*
  838. * This function handles the architcture specific differences between arm and
  839. * arm64 regarding where the kernel image must be loaded and any memory that
  840. * must be reserved. On failure it is required to free all
  841. * all allocations it has made.
  842. */
  843. efi_status_t handle_kernel_image(unsigned long *image_addr,
  844. unsigned long *image_size,
  845. unsigned long *reserve_addr,
  846. unsigned long *reserve_size,
  847. efi_loaded_image_t *image,
  848. efi_handle_t image_handle);
  849. asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,
  850. unsigned long fdt_addr,
  851. unsigned long fdt_size);
  852. void efi_handle_post_ebs_state(void);
  853. enum efi_secureboot_mode efi_get_secureboot(void);
  854. #ifdef CONFIG_RESET_ATTACK_MITIGATION
  855. void efi_enable_reset_attack_mitigation(void);
  856. #else
  857. static inline void
  858. efi_enable_reset_attack_mitigation(void) { }
  859. #endif
  860. void efi_retrieve_tpm2_eventlog(void);
  861. struct efi_smbios_record {
  862. u8 type;
  863. u8 length;
  864. u16 handle;
  865. };
  866. const struct efi_smbios_record *efi_get_smbios_record(u8 type);
  867. struct efi_smbios_type1_record {
  868. struct efi_smbios_record header;
  869. u8 manufacturer;
  870. u8 product_name;
  871. u8 version;
  872. u8 serial_number;
  873. efi_guid_t uuid;
  874. u8 wakeup_type;
  875. u8 sku_number;
  876. u8 family;
  877. };
  878. struct efi_smbios_type4_record {
  879. struct efi_smbios_record header;
  880. u8 socket;
  881. u8 processor_type;
  882. u8 processor_family;
  883. u8 processor_manufacturer;
  884. u8 processor_id[8];
  885. u8 processor_version;
  886. u8 voltage;
  887. u16 external_clock;
  888. u16 max_speed;
  889. u16 current_speed;
  890. u8 status;
  891. u8 processor_upgrade;
  892. u16 l1_cache_handle;
  893. u16 l2_cache_handle;
  894. u16 l3_cache_handle;
  895. u8 serial_number;
  896. u8 asset_tag;
  897. u8 part_number;
  898. u8 core_count;
  899. u8 enabled_core_count;
  900. u8 thread_count;
  901. u16 processor_characteristics;
  902. u16 processor_family2;
  903. u16 core_count2;
  904. u16 enabled_core_count2;
  905. u16 thread_count2;
  906. u16 thread_enabled;
  907. };
  908. #define efi_get_smbios_string(__record, __type, __name) ({ \
  909. int size = sizeof(struct efi_smbios_type ## __type ## _record); \
  910. int off = offsetof(struct efi_smbios_type ## __type ## _record, \
  911. __name); \
  912. __efi_get_smbios_string((__record), __type, off, size); \
  913. })
  914. const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,
  915. u8 type, int offset, int recsize);
  916. #endif