2 * linux/arch/i386/kernel/setup.c
4 * Copyright (C) 1995 Linus Torvalds
6 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
8 * Memory region support
9 * David Parsons <orc@pell.chi.il.us>, July-August 1999
11 * Added E820 sanitization routine (removes overlapping memory regions);
12 * Brian Moyle <bmoyle@mvista.com>, February 2001
14 * Moved CPU detection code to cpu/${cpu}.c
15 * Patrick Mochel <mochel@osdl.org>, March 2002
17 * Provisions for empty E820 memory regions (reported by certain BIOSes).
18 * Alex Achenbach <xela@slit.de>, December 2002.
23 * This file handles the architecture-dependent parts of initialization
26 #include <linux/sched.h>
28 #include <linux/mmzone.h>
29 #include <linux/screen_info.h>
30 #include <linux/ioport.h>
31 #include <linux/acpi.h>
32 #include <linux/apm_bios.h>
33 #include <linux/initrd.h>
34 #include <linux/bootmem.h>
35 #include <linux/seq_file.h>
36 #include <linux/platform_device.h>
37 #include <linux/console.h>
38 #include <linux/mca.h>
39 #include <linux/root_dev.h>
40 #include <linux/highmem.h>
41 #include <linux/module.h>
42 #include <linux/efi.h>
43 #include <linux/init.h>
44 #include <linux/edd.h>
45 #include <linux/nodemask.h>
46 #include <linux/kexec.h>
47 #include <linux/crash_dump.h>
48 #include <linux/dmi.h>
49 #include <linux/pfn.h>
51 #include <video/edid.h>
55 #include <asm/mpspec.h>
56 #include <asm/setup.h>
57 #include <asm/arch_hooks.h>
58 #include <asm/sections.h>
59 #include <asm/io_apic.h>
62 #include <setup_arch.h>
63 #include <bios_ebda.h>
65 /* Forward Declaration. */
66 void __init find_max_pfn(void);
68 /* This value is set up by the early boot code to point to the value
69 immediately after the boot time page tables. It contains a *physical*
70 address, and must not be in the .bss segment! */
71 unsigned long init_pg_tables_end __initdata = ~0UL;
73 int disable_pse __devinitdata = 0;
81 EXPORT_SYMBOL(efi_enabled);
84 /* cpu data as detected by the assembly code in head.S */
85 struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
86 /* common cpu data for all cpus */
87 struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
88 EXPORT_SYMBOL(boot_cpu_data);
90 unsigned long mmu_cr4_features;
92 /* for MCA, but anyone else can use it if they want */
93 unsigned int machine_id;
95 EXPORT_SYMBOL(machine_id);
97 unsigned int machine_submodel_id;
98 unsigned int BIOS_revision;
99 unsigned int mca_pentium_flag;
101 /* For PCI or other memory-mapped resources */
102 unsigned long pci_mem_start = 0x10000000;
104 EXPORT_SYMBOL(pci_mem_start);
107 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
110 /* user-defined highmem size */
111 static unsigned int highmem_pages = -1;
116 struct drive_info_struct { char dummy[32]; } drive_info;
117 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_HD) || \
118 defined(CONFIG_BLK_DEV_IDE_MODULE) || defined(CONFIG_BLK_DEV_HD_MODULE)
119 EXPORT_SYMBOL(drive_info);
121 struct screen_info screen_info;
122 EXPORT_SYMBOL(screen_info);
123 struct apm_info apm_info;
124 EXPORT_SYMBOL(apm_info);
125 struct sys_desc_table_struct {
126 unsigned short length;
127 unsigned char table[0];
129 struct edid_info edid_info;
130 EXPORT_SYMBOL_GPL(edid_info);
131 struct ist_info ist_info;
132 #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
133 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
134 EXPORT_SYMBOL(ist_info);
138 extern void early_cpu_init(void);
139 extern int root_mountflags;
141 unsigned long saved_videomode;
143 #define RAMDISK_IMAGE_START_MASK 0x07FF
144 #define RAMDISK_PROMPT_FLAG 0x8000
145 #define RAMDISK_LOAD_FLAG 0x4000
147 static char command_line[COMMAND_LINE_SIZE];
149 unsigned char __initdata boot_params[PARAM_SIZE];
151 static struct resource data_resource = {
152 .name = "Kernel data",
155 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
158 static struct resource code_resource = {
159 .name = "Kernel code",
162 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
165 static struct resource system_rom_resource = {
166 .name = "System ROM",
169 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
172 static struct resource extension_rom_resource = {
173 .name = "Extension ROM",
176 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
179 static struct resource adapter_rom_resources[] = { {
180 .name = "Adapter ROM",
183 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
185 .name = "Adapter ROM",
188 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
190 .name = "Adapter ROM",
193 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
195 .name = "Adapter ROM",
198 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
200 .name = "Adapter ROM",
203 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
205 .name = "Adapter ROM",
208 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
211 #define ADAPTER_ROM_RESOURCES \
212 (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
214 static struct resource video_rom_resource = {
218 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
221 static struct resource video_ram_resource = {
222 .name = "Video RAM area",
225 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
228 static struct resource standard_io_resources[] = { {
232 .flags = IORESOURCE_BUSY | IORESOURCE_IO
237 .flags = IORESOURCE_BUSY | IORESOURCE_IO
242 .flags = IORESOURCE_BUSY | IORESOURCE_IO
247 .flags = IORESOURCE_BUSY | IORESOURCE_IO
252 .flags = IORESOURCE_BUSY | IORESOURCE_IO
254 .name = "dma page reg",
257 .flags = IORESOURCE_BUSY | IORESOURCE_IO
262 .flags = IORESOURCE_BUSY | IORESOURCE_IO
267 .flags = IORESOURCE_BUSY | IORESOURCE_IO
272 .flags = IORESOURCE_BUSY | IORESOURCE_IO
275 #define STANDARD_IO_RESOURCES \
276 (sizeof standard_io_resources / sizeof standard_io_resources[0])
278 #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
280 static int __init romchecksum(unsigned char *rom, unsigned long length)
282 unsigned char *p, sum = 0;
284 for (p = rom; p < rom + length; p++)
289 static void __init probe_roms(void)
291 unsigned long start, length, upper;
296 upper = adapter_rom_resources[0].start;
297 for (start = video_rom_resource.start; start < upper; start += 2048) {
298 rom = isa_bus_to_virt(start);
299 if (!romsignature(rom))
302 video_rom_resource.start = start;
304 /* 0 < length <= 0x7f * 512, historically */
305 length = rom[2] * 512;
307 /* if checksum okay, trust length byte */
308 if (length && romchecksum(rom, length))
309 video_rom_resource.end = start + length - 1;
311 request_resource(&iomem_resource, &video_rom_resource);
315 start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
320 request_resource(&iomem_resource, &system_rom_resource);
321 upper = system_rom_resource.start;
323 /* check for extension rom (ignore length byte!) */
324 rom = isa_bus_to_virt(extension_rom_resource.start);
325 if (romsignature(rom)) {
326 length = extension_rom_resource.end - extension_rom_resource.start + 1;
327 if (romchecksum(rom, length)) {
328 request_resource(&iomem_resource, &extension_rom_resource);
329 upper = extension_rom_resource.start;
333 /* check for adapter roms on 2k boundaries */
334 for (i = 0; i < ADAPTER_ROM_RESOURCES && start < upper; start += 2048) {
335 rom = isa_bus_to_virt(start);
336 if (!romsignature(rom))
339 /* 0 < length <= 0x7f * 512, historically */
340 length = rom[2] * 512;
342 /* but accept any length that fits if checksum okay */
343 if (!length || start + length > upper || !romchecksum(rom, length))
346 adapter_rom_resources[i].start = start;
347 adapter_rom_resources[i].end = start + length - 1;
348 request_resource(&iomem_resource, &adapter_rom_resources[i]);
350 start = adapter_rom_resources[i++].end & ~2047UL;
354 static void __init limit_regions(unsigned long long size)
356 unsigned long long current_addr = 0;
360 efi_memory_desc_t *md;
363 for (p = memmap.map, i = 0; p < memmap.map_end;
364 p += memmap.desc_size, i++) {
366 current_addr = md->phys_addr + (md->num_pages << 12);
367 if (md->type == EFI_CONVENTIONAL_MEMORY) {
368 if (current_addr >= size) {
370 (((current_addr-size) + PAGE_SIZE-1) >> PAGE_SHIFT);
371 memmap.nr_map = i + 1;
377 for (i = 0; i < e820.nr_map; i++) {
378 current_addr = e820.map[i].addr + e820.map[i].size;
379 if (current_addr < size)
382 if (e820.map[i].type != E820_RAM)
385 if (e820.map[i].addr >= size) {
387 * This region starts past the end of the
388 * requested size, skip it completely.
393 e820.map[i].size -= current_addr - size;
399 void __init add_memory_region(unsigned long long start,
400 unsigned long long size, int type)
408 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
412 e820.map[x].addr = start;
413 e820.map[x].size = size;
414 e820.map[x].type = type;
417 } /* add_memory_region */
421 static void __init print_memory_map(char *who)
425 for (i = 0; i < e820.nr_map; i++) {
426 printk(" %s: %016Lx - %016Lx ", who,
428 e820.map[i].addr + e820.map[i].size);
429 switch (e820.map[i].type) {
430 case E820_RAM: printk("(usable)\n");
433 printk("(reserved)\n");
436 printk("(ACPI data)\n");
439 printk("(ACPI NVS)\n");
441 default: printk("type %lu\n", e820.map[i].type);
448 * Sanitize the BIOS e820 map.
450 * Some e820 responses include overlapping entries. The following
451 * replaces the original e820 map with a new one, removing overlaps.
454 struct change_member {
455 struct e820entry *pbios; /* pointer to original bios entry */
456 unsigned long long addr; /* address for this change point */
458 static struct change_member change_point_list[2*E820MAX] __initdata;
459 static struct change_member *change_point[2*E820MAX] __initdata;
460 static struct e820entry *overlap_list[E820MAX] __initdata;
461 static struct e820entry new_bios[E820MAX] __initdata;
463 int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
465 struct change_member *change_tmp;
466 unsigned long current_type, last_type;
467 unsigned long long last_addr;
468 int chgidx, still_changing;
471 int old_nr, new_nr, chg_nr;
475 Visually we're performing the following (1,2,3,4 = memory types)...
477 Sample memory map (w/overlaps):
478 ____22__________________
479 ______________________4_
480 ____1111________________
481 _44_____________________
482 11111111________________
483 ____________________33__
484 ___________44___________
485 __________33333_________
486 ______________22________
487 ___________________2222_
488 _________111111111______
489 _____________________11_
490 _________________4______
492 Sanitized equivalent (no overlap):
493 1_______________________
494 _44_____________________
495 ___1____________________
496 ____22__________________
497 ______11________________
498 _________1______________
499 __________3_____________
500 ___________44___________
501 _____________33_________
502 _______________2________
503 ________________1_______
504 _________________4______
505 ___________________2____
506 ____________________33__
507 ______________________4_
510 /* if there's only one memory region, don't bother */
516 /* bail out if we find any unreasonable addresses in bios map */
517 for (i=0; i<old_nr; i++)
518 if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
521 /* create pointers for initial change-point information (for sorting) */
522 for (i=0; i < 2*old_nr; i++)
523 change_point[i] = &change_point_list[i];
525 /* record all known change-points (starting and ending addresses),
526 omitting those that are for empty memory regions */
528 for (i=0; i < old_nr; i++) {
529 if (biosmap[i].size != 0) {
530 change_point[chgidx]->addr = biosmap[i].addr;
531 change_point[chgidx++]->pbios = &biosmap[i];
532 change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
533 change_point[chgidx++]->pbios = &biosmap[i];
536 chg_nr = chgidx; /* true number of change-points */
538 /* sort change-point list by memory addresses (low -> high) */
540 while (still_changing) {
542 for (i=1; i < chg_nr; i++) {
543 /* if <current_addr> > <last_addr>, swap */
544 /* or, if current=<start_addr> & last=<end_addr>, swap */
545 if ((change_point[i]->addr < change_point[i-1]->addr) ||
546 ((change_point[i]->addr == change_point[i-1]->addr) &&
547 (change_point[i]->addr == change_point[i]->pbios->addr) &&
548 (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
551 change_tmp = change_point[i];
552 change_point[i] = change_point[i-1];
553 change_point[i-1] = change_tmp;
559 /* create a new bios memory map, removing overlaps */
560 overlap_entries=0; /* number of entries in the overlap table */
561 new_bios_entry=0; /* index for creating new bios map entries */
562 last_type = 0; /* start with undefined memory type */
563 last_addr = 0; /* start with 0 as last starting address */
564 /* loop through change-points, determining affect on the new bios map */
565 for (chgidx=0; chgidx < chg_nr; chgidx++)
567 /* keep track of all overlapping bios entries */
568 if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
570 /* add map entry to overlap list (> 1 entry implies an overlap) */
571 overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
575 /* remove entry from list (order independent, so swap with last) */
576 for (i=0; i<overlap_entries; i++)
578 if (overlap_list[i] == change_point[chgidx]->pbios)
579 overlap_list[i] = overlap_list[overlap_entries-1];
583 /* if there are overlapping entries, decide which "type" to use */
584 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
586 for (i=0; i<overlap_entries; i++)
587 if (overlap_list[i]->type > current_type)
588 current_type = overlap_list[i]->type;
589 /* continue building up new bios map based on this information */
590 if (current_type != last_type) {
591 if (last_type != 0) {
592 new_bios[new_bios_entry].size =
593 change_point[chgidx]->addr - last_addr;
594 /* move forward only if the new size was non-zero */
595 if (new_bios[new_bios_entry].size != 0)
596 if (++new_bios_entry >= E820MAX)
597 break; /* no more space left for new bios entries */
599 if (current_type != 0) {
600 new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
601 new_bios[new_bios_entry].type = current_type;
602 last_addr=change_point[chgidx]->addr;
604 last_type = current_type;
607 new_nr = new_bios_entry; /* retain count for new bios entries */
609 /* copy new bios mapping into original location */
610 memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
617 * Copy the BIOS e820 map into a safe place.
619 * Sanity-check it while we're at it..
621 * If we're lucky and live on a modern system, the setup code
622 * will have given us a memory map that we can use to properly
623 * set up memory. If we aren't, we'll fake a memory map.
625 * We check to see that the memory map contains at least 2 elements
626 * before we'll use it, because the detection code in setup.S may
627 * not be perfect and most every PC known to man has two memory
628 * regions: one from 0 to 640k, and one from 1mb up. (The IBM
629 * thinkpad 560x, for example, does not cooperate with the memory
632 int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
634 /* Only one memory region (or negative)? Ignore it */
639 unsigned long long start = biosmap->addr;
640 unsigned long long size = biosmap->size;
641 unsigned long long end = start + size;
642 unsigned long type = biosmap->type;
644 /* Overflow in 64 bits? Ignore the memory map. */
649 * Some BIOSes claim RAM in the 640k - 1M region.
650 * Not right. Fix it up.
652 if (type == E820_RAM) {
653 if (start < 0x100000ULL && end > 0xA0000ULL) {
654 if (start < 0xA0000ULL)
655 add_memory_region(start, 0xA0000ULL-start, type);
656 if (end <= 0x100000ULL)
662 add_memory_region(start, size, type);
663 } while (biosmap++,--nr_map);
667 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
669 #ifdef CONFIG_EDD_MODULE
673 * copy_edd() - Copy the BIOS EDD information
674 * from boot_params into a safe place.
677 static inline void copy_edd(void)
679 memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
680 memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
681 edd.mbr_signature_nr = EDD_MBR_SIG_NR;
682 edd.edd_info_nr = EDD_NR;
685 static inline void copy_edd(void)
690 static int __initdata user_defined_memmap = 0;
693 * "mem=nopentium" disables the 4MB page tables.
694 * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
695 * to <mem>, overriding the bios size.
696 * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
697 * <start> to <start>+<mem>, overriding the bios size.
699 * HPA tells me bootloaders need to parse mem=, so no new
700 * option should be mem= [also see Documentation/i386/boot.txt]
702 static int __init parse_mem(char *arg)
707 if (strcmp(arg, "nopentium") == 0) {
708 clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
711 /* If the user specifies memory size, we
712 * limit the BIOS-provided memory map to
713 * that size. exactmap can be used to specify
714 * the exact map. mem=number can be used to
715 * trim the existing memory map.
717 unsigned long long mem_size;
719 mem_size = memparse(arg, &arg);
720 limit_regions(mem_size);
721 user_defined_memmap = 1;
725 early_param("mem", parse_mem);
727 static int __init parse_memmap(char *arg)
732 if (strcmp(arg, "exactmap") == 0) {
733 #ifdef CONFIG_CRASH_DUMP
734 /* If we are doing a crash dump, we
735 * still need to know the real mem
736 * size before original memory map is
740 saved_max_pfn = max_pfn;
743 user_defined_memmap = 1;
745 /* If the user specifies memory size, we
746 * limit the BIOS-provided memory map to
747 * that size. exactmap can be used to specify
748 * the exact map. mem=number can be used to
749 * trim the existing memory map.
751 unsigned long long start_at, mem_size;
753 mem_size = memparse(arg, &arg);
755 start_at = memparse(arg+1, &arg);
756 add_memory_region(start_at, mem_size, E820_RAM);
757 } else if (*arg == '#') {
758 start_at = memparse(arg+1, &arg);
759 add_memory_region(start_at, mem_size, E820_ACPI);
760 } else if (*arg == '$') {
761 start_at = memparse(arg+1, &arg);
762 add_memory_region(start_at, mem_size, E820_RESERVED);
764 limit_regions(mem_size);
765 user_defined_memmap = 1;
770 early_param("memmap", parse_memmap);
772 #ifdef CONFIG_PROC_VMCORE
773 /* elfcorehdr= specifies the location of elf core header
774 * stored by the crashed kernel.
776 static int __init parse_elfcorehdr(char *arg)
781 elfcorehdr_addr = memparse(arg, &arg);
784 early_param("elfcorehdr", parse_elfcorehdr);
785 #endif /* CONFIG_PROC_VMCORE */
788 * highmem=size forces highmem to be exactly 'size' bytes.
789 * This works even on boxes that have no highmem otherwise.
790 * This also works to reduce highmem size on bigger boxes.
792 static int __init parse_highmem(char *arg)
797 highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
800 early_param("highmem", parse_highmem);
803 * vmalloc=size forces the vmalloc area to be exactly 'size'
804 * bytes. This can be used to increase (or decrease) the
805 * vmalloc area - the default is 128m.
807 static int __init parse_vmalloc(char *arg)
812 __VMALLOC_RESERVE = memparse(arg, &arg);
815 early_param("vmalloc", parse_vmalloc);
818 * Callback for efi_memory_walk.
821 efi_find_max_pfn(unsigned long start, unsigned long end, void *arg)
823 unsigned long *max_pfn = arg, pfn;
826 pfn = PFN_UP(end -1);
834 efi_memory_present_wrapper(unsigned long start, unsigned long end, void *arg)
836 memory_present(0, start, end);
841 * This function checks if the entire range <start,end> is mapped with type.
843 * Note: this function only works correct if the e820 table is sorted and
844 * not-overlapping, which is the case
847 e820_all_mapped(unsigned long s, unsigned long e, unsigned type)
852 for (i = 0; i < e820.nr_map; i++) {
853 struct e820entry *ei = &e820.map[i];
854 if (type && ei->type != type)
856 /* is the region (part) in overlap with the current region ?*/
857 if (ei->addr >= end || ei->addr + ei->size <= start)
859 /* if the region is at the beginning of <start,end> we move
860 * start to the end of the region since it's ok until there
862 if (ei->addr <= start)
863 start = ei->addr + ei->size;
864 /* if start is now at or beyond end, we're done, full
867 return 1; /* we're done */
873 * Find the highest page frame number we have available
875 void __init find_max_pfn(void)
881 efi_memmap_walk(efi_find_max_pfn, &max_pfn);
882 efi_memmap_walk(efi_memory_present_wrapper, NULL);
886 for (i = 0; i < e820.nr_map; i++) {
887 unsigned long start, end;
889 if (e820.map[i].type != E820_RAM)
891 start = PFN_UP(e820.map[i].addr);
892 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
897 memory_present(0, start, end);
902 * Determine low and high memory ranges:
904 unsigned long __init find_max_low_pfn(void)
906 unsigned long max_low_pfn;
908 max_low_pfn = max_pfn;
909 if (max_low_pfn > MAXMEM_PFN) {
910 if (highmem_pages == -1)
911 highmem_pages = max_pfn - MAXMEM_PFN;
912 if (highmem_pages + MAXMEM_PFN < max_pfn)
913 max_pfn = MAXMEM_PFN + highmem_pages;
914 if (highmem_pages + MAXMEM_PFN > max_pfn) {
915 printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
918 max_low_pfn = MAXMEM_PFN;
919 #ifndef CONFIG_HIGHMEM
920 /* Maximum memory usable is what is directly addressable */
921 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
923 if (max_pfn > MAX_NONPAE_PFN)
924 printk(KERN_WARNING "Use a PAE enabled kernel.\n");
926 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
927 max_pfn = MAXMEM_PFN;
928 #else /* !CONFIG_HIGHMEM */
929 #ifndef CONFIG_X86_PAE
930 if (max_pfn > MAX_NONPAE_PFN) {
931 max_pfn = MAX_NONPAE_PFN;
932 printk(KERN_WARNING "Warning only 4GB will be used.\n");
933 printk(KERN_WARNING "Use a PAE enabled kernel.\n");
935 #endif /* !CONFIG_X86_PAE */
936 #endif /* !CONFIG_HIGHMEM */
938 if (highmem_pages == -1)
940 #ifdef CONFIG_HIGHMEM
941 if (highmem_pages >= max_pfn) {
942 printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
946 if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
947 printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
950 max_low_pfn -= highmem_pages;
954 printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
961 * Free all available memory for boot time allocation. Used
962 * as a callback function by efi_memory_walk()
966 free_available_memory(unsigned long start, unsigned long end, void *arg)
968 /* check max_low_pfn */
969 if (start >= (max_low_pfn << PAGE_SHIFT))
971 if (end >= (max_low_pfn << PAGE_SHIFT))
972 end = max_low_pfn << PAGE_SHIFT;
974 free_bootmem(start, end - start);
979 * Register fully available low RAM pages with the bootmem allocator.
981 static void __init register_bootmem_low_pages(unsigned long max_low_pfn)
986 efi_memmap_walk(free_available_memory, NULL);
989 for (i = 0; i < e820.nr_map; i++) {
990 unsigned long curr_pfn, last_pfn, size;
992 * Reserve usable low memory
994 if (e820.map[i].type != E820_RAM)
997 * We are rounding up the start address of usable memory:
999 curr_pfn = PFN_UP(e820.map[i].addr);
1000 if (curr_pfn >= max_low_pfn)
1003 * ... and at the end of the usable range downwards:
1005 last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
1007 if (last_pfn > max_low_pfn)
1008 last_pfn = max_low_pfn;
1011 * .. finally, did all the rounding and playing
1012 * around just make the area go away?
1014 if (last_pfn <= curr_pfn)
1017 size = last_pfn - curr_pfn;
1018 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
1023 * workaround for Dell systems that neglect to reserve EBDA
1025 static void __init reserve_ebda_region(void)
1028 addr = get_bios_ebda();
1030 reserve_bootmem(addr, PAGE_SIZE);
1033 #ifndef CONFIG_NEED_MULTIPLE_NODES
1034 void __init setup_bootmem_allocator(void);
1035 static unsigned long __init setup_memory(void)
1038 * partially used pages are not usable - thus
1039 * we are rounding upwards:
1041 min_low_pfn = PFN_UP(init_pg_tables_end);
1045 max_low_pfn = find_max_low_pfn();
1047 #ifdef CONFIG_HIGHMEM
1048 highstart_pfn = highend_pfn = max_pfn;
1049 if (max_pfn > max_low_pfn) {
1050 highstart_pfn = max_low_pfn;
1052 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
1053 pages_to_mb(highend_pfn - highstart_pfn));
1054 num_physpages = highend_pfn;
1055 high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
1057 num_physpages = max_low_pfn;
1058 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
1060 #ifdef CONFIG_FLATMEM
1061 max_mapnr = num_physpages;
1063 printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
1064 pages_to_mb(max_low_pfn));
1066 setup_bootmem_allocator();
1071 void __init zone_sizes_init(void)
1073 unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
1074 unsigned int max_dma, low;
1076 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
1080 zones_size[ZONE_DMA] = low;
1082 zones_size[ZONE_DMA] = max_dma;
1083 zones_size[ZONE_NORMAL] = low - max_dma;
1084 #ifdef CONFIG_HIGHMEM
1085 zones_size[ZONE_HIGHMEM] = highend_pfn - low;
1088 free_area_init(zones_size);
1091 extern unsigned long __init setup_memory(void);
1092 extern void zone_sizes_init(void);
1093 #endif /* !CONFIG_NEED_MULTIPLE_NODES */
1095 void __init setup_bootmem_allocator(void)
1097 unsigned long bootmap_size;
1099 * Initialize the boot-time allocator (with low memory only):
1101 bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
1103 register_bootmem_low_pages(max_low_pfn);
1106 * Reserve the bootmem bitmap itself as well. We do this in two
1107 * steps (first step was init_bootmem()) because this catches
1108 * the (very unlikely) case of us accidentally initializing the
1109 * bootmem allocator with an invalid RAM area.
1111 reserve_bootmem(__PHYSICAL_START, (PFN_PHYS(min_low_pfn) +
1112 bootmap_size + PAGE_SIZE-1) - (__PHYSICAL_START));
1115 * reserve physical page 0 - it's a special BIOS page on many boxes,
1116 * enabling clean reboots, SMP operation, laptop functions.
1118 reserve_bootmem(0, PAGE_SIZE);
1120 /* reserve EBDA region, it's a 4K region */
1121 reserve_ebda_region();
1123 /* could be an AMD 768MPX chipset. Reserve a page before VGA to prevent
1124 PCI prefetch into it (errata #56). Usually the page is reserved anyways,
1125 unless you have no PS/2 mouse plugged in. */
1126 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
1127 boot_cpu_data.x86 == 6)
1128 reserve_bootmem(0xa0000 - 4096, 4096);
1132 * But first pinch a few for the stack/trampoline stuff
1133 * FIXME: Don't need the extra page at 4K, but need to fix
1134 * trampoline before removing it. (see the GDT stuff)
1136 reserve_bootmem(PAGE_SIZE, PAGE_SIZE);
1138 #ifdef CONFIG_ACPI_SLEEP
1140 * Reserve low memory region for sleep support.
1142 acpi_reserve_bootmem();
1144 #ifdef CONFIG_X86_FIND_SMP_CONFIG
1146 * Find and reserve possible boot-time SMP configuration:
1151 #ifdef CONFIG_BLK_DEV_INITRD
1152 if (LOADER_TYPE && INITRD_START) {
1153 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
1154 reserve_bootmem(INITRD_START, INITRD_SIZE);
1156 INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
1157 initrd_end = initrd_start+INITRD_SIZE;
1160 printk(KERN_ERR "initrd extends beyond end of memory "
1161 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
1162 INITRD_START + INITRD_SIZE,
1163 max_low_pfn << PAGE_SHIFT);
1169 if (crashk_res.start != crashk_res.end)
1170 reserve_bootmem(crashk_res.start,
1171 crashk_res.end - crashk_res.start + 1);
1176 * The node 0 pgdat is initialized before all of these because
1177 * it's needed for bootmem. node>0 pgdats have their virtual
1178 * space allocated before the pagetables are in place to access
1179 * them, so they can't be cleared then.
1181 * This should all compile down to nothing when NUMA is off.
1183 void __init remapped_pgdat_init(void)
1187 for_each_online_node(nid) {
1189 memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
1194 * Request address space for all standard RAM and ROM resources
1195 * and also for regions reported as reserved by the e820.
1198 legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
1203 for (i = 0; i < e820.nr_map; i++) {
1204 struct resource *res;
1205 #ifndef CONFIG_RESOURCES_64BIT
1206 if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
1209 res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
1210 switch (e820.map[i].type) {
1211 case E820_RAM: res->name = "System RAM"; break;
1212 case E820_ACPI: res->name = "ACPI Tables"; break;
1213 case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
1214 default: res->name = "reserved";
1216 res->start = e820.map[i].addr;
1217 res->end = res->start + e820.map[i].size - 1;
1218 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
1219 if (request_resource(&iomem_resource, res)) {
1223 if (e820.map[i].type == E820_RAM) {
1225 * We don't know which RAM region contains kernel data,
1226 * so we try it repeatedly and let the resource manager
1229 request_resource(res, code_resource);
1230 request_resource(res, data_resource);
1232 request_resource(res, &crashk_res);
1239 * Request address space for all standard resources
1241 * This is called just before pcibios_init(), which is also a
1242 * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
1244 static int __init request_standard_resources(void)
1248 printk("Setting up standard PCI resources\n");
1250 efi_initialize_iomem_resources(&code_resource, &data_resource);
1252 legacy_init_iomem_resources(&code_resource, &data_resource);
1254 /* EFI systems may still have VGA */
1255 request_resource(&iomem_resource, &video_ram_resource);
1257 /* request I/O space for devices used on all i[345]86 PCs */
1258 for (i = 0; i < STANDARD_IO_RESOURCES; i++)
1259 request_resource(&ioport_resource, &standard_io_resources[i]);
1263 subsys_initcall(request_standard_resources);
1265 static void __init register_memory(void)
1267 unsigned long gapstart, gapsize, round;
1268 unsigned long long last;
1272 * Search for the bigest gap in the low 32 bits of the e820
1275 last = 0x100000000ull;
1276 gapstart = 0x10000000;
1280 unsigned long long start = e820.map[i].addr;
1281 unsigned long long end = start + e820.map[i].size;
1284 * Since "last" is at most 4GB, we know we'll
1285 * fit in 32 bits if this condition is true
1288 unsigned long gap = last - end;
1290 if (gap > gapsize) {
1300 * See how much we want to round up: start off with
1301 * rounding to the next 1MB area.
1304 while ((gapsize >> 4) > round)
1306 /* Fun with two's complement */
1307 pci_mem_start = (gapstart + round) & -round;
1309 printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
1310 pci_mem_start, gapstart, gapsize);
1314 static void set_mca_bus(int x)
1319 static void set_mca_bus(int x) { }
1323 * Determine if we were loaded by an EFI loader. If so, then we have also been
1324 * passed the efi memmap, systab, etc., so we should use these data structures
1325 * for initialization. Note, the efi init code path is determined by the
1326 * global efi_enabled. This allows the same kernel image to be used on existing
1327 * systems (with a traditional BIOS) as well as on EFI systems.
1329 void __init setup_arch(char **cmdline_p)
1331 unsigned long max_low_pfn;
1333 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
1334 pre_setup_arch_hook();
1338 * FIXME: This isn't an official loader_type right
1339 * now but does currently work with elilo.
1340 * If we were configured as an EFI kernel, check to make
1341 * sure that we were loaded correctly from elilo and that
1342 * the system table is valid. If not, then initialize normally.
1345 if ((LOADER_TYPE == 0x50) && EFI_SYSTAB)
1349 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
1350 drive_info = DRIVE_INFO;
1351 screen_info = SCREEN_INFO;
1352 edid_info = EDID_INFO;
1353 apm_info.bios = APM_BIOS_INFO;
1354 ist_info = IST_INFO;
1355 saved_videomode = VIDEO_MODE;
1356 if( SYS_DESC_TABLE.length != 0 ) {
1357 set_mca_bus(SYS_DESC_TABLE.table[3] & 0x2);
1358 machine_id = SYS_DESC_TABLE.table[0];
1359 machine_submodel_id = SYS_DESC_TABLE.table[1];
1360 BIOS_revision = SYS_DESC_TABLE.table[2];
1362 bootloader_type = LOADER_TYPE;
1364 #ifdef CONFIG_BLK_DEV_RAM
1365 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
1366 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
1367 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
1373 printk(KERN_INFO "BIOS-provided physical RAM map:\n");
1374 print_memory_map(machine_specific_memory_setup());
1379 if (!MOUNT_ROOT_RDONLY)
1380 root_mountflags &= ~MS_RDONLY;
1381 init_mm.start_code = (unsigned long) _text;
1382 init_mm.end_code = (unsigned long) _etext;
1383 init_mm.end_data = (unsigned long) _edata;
1384 init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
1386 code_resource.start = virt_to_phys(_text);
1387 code_resource.end = virt_to_phys(_etext)-1;
1388 data_resource.start = virt_to_phys(_etext);
1389 data_resource.end = virt_to_phys(_edata)-1;
1391 parse_early_param();
1393 if (user_defined_memmap) {
1394 printk(KERN_INFO "user-defined physical RAM map:\n");
1395 print_memory_map("user");
1398 strlcpy(command_line, saved_command_line, COMMAND_LINE_SIZE);
1399 *cmdline_p = command_line;
1401 max_low_pfn = setup_memory();
1404 * NOTE: before this point _nobody_ is allowed to allocate
1405 * any memory using the bootmem allocator. Although the
1406 * alloctor is now initialised only the first 8Mb of the kernel
1407 * virtual address space has been mapped. All allocations before
1408 * paging_init() has completed must use the alloc_bootmem_low_pages()
1409 * variant (which allocates DMA'able memory) and care must be taken
1410 * not to exceed the 8Mb limit.
1414 smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
1417 remapped_pgdat_init();
1422 * NOTE: at this point the bootmem allocator is fully available.
1427 #ifdef CONFIG_X86_GENERICARCH
1428 generic_apic_probe();
1435 * Parse the ACPI tables for possible boot-time SMP configuration.
1437 acpi_boot_table_init();
1441 #ifdef CONFIG_X86_IO_APIC
1442 check_acpi_pci(); /* Checks more than just ACPI actually */
1449 #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
1451 printk(KERN_WARNING "More than 8 CPUs detected and "
1452 "CONFIG_X86_PC cannot handle it.\nUse "
1453 "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
1456 #ifdef CONFIG_X86_LOCAL_APIC
1457 if (smp_found_config)
1464 #if defined(CONFIG_VGA_CONSOLE)
1465 if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
1466 conswitchp = &vga_con;
1467 #elif defined(CONFIG_DUMMY_CONSOLE)
1468 conswitchp = &dummy_con;
1474 static __init int add_pcspkr(void)
1476 struct platform_device *pd;
1479 pd = platform_device_alloc("pcspkr", -1);
1483 ret = platform_device_add(pd);
1485 platform_device_put(pd);
1489 device_initcall(add_pcspkr);
1494 * c-file-style:"k&r"