1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
4 #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
5 
6 #include <linux/compiler.h>
7 #include <linux/efi.h>
8 #include <linux/kernel.h>
9 #include <linux/kern_levels.h>
10 #include <linux/types.h>
11 #include <asm/efi.h>
12 
13 /* error code which can't be mistaken for valid address */
14 #define EFI_ERROR	(~0UL)
15 
16 /*
17  * __init annotations should not be used in the EFI stub, since the code is
18  * either included in the decompressor (x86, ARM) where they have no effect,
19  * or the whole stub is __init annotated at the section level (arm64), by
20  * renaming the sections, in which case the __init annotation will be
21  * redundant, and will result in section names like .init.init.text, and our
22  * linker script does not expect that.
23  */
24 #undef __init
25 
26 /*
27  * Allow the platform to override the allocation granularity: this allows
28  * systems that have the capability to run with a larger page size to deal
29  * with the allocations for initrd and fdt more efficiently.
30  */
31 #ifndef EFI_ALLOC_ALIGN
32 #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
33 #endif
34 
35 extern bool efi_nochunk;
36 extern bool efi_nokaslr;
37 extern bool efi_noinitrd;
38 extern int efi_loglevel;
39 extern bool efi_novamap;
40 
41 extern const efi_system_table_t *efi_system_table;
42 
43 efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
44 				   efi_system_table_t *sys_table_arg);
45 
46 #ifndef ARCH_HAS_EFISTUB_WRAPPERS
47 
48 #define efi_is_native()		(true)
49 #define efi_bs_call(func, ...)	efi_system_table->boottime->func(__VA_ARGS__)
50 #define efi_rt_call(func, ...)	efi_system_table->runtime->func(__VA_ARGS__)
51 #define efi_table_attr(inst, attr)	(inst->attr)
52 #define efi_call_proto(inst, func, ...) inst->func(inst, ##__VA_ARGS__)
53 
54 #endif
55 
56 #define efi_info(fmt, ...) \
57 	efi_printk(KERN_INFO fmt, ##__VA_ARGS__)
58 #define efi_err(fmt, ...) \
59 	efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
60 #define efi_debug(fmt, ...) \
61 	efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
62 
63 /* Helper macros for the usual case of using simple C variables: */
64 #ifndef fdt_setprop_inplace_var
65 #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
66 	fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
67 #endif
68 
69 #ifndef fdt_setprop_var
70 #define fdt_setprop_var(fdt, node_offset, name, var) \
71 	fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
72 #endif
73 
74 #define get_efi_var(name, vendor, ...)				\
75 	efi_rt_call(get_variable, (efi_char16_t *)(name),	\
76 		    (efi_guid_t *)(vendor), __VA_ARGS__)
77 
78 #define set_efi_var(name, vendor, ...)				\
79 	efi_rt_call(set_variable, (efi_char16_t *)(name),	\
80 		    (efi_guid_t *)(vendor), __VA_ARGS__)
81 
82 #define efi_get_handle_at(array, idx)					\
83 	(efi_is_native() ? (array)[idx] 				\
84 		: (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
85 
86 #define efi_get_handle_num(size)					\
87 	((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
88 
89 #define for_each_efi_handle(handle, array, size, i)			\
90 	for (i = 0;							\
91 	     i < efi_get_handle_num(size) &&				\
92 		((handle = efi_get_handle_at((array), i)) || true);	\
93 	     i++)
94 
95 static inline
96 void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
97 {
98 	*lo = lower_32_bits(data);
99 	*hi = upper_32_bits(data);
100 }
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 /*
111  * The type of search to perform when calling boottime->locate_handle
112  */
113 #define EFI_LOCATE_ALL_HANDLES			0
114 #define EFI_LOCATE_BY_REGISTER_NOTIFY		1
115 #define EFI_LOCATE_BY_PROTOCOL			2
116 
117 /*
118  * boottime->stall takes the time period in microseconds
119  */
120 #define EFI_USEC_PER_SEC		1000000
121 
122 /*
123  * boottime->set_timer takes the time in 100ns units
124  */
125 #define EFI_100NSEC_PER_USEC	((u64)10)
126 
127 /*
128  * An efi_boot_memmap is used by efi_get_memory_map() to return the
129  * EFI memory map in a dynamically allocated buffer.
130  *
131  * The buffer allocated for the EFI memory map includes extra room for
132  * a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.
133  * This facilitates the reuse of the EFI memory map buffer when a second
134  * call to ExitBootServices() is needed because of intervening changes to
135  * the EFI memory map. Other related structures, e.g. x86 e820ext, need
136  * to factor in this headroom requirement as well.
137  */
138 #define EFI_MMAP_NR_SLACK_SLOTS	8
139 
140 struct efi_boot_memmap {
141 	efi_memory_desc_t	**map;
142 	unsigned long		*map_size;
143 	unsigned long		*desc_size;
144 	u32			*desc_ver;
145 	unsigned long		*key_ptr;
146 	unsigned long		*buff_size;
147 };
148 
149 typedef struct efi_generic_dev_path efi_device_path_protocol_t;
150 
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 
155 #define EFI_EVT_TIMER		0x80000000U
156 #define EFI_EVT_RUNTIME		0x40000000U
157 #define EFI_EVT_NOTIFY_WAIT	0x00000100U
158 #define EFI_EVT_NOTIFY_SIGNAL	0x00000200U
159 
160 /*
161  * boottime->wait_for_event takes an array of events as input.
162  * Provide a helper to set it up correctly for mixed mode.
163  */
164 static inline
165 void efi_set_event_at(efi_event_t *events, size_t idx, efi_event_t event)
166 {
167 	if (efi_is_native())
168 		events[idx] = event;
169 	else
170 		((u32 *)events)[idx] = (u32)(unsigned long)event;
171 }
172 
173 #define EFI_TPL_APPLICATION	4
174 #define EFI_TPL_CALLBACK	8
175 #define EFI_TPL_NOTIFY		16
176 #define EFI_TPL_HIGH_LEVEL	31
177 
178 typedef enum {
179 	EfiTimerCancel,
180 	EfiTimerPeriodic,
181 	EfiTimerRelative
182 } EFI_TIMER_DELAY;
183 
184 /*
185  * EFI Boot Services table
186  */
187 union efi_boot_services {
188 	struct {
189 		efi_table_hdr_t hdr;
190 		void *raise_tpl;
191 		void *restore_tpl;
192 		efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
193 							efi_physical_addr_t *);
194 		efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
195 						    unsigned long);
196 		efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
197 							unsigned long *,
198 							unsigned long *, u32 *);
199 		efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
200 						       void **);
201 		efi_status_t (__efiapi *free_pool)(void *);
202 		efi_status_t (__efiapi *create_event)(u32, unsigned long,
203 						      efi_event_notify_t, void *,
204 						      efi_event_t *);
205 		efi_status_t (__efiapi *set_timer)(efi_event_t,
206 						  EFI_TIMER_DELAY, u64);
207 		efi_status_t (__efiapi *wait_for_event)(unsigned long,
208 							efi_event_t *,
209 							unsigned long *);
210 		void *signal_event;
211 		efi_status_t (__efiapi *close_event)(efi_event_t);
212 		void *check_event;
213 		void *install_protocol_interface;
214 		void *reinstall_protocol_interface;
215 		void *uninstall_protocol_interface;
216 		efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
217 							 efi_guid_t *, void **);
218 		void *__reserved;
219 		void *register_protocol_notify;
220 		efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
221 						       void *, unsigned long *,
222 						       efi_handle_t *);
223 		efi_status_t (__efiapi *locate_device_path)(efi_guid_t *,
224 							    efi_device_path_protocol_t **,
225 							    efi_handle_t *);
226 		efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
227 								     void *);
228 		void *load_image;
229 		void *start_image;
230 		efi_status_t __noreturn (__efiapi *exit)(efi_handle_t,
231 							 efi_status_t,
232 							 unsigned long,
233 							 efi_char16_t *);
234 		void *unload_image;
235 		efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
236 							    unsigned long);
237 		void *get_next_monotonic_count;
238 		efi_status_t (__efiapi *stall)(unsigned long);
239 		void *set_watchdog_timer;
240 		void *connect_controller;
241 		efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,
242 							       efi_handle_t,
243 							       efi_handle_t);
244 		void *open_protocol;
245 		void *close_protocol;
246 		void *open_protocol_information;
247 		void *protocols_per_handle;
248 		void *locate_handle_buffer;
249 		efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
250 							 void **);
251 		void *install_multiple_protocol_interfaces;
252 		void *uninstall_multiple_protocol_interfaces;
253 		void *calculate_crc32;
254 		void *copy_mem;
255 		void *set_mem;
256 		void *create_event_ex;
257 	};
258 	struct {
259 		efi_table_hdr_t hdr;
260 		u32 raise_tpl;
261 		u32 restore_tpl;
262 		u32 allocate_pages;
263 		u32 free_pages;
264 		u32 get_memory_map;
265 		u32 allocate_pool;
266 		u32 free_pool;
267 		u32 create_event;
268 		u32 set_timer;
269 		u32 wait_for_event;
270 		u32 signal_event;
271 		u32 close_event;
272 		u32 check_event;
273 		u32 install_protocol_interface;
274 		u32 reinstall_protocol_interface;
275 		u32 uninstall_protocol_interface;
276 		u32 handle_protocol;
277 		u32 __reserved;
278 		u32 register_protocol_notify;
279 		u32 locate_handle;
280 		u32 locate_device_path;
281 		u32 install_configuration_table;
282 		u32 load_image;
283 		u32 start_image;
284 		u32 exit;
285 		u32 unload_image;
286 		u32 exit_boot_services;
287 		u32 get_next_monotonic_count;
288 		u32 stall;
289 		u32 set_watchdog_timer;
290 		u32 connect_controller;
291 		u32 disconnect_controller;
292 		u32 open_protocol;
293 		u32 close_protocol;
294 		u32 open_protocol_information;
295 		u32 protocols_per_handle;
296 		u32 locate_handle_buffer;
297 		u32 locate_protocol;
298 		u32 install_multiple_protocol_interfaces;
299 		u32 uninstall_multiple_protocol_interfaces;
300 		u32 calculate_crc32;
301 		u32 copy_mem;
302 		u32 set_mem;
303 		u32 create_event_ex;
304 	} mixed_mode;
305 };
306 
307 typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
308 
309 union efi_uga_draw_protocol {
310 	struct {
311 		efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
312 						  u32*, u32*, u32*, u32*);
313 		void *set_mode;
314 		void *blt;
315 	};
316 	struct {
317 		u32 get_mode;
318 		u32 set_mode;
319 		u32 blt;
320 	} mixed_mode;
321 };
322 
323 typedef struct {
324 	u16 scan_code;
325 	efi_char16_t unicode_char;
326 } efi_input_key_t;
327 
328 union efi_simple_text_input_protocol {
329 	struct {
330 		void *reset;
331 		efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,
332 							efi_input_key_t *);
333 		efi_event_t wait_for_key;
334 	};
335 	struct {
336 		u32 reset;
337 		u32 read_keystroke;
338 		u32 wait_for_key;
339 	} mixed_mode;
340 };
341 
342 efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key);
343 
344 union efi_simple_text_output_protocol {
345 	struct {
346 		void *reset;
347 		efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
348 						       efi_char16_t *);
349 		void *test_string;
350 	};
351 	struct {
352 		u32 reset;
353 		u32 output_string;
354 		u32 test_string;
355 	} mixed_mode;
356 };
357 
358 #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR		0
359 #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR		1
360 #define PIXEL_BIT_MASK					2
361 #define PIXEL_BLT_ONLY					3
362 #define PIXEL_FORMAT_MAX				4
363 
364 typedef struct {
365 	u32 red_mask;
366 	u32 green_mask;
367 	u32 blue_mask;
368 	u32 reserved_mask;
369 } efi_pixel_bitmask_t;
370 
371 typedef struct {
372 	u32 version;
373 	u32 horizontal_resolution;
374 	u32 vertical_resolution;
375 	int pixel_format;
376 	efi_pixel_bitmask_t pixel_information;
377 	u32 pixels_per_scan_line;
378 } efi_graphics_output_mode_info_t;
379 
380 typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
381 
382 union efi_graphics_output_protocol_mode {
383 	struct {
384 		u32 max_mode;
385 		u32 mode;
386 		efi_graphics_output_mode_info_t *info;
387 		unsigned long size_of_info;
388 		efi_physical_addr_t frame_buffer_base;
389 		unsigned long frame_buffer_size;
390 	};
391 	struct {
392 		u32 max_mode;
393 		u32 mode;
394 		u32 info;
395 		u32 size_of_info;
396 		u64 frame_buffer_base;
397 		u32 frame_buffer_size;
398 	} mixed_mode;
399 };
400 
401 typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
402 
403 union efi_graphics_output_protocol {
404 	struct {
405 		efi_status_t (__efiapi *query_mode)(efi_graphics_output_protocol_t *,
406 						    u32, unsigned long *,
407 						    efi_graphics_output_mode_info_t **);
408 		efi_status_t (__efiapi *set_mode)  (efi_graphics_output_protocol_t *, u32);
409 		void *blt;
410 		efi_graphics_output_protocol_mode_t *mode;
411 	};
412 	struct {
413 		u32 query_mode;
414 		u32 set_mode;
415 		u32 blt;
416 		u32 mode;
417 	} mixed_mode;
418 };
419 
420 typedef union {
421 	struct {
422 		u32			revision;
423 		efi_handle_t		parent_handle;
424 		efi_system_table_t	*system_table;
425 		efi_handle_t		device_handle;
426 		void			*file_path;
427 		void			*reserved;
428 		u32			load_options_size;
429 		void			*load_options;
430 		void			*image_base;
431 		__aligned_u64		image_size;
432 		unsigned int		image_code_type;
433 		unsigned int		image_data_type;
434 		efi_status_t		(__efiapi *unload)(efi_handle_t image_handle);
435 	};
436 	struct {
437 		u32		revision;
438 		u32		parent_handle;
439 		u32		system_table;
440 		u32		device_handle;
441 		u32		file_path;
442 		u32		reserved;
443 		u32		load_options_size;
444 		u32		load_options;
445 		u32		image_base;
446 		__aligned_u64	image_size;
447 		u32		image_code_type;
448 		u32		image_data_type;
449 		u32		unload;
450 	} mixed_mode;
451 } efi_loaded_image_t;
452 
453 typedef struct {
454 	u64			size;
455 	u64			file_size;
456 	u64			phys_size;
457 	efi_time_t		create_time;
458 	efi_time_t		last_access_time;
459 	efi_time_t		modification_time;
460 	__aligned_u64		attribute;
461 	efi_char16_t		filename[];
462 } efi_file_info_t;
463 
464 typedef struct efi_file_protocol efi_file_protocol_t;
465 
466 struct efi_file_protocol {
467 	u64		revision;
468 	efi_status_t	(__efiapi *open)	(efi_file_protocol_t *,
469 						 efi_file_protocol_t **,
470 						 efi_char16_t *, u64, u64);
471 	efi_status_t	(__efiapi *close)	(efi_file_protocol_t *);
472 	efi_status_t	(__efiapi *delete)	(efi_file_protocol_t *);
473 	efi_status_t	(__efiapi *read)	(efi_file_protocol_t *,
474 						 unsigned long *, void *);
475 	efi_status_t	(__efiapi *write)	(efi_file_protocol_t *,
476 						 unsigned long, void *);
477 	efi_status_t	(__efiapi *get_position)(efi_file_protocol_t *, u64 *);
478 	efi_status_t	(__efiapi *set_position)(efi_file_protocol_t *, u64);
479 	efi_status_t	(__efiapi *get_info)	(efi_file_protocol_t *,
480 						 efi_guid_t *, unsigned long *,
481 						 void *);
482 	efi_status_t	(__efiapi *set_info)	(efi_file_protocol_t *,
483 						 efi_guid_t *, unsigned long,
484 						 void *);
485 	efi_status_t	(__efiapi *flush)	(efi_file_protocol_t *);
486 };
487 
488 typedef struct efi_simple_file_system_protocol efi_simple_file_system_protocol_t;
489 
490 struct efi_simple_file_system_protocol {
491 	u64	revision;
492 	int	(__efiapi *open_volume)(efi_simple_file_system_protocol_t *,
493 					efi_file_protocol_t **);
494 };
495 
496 #define EFI_FILE_MODE_READ	0x0000000000000001
497 #define EFI_FILE_MODE_WRITE	0x0000000000000002
498 #define EFI_FILE_MODE_CREATE	0x8000000000000000
499 
500 typedef enum {
501 	EfiPciIoWidthUint8,
502 	EfiPciIoWidthUint16,
503 	EfiPciIoWidthUint32,
504 	EfiPciIoWidthUint64,
505 	EfiPciIoWidthFifoUint8,
506 	EfiPciIoWidthFifoUint16,
507 	EfiPciIoWidthFifoUint32,
508 	EfiPciIoWidthFifoUint64,
509 	EfiPciIoWidthFillUint8,
510 	EfiPciIoWidthFillUint16,
511 	EfiPciIoWidthFillUint32,
512 	EfiPciIoWidthFillUint64,
513 	EfiPciIoWidthMaximum
514 } EFI_PCI_IO_PROTOCOL_WIDTH;
515 
516 typedef enum {
517 	EfiPciIoAttributeOperationGet,
518 	EfiPciIoAttributeOperationSet,
519 	EfiPciIoAttributeOperationEnable,
520 	EfiPciIoAttributeOperationDisable,
521 	EfiPciIoAttributeOperationSupported,
522     EfiPciIoAttributeOperationMaximum
523 } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
524 
525 typedef struct {
526 	u32 read;
527 	u32 write;
528 } efi_pci_io_protocol_access_32_t;
529 
530 typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
531 
532 typedef
533 efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
534 						   EFI_PCI_IO_PROTOCOL_WIDTH,
535 						   u32 offset,
536 						   unsigned long count,
537 						   void *buffer);
538 
539 typedef struct {
540 	void *read;
541 	void *write;
542 } efi_pci_io_protocol_access_t;
543 
544 typedef struct {
545 	efi_pci_io_protocol_cfg_t read;
546 	efi_pci_io_protocol_cfg_t write;
547 } efi_pci_io_protocol_config_access_t;
548 
549 union efi_pci_io_protocol {
550 	struct {
551 		void *poll_mem;
552 		void *poll_io;
553 		efi_pci_io_protocol_access_t mem;
554 		efi_pci_io_protocol_access_t io;
555 		efi_pci_io_protocol_config_access_t pci;
556 		void *copy_mem;
557 		void *map;
558 		void *unmap;
559 		void *allocate_buffer;
560 		void *free_buffer;
561 		void *flush;
562 		efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
563 						      unsigned long *segment_nr,
564 						      unsigned long *bus_nr,
565 						      unsigned long *device_nr,
566 						      unsigned long *func_nr);
567 		void *attributes;
568 		void *get_bar_attributes;
569 		void *set_bar_attributes;
570 		uint64_t romsize;
571 		void *romimage;
572 	};
573 	struct {
574 		u32 poll_mem;
575 		u32 poll_io;
576 		efi_pci_io_protocol_access_32_t mem;
577 		efi_pci_io_protocol_access_32_t io;
578 		efi_pci_io_protocol_access_32_t pci;
579 		u32 copy_mem;
580 		u32 map;
581 		u32 unmap;
582 		u32 allocate_buffer;
583 		u32 free_buffer;
584 		u32 flush;
585 		u32 get_location;
586 		u32 attributes;
587 		u32 get_bar_attributes;
588 		u32 set_bar_attributes;
589 		u64 romsize;
590 		u32 romimage;
591 	} mixed_mode;
592 };
593 
594 #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
595 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
596 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
597 #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
598 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
599 #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
600 #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
601 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
602 #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
603 #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
604 #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
605 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
606 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
607 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
608 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
609 #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
610 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
611 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
612 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
613 
614 struct efi_dev_path;
615 
616 typedef union apple_properties_protocol apple_properties_protocol_t;
617 
618 union apple_properties_protocol {
619 	struct {
620 		unsigned long version;
621 		efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
622 					     struct efi_dev_path *,
623 					     efi_char16_t *, void *, u32 *);
624 		efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
625 					     struct efi_dev_path *,
626 					     efi_char16_t *, void *, u32);
627 		efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
628 					     struct efi_dev_path *,
629 					     efi_char16_t *);
630 		efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
631 						 void *buffer, u32 *);
632 	};
633 	struct {
634 		u32 version;
635 		u32 get;
636 		u32 set;
637 		u32 del;
638 		u32 get_all;
639 	} mixed_mode;
640 };
641 
642 typedef u32 efi_tcg2_event_log_format;
643 
644 typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
645 
646 union efi_tcg2_protocol {
647 	struct {
648 		void *get_capability;
649 		efi_status_t (__efiapi *get_event_log)(efi_handle_t,
650 						       efi_tcg2_event_log_format,
651 						       efi_physical_addr_t *,
652 						       efi_physical_addr_t *,
653 						       efi_bool_t *);
654 		void *hash_log_extend_event;
655 		void *submit_command;
656 		void *get_active_pcr_banks;
657 		void *set_active_pcr_banks;
658 		void *get_result_of_set_active_pcr_banks;
659 	};
660 	struct {
661 		u32 get_capability;
662 		u32 get_event_log;
663 		u32 hash_log_extend_event;
664 		u32 submit_command;
665 		u32 get_active_pcr_banks;
666 		u32 set_active_pcr_banks;
667 		u32 get_result_of_set_active_pcr_banks;
668 	} mixed_mode;
669 };
670 
671 typedef union efi_load_file_protocol efi_load_file_protocol_t;
672 typedef union efi_load_file_protocol efi_load_file2_protocol_t;
673 
674 union efi_load_file_protocol {
675 	struct {
676 		efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,
677 						   efi_device_path_protocol_t *,
678 						   bool, unsigned long *, void *);
679 	};
680 	struct {
681 		u32 load_file;
682 	} mixed_mode;
683 };
684 
685 void efi_pci_disable_bridge_busmaster(void);
686 
687 typedef efi_status_t (*efi_exit_boot_map_processing)(
688 	struct efi_boot_memmap *map,
689 	void *priv);
690 
691 efi_status_t efi_exit_boot_services(void *handle,
692 				    struct efi_boot_memmap *map,
693 				    void *priv,
694 				    efi_exit_boot_map_processing priv_func);
695 
696 efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
697 					    unsigned long *new_fdt_addr,
698 					    unsigned long max_addr,
699 					    u64 initrd_addr, u64 initrd_size,
700 					    char *cmdline_ptr,
701 					    unsigned long fdt_addr,
702 					    unsigned long fdt_size);
703 
704 void *get_fdt(unsigned long *fdt_size);
705 
706 void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
707 		     unsigned long desc_size, efi_memory_desc_t *runtime_map,
708 		     int *count);
709 
710 efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
711 
712 efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
713 			      unsigned long *addr, unsigned long random_seed);
714 
715 efi_status_t check_platform_features(void);
716 
717 void *get_efi_config_table(efi_guid_t guid);
718 
719 /* NOTE: These functions do not print a trailing newline after the string */
720 void efi_char16_puts(efi_char16_t *);
721 void efi_puts(const char *str);
722 
723 __printf(1, 2) int efi_printk(char const *fmt, ...);
724 
725 void efi_free(unsigned long size, unsigned long addr);
726 
727 char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len);
728 
729 efi_status_t efi_get_memory_map(struct efi_boot_memmap *map);
730 
731 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
732 				unsigned long max);
733 
734 efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
735 					unsigned long max, unsigned long align);
736 
737 efi_status_t efi_relocate_kernel(unsigned long *image_addr,
738 				 unsigned long image_size,
739 				 unsigned long alloc_size,
740 				 unsigned long preferred_addr,
741 				 unsigned long alignment,
742 				 unsigned long min_addr);
743 
744 efi_status_t efi_parse_options(char const *cmdline);
745 
746 void efi_parse_option_graphics(char *option);
747 
748 efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
749 			   unsigned long size);
750 
751 efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
752 				  const efi_char16_t *optstr,
753 				  int optstr_size,
754 				  unsigned long soft_limit,
755 				  unsigned long hard_limit,
756 				  unsigned long *load_addr,
757 				  unsigned long *load_size);
758 
759 
760 static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,
761 					unsigned long *load_addr,
762 					unsigned long *load_size)
763 {
764 	return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,
765 				    ULONG_MAX, ULONG_MAX, load_addr, load_size);
766 }
767 
768 efi_status_t efi_load_initrd(efi_loaded_image_t *image,
769 			     unsigned long *load_addr,
770 			     unsigned long *load_size,
771 			     unsigned long soft_limit,
772 			     unsigned long hard_limit);
773 
774 #endif
775