]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/firmware/efi/libstub/efistub.h
Linux 5.6-rc7
[linux.git] / drivers / firmware / efi / libstub / efistub.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
4 #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
5
6 /* error code which can't be mistaken for valid address */
7 #define EFI_ERROR       (~0UL)
8
9 /*
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.
16  */
17 #undef __init
18
19 /*
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.
23  */
24 #ifndef EFI_ALLOC_ALIGN
25 #define EFI_ALLOC_ALIGN         EFI_PAGE_SIZE
26 #endif
27
28 #ifdef CONFIG_ARM
29 #define __efistub_global        __section(.data)
30 #else
31 #define __efistub_global
32 #endif
33
34 extern bool __pure nokaslr(void);
35 extern bool __pure is_quiet(void);
36 extern bool __pure novamap(void);
37
38 extern __pure efi_system_table_t  *efi_system_table(void);
39
40 #define pr_efi(msg)             do {                    \
41         if (!is_quiet()) efi_printk("EFI stub: "msg);   \
42 } while (0)
43
44 #define pr_efi_err(msg) efi_printk("EFI stub: ERROR: "msg)
45
46 void efi_char16_printk(efi_char16_t *);
47 void efi_char16_printk(efi_char16_t *);
48
49 unsigned long get_dram_base(void);
50
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,
55                                             char *cmdline_ptr,
56                                             unsigned long fdt_addr,
57                                             unsigned long fdt_size);
58
59 void *get_fdt(unsigned long *fdt_size);
60
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,
63                      int *count);
64
65 efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
66
67 efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
68                               unsigned long *addr, unsigned long random_seed);
69
70 efi_status_t check_platform_features(void);
71
72 void *get_efi_config_table(efi_guid_t guid);
73
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))
78 #endif
79
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))
83 #endif
84
85 #define get_efi_var(name, vendor, ...)                          \
86         efi_rt_call(get_variable, (efi_char16_t *)(name),       \
87                     (efi_guid_t *)(vendor), __VA_ARGS__)
88
89 #define set_efi_var(name, vendor, ...)                          \
90         efi_rt_call(set_variable, (efi_char16_t *)(name),       \
91                     (efi_guid_t *)(vendor), __VA_ARGS__)
92
93 #endif