blob: d3663df2f967ee1cde95722585ea7218c07b9ed7 [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>
Yinghai Lua9ce6bc2010-08-25 13:39:17 -070011#include <linux/memblock.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070012
13#include <asm/elf.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010014#include <asm/vdso.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070015#include <asm/e820.h>
16#include <asm/setup.h>
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -070017#include <asm/acpi.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070018#include <asm/xen/hypervisor.h>
19#include <asm/xen/hypercall.h>
20
Ian Campbell45263cb2010-10-25 16:32:29 -070021#include <xen/xen.h>
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +010022#include <xen/page.h>
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -070023#include <xen/interface/callback.h>
Ian Campbell35ae11f2009-02-06 19:09:48 -080024#include <xen/interface/memory.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070025#include <xen/interface/physdev.h>
26#include <xen/features.h>
27
28#include "xen-ops.h"
Roland McGrathd2eea682007-07-20 00:31:43 -070029#include "vdso.h"
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070030
31/* These are code, but not functions. Defined in entry.S */
32extern const char xen_hypervisor_callback[];
33extern const char xen_failsafe_callback[];
Tejf63c2f22008-12-16 11:56:06 -080034extern void xen_sysenter_target(void);
35extern void xen_syscall_target(void);
36extern void xen_syscall32_target(void);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070037
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070038/* Amount of extra memory space we add to the e820 ranges */
39phys_addr_t xen_extra_mem_start, xen_extra_mem_size;
40
Jeremy Fitzhardinge698bb8d2010-09-14 10:19:14 -070041/*
42 * The maximum amount of extra memory compared to the base size. The
43 * main scaling factor is the size of struct page. At extreme ratios
44 * of base:extra, all the base memory can be filled with page
45 * structures for the extra memory, leaving no space for anything
46 * else.
47 *
48 * 10x seems like a reasonable balance between scaling flexibility and
49 * leaving a practically usable system.
50 */
51#define EXTRA_MEM_RATIO (10)
52
Daniel Kiperae15a3b2011-05-04 20:17:21 +020053static void __init xen_add_extra_mem(unsigned long pages)
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070054{
Konrad Rzeszutek Wilk6eaa4122011-01-18 20:09:41 -050055 unsigned long pfn;
56
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070057 u64 size = (u64)pages * PAGE_SIZE;
Jeremy Fitzhardinge36545812010-09-29 16:54:33 -070058 u64 extra_start = xen_extra_mem_start + xen_extra_mem_size;
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070059
60 if (!pages)
61 return;
62
Jeremy Fitzhardinge36545812010-09-29 16:54:33 -070063 e820_add_region(extra_start, size, E820_RAM);
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070064 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
65
Linus Torvalds520045d2010-10-26 18:20:19 -070066 memblock_x86_reserve_range(extra_start, extra_start + size, "XEN EXTRA");
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070067
68 xen_extra_mem_size += size;
Jeremy Fitzhardinge2f7acb22010-09-15 13:32:49 -070069
Jeremy Fitzhardinge36545812010-09-29 16:54:33 -070070 xen_max_p2m_pfn = PFN_DOWN(extra_start + size);
Konrad Rzeszutek Wilk6eaa4122011-01-18 20:09:41 -050071
72 for (pfn = PFN_DOWN(extra_start); pfn <= xen_max_p2m_pfn; pfn++)
73 __set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070074}
75
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -070076static unsigned long __init xen_release_chunk(phys_addr_t start_addr,
77 phys_addr_t end_addr)
Miroslav Rezanina093d7b42009-09-16 03:56:17 -040078{
79 struct xen_memory_reservation reservation = {
80 .address_bits = 0,
81 .extent_order = 0,
82 .domid = DOMID_SELF
83 };
Miroslav Rezanina093d7b42009-09-16 03:56:17 -040084 unsigned long start, end;
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -070085 unsigned long len = 0;
Miroslav Rezanina093d7b42009-09-16 03:56:17 -040086 unsigned long pfn;
87 int ret;
88
89 start = PFN_UP(start_addr);
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -070090 end = PFN_DOWN(end_addr);
Miroslav Rezanina093d7b42009-09-16 03:56:17 -040091
92 if (end <= start)
93 return 0;
94
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -070095 printk(KERN_INFO "xen_release_chunk: looking at area pfn %lx-%lx: ",
96 start, end);
97 for(pfn = start; pfn < end; pfn++) {
98 unsigned long mfn = pfn_to_mfn(pfn);
Miroslav Rezanina093d7b42009-09-16 03:56:17 -040099
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -0700100 /* Make sure pfn exists to start with */
101 if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn)
102 continue;
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400103
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -0700104 set_xen_guest_handle(reservation.extent_start, &mfn);
105 reservation.nr_extents = 1;
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400106
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -0700107 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
108 &reservation);
109 WARN(ret != 1, "Failed to release memory %lx-%lx err=%d\n",
110 start, end, ret);
111 if (ret == 1) {
Konrad Rzeszutek Wilk6eaa4122011-01-18 20:09:41 -0500112 __set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -0700113 len++;
114 }
115 }
116 printk(KERN_CONT "%ld pages freed\n", len);
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400117
118 return len;
119}
120
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -0700121static unsigned long __init xen_return_unused_memory(unsigned long max_pfn,
122 const struct e820map *e820)
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400123{
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -0700124 phys_addr_t max_addr = PFN_PHYS(max_pfn);
Ian Campbell9ec23a7f2010-10-28 11:32:29 -0700125 phys_addr_t last_end = ISA_END_ADDRESS;
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400126 unsigned long released = 0;
127 int i;
128
Ian Campbell9ec23a7f2010-10-28 11:32:29 -0700129 /* Free any unused memory above the low 1Mbyte. */
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -0700130 for (i = 0; i < e820->nr_map && last_end < max_addr; i++) {
131 phys_addr_t end = e820->map[i].addr;
132 end = min(max_addr, end);
133
Ian Campbell9ec23a7f2010-10-28 11:32:29 -0700134 if (last_end < end)
135 released += xen_release_chunk(last_end, end);
136 last_end = max(last_end, e820->map[i].addr + e820->map[i].size);
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400137 }
138
Jeremy Fitzhardingef89e0482009-09-16 12:38:33 -0700139 if (last_end < max_addr)
140 released += xen_release_chunk(last_end, max_addr);
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400141
142 printk(KERN_INFO "released %ld pages of unused memory\n", released);
143 return released;
144}
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700145
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500146static unsigned long __init xen_set_identity(const struct e820entry *list,
147 ssize_t map_size)
148{
149 phys_addr_t last = xen_initial_domain() ? 0 : ISA_END_ADDRESS;
150 phys_addr_t start_pci = last;
151 const struct e820entry *entry;
152 unsigned long identity = 0;
153 int i;
154
155 for (i = 0, entry = list; i < map_size; i++, entry++) {
156 phys_addr_t start = entry->addr;
157 phys_addr_t end = start + entry->size;
158
159 if (start < last)
160 start = last;
161
162 if (end <= start)
163 continue;
164
165 /* Skip over the 1MB region. */
166 if (last > end)
167 continue;
168
169 if (entry->type == E820_RAM) {
170 if (start > start_pci)
171 identity += set_phys_range_identity(
172 PFN_UP(start_pci), PFN_DOWN(start));
173
174 /* Without saving 'last' we would gooble RAM too
175 * at the end of the loop. */
176 last = end;
177 start_pci = end;
178 continue;
179 }
180 start_pci = min(start, start_pci);
181 last = end;
182 }
183 if (last > start_pci)
184 identity += set_phys_range_identity(
185 PFN_UP(start_pci), PFN_DOWN(last));
186 return identity;
187}
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700188/**
189 * machine_specific_memory_setup - Hook for machine specific memory setup.
190 **/
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700191char * __init xen_memory_setup(void)
192{
Ian Campbell35ae11f2009-02-06 19:09:48 -0800193 static struct e820entry map[E820MAX] __initdata;
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500194 static struct e820entry map_raw[E820MAX] __initdata;
Ian Campbell35ae11f2009-02-06 19:09:48 -0800195
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700196 unsigned long max_pfn = xen_start_info->nr_pages;
Ian Campbell35ae11f2009-02-06 19:09:48 -0800197 unsigned long long mem_end;
198 int rc;
199 struct xen_memory_map memmap;
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -0700200 unsigned long extra_pages = 0;
Jeremy Fitzhardinge698bb8d2010-09-14 10:19:14 -0700201 unsigned long extra_limit;
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500202 unsigned long identity_pages = 0;
Ian Campbell35ae11f2009-02-06 19:09:48 -0800203 int i;
Ian Campbell9e9a5fc2010-09-02 16:16:00 +0100204 int op;
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700205
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +0100206 max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
Ian Campbell35ae11f2009-02-06 19:09:48 -0800207 mem_end = PFN_PHYS(max_pfn);
208
209 memmap.nr_entries = E820MAX;
210 set_xen_guest_handle(memmap.buffer, map);
211
Ian Campbell9e9a5fc2010-09-02 16:16:00 +0100212 op = xen_initial_domain() ?
213 XENMEM_machine_memory_map :
214 XENMEM_memory_map;
215 rc = HYPERVISOR_memory_op(op, &memmap);
Ian Campbell35ae11f2009-02-06 19:09:48 -0800216 if (rc == -ENOSYS) {
Ian Campbell9ec23a7f2010-10-28 11:32:29 -0700217 BUG_ON(xen_initial_domain());
Ian Campbell35ae11f2009-02-06 19:09:48 -0800218 memmap.nr_entries = 1;
219 map[0].addr = 0ULL;
220 map[0].size = mem_end;
221 /* 8MB slack (to balance backend allocations). */
222 map[0].size += 8ULL << 20;
223 map[0].type = E820_RAM;
224 rc = 0;
225 }
226 BUG_ON(rc);
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +0100227
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500228 memcpy(map_raw, map, sizeof(map));
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700229 e820.nr_map = 0;
Stefano Stabellini24bdb0b2011-04-12 12:19:52 +0100230 xen_extra_mem_start = max((1ULL << 32), mem_end);
Ian Campbell35ae11f2009-02-06 19:09:48 -0800231 for (i = 0; i < memmap.nr_entries; i++) {
Stefano Stabellini7cb31b72011-01-27 10:13:25 -0500232 unsigned long long end;
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -0700233
Stefano Stabellini7cb31b72011-01-27 10:13:25 -0500234 /* Guard against non-page aligned E820 entries. */
235 if (map[i].type == E820_RAM)
236 map[i].size -= (map[i].size + map[i].addr) % PAGE_SIZE;
237
238 end = map[i].addr + map[i].size;
Jeremy Fitzhardingec2d08792010-11-22 16:31:35 -0800239 if (map[i].type == E820_RAM && end > mem_end) {
240 /* RAM off the end - may be partially included */
241 u64 delta = min(map[i].size, end - mem_end);
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -0700242
Jeremy Fitzhardingec2d08792010-11-22 16:31:35 -0800243 map[i].size -= delta;
244 end -= delta;
Jeremy Fitzhardinge36545812010-09-29 16:54:33 -0700245
Jeremy Fitzhardingec2d08792010-11-22 16:31:35 -0800246 extra_pages += PFN_DOWN(delta);
Zhang, Fengzhe2f14ddc2011-02-16 22:26:20 +0800247 /*
248 * Set RAM below 4GB that is not for us to be unusable.
249 * This prevents "System RAM" address space from being
250 * used as potential resource for I/O address (happens
251 * when 'allocate_resource' is called).
252 */
Konrad Rzeszutek Wilk86b32122011-03-09 22:03:16 -0500253 if (delta &&
254 (xen_initial_domain() && end < 0x100000000ULL))
Zhang, Fengzhe2f14ddc2011-02-16 22:26:20 +0800255 e820_add_region(end, delta, E820_UNUSABLE);
Jeremy Fitzhardinge36545812010-09-29 16:54:33 -0700256 }
257
Jeremy Fitzhardingec2d08792010-11-22 16:31:35 -0800258 if (map[i].size > 0 && end > xen_extra_mem_start)
Jeremy Fitzhardinge36bc2512010-09-02 17:07:03 -0700259 xen_extra_mem_start = end;
Jeremy Fitzhardingeb5b43ce2010-09-02 17:10:12 -0700260
Jeremy Fitzhardingec2d08792010-11-22 16:31:35 -0800261 /* Add region if any remains */
262 if (map[i].size > 0)
Ian Campbell35ae11f2009-02-06 19:09:48 -0800263 e820_add_region(map[i].addr, map[i].size, map[i].type);
264 }
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -0700265
266 /*
Ian Campbell9ec23a7f2010-10-28 11:32:29 -0700267 * In domU, the ISA region is normal, usable memory, but we
268 * reserve ISA memory anyway because too many things poke
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -0700269 * about in there.
Juan Quintela4ec53872010-09-02 15:45:43 +0100270 *
Ian Campbell9ec23a7f2010-10-28 11:32:29 -0700271 * In Dom0, the host E820 information can leave gaps in the
272 * ISA range, which would cause us to release those pages. To
273 * avoid this, we unconditionally reserve them here.
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -0700274 */
275 e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
276 E820_RESERVED);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700277
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -0700278 /*
279 * Reserve Xen bits:
280 * - mfn_list
281 * - xen_start_info
282 * See comment above "struct start_info" in <xen/interface/xen.h>
283 */
Yinghai Lua9ce6bc2010-08-25 13:39:17 -0700284 memblock_x86_reserve_range(__pa(xen_start_info->mfn_list),
Jeremy Fitzhardinge6b2e8522009-05-07 11:56:49 -0700285 __pa(xen_start_info->pt_base),
286 "XEN START INFO");
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -0700287
288 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
289
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -0700290 extra_pages += xen_return_unused_memory(xen_start_info->nr_pages, &e820);
291
Jeremy Fitzhardinge698bb8d2010-09-14 10:19:14 -0700292 /*
293 * Clamp the amount of extra memory to a EXTRA_MEM_RATIO
294 * factor the base size. On non-highmem systems, the base
295 * size is the full initial memory allocation; on highmem it
296 * is limited to the max size of lowmem, so that it doesn't
297 * get completely filled.
298 *
299 * In principle there could be a problem in lowmem systems if
300 * the initial memory is also very large with respect to
301 * lowmem, but we won't try to deal with that here.
302 */
303 extra_limit = min(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)),
304 max_pfn + extra_pages);
305
306 if (extra_limit >= max_pfn)
307 extra_pages = extra_limit - max_pfn;
308 else
309 extra_pages = 0;
310
Jeremy Fitzhardinged2a81712010-11-19 23:27:06 -0800311 xen_add_extra_mem(extra_pages);
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400312
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500313 /*
314 * Set P2M for all non-RAM pages and E820 gaps to be identity
315 * type PFNs. We supply it with the non-sanitized version
316 * of the E820.
317 */
318 identity_pages = xen_set_identity(map_raw, memmap.nr_entries);
319 printk(KERN_INFO "Set %ld page(s) to 1-1 mapping.\n", identity_pages);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700320 return "Xen";
321}
322
Roland McGrathd2eea682007-07-20 00:31:43 -0700323/*
324 * Set the bit indicating "nosegneg" library variants should be used.
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -0700325 * We only need to bother in pure 32-bit mode; compat 32-bit processes
326 * can have un-truncated segments, so wrapping around is allowed.
Roland McGrathd2eea682007-07-20 00:31:43 -0700327 */
Sam Ravnborg08b6d292008-01-30 13:33:25 +0100328static void __init fiddle_vdso(void)
Roland McGrathd2eea682007-07-20 00:31:43 -0700329{
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -0700330#ifdef CONFIG_X86_32
331 u32 *mask;
332 mask = VDSO32_SYMBOL(&vdso32_int80_start, NOTE_MASK);
333 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
334 mask = VDSO32_SYMBOL(&vdso32_sysenter_start, NOTE_MASK);
Roland McGrathd2eea682007-07-20 00:31:43 -0700335 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700336#endif
Roland McGrathd2eea682007-07-20 00:31:43 -0700337}
338
Daniel Kiperae15a3b2011-05-04 20:17:21 +0200339static int __cpuinit register_callback(unsigned type, const void *func)
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700340{
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700341 struct callback_register callback = {
342 .type = type,
343 .address = XEN_CALLBACK(__KERNEL_CS, func),
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700344 .flags = CALLBACKF_mask_events,
345 };
346
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700347 return HYPERVISOR_callback_op(CALLBACKOP_register, &callback);
348}
349
350void __cpuinit xen_enable_sysenter(void)
351{
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700352 int ret;
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700353 unsigned sysenter_feature;
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700354
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700355#ifdef CONFIG_X86_32
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700356 sysenter_feature = X86_FEATURE_SEP;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700357#else
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700358 sysenter_feature = X86_FEATURE_SYSENTER32;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700359#endif
360
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700361 if (!boot_cpu_has(sysenter_feature))
362 return;
363
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700364 ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target);
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700365 if(ret != 0)
366 setup_clear_cpu_cap(sysenter_feature);
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700367}
368
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700369void __cpuinit xen_enable_syscall(void)
370{
371#ifdef CONFIG_X86_64
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700372 int ret;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700373
374 ret = register_callback(CALLBACKTYPE_syscall, xen_syscall_target);
375 if (ret != 0) {
Jeremy Fitzhardinged5303b82008-07-12 02:22:06 -0700376 printk(KERN_ERR "Failed to set syscall callback: %d\n", ret);
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700377 /* Pretty fatal; 64-bit userspace has no other
378 mechanism for syscalls. */
379 }
380
381 if (boot_cpu_has(X86_FEATURE_SYSCALL32)) {
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700382 ret = register_callback(CALLBACKTYPE_syscall32,
383 xen_syscall32_target);
Jeremy Fitzhardinged5303b82008-07-12 02:22:06 -0700384 if (ret != 0)
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700385 setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700386 }
387#endif /* CONFIG_X86_64 */
388}
389
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700390void __init xen_arch_setup(void)
391{
Donald Dutilef09f6d12010-07-15 14:56:49 -0400392 xen_panic_handler_init();
393
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700394 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
395 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
396
397 if (!xen_feature(XENFEAT_auto_translated_physmap))
Tejf63c2f22008-12-16 11:56:06 -0800398 HYPERVISOR_vm_assist(VMASST_CMD_enable,
399 VMASST_TYPE_pae_extended_cr3);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700400
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700401 if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) ||
402 register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback))
403 BUG();
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700404
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700405 xen_enable_sysenter();
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700406 xen_enable_syscall();
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700407
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700408#ifdef CONFIG_ACPI
409 if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
410 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
411 disable_acpi();
412 }
413#endif
414
415 memcpy(boot_command_line, xen_start_info->cmd_line,
416 MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
417 COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
418
Jeremy Fitzhardingebc15fde2010-11-22 17:17:50 -0800419 /* Set up idle, making sure it calls safe_halt() pvop */
420#ifdef CONFIG_X86_32
421 boot_cpu_data.hlt_works_ok = 1;
422#endif
423 pm_idle = default_idle;
Stefano Stabellini23febed2011-01-26 17:07:27 +0000424 boot_option_idle_override = IDLE_HALT;
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700425
Roland McGrathd2eea682007-07-20 00:31:43 -0700426 fiddle_vdso();
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700427}