This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / x86_64 / kernel / head64-xen.c
1 /*
2  *  linux/arch/x86_64/kernel/head64.c -- prepare to run common code
3  *
4  *  Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
5  *
6  *  $Id: head64.c,v 1.22 2001/07/06 14:28:20 ak Exp $
7  *
8  *  Jun Nakajima <jun.nakajima@intel.com>
9  *      Modified for Xen.
10  */
11
12 #include <linux/init.h>
13 #include <linux/linkage.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/percpu.h>
18 #include <linux/module.h>
19
20 #include <asm/processor.h>
21 #include <asm/proto.h>
22 #include <asm/smp.h>
23 #include <asm/bootsetup.h>
24 #include <asm/setup.h>
25 #include <asm/desc.h>
26 #include <asm/pgtable.h>
27 #include <asm/sections.h>
28
29 unsigned long start_pfn;
30
31 /* Don't add a printk in there. printk relies on the PDA which is not initialized 
32    yet. */
33 #if 0
34 static void __init clear_bss(void)
35 {
36         memset(__bss_start, 0,
37                (unsigned long) __bss_stop - (unsigned long) __bss_start);
38 }
39 #endif
40
41 #define NEW_CL_POINTER          0x228   /* Relative to real mode data */
42 #define OLD_CL_MAGIC_ADDR       0x90020
43 #define OLD_CL_MAGIC            0xA33F
44 #define OLD_CL_BASE_ADDR        0x90000
45 #define OLD_CL_OFFSET           0x90022
46
47 extern char saved_command_line[];
48
49 static void __init copy_bootdata(char *real_mode_data)
50 {
51 #ifndef CONFIG_XEN
52         int new_data;
53         char * command_line;
54
55         memcpy(x86_boot_params, real_mode_data, BOOT_PARAM_SIZE);
56         new_data = *(int *) (x86_boot_params + NEW_CL_POINTER);
57         if (!new_data) {
58                 if (OLD_CL_MAGIC != * (u16 *) OLD_CL_MAGIC_ADDR) {
59                         printk("so old bootloader that it does not support commandline?!\n");
60                         return;
61                 }
62                 new_data = OLD_CL_BASE_ADDR + * (u16 *) OLD_CL_OFFSET;
63                 printk("old bootloader convention, maybe loadlin?\n");
64         }
65         command_line = (char *) ((u64)(new_data));
66         memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
67 #else
68         int max_cmdline;
69         
70         if ((max_cmdline = MAX_GUEST_CMDLINE) > COMMAND_LINE_SIZE)
71                 max_cmdline = COMMAND_LINE_SIZE;
72         memcpy(saved_command_line, xen_start_info->cmd_line, max_cmdline);
73         saved_command_line[max_cmdline-1] = '\0';
74 #endif
75         printk("Bootdata ok (command line is %s)\n", saved_command_line);
76 }
77
78 static void __init setup_boot_cpu_data(void)
79 {
80         unsigned int dummy, eax;
81
82         /* get vendor info */
83         cpuid(0, (unsigned int *)&boot_cpu_data.cpuid_level,
84               (unsigned int *)&boot_cpu_data.x86_vendor_id[0],
85               (unsigned int *)&boot_cpu_data.x86_vendor_id[8],
86               (unsigned int *)&boot_cpu_data.x86_vendor_id[4]);
87
88         /* get cpu type */
89         cpuid(1, &eax, &dummy, &dummy,
90                 (unsigned int *) &boot_cpu_data.x86_capability);
91         boot_cpu_data.x86 = (eax >> 8) & 0xf;
92         boot_cpu_data.x86_model = (eax >> 4) & 0xf;
93         boot_cpu_data.x86_mask = eax & 0xf;
94 }
95
96 #include <xen/interface/memory.h>
97 unsigned long *machine_to_phys_mapping;
98 EXPORT_SYMBOL(machine_to_phys_mapping);
99 unsigned int machine_to_phys_order;
100 EXPORT_SYMBOL(machine_to_phys_order);
101
102 void __init x86_64_start_kernel(char * real_mode_data)
103 {
104         struct xen_machphys_mapping mapping;
105         unsigned long machine_to_phys_nr_ents;
106         char *s;
107         int i;
108
109         xen_start_info = (struct start_info *)real_mode_data;
110         if (!xen_feature(XENFEAT_auto_translated_physmap)) {
111                 phys_to_machine_mapping =
112                         (unsigned long *)xen_start_info->mfn_list;
113                 start_pfn = (__pa(xen_start_info->pt_base) >> PAGE_SHIFT) +
114                         xen_start_info->nr_pt_frames;
115         }
116
117
118         machine_to_phys_mapping = (unsigned long *)MACH2PHYS_VIRT_START;
119         machine_to_phys_nr_ents = MACH2PHYS_NR_ENTRIES;
120         if (HYPERVISOR_memory_op(XENMEM_machphys_mapping, &mapping) == 0) {
121                 machine_to_phys_mapping = (unsigned long *)mapping.v_start;
122                 machine_to_phys_nr_ents = mapping.max_mfn + 1;
123         }
124         while ((1UL << machine_to_phys_order) < machine_to_phys_nr_ents )
125                 machine_to_phys_order++;
126
127 #if 0
128         for (i = 0; i < 256; i++)
129                 set_intr_gate(i, early_idt_handler);
130         asm volatile("lidt %0" :: "m" (idt_descr));
131 #endif
132
133         for (i = 0; i < NR_CPUS; i++)
134                 cpu_pda(i) = &boot_cpu_pda[i];
135
136         pda_init(0);
137         copy_bootdata(real_mode_data);
138 #ifdef CONFIG_SMP
139         cpu_set(0, cpu_online_map);
140 #endif
141         s = strstr(saved_command_line, "earlyprintk=");
142         if (s != NULL)
143                 setup_early_printk(strchr(s, '=') + 1);
144 #ifdef CONFIG_NUMA
145         s = strstr(saved_command_line, "numa=");
146         if (s != NULL)
147                 numa_setup(s+5);
148 #endif
149 #ifdef CONFIG_X86_IO_APIC
150         if (strstr(saved_command_line, "disableapic"))
151                 disable_apic = 1;
152 #endif
153         /* You need early console to see that */
154         if (__pa_symbol(&_end) >= KERNEL_TEXT_SIZE)
155                 panic("Kernel too big for kernel mapping\n");
156
157         setup_boot_cpu_data();
158         start_kernel();
159 }