1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2f4f75ad5SArd Biesheuvel 
3f4f75ad5SArd Biesheuvel #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
4f4f75ad5SArd Biesheuvel #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
5f4f75ad5SArd Biesheuvel 
6f4f75ad5SArd Biesheuvel /* error code which can't be mistaken for valid address */
7f4f75ad5SArd Biesheuvel #define EFI_ERROR	(~0UL)
8f4f75ad5SArd Biesheuvel 
907e83dbbSArd Biesheuvel /*
1007e83dbbSArd Biesheuvel  * __init annotations should not be used in the EFI stub, since the code is
1107e83dbbSArd Biesheuvel  * either included in the decompressor (x86, ARM) where they have no effect,
1207e83dbbSArd Biesheuvel  * or the whole stub is __init annotated at the section level (arm64), by
1307e83dbbSArd Biesheuvel  * renaming the sections, in which case the __init annotation will be
1407e83dbbSArd Biesheuvel  * redundant, and will result in section names like .init.init.text, and our
1507e83dbbSArd Biesheuvel  * linker script does not expect that.
1607e83dbbSArd Biesheuvel  */
1707e83dbbSArd Biesheuvel #undef __init
1807e83dbbSArd Biesheuvel 
19a6a14469SArd Biesheuvel /*
20a6a14469SArd Biesheuvel  * Allow the platform to override the allocation granularity: this allows
21a6a14469SArd Biesheuvel  * systems that have the capability to run with a larger page size to deal
22a6a14469SArd Biesheuvel  * with the allocations for initrd and fdt more efficiently.
23a6a14469SArd Biesheuvel  */
24a6a14469SArd Biesheuvel #ifndef EFI_ALLOC_ALIGN
25a6a14469SArd Biesheuvel #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
26a6a14469SArd Biesheuvel #endif
27a6a14469SArd Biesheuvel 
287d4e323dSArd Biesheuvel #ifdef CONFIG_ARM
297d4e323dSArd Biesheuvel #define __efistub_global	__section(.data)
307d4e323dSArd Biesheuvel #else
317d4e323dSArd Biesheuvel #define __efistub_global
327d4e323dSArd Biesheuvel #endif
337d4e323dSArd Biesheuvel 
347d4e323dSArd Biesheuvel extern bool __pure nokaslr(void);
357d4e323dSArd Biesheuvel extern bool __pure is_quiet(void);
367d4e323dSArd Biesheuvel extern bool __pure novamap(void);
37eeff7d63SArd Biesheuvel 
382fcdad2aSArd Biesheuvel extern __pure efi_system_table_t  *efi_system_table(void);
392fcdad2aSArd Biesheuvel 
408173ec79SArd Biesheuvel #define pr_efi(msg)		do {			\
418173ec79SArd Biesheuvel 	if (!is_quiet()) efi_printk("EFI stub: "msg);	\
42eeff7d63SArd Biesheuvel } while (0)
43eeff7d63SArd Biesheuvel 
448173ec79SArd Biesheuvel #define pr_efi_err(msg) efi_printk("EFI stub: ERROR: "msg)
4560f38de7SArd Biesheuvel 
468173ec79SArd Biesheuvel void efi_char16_printk(efi_char16_t *);
478173ec79SArd Biesheuvel void efi_char16_printk(efi_char16_t *);
48f4f75ad5SArd Biesheuvel 
49cd33a5c1SArd Biesheuvel unsigned long get_dram_base(void);
50f4f75ad5SArd Biesheuvel 
51cd33a5c1SArd Biesheuvel efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
52f4f75ad5SArd Biesheuvel 					    unsigned long *new_fdt_addr,
53f4f75ad5SArd Biesheuvel 					    unsigned long max_addr,
54f4f75ad5SArd Biesheuvel 					    u64 initrd_addr, u64 initrd_size,
55f4f75ad5SArd Biesheuvel 					    char *cmdline_ptr,
56f4f75ad5SArd Biesheuvel 					    unsigned long fdt_addr,
57f4f75ad5SArd Biesheuvel 					    unsigned long fdt_size);
58f4f75ad5SArd Biesheuvel 
59cd33a5c1SArd Biesheuvel void *get_fdt(unsigned long *fdt_size);
60f4f75ad5SArd Biesheuvel 
61f3cdfd23SArd Biesheuvel void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
62f3cdfd23SArd Biesheuvel 		     unsigned long desc_size, efi_memory_desc_t *runtime_map,
63f3cdfd23SArd Biesheuvel 		     int *count);
64f3cdfd23SArd Biesheuvel 
65cd33a5c1SArd Biesheuvel efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
66e4fbf476SArd Biesheuvel 
67cd33a5c1SArd Biesheuvel efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
682ddbfc81SArd Biesheuvel 			      unsigned long *addr, unsigned long random_seed);
692ddbfc81SArd Biesheuvel 
70cd33a5c1SArd Biesheuvel efi_status_t check_platform_features(void);
71b9d6769bSArd Biesheuvel 
72cd33a5c1SArd Biesheuvel void *get_efi_config_table(efi_guid_t guid);
7382d736acSMatthew Garrett 
74ac9aff8eSIngo Molnar /* Helper macros for the usual case of using simple C variables: */
75ac9aff8eSIngo Molnar #ifndef fdt_setprop_inplace_var
76ac9aff8eSIngo Molnar #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
77ac9aff8eSIngo Molnar 	fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
78ac9aff8eSIngo Molnar #endif
79ac9aff8eSIngo Molnar 
80ac9aff8eSIngo Molnar #ifndef fdt_setprop_var
81ac9aff8eSIngo Molnar #define fdt_setprop_var(fdt, node_offset, name, var) \
82ac9aff8eSIngo Molnar 	fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
83ac9aff8eSIngo Molnar #endif
84ac9aff8eSIngo Molnar 
85966291f6SArd Biesheuvel #define get_efi_var(name, vendor, ...)				\
86966291f6SArd Biesheuvel 	efi_rt_call(get_variable, (efi_char16_t *)(name),	\
87966291f6SArd Biesheuvel 		    (efi_guid_t *)(vendor), __VA_ARGS__)
88966291f6SArd Biesheuvel 
89966291f6SArd Biesheuvel #define set_efi_var(name, vendor, ...)				\
90966291f6SArd Biesheuvel 	efi_rt_call(set_variable, (efi_char16_t *)(name),	\
91966291f6SArd Biesheuvel 		    (efi_guid_t *)(vendor), __VA_ARGS__)
92966291f6SArd Biesheuvel 
93c2d0b470SArd Biesheuvel typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
94c2d0b470SArd Biesheuvel 
95c2d0b470SArd Biesheuvel union efi_uga_draw_protocol {
96c2d0b470SArd Biesheuvel 	struct {
97c2d0b470SArd Biesheuvel 		efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
98c2d0b470SArd Biesheuvel 						  u32*, u32*, u32*, u32*);
99c2d0b470SArd Biesheuvel 		void *set_mode;
100c2d0b470SArd Biesheuvel 		void *blt;
101c2d0b470SArd Biesheuvel 	};
102c2d0b470SArd Biesheuvel 	struct {
103c2d0b470SArd Biesheuvel 		u32 get_mode;
104c2d0b470SArd Biesheuvel 		u32 set_mode;
105c2d0b470SArd Biesheuvel 		u32 blt;
106c2d0b470SArd Biesheuvel 	} mixed_mode;
107c2d0b470SArd Biesheuvel };
108c2d0b470SArd Biesheuvel 
109f4f75ad5SArd Biesheuvel #endif
110