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/memblock.h>
35 #include <linux/seq_file.h>
36 #include <linux/console.h>
37 #include <linux/mca.h>
38 #include <linux/root_dev.h>
39 #include <linux/highmem.h>
40 #include <linux/module.h>
41 #include <linux/efi.h>
42 #include <linux/init.h>
43 #include <linux/edd.h>
44 #include <linux/iscsi_ibft.h>
45 #include <linux/nodemask.h>
46 #include <linux/kexec.h>
47 #include <linux/dmi.h>
48 #include <linux/pfn.h>
49 #include <linux/pci.h>
50 #include <asm/pci-direct.h>
51 #include <linux/init_ohci1394_dma.h>
52 #include <linux/kvm_para.h>
54 #include <linux/errno.h>
55 #include <linux/kernel.h>
56 #include <linux/stddef.h>
57 #include <linux/unistd.h>
58 #include <linux/ptrace.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>
76 #include <asm/trampoline.h>
78 #include <asm/mpspec.h>
79 #include <asm/setup.h>
81 #include <asm/timer.h>
82 #include <asm/i8259.h>
83 #include <asm/sections.h>
85 #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/vsyscall.h>
97 #include <asm/iommu.h>
99 #include <asm/mmu_context.h>
100 #include <asm/proto.h>
102 #include <asm/paravirt.h>
103 #include <asm/hypervisor.h>
104 #include <asm/olpc_ofw.h>
106 #include <asm/percpu.h>
107 #include <asm/topology.h>
108 #include <asm/apicdef.h>
109 #include <asm/amd_nb.h>
111 #include <asm/numa_64.h>
114 #include <asm/alternative.h>
115 #include <asm/prom.h>
118 #include <asm/hypervisor.h>
119 #include <xen/interface/kexec.h>
120 #include <xen/interface/memory.h>
121 #include <xen/interface/nmi.h>
122 #include <xen/interface/physdev.h>
123 #include <xen/features.h>
124 #include <xen/firmware.h>
125 #include <xen/xencons.h>
127 static int xen_panic_event(struct notifier_block *, unsigned long, void *);
128 static struct notifier_block xen_panic_block = {
129 xen_panic_event, NULL, 0 /* try to go last */
132 unsigned long *phys_to_machine_mapping;
133 EXPORT_SYMBOL(phys_to_machine_mapping);
135 static unsigned long *pfn_to_mfn_frame_list_list, **pfn_to_mfn_frame_list;
137 /* Raw start-of-day parameters from the hypervisor. */
138 start_info_t *xen_start_info;
139 EXPORT_SYMBOL(xen_start_info);
143 * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
144 * The direct mapping extends to max_pfn_mapped, so that we can directly access
145 * apertures, ACPI and other tables without having to play with fixmaps.
147 unsigned long max_low_pfn_mapped;
148 unsigned long max_pfn_mapped;
151 RESERVE_BRK(dmi_alloc, 65536);
155 static __initdata unsigned long _brk_start = (unsigned long)__brk_base;
156 unsigned long _brk_end = (unsigned long)__brk_base;
160 int default_cpu_present_to_apicid(int mps_cpu)
162 return __default_cpu_present_to_apicid(mps_cpu);
165 int default_check_phys_apicid_present(int phys_apicid)
167 return __default_check_phys_apicid_present(phys_apicid);
171 #ifndef CONFIG_DEBUG_BOOT_PARAMS
172 struct boot_params __initdata boot_params;
174 struct boot_params boot_params;
176 #else /* CONFIG_XEN */
178 * Initialise the list of the frames that specify the list of
179 * frames that make up the p2m table. Used by save/restore and
182 #ifdef CONFIG_PM_SLEEP
187 setup_pfn_to_mfn_frame_list(typeof(__alloc_bootmem) *__alloc_bootmem)
189 unsigned long i, j, size;
190 unsigned int k, fpp = PAGE_SIZE / sizeof(unsigned long);
192 size = (max_pfn + fpp - 1) / fpp;
193 size = (size + fpp - 1) / fpp;
194 ++size; /* include a zero terminator for crash tools */
195 size *= sizeof(unsigned long);
197 pfn_to_mfn_frame_list_list = alloc_bootmem_pages(size);
199 && xen_create_contiguous_region((unsigned long)
200 pfn_to_mfn_frame_list_list,
203 size -= sizeof(unsigned long);
205 pfn_to_mfn_frame_list = alloc_bootmem(size);
207 for (i = j = 0, k = -1; i < max_pfn; i += fpp, j++) {
212 BUG_ON(k * sizeof(unsigned long) >= size);
214 pfn_to_mfn_frame_list[k] =
215 alloc_bootmem_pages(PAGE_SIZE);
216 pfn_to_mfn_frame_list_list[k] =
217 virt_to_mfn(pfn_to_mfn_frame_list[k]);
219 pfn_to_mfn_frame_list[k][j] =
220 virt_to_mfn(&phys_to_machine_mapping[i]);
222 HYPERVISOR_shared_info->arch.max_pfn = max_pfn;
223 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
224 virt_to_mfn(pfn_to_mfn_frame_list_list);
231 static struct resource data_resource = {
232 .name = "Kernel data",
235 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
238 static struct resource code_resource = {
239 .name = "Kernel code",
242 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
245 static struct resource bss_resource = {
246 .name = "Kernel bss",
249 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
254 /* cpu data as detected by the assembly code in head.S */
255 struct cpuinfo_x86 new_cpu_data __cpuinitdata = { .wp_works_ok = 1, .hard_math = 1 };
256 /* common cpu data for all cpus */
257 struct cpuinfo_x86 boot_cpu_data __read_mostly = { .wp_works_ok = 1, .hard_math = 1 };
258 EXPORT_SYMBOL(boot_cpu_data);
260 static void set_mca_bus(int x)
267 unsigned int def_to_bigsmp;
269 /* for MCA, but anyone else can use it if they want */
270 unsigned int machine_id;
271 unsigned int machine_submodel_id;
272 unsigned int BIOS_revision;
274 struct apm_info apm_info;
275 EXPORT_SYMBOL(apm_info);
278 #if defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
279 struct ist_info ist_info;
280 EXPORT_SYMBOL(ist_info);
281 #elif defined(CONFIG_X86_SPEEDSTEP_SMI)
282 struct ist_info ist_info;
286 struct cpuinfo_x86 boot_cpu_data __read_mostly = {
287 .x86_phys_bits = MAX_PHYSMEM_BITS,
289 EXPORT_SYMBOL(boot_cpu_data);
293 #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
294 unsigned long mmu_cr4_features;
296 unsigned long mmu_cr4_features = X86_CR4_PAE;
299 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
300 int bootloader_type, bootloader_version;
305 struct screen_info screen_info;
306 EXPORT_SYMBOL(screen_info);
307 struct edid_info edid_info;
308 EXPORT_SYMBOL_GPL(edid_info);
310 extern int root_mountflags;
312 unsigned long saved_video_mode;
314 #define RAMDISK_IMAGE_START_MASK 0x07FF
315 #define RAMDISK_PROMPT_FLAG 0x8000
316 #define RAMDISK_LOAD_FLAG 0x4000
318 static char __initdata command_line[COMMAND_LINE_SIZE];
319 #ifdef CONFIG_CMDLINE_BOOL
320 static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
323 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
325 #ifdef CONFIG_EDD_MODULE
330 * copy_edd() - Copy the BIOS EDD information
331 * from boot_params into a safe place.
334 static inline void __init copy_edd(void)
336 memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
337 sizeof(edd.mbr_signature));
338 memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
339 edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
340 edd.edd_info_nr = boot_params.eddbuf_entries;
344 static inline void __init copy_edd(void)
349 void * __init extend_brk(size_t size, size_t align)
351 size_t mask = align - 1;
354 BUG_ON(_brk_start == 0);
355 BUG_ON(align & mask);
357 _brk_end = (_brk_end + mask) & ~mask;
358 BUG_ON((char *)(_brk_end + size) > __brk_limit);
360 ret = (void *)_brk_end;
363 memset(ret, 0, size);
368 #if defined(CONFIG_X86_64) && !defined(CONFIG_XEN)
369 static void __init init_gbpages(void)
371 if (direct_gbpages && cpu_has_gbpages)
372 printk(KERN_INFO "Using GB pages for direct mapping\n");
377 static inline void init_gbpages(void)
380 static void __init cleanup_highmap(void)
385 static void __init reserve_brk(void)
387 if (_brk_end > _brk_start)
388 memblock_reserve(__pa(_brk_start),
389 __pa(_brk_end) - __pa(_brk_start));
391 /* Mark brk area as locked down and no longer taking any
396 #ifdef CONFIG_BLK_DEV_INITRD
398 #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
399 static void __init relocate_initrd(void)
402 /* Assume only end is not page aligned */
403 u64 ramdisk_image = boot_params.hdr.ramdisk_image;
404 u64 ramdisk_size = boot_params.hdr.ramdisk_size;
405 u64 area_size = PAGE_ALIGN(ramdisk_size);
406 u64 end_of_lowmem = max_low_pfn_mapped << PAGE_SHIFT;
408 unsigned long slop, clen, mapaddr;
411 /* We need to move the initrd down into lowmem */
412 ramdisk_here = memblock_find_in_range(0, end_of_lowmem, area_size,
416 panic("Cannot find place for new RAMDISK of size %lld\n",
419 /* Note: this includes all the lowmem currently occupied by
420 the initrd, we rely on that fact to keep the data intact. */
421 memblock_reserve(ramdisk_here, area_size);
422 initrd_start = ramdisk_here + PAGE_OFFSET;
423 initrd_end = initrd_start + ramdisk_size;
424 printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
425 ramdisk_here, ramdisk_here + ramdisk_size);
427 q = (char *)initrd_start;
429 /* Copy any lowmem portion of the initrd */
430 if (ramdisk_image < end_of_lowmem) {
431 clen = end_of_lowmem - ramdisk_image;
432 p = (char *)__va(ramdisk_image);
435 ramdisk_image += clen;
436 ramdisk_size -= clen;
439 /* Copy the highmem portion of the initrd */
440 while (ramdisk_size) {
441 slop = ramdisk_image & ~PAGE_MASK;
443 if (clen > MAX_MAP_CHUNK-slop)
444 clen = MAX_MAP_CHUNK-slop;
445 mapaddr = ramdisk_image & PAGE_MASK;
446 p = early_memremap(mapaddr, clen+slop);
447 memcpy(q, p+slop, clen);
448 early_iounmap(p, clen+slop);
450 ramdisk_image += clen;
451 ramdisk_size -= clen;
453 /* high pages is not converted by early_res_to_bootmem */
454 ramdisk_image = boot_params.hdr.ramdisk_image;
455 ramdisk_size = boot_params.hdr.ramdisk_size;
456 printk(KERN_INFO "Move RAMDISK from %016llx - %016llx to"
457 " %08llx - %08llx\n",
458 ramdisk_image, ramdisk_image + ramdisk_size - 1,
459 ramdisk_here, ramdisk_here + ramdisk_size - 1);
461 printk(KERN_ERR "initrd extends beyond end of memory "
462 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
463 xen_initrd_start + xen_start_info->mod_len,
464 max_low_pfn_mapped << PAGE_SHIFT);
469 static void __init reserve_initrd(void)
471 /* Assume only end is not page aligned */
473 u64 ramdisk_image = boot_params.hdr.ramdisk_image;
474 u64 ramdisk_size = boot_params.hdr.ramdisk_size;
475 u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
476 u64 end_of_lowmem = max_low_pfn_mapped << PAGE_SHIFT;
478 if (!boot_params.hdr.type_of_loader ||
479 !ramdisk_image || !ramdisk_size)
480 return; /* No initrd provided by bootloader */
482 unsigned long ramdisk_image = xen_initrd_start;
483 unsigned long ramdisk_size = xen_start_info->mod_len;
484 unsigned long ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
485 unsigned long end_of_lowmem = max_low_pfn_mapped << PAGE_SHIFT;
487 if (!xen_start_info->mod_start || !ramdisk_size)
488 return; /* No initrd provided by bootloader */
493 if (ramdisk_size >= (end_of_lowmem>>1)) {
494 memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
495 printk(KERN_ERR "initrd too large to handle, "
496 "disabling initrd\n");
500 printk(KERN_INFO "RAMDISK: %08lx - %08lx\n", ramdisk_image,
504 if (ramdisk_end <= end_of_lowmem) {
505 /* All in lowmem, easy case */
507 * don't need to reserve again, already reserved early
508 * in i386_start_kernel
510 initrd_start = ramdisk_image + PAGE_OFFSET;
511 initrd_end = initrd_start + ramdisk_size;
512 #ifdef CONFIG_X86_64_XEN
513 initrd_below_start_ok = 1;
517 memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
519 #ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
520 acpi_initrd_offset = acpi_initrd_table_override((void *)initrd_start,
522 if (!acpi_initrd_offset)
524 printk(KERN_INFO "Found acpi tables of size: %lu at 0x%lx\n",
525 acpi_initrd_offset, initrd_start);
526 initrd_start += acpi_initrd_offset;
531 static void __init reserve_initrd(void)
534 #endif /* CONFIG_BLK_DEV_INITRD */
536 static void __init parse_setup_data(void)
539 struct setup_data *data;
542 if (boot_params.hdr.version < 0x0209)
544 pa_data = boot_params.hdr.setup_data;
546 u32 data_len, map_len;
548 map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK),
549 (u64)sizeof(struct setup_data));
550 data = early_memremap(pa_data, map_len);
551 data_len = data->len + sizeof(struct setup_data);
552 if (data_len > map_len) {
553 early_iounmap(data, map_len);
554 data = early_memremap(pa_data, data_len);
558 switch (data->type) {
560 parse_e820_ext(data);
568 pa_data = data->next;
569 early_iounmap(data, map_len);
574 static void __init e820_reserve_setup_data(void)
577 struct setup_data *data;
581 if (boot_params.hdr.version < 0x0209)
583 pa_data = boot_params.hdr.setup_data;
585 data = early_memremap(pa_data, sizeof(*data));
586 e820_update_range(pa_data, sizeof(*data)+data->len,
587 E820_RAM, E820_RESERVED_KERN);
589 pa_data = data->next;
590 early_iounmap(data, sizeof(*data));
595 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
596 memcpy(&e820_saved, &e820, sizeof(struct e820map));
597 printk(KERN_INFO "extended physical RAM map:\n");
598 e820_print_map("reserve setup_data");
602 static void __init memblock_x86_reserve_range_setup_data(void)
605 struct setup_data *data;
608 if (boot_params.hdr.version < 0x0209)
610 pa_data = boot_params.hdr.setup_data;
612 data = early_memremap(pa_data, sizeof(*data));
613 memblock_reserve(pa_data, sizeof(*data) + data->len);
614 pa_data = data->next;
615 early_iounmap(data, sizeof(*data));
622 * --------- Crashkernel reservation ------------------------------
628 * Keep the crash kernel below this limit. On 32 bits earlier kernels
629 * would limit the kernel to the low 512 MiB due to mapping restrictions.
630 * On 64 bits, kexec-tools currently limits us to 896 MiB; increase this
631 * limit once kexec-tools are fixed.
634 # define CRASH_KERNEL_ADDR_MAX (512 << 20)
636 # define CRASH_KERNEL_ADDR_MAX (896 << 20)
639 static void __init reserve_crashkernel(void)
641 unsigned long long total_mem;
642 unsigned long long crash_size, crash_base;
645 total_mem = memblock_phys_mem_size();
647 ret = parse_crashkernel(boot_command_line, total_mem,
648 &crash_size, &crash_base);
649 if (ret != 0 || crash_size <= 0)
652 /* 0 means: find the address automatically */
653 if (crash_base <= 0) {
654 const unsigned long long alignment = 16<<20; /* 16M */
657 * kexec want bzImage is below CRASH_KERNEL_ADDR_MAX
659 crash_base = memblock_find_in_range(alignment,
660 CRASH_KERNEL_ADDR_MAX, crash_size, alignment);
663 pr_info("crashkernel reservation failed - No suitable area found.\n");
667 unsigned long long start;
669 start = memblock_find_in_range(crash_base,
670 crash_base + crash_size, crash_size, 1<<20);
671 if (start != crash_base) {
672 pr_info("crashkernel reservation failed - memory is in use.\n");
676 memblock_reserve(crash_base, crash_size);
678 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
679 "for crashkernel (System RAM: %ldMB)\n",
680 (unsigned long)(crash_size >> 20),
681 (unsigned long)(crash_base >> 20),
682 (unsigned long)(total_mem >> 20));
684 crashk_res.start = crash_base;
685 crashk_res.end = crash_base + crash_size - 1;
686 insert_resource(&iomem_resource, &crashk_res);
689 static void __init reserve_crashkernel(void)
693 #endif /* CONFIG_XEN */
695 static struct resource standard_io_resources[] = {
696 { .name = "dma1", .start = 0x00, .end = 0x1f,
697 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
698 { .name = "pic1", .start = 0x20, .end = 0x21,
699 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
700 { .name = "timer0", .start = 0x40, .end = 0x43,
701 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
702 { .name = "timer1", .start = 0x50, .end = 0x53,
703 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
704 { .name = "keyboard", .start = 0x60, .end = 0x60,
705 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
706 { .name = "keyboard", .start = 0x64, .end = 0x64,
707 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
708 { .name = "dma page reg", .start = 0x80, .end = 0x8f,
709 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
710 { .name = "pic2", .start = 0xa0, .end = 0xa1,
711 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
712 { .name = "dma2", .start = 0xc0, .end = 0xdf,
713 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
714 { .name = "fpu", .start = 0xf0, .end = 0xff,
715 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
718 void __init reserve_standard_io_resources(void)
722 /* Nothing to do if not running in dom0. */
723 if (!is_initial_xendomain())
726 /* request I/O space for devices used on all i[345]86 PCs */
727 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
728 request_resource(&ioport_resource, &standard_io_resources[i]);
732 static __init void reserve_ibft_region(void)
734 unsigned long addr, size = 0;
736 addr = find_ibft_region(&size);
740 memblock_reserve(addr, size);
745 static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10;
747 static void __init trim_bios_range(void)
750 * A special case is the first 4Kb of memory;
751 * This is a BIOS owned area, not kernel ram, but generally
752 * not listed as such in the E820 table.
754 * This typically reserves additional memory (64KiB by default)
755 * since some BIOSes are known to corrupt low memory. See the
756 * Kconfig help text for X86_RESERVE_LOW.
758 e820_update_range(0, ALIGN(reserve_low, PAGE_SIZE),
759 E820_RAM, E820_RESERVED);
762 * special case: Some BIOSen report the PC BIOS
763 * area (640->1Mb) as ram even though it is not.
766 e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
767 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
770 static int __init parse_reservelow(char *p)
772 unsigned long long size;
777 size = memparse(p, &p);
790 early_param("reservelow", parse_reservelow);
794 * Determine if we were loaded by an EFI loader. If so, then we have also been
795 * passed the efi memmap, systab, etc., so we should use these data structures
796 * for initialization. Note, the efi init code path is determined by the
797 * global efi_enabled. This allows the same kernel image to be used on existing
798 * systems (with a traditional BIOS) as well as on EFI systems.
801 * setup_arch - architecture-specific boot-time initializations
803 * Note: On x86_64, fixmaps are ready for use even before this is called.
806 void __init setup_arch(char **cmdline_p)
809 unsigned long p2m_pages;
810 struct physdev_set_iopl set_iopl;
812 if (!is_initial_xendomain()) {
814 /* Force a quick death if the kernel panics (not domain 0). */
815 extern int panic_timeout;
820 /* Register a call for panic conditions. */
821 atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
825 WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl));
826 #endif /* CONFIG_XEN */
829 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
830 visws_early_detect();
834 * copy kernel address range established so far and switch
835 * to the proper swapper page table
837 clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY,
838 initial_page_table + KERNEL_PGD_BOUNDARY,
841 load_cr3(swapper_pg_dir);
845 printk(KERN_INFO "Command line: %s\n", boot_command_line);
849 * If we have OLPC OFW, we might end up relocating the fixmap due to
850 * reserve_top(), so do this before touching the ioremap area.
856 early_ioremap_init();
858 setup_olpc_ofw_pgd();
861 ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
862 screen_info = boot_params.screen_info;
863 edid_info = boot_params.edid_info;
865 apm_info.bios = boot_params.apm_bios_info;
866 ist_info = boot_params.ist_info;
867 if (boot_params.sys_desc_table.length != 0) {
868 set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
869 machine_id = boot_params.sys_desc_table.table[0];
870 machine_submodel_id = boot_params.sys_desc_table.table[1];
871 BIOS_revision = boot_params.sys_desc_table.table[2];
874 saved_video_mode = boot_params.hdr.vid_mode;
875 bootloader_type = boot_params.hdr.type_of_loader;
876 if ((bootloader_type >> 4) == 0xe) {
877 bootloader_type &= 0xf;
878 bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4;
880 bootloader_version = bootloader_type & 0xf;
881 bootloader_version |= boot_params.hdr.ext_loader_ver << 4;
883 #ifdef CONFIG_BLK_DEV_RAM
884 rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
885 rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
886 rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
889 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
893 } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
898 if (efi_enabled && efi_memblock_x86_reserve_range())
901 #else /* CONFIG_XEN */
903 /* This must be initialized to UNNAMED_MAJOR for ipconfig to work
904 properly. Setting ROOT_DEV to default to /dev/ram0 breaks initrd.
906 ROOT_DEV = MKDEV(UNNAMED_MAJOR,0);
908 ROOT_DEV = MKDEV(RAMDISK_MAJOR,0);
910 if (is_initial_xendomain()) {
911 const struct dom0_vga_console_info *info =
912 (void *)((char *)xen_start_info +
913 xen_start_info->console.dom0.info_off);
915 dom0_init_screen_info(info,
916 xen_start_info->console.dom0.info_size);
917 xen_start_info->console.domU.mfn = 0;
918 xen_start_info->console.domU.evtchn = 0;
922 screen_info.orig_video_isVGA = 0;
924 #endif /* CONFIG_XEN */
926 x86_init.oem.arch_setup();
928 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
931 /* update the e820_saved too */
932 e820_reserve_setup_data();
937 if (!boot_params.hdr.root_flags)
938 root_mountflags &= ~MS_RDONLY;
940 init_mm.start_code = (unsigned long) _text;
941 init_mm.end_code = (unsigned long) _etext;
942 init_mm.end_data = (unsigned long) _edata;
943 init_mm.brk = _brk_end;
945 code_resource.start = virt_to_phys(_text);
946 code_resource.end = virt_to_phys(_etext)-1;
947 data_resource.start = virt_to_phys(_etext);
948 data_resource.end = virt_to_phys(_edata)-1;
949 bss_resource.start = virt_to_phys(&__bss_start);
950 bss_resource.end = virt_to_phys(&__bss_stop)-1;
952 #ifdef CONFIG_CMDLINE_BOOL
953 #ifdef CONFIG_CMDLINE_OVERRIDE
954 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
956 if (builtin_cmdline[0]) {
957 /* append boot loader cmdline to builtin */
958 strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
959 strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
960 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
965 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
966 *cmdline_p = command_line;
969 * x86_configure_nx() is called before parse_early_param() to detect
970 * whether hardware doesn't support NX (so that the early EHCI debug
971 * console setup can safely call set_fixmap()). It may then be called
972 * again from within noexec_setup() during parsing early parameters
973 * to honor the respective command line option.
981 /* after early param, so could get panic from serial */
982 memblock_x86_reserve_range_setup_data();
984 if (acpi_mps_check()) {
985 #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_XEN)
988 setup_clear_cpu_cap(X86_FEATURE_APIC);
992 if (pci_early_dump_regs)
993 early_dump_pci_devices();
996 finish_e820_parsing();
1001 if (is_initial_xendomain())
1005 * VMware detection requires dmi to be available, so this
1006 * needs to be done after dmi_scan_machine, for the BP.
1008 init_hypervisor_platform();
1010 x86_init.resources.probe_roms();
1013 /* after parse_early_param, so could debug it */
1014 insert_resource(&iomem_resource, &code_resource);
1015 insert_resource(&iomem_resource, &data_resource);
1016 insert_resource(&iomem_resource, &bss_resource);
1019 #ifdef CONFIG_X86_32
1020 if (ppro_with_ram_bug()) {
1021 e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
1023 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
1024 printk(KERN_INFO "fixed physical RAM map:\n");
1025 e820_print_map("bad_ppro");
1028 early_gart_iommu_check();
1030 #endif /* CONFIG_XEN */
1033 * partially used pages are not usable - thus
1034 * we are rounding upwards:
1036 max_pfn = e820_end_of_ram_pfn();
1038 /* update e820 for memory not covered by WB MTRRs */
1041 if (mtrr_trim_uncached_memory(max_pfn))
1042 max_pfn = e820_end_of_ram_pfn();
1045 #ifdef CONFIG_X86_32
1046 /* max_low_pfn get updated here */
1047 find_low_pfn_range();
1049 num_physpages = max_pfn;
1050 max_mapnr = max_pfn;
1052 #ifdef CONFIG_X86_LOCAL_APIC
1056 /* How many end-of-memory variables you have, grandma! */
1057 /* need this before calling reserve_initrd */
1058 if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
1059 max_low_pfn = e820_end_of_low_ram_pfn();
1061 max_low_pfn = max_pfn;
1063 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
1067 * Find and reserve possible boot-time SMP configuration:
1071 reserve_ibft_region();
1074 * Need to conclude brk, before memblock_x86_fill()
1075 * it could use memblock_find_in_range, could overlap with
1082 memblock.current_limit = get_max_mapped();
1083 memblock_x86_fill();
1086 * The EFI specification says that boot service code won't be called
1087 * after ExitBootServices(). This is, in fact, a lie.
1090 efi_reserve_boot_services();
1092 /* preallocate 4k for mptable mpc */
1093 early_reserve_e820_mpc_new();
1095 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
1096 setup_bios_corruption_check();
1099 printk(KERN_DEBUG "initial memory mapped : 0 - %08lx\n",
1100 max_pfn_mapped<<PAGE_SHIFT);
1103 setup_trampolines();
1108 /* max_pfn_mapped is updated here */
1109 #ifdef CONFIG_X86_64_XEN
1110 if (xen_start_info->mfn_list < __START_KERNEL_map) {
1111 /* Map P2M space only after all usable memory. */
1112 unsigned long p2m_start = xen_start_info->first_p2m_pfn;
1113 unsigned long p2m_end = p2m_start
1114 + xen_start_info->nr_p2m_frames;
1117 max_low_pfn_mapped = init_memory_mapping(
1118 0, min(max_low_pfn, p2m_start) << PAGE_SHIFT);
1119 max_pfn_mapped = max_low_pfn_mapped;
1121 if (p2m_end < max_low_pfn)
1122 max_low_pfn_mapped = init_memory_mapping(
1123 p2m_end << PAGE_SHIFT,
1124 max_low_pfn << PAGE_SHIFT);
1125 max_pfn_mapped = max_low_pfn_mapped;
1127 if (max_low_pfn < p2m_start)
1128 max_pfn_mapped = init_memory_mapping(
1129 max_low_pfn << PAGE_SHIFT,
1130 p2m_start << PAGE_SHIFT);
1132 if (max(max_low_pfn, p2m_end) < max_pfn)
1133 max_pfn_mapped = init_memory_mapping(
1134 max(max_low_pfn, p2m_end) << PAGE_SHIFT,
1135 max_pfn << PAGE_SHIFT);
1137 temp = max_pfn_mapped;
1138 if (p2m_start < max_low_pfn) {
1139 temp = init_memory_mapping(
1140 p2m_start << PAGE_SHIFT,
1141 min(max_low_pfn, p2m_end) << PAGE_SHIFT);
1142 if (temp > max_low_pfn_mapped)
1143 max_low_pfn_mapped = temp;
1146 if (max_low_pfn < p2m_end)
1147 temp = init_memory_mapping(
1148 max(max_low_pfn, p2m_start) << PAGE_SHIFT,
1149 p2m_end << PAGE_SHIFT);
1150 if (temp > max_pfn_mapped)
1151 max_pfn_mapped = temp;
1153 goto init_memory_mapping_done;
1157 max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT);
1158 max_pfn_mapped = max_low_pfn_mapped;
1160 #ifdef CONFIG_X86_64
1161 if (max_pfn > max_low_pfn) {
1162 max_pfn_mapped = init_memory_mapping(1UL<<32,
1163 max_pfn<<PAGE_SHIFT);
1164 init_memory_mapping_done:
1165 /* can we preseve max_low_pfn ?*/
1166 max_low_pfn = max_pfn;
1169 memblock.current_limit = get_max_mapped();
1172 * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
1175 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
1176 if (init_ohci1394_dma_early)
1177 init_ohci1394_dma_on_all_controllers();
1179 /* Allocate bigger log buffer */
1185 reserve_crashkernel();
1193 if (!is_initial_xendomain()) {
1194 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
1200 * Parse the ACPI tables for possible boot-time SMP configuration.
1202 acpi_boot_table_init();
1204 early_acpi_boot_init();
1207 memblock_find_dma_reserve();
1209 #ifdef CONFIG_KVM_CLOCK
1213 x86_init.paging.pagetable_setup_start(swapper_pg_dir);
1215 x86_init.paging.pagetable_setup_done(swapper_pg_dir);
1217 if (boot_cpu_data.cpuid_level >= 0) {
1218 /* A CPU has %cr4 if and only if it has CPUID */
1219 mmu_cr4_features = read_cr4();
1222 #if defined(CONFIG_X86_32) && !defined(CONFIG_XEN)
1223 /* sync back kernel address range */
1224 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
1225 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
1231 #ifdef CONFIG_X86_64
1237 xen_machine_kexec_setup_resources();
1238 # define kexec_enabled() (crashk_res.start < crashk_res.end)
1240 # define kexec_enabled() 0
1242 p2m_pages = max_pfn;
1243 if (xen_start_info->nr_pages > max_pfn) {
1245 * the max_pfn was shrunk (probably by mem= or highmem=
1246 * kernel parameter); shrink reservation with the HV
1248 struct xen_memory_reservation reservation = {
1253 unsigned int difference;
1256 difference = xen_start_info->nr_pages - max_pfn;
1258 set_xen_guest_handle(reservation.extent_start,
1259 phys_to_machine_mapping + max_pfn);
1260 reservation.nr_extents = difference;
1261 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
1263 BUG_ON(ret != difference);
1264 } else if (max_pfn > xen_start_info->nr_pages)
1265 p2m_pages = xen_start_info->nr_pages;
1267 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
1268 /* Make sure we have a large enough P->M table. */
1269 phys_to_machine_mapping = alloc_bootmem_pages(
1270 max_pfn * sizeof(unsigned long));
1271 memcpy(phys_to_machine_mapping,
1272 __va(__pa(xen_start_info->mfn_list)),
1273 p2m_pages * sizeof(unsigned long));
1274 memset(phys_to_machine_mapping + p2m_pages, ~0,
1275 (max_pfn - p2m_pages) * sizeof(unsigned long));
1276 #ifdef CONFIG_X86_64
1277 if (xen_start_info->mfn_list == VMEMMAP_START) {
1279 * Since it is well isolated we can (and since it is
1280 * perhaps large we should) also free the page tables
1281 * mapping the initial P->M table.
1283 unsigned long va = VMEMMAP_START, pa;
1284 pgd_t *pgd = pgd_offset_k(va);
1285 pud_t *pud_page = pud_offset(pgd, 0);
1287 BUILD_BUG_ON(VMEMMAP_START & ~PGDIR_MASK);
1288 xen_l4_entry_update(pgd, __pgd(0));
1290 pud_t *pud = pud_page + pud_index(va);
1294 else if (pud_large(*pud)) {
1295 pa = pud_val(*pud) & PHYSICAL_PAGE_MASK;
1296 make_pages_writable(__va(pa),
1297 PUD_SIZE >> PAGE_SHIFT,
1298 XENFEAT_writable_page_tables);
1299 free_bootmem(pa, PUD_SIZE);
1302 pmd_t *pmd = pmd_offset(pud, va);
1304 if (pmd_large(*pmd)) {
1305 pa = pmd_val(*pmd) & PHYSICAL_PAGE_MASK;
1306 make_pages_writable(__va(pa),
1307 PMD_SIZE >> PAGE_SHIFT,
1308 XENFEAT_writable_page_tables);
1309 free_bootmem(pa, PMD_SIZE);
1310 } else if (!pmd_none(*pmd)) {
1312 pte_t *pte = pte_offset_kernel(pmd, va);
1314 for (i = 0; i < PTRS_PER_PTE; ++i) {
1315 if (pte_none(pte[i]))
1317 pa = pte_pfn(pte[i]) << PAGE_SHIFT;
1318 make_page_writable(__va(pa),
1319 XENFEAT_writable_page_tables);
1320 free_bootmem(pa, PAGE_SIZE);
1322 ClearPagePinned(virt_to_page(pte));
1323 make_page_writable(pte,
1324 XENFEAT_writable_page_tables);
1325 free_bootmem(__pa(pte), PAGE_SIZE);
1330 ClearPagePinned(virt_to_page(pmd));
1331 make_page_writable(pmd,
1332 XENFEAT_writable_page_tables);
1333 free_bootmem(__pa((unsigned long)pmd
1337 } while (pud_index(va));
1338 ClearPagePinned(virt_to_page(pud_page));
1339 make_page_writable(pud_page,
1340 XENFEAT_writable_page_tables);
1341 free_bootmem(__pa((unsigned long)pud_page & PAGE_MASK),
1343 } else if (!WARN_ON(xen_start_info->mfn_list
1344 < __START_KERNEL_map))
1346 free_bootmem(__pa(xen_start_info->mfn_list),
1347 PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
1348 sizeof(unsigned long))));
1350 if (!is_initial_xendomain() || kexec_enabled())
1351 setup_pfn_to_mfn_frame_list(__alloc_bootmem);
1354 #ifdef CONFIG_ISA_DMA_API
1355 # define ch p2m_pages
1356 /* Mark all ISA DMA channels in-use - using them wouldn't work. */
1357 for (ch = 0; ch < MAX_DMA_CHANNELS; ++ch)
1358 if (ch != 4 && request_dma(ch, "xen") != 0)
1362 #else /* CONFIG_XEN */
1363 generic_apic_probe();
1369 * Read APIC and some other early information from ACPI tables.
1376 * get boot-time SMP configuration:
1378 if (smp_found_config)
1381 prefill_possible_map();
1386 init_apic_mappings();
1387 ioapic_and_gsi_init();
1391 e820_reserve_resources();
1392 e820_mark_nosave_regions(max_low_pfn);
1394 if (is_initial_xendomain())
1395 e820_reserve_resources();
1398 x86_init.resources.reserve_resources();
1401 if (is_initial_xendomain())
1406 #ifdef CONFIG_DUMMY_CONSOLE
1407 conswitchp = &dummy_con;
1409 #ifdef CONFIG_VGA_CONSOLE
1411 if (!is_initial_xendomain())
1415 if (!efi_enabled || efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)
1416 conswitchp = &vga_con;
1419 x86_init.oem.banner();
1421 x86_init.timers.wallclock_init();
1423 x86_platform.wallclock_init();
1427 arch_init_ideal_nops();
1430 #ifdef CONFIG_X86_32
1432 static struct resource video_ram_resource = {
1433 .name = "Video RAM area",
1436 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
1439 void __init i386_reserve_resources(void)
1441 if (is_initial_xendomain())
1442 request_resource(&iomem_resource, &video_ram_resource);
1443 reserve_standard_io_resources();
1446 #endif /* CONFIG_X86_32 */
1450 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
1452 HYPERVISOR_shutdown(SHUTDOWN_crash);
1453 /* we're never actually going to get here... */
1456 #endif /* !CONFIG_XEN */