]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/i386/kernel/setup.c
[PATCH] i386: Move find_max_pfn function to e820.c
[karo-tx-linux.git] / arch / i386 / kernel / setup.c
1 /*
2  *  linux/arch/i386/kernel/setup.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *
6  *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
7  *
8  *  Memory region support
9  *      David Parsons <orc@pell.chi.il.us>, July-August 1999
10  *
11  *  Added E820 sanitization routine (removes overlapping memory regions);
12  *  Brian Moyle <bmoyle@mvista.com>, February 2001
13  *
14  * Moved CPU detection code to cpu/${cpu}.c
15  *    Patrick Mochel <mochel@osdl.org>, March 2002
16  *
17  *  Provisions for empty E820 memory regions (reported by certain BIOSes).
18  *  Alex Achenbach <xela@slit.de>, December 2002.
19  *
20  */
21
22 /*
23  * This file handles the architecture-dependent parts of initialization
24  */
25
26 #include <linux/sched.h>
27 #include <linux/mm.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>
50
51 #include <video/edid.h>
52
53 #include <asm/apic.h>
54 #include <asm/e820.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>
61 #include <asm/ist.h>
62 #include <asm/io.h>
63 #include <setup_arch.h>
64 #include <bios_ebda.h>
65
66 /* This value is set up by the early boot code to point to the value
67    immediately after the boot time page tables.  It contains a *physical*
68    address, and must not be in the .bss segment! */
69 unsigned long init_pg_tables_end __initdata = ~0UL;
70
71 int disable_pse __devinitdata = 0;
72
73 /*
74  * Machine setup..
75  */
76 extern struct e820map e820;
77 extern struct resource code_resource;
78 extern struct resource data_resource;
79
80 /* cpu data as detected by the assembly code in head.S */
81 struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
82 /* common cpu data for all cpus */
83 struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
84 EXPORT_SYMBOL(boot_cpu_data);
85
86 unsigned long mmu_cr4_features;
87
88 /* for MCA, but anyone else can use it if they want */
89 unsigned int machine_id;
90 #ifdef CONFIG_MCA
91 EXPORT_SYMBOL(machine_id);
92 #endif
93 unsigned int machine_submodel_id;
94 unsigned int BIOS_revision;
95 unsigned int mca_pentium_flag;
96
97 /* For PCI or other memory-mapped resources */
98 unsigned long pci_mem_start = 0x10000000;
99 #ifdef CONFIG_PCI
100 EXPORT_SYMBOL(pci_mem_start);
101 #endif
102
103 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
104 int bootloader_type;
105
106 /* user-defined highmem size */
107 static unsigned int highmem_pages = -1;
108
109 /*
110  * Setup options
111  */
112 struct drive_info_struct { char dummy[32]; } drive_info;
113 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_HD) || \
114     defined(CONFIG_BLK_DEV_IDE_MODULE) || defined(CONFIG_BLK_DEV_HD_MODULE)
115 EXPORT_SYMBOL(drive_info);
116 #endif
117 struct screen_info screen_info;
118 EXPORT_SYMBOL(screen_info);
119 struct apm_info apm_info;
120 EXPORT_SYMBOL(apm_info);
121 struct sys_desc_table_struct {
122         unsigned short length;
123         unsigned char table[0];
124 };
125 struct edid_info edid_info;
126 EXPORT_SYMBOL_GPL(edid_info);
127 struct ist_info ist_info;
128 #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
129         defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
130 EXPORT_SYMBOL(ist_info);
131 #endif
132
133 extern void early_cpu_init(void);
134 extern int root_mountflags;
135
136 unsigned long saved_videomode;
137
138 #define RAMDISK_IMAGE_START_MASK        0x07FF
139 #define RAMDISK_PROMPT_FLAG             0x8000
140 #define RAMDISK_LOAD_FLAG               0x4000  
141
142 static char command_line[COMMAND_LINE_SIZE];
143
144 unsigned char __initdata boot_params[PARAM_SIZE];
145
146 static void __init limit_regions(unsigned long long size)
147 {
148         unsigned long long current_addr = 0;
149         int i;
150
151         if (efi_enabled) {
152                 efi_memory_desc_t *md;
153                 void *p;
154
155                 for (p = memmap.map, i = 0; p < memmap.map_end;
156                         p += memmap.desc_size, i++) {
157                         md = p;
158                         current_addr = md->phys_addr + (md->num_pages << 12);
159                         if (md->type == EFI_CONVENTIONAL_MEMORY) {
160                                 if (current_addr >= size) {
161                                         md->num_pages -=
162                                                 (((current_addr-size) + PAGE_SIZE-1) >> PAGE_SHIFT);
163                                         memmap.nr_map = i + 1;
164                                         return;
165                                 }
166                         }
167                 }
168         }
169         for (i = 0; i < e820.nr_map; i++) {
170                 current_addr = e820.map[i].addr + e820.map[i].size;
171                 if (current_addr < size)
172                         continue;
173
174                 if (e820.map[i].type != E820_RAM)
175                         continue;
176
177                 if (e820.map[i].addr >= size) {
178                         /*
179                          * This region starts past the end of the
180                          * requested size, skip it completely.
181                          */
182                         e820.nr_map = i;
183                 } else {
184                         e820.nr_map = i + 1;
185                         e820.map[i].size -= current_addr - size;
186                 }
187                 return;
188         }
189 }
190
191 #define E820_DEBUG      1
192
193 static void __init print_memory_map(char *who)
194 {
195         int i;
196
197         for (i = 0; i < e820.nr_map; i++) {
198                 printk(" %s: %016Lx - %016Lx ", who,
199                         e820.map[i].addr,
200                         e820.map[i].addr + e820.map[i].size);
201                 switch (e820.map[i].type) {
202                 case E820_RAM:  printk("(usable)\n");
203                                 break;
204                 case E820_RESERVED:
205                                 printk("(reserved)\n");
206                                 break;
207                 case E820_ACPI:
208                                 printk("(ACPI data)\n");
209                                 break;
210                 case E820_NVS:
211                                 printk("(ACPI NVS)\n");
212                                 break;
213                 default:        printk("type %lu\n", e820.map[i].type);
214                                 break;
215                 }
216         }
217 }
218
219 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
220 struct edd edd;
221 #ifdef CONFIG_EDD_MODULE
222 EXPORT_SYMBOL(edd);
223 #endif
224 /**
225  * copy_edd() - Copy the BIOS EDD information
226  *              from boot_params into a safe place.
227  *
228  */
229 static inline void copy_edd(void)
230 {
231      memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
232      memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
233      edd.mbr_signature_nr = EDD_MBR_SIG_NR;
234      edd.edd_info_nr = EDD_NR;
235 }
236 #else
237 static inline void copy_edd(void)
238 {
239 }
240 #endif
241
242 static int __initdata user_defined_memmap = 0;
243
244 /*
245  * "mem=nopentium" disables the 4MB page tables.
246  * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
247  * to <mem>, overriding the bios size.
248  * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
249  * <start> to <start>+<mem>, overriding the bios size.
250  *
251  * HPA tells me bootloaders need to parse mem=, so no new
252  * option should be mem=  [also see Documentation/i386/boot.txt]
253  */
254 static int __init parse_mem(char *arg)
255 {
256         if (!arg)
257                 return -EINVAL;
258
259         if (strcmp(arg, "nopentium") == 0) {
260                 clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
261                 disable_pse = 1;
262         } else {
263                 /* If the user specifies memory size, we
264                  * limit the BIOS-provided memory map to
265                  * that size. exactmap can be used to specify
266                  * the exact map. mem=number can be used to
267                  * trim the existing memory map.
268                  */
269                 unsigned long long mem_size;
270  
271                 mem_size = memparse(arg, &arg);
272                 limit_regions(mem_size);
273                 user_defined_memmap = 1;
274         }
275         return 0;
276 }
277 early_param("mem", parse_mem);
278
279 static int __init parse_memmap(char *arg)
280 {
281         if (!arg)
282                 return -EINVAL;
283
284         if (strcmp(arg, "exactmap") == 0) {
285 #ifdef CONFIG_CRASH_DUMP
286                 /* If we are doing a crash dump, we
287                  * still need to know the real mem
288                  * size before original memory map is
289                  * reset.
290                  */
291                 find_max_pfn();
292                 saved_max_pfn = max_pfn;
293 #endif
294                 e820.nr_map = 0;
295                 user_defined_memmap = 1;
296         } else {
297                 /* If the user specifies memory size, we
298                  * limit the BIOS-provided memory map to
299                  * that size. exactmap can be used to specify
300                  * the exact map. mem=number can be used to
301                  * trim the existing memory map.
302                  */
303                 unsigned long long start_at, mem_size;
304
305                 mem_size = memparse(arg, &arg);
306                 if (*arg == '@') {
307                         start_at = memparse(arg+1, &arg);
308                         add_memory_region(start_at, mem_size, E820_RAM);
309                 } else if (*arg == '#') {
310                         start_at = memparse(arg+1, &arg);
311                         add_memory_region(start_at, mem_size, E820_ACPI);
312                 } else if (*arg == '$') {
313                         start_at = memparse(arg+1, &arg);
314                         add_memory_region(start_at, mem_size, E820_RESERVED);
315                 } else {
316                         limit_regions(mem_size);
317                         user_defined_memmap = 1;
318                 }
319         }
320         return 0;
321 }
322 early_param("memmap", parse_memmap);
323
324 #ifdef CONFIG_PROC_VMCORE
325 /* elfcorehdr= specifies the location of elf core header
326  * stored by the crashed kernel.
327  */
328 static int __init parse_elfcorehdr(char *arg)
329 {
330         if (!arg)
331                 return -EINVAL;
332
333         elfcorehdr_addr = memparse(arg, &arg);
334         return 0;
335 }
336 early_param("elfcorehdr", parse_elfcorehdr);
337 #endif /* CONFIG_PROC_VMCORE */
338
339 /*
340  * highmem=size forces highmem to be exactly 'size' bytes.
341  * This works even on boxes that have no highmem otherwise.
342  * This also works to reduce highmem size on bigger boxes.
343  */
344 static int __init parse_highmem(char *arg)
345 {
346         if (!arg)
347                 return -EINVAL;
348
349         highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
350         return 0;
351 }
352 early_param("highmem", parse_highmem);
353
354 /*
355  * vmalloc=size forces the vmalloc area to be exactly 'size'
356  * bytes. This can be used to increase (or decrease) the
357  * vmalloc area - the default is 128m.
358  */
359 static int __init parse_vmalloc(char *arg)
360 {
361         if (!arg)
362                 return -EINVAL;
363
364         __VMALLOC_RESERVE = memparse(arg, &arg);
365         return 0;
366 }
367 early_param("vmalloc", parse_vmalloc);
368
369 /*
370  * reservetop=size reserves a hole at the top of the kernel address space which
371  * a hypervisor can load into later.  Needed for dynamically loaded hypervisors,
372  * so relocating the fixmap can be done before paging initialization.
373  */
374 static int __init parse_reservetop(char *arg)
375 {
376         unsigned long address;
377
378         if (!arg)
379                 return -EINVAL;
380
381         address = memparse(arg, &arg);
382         reserve_top_address(address);
383         return 0;
384 }
385 early_param("reservetop", parse_reservetop);
386
387  /*
388   * This function checks if the entire range <start,end> is mapped with type.
389   *
390   * Note: this function only works correct if the e820 table is sorted and
391   * not-overlapping, which is the case
392   */
393 int __init
394 e820_all_mapped(unsigned long s, unsigned long e, unsigned type)
395 {
396         u64 start = s;
397         u64 end = e;
398         int i;
399         for (i = 0; i < e820.nr_map; i++) {
400                 struct e820entry *ei = &e820.map[i];
401                 if (type && ei->type != type)
402                         continue;
403                 /* is the region (part) in overlap with the current region ?*/
404                 if (ei->addr >= end || ei->addr + ei->size <= start)
405                         continue;
406                 /* if the region is at the beginning of <start,end> we move
407                  * start to the end of the region since it's ok until there
408                  */
409                 if (ei->addr <= start)
410                         start = ei->addr + ei->size;
411                 /* if start is now at or beyond end, we're done, full
412                  * coverage */
413                 if (start >= end)
414                         return 1; /* we're done */
415         }
416         return 0;
417 }
418
419 /*
420  * Determine low and high memory ranges:
421  */
422 unsigned long __init find_max_low_pfn(void)
423 {
424         unsigned long max_low_pfn;
425
426         max_low_pfn = max_pfn;
427         if (max_low_pfn > MAXMEM_PFN) {
428                 if (highmem_pages == -1)
429                         highmem_pages = max_pfn - MAXMEM_PFN;
430                 if (highmem_pages + MAXMEM_PFN < max_pfn)
431                         max_pfn = MAXMEM_PFN + highmem_pages;
432                 if (highmem_pages + MAXMEM_PFN > max_pfn) {
433                         printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
434                         highmem_pages = 0;
435                 }
436                 max_low_pfn = MAXMEM_PFN;
437 #ifndef CONFIG_HIGHMEM
438                 /* Maximum memory usable is what is directly addressable */
439                 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
440                                         MAXMEM>>20);
441                 if (max_pfn > MAX_NONPAE_PFN)
442                         printk(KERN_WARNING "Use a PAE enabled kernel.\n");
443                 else
444                         printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
445                 max_pfn = MAXMEM_PFN;
446 #else /* !CONFIG_HIGHMEM */
447 #ifndef CONFIG_X86_PAE
448                 if (max_pfn > MAX_NONPAE_PFN) {
449                         max_pfn = MAX_NONPAE_PFN;
450                         printk(KERN_WARNING "Warning only 4GB will be used.\n");
451                         printk(KERN_WARNING "Use a PAE enabled kernel.\n");
452                 }
453 #endif /* !CONFIG_X86_PAE */
454 #endif /* !CONFIG_HIGHMEM */
455         } else {
456                 if (highmem_pages == -1)
457                         highmem_pages = 0;
458 #ifdef CONFIG_HIGHMEM
459                 if (highmem_pages >= max_pfn) {
460                         printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
461                         highmem_pages = 0;
462                 }
463                 if (highmem_pages) {
464                         if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
465                                 printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
466                                 highmem_pages = 0;
467                         }
468                         max_low_pfn -= highmem_pages;
469                 }
470 #else
471                 if (highmem_pages)
472                         printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
473 #endif
474         }
475         return max_low_pfn;
476 }
477
478 /*
479  * Free all available memory for boot time allocation.  Used
480  * as a callback function by efi_memory_walk()
481  */
482
483 static int __init
484 free_available_memory(unsigned long start, unsigned long end, void *arg)
485 {
486         /* check max_low_pfn */
487         if (start >= (max_low_pfn << PAGE_SHIFT))
488                 return 0;
489         if (end >= (max_low_pfn << PAGE_SHIFT))
490                 end = max_low_pfn << PAGE_SHIFT;
491         if (start < end)
492                 free_bootmem(start, end - start);
493
494         return 0;
495 }
496 /*
497  * Register fully available low RAM pages with the bootmem allocator.
498  */
499 static void __init register_bootmem_low_pages(unsigned long max_low_pfn)
500 {
501         int i;
502
503         if (efi_enabled) {
504                 efi_memmap_walk(free_available_memory, NULL);
505                 return;
506         }
507         for (i = 0; i < e820.nr_map; i++) {
508                 unsigned long curr_pfn, last_pfn, size;
509                 /*
510                  * Reserve usable low memory
511                  */
512                 if (e820.map[i].type != E820_RAM)
513                         continue;
514                 /*
515                  * We are rounding up the start address of usable memory:
516                  */
517                 curr_pfn = PFN_UP(e820.map[i].addr);
518                 if (curr_pfn >= max_low_pfn)
519                         continue;
520                 /*
521                  * ... and at the end of the usable range downwards:
522                  */
523                 last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
524
525                 if (last_pfn > max_low_pfn)
526                         last_pfn = max_low_pfn;
527
528                 /*
529                  * .. finally, did all the rounding and playing
530                  * around just make the area go away?
531                  */
532                 if (last_pfn <= curr_pfn)
533                         continue;
534
535                 size = last_pfn - curr_pfn;
536                 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
537         }
538 }
539
540 /*
541  * workaround for Dell systems that neglect to reserve EBDA
542  */
543 static void __init reserve_ebda_region(void)
544 {
545         unsigned int addr;
546         addr = get_bios_ebda();
547         if (addr)
548                 reserve_bootmem(addr, PAGE_SIZE);       
549 }
550
551 #ifndef CONFIG_NEED_MULTIPLE_NODES
552 void __init setup_bootmem_allocator(void);
553 static unsigned long __init setup_memory(void)
554 {
555         /*
556          * partially used pages are not usable - thus
557          * we are rounding upwards:
558          */
559         min_low_pfn = PFN_UP(init_pg_tables_end);
560
561         find_max_pfn();
562
563         max_low_pfn = find_max_low_pfn();
564
565 #ifdef CONFIG_HIGHMEM
566         highstart_pfn = highend_pfn = max_pfn;
567         if (max_pfn > max_low_pfn) {
568                 highstart_pfn = max_low_pfn;
569         }
570         printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
571                 pages_to_mb(highend_pfn - highstart_pfn));
572         num_physpages = highend_pfn;
573         high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
574 #else
575         num_physpages = max_low_pfn;
576         high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
577 #endif
578 #ifdef CONFIG_FLATMEM
579         max_mapnr = num_physpages;
580 #endif
581         printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
582                         pages_to_mb(max_low_pfn));
583
584         setup_bootmem_allocator();
585
586         return max_low_pfn;
587 }
588
589 void __init zone_sizes_init(void)
590 {
591         unsigned long max_zone_pfns[MAX_NR_ZONES];
592         memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
593         max_zone_pfns[ZONE_DMA] =
594                 virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
595         max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
596 #ifdef CONFIG_HIGHMEM
597         max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
598         add_active_range(0, 0, highend_pfn);
599 #else
600         add_active_range(0, 0, max_low_pfn);
601 #endif
602
603         free_area_init_nodes(max_zone_pfns);
604 }
605 #else
606 extern unsigned long __init setup_memory(void);
607 extern void zone_sizes_init(void);
608 #endif /* !CONFIG_NEED_MULTIPLE_NODES */
609
610 void __init setup_bootmem_allocator(void)
611 {
612         unsigned long bootmap_size;
613         /*
614          * Initialize the boot-time allocator (with low memory only):
615          */
616         bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
617
618         register_bootmem_low_pages(max_low_pfn);
619
620         /*
621          * Reserve the bootmem bitmap itself as well. We do this in two
622          * steps (first step was init_bootmem()) because this catches
623          * the (very unlikely) case of us accidentally initializing the
624          * bootmem allocator with an invalid RAM area.
625          */
626         reserve_bootmem(__pa_symbol(_text), (PFN_PHYS(min_low_pfn) +
627                          bootmap_size + PAGE_SIZE-1) - __pa_symbol(_text));
628
629         /*
630          * reserve physical page 0 - it's a special BIOS page on many boxes,
631          * enabling clean reboots, SMP operation, laptop functions.
632          */
633         reserve_bootmem(0, PAGE_SIZE);
634
635         /* reserve EBDA region, it's a 4K region */
636         reserve_ebda_region();
637
638     /* could be an AMD 768MPX chipset. Reserve a page  before VGA to prevent
639        PCI prefetch into it (errata #56). Usually the page is reserved anyways,
640        unless you have no PS/2 mouse plugged in. */
641         if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
642             boot_cpu_data.x86 == 6)
643              reserve_bootmem(0xa0000 - 4096, 4096);
644
645 #ifdef CONFIG_SMP
646         /*
647          * But first pinch a few for the stack/trampoline stuff
648          * FIXME: Don't need the extra page at 4K, but need to fix
649          * trampoline before removing it. (see the GDT stuff)
650          */
651         reserve_bootmem(PAGE_SIZE, PAGE_SIZE);
652 #endif
653 #ifdef CONFIG_ACPI_SLEEP
654         /*
655          * Reserve low memory region for sleep support.
656          */
657         acpi_reserve_bootmem();
658 #endif
659 #ifdef CONFIG_X86_FIND_SMP_CONFIG
660         /*
661          * Find and reserve possible boot-time SMP configuration:
662          */
663         find_smp_config();
664 #endif
665         numa_kva_reserve();
666 #ifdef CONFIG_BLK_DEV_INITRD
667         if (LOADER_TYPE && INITRD_START) {
668                 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
669                         reserve_bootmem(INITRD_START, INITRD_SIZE);
670                         initrd_start =
671                                 INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
672                         initrd_end = initrd_start+INITRD_SIZE;
673                 }
674                 else {
675                         printk(KERN_ERR "initrd extends beyond end of memory "
676                             "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
677                             INITRD_START + INITRD_SIZE,
678                             max_low_pfn << PAGE_SHIFT);
679                         initrd_start = 0;
680                 }
681         }
682 #endif
683 #ifdef CONFIG_KEXEC
684         if (crashk_res.start != crashk_res.end)
685                 reserve_bootmem(crashk_res.start,
686                         crashk_res.end - crashk_res.start + 1);
687 #endif
688 }
689
690 /*
691  * The node 0 pgdat is initialized before all of these because
692  * it's needed for bootmem.  node>0 pgdats have their virtual
693  * space allocated before the pagetables are in place to access
694  * them, so they can't be cleared then.
695  *
696  * This should all compile down to nothing when NUMA is off.
697  */
698 void __init remapped_pgdat_init(void)
699 {
700         int nid;
701
702         for_each_online_node(nid) {
703                 if (nid != 0)
704                         memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
705         }
706 }
707
708
709
710 static void __init register_memory(void)
711 {
712         unsigned long gapstart, gapsize, round;
713         unsigned long long last;
714         int i;
715
716         /*
717          * Search for the bigest gap in the low 32 bits of the e820
718          * memory space.
719          */
720         last = 0x100000000ull;
721         gapstart = 0x10000000;
722         gapsize = 0x400000;
723         i = e820.nr_map;
724         while (--i >= 0) {
725                 unsigned long long start = e820.map[i].addr;
726                 unsigned long long end = start + e820.map[i].size;
727
728                 /*
729                  * Since "last" is at most 4GB, we know we'll
730                  * fit in 32 bits if this condition is true
731                  */
732                 if (last > end) {
733                         unsigned long gap = last - end;
734
735                         if (gap > gapsize) {
736                                 gapsize = gap;
737                                 gapstart = end;
738                         }
739                 }
740                 if (start < last)
741                         last = start;
742         }
743
744         /*
745          * See how much we want to round up: start off with
746          * rounding to the next 1MB area.
747          */
748         round = 0x100000;
749         while ((gapsize >> 4) > round)
750                 round += round;
751         /* Fun with two's complement */
752         pci_mem_start = (gapstart + round) & -round;
753
754         printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
755                 pci_mem_start, gapstart, gapsize);
756 }
757
758 #ifdef CONFIG_MCA
759 static void set_mca_bus(int x)
760 {
761         MCA_bus = x;
762 }
763 #else
764 static void set_mca_bus(int x) { }
765 #endif
766
767 /*
768  * Determine if we were loaded by an EFI loader.  If so, then we have also been
769  * passed the efi memmap, systab, etc., so we should use these data structures
770  * for initialization.  Note, the efi init code path is determined by the
771  * global efi_enabled. This allows the same kernel image to be used on existing
772  * systems (with a traditional BIOS) as well as on EFI systems.
773  */
774 void __init setup_arch(char **cmdline_p)
775 {
776         unsigned long max_low_pfn;
777
778         memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
779         pre_setup_arch_hook();
780         early_cpu_init();
781
782         /*
783          * FIXME: This isn't an official loader_type right
784          * now but does currently work with elilo.
785          * If we were configured as an EFI kernel, check to make
786          * sure that we were loaded correctly from elilo and that
787          * the system table is valid.  If not, then initialize normally.
788          */
789 #ifdef CONFIG_EFI
790         if ((LOADER_TYPE == 0x50) && EFI_SYSTAB)
791                 efi_enabled = 1;
792 #endif
793
794         ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
795         drive_info = DRIVE_INFO;
796         screen_info = SCREEN_INFO;
797         edid_info = EDID_INFO;
798         apm_info.bios = APM_BIOS_INFO;
799         ist_info = IST_INFO;
800         saved_videomode = VIDEO_MODE;
801         if( SYS_DESC_TABLE.length != 0 ) {
802                 set_mca_bus(SYS_DESC_TABLE.table[3] & 0x2);
803                 machine_id = SYS_DESC_TABLE.table[0];
804                 machine_submodel_id = SYS_DESC_TABLE.table[1];
805                 BIOS_revision = SYS_DESC_TABLE.table[2];
806         }
807         bootloader_type = LOADER_TYPE;
808
809 #ifdef CONFIG_BLK_DEV_RAM
810         rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
811         rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
812         rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
813 #endif
814         ARCH_SETUP
815         if (efi_enabled)
816                 efi_init();
817         else {
818                 printk(KERN_INFO "BIOS-provided physical RAM map:\n");
819                 print_memory_map(machine_specific_memory_setup());
820         }
821
822         copy_edd();
823
824         if (!MOUNT_ROOT_RDONLY)
825                 root_mountflags &= ~MS_RDONLY;
826         init_mm.start_code = (unsigned long) _text;
827         init_mm.end_code = (unsigned long) _etext;
828         init_mm.end_data = (unsigned long) _edata;
829         init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
830
831         code_resource.start = virt_to_phys(_text);
832         code_resource.end = virt_to_phys(_etext)-1;
833         data_resource.start = virt_to_phys(_etext);
834         data_resource.end = virt_to_phys(_edata)-1;
835
836         parse_early_param();
837
838         if (user_defined_memmap) {
839                 printk(KERN_INFO "user-defined physical RAM map:\n");
840                 print_memory_map("user");
841         }
842
843         strlcpy(command_line, saved_command_line, COMMAND_LINE_SIZE);
844         *cmdline_p = command_line;
845
846         max_low_pfn = setup_memory();
847
848         /*
849          * NOTE: before this point _nobody_ is allowed to allocate
850          * any memory using the bootmem allocator.  Although the
851          * alloctor is now initialised only the first 8Mb of the kernel
852          * virtual address space has been mapped.  All allocations before
853          * paging_init() has completed must use the alloc_bootmem_low_pages()
854          * variant (which allocates DMA'able memory) and care must be taken
855          * not to exceed the 8Mb limit.
856          */
857
858 #ifdef CONFIG_SMP
859         smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
860 #endif
861         paging_init();
862         remapped_pgdat_init();
863         sparse_init();
864         zone_sizes_init();
865
866         /*
867          * NOTE: at this point the bootmem allocator is fully available.
868          */
869
870         dmi_scan_machine();
871
872 #ifdef CONFIG_X86_GENERICARCH
873         generic_apic_probe();
874 #endif  
875         if (efi_enabled)
876                 efi_map_memmap();
877
878 #ifdef CONFIG_ACPI
879         /*
880          * Parse the ACPI tables for possible boot-time SMP configuration.
881          */
882         acpi_boot_table_init();
883 #endif
884
885 #ifdef CONFIG_PCI
886 #ifdef CONFIG_X86_IO_APIC
887         check_acpi_pci();       /* Checks more than just ACPI actually */
888 #endif
889 #endif
890
891 #ifdef CONFIG_ACPI
892         acpi_boot_init();
893
894 #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
895         if (def_to_bigsmp)
896                 printk(KERN_WARNING "More than 8 CPUs detected and "
897                         "CONFIG_X86_PC cannot handle it.\nUse "
898                         "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
899 #endif
900 #endif
901 #ifdef CONFIG_X86_LOCAL_APIC
902         if (smp_found_config)
903                 get_smp_config();
904 #endif
905
906         register_memory();
907
908 #ifdef CONFIG_VT
909 #if defined(CONFIG_VGA_CONSOLE)
910         if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
911                 conswitchp = &vga_con;
912 #elif defined(CONFIG_DUMMY_CONSOLE)
913         conswitchp = &dummy_con;
914 #endif
915 #endif
916         tsc_init();
917 }
918
919 static __init int add_pcspkr(void)
920 {
921         struct platform_device *pd;
922         int ret;
923
924         pd = platform_device_alloc("pcspkr", -1);
925         if (!pd)
926                 return -ENOMEM;
927
928         ret = platform_device_add(pd);
929         if (ret)
930                 platform_device_put(pd);
931
932         return ret;
933 }
934 device_initcall(add_pcspkr);
935
936 /*
937  * Local Variables:
938  * mode:c
939  * c-file-style:"k&r"
940  * c-basic-offset:8
941  * End:
942  */