Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / arch / i386 / mach-xen / setup.c
1 /*
2  *      Machine specific setup for generic
3  */
4
5 #include <linux/smp.h>
6 #include <linux/init.h>
7 #include <linux/interrupt.h>
8 #include <linux/module.h>
9 #include <asm/acpi.h>
10 #include <asm/arch_hooks.h>
11 #include <asm/e820.h>
12 #include <asm/setup.h>
13 #include <asm/fixmap.h>
14
15 #include <xen/interface/callback.h>
16 #include <xen/interface/memory.h>
17
18 #ifdef CONFIG_HOTPLUG_CPU
19 #define DEFAULT_SEND_IPI        (1)
20 #else
21 #define DEFAULT_SEND_IPI        (0)
22 #endif
23
24 int no_broadcast=DEFAULT_SEND_IPI;
25
26 static __init int no_ipi_broadcast(char *str)
27 {
28         get_option(&str, &no_broadcast);
29         printk ("Using %s mode\n", no_broadcast ? "No IPI Broadcast" :
30                                                                                         "IPI Broadcast");
31         return 1;
32 }
33
34 __setup("no_ipi_broadcast", no_ipi_broadcast);
35
36 static int __init print_ipi_mode(void)
37 {
38         printk ("Using IPI %s mode\n", no_broadcast ? "No-Shortcut" :
39                                                                                         "Shortcut");
40         return 0;
41 }
42
43 late_initcall(print_ipi_mode);
44
45 /**
46  * machine_specific_memory_setup - Hook for machine specific memory setup.
47  *
48  * Description:
49  *      This is included late in kernel/setup.c so that it can make
50  *      use of all of the static functions.
51  **/
52
53 char * __init machine_specific_memory_setup(void)
54 {
55         int rc;
56         struct xen_memory_map memmap;
57         /*
58          * This is rather large for a stack variable but this early in
59          * the boot process we know we have plenty slack space.
60          */
61         struct e820entry map[E820MAX];
62
63         memmap.nr_entries = E820MAX;
64         set_xen_guest_handle(memmap.buffer, map);
65
66         rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
67         if ( rc == -ENOSYS ) {
68                 memmap.nr_entries = 1;
69                 map[0].addr = 0ULL;
70                 map[0].size = PFN_PHYS(xen_start_info->nr_pages);
71                 /* 8MB slack (to balance backend allocations). */
72                 map[0].size += 8ULL << 20;
73                 map[0].type = E820_RAM;
74                 rc = 0;
75         }
76         BUG_ON(rc);
77
78         sanitize_e820_map(map, (char *)&memmap.nr_entries);
79
80         BUG_ON(copy_e820_map(map, (char)memmap.nr_entries) < 0);
81
82         return "Xen";
83 }
84
85 extern void hypervisor_callback(void);
86 extern void failsafe_callback(void);
87 extern void nmi(void);
88
89 unsigned long *machine_to_phys_mapping;
90 EXPORT_SYMBOL(machine_to_phys_mapping);
91 unsigned int machine_to_phys_order;
92 EXPORT_SYMBOL(machine_to_phys_order);
93
94 void __init machine_specific_arch_setup(void)
95 {
96         int ret;
97         struct xen_machphys_mapping mapping;
98         unsigned long machine_to_phys_nr_ents;
99         struct xen_platform_parameters pp;
100         struct callback_register event = {
101                 .type = CALLBACKTYPE_event,
102                 .address = { __KERNEL_CS, (unsigned long)hypervisor_callback },
103         };
104         struct callback_register failsafe = {
105                 .type = CALLBACKTYPE_failsafe,
106                 .address = { __KERNEL_CS, (unsigned long)failsafe_callback },
107         };
108         struct callback_register nmi_cb = {
109                 .type = CALLBACKTYPE_nmi,
110                 .address = { __KERNEL_CS, (unsigned long)nmi },
111         };
112
113         ret = HYPERVISOR_callback_op(CALLBACKOP_register, &event);
114         if (ret == 0)
115                 ret = HYPERVISOR_callback_op(CALLBACKOP_register, &failsafe);
116         if (ret == -ENOSYS)
117                 ret = HYPERVISOR_set_callbacks(
118                         event.address.cs, event.address.eip,
119                         failsafe.address.cs, failsafe.address.eip);
120         BUG_ON(ret);
121
122         ret = HYPERVISOR_callback_op(CALLBACKOP_register, &nmi_cb);
123         if (ret == -ENOSYS) {
124                 struct xennmi_callback cb;
125
126                 cb.handler_address = nmi_cb.address.eip;
127                 HYPERVISOR_nmi_op(XENNMI_register_callback, &cb);
128         }
129
130         if (HYPERVISOR_xen_version(XENVER_platform_parameters,
131                                    &pp) == 0)
132                 set_fixaddr_top(pp.virt_start - PAGE_SIZE);
133
134         machine_to_phys_mapping = (unsigned long *)MACH2PHYS_VIRT_START;
135         machine_to_phys_nr_ents = MACH2PHYS_NR_ENTRIES;
136         if (HYPERVISOR_memory_op(XENMEM_machphys_mapping, &mapping) == 0) {
137                 machine_to_phys_mapping = (unsigned long *)mapping.v_start;
138                 machine_to_phys_nr_ents = mapping.max_mfn + 1;
139         }
140         while ((1UL << machine_to_phys_order) < machine_to_phys_nr_ents )
141                 machine_to_phys_order++;
142 }
143
144 /**
145  * pre_setup_arch_hook - hook called prior to any setup_arch() execution
146  *
147  * Description:
148  *      generally used to activate any machine specific identification
149  *      routines that may be needed before setup_arch() runs.  On VISWS
150  *      this is used to get the board revision and type.
151  **/
152 void __init pre_setup_arch_hook(void)
153 {
154 }