1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 255f26239SYinghai Lu /* 355f26239SYinghai Lu * Copyright (C) 1995 Linus Torvalds 455f26239SYinghai Lu * 512609013SIngo Molnar * This file contains the setup_arch() code, which handles the architecture-dependent 612609013SIngo Molnar * parts of early kernel initialization. 755f26239SYinghai Lu */ 855f26239SYinghai Lu #include <linux/console.h> 912609013SIngo Molnar #include <linux/crash_dump.h> 100b1abd1fSChristoph Hellwig #include <linux/dma-map-ops.h> 1155f26239SYinghai Lu #include <linux/dmi.h> 1212609013SIngo Molnar #include <linux/efi.h> 1355f26239SYinghai Lu #include <linux/init_ohci1394_dma.h> 1412609013SIngo Molnar #include <linux/initrd.h> 1512609013SIngo Molnar #include <linux/iscsi_ibft.h> 1612609013SIngo Molnar #include <linux/memblock.h> 1712609013SIngo Molnar #include <linux/pci.h> 1812609013SIngo Molnar #include <linux/root_dev.h> 19cf11e85fSRoman Gushchin #include <linux/hugetlb.h> 2012609013SIngo Molnar #include <linux/tboot.h> 2112609013SIngo Molnar #include <linux/usb/xhci-dbgp.h> 22a945c834SPeter Zijlstra #include <linux/static_call.h> 230a0f0d8bSChristoph Hellwig #include <linux/swiotlb.h> 2412609013SIngo Molnar 25e262e32dSDavid Howells #include <uapi/linux/mount.h> 2655f26239SYinghai Lu 2712609013SIngo Molnar #include <xen/xen.h> 2855f26239SYinghai Lu 2955f26239SYinghai Lu #include <asm/apic.h> 3013c01139SIngo Molnar #include <asm/numa.h> 3155f26239SYinghai Lu #include <asm/bios_ebda.h> 3255f26239SYinghai Lu #include <asm/bugs.h> 336e5385d4SJaswinder Singh Rajput #include <asm/cpu.h> 3412609013SIngo Molnar #include <asm/efi.h> 351d9b16d1SJoerg Roedel #include <asm/gart.h> 3688b094fbSAlok Kataria #include <asm/hypervisor.h> 3712609013SIngo Molnar #include <asm/io_apic.h> 3812609013SIngo Molnar #include <asm/kasan.h> 390483e1faSThomas Garnier #include <asm/kaslr.h> 4012609013SIngo Molnar #include <asm/mce.h> 4112609013SIngo Molnar #include <asm/mtrr.h> 42ca947b72SSean Christopherson #include <asm/realmode.h> 4312609013SIngo Molnar #include <asm/olpc_ofw.h> 4412609013SIngo Molnar #include <asm/pci-direct.h> 4512609013SIngo Molnar #include <asm/prom.h> 4612609013SIngo Molnar #include <asm/proto.h> 479a90ed06SBorislav Petkov #include <asm/thermal.h> 48ee9f8fceSJosh Poimboeuf #include <asm/unwind.h> 4912609013SIngo Molnar #include <asm/vsyscall.h> 50186525bdSIngo Molnar #include <linux/vmalloc.h> 5155f26239SYinghai Lu 522b72394eSPekka Enberg /* 53360db4acSIngo Molnar * max_low_pfn_mapped: highest directly mapped pfn < 4 GB 54360db4acSIngo Molnar * max_pfn_mapped: highest directly mapped pfn > 4 GB 5566520ebcSJacob Shin * 5609821ff1SIngo Molnar * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are 57360db4acSIngo Molnar * represented by pfn_mapped[]. 582b72394eSPekka Enberg */ 592b72394eSPekka Enberg unsigned long max_low_pfn_mapped; 602b72394eSPekka Enberg unsigned long max_pfn_mapped; 612b72394eSPekka Enberg 62e808bae2SThadeu Lima de Souza Cascardo #ifdef CONFIG_DMI 63796216a5SJeremy Fitzhardinge RESERVE_BRK(dmi_alloc, 65536); 64e808bae2SThadeu Lima de Souza Cascardo #endif 65796216a5SJeremy Fitzhardinge 66c0b5842aSIngo Molnar 67360db4acSIngo Molnar /* 68360db4acSIngo Molnar * Range of the BSS area. The size of the BSS area is determined 6981519f77SCao jin * at link time, with RESERVE_BRK() facility reserving additional 70360db4acSIngo Molnar * chunks. 71360db4acSIngo Molnar */ 72360db4acSIngo Molnar unsigned long _brk_start = (unsigned long)__brk_base; 7393dbda7cSJeremy Fitzhardinge unsigned long _brk_end = (unsigned long)__brk_base; 7493dbda7cSJeremy Fitzhardinge 75217b8ce8SYinghai Lu struct boot_params boot_params; 76217b8ce8SYinghai Lu 774046d6e8SLinus Torvalds /* 78360db4acSIngo Molnar * These are the four main kernel memory regions, we put them into 79360db4acSIngo Molnar * the resource tree so that kdump tools and other debugging tools 80360db4acSIngo Molnar * recover it: 814046d6e8SLinus Torvalds */ 82360db4acSIngo Molnar 83a3299754SKees Cook static struct resource rodata_resource = { 84a3299754SKees Cook .name = "Kernel rodata", 85a3299754SKees Cook .start = 0, 86a3299754SKees Cook .end = 0, 87a3299754SKees Cook .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 88a3299754SKees Cook }; 89a3299754SKees Cook 904046d6e8SLinus Torvalds static struct resource data_resource = { 914046d6e8SLinus Torvalds .name = "Kernel data", 924046d6e8SLinus Torvalds .start = 0, 934046d6e8SLinus Torvalds .end = 0, 944046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 954046d6e8SLinus Torvalds }; 964046d6e8SLinus Torvalds 974046d6e8SLinus Torvalds static struct resource code_resource = { 984046d6e8SLinus Torvalds .name = "Kernel code", 994046d6e8SLinus Torvalds .start = 0, 1004046d6e8SLinus Torvalds .end = 0, 1014046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1024046d6e8SLinus Torvalds }; 1034046d6e8SLinus Torvalds 1044046d6e8SLinus Torvalds static struct resource bss_resource = { 1054046d6e8SLinus Torvalds .name = "Kernel bss", 1064046d6e8SLinus Torvalds .start = 0, 1074046d6e8SLinus Torvalds .end = 0, 1084046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1094046d6e8SLinus Torvalds }; 1104046d6e8SLinus Torvalds 1114046d6e8SLinus Torvalds 11255f26239SYinghai Lu #ifdef CONFIG_X86_32 113360db4acSIngo Molnar /* CPU data as detected by the assembly code in head_32.S */ 1146415813bSMathias Krause struct cpuinfo_x86 new_cpu_data; 1156415813bSMathias Krause 116360db4acSIngo Molnar /* Common CPU data for all CPUs */ 1176415813bSMathias Krause struct cpuinfo_x86 boot_cpu_data __read_mostly; 11855f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 11955f26239SYinghai Lu 12055f26239SYinghai Lu unsigned int def_to_bigsmp; 12155f26239SYinghai Lu 12255f26239SYinghai Lu struct apm_info apm_info; 12355f26239SYinghai Lu EXPORT_SYMBOL(apm_info); 12455f26239SYinghai Lu 12555f26239SYinghai Lu #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ 12655f26239SYinghai Lu defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) 12755f26239SYinghai Lu struct ist_info ist_info; 12855f26239SYinghai Lu EXPORT_SYMBOL(ist_info); 12955f26239SYinghai Lu #else 13055f26239SYinghai Lu struct ist_info ist_info; 13155f26239SYinghai Lu #endif 13255f26239SYinghai Lu 13355f26239SYinghai Lu #else 134162434e7SKirill A. Shutemov struct cpuinfo_x86 boot_cpu_data __read_mostly; 13555f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 13655f26239SYinghai Lu #endif 13755f26239SYinghai Lu 13855f26239SYinghai Lu 13955f26239SYinghai Lu #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64) 140404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init; 14155f26239SYinghai Lu #else 142404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; 14355f26239SYinghai Lu #endif 14455f26239SYinghai Lu 1455031296cSH. Peter Anvin /* Boot loader ID and version as integers, for the benefit of proc_dointvec */ 1465031296cSH. Peter Anvin int bootloader_type, bootloader_version; 14755f26239SYinghai Lu 14855f26239SYinghai Lu /* 14955f26239SYinghai Lu * Setup options 15055f26239SYinghai Lu */ 15155f26239SYinghai Lu struct screen_info screen_info; 15255f26239SYinghai Lu EXPORT_SYMBOL(screen_info); 15355f26239SYinghai Lu struct edid_info edid_info; 15455f26239SYinghai Lu EXPORT_SYMBOL_GPL(edid_info); 15555f26239SYinghai Lu 15655f26239SYinghai Lu extern int root_mountflags; 15755f26239SYinghai Lu 15855f26239SYinghai Lu unsigned long saved_video_mode; 15955f26239SYinghai Lu 16055f26239SYinghai Lu #define RAMDISK_IMAGE_START_MASK 0x07FF 16155f26239SYinghai Lu #define RAMDISK_PROMPT_FLAG 0x8000 16255f26239SYinghai Lu #define RAMDISK_LOAD_FLAG 0x4000 16355f26239SYinghai Lu 16455f26239SYinghai Lu static char __initdata command_line[COMMAND_LINE_SIZE]; 165516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 166516cbf37STim Bird static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; 167516cbf37STim Bird #endif 16855f26239SYinghai Lu 16955f26239SYinghai Lu #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) 17055f26239SYinghai Lu struct edd edd; 17155f26239SYinghai Lu #ifdef CONFIG_EDD_MODULE 17255f26239SYinghai Lu EXPORT_SYMBOL(edd); 17355f26239SYinghai Lu #endif 17455f26239SYinghai Lu /** 17555f26239SYinghai Lu * copy_edd() - Copy the BIOS EDD information 17655f26239SYinghai Lu * from boot_params into a safe place. 17755f26239SYinghai Lu * 17855f26239SYinghai Lu */ 1799eaa192dSHelight.Xu static inline void __init copy_edd(void) 18055f26239SYinghai Lu { 18155f26239SYinghai Lu memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, 18255f26239SYinghai Lu sizeof(edd.mbr_signature)); 18355f26239SYinghai Lu memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); 18455f26239SYinghai Lu edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; 18555f26239SYinghai Lu edd.edd_info_nr = boot_params.eddbuf_entries; 18655f26239SYinghai Lu } 18755f26239SYinghai Lu #else 1889eaa192dSHelight.Xu static inline void __init copy_edd(void) 18955f26239SYinghai Lu { 19055f26239SYinghai Lu } 19155f26239SYinghai Lu #endif 19255f26239SYinghai Lu 1935368a2beSH. Peter Anvin void * __init extend_brk(size_t size, size_t align) 1945368a2beSH. Peter Anvin { 1955368a2beSH. Peter Anvin size_t mask = align - 1; 1965368a2beSH. Peter Anvin void *ret; 1975368a2beSH. Peter Anvin 1985368a2beSH. Peter Anvin BUG_ON(_brk_start == 0); 1995368a2beSH. Peter Anvin BUG_ON(align & mask); 2005368a2beSH. Peter Anvin 2015368a2beSH. Peter Anvin _brk_end = (_brk_end + mask) & ~mask; 2025368a2beSH. Peter Anvin BUG_ON((char *)(_brk_end + size) > __brk_limit); 2035368a2beSH. Peter Anvin 2045368a2beSH. Peter Anvin ret = (void *)_brk_end; 2055368a2beSH. Peter Anvin _brk_end += size; 2065368a2beSH. Peter Anvin 2075368a2beSH. Peter Anvin memset(ret, 0, size); 2085368a2beSH. Peter Anvin 2095368a2beSH. Peter Anvin return ret; 2105368a2beSH. Peter Anvin } 2115368a2beSH. Peter Anvin 212148b2098SYinghai Lu #ifdef CONFIG_X86_32 213e5f15b45SYinghai Lu static void __init cleanup_highmap(void) 214f005fe12SYinghai Lu { 215f005fe12SYinghai Lu } 216854c879fSPekka J Enberg #endif 217854c879fSPekka J Enberg 2185368a2beSH. Peter Anvin static void __init reserve_brk(void) 2195368a2beSH. Peter Anvin { 2205368a2beSH. Peter Anvin if (_brk_end > _brk_start) 221fc8d7826SAlexander Duyck memblock_reserve(__pa_symbol(_brk_start), 222fc8d7826SAlexander Duyck _brk_end - _brk_start); 2235368a2beSH. Peter Anvin 2245368a2beSH. Peter Anvin /* Mark brk area as locked down and no longer taking any 2255368a2beSH. Peter Anvin new allocations */ 2265368a2beSH. Peter Anvin _brk_start = 0; 2275368a2beSH. Peter Anvin } 2285368a2beSH. Peter Anvin 2295aa3d718SBorislav Petkov u64 relocated_ramdisk; 2305aa3d718SBorislav Petkov 23155f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_INITRD 23255f26239SYinghai Lu 233a8a51a88SYinghai Lu static u64 __init get_ramdisk_image(void) 234a8a51a88SYinghai Lu { 235a8a51a88SYinghai Lu u64 ramdisk_image = boot_params.hdr.ramdisk_image; 236a8a51a88SYinghai Lu 237ee92d815SYinghai Lu ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; 238ee92d815SYinghai Lu 239694cfd87SRonald G. Minnich if (ramdisk_image == 0) 240694cfd87SRonald G. Minnich ramdisk_image = phys_initrd_start; 241694cfd87SRonald G. Minnich 242a8a51a88SYinghai Lu return ramdisk_image; 243a8a51a88SYinghai Lu } 244a8a51a88SYinghai Lu static u64 __init get_ramdisk_size(void) 245a8a51a88SYinghai Lu { 246a8a51a88SYinghai Lu u64 ramdisk_size = boot_params.hdr.ramdisk_size; 247a8a51a88SYinghai Lu 248ee92d815SYinghai Lu ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; 249ee92d815SYinghai Lu 250694cfd87SRonald G. Minnich if (ramdisk_size == 0) 251694cfd87SRonald G. Minnich ramdisk_size = phys_initrd_size; 252694cfd87SRonald G. Minnich 253a8a51a88SYinghai Lu return ramdisk_size; 254a8a51a88SYinghai Lu } 255a8a51a88SYinghai Lu 25655f26239SYinghai Lu static void __init relocate_initrd(void) 25755f26239SYinghai Lu { 258c967da6aSYinghai Lu /* Assume only end is not page aligned */ 259a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 260a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 261c967da6aSYinghai Lu u64 area_size = PAGE_ALIGN(ramdisk_size); 26255f26239SYinghai Lu 263e8c57d40SYinghai Lu /* We need to move the initrd down into directly mapped mem */ 2643c45ee6dSMike Rapoport relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0, 2653c45ee6dSMike Rapoport PFN_PHYS(max_pfn_mapped)); 2665aa3d718SBorislav Petkov if (!relocated_ramdisk) 26755f26239SYinghai Lu panic("Cannot find place for new RAMDISK of size %lld\n", 26855f26239SYinghai Lu ramdisk_size); 26955f26239SYinghai Lu 2705aa3d718SBorislav Petkov initrd_start = relocated_ramdisk + PAGE_OFFSET; 27155f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 272365811d6SBjorn Helgaas printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", 2735aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 27455f26239SYinghai Lu 2755dd2c4bdSMark Salter copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size); 27655f26239SYinghai Lu 277365811d6SBjorn Helgaas printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to" 278365811d6SBjorn Helgaas " [mem %#010llx-%#010llx]\n", 27955f26239SYinghai Lu ramdisk_image, ramdisk_image + ramdisk_size - 1, 2805aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 28155f26239SYinghai Lu } 28255f26239SYinghai Lu 2831b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 2841b8c78beSYinghai Lu { 2851b8c78beSYinghai Lu /* Assume only end is not page aligned */ 286a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 287a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 2881b8c78beSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 2891b8c78beSYinghai Lu 2901b8c78beSYinghai Lu if (!boot_params.hdr.type_of_loader || 2911b8c78beSYinghai Lu !ramdisk_image || !ramdisk_size) 2921b8c78beSYinghai Lu return; /* No initrd provided by bootloader */ 2931b8c78beSYinghai Lu 2941b8c78beSYinghai Lu memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); 2951b8c78beSYinghai Lu } 2963c45ee6dSMike Rapoport 29755f26239SYinghai Lu static void __init reserve_initrd(void) 29855f26239SYinghai Lu { 299c967da6aSYinghai Lu /* Assume only end is not page aligned */ 300a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 301a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 302c967da6aSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 30355f26239SYinghai Lu 30455f26239SYinghai Lu if (!boot_params.hdr.type_of_loader || 30555f26239SYinghai Lu !ramdisk_image || !ramdisk_size) 30655f26239SYinghai Lu return; /* No initrd provided by bootloader */ 30755f26239SYinghai Lu 30855f26239SYinghai Lu initrd_start = 0; 30955f26239SYinghai Lu 310365811d6SBjorn Helgaas printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, 311365811d6SBjorn Helgaas ramdisk_end - 1); 31255f26239SYinghai Lu 31374f27655SYinghai Lu if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image), 314e8c57d40SYinghai Lu PFN_DOWN(ramdisk_end))) { 315e8c57d40SYinghai Lu /* All are mapped, easy case */ 31655f26239SYinghai Lu initrd_start = ramdisk_image + PAGE_OFFSET; 31755f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 31855f26239SYinghai Lu return; 31955f26239SYinghai Lu } 32055f26239SYinghai Lu 32155f26239SYinghai Lu relocate_initrd(); 3228c5dd8f4SYinghai Lu 32324aa0788STejun Heo memblock_free(ramdisk_image, ramdisk_end - ramdisk_image); 32455f26239SYinghai Lu } 325af06f8b7SLv Zheng 32655f26239SYinghai Lu #else 3271b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3281b8c78beSYinghai Lu { 3291b8c78beSYinghai Lu } 33055f26239SYinghai Lu static void __init reserve_initrd(void) 33155f26239SYinghai Lu { 33255f26239SYinghai Lu } 33355f26239SYinghai Lu #endif /* CONFIG_BLK_DEV_INITRD */ 33455f26239SYinghai Lu 33529f784e3SYinghai Lu static void __init parse_setup_data(void) 336257b0fdeSYinghai Lu { 337257b0fdeSYinghai Lu struct setup_data *data; 33830e46b57SLinn Crosetto u64 pa_data, pa_next; 339257b0fdeSYinghai Lu 340257b0fdeSYinghai Lu pa_data = boot_params.hdr.setup_data; 341257b0fdeSYinghai Lu while (pa_data) { 3427389882cSWANG Chao u32 data_len, data_type; 343f1c2b357SSebastian Andrzej Siewior 3447389882cSWANG Chao data = early_memremap(pa_data, sizeof(*data)); 345f1c2b357SSebastian Andrzej Siewior data_len = data->len + sizeof(struct setup_data); 34630e46b57SLinn Crosetto data_type = data->type; 34730e46b57SLinn Crosetto pa_next = data->next; 3488d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 349f1c2b357SSebastian Andrzej Siewior 35030e46b57SLinn Crosetto switch (data_type) { 351257b0fdeSYinghai Lu case SETUP_E820_EXT: 352914053c0SIngo Molnar e820__memory_setup_extended(pa_data, data_len); 353257b0fdeSYinghai Lu break; 354da6b737bSSebastian Andrzej Siewior case SETUP_DTB: 355da6b737bSSebastian Andrzej Siewior add_dtb(pa_data); 356257b0fdeSYinghai Lu break; 3571fec0533SDave Young case SETUP_EFI: 3581fec0533SDave Young parse_efi_setup(pa_data, data_len); 3591fec0533SDave Young break; 360257b0fdeSYinghai Lu default: 361257b0fdeSYinghai Lu break; 362257b0fdeSYinghai Lu } 36330e46b57SLinn Crosetto pa_data = pa_next; 364257b0fdeSYinghai Lu } 365257b0fdeSYinghai Lu } 366257b0fdeSYinghai Lu 367a9ce6bc1SYinghai Lu static void __init memblock_x86_reserve_range_setup_data(void) 368a0a0becdSYinghai Lu { 369a0a0becdSYinghai Lu struct setup_data *data; 370a0a0becdSYinghai Lu u64 pa_data; 371a0a0becdSYinghai Lu 372a0a0becdSYinghai Lu pa_data = boot_params.hdr.setup_data; 373a0a0becdSYinghai Lu while (pa_data) { 37488b4c146SJeremy Fitzhardinge data = early_memremap(pa_data, sizeof(*data)); 37524aa0788STejun Heo memblock_reserve(pa_data, sizeof(*data) + data->len); 376b3c72fc9SDaniel Kiper 377b3c72fc9SDaniel Kiper if (data->type == SETUP_INDIRECT && 378b3c72fc9SDaniel Kiper ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) 379b3c72fc9SDaniel Kiper memblock_reserve(((struct setup_indirect *)data->data)->addr, 380b3c72fc9SDaniel Kiper ((struct setup_indirect *)data->data)->len); 381b3c72fc9SDaniel Kiper 382a0a0becdSYinghai Lu pa_data = data->next; 3838d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 384a0a0becdSYinghai Lu } 385a0a0becdSYinghai Lu } 386a0a0becdSYinghai Lu 38755f26239SYinghai Lu /* 388ccb4defaSYinghai Lu * --------- Crashkernel reservation ------------------------------ 389ccb4defaSYinghai Lu */ 390ccb4defaSYinghai Lu 3912965faa5SDave Young #ifdef CONFIG_KEXEC_CORE 39232105f7fSBernhard Walle 393606134f7SBorislav Petkov /* 16M alignment for crash kernel regions */ 3949ca5c8e6SDave Young #define CRASH_ALIGN SZ_16M 395606134f7SBorislav Petkov 3967f8595bfSH. Peter Anvin /* 3978ff80fbeSBaoquan He * Keep the crash kernel below this limit. 3988ff80fbeSBaoquan He * 399360db4acSIngo Molnar * Earlier 32-bits kernels would limit the kernel to the low 512 MB range 4008ff80fbeSBaoquan He * due to mapping restrictions. 4018ff80fbeSBaoquan He * 402360db4acSIngo Molnar * 64-bit kdump kernels need to be restricted to be under 64 TB, which is 40311a98f37SCao jin * the upper limit of system RAM in 4-level paging mode. Since the kdump 404360db4acSIngo Molnar * jump could be from 5-level paging to 4-level paging, the jump will fail if 405360db4acSIngo Molnar * the kernel is put above 64 TB, and during the 1st kernel bootup there's 406360db4acSIngo Molnar * no good way to detect the paging mode of the target kernel which will be 407360db4acSIngo Molnar * loaded for dumping. 4087f8595bfSH. Peter Anvin */ 4097f8595bfSH. Peter Anvin #ifdef CONFIG_X86_32 4109ca5c8e6SDave Young # define CRASH_ADDR_LOW_MAX SZ_512M 4119ca5c8e6SDave Young # define CRASH_ADDR_HIGH_MAX SZ_512M 4127f8595bfSH. Peter Anvin #else 4139ca5c8e6SDave Young # define CRASH_ADDR_LOW_MAX SZ_4G 4148ff80fbeSBaoquan He # define CRASH_ADDR_HIGH_MAX SZ_64T 4157f8595bfSH. Peter Anvin #endif 4167f8595bfSH. Peter Anvin 417eb6db83dSBaoquan He static int __init reserve_crashkernel_low(void) 4180212f915SYinghai Lu { 4190212f915SYinghai Lu #ifdef CONFIG_X86_64 420f56d5578SBorislav Petkov unsigned long long base, low_base = 0, low_size = 0; 4216120cdc0SMike Rapoport unsigned long low_mem_limit; 4220212f915SYinghai Lu int ret; 4230212f915SYinghai Lu 4246120cdc0SMike Rapoport low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX); 42597eac21bSBorislav Petkov 426adbc742bSYinghai Lu /* crashkernel=Y,low */ 4276120cdc0SMike Rapoport ret = parse_crashkernel_low(boot_command_line, low_mem_limit, &low_size, &base); 428f56d5578SBorislav Petkov if (ret) { 429c729de8fSYinghai Lu /* 430392e879aSAndy Shevchenko * two parts from kernel/dma/swiotlb.c: 43194fb9334SJoerg Roedel * -swiotlb size: user-specified with swiotlb= or default. 43294fb9334SJoerg Roedel * 43394fb9334SJoerg Roedel * -swiotlb overflow buffer: now hardcoded to 32k. We round it 43494fb9334SJoerg Roedel * to 8M for other buffers that may need to stay low too. Also 43594fb9334SJoerg Roedel * make sure we allocate enough extra low memory so that we 43694fb9334SJoerg Roedel * don't run out of DMA buffers for 32-bit devices. 437c729de8fSYinghai Lu */ 43894fb9334SJoerg Roedel low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); 439c729de8fSYinghai Lu } else { 440adbc742bSYinghai Lu /* passed with crashkernel=0,low ? */ 441c729de8fSYinghai Lu if (!low_size) 442eb6db83dSBaoquan He return 0; 443c729de8fSYinghai Lu } 4440212f915SYinghai Lu 4456120cdc0SMike Rapoport low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); 4460212f915SYinghai Lu if (!low_base) { 447eb6db83dSBaoquan He pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", 448eb6db83dSBaoquan He (unsigned long)(low_size >> 20)); 449eb6db83dSBaoquan He return -ENOMEM; 4500212f915SYinghai Lu } 4510212f915SYinghai Lu 4526120cdc0SMike Rapoport pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (low RAM limit: %ldMB)\n", 4530212f915SYinghai Lu (unsigned long)(low_size >> 20), 4540212f915SYinghai Lu (unsigned long)(low_base >> 20), 4556120cdc0SMike Rapoport (unsigned long)(low_mem_limit >> 20)); 45697eac21bSBorislav Petkov 4570212f915SYinghai Lu crashk_low_res.start = low_base; 4580212f915SYinghai Lu crashk_low_res.end = low_base + low_size - 1; 4590212f915SYinghai Lu insert_resource(&iomem_resource, &crashk_low_res); 4600212f915SYinghai Lu #endif 461eb6db83dSBaoquan He return 0; 4620212f915SYinghai Lu } 4630212f915SYinghai Lu 46429f784e3SYinghai Lu static void __init reserve_crashkernel(void) 465ccb4defaSYinghai Lu { 466f56d5578SBorislav Petkov unsigned long long crash_size, crash_base, total_mem; 46755a20ee7SYinghai Lu bool high = false; 468ccb4defaSYinghai Lu int ret; 469ccb4defaSYinghai Lu 47009c71bfdSDave Young total_mem = memblock_phys_mem_size(); 471ccb4defaSYinghai Lu 47255a20ee7SYinghai Lu /* crashkernel=XM */ 47397eac21bSBorislav Petkov ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); 47455a20ee7SYinghai Lu if (ret != 0 || crash_size <= 0) { 475adbc742bSYinghai Lu /* crashkernel=X,high */ 47655a20ee7SYinghai Lu ret = parse_crashkernel_high(boot_command_line, total_mem, 47755a20ee7SYinghai Lu &crash_size, &crash_base); 47832105f7fSBernhard Walle if (ret != 0 || crash_size <= 0) 47932105f7fSBernhard Walle return; 48055a20ee7SYinghai Lu high = true; 48155a20ee7SYinghai Lu } 48232105f7fSBernhard Walle 4833db3eb28SPetr Tesarik if (xen_pv_domain()) { 4843db3eb28SPetr Tesarik pr_info("Ignoring crashkernel for a Xen PV domain\n"); 4853db3eb28SPetr Tesarik return; 4863db3eb28SPetr Tesarik } 4873db3eb28SPetr Tesarik 48832105f7fSBernhard Walle /* 0 means: find the address automatically */ 489b9ac3849SDave Young if (!crash_base) { 4909f4c1396SYinghai Lu /* 491a8d4c824SXunlei Pang * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, 492b9ac3849SDave Young * crashkernel=x,high reserves memory over 4G, also allocates 493b9ac3849SDave Young * 256M extra low memory for DMA buffers and swiotlb. 494b9ac3849SDave Young * But the extra memory is not required for all machines. 495b9ac3849SDave Young * So try low memory first and fall back to high memory 496b9ac3849SDave Young * unless "crashkernel=size[KMG],high" is specified. 4979f4c1396SYinghai Lu */ 498b9ac3849SDave Young if (!high) 4996120cdc0SMike Rapoport crash_base = memblock_phys_alloc_range(crash_size, 5006120cdc0SMike Rapoport CRASH_ALIGN, CRASH_ALIGN, 5016120cdc0SMike Rapoport CRASH_ADDR_LOW_MAX); 502b9ac3849SDave Young if (!crash_base) 5036120cdc0SMike Rapoport crash_base = memblock_phys_alloc_range(crash_size, 5046120cdc0SMike Rapoport CRASH_ALIGN, CRASH_ALIGN, 5056120cdc0SMike Rapoport CRASH_ADDR_HIGH_MAX); 5061f5026a7STejun Heo if (!crash_base) { 50744280733SYinghai Lu pr_info("crashkernel reservation failed - No suitable area found.\n"); 508ccb4defaSYinghai Lu return; 509ccb4defaSYinghai Lu } 51032105f7fSBernhard Walle } else { 51144280733SYinghai Lu unsigned long long start; 51244280733SYinghai Lu 5136120cdc0SMike Rapoport start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base, 5146120cdc0SMike Rapoport crash_base + crash_size); 51544280733SYinghai Lu if (start != crash_base) { 51644280733SYinghai Lu pr_info("crashkernel reservation failed - memory is in use.\n"); 517ccb4defaSYinghai Lu return; 518ccb4defaSYinghai Lu } 51932105f7fSBernhard Walle } 520ccb4defaSYinghai Lu 521eb6db83dSBaoquan He if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { 522eb6db83dSBaoquan He memblock_free(crash_base, crash_size); 523eb6db83dSBaoquan He return; 524eb6db83dSBaoquan He } 525eb6db83dSBaoquan He 526f56d5578SBorislav Petkov pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", 527ccb4defaSYinghai Lu (unsigned long)(crash_size >> 20), 528ccb4defaSYinghai Lu (unsigned long)(crash_base >> 20), 529ccb4defaSYinghai Lu (unsigned long)(total_mem >> 20)); 530ccb4defaSYinghai Lu 531ccb4defaSYinghai Lu crashk_res.start = crash_base; 532ccb4defaSYinghai Lu crashk_res.end = crash_base + crash_size - 1; 533ccb4defaSYinghai Lu insert_resource(&iomem_resource, &crashk_res); 534ccb4defaSYinghai Lu } 535ccb4defaSYinghai Lu #else 53629f784e3SYinghai Lu static void __init reserve_crashkernel(void) 537ccb4defaSYinghai Lu { 538ccb4defaSYinghai Lu } 539ccb4defaSYinghai Lu #endif 540ccb4defaSYinghai Lu 541bdba0e70SYinghai Lu static struct resource standard_io_resources[] = { 542bdba0e70SYinghai Lu { .name = "dma1", .start = 0x00, .end = 0x1f, 543bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 544bdba0e70SYinghai Lu { .name = "pic1", .start = 0x20, .end = 0x21, 545bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 546bdba0e70SYinghai Lu { .name = "timer0", .start = 0x40, .end = 0x43, 547bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 548bdba0e70SYinghai Lu { .name = "timer1", .start = 0x50, .end = 0x53, 549bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 550bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x60, .end = 0x60, 551bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 552bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x64, .end = 0x64, 553bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 554bdba0e70SYinghai Lu { .name = "dma page reg", .start = 0x80, .end = 0x8f, 555bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 556bdba0e70SYinghai Lu { .name = "pic2", .start = 0xa0, .end = 0xa1, 557bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 558bdba0e70SYinghai Lu { .name = "dma2", .start = 0xc0, .end = 0xdf, 559bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 560bdba0e70SYinghai Lu { .name = "fpu", .start = 0xf0, .end = 0xff, 561bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO } 562bdba0e70SYinghai Lu }; 563bdba0e70SYinghai Lu 5648fee697dSThomas Gleixner void __init reserve_standard_io_resources(void) 565bdba0e70SYinghai Lu { 566bdba0e70SYinghai Lu int i; 567bdba0e70SYinghai Lu 568bdba0e70SYinghai Lu /* request I/O space for devices used on all i[345]86 PCs */ 569bdba0e70SYinghai Lu for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) 570bdba0e70SYinghai Lu request_resource(&ioport_resource, &standard_io_resources[i]); 571bdba0e70SYinghai Lu 572bdba0e70SYinghai Lu } 573bdba0e70SYinghai Lu 574042be38eSYinghai Lu static __init void reserve_ibft_region(void) 575042be38eSYinghai Lu { 576042be38eSYinghai Lu unsigned long addr, size = 0; 577042be38eSYinghai Lu 578042be38eSYinghai Lu addr = find_ibft_region(&size); 579042be38eSYinghai Lu 580042be38eSYinghai Lu if (size) 58124aa0788STejun Heo memblock_reserve(addr, size); 582042be38eSYinghai Lu } 583042be38eSYinghai Lu 584a9acc536SJesse Barnes static bool __init snb_gfx_workaround_needed(void) 585a9acc536SJesse Barnes { 586e43b3cecSH. Peter Anvin #ifdef CONFIG_PCI 587a9acc536SJesse Barnes int i; 588a9acc536SJesse Barnes u16 vendor, devid; 589ab3cd867SH. Peter Anvin static const __initconst u16 snb_ids[] = { 590a9acc536SJesse Barnes 0x0102, 591a9acc536SJesse Barnes 0x0112, 592a9acc536SJesse Barnes 0x0122, 593a9acc536SJesse Barnes 0x0106, 594a9acc536SJesse Barnes 0x0116, 595a9acc536SJesse Barnes 0x0126, 596a9acc536SJesse Barnes 0x010a, 597a9acc536SJesse Barnes }; 598a9acc536SJesse Barnes 599a9acc536SJesse Barnes /* Assume no if something weird is going on with PCI */ 600a9acc536SJesse Barnes if (!early_pci_allowed()) 601a9acc536SJesse Barnes return false; 602a9acc536SJesse Barnes 603a9acc536SJesse Barnes vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); 604a9acc536SJesse Barnes if (vendor != 0x8086) 605a9acc536SJesse Barnes return false; 606a9acc536SJesse Barnes 607a9acc536SJesse Barnes devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); 608a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(snb_ids); i++) 609a9acc536SJesse Barnes if (devid == snb_ids[i]) 610a9acc536SJesse Barnes return true; 611e43b3cecSH. Peter Anvin #endif 612a9acc536SJesse Barnes 613a9acc536SJesse Barnes return false; 614a9acc536SJesse Barnes } 615a9acc536SJesse Barnes 616a9acc536SJesse Barnes /* 617a9acc536SJesse Barnes * Sandy Bridge graphics has trouble with certain ranges, exclude 618a9acc536SJesse Barnes * them from allocation. 619a9acc536SJesse Barnes */ 620a9acc536SJesse Barnes static void __init trim_snb_memory(void) 621a9acc536SJesse Barnes { 622ab3cd867SH. Peter Anvin static const __initconst unsigned long bad_pages[] = { 623a9acc536SJesse Barnes 0x20050000, 624a9acc536SJesse Barnes 0x20110000, 625a9acc536SJesse Barnes 0x20130000, 626a9acc536SJesse Barnes 0x20138000, 627a9acc536SJesse Barnes 0x40004000, 628a9acc536SJesse Barnes }; 629a9acc536SJesse Barnes int i; 630a9acc536SJesse Barnes 631a9acc536SJesse Barnes if (!snb_gfx_workaround_needed()) 632a9acc536SJesse Barnes return; 633a9acc536SJesse Barnes 634a9acc536SJesse Barnes printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); 635a9acc536SJesse Barnes 636a9acc536SJesse Barnes /* 637c361e5d4SMike Rapoport * SandyBridge integrated graphics devices have a bug that prevents 638c361e5d4SMike Rapoport * them from accessing certain memory ranges, namely anything below 639c361e5d4SMike Rapoport * 1M and in the pages listed in bad_pages[] above. 640c361e5d4SMike Rapoport * 641f1d4d47cSMike Rapoport * To avoid these pages being ever accessed by SNB gfx devices reserve 642f1d4d47cSMike Rapoport * bad_pages that have not already been reserved at boot time. 643f1d4d47cSMike Rapoport * All memory below the 1 MB mark is anyway reserved later during 644f1d4d47cSMike Rapoport * setup_arch(), so there is no need to reserve it here. 645a9acc536SJesse Barnes */ 646a9acc536SJesse Barnes 647a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { 648a9acc536SJesse Barnes if (memblock_reserve(bad_pages[i], PAGE_SIZE)) 649a9acc536SJesse Barnes printk(KERN_WARNING "failed to reserve 0x%08lx\n", 650a9acc536SJesse Barnes bad_pages[i]); 651a9acc536SJesse Barnes } 652a9acc536SJesse Barnes } 653a9acc536SJesse Barnes 6541b5576e6SYinghai Lu static void __init trim_bios_range(void) 6551b5576e6SYinghai Lu { 6561b5576e6SYinghai Lu /* 6575c279c4cSMike Rapoport * A special case is the first 4Kb of memory; 6585c279c4cSMike Rapoport * This is a BIOS owned area, not kernel ram, but generally 6595c279c4cSMike Rapoport * not listed as such in the E820 table. 6605c279c4cSMike Rapoport * 6615c279c4cSMike Rapoport * This typically reserves additional memory (64KiB by default) 6625c279c4cSMike Rapoport * since some BIOSes are known to corrupt low memory. See the 6635c279c4cSMike Rapoport * Kconfig help text for X86_RESERVE_LOW. 6645c279c4cSMike Rapoport */ 6655c279c4cSMike Rapoport e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); 6665c279c4cSMike Rapoport 6675c279c4cSMike Rapoport /* 66811a98f37SCao jin * special case: Some BIOSes report the PC BIOS 66911a98f37SCao jin * area (640Kb -> 1Mb) as RAM even though it is not. 6701b5576e6SYinghai Lu * take them out. 6711b5576e6SYinghai Lu */ 67209821ff1SIngo Molnar e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); 673a9acc536SJesse Barnes 674f9748fa0SIngo Molnar e820__update_table(e820_table); 6751b5576e6SYinghai Lu } 6761b5576e6SYinghai Lu 677b422a309SYinghai Lu /* called before trim_bios_range() to spare extra sanitize */ 678b422a309SYinghai Lu static void __init e820_add_kernel_range(void) 679b422a309SYinghai Lu { 680b422a309SYinghai Lu u64 start = __pa_symbol(_text); 681b422a309SYinghai Lu u64 size = __pa_symbol(_end) - start; 682b422a309SYinghai Lu 683b422a309SYinghai Lu /* 68409821ff1SIngo Molnar * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and 685b422a309SYinghai Lu * attempt to fix it by adding the range. We may have a confused BIOS, 686b422a309SYinghai Lu * or the user may have used memmap=exactmap or memmap=xxM$yyM to 687b422a309SYinghai Lu * exclude kernel range. If we really are running on top non-RAM, 688b422a309SYinghai Lu * we will crash later anyways. 689b422a309SYinghai Lu */ 69009821ff1SIngo Molnar if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) 691b422a309SYinghai Lu return; 692b422a309SYinghai Lu 69309821ff1SIngo Molnar pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); 69409821ff1SIngo Molnar e820__range_remove(start, size, E820_TYPE_RAM, 0); 69509821ff1SIngo Molnar e820__range_add(start, size, E820_TYPE_RAM); 696b422a309SYinghai Lu } 697b422a309SYinghai Lu 698a799c2bdSMike Rapoport static void __init early_reserve_memory(void) 69995c96084SH. Peter Anvin { 700a799c2bdSMike Rapoport /* 701a799c2bdSMike Rapoport * Reserve the memory occupied by the kernel between _text and 702a799c2bdSMike Rapoport * __end_of_kernel_reserve symbols. Any kernel sections after the 703a799c2bdSMike Rapoport * __end_of_kernel_reserve symbol must be explicitly reserved with a 704a799c2bdSMike Rapoport * separate memblock_reserve() or they will be discarded. 705a799c2bdSMike Rapoport */ 706a799c2bdSMike Rapoport memblock_reserve(__pa_symbol(_text), 707a799c2bdSMike Rapoport (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); 708a799c2bdSMike Rapoport 709a799c2bdSMike Rapoport /* 7104c674481SMike Rapoport * The first 4Kb of memory is a BIOS owned area, but generally it is 7114c674481SMike Rapoport * not listed as such in the E820 table. 7124c674481SMike Rapoport * 713f1d4d47cSMike Rapoport * Reserve the first 64K of memory since some BIOSes are known to 714f1d4d47cSMike Rapoport * corrupt low memory. After the real mode trampoline is allocated the 715f1d4d47cSMike Rapoport * rest of the memory below 640k is reserved. 7164c674481SMike Rapoport * 7174c674481SMike Rapoport * In addition, make sure page 0 is always reserved because on 7184c674481SMike Rapoport * systems with L1TF its contents can be leaked to user processes. 719a799c2bdSMike Rapoport */ 720f1d4d47cSMike Rapoport memblock_reserve(0, SZ_64K); 721a799c2bdSMike Rapoport 722a799c2bdSMike Rapoport early_reserve_initrd(); 723a799c2bdSMike Rapoport 724a799c2bdSMike Rapoport if (efi_enabled(EFI_BOOT)) 725a799c2bdSMike Rapoport efi_memblock_x86_reserve_range(); 726a799c2bdSMike Rapoport 727a799c2bdSMike Rapoport memblock_x86_reserve_range_setup_data(); 728a799c2bdSMike Rapoport 729a799c2bdSMike Rapoport reserve_ibft_region(); 730a799c2bdSMike Rapoport reserve_bios_regions(); 731f1d4d47cSMike Rapoport trim_snb_memory(); 73295c96084SH. Peter Anvin } 73395c96084SH. Peter Anvin 7345394f80fSJeremy Fitzhardinge /* 735f32360efSKees Cook * Dump out kernel offset information on panic. 736f32360efSKees Cook */ 737f32360efSKees Cook static int 738f32360efSKees Cook dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) 739f32360efSKees Cook { 74078cac48cSBorislav Petkov if (kaslr_enabled()) { 74178cac48cSBorislav Petkov pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", 7424545c898SJiri Kosina kaslr_offset(), 74378cac48cSBorislav Petkov __START_KERNEL, 74478cac48cSBorislav Petkov __START_KERNEL_map, 74578cac48cSBorislav Petkov MODULES_VADDR-1); 74678cac48cSBorislav Petkov } else { 74778cac48cSBorislav Petkov pr_emerg("Kernel Offset: disabled\n"); 74878cac48cSBorislav Petkov } 749f32360efSKees Cook 750f32360efSKees Cook return 0; 751f32360efSKees Cook } 752f32360efSKees Cook 753f32360efSKees Cook /* 75455f26239SYinghai Lu * Determine if we were loaded by an EFI loader. If so, then we have also been 75555f26239SYinghai Lu * passed the efi memmap, systab, etc., so we should use these data structures 75655f26239SYinghai Lu * for initialization. Note, the efi init code path is determined by the 75755f26239SYinghai Lu * global efi_enabled. This allows the same kernel image to be used on existing 75855f26239SYinghai Lu * systems (with a traditional BIOS) as well as on EFI systems. 75955f26239SYinghai Lu */ 76055f26239SYinghai Lu /* 76155f26239SYinghai Lu * setup_arch - architecture-specific boot-time initializations 76255f26239SYinghai Lu * 76355f26239SYinghai Lu * Note: On x86_64, fixmaps are ready for use even before this is called. 76455f26239SYinghai Lu */ 76555f26239SYinghai Lu 76655f26239SYinghai Lu void __init setup_arch(char **cmdline_p) 76755f26239SYinghai Lu { 76855f26239SYinghai Lu #ifdef CONFIG_X86_32 76955f26239SYinghai Lu memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); 770b40827faSBorislav Petkov 771b40827faSBorislav Petkov /* 772b40827faSBorislav Petkov * copy kernel address range established so far and switch 773b40827faSBorislav Petkov * to the proper swapper page table 774b40827faSBorislav Petkov */ 775b40827faSBorislav Petkov clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, 776b40827faSBorislav Petkov initial_page_table + KERNEL_PGD_BOUNDARY, 777b40827faSBorislav Petkov KERNEL_PGD_PTRS); 778b40827faSBorislav Petkov 779b40827faSBorislav Petkov load_cr3(swapper_pg_dir); 7802075244fSBryan O'Donoghue /* 7812075244fSBryan O'Donoghue * Note: Quark X1000 CPUs advertise PGE incorrectly and require 7822075244fSBryan O'Donoghue * a cr3 based tlb flush, so the following __flush_tlb_all() 783360db4acSIngo Molnar * will not flush anything because the CPU quirk which clears 7842075244fSBryan O'Donoghue * X86_FEATURE_PGE has not been invoked yet. Though due to the 7852075244fSBryan O'Donoghue * load_cr3() above the TLB has been flushed already. The 7862075244fSBryan O'Donoghue * quirk is invoked before subsequent calls to __flush_tlb_all() 7872075244fSBryan O'Donoghue * so proper operation is guaranteed. 7882075244fSBryan O'Donoghue */ 789b40827faSBorislav Petkov __flush_tlb_all(); 79055f26239SYinghai Lu #else 79155f26239SYinghai Lu printk(KERN_INFO "Command line: %s\n", boot_command_line); 792162434e7SKirill A. Shutemov boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; 79355f26239SYinghai Lu #endif 79455f26239SYinghai Lu 7959863c90fSAlok Kataria /* 7969863c90fSAlok Kataria * If we have OLPC OFW, we might end up relocating the fixmap due to 7979863c90fSAlok Kataria * reserve_top(), so do this before touching the ioremap area. 7989863c90fSAlok Kataria */ 799fd699c76SAndres Salomon olpc_ofw_detect(); 800fd699c76SAndres Salomon 801433f8924SThomas Gleixner idt_setup_early_traps(); 8029e882c92SJeremy Fitzhardinge early_cpu_init(); 8038990cac6SPavel Tatashin jump_label_init(); 804a945c834SPeter Zijlstra static_call_init(); 8051a98fd14SJeremy Fitzhardinge early_ioremap_init(); 8061a98fd14SJeremy Fitzhardinge 807fd699c76SAndres Salomon setup_olpc_ofw_pgd(); 808fd699c76SAndres Salomon 80955f26239SYinghai Lu ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); 81055f26239SYinghai Lu screen_info = boot_params.screen_info; 81155f26239SYinghai Lu edid_info = boot_params.edid_info; 81255f26239SYinghai Lu #ifdef CONFIG_X86_32 81355f26239SYinghai Lu apm_info.bios = boot_params.apm_bios_info; 81455f26239SYinghai Lu ist_info = boot_params.ist_info; 81555f26239SYinghai Lu #endif 81655f26239SYinghai Lu saved_video_mode = boot_params.hdr.vid_mode; 81755f26239SYinghai Lu bootloader_type = boot_params.hdr.type_of_loader; 8185031296cSH. Peter Anvin if ((bootloader_type >> 4) == 0xe) { 8195031296cSH. Peter Anvin bootloader_type &= 0xf; 8205031296cSH. Peter Anvin bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; 8215031296cSH. Peter Anvin } 8225031296cSH. Peter Anvin bootloader_version = bootloader_type & 0xf; 8235031296cSH. Peter Anvin bootloader_version |= boot_params.hdr.ext_loader_ver << 4; 82455f26239SYinghai Lu 82555f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_RAM 82655f26239SYinghai Lu rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; 82755f26239SYinghai Lu #endif 82855f26239SYinghai Lu #ifdef CONFIG_EFI 82955f26239SYinghai Lu if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 8309402973dSDaniel Kiper EFI32_LOADER_SIGNATURE, 4)) { 8313e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 8321adbfa35SOlof Johansson } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 8339402973dSDaniel Kiper EFI64_LOADER_SIGNATURE, 4)) { 8343e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 8353e909599SMatt Fleming set_bit(EFI_64BIT, &efi.flags); 83655f26239SYinghai Lu } 83755f26239SYinghai Lu #endif 83855f26239SYinghai Lu 83942bbdb43SThomas Gleixner x86_init.oem.arch_setup(); 84055f26239SYinghai Lu 841419afdf5SBjorn Helgaas iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 842103e2063SIngo Molnar e820__memory_setup(); 84328bb2237SYinghai Lu parse_setup_data(); 84428bb2237SYinghai Lu 84555f26239SYinghai Lu copy_edd(); 84655f26239SYinghai Lu 84755f26239SYinghai Lu if (!boot_params.hdr.root_flags) 84855f26239SYinghai Lu root_mountflags &= ~MS_RDONLY; 84955f26239SYinghai Lu init_mm.start_code = (unsigned long) _text; 85055f26239SYinghai Lu init_mm.end_code = (unsigned long) _etext; 85155f26239SYinghai Lu init_mm.end_data = (unsigned long) _edata; 85293dbda7cSJeremy Fitzhardinge init_mm.brk = _brk_end; 85355f26239SYinghai Lu 8544046d6e8SLinus Torvalds code_resource.start = __pa_symbol(_text); 8554046d6e8SLinus Torvalds code_resource.end = __pa_symbol(_etext)-1; 856a3299754SKees Cook rodata_resource.start = __pa_symbol(__start_rodata); 857a3299754SKees Cook rodata_resource.end = __pa_symbol(__end_rodata)-1; 858a3299754SKees Cook data_resource.start = __pa_symbol(_sdata); 8594046d6e8SLinus Torvalds data_resource.end = __pa_symbol(_edata)-1; 8604046d6e8SLinus Torvalds bss_resource.start = __pa_symbol(__bss_start); 8614046d6e8SLinus Torvalds bss_resource.end = __pa_symbol(__bss_stop)-1; 8624046d6e8SLinus Torvalds 863516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 864516cbf37STim Bird #ifdef CONFIG_CMDLINE_OVERRIDE 865516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 866516cbf37STim Bird #else 867516cbf37STim Bird if (builtin_cmdline[0]) { 868516cbf37STim Bird /* append boot loader cmdline to builtin */ 869516cbf37STim Bird strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 870516cbf37STim Bird strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 871516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 872516cbf37STim Bird } 873516cbf37STim Bird #endif 874516cbf37STim Bird #endif 875516cbf37STim Bird 876eda6da92SYinghai Lu strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 877eda6da92SYinghai Lu *cmdline_p = command_line; 878eda6da92SYinghai Lu 879eda6da92SYinghai Lu /* 8804b0f3b81SKees Cook * x86_configure_nx() is called before parse_early_param() to detect 8814b0f3b81SKees Cook * whether hardware doesn't support NX (so that the early EHCI debug 8824b0f3b81SKees Cook * console setup can safely call set_fixmap()). It may then be called 8834b0f3b81SKees Cook * again from within noexec_setup() during parsing early parameters 8844b0f3b81SKees Cook * to honor the respective command line option. 885eda6da92SYinghai Lu */ 8864763ed4dSH. Peter Anvin x86_configure_nx(); 887eda6da92SYinghai Lu 888eda6da92SYinghai Lu parse_early_param(); 889eda6da92SYinghai Lu 890a799c2bdSMike Rapoport /* 891a799c2bdSMike Rapoport * Do some memory reservations *before* memory is added to 892a799c2bdSMike Rapoport * memblock, so memblock allocations won't overwrite it. 893a799c2bdSMike Rapoport * Do it after early param, so we could get (unlikely) panic from 894a799c2bdSMike Rapoport * serial. 895a799c2bdSMike Rapoport * 896a799c2bdSMike Rapoport * After this point everything still needed from the boot loader or 897a799c2bdSMike Rapoport * firmware or kernel text should be early reserved or marked not 898a799c2bdSMike Rapoport * RAM in e820. All other memory is free game. 899a799c2bdSMike Rapoport */ 900a799c2bdSMike Rapoport early_reserve_memory(); 901a799c2bdSMike Rapoport 90239fa104dSReza Arbab #ifdef CONFIG_MEMORY_HOTPLUG 90339fa104dSReza Arbab /* 90439fa104dSReza Arbab * Memory used by the kernel cannot be hot-removed because Linux 90539fa104dSReza Arbab * cannot migrate the kernel pages. When memory hotplug is 90639fa104dSReza Arbab * enabled, we should prevent memblock from allocating memory 90739fa104dSReza Arbab * for the kernel. 90839fa104dSReza Arbab * 90939fa104dSReza Arbab * ACPI SRAT records all hotpluggable memory ranges. But before 91039fa104dSReza Arbab * SRAT is parsed, we don't know about it. 91139fa104dSReza Arbab * 91239fa104dSReza Arbab * The kernel image is loaded into memory at very early time. We 91339fa104dSReza Arbab * cannot prevent this anyway. So on NUMA system, we set any 91439fa104dSReza Arbab * node the kernel resides in as un-hotpluggable. 91539fa104dSReza Arbab * 91639fa104dSReza Arbab * Since on modern servers, one node could have double-digit 91739fa104dSReza Arbab * gigabytes memory, we can assume the memory around the kernel 91839fa104dSReza Arbab * image is also un-hotpluggable. So before SRAT is parsed, just 91939fa104dSReza Arbab * allocate memory near the kernel image to try the best to keep 92039fa104dSReza Arbab * the kernel away from hotpluggable memory. 92139fa104dSReza Arbab */ 92239fa104dSReza Arbab if (movable_node_is_enabled()) 92339fa104dSReza Arbab memblock_set_bottom_up(true); 92439fa104dSReza Arbab #endif 92539fa104dSReza Arbab 9264b0f3b81SKees Cook x86_report_nx(); 9270ad5bce7SJeremy Fitzhardinge 92855f26239SYinghai Lu if (acpi_mps_check()) { 92955f26239SYinghai Lu #ifdef CONFIG_X86_LOCAL_APIC 93055f26239SYinghai Lu disable_apic = 1; 93155f26239SYinghai Lu #endif 932988781dcSYinghai Lu setup_clear_cpu_cap(X86_FEATURE_APIC); 93355f26239SYinghai Lu } 93455f26239SYinghai Lu 9351a127034SIngo Molnar e820__reserve_setup_data(); 9369641bdafSIngo Molnar e820__finish_early_params(); 93755f26239SYinghai Lu 93883e68189SMatt Fleming if (efi_enabled(EFI_BOOT)) 939ff0c0874SBrian Maly efi_init(); 940ff0c0874SBrian Maly 9410fca0812SRobert Richter dmi_setup(); 9422216d199SYinghai Lu 94388b094fbSAlok Kataria /* 94488b094fbSAlok Kataria * VMware detection requires dmi to be available, so this 9450fca0812SRobert Richter * needs to be done after dmi_setup(), for the boot CPU. 94688b094fbSAlok Kataria */ 9472d826404SThomas Gleixner init_hypervisor_platform(); 94888b094fbSAlok Kataria 949cf7a63efSPavel Tatashin tsc_early_init(); 950f7cf5a5bSThomas Gleixner x86_init.resources.probe_roms(); 95155f26239SYinghai Lu 9524046d6e8SLinus Torvalds /* after parse_early_param, so could debug it */ 9534046d6e8SLinus Torvalds insert_resource(&iomem_resource, &code_resource); 954a3299754SKees Cook insert_resource(&iomem_resource, &rodata_resource); 9554046d6e8SLinus Torvalds insert_resource(&iomem_resource, &data_resource); 9564046d6e8SLinus Torvalds insert_resource(&iomem_resource, &bss_resource); 9574046d6e8SLinus Torvalds 958b422a309SYinghai Lu e820_add_kernel_range(); 9591b5576e6SYinghai Lu trim_bios_range(); 96055f26239SYinghai Lu #ifdef CONFIG_X86_32 96155f26239SYinghai Lu if (ppro_with_ram_bug()) { 96209821ff1SIngo Molnar e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, 96309821ff1SIngo Molnar E820_TYPE_RESERVED); 964f9748fa0SIngo Molnar e820__update_table(e820_table); 96555f26239SYinghai Lu printk(KERN_INFO "fixed physical RAM map:\n"); 966be0c3f0fSIngo Molnar e820__print_table("bad_ppro"); 96755f26239SYinghai Lu } 96855f26239SYinghai Lu #else 96955f26239SYinghai Lu early_gart_iommu_check(); 97055f26239SYinghai Lu #endif 97155f26239SYinghai Lu 97255f26239SYinghai Lu /* 97355f26239SYinghai Lu * partially used pages are not usable - thus 97455f26239SYinghai Lu * we are rounding upwards: 97555f26239SYinghai Lu */ 9760c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 97755f26239SYinghai Lu 97855f26239SYinghai Lu /* update e820 for memory not covered by WB MTRRs */ 97955f26239SYinghai Lu mtrr_bp_init(); 9802dc807b3SYinghai Lu if (mtrr_trim_uncached_memory(max_pfn)) 9810c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 98255f26239SYinghai Lu 9838dd33030SIgor Mammedov max_possible_pfn = max_pfn; 9848dd33030SIgor Mammedov 985c7d2361fSThomas Garnier /* 98699c13b8cSMikulas Patocka * This call is required when the CPU does not support PAT. If 98799c13b8cSMikulas Patocka * mtrr_bp_init() invoked it already via pat_init() the call has no 98899c13b8cSMikulas Patocka * effect. 98999c13b8cSMikulas Patocka */ 99099c13b8cSMikulas Patocka init_cache_modes(); 99199c13b8cSMikulas Patocka 99299c13b8cSMikulas Patocka /* 993c7d2361fSThomas Garnier * Define random base addresses for memory sections after max_pfn is 994c7d2361fSThomas Garnier * defined and before each memory section base is used. 995c7d2361fSThomas Garnier */ 996c7d2361fSThomas Garnier kernel_randomize_memory(); 997c7d2361fSThomas Garnier 99855f26239SYinghai Lu #ifdef CONFIG_X86_32 99955f26239SYinghai Lu /* max_low_pfn get updated here */ 100055f26239SYinghai Lu find_low_pfn_range(); 100155f26239SYinghai Lu #else 10026e1cb38aSSuresh Siddha check_x2apic(); 100355f26239SYinghai Lu 100455f26239SYinghai Lu /* How many end-of-memory variables you have, grandma! */ 100555f26239SYinghai Lu /* need this before calling reserve_initrd */ 1006f361a450SYinghai Lu if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) 10070c6fc11aSIngo Molnar max_low_pfn = e820__end_of_low_ram_pfn(); 1008f361a450SYinghai Lu else 100955f26239SYinghai Lu max_low_pfn = max_pfn; 1010f361a450SYinghai Lu 101155f26239SYinghai Lu high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 101255f26239SYinghai Lu #endif 101355f26239SYinghai Lu 1014893f38d1SYinghai Lu /* 1015893f38d1SYinghai Lu * Find and reserve possible boot-time SMP configuration: 1016893f38d1SYinghai Lu */ 1017893f38d1SYinghai Lu find_smp_config(); 1018893f38d1SYinghai Lu 10198d57470dSYinghai Lu early_alloc_pgt_buf(); 10208d57470dSYinghai Lu 102172d7c3b3SYinghai Lu /* 10224918e228SIngo Molnar * Need to conclude brk, before e820__memblock_setup() 102372d7c3b3SYinghai Lu * it could use memblock_find_in_range, could overlap with 102472d7c3b3SYinghai Lu * brk area. 102572d7c3b3SYinghai Lu */ 102672d7c3b3SYinghai Lu reserve_brk(); 102772d7c3b3SYinghai Lu 1028e5f15b45SYinghai Lu cleanup_highmap(); 1029e5f15b45SYinghai Lu 10302449f343STang Chen memblock_set_current_limit(ISA_END_ADDRESS); 10314918e228SIngo Molnar e820__memblock_setup(); 103272d7c3b3SYinghai Lu 1033e998879dSAshish Kalra /* 1034e998879dSAshish Kalra * Needs to run after memblock setup because it needs the physical 1035e998879dSAshish Kalra * memory size. 1036e998879dSAshish Kalra */ 1037e998879dSAshish Kalra sev_setup_arch(); 1038e998879dSAshish Kalra 10394971531aSMatt Fleming efi_fake_memmap(); 10404971531aSMatt Fleming efi_find_mirror(); 10413dad6f7fSRicardo Neri efi_esrt_init(); 104258c90902SLenny Szubowicz efi_mokvar_table_init(); 10434971531aSMatt Fleming 1044916f676fSMatthew Garrett /* 10454971531aSMatt Fleming * The EFI specification says that boot service code won't be 10464971531aSMatt Fleming * called after ExitBootServices(). This is, in fact, a lie. 1047916f676fSMatthew Garrett */ 1048916f676fSMatthew Garrett efi_reserve_boot_services(); 1049916f676fSMatthew Garrett 105072d7c3b3SYinghai Lu /* preallocate 4k for mptable mpc */ 10515da217caSIngo Molnar e820__memblock_alloc_reserved_mpc_new(); 105272d7c3b3SYinghai Lu 105372d7c3b3SYinghai Lu #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 105472d7c3b3SYinghai Lu setup_bios_corruption_check(); 105572d7c3b3SYinghai Lu #endif 105672d7c3b3SYinghai Lu 105710054230SYinghai Lu #ifdef CONFIG_X86_32 1058365811d6SBjorn Helgaas printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", 1059365811d6SBjorn Helgaas (max_pfn_mapped<<PAGE_SHIFT) - 1); 106010054230SYinghai Lu #endif 106172d7c3b3SYinghai Lu 1062c361e5d4SMike Rapoport /* 1063*ec35d1d9SBorislav Petkov * Find free memory for the real mode trampoline and place it there. If 1064*ec35d1d9SBorislav Petkov * there is not enough free memory under 1M, on EFI-enabled systems 1065*ec35d1d9SBorislav Petkov * there will be additional attempt to reclaim the memory for the real 1066*ec35d1d9SBorislav Petkov * mode trampoline at efi_free_boot_services(). 1067f1d4d47cSMike Rapoport * 1068*ec35d1d9SBorislav Petkov * Unconditionally reserve the entire first 1M of RAM because BIOSes 1069*ec35d1d9SBorislav Petkov * are known to corrupt low memory and several hundred kilobytes are not 1070*ec35d1d9SBorislav Petkov * worth complex detection what memory gets clobbered. Windows does the 1071*ec35d1d9SBorislav Petkov * same thing for very similar reasons. 1072*ec35d1d9SBorislav Petkov * 1073*ec35d1d9SBorislav Petkov * Moreover, on machines with SandyBridge graphics or in setups that use 1074*ec35d1d9SBorislav Petkov * crashkernel the entire 1M is reserved anyway. 1075c361e5d4SMike Rapoport */ 1076f1d4d47cSMike Rapoport reserve_real_mode(); 1077a9acc536SJesse Barnes 107822ddfcaaSYinghai Lu init_mem_mapping(); 1079854c879fSPekka J Enberg 1080433f8924SThomas Gleixner idt_setup_early_pf(); 1081cda846f1SJarkko Sakkinen 108218bc7bd5SAndy Lutomirski /* 108318bc7bd5SAndy Lutomirski * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) 108418bc7bd5SAndy Lutomirski * with the current CR4 value. This may not be necessary, but 108518bc7bd5SAndy Lutomirski * auditing all the early-boot CR4 manipulation would be needed to 108618bc7bd5SAndy Lutomirski * rule it out. 1087c7ad5ad2SAndy Lutomirski * 1088c7ad5ad2SAndy Lutomirski * Mask off features that don't work outside long mode (just 1089c7ad5ad2SAndy Lutomirski * PCIDE for now). 109018bc7bd5SAndy Lutomirski */ 1091c7ad5ad2SAndy Lutomirski mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; 109218bc7bd5SAndy Lutomirski 10934ce7a869SYinghai Lu memblock_set_current_limit(get_max_mapped()); 1094e7b37895SYinghai Lu 1095e7b37895SYinghai Lu /* 1096e7b37895SYinghai Lu * NOTE: On x86-32, only from this point on, fixmaps are ready for use. 1097e7b37895SYinghai Lu */ 1098e7b37895SYinghai Lu 1099e7b37895SYinghai Lu #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 1100e7b37895SYinghai Lu if (init_ohci1394_dma_early) 1101162a7e75SMike Travis init_ohci1394_dma_on_all_controllers(); 1102162a7e75SMike Travis #endif 1103e7b37895SYinghai Lu /* Allocate bigger log buffer */ 110455f26239SYinghai Lu setup_log_buf(1); 110555f26239SYinghai Lu 11069661b332SDavid Howells if (efi_enabled(EFI_BOOT)) { 11079661b332SDavid Howells switch (boot_params.secure_boot) { 11089661b332SDavid Howells case efi_secureboot_mode_disabled: 11099661b332SDavid Howells pr_info("Secure boot disabled\n"); 11109661b332SDavid Howells break; 11119661b332SDavid Howells case efi_secureboot_mode_enabled: 11129661b332SDavid Howells pr_info("Secure boot enabled\n"); 11139661b332SDavid Howells break; 11149661b332SDavid Howells default: 11159661b332SDavid Howells pr_info("Secure boot could not be determined\n"); 11169661b332SDavid Howells break; 11179661b332SDavid Howells } 11189661b332SDavid Howells } 11199661b332SDavid Howells 112044280733SYinghai Lu reserve_initrd(); 112144280733SYinghai Lu 1122da3d3f98SAleksey Makarov acpi_table_upgrade(); 11236998a880SRafael J. Wysocki /* Look for ACPI tables and reserve memory occupied by them. */ 11246998a880SRafael J. Wysocki acpi_boot_table_init(); 112555f26239SYinghai Lu 112655f26239SYinghai Lu vsmp_init(); 112755f26239SYinghai Lu 112855f26239SYinghai Lu io_delay_init(); 112955f26239SYinghai Lu 1130630b3affSLukas Wunner early_platform_quirks(); 1131630b3affSLukas Wunner 113220e6926dSYinghai Lu early_acpi_boot_init(); 113320e6926dSYinghai Lu 113491467bdfSBernhard Walle initmem_init(); 11353c325f82SWeijie Yang dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); 1136fa591c4aSTang Chen 1137cf11e85fSRoman Gushchin if (boot_cpu_has(X86_FEATURE_GBPAGES)) 1138cf11e85fSRoman Gushchin hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); 1139cf11e85fSRoman Gushchin 1140fa591c4aSTang Chen /* 1141fa591c4aSTang Chen * Reserve memory for crash kernel after SRAT is parsed so that it 1142fa591c4aSTang Chen * won't consume hotpluggable memory. 1143fa591c4aSTang Chen */ 1144fa591c4aSTang Chen reserve_crashkernel(); 1145fa591c4aSTang Chen 114655f26239SYinghai Lu memblock_find_dma_reserve(); 114755f26239SYinghai Lu 1148ccb64941SBoris Ostrovsky if (!early_xdbc_setup_hardware()) 1149ccb64941SBoris Ostrovsky early_xdbc_register_console(); 1150ccb64941SBoris Ostrovsky 1151030cb6c0SThomas Gleixner x86_init.paging.pagetable_init(); 115255f26239SYinghai Lu 1153ef7f0d6aSAndrey Ryabinin kasan_init(); 1154ef7f0d6aSAndrey Ryabinin 1155d2b6dc61SAndy Lutomirski /* 1156945fd17aSThomas Gleixner * Sync back kernel address range. 1157945fd17aSThomas Gleixner * 1158945fd17aSThomas Gleixner * FIXME: Can the later sync in setup_cpu_entry_areas() replace 1159945fd17aSThomas Gleixner * this call? 1160d2b6dc61SAndy Lutomirski */ 1161945fd17aSThomas Gleixner sync_initial_page_table(); 1162d2b6dc61SAndy Lutomirski 116331625340SJoseph Cihula tboot_probe(); 116431625340SJoseph Cihula 116555f26239SYinghai Lu map_vsyscall(); 116655f26239SYinghai Lu 116755f26239SYinghai Lu generic_apic_probe(); 116855f26239SYinghai Lu 116955f26239SYinghai Lu early_quirks(); 117055f26239SYinghai Lu 117155f26239SYinghai Lu /* 117255f26239SYinghai Lu * Read APIC and some other early information from ACPI tables. 117355f26239SYinghai Lu */ 117455f26239SYinghai Lu acpi_boot_init(); 1175a906fdaaSThomas Gleixner x86_dtb_init(); 1176efafc8b2SFeng Tang 117755f26239SYinghai Lu /* 117855f26239SYinghai Lu * get boot-time SMP configuration: 117955f26239SYinghai Lu */ 118055f26239SYinghai Lu get_smp_config(); 118155f26239SYinghai Lu 11821e90a13dSThomas Gleixner /* 11831e90a13dSThomas Gleixner * Systems w/o ACPI and mptables might not have it mapped the local 11841e90a13dSThomas Gleixner * APIC yet, but prefill_possible_map() might need to access it. 11851e90a13dSThomas Gleixner */ 11861e90a13dSThomas Gleixner init_apic_mappings(); 11871e90a13dSThomas Gleixner 1188329513a3SYinghai Lu prefill_possible_map(); 1189301e6190SYinghai Lu 11905f4765f9SYinghai Lu init_cpu_to_node(); 119173bf7382SJonathan Cameron init_gi_nodes(); 11925f4765f9SYinghai Lu 1193ca1b8862SThomas Gleixner io_apic_init_mappings(); 11949d6a4d08SYinghai Lu 1195f3614646SJuergen Gross x86_init.hyper.guest_late_init(); 119655f26239SYinghai Lu 11971506c8dcSIngo Molnar e820__reserve_resources(); 1198cc55f753SZhimin Gu e820__register_nosave_regions(max_pfn); 119955f26239SYinghai Lu 12008fee697dSThomas Gleixner x86_init.resources.reserve_resources(); 120155f26239SYinghai Lu 12022df908baSIngo Molnar e820__setup_pci_gap(); 120355f26239SYinghai Lu 120455f26239SYinghai Lu #ifdef CONFIG_VT 120555f26239SYinghai Lu #if defined(CONFIG_VGA_CONSOLE) 120683e68189SMatt Fleming if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) 120755f26239SYinghai Lu conswitchp = &vga_con; 120855f26239SYinghai Lu #endif 120955f26239SYinghai Lu #endif 12106f30c1acSThomas Gleixner x86_init.oem.banner(); 1211a2202aa2SYong Wang 12126b617e22SFeng Tang x86_init.timers.wallclock_init(); 12136b617e22SFeng Tang 12149a90ed06SBorislav Petkov /* 12159a90ed06SBorislav Petkov * This needs to run before setup_local_APIC() which soft-disables the 12169a90ed06SBorislav Petkov * local APIC temporarily and that masks the thermal LVT interrupt, 12179a90ed06SBorislav Petkov * leading to softlockups on machines which have configured SMI 12189a90ed06SBorislav Petkov * interrupt delivery. 12199a90ed06SBorislav Petkov */ 12209a90ed06SBorislav Petkov therm_lvt_init(); 12219a90ed06SBorislav Petkov 1222a2202aa2SYong Wang mcheck_init(); 1223f49aa448SJason Baron 1224b3c869d3SJohn Stultz register_refined_jiffies(CLOCK_TICK_RATE); 12255189c2a7SOlof Johansson 12265189c2a7SOlof Johansson #ifdef CONFIG_EFI 1227a5d90c92SBorislav Petkov if (efi_enabled(EFI_BOOT)) 1228a5d90c92SBorislav Petkov efi_apply_memmap_quirks(); 12295189c2a7SOlof Johansson #endif 1230ee9f8fceSJosh Poimboeuf 1231ee9f8fceSJosh Poimboeuf unwind_init(); 123255f26239SYinghai Lu } 12335649b7c3SIngo Molnar 12349be1b56aSIngo Molnar #ifdef CONFIG_X86_32 12355649b7c3SIngo Molnar 12368fee697dSThomas Gleixner static struct resource video_ram_resource = { 12378fee697dSThomas Gleixner .name = "Video RAM area", 12388fee697dSThomas Gleixner .start = 0xa0000, 12398fee697dSThomas Gleixner .end = 0xbffff, 12408fee697dSThomas Gleixner .flags = IORESOURCE_BUSY | IORESOURCE_MEM 12419be1b56aSIngo Molnar }; 12429be1b56aSIngo Molnar 12438fee697dSThomas Gleixner void __init i386_reserve_resources(void) 12449be1b56aSIngo Molnar { 12458fee697dSThomas Gleixner request_resource(&iomem_resource, &video_ram_resource); 12468fee697dSThomas Gleixner reserve_standard_io_resources(); 12479be1b56aSIngo Molnar } 12489be1b56aSIngo Molnar 12499be1b56aSIngo Molnar #endif /* CONFIG_X86_32 */ 1250f32360efSKees Cook 1251f32360efSKees Cook static struct notifier_block kernel_offset_notifier = { 1252f32360efSKees Cook .notifier_call = dump_kernel_offset 1253f32360efSKees Cook }; 1254f32360efSKees Cook 1255f32360efSKees Cook static int __init register_kernel_offset_dumper(void) 1256f32360efSKees Cook { 1257f32360efSKees Cook atomic_notifier_chain_register(&panic_notifier_list, 1258f32360efSKees Cook &kernel_offset_notifier); 1259f32360efSKees Cook return 0; 1260f32360efSKees Cook } 1261f32360efSKees Cook __initcall(register_kernel_offset_dumper); 1262