blob: dfd77dec8e2b7c1ef72d16adb1ecf7f7b80c88de [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>
Len Brownd91ee582011-04-01 18:28:35 -040012#include <linux/cpuidle.h>
Konrad Rzeszutek Wilk48cdd822012-03-13 20:06:57 -040013#include <linux/cpufreq.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070014
15#include <asm/elf.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010016#include <asm/vdso.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070017#include <asm/e820.h>
18#include <asm/setup.h>
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -070019#include <asm/acpi.h>
Konrad Rzeszutek Wilk8d54db792012-08-17 10:22:37 -040020#include <asm/numa.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070021#include <asm/xen/hypervisor.h>
22#include <asm/xen/hypercall.h>
23
Ian Campbell45263cb2010-10-25 16:32:29 -070024#include <xen/xen.h>
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +010025#include <xen/page.h>
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -070026#include <xen/interface/callback.h>
Ian Campbell35ae11f2009-02-06 19:09:48 -080027#include <xen/interface/memory.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070028#include <xen/interface/physdev.h>
29#include <xen/features.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070030#include "xen-ops.h"
Roland McGrathd2eea682007-07-20 00:31:43 -070031#include "vdso.h"
Matt Rushton4fbb67e32014-08-11 11:57:57 -070032#include "p2m.h"
Juergen Gross1f3ac862014-11-28 11:53:53 +010033#include "mmu.h"
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070034
35/* These are code, but not functions. Defined in entry.S */
36extern const char xen_hypervisor_callback[];
37extern const char xen_failsafe_callback[];
Konrad Rzeszutek Wilk6efa20e2013-07-19 11:51:31 -040038#ifdef CONFIG_X86_64
Andi Kleen07ba06d2013-10-22 09:07:59 -070039extern asmlinkage void nmi(void);
Konrad Rzeszutek Wilk6efa20e2013-07-19 11:51:31 -040040#endif
Tejf63c2f22008-12-16 11:56:06 -080041extern void xen_sysenter_target(void);
42extern void xen_syscall_target(void);
43extern void xen_syscall32_target(void);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070044
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070045/* Amount of extra memory space we add to the e820 ranges */
David Vrabel8b5d44a2011-09-28 17:46:34 +010046struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070047
David Vrabelaa244112011-09-28 17:46:32 +010048/* Number of pages released from the initial allocation. */
49unsigned long xen_released_pages;
50
Juergen Gross1f3ac862014-11-28 11:53:53 +010051/*
52 * Buffer used to remap identity mapped pages. We only need the virtual space.
53 * The physical page behind this address is remapped as needed to different
54 * buffer pages.
55 */
56#define REMAP_SIZE (P2M_PER_PAGE - 3)
57static struct {
58 unsigned long next_area_mfn;
59 unsigned long target_pfn;
60 unsigned long size;
61 unsigned long mfns[REMAP_SIZE];
62} xen_remap_buf __initdata __aligned(PAGE_SIZE);
63static unsigned long xen_remap_mfn __initdata = INVALID_P2M_ENTRY;
Matt Rushton4fbb67e32014-08-11 11:57:57 -070064
Jeremy Fitzhardinge698bb8d2010-09-14 10:19:14 -070065/*
66 * The maximum amount of extra memory compared to the base size. The
67 * main scaling factor is the size of struct page. At extreme ratios
68 * of base:extra, all the base memory can be filled with page
69 * structures for the extra memory, leaving no space for anything
70 * else.
71 *
72 * 10x seems like a reasonable balance between scaling flexibility and
73 * leaving a practically usable system.
74 */
75#define EXTRA_MEM_RATIO (10)
76
David Vrabeldc91c722011-09-29 12:26:19 +010077static void __init xen_add_extra_mem(u64 start, u64 size)
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070078{
David Vrabeldc91c722011-09-29 12:26:19 +010079 int i;
Konrad Rzeszutek Wilk6eaa4122011-01-18 20:09:41 -050080
David Vrabeldc91c722011-09-29 12:26:19 +010081 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
82 /* Add new region. */
83 if (xen_extra_mem[i].size == 0) {
84 xen_extra_mem[i].start = start;
85 xen_extra_mem[i].size = size;
86 break;
87 }
88 /* Append to existing region. */
89 if (xen_extra_mem[i].start + xen_extra_mem[i].size == start) {
90 xen_extra_mem[i].size += size;
91 break;
92 }
93 }
94 if (i == XEN_EXTRA_MEM_MAX_REGIONS)
95 printk(KERN_WARNING "Warning: not enough extra memory regions\n");
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070096
Tejun Heod4bbf7e2011-11-28 09:46:22 -080097 memblock_reserve(start, size);
Juergen Gross5b8e7d82014-11-28 11:53:55 +010098}
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -070099
Juergen Gross5b8e7d82014-11-28 11:53:55 +0100100static void __init xen_del_extra_mem(u64 start, u64 size)
101{
102 int i;
103 u64 start_r, size_r;
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -0700104
Juergen Gross5b8e7d82014-11-28 11:53:55 +0100105 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
106 start_r = xen_extra_mem[i].start;
107 size_r = xen_extra_mem[i].size;
Konrad Rzeszutek Wilkc96aae12012-08-17 16:43:28 -0400108
Juergen Gross5b8e7d82014-11-28 11:53:55 +0100109 /* Start of region. */
110 if (start_r == start) {
111 BUG_ON(size > size_r);
112 xen_extra_mem[i].start += size;
113 xen_extra_mem[i].size -= size;
114 break;
115 }
116 /* End of region. */
117 if (start_r + size_r == start + size) {
118 BUG_ON(size > size_r);
119 xen_extra_mem[i].size -= size;
120 break;
121 }
122 /* Mid of region. */
123 if (start > start_r && start < start_r + size_r) {
124 BUG_ON(start + size > start_r + size_r);
125 xen_extra_mem[i].size = start - start_r;
126 /* Calling memblock_reserve() again is okay. */
127 xen_add_extra_mem(start + size, start_r + size_r -
128 (start + size));
129 break;
130 }
131 }
132 memblock_free(start, size);
133}
134
135/*
136 * Called during boot before the p2m list can take entries beyond the
137 * hypervisor supplied p2m list. Entries in extra mem are to be regarded as
138 * invalid.
139 */
140unsigned long __ref xen_chk_extra_mem(unsigned long pfn)
141{
142 int i;
143 unsigned long addr = PFN_PHYS(pfn);
144
145 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
146 if (addr >= xen_extra_mem[i].start &&
147 addr < xen_extra_mem[i].start + xen_extra_mem[i].size)
148 return INVALID_P2M_ENTRY;
149 }
150
151 return IDENTITY_FRAME(pfn);
152}
153
154/*
155 * Mark all pfns of extra mem as invalid in p2m list.
156 */
157void __init xen_inv_extra_mem(void)
158{
159 unsigned long pfn, pfn_s, pfn_e;
160 int i;
161
162 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
163 pfn_s = PFN_DOWN(xen_extra_mem[i].start);
164 pfn_e = PFN_UP(xen_extra_mem[i].start + xen_extra_mem[i].size);
165 for (pfn = pfn_s; pfn < pfn_e; pfn++)
166 set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
Konrad Rzeszutek Wilkc96aae12012-08-17 16:43:28 -0400167 }
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -0700168}
169
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700170/*
171 * Finds the next RAM pfn available in the E820 map after min_pfn.
172 * This function updates min_pfn with the pfn found and returns
173 * the size of that range or zero if not found.
174 */
175static unsigned long __init xen_find_pfn_range(
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400176 const struct e820entry *list, size_t map_size,
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700177 unsigned long *min_pfn)
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400178{
179 const struct e820entry *entry;
180 unsigned int i;
181 unsigned long done = 0;
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400182
183 for (i = 0, entry = list; i < map_size; i++, entry++) {
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400184 unsigned long s_pfn;
185 unsigned long e_pfn;
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400186
187 if (entry->type != E820_RAM)
188 continue;
189
zhenzhong.duanc3d93f82012-07-18 13:06:39 +0800190 e_pfn = PFN_DOWN(entry->addr + entry->size);
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400191
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700192 /* We only care about E820 after this */
193 if (e_pfn < *min_pfn)
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400194 continue;
195
zhenzhong.duanc3d93f82012-07-18 13:06:39 +0800196 s_pfn = PFN_UP(entry->addr);
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700197
198 /* If min_pfn falls within the E820 entry, we want to start
199 * at the min_pfn PFN.
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400200 */
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700201 if (s_pfn <= *min_pfn) {
202 done = e_pfn - *min_pfn;
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400203 } else {
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700204 done = e_pfn - s_pfn;
205 *min_pfn = s_pfn;
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400206 }
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700207 break;
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400208 }
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700209
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400210 return done;
211}
David Vrabel83d51ab2012-05-03 16:15:42 +0100212
Juergen Gross1f3ac862014-11-28 11:53:53 +0100213static int __init xen_free_mfn(unsigned long mfn)
214{
215 struct xen_memory_reservation reservation = {
216 .address_bits = 0,
217 .extent_order = 0,
218 .domid = DOMID_SELF
219 };
220
221 set_xen_guest_handle(reservation.extent_start, &mfn);
222 reservation.nr_extents = 1;
223
224 return HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
225}
226
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700227/*
Juergen Gross1f3ac862014-11-28 11:53:53 +0100228 * This releases a chunk of memory and then does the identity map. It's used
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700229 * as a fallback if the remapping fails.
230 */
231static void __init xen_set_identity_and_release_chunk(unsigned long start_pfn,
232 unsigned long end_pfn, unsigned long nr_pages, unsigned long *identity,
233 unsigned long *released)
David Vrabel83d51ab2012-05-03 16:15:42 +0100234{
Juergen Gross1f3ac862014-11-28 11:53:53 +0100235 unsigned long len = 0;
236 unsigned long pfn, end;
237 int ret;
238
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700239 WARN_ON(start_pfn > end_pfn);
David Vrabel83d51ab2012-05-03 16:15:42 +0100240
Juergen Gross1f3ac862014-11-28 11:53:53 +0100241 end = min(end_pfn, nr_pages);
242 for (pfn = start_pfn; pfn < end; pfn++) {
243 unsigned long mfn = pfn_to_mfn(pfn);
244
245 /* Make sure pfn exists to start with */
246 if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn)
247 continue;
248
249 ret = xen_free_mfn(mfn);
250 WARN(ret != 1, "Failed to release pfn %lx err=%d\n", pfn, ret);
251
252 if (ret == 1) {
253 if (!__set_phys_to_machine(pfn, INVALID_P2M_ENTRY))
254 break;
255 len++;
256 } else
257 break;
258 }
259
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700260 /* Need to release pages first */
Juergen Gross1f3ac862014-11-28 11:53:53 +0100261 *released += len;
David Vrabel83d51ab2012-05-03 16:15:42 +0100262 *identity += set_phys_range_identity(start_pfn, end_pfn);
263}
264
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700265/*
Juergen Gross1f3ac862014-11-28 11:53:53 +0100266 * Helper function to update the p2m and m2p tables and kernel mapping.
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700267 */
Juergen Gross1f3ac862014-11-28 11:53:53 +0100268static void __init xen_update_mem_tables(unsigned long pfn, unsigned long mfn)
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700269{
270 struct mmu_update update = {
271 .ptr = ((unsigned long long)mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
272 .val = pfn
273 };
274
275 /* Update p2m */
Juergen Gross1f3ac862014-11-28 11:53:53 +0100276 if (!set_phys_to_machine(pfn, mfn)) {
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700277 WARN(1, "Failed to set p2m mapping for pfn=%ld mfn=%ld\n",
278 pfn, mfn);
Juergen Gross1f3ac862014-11-28 11:53:53 +0100279 BUG();
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700280 }
281
282 /* Update m2p */
283 if (HYPERVISOR_mmu_update(&update, 1, NULL, DOMID_SELF) < 0) {
284 WARN(1, "Failed to set m2p mapping for mfn=%ld pfn=%ld\n",
285 mfn, pfn);
Juergen Gross1f3ac862014-11-28 11:53:53 +0100286 BUG();
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700287 }
288
Juergen Gross1f3ac862014-11-28 11:53:53 +0100289 /* Update kernel mapping, but not for highmem. */
290 if ((pfn << PAGE_SHIFT) >= __pa(high_memory))
291 return;
292
293 if (HYPERVISOR_update_va_mapping((unsigned long)__va(pfn << PAGE_SHIFT),
294 mfn_pte(mfn, PAGE_KERNEL), 0)) {
295 WARN(1, "Failed to update kernel mapping for mfn=%ld pfn=%ld\n",
296 mfn, pfn);
297 BUG();
298 }
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700299}
300
301/*
302 * This function updates the p2m and m2p tables with an identity map from
Juergen Gross1f3ac862014-11-28 11:53:53 +0100303 * start_pfn to start_pfn+size and prepares remapping the underlying RAM of the
304 * original allocation at remap_pfn. The information needed for remapping is
305 * saved in the memory itself to avoid the need for allocating buffers. The
306 * complete remap information is contained in a list of MFNs each containing
307 * up to REMAP_SIZE MFNs and the start target PFN for doing the remap.
308 * This enables us to preserve the original mfn sequence while doing the
309 * remapping at a time when the memory management is capable of allocating
310 * virtual and physical memory in arbitrary amounts, see 'xen_remap_memory' and
311 * its callers.
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700312 */
Juergen Gross1f3ac862014-11-28 11:53:53 +0100313static void __init xen_do_set_identity_and_remap_chunk(
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700314 unsigned long start_pfn, unsigned long size, unsigned long remap_pfn)
315{
Juergen Gross1f3ac862014-11-28 11:53:53 +0100316 unsigned long buf = (unsigned long)&xen_remap_buf;
317 unsigned long mfn_save, mfn;
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700318 unsigned long ident_pfn_iter, remap_pfn_iter;
Juergen Gross1f3ac862014-11-28 11:53:53 +0100319 unsigned long ident_end_pfn = start_pfn + size;
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700320 unsigned long left = size;
Juergen Gross1f3ac862014-11-28 11:53:53 +0100321 unsigned long ident_cnt = 0;
322 unsigned int i, chunk;
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700323
324 WARN_ON(size == 0);
325
326 BUG_ON(xen_feature(XENFEAT_auto_translated_physmap));
327
Juergen Gross1f3ac862014-11-28 11:53:53 +0100328 mfn_save = virt_to_mfn(buf);
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700329
Juergen Gross1f3ac862014-11-28 11:53:53 +0100330 for (ident_pfn_iter = start_pfn, remap_pfn_iter = remap_pfn;
331 ident_pfn_iter < ident_end_pfn;
332 ident_pfn_iter += REMAP_SIZE, remap_pfn_iter += REMAP_SIZE) {
333 chunk = (left < REMAP_SIZE) ? left : REMAP_SIZE;
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700334
Juergen Gross1f3ac862014-11-28 11:53:53 +0100335 /* Map first pfn to xen_remap_buf */
336 mfn = pfn_to_mfn(ident_pfn_iter);
337 set_pte_mfn(buf, mfn, PAGE_KERNEL);
338
339 /* Save mapping information in page */
340 xen_remap_buf.next_area_mfn = xen_remap_mfn;
341 xen_remap_buf.target_pfn = remap_pfn_iter;
342 xen_remap_buf.size = chunk;
343 for (i = 0; i < chunk; i++)
344 xen_remap_buf.mfns[i] = pfn_to_mfn(ident_pfn_iter + i);
345
346 /* Put remap buf into list. */
347 xen_remap_mfn = mfn;
348
349 /* Set identity map */
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700350 ident_cnt += set_phys_range_identity(ident_pfn_iter,
Juergen Gross1f3ac862014-11-28 11:53:53 +0100351 ident_pfn_iter + chunk);
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700352
Juergen Gross1f3ac862014-11-28 11:53:53 +0100353 left -= chunk;
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700354 }
355
Juergen Gross1f3ac862014-11-28 11:53:53 +0100356 /* Restore old xen_remap_buf mapping */
357 set_pte_mfn(buf, mfn_save, PAGE_KERNEL);
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700358}
359
360/*
361 * This function takes a contiguous pfn range that needs to be identity mapped
362 * and:
363 *
364 * 1) Finds a new range of pfns to use to remap based on E820 and remap_pfn.
365 * 2) Calls the do_ function to actually do the mapping/remapping work.
366 *
367 * The goal is to not allocate additional memory but to remap the existing
368 * pages. In the case of an error the underlying memory is simply released back
369 * to Xen and not remapped.
370 */
Juergen Gross76f0a482014-12-08 06:32:19 +0100371static unsigned long __init xen_set_identity_and_remap_chunk(
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700372 const struct e820entry *list, size_t map_size, unsigned long start_pfn,
373 unsigned long end_pfn, unsigned long nr_pages, unsigned long remap_pfn,
Juergen Gross1f3ac862014-11-28 11:53:53 +0100374 unsigned long *identity, unsigned long *released)
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700375{
376 unsigned long pfn;
377 unsigned long i = 0;
378 unsigned long n = end_pfn - start_pfn;
379
380 while (i < n) {
381 unsigned long cur_pfn = start_pfn + i;
382 unsigned long left = n - i;
383 unsigned long size = left;
384 unsigned long remap_range_size;
385
386 /* Do not remap pages beyond the current allocation */
387 if (cur_pfn >= nr_pages) {
388 /* Identity map remaining pages */
389 *identity += set_phys_range_identity(cur_pfn,
390 cur_pfn + size);
391 break;
392 }
393 if (cur_pfn + size > nr_pages)
394 size = nr_pages - cur_pfn;
395
396 remap_range_size = xen_find_pfn_range(list, map_size,
397 &remap_pfn);
398 if (!remap_range_size) {
399 pr_warning("Unable to find available pfn range, not remapping identity pages\n");
400 xen_set_identity_and_release_chunk(cur_pfn,
401 cur_pfn + left, nr_pages, identity, released);
402 break;
403 }
404 /* Adjust size to fit in current e820 RAM region */
405 if (size > remap_range_size)
406 size = remap_range_size;
407
Juergen Gross1f3ac862014-11-28 11:53:53 +0100408 xen_do_set_identity_and_remap_chunk(cur_pfn, size, remap_pfn);
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700409
410 /* Update variables to reflect new mappings. */
411 i += size;
412 remap_pfn += size;
413 *identity += size;
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700414 }
415
416 /*
417 * If the PFNs are currently mapped, the VA mapping also needs
418 * to be updated to be 1:1.
419 */
420 for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++)
421 (void)HYPERVISOR_update_va_mapping(
422 (unsigned long)__va(pfn << PAGE_SHIFT),
423 mfn_pte(pfn, PAGE_KERNEL_IO), 0);
424
425 return remap_pfn;
426}
427
Juergen Gross5b8e7d82014-11-28 11:53:55 +0100428static void __init xen_set_identity_and_remap(
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700429 const struct e820entry *list, size_t map_size, unsigned long nr_pages,
430 unsigned long *released)
Miroslav Rezanina093d7b42009-09-16 03:56:17 -0400431{
David Vrabelf3f436e2011-09-28 17:46:36 +0100432 phys_addr_t start = 0;
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500433 unsigned long identity = 0;
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700434 unsigned long last_pfn = nr_pages;
David Vrabelf3f436e2011-09-28 17:46:36 +0100435 const struct e820entry *entry;
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700436 unsigned long num_released = 0;
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500437 int i;
438
David Vrabelf3f436e2011-09-28 17:46:36 +0100439 /*
440 * Combine non-RAM regions and gaps until a RAM region (or the
441 * end of the map) is reached, then set the 1:1 map and
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700442 * remap the memory in those non-RAM regions.
David Vrabelf3f436e2011-09-28 17:46:36 +0100443 *
444 * The combined non-RAM regions are rounded to a whole number
445 * of pages so any partial pages are accessible via the 1:1
446 * mapping. This is needed for some BIOSes that put (for
447 * example) the DMI tables in a reserved region that begins on
448 * a non-page boundary.
449 */
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500450 for (i = 0, entry = list; i < map_size; i++, entry++) {
David Vrabelf3f436e2011-09-28 17:46:36 +0100451 phys_addr_t end = entry->addr + entry->size;
David Vrabelf3f436e2011-09-28 17:46:36 +0100452 if (entry->type == E820_RAM || i == map_size - 1) {
453 unsigned long start_pfn = PFN_DOWN(start);
454 unsigned long end_pfn = PFN_UP(end);
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500455
David Vrabelf3f436e2011-09-28 17:46:36 +0100456 if (entry->type == E820_RAM)
457 end_pfn = PFN_UP(entry->addr);
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500458
David Vrabel83d51ab2012-05-03 16:15:42 +0100459 if (start_pfn < end_pfn)
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700460 last_pfn = xen_set_identity_and_remap_chunk(
461 list, map_size, start_pfn,
462 end_pfn, nr_pages, last_pfn,
Juergen Gross1f3ac862014-11-28 11:53:53 +0100463 &identity, &num_released);
David Vrabelf3f436e2011-09-28 17:46:36 +0100464 start = end;
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500465 }
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500466 }
David Vrabelf3f436e2011-09-28 17:46:36 +0100467
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700468 *released = num_released;
David Vrabelf3f436e2011-09-28 17:46:36 +0100469
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700470 pr_info("Set %ld page(s) to 1-1 mapping\n", identity);
Matt Rushton4fbb67e32014-08-11 11:57:57 -0700471 pr_info("Released %ld page(s)\n", num_released);
Konrad Rzeszutek Wilk68df0da2011-02-01 17:15:30 -0500472}
Juergen Gross1f3ac862014-11-28 11:53:53 +0100473
474/*
475 * Remap the memory prepared in xen_do_set_identity_and_remap_chunk().
476 * The remap information (which mfn remap to which pfn) is contained in the
477 * to be remapped memory itself in a linked list anchored at xen_remap_mfn.
478 * This scheme allows to remap the different chunks in arbitrary order while
479 * the resulting mapping will be independant from the order.
480 */
481void __init xen_remap_memory(void)
482{
483 unsigned long buf = (unsigned long)&xen_remap_buf;
484 unsigned long mfn_save, mfn, pfn;
485 unsigned long remapped = 0;
486 unsigned int i;
487 unsigned long pfn_s = ~0UL;
488 unsigned long len = 0;
489
490 mfn_save = virt_to_mfn(buf);
491
492 while (xen_remap_mfn != INVALID_P2M_ENTRY) {
493 /* Map the remap information */
494 set_pte_mfn(buf, xen_remap_mfn, PAGE_KERNEL);
495
496 BUG_ON(xen_remap_mfn != xen_remap_buf.mfns[0]);
497
498 pfn = xen_remap_buf.target_pfn;
499 for (i = 0; i < xen_remap_buf.size; i++) {
500 mfn = xen_remap_buf.mfns[i];
501 xen_update_mem_tables(pfn, mfn);
502 remapped++;
503 pfn++;
504 }
505 if (pfn_s == ~0UL || pfn == pfn_s) {
506 pfn_s = xen_remap_buf.target_pfn;
507 len += xen_remap_buf.size;
508 } else if (pfn_s + len == xen_remap_buf.target_pfn) {
509 len += xen_remap_buf.size;
510 } else {
Juergen Gross5b8e7d82014-11-28 11:53:55 +0100511 xen_del_extra_mem(PFN_PHYS(pfn_s), PFN_PHYS(len));
Juergen Gross1f3ac862014-11-28 11:53:53 +0100512 pfn_s = xen_remap_buf.target_pfn;
513 len = xen_remap_buf.size;
514 }
515
516 mfn = xen_remap_mfn;
517 xen_remap_mfn = xen_remap_buf.next_area_mfn;
518 }
519
520 if (pfn_s != ~0UL && len)
Juergen Gross5b8e7d82014-11-28 11:53:55 +0100521 xen_del_extra_mem(PFN_PHYS(pfn_s), PFN_PHYS(len));
Juergen Gross1f3ac862014-11-28 11:53:53 +0100522
523 set_pte_mfn(buf, mfn_save, PAGE_KERNEL);
524
525 pr_info("Remapped %ld page(s)\n", remapped);
526}
527
David Vrabeld312ae872011-08-19 15:57:16 +0100528static unsigned long __init xen_get_max_pages(void)
529{
530 unsigned long max_pages = MAX_DOMAIN_PAGES;
531 domid_t domid = DOMID_SELF;
532 int ret;
533
Ian Campbelld3db7282011-12-14 12:16:08 +0000534 /*
535 * For the initial domain we use the maximum reservation as
536 * the maximum page.
537 *
538 * For guest domains the current maximum reservation reflects
539 * the current maximum rather than the static maximum. In this
540 * case the e820 map provided to us will cover the static
541 * maximum region.
542 */
543 if (xen_initial_domain()) {
544 ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid);
545 if (ret > 0)
546 max_pages = ret;
547 }
548
David Vrabeld312ae872011-08-19 15:57:16 +0100549 return min(max_pages, MAX_DOMAIN_PAGES);
550}
551
David Vrabeldc91c722011-09-29 12:26:19 +0100552static void xen_align_and_add_e820_region(u64 start, u64 size, int type)
553{
554 u64 end = start + size;
555
556 /* Align RAM regions to page boundaries. */
557 if (type == E820_RAM) {
558 start = PAGE_ALIGN(start);
559 end &= ~((u64)PAGE_SIZE - 1);
560 }
561
562 e820_add_region(start, end - start, type);
563}
564
David Vrabel3bc38cb2013-08-16 15:42:55 +0100565void xen_ignore_unusable(struct e820entry *list, size_t map_size)
566{
567 struct e820entry *entry;
568 unsigned int i;
569
570 for (i = 0, entry = list; i < map_size; i++, entry++) {
571 if (entry->type == E820_UNUSABLE)
572 entry->type = E820_RAM;
573 }
574}
575
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700576/**
577 * machine_specific_memory_setup - Hook for machine specific memory setup.
578 **/
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700579char * __init xen_memory_setup(void)
580{
Ian Campbell35ae11f2009-02-06 19:09:48 -0800581 static struct e820entry map[E820MAX] __initdata;
582
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700583 unsigned long max_pfn = xen_start_info->nr_pages;
Ian Campbell35ae11f2009-02-06 19:09:48 -0800584 unsigned long long mem_end;
585 int rc;
586 struct xen_memory_map memmap;
David Vrabeldc91c722011-09-29 12:26:19 +0100587 unsigned long max_pages;
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -0700588 unsigned long extra_pages = 0;
Ian Campbell35ae11f2009-02-06 19:09:48 -0800589 int i;
Ian Campbell9e9a5fc2010-09-02 16:16:00 +0100590 int op;
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700591
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +0100592 max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
Ian Campbell35ae11f2009-02-06 19:09:48 -0800593 mem_end = PFN_PHYS(max_pfn);
594
595 memmap.nr_entries = E820MAX;
596 set_xen_guest_handle(memmap.buffer, map);
597
Ian Campbell9e9a5fc2010-09-02 16:16:00 +0100598 op = xen_initial_domain() ?
599 XENMEM_machine_memory_map :
600 XENMEM_memory_map;
601 rc = HYPERVISOR_memory_op(op, &memmap);
Ian Campbell35ae11f2009-02-06 19:09:48 -0800602 if (rc == -ENOSYS) {
Ian Campbell9ec23a7f2010-10-28 11:32:29 -0700603 BUG_ON(xen_initial_domain());
Ian Campbell35ae11f2009-02-06 19:09:48 -0800604 memmap.nr_entries = 1;
605 map[0].addr = 0ULL;
606 map[0].size = mem_end;
607 /* 8MB slack (to balance backend allocations). */
608 map[0].size += 8ULL << 20;
609 map[0].type = E820_RAM;
610 rc = 0;
611 }
612 BUG_ON(rc);
Martin Kelly1ea644c2014-10-16 20:48:11 -0700613 BUG_ON(memmap.nr_entries == 0);
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +0100614
David Vrabel3bc38cb2013-08-16 15:42:55 +0100615 /*
616 * Xen won't allow a 1:1 mapping to be created to UNUSABLE
617 * regions, so if we're using the machine memory map leave the
618 * region as RAM as it is in the pseudo-physical map.
619 *
620 * UNUSABLE regions in domUs are not handled and will need
621 * a patch in the future.
622 */
623 if (xen_initial_domain())
624 xen_ignore_unusable(map, memmap.nr_entries);
625
David Vrabeldc91c722011-09-29 12:26:19 +0100626 /* Make sure the Xen-supplied memory map is well-ordered. */
627 sanitize_e820_map(map, memmap.nr_entries, &memmap.nr_entries);
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -0700628
David Vrabeldc91c722011-09-29 12:26:19 +0100629 max_pages = xen_get_max_pages();
630 if (max_pages > max_pfn)
631 extra_pages += max_pages - max_pfn;
Stefano Stabellini7cb31b72011-01-27 10:13:25 -0500632
David Vrabelf3f436e2011-09-28 17:46:36 +0100633 /*
Juergen Gross1f3ac862014-11-28 11:53:53 +0100634 * Set identity map on non-RAM pages and prepare remapping the
635 * underlying RAM.
David Vrabelf3f436e2011-09-28 17:46:36 +0100636 */
Juergen Gross5b8e7d82014-11-28 11:53:55 +0100637 xen_set_identity_and_remap(map, memmap.nr_entries, max_pfn,
638 &xen_released_pages);
Jeremy Fitzhardinge42ee1472010-08-30 16:41:02 -0700639
Konrad Rzeszutek Wilk58b7b532012-05-29 12:36:43 -0400640 extra_pages += xen_released_pages;
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400641
Konrad Rzeszutek Wilk2e2fb752012-04-06 10:07:11 -0400642 /*
David Vrabeldc91c722011-09-29 12:26:19 +0100643 * Clamp the amount of extra memory to a EXTRA_MEM_RATIO
644 * factor the base size. On non-highmem systems, the base
645 * size is the full initial memory allocation; on highmem it
646 * is limited to the max size of lowmem, so that it doesn't
647 * get completely filled.
648 *
649 * In principle there could be a problem in lowmem systems if
650 * the initial memory is also very large with respect to
651 * lowmem, but we won't try to deal with that here.
652 */
653 extra_pages = min(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)),
654 extra_pages);
David Vrabeldc91c722011-09-29 12:26:19 +0100655 i = 0;
656 while (i < memmap.nr_entries) {
657 u64 addr = map[i].addr;
658 u64 size = map[i].size;
659 u32 type = map[i].type;
660
661 if (type == E820_RAM) {
662 if (addr < mem_end) {
663 size = min(size, mem_end - addr);
664 } else if (extra_pages) {
665 size = min(size, (u64)extra_pages * PAGE_SIZE);
666 extra_pages -= size / PAGE_SIZE;
667 xen_add_extra_mem(addr, size);
Juergen Gross5b8e7d82014-11-28 11:53:55 +0100668 xen_max_p2m_pfn = PFN_DOWN(addr + size);
David Vrabeldc91c722011-09-29 12:26:19 +0100669 } else
670 type = E820_UNUSABLE;
Jeremy Fitzhardinge36545812010-09-29 16:54:33 -0700671 }
672
David Vrabeldc91c722011-09-29 12:26:19 +0100673 xen_align_and_add_e820_region(addr, size, type);
Jeremy Fitzhardingeb5b43ce2010-09-02 17:10:12 -0700674
David Vrabeldc91c722011-09-29 12:26:19 +0100675 map[i].addr += size;
676 map[i].size -= size;
677 if (map[i].size == 0)
678 i++;
Ian Campbell35ae11f2009-02-06 19:09:48 -0800679 }
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -0700680
681 /*
David Vrabel25b884a2014-01-03 15:46:10 +0000682 * Set the rest as identity mapped, in case PCI BARs are
683 * located here.
684 *
685 * PFNs above MAX_P2M_PFN are considered identity mapped as
686 * well.
687 */
688 set_phys_range_identity(map[i-1].addr / PAGE_SIZE, ~0ul);
689
690 /*
Ian Campbell9ec23a7f2010-10-28 11:32:29 -0700691 * In domU, the ISA region is normal, usable memory, but we
692 * reserve ISA memory anyway because too many things poke
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -0700693 * about in there.
694 */
695 e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
696 E820_RESERVED);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700697
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -0700698 /*
699 * Reserve Xen bits:
700 * - mfn_list
701 * - xen_start_info
702 * See comment above "struct start_info" in <xen/interface/xen.h>
Konrad Rzeszutek Wilk51faaf22012-08-22 13:00:10 -0400703 * We tried to make the the memblock_reserve more selective so
704 * that it would be clear what region is reserved. Sadly we ran
705 * in the problem wherein on a 64-bit hypervisor with a 32-bit
706 * initial domain, the pt_base has the cr3 value which is not
707 * neccessarily where the pagetable starts! As Jan put it: "
708 * Actually, the adjustment turns out to be correct: The page
709 * tables for a 32-on-64 dom0 get allocated in the order "first L1",
710 * "first L2", "first L3", so the offset to the page table base is
711 * indeed 2. When reading xen/include/public/xen.h's comment
712 * very strictly, this is not a violation (since there nothing is said
713 * that the first thing in the page table space is pointed to by
714 * pt_base; I admit that this seems to be implied though, namely
715 * do I think that it is implied that the page table space is the
716 * range [pt_base, pt_base + nt_pt_frames), whereas that
717 * range here indeed is [pt_base - 2, pt_base - 2 + nt_pt_frames),
718 * which - without a priori knowledge - the kernel would have
719 * difficulty to figure out)." - so lets just fall back to the
720 * easy way and reserve the whole region.
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -0700721 */
Tejun Heo24aa0782011-07-12 11:16:06 +0200722 memblock_reserve(__pa(xen_start_info->mfn_list),
723 xen_start_info->pt_base - xen_start_info->mfn_list);
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -0700724
725 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
726
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700727 return "Xen";
728}
729
Roland McGrathd2eea682007-07-20 00:31:43 -0700730/*
David Vrabelabacaad2014-06-02 17:58:01 +0100731 * Machine specific memory setup for auto-translated guests.
732 */
733char * __init xen_auto_xlated_memory_setup(void)
734{
735 static struct e820entry map[E820MAX] __initdata;
736
737 struct xen_memory_map memmap;
738 int i;
739 int rc;
740
741 memmap.nr_entries = E820MAX;
742 set_xen_guest_handle(memmap.buffer, map);
743
744 rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
745 if (rc < 0)
746 panic("No memory map (%d)\n", rc);
747
748 sanitize_e820_map(map, ARRAY_SIZE(map), &memmap.nr_entries);
749
750 for (i = 0; i < memmap.nr_entries; i++)
751 e820_add_region(map[i].addr, map[i].size, map[i].type);
752
753 memblock_reserve(__pa(xen_start_info->mfn_list),
754 xen_start_info->pt_base - xen_start_info->mfn_list);
755
756 return "Xen";
757}
758
759/*
Roland McGrathd2eea682007-07-20 00:31:43 -0700760 * Set the bit indicating "nosegneg" library variants should be used.
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -0700761 * We only need to bother in pure 32-bit mode; compat 32-bit processes
762 * can have un-truncated segments, so wrapping around is allowed.
Roland McGrathd2eea682007-07-20 00:31:43 -0700763 */
Sam Ravnborg08b6d292008-01-30 13:33:25 +0100764static void __init fiddle_vdso(void)
Roland McGrathd2eea682007-07-20 00:31:43 -0700765{
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -0700766#ifdef CONFIG_X86_32
Andy Lutomirski6f121e52014-05-05 12:19:34 -0700767 /*
768 * This could be called before selected_vdso32 is initialized, so
769 * just fiddle with both possible images. vdso_image_32_syscall
770 * can't be selected, since it only exists on 64-bit systems.
771 */
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -0700772 u32 *mask;
Andy Lutomirski6f121e52014-05-05 12:19:34 -0700773 mask = vdso_image_32_int80.data +
774 vdso_image_32_int80.sym_VDSO32_NOTE_MASK;
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -0700775 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
Andy Lutomirski6f121e52014-05-05 12:19:34 -0700776 mask = vdso_image_32_sysenter.data +
777 vdso_image_32_sysenter.sym_VDSO32_NOTE_MASK;
Roland McGrathd2eea682007-07-20 00:31:43 -0700778 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700779#endif
Roland McGrathd2eea682007-07-20 00:31:43 -0700780}
781
Paul Gortmaker148f9bb2013-06-18 18:23:59 -0400782static int register_callback(unsigned type, const void *func)
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700783{
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700784 struct callback_register callback = {
785 .type = type,
786 .address = XEN_CALLBACK(__KERNEL_CS, func),
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700787 .flags = CALLBACKF_mask_events,
788 };
789
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700790 return HYPERVISOR_callback_op(CALLBACKOP_register, &callback);
791}
792
Paul Gortmaker148f9bb2013-06-18 18:23:59 -0400793void xen_enable_sysenter(void)
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700794{
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700795 int ret;
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700796 unsigned sysenter_feature;
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700797
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700798#ifdef CONFIG_X86_32
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700799 sysenter_feature = X86_FEATURE_SEP;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700800#else
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700801 sysenter_feature = X86_FEATURE_SYSENTER32;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700802#endif
803
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700804 if (!boot_cpu_has(sysenter_feature))
805 return;
806
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700807 ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target);
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700808 if(ret != 0)
809 setup_clear_cpu_cap(sysenter_feature);
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700810}
811
Paul Gortmaker148f9bb2013-06-18 18:23:59 -0400812void xen_enable_syscall(void)
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700813{
814#ifdef CONFIG_X86_64
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700815 int ret;
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700816
817 ret = register_callback(CALLBACKTYPE_syscall, xen_syscall_target);
818 if (ret != 0) {
Jeremy Fitzhardinged5303b82008-07-12 02:22:06 -0700819 printk(KERN_ERR "Failed to set syscall callback: %d\n", ret);
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700820 /* Pretty fatal; 64-bit userspace has no other
821 mechanism for syscalls. */
822 }
823
824 if (boot_cpu_has(X86_FEATURE_SYSCALL32)) {
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700825 ret = register_callback(CALLBACKTYPE_syscall32,
826 xen_syscall32_target);
Jeremy Fitzhardinged5303b82008-07-12 02:22:06 -0700827 if (ret != 0)
Jeremy Fitzhardinge62541c32008-07-10 16:24:08 -0700828 setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700829 }
830#endif /* CONFIG_X86_64 */
831}
David Vrabelea9f9272014-06-16 13:07:00 +0200832
Mukesh Rathord285d682013-12-13 12:45:31 -0500833void __init xen_pvmmu_arch_setup(void)
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700834{
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700835 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
836 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
837
Mukesh Rathord285d682013-12-13 12:45:31 -0500838 HYPERVISOR_vm_assist(VMASST_CMD_enable,
839 VMASST_TYPE_pae_extended_cr3);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700840
Jeremy Fitzhardinge88459d42008-07-08 15:07:02 -0700841 if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) ||
842 register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback))
843 BUG();
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700844
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700845 xen_enable_sysenter();
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700846 xen_enable_syscall();
Mukesh Rathord285d682013-12-13 12:45:31 -0500847}
848
849/* This function is not called for HVM domains */
850void __init xen_arch_setup(void)
851{
852 xen_panic_handler_init();
853 if (!xen_feature(XENFEAT_auto_translated_physmap))
854 xen_pvmmu_arch_setup();
855
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700856#ifdef CONFIG_ACPI
857 if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
858 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
859 disable_acpi();
860 }
861#endif
862
863 memcpy(boot_command_line, xen_start_info->cmd_line,
864 MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
865 COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
866
Jeremy Fitzhardingebc15fde2010-11-22 17:17:50 -0800867 /* Set up idle, making sure it calls safe_halt() pvop */
Len Brownd91ee582011-04-01 18:28:35 -0400868 disable_cpuidle();
Konrad Rzeszutek Wilk48cdd822012-03-13 20:06:57 -0400869 disable_cpufreq();
Len Brown6a377dd2013-02-09 23:08:07 -0500870 WARN_ON(xen_set_default_idle());
Roland McGrathd2eea682007-07-20 00:31:43 -0700871 fiddle_vdso();
Konrad Rzeszutek Wilk8d54db792012-08-17 10:22:37 -0400872#ifdef CONFIG_NUMA
873 numa_off = 1;
874#endif
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700875}