xref: /linux/arch/x86/boot/compressed/misc.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
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 
225462ade6SKirill A. Shutemov /*
235462ade6SKirill A. Shutemov  * Boot stub deals with identity mappings, physical and virtual addresses are
245462ade6SKirill A. Shutemov  * the same, so override these defines.
255462ade6SKirill A. Shutemov  *
265462ade6SKirill A. Shutemov  * <asm/page.h> will not define them if they are already defined.
275462ade6SKirill A. Shutemov  */
285462ade6SKirill A. Shutemov #define __pa(x)  ((unsigned long)(x))
295462ade6SKirill A. Shutemov #define __va(x)  ((void *)((unsigned long)(x)))
305462ade6SKirill A. Shutemov 
318fee13a4SYinghai Lu #include <linux/linkage.h>
328fee13a4SYinghai Lu #include <linux/screen_info.h>
338fee13a4SYinghai Lu #include <linux/elf.h>
348fee13a4SYinghai Lu #include <asm/page.h>
358fee13a4SYinghai Lu #include <asm/boot.h>
368fee13a4SYinghai Lu #include <asm/bootparam.h>
3764e68263SJoerg Roedel #include <asm/desc_defs.h>
388fee13a4SYinghai Lu 
394b05f815SKuppuswamy Sathyanarayanan #include "tdx.h"
404b05f815SKuppuswamy Sathyanarayanan 
413c98e71bSChao Fan #define BOOT_CTYPE_H
423c98e71bSChao Fan #include <linux/acpi.h>
433c98e71bSChao Fan 
448fee13a4SYinghai Lu #define BOOT_BOOT_H
456238b47bSH. Peter Anvin #include "../ctype.h"
46eb4ea1aeSKirill A. Shutemov #include "../io.h"
478fee13a4SYinghai Lu 
485dc91f2dSBorislav Petkov #include "efi.h"
495dc91f2dSBorislav Petkov 
5082fa9637SKees Cook #ifdef CONFIG_X86_64
5182fa9637SKees Cook #define memptr long
5282fa9637SKees Cook #else
5382fa9637SKees Cook #define memptr unsigned
5482fa9637SKees Cook #endif
5582fa9637SKees Cook 
568b0d3b3bSJoerg Roedel /* boot/compressed/vmlinux start and end markers */
578b0d3b3bSJoerg Roedel extern char _head[], _end[];
588b0d3b3bSJoerg Roedel 
598fee13a4SYinghai Lu /* misc.c */
6082fa9637SKees Cook extern memptr free_mem_ptr;
6182fa9637SKees Cook extern memptr free_mem_end_ptr;
62*ac456ca0SNOMURA JUNICHI(野村 淳一) extern int spurious_nmi_count;
6333f98a97SKees Cook void *malloc(int size);
6433f98a97SKees Cook void free(void *where);
657aac3015SJoe Millenbach void __putstr(const char *s);
6679063a7cSKees Cook void __puthex(unsigned long value);
679ba8ec8eSH. Peter Anvin void __putdec(unsigned long value);
687aac3015SJoe Millenbach #define error_putstr(__x)  __putstr(__x)
6979063a7cSKees Cook #define error_puthex(__x)  __puthex(__x)
709ba8ec8eSH. Peter Anvin #define error_putdec(__x)  __putdec(__x)
717aac3015SJoe Millenbach 
727aac3015SJoe Millenbach #ifdef CONFIG_X86_VERBOSE_BOOTUP
737aac3015SJoe Millenbach 
747aac3015SJoe Millenbach #define debug_putstr(__x)  __putstr(__x)
7579063a7cSKees Cook #define debug_puthex(__x)  __puthex(__x)
7679063a7cSKees Cook #define debug_putaddr(__x) { \
7779063a7cSKees Cook 		debug_putstr(#__x ": 0x"); \
7879063a7cSKees Cook 		debug_puthex((unsigned long)(__x)); \
7979063a7cSKees Cook 		debug_putstr("\n"); \
8079063a7cSKees Cook 	}
817aac3015SJoe Millenbach 
827aac3015SJoe Millenbach #else
837aac3015SJoe Millenbach 
debug_putstr(const char * s)847aac3015SJoe Millenbach static inline void debug_putstr(const char *s)
857aac3015SJoe Millenbach { }
debug_puthex(unsigned long value)86c90beea2SJoerg Roedel static inline void debug_puthex(unsigned long value)
8779063a7cSKees Cook { }
8879063a7cSKees Cook #define debug_putaddr(x) /* */
897aac3015SJoe Millenbach 
907aac3015SJoe Millenbach #endif
918fee13a4SYinghai Lu 
928fee13a4SYinghai Lu /* cmdline.c */
938fee13a4SYinghai Lu int cmdline_find_option(const char *option, char *buffer, int bufsize);
948fee13a4SYinghai Lu int cmdline_find_option_bool(const char *option);
958fee13a4SYinghai Lu 
9602a3e3cdSChao Fan struct mem_vector {
973a066990SArvind Sankar 	u64 start;
983a066990SArvind Sankar 	u64 size;
9902a3e3cdSChao Fan };
1008ab3820fSKees Cook 
101a554e740SNick Desaulniers #ifdef CONFIG_RANDOMIZE_BASE
1029b238748SKees Cook /* kaslr.c */
1038391c73cSBaoquan He void choose_random_location(unsigned long input,
1048ab3820fSKees Cook 			    unsigned long input_size,
1058391c73cSBaoquan He 			    unsigned long *output,
1068391c73cSBaoquan He 			    unsigned long output_size,
1078391c73cSBaoquan He 			    unsigned long *virt_addr);
1088ab3820fSKees Cook #else
choose_random_location(unsigned long input,unsigned long input_size,unsigned long * output,unsigned long output_size,unsigned long * virt_addr)1098391c73cSBaoquan He static inline void choose_random_location(unsigned long input,
1108ab3820fSKees Cook 					  unsigned long input_size,
1118391c73cSBaoquan He 					  unsigned long *output,
1128391c73cSBaoquan He 					  unsigned long output_size,
1138391c73cSBaoquan He 					  unsigned long *virt_addr)
1148ab3820fSKees Cook {
1158ab3820fSKees Cook }
1168ab3820fSKees Cook #endif
1178ab3820fSKees Cook 
118f5ed7775SMartin Radev /* cpuflags.c */
119f5ed7775SMartin Radev bool has_cpuflag(int flag);
120f5ed7775SMartin Radev 
1213a94707dSKees Cook #ifdef CONFIG_X86_64
122c81d6002SJoerg Roedel extern int set_page_decrypted(unsigned long address);
123c81d6002SJoerg Roedel extern int set_page_encrypted(unsigned long address);
12469add17aSJoerg Roedel extern int set_page_non_present(unsigned long address);
1253a94707dSKees Cook extern unsigned char _pgtable[];
1263a94707dSKees Cook #endif
1273a94707dSKees Cook 
1288ab3820fSKees Cook #ifdef CONFIG_EARLY_PRINTK
1298fee13a4SYinghai Lu /* early_serial_console.c */
1308fee13a4SYinghai Lu extern int early_serial_base;
1318fee13a4SYinghai Lu void console_init(void);
132cec49df9SJoe Millenbach #else
133cec49df9SJoe Millenbach static const int early_serial_base;
console_init(void)134cec49df9SJoe Millenbach static inline void console_init(void)
135cec49df9SJoe Millenbach { }
136cec49df9SJoe Millenbach #endif
137cec49df9SJoe Millenbach 
138597cfe48SJoerg Roedel #ifdef CONFIG_AMD_MEM_ENCRYPT
139ec1c66afSMichael Roth void sev_enable(struct boot_params *bp);
1408c29f016SNikunj A Dadhania void snp_check_features(void);
141597cfe48SJoerg Roedel void sev_es_shutdown_ghcb(void);
14269add17aSJoerg Roedel extern bool sev_es_check_ghcb_fault(unsigned long address);
1434f9c403eSBrijesh Singh void snp_set_page_private(unsigned long paddr);
1444f9c403eSBrijesh Singh void snp_set_page_shared(unsigned long paddr);
14576f61e1eSMichael Roth void sev_prep_identity_maps(unsigned long top_level_pgt);
146597cfe48SJoerg Roedel #else
sev_enable(struct boot_params * bp)1474b1c7424SMichael Roth static inline void sev_enable(struct boot_params *bp)
1484b1c7424SMichael Roth {
1494b1c7424SMichael Roth 	/*
1504b1c7424SMichael Roth 	 * bp->cc_blob_address should only be set by boot/compressed kernel.
1514b1c7424SMichael Roth 	 * Initialize it to 0 unconditionally (thus here in this stub too) to
1524b1c7424SMichael Roth 	 * ensure that uninitialized values from buggy bootloaders aren't
1534b1c7424SMichael Roth 	 * propagated.
1544b1c7424SMichael Roth 	 */
1554b1c7424SMichael Roth 	if (bp)
1564b1c7424SMichael Roth 		bp->cc_blob_address = 0;
1574b1c7424SMichael Roth }
snp_check_features(void)1588c29f016SNikunj A Dadhania static inline void snp_check_features(void) { }
sev_es_shutdown_ghcb(void)159597cfe48SJoerg Roedel static inline void sev_es_shutdown_ghcb(void) { }
sev_es_check_ghcb_fault(unsigned long address)16069add17aSJoerg Roedel static inline bool sev_es_check_ghcb_fault(unsigned long address)
16169add17aSJoerg Roedel {
16269add17aSJoerg Roedel 	return false;
16369add17aSJoerg Roedel }
snp_set_page_private(unsigned long paddr)1644f9c403eSBrijesh Singh static inline void snp_set_page_private(unsigned long paddr) { }
snp_set_page_shared(unsigned long paddr)1654f9c403eSBrijesh Singh static inline void snp_set_page_shared(unsigned long paddr) { }
sev_prep_identity_maps(unsigned long top_level_pgt)16676f61e1eSMichael Roth static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { }
167597cfe48SJoerg Roedel #endif
168597cfe48SJoerg Roedel 
1693a63f70bSChao Fan /* acpi.c */
1703a63f70bSChao Fan #ifdef CONFIG_ACPI
1713a63f70bSChao Fan acpi_physical_address get_rsdp_addr(void);
1723a63f70bSChao Fan #else
get_rsdp_addr(void)1733a63f70bSChao Fan static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
1743a63f70bSChao Fan #endif
17502a3e3cdSChao Fan 
17682df8261SBorislav Petkov #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
177690eaa53SChao Fan extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
17802a3e3cdSChao Fan int count_immovable_mem_regions(void);
17902a3e3cdSChao Fan #else
count_immovable_mem_regions(void)18002a3e3cdSChao Fan static inline int count_immovable_mem_regions(void) { return 0; }
18102a3e3cdSChao Fan #endif
1820f02daedSBaoquan He 
1835f2bb016SJoerg Roedel /* ident_map_64.c */
1845f2bb016SJoerg Roedel extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
185a9ee679bSMichael Roth extern void kernel_add_identity_map(unsigned long start, unsigned long end);
1865f2bb016SJoerg Roedel 
1875f2bb016SJoerg Roedel /* Used by PAGE_KERN* macros: */
1885f2bb016SJoerg Roedel extern pteval_t __default_kernel_pte_mask;
1895f2bb016SJoerg Roedel 
19064e68263SJoerg Roedel /* idt_64.c */
19164e68263SJoerg Roedel extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
19264e68263SJoerg Roedel extern struct desc_ptr boot_idt_desc;
19364e68263SJoerg Roedel 
194b099155eSJoerg Roedel #ifdef CONFIG_X86_64
195b099155eSJoerg Roedel void cleanup_exception_handling(void);
196b099155eSJoerg Roedel #else
cleanup_exception_handling(void)197b099155eSJoerg Roedel static inline void cleanup_exception_handling(void) { }
198b099155eSJoerg Roedel #endif
199b099155eSJoerg Roedel 
2008b0d3b3bSJoerg Roedel /* IDT Entry Points */
2018b0d3b3bSJoerg Roedel void boot_page_fault(void);
20278a509fbSJun'ichi Nomura void boot_nmi_trap(void);
20329dcc60fSJoerg Roedel void boot_stage1_vc(void);
204597cfe48SJoerg Roedel void boot_stage2_vc(void);
2058b0d3b3bSJoerg Roedel 
20686ce43f7SJoerg Roedel unsigned long sev_verify_cbit(unsigned long cr3);
20786ce43f7SJoerg Roedel 
2087c4146e8SMichael Roth enum efi_type {
2097c4146e8SMichael Roth 	EFI_TYPE_64,
2107c4146e8SMichael Roth 	EFI_TYPE_32,
2117c4146e8SMichael Roth 	EFI_TYPE_NONE,
2127c4146e8SMichael Roth };
2137c4146e8SMichael Roth 
2147c4146e8SMichael Roth #ifdef CONFIG_EFI
2157c4146e8SMichael Roth /* helpers for early EFI config table access */
2167c4146e8SMichael Roth enum efi_type efi_get_type(struct boot_params *bp);
21758f3e6b7SMichael Roth unsigned long efi_get_system_table(struct boot_params *bp);
21861c14cedSMichael Roth int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
21961c14cedSMichael Roth 		       unsigned int *cfg_tbl_len);
220dee602ddSMichael Roth unsigned long efi_find_vendor_table(struct boot_params *bp,
221dee602ddSMichael Roth 				    unsigned long cfg_tbl_pa,
222dee602ddSMichael Roth 				    unsigned int cfg_tbl_len,
223dee602ddSMichael Roth 				    efi_guid_t guid);
2247c4146e8SMichael Roth #else
efi_get_type(struct boot_params * bp)2257c4146e8SMichael Roth static inline enum efi_type efi_get_type(struct boot_params *bp)
2267c4146e8SMichael Roth {
2277c4146e8SMichael Roth 	return EFI_TYPE_NONE;
2287c4146e8SMichael Roth }
22958f3e6b7SMichael Roth 
efi_get_system_table(struct boot_params * bp)23058f3e6b7SMichael Roth static inline unsigned long efi_get_system_table(struct boot_params *bp)
23158f3e6b7SMichael Roth {
23258f3e6b7SMichael Roth 	return 0;
23358f3e6b7SMichael Roth }
23461c14cedSMichael Roth 
efi_get_conf_table(struct boot_params * bp,unsigned long * cfg_tbl_pa,unsigned int * cfg_tbl_len)23561c14cedSMichael Roth static inline int efi_get_conf_table(struct boot_params *bp,
23661c14cedSMichael Roth 				     unsigned long *cfg_tbl_pa,
23761c14cedSMichael Roth 				     unsigned int *cfg_tbl_len)
23861c14cedSMichael Roth {
23961c14cedSMichael Roth 	return -ENOENT;
24061c14cedSMichael Roth }
241dee602ddSMichael Roth 
efi_find_vendor_table(struct boot_params * bp,unsigned long cfg_tbl_pa,unsigned int cfg_tbl_len,efi_guid_t guid)242dee602ddSMichael Roth static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
243dee602ddSMichael Roth 						  unsigned long cfg_tbl_pa,
244dee602ddSMichael Roth 						  unsigned int cfg_tbl_len,
245dee602ddSMichael Roth 						  efi_guid_t guid)
246dee602ddSMichael Roth {
247dee602ddSMichael Roth 	return 0;
248dee602ddSMichael Roth }
2497c4146e8SMichael Roth #endif /* CONFIG_EFI */
2507c4146e8SMichael Roth 
2513fd1239aSKirill A. Shutemov #ifdef CONFIG_UNACCEPTED_MEMORY
2523fd1239aSKirill A. Shutemov bool init_unaccepted_memory(void);
2533fd1239aSKirill A. Shutemov #else
init_unaccepted_memory(void)2543fd1239aSKirill A. Shutemov static inline bool init_unaccepted_memory(void) { return false; }
2553fd1239aSKirill A. Shutemov #endif
2563fd1239aSKirill A. Shutemov 
2573fd1239aSKirill A. Shutemov /* Defined in EFI stub */
2583fd1239aSKirill A. Shutemov extern struct efi_unaccepted_memory *unaccepted_table;
2593fd1239aSKirill A. Shutemov void accept_memory(phys_addr_t start, phys_addr_t end);
2603fd1239aSKirill A. Shutemov 
2610f02daedSBaoquan He #endif /* BOOT_COMPRESSED_MISC_H */
262