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