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 
2860f38de7SArd Biesheuvel extern int __pure nokaslr(void);
29eeff7d63SArd Biesheuvel extern int __pure is_quiet(void);
304e46c2a9SArd Biesheuvel extern int __pure novamap(void);
31eeff7d63SArd Biesheuvel 
32eeff7d63SArd Biesheuvel #define pr_efi(sys_table, msg)		do {				\
33eeff7d63SArd Biesheuvel 	if (!is_quiet()) efi_printk(sys_table, "EFI stub: "msg);	\
34eeff7d63SArd Biesheuvel } while (0)
35eeff7d63SArd Biesheuvel 
36eeff7d63SArd Biesheuvel #define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg)
3760f38de7SArd Biesheuvel 
38f4f75ad5SArd Biesheuvel void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
39f4f75ad5SArd Biesheuvel 
40f4f75ad5SArd Biesheuvel unsigned long get_dram_base(efi_system_table_t *sys_table_arg);
41f4f75ad5SArd Biesheuvel 
42f4f75ad5SArd Biesheuvel efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table,
43f4f75ad5SArd Biesheuvel 					    void *handle,
44f4f75ad5SArd Biesheuvel 					    unsigned long *new_fdt_addr,
45f4f75ad5SArd Biesheuvel 					    unsigned long max_addr,
46f4f75ad5SArd Biesheuvel 					    u64 initrd_addr, u64 initrd_size,
47f4f75ad5SArd Biesheuvel 					    char *cmdline_ptr,
48f4f75ad5SArd Biesheuvel 					    unsigned long fdt_addr,
49f4f75ad5SArd Biesheuvel 					    unsigned long fdt_size);
50f4f75ad5SArd Biesheuvel 
51a643375fSArd Biesheuvel void *get_fdt(efi_system_table_t *sys_table, unsigned long *fdt_size);
52f4f75ad5SArd Biesheuvel 
53f3cdfd23SArd Biesheuvel void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
54f3cdfd23SArd Biesheuvel 		     unsigned long desc_size, efi_memory_desc_t *runtime_map,
55f3cdfd23SArd Biesheuvel 		     int *count);
56f3cdfd23SArd Biesheuvel 
57e4fbf476SArd Biesheuvel efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table,
58e4fbf476SArd Biesheuvel 				  unsigned long size, u8 *out);
59e4fbf476SArd Biesheuvel 
602ddbfc81SArd Biesheuvel efi_status_t efi_random_alloc(efi_system_table_t *sys_table_arg,
612ddbfc81SArd Biesheuvel 			      unsigned long size, unsigned long align,
622ddbfc81SArd Biesheuvel 			      unsigned long *addr, unsigned long random_seed);
632ddbfc81SArd Biesheuvel 
64b9d6769bSArd Biesheuvel efi_status_t check_platform_features(efi_system_table_t *sys_table_arg);
65b9d6769bSArd Biesheuvel 
66568bc4e8SArd Biesheuvel efi_status_t efi_random_get_seed(efi_system_table_t *sys_table_arg);
67568bc4e8SArd Biesheuvel 
6882d736acSMatthew Garrett void *get_efi_config_table(efi_system_table_t *sys_table, efi_guid_t guid);
6982d736acSMatthew Garrett 
70ac9aff8eSIngo Molnar /* Helper macros for the usual case of using simple C variables: */
71ac9aff8eSIngo Molnar #ifndef fdt_setprop_inplace_var
72ac9aff8eSIngo Molnar #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
73ac9aff8eSIngo Molnar 	fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
74ac9aff8eSIngo Molnar #endif
75ac9aff8eSIngo Molnar 
76ac9aff8eSIngo Molnar #ifndef fdt_setprop_var
77ac9aff8eSIngo Molnar #define fdt_setprop_var(fdt, node_offset, name, var) \
78ac9aff8eSIngo Molnar 	fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
79ac9aff8eSIngo Molnar #endif
80ac9aff8eSIngo Molnar 
81f4f75ad5SArd Biesheuvel #endif
82