blob: 82517e4a752a19049c0177768851f48a1190a639 [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 Fitzhardingee2a81ba2008-03-17 16:37:17 -070019#include <xen/interface/callback.h>
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070020#include <xen/interface/physdev.h>
21#include <xen/features.h>
22
23#include "xen-ops.h"
Roland McGrathd2eea682007-07-20 00:31:43 -070024#include "vdso.h"
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070025
26/* These are code, but not functions. Defined in entry.S */
27extern const char xen_hypervisor_callback[];
28extern const char xen_failsafe_callback[];
29
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070030unsigned long *phys_to_machine_mapping;
31EXPORT_SYMBOL(phys_to_machine_mapping);
32
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
41 e820.nr_map = 0;
Ian Campbell87d034f2008-02-28 23:16:49 +000042 add_memory_region(0, LOWMEMSIZE(), E820_RAM);
43 add_memory_region(HIGH_MEMORY, PFN_PHYS(max_pfn)-HIGH_MEMORY, E820_RAM);
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070044
45 return "Xen";
46}
47
48static void xen_idle(void)
49{
50 local_irq_disable();
51
52 if (need_resched())
53 local_irq_enable();
54 else {
55 current_thread_info()->status &= ~TS_POLLING;
56 smp_mb__after_clear_bit();
57 safe_halt();
58 current_thread_info()->status |= TS_POLLING;
59 }
60}
61
Roland McGrathd2eea682007-07-20 00:31:43 -070062/*
63 * Set the bit indicating "nosegneg" library variants should be used.
64 */
Sam Ravnborg08b6d292008-01-30 13:33:25 +010065static void __init fiddle_vdso(void)
Roland McGrathd2eea682007-07-20 00:31:43 -070066{
Roland McGrathaf65d642008-01-30 13:30:43 +010067 extern const char vdso32_default_start;
68 u32 *mask = VDSO32_SYMBOL(&vdso32_default_start, NOTE_MASK);
Roland McGrathd2eea682007-07-20 00:31:43 -070069 *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT;
70}
71
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -070072void xen_enable_sysenter(void)
73{
74 int cpu = smp_processor_id();
75 extern void xen_sysenter_target(void);
76 /* Mask events on entry, even though they get enabled immediately */
77 static struct callback_register sysenter = {
78 .type = CALLBACKTYPE_sysenter,
79 .address = { __KERNEL_CS, (unsigned long)xen_sysenter_target },
80 .flags = CALLBACKF_mask_events,
81 };
82
83 if (!boot_cpu_has(X86_FEATURE_SEP) ||
84 HYPERVISOR_callback_op(CALLBACKOP_register, &sysenter) != 0) {
85 clear_cpu_cap(&cpu_data(cpu), X86_FEATURE_SEP);
86 clear_cpu_cap(&boot_cpu_data, X86_FEATURE_SEP);
87 }
88}
89
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -070090void __init xen_arch_setup(void)
91{
92 struct physdev_set_iopl set_iopl;
93 int rc;
94
95 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
96 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
97
98 if (!xen_feature(XENFEAT_auto_translated_physmap))
99 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_pae_extended_cr3);
100
101 HYPERVISOR_set_callbacks(__KERNEL_CS, (unsigned long)xen_hypervisor_callback,
102 __KERNEL_CS, (unsigned long)xen_failsafe_callback);
103
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700104 xen_enable_sysenter();
105
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700106 set_iopl.iopl = 1;
107 rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
108 if (rc != 0)
109 printk(KERN_INFO "physdev_op failed %d\n", rc);
110
111#ifdef CONFIG_ACPI
112 if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
113 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
114 disable_acpi();
115 }
116#endif
117
118 memcpy(boot_command_line, xen_start_info->cmd_line,
119 MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
120 COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
121
122 pm_idle = xen_idle;
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700123
124#ifdef CONFIG_SMP
125 /* fill cpus_possible with all available cpus */
126 xen_fill_possible_map();
127#endif
Jeremy Fitzhardingedfdcdd42007-07-17 18:37:07 -0700128
129 paravirt_disable_iospace();
Roland McGrathd2eea682007-07-20 00:31:43 -0700130
131 fiddle_vdso();
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700132}