Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [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. 2008 |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 16 | * Copyright 2011 Freescale Semiconductor, Inc. |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 17 | * |
| 18 | * Authors: Hollis Blanchard <hollisb@us.ibm.com> |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kvm_host.h> |
| 22 | #include <asm/disassemble.h> |
| 23 | |
| 24 | #include "booke.h" |
| 25 | |
| 26 | #define OP_19_XOP_RFI 50 |
Bharat Bhushan | 0c1fc3c | 2012-06-27 19:37:31 +0000 | [diff] [blame] | 27 | #define OP_19_XOP_RFCI 51 |
Bharat Bhushan | c8ca97c | 2014-08-06 12:08:52 +0530 | [diff] [blame] | 28 | #define OP_19_XOP_RFDI 39 |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 29 | |
| 30 | #define OP_31_XOP_MFMSR 83 |
| 31 | #define OP_31_XOP_WRTEE 131 |
| 32 | #define OP_31_XOP_MTMSR 146 |
| 33 | #define OP_31_XOP_WRTEEI 163 |
| 34 | |
| 35 | static void kvmppc_emul_rfi(struct kvm_vcpu *vcpu) |
| 36 | { |
Simon Guo | 173c520 | 2018-05-07 14:20:08 +0800 | [diff] [blame^] | 37 | vcpu->arch.regs.nip = vcpu->arch.shared->srr0; |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 38 | kvmppc_set_msr(vcpu, vcpu->arch.shared->srr1); |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 39 | } |
| 40 | |
Bharat Bhushan | c8ca97c | 2014-08-06 12:08:52 +0530 | [diff] [blame] | 41 | static void kvmppc_emul_rfdi(struct kvm_vcpu *vcpu) |
| 42 | { |
Simon Guo | 173c520 | 2018-05-07 14:20:08 +0800 | [diff] [blame^] | 43 | vcpu->arch.regs.nip = vcpu->arch.dsrr0; |
Bharat Bhushan | c8ca97c | 2014-08-06 12:08:52 +0530 | [diff] [blame] | 44 | kvmppc_set_msr(vcpu, vcpu->arch.dsrr1); |
| 45 | } |
| 46 | |
Bharat Bhushan | 0c1fc3c | 2012-06-27 19:37:31 +0000 | [diff] [blame] | 47 | static void kvmppc_emul_rfci(struct kvm_vcpu *vcpu) |
| 48 | { |
Simon Guo | 173c520 | 2018-05-07 14:20:08 +0800 | [diff] [blame^] | 49 | vcpu->arch.regs.nip = vcpu->arch.csrr0; |
Bharat Bhushan | 0c1fc3c | 2012-06-27 19:37:31 +0000 | [diff] [blame] | 50 | kvmppc_set_msr(vcpu, vcpu->arch.csrr1); |
| 51 | } |
| 52 | |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 53 | int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 54 | unsigned int inst, int *advance) |
| 55 | { |
| 56 | int emulated = EMULATE_DONE; |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 57 | int rs = get_rs(inst); |
| 58 | int rt = get_rt(inst); |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 59 | |
| 60 | switch (get_op(inst)) { |
| 61 | case 19: |
| 62 | switch (get_xop(inst)) { |
| 63 | case OP_19_XOP_RFI: |
| 64 | kvmppc_emul_rfi(vcpu); |
| 65 | kvmppc_set_exit_type(vcpu, EMULATED_RFI_EXITS); |
| 66 | *advance = 0; |
| 67 | break; |
| 68 | |
Bharat Bhushan | 0c1fc3c | 2012-06-27 19:37:31 +0000 | [diff] [blame] | 69 | case OP_19_XOP_RFCI: |
| 70 | kvmppc_emul_rfci(vcpu); |
| 71 | kvmppc_set_exit_type(vcpu, EMULATED_RFCI_EXITS); |
| 72 | *advance = 0; |
| 73 | break; |
| 74 | |
Bharat Bhushan | c8ca97c | 2014-08-06 12:08:52 +0530 | [diff] [blame] | 75 | case OP_19_XOP_RFDI: |
| 76 | kvmppc_emul_rfdi(vcpu); |
| 77 | kvmppc_set_exit_type(vcpu, EMULATED_RFDI_EXITS); |
| 78 | *advance = 0; |
| 79 | break; |
| 80 | |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 81 | default: |
| 82 | emulated = EMULATE_FAIL; |
| 83 | break; |
| 84 | } |
| 85 | break; |
| 86 | |
| 87 | case 31: |
| 88 | switch (get_xop(inst)) { |
| 89 | |
| 90 | case OP_31_XOP_MFMSR: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 91 | kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->msr); |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 92 | kvmppc_set_exit_type(vcpu, EMULATED_MFMSR_EXITS); |
| 93 | break; |
| 94 | |
| 95 | case OP_31_XOP_MTMSR: |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 96 | kvmppc_set_exit_type(vcpu, EMULATED_MTMSR_EXITS); |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 97 | kvmppc_set_msr(vcpu, kvmppc_get_gpr(vcpu, rs)); |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 98 | break; |
| 99 | |
| 100 | case OP_31_XOP_WRTEE: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 101 | vcpu->arch.shared->msr = (vcpu->arch.shared->msr & ~MSR_EE) |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 102 | | (kvmppc_get_gpr(vcpu, rs) & MSR_EE); |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 103 | kvmppc_set_exit_type(vcpu, EMULATED_WRTEE_EXITS); |
| 104 | break; |
| 105 | |
| 106 | case OP_31_XOP_WRTEEI: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 107 | vcpu->arch.shared->msr = (vcpu->arch.shared->msr & ~MSR_EE) |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 108 | | (inst & MSR_EE); |
| 109 | kvmppc_set_exit_type(vcpu, EMULATED_WRTEE_EXITS); |
| 110 | break; |
| 111 | |
| 112 | default: |
| 113 | emulated = EMULATE_FAIL; |
| 114 | } |
| 115 | |
| 116 | break; |
| 117 | |
| 118 | default: |
| 119 | emulated = EMULATE_FAIL; |
| 120 | } |
| 121 | |
| 122 | return emulated; |
| 123 | } |
| 124 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 125 | /* |
| 126 | * NOTE: some of these registers are not emulated on BOOKE_HV (GS-mode). |
| 127 | * Their backing store is in real registers, and these functions |
| 128 | * will return the wrong result if called for them in another context |
| 129 | * (such as debugging). |
| 130 | */ |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 131 | int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 132 | { |
| 133 | int emulated = EMULATE_DONE; |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 134 | bool debug_inst = false; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 135 | |
| 136 | switch (sprn) { |
| 137 | case SPRN_DEAR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 138 | vcpu->arch.shared->dar = spr_val; |
| 139 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 140 | case SPRN_ESR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 141 | vcpu->arch.shared->esr = spr_val; |
| 142 | break; |
Bharat Bhushan | 0c1fc3c | 2012-06-27 19:37:31 +0000 | [diff] [blame] | 143 | case SPRN_CSRR0: |
| 144 | vcpu->arch.csrr0 = spr_val; |
| 145 | break; |
| 146 | case SPRN_CSRR1: |
| 147 | vcpu->arch.csrr1 = spr_val; |
| 148 | break; |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 149 | case SPRN_DSRR0: |
| 150 | vcpu->arch.dsrr0 = spr_val; |
| 151 | break; |
| 152 | case SPRN_DSRR1: |
| 153 | vcpu->arch.dsrr1 = spr_val; |
| 154 | break; |
| 155 | case SPRN_IAC1: |
| 156 | /* |
| 157 | * If userspace is debugging guest then guest |
| 158 | * can not access debug registers. |
| 159 | */ |
| 160 | if (vcpu->guest_debug) |
| 161 | break; |
| 162 | |
| 163 | debug_inst = true; |
| 164 | vcpu->arch.dbg_reg.iac1 = spr_val; |
| 165 | break; |
| 166 | case SPRN_IAC2: |
| 167 | /* |
| 168 | * If userspace is debugging guest then guest |
| 169 | * can not access debug registers. |
| 170 | */ |
| 171 | if (vcpu->guest_debug) |
| 172 | break; |
| 173 | |
| 174 | debug_inst = true; |
| 175 | vcpu->arch.dbg_reg.iac2 = spr_val; |
| 176 | break; |
| 177 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 178 | case SPRN_IAC3: |
| 179 | /* |
| 180 | * If userspace is debugging guest then guest |
| 181 | * can not access debug registers. |
| 182 | */ |
| 183 | if (vcpu->guest_debug) |
| 184 | break; |
| 185 | |
| 186 | debug_inst = true; |
| 187 | vcpu->arch.dbg_reg.iac3 = spr_val; |
| 188 | break; |
| 189 | case SPRN_IAC4: |
| 190 | /* |
| 191 | * If userspace is debugging guest then guest |
| 192 | * can not access debug registers. |
| 193 | */ |
| 194 | if (vcpu->guest_debug) |
| 195 | break; |
| 196 | |
| 197 | debug_inst = true; |
| 198 | vcpu->arch.dbg_reg.iac4 = spr_val; |
| 199 | break; |
| 200 | #endif |
| 201 | case SPRN_DAC1: |
| 202 | /* |
| 203 | * If userspace is debugging guest then guest |
| 204 | * can not access debug registers. |
| 205 | */ |
| 206 | if (vcpu->guest_debug) |
| 207 | break; |
| 208 | |
| 209 | debug_inst = true; |
| 210 | vcpu->arch.dbg_reg.dac1 = spr_val; |
| 211 | break; |
| 212 | case SPRN_DAC2: |
| 213 | /* |
| 214 | * If userspace is debugging guest then guest |
| 215 | * can not access debug registers. |
| 216 | */ |
| 217 | if (vcpu->guest_debug) |
| 218 | break; |
| 219 | |
| 220 | debug_inst = true; |
| 221 | vcpu->arch.dbg_reg.dac2 = spr_val; |
| 222 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 223 | case SPRN_DBCR0: |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 224 | /* |
| 225 | * If userspace is debugging guest then guest |
| 226 | * can not access debug registers. |
| 227 | */ |
| 228 | if (vcpu->guest_debug) |
| 229 | break; |
| 230 | |
| 231 | debug_inst = true; |
| 232 | spr_val &= (DBCR0_IDM | DBCR0_IC | DBCR0_BT | DBCR0_TIE | |
| 233 | DBCR0_IAC1 | DBCR0_IAC2 | DBCR0_IAC3 | DBCR0_IAC4 | |
| 234 | DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W); |
| 235 | |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 236 | vcpu->arch.dbg_reg.dbcr0 = spr_val; |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 237 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 238 | case SPRN_DBCR1: |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 239 | /* |
| 240 | * If userspace is debugging guest then guest |
| 241 | * can not access debug registers. |
| 242 | */ |
| 243 | if (vcpu->guest_debug) |
| 244 | break; |
| 245 | |
| 246 | debug_inst = true; |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 247 | vcpu->arch.dbg_reg.dbcr1 = spr_val; |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 248 | break; |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 249 | case SPRN_DBCR2: |
| 250 | /* |
| 251 | * If userspace is debugging guest then guest |
| 252 | * can not access debug registers. |
| 253 | */ |
| 254 | if (vcpu->guest_debug) |
| 255 | break; |
| 256 | |
| 257 | debug_inst = true; |
| 258 | vcpu->arch.dbg_reg.dbcr2 = spr_val; |
| 259 | break; |
Hollis Blanchard | f7b200a | 2009-01-03 16:23:07 -0600 | [diff] [blame] | 260 | case SPRN_DBSR: |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 261 | /* |
| 262 | * If userspace is debugging guest then guest |
| 263 | * can not access debug registers. |
| 264 | */ |
| 265 | if (vcpu->guest_debug) |
| 266 | break; |
| 267 | |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 268 | vcpu->arch.dbsr &= ~spr_val; |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 269 | if (!(vcpu->arch.dbsr & ~DBSR_IDE)) |
| 270 | kvmppc_core_dequeue_debug(vcpu); |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 271 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 272 | case SPRN_TSR: |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 273 | kvmppc_clr_tsr_bits(vcpu, spr_val); |
| 274 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 275 | case SPRN_TCR: |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 276 | /* |
| 277 | * WRC is a 2-bit field that is supposed to preserve its |
| 278 | * value once written to non-zero. |
| 279 | */ |
| 280 | if (vcpu->arch.tcr & TCR_WRC_MASK) { |
| 281 | spr_val &= ~TCR_WRC_MASK; |
| 282 | spr_val |= vcpu->arch.tcr & TCR_WRC_MASK; |
| 283 | } |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 284 | kvmppc_set_tcr(vcpu, spr_val); |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 285 | break; |
| 286 | |
Bharat Bhushan | 21bd000 | 2012-05-20 23:21:23 +0000 | [diff] [blame] | 287 | case SPRN_DECAR: |
| 288 | vcpu->arch.decar = spr_val; |
| 289 | break; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 290 | /* |
| 291 | * Note: SPRG4-7 are user-readable. |
| 292 | * These values are loaded into the real SPRGs when resuming the |
| 293 | * guest (PR-mode only). |
| 294 | */ |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 295 | case SPRN_SPRG4: |
Bharat Bhushan | c1b8a01 | 2014-07-17 17:01:39 +0530 | [diff] [blame] | 296 | kvmppc_set_sprg4(vcpu, spr_val); |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 297 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 298 | case SPRN_SPRG5: |
Bharat Bhushan | c1b8a01 | 2014-07-17 17:01:39 +0530 | [diff] [blame] | 299 | kvmppc_set_sprg5(vcpu, spr_val); |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 300 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 301 | case SPRN_SPRG6: |
Bharat Bhushan | c1b8a01 | 2014-07-17 17:01:39 +0530 | [diff] [blame] | 302 | kvmppc_set_sprg6(vcpu, spr_val); |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 303 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 304 | case SPRN_SPRG7: |
Bharat Bhushan | c1b8a01 | 2014-07-17 17:01:39 +0530 | [diff] [blame] | 305 | kvmppc_set_sprg7(vcpu, spr_val); |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 306 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 307 | |
| 308 | case SPRN_IVPR: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 309 | vcpu->arch.ivpr = spr_val; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 310 | #ifdef CONFIG_KVM_BOOKE_HV |
| 311 | mtspr(SPRN_GIVPR, spr_val); |
| 312 | #endif |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 313 | break; |
| 314 | case SPRN_IVOR0: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 315 | vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 316 | break; |
| 317 | case SPRN_IVOR1: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 318 | vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 319 | break; |
| 320 | case SPRN_IVOR2: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 321 | vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE] = spr_val; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 322 | #ifdef CONFIG_KVM_BOOKE_HV |
| 323 | mtspr(SPRN_GIVOR2, spr_val); |
| 324 | #endif |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 325 | break; |
| 326 | case SPRN_IVOR3: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 327 | vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 328 | break; |
| 329 | case SPRN_IVOR4: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 330 | vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 331 | break; |
| 332 | case SPRN_IVOR5: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 333 | vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 334 | break; |
| 335 | case SPRN_IVOR6: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 336 | vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 337 | break; |
| 338 | case SPRN_IVOR7: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 339 | vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 340 | break; |
| 341 | case SPRN_IVOR8: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 342 | vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL] = spr_val; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 343 | #ifdef CONFIG_KVM_BOOKE_HV |
| 344 | mtspr(SPRN_GIVOR8, spr_val); |
| 345 | #endif |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 346 | break; |
| 347 | case SPRN_IVOR9: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 348 | vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 349 | break; |
| 350 | case SPRN_IVOR10: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 351 | vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 352 | break; |
| 353 | case SPRN_IVOR11: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 354 | vcpu->arch.ivor[BOOKE_IRQPRIO_FIT] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 355 | break; |
| 356 | case SPRN_IVOR12: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 357 | vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 358 | break; |
| 359 | case SPRN_IVOR13: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 360 | vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 361 | break; |
| 362 | case SPRN_IVOR14: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 363 | vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 364 | break; |
| 365 | case SPRN_IVOR15: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 366 | vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = spr_val; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 367 | break; |
Alexander Graf | 50c871e | 2012-08-13 14:50:54 +0200 | [diff] [blame] | 368 | case SPRN_MCSR: |
| 369 | vcpu->arch.mcsr &= ~spr_val; |
| 370 | break; |
Mihai Caraman | 38f9882 | 2012-10-11 06:13:27 +0000 | [diff] [blame] | 371 | #if defined(CONFIG_64BIT) |
| 372 | case SPRN_EPCR: |
| 373 | kvmppc_set_epcr(vcpu, spr_val); |
| 374 | #ifdef CONFIG_KVM_BOOKE_HV |
| 375 | mtspr(SPRN_EPCR, vcpu->arch.shadow_epcr); |
| 376 | #endif |
| 377 | break; |
| 378 | #endif |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 379 | default: |
| 380 | emulated = EMULATE_FAIL; |
| 381 | } |
| 382 | |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 383 | if (debug_inst) { |
| 384 | current->thread.debug = vcpu->arch.dbg_reg; |
| 385 | switch_booke_debug_regs(&vcpu->arch.dbg_reg); |
| 386 | } |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 387 | return emulated; |
| 388 | } |
| 389 | |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 390 | int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val) |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 391 | { |
| 392 | int emulated = EMULATE_DONE; |
| 393 | |
| 394 | switch (sprn) { |
| 395 | case SPRN_IVPR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 396 | *spr_val = vcpu->arch.ivpr; |
| 397 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 398 | case SPRN_DEAR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 399 | *spr_val = vcpu->arch.shared->dar; |
| 400 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 401 | case SPRN_ESR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 402 | *spr_val = vcpu->arch.shared->esr; |
| 403 | break; |
Alexander Graf | 37ecb25 | 2013-01-04 18:02:14 +0100 | [diff] [blame] | 404 | case SPRN_EPR: |
| 405 | *spr_val = vcpu->arch.epr; |
| 406 | break; |
Bharat Bhushan | 0c1fc3c | 2012-06-27 19:37:31 +0000 | [diff] [blame] | 407 | case SPRN_CSRR0: |
| 408 | *spr_val = vcpu->arch.csrr0; |
| 409 | break; |
| 410 | case SPRN_CSRR1: |
| 411 | *spr_val = vcpu->arch.csrr1; |
| 412 | break; |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 413 | case SPRN_DSRR0: |
| 414 | *spr_val = vcpu->arch.dsrr0; |
| 415 | break; |
| 416 | case SPRN_DSRR1: |
| 417 | *spr_val = vcpu->arch.dsrr1; |
| 418 | break; |
| 419 | case SPRN_IAC1: |
| 420 | *spr_val = vcpu->arch.dbg_reg.iac1; |
| 421 | break; |
| 422 | case SPRN_IAC2: |
| 423 | *spr_val = vcpu->arch.dbg_reg.iac2; |
| 424 | break; |
| 425 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 426 | case SPRN_IAC3: |
| 427 | *spr_val = vcpu->arch.dbg_reg.iac3; |
| 428 | break; |
| 429 | case SPRN_IAC4: |
| 430 | *spr_val = vcpu->arch.dbg_reg.iac4; |
| 431 | break; |
| 432 | #endif |
| 433 | case SPRN_DAC1: |
| 434 | *spr_val = vcpu->arch.dbg_reg.dac1; |
| 435 | break; |
| 436 | case SPRN_DAC2: |
| 437 | *spr_val = vcpu->arch.dbg_reg.dac2; |
| 438 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 439 | case SPRN_DBCR0: |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 440 | *spr_val = vcpu->arch.dbg_reg.dbcr0; |
Bharat Bhushan | 348ba71 | 2014-08-06 12:08:55 +0530 | [diff] [blame] | 441 | if (vcpu->guest_debug) |
| 442 | *spr_val = *spr_val | DBCR0_EDM; |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 443 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 444 | case SPRN_DBCR1: |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 445 | *spr_val = vcpu->arch.dbg_reg.dbcr1; |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 446 | break; |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 447 | case SPRN_DBCR2: |
| 448 | *spr_val = vcpu->arch.dbg_reg.dbcr2; |
| 449 | break; |
Hollis Blanchard | f7b200a | 2009-01-03 16:23:07 -0600 | [diff] [blame] | 450 | case SPRN_DBSR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 451 | *spr_val = vcpu->arch.dbsr; |
| 452 | break; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 453 | case SPRN_TSR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 454 | *spr_val = vcpu->arch.tsr; |
| 455 | break; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 456 | case SPRN_TCR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 457 | *spr_val = vcpu->arch.tcr; |
| 458 | break; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 459 | |
| 460 | case SPRN_IVOR0: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 461 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 462 | break; |
| 463 | case SPRN_IVOR1: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 464 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 465 | break; |
| 466 | case SPRN_IVOR2: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 467 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 468 | break; |
| 469 | case SPRN_IVOR3: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 470 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 471 | break; |
| 472 | case SPRN_IVOR4: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 473 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 474 | break; |
| 475 | case SPRN_IVOR5: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 476 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 477 | break; |
| 478 | case SPRN_IVOR6: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 479 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 480 | break; |
| 481 | case SPRN_IVOR7: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 482 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 483 | break; |
| 484 | case SPRN_IVOR8: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 485 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 486 | break; |
| 487 | case SPRN_IVOR9: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 488 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 489 | break; |
| 490 | case SPRN_IVOR10: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 491 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 492 | break; |
| 493 | case SPRN_IVOR11: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 494 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_FIT]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 495 | break; |
| 496 | case SPRN_IVOR12: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 497 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 498 | break; |
| 499 | case SPRN_IVOR13: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 500 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 501 | break; |
| 502 | case SPRN_IVOR14: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 503 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 504 | break; |
| 505 | case SPRN_IVOR15: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 506 | *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]; |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 507 | break; |
Alexander Graf | 50c871e | 2012-08-13 14:50:54 +0200 | [diff] [blame] | 508 | case SPRN_MCSR: |
| 509 | *spr_val = vcpu->arch.mcsr; |
| 510 | break; |
Mihai Caraman | 38f9882 | 2012-10-11 06:13:27 +0000 | [diff] [blame] | 511 | #if defined(CONFIG_64BIT) |
| 512 | case SPRN_EPCR: |
| 513 | *spr_val = vcpu->arch.epcr; |
| 514 | break; |
| 515 | #endif |
Hollis Blanchard | d0c7dc0 | 2009-01-03 16:23:06 -0600 | [diff] [blame] | 516 | |
| 517 | default: |
| 518 | emulated = EMULATE_FAIL; |
| 519 | } |
| 520 | |
| 521 | return emulated; |
| 522 | } |