1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 255f26239SYinghai Lu /* 355f26239SYinghai Lu * Copyright (C) 1995 Linus Torvalds 455f26239SYinghai Lu * 555f26239SYinghai Lu * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 655f26239SYinghai Lu * 755f26239SYinghai Lu * Memory region support 855f26239SYinghai Lu * David Parsons <[email protected]>, July-August 1999 955f26239SYinghai Lu * 1055f26239SYinghai Lu * Added E820 sanitization routine (removes overlapping memory regions); 1155f26239SYinghai Lu * Brian Moyle <[email protected]>, February 2001 1255f26239SYinghai Lu * 1355f26239SYinghai Lu * Moved CPU detection code to cpu/${cpu}.c 1455f26239SYinghai Lu * Patrick Mochel <[email protected]>, March 2002 1555f26239SYinghai Lu * 1655f26239SYinghai Lu * Provisions for empty E820 memory regions (reported by certain BIOSes). 1755f26239SYinghai Lu * Alex Achenbach <[email protected]>, December 2002. 1855f26239SYinghai Lu * 1955f26239SYinghai Lu */ 2055f26239SYinghai Lu 2155f26239SYinghai Lu /* 2255f26239SYinghai Lu * This file handles the architecture-dependent parts of initialization 2355f26239SYinghai Lu */ 2455f26239SYinghai Lu 2555f26239SYinghai Lu #include <linux/sched.h> 2655f26239SYinghai Lu #include <linux/mm.h> 2755f26239SYinghai Lu #include <linux/mmzone.h> 2855f26239SYinghai Lu #include <linux/screen_info.h> 2955f26239SYinghai Lu #include <linux/ioport.h> 3055f26239SYinghai Lu #include <linux/acpi.h> 31efafc8b2SFeng Tang #include <linux/sfi.h> 3255f26239SYinghai Lu #include <linux/apm_bios.h> 3355f26239SYinghai Lu #include <linux/initrd.h> 3472d7c3b3SYinghai Lu #include <linux/memblock.h> 3555f26239SYinghai Lu #include <linux/seq_file.h> 3655f26239SYinghai Lu #include <linux/console.h> 3755f26239SYinghai Lu #include <linux/root_dev.h> 3855f26239SYinghai Lu #include <linux/highmem.h> 39186f4360SPaul Gortmaker #include <linux/export.h> 4055f26239SYinghai Lu #include <linux/efi.h> 4155f26239SYinghai Lu #include <linux/init.h> 4255f26239SYinghai Lu #include <linux/edd.h> 4355f26239SYinghai Lu #include <linux/iscsi_ibft.h> 4455f26239SYinghai Lu #include <linux/nodemask.h> 4555f26239SYinghai Lu #include <linux/kexec.h> 4655f26239SYinghai Lu #include <linux/dmi.h> 4755f26239SYinghai Lu #include <linux/pfn.h> 4855f26239SYinghai Lu #include <linux/pci.h> 4955f26239SYinghai Lu #include <asm/pci-direct.h> 5055f26239SYinghai Lu #include <linux/init_ohci1394_dma.h> 5155f26239SYinghai Lu #include <linux/kvm_para.h> 520a2b9a6eSMarek Szyprowski #include <linux/dma-contiguous.h> 533db3eb28SPetr Tesarik #include <xen/xen.h> 54e262e32dSDavid Howells #include <uapi/linux/mount.h> 5555f26239SYinghai Lu 5655f26239SYinghai Lu #include <linux/errno.h> 5755f26239SYinghai Lu #include <linux/kernel.h> 5855f26239SYinghai Lu #include <linux/stddef.h> 5955f26239SYinghai Lu #include <linux/unistd.h> 6055f26239SYinghai Lu #include <linux/ptrace.h> 6155f26239SYinghai Lu #include <linux/user.h> 6255f26239SYinghai Lu #include <linux/delay.h> 6355f26239SYinghai Lu 6455f26239SYinghai Lu #include <linux/kallsyms.h> 6555f26239SYinghai Lu #include <linux/cpufreq.h> 6655f26239SYinghai Lu #include <linux/dma-mapping.h> 6755f26239SYinghai Lu #include <linux/ctype.h> 6855f26239SYinghai Lu #include <linux/uaccess.h> 6955f26239SYinghai Lu 7055f26239SYinghai Lu #include <linux/percpu.h> 7155f26239SYinghai Lu #include <linux/crash_dump.h> 7269575d38SShane Wang #include <linux/tboot.h> 73b3c869d3SJohn Stultz #include <linux/jiffies.h> 74b9d05200STom Lendacky #include <linux/mem_encrypt.h> 759ca5c8e6SDave Young #include <linux/sizes.h> 7655f26239SYinghai Lu 771b5aeebfSLu Baolu #include <linux/usb/xhci-dbgp.h> 7855f26239SYinghai Lu #include <video/edid.h> 7955f26239SYinghai Lu 8055f26239SYinghai Lu #include <asm/mtrr.h> 8155f26239SYinghai Lu #include <asm/apic.h> 82084ee1c6SJarkko Sakkinen #include <asm/realmode.h> 8366441bd3SIngo Molnar #include <asm/e820/api.h> 8455f26239SYinghai Lu #include <asm/mpspec.h> 8555f26239SYinghai Lu #include <asm/setup.h> 8655f26239SYinghai Lu #include <asm/efi.h> 878e6dafd6SIngo Molnar #include <asm/timer.h> 888e6dafd6SIngo Molnar #include <asm/i8259.h> 8955f26239SYinghai Lu #include <asm/sections.h> 9055f26239SYinghai Lu #include <asm/io_apic.h> 9155f26239SYinghai Lu #include <asm/ist.h> 921164dd00SIngo Molnar #include <asm/setup_arch.h> 9355f26239SYinghai Lu #include <asm/bios_ebda.h> 9455f26239SYinghai Lu #include <asm/cacheflush.h> 9555f26239SYinghai Lu #include <asm/processor.h> 9655f26239SYinghai Lu #include <asm/bugs.h> 97ef7f0d6aSAndrey Ryabinin #include <asm/kasan.h> 9855f26239SYinghai Lu 9955f26239SYinghai Lu #include <asm/vsyscall.h> 1006e5385d4SJaswinder Singh Rajput #include <asm/cpu.h> 10155f26239SYinghai Lu #include <asm/desc.h> 10255f26239SYinghai Lu #include <asm/dma.h> 10346a7fa27SFUJITA Tomonori #include <asm/iommu.h> 1041d9b16d1SJoerg Roedel #include <asm/gart.h> 10555f26239SYinghai Lu #include <asm/mmu_context.h> 10655f26239SYinghai Lu #include <asm/proto.h> 10755f26239SYinghai Lu 10855f26239SYinghai Lu #include <asm/paravirt.h> 10988b094fbSAlok Kataria #include <asm/hypervisor.h> 110fd699c76SAndres Salomon #include <asm/olpc_ofw.h> 11155f26239SYinghai Lu 11255f26239SYinghai Lu #include <asm/percpu.h> 11355f26239SYinghai Lu #include <asm/topology.h> 11455f26239SYinghai Lu #include <asm/apicdef.h> 11523ac4ae8SAndreas Herrmann #include <asm/amd_nb.h> 116a2202aa2SYong Wang #include <asm/mce.h> 117f49aa448SJason Baron #include <asm/alternative.h> 118da6b737bSSebastian Andrzej Siewior #include <asm/prom.h> 1199a2bc335SBorislav Petkov #include <asm/microcode.h> 1200483e1faSThomas Garnier #include <asm/kaslr.h> 121ee9f8fceSJosh Poimboeuf #include <asm/unwind.h> 12255f26239SYinghai Lu 1232b72394eSPekka Enberg /* 12466520ebcSJacob Shin * max_low_pfn_mapped: highest direct mapped pfn under 4GB 12566520ebcSJacob Shin * max_pfn_mapped: highest direct mapped pfn over 4GB 12666520ebcSJacob Shin * 12709821ff1SIngo Molnar * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are 12866520ebcSJacob Shin * represented by pfn_mapped 1292b72394eSPekka Enberg */ 1302b72394eSPekka Enberg unsigned long max_low_pfn_mapped; 1312b72394eSPekka Enberg unsigned long max_pfn_mapped; 1322b72394eSPekka Enberg 133e808bae2SThadeu Lima de Souza Cascardo #ifdef CONFIG_DMI 134796216a5SJeremy Fitzhardinge RESERVE_BRK(dmi_alloc, 65536); 135e808bae2SThadeu Lima de Souza Cascardo #endif 136796216a5SJeremy Fitzhardinge 137c0b5842aSIngo Molnar 13893dbda7cSJeremy Fitzhardinge static __initdata unsigned long _brk_start = (unsigned long)__brk_base; 13993dbda7cSJeremy Fitzhardinge unsigned long _brk_end = (unsigned long)__brk_base; 14093dbda7cSJeremy Fitzhardinge 141217b8ce8SYinghai Lu struct boot_params boot_params; 142217b8ce8SYinghai Lu 1434046d6e8SLinus Torvalds /* 1444046d6e8SLinus Torvalds * Machine setup.. 1454046d6e8SLinus Torvalds */ 146*a3299754SKees Cook static struct resource rodata_resource = { 147*a3299754SKees Cook .name = "Kernel rodata", 148*a3299754SKees Cook .start = 0, 149*a3299754SKees Cook .end = 0, 150*a3299754SKees Cook .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 151*a3299754SKees Cook }; 152*a3299754SKees Cook 1534046d6e8SLinus Torvalds static struct resource data_resource = { 1544046d6e8SLinus Torvalds .name = "Kernel data", 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 code_resource = { 1614046d6e8SLinus Torvalds .name = "Kernel code", 1624046d6e8SLinus Torvalds .start = 0, 1634046d6e8SLinus Torvalds .end = 0, 1644046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1654046d6e8SLinus Torvalds }; 1664046d6e8SLinus Torvalds 1674046d6e8SLinus Torvalds static struct resource bss_resource = { 1684046d6e8SLinus Torvalds .name = "Kernel bss", 1694046d6e8SLinus Torvalds .start = 0, 1704046d6e8SLinus Torvalds .end = 0, 1714046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1724046d6e8SLinus Torvalds }; 1734046d6e8SLinus Torvalds 1744046d6e8SLinus Torvalds 17555f26239SYinghai Lu #ifdef CONFIG_X86_32 1766415813bSMathias Krause /* cpu data as detected by the assembly code in head_32.S */ 1776415813bSMathias Krause struct cpuinfo_x86 new_cpu_data; 1786415813bSMathias Krause 17955f26239SYinghai Lu /* common cpu data for all cpus */ 1806415813bSMathias Krause struct cpuinfo_x86 boot_cpu_data __read_mostly; 18155f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 18255f26239SYinghai Lu 18355f26239SYinghai Lu unsigned int def_to_bigsmp; 18455f26239SYinghai Lu 18555f26239SYinghai Lu /* for MCA, but anyone else can use it if they want */ 18655f26239SYinghai Lu unsigned int machine_id; 18755f26239SYinghai Lu unsigned int machine_submodel_id; 18855f26239SYinghai Lu unsigned int BIOS_revision; 18955f26239SYinghai Lu 19055f26239SYinghai Lu struct apm_info apm_info; 19155f26239SYinghai Lu EXPORT_SYMBOL(apm_info); 19255f26239SYinghai Lu 19355f26239SYinghai Lu #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ 19455f26239SYinghai Lu defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) 19555f26239SYinghai Lu struct ist_info ist_info; 19655f26239SYinghai Lu EXPORT_SYMBOL(ist_info); 19755f26239SYinghai Lu #else 19855f26239SYinghai Lu struct ist_info ist_info; 19955f26239SYinghai Lu #endif 20055f26239SYinghai Lu 20155f26239SYinghai Lu #else 202162434e7SKirill A. Shutemov struct cpuinfo_x86 boot_cpu_data __read_mostly; 20355f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 20455f26239SYinghai Lu #endif 20555f26239SYinghai Lu 20655f26239SYinghai Lu 20755f26239SYinghai Lu #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64) 208404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init; 20955f26239SYinghai Lu #else 210404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; 21155f26239SYinghai Lu #endif 21255f26239SYinghai Lu 2135031296cSH. Peter Anvin /* Boot loader ID and version as integers, for the benefit of proc_dointvec */ 2145031296cSH. Peter Anvin int bootloader_type, bootloader_version; 21555f26239SYinghai Lu 21655f26239SYinghai Lu /* 21755f26239SYinghai Lu * Setup options 21855f26239SYinghai Lu */ 21955f26239SYinghai Lu struct screen_info screen_info; 22055f26239SYinghai Lu EXPORT_SYMBOL(screen_info); 22155f26239SYinghai Lu struct edid_info edid_info; 22255f26239SYinghai Lu EXPORT_SYMBOL_GPL(edid_info); 22355f26239SYinghai Lu 22455f26239SYinghai Lu extern int root_mountflags; 22555f26239SYinghai Lu 22655f26239SYinghai Lu unsigned long saved_video_mode; 22755f26239SYinghai Lu 22855f26239SYinghai Lu #define RAMDISK_IMAGE_START_MASK 0x07FF 22955f26239SYinghai Lu #define RAMDISK_PROMPT_FLAG 0x8000 23055f26239SYinghai Lu #define RAMDISK_LOAD_FLAG 0x4000 23155f26239SYinghai Lu 23255f26239SYinghai Lu static char __initdata command_line[COMMAND_LINE_SIZE]; 233516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 234516cbf37STim Bird static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; 235516cbf37STim Bird #endif 23655f26239SYinghai Lu 23755f26239SYinghai Lu #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) 23855f26239SYinghai Lu struct edd edd; 23955f26239SYinghai Lu #ifdef CONFIG_EDD_MODULE 24055f26239SYinghai Lu EXPORT_SYMBOL(edd); 24155f26239SYinghai Lu #endif 24255f26239SYinghai Lu /** 24355f26239SYinghai Lu * copy_edd() - Copy the BIOS EDD information 24455f26239SYinghai Lu * from boot_params into a safe place. 24555f26239SYinghai Lu * 24655f26239SYinghai Lu */ 2479eaa192dSHelight.Xu static inline void __init copy_edd(void) 24855f26239SYinghai Lu { 24955f26239SYinghai Lu memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, 25055f26239SYinghai Lu sizeof(edd.mbr_signature)); 25155f26239SYinghai Lu memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); 25255f26239SYinghai Lu edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; 25355f26239SYinghai Lu edd.edd_info_nr = boot_params.eddbuf_entries; 25455f26239SYinghai Lu } 25555f26239SYinghai Lu #else 2569eaa192dSHelight.Xu static inline void __init copy_edd(void) 25755f26239SYinghai Lu { 25855f26239SYinghai Lu } 25955f26239SYinghai Lu #endif 26055f26239SYinghai Lu 2615368a2beSH. Peter Anvin void * __init extend_brk(size_t size, size_t align) 2625368a2beSH. Peter Anvin { 2635368a2beSH. Peter Anvin size_t mask = align - 1; 2645368a2beSH. Peter Anvin void *ret; 2655368a2beSH. Peter Anvin 2665368a2beSH. Peter Anvin BUG_ON(_brk_start == 0); 2675368a2beSH. Peter Anvin BUG_ON(align & mask); 2685368a2beSH. Peter Anvin 2695368a2beSH. Peter Anvin _brk_end = (_brk_end + mask) & ~mask; 2705368a2beSH. Peter Anvin BUG_ON((char *)(_brk_end + size) > __brk_limit); 2715368a2beSH. Peter Anvin 2725368a2beSH. Peter Anvin ret = (void *)_brk_end; 2735368a2beSH. Peter Anvin _brk_end += size; 2745368a2beSH. Peter Anvin 2755368a2beSH. Peter Anvin memset(ret, 0, size); 2765368a2beSH. Peter Anvin 2775368a2beSH. Peter Anvin return ret; 2785368a2beSH. Peter Anvin } 2795368a2beSH. Peter Anvin 280148b2098SYinghai Lu #ifdef CONFIG_X86_32 281e5f15b45SYinghai Lu static void __init cleanup_highmap(void) 282f005fe12SYinghai Lu { 283f005fe12SYinghai Lu } 284854c879fSPekka J Enberg #endif 285854c879fSPekka J Enberg 2865368a2beSH. Peter Anvin static void __init reserve_brk(void) 2875368a2beSH. Peter Anvin { 2885368a2beSH. Peter Anvin if (_brk_end > _brk_start) 289fc8d7826SAlexander Duyck memblock_reserve(__pa_symbol(_brk_start), 290fc8d7826SAlexander Duyck _brk_end - _brk_start); 2915368a2beSH. Peter Anvin 2925368a2beSH. Peter Anvin /* Mark brk area as locked down and no longer taking any 2935368a2beSH. Peter Anvin new allocations */ 2945368a2beSH. Peter Anvin _brk_start = 0; 2955368a2beSH. Peter Anvin } 2965368a2beSH. Peter Anvin 2975aa3d718SBorislav Petkov u64 relocated_ramdisk; 2985aa3d718SBorislav Petkov 29955f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_INITRD 30055f26239SYinghai Lu 301a8a51a88SYinghai Lu static u64 __init get_ramdisk_image(void) 302a8a51a88SYinghai Lu { 303a8a51a88SYinghai Lu u64 ramdisk_image = boot_params.hdr.ramdisk_image; 304a8a51a88SYinghai Lu 305ee92d815SYinghai Lu ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; 306ee92d815SYinghai Lu 307a8a51a88SYinghai Lu return ramdisk_image; 308a8a51a88SYinghai Lu } 309a8a51a88SYinghai Lu static u64 __init get_ramdisk_size(void) 310a8a51a88SYinghai Lu { 311a8a51a88SYinghai Lu u64 ramdisk_size = boot_params.hdr.ramdisk_size; 312a8a51a88SYinghai Lu 313ee92d815SYinghai Lu ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; 314ee92d815SYinghai Lu 315a8a51a88SYinghai Lu return ramdisk_size; 316a8a51a88SYinghai Lu } 317a8a51a88SYinghai Lu 31855f26239SYinghai Lu static void __init relocate_initrd(void) 31955f26239SYinghai Lu { 320c967da6aSYinghai Lu /* Assume only end is not page aligned */ 321a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 322a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 323c967da6aSYinghai Lu u64 area_size = PAGE_ALIGN(ramdisk_size); 32455f26239SYinghai Lu 325e8c57d40SYinghai Lu /* We need to move the initrd down into directly mapped mem */ 3265aa3d718SBorislav Petkov relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped), 327e8c57d40SYinghai Lu area_size, PAGE_SIZE); 32855f26239SYinghai Lu 3295aa3d718SBorislav Petkov if (!relocated_ramdisk) 33055f26239SYinghai Lu panic("Cannot find place for new RAMDISK of size %lld\n", 33155f26239SYinghai Lu ramdisk_size); 33255f26239SYinghai Lu 333e8c57d40SYinghai Lu /* Note: this includes all the mem currently occupied by 33455f26239SYinghai Lu the initrd, we rely on that fact to keep the data intact. */ 3355aa3d718SBorislav Petkov memblock_reserve(relocated_ramdisk, area_size); 3365aa3d718SBorislav Petkov initrd_start = relocated_ramdisk + PAGE_OFFSET; 33755f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 338365811d6SBjorn Helgaas printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", 3395aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 34055f26239SYinghai Lu 3415dd2c4bdSMark Salter copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size); 34255f26239SYinghai Lu 343365811d6SBjorn Helgaas printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to" 344365811d6SBjorn Helgaas " [mem %#010llx-%#010llx]\n", 34555f26239SYinghai Lu ramdisk_image, ramdisk_image + ramdisk_size - 1, 3465aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 34755f26239SYinghai Lu } 34855f26239SYinghai Lu 3491b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3501b8c78beSYinghai Lu { 3511b8c78beSYinghai Lu /* Assume only end is not page aligned */ 352a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 353a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 3541b8c78beSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 3551b8c78beSYinghai Lu 3561b8c78beSYinghai Lu if (!boot_params.hdr.type_of_loader || 3571b8c78beSYinghai Lu !ramdisk_image || !ramdisk_size) 3581b8c78beSYinghai Lu return; /* No initrd provided by bootloader */ 3591b8c78beSYinghai Lu 3601b8c78beSYinghai Lu memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); 3611b8c78beSYinghai Lu } 36255f26239SYinghai Lu static void __init reserve_initrd(void) 36355f26239SYinghai Lu { 364c967da6aSYinghai Lu /* Assume only end is not page aligned */ 365a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 366a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 367c967da6aSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 368e8c57d40SYinghai Lu u64 mapped_size; 36955f26239SYinghai Lu 37055f26239SYinghai Lu if (!boot_params.hdr.type_of_loader || 37155f26239SYinghai Lu !ramdisk_image || !ramdisk_size) 37255f26239SYinghai Lu return; /* No initrd provided by bootloader */ 37355f26239SYinghai Lu 37455f26239SYinghai Lu initrd_start = 0; 37555f26239SYinghai Lu 376595ad9afSYinghai Lu mapped_size = memblock_mem_size(max_pfn_mapped); 377e8c57d40SYinghai Lu if (ramdisk_size >= (mapped_size>>1)) 378ab7b64e9SPeter Jones panic("initrd too large to handle, " 379ab7b64e9SPeter Jones "disabling initrd (%lld needed, %lld available)\n", 380e8c57d40SYinghai Lu ramdisk_size, mapped_size>>1); 38155f26239SYinghai Lu 382365811d6SBjorn Helgaas printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, 383365811d6SBjorn Helgaas ramdisk_end - 1); 38455f26239SYinghai Lu 38574f27655SYinghai Lu if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image), 386e8c57d40SYinghai Lu PFN_DOWN(ramdisk_end))) { 387e8c57d40SYinghai Lu /* All are mapped, easy case */ 38855f26239SYinghai Lu initrd_start = ramdisk_image + PAGE_OFFSET; 38955f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 39055f26239SYinghai Lu return; 39155f26239SYinghai Lu } 39255f26239SYinghai Lu 39355f26239SYinghai Lu relocate_initrd(); 3948c5dd8f4SYinghai Lu 39524aa0788STejun Heo memblock_free(ramdisk_image, ramdisk_end - ramdisk_image); 39655f26239SYinghai Lu } 397af06f8b7SLv Zheng 39855f26239SYinghai Lu #else 3991b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 4001b8c78beSYinghai Lu { 4011b8c78beSYinghai Lu } 40255f26239SYinghai Lu static void __init reserve_initrd(void) 40355f26239SYinghai Lu { 40455f26239SYinghai Lu } 40555f26239SYinghai Lu #endif /* CONFIG_BLK_DEV_INITRD */ 40655f26239SYinghai Lu 40729f784e3SYinghai Lu static void __init parse_setup_data(void) 408257b0fdeSYinghai Lu { 409257b0fdeSYinghai Lu struct setup_data *data; 41030e46b57SLinn Crosetto u64 pa_data, pa_next; 411257b0fdeSYinghai Lu 412257b0fdeSYinghai Lu pa_data = boot_params.hdr.setup_data; 413257b0fdeSYinghai Lu while (pa_data) { 4147389882cSWANG Chao u32 data_len, data_type; 415f1c2b357SSebastian Andrzej Siewior 4167389882cSWANG Chao data = early_memremap(pa_data, sizeof(*data)); 417f1c2b357SSebastian Andrzej Siewior data_len = data->len + sizeof(struct setup_data); 41830e46b57SLinn Crosetto data_type = data->type; 41930e46b57SLinn Crosetto pa_next = data->next; 4208d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 421f1c2b357SSebastian Andrzej Siewior 42230e46b57SLinn Crosetto switch (data_type) { 423257b0fdeSYinghai Lu case SETUP_E820_EXT: 424914053c0SIngo Molnar e820__memory_setup_extended(pa_data, data_len); 425257b0fdeSYinghai Lu break; 426da6b737bSSebastian Andrzej Siewior case SETUP_DTB: 427da6b737bSSebastian Andrzej Siewior add_dtb(pa_data); 428257b0fdeSYinghai Lu break; 4291fec0533SDave Young case SETUP_EFI: 4301fec0533SDave Young parse_efi_setup(pa_data, data_len); 4311fec0533SDave Young break; 432257b0fdeSYinghai Lu default: 433257b0fdeSYinghai Lu break; 434257b0fdeSYinghai Lu } 43530e46b57SLinn Crosetto pa_data = pa_next; 436257b0fdeSYinghai Lu } 437257b0fdeSYinghai Lu } 438257b0fdeSYinghai Lu 439a9ce6bc1SYinghai Lu static void __init memblock_x86_reserve_range_setup_data(void) 440a0a0becdSYinghai Lu { 441a0a0becdSYinghai Lu struct setup_data *data; 442a0a0becdSYinghai Lu u64 pa_data; 443a0a0becdSYinghai Lu 444a0a0becdSYinghai Lu pa_data = boot_params.hdr.setup_data; 445a0a0becdSYinghai Lu while (pa_data) { 44688b4c146SJeremy Fitzhardinge data = early_memremap(pa_data, sizeof(*data)); 44724aa0788STejun Heo memblock_reserve(pa_data, sizeof(*data) + data->len); 448a0a0becdSYinghai Lu pa_data = data->next; 4498d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 450a0a0becdSYinghai Lu } 451a0a0becdSYinghai Lu } 452a0a0becdSYinghai Lu 45355f26239SYinghai Lu /* 454ccb4defaSYinghai Lu * --------- Crashkernel reservation ------------------------------ 455ccb4defaSYinghai Lu */ 456ccb4defaSYinghai Lu 4572965faa5SDave Young #ifdef CONFIG_KEXEC_CORE 45832105f7fSBernhard Walle 459606134f7SBorislav Petkov /* 16M alignment for crash kernel regions */ 4609ca5c8e6SDave Young #define CRASH_ALIGN SZ_16M 461606134f7SBorislav Petkov 4627f8595bfSH. Peter Anvin /* 4638ff80fbeSBaoquan He * Keep the crash kernel below this limit. 4648ff80fbeSBaoquan He * 4658ff80fbeSBaoquan He * On 32 bits earlier kernels would limit the kernel to the low 512 MiB 4668ff80fbeSBaoquan He * due to mapping restrictions. 4678ff80fbeSBaoquan He * 4688ff80fbeSBaoquan He * On 64bit, kdump kernel need be restricted to be under 64TB, which is 4698ff80fbeSBaoquan He * the upper limit of system RAM in 4-level paing mode. Since the kdump 4708ff80fbeSBaoquan He * jumping could be from 5-level to 4-level, the jumping will fail if 4718ff80fbeSBaoquan He * kernel is put above 64TB, and there's no way to detect the paging mode 4728ff80fbeSBaoquan He * of the kernel which will be loaded for dumping during the 1st kernel 4738ff80fbeSBaoquan He * bootup. 4747f8595bfSH. Peter Anvin */ 4757f8595bfSH. Peter Anvin #ifdef CONFIG_X86_32 4769ca5c8e6SDave Young # define CRASH_ADDR_LOW_MAX SZ_512M 4779ca5c8e6SDave Young # define CRASH_ADDR_HIGH_MAX SZ_512M 4787f8595bfSH. Peter Anvin #else 4799ca5c8e6SDave Young # define CRASH_ADDR_LOW_MAX SZ_4G 4808ff80fbeSBaoquan He # define CRASH_ADDR_HIGH_MAX SZ_64T 4817f8595bfSH. Peter Anvin #endif 4827f8595bfSH. Peter Anvin 483eb6db83dSBaoquan He static int __init reserve_crashkernel_low(void) 4840212f915SYinghai Lu { 4850212f915SYinghai Lu #ifdef CONFIG_X86_64 486f56d5578SBorislav Petkov unsigned long long base, low_base = 0, low_size = 0; 4870212f915SYinghai Lu unsigned long total_low_mem; 4880212f915SYinghai Lu int ret; 4890212f915SYinghai Lu 4900212f915SYinghai Lu total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); 49197eac21bSBorislav Petkov 492adbc742bSYinghai Lu /* crashkernel=Y,low */ 49397eac21bSBorislav Petkov ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base); 494f56d5578SBorislav Petkov if (ret) { 495c729de8fSYinghai Lu /* 496392e879aSAndy Shevchenko * two parts from kernel/dma/swiotlb.c: 49794fb9334SJoerg Roedel * -swiotlb size: user-specified with swiotlb= or default. 49894fb9334SJoerg Roedel * 49994fb9334SJoerg Roedel * -swiotlb overflow buffer: now hardcoded to 32k. We round it 50094fb9334SJoerg Roedel * to 8M for other buffers that may need to stay low too. Also 50194fb9334SJoerg Roedel * make sure we allocate enough extra low memory so that we 50294fb9334SJoerg Roedel * don't run out of DMA buffers for 32-bit devices. 503c729de8fSYinghai Lu */ 50494fb9334SJoerg Roedel low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); 505c729de8fSYinghai Lu } else { 506adbc742bSYinghai Lu /* passed with crashkernel=0,low ? */ 507c729de8fSYinghai Lu if (!low_size) 508eb6db83dSBaoquan He return 0; 509c729de8fSYinghai Lu } 5100212f915SYinghai Lu 511fe2d48b8SJiri Bohac low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN); 5120212f915SYinghai Lu if (!low_base) { 513eb6db83dSBaoquan He pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", 514eb6db83dSBaoquan He (unsigned long)(low_size >> 20)); 515eb6db83dSBaoquan He return -ENOMEM; 5160212f915SYinghai Lu } 5170212f915SYinghai Lu 5186f376057SBorislav Petkov ret = memblock_reserve(low_base, low_size); 5196f376057SBorislav Petkov if (ret) { 5206f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel low memblock.\n", __func__); 5216f376057SBorislav Petkov return ret; 5226f376057SBorislav Petkov } 52397eac21bSBorislav Petkov 5240212f915SYinghai Lu pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n", 5250212f915SYinghai Lu (unsigned long)(low_size >> 20), 5260212f915SYinghai Lu (unsigned long)(low_base >> 20), 5270212f915SYinghai Lu (unsigned long)(total_low_mem >> 20)); 52897eac21bSBorislav Petkov 5290212f915SYinghai Lu crashk_low_res.start = low_base; 5300212f915SYinghai Lu crashk_low_res.end = low_base + low_size - 1; 5310212f915SYinghai Lu insert_resource(&iomem_resource, &crashk_low_res); 5320212f915SYinghai Lu #endif 533eb6db83dSBaoquan He return 0; 5340212f915SYinghai Lu } 5350212f915SYinghai Lu 53629f784e3SYinghai Lu static void __init reserve_crashkernel(void) 537ccb4defaSYinghai Lu { 538f56d5578SBorislav Petkov unsigned long long crash_size, crash_base, total_mem; 53955a20ee7SYinghai Lu bool high = false; 540ccb4defaSYinghai Lu int ret; 541ccb4defaSYinghai Lu 54209c71bfdSDave Young total_mem = memblock_phys_mem_size(); 543ccb4defaSYinghai Lu 54455a20ee7SYinghai Lu /* crashkernel=XM */ 54597eac21bSBorislav Petkov ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); 54655a20ee7SYinghai Lu if (ret != 0 || crash_size <= 0) { 547adbc742bSYinghai Lu /* crashkernel=X,high */ 54855a20ee7SYinghai Lu ret = parse_crashkernel_high(boot_command_line, total_mem, 54955a20ee7SYinghai Lu &crash_size, &crash_base); 55032105f7fSBernhard Walle if (ret != 0 || crash_size <= 0) 55132105f7fSBernhard Walle return; 55255a20ee7SYinghai Lu high = true; 55355a20ee7SYinghai Lu } 55432105f7fSBernhard Walle 5553db3eb28SPetr Tesarik if (xen_pv_domain()) { 5563db3eb28SPetr Tesarik pr_info("Ignoring crashkernel for a Xen PV domain\n"); 5573db3eb28SPetr Tesarik return; 5583db3eb28SPetr Tesarik } 5593db3eb28SPetr Tesarik 56032105f7fSBernhard Walle /* 0 means: find the address automatically */ 561b9ac3849SDave Young if (!crash_base) { 5629f4c1396SYinghai Lu /* 563a8d4c824SXunlei Pang * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, 564b9ac3849SDave Young * crashkernel=x,high reserves memory over 4G, also allocates 565b9ac3849SDave Young * 256M extra low memory for DMA buffers and swiotlb. 566b9ac3849SDave Young * But the extra memory is not required for all machines. 567b9ac3849SDave Young * So try low memory first and fall back to high memory 568b9ac3849SDave Young * unless "crashkernel=size[KMG],high" is specified. 5699f4c1396SYinghai Lu */ 570b9ac3849SDave Young if (!high) 571606134f7SBorislav Petkov crash_base = memblock_find_in_range(CRASH_ALIGN, 572b9ac3849SDave Young CRASH_ADDR_LOW_MAX, 573b9ac3849SDave Young crash_size, CRASH_ALIGN); 574b9ac3849SDave Young if (!crash_base) 575b9ac3849SDave Young crash_base = memblock_find_in_range(CRASH_ALIGN, 576b9ac3849SDave Young CRASH_ADDR_HIGH_MAX, 577606134f7SBorislav Petkov crash_size, CRASH_ALIGN); 5781f5026a7STejun Heo if (!crash_base) { 57944280733SYinghai Lu pr_info("crashkernel reservation failed - No suitable area found.\n"); 580ccb4defaSYinghai Lu return; 581ccb4defaSYinghai Lu } 58232105f7fSBernhard Walle } else { 58344280733SYinghai Lu unsigned long long start; 58444280733SYinghai Lu 5859f4c1396SYinghai Lu start = memblock_find_in_range(crash_base, 58697eac21bSBorislav Petkov crash_base + crash_size, 58797eac21bSBorislav Petkov crash_size, 1 << 20); 58844280733SYinghai Lu if (start != crash_base) { 58944280733SYinghai Lu pr_info("crashkernel reservation failed - memory is in use.\n"); 590ccb4defaSYinghai Lu return; 591ccb4defaSYinghai Lu } 59232105f7fSBernhard Walle } 5936f376057SBorislav Petkov ret = memblock_reserve(crash_base, crash_size); 5946f376057SBorislav Petkov if (ret) { 5956f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel memblock.\n", __func__); 5966f376057SBorislav Petkov return; 5976f376057SBorislav Petkov } 598ccb4defaSYinghai Lu 599eb6db83dSBaoquan He if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { 600eb6db83dSBaoquan He memblock_free(crash_base, crash_size); 601eb6db83dSBaoquan He return; 602eb6db83dSBaoquan He } 603eb6db83dSBaoquan He 604f56d5578SBorislav Petkov pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", 605ccb4defaSYinghai Lu (unsigned long)(crash_size >> 20), 606ccb4defaSYinghai Lu (unsigned long)(crash_base >> 20), 607ccb4defaSYinghai Lu (unsigned long)(total_mem >> 20)); 608ccb4defaSYinghai Lu 609ccb4defaSYinghai Lu crashk_res.start = crash_base; 610ccb4defaSYinghai Lu crashk_res.end = crash_base + crash_size - 1; 611ccb4defaSYinghai Lu insert_resource(&iomem_resource, &crashk_res); 612ccb4defaSYinghai Lu } 613ccb4defaSYinghai Lu #else 61429f784e3SYinghai Lu static void __init reserve_crashkernel(void) 615ccb4defaSYinghai Lu { 616ccb4defaSYinghai Lu } 617ccb4defaSYinghai Lu #endif 618ccb4defaSYinghai Lu 619bdba0e70SYinghai Lu static struct resource standard_io_resources[] = { 620bdba0e70SYinghai Lu { .name = "dma1", .start = 0x00, .end = 0x1f, 621bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 622bdba0e70SYinghai Lu { .name = "pic1", .start = 0x20, .end = 0x21, 623bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 624bdba0e70SYinghai Lu { .name = "timer0", .start = 0x40, .end = 0x43, 625bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 626bdba0e70SYinghai Lu { .name = "timer1", .start = 0x50, .end = 0x53, 627bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 628bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x60, .end = 0x60, 629bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 630bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x64, .end = 0x64, 631bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 632bdba0e70SYinghai Lu { .name = "dma page reg", .start = 0x80, .end = 0x8f, 633bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 634bdba0e70SYinghai Lu { .name = "pic2", .start = 0xa0, .end = 0xa1, 635bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 636bdba0e70SYinghai Lu { .name = "dma2", .start = 0xc0, .end = 0xdf, 637bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 638bdba0e70SYinghai Lu { .name = "fpu", .start = 0xf0, .end = 0xff, 639bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO } 640bdba0e70SYinghai Lu }; 641bdba0e70SYinghai Lu 6428fee697dSThomas Gleixner void __init reserve_standard_io_resources(void) 643bdba0e70SYinghai Lu { 644bdba0e70SYinghai Lu int i; 645bdba0e70SYinghai Lu 646bdba0e70SYinghai Lu /* request I/O space for devices used on all i[345]86 PCs */ 647bdba0e70SYinghai Lu for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) 648bdba0e70SYinghai Lu request_resource(&ioport_resource, &standard_io_resources[i]); 649bdba0e70SYinghai Lu 650bdba0e70SYinghai Lu } 651bdba0e70SYinghai Lu 652042be38eSYinghai Lu static __init void reserve_ibft_region(void) 653042be38eSYinghai Lu { 654042be38eSYinghai Lu unsigned long addr, size = 0; 655042be38eSYinghai Lu 656042be38eSYinghai Lu addr = find_ibft_region(&size); 657042be38eSYinghai Lu 658042be38eSYinghai Lu if (size) 65924aa0788STejun Heo memblock_reserve(addr, size); 660042be38eSYinghai Lu } 661042be38eSYinghai Lu 662a9acc536SJesse Barnes static bool __init snb_gfx_workaround_needed(void) 663a9acc536SJesse Barnes { 664e43b3cecSH. Peter Anvin #ifdef CONFIG_PCI 665a9acc536SJesse Barnes int i; 666a9acc536SJesse Barnes u16 vendor, devid; 667ab3cd867SH. Peter Anvin static const __initconst u16 snb_ids[] = { 668a9acc536SJesse Barnes 0x0102, 669a9acc536SJesse Barnes 0x0112, 670a9acc536SJesse Barnes 0x0122, 671a9acc536SJesse Barnes 0x0106, 672a9acc536SJesse Barnes 0x0116, 673a9acc536SJesse Barnes 0x0126, 674a9acc536SJesse Barnes 0x010a, 675a9acc536SJesse Barnes }; 676a9acc536SJesse Barnes 677a9acc536SJesse Barnes /* Assume no if something weird is going on with PCI */ 678a9acc536SJesse Barnes if (!early_pci_allowed()) 679a9acc536SJesse Barnes return false; 680a9acc536SJesse Barnes 681a9acc536SJesse Barnes vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); 682a9acc536SJesse Barnes if (vendor != 0x8086) 683a9acc536SJesse Barnes return false; 684a9acc536SJesse Barnes 685a9acc536SJesse Barnes devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); 686a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(snb_ids); i++) 687a9acc536SJesse Barnes if (devid == snb_ids[i]) 688a9acc536SJesse Barnes return true; 689e43b3cecSH. Peter Anvin #endif 690a9acc536SJesse Barnes 691a9acc536SJesse Barnes return false; 692a9acc536SJesse Barnes } 693a9acc536SJesse Barnes 694a9acc536SJesse Barnes /* 695a9acc536SJesse Barnes * Sandy Bridge graphics has trouble with certain ranges, exclude 696a9acc536SJesse Barnes * them from allocation. 697a9acc536SJesse Barnes */ 698a9acc536SJesse Barnes static void __init trim_snb_memory(void) 699a9acc536SJesse Barnes { 700ab3cd867SH. Peter Anvin static const __initconst unsigned long bad_pages[] = { 701a9acc536SJesse Barnes 0x20050000, 702a9acc536SJesse Barnes 0x20110000, 703a9acc536SJesse Barnes 0x20130000, 704a9acc536SJesse Barnes 0x20138000, 705a9acc536SJesse Barnes 0x40004000, 706a9acc536SJesse Barnes }; 707a9acc536SJesse Barnes int i; 708a9acc536SJesse Barnes 709a9acc536SJesse Barnes if (!snb_gfx_workaround_needed()) 710a9acc536SJesse Barnes return; 711a9acc536SJesse Barnes 712a9acc536SJesse Barnes printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); 713a9acc536SJesse Barnes 714a9acc536SJesse Barnes /* 715a9acc536SJesse Barnes * Reserve all memory below the 1 MB mark that has not 716a9acc536SJesse Barnes * already been reserved. 717a9acc536SJesse Barnes */ 718a9acc536SJesse Barnes memblock_reserve(0, 1<<20); 719a9acc536SJesse Barnes 720a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { 721a9acc536SJesse Barnes if (memblock_reserve(bad_pages[i], PAGE_SIZE)) 722a9acc536SJesse Barnes printk(KERN_WARNING "failed to reserve 0x%08lx\n", 723a9acc536SJesse Barnes bad_pages[i]); 724a9acc536SJesse Barnes } 725a9acc536SJesse Barnes } 726a9acc536SJesse Barnes 727a9acc536SJesse Barnes /* 728a9acc536SJesse Barnes * Here we put platform-specific memory range workarounds, i.e. 729a9acc536SJesse Barnes * memory known to be corrupt or otherwise in need to be reserved on 730a9acc536SJesse Barnes * specific platforms. 731a9acc536SJesse Barnes * 732a9acc536SJesse Barnes * If this gets used more widely it could use a real dispatch mechanism. 733a9acc536SJesse Barnes */ 734a9acc536SJesse Barnes static void __init trim_platform_memory_ranges(void) 735a9acc536SJesse Barnes { 736a9acc536SJesse Barnes trim_snb_memory(); 737a9acc536SJesse Barnes } 738a9acc536SJesse Barnes 7391b5576e6SYinghai Lu static void __init trim_bios_range(void) 7401b5576e6SYinghai Lu { 7411b5576e6SYinghai Lu /* 7421b5576e6SYinghai Lu * A special case is the first 4Kb of memory; 7431b5576e6SYinghai Lu * This is a BIOS owned area, not kernel ram, but generally 7441b5576e6SYinghai Lu * not listed as such in the E820 table. 745d0cd7425SH. Peter Anvin * 746d0cd7425SH. Peter Anvin * This typically reserves additional memory (64KiB by default) 747d0cd7425SH. Peter Anvin * since some BIOSes are known to corrupt low memory. See the 7489ea77bdbSH. Peter Anvin * Kconfig help text for X86_RESERVE_LOW. 7491b5576e6SYinghai Lu */ 75009821ff1SIngo Molnar e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); 751d0cd7425SH. Peter Anvin 7521b5576e6SYinghai Lu /* 7531b5576e6SYinghai Lu * special case: Some BIOSen report the PC BIOS 7541b5576e6SYinghai Lu * area (640->1Mb) as ram even though it is not. 7551b5576e6SYinghai Lu * take them out. 7561b5576e6SYinghai Lu */ 75709821ff1SIngo Molnar e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); 758a9acc536SJesse Barnes 759f9748fa0SIngo Molnar e820__update_table(e820_table); 7601b5576e6SYinghai Lu } 7611b5576e6SYinghai Lu 762b422a309SYinghai Lu /* called before trim_bios_range() to spare extra sanitize */ 763b422a309SYinghai Lu static void __init e820_add_kernel_range(void) 764b422a309SYinghai Lu { 765b422a309SYinghai Lu u64 start = __pa_symbol(_text); 766b422a309SYinghai Lu u64 size = __pa_symbol(_end) - start; 767b422a309SYinghai Lu 768b422a309SYinghai Lu /* 76909821ff1SIngo Molnar * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and 770b422a309SYinghai Lu * attempt to fix it by adding the range. We may have a confused BIOS, 771b422a309SYinghai Lu * or the user may have used memmap=exactmap or memmap=xxM$yyM to 772b422a309SYinghai Lu * exclude kernel range. If we really are running on top non-RAM, 773b422a309SYinghai Lu * we will crash later anyways. 774b422a309SYinghai Lu */ 77509821ff1SIngo Molnar if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) 776b422a309SYinghai Lu return; 777b422a309SYinghai Lu 77809821ff1SIngo Molnar pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); 77909821ff1SIngo Molnar e820__range_remove(start, size, E820_TYPE_RAM, 0); 78009821ff1SIngo Molnar e820__range_add(start, size, E820_TYPE_RAM); 781b422a309SYinghai Lu } 782b422a309SYinghai Lu 78395c96084SH. Peter Anvin static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10; 78495c96084SH. Peter Anvin 7859ea77bdbSH. Peter Anvin static int __init parse_reservelow(char *p) 7869ea77bdbSH. Peter Anvin { 7879ea77bdbSH. Peter Anvin unsigned long long size; 7889ea77bdbSH. Peter Anvin 7899ea77bdbSH. Peter Anvin if (!p) 7909ea77bdbSH. Peter Anvin return -EINVAL; 7919ea77bdbSH. Peter Anvin 7929ea77bdbSH. Peter Anvin size = memparse(p, &p); 7939ea77bdbSH. Peter Anvin 7949ea77bdbSH. Peter Anvin if (size < 4096) 7959ea77bdbSH. Peter Anvin size = 4096; 7969ea77bdbSH. Peter Anvin 7979ea77bdbSH. Peter Anvin if (size > 640*1024) 7989ea77bdbSH. Peter Anvin size = 640*1024; 7999ea77bdbSH. Peter Anvin 8009ea77bdbSH. Peter Anvin reserve_low = size; 8019ea77bdbSH. Peter Anvin 8029ea77bdbSH. Peter Anvin return 0; 8039ea77bdbSH. Peter Anvin } 8049ea77bdbSH. Peter Anvin 8059ea77bdbSH. Peter Anvin early_param("reservelow", parse_reservelow); 8069ea77bdbSH. Peter Anvin 80795c96084SH. Peter Anvin static void __init trim_low_memory_range(void) 80895c96084SH. Peter Anvin { 80995c96084SH. Peter Anvin memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); 81095c96084SH. Peter Anvin } 81195c96084SH. Peter Anvin 8125394f80fSJeremy Fitzhardinge /* 813f32360efSKees Cook * Dump out kernel offset information on panic. 814f32360efSKees Cook */ 815f32360efSKees Cook static int 816f32360efSKees Cook dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) 817f32360efSKees Cook { 81878cac48cSBorislav Petkov if (kaslr_enabled()) { 81978cac48cSBorislav Petkov pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", 8204545c898SJiri Kosina kaslr_offset(), 82178cac48cSBorislav Petkov __START_KERNEL, 82278cac48cSBorislav Petkov __START_KERNEL_map, 82378cac48cSBorislav Petkov MODULES_VADDR-1); 82478cac48cSBorislav Petkov } else { 82578cac48cSBorislav Petkov pr_emerg("Kernel Offset: disabled\n"); 82678cac48cSBorislav Petkov } 827f32360efSKees Cook 828f32360efSKees Cook return 0; 829f32360efSKees Cook } 830f32360efSKees Cook 831f32360efSKees Cook /* 83255f26239SYinghai Lu * Determine if we were loaded by an EFI loader. If so, then we have also been 83355f26239SYinghai Lu * passed the efi memmap, systab, etc., so we should use these data structures 83455f26239SYinghai Lu * for initialization. Note, the efi init code path is determined by the 83555f26239SYinghai Lu * global efi_enabled. This allows the same kernel image to be used on existing 83655f26239SYinghai Lu * systems (with a traditional BIOS) as well as on EFI systems. 83755f26239SYinghai Lu */ 83855f26239SYinghai Lu /* 83955f26239SYinghai Lu * setup_arch - architecture-specific boot-time initializations 84055f26239SYinghai Lu * 84155f26239SYinghai Lu * Note: On x86_64, fixmaps are ready for use even before this is called. 84255f26239SYinghai Lu */ 84355f26239SYinghai Lu 84455f26239SYinghai Lu void __init setup_arch(char **cmdline_p) 84555f26239SYinghai Lu { 846c603a309SThomas Lendacky /* 847c603a309SThomas Lendacky * Reserve the memory occupied by the kernel between _text and 848c603a309SThomas Lendacky * __end_of_kernel_reserve symbols. Any kernel sections after the 849c603a309SThomas Lendacky * __end_of_kernel_reserve symbol must be explicitly reserved with a 850c603a309SThomas Lendacky * separate memblock_reserve() or they will be discarded. 851c603a309SThomas Lendacky */ 8526c902b65SYinghai Lu memblock_reserve(__pa_symbol(_text), 853c603a309SThomas Lendacky (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); 8546c902b65SYinghai Lu 85510a70416SAndi Kleen /* 85610a70416SAndi Kleen * Make sure page 0 is always reserved because on systems with 85710a70416SAndi Kleen * L1TF its contents can be leaked to user processes. 85810a70416SAndi Kleen */ 85910a70416SAndi Kleen memblock_reserve(0, PAGE_SIZE); 86010a70416SAndi Kleen 8611b8c78beSYinghai Lu early_reserve_initrd(); 8621b8c78beSYinghai Lu 8636c902b65SYinghai Lu /* 8646c902b65SYinghai Lu * At this point everything still needed from the boot loader 8656c902b65SYinghai Lu * or BIOS or kernel text should be early reserved or marked not 8666c902b65SYinghai Lu * RAM in e820. All other memory is free game. 8676c902b65SYinghai Lu */ 8686c902b65SYinghai Lu 86955f26239SYinghai Lu #ifdef CONFIG_X86_32 87055f26239SYinghai Lu memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); 871b40827faSBorislav Petkov 872b40827faSBorislav Petkov /* 873b40827faSBorislav Petkov * copy kernel address range established so far and switch 874b40827faSBorislav Petkov * to the proper swapper page table 875b40827faSBorislav Petkov */ 876b40827faSBorislav Petkov clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, 877b40827faSBorislav Petkov initial_page_table + KERNEL_PGD_BOUNDARY, 878b40827faSBorislav Petkov KERNEL_PGD_PTRS); 879b40827faSBorislav Petkov 880b40827faSBorislav Petkov load_cr3(swapper_pg_dir); 8812075244fSBryan O'Donoghue /* 8822075244fSBryan O'Donoghue * Note: Quark X1000 CPUs advertise PGE incorrectly and require 8832075244fSBryan O'Donoghue * a cr3 based tlb flush, so the following __flush_tlb_all() 8842075244fSBryan O'Donoghue * will not flush anything because the cpu quirk which clears 8852075244fSBryan O'Donoghue * X86_FEATURE_PGE has not been invoked yet. Though due to the 8862075244fSBryan O'Donoghue * load_cr3() above the TLB has been flushed already. The 8872075244fSBryan O'Donoghue * quirk is invoked before subsequent calls to __flush_tlb_all() 8882075244fSBryan O'Donoghue * so proper operation is guaranteed. 8892075244fSBryan O'Donoghue */ 890b40827faSBorislav Petkov __flush_tlb_all(); 89155f26239SYinghai Lu #else 89255f26239SYinghai Lu printk(KERN_INFO "Command line: %s\n", boot_command_line); 893162434e7SKirill A. Shutemov boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; 89455f26239SYinghai Lu #endif 89555f26239SYinghai Lu 8969863c90fSAlok Kataria /* 8979863c90fSAlok Kataria * If we have OLPC OFW, we might end up relocating the fixmap due to 8989863c90fSAlok Kataria * reserve_top(), so do this before touching the ioremap area. 8999863c90fSAlok Kataria */ 900fd699c76SAndres Salomon olpc_ofw_detect(); 901fd699c76SAndres Salomon 902433f8924SThomas Gleixner idt_setup_early_traps(); 9039e882c92SJeremy Fitzhardinge early_cpu_init(); 9048990cac6SPavel Tatashin arch_init_ideal_nops(); 9058990cac6SPavel Tatashin jump_label_init(); 9061a98fd14SJeremy Fitzhardinge early_ioremap_init(); 9071a98fd14SJeremy Fitzhardinge 908fd699c76SAndres Salomon setup_olpc_ofw_pgd(); 909fd699c76SAndres Salomon 91055f26239SYinghai Lu ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); 91155f26239SYinghai Lu screen_info = boot_params.screen_info; 91255f26239SYinghai Lu edid_info = boot_params.edid_info; 91355f26239SYinghai Lu #ifdef CONFIG_X86_32 91455f26239SYinghai Lu apm_info.bios = boot_params.apm_bios_info; 91555f26239SYinghai Lu ist_info = boot_params.ist_info; 91655f26239SYinghai Lu #endif 91755f26239SYinghai Lu saved_video_mode = boot_params.hdr.vid_mode; 91855f26239SYinghai Lu bootloader_type = boot_params.hdr.type_of_loader; 9195031296cSH. Peter Anvin if ((bootloader_type >> 4) == 0xe) { 9205031296cSH. Peter Anvin bootloader_type &= 0xf; 9215031296cSH. Peter Anvin bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; 9225031296cSH. Peter Anvin } 9235031296cSH. Peter Anvin bootloader_version = bootloader_type & 0xf; 9245031296cSH. Peter Anvin bootloader_version |= boot_params.hdr.ext_loader_ver << 4; 92555f26239SYinghai Lu 92655f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_RAM 92755f26239SYinghai Lu rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; 92855f26239SYinghai Lu rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0); 92955f26239SYinghai Lu rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0); 93055f26239SYinghai Lu #endif 93155f26239SYinghai Lu #ifdef CONFIG_EFI 93255f26239SYinghai Lu if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 9339402973dSDaniel Kiper EFI32_LOADER_SIGNATURE, 4)) { 9343e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 9351adbfa35SOlof Johansson } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 9369402973dSDaniel Kiper EFI64_LOADER_SIGNATURE, 4)) { 9373e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 9383e909599SMatt Fleming set_bit(EFI_64BIT, &efi.flags); 93955f26239SYinghai Lu } 94055f26239SYinghai Lu #endif 94155f26239SYinghai Lu 94242bbdb43SThomas Gleixner x86_init.oem.arch_setup(); 94355f26239SYinghai Lu 944419afdf5SBjorn Helgaas iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 945103e2063SIngo Molnar e820__memory_setup(); 94628bb2237SYinghai Lu parse_setup_data(); 94728bb2237SYinghai Lu 94855f26239SYinghai Lu copy_edd(); 94955f26239SYinghai Lu 95055f26239SYinghai Lu if (!boot_params.hdr.root_flags) 95155f26239SYinghai Lu root_mountflags &= ~MS_RDONLY; 95255f26239SYinghai Lu init_mm.start_code = (unsigned long) _text; 95355f26239SYinghai Lu init_mm.end_code = (unsigned long) _etext; 95455f26239SYinghai Lu init_mm.end_data = (unsigned long) _edata; 95593dbda7cSJeremy Fitzhardinge init_mm.brk = _brk_end; 95655f26239SYinghai Lu 957fe3d197fSDave Hansen mpx_mm_init(&init_mm); 958fe3d197fSDave Hansen 9594046d6e8SLinus Torvalds code_resource.start = __pa_symbol(_text); 9604046d6e8SLinus Torvalds code_resource.end = __pa_symbol(_etext)-1; 961*a3299754SKees Cook rodata_resource.start = __pa_symbol(__start_rodata); 962*a3299754SKees Cook rodata_resource.end = __pa_symbol(__end_rodata)-1; 963*a3299754SKees Cook data_resource.start = __pa_symbol(_sdata); 9644046d6e8SLinus Torvalds data_resource.end = __pa_symbol(_edata)-1; 9654046d6e8SLinus Torvalds bss_resource.start = __pa_symbol(__bss_start); 9664046d6e8SLinus Torvalds bss_resource.end = __pa_symbol(__bss_stop)-1; 9674046d6e8SLinus Torvalds 968516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 969516cbf37STim Bird #ifdef CONFIG_CMDLINE_OVERRIDE 970516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 971516cbf37STim Bird #else 972516cbf37STim Bird if (builtin_cmdline[0]) { 973516cbf37STim Bird /* append boot loader cmdline to builtin */ 974516cbf37STim Bird strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 975516cbf37STim Bird strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 976516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 977516cbf37STim Bird } 978516cbf37STim Bird #endif 979516cbf37STim Bird #endif 980516cbf37STim Bird 981eda6da92SYinghai Lu strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 982eda6da92SYinghai Lu *cmdline_p = command_line; 983eda6da92SYinghai Lu 984eda6da92SYinghai Lu /* 9854b0f3b81SKees Cook * x86_configure_nx() is called before parse_early_param() to detect 9864b0f3b81SKees Cook * whether hardware doesn't support NX (so that the early EHCI debug 9874b0f3b81SKees Cook * console setup can safely call set_fixmap()). It may then be called 9884b0f3b81SKees Cook * again from within noexec_setup() during parsing early parameters 9894b0f3b81SKees Cook * to honor the respective command line option. 990eda6da92SYinghai Lu */ 9914763ed4dSH. Peter Anvin x86_configure_nx(); 992eda6da92SYinghai Lu 993eda6da92SYinghai Lu parse_early_param(); 994eda6da92SYinghai Lu 995835bcec5SDave Young if (efi_enabled(EFI_BOOT)) 996835bcec5SDave Young efi_memblock_x86_reserve_range(); 99739fa104dSReza Arbab #ifdef CONFIG_MEMORY_HOTPLUG 99839fa104dSReza Arbab /* 99939fa104dSReza Arbab * Memory used by the kernel cannot be hot-removed because Linux 100039fa104dSReza Arbab * cannot migrate the kernel pages. When memory hotplug is 100139fa104dSReza Arbab * enabled, we should prevent memblock from allocating memory 100239fa104dSReza Arbab * for the kernel. 100339fa104dSReza Arbab * 100439fa104dSReza Arbab * ACPI SRAT records all hotpluggable memory ranges. But before 100539fa104dSReza Arbab * SRAT is parsed, we don't know about it. 100639fa104dSReza Arbab * 100739fa104dSReza Arbab * The kernel image is loaded into memory at very early time. We 100839fa104dSReza Arbab * cannot prevent this anyway. So on NUMA system, we set any 100939fa104dSReza Arbab * node the kernel resides in as un-hotpluggable. 101039fa104dSReza Arbab * 101139fa104dSReza Arbab * Since on modern servers, one node could have double-digit 101239fa104dSReza Arbab * gigabytes memory, we can assume the memory around the kernel 101339fa104dSReza Arbab * image is also un-hotpluggable. So before SRAT is parsed, just 101439fa104dSReza Arbab * allocate memory near the kernel image to try the best to keep 101539fa104dSReza Arbab * the kernel away from hotpluggable memory. 101639fa104dSReza Arbab */ 101739fa104dSReza Arbab if (movable_node_is_enabled()) 101839fa104dSReza Arbab memblock_set_bottom_up(true); 101939fa104dSReza Arbab #endif 102039fa104dSReza Arbab 10214b0f3b81SKees Cook x86_report_nx(); 10220ad5bce7SJeremy Fitzhardinge 102328bb2237SYinghai Lu /* after early param, so could get panic from serial */ 1024a9ce6bc1SYinghai Lu memblock_x86_reserve_range_setup_data(); 102528bb2237SYinghai Lu 102655f26239SYinghai Lu if (acpi_mps_check()) { 102755f26239SYinghai Lu #ifdef CONFIG_X86_LOCAL_APIC 102855f26239SYinghai Lu disable_apic = 1; 102955f26239SYinghai Lu #endif 1030988781dcSYinghai Lu setup_clear_cpu_cap(X86_FEATURE_APIC); 103155f26239SYinghai Lu } 103255f26239SYinghai Lu 10331a127034SIngo Molnar e820__reserve_setup_data(); 10349641bdafSIngo Molnar e820__finish_early_params(); 103555f26239SYinghai Lu 103683e68189SMatt Fleming if (efi_enabled(EFI_BOOT)) 1037ff0c0874SBrian Maly efi_init(); 1038ff0c0874SBrian Maly 10390fca0812SRobert Richter dmi_setup(); 10402216d199SYinghai Lu 104188b094fbSAlok Kataria /* 104288b094fbSAlok Kataria * VMware detection requires dmi to be available, so this 10430fca0812SRobert Richter * needs to be done after dmi_setup(), for the boot CPU. 104488b094fbSAlok Kataria */ 10452d826404SThomas Gleixner init_hypervisor_platform(); 104688b094fbSAlok Kataria 1047cf7a63efSPavel Tatashin tsc_early_init(); 1048f7cf5a5bSThomas Gleixner x86_init.resources.probe_roms(); 104955f26239SYinghai Lu 10504046d6e8SLinus Torvalds /* after parse_early_param, so could debug it */ 10514046d6e8SLinus Torvalds insert_resource(&iomem_resource, &code_resource); 1052*a3299754SKees Cook insert_resource(&iomem_resource, &rodata_resource); 10534046d6e8SLinus Torvalds insert_resource(&iomem_resource, &data_resource); 10544046d6e8SLinus Torvalds insert_resource(&iomem_resource, &bss_resource); 10554046d6e8SLinus Torvalds 1056b422a309SYinghai Lu e820_add_kernel_range(); 10571b5576e6SYinghai Lu trim_bios_range(); 105855f26239SYinghai Lu #ifdef CONFIG_X86_32 105955f26239SYinghai Lu if (ppro_with_ram_bug()) { 106009821ff1SIngo Molnar e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, 106109821ff1SIngo Molnar E820_TYPE_RESERVED); 1062f9748fa0SIngo Molnar e820__update_table(e820_table); 106355f26239SYinghai Lu printk(KERN_INFO "fixed physical RAM map:\n"); 1064be0c3f0fSIngo Molnar e820__print_table("bad_ppro"); 106555f26239SYinghai Lu } 106655f26239SYinghai Lu #else 106755f26239SYinghai Lu early_gart_iommu_check(); 106855f26239SYinghai Lu #endif 106955f26239SYinghai Lu 107055f26239SYinghai Lu /* 107155f26239SYinghai Lu * partially used pages are not usable - thus 107255f26239SYinghai Lu * we are rounding upwards: 107355f26239SYinghai Lu */ 10740c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 107555f26239SYinghai Lu 107655f26239SYinghai Lu /* update e820 for memory not covered by WB MTRRs */ 107755f26239SYinghai Lu mtrr_bp_init(); 10782dc807b3SYinghai Lu if (mtrr_trim_uncached_memory(max_pfn)) 10790c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 108055f26239SYinghai Lu 10818dd33030SIgor Mammedov max_possible_pfn = max_pfn; 10828dd33030SIgor Mammedov 1083c7d2361fSThomas Garnier /* 108499c13b8cSMikulas Patocka * This call is required when the CPU does not support PAT. If 108599c13b8cSMikulas Patocka * mtrr_bp_init() invoked it already via pat_init() the call has no 108699c13b8cSMikulas Patocka * effect. 108799c13b8cSMikulas Patocka */ 108899c13b8cSMikulas Patocka init_cache_modes(); 108999c13b8cSMikulas Patocka 109099c13b8cSMikulas Patocka /* 1091c7d2361fSThomas Garnier * Define random base addresses for memory sections after max_pfn is 1092c7d2361fSThomas Garnier * defined and before each memory section base is used. 1093c7d2361fSThomas Garnier */ 1094c7d2361fSThomas Garnier kernel_randomize_memory(); 1095c7d2361fSThomas Garnier 109655f26239SYinghai Lu #ifdef CONFIG_X86_32 109755f26239SYinghai Lu /* max_low_pfn get updated here */ 109855f26239SYinghai Lu find_low_pfn_range(); 109955f26239SYinghai Lu #else 11006e1cb38aSSuresh Siddha check_x2apic(); 110155f26239SYinghai Lu 110255f26239SYinghai Lu /* How many end-of-memory variables you have, grandma! */ 110355f26239SYinghai Lu /* need this before calling reserve_initrd */ 1104f361a450SYinghai Lu if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) 11050c6fc11aSIngo Molnar max_low_pfn = e820__end_of_low_ram_pfn(); 1106f361a450SYinghai Lu else 110755f26239SYinghai Lu max_low_pfn = max_pfn; 1108f361a450SYinghai Lu 110955f26239SYinghai Lu high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 111055f26239SYinghai Lu #endif 111155f26239SYinghai Lu 1112893f38d1SYinghai Lu /* 1113893f38d1SYinghai Lu * Find and reserve possible boot-time SMP configuration: 1114893f38d1SYinghai Lu */ 1115893f38d1SYinghai Lu find_smp_config(); 1116893f38d1SYinghai Lu 1117042be38eSYinghai Lu reserve_ibft_region(); 1118042be38eSYinghai Lu 11198d57470dSYinghai Lu early_alloc_pgt_buf(); 11208d57470dSYinghai Lu 112172d7c3b3SYinghai Lu /* 11224918e228SIngo Molnar * Need to conclude brk, before e820__memblock_setup() 112372d7c3b3SYinghai Lu * it could use memblock_find_in_range, could overlap with 112472d7c3b3SYinghai Lu * brk area. 112572d7c3b3SYinghai Lu */ 112672d7c3b3SYinghai Lu reserve_brk(); 112772d7c3b3SYinghai Lu 1128e5f15b45SYinghai Lu cleanup_highmap(); 1129e5f15b45SYinghai Lu 11302449f343STang Chen memblock_set_current_limit(ISA_END_ADDRESS); 11314918e228SIngo Molnar e820__memblock_setup(); 113272d7c3b3SYinghai Lu 1133007b7560SAndy Lutomirski reserve_bios_regions(); 1134007b7560SAndy Lutomirski 11354971531aSMatt Fleming if (efi_enabled(EFI_MEMMAP)) { 11364971531aSMatt Fleming efi_fake_memmap(); 11374971531aSMatt Fleming efi_find_mirror(); 11383dad6f7fSRicardo Neri efi_esrt_init(); 11394971531aSMatt Fleming 1140916f676fSMatthew Garrett /* 11414971531aSMatt Fleming * The EFI specification says that boot service code won't be 11424971531aSMatt Fleming * called after ExitBootServices(). This is, in fact, a lie. 1143916f676fSMatthew Garrett */ 1144916f676fSMatthew Garrett efi_reserve_boot_services(); 11454971531aSMatt Fleming } 1146916f676fSMatthew Garrett 114772d7c3b3SYinghai Lu /* preallocate 4k for mptable mpc */ 11485da217caSIngo Molnar e820__memblock_alloc_reserved_mpc_new(); 114972d7c3b3SYinghai Lu 115072d7c3b3SYinghai Lu #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 115172d7c3b3SYinghai Lu setup_bios_corruption_check(); 115272d7c3b3SYinghai Lu #endif 115372d7c3b3SYinghai Lu 115410054230SYinghai Lu #ifdef CONFIG_X86_32 1155365811d6SBjorn Helgaas printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", 1156365811d6SBjorn Helgaas (max_pfn_mapped<<PAGE_SHIFT) - 1); 115710054230SYinghai Lu #endif 115872d7c3b3SYinghai Lu 11594f7b9226SYinghai Lu reserve_real_mode(); 1160893f38d1SYinghai Lu 1161a9acc536SJesse Barnes trim_platform_memory_ranges(); 116295c96084SH. Peter Anvin trim_low_memory_range(); 1163a9acc536SJesse Barnes 116422ddfcaaSYinghai Lu init_mem_mapping(); 1165854c879fSPekka J Enberg 1166433f8924SThomas Gleixner idt_setup_early_pf(); 1167cda846f1SJarkko Sakkinen 116818bc7bd5SAndy Lutomirski /* 116918bc7bd5SAndy Lutomirski * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) 117018bc7bd5SAndy Lutomirski * with the current CR4 value. This may not be necessary, but 117118bc7bd5SAndy Lutomirski * auditing all the early-boot CR4 manipulation would be needed to 117218bc7bd5SAndy Lutomirski * rule it out. 1173c7ad5ad2SAndy Lutomirski * 1174c7ad5ad2SAndy Lutomirski * Mask off features that don't work outside long mode (just 1175c7ad5ad2SAndy Lutomirski * PCIDE for now). 117618bc7bd5SAndy Lutomirski */ 1177c7ad5ad2SAndy Lutomirski mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; 117818bc7bd5SAndy Lutomirski 11794ce7a869SYinghai Lu memblock_set_current_limit(get_max_mapped()); 1180e7b37895SYinghai Lu 1181e7b37895SYinghai Lu /* 1182e7b37895SYinghai Lu * NOTE: On x86-32, only from this point on, fixmaps are ready for use. 1183e7b37895SYinghai Lu */ 1184e7b37895SYinghai Lu 1185e7b37895SYinghai Lu #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 1186e7b37895SYinghai Lu if (init_ohci1394_dma_early) 1187162a7e75SMike Travis init_ohci1394_dma_on_all_controllers(); 1188162a7e75SMike Travis #endif 1189e7b37895SYinghai Lu /* Allocate bigger log buffer */ 119055f26239SYinghai Lu setup_log_buf(1); 119155f26239SYinghai Lu 11929661b332SDavid Howells if (efi_enabled(EFI_BOOT)) { 11939661b332SDavid Howells switch (boot_params.secure_boot) { 11949661b332SDavid Howells case efi_secureboot_mode_disabled: 11959661b332SDavid Howells pr_info("Secure boot disabled\n"); 11969661b332SDavid Howells break; 11979661b332SDavid Howells case efi_secureboot_mode_enabled: 11989661b332SDavid Howells pr_info("Secure boot enabled\n"); 11999661b332SDavid Howells break; 12009661b332SDavid Howells default: 12019661b332SDavid Howells pr_info("Secure boot could not be determined\n"); 12029661b332SDavid Howells break; 12039661b332SDavid Howells } 12049661b332SDavid Howells } 12059661b332SDavid Howells 120644280733SYinghai Lu reserve_initrd(); 120744280733SYinghai Lu 1208da3d3f98SAleksey Makarov acpi_table_upgrade(); 120955f26239SYinghai Lu 121055f26239SYinghai Lu vsmp_init(); 121155f26239SYinghai Lu 121255f26239SYinghai Lu io_delay_init(); 121355f26239SYinghai Lu 1214630b3affSLukas Wunner early_platform_quirks(); 1215630b3affSLukas Wunner 121655f26239SYinghai Lu /* 121755f26239SYinghai Lu * Parse the ACPI tables for possible boot-time SMP configuration. 121855f26239SYinghai Lu */ 121920e6926dSYinghai Lu acpi_boot_table_init(); 122020e6926dSYinghai Lu 122120e6926dSYinghai Lu early_acpi_boot_init(); 122220e6926dSYinghai Lu 122391467bdfSBernhard Walle initmem_init(); 12243c325f82SWeijie Yang dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); 1225fa591c4aSTang Chen 1226fa591c4aSTang Chen /* 1227fa591c4aSTang Chen * Reserve memory for crash kernel after SRAT is parsed so that it 1228fa591c4aSTang Chen * won't consume hotpluggable memory. 1229fa591c4aSTang Chen */ 1230fa591c4aSTang Chen reserve_crashkernel(); 1231fa591c4aSTang Chen 123255f26239SYinghai Lu memblock_find_dma_reserve(); 123355f26239SYinghai Lu 1234ccb64941SBoris Ostrovsky if (!early_xdbc_setup_hardware()) 1235ccb64941SBoris Ostrovsky early_xdbc_register_console(); 1236ccb64941SBoris Ostrovsky 1237030cb6c0SThomas Gleixner x86_init.paging.pagetable_init(); 123855f26239SYinghai Lu 1239ef7f0d6aSAndrey Ryabinin kasan_init(); 1240ef7f0d6aSAndrey Ryabinin 1241d2b6dc61SAndy Lutomirski /* 1242945fd17aSThomas Gleixner * Sync back kernel address range. 1243945fd17aSThomas Gleixner * 1244945fd17aSThomas Gleixner * FIXME: Can the later sync in setup_cpu_entry_areas() replace 1245945fd17aSThomas Gleixner * this call? 1246d2b6dc61SAndy Lutomirski */ 1247945fd17aSThomas Gleixner sync_initial_page_table(); 1248d2b6dc61SAndy Lutomirski 124931625340SJoseph Cihula tboot_probe(); 125031625340SJoseph Cihula 125155f26239SYinghai Lu map_vsyscall(); 125255f26239SYinghai Lu 125355f26239SYinghai Lu generic_apic_probe(); 125455f26239SYinghai Lu 125555f26239SYinghai Lu early_quirks(); 125655f26239SYinghai Lu 125755f26239SYinghai Lu /* 125855f26239SYinghai Lu * Read APIC and some other early information from ACPI tables. 125955f26239SYinghai Lu */ 126055f26239SYinghai Lu acpi_boot_init(); 1261efafc8b2SFeng Tang sfi_init(); 1262a906fdaaSThomas Gleixner x86_dtb_init(); 1263efafc8b2SFeng Tang 126455f26239SYinghai Lu /* 126555f26239SYinghai Lu * get boot-time SMP configuration: 126655f26239SYinghai Lu */ 126755f26239SYinghai Lu get_smp_config(); 126855f26239SYinghai Lu 12691e90a13dSThomas Gleixner /* 12701e90a13dSThomas Gleixner * Systems w/o ACPI and mptables might not have it mapped the local 12711e90a13dSThomas Gleixner * APIC yet, but prefill_possible_map() might need to access it. 12721e90a13dSThomas Gleixner */ 12731e90a13dSThomas Gleixner init_apic_mappings(); 12741e90a13dSThomas Gleixner 1275329513a3SYinghai Lu prefill_possible_map(); 1276301e6190SYinghai Lu 12775f4765f9SYinghai Lu init_cpu_to_node(); 12785f4765f9SYinghai Lu 1279ca1b8862SThomas Gleixner io_apic_init_mappings(); 12809d6a4d08SYinghai Lu 1281f3614646SJuergen Gross x86_init.hyper.guest_late_init(); 128255f26239SYinghai Lu 12831506c8dcSIngo Molnar e820__reserve_resources(); 1284cc55f753SZhimin Gu e820__register_nosave_regions(max_pfn); 128555f26239SYinghai Lu 12868fee697dSThomas Gleixner x86_init.resources.reserve_resources(); 128755f26239SYinghai Lu 12882df908baSIngo Molnar e820__setup_pci_gap(); 128955f26239SYinghai Lu 129055f26239SYinghai Lu #ifdef CONFIG_VT 129155f26239SYinghai Lu #if defined(CONFIG_VGA_CONSOLE) 129283e68189SMatt Fleming if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) 129355f26239SYinghai Lu conswitchp = &vga_con; 129455f26239SYinghai Lu #elif defined(CONFIG_DUMMY_CONSOLE) 129555f26239SYinghai Lu conswitchp = &dummy_con; 129655f26239SYinghai Lu #endif 129755f26239SYinghai Lu #endif 12986f30c1acSThomas Gleixner x86_init.oem.banner(); 1299a2202aa2SYong Wang 13006b617e22SFeng Tang x86_init.timers.wallclock_init(); 13016b617e22SFeng Tang 1302a2202aa2SYong Wang mcheck_init(); 1303f49aa448SJason Baron 1304b3c869d3SJohn Stultz register_refined_jiffies(CLOCK_TICK_RATE); 13055189c2a7SOlof Johansson 13065189c2a7SOlof Johansson #ifdef CONFIG_EFI 1307a5d90c92SBorislav Petkov if (efi_enabled(EFI_BOOT)) 1308a5d90c92SBorislav Petkov efi_apply_memmap_quirks(); 13095189c2a7SOlof Johansson #endif 1310ee9f8fceSJosh Poimboeuf 1311ee9f8fceSJosh Poimboeuf unwind_init(); 131255f26239SYinghai Lu } 13135649b7c3SIngo Molnar 13149be1b56aSIngo Molnar #ifdef CONFIG_X86_32 13155649b7c3SIngo Molnar 13168fee697dSThomas Gleixner static struct resource video_ram_resource = { 13178fee697dSThomas Gleixner .name = "Video RAM area", 13188fee697dSThomas Gleixner .start = 0xa0000, 13198fee697dSThomas Gleixner .end = 0xbffff, 13208fee697dSThomas Gleixner .flags = IORESOURCE_BUSY | IORESOURCE_MEM 13219be1b56aSIngo Molnar }; 13229be1b56aSIngo Molnar 13238fee697dSThomas Gleixner void __init i386_reserve_resources(void) 13249be1b56aSIngo Molnar { 13258fee697dSThomas Gleixner request_resource(&iomem_resource, &video_ram_resource); 13268fee697dSThomas Gleixner reserve_standard_io_resources(); 13279be1b56aSIngo Molnar } 13289be1b56aSIngo Molnar 13299be1b56aSIngo Molnar #endif /* CONFIG_X86_32 */ 1330f32360efSKees Cook 1331f32360efSKees Cook static struct notifier_block kernel_offset_notifier = { 1332f32360efSKees Cook .notifier_call = dump_kernel_offset 1333f32360efSKees Cook }; 1334f32360efSKees Cook 1335f32360efSKees Cook static int __init register_kernel_offset_dumper(void) 1336f32360efSKees Cook { 1337f32360efSKees Cook atomic_notifier_chain_register(&panic_notifier_list, 1338f32360efSKees Cook &kernel_offset_notifier); 1339f32360efSKees Cook return 0; 1340f32360efSKees Cook } 1341f32360efSKees Cook __initcall(register_kernel_offset_dumper); 1342