2 * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
7 * This file is derived from arch/powerpc/kvm/44x_emulate.c,
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License, version 2, as
12 * published by the Free Software Foundation.
15 #include <asm/kvm_ppc.h>
16 #include <asm/disassemble.h>
17 #include <asm/dbell.h>
22 #define XOP_DCBTLS 166
23 #define XOP_MSGSND 206
24 #define XOP_MSGCLR 238
25 #define XOP_TLBIVAX 786
30 #define XOP_EHPRIV 270
32 #ifdef CONFIG_KVM_E500MC
33 static int dbell2prio(ulong param)
35 int msg = param & PPC_DBELL_TYPE_MASK;
39 case PPC_DBELL_TYPE(PPC_DBELL):
40 prio = BOOKE_IRQPRIO_DBELL;
42 case PPC_DBELL_TYPE(PPC_DBELL_CRIT):
43 prio = BOOKE_IRQPRIO_DBELL_CRIT;
52 static int kvmppc_e500_emul_msgclr(struct kvm_vcpu *vcpu, int rb)
54 ulong param = vcpu->arch.gpr[rb];
55 int prio = dbell2prio(param);
60 clear_bit(prio, &vcpu->arch.pending_exceptions);
64 static int kvmppc_e500_emul_msgsnd(struct kvm_vcpu *vcpu, int rb)
66 ulong param = vcpu->arch.gpr[rb];
67 int prio = dbell2prio(rb);
68 int pir = param & PPC_DBELL_PIR_MASK;
70 struct kvm_vcpu *cvcpu;
75 kvm_for_each_vcpu(i, cvcpu, vcpu->kvm) {
76 int cpir = cvcpu->arch.shared->pir;
77 if ((param & PPC_DBELL_MSG_BRDCAST) || (cpir == pir)) {
78 set_bit(prio, &cvcpu->arch.pending_exceptions);
87 static int kvmppc_e500_emul_ehpriv(struct kvm_run *run, struct kvm_vcpu *vcpu,
88 unsigned int inst, int *advance)
90 int emulated = EMULATE_DONE;
92 switch (get_oc(inst)) {
94 run->exit_reason = KVM_EXIT_DEBUG;
95 run->debug.arch.address = vcpu->arch.pc;
96 run->debug.arch.status = 0;
97 kvmppc_account_exit(vcpu, DEBUG_EXITS);
98 emulated = EMULATE_EXIT_USER;
102 emulated = EMULATE_FAIL;
107 static int kvmppc_e500_emul_dcbtls(struct kvm_vcpu *vcpu)
109 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
111 /* Always fail to lock the cache */
112 vcpu_e500->l1csr0 |= L1CSR0_CUL;
116 int kvmppc_core_emulate_op_e500(struct kvm_run *run, struct kvm_vcpu *vcpu,
117 unsigned int inst, int *advance)
119 int emulated = EMULATE_DONE;
120 int ra = get_ra(inst);
121 int rb = get_rb(inst);
122 int rt = get_rt(inst);
125 switch (get_op(inst)) {
127 switch (get_xop(inst)) {
130 emulated = kvmppc_e500_emul_dcbtls(vcpu);
133 #ifdef CONFIG_KVM_E500MC
135 emulated = kvmppc_e500_emul_msgsnd(vcpu, rb);
139 emulated = kvmppc_e500_emul_msgclr(vcpu, rb);
144 emulated = kvmppc_e500_emul_tlbre(vcpu);
148 emulated = kvmppc_e500_emul_tlbwe(vcpu);
152 ea = kvmppc_get_ea_indexed(vcpu, ra, rb);
153 emulated = kvmppc_e500_emul_tlbsx(vcpu, ea);
158 ea = kvmppc_get_ea_indexed(vcpu, ra, rb);
159 emulated = kvmppc_e500_emul_tlbilx(vcpu, type, ea);
164 ea = kvmppc_get_ea_indexed(vcpu, ra, rb);
165 emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
169 emulated = kvmppc_e500_emul_ehpriv(run, vcpu, inst,
174 emulated = EMULATE_FAIL;
180 emulated = EMULATE_FAIL;
183 if (emulated == EMULATE_FAIL)
184 emulated = kvmppc_booke_emulate_op(run, vcpu, inst, advance);
189 int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
191 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
192 int emulated = EMULATE_DONE;
195 #ifndef CONFIG_KVM_BOOKE_HV
197 kvmppc_set_pid(vcpu, spr_val);
202 vcpu_e500->pid[1] = spr_val;
207 vcpu_e500->pid[2] = spr_val;
210 vcpu->arch.shared->mas0 = spr_val;
213 vcpu->arch.shared->mas1 = spr_val;
216 vcpu->arch.shared->mas2 = spr_val;
219 vcpu->arch.shared->mas7_3 &= ~(u64)0xffffffff;
220 vcpu->arch.shared->mas7_3 |= spr_val;
223 vcpu->arch.shared->mas4 = spr_val;
226 vcpu->arch.shared->mas6 = spr_val;
229 vcpu->arch.shared->mas7_3 &= (u64)0xffffffff;
230 vcpu->arch.shared->mas7_3 |= (u64)spr_val << 32;
234 vcpu_e500->l1csr0 = spr_val;
235 vcpu_e500->l1csr0 &= ~(L1CSR0_DCFI | L1CSR0_CLFC);
238 vcpu_e500->l1csr1 = spr_val;
239 vcpu_e500->l1csr1 &= ~(L1CSR1_ICFI | L1CSR1_ICLFR);
242 vcpu_e500->hid0 = spr_val;
245 vcpu_e500->hid1 = spr_val;
249 emulated = kvmppc_e500_emul_mt_mmucsr0(vcpu_e500,
255 * Guest relies on host power management configurations
256 * Treat the request as a general store
258 vcpu->arch.pwrmgtcr0 = spr_val;
261 /* extra exceptions */
262 #ifdef CONFIG_SPE_POSSIBLE
264 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL] = spr_val;
267 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA] = spr_val;
270 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND] = spr_val;
273 #ifdef CONFIG_ALTIVEC
275 vcpu->arch.ivor[BOOKE_IRQPRIO_ALTIVEC_UNAVAIL] = spr_val;
278 vcpu->arch.ivor[BOOKE_IRQPRIO_ALTIVEC_ASSIST] = spr_val;
282 vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR] = spr_val;
284 #ifdef CONFIG_KVM_BOOKE_HV
286 vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL] = spr_val;
289 vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL_CRIT] = spr_val;
293 emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, spr_val);
299 int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
301 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
302 int emulated = EMULATE_DONE;
305 #ifndef CONFIG_KVM_BOOKE_HV
307 *spr_val = vcpu_e500->pid[0];
310 *spr_val = vcpu_e500->pid[1];
313 *spr_val = vcpu_e500->pid[2];
316 *spr_val = vcpu->arch.shared->mas0;
319 *spr_val = vcpu->arch.shared->mas1;
322 *spr_val = vcpu->arch.shared->mas2;
325 *spr_val = (u32)vcpu->arch.shared->mas7_3;
328 *spr_val = vcpu->arch.shared->mas4;
331 *spr_val = vcpu->arch.shared->mas6;
334 *spr_val = vcpu->arch.shared->mas7_3 >> 32;
338 *spr_val = vcpu->arch.decar;
341 *spr_val = vcpu->arch.tlbcfg[0];
344 *spr_val = vcpu->arch.tlbcfg[1];
347 if (!has_feature(vcpu, VCPU_FTR_MMU_V2))
349 *spr_val = vcpu->arch.tlbps[0];
352 if (!has_feature(vcpu, VCPU_FTR_MMU_V2))
354 *spr_val = vcpu->arch.tlbps[1];
357 *spr_val = vcpu_e500->l1csr0;
360 *spr_val = vcpu_e500->l1csr1;
363 *spr_val = vcpu_e500->hid0;
366 *spr_val = vcpu_e500->hid1;
369 *spr_val = vcpu_e500->svr;
377 *spr_val = vcpu->arch.mmucfg;
380 if (!has_feature(vcpu, VCPU_FTR_MMU_V2))
383 * Legacy Linux guests access EPTCFG register even if the E.PT
384 * category is disabled in the VM. Give them a chance to live.
386 *spr_val = vcpu->arch.eptcfg;
390 *spr_val = vcpu->arch.pwrmgtcr0;
393 /* extra exceptions */
394 #ifdef CONFIG_SPE_POSSIBLE
396 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL];
399 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA];
402 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND];
405 #ifdef CONFIG_ALTIVEC
407 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_ALTIVEC_UNAVAIL];
410 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_ALTIVEC_ASSIST];
414 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR];
416 #ifdef CONFIG_KVM_BOOKE_HV
418 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL];
421 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL_CRIT];
425 emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, spr_val);