Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * VMI specific paravirt-ops implementation |
| 3 | * |
| 4 | * Copyright (C) 2005, VMware, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 14 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 15 | * details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | * |
| 21 | * Send feedback to zach@vmware.com |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/module.h> |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 26 | #include <linux/cpu.h> |
| 27 | #include <linux/bootmem.h> |
| 28 | #include <linux/mm.h> |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 29 | #include <linux/highmem.h> |
Alexey Dobriyan | fa0aa86 | 2007-06-01 00:46:27 -0700 | [diff] [blame] | 30 | #include <linux/sched.h> |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 31 | #include <asm/vmi.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/fixmap.h> |
| 34 | #include <asm/apicdef.h> |
| 35 | #include <asm/apic.h> |
| 36 | #include <asm/processor.h> |
| 37 | #include <asm/timer.h> |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 38 | #include <asm/vmi_time.h> |
Adrian Bunk | 8f48561 | 2007-03-05 00:30:56 -0800 | [diff] [blame] | 39 | #include <asm/kmap_types.h> |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 40 | |
| 41 | /* Convenient for calling VMI functions indirectly in the ROM */ |
| 42 | typedef u32 __attribute__((regparm(1))) (VROMFUNC)(void); |
| 43 | typedef u64 __attribute__((regparm(2))) (VROMLONGFUNC)(int); |
| 44 | |
| 45 | #define call_vrom_func(rom,func) \ |
| 46 | (((VROMFUNC *)(rom->func))()) |
| 47 | |
| 48 | #define call_vrom_long_func(rom,func,arg) \ |
| 49 | (((VROMLONGFUNC *)(rom->func)) (arg)) |
| 50 | |
| 51 | static struct vrom_header *vmi_rom; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 52 | static int disable_pge; |
| 53 | static int disable_pse; |
| 54 | static int disable_sep; |
| 55 | static int disable_tsc; |
| 56 | static int disable_mtrr; |
Zachary Amsden | 7507ba3 | 2007-03-05 00:30:34 -0800 | [diff] [blame] | 57 | static int disable_noidle; |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 58 | static int disable_vmi_timer; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 59 | |
| 60 | /* Cached VMI operations */ |
Adrian Bunk | 30a1528 | 2007-05-02 19:27:08 +0200 | [diff] [blame] | 61 | static struct { |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 62 | void (*cpuid)(void /* non-c */); |
| 63 | void (*_set_ldt)(u32 selector); |
| 64 | void (*set_tr)(u32 selector); |
Glauber de Oliveira Costa | 8d94734 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 65 | void (*write_idt_entry)(struct desc_struct *, int, u32, u32); |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 66 | void (*write_gdt_entry)(struct desc_struct *, int, u32, u32); |
Glauber de Oliveira Costa | 75b8bb3 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 67 | void (*write_ldt_entry)(struct desc_struct *, int, u32, u32); |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 68 | void (*set_kernel_stack)(u32 selector, u32 sp0); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 69 | void (*allocate_page)(u32, u32, u32, u32, u32); |
| 70 | void (*release_page)(u32, u32); |
| 71 | void (*set_pte)(pte_t, pte_t *, unsigned); |
| 72 | void (*update_pte)(pte_t *, unsigned); |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 73 | void (*set_linear_mapping)(int, void *, u32, u32); |
| 74 | void (*_flush_tlb)(int); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 75 | void (*set_initial_ap_state)(int, int); |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 76 | void (*halt)(void); |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 77 | void (*set_lazy_mode)(int mode); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 78 | } vmi_ops; |
| 79 | |
Zachary Amsden | e0bb864 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 80 | /* Cached VMI operations */ |
| 81 | struct vmi_timer_ops vmi_timer_ops; |
| 82 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 83 | /* |
| 84 | * VMI patching routines. |
| 85 | */ |
| 86 | #define MNEM_CALL 0xe8 |
| 87 | #define MNEM_JMP 0xe9 |
| 88 | #define MNEM_RET 0xc3 |
| 89 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 90 | #define IRQ_PATCH_INT_MASK 0 |
| 91 | #define IRQ_PATCH_DISABLE 5 |
| 92 | |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 93 | static inline void patch_offset(void *insnbuf, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 94 | unsigned long ip, unsigned long dest) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 95 | { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 96 | *(unsigned long *)(insnbuf+1) = dest-ip-5; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 99 | static unsigned patch_internal(int call, unsigned len, void *insnbuf, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 100 | unsigned long ip) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 101 | { |
| 102 | u64 reloc; |
| 103 | struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc; |
| 104 | reloc = call_vrom_long_func(vmi_rom, get_reloc, call); |
| 105 | switch(rel->type) { |
| 106 | case VMI_RELOCATION_CALL_REL: |
| 107 | BUG_ON(len < 5); |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 108 | *(char *)insnbuf = MNEM_CALL; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 109 | patch_offset(insnbuf, ip, (unsigned long)rel->eip); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 110 | return 5; |
| 111 | |
| 112 | case VMI_RELOCATION_JUMP_REL: |
| 113 | BUG_ON(len < 5); |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 114 | *(char *)insnbuf = MNEM_JMP; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 115 | patch_offset(insnbuf, ip, (unsigned long)rel->eip); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 116 | return 5; |
| 117 | |
| 118 | case VMI_RELOCATION_NOP: |
| 119 | /* obliterate the whole thing */ |
| 120 | return 0; |
| 121 | |
| 122 | case VMI_RELOCATION_NONE: |
| 123 | /* leave native code in place */ |
| 124 | break; |
| 125 | |
| 126 | default: |
| 127 | BUG(); |
| 128 | } |
| 129 | return len; |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * Apply patch if appropriate, return length of new instruction |
| 134 | * sequence. The callee does nop padding for us. |
| 135 | */ |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 136 | static unsigned vmi_patch(u8 type, u16 clobbers, void *insns, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 137 | unsigned long ip, unsigned len) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 138 | { |
| 139 | switch (type) { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 140 | case PARAVIRT_PATCH(pv_irq_ops.irq_disable): |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 141 | return patch_internal(VMI_CALL_DisableInterrupts, len, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 142 | insns, ip); |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 143 | case PARAVIRT_PATCH(pv_irq_ops.irq_enable): |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 144 | return patch_internal(VMI_CALL_EnableInterrupts, len, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 145 | insns, ip); |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 146 | case PARAVIRT_PATCH(pv_irq_ops.restore_fl): |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 147 | return patch_internal(VMI_CALL_SetInterruptMask, len, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 148 | insns, ip); |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 149 | case PARAVIRT_PATCH(pv_irq_ops.save_fl): |
Andi Kleen | ab144f5 | 2007-08-10 22:31:03 +0200 | [diff] [blame] | 150 | return patch_internal(VMI_CALL_GetInterruptMask, len, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 151 | insns, ip); |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 152 | case PARAVIRT_PATCH(pv_cpu_ops.iret): |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 153 | return patch_internal(VMI_CALL_IRET, len, insns, ip); |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 154 | case PARAVIRT_PATCH(pv_cpu_ops.irq_enable_syscall_ret): |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 155 | return patch_internal(VMI_CALL_SYSEXIT, len, insns, ip); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 156 | default: |
| 157 | break; |
| 158 | } |
| 159 | return len; |
| 160 | } |
| 161 | |
| 162 | /* CPUID has non-C semantics, and paravirt-ops API doesn't match hardware ISA */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 163 | static void vmi_cpuid(unsigned int *ax, unsigned int *bx, |
| 164 | unsigned int *cx, unsigned int *dx) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 165 | { |
| 166 | int override = 0; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 167 | if (*ax == 1) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 168 | override = 1; |
| 169 | asm volatile ("call *%6" |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 170 | : "=a" (*ax), |
| 171 | "=b" (*bx), |
| 172 | "=c" (*cx), |
| 173 | "=d" (*dx) |
| 174 | : "0" (*ax), "2" (*cx), "r" (vmi_ops.cpuid)); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 175 | if (override) { |
| 176 | if (disable_pse) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 177 | *dx &= ~X86_FEATURE_PSE; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 178 | if (disable_pge) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 179 | *dx &= ~X86_FEATURE_PGE; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 180 | if (disable_sep) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 181 | *dx &= ~X86_FEATURE_SEP; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 182 | if (disable_tsc) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 183 | *dx &= ~X86_FEATURE_TSC; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 184 | if (disable_mtrr) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 185 | *dx &= ~X86_FEATURE_MTRR; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
| 189 | static inline void vmi_maybe_load_tls(struct desc_struct *gdt, int nr, struct desc_struct *new) |
| 190 | { |
| 191 | if (gdt[nr].a != new->a || gdt[nr].b != new->b) |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 192 | write_gdt_entry(gdt, nr, new, 0); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static void vmi_load_tls(struct thread_struct *t, unsigned int cpu) |
| 196 | { |
| 197 | struct desc_struct *gdt = get_cpu_gdt_table(cpu); |
| 198 | vmi_maybe_load_tls(gdt, GDT_ENTRY_TLS_MIN + 0, &t->tls_array[0]); |
| 199 | vmi_maybe_load_tls(gdt, GDT_ENTRY_TLS_MIN + 1, &t->tls_array[1]); |
| 200 | vmi_maybe_load_tls(gdt, GDT_ENTRY_TLS_MIN + 2, &t->tls_array[2]); |
| 201 | } |
| 202 | |
| 203 | static void vmi_set_ldt(const void *addr, unsigned entries) |
| 204 | { |
| 205 | unsigned cpu = smp_processor_id(); |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 206 | struct desc_struct desc; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 207 | |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 208 | pack_descriptor(&desc, (unsigned long)addr, |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 209 | entries * sizeof(struct desc_struct) - 1, |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 210 | DESC_LDT, 0); |
| 211 | write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_LDT, &desc, DESC_LDT); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 212 | vmi_ops._set_ldt(entries ? GDT_ENTRY_LDT*sizeof(struct desc_struct) : 0); |
| 213 | } |
| 214 | |
| 215 | static void vmi_set_tr(void) |
| 216 | { |
| 217 | vmi_ops.set_tr(GDT_ENTRY_TSS*sizeof(struct desc_struct)); |
| 218 | } |
| 219 | |
Glauber de Oliveira Costa | 8d94734 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 220 | static void vmi_write_idt_entry(gate_desc *dt, int entry, const gate_desc *g) |
| 221 | { |
| 222 | u32 *idt_entry = (u32 *)g; |
Ingo Molnar | 262d5ee | 2008-02-04 16:47:54 +0100 | [diff] [blame] | 223 | vmi_ops.write_idt_entry(dt, entry, idt_entry[0], idt_entry[1]); |
Glauber de Oliveira Costa | 8d94734 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 226 | static void vmi_write_gdt_entry(struct desc_struct *dt, int entry, |
| 227 | const void *desc, int type) |
| 228 | { |
| 229 | u32 *gdt_entry = (u32 *)desc; |
Ingo Molnar | 262d5ee | 2008-02-04 16:47:54 +0100 | [diff] [blame] | 230 | vmi_ops.write_gdt_entry(dt, entry, gdt_entry[0], gdt_entry[1]); |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 231 | } |
| 232 | |
Glauber de Oliveira Costa | 75b8bb3 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 233 | static void vmi_write_ldt_entry(struct desc_struct *dt, int entry, |
| 234 | const void *desc) |
| 235 | { |
| 236 | u32 *ldt_entry = (u32 *)desc; |
Ingo Molnar | 262d5ee | 2008-02-04 16:47:54 +0100 | [diff] [blame] | 237 | vmi_ops.write_idt_entry(dt, entry, ldt_entry[0], ldt_entry[1]); |
Glauber de Oliveira Costa | 75b8bb3 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 238 | } |
| 239 | |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 240 | static void vmi_load_sp0(struct tss_struct *tss, |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 241 | struct thread_struct *thread) |
| 242 | { |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 243 | tss->x86_tss.sp0 = thread->sp0; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 244 | |
| 245 | /* This can only happen when SEP is enabled, no need to test "SEP"arately */ |
Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 246 | if (unlikely(tss->x86_tss.ss1 != thread->sysenter_cs)) { |
| 247 | tss->x86_tss.ss1 = thread->sysenter_cs; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 248 | wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0); |
| 249 | } |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 250 | vmi_ops.set_kernel_stack(__KERNEL_DS, tss->x86_tss.sp0); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static void vmi_flush_tlb_user(void) |
| 254 | { |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 255 | vmi_ops._flush_tlb(VMI_FLUSH_TLB); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static void vmi_flush_tlb_kernel(void) |
| 259 | { |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 260 | vmi_ops._flush_tlb(VMI_FLUSH_TLB | VMI_FLUSH_GLOBAL); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* Stub to do nothing at all; used for delays and unimplemented calls */ |
| 264 | static void vmi_nop(void) |
| 265 | { |
| 266 | } |
| 267 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 268 | #ifdef CONFIG_DEBUG_PAGE_TYPE |
| 269 | |
| 270 | #ifdef CONFIG_X86_PAE |
| 271 | #define MAX_BOOT_PTS (2048+4+1) |
| 272 | #else |
| 273 | #define MAX_BOOT_PTS (1024+1) |
| 274 | #endif |
| 275 | |
| 276 | /* |
| 277 | * During boot, mem_map is not yet available in paging_init, so stash |
| 278 | * all the boot page allocations here. |
| 279 | */ |
| 280 | static struct { |
| 281 | u32 pfn; |
| 282 | int type; |
| 283 | } boot_page_allocations[MAX_BOOT_PTS]; |
| 284 | static int num_boot_page_allocations; |
| 285 | static int boot_allocations_applied; |
| 286 | |
| 287 | void vmi_apply_boot_page_allocations(void) |
| 288 | { |
| 289 | int i; |
| 290 | BUG_ON(!mem_map); |
| 291 | for (i = 0; i < num_boot_page_allocations; i++) { |
| 292 | struct page *page = pfn_to_page(boot_page_allocations[i].pfn); |
| 293 | page->type = boot_page_allocations[i].type; |
| 294 | page->type = boot_page_allocations[i].type & |
| 295 | ~(VMI_PAGE_ZEROED | VMI_PAGE_CLONE); |
| 296 | } |
| 297 | boot_allocations_applied = 1; |
| 298 | } |
| 299 | |
| 300 | static void record_page_type(u32 pfn, int type) |
| 301 | { |
| 302 | BUG_ON(num_boot_page_allocations >= MAX_BOOT_PTS); |
| 303 | boot_page_allocations[num_boot_page_allocations].pfn = pfn; |
| 304 | boot_page_allocations[num_boot_page_allocations].type = type; |
| 305 | num_boot_page_allocations++; |
| 306 | } |
| 307 | |
| 308 | static void check_zeroed_page(u32 pfn, int type, struct page *page) |
| 309 | { |
| 310 | u32 *ptr; |
| 311 | int i; |
| 312 | int limit = PAGE_SIZE / sizeof(int); |
| 313 | |
| 314 | if (page_address(page)) |
| 315 | ptr = (u32 *)page_address(page); |
| 316 | else |
| 317 | ptr = (u32 *)__va(pfn << PAGE_SHIFT); |
| 318 | /* |
| 319 | * When cloning the root in non-PAE mode, only the userspace |
| 320 | * pdes need to be zeroed. |
| 321 | */ |
| 322 | if (type & VMI_PAGE_CLONE) |
Jeremy Fitzhardinge | 68db065 | 2008-03-17 16:37:13 -0700 | [diff] [blame] | 323 | limit = KERNEL_PGD_BOUNDARY; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 324 | for (i = 0; i < limit; i++) |
| 325 | BUG_ON(ptr[i]); |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | * We stash the page type into struct page so we can verify the page |
| 330 | * types are used properly. |
| 331 | */ |
| 332 | static void vmi_set_page_type(u32 pfn, int type) |
| 333 | { |
| 334 | /* PAE can have multiple roots per page - don't track */ |
| 335 | if (PTRS_PER_PMD > 1 && (type & VMI_PAGE_PDP)) |
| 336 | return; |
| 337 | |
| 338 | if (boot_allocations_applied) { |
| 339 | struct page *page = pfn_to_page(pfn); |
| 340 | if (type != VMI_PAGE_NORMAL) |
| 341 | BUG_ON(page->type); |
| 342 | else |
| 343 | BUG_ON(page->type == VMI_PAGE_NORMAL); |
| 344 | page->type = type & ~(VMI_PAGE_ZEROED | VMI_PAGE_CLONE); |
| 345 | if (type & VMI_PAGE_ZEROED) |
| 346 | check_zeroed_page(pfn, type, page); |
| 347 | } else { |
| 348 | record_page_type(pfn, type); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | static void vmi_check_page_type(u32 pfn, int type) |
| 353 | { |
| 354 | /* PAE can have multiple roots per page - skip checks */ |
| 355 | if (PTRS_PER_PMD > 1 && (type & VMI_PAGE_PDP)) |
| 356 | return; |
| 357 | |
| 358 | type &= ~(VMI_PAGE_ZEROED | VMI_PAGE_CLONE); |
| 359 | if (boot_allocations_applied) { |
| 360 | struct page *page = pfn_to_page(pfn); |
| 361 | BUG_ON((page->type ^ type) & VMI_PAGE_PAE); |
| 362 | BUG_ON(type == VMI_PAGE_NORMAL && page->type); |
| 363 | BUG_ON((type & page->type) == 0); |
| 364 | } |
| 365 | } |
| 366 | #else |
| 367 | #define vmi_set_page_type(p,t) do { } while (0) |
| 368 | #define vmi_check_page_type(p,t) do { } while (0) |
| 369 | #endif |
| 370 | |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 371 | #ifdef CONFIG_HIGHPTE |
| 372 | static void *vmi_kmap_atomic_pte(struct page *page, enum km_type type) |
Zachary Amsden | 9a1c13e | 2007-03-05 00:30:37 -0800 | [diff] [blame] | 373 | { |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 374 | void *va = kmap_atomic(page, type); |
| 375 | |
Zachary Amsden | 9a1c13e | 2007-03-05 00:30:37 -0800 | [diff] [blame] | 376 | /* |
| 377 | * Internally, the VMI ROM must map virtual addresses to physical |
| 378 | * addresses for processing MMU updates. By the time MMU updates |
| 379 | * are issued, this information is typically already lost. |
| 380 | * Fortunately, the VMI provides a cache of mapping slots for active |
| 381 | * page tables. |
| 382 | * |
| 383 | * We use slot zero for the linear mapping of physical memory, and |
| 384 | * in HIGHPTE kernels, slot 1 and 2 for KM_PTE0 and KM_PTE1. |
| 385 | * |
| 386 | * args: SLOT VA COUNT PFN |
| 387 | */ |
| 388 | BUG_ON(type != KM_PTE0 && type != KM_PTE1); |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 389 | vmi_ops.set_linear_mapping((type - KM_PTE0)+1, va, 1, page_to_pfn(page)); |
| 390 | |
| 391 | return va; |
Zachary Amsden | 9a1c13e | 2007-03-05 00:30:37 -0800 | [diff] [blame] | 392 | } |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 393 | #endif |
Zachary Amsden | 9a1c13e | 2007-03-05 00:30:37 -0800 | [diff] [blame] | 394 | |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 395 | static void vmi_allocate_pte(struct mm_struct *mm, u32 pfn) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 396 | { |
| 397 | vmi_set_page_type(pfn, VMI_PAGE_L1); |
| 398 | vmi_ops.allocate_page(pfn, VMI_PAGE_L1, 0, 0, 0); |
| 399 | } |
| 400 | |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 401 | static void vmi_allocate_pmd(struct mm_struct *mm, u32 pfn) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 402 | { |
| 403 | /* |
| 404 | * This call comes in very early, before mem_map is setup. |
| 405 | * It is called only for swapper_pg_dir, which already has |
| 406 | * data on it. |
| 407 | */ |
| 408 | vmi_set_page_type(pfn, VMI_PAGE_L2); |
| 409 | vmi_ops.allocate_page(pfn, VMI_PAGE_L2, 0, 0, 0); |
| 410 | } |
| 411 | |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 412 | static void vmi_allocate_pmd_clone(u32 pfn, u32 clonepfn, u32 start, u32 count) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 413 | { |
| 414 | vmi_set_page_type(pfn, VMI_PAGE_L2 | VMI_PAGE_CLONE); |
| 415 | vmi_check_page_type(clonepfn, VMI_PAGE_L2); |
| 416 | vmi_ops.allocate_page(pfn, VMI_PAGE_L2 | VMI_PAGE_CLONE, clonepfn, start, count); |
| 417 | } |
| 418 | |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 419 | static void vmi_release_pte(u32 pfn) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 420 | { |
| 421 | vmi_ops.release_page(pfn, VMI_PAGE_L1); |
| 422 | vmi_set_page_type(pfn, VMI_PAGE_NORMAL); |
| 423 | } |
| 424 | |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 425 | static void vmi_release_pmd(u32 pfn) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 426 | { |
| 427 | vmi_ops.release_page(pfn, VMI_PAGE_L2); |
| 428 | vmi_set_page_type(pfn, VMI_PAGE_NORMAL); |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | * Helper macros for MMU update flags. We can defer updates until a flush |
| 433 | * or page invalidation only if the update is to the current address space |
| 434 | * (otherwise, there is no flush). We must check against init_mm, since |
| 435 | * this could be a kernel update, which usually passes init_mm, although |
| 436 | * sometimes this check can be skipped if we know the particular function |
| 437 | * is only called on user mode PTEs. We could change the kernel to pass |
| 438 | * current->active_mm here, but in particular, I was unsure if changing |
| 439 | * mm/highmem.c to do this would still be correct on other architectures. |
| 440 | */ |
| 441 | #define is_current_as(mm, mustbeuser) ((mm) == current->active_mm || \ |
| 442 | (!mustbeuser && (mm) == &init_mm)) |
| 443 | #define vmi_flags_addr(mm, addr, level, user) \ |
| 444 | ((level) | (is_current_as(mm, user) ? \ |
| 445 | (VMI_PAGE_CURRENT_AS | ((addr) & VMI_PAGE_VA_MASK)) : 0)) |
| 446 | #define vmi_flags_addr_defer(mm, addr, level, user) \ |
| 447 | ((level) | (is_current_as(mm, user) ? \ |
| 448 | (VMI_PAGE_DEFER | VMI_PAGE_CURRENT_AS | ((addr) & VMI_PAGE_VA_MASK)) : 0)) |
| 449 | |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 450 | static void vmi_update_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 451 | { |
| 452 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); |
| 453 | vmi_ops.update_pte(ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); |
| 454 | } |
| 455 | |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 456 | static void vmi_update_pte_defer(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 457 | { |
| 458 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); |
| 459 | vmi_ops.update_pte(ptep, vmi_flags_addr_defer(mm, addr, VMI_PAGE_PT, 0)); |
| 460 | } |
| 461 | |
| 462 | static void vmi_set_pte(pte_t *ptep, pte_t pte) |
| 463 | { |
| 464 | /* XXX because of set_pmd_pte, this can be called on PT or PD layers */ |
| 465 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE | VMI_PAGE_PD); |
| 466 | vmi_ops.set_pte(pte, ptep, VMI_PAGE_PT); |
| 467 | } |
| 468 | |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 469 | static void vmi_set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 470 | { |
| 471 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); |
| 472 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); |
| 473 | } |
| 474 | |
| 475 | static void vmi_set_pmd(pmd_t *pmdp, pmd_t pmdval) |
| 476 | { |
| 477 | #ifdef CONFIG_X86_PAE |
Jeremy Fitzhardinge | e332870 | 2008-01-30 13:32:58 +0100 | [diff] [blame] | 478 | const pte_t pte = { .pte = pmdval.pmd }; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 479 | vmi_check_page_type(__pa(pmdp) >> PAGE_SHIFT, VMI_PAGE_PMD); |
| 480 | #else |
| 481 | const pte_t pte = { pmdval.pud.pgd.pgd }; |
| 482 | vmi_check_page_type(__pa(pmdp) >> PAGE_SHIFT, VMI_PAGE_PGD); |
| 483 | #endif |
| 484 | vmi_ops.set_pte(pte, (pte_t *)pmdp, VMI_PAGE_PD); |
| 485 | } |
| 486 | |
| 487 | #ifdef CONFIG_X86_PAE |
| 488 | |
| 489 | static void vmi_set_pte_atomic(pte_t *ptep, pte_t pteval) |
| 490 | { |
| 491 | /* |
| 492 | * XXX This is called from set_pmd_pte, but at both PT |
| 493 | * and PD layers so the VMI_PAGE_PT flag is wrong. But |
| 494 | * it is only called for large page mapping changes, |
| 495 | * the Xen backend, doesn't support large pages, and the |
| 496 | * ESX backend doesn't depend on the flag. |
| 497 | */ |
| 498 | set_64bit((unsigned long long *)ptep,pte_val(pteval)); |
| 499 | vmi_ops.update_pte(ptep, VMI_PAGE_PT); |
| 500 | } |
| 501 | |
| 502 | static void vmi_set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) |
| 503 | { |
| 504 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); |
| 505 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr_defer(mm, addr, VMI_PAGE_PT, 1)); |
| 506 | } |
| 507 | |
| 508 | static void vmi_set_pud(pud_t *pudp, pud_t pudval) |
| 509 | { |
| 510 | /* Um, eww */ |
Jeremy Fitzhardinge | e332870 | 2008-01-30 13:32:58 +0100 | [diff] [blame] | 511 | const pte_t pte = { .pte = pudval.pgd.pgd }; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 512 | vmi_check_page_type(__pa(pudp) >> PAGE_SHIFT, VMI_PAGE_PGD); |
| 513 | vmi_ops.set_pte(pte, (pte_t *)pudp, VMI_PAGE_PDP); |
| 514 | } |
| 515 | |
| 516 | static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
| 517 | { |
Jeremy Fitzhardinge | e332870 | 2008-01-30 13:32:58 +0100 | [diff] [blame] | 518 | const pte_t pte = { .pte = 0 }; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 519 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); |
| 520 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); |
| 521 | } |
| 522 | |
Adrian Bunk | 8eb68fa | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 523 | static void vmi_pmd_clear(pmd_t *pmd) |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 524 | { |
Jeremy Fitzhardinge | e332870 | 2008-01-30 13:32:58 +0100 | [diff] [blame] | 525 | const pte_t pte = { .pte = 0 }; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 526 | vmi_check_page_type(__pa(pmd) >> PAGE_SHIFT, VMI_PAGE_PMD); |
| 527 | vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD); |
| 528 | } |
| 529 | #endif |
| 530 | |
| 531 | #ifdef CONFIG_SMP |
Zachary Amsden | c6b36e9 | 2007-03-05 00:30:43 -0800 | [diff] [blame] | 532 | static void __devinit |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 533 | vmi_startup_ipi_hook(int phys_apicid, unsigned long start_eip, |
| 534 | unsigned long start_esp) |
| 535 | { |
Zachary Amsden | c6b36e9 | 2007-03-05 00:30:43 -0800 | [diff] [blame] | 536 | struct vmi_ap_state ap; |
| 537 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 538 | /* Default everything to zero. This is fine for most GPRs. */ |
| 539 | memset(&ap, 0, sizeof(struct vmi_ap_state)); |
| 540 | |
| 541 | ap.gdtr_limit = GDT_SIZE - 1; |
| 542 | ap.gdtr_base = (unsigned long) get_cpu_gdt_table(phys_apicid); |
| 543 | |
| 544 | ap.idtr_limit = IDT_ENTRIES * 8 - 1; |
| 545 | ap.idtr_base = (unsigned long) idt_table; |
| 546 | |
| 547 | ap.ldtr = 0; |
| 548 | |
| 549 | ap.cs = __KERNEL_CS; |
| 550 | ap.eip = (unsigned long) start_eip; |
| 551 | ap.ss = __KERNEL_DS; |
| 552 | ap.esp = (unsigned long) start_esp; |
| 553 | |
| 554 | ap.ds = __USER_DS; |
| 555 | ap.es = __USER_DS; |
Jeremy Fitzhardinge | 7c3576d | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 556 | ap.fs = __KERNEL_PERCPU; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 557 | ap.gs = 0; |
| 558 | |
| 559 | ap.eflags = 0; |
| 560 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 561 | #ifdef CONFIG_X86_PAE |
| 562 | /* efer should match BSP efer. */ |
| 563 | if (cpu_has_nx) { |
| 564 | unsigned l, h; |
| 565 | rdmsr(MSR_EFER, l, h); |
| 566 | ap.efer = (unsigned long long) h << 32 | l; |
| 567 | } |
| 568 | #endif |
| 569 | |
| 570 | ap.cr3 = __pa(swapper_pg_dir); |
| 571 | /* Protected mode, paging, AM, WP, NE, MP. */ |
| 572 | ap.cr0 = 0x80050023; |
| 573 | ap.cr4 = mmu_cr4_features; |
Zachary Amsden | c6b36e9 | 2007-03-05 00:30:43 -0800 | [diff] [blame] | 574 | vmi_ops.set_initial_ap_state((u32)&ap, phys_apicid); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 575 | } |
| 576 | #endif |
| 577 | |
Jeremy Fitzhardinge | 8965c1c | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 578 | static void vmi_enter_lazy_cpu(void) |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 579 | { |
Jeremy Fitzhardinge | 8965c1c | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 580 | paravirt_enter_lazy_cpu(); |
| 581 | vmi_ops.set_lazy_mode(2); |
| 582 | } |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 583 | |
Jeremy Fitzhardinge | 8965c1c | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 584 | static void vmi_enter_lazy_mmu(void) |
| 585 | { |
| 586 | paravirt_enter_lazy_mmu(); |
| 587 | vmi_ops.set_lazy_mode(1); |
| 588 | } |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 589 | |
Jeremy Fitzhardinge | 8965c1c | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 590 | static void vmi_leave_lazy(void) |
| 591 | { |
| 592 | paravirt_leave_lazy(paravirt_get_lazy_mode()); |
| 593 | vmi_ops.set_lazy_mode(0); |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 596 | static inline int __init check_vmi_rom(struct vrom_header *rom) |
| 597 | { |
| 598 | struct pci_header *pci; |
| 599 | struct pnp_header *pnp; |
| 600 | const char *manufacturer = "UNKNOWN"; |
| 601 | const char *product = "UNKNOWN"; |
| 602 | const char *license = "unspecified"; |
| 603 | |
| 604 | if (rom->rom_signature != 0xaa55) |
| 605 | return 0; |
| 606 | if (rom->vrom_signature != VMI_SIGNATURE) |
| 607 | return 0; |
| 608 | if (rom->api_version_maj != VMI_API_REV_MAJOR || |
| 609 | rom->api_version_min+1 < VMI_API_REV_MINOR+1) { |
| 610 | printk(KERN_WARNING "VMI: Found mismatched rom version %d.%d\n", |
| 611 | rom->api_version_maj, |
| 612 | rom->api_version_min); |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * Relying on the VMI_SIGNATURE field is not 100% safe, so check |
| 618 | * the PCI header and device type to make sure this is really a |
| 619 | * VMI device. |
| 620 | */ |
| 621 | if (!rom->pci_header_offs) { |
| 622 | printk(KERN_WARNING "VMI: ROM does not contain PCI header.\n"); |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | pci = (struct pci_header *)((char *)rom+rom->pci_header_offs); |
| 627 | if (pci->vendorID != PCI_VENDOR_ID_VMWARE || |
| 628 | pci->deviceID != PCI_DEVICE_ID_VMWARE_VMI) { |
| 629 | /* Allow it to run... anyways, but warn */ |
| 630 | printk(KERN_WARNING "VMI: ROM from unknown manufacturer\n"); |
| 631 | } |
| 632 | |
| 633 | if (rom->pnp_header_offs) { |
| 634 | pnp = (struct pnp_header *)((char *)rom+rom->pnp_header_offs); |
| 635 | if (pnp->manufacturer_offset) |
| 636 | manufacturer = (const char *)rom+pnp->manufacturer_offset; |
| 637 | if (pnp->product_offset) |
| 638 | product = (const char *)rom+pnp->product_offset; |
| 639 | } |
| 640 | |
| 641 | if (rom->license_offs) |
| 642 | license = (char *)rom+rom->license_offs; |
| 643 | |
| 644 | printk(KERN_INFO "VMI: Found %s %s, API version %d.%d, ROM version %d.%d\n", |
| 645 | manufacturer, product, |
| 646 | rom->api_version_maj, rom->api_version_min, |
| 647 | pci->rom_version_maj, pci->rom_version_min); |
| 648 | |
Andi Kleen | 302cf93 | 2007-03-16 21:07:36 +0100 | [diff] [blame] | 649 | /* Don't allow BSD/MIT here for now because we don't want to end up |
| 650 | with any binary only shim layers */ |
| 651 | if (strcmp(license, "GPL") && strcmp(license, "GPL v2")) { |
| 652 | printk(KERN_WARNING "VMI: Non GPL license `%s' found for ROM. Not used.\n", |
| 653 | license); |
| 654 | return 0; |
| 655 | } |
| 656 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 657 | return 1; |
| 658 | } |
| 659 | |
| 660 | /* |
| 661 | * Probe for the VMI option ROM |
| 662 | */ |
| 663 | static inline int __init probe_vmi_rom(void) |
| 664 | { |
| 665 | unsigned long base; |
| 666 | |
| 667 | /* VMI ROM is in option ROM area, check signature */ |
| 668 | for (base = 0xC0000; base < 0xE0000; base += 2048) { |
| 669 | struct vrom_header *romstart; |
| 670 | romstart = (struct vrom_header *)isa_bus_to_virt(base); |
| 671 | if (check_vmi_rom(romstart)) { |
| 672 | vmi_rom = romstart; |
| 673 | return 1; |
| 674 | } |
| 675 | } |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | /* |
| 680 | * VMI setup common to all processors |
| 681 | */ |
| 682 | void vmi_bringup(void) |
| 683 | { |
| 684 | /* We must establish the lowmem mapping for MMU ops to work */ |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 685 | if (vmi_ops.set_linear_mapping) |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 686 | vmi_ops.set_linear_mapping(0, (void *)__PAGE_OFFSET, max_low_pfn, 0); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /* |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 690 | * Return a pointer to a VMI function or NULL if unimplemented |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 691 | */ |
| 692 | static void *vmi_get_function(int vmicall) |
| 693 | { |
| 694 | u64 reloc; |
| 695 | const struct vmi_relocation_info *rel = (struct vmi_relocation_info *)&reloc; |
| 696 | reloc = call_vrom_long_func(vmi_rom, get_reloc, vmicall); |
| 697 | BUG_ON(rel->type == VMI_RELOCATION_JUMP_REL); |
| 698 | if (rel->type == VMI_RELOCATION_CALL_REL) |
| 699 | return (void *)rel->eip; |
| 700 | else |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 701 | return NULL; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /* |
| 705 | * Helper macro for making the VMI paravirt-ops fill code readable. |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 706 | * For unimplemented operations, fall back to default, unless nop |
| 707 | * is returned by the ROM. |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 708 | */ |
| 709 | #define para_fill(opname, vmicall) \ |
| 710 | do { \ |
| 711 | reloc = call_vrom_long_func(vmi_rom, get_reloc, \ |
| 712 | VMI_CALL_##vmicall); \ |
Zachary Amsden | 0492c37 | 2007-04-12 19:28:46 -0700 | [diff] [blame] | 713 | if (rel->type == VMI_RELOCATION_CALL_REL) \ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 714 | opname = (void *)rel->eip; \ |
Zachary Amsden | 0492c37 | 2007-04-12 19:28:46 -0700 | [diff] [blame] | 715 | else if (rel->type == VMI_RELOCATION_NOP) \ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 716 | opname = (void *)vmi_nop; \ |
Zachary Amsden | 0492c37 | 2007-04-12 19:28:46 -0700 | [diff] [blame] | 717 | else if (rel->type != VMI_RELOCATION_NONE) \ |
| 718 | printk(KERN_WARNING "VMI: Unknown relocation " \ |
| 719 | "type %d for " #vmicall"\n",\ |
| 720 | rel->type); \ |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 721 | } while (0) |
| 722 | |
| 723 | /* |
| 724 | * Helper macro for making the VMI paravirt-ops fill code readable. |
| 725 | * For cached operations which do not match the VMI ROM ABI and must |
| 726 | * go through a tranlation stub. Ignore NOPs, since it is not clear |
| 727 | * a NOP * VMI function corresponds to a NOP paravirt-op when the |
| 728 | * functions are not in 1-1 correspondence. |
| 729 | */ |
| 730 | #define para_wrap(opname, wrapper, cache, vmicall) \ |
| 731 | do { \ |
| 732 | reloc = call_vrom_long_func(vmi_rom, get_reloc, \ |
| 733 | VMI_CALL_##vmicall); \ |
| 734 | BUG_ON(rel->type == VMI_RELOCATION_JUMP_REL); \ |
| 735 | if (rel->type == VMI_RELOCATION_CALL_REL) { \ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 736 | opname = wrapper; \ |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 737 | vmi_ops.cache = (void *)rel->eip; \ |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 738 | } \ |
| 739 | } while (0) |
| 740 | |
| 741 | /* |
| 742 | * Activate the VMI interface and switch into paravirtualized mode |
| 743 | */ |
| 744 | static inline int __init activate_vmi(void) |
| 745 | { |
| 746 | short kernel_cs; |
| 747 | u64 reloc; |
| 748 | const struct vmi_relocation_info *rel = (struct vmi_relocation_info *)&reloc; |
| 749 | |
| 750 | if (call_vrom_func(vmi_rom, vmi_init) != 0) { |
| 751 | printk(KERN_ERR "VMI ROM failed to initialize!"); |
| 752 | return 0; |
| 753 | } |
| 754 | savesegment(cs, kernel_cs); |
| 755 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 756 | pv_info.paravirt_enabled = 1; |
| 757 | pv_info.kernel_rpl = kernel_cs & SEGMENT_RPL_MASK; |
| 758 | pv_info.name = "vmi"; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 759 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 760 | pv_init_ops.patch = vmi_patch; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 761 | |
| 762 | /* |
| 763 | * Many of these operations are ABI compatible with VMI. |
| 764 | * This means we can fill in the paravirt-ops with direct |
| 765 | * pointers into the VMI ROM. If the calling convention for |
| 766 | * these operations changes, this code needs to be updated. |
| 767 | * |
| 768 | * Exceptions |
| 769 | * CPUID paravirt-op uses pointers, not the native ISA |
| 770 | * halt has no VMI equivalent; all VMI halts are "safe" |
| 771 | * no MSR support yet - just trap and emulate. VMI uses the |
| 772 | * same ABI as the native ISA, but Linux wants exceptions |
| 773 | * from bogus MSR read / write handled |
| 774 | * rdpmc is not yet used in Linux |
| 775 | */ |
| 776 | |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 777 | /* CPUID is special, so very special it gets wrapped like a present */ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 778 | para_wrap(pv_cpu_ops.cpuid, vmi_cpuid, cpuid, CPUID); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 779 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 780 | para_fill(pv_cpu_ops.clts, CLTS); |
| 781 | para_fill(pv_cpu_ops.get_debugreg, GetDR); |
| 782 | para_fill(pv_cpu_ops.set_debugreg, SetDR); |
| 783 | para_fill(pv_cpu_ops.read_cr0, GetCR0); |
| 784 | para_fill(pv_mmu_ops.read_cr2, GetCR2); |
| 785 | para_fill(pv_mmu_ops.read_cr3, GetCR3); |
| 786 | para_fill(pv_cpu_ops.read_cr4, GetCR4); |
| 787 | para_fill(pv_cpu_ops.write_cr0, SetCR0); |
| 788 | para_fill(pv_mmu_ops.write_cr2, SetCR2); |
| 789 | para_fill(pv_mmu_ops.write_cr3, SetCR3); |
| 790 | para_fill(pv_cpu_ops.write_cr4, SetCR4); |
| 791 | para_fill(pv_irq_ops.save_fl, GetInterruptMask); |
| 792 | para_fill(pv_irq_ops.restore_fl, SetInterruptMask); |
| 793 | para_fill(pv_irq_ops.irq_disable, DisableInterrupts); |
| 794 | para_fill(pv_irq_ops.irq_enable, EnableInterrupts); |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 795 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 796 | para_fill(pv_cpu_ops.wbinvd, WBINVD); |
| 797 | para_fill(pv_cpu_ops.read_tsc, RDTSC); |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 798 | |
| 799 | /* The following we emulate with trap and emulate for now */ |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 800 | /* paravirt_ops.read_msr = vmi_rdmsr */ |
| 801 | /* paravirt_ops.write_msr = vmi_wrmsr */ |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 802 | /* paravirt_ops.rdpmc = vmi_rdpmc */ |
| 803 | |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 804 | /* TR interface doesn't pass TR value, wrap */ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 805 | para_wrap(pv_cpu_ops.load_tr_desc, vmi_set_tr, set_tr, SetTR); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 806 | |
| 807 | /* LDT is special, too */ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 808 | para_wrap(pv_cpu_ops.set_ldt, vmi_set_ldt, _set_ldt, SetLDT); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 809 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 810 | para_fill(pv_cpu_ops.load_gdt, SetGDT); |
| 811 | para_fill(pv_cpu_ops.load_idt, SetIDT); |
| 812 | para_fill(pv_cpu_ops.store_gdt, GetGDT); |
| 813 | para_fill(pv_cpu_ops.store_idt, GetIDT); |
| 814 | para_fill(pv_cpu_ops.store_tr, GetTR); |
| 815 | pv_cpu_ops.load_tls = vmi_load_tls; |
Glauber de Oliveira Costa | 75b8bb3 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 816 | para_wrap(pv_cpu_ops.write_ldt_entry, vmi_write_ldt_entry, |
| 817 | write_ldt_entry, WriteLDTEntry); |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 818 | para_wrap(pv_cpu_ops.write_gdt_entry, vmi_write_gdt_entry, |
| 819 | write_gdt_entry, WriteGDTEntry); |
Glauber de Oliveira Costa | 8d94734 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 820 | para_wrap(pv_cpu_ops.write_idt_entry, vmi_write_idt_entry, |
| 821 | write_idt_entry, WriteIDTEntry); |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 822 | para_wrap(pv_cpu_ops.load_sp0, vmi_load_sp0, set_kernel_stack, UpdateKernelStack); |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 823 | para_fill(pv_cpu_ops.set_iopl_mask, SetIOPLMask); |
| 824 | para_fill(pv_cpu_ops.io_delay, IODelay); |
Jeremy Fitzhardinge | 8965c1c | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 825 | |
| 826 | para_wrap(pv_cpu_ops.lazy_mode.enter, vmi_enter_lazy_cpu, |
| 827 | set_lazy_mode, SetLazyMode); |
| 828 | para_wrap(pv_cpu_ops.lazy_mode.leave, vmi_leave_lazy, |
| 829 | set_lazy_mode, SetLazyMode); |
| 830 | |
| 831 | para_wrap(pv_mmu_ops.lazy_mode.enter, vmi_enter_lazy_mmu, |
| 832 | set_lazy_mode, SetLazyMode); |
| 833 | para_wrap(pv_mmu_ops.lazy_mode.leave, vmi_leave_lazy, |
| 834 | set_lazy_mode, SetLazyMode); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 835 | |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 836 | /* user and kernel flush are just handled with different flags to FlushTLB */ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 837 | para_wrap(pv_mmu_ops.flush_tlb_user, vmi_flush_tlb_user, _flush_tlb, FlushTLB); |
| 838 | para_wrap(pv_mmu_ops.flush_tlb_kernel, vmi_flush_tlb_kernel, _flush_tlb, FlushTLB); |
| 839 | para_fill(pv_mmu_ops.flush_tlb_single, InvalPage); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 840 | |
| 841 | /* |
| 842 | * Until a standard flag format can be agreed on, we need to |
| 843 | * implement these as wrappers in Linux. Get the VMI ROM |
| 844 | * function pointers for the two backend calls. |
| 845 | */ |
| 846 | #ifdef CONFIG_X86_PAE |
| 847 | vmi_ops.set_pte = vmi_get_function(VMI_CALL_SetPxELong); |
| 848 | vmi_ops.update_pte = vmi_get_function(VMI_CALL_UpdatePxELong); |
| 849 | #else |
| 850 | vmi_ops.set_pte = vmi_get_function(VMI_CALL_SetPxE); |
| 851 | vmi_ops.update_pte = vmi_get_function(VMI_CALL_UpdatePxE); |
| 852 | #endif |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 853 | |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 854 | if (vmi_ops.set_pte) { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 855 | pv_mmu_ops.set_pte = vmi_set_pte; |
| 856 | pv_mmu_ops.set_pte_at = vmi_set_pte_at; |
| 857 | pv_mmu_ops.set_pmd = vmi_set_pmd; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 858 | #ifdef CONFIG_X86_PAE |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 859 | pv_mmu_ops.set_pte_atomic = vmi_set_pte_atomic; |
| 860 | pv_mmu_ops.set_pte_present = vmi_set_pte_present; |
| 861 | pv_mmu_ops.set_pud = vmi_set_pud; |
| 862 | pv_mmu_ops.pte_clear = vmi_pte_clear; |
| 863 | pv_mmu_ops.pmd_clear = vmi_pmd_clear; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 864 | #endif |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | if (vmi_ops.update_pte) { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 868 | pv_mmu_ops.pte_update = vmi_update_pte; |
| 869 | pv_mmu_ops.pte_update_defer = vmi_update_pte_defer; |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | vmi_ops.allocate_page = vmi_get_function(VMI_CALL_AllocatePage); |
| 873 | if (vmi_ops.allocate_page) { |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 874 | pv_mmu_ops.alloc_pte = vmi_allocate_pte; |
| 875 | pv_mmu_ops.alloc_pmd = vmi_allocate_pmd; |
| 876 | pv_mmu_ops.alloc_pmd_clone = vmi_allocate_pmd_clone; |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | vmi_ops.release_page = vmi_get_function(VMI_CALL_ReleasePage); |
| 880 | if (vmi_ops.release_page) { |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 881 | pv_mmu_ops.release_pte = vmi_release_pte; |
| 882 | pv_mmu_ops.release_pmd = vmi_release_pmd; |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 883 | } |
Zachary Amsden | eeef9c6 | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 884 | |
| 885 | /* Set linear is needed in all cases */ |
| 886 | vmi_ops.set_linear_mapping = vmi_get_function(VMI_CALL_SetLinearMapping); |
| 887 | #ifdef CONFIG_HIGHPTE |
| 888 | if (vmi_ops.set_linear_mapping) |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 889 | pv_mmu_ops.kmap_atomic_pte = vmi_kmap_atomic_pte; |
Jeremy Fitzhardinge | a27fe80 | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 890 | #endif |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 891 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 892 | /* |
| 893 | * These MUST always be patched. Don't support indirect jumps |
| 894 | * through these operations, as the VMI interface may use either |
| 895 | * a jump or a call to get to these operations, depending on |
| 896 | * the backend. They are performance critical anyway, so requiring |
| 897 | * a patch is not a big problem. |
| 898 | */ |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 899 | pv_cpu_ops.irq_enable_syscall_ret = (void *)0xfeedbab0; |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 900 | pv_cpu_ops.iret = (void *)0xbadbab0; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 901 | |
| 902 | #ifdef CONFIG_SMP |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 903 | para_wrap(pv_apic_ops.startup_ipi_hook, vmi_startup_ipi_hook, set_initial_ap_state, SetInitialAPState); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 904 | #endif |
| 905 | |
| 906 | #ifdef CONFIG_X86_LOCAL_APIC |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 907 | para_fill(pv_apic_ops.apic_read, APICRead); |
| 908 | para_fill(pv_apic_ops.apic_write, APICWrite); |
| 909 | para_fill(pv_apic_ops.apic_write_atomic, APICWrite); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 910 | #endif |
| 911 | |
| 912 | /* |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 913 | * Check for VMI timer functionality by probing for a cycle frequency method |
| 914 | */ |
| 915 | reloc = call_vrom_long_func(vmi_rom, get_reloc, VMI_CALL_GetCycleFrequency); |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 916 | if (!disable_vmi_timer && rel->type != VMI_RELOCATION_NONE) { |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 917 | vmi_timer_ops.get_cycle_frequency = (void *)rel->eip; |
| 918 | vmi_timer_ops.get_cycle_counter = |
| 919 | vmi_get_function(VMI_CALL_GetCycleCounter); |
| 920 | vmi_timer_ops.get_wallclock = |
| 921 | vmi_get_function(VMI_CALL_GetWallclockTime); |
| 922 | vmi_timer_ops.wallclock_updated = |
| 923 | vmi_get_function(VMI_CALL_WallclockUpdated); |
| 924 | vmi_timer_ops.set_alarm = vmi_get_function(VMI_CALL_SetAlarm); |
| 925 | vmi_timer_ops.cancel_alarm = |
| 926 | vmi_get_function(VMI_CALL_CancelAlarm); |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 927 | pv_time_ops.time_init = vmi_time_init; |
| 928 | pv_time_ops.get_wallclock = vmi_get_wallclock; |
| 929 | pv_time_ops.set_wallclock = vmi_set_wallclock; |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 930 | #ifdef CONFIG_X86_LOCAL_APIC |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 931 | pv_apic_ops.setup_boot_clock = vmi_time_bsp_init; |
| 932 | pv_apic_ops.setup_secondary_clock = vmi_time_ap_init; |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 933 | #endif |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 934 | pv_time_ops.sched_clock = vmi_sched_clock; |
| 935 | pv_time_ops.get_cpu_khz = vmi_cpu_khz; |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 936 | |
| 937 | /* We have true wallclock functions; disable CMOS clock sync */ |
| 938 | no_sync_cmos_clock = 1; |
| 939 | } else { |
| 940 | disable_noidle = 1; |
| 941 | disable_vmi_timer = 1; |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 942 | } |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 943 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 944 | para_fill(pv_irq_ops.safe_halt, Halt); |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 945 | |
| 946 | /* |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 947 | * Alternative instruction rewriting doesn't happen soon enough |
| 948 | * to convert VMI_IRET to a call instead of a jump; so we have |
| 949 | * to do this before IRQs get reenabled. Fortunately, it is |
| 950 | * idempotent. |
| 951 | */ |
Jeremy Fitzhardinge | 441d40d | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 952 | apply_paravirt(__parainstructions, __parainstructions_end); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 953 | |
| 954 | vmi_bringup(); |
| 955 | |
| 956 | return 1; |
| 957 | } |
| 958 | |
| 959 | #undef para_fill |
| 960 | |
| 961 | void __init vmi_init(void) |
| 962 | { |
| 963 | unsigned long flags; |
| 964 | |
| 965 | if (!vmi_rom) |
| 966 | probe_vmi_rom(); |
| 967 | else |
| 968 | check_vmi_rom(vmi_rom); |
| 969 | |
| 970 | /* In case probing for or validating the ROM failed, basil */ |
| 971 | if (!vmi_rom) |
| 972 | return; |
| 973 | |
| 974 | reserve_top_address(-vmi_rom->virtual_top); |
| 975 | |
| 976 | local_irq_save(flags); |
| 977 | activate_vmi(); |
Zachary Amsden | 7507ba3 | 2007-03-05 00:30:34 -0800 | [diff] [blame] | 978 | |
| 979 | #ifdef CONFIG_X86_IO_APIC |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 980 | /* This is virtual hardware; timer routing is wired correctly */ |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 981 | no_timer_check = 1; |
| 982 | #endif |
| 983 | local_irq_restore(flags & X86_EFLAGS_IF); |
| 984 | } |
| 985 | |
| 986 | static int __init parse_vmi(char *arg) |
| 987 | { |
| 988 | if (!arg) |
| 989 | return -EINVAL; |
| 990 | |
Zachary Amsden | eda08b1 | 2007-03-05 00:30:38 -0800 | [diff] [blame] | 991 | if (!strcmp(arg, "disable_pge")) { |
Jeremy Fitzhardinge | 53756d3 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 992 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_PGE); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 993 | disable_pge = 1; |
| 994 | } else if (!strcmp(arg, "disable_pse")) { |
Jeremy Fitzhardinge | 53756d3 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 995 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_PSE); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 996 | disable_pse = 1; |
| 997 | } else if (!strcmp(arg, "disable_sep")) { |
Jeremy Fitzhardinge | 53756d3 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 998 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_SEP); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 999 | disable_sep = 1; |
| 1000 | } else if (!strcmp(arg, "disable_tsc")) { |
Jeremy Fitzhardinge | 53756d3 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 1001 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1002 | disable_tsc = 1; |
| 1003 | } else if (!strcmp(arg, "disable_mtrr")) { |
Jeremy Fitzhardinge | 53756d3 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 1004 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_MTRR); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1005 | disable_mtrr = 1; |
Zachary Amsden | 772205f | 2007-03-05 00:30:41 -0800 | [diff] [blame] | 1006 | } else if (!strcmp(arg, "disable_timer")) { |
| 1007 | disable_vmi_timer = 1; |
| 1008 | disable_noidle = 1; |
Zachary Amsden | 7507ba3 | 2007-03-05 00:30:34 -0800 | [diff] [blame] | 1009 | } else if (!strcmp(arg, "disable_noidle")) |
| 1010 | disable_noidle = 1; |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | early_param("vmi", parse_vmi); |