0001
0002 #ifndef BOOT_COMPRESSED_MISC_H
0003 #define BOOT_COMPRESSED_MISC_H
0004
0005
0006
0007
0008
0009
0010
0011 #undef CONFIG_PARAVIRT
0012 #undef CONFIG_PARAVIRT_XXL
0013 #undef CONFIG_PARAVIRT_SPINLOCKS
0014 #undef CONFIG_KASAN
0015 #undef CONFIG_KASAN_GENERIC
0016
0017 #define __NO_FORTIFY
0018
0019
0020 #define USE_EARLY_PGTABLE_L5
0021
0022 #include <linux/linkage.h>
0023 #include <linux/screen_info.h>
0024 #include <linux/elf.h>
0025 #include <asm/page.h>
0026 #include <asm/boot.h>
0027 #include <asm/bootparam.h>
0028 #include <asm/desc_defs.h>
0029
0030 #include "tdx.h"
0031
0032 #define BOOT_CTYPE_H
0033 #include <linux/acpi.h>
0034
0035 #define BOOT_BOOT_H
0036 #include "../ctype.h"
0037 #include "../io.h"
0038
0039 #include "efi.h"
0040
0041 #ifdef CONFIG_X86_64
0042 #define memptr long
0043 #else
0044 #define memptr unsigned
0045 #endif
0046
0047
0048 extern char _head[], _end[];
0049
0050
0051 extern memptr free_mem_ptr;
0052 extern memptr free_mem_end_ptr;
0053 void *malloc(int size);
0054 void free(void *where);
0055 extern struct boot_params *boot_params;
0056 void __putstr(const char *s);
0057 void __puthex(unsigned long value);
0058 #define error_putstr(__x) __putstr(__x)
0059 #define error_puthex(__x) __puthex(__x)
0060
0061 #ifdef CONFIG_X86_VERBOSE_BOOTUP
0062
0063 #define debug_putstr(__x) __putstr(__x)
0064 #define debug_puthex(__x) __puthex(__x)
0065 #define debug_putaddr(__x) { \
0066 debug_putstr(#__x ": 0x"); \
0067 debug_puthex((unsigned long)(__x)); \
0068 debug_putstr("\n"); \
0069 }
0070
0071 #else
0072
0073 static inline void debug_putstr(const char *s)
0074 { }
0075 static inline void debug_puthex(unsigned long value)
0076 { }
0077 #define debug_putaddr(x)
0078
0079 #endif
0080
0081
0082 int cmdline_find_option(const char *option, char *buffer, int bufsize);
0083 int cmdline_find_option_bool(const char *option);
0084
0085 struct mem_vector {
0086 u64 start;
0087 u64 size;
0088 };
0089
0090 #ifdef CONFIG_RANDOMIZE_BASE
0091
0092 void choose_random_location(unsigned long input,
0093 unsigned long input_size,
0094 unsigned long *output,
0095 unsigned long output_size,
0096 unsigned long *virt_addr);
0097 #else
0098 static inline void choose_random_location(unsigned long input,
0099 unsigned long input_size,
0100 unsigned long *output,
0101 unsigned long output_size,
0102 unsigned long *virt_addr)
0103 {
0104 }
0105 #endif
0106
0107
0108 bool has_cpuflag(int flag);
0109
0110 #ifdef CONFIG_X86_64
0111 extern int set_page_decrypted(unsigned long address);
0112 extern int set_page_encrypted(unsigned long address);
0113 extern int set_page_non_present(unsigned long address);
0114 extern unsigned char _pgtable[];
0115 #endif
0116
0117 #ifdef CONFIG_EARLY_PRINTK
0118
0119 extern int early_serial_base;
0120 void console_init(void);
0121 #else
0122 static const int early_serial_base;
0123 static inline void console_init(void)
0124 { }
0125 #endif
0126
0127 #ifdef CONFIG_AMD_MEM_ENCRYPT
0128 void sev_enable(struct boot_params *bp);
0129 void sev_es_shutdown_ghcb(void);
0130 extern bool sev_es_check_ghcb_fault(unsigned long address);
0131 void snp_set_page_private(unsigned long paddr);
0132 void snp_set_page_shared(unsigned long paddr);
0133 void sev_prep_identity_maps(unsigned long top_level_pgt);
0134 #else
0135 static inline void sev_enable(struct boot_params *bp)
0136 {
0137
0138
0139
0140
0141
0142
0143 if (bp)
0144 bp->cc_blob_address = 0;
0145 }
0146 static inline void sev_es_shutdown_ghcb(void) { }
0147 static inline bool sev_es_check_ghcb_fault(unsigned long address)
0148 {
0149 return false;
0150 }
0151 static inline void snp_set_page_private(unsigned long paddr) { }
0152 static inline void snp_set_page_shared(unsigned long paddr) { }
0153 static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { }
0154 #endif
0155
0156
0157 #ifdef CONFIG_ACPI
0158 acpi_physical_address get_rsdp_addr(void);
0159 #else
0160 static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
0161 #endif
0162
0163 #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
0164 extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
0165 int count_immovable_mem_regions(void);
0166 #else
0167 static inline int count_immovable_mem_regions(void) { return 0; }
0168 #endif
0169
0170
0171 #ifdef CONFIG_X86_5LEVEL
0172 extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
0173 #endif
0174 extern void kernel_add_identity_map(unsigned long start, unsigned long end);
0175
0176
0177 extern pteval_t __default_kernel_pte_mask;
0178
0179
0180 extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
0181 extern struct desc_ptr boot_idt_desc;
0182
0183 #ifdef CONFIG_X86_64
0184 void cleanup_exception_handling(void);
0185 #else
0186 static inline void cleanup_exception_handling(void) { }
0187 #endif
0188
0189
0190 void boot_page_fault(void);
0191 void boot_stage1_vc(void);
0192 void boot_stage2_vc(void);
0193
0194 unsigned long sev_verify_cbit(unsigned long cr3);
0195
0196 enum efi_type {
0197 EFI_TYPE_64,
0198 EFI_TYPE_32,
0199 EFI_TYPE_NONE,
0200 };
0201
0202 #ifdef CONFIG_EFI
0203
0204 enum efi_type efi_get_type(struct boot_params *bp);
0205 unsigned long efi_get_system_table(struct boot_params *bp);
0206 int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
0207 unsigned int *cfg_tbl_len);
0208 unsigned long efi_find_vendor_table(struct boot_params *bp,
0209 unsigned long cfg_tbl_pa,
0210 unsigned int cfg_tbl_len,
0211 efi_guid_t guid);
0212 #else
0213 static inline enum efi_type efi_get_type(struct boot_params *bp)
0214 {
0215 return EFI_TYPE_NONE;
0216 }
0217
0218 static inline unsigned long efi_get_system_table(struct boot_params *bp)
0219 {
0220 return 0;
0221 }
0222
0223 static inline int efi_get_conf_table(struct boot_params *bp,
0224 unsigned long *cfg_tbl_pa,
0225 unsigned int *cfg_tbl_len)
0226 {
0227 return -ENOENT;
0228 }
0229
0230 static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
0231 unsigned long cfg_tbl_pa,
0232 unsigned int cfg_tbl_len,
0233 efi_guid_t guid)
0234 {
0235 return 0;
0236 }
0237 #endif
0238
0239 #endif