1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
4 #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
6 /* error code which can't be mistaken for valid address */
7 #define EFI_ERROR (~0UL)
10 * __init annotations should not be used in the EFI stub, since the code is
11 * either included in the decompressor (x86, ARM) where they have no effect,
12 * or the whole stub is __init annotated at the section level (arm64), by
13 * renaming the sections, in which case the __init annotation will be
14 * redundant, and will result in section names like .init.init.text, and our
15 * linker script does not expect that.
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.
24 #ifndef EFI_ALLOC_ALIGN
25 #define EFI_ALLOC_ALIGN EFI_PAGE_SIZE
29 #define __efistub_global __section(.data)
31 #define __efistub_global
34 extern bool __pure nokaslr(void);
35 extern bool __pure is_quiet(void);
36 extern bool __pure novamap(void);
38 extern __pure efi_system_table_t *efi_system_table(void);
40 #define pr_efi(msg) do { \
41 if (!is_quiet()) efi_printk("EFI stub: "msg); \
44 #define pr_efi_err(msg) efi_printk("EFI stub: ERROR: "msg)
46 void efi_char16_printk(efi_char16_t *);
47 void efi_char16_printk(efi_char16_t *);
49 unsigned long get_dram_base(void);
51 efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
52 unsigned long *new_fdt_addr,
53 unsigned long max_addr,
54 u64 initrd_addr, u64 initrd_size,
56 unsigned long fdt_addr,
57 unsigned long fdt_size);
59 void *get_fdt(unsigned long *fdt_size);
61 void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
62 unsigned long desc_size, efi_memory_desc_t *runtime_map,
65 efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
67 efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
68 unsigned long *addr, unsigned long random_seed);
70 efi_status_t check_platform_features(void);
72 void *get_efi_config_table(efi_guid_t guid);
74 /* Helper macros for the usual case of using simple C variables: */
75 #ifndef fdt_setprop_inplace_var
76 #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
77 fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
80 #ifndef fdt_setprop_var
81 #define fdt_setprop_var(fdt, node_offset, name, var) \
82 fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
85 #define get_efi_var(name, vendor, ...) \
86 efi_rt_call(get_variable, (efi_char16_t *)(name), \
87 (efi_guid_t *)(vendor), __VA_ARGS__)
89 #define set_efi_var(name, vendor, ...) \
90 efi_rt_call(set_variable, (efi_char16_t *)(name), \
91 (efi_guid_t *)(vendor), __VA_ARGS__)