- Update Xen patches to 3.4-rc6.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / kernel / setup-xen.c
1 /*
2  *  Copyright (C) 1995  Linus Torvalds
3  *
4  *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
5  *
6  *  Memory region support
7  *      David Parsons <orc@pell.chi.il.us>, July-August 1999
8  *
9  *  Added E820 sanitization routine (removes overlapping memory regions);
10  *  Brian Moyle <bmoyle@mvista.com>, February 2001
11  *
12  * Moved CPU detection code to cpu/${cpu}.c
13  *    Patrick Mochel <mochel@osdl.org>, March 2002
14  *
15  *  Provisions for empty E820 memory regions (reported by certain BIOSes).
16  *  Alex Achenbach <xela@slit.de>, December 2002.
17  *
18  */
19
20 /*
21  * This file handles the architecture-dependent parts of initialization
22  */
23
24 #include <linux/sched.h>
25 #include <linux/mm.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>
53
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>
61
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>
67
68 #include <linux/percpu.h>
69 #include <linux/crash_dump.h>
70 #include <linux/tboot.h>
71
72 #include <video/edid.h>
73
74 #include <asm/mtrr.h>
75 #include <asm/apic.h>
76 #include <asm/trampoline.h>
77 #include <asm/e820.h>
78 #include <asm/mpspec.h>
79 #include <asm/setup.h>
80 #include <asm/efi.h>
81 #include <asm/timer.h>
82 #include <asm/i8259.h>
83 #include <asm/sections.h>
84 #include <asm/dmi.h>
85 #include <asm/io_apic.h>
86 #include <asm/ist.h>
87 #include <asm/setup_arch.h>
88 #include <asm/bios_ebda.h>
89 #include <asm/cacheflush.h>
90 #include <asm/processor.h>
91 #include <asm/bugs.h>
92
93 #include <asm/vsyscall.h>
94 #include <asm/cpu.h>
95 #include <asm/desc.h>
96 #include <asm/dma.h>
97 #include <asm/iommu.h>
98 #include <asm/gart.h>
99 #include <asm/mmu_context.h>
100 #include <asm/proto.h>
101
102 #include <asm/paravirt.h>
103 #include <asm/hypervisor.h>
104 #include <asm/olpc_ofw.h>
105
106 #include <asm/percpu.h>
107 #include <asm/topology.h>
108 #include <asm/apicdef.h>
109 #include <asm/amd_nb.h>
110 #ifdef CONFIG_X86_64
111 #include <asm/numa_64.h>
112 #endif
113 #include <asm/mce.h>
114 #include <asm/alternative.h>
115 #include <asm/prom.h>
116
117 #ifdef CONFIG_XEN
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>
126
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 */
130 };
131
132 unsigned long *phys_to_machine_mapping;
133 EXPORT_SYMBOL(phys_to_machine_mapping);
134
135 static unsigned long *pfn_to_mfn_frame_list_list, **pfn_to_mfn_frame_list;
136
137 /* Raw start-of-day parameters from the hypervisor. */
138 start_info_t *xen_start_info;
139 EXPORT_SYMBOL(xen_start_info);
140 #endif
141
142 /*
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.
146  */
147 unsigned long max_low_pfn_mapped;
148 unsigned long max_pfn_mapped;
149
150 #ifdef CONFIG_DMI
151 RESERVE_BRK(dmi_alloc, 65536);
152 #endif
153
154
155 static __initdata unsigned long _brk_start = (unsigned long)__brk_base;
156 unsigned long _brk_end = (unsigned long)__brk_base;
157
158 #ifndef CONFIG_XEN
159 #ifdef CONFIG_X86_64
160 int default_cpu_present_to_apicid(int mps_cpu)
161 {
162         return __default_cpu_present_to_apicid(mps_cpu);
163 }
164
165 int default_check_phys_apicid_present(int phys_apicid)
166 {
167         return __default_check_phys_apicid_present(phys_apicid);
168 }
169 #endif
170
171 #ifndef CONFIG_DEBUG_BOOT_PARAMS
172 struct boot_params __initdata boot_params;
173 #else
174 struct boot_params boot_params;
175 #endif
176 #else /* CONFIG_XEN */
177 /*
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
180  * kexec/crash.
181  */
182 #ifdef CONFIG_PM_SLEEP
183 void
184 #else
185 static void __init
186 #endif
187 setup_pfn_to_mfn_frame_list(typeof(__alloc_bootmem) *__alloc_bootmem)
188 {
189         unsigned long i, j, size;
190         unsigned int k, fpp = PAGE_SIZE / sizeof(unsigned long);
191
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);
196         if (__alloc_bootmem)
197                 pfn_to_mfn_frame_list_list = alloc_bootmem_pages(size);
198         if (size > PAGE_SIZE
199             && xen_create_contiguous_region((unsigned long)
200                                             pfn_to_mfn_frame_list_list,
201                                             get_order(size), 0))
202                 BUG();
203         size -= sizeof(unsigned long);
204         if (__alloc_bootmem)
205                 pfn_to_mfn_frame_list = alloc_bootmem(size);
206
207         for (i = j = 0, k = -1; i < max_pfn; i += fpp, j++) {
208                 if (j == fpp)
209                         j = 0;
210                 if (j == 0) {
211                         k++;
212                         BUG_ON(k * sizeof(unsigned long) >= size);
213                         if (__alloc_bootmem)
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]);
218                 }
219                 pfn_to_mfn_frame_list[k][j] =
220                         virt_to_mfn(&phys_to_machine_mapping[i]);
221         }
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);
225 }
226 #endif
227
228 /*
229  * Machine setup..
230  */
231 static struct resource data_resource = {
232         .name   = "Kernel data",
233         .start  = 0,
234         .end    = 0,
235         .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
236 };
237
238 static struct resource code_resource = {
239         .name   = "Kernel code",
240         .start  = 0,
241         .end    = 0,
242         .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
243 };
244
245 static struct resource bss_resource = {
246         .name   = "Kernel bss",
247         .start  = 0,
248         .end    = 0,
249         .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
250 };
251
252
253 #ifdef CONFIG_X86_32
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);
259 #ifndef CONFIG_XEN
260 static void set_mca_bus(int x)
261 {
262 #ifdef CONFIG_MCA
263         MCA_bus = x;
264 #endif
265 }
266
267 unsigned int def_to_bigsmp;
268
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;
273
274 struct apm_info apm_info;
275 EXPORT_SYMBOL(apm_info);
276 #endif
277
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;
283 #endif
284
285 #else
286 struct cpuinfo_x86 boot_cpu_data __read_mostly = {
287         .x86_phys_bits = MAX_PHYSMEM_BITS,
288 };
289 EXPORT_SYMBOL(boot_cpu_data);
290 #endif
291
292
293 #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
294 unsigned long mmu_cr4_features;
295 #else
296 unsigned long mmu_cr4_features = X86_CR4_PAE;
297 #endif
298
299 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
300 int bootloader_type, bootloader_version;
301
302 /*
303  * Setup options
304  */
305 struct screen_info screen_info;
306 EXPORT_SYMBOL(screen_info);
307 struct edid_info edid_info;
308 EXPORT_SYMBOL_GPL(edid_info);
309
310 extern int root_mountflags;
311
312 unsigned long saved_video_mode;
313
314 #define RAMDISK_IMAGE_START_MASK        0x07FF
315 #define RAMDISK_PROMPT_FLAG             0x8000
316 #define RAMDISK_LOAD_FLAG               0x4000
317
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;
321 #endif
322
323 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
324 struct edd edd;
325 #ifdef CONFIG_EDD_MODULE
326 EXPORT_SYMBOL(edd);
327 #endif
328 #ifndef CONFIG_XEN
329 /**
330  * copy_edd() - Copy the BIOS EDD information
331  *              from boot_params into a safe place.
332  *
333  */
334 static inline void __init copy_edd(void)
335 {
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;
341 }
342 #endif
343 #else
344 static inline void __init copy_edd(void)
345 {
346 }
347 #endif
348
349 void * __init extend_brk(size_t size, size_t align)
350 {
351         size_t mask = align - 1;
352         void *ret;
353
354         BUG_ON(_brk_start == 0);
355         BUG_ON(align & mask);
356
357         _brk_end = (_brk_end + mask) & ~mask;
358         BUG_ON((char *)(_brk_end + size) > __brk_limit);
359
360         ret = (void *)_brk_end;
361         _brk_end += size;
362
363         memset(ret, 0, size);
364
365         return ret;
366 }
367
368 #if defined(CONFIG_X86_64) && !defined(CONFIG_XEN)
369 static void __init init_gbpages(void)
370 {
371         if (direct_gbpages && cpu_has_gbpages)
372                 printk(KERN_INFO "Using GB pages for direct mapping\n");
373         else
374                 direct_gbpages = 0;
375 }
376 #else
377 static inline void init_gbpages(void)
378 {
379 }
380 static void __init cleanup_highmap(void)
381 {
382 }
383 #endif
384
385 static void __init reserve_brk(void)
386 {
387         if (_brk_end > _brk_start)
388                 memblock_reserve(__pa(_brk_start),
389                                  __pa(_brk_end) - __pa(_brk_start));
390
391         /* Mark brk area as locked down and no longer taking any
392            new allocations */
393         _brk_start = 0;
394 }
395
396 #ifdef CONFIG_BLK_DEV_INITRD
397
398 #define MAX_MAP_CHUNK   (NR_FIX_BTMAPS << PAGE_SHIFT)
399 static void __init relocate_initrd(void)
400 {
401 #ifndef CONFIG_XEN
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;
407         u64 ramdisk_here;
408         unsigned long slop, clen, mapaddr;
409         char *p, *q;
410
411         /* We need to move the initrd down into lowmem */
412         ramdisk_here = memblock_find_in_range(0, end_of_lowmem, area_size,
413                                          PAGE_SIZE);
414
415         if (!ramdisk_here)
416                 panic("Cannot find place for new RAMDISK of size %lld\n",
417                          ramdisk_size);
418
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);
426
427         q = (char *)initrd_start;
428
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);
433                 memcpy(q, p, clen);
434                 q += clen;
435                 ramdisk_image += clen;
436                 ramdisk_size  -= clen;
437         }
438
439         /* Copy the highmem portion of the initrd */
440         while (ramdisk_size) {
441                 slop = ramdisk_image & ~PAGE_MASK;
442                 clen = ramdisk_size;
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);
449                 q += clen;
450                 ramdisk_image += clen;
451                 ramdisk_size  -= clen;
452         }
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);
460 #else
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);
465         initrd_start = 0;
466 #endif
467 }
468
469 static void __init reserve_initrd(void)
470 {
471         /* Assume only end is not page aligned */
472 #ifndef CONFIG_XEN
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;
477
478         if (!boot_params.hdr.type_of_loader ||
479             !ramdisk_image || !ramdisk_size)
480                 return;         /* No initrd provided by bootloader */
481 #else
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;
486
487         if (!xen_start_info->mod_start || !ramdisk_size)
488                 return;         /* No initrd provided by bootloader */
489 #endif
490
491         initrd_start = 0;
492
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");
497                 return;
498         }
499
500         printk(KERN_INFO "RAMDISK: %08lx - %08lx\n", ramdisk_image,
501                         ramdisk_end);
502
503
504         if (ramdisk_end <= end_of_lowmem) {
505                 /* All in lowmem, easy case */
506                 /*
507                  * don't need to reserve again, already reserved early
508                  * in i386_start_kernel
509                  */
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;
514 #endif
515         } else {
516                 relocate_initrd();
517                 memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
518         }
519 #ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
520         acpi_initrd_offset = acpi_initrd_table_override((void *)initrd_start,
521                                                         (void *)initrd_end);
522         if (!acpi_initrd_offset)
523                 return;
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;
527         return;
528 #endif
529 }
530 #else
531 static void __init reserve_initrd(void)
532 {
533 }
534 #endif /* CONFIG_BLK_DEV_INITRD */
535
536 static void __init parse_setup_data(void)
537 {
538 #ifndef CONFIG_XEN
539         struct setup_data *data;
540         u64 pa_data;
541
542         if (boot_params.hdr.version < 0x0209)
543                 return;
544         pa_data = boot_params.hdr.setup_data;
545         while (pa_data) {
546                 u32 data_len, map_len;
547
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);
555                         map_len = data_len;
556                 }
557
558                 switch (data->type) {
559                 case SETUP_E820_EXT:
560                         parse_e820_ext(data);
561                         break;
562                 case SETUP_DTB:
563                         add_dtb(pa_data);
564                         break;
565                 default:
566                         break;
567                 }
568                 pa_data = data->next;
569                 early_iounmap(data, map_len);
570         }
571 #endif
572 }
573
574 static void __init e820_reserve_setup_data(void)
575 {
576 #ifndef CONFIG_XEN
577         struct setup_data *data;
578         u64 pa_data;
579         int found = 0;
580
581         if (boot_params.hdr.version < 0x0209)
582                 return;
583         pa_data = boot_params.hdr.setup_data;
584         while (pa_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);
588                 found = 1;
589                 pa_data = data->next;
590                 early_iounmap(data, sizeof(*data));
591         }
592         if (!found)
593                 return;
594
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");
599 #endif
600 }
601
602 static void __init memblock_x86_reserve_range_setup_data(void)
603 {
604 #ifndef CONFIG_XEN
605         struct setup_data *data;
606         u64 pa_data;
607
608         if (boot_params.hdr.version < 0x0209)
609                 return;
610         pa_data = boot_params.hdr.setup_data;
611         while (pa_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));
616         }
617 #endif
618 }
619
620 #ifndef CONFIG_XEN
621 /*
622  * --------- Crashkernel reservation ------------------------------
623  */
624
625 #ifdef CONFIG_KEXEC
626
627 /*
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.
632  */
633 #ifdef CONFIG_X86_32
634 # define CRASH_KERNEL_ADDR_MAX  (512 << 20)
635 #else
636 # define CRASH_KERNEL_ADDR_MAX  (896 << 20)
637 #endif
638
639 static void __init reserve_crashkernel(void)
640 {
641         unsigned long long total_mem;
642         unsigned long long crash_size, crash_base;
643         int ret;
644
645         total_mem = memblock_phys_mem_size();
646
647         ret = parse_crashkernel(boot_command_line, total_mem,
648                         &crash_size, &crash_base);
649         if (ret != 0 || crash_size <= 0)
650                 return;
651
652         /* 0 means: find the address automatically */
653         if (crash_base <= 0) {
654                 const unsigned long long alignment = 16<<20;    /* 16M */
655
656                 /*
657                  *  kexec want bzImage is below CRASH_KERNEL_ADDR_MAX
658                  */
659                 crash_base = memblock_find_in_range(alignment,
660                                CRASH_KERNEL_ADDR_MAX, crash_size, alignment);
661
662                 if (!crash_base) {
663                         pr_info("crashkernel reservation failed - No suitable area found.\n");
664                         return;
665                 }
666         } else {
667                 unsigned long long start;
668
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");
673                         return;
674                 }
675         }
676         memblock_reserve(crash_base, crash_size);
677
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));
683
684         crashk_res.start = crash_base;
685         crashk_res.end   = crash_base + crash_size - 1;
686         insert_resource(&iomem_resource, &crashk_res);
687 }
688 #else
689 static void __init reserve_crashkernel(void)
690 {
691 }
692 #endif
693 #endif /* CONFIG_XEN */
694
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 }
716 };
717
718 void __init reserve_standard_io_resources(void)
719 {
720         int i;
721
722         /* Nothing to do if not running in dom0. */
723         if (!is_initial_xendomain())
724                 return;
725
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]);
729
730 }
731
732 static __init void reserve_ibft_region(void)
733 {
734         unsigned long addr, size = 0;
735
736         addr = find_ibft_region(&size);
737
738 #ifndef CONFIG_XEN
739         if (size)
740                 memblock_reserve(addr, size);
741 #endif
742 }
743
744 #ifndef CONFIG_XEN
745 static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10;
746
747 static void __init trim_bios_range(void)
748 {
749         /*
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.
753          *
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.
757          */
758         e820_update_range(0, ALIGN(reserve_low, PAGE_SIZE),
759                           E820_RAM, E820_RESERVED);
760
761         /*
762          * special case: Some BIOSen report the PC BIOS
763          * area (640->1Mb) as ram even though it is not.
764          * take them out.
765          */
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);
768 }
769
770 static int __init parse_reservelow(char *p)
771 {
772         unsigned long long size;
773
774         if (!p)
775                 return -EINVAL;
776
777         size = memparse(p, &p);
778
779         if (size < 4096)
780                 size = 4096;
781
782         if (size > 640*1024)
783                 size = 640*1024;
784
785         reserve_low = size;
786
787         return 0;
788 }
789
790 early_param("reservelow", parse_reservelow);
791 #endif
792
793 /*
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.
799  */
800 /*
801  * setup_arch - architecture-specific boot-time initializations
802  *
803  * Note: On x86_64, fixmaps are ready for use even before this is called.
804  */
805
806 void __init setup_arch(char **cmdline_p)
807 {
808 #ifdef CONFIG_XEN
809         unsigned long p2m_pages;
810         struct physdev_set_iopl set_iopl;
811
812         if (!is_initial_xendomain()) {
813 #ifdef CONFIG_X86_32
814                 /* Force a quick death if the kernel panics (not domain 0). */
815                 extern int panic_timeout;
816                 if (!panic_timeout)
817                         panic_timeout = 1;
818 #endif
819
820                 /* Register a call for panic conditions. */
821                 atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
822         }
823
824         set_iopl.iopl = 1;
825         WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl));
826 #endif /* CONFIG_XEN */
827
828 #ifdef CONFIG_X86_32
829         memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
830         visws_early_detect();
831
832 #ifndef CONFIG_XEN
833         /*
834          * copy kernel address range established so far and switch
835          * to the proper swapper page table
836          */
837         clone_pgd_range(swapper_pg_dir     + KERNEL_PGD_BOUNDARY,
838                         initial_page_table + KERNEL_PGD_BOUNDARY,
839                         KERNEL_PGD_PTRS);
840
841         load_cr3(swapper_pg_dir);
842         __flush_tlb_all();
843 #endif
844 #else
845         printk(KERN_INFO "Command line: %s\n", boot_command_line);
846 #endif
847
848         /*
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.
851          */
852         olpc_ofw_detect();
853
854         early_trap_init();
855         early_cpu_init();
856         early_ioremap_init();
857
858         setup_olpc_ofw_pgd();
859
860 #ifndef CONFIG_XEN
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;
864 #ifdef CONFIG_X86_32
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];
872         }
873 #endif
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;
879         }
880         bootloader_version  = bootloader_type & 0xf;
881         bootloader_version |= boot_params.hdr.ext_loader_ver << 4;
882
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);
887 #endif
888 #ifdef CONFIG_EFI
889         if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
890                      "EL32", 4)) {
891                 efi_enabled = 1;
892                 efi_64bit = false;
893         } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
894                      "EL64", 4)) {
895                 efi_enabled = 1;
896                 efi_64bit = true;
897         }
898         if (efi_enabled && efi_memblock_x86_reserve_range())
899                 efi_enabled = 0;
900 #endif
901 #else /* CONFIG_XEN */
902 #ifdef CONFIG_X86_32
903         /* This must be initialized to UNNAMED_MAJOR for ipconfig to work
904            properly.  Setting ROOT_DEV to default to /dev/ram0 breaks initrd.
905         */
906         ROOT_DEV = MKDEV(UNNAMED_MAJOR,0);
907 #else
908         ROOT_DEV = MKDEV(RAMDISK_MAJOR,0);
909 #endif
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);
914
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;
919
920                 efi_probe();
921         } else
922                 screen_info.orig_video_isVGA = 0;
923         copy_edid();
924 #endif /* CONFIG_XEN */
925
926         x86_init.oem.arch_setup();
927
928         iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
929         setup_memory_map();
930         parse_setup_data();
931         /* update the e820_saved too */
932         e820_reserve_setup_data();
933
934         copy_edd();
935
936 #ifndef CONFIG_XEN
937         if (!boot_params.hdr.root_flags)
938                 root_mountflags &= ~MS_RDONLY;
939 #endif
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;
944
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;
951
952 #ifdef CONFIG_CMDLINE_BOOL
953 #ifdef CONFIG_CMDLINE_OVERRIDE
954         strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
955 #else
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);
961         }
962 #endif
963 #endif
964
965         strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
966         *cmdline_p = command_line;
967
968         /*
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.
974          */
975         x86_configure_nx();
976
977         parse_early_param();
978
979         x86_report_nx();
980
981         /* after early param, so could get panic from serial */
982         memblock_x86_reserve_range_setup_data();
983
984         if (acpi_mps_check()) {
985 #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_XEN)
986                 disable_apic = 1;
987 #endif
988                 setup_clear_cpu_cap(X86_FEATURE_APIC);
989         }
990
991 #ifdef CONFIG_PCI
992         if (pci_early_dump_regs)
993                 early_dump_pci_devices();
994 #endif
995
996         finish_e820_parsing();
997
998         if (efi_enabled)
999                 efi_init();
1000
1001         if (is_initial_xendomain())
1002                 dmi_scan_machine();
1003
1004         /*
1005          * VMware detection requires dmi to be available, so this
1006          * needs to be done after dmi_scan_machine, for the BP.
1007          */
1008         init_hypervisor_platform();
1009
1010         x86_init.resources.probe_roms();
1011
1012 #ifndef CONFIG_XEN
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);
1017
1018         trim_bios_range();
1019 #ifdef CONFIG_X86_32
1020         if (ppro_with_ram_bug()) {
1021                 e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
1022                                   E820_RESERVED);
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");
1026         }
1027 #else
1028         early_gart_iommu_check();
1029 #endif
1030 #endif /* CONFIG_XEN */
1031
1032         /*
1033          * partially used pages are not usable - thus
1034          * we are rounding upwards:
1035          */
1036         max_pfn = e820_end_of_ram_pfn();
1037
1038         /* update e820 for memory not covered by WB MTRRs */
1039         mtrr_bp_init();
1040 #ifndef CONFIG_XEN
1041         if (mtrr_trim_uncached_memory(max_pfn))
1042                 max_pfn = e820_end_of_ram_pfn();
1043 #endif
1044
1045 #ifdef CONFIG_X86_32
1046         /* max_low_pfn get updated here */
1047         find_low_pfn_range();
1048 #else
1049         num_physpages = max_pfn;
1050         max_mapnr = max_pfn;
1051
1052 #ifdef CONFIG_X86_LOCAL_APIC
1053         check_x2apic();
1054 #endif
1055
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();
1060         else
1061                 max_low_pfn = max_pfn;
1062
1063         high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
1064 #endif
1065
1066         /*
1067          * Find and reserve possible boot-time SMP configuration:
1068          */
1069         find_smp_config();
1070
1071         reserve_ibft_region();
1072
1073         /*
1074          * Need to conclude brk, before memblock_x86_fill()
1075          *  it could use memblock_find_in_range, could overlap with
1076          *  brk area.
1077          */
1078         reserve_brk();
1079
1080         cleanup_highmap();
1081
1082         memblock.current_limit = get_max_mapped();
1083         memblock_x86_fill();
1084
1085         /*
1086          * The EFI specification says that boot service code won't be called
1087          * after ExitBootServices(). This is, in fact, a lie.
1088          */
1089         if (efi_enabled)
1090                 efi_reserve_boot_services();
1091
1092         /* preallocate 4k for mptable mpc */
1093         early_reserve_e820_mpc_new();
1094
1095 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
1096         setup_bios_corruption_check();
1097 #endif
1098
1099         printk(KERN_DEBUG "initial memory mapped : 0 - %08lx\n",
1100                         max_pfn_mapped<<PAGE_SHIFT);
1101
1102 #ifndef CONFIG_XEN
1103         setup_trampolines();
1104 #endif
1105
1106         init_gbpages();
1107
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;
1115                 unsigned long temp;
1116
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;
1120
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;
1126
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);
1131
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);
1136
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;
1144                 }
1145
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;
1152
1153                 goto init_memory_mapping_done;
1154         }
1155 #endif
1156
1157         max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT);
1158         max_pfn_mapped = max_low_pfn_mapped;
1159
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;
1167         }
1168 #endif
1169         memblock.current_limit = get_max_mapped();
1170
1171         /*
1172          * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
1173          */
1174
1175 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
1176         if (init_ohci1394_dma_early)
1177                 init_ohci1394_dma_on_all_controllers();
1178 #endif
1179         /* Allocate bigger log buffer */
1180         setup_log_buf(1);
1181
1182         reserve_initrd();
1183
1184 #ifndef CONFIG_XEN
1185         reserve_crashkernel();
1186
1187         vsmp_init();
1188 #endif
1189
1190         io_delay_init();
1191
1192 #ifdef CONFIG_ACPI
1193         if (!is_initial_xendomain()) {
1194                 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
1195                 disable_acpi();
1196         }
1197 #endif
1198
1199         /*
1200          * Parse the ACPI tables for possible boot-time SMP configuration.
1201          */
1202         acpi_boot_table_init();
1203
1204         early_acpi_boot_init();
1205
1206         initmem_init();
1207         memblock_find_dma_reserve();
1208
1209 #ifdef CONFIG_KVM_CLOCK
1210         kvmclock_init();
1211 #endif
1212
1213         x86_init.paging.pagetable_setup_start(swapper_pg_dir);
1214         paging_init();
1215         x86_init.paging.pagetable_setup_done(swapper_pg_dir);
1216
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();
1220         }
1221
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,
1226                         KERNEL_PGD_PTRS);
1227 #endif
1228
1229         tboot_probe();
1230
1231 #ifdef CONFIG_X86_64
1232         map_vsyscall();
1233 #endif
1234
1235 #ifdef CONFIG_XEN
1236 #ifdef CONFIG_KEXEC
1237         xen_machine_kexec_setup_resources();
1238 # define kexec_enabled() (crashk_res.start < crashk_res.end)
1239 #else
1240 # define kexec_enabled() 0
1241 #endif
1242         p2m_pages = max_pfn;
1243         if (xen_start_info->nr_pages > max_pfn) {
1244                 /*
1245                  * the max_pfn was shrunk (probably by mem= or highmem=
1246                  * kernel parameter); shrink reservation with the HV
1247                  */
1248                 struct xen_memory_reservation reservation = {
1249                         .address_bits = 0,
1250                         .extent_order = 0,
1251                         .domid = DOMID_SELF
1252                 };
1253                 unsigned int difference;
1254                 int ret;
1255
1256                 difference = xen_start_info->nr_pages - max_pfn;
1257
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,
1262                                            &reservation);
1263                 BUG_ON(ret != difference);
1264         } else if (max_pfn > xen_start_info->nr_pages)
1265                 p2m_pages = xen_start_info->nr_pages;
1266
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) {
1278                         /*
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.
1282                          */
1283                         unsigned long va = VMEMMAP_START, pa;
1284                         pgd_t *pgd = pgd_offset_k(va);
1285                         pud_t *pud_page = pud_offset(pgd, 0);
1286
1287                         BUILD_BUG_ON(VMEMMAP_START & ~PGDIR_MASK);
1288                         xen_l4_entry_update(pgd, __pgd(0));
1289                         do {
1290                                 pud_t *pud = pud_page + pud_index(va);
1291
1292                                 if (pud_none(*pud))
1293                                         va += PUD_SIZE;
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);
1300                                         va += PUD_SIZE;
1301                                 } else {
1302                                         pmd_t *pmd = pmd_offset(pud, va);
1303
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)) {
1311                                                 unsigned int i;
1312                                                 pte_t *pte = pte_offset_kernel(pmd, va);
1313
1314                                                 for (i = 0; i < PTRS_PER_PTE; ++i) {
1315                                                         if (pte_none(pte[i]))
1316                                                                 break;
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);
1321                                                 }
1322                                                 ClearPagePinned(virt_to_page(pte));
1323                                                 make_page_writable(pte,
1324                                                         XENFEAT_writable_page_tables);
1325                                                 free_bootmem(__pa(pte), PAGE_SIZE);
1326                                         }
1327                                         va += PMD_SIZE;
1328                                         if (pmd_index(va))
1329                                                 continue;
1330                                         ClearPagePinned(virt_to_page(pmd));
1331                                         make_page_writable(pmd,
1332                                                 XENFEAT_writable_page_tables);
1333                                         free_bootmem(__pa((unsigned long)pmd
1334                                                           & PAGE_MASK),
1335                                                      PAGE_SIZE);
1336                                 }
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),
1342                                      PAGE_SIZE);
1343                 } else if (!WARN_ON(xen_start_info->mfn_list
1344                                     < __START_KERNEL_map))
1345 #endif
1346                         free_bootmem(__pa(xen_start_info->mfn_list),
1347                                      PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
1348                                                      sizeof(unsigned long))));
1349
1350                 if (!is_initial_xendomain() || kexec_enabled())
1351                         setup_pfn_to_mfn_frame_list(__alloc_bootmem);
1352         }
1353
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)
1359                         BUG();
1360 # undef ch
1361 #endif
1362 #else /* CONFIG_XEN */
1363         generic_apic_probe();
1364
1365         early_quirks();
1366 #endif
1367
1368         /*
1369          * Read APIC and some other early information from ACPI tables.
1370          */
1371         acpi_boot_init();
1372         sfi_init();
1373         x86_dtb_init();
1374
1375         /*
1376          * get boot-time SMP configuration:
1377          */
1378         if (smp_found_config)
1379                 get_smp_config();
1380
1381         prefill_possible_map();
1382
1383         init_cpu_to_node();
1384
1385 #ifndef CONFIG_XEN
1386         init_apic_mappings();
1387         ioapic_and_gsi_init();
1388
1389         kvm_guest_init();
1390
1391         e820_reserve_resources();
1392         e820_mark_nosave_regions(max_low_pfn);
1393 #else
1394         if (is_initial_xendomain())
1395                 e820_reserve_resources();
1396 #endif
1397
1398         x86_init.resources.reserve_resources();
1399
1400 #ifdef CONFIG_XEN
1401         if (is_initial_xendomain())
1402 #endif
1403                 e820_setup_gap();
1404
1405 #ifdef CONFIG_VT
1406 #ifdef CONFIG_DUMMY_CONSOLE
1407         conswitchp = &dummy_con;
1408 #endif
1409 #ifdef CONFIG_VGA_CONSOLE
1410 #ifdef CONFIG_XEN
1411         if (!is_initial_xendomain())
1412                 ;
1413         else
1414 #endif
1415         if (!efi_enabled || efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)
1416                 conswitchp = &vga_con;
1417 #endif
1418 #endif
1419         x86_init.oem.banner();
1420
1421         x86_init.timers.wallclock_init();
1422
1423         x86_platform.wallclock_init();
1424
1425         mcheck_init();
1426
1427         arch_init_ideal_nops();
1428 }
1429
1430 #ifdef CONFIG_X86_32
1431
1432 static struct resource video_ram_resource = {
1433         .name   = "Video RAM area",
1434         .start  = 0xa0000,
1435         .end    = 0xbffff,
1436         .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
1437 };
1438
1439 void __init i386_reserve_resources(void)
1440 {
1441         if (is_initial_xendomain())
1442                 request_resource(&iomem_resource, &video_ram_resource);
1443         reserve_standard_io_resources();
1444 }
1445
1446 #endif /* CONFIG_X86_32 */
1447
1448 #ifdef CONFIG_XEN
1449 static int
1450 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
1451 {
1452         HYPERVISOR_shutdown(SHUTDOWN_crash);
1453         /* we're never actually going to get here... */
1454         return NOTIFY_DONE;
1455 }
1456 #endif /* !CONFIG_XEN */