Commit | Line | Data |
---|---|---|
457c8996 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 | 2 | /* |
1da177e4 LT |
3 | * Copyright (C) 1995 Linus Torvalds |
4 | * | |
12609013 IM |
5 | * This file contains the setup_arch() code, which handles the architecture-dependent |
6 | * parts of early kernel initialization. | |
1da177e4 | 7 | */ |
ea7b4244 | 8 | #include <linux/acpi.h> |
1da177e4 | 9 | #include <linux/console.h> |
12609013 | 10 | #include <linux/crash_dump.h> |
0b1abd1f | 11 | #include <linux/dma-map-ops.h> |
12609013 | 12 | #include <linux/dmi.h> |
1da177e4 | 13 | #include <linux/efi.h> |
b69a2afd | 14 | #include <linux/ima.h> |
12609013 IM |
15 | #include <linux/init_ohci1394_dma.h> |
16 | #include <linux/initrd.h> | |
138fe4e0 | 17 | #include <linux/iscsi_ibft.h> |
12609013 | 18 | #include <linux/memblock.h> |
f39650de | 19 | #include <linux/panic_notifier.h> |
376ff035 | 20 | #include <linux/pci.h> |
12609013 | 21 | #include <linux/root_dev.h> |
cf11e85f | 22 | #include <linux/hugetlb.h> |
69575d38 | 23 | #include <linux/tboot.h> |
1b5aeebf | 24 | #include <linux/usb/xhci-dbgp.h> |
a945c834 | 25 | #include <linux/static_call.h> |
0a0f0d8b | 26 | #include <linux/swiotlb.h> |
68b8e971 | 27 | #include <linux/random.h> |
1bc3b91a | 28 | |
12609013 IM |
29 | #include <uapi/linux/mount.h> |
30 | ||
31 | #include <xen/xen.h> | |
32 | ||
9635b47d | 33 | #include <asm/apic.h> |
13c01139 | 34 | #include <asm/numa.h> |
ce3fe6b2 | 35 | #include <asm/bios_ebda.h> |
cc9f7a0c | 36 | #include <asm/bugs.h> |
0b9a6a8b | 37 | #include <asm/cacheinfo.h> |
6e5385d4 | 38 | #include <asm/cpu.h> |
12609013 | 39 | #include <asm/efi.h> |
1d9b16d1 | 40 | #include <asm/gart.h> |
88b094fb | 41 | #include <asm/hypervisor.h> |
12609013 IM |
42 | #include <asm/io_apic.h> |
43 | #include <asm/kasan.h> | |
44 | #include <asm/kaslr.h> | |
a2202aa2 | 45 | #include <asm/mce.h> |
4d5cff69 | 46 | #include <asm/memtype.h> |
12609013 | 47 | #include <asm/mtrr.h> |
ca947b72 | 48 | #include <asm/realmode.h> |
12609013 IM |
49 | #include <asm/olpc_ofw.h> |
50 | #include <asm/pci-direct.h> | |
da6b737b | 51 | #include <asm/prom.h> |
12609013 | 52 | #include <asm/proto.h> |
9a90ed06 | 53 | #include <asm/thermal.h> |
ee9f8fce | 54 | #include <asm/unwind.h> |
12609013 | 55 | #include <asm/vsyscall.h> |
186525bd | 56 | #include <linux/vmalloc.h> |
46d671b5 | 57 | |
2b72394e | 58 | /* |
360db4ac IM |
59 | * max_low_pfn_mapped: highest directly mapped pfn < 4 GB |
60 | * max_pfn_mapped: highest directly mapped pfn > 4 GB | |
66520ebc | 61 | * |
09821ff1 | 62 | * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are |
360db4ac | 63 | * represented by pfn_mapped[]. |
2b72394e PE |
64 | */ |
65 | unsigned long max_low_pfn_mapped; | |
66 | unsigned long max_pfn_mapped; | |
67 | ||
e808bae2 | 68 | #ifdef CONFIG_DMI |
796216a5 | 69 | RESERVE_BRK(dmi_alloc, 65536); |
e808bae2 | 70 | #endif |
796216a5 | 71 | |
c0b5842a | 72 | |
360db4ac IM |
73 | unsigned long _brk_start = (unsigned long)__brk_base; |
74 | unsigned long _brk_end = (unsigned long)__brk_base; | |
93dbda7c | 75 | |
217b8ce8 | 76 | struct boot_params boot_params; |
217b8ce8 | 77 | |
4046d6e8 | 78 | /* |
360db4ac IM |
79 | * These are the four main kernel memory regions, we put them into |
80 | * the resource tree so that kdump tools and other debugging tools | |
81 | * recover it: | |
4046d6e8 | 82 | */ |
360db4ac | 83 | |
a3299754 KC |
84 | static struct resource rodata_resource = { |
85 | .name = "Kernel rodata", | |
86 | .start = 0, | |
87 | .end = 0, | |
88 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM | |
89 | }; | |
90 | ||
4046d6e8 LT |
91 | static struct resource data_resource = { |
92 | .name = "Kernel data", | |
93 | .start = 0, | |
94 | .end = 0, | |
95 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM | |
96 | }; | |
97 | ||
98 | static struct resource code_resource = { | |
99 | .name = "Kernel code", | |
100 | .start = 0, | |
101 | .end = 0, | |
102 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM | |
103 | }; | |
104 | ||
105 | static struct resource bss_resource = { | |
106 | .name = "Kernel bss", | |
107 | .start = 0, | |
108 | .end = 0, | |
109 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM | |
110 | }; | |
111 | ||
112 | ||
7dea23ec | 113 | #ifdef CONFIG_X86_32 |
360db4ac | 114 | /* CPU data as detected by the assembly code in head_32.S */ |
6415813b MK |
115 | struct cpuinfo_x86 new_cpu_data; |
116 | ||
360db4ac | 117 | /* Common CPU data for all CPUs */ |
6415813b | 118 | struct cpuinfo_x86 boot_cpu_data __read_mostly; |
129f6946 | 119 | EXPORT_SYMBOL(boot_cpu_data); |
1da177e4 | 120 | |
0c254e38 AS |
121 | unsigned int def_to_bigsmp; |
122 | ||
7dea23ec YL |
123 | struct apm_info apm_info; |
124 | EXPORT_SYMBOL(apm_info); | |
125 | ||
126 | #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ | |
127 | defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) | |
128 | struct ist_info ist_info; | |
129 | EXPORT_SYMBOL(ist_info); | |
130 | #else | |
131 | struct ist_info ist_info; | |
132 | #endif | |
133 | ||
134 | #else | |
162434e7 | 135 | struct cpuinfo_x86 boot_cpu_data __read_mostly; |
7dea23ec YL |
136 | EXPORT_SYMBOL(boot_cpu_data); |
137 | #endif | |
138 | ||
139 | ||
140 | #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64) | |
404f6aac | 141 | __visible unsigned long mmu_cr4_features __ro_after_init; |
7dea23ec | 142 | #else |
404f6aac | 143 | __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; |
7dea23ec YL |
144 | #endif |
145 | ||
b69a2afd JM |
146 | #ifdef CONFIG_IMA |
147 | static phys_addr_t ima_kexec_buffer_phys; | |
148 | static size_t ima_kexec_buffer_size; | |
149 | #endif | |
150 | ||
5031296c PA |
151 | /* Boot loader ID and version as integers, for the benefit of proc_dointvec */ |
152 | int bootloader_type, bootloader_version; | |
1da177e4 | 153 | |
1da177e4 LT |
154 | /* |
155 | * Setup options | |
156 | */ | |
1da177e4 | 157 | struct screen_info screen_info; |
129f6946 | 158 | EXPORT_SYMBOL(screen_info); |
1da177e4 | 159 | struct edid_info edid_info; |
5e518d76 | 160 | EXPORT_SYMBOL_GPL(edid_info); |
1da177e4 | 161 | |
1da177e4 LT |
162 | extern int root_mountflags; |
163 | ||
e44b7b75 | 164 | unsigned long saved_video_mode; |
1da177e4 | 165 | |
cf8fa920 | 166 | #define RAMDISK_IMAGE_START_MASK 0x07FF |
1da177e4 | 167 | #define RAMDISK_PROMPT_FLAG 0x8000 |
cf8fa920 | 168 | #define RAMDISK_LOAD_FLAG 0x4000 |
1da177e4 | 169 | |
4e498b66 | 170 | static char __initdata command_line[COMMAND_LINE_SIZE]; |
516cbf37 TB |
171 | #ifdef CONFIG_CMDLINE_BOOL |
172 | static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; | |
173 | #endif | |
1da177e4 | 174 | |
1da177e4 LT |
175 | #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) |
176 | struct edd edd; | |
177 | #ifdef CONFIG_EDD_MODULE | |
178 | EXPORT_SYMBOL(edd); | |
179 | #endif | |
180 | /** | |
181 | * copy_edd() - Copy the BIOS EDD information | |
182 | * from boot_params into a safe place. | |
183 | * | |
184 | */ | |
9eaa192d | 185 | static inline void __init copy_edd(void) |
1da177e4 | 186 | { |
30c82645 PA |
187 | memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, |
188 | sizeof(edd.mbr_signature)); | |
189 | memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); | |
190 | edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; | |
191 | edd.edd_info_nr = boot_params.eddbuf_entries; | |
1da177e4 LT |
192 | } |
193 | #else | |
9eaa192d | 194 | static inline void __init copy_edd(void) |
1da177e4 LT |
195 | { |
196 | } | |
197 | #endif | |
198 | ||
5368a2be PA |
199 | void * __init extend_brk(size_t size, size_t align) |
200 | { | |
201 | size_t mask = align - 1; | |
202 | void *ret; | |
203 | ||
204 | BUG_ON(_brk_start == 0); | |
205 | BUG_ON(align & mask); | |
206 | ||
207 | _brk_end = (_brk_end + mask) & ~mask; | |
208 | BUG_ON((char *)(_brk_end + size) > __brk_limit); | |
209 | ||
210 | ret = (void *)_brk_end; | |
211 | _brk_end += size; | |
212 | ||
213 | memset(ret, 0, size); | |
214 | ||
215 | return ret; | |
216 | } | |
217 | ||
148b2098 | 218 | #ifdef CONFIG_X86_32 |
e5f15b45 | 219 | static void __init cleanup_highmap(void) |
f005fe12 YL |
220 | { |
221 | } | |
854c879f PE |
222 | #endif |
223 | ||
5368a2be PA |
224 | static void __init reserve_brk(void) |
225 | { | |
226 | if (_brk_end > _brk_start) | |
fc8d7826 AD |
227 | memblock_reserve(__pa_symbol(_brk_start), |
228 | _brk_end - _brk_start); | |
5368a2be PA |
229 | |
230 | /* Mark brk area as locked down and no longer taking any | |
231 | new allocations */ | |
232 | _brk_start = 0; | |
233 | } | |
234 | ||
5aa3d718 BP |
235 | u64 relocated_ramdisk; |
236 | ||
cf8fa920 PA |
237 | #ifdef CONFIG_BLK_DEV_INITRD |
238 | ||
a8a51a88 YL |
239 | static u64 __init get_ramdisk_image(void) |
240 | { | |
241 | u64 ramdisk_image = boot_params.hdr.ramdisk_image; | |
242 | ||
ee92d815 YL |
243 | ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; |
244 | ||
694cfd87 RM |
245 | if (ramdisk_image == 0) |
246 | ramdisk_image = phys_initrd_start; | |
247 | ||
a8a51a88 YL |
248 | return ramdisk_image; |
249 | } | |
250 | static u64 __init get_ramdisk_size(void) | |
251 | { | |
252 | u64 ramdisk_size = boot_params.hdr.ramdisk_size; | |
253 | ||
ee92d815 YL |
254 | ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; |
255 | ||
694cfd87 RM |
256 | if (ramdisk_size == 0) |
257 | ramdisk_size = phys_initrd_size; | |
258 | ||
a8a51a88 YL |
259 | return ramdisk_size; |
260 | } | |
261 | ||
eb1379cb | 262 | static void __init relocate_initrd(void) |
cf8fa920 | 263 | { |
c967da6a | 264 | /* Assume only end is not page aligned */ |
a8a51a88 YL |
265 | u64 ramdisk_image = get_ramdisk_image(); |
266 | u64 ramdisk_size = get_ramdisk_size(); | |
c967da6a | 267 | u64 area_size = PAGE_ALIGN(ramdisk_size); |
cf8fa920 | 268 | |
e8c57d40 | 269 | /* We need to move the initrd down into directly mapped mem */ |
3c45ee6d MR |
270 | relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0, |
271 | PFN_PHYS(max_pfn_mapped)); | |
5aa3d718 | 272 | if (!relocated_ramdisk) |
3945e2c9 | 273 | panic("Cannot find place for new RAMDISK of size %lld\n", |
5aa3d718 | 274 | ramdisk_size); |
3945e2c9 | 275 | |
5aa3d718 | 276 | initrd_start = relocated_ramdisk + PAGE_OFFSET; |
cf8fa920 | 277 | initrd_end = initrd_start + ramdisk_size; |
365811d6 | 278 | printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", |
5aa3d718 | 279 | relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); |
cf8fa920 | 280 | |
5dd2c4bd MS |
281 | copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size); |
282 | ||
365811d6 BH |
283 | printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to" |
284 | " [mem %#010llx-%#010llx]\n", | |
ba5b14cc | 285 | ramdisk_image, ramdisk_image + ramdisk_size - 1, |
5aa3d718 | 286 | relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); |
eb1379cb | 287 | } |
9a27f5c5 | 288 | |
1b8c78be YL |
289 | static void __init early_reserve_initrd(void) |
290 | { | |
291 | /* Assume only end is not page aligned */ | |
a8a51a88 YL |
292 | u64 ramdisk_image = get_ramdisk_image(); |
293 | u64 ramdisk_size = get_ramdisk_size(); | |
1b8c78be YL |
294 | u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); |
295 | ||
296 | if (!boot_params.hdr.type_of_loader || | |
297 | !ramdisk_image || !ramdisk_size) | |
298 | return; /* No initrd provided by bootloader */ | |
299 | ||
300 | memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); | |
301 | } | |
3c45ee6d | 302 | |
eb1379cb YL |
303 | static void __init reserve_initrd(void) |
304 | { | |
c967da6a | 305 | /* Assume only end is not page aligned */ |
a8a51a88 YL |
306 | u64 ramdisk_image = get_ramdisk_image(); |
307 | u64 ramdisk_size = get_ramdisk_size(); | |
c967da6a | 308 | u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); |
eb1379cb YL |
309 | |
310 | if (!boot_params.hdr.type_of_loader || | |
311 | !ramdisk_image || !ramdisk_size) | |
312 | return; /* No initrd provided by bootloader */ | |
313 | ||
314 | initrd_start = 0; | |
315 | ||
365811d6 BH |
316 | printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, |
317 | ramdisk_end - 1); | |
eb1379cb | 318 | |
74f27655 | 319 | if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image), |
e8c57d40 YL |
320 | PFN_DOWN(ramdisk_end))) { |
321 | /* All are mapped, easy case */ | |
eb1379cb YL |
322 | initrd_start = ramdisk_image + PAGE_OFFSET; |
323 | initrd_end = initrd_start + ramdisk_size; | |
324 | return; | |
325 | } | |
326 | ||
eb1379cb | 327 | relocate_initrd(); |
8c5dd8f4 | 328 | |
3ecc6834 | 329 | memblock_phys_free(ramdisk_image, ramdisk_end - ramdisk_image); |
cf8fa920 | 330 | } |
af06f8b7 | 331 | |
225c37d7 | 332 | #else |
1b8c78be YL |
333 | static void __init early_reserve_initrd(void) |
334 | { | |
335 | } | |
eb1379cb | 336 | static void __init reserve_initrd(void) |
225c37d7 YL |
337 | { |
338 | } | |
cf8fa920 PA |
339 | #endif /* CONFIG_BLK_DEV_INITRD */ |
340 | ||
b69a2afd JM |
341 | static void __init add_early_ima_buffer(u64 phys_addr) |
342 | { | |
343 | #ifdef CONFIG_IMA | |
344 | struct ima_setup_data *data; | |
345 | ||
346 | data = early_memremap(phys_addr + sizeof(struct setup_data), sizeof(*data)); | |
347 | if (!data) { | |
348 | pr_warn("setup: failed to memremap ima_setup_data entry\n"); | |
349 | return; | |
350 | } | |
351 | ||
352 | if (data->size) { | |
353 | memblock_reserve(data->addr, data->size); | |
354 | ima_kexec_buffer_phys = data->addr; | |
355 | ima_kexec_buffer_size = data->size; | |
356 | } | |
357 | ||
358 | early_memunmap(data, sizeof(*data)); | |
359 | #else | |
360 | pr_warn("Passed IMA kexec data, but CONFIG_IMA not set. Ignoring.\n"); | |
361 | #endif | |
362 | } | |
363 | ||
364 | #if defined(CONFIG_HAVE_IMA_KEXEC) && !defined(CONFIG_OF_FLATTREE) | |
365 | int __init ima_free_kexec_buffer(void) | |
366 | { | |
367 | int rc; | |
368 | ||
369 | if (!ima_kexec_buffer_size) | |
370 | return -ENOENT; | |
371 | ||
372 | rc = memblock_phys_free(ima_kexec_buffer_phys, | |
373 | ima_kexec_buffer_size); | |
374 | if (rc) | |
375 | return rc; | |
376 | ||
377 | ima_kexec_buffer_phys = 0; | |
378 | ima_kexec_buffer_size = 0; | |
379 | ||
380 | return 0; | |
381 | } | |
382 | ||
383 | int __init ima_get_kexec_buffer(void **addr, size_t *size) | |
384 | { | |
385 | if (!ima_kexec_buffer_size) | |
386 | return -ENOENT; | |
387 | ||
388 | *addr = __va(ima_kexec_buffer_phys); | |
389 | *size = ima_kexec_buffer_size; | |
390 | ||
391 | return 0; | |
392 | } | |
393 | #endif | |
394 | ||
29f784e3 | 395 | static void __init parse_setup_data(void) |
257b0fde YL |
396 | { |
397 | struct setup_data *data; | |
30e46b57 | 398 | u64 pa_data, pa_next; |
257b0fde | 399 | |
257b0fde YL |
400 | pa_data = boot_params.hdr.setup_data; |
401 | while (pa_data) { | |
7389882c | 402 | u32 data_len, data_type; |
f1c2b357 | 403 | |
7389882c | 404 | data = early_memremap(pa_data, sizeof(*data)); |
f1c2b357 | 405 | data_len = data->len + sizeof(struct setup_data); |
30e46b57 LC |
406 | data_type = data->type; |
407 | pa_next = data->next; | |
8d4a40bc | 408 | early_memunmap(data, sizeof(*data)); |
f1c2b357 | 409 | |
30e46b57 | 410 | switch (data_type) { |
257b0fde | 411 | case SETUP_E820_EXT: |
914053c0 | 412 | e820__memory_setup_extended(pa_data, data_len); |
257b0fde | 413 | break; |
da6b737b SAS |
414 | case SETUP_DTB: |
415 | add_dtb(pa_data); | |
257b0fde | 416 | break; |
1fec0533 DY |
417 | case SETUP_EFI: |
418 | parse_efi_setup(pa_data, data_len); | |
419 | break; | |
b69a2afd JM |
420 | case SETUP_IMA: |
421 | add_early_ima_buffer(pa_data); | |
422 | break; | |
68b8e971 JD |
423 | case SETUP_RNG_SEED: |
424 | data = early_memremap(pa_data, data_len); | |
425 | add_bootloader_randomness(data->data, data->len); | |
426 | /* Zero seed for forward secrecy. */ | |
427 | memzero_explicit(data->data, data->len); | |
428 | /* Zero length in case we find ourselves back here by accident. */ | |
429 | memzero_explicit(&data->len, sizeof(data->len)); | |
430 | early_memunmap(data, data_len); | |
431 | break; | |
257b0fde YL |
432 | default: |
433 | break; | |
434 | } | |
30e46b57 | 435 | pa_data = pa_next; |
257b0fde YL |
436 | } |
437 | } | |
438 | ||
a9ce6bc1 | 439 | static void __init memblock_x86_reserve_range_setup_data(void) |
a0a0becd | 440 | { |
7228918b | 441 | struct setup_indirect *indirect; |
a0a0becd | 442 | struct setup_data *data; |
7228918b RP |
443 | u64 pa_data, pa_next; |
444 | u32 len; | |
a0a0becd | 445 | |
a0a0becd YL |
446 | pa_data = boot_params.hdr.setup_data; |
447 | while (pa_data) { | |
88b4c146 | 448 | data = early_memremap(pa_data, sizeof(*data)); |
7228918b RP |
449 | if (!data) { |
450 | pr_warn("setup: failed to memremap setup_data entry\n"); | |
451 | return; | |
452 | } | |
453 | ||
454 | len = sizeof(*data); | |
455 | pa_next = data->next; | |
456 | ||
24aa0788 | 457 | memblock_reserve(pa_data, sizeof(*data) + data->len); |
b3c72fc9 | 458 | |
7228918b RP |
459 | if (data->type == SETUP_INDIRECT) { |
460 | len += data->len; | |
461 | early_memunmap(data, sizeof(*data)); | |
462 | data = early_memremap(pa_data, len); | |
463 | if (!data) { | |
464 | pr_warn("setup: failed to memremap indirect setup_data\n"); | |
465 | return; | |
466 | } | |
b3c72fc9 | 467 | |
7228918b RP |
468 | indirect = (struct setup_indirect *)data->data; |
469 | ||
470 | if (indirect->type != SETUP_INDIRECT) | |
471 | memblock_reserve(indirect->addr, indirect->len); | |
472 | } | |
473 | ||
474 | pa_data = pa_next; | |
475 | early_memunmap(data, len); | |
a0a0becd YL |
476 | } |
477 | } | |
478 | ||
ccb4defa YL |
479 | /* |
480 | * --------- Crashkernel reservation ------------------------------ | |
481 | */ | |
482 | ||
606134f7 | 483 | /* 16M alignment for crash kernel regions */ |
9ca5c8e6 | 484 | #define CRASH_ALIGN SZ_16M |
606134f7 | 485 | |
7f8595bf | 486 | /* |
8ff80fbe BH |
487 | * Keep the crash kernel below this limit. |
488 | * | |
360db4ac | 489 | * Earlier 32-bits kernels would limit the kernel to the low 512 MB range |
8ff80fbe BH |
490 | * due to mapping restrictions. |
491 | * | |
360db4ac | 492 | * 64-bit kdump kernels need to be restricted to be under 64 TB, which is |
11a98f37 | 493 | * the upper limit of system RAM in 4-level paging mode. Since the kdump |
360db4ac IM |
494 | * jump could be from 5-level paging to 4-level paging, the jump will fail if |
495 | * the kernel is put above 64 TB, and during the 1st kernel bootup there's | |
496 | * no good way to detect the paging mode of the target kernel which will be | |
497 | * loaded for dumping. | |
7f8595bf PA |
498 | */ |
499 | #ifdef CONFIG_X86_32 | |
9ca5c8e6 DY |
500 | # define CRASH_ADDR_LOW_MAX SZ_512M |
501 | # define CRASH_ADDR_HIGH_MAX SZ_512M | |
7f8595bf | 502 | #else |
9ca5c8e6 | 503 | # define CRASH_ADDR_LOW_MAX SZ_4G |
8ff80fbe | 504 | # define CRASH_ADDR_HIGH_MAX SZ_64T |
7f8595bf PA |
505 | #endif |
506 | ||
eb6db83d | 507 | static int __init reserve_crashkernel_low(void) |
0212f915 YL |
508 | { |
509 | #ifdef CONFIG_X86_64 | |
f56d5578 | 510 | unsigned long long base, low_base = 0, low_size = 0; |
6120cdc0 | 511 | unsigned long low_mem_limit; |
0212f915 YL |
512 | int ret; |
513 | ||
6120cdc0 | 514 | low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX); |
97eac21b | 515 | |
adbc742b | 516 | /* crashkernel=Y,low */ |
6120cdc0 | 517 | ret = parse_crashkernel_low(boot_command_line, low_mem_limit, &low_size, &base); |
f56d5578 | 518 | if (ret) { |
c729de8f | 519 | /* |
392e879a | 520 | * two parts from kernel/dma/swiotlb.c: |
94fb9334 JR |
521 | * -swiotlb size: user-specified with swiotlb= or default. |
522 | * | |
523 | * -swiotlb overflow buffer: now hardcoded to 32k. We round it | |
524 | * to 8M for other buffers that may need to stay low too. Also | |
525 | * make sure we allocate enough extra low memory so that we | |
526 | * don't run out of DMA buffers for 32-bit devices. | |
c729de8f | 527 | */ |
97eac21b | 528 | low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); |
c729de8f | 529 | } else { |
adbc742b | 530 | /* passed with crashkernel=0,low ? */ |
c729de8f | 531 | if (!low_size) |
eb6db83d | 532 | return 0; |
c729de8f | 533 | } |
0212f915 | 534 | |
6120cdc0 | 535 | low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); |
0212f915 | 536 | if (!low_base) { |
eb6db83d BH |
537 | pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", |
538 | (unsigned long)(low_size >> 20)); | |
539 | return -ENOMEM; | |
0212f915 | 540 | } |
0212f915 | 541 | |
6120cdc0 | 542 | pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (low RAM limit: %ldMB)\n", |
97eac21b BP |
543 | (unsigned long)(low_size >> 20), |
544 | (unsigned long)(low_base >> 20), | |
6120cdc0 | 545 | (unsigned long)(low_mem_limit >> 20)); |
97eac21b | 546 | |
0212f915 YL |
547 | crashk_low_res.start = low_base; |
548 | crashk_low_res.end = low_base + low_size - 1; | |
549 | insert_resource(&iomem_resource, &crashk_low_res); | |
7f8595bf | 550 | #endif |
eb6db83d | 551 | return 0; |
0212f915 | 552 | } |
7f8595bf | 553 | |
29f784e3 | 554 | static void __init reserve_crashkernel(void) |
ccb4defa | 555 | { |
f56d5578 | 556 | unsigned long long crash_size, crash_base, total_mem; |
55a20ee7 | 557 | bool high = false; |
ccb4defa YL |
558 | int ret; |
559 | ||
4ece09be JZ |
560 | if (!IS_ENABLED(CONFIG_KEXEC_CORE)) |
561 | return; | |
562 | ||
09c71bfd | 563 | total_mem = memblock_phys_mem_size(); |
ccb4defa | 564 | |
55a20ee7 | 565 | /* crashkernel=XM */ |
97eac21b | 566 | ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); |
55a20ee7 | 567 | if (ret != 0 || crash_size <= 0) { |
adbc742b | 568 | /* crashkernel=X,high */ |
55a20ee7 | 569 | ret = parse_crashkernel_high(boot_command_line, total_mem, |
97eac21b | 570 | &crash_size, &crash_base); |
55a20ee7 YL |
571 | if (ret != 0 || crash_size <= 0) |
572 | return; | |
573 | high = true; | |
574 | } | |
32105f7f | 575 | |
3db3eb28 PT |
576 | if (xen_pv_domain()) { |
577 | pr_info("Ignoring crashkernel for a Xen PV domain\n"); | |
578 | return; | |
579 | } | |
580 | ||
32105f7f | 581 | /* 0 means: find the address automatically */ |
b9ac3849 | 582 | if (!crash_base) { |
9f4c1396 | 583 | /* |
a8d4c824 | 584 | * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, |
b9ac3849 DY |
585 | * crashkernel=x,high reserves memory over 4G, also allocates |
586 | * 256M extra low memory for DMA buffers and swiotlb. | |
587 | * But the extra memory is not required for all machines. | |
588 | * So try low memory first and fall back to high memory | |
589 | * unless "crashkernel=size[KMG],high" is specified. | |
9f4c1396 | 590 | */ |
b9ac3849 | 591 | if (!high) |
6120cdc0 MR |
592 | crash_base = memblock_phys_alloc_range(crash_size, |
593 | CRASH_ALIGN, CRASH_ALIGN, | |
594 | CRASH_ADDR_LOW_MAX); | |
b9ac3849 | 595 | if (!crash_base) |
6120cdc0 MR |
596 | crash_base = memblock_phys_alloc_range(crash_size, |
597 | CRASH_ALIGN, CRASH_ALIGN, | |
598 | CRASH_ADDR_HIGH_MAX); | |
1f5026a7 | 599 | if (!crash_base) { |
44280733 | 600 | pr_info("crashkernel reservation failed - No suitable area found.\n"); |
ccb4defa YL |
601 | return; |
602 | } | |
32105f7f | 603 | } else { |
44280733 YL |
604 | unsigned long long start; |
605 | ||
6120cdc0 MR |
606 | start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base, |
607 | crash_base + crash_size); | |
44280733 YL |
608 | if (start != crash_base) { |
609 | pr_info("crashkernel reservation failed - memory is in use.\n"); | |
ccb4defa YL |
610 | return; |
611 | } | |
32105f7f | 612 | } |
ccb4defa | 613 | |
eb6db83d | 614 | if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { |
3ecc6834 | 615 | memblock_phys_free(crash_base, crash_size); |
eb6db83d BH |
616 | return; |
617 | } | |
ccb4defa | 618 | |
f56d5578 BP |
619 | pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", |
620 | (unsigned long)(crash_size >> 20), | |
621 | (unsigned long)(crash_base >> 20), | |
622 | (unsigned long)(total_mem >> 20)); | |
ccb4defa | 623 | |
32105f7f BW |
624 | crashk_res.start = crash_base; |
625 | crashk_res.end = crash_base + crash_size - 1; | |
626 | insert_resource(&iomem_resource, &crashk_res); | |
ccb4defa | 627 | } |
ccb4defa | 628 | |
bdba0e70 YL |
629 | static struct resource standard_io_resources[] = { |
630 | { .name = "dma1", .start = 0x00, .end = 0x1f, | |
631 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
632 | { .name = "pic1", .start = 0x20, .end = 0x21, | |
633 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
634 | { .name = "timer0", .start = 0x40, .end = 0x43, | |
635 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
636 | { .name = "timer1", .start = 0x50, .end = 0x53, | |
637 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
638 | { .name = "keyboard", .start = 0x60, .end = 0x60, | |
639 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
640 | { .name = "keyboard", .start = 0x64, .end = 0x64, | |
641 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
642 | { .name = "dma page reg", .start = 0x80, .end = 0x8f, | |
643 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
644 | { .name = "pic2", .start = 0xa0, .end = 0xa1, | |
645 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
646 | { .name = "dma2", .start = 0xc0, .end = 0xdf, | |
647 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, | |
648 | { .name = "fpu", .start = 0xf0, .end = 0xff, | |
649 | .flags = IORESOURCE_BUSY | IORESOURCE_IO } | |
650 | }; | |
651 | ||
8fee697d | 652 | void __init reserve_standard_io_resources(void) |
bdba0e70 YL |
653 | { |
654 | int i; | |
655 | ||
656 | /* request I/O space for devices used on all i[345]86 PCs */ | |
657 | for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) | |
658 | request_resource(&ioport_resource, &standard_io_resources[i]); | |
659 | ||
660 | } | |
661 | ||
a9acc536 JB |
662 | static bool __init snb_gfx_workaround_needed(void) |
663 | { | |
e43b3cec | 664 | #ifdef CONFIG_PCI |
a9acc536 JB |
665 | int i; |
666 | u16 vendor, devid; | |
ab3cd867 | 667 | static const __initconst u16 snb_ids[] = { |
a9acc536 JB |
668 | 0x0102, |
669 | 0x0112, | |
670 | 0x0122, | |
671 | 0x0106, | |
672 | 0x0116, | |
673 | 0x0126, | |
674 | 0x010a, | |
675 | }; | |
676 | ||
677 | /* Assume no if something weird is going on with PCI */ | |
678 | if (!early_pci_allowed()) | |
679 | return false; | |
680 | ||
681 | vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); | |
682 | if (vendor != 0x8086) | |
683 | return false; | |
684 | ||
685 | devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); | |
686 | for (i = 0; i < ARRAY_SIZE(snb_ids); i++) | |
687 | if (devid == snb_ids[i]) | |
688 | return true; | |
e43b3cec | 689 | #endif |
a9acc536 JB |
690 | |
691 | return false; | |
692 | } | |
693 | ||
694 | /* | |
695 | * Sandy Bridge graphics has trouble with certain ranges, exclude | |
696 | * them from allocation. | |
697 | */ | |
698 | static void __init trim_snb_memory(void) | |
699 | { | |
ab3cd867 | 700 | static const __initconst unsigned long bad_pages[] = { |
a9acc536 JB |
701 | 0x20050000, |
702 | 0x20110000, | |
703 | 0x20130000, | |
704 | 0x20138000, | |
705 | 0x40004000, | |
706 | }; | |
707 | int i; | |
708 | ||
709 | if (!snb_gfx_workaround_needed()) | |
710 | return; | |
711 | ||
712 | printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); | |
713 | ||
714 | /* | |
c361e5d4 MR |
715 | * SandyBridge integrated graphics devices have a bug that prevents |
716 | * them from accessing certain memory ranges, namely anything below | |
717 | * 1M and in the pages listed in bad_pages[] above. | |
718 | * | |
f1d4d47c MR |
719 | * To avoid these pages being ever accessed by SNB gfx devices reserve |
720 | * bad_pages that have not already been reserved at boot time. | |
721 | * All memory below the 1 MB mark is anyway reserved later during | |
722 | * setup_arch(), so there is no need to reserve it here. | |
a9acc536 | 723 | */ |
c361e5d4 | 724 | |
a9acc536 JB |
725 | for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { |
726 | if (memblock_reserve(bad_pages[i], PAGE_SIZE)) | |
727 | printk(KERN_WARNING "failed to reserve 0x%08lx\n", | |
728 | bad_pages[i]); | |
729 | } | |
730 | } | |
731 | ||
1b5576e6 YL |
732 | static void __init trim_bios_range(void) |
733 | { | |
5c279c4c MR |
734 | /* |
735 | * A special case is the first 4Kb of memory; | |
736 | * This is a BIOS owned area, not kernel ram, but generally | |
737 | * not listed as such in the E820 table. | |
738 | * | |
739 | * This typically reserves additional memory (64KiB by default) | |
740 | * since some BIOSes are known to corrupt low memory. See the | |
741 | * Kconfig help text for X86_RESERVE_LOW. | |
742 | */ | |
743 | e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); | |
744 | ||
1b5576e6 | 745 | /* |
11a98f37 C |
746 | * special case: Some BIOSes report the PC BIOS |
747 | * area (640Kb -> 1Mb) as RAM even though it is not. | |
1b5576e6 YL |
748 | * take them out. |
749 | */ | |
09821ff1 | 750 | e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); |
a9acc536 | 751 | |
f9748fa0 | 752 | e820__update_table(e820_table); |
1b5576e6 YL |
753 | } |
754 | ||
b422a309 YL |
755 | /* called before trim_bios_range() to spare extra sanitize */ |
756 | static void __init e820_add_kernel_range(void) | |
757 | { | |
758 | u64 start = __pa_symbol(_text); | |
759 | u64 size = __pa_symbol(_end) - start; | |
760 | ||
761 | /* | |
09821ff1 | 762 | * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and |
b422a309 YL |
763 | * attempt to fix it by adding the range. We may have a confused BIOS, |
764 | * or the user may have used memmap=exactmap or memmap=xxM$yyM to | |
765 | * exclude kernel range. If we really are running on top non-RAM, | |
766 | * we will crash later anyways. | |
767 | */ | |
09821ff1 | 768 | if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) |
b422a309 YL |
769 | return; |
770 | ||
09821ff1 IM |
771 | pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); |
772 | e820__range_remove(start, size, E820_TYPE_RAM, 0); | |
773 | e820__range_add(start, size, E820_TYPE_RAM); | |
b422a309 YL |
774 | } |
775 | ||
a799c2bd | 776 | static void __init early_reserve_memory(void) |
95c96084 | 777 | { |
a799c2bd MR |
778 | /* |
779 | * Reserve the memory occupied by the kernel between _text and | |
780 | * __end_of_kernel_reserve symbols. Any kernel sections after the | |
781 | * __end_of_kernel_reserve symbol must be explicitly reserved with a | |
782 | * separate memblock_reserve() or they will be discarded. | |
783 | */ | |
784 | memblock_reserve(__pa_symbol(_text), | |
785 | (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); | |
786 | ||
787 | /* | |
4c674481 MR |
788 | * The first 4Kb of memory is a BIOS owned area, but generally it is |
789 | * not listed as such in the E820 table. | |
790 | * | |
f1d4d47c MR |
791 | * Reserve the first 64K of memory since some BIOSes are known to |
792 | * corrupt low memory. After the real mode trampoline is allocated the | |
793 | * rest of the memory below 640k is reserved. | |
4c674481 MR |
794 | * |
795 | * In addition, make sure page 0 is always reserved because on | |
796 | * systems with L1TF its contents can be leaked to user processes. | |
a799c2bd | 797 | */ |
f1d4d47c | 798 | memblock_reserve(0, SZ_64K); |
a799c2bd MR |
799 | |
800 | early_reserve_initrd(); | |
801 | ||
a799c2bd MR |
802 | memblock_x86_reserve_range_setup_data(); |
803 | ||
804 | reserve_ibft_region(); | |
805 | reserve_bios_regions(); | |
f1d4d47c | 806 | trim_snb_memory(); |
95c96084 | 807 | } |
a799c2bd | 808 | |
f32360ef KC |
809 | /* |
810 | * Dump out kernel offset information on panic. | |
811 | */ | |
812 | static int | |
813 | dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) | |
814 | { | |
78cac48c BP |
815 | if (kaslr_enabled()) { |
816 | pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", | |
4545c898 | 817 | kaslr_offset(), |
78cac48c BP |
818 | __START_KERNEL, |
819 | __START_KERNEL_map, | |
820 | MODULES_VADDR-1); | |
821 | } else { | |
822 | pr_emerg("Kernel Offset: disabled\n"); | |
823 | } | |
f32360ef KC |
824 | |
825 | return 0; | |
826 | } | |
827 | ||
76ea0025 BP |
828 | void x86_configure_nx(void) |
829 | { | |
830 | if (boot_cpu_has(X86_FEATURE_NX)) | |
831 | __supported_pte_mask |= _PAGE_NX; | |
832 | else | |
833 | __supported_pte_mask &= ~_PAGE_NX; | |
834 | } | |
835 | ||
836 | static void __init x86_report_nx(void) | |
837 | { | |
838 | if (!boot_cpu_has(X86_FEATURE_NX)) { | |
839 | printk(KERN_NOTICE "Notice: NX (Execute Disable) protection " | |
840 | "missing in CPU!\n"); | |
841 | } else { | |
842 | #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE) | |
843 | printk(KERN_INFO "NX (Execute Disable) protection: active\n"); | |
844 | #else | |
845 | /* 32bit non-PAE kernel, NX cannot be used */ | |
846 | printk(KERN_NOTICE "Notice: NX (Execute Disable) protection " | |
847 | "cannot be enabled: non-PAE kernel!\n"); | |
848 | #endif | |
849 | } | |
850 | } | |
851 | ||
1da177e4 LT |
852 | /* |
853 | * Determine if we were loaded by an EFI loader. If so, then we have also been | |
854 | * passed the efi memmap, systab, etc., so we should use these data structures | |
855 | * for initialization. Note, the efi init code path is determined by the | |
856 | * global efi_enabled. This allows the same kernel image to be used on existing | |
857 | * systems (with a traditional BIOS) as well as on EFI systems. | |
858 | */ | |
76934ed4 YL |
859 | /* |
860 | * setup_arch - architecture-specific boot-time initializations | |
861 | * | |
862 | * Note: On x86_64, fixmaps are ready for use even before this is called. | |
863 | */ | |
864 | ||
1da177e4 LT |
865 | void __init setup_arch(char **cmdline_p) |
866 | { | |
76934ed4 | 867 | #ifdef CONFIG_X86_32 |
1da177e4 | 868 | memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); |
b40827fa BP |
869 | |
870 | /* | |
871 | * copy kernel address range established so far and switch | |
872 | * to the proper swapper page table | |
873 | */ | |
874 | clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, | |
875 | initial_page_table + KERNEL_PGD_BOUNDARY, | |
876 | KERNEL_PGD_PTRS); | |
877 | ||
878 | load_cr3(swapper_pg_dir); | |
2075244f BD |
879 | /* |
880 | * Note: Quark X1000 CPUs advertise PGE incorrectly and require | |
881 | * a cr3 based tlb flush, so the following __flush_tlb_all() | |
360db4ac | 882 | * will not flush anything because the CPU quirk which clears |
2075244f BD |
883 | * X86_FEATURE_PGE has not been invoked yet. Though due to the |
884 | * load_cr3() above the TLB has been flushed already. The | |
885 | * quirk is invoked before subsequent calls to __flush_tlb_all() | |
886 | * so proper operation is guaranteed. | |
887 | */ | |
b40827fa | 888 | __flush_tlb_all(); |
76934ed4 YL |
889 | #else |
890 | printk(KERN_INFO "Command line: %s\n", boot_command_line); | |
162434e7 | 891 | boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; |
76934ed4 | 892 | #endif |
1da177e4 | 893 | |
9863c90f AK |
894 | /* |
895 | * If we have OLPC OFW, we might end up relocating the fixmap due to | |
896 | * reserve_top(), so do this before touching the ioremap area. | |
897 | */ | |
fd699c76 AS |
898 | olpc_ofw_detect(); |
899 | ||
433f8924 | 900 | idt_setup_early_traps(); |
9e882c92 | 901 | early_cpu_init(); |
8990cac6 | 902 | jump_label_init(); |
a945c834 | 903 | static_call_init(); |
1a98fd14 JF |
904 | early_ioremap_init(); |
905 | ||
fd699c76 AS |
906 | setup_olpc_ofw_pgd(); |
907 | ||
30c82645 PA |
908 | ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); |
909 | screen_info = boot_params.screen_info; | |
910 | edid_info = boot_params.edid_info; | |
76934ed4 | 911 | #ifdef CONFIG_X86_32 |
30c82645 PA |
912 | apm_info.bios = boot_params.apm_bios_info; |
913 | ist_info = boot_params.ist_info; | |
76934ed4 YL |
914 | #endif |
915 | saved_video_mode = boot_params.hdr.vid_mode; | |
30c82645 | 916 | bootloader_type = boot_params.hdr.type_of_loader; |
5031296c PA |
917 | if ((bootloader_type >> 4) == 0xe) { |
918 | bootloader_type &= 0xf; | |
919 | bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; | |
920 | } | |
921 | bootloader_version = bootloader_type & 0xf; | |
922 | bootloader_version |= boot_params.hdr.ext_loader_ver << 4; | |
1da177e4 LT |
923 | |
924 | #ifdef CONFIG_BLK_DEV_RAM | |
30c82645 | 925 | rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; |
1da177e4 | 926 | #endif |
7465252e YL |
927 | #ifdef CONFIG_EFI |
928 | if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, | |
9402973d | 929 | EFI32_LOADER_SIGNATURE, 4)) { |
3e909599 | 930 | set_bit(EFI_BOOT, &efi.flags); |
1adbfa35 | 931 | } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, |
9402973d | 932 | EFI64_LOADER_SIGNATURE, 4)) { |
3e909599 MF |
933 | set_bit(EFI_BOOT, &efi.flags); |
934 | set_bit(EFI_64BIT, &efi.flags); | |
7465252e YL |
935 | } |
936 | #endif | |
937 | ||
42bbdb43 | 938 | x86_init.oem.arch_setup(); |
2215e69d | 939 | |
8aa83e63 JG |
940 | /* |
941 | * Do some memory reservations *before* memory is added to memblock, so | |
942 | * memblock allocations won't overwrite it. | |
943 | * | |
944 | * After this point, everything still needed from the boot loader or | |
945 | * firmware or kernel text should be early reserved or marked not RAM in | |
946 | * e820. All other memory is free game. | |
947 | * | |
948 | * This call needs to happen before e820__memory_setup() which calls the | |
949 | * xen_memory_setup() on Xen dom0 which relies on the fact that those | |
950 | * early reservations have happened already. | |
951 | */ | |
952 | early_reserve_memory(); | |
953 | ||
419afdf5 | 954 | iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; |
103e2063 | 955 | e820__memory_setup(); |
28bb2237 YL |
956 | parse_setup_data(); |
957 | ||
1da177e4 LT |
958 | copy_edd(); |
959 | ||
30c82645 | 960 | if (!boot_params.hdr.root_flags) |
1da177e4 | 961 | root_mountflags &= ~MS_RDONLY; |
30120d72 | 962 | setup_initial_init_mm(_text, _etext, _edata, (void *)_brk_end); |
fe3d197f | 963 | |
4046d6e8 LT |
964 | code_resource.start = __pa_symbol(_text); |
965 | code_resource.end = __pa_symbol(_etext)-1; | |
a3299754 KC |
966 | rodata_resource.start = __pa_symbol(__start_rodata); |
967 | rodata_resource.end = __pa_symbol(__end_rodata)-1; | |
968 | data_resource.start = __pa_symbol(_sdata); | |
4046d6e8 LT |
969 | data_resource.end = __pa_symbol(_edata)-1; |
970 | bss_resource.start = __pa_symbol(__bss_start); | |
971 | bss_resource.end = __pa_symbol(__bss_stop)-1; | |
972 | ||
fbe61839 BP |
973 | #ifdef CONFIG_CMDLINE_BOOL |
974 | #ifdef CONFIG_CMDLINE_OVERRIDE | |
8a33d96b | 975 | strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); |
fbe61839 BP |
976 | #else |
977 | if (builtin_cmdline[0]) { | |
978 | /* append boot loader cmdline to builtin */ | |
979 | strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); | |
980 | strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); | |
8a33d96b | 981 | strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); |
fbe61839 BP |
982 | } |
983 | #endif | |
984 | #endif | |
985 | ||
8a33d96b | 986 | strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE); |
fbe61839 BP |
987 | *cmdline_p = command_line; |
988 | ||
989 | /* | |
990 | * x86_configure_nx() is called before parse_early_param() to detect | |
991 | * whether hardware doesn't support NX (so that the early EHCI debug | |
76ea0025 | 992 | * console setup can safely call set_fixmap()). |
fbe61839 BP |
993 | */ |
994 | x86_configure_nx(); | |
995 | ||
996 | parse_early_param(); | |
997 | ||
2f5b3514 MR |
998 | if (efi_enabled(EFI_BOOT)) |
999 | efi_memblock_x86_reserve_range(); | |
1000 | ||
39fa104d RA |
1001 | #ifdef CONFIG_MEMORY_HOTPLUG |
1002 | /* | |
1003 | * Memory used by the kernel cannot be hot-removed because Linux | |
1004 | * cannot migrate the kernel pages. When memory hotplug is | |
1005 | * enabled, we should prevent memblock from allocating memory | |
1006 | * for the kernel. | |
1007 | * | |
1008 | * ACPI SRAT records all hotpluggable memory ranges. But before | |
1009 | * SRAT is parsed, we don't know about it. | |
1010 | * | |
1011 | * The kernel image is loaded into memory at very early time. We | |
1012 | * cannot prevent this anyway. So on NUMA system, we set any | |
1013 | * node the kernel resides in as un-hotpluggable. | |
1014 | * | |
1015 | * Since on modern servers, one node could have double-digit | |
1016 | * gigabytes memory, we can assume the memory around the kernel | |
1017 | * image is also un-hotpluggable. So before SRAT is parsed, just | |
1018 | * allocate memory near the kernel image to try the best to keep | |
1019 | * the kernel away from hotpluggable memory. | |
1020 | */ | |
1021 | if (movable_node_is_enabled()) | |
1022 | memblock_set_bottom_up(true); | |
1023 | #endif | |
1024 | ||
4b0f3b81 | 1025 | x86_report_nx(); |
0ad5bce7 | 1026 | |
76934ed4 | 1027 | if (acpi_mps_check()) { |
3eb11edc | 1028 | #ifdef CONFIG_X86_LOCAL_APIC |
76934ed4 | 1029 | disable_apic = 1; |
3eb11edc | 1030 | #endif |
988781dc | 1031 | setup_clear_cpu_cap(X86_FEATURE_APIC); |
3c999f14 YL |
1032 | } |
1033 | ||
1a127034 | 1034 | e820__reserve_setup_data(); |
9641bdaf | 1035 | e820__finish_early_params(); |
1a3f239d | 1036 | |
83e68189 | 1037 | if (efi_enabled(EFI_BOOT)) |
ff0c0874 BM |
1038 | efi_init(); |
1039 | ||
0fca0812 | 1040 | dmi_setup(); |
2216d199 | 1041 | |
88b094fb AK |
1042 | /* |
1043 | * VMware detection requires dmi to be available, so this | |
0fca0812 | 1044 | * needs to be done after dmi_setup(), for the boot CPU. |
88b094fb | 1045 | */ |
2d826404 | 1046 | init_hypervisor_platform(); |
88b094fb | 1047 | |
cf7a63ef | 1048 | tsc_early_init(); |
f7cf5a5b | 1049 | x86_init.resources.probe_roms(); |
41c094fd | 1050 | |
4046d6e8 LT |
1051 | /* after parse_early_param, so could debug it */ |
1052 | insert_resource(&iomem_resource, &code_resource); | |
a3299754 | 1053 | insert_resource(&iomem_resource, &rodata_resource); |
4046d6e8 LT |
1054 | insert_resource(&iomem_resource, &data_resource); |
1055 | insert_resource(&iomem_resource, &bss_resource); | |
1056 | ||
b422a309 | 1057 | e820_add_kernel_range(); |
1b5576e6 | 1058 | trim_bios_range(); |
76934ed4 | 1059 | #ifdef CONFIG_X86_32 |
cc9f7a0c | 1060 | if (ppro_with_ram_bug()) { |
09821ff1 IM |
1061 | e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, |
1062 | E820_TYPE_RESERVED); | |
f9748fa0 | 1063 | e820__update_table(e820_table); |
cc9f7a0c | 1064 | printk(KERN_INFO "fixed physical RAM map:\n"); |
be0c3f0f | 1065 | e820__print_table("bad_ppro"); |
cc9f7a0c | 1066 | } |
76934ed4 YL |
1067 | #else |
1068 | early_gart_iommu_check(); | |
1069 | #endif | |
cc9f7a0c | 1070 | |
7b2a0a6c YL |
1071 | /* |
1072 | * partially used pages are not usable - thus | |
1073 | * we are rounding upwards: | |
1074 | */ | |
0c6fc11a | 1075 | max_pfn = e820__end_of_ram_pfn(); |
7b2a0a6c | 1076 | |
093af8d7 | 1077 | /* update e820 for memory not covered by WB MTRRs */ |
4d5cff69 | 1078 | if (IS_ENABLED(CONFIG_MTRR)) |
0b9a6a8b | 1079 | cache_bp_init(); |
4d5cff69 CH |
1080 | else |
1081 | pat_disable("PAT support disabled because CONFIG_MTRR is disabled in the kernel."); | |
1082 | ||
2dc807b3 | 1083 | if (mtrr_trim_uncached_memory(max_pfn)) |
0c6fc11a | 1084 | max_pfn = e820__end_of_ram_pfn(); |
76c32418 | 1085 | |
8dd33030 IM |
1086 | max_possible_pfn = max_pfn; |
1087 | ||
99c13b8c MP |
1088 | /* |
1089 | * This call is required when the CPU does not support PAT. If | |
1090 | * mtrr_bp_init() invoked it already via pat_init() the call has no | |
1091 | * effect. | |
1092 | */ | |
1093 | init_cache_modes(); | |
1094 | ||
c7d2361f TG |
1095 | /* |
1096 | * Define random base addresses for memory sections after max_pfn is | |
1097 | * defined and before each memory section base is used. | |
1098 | */ | |
1099 | kernel_randomize_memory(); | |
1100 | ||
76934ed4 | 1101 | #ifdef CONFIG_X86_32 |
4e29684c | 1102 | /* max_low_pfn get updated here */ |
2ec65f8b | 1103 | find_low_pfn_range(); |
76934ed4 | 1104 | #else |
06cd9a7d | 1105 | check_x2apic(); |
76934ed4 YL |
1106 | |
1107 | /* How many end-of-memory variables you have, grandma! */ | |
1108 | /* need this before calling reserve_initrd */ | |
f361a450 | 1109 | if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) |
0c6fc11a | 1110 | max_low_pfn = e820__end_of_low_ram_pfn(); |
f361a450 YL |
1111 | else |
1112 | max_low_pfn = max_pfn; | |
1113 | ||
76934ed4 | 1114 | high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; |
5394f80f JF |
1115 | #endif |
1116 | ||
893f38d1 YL |
1117 | /* |
1118 | * Find and reserve possible boot-time SMP configuration: | |
1119 | */ | |
1120 | find_smp_config(); | |
1121 | ||
8d57470d YL |
1122 | early_alloc_pgt_buf(); |
1123 | ||
72d7c3b3 | 1124 | /* |
4918e228 | 1125 | * Need to conclude brk, before e820__memblock_setup() |
81519f77 C |
1126 | * it could use memblock_find_in_range, could overlap with |
1127 | * brk area. | |
72d7c3b3 YL |
1128 | */ |
1129 | reserve_brk(); | |
1130 | ||
e5f15b45 YL |
1131 | cleanup_highmap(); |
1132 | ||
2449f343 | 1133 | memblock_set_current_limit(ISA_END_ADDRESS); |
4918e228 | 1134 | e820__memblock_setup(); |
72d7c3b3 | 1135 | |
e998879d AK |
1136 | /* |
1137 | * Needs to run after memblock setup because it needs the physical | |
1138 | * memory size. | |
1139 | */ | |
1140 | sev_setup_arch(); | |
1141 | ||
6950e31b DW |
1142 | efi_fake_memmap(); |
1143 | efi_find_mirror(); | |
1144 | efi_esrt_init(); | |
58c90902 | 1145 | efi_mokvar_table_init(); |
007b7560 | 1146 | |
6950e31b DW |
1147 | /* |
1148 | * The EFI specification says that boot service code won't be | |
1149 | * called after ExitBootServices(). This is, in fact, a lie. | |
1150 | */ | |
1151 | efi_reserve_boot_services(); | |
916f676f | 1152 | |
72d7c3b3 | 1153 | /* preallocate 4k for mptable mpc */ |
5da217ca | 1154 | e820__memblock_alloc_reserved_mpc_new(); |
72d7c3b3 YL |
1155 | |
1156 | #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION | |
1157 | setup_bios_corruption_check(); | |
1158 | #endif | |
1159 | ||
10054230 | 1160 | #ifdef CONFIG_X86_32 |
365811d6 BH |
1161 | printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", |
1162 | (max_pfn_mapped<<PAGE_SHIFT) - 1); | |
10054230 | 1163 | #endif |
72d7c3b3 | 1164 | |
c361e5d4 | 1165 | /* |
ec35d1d9 BP |
1166 | * Find free memory for the real mode trampoline and place it there. If |
1167 | * there is not enough free memory under 1M, on EFI-enabled systems | |
1168 | * there will be additional attempt to reclaim the memory for the real | |
1169 | * mode trampoline at efi_free_boot_services(). | |
f1d4d47c | 1170 | * |
ec35d1d9 BP |
1171 | * Unconditionally reserve the entire first 1M of RAM because BIOSes |
1172 | * are known to corrupt low memory and several hundred kilobytes are not | |
1173 | * worth complex detection what memory gets clobbered. Windows does the | |
1174 | * same thing for very similar reasons. | |
1175 | * | |
1176 | * Moreover, on machines with SandyBridge graphics or in setups that use | |
1177 | * crashkernel the entire 1M is reserved anyway. | |
c361e5d4 | 1178 | */ |
f1d4d47c | 1179 | reserve_real_mode(); |
a9acc536 | 1180 | |
22ddfcaa | 1181 | init_mem_mapping(); |
1bbbbe77 | 1182 | |
433f8924 | 1183 | idt_setup_early_pf(); |
1bbbbe77 | 1184 | |
18bc7bd5 AL |
1185 | /* |
1186 | * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) | |
1187 | * with the current CR4 value. This may not be necessary, but | |
1188 | * auditing all the early-boot CR4 manipulation would be needed to | |
1189 | * rule it out. | |
c7ad5ad2 AL |
1190 | * |
1191 | * Mask off features that don't work outside long mode (just | |
1192 | * PCIDE for now). | |
18bc7bd5 | 1193 | */ |
c7ad5ad2 | 1194 | mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; |
18bc7bd5 | 1195 | |
4ce7a869 | 1196 | memblock_set_current_limit(get_max_mapped()); |
4e29684c | 1197 | |
e7b37895 YL |
1198 | /* |
1199 | * NOTE: On x86-32, only from this point on, fixmaps are ready for use. | |
1200 | */ | |
1201 | ||
1202 | #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT | |
1203 | if (init_ohci1394_dma_early) | |
1204 | init_ohci1394_dma_on_all_controllers(); | |
1205 | #endif | |
162a7e75 MT |
1206 | /* Allocate bigger log buffer */ |
1207 | setup_log_buf(1); | |
e7b37895 | 1208 | |
9661b332 DH |
1209 | if (efi_enabled(EFI_BOOT)) { |
1210 | switch (boot_params.secure_boot) { | |
1211 | case efi_secureboot_mode_disabled: | |
1212 | pr_info("Secure boot disabled\n"); | |
1213 | break; | |
1214 | case efi_secureboot_mode_enabled: | |
1215 | pr_info("Secure boot enabled\n"); | |
1216 | break; | |
1217 | default: | |
1218 | pr_info("Secure boot could not be determined\n"); | |
1219 | break; | |
1220 | } | |
1221 | } | |
1222 | ||
2ec65f8b YL |
1223 | reserve_initrd(); |
1224 | ||
da3d3f98 | 1225 | acpi_table_upgrade(); |
6998a880 RW |
1226 | /* Look for ACPI tables and reserve memory occupied by them. */ |
1227 | acpi_boot_table_init(); | |
53aac44c | 1228 | |
76934ed4 | 1229 | vsmp_init(); |
76934ed4 | 1230 | |
1c6e5503 YL |
1231 | io_delay_init(); |
1232 | ||
630b3aff LW |
1233 | early_platform_quirks(); |
1234 | ||
20e6926d YL |
1235 | early_acpi_boot_init(); |
1236 | ||
d8fc3afc | 1237 | initmem_init(); |
3c325f82 | 1238 | dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); |
fa591c4a | 1239 | |
cf11e85f RG |
1240 | if (boot_cpu_has(X86_FEATURE_GBPAGES)) |
1241 | hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); | |
1242 | ||
fa591c4a TC |
1243 | /* |
1244 | * Reserve memory for crash kernel after SRAT is parsed so that it | |
1245 | * won't consume hotpluggable memory. | |
1246 | */ | |
1247 | reserve_crashkernel(); | |
1248 | ||
6f2a7536 | 1249 | memblock_find_dma_reserve(); |
91467bdf | 1250 | |
ccb64941 BO |
1251 | if (!early_xdbc_setup_hardware()) |
1252 | early_xdbc_register_console(); | |
1253 | ||
7737b215 | 1254 | x86_init.paging.pagetable_init(); |
f212ec4b | 1255 | |
ef7f0d6a AR |
1256 | kasan_init(); |
1257 | ||
d2b6dc61 | 1258 | /* |
945fd17a TG |
1259 | * Sync back kernel address range. |
1260 | * | |
1261 | * FIXME: Can the later sync in setup_cpu_entry_areas() replace | |
1262 | * this call? | |
d2b6dc61 | 1263 | */ |
945fd17a | 1264 | sync_initial_page_table(); |
d2b6dc61 | 1265 | |
31625340 JC |
1266 | tboot_probe(); |
1267 | ||
76934ed4 | 1268 | map_vsyscall(); |
76934ed4 | 1269 | |
1a3f239d | 1270 | generic_apic_probe(); |
1da177e4 | 1271 | |
54ef3400 | 1272 | early_quirks(); |
d44647b0 | 1273 | |
295deae4 YL |
1274 | /* |
1275 | * Read APIC and some other early information from ACPI tables. | |
1276 | */ | |
1da177e4 | 1277 | acpi_boot_init(); |
a906fdaa | 1278 | x86_dtb_init(); |
04606618 | 1279 | |
295deae4 YL |
1280 | /* |
1281 | * get boot-time SMP configuration: | |
1282 | */ | |
a91bf718 | 1283 | get_smp_config(); |
76934ed4 | 1284 | |
1e90a13d TG |
1285 | /* |
1286 | * Systems w/o ACPI and mptables might not have it mapped the local | |
1287 | * APIC yet, but prefill_possible_map() might need to access it. | |
1288 | */ | |
1289 | init_apic_mappings(); | |
1290 | ||
329513a3 | 1291 | prefill_possible_map(); |
301e6190 | 1292 | |
5f4765f9 | 1293 | init_cpu_to_node(); |
73bf7382 | 1294 | init_gi_nodes(); |
5f4765f9 | 1295 | |
ca1b8862 | 1296 | io_apic_init_mappings(); |
9d6a4d08 | 1297 | |
f3614646 | 1298 | x86_init.hyper.guest_late_init(); |
1da177e4 | 1299 | |
1506c8dc | 1300 | e820__reserve_resources(); |
cc55f753 | 1301 | e820__register_nosave_regions(max_pfn); |
1da177e4 | 1302 | |
8fee697d | 1303 | x86_init.resources.reserve_resources(); |
41c094fd | 1304 | |
2df908ba | 1305 | e820__setup_pci_gap(); |
41c094fd | 1306 | |
1da177e4 LT |
1307 | #ifdef CONFIG_VT |
1308 | #if defined(CONFIG_VGA_CONSOLE) | |
83e68189 | 1309 | if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) |
1da177e4 | 1310 | conswitchp = &vga_con; |
1da177e4 LT |
1311 | #endif |
1312 | #endif | |
6f30c1ac | 1313 | x86_init.oem.banner(); |
a2202aa2 | 1314 | |
6b617e22 FT |
1315 | x86_init.timers.wallclock_init(); |
1316 | ||
9a90ed06 BP |
1317 | /* |
1318 | * This needs to run before setup_local_APIC() which soft-disables the | |
1319 | * local APIC temporarily and that masks the thermal LVT interrupt, | |
1320 | * leading to softlockups on machines which have configured SMI | |
1321 | * interrupt delivery. | |
1322 | */ | |
1323 | therm_lvt_init(); | |
1324 | ||
a2202aa2 | 1325 | mcheck_init(); |
f49aa448 | 1326 | |
b3c869d3 | 1327 | register_refined_jiffies(CLOCK_TICK_RATE); |
5189c2a7 OJ |
1328 | |
1329 | #ifdef CONFIG_EFI | |
a5d90c92 BP |
1330 | if (efi_enabled(EFI_BOOT)) |
1331 | efi_apply_memmap_quirks(); | |
5189c2a7 | 1332 | #endif |
ee9f8fce JP |
1333 | |
1334 | unwind_init(); | |
1da177e4 | 1335 | } |
5649b7c3 | 1336 | |
9be1b56a IM |
1337 | #ifdef CONFIG_X86_32 |
1338 | ||
8fee697d TG |
1339 | static struct resource video_ram_resource = { |
1340 | .name = "Video RAM area", | |
1341 | .start = 0xa0000, | |
1342 | .end = 0xbffff, | |
1343 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM | |
9be1b56a IM |
1344 | }; |
1345 | ||
8fee697d | 1346 | void __init i386_reserve_resources(void) |
9be1b56a | 1347 | { |
8fee697d TG |
1348 | request_resource(&iomem_resource, &video_ram_resource); |
1349 | reserve_standard_io_resources(); | |
9be1b56a IM |
1350 | } |
1351 | ||
9be1b56a | 1352 | #endif /* CONFIG_X86_32 */ |
f32360ef KC |
1353 | |
1354 | static struct notifier_block kernel_offset_notifier = { | |
1355 | .notifier_call = dump_kernel_offset | |
1356 | }; | |
1357 | ||
1358 | static int __init register_kernel_offset_dumper(void) | |
1359 | { | |
1360 | atomic_notifier_chain_register(&panic_notifier_list, | |
1361 | &kernel_offset_notifier); | |
1362 | return 0; | |
1363 | } | |
1364 | __initcall(register_kernel_offset_dumper); |