1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef BOOT_COMPRESSED_MISC_H
3 #define BOOT_COMPRESSED_MISC_H
6 * Special hack: we have to be careful, because no indirections are allowed here,
7 * and paravirt_ops is a kind of one. As it will only run in baremetal anyway,
8 * we just keep it from happening. (This list needs to be extended when new
9 * paravirt and debugging variants are added.)
11 #undef CONFIG_PARAVIRT
12 #undef CONFIG_PARAVIRT_XXL
13 #undef CONFIG_PARAVIRT_SPINLOCKS
15 #undef CONFIG_KASAN_GENERIC
19 /* cpu_feature_enabled() cannot be used this early */
20 #define USE_EARLY_PGTABLE_L5
23 * Boot stub deals with identity mappings, physical and virtual addresses are
24 * the same, so override these defines.
26 * <asm/page.h> will not define them if they are already defined.
28 #define __pa(x) ((unsigned long)(x))
29 #define __va(x) ((void *)((unsigned long)(x)))
31 #include <linux/linkage.h>
32 #include <linux/screen_info.h>
33 #include <linux/elf.h>
36 #include <asm/bootparam.h>
37 #include <asm/desc_defs.h>
42 #include <linux/acpi.h>
53 #define memptr unsigned
56 /* boot/compressed/vmlinux start and end markers */
57 extern char _head[], _end[];
60 extern memptr free_mem_ptr;
61 extern memptr free_mem_end_ptr;
62 extern int spurious_nmi_count;
63 void *malloc(int size);
64 void free(void *where);
65 void __putstr(const char *s);
66 void __puthex(unsigned long value);
67 void __putdec(unsigned long value);
68 #define error_putstr(__x) __putstr(__x)
69 #define error_puthex(__x) __puthex(__x)
70 #define error_putdec(__x) __putdec(__x)
72 #ifdef CONFIG_X86_VERBOSE_BOOTUP
74 #define debug_putstr(__x) __putstr(__x)
75 #define debug_puthex(__x) __puthex(__x)
76 #define debug_putaddr(__x) { \
77 debug_putstr(#__x ": 0x"); \
78 debug_puthex((unsigned long)(__x)); \
84 static inline void debug_putstr(const char *s)
86 static inline void debug_puthex(unsigned long value)
88 #define debug_putaddr(x) /* */
93 int cmdline_find_option(const char *option, char *buffer, int bufsize);
94 int cmdline_find_option_bool(const char *option);
101 #ifdef CONFIG_RANDOMIZE_BASE
103 void choose_random_location(unsigned long input,
104 unsigned long input_size,
105 unsigned long *output,
106 unsigned long output_size,
107 unsigned long *virt_addr);
109 static inline void choose_random_location(unsigned long input,
110 unsigned long input_size,
111 unsigned long *output,
112 unsigned long output_size,
113 unsigned long *virt_addr)
119 bool has_cpuflag(int flag);
122 extern int set_page_decrypted(unsigned long address);
123 extern int set_page_encrypted(unsigned long address);
124 extern int set_page_non_present(unsigned long address);
125 extern unsigned char _pgtable[];
128 #ifdef CONFIG_EARLY_PRINTK
129 /* early_serial_console.c */
130 extern int early_serial_base;
131 void console_init(void);
133 static const int early_serial_base;
134 static inline void console_init(void)
138 #ifdef CONFIG_AMD_MEM_ENCRYPT
139 void sev_enable(struct boot_params *bp);
140 void snp_check_features(void);
141 void sev_es_shutdown_ghcb(void);
142 extern bool sev_es_check_ghcb_fault(unsigned long address);
143 void snp_set_page_private(unsigned long paddr);
144 void snp_set_page_shared(unsigned long paddr);
145 void sev_prep_identity_maps(unsigned long top_level_pgt);
147 static inline void sev_enable(struct boot_params *bp)
150 * bp->cc_blob_address should only be set by boot/compressed kernel.
151 * Initialize it to 0 unconditionally (thus here in this stub too) to
152 * ensure that uninitialized values from buggy bootloaders aren't
156 bp->cc_blob_address = 0;
158 static inline void snp_check_features(void) { }
159 static inline void sev_es_shutdown_ghcb(void) { }
160 static inline bool sev_es_check_ghcb_fault(unsigned long address)
164 static inline void snp_set_page_private(unsigned long paddr) { }
165 static inline void snp_set_page_shared(unsigned long paddr) { }
166 static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { }
171 acpi_physical_address get_rsdp_addr(void);
173 static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
176 #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
177 extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
178 int count_immovable_mem_regions(void);
180 static inline int count_immovable_mem_regions(void) { return 0; }
184 extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
185 extern void kernel_add_identity_map(unsigned long start, unsigned long end);
187 /* Used by PAGE_KERN* macros: */
188 extern pteval_t __default_kernel_pte_mask;
191 extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
192 extern struct desc_ptr boot_idt_desc;
195 void cleanup_exception_handling(void);
197 static inline void cleanup_exception_handling(void) { }
200 /* IDT Entry Points */
201 void boot_page_fault(void);
202 void boot_nmi_trap(void);
203 void boot_stage1_vc(void);
204 void boot_stage2_vc(void);
206 unsigned long sev_verify_cbit(unsigned long cr3);
215 /* helpers for early EFI config table access */
216 enum efi_type efi_get_type(struct boot_params *bp);
217 unsigned long efi_get_system_table(struct boot_params *bp);
218 int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
219 unsigned int *cfg_tbl_len);
220 unsigned long efi_find_vendor_table(struct boot_params *bp,
221 unsigned long cfg_tbl_pa,
222 unsigned int cfg_tbl_len,
225 static inline enum efi_type efi_get_type(struct boot_params *bp)
227 return EFI_TYPE_NONE;
230 static inline unsigned long efi_get_system_table(struct boot_params *bp)
235 static inline int efi_get_conf_table(struct boot_params *bp,
236 unsigned long *cfg_tbl_pa,
237 unsigned int *cfg_tbl_len)
242 static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
243 unsigned long cfg_tbl_pa,
244 unsigned int cfg_tbl_len,
249 #endif /* CONFIG_EFI */
251 #ifdef CONFIG_UNACCEPTED_MEMORY
252 bool init_unaccepted_memory(void);
254 static inline bool init_unaccepted_memory(void) { return false; }
257 /* Defined in EFI stub */
258 extern struct efi_unaccepted_memory *unaccepted_table;
259 void accept_memory(phys_addr_t start, unsigned long size);
261 #endif /* BOOT_COMPRESSED_MISC_H */