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#undef CONFIG_KASAN_GENERIC
16
17#define __NO_FORTIFY
18
19/* cpu_feature_enabled() cannot be used this early */
20#define USE_EARLY_PGTABLE_L5
21
22/*
23 * Boot stub deals with identity mappings, physical and virtual addresses are
24 * the same, so override these defines.
25 *
26 * <asm/page.h> will not define them if they are already defined.
27 */
28#define __pa(x) ((unsigned long)(x))
29#define __va(x) ((void *)((unsigned long)(x)))
30
31#include <linux/linkage.h>
32#include <linux/screen_info.h>
33#include <linux/elf.h>
34#include <asm/page.h>
35#include <asm/boot.h>
36#include <asm/bootparam.h>
37#include <asm/desc_defs.h>
38
39#include "tdx.h"
40
41#define BOOT_CTYPE_H
42#include <linux/acpi.h>
43
44#define BOOT_BOOT_H
45#include "../ctype.h"
46#include "../io.h"
47
48#include "efi.h"
49
50#ifdef CONFIG_X86_64
51#define memptr long
52#else
53#define memptr unsigned
54#endif
55
56/* boot/compressed/vmlinux start and end markers */
57extern char _head[], _end[];
58
59/* misc.c */
60extern memptr free_mem_ptr;
61extern memptr free_mem_end_ptr;
62void *malloc(int size);
63void free(void *where);
64void __putstr(const char *s);
65void __puthex(unsigned long value);
66#define error_putstr(__x) __putstr(__x)
67#define error_puthex(__x) __puthex(__x)
68
69#ifdef CONFIG_X86_VERBOSE_BOOTUP
70
71#define debug_putstr(__x) __putstr(__x)
72#define debug_puthex(__x) __puthex(__x)
73#define debug_putaddr(__x) { \
74 debug_putstr(#__x ": 0x"); \
75 debug_puthex((unsigned long)(__x)); \
76 debug_putstr("\n"); \
77 }
78
79#else
80
81static inline void debug_putstr(const char *s)
82{ }
83static inline void debug_puthex(unsigned long value)
84{ }
85#define debug_putaddr(x) /* */
86
87#endif
88
89/* cmdline.c */
90int cmdline_find_option(const char *option, char *buffer, int bufsize);
91int cmdline_find_option_bool(const char *option);
92
93struct mem_vector {
94 u64 start;
95 u64 size;
96};
97
98#ifdef CONFIG_RANDOMIZE_BASE
99/* kaslr.c */
100void choose_random_location(unsigned long input,
101 unsigned long input_size,
102 unsigned long *output,
103 unsigned long output_size,
104 unsigned long *virt_addr);
105#else
106static inline void choose_random_location(unsigned long input,
107 unsigned long input_size,
108 unsigned long *output,
109 unsigned long output_size,
110 unsigned long *virt_addr)
111{
112}
113#endif
114
115/* cpuflags.c */
116bool has_cpuflag(int flag);
117
118#ifdef CONFIG_X86_64
119extern int set_page_decrypted(unsigned long address);
120extern int set_page_encrypted(unsigned long address);
121extern int set_page_non_present(unsigned long address);
122extern unsigned char _pgtable[];
123#endif
124
125#ifdef CONFIG_EARLY_PRINTK
126/* early_serial_console.c */
127extern int early_serial_base;
128void console_init(void);
129#else
130static const int early_serial_base;
131static inline void console_init(void)
132{ }
133#endif
134
135#ifdef CONFIG_AMD_MEM_ENCRYPT
136void sev_enable(struct boot_params *bp);
137void snp_check_features(void);
138void sev_es_shutdown_ghcb(void);
139extern bool sev_es_check_ghcb_fault(unsigned long address);
140void snp_set_page_private(unsigned long paddr);
141void snp_set_page_shared(unsigned long paddr);
142void sev_prep_identity_maps(unsigned long top_level_pgt);
143#else
144static inline void sev_enable(struct boot_params *bp)
145{
146 /*
147 * bp->cc_blob_address should only be set by boot/compressed kernel.
148 * Initialize it to 0 unconditionally (thus here in this stub too) to
149 * ensure that uninitialized values from buggy bootloaders aren't
150 * propagated.
151 */
152 if (bp)
153 bp->cc_blob_address = 0;
154}
155static inline void snp_check_features(void) { }
156static inline void sev_es_shutdown_ghcb(void) { }
157static inline bool sev_es_check_ghcb_fault(unsigned long address)
158{
159 return false;
160}
161static inline void snp_set_page_private(unsigned long paddr) { }
162static inline void snp_set_page_shared(unsigned long paddr) { }
163static inline void sev_prep_identity_maps(unsigned long top_level_pgt) { }
164#endif
165
166/* acpi.c */
167#ifdef CONFIG_ACPI
168acpi_physical_address get_rsdp_addr(void);
169#else
170static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
171#endif
172
173#if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
174extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
175int count_immovable_mem_regions(void);
176#else
177static inline int count_immovable_mem_regions(void) { return 0; }
178#endif
179
180/* ident_map_64.c */
181extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
182extern void kernel_add_identity_map(unsigned long start, unsigned long end);
183
184/* Used by PAGE_KERN* macros: */
185extern pteval_t __default_kernel_pte_mask;
186
187/* idt_64.c */
188extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
189extern struct desc_ptr boot_idt_desc;
190
191#ifdef CONFIG_X86_64
192void cleanup_exception_handling(void);
193#else
194static inline void cleanup_exception_handling(void) { }
195#endif
196
197/* IDT Entry Points */
198void boot_page_fault(void);
199void boot_stage1_vc(void);
200void boot_stage2_vc(void);
201
202unsigned long sev_verify_cbit(unsigned long cr3);
203
204enum efi_type {
205 EFI_TYPE_64,
206 EFI_TYPE_32,
207 EFI_TYPE_NONE,
208};
209
210#ifdef CONFIG_EFI
211/* helpers for early EFI config table access */
212enum efi_type efi_get_type(struct boot_params *bp);
213unsigned long efi_get_system_table(struct boot_params *bp);
214int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
215 unsigned int *cfg_tbl_len);
216unsigned long efi_find_vendor_table(struct boot_params *bp,
217 unsigned long cfg_tbl_pa,
218 unsigned int cfg_tbl_len,
219 efi_guid_t guid);
220#else
221static inline enum efi_type efi_get_type(struct boot_params *bp)
222{
223 return EFI_TYPE_NONE;
224}
225
226static inline unsigned long efi_get_system_table(struct boot_params *bp)
227{
228 return 0;
229}
230
231static inline int efi_get_conf_table(struct boot_params *bp,
232 unsigned long *cfg_tbl_pa,
233 unsigned int *cfg_tbl_len)
234{
235 return -ENOENT;
236}
237
238static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
239 unsigned long cfg_tbl_pa,
240 unsigned int cfg_tbl_len,
241 efi_guid_t guid)
242{
243 return 0;
244}
245#endif /* CONFIG_EFI */
246
247#ifdef CONFIG_UNACCEPTED_MEMORY
248bool init_unaccepted_memory(void);
249#else
250static inline bool init_unaccepted_memory(void) { return false; }
251#endif
252
253/* Defined in EFI stub */
254extern struct efi_unaccepted_memory *unaccepted_table;
255void accept_memory(phys_addr_t start, phys_addr_t end);
256
257#endif /* BOOT_COMPRESSED_MISC_H */
258

source code of linux/arch/x86/boot/compressed/misc.h