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 */ 8ea7b4244SNathan Chancellor #include <linux/acpi.h> 955f26239SYinghai Lu #include <linux/console.h> 10*edf66a3cSRafael J. Wysocki #include <linux/cpu.h> 1112609013SIngo Molnar #include <linux/crash_dump.h> 120b1abd1fSChristoph Hellwig #include <linux/dma-map-ops.h> 1355f26239SYinghai Lu #include <linux/dmi.h> 1412609013SIngo Molnar #include <linux/efi.h> 15b69a2afdSJonathan McDowell #include <linux/ima.h> 1655f26239SYinghai Lu #include <linux/init_ohci1394_dma.h> 1712609013SIngo Molnar #include <linux/initrd.h> 1812609013SIngo Molnar #include <linux/iscsi_ibft.h> 1912609013SIngo Molnar #include <linux/memblock.h> 20f39650deSAndy Shevchenko #include <linux/panic_notifier.h> 2112609013SIngo Molnar #include <linux/pci.h> 2212609013SIngo Molnar #include <linux/root_dev.h> 23cf11e85fSRoman Gushchin #include <linux/hugetlb.h> 2412609013SIngo Molnar #include <linux/tboot.h> 2512609013SIngo Molnar #include <linux/usb/xhci-dbgp.h> 26a945c834SPeter Zijlstra #include <linux/static_call.h> 270a0f0d8bSChristoph Hellwig #include <linux/swiotlb.h> 2868b8e971SJason A. Donenfeld #include <linux/random.h> 2912609013SIngo Molnar 30e262e32dSDavid Howells #include <uapi/linux/mount.h> 3155f26239SYinghai Lu 3212609013SIngo Molnar #include <xen/xen.h> 3355f26239SYinghai Lu 3455f26239SYinghai Lu #include <asm/apic.h> 354059ba65SArd Biesheuvel #include <asm/efi.h> 3613c01139SIngo Molnar #include <asm/numa.h> 3755f26239SYinghai Lu #include <asm/bios_ebda.h> 3855f26239SYinghai Lu #include <asm/bugs.h> 390b9a6a8bSJuergen Gross #include <asm/cacheinfo.h> 406e5385d4SJaswinder Singh Rajput #include <asm/cpu.h> 4112609013SIngo Molnar #include <asm/efi.h> 421d9b16d1SJoerg Roedel #include <asm/gart.h> 4388b094fbSAlok Kataria #include <asm/hypervisor.h> 4412609013SIngo Molnar #include <asm/io_apic.h> 4512609013SIngo Molnar #include <asm/kasan.h> 460483e1faSThomas Garnier #include <asm/kaslr.h> 4712609013SIngo Molnar #include <asm/mce.h> 484d5cff69SChristoph Hellwig #include <asm/memtype.h> 4912609013SIngo Molnar #include <asm/mtrr.h> 50ca947b72SSean Christopherson #include <asm/realmode.h> 5112609013SIngo Molnar #include <asm/olpc_ofw.h> 5212609013SIngo Molnar #include <asm/pci-direct.h> 5312609013SIngo Molnar #include <asm/prom.h> 5412609013SIngo Molnar #include <asm/proto.h> 559a90ed06SBorislav Petkov #include <asm/thermal.h> 56ee9f8fceSJosh Poimboeuf #include <asm/unwind.h> 5712609013SIngo Molnar #include <asm/vsyscall.h> 58186525bdSIngo Molnar #include <linux/vmalloc.h> 5955f26239SYinghai Lu 602b72394eSPekka Enberg /* 61360db4acSIngo Molnar * max_low_pfn_mapped: highest directly mapped pfn < 4 GB 62360db4acSIngo Molnar * max_pfn_mapped: highest directly mapped pfn > 4 GB 6366520ebcSJacob Shin * 6409821ff1SIngo Molnar * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are 65360db4acSIngo Molnar * represented by pfn_mapped[]. 662b72394eSPekka Enberg */ 672b72394eSPekka Enberg unsigned long max_low_pfn_mapped; 682b72394eSPekka Enberg unsigned long max_pfn_mapped; 692b72394eSPekka Enberg 70e808bae2SThadeu Lima de Souza Cascardo #ifdef CONFIG_DMI 71796216a5SJeremy Fitzhardinge RESERVE_BRK(dmi_alloc, 65536); 72e808bae2SThadeu Lima de Souza Cascardo #endif 73796216a5SJeremy Fitzhardinge 74c0b5842aSIngo Molnar 75360db4acSIngo Molnar unsigned long _brk_start = (unsigned long)__brk_base; 7693dbda7cSJeremy Fitzhardinge unsigned long _brk_end = (unsigned long)__brk_base; 7793dbda7cSJeremy Fitzhardinge 78217b8ce8SYinghai Lu struct boot_params boot_params; 79217b8ce8SYinghai Lu 804046d6e8SLinus Torvalds /* 81360db4acSIngo Molnar * These are the four main kernel memory regions, we put them into 82360db4acSIngo Molnar * the resource tree so that kdump tools and other debugging tools 83360db4acSIngo Molnar * recover it: 844046d6e8SLinus Torvalds */ 85360db4acSIngo Molnar 86a3299754SKees Cook static struct resource rodata_resource = { 87a3299754SKees Cook .name = "Kernel rodata", 88a3299754SKees Cook .start = 0, 89a3299754SKees Cook .end = 0, 90a3299754SKees Cook .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 91a3299754SKees Cook }; 92a3299754SKees Cook 934046d6e8SLinus Torvalds static struct resource data_resource = { 944046d6e8SLinus Torvalds .name = "Kernel data", 954046d6e8SLinus Torvalds .start = 0, 964046d6e8SLinus Torvalds .end = 0, 974046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 984046d6e8SLinus Torvalds }; 994046d6e8SLinus Torvalds 1004046d6e8SLinus Torvalds static struct resource code_resource = { 1014046d6e8SLinus Torvalds .name = "Kernel code", 1024046d6e8SLinus Torvalds .start = 0, 1034046d6e8SLinus Torvalds .end = 0, 1044046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1054046d6e8SLinus Torvalds }; 1064046d6e8SLinus Torvalds 1074046d6e8SLinus Torvalds static struct resource bss_resource = { 1084046d6e8SLinus Torvalds .name = "Kernel bss", 1094046d6e8SLinus Torvalds .start = 0, 1104046d6e8SLinus Torvalds .end = 0, 1114046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1124046d6e8SLinus Torvalds }; 1134046d6e8SLinus Torvalds 1144046d6e8SLinus Torvalds 11555f26239SYinghai Lu #ifdef CONFIG_X86_32 116360db4acSIngo Molnar /* CPU data as detected by the assembly code in head_32.S */ 1176415813bSMathias Krause struct cpuinfo_x86 new_cpu_data; 11855f26239SYinghai Lu 11955f26239SYinghai Lu struct apm_info apm_info; 12055f26239SYinghai Lu EXPORT_SYMBOL(apm_info); 12155f26239SYinghai Lu 12255f26239SYinghai Lu #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ 12355f26239SYinghai Lu defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) 12455f26239SYinghai Lu struct ist_info ist_info; 12555f26239SYinghai Lu EXPORT_SYMBOL(ist_info); 12655f26239SYinghai Lu #else 12755f26239SYinghai Lu struct ist_info ist_info; 12855f26239SYinghai Lu #endif 12955f26239SYinghai Lu 13055f26239SYinghai Lu #endif 13155f26239SYinghai Lu 13250c66d7bSYuntao Wang struct cpuinfo_x86 boot_cpu_data __read_mostly; 13350c66d7bSYuntao Wang EXPORT_SYMBOL(boot_cpu_data); 13455f26239SYinghai Lu 13555f26239SYinghai Lu #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64) 136404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init; 13755f26239SYinghai Lu #else 138404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; 13955f26239SYinghai Lu #endif 14055f26239SYinghai Lu 141b69a2afdSJonathan McDowell #ifdef CONFIG_IMA 142b69a2afdSJonathan McDowell static phys_addr_t ima_kexec_buffer_phys; 143b69a2afdSJonathan McDowell static size_t ima_kexec_buffer_size; 144b69a2afdSJonathan McDowell #endif 145b69a2afdSJonathan McDowell 1465031296cSH. Peter Anvin /* Boot loader ID and version as integers, for the benefit of proc_dointvec */ 1475031296cSH. Peter Anvin int bootloader_type, bootloader_version; 14855f26239SYinghai Lu 14955f26239SYinghai Lu /* 15055f26239SYinghai Lu * Setup options 15155f26239SYinghai Lu */ 15255f26239SYinghai Lu struct screen_info screen_info; 15355f26239SYinghai Lu EXPORT_SYMBOL(screen_info); 15455f26239SYinghai Lu struct edid_info edid_info; 15555f26239SYinghai Lu EXPORT_SYMBOL_GPL(edid_info); 15655f26239SYinghai Lu 15755f26239SYinghai Lu extern int root_mountflags; 15855f26239SYinghai Lu 15955f26239SYinghai Lu unsigned long saved_video_mode; 16055f26239SYinghai Lu 16155f26239SYinghai Lu #define RAMDISK_IMAGE_START_MASK 0x07FF 16255f26239SYinghai Lu #define RAMDISK_PROMPT_FLAG 0x8000 16355f26239SYinghai Lu #define RAMDISK_LOAD_FLAG 0x4000 16455f26239SYinghai Lu 16555f26239SYinghai Lu static char __initdata command_line[COMMAND_LINE_SIZE]; 166516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 167516cbf37STim Bird static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; 168516cbf37STim Bird #endif 16955f26239SYinghai Lu 17055f26239SYinghai Lu #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) 17155f26239SYinghai Lu struct edd edd; 17255f26239SYinghai Lu #ifdef CONFIG_EDD_MODULE 17355f26239SYinghai Lu EXPORT_SYMBOL(edd); 17455f26239SYinghai Lu #endif 17555f26239SYinghai Lu /** 17655f26239SYinghai Lu * copy_edd() - Copy the BIOS EDD information 17755f26239SYinghai Lu * from boot_params into a safe place. 17855f26239SYinghai Lu * 17955f26239SYinghai Lu */ 1809eaa192dSHelight.Xu static inline void __init copy_edd(void) 18155f26239SYinghai Lu { 18255f26239SYinghai Lu memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, 18355f26239SYinghai Lu sizeof(edd.mbr_signature)); 18455f26239SYinghai Lu memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); 18555f26239SYinghai Lu edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; 18655f26239SYinghai Lu edd.edd_info_nr = boot_params.eddbuf_entries; 18755f26239SYinghai Lu } 18855f26239SYinghai Lu #else 1899eaa192dSHelight.Xu static inline void __init copy_edd(void) 19055f26239SYinghai Lu { 19155f26239SYinghai Lu } 19255f26239SYinghai Lu #endif 19355f26239SYinghai Lu 1945368a2beSH. Peter Anvin void * __init extend_brk(size_t size, size_t align) 1955368a2beSH. Peter Anvin { 1965368a2beSH. Peter Anvin size_t mask = align - 1; 1975368a2beSH. Peter Anvin void *ret; 1985368a2beSH. Peter Anvin 1995368a2beSH. Peter Anvin BUG_ON(_brk_start == 0); 2005368a2beSH. Peter Anvin BUG_ON(align & mask); 2015368a2beSH. Peter Anvin 2025368a2beSH. Peter Anvin _brk_end = (_brk_end + mask) & ~mask; 2035368a2beSH. Peter Anvin BUG_ON((char *)(_brk_end + size) > __brk_limit); 2045368a2beSH. Peter Anvin 2055368a2beSH. Peter Anvin ret = (void *)_brk_end; 2065368a2beSH. Peter Anvin _brk_end += size; 2075368a2beSH. Peter Anvin 2085368a2beSH. Peter Anvin memset(ret, 0, size); 2095368a2beSH. Peter Anvin 2105368a2beSH. Peter Anvin return ret; 2115368a2beSH. Peter Anvin } 2125368a2beSH. Peter Anvin 213148b2098SYinghai Lu #ifdef CONFIG_X86_32 214e5f15b45SYinghai Lu static void __init cleanup_highmap(void) 215f005fe12SYinghai Lu { 216f005fe12SYinghai Lu } 217854c879fSPekka J Enberg #endif 218854c879fSPekka J Enberg 2195368a2beSH. Peter Anvin static void __init reserve_brk(void) 2205368a2beSH. Peter Anvin { 2215368a2beSH. Peter Anvin if (_brk_end > _brk_start) 222fc8d7826SAlexander Duyck memblock_reserve(__pa_symbol(_brk_start), 223fc8d7826SAlexander Duyck _brk_end - _brk_start); 2245368a2beSH. Peter Anvin 2255368a2beSH. Peter Anvin /* Mark brk area as locked down and no longer taking any 2265368a2beSH. Peter Anvin new allocations */ 2275368a2beSH. Peter Anvin _brk_start = 0; 2285368a2beSH. Peter Anvin } 2295368a2beSH. Peter Anvin 23055f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_INITRD 23155f26239SYinghai Lu 232a8a51a88SYinghai Lu static u64 __init get_ramdisk_image(void) 233a8a51a88SYinghai Lu { 234a8a51a88SYinghai Lu u64 ramdisk_image = boot_params.hdr.ramdisk_image; 235a8a51a88SYinghai Lu 236ee92d815SYinghai Lu ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; 237ee92d815SYinghai Lu 238694cfd87SRonald G. Minnich if (ramdisk_image == 0) 239694cfd87SRonald G. Minnich ramdisk_image = phys_initrd_start; 240694cfd87SRonald G. Minnich 241a8a51a88SYinghai Lu return ramdisk_image; 242a8a51a88SYinghai Lu } 243a8a51a88SYinghai Lu static u64 __init get_ramdisk_size(void) 244a8a51a88SYinghai Lu { 245a8a51a88SYinghai Lu u64 ramdisk_size = boot_params.hdr.ramdisk_size; 246a8a51a88SYinghai Lu 247ee92d815SYinghai Lu ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; 248ee92d815SYinghai Lu 249694cfd87SRonald G. Minnich if (ramdisk_size == 0) 250694cfd87SRonald G. Minnich ramdisk_size = phys_initrd_size; 251694cfd87SRonald G. Minnich 252a8a51a88SYinghai Lu return ramdisk_size; 253a8a51a88SYinghai Lu } 254a8a51a88SYinghai Lu 25555f26239SYinghai Lu static void __init relocate_initrd(void) 25655f26239SYinghai Lu { 257c967da6aSYinghai Lu /* Assume only end is not page aligned */ 258a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 259a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 260c967da6aSYinghai Lu u64 area_size = PAGE_ALIGN(ramdisk_size); 26155f26239SYinghai Lu 262e8c57d40SYinghai Lu /* We need to move the initrd down into directly mapped mem */ 263f7a25cf1SYuntao Wang u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0, 2643c45ee6dSMike Rapoport PFN_PHYS(max_pfn_mapped)); 2655aa3d718SBorislav Petkov if (!relocated_ramdisk) 26655f26239SYinghai Lu panic("Cannot find place for new RAMDISK of size %lld\n", 26755f26239SYinghai Lu ramdisk_size); 26855f26239SYinghai Lu 2695aa3d718SBorislav Petkov initrd_start = relocated_ramdisk + PAGE_OFFSET; 27055f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 271365811d6SBjorn Helgaas printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", 2725aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 27355f26239SYinghai Lu 2745dd2c4bdSMark Salter copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size); 27555f26239SYinghai Lu 276365811d6SBjorn Helgaas printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to" 277365811d6SBjorn Helgaas " [mem %#010llx-%#010llx]\n", 27855f26239SYinghai Lu ramdisk_image, ramdisk_image + ramdisk_size - 1, 2795aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 28055f26239SYinghai Lu } 28155f26239SYinghai Lu 2821b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 2831b8c78beSYinghai Lu { 2841b8c78beSYinghai Lu /* Assume only end is not page aligned */ 285a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 286a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 2871b8c78beSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 2881b8c78beSYinghai Lu 2891b8c78beSYinghai Lu if (!boot_params.hdr.type_of_loader || 2901b8c78beSYinghai Lu !ramdisk_image || !ramdisk_size) 2911b8c78beSYinghai Lu return; /* No initrd provided by bootloader */ 2921b8c78beSYinghai Lu 2931b8c78beSYinghai Lu memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); 2941b8c78beSYinghai Lu } 2953c45ee6dSMike Rapoport 29655f26239SYinghai Lu static void __init reserve_initrd(void) 29755f26239SYinghai Lu { 298c967da6aSYinghai Lu /* Assume only end is not page aligned */ 299a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 300a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 301c967da6aSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 30255f26239SYinghai Lu 30355f26239SYinghai Lu if (!boot_params.hdr.type_of_loader || 30455f26239SYinghai Lu !ramdisk_image || !ramdisk_size) 30555f26239SYinghai Lu return; /* No initrd provided by bootloader */ 30655f26239SYinghai Lu 30755f26239SYinghai Lu initrd_start = 0; 30855f26239SYinghai Lu 309365811d6SBjorn Helgaas printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, 310365811d6SBjorn Helgaas ramdisk_end - 1); 31155f26239SYinghai Lu 31274f27655SYinghai Lu if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image), 313e8c57d40SYinghai Lu PFN_DOWN(ramdisk_end))) { 314e8c57d40SYinghai Lu /* All are mapped, easy case */ 31555f26239SYinghai Lu initrd_start = ramdisk_image + PAGE_OFFSET; 31655f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 31755f26239SYinghai Lu return; 31855f26239SYinghai Lu } 31955f26239SYinghai Lu 32055f26239SYinghai Lu relocate_initrd(); 3218c5dd8f4SYinghai Lu 3223ecc6834SMike Rapoport memblock_phys_free(ramdisk_image, ramdisk_end - ramdisk_image); 32355f26239SYinghai Lu } 324af06f8b7SLv Zheng 32555f26239SYinghai Lu #else 3261b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3271b8c78beSYinghai Lu { 3281b8c78beSYinghai Lu } 32955f26239SYinghai Lu static void __init reserve_initrd(void) 33055f26239SYinghai Lu { 33155f26239SYinghai Lu } 33255f26239SYinghai Lu #endif /* CONFIG_BLK_DEV_INITRD */ 33355f26239SYinghai Lu 334b69a2afdSJonathan McDowell static void __init add_early_ima_buffer(u64 phys_addr) 335b69a2afdSJonathan McDowell { 336b69a2afdSJonathan McDowell #ifdef CONFIG_IMA 337b69a2afdSJonathan McDowell struct ima_setup_data *data; 338b69a2afdSJonathan McDowell 339b69a2afdSJonathan McDowell data = early_memremap(phys_addr + sizeof(struct setup_data), sizeof(*data)); 340b69a2afdSJonathan McDowell if (!data) { 341b69a2afdSJonathan McDowell pr_warn("setup: failed to memremap ima_setup_data entry\n"); 342b69a2afdSJonathan McDowell return; 343b69a2afdSJonathan McDowell } 344b69a2afdSJonathan McDowell 345b69a2afdSJonathan McDowell if (data->size) { 346b69a2afdSJonathan McDowell memblock_reserve(data->addr, data->size); 347b69a2afdSJonathan McDowell ima_kexec_buffer_phys = data->addr; 348b69a2afdSJonathan McDowell ima_kexec_buffer_size = data->size; 349b69a2afdSJonathan McDowell } 350b69a2afdSJonathan McDowell 351b69a2afdSJonathan McDowell early_memunmap(data, sizeof(*data)); 352b69a2afdSJonathan McDowell #else 353b69a2afdSJonathan McDowell pr_warn("Passed IMA kexec data, but CONFIG_IMA not set. Ignoring.\n"); 354b69a2afdSJonathan McDowell #endif 355b69a2afdSJonathan McDowell } 356b69a2afdSJonathan McDowell 357b69a2afdSJonathan McDowell #if defined(CONFIG_HAVE_IMA_KEXEC) && !defined(CONFIG_OF_FLATTREE) 358b69a2afdSJonathan McDowell int __init ima_free_kexec_buffer(void) 359b69a2afdSJonathan McDowell { 360b69a2afdSJonathan McDowell if (!ima_kexec_buffer_size) 361b69a2afdSJonathan McDowell return -ENOENT; 362b69a2afdSJonathan McDowell 36334cf99c2SRik van Riel memblock_free_late(ima_kexec_buffer_phys, 364b69a2afdSJonathan McDowell ima_kexec_buffer_size); 365b69a2afdSJonathan McDowell 366b69a2afdSJonathan McDowell ima_kexec_buffer_phys = 0; 367b69a2afdSJonathan McDowell ima_kexec_buffer_size = 0; 368b69a2afdSJonathan McDowell 369b69a2afdSJonathan McDowell return 0; 370b69a2afdSJonathan McDowell } 371b69a2afdSJonathan McDowell 372b69a2afdSJonathan McDowell int __init ima_get_kexec_buffer(void **addr, size_t *size) 373b69a2afdSJonathan McDowell { 374b69a2afdSJonathan McDowell if (!ima_kexec_buffer_size) 375b69a2afdSJonathan McDowell return -ENOENT; 376b69a2afdSJonathan McDowell 377b69a2afdSJonathan McDowell *addr = __va(ima_kexec_buffer_phys); 378b69a2afdSJonathan McDowell *size = ima_kexec_buffer_size; 379b69a2afdSJonathan McDowell 380b69a2afdSJonathan McDowell return 0; 381b69a2afdSJonathan McDowell } 382b69a2afdSJonathan McDowell #endif 383b69a2afdSJonathan McDowell 38429f784e3SYinghai Lu static void __init parse_setup_data(void) 385257b0fdeSYinghai Lu { 386257b0fdeSYinghai Lu struct setup_data *data; 38730e46b57SLinn Crosetto u64 pa_data, pa_next; 388257b0fdeSYinghai Lu 389257b0fdeSYinghai Lu pa_data = boot_params.hdr.setup_data; 390257b0fdeSYinghai Lu while (pa_data) { 3917389882cSWANG Chao u32 data_len, data_type; 392f1c2b357SSebastian Andrzej Siewior 3937389882cSWANG Chao data = early_memremap(pa_data, sizeof(*data)); 394f1c2b357SSebastian Andrzej Siewior data_len = data->len + sizeof(struct setup_data); 39530e46b57SLinn Crosetto data_type = data->type; 39630e46b57SLinn Crosetto pa_next = data->next; 3978d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 398f1c2b357SSebastian Andrzej Siewior 39930e46b57SLinn Crosetto switch (data_type) { 400257b0fdeSYinghai Lu case SETUP_E820_EXT: 401914053c0SIngo Molnar e820__memory_setup_extended(pa_data, data_len); 402257b0fdeSYinghai Lu break; 403da6b737bSSebastian Andrzej Siewior case SETUP_DTB: 404da6b737bSSebastian Andrzej Siewior add_dtb(pa_data); 405257b0fdeSYinghai Lu break; 4061fec0533SDave Young case SETUP_EFI: 4071fec0533SDave Young parse_efi_setup(pa_data, data_len); 4081fec0533SDave Young break; 409b69a2afdSJonathan McDowell case SETUP_IMA: 410b69a2afdSJonathan McDowell add_early_ima_buffer(pa_data); 411b69a2afdSJonathan McDowell break; 41268b8e971SJason A. Donenfeld case SETUP_RNG_SEED: 41368b8e971SJason A. Donenfeld data = early_memremap(pa_data, data_len); 41468b8e971SJason A. Donenfeld add_bootloader_randomness(data->data, data->len); 41568b8e971SJason A. Donenfeld /* Zero seed for forward secrecy. */ 41668b8e971SJason A. Donenfeld memzero_explicit(data->data, data->len); 41768b8e971SJason A. Donenfeld /* Zero length in case we find ourselves back here by accident. */ 41868b8e971SJason A. Donenfeld memzero_explicit(&data->len, sizeof(data->len)); 41968b8e971SJason A. Donenfeld early_memunmap(data, data_len); 42068b8e971SJason A. Donenfeld break; 421257b0fdeSYinghai Lu default: 422257b0fdeSYinghai Lu break; 423257b0fdeSYinghai Lu } 42430e46b57SLinn Crosetto pa_data = pa_next; 425257b0fdeSYinghai Lu } 426257b0fdeSYinghai Lu } 427257b0fdeSYinghai Lu 428a9ce6bc1SYinghai Lu static void __init memblock_x86_reserve_range_setup_data(void) 429a0a0becdSYinghai Lu { 4307228918bSRoss Philipson struct setup_indirect *indirect; 431a0a0becdSYinghai Lu struct setup_data *data; 4327228918bSRoss Philipson u64 pa_data, pa_next; 4337228918bSRoss Philipson u32 len; 434a0a0becdSYinghai Lu 435a0a0becdSYinghai Lu pa_data = boot_params.hdr.setup_data; 436a0a0becdSYinghai Lu while (pa_data) { 43788b4c146SJeremy Fitzhardinge data = early_memremap(pa_data, sizeof(*data)); 4387228918bSRoss Philipson if (!data) { 4397228918bSRoss Philipson pr_warn("setup: failed to memremap setup_data entry\n"); 4407228918bSRoss Philipson return; 4417228918bSRoss Philipson } 4427228918bSRoss Philipson 4437228918bSRoss Philipson len = sizeof(*data); 4447228918bSRoss Philipson pa_next = data->next; 4457228918bSRoss Philipson 44624aa0788STejun Heo memblock_reserve(pa_data, sizeof(*data) + data->len); 447b3c72fc9SDaniel Kiper 4487228918bSRoss Philipson if (data->type == SETUP_INDIRECT) { 4497228918bSRoss Philipson len += data->len; 4508d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 4517228918bSRoss Philipson data = early_memremap(pa_data, len); 4527228918bSRoss Philipson if (!data) { 4537228918bSRoss Philipson pr_warn("setup: failed to memremap indirect setup_data\n"); 4547228918bSRoss Philipson return; 4557228918bSRoss Philipson } 4567228918bSRoss Philipson 4577228918bSRoss Philipson indirect = (struct setup_indirect *)data->data; 4587228918bSRoss Philipson 4597228918bSRoss Philipson if (indirect->type != SETUP_INDIRECT) 4607228918bSRoss Philipson memblock_reserve(indirect->addr, indirect->len); 4617228918bSRoss Philipson } 4627228918bSRoss Philipson 4637228918bSRoss Philipson pa_data = pa_next; 4647228918bSRoss Philipson early_memunmap(data, len); 465a0a0becdSYinghai Lu } 466a0a0becdSYinghai Lu } 467a0a0becdSYinghai Lu 4689c08a2a1SBaoquan He static void __init arch_reserve_crashkernel(void) 4690212f915SYinghai Lu { 4709c08a2a1SBaoquan He unsigned long long crash_base, crash_size, low_size = 0; 4719c08a2a1SBaoquan He char *cmdline = boot_command_line; 47255a20ee7SYinghai Lu bool high = false; 473ccb4defaSYinghai Lu int ret; 474ccb4defaSYinghai Lu 475a4eeb217SBaoquan He if (!IS_ENABLED(CONFIG_CRASH_RESERVE)) 4764ece09beSJisheng Zhang return; 4774ece09beSJisheng Zhang 4789c08a2a1SBaoquan He ret = parse_crashkernel(cmdline, memblock_phys_mem_size(), 4799c08a2a1SBaoquan He &crash_size, &crash_base, 4809c08a2a1SBaoquan He &low_size, &high); 4819c08a2a1SBaoquan He if (ret) 48232105f7fSBernhard Walle return; 48332105f7fSBernhard Walle 4843db3eb28SPetr Tesarik if (xen_pv_domain()) { 4853db3eb28SPetr Tesarik pr_info("Ignoring crashkernel for a Xen PV domain\n"); 4863db3eb28SPetr Tesarik return; 4873db3eb28SPetr Tesarik } 4883db3eb28SPetr Tesarik 4899c08a2a1SBaoquan He reserve_crashkernel_generic(cmdline, crash_size, crash_base, 4909c08a2a1SBaoquan He low_size, high); 491ccb4defaSYinghai Lu } 492ccb4defaSYinghai Lu 493bdba0e70SYinghai Lu static struct resource standard_io_resources[] = { 494bdba0e70SYinghai Lu { .name = "dma1", .start = 0x00, .end = 0x1f, 495bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 496bdba0e70SYinghai Lu { .name = "pic1", .start = 0x20, .end = 0x21, 497bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 498bdba0e70SYinghai Lu { .name = "timer0", .start = 0x40, .end = 0x43, 499bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 500bdba0e70SYinghai Lu { .name = "timer1", .start = 0x50, .end = 0x53, 501bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 502bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x60, .end = 0x60, 503bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 504bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x64, .end = 0x64, 505bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 506bdba0e70SYinghai Lu { .name = "dma page reg", .start = 0x80, .end = 0x8f, 507bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 508bdba0e70SYinghai Lu { .name = "pic2", .start = 0xa0, .end = 0xa1, 509bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 510bdba0e70SYinghai Lu { .name = "dma2", .start = 0xc0, .end = 0xdf, 511bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 512bdba0e70SYinghai Lu { .name = "fpu", .start = 0xf0, .end = 0xff, 513bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO } 514bdba0e70SYinghai Lu }; 515bdba0e70SYinghai Lu 5168fee697dSThomas Gleixner void __init reserve_standard_io_resources(void) 517bdba0e70SYinghai Lu { 518bdba0e70SYinghai Lu int i; 519bdba0e70SYinghai Lu 520bdba0e70SYinghai Lu /* request I/O space for devices used on all i[345]86 PCs */ 521bdba0e70SYinghai Lu for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) 522bdba0e70SYinghai Lu request_resource(&ioport_resource, &standard_io_resources[i]); 523bdba0e70SYinghai Lu 524bdba0e70SYinghai Lu } 525bdba0e70SYinghai Lu 526a9acc536SJesse Barnes static bool __init snb_gfx_workaround_needed(void) 527a9acc536SJesse Barnes { 528e43b3cecSH. Peter Anvin #ifdef CONFIG_PCI 529a9acc536SJesse Barnes int i; 530a9acc536SJesse Barnes u16 vendor, devid; 531ab3cd867SH. Peter Anvin static const __initconst u16 snb_ids[] = { 532a9acc536SJesse Barnes 0x0102, 533a9acc536SJesse Barnes 0x0112, 534a9acc536SJesse Barnes 0x0122, 535a9acc536SJesse Barnes 0x0106, 536a9acc536SJesse Barnes 0x0116, 537a9acc536SJesse Barnes 0x0126, 538a9acc536SJesse Barnes 0x010a, 539a9acc536SJesse Barnes }; 540a9acc536SJesse Barnes 541a9acc536SJesse Barnes /* Assume no if something weird is going on with PCI */ 542a9acc536SJesse Barnes if (!early_pci_allowed()) 543a9acc536SJesse Barnes return false; 544a9acc536SJesse Barnes 545a9acc536SJesse Barnes vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); 546a9acc536SJesse Barnes if (vendor != 0x8086) 547a9acc536SJesse Barnes return false; 548a9acc536SJesse Barnes 549a9acc536SJesse Barnes devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); 550a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(snb_ids); i++) 551a9acc536SJesse Barnes if (devid == snb_ids[i]) 552a9acc536SJesse Barnes return true; 553e43b3cecSH. Peter Anvin #endif 554a9acc536SJesse Barnes 555a9acc536SJesse Barnes return false; 556a9acc536SJesse Barnes } 557a9acc536SJesse Barnes 558a9acc536SJesse Barnes /* 559a9acc536SJesse Barnes * Sandy Bridge graphics has trouble with certain ranges, exclude 560a9acc536SJesse Barnes * them from allocation. 561a9acc536SJesse Barnes */ 562a9acc536SJesse Barnes static void __init trim_snb_memory(void) 563a9acc536SJesse Barnes { 564ab3cd867SH. Peter Anvin static const __initconst unsigned long bad_pages[] = { 565a9acc536SJesse Barnes 0x20050000, 566a9acc536SJesse Barnes 0x20110000, 567a9acc536SJesse Barnes 0x20130000, 568a9acc536SJesse Barnes 0x20138000, 569a9acc536SJesse Barnes 0x40004000, 570a9acc536SJesse Barnes }; 571a9acc536SJesse Barnes int i; 572a9acc536SJesse Barnes 573a9acc536SJesse Barnes if (!snb_gfx_workaround_needed()) 574a9acc536SJesse Barnes return; 575a9acc536SJesse Barnes 576a9acc536SJesse Barnes printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); 577a9acc536SJesse Barnes 578a9acc536SJesse Barnes /* 579c361e5d4SMike Rapoport * SandyBridge integrated graphics devices have a bug that prevents 580c361e5d4SMike Rapoport * them from accessing certain memory ranges, namely anything below 581c361e5d4SMike Rapoport * 1M and in the pages listed in bad_pages[] above. 582c361e5d4SMike Rapoport * 583f1d4d47cSMike Rapoport * To avoid these pages being ever accessed by SNB gfx devices reserve 584f1d4d47cSMike Rapoport * bad_pages that have not already been reserved at boot time. 585f1d4d47cSMike Rapoport * All memory below the 1 MB mark is anyway reserved later during 586f1d4d47cSMike Rapoport * setup_arch(), so there is no need to reserve it here. 587a9acc536SJesse Barnes */ 588a9acc536SJesse Barnes 589a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { 590a9acc536SJesse Barnes if (memblock_reserve(bad_pages[i], PAGE_SIZE)) 591a9acc536SJesse Barnes printk(KERN_WARNING "failed to reserve 0x%08lx\n", 592a9acc536SJesse Barnes bad_pages[i]); 593a9acc536SJesse Barnes } 594a9acc536SJesse Barnes } 595a9acc536SJesse Barnes 5961b5576e6SYinghai Lu static void __init trim_bios_range(void) 5971b5576e6SYinghai Lu { 5981b5576e6SYinghai Lu /* 5995c279c4cSMike Rapoport * A special case is the first 4Kb of memory; 6005c279c4cSMike Rapoport * This is a BIOS owned area, not kernel ram, but generally 6015c279c4cSMike Rapoport * not listed as such in the E820 table. 6025c279c4cSMike Rapoport * 6035c279c4cSMike Rapoport * This typically reserves additional memory (64KiB by default) 6045c279c4cSMike Rapoport * since some BIOSes are known to corrupt low memory. See the 6055c279c4cSMike Rapoport * Kconfig help text for X86_RESERVE_LOW. 6065c279c4cSMike Rapoport */ 6075c279c4cSMike Rapoport e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); 6085c279c4cSMike Rapoport 6095c279c4cSMike Rapoport /* 61011a98f37SCao jin * special case: Some BIOSes report the PC BIOS 61111a98f37SCao jin * area (640Kb -> 1Mb) as RAM even though it is not. 6121b5576e6SYinghai Lu * take them out. 6131b5576e6SYinghai Lu */ 61409821ff1SIngo Molnar e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); 615a9acc536SJesse Barnes 616f9748fa0SIngo Molnar e820__update_table(e820_table); 6171b5576e6SYinghai Lu } 6181b5576e6SYinghai Lu 619b422a309SYinghai Lu /* called before trim_bios_range() to spare extra sanitize */ 620b422a309SYinghai Lu static void __init e820_add_kernel_range(void) 621b422a309SYinghai Lu { 622b422a309SYinghai Lu u64 start = __pa_symbol(_text); 623b422a309SYinghai Lu u64 size = __pa_symbol(_end) - start; 624b422a309SYinghai Lu 625b422a309SYinghai Lu /* 62609821ff1SIngo Molnar * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and 627b422a309SYinghai Lu * attempt to fix it by adding the range. We may have a confused BIOS, 628b422a309SYinghai Lu * or the user may have used memmap=exactmap or memmap=xxM$yyM to 629b422a309SYinghai Lu * exclude kernel range. If we really are running on top non-RAM, 630b422a309SYinghai Lu * we will crash later anyways. 631b422a309SYinghai Lu */ 63209821ff1SIngo Molnar if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) 633b422a309SYinghai Lu return; 634b422a309SYinghai Lu 63509821ff1SIngo Molnar pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); 63609821ff1SIngo Molnar e820__range_remove(start, size, E820_TYPE_RAM, 0); 63709821ff1SIngo Molnar e820__range_add(start, size, E820_TYPE_RAM); 638b422a309SYinghai Lu } 639b422a309SYinghai Lu 640a799c2bdSMike Rapoport static void __init early_reserve_memory(void) 64195c96084SH. Peter Anvin { 642a799c2bdSMike Rapoport /* 643a799c2bdSMike Rapoport * Reserve the memory occupied by the kernel between _text and 644a799c2bdSMike Rapoport * __end_of_kernel_reserve symbols. Any kernel sections after the 645a799c2bdSMike Rapoport * __end_of_kernel_reserve symbol must be explicitly reserved with a 646a799c2bdSMike Rapoport * separate memblock_reserve() or they will be discarded. 647a799c2bdSMike Rapoport */ 648a799c2bdSMike Rapoport memblock_reserve(__pa_symbol(_text), 649a799c2bdSMike Rapoport (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); 650a799c2bdSMike Rapoport 651a799c2bdSMike Rapoport /* 6524c674481SMike Rapoport * The first 4Kb of memory is a BIOS owned area, but generally it is 6534c674481SMike Rapoport * not listed as such in the E820 table. 6544c674481SMike Rapoport * 655f1d4d47cSMike Rapoport * Reserve the first 64K of memory since some BIOSes are known to 656f1d4d47cSMike Rapoport * corrupt low memory. After the real mode trampoline is allocated the 657f1d4d47cSMike Rapoport * rest of the memory below 640k is reserved. 6584c674481SMike Rapoport * 6594c674481SMike Rapoport * In addition, make sure page 0 is always reserved because on 6604c674481SMike Rapoport * systems with L1TF its contents can be leaked to user processes. 661a799c2bdSMike Rapoport */ 662f1d4d47cSMike Rapoport memblock_reserve(0, SZ_64K); 663a799c2bdSMike Rapoport 664a799c2bdSMike Rapoport early_reserve_initrd(); 665a799c2bdSMike Rapoport 666a799c2bdSMike Rapoport memblock_x86_reserve_range_setup_data(); 667a799c2bdSMike Rapoport 668a799c2bdSMike Rapoport reserve_bios_regions(); 669f1d4d47cSMike Rapoport trim_snb_memory(); 67095c96084SH. Peter Anvin } 67195c96084SH. Peter Anvin 6725394f80fSJeremy Fitzhardinge /* 673f32360efSKees Cook * Dump out kernel offset information on panic. 674f32360efSKees Cook */ 675f32360efSKees Cook static int 676f32360efSKees Cook dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) 677f32360efSKees Cook { 67878cac48cSBorislav Petkov if (kaslr_enabled()) { 67978cac48cSBorislav Petkov pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", 6804545c898SJiri Kosina kaslr_offset(), 68178cac48cSBorislav Petkov __START_KERNEL, 68278cac48cSBorislav Petkov __START_KERNEL_map, 68378cac48cSBorislav Petkov MODULES_VADDR-1); 68478cac48cSBorislav Petkov } else { 68578cac48cSBorislav Petkov pr_emerg("Kernel Offset: disabled\n"); 68678cac48cSBorislav Petkov } 687f32360efSKees Cook 688f32360efSKees Cook return 0; 689f32360efSKees Cook } 690f32360efSKees Cook 69176ea0025SBorislav Petkov void x86_configure_nx(void) 69276ea0025SBorislav Petkov { 69376ea0025SBorislav Petkov if (boot_cpu_has(X86_FEATURE_NX)) 69476ea0025SBorislav Petkov __supported_pte_mask |= _PAGE_NX; 69576ea0025SBorislav Petkov else 69676ea0025SBorislav Petkov __supported_pte_mask &= ~_PAGE_NX; 69776ea0025SBorislav Petkov } 69876ea0025SBorislav Petkov 69976ea0025SBorislav Petkov static void __init x86_report_nx(void) 70076ea0025SBorislav Petkov { 70176ea0025SBorislav Petkov if (!boot_cpu_has(X86_FEATURE_NX)) { 70276ea0025SBorislav Petkov printk(KERN_NOTICE "Notice: NX (Execute Disable) protection " 70376ea0025SBorislav Petkov "missing in CPU!\n"); 70476ea0025SBorislav Petkov } else { 70576ea0025SBorislav Petkov #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE) 70676ea0025SBorislav Petkov printk(KERN_INFO "NX (Execute Disable) protection: active\n"); 70776ea0025SBorislav Petkov #else 70876ea0025SBorislav Petkov /* 32bit non-PAE kernel, NX cannot be used */ 70976ea0025SBorislav Petkov printk(KERN_NOTICE "Notice: NX (Execute Disable) protection " 71076ea0025SBorislav Petkov "cannot be enabled: non-PAE kernel!\n"); 71176ea0025SBorislav Petkov #endif 71276ea0025SBorislav Petkov } 71376ea0025SBorislav Petkov } 71476ea0025SBorislav Petkov 715f32360efSKees Cook /* 71655f26239SYinghai Lu * Determine if we were loaded by an EFI loader. If so, then we have also been 71755f26239SYinghai Lu * passed the efi memmap, systab, etc., so we should use these data structures 71855f26239SYinghai Lu * for initialization. Note, the efi init code path is determined by the 71955f26239SYinghai Lu * global efi_enabled. This allows the same kernel image to be used on existing 72055f26239SYinghai Lu * systems (with a traditional BIOS) as well as on EFI systems. 72155f26239SYinghai Lu */ 72255f26239SYinghai Lu /* 72355f26239SYinghai Lu * setup_arch - architecture-specific boot-time initializations 72455f26239SYinghai Lu * 72555f26239SYinghai Lu * Note: On x86_64, fixmaps are ready for use even before this is called. 72655f26239SYinghai Lu */ 72755f26239SYinghai Lu 72855f26239SYinghai Lu void __init setup_arch(char **cmdline_p) 72955f26239SYinghai Lu { 73055f26239SYinghai Lu #ifdef CONFIG_X86_32 73155f26239SYinghai Lu memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); 732b40827faSBorislav Petkov 733b40827faSBorislav Petkov /* 734b40827faSBorislav Petkov * copy kernel address range established so far and switch 735b40827faSBorislav Petkov * to the proper swapper page table 736b40827faSBorislav Petkov */ 737b40827faSBorislav Petkov clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, 738b40827faSBorislav Petkov initial_page_table + KERNEL_PGD_BOUNDARY, 739b40827faSBorislav Petkov KERNEL_PGD_PTRS); 740b40827faSBorislav Petkov 741b40827faSBorislav Petkov load_cr3(swapper_pg_dir); 7422075244fSBryan O'Donoghue /* 7432075244fSBryan O'Donoghue * Note: Quark X1000 CPUs advertise PGE incorrectly and require 7442075244fSBryan O'Donoghue * a cr3 based tlb flush, so the following __flush_tlb_all() 745360db4acSIngo Molnar * will not flush anything because the CPU quirk which clears 7462075244fSBryan O'Donoghue * X86_FEATURE_PGE has not been invoked yet. Though due to the 7472075244fSBryan O'Donoghue * load_cr3() above the TLB has been flushed already. The 7482075244fSBryan O'Donoghue * quirk is invoked before subsequent calls to __flush_tlb_all() 7492075244fSBryan O'Donoghue * so proper operation is guaranteed. 7502075244fSBryan O'Donoghue */ 751b40827faSBorislav Petkov __flush_tlb_all(); 75255f26239SYinghai Lu #else 75355f26239SYinghai Lu printk(KERN_INFO "Command line: %s\n", boot_command_line); 754162434e7SKirill A. Shutemov boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; 75555f26239SYinghai Lu #endif 75655f26239SYinghai Lu 7579863c90fSAlok Kataria /* 7589863c90fSAlok Kataria * If we have OLPC OFW, we might end up relocating the fixmap due to 7599863c90fSAlok Kataria * reserve_top(), so do this before touching the ioremap area. 7609863c90fSAlok Kataria */ 761fd699c76SAndres Salomon olpc_ofw_detect(); 762fd699c76SAndres Salomon 763433f8924SThomas Gleixner idt_setup_early_traps(); 7649e882c92SJeremy Fitzhardinge early_cpu_init(); 7658990cac6SPavel Tatashin jump_label_init(); 766a945c834SPeter Zijlstra static_call_init(); 7671a98fd14SJeremy Fitzhardinge early_ioremap_init(); 7681a98fd14SJeremy Fitzhardinge 769fd699c76SAndres Salomon setup_olpc_ofw_pgd(); 770fd699c76SAndres Salomon 77155f26239SYinghai Lu ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); 77255f26239SYinghai Lu screen_info = boot_params.screen_info; 77355f26239SYinghai Lu edid_info = boot_params.edid_info; 77455f26239SYinghai Lu #ifdef CONFIG_X86_32 77555f26239SYinghai Lu apm_info.bios = boot_params.apm_bios_info; 77655f26239SYinghai Lu ist_info = boot_params.ist_info; 77755f26239SYinghai Lu #endif 77855f26239SYinghai Lu saved_video_mode = boot_params.hdr.vid_mode; 77955f26239SYinghai Lu bootloader_type = boot_params.hdr.type_of_loader; 7805031296cSH. Peter Anvin if ((bootloader_type >> 4) == 0xe) { 7815031296cSH. Peter Anvin bootloader_type &= 0xf; 7825031296cSH. Peter Anvin bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; 7835031296cSH. Peter Anvin } 7845031296cSH. Peter Anvin bootloader_version = bootloader_type & 0xf; 7855031296cSH. Peter Anvin bootloader_version |= boot_params.hdr.ext_loader_ver << 4; 78655f26239SYinghai Lu 78755f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_RAM 78855f26239SYinghai Lu rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; 78955f26239SYinghai Lu #endif 79055f26239SYinghai Lu #ifdef CONFIG_EFI 79155f26239SYinghai Lu if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 7929402973dSDaniel Kiper EFI32_LOADER_SIGNATURE, 4)) { 7933e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 7941adbfa35SOlof Johansson } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 7959402973dSDaniel Kiper EFI64_LOADER_SIGNATURE, 4)) { 7963e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 7973e909599SMatt Fleming set_bit(EFI_64BIT, &efi.flags); 79855f26239SYinghai Lu } 79955f26239SYinghai Lu #endif 80055f26239SYinghai Lu 80142bbdb43SThomas Gleixner x86_init.oem.arch_setup(); 80255f26239SYinghai Lu 8038aa83e63SJuergen Gross /* 8048aa83e63SJuergen Gross * Do some memory reservations *before* memory is added to memblock, so 8058aa83e63SJuergen Gross * memblock allocations won't overwrite it. 8068aa83e63SJuergen Gross * 8078aa83e63SJuergen Gross * After this point, everything still needed from the boot loader or 8088aa83e63SJuergen Gross * firmware or kernel text should be early reserved or marked not RAM in 8098aa83e63SJuergen Gross * e820. All other memory is free game. 8108aa83e63SJuergen Gross * 8118aa83e63SJuergen Gross * This call needs to happen before e820__memory_setup() which calls the 8128aa83e63SJuergen Gross * xen_memory_setup() on Xen dom0 which relies on the fact that those 8138aa83e63SJuergen Gross * early reservations have happened already. 8148aa83e63SJuergen Gross */ 8158aa83e63SJuergen Gross early_reserve_memory(); 8168aa83e63SJuergen Gross 817419afdf5SBjorn Helgaas iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 818103e2063SIngo Molnar e820__memory_setup(); 81928bb2237SYinghai Lu parse_setup_data(); 82028bb2237SYinghai Lu 82155f26239SYinghai Lu copy_edd(); 82255f26239SYinghai Lu 82355f26239SYinghai Lu if (!boot_params.hdr.root_flags) 82455f26239SYinghai Lu root_mountflags &= ~MS_RDONLY; 82530120d72SKefeng Wang setup_initial_init_mm(_text, _etext, _edata, (void *)_brk_end); 82655f26239SYinghai Lu 8274046d6e8SLinus Torvalds code_resource.start = __pa_symbol(_text); 8284046d6e8SLinus Torvalds code_resource.end = __pa_symbol(_etext)-1; 829a3299754SKees Cook rodata_resource.start = __pa_symbol(__start_rodata); 830a3299754SKees Cook rodata_resource.end = __pa_symbol(__end_rodata)-1; 831a3299754SKees Cook data_resource.start = __pa_symbol(_sdata); 8324046d6e8SLinus Torvalds data_resource.end = __pa_symbol(_edata)-1; 8334046d6e8SLinus Torvalds bss_resource.start = __pa_symbol(__bss_start); 8344046d6e8SLinus Torvalds bss_resource.end = __pa_symbol(__bss_stop)-1; 8354046d6e8SLinus Torvalds 836fbe61839SBorislav Petkov #ifdef CONFIG_CMDLINE_BOOL 837fbe61839SBorislav Petkov #ifdef CONFIG_CMDLINE_OVERRIDE 8388a33d96bSXueBing Chen strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 839fbe61839SBorislav Petkov #else 840fbe61839SBorislav Petkov if (builtin_cmdline[0]) { 841fbe61839SBorislav Petkov /* append boot loader cmdline to builtin */ 842fbe61839SBorislav Petkov strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 843fbe61839SBorislav Petkov strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 8448a33d96bSXueBing Chen strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 845fbe61839SBorislav Petkov } 846fbe61839SBorislav Petkov #endif 847fbe61839SBorislav Petkov #endif 848fbe61839SBorislav Petkov 8498a33d96bSXueBing Chen strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 850fbe61839SBorislav Petkov *cmdline_p = command_line; 851fbe61839SBorislav Petkov 852fbe61839SBorislav Petkov /* 853fbe61839SBorislav Petkov * x86_configure_nx() is called before parse_early_param() to detect 854fbe61839SBorislav Petkov * whether hardware doesn't support NX (so that the early EHCI debug 85576ea0025SBorislav Petkov * console setup can safely call set_fixmap()). 856fbe61839SBorislav Petkov */ 857fbe61839SBorislav Petkov x86_configure_nx(); 858fbe61839SBorislav Petkov 859fbe61839SBorislav Petkov parse_early_param(); 860fbe61839SBorislav Petkov 8612f5b3514SMike Rapoport if (efi_enabled(EFI_BOOT)) 8622f5b3514SMike Rapoport efi_memblock_x86_reserve_range(); 8632f5b3514SMike Rapoport 86439fa104dSReza Arbab #ifdef CONFIG_MEMORY_HOTPLUG 86539fa104dSReza Arbab /* 86639fa104dSReza Arbab * Memory used by the kernel cannot be hot-removed because Linux 86739fa104dSReza Arbab * cannot migrate the kernel pages. When memory hotplug is 86839fa104dSReza Arbab * enabled, we should prevent memblock from allocating memory 86939fa104dSReza Arbab * for the kernel. 87039fa104dSReza Arbab * 87139fa104dSReza Arbab * ACPI SRAT records all hotpluggable memory ranges. But before 87239fa104dSReza Arbab * SRAT is parsed, we don't know about it. 87339fa104dSReza Arbab * 87439fa104dSReza Arbab * The kernel image is loaded into memory at very early time. We 87539fa104dSReza Arbab * cannot prevent this anyway. So on NUMA system, we set any 87639fa104dSReza Arbab * node the kernel resides in as un-hotpluggable. 87739fa104dSReza Arbab * 87839fa104dSReza Arbab * Since on modern servers, one node could have double-digit 87939fa104dSReza Arbab * gigabytes memory, we can assume the memory around the kernel 88039fa104dSReza Arbab * image is also un-hotpluggable. So before SRAT is parsed, just 88139fa104dSReza Arbab * allocate memory near the kernel image to try the best to keep 88239fa104dSReza Arbab * the kernel away from hotpluggable memory. 88339fa104dSReza Arbab */ 88439fa104dSReza Arbab if (movable_node_is_enabled()) 88539fa104dSReza Arbab memblock_set_bottom_up(true); 88639fa104dSReza Arbab #endif 88739fa104dSReza Arbab 8884b0f3b81SKees Cook x86_report_nx(); 8890ad5bce7SJeremy Fitzhardinge 890bef4f379SThomas Gleixner apic_setup_apic_calls(); 891bef4f379SThomas Gleixner 89255f26239SYinghai Lu if (acpi_mps_check()) { 89355f26239SYinghai Lu #ifdef CONFIG_X86_LOCAL_APIC 89449062454SThomas Gleixner apic_is_disabled = true; 89555f26239SYinghai Lu #endif 896988781dcSYinghai Lu setup_clear_cpu_cap(X86_FEATURE_APIC); 89755f26239SYinghai Lu } 89855f26239SYinghai Lu 8991a127034SIngo Molnar e820__reserve_setup_data(); 9009641bdafSIngo Molnar e820__finish_early_params(); 90155f26239SYinghai Lu 90283e68189SMatt Fleming if (efi_enabled(EFI_BOOT)) 903ff0c0874SBrian Maly efi_init(); 904ff0c0874SBrian Maly 9059338c223SRoss Lagerwall reserve_ibft_region(); 9060fca0812SRobert Richter dmi_setup(); 9072216d199SYinghai Lu 90888b094fbSAlok Kataria /* 90988b094fbSAlok Kataria * VMware detection requires dmi to be available, so this 9100fca0812SRobert Richter * needs to be done after dmi_setup(), for the boot CPU. 91129055dc7SJuergen Gross * For some guest types (Xen PV, SEV-SNP, TDX) it is required to be 91229055dc7SJuergen Gross * called before cache_bp_init() for setting up MTRR state. 91388b094fbSAlok Kataria */ 9142d826404SThomas Gleixner init_hypervisor_platform(); 91588b094fbSAlok Kataria 916cf7a63efSPavel Tatashin tsc_early_init(); 917f7cf5a5bSThomas Gleixner x86_init.resources.probe_roms(); 91855f26239SYinghai Lu 9194046d6e8SLinus Torvalds /* after parse_early_param, so could debug it */ 9204046d6e8SLinus Torvalds insert_resource(&iomem_resource, &code_resource); 921a3299754SKees Cook insert_resource(&iomem_resource, &rodata_resource); 9224046d6e8SLinus Torvalds insert_resource(&iomem_resource, &data_resource); 9234046d6e8SLinus Torvalds insert_resource(&iomem_resource, &bss_resource); 9244046d6e8SLinus Torvalds 925b422a309SYinghai Lu e820_add_kernel_range(); 9261b5576e6SYinghai Lu trim_bios_range(); 92755f26239SYinghai Lu #ifdef CONFIG_X86_32 92855f26239SYinghai Lu if (ppro_with_ram_bug()) { 92909821ff1SIngo Molnar e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, 93009821ff1SIngo Molnar E820_TYPE_RESERVED); 931f9748fa0SIngo Molnar e820__update_table(e820_table); 93255f26239SYinghai Lu printk(KERN_INFO "fixed physical RAM map:\n"); 933be0c3f0fSIngo Molnar e820__print_table("bad_ppro"); 93455f26239SYinghai Lu } 93555f26239SYinghai Lu #else 93655f26239SYinghai Lu early_gart_iommu_check(); 93755f26239SYinghai Lu #endif 93855f26239SYinghai Lu 93955f26239SYinghai Lu /* 94055f26239SYinghai Lu * partially used pages are not usable - thus 94155f26239SYinghai Lu * we are rounding upwards: 94255f26239SYinghai Lu */ 9430c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 94455f26239SYinghai Lu 94555f26239SYinghai Lu /* update e820 for memory not covered by WB MTRRs */ 9460b9a6a8bSJuergen Gross cache_bp_init(); 9472dc807b3SYinghai Lu if (mtrr_trim_uncached_memory(max_pfn)) 9480c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 94955f26239SYinghai Lu 9508dd33030SIgor Mammedov max_possible_pfn = max_pfn; 9518dd33030SIgor Mammedov 952c7d2361fSThomas Garnier /* 953c7d2361fSThomas Garnier * Define random base addresses for memory sections after max_pfn is 954c7d2361fSThomas Garnier * defined and before each memory section base is used. 955c7d2361fSThomas Garnier */ 956c7d2361fSThomas Garnier kernel_randomize_memory(); 957c7d2361fSThomas Garnier 95855f26239SYinghai Lu #ifdef CONFIG_X86_32 95955f26239SYinghai Lu /* max_low_pfn get updated here */ 96055f26239SYinghai Lu find_low_pfn_range(); 96155f26239SYinghai Lu #else 9626e1cb38aSSuresh Siddha check_x2apic(); 96355f26239SYinghai Lu 96455f26239SYinghai Lu /* How many end-of-memory variables you have, grandma! */ 96555f26239SYinghai Lu /* need this before calling reserve_initrd */ 966f361a450SYinghai Lu if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) 9670c6fc11aSIngo Molnar max_low_pfn = e820__end_of_low_ram_pfn(); 968f361a450SYinghai Lu else 96955f26239SYinghai Lu max_low_pfn = max_pfn; 970f361a450SYinghai Lu 97155f26239SYinghai Lu high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 97255f26239SYinghai Lu #endif 97355f26239SYinghai Lu 974e061c7aeSThomas Gleixner /* Find and reserve MPTABLE area */ 975e061c7aeSThomas Gleixner x86_init.mpparse.find_mptable(); 976893f38d1SYinghai Lu 9778d57470dSYinghai Lu early_alloc_pgt_buf(); 9788d57470dSYinghai Lu 97972d7c3b3SYinghai Lu /* 9804918e228SIngo Molnar * Need to conclude brk, before e820__memblock_setup() 98172d7c3b3SYinghai Lu * it could use memblock_find_in_range, could overlap with 98272d7c3b3SYinghai Lu * brk area. 98372d7c3b3SYinghai Lu */ 98472d7c3b3SYinghai Lu reserve_brk(); 98572d7c3b3SYinghai Lu 986e5f15b45SYinghai Lu cleanup_highmap(); 987e5f15b45SYinghai Lu 9882449f343STang Chen memblock_set_current_limit(ISA_END_ADDRESS); 9894918e228SIngo Molnar e820__memblock_setup(); 99072d7c3b3SYinghai Lu 991e998879dSAshish Kalra /* 992e998879dSAshish Kalra * Needs to run after memblock setup because it needs the physical 993e998879dSAshish Kalra * memory size. 994e998879dSAshish Kalra */ 9956e74b125SAlexander Shishkin mem_encrypt_setup_arch(); 996e998879dSAshish Kalra 9974971531aSMatt Fleming efi_fake_memmap(); 9984971531aSMatt Fleming efi_find_mirror(); 9993dad6f7fSRicardo Neri efi_esrt_init(); 100058c90902SLenny Szubowicz efi_mokvar_table_init(); 10014971531aSMatt Fleming 1002916f676fSMatthew Garrett /* 10034971531aSMatt Fleming * The EFI specification says that boot service code won't be 10044971531aSMatt Fleming * called after ExitBootServices(). This is, in fact, a lie. 1005916f676fSMatthew Garrett */ 1006916f676fSMatthew Garrett efi_reserve_boot_services(); 1007916f676fSMatthew Garrett 100872d7c3b3SYinghai Lu /* preallocate 4k for mptable mpc */ 10095da217caSIngo Molnar e820__memblock_alloc_reserved_mpc_new(); 101072d7c3b3SYinghai Lu 101172d7c3b3SYinghai Lu #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 101272d7c3b3SYinghai Lu setup_bios_corruption_check(); 101372d7c3b3SYinghai Lu #endif 101472d7c3b3SYinghai Lu 101510054230SYinghai Lu #ifdef CONFIG_X86_32 1016365811d6SBjorn Helgaas printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", 1017365811d6SBjorn Helgaas (max_pfn_mapped<<PAGE_SHIFT) - 1); 101810054230SYinghai Lu #endif 101972d7c3b3SYinghai Lu 1020c361e5d4SMike Rapoport /* 1021ec35d1d9SBorislav Petkov * Find free memory for the real mode trampoline and place it there. If 1022ec35d1d9SBorislav Petkov * there is not enough free memory under 1M, on EFI-enabled systems 1023ec35d1d9SBorislav Petkov * there will be additional attempt to reclaim the memory for the real 1024ec35d1d9SBorislav Petkov * mode trampoline at efi_free_boot_services(). 1025f1d4d47cSMike Rapoport * 1026ec35d1d9SBorislav Petkov * Unconditionally reserve the entire first 1M of RAM because BIOSes 1027ec35d1d9SBorislav Petkov * are known to corrupt low memory and several hundred kilobytes are not 1028ec35d1d9SBorislav Petkov * worth complex detection what memory gets clobbered. Windows does the 1029ec35d1d9SBorislav Petkov * same thing for very similar reasons. 1030ec35d1d9SBorislav Petkov * 1031ec35d1d9SBorislav Petkov * Moreover, on machines with SandyBridge graphics or in setups that use 1032ec35d1d9SBorislav Petkov * crashkernel the entire 1M is reserved anyway. 1033abe8dbabSKai Huang * 1034abe8dbabSKai Huang * Note the host kernel TDX also requires the first 1MB being reserved. 1035c361e5d4SMike Rapoport */ 1036f1e52500SJuergen Gross x86_platform.realmode_reserve(); 1037a9acc536SJesse Barnes 103822ddfcaaSYinghai Lu init_mem_mapping(); 1039854c879fSPekka J Enberg 1040433f8924SThomas Gleixner idt_setup_early_pf(); 1041cda846f1SJarkko Sakkinen 104218bc7bd5SAndy Lutomirski /* 104318bc7bd5SAndy Lutomirski * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) 104418bc7bd5SAndy Lutomirski * with the current CR4 value. This may not be necessary, but 104518bc7bd5SAndy Lutomirski * auditing all the early-boot CR4 manipulation would be needed to 104618bc7bd5SAndy Lutomirski * rule it out. 1047c7ad5ad2SAndy Lutomirski * 1048c7ad5ad2SAndy Lutomirski * Mask off features that don't work outside long mode (just 1049c7ad5ad2SAndy Lutomirski * PCIDE for now). 105018bc7bd5SAndy Lutomirski */ 1051c7ad5ad2SAndy Lutomirski mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; 105218bc7bd5SAndy Lutomirski 10534ce7a869SYinghai Lu memblock_set_current_limit(get_max_mapped()); 1054e7b37895SYinghai Lu 1055e7b37895SYinghai Lu /* 1056e7b37895SYinghai Lu * NOTE: On x86-32, only from this point on, fixmaps are ready for use. 1057e7b37895SYinghai Lu */ 1058e7b37895SYinghai Lu 1059e7b37895SYinghai Lu #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 1060e7b37895SYinghai Lu if (init_ohci1394_dma_early) 1061162a7e75SMike Travis init_ohci1394_dma_on_all_controllers(); 1062162a7e75SMike Travis #endif 1063e7b37895SYinghai Lu /* Allocate bigger log buffer */ 106455f26239SYinghai Lu setup_log_buf(1); 106555f26239SYinghai Lu 10669661b332SDavid Howells if (efi_enabled(EFI_BOOT)) { 10679661b332SDavid Howells switch (boot_params.secure_boot) { 10689661b332SDavid Howells case efi_secureboot_mode_disabled: 10699661b332SDavid Howells pr_info("Secure boot disabled\n"); 10709661b332SDavid Howells break; 10719661b332SDavid Howells case efi_secureboot_mode_enabled: 10729661b332SDavid Howells pr_info("Secure boot enabled\n"); 10739661b332SDavid Howells break; 10749661b332SDavid Howells default: 10759661b332SDavid Howells pr_info("Secure boot could not be determined\n"); 10769661b332SDavid Howells break; 10779661b332SDavid Howells } 10789661b332SDavid Howells } 10799661b332SDavid Howells 108044280733SYinghai Lu reserve_initrd(); 108144280733SYinghai Lu 1082da3d3f98SAleksey Makarov acpi_table_upgrade(); 10836998a880SRafael J. Wysocki /* Look for ACPI tables and reserve memory occupied by them. */ 10846998a880SRafael J. Wysocki acpi_boot_table_init(); 108555f26239SYinghai Lu 108655f26239SYinghai Lu vsmp_init(); 108755f26239SYinghai Lu 108855f26239SYinghai Lu io_delay_init(); 108955f26239SYinghai Lu 1090630b3affSLukas Wunner early_platform_quirks(); 1091630b3affSLukas Wunner 1092de6aec24SThomas Gleixner /* Some platforms need the APIC registered for NUMA configuration */ 109320e6926dSYinghai Lu early_acpi_boot_init(); 1094de6aec24SThomas Gleixner x86_init.mpparse.early_parse_smp_cfg(); 109520e6926dSYinghai Lu 10960d294c8cSSaurabh Sengar x86_flattree_get_config(); 10970d294c8cSSaurabh Sengar 109891467bdfSBernhard Walle initmem_init(); 10993c325f82SWeijie Yang dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); 1100fa591c4aSTang Chen 1101cf11e85fSRoman Gushchin if (boot_cpu_has(X86_FEATURE_GBPAGES)) 1102cf11e85fSRoman Gushchin hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); 1103cf11e85fSRoman Gushchin 1104fa591c4aSTang Chen /* 1105fa591c4aSTang Chen * Reserve memory for crash kernel after SRAT is parsed so that it 1106fa591c4aSTang Chen * won't consume hotpluggable memory. 1107fa591c4aSTang Chen */ 11089c08a2a1SBaoquan He arch_reserve_crashkernel(); 1109fa591c4aSTang Chen 111055f26239SYinghai Lu memblock_find_dma_reserve(); 111155f26239SYinghai Lu 1112ccb64941SBoris Ostrovsky if (!early_xdbc_setup_hardware()) 1113ccb64941SBoris Ostrovsky early_xdbc_register_console(); 1114ccb64941SBoris Ostrovsky 1115030cb6c0SThomas Gleixner x86_init.paging.pagetable_init(); 111655f26239SYinghai Lu 1117ef7f0d6aSAndrey Ryabinin kasan_init(); 1118ef7f0d6aSAndrey Ryabinin 1119d2b6dc61SAndy Lutomirski /* 1120945fd17aSThomas Gleixner * Sync back kernel address range. 1121945fd17aSThomas Gleixner * 1122945fd17aSThomas Gleixner * FIXME: Can the later sync in setup_cpu_entry_areas() replace 1123945fd17aSThomas Gleixner * this call? 1124d2b6dc61SAndy Lutomirski */ 1125945fd17aSThomas Gleixner sync_initial_page_table(); 1126d2b6dc61SAndy Lutomirski 112731625340SJoseph Cihula tboot_probe(); 112831625340SJoseph Cihula 112955f26239SYinghai Lu map_vsyscall(); 113055f26239SYinghai Lu 11319d87f5b6SThomas Gleixner x86_32_probe_apic(); 113255f26239SYinghai Lu 113355f26239SYinghai Lu early_quirks(); 113455f26239SYinghai Lu 11357c0edad3SThomas Gleixner topology_apply_cmdline_limits_early(); 11367c0edad3SThomas Gleixner 113755f26239SYinghai Lu /* 1138dcb76008SThomas Gleixner * Parse SMP configuration. Try ACPI first and then the platform 1139dcb76008SThomas Gleixner * specific parser. 114055f26239SYinghai Lu */ 114155f26239SYinghai Lu acpi_boot_init(); 1142dcb76008SThomas Gleixner x86_init.mpparse.parse_smp_cfg(); 114355f26239SYinghai Lu 11447c0edad3SThomas Gleixner /* Last opportunity to detect and map the local APIC */ 11451e90a13dSThomas Gleixner init_apic_mappings(); 11461e90a13dSThomas Gleixner 11477c0edad3SThomas Gleixner topology_init_possible_cpus(); 1148301e6190SYinghai Lu 11495f4765f9SYinghai Lu init_cpu_to_node(); 115073bf7382SJonathan Cameron init_gi_nodes(); 11515f4765f9SYinghai Lu 1152ca1b8862SThomas Gleixner io_apic_init_mappings(); 11539d6a4d08SYinghai Lu 1154f3614646SJuergen Gross x86_init.hyper.guest_late_init(); 115555f26239SYinghai Lu 11561506c8dcSIngo Molnar e820__reserve_resources(); 1157cc55f753SZhimin Gu e820__register_nosave_regions(max_pfn); 115855f26239SYinghai Lu 11598fee697dSThomas Gleixner x86_init.resources.reserve_resources(); 116055f26239SYinghai Lu 11612df908baSIngo Molnar e820__setup_pci_gap(); 116255f26239SYinghai Lu 116355f26239SYinghai Lu #ifdef CONFIG_VT 116455f26239SYinghai Lu #if defined(CONFIG_VGA_CONSOLE) 116583e68189SMatt Fleming if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) 1166acfc7882SArnd Bergmann vgacon_register_screen(&screen_info); 116755f26239SYinghai Lu #endif 116855f26239SYinghai Lu #endif 11696f30c1acSThomas Gleixner x86_init.oem.banner(); 1170a2202aa2SYong Wang 11716b617e22SFeng Tang x86_init.timers.wallclock_init(); 11726b617e22SFeng Tang 11739a90ed06SBorislav Petkov /* 11749a90ed06SBorislav Petkov * This needs to run before setup_local_APIC() which soft-disables the 11759a90ed06SBorislav Petkov * local APIC temporarily and that masks the thermal LVT interrupt, 11769a90ed06SBorislav Petkov * leading to softlockups on machines which have configured SMI 11779a90ed06SBorislav Petkov * interrupt delivery. 11789a90ed06SBorislav Petkov */ 11799a90ed06SBorislav Petkov therm_lvt_init(); 11809a90ed06SBorislav Petkov 1181a2202aa2SYong Wang mcheck_init(); 1182f49aa448SJason Baron 1183b3c869d3SJohn Stultz register_refined_jiffies(CLOCK_TICK_RATE); 11845189c2a7SOlof Johansson 11855189c2a7SOlof Johansson #ifdef CONFIG_EFI 1186a5d90c92SBorislav Petkov if (efi_enabled(EFI_BOOT)) 1187a5d90c92SBorislav Petkov efi_apply_memmap_quirks(); 11885189c2a7SOlof Johansson #endif 1189ee9f8fceSJosh Poimboeuf 1190ee9f8fceSJosh Poimboeuf unwind_init(); 119155f26239SYinghai Lu } 11925649b7c3SIngo Molnar 11939be1b56aSIngo Molnar #ifdef CONFIG_X86_32 11945649b7c3SIngo Molnar 11958fee697dSThomas Gleixner static struct resource video_ram_resource = { 11968fee697dSThomas Gleixner .name = "Video RAM area", 11978fee697dSThomas Gleixner .start = 0xa0000, 11988fee697dSThomas Gleixner .end = 0xbffff, 11998fee697dSThomas Gleixner .flags = IORESOURCE_BUSY | IORESOURCE_MEM 12009be1b56aSIngo Molnar }; 12019be1b56aSIngo Molnar 12028fee697dSThomas Gleixner void __init i386_reserve_resources(void) 12039be1b56aSIngo Molnar { 12048fee697dSThomas Gleixner request_resource(&iomem_resource, &video_ram_resource); 12058fee697dSThomas Gleixner reserve_standard_io_resources(); 12069be1b56aSIngo Molnar } 12079be1b56aSIngo Molnar 12089be1b56aSIngo Molnar #endif /* CONFIG_X86_32 */ 1209f32360efSKees Cook 121071eb4893SThomas Gleixner #ifndef CONFIG_SMP 121171eb4893SThomas Gleixner void __init smp_prepare_boot_cpu(void) 121271eb4893SThomas Gleixner { 121371eb4893SThomas Gleixner struct cpuinfo_x86 *c = &cpu_data(0); 121471eb4893SThomas Gleixner 121571eb4893SThomas Gleixner *c = boot_cpu_data; 121671eb4893SThomas Gleixner c->initialized = true; 121771eb4893SThomas Gleixner } 121871eb4893SThomas Gleixner #endif 121971eb4893SThomas Gleixner 1220f32360efSKees Cook static struct notifier_block kernel_offset_notifier = { 1221f32360efSKees Cook .notifier_call = dump_kernel_offset 1222f32360efSKees Cook }; 1223f32360efSKees Cook 1224f32360efSKees Cook static int __init register_kernel_offset_dumper(void) 1225f32360efSKees Cook { 1226f32360efSKees Cook atomic_notifier_chain_register(&panic_notifier_list, 1227f32360efSKees Cook &kernel_offset_notifier); 1228f32360efSKees Cook return 0; 1229f32360efSKees Cook } 1230f32360efSKees Cook __initcall(register_kernel_offset_dumper); 1231*edf66a3cSRafael J. Wysocki 1232*edf66a3cSRafael J. Wysocki #ifdef CONFIG_HOTPLUG_CPU 1233*edf66a3cSRafael J. Wysocki bool arch_cpu_is_hotpluggable(int cpu) 1234*edf66a3cSRafael J. Wysocki { 1235*edf66a3cSRafael J. Wysocki return cpu > 0; 1236*edf66a3cSRafael J. Wysocki } 1237*edf66a3cSRafael J. Wysocki #endif /* CONFIG_HOTPLUG_CPU */ 1238