ia64/linux-2.6.18-xen.hg

view arch/i386/kernel/setup-xen.c @ 912:dd42cdb0ab89

[IA64] Build blktap2 driver by default in x86 builds.

add CONFIG_XEN_BLKDEV_TAP2=y to buildconfigs/linux-defconfig_xen_ia64.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 12:09:16 2009 +0900 (2009-06-29)
parents 1c928f28914a
children
line source
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 */
22 /*
23 * This file handles the architecture-dependent parts of initialization
24 */
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/kernel.h>
47 #include <linux/percpu.h>
48 #include <linux/notifier.h>
49 #include <linux/kexec.h>
50 #include <linux/crash_dump.h>
51 #include <linux/dmi.h>
52 #include <linux/pfn.h>
54 #include <video/edid.h>
56 #include <asm/apic.h>
57 #include <asm/e820.h>
58 #include <asm/mpspec.h>
59 #include <asm/setup.h>
60 #include <asm/arch_hooks.h>
61 #include <asm/sections.h>
62 #include <asm/io_apic.h>
63 #include <asm/ist.h>
64 #include <asm/io.h>
65 #include <asm/hypervisor.h>
66 #include <xen/interface/physdev.h>
67 #include <xen/interface/memory.h>
68 #include <xen/features.h>
69 #include <xen/firmware.h>
70 #include <xen/xencons.h>
71 #include <setup_arch.h>
72 #include <bios_ebda.h>
74 #ifdef CONFIG_XEN
75 #include <xen/interface/kexec.h>
76 #endif
78 /* Forward Declaration. */
79 void __init find_max_pfn(void);
81 static int xen_panic_event(struct notifier_block *, unsigned long, void *);
82 static struct notifier_block xen_panic_block = {
83 xen_panic_event, NULL, 0 /* try to go last */
84 };
86 extern char hypercall_page[PAGE_SIZE];
87 EXPORT_SYMBOL(hypercall_page);
89 int disable_pse __devinitdata = 0;
91 /*
92 * Machine setup..
93 */
95 #ifdef CONFIG_EFI
96 int efi_enabled = 0;
97 EXPORT_SYMBOL(efi_enabled);
98 #endif
100 /* cpu data as detected by the assembly code in head.S */
101 struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
102 /* common cpu data for all cpus */
103 struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
104 EXPORT_SYMBOL(boot_cpu_data);
106 unsigned long mmu_cr4_features;
108 #ifdef CONFIG_ACPI
109 int acpi_disabled = 0;
110 #else
111 int acpi_disabled = 1;
112 #endif
113 EXPORT_SYMBOL(acpi_disabled);
115 #ifdef CONFIG_ACPI
116 int __initdata acpi_force = 0;
117 extern acpi_interrupt_flags acpi_sci_flags;
118 #endif
120 /* for MCA, but anyone else can use it if they want */
121 unsigned int machine_id;
122 #ifdef CONFIG_MCA
123 EXPORT_SYMBOL(machine_id);
124 #endif
125 unsigned int machine_submodel_id;
126 unsigned int BIOS_revision;
127 unsigned int mca_pentium_flag;
129 /* For PCI or other memory-mapped resources */
130 unsigned long pci_mem_start = 0x10000000;
131 #ifdef CONFIG_PCI
132 EXPORT_SYMBOL(pci_mem_start);
133 #endif
135 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
136 int bootloader_type;
138 /* user-defined highmem size */
139 static unsigned int highmem_pages = -1;
141 /*
142 * Setup options
143 */
144 struct drive_info_struct { char dummy[32]; } drive_info;
145 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_HD) || \
146 defined(CONFIG_BLK_DEV_IDE_MODULE) || defined(CONFIG_BLK_DEV_HD_MODULE)
147 EXPORT_SYMBOL(drive_info);
148 #endif
149 struct screen_info screen_info;
150 EXPORT_SYMBOL(screen_info);
151 struct apm_info apm_info;
152 EXPORT_SYMBOL(apm_info);
153 struct sys_desc_table_struct {
154 unsigned short length;
155 unsigned char table[0];
156 };
157 struct edid_info edid_info;
158 EXPORT_SYMBOL_GPL(edid_info);
159 #ifndef CONFIG_XEN
160 #define copy_edid() (edid_info = EDID_INFO)
161 #endif
162 struct ist_info ist_info;
163 #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
164 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
165 EXPORT_SYMBOL(ist_info);
166 #endif
167 struct e820map e820;
168 #ifdef CONFIG_XEN
169 struct e820map machine_e820;
170 #endif
172 extern void early_cpu_init(void);
173 extern void generic_apic_probe(char *);
174 extern int root_mountflags;
176 unsigned long saved_videomode;
178 #define RAMDISK_IMAGE_START_MASK 0x07FF
179 #define RAMDISK_PROMPT_FLAG 0x8000
180 #define RAMDISK_LOAD_FLAG 0x4000
182 static char command_line[COMMAND_LINE_SIZE];
184 unsigned char __initdata boot_params[PARAM_SIZE];
186 static struct resource data_resource = {
187 .name = "Kernel data",
188 .start = 0,
189 .end = 0,
190 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
191 };
193 static struct resource code_resource = {
194 .name = "Kernel code",
195 .start = 0,
196 .end = 0,
197 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
198 };
200 static struct resource system_rom_resource = {
201 .name = "System ROM",
202 .start = 0xf0000,
203 .end = 0xfffff,
204 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
205 };
207 static struct resource extension_rom_resource = {
208 .name = "Extension ROM",
209 .start = 0xe0000,
210 .end = 0xeffff,
211 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
212 };
214 static struct resource adapter_rom_resources[] = { {
215 .name = "Adapter ROM",
216 .start = 0xc8000,
217 .end = 0,
218 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
219 }, {
220 .name = "Adapter ROM",
221 .start = 0,
222 .end = 0,
223 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
224 }, {
225 .name = "Adapter ROM",
226 .start = 0,
227 .end = 0,
228 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
229 }, {
230 .name = "Adapter ROM",
231 .start = 0,
232 .end = 0,
233 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
234 }, {
235 .name = "Adapter ROM",
236 .start = 0,
237 .end = 0,
238 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
239 }, {
240 .name = "Adapter ROM",
241 .start = 0,
242 .end = 0,
243 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
244 } };
246 #define ADAPTER_ROM_RESOURCES \
247 (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
249 static struct resource video_rom_resource = {
250 .name = "Video ROM",
251 .start = 0xc0000,
252 .end = 0xc7fff,
253 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
254 };
256 static struct resource video_ram_resource = {
257 .name = "Video RAM area",
258 .start = 0xa0000,
259 .end = 0xbffff,
260 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
261 };
263 static struct resource standard_io_resources[] = { {
264 .name = "dma1",
265 .start = 0x0000,
266 .end = 0x001f,
267 .flags = IORESOURCE_BUSY | IORESOURCE_IO
268 }, {
269 .name = "pic1",
270 .start = 0x0020,
271 .end = 0x0021,
272 .flags = IORESOURCE_BUSY | IORESOURCE_IO
273 }, {
274 .name = "timer0",
275 .start = 0x0040,
276 .end = 0x0043,
277 .flags = IORESOURCE_BUSY | IORESOURCE_IO
278 }, {
279 .name = "timer1",
280 .start = 0x0050,
281 .end = 0x0053,
282 .flags = IORESOURCE_BUSY | IORESOURCE_IO
283 }, {
284 .name = "keyboard",
285 .start = 0x0060,
286 .end = 0x0060,
287 .flags = IORESOURCE_BUSY | IORESOURCE_IO
288 }, {
289 .name = "keyboard",
290 .start = 0x0064,
291 .end = 0x0064,
292 .flags = IORESOURCE_BUSY | IORESOURCE_IO
293 }, {
294 .name = "dma page reg",
295 .start = 0x0080,
296 .end = 0x008f,
297 .flags = IORESOURCE_BUSY | IORESOURCE_IO
298 }, {
299 .name = "pic2",
300 .start = 0x00a0,
301 .end = 0x00a1,
302 .flags = IORESOURCE_BUSY | IORESOURCE_IO
303 }, {
304 .name = "dma2",
305 .start = 0x00c0,
306 .end = 0x00df,
307 .flags = IORESOURCE_BUSY | IORESOURCE_IO
308 }, {
309 .name = "fpu",
310 .start = 0x00f0,
311 .end = 0x00ff,
312 .flags = IORESOURCE_BUSY | IORESOURCE_IO
313 } };
315 #define STANDARD_IO_RESOURCES \
316 (sizeof standard_io_resources / sizeof standard_io_resources[0])
318 #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
320 static int __init romchecksum(unsigned char *rom, unsigned long length)
321 {
322 unsigned char *p, sum = 0;
324 for (p = rom; p < rom + length; p++)
325 sum += *p;
326 return sum == 0;
327 }
329 static void __init probe_roms(void)
330 {
331 unsigned long start, length, upper;
332 unsigned char *rom;
333 int i;
335 #ifdef CONFIG_XEN
336 /* Nothing to do if not running in dom0. */
337 if (!is_initial_xendomain())
338 return;
339 #endif
341 /* video rom */
342 upper = adapter_rom_resources[0].start;
343 for (start = video_rom_resource.start; start < upper; start += 2048) {
344 rom = isa_bus_to_virt(start);
345 if (!romsignature(rom))
346 continue;
348 video_rom_resource.start = start;
350 /* 0 < length <= 0x7f * 512, historically */
351 length = rom[2] * 512;
353 /* if checksum okay, trust length byte */
354 if (length && romchecksum(rom, length))
355 video_rom_resource.end = start + length - 1;
357 request_resource(&iomem_resource, &video_rom_resource);
358 break;
359 }
361 start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
362 if (start < upper)
363 start = upper;
365 /* system rom */
366 request_resource(&iomem_resource, &system_rom_resource);
367 upper = system_rom_resource.start;
369 /* check for extension rom (ignore length byte!) */
370 rom = isa_bus_to_virt(extension_rom_resource.start);
371 if (romsignature(rom)) {
372 length = extension_rom_resource.end - extension_rom_resource.start + 1;
373 if (romchecksum(rom, length)) {
374 request_resource(&iomem_resource, &extension_rom_resource);
375 upper = extension_rom_resource.start;
376 }
377 }
379 /* check for adapter roms on 2k boundaries */
380 for (i = 0; i < ADAPTER_ROM_RESOURCES && start < upper; start += 2048) {
381 rom = isa_bus_to_virt(start);
382 if (!romsignature(rom))
383 continue;
385 /* 0 < length <= 0x7f * 512, historically */
386 length = rom[2] * 512;
388 /* but accept any length that fits if checksum okay */
389 if (!length || start + length > upper || !romchecksum(rom, length))
390 continue;
392 adapter_rom_resources[i].start = start;
393 adapter_rom_resources[i].end = start + length - 1;
394 request_resource(&iomem_resource, &adapter_rom_resources[i]);
396 start = adapter_rom_resources[i++].end & ~2047UL;
397 }
398 }
400 /*
401 * Point at the empty zero page to start with. We map the real shared_info
402 * page as soon as fixmap is up and running.
403 */
404 shared_info_t *HYPERVISOR_shared_info = (shared_info_t *)empty_zero_page;
405 EXPORT_SYMBOL(HYPERVISOR_shared_info);
407 unsigned long *phys_to_machine_mapping;
408 unsigned long *pfn_to_mfn_frame_list_list, *pfn_to_mfn_frame_list[16];
409 EXPORT_SYMBOL(phys_to_machine_mapping);
411 /* Raw start-of-day parameters from the hypervisor. */
412 start_info_t *xen_start_info;
413 EXPORT_SYMBOL(xen_start_info);
415 void __init add_memory_region(unsigned long long start,
416 unsigned long long size, int type)
417 {
418 int x;
420 if (!efi_enabled) {
421 x = e820.nr_map;
423 if (x == E820MAX) {
424 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
425 return;
426 }
428 e820.map[x].addr = start;
429 e820.map[x].size = size;
430 e820.map[x].type = type;
431 e820.nr_map++;
432 }
433 } /* add_memory_region */
435 static void __init limit_regions(unsigned long long size)
436 {
437 unsigned long long current_addr = 0;
438 int i;
440 if (efi_enabled) {
441 efi_memory_desc_t *md;
442 void *p;
444 for (p = memmap.map, i = 0; p < memmap.map_end;
445 p += memmap.desc_size, i++) {
446 md = p;
447 current_addr = md->phys_addr + (md->num_pages << 12);
448 if (md->type == EFI_CONVENTIONAL_MEMORY) {
449 if (current_addr >= size) {
450 md->num_pages -=
451 (((current_addr-size) + PAGE_SIZE-1) >> PAGE_SHIFT);
452 memmap.nr_map = i + 1;
453 return;
454 }
455 }
456 }
457 }
458 for (i = 0; i < e820.nr_map; i++) {
459 current_addr = e820.map[i].addr + e820.map[i].size;
460 if (current_addr < size)
461 continue;
463 if (e820.map[i].type != E820_RAM)
464 continue;
466 if (e820.map[i].addr >= size) {
467 /*
468 * This region starts past the end of the
469 * requested size, skip it completely.
470 */
471 e820.nr_map = i;
472 } else {
473 e820.nr_map = i + 1;
474 e820.map[i].size -= current_addr - size;
475 }
476 return;
477 }
478 #ifdef CONFIG_XEN
479 if (i==e820.nr_map && current_addr < size) {
480 /*
481 * The e820 map finished before our requested size so
482 * extend the final entry to the requested address.
483 */
484 --i;
485 if (e820.map[i].type == E820_RAM)
486 e820.map[i].size -= current_addr - size;
487 else
488 add_memory_region(current_addr, size - current_addr, E820_RAM);
489 }
490 #endif
491 }
493 #define E820_DEBUG 1
495 static void __init print_memory_map(char *who)
496 {
497 int i;
499 for (i = 0; i < e820.nr_map; i++) {
500 printk(" %s: %016Lx - %016Lx ", who,
501 e820.map[i].addr,
502 e820.map[i].addr + e820.map[i].size);
503 switch (e820.map[i].type) {
504 case E820_RAM: printk("(usable)\n");
505 break;
506 case E820_RESERVED:
507 printk("(reserved)\n");
508 break;
509 case E820_ACPI:
510 printk("(ACPI data)\n");
511 break;
512 case E820_NVS:
513 printk("(ACPI NVS)\n");
514 break;
515 default: printk("type %lu\n", e820.map[i].type);
516 break;
517 }
518 }
519 }
521 /*
522 * Sanitize the BIOS e820 map.
523 *
524 * Some e820 responses include overlapping entries. The following
525 * replaces the original e820 map with a new one, removing overlaps.
526 *
527 */
528 struct change_member {
529 struct e820entry *pbios; /* pointer to original bios entry */
530 unsigned long long addr; /* address for this change point */
531 };
532 static struct change_member change_point_list[2*E820MAX] __initdata;
533 static struct change_member *change_point[2*E820MAX] __initdata;
534 static struct e820entry *overlap_list[E820MAX] __initdata;
535 static struct e820entry new_bios[E820MAX] __initdata;
537 int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
538 {
539 struct change_member *change_tmp;
540 unsigned long current_type, last_type;
541 unsigned long long last_addr;
542 int chgidx, still_changing;
543 int overlap_entries;
544 int new_bios_entry;
545 int old_nr, new_nr, chg_nr;
546 int i;
548 /*
549 Visually we're performing the following (1,2,3,4 = memory types)...
551 Sample memory map (w/overlaps):
552 ____22__________________
553 ______________________4_
554 ____1111________________
555 _44_____________________
556 11111111________________
557 ____________________33__
558 ___________44___________
559 __________33333_________
560 ______________22________
561 ___________________2222_
562 _________111111111______
563 _____________________11_
564 _________________4______
566 Sanitized equivalent (no overlap):
567 1_______________________
568 _44_____________________
569 ___1____________________
570 ____22__________________
571 ______11________________
572 _________1______________
573 __________3_____________
574 ___________44___________
575 _____________33_________
576 _______________2________
577 ________________1_______
578 _________________4______
579 ___________________2____
580 ____________________33__
581 ______________________4_
582 */
584 /* if there's only one memory region, don't bother */
585 if (*pnr_map < 2)
586 return -1;
588 old_nr = *pnr_map;
590 /* bail out if we find any unreasonable addresses in bios map */
591 for (i=0; i<old_nr; i++)
592 if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
593 return -1;
595 /* create pointers for initial change-point information (for sorting) */
596 for (i=0; i < 2*old_nr; i++)
597 change_point[i] = &change_point_list[i];
599 /* record all known change-points (starting and ending addresses),
600 omitting those that are for empty memory regions */
601 chgidx = 0;
602 for (i=0; i < old_nr; i++) {
603 if (biosmap[i].size != 0) {
604 change_point[chgidx]->addr = biosmap[i].addr;
605 change_point[chgidx++]->pbios = &biosmap[i];
606 change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
607 change_point[chgidx++]->pbios = &biosmap[i];
608 }
609 }
610 chg_nr = chgidx; /* true number of change-points */
612 /* sort change-point list by memory addresses (low -> high) */
613 still_changing = 1;
614 while (still_changing) {
615 still_changing = 0;
616 for (i=1; i < chg_nr; i++) {
617 /* if <current_addr> > <last_addr>, swap */
618 /* or, if current=<start_addr> & last=<end_addr>, swap */
619 if ((change_point[i]->addr < change_point[i-1]->addr) ||
620 ((change_point[i]->addr == change_point[i-1]->addr) &&
621 (change_point[i]->addr == change_point[i]->pbios->addr) &&
622 (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
623 )
624 {
625 change_tmp = change_point[i];
626 change_point[i] = change_point[i-1];
627 change_point[i-1] = change_tmp;
628 still_changing=1;
629 }
630 }
631 }
633 /* create a new bios memory map, removing overlaps */
634 overlap_entries=0; /* number of entries in the overlap table */
635 new_bios_entry=0; /* index for creating new bios map entries */
636 last_type = 0; /* start with undefined memory type */
637 last_addr = 0; /* start with 0 as last starting address */
638 /* loop through change-points, determining affect on the new bios map */
639 for (chgidx=0; chgidx < chg_nr; chgidx++)
640 {
641 /* keep track of all overlapping bios entries */
642 if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
643 {
644 /* add map entry to overlap list (> 1 entry implies an overlap) */
645 overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
646 }
647 else
648 {
649 /* remove entry from list (order independent, so swap with last) */
650 for (i=0; i<overlap_entries; i++)
651 {
652 if (overlap_list[i] == change_point[chgidx]->pbios)
653 overlap_list[i] = overlap_list[overlap_entries-1];
654 }
655 overlap_entries--;
656 }
657 /* if there are overlapping entries, decide which "type" to use */
658 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
659 current_type = 0;
660 for (i=0; i<overlap_entries; i++)
661 if (overlap_list[i]->type > current_type)
662 current_type = overlap_list[i]->type;
663 /* continue building up new bios map based on this information */
664 if (current_type != last_type) {
665 if (last_type != 0) {
666 new_bios[new_bios_entry].size =
667 change_point[chgidx]->addr - last_addr;
668 /* move forward only if the new size was non-zero */
669 if (new_bios[new_bios_entry].size != 0)
670 if (++new_bios_entry >= E820MAX)
671 break; /* no more space left for new bios entries */
672 }
673 if (current_type != 0) {
674 new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
675 new_bios[new_bios_entry].type = current_type;
676 last_addr=change_point[chgidx]->addr;
677 }
678 last_type = current_type;
679 }
680 }
681 new_nr = new_bios_entry; /* retain count for new bios entries */
683 /* copy new bios mapping into original location */
684 memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
685 *pnr_map = new_nr;
687 return 0;
688 }
690 /*
691 * Copy the BIOS e820 map into a safe place.
692 *
693 * Sanity-check it while we're at it..
694 *
695 * If we're lucky and live on a modern system, the setup code
696 * will have given us a memory map that we can use to properly
697 * set up memory. If we aren't, we'll fake a memory map.
698 *
699 * We check to see that the memory map contains at least 2 elements
700 * before we'll use it, because the detection code in setup.S may
701 * not be perfect and most every PC known to man has two memory
702 * regions: one from 0 to 640k, and one from 1mb up. (The IBM
703 * thinkpad 560x, for example, does not cooperate with the memory
704 * detection code.)
705 */
706 int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
707 {
708 #ifndef CONFIG_XEN
709 /* Only one memory region (or negative)? Ignore it */
710 if (nr_map < 2)
711 return -1;
712 #else
713 BUG_ON(nr_map < 1);
714 #endif
716 do {
717 unsigned long long start = biosmap->addr;
718 unsigned long long size = biosmap->size;
719 unsigned long long end = start + size;
720 unsigned long type = biosmap->type;
722 /* Overflow in 64 bits? Ignore the memory map. */
723 if (start > end)
724 return -1;
726 #ifndef CONFIG_XEN
727 /*
728 * Some BIOSes claim RAM in the 640k - 1M region.
729 * Not right. Fix it up.
730 */
731 if (type == E820_RAM) {
732 if (start < 0x100000ULL && end > 0xA0000ULL) {
733 if (start < 0xA0000ULL)
734 add_memory_region(start, 0xA0000ULL-start, type);
735 if (end <= 0x100000ULL)
736 continue;
737 start = 0x100000ULL;
738 size = end - start;
739 }
740 }
741 #endif
742 add_memory_region(start, size, type);
743 } while (biosmap++,--nr_map);
745 #ifdef CONFIG_XEN
746 if (is_initial_xendomain()) {
747 struct xen_memory_map memmap;
749 memmap.nr_entries = E820MAX;
750 set_xen_guest_handle(memmap.buffer, machine_e820.map);
752 if (HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap))
753 BUG();
754 machine_e820.nr_map = memmap.nr_entries;
755 } else
756 machine_e820 = e820;
757 #endif
759 return 0;
760 }
762 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
763 struct edd edd;
764 #ifdef CONFIG_EDD_MODULE
765 EXPORT_SYMBOL(edd);
766 #endif
767 #ifndef CONFIG_XEN
768 /**
769 * copy_edd() - Copy the BIOS EDD information
770 * from boot_params into a safe place.
771 *
772 */
773 static inline void copy_edd(void)
774 {
775 memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
776 memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
777 edd.mbr_signature_nr = EDD_MBR_SIG_NR;
778 edd.edd_info_nr = EDD_NR;
779 }
780 #endif
781 #else
782 static inline void copy_edd(void)
783 {
784 }
785 #endif
787 static void __init parse_cmdline_early (char ** cmdline_p)
788 {
789 char c = ' ', *to = command_line, *from = saved_command_line;
790 int len = 0, max_cmdline;
791 int userdef = 0;
793 if ((max_cmdline = MAX_GUEST_CMDLINE) > COMMAND_LINE_SIZE)
794 max_cmdline = COMMAND_LINE_SIZE;
795 memcpy(saved_command_line, xen_start_info->cmd_line, max_cmdline);
796 /* Save unparsed command line copy for /proc/cmdline */
797 saved_command_line[max_cmdline-1] = '\0';
799 for (;;) {
800 if (c != ' ')
801 goto next_char;
802 /*
803 * "mem=nopentium" disables the 4MB page tables.
804 * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
805 * to <mem>, overriding the bios size.
806 * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
807 * <start> to <start>+<mem>, overriding the bios size.
808 *
809 * HPA tells me bootloaders need to parse mem=, so no new
810 * option should be mem= [also see Documentation/i386/boot.txt]
811 */
812 if (!memcmp(from, "mem=", 4)) {
813 if (to != command_line)
814 to--;
815 if (!memcmp(from+4, "nopentium", 9)) {
816 from += 9+4;
817 clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
818 disable_pse = 1;
819 } else {
820 /* If the user specifies memory size, we
821 * limit the BIOS-provided memory map to
822 * that size. exactmap can be used to specify
823 * the exact map. mem=number can be used to
824 * trim the existing memory map.
825 */
826 unsigned long long mem_size;
828 mem_size = memparse(from+4, &from);
829 limit_regions(mem_size);
830 userdef=1;
831 }
832 }
834 else if (!memcmp(from, "memmap=", 7)) {
835 if (to != command_line)
836 to--;
837 if (!memcmp(from+7, "exactmap", 8)) {
838 #ifdef CONFIG_CRASH_DUMP
839 /* If we are doing a crash dump, we
840 * still need to know the real mem
841 * size before original memory map is
842 * reset.
843 */
844 find_max_pfn();
845 saved_max_pfn = max_pfn;
846 #endif
847 from += 8+7;
848 e820.nr_map = 0;
849 userdef = 1;
850 } else {
851 /* If the user specifies memory size, we
852 * limit the BIOS-provided memory map to
853 * that size. exactmap can be used to specify
854 * the exact map. mem=number can be used to
855 * trim the existing memory map.
856 */
857 unsigned long long start_at, mem_size;
859 mem_size = memparse(from+7, &from);
860 if (*from == '@') {
861 start_at = memparse(from+1, &from);
862 add_memory_region(start_at, mem_size, E820_RAM);
863 } else if (*from == '#') {
864 start_at = memparse(from+1, &from);
865 add_memory_region(start_at, mem_size, E820_ACPI);
866 } else if (*from == '$') {
867 start_at = memparse(from+1, &from);
868 add_memory_region(start_at, mem_size, E820_RESERVED);
869 } else {
870 limit_regions(mem_size);
871 userdef=1;
872 }
873 }
874 }
876 else if (!memcmp(from, "noexec=", 7))
877 noexec_setup(from + 7);
880 #ifdef CONFIG_X86_MPPARSE
881 /*
882 * If the BIOS enumerates physical processors before logical,
883 * maxcpus=N at enumeration-time can be used to disable HT.
884 */
885 else if (!memcmp(from, "maxcpus=", 8)) {
886 extern unsigned int maxcpus;
888 maxcpus = simple_strtoul(from + 8, NULL, 0);
889 }
890 #endif
892 #ifdef CONFIG_ACPI
893 /* "acpi=off" disables both ACPI table parsing and interpreter */
894 else if (!memcmp(from, "acpi=off", 8)) {
895 disable_acpi();
896 }
898 /* acpi=force to over-ride black-list */
899 else if (!memcmp(from, "acpi=force", 10)) {
900 acpi_force = 1;
901 acpi_ht = 1;
902 acpi_disabled = 0;
903 }
905 /* acpi=strict disables out-of-spec workarounds */
906 else if (!memcmp(from, "acpi=strict", 11)) {
907 acpi_strict = 1;
908 }
910 /* Limit ACPI just to boot-time to enable HT */
911 else if (!memcmp(from, "acpi=ht", 7)) {
912 if (!acpi_force)
913 disable_acpi();
914 acpi_ht = 1;
915 }
917 /* "pci=noacpi" disable ACPI IRQ routing and PCI scan */
918 else if (!memcmp(from, "pci=noacpi", 10)) {
919 acpi_disable_pci();
920 }
921 /* "acpi=noirq" disables ACPI interrupt routing */
922 else if (!memcmp(from, "acpi=noirq", 10)) {
923 acpi_noirq_set();
924 }
926 else if (!memcmp(from, "acpi_sci=edge", 13))
927 acpi_sci_flags.trigger = 1;
929 else if (!memcmp(from, "acpi_sci=level", 14))
930 acpi_sci_flags.trigger = 3;
932 else if (!memcmp(from, "acpi_sci=high", 13))
933 acpi_sci_flags.polarity = 1;
935 else if (!memcmp(from, "acpi_sci=low", 12))
936 acpi_sci_flags.polarity = 3;
938 #ifdef CONFIG_X86_IO_APIC
939 else if (!memcmp(from, "acpi_skip_timer_override", 24))
940 acpi_skip_timer_override = 1;
942 if (!memcmp(from, "disable_timer_pin_1", 19))
943 disable_timer_pin_1 = 1;
944 if (!memcmp(from, "enable_timer_pin_1", 18))
945 disable_timer_pin_1 = -1;
947 /* disable IO-APIC */
948 else if (!memcmp(from, "noapic", 6))
949 disable_ioapic_setup();
950 #endif /* CONFIG_X86_IO_APIC */
951 #endif /* CONFIG_ACPI */
953 #ifdef CONFIG_X86_LOCAL_APIC
954 /* enable local APIC */
955 else if (!memcmp(from, "lapic", 5))
956 lapic_enable();
958 /* disable local APIC */
959 else if (!memcmp(from, "nolapic", 6))
960 lapic_disable();
961 #endif /* CONFIG_X86_LOCAL_APIC */
963 #ifdef CONFIG_KEXEC
964 /* crashkernel=size@addr specifies the location to reserve for
965 * a crash kernel. By reserving this memory we guarantee
966 * that linux never set's it up as a DMA target.
967 * Useful for holding code to do something appropriate
968 * after a kernel panic.
969 */
970 else if (!memcmp(from, "crashkernel=", 12)) {
971 #ifndef CONFIG_XEN
972 unsigned long size, base;
973 size = memparse(from+12, &from);
974 if (*from == '@') {
975 base = memparse(from+1, &from);
976 /* FIXME: Do I want a sanity check
977 * to validate the memory range?
978 */
979 crashk_res.start = base;
980 crashk_res.end = base + size - 1;
981 }
982 #else
983 printk("Ignoring crashkernel command line, "
984 "parameter will be supplied by xen\n");
985 #endif
986 }
987 #endif
988 #ifdef CONFIG_PROC_VMCORE
989 /* elfcorehdr= specifies the location of elf core header
990 * stored by the crashed kernel.
991 */
992 else if (!memcmp(from, "elfcorehdr=", 11))
993 elfcorehdr_addr = memparse(from+11, &from);
994 #endif
996 /*
997 * highmem=size forces highmem to be exactly 'size' bytes.
998 * This works even on boxes that have no highmem otherwise.
999 * This also works to reduce highmem size on bigger boxes.
1000 */
1001 else if (!memcmp(from, "highmem=", 8))
1002 highmem_pages = memparse(from+8, &from) >> PAGE_SHIFT;
1004 /*
1005 * vmalloc=size forces the vmalloc area to be exactly 'size'
1006 * bytes. This can be used to increase (or decrease) the
1007 * vmalloc area - the default is 128m.
1008 */
1009 else if (!memcmp(from, "vmalloc=", 8))
1010 __VMALLOC_RESERVE = memparse(from+8, &from);
1012 next_char:
1013 c = *(from++);
1014 if (!c)
1015 break;
1016 if (COMMAND_LINE_SIZE <= ++len)
1017 break;
1018 *(to++) = c;
1020 *to = '\0';
1021 *cmdline_p = command_line;
1022 if (userdef) {
1023 printk(KERN_INFO "user-defined physical RAM map:\n");
1024 print_memory_map("user");
1028 /*
1029 * Callback for efi_memory_walk.
1030 */
1031 static int __init
1032 efi_find_max_pfn(unsigned long start, unsigned long end, void *arg)
1034 unsigned long *max_pfn = arg, pfn;
1036 if (start < end) {
1037 pfn = PFN_UP(end -1);
1038 if (pfn > *max_pfn)
1039 *max_pfn = pfn;
1041 return 0;
1044 static int __init
1045 efi_memory_present_wrapper(unsigned long start, unsigned long end, void *arg)
1047 memory_present(0, start, end);
1048 return 0;
1051 /*
1052 * This function checks if any part of the range <start,end> is mapped
1053 * with type.
1054 */
1055 int
1056 e820_any_mapped(u64 start, u64 end, unsigned type)
1058 int i;
1060 #ifndef CONFIG_XEN
1061 for (i = 0; i < e820.nr_map; i++) {
1062 const struct e820entry *ei = &e820.map[i];
1063 #else
1064 if (!is_initial_xendomain())
1065 return 0;
1066 for (i = 0; i < machine_e820.nr_map; ++i) {
1067 const struct e820entry *ei = &machine_e820.map[i];
1068 #endif
1070 if (type && ei->type != type)
1071 continue;
1072 if (ei->addr >= end || ei->addr + ei->size <= start)
1073 continue;
1074 return 1;
1076 return 0;
1078 EXPORT_SYMBOL_GPL(e820_any_mapped);
1080 /*
1081 * This function checks if the entire range <start,end> is mapped with type.
1083 * Note: this function only works correct if the e820 table is sorted and
1084 * not-overlapping, which is the case
1085 */
1086 int __init
1087 e820_all_mapped(unsigned long s, unsigned long e, unsigned type)
1089 u64 start = s;
1090 u64 end = e;
1091 int i;
1093 #ifndef CONFIG_XEN
1094 for (i = 0; i < e820.nr_map; i++) {
1095 struct e820entry *ei = &e820.map[i];
1096 #else
1097 if (!is_initial_xendomain())
1098 return 0;
1099 for (i = 0; i < machine_e820.nr_map; ++i) {
1100 const struct e820entry *ei = &machine_e820.map[i];
1101 #endif
1102 if (type && ei->type != type)
1103 continue;
1104 /* is the region (part) in overlap with the current region ?*/
1105 if (ei->addr >= end || ei->addr + ei->size <= start)
1106 continue;
1107 /* if the region is at the beginning of <start,end> we move
1108 * start to the end of the region since it's ok until there
1109 */
1110 if (ei->addr <= start)
1111 start = ei->addr + ei->size;
1112 /* if start is now at or beyond end, we're done, full
1113 * coverage */
1114 if (start >= end)
1115 return 1; /* we're done */
1117 return 0;
1120 /*
1121 * Find the highest page frame number we have available
1122 */
1123 void __init find_max_pfn(void)
1125 int i;
1127 max_pfn = 0;
1128 if (efi_enabled) {
1129 efi_memmap_walk(efi_find_max_pfn, &max_pfn);
1130 efi_memmap_walk(efi_memory_present_wrapper, NULL);
1131 return;
1134 for (i = 0; i < e820.nr_map; i++) {
1135 unsigned long start, end;
1136 /* RAM? */
1137 if (e820.map[i].type != E820_RAM)
1138 continue;
1139 start = PFN_UP(e820.map[i].addr);
1140 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
1141 if (start >= end)
1142 continue;
1143 if (end > max_pfn)
1144 max_pfn = end;
1145 memory_present(0, start, end);
1149 /*
1150 * Determine low and high memory ranges:
1151 */
1152 unsigned long __init find_max_low_pfn(void)
1154 unsigned long max_low_pfn;
1156 max_low_pfn = max_pfn;
1157 if (max_low_pfn > MAXMEM_PFN) {
1158 if (highmem_pages == -1)
1159 highmem_pages = max_pfn - MAXMEM_PFN;
1160 if (highmem_pages + MAXMEM_PFN < max_pfn)
1161 max_pfn = MAXMEM_PFN + highmem_pages;
1162 if (highmem_pages + MAXMEM_PFN > max_pfn) {
1163 printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
1164 highmem_pages = 0;
1166 max_low_pfn = MAXMEM_PFN;
1167 #ifndef CONFIG_HIGHMEM
1168 /* Maximum memory usable is what is directly addressable */
1169 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
1170 MAXMEM>>20);
1171 if (max_pfn > MAX_NONPAE_PFN)
1172 printk(KERN_WARNING "Use a PAE enabled kernel.\n");
1173 else
1174 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
1175 max_pfn = MAXMEM_PFN;
1176 #else /* !CONFIG_HIGHMEM */
1177 #ifndef CONFIG_X86_PAE
1178 if (max_pfn > MAX_NONPAE_PFN) {
1179 max_pfn = MAX_NONPAE_PFN;
1180 printk(KERN_WARNING "Warning only 4GB will be used.\n");
1181 printk(KERN_WARNING "Use a PAE enabled kernel.\n");
1183 #endif /* !CONFIG_X86_PAE */
1184 #endif /* !CONFIG_HIGHMEM */
1185 } else {
1186 if (highmem_pages == -1)
1187 highmem_pages = 0;
1188 #ifdef CONFIG_HIGHMEM
1189 if (highmem_pages >= max_pfn) {
1190 printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
1191 highmem_pages = 0;
1193 if (highmem_pages) {
1194 if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
1195 printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
1196 highmem_pages = 0;
1198 max_low_pfn -= highmem_pages;
1200 #else
1201 if (highmem_pages)
1202 printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
1203 #endif
1205 return max_low_pfn;
1208 /*
1209 * Free all available memory for boot time allocation. Used
1210 * as a callback function by efi_memory_walk()
1211 */
1213 static int __init
1214 free_available_memory(unsigned long start, unsigned long end, void *arg)
1216 /* check max_low_pfn */
1217 if (start >= (max_low_pfn << PAGE_SHIFT))
1218 return 0;
1219 if (end >= (max_low_pfn << PAGE_SHIFT))
1220 end = max_low_pfn << PAGE_SHIFT;
1221 if (start < end)
1222 free_bootmem(start, end - start);
1224 return 0;
1226 /*
1227 * Register fully available low RAM pages with the bootmem allocator.
1228 */
1229 static void __init register_bootmem_low_pages(unsigned long max_low_pfn)
1231 int i;
1233 if (efi_enabled) {
1234 efi_memmap_walk(free_available_memory, NULL);
1235 return;
1237 for (i = 0; i < e820.nr_map; i++) {
1238 unsigned long curr_pfn, last_pfn, size;
1239 /*
1240 * Reserve usable low memory
1241 */
1242 if (e820.map[i].type != E820_RAM)
1243 continue;
1244 /*
1245 * We are rounding up the start address of usable memory:
1246 */
1247 curr_pfn = PFN_UP(e820.map[i].addr);
1248 if (curr_pfn >= max_low_pfn)
1249 continue;
1250 /*
1251 * ... and at the end of the usable range downwards:
1252 */
1253 last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
1255 #ifdef CONFIG_XEN
1256 /*
1257 * Truncate to the number of actual pages currently
1258 * present.
1259 */
1260 if (last_pfn > xen_start_info->nr_pages)
1261 last_pfn = xen_start_info->nr_pages;
1262 #endif
1264 if (last_pfn > max_low_pfn)
1265 last_pfn = max_low_pfn;
1267 /*
1268 * .. finally, did all the rounding and playing
1269 * around just make the area go away?
1270 */
1271 if (last_pfn <= curr_pfn)
1272 continue;
1274 size = last_pfn - curr_pfn;
1275 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
1279 #ifndef CONFIG_XEN
1280 /*
1281 * workaround for Dell systems that neglect to reserve EBDA
1282 */
1283 static void __init reserve_ebda_region(void)
1285 unsigned int addr;
1286 addr = get_bios_ebda();
1287 if (addr)
1288 reserve_bootmem(addr, PAGE_SIZE);
1290 #endif
1292 #ifndef CONFIG_NEED_MULTIPLE_NODES
1293 void __init setup_bootmem_allocator(void);
1294 static unsigned long __init setup_memory(void)
1296 /*
1297 * partially used pages are not usable - thus
1298 * we are rounding upwards:
1299 */
1300 min_low_pfn = PFN_UP(__pa(xen_start_info->pt_base)) +
1301 xen_start_info->nr_pt_frames;
1303 find_max_pfn();
1305 max_low_pfn = find_max_low_pfn();
1307 #ifdef CONFIG_HIGHMEM
1308 highstart_pfn = highend_pfn = max_pfn;
1309 if (max_pfn > max_low_pfn) {
1310 highstart_pfn = max_low_pfn;
1312 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
1313 pages_to_mb(highend_pfn - highstart_pfn));
1314 #endif
1315 printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
1316 pages_to_mb(max_low_pfn));
1318 setup_bootmem_allocator();
1320 return max_low_pfn;
1323 void __init zone_sizes_init(void)
1325 unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
1326 unsigned int max_dma, low;
1328 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
1329 low = max_low_pfn;
1331 if (low < max_dma)
1332 zones_size[ZONE_DMA] = low;
1333 else {
1334 zones_size[ZONE_DMA] = max_dma;
1335 zones_size[ZONE_NORMAL] = low - max_dma;
1336 #ifdef CONFIG_HIGHMEM
1337 zones_size[ZONE_HIGHMEM] = highend_pfn - low;
1338 #endif
1340 free_area_init(zones_size);
1342 #else
1343 extern unsigned long __init setup_memory(void);
1344 extern void zone_sizes_init(void);
1345 #endif /* !CONFIG_NEED_MULTIPLE_NODES */
1347 void __init setup_bootmem_allocator(void)
1349 unsigned long bootmap_size;
1350 /*
1351 * Initialize the boot-time allocator (with low memory only):
1352 */
1353 bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
1355 register_bootmem_low_pages(max_low_pfn);
1357 /*
1358 * Reserve the bootmem bitmap itself as well. We do this in two
1359 * steps (first step was init_bootmem()) because this catches
1360 * the (very unlikely) case of us accidentally initializing the
1361 * bootmem allocator with an invalid RAM area.
1362 */
1363 reserve_bootmem(__PHYSICAL_START, (PFN_PHYS(min_low_pfn) +
1364 bootmap_size + PAGE_SIZE-1) - (__PHYSICAL_START));
1366 #ifndef CONFIG_XEN
1367 /*
1368 * reserve physical page 0 - it's a special BIOS page on many boxes,
1369 * enabling clean reboots, SMP operation, laptop functions.
1370 */
1371 reserve_bootmem(0, PAGE_SIZE);
1373 /* reserve EBDA region, it's a 4K region */
1374 reserve_ebda_region();
1376 /* could be an AMD 768MPX chipset. Reserve a page before VGA to prevent
1377 PCI prefetch into it (errata #56). Usually the page is reserved anyways,
1378 unless you have no PS/2 mouse plugged in. */
1379 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
1380 boot_cpu_data.x86 == 6)
1381 reserve_bootmem(0xa0000 - 4096, 4096);
1383 #ifdef CONFIG_SMP
1384 /*
1385 * But first pinch a few for the stack/trampoline stuff
1386 * FIXME: Don't need the extra page at 4K, but need to fix
1387 * trampoline before removing it. (see the GDT stuff)
1388 */
1389 reserve_bootmem(PAGE_SIZE, PAGE_SIZE);
1390 #endif
1391 #ifdef CONFIG_ACPI_SLEEP
1392 /*
1393 * Reserve low memory region for sleep support.
1394 */
1395 acpi_reserve_bootmem();
1396 #endif
1397 #endif /* !CONFIG_XEN */
1399 #ifdef CONFIG_BLK_DEV_INITRD
1400 if (xen_start_info->mod_start) {
1401 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
1402 /*reserve_bootmem(INITRD_START, INITRD_SIZE);*/
1403 initrd_start = INITRD_START + PAGE_OFFSET;
1404 initrd_end = initrd_start+INITRD_SIZE;
1405 initrd_below_start_ok = 1;
1407 else {
1408 printk(KERN_ERR "initrd extends beyond end of memory "
1409 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
1410 INITRD_START + INITRD_SIZE,
1411 max_low_pfn << PAGE_SHIFT);
1412 initrd_start = 0;
1415 #endif
1416 #ifdef CONFIG_KEXEC
1417 #ifdef CONFIG_XEN
1418 xen_machine_kexec_setup_resources();
1419 #else
1420 if (crashk_res.start != crashk_res.end)
1421 reserve_bootmem(crashk_res.start,
1422 crashk_res.end - crashk_res.start + 1);
1423 #endif
1424 #endif
1427 /*
1428 * The node 0 pgdat is initialized before all of these because
1429 * it's needed for bootmem. node>0 pgdats have their virtual
1430 * space allocated before the pagetables are in place to access
1431 * them, so they can't be cleared then.
1433 * This should all compile down to nothing when NUMA is off.
1434 */
1435 void __init remapped_pgdat_init(void)
1437 int nid;
1439 for_each_online_node(nid) {
1440 if (nid != 0)
1441 memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
1445 /*
1446 * Request address space for all standard RAM and ROM resources
1447 * and also for regions reported as reserved by the e820.
1448 */
1449 static void __init
1450 legacy_init_iomem_resources(struct e820entry *e820, int nr_map,
1451 struct resource *code_resource,
1452 struct resource *data_resource)
1454 int i;
1456 probe_roms();
1458 for (i = 0; i < nr_map; i++) {
1459 struct resource *res;
1460 #ifndef CONFIG_RESOURCES_64BIT
1461 if (e820[i].addr + e820[i].size > 0x100000000ULL)
1462 continue;
1463 #endif
1464 res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
1465 switch (e820[i].type) {
1466 case E820_RAM: res->name = "System RAM"; break;
1467 case E820_ACPI: res->name = "ACPI Tables"; break;
1468 case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
1469 default: res->name = "reserved";
1471 res->start = e820[i].addr;
1472 res->end = res->start + e820[i].size - 1;
1473 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
1474 if (request_resource(&iomem_resource, res)) {
1475 kfree(res);
1476 continue;
1478 if (e820[i].type == E820_RAM) {
1479 /*
1480 * We don't know which RAM region contains kernel data,
1481 * so we try it repeatedly and let the resource manager
1482 * test it.
1483 */
1484 #ifndef CONFIG_XEN
1485 request_resource(res, code_resource);
1486 request_resource(res, data_resource);
1487 #endif
1488 #ifdef CONFIG_KEXEC
1489 if (crashk_res.start != crashk_res.end)
1490 request_resource(res, &crashk_res);
1491 #ifdef CONFIG_XEN
1492 xen_machine_kexec_register_resources(res);
1493 #endif
1494 #endif
1499 /*
1500 * Locate a unused range of the physical address space below 4G which
1501 * can be used for PCI mappings.
1502 */
1503 static void __init
1504 e820_setup_gap(struct e820entry *e820, int nr_map)
1506 unsigned long gapstart, gapsize, round;
1507 unsigned long long last;
1508 int i;
1510 /*
1511 * Search for the bigest gap in the low 32 bits of the e820
1512 * memory space.
1513 */
1514 last = 0x100000000ull;
1515 gapstart = 0x10000000;
1516 gapsize = 0x400000;
1517 i = nr_map;
1518 while (--i >= 0) {
1519 unsigned long long start = e820[i].addr;
1520 unsigned long long end = start + e820[i].size;
1522 /*
1523 * Since "last" is at most 4GB, we know we'll
1524 * fit in 32 bits if this condition is true
1525 */
1526 if (last > end) {
1527 unsigned long gap = last - end;
1529 if (gap > gapsize) {
1530 gapsize = gap;
1531 gapstart = end;
1534 if (start < last)
1535 last = start;
1538 /*
1539 * See how much we want to round up: start off with
1540 * rounding to the next 1MB area.
1541 */
1542 round = 0x100000;
1543 while ((gapsize >> 4) > round)
1544 round += round;
1545 /* Fun with two's complement */
1546 pci_mem_start = (gapstart + round) & -round;
1548 printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
1549 pci_mem_start, gapstart, gapsize);
1552 /*
1553 * Request address space for all standard resources
1555 * This is called just before pcibios_init(), which is also a
1556 * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
1557 */
1558 static int __init request_standard_resources(void)
1560 int i;
1562 /* Nothing to do if not running in dom0. */
1563 if (!is_initial_xendomain())
1564 return 0;
1566 printk("Setting up standard PCI resources\n");
1567 #ifdef CONFIG_XEN
1568 legacy_init_iomem_resources(machine_e820.map, machine_e820.nr_map,
1569 &code_resource, &data_resource);
1570 #else
1571 if (efi_enabled)
1572 efi_initialize_iomem_resources(&code_resource, &data_resource);
1573 else
1574 legacy_init_iomem_resources(e820.map, e820.nr_map,
1575 &code_resource, &data_resource);
1576 #endif
1578 /* EFI systems may still have VGA */
1579 request_resource(&iomem_resource, &video_ram_resource);
1581 /* request I/O space for devices used on all i[345]86 PCs */
1582 for (i = 0; i < STANDARD_IO_RESOURCES; i++)
1583 request_resource(&ioport_resource, &standard_io_resources[i]);
1584 return 0;
1587 subsys_initcall(request_standard_resources);
1589 static void __init register_memory(void)
1591 #ifdef CONFIG_XEN
1592 if (is_initial_xendomain())
1593 e820_setup_gap(machine_e820.map, machine_e820.nr_map);
1594 else
1595 #endif
1596 e820_setup_gap(e820.map, e820.nr_map);
1599 #ifdef CONFIG_MCA
1600 static void set_mca_bus(int x)
1602 MCA_bus = x;
1604 #else
1605 static void set_mca_bus(int x) { }
1606 #endif
1608 /*
1609 * Determine if we were loaded by an EFI loader. If so, then we have also been
1610 * passed the efi memmap, systab, etc., so we should use these data structures
1611 * for initialization. Note, the efi init code path is determined by the
1612 * global efi_enabled. This allows the same kernel image to be used on existing
1613 * systems (with a traditional BIOS) as well as on EFI systems.
1614 */
1615 void __init setup_arch(char **cmdline_p)
1617 int i, j, k, fpp;
1618 struct physdev_set_iopl set_iopl;
1619 unsigned long max_low_pfn;
1620 unsigned long p2m_pages;
1622 /* Force a quick death if the kernel panics (not domain 0). */
1623 extern int panic_timeout;
1624 if (!panic_timeout && !is_initial_xendomain())
1625 panic_timeout = 1;
1627 /* Register a call for panic conditions. */
1628 atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
1630 WARN_ON(HYPERVISOR_vm_assist(VMASST_CMD_enable,
1631 VMASST_TYPE_4gb_segments));
1632 WARN_ON(HYPERVISOR_vm_assist(VMASST_CMD_enable,
1633 VMASST_TYPE_writable_pagetables));
1635 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
1636 pre_setup_arch_hook();
1637 early_cpu_init();
1638 #ifdef CONFIG_SMP
1639 prefill_possible_map();
1640 #endif
1642 /*
1643 * FIXME: This isn't an official loader_type right
1644 * now but does currently work with elilo.
1645 * If we were configured as an EFI kernel, check to make
1646 * sure that we were loaded correctly from elilo and that
1647 * the system table is valid. If not, then initialize normally.
1648 */
1649 #ifdef CONFIG_EFI
1650 if ((LOADER_TYPE == 0x50) && EFI_SYSTAB)
1651 efi_enabled = 1;
1652 #endif
1654 /* This must be initialized to UNNAMED_MAJOR for ipconfig to work
1655 properly. Setting ROOT_DEV to default to /dev/ram0 breaks initrd.
1656 */
1657 ROOT_DEV = MKDEV(UNNAMED_MAJOR,0);
1658 drive_info = DRIVE_INFO;
1659 screen_info = SCREEN_INFO;
1660 copy_edid();
1661 apm_info.bios = APM_BIOS_INFO;
1662 ist_info = IST_INFO;
1663 saved_videomode = VIDEO_MODE;
1664 if( SYS_DESC_TABLE.length != 0 ) {
1665 set_mca_bus(SYS_DESC_TABLE.table[3] & 0x2);
1666 machine_id = SYS_DESC_TABLE.table[0];
1667 machine_submodel_id = SYS_DESC_TABLE.table[1];
1668 BIOS_revision = SYS_DESC_TABLE.table[2];
1670 bootloader_type = LOADER_TYPE;
1672 if (is_initial_xendomain()) {
1673 const struct dom0_vga_console_info *info =
1674 (void *)((char *)xen_start_info +
1675 xen_start_info->console.dom0.info_off);
1677 dom0_init_screen_info(info,
1678 xen_start_info->console.dom0.info_size);
1679 xen_start_info->console.domU.mfn = 0;
1680 xen_start_info->console.domU.evtchn = 0;
1681 } else
1682 screen_info.orig_video_isVGA = 0;
1684 #ifdef CONFIG_BLK_DEV_RAM
1685 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
1686 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
1687 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
1688 #endif
1690 ARCH_SETUP
1691 if (efi_enabled)
1692 efi_init();
1693 else {
1694 printk(KERN_INFO "BIOS-provided physical RAM map:\n");
1695 print_memory_map(machine_specific_memory_setup());
1698 copy_edd();
1700 if (!MOUNT_ROOT_RDONLY)
1701 root_mountflags &= ~MS_RDONLY;
1702 init_mm.start_code = (unsigned long) _text;
1703 init_mm.end_code = (unsigned long) _etext;
1704 init_mm.end_data = (unsigned long) _edata;
1705 init_mm.brk = (PFN_UP(__pa(xen_start_info->pt_base)) +
1706 xen_start_info->nr_pt_frames) << PAGE_SHIFT;
1708 code_resource.start = virt_to_phys(_text);
1709 code_resource.end = virt_to_phys(_etext)-1;
1710 data_resource.start = virt_to_phys(_etext);
1711 data_resource.end = virt_to_phys(_edata)-1;
1713 parse_cmdline_early(cmdline_p);
1715 #ifdef CONFIG_EARLY_PRINTK
1717 char *s = strstr(*cmdline_p, "earlyprintk=");
1718 if (s) {
1719 setup_early_printk(strchr(s, '=') + 1);
1720 printk("early console enabled\n");
1723 #endif
1725 max_low_pfn = setup_memory();
1727 /*
1728 * NOTE: before this point _nobody_ is allowed to allocate
1729 * any memory using the bootmem allocator. Although the
1730 * alloctor is now initialised only the first 8Mb of the kernel
1731 * virtual address space has been mapped. All allocations before
1732 * paging_init() has completed must use the alloc_bootmem_low_pages()
1733 * variant (which allocates DMA'able memory) and care must be taken
1734 * not to exceed the 8Mb limit.
1735 */
1737 #ifdef CONFIG_SMP
1738 smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
1739 #endif
1740 paging_init();
1741 remapped_pgdat_init();
1742 sparse_init();
1743 zone_sizes_init();
1745 #ifdef CONFIG_X86_FIND_SMP_CONFIG
1746 /*
1747 * Find and reserve possible boot-time SMP configuration:
1748 */
1749 find_smp_config();
1750 #endif
1752 p2m_pages = max_pfn;
1753 if (xen_start_info->nr_pages > max_pfn) {
1754 /*
1755 * the max_pfn was shrunk (probably by mem= or highmem=
1756 * kernel parameter); shrink reservation with the HV
1757 */
1758 struct xen_memory_reservation reservation = {
1759 .address_bits = 0,
1760 .extent_order = 0,
1761 .domid = DOMID_SELF
1762 };
1763 unsigned int difference;
1764 int ret;
1766 difference = xen_start_info->nr_pages - max_pfn;
1768 set_xen_guest_handle(reservation.extent_start,
1769 ((unsigned long *)xen_start_info->mfn_list) + max_pfn);
1770 reservation.nr_extents = difference;
1771 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
1772 &reservation);
1773 BUG_ON (ret != difference);
1775 else if (max_pfn > xen_start_info->nr_pages)
1776 p2m_pages = xen_start_info->nr_pages;
1778 /* Make sure we have a correctly sized P->M table. */
1779 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1780 phys_to_machine_mapping = alloc_bootmem_low_pages(
1781 max_pfn * sizeof(unsigned long));
1782 memset(phys_to_machine_mapping, ~0,
1783 max_pfn * sizeof(unsigned long));
1784 memcpy(phys_to_machine_mapping,
1785 (unsigned long *)xen_start_info->mfn_list,
1786 p2m_pages * sizeof(unsigned long));
1787 free_bootmem(
1788 __pa(xen_start_info->mfn_list),
1789 PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
1790 sizeof(unsigned long))));
1792 /*
1793 * Initialise the list of the frames that specify the list of
1794 * frames that make up the p2m table. Used by save/restore
1795 */
1796 pfn_to_mfn_frame_list_list = alloc_bootmem_low_pages(PAGE_SIZE);
1798 fpp = PAGE_SIZE/sizeof(unsigned long);
1799 for (i=0, j=0, k=-1; i< max_pfn; i+=fpp, j++) {
1800 if ((j % fpp) == 0) {
1801 k++;
1802 BUG_ON(k>=16);
1803 pfn_to_mfn_frame_list[k] =
1804 alloc_bootmem_low_pages(PAGE_SIZE);
1805 pfn_to_mfn_frame_list_list[k] =
1806 virt_to_mfn(pfn_to_mfn_frame_list[k]);
1807 j=0;
1809 pfn_to_mfn_frame_list[k][j] =
1810 virt_to_mfn(&phys_to_machine_mapping[i]);
1812 HYPERVISOR_shared_info->arch.max_pfn = max_pfn;
1813 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
1814 virt_to_mfn(pfn_to_mfn_frame_list_list);
1817 /* Mark all ISA DMA channels in-use - using them wouldn't work. */
1818 for (i = 0; i < MAX_DMA_CHANNELS; ++i)
1819 if (i != 4 && request_dma(i, "xen") != 0)
1820 BUG();
1822 /*
1823 * NOTE: at this point the bootmem allocator is fully available.
1824 */
1826 if (is_initial_xendomain())
1827 dmi_scan_machine();
1829 #ifdef CONFIG_X86_GENERICARCH
1830 generic_apic_probe(*cmdline_p);
1831 #endif
1832 if (efi_enabled)
1833 efi_map_memmap();
1835 set_iopl.iopl = 1;
1836 WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl));
1838 #ifdef CONFIG_ACPI
1839 if (!is_initial_xendomain()) {
1840 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
1841 acpi_disabled = 1;
1842 acpi_ht = 0;
1845 /*
1846 * Parse the ACPI tables for possible boot-time SMP configuration.
1847 */
1848 acpi_boot_table_init();
1849 #endif
1851 #ifdef CONFIG_X86_IO_APIC
1852 check_acpi_pci(); /* Checks more than just ACPI actually */
1853 #endif
1855 #ifdef CONFIG_ACPI
1856 acpi_boot_init();
1858 #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
1859 if (def_to_bigsmp)
1860 printk(KERN_WARNING "More than 8 CPUs detected and "
1861 "CONFIG_X86_PC cannot handle it.\nUse "
1862 "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
1863 #endif
1864 #endif
1865 #ifdef CONFIG_X86_LOCAL_APIC
1866 if (smp_found_config)
1867 get_smp_config();
1868 #endif
1870 register_memory();
1872 if (is_initial_xendomain()) {
1873 #ifdef CONFIG_VT
1874 #if defined(CONFIG_VGA_CONSOLE)
1875 if (!efi_enabled ||
1876 (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
1877 conswitchp = &vga_con;
1878 #elif defined(CONFIG_DUMMY_CONSOLE)
1879 conswitchp = &dummy_con;
1880 #endif
1881 #endif
1882 } else {
1883 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
1884 conswitchp = &dummy_con;
1885 #endif
1887 tsc_init();
1890 static int
1891 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
1893 HYPERVISOR_shutdown(SHUTDOWN_crash);
1894 /* we're never actually going to get here... */
1895 return NOTIFY_DONE;
1898 static __init int add_pcspkr(void)
1900 struct platform_device *pd;
1901 int ret;
1903 if (!is_initial_xendomain())
1904 return 0;
1906 pd = platform_device_alloc("pcspkr", -1);
1907 if (!pd)
1908 return -ENOMEM;
1910 ret = platform_device_add(pd);
1911 if (ret)
1912 platform_device_put(pd);
1914 return ret;
1916 device_initcall(add_pcspkr);
1918 /*
1919 * Local Variables:
1920 * mode:c
1921 * c-file-style:"k&r"
1922 * c-basic-offset:8
1923 * End:
1924 */