xref: /openbmc/linux/arch/x86/boot/compressed/misc.h (revision 07d9a767)
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 */
41 extern char _head[], _end[];
42 
43 /* misc.c */
44 extern memptr free_mem_ptr;
45 extern memptr free_mem_end_ptr;
46 extern struct boot_params *boot_params;
47 void __putstr(const char *s);
48 void __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 
64 static inline void debug_putstr(const char *s)
65 { }
66 static inline void debug_puthex(unsigned long value)
67 { }
68 #define debug_putaddr(x) /* */
69 
70 #endif
71 
72 /* cmdline.c */
73 int cmdline_find_option(const char *option, char *buffer, int bufsize);
74 int cmdline_find_option_bool(const char *option);
75 
76 struct mem_vector {
77 	u64 start;
78 	u64 size;
79 };
80 
81 #if CONFIG_RANDOMIZE_BASE
82 /* kaslr.c */
83 void 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
89 static 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 */
99 bool has_cpuflag(int flag);
100 
101 #ifdef CONFIG_X86_64
102 extern int set_page_decrypted(unsigned long address);
103 extern int set_page_encrypted(unsigned long address);
104 extern int set_page_non_present(unsigned long address);
105 extern unsigned char _pgtable[];
106 #endif
107 
108 #ifdef CONFIG_EARLY_PRINTK
109 /* early_serial_console.c */
110 extern int early_serial_base;
111 void console_init(void);
112 #else
113 static const int early_serial_base;
114 static inline void console_init(void)
115 { }
116 #endif
117 
118 void set_sev_encryption_mask(void);
119 
120 #ifdef CONFIG_AMD_MEM_ENCRYPT
121 void sev_es_shutdown_ghcb(void);
122 extern bool sev_es_check_ghcb_fault(unsigned long address);
123 #else
124 static inline void sev_es_shutdown_ghcb(void) { }
125 static 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
133 acpi_physical_address get_rsdp_addr(void);
134 #else
135 static 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)
139 extern struct mem_vector immovable_mem[MAX_NUMNODES*2];
140 int count_immovable_mem_regions(void);
141 #else
142 static inline int count_immovable_mem_regions(void) { return 0; }
143 #endif
144 
145 /* ident_map_64.c */
146 #ifdef CONFIG_X86_5LEVEL
147 extern unsigned int __pgtable_l5_enabled, pgdir_shift, ptrs_per_p4d;
148 #endif
149 
150 /* Used by PAGE_KERN* macros: */
151 extern pteval_t __default_kernel_pte_mask;
152 
153 /* idt_64.c */
154 extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
155 extern struct desc_ptr boot_idt_desc;
156 
157 /* IDT Entry Points */
158 void boot_page_fault(void);
159 void boot_stage1_vc(void);
160 void boot_stage2_vc(void);
161 
162 unsigned long sev_verify_cbit(unsigned long cr3);
163 
164 #endif /* BOOT_COMPRESSED_MISC_H */
165