ia64/linux-2.6.18-xen.hg

annotate arch/i386/kernel/setup-xen.c @ 526:f128849f9e78

linux/x86: set up machine_e820 in copy_e820_map() for it to be usable
earlier (and also for being placed more logically).

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