blob: dc2ca8ad3603aba73b8a4ed8c78478c74e31ba4a [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>
16#include <asm/xen/hypervisor.h>
17#include <asm/xen/hypercall.h>
18
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +010019#include <xen/page.h>
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -070020#include <xen/interface/callback.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070021#include <xen/interface/physdev.h>
22#include <xen/features.h>
23
24#include "xen-ops.h"
Roland McGrathd2eea682007-07-20 00:31:43 -070025#include "vdso.h"
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070026
27/* These are code, but not functions. Defined in entry.S */
28extern const char xen_hypervisor_callback[];
29extern const char xen_failsafe_callback[];
30
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070031
32/**
33 * machine_specific_memory_setup - Hook for machine specific memory setup.
34 **/
35
36char * __init xen_memory_setup(void)
37{
38 unsigned long max_pfn = xen_start_info->nr_pages;
39
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +010040 max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
41
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070042 e820.nr_map = 0;
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -070043
Yinghai Lud0be6bd2008-06-15 18:58:51 -070044 e820_add_region(0, LOWMEMSIZE(), E820_RAM);
45 e820_add_region(HIGH_MEMORY, PFN_PHYS(max_pfn)-HIGH_MEMORY, E820_RAM);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070046
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -070047 /*
48 * Reserve Xen bits:
49 * - mfn_list
50 * - xen_start_info
51 * See comment above "struct start_info" in <xen/interface/xen.h>
52 */
53 e820_add_region(__pa(xen_start_info->mfn_list),
54 xen_start_info->pt_base - xen_start_info->mfn_list,
55 E820_RESERVED);
56
57 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
58
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070059 return "Xen";
60}
61
62static void xen_idle(void)
63{
64 local_irq_disable();
65
66 if (need_resched())
67 local_irq_enable();
68 else {
69 current_thread_info()->status &= ~TS_POLLING;
70 smp_mb__after_clear_bit();
71 safe_halt();
72 current_thread_info()->status |= TS_POLLING;
73 }
74}
75
Roland McGrathd2eea682007-07-20 00:31:43 -070076/*
77 * Set the bit indicating "nosegneg" library variants should be used.
78 */
Sam Ravnborg08b6d292008-01-30 13:33:25 +010079static void __init fiddle_vdso(void)
Roland McGrathd2eea682007-07-20 00:31:43 -070080{
Roland McGrathaf65d642008-01-30 13:30:43 +010081 extern const char vdso32_default_start;
82 u32 *mask = VDSO32_SYMBOL(&vdso32_default_start, NOTE_MASK);
Roland McGrathd2eea682007-07-20 00:31:43 -070083 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
84}
85
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -070086void xen_enable_sysenter(void)
87{
88 int cpu = smp_processor_id();
89 extern void xen_sysenter_target(void);
90 /* Mask events on entry, even though they get enabled immediately */
91 static struct callback_register sysenter = {
92 .type = CALLBACKTYPE_sysenter,
93 .address = { __KERNEL_CS, (unsigned long)xen_sysenter_target },
94 .flags = CALLBACKF_mask_events,
95 };
96
97 if (!boot_cpu_has(X86_FEATURE_SEP) ||
98 HYPERVISOR_callback_op(CALLBACKOP_register, &sysenter) != 0) {
99 clear_cpu_cap(&cpu_data(cpu), X86_FEATURE_SEP);
100 clear_cpu_cap(&boot_cpu_data, X86_FEATURE_SEP);
101 }
102}
103
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700104void __init xen_arch_setup(void)
105{
106 struct physdev_set_iopl set_iopl;
107 int rc;
108
109 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
110 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
111
112 if (!xen_feature(XENFEAT_auto_translated_physmap))
113 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_pae_extended_cr3);
114
115 HYPERVISOR_set_callbacks(__KERNEL_CS, (unsigned long)xen_hypervisor_callback,
116 __KERNEL_CS, (unsigned long)xen_failsafe_callback);
117
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700118 xen_enable_sysenter();
119
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700120 set_iopl.iopl = 1;
121 rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
122 if (rc != 0)
123 printk(KERN_INFO "physdev_op failed %d\n", rc);
124
125#ifdef CONFIG_ACPI
126 if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
127 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
128 disable_acpi();
129 }
130#endif
131
132 memcpy(boot_command_line, xen_start_info->cmd_line,
133 MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
134 COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
135
136 pm_idle = xen_idle;
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700137
138#ifdef CONFIG_SMP
139 /* fill cpus_possible with all available cpus */
140 xen_fill_possible_map();
141#endif
Jeremy Fitzhardingedfdcdd42007-07-17 18:37:07 -0700142
143 paravirt_disable_iospace();
Roland McGrathd2eea682007-07-20 00:31:43 -0700144
145 fiddle_vdso();
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700146}