xref: /linux/arch/x86/boot/compressed/misc.h (revision 6aacab308a5dfd222b2d23662bbae60c11007cfb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef BOOT_COMPRESSED_MISC_H
3 #define BOOT_COMPRESSED_MISC_H
4 
5 /*
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.)
10  */
11 #undef CONFIG_PARAVIRT
12 #undef CONFIG_PARAVIRT_XXL
13 #undef CONFIG_PARAVIRT_SPINLOCKS
14 #undef CONFIG_ARCH_HAS_LAZY_MMU_MODE
15 #undef CONFIG_KASAN
16 #undef CONFIG_KASAN_GENERIC
17 
18 #define __NO_FORTIFY
19 
20 /* cpu_feature_enabled() cannot be used this early */
21 #define USE_EARLY_PGTABLE_L5
22 
23 /*
24  * Boot stub deals with identity mappings, physical and virtual addresses are
25  * the same, so override these defines.
26  *
27  * <asm/page.h> will not define them if they are already defined.
28  */
29 #define __pa(x)  ((unsigned long)(x))
30 #define __va(x)  ((void *)((unsigned long)(x)))
31 
32 #include <linux/linkage.h>
33 #include <linux/screen_info.h>
34 #include <linux/elf.h>
35 #include <asm/page.h>
36 #include <asm/boot.h>
37 #include <asm/bootparam.h>
38 #include <asm/desc_defs.h>
39 
40 #include "tdx.h"
41 
42 #define BOOT_CTYPE_H
43 #include <linux/acpi.h>
44 
45 #define BOOT_BOOT_H
46 #include "../ctype.h"
47 #include "../io.h"
48 
49 #include "efi.h"
50 
51 #ifdef CONFIG_X86_64
52 #define memptr long
53 #else
54 #define memptr unsigned
55 #endif
56 
57 /* boot/compressed/vmlinux start and end markers */
58 extern char _head[], _end[];
59 
60 /* misc.c */
61 extern memptr free_mem_ptr;
62 extern memptr free_mem_end_ptr;
63 extern int spurious_nmi_count;
64 void *malloc(int size);
65 void free(void *where);
66 void __putstr(const char *s);
67 void __puthex(unsigned long value);
68 void __putdec(unsigned long value);
69 #define error_putstr(__x)  __putstr(__x)
70 #define error_puthex(__x)  __puthex(__x)
71 #define error_putdec(__x)  __putdec(__x)
72 
73 #ifdef CONFIG_X86_VERBOSE_BOOTUP
74 
75 #define debug_putstr(__x)  __putstr(__x)
76 #define debug_puthex(__x)  __puthex(__x)
77 #define debug_putaddr(__x) { \
78 		debug_putstr(#__x ": 0x"); \
79 		debug_puthex((unsigned long)(__x)); \
80 		debug_putstr("\n"); \
81 	}
82 
83 #else
84 
85 static inline void debug_putstr(const char *s)
86 { }
87 static inline void debug_puthex(unsigned long value)
88 { }
89 #define debug_putaddr(x) /* */
90 
91 #endif
92 
93 /* cmdline.c */
94 int cmdline_find_option(const char *option, char *buffer, int bufsize);
95 int cmdline_find_option_bool(const char *option);
96 
97 struct mem_vector {
98 	u64 start;
99 	u64 size;
100 };
101 
102 #ifdef CONFIG_RANDOMIZE_BASE
103 /* kaslr.c */
104 void choose_random_location(unsigned long input,
105 			    unsigned long input_size,
106 			    unsigned long *output,
107 			    unsigned long output_size,
108 			    unsigned long *virt_addr);
109 #else
110 static inline void choose_random_location(unsigned long input,
111 					  unsigned long input_size,
112 					  unsigned long *output,
113 					  unsigned long output_size,
114 					  unsigned long *virt_addr)
115 {
116 }
117 #endif
118 
119 /* cpuflags.c */
120 bool has_cpuflag(int flag);
121 
122 #ifdef CONFIG_X86_64
123 extern int set_page_decrypted(unsigned long address);
124 extern int set_page_encrypted(unsigned long address);
125 extern int set_page_non_present(unsigned long address);
126 extern unsigned char _pgtable[];
127 #endif
128 
129 #ifdef CONFIG_EARLY_PRINTK
130 /* early_serial_console.c */
131 extern int early_serial_base;
132 void console_init(void);
133 #else
134 static const int early_serial_base;
135 static inline void console_init(void)
136 { }
137 #endif
138 
139 #ifdef CONFIG_AMD_MEM_ENCRYPT
140 struct es_em_ctxt;
141 struct insn;
142 
143 void sev_enable(struct boot_params *bp);
144 void snp_check_features(void);
145 void sev_es_shutdown_ghcb(void);
146 extern bool sev_es_check_ghcb_fault(unsigned long address);
147 void snp_set_page_private(unsigned long paddr);
148 void snp_set_page_shared(unsigned long paddr);
149 void sev_prep_identity_maps(unsigned long top_level_pgt);
150 
151 enum es_result vc_decode_insn(struct es_em_ctxt *ctxt);
152 bool insn_has_rep_prefix(struct insn *insn);
153 void sev_insn_decode_init(void);
154 bool early_setup_ghcb(void);
155 #else
156 static inline void snp_check_features(void) { }
157 static inline void sev_es_shutdown_ghcb(void) { }
158 static inline bool sev_es_check_ghcb_fault(unsigned long address)
159 {
160 	return false;
161 }
162 static inline void snp_set_page_private(unsigned long paddr) { }
163 static inline void snp_set_page_shared(unsigned long paddr) { }
164 static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { }
165 #endif
166 
167 /* acpi.c */
168 #ifdef CONFIG_ACPI
169 acpi_physical_address get_rsdp_addr(void);
170 #else
171 static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
172 #endif
173 
174 #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
175 extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
176 int count_immovable_mem_regions(void);
177 #else
178 static inline int count_immovable_mem_regions(void) { return 0; }
179 #endif
180 
181 /* ident_map_64.c */
182 extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
183 extern void kernel_add_identity_map(unsigned long start, unsigned long end);
184 
185 /* Used by PAGE_KERN* macros: */
186 extern pteval_t __default_kernel_pte_mask;
187 
188 /* idt_64.c */
189 extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
190 extern struct desc_ptr boot_idt_desc;
191 
192 #ifdef CONFIG_X86_64
193 void cleanup_exception_handling(void);
194 #else
195 static inline void cleanup_exception_handling(void) { }
196 #endif
197 
198 /* IDT Entry Points */
199 void boot_page_fault(void);
200 void boot_nmi_trap(void);
201 void boot_stage1_vc(void);
202 void boot_stage2_vc(void);
203 
204 unsigned long sev_verify_cbit(unsigned long cr3);
205 
206 enum efi_type {
207 	EFI_TYPE_64,
208 	EFI_TYPE_32,
209 	EFI_TYPE_NONE,
210 };
211 
212 #ifdef CONFIG_EFI
213 /* helpers for early EFI config table access */
214 enum efi_type efi_get_type(struct boot_params *bp);
215 unsigned long efi_get_system_table(struct boot_params *bp);
216 int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
217 		       unsigned int *cfg_tbl_len);
218 unsigned long efi_find_vendor_table(struct boot_params *bp,
219 				    unsigned long cfg_tbl_pa,
220 				    unsigned int cfg_tbl_len,
221 				    efi_guid_t guid);
222 #else
223 static inline enum efi_type efi_get_type(struct boot_params *bp)
224 {
225 	return EFI_TYPE_NONE;
226 }
227 
228 static inline unsigned long efi_get_system_table(struct boot_params *bp)
229 {
230 	return 0;
231 }
232 
233 static inline int efi_get_conf_table(struct boot_params *bp,
234 				     unsigned long *cfg_tbl_pa,
235 				     unsigned int *cfg_tbl_len)
236 {
237 	return -ENOENT;
238 }
239 
240 static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
241 						  unsigned long cfg_tbl_pa,
242 						  unsigned int cfg_tbl_len,
243 						  efi_guid_t guid)
244 {
245 	return 0;
246 }
247 #endif /* CONFIG_EFI */
248 
249 #ifdef CONFIG_UNACCEPTED_MEMORY
250 bool init_unaccepted_memory(void);
251 #else
252 static inline bool init_unaccepted_memory(void) { return false; }
253 #endif
254 
255 /* Defined in EFI stub */
256 extern struct efi_unaccepted_memory *unaccepted_table;
257 void accept_memory(phys_addr_t start, unsigned long size);
258 
259 #endif /* BOOT_COMPRESSED_MISC_H */
260