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