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