xref: /openbmc/linux/arch/x86/boot/compressed/misc.h (revision 18da174d)
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_KASAN
15 #undef CONFIG_KASAN_GENERIC
16 
17 #define __NO_FORTIFY
18 
19 /* cpu_feature_enabled() cannot be used this early */
20 #define USE_EARLY_PGTABLE_L5
21 
22 /*
23  * Boot stub deals with identity mappings, physical and virtual addresses are
24  * the same, so override these defines.
25  *
26  * <asm/page.h> will not define them if they are already defined.
27  */
28 #define __pa(x)  ((unsigned long)(x))
29 #define __va(x)  ((void *)((unsigned long)(x)))
30 
31 #include <linux/linkage.h>
32 #include <linux/screen_info.h>
33 #include <linux/elf.h>
34 #include <asm/page.h>
35 #include <asm/boot.h>
36 #include <asm/bootparam.h>
37 #include <asm/desc_defs.h>
38 
39 #include "tdx.h"
40 
41 #define BOOT_CTYPE_H
42 #include <linux/acpi.h>
43 
44 #define BOOT_BOOT_H
45 #include "../ctype.h"
46 #include "../io.h"
47 
48 #include "efi.h"
49 
50 #ifdef CONFIG_X86_64
51 #define memptr long
52 #else
53 #define memptr unsigned
54 #endif
55 
56 /* boot/compressed/vmlinux start and end markers */
57 extern char _head[], _end[];
58 
59 /* misc.c */
60 extern memptr free_mem_ptr;
61 extern memptr free_mem_end_ptr;
62 void *malloc(int size);
63 void free(void *where);
64 extern struct boot_params *boot_params;
65 void __putstr(const char *s);
66 void __puthex(unsigned long value);
67 #define error_putstr(__x)  __putstr(__x)
68 #define error_puthex(__x)  __puthex(__x)
69 
70 #ifdef CONFIG_X86_VERBOSE_BOOTUP
71 
72 #define debug_putstr(__x)  __putstr(__x)
73 #define debug_puthex(__x)  __puthex(__x)
74 #define debug_putaddr(__x) { \
75 		debug_putstr(#__x ": 0x"); \
76 		debug_puthex((unsigned long)(__x)); \
77 		debug_putstr("\n"); \
78 	}
79 
80 #else
81 
82 static inline void debug_putstr(const char *s)
83 { }
84 static inline void debug_puthex(unsigned long value)
85 { }
86 #define debug_putaddr(x) /* */
87 
88 #endif
89 
90 /* cmdline.c */
91 int cmdline_find_option(const char *option, char *buffer, int bufsize);
92 int cmdline_find_option_bool(const char *option);
93 
94 struct mem_vector {
95 	u64 start;
96 	u64 size;
97 };
98 
99 #ifdef CONFIG_RANDOMIZE_BASE
100 /* kaslr.c */
101 void choose_random_location(unsigned long input,
102 			    unsigned long input_size,
103 			    unsigned long *output,
104 			    unsigned long output_size,
105 			    unsigned long *virt_addr);
106 #else
107 static inline void choose_random_location(unsigned long input,
108 					  unsigned long input_size,
109 					  unsigned long *output,
110 					  unsigned long output_size,
111 					  unsigned long *virt_addr)
112 {
113 }
114 #endif
115 
116 /* cpuflags.c */
117 bool has_cpuflag(int flag);
118 
119 #ifdef CONFIG_X86_64
120 extern int set_page_decrypted(unsigned long address);
121 extern int set_page_encrypted(unsigned long address);
122 extern int set_page_non_present(unsigned long address);
123 extern unsigned char _pgtable[];
124 #endif
125 
126 #ifdef CONFIG_EARLY_PRINTK
127 /* early_serial_console.c */
128 extern int early_serial_base;
129 void console_init(void);
130 #else
131 static const int early_serial_base;
132 static inline void console_init(void)
133 { }
134 #endif
135 
136 #ifdef CONFIG_AMD_MEM_ENCRYPT
137 void sev_enable(struct boot_params *bp);
138 void snp_check_features(void);
139 void sev_es_shutdown_ghcb(void);
140 extern bool sev_es_check_ghcb_fault(unsigned long address);
141 void snp_set_page_private(unsigned long paddr);
142 void snp_set_page_shared(unsigned long paddr);
143 void sev_prep_identity_maps(unsigned long top_level_pgt);
144 #else
145 static inline void sev_enable(struct boot_params *bp)
146 {
147 	/*
148 	 * bp->cc_blob_address should only be set by boot/compressed kernel.
149 	 * Initialize it to 0 unconditionally (thus here in this stub too) to
150 	 * ensure that uninitialized values from buggy bootloaders aren't
151 	 * propagated.
152 	 */
153 	if (bp)
154 		bp->cc_blob_address = 0;
155 }
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 #ifdef CONFIG_X86_5LEVEL
183 extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
184 #endif
185 extern void kernel_add_identity_map(unsigned long start, unsigned long end);
186 
187 /* Used by PAGE_KERN* macros: */
188 extern pteval_t __default_kernel_pte_mask;
189 
190 /* idt_64.c */
191 extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
192 extern struct desc_ptr boot_idt_desc;
193 
194 #ifdef CONFIG_X86_64
195 void cleanup_exception_handling(void);
196 #else
197 static inline void cleanup_exception_handling(void) { }
198 #endif
199 
200 /* IDT Entry Points */
201 void boot_page_fault(void);
202 void boot_stage1_vc(void);
203 void boot_stage2_vc(void);
204 
205 unsigned long sev_verify_cbit(unsigned long cr3);
206 
207 enum efi_type {
208 	EFI_TYPE_64,
209 	EFI_TYPE_32,
210 	EFI_TYPE_NONE,
211 };
212 
213 #ifdef CONFIG_EFI
214 /* helpers for early EFI config table access */
215 enum efi_type efi_get_type(struct boot_params *bp);
216 unsigned long efi_get_system_table(struct boot_params *bp);
217 int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
218 		       unsigned int *cfg_tbl_len);
219 unsigned long efi_find_vendor_table(struct boot_params *bp,
220 				    unsigned long cfg_tbl_pa,
221 				    unsigned int cfg_tbl_len,
222 				    efi_guid_t guid);
223 #else
224 static inline enum efi_type efi_get_type(struct boot_params *bp)
225 {
226 	return EFI_TYPE_NONE;
227 }
228 
229 static inline unsigned long efi_get_system_table(struct boot_params *bp)
230 {
231 	return 0;
232 }
233 
234 static inline int efi_get_conf_table(struct boot_params *bp,
235 				     unsigned long *cfg_tbl_pa,
236 				     unsigned int *cfg_tbl_len)
237 {
238 	return -ENOENT;
239 }
240 
241 static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
242 						  unsigned long cfg_tbl_pa,
243 						  unsigned int cfg_tbl_len,
244 						  efi_guid_t guid)
245 {
246 	return 0;
247 }
248 #endif /* CONFIG_EFI */
249 
250 #endif /* BOOT_COMPRESSED_MISC_H */
251