1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 255f26239SYinghai Lu /* 355f26239SYinghai Lu * Copyright (C) 1995 Linus Torvalds 455f26239SYinghai Lu * 555f26239SYinghai Lu * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 655f26239SYinghai Lu * 755f26239SYinghai Lu * Memory region support 855f26239SYinghai Lu * David Parsons <[email protected]>, July-August 1999 955f26239SYinghai Lu * 1055f26239SYinghai Lu * Added E820 sanitization routine (removes overlapping memory regions); 1155f26239SYinghai Lu * Brian Moyle <[email protected]>, February 2001 1255f26239SYinghai Lu * 1355f26239SYinghai Lu * Moved CPU detection code to cpu/${cpu}.c 1455f26239SYinghai Lu * Patrick Mochel <[email protected]>, March 2002 1555f26239SYinghai Lu * 1655f26239SYinghai Lu * Provisions for empty E820 memory regions (reported by certain BIOSes). 1755f26239SYinghai Lu * Alex Achenbach <[email protected]>, December 2002. 1855f26239SYinghai Lu * 1955f26239SYinghai Lu */ 2055f26239SYinghai Lu 2155f26239SYinghai Lu /* 2255f26239SYinghai Lu * This file handles the architecture-dependent parts of initialization 2355f26239SYinghai Lu */ 2455f26239SYinghai Lu 2555f26239SYinghai Lu #include <linux/sched.h> 2655f26239SYinghai Lu #include <linux/mm.h> 2755f26239SYinghai Lu #include <linux/mmzone.h> 2855f26239SYinghai Lu #include <linux/screen_info.h> 2955f26239SYinghai Lu #include <linux/ioport.h> 3055f26239SYinghai Lu #include <linux/acpi.h> 31efafc8b2SFeng Tang #include <linux/sfi.h> 3255f26239SYinghai Lu #include <linux/apm_bios.h> 3355f26239SYinghai Lu #include <linux/initrd.h> 3472d7c3b3SYinghai Lu #include <linux/memblock.h> 3555f26239SYinghai Lu #include <linux/seq_file.h> 3655f26239SYinghai Lu #include <linux/console.h> 3755f26239SYinghai Lu #include <linux/root_dev.h> 3855f26239SYinghai Lu #include <linux/highmem.h> 39186f4360SPaul Gortmaker #include <linux/export.h> 4055f26239SYinghai Lu #include <linux/efi.h> 4155f26239SYinghai Lu #include <linux/init.h> 4255f26239SYinghai Lu #include <linux/edd.h> 4355f26239SYinghai Lu #include <linux/iscsi_ibft.h> 4455f26239SYinghai Lu #include <linux/nodemask.h> 4555f26239SYinghai Lu #include <linux/kexec.h> 4655f26239SYinghai Lu #include <linux/dmi.h> 4755f26239SYinghai Lu #include <linux/pfn.h> 4855f26239SYinghai Lu #include <linux/pci.h> 4955f26239SYinghai Lu #include <asm/pci-direct.h> 5055f26239SYinghai Lu #include <linux/init_ohci1394_dma.h> 5155f26239SYinghai Lu #include <linux/kvm_para.h> 520a2b9a6eSMarek Szyprowski #include <linux/dma-contiguous.h> 533db3eb28SPetr Tesarik #include <xen/xen.h> 54e262e32dSDavid Howells #include <uapi/linux/mount.h> 5555f26239SYinghai Lu 5655f26239SYinghai Lu #include <linux/errno.h> 5755f26239SYinghai Lu #include <linux/kernel.h> 5855f26239SYinghai Lu #include <linux/stddef.h> 5955f26239SYinghai Lu #include <linux/unistd.h> 6055f26239SYinghai Lu #include <linux/ptrace.h> 6155f26239SYinghai Lu #include <linux/user.h> 6255f26239SYinghai Lu #include <linux/delay.h> 6355f26239SYinghai Lu 6455f26239SYinghai Lu #include <linux/kallsyms.h> 6555f26239SYinghai Lu #include <linux/cpufreq.h> 6655f26239SYinghai Lu #include <linux/dma-mapping.h> 6755f26239SYinghai Lu #include <linux/ctype.h> 6855f26239SYinghai Lu #include <linux/uaccess.h> 6955f26239SYinghai Lu 7055f26239SYinghai Lu #include <linux/percpu.h> 7155f26239SYinghai Lu #include <linux/crash_dump.h> 7269575d38SShane Wang #include <linux/tboot.h> 73b3c869d3SJohn Stultz #include <linux/jiffies.h> 74b9d05200STom Lendacky #include <linux/mem_encrypt.h> 759ca5c8e6SDave Young #include <linux/sizes.h> 7655f26239SYinghai Lu 771b5aeebfSLu Baolu #include <linux/usb/xhci-dbgp.h> 7855f26239SYinghai Lu #include <video/edid.h> 7955f26239SYinghai Lu 8055f26239SYinghai Lu #include <asm/mtrr.h> 8155f26239SYinghai Lu #include <asm/apic.h> 82084ee1c6SJarkko Sakkinen #include <asm/realmode.h> 8366441bd3SIngo Molnar #include <asm/e820/api.h> 8455f26239SYinghai Lu #include <asm/mpspec.h> 8555f26239SYinghai Lu #include <asm/setup.h> 8655f26239SYinghai Lu #include <asm/efi.h> 878e6dafd6SIngo Molnar #include <asm/timer.h> 888e6dafd6SIngo Molnar #include <asm/i8259.h> 8955f26239SYinghai Lu #include <asm/sections.h> 9055f26239SYinghai Lu #include <asm/io_apic.h> 9155f26239SYinghai Lu #include <asm/ist.h> 921164dd00SIngo Molnar #include <asm/setup_arch.h> 9355f26239SYinghai Lu #include <asm/bios_ebda.h> 9455f26239SYinghai Lu #include <asm/cacheflush.h> 9555f26239SYinghai Lu #include <asm/processor.h> 9655f26239SYinghai Lu #include <asm/bugs.h> 97ef7f0d6aSAndrey Ryabinin #include <asm/kasan.h> 9855f26239SYinghai Lu 9955f26239SYinghai Lu #include <asm/vsyscall.h> 1006e5385d4SJaswinder Singh Rajput #include <asm/cpu.h> 10155f26239SYinghai Lu #include <asm/desc.h> 10255f26239SYinghai Lu #include <asm/dma.h> 10346a7fa27SFUJITA Tomonori #include <asm/iommu.h> 1041d9b16d1SJoerg Roedel #include <asm/gart.h> 10555f26239SYinghai Lu #include <asm/mmu_context.h> 10655f26239SYinghai Lu #include <asm/proto.h> 10755f26239SYinghai Lu 10855f26239SYinghai Lu #include <asm/paravirt.h> 10988b094fbSAlok Kataria #include <asm/hypervisor.h> 110fd699c76SAndres Salomon #include <asm/olpc_ofw.h> 11155f26239SYinghai Lu 11255f26239SYinghai Lu #include <asm/percpu.h> 11355f26239SYinghai Lu #include <asm/topology.h> 11455f26239SYinghai Lu #include <asm/apicdef.h> 11523ac4ae8SAndreas Herrmann #include <asm/amd_nb.h> 116a2202aa2SYong Wang #include <asm/mce.h> 117f49aa448SJason Baron #include <asm/alternative.h> 118da6b737bSSebastian Andrzej Siewior #include <asm/prom.h> 1199a2bc335SBorislav Petkov #include <asm/microcode.h> 1200483e1faSThomas Garnier #include <asm/kaslr.h> 121ee9f8fceSJosh Poimboeuf #include <asm/unwind.h> 12255f26239SYinghai Lu 1232b72394eSPekka Enberg /* 12466520ebcSJacob Shin * max_low_pfn_mapped: highest direct mapped pfn under 4GB 12566520ebcSJacob Shin * max_pfn_mapped: highest direct mapped pfn over 4GB 12666520ebcSJacob Shin * 12709821ff1SIngo Molnar * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are 12866520ebcSJacob Shin * represented by pfn_mapped 1292b72394eSPekka Enberg */ 1302b72394eSPekka Enberg unsigned long max_low_pfn_mapped; 1312b72394eSPekka Enberg unsigned long max_pfn_mapped; 1322b72394eSPekka Enberg 133e808bae2SThadeu Lima de Souza Cascardo #ifdef CONFIG_DMI 134796216a5SJeremy Fitzhardinge RESERVE_BRK(dmi_alloc, 65536); 135e808bae2SThadeu Lima de Souza Cascardo #endif 136796216a5SJeremy Fitzhardinge 137c0b5842aSIngo Molnar 13893dbda7cSJeremy Fitzhardinge static __initdata unsigned long _brk_start = (unsigned long)__brk_base; 13993dbda7cSJeremy Fitzhardinge unsigned long _brk_end = (unsigned long)__brk_base; 14093dbda7cSJeremy Fitzhardinge 141217b8ce8SYinghai Lu struct boot_params boot_params; 142217b8ce8SYinghai Lu 1434046d6e8SLinus Torvalds /* 1444046d6e8SLinus Torvalds * Machine setup.. 1454046d6e8SLinus Torvalds */ 1464046d6e8SLinus Torvalds static struct resource data_resource = { 1474046d6e8SLinus Torvalds .name = "Kernel data", 1484046d6e8SLinus Torvalds .start = 0, 1494046d6e8SLinus Torvalds .end = 0, 1504046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1514046d6e8SLinus Torvalds }; 1524046d6e8SLinus Torvalds 1534046d6e8SLinus Torvalds static struct resource code_resource = { 1544046d6e8SLinus Torvalds .name = "Kernel code", 1554046d6e8SLinus Torvalds .start = 0, 1564046d6e8SLinus Torvalds .end = 0, 1574046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1584046d6e8SLinus Torvalds }; 1594046d6e8SLinus Torvalds 1604046d6e8SLinus Torvalds static struct resource bss_resource = { 1614046d6e8SLinus Torvalds .name = "Kernel bss", 1624046d6e8SLinus Torvalds .start = 0, 1634046d6e8SLinus Torvalds .end = 0, 1644046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1654046d6e8SLinus Torvalds }; 1664046d6e8SLinus Torvalds 1674046d6e8SLinus Torvalds 16855f26239SYinghai Lu #ifdef CONFIG_X86_32 1696415813bSMathias Krause /* cpu data as detected by the assembly code in head_32.S */ 1706415813bSMathias Krause struct cpuinfo_x86 new_cpu_data; 1716415813bSMathias Krause 17255f26239SYinghai Lu /* common cpu data for all cpus */ 1736415813bSMathias Krause struct cpuinfo_x86 boot_cpu_data __read_mostly; 17455f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 17555f26239SYinghai Lu 17655f26239SYinghai Lu unsigned int def_to_bigsmp; 17755f26239SYinghai Lu 17855f26239SYinghai Lu /* for MCA, but anyone else can use it if they want */ 17955f26239SYinghai Lu unsigned int machine_id; 18055f26239SYinghai Lu unsigned int machine_submodel_id; 18155f26239SYinghai Lu unsigned int BIOS_revision; 18255f26239SYinghai Lu 18355f26239SYinghai Lu struct apm_info apm_info; 18455f26239SYinghai Lu EXPORT_SYMBOL(apm_info); 18555f26239SYinghai Lu 18655f26239SYinghai Lu #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ 18755f26239SYinghai Lu defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) 18855f26239SYinghai Lu struct ist_info ist_info; 18955f26239SYinghai Lu EXPORT_SYMBOL(ist_info); 19055f26239SYinghai Lu #else 19155f26239SYinghai Lu struct ist_info ist_info; 19255f26239SYinghai Lu #endif 19355f26239SYinghai Lu 19455f26239SYinghai Lu #else 195162434e7SKirill A. Shutemov struct cpuinfo_x86 boot_cpu_data __read_mostly; 19655f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 19755f26239SYinghai Lu #endif 19855f26239SYinghai Lu 19955f26239SYinghai Lu 20055f26239SYinghai Lu #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64) 201404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init; 20255f26239SYinghai Lu #else 203404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; 20455f26239SYinghai Lu #endif 20555f26239SYinghai Lu 2065031296cSH. Peter Anvin /* Boot loader ID and version as integers, for the benefit of proc_dointvec */ 2075031296cSH. Peter Anvin int bootloader_type, bootloader_version; 20855f26239SYinghai Lu 20955f26239SYinghai Lu /* 21055f26239SYinghai Lu * Setup options 21155f26239SYinghai Lu */ 21255f26239SYinghai Lu struct screen_info screen_info; 21355f26239SYinghai Lu EXPORT_SYMBOL(screen_info); 21455f26239SYinghai Lu struct edid_info edid_info; 21555f26239SYinghai Lu EXPORT_SYMBOL_GPL(edid_info); 21655f26239SYinghai Lu 21755f26239SYinghai Lu extern int root_mountflags; 21855f26239SYinghai Lu 21955f26239SYinghai Lu unsigned long saved_video_mode; 22055f26239SYinghai Lu 22155f26239SYinghai Lu #define RAMDISK_IMAGE_START_MASK 0x07FF 22255f26239SYinghai Lu #define RAMDISK_PROMPT_FLAG 0x8000 22355f26239SYinghai Lu #define RAMDISK_LOAD_FLAG 0x4000 22455f26239SYinghai Lu 22555f26239SYinghai Lu static char __initdata command_line[COMMAND_LINE_SIZE]; 226516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 227516cbf37STim Bird static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; 228516cbf37STim Bird #endif 22955f26239SYinghai Lu 23055f26239SYinghai Lu #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) 23155f26239SYinghai Lu struct edd edd; 23255f26239SYinghai Lu #ifdef CONFIG_EDD_MODULE 23355f26239SYinghai Lu EXPORT_SYMBOL(edd); 23455f26239SYinghai Lu #endif 23555f26239SYinghai Lu /** 23655f26239SYinghai Lu * copy_edd() - Copy the BIOS EDD information 23755f26239SYinghai Lu * from boot_params into a safe place. 23855f26239SYinghai Lu * 23955f26239SYinghai Lu */ 2409eaa192dSHelight.Xu static inline void __init copy_edd(void) 24155f26239SYinghai Lu { 24255f26239SYinghai Lu memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, 24355f26239SYinghai Lu sizeof(edd.mbr_signature)); 24455f26239SYinghai Lu memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); 24555f26239SYinghai Lu edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; 24655f26239SYinghai Lu edd.edd_info_nr = boot_params.eddbuf_entries; 24755f26239SYinghai Lu } 24855f26239SYinghai Lu #else 2499eaa192dSHelight.Xu static inline void __init copy_edd(void) 25055f26239SYinghai Lu { 25155f26239SYinghai Lu } 25255f26239SYinghai Lu #endif 25355f26239SYinghai Lu 2545368a2beSH. Peter Anvin void * __init extend_brk(size_t size, size_t align) 2555368a2beSH. Peter Anvin { 2565368a2beSH. Peter Anvin size_t mask = align - 1; 2575368a2beSH. Peter Anvin void *ret; 2585368a2beSH. Peter Anvin 2595368a2beSH. Peter Anvin BUG_ON(_brk_start == 0); 2605368a2beSH. Peter Anvin BUG_ON(align & mask); 2615368a2beSH. Peter Anvin 2625368a2beSH. Peter Anvin _brk_end = (_brk_end + mask) & ~mask; 2635368a2beSH. Peter Anvin BUG_ON((char *)(_brk_end + size) > __brk_limit); 2645368a2beSH. Peter Anvin 2655368a2beSH. Peter Anvin ret = (void *)_brk_end; 2665368a2beSH. Peter Anvin _brk_end += size; 2675368a2beSH. Peter Anvin 2685368a2beSH. Peter Anvin memset(ret, 0, size); 2695368a2beSH. Peter Anvin 2705368a2beSH. Peter Anvin return ret; 2715368a2beSH. Peter Anvin } 2725368a2beSH. Peter Anvin 273148b2098SYinghai Lu #ifdef CONFIG_X86_32 274e5f15b45SYinghai Lu static void __init cleanup_highmap(void) 275f005fe12SYinghai Lu { 276f005fe12SYinghai Lu } 277854c879fSPekka J Enberg #endif 278854c879fSPekka J Enberg 2795368a2beSH. Peter Anvin static void __init reserve_brk(void) 2805368a2beSH. Peter Anvin { 2815368a2beSH. Peter Anvin if (_brk_end > _brk_start) 282fc8d7826SAlexander Duyck memblock_reserve(__pa_symbol(_brk_start), 283fc8d7826SAlexander Duyck _brk_end - _brk_start); 2845368a2beSH. Peter Anvin 2855368a2beSH. Peter Anvin /* Mark brk area as locked down and no longer taking any 2865368a2beSH. Peter Anvin new allocations */ 2875368a2beSH. Peter Anvin _brk_start = 0; 2885368a2beSH. Peter Anvin } 2895368a2beSH. Peter Anvin 2905aa3d718SBorislav Petkov u64 relocated_ramdisk; 2915aa3d718SBorislav Petkov 29255f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_INITRD 29355f26239SYinghai Lu 294a8a51a88SYinghai Lu static u64 __init get_ramdisk_image(void) 295a8a51a88SYinghai Lu { 296a8a51a88SYinghai Lu u64 ramdisk_image = boot_params.hdr.ramdisk_image; 297a8a51a88SYinghai Lu 298ee92d815SYinghai Lu ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; 299ee92d815SYinghai Lu 300a8a51a88SYinghai Lu return ramdisk_image; 301a8a51a88SYinghai Lu } 302a8a51a88SYinghai Lu static u64 __init get_ramdisk_size(void) 303a8a51a88SYinghai Lu { 304a8a51a88SYinghai Lu u64 ramdisk_size = boot_params.hdr.ramdisk_size; 305a8a51a88SYinghai Lu 306ee92d815SYinghai Lu ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; 307ee92d815SYinghai Lu 308a8a51a88SYinghai Lu return ramdisk_size; 309a8a51a88SYinghai Lu } 310a8a51a88SYinghai Lu 31155f26239SYinghai Lu static void __init relocate_initrd(void) 31255f26239SYinghai Lu { 313c967da6aSYinghai Lu /* Assume only end is not page aligned */ 314a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 315a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 316c967da6aSYinghai Lu u64 area_size = PAGE_ALIGN(ramdisk_size); 31755f26239SYinghai Lu 318e8c57d40SYinghai Lu /* We need to move the initrd down into directly mapped mem */ 3195aa3d718SBorislav Petkov relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped), 320e8c57d40SYinghai Lu area_size, PAGE_SIZE); 32155f26239SYinghai Lu 3225aa3d718SBorislav Petkov if (!relocated_ramdisk) 32355f26239SYinghai Lu panic("Cannot find place for new RAMDISK of size %lld\n", 32455f26239SYinghai Lu ramdisk_size); 32555f26239SYinghai Lu 326e8c57d40SYinghai Lu /* Note: this includes all the mem currently occupied by 32755f26239SYinghai Lu the initrd, we rely on that fact to keep the data intact. */ 3285aa3d718SBorislav Petkov memblock_reserve(relocated_ramdisk, area_size); 3295aa3d718SBorislav Petkov initrd_start = relocated_ramdisk + PAGE_OFFSET; 33055f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 331365811d6SBjorn Helgaas printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", 3325aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 33355f26239SYinghai Lu 3345dd2c4bdSMark Salter copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size); 33555f26239SYinghai Lu 336365811d6SBjorn Helgaas printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to" 337365811d6SBjorn Helgaas " [mem %#010llx-%#010llx]\n", 33855f26239SYinghai Lu ramdisk_image, ramdisk_image + ramdisk_size - 1, 3395aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 34055f26239SYinghai Lu } 34155f26239SYinghai Lu 3421b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3431b8c78beSYinghai Lu { 3441b8c78beSYinghai Lu /* Assume only end is not page aligned */ 345a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 346a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 3471b8c78beSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 3481b8c78beSYinghai Lu 3491b8c78beSYinghai Lu if (!boot_params.hdr.type_of_loader || 3501b8c78beSYinghai Lu !ramdisk_image || !ramdisk_size) 3511b8c78beSYinghai Lu return; /* No initrd provided by bootloader */ 3521b8c78beSYinghai Lu 3531b8c78beSYinghai Lu memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); 3541b8c78beSYinghai Lu } 35555f26239SYinghai Lu static void __init reserve_initrd(void) 35655f26239SYinghai Lu { 357c967da6aSYinghai Lu /* Assume only end is not page aligned */ 358a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 359a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 360c967da6aSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 361e8c57d40SYinghai Lu u64 mapped_size; 36255f26239SYinghai Lu 36355f26239SYinghai Lu if (!boot_params.hdr.type_of_loader || 36455f26239SYinghai Lu !ramdisk_image || !ramdisk_size) 36555f26239SYinghai Lu return; /* No initrd provided by bootloader */ 36655f26239SYinghai Lu 36755f26239SYinghai Lu initrd_start = 0; 36855f26239SYinghai Lu 369595ad9afSYinghai Lu mapped_size = memblock_mem_size(max_pfn_mapped); 370e8c57d40SYinghai Lu if (ramdisk_size >= (mapped_size>>1)) 371ab7b64e9SPeter Jones panic("initrd too large to handle, " 372ab7b64e9SPeter Jones "disabling initrd (%lld needed, %lld available)\n", 373e8c57d40SYinghai Lu ramdisk_size, mapped_size>>1); 37455f26239SYinghai Lu 375365811d6SBjorn Helgaas printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, 376365811d6SBjorn Helgaas ramdisk_end - 1); 37755f26239SYinghai Lu 37874f27655SYinghai Lu if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image), 379e8c57d40SYinghai Lu PFN_DOWN(ramdisk_end))) { 380e8c57d40SYinghai Lu /* All are mapped, easy case */ 38155f26239SYinghai Lu initrd_start = ramdisk_image + PAGE_OFFSET; 38255f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 38355f26239SYinghai Lu return; 38455f26239SYinghai Lu } 38555f26239SYinghai Lu 38655f26239SYinghai Lu relocate_initrd(); 3878c5dd8f4SYinghai Lu 38824aa0788STejun Heo memblock_free(ramdisk_image, ramdisk_end - ramdisk_image); 38955f26239SYinghai Lu } 390af06f8b7SLv Zheng 39155f26239SYinghai Lu #else 3921b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3931b8c78beSYinghai Lu { 3941b8c78beSYinghai Lu } 39555f26239SYinghai Lu static void __init reserve_initrd(void) 39655f26239SYinghai Lu { 39755f26239SYinghai Lu } 39855f26239SYinghai Lu #endif /* CONFIG_BLK_DEV_INITRD */ 39955f26239SYinghai Lu 40029f784e3SYinghai Lu static void __init parse_setup_data(void) 401257b0fdeSYinghai Lu { 402257b0fdeSYinghai Lu struct setup_data *data; 40330e46b57SLinn Crosetto u64 pa_data, pa_next; 404257b0fdeSYinghai Lu 405257b0fdeSYinghai Lu pa_data = boot_params.hdr.setup_data; 406257b0fdeSYinghai Lu while (pa_data) { 4077389882cSWANG Chao u32 data_len, data_type; 408f1c2b357SSebastian Andrzej Siewior 4097389882cSWANG Chao data = early_memremap(pa_data, sizeof(*data)); 410f1c2b357SSebastian Andrzej Siewior data_len = data->len + sizeof(struct setup_data); 41130e46b57SLinn Crosetto data_type = data->type; 41230e46b57SLinn Crosetto pa_next = data->next; 4138d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 414f1c2b357SSebastian Andrzej Siewior 41530e46b57SLinn Crosetto switch (data_type) { 416257b0fdeSYinghai Lu case SETUP_E820_EXT: 417914053c0SIngo Molnar e820__memory_setup_extended(pa_data, data_len); 418257b0fdeSYinghai Lu break; 419da6b737bSSebastian Andrzej Siewior case SETUP_DTB: 420da6b737bSSebastian Andrzej Siewior add_dtb(pa_data); 421257b0fdeSYinghai Lu break; 4221fec0533SDave Young case SETUP_EFI: 4231fec0533SDave Young parse_efi_setup(pa_data, data_len); 4241fec0533SDave Young break; 425257b0fdeSYinghai Lu default: 426257b0fdeSYinghai Lu break; 427257b0fdeSYinghai Lu } 42830e46b57SLinn Crosetto pa_data = pa_next; 429257b0fdeSYinghai Lu } 430257b0fdeSYinghai Lu } 431257b0fdeSYinghai Lu 432a9ce6bc1SYinghai Lu static void __init memblock_x86_reserve_range_setup_data(void) 433a0a0becdSYinghai Lu { 434a0a0becdSYinghai Lu struct setup_data *data; 435a0a0becdSYinghai Lu u64 pa_data; 436a0a0becdSYinghai Lu 437a0a0becdSYinghai Lu pa_data = boot_params.hdr.setup_data; 438a0a0becdSYinghai Lu while (pa_data) { 43988b4c146SJeremy Fitzhardinge data = early_memremap(pa_data, sizeof(*data)); 44024aa0788STejun Heo memblock_reserve(pa_data, sizeof(*data) + data->len); 441a0a0becdSYinghai Lu pa_data = data->next; 4428d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 443a0a0becdSYinghai Lu } 444a0a0becdSYinghai Lu } 445a0a0becdSYinghai Lu 44655f26239SYinghai Lu /* 447ccb4defaSYinghai Lu * --------- Crashkernel reservation ------------------------------ 448ccb4defaSYinghai Lu */ 449ccb4defaSYinghai Lu 4502965faa5SDave Young #ifdef CONFIG_KEXEC_CORE 45132105f7fSBernhard Walle 452606134f7SBorislav Petkov /* 16M alignment for crash kernel regions */ 4539ca5c8e6SDave Young #define CRASH_ALIGN SZ_16M 454606134f7SBorislav Petkov 4557f8595bfSH. Peter Anvin /* 456*8ff80fbeSBaoquan He * Keep the crash kernel below this limit. 457*8ff80fbeSBaoquan He * 458*8ff80fbeSBaoquan He * On 32 bits earlier kernels would limit the kernel to the low 512 MiB 459*8ff80fbeSBaoquan He * due to mapping restrictions. 460*8ff80fbeSBaoquan He * 461*8ff80fbeSBaoquan He * On 64bit, kdump kernel need be restricted to be under 64TB, which is 462*8ff80fbeSBaoquan He * the upper limit of system RAM in 4-level paing mode. Since the kdump 463*8ff80fbeSBaoquan He * jumping could be from 5-level to 4-level, the jumping will fail if 464*8ff80fbeSBaoquan He * kernel is put above 64TB, and there's no way to detect the paging mode 465*8ff80fbeSBaoquan He * of the kernel which will be loaded for dumping during the 1st kernel 466*8ff80fbeSBaoquan He * bootup. 4677f8595bfSH. Peter Anvin */ 4687f8595bfSH. Peter Anvin #ifdef CONFIG_X86_32 4699ca5c8e6SDave Young # define CRASH_ADDR_LOW_MAX SZ_512M 4709ca5c8e6SDave Young # define CRASH_ADDR_HIGH_MAX SZ_512M 4717f8595bfSH. Peter Anvin #else 4729ca5c8e6SDave Young # define CRASH_ADDR_LOW_MAX SZ_4G 473*8ff80fbeSBaoquan He # define CRASH_ADDR_HIGH_MAX SZ_64T 4747f8595bfSH. Peter Anvin #endif 4757f8595bfSH. Peter Anvin 476eb6db83dSBaoquan He static int __init reserve_crashkernel_low(void) 4770212f915SYinghai Lu { 4780212f915SYinghai Lu #ifdef CONFIG_X86_64 479f56d5578SBorislav Petkov unsigned long long base, low_base = 0, low_size = 0; 4800212f915SYinghai Lu unsigned long total_low_mem; 4810212f915SYinghai Lu int ret; 4820212f915SYinghai Lu 4830212f915SYinghai Lu total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); 48497eac21bSBorislav Petkov 485adbc742bSYinghai Lu /* crashkernel=Y,low */ 48697eac21bSBorislav Petkov ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base); 487f56d5578SBorislav Petkov if (ret) { 488c729de8fSYinghai Lu /* 489c729de8fSYinghai Lu * two parts from lib/swiotlb.c: 49094fb9334SJoerg Roedel * -swiotlb size: user-specified with swiotlb= or default. 49194fb9334SJoerg Roedel * 49294fb9334SJoerg Roedel * -swiotlb overflow buffer: now hardcoded to 32k. We round it 49394fb9334SJoerg Roedel * to 8M for other buffers that may need to stay low too. Also 49494fb9334SJoerg Roedel * make sure we allocate enough extra low memory so that we 49594fb9334SJoerg Roedel * don't run out of DMA buffers for 32-bit devices. 496c729de8fSYinghai Lu */ 49794fb9334SJoerg Roedel low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); 498c729de8fSYinghai Lu } else { 499adbc742bSYinghai Lu /* passed with crashkernel=0,low ? */ 500c729de8fSYinghai Lu if (!low_size) 501eb6db83dSBaoquan He return 0; 502c729de8fSYinghai Lu } 5030212f915SYinghai Lu 504fe2d48b8SJiri Bohac low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN); 5050212f915SYinghai Lu if (!low_base) { 506eb6db83dSBaoquan He pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", 507eb6db83dSBaoquan He (unsigned long)(low_size >> 20)); 508eb6db83dSBaoquan He return -ENOMEM; 5090212f915SYinghai Lu } 5100212f915SYinghai Lu 5116f376057SBorislav Petkov ret = memblock_reserve(low_base, low_size); 5126f376057SBorislav Petkov if (ret) { 5136f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel low memblock.\n", __func__); 5146f376057SBorislav Petkov return ret; 5156f376057SBorislav Petkov } 51697eac21bSBorislav Petkov 5170212f915SYinghai Lu pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n", 5180212f915SYinghai Lu (unsigned long)(low_size >> 20), 5190212f915SYinghai Lu (unsigned long)(low_base >> 20), 5200212f915SYinghai Lu (unsigned long)(total_low_mem >> 20)); 52197eac21bSBorislav Petkov 5220212f915SYinghai Lu crashk_low_res.start = low_base; 5230212f915SYinghai Lu crashk_low_res.end = low_base + low_size - 1; 5240212f915SYinghai Lu insert_resource(&iomem_resource, &crashk_low_res); 5250212f915SYinghai Lu #endif 526eb6db83dSBaoquan He return 0; 5270212f915SYinghai Lu } 5280212f915SYinghai Lu 52929f784e3SYinghai Lu static void __init reserve_crashkernel(void) 530ccb4defaSYinghai Lu { 531f56d5578SBorislav Petkov unsigned long long crash_size, crash_base, total_mem; 53255a20ee7SYinghai Lu bool high = false; 533ccb4defaSYinghai Lu int ret; 534ccb4defaSYinghai Lu 53509c71bfdSDave Young total_mem = memblock_phys_mem_size(); 536ccb4defaSYinghai Lu 53755a20ee7SYinghai Lu /* crashkernel=XM */ 53897eac21bSBorislav Petkov ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); 53955a20ee7SYinghai Lu if (ret != 0 || crash_size <= 0) { 540adbc742bSYinghai Lu /* crashkernel=X,high */ 54155a20ee7SYinghai Lu ret = parse_crashkernel_high(boot_command_line, total_mem, 54255a20ee7SYinghai Lu &crash_size, &crash_base); 54332105f7fSBernhard Walle if (ret != 0 || crash_size <= 0) 54432105f7fSBernhard Walle return; 54555a20ee7SYinghai Lu high = true; 54655a20ee7SYinghai Lu } 54732105f7fSBernhard Walle 5483db3eb28SPetr Tesarik if (xen_pv_domain()) { 5493db3eb28SPetr Tesarik pr_info("Ignoring crashkernel for a Xen PV domain\n"); 5503db3eb28SPetr Tesarik return; 5513db3eb28SPetr Tesarik } 5523db3eb28SPetr Tesarik 55332105f7fSBernhard Walle /* 0 means: find the address automatically */ 554b9ac3849SDave Young if (!crash_base) { 5559f4c1396SYinghai Lu /* 556a8d4c824SXunlei Pang * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, 557b9ac3849SDave Young * crashkernel=x,high reserves memory over 4G, also allocates 558b9ac3849SDave Young * 256M extra low memory for DMA buffers and swiotlb. 559b9ac3849SDave Young * But the extra memory is not required for all machines. 560b9ac3849SDave Young * So try low memory first and fall back to high memory 561b9ac3849SDave Young * unless "crashkernel=size[KMG],high" is specified. 5629f4c1396SYinghai Lu */ 563b9ac3849SDave Young if (!high) 564606134f7SBorislav Petkov crash_base = memblock_find_in_range(CRASH_ALIGN, 565b9ac3849SDave Young CRASH_ADDR_LOW_MAX, 566b9ac3849SDave Young crash_size, CRASH_ALIGN); 567b9ac3849SDave Young if (!crash_base) 568b9ac3849SDave Young crash_base = memblock_find_in_range(CRASH_ALIGN, 569b9ac3849SDave Young CRASH_ADDR_HIGH_MAX, 570606134f7SBorislav Petkov crash_size, CRASH_ALIGN); 5711f5026a7STejun Heo if (!crash_base) { 57244280733SYinghai Lu pr_info("crashkernel reservation failed - No suitable area found.\n"); 573ccb4defaSYinghai Lu return; 574ccb4defaSYinghai Lu } 57532105f7fSBernhard Walle } else { 57644280733SYinghai Lu unsigned long long start; 57744280733SYinghai Lu 5789f4c1396SYinghai Lu start = memblock_find_in_range(crash_base, 57997eac21bSBorislav Petkov crash_base + crash_size, 58097eac21bSBorislav Petkov crash_size, 1 << 20); 58144280733SYinghai Lu if (start != crash_base) { 58244280733SYinghai Lu pr_info("crashkernel reservation failed - memory is in use.\n"); 583ccb4defaSYinghai Lu return; 584ccb4defaSYinghai Lu } 58532105f7fSBernhard Walle } 5866f376057SBorislav Petkov ret = memblock_reserve(crash_base, crash_size); 5876f376057SBorislav Petkov if (ret) { 5886f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel memblock.\n", __func__); 5896f376057SBorislav Petkov return; 5906f376057SBorislav Petkov } 591ccb4defaSYinghai Lu 592eb6db83dSBaoquan He if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { 593eb6db83dSBaoquan He memblock_free(crash_base, crash_size); 594eb6db83dSBaoquan He return; 595eb6db83dSBaoquan He } 596eb6db83dSBaoquan He 597f56d5578SBorislav Petkov pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", 598ccb4defaSYinghai Lu (unsigned long)(crash_size >> 20), 599ccb4defaSYinghai Lu (unsigned long)(crash_base >> 20), 600ccb4defaSYinghai Lu (unsigned long)(total_mem >> 20)); 601ccb4defaSYinghai Lu 602ccb4defaSYinghai Lu crashk_res.start = crash_base; 603ccb4defaSYinghai Lu crashk_res.end = crash_base + crash_size - 1; 604ccb4defaSYinghai Lu insert_resource(&iomem_resource, &crashk_res); 605ccb4defaSYinghai Lu } 606ccb4defaSYinghai Lu #else 60729f784e3SYinghai Lu static void __init reserve_crashkernel(void) 608ccb4defaSYinghai Lu { 609ccb4defaSYinghai Lu } 610ccb4defaSYinghai Lu #endif 611ccb4defaSYinghai Lu 612bdba0e70SYinghai Lu static struct resource standard_io_resources[] = { 613bdba0e70SYinghai Lu { .name = "dma1", .start = 0x00, .end = 0x1f, 614bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 615bdba0e70SYinghai Lu { .name = "pic1", .start = 0x20, .end = 0x21, 616bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 617bdba0e70SYinghai Lu { .name = "timer0", .start = 0x40, .end = 0x43, 618bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 619bdba0e70SYinghai Lu { .name = "timer1", .start = 0x50, .end = 0x53, 620bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 621bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x60, .end = 0x60, 622bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 623bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x64, .end = 0x64, 624bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 625bdba0e70SYinghai Lu { .name = "dma page reg", .start = 0x80, .end = 0x8f, 626bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 627bdba0e70SYinghai Lu { .name = "pic2", .start = 0xa0, .end = 0xa1, 628bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 629bdba0e70SYinghai Lu { .name = "dma2", .start = 0xc0, .end = 0xdf, 630bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 631bdba0e70SYinghai Lu { .name = "fpu", .start = 0xf0, .end = 0xff, 632bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO } 633bdba0e70SYinghai Lu }; 634bdba0e70SYinghai Lu 6358fee697dSThomas Gleixner void __init reserve_standard_io_resources(void) 636bdba0e70SYinghai Lu { 637bdba0e70SYinghai Lu int i; 638bdba0e70SYinghai Lu 639bdba0e70SYinghai Lu /* request I/O space for devices used on all i[345]86 PCs */ 640bdba0e70SYinghai Lu for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) 641bdba0e70SYinghai Lu request_resource(&ioport_resource, &standard_io_resources[i]); 642bdba0e70SYinghai Lu 643bdba0e70SYinghai Lu } 644bdba0e70SYinghai Lu 645042be38eSYinghai Lu static __init void reserve_ibft_region(void) 646042be38eSYinghai Lu { 647042be38eSYinghai Lu unsigned long addr, size = 0; 648042be38eSYinghai Lu 649042be38eSYinghai Lu addr = find_ibft_region(&size); 650042be38eSYinghai Lu 651042be38eSYinghai Lu if (size) 65224aa0788STejun Heo memblock_reserve(addr, size); 653042be38eSYinghai Lu } 654042be38eSYinghai Lu 655a9acc536SJesse Barnes static bool __init snb_gfx_workaround_needed(void) 656a9acc536SJesse Barnes { 657e43b3cecSH. Peter Anvin #ifdef CONFIG_PCI 658a9acc536SJesse Barnes int i; 659a9acc536SJesse Barnes u16 vendor, devid; 660ab3cd867SH. Peter Anvin static const __initconst u16 snb_ids[] = { 661a9acc536SJesse Barnes 0x0102, 662a9acc536SJesse Barnes 0x0112, 663a9acc536SJesse Barnes 0x0122, 664a9acc536SJesse Barnes 0x0106, 665a9acc536SJesse Barnes 0x0116, 666a9acc536SJesse Barnes 0x0126, 667a9acc536SJesse Barnes 0x010a, 668a9acc536SJesse Barnes }; 669a9acc536SJesse Barnes 670a9acc536SJesse Barnes /* Assume no if something weird is going on with PCI */ 671a9acc536SJesse Barnes if (!early_pci_allowed()) 672a9acc536SJesse Barnes return false; 673a9acc536SJesse Barnes 674a9acc536SJesse Barnes vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); 675a9acc536SJesse Barnes if (vendor != 0x8086) 676a9acc536SJesse Barnes return false; 677a9acc536SJesse Barnes 678a9acc536SJesse Barnes devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); 679a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(snb_ids); i++) 680a9acc536SJesse Barnes if (devid == snb_ids[i]) 681a9acc536SJesse Barnes return true; 682e43b3cecSH. Peter Anvin #endif 683a9acc536SJesse Barnes 684a9acc536SJesse Barnes return false; 685a9acc536SJesse Barnes } 686a9acc536SJesse Barnes 687a9acc536SJesse Barnes /* 688a9acc536SJesse Barnes * Sandy Bridge graphics has trouble with certain ranges, exclude 689a9acc536SJesse Barnes * them from allocation. 690a9acc536SJesse Barnes */ 691a9acc536SJesse Barnes static void __init trim_snb_memory(void) 692a9acc536SJesse Barnes { 693ab3cd867SH. Peter Anvin static const __initconst unsigned long bad_pages[] = { 694a9acc536SJesse Barnes 0x20050000, 695a9acc536SJesse Barnes 0x20110000, 696a9acc536SJesse Barnes 0x20130000, 697a9acc536SJesse Barnes 0x20138000, 698a9acc536SJesse Barnes 0x40004000, 699a9acc536SJesse Barnes }; 700a9acc536SJesse Barnes int i; 701a9acc536SJesse Barnes 702a9acc536SJesse Barnes if (!snb_gfx_workaround_needed()) 703a9acc536SJesse Barnes return; 704a9acc536SJesse Barnes 705a9acc536SJesse Barnes printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); 706a9acc536SJesse Barnes 707a9acc536SJesse Barnes /* 708a9acc536SJesse Barnes * Reserve all memory below the 1 MB mark that has not 709a9acc536SJesse Barnes * already been reserved. 710a9acc536SJesse Barnes */ 711a9acc536SJesse Barnes memblock_reserve(0, 1<<20); 712a9acc536SJesse Barnes 713a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { 714a9acc536SJesse Barnes if (memblock_reserve(bad_pages[i], PAGE_SIZE)) 715a9acc536SJesse Barnes printk(KERN_WARNING "failed to reserve 0x%08lx\n", 716a9acc536SJesse Barnes bad_pages[i]); 717a9acc536SJesse Barnes } 718a9acc536SJesse Barnes } 719a9acc536SJesse Barnes 720a9acc536SJesse Barnes /* 721a9acc536SJesse Barnes * Here we put platform-specific memory range workarounds, i.e. 722a9acc536SJesse Barnes * memory known to be corrupt or otherwise in need to be reserved on 723a9acc536SJesse Barnes * specific platforms. 724a9acc536SJesse Barnes * 725a9acc536SJesse Barnes * If this gets used more widely it could use a real dispatch mechanism. 726a9acc536SJesse Barnes */ 727a9acc536SJesse Barnes static void __init trim_platform_memory_ranges(void) 728a9acc536SJesse Barnes { 729a9acc536SJesse Barnes trim_snb_memory(); 730a9acc536SJesse Barnes } 731a9acc536SJesse Barnes 7321b5576e6SYinghai Lu static void __init trim_bios_range(void) 7331b5576e6SYinghai Lu { 7341b5576e6SYinghai Lu /* 7351b5576e6SYinghai Lu * A special case is the first 4Kb of memory; 7361b5576e6SYinghai Lu * This is a BIOS owned area, not kernel ram, but generally 7371b5576e6SYinghai Lu * not listed as such in the E820 table. 738d0cd7425SH. Peter Anvin * 739d0cd7425SH. Peter Anvin * This typically reserves additional memory (64KiB by default) 740d0cd7425SH. Peter Anvin * since some BIOSes are known to corrupt low memory. See the 7419ea77bdbSH. Peter Anvin * Kconfig help text for X86_RESERVE_LOW. 7421b5576e6SYinghai Lu */ 74309821ff1SIngo Molnar e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); 744d0cd7425SH. Peter Anvin 7451b5576e6SYinghai Lu /* 7461b5576e6SYinghai Lu * special case: Some BIOSen report the PC BIOS 7471b5576e6SYinghai Lu * area (640->1Mb) as ram even though it is not. 7481b5576e6SYinghai Lu * take them out. 7491b5576e6SYinghai Lu */ 75009821ff1SIngo Molnar e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); 751a9acc536SJesse Barnes 752f9748fa0SIngo Molnar e820__update_table(e820_table); 7531b5576e6SYinghai Lu } 7541b5576e6SYinghai Lu 755b422a309SYinghai Lu /* called before trim_bios_range() to spare extra sanitize */ 756b422a309SYinghai Lu static void __init e820_add_kernel_range(void) 757b422a309SYinghai Lu { 758b422a309SYinghai Lu u64 start = __pa_symbol(_text); 759b422a309SYinghai Lu u64 size = __pa_symbol(_end) - start; 760b422a309SYinghai Lu 761b422a309SYinghai Lu /* 76209821ff1SIngo Molnar * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and 763b422a309SYinghai Lu * attempt to fix it by adding the range. We may have a confused BIOS, 764b422a309SYinghai Lu * or the user may have used memmap=exactmap or memmap=xxM$yyM to 765b422a309SYinghai Lu * exclude kernel range. If we really are running on top non-RAM, 766b422a309SYinghai Lu * we will crash later anyways. 767b422a309SYinghai Lu */ 76809821ff1SIngo Molnar if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) 769b422a309SYinghai Lu return; 770b422a309SYinghai Lu 77109821ff1SIngo Molnar pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); 77209821ff1SIngo Molnar e820__range_remove(start, size, E820_TYPE_RAM, 0); 77309821ff1SIngo Molnar e820__range_add(start, size, E820_TYPE_RAM); 774b422a309SYinghai Lu } 775b422a309SYinghai Lu 77695c96084SH. Peter Anvin static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10; 77795c96084SH. Peter Anvin 7789ea77bdbSH. Peter Anvin static int __init parse_reservelow(char *p) 7799ea77bdbSH. Peter Anvin { 7809ea77bdbSH. Peter Anvin unsigned long long size; 7819ea77bdbSH. Peter Anvin 7829ea77bdbSH. Peter Anvin if (!p) 7839ea77bdbSH. Peter Anvin return -EINVAL; 7849ea77bdbSH. Peter Anvin 7859ea77bdbSH. Peter Anvin size = memparse(p, &p); 7869ea77bdbSH. Peter Anvin 7879ea77bdbSH. Peter Anvin if (size < 4096) 7889ea77bdbSH. Peter Anvin size = 4096; 7899ea77bdbSH. Peter Anvin 7909ea77bdbSH. Peter Anvin if (size > 640*1024) 7919ea77bdbSH. Peter Anvin size = 640*1024; 7929ea77bdbSH. Peter Anvin 7939ea77bdbSH. Peter Anvin reserve_low = size; 7949ea77bdbSH. Peter Anvin 7959ea77bdbSH. Peter Anvin return 0; 7969ea77bdbSH. Peter Anvin } 7979ea77bdbSH. Peter Anvin 7989ea77bdbSH. Peter Anvin early_param("reservelow", parse_reservelow); 7999ea77bdbSH. Peter Anvin 80095c96084SH. Peter Anvin static void __init trim_low_memory_range(void) 80195c96084SH. Peter Anvin { 80295c96084SH. Peter Anvin memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); 80395c96084SH. Peter Anvin } 80495c96084SH. Peter Anvin 8055394f80fSJeremy Fitzhardinge /* 806f32360efSKees Cook * Dump out kernel offset information on panic. 807f32360efSKees Cook */ 808f32360efSKees Cook static int 809f32360efSKees Cook dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) 810f32360efSKees Cook { 81178cac48cSBorislav Petkov if (kaslr_enabled()) { 81278cac48cSBorislav Petkov pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", 8134545c898SJiri Kosina kaslr_offset(), 81478cac48cSBorislav Petkov __START_KERNEL, 81578cac48cSBorislav Petkov __START_KERNEL_map, 81678cac48cSBorislav Petkov MODULES_VADDR-1); 81778cac48cSBorislav Petkov } else { 81878cac48cSBorislav Petkov pr_emerg("Kernel Offset: disabled\n"); 81978cac48cSBorislav Petkov } 820f32360efSKees Cook 821f32360efSKees Cook return 0; 822f32360efSKees Cook } 823f32360efSKees Cook 824f32360efSKees Cook /* 82555f26239SYinghai Lu * Determine if we were loaded by an EFI loader. If so, then we have also been 82655f26239SYinghai Lu * passed the efi memmap, systab, etc., so we should use these data structures 82755f26239SYinghai Lu * for initialization. Note, the efi init code path is determined by the 82855f26239SYinghai Lu * global efi_enabled. This allows the same kernel image to be used on existing 82955f26239SYinghai Lu * systems (with a traditional BIOS) as well as on EFI systems. 83055f26239SYinghai Lu */ 83155f26239SYinghai Lu /* 83255f26239SYinghai Lu * setup_arch - architecture-specific boot-time initializations 83355f26239SYinghai Lu * 83455f26239SYinghai Lu * Note: On x86_64, fixmaps are ready for use even before this is called. 83555f26239SYinghai Lu */ 83655f26239SYinghai Lu 83755f26239SYinghai Lu void __init setup_arch(char **cmdline_p) 83855f26239SYinghai Lu { 8396c902b65SYinghai Lu memblock_reserve(__pa_symbol(_text), 8406c902b65SYinghai Lu (unsigned long)__bss_stop - (unsigned long)_text); 8416c902b65SYinghai Lu 84210a70416SAndi Kleen /* 84310a70416SAndi Kleen * Make sure page 0 is always reserved because on systems with 84410a70416SAndi Kleen * L1TF its contents can be leaked to user processes. 84510a70416SAndi Kleen */ 84610a70416SAndi Kleen memblock_reserve(0, PAGE_SIZE); 84710a70416SAndi Kleen 8481b8c78beSYinghai Lu early_reserve_initrd(); 8491b8c78beSYinghai Lu 8506c902b65SYinghai Lu /* 8516c902b65SYinghai Lu * At this point everything still needed from the boot loader 8526c902b65SYinghai Lu * or BIOS or kernel text should be early reserved or marked not 8536c902b65SYinghai Lu * RAM in e820. All other memory is free game. 8546c902b65SYinghai Lu */ 8556c902b65SYinghai Lu 85655f26239SYinghai Lu #ifdef CONFIG_X86_32 85755f26239SYinghai Lu memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); 858b40827faSBorislav Petkov 859b40827faSBorislav Petkov /* 860b40827faSBorislav Petkov * copy kernel address range established so far and switch 861b40827faSBorislav Petkov * to the proper swapper page table 862b40827faSBorislav Petkov */ 863b40827faSBorislav Petkov clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, 864b40827faSBorislav Petkov initial_page_table + KERNEL_PGD_BOUNDARY, 865b40827faSBorislav Petkov KERNEL_PGD_PTRS); 866b40827faSBorislav Petkov 867b40827faSBorislav Petkov load_cr3(swapper_pg_dir); 8682075244fSBryan O'Donoghue /* 8692075244fSBryan O'Donoghue * Note: Quark X1000 CPUs advertise PGE incorrectly and require 8702075244fSBryan O'Donoghue * a cr3 based tlb flush, so the following __flush_tlb_all() 8712075244fSBryan O'Donoghue * will not flush anything because the cpu quirk which clears 8722075244fSBryan O'Donoghue * X86_FEATURE_PGE has not been invoked yet. Though due to the 8732075244fSBryan O'Donoghue * load_cr3() above the TLB has been flushed already. The 8742075244fSBryan O'Donoghue * quirk is invoked before subsequent calls to __flush_tlb_all() 8752075244fSBryan O'Donoghue * so proper operation is guaranteed. 8762075244fSBryan O'Donoghue */ 877b40827faSBorislav Petkov __flush_tlb_all(); 87855f26239SYinghai Lu #else 87955f26239SYinghai Lu printk(KERN_INFO "Command line: %s\n", boot_command_line); 880162434e7SKirill A. Shutemov boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; 88155f26239SYinghai Lu #endif 88255f26239SYinghai Lu 8839863c90fSAlok Kataria /* 8849863c90fSAlok Kataria * If we have OLPC OFW, we might end up relocating the fixmap due to 8859863c90fSAlok Kataria * reserve_top(), so do this before touching the ioremap area. 8869863c90fSAlok Kataria */ 887fd699c76SAndres Salomon olpc_ofw_detect(); 888fd699c76SAndres Salomon 889433f8924SThomas Gleixner idt_setup_early_traps(); 8909e882c92SJeremy Fitzhardinge early_cpu_init(); 8918990cac6SPavel Tatashin arch_init_ideal_nops(); 8928990cac6SPavel Tatashin jump_label_init(); 8931a98fd14SJeremy Fitzhardinge early_ioremap_init(); 8941a98fd14SJeremy Fitzhardinge 895fd699c76SAndres Salomon setup_olpc_ofw_pgd(); 896fd699c76SAndres Salomon 89755f26239SYinghai Lu ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); 89855f26239SYinghai Lu screen_info = boot_params.screen_info; 89955f26239SYinghai Lu edid_info = boot_params.edid_info; 90055f26239SYinghai Lu #ifdef CONFIG_X86_32 90155f26239SYinghai Lu apm_info.bios = boot_params.apm_bios_info; 90255f26239SYinghai Lu ist_info = boot_params.ist_info; 90355f26239SYinghai Lu #endif 90455f26239SYinghai Lu saved_video_mode = boot_params.hdr.vid_mode; 90555f26239SYinghai Lu bootloader_type = boot_params.hdr.type_of_loader; 9065031296cSH. Peter Anvin if ((bootloader_type >> 4) == 0xe) { 9075031296cSH. Peter Anvin bootloader_type &= 0xf; 9085031296cSH. Peter Anvin bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; 9095031296cSH. Peter Anvin } 9105031296cSH. Peter Anvin bootloader_version = bootloader_type & 0xf; 9115031296cSH. Peter Anvin bootloader_version |= boot_params.hdr.ext_loader_ver << 4; 91255f26239SYinghai Lu 91355f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_RAM 91455f26239SYinghai Lu rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; 91555f26239SYinghai Lu rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0); 91655f26239SYinghai Lu rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0); 91755f26239SYinghai Lu #endif 91855f26239SYinghai Lu #ifdef CONFIG_EFI 91955f26239SYinghai Lu if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 9209402973dSDaniel Kiper EFI32_LOADER_SIGNATURE, 4)) { 9213e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 9221adbfa35SOlof Johansson } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 9239402973dSDaniel Kiper EFI64_LOADER_SIGNATURE, 4)) { 9243e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 9253e909599SMatt Fleming set_bit(EFI_64BIT, &efi.flags); 92655f26239SYinghai Lu } 92755f26239SYinghai Lu #endif 92855f26239SYinghai Lu 92942bbdb43SThomas Gleixner x86_init.oem.arch_setup(); 93055f26239SYinghai Lu 931419afdf5SBjorn Helgaas iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 932103e2063SIngo Molnar e820__memory_setup(); 93328bb2237SYinghai Lu parse_setup_data(); 93428bb2237SYinghai Lu 93555f26239SYinghai Lu copy_edd(); 93655f26239SYinghai Lu 93755f26239SYinghai Lu if (!boot_params.hdr.root_flags) 93855f26239SYinghai Lu root_mountflags &= ~MS_RDONLY; 93955f26239SYinghai Lu init_mm.start_code = (unsigned long) _text; 94055f26239SYinghai Lu init_mm.end_code = (unsigned long) _etext; 94155f26239SYinghai Lu init_mm.end_data = (unsigned long) _edata; 94293dbda7cSJeremy Fitzhardinge init_mm.brk = _brk_end; 94355f26239SYinghai Lu 944fe3d197fSDave Hansen mpx_mm_init(&init_mm); 945fe3d197fSDave Hansen 9464046d6e8SLinus Torvalds code_resource.start = __pa_symbol(_text); 9474046d6e8SLinus Torvalds code_resource.end = __pa_symbol(_etext)-1; 9484046d6e8SLinus Torvalds data_resource.start = __pa_symbol(_etext); 9494046d6e8SLinus Torvalds data_resource.end = __pa_symbol(_edata)-1; 9504046d6e8SLinus Torvalds bss_resource.start = __pa_symbol(__bss_start); 9514046d6e8SLinus Torvalds bss_resource.end = __pa_symbol(__bss_stop)-1; 9524046d6e8SLinus Torvalds 953516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 954516cbf37STim Bird #ifdef CONFIG_CMDLINE_OVERRIDE 955516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 956516cbf37STim Bird #else 957516cbf37STim Bird if (builtin_cmdline[0]) { 958516cbf37STim Bird /* append boot loader cmdline to builtin */ 959516cbf37STim Bird strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 960516cbf37STim Bird strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 961516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 962516cbf37STim Bird } 963516cbf37STim Bird #endif 964516cbf37STim Bird #endif 965516cbf37STim Bird 966eda6da92SYinghai Lu strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 967eda6da92SYinghai Lu *cmdline_p = command_line; 968eda6da92SYinghai Lu 969eda6da92SYinghai Lu /* 9704b0f3b81SKees Cook * x86_configure_nx() is called before parse_early_param() to detect 9714b0f3b81SKees Cook * whether hardware doesn't support NX (so that the early EHCI debug 9724b0f3b81SKees Cook * console setup can safely call set_fixmap()). It may then be called 9734b0f3b81SKees Cook * again from within noexec_setup() during parsing early parameters 9744b0f3b81SKees Cook * to honor the respective command line option. 975eda6da92SYinghai Lu */ 9764763ed4dSH. Peter Anvin x86_configure_nx(); 977eda6da92SYinghai Lu 978eda6da92SYinghai Lu parse_early_param(); 979eda6da92SYinghai Lu 980835bcec5SDave Young if (efi_enabled(EFI_BOOT)) 981835bcec5SDave Young efi_memblock_x86_reserve_range(); 98239fa104dSReza Arbab #ifdef CONFIG_MEMORY_HOTPLUG 98339fa104dSReza Arbab /* 98439fa104dSReza Arbab * Memory used by the kernel cannot be hot-removed because Linux 98539fa104dSReza Arbab * cannot migrate the kernel pages. When memory hotplug is 98639fa104dSReza Arbab * enabled, we should prevent memblock from allocating memory 98739fa104dSReza Arbab * for the kernel. 98839fa104dSReza Arbab * 98939fa104dSReza Arbab * ACPI SRAT records all hotpluggable memory ranges. But before 99039fa104dSReza Arbab * SRAT is parsed, we don't know about it. 99139fa104dSReza Arbab * 99239fa104dSReza Arbab * The kernel image is loaded into memory at very early time. We 99339fa104dSReza Arbab * cannot prevent this anyway. So on NUMA system, we set any 99439fa104dSReza Arbab * node the kernel resides in as un-hotpluggable. 99539fa104dSReza Arbab * 99639fa104dSReza Arbab * Since on modern servers, one node could have double-digit 99739fa104dSReza Arbab * gigabytes memory, we can assume the memory around the kernel 99839fa104dSReza Arbab * image is also un-hotpluggable. So before SRAT is parsed, just 99939fa104dSReza Arbab * allocate memory near the kernel image to try the best to keep 100039fa104dSReza Arbab * the kernel away from hotpluggable memory. 100139fa104dSReza Arbab */ 100239fa104dSReza Arbab if (movable_node_is_enabled()) 100339fa104dSReza Arbab memblock_set_bottom_up(true); 100439fa104dSReza Arbab #endif 100539fa104dSReza Arbab 10064b0f3b81SKees Cook x86_report_nx(); 10070ad5bce7SJeremy Fitzhardinge 100828bb2237SYinghai Lu /* after early param, so could get panic from serial */ 1009a9ce6bc1SYinghai Lu memblock_x86_reserve_range_setup_data(); 101028bb2237SYinghai Lu 101155f26239SYinghai Lu if (acpi_mps_check()) { 101255f26239SYinghai Lu #ifdef CONFIG_X86_LOCAL_APIC 101355f26239SYinghai Lu disable_apic = 1; 101455f26239SYinghai Lu #endif 1015988781dcSYinghai Lu setup_clear_cpu_cap(X86_FEATURE_APIC); 101655f26239SYinghai Lu } 101755f26239SYinghai Lu 10181a127034SIngo Molnar e820__reserve_setup_data(); 10199641bdafSIngo Molnar e820__finish_early_params(); 102055f26239SYinghai Lu 102183e68189SMatt Fleming if (efi_enabled(EFI_BOOT)) 1022ff0c0874SBrian Maly efi_init(); 1023ff0c0874SBrian Maly 10240fca0812SRobert Richter dmi_setup(); 10252216d199SYinghai Lu 102688b094fbSAlok Kataria /* 102788b094fbSAlok Kataria * VMware detection requires dmi to be available, so this 10280fca0812SRobert Richter * needs to be done after dmi_setup(), for the boot CPU. 102988b094fbSAlok Kataria */ 10302d826404SThomas Gleixner init_hypervisor_platform(); 103188b094fbSAlok Kataria 1032cf7a63efSPavel Tatashin tsc_early_init(); 1033f7cf5a5bSThomas Gleixner x86_init.resources.probe_roms(); 103455f26239SYinghai Lu 10354046d6e8SLinus Torvalds /* after parse_early_param, so could debug it */ 10364046d6e8SLinus Torvalds insert_resource(&iomem_resource, &code_resource); 10374046d6e8SLinus Torvalds insert_resource(&iomem_resource, &data_resource); 10384046d6e8SLinus Torvalds insert_resource(&iomem_resource, &bss_resource); 10394046d6e8SLinus Torvalds 1040b422a309SYinghai Lu e820_add_kernel_range(); 10411b5576e6SYinghai Lu trim_bios_range(); 104255f26239SYinghai Lu #ifdef CONFIG_X86_32 104355f26239SYinghai Lu if (ppro_with_ram_bug()) { 104409821ff1SIngo Molnar e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, 104509821ff1SIngo Molnar E820_TYPE_RESERVED); 1046f9748fa0SIngo Molnar e820__update_table(e820_table); 104755f26239SYinghai Lu printk(KERN_INFO "fixed physical RAM map:\n"); 1048be0c3f0fSIngo Molnar e820__print_table("bad_ppro"); 104955f26239SYinghai Lu } 105055f26239SYinghai Lu #else 105155f26239SYinghai Lu early_gart_iommu_check(); 105255f26239SYinghai Lu #endif 105355f26239SYinghai Lu 105455f26239SYinghai Lu /* 105555f26239SYinghai Lu * partially used pages are not usable - thus 105655f26239SYinghai Lu * we are rounding upwards: 105755f26239SYinghai Lu */ 10580c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 105955f26239SYinghai Lu 106055f26239SYinghai Lu /* update e820 for memory not covered by WB MTRRs */ 106155f26239SYinghai Lu mtrr_bp_init(); 10622dc807b3SYinghai Lu if (mtrr_trim_uncached_memory(max_pfn)) 10630c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 106455f26239SYinghai Lu 10658dd33030SIgor Mammedov max_possible_pfn = max_pfn; 10668dd33030SIgor Mammedov 1067c7d2361fSThomas Garnier /* 106899c13b8cSMikulas Patocka * This call is required when the CPU does not support PAT. If 106999c13b8cSMikulas Patocka * mtrr_bp_init() invoked it already via pat_init() the call has no 107099c13b8cSMikulas Patocka * effect. 107199c13b8cSMikulas Patocka */ 107299c13b8cSMikulas Patocka init_cache_modes(); 107399c13b8cSMikulas Patocka 107499c13b8cSMikulas Patocka /* 1075c7d2361fSThomas Garnier * Define random base addresses for memory sections after max_pfn is 1076c7d2361fSThomas Garnier * defined and before each memory section base is used. 1077c7d2361fSThomas Garnier */ 1078c7d2361fSThomas Garnier kernel_randomize_memory(); 1079c7d2361fSThomas Garnier 108055f26239SYinghai Lu #ifdef CONFIG_X86_32 108155f26239SYinghai Lu /* max_low_pfn get updated here */ 108255f26239SYinghai Lu find_low_pfn_range(); 108355f26239SYinghai Lu #else 10846e1cb38aSSuresh Siddha check_x2apic(); 108555f26239SYinghai Lu 108655f26239SYinghai Lu /* How many end-of-memory variables you have, grandma! */ 108755f26239SYinghai Lu /* need this before calling reserve_initrd */ 1088f361a450SYinghai Lu if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) 10890c6fc11aSIngo Molnar max_low_pfn = e820__end_of_low_ram_pfn(); 1090f361a450SYinghai Lu else 109155f26239SYinghai Lu max_low_pfn = max_pfn; 1092f361a450SYinghai Lu 109355f26239SYinghai Lu high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 109455f26239SYinghai Lu #endif 109555f26239SYinghai Lu 1096893f38d1SYinghai Lu /* 1097893f38d1SYinghai Lu * Find and reserve possible boot-time SMP configuration: 1098893f38d1SYinghai Lu */ 1099893f38d1SYinghai Lu find_smp_config(); 1100893f38d1SYinghai Lu 1101042be38eSYinghai Lu reserve_ibft_region(); 1102042be38eSYinghai Lu 11038d57470dSYinghai Lu early_alloc_pgt_buf(); 11048d57470dSYinghai Lu 110572d7c3b3SYinghai Lu /* 11064918e228SIngo Molnar * Need to conclude brk, before e820__memblock_setup() 110772d7c3b3SYinghai Lu * it could use memblock_find_in_range, could overlap with 110872d7c3b3SYinghai Lu * brk area. 110972d7c3b3SYinghai Lu */ 111072d7c3b3SYinghai Lu reserve_brk(); 111172d7c3b3SYinghai Lu 1112e5f15b45SYinghai Lu cleanup_highmap(); 1113e5f15b45SYinghai Lu 11142449f343STang Chen memblock_set_current_limit(ISA_END_ADDRESS); 11154918e228SIngo Molnar e820__memblock_setup(); 111672d7c3b3SYinghai Lu 1117007b7560SAndy Lutomirski reserve_bios_regions(); 1118007b7560SAndy Lutomirski 11194971531aSMatt Fleming if (efi_enabled(EFI_MEMMAP)) { 11204971531aSMatt Fleming efi_fake_memmap(); 11214971531aSMatt Fleming efi_find_mirror(); 11223dad6f7fSRicardo Neri efi_esrt_init(); 11234971531aSMatt Fleming 1124916f676fSMatthew Garrett /* 11254971531aSMatt Fleming * The EFI specification says that boot service code won't be 11264971531aSMatt Fleming * called after ExitBootServices(). This is, in fact, a lie. 1127916f676fSMatthew Garrett */ 1128916f676fSMatthew Garrett efi_reserve_boot_services(); 11294971531aSMatt Fleming } 1130916f676fSMatthew Garrett 113172d7c3b3SYinghai Lu /* preallocate 4k for mptable mpc */ 11325da217caSIngo Molnar e820__memblock_alloc_reserved_mpc_new(); 113372d7c3b3SYinghai Lu 113472d7c3b3SYinghai Lu #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 113572d7c3b3SYinghai Lu setup_bios_corruption_check(); 113672d7c3b3SYinghai Lu #endif 113772d7c3b3SYinghai Lu 113810054230SYinghai Lu #ifdef CONFIG_X86_32 1139365811d6SBjorn Helgaas printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", 1140365811d6SBjorn Helgaas (max_pfn_mapped<<PAGE_SHIFT) - 1); 114110054230SYinghai Lu #endif 114272d7c3b3SYinghai Lu 11434f7b9226SYinghai Lu reserve_real_mode(); 1144893f38d1SYinghai Lu 1145a9acc536SJesse Barnes trim_platform_memory_ranges(); 114695c96084SH. Peter Anvin trim_low_memory_range(); 1147a9acc536SJesse Barnes 114822ddfcaaSYinghai Lu init_mem_mapping(); 1149854c879fSPekka J Enberg 1150433f8924SThomas Gleixner idt_setup_early_pf(); 1151cda846f1SJarkko Sakkinen 115218bc7bd5SAndy Lutomirski /* 115318bc7bd5SAndy Lutomirski * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) 115418bc7bd5SAndy Lutomirski * with the current CR4 value. This may not be necessary, but 115518bc7bd5SAndy Lutomirski * auditing all the early-boot CR4 manipulation would be needed to 115618bc7bd5SAndy Lutomirski * rule it out. 1157c7ad5ad2SAndy Lutomirski * 1158c7ad5ad2SAndy Lutomirski * Mask off features that don't work outside long mode (just 1159c7ad5ad2SAndy Lutomirski * PCIDE for now). 116018bc7bd5SAndy Lutomirski */ 1161c7ad5ad2SAndy Lutomirski mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; 116218bc7bd5SAndy Lutomirski 11634ce7a869SYinghai Lu memblock_set_current_limit(get_max_mapped()); 1164e7b37895SYinghai Lu 1165e7b37895SYinghai Lu /* 1166e7b37895SYinghai Lu * NOTE: On x86-32, only from this point on, fixmaps are ready for use. 1167e7b37895SYinghai Lu */ 1168e7b37895SYinghai Lu 1169e7b37895SYinghai Lu #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 1170e7b37895SYinghai Lu if (init_ohci1394_dma_early) 1171162a7e75SMike Travis init_ohci1394_dma_on_all_controllers(); 1172162a7e75SMike Travis #endif 1173e7b37895SYinghai Lu /* Allocate bigger log buffer */ 117455f26239SYinghai Lu setup_log_buf(1); 117555f26239SYinghai Lu 11769661b332SDavid Howells if (efi_enabled(EFI_BOOT)) { 11779661b332SDavid Howells switch (boot_params.secure_boot) { 11789661b332SDavid Howells case efi_secureboot_mode_disabled: 11799661b332SDavid Howells pr_info("Secure boot disabled\n"); 11809661b332SDavid Howells break; 11819661b332SDavid Howells case efi_secureboot_mode_enabled: 11829661b332SDavid Howells pr_info("Secure boot enabled\n"); 11839661b332SDavid Howells break; 11849661b332SDavid Howells default: 11859661b332SDavid Howells pr_info("Secure boot could not be determined\n"); 11869661b332SDavid Howells break; 11879661b332SDavid Howells } 11889661b332SDavid Howells } 11899661b332SDavid Howells 119044280733SYinghai Lu reserve_initrd(); 119144280733SYinghai Lu 1192da3d3f98SAleksey Makarov acpi_table_upgrade(); 119355f26239SYinghai Lu 119455f26239SYinghai Lu vsmp_init(); 119555f26239SYinghai Lu 119655f26239SYinghai Lu io_delay_init(); 119755f26239SYinghai Lu 1198630b3affSLukas Wunner early_platform_quirks(); 1199630b3affSLukas Wunner 120055f26239SYinghai Lu /* 120155f26239SYinghai Lu * Parse the ACPI tables for possible boot-time SMP configuration. 120255f26239SYinghai Lu */ 120320e6926dSYinghai Lu acpi_boot_table_init(); 120420e6926dSYinghai Lu 120520e6926dSYinghai Lu early_acpi_boot_init(); 120620e6926dSYinghai Lu 120791467bdfSBernhard Walle initmem_init(); 12083c325f82SWeijie Yang dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); 1209fa591c4aSTang Chen 1210fa591c4aSTang Chen /* 1211fa591c4aSTang Chen * Reserve memory for crash kernel after SRAT is parsed so that it 1212fa591c4aSTang Chen * won't consume hotpluggable memory. 1213fa591c4aSTang Chen */ 1214fa591c4aSTang Chen reserve_crashkernel(); 1215fa591c4aSTang Chen 121655f26239SYinghai Lu memblock_find_dma_reserve(); 121755f26239SYinghai Lu 1218ccb64941SBoris Ostrovsky if (!early_xdbc_setup_hardware()) 1219ccb64941SBoris Ostrovsky early_xdbc_register_console(); 1220ccb64941SBoris Ostrovsky 1221030cb6c0SThomas Gleixner x86_init.paging.pagetable_init(); 122255f26239SYinghai Lu 1223ef7f0d6aSAndrey Ryabinin kasan_init(); 1224ef7f0d6aSAndrey Ryabinin 1225d2b6dc61SAndy Lutomirski /* 1226945fd17aSThomas Gleixner * Sync back kernel address range. 1227945fd17aSThomas Gleixner * 1228945fd17aSThomas Gleixner * FIXME: Can the later sync in setup_cpu_entry_areas() replace 1229945fd17aSThomas Gleixner * this call? 1230d2b6dc61SAndy Lutomirski */ 1231945fd17aSThomas Gleixner sync_initial_page_table(); 1232d2b6dc61SAndy Lutomirski 123331625340SJoseph Cihula tboot_probe(); 123431625340SJoseph Cihula 123555f26239SYinghai Lu map_vsyscall(); 123655f26239SYinghai Lu 123755f26239SYinghai Lu generic_apic_probe(); 123855f26239SYinghai Lu 123955f26239SYinghai Lu early_quirks(); 124055f26239SYinghai Lu 124155f26239SYinghai Lu /* 124255f26239SYinghai Lu * Read APIC and some other early information from ACPI tables. 124355f26239SYinghai Lu */ 124455f26239SYinghai Lu acpi_boot_init(); 1245efafc8b2SFeng Tang sfi_init(); 1246a906fdaaSThomas Gleixner x86_dtb_init(); 1247efafc8b2SFeng Tang 124855f26239SYinghai Lu /* 124955f26239SYinghai Lu * get boot-time SMP configuration: 125055f26239SYinghai Lu */ 125155f26239SYinghai Lu get_smp_config(); 125255f26239SYinghai Lu 12531e90a13dSThomas Gleixner /* 12541e90a13dSThomas Gleixner * Systems w/o ACPI and mptables might not have it mapped the local 12551e90a13dSThomas Gleixner * APIC yet, but prefill_possible_map() might need to access it. 12561e90a13dSThomas Gleixner */ 12571e90a13dSThomas Gleixner init_apic_mappings(); 12581e90a13dSThomas Gleixner 1259329513a3SYinghai Lu prefill_possible_map(); 1260301e6190SYinghai Lu 12615f4765f9SYinghai Lu init_cpu_to_node(); 12625f4765f9SYinghai Lu 1263ca1b8862SThomas Gleixner io_apic_init_mappings(); 12649d6a4d08SYinghai Lu 1265f3614646SJuergen Gross x86_init.hyper.guest_late_init(); 126655f26239SYinghai Lu 12671506c8dcSIngo Molnar e820__reserve_resources(); 1268cc55f753SZhimin Gu e820__register_nosave_regions(max_pfn); 126955f26239SYinghai Lu 12708fee697dSThomas Gleixner x86_init.resources.reserve_resources(); 127155f26239SYinghai Lu 12722df908baSIngo Molnar e820__setup_pci_gap(); 127355f26239SYinghai Lu 127455f26239SYinghai Lu #ifdef CONFIG_VT 127555f26239SYinghai Lu #if defined(CONFIG_VGA_CONSOLE) 127683e68189SMatt Fleming if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) 127755f26239SYinghai Lu conswitchp = &vga_con; 127855f26239SYinghai Lu #elif defined(CONFIG_DUMMY_CONSOLE) 127955f26239SYinghai Lu conswitchp = &dummy_con; 128055f26239SYinghai Lu #endif 128155f26239SYinghai Lu #endif 12826f30c1acSThomas Gleixner x86_init.oem.banner(); 1283a2202aa2SYong Wang 12846b617e22SFeng Tang x86_init.timers.wallclock_init(); 12856b617e22SFeng Tang 1286a2202aa2SYong Wang mcheck_init(); 1287f49aa448SJason Baron 1288b3c869d3SJohn Stultz register_refined_jiffies(CLOCK_TICK_RATE); 12895189c2a7SOlof Johansson 12905189c2a7SOlof Johansson #ifdef CONFIG_EFI 1291a5d90c92SBorislav Petkov if (efi_enabled(EFI_BOOT)) 1292a5d90c92SBorislav Petkov efi_apply_memmap_quirks(); 12935189c2a7SOlof Johansson #endif 1294ee9f8fceSJosh Poimboeuf 1295ee9f8fceSJosh Poimboeuf unwind_init(); 129655f26239SYinghai Lu } 12975649b7c3SIngo Molnar 12989be1b56aSIngo Molnar #ifdef CONFIG_X86_32 12995649b7c3SIngo Molnar 13008fee697dSThomas Gleixner static struct resource video_ram_resource = { 13018fee697dSThomas Gleixner .name = "Video RAM area", 13028fee697dSThomas Gleixner .start = 0xa0000, 13038fee697dSThomas Gleixner .end = 0xbffff, 13048fee697dSThomas Gleixner .flags = IORESOURCE_BUSY | IORESOURCE_MEM 13059be1b56aSIngo Molnar }; 13069be1b56aSIngo Molnar 13078fee697dSThomas Gleixner void __init i386_reserve_resources(void) 13089be1b56aSIngo Molnar { 13098fee697dSThomas Gleixner request_resource(&iomem_resource, &video_ram_resource); 13108fee697dSThomas Gleixner reserve_standard_io_resources(); 13119be1b56aSIngo Molnar } 13129be1b56aSIngo Molnar 13139be1b56aSIngo Molnar #endif /* CONFIG_X86_32 */ 1314f32360efSKees Cook 1315f32360efSKees Cook static struct notifier_block kernel_offset_notifier = { 1316f32360efSKees Cook .notifier_call = dump_kernel_offset 1317f32360efSKees Cook }; 1318f32360efSKees Cook 1319f32360efSKees Cook static int __init register_kernel_offset_dumper(void) 1320f32360efSKees Cook { 1321f32360efSKees Cook atomic_notifier_chain_register(&panic_notifier_list, 1322f32360efSKees Cook &kernel_offset_notifier); 1323f32360efSKees Cook return 0; 1324f32360efSKees Cook } 1325f32360efSKees Cook __initcall(register_kernel_offset_dumper); 1326