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