📄 setup_32.c
字号:
/* * Copyright (C) 1995 Linus Torvalds * * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 * * Memory region support * David Parsons <orc@pell.chi.il.us>, July-August 1999 * * Added E820 sanitization routine (removes overlapping memory regions); * Brian Moyle <bmoyle@mvista.com>, February 2001 * * Moved CPU detection code to cpu/${cpu}.c * Patrick Mochel <mochel@osdl.org>, March 2002 * * Provisions for empty E820 memory regions (reported by certain BIOSes). * Alex Achenbach <xela@slit.de>, December 2002. * *//* * This file handles the architecture-dependent parts of initialization */#include <linux/sched.h>#include <linux/mm.h>#include <linux/mmzone.h>#include <linux/screen_info.h>#include <linux/ioport.h>#include <linux/acpi.h>#include <linux/apm_bios.h>#include <linux/initrd.h>#include <linux/bootmem.h>#include <linux/seq_file.h>#include <linux/console.h>#include <linux/mca.h>#include <linux/root_dev.h>#include <linux/highmem.h>#include <linux/module.h>#include <linux/efi.h>#include <linux/init.h>#include <linux/edd.h>#include <linux/nodemask.h>#include <linux/kexec.h>#include <linux/crash_dump.h>#include <linux/dmi.h>#include <linux/pfn.h>#include <video/edid.h>#include <asm/apic.h>#include <asm/e820.h>#include <asm/mpspec.h>#include <asm/mmzone.h>#include <asm/setup.h>#include <asm/arch_hooks.h>#include <asm/sections.h>#include <asm/io_apic.h>#include <asm/ist.h>#include <asm/io.h>#include <asm/vmi.h>#include <setup_arch.h>#include <bios_ebda.h>#include <asm/cacheflush.h>/* This value is set up by the early boot code to point to the value immediately after the boot time page tables. It contains a *physical* address, and must not be in the .bss segment! */unsigned long init_pg_tables_end __initdata = ~0UL;int disable_pse __cpuinitdata = 0;/* * Machine setup.. */extern struct resource code_resource;extern struct resource data_resource;extern struct resource bss_resource;/* cpu data as detected by the assembly code in head.S */struct cpuinfo_x86 new_cpu_data __cpuinitdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };/* common cpu data for all cpus */struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };EXPORT_SYMBOL(boot_cpu_data);unsigned long mmu_cr4_features;/* for MCA, but anyone else can use it if they want */unsigned int machine_id;unsigned int machine_submodel_id;unsigned int BIOS_revision;unsigned int mca_pentium_flag;/* Boot loader ID as an integer, for the benefit of proc_dointvec */int bootloader_type;/* user-defined highmem size */static unsigned int highmem_pages = -1;/* * Setup options */struct screen_info screen_info;EXPORT_SYMBOL(screen_info);struct apm_info apm_info;EXPORT_SYMBOL(apm_info);struct edid_info edid_info;EXPORT_SYMBOL_GPL(edid_info);struct ist_info ist_info;#if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)EXPORT_SYMBOL(ist_info);#endifextern void early_cpu_init(void);extern int root_mountflags;unsigned long saved_videomode;#define RAMDISK_IMAGE_START_MASK 0x07FF#define RAMDISK_PROMPT_FLAG 0x8000#define RAMDISK_LOAD_FLAG 0x4000 static char __initdata command_line[COMMAND_LINE_SIZE];struct boot_params __initdata boot_params;#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)struct edd edd;#ifdef CONFIG_EDD_MODULEEXPORT_SYMBOL(edd);#endif/** * copy_edd() - Copy the BIOS EDD information * from boot_params into a safe place. * */static inline void copy_edd(void){ memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, sizeof(edd.mbr_signature)); memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; edd.edd_info_nr = boot_params.eddbuf_entries;}#elsestatic inline void copy_edd(void){}#endifint __initdata user_defined_memmap = 0;/* * "mem=nopentium" disables the 4MB page tables. * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM * to <mem>, overriding the bios size. * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from * <start> to <start>+<mem>, overriding the bios size. * * HPA tells me bootloaders need to parse mem=, so no new * option should be mem= [also see Documentation/i386/boot.txt] */static int __init parse_mem(char *arg){ if (!arg) return -EINVAL; if (strcmp(arg, "nopentium") == 0) { clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability); disable_pse = 1; } else { /* If the user specifies memory size, we * limit the BIOS-provided memory map to * that size. exactmap can be used to specify * the exact map. mem=number can be used to * trim the existing memory map. */ unsigned long long mem_size; mem_size = memparse(arg, &arg); limit_regions(mem_size); user_defined_memmap = 1; } return 0;}early_param("mem", parse_mem);#ifdef CONFIG_PROC_VMCORE/* elfcorehdr= specifies the location of elf core header * stored by the crashed kernel. */static int __init parse_elfcorehdr(char *arg){ if (!arg) return -EINVAL; elfcorehdr_addr = memparse(arg, &arg); return 0;}early_param("elfcorehdr", parse_elfcorehdr);#endif /* CONFIG_PROC_VMCORE *//* * highmem=size forces highmem to be exactly 'size' bytes. * This works even on boxes that have no highmem otherwise. * This also works to reduce highmem size on bigger boxes. */static int __init parse_highmem(char *arg){ if (!arg) return -EINVAL; highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT; return 0;}early_param("highmem", parse_highmem);/* * vmalloc=size forces the vmalloc area to be exactly 'size' * bytes. This can be used to increase (or decrease) the * vmalloc area - the default is 128m. */static int __init parse_vmalloc(char *arg){ if (!arg) return -EINVAL; __VMALLOC_RESERVE = memparse(arg, &arg); return 0;}early_param("vmalloc", parse_vmalloc);/* * reservetop=size reserves a hole at the top of the kernel address space which * a hypervisor can load into later. Needed for dynamically loaded hypervisors, * so relocating the fixmap can be done before paging initialization. */static int __init parse_reservetop(char *arg){ unsigned long address; if (!arg) return -EINVAL; address = memparse(arg, &arg); reserve_top_address(address); return 0;}early_param("reservetop", parse_reservetop);/* * Determine low and high memory ranges: */unsigned long __init find_max_low_pfn(void){ unsigned long max_low_pfn; max_low_pfn = max_pfn; if (max_low_pfn > MAXMEM_PFN) { if (highmem_pages == -1) highmem_pages = max_pfn - MAXMEM_PFN; if (highmem_pages + MAXMEM_PFN < max_pfn) max_pfn = MAXMEM_PFN + highmem_pages; if (highmem_pages + MAXMEM_PFN > max_pfn) { printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages)); highmem_pages = 0; } max_low_pfn = MAXMEM_PFN;#ifndef CONFIG_HIGHMEM /* Maximum memory usable is what is directly addressable */ printk(KERN_WARNING "Warning only %ldMB will be used.\n", MAXMEM>>20); if (max_pfn > MAX_NONPAE_PFN) printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n"); else printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n"); max_pfn = MAXMEM_PFN;#else /* !CONFIG_HIGHMEM */#ifndef CONFIG_HIGHMEM64G if (max_pfn > MAX_NONPAE_PFN) { max_pfn = MAX_NONPAE_PFN; printk(KERN_WARNING "Warning only 4GB will be used.\n"); printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n"); }#endif /* !CONFIG_HIGHMEM64G */#endif /* !CONFIG_HIGHMEM */ } else { if (highmem_pages == -1) highmem_pages = 0;#ifdef CONFIG_HIGHMEM if (highmem_pages >= max_pfn) { printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn)); highmem_pages = 0; } if (highmem_pages) { if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){ printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages)); highmem_pages = 0; } max_low_pfn -= highmem_pages; }#else if (highmem_pages) printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");#endif } return max_low_pfn;}/* * workaround for Dell systems that neglect to reserve EBDA */static void __init reserve_ebda_region(void){ unsigned int addr; addr = get_bios_ebda(); if (addr) reserve_bootmem(addr, PAGE_SIZE); }#ifndef CONFIG_NEED_MULTIPLE_NODESvoid __init setup_bootmem_allocator(void);static unsigned long __init setup_memory(void){ /* * partially used pages are not usable - thus * we are rounding upwards: */ min_low_pfn = PFN_UP(init_pg_tables_end); find_max_pfn(); max_low_pfn = find_max_low_pfn();#ifdef CONFIG_HIGHMEM highstart_pfn = highend_pfn = max_pfn; if (max_pfn > max_low_pfn) { highstart_pfn = max_low_pfn; } printk(KERN_NOTICE "%ldMB HIGHMEM available.\n", pages_to_mb(highend_pfn - highstart_pfn)); num_physpages = highend_pfn; high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;#else num_physpages = max_low_pfn; high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;#endif#ifdef CONFIG_FLATMEM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -