1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 28fee13a4SYinghai Lu #ifndef BOOT_COMPRESSED_MISC_H 38fee13a4SYinghai Lu #define BOOT_COMPRESSED_MISC_H 48fee13a4SYinghai Lu 58fee13a4SYinghai Lu /* 6927392d7SIngo Molnar * Special hack: we have to be careful, because no indirections are allowed here, 7927392d7SIngo Molnar * and paravirt_ops is a kind of one. As it will only run in baremetal anyway, 8927392d7SIngo Molnar * we just keep it from happening. (This list needs to be extended when new 9927392d7SIngo Molnar * paravirt and debugging variants are added.) 108fee13a4SYinghai Lu */ 118fee13a4SYinghai Lu #undef CONFIG_PARAVIRT 12c00a280aSJuergen Gross #undef CONFIG_PARAVIRT_XXL 13927392d7SIngo Molnar #undef CONFIG_PARAVIRT_SPINLOCKS 14393f203fSAndrey Ryabinin #undef CONFIG_KASAN 158a494023SAndrey Konovalov #undef CONFIG_KASAN_GENERIC 168fee13a4SYinghai Lu 17cfecea6eSKees Cook #define __NO_FORTIFY 18cfecea6eSKees Cook 19ad3fe525SKirill A. Shutemov /* cpu_feature_enabled() cannot be used this early */ 20ad3fe525SKirill A. Shutemov #define USE_EARLY_PGTABLE_L5 2139b95522SKirill A. Shutemov 228fee13a4SYinghai Lu #include <linux/linkage.h> 238fee13a4SYinghai Lu #include <linux/screen_info.h> 248fee13a4SYinghai Lu #include <linux/elf.h> 258fee13a4SYinghai Lu #include <linux/io.h> 268fee13a4SYinghai Lu #include <asm/page.h> 278fee13a4SYinghai Lu #include <asm/boot.h> 288fee13a4SYinghai Lu #include <asm/bootparam.h> 2964e68263SJoerg Roedel #include <asm/desc_defs.h> 308fee13a4SYinghai Lu 313c98e71bSChao Fan #define BOOT_CTYPE_H 323c98e71bSChao Fan #include <linux/acpi.h> 333c98e71bSChao Fan 348fee13a4SYinghai Lu #define BOOT_BOOT_H 356238b47bSH. Peter Anvin #include "../ctype.h" 368fee13a4SYinghai Lu 37*5dc91f2dSBorislav Petkov #include "efi.h" 38*5dc91f2dSBorislav Petkov 3982fa9637SKees Cook #ifdef CONFIG_X86_64 4082fa9637SKees Cook #define memptr long 4182fa9637SKees Cook #else 4282fa9637SKees Cook #define memptr unsigned 4382fa9637SKees Cook #endif 4482fa9637SKees Cook 458b0d3b3bSJoerg Roedel /* boot/compressed/vmlinux start and end markers */ 468b0d3b3bSJoerg Roedel extern char _head[], _end[]; 478b0d3b3bSJoerg Roedel 488fee13a4SYinghai Lu /* misc.c */ 4982fa9637SKees Cook extern memptr free_mem_ptr; 5082fa9637SKees Cook extern memptr free_mem_end_ptr; 5133f98a97SKees Cook void *malloc(int size); 5233f98a97SKees Cook void free(void *where); 536655e0aaSKees Cook extern struct boot_params *boot_params; 547aac3015SJoe Millenbach void __putstr(const char *s); 5579063a7cSKees Cook void __puthex(unsigned long value); 567aac3015SJoe Millenbach #define error_putstr(__x) __putstr(__x) 5779063a7cSKees Cook #define error_puthex(__x) __puthex(__x) 587aac3015SJoe Millenbach 597aac3015SJoe Millenbach #ifdef CONFIG_X86_VERBOSE_BOOTUP 607aac3015SJoe Millenbach 617aac3015SJoe Millenbach #define debug_putstr(__x) __putstr(__x) 6279063a7cSKees Cook #define debug_puthex(__x) __puthex(__x) 6379063a7cSKees Cook #define debug_putaddr(__x) { \ 6479063a7cSKees Cook debug_putstr(#__x ": 0x"); \ 6579063a7cSKees Cook debug_puthex((unsigned long)(__x)); \ 6679063a7cSKees Cook debug_putstr("\n"); \ 6779063a7cSKees Cook } 687aac3015SJoe Millenbach 697aac3015SJoe Millenbach #else 707aac3015SJoe Millenbach 717aac3015SJoe Millenbach static inline void debug_putstr(const char *s) 727aac3015SJoe Millenbach { } 73c90beea2SJoerg Roedel static inline void debug_puthex(unsigned long value) 7479063a7cSKees Cook { } 7579063a7cSKees Cook #define debug_putaddr(x) /* */ 767aac3015SJoe Millenbach 777aac3015SJoe Millenbach #endif 788fee13a4SYinghai Lu 798fee13a4SYinghai Lu /* cmdline.c */ 808fee13a4SYinghai Lu int cmdline_find_option(const char *option, char *buffer, int bufsize); 818fee13a4SYinghai Lu int cmdline_find_option_bool(const char *option); 828fee13a4SYinghai Lu 8302a3e3cdSChao Fan struct mem_vector { 843a066990SArvind Sankar u64 start; 853a066990SArvind Sankar u64 size; 8602a3e3cdSChao Fan }; 878ab3820fSKees Cook 88a554e740SNick Desaulniers #ifdef CONFIG_RANDOMIZE_BASE 899b238748SKees Cook /* kaslr.c */ 908391c73cSBaoquan He void choose_random_location(unsigned long input, 918ab3820fSKees Cook unsigned long input_size, 928391c73cSBaoquan He unsigned long *output, 938391c73cSBaoquan He unsigned long output_size, 948391c73cSBaoquan He unsigned long *virt_addr); 958ab3820fSKees Cook #else 968391c73cSBaoquan He static inline void choose_random_location(unsigned long input, 978ab3820fSKees Cook unsigned long input_size, 988391c73cSBaoquan He unsigned long *output, 998391c73cSBaoquan He unsigned long output_size, 1008391c73cSBaoquan He unsigned long *virt_addr) 1018ab3820fSKees Cook { 1028ab3820fSKees Cook } 1038ab3820fSKees Cook #endif 1048ab3820fSKees Cook 105f5ed7775SMartin Radev /* cpuflags.c */ 106f5ed7775SMartin Radev bool has_cpuflag(int flag); 107f5ed7775SMartin Radev 1083a94707dSKees Cook #ifdef CONFIG_X86_64 109c81d6002SJoerg Roedel extern int set_page_decrypted(unsigned long address); 110c81d6002SJoerg Roedel extern int set_page_encrypted(unsigned long address); 11169add17aSJoerg Roedel extern int set_page_non_present(unsigned long address); 1123a94707dSKees Cook extern unsigned char _pgtable[]; 1133a94707dSKees Cook #endif 1143a94707dSKees Cook 1158ab3820fSKees Cook #ifdef CONFIG_EARLY_PRINTK 1168fee13a4SYinghai Lu /* early_serial_console.c */ 1178fee13a4SYinghai Lu extern int early_serial_base; 1188fee13a4SYinghai Lu void console_init(void); 119cec49df9SJoe Millenbach #else 120cec49df9SJoe Millenbach static const int early_serial_base; 121cec49df9SJoe Millenbach static inline void console_init(void) 122cec49df9SJoe Millenbach { } 123cec49df9SJoe Millenbach #endif 124cec49df9SJoe Millenbach 125597cfe48SJoerg Roedel #ifdef CONFIG_AMD_MEM_ENCRYPT 126ec1c66afSMichael Roth void sev_enable(struct boot_params *bp); 127597cfe48SJoerg Roedel void sev_es_shutdown_ghcb(void); 12869add17aSJoerg Roedel extern bool sev_es_check_ghcb_fault(unsigned long address); 1294f9c403eSBrijesh Singh void snp_set_page_private(unsigned long paddr); 1304f9c403eSBrijesh Singh void snp_set_page_shared(unsigned long paddr); 13176f61e1eSMichael Roth void sev_prep_identity_maps(unsigned long top_level_pgt); 132597cfe48SJoerg Roedel #else 133ec1c66afSMichael Roth static inline void sev_enable(struct boot_params *bp) { } 134597cfe48SJoerg Roedel static inline void sev_es_shutdown_ghcb(void) { } 13569add17aSJoerg Roedel static inline bool sev_es_check_ghcb_fault(unsigned long address) 13669add17aSJoerg Roedel { 13769add17aSJoerg Roedel return false; 13869add17aSJoerg Roedel } 1394f9c403eSBrijesh Singh static inline void snp_set_page_private(unsigned long paddr) { } 1404f9c403eSBrijesh Singh static inline void snp_set_page_shared(unsigned long paddr) { } 14176f61e1eSMichael Roth static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { } 142597cfe48SJoerg Roedel #endif 143597cfe48SJoerg Roedel 1443a63f70bSChao Fan /* acpi.c */ 1453a63f70bSChao Fan #ifdef CONFIG_ACPI 1463a63f70bSChao Fan acpi_physical_address get_rsdp_addr(void); 1473a63f70bSChao Fan #else 1483a63f70bSChao Fan static inline acpi_physical_address get_rsdp_addr(void) { return 0; } 1493a63f70bSChao Fan #endif 15002a3e3cdSChao Fan 15182df8261SBorislav Petkov #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI) 152690eaa53SChao Fan extern struct mem_vector immovable_mem[MAX_NUMNODES*2]; 15302a3e3cdSChao Fan int count_immovable_mem_regions(void); 15402a3e3cdSChao Fan #else 15502a3e3cdSChao Fan static inline int count_immovable_mem_regions(void) { return 0; } 15602a3e3cdSChao Fan #endif 1570f02daedSBaoquan He 1585f2bb016SJoerg Roedel /* ident_map_64.c */ 1595f2bb016SJoerg Roedel #ifdef CONFIG_X86_5LEVEL 1605f2bb016SJoerg Roedel extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d; 1615f2bb016SJoerg Roedel #endif 162a9ee679bSMichael Roth extern void kernel_add_identity_map(unsigned long start, unsigned long end); 1635f2bb016SJoerg Roedel 1645f2bb016SJoerg Roedel /* Used by PAGE_KERN* macros: */ 1655f2bb016SJoerg Roedel extern pteval_t __default_kernel_pte_mask; 1665f2bb016SJoerg Roedel 16764e68263SJoerg Roedel /* idt_64.c */ 16864e68263SJoerg Roedel extern gate_desc boot_idt[BOOT_IDT_ENTRIES]; 16964e68263SJoerg Roedel extern struct desc_ptr boot_idt_desc; 17064e68263SJoerg Roedel 171b099155eSJoerg Roedel #ifdef CONFIG_X86_64 172b099155eSJoerg Roedel void cleanup_exception_handling(void); 173b099155eSJoerg Roedel #else 174b099155eSJoerg Roedel static inline void cleanup_exception_handling(void) { } 175b099155eSJoerg Roedel #endif 176b099155eSJoerg Roedel 1778b0d3b3bSJoerg Roedel /* IDT Entry Points */ 1788b0d3b3bSJoerg Roedel void boot_page_fault(void); 17929dcc60fSJoerg Roedel void boot_stage1_vc(void); 180597cfe48SJoerg Roedel void boot_stage2_vc(void); 1818b0d3b3bSJoerg Roedel 18286ce43f7SJoerg Roedel unsigned long sev_verify_cbit(unsigned long cr3); 18386ce43f7SJoerg Roedel 1847c4146e8SMichael Roth enum efi_type { 1857c4146e8SMichael Roth EFI_TYPE_64, 1867c4146e8SMichael Roth EFI_TYPE_32, 1877c4146e8SMichael Roth EFI_TYPE_NONE, 1887c4146e8SMichael Roth }; 1897c4146e8SMichael Roth 1907c4146e8SMichael Roth #ifdef CONFIG_EFI 1917c4146e8SMichael Roth /* helpers for early EFI config table access */ 1927c4146e8SMichael Roth enum efi_type efi_get_type(struct boot_params *bp); 19358f3e6b7SMichael Roth unsigned long efi_get_system_table(struct boot_params *bp); 19461c14cedSMichael Roth int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa, 19561c14cedSMichael Roth unsigned int *cfg_tbl_len); 196dee602ddSMichael Roth unsigned long efi_find_vendor_table(struct boot_params *bp, 197dee602ddSMichael Roth unsigned long cfg_tbl_pa, 198dee602ddSMichael Roth unsigned int cfg_tbl_len, 199dee602ddSMichael Roth efi_guid_t guid); 2007c4146e8SMichael Roth #else 2017c4146e8SMichael Roth static inline enum efi_type efi_get_type(struct boot_params *bp) 2027c4146e8SMichael Roth { 2037c4146e8SMichael Roth return EFI_TYPE_NONE; 2047c4146e8SMichael Roth } 20558f3e6b7SMichael Roth 20658f3e6b7SMichael Roth static inline unsigned long efi_get_system_table(struct boot_params *bp) 20758f3e6b7SMichael Roth { 20858f3e6b7SMichael Roth return 0; 20958f3e6b7SMichael Roth } 21061c14cedSMichael Roth 21161c14cedSMichael Roth static inline int efi_get_conf_table(struct boot_params *bp, 21261c14cedSMichael Roth unsigned long *cfg_tbl_pa, 21361c14cedSMichael Roth unsigned int *cfg_tbl_len) 21461c14cedSMichael Roth { 21561c14cedSMichael Roth return -ENOENT; 21661c14cedSMichael Roth } 217dee602ddSMichael Roth 218dee602ddSMichael Roth static inline unsigned long efi_find_vendor_table(struct boot_params *bp, 219dee602ddSMichael Roth unsigned long cfg_tbl_pa, 220dee602ddSMichael Roth unsigned int cfg_tbl_len, 221dee602ddSMichael Roth efi_guid_t guid) 222dee602ddSMichael Roth { 223dee602ddSMichael Roth return 0; 224dee602ddSMichael Roth } 2257c4146e8SMichael Roth #endif /* CONFIG_EFI */ 2267c4146e8SMichael Roth 2270f02daedSBaoquan He #endif /* BOOT_COMPRESSED_MISC_H */ 228