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/mmzone.h>
57 #include <asm/setup.h>
58 #include <asm/arch_hooks.h>
59 #include <asm/sections.h>
60 #include <asm/io_apic.h>
63 #include <setup_arch.h>
64 #include <bios_ebda.h>
66 /* Forward Declaration. */
67 void __init find_max_pfn(void);
69 /* This value is set up by the early boot code to point to the value
70 immediately after the boot time page tables. It contains a *physical*
71 address, and must not be in the .bss segment! */
72 unsigned long init_pg_tables_end __initdata = ~0UL;
74 int disable_pse __devinitdata = 0;
79 extern struct e820map e820;
80 extern struct resource code_resource;
81 extern struct resource data_resource;
83 /* cpu data as detected by the assembly code in head.S */
84 struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
85 /* common cpu data for all cpus */
86 struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
87 EXPORT_SYMBOL(boot_cpu_data);
89 unsigned long mmu_cr4_features;
91 /* for MCA, but anyone else can use it if they want */
92 unsigned int machine_id;
94 EXPORT_SYMBOL(machine_id);
96 unsigned int machine_submodel_id;
97 unsigned int BIOS_revision;
98 unsigned int mca_pentium_flag;
100 /* For PCI or other memory-mapped resources */
101 unsigned long pci_mem_start = 0x10000000;
103 EXPORT_SYMBOL(pci_mem_start);
106 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
109 /* user-defined highmem size */
110 static unsigned int highmem_pages = -1;
115 struct drive_info_struct { char dummy[32]; } drive_info;
116 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_HD) || \
117 defined(CONFIG_BLK_DEV_IDE_MODULE) || defined(CONFIG_BLK_DEV_HD_MODULE)
118 EXPORT_SYMBOL(drive_info);
120 struct screen_info screen_info;
121 EXPORT_SYMBOL(screen_info);
122 struct apm_info apm_info;
123 EXPORT_SYMBOL(apm_info);
124 struct sys_desc_table_struct {
125 unsigned short length;
126 unsigned char table[0];
128 struct edid_info edid_info;
129 EXPORT_SYMBOL_GPL(edid_info);
130 struct ist_info ist_info;
131 #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
132 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
133 EXPORT_SYMBOL(ist_info);
136 extern void early_cpu_init(void);
137 extern int root_mountflags;
139 unsigned long saved_videomode;
141 #define RAMDISK_IMAGE_START_MASK 0x07FF
142 #define RAMDISK_PROMPT_FLAG 0x8000
143 #define RAMDISK_LOAD_FLAG 0x4000
145 static char command_line[COMMAND_LINE_SIZE];
147 unsigned char __initdata boot_params[PARAM_SIZE];
149 static void __init limit_regions(unsigned long long size)
151 unsigned long long current_addr = 0;
155 efi_memory_desc_t *md;
158 for (p = memmap.map, i = 0; p < memmap.map_end;
159 p += memmap.desc_size, i++) {
161 current_addr = md->phys_addr + (md->num_pages << 12);
162 if (md->type == EFI_CONVENTIONAL_MEMORY) {
163 if (current_addr >= size) {
165 (((current_addr-size) + PAGE_SIZE-1) >> PAGE_SHIFT);
166 memmap.nr_map = i + 1;
172 for (i = 0; i < e820.nr_map; i++) {
173 current_addr = e820.map[i].addr + e820.map[i].size;
174 if (current_addr < size)
177 if (e820.map[i].type != E820_RAM)
180 if (e820.map[i].addr >= size) {
182 * This region starts past the end of the
183 * requested size, skip it completely.
188 e820.map[i].size -= current_addr - size;
194 void __init add_memory_region(unsigned long long start,
195 unsigned long long size, int type)
203 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
207 e820.map[x].addr = start;
208 e820.map[x].size = size;
209 e820.map[x].type = type;
212 } /* add_memory_region */
216 static void __init print_memory_map(char *who)
220 for (i = 0; i < e820.nr_map; i++) {
221 printk(" %s: %016Lx - %016Lx ", who,
223 e820.map[i].addr + e820.map[i].size);
224 switch (e820.map[i].type) {
225 case E820_RAM: printk("(usable)\n");
228 printk("(reserved)\n");
231 printk("(ACPI data)\n");
234 printk("(ACPI NVS)\n");
236 default: printk("type %lu\n", e820.map[i].type);
243 * Sanitize the BIOS e820 map.
245 * Some e820 responses include overlapping entries. The following
246 * replaces the original e820 map with a new one, removing overlaps.
249 struct change_member {
250 struct e820entry *pbios; /* pointer to original bios entry */
251 unsigned long long addr; /* address for this change point */
253 static struct change_member change_point_list[2*E820MAX] __initdata;
254 static struct change_member *change_point[2*E820MAX] __initdata;
255 static struct e820entry *overlap_list[E820MAX] __initdata;
256 static struct e820entry new_bios[E820MAX] __initdata;
258 int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
260 struct change_member *change_tmp;
261 unsigned long current_type, last_type;
262 unsigned long long last_addr;
263 int chgidx, still_changing;
266 int old_nr, new_nr, chg_nr;
270 Visually we're performing the following (1,2,3,4 = memory types)...
272 Sample memory map (w/overlaps):
273 ____22__________________
274 ______________________4_
275 ____1111________________
276 _44_____________________
277 11111111________________
278 ____________________33__
279 ___________44___________
280 __________33333_________
281 ______________22________
282 ___________________2222_
283 _________111111111______
284 _____________________11_
285 _________________4______
287 Sanitized equivalent (no overlap):
288 1_______________________
289 _44_____________________
290 ___1____________________
291 ____22__________________
292 ______11________________
293 _________1______________
294 __________3_____________
295 ___________44___________
296 _____________33_________
297 _______________2________
298 ________________1_______
299 _________________4______
300 ___________________2____
301 ____________________33__
302 ______________________4_
305 /* if there's only one memory region, don't bother */
311 /* bail out if we find any unreasonable addresses in bios map */
312 for (i=0; i<old_nr; i++)
313 if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
316 /* create pointers for initial change-point information (for sorting) */
317 for (i=0; i < 2*old_nr; i++)
318 change_point[i] = &change_point_list[i];
320 /* record all known change-points (starting and ending addresses),
321 omitting those that are for empty memory regions */
323 for (i=0; i < old_nr; i++) {
324 if (biosmap[i].size != 0) {
325 change_point[chgidx]->addr = biosmap[i].addr;
326 change_point[chgidx++]->pbios = &biosmap[i];
327 change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
328 change_point[chgidx++]->pbios = &biosmap[i];
331 chg_nr = chgidx; /* true number of change-points */
333 /* sort change-point list by memory addresses (low -> high) */
335 while (still_changing) {
337 for (i=1; i < chg_nr; i++) {
338 /* if <current_addr> > <last_addr>, swap */
339 /* or, if current=<start_addr> & last=<end_addr>, swap */
340 if ((change_point[i]->addr < change_point[i-1]->addr) ||
341 ((change_point[i]->addr == change_point[i-1]->addr) &&
342 (change_point[i]->addr == change_point[i]->pbios->addr) &&
343 (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
346 change_tmp = change_point[i];
347 change_point[i] = change_point[i-1];
348 change_point[i-1] = change_tmp;
354 /* create a new bios memory map, removing overlaps */
355 overlap_entries=0; /* number of entries in the overlap table */
356 new_bios_entry=0; /* index for creating new bios map entries */
357 last_type = 0; /* start with undefined memory type */
358 last_addr = 0; /* start with 0 as last starting address */
359 /* loop through change-points, determining affect on the new bios map */
360 for (chgidx=0; chgidx < chg_nr; chgidx++)
362 /* keep track of all overlapping bios entries */
363 if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
365 /* add map entry to overlap list (> 1 entry implies an overlap) */
366 overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
370 /* remove entry from list (order independent, so swap with last) */
371 for (i=0; i<overlap_entries; i++)
373 if (overlap_list[i] == change_point[chgidx]->pbios)
374 overlap_list[i] = overlap_list[overlap_entries-1];
378 /* if there are overlapping entries, decide which "type" to use */
379 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
381 for (i=0; i<overlap_entries; i++)
382 if (overlap_list[i]->type > current_type)
383 current_type = overlap_list[i]->type;
384 /* continue building up new bios map based on this information */
385 if (current_type != last_type) {
386 if (last_type != 0) {
387 new_bios[new_bios_entry].size =
388 change_point[chgidx]->addr - last_addr;
389 /* move forward only if the new size was non-zero */
390 if (new_bios[new_bios_entry].size != 0)
391 if (++new_bios_entry >= E820MAX)
392 break; /* no more space left for new bios entries */
394 if (current_type != 0) {
395 new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
396 new_bios[new_bios_entry].type = current_type;
397 last_addr=change_point[chgidx]->addr;
399 last_type = current_type;
402 new_nr = new_bios_entry; /* retain count for new bios entries */
404 /* copy new bios mapping into original location */
405 memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
412 * Copy the BIOS e820 map into a safe place.
414 * Sanity-check it while we're at it..
416 * If we're lucky and live on a modern system, the setup code
417 * will have given us a memory map that we can use to properly
418 * set up memory. If we aren't, we'll fake a memory map.
420 * We check to see that the memory map contains at least 2 elements
421 * before we'll use it, because the detection code in setup.S may
422 * not be perfect and most every PC known to man has two memory
423 * regions: one from 0 to 640k, and one from 1mb up. (The IBM
424 * thinkpad 560x, for example, does not cooperate with the memory
427 int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
429 /* Only one memory region (or negative)? Ignore it */
434 unsigned long long start = biosmap->addr;
435 unsigned long long size = biosmap->size;
436 unsigned long long end = start + size;
437 unsigned long type = biosmap->type;
439 /* Overflow in 64 bits? Ignore the memory map. */
444 * Some BIOSes claim RAM in the 640k - 1M region.
445 * Not right. Fix it up.
447 if (type == E820_RAM) {
448 if (start < 0x100000ULL && end > 0xA0000ULL) {
449 if (start < 0xA0000ULL)
450 add_memory_region(start, 0xA0000ULL-start, type);
451 if (end <= 0x100000ULL)
457 add_memory_region(start, size, type);
458 } while (biosmap++,--nr_map);
462 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
464 #ifdef CONFIG_EDD_MODULE
468 * copy_edd() - Copy the BIOS EDD information
469 * from boot_params into a safe place.
472 static inline void copy_edd(void)
474 memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
475 memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
476 edd.mbr_signature_nr = EDD_MBR_SIG_NR;
477 edd.edd_info_nr = EDD_NR;
480 static inline void copy_edd(void)
485 static int __initdata user_defined_memmap = 0;
488 * "mem=nopentium" disables the 4MB page tables.
489 * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
490 * to <mem>, overriding the bios size.
491 * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
492 * <start> to <start>+<mem>, overriding the bios size.
494 * HPA tells me bootloaders need to parse mem=, so no new
495 * option should be mem= [also see Documentation/i386/boot.txt]
497 static int __init parse_mem(char *arg)
502 if (strcmp(arg, "nopentium") == 0) {
503 clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
506 /* If the user specifies memory size, we
507 * limit the BIOS-provided memory map to
508 * that size. exactmap can be used to specify
509 * the exact map. mem=number can be used to
510 * trim the existing memory map.
512 unsigned long long mem_size;
514 mem_size = memparse(arg, &arg);
515 limit_regions(mem_size);
516 user_defined_memmap = 1;
520 early_param("mem", parse_mem);
522 static int __init parse_memmap(char *arg)
527 if (strcmp(arg, "exactmap") == 0) {
528 #ifdef CONFIG_CRASH_DUMP
529 /* If we are doing a crash dump, we
530 * still need to know the real mem
531 * size before original memory map is
535 saved_max_pfn = max_pfn;
538 user_defined_memmap = 1;
540 /* If the user specifies memory size, we
541 * limit the BIOS-provided memory map to
542 * that size. exactmap can be used to specify
543 * the exact map. mem=number can be used to
544 * trim the existing memory map.
546 unsigned long long start_at, mem_size;
548 mem_size = memparse(arg, &arg);
550 start_at = memparse(arg+1, &arg);
551 add_memory_region(start_at, mem_size, E820_RAM);
552 } else if (*arg == '#') {
553 start_at = memparse(arg+1, &arg);
554 add_memory_region(start_at, mem_size, E820_ACPI);
555 } else if (*arg == '$') {
556 start_at = memparse(arg+1, &arg);
557 add_memory_region(start_at, mem_size, E820_RESERVED);
559 limit_regions(mem_size);
560 user_defined_memmap = 1;
565 early_param("memmap", parse_memmap);
567 #ifdef CONFIG_PROC_VMCORE
568 /* elfcorehdr= specifies the location of elf core header
569 * stored by the crashed kernel.
571 static int __init parse_elfcorehdr(char *arg)
576 elfcorehdr_addr = memparse(arg, &arg);
579 early_param("elfcorehdr", parse_elfcorehdr);
580 #endif /* CONFIG_PROC_VMCORE */
583 * highmem=size forces highmem to be exactly 'size' bytes.
584 * This works even on boxes that have no highmem otherwise.
585 * This also works to reduce highmem size on bigger boxes.
587 static int __init parse_highmem(char *arg)
592 highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
595 early_param("highmem", parse_highmem);
598 * vmalloc=size forces the vmalloc area to be exactly 'size'
599 * bytes. This can be used to increase (or decrease) the
600 * vmalloc area - the default is 128m.
602 static int __init parse_vmalloc(char *arg)
607 __VMALLOC_RESERVE = memparse(arg, &arg);
610 early_param("vmalloc", parse_vmalloc);
613 * reservetop=size reserves a hole at the top of the kernel address space which
614 * a hypervisor can load into later. Needed for dynamically loaded hypervisors,
615 * so relocating the fixmap can be done before paging initialization.
617 static int __init parse_reservetop(char *arg)
619 unsigned long address;
624 address = memparse(arg, &arg);
625 reserve_top_address(address);
628 early_param("reservetop", parse_reservetop);
631 * Callback for efi_memory_walk.
634 efi_find_max_pfn(unsigned long start, unsigned long end, void *arg)
636 unsigned long *max_pfn = arg, pfn;
639 pfn = PFN_UP(end -1);
647 efi_memory_present_wrapper(unsigned long start, unsigned long end, void *arg)
649 memory_present(0, PFN_UP(start), PFN_DOWN(end));
654 * This function checks if the entire range <start,end> is mapped with type.
656 * Note: this function only works correct if the e820 table is sorted and
657 * not-overlapping, which is the case
660 e820_all_mapped(unsigned long s, unsigned long e, unsigned type)
665 for (i = 0; i < e820.nr_map; i++) {
666 struct e820entry *ei = &e820.map[i];
667 if (type && ei->type != type)
669 /* is the region (part) in overlap with the current region ?*/
670 if (ei->addr >= end || ei->addr + ei->size <= start)
672 /* if the region is at the beginning of <start,end> we move
673 * start to the end of the region since it's ok until there
675 if (ei->addr <= start)
676 start = ei->addr + ei->size;
677 /* if start is now at or beyond end, we're done, full
680 return 1; /* we're done */
686 * Find the highest page frame number we have available
688 void __init find_max_pfn(void)
694 efi_memmap_walk(efi_find_max_pfn, &max_pfn);
695 efi_memmap_walk(efi_memory_present_wrapper, NULL);
699 for (i = 0; i < e820.nr_map; i++) {
700 unsigned long start, end;
702 if (e820.map[i].type != E820_RAM)
704 start = PFN_UP(e820.map[i].addr);
705 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
710 memory_present(0, start, end);
715 * Determine low and high memory ranges:
717 unsigned long __init find_max_low_pfn(void)
719 unsigned long max_low_pfn;
721 max_low_pfn = max_pfn;
722 if (max_low_pfn > MAXMEM_PFN) {
723 if (highmem_pages == -1)
724 highmem_pages = max_pfn - MAXMEM_PFN;
725 if (highmem_pages + MAXMEM_PFN < max_pfn)
726 max_pfn = MAXMEM_PFN + highmem_pages;
727 if (highmem_pages + MAXMEM_PFN > max_pfn) {
728 printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
731 max_low_pfn = MAXMEM_PFN;
732 #ifndef CONFIG_HIGHMEM
733 /* Maximum memory usable is what is directly addressable */
734 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
736 if (max_pfn > MAX_NONPAE_PFN)
737 printk(KERN_WARNING "Use a PAE enabled kernel.\n");
739 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
740 max_pfn = MAXMEM_PFN;
741 #else /* !CONFIG_HIGHMEM */
742 #ifndef CONFIG_X86_PAE
743 if (max_pfn > MAX_NONPAE_PFN) {
744 max_pfn = MAX_NONPAE_PFN;
745 printk(KERN_WARNING "Warning only 4GB will be used.\n");
746 printk(KERN_WARNING "Use a PAE enabled kernel.\n");
748 #endif /* !CONFIG_X86_PAE */
749 #endif /* !CONFIG_HIGHMEM */
751 if (highmem_pages == -1)
753 #ifdef CONFIG_HIGHMEM
754 if (highmem_pages >= max_pfn) {
755 printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
759 if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
760 printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
763 max_low_pfn -= highmem_pages;
767 printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
774 * Free all available memory for boot time allocation. Used
775 * as a callback function by efi_memory_walk()
779 free_available_memory(unsigned long start, unsigned long end, void *arg)
781 /* check max_low_pfn */
782 if (start >= (max_low_pfn << PAGE_SHIFT))
784 if (end >= (max_low_pfn << PAGE_SHIFT))
785 end = max_low_pfn << PAGE_SHIFT;
787 free_bootmem(start, end - start);
792 * Register fully available low RAM pages with the bootmem allocator.
794 static void __init register_bootmem_low_pages(unsigned long max_low_pfn)
799 efi_memmap_walk(free_available_memory, NULL);
802 for (i = 0; i < e820.nr_map; i++) {
803 unsigned long curr_pfn, last_pfn, size;
805 * Reserve usable low memory
807 if (e820.map[i].type != E820_RAM)
810 * We are rounding up the start address of usable memory:
812 curr_pfn = PFN_UP(e820.map[i].addr);
813 if (curr_pfn >= max_low_pfn)
816 * ... and at the end of the usable range downwards:
818 last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
820 if (last_pfn > max_low_pfn)
821 last_pfn = max_low_pfn;
824 * .. finally, did all the rounding and playing
825 * around just make the area go away?
827 if (last_pfn <= curr_pfn)
830 size = last_pfn - curr_pfn;
831 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
836 * workaround for Dell systems that neglect to reserve EBDA
838 static void __init reserve_ebda_region(void)
841 addr = get_bios_ebda();
843 reserve_bootmem(addr, PAGE_SIZE);
846 #ifndef CONFIG_NEED_MULTIPLE_NODES
847 void __init setup_bootmem_allocator(void);
848 static unsigned long __init setup_memory(void)
851 * partially used pages are not usable - thus
852 * we are rounding upwards:
854 min_low_pfn = PFN_UP(init_pg_tables_end);
858 max_low_pfn = find_max_low_pfn();
860 #ifdef CONFIG_HIGHMEM
861 highstart_pfn = highend_pfn = max_pfn;
862 if (max_pfn > max_low_pfn) {
863 highstart_pfn = max_low_pfn;
865 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
866 pages_to_mb(highend_pfn - highstart_pfn));
867 num_physpages = highend_pfn;
868 high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
870 num_physpages = max_low_pfn;
871 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
873 #ifdef CONFIG_FLATMEM
874 max_mapnr = num_physpages;
876 printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
877 pages_to_mb(max_low_pfn));
879 setup_bootmem_allocator();
884 void __init zone_sizes_init(void)
886 unsigned long max_zone_pfns[MAX_NR_ZONES];
887 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
888 max_zone_pfns[ZONE_DMA] =
889 virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
890 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
891 #ifdef CONFIG_HIGHMEM
892 max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
893 add_active_range(0, 0, highend_pfn);
895 add_active_range(0, 0, max_low_pfn);
898 free_area_init_nodes(max_zone_pfns);
901 extern unsigned long __init setup_memory(void);
902 extern void zone_sizes_init(void);
903 #endif /* !CONFIG_NEED_MULTIPLE_NODES */
905 void __init setup_bootmem_allocator(void)
907 unsigned long bootmap_size;
909 * Initialize the boot-time allocator (with low memory only):
911 bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
913 register_bootmem_low_pages(max_low_pfn);
916 * Reserve the bootmem bitmap itself as well. We do this in two
917 * steps (first step was init_bootmem()) because this catches
918 * the (very unlikely) case of us accidentally initializing the
919 * bootmem allocator with an invalid RAM area.
921 reserve_bootmem(__pa_symbol(_text), (PFN_PHYS(min_low_pfn) +
922 bootmap_size + PAGE_SIZE-1) - __pa_symbol(_text));
925 * reserve physical page 0 - it's a special BIOS page on many boxes,
926 * enabling clean reboots, SMP operation, laptop functions.
928 reserve_bootmem(0, PAGE_SIZE);
930 /* reserve EBDA region, it's a 4K region */
931 reserve_ebda_region();
933 /* could be an AMD 768MPX chipset. Reserve a page before VGA to prevent
934 PCI prefetch into it (errata #56). Usually the page is reserved anyways,
935 unless you have no PS/2 mouse plugged in. */
936 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
937 boot_cpu_data.x86 == 6)
938 reserve_bootmem(0xa0000 - 4096, 4096);
942 * But first pinch a few for the stack/trampoline stuff
943 * FIXME: Don't need the extra page at 4K, but need to fix
944 * trampoline before removing it. (see the GDT stuff)
946 reserve_bootmem(PAGE_SIZE, PAGE_SIZE);
948 #ifdef CONFIG_ACPI_SLEEP
950 * Reserve low memory region for sleep support.
952 acpi_reserve_bootmem();
954 #ifdef CONFIG_X86_FIND_SMP_CONFIG
956 * Find and reserve possible boot-time SMP configuration:
961 #ifdef CONFIG_BLK_DEV_INITRD
962 if (LOADER_TYPE && INITRD_START) {
963 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
964 reserve_bootmem(INITRD_START, INITRD_SIZE);
966 INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
967 initrd_end = initrd_start+INITRD_SIZE;
970 printk(KERN_ERR "initrd extends beyond end of memory "
971 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
972 INITRD_START + INITRD_SIZE,
973 max_low_pfn << PAGE_SHIFT);
979 if (crashk_res.start != crashk_res.end)
980 reserve_bootmem(crashk_res.start,
981 crashk_res.end - crashk_res.start + 1);
986 * The node 0 pgdat is initialized before all of these because
987 * it's needed for bootmem. node>0 pgdats have their virtual
988 * space allocated before the pagetables are in place to access
989 * them, so they can't be cleared then.
991 * This should all compile down to nothing when NUMA is off.
993 void __init remapped_pgdat_init(void)
997 for_each_online_node(nid) {
999 memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
1005 static void __init register_memory(void)
1007 unsigned long gapstart, gapsize, round;
1008 unsigned long long last;
1012 * Search for the bigest gap in the low 32 bits of the e820
1015 last = 0x100000000ull;
1016 gapstart = 0x10000000;
1020 unsigned long long start = e820.map[i].addr;
1021 unsigned long long end = start + e820.map[i].size;
1024 * Since "last" is at most 4GB, we know we'll
1025 * fit in 32 bits if this condition is true
1028 unsigned long gap = last - end;
1030 if (gap > gapsize) {
1040 * See how much we want to round up: start off with
1041 * rounding to the next 1MB area.
1044 while ((gapsize >> 4) > round)
1046 /* Fun with two's complement */
1047 pci_mem_start = (gapstart + round) & -round;
1049 printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
1050 pci_mem_start, gapstart, gapsize);
1054 static void set_mca_bus(int x)
1059 static void set_mca_bus(int x) { }
1063 * Determine if we were loaded by an EFI loader. If so, then we have also been
1064 * passed the efi memmap, systab, etc., so we should use these data structures
1065 * for initialization. Note, the efi init code path is determined by the
1066 * global efi_enabled. This allows the same kernel image to be used on existing
1067 * systems (with a traditional BIOS) as well as on EFI systems.
1069 void __init setup_arch(char **cmdline_p)
1071 unsigned long max_low_pfn;
1073 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
1074 pre_setup_arch_hook();
1078 * FIXME: This isn't an official loader_type right
1079 * now but does currently work with elilo.
1080 * If we were configured as an EFI kernel, check to make
1081 * sure that we were loaded correctly from elilo and that
1082 * the system table is valid. If not, then initialize normally.
1085 if ((LOADER_TYPE == 0x50) && EFI_SYSTAB)
1089 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
1090 drive_info = DRIVE_INFO;
1091 screen_info = SCREEN_INFO;
1092 edid_info = EDID_INFO;
1093 apm_info.bios = APM_BIOS_INFO;
1094 ist_info = IST_INFO;
1095 saved_videomode = VIDEO_MODE;
1096 if( SYS_DESC_TABLE.length != 0 ) {
1097 set_mca_bus(SYS_DESC_TABLE.table[3] & 0x2);
1098 machine_id = SYS_DESC_TABLE.table[0];
1099 machine_submodel_id = SYS_DESC_TABLE.table[1];
1100 BIOS_revision = SYS_DESC_TABLE.table[2];
1102 bootloader_type = LOADER_TYPE;
1104 #ifdef CONFIG_BLK_DEV_RAM
1105 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
1106 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
1107 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
1113 printk(KERN_INFO "BIOS-provided physical RAM map:\n");
1114 print_memory_map(machine_specific_memory_setup());
1119 if (!MOUNT_ROOT_RDONLY)
1120 root_mountflags &= ~MS_RDONLY;
1121 init_mm.start_code = (unsigned long) _text;
1122 init_mm.end_code = (unsigned long) _etext;
1123 init_mm.end_data = (unsigned long) _edata;
1124 init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
1126 code_resource.start = virt_to_phys(_text);
1127 code_resource.end = virt_to_phys(_etext)-1;
1128 data_resource.start = virt_to_phys(_etext);
1129 data_resource.end = virt_to_phys(_edata)-1;
1131 parse_early_param();
1133 if (user_defined_memmap) {
1134 printk(KERN_INFO "user-defined physical RAM map:\n");
1135 print_memory_map("user");
1138 strlcpy(command_line, saved_command_line, COMMAND_LINE_SIZE);
1139 *cmdline_p = command_line;
1141 max_low_pfn = setup_memory();
1144 * NOTE: before this point _nobody_ is allowed to allocate
1145 * any memory using the bootmem allocator. Although the
1146 * alloctor is now initialised only the first 8Mb of the kernel
1147 * virtual address space has been mapped. All allocations before
1148 * paging_init() has completed must use the alloc_bootmem_low_pages()
1149 * variant (which allocates DMA'able memory) and care must be taken
1150 * not to exceed the 8Mb limit.
1154 smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
1157 remapped_pgdat_init();
1162 * NOTE: at this point the bootmem allocator is fully available.
1167 #ifdef CONFIG_X86_GENERICARCH
1168 generic_apic_probe();
1175 * Parse the ACPI tables for possible boot-time SMP configuration.
1177 acpi_boot_table_init();
1181 #ifdef CONFIG_X86_IO_APIC
1182 check_acpi_pci(); /* Checks more than just ACPI actually */
1189 #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
1191 printk(KERN_WARNING "More than 8 CPUs detected and "
1192 "CONFIG_X86_PC cannot handle it.\nUse "
1193 "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
1196 #ifdef CONFIG_X86_LOCAL_APIC
1197 if (smp_found_config)
1204 #if defined(CONFIG_VGA_CONSOLE)
1205 if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
1206 conswitchp = &vga_con;
1207 #elif defined(CONFIG_DUMMY_CONSOLE)
1208 conswitchp = &dummy_con;
1214 static __init int add_pcspkr(void)
1216 struct platform_device *pd;
1219 pd = platform_device_alloc("pcspkr", -1);
1223 ret = platform_device_add(pd);
1225 platform_device_put(pd);
1229 device_initcall(add_pcspkr);
1234 * c-file-style:"k&r"