1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef BOOT_COMPRESSED_MISC_H
3#define BOOT_COMPRESSED_MISC_H
4
5/*
6 * Special hack: we have to be careful, because no indirections are allowed here,
7 * and paravirt_ops is a kind of one. As it will only run in baremetal anyway,
8 * we just keep it from happening. (This list needs to be extended when new
9 * paravirt and debugging variants are added.)
10 */
11#undef CONFIG_PARAVIRT
12#undef CONFIG_PARAVIRT_XXL
13#undef CONFIG_PARAVIRT_SPINLOCKS
14#undef CONFIG_KASAN
15
16/* cpu_feature_enabled() cannot be used this early */
17#define USE_EARLY_PGTABLE_L5
18
19#include <linux/linkage.h>
20#include <linux/screen_info.h>
21#include <linux/elf.h>
22#include <linux/io.h>
23#include <asm/page.h>
24#include <asm/boot.h>
25#include <asm/bootparam.h>
26#include <asm/desc_defs.h>
27
28#define BOOT_CTYPE_H
29#include <linux/acpi.h>
30
31#define BOOT_BOOT_H
32#include "../ctype.h"
33
34#ifdef CONFIG_X86_64
35#define memptr long
36#else
37#define memptr unsigned
38#endif
39
40/* boot/compressed/vmlinux start and end markers */
41extern char _head[], _end[];
42
43/* misc.c */
44extern memptr free_mem_ptr;
45extern memptr free_mem_end_ptr;
46extern struct boot_params *boot_params;
47void __putstr(const char *s);
48void __puthex(unsigned long value);
49#define error_putstr(__x)  __putstr(__x)
50#define error_puthex(__x)  __puthex(__x)
51
52#ifdef CONFIG_X86_VERBOSE_BOOTUP
53
54#define debug_putstr(__x)  __putstr(__x)
55#define debug_puthex(__x)  __puthex(__x)
56#define debug_putaddr(__x) { \
57		debug_putstr(#__x ": 0x"); \
58		debug_puthex((unsigned long)(__x)); \
59		debug_putstr("\n"); \
60	}
61
62#else
63
64static inline void debug_putstr(const char *s)
65{ }
66static inline void debug_puthex(unsigned long value)
67{ }
68#define debug_putaddr(x) /* */
69
70#endif
71
72/* cmdline.c */
73int cmdline_find_option(const char *option, char *buffer, int bufsize);
74int cmdline_find_option_bool(const char *option);
75
76struct mem_vector {
77	u64 start;
78	u64 size;
79};
80
81#if CONFIG_RANDOMIZE_BASE
82/* kaslr.c */
83void choose_random_location(unsigned long input,
84			    unsigned long input_size,
85			    unsigned long *output,
86			    unsigned long output_size,
87			    unsigned long *virt_addr);
88#else
89static inline void choose_random_location(unsigned long input,
90					  unsigned long input_size,
91					  unsigned long *output,
92					  unsigned long output_size,
93					  unsigned long *virt_addr)
94{
95}
96#endif
97
98/* cpuflags.c */
99bool has_cpuflag(int flag);
100
101#ifdef CONFIG_X86_64
102extern int set_page_decrypted(unsigned long address);
103extern int set_page_encrypted(unsigned long address);
104extern int set_page_non_present(unsigned long address);
105extern unsigned char _pgtable[];
106#endif
107
108#ifdef CONFIG_EARLY_PRINTK
109/* early_serial_console.c */
110extern int early_serial_base;
111void console_init(void);
112#else
113static const int early_serial_base;
114static inline void console_init(void)
115{ }
116#endif
117
118void set_sev_encryption_mask(void);
119
120#ifdef CONFIG_AMD_MEM_ENCRYPT
121void sev_es_shutdown_ghcb(void);
122extern bool sev_es_check_ghcb_fault(unsigned long address);
123#else
124static inline void sev_es_shutdown_ghcb(void) { }
125static inline bool sev_es_check_ghcb_fault(unsigned long address)
126{
127	return false;
128}
129#endif
130
131/* acpi.c */
132#ifdef CONFIG_ACPI
133acpi_physical_address get_rsdp_addr(void);
134#else
135static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
136#endif
137
138#if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
139extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
140int count_immovable_mem_regions(void);
141#else
142static inline int count_immovable_mem_regions(void) { return 0; }
143#endif
144
145/* ident_map_64.c */
146#ifdef CONFIG_X86_5LEVEL
147extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
148#endif
149
150/* Used by PAGE_KERN* macros: */
151extern pteval_t __default_kernel_pte_mask;
152
153/* idt_64.c */
154extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
155extern struct desc_ptr boot_idt_desc;
156
157/* IDT Entry Points */
158void boot_page_fault(void);
159void boot_nmi_trap(void);
160void boot_stage1_vc(void);
161void boot_stage2_vc(void);
162
163unsigned long sev_verify_cbit(unsigned long cr3);
164
165#endif /* BOOT_COMPRESSED_MISC_H */
166