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