xref: /openbmc/linux/arch/x86/boot/compressed/misc.h (revision be58f710)
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 #include <linux/linkage.h>
23 #include <linux/screen_info.h>
24 #include <linux/elf.h>
25 #include <linux/io.h>
26 #include <asm/page.h>
27 #include <asm/boot.h>
28 #include <asm/bootparam.h>
29 #include <asm/desc_defs.h>
30 
31 #define BOOT_CTYPE_H
32 #include <linux/acpi.h>
33 
34 #define BOOT_BOOT_H
35 #include "../ctype.h"
36 
37 #ifdef CONFIG_X86_64
38 #define memptr long
39 #else
40 #define memptr unsigned
41 #endif
42 
43 /* boot/compressed/vmlinux start and end markers */
44 extern char _head[], _end[];
45 
46 /* misc.c */
47 extern memptr free_mem_ptr;
48 extern memptr free_mem_end_ptr;
49 extern struct boot_params *boot_params;
50 void __putstr(const char *s);
51 void __puthex(unsigned long value);
52 #define error_putstr(__x)  __putstr(__x)
53 #define error_puthex(__x)  __puthex(__x)
54 
55 #ifdef CONFIG_X86_VERBOSE_BOOTUP
56 
57 #define debug_putstr(__x)  __putstr(__x)
58 #define debug_puthex(__x)  __puthex(__x)
59 #define debug_putaddr(__x) { \
60 		debug_putstr(#__x ": 0x"); \
61 		debug_puthex((unsigned long)(__x)); \
62 		debug_putstr("\n"); \
63 	}
64 
65 #else
66 
67 static inline void debug_putstr(const char *s)
68 { }
69 static inline void debug_puthex(unsigned long value)
70 { }
71 #define debug_putaddr(x) /* */
72 
73 #endif
74 
75 /* cmdline.c */
76 int cmdline_find_option(const char *option, char *buffer, int bufsize);
77 int cmdline_find_option_bool(const char *option);
78 
79 struct mem_vector {
80 	u64 start;
81 	u64 size;
82 };
83 
84 #ifdef CONFIG_RANDOMIZE_BASE
85 /* kaslr.c */
86 void choose_random_location(unsigned long input,
87 			    unsigned long input_size,
88 			    unsigned long *output,
89 			    unsigned long output_size,
90 			    unsigned long *virt_addr);
91 #else
92 static inline void choose_random_location(unsigned long input,
93 					  unsigned long input_size,
94 					  unsigned long *output,
95 					  unsigned long output_size,
96 					  unsigned long *virt_addr)
97 {
98 }
99 #endif
100 
101 /* cpuflags.c */
102 bool has_cpuflag(int flag);
103 
104 #ifdef CONFIG_X86_64
105 extern int set_page_decrypted(unsigned long address);
106 extern int set_page_encrypted(unsigned long address);
107 extern int set_page_non_present(unsigned long address);
108 extern unsigned char _pgtable[];
109 #endif
110 
111 #ifdef CONFIG_EARLY_PRINTK
112 /* early_serial_console.c */
113 extern int early_serial_base;
114 void console_init(void);
115 #else
116 static const int early_serial_base;
117 static inline void console_init(void)
118 { }
119 #endif
120 
121 void set_sev_encryption_mask(void);
122 
123 #ifdef CONFIG_AMD_MEM_ENCRYPT
124 void sev_es_shutdown_ghcb(void);
125 extern bool sev_es_check_ghcb_fault(unsigned long address);
126 #else
127 static inline void sev_es_shutdown_ghcb(void) { }
128 static inline bool sev_es_check_ghcb_fault(unsigned long address)
129 {
130 	return false;
131 }
132 #endif
133 
134 /* acpi.c */
135 #ifdef CONFIG_ACPI
136 acpi_physical_address get_rsdp_addr(void);
137 #else
138 static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
139 #endif
140 
141 #if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
142 extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
143 int count_immovable_mem_regions(void);
144 #else
145 static inline int count_immovable_mem_regions(void) { return 0; }
146 #endif
147 
148 /* ident_map_64.c */
149 #ifdef CONFIG_X86_5LEVEL
150 extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
151 #endif
152 
153 /* Used by PAGE_KERN* macros: */
154 extern pteval_t __default_kernel_pte_mask;
155 
156 /* idt_64.c */
157 extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
158 extern struct desc_ptr boot_idt_desc;
159 
160 #ifdef CONFIG_X86_64
161 void cleanup_exception_handling(void);
162 #else
163 static inline void cleanup_exception_handling(void) { }
164 #endif
165 
166 /* IDT Entry Points */
167 void boot_page_fault(void);
168 void boot_stage1_vc(void);
169 void boot_stage2_vc(void);
170 
171 unsigned long sev_verify_cbit(unsigned long cr3);
172 
173 #endif /* BOOT_COMPRESSED_MISC_H */
174