Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License, version 2, as |
| 4 | * published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public License |
| 12 | * along with this program; if not, write to the Free Software |
| 13 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 14 | * |
| 15 | * Copyright IBM Corp. 2007 |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 16 | * Copyright 2010-2011 Freescale Semiconductor, Inc. |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 17 | * |
| 18 | * Authors: Hollis Blanchard <hollisb@us.ibm.com> |
| 19 | * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 20 | * Scott Wood <scottwood@freescale.com> |
| 21 | * Varun Sethi <varun.sethi@freescale.com> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/err.h> |
| 26 | #include <linux/kvm_host.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/gfp.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/vmalloc.h> |
| 30 | #include <linux/fs.h> |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 31 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 32 | #include <asm/cputable.h> |
| 33 | #include <asm/uaccess.h> |
| 34 | #include <asm/kvm_ppc.h> |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 35 | #include <asm/cacheflush.h> |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 36 | #include <asm/dbell.h> |
| 37 | #include <asm/hw_irq.h> |
| 38 | #include <asm/irq.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 39 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 40 | #include "timing.h" |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 41 | #include "booke.h" |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 42 | |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 43 | unsigned long kvmppc_booke_handlers; |
| 44 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 45 | #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM |
| 46 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU |
| 47 | |
| 48 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 49 | { "mmio", VCPU_STAT(mmio_exits) }, |
| 50 | { "dcr", VCPU_STAT(dcr_exits) }, |
| 51 | { "sig", VCPU_STAT(signal_exits) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 52 | { "itlb_r", VCPU_STAT(itlb_real_miss_exits) }, |
| 53 | { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) }, |
| 54 | { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) }, |
| 55 | { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) }, |
| 56 | { "sysc", VCPU_STAT(syscall_exits) }, |
| 57 | { "isi", VCPU_STAT(isi_exits) }, |
| 58 | { "dsi", VCPU_STAT(dsi_exits) }, |
| 59 | { "inst_emu", VCPU_STAT(emulated_inst_exits) }, |
| 60 | { "dec", VCPU_STAT(dec_exits) }, |
| 61 | { "ext_intr", VCPU_STAT(ext_intr_exits) }, |
Hollis Blanchard | 45c5eb6 | 2008-04-25 17:55:49 -0500 | [diff] [blame] | 62 | { "halt_wakeup", VCPU_STAT(halt_wakeup) }, |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 63 | { "doorbell", VCPU_STAT(dbell_exits) }, |
| 64 | { "guest doorbell", VCPU_STAT(gdbell_exits) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 65 | { NULL } |
| 66 | }; |
| 67 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 68 | /* TODO: use vcpu_printf() */ |
| 69 | void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu) |
| 70 | { |
| 71 | int i; |
| 72 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 73 | printk("pc: %08lx msr: %08llx\n", vcpu->arch.pc, vcpu->arch.shared->msr); |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 74 | printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 75 | printk("srr0: %08llx srr1: %08llx\n", vcpu->arch.shared->srr0, |
| 76 | vcpu->arch.shared->srr1); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 77 | |
| 78 | printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions); |
| 79 | |
| 80 | for (i = 0; i < 32; i += 4) { |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 81 | printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i, |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 82 | kvmppc_get_gpr(vcpu, i), |
| 83 | kvmppc_get_gpr(vcpu, i+1), |
| 84 | kvmppc_get_gpr(vcpu, i+2), |
| 85 | kvmppc_get_gpr(vcpu, i+3)); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 89 | #ifdef CONFIG_SPE |
| 90 | void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu) |
| 91 | { |
| 92 | preempt_disable(); |
| 93 | enable_kernel_spe(); |
| 94 | kvmppc_save_guest_spe(vcpu); |
| 95 | vcpu->arch.shadow_msr &= ~MSR_SPE; |
| 96 | preempt_enable(); |
| 97 | } |
| 98 | |
| 99 | static void kvmppc_vcpu_enable_spe(struct kvm_vcpu *vcpu) |
| 100 | { |
| 101 | preempt_disable(); |
| 102 | enable_kernel_spe(); |
| 103 | kvmppc_load_guest_spe(vcpu); |
| 104 | vcpu->arch.shadow_msr |= MSR_SPE; |
| 105 | preempt_enable(); |
| 106 | } |
| 107 | |
| 108 | static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu) |
| 109 | { |
| 110 | if (vcpu->arch.shared->msr & MSR_SPE) { |
| 111 | if (!(vcpu->arch.shadow_msr & MSR_SPE)) |
| 112 | kvmppc_vcpu_enable_spe(vcpu); |
| 113 | } else if (vcpu->arch.shadow_msr & MSR_SPE) { |
| 114 | kvmppc_vcpu_disable_spe(vcpu); |
| 115 | } |
| 116 | } |
| 117 | #else |
| 118 | static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu) |
| 119 | { |
| 120 | } |
| 121 | #endif |
| 122 | |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 123 | /* |
| 124 | * Helper function for "full" MSR writes. No need to call this if only |
| 125 | * EE/CE/ME/DE/RI are changing. |
| 126 | */ |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 127 | void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) |
| 128 | { |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 129 | u32 old_msr = vcpu->arch.shared->msr; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 130 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 131 | #ifdef CONFIG_KVM_BOOKE_HV |
| 132 | new_msr |= MSR_GS; |
| 133 | #endif |
| 134 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 135 | vcpu->arch.shared->msr = new_msr; |
| 136 | |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 137 | kvmppc_mmu_msr_notify(vcpu, old_msr); |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 138 | kvmppc_vcpu_sync_spe(vcpu); |
| 139 | } |
| 140 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 141 | static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, |
| 142 | unsigned int priority) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 143 | { |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 144 | set_bit(priority, &vcpu->arch.pending_exceptions); |
| 145 | } |
| 146 | |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 147 | static void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, |
| 148 | ulong dear_flags, ulong esr_flags) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 149 | { |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 150 | vcpu->arch.queued_dear = dear_flags; |
| 151 | vcpu->arch.queued_esr = esr_flags; |
| 152 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS); |
| 153 | } |
| 154 | |
| 155 | static void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, |
| 156 | ulong dear_flags, ulong esr_flags) |
| 157 | { |
| 158 | vcpu->arch.queued_dear = dear_flags; |
| 159 | vcpu->arch.queued_esr = esr_flags; |
| 160 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE); |
| 161 | } |
| 162 | |
| 163 | static void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, |
| 164 | ulong esr_flags) |
| 165 | { |
| 166 | vcpu->arch.queued_esr = esr_flags; |
| 167 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE); |
| 168 | } |
| 169 | |
| 170 | void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags) |
| 171 | { |
| 172 | vcpu->arch.queued_esr = esr_flags; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 173 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu) |
| 177 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 178 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu) |
| 182 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 183 | return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 184 | } |
| 185 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 186 | void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu) |
| 187 | { |
| 188 | clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
| 189 | } |
| 190 | |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 191 | void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 192 | struct kvm_interrupt *irq) |
| 193 | { |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 194 | unsigned int prio = BOOKE_IRQPRIO_EXTERNAL; |
| 195 | |
| 196 | if (irq->irq == KVM_INTERRUPT_SET_LEVEL) |
| 197 | prio = BOOKE_IRQPRIO_EXTERNAL_LEVEL; |
| 198 | |
| 199 | kvmppc_booke_queue_irqprio(vcpu, prio); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 200 | } |
| 201 | |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 202 | void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu, |
| 203 | struct kvm_interrupt *irq) |
| 204 | { |
| 205 | clear_bit(BOOKE_IRQPRIO_EXTERNAL, &vcpu->arch.pending_exceptions); |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 206 | clear_bit(BOOKE_IRQPRIO_EXTERNAL_LEVEL, &vcpu->arch.pending_exceptions); |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 207 | } |
| 208 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 209 | static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 210 | { |
| 211 | #ifdef CONFIG_KVM_BOOKE_HV |
| 212 | mtspr(SPRN_GSRR0, srr0); |
| 213 | mtspr(SPRN_GSRR1, srr1); |
| 214 | #else |
| 215 | vcpu->arch.shared->srr0 = srr0; |
| 216 | vcpu->arch.shared->srr1 = srr1; |
| 217 | #endif |
| 218 | } |
| 219 | |
| 220 | static void set_guest_csrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 221 | { |
| 222 | vcpu->arch.csrr0 = srr0; |
| 223 | vcpu->arch.csrr1 = srr1; |
| 224 | } |
| 225 | |
| 226 | static void set_guest_dsrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 227 | { |
| 228 | if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC)) { |
| 229 | vcpu->arch.dsrr0 = srr0; |
| 230 | vcpu->arch.dsrr1 = srr1; |
| 231 | } else { |
| 232 | set_guest_csrr(vcpu, srr0, srr1); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static void set_guest_mcsrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 237 | { |
| 238 | vcpu->arch.mcsrr0 = srr0; |
| 239 | vcpu->arch.mcsrr1 = srr1; |
| 240 | } |
| 241 | |
| 242 | static unsigned long get_guest_dear(struct kvm_vcpu *vcpu) |
| 243 | { |
| 244 | #ifdef CONFIG_KVM_BOOKE_HV |
| 245 | return mfspr(SPRN_GDEAR); |
| 246 | #else |
| 247 | return vcpu->arch.shared->dar; |
| 248 | #endif |
| 249 | } |
| 250 | |
| 251 | static void set_guest_dear(struct kvm_vcpu *vcpu, unsigned long dear) |
| 252 | { |
| 253 | #ifdef CONFIG_KVM_BOOKE_HV |
| 254 | mtspr(SPRN_GDEAR, dear); |
| 255 | #else |
| 256 | vcpu->arch.shared->dar = dear; |
| 257 | #endif |
| 258 | } |
| 259 | |
| 260 | static unsigned long get_guest_esr(struct kvm_vcpu *vcpu) |
| 261 | { |
| 262 | #ifdef CONFIG_KVM_BOOKE_HV |
| 263 | return mfspr(SPRN_GESR); |
| 264 | #else |
| 265 | return vcpu->arch.shared->esr; |
| 266 | #endif |
| 267 | } |
| 268 | |
| 269 | static void set_guest_esr(struct kvm_vcpu *vcpu, u32 esr) |
| 270 | { |
| 271 | #ifdef CONFIG_KVM_BOOKE_HV |
| 272 | mtspr(SPRN_GESR, esr); |
| 273 | #else |
| 274 | vcpu->arch.shared->esr = esr; |
| 275 | #endif |
| 276 | } |
| 277 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 278 | /* Deliver the interrupt of the corresponding priority, if possible. */ |
| 279 | static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, |
| 280 | unsigned int priority) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 281 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 282 | int allowed = 0; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 283 | ulong msr_mask = 0; |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 284 | bool update_esr = false, update_dear = false; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 285 | ulong crit_raw = vcpu->arch.shared->critical; |
| 286 | ulong crit_r1 = kvmppc_get_gpr(vcpu, 1); |
| 287 | bool crit; |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 288 | bool keep_irq = false; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 289 | enum int_class int_class; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 290 | |
| 291 | /* Truncate crit indicators in 32 bit mode */ |
| 292 | if (!(vcpu->arch.shared->msr & MSR_SF)) { |
| 293 | crit_raw &= 0xffffffff; |
| 294 | crit_r1 &= 0xffffffff; |
| 295 | } |
| 296 | |
| 297 | /* Critical section when crit == r1 */ |
| 298 | crit = (crit_raw == crit_r1); |
| 299 | /* ... and we're in supervisor mode */ |
| 300 | crit = crit && !(vcpu->arch.shared->msr & MSR_PR); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 301 | |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 302 | if (priority == BOOKE_IRQPRIO_EXTERNAL_LEVEL) { |
| 303 | priority = BOOKE_IRQPRIO_EXTERNAL; |
| 304 | keep_irq = true; |
| 305 | } |
| 306 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 307 | switch (priority) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 308 | case BOOKE_IRQPRIO_DTLB_MISS: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 309 | case BOOKE_IRQPRIO_DATA_STORAGE: |
| 310 | update_dear = true; |
| 311 | /* fall through */ |
| 312 | case BOOKE_IRQPRIO_INST_STORAGE: |
| 313 | case BOOKE_IRQPRIO_PROGRAM: |
| 314 | update_esr = true; |
| 315 | /* fall through */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 316 | case BOOKE_IRQPRIO_ITLB_MISS: |
| 317 | case BOOKE_IRQPRIO_SYSCALL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 318 | case BOOKE_IRQPRIO_FP_UNAVAIL: |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 319 | case BOOKE_IRQPRIO_SPE_UNAVAIL: |
| 320 | case BOOKE_IRQPRIO_SPE_FP_DATA: |
| 321 | case BOOKE_IRQPRIO_SPE_FP_ROUND: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 322 | case BOOKE_IRQPRIO_AP_UNAVAIL: |
| 323 | case BOOKE_IRQPRIO_ALIGNMENT: |
| 324 | allowed = 1; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 325 | msr_mask = MSR_CE | MSR_ME | MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 326 | int_class = INT_CLASS_NONCRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 327 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 328 | case BOOKE_IRQPRIO_CRITICAL: |
Alexander Graf | 4ab9691 | 2012-02-15 13:28:48 +0000 | [diff] [blame] | 329 | case BOOKE_IRQPRIO_DBELL_CRIT: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 330 | allowed = vcpu->arch.shared->msr & MSR_CE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 331 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 332 | msr_mask = MSR_ME; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 333 | int_class = INT_CLASS_CRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 334 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 335 | case BOOKE_IRQPRIO_MACHINE_CHECK: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 336 | allowed = vcpu->arch.shared->msr & MSR_ME; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 337 | allowed = allowed && !crit; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 338 | int_class = INT_CLASS_MC; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 339 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 340 | case BOOKE_IRQPRIO_DECREMENTER: |
| 341 | case BOOKE_IRQPRIO_FIT: |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 342 | keep_irq = true; |
| 343 | /* fall through */ |
| 344 | case BOOKE_IRQPRIO_EXTERNAL: |
Alexander Graf | 4ab9691 | 2012-02-15 13:28:48 +0000 | [diff] [blame] | 345 | case BOOKE_IRQPRIO_DBELL: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 346 | allowed = vcpu->arch.shared->msr & MSR_EE; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 347 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 348 | msr_mask = MSR_CE | MSR_ME | MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 349 | int_class = INT_CLASS_NONCRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 350 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 351 | case BOOKE_IRQPRIO_DEBUG: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 352 | allowed = vcpu->arch.shared->msr & MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 353 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 354 | msr_mask = MSR_ME; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 355 | int_class = INT_CLASS_CRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 356 | break; |
| 357 | } |
| 358 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 359 | if (allowed) { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 360 | switch (int_class) { |
| 361 | case INT_CLASS_NONCRIT: |
| 362 | set_guest_srr(vcpu, vcpu->arch.pc, |
| 363 | vcpu->arch.shared->msr); |
| 364 | break; |
| 365 | case INT_CLASS_CRIT: |
| 366 | set_guest_csrr(vcpu, vcpu->arch.pc, |
| 367 | vcpu->arch.shared->msr); |
| 368 | break; |
| 369 | case INT_CLASS_DBG: |
| 370 | set_guest_dsrr(vcpu, vcpu->arch.pc, |
| 371 | vcpu->arch.shared->msr); |
| 372 | break; |
| 373 | case INT_CLASS_MC: |
| 374 | set_guest_mcsrr(vcpu, vcpu->arch.pc, |
| 375 | vcpu->arch.shared->msr); |
| 376 | break; |
| 377 | } |
| 378 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 379 | vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority]; |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 380 | if (update_esr == true) |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 381 | set_guest_esr(vcpu, vcpu->arch.queued_esr); |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 382 | if (update_dear == true) |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 383 | set_guest_dear(vcpu, vcpu->arch.queued_dear); |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 384 | kvmppc_set_msr(vcpu, vcpu->arch.shared->msr & msr_mask); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 385 | |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 386 | if (!keep_irq) |
| 387 | clear_bit(priority, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 388 | } |
| 389 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 390 | #ifdef CONFIG_KVM_BOOKE_HV |
| 391 | /* |
| 392 | * If an interrupt is pending but masked, raise a guest doorbell |
| 393 | * so that we are notified when the guest enables the relevant |
| 394 | * MSR bit. |
| 395 | */ |
| 396 | if (vcpu->arch.pending_exceptions & BOOKE_IRQMASK_EE) |
| 397 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_NONCRIT); |
| 398 | if (vcpu->arch.pending_exceptions & BOOKE_IRQMASK_CE) |
| 399 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_CRIT); |
| 400 | if (vcpu->arch.pending_exceptions & BOOKE_IRQPRIO_MACHINE_CHECK) |
| 401 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_MC); |
| 402 | #endif |
| 403 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 404 | return allowed; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 405 | } |
| 406 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 407 | static void update_timer_ints(struct kvm_vcpu *vcpu) |
| 408 | { |
| 409 | if ((vcpu->arch.tcr & TCR_DIE) && (vcpu->arch.tsr & TSR_DIS)) |
| 410 | kvmppc_core_queue_dec(vcpu); |
| 411 | else |
| 412 | kvmppc_core_dequeue_dec(vcpu); |
| 413 | } |
| 414 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 415 | static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 416 | { |
| 417 | unsigned long *pending = &vcpu->arch.pending_exceptions; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 418 | unsigned int priority; |
| 419 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 420 | if (vcpu->requests) { |
| 421 | if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) { |
| 422 | smp_mb(); |
| 423 | update_timer_ints(vcpu); |
| 424 | } |
| 425 | } |
| 426 | |
Hollis Blanchard | 9ab8084 | 2008-11-05 09:36:22 -0600 | [diff] [blame] | 427 | priority = __ffs(*pending); |
Alexander Graf | 8b3a00f | 2012-02-16 14:12:46 +0000 | [diff] [blame^] | 428 | while (priority < BOOKE_IRQPRIO_MAX) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 429 | if (kvmppc_booke_irqprio_deliver(vcpu, priority)) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 430 | break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 431 | |
| 432 | priority = find_next_bit(pending, |
| 433 | BITS_PER_BYTE * sizeof(*pending), |
| 434 | priority + 1); |
| 435 | } |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame] | 436 | |
| 437 | /* Tell the guest about our interrupt status */ |
Scott Wood | 29ac26e | 2011-11-08 18:23:27 -0600 | [diff] [blame] | 438 | vcpu->arch.shared->int_pending = !!*pending; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 439 | } |
| 440 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 441 | /* Check pending exceptions and deliver one, if possible. */ |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 442 | int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu) |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 443 | { |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 444 | int r = 0; |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 445 | WARN_ON_ONCE(!irqs_disabled()); |
| 446 | |
| 447 | kvmppc_core_check_exceptions(vcpu); |
| 448 | |
| 449 | if (vcpu->arch.shared->msr & MSR_WE) { |
| 450 | local_irq_enable(); |
| 451 | kvm_vcpu_block(vcpu); |
| 452 | local_irq_disable(); |
| 453 | |
| 454 | kvmppc_set_exit_type(vcpu, EMULATED_MTMSRWE_EXITS); |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 455 | r = 1; |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 456 | }; |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 457 | |
| 458 | return r; |
| 459 | } |
| 460 | |
| 461 | /* |
| 462 | * Common checks before entering the guest world. Call with interrupts |
| 463 | * disabled. |
| 464 | * |
| 465 | * returns !0 if a signal is pending and check_signal is true |
| 466 | */ |
| 467 | static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu, bool check_signal) |
| 468 | { |
| 469 | int r = 0; |
| 470 | |
| 471 | WARN_ON_ONCE(!irqs_disabled()); |
| 472 | while (true) { |
| 473 | if (need_resched()) { |
| 474 | local_irq_enable(); |
| 475 | cond_resched(); |
| 476 | local_irq_disable(); |
| 477 | continue; |
| 478 | } |
| 479 | |
| 480 | if (check_signal && signal_pending(current)) { |
| 481 | r = 1; |
| 482 | break; |
| 483 | } |
| 484 | |
| 485 | if (kvmppc_core_prepare_to_enter(vcpu)) { |
| 486 | /* interrupts got enabled in between, so we |
| 487 | are back at square 1 */ |
| 488 | continue; |
| 489 | } |
| 490 | |
| 491 | break; |
| 492 | } |
| 493 | |
| 494 | return r; |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 495 | } |
| 496 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 497 | int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 498 | { |
| 499 | int ret; |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 500 | #ifdef CONFIG_PPC_FPU |
| 501 | unsigned int fpscr; |
| 502 | int fpexc_mode; |
| 503 | u64 fpr[32]; |
| 504 | #endif |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 505 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 506 | if (!vcpu->arch.sane) { |
| 507 | kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR; |
| 508 | return -EINVAL; |
| 509 | } |
| 510 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 511 | local_irq_disable(); |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 512 | if (kvmppc_prepare_to_enter(vcpu, true)) { |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 513 | kvm_run->exit_reason = KVM_EXIT_INTR; |
| 514 | ret = -EINTR; |
| 515 | goto out; |
| 516 | } |
| 517 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 518 | kvm_guest_enter(); |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 519 | |
| 520 | #ifdef CONFIG_PPC_FPU |
| 521 | /* Save userspace FPU state in stack */ |
| 522 | enable_kernel_fp(); |
| 523 | memcpy(fpr, current->thread.fpr, sizeof(current->thread.fpr)); |
| 524 | fpscr = current->thread.fpscr.val; |
| 525 | fpexc_mode = current->thread.fpexc_mode; |
| 526 | |
| 527 | /* Restore guest FPU state to thread */ |
| 528 | memcpy(current->thread.fpr, vcpu->arch.fpr, sizeof(vcpu->arch.fpr)); |
| 529 | current->thread.fpscr.val = vcpu->arch.fpscr; |
| 530 | |
| 531 | /* |
| 532 | * Since we can't trap on MSR_FP in GS-mode, we consider the guest |
| 533 | * as always using the FPU. Kernel usage of FP (via |
| 534 | * enable_kernel_fp()) in this thread must not occur while |
| 535 | * vcpu->fpu_active is set. |
| 536 | */ |
| 537 | vcpu->fpu_active = 1; |
| 538 | |
| 539 | kvmppc_load_guest_fp(vcpu); |
| 540 | #endif |
| 541 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 542 | ret = __kvmppc_vcpu_run(kvm_run, vcpu); |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 543 | |
| 544 | #ifdef CONFIG_PPC_FPU |
| 545 | kvmppc_save_guest_fp(vcpu); |
| 546 | |
| 547 | vcpu->fpu_active = 0; |
| 548 | |
| 549 | /* Save guest FPU state from thread */ |
| 550 | memcpy(vcpu->arch.fpr, current->thread.fpr, sizeof(vcpu->arch.fpr)); |
| 551 | vcpu->arch.fpscr = current->thread.fpscr.val; |
| 552 | |
| 553 | /* Restore userspace FPU state from stack */ |
| 554 | memcpy(current->thread.fpr, fpr, sizeof(current->thread.fpr)); |
| 555 | current->thread.fpscr.val = fpscr; |
| 556 | current->thread.fpexc_mode = fpexc_mode; |
| 557 | #endif |
| 558 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 559 | kvm_guest_exit(); |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 560 | |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 561 | out: |
| 562 | local_irq_enable(); |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 563 | return ret; |
| 564 | } |
| 565 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 566 | static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) |
| 567 | { |
| 568 | enum emulation_result er; |
| 569 | |
| 570 | er = kvmppc_emulate_instruction(run, vcpu); |
| 571 | switch (er) { |
| 572 | case EMULATE_DONE: |
| 573 | /* don't overwrite subtypes, just account kvm_stats */ |
| 574 | kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS); |
| 575 | /* Future optimization: only reload non-volatiles if |
| 576 | * they were actually modified by emulation. */ |
| 577 | return RESUME_GUEST_NV; |
| 578 | |
| 579 | case EMULATE_DO_DCR: |
| 580 | run->exit_reason = KVM_EXIT_DCR; |
| 581 | return RESUME_HOST; |
| 582 | |
| 583 | case EMULATE_FAIL: |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 584 | printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n", |
| 585 | __func__, vcpu->arch.pc, vcpu->arch.last_inst); |
| 586 | /* For debugging, encode the failing instruction and |
| 587 | * report it to userspace. */ |
| 588 | run->hw.hardware_exit_reason = ~0ULL << 32; |
| 589 | run->hw.hardware_exit_reason |= vcpu->arch.last_inst; |
Alexander Graf | d1ff549 | 2012-02-16 13:24:03 +0000 | [diff] [blame] | 590 | kvmppc_core_queue_program(vcpu, ESR_PIL); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 591 | return RESUME_HOST; |
| 592 | |
| 593 | default: |
| 594 | BUG(); |
| 595 | } |
| 596 | } |
| 597 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 598 | /** |
| 599 | * kvmppc_handle_exit |
| 600 | * |
| 601 | * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV) |
| 602 | */ |
| 603 | int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 604 | unsigned int exit_nr) |
| 605 | { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 606 | int r = RESUME_HOST; |
| 607 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 608 | /* update before a new last_exit_type is rewritten */ |
| 609 | kvmppc_update_timing_stats(vcpu); |
| 610 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 611 | switch (exit_nr) { |
| 612 | case BOOKE_INTERRUPT_EXTERNAL: |
| 613 | do_IRQ(current->thread.regs); |
| 614 | break; |
| 615 | |
| 616 | case BOOKE_INTERRUPT_DECREMENTER: |
| 617 | timer_interrupt(current->thread.regs); |
| 618 | break; |
| 619 | |
| 620 | #if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3E_64) |
| 621 | case BOOKE_INTERRUPT_DOORBELL: |
| 622 | doorbell_exception(current->thread.regs); |
| 623 | break; |
| 624 | #endif |
| 625 | case BOOKE_INTERRUPT_MACHINE_CHECK: |
| 626 | /* FIXME */ |
| 627 | break; |
| 628 | } |
| 629 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 630 | local_irq_enable(); |
| 631 | |
| 632 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 633 | run->ready_for_interrupt_injection = 1; |
| 634 | |
| 635 | switch (exit_nr) { |
| 636 | case BOOKE_INTERRUPT_MACHINE_CHECK: |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 637 | r = RESUME_GUEST; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 638 | break; |
| 639 | |
| 640 | case BOOKE_INTERRUPT_EXTERNAL: |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 641 | kvmppc_account_exit(vcpu, EXT_INTR_EXITS); |
Hollis Blanchard | 1b6766c | 2008-11-05 09:36:21 -0600 | [diff] [blame] | 642 | r = RESUME_GUEST; |
| 643 | break; |
| 644 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 645 | case BOOKE_INTERRUPT_DECREMENTER: |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 646 | kvmppc_account_exit(vcpu, DEC_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 647 | r = RESUME_GUEST; |
| 648 | break; |
| 649 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 650 | case BOOKE_INTERRUPT_DOORBELL: |
| 651 | kvmppc_account_exit(vcpu, DBELL_EXITS); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 652 | r = RESUME_GUEST; |
| 653 | break; |
| 654 | |
| 655 | case BOOKE_INTERRUPT_GUEST_DBELL_CRIT: |
| 656 | kvmppc_account_exit(vcpu, GDBELL_EXITS); |
| 657 | |
| 658 | /* |
| 659 | * We are here because there is a pending guest interrupt |
| 660 | * which could not be delivered as MSR_CE or MSR_ME was not |
| 661 | * set. Once we break from here we will retry delivery. |
| 662 | */ |
| 663 | r = RESUME_GUEST; |
| 664 | break; |
| 665 | |
| 666 | case BOOKE_INTERRUPT_GUEST_DBELL: |
| 667 | kvmppc_account_exit(vcpu, GDBELL_EXITS); |
| 668 | |
| 669 | /* |
| 670 | * We are here because there is a pending guest interrupt |
| 671 | * which could not be delivered as MSR_EE was not set. Once |
| 672 | * we break from here we will retry delivery. |
| 673 | */ |
| 674 | r = RESUME_GUEST; |
| 675 | break; |
| 676 | |
| 677 | case BOOKE_INTERRUPT_HV_PRIV: |
| 678 | r = emulation_exit(run, vcpu); |
| 679 | break; |
| 680 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 681 | case BOOKE_INTERRUPT_PROGRAM: |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 682 | if (vcpu->arch.shared->msr & (MSR_PR | MSR_GS)) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 683 | /* Program traps generated by user-level software must be handled |
| 684 | * by the guest kernel. */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 685 | kvmppc_core_queue_program(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 686 | r = RESUME_GUEST; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 687 | kvmppc_account_exit(vcpu, USR_PR_INST); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 688 | break; |
| 689 | } |
| 690 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 691 | r = emulation_exit(run, vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 692 | break; |
| 693 | |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 694 | case BOOKE_INTERRUPT_FP_UNAVAIL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 695 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 696 | kvmppc_account_exit(vcpu, FP_UNAVAIL); |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 697 | r = RESUME_GUEST; |
| 698 | break; |
| 699 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 700 | #ifdef CONFIG_SPE |
| 701 | case BOOKE_INTERRUPT_SPE_UNAVAIL: { |
| 702 | if (vcpu->arch.shared->msr & MSR_SPE) |
| 703 | kvmppc_vcpu_enable_spe(vcpu); |
| 704 | else |
| 705 | kvmppc_booke_queue_irqprio(vcpu, |
| 706 | BOOKE_IRQPRIO_SPE_UNAVAIL); |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 707 | r = RESUME_GUEST; |
| 708 | break; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 709 | } |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 710 | |
| 711 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 712 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA); |
| 713 | r = RESUME_GUEST; |
| 714 | break; |
| 715 | |
| 716 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 717 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND); |
| 718 | r = RESUME_GUEST; |
| 719 | break; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 720 | #else |
| 721 | case BOOKE_INTERRUPT_SPE_UNAVAIL: |
| 722 | /* |
| 723 | * Guest wants SPE, but host kernel doesn't support it. Send |
| 724 | * an "unimplemented operation" program check to the guest. |
| 725 | */ |
| 726 | kvmppc_core_queue_program(vcpu, ESR_PUO | ESR_SPV); |
| 727 | r = RESUME_GUEST; |
| 728 | break; |
| 729 | |
| 730 | /* |
| 731 | * These really should never happen without CONFIG_SPE, |
| 732 | * as we should never enable the real MSR[SPE] in the guest. |
| 733 | */ |
| 734 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 735 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 736 | printk(KERN_CRIT "%s: unexpected SPE interrupt %u at %08lx\n", |
| 737 | __func__, exit_nr, vcpu->arch.pc); |
| 738 | run->hw.hardware_exit_reason = exit_nr; |
| 739 | r = RESUME_HOST; |
| 740 | break; |
| 741 | #endif |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 742 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 743 | case BOOKE_INTERRUPT_DATA_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 744 | kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear, |
| 745 | vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 746 | kvmppc_account_exit(vcpu, DSI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 747 | r = RESUME_GUEST; |
| 748 | break; |
| 749 | |
| 750 | case BOOKE_INTERRUPT_INST_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 751 | kvmppc_core_queue_inst_storage(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 752 | kvmppc_account_exit(vcpu, ISI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 753 | r = RESUME_GUEST; |
| 754 | break; |
| 755 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 756 | #ifdef CONFIG_KVM_BOOKE_HV |
| 757 | case BOOKE_INTERRUPT_HV_SYSCALL: |
| 758 | if (!(vcpu->arch.shared->msr & MSR_PR)) { |
| 759 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 760 | } else { |
| 761 | /* |
| 762 | * hcall from guest userspace -- send privileged |
| 763 | * instruction program check. |
| 764 | */ |
| 765 | kvmppc_core_queue_program(vcpu, ESR_PPR); |
| 766 | } |
| 767 | |
| 768 | r = RESUME_GUEST; |
| 769 | break; |
| 770 | #else |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 771 | case BOOKE_INTERRUPT_SYSCALL: |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 772 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 773 | (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) { |
| 774 | /* KVM PV hypercalls */ |
| 775 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 776 | r = RESUME_GUEST; |
| 777 | } else { |
| 778 | /* Guest syscalls */ |
| 779 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL); |
| 780 | } |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 781 | kvmppc_account_exit(vcpu, SYSCALL_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 782 | r = RESUME_GUEST; |
| 783 | break; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 784 | #endif |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 785 | |
| 786 | case BOOKE_INTERRUPT_DTLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 787 | unsigned long eaddr = vcpu->arch.fault_dear; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 788 | int gtlb_index; |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 789 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 790 | gfn_t gfn; |
| 791 | |
Alexander Graf | bf7ca4b | 2012-02-15 23:40:00 +0000 | [diff] [blame] | 792 | #ifdef CONFIG_KVM_E500V2 |
Scott Wood | a4cd8b2 | 2011-06-14 18:34:41 -0500 | [diff] [blame] | 793 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 794 | (eaddr & PAGE_MASK) == vcpu->arch.magic_page_ea) { |
| 795 | kvmppc_map_magic(vcpu); |
| 796 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
| 797 | r = RESUME_GUEST; |
| 798 | |
| 799 | break; |
| 800 | } |
| 801 | #endif |
| 802 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 803 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 804 | gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 805 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 806 | /* The guest didn't have a mapping for it. */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 807 | kvmppc_core_queue_dtlb_miss(vcpu, |
| 808 | vcpu->arch.fault_dear, |
| 809 | vcpu->arch.fault_esr); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 810 | kvmppc_mmu_dtlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 811 | kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 812 | r = RESUME_GUEST; |
| 813 | break; |
| 814 | } |
| 815 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 816 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 817 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 818 | |
| 819 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 820 | /* The guest TLB had a mapping, but the shadow TLB |
| 821 | * didn't, and it is RAM. This could be because: |
| 822 | * a) the entry is mapping the host kernel, or |
| 823 | * b) the guest used a large mapping which we're faking |
| 824 | * Either way, we need to satisfy the fault without |
| 825 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 826 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 827 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 828 | r = RESUME_GUEST; |
| 829 | } else { |
| 830 | /* Guest has mapped and accessed a page which is not |
| 831 | * actually RAM. */ |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 832 | vcpu->arch.paddr_accessed = gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 833 | r = kvmppc_emulate_mmio(run, vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 834 | kvmppc_account_exit(vcpu, MMIO_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | break; |
| 838 | } |
| 839 | |
| 840 | case BOOKE_INTERRUPT_ITLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 841 | unsigned long eaddr = vcpu->arch.pc; |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 842 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 843 | gfn_t gfn; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 844 | int gtlb_index; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 845 | |
| 846 | r = RESUME_GUEST; |
| 847 | |
| 848 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 849 | gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 850 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 851 | /* The guest didn't have a mapping for it. */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 852 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 853 | kvmppc_mmu_itlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 854 | kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 855 | break; |
| 856 | } |
| 857 | |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 858 | kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 859 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 860 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 861 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 862 | |
| 863 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 864 | /* The guest TLB had a mapping, but the shadow TLB |
| 865 | * didn't. This could be because: |
| 866 | * a) the entry is mapping the host kernel, or |
| 867 | * b) the guest used a large mapping which we're faking |
| 868 | * Either way, we need to satisfy the fault without |
| 869 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 870 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 871 | } else { |
| 872 | /* Guest mapped and leaped at non-RAM! */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 873 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | break; |
| 877 | } |
| 878 | |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 879 | case BOOKE_INTERRUPT_DEBUG: { |
| 880 | u32 dbsr; |
| 881 | |
| 882 | vcpu->arch.pc = mfspr(SPRN_CSRR0); |
| 883 | |
| 884 | /* clear IAC events in DBSR register */ |
| 885 | dbsr = mfspr(SPRN_DBSR); |
| 886 | dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4; |
| 887 | mtspr(SPRN_DBSR, dbsr); |
| 888 | |
| 889 | run->exit_reason = KVM_EXIT_DEBUG; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 890 | kvmppc_account_exit(vcpu, DEBUG_EXITS); |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 891 | r = RESUME_HOST; |
| 892 | break; |
| 893 | } |
| 894 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 895 | default: |
| 896 | printk(KERN_EMERG "exit_nr %d\n", exit_nr); |
| 897 | BUG(); |
| 898 | } |
| 899 | |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 900 | /* |
| 901 | * To avoid clobbering exit_reason, only check for signals if we |
| 902 | * aren't already exiting to userspace for some other reason. |
| 903 | */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 904 | local_irq_disable(); |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 905 | if (kvmppc_prepare_to_enter(vcpu, !(r & RESUME_HOST))) { |
| 906 | run->exit_reason = KVM_EXIT_INTR; |
| 907 | r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV); |
| 908 | kvmppc_account_exit(vcpu, SIGNAL_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | return r; |
| 912 | } |
| 913 | |
| 914 | /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */ |
| 915 | int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) |
| 916 | { |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 917 | int i; |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 918 | int r; |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 919 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 920 | vcpu->arch.pc = 0; |
Scott Wood | b590497 | 2011-11-08 18:23:30 -0600 | [diff] [blame] | 921 | vcpu->arch.shared->pir = vcpu->vcpu_id; |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 922 | kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */ |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 923 | kvmppc_set_msr(vcpu, 0); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 924 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 925 | #ifndef CONFIG_KVM_BOOKE_HV |
| 926 | vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS; |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 927 | vcpu->arch.shadow_pid = 1; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 928 | vcpu->arch.shared->msr = 0; |
| 929 | #endif |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 930 | |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 931 | /* Eye-catching numbers so we know if the guest takes an interrupt |
| 932 | * before it's programmed its own IVPR/IVORs. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 933 | vcpu->arch.ivpr = 0x55550000; |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 934 | for (i = 0; i < BOOKE_IRQPRIO_MAX; i++) |
| 935 | vcpu->arch.ivor[i] = 0x7700 | i * 4; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 936 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 937 | kvmppc_init_timing_stats(vcpu); |
| 938 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 939 | r = kvmppc_core_vcpu_setup(vcpu); |
| 940 | kvmppc_sanity_check(vcpu); |
| 941 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 945 | { |
| 946 | int i; |
| 947 | |
| 948 | regs->pc = vcpu->arch.pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 949 | regs->cr = kvmppc_get_cr(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 950 | regs->ctr = vcpu->arch.ctr; |
| 951 | regs->lr = vcpu->arch.lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 952 | regs->xer = kvmppc_get_xer(vcpu); |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 953 | regs->msr = vcpu->arch.shared->msr; |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 954 | regs->srr0 = vcpu->arch.shared->srr0; |
| 955 | regs->srr1 = vcpu->arch.shared->srr1; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 956 | regs->pid = vcpu->arch.pid; |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 957 | regs->sprg0 = vcpu->arch.shared->sprg0; |
| 958 | regs->sprg1 = vcpu->arch.shared->sprg1; |
| 959 | regs->sprg2 = vcpu->arch.shared->sprg2; |
| 960 | regs->sprg3 = vcpu->arch.shared->sprg3; |
Scott Wood | b590497 | 2011-11-08 18:23:30 -0600 | [diff] [blame] | 961 | regs->sprg4 = vcpu->arch.shared->sprg4; |
| 962 | regs->sprg5 = vcpu->arch.shared->sprg5; |
| 963 | regs->sprg6 = vcpu->arch.shared->sprg6; |
| 964 | regs->sprg7 = vcpu->arch.shared->sprg7; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 965 | |
| 966 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 967 | regs->gpr[i] = kvmppc_get_gpr(vcpu, i); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 973 | { |
| 974 | int i; |
| 975 | |
| 976 | vcpu->arch.pc = regs->pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 977 | kvmppc_set_cr(vcpu, regs->cr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 978 | vcpu->arch.ctr = regs->ctr; |
| 979 | vcpu->arch.lr = regs->lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 980 | kvmppc_set_xer(vcpu, regs->xer); |
Hollis Blanchard | b8fd68a | 2008-11-05 09:36:20 -0600 | [diff] [blame] | 981 | kvmppc_set_msr(vcpu, regs->msr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 982 | vcpu->arch.shared->srr0 = regs->srr0; |
| 983 | vcpu->arch.shared->srr1 = regs->srr1; |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 984 | kvmppc_set_pid(vcpu, regs->pid); |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 985 | vcpu->arch.shared->sprg0 = regs->sprg0; |
| 986 | vcpu->arch.shared->sprg1 = regs->sprg1; |
| 987 | vcpu->arch.shared->sprg2 = regs->sprg2; |
| 988 | vcpu->arch.shared->sprg3 = regs->sprg3; |
Scott Wood | b590497 | 2011-11-08 18:23:30 -0600 | [diff] [blame] | 989 | vcpu->arch.shared->sprg4 = regs->sprg4; |
| 990 | vcpu->arch.shared->sprg5 = regs->sprg5; |
| 991 | vcpu->arch.shared->sprg6 = regs->sprg6; |
| 992 | vcpu->arch.shared->sprg7 = regs->sprg7; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 993 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 994 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
| 995 | kvmppc_set_gpr(vcpu, i, regs->gpr[i]); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 996 | |
| 997 | return 0; |
| 998 | } |
| 999 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1000 | static void get_sregs_base(struct kvm_vcpu *vcpu, |
| 1001 | struct kvm_sregs *sregs) |
| 1002 | { |
| 1003 | u64 tb = get_tb(); |
| 1004 | |
| 1005 | sregs->u.e.features |= KVM_SREGS_E_BASE; |
| 1006 | |
| 1007 | sregs->u.e.csrr0 = vcpu->arch.csrr0; |
| 1008 | sregs->u.e.csrr1 = vcpu->arch.csrr1; |
| 1009 | sregs->u.e.mcsr = vcpu->arch.mcsr; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1010 | sregs->u.e.esr = get_guest_esr(vcpu); |
| 1011 | sregs->u.e.dear = get_guest_dear(vcpu); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1012 | sregs->u.e.tsr = vcpu->arch.tsr; |
| 1013 | sregs->u.e.tcr = vcpu->arch.tcr; |
| 1014 | sregs->u.e.dec = kvmppc_get_dec(vcpu, tb); |
| 1015 | sregs->u.e.tb = tb; |
| 1016 | sregs->u.e.vrsave = vcpu->arch.vrsave; |
| 1017 | } |
| 1018 | |
| 1019 | static int set_sregs_base(struct kvm_vcpu *vcpu, |
| 1020 | struct kvm_sregs *sregs) |
| 1021 | { |
| 1022 | if (!(sregs->u.e.features & KVM_SREGS_E_BASE)) |
| 1023 | return 0; |
| 1024 | |
| 1025 | vcpu->arch.csrr0 = sregs->u.e.csrr0; |
| 1026 | vcpu->arch.csrr1 = sregs->u.e.csrr1; |
| 1027 | vcpu->arch.mcsr = sregs->u.e.mcsr; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1028 | set_guest_esr(vcpu, sregs->u.e.esr); |
| 1029 | set_guest_dear(vcpu, sregs->u.e.dear); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1030 | vcpu->arch.vrsave = sregs->u.e.vrsave; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1031 | kvmppc_set_tcr(vcpu, sregs->u.e.tcr); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1032 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1033 | if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_DEC) { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1034 | vcpu->arch.dec = sregs->u.e.dec; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1035 | kvmppc_emulate_dec(vcpu); |
| 1036 | } |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1037 | |
| 1038 | if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_TSR) { |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1039 | vcpu->arch.tsr = sregs->u.e.tsr; |
| 1040 | update_timer_ints(vcpu); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | static void get_sregs_arch206(struct kvm_vcpu *vcpu, |
| 1047 | struct kvm_sregs *sregs) |
| 1048 | { |
| 1049 | sregs->u.e.features |= KVM_SREGS_E_ARCH206; |
| 1050 | |
Scott Wood | 841741f | 2011-09-02 17:39:37 -0500 | [diff] [blame] | 1051 | sregs->u.e.pir = vcpu->vcpu_id; |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1052 | sregs->u.e.mcsrr0 = vcpu->arch.mcsrr0; |
| 1053 | sregs->u.e.mcsrr1 = vcpu->arch.mcsrr1; |
| 1054 | sregs->u.e.decar = vcpu->arch.decar; |
| 1055 | sregs->u.e.ivpr = vcpu->arch.ivpr; |
| 1056 | } |
| 1057 | |
| 1058 | static int set_sregs_arch206(struct kvm_vcpu *vcpu, |
| 1059 | struct kvm_sregs *sregs) |
| 1060 | { |
| 1061 | if (!(sregs->u.e.features & KVM_SREGS_E_ARCH206)) |
| 1062 | return 0; |
| 1063 | |
Scott Wood | 841741f | 2011-09-02 17:39:37 -0500 | [diff] [blame] | 1064 | if (sregs->u.e.pir != vcpu->vcpu_id) |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1065 | return -EINVAL; |
| 1066 | |
| 1067 | vcpu->arch.mcsrr0 = sregs->u.e.mcsrr0; |
| 1068 | vcpu->arch.mcsrr1 = sregs->u.e.mcsrr1; |
| 1069 | vcpu->arch.decar = sregs->u.e.decar; |
| 1070 | vcpu->arch.ivpr = sregs->u.e.ivpr; |
| 1071 | |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) |
| 1076 | { |
| 1077 | sregs->u.e.features |= KVM_SREGS_E_IVOR; |
| 1078 | |
| 1079 | sregs->u.e.ivor_low[0] = vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL]; |
| 1080 | sregs->u.e.ivor_low[1] = vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK]; |
| 1081 | sregs->u.e.ivor_low[2] = vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE]; |
| 1082 | sregs->u.e.ivor_low[3] = vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE]; |
| 1083 | sregs->u.e.ivor_low[4] = vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL]; |
| 1084 | sregs->u.e.ivor_low[5] = vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT]; |
| 1085 | sregs->u.e.ivor_low[6] = vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM]; |
| 1086 | sregs->u.e.ivor_low[7] = vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL]; |
| 1087 | sregs->u.e.ivor_low[8] = vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL]; |
| 1088 | sregs->u.e.ivor_low[9] = vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL]; |
| 1089 | sregs->u.e.ivor_low[10] = vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER]; |
| 1090 | sregs->u.e.ivor_low[11] = vcpu->arch.ivor[BOOKE_IRQPRIO_FIT]; |
| 1091 | sregs->u.e.ivor_low[12] = vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG]; |
| 1092 | sregs->u.e.ivor_low[13] = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS]; |
| 1093 | sregs->u.e.ivor_low[14] = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS]; |
| 1094 | sregs->u.e.ivor_low[15] = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]; |
| 1095 | } |
| 1096 | |
| 1097 | int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) |
| 1098 | { |
| 1099 | if (!(sregs->u.e.features & KVM_SREGS_E_IVOR)) |
| 1100 | return 0; |
| 1101 | |
| 1102 | vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL] = sregs->u.e.ivor_low[0]; |
| 1103 | vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK] = sregs->u.e.ivor_low[1]; |
| 1104 | vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE] = sregs->u.e.ivor_low[2]; |
| 1105 | vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE] = sregs->u.e.ivor_low[3]; |
| 1106 | vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL] = sregs->u.e.ivor_low[4]; |
| 1107 | vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT] = sregs->u.e.ivor_low[5]; |
| 1108 | vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM] = sregs->u.e.ivor_low[6]; |
| 1109 | vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL] = sregs->u.e.ivor_low[7]; |
| 1110 | vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL] = sregs->u.e.ivor_low[8]; |
| 1111 | vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL] = sregs->u.e.ivor_low[9]; |
| 1112 | vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER] = sregs->u.e.ivor_low[10]; |
| 1113 | vcpu->arch.ivor[BOOKE_IRQPRIO_FIT] = sregs->u.e.ivor_low[11]; |
| 1114 | vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG] = sregs->u.e.ivor_low[12]; |
| 1115 | vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS] = sregs->u.e.ivor_low[13]; |
| 1116 | vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS] = sregs->u.e.ivor_low[14]; |
| 1117 | vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = sregs->u.e.ivor_low[15]; |
| 1118 | |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1122 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 1123 | struct kvm_sregs *sregs) |
| 1124 | { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1125 | sregs->pvr = vcpu->arch.pvr; |
| 1126 | |
| 1127 | get_sregs_base(vcpu, sregs); |
| 1128 | get_sregs_arch206(vcpu, sregs); |
| 1129 | kvmppc_core_get_sregs(vcpu, sregs); |
| 1130 | return 0; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 1134 | struct kvm_sregs *sregs) |
| 1135 | { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1136 | int ret; |
| 1137 | |
| 1138 | if (vcpu->arch.pvr != sregs->pvr) |
| 1139 | return -EINVAL; |
| 1140 | |
| 1141 | ret = set_sregs_base(vcpu, sregs); |
| 1142 | if (ret < 0) |
| 1143 | return ret; |
| 1144 | |
| 1145 | ret = set_sregs_arch206(vcpu, sregs); |
| 1146 | if (ret < 0) |
| 1147 | return ret; |
| 1148 | |
| 1149 | return kvmppc_core_set_sregs(vcpu, sregs); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1150 | } |
| 1151 | |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1152 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
| 1153 | { |
| 1154 | return -EINVAL; |
| 1155 | } |
| 1156 | |
| 1157 | int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
| 1158 | { |
| 1159 | return -EINVAL; |
| 1160 | } |
| 1161 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1162 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 1163 | { |
| 1164 | return -ENOTSUPP; |
| 1165 | } |
| 1166 | |
| 1167 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 1168 | { |
| 1169 | return -ENOTSUPP; |
| 1170 | } |
| 1171 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1172 | int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, |
| 1173 | struct kvm_translation *tr) |
| 1174 | { |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1175 | int r; |
| 1176 | |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1177 | r = kvmppc_core_vcpu_translate(vcpu, tr); |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1178 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1179 | } |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1180 | |
Alexander Graf | 4e75575 | 2009-10-30 05:47:01 +0000 | [diff] [blame] | 1181 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) |
| 1182 | { |
| 1183 | return -ENOTSUPP; |
| 1184 | } |
| 1185 | |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 1186 | int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
| 1187 | struct kvm_userspace_memory_region *mem) |
| 1188 | { |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | void kvmppc_core_commit_memory_region(struct kvm *kvm, |
| 1193 | struct kvm_userspace_memory_region *mem) |
| 1194 | { |
| 1195 | } |
| 1196 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1197 | void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr) |
| 1198 | { |
| 1199 | vcpu->arch.tcr = new_tcr; |
| 1200 | update_timer_ints(vcpu); |
| 1201 | } |
| 1202 | |
| 1203 | void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits) |
| 1204 | { |
| 1205 | set_bits(tsr_bits, &vcpu->arch.tsr); |
| 1206 | smp_wmb(); |
| 1207 | kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu); |
| 1208 | kvm_vcpu_kick(vcpu); |
| 1209 | } |
| 1210 | |
| 1211 | void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits) |
| 1212 | { |
| 1213 | clear_bits(tsr_bits, &vcpu->arch.tsr); |
| 1214 | update_timer_ints(vcpu); |
| 1215 | } |
| 1216 | |
| 1217 | void kvmppc_decrementer_func(unsigned long data) |
| 1218 | { |
| 1219 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; |
| 1220 | |
| 1221 | kvmppc_set_tsr_bits(vcpu, TSR_DIS); |
| 1222 | } |
| 1223 | |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 1224 | void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
| 1225 | { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1226 | current->thread.kvm_vcpu = vcpu; |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu) |
| 1230 | { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1231 | current->thread.kvm_vcpu = NULL; |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Stephen Rothwell | 2986b8c | 2009-06-02 11:46:14 +1000 | [diff] [blame] | 1234 | int __init kvmppc_booke_init(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1235 | { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1236 | #ifndef CONFIG_KVM_BOOKE_HV |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1237 | unsigned long ivor[16]; |
| 1238 | unsigned long max_ivor = 0; |
| 1239 | int i; |
| 1240 | |
| 1241 | /* We install our own exception handlers by hijacking IVPR. IVPR must |
| 1242 | * be 16-bit aligned, so we need a 64KB allocation. */ |
| 1243 | kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 1244 | VCPU_SIZE_ORDER); |
| 1245 | if (!kvmppc_booke_handlers) |
| 1246 | return -ENOMEM; |
| 1247 | |
| 1248 | /* XXX make sure our handlers are smaller than Linux's */ |
| 1249 | |
| 1250 | /* Copy our interrupt handlers to match host IVORs. That way we don't |
| 1251 | * have to swap the IVORs on every guest/host transition. */ |
| 1252 | ivor[0] = mfspr(SPRN_IVOR0); |
| 1253 | ivor[1] = mfspr(SPRN_IVOR1); |
| 1254 | ivor[2] = mfspr(SPRN_IVOR2); |
| 1255 | ivor[3] = mfspr(SPRN_IVOR3); |
| 1256 | ivor[4] = mfspr(SPRN_IVOR4); |
| 1257 | ivor[5] = mfspr(SPRN_IVOR5); |
| 1258 | ivor[6] = mfspr(SPRN_IVOR6); |
| 1259 | ivor[7] = mfspr(SPRN_IVOR7); |
| 1260 | ivor[8] = mfspr(SPRN_IVOR8); |
| 1261 | ivor[9] = mfspr(SPRN_IVOR9); |
| 1262 | ivor[10] = mfspr(SPRN_IVOR10); |
| 1263 | ivor[11] = mfspr(SPRN_IVOR11); |
| 1264 | ivor[12] = mfspr(SPRN_IVOR12); |
| 1265 | ivor[13] = mfspr(SPRN_IVOR13); |
| 1266 | ivor[14] = mfspr(SPRN_IVOR14); |
| 1267 | ivor[15] = mfspr(SPRN_IVOR15); |
| 1268 | |
| 1269 | for (i = 0; i < 16; i++) { |
| 1270 | if (ivor[i] > max_ivor) |
| 1271 | max_ivor = ivor[i]; |
| 1272 | |
| 1273 | memcpy((void *)kvmppc_booke_handlers + ivor[i], |
| 1274 | kvmppc_handlers_start + i * kvmppc_handler_len, |
| 1275 | kvmppc_handler_len); |
| 1276 | } |
| 1277 | flush_icache_range(kvmppc_booke_handlers, |
| 1278 | kvmppc_booke_handlers + max_ivor + kvmppc_handler_len); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1279 | #endif /* !BOOKE_HV */ |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 1280 | return 0; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1281 | } |
| 1282 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 1283 | void __exit kvmppc_booke_exit(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1284 | { |
| 1285 | free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER); |
| 1286 | kvm_exit(); |
| 1287 | } |