2 * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
4 * Author: Yu Liu, <yu.liu@freescale.com>
7 * This file is derived from arch/powerpc/kvm/44x_emulate.c,
8 * by Hollis Blanchard <hollisb@us.ibm.com>.
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_MSGSND 206
23 #define XOP_MSGCLR 238
24 #define XOP_TLBIVAX 786
30 #ifdef CONFIG_KVM_E500MC
31 static int dbell2prio(ulong param
)
33 int msg
= param
& PPC_DBELL_TYPE_MASK
;
37 case PPC_DBELL_TYPE(PPC_DBELL
):
38 prio
= BOOKE_IRQPRIO_DBELL
;
40 case PPC_DBELL_TYPE(PPC_DBELL_CRIT
):
41 prio
= BOOKE_IRQPRIO_DBELL_CRIT
;
50 static int kvmppc_e500_emul_msgclr(struct kvm_vcpu
*vcpu
, int rb
)
52 ulong param
= vcpu
->arch
.gpr
[rb
];
53 int prio
= dbell2prio(param
);
58 clear_bit(prio
, &vcpu
->arch
.pending_exceptions
);
62 static int kvmppc_e500_emul_msgsnd(struct kvm_vcpu
*vcpu
, int rb
)
64 ulong param
= vcpu
->arch
.gpr
[rb
];
65 int prio
= dbell2prio(rb
);
66 int pir
= param
& PPC_DBELL_PIR_MASK
;
68 struct kvm_vcpu
*cvcpu
;
73 kvm_for_each_vcpu(i
, cvcpu
, vcpu
->kvm
) {
74 int cpir
= cvcpu
->arch
.shared
->pir
;
75 if ((param
& PPC_DBELL_MSG_BRDCAST
) || (cpir
== pir
)) {
76 set_bit(prio
, &cvcpu
->arch
.pending_exceptions
);
85 int kvmppc_core_emulate_op(struct kvm_run
*run
, struct kvm_vcpu
*vcpu
,
86 unsigned int inst
, int *advance
)
88 int emulated
= EMULATE_DONE
;
89 int ra
= get_ra(inst
);
90 int rb
= get_rb(inst
);
91 int rt
= get_rt(inst
);
93 switch (get_op(inst
)) {
95 switch (get_xop(inst
)) {
97 #ifdef CONFIG_KVM_E500MC
99 emulated
= kvmppc_e500_emul_msgsnd(vcpu
, rb
);
103 emulated
= kvmppc_e500_emul_msgclr(vcpu
, rb
);
108 emulated
= kvmppc_e500_emul_tlbre(vcpu
);
112 emulated
= kvmppc_e500_emul_tlbwe(vcpu
);
116 emulated
= kvmppc_e500_emul_tlbsx(vcpu
,rb
);
120 emulated
= kvmppc_e500_emul_tlbilx(vcpu
, rt
, ra
, rb
);
124 emulated
= kvmppc_e500_emul_tlbivax(vcpu
, ra
, rb
);
128 emulated
= EMULATE_FAIL
;
134 emulated
= EMULATE_FAIL
;
137 if (emulated
== EMULATE_FAIL
)
138 emulated
= kvmppc_booke_emulate_op(run
, vcpu
, inst
, advance
);
143 int kvmppc_core_emulate_mtspr(struct kvm_vcpu
*vcpu
, int sprn
, ulong spr_val
)
145 struct kvmppc_vcpu_e500
*vcpu_e500
= to_e500(vcpu
);
146 int emulated
= EMULATE_DONE
;
149 #ifndef CONFIG_KVM_BOOKE_HV
151 kvmppc_set_pid(vcpu
, spr_val
);
156 vcpu_e500
->pid
[1] = spr_val
;
161 vcpu_e500
->pid
[2] = spr_val
;
164 vcpu
->arch
.shared
->mas0
= spr_val
;
167 vcpu
->arch
.shared
->mas1
= spr_val
;
170 vcpu
->arch
.shared
->mas2
= spr_val
;
173 vcpu
->arch
.shared
->mas7_3
&= ~(u64
)0xffffffff;
174 vcpu
->arch
.shared
->mas7_3
|= spr_val
;
177 vcpu
->arch
.shared
->mas4
= spr_val
;
180 vcpu
->arch
.shared
->mas6
= spr_val
;
183 vcpu
->arch
.shared
->mas7_3
&= (u64
)0xffffffff;
184 vcpu
->arch
.shared
->mas7_3
|= (u64
)spr_val
<< 32;
188 vcpu_e500
->l1csr0
= spr_val
;
189 vcpu_e500
->l1csr0
&= ~(L1CSR0_DCFI
| L1CSR0_CLFC
);
192 vcpu_e500
->l1csr1
= spr_val
;
195 vcpu_e500
->hid0
= spr_val
;
198 vcpu_e500
->hid1
= spr_val
;
202 emulated
= kvmppc_e500_emul_mt_mmucsr0(vcpu_e500
,
206 /* extra exceptions */
208 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_UNAVAIL
] = spr_val
;
211 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_DATA
] = spr_val
;
214 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_ROUND
] = spr_val
;
217 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PERFORMANCE_MONITOR
] = spr_val
;
219 #ifdef CONFIG_KVM_BOOKE_HV
221 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL
] = spr_val
;
224 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL_CRIT
] = spr_val
;
228 emulated
= kvmppc_booke_emulate_mtspr(vcpu
, sprn
, spr_val
);
234 int kvmppc_core_emulate_mfspr(struct kvm_vcpu
*vcpu
, int sprn
, ulong
*spr_val
)
236 struct kvmppc_vcpu_e500
*vcpu_e500
= to_e500(vcpu
);
237 int emulated
= EMULATE_DONE
;
240 #ifndef CONFIG_KVM_BOOKE_HV
242 *spr_val
= vcpu_e500
->pid
[0];
245 *spr_val
= vcpu_e500
->pid
[1];
248 *spr_val
= vcpu_e500
->pid
[2];
251 *spr_val
= vcpu
->arch
.shared
->mas0
;
254 *spr_val
= vcpu
->arch
.shared
->mas1
;
257 *spr_val
= vcpu
->arch
.shared
->mas2
;
260 *spr_val
= (u32
)vcpu
->arch
.shared
->mas7_3
;
263 *spr_val
= vcpu
->arch
.shared
->mas4
;
266 *spr_val
= vcpu
->arch
.shared
->mas6
;
269 *spr_val
= vcpu
->arch
.shared
->mas7_3
>> 32;
273 *spr_val
= vcpu
->arch
.decar
;
276 *spr_val
= vcpu
->arch
.tlbcfg
[0];
279 *spr_val
= vcpu
->arch
.tlbcfg
[1];
282 *spr_val
= vcpu_e500
->l1csr0
;
285 *spr_val
= vcpu_e500
->l1csr1
;
288 *spr_val
= vcpu_e500
->hid0
;
291 *spr_val
= vcpu_e500
->hid1
;
294 *spr_val
= vcpu_e500
->svr
;
302 *spr_val
= vcpu
->arch
.mmucfg
;
305 /* extra exceptions */
307 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_UNAVAIL
];
310 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_DATA
];
313 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_ROUND
];
316 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PERFORMANCE_MONITOR
];
318 #ifdef CONFIG_KVM_BOOKE_HV
320 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL
];
323 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL_CRIT
];
327 emulated
= kvmppc_booke_emulate_mfspr(vcpu
, sprn
, spr_val
);