18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef BOOT_COMPRESSED_MISC_H
38c2ecf20Sopenharmony_ci#define BOOT_COMPRESSED_MISC_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * Special hack: we have to be careful, because no indirections are allowed here,
78c2ecf20Sopenharmony_ci * and paravirt_ops is a kind of one. As it will only run in baremetal anyway,
88c2ecf20Sopenharmony_ci * we just keep it from happening. (This list needs to be extended when new
98c2ecf20Sopenharmony_ci * paravirt and debugging variants are added.)
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#undef CONFIG_PARAVIRT
128c2ecf20Sopenharmony_ci#undef CONFIG_PARAVIRT_XXL
138c2ecf20Sopenharmony_ci#undef CONFIG_PARAVIRT_SPINLOCKS
148c2ecf20Sopenharmony_ci#undef CONFIG_KASAN
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* cpu_feature_enabled() cannot be used this early */
178c2ecf20Sopenharmony_ci#define USE_EARLY_PGTABLE_L5
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <linux/linkage.h>
208c2ecf20Sopenharmony_ci#include <linux/screen_info.h>
218c2ecf20Sopenharmony_ci#include <linux/elf.h>
228c2ecf20Sopenharmony_ci#include <linux/io.h>
238c2ecf20Sopenharmony_ci#include <asm/page.h>
248c2ecf20Sopenharmony_ci#include <asm/boot.h>
258c2ecf20Sopenharmony_ci#include <asm/bootparam.h>
268c2ecf20Sopenharmony_ci#include <asm/desc_defs.h>
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define BOOT_CTYPE_H
298c2ecf20Sopenharmony_ci#include <linux/acpi.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define BOOT_BOOT_H
328c2ecf20Sopenharmony_ci#include "../ctype.h"
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64
358c2ecf20Sopenharmony_ci#define memptr long
368c2ecf20Sopenharmony_ci#else
378c2ecf20Sopenharmony_ci#define memptr unsigned
388c2ecf20Sopenharmony_ci#endif
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* boot/compressed/vmlinux start and end markers */
418c2ecf20Sopenharmony_ciextern char _head[], _end[];
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/* misc.c */
448c2ecf20Sopenharmony_ciextern memptr free_mem_ptr;
458c2ecf20Sopenharmony_ciextern memptr free_mem_end_ptr;
468c2ecf20Sopenharmony_ciextern struct boot_params *boot_params;
478c2ecf20Sopenharmony_civoid __putstr(const char *s);
488c2ecf20Sopenharmony_civoid __puthex(unsigned long value);
498c2ecf20Sopenharmony_ci#define error_putstr(__x)  __putstr(__x)
508c2ecf20Sopenharmony_ci#define error_puthex(__x)  __puthex(__x)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_VERBOSE_BOOTUP
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define debug_putstr(__x)  __putstr(__x)
558c2ecf20Sopenharmony_ci#define debug_puthex(__x)  __puthex(__x)
568c2ecf20Sopenharmony_ci#define debug_putaddr(__x) { \
578c2ecf20Sopenharmony_ci		debug_putstr(#__x ": 0x"); \
588c2ecf20Sopenharmony_ci		debug_puthex((unsigned long)(__x)); \
598c2ecf20Sopenharmony_ci		debug_putstr("\n"); \
608c2ecf20Sopenharmony_ci	}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#else
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic inline void debug_putstr(const char *s)
658c2ecf20Sopenharmony_ci{ }
668c2ecf20Sopenharmony_cistatic inline void debug_puthex(unsigned long value)
678c2ecf20Sopenharmony_ci{ }
688c2ecf20Sopenharmony_ci#define debug_putaddr(x) /* */
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#endif
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* cmdline.c */
738c2ecf20Sopenharmony_ciint cmdline_find_option(const char *option, char *buffer, int bufsize);
748c2ecf20Sopenharmony_ciint cmdline_find_option_bool(const char *option);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistruct mem_vector {
778c2ecf20Sopenharmony_ci	u64 start;
788c2ecf20Sopenharmony_ci	u64 size;
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#if CONFIG_RANDOMIZE_BASE
828c2ecf20Sopenharmony_ci/* kaslr.c */
838c2ecf20Sopenharmony_civoid choose_random_location(unsigned long input,
848c2ecf20Sopenharmony_ci			    unsigned long input_size,
858c2ecf20Sopenharmony_ci			    unsigned long *output,
868c2ecf20Sopenharmony_ci			    unsigned long output_size,
878c2ecf20Sopenharmony_ci			    unsigned long *virt_addr);
888c2ecf20Sopenharmony_ci#else
898c2ecf20Sopenharmony_cistatic inline void choose_random_location(unsigned long input,
908c2ecf20Sopenharmony_ci					  unsigned long input_size,
918c2ecf20Sopenharmony_ci					  unsigned long *output,
928c2ecf20Sopenharmony_ci					  unsigned long output_size,
938c2ecf20Sopenharmony_ci					  unsigned long *virt_addr)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci#endif
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* cpuflags.c */
998c2ecf20Sopenharmony_cibool has_cpuflag(int flag);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64
1028c2ecf20Sopenharmony_ciextern int set_page_decrypted(unsigned long address);
1038c2ecf20Sopenharmony_ciextern int set_page_encrypted(unsigned long address);
1048c2ecf20Sopenharmony_ciextern int set_page_non_present(unsigned long address);
1058c2ecf20Sopenharmony_ciextern unsigned char _pgtable[];
1068c2ecf20Sopenharmony_ci#endif
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#ifdef CONFIG_EARLY_PRINTK
1098c2ecf20Sopenharmony_ci/* early_serial_console.c */
1108c2ecf20Sopenharmony_ciextern int early_serial_base;
1118c2ecf20Sopenharmony_civoid console_init(void);
1128c2ecf20Sopenharmony_ci#else
1138c2ecf20Sopenharmony_cistatic const int early_serial_base;
1148c2ecf20Sopenharmony_cistatic inline void console_init(void)
1158c2ecf20Sopenharmony_ci{ }
1168c2ecf20Sopenharmony_ci#endif
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_civoid set_sev_encryption_mask(void);
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#ifdef CONFIG_AMD_MEM_ENCRYPT
1218c2ecf20Sopenharmony_civoid sev_es_shutdown_ghcb(void);
1228c2ecf20Sopenharmony_ciextern bool sev_es_check_ghcb_fault(unsigned long address);
1238c2ecf20Sopenharmony_ci#else
1248c2ecf20Sopenharmony_cistatic inline void sev_es_shutdown_ghcb(void) { }
1258c2ecf20Sopenharmony_cistatic inline bool sev_es_check_ghcb_fault(unsigned long address)
1268c2ecf20Sopenharmony_ci{
1278c2ecf20Sopenharmony_ci	return false;
1288c2ecf20Sopenharmony_ci}
1298c2ecf20Sopenharmony_ci#endif
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* acpi.c */
1328c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI
1338c2ecf20Sopenharmony_ciacpi_physical_address get_rsdp_addr(void);
1348c2ecf20Sopenharmony_ci#else
1358c2ecf20Sopenharmony_cistatic inline acpi_physical_address get_rsdp_addr(void) { return 0; }
1368c2ecf20Sopenharmony_ci#endif
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
1398c2ecf20Sopenharmony_ciextern struct mem_vector immovable_mem[MAX_NUMNODES*2];
1408c2ecf20Sopenharmony_ciint count_immovable_mem_regions(void);
1418c2ecf20Sopenharmony_ci#else
1428c2ecf20Sopenharmony_cistatic inline int count_immovable_mem_regions(void) { return 0; }
1438c2ecf20Sopenharmony_ci#endif
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* ident_map_64.c */
1468c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_5LEVEL
1478c2ecf20Sopenharmony_ciextern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
1488c2ecf20Sopenharmony_ci#endif
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/* Used by PAGE_KERN* macros: */
1518c2ecf20Sopenharmony_ciextern pteval_t __default_kernel_pte_mask;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/* idt_64.c */
1548c2ecf20Sopenharmony_ciextern gate_desc boot_idt[BOOT_IDT_ENTRIES];
1558c2ecf20Sopenharmony_ciextern struct desc_ptr boot_idt_desc;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/* IDT Entry Points */
1588c2ecf20Sopenharmony_civoid boot_page_fault(void);
1598c2ecf20Sopenharmony_civoid boot_nmi_trap(void);
1608c2ecf20Sopenharmony_civoid boot_stage1_vc(void);
1618c2ecf20Sopenharmony_civoid boot_stage2_vc(void);
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciunsigned long sev_verify_cbit(unsigned long cr3);
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci#endif /* BOOT_COMPRESSED_MISC_H */
166