Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1 | /* |
| 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 McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 13 | #include <asm/vdso.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 14 | #include <asm/e820.h> |
| 15 | #include <asm/setup.h> |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 16 | #include <asm/acpi.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 17 | #include <asm/xen/hypervisor.h> |
| 18 | #include <asm/xen/hypercall.h> |
| 19 | |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 20 | #include <xen/page.h> |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 21 | #include <xen/interface/callback.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 22 | #include <xen/interface/physdev.h> |
| 23 | #include <xen/features.h> |
| 24 | |
| 25 | #include "xen-ops.h" |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 26 | #include "vdso.h" |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 27 | |
| 28 | /* These are code, but not functions. Defined in entry.S */ |
| 29 | extern const char xen_hypervisor_callback[]; |
| 30 | extern const char xen_failsafe_callback[]; |
| 31 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * machine_specific_memory_setup - Hook for machine specific memory setup. |
| 35 | **/ |
| 36 | |
| 37 | char * __init xen_memory_setup(void) |
| 38 | { |
| 39 | unsigned long max_pfn = xen_start_info->nr_pages; |
| 40 | |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 41 | max_pfn = min(MAX_DOMAIN_PAGES, max_pfn); |
| 42 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 43 | e820.nr_map = 0; |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 44 | |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 45 | 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 Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 54 | |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 55 | /* |
| 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 Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 67 | return "Xen"; |
| 68 | } |
| 69 | |
| 70 | static 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 McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 84 | /* |
| 85 | * Set the bit indicating "nosegneg" library variants should be used. |
| 86 | */ |
Sam Ravnborg | 08b6d29 | 2008-01-30 13:33:25 +0100 | [diff] [blame] | 87 | static void __init fiddle_vdso(void) |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 88 | { |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame^] | 89 | #if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 90 | extern const char vdso32_default_start; |
| 91 | u32 *mask = VDSO32_SYMBOL(&vdso32_default_start, NOTE_MASK); |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 92 | *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame^] | 93 | #endif |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 96 | static __cpuinit int register_callback(unsigned type, const void *func) |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 97 | { |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 98 | struct callback_register callback = { |
| 99 | .type = type, |
| 100 | .address = XEN_CALLBACK(__KERNEL_CS, func), |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 101 | .flags = CALLBACKF_mask_events, |
| 102 | }; |
| 103 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 104 | return HYPERVISOR_callback_op(CALLBACKOP_register, &callback); |
| 105 | } |
| 106 | |
| 107 | void __cpuinit xen_enable_sysenter(void) |
| 108 | { |
| 109 | int cpu = smp_processor_id(); |
| 110 | extern void xen_sysenter_target(void); |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame^] | 111 | int ret; |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 112 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame^] | 113 | #ifdef CONFIG_X86_32 |
| 114 | if (!boot_cpu_has(X86_FEATURE_SEP)) { |
| 115 | return; |
| 116 | } |
| 117 | #else |
| 118 | if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL && |
| 119 | boot_cpu_data.x86_vendor != X86_VENDOR_CENTAUR) { |
| 120 | return; |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target); |
| 125 | if(ret != 0) { |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 126 | clear_cpu_cap(&cpu_data(cpu), X86_FEATURE_SEP); |
| 127 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_SEP); |
| 128 | } |
| 129 | } |
| 130 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame^] | 131 | void __cpuinit xen_enable_syscall(void) |
| 132 | { |
| 133 | #ifdef CONFIG_X86_64 |
| 134 | int cpu = smp_processor_id(); |
| 135 | int ret; |
| 136 | extern void xen_syscall_target(void); |
| 137 | extern void xen_syscall32_target(void); |
| 138 | |
| 139 | ret = register_callback(CALLBACKTYPE_syscall, xen_syscall_target); |
| 140 | if (ret != 0) { |
| 141 | printk("failed to set syscall: %d\n", ret); |
| 142 | clear_cpu_cap(&cpu_data(cpu), X86_FEATURE_SYSCALL); |
| 143 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_SYSCALL); |
| 144 | } else { |
| 145 | ret = register_callback(CALLBACKTYPE_syscall32, |
| 146 | xen_syscall32_target); |
| 147 | if (ret != 0) |
| 148 | printk("failed to set 32-bit syscall: %d\n", ret); |
| 149 | } |
| 150 | #endif /* CONFIG_X86_64 */ |
| 151 | } |
| 152 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 153 | void __init xen_arch_setup(void) |
| 154 | { |
| 155 | struct physdev_set_iopl set_iopl; |
| 156 | int rc; |
| 157 | |
| 158 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); |
| 159 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); |
| 160 | |
| 161 | if (!xen_feature(XENFEAT_auto_translated_physmap)) |
| 162 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_pae_extended_cr3); |
| 163 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 164 | if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) || |
| 165 | register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback)) |
| 166 | BUG(); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 167 | |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 168 | xen_enable_sysenter(); |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame^] | 169 | xen_enable_syscall(); |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 170 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 171 | set_iopl.iopl = 1; |
| 172 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl); |
| 173 | if (rc != 0) |
| 174 | printk(KERN_INFO "physdev_op failed %d\n", rc); |
| 175 | |
| 176 | #ifdef CONFIG_ACPI |
| 177 | if (!(xen_start_info->flags & SIF_INITDOMAIN)) { |
| 178 | printk(KERN_INFO "ACPI in unprivileged domain disabled\n"); |
| 179 | disable_acpi(); |
| 180 | } |
| 181 | #endif |
| 182 | |
| 183 | memcpy(boot_command_line, xen_start_info->cmd_line, |
| 184 | MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ? |
| 185 | COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE); |
| 186 | |
| 187 | pm_idle = xen_idle; |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 188 | |
Jeremy Fitzhardinge | dfdcdd4 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 189 | paravirt_disable_iospace(); |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 190 | |
| 191 | fiddle_vdso(); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 192 | } |