- Update Xen patches to 3.3-rc5 and c/s 1157.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / kernel / head64-xen.c
1 /*
2  *  prepare to run common code
3  *
4  *  Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
5  *
6  *  Jun Nakajima <jun.nakajima@intel.com>
7  *      Modified for Xen.
8  */
9
10 #include <linux/init.h>
11 #include <linux/linkage.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/percpu.h>
16 #include <linux/start_kernel.h>
17 #include <linux/io.h>
18 #include <linux/memblock.h>
19
20 #include <asm/processor.h>
21 #include <asm/proto.h>
22 #include <asm/smp.h>
23 #include <asm/setup.h>
24 #include <asm/desc.h>
25 #include <asm/pgtable.h>
26 #include <asm/tlbflush.h>
27 #include <asm/sections.h>
28 #include <asm/kdebug.h>
29 #include <asm/e820.h>
30 #include <asm/trampoline.h>
31 #include <asm/bios_ebda.h>
32
33 #ifndef CONFIG_XEN
34 static void __init zap_identity_mappings(void)
35 {
36         pgd_t *pgd = pgd_offset_k(0UL);
37         pgd_clear(pgd);
38         __flush_tlb_all();
39 }
40
41 /* Don't add a printk in there. printk relies on the PDA which is not initialized 
42    yet. */
43 static void __init clear_bss(void)
44 {
45         memset(__bss_start, 0,
46                (unsigned long) __bss_stop - (unsigned long) __bss_start);
47 }
48 #endif
49
50 static void __init copy_bootdata(char *real_mode_data)
51 {
52 #ifndef CONFIG_XEN
53         char * command_line;
54
55         memcpy(&boot_params, real_mode_data, sizeof boot_params);
56         if (boot_params.hdr.cmd_line_ptr) {
57                 command_line = __va(boot_params.hdr.cmd_line_ptr);
58                 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
59         }
60 #else
61         int max_cmdline;
62         
63         if ((max_cmdline = MAX_GUEST_CMDLINE) > COMMAND_LINE_SIZE)
64                 max_cmdline = COMMAND_LINE_SIZE;
65         memcpy(boot_command_line, xen_start_info->cmd_line, max_cmdline);
66         boot_command_line[max_cmdline-1] = '\0';
67 #endif
68 }
69
70 #include <xen/interface/memory.h>
71
72 void __init x86_64_start_kernel(char * real_mode_data)
73 {
74         /*
75          * Build-time sanity checks on the kernel image and module
76          * area mappings. (these are purely build-time and produce no code)
77          */
78         BUILD_BUG_ON(MODULES_VADDR < KERNEL_IMAGE_START);
79         BUILD_BUG_ON(MODULES_VADDR-KERNEL_IMAGE_START < KERNEL_IMAGE_SIZE);
80         BUILD_BUG_ON(MODULES_LEN + KERNEL_IMAGE_SIZE > 2*PUD_SIZE);
81         BUILD_BUG_ON((KERNEL_IMAGE_START & ~PMD_MASK) != 0);
82         BUILD_BUG_ON((MODULES_VADDR & ~PMD_MASK) != 0);
83         BUILD_BUG_ON(!(MODULES_VADDR > __START_KERNEL));
84         BUILD_BUG_ON(!(((MODULES_END - 1) & PGDIR_MASK) ==
85                                 (__START_KERNEL & PGDIR_MASK)));
86         BUILD_BUG_ON(__fix_to_virt(__end_of_fixed_addresses) <= MODULES_END);
87
88         xen_start_info = (struct start_info *)real_mode_data;
89         xen_start_kernel();
90
91 #ifndef CONFIG_XEN
92         /* clear bss before set_intr_gate with early_idt_handler */
93         clear_bss();
94
95         /* Make NULL pointers segfault */
96         zap_identity_mappings();
97
98         for (i = 0; i < NUM_EXCEPTION_VECTORS; i++) {
99 #ifdef CONFIG_EARLY_PRINTK
100                 set_intr_gate(i, &early_idt_handlers[i]);
101 #else
102                 set_intr_gate(i, early_idt_handler);
103 #endif
104         }
105         load_idt((const struct desc_ptr *)&idt_descr);
106 #endif
107
108         if (console_loglevel == 10)
109                 early_printk("Kernel alive\n");
110
111         xen_switch_pt();
112
113         x86_64_start_reservations(real_mode_data);
114 }
115
116 void __init x86_64_start_reservations(char *real_mode_data)
117 {
118         copy_bootdata(__va(real_mode_data));
119
120         memblock_reserve(__pa_symbol(&_text),
121                          __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
122
123 #ifdef CONFIG_BLK_DEV_INITRD
124         /* Reserve INITRD if needed. */
125         if (xen_start_info->flags & SIF_MOD_START_PFN) {
126                 reserve_pfn_range(xen_start_info->mod_start,
127                                   PFN_UP(xen_start_info->mod_len));
128                 xen_initrd_start = xen_start_info->mod_start << PAGE_SHIFT;
129         } else if (xen_start_info->mod_start)
130                 xen_initrd_start = __pa(xen_start_info->mod_start);
131 #endif
132
133         if (xen_feature(XENFEAT_auto_translated_physmap))
134                 xen_start_info->mfn_list = ~0UL;
135         else if (xen_start_info->mfn_list < __START_KERNEL_map)
136                 reserve_pfn_range(xen_start_info->first_p2m_pfn,
137                                   xen_start_info->nr_p2m_frames);
138
139         /*
140          * At this point everything still needed from the boot loader
141          * or BIOS or kernel text should be early reserved or marked not
142          * RAM in e820. All other memory is free game.
143          */
144
145         start_kernel();
146 }