blob: ad0047f47cd476004c99485877f6d62a7db20d86 [file] [log] [blame]
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001/*
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>
Roland McGrath6c3652e2008-01-30 13:30:42 +010013#include <asm/vdso.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070014#include <asm/e820.h>
15#include <asm/setup.h>
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -070016#include <asm/acpi.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070017#include <asm/xen/hypervisor.h>
18#include <asm/xen/hypercall.h>
19
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +010020#include <xen/page.h>
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -070021#include <xen/interface/callback.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070022#include <xen/interface/physdev.h>
23#include <xen/features.h>
24
25#include "xen-ops.h"
Roland McGrathd2eea682007-07-20 00:31:43 -070026#include "vdso.h"
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070027
28/* These are code, but not functions. Defined in entry.S */
29extern const char xen_hypervisor_callback[];
30extern const char xen_failsafe_callback[];
Tejf63c2f22008-12-16 11:56:06 -080031extern void xen_sysenter_target(void);
32extern void xen_syscall_target(void);
33extern void xen_syscall32_target(void);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070034
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070035
36/**
37 * machine_specific_memory_setup - Hook for machine specific memory setup.
38 **/
39
40char * __init xen_memory_setup(void)
41{
42 unsigned long max_pfn = xen_start_info->nr_pages;
43
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +010044 max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
45
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070046 e820.nr_map = 0;
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -070047
Jeremy Fitzhardinge5670a432008-09-14 07:42:23 -070048 e820_add_region(0, PFN_PHYS((u64)max_pfn), E820_RAM);
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -070049
50 /*
51 * Even though this is normal, usable memory under Xen, reserve
52 * ISA memory anyway because too many things think they can poke
53 * about in there.
54 */
55 e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
56 E820_RESERVED);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070057
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -070058 /*
59 * Reserve Xen bits:
60 * - mfn_list
61 * - xen_start_info
62 * See comment above "struct start_info" in <xen/interface/xen.h>
63 */
Jeremy Fitzhardinge6b2e8522009-05-07 11:56:49 -070064 reserve_early(__pa(xen_start_info->mfn_list),
65 __pa(xen_start_info->pt_base),
66 "XEN START INFO");
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -070067
68 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
69
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070070 return "Xen";
71}
72
73static void xen_idle(void)
74{
75 local_irq_disable();
76
77 if (need_resched())
78 local_irq_enable();
79 else {
80 current_thread_info()->status &= ~TS_POLLING;
81 smp_mb__after_clear_bit();
82 safe_halt();
83 current_thread_info()->status |= TS_POLLING;
84 }
85}
86
Roland McGrathd2eea682007-07-20 00:31:43 -070087/*
88 * Set the bit indicating "nosegneg" library variants should be used.
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -070089 * We only need to bother in pure 32-bit mode; compat 32-bit processes
90 * can have un-truncated segments, so wrapping around is allowed.
Roland McGrathd2eea682007-07-20 00:31:43 -070091 */
Sam Ravnborg08b6d292008-01-30 13:33:25 +010092static void __init fiddle_vdso(void)
Roland McGrathd2eea682007-07-20 00:31:43 -070093{
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -070094#ifdef CONFIG_X86_32
95 u32 *mask;
96 mask = VDSO32_SYMBOL(&vdso32_int80_start, NOTE_MASK);
97 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
98 mask = VDSO32_SYMBOL(&vdso32_sysenter_start, NOTE_MASK);
Roland McGrathd2eea682007-07-20 00:31:43 -070099 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700100#endif
Roland McGrathd2eea682007-07-20 00:31:43 -0700101}
102
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700103static __cpuinit int register_callback(unsigned type, const void *func)
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700104{
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700105 struct callback_register callback = {
106 .type = type,
107 .address = XEN_CALLBACK(__KERNEL_CS, func),
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700108 .flags = CALLBACKF_mask_events,
109 };
110
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700111 return HYPERVISOR_callback_op(CALLBACKOP_register, &callback);
112}
113
114void __cpuinit xen_enable_sysenter(void)
115{
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700116 int ret;
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700117 unsigned sysenter_feature;
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700118
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700119#ifdef CONFIG_X86_32
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700120 sysenter_feature = X86_FEATURE_SEP;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700121#else
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700122 sysenter_feature = X86_FEATURE_SYSENTER32;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700123#endif
124
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700125 if (!boot_cpu_has(sysenter_feature))
126 return;
127
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700128 ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target);
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700129 if(ret != 0)
130 setup_clear_cpu_cap(sysenter_feature);
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700131}
132
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700133void __cpuinit xen_enable_syscall(void)
134{
135#ifdef CONFIG_X86_64
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700136 int ret;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700137
138 ret = register_callback(CALLBACKTYPE_syscall, xen_syscall_target);
139 if (ret != 0) {
Jeremy Fitzhardinged5303b82008-07-12 02:22:06 -0700140 printk(KERN_ERR "Failed to set syscall callback: %d\n", ret);
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700141 /* Pretty fatal; 64-bit userspace has no other
142 mechanism for syscalls. */
143 }
144
145 if (boot_cpu_has(X86_FEATURE_SYSCALL32)) {
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700146 ret = register_callback(CALLBACKTYPE_syscall32,
147 xen_syscall32_target);
Jeremy Fitzhardinged5303b82008-07-12 02:22:06 -0700148 if (ret != 0)
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700149 setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700150 }
151#endif /* CONFIG_X86_64 */
152}
153
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700154void __init xen_arch_setup(void)
155{
156 struct physdev_set_iopl set_iopl;
157 int rc;
158
159 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
160 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
161
162 if (!xen_feature(XENFEAT_auto_translated_physmap))
Tejf63c2f22008-12-16 11:56:06 -0800163 HYPERVISOR_vm_assist(VMASST_CMD_enable,
164 VMASST_TYPE_pae_extended_cr3);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700165
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700166 if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) ||
167 register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback))
168 BUG();
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700169
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700170 xen_enable_sysenter();
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700171 xen_enable_syscall();
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700172
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700173 set_iopl.iopl = 1;
174 rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
175 if (rc != 0)
176 printk(KERN_INFO "physdev_op failed %d\n", rc);
177
178#ifdef CONFIG_ACPI
179 if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
180 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
181 disable_acpi();
182 }
183#endif
184
185 memcpy(boot_command_line, xen_start_info->cmd_line,
186 MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
187 COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
188
189 pm_idle = xen_idle;
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700190
Jeremy Fitzhardingedfdcdd42007-07-17 18:37:07 -0700191 paravirt_disable_iospace();
Roland McGrathd2eea682007-07-20 00:31:43 -0700192
193 fiddle_vdso();
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700194}