1*457c8996SThomas 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 /* 4567f8595bfSH. Peter Anvin * Keep the crash kernel below this limit. On 32 bits earlier kernels 4577f8595bfSH. Peter Anvin * would limit the kernel to the low 512 MiB due to mapping restrictions. 4587f8595bfSH. Peter Anvin */ 4597f8595bfSH. Peter Anvin #ifdef CONFIG_X86_32 4609ca5c8e6SDave Young # define CRASH_ADDR_LOW_MAX SZ_512M 4619ca5c8e6SDave Young # define CRASH_ADDR_HIGH_MAX SZ_512M 4627f8595bfSH. Peter Anvin #else 4639ca5c8e6SDave Young # define CRASH_ADDR_LOW_MAX SZ_4G 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 5393db3eb28SPetr Tesarik if (xen_pv_domain()) { 5403db3eb28SPetr Tesarik pr_info("Ignoring crashkernel for a Xen PV domain\n"); 5413db3eb28SPetr Tesarik return; 5423db3eb28SPetr Tesarik } 5433db3eb28SPetr Tesarik 54432105f7fSBernhard Walle /* 0 means: find the address automatically */ 545b9ac3849SDave Young if (!crash_base) { 5469f4c1396SYinghai Lu /* 547a8d4c824SXunlei Pang * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, 548b9ac3849SDave Young * crashkernel=x,high reserves memory over 4G, also allocates 549b9ac3849SDave Young * 256M extra low memory for DMA buffers and swiotlb. 550b9ac3849SDave Young * But the extra memory is not required for all machines. 551b9ac3849SDave Young * So try low memory first and fall back to high memory 552b9ac3849SDave Young * unless "crashkernel=size[KMG],high" is specified. 5539f4c1396SYinghai Lu */ 554b9ac3849SDave Young if (!high) 555606134f7SBorislav Petkov crash_base = memblock_find_in_range(CRASH_ALIGN, 556b9ac3849SDave Young CRASH_ADDR_LOW_MAX, 557b9ac3849SDave Young crash_size, CRASH_ALIGN); 558b9ac3849SDave Young if (!crash_base) 559b9ac3849SDave Young crash_base = memblock_find_in_range(CRASH_ALIGN, 560b9ac3849SDave Young CRASH_ADDR_HIGH_MAX, 561606134f7SBorislav Petkov crash_size, CRASH_ALIGN); 5621f5026a7STejun Heo if (!crash_base) { 56344280733SYinghai Lu pr_info("crashkernel reservation failed - No suitable area found.\n"); 564ccb4defaSYinghai Lu return; 565ccb4defaSYinghai Lu } 56632105f7fSBernhard Walle } else { 56744280733SYinghai Lu unsigned long long start; 56844280733SYinghai Lu 5699f4c1396SYinghai Lu start = memblock_find_in_range(crash_base, 57097eac21bSBorislav Petkov crash_base + crash_size, 57197eac21bSBorislav Petkov crash_size, 1 << 20); 57244280733SYinghai Lu if (start != crash_base) { 57344280733SYinghai Lu pr_info("crashkernel reservation failed - memory is in use.\n"); 574ccb4defaSYinghai Lu return; 575ccb4defaSYinghai Lu } 57632105f7fSBernhard Walle } 5776f376057SBorislav Petkov ret = memblock_reserve(crash_base, crash_size); 5786f376057SBorislav Petkov if (ret) { 5796f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel memblock.\n", __func__); 5806f376057SBorislav Petkov return; 5816f376057SBorislav Petkov } 582ccb4defaSYinghai Lu 583eb6db83dSBaoquan He if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { 584eb6db83dSBaoquan He memblock_free(crash_base, crash_size); 585eb6db83dSBaoquan He return; 586eb6db83dSBaoquan He } 587eb6db83dSBaoquan He 588f56d5578SBorislav Petkov pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", 589ccb4defaSYinghai Lu (unsigned long)(crash_size >> 20), 590ccb4defaSYinghai Lu (unsigned long)(crash_base >> 20), 591ccb4defaSYinghai Lu (unsigned long)(total_mem >> 20)); 592ccb4defaSYinghai Lu 593ccb4defaSYinghai Lu crashk_res.start = crash_base; 594ccb4defaSYinghai Lu crashk_res.end = crash_base + crash_size - 1; 595ccb4defaSYinghai Lu insert_resource(&iomem_resource, &crashk_res); 596ccb4defaSYinghai Lu } 597ccb4defaSYinghai Lu #else 59829f784e3SYinghai Lu static void __init reserve_crashkernel(void) 599ccb4defaSYinghai Lu { 600ccb4defaSYinghai Lu } 601ccb4defaSYinghai Lu #endif 602ccb4defaSYinghai Lu 603bdba0e70SYinghai Lu static struct resource standard_io_resources[] = { 604bdba0e70SYinghai Lu { .name = "dma1", .start = 0x00, .end = 0x1f, 605bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 606bdba0e70SYinghai Lu { .name = "pic1", .start = 0x20, .end = 0x21, 607bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 608bdba0e70SYinghai Lu { .name = "timer0", .start = 0x40, .end = 0x43, 609bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 610bdba0e70SYinghai Lu { .name = "timer1", .start = 0x50, .end = 0x53, 611bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 612bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x60, .end = 0x60, 613bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 614bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x64, .end = 0x64, 615bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 616bdba0e70SYinghai Lu { .name = "dma page reg", .start = 0x80, .end = 0x8f, 617bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 618bdba0e70SYinghai Lu { .name = "pic2", .start = 0xa0, .end = 0xa1, 619bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 620bdba0e70SYinghai Lu { .name = "dma2", .start = 0xc0, .end = 0xdf, 621bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 622bdba0e70SYinghai Lu { .name = "fpu", .start = 0xf0, .end = 0xff, 623bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO } 624bdba0e70SYinghai Lu }; 625bdba0e70SYinghai Lu 6268fee697dSThomas Gleixner void __init reserve_standard_io_resources(void) 627bdba0e70SYinghai Lu { 628bdba0e70SYinghai Lu int i; 629bdba0e70SYinghai Lu 630bdba0e70SYinghai Lu /* request I/O space for devices used on all i[345]86 PCs */ 631bdba0e70SYinghai Lu for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) 632bdba0e70SYinghai Lu request_resource(&ioport_resource, &standard_io_resources[i]); 633bdba0e70SYinghai Lu 634bdba0e70SYinghai Lu } 635bdba0e70SYinghai Lu 636042be38eSYinghai Lu static __init void reserve_ibft_region(void) 637042be38eSYinghai Lu { 638042be38eSYinghai Lu unsigned long addr, size = 0; 639042be38eSYinghai Lu 640042be38eSYinghai Lu addr = find_ibft_region(&size); 641042be38eSYinghai Lu 642042be38eSYinghai Lu if (size) 64324aa0788STejun Heo memblock_reserve(addr, size); 644042be38eSYinghai Lu } 645042be38eSYinghai Lu 646a9acc536SJesse Barnes static bool __init snb_gfx_workaround_needed(void) 647a9acc536SJesse Barnes { 648e43b3cecSH. Peter Anvin #ifdef CONFIG_PCI 649a9acc536SJesse Barnes int i; 650a9acc536SJesse Barnes u16 vendor, devid; 651ab3cd867SH. Peter Anvin static const __initconst u16 snb_ids[] = { 652a9acc536SJesse Barnes 0x0102, 653a9acc536SJesse Barnes 0x0112, 654a9acc536SJesse Barnes 0x0122, 655a9acc536SJesse Barnes 0x0106, 656a9acc536SJesse Barnes 0x0116, 657a9acc536SJesse Barnes 0x0126, 658a9acc536SJesse Barnes 0x010a, 659a9acc536SJesse Barnes }; 660a9acc536SJesse Barnes 661a9acc536SJesse Barnes /* Assume no if something weird is going on with PCI */ 662a9acc536SJesse Barnes if (!early_pci_allowed()) 663a9acc536SJesse Barnes return false; 664a9acc536SJesse Barnes 665a9acc536SJesse Barnes vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); 666a9acc536SJesse Barnes if (vendor != 0x8086) 667a9acc536SJesse Barnes return false; 668a9acc536SJesse Barnes 669a9acc536SJesse Barnes devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); 670a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(snb_ids); i++) 671a9acc536SJesse Barnes if (devid == snb_ids[i]) 672a9acc536SJesse Barnes return true; 673e43b3cecSH. Peter Anvin #endif 674a9acc536SJesse Barnes 675a9acc536SJesse Barnes return false; 676a9acc536SJesse Barnes } 677a9acc536SJesse Barnes 678a9acc536SJesse Barnes /* 679a9acc536SJesse Barnes * Sandy Bridge graphics has trouble with certain ranges, exclude 680a9acc536SJesse Barnes * them from allocation. 681a9acc536SJesse Barnes */ 682a9acc536SJesse Barnes static void __init trim_snb_memory(void) 683a9acc536SJesse Barnes { 684ab3cd867SH. Peter Anvin static const __initconst unsigned long bad_pages[] = { 685a9acc536SJesse Barnes 0x20050000, 686a9acc536SJesse Barnes 0x20110000, 687a9acc536SJesse Barnes 0x20130000, 688a9acc536SJesse Barnes 0x20138000, 689a9acc536SJesse Barnes 0x40004000, 690a9acc536SJesse Barnes }; 691a9acc536SJesse Barnes int i; 692a9acc536SJesse Barnes 693a9acc536SJesse Barnes if (!snb_gfx_workaround_needed()) 694a9acc536SJesse Barnes return; 695a9acc536SJesse Barnes 696a9acc536SJesse Barnes printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); 697a9acc536SJesse Barnes 698a9acc536SJesse Barnes /* 699a9acc536SJesse Barnes * Reserve all memory below the 1 MB mark that has not 700a9acc536SJesse Barnes * already been reserved. 701a9acc536SJesse Barnes */ 702a9acc536SJesse Barnes memblock_reserve(0, 1<<20); 703a9acc536SJesse Barnes 704a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { 705a9acc536SJesse Barnes if (memblock_reserve(bad_pages[i], PAGE_SIZE)) 706a9acc536SJesse Barnes printk(KERN_WARNING "failed to reserve 0x%08lx\n", 707a9acc536SJesse Barnes bad_pages[i]); 708a9acc536SJesse Barnes } 709a9acc536SJesse Barnes } 710a9acc536SJesse Barnes 711a9acc536SJesse Barnes /* 712a9acc536SJesse Barnes * Here we put platform-specific memory range workarounds, i.e. 713a9acc536SJesse Barnes * memory known to be corrupt or otherwise in need to be reserved on 714a9acc536SJesse Barnes * specific platforms. 715a9acc536SJesse Barnes * 716a9acc536SJesse Barnes * If this gets used more widely it could use a real dispatch mechanism. 717a9acc536SJesse Barnes */ 718a9acc536SJesse Barnes static void __init trim_platform_memory_ranges(void) 719a9acc536SJesse Barnes { 720a9acc536SJesse Barnes trim_snb_memory(); 721a9acc536SJesse Barnes } 722a9acc536SJesse Barnes 7231b5576e6SYinghai Lu static void __init trim_bios_range(void) 7241b5576e6SYinghai Lu { 7251b5576e6SYinghai Lu /* 7261b5576e6SYinghai Lu * A special case is the first 4Kb of memory; 7271b5576e6SYinghai Lu * This is a BIOS owned area, not kernel ram, but generally 7281b5576e6SYinghai Lu * not listed as such in the E820 table. 729d0cd7425SH. Peter Anvin * 730d0cd7425SH. Peter Anvin * This typically reserves additional memory (64KiB by default) 731d0cd7425SH. Peter Anvin * since some BIOSes are known to corrupt low memory. See the 7329ea77bdbSH. Peter Anvin * Kconfig help text for X86_RESERVE_LOW. 7331b5576e6SYinghai Lu */ 73409821ff1SIngo Molnar e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); 735d0cd7425SH. Peter Anvin 7361b5576e6SYinghai Lu /* 7371b5576e6SYinghai Lu * special case: Some BIOSen report the PC BIOS 7381b5576e6SYinghai Lu * area (640->1Mb) as ram even though it is not. 7391b5576e6SYinghai Lu * take them out. 7401b5576e6SYinghai Lu */ 74109821ff1SIngo Molnar e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); 742a9acc536SJesse Barnes 743f9748fa0SIngo Molnar e820__update_table(e820_table); 7441b5576e6SYinghai Lu } 7451b5576e6SYinghai Lu 746b422a309SYinghai Lu /* called before trim_bios_range() to spare extra sanitize */ 747b422a309SYinghai Lu static void __init e820_add_kernel_range(void) 748b422a309SYinghai Lu { 749b422a309SYinghai Lu u64 start = __pa_symbol(_text); 750b422a309SYinghai Lu u64 size = __pa_symbol(_end) - start; 751b422a309SYinghai Lu 752b422a309SYinghai Lu /* 75309821ff1SIngo Molnar * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and 754b422a309SYinghai Lu * attempt to fix it by adding the range. We may have a confused BIOS, 755b422a309SYinghai Lu * or the user may have used memmap=exactmap or memmap=xxM$yyM to 756b422a309SYinghai Lu * exclude kernel range. If we really are running on top non-RAM, 757b422a309SYinghai Lu * we will crash later anyways. 758b422a309SYinghai Lu */ 75909821ff1SIngo Molnar if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) 760b422a309SYinghai Lu return; 761b422a309SYinghai Lu 76209821ff1SIngo Molnar pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); 76309821ff1SIngo Molnar e820__range_remove(start, size, E820_TYPE_RAM, 0); 76409821ff1SIngo Molnar e820__range_add(start, size, E820_TYPE_RAM); 765b422a309SYinghai Lu } 766b422a309SYinghai Lu 76795c96084SH. Peter Anvin static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10; 76895c96084SH. Peter Anvin 7699ea77bdbSH. Peter Anvin static int __init parse_reservelow(char *p) 7709ea77bdbSH. Peter Anvin { 7719ea77bdbSH. Peter Anvin unsigned long long size; 7729ea77bdbSH. Peter Anvin 7739ea77bdbSH. Peter Anvin if (!p) 7749ea77bdbSH. Peter Anvin return -EINVAL; 7759ea77bdbSH. Peter Anvin 7769ea77bdbSH. Peter Anvin size = memparse(p, &p); 7779ea77bdbSH. Peter Anvin 7789ea77bdbSH. Peter Anvin if (size < 4096) 7799ea77bdbSH. Peter Anvin size = 4096; 7809ea77bdbSH. Peter Anvin 7819ea77bdbSH. Peter Anvin if (size > 640*1024) 7829ea77bdbSH. Peter Anvin size = 640*1024; 7839ea77bdbSH. Peter Anvin 7849ea77bdbSH. Peter Anvin reserve_low = size; 7859ea77bdbSH. Peter Anvin 7869ea77bdbSH. Peter Anvin return 0; 7879ea77bdbSH. Peter Anvin } 7889ea77bdbSH. Peter Anvin 7899ea77bdbSH. Peter Anvin early_param("reservelow", parse_reservelow); 7909ea77bdbSH. Peter Anvin 79195c96084SH. Peter Anvin static void __init trim_low_memory_range(void) 79295c96084SH. Peter Anvin { 79395c96084SH. Peter Anvin memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); 79495c96084SH. Peter Anvin } 79595c96084SH. Peter Anvin 7965394f80fSJeremy Fitzhardinge /* 797f32360efSKees Cook * Dump out kernel offset information on panic. 798f32360efSKees Cook */ 799f32360efSKees Cook static int 800f32360efSKees Cook dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) 801f32360efSKees Cook { 80278cac48cSBorislav Petkov if (kaslr_enabled()) { 80378cac48cSBorislav Petkov pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", 8044545c898SJiri Kosina kaslr_offset(), 80578cac48cSBorislav Petkov __START_KERNEL, 80678cac48cSBorislav Petkov __START_KERNEL_map, 80778cac48cSBorislav Petkov MODULES_VADDR-1); 80878cac48cSBorislav Petkov } else { 80978cac48cSBorislav Petkov pr_emerg("Kernel Offset: disabled\n"); 81078cac48cSBorislav Petkov } 811f32360efSKees Cook 812f32360efSKees Cook return 0; 813f32360efSKees Cook } 814f32360efSKees Cook 815f32360efSKees Cook /* 81655f26239SYinghai Lu * Determine if we were loaded by an EFI loader. If so, then we have also been 81755f26239SYinghai Lu * passed the efi memmap, systab, etc., so we should use these data structures 81855f26239SYinghai Lu * for initialization. Note, the efi init code path is determined by the 81955f26239SYinghai Lu * global efi_enabled. This allows the same kernel image to be used on existing 82055f26239SYinghai Lu * systems (with a traditional BIOS) as well as on EFI systems. 82155f26239SYinghai Lu */ 82255f26239SYinghai Lu /* 82355f26239SYinghai Lu * setup_arch - architecture-specific boot-time initializations 82455f26239SYinghai Lu * 82555f26239SYinghai Lu * Note: On x86_64, fixmaps are ready for use even before this is called. 82655f26239SYinghai Lu */ 82755f26239SYinghai Lu 82855f26239SYinghai Lu void __init setup_arch(char **cmdline_p) 82955f26239SYinghai Lu { 8306c902b65SYinghai Lu memblock_reserve(__pa_symbol(_text), 8316c902b65SYinghai Lu (unsigned long)__bss_stop - (unsigned long)_text); 8326c902b65SYinghai Lu 83310a70416SAndi Kleen /* 83410a70416SAndi Kleen * Make sure page 0 is always reserved because on systems with 83510a70416SAndi Kleen * L1TF its contents can be leaked to user processes. 83610a70416SAndi Kleen */ 83710a70416SAndi Kleen memblock_reserve(0, PAGE_SIZE); 83810a70416SAndi Kleen 8391b8c78beSYinghai Lu early_reserve_initrd(); 8401b8c78beSYinghai Lu 8416c902b65SYinghai Lu /* 8426c902b65SYinghai Lu * At this point everything still needed from the boot loader 8436c902b65SYinghai Lu * or BIOS or kernel text should be early reserved or marked not 8446c902b65SYinghai Lu * RAM in e820. All other memory is free game. 8456c902b65SYinghai Lu */ 8466c902b65SYinghai Lu 84755f26239SYinghai Lu #ifdef CONFIG_X86_32 84855f26239SYinghai Lu memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); 849b40827faSBorislav Petkov 850b40827faSBorislav Petkov /* 851b40827faSBorislav Petkov * copy kernel address range established so far and switch 852b40827faSBorislav Petkov * to the proper swapper page table 853b40827faSBorislav Petkov */ 854b40827faSBorislav Petkov clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, 855b40827faSBorislav Petkov initial_page_table + KERNEL_PGD_BOUNDARY, 856b40827faSBorislav Petkov KERNEL_PGD_PTRS); 857b40827faSBorislav Petkov 858b40827faSBorislav Petkov load_cr3(swapper_pg_dir); 8592075244fSBryan O'Donoghue /* 8602075244fSBryan O'Donoghue * Note: Quark X1000 CPUs advertise PGE incorrectly and require 8612075244fSBryan O'Donoghue * a cr3 based tlb flush, so the following __flush_tlb_all() 8622075244fSBryan O'Donoghue * will not flush anything because the cpu quirk which clears 8632075244fSBryan O'Donoghue * X86_FEATURE_PGE has not been invoked yet. Though due to the 8642075244fSBryan O'Donoghue * load_cr3() above the TLB has been flushed already. The 8652075244fSBryan O'Donoghue * quirk is invoked before subsequent calls to __flush_tlb_all() 8662075244fSBryan O'Donoghue * so proper operation is guaranteed. 8672075244fSBryan O'Donoghue */ 868b40827faSBorislav Petkov __flush_tlb_all(); 86955f26239SYinghai Lu #else 87055f26239SYinghai Lu printk(KERN_INFO "Command line: %s\n", boot_command_line); 871162434e7SKirill A. Shutemov boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; 87255f26239SYinghai Lu #endif 87355f26239SYinghai Lu 8749863c90fSAlok Kataria /* 8759863c90fSAlok Kataria * If we have OLPC OFW, we might end up relocating the fixmap due to 8769863c90fSAlok Kataria * reserve_top(), so do this before touching the ioremap area. 8779863c90fSAlok Kataria */ 878fd699c76SAndres Salomon olpc_ofw_detect(); 879fd699c76SAndres Salomon 880433f8924SThomas Gleixner idt_setup_early_traps(); 8819e882c92SJeremy Fitzhardinge early_cpu_init(); 8828990cac6SPavel Tatashin arch_init_ideal_nops(); 8838990cac6SPavel Tatashin jump_label_init(); 8841a98fd14SJeremy Fitzhardinge early_ioremap_init(); 8851a98fd14SJeremy Fitzhardinge 886fd699c76SAndres Salomon setup_olpc_ofw_pgd(); 887fd699c76SAndres Salomon 88855f26239SYinghai Lu ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); 88955f26239SYinghai Lu screen_info = boot_params.screen_info; 89055f26239SYinghai Lu edid_info = boot_params.edid_info; 89155f26239SYinghai Lu #ifdef CONFIG_X86_32 89255f26239SYinghai Lu apm_info.bios = boot_params.apm_bios_info; 89355f26239SYinghai Lu ist_info = boot_params.ist_info; 89455f26239SYinghai Lu #endif 89555f26239SYinghai Lu saved_video_mode = boot_params.hdr.vid_mode; 89655f26239SYinghai Lu bootloader_type = boot_params.hdr.type_of_loader; 8975031296cSH. Peter Anvin if ((bootloader_type >> 4) == 0xe) { 8985031296cSH. Peter Anvin bootloader_type &= 0xf; 8995031296cSH. Peter Anvin bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; 9005031296cSH. Peter Anvin } 9015031296cSH. Peter Anvin bootloader_version = bootloader_type & 0xf; 9025031296cSH. Peter Anvin bootloader_version |= boot_params.hdr.ext_loader_ver << 4; 90355f26239SYinghai Lu 90455f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_RAM 90555f26239SYinghai Lu rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; 90655f26239SYinghai Lu rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0); 90755f26239SYinghai Lu rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0); 90855f26239SYinghai Lu #endif 90955f26239SYinghai Lu #ifdef CONFIG_EFI 91055f26239SYinghai Lu if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 9119402973dSDaniel Kiper EFI32_LOADER_SIGNATURE, 4)) { 9123e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 9131adbfa35SOlof Johansson } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 9149402973dSDaniel Kiper EFI64_LOADER_SIGNATURE, 4)) { 9153e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 9163e909599SMatt Fleming set_bit(EFI_64BIT, &efi.flags); 91755f26239SYinghai Lu } 91855f26239SYinghai Lu #endif 91955f26239SYinghai Lu 92042bbdb43SThomas Gleixner x86_init.oem.arch_setup(); 92155f26239SYinghai Lu 922419afdf5SBjorn Helgaas iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 923103e2063SIngo Molnar e820__memory_setup(); 92428bb2237SYinghai Lu parse_setup_data(); 92528bb2237SYinghai Lu 92655f26239SYinghai Lu copy_edd(); 92755f26239SYinghai Lu 92855f26239SYinghai Lu if (!boot_params.hdr.root_flags) 92955f26239SYinghai Lu root_mountflags &= ~MS_RDONLY; 93055f26239SYinghai Lu init_mm.start_code = (unsigned long) _text; 93155f26239SYinghai Lu init_mm.end_code = (unsigned long) _etext; 93255f26239SYinghai Lu init_mm.end_data = (unsigned long) _edata; 93393dbda7cSJeremy Fitzhardinge init_mm.brk = _brk_end; 93455f26239SYinghai Lu 935fe3d197fSDave Hansen mpx_mm_init(&init_mm); 936fe3d197fSDave Hansen 9374046d6e8SLinus Torvalds code_resource.start = __pa_symbol(_text); 9384046d6e8SLinus Torvalds code_resource.end = __pa_symbol(_etext)-1; 9394046d6e8SLinus Torvalds data_resource.start = __pa_symbol(_etext); 9404046d6e8SLinus Torvalds data_resource.end = __pa_symbol(_edata)-1; 9414046d6e8SLinus Torvalds bss_resource.start = __pa_symbol(__bss_start); 9424046d6e8SLinus Torvalds bss_resource.end = __pa_symbol(__bss_stop)-1; 9434046d6e8SLinus Torvalds 944516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 945516cbf37STim Bird #ifdef CONFIG_CMDLINE_OVERRIDE 946516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 947516cbf37STim Bird #else 948516cbf37STim Bird if (builtin_cmdline[0]) { 949516cbf37STim Bird /* append boot loader cmdline to builtin */ 950516cbf37STim Bird strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 951516cbf37STim Bird strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 952516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 953516cbf37STim Bird } 954516cbf37STim Bird #endif 955516cbf37STim Bird #endif 956516cbf37STim Bird 957eda6da92SYinghai Lu strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 958eda6da92SYinghai Lu *cmdline_p = command_line; 959eda6da92SYinghai Lu 960eda6da92SYinghai Lu /* 9614b0f3b81SKees Cook * x86_configure_nx() is called before parse_early_param() to detect 9624b0f3b81SKees Cook * whether hardware doesn't support NX (so that the early EHCI debug 9634b0f3b81SKees Cook * console setup can safely call set_fixmap()). It may then be called 9644b0f3b81SKees Cook * again from within noexec_setup() during parsing early parameters 9654b0f3b81SKees Cook * to honor the respective command line option. 966eda6da92SYinghai Lu */ 9674763ed4dSH. Peter Anvin x86_configure_nx(); 968eda6da92SYinghai Lu 969eda6da92SYinghai Lu parse_early_param(); 970eda6da92SYinghai Lu 971835bcec5SDave Young if (efi_enabled(EFI_BOOT)) 972835bcec5SDave Young efi_memblock_x86_reserve_range(); 97339fa104dSReza Arbab #ifdef CONFIG_MEMORY_HOTPLUG 97439fa104dSReza Arbab /* 97539fa104dSReza Arbab * Memory used by the kernel cannot be hot-removed because Linux 97639fa104dSReza Arbab * cannot migrate the kernel pages. When memory hotplug is 97739fa104dSReza Arbab * enabled, we should prevent memblock from allocating memory 97839fa104dSReza Arbab * for the kernel. 97939fa104dSReza Arbab * 98039fa104dSReza Arbab * ACPI SRAT records all hotpluggable memory ranges. But before 98139fa104dSReza Arbab * SRAT is parsed, we don't know about it. 98239fa104dSReza Arbab * 98339fa104dSReza Arbab * The kernel image is loaded into memory at very early time. We 98439fa104dSReza Arbab * cannot prevent this anyway. So on NUMA system, we set any 98539fa104dSReza Arbab * node the kernel resides in as un-hotpluggable. 98639fa104dSReza Arbab * 98739fa104dSReza Arbab * Since on modern servers, one node could have double-digit 98839fa104dSReza Arbab * gigabytes memory, we can assume the memory around the kernel 98939fa104dSReza Arbab * image is also un-hotpluggable. So before SRAT is parsed, just 99039fa104dSReza Arbab * allocate memory near the kernel image to try the best to keep 99139fa104dSReza Arbab * the kernel away from hotpluggable memory. 99239fa104dSReza Arbab */ 99339fa104dSReza Arbab if (movable_node_is_enabled()) 99439fa104dSReza Arbab memblock_set_bottom_up(true); 99539fa104dSReza Arbab #endif 99639fa104dSReza Arbab 9974b0f3b81SKees Cook x86_report_nx(); 9980ad5bce7SJeremy Fitzhardinge 99928bb2237SYinghai Lu /* after early param, so could get panic from serial */ 1000a9ce6bc1SYinghai Lu memblock_x86_reserve_range_setup_data(); 100128bb2237SYinghai Lu 100255f26239SYinghai Lu if (acpi_mps_check()) { 100355f26239SYinghai Lu #ifdef CONFIG_X86_LOCAL_APIC 100455f26239SYinghai Lu disable_apic = 1; 100555f26239SYinghai Lu #endif 1006988781dcSYinghai Lu setup_clear_cpu_cap(X86_FEATURE_APIC); 100755f26239SYinghai Lu } 100855f26239SYinghai Lu 10091a127034SIngo Molnar e820__reserve_setup_data(); 10109641bdafSIngo Molnar e820__finish_early_params(); 101155f26239SYinghai Lu 101283e68189SMatt Fleming if (efi_enabled(EFI_BOOT)) 1013ff0c0874SBrian Maly efi_init(); 1014ff0c0874SBrian Maly 10150fca0812SRobert Richter dmi_setup(); 10162216d199SYinghai Lu 101788b094fbSAlok Kataria /* 101888b094fbSAlok Kataria * VMware detection requires dmi to be available, so this 10190fca0812SRobert Richter * needs to be done after dmi_setup(), for the boot CPU. 102088b094fbSAlok Kataria */ 10212d826404SThomas Gleixner init_hypervisor_platform(); 102288b094fbSAlok Kataria 1023cf7a63efSPavel Tatashin tsc_early_init(); 1024f7cf5a5bSThomas Gleixner x86_init.resources.probe_roms(); 102555f26239SYinghai Lu 10264046d6e8SLinus Torvalds /* after parse_early_param, so could debug it */ 10274046d6e8SLinus Torvalds insert_resource(&iomem_resource, &code_resource); 10284046d6e8SLinus Torvalds insert_resource(&iomem_resource, &data_resource); 10294046d6e8SLinus Torvalds insert_resource(&iomem_resource, &bss_resource); 10304046d6e8SLinus Torvalds 1031b422a309SYinghai Lu e820_add_kernel_range(); 10321b5576e6SYinghai Lu trim_bios_range(); 103355f26239SYinghai Lu #ifdef CONFIG_X86_32 103455f26239SYinghai Lu if (ppro_with_ram_bug()) { 103509821ff1SIngo Molnar e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, 103609821ff1SIngo Molnar E820_TYPE_RESERVED); 1037f9748fa0SIngo Molnar e820__update_table(e820_table); 103855f26239SYinghai Lu printk(KERN_INFO "fixed physical RAM map:\n"); 1039be0c3f0fSIngo Molnar e820__print_table("bad_ppro"); 104055f26239SYinghai Lu } 104155f26239SYinghai Lu #else 104255f26239SYinghai Lu early_gart_iommu_check(); 104355f26239SYinghai Lu #endif 104455f26239SYinghai Lu 104555f26239SYinghai Lu /* 104655f26239SYinghai Lu * partially used pages are not usable - thus 104755f26239SYinghai Lu * we are rounding upwards: 104855f26239SYinghai Lu */ 10490c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 105055f26239SYinghai Lu 105155f26239SYinghai Lu /* update e820 for memory not covered by WB MTRRs */ 105255f26239SYinghai Lu mtrr_bp_init(); 10532dc807b3SYinghai Lu if (mtrr_trim_uncached_memory(max_pfn)) 10540c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 105555f26239SYinghai Lu 10568dd33030SIgor Mammedov max_possible_pfn = max_pfn; 10578dd33030SIgor Mammedov 1058c7d2361fSThomas Garnier /* 105999c13b8cSMikulas Patocka * This call is required when the CPU does not support PAT. If 106099c13b8cSMikulas Patocka * mtrr_bp_init() invoked it already via pat_init() the call has no 106199c13b8cSMikulas Patocka * effect. 106299c13b8cSMikulas Patocka */ 106399c13b8cSMikulas Patocka init_cache_modes(); 106499c13b8cSMikulas Patocka 106599c13b8cSMikulas Patocka /* 1066c7d2361fSThomas Garnier * Define random base addresses for memory sections after max_pfn is 1067c7d2361fSThomas Garnier * defined and before each memory section base is used. 1068c7d2361fSThomas Garnier */ 1069c7d2361fSThomas Garnier kernel_randomize_memory(); 1070c7d2361fSThomas Garnier 107155f26239SYinghai Lu #ifdef CONFIG_X86_32 107255f26239SYinghai Lu /* max_low_pfn get updated here */ 107355f26239SYinghai Lu find_low_pfn_range(); 107455f26239SYinghai Lu #else 10756e1cb38aSSuresh Siddha check_x2apic(); 107655f26239SYinghai Lu 107755f26239SYinghai Lu /* How many end-of-memory variables you have, grandma! */ 107855f26239SYinghai Lu /* need this before calling reserve_initrd */ 1079f361a450SYinghai Lu if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) 10800c6fc11aSIngo Molnar max_low_pfn = e820__end_of_low_ram_pfn(); 1081f361a450SYinghai Lu else 108255f26239SYinghai Lu max_low_pfn = max_pfn; 1083f361a450SYinghai Lu 108455f26239SYinghai Lu high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 108555f26239SYinghai Lu #endif 108655f26239SYinghai Lu 1087893f38d1SYinghai Lu /* 1088893f38d1SYinghai Lu * Find and reserve possible boot-time SMP configuration: 1089893f38d1SYinghai Lu */ 1090893f38d1SYinghai Lu find_smp_config(); 1091893f38d1SYinghai Lu 1092042be38eSYinghai Lu reserve_ibft_region(); 1093042be38eSYinghai Lu 10948d57470dSYinghai Lu early_alloc_pgt_buf(); 10958d57470dSYinghai Lu 109672d7c3b3SYinghai Lu /* 10974918e228SIngo Molnar * Need to conclude brk, before e820__memblock_setup() 109872d7c3b3SYinghai Lu * it could use memblock_find_in_range, could overlap with 109972d7c3b3SYinghai Lu * brk area. 110072d7c3b3SYinghai Lu */ 110172d7c3b3SYinghai Lu reserve_brk(); 110272d7c3b3SYinghai Lu 1103e5f15b45SYinghai Lu cleanup_highmap(); 1104e5f15b45SYinghai Lu 11052449f343STang Chen memblock_set_current_limit(ISA_END_ADDRESS); 11064918e228SIngo Molnar e820__memblock_setup(); 110772d7c3b3SYinghai Lu 1108007b7560SAndy Lutomirski reserve_bios_regions(); 1109007b7560SAndy Lutomirski 11104971531aSMatt Fleming if (efi_enabled(EFI_MEMMAP)) { 11114971531aSMatt Fleming efi_fake_memmap(); 11124971531aSMatt Fleming efi_find_mirror(); 11133dad6f7fSRicardo Neri efi_esrt_init(); 11144971531aSMatt Fleming 1115916f676fSMatthew Garrett /* 11164971531aSMatt Fleming * The EFI specification says that boot service code won't be 11174971531aSMatt Fleming * called after ExitBootServices(). This is, in fact, a lie. 1118916f676fSMatthew Garrett */ 1119916f676fSMatthew Garrett efi_reserve_boot_services(); 11204971531aSMatt Fleming } 1121916f676fSMatthew Garrett 112272d7c3b3SYinghai Lu /* preallocate 4k for mptable mpc */ 11235da217caSIngo Molnar e820__memblock_alloc_reserved_mpc_new(); 112472d7c3b3SYinghai Lu 112572d7c3b3SYinghai Lu #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 112672d7c3b3SYinghai Lu setup_bios_corruption_check(); 112772d7c3b3SYinghai Lu #endif 112872d7c3b3SYinghai Lu 112910054230SYinghai Lu #ifdef CONFIG_X86_32 1130365811d6SBjorn Helgaas printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", 1131365811d6SBjorn Helgaas (max_pfn_mapped<<PAGE_SHIFT) - 1); 113210054230SYinghai Lu #endif 113372d7c3b3SYinghai Lu 11344f7b9226SYinghai Lu reserve_real_mode(); 1135893f38d1SYinghai Lu 1136a9acc536SJesse Barnes trim_platform_memory_ranges(); 113795c96084SH. Peter Anvin trim_low_memory_range(); 1138a9acc536SJesse Barnes 113922ddfcaaSYinghai Lu init_mem_mapping(); 1140854c879fSPekka J Enberg 1141433f8924SThomas Gleixner idt_setup_early_pf(); 1142cda846f1SJarkko Sakkinen 114318bc7bd5SAndy Lutomirski /* 114418bc7bd5SAndy Lutomirski * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) 114518bc7bd5SAndy Lutomirski * with the current CR4 value. This may not be necessary, but 114618bc7bd5SAndy Lutomirski * auditing all the early-boot CR4 manipulation would be needed to 114718bc7bd5SAndy Lutomirski * rule it out. 1148c7ad5ad2SAndy Lutomirski * 1149c7ad5ad2SAndy Lutomirski * Mask off features that don't work outside long mode (just 1150c7ad5ad2SAndy Lutomirski * PCIDE for now). 115118bc7bd5SAndy Lutomirski */ 1152c7ad5ad2SAndy Lutomirski mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; 115318bc7bd5SAndy Lutomirski 11544ce7a869SYinghai Lu memblock_set_current_limit(get_max_mapped()); 1155e7b37895SYinghai Lu 1156e7b37895SYinghai Lu /* 1157e7b37895SYinghai Lu * NOTE: On x86-32, only from this point on, fixmaps are ready for use. 1158e7b37895SYinghai Lu */ 1159e7b37895SYinghai Lu 1160e7b37895SYinghai Lu #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 1161e7b37895SYinghai Lu if (init_ohci1394_dma_early) 1162162a7e75SMike Travis init_ohci1394_dma_on_all_controllers(); 1163162a7e75SMike Travis #endif 1164e7b37895SYinghai Lu /* Allocate bigger log buffer */ 116555f26239SYinghai Lu setup_log_buf(1); 116655f26239SYinghai Lu 11679661b332SDavid Howells if (efi_enabled(EFI_BOOT)) { 11689661b332SDavid Howells switch (boot_params.secure_boot) { 11699661b332SDavid Howells case efi_secureboot_mode_disabled: 11709661b332SDavid Howells pr_info("Secure boot disabled\n"); 11719661b332SDavid Howells break; 11729661b332SDavid Howells case efi_secureboot_mode_enabled: 11739661b332SDavid Howells pr_info("Secure boot enabled\n"); 11749661b332SDavid Howells break; 11759661b332SDavid Howells default: 11769661b332SDavid Howells pr_info("Secure boot could not be determined\n"); 11779661b332SDavid Howells break; 11789661b332SDavid Howells } 11799661b332SDavid Howells } 11809661b332SDavid Howells 118144280733SYinghai Lu reserve_initrd(); 118244280733SYinghai Lu 1183da3d3f98SAleksey Makarov acpi_table_upgrade(); 118455f26239SYinghai Lu 118555f26239SYinghai Lu vsmp_init(); 118655f26239SYinghai Lu 118755f26239SYinghai Lu io_delay_init(); 118855f26239SYinghai Lu 1189630b3affSLukas Wunner early_platform_quirks(); 1190630b3affSLukas Wunner 119155f26239SYinghai Lu /* 119255f26239SYinghai Lu * Parse the ACPI tables for possible boot-time SMP configuration. 119355f26239SYinghai Lu */ 119420e6926dSYinghai Lu acpi_boot_table_init(); 119520e6926dSYinghai Lu 119620e6926dSYinghai Lu early_acpi_boot_init(); 119720e6926dSYinghai Lu 119891467bdfSBernhard Walle initmem_init(); 11993c325f82SWeijie Yang dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); 1200fa591c4aSTang Chen 1201fa591c4aSTang Chen /* 1202fa591c4aSTang Chen * Reserve memory for crash kernel after SRAT is parsed so that it 1203fa591c4aSTang Chen * won't consume hotpluggable memory. 1204fa591c4aSTang Chen */ 1205fa591c4aSTang Chen reserve_crashkernel(); 1206fa591c4aSTang Chen 120755f26239SYinghai Lu memblock_find_dma_reserve(); 120855f26239SYinghai Lu 1209ccb64941SBoris Ostrovsky if (!early_xdbc_setup_hardware()) 1210ccb64941SBoris Ostrovsky early_xdbc_register_console(); 1211ccb64941SBoris Ostrovsky 1212030cb6c0SThomas Gleixner x86_init.paging.pagetable_init(); 121355f26239SYinghai Lu 1214ef7f0d6aSAndrey Ryabinin kasan_init(); 1215ef7f0d6aSAndrey Ryabinin 1216d2b6dc61SAndy Lutomirski /* 1217945fd17aSThomas Gleixner * Sync back kernel address range. 1218945fd17aSThomas Gleixner * 1219945fd17aSThomas Gleixner * FIXME: Can the later sync in setup_cpu_entry_areas() replace 1220945fd17aSThomas Gleixner * this call? 1221d2b6dc61SAndy Lutomirski */ 1222945fd17aSThomas Gleixner sync_initial_page_table(); 1223d2b6dc61SAndy Lutomirski 122431625340SJoseph Cihula tboot_probe(); 122531625340SJoseph Cihula 122655f26239SYinghai Lu map_vsyscall(); 122755f26239SYinghai Lu 122855f26239SYinghai Lu generic_apic_probe(); 122955f26239SYinghai Lu 123055f26239SYinghai Lu early_quirks(); 123155f26239SYinghai Lu 123255f26239SYinghai Lu /* 123355f26239SYinghai Lu * Read APIC and some other early information from ACPI tables. 123455f26239SYinghai Lu */ 123555f26239SYinghai Lu acpi_boot_init(); 1236efafc8b2SFeng Tang sfi_init(); 1237a906fdaaSThomas Gleixner x86_dtb_init(); 1238efafc8b2SFeng Tang 123955f26239SYinghai Lu /* 124055f26239SYinghai Lu * get boot-time SMP configuration: 124155f26239SYinghai Lu */ 124255f26239SYinghai Lu get_smp_config(); 124355f26239SYinghai Lu 12441e90a13dSThomas Gleixner /* 12451e90a13dSThomas Gleixner * Systems w/o ACPI and mptables might not have it mapped the local 12461e90a13dSThomas Gleixner * APIC yet, but prefill_possible_map() might need to access it. 12471e90a13dSThomas Gleixner */ 12481e90a13dSThomas Gleixner init_apic_mappings(); 12491e90a13dSThomas Gleixner 1250329513a3SYinghai Lu prefill_possible_map(); 1251301e6190SYinghai Lu 12525f4765f9SYinghai Lu init_cpu_to_node(); 12535f4765f9SYinghai Lu 1254ca1b8862SThomas Gleixner io_apic_init_mappings(); 12559d6a4d08SYinghai Lu 1256f3614646SJuergen Gross x86_init.hyper.guest_late_init(); 125755f26239SYinghai Lu 12581506c8dcSIngo Molnar e820__reserve_resources(); 1259cc55f753SZhimin Gu e820__register_nosave_regions(max_pfn); 126055f26239SYinghai Lu 12618fee697dSThomas Gleixner x86_init.resources.reserve_resources(); 126255f26239SYinghai Lu 12632df908baSIngo Molnar e820__setup_pci_gap(); 126455f26239SYinghai Lu 126555f26239SYinghai Lu #ifdef CONFIG_VT 126655f26239SYinghai Lu #if defined(CONFIG_VGA_CONSOLE) 126783e68189SMatt Fleming if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) 126855f26239SYinghai Lu conswitchp = &vga_con; 126955f26239SYinghai Lu #elif defined(CONFIG_DUMMY_CONSOLE) 127055f26239SYinghai Lu conswitchp = &dummy_con; 127155f26239SYinghai Lu #endif 127255f26239SYinghai Lu #endif 12736f30c1acSThomas Gleixner x86_init.oem.banner(); 1274a2202aa2SYong Wang 12756b617e22SFeng Tang x86_init.timers.wallclock_init(); 12766b617e22SFeng Tang 1277a2202aa2SYong Wang mcheck_init(); 1278f49aa448SJason Baron 1279b3c869d3SJohn Stultz register_refined_jiffies(CLOCK_TICK_RATE); 12805189c2a7SOlof Johansson 12815189c2a7SOlof Johansson #ifdef CONFIG_EFI 1282a5d90c92SBorislav Petkov if (efi_enabled(EFI_BOOT)) 1283a5d90c92SBorislav Petkov efi_apply_memmap_quirks(); 12845189c2a7SOlof Johansson #endif 1285ee9f8fceSJosh Poimboeuf 1286ee9f8fceSJosh Poimboeuf unwind_init(); 128755f26239SYinghai Lu } 12885649b7c3SIngo Molnar 12899be1b56aSIngo Molnar #ifdef CONFIG_X86_32 12905649b7c3SIngo Molnar 12918fee697dSThomas Gleixner static struct resource video_ram_resource = { 12928fee697dSThomas Gleixner .name = "Video RAM area", 12938fee697dSThomas Gleixner .start = 0xa0000, 12948fee697dSThomas Gleixner .end = 0xbffff, 12958fee697dSThomas Gleixner .flags = IORESOURCE_BUSY | IORESOURCE_MEM 12969be1b56aSIngo Molnar }; 12979be1b56aSIngo Molnar 12988fee697dSThomas Gleixner void __init i386_reserve_resources(void) 12999be1b56aSIngo Molnar { 13008fee697dSThomas Gleixner request_resource(&iomem_resource, &video_ram_resource); 13018fee697dSThomas Gleixner reserve_standard_io_resources(); 13029be1b56aSIngo Molnar } 13039be1b56aSIngo Molnar 13049be1b56aSIngo Molnar #endif /* CONFIG_X86_32 */ 1305f32360efSKees Cook 1306f32360efSKees Cook static struct notifier_block kernel_offset_notifier = { 1307f32360efSKees Cook .notifier_call = dump_kernel_offset 1308f32360efSKees Cook }; 1309f32360efSKees Cook 1310f32360efSKees Cook static int __init register_kernel_offset_dumper(void) 1311f32360efSKees Cook { 1312f32360efSKees Cook atomic_notifier_chain_register(&panic_notifier_list, 1313f32360efSKees Cook &kernel_offset_notifier); 1314f32360efSKees Cook return 0; 1315f32360efSKees Cook } 1316f32360efSKees Cook __initcall(register_kernel_offset_dumper); 1317