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 3782fa9637SKees Cook #ifdef CONFIG_X86_64 3882fa9637SKees Cook #define memptr long 3982fa9637SKees Cook #else 4082fa9637SKees Cook #define memptr unsigned 4182fa9637SKees Cook #endif 4282fa9637SKees Cook 438b0d3b3bSJoerg Roedel /* boot/compressed/vmlinux start and end markers */ 448b0d3b3bSJoerg Roedel extern char _head[], _end[]; 458b0d3b3bSJoerg Roedel 468fee13a4SYinghai Lu /* misc.c */ 4782fa9637SKees Cook extern memptr free_mem_ptr; 4882fa9637SKees Cook extern memptr free_mem_end_ptr; 4933f98a97SKees Cook void *malloc(int size); 5033f98a97SKees Cook void free(void *where); 516655e0aaSKees Cook extern struct boot_params *boot_params; 527aac3015SJoe Millenbach void __putstr(const char *s); 5379063a7cSKees Cook void __puthex(unsigned long value); 547aac3015SJoe Millenbach #define error_putstr(__x) __putstr(__x) 5579063a7cSKees Cook #define error_puthex(__x) __puthex(__x) 567aac3015SJoe Millenbach 577aac3015SJoe Millenbach #ifdef CONFIG_X86_VERBOSE_BOOTUP 587aac3015SJoe Millenbach 597aac3015SJoe Millenbach #define debug_putstr(__x) __putstr(__x) 6079063a7cSKees Cook #define debug_puthex(__x) __puthex(__x) 6179063a7cSKees Cook #define debug_putaddr(__x) { \ 6279063a7cSKees Cook debug_putstr(#__x ": 0x"); \ 6379063a7cSKees Cook debug_puthex((unsigned long)(__x)); \ 6479063a7cSKees Cook debug_putstr("\n"); \ 6579063a7cSKees Cook } 667aac3015SJoe Millenbach 677aac3015SJoe Millenbach #else 687aac3015SJoe Millenbach 697aac3015SJoe Millenbach static inline void debug_putstr(const char *s) 707aac3015SJoe Millenbach { } 71c90beea2SJoerg Roedel static inline void debug_puthex(unsigned long value) 7279063a7cSKees Cook { } 7379063a7cSKees Cook #define debug_putaddr(x) /* */ 747aac3015SJoe Millenbach 757aac3015SJoe Millenbach #endif 768fee13a4SYinghai Lu 778fee13a4SYinghai Lu /* cmdline.c */ 788fee13a4SYinghai Lu int cmdline_find_option(const char *option, char *buffer, int bufsize); 798fee13a4SYinghai Lu int cmdline_find_option_bool(const char *option); 808fee13a4SYinghai Lu 8102a3e3cdSChao Fan struct mem_vector { 823a066990SArvind Sankar u64 start; 833a066990SArvind Sankar u64 size; 8402a3e3cdSChao Fan }; 858ab3820fSKees Cook 86a554e740SNick Desaulniers #ifdef CONFIG_RANDOMIZE_BASE 879b238748SKees Cook /* kaslr.c */ 888391c73cSBaoquan He void choose_random_location(unsigned long input, 898ab3820fSKees Cook unsigned long input_size, 908391c73cSBaoquan He unsigned long *output, 918391c73cSBaoquan He unsigned long output_size, 928391c73cSBaoquan He unsigned long *virt_addr); 938ab3820fSKees Cook #else 948391c73cSBaoquan He static inline void choose_random_location(unsigned long input, 958ab3820fSKees Cook unsigned long input_size, 968391c73cSBaoquan He unsigned long *output, 978391c73cSBaoquan He unsigned long output_size, 988391c73cSBaoquan He unsigned long *virt_addr) 998ab3820fSKees Cook { 1008ab3820fSKees Cook } 1018ab3820fSKees Cook #endif 1028ab3820fSKees Cook 103f5ed7775SMartin Radev /* cpuflags.c */ 104f5ed7775SMartin Radev bool has_cpuflag(int flag); 105f5ed7775SMartin Radev 1063a94707dSKees Cook #ifdef CONFIG_X86_64 107c81d6002SJoerg Roedel extern int set_page_decrypted(unsigned long address); 108c81d6002SJoerg Roedel extern int set_page_encrypted(unsigned long address); 10969add17aSJoerg Roedel extern int set_page_non_present(unsigned long address); 1103a94707dSKees Cook extern unsigned char _pgtable[]; 1113a94707dSKees Cook #endif 1123a94707dSKees Cook 1138ab3820fSKees Cook #ifdef CONFIG_EARLY_PRINTK 1148fee13a4SYinghai Lu /* early_serial_console.c */ 1158fee13a4SYinghai Lu extern int early_serial_base; 1168fee13a4SYinghai Lu void console_init(void); 117cec49df9SJoe Millenbach #else 118cec49df9SJoe Millenbach static const int early_serial_base; 119cec49df9SJoe Millenbach static inline void console_init(void) 120cec49df9SJoe Millenbach { } 121cec49df9SJoe Millenbach #endif 122cec49df9SJoe Millenbach 123597cfe48SJoerg Roedel #ifdef CONFIG_AMD_MEM_ENCRYPT 124ec1c66afSMichael Roth void sev_enable(struct boot_params *bp); 125597cfe48SJoerg Roedel void sev_es_shutdown_ghcb(void); 12669add17aSJoerg Roedel extern bool sev_es_check_ghcb_fault(unsigned long address); 127*4f9c403eSBrijesh Singh void snp_set_page_private(unsigned long paddr); 128*4f9c403eSBrijesh Singh void snp_set_page_shared(unsigned long paddr); 129597cfe48SJoerg Roedel #else 130ec1c66afSMichael Roth static inline void sev_enable(struct boot_params *bp) { } 131597cfe48SJoerg Roedel static inline void sev_es_shutdown_ghcb(void) { } 13269add17aSJoerg Roedel static inline bool sev_es_check_ghcb_fault(unsigned long address) 13369add17aSJoerg Roedel { 13469add17aSJoerg Roedel return false; 13569add17aSJoerg Roedel } 136*4f9c403eSBrijesh Singh static inline void snp_set_page_private(unsigned long paddr) { } 137*4f9c403eSBrijesh Singh static inline void snp_set_page_shared(unsigned long paddr) { } 138597cfe48SJoerg Roedel #endif 139597cfe48SJoerg Roedel 1403a63f70bSChao Fan /* acpi.c */ 1413a63f70bSChao Fan #ifdef CONFIG_ACPI 1423a63f70bSChao Fan acpi_physical_address get_rsdp_addr(void); 1433a63f70bSChao Fan #else 1443a63f70bSChao Fan static inline acpi_physical_address get_rsdp_addr(void) { return 0; } 1453a63f70bSChao Fan #endif 14602a3e3cdSChao Fan 14782df8261SBorislav Petkov #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI) 148690eaa53SChao Fan extern struct mem_vector immovable_mem[MAX_NUMNODES*2]; 14902a3e3cdSChao Fan int count_immovable_mem_regions(void); 15002a3e3cdSChao Fan #else 15102a3e3cdSChao Fan static inline int count_immovable_mem_regions(void) { return 0; } 15202a3e3cdSChao Fan #endif 1530f02daedSBaoquan He 1545f2bb016SJoerg Roedel /* ident_map_64.c */ 1555f2bb016SJoerg Roedel #ifdef CONFIG_X86_5LEVEL 1565f2bb016SJoerg Roedel extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d; 1575f2bb016SJoerg Roedel #endif 1585f2bb016SJoerg Roedel 1595f2bb016SJoerg Roedel /* Used by PAGE_KERN* macros: */ 1605f2bb016SJoerg Roedel extern pteval_t __default_kernel_pte_mask; 1615f2bb016SJoerg Roedel 16264e68263SJoerg Roedel /* idt_64.c */ 16364e68263SJoerg Roedel extern gate_desc boot_idt[BOOT_IDT_ENTRIES]; 16464e68263SJoerg Roedel extern struct desc_ptr boot_idt_desc; 16564e68263SJoerg Roedel 166b099155eSJoerg Roedel #ifdef CONFIG_X86_64 167b099155eSJoerg Roedel void cleanup_exception_handling(void); 168b099155eSJoerg Roedel #else 169b099155eSJoerg Roedel static inline void cleanup_exception_handling(void) { } 170b099155eSJoerg Roedel #endif 171b099155eSJoerg Roedel 1728b0d3b3bSJoerg Roedel /* IDT Entry Points */ 1738b0d3b3bSJoerg Roedel void boot_page_fault(void); 17429dcc60fSJoerg Roedel void boot_stage1_vc(void); 175597cfe48SJoerg Roedel void boot_stage2_vc(void); 1768b0d3b3bSJoerg Roedel 17786ce43f7SJoerg Roedel unsigned long sev_verify_cbit(unsigned long cr3); 17886ce43f7SJoerg Roedel 1790f02daedSBaoquan He #endif /* BOOT_COMPRESSED_MISC_H */ 180