blob: e0a39595bde3b342c8364a4306f3b8ea61d88def [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[];
31
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070032
33/**
34 * machine_specific_memory_setup - Hook for machine specific memory setup.
35 **/
36
37char * __init xen_memory_setup(void)
38{
39 unsigned long max_pfn = xen_start_info->nr_pages;
40
Jeremy Fitzhardinge8006ec32008-05-26 23:31:19 +010041 max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
42
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070043 e820.nr_map = 0;
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -070044
Jeremy Fitzhardingeb792c752008-06-16 14:54:49 -070045 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);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070054
Jeremy Fitzhardingebe5bf9f2008-06-16 14:54:46 -070055 /*
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
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070067 return "Xen";
68}
69
70static 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
Roland McGrathd2eea682007-07-20 00:31:43 -070084/*
85 * Set the bit indicating "nosegneg" library variants should be used.
86 */
Sam Ravnborg08b6d292008-01-30 13:33:25 +010087static void __init fiddle_vdso(void)
Roland McGrathd2eea682007-07-20 00:31:43 -070088{
Roland McGrathaf65d642008-01-30 13:30:43 +010089 extern const char vdso32_default_start;
90 u32 *mask = VDSO32_SYMBOL(&vdso32_default_start, NOTE_MASK);
Roland McGrathd2eea682007-07-20 00:31:43 -070091 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
92}
93
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -070094void xen_enable_sysenter(void)
95{
96 int cpu = smp_processor_id();
97 extern void xen_sysenter_target(void);
98 /* Mask events on entry, even though they get enabled immediately */
99 static struct callback_register sysenter = {
100 .type = CALLBACKTYPE_sysenter,
101 .address = { __KERNEL_CS, (unsigned long)xen_sysenter_target },
102 .flags = CALLBACKF_mask_events,
103 };
104
105 if (!boot_cpu_has(X86_FEATURE_SEP) ||
106 HYPERVISOR_callback_op(CALLBACKOP_register, &sysenter) != 0) {
107 clear_cpu_cap(&cpu_data(cpu), X86_FEATURE_SEP);
108 clear_cpu_cap(&boot_cpu_data, X86_FEATURE_SEP);
109 }
110}
111
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700112void __init xen_arch_setup(void)
113{
114 struct physdev_set_iopl set_iopl;
115 int rc;
116
117 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
118 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
119
120 if (!xen_feature(XENFEAT_auto_translated_physmap))
121 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_pae_extended_cr3);
122
123 HYPERVISOR_set_callbacks(__KERNEL_CS, (unsigned long)xen_hypervisor_callback,
124 __KERNEL_CS, (unsigned long)xen_failsafe_callback);
125
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700126 xen_enable_sysenter();
127
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700128 set_iopl.iopl = 1;
129 rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
130 if (rc != 0)
131 printk(KERN_INFO "physdev_op failed %d\n", rc);
132
133#ifdef CONFIG_ACPI
134 if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
135 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
136 disable_acpi();
137 }
138#endif
139
140 memcpy(boot_command_line, xen_start_info->cmd_line,
141 MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
142 COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
143
144 pm_idle = xen_idle;
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700145
146#ifdef CONFIG_SMP
147 /* fill cpus_possible with all available cpus */
148 xen_fill_possible_map();
149#endif
Jeremy Fitzhardingedfdcdd42007-07-17 18:37:07 -0700150
151 paravirt_disable_iospace();
Roland McGrathd2eea682007-07-20 00:31:43 -0700152
153 fiddle_vdso();
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700154}