2 * Copyright (C) 1995 Linus Torvalds
4 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
6 * Memory region support
7 * David Parsons <orc@pell.chi.il.us>, July-August 1999
9 * Added E820 sanitization routine (removes overlapping memory regions);
10 * Brian Moyle <bmoyle@mvista.com>, February 2001
12 * Moved CPU detection code to cpu/${cpu}.c
13 * Patrick Mochel <mochel@osdl.org>, March 2002
15 * Provisions for empty E820 memory regions (reported by certain BIOSes).
16 * Alex Achenbach <xela@slit.de>, December 2002.
21 * This file handles the architecture-dependent parts of initialization
24 #include <linux/sched.h>
26 #include <linux/mmzone.h>
27 #include <linux/screen_info.h>
28 #include <linux/ioport.h>
29 #include <linux/acpi.h>
30 #include <linux/sfi.h>
31 #include <linux/apm_bios.h>
32 #include <linux/initrd.h>
33 #include <linux/bootmem.h>
34 #include <linux/seq_file.h>
35 #include <linux/console.h>
36 #include <linux/mca.h>
37 #include <linux/root_dev.h>
38 #include <linux/highmem.h>
39 #include <linux/module.h>
40 #include <linux/efi.h>
41 #include <linux/init.h>
42 #include <linux/edd.h>
43 #include <linux/iscsi_ibft.h>
44 #include <linux/nodemask.h>
45 #include <linux/kexec.h>
46 #include <linux/dmi.h>
47 #include <linux/pfn.h>
48 #include <linux/pci.h>
49 #include <asm/pci-direct.h>
50 #include <linux/init_ohci1394_dma.h>
51 #include <linux/kvm_para.h>
53 #include <linux/errno.h>
54 #include <linux/kernel.h>
55 #include <linux/stddef.h>
56 #include <linux/unistd.h>
57 #include <linux/ptrace.h>
58 #include <linux/slab.h>
59 #include <linux/user.h>
60 #include <linux/delay.h>
62 #include <linux/kallsyms.h>
63 #include <linux/cpufreq.h>
64 #include <linux/dma-mapping.h>
65 #include <linux/ctype.h>
66 #include <linux/uaccess.h>
68 #include <linux/percpu.h>
69 #include <linux/crash_dump.h>
70 #include <linux/tboot.h>
72 #include <video/edid.h>
77 #include <asm/mpspec.h>
78 #include <asm/setup.h>
80 #include <asm/timer.h>
81 #include <asm/i8259.h>
82 #include <asm/sections.h>
84 #include <asm/io_apic.h>
87 #include <asm/setup_arch.h>
88 #include <asm/bios_ebda.h>
89 #include <asm/cacheflush.h>
90 #include <asm/processor.h>
93 #include <asm/system.h>
94 #include <asm/vsyscall.h>
98 #include <asm/iommu.h>
100 #include <asm/mmu_context.h>
101 #include <asm/proto.h>
103 #include <asm/paravirt.h>
104 #include <asm/hypervisor.h>
106 #include <asm/percpu.h>
107 #include <asm/topology.h>
108 #include <asm/apicdef.h>
110 #include <asm/numa_64.h>
115 #include <asm/hypervisor.h>
116 #include <xen/interface/kexec.h>
117 #include <xen/interface/memory.h>
118 #include <xen/interface/nmi.h>
119 #include <xen/interface/physdev.h>
120 #include <xen/features.h>
121 #include <xen/firmware.h>
122 #include <xen/xencons.h>
124 static int xen_panic_event(struct notifier_block *, unsigned long, void *);
125 static struct notifier_block xen_panic_block = {
126 xen_panic_event, NULL, 0 /* try to go last */
129 unsigned long *phys_to_machine_mapping;
130 EXPORT_SYMBOL(phys_to_machine_mapping);
132 unsigned long *pfn_to_mfn_frame_list_list, **pfn_to_mfn_frame_list;
134 /* Raw start-of-day parameters from the hypervisor. */
135 start_info_t *xen_start_info;
136 EXPORT_SYMBOL(xen_start_info);
140 * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
141 * The direct mapping extends to max_pfn_mapped, so that we can directly access
142 * apertures, ACPI and other tables without having to play with fixmaps.
144 unsigned long max_low_pfn_mapped;
145 unsigned long max_pfn_mapped;
147 RESERVE_BRK(dmi_alloc, 65536);
149 unsigned int boot_cpu_id __read_mostly;
151 static __initdata unsigned long _brk_start = (unsigned long)__brk_base;
152 unsigned long _brk_end = (unsigned long)__brk_base;
156 int default_cpu_present_to_apicid(int mps_cpu)
158 return __default_cpu_present_to_apicid(mps_cpu);
161 int default_check_phys_apicid_present(int phys_apicid)
163 return __default_check_phys_apicid_present(phys_apicid);
167 #ifndef CONFIG_DEBUG_BOOT_PARAMS
168 struct boot_params __initdata boot_params;
170 struct boot_params boot_params;
177 static struct resource data_resource = {
178 .name = "Kernel data",
181 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
184 static struct resource code_resource = {
185 .name = "Kernel code",
188 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
191 static struct resource bss_resource = {
192 .name = "Kernel bss",
195 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
200 /* cpu data as detected by the assembly code in head.S */
201 struct cpuinfo_x86 new_cpu_data __cpuinitdata = {0, 0, 0, 0, -1, 1, 0, 0, -1};
202 /* common cpu data for all cpus */
203 struct cpuinfo_x86 boot_cpu_data __read_mostly = {0, 0, 0, 0, -1, 1, 0, 0, -1};
204 EXPORT_SYMBOL(boot_cpu_data);
206 static void set_mca_bus(int x)
213 unsigned int def_to_bigsmp;
215 /* for MCA, but anyone else can use it if they want */
216 unsigned int machine_id;
217 unsigned int machine_submodel_id;
218 unsigned int BIOS_revision;
220 struct apm_info apm_info;
221 EXPORT_SYMBOL(apm_info);
224 #if defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
225 struct ist_info ist_info;
226 EXPORT_SYMBOL(ist_info);
227 #elif defined(CONFIG_X86_SPEEDSTEP_SMI)
228 struct ist_info ist_info;
232 struct cpuinfo_x86 boot_cpu_data __read_mostly = {
233 .x86_phys_bits = MAX_PHYSMEM_BITS,
235 EXPORT_SYMBOL(boot_cpu_data);
239 #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
240 unsigned long mmu_cr4_features;
242 unsigned long mmu_cr4_features = X86_CR4_PAE;
245 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
246 int bootloader_type, bootloader_version;
251 struct screen_info screen_info;
252 EXPORT_SYMBOL(screen_info);
253 struct edid_info edid_info;
254 EXPORT_SYMBOL_GPL(edid_info);
256 extern int root_mountflags;
258 unsigned long saved_video_mode;
260 #define RAMDISK_IMAGE_START_MASK 0x07FF
261 #define RAMDISK_PROMPT_FLAG 0x8000
262 #define RAMDISK_LOAD_FLAG 0x4000
264 static char __initdata command_line[COMMAND_LINE_SIZE];
265 #ifdef CONFIG_CMDLINE_BOOL
266 static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
269 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
271 #ifdef CONFIG_EDD_MODULE
276 * copy_edd() - Copy the BIOS EDD information
277 * from boot_params into a safe place.
280 static inline void copy_edd(void)
282 memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
283 sizeof(edd.mbr_signature));
284 memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
285 edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
286 edd.edd_info_nr = boot_params.eddbuf_entries;
290 static inline void copy_edd(void)
295 void * __init extend_brk(size_t size, size_t align)
297 size_t mask = align - 1;
300 BUG_ON(_brk_start == 0);
301 BUG_ON(align & mask);
303 _brk_end = (_brk_end + mask) & ~mask;
304 BUG_ON((char *)(_brk_end + size) > __brk_limit);
306 ret = (void *)_brk_end;
309 memset(ret, 0, size);
314 #if defined(CONFIG_X86_64) && !defined(CONFIG_XEN)
315 static void __init init_gbpages(void)
317 if (direct_gbpages && cpu_has_gbpages)
318 printk(KERN_INFO "Using GB pages for direct mapping\n");
323 static inline void init_gbpages(void)
328 static void __init reserve_brk(void)
330 if (_brk_end > _brk_start)
331 reserve_early(__pa(_brk_start), __pa(_brk_end), "BRK");
333 /* Mark brk area as locked down and no longer taking any
338 #ifdef CONFIG_BLK_DEV_INITRD
340 #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
341 static void __init relocate_initrd(void)
344 u64 ramdisk_image = boot_params.hdr.ramdisk_image;
345 u64 ramdisk_size = boot_params.hdr.ramdisk_size;
346 u64 end_of_lowmem = max_low_pfn_mapped << PAGE_SHIFT;
348 unsigned long slop, clen, mapaddr;
351 /* We need to move the initrd down into lowmem */
352 ramdisk_here = find_e820_area(0, end_of_lowmem, ramdisk_size,
355 if (ramdisk_here == -1ULL)
356 panic("Cannot find place for new RAMDISK of size %lld\n",
359 /* Note: this includes all the lowmem currently occupied by
360 the initrd, we rely on that fact to keep the data intact. */
361 reserve_early(ramdisk_here, ramdisk_here + ramdisk_size,
363 initrd_start = ramdisk_here + PAGE_OFFSET;
364 initrd_end = initrd_start + ramdisk_size;
365 printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
366 ramdisk_here, ramdisk_here + ramdisk_size);
368 q = (char *)initrd_start;
370 /* Copy any lowmem portion of the initrd */
371 if (ramdisk_image < end_of_lowmem) {
372 clen = end_of_lowmem - ramdisk_image;
373 p = (char *)__va(ramdisk_image);
376 ramdisk_image += clen;
377 ramdisk_size -= clen;
380 /* Copy the highmem portion of the initrd */
381 while (ramdisk_size) {
382 slop = ramdisk_image & ~PAGE_MASK;
384 if (clen > MAX_MAP_CHUNK-slop)
385 clen = MAX_MAP_CHUNK-slop;
386 mapaddr = ramdisk_image & PAGE_MASK;
387 p = early_memremap(mapaddr, clen+slop);
388 memcpy(q, p+slop, clen);
389 early_iounmap(p, clen+slop);
391 ramdisk_image += clen;
392 ramdisk_size -= clen;
394 /* high pages is not converted by early_res_to_bootmem */
395 ramdisk_image = boot_params.hdr.ramdisk_image;
396 ramdisk_size = boot_params.hdr.ramdisk_size;
397 printk(KERN_INFO "Move RAMDISK from %016llx - %016llx to"
398 " %08llx - %08llx\n",
399 ramdisk_image, ramdisk_image + ramdisk_size - 1,
400 ramdisk_here, ramdisk_here + ramdisk_size - 1);
402 printk(KERN_ERR "initrd extends beyond end of memory "
403 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
404 __pa(xen_start_info->mod_start) + xen_start_info->mod_len,
405 max_low_pfn_mapped << PAGE_SHIFT);
410 static void __init reserve_initrd(void)
413 u64 ramdisk_image = boot_params.hdr.ramdisk_image;
414 u64 ramdisk_size = boot_params.hdr.ramdisk_size;
415 u64 ramdisk_end = ramdisk_image + ramdisk_size;
416 u64 end_of_lowmem = max_low_pfn_mapped << PAGE_SHIFT;
418 if (!boot_params.hdr.type_of_loader ||
419 !ramdisk_image || !ramdisk_size)
420 return; /* No initrd provided by bootloader */
422 unsigned long ramdisk_image = __pa(xen_start_info->mod_start);
423 unsigned long ramdisk_size = xen_start_info->mod_len;
424 unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
425 unsigned long end_of_lowmem = max_low_pfn_mapped << PAGE_SHIFT;
427 if (!xen_start_info->mod_start || !ramdisk_size)
428 return; /* No initrd provided by bootloader */
433 if (ramdisk_size >= (end_of_lowmem>>1)) {
434 free_early(ramdisk_image, ramdisk_end);
435 printk(KERN_ERR "initrd too large to handle, "
436 "disabling initrd\n");
440 printk(KERN_INFO "RAMDISK: %08lx - %08lx\n", ramdisk_image,
444 if (ramdisk_end <= end_of_lowmem) {
445 /* All in lowmem, easy case */
447 * don't need to reserve again, already reserved early
448 * in i386_start_kernel
450 initrd_start = ramdisk_image + PAGE_OFFSET;
451 initrd_end = initrd_start + ramdisk_size;
452 #ifdef CONFIG_X86_64_XEN
453 initrd_below_start_ok = 1;
460 free_early(ramdisk_image, ramdisk_end);
463 static void __init reserve_initrd(void)
466 #endif /* CONFIG_BLK_DEV_INITRD */
468 static void __init parse_setup_data(void)
471 struct setup_data *data;
474 if (boot_params.hdr.version < 0x0209)
476 pa_data = boot_params.hdr.setup_data;
478 data = early_memremap(pa_data, PAGE_SIZE);
479 switch (data->type) {
481 parse_e820_ext(data, pa_data);
486 pa_data = data->next;
487 early_iounmap(data, PAGE_SIZE);
492 static void __init e820_reserve_setup_data(void)
495 struct setup_data *data;
499 if (boot_params.hdr.version < 0x0209)
501 pa_data = boot_params.hdr.setup_data;
503 data = early_memremap(pa_data, sizeof(*data));
504 e820_update_range(pa_data, sizeof(*data)+data->len,
505 E820_RAM, E820_RESERVED_KERN);
507 pa_data = data->next;
508 early_iounmap(data, sizeof(*data));
513 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
514 memcpy(&e820_saved, &e820, sizeof(struct e820map));
515 printk(KERN_INFO "extended physical RAM map:\n");
516 e820_print_map("reserve setup_data");
520 static void __init reserve_early_setup_data(void)
523 struct setup_data *data;
527 if (boot_params.hdr.version < 0x0209)
529 pa_data = boot_params.hdr.setup_data;
531 data = early_memremap(pa_data, sizeof(*data));
532 sprintf(buf, "setup data %x", data->type);
533 reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
534 pa_data = data->next;
535 early_iounmap(data, sizeof(*data));
541 * --------- Crashkernel reservation ------------------------------
548 * Reserve @size bytes of crashkernel memory at any suitable offset.
550 * @size: Size of the crashkernel memory to reserve.
551 * Returns the base address on success, and -1ULL on failure.
554 unsigned long long __init find_and_reserve_crashkernel(unsigned long long size)
556 const unsigned long long alignment = 16<<20; /* 16M */
557 unsigned long long start = 0LL;
562 start = find_e820_area(start, ULONG_MAX, size, alignment);
566 /* try to reserve it */
567 ret = reserve_bootmem_generic(start, size, BOOTMEM_EXCLUSIVE);
575 static inline unsigned long long get_total_mem(void)
577 unsigned long long total;
579 total = max_low_pfn - min_low_pfn;
580 #ifdef CONFIG_HIGHMEM
581 total += highend_pfn - highstart_pfn;
584 return total << PAGE_SHIFT;
587 static void __init reserve_crashkernel(void)
589 unsigned long long total_mem;
590 unsigned long long crash_size, crash_base;
593 total_mem = get_total_mem();
595 ret = parse_crashkernel(boot_command_line, total_mem,
596 &crash_size, &crash_base);
597 if (ret != 0 || crash_size <= 0)
600 /* 0 means: find the address automatically */
601 if (crash_base <= 0) {
602 crash_base = find_and_reserve_crashkernel(crash_size);
603 if (crash_base == -1ULL) {
604 pr_info("crashkernel reservation failed. "
605 "No suitable area found.\n");
609 ret = reserve_bootmem_generic(crash_base, crash_size,
612 pr_info("crashkernel reservation failed - "
613 "memory is in use\n");
618 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
619 "for crashkernel (System RAM: %ldMB)\n",
620 (unsigned long)(crash_size >> 20),
621 (unsigned long)(crash_base >> 20),
622 (unsigned long)(total_mem >> 20));
624 crashk_res.start = crash_base;
625 crashk_res.end = crash_base + crash_size - 1;
626 insert_resource(&iomem_resource, &crashk_res);
629 #define reserve_crashkernel xen_machine_kexec_setup_resources
632 static void __init reserve_crashkernel(void)
637 static struct resource standard_io_resources[] = {
638 { .name = "dma1", .start = 0x00, .end = 0x1f,
639 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
640 { .name = "pic1", .start = 0x20, .end = 0x21,
641 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
642 { .name = "timer0", .start = 0x40, .end = 0x43,
643 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
644 { .name = "timer1", .start = 0x50, .end = 0x53,
645 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
646 { .name = "keyboard", .start = 0x60, .end = 0x60,
647 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
648 { .name = "keyboard", .start = 0x64, .end = 0x64,
649 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
650 { .name = "dma page reg", .start = 0x80, .end = 0x8f,
651 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
652 { .name = "pic2", .start = 0xa0, .end = 0xa1,
653 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
654 { .name = "dma2", .start = 0xc0, .end = 0xdf,
655 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
656 { .name = "fpu", .start = 0xf0, .end = 0xff,
657 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
660 void __init reserve_standard_io_resources(void)
664 /* Nothing to do if not running in dom0. */
665 if (!is_initial_xendomain())
668 /* request I/O space for devices used on all i[345]86 PCs */
669 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
670 request_resource(&ioport_resource, &standard_io_resources[i]);
675 * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
676 * is_kdump_kernel() to determine if we are booting after a panic. Hence
677 * ifdef it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
680 #ifdef CONFIG_CRASH_DUMP
681 /* elfcorehdr= specifies the location of elf core header
682 * stored by the crashed kernel. This option will be passed
683 * by kexec loader to the capture kernel.
685 static int __init setup_elfcorehdr(char *arg)
690 elfcorehdr_addr = memparse(arg, &end);
691 return end > arg ? 0 : -EINVAL;
693 early_param("elfcorehdr", setup_elfcorehdr);
696 #ifdef CONFIG_X86_RESERVE_LOW_64K
697 static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
700 "%s detected: BIOS may corrupt low RAM, working around it.\n",
703 e820_update_range(0, 0x10000, E820_RAM, E820_RESERVED);
704 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
710 /* List of systems that have known low memory corruption BIOS problems */
711 static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
712 #ifdef CONFIG_X86_RESERVE_LOW_64K
714 .callback = dmi_low_memory_corruption,
717 DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
721 .callback = dmi_low_memory_corruption,
722 .ident = "Phoenix BIOS",
724 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies"),
728 .callback = dmi_low_memory_corruption,
729 .ident = "Phoenix/MSC BIOS",
731 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix/MSC"),
736 * AMI BIOS with low memory corruption was found on Intel DG45ID board.
737 * It hase different DMI_BIOS_VENDOR = "Intel Corp.", for now we will
738 * match only DMI_BOARD_NAME and see if there is more bad products
741 .callback = dmi_low_memory_corruption,
744 DMI_MATCH(DMI_BOARD_NAME, "DG45ID"),
752 * Determine if we were loaded by an EFI loader. If so, then we have also been
753 * passed the efi memmap, systab, etc., so we should use these data structures
754 * for initialization. Note, the efi init code path is determined by the
755 * global efi_enabled. This allows the same kernel image to be used on existing
756 * systems (with a traditional BIOS) as well as on EFI systems.
759 * setup_arch - architecture-specific boot-time initializations
761 * Note: On x86_64, fixmaps are ready for use even before this is called.
764 void __init setup_arch(char **cmdline_p)
768 unsigned long p2m_pages;
769 struct physdev_set_iopl set_iopl;
771 if (!is_initial_xendomain()) {
773 /* Force a quick death if the kernel panics (not domain 0). */
774 extern int panic_timeout;
779 /* Register a call for panic conditions. */
780 atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
782 #endif /* CONFIG_XEN */
785 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
786 visws_early_detect();
788 printk(KERN_INFO "Command line: %s\n", boot_command_line);
791 /* VMI may relocate the fixmap; do this before touching ioremap area */
795 early_ioremap_init();
798 ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
799 screen_info = boot_params.screen_info;
800 edid_info = boot_params.edid_info;
802 apm_info.bios = boot_params.apm_bios_info;
803 ist_info = boot_params.ist_info;
804 if (boot_params.sys_desc_table.length != 0) {
805 set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
806 machine_id = boot_params.sys_desc_table.table[0];
807 machine_submodel_id = boot_params.sys_desc_table.table[1];
808 BIOS_revision = boot_params.sys_desc_table.table[2];
811 saved_video_mode = boot_params.hdr.vid_mode;
812 bootloader_type = boot_params.hdr.type_of_loader;
813 if ((bootloader_type >> 4) == 0xe) {
814 bootloader_type &= 0xf;
815 bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4;
817 bootloader_version = bootloader_type & 0xf;
818 bootloader_version |= boot_params.hdr.ext_loader_ver << 4;
820 #ifdef CONFIG_BLK_DEV_RAM
821 rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
822 rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
823 rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
826 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
837 #else /* CONFIG_XEN */
839 /* This must be initialized to UNNAMED_MAJOR for ipconfig to work
840 properly. Setting ROOT_DEV to default to /dev/ram0 breaks initrd.
842 ROOT_DEV = MKDEV(UNNAMED_MAJOR,0);
844 ROOT_DEV = MKDEV(RAMDISK_MAJOR,0);
846 if (is_initial_xendomain()) {
847 const struct dom0_vga_console_info *info =
848 (void *)((char *)xen_start_info +
849 xen_start_info->console.dom0.info_off);
851 dom0_init_screen_info(info,
852 xen_start_info->console.dom0.info_size);
853 xen_start_info->console.domU.mfn = 0;
854 xen_start_info->console.domU.evtchn = 0;
856 screen_info.orig_video_isVGA = 0;
858 #endif /* CONFIG_XEN */
860 x86_init.oem.arch_setup();
864 /* update the e820_saved too */
865 e820_reserve_setup_data();
870 if (!boot_params.hdr.root_flags)
871 root_mountflags &= ~MS_RDONLY;
873 init_mm.start_code = (unsigned long) _text;
874 init_mm.end_code = (unsigned long) _etext;
875 init_mm.end_data = (unsigned long) _edata;
876 init_mm.brk = _brk_end;
878 code_resource.start = virt_to_phys(_text);
879 code_resource.end = virt_to_phys(_etext)-1;
880 data_resource.start = virt_to_phys(_etext);
881 data_resource.end = virt_to_phys(_edata)-1;
882 bss_resource.start = virt_to_phys(&__bss_start);
883 bss_resource.end = virt_to_phys(&__bss_stop)-1;
885 #ifdef CONFIG_CMDLINE_BOOL
886 #ifdef CONFIG_CMDLINE_OVERRIDE
887 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
889 if (builtin_cmdline[0]) {
890 /* append boot loader cmdline to builtin */
891 strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
892 strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
893 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
898 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
899 *cmdline_p = command_line;
903 * Must call this twice: Once just to detect whether hardware doesn't
904 * support NX (so that the early EHCI debug console setup can safely
905 * call set_fixmap(), and then again after parsing early parameters to
906 * honor the respective command line option.
917 /* Must be before kernel pagetables are setup */
920 /* after early param, so could get panic from serial */
921 reserve_early_setup_data();
923 if (acpi_mps_check()) {
924 #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_XEN)
927 setup_clear_cpu_cap(X86_FEATURE_APIC);
931 if (pci_early_dump_regs)
932 early_dump_pci_devices();
935 finish_e820_parsing();
940 if (is_initial_xendomain()) {
943 dmi_check_system(bad_bios_dmi_table);
947 * VMware detection requires dmi to be available, so this
948 * needs to be done after dmi_scan_machine, for the BP.
950 init_hypervisor_platform();
952 x86_init.resources.probe_roms();
955 /* after parse_early_param, so could debug it */
956 insert_resource(&iomem_resource, &code_resource);
957 insert_resource(&iomem_resource, &data_resource);
958 insert_resource(&iomem_resource, &bss_resource);
962 if (ppro_with_ram_bug()) {
963 e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
965 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
966 printk(KERN_INFO "fixed physical RAM map:\n");
967 e820_print_map("bad_ppro");
970 early_gart_iommu_check();
972 #endif /* CONFIG_XEN */
975 * partially used pages are not usable - thus
976 * we are rounding upwards:
978 max_pfn = e820_end_of_ram_pfn();
980 /* preallocate 4k for mptable mpc */
981 early_reserve_e820_mpc_new();
982 /* update e820 for memory not covered by WB MTRRs */
985 if (mtrr_trim_uncached_memory(max_pfn))
986 max_pfn = e820_end_of_ram_pfn();
990 /* max_low_pfn get updated here */
991 find_low_pfn_range();
993 num_physpages = max_pfn;
996 #ifdef CONFIG_X86_LOCAL_APIC
1000 /* How many end-of-memory variables you have, grandma! */
1001 /* need this before calling reserve_initrd */
1002 if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
1003 max_low_pfn = e820_end_of_low_ram_pfn();
1005 max_low_pfn = max_pfn;
1007 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
1009 max_pfn_mapped = KERNEL_IMAGE_SIZE >> PAGE_SHIFT;
1013 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
1014 setup_bios_corruption_check();
1017 printk(KERN_DEBUG "initial memory mapped : 0 - %08lx\n",
1018 max_pfn_mapped<<PAGE_SHIFT);
1024 /* max_pfn_mapped is updated here */
1025 max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT);
1026 max_pfn_mapped = max_low_pfn_mapped;
1028 #ifdef CONFIG_X86_64
1029 if (max_pfn > max_low_pfn) {
1030 max_pfn_mapped = init_memory_mapping(1UL<<32,
1031 max_pfn<<PAGE_SHIFT);
1032 /* can we preseve max_low_pfn ?*/
1033 max_low_pfn = max_pfn;
1038 * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
1041 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
1042 if (init_ohci1394_dma_early)
1043 init_ohci1394_dma_on_all_controllers();
1055 if (!is_initial_xendomain()) {
1056 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
1062 * Parse the ACPI tables for possible boot-time SMP configuration.
1064 acpi_boot_table_init();
1066 early_acpi_boot_init();
1068 #ifdef CONFIG_ACPI_NUMA
1070 * Parse SRAT to discover nodes.
1075 initmem_init(0, max_pfn);
1077 #ifdef CONFIG_ACPI_SLEEP
1079 * Reserve low memory region for sleep support.
1081 acpi_reserve_bootmem();
1084 * Find and reserve possible boot-time SMP configuration:
1088 reserve_crashkernel();
1090 #if defined(CONFIG_X86_64) && !defined(CONFIG_XEN)
1092 * dma32_reserve_bootmem() allocates bootmem which may conflict
1093 * with the crashkernel command line, so do that after
1094 * reserve_crashkernel()
1096 dma32_reserve_bootmem();
1099 reserve_ibft_region();
1101 #ifdef CONFIG_KVM_CLOCK
1105 x86_init.paging.pagetable_setup_start(swapper_pg_dir);
1107 x86_init.paging.pagetable_setup_done(swapper_pg_dir);
1111 #ifdef CONFIG_X86_64
1116 p2m_pages = max_pfn;
1117 if (xen_start_info->nr_pages > max_pfn) {
1119 * the max_pfn was shrunk (probably by mem= or highmem=
1120 * kernel parameter); shrink reservation with the HV
1122 struct xen_memory_reservation reservation = {
1127 unsigned int difference;
1130 difference = xen_start_info->nr_pages - max_pfn;
1132 set_xen_guest_handle(reservation.extent_start,
1133 phys_to_machine_mapping + max_pfn);
1134 reservation.nr_extents = difference;
1135 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
1137 BUG_ON(ret != difference);
1139 else if (max_pfn > xen_start_info->nr_pages)
1140 p2m_pages = xen_start_info->nr_pages;
1142 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1143 unsigned long i, j, size;
1144 unsigned int k, fpp;
1146 /* Make sure we have a large enough P->M table. */
1147 phys_to_machine_mapping = alloc_bootmem_pages(
1148 max_pfn * sizeof(unsigned long));
1149 memcpy(phys_to_machine_mapping,
1150 __va(__pa(xen_start_info->mfn_list)),
1151 p2m_pages * sizeof(unsigned long));
1152 memset(phys_to_machine_mapping + p2m_pages, ~0,
1153 (max_pfn - p2m_pages) * sizeof(unsigned long));
1155 #ifdef CONFIG_X86_64
1156 if (xen_start_info->mfn_list == VMEMMAP_START) {
1158 * Since it is well isolated we can (and since it is
1159 * perhaps large we should) also free the page tables
1160 * mapping the initial P->M table.
1162 unsigned long va = VMEMMAP_START, pa;
1163 pgd_t *pgd = pgd_offset_k(va);
1164 pud_t *pud_page = pud_offset(pgd, 0);
1166 BUILD_BUG_ON(VMEMMAP_START & ~PGDIR_MASK);
1167 xen_l4_entry_update(pgd, __pgd(0));
1169 pud_t *pud = pud_page + pud_index(va);
1173 else if (pud_large(*pud)) {
1174 pa = pud_val(*pud) & PHYSICAL_PAGE_MASK;
1175 make_pages_writable(__va(pa),
1176 PUD_SIZE >> PAGE_SHIFT,
1177 XENFEAT_writable_page_tables);
1178 free_bootmem(pa, PUD_SIZE);
1181 pmd_t *pmd = pmd_offset(pud, va);
1183 if (pmd_large(*pmd)) {
1184 pa = pmd_val(*pmd) & PHYSICAL_PAGE_MASK;
1185 make_pages_writable(__va(pa),
1186 PMD_SIZE >> PAGE_SHIFT,
1187 XENFEAT_writable_page_tables);
1188 free_bootmem(pa, PMD_SIZE);
1189 } else if (!pmd_none(*pmd)) {
1190 pte_t *pte = pte_offset_kernel(pmd, va);
1192 for (i = 0; i < PTRS_PER_PTE; ++i) {
1193 if (pte_none(pte[i]))
1195 pa = pte_pfn(pte[i]) << PAGE_SHIFT;
1196 make_page_writable(__va(pa),
1197 XENFEAT_writable_page_tables);
1198 free_bootmem(pa, PAGE_SIZE);
1200 ClearPagePinned(virt_to_page(pte));
1201 make_page_writable(pte,
1202 XENFEAT_writable_page_tables);
1203 free_bootmem(__pa(pte), PAGE_SIZE);
1208 ClearPagePinned(virt_to_page(pmd));
1209 make_page_writable(pmd,
1210 XENFEAT_writable_page_tables);
1211 free_bootmem(__pa((unsigned long)pmd
1218 ClearPagePinned(virt_to_page(pud_page));
1219 make_page_writable(pud_page,
1220 XENFEAT_writable_page_tables);
1221 free_bootmem(__pa((unsigned long)pud_page & PAGE_MASK),
1223 } else if (!WARN_ON(xen_start_info->mfn_list
1224 < __START_KERNEL_map))
1226 free_bootmem(__pa(xen_start_info->mfn_list),
1227 PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
1228 sizeof(unsigned long))));
1232 * Initialise the list of the frames that specify the list of
1233 * frames that make up the p2m table. Used by save/restore.
1235 fpp = PAGE_SIZE/sizeof(unsigned long);
1236 size = (max_pfn + fpp - 1) / fpp;
1237 size = (size + fpp - 1) / fpp;
1238 ++size; /* include a zero terminator for crash tools */
1239 size *= sizeof(unsigned long);
1240 pfn_to_mfn_frame_list_list = alloc_bootmem_pages(size);
1241 if (size > PAGE_SIZE
1242 && xen_create_contiguous_region((unsigned long)
1243 pfn_to_mfn_frame_list_list,
1244 get_order(size), 0))
1246 size -= sizeof(unsigned long);
1247 pfn_to_mfn_frame_list = alloc_bootmem(size);
1249 for (i = j = 0, k = -1; i < max_pfn; i += fpp, j++) {
1254 BUG_ON(k * sizeof(unsigned long) >= size);
1255 pfn_to_mfn_frame_list[k] =
1256 alloc_bootmem_pages(PAGE_SIZE);
1257 pfn_to_mfn_frame_list_list[k] =
1258 virt_to_mfn(pfn_to_mfn_frame_list[k]);
1260 pfn_to_mfn_frame_list[k][j] =
1261 virt_to_mfn(&phys_to_machine_mapping[i]);
1263 HYPERVISOR_shared_info->arch.max_pfn = max_pfn;
1264 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
1265 virt_to_mfn(pfn_to_mfn_frame_list_list);
1268 /* Mark all ISA DMA channels in-use - using them wouldn't work. */
1269 for (i = 0; i < MAX_DMA_CHANNELS; ++i)
1270 if (i != 4 && request_dma(i, "xen") != 0)
1272 #else /* CONFIG_XEN */
1273 generic_apic_probe();
1279 * Read APIC and some other early information from ACPI tables.
1286 * get boot-time SMP configuration:
1288 if (smp_found_config)
1291 prefill_possible_map();
1293 #ifdef CONFIG_X86_64
1298 init_apic_mappings();
1299 ioapic_init_mappings();
1301 /* need to wait for io_apic is mapped */
1302 probe_nr_irqs_gsi();
1306 e820_reserve_resources();
1307 e820_mark_nosave_regions(max_low_pfn);
1309 if (is_initial_xendomain())
1310 e820_reserve_resources();
1313 x86_init.resources.reserve_resources();
1319 #if defined(CONFIG_VGA_CONSOLE)
1320 if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
1321 conswitchp = &vga_con;
1322 #elif defined(CONFIG_DUMMY_CONSOLE)
1323 conswitchp = &dummy_con;
1326 #else /* CONFIG_XEN */
1327 if (is_initial_xendomain())
1331 WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl));
1334 #ifdef CONFIG_DUMMY_CONSOLE
1335 conswitchp = &dummy_con;
1337 #ifdef CONFIG_VGA_CONSOLE
1338 if (is_initial_xendomain())
1339 conswitchp = &vga_con;
1342 #endif /* CONFIG_XEN */
1343 x86_init.oem.banner();
1345 mcheck_intel_therm_init();
1348 #ifdef CONFIG_X86_32
1350 static struct resource video_ram_resource = {
1351 .name = "Video RAM area",
1354 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
1357 void __init i386_reserve_resources(void)
1359 if (is_initial_xendomain())
1360 request_resource(&iomem_resource, &video_ram_resource);
1361 reserve_standard_io_resources();
1364 #endif /* CONFIG_X86_32 */
1368 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
1370 HYPERVISOR_shutdown(SHUTDOWN_crash);
1371 /* we're never actually going to get here... */
1374 #endif /* !CONFIG_XEN */