]>
Commit | Line | Data |
---|---|---|
5ead97c8 JF |
1 | /* |
2 | * Machine specific setup for xen | |
3 | * | |
4 | * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007 | |
5 | */ | |
6 | ||
7 | #include <linux/module.h> | |
8 | #include <linux/sched.h> | |
9 | #include <linux/mm.h> | |
10 | #include <linux/pm.h> | |
11 | ||
12 | #include <asm/elf.h> | |
6c3652ef | 13 | #include <asm/vdso.h> |
5ead97c8 JF |
14 | #include <asm/e820.h> |
15 | #include <asm/setup.h> | |
b792c755 | 16 | #include <asm/acpi.h> |
5ead97c8 JF |
17 | #include <asm/xen/hypervisor.h> |
18 | #include <asm/xen/hypercall.h> | |
19 | ||
8006ec3e | 20 | #include <xen/page.h> |
e2a81baf | 21 | #include <xen/interface/callback.h> |
5ead97c8 JF |
22 | #include <xen/interface/physdev.h> |
23 | #include <xen/features.h> | |
24 | ||
25 | #include "xen-ops.h" | |
d2eea68e | 26 | #include "vdso.h" |
5ead97c8 JF |
27 | |
28 | /* These are code, but not functions. Defined in entry.S */ | |
29 | extern const char xen_hypervisor_callback[]; | |
30 | extern const char xen_failsafe_callback[]; | |
31 | ||
5ead97c8 JF |
32 | |
33 | /** | |
34 | * machine_specific_memory_setup - Hook for machine specific memory setup. | |
35 | **/ | |
36 | ||
37 | char * __init xen_memory_setup(void) | |
38 | { | |
39 | unsigned long max_pfn = xen_start_info->nr_pages; | |
40 | ||
8006ec3e JF |
41 | max_pfn = min(MAX_DOMAIN_PAGES, max_pfn); |
42 | ||
5ead97c8 | 43 | e820.nr_map = 0; |
be5bf9fa | 44 | |
b792c755 JF |
45 | e820_add_region(0, PFN_PHYS(max_pfn), E820_RAM); |
46 | ||
47 | /* | |
48 | * Even though this is normal, usable memory under Xen, reserve | |
49 | * ISA memory anyway because too many things think they can poke | |
50 | * about in there. | |
51 | */ | |
52 | e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, | |
53 | E820_RESERVED); | |
5ead97c8 | 54 | |
be5bf9fa JF |
55 | /* |
56 | * Reserve Xen bits: | |
57 | * - mfn_list | |
58 | * - xen_start_info | |
59 | * See comment above "struct start_info" in <xen/interface/xen.h> | |
60 | */ | |
61 | e820_add_region(__pa(xen_start_info->mfn_list), | |
62 | xen_start_info->pt_base - xen_start_info->mfn_list, | |
63 | E820_RESERVED); | |
64 | ||
65 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); | |
66 | ||
5ead97c8 JF |
67 | return "Xen"; |
68 | } | |
69 | ||
70 | static void xen_idle(void) | |
71 | { | |
72 | local_irq_disable(); | |
73 | ||
74 | if (need_resched()) | |
75 | local_irq_enable(); | |
76 | else { | |
77 | current_thread_info()->status &= ~TS_POLLING; | |
78 | smp_mb__after_clear_bit(); | |
79 | safe_halt(); | |
80 | current_thread_info()->status |= TS_POLLING; | |
81 | } | |
82 | } | |
83 | ||
d2eea68e RM |
84 | /* |
85 | * Set the bit indicating "nosegneg" library variants should be used. | |
86 | */ | |
08b6d290 | 87 | static void __init fiddle_vdso(void) |
d2eea68e | 88 | { |
af65d648 RM |
89 | extern const char vdso32_default_start; |
90 | u32 *mask = VDSO32_SYMBOL(&vdso32_default_start, NOTE_MASK); | |
d2eea68e RM |
91 | *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT; |
92 | } | |
93 | ||
88459d4c | 94 | static __cpuinit int register_callback(unsigned type, const void *func) |
e2a81baf | 95 | { |
88459d4c JF |
96 | struct callback_register callback = { |
97 | .type = type, | |
98 | .address = XEN_CALLBACK(__KERNEL_CS, func), | |
e2a81baf JF |
99 | .flags = CALLBACKF_mask_events, |
100 | }; | |
101 | ||
88459d4c JF |
102 | return HYPERVISOR_callback_op(CALLBACKOP_register, &callback); |
103 | } | |
104 | ||
105 | void __cpuinit xen_enable_sysenter(void) | |
106 | { | |
107 | int cpu = smp_processor_id(); | |
108 | extern void xen_sysenter_target(void); | |
109 | ||
e2a81baf | 110 | if (!boot_cpu_has(X86_FEATURE_SEP) || |
88459d4c JF |
111 | register_callback(CALLBACKTYPE_sysenter, |
112 | xen_sysenter_target) != 0) { | |
e2a81baf JF |
113 | clear_cpu_cap(&cpu_data(cpu), X86_FEATURE_SEP); |
114 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_SEP); | |
115 | } | |
116 | } | |
117 | ||
5ead97c8 JF |
118 | void __init xen_arch_setup(void) |
119 | { | |
120 | struct physdev_set_iopl set_iopl; | |
121 | int rc; | |
122 | ||
123 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); | |
124 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); | |
125 | ||
126 | if (!xen_feature(XENFEAT_auto_translated_physmap)) | |
127 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_pae_extended_cr3); | |
128 | ||
88459d4c JF |
129 | if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) || |
130 | register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback)) | |
131 | BUG(); | |
5ead97c8 | 132 | |
e2a81baf JF |
133 | xen_enable_sysenter(); |
134 | ||
5ead97c8 JF |
135 | set_iopl.iopl = 1; |
136 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl); | |
137 | if (rc != 0) | |
138 | printk(KERN_INFO "physdev_op failed %d\n", rc); | |
139 | ||
140 | #ifdef CONFIG_ACPI | |
141 | if (!(xen_start_info->flags & SIF_INITDOMAIN)) { | |
142 | printk(KERN_INFO "ACPI in unprivileged domain disabled\n"); | |
143 | disable_acpi(); | |
144 | } | |
145 | #endif | |
146 | ||
147 | memcpy(boot_command_line, xen_start_info->cmd_line, | |
148 | MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ? | |
149 | COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE); | |
150 | ||
151 | pm_idle = xen_idle; | |
f87e4cac | 152 | |
dfdcdd42 | 153 | paravirt_disable_iospace(); |
d2eea68e RM |
154 | |
155 | fiddle_vdso(); | |
5ead97c8 | 156 | } |