xref: /openbmc/linux/arch/x86/boot/compressed/misc.h (revision 8ebc80a25f9d9bf7a8e368b266d5b740c485c362)
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;
6233f98a97SKees Cook void *malloc(int size);
6333f98a97SKees Cook void free(void *where);
647aac3015SJoe Millenbach void __putstr(const char *s);
6579063a7cSKees Cook void __puthex(unsigned long value);
667aac3015SJoe Millenbach #define error_putstr(__x)  __putstr(__x)
6779063a7cSKees Cook #define error_puthex(__x)  __puthex(__x)
687aac3015SJoe Millenbach 
697aac3015SJoe Millenbach #ifdef CONFIG_X86_VERBOSE_BOOTUP
707aac3015SJoe Millenbach 
717aac3015SJoe Millenbach #define debug_putstr(__x)  __putstr(__x)
7279063a7cSKees Cook #define debug_puthex(__x)  __puthex(__x)
7379063a7cSKees Cook #define debug_putaddr(__x) { \
7479063a7cSKees Cook 		debug_putstr(#__x ": 0x"); \
7579063a7cSKees Cook 		debug_puthex((unsigned long)(__x)); \
7679063a7cSKees Cook 		debug_putstr("\n"); \
7779063a7cSKees Cook 	}
787aac3015SJoe Millenbach 
797aac3015SJoe Millenbach #else
807aac3015SJoe Millenbach 
debug_putstr(const char * s)817aac3015SJoe Millenbach static inline void debug_putstr(const char *s)
827aac3015SJoe Millenbach { }
debug_puthex(unsigned long value)83c90beea2SJoerg Roedel static inline void debug_puthex(unsigned long value)
8479063a7cSKees Cook { }
8579063a7cSKees Cook #define debug_putaddr(x) /* */
867aac3015SJoe Millenbach 
877aac3015SJoe Millenbach #endif
888fee13a4SYinghai Lu 
898fee13a4SYinghai Lu /* cmdline.c */
908fee13a4SYinghai Lu int cmdline_find_option(const char *option, char *buffer, int bufsize);
918fee13a4SYinghai Lu int cmdline_find_option_bool(const char *option);
928fee13a4SYinghai Lu 
9302a3e3cdSChao Fan struct mem_vector {
943a066990SArvind Sankar 	u64 start;
953a066990SArvind Sankar 	u64 size;
9602a3e3cdSChao Fan };
978ab3820fSKees Cook 
98a554e740SNick Desaulniers #ifdef CONFIG_RANDOMIZE_BASE
999b238748SKees Cook /* kaslr.c */
1008391c73cSBaoquan He void choose_random_location(unsigned long input,
1018ab3820fSKees Cook 			    unsigned long input_size,
1028391c73cSBaoquan He 			    unsigned long *output,
1038391c73cSBaoquan He 			    unsigned long output_size,
1048391c73cSBaoquan He 			    unsigned long *virt_addr);
1058ab3820fSKees Cook #else
choose_random_location(unsigned long input,unsigned long input_size,unsigned long * output,unsigned long output_size,unsigned long * virt_addr)1068391c73cSBaoquan He static inline void choose_random_location(unsigned long input,
1078ab3820fSKees Cook 					  unsigned long input_size,
1088391c73cSBaoquan He 					  unsigned long *output,
1098391c73cSBaoquan He 					  unsigned long output_size,
1108391c73cSBaoquan He 					  unsigned long *virt_addr)
1118ab3820fSKees Cook {
1128ab3820fSKees Cook }
1138ab3820fSKees Cook #endif
1148ab3820fSKees Cook 
115f5ed7775SMartin Radev /* cpuflags.c */
116f5ed7775SMartin Radev bool has_cpuflag(int flag);
117f5ed7775SMartin Radev 
1183a94707dSKees Cook #ifdef CONFIG_X86_64
119c81d6002SJoerg Roedel extern int set_page_decrypted(unsigned long address);
120c81d6002SJoerg Roedel extern int set_page_encrypted(unsigned long address);
12169add17aSJoerg Roedel extern int set_page_non_present(unsigned long address);
1223a94707dSKees Cook extern unsigned char _pgtable[];
1233a94707dSKees Cook #endif
1243a94707dSKees Cook 
1258ab3820fSKees Cook #ifdef CONFIG_EARLY_PRINTK
1268fee13a4SYinghai Lu /* early_serial_console.c */
1278fee13a4SYinghai Lu extern int early_serial_base;
1288fee13a4SYinghai Lu void console_init(void);
129cec49df9SJoe Millenbach #else
130cec49df9SJoe Millenbach static const int early_serial_base;
console_init(void)131cec49df9SJoe Millenbach static inline void console_init(void)
132cec49df9SJoe Millenbach { }
133cec49df9SJoe Millenbach #endif
134cec49df9SJoe Millenbach 
135597cfe48SJoerg Roedel #ifdef CONFIG_AMD_MEM_ENCRYPT
136ec1c66afSMichael Roth void sev_enable(struct boot_params *bp);
1378c29f016SNikunj A Dadhania void snp_check_features(void);
138597cfe48SJoerg Roedel void sev_es_shutdown_ghcb(void);
13969add17aSJoerg Roedel extern bool sev_es_check_ghcb_fault(unsigned long address);
1404f9c403eSBrijesh Singh void snp_set_page_private(unsigned long paddr);
1414f9c403eSBrijesh Singh void snp_set_page_shared(unsigned long paddr);
14276f61e1eSMichael Roth void sev_prep_identity_maps(unsigned long top_level_pgt);
143597cfe48SJoerg Roedel #else
sev_enable(struct boot_params * bp)1444b1c7424SMichael Roth static inline void sev_enable(struct boot_params *bp)
1454b1c7424SMichael Roth {
1464b1c7424SMichael Roth 	/*
1474b1c7424SMichael Roth 	 * bp->cc_blob_address should only be set by boot/compressed kernel.
1484b1c7424SMichael Roth 	 * Initialize it to 0 unconditionally (thus here in this stub too) to
1494b1c7424SMichael Roth 	 * ensure that uninitialized values from buggy bootloaders aren't
1504b1c7424SMichael Roth 	 * propagated.
1514b1c7424SMichael Roth 	 */
1524b1c7424SMichael Roth 	if (bp)
1534b1c7424SMichael Roth 		bp->cc_blob_address = 0;
1544b1c7424SMichael Roth }
snp_check_features(void)1558c29f016SNikunj A Dadhania static inline void snp_check_features(void) { }
sev_es_shutdown_ghcb(void)156597cfe48SJoerg Roedel static inline void sev_es_shutdown_ghcb(void) { }
sev_es_check_ghcb_fault(unsigned long address)15769add17aSJoerg Roedel static inline bool sev_es_check_ghcb_fault(unsigned long address)
15869add17aSJoerg Roedel {
15969add17aSJoerg Roedel 	return false;
16069add17aSJoerg Roedel }
snp_set_page_private(unsigned long paddr)1614f9c403eSBrijesh Singh static inline void snp_set_page_private(unsigned long paddr) { }
snp_set_page_shared(unsigned long paddr)1624f9c403eSBrijesh Singh static inline void snp_set_page_shared(unsigned long paddr) { }
sev_prep_identity_maps(unsigned long top_level_pgt)16376f61e1eSMichael Roth static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { }
164597cfe48SJoerg Roedel #endif
165597cfe48SJoerg Roedel 
1663a63f70bSChao Fan /* acpi.c */
1673a63f70bSChao Fan #ifdef CONFIG_ACPI
1683a63f70bSChao Fan acpi_physical_address get_rsdp_addr(void);
1693a63f70bSChao Fan #else
get_rsdp_addr(void)1703a63f70bSChao Fan static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
1713a63f70bSChao Fan #endif
17202a3e3cdSChao Fan 
17382df8261SBorislav Petkov #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
174690eaa53SChao Fan extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
17502a3e3cdSChao Fan int count_immovable_mem_regions(void);
17602a3e3cdSChao Fan #else
count_immovable_mem_regions(void)17702a3e3cdSChao Fan static inline int count_immovable_mem_regions(void) { return 0; }
17802a3e3cdSChao Fan #endif
1790f02daedSBaoquan He 
1805f2bb016SJoerg Roedel /* ident_map_64.c */
1815f2bb016SJoerg Roedel extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
182a9ee679bSMichael Roth extern void kernel_add_identity_map(unsigned long start, unsigned long end);
1835f2bb016SJoerg Roedel 
1845f2bb016SJoerg Roedel /* Used by PAGE_KERN* macros: */
1855f2bb016SJoerg Roedel extern pteval_t __default_kernel_pte_mask;
1865f2bb016SJoerg Roedel 
18764e68263SJoerg Roedel /* idt_64.c */
18864e68263SJoerg Roedel extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
18964e68263SJoerg Roedel extern struct desc_ptr boot_idt_desc;
19064e68263SJoerg Roedel 
191b099155eSJoerg Roedel #ifdef CONFIG_X86_64
192b099155eSJoerg Roedel void cleanup_exception_handling(void);
193b099155eSJoerg Roedel #else
cleanup_exception_handling(void)194b099155eSJoerg Roedel static inline void cleanup_exception_handling(void) { }
195b099155eSJoerg Roedel #endif
196b099155eSJoerg Roedel 
1978b0d3b3bSJoerg Roedel /* IDT Entry Points */
1988b0d3b3bSJoerg Roedel void boot_page_fault(void);
199*f77cb047SJun'ichi Nomura void boot_nmi_trap(void);
20029dcc60fSJoerg Roedel void boot_stage1_vc(void);
201597cfe48SJoerg Roedel void boot_stage2_vc(void);
2028b0d3b3bSJoerg Roedel 
20386ce43f7SJoerg Roedel unsigned long sev_verify_cbit(unsigned long cr3);
20486ce43f7SJoerg Roedel 
2057c4146e8SMichael Roth enum efi_type {
2067c4146e8SMichael Roth 	EFI_TYPE_64,
2077c4146e8SMichael Roth 	EFI_TYPE_32,
2087c4146e8SMichael Roth 	EFI_TYPE_NONE,
2097c4146e8SMichael Roth };
2107c4146e8SMichael Roth 
2117c4146e8SMichael Roth #ifdef CONFIG_EFI
2127c4146e8SMichael Roth /* helpers for early EFI config table access */
2137c4146e8SMichael Roth enum efi_type efi_get_type(struct boot_params *bp);
21458f3e6b7SMichael Roth unsigned long efi_get_system_table(struct boot_params *bp);
21561c14cedSMichael Roth int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
21661c14cedSMichael Roth 		       unsigned int *cfg_tbl_len);
217dee602ddSMichael Roth unsigned long efi_find_vendor_table(struct boot_params *bp,
218dee602ddSMichael Roth 				    unsigned long cfg_tbl_pa,
219dee602ddSMichael Roth 				    unsigned int cfg_tbl_len,
220dee602ddSMichael Roth 				    efi_guid_t guid);
2217c4146e8SMichael Roth #else
efi_get_type(struct boot_params * bp)2227c4146e8SMichael Roth static inline enum efi_type efi_get_type(struct boot_params *bp)
2237c4146e8SMichael Roth {
2247c4146e8SMichael Roth 	return EFI_TYPE_NONE;
2257c4146e8SMichael Roth }
22658f3e6b7SMichael Roth 
efi_get_system_table(struct boot_params * bp)22758f3e6b7SMichael Roth static inline unsigned long efi_get_system_table(struct boot_params *bp)
22858f3e6b7SMichael Roth {
22958f3e6b7SMichael Roth 	return 0;
23058f3e6b7SMichael Roth }
23161c14cedSMichael Roth 
efi_get_conf_table(struct boot_params * bp,unsigned long * cfg_tbl_pa,unsigned int * cfg_tbl_len)23261c14cedSMichael Roth static inline int efi_get_conf_table(struct boot_params *bp,
23361c14cedSMichael Roth 				     unsigned long *cfg_tbl_pa,
23461c14cedSMichael Roth 				     unsigned int *cfg_tbl_len)
23561c14cedSMichael Roth {
23661c14cedSMichael Roth 	return -ENOENT;
23761c14cedSMichael Roth }
238dee602ddSMichael Roth 
efi_find_vendor_table(struct boot_params * bp,unsigned long cfg_tbl_pa,unsigned int cfg_tbl_len,efi_guid_t guid)239dee602ddSMichael Roth static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
240dee602ddSMichael Roth 						  unsigned long cfg_tbl_pa,
241dee602ddSMichael Roth 						  unsigned int cfg_tbl_len,
242dee602ddSMichael Roth 						  efi_guid_t guid)
243dee602ddSMichael Roth {
244dee602ddSMichael Roth 	return 0;
245dee602ddSMichael Roth }
2467c4146e8SMichael Roth #endif /* CONFIG_EFI */
2477c4146e8SMichael Roth 
2483fd1239aSKirill A. Shutemov #ifdef CONFIG_UNACCEPTED_MEMORY
2493fd1239aSKirill A. Shutemov bool init_unaccepted_memory(void);
2503fd1239aSKirill A. Shutemov #else
init_unaccepted_memory(void)2513fd1239aSKirill A. Shutemov static inline bool init_unaccepted_memory(void) { return false; }
2523fd1239aSKirill A. Shutemov #endif
2533fd1239aSKirill A. Shutemov 
2543fd1239aSKirill A. Shutemov /* Defined in EFI stub */
2553fd1239aSKirill A. Shutemov extern struct efi_unaccepted_memory *unaccepted_table;
2563fd1239aSKirill A. Shutemov void accept_memory(phys_addr_t start, phys_addr_t end);
2573fd1239aSKirill A. Shutemov 
2580f02daedSBaoquan He #endif /* BOOT_COMPRESSED_MISC_H */
259