155f26239SYinghai Lu /* 255f26239SYinghai Lu * Copyright (C) 1995 Linus Torvalds 355f26239SYinghai Lu * 455f26239SYinghai Lu * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 555f26239SYinghai Lu * 655f26239SYinghai Lu * Memory region support 755f26239SYinghai Lu * David Parsons <[email protected]>, July-August 1999 855f26239SYinghai Lu * 955f26239SYinghai Lu * Added E820 sanitization routine (removes overlapping memory regions); 1055f26239SYinghai Lu * Brian Moyle <[email protected]>, February 2001 1155f26239SYinghai Lu * 1255f26239SYinghai Lu * Moved CPU detection code to cpu/${cpu}.c 1355f26239SYinghai Lu * Patrick Mochel <[email protected]>, March 2002 1455f26239SYinghai Lu * 1555f26239SYinghai Lu * Provisions for empty E820 memory regions (reported by certain BIOSes). 1655f26239SYinghai Lu * Alex Achenbach <[email protected]>, December 2002. 1755f26239SYinghai Lu * 1855f26239SYinghai Lu */ 1955f26239SYinghai Lu 2055f26239SYinghai Lu /* 2155f26239SYinghai Lu * This file handles the architecture-dependent parts of initialization 2255f26239SYinghai Lu */ 2355f26239SYinghai Lu 2455f26239SYinghai Lu #include <linux/sched.h> 2555f26239SYinghai Lu #include <linux/mm.h> 2655f26239SYinghai Lu #include <linux/mmzone.h> 2755f26239SYinghai Lu #include <linux/screen_info.h> 2855f26239SYinghai Lu #include <linux/ioport.h> 2955f26239SYinghai Lu #include <linux/acpi.h> 30efafc8b2SFeng Tang #include <linux/sfi.h> 3155f26239SYinghai Lu #include <linux/apm_bios.h> 3255f26239SYinghai Lu #include <linux/initrd.h> 3355f26239SYinghai Lu #include <linux/bootmem.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> 5355f26239SYinghai Lu 5455f26239SYinghai Lu #include <linux/errno.h> 5555f26239SYinghai Lu #include <linux/kernel.h> 5655f26239SYinghai Lu #include <linux/stddef.h> 5755f26239SYinghai Lu #include <linux/unistd.h> 5855f26239SYinghai Lu #include <linux/ptrace.h> 5955f26239SYinghai Lu #include <linux/user.h> 6055f26239SYinghai Lu #include <linux/delay.h> 6155f26239SYinghai Lu 6255f26239SYinghai Lu #include <linux/kallsyms.h> 6355f26239SYinghai Lu #include <linux/cpufreq.h> 6455f26239SYinghai Lu #include <linux/dma-mapping.h> 6555f26239SYinghai Lu #include <linux/ctype.h> 6655f26239SYinghai Lu #include <linux/uaccess.h> 6755f26239SYinghai Lu 6855f26239SYinghai Lu #include <linux/percpu.h> 6955f26239SYinghai Lu #include <linux/crash_dump.h> 7069575d38SShane Wang #include <linux/tboot.h> 71b3c869d3SJohn Stultz #include <linux/jiffies.h> 72b9d05200STom Lendacky #include <linux/mem_encrypt.h> 7355f26239SYinghai Lu 741b5aeebfSLu Baolu #include <linux/usb/xhci-dbgp.h> 7555f26239SYinghai Lu #include <video/edid.h> 7655f26239SYinghai Lu 7755f26239SYinghai Lu #include <asm/mtrr.h> 7855f26239SYinghai Lu #include <asm/apic.h> 79084ee1c6SJarkko Sakkinen #include <asm/realmode.h> 8066441bd3SIngo Molnar #include <asm/e820/api.h> 8155f26239SYinghai Lu #include <asm/mpspec.h> 8255f26239SYinghai Lu #include <asm/setup.h> 8355f26239SYinghai Lu #include <asm/efi.h> 848e6dafd6SIngo Molnar #include <asm/timer.h> 858e6dafd6SIngo Molnar #include <asm/i8259.h> 8655f26239SYinghai Lu #include <asm/sections.h> 8755f26239SYinghai Lu #include <asm/io_apic.h> 8855f26239SYinghai Lu #include <asm/ist.h> 891164dd00SIngo Molnar #include <asm/setup_arch.h> 9055f26239SYinghai Lu #include <asm/bios_ebda.h> 9155f26239SYinghai Lu #include <asm/cacheflush.h> 9255f26239SYinghai Lu #include <asm/processor.h> 9355f26239SYinghai Lu #include <asm/bugs.h> 94ef7f0d6aSAndrey Ryabinin #include <asm/kasan.h> 9555f26239SYinghai Lu 9655f26239SYinghai Lu #include <asm/vsyscall.h> 976e5385d4SJaswinder Singh Rajput #include <asm/cpu.h> 9855f26239SYinghai Lu #include <asm/desc.h> 9955f26239SYinghai Lu #include <asm/dma.h> 10046a7fa27SFUJITA Tomonori #include <asm/iommu.h> 1011d9b16d1SJoerg Roedel #include <asm/gart.h> 10255f26239SYinghai Lu #include <asm/mmu_context.h> 10355f26239SYinghai Lu #include <asm/proto.h> 10455f26239SYinghai Lu 10555f26239SYinghai Lu #include <asm/paravirt.h> 10688b094fbSAlok Kataria #include <asm/hypervisor.h> 107fd699c76SAndres Salomon #include <asm/olpc_ofw.h> 10855f26239SYinghai Lu 10955f26239SYinghai Lu #include <asm/percpu.h> 11055f26239SYinghai Lu #include <asm/topology.h> 11155f26239SYinghai Lu #include <asm/apicdef.h> 11223ac4ae8SAndreas Herrmann #include <asm/amd_nb.h> 113a2202aa2SYong Wang #include <asm/mce.h> 114f49aa448SJason Baron #include <asm/alternative.h> 115da6b737bSSebastian Andrzej Siewior #include <asm/prom.h> 1169a2bc335SBorislav Petkov #include <asm/microcode.h> 1170483e1faSThomas Garnier #include <asm/kaslr.h> 118ee9f8fceSJosh Poimboeuf #include <asm/unwind.h> 11955f26239SYinghai Lu 1202b72394eSPekka Enberg /* 12166520ebcSJacob Shin * max_low_pfn_mapped: highest direct mapped pfn under 4GB 12266520ebcSJacob Shin * max_pfn_mapped: highest direct mapped pfn over 4GB 12366520ebcSJacob Shin * 12409821ff1SIngo Molnar * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are 12566520ebcSJacob Shin * represented by pfn_mapped 1262b72394eSPekka Enberg */ 1272b72394eSPekka Enberg unsigned long max_low_pfn_mapped; 1282b72394eSPekka Enberg unsigned long max_pfn_mapped; 1292b72394eSPekka Enberg 130e808bae2SThadeu Lima de Souza Cascardo #ifdef CONFIG_DMI 131796216a5SJeremy Fitzhardinge RESERVE_BRK(dmi_alloc, 65536); 132e808bae2SThadeu Lima de Souza Cascardo #endif 133796216a5SJeremy Fitzhardinge 134c0b5842aSIngo Molnar 13593dbda7cSJeremy Fitzhardinge static __initdata unsigned long _brk_start = (unsigned long)__brk_base; 13693dbda7cSJeremy Fitzhardinge unsigned long _brk_end = (unsigned long)__brk_base; 13793dbda7cSJeremy Fitzhardinge 138217b8ce8SYinghai Lu struct boot_params boot_params; 139217b8ce8SYinghai Lu 1404046d6e8SLinus Torvalds /* 1414046d6e8SLinus Torvalds * Machine setup.. 1424046d6e8SLinus Torvalds */ 1434046d6e8SLinus Torvalds static struct resource data_resource = { 1444046d6e8SLinus Torvalds .name = "Kernel data", 1454046d6e8SLinus Torvalds .start = 0, 1464046d6e8SLinus Torvalds .end = 0, 1474046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1484046d6e8SLinus Torvalds }; 1494046d6e8SLinus Torvalds 1504046d6e8SLinus Torvalds static struct resource code_resource = { 1514046d6e8SLinus Torvalds .name = "Kernel code", 1524046d6e8SLinus Torvalds .start = 0, 1534046d6e8SLinus Torvalds .end = 0, 1544046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1554046d6e8SLinus Torvalds }; 1564046d6e8SLinus Torvalds 1574046d6e8SLinus Torvalds static struct resource bss_resource = { 1584046d6e8SLinus Torvalds .name = "Kernel bss", 1594046d6e8SLinus Torvalds .start = 0, 1604046d6e8SLinus Torvalds .end = 0, 1614046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1624046d6e8SLinus Torvalds }; 1634046d6e8SLinus Torvalds 1644046d6e8SLinus Torvalds 16555f26239SYinghai Lu #ifdef CONFIG_X86_32 1666415813bSMathias Krause /* cpu data as detected by the assembly code in head_32.S */ 1676415813bSMathias Krause struct cpuinfo_x86 new_cpu_data; 1686415813bSMathias Krause 16955f26239SYinghai Lu /* common cpu data for all cpus */ 1706415813bSMathias Krause struct cpuinfo_x86 boot_cpu_data __read_mostly; 17155f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 17255f26239SYinghai Lu 17355f26239SYinghai Lu unsigned int def_to_bigsmp; 17455f26239SYinghai Lu 17555f26239SYinghai Lu /* for MCA, but anyone else can use it if they want */ 17655f26239SYinghai Lu unsigned int machine_id; 17755f26239SYinghai Lu unsigned int machine_submodel_id; 17855f26239SYinghai Lu unsigned int BIOS_revision; 17955f26239SYinghai Lu 18055f26239SYinghai Lu struct apm_info apm_info; 18155f26239SYinghai Lu EXPORT_SYMBOL(apm_info); 18255f26239SYinghai Lu 18355f26239SYinghai Lu #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ 18455f26239SYinghai Lu defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) 18555f26239SYinghai Lu struct ist_info ist_info; 18655f26239SYinghai Lu EXPORT_SYMBOL(ist_info); 18755f26239SYinghai Lu #else 18855f26239SYinghai Lu struct ist_info ist_info; 18955f26239SYinghai Lu #endif 19055f26239SYinghai Lu 19155f26239SYinghai Lu #else 192ed26dbe5SJeremy Fitzhardinge struct cpuinfo_x86 boot_cpu_data __read_mostly = { 193ed26dbe5SJeremy Fitzhardinge .x86_phys_bits = MAX_PHYSMEM_BITS, 194ed26dbe5SJeremy Fitzhardinge }; 19555f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 19655f26239SYinghai Lu #endif 19755f26239SYinghai Lu 19855f26239SYinghai Lu 19955f26239SYinghai Lu #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64) 200404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init; 20155f26239SYinghai Lu #else 202404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; 20355f26239SYinghai Lu #endif 20455f26239SYinghai Lu 2055031296cSH. Peter Anvin /* Boot loader ID and version as integers, for the benefit of proc_dointvec */ 2065031296cSH. Peter Anvin int bootloader_type, bootloader_version; 20755f26239SYinghai Lu 20855f26239SYinghai Lu /* 20955f26239SYinghai Lu * Setup options 21055f26239SYinghai Lu */ 21155f26239SYinghai Lu struct screen_info screen_info; 21255f26239SYinghai Lu EXPORT_SYMBOL(screen_info); 21355f26239SYinghai Lu struct edid_info edid_info; 21455f26239SYinghai Lu EXPORT_SYMBOL_GPL(edid_info); 21555f26239SYinghai Lu 21655f26239SYinghai Lu extern int root_mountflags; 21755f26239SYinghai Lu 21855f26239SYinghai Lu unsigned long saved_video_mode; 21955f26239SYinghai Lu 22055f26239SYinghai Lu #define RAMDISK_IMAGE_START_MASK 0x07FF 22155f26239SYinghai Lu #define RAMDISK_PROMPT_FLAG 0x8000 22255f26239SYinghai Lu #define RAMDISK_LOAD_FLAG 0x4000 22355f26239SYinghai Lu 22455f26239SYinghai Lu static char __initdata command_line[COMMAND_LINE_SIZE]; 225516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 226516cbf37STim Bird static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; 227516cbf37STim Bird #endif 22855f26239SYinghai Lu 22955f26239SYinghai Lu #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) 23055f26239SYinghai Lu struct edd edd; 23155f26239SYinghai Lu #ifdef CONFIG_EDD_MODULE 23255f26239SYinghai Lu EXPORT_SYMBOL(edd); 23355f26239SYinghai Lu #endif 23455f26239SYinghai Lu /** 23555f26239SYinghai Lu * copy_edd() - Copy the BIOS EDD information 23655f26239SYinghai Lu * from boot_params into a safe place. 23755f26239SYinghai Lu * 23855f26239SYinghai Lu */ 2399eaa192dSHelight.Xu static inline void __init copy_edd(void) 24055f26239SYinghai Lu { 24155f26239SYinghai Lu memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, 24255f26239SYinghai Lu sizeof(edd.mbr_signature)); 24355f26239SYinghai Lu memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); 24455f26239SYinghai Lu edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; 24555f26239SYinghai Lu edd.edd_info_nr = boot_params.eddbuf_entries; 24655f26239SYinghai Lu } 24755f26239SYinghai Lu #else 2489eaa192dSHelight.Xu static inline void __init copy_edd(void) 24955f26239SYinghai Lu { 25055f26239SYinghai Lu } 25155f26239SYinghai Lu #endif 25255f26239SYinghai Lu 2535368a2beSH. Peter Anvin void * __init extend_brk(size_t size, size_t align) 2545368a2beSH. Peter Anvin { 2555368a2beSH. Peter Anvin size_t mask = align - 1; 2565368a2beSH. Peter Anvin void *ret; 2575368a2beSH. Peter Anvin 2585368a2beSH. Peter Anvin BUG_ON(_brk_start == 0); 2595368a2beSH. Peter Anvin BUG_ON(align & mask); 2605368a2beSH. Peter Anvin 2615368a2beSH. Peter Anvin _brk_end = (_brk_end + mask) & ~mask; 2625368a2beSH. Peter Anvin BUG_ON((char *)(_brk_end + size) > __brk_limit); 2635368a2beSH. Peter Anvin 2645368a2beSH. Peter Anvin ret = (void *)_brk_end; 2655368a2beSH. Peter Anvin _brk_end += size; 2665368a2beSH. Peter Anvin 2675368a2beSH. Peter Anvin memset(ret, 0, size); 2685368a2beSH. Peter Anvin 2695368a2beSH. Peter Anvin return ret; 2705368a2beSH. Peter Anvin } 2715368a2beSH. Peter Anvin 272148b2098SYinghai Lu #ifdef CONFIG_X86_32 273e5f15b45SYinghai Lu static void __init cleanup_highmap(void) 274f005fe12SYinghai Lu { 275f005fe12SYinghai Lu } 276854c879fSPekka J Enberg #endif 277854c879fSPekka J Enberg 2785368a2beSH. Peter Anvin static void __init reserve_brk(void) 2795368a2beSH. Peter Anvin { 2805368a2beSH. Peter Anvin if (_brk_end > _brk_start) 281fc8d7826SAlexander Duyck memblock_reserve(__pa_symbol(_brk_start), 282fc8d7826SAlexander Duyck _brk_end - _brk_start); 2835368a2beSH. Peter Anvin 2845368a2beSH. Peter Anvin /* Mark brk area as locked down and no longer taking any 2855368a2beSH. Peter Anvin new allocations */ 2865368a2beSH. Peter Anvin _brk_start = 0; 2875368a2beSH. Peter Anvin } 2885368a2beSH. Peter Anvin 2895aa3d718SBorislav Petkov u64 relocated_ramdisk; 2905aa3d718SBorislav Petkov 29155f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_INITRD 29255f26239SYinghai Lu 293a8a51a88SYinghai Lu static u64 __init get_ramdisk_image(void) 294a8a51a88SYinghai Lu { 295a8a51a88SYinghai Lu u64 ramdisk_image = boot_params.hdr.ramdisk_image; 296a8a51a88SYinghai Lu 297ee92d815SYinghai Lu ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; 298ee92d815SYinghai Lu 299a8a51a88SYinghai Lu return ramdisk_image; 300a8a51a88SYinghai Lu } 301a8a51a88SYinghai Lu static u64 __init get_ramdisk_size(void) 302a8a51a88SYinghai Lu { 303a8a51a88SYinghai Lu u64 ramdisk_size = boot_params.hdr.ramdisk_size; 304a8a51a88SYinghai Lu 305ee92d815SYinghai Lu ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; 306ee92d815SYinghai Lu 307a8a51a88SYinghai Lu return ramdisk_size; 308a8a51a88SYinghai Lu } 309a8a51a88SYinghai Lu 31055f26239SYinghai Lu static void __init relocate_initrd(void) 31155f26239SYinghai Lu { 312c967da6aSYinghai Lu /* Assume only end is not page aligned */ 313a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 314a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 315c967da6aSYinghai Lu u64 area_size = PAGE_ALIGN(ramdisk_size); 31655f26239SYinghai Lu 317e8c57d40SYinghai Lu /* We need to move the initrd down into directly mapped mem */ 3185aa3d718SBorislav Petkov relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped), 319e8c57d40SYinghai Lu area_size, PAGE_SIZE); 32055f26239SYinghai Lu 3215aa3d718SBorislav Petkov if (!relocated_ramdisk) 32255f26239SYinghai Lu panic("Cannot find place for new RAMDISK of size %lld\n", 32355f26239SYinghai Lu ramdisk_size); 32455f26239SYinghai Lu 325e8c57d40SYinghai Lu /* Note: this includes all the mem currently occupied by 32655f26239SYinghai Lu the initrd, we rely on that fact to keep the data intact. */ 3275aa3d718SBorislav Petkov memblock_reserve(relocated_ramdisk, area_size); 3285aa3d718SBorislav Petkov initrd_start = relocated_ramdisk + PAGE_OFFSET; 32955f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 330365811d6SBjorn Helgaas printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", 3315aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 33255f26239SYinghai Lu 3335dd2c4bdSMark Salter copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size); 33455f26239SYinghai Lu 335365811d6SBjorn Helgaas printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to" 336365811d6SBjorn Helgaas " [mem %#010llx-%#010llx]\n", 33755f26239SYinghai Lu ramdisk_image, ramdisk_image + ramdisk_size - 1, 3385aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 33955f26239SYinghai Lu } 34055f26239SYinghai Lu 3411b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3421b8c78beSYinghai Lu { 3431b8c78beSYinghai Lu /* Assume only end is not page aligned */ 344a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 345a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 3461b8c78beSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 3471b8c78beSYinghai Lu 3481b8c78beSYinghai Lu if (!boot_params.hdr.type_of_loader || 3491b8c78beSYinghai Lu !ramdisk_image || !ramdisk_size) 3501b8c78beSYinghai Lu return; /* No initrd provided by bootloader */ 3511b8c78beSYinghai Lu 3521b8c78beSYinghai Lu memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); 3531b8c78beSYinghai Lu } 35455f26239SYinghai Lu static void __init reserve_initrd(void) 35555f26239SYinghai Lu { 356c967da6aSYinghai Lu /* Assume only end is not page aligned */ 357a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 358a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 359c967da6aSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 360e8c57d40SYinghai Lu u64 mapped_size; 36155f26239SYinghai Lu 36255f26239SYinghai Lu if (!boot_params.hdr.type_of_loader || 36355f26239SYinghai Lu !ramdisk_image || !ramdisk_size) 36455f26239SYinghai Lu return; /* No initrd provided by bootloader */ 36555f26239SYinghai Lu 36655f26239SYinghai Lu initrd_start = 0; 36755f26239SYinghai Lu 368595ad9afSYinghai Lu mapped_size = memblock_mem_size(max_pfn_mapped); 369e8c57d40SYinghai Lu if (ramdisk_size >= (mapped_size>>1)) 370ab7b64e9SPeter Jones panic("initrd too large to handle, " 371ab7b64e9SPeter Jones "disabling initrd (%lld needed, %lld available)\n", 372e8c57d40SYinghai Lu ramdisk_size, mapped_size>>1); 37355f26239SYinghai Lu 374365811d6SBjorn Helgaas printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, 375365811d6SBjorn Helgaas ramdisk_end - 1); 37655f26239SYinghai Lu 37774f27655SYinghai Lu if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image), 378e8c57d40SYinghai Lu PFN_DOWN(ramdisk_end))) { 379e8c57d40SYinghai Lu /* All are mapped, easy case */ 38055f26239SYinghai Lu initrd_start = ramdisk_image + PAGE_OFFSET; 38155f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 38255f26239SYinghai Lu return; 38355f26239SYinghai Lu } 38455f26239SYinghai Lu 38555f26239SYinghai Lu relocate_initrd(); 3868c5dd8f4SYinghai Lu 38724aa0788STejun Heo memblock_free(ramdisk_image, ramdisk_end - ramdisk_image); 38855f26239SYinghai Lu } 389af06f8b7SLv Zheng 39055f26239SYinghai Lu #else 3911b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3921b8c78beSYinghai Lu { 3931b8c78beSYinghai Lu } 39455f26239SYinghai Lu static void __init reserve_initrd(void) 39555f26239SYinghai Lu { 39655f26239SYinghai Lu } 39755f26239SYinghai Lu #endif /* CONFIG_BLK_DEV_INITRD */ 39855f26239SYinghai Lu 39929f784e3SYinghai Lu static void __init parse_setup_data(void) 400257b0fdeSYinghai Lu { 401257b0fdeSYinghai Lu struct setup_data *data; 40230e46b57SLinn Crosetto u64 pa_data, pa_next; 403257b0fdeSYinghai Lu 404257b0fdeSYinghai Lu pa_data = boot_params.hdr.setup_data; 405257b0fdeSYinghai Lu while (pa_data) { 4067389882cSWANG Chao u32 data_len, data_type; 407f1c2b357SSebastian Andrzej Siewior 4087389882cSWANG Chao data = early_memremap(pa_data, sizeof(*data)); 409f1c2b357SSebastian Andrzej Siewior data_len = data->len + sizeof(struct setup_data); 41030e46b57SLinn Crosetto data_type = data->type; 41130e46b57SLinn Crosetto pa_next = data->next; 4128d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 413f1c2b357SSebastian Andrzej Siewior 41430e46b57SLinn Crosetto switch (data_type) { 415257b0fdeSYinghai Lu case SETUP_E820_EXT: 416914053c0SIngo Molnar e820__memory_setup_extended(pa_data, data_len); 417257b0fdeSYinghai Lu break; 418da6b737bSSebastian Andrzej Siewior case SETUP_DTB: 419da6b737bSSebastian Andrzej Siewior add_dtb(pa_data); 420257b0fdeSYinghai Lu break; 4211fec0533SDave Young case SETUP_EFI: 4221fec0533SDave Young parse_efi_setup(pa_data, data_len); 4231fec0533SDave Young break; 424257b0fdeSYinghai Lu default: 425257b0fdeSYinghai Lu break; 426257b0fdeSYinghai Lu } 42730e46b57SLinn Crosetto pa_data = pa_next; 428257b0fdeSYinghai Lu } 429257b0fdeSYinghai Lu } 430257b0fdeSYinghai Lu 431a9ce6bc1SYinghai Lu static void __init memblock_x86_reserve_range_setup_data(void) 432a0a0becdSYinghai Lu { 433a0a0becdSYinghai Lu struct setup_data *data; 434a0a0becdSYinghai Lu u64 pa_data; 435a0a0becdSYinghai Lu 436a0a0becdSYinghai Lu pa_data = boot_params.hdr.setup_data; 437a0a0becdSYinghai Lu while (pa_data) { 43888b4c146SJeremy Fitzhardinge data = early_memremap(pa_data, sizeof(*data)); 43924aa0788STejun Heo memblock_reserve(pa_data, sizeof(*data) + data->len); 440a0a0becdSYinghai Lu pa_data = data->next; 4418d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 442a0a0becdSYinghai Lu } 443a0a0becdSYinghai Lu } 444a0a0becdSYinghai Lu 44555f26239SYinghai Lu /* 446ccb4defaSYinghai Lu * --------- Crashkernel reservation ------------------------------ 447ccb4defaSYinghai Lu */ 448ccb4defaSYinghai Lu 4492965faa5SDave Young #ifdef CONFIG_KEXEC_CORE 45032105f7fSBernhard Walle 451606134f7SBorislav Petkov /* 16M alignment for crash kernel regions */ 452606134f7SBorislav Petkov #define CRASH_ALIGN (16 << 20) 453606134f7SBorislav Petkov 4547f8595bfSH. Peter Anvin /* 4557f8595bfSH. Peter Anvin * Keep the crash kernel below this limit. On 32 bits earlier kernels 4567f8595bfSH. Peter Anvin * would limit the kernel to the low 512 MiB due to mapping restrictions. 45755a20ee7SYinghai Lu * On 64bit, old kexec-tools need to under 896MiB. 4587f8595bfSH. Peter Anvin */ 4597f8595bfSH. Peter Anvin #ifdef CONFIG_X86_32 46097eac21bSBorislav Petkov # define CRASH_ADDR_LOW_MAX (512 << 20) 46197eac21bSBorislav Petkov # define CRASH_ADDR_HIGH_MAX (512 << 20) 4627f8595bfSH. Peter Anvin #else 46397eac21bSBorislav Petkov # define CRASH_ADDR_LOW_MAX (896UL << 20) 46497eac21bSBorislav Petkov # define CRASH_ADDR_HIGH_MAX MAXMEM 4657f8595bfSH. Peter Anvin #endif 4667f8595bfSH. Peter Anvin 467eb6db83dSBaoquan He static int __init reserve_crashkernel_low(void) 4680212f915SYinghai Lu { 4690212f915SYinghai Lu #ifdef CONFIG_X86_64 470f56d5578SBorislav Petkov unsigned long long base, low_base = 0, low_size = 0; 4710212f915SYinghai Lu unsigned long total_low_mem; 4720212f915SYinghai Lu int ret; 4730212f915SYinghai Lu 4740212f915SYinghai Lu total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); 47597eac21bSBorislav Petkov 476adbc742bSYinghai Lu /* crashkernel=Y,low */ 47797eac21bSBorislav Petkov ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base); 478f56d5578SBorislav Petkov if (ret) { 479c729de8fSYinghai Lu /* 480c729de8fSYinghai Lu * two parts from lib/swiotlb.c: 48194fb9334SJoerg Roedel * -swiotlb size: user-specified with swiotlb= or default. 48294fb9334SJoerg Roedel * 48394fb9334SJoerg Roedel * -swiotlb overflow buffer: now hardcoded to 32k. We round it 48494fb9334SJoerg Roedel * to 8M for other buffers that may need to stay low too. Also 48594fb9334SJoerg Roedel * make sure we allocate enough extra low memory so that we 48694fb9334SJoerg Roedel * don't run out of DMA buffers for 32-bit devices. 487c729de8fSYinghai Lu */ 48894fb9334SJoerg Roedel low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); 489c729de8fSYinghai Lu } else { 490adbc742bSYinghai Lu /* passed with crashkernel=0,low ? */ 491c729de8fSYinghai Lu if (!low_size) 492eb6db83dSBaoquan He return 0; 493c729de8fSYinghai Lu } 4940212f915SYinghai Lu 495fe2d48b8SJiri Bohac low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN); 4960212f915SYinghai Lu if (!low_base) { 497eb6db83dSBaoquan He pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", 498eb6db83dSBaoquan He (unsigned long)(low_size >> 20)); 499eb6db83dSBaoquan He return -ENOMEM; 5000212f915SYinghai Lu } 5010212f915SYinghai Lu 5026f376057SBorislav Petkov ret = memblock_reserve(low_base, low_size); 5036f376057SBorislav Petkov if (ret) { 5046f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel low memblock.\n", __func__); 5056f376057SBorislav Petkov return ret; 5066f376057SBorislav Petkov } 50797eac21bSBorislav Petkov 5080212f915SYinghai Lu pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n", 5090212f915SYinghai Lu (unsigned long)(low_size >> 20), 5100212f915SYinghai Lu (unsigned long)(low_base >> 20), 5110212f915SYinghai Lu (unsigned long)(total_low_mem >> 20)); 51297eac21bSBorislav Petkov 5130212f915SYinghai Lu crashk_low_res.start = low_base; 5140212f915SYinghai Lu crashk_low_res.end = low_base + low_size - 1; 5150212f915SYinghai Lu insert_resource(&iomem_resource, &crashk_low_res); 5160212f915SYinghai Lu #endif 517eb6db83dSBaoquan He return 0; 5180212f915SYinghai Lu } 5190212f915SYinghai Lu 52029f784e3SYinghai Lu static void __init reserve_crashkernel(void) 521ccb4defaSYinghai Lu { 522f56d5578SBorislav Petkov unsigned long long crash_size, crash_base, total_mem; 52355a20ee7SYinghai Lu bool high = false; 524ccb4defaSYinghai Lu int ret; 525ccb4defaSYinghai Lu 52609c71bfdSDave Young total_mem = memblock_phys_mem_size(); 527ccb4defaSYinghai Lu 52855a20ee7SYinghai Lu /* crashkernel=XM */ 52997eac21bSBorislav Petkov ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); 53055a20ee7SYinghai Lu if (ret != 0 || crash_size <= 0) { 531adbc742bSYinghai Lu /* crashkernel=X,high */ 53255a20ee7SYinghai Lu ret = parse_crashkernel_high(boot_command_line, total_mem, 53355a20ee7SYinghai Lu &crash_size, &crash_base); 53432105f7fSBernhard Walle if (ret != 0 || crash_size <= 0) 53532105f7fSBernhard Walle return; 53655a20ee7SYinghai Lu high = true; 53755a20ee7SYinghai Lu } 53832105f7fSBernhard Walle 53932105f7fSBernhard Walle /* 0 means: find the address automatically */ 540ccb4defaSYinghai Lu if (crash_base <= 0) { 5419f4c1396SYinghai Lu /* 542a8d4c824SXunlei Pang * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, 543a8d4c824SXunlei Pang * as old kexec-tools loads bzImage below that, unless 544a8d4c824SXunlei Pang * "crashkernel=size[KMG],high" is specified. 5459f4c1396SYinghai Lu */ 546606134f7SBorislav Petkov crash_base = memblock_find_in_range(CRASH_ALIGN, 54797eac21bSBorislav Petkov high ? CRASH_ADDR_HIGH_MAX 54897eac21bSBorislav Petkov : CRASH_ADDR_LOW_MAX, 549606134f7SBorislav Petkov crash_size, CRASH_ALIGN); 5501f5026a7STejun Heo if (!crash_base) { 55144280733SYinghai Lu pr_info("crashkernel reservation failed - No suitable area found.\n"); 552ccb4defaSYinghai Lu return; 553ccb4defaSYinghai Lu } 5540212f915SYinghai Lu 55532105f7fSBernhard Walle } else { 55644280733SYinghai Lu unsigned long long start; 55744280733SYinghai Lu 5589f4c1396SYinghai Lu start = memblock_find_in_range(crash_base, 55997eac21bSBorislav Petkov crash_base + crash_size, 56097eac21bSBorislav Petkov crash_size, 1 << 20); 56144280733SYinghai Lu if (start != crash_base) { 56244280733SYinghai Lu pr_info("crashkernel reservation failed - memory is in use.\n"); 563ccb4defaSYinghai Lu return; 564ccb4defaSYinghai Lu } 56532105f7fSBernhard Walle } 5666f376057SBorislav Petkov ret = memblock_reserve(crash_base, crash_size); 5676f376057SBorislav Petkov if (ret) { 5686f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel memblock.\n", __func__); 5696f376057SBorislav Petkov return; 5706f376057SBorislav Petkov } 571ccb4defaSYinghai Lu 572eb6db83dSBaoquan He if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { 573eb6db83dSBaoquan He memblock_free(crash_base, crash_size); 574eb6db83dSBaoquan He return; 575eb6db83dSBaoquan He } 576eb6db83dSBaoquan He 577f56d5578SBorislav Petkov pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", 578ccb4defaSYinghai Lu (unsigned long)(crash_size >> 20), 579ccb4defaSYinghai Lu (unsigned long)(crash_base >> 20), 580ccb4defaSYinghai Lu (unsigned long)(total_mem >> 20)); 581ccb4defaSYinghai Lu 582ccb4defaSYinghai Lu crashk_res.start = crash_base; 583ccb4defaSYinghai Lu crashk_res.end = crash_base + crash_size - 1; 584ccb4defaSYinghai Lu insert_resource(&iomem_resource, &crashk_res); 585ccb4defaSYinghai Lu } 586ccb4defaSYinghai Lu #else 58729f784e3SYinghai Lu static void __init reserve_crashkernel(void) 588ccb4defaSYinghai Lu { 589ccb4defaSYinghai Lu } 590ccb4defaSYinghai Lu #endif 591ccb4defaSYinghai Lu 592bdba0e70SYinghai Lu static struct resource standard_io_resources[] = { 593bdba0e70SYinghai Lu { .name = "dma1", .start = 0x00, .end = 0x1f, 594bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 595bdba0e70SYinghai Lu { .name = "pic1", .start = 0x20, .end = 0x21, 596bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 597bdba0e70SYinghai Lu { .name = "timer0", .start = 0x40, .end = 0x43, 598bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 599bdba0e70SYinghai Lu { .name = "timer1", .start = 0x50, .end = 0x53, 600bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 601bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x60, .end = 0x60, 602bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 603bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x64, .end = 0x64, 604bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 605bdba0e70SYinghai Lu { .name = "dma page reg", .start = 0x80, .end = 0x8f, 606bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 607bdba0e70SYinghai Lu { .name = "pic2", .start = 0xa0, .end = 0xa1, 608bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 609bdba0e70SYinghai Lu { .name = "dma2", .start = 0xc0, .end = 0xdf, 610bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 611bdba0e70SYinghai Lu { .name = "fpu", .start = 0xf0, .end = 0xff, 612bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO } 613bdba0e70SYinghai Lu }; 614bdba0e70SYinghai Lu 6158fee697dSThomas Gleixner void __init reserve_standard_io_resources(void) 616bdba0e70SYinghai Lu { 617bdba0e70SYinghai Lu int i; 618bdba0e70SYinghai Lu 619bdba0e70SYinghai Lu /* request I/O space for devices used on all i[345]86 PCs */ 620bdba0e70SYinghai Lu for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) 621bdba0e70SYinghai Lu request_resource(&ioport_resource, &standard_io_resources[i]); 622bdba0e70SYinghai Lu 623bdba0e70SYinghai Lu } 624bdba0e70SYinghai Lu 625042be38eSYinghai Lu static __init void reserve_ibft_region(void) 626042be38eSYinghai Lu { 627042be38eSYinghai Lu unsigned long addr, size = 0; 628042be38eSYinghai Lu 629042be38eSYinghai Lu addr = find_ibft_region(&size); 630042be38eSYinghai Lu 631042be38eSYinghai Lu if (size) 63224aa0788STejun Heo memblock_reserve(addr, size); 633042be38eSYinghai Lu } 634042be38eSYinghai Lu 635a9acc536SJesse Barnes static bool __init snb_gfx_workaround_needed(void) 636a9acc536SJesse Barnes { 637e43b3cecSH. Peter Anvin #ifdef CONFIG_PCI 638a9acc536SJesse Barnes int i; 639a9acc536SJesse Barnes u16 vendor, devid; 640ab3cd867SH. Peter Anvin static const __initconst u16 snb_ids[] = { 641a9acc536SJesse Barnes 0x0102, 642a9acc536SJesse Barnes 0x0112, 643a9acc536SJesse Barnes 0x0122, 644a9acc536SJesse Barnes 0x0106, 645a9acc536SJesse Barnes 0x0116, 646a9acc536SJesse Barnes 0x0126, 647a9acc536SJesse Barnes 0x010a, 648a9acc536SJesse Barnes }; 649a9acc536SJesse Barnes 650a9acc536SJesse Barnes /* Assume no if something weird is going on with PCI */ 651a9acc536SJesse Barnes if (!early_pci_allowed()) 652a9acc536SJesse Barnes return false; 653a9acc536SJesse Barnes 654a9acc536SJesse Barnes vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); 655a9acc536SJesse Barnes if (vendor != 0x8086) 656a9acc536SJesse Barnes return false; 657a9acc536SJesse Barnes 658a9acc536SJesse Barnes devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); 659a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(snb_ids); i++) 660a9acc536SJesse Barnes if (devid == snb_ids[i]) 661a9acc536SJesse Barnes return true; 662e43b3cecSH. Peter Anvin #endif 663a9acc536SJesse Barnes 664a9acc536SJesse Barnes return false; 665a9acc536SJesse Barnes } 666a9acc536SJesse Barnes 667a9acc536SJesse Barnes /* 668a9acc536SJesse Barnes * Sandy Bridge graphics has trouble with certain ranges, exclude 669a9acc536SJesse Barnes * them from allocation. 670a9acc536SJesse Barnes */ 671a9acc536SJesse Barnes static void __init trim_snb_memory(void) 672a9acc536SJesse Barnes { 673ab3cd867SH. Peter Anvin static const __initconst unsigned long bad_pages[] = { 674a9acc536SJesse Barnes 0x20050000, 675a9acc536SJesse Barnes 0x20110000, 676a9acc536SJesse Barnes 0x20130000, 677a9acc536SJesse Barnes 0x20138000, 678a9acc536SJesse Barnes 0x40004000, 679a9acc536SJesse Barnes }; 680a9acc536SJesse Barnes int i; 681a9acc536SJesse Barnes 682a9acc536SJesse Barnes if (!snb_gfx_workaround_needed()) 683a9acc536SJesse Barnes return; 684a9acc536SJesse Barnes 685a9acc536SJesse Barnes printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); 686a9acc536SJesse Barnes 687a9acc536SJesse Barnes /* 688a9acc536SJesse Barnes * Reserve all memory below the 1 MB mark that has not 689a9acc536SJesse Barnes * already been reserved. 690a9acc536SJesse Barnes */ 691a9acc536SJesse Barnes memblock_reserve(0, 1<<20); 692a9acc536SJesse Barnes 693a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { 694a9acc536SJesse Barnes if (memblock_reserve(bad_pages[i], PAGE_SIZE)) 695a9acc536SJesse Barnes printk(KERN_WARNING "failed to reserve 0x%08lx\n", 696a9acc536SJesse Barnes bad_pages[i]); 697a9acc536SJesse Barnes } 698a9acc536SJesse Barnes } 699a9acc536SJesse Barnes 700a9acc536SJesse Barnes /* 701a9acc536SJesse Barnes * Here we put platform-specific memory range workarounds, i.e. 702a9acc536SJesse Barnes * memory known to be corrupt or otherwise in need to be reserved on 703a9acc536SJesse Barnes * specific platforms. 704a9acc536SJesse Barnes * 705a9acc536SJesse Barnes * If this gets used more widely it could use a real dispatch mechanism. 706a9acc536SJesse Barnes */ 707a9acc536SJesse Barnes static void __init trim_platform_memory_ranges(void) 708a9acc536SJesse Barnes { 709a9acc536SJesse Barnes trim_snb_memory(); 710a9acc536SJesse Barnes } 711a9acc536SJesse Barnes 7121b5576e6SYinghai Lu static void __init trim_bios_range(void) 7131b5576e6SYinghai Lu { 7141b5576e6SYinghai Lu /* 7151b5576e6SYinghai Lu * A special case is the first 4Kb of memory; 7161b5576e6SYinghai Lu * This is a BIOS owned area, not kernel ram, but generally 7171b5576e6SYinghai Lu * not listed as such in the E820 table. 718d0cd7425SH. Peter Anvin * 719d0cd7425SH. Peter Anvin * This typically reserves additional memory (64KiB by default) 720d0cd7425SH. Peter Anvin * since some BIOSes are known to corrupt low memory. See the 7219ea77bdbSH. Peter Anvin * Kconfig help text for X86_RESERVE_LOW. 7221b5576e6SYinghai Lu */ 72309821ff1SIngo Molnar e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); 724d0cd7425SH. Peter Anvin 7251b5576e6SYinghai Lu /* 7261b5576e6SYinghai Lu * special case: Some BIOSen report the PC BIOS 7271b5576e6SYinghai Lu * area (640->1Mb) as ram even though it is not. 7281b5576e6SYinghai Lu * take them out. 7291b5576e6SYinghai Lu */ 73009821ff1SIngo Molnar e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); 731a9acc536SJesse Barnes 732f9748fa0SIngo Molnar e820__update_table(e820_table); 7331b5576e6SYinghai Lu } 7341b5576e6SYinghai Lu 735b422a309SYinghai Lu /* called before trim_bios_range() to spare extra sanitize */ 736b422a309SYinghai Lu static void __init e820_add_kernel_range(void) 737b422a309SYinghai Lu { 738b422a309SYinghai Lu u64 start = __pa_symbol(_text); 739b422a309SYinghai Lu u64 size = __pa_symbol(_end) - start; 740b422a309SYinghai Lu 741b422a309SYinghai Lu /* 74209821ff1SIngo Molnar * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and 743b422a309SYinghai Lu * attempt to fix it by adding the range. We may have a confused BIOS, 744b422a309SYinghai Lu * or the user may have used memmap=exactmap or memmap=xxM$yyM to 745b422a309SYinghai Lu * exclude kernel range. If we really are running on top non-RAM, 746b422a309SYinghai Lu * we will crash later anyways. 747b422a309SYinghai Lu */ 74809821ff1SIngo Molnar if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) 749b422a309SYinghai Lu return; 750b422a309SYinghai Lu 75109821ff1SIngo Molnar pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); 75209821ff1SIngo Molnar e820__range_remove(start, size, E820_TYPE_RAM, 0); 75309821ff1SIngo Molnar e820__range_add(start, size, E820_TYPE_RAM); 754b422a309SYinghai Lu } 755b422a309SYinghai Lu 75695c96084SH. Peter Anvin static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10; 75795c96084SH. Peter Anvin 7589ea77bdbSH. Peter Anvin static int __init parse_reservelow(char *p) 7599ea77bdbSH. Peter Anvin { 7609ea77bdbSH. Peter Anvin unsigned long long size; 7619ea77bdbSH. Peter Anvin 7629ea77bdbSH. Peter Anvin if (!p) 7639ea77bdbSH. Peter Anvin return -EINVAL; 7649ea77bdbSH. Peter Anvin 7659ea77bdbSH. Peter Anvin size = memparse(p, &p); 7669ea77bdbSH. Peter Anvin 7679ea77bdbSH. Peter Anvin if (size < 4096) 7689ea77bdbSH. Peter Anvin size = 4096; 7699ea77bdbSH. Peter Anvin 7709ea77bdbSH. Peter Anvin if (size > 640*1024) 7719ea77bdbSH. Peter Anvin size = 640*1024; 7729ea77bdbSH. Peter Anvin 7739ea77bdbSH. Peter Anvin reserve_low = size; 7749ea77bdbSH. Peter Anvin 7759ea77bdbSH. Peter Anvin return 0; 7769ea77bdbSH. Peter Anvin } 7779ea77bdbSH. Peter Anvin 7789ea77bdbSH. Peter Anvin early_param("reservelow", parse_reservelow); 7799ea77bdbSH. Peter Anvin 78095c96084SH. Peter Anvin static void __init trim_low_memory_range(void) 78195c96084SH. Peter Anvin { 78295c96084SH. Peter Anvin memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); 78395c96084SH. Peter Anvin } 78495c96084SH. Peter Anvin 7855394f80fSJeremy Fitzhardinge /* 786f32360efSKees Cook * Dump out kernel offset information on panic. 787f32360efSKees Cook */ 788f32360efSKees Cook static int 789f32360efSKees Cook dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) 790f32360efSKees Cook { 79178cac48cSBorislav Petkov if (kaslr_enabled()) { 79278cac48cSBorislav Petkov pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", 7934545c898SJiri Kosina kaslr_offset(), 79478cac48cSBorislav Petkov __START_KERNEL, 79578cac48cSBorislav Petkov __START_KERNEL_map, 79678cac48cSBorislav Petkov MODULES_VADDR-1); 79778cac48cSBorislav Petkov } else { 79878cac48cSBorislav Petkov pr_emerg("Kernel Offset: disabled\n"); 79978cac48cSBorislav Petkov } 800f32360efSKees Cook 801f32360efSKees Cook return 0; 802f32360efSKees Cook } 803f32360efSKees Cook 804f32360efSKees Cook /* 80555f26239SYinghai Lu * Determine if we were loaded by an EFI loader. If so, then we have also been 80655f26239SYinghai Lu * passed the efi memmap, systab, etc., so we should use these data structures 80755f26239SYinghai Lu * for initialization. Note, the efi init code path is determined by the 80855f26239SYinghai Lu * global efi_enabled. This allows the same kernel image to be used on existing 80955f26239SYinghai Lu * systems (with a traditional BIOS) as well as on EFI systems. 81055f26239SYinghai Lu */ 81155f26239SYinghai Lu /* 81255f26239SYinghai Lu * setup_arch - architecture-specific boot-time initializations 81355f26239SYinghai Lu * 81455f26239SYinghai Lu * Note: On x86_64, fixmaps are ready for use even before this is called. 81555f26239SYinghai Lu */ 81655f26239SYinghai Lu 81755f26239SYinghai Lu void __init setup_arch(char **cmdline_p) 81855f26239SYinghai Lu { 8196c902b65SYinghai Lu memblock_reserve(__pa_symbol(_text), 8206c902b65SYinghai Lu (unsigned long)__bss_stop - (unsigned long)_text); 8216c902b65SYinghai Lu 8221b8c78beSYinghai Lu early_reserve_initrd(); 8231b8c78beSYinghai Lu 8246c902b65SYinghai Lu /* 8256c902b65SYinghai Lu * At this point everything still needed from the boot loader 8266c902b65SYinghai Lu * or BIOS or kernel text should be early reserved or marked not 8276c902b65SYinghai Lu * RAM in e820. All other memory is free game. 8286c902b65SYinghai Lu */ 8296c902b65SYinghai Lu 83055f26239SYinghai Lu #ifdef CONFIG_X86_32 83155f26239SYinghai Lu memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); 832b40827faSBorislav Petkov 833b40827faSBorislav Petkov /* 834b40827faSBorislav Petkov * copy kernel address range established so far and switch 835b40827faSBorislav Petkov * to the proper swapper page table 836b40827faSBorislav Petkov */ 837b40827faSBorislav Petkov clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, 838b40827faSBorislav Petkov initial_page_table + KERNEL_PGD_BOUNDARY, 839b40827faSBorislav Petkov KERNEL_PGD_PTRS); 840b40827faSBorislav Petkov 841b40827faSBorislav Petkov load_cr3(swapper_pg_dir); 8422075244fSBryan O'Donoghue /* 8432075244fSBryan O'Donoghue * Note: Quark X1000 CPUs advertise PGE incorrectly and require 8442075244fSBryan O'Donoghue * a cr3 based tlb flush, so the following __flush_tlb_all() 8452075244fSBryan O'Donoghue * will not flush anything because the cpu quirk which clears 8462075244fSBryan O'Donoghue * X86_FEATURE_PGE has not been invoked yet. Though due to the 8472075244fSBryan O'Donoghue * load_cr3() above the TLB has been flushed already. The 8482075244fSBryan O'Donoghue * quirk is invoked before subsequent calls to __flush_tlb_all() 8492075244fSBryan O'Donoghue * so proper operation is guaranteed. 8502075244fSBryan O'Donoghue */ 851b40827faSBorislav Petkov __flush_tlb_all(); 85255f26239SYinghai Lu #else 85355f26239SYinghai Lu printk(KERN_INFO "Command line: %s\n", boot_command_line); 85455f26239SYinghai Lu #endif 85555f26239SYinghai Lu 8569863c90fSAlok Kataria /* 8579863c90fSAlok Kataria * If we have OLPC OFW, we might end up relocating the fixmap due to 8589863c90fSAlok Kataria * reserve_top(), so do this before touching the ioremap area. 8599863c90fSAlok Kataria */ 860fd699c76SAndres Salomon olpc_ofw_detect(); 861fd699c76SAndres Salomon 862433f8924SThomas Gleixner idt_setup_early_traps(); 8639e882c92SJeremy Fitzhardinge early_cpu_init(); 8641a98fd14SJeremy Fitzhardinge early_ioremap_init(); 8651a98fd14SJeremy Fitzhardinge 866fd699c76SAndres Salomon setup_olpc_ofw_pgd(); 867fd699c76SAndres Salomon 86855f26239SYinghai Lu ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); 86955f26239SYinghai Lu screen_info = boot_params.screen_info; 87055f26239SYinghai Lu edid_info = boot_params.edid_info; 87155f26239SYinghai Lu #ifdef CONFIG_X86_32 87255f26239SYinghai Lu apm_info.bios = boot_params.apm_bios_info; 87355f26239SYinghai Lu ist_info = boot_params.ist_info; 87455f26239SYinghai Lu #endif 87555f26239SYinghai Lu saved_video_mode = boot_params.hdr.vid_mode; 87655f26239SYinghai Lu bootloader_type = boot_params.hdr.type_of_loader; 8775031296cSH. Peter Anvin if ((bootloader_type >> 4) == 0xe) { 8785031296cSH. Peter Anvin bootloader_type &= 0xf; 8795031296cSH. Peter Anvin bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; 8805031296cSH. Peter Anvin } 8815031296cSH. Peter Anvin bootloader_version = bootloader_type & 0xf; 8825031296cSH. Peter Anvin bootloader_version |= boot_params.hdr.ext_loader_ver << 4; 88355f26239SYinghai Lu 88455f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_RAM 88555f26239SYinghai Lu rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; 88655f26239SYinghai Lu rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0); 88755f26239SYinghai Lu rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0); 88855f26239SYinghai Lu #endif 88955f26239SYinghai Lu #ifdef CONFIG_EFI 89055f26239SYinghai Lu if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 8919402973dSDaniel Kiper EFI32_LOADER_SIGNATURE, 4)) { 8923e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 8931adbfa35SOlof Johansson } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 8949402973dSDaniel Kiper EFI64_LOADER_SIGNATURE, 4)) { 8953e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 8963e909599SMatt Fleming set_bit(EFI_64BIT, &efi.flags); 89755f26239SYinghai Lu } 89855f26239SYinghai Lu #endif 89955f26239SYinghai Lu 90042bbdb43SThomas Gleixner x86_init.oem.arch_setup(); 90155f26239SYinghai Lu 902419afdf5SBjorn Helgaas iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 903103e2063SIngo Molnar e820__memory_setup(); 90428bb2237SYinghai Lu parse_setup_data(); 90528bb2237SYinghai Lu 90655f26239SYinghai Lu copy_edd(); 90755f26239SYinghai Lu 90855f26239SYinghai Lu if (!boot_params.hdr.root_flags) 90955f26239SYinghai Lu root_mountflags &= ~MS_RDONLY; 91055f26239SYinghai Lu init_mm.start_code = (unsigned long) _text; 91155f26239SYinghai Lu init_mm.end_code = (unsigned long) _etext; 91255f26239SYinghai Lu init_mm.end_data = (unsigned long) _edata; 91393dbda7cSJeremy Fitzhardinge init_mm.brk = _brk_end; 91455f26239SYinghai Lu 915fe3d197fSDave Hansen mpx_mm_init(&init_mm); 916fe3d197fSDave Hansen 9174046d6e8SLinus Torvalds code_resource.start = __pa_symbol(_text); 9184046d6e8SLinus Torvalds code_resource.end = __pa_symbol(_etext)-1; 9194046d6e8SLinus Torvalds data_resource.start = __pa_symbol(_etext); 9204046d6e8SLinus Torvalds data_resource.end = __pa_symbol(_edata)-1; 9214046d6e8SLinus Torvalds bss_resource.start = __pa_symbol(__bss_start); 9224046d6e8SLinus Torvalds bss_resource.end = __pa_symbol(__bss_stop)-1; 9234046d6e8SLinus Torvalds 924516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 925516cbf37STim Bird #ifdef CONFIG_CMDLINE_OVERRIDE 926516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 927516cbf37STim Bird #else 928516cbf37STim Bird if (builtin_cmdline[0]) { 929516cbf37STim Bird /* append boot loader cmdline to builtin */ 930516cbf37STim Bird strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 931516cbf37STim Bird strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 932516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 933516cbf37STim Bird } 934516cbf37STim Bird #endif 935516cbf37STim Bird #endif 936516cbf37STim Bird 937eda6da92SYinghai Lu strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 938eda6da92SYinghai Lu *cmdline_p = command_line; 939eda6da92SYinghai Lu 940eda6da92SYinghai Lu /* 9414b0f3b81SKees Cook * x86_configure_nx() is called before parse_early_param() to detect 9424b0f3b81SKees Cook * whether hardware doesn't support NX (so that the early EHCI debug 9434b0f3b81SKees Cook * console setup can safely call set_fixmap()). It may then be called 9444b0f3b81SKees Cook * again from within noexec_setup() during parsing early parameters 9454b0f3b81SKees Cook * to honor the respective command line option. 946eda6da92SYinghai Lu */ 9474763ed4dSH. Peter Anvin x86_configure_nx(); 948eda6da92SYinghai Lu 949eda6da92SYinghai Lu parse_early_param(); 950eda6da92SYinghai Lu 951835bcec5SDave Young if (efi_enabled(EFI_BOOT)) 952835bcec5SDave Young efi_memblock_x86_reserve_range(); 95339fa104dSReza Arbab #ifdef CONFIG_MEMORY_HOTPLUG 95439fa104dSReza Arbab /* 95539fa104dSReza Arbab * Memory used by the kernel cannot be hot-removed because Linux 95639fa104dSReza Arbab * cannot migrate the kernel pages. When memory hotplug is 95739fa104dSReza Arbab * enabled, we should prevent memblock from allocating memory 95839fa104dSReza Arbab * for the kernel. 95939fa104dSReza Arbab * 96039fa104dSReza Arbab * ACPI SRAT records all hotpluggable memory ranges. But before 96139fa104dSReza Arbab * SRAT is parsed, we don't know about it. 96239fa104dSReza Arbab * 96339fa104dSReza Arbab * The kernel image is loaded into memory at very early time. We 96439fa104dSReza Arbab * cannot prevent this anyway. So on NUMA system, we set any 96539fa104dSReza Arbab * node the kernel resides in as un-hotpluggable. 96639fa104dSReza Arbab * 96739fa104dSReza Arbab * Since on modern servers, one node could have double-digit 96839fa104dSReza Arbab * gigabytes memory, we can assume the memory around the kernel 96939fa104dSReza Arbab * image is also un-hotpluggable. So before SRAT is parsed, just 97039fa104dSReza Arbab * allocate memory near the kernel image to try the best to keep 97139fa104dSReza Arbab * the kernel away from hotpluggable memory. 97239fa104dSReza Arbab */ 97339fa104dSReza Arbab if (movable_node_is_enabled()) 97439fa104dSReza Arbab memblock_set_bottom_up(true); 97539fa104dSReza Arbab #endif 97639fa104dSReza Arbab 9774b0f3b81SKees Cook x86_report_nx(); 9780ad5bce7SJeremy Fitzhardinge 97928bb2237SYinghai Lu /* after early param, so could get panic from serial */ 980a9ce6bc1SYinghai Lu memblock_x86_reserve_range_setup_data(); 98128bb2237SYinghai Lu 98255f26239SYinghai Lu if (acpi_mps_check()) { 98355f26239SYinghai Lu #ifdef CONFIG_X86_LOCAL_APIC 98455f26239SYinghai Lu disable_apic = 1; 98555f26239SYinghai Lu #endif 986988781dcSYinghai Lu setup_clear_cpu_cap(X86_FEATURE_APIC); 98755f26239SYinghai Lu } 98855f26239SYinghai Lu 989dc7c65dbSLinus Torvalds #ifdef CONFIG_PCI 990dc7c65dbSLinus Torvalds if (pci_early_dump_regs) 991dc7c65dbSLinus Torvalds early_dump_pci_devices(); 992dc7c65dbSLinus Torvalds #endif 993dc7c65dbSLinus Torvalds 9941a127034SIngo Molnar e820__reserve_setup_data(); 9959641bdafSIngo Molnar e820__finish_early_params(); 99655f26239SYinghai Lu 99783e68189SMatt Fleming if (efi_enabled(EFI_BOOT)) 998ff0c0874SBrian Maly efi_init(); 999ff0c0874SBrian Maly 10002216d199SYinghai Lu dmi_scan_machine(); 1001dd6dad42SChen, Gong dmi_memdev_walk(); 100298e5e1bfSTejun Heo dmi_set_dump_stack_arch_desc(); 10032216d199SYinghai Lu 100488b094fbSAlok Kataria /* 100588b094fbSAlok Kataria * VMware detection requires dmi to be available, so this 1006a1652bb8SJean Delvare * needs to be done after dmi_scan_machine(), for the boot CPU. 100788b094fbSAlok Kataria */ 10082d826404SThomas Gleixner init_hypervisor_platform(); 100988b094fbSAlok Kataria 1010f7cf5a5bSThomas Gleixner x86_init.resources.probe_roms(); 101155f26239SYinghai Lu 10124046d6e8SLinus Torvalds /* after parse_early_param, so could debug it */ 10134046d6e8SLinus Torvalds insert_resource(&iomem_resource, &code_resource); 10144046d6e8SLinus Torvalds insert_resource(&iomem_resource, &data_resource); 10154046d6e8SLinus Torvalds insert_resource(&iomem_resource, &bss_resource); 10164046d6e8SLinus Torvalds 1017b422a309SYinghai Lu e820_add_kernel_range(); 10181b5576e6SYinghai Lu trim_bios_range(); 101955f26239SYinghai Lu #ifdef CONFIG_X86_32 102055f26239SYinghai Lu if (ppro_with_ram_bug()) { 102109821ff1SIngo Molnar e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, 102209821ff1SIngo Molnar E820_TYPE_RESERVED); 1023f9748fa0SIngo Molnar e820__update_table(e820_table); 102455f26239SYinghai Lu printk(KERN_INFO "fixed physical RAM map:\n"); 1025be0c3f0fSIngo Molnar e820__print_table("bad_ppro"); 102655f26239SYinghai Lu } 102755f26239SYinghai Lu #else 102855f26239SYinghai Lu early_gart_iommu_check(); 102955f26239SYinghai Lu #endif 103055f26239SYinghai Lu 103155f26239SYinghai Lu /* 103255f26239SYinghai Lu * partially used pages are not usable - thus 103355f26239SYinghai Lu * we are rounding upwards: 103455f26239SYinghai Lu */ 10350c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 103655f26239SYinghai Lu 103755f26239SYinghai Lu /* update e820 for memory not covered by WB MTRRs */ 103855f26239SYinghai Lu mtrr_bp_init(); 10392dc807b3SYinghai Lu if (mtrr_trim_uncached_memory(max_pfn)) 10400c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 104155f26239SYinghai Lu 10428dd33030SIgor Mammedov max_possible_pfn = max_pfn; 10438dd33030SIgor Mammedov 1044c7d2361fSThomas Garnier /* 104599c13b8cSMikulas Patocka * This call is required when the CPU does not support PAT. If 104699c13b8cSMikulas Patocka * mtrr_bp_init() invoked it already via pat_init() the call has no 104799c13b8cSMikulas Patocka * effect. 104899c13b8cSMikulas Patocka */ 104999c13b8cSMikulas Patocka init_cache_modes(); 105099c13b8cSMikulas Patocka 105199c13b8cSMikulas Patocka /* 1052c7d2361fSThomas Garnier * Define random base addresses for memory sections after max_pfn is 1053c7d2361fSThomas Garnier * defined and before each memory section base is used. 1054c7d2361fSThomas Garnier */ 1055c7d2361fSThomas Garnier kernel_randomize_memory(); 1056c7d2361fSThomas Garnier 105755f26239SYinghai Lu #ifdef CONFIG_X86_32 105855f26239SYinghai Lu /* max_low_pfn get updated here */ 105955f26239SYinghai Lu find_low_pfn_range(); 106055f26239SYinghai Lu #else 10616e1cb38aSSuresh Siddha check_x2apic(); 106255f26239SYinghai Lu 106355f26239SYinghai Lu /* How many end-of-memory variables you have, grandma! */ 106455f26239SYinghai Lu /* need this before calling reserve_initrd */ 1065f361a450SYinghai Lu if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) 10660c6fc11aSIngo Molnar max_low_pfn = e820__end_of_low_ram_pfn(); 1067f361a450SYinghai Lu else 106855f26239SYinghai Lu max_low_pfn = max_pfn; 1069f361a450SYinghai Lu 107055f26239SYinghai Lu high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 107155f26239SYinghai Lu #endif 107255f26239SYinghai Lu 1073893f38d1SYinghai Lu /* 1074893f38d1SYinghai Lu * Find and reserve possible boot-time SMP configuration: 1075893f38d1SYinghai Lu */ 1076893f38d1SYinghai Lu find_smp_config(); 1077893f38d1SYinghai Lu 1078042be38eSYinghai Lu reserve_ibft_region(); 1079042be38eSYinghai Lu 10808d57470dSYinghai Lu early_alloc_pgt_buf(); 10818d57470dSYinghai Lu 108272d7c3b3SYinghai Lu /* 10834918e228SIngo Molnar * Need to conclude brk, before e820__memblock_setup() 108472d7c3b3SYinghai Lu * it could use memblock_find_in_range, could overlap with 108572d7c3b3SYinghai Lu * brk area. 108672d7c3b3SYinghai Lu */ 108772d7c3b3SYinghai Lu reserve_brk(); 108872d7c3b3SYinghai Lu 1089e5f15b45SYinghai Lu cleanup_highmap(); 1090e5f15b45SYinghai Lu 10912449f343STang Chen memblock_set_current_limit(ISA_END_ADDRESS); 10924918e228SIngo Molnar e820__memblock_setup(); 109372d7c3b3SYinghai Lu 1094007b7560SAndy Lutomirski reserve_bios_regions(); 1095007b7560SAndy Lutomirski 10964971531aSMatt Fleming if (efi_enabled(EFI_MEMMAP)) { 10974971531aSMatt Fleming efi_fake_memmap(); 10984971531aSMatt Fleming efi_find_mirror(); 10993dad6f7fSRicardo Neri efi_esrt_init(); 11004971531aSMatt Fleming 1101916f676fSMatthew Garrett /* 11024971531aSMatt Fleming * The EFI specification says that boot service code won't be 11034971531aSMatt Fleming * called after ExitBootServices(). This is, in fact, a lie. 1104916f676fSMatthew Garrett */ 1105916f676fSMatthew Garrett efi_reserve_boot_services(); 11064971531aSMatt Fleming } 1107916f676fSMatthew Garrett 110872d7c3b3SYinghai Lu /* preallocate 4k for mptable mpc */ 11095da217caSIngo Molnar e820__memblock_alloc_reserved_mpc_new(); 111072d7c3b3SYinghai Lu 111172d7c3b3SYinghai Lu #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 111272d7c3b3SYinghai Lu setup_bios_corruption_check(); 111372d7c3b3SYinghai Lu #endif 111472d7c3b3SYinghai Lu 111510054230SYinghai Lu #ifdef CONFIG_X86_32 1116365811d6SBjorn Helgaas printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", 1117365811d6SBjorn Helgaas (max_pfn_mapped<<PAGE_SHIFT) - 1); 111810054230SYinghai Lu #endif 111972d7c3b3SYinghai Lu 11204f7b9226SYinghai Lu reserve_real_mode(); 1121893f38d1SYinghai Lu 1122a9acc536SJesse Barnes trim_platform_memory_ranges(); 112395c96084SH. Peter Anvin trim_low_memory_range(); 1124a9acc536SJesse Barnes 112522ddfcaaSYinghai Lu init_mem_mapping(); 1126854c879fSPekka J Enberg 1127433f8924SThomas Gleixner idt_setup_early_pf(); 1128cda846f1SJarkko Sakkinen 112918bc7bd5SAndy Lutomirski /* 113018bc7bd5SAndy Lutomirski * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) 113118bc7bd5SAndy Lutomirski * with the current CR4 value. This may not be necessary, but 113218bc7bd5SAndy Lutomirski * auditing all the early-boot CR4 manipulation would be needed to 113318bc7bd5SAndy Lutomirski * rule it out. 1134c7ad5ad2SAndy Lutomirski * 1135c7ad5ad2SAndy Lutomirski * Mask off features that don't work outside long mode (just 1136c7ad5ad2SAndy Lutomirski * PCIDE for now). 113718bc7bd5SAndy Lutomirski */ 1138c7ad5ad2SAndy Lutomirski mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; 113918bc7bd5SAndy Lutomirski 11404ce7a869SYinghai Lu memblock_set_current_limit(get_max_mapped()); 1141e7b37895SYinghai Lu 1142e7b37895SYinghai Lu /* 1143e7b37895SYinghai Lu * NOTE: On x86-32, only from this point on, fixmaps are ready for use. 1144e7b37895SYinghai Lu */ 1145e7b37895SYinghai Lu 1146e7b37895SYinghai Lu #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 1147e7b37895SYinghai Lu if (init_ohci1394_dma_early) 1148162a7e75SMike Travis init_ohci1394_dma_on_all_controllers(); 1149162a7e75SMike Travis #endif 1150e7b37895SYinghai Lu /* Allocate bigger log buffer */ 115155f26239SYinghai Lu setup_log_buf(1); 115255f26239SYinghai Lu 11539661b332SDavid Howells if (efi_enabled(EFI_BOOT)) { 11549661b332SDavid Howells switch (boot_params.secure_boot) { 11559661b332SDavid Howells case efi_secureboot_mode_disabled: 11569661b332SDavid Howells pr_info("Secure boot disabled\n"); 11579661b332SDavid Howells break; 11589661b332SDavid Howells case efi_secureboot_mode_enabled: 11599661b332SDavid Howells pr_info("Secure boot enabled\n"); 11609661b332SDavid Howells break; 11619661b332SDavid Howells default: 11629661b332SDavid Howells pr_info("Secure boot could not be determined\n"); 11639661b332SDavid Howells break; 11649661b332SDavid Howells } 11659661b332SDavid Howells } 11669661b332SDavid Howells 116744280733SYinghai Lu reserve_initrd(); 116844280733SYinghai Lu 1169da3d3f98SAleksey Makarov acpi_table_upgrade(); 117055f26239SYinghai Lu 117155f26239SYinghai Lu vsmp_init(); 117255f26239SYinghai Lu 117355f26239SYinghai Lu io_delay_init(); 117455f26239SYinghai Lu 1175630b3affSLukas Wunner early_platform_quirks(); 1176630b3affSLukas Wunner 117755f26239SYinghai Lu /* 117855f26239SYinghai Lu * Parse the ACPI tables for possible boot-time SMP configuration. 117955f26239SYinghai Lu */ 118020e6926dSYinghai Lu acpi_boot_table_init(); 118120e6926dSYinghai Lu 118220e6926dSYinghai Lu early_acpi_boot_init(); 118320e6926dSYinghai Lu 118491467bdfSBernhard Walle initmem_init(); 11853c325f82SWeijie Yang dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); 1186fa591c4aSTang Chen 1187fa591c4aSTang Chen /* 1188fa591c4aSTang Chen * Reserve memory for crash kernel after SRAT is parsed so that it 1189fa591c4aSTang Chen * won't consume hotpluggable memory. 1190fa591c4aSTang Chen */ 1191fa591c4aSTang Chen reserve_crashkernel(); 1192fa591c4aSTang Chen 119355f26239SYinghai Lu memblock_find_dma_reserve(); 119455f26239SYinghai Lu 119555f26239SYinghai Lu #ifdef CONFIG_KVM_GUEST 119655f26239SYinghai Lu kvmclock_init(); 1197030cb6c0SThomas Gleixner #endif 119855f26239SYinghai Lu 1199ccb64941SBoris Ostrovsky tsc_early_delay_calibrate(); 1200ccb64941SBoris Ostrovsky if (!early_xdbc_setup_hardware()) 1201ccb64941SBoris Ostrovsky early_xdbc_register_console(); 1202ccb64941SBoris Ostrovsky 1203030cb6c0SThomas Gleixner x86_init.paging.pagetable_init(); 120455f26239SYinghai Lu 1205ef7f0d6aSAndrey Ryabinin kasan_init(); 1206ef7f0d6aSAndrey Ryabinin 1207d2b6dc61SAndy Lutomirski /* 1208*945fd17aSThomas Gleixner * Sync back kernel address range. 1209*945fd17aSThomas Gleixner * 1210*945fd17aSThomas Gleixner * FIXME: Can the later sync in setup_cpu_entry_areas() replace 1211*945fd17aSThomas Gleixner * this call? 1212d2b6dc61SAndy Lutomirski */ 1213*945fd17aSThomas Gleixner sync_initial_page_table(); 1214d2b6dc61SAndy Lutomirski 121531625340SJoseph Cihula tboot_probe(); 121631625340SJoseph Cihula 121755f26239SYinghai Lu map_vsyscall(); 121855f26239SYinghai Lu 121955f26239SYinghai Lu generic_apic_probe(); 122055f26239SYinghai Lu 122155f26239SYinghai Lu early_quirks(); 122255f26239SYinghai Lu 122355f26239SYinghai Lu /* 122455f26239SYinghai Lu * Read APIC and some other early information from ACPI tables. 122555f26239SYinghai Lu */ 122655f26239SYinghai Lu acpi_boot_init(); 1227efafc8b2SFeng Tang sfi_init(); 1228a906fdaaSThomas Gleixner x86_dtb_init(); 1229efafc8b2SFeng Tang 123055f26239SYinghai Lu /* 123155f26239SYinghai Lu * get boot-time SMP configuration: 123255f26239SYinghai Lu */ 123355f26239SYinghai Lu get_smp_config(); 123455f26239SYinghai Lu 12351e90a13dSThomas Gleixner /* 12361e90a13dSThomas Gleixner * Systems w/o ACPI and mptables might not have it mapped the local 12371e90a13dSThomas Gleixner * APIC yet, but prefill_possible_map() might need to access it. 12381e90a13dSThomas Gleixner */ 12391e90a13dSThomas Gleixner init_apic_mappings(); 12401e90a13dSThomas Gleixner 1241329513a3SYinghai Lu prefill_possible_map(); 1242301e6190SYinghai Lu 12435f4765f9SYinghai Lu init_cpu_to_node(); 12445f4765f9SYinghai Lu 1245ca1b8862SThomas Gleixner io_apic_init_mappings(); 12469d6a4d08SYinghai Lu 1247f3614646SJuergen Gross x86_init.hyper.guest_late_init(); 124855f26239SYinghai Lu 12491506c8dcSIngo Molnar e820__reserve_resources(); 1250090d7171SIngo Molnar e820__register_nosave_regions(max_low_pfn); 125155f26239SYinghai Lu 12528fee697dSThomas Gleixner x86_init.resources.reserve_resources(); 125355f26239SYinghai Lu 12542df908baSIngo Molnar e820__setup_pci_gap(); 125555f26239SYinghai Lu 125655f26239SYinghai Lu #ifdef CONFIG_VT 125755f26239SYinghai Lu #if defined(CONFIG_VGA_CONSOLE) 125883e68189SMatt Fleming if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) 125955f26239SYinghai Lu conswitchp = &vga_con; 126055f26239SYinghai Lu #elif defined(CONFIG_DUMMY_CONSOLE) 126155f26239SYinghai Lu conswitchp = &dummy_con; 126255f26239SYinghai Lu #endif 126355f26239SYinghai Lu #endif 12646f30c1acSThomas Gleixner x86_init.oem.banner(); 1265a2202aa2SYong Wang 12666b617e22SFeng Tang x86_init.timers.wallclock_init(); 12676b617e22SFeng Tang 1268a2202aa2SYong Wang mcheck_init(); 1269f49aa448SJason Baron 1270dc326fcaSH. Peter Anvin arch_init_ideal_nops(); 1271b3c869d3SJohn Stultz 1272b3c869d3SJohn Stultz register_refined_jiffies(CLOCK_TICK_RATE); 12735189c2a7SOlof Johansson 12745189c2a7SOlof Johansson #ifdef CONFIG_EFI 1275a5d90c92SBorislav Petkov if (efi_enabled(EFI_BOOT)) 1276a5d90c92SBorislav Petkov efi_apply_memmap_quirks(); 12775189c2a7SOlof Johansson #endif 1278ee9f8fceSJosh Poimboeuf 1279ee9f8fceSJosh Poimboeuf unwind_init(); 128055f26239SYinghai Lu } 12815649b7c3SIngo Molnar 12829be1b56aSIngo Molnar #ifdef CONFIG_X86_32 12835649b7c3SIngo Molnar 12848fee697dSThomas Gleixner static struct resource video_ram_resource = { 12858fee697dSThomas Gleixner .name = "Video RAM area", 12868fee697dSThomas Gleixner .start = 0xa0000, 12878fee697dSThomas Gleixner .end = 0xbffff, 12888fee697dSThomas Gleixner .flags = IORESOURCE_BUSY | IORESOURCE_MEM 12899be1b56aSIngo Molnar }; 12909be1b56aSIngo Molnar 12918fee697dSThomas Gleixner void __init i386_reserve_resources(void) 12929be1b56aSIngo Molnar { 12938fee697dSThomas Gleixner request_resource(&iomem_resource, &video_ram_resource); 12948fee697dSThomas Gleixner reserve_standard_io_resources(); 12959be1b56aSIngo Molnar } 12969be1b56aSIngo Molnar 12979be1b56aSIngo Molnar #endif /* CONFIG_X86_32 */ 1298f32360efSKees Cook 1299f32360efSKees Cook static struct notifier_block kernel_offset_notifier = { 1300f32360efSKees Cook .notifier_call = dump_kernel_offset 1301f32360efSKees Cook }; 1302f32360efSKees Cook 1303f32360efSKees Cook static int __init register_kernel_offset_dumper(void) 1304f32360efSKees Cook { 1305f32360efSKees Cook atomic_notifier_chain_register(&panic_notifier_list, 1306f32360efSKees Cook &kernel_offset_notifier); 1307f32360efSKees Cook return 0; 1308f32360efSKees Cook } 1309f32360efSKees Cook __initcall(register_kernel_offset_dumper); 1310c1192f84SDave Hansen 1311c1192f84SDave Hansen void arch_show_smap(struct seq_file *m, struct vm_area_struct *vma) 1312c1192f84SDave Hansen { 1313c1192f84SDave Hansen if (!boot_cpu_has(X86_FEATURE_OSPKE)) 1314c1192f84SDave Hansen return; 1315c1192f84SDave Hansen 1316c1192f84SDave Hansen seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); 1317c1192f84SDave Hansen } 1318