155f26239SYinghai Lu /* 255f26239SYinghai Lu * Copyright (C) 1995 Linus Torvalds 355f26239SYinghai Lu * 455f26239SYinghai Lu * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 555f26239SYinghai Lu * 655f26239SYinghai Lu * Memory region support 755f26239SYinghai Lu * David Parsons <[email protected]>, July-August 1999 855f26239SYinghai Lu * 955f26239SYinghai Lu * Added E820 sanitization routine (removes overlapping memory regions); 1055f26239SYinghai Lu * Brian Moyle <[email protected]>, February 2001 1155f26239SYinghai Lu * 1255f26239SYinghai Lu * Moved CPU detection code to cpu/${cpu}.c 1355f26239SYinghai Lu * Patrick Mochel <[email protected]>, March 2002 1455f26239SYinghai Lu * 1555f26239SYinghai Lu * Provisions for empty E820 memory regions (reported by certain BIOSes). 1655f26239SYinghai Lu * Alex Achenbach <[email protected]>, December 2002. 1755f26239SYinghai Lu * 1855f26239SYinghai Lu */ 1955f26239SYinghai Lu 2055f26239SYinghai Lu /* 2155f26239SYinghai Lu * This file handles the architecture-dependent parts of initialization 2255f26239SYinghai Lu */ 2355f26239SYinghai Lu 2455f26239SYinghai Lu #include <linux/sched.h> 2555f26239SYinghai Lu #include <linux/mm.h> 2655f26239SYinghai Lu #include <linux/mmzone.h> 2755f26239SYinghai Lu #include <linux/screen_info.h> 2855f26239SYinghai Lu #include <linux/ioport.h> 2955f26239SYinghai Lu #include <linux/acpi.h> 30efafc8b2SFeng Tang #include <linux/sfi.h> 3155f26239SYinghai Lu #include <linux/apm_bios.h> 3255f26239SYinghai Lu #include <linux/initrd.h> 3355f26239SYinghai Lu #include <linux/bootmem.h> 3472d7c3b3SYinghai Lu #include <linux/memblock.h> 3555f26239SYinghai Lu #include <linux/seq_file.h> 3655f26239SYinghai Lu #include <linux/console.h> 3755f26239SYinghai Lu #include <linux/root_dev.h> 3855f26239SYinghai Lu #include <linux/highmem.h> 39186f4360SPaul Gortmaker #include <linux/export.h> 4055f26239SYinghai Lu #include <linux/efi.h> 4155f26239SYinghai Lu #include <linux/init.h> 4255f26239SYinghai Lu #include <linux/edd.h> 4355f26239SYinghai Lu #include <linux/iscsi_ibft.h> 4455f26239SYinghai Lu #include <linux/nodemask.h> 4555f26239SYinghai Lu #include <linux/kexec.h> 4655f26239SYinghai Lu #include <linux/dmi.h> 4755f26239SYinghai Lu #include <linux/pfn.h> 4855f26239SYinghai Lu #include <linux/pci.h> 4955f26239SYinghai Lu #include <asm/pci-direct.h> 5055f26239SYinghai Lu #include <linux/init_ohci1394_dma.h> 5155f26239SYinghai Lu #include <linux/kvm_para.h> 520a2b9a6eSMarek Szyprowski #include <linux/dma-contiguous.h> 53*3db3eb28SPetr Tesarik #include <xen/xen.h> 5455f26239SYinghai Lu 5555f26239SYinghai Lu #include <linux/errno.h> 5655f26239SYinghai Lu #include <linux/kernel.h> 5755f26239SYinghai Lu #include <linux/stddef.h> 5855f26239SYinghai Lu #include <linux/unistd.h> 5955f26239SYinghai Lu #include <linux/ptrace.h> 6055f26239SYinghai Lu #include <linux/user.h> 6155f26239SYinghai Lu #include <linux/delay.h> 6255f26239SYinghai Lu 6355f26239SYinghai Lu #include <linux/kallsyms.h> 6455f26239SYinghai Lu #include <linux/cpufreq.h> 6555f26239SYinghai Lu #include <linux/dma-mapping.h> 6655f26239SYinghai Lu #include <linux/ctype.h> 6755f26239SYinghai Lu #include <linux/uaccess.h> 6855f26239SYinghai Lu 6955f26239SYinghai Lu #include <linux/percpu.h> 7055f26239SYinghai Lu #include <linux/crash_dump.h> 7169575d38SShane Wang #include <linux/tboot.h> 72b3c869d3SJohn Stultz #include <linux/jiffies.h> 73b9d05200STom Lendacky #include <linux/mem_encrypt.h> 7455f26239SYinghai Lu 751b5aeebfSLu Baolu #include <linux/usb/xhci-dbgp.h> 7655f26239SYinghai Lu #include <video/edid.h> 7755f26239SYinghai Lu 7855f26239SYinghai Lu #include <asm/mtrr.h> 7955f26239SYinghai Lu #include <asm/apic.h> 80084ee1c6SJarkko Sakkinen #include <asm/realmode.h> 8166441bd3SIngo Molnar #include <asm/e820/api.h> 8255f26239SYinghai Lu #include <asm/mpspec.h> 8355f26239SYinghai Lu #include <asm/setup.h> 8455f26239SYinghai Lu #include <asm/efi.h> 858e6dafd6SIngo Molnar #include <asm/timer.h> 868e6dafd6SIngo Molnar #include <asm/i8259.h> 8755f26239SYinghai Lu #include <asm/sections.h> 8855f26239SYinghai Lu #include <asm/io_apic.h> 8955f26239SYinghai Lu #include <asm/ist.h> 901164dd00SIngo Molnar #include <asm/setup_arch.h> 9155f26239SYinghai Lu #include <asm/bios_ebda.h> 9255f26239SYinghai Lu #include <asm/cacheflush.h> 9355f26239SYinghai Lu #include <asm/processor.h> 9455f26239SYinghai Lu #include <asm/bugs.h> 95ef7f0d6aSAndrey Ryabinin #include <asm/kasan.h> 9655f26239SYinghai Lu 9755f26239SYinghai Lu #include <asm/vsyscall.h> 986e5385d4SJaswinder Singh Rajput #include <asm/cpu.h> 9955f26239SYinghai Lu #include <asm/desc.h> 10055f26239SYinghai Lu #include <asm/dma.h> 10146a7fa27SFUJITA Tomonori #include <asm/iommu.h> 1021d9b16d1SJoerg Roedel #include <asm/gart.h> 10355f26239SYinghai Lu #include <asm/mmu_context.h> 10455f26239SYinghai Lu #include <asm/proto.h> 10555f26239SYinghai Lu 10655f26239SYinghai Lu #include <asm/paravirt.h> 10788b094fbSAlok Kataria #include <asm/hypervisor.h> 108fd699c76SAndres Salomon #include <asm/olpc_ofw.h> 10955f26239SYinghai Lu 11055f26239SYinghai Lu #include <asm/percpu.h> 11155f26239SYinghai Lu #include <asm/topology.h> 11255f26239SYinghai Lu #include <asm/apicdef.h> 11323ac4ae8SAndreas Herrmann #include <asm/amd_nb.h> 114a2202aa2SYong Wang #include <asm/mce.h> 115f49aa448SJason Baron #include <asm/alternative.h> 116da6b737bSSebastian Andrzej Siewior #include <asm/prom.h> 1179a2bc335SBorislav Petkov #include <asm/microcode.h> 1180483e1faSThomas Garnier #include <asm/kaslr.h> 119ee9f8fceSJosh Poimboeuf #include <asm/unwind.h> 12055f26239SYinghai Lu 1212b72394eSPekka Enberg /* 12266520ebcSJacob Shin * max_low_pfn_mapped: highest direct mapped pfn under 4GB 12366520ebcSJacob Shin * max_pfn_mapped: highest direct mapped pfn over 4GB 12466520ebcSJacob Shin * 12509821ff1SIngo Molnar * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are 12666520ebcSJacob Shin * represented by pfn_mapped 1272b72394eSPekka Enberg */ 1282b72394eSPekka Enberg unsigned long max_low_pfn_mapped; 1292b72394eSPekka Enberg unsigned long max_pfn_mapped; 1302b72394eSPekka Enberg 131e808bae2SThadeu Lima de Souza Cascardo #ifdef CONFIG_DMI 132796216a5SJeremy Fitzhardinge RESERVE_BRK(dmi_alloc, 65536); 133e808bae2SThadeu Lima de Souza Cascardo #endif 134796216a5SJeremy Fitzhardinge 135c0b5842aSIngo Molnar 13693dbda7cSJeremy Fitzhardinge static __initdata unsigned long _brk_start = (unsigned long)__brk_base; 13793dbda7cSJeremy Fitzhardinge unsigned long _brk_end = (unsigned long)__brk_base; 13893dbda7cSJeremy Fitzhardinge 139217b8ce8SYinghai Lu struct boot_params boot_params; 140217b8ce8SYinghai Lu 1414046d6e8SLinus Torvalds /* 1424046d6e8SLinus Torvalds * Machine setup.. 1434046d6e8SLinus Torvalds */ 1444046d6e8SLinus Torvalds static struct resource data_resource = { 1454046d6e8SLinus Torvalds .name = "Kernel data", 1464046d6e8SLinus Torvalds .start = 0, 1474046d6e8SLinus Torvalds .end = 0, 1484046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1494046d6e8SLinus Torvalds }; 1504046d6e8SLinus Torvalds 1514046d6e8SLinus Torvalds static struct resource code_resource = { 1524046d6e8SLinus Torvalds .name = "Kernel code", 1534046d6e8SLinus Torvalds .start = 0, 1544046d6e8SLinus Torvalds .end = 0, 1554046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1564046d6e8SLinus Torvalds }; 1574046d6e8SLinus Torvalds 1584046d6e8SLinus Torvalds static struct resource bss_resource = { 1594046d6e8SLinus Torvalds .name = "Kernel bss", 1604046d6e8SLinus Torvalds .start = 0, 1614046d6e8SLinus Torvalds .end = 0, 1624046d6e8SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM 1634046d6e8SLinus Torvalds }; 1644046d6e8SLinus Torvalds 1654046d6e8SLinus Torvalds 16655f26239SYinghai Lu #ifdef CONFIG_X86_32 1676415813bSMathias Krause /* cpu data as detected by the assembly code in head_32.S */ 1686415813bSMathias Krause struct cpuinfo_x86 new_cpu_data; 1696415813bSMathias Krause 17055f26239SYinghai Lu /* common cpu data for all cpus */ 1716415813bSMathias Krause struct cpuinfo_x86 boot_cpu_data __read_mostly; 17255f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 17355f26239SYinghai Lu 17455f26239SYinghai Lu unsigned int def_to_bigsmp; 17555f26239SYinghai Lu 17655f26239SYinghai Lu /* for MCA, but anyone else can use it if they want */ 17755f26239SYinghai Lu unsigned int machine_id; 17855f26239SYinghai Lu unsigned int machine_submodel_id; 17955f26239SYinghai Lu unsigned int BIOS_revision; 18055f26239SYinghai Lu 18155f26239SYinghai Lu struct apm_info apm_info; 18255f26239SYinghai Lu EXPORT_SYMBOL(apm_info); 18355f26239SYinghai Lu 18455f26239SYinghai Lu #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ 18555f26239SYinghai Lu defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) 18655f26239SYinghai Lu struct ist_info ist_info; 18755f26239SYinghai Lu EXPORT_SYMBOL(ist_info); 18855f26239SYinghai Lu #else 18955f26239SYinghai Lu struct ist_info ist_info; 19055f26239SYinghai Lu #endif 19155f26239SYinghai Lu 19255f26239SYinghai Lu #else 193162434e7SKirill A. Shutemov struct cpuinfo_x86 boot_cpu_data __read_mostly; 19455f26239SYinghai Lu EXPORT_SYMBOL(boot_cpu_data); 19555f26239SYinghai Lu #endif 19655f26239SYinghai Lu 19755f26239SYinghai Lu 19855f26239SYinghai Lu #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64) 199404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init; 20055f26239SYinghai Lu #else 201404f6aacSKees Cook __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; 20255f26239SYinghai Lu #endif 20355f26239SYinghai Lu 2045031296cSH. Peter Anvin /* Boot loader ID and version as integers, for the benefit of proc_dointvec */ 2055031296cSH. Peter Anvin int bootloader_type, bootloader_version; 20655f26239SYinghai Lu 20755f26239SYinghai Lu /* 20855f26239SYinghai Lu * Setup options 20955f26239SYinghai Lu */ 21055f26239SYinghai Lu struct screen_info screen_info; 21155f26239SYinghai Lu EXPORT_SYMBOL(screen_info); 21255f26239SYinghai Lu struct edid_info edid_info; 21355f26239SYinghai Lu EXPORT_SYMBOL_GPL(edid_info); 21455f26239SYinghai Lu 21555f26239SYinghai Lu extern int root_mountflags; 21655f26239SYinghai Lu 21755f26239SYinghai Lu unsigned long saved_video_mode; 21855f26239SYinghai Lu 21955f26239SYinghai Lu #define RAMDISK_IMAGE_START_MASK 0x07FF 22055f26239SYinghai Lu #define RAMDISK_PROMPT_FLAG 0x8000 22155f26239SYinghai Lu #define RAMDISK_LOAD_FLAG 0x4000 22255f26239SYinghai Lu 22355f26239SYinghai Lu static char __initdata command_line[COMMAND_LINE_SIZE]; 224516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 225516cbf37STim Bird static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; 226516cbf37STim Bird #endif 22755f26239SYinghai Lu 22855f26239SYinghai Lu #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) 22955f26239SYinghai Lu struct edd edd; 23055f26239SYinghai Lu #ifdef CONFIG_EDD_MODULE 23155f26239SYinghai Lu EXPORT_SYMBOL(edd); 23255f26239SYinghai Lu #endif 23355f26239SYinghai Lu /** 23455f26239SYinghai Lu * copy_edd() - Copy the BIOS EDD information 23555f26239SYinghai Lu * from boot_params into a safe place. 23655f26239SYinghai Lu * 23755f26239SYinghai Lu */ 2389eaa192dSHelight.Xu static inline void __init copy_edd(void) 23955f26239SYinghai Lu { 24055f26239SYinghai Lu memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, 24155f26239SYinghai Lu sizeof(edd.mbr_signature)); 24255f26239SYinghai Lu memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); 24355f26239SYinghai Lu edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; 24455f26239SYinghai Lu edd.edd_info_nr = boot_params.eddbuf_entries; 24555f26239SYinghai Lu } 24655f26239SYinghai Lu #else 2479eaa192dSHelight.Xu static inline void __init copy_edd(void) 24855f26239SYinghai Lu { 24955f26239SYinghai Lu } 25055f26239SYinghai Lu #endif 25155f26239SYinghai Lu 2525368a2beSH. Peter Anvin void * __init extend_brk(size_t size, size_t align) 2535368a2beSH. Peter Anvin { 2545368a2beSH. Peter Anvin size_t mask = align - 1; 2555368a2beSH. Peter Anvin void *ret; 2565368a2beSH. Peter Anvin 2575368a2beSH. Peter Anvin BUG_ON(_brk_start == 0); 2585368a2beSH. Peter Anvin BUG_ON(align & mask); 2595368a2beSH. Peter Anvin 2605368a2beSH. Peter Anvin _brk_end = (_brk_end + mask) & ~mask; 2615368a2beSH. Peter Anvin BUG_ON((char *)(_brk_end + size) > __brk_limit); 2625368a2beSH. Peter Anvin 2635368a2beSH. Peter Anvin ret = (void *)_brk_end; 2645368a2beSH. Peter Anvin _brk_end += size; 2655368a2beSH. Peter Anvin 2665368a2beSH. Peter Anvin memset(ret, 0, size); 2675368a2beSH. Peter Anvin 2685368a2beSH. Peter Anvin return ret; 2695368a2beSH. Peter Anvin } 2705368a2beSH. Peter Anvin 271148b2098SYinghai Lu #ifdef CONFIG_X86_32 272e5f15b45SYinghai Lu static void __init cleanup_highmap(void) 273f005fe12SYinghai Lu { 274f005fe12SYinghai Lu } 275854c879fSPekka J Enberg #endif 276854c879fSPekka J Enberg 2775368a2beSH. Peter Anvin static void __init reserve_brk(void) 2785368a2beSH. Peter Anvin { 2795368a2beSH. Peter Anvin if (_brk_end > _brk_start) 280fc8d7826SAlexander Duyck memblock_reserve(__pa_symbol(_brk_start), 281fc8d7826SAlexander Duyck _brk_end - _brk_start); 2825368a2beSH. Peter Anvin 2835368a2beSH. Peter Anvin /* Mark brk area as locked down and no longer taking any 2845368a2beSH. Peter Anvin new allocations */ 2855368a2beSH. Peter Anvin _brk_start = 0; 2865368a2beSH. Peter Anvin } 2875368a2beSH. Peter Anvin 2885aa3d718SBorislav Petkov u64 relocated_ramdisk; 2895aa3d718SBorislav Petkov 29055f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_INITRD 29155f26239SYinghai Lu 292a8a51a88SYinghai Lu static u64 __init get_ramdisk_image(void) 293a8a51a88SYinghai Lu { 294a8a51a88SYinghai Lu u64 ramdisk_image = boot_params.hdr.ramdisk_image; 295a8a51a88SYinghai Lu 296ee92d815SYinghai Lu ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; 297ee92d815SYinghai Lu 298a8a51a88SYinghai Lu return ramdisk_image; 299a8a51a88SYinghai Lu } 300a8a51a88SYinghai Lu static u64 __init get_ramdisk_size(void) 301a8a51a88SYinghai Lu { 302a8a51a88SYinghai Lu u64 ramdisk_size = boot_params.hdr.ramdisk_size; 303a8a51a88SYinghai Lu 304ee92d815SYinghai Lu ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; 305ee92d815SYinghai Lu 306a8a51a88SYinghai Lu return ramdisk_size; 307a8a51a88SYinghai Lu } 308a8a51a88SYinghai Lu 30955f26239SYinghai Lu static void __init relocate_initrd(void) 31055f26239SYinghai Lu { 311c967da6aSYinghai Lu /* Assume only end is not page aligned */ 312a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 313a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 314c967da6aSYinghai Lu u64 area_size = PAGE_ALIGN(ramdisk_size); 31555f26239SYinghai Lu 316e8c57d40SYinghai Lu /* We need to move the initrd down into directly mapped mem */ 3175aa3d718SBorislav Petkov relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped), 318e8c57d40SYinghai Lu area_size, PAGE_SIZE); 31955f26239SYinghai Lu 3205aa3d718SBorislav Petkov if (!relocated_ramdisk) 32155f26239SYinghai Lu panic("Cannot find place for new RAMDISK of size %lld\n", 32255f26239SYinghai Lu ramdisk_size); 32355f26239SYinghai Lu 324e8c57d40SYinghai Lu /* Note: this includes all the mem currently occupied by 32555f26239SYinghai Lu the initrd, we rely on that fact to keep the data intact. */ 3265aa3d718SBorislav Petkov memblock_reserve(relocated_ramdisk, area_size); 3275aa3d718SBorislav Petkov initrd_start = relocated_ramdisk + PAGE_OFFSET; 32855f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 329365811d6SBjorn Helgaas printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", 3305aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 33155f26239SYinghai Lu 3325dd2c4bdSMark Salter copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size); 33355f26239SYinghai Lu 334365811d6SBjorn Helgaas printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to" 335365811d6SBjorn Helgaas " [mem %#010llx-%#010llx]\n", 33655f26239SYinghai Lu ramdisk_image, ramdisk_image + ramdisk_size - 1, 3375aa3d718SBorislav Petkov relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); 33855f26239SYinghai Lu } 33955f26239SYinghai Lu 3401b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3411b8c78beSYinghai Lu { 3421b8c78beSYinghai Lu /* Assume only end is not page aligned */ 343a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 344a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 3451b8c78beSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 3461b8c78beSYinghai Lu 3471b8c78beSYinghai Lu if (!boot_params.hdr.type_of_loader || 3481b8c78beSYinghai Lu !ramdisk_image || !ramdisk_size) 3491b8c78beSYinghai Lu return; /* No initrd provided by bootloader */ 3501b8c78beSYinghai Lu 3511b8c78beSYinghai Lu memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); 3521b8c78beSYinghai Lu } 35355f26239SYinghai Lu static void __init reserve_initrd(void) 35455f26239SYinghai Lu { 355c967da6aSYinghai Lu /* Assume only end is not page aligned */ 356a8a51a88SYinghai Lu u64 ramdisk_image = get_ramdisk_image(); 357a8a51a88SYinghai Lu u64 ramdisk_size = get_ramdisk_size(); 358c967da6aSYinghai Lu u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); 359e8c57d40SYinghai Lu u64 mapped_size; 36055f26239SYinghai Lu 36155f26239SYinghai Lu if (!boot_params.hdr.type_of_loader || 36255f26239SYinghai Lu !ramdisk_image || !ramdisk_size) 36355f26239SYinghai Lu return; /* No initrd provided by bootloader */ 36455f26239SYinghai Lu 36555f26239SYinghai Lu initrd_start = 0; 36655f26239SYinghai Lu 367595ad9afSYinghai Lu mapped_size = memblock_mem_size(max_pfn_mapped); 368e8c57d40SYinghai Lu if (ramdisk_size >= (mapped_size>>1)) 369ab7b64e9SPeter Jones panic("initrd too large to handle, " 370ab7b64e9SPeter Jones "disabling initrd (%lld needed, %lld available)\n", 371e8c57d40SYinghai Lu ramdisk_size, mapped_size>>1); 37255f26239SYinghai Lu 373365811d6SBjorn Helgaas printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, 374365811d6SBjorn Helgaas ramdisk_end - 1); 37555f26239SYinghai Lu 37674f27655SYinghai Lu if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image), 377e8c57d40SYinghai Lu PFN_DOWN(ramdisk_end))) { 378e8c57d40SYinghai Lu /* All are mapped, easy case */ 37955f26239SYinghai Lu initrd_start = ramdisk_image + PAGE_OFFSET; 38055f26239SYinghai Lu initrd_end = initrd_start + ramdisk_size; 38155f26239SYinghai Lu return; 38255f26239SYinghai Lu } 38355f26239SYinghai Lu 38455f26239SYinghai Lu relocate_initrd(); 3858c5dd8f4SYinghai Lu 38624aa0788STejun Heo memblock_free(ramdisk_image, ramdisk_end - ramdisk_image); 38755f26239SYinghai Lu } 388af06f8b7SLv Zheng 38955f26239SYinghai Lu #else 3901b8c78beSYinghai Lu static void __init early_reserve_initrd(void) 3911b8c78beSYinghai Lu { 3921b8c78beSYinghai Lu } 39355f26239SYinghai Lu static void __init reserve_initrd(void) 39455f26239SYinghai Lu { 39555f26239SYinghai Lu } 39655f26239SYinghai Lu #endif /* CONFIG_BLK_DEV_INITRD */ 39755f26239SYinghai Lu 39829f784e3SYinghai Lu static void __init parse_setup_data(void) 399257b0fdeSYinghai Lu { 400257b0fdeSYinghai Lu struct setup_data *data; 40130e46b57SLinn Crosetto u64 pa_data, pa_next; 402257b0fdeSYinghai Lu 403257b0fdeSYinghai Lu pa_data = boot_params.hdr.setup_data; 404257b0fdeSYinghai Lu while (pa_data) { 4057389882cSWANG Chao u32 data_len, data_type; 406f1c2b357SSebastian Andrzej Siewior 4077389882cSWANG Chao data = early_memremap(pa_data, sizeof(*data)); 408f1c2b357SSebastian Andrzej Siewior data_len = data->len + sizeof(struct setup_data); 40930e46b57SLinn Crosetto data_type = data->type; 41030e46b57SLinn Crosetto pa_next = data->next; 4118d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 412f1c2b357SSebastian Andrzej Siewior 41330e46b57SLinn Crosetto switch (data_type) { 414257b0fdeSYinghai Lu case SETUP_E820_EXT: 415914053c0SIngo Molnar e820__memory_setup_extended(pa_data, data_len); 416257b0fdeSYinghai Lu break; 417da6b737bSSebastian Andrzej Siewior case SETUP_DTB: 418da6b737bSSebastian Andrzej Siewior add_dtb(pa_data); 419257b0fdeSYinghai Lu break; 4201fec0533SDave Young case SETUP_EFI: 4211fec0533SDave Young parse_efi_setup(pa_data, data_len); 4221fec0533SDave Young break; 423257b0fdeSYinghai Lu default: 424257b0fdeSYinghai Lu break; 425257b0fdeSYinghai Lu } 42630e46b57SLinn Crosetto pa_data = pa_next; 427257b0fdeSYinghai Lu } 428257b0fdeSYinghai Lu } 429257b0fdeSYinghai Lu 430a9ce6bc1SYinghai Lu static void __init memblock_x86_reserve_range_setup_data(void) 431a0a0becdSYinghai Lu { 432a0a0becdSYinghai Lu struct setup_data *data; 433a0a0becdSYinghai Lu u64 pa_data; 434a0a0becdSYinghai Lu 435a0a0becdSYinghai Lu pa_data = boot_params.hdr.setup_data; 436a0a0becdSYinghai Lu while (pa_data) { 43788b4c146SJeremy Fitzhardinge data = early_memremap(pa_data, sizeof(*data)); 43824aa0788STejun Heo memblock_reserve(pa_data, sizeof(*data) + data->len); 439a0a0becdSYinghai Lu pa_data = data->next; 4408d4a40bcSJuergen Gross early_memunmap(data, sizeof(*data)); 441a0a0becdSYinghai Lu } 442a0a0becdSYinghai Lu } 443a0a0becdSYinghai Lu 44455f26239SYinghai Lu /* 445ccb4defaSYinghai Lu * --------- Crashkernel reservation ------------------------------ 446ccb4defaSYinghai Lu */ 447ccb4defaSYinghai Lu 4482965faa5SDave Young #ifdef CONFIG_KEXEC_CORE 44932105f7fSBernhard Walle 450606134f7SBorislav Petkov /* 16M alignment for crash kernel regions */ 451606134f7SBorislav Petkov #define CRASH_ALIGN (16 << 20) 452606134f7SBorislav Petkov 4537f8595bfSH. Peter Anvin /* 4547f8595bfSH. Peter Anvin * Keep the crash kernel below this limit. On 32 bits earlier kernels 4557f8595bfSH. Peter Anvin * would limit the kernel to the low 512 MiB due to mapping restrictions. 45655a20ee7SYinghai Lu * On 64bit, old kexec-tools need to under 896MiB. 4577f8595bfSH. Peter Anvin */ 4587f8595bfSH. Peter Anvin #ifdef CONFIG_X86_32 45997eac21bSBorislav Petkov # define CRASH_ADDR_LOW_MAX (512 << 20) 46097eac21bSBorislav Petkov # define CRASH_ADDR_HIGH_MAX (512 << 20) 4617f8595bfSH. Peter Anvin #else 46297eac21bSBorislav Petkov # define CRASH_ADDR_LOW_MAX (896UL << 20) 46397eac21bSBorislav Petkov # define CRASH_ADDR_HIGH_MAX MAXMEM 4647f8595bfSH. Peter Anvin #endif 4657f8595bfSH. Peter Anvin 466eb6db83dSBaoquan He static int __init reserve_crashkernel_low(void) 4670212f915SYinghai Lu { 4680212f915SYinghai Lu #ifdef CONFIG_X86_64 469f56d5578SBorislav Petkov unsigned long long base, low_base = 0, low_size = 0; 4700212f915SYinghai Lu unsigned long total_low_mem; 4710212f915SYinghai Lu int ret; 4720212f915SYinghai Lu 4730212f915SYinghai Lu total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); 47497eac21bSBorislav Petkov 475adbc742bSYinghai Lu /* crashkernel=Y,low */ 47697eac21bSBorislav Petkov ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base); 477f56d5578SBorislav Petkov if (ret) { 478c729de8fSYinghai Lu /* 479c729de8fSYinghai Lu * two parts from lib/swiotlb.c: 48094fb9334SJoerg Roedel * -swiotlb size: user-specified with swiotlb= or default. 48194fb9334SJoerg Roedel * 48294fb9334SJoerg Roedel * -swiotlb overflow buffer: now hardcoded to 32k. We round it 48394fb9334SJoerg Roedel * to 8M for other buffers that may need to stay low too. Also 48494fb9334SJoerg Roedel * make sure we allocate enough extra low memory so that we 48594fb9334SJoerg Roedel * don't run out of DMA buffers for 32-bit devices. 486c729de8fSYinghai Lu */ 48794fb9334SJoerg Roedel low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); 488c729de8fSYinghai Lu } else { 489adbc742bSYinghai Lu /* passed with crashkernel=0,low ? */ 490c729de8fSYinghai Lu if (!low_size) 491eb6db83dSBaoquan He return 0; 492c729de8fSYinghai Lu } 4930212f915SYinghai Lu 494fe2d48b8SJiri Bohac low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN); 4950212f915SYinghai Lu if (!low_base) { 496eb6db83dSBaoquan He pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", 497eb6db83dSBaoquan He (unsigned long)(low_size >> 20)); 498eb6db83dSBaoquan He return -ENOMEM; 4990212f915SYinghai Lu } 5000212f915SYinghai Lu 5016f376057SBorislav Petkov ret = memblock_reserve(low_base, low_size); 5026f376057SBorislav Petkov if (ret) { 5036f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel low memblock.\n", __func__); 5046f376057SBorislav Petkov return ret; 5056f376057SBorislav Petkov } 50697eac21bSBorislav Petkov 5070212f915SYinghai Lu pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n", 5080212f915SYinghai Lu (unsigned long)(low_size >> 20), 5090212f915SYinghai Lu (unsigned long)(low_base >> 20), 5100212f915SYinghai Lu (unsigned long)(total_low_mem >> 20)); 51197eac21bSBorislav Petkov 5120212f915SYinghai Lu crashk_low_res.start = low_base; 5130212f915SYinghai Lu crashk_low_res.end = low_base + low_size - 1; 5140212f915SYinghai Lu insert_resource(&iomem_resource, &crashk_low_res); 5150212f915SYinghai Lu #endif 516eb6db83dSBaoquan He return 0; 5170212f915SYinghai Lu } 5180212f915SYinghai Lu 51929f784e3SYinghai Lu static void __init reserve_crashkernel(void) 520ccb4defaSYinghai Lu { 521f56d5578SBorislav Petkov unsigned long long crash_size, crash_base, total_mem; 52255a20ee7SYinghai Lu bool high = false; 523ccb4defaSYinghai Lu int ret; 524ccb4defaSYinghai Lu 52509c71bfdSDave Young total_mem = memblock_phys_mem_size(); 526ccb4defaSYinghai Lu 52755a20ee7SYinghai Lu /* crashkernel=XM */ 52897eac21bSBorislav Petkov ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); 52955a20ee7SYinghai Lu if (ret != 0 || crash_size <= 0) { 530adbc742bSYinghai Lu /* crashkernel=X,high */ 53155a20ee7SYinghai Lu ret = parse_crashkernel_high(boot_command_line, total_mem, 53255a20ee7SYinghai Lu &crash_size, &crash_base); 53332105f7fSBernhard Walle if (ret != 0 || crash_size <= 0) 53432105f7fSBernhard Walle return; 53555a20ee7SYinghai Lu high = true; 53655a20ee7SYinghai Lu } 53732105f7fSBernhard Walle 538*3db3eb28SPetr Tesarik if (xen_pv_domain()) { 539*3db3eb28SPetr Tesarik pr_info("Ignoring crashkernel for a Xen PV domain\n"); 540*3db3eb28SPetr Tesarik return; 541*3db3eb28SPetr Tesarik } 542*3db3eb28SPetr Tesarik 54332105f7fSBernhard Walle /* 0 means: find the address automatically */ 544ccb4defaSYinghai Lu if (crash_base <= 0) { 5459f4c1396SYinghai Lu /* 546a8d4c824SXunlei Pang * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, 547a8d4c824SXunlei Pang * as old kexec-tools loads bzImage below that, unless 548a8d4c824SXunlei Pang * "crashkernel=size[KMG],high" is specified. 5499f4c1396SYinghai Lu */ 550606134f7SBorislav Petkov crash_base = memblock_find_in_range(CRASH_ALIGN, 55197eac21bSBorislav Petkov high ? CRASH_ADDR_HIGH_MAX 55297eac21bSBorislav Petkov : CRASH_ADDR_LOW_MAX, 553606134f7SBorislav Petkov crash_size, CRASH_ALIGN); 5541f5026a7STejun Heo if (!crash_base) { 55544280733SYinghai Lu pr_info("crashkernel reservation failed - No suitable area found.\n"); 556ccb4defaSYinghai Lu return; 557ccb4defaSYinghai Lu } 5580212f915SYinghai Lu 55932105f7fSBernhard Walle } else { 56044280733SYinghai Lu unsigned long long start; 56144280733SYinghai Lu 5629f4c1396SYinghai Lu start = memblock_find_in_range(crash_base, 56397eac21bSBorislav Petkov crash_base + crash_size, 56497eac21bSBorislav Petkov crash_size, 1 << 20); 56544280733SYinghai Lu if (start != crash_base) { 56644280733SYinghai Lu pr_info("crashkernel reservation failed - memory is in use.\n"); 567ccb4defaSYinghai Lu return; 568ccb4defaSYinghai Lu } 56932105f7fSBernhard Walle } 5706f376057SBorislav Petkov ret = memblock_reserve(crash_base, crash_size); 5716f376057SBorislav Petkov if (ret) { 5726f376057SBorislav Petkov pr_err("%s: Error reserving crashkernel memblock.\n", __func__); 5736f376057SBorislav Petkov return; 5746f376057SBorislav Petkov } 575ccb4defaSYinghai Lu 576eb6db83dSBaoquan He if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { 577eb6db83dSBaoquan He memblock_free(crash_base, crash_size); 578eb6db83dSBaoquan He return; 579eb6db83dSBaoquan He } 580eb6db83dSBaoquan He 581f56d5578SBorislav Petkov pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", 582ccb4defaSYinghai Lu (unsigned long)(crash_size >> 20), 583ccb4defaSYinghai Lu (unsigned long)(crash_base >> 20), 584ccb4defaSYinghai Lu (unsigned long)(total_mem >> 20)); 585ccb4defaSYinghai Lu 586ccb4defaSYinghai Lu crashk_res.start = crash_base; 587ccb4defaSYinghai Lu crashk_res.end = crash_base + crash_size - 1; 588ccb4defaSYinghai Lu insert_resource(&iomem_resource, &crashk_res); 589ccb4defaSYinghai Lu } 590ccb4defaSYinghai Lu #else 59129f784e3SYinghai Lu static void __init reserve_crashkernel(void) 592ccb4defaSYinghai Lu { 593ccb4defaSYinghai Lu } 594ccb4defaSYinghai Lu #endif 595ccb4defaSYinghai Lu 596bdba0e70SYinghai Lu static struct resource standard_io_resources[] = { 597bdba0e70SYinghai Lu { .name = "dma1", .start = 0x00, .end = 0x1f, 598bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 599bdba0e70SYinghai Lu { .name = "pic1", .start = 0x20, .end = 0x21, 600bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 601bdba0e70SYinghai Lu { .name = "timer0", .start = 0x40, .end = 0x43, 602bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 603bdba0e70SYinghai Lu { .name = "timer1", .start = 0x50, .end = 0x53, 604bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 605bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x60, .end = 0x60, 606bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 607bdba0e70SYinghai Lu { .name = "keyboard", .start = 0x64, .end = 0x64, 608bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 609bdba0e70SYinghai Lu { .name = "dma page reg", .start = 0x80, .end = 0x8f, 610bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 611bdba0e70SYinghai Lu { .name = "pic2", .start = 0xa0, .end = 0xa1, 612bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 613bdba0e70SYinghai Lu { .name = "dma2", .start = 0xc0, .end = 0xdf, 614bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO }, 615bdba0e70SYinghai Lu { .name = "fpu", .start = 0xf0, .end = 0xff, 616bdba0e70SYinghai Lu .flags = IORESOURCE_BUSY | IORESOURCE_IO } 617bdba0e70SYinghai Lu }; 618bdba0e70SYinghai Lu 6198fee697dSThomas Gleixner void __init reserve_standard_io_resources(void) 620bdba0e70SYinghai Lu { 621bdba0e70SYinghai Lu int i; 622bdba0e70SYinghai Lu 623bdba0e70SYinghai Lu /* request I/O space for devices used on all i[345]86 PCs */ 624bdba0e70SYinghai Lu for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) 625bdba0e70SYinghai Lu request_resource(&ioport_resource, &standard_io_resources[i]); 626bdba0e70SYinghai Lu 627bdba0e70SYinghai Lu } 628bdba0e70SYinghai Lu 629042be38eSYinghai Lu static __init void reserve_ibft_region(void) 630042be38eSYinghai Lu { 631042be38eSYinghai Lu unsigned long addr, size = 0; 632042be38eSYinghai Lu 633042be38eSYinghai Lu addr = find_ibft_region(&size); 634042be38eSYinghai Lu 635042be38eSYinghai Lu if (size) 63624aa0788STejun Heo memblock_reserve(addr, size); 637042be38eSYinghai Lu } 638042be38eSYinghai Lu 639a9acc536SJesse Barnes static bool __init snb_gfx_workaround_needed(void) 640a9acc536SJesse Barnes { 641e43b3cecSH. Peter Anvin #ifdef CONFIG_PCI 642a9acc536SJesse Barnes int i; 643a9acc536SJesse Barnes u16 vendor, devid; 644ab3cd867SH. Peter Anvin static const __initconst u16 snb_ids[] = { 645a9acc536SJesse Barnes 0x0102, 646a9acc536SJesse Barnes 0x0112, 647a9acc536SJesse Barnes 0x0122, 648a9acc536SJesse Barnes 0x0106, 649a9acc536SJesse Barnes 0x0116, 650a9acc536SJesse Barnes 0x0126, 651a9acc536SJesse Barnes 0x010a, 652a9acc536SJesse Barnes }; 653a9acc536SJesse Barnes 654a9acc536SJesse Barnes /* Assume no if something weird is going on with PCI */ 655a9acc536SJesse Barnes if (!early_pci_allowed()) 656a9acc536SJesse Barnes return false; 657a9acc536SJesse Barnes 658a9acc536SJesse Barnes vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); 659a9acc536SJesse Barnes if (vendor != 0x8086) 660a9acc536SJesse Barnes return false; 661a9acc536SJesse Barnes 662a9acc536SJesse Barnes devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); 663a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(snb_ids); i++) 664a9acc536SJesse Barnes if (devid == snb_ids[i]) 665a9acc536SJesse Barnes return true; 666e43b3cecSH. Peter Anvin #endif 667a9acc536SJesse Barnes 668a9acc536SJesse Barnes return false; 669a9acc536SJesse Barnes } 670a9acc536SJesse Barnes 671a9acc536SJesse Barnes /* 672a9acc536SJesse Barnes * Sandy Bridge graphics has trouble with certain ranges, exclude 673a9acc536SJesse Barnes * them from allocation. 674a9acc536SJesse Barnes */ 675a9acc536SJesse Barnes static void __init trim_snb_memory(void) 676a9acc536SJesse Barnes { 677ab3cd867SH. Peter Anvin static const __initconst unsigned long bad_pages[] = { 678a9acc536SJesse Barnes 0x20050000, 679a9acc536SJesse Barnes 0x20110000, 680a9acc536SJesse Barnes 0x20130000, 681a9acc536SJesse Barnes 0x20138000, 682a9acc536SJesse Barnes 0x40004000, 683a9acc536SJesse Barnes }; 684a9acc536SJesse Barnes int i; 685a9acc536SJesse Barnes 686a9acc536SJesse Barnes if (!snb_gfx_workaround_needed()) 687a9acc536SJesse Barnes return; 688a9acc536SJesse Barnes 689a9acc536SJesse Barnes printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); 690a9acc536SJesse Barnes 691a9acc536SJesse Barnes /* 692a9acc536SJesse Barnes * Reserve all memory below the 1 MB mark that has not 693a9acc536SJesse Barnes * already been reserved. 694a9acc536SJesse Barnes */ 695a9acc536SJesse Barnes memblock_reserve(0, 1<<20); 696a9acc536SJesse Barnes 697a9acc536SJesse Barnes for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { 698a9acc536SJesse Barnes if (memblock_reserve(bad_pages[i], PAGE_SIZE)) 699a9acc536SJesse Barnes printk(KERN_WARNING "failed to reserve 0x%08lx\n", 700a9acc536SJesse Barnes bad_pages[i]); 701a9acc536SJesse Barnes } 702a9acc536SJesse Barnes } 703a9acc536SJesse Barnes 704a9acc536SJesse Barnes /* 705a9acc536SJesse Barnes * Here we put platform-specific memory range workarounds, i.e. 706a9acc536SJesse Barnes * memory known to be corrupt or otherwise in need to be reserved on 707a9acc536SJesse Barnes * specific platforms. 708a9acc536SJesse Barnes * 709a9acc536SJesse Barnes * If this gets used more widely it could use a real dispatch mechanism. 710a9acc536SJesse Barnes */ 711a9acc536SJesse Barnes static void __init trim_platform_memory_ranges(void) 712a9acc536SJesse Barnes { 713a9acc536SJesse Barnes trim_snb_memory(); 714a9acc536SJesse Barnes } 715a9acc536SJesse Barnes 7161b5576e6SYinghai Lu static void __init trim_bios_range(void) 7171b5576e6SYinghai Lu { 7181b5576e6SYinghai Lu /* 7191b5576e6SYinghai Lu * A special case is the first 4Kb of memory; 7201b5576e6SYinghai Lu * This is a BIOS owned area, not kernel ram, but generally 7211b5576e6SYinghai Lu * not listed as such in the E820 table. 722d0cd7425SH. Peter Anvin * 723d0cd7425SH. Peter Anvin * This typically reserves additional memory (64KiB by default) 724d0cd7425SH. Peter Anvin * since some BIOSes are known to corrupt low memory. See the 7259ea77bdbSH. Peter Anvin * Kconfig help text for X86_RESERVE_LOW. 7261b5576e6SYinghai Lu */ 72709821ff1SIngo Molnar e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); 728d0cd7425SH. Peter Anvin 7291b5576e6SYinghai Lu /* 7301b5576e6SYinghai Lu * special case: Some BIOSen report the PC BIOS 7311b5576e6SYinghai Lu * area (640->1Mb) as ram even though it is not. 7321b5576e6SYinghai Lu * take them out. 7331b5576e6SYinghai Lu */ 73409821ff1SIngo Molnar e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); 735a9acc536SJesse Barnes 736f9748fa0SIngo Molnar e820__update_table(e820_table); 7371b5576e6SYinghai Lu } 7381b5576e6SYinghai Lu 739b422a309SYinghai Lu /* called before trim_bios_range() to spare extra sanitize */ 740b422a309SYinghai Lu static void __init e820_add_kernel_range(void) 741b422a309SYinghai Lu { 742b422a309SYinghai Lu u64 start = __pa_symbol(_text); 743b422a309SYinghai Lu u64 size = __pa_symbol(_end) - start; 744b422a309SYinghai Lu 745b422a309SYinghai Lu /* 74609821ff1SIngo Molnar * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and 747b422a309SYinghai Lu * attempt to fix it by adding the range. We may have a confused BIOS, 748b422a309SYinghai Lu * or the user may have used memmap=exactmap or memmap=xxM$yyM to 749b422a309SYinghai Lu * exclude kernel range. If we really are running on top non-RAM, 750b422a309SYinghai Lu * we will crash later anyways. 751b422a309SYinghai Lu */ 75209821ff1SIngo Molnar if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) 753b422a309SYinghai Lu return; 754b422a309SYinghai Lu 75509821ff1SIngo Molnar pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); 75609821ff1SIngo Molnar e820__range_remove(start, size, E820_TYPE_RAM, 0); 75709821ff1SIngo Molnar e820__range_add(start, size, E820_TYPE_RAM); 758b422a309SYinghai Lu } 759b422a309SYinghai Lu 76095c96084SH. Peter Anvin static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10; 76195c96084SH. Peter Anvin 7629ea77bdbSH. Peter Anvin static int __init parse_reservelow(char *p) 7639ea77bdbSH. Peter Anvin { 7649ea77bdbSH. Peter Anvin unsigned long long size; 7659ea77bdbSH. Peter Anvin 7669ea77bdbSH. Peter Anvin if (!p) 7679ea77bdbSH. Peter Anvin return -EINVAL; 7689ea77bdbSH. Peter Anvin 7699ea77bdbSH. Peter Anvin size = memparse(p, &p); 7709ea77bdbSH. Peter Anvin 7719ea77bdbSH. Peter Anvin if (size < 4096) 7729ea77bdbSH. Peter Anvin size = 4096; 7739ea77bdbSH. Peter Anvin 7749ea77bdbSH. Peter Anvin if (size > 640*1024) 7759ea77bdbSH. Peter Anvin size = 640*1024; 7769ea77bdbSH. Peter Anvin 7779ea77bdbSH. Peter Anvin reserve_low = size; 7789ea77bdbSH. Peter Anvin 7799ea77bdbSH. Peter Anvin return 0; 7809ea77bdbSH. Peter Anvin } 7819ea77bdbSH. Peter Anvin 7829ea77bdbSH. Peter Anvin early_param("reservelow", parse_reservelow); 7839ea77bdbSH. Peter Anvin 78495c96084SH. Peter Anvin static void __init trim_low_memory_range(void) 78595c96084SH. Peter Anvin { 78695c96084SH. Peter Anvin memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); 78795c96084SH. Peter Anvin } 78895c96084SH. Peter Anvin 7895394f80fSJeremy Fitzhardinge /* 790f32360efSKees Cook * Dump out kernel offset information on panic. 791f32360efSKees Cook */ 792f32360efSKees Cook static int 793f32360efSKees Cook dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) 794f32360efSKees Cook { 79578cac48cSBorislav Petkov if (kaslr_enabled()) { 79678cac48cSBorislav Petkov pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", 7974545c898SJiri Kosina kaslr_offset(), 79878cac48cSBorislav Petkov __START_KERNEL, 79978cac48cSBorislav Petkov __START_KERNEL_map, 80078cac48cSBorislav Petkov MODULES_VADDR-1); 80178cac48cSBorislav Petkov } else { 80278cac48cSBorislav Petkov pr_emerg("Kernel Offset: disabled\n"); 80378cac48cSBorislav Petkov } 804f32360efSKees Cook 805f32360efSKees Cook return 0; 806f32360efSKees Cook } 807f32360efSKees Cook 808f32360efSKees Cook /* 80955f26239SYinghai Lu * Determine if we were loaded by an EFI loader. If so, then we have also been 81055f26239SYinghai Lu * passed the efi memmap, systab, etc., so we should use these data structures 81155f26239SYinghai Lu * for initialization. Note, the efi init code path is determined by the 81255f26239SYinghai Lu * global efi_enabled. This allows the same kernel image to be used on existing 81355f26239SYinghai Lu * systems (with a traditional BIOS) as well as on EFI systems. 81455f26239SYinghai Lu */ 81555f26239SYinghai Lu /* 81655f26239SYinghai Lu * setup_arch - architecture-specific boot-time initializations 81755f26239SYinghai Lu * 81855f26239SYinghai Lu * Note: On x86_64, fixmaps are ready for use even before this is called. 81955f26239SYinghai Lu */ 82055f26239SYinghai Lu 82155f26239SYinghai Lu void __init setup_arch(char **cmdline_p) 82255f26239SYinghai Lu { 8236c902b65SYinghai Lu memblock_reserve(__pa_symbol(_text), 8246c902b65SYinghai Lu (unsigned long)__bss_stop - (unsigned long)_text); 8256c902b65SYinghai Lu 8261b8c78beSYinghai Lu early_reserve_initrd(); 8271b8c78beSYinghai Lu 8286c902b65SYinghai Lu /* 8296c902b65SYinghai Lu * At this point everything still needed from the boot loader 8306c902b65SYinghai Lu * or BIOS or kernel text should be early reserved or marked not 8316c902b65SYinghai Lu * RAM in e820. All other memory is free game. 8326c902b65SYinghai Lu */ 8336c902b65SYinghai Lu 83455f26239SYinghai Lu #ifdef CONFIG_X86_32 83555f26239SYinghai Lu memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); 836b40827faSBorislav Petkov 837b40827faSBorislav Petkov /* 838b40827faSBorislav Petkov * copy kernel address range established so far and switch 839b40827faSBorislav Petkov * to the proper swapper page table 840b40827faSBorislav Petkov */ 841b40827faSBorislav Petkov clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, 842b40827faSBorislav Petkov initial_page_table + KERNEL_PGD_BOUNDARY, 843b40827faSBorislav Petkov KERNEL_PGD_PTRS); 844b40827faSBorislav Petkov 845b40827faSBorislav Petkov load_cr3(swapper_pg_dir); 8462075244fSBryan O'Donoghue /* 8472075244fSBryan O'Donoghue * Note: Quark X1000 CPUs advertise PGE incorrectly and require 8482075244fSBryan O'Donoghue * a cr3 based tlb flush, so the following __flush_tlb_all() 8492075244fSBryan O'Donoghue * will not flush anything because the cpu quirk which clears 8502075244fSBryan O'Donoghue * X86_FEATURE_PGE has not been invoked yet. Though due to the 8512075244fSBryan O'Donoghue * load_cr3() above the TLB has been flushed already. The 8522075244fSBryan O'Donoghue * quirk is invoked before subsequent calls to __flush_tlb_all() 8532075244fSBryan O'Donoghue * so proper operation is guaranteed. 8542075244fSBryan O'Donoghue */ 855b40827faSBorislav Petkov __flush_tlb_all(); 85655f26239SYinghai Lu #else 85755f26239SYinghai Lu printk(KERN_INFO "Command line: %s\n", boot_command_line); 858162434e7SKirill A. Shutemov boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; 85955f26239SYinghai Lu #endif 86055f26239SYinghai Lu 8619863c90fSAlok Kataria /* 8629863c90fSAlok Kataria * If we have OLPC OFW, we might end up relocating the fixmap due to 8639863c90fSAlok Kataria * reserve_top(), so do this before touching the ioremap area. 8649863c90fSAlok Kataria */ 865fd699c76SAndres Salomon olpc_ofw_detect(); 866fd699c76SAndres Salomon 867433f8924SThomas Gleixner idt_setup_early_traps(); 8689e882c92SJeremy Fitzhardinge early_cpu_init(); 8691a98fd14SJeremy Fitzhardinge early_ioremap_init(); 8701a98fd14SJeremy Fitzhardinge 871fd699c76SAndres Salomon setup_olpc_ofw_pgd(); 872fd699c76SAndres Salomon 87355f26239SYinghai Lu ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); 87455f26239SYinghai Lu screen_info = boot_params.screen_info; 87555f26239SYinghai Lu edid_info = boot_params.edid_info; 87655f26239SYinghai Lu #ifdef CONFIG_X86_32 87755f26239SYinghai Lu apm_info.bios = boot_params.apm_bios_info; 87855f26239SYinghai Lu ist_info = boot_params.ist_info; 87955f26239SYinghai Lu #endif 88055f26239SYinghai Lu saved_video_mode = boot_params.hdr.vid_mode; 88155f26239SYinghai Lu bootloader_type = boot_params.hdr.type_of_loader; 8825031296cSH. Peter Anvin if ((bootloader_type >> 4) == 0xe) { 8835031296cSH. Peter Anvin bootloader_type &= 0xf; 8845031296cSH. Peter Anvin bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; 8855031296cSH. Peter Anvin } 8865031296cSH. Peter Anvin bootloader_version = bootloader_type & 0xf; 8875031296cSH. Peter Anvin bootloader_version |= boot_params.hdr.ext_loader_ver << 4; 88855f26239SYinghai Lu 88955f26239SYinghai Lu #ifdef CONFIG_BLK_DEV_RAM 89055f26239SYinghai Lu rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; 89155f26239SYinghai Lu rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0); 89255f26239SYinghai Lu rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0); 89355f26239SYinghai Lu #endif 89455f26239SYinghai Lu #ifdef CONFIG_EFI 89555f26239SYinghai Lu if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 8969402973dSDaniel Kiper EFI32_LOADER_SIGNATURE, 4)) { 8973e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 8981adbfa35SOlof Johansson } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 8999402973dSDaniel Kiper EFI64_LOADER_SIGNATURE, 4)) { 9003e909599SMatt Fleming set_bit(EFI_BOOT, &efi.flags); 9013e909599SMatt Fleming set_bit(EFI_64BIT, &efi.flags); 90255f26239SYinghai Lu } 90355f26239SYinghai Lu #endif 90455f26239SYinghai Lu 90542bbdb43SThomas Gleixner x86_init.oem.arch_setup(); 90655f26239SYinghai Lu 907419afdf5SBjorn Helgaas iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 908103e2063SIngo Molnar e820__memory_setup(); 90928bb2237SYinghai Lu parse_setup_data(); 91028bb2237SYinghai Lu 91155f26239SYinghai Lu copy_edd(); 91255f26239SYinghai Lu 91355f26239SYinghai Lu if (!boot_params.hdr.root_flags) 91455f26239SYinghai Lu root_mountflags &= ~MS_RDONLY; 91555f26239SYinghai Lu init_mm.start_code = (unsigned long) _text; 91655f26239SYinghai Lu init_mm.end_code = (unsigned long) _etext; 91755f26239SYinghai Lu init_mm.end_data = (unsigned long) _edata; 91893dbda7cSJeremy Fitzhardinge init_mm.brk = _brk_end; 91955f26239SYinghai Lu 920fe3d197fSDave Hansen mpx_mm_init(&init_mm); 921fe3d197fSDave Hansen 9224046d6e8SLinus Torvalds code_resource.start = __pa_symbol(_text); 9234046d6e8SLinus Torvalds code_resource.end = __pa_symbol(_etext)-1; 9244046d6e8SLinus Torvalds data_resource.start = __pa_symbol(_etext); 9254046d6e8SLinus Torvalds data_resource.end = __pa_symbol(_edata)-1; 9264046d6e8SLinus Torvalds bss_resource.start = __pa_symbol(__bss_start); 9274046d6e8SLinus Torvalds bss_resource.end = __pa_symbol(__bss_stop)-1; 9284046d6e8SLinus Torvalds 929516cbf37STim Bird #ifdef CONFIG_CMDLINE_BOOL 930516cbf37STim Bird #ifdef CONFIG_CMDLINE_OVERRIDE 931516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 932516cbf37STim Bird #else 933516cbf37STim Bird if (builtin_cmdline[0]) { 934516cbf37STim Bird /* append boot loader cmdline to builtin */ 935516cbf37STim Bird strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); 936516cbf37STim Bird strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); 937516cbf37STim Bird strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); 938516cbf37STim Bird } 939516cbf37STim Bird #endif 940516cbf37STim Bird #endif 941516cbf37STim Bird 942eda6da92SYinghai Lu strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); 943eda6da92SYinghai Lu *cmdline_p = command_line; 944eda6da92SYinghai Lu 945eda6da92SYinghai Lu /* 9464b0f3b81SKees Cook * x86_configure_nx() is called before parse_early_param() to detect 9474b0f3b81SKees Cook * whether hardware doesn't support NX (so that the early EHCI debug 9484b0f3b81SKees Cook * console setup can safely call set_fixmap()). It may then be called 9494b0f3b81SKees Cook * again from within noexec_setup() during parsing early parameters 9504b0f3b81SKees Cook * to honor the respective command line option. 951eda6da92SYinghai Lu */ 9524763ed4dSH. Peter Anvin x86_configure_nx(); 953eda6da92SYinghai Lu 954eda6da92SYinghai Lu parse_early_param(); 955eda6da92SYinghai Lu 956835bcec5SDave Young if (efi_enabled(EFI_BOOT)) 957835bcec5SDave Young efi_memblock_x86_reserve_range(); 95839fa104dSReza Arbab #ifdef CONFIG_MEMORY_HOTPLUG 95939fa104dSReza Arbab /* 96039fa104dSReza Arbab * Memory used by the kernel cannot be hot-removed because Linux 96139fa104dSReza Arbab * cannot migrate the kernel pages. When memory hotplug is 96239fa104dSReza Arbab * enabled, we should prevent memblock from allocating memory 96339fa104dSReza Arbab * for the kernel. 96439fa104dSReza Arbab * 96539fa104dSReza Arbab * ACPI SRAT records all hotpluggable memory ranges. But before 96639fa104dSReza Arbab * SRAT is parsed, we don't know about it. 96739fa104dSReza Arbab * 96839fa104dSReza Arbab * The kernel image is loaded into memory at very early time. We 96939fa104dSReza Arbab * cannot prevent this anyway. So on NUMA system, we set any 97039fa104dSReza Arbab * node the kernel resides in as un-hotpluggable. 97139fa104dSReza Arbab * 97239fa104dSReza Arbab * Since on modern servers, one node could have double-digit 97339fa104dSReza Arbab * gigabytes memory, we can assume the memory around the kernel 97439fa104dSReza Arbab * image is also un-hotpluggable. So before SRAT is parsed, just 97539fa104dSReza Arbab * allocate memory near the kernel image to try the best to keep 97639fa104dSReza Arbab * the kernel away from hotpluggable memory. 97739fa104dSReza Arbab */ 97839fa104dSReza Arbab if (movable_node_is_enabled()) 97939fa104dSReza Arbab memblock_set_bottom_up(true); 98039fa104dSReza Arbab #endif 98139fa104dSReza Arbab 9824b0f3b81SKees Cook x86_report_nx(); 9830ad5bce7SJeremy Fitzhardinge 98428bb2237SYinghai Lu /* after early param, so could get panic from serial */ 985a9ce6bc1SYinghai Lu memblock_x86_reserve_range_setup_data(); 98628bb2237SYinghai Lu 98755f26239SYinghai Lu if (acpi_mps_check()) { 98855f26239SYinghai Lu #ifdef CONFIG_X86_LOCAL_APIC 98955f26239SYinghai Lu disable_apic = 1; 99055f26239SYinghai Lu #endif 991988781dcSYinghai Lu setup_clear_cpu_cap(X86_FEATURE_APIC); 99255f26239SYinghai Lu } 99355f26239SYinghai Lu 994dc7c65dbSLinus Torvalds #ifdef CONFIG_PCI 995dc7c65dbSLinus Torvalds if (pci_early_dump_regs) 996dc7c65dbSLinus Torvalds early_dump_pci_devices(); 997dc7c65dbSLinus Torvalds #endif 998dc7c65dbSLinus Torvalds 9991a127034SIngo Molnar e820__reserve_setup_data(); 10009641bdafSIngo Molnar e820__finish_early_params(); 100155f26239SYinghai Lu 100283e68189SMatt Fleming if (efi_enabled(EFI_BOOT)) 1003ff0c0874SBrian Maly efi_init(); 1004ff0c0874SBrian Maly 10052216d199SYinghai Lu dmi_scan_machine(); 1006dd6dad42SChen, Gong dmi_memdev_walk(); 100798e5e1bfSTejun Heo dmi_set_dump_stack_arch_desc(); 10082216d199SYinghai Lu 100988b094fbSAlok Kataria /* 101088b094fbSAlok Kataria * VMware detection requires dmi to be available, so this 1011a1652bb8SJean Delvare * needs to be done after dmi_scan_machine(), for the boot CPU. 101288b094fbSAlok Kataria */ 10132d826404SThomas Gleixner init_hypervisor_platform(); 101488b094fbSAlok Kataria 1015f7cf5a5bSThomas Gleixner x86_init.resources.probe_roms(); 101655f26239SYinghai Lu 10174046d6e8SLinus Torvalds /* after parse_early_param, so could debug it */ 10184046d6e8SLinus Torvalds insert_resource(&iomem_resource, &code_resource); 10194046d6e8SLinus Torvalds insert_resource(&iomem_resource, &data_resource); 10204046d6e8SLinus Torvalds insert_resource(&iomem_resource, &bss_resource); 10214046d6e8SLinus Torvalds 1022b422a309SYinghai Lu e820_add_kernel_range(); 10231b5576e6SYinghai Lu trim_bios_range(); 102455f26239SYinghai Lu #ifdef CONFIG_X86_32 102555f26239SYinghai Lu if (ppro_with_ram_bug()) { 102609821ff1SIngo Molnar e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, 102709821ff1SIngo Molnar E820_TYPE_RESERVED); 1028f9748fa0SIngo Molnar e820__update_table(e820_table); 102955f26239SYinghai Lu printk(KERN_INFO "fixed physical RAM map:\n"); 1030be0c3f0fSIngo Molnar e820__print_table("bad_ppro"); 103155f26239SYinghai Lu } 103255f26239SYinghai Lu #else 103355f26239SYinghai Lu early_gart_iommu_check(); 103455f26239SYinghai Lu #endif 103555f26239SYinghai Lu 103655f26239SYinghai Lu /* 103755f26239SYinghai Lu * partially used pages are not usable - thus 103855f26239SYinghai Lu * we are rounding upwards: 103955f26239SYinghai Lu */ 10400c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 104155f26239SYinghai Lu 104255f26239SYinghai Lu /* update e820 for memory not covered by WB MTRRs */ 104355f26239SYinghai Lu mtrr_bp_init(); 10442dc807b3SYinghai Lu if (mtrr_trim_uncached_memory(max_pfn)) 10450c6fc11aSIngo Molnar max_pfn = e820__end_of_ram_pfn(); 104655f26239SYinghai Lu 10478dd33030SIgor Mammedov max_possible_pfn = max_pfn; 10488dd33030SIgor Mammedov 1049c7d2361fSThomas Garnier /* 105099c13b8cSMikulas Patocka * This call is required when the CPU does not support PAT. If 105199c13b8cSMikulas Patocka * mtrr_bp_init() invoked it already via pat_init() the call has no 105299c13b8cSMikulas Patocka * effect. 105399c13b8cSMikulas Patocka */ 105499c13b8cSMikulas Patocka init_cache_modes(); 105599c13b8cSMikulas Patocka 105699c13b8cSMikulas Patocka /* 1057c7d2361fSThomas Garnier * Define random base addresses for memory sections after max_pfn is 1058c7d2361fSThomas Garnier * defined and before each memory section base is used. 1059c7d2361fSThomas Garnier */ 1060c7d2361fSThomas Garnier kernel_randomize_memory(); 1061c7d2361fSThomas Garnier 106255f26239SYinghai Lu #ifdef CONFIG_X86_32 106355f26239SYinghai Lu /* max_low_pfn get updated here */ 106455f26239SYinghai Lu find_low_pfn_range(); 106555f26239SYinghai Lu #else 10666e1cb38aSSuresh Siddha check_x2apic(); 106755f26239SYinghai Lu 106855f26239SYinghai Lu /* How many end-of-memory variables you have, grandma! */ 106955f26239SYinghai Lu /* need this before calling reserve_initrd */ 1070f361a450SYinghai Lu if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) 10710c6fc11aSIngo Molnar max_low_pfn = e820__end_of_low_ram_pfn(); 1072f361a450SYinghai Lu else 107355f26239SYinghai Lu max_low_pfn = max_pfn; 1074f361a450SYinghai Lu 107555f26239SYinghai Lu high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 107655f26239SYinghai Lu #endif 107755f26239SYinghai Lu 1078893f38d1SYinghai Lu /* 1079893f38d1SYinghai Lu * Find and reserve possible boot-time SMP configuration: 1080893f38d1SYinghai Lu */ 1081893f38d1SYinghai Lu find_smp_config(); 1082893f38d1SYinghai Lu 1083042be38eSYinghai Lu reserve_ibft_region(); 1084042be38eSYinghai Lu 10858d57470dSYinghai Lu early_alloc_pgt_buf(); 10868d57470dSYinghai Lu 108772d7c3b3SYinghai Lu /* 10884918e228SIngo Molnar * Need to conclude brk, before e820__memblock_setup() 108972d7c3b3SYinghai Lu * it could use memblock_find_in_range, could overlap with 109072d7c3b3SYinghai Lu * brk area. 109172d7c3b3SYinghai Lu */ 109272d7c3b3SYinghai Lu reserve_brk(); 109372d7c3b3SYinghai Lu 1094e5f15b45SYinghai Lu cleanup_highmap(); 1095e5f15b45SYinghai Lu 10962449f343STang Chen memblock_set_current_limit(ISA_END_ADDRESS); 10974918e228SIngo Molnar e820__memblock_setup(); 109872d7c3b3SYinghai Lu 1099007b7560SAndy Lutomirski reserve_bios_regions(); 1100007b7560SAndy Lutomirski 11014971531aSMatt Fleming if (efi_enabled(EFI_MEMMAP)) { 11024971531aSMatt Fleming efi_fake_memmap(); 11034971531aSMatt Fleming efi_find_mirror(); 11043dad6f7fSRicardo Neri efi_esrt_init(); 11054971531aSMatt Fleming 1106916f676fSMatthew Garrett /* 11074971531aSMatt Fleming * The EFI specification says that boot service code won't be 11084971531aSMatt Fleming * called after ExitBootServices(). This is, in fact, a lie. 1109916f676fSMatthew Garrett */ 1110916f676fSMatthew Garrett efi_reserve_boot_services(); 11114971531aSMatt Fleming } 1112916f676fSMatthew Garrett 111372d7c3b3SYinghai Lu /* preallocate 4k for mptable mpc */ 11145da217caSIngo Molnar e820__memblock_alloc_reserved_mpc_new(); 111572d7c3b3SYinghai Lu 111672d7c3b3SYinghai Lu #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 111772d7c3b3SYinghai Lu setup_bios_corruption_check(); 111872d7c3b3SYinghai Lu #endif 111972d7c3b3SYinghai Lu 112010054230SYinghai Lu #ifdef CONFIG_X86_32 1121365811d6SBjorn Helgaas printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", 1122365811d6SBjorn Helgaas (max_pfn_mapped<<PAGE_SHIFT) - 1); 112310054230SYinghai Lu #endif 112472d7c3b3SYinghai Lu 11254f7b9226SYinghai Lu reserve_real_mode(); 1126893f38d1SYinghai Lu 1127a9acc536SJesse Barnes trim_platform_memory_ranges(); 112895c96084SH. Peter Anvin trim_low_memory_range(); 1129a9acc536SJesse Barnes 113022ddfcaaSYinghai Lu init_mem_mapping(); 1131854c879fSPekka J Enberg 1132433f8924SThomas Gleixner idt_setup_early_pf(); 1133cda846f1SJarkko Sakkinen 113418bc7bd5SAndy Lutomirski /* 113518bc7bd5SAndy Lutomirski * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) 113618bc7bd5SAndy Lutomirski * with the current CR4 value. This may not be necessary, but 113718bc7bd5SAndy Lutomirski * auditing all the early-boot CR4 manipulation would be needed to 113818bc7bd5SAndy Lutomirski * rule it out. 1139c7ad5ad2SAndy Lutomirski * 1140c7ad5ad2SAndy Lutomirski * Mask off features that don't work outside long mode (just 1141c7ad5ad2SAndy Lutomirski * PCIDE for now). 114218bc7bd5SAndy Lutomirski */ 1143c7ad5ad2SAndy Lutomirski mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; 114418bc7bd5SAndy Lutomirski 11454ce7a869SYinghai Lu memblock_set_current_limit(get_max_mapped()); 1146e7b37895SYinghai Lu 1147e7b37895SYinghai Lu /* 1148e7b37895SYinghai Lu * NOTE: On x86-32, only from this point on, fixmaps are ready for use. 1149e7b37895SYinghai Lu */ 1150e7b37895SYinghai Lu 1151e7b37895SYinghai Lu #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 1152e7b37895SYinghai Lu if (init_ohci1394_dma_early) 1153162a7e75SMike Travis init_ohci1394_dma_on_all_controllers(); 1154162a7e75SMike Travis #endif 1155e7b37895SYinghai Lu /* Allocate bigger log buffer */ 115655f26239SYinghai Lu setup_log_buf(1); 115755f26239SYinghai Lu 11589661b332SDavid Howells if (efi_enabled(EFI_BOOT)) { 11599661b332SDavid Howells switch (boot_params.secure_boot) { 11609661b332SDavid Howells case efi_secureboot_mode_disabled: 11619661b332SDavid Howells pr_info("Secure boot disabled\n"); 11629661b332SDavid Howells break; 11639661b332SDavid Howells case efi_secureboot_mode_enabled: 11649661b332SDavid Howells pr_info("Secure boot enabled\n"); 11659661b332SDavid Howells break; 11669661b332SDavid Howells default: 11679661b332SDavid Howells pr_info("Secure boot could not be determined\n"); 11689661b332SDavid Howells break; 11699661b332SDavid Howells } 11709661b332SDavid Howells } 11719661b332SDavid Howells 117244280733SYinghai Lu reserve_initrd(); 117344280733SYinghai Lu 1174da3d3f98SAleksey Makarov acpi_table_upgrade(); 117555f26239SYinghai Lu 117655f26239SYinghai Lu vsmp_init(); 117755f26239SYinghai Lu 117855f26239SYinghai Lu io_delay_init(); 117955f26239SYinghai Lu 1180630b3affSLukas Wunner early_platform_quirks(); 1181630b3affSLukas Wunner 118255f26239SYinghai Lu /* 118355f26239SYinghai Lu * Parse the ACPI tables for possible boot-time SMP configuration. 118455f26239SYinghai Lu */ 118520e6926dSYinghai Lu acpi_boot_table_init(); 118620e6926dSYinghai Lu 118720e6926dSYinghai Lu early_acpi_boot_init(); 118820e6926dSYinghai Lu 118991467bdfSBernhard Walle initmem_init(); 11903c325f82SWeijie Yang dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); 1191fa591c4aSTang Chen 1192fa591c4aSTang Chen /* 1193fa591c4aSTang Chen * Reserve memory for crash kernel after SRAT is parsed so that it 1194fa591c4aSTang Chen * won't consume hotpluggable memory. 1195fa591c4aSTang Chen */ 1196fa591c4aSTang Chen reserve_crashkernel(); 1197fa591c4aSTang Chen 119855f26239SYinghai Lu memblock_find_dma_reserve(); 119955f26239SYinghai Lu 120055f26239SYinghai Lu #ifdef CONFIG_KVM_GUEST 120155f26239SYinghai Lu kvmclock_init(); 1202030cb6c0SThomas Gleixner #endif 120355f26239SYinghai Lu 1204ccb64941SBoris Ostrovsky tsc_early_delay_calibrate(); 1205ccb64941SBoris Ostrovsky if (!early_xdbc_setup_hardware()) 1206ccb64941SBoris Ostrovsky early_xdbc_register_console(); 1207ccb64941SBoris Ostrovsky 1208030cb6c0SThomas Gleixner x86_init.paging.pagetable_init(); 120955f26239SYinghai Lu 1210ef7f0d6aSAndrey Ryabinin kasan_init(); 1211ef7f0d6aSAndrey Ryabinin 1212d2b6dc61SAndy Lutomirski /* 1213945fd17aSThomas Gleixner * Sync back kernel address range. 1214945fd17aSThomas Gleixner * 1215945fd17aSThomas Gleixner * FIXME: Can the later sync in setup_cpu_entry_areas() replace 1216945fd17aSThomas Gleixner * this call? 1217d2b6dc61SAndy Lutomirski */ 1218945fd17aSThomas Gleixner sync_initial_page_table(); 1219d2b6dc61SAndy Lutomirski 122031625340SJoseph Cihula tboot_probe(); 122131625340SJoseph Cihula 122255f26239SYinghai Lu map_vsyscall(); 122355f26239SYinghai Lu 122455f26239SYinghai Lu generic_apic_probe(); 122555f26239SYinghai Lu 122655f26239SYinghai Lu early_quirks(); 122755f26239SYinghai Lu 122855f26239SYinghai Lu /* 122955f26239SYinghai Lu * Read APIC and some other early information from ACPI tables. 123055f26239SYinghai Lu */ 123155f26239SYinghai Lu acpi_boot_init(); 1232efafc8b2SFeng Tang sfi_init(); 1233a906fdaaSThomas Gleixner x86_dtb_init(); 1234efafc8b2SFeng Tang 123555f26239SYinghai Lu /* 123655f26239SYinghai Lu * get boot-time SMP configuration: 123755f26239SYinghai Lu */ 123855f26239SYinghai Lu get_smp_config(); 123955f26239SYinghai Lu 12401e90a13dSThomas Gleixner /* 12411e90a13dSThomas Gleixner * Systems w/o ACPI and mptables might not have it mapped the local 12421e90a13dSThomas Gleixner * APIC yet, but prefill_possible_map() might need to access it. 12431e90a13dSThomas Gleixner */ 12441e90a13dSThomas Gleixner init_apic_mappings(); 12451e90a13dSThomas Gleixner 1246329513a3SYinghai Lu prefill_possible_map(); 1247301e6190SYinghai Lu 12485f4765f9SYinghai Lu init_cpu_to_node(); 12495f4765f9SYinghai Lu 1250ca1b8862SThomas Gleixner io_apic_init_mappings(); 12519d6a4d08SYinghai Lu 1252f3614646SJuergen Gross x86_init.hyper.guest_late_init(); 125355f26239SYinghai Lu 12541506c8dcSIngo Molnar e820__reserve_resources(); 1255090d7171SIngo Molnar e820__register_nosave_regions(max_low_pfn); 125655f26239SYinghai Lu 12578fee697dSThomas Gleixner x86_init.resources.reserve_resources(); 125855f26239SYinghai Lu 12592df908baSIngo Molnar e820__setup_pci_gap(); 126055f26239SYinghai Lu 126155f26239SYinghai Lu #ifdef CONFIG_VT 126255f26239SYinghai Lu #if defined(CONFIG_VGA_CONSOLE) 126383e68189SMatt Fleming if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) 126455f26239SYinghai Lu conswitchp = &vga_con; 126555f26239SYinghai Lu #elif defined(CONFIG_DUMMY_CONSOLE) 126655f26239SYinghai Lu conswitchp = &dummy_con; 126755f26239SYinghai Lu #endif 126855f26239SYinghai Lu #endif 12696f30c1acSThomas Gleixner x86_init.oem.banner(); 1270a2202aa2SYong Wang 12716b617e22SFeng Tang x86_init.timers.wallclock_init(); 12726b617e22SFeng Tang 1273a2202aa2SYong Wang mcheck_init(); 1274f49aa448SJason Baron 1275dc326fcaSH. Peter Anvin arch_init_ideal_nops(); 1276b3c869d3SJohn Stultz 1277b3c869d3SJohn Stultz register_refined_jiffies(CLOCK_TICK_RATE); 12785189c2a7SOlof Johansson 12795189c2a7SOlof Johansson #ifdef CONFIG_EFI 1280a5d90c92SBorislav Petkov if (efi_enabled(EFI_BOOT)) 1281a5d90c92SBorislav Petkov efi_apply_memmap_quirks(); 12825189c2a7SOlof Johansson #endif 1283ee9f8fceSJosh Poimboeuf 1284ee9f8fceSJosh Poimboeuf unwind_init(); 128555f26239SYinghai Lu } 12865649b7c3SIngo Molnar 12879be1b56aSIngo Molnar #ifdef CONFIG_X86_32 12885649b7c3SIngo Molnar 12898fee697dSThomas Gleixner static struct resource video_ram_resource = { 12908fee697dSThomas Gleixner .name = "Video RAM area", 12918fee697dSThomas Gleixner .start = 0xa0000, 12928fee697dSThomas Gleixner .end = 0xbffff, 12938fee697dSThomas Gleixner .flags = IORESOURCE_BUSY | IORESOURCE_MEM 12949be1b56aSIngo Molnar }; 12959be1b56aSIngo Molnar 12968fee697dSThomas Gleixner void __init i386_reserve_resources(void) 12979be1b56aSIngo Molnar { 12988fee697dSThomas Gleixner request_resource(&iomem_resource, &video_ram_resource); 12998fee697dSThomas Gleixner reserve_standard_io_resources(); 13009be1b56aSIngo Molnar } 13019be1b56aSIngo Molnar 13029be1b56aSIngo Molnar #endif /* CONFIG_X86_32 */ 1303f32360efSKees Cook 1304f32360efSKees Cook static struct notifier_block kernel_offset_notifier = { 1305f32360efSKees Cook .notifier_call = dump_kernel_offset 1306f32360efSKees Cook }; 1307f32360efSKees Cook 1308f32360efSKees Cook static int __init register_kernel_offset_dumper(void) 1309f32360efSKees Cook { 1310f32360efSKees Cook atomic_notifier_chain_register(&panic_notifier_list, 1311f32360efSKees Cook &kernel_offset_notifier); 1312f32360efSKees Cook return 0; 1313f32360efSKees Cook } 1314f32360efSKees Cook __initcall(register_kernel_offset_dumper); 1315c1192f84SDave Hansen 1316c1192f84SDave Hansen void arch_show_smap(struct seq_file *m, struct vm_area_struct *vma) 1317c1192f84SDave Hansen { 1318c1192f84SDave Hansen if (!boot_cpu_has(X86_FEATURE_OSPKE)) 1319c1192f84SDave Hansen return; 1320c1192f84SDave Hansen 1321c1192f84SDave Hansen seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); 1322c1192f84SDave Hansen } 1323