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_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 */
263 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_UNAVAIL
] = spr_val
;
266 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_DATA
] = spr_val
;
269 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_ROUND
] = spr_val
;
272 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PERFORMANCE_MONITOR
] = spr_val
;
274 #ifdef CONFIG_KVM_BOOKE_HV
276 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL
] = spr_val
;
279 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL_CRIT
] = spr_val
;
283 emulated
= kvmppc_booke_emulate_mtspr(vcpu
, sprn
, spr_val
);
289 int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu
*vcpu
, int sprn
, ulong
*spr_val
)
291 struct kvmppc_vcpu_e500
*vcpu_e500
= to_e500(vcpu
);
292 int emulated
= EMULATE_DONE
;
295 #ifndef CONFIG_KVM_BOOKE_HV
297 *spr_val
= vcpu_e500
->pid
[0];
300 *spr_val
= vcpu_e500
->pid
[1];
303 *spr_val
= vcpu_e500
->pid
[2];
306 *spr_val
= vcpu
->arch
.shared
->mas0
;
309 *spr_val
= vcpu
->arch
.shared
->mas1
;
312 *spr_val
= vcpu
->arch
.shared
->mas2
;
315 *spr_val
= (u32
)vcpu
->arch
.shared
->mas7_3
;
318 *spr_val
= vcpu
->arch
.shared
->mas4
;
321 *spr_val
= vcpu
->arch
.shared
->mas6
;
324 *spr_val
= vcpu
->arch
.shared
->mas7_3
>> 32;
328 *spr_val
= vcpu
->arch
.decar
;
331 *spr_val
= vcpu
->arch
.tlbcfg
[0];
334 *spr_val
= vcpu
->arch
.tlbcfg
[1];
337 if (!has_feature(vcpu
, VCPU_FTR_MMU_V2
))
339 *spr_val
= vcpu
->arch
.tlbps
[0];
342 if (!has_feature(vcpu
, VCPU_FTR_MMU_V2
))
344 *spr_val
= vcpu
->arch
.tlbps
[1];
347 *spr_val
= vcpu_e500
->l1csr0
;
350 *spr_val
= vcpu_e500
->l1csr1
;
353 *spr_val
= vcpu_e500
->hid0
;
356 *spr_val
= vcpu_e500
->hid1
;
359 *spr_val
= vcpu_e500
->svr
;
367 *spr_val
= vcpu
->arch
.mmucfg
;
370 if (!has_feature(vcpu
, VCPU_FTR_MMU_V2
))
373 * Legacy Linux guests access EPTCFG register even if the E.PT
374 * category is disabled in the VM. Give them a chance to live.
376 *spr_val
= vcpu
->arch
.eptcfg
;
380 *spr_val
= vcpu
->arch
.pwrmgtcr0
;
383 /* extra exceptions */
385 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_UNAVAIL
];
388 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_DATA
];
391 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_ROUND
];
394 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PERFORMANCE_MONITOR
];
396 #ifdef CONFIG_KVM_BOOKE_HV
398 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL
];
401 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL_CRIT
];
405 emulated
= kvmppc_booke_emulate_mfspr(vcpu
, sprn
, spr_val
);