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 #include <linux/linkage.h> 23 #include <linux/screen_info.h> 24 #include <linux/elf.h> 25 #include <linux/io.h> 26 #include <asm/page.h> 27 #include <asm/boot.h> 28 #include <asm/bootparam.h> 29 #include <asm/desc_defs.h> 30 31 #define BOOT_CTYPE_H 32 #include <linux/acpi.h> 33 34 #define BOOT_BOOT_H 35 #include "../ctype.h" 36 37 #include "efi.h" 38 39 #ifdef CONFIG_X86_64 40 #define memptr long 41 #else 42 #define memptr unsigned 43 #endif 44 45 /* boot/compressed/vmlinux start and end markers */ 46 extern char _head[], _end[]; 47 48 /* misc.c */ 49 extern memptr free_mem_ptr; 50 extern memptr free_mem_end_ptr; 51 void *malloc(int size); 52 void free(void *where); 53 extern struct boot_params *boot_params; 54 void __putstr(const char *s); 55 void __puthex(unsigned long value); 56 #define error_putstr(__x) __putstr(__x) 57 #define error_puthex(__x) __puthex(__x) 58 59 #ifdef CONFIG_X86_VERBOSE_BOOTUP 60 61 #define debug_putstr(__x) __putstr(__x) 62 #define debug_puthex(__x) __puthex(__x) 63 #define debug_putaddr(__x) { \ 64 debug_putstr(#__x ": 0x"); \ 65 debug_puthex((unsigned long)(__x)); \ 66 debug_putstr("\n"); \ 67 } 68 69 #else 70 71 static inline void debug_putstr(const char *s) 72 { } 73 static inline void debug_puthex(unsigned long value) 74 { } 75 #define debug_putaddr(x) /* */ 76 77 #endif 78 79 /* cmdline.c */ 80 int cmdline_find_option(const char *option, char *buffer, int bufsize); 81 int cmdline_find_option_bool(const char *option); 82 83 struct mem_vector { 84 u64 start; 85 u64 size; 86 }; 87 88 #ifdef CONFIG_RANDOMIZE_BASE 89 /* kaslr.c */ 90 void choose_random_location(unsigned long input, 91 unsigned long input_size, 92 unsigned long *output, 93 unsigned long output_size, 94 unsigned long *virt_addr); 95 #else 96 static inline void choose_random_location(unsigned long input, 97 unsigned long input_size, 98 unsigned long *output, 99 unsigned long output_size, 100 unsigned long *virt_addr) 101 { 102 } 103 #endif 104 105 /* cpuflags.c */ 106 bool has_cpuflag(int flag); 107 108 #ifdef CONFIG_X86_64 109 extern int set_page_decrypted(unsigned long address); 110 extern int set_page_encrypted(unsigned long address); 111 extern int set_page_non_present(unsigned long address); 112 extern unsigned char _pgtable[]; 113 #endif 114 115 #ifdef CONFIG_EARLY_PRINTK 116 /* early_serial_console.c */ 117 extern int early_serial_base; 118 void console_init(void); 119 #else 120 static const int early_serial_base; 121 static inline void console_init(void) 122 { } 123 #endif 124 125 #ifdef CONFIG_AMD_MEM_ENCRYPT 126 void sev_enable(struct boot_params *bp); 127 void sev_es_shutdown_ghcb(void); 128 extern bool sev_es_check_ghcb_fault(unsigned long address); 129 void snp_set_page_private(unsigned long paddr); 130 void snp_set_page_shared(unsigned long paddr); 131 void sev_prep_identity_maps(unsigned long top_level_pgt); 132 #else 133 static inline void sev_enable(struct boot_params *bp) { } 134 static inline void sev_es_shutdown_ghcb(void) { } 135 static inline bool sev_es_check_ghcb_fault(unsigned long address) 136 { 137 return false; 138 } 139 static inline void snp_set_page_private(unsigned long paddr) { } 140 static inline void snp_set_page_shared(unsigned long paddr) { } 141 static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { } 142 #endif 143 144 /* acpi.c */ 145 #ifdef CONFIG_ACPI 146 acpi_physical_address get_rsdp_addr(void); 147 #else 148 static inline acpi_physical_address get_rsdp_addr(void) { return 0; } 149 #endif 150 151 #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI) 152 extern struct mem_vector immovable_mem[MAX_NUMNODES*2]; 153 int count_immovable_mem_regions(void); 154 #else 155 static inline int count_immovable_mem_regions(void) { return 0; } 156 #endif 157 158 /* ident_map_64.c */ 159 #ifdef CONFIG_X86_5LEVEL 160 extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d; 161 #endif 162 extern void kernel_add_identity_map(unsigned long start, unsigned long end); 163 164 /* Used by PAGE_KERN* macros: */ 165 extern pteval_t __default_kernel_pte_mask; 166 167 /* idt_64.c */ 168 extern gate_desc boot_idt[BOOT_IDT_ENTRIES]; 169 extern struct desc_ptr boot_idt_desc; 170 171 #ifdef CONFIG_X86_64 172 void cleanup_exception_handling(void); 173 #else 174 static inline void cleanup_exception_handling(void) { } 175 #endif 176 177 /* IDT Entry Points */ 178 void boot_page_fault(void); 179 void boot_stage1_vc(void); 180 void boot_stage2_vc(void); 181 182 unsigned long sev_verify_cbit(unsigned long cr3); 183 184 enum efi_type { 185 EFI_TYPE_64, 186 EFI_TYPE_32, 187 EFI_TYPE_NONE, 188 }; 189 190 #ifdef CONFIG_EFI 191 /* helpers for early EFI config table access */ 192 enum efi_type efi_get_type(struct boot_params *bp); 193 unsigned long efi_get_system_table(struct boot_params *bp); 194 int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa, 195 unsigned int *cfg_tbl_len); 196 unsigned long efi_find_vendor_table(struct boot_params *bp, 197 unsigned long cfg_tbl_pa, 198 unsigned int cfg_tbl_len, 199 efi_guid_t guid); 200 #else 201 static inline enum efi_type efi_get_type(struct boot_params *bp) 202 { 203 return EFI_TYPE_NONE; 204 } 205 206 static inline unsigned long efi_get_system_table(struct boot_params *bp) 207 { 208 return 0; 209 } 210 211 static inline int efi_get_conf_table(struct boot_params *bp, 212 unsigned long *cfg_tbl_pa, 213 unsigned int *cfg_tbl_len) 214 { 215 return -ENOENT; 216 } 217 218 static inline 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 { 223 return 0; 224 } 225 #endif /* CONFIG_EFI */ 226 227 #endif /* BOOT_COMPRESSED_MISC_H */ 228