1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/sched.h>
25#include <linux/mm.h>
26#include <linux/mmzone.h>
27#include <linux/screen_info.h>
28#include <linux/ioport.h>
29#include <linux/acpi.h>
30#include <linux/sfi.h>
31#include <linux/apm_bios.h>
32#include <linux/initrd.h>
33#include <linux/memblock.h>
34#include <linux/seq_file.h>
35#include <linux/console.h>
36#include <linux/root_dev.h>
37#include <linux/highmem.h>
38#include <linux/export.h>
39#include <linux/efi.h>
40#include <linux/init.h>
41#include <linux/edd.h>
42#include <linux/iscsi_ibft.h>
43#include <linux/nodemask.h>
44#include <linux/kexec.h>
45#include <linux/dmi.h>
46#include <linux/pfn.h>
47#include <linux/pci.h>
48#include <asm/pci-direct.h>
49#include <linux/init_ohci1394_dma.h>
50#include <linux/kvm_para.h>
51#include <linux/dma-contiguous.h>
52#include <xen/xen.h>
53#include <uapi/linux/mount.h>
54
55#include <linux/errno.h>
56#include <linux/kernel.h>
57#include <linux/stddef.h>
58#include <linux/unistd.h>
59#include <linux/ptrace.h>
60#include <linux/user.h>
61#include <linux/delay.h>
62
63#include <linux/kallsyms.h>
64#include <linux/cpufreq.h>
65#include <linux/dma-mapping.h>
66#include <linux/ctype.h>
67#include <linux/uaccess.h>
68#include <linux/security.h>
69
70#include <linux/percpu.h>
71#include <linux/crash_dump.h>
72#include <linux/tboot.h>
73#include <linux/jiffies.h>
74#include <linux/mem_encrypt.h>
75#include <linux/sizes.h>
76
77#include <linux/usb/xhci-dbgp.h>
78#include <video/edid.h>
79
80#include <asm/mtrr.h>
81#include <asm/apic.h>
82#include <asm/realmode.h>
83#include <asm/e820/api.h>
84#include <asm/mpspec.h>
85#include <asm/setup.h>
86#include <asm/efi.h>
87#include <asm/timer.h>
88#include <asm/i8259.h>
89#include <asm/sections.h>
90#include <asm/io_apic.h>
91#include <asm/ist.h>
92#include <asm/setup_arch.h>
93#include <asm/bios_ebda.h>
94#include <asm/cacheflush.h>
95#include <asm/processor.h>
96#include <asm/bugs.h>
97#include <asm/kasan.h>
98
99#include <asm/vsyscall.h>
100#include <asm/cpu.h>
101#include <asm/desc.h>
102#include <asm/dma.h>
103#include <asm/iommu.h>
104#include <asm/gart.h>
105#include <asm/mmu_context.h>
106#include <asm/proto.h>
107
108#include <asm/paravirt.h>
109#include <asm/hypervisor.h>
110#include <asm/olpc_ofw.h>
111
112#include <asm/percpu.h>
113#include <asm/topology.h>
114#include <asm/apicdef.h>
115#include <asm/amd_nb.h>
116#include <asm/mce.h>
117#include <asm/alternative.h>
118#include <asm/prom.h>
119#include <asm/microcode.h>
120#include <asm/kaslr.h>
121#include <asm/unwind.h>
122#include <asm/intel-family.h>
123
124
125
126
127
128
129
130
131unsigned long max_low_pfn_mapped;
132unsigned long max_pfn_mapped;
133
134#ifdef CONFIG_DMI
135RESERVE_BRK(dmi_alloc, 65536);
136#endif
137
138
139static __initdata unsigned long _brk_start = (unsigned long)__brk_base;
140unsigned long _brk_end = (unsigned long)__brk_base;
141
142struct boot_params boot_params;
143
144
145
146
147static struct resource data_resource = {
148 .name = "Kernel data",
149 .start = 0,
150 .end = 0,
151 .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
152};
153
154static struct resource code_resource = {
155 .name = "Kernel code",
156 .start = 0,
157 .end = 0,
158 .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
159};
160
161static struct resource bss_resource = {
162 .name = "Kernel bss",
163 .start = 0,
164 .end = 0,
165 .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
166};
167
168
169#ifdef CONFIG_X86_32
170
171struct cpuinfo_x86 new_cpu_data;
172
173
174struct cpuinfo_x86 boot_cpu_data __read_mostly;
175EXPORT_SYMBOL(boot_cpu_data);
176
177unsigned int def_to_bigsmp;
178
179
180unsigned int machine_id;
181unsigned int machine_submodel_id;
182unsigned int BIOS_revision;
183
184struct apm_info apm_info;
185EXPORT_SYMBOL(apm_info);
186
187#if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
188 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
189struct ist_info ist_info;
190EXPORT_SYMBOL(ist_info);
191#else
192struct ist_info ist_info;
193#endif
194
195#else
196struct cpuinfo_x86 boot_cpu_data __read_mostly;
197EXPORT_SYMBOL(boot_cpu_data);
198#endif
199
200
201#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
202__visible unsigned long mmu_cr4_features __ro_after_init;
203#else
204__visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE;
205#endif
206
207
208int bootloader_type, bootloader_version;
209
210
211
212
213struct screen_info screen_info;
214EXPORT_SYMBOL(screen_info);
215struct edid_info edid_info;
216EXPORT_SYMBOL_GPL(edid_info);
217
218extern int root_mountflags;
219
220unsigned long saved_video_mode;
221
222#define RAMDISK_IMAGE_START_MASK 0x07FF
223#define RAMDISK_PROMPT_FLAG 0x8000
224#define RAMDISK_LOAD_FLAG 0x4000
225
226static char __initdata command_line[COMMAND_LINE_SIZE];
227#ifdef CONFIG_CMDLINE_BOOL
228static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
229#endif
230
231#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
232struct edd edd;
233#ifdef CONFIG_EDD_MODULE
234EXPORT_SYMBOL(edd);
235#endif
236
237
238
239
240
241static inline void __init copy_edd(void)
242{
243 memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
244 sizeof(edd.mbr_signature));
245 memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
246 edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
247 edd.edd_info_nr = boot_params.eddbuf_entries;
248}
249#else
250static inline void __init copy_edd(void)
251{
252}
253#endif
254
255void * __init extend_brk(size_t size, size_t align)
256{
257 size_t mask = align - 1;
258 void *ret;
259
260 BUG_ON(_brk_start == 0);
261 BUG_ON(align & mask);
262
263 _brk_end = (_brk_end + mask) & ~mask;
264 BUG_ON((char *)(_brk_end + size) > __brk_limit);
265
266 ret = (void *)_brk_end;
267 _brk_end += size;
268
269 memset(ret, 0, size);
270
271 return ret;
272}
273
274#ifdef CONFIG_X86_32
275static void __init cleanup_highmap(void)
276{
277}
278#endif
279
280static void __init reserve_brk(void)
281{
282 if (_brk_end > _brk_start)
283 memblock_reserve(__pa_symbol(_brk_start),
284 _brk_end - _brk_start);
285
286
287
288 _brk_start = 0;
289}
290
291u64 relocated_ramdisk;
292
293#ifdef CONFIG_BLK_DEV_INITRD
294
295static u64 __init get_ramdisk_image(void)
296{
297 u64 ramdisk_image = boot_params.hdr.ramdisk_image;
298
299 ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
300
301 return ramdisk_image;
302}
303static u64 __init get_ramdisk_size(void)
304{
305 u64 ramdisk_size = boot_params.hdr.ramdisk_size;
306
307 ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
308
309 return ramdisk_size;
310}
311
312static void __init relocate_initrd(void)
313{
314
315 u64 ramdisk_image = get_ramdisk_image();
316 u64 ramdisk_size = get_ramdisk_size();
317 u64 area_size = PAGE_ALIGN(ramdisk_size);
318
319
320 relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
321 area_size, PAGE_SIZE);
322
323 if (!relocated_ramdisk)
324 panic("Cannot find place for new RAMDISK of size %lld\n",
325 ramdisk_size);
326
327
328
329 memblock_reserve(relocated_ramdisk, area_size);
330 initrd_start = relocated_ramdisk + PAGE_OFFSET;
331 initrd_end = initrd_start + ramdisk_size;
332 printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
333 relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
334
335 copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
336
337 printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
338 " [mem %#010llx-%#010llx]\n",
339 ramdisk_image, ramdisk_image + ramdisk_size - 1,
340 relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
341}
342
343static void __init early_reserve_initrd(void)
344{
345
346 u64 ramdisk_image = get_ramdisk_image();
347 u64 ramdisk_size = get_ramdisk_size();
348 u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
349
350 if (!boot_params.hdr.type_of_loader ||
351 !ramdisk_image || !ramdisk_size)
352 return;
353
354 memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
355}
356static void __init reserve_initrd(void)
357{
358
359 u64 ramdisk_image = get_ramdisk_image();
360 u64 ramdisk_size = get_ramdisk_size();
361 u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
362 u64 mapped_size;
363
364 if (!boot_params.hdr.type_of_loader ||
365 !ramdisk_image || !ramdisk_size)
366 return;
367
368 initrd_start = 0;
369
370 mapped_size = memblock_mem_size(max_pfn_mapped);
371 if (ramdisk_size >= (mapped_size>>1))
372 panic("initrd too large to handle, "
373 "disabling initrd (%lld needed, %lld available)\n",
374 ramdisk_size, mapped_size>>1);
375
376 printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image,
377 ramdisk_end - 1);
378
379 if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image),
380 PFN_DOWN(ramdisk_end))) {
381
382 initrd_start = ramdisk_image + PAGE_OFFSET;
383 initrd_end = initrd_start + ramdisk_size;
384 return;
385 }
386
387 relocate_initrd();
388
389 memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
390}
391
392#else
393static void __init early_reserve_initrd(void)
394{
395}
396static void __init reserve_initrd(void)
397{
398}
399#endif
400
401static void __init parse_setup_data(void)
402{
403 struct setup_data *data;
404 u64 pa_data, pa_next;
405
406 pa_data = boot_params.hdr.setup_data;
407 while (pa_data) {
408 u32 data_len, data_type;
409
410 data = early_memremap(pa_data, sizeof(*data));
411 data_len = data->len + sizeof(struct setup_data);
412 data_type = data->type;
413 pa_next = data->next;
414 early_memunmap(data, sizeof(*data));
415
416 switch (data_type) {
417 case SETUP_E820_EXT:
418 e820__memory_setup_extended(pa_data, data_len);
419 break;
420 case SETUP_DTB:
421 add_dtb(pa_data);
422 break;
423 case SETUP_EFI:
424 parse_efi_setup(pa_data, data_len);
425 break;
426 default:
427 break;
428 }
429 pa_data = pa_next;
430 }
431}
432
433static void __init memblock_x86_reserve_range_setup_data(void)
434{
435 struct setup_data *data;
436 u64 pa_data;
437
438 pa_data = boot_params.hdr.setup_data;
439 while (pa_data) {
440 data = early_memremap(pa_data, sizeof(*data));
441 memblock_reserve(pa_data, sizeof(*data) + data->len);
442 pa_data = data->next;
443 early_memunmap(data, sizeof(*data));
444 }
445}
446
447
448
449
450
451#ifdef CONFIG_KEXEC_CORE
452
453
454#define CRASH_ALIGN SZ_16M
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469#ifdef CONFIG_X86_32
470# define CRASH_ADDR_LOW_MAX SZ_512M
471# define CRASH_ADDR_HIGH_MAX SZ_512M
472#else
473# define CRASH_ADDR_LOW_MAX SZ_4G
474# define CRASH_ADDR_HIGH_MAX SZ_64T
475#endif
476
477static int __init reserve_crashkernel_low(void)
478{
479#ifdef CONFIG_X86_64
480 unsigned long long base, low_base = 0, low_size = 0;
481 unsigned long total_low_mem;
482 int ret;
483
484 total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT));
485
486
487 ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base);
488 if (ret) {
489
490
491
492
493
494
495
496
497
498 low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20);
499 } else {
500
501 if (!low_size)
502 return 0;
503 }
504
505 low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN);
506 if (!low_base) {
507 pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n",
508 (unsigned long)(low_size >> 20));
509 return -ENOMEM;
510 }
511
512 ret = memblock_reserve(low_base, low_size);
513 if (ret) {
514 pr_err("%s: Error reserving crashkernel low memblock.\n", __func__);
515 return ret;
516 }
517
518 pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n",
519 (unsigned long)(low_size >> 20),
520 (unsigned long)(low_base >> 20),
521 (unsigned long)(total_low_mem >> 20));
522
523 crashk_low_res.start = low_base;
524 crashk_low_res.end = low_base + low_size - 1;
525 insert_resource(&iomem_resource, &crashk_low_res);
526#endif
527 return 0;
528}
529
530static void __init reserve_crashkernel(void)
531{
532 unsigned long long crash_size, crash_base, total_mem, mem_enc_req;
533 bool high = false;
534 int ret;
535
536 total_mem = memblock_phys_mem_size();
537
538
539 ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base);
540 if (ret != 0 || crash_size <= 0) {
541
542 ret = parse_crashkernel_high(boot_command_line, total_mem,
543 &crash_size, &crash_base);
544 if (ret != 0 || crash_size <= 0)
545 return;
546 high = true;
547 }
548
549 if (xen_pv_domain()) {
550 pr_info("Ignoring crashkernel for a Xen PV domain\n");
551 return;
552 }
553
554
555
556
557
558 if (mem_encrypt_active())
559 mem_enc_req = min(ALIGN(swiotlb_size_or_default(), SZ_1M), 64UL << 20);
560 else
561 mem_enc_req = 0;
562
563
564 if (!crash_base) {
565
566
567
568
569
570
571
572
573 if (!high)
574 crash_base = memblock_find_in_range(CRASH_ALIGN,
575 CRASH_ADDR_LOW_MAX,
576 crash_size + mem_enc_req,
577 CRASH_ALIGN);
578
579
580
581
582
583 if (!crash_base) {
584 mem_enc_req = 0;
585 crash_base = memblock_find_in_range(CRASH_ALIGN,
586 CRASH_ADDR_HIGH_MAX,
587 crash_size, CRASH_ALIGN);
588 }
589 if (!crash_base) {
590 pr_info("crashkernel reservation failed - No suitable area found.\n");
591 return;
592 }
593 } else {
594 unsigned long long start;
595
596 mem_enc_req = 0;
597 start = memblock_find_in_range(crash_base,
598 crash_base + crash_size,
599 crash_size, 1 << 20);
600 if (start != crash_base) {
601 pr_info("crashkernel reservation failed - memory is in use.\n");
602 return;
603 }
604 }
605
606 if (mem_enc_req) {
607 pr_info("Memory encryption is active, crashkernel needs %ldMB extra memory\n",
608 (unsigned long)(mem_enc_req >> 20));
609 crash_size += mem_enc_req;
610 }
611
612 ret = memblock_reserve(crash_base, crash_size);
613 if (ret) {
614 pr_err("%s: Error reserving crashkernel memblock.\n", __func__);
615 return;
616 }
617
618 if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) {
619 memblock_free(crash_base, crash_size);
620 return;
621 }
622
623 pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n",
624 (unsigned long)(crash_size >> 20),
625 (unsigned long)(crash_base >> 20),
626 (unsigned long)(total_mem >> 20));
627
628 crashk_res.start = crash_base;
629 crashk_res.end = crash_base + crash_size - 1;
630 insert_resource(&iomem_resource, &crashk_res);
631}
632#else
633static void __init reserve_crashkernel(void)
634{
635}
636#endif
637
638static struct resource standard_io_resources[] = {
639 { .name = "dma1", .start = 0x00, .end = 0x1f,
640 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
641 { .name = "pic1", .start = 0x20, .end = 0x21,
642 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
643 { .name = "timer0", .start = 0x40, .end = 0x43,
644 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
645 { .name = "timer1", .start = 0x50, .end = 0x53,
646 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
647 { .name = "keyboard", .start = 0x60, .end = 0x60,
648 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
649 { .name = "keyboard", .start = 0x64, .end = 0x64,
650 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
651 { .name = "dma page reg", .start = 0x80, .end = 0x8f,
652 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
653 { .name = "pic2", .start = 0xa0, .end = 0xa1,
654 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
655 { .name = "dma2", .start = 0xc0, .end = 0xdf,
656 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
657 { .name = "fpu", .start = 0xf0, .end = 0xff,
658 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
659};
660
661void __init reserve_standard_io_resources(void)
662{
663 int i;
664
665
666 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
667 request_resource(&ioport_resource, &standard_io_resources[i]);
668
669}
670
671static __init void reserve_ibft_region(void)
672{
673 unsigned long addr, size = 0;
674
675 addr = find_ibft_region(&size);
676
677 if (size)
678 memblock_reserve(addr, size);
679}
680
681static bool __init snb_gfx_workaround_needed(void)
682{
683#ifdef CONFIG_PCI
684 int i;
685 u16 vendor, devid;
686 static const __initconst u16 snb_ids[] = {
687 0x0102,
688 0x0112,
689 0x0122,
690 0x0106,
691 0x0116,
692 0x0126,
693 0x010a,
694 };
695
696
697 if (!early_pci_allowed())
698 return false;
699
700 vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID);
701 if (vendor != 0x8086)
702 return false;
703
704 devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID);
705 for (i = 0; i < ARRAY_SIZE(snb_ids); i++)
706 if (devid == snb_ids[i])
707 return true;
708#endif
709
710 return false;
711}
712
713
714
715
716
717static void __init trim_snb_memory(void)
718{
719 static const __initconst unsigned long bad_pages[] = {
720 0x20050000,
721 0x20110000,
722 0x20130000,
723 0x20138000,
724 0x40004000,
725 };
726 int i;
727
728 if (!snb_gfx_workaround_needed())
729 return;
730
731 printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n");
732
733 for (i = 0; i < ARRAY_SIZE(bad_pages); i++) {
734 if (memblock_reserve(bad_pages[i], PAGE_SIZE))
735 printk(KERN_WARNING "failed to reserve 0x%08lx\n",
736 bad_pages[i]);
737 }
738}
739
740
741
742
743
744
745
746
747static void __init trim_platform_memory_ranges(void)
748{
749 trim_snb_memory();
750}
751
752static void __init trim_bios_range(void)
753{
754
755
756
757
758
759
760
761
762
763 e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED);
764
765
766
767
768
769
770 e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1);
771
772 e820__update_table(e820_table);
773}
774
775
776static void __init e820_add_kernel_range(void)
777{
778 u64 start = __pa_symbol(_text);
779 u64 size = __pa_symbol(_end) - start;
780
781
782
783
784
785
786
787
788 if (e820__mapped_all(start, start + size, E820_TYPE_RAM))
789 return;
790
791 pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n");
792 e820__range_remove(start, size, E820_TYPE_RAM, 0);
793 e820__range_add(start, size, E820_TYPE_RAM);
794}
795
796static void __init trim_low_memory_range(void)
797{
798 memblock_reserve(0, SZ_64K);
799}
800
801static void rh_check_supported(void)
802{
803 bool guest;
804
805 guest = (x86_hyper_type != X86_HYPER_NATIVE || boot_cpu_has(X86_FEATURE_HYPERVISOR));
806
807
808 if (((boot_cpu_data.x86_max_cores * smp_num_siblings) == 1) &&
809 !guest && is_kdump_kernel()) {
810 pr_crit("Detected single cpu native boot.\n");
811 pr_crit("Important: In Red Hat Enterprise Linux 8, single threaded, single CPU 64-bit physical systems are unsupported by Red Hat. Please contact your Red Hat support representative for a list of certified and supported systems.");
812 }
813
814
815
816
817
818 switch (boot_cpu_data.x86_vendor) {
819 case X86_VENDOR_AMD:
820 case X86_VENDOR_INTEL:
821 break;
822 default:
823 pr_crit("Detected processor %s %s\n",
824 boot_cpu_data.x86_vendor_id,
825 boot_cpu_data.x86_model_id);
826 mark_hardware_unsupported("Processor");
827 break;
828 }
829
830
831
832
833
834
835
836 if (acpi_disabled && !guest)
837 pr_crit("ACPI has been disabled or is not available on this hardware. This may result in a single cpu boot, incorrect PCI IRQ routing, or boot failure.\n");
838}
839
840
841
842
843static int
844dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
845{
846 if (kaslr_enabled()) {
847 pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n",
848 kaslr_offset(),
849 __START_KERNEL,
850 __START_KERNEL_map,
851 MODULES_VADDR-1);
852 } else {
853 pr_emerg("Kernel Offset: disabled\n");
854 }
855
856 return 0;
857}
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872void __init setup_arch(char **cmdline_p)
873{
874
875
876
877
878
879
880 memblock_reserve(__pa_symbol(_text),
881 (unsigned long)__end_of_kernel_reserve - (unsigned long)_text);
882
883
884
885
886
887 memblock_reserve(0, PAGE_SIZE);
888
889 early_reserve_initrd();
890
891
892
893
894
895
896
897#ifdef CONFIG_X86_32
898 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
899
900
901
902
903
904 clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY,
905 initial_page_table + KERNEL_PGD_BOUNDARY,
906 KERNEL_PGD_PTRS);
907
908 load_cr3(swapper_pg_dir);
909
910
911
912
913
914
915
916
917
918 __flush_tlb_all();
919#else
920 printk(KERN_INFO "Command line: %s\n", boot_command_line);
921 boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS;
922#endif
923
924
925
926
927
928 olpc_ofw_detect();
929
930 idt_setup_early_traps();
931 early_cpu_init();
932 arch_init_ideal_nops();
933 jump_label_init();
934 early_ioremap_init();
935
936 setup_olpc_ofw_pgd();
937
938 ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
939 screen_info = boot_params.screen_info;
940 edid_info = boot_params.edid_info;
941#ifdef CONFIG_X86_32
942 apm_info.bios = boot_params.apm_bios_info;
943 ist_info = boot_params.ist_info;
944#endif
945 saved_video_mode = boot_params.hdr.vid_mode;
946 bootloader_type = boot_params.hdr.type_of_loader;
947 if ((bootloader_type >> 4) == 0xe) {
948 bootloader_type &= 0xf;
949 bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4;
950 }
951 bootloader_version = bootloader_type & 0xf;
952 bootloader_version |= boot_params.hdr.ext_loader_ver << 4;
953
954#ifdef CONFIG_BLK_DEV_RAM
955 rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
956 rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
957 rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
958#endif
959#ifdef CONFIG_EFI
960 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
961 EFI32_LOADER_SIGNATURE, 4)) {
962 set_bit(EFI_BOOT, &efi.flags);
963 } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
964 EFI64_LOADER_SIGNATURE, 4)) {
965 set_bit(EFI_BOOT, &efi.flags);
966 set_bit(EFI_64BIT, &efi.flags);
967 }
968#endif
969
970 x86_init.oem.arch_setup();
971
972 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
973 e820__memory_setup();
974 parse_setup_data();
975
976 copy_edd();
977
978 if (!boot_params.hdr.root_flags)
979 root_mountflags &= ~MS_RDONLY;
980 init_mm.start_code = (unsigned long) _text;
981 init_mm.end_code = (unsigned long) _etext;
982 init_mm.end_data = (unsigned long) _edata;
983 init_mm.brk = _brk_end;
984
985 mpx_mm_init(&init_mm);
986
987 code_resource.start = __pa_symbol(_text);
988 code_resource.end = __pa_symbol(_etext)-1;
989 data_resource.start = __pa_symbol(_etext);
990 data_resource.end = __pa_symbol(_edata)-1;
991 bss_resource.start = __pa_symbol(__bss_start);
992 bss_resource.end = __pa_symbol(__bss_stop)-1;
993
994#ifdef CONFIG_CMDLINE_BOOL
995#ifdef CONFIG_CMDLINE_OVERRIDE
996 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
997#else
998 if (builtin_cmdline[0]) {
999
1000 strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
1001 strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
1002 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
1003 }
1004#endif
1005#endif
1006
1007 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
1008 *cmdline_p = command_line;
1009
1010
1011
1012
1013
1014
1015
1016
1017 x86_configure_nx();
1018
1019 parse_early_param();
1020
1021 if (efi_enabled(EFI_BOOT))
1022 efi_memblock_x86_reserve_range();
1023#ifdef CONFIG_MEMORY_HOTPLUG
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043 if (movable_node_is_enabled())
1044 memblock_set_bottom_up(true);
1045#endif
1046
1047 x86_report_nx();
1048
1049
1050 memblock_x86_reserve_range_setup_data();
1051
1052 if (acpi_mps_check()) {
1053#ifdef CONFIG_X86_LOCAL_APIC
1054 disable_apic = 1;
1055#endif
1056 setup_clear_cpu_cap(X86_FEATURE_APIC);
1057 }
1058
1059 e820__reserve_setup_data();
1060 e820__finish_early_params();
1061
1062 if (efi_enabled(EFI_BOOT))
1063 efi_init();
1064
1065 efi_set_secure_boot(boot_params.secure_boot);
1066
1067 init_lockdown();
1068
1069 dmi_scan_machine();
1070 dmi_memdev_walk();
1071 dmi_set_dump_stack_arch_desc();
1072
1073
1074
1075
1076
1077 init_hypervisor_platform();
1078
1079 tsc_early_init();
1080 x86_init.resources.probe_roms();
1081
1082
1083 insert_resource(&iomem_resource, &code_resource);
1084 insert_resource(&iomem_resource, &data_resource);
1085 insert_resource(&iomem_resource, &bss_resource);
1086
1087 e820_add_kernel_range();
1088 trim_bios_range();
1089#ifdef CONFIG_X86_32
1090 if (ppro_with_ram_bug()) {
1091 e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM,
1092 E820_TYPE_RESERVED);
1093 e820__update_table(e820_table);
1094 printk(KERN_INFO "fixed physical RAM map:\n");
1095 e820__print_table("bad_ppro");
1096 }
1097#else
1098 early_gart_iommu_check();
1099#endif
1100
1101
1102
1103
1104
1105 max_pfn = e820__end_of_ram_pfn();
1106
1107
1108 mtrr_bp_init();
1109 if (mtrr_trim_uncached_memory(max_pfn))
1110 max_pfn = e820__end_of_ram_pfn();
1111
1112 max_possible_pfn = max_pfn;
1113
1114
1115
1116
1117
1118
1119 init_cache_modes();
1120
1121
1122
1123
1124
1125 kernel_randomize_memory();
1126
1127#ifdef CONFIG_X86_32
1128
1129 find_low_pfn_range();
1130#else
1131 check_x2apic();
1132
1133
1134
1135 if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
1136 max_low_pfn = e820__end_of_low_ram_pfn();
1137 else
1138 max_low_pfn = max_pfn;
1139
1140 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
1141#endif
1142
1143
1144
1145
1146 find_smp_config();
1147
1148 reserve_ibft_region();
1149
1150 early_alloc_pgt_buf();
1151
1152
1153
1154
1155
1156
1157 reserve_brk();
1158
1159 cleanup_highmap();
1160
1161 memblock_set_current_limit(ISA_END_ADDRESS);
1162 e820__memblock_setup();
1163
1164
1165
1166
1167
1168 sev_setup_arch();
1169
1170 reserve_bios_regions();
1171
1172 efi_fake_memmap();
1173 efi_find_mirror();
1174 efi_esrt_init();
1175 efi_mokvar_table_init();
1176
1177
1178
1179
1180
1181 efi_reserve_boot_services();
1182
1183
1184 e820__memblock_alloc_reserved_mpc_new();
1185
1186#ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
1187 setup_bios_corruption_check();
1188#endif
1189
1190#ifdef CONFIG_X86_32
1191 printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n",
1192 (max_pfn_mapped<<PAGE_SHIFT) - 1);
1193#endif
1194
1195 trim_platform_memory_ranges();
1196 trim_low_memory_range();
1197
1198 reserve_real_mode();
1199
1200 init_mem_mapping();
1201
1202 idt_setup_early_pf();
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213 mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE;
1214
1215 memblock_set_current_limit(get_max_mapped());
1216
1217
1218
1219
1220
1221#ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
1222 if (init_ohci1394_dma_early)
1223 init_ohci1394_dma_on_all_controllers();
1224#endif
1225
1226 setup_log_buf(1);
1227
1228 reserve_initrd();
1229
1230 acpi_table_upgrade();
1231
1232 acpi_boot_table_init();
1233
1234 vsmp_init();
1235
1236 io_delay_init();
1237
1238 early_platform_quirks();
1239
1240 early_acpi_boot_init();
1241
1242 initmem_init();
1243 dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT);
1244
1245
1246
1247
1248
1249 reserve_crashkernel();
1250
1251 memblock_find_dma_reserve();
1252
1253 if (!early_xdbc_setup_hardware())
1254 early_xdbc_register_console();
1255
1256 x86_init.paging.pagetable_init();
1257
1258 kasan_init();
1259
1260
1261
1262
1263
1264
1265
1266 sync_initial_page_table();
1267
1268 tboot_probe();
1269
1270 map_vsyscall();
1271
1272 generic_apic_probe();
1273
1274 early_quirks();
1275
1276
1277
1278
1279 acpi_boot_init();
1280 sfi_init();
1281 x86_dtb_init();
1282
1283
1284
1285
1286 get_smp_config();
1287
1288
1289
1290
1291
1292 init_apic_mappings();
1293
1294 prefill_possible_map();
1295
1296 init_cpu_to_node();
1297
1298 io_apic_init_mappings();
1299
1300 x86_init.hyper.guest_late_init();
1301
1302 e820__reserve_resources();
1303 e820__register_nosave_regions(max_low_pfn);
1304
1305 x86_init.resources.reserve_resources();
1306
1307 e820__setup_pci_gap();
1308
1309#ifdef CONFIG_VT
1310#if defined(CONFIG_VGA_CONSOLE)
1311 if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
1312 conswitchp = &vga_con;
1313#elif defined(CONFIG_DUMMY_CONSOLE)
1314 conswitchp = &dummy_con;
1315#endif
1316#endif
1317 x86_init.oem.banner();
1318
1319 x86_init.timers.wallclock_init();
1320
1321 mcheck_init();
1322
1323 register_refined_jiffies(CLOCK_TICK_RATE);
1324
1325#ifdef CONFIG_EFI
1326 if (efi_enabled(EFI_BOOT))
1327 efi_apply_memmap_quirks();
1328#endif
1329
1330 rh_check_supported();
1331
1332 unwind_init();
1333}
1334
1335#ifdef CONFIG_X86_32
1336
1337static struct resource video_ram_resource = {
1338 .name = "Video RAM area",
1339 .start = 0xa0000,
1340 .end = 0xbffff,
1341 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
1342};
1343
1344void __init i386_reserve_resources(void)
1345{
1346 request_resource(&iomem_resource, &video_ram_resource);
1347 reserve_standard_io_resources();
1348}
1349
1350#endif
1351
1352static struct notifier_block kernel_offset_notifier = {
1353 .notifier_call = dump_kernel_offset
1354};
1355
1356static int __init register_kernel_offset_dumper(void)
1357{
1358 atomic_notifier_chain_register(&panic_notifier_list,
1359 &kernel_offset_notifier);
1360 return 0;
1361}
1362__initcall(register_kernel_offset_dumper);
1363