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
29 #define XOP_EHPRIV 270
31 #ifdef CONFIG_KVM_E500MC
32 static int dbell2prio(ulong param
)
34 int msg
= param
& PPC_DBELL_TYPE_MASK
;
38 case PPC_DBELL_TYPE(PPC_DBELL
):
39 prio
= BOOKE_IRQPRIO_DBELL
;
41 case PPC_DBELL_TYPE(PPC_DBELL_CRIT
):
42 prio
= BOOKE_IRQPRIO_DBELL_CRIT
;
51 static int kvmppc_e500_emul_msgclr(struct kvm_vcpu
*vcpu
, int rb
)
53 ulong param
= vcpu
->arch
.gpr
[rb
];
54 int prio
= dbell2prio(param
);
59 clear_bit(prio
, &vcpu
->arch
.pending_exceptions
);
63 static int kvmppc_e500_emul_msgsnd(struct kvm_vcpu
*vcpu
, int rb
)
65 ulong param
= vcpu
->arch
.gpr
[rb
];
66 int prio
= dbell2prio(rb
);
67 int pir
= param
& PPC_DBELL_PIR_MASK
;
69 struct kvm_vcpu
*cvcpu
;
74 kvm_for_each_vcpu(i
, cvcpu
, vcpu
->kvm
) {
75 int cpir
= cvcpu
->arch
.shared
->pir
;
76 if ((param
& PPC_DBELL_MSG_BRDCAST
) || (cpir
== pir
)) {
77 set_bit(prio
, &cvcpu
->arch
.pending_exceptions
);
86 static int kvmppc_e500_emul_ehpriv(struct kvm_run
*run
, struct kvm_vcpu
*vcpu
,
87 unsigned int inst
, int *advance
)
89 int emulated
= EMULATE_DONE
;
91 switch (get_oc(inst
)) {
93 run
->exit_reason
= KVM_EXIT_DEBUG
;
94 run
->debug
.arch
.address
= vcpu
->arch
.pc
;
95 run
->debug
.arch
.status
= 0;
96 kvmppc_account_exit(vcpu
, DEBUG_EXITS
);
97 emulated
= EMULATE_EXIT_USER
;
101 emulated
= EMULATE_FAIL
;
106 int kvmppc_core_emulate_op_e500(struct kvm_run
*run
, struct kvm_vcpu
*vcpu
,
107 unsigned int inst
, int *advance
)
109 int emulated
= EMULATE_DONE
;
110 int ra
= get_ra(inst
);
111 int rb
= get_rb(inst
);
112 int rt
= get_rt(inst
);
115 switch (get_op(inst
)) {
117 switch (get_xop(inst
)) {
119 #ifdef CONFIG_KVM_E500MC
121 emulated
= kvmppc_e500_emul_msgsnd(vcpu
, rb
);
125 emulated
= kvmppc_e500_emul_msgclr(vcpu
, rb
);
130 emulated
= kvmppc_e500_emul_tlbre(vcpu
);
134 emulated
= kvmppc_e500_emul_tlbwe(vcpu
);
138 ea
= kvmppc_get_ea_indexed(vcpu
, ra
, rb
);
139 emulated
= kvmppc_e500_emul_tlbsx(vcpu
, ea
);
144 ea
= kvmppc_get_ea_indexed(vcpu
, ra
, rb
);
145 emulated
= kvmppc_e500_emul_tlbilx(vcpu
, type
, ea
);
150 ea
= kvmppc_get_ea_indexed(vcpu
, ra
, rb
);
151 emulated
= kvmppc_e500_emul_tlbivax(vcpu
, ea
);
155 emulated
= kvmppc_e500_emul_ehpriv(run
, vcpu
, inst
,
160 emulated
= EMULATE_FAIL
;
166 emulated
= EMULATE_FAIL
;
169 if (emulated
== EMULATE_FAIL
)
170 emulated
= kvmppc_booke_emulate_op(run
, vcpu
, inst
, advance
);
175 int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu
*vcpu
, int sprn
, ulong spr_val
)
177 struct kvmppc_vcpu_e500
*vcpu_e500
= to_e500(vcpu
);
178 int emulated
= EMULATE_DONE
;
181 #ifndef CONFIG_KVM_BOOKE_HV
183 kvmppc_set_pid(vcpu
, spr_val
);
188 vcpu_e500
->pid
[1] = spr_val
;
193 vcpu_e500
->pid
[2] = spr_val
;
196 vcpu
->arch
.shared
->mas0
= spr_val
;
199 vcpu
->arch
.shared
->mas1
= spr_val
;
202 vcpu
->arch
.shared
->mas2
= spr_val
;
205 vcpu
->arch
.shared
->mas7_3
&= ~(u64
)0xffffffff;
206 vcpu
->arch
.shared
->mas7_3
|= spr_val
;
209 vcpu
->arch
.shared
->mas4
= spr_val
;
212 vcpu
->arch
.shared
->mas6
= spr_val
;
215 vcpu
->arch
.shared
->mas7_3
&= (u64
)0xffffffff;
216 vcpu
->arch
.shared
->mas7_3
|= (u64
)spr_val
<< 32;
220 vcpu_e500
->l1csr0
= spr_val
;
221 vcpu_e500
->l1csr0
&= ~(L1CSR0_DCFI
| L1CSR0_CLFC
);
224 vcpu_e500
->l1csr1
= spr_val
;
227 vcpu_e500
->hid0
= spr_val
;
230 vcpu_e500
->hid1
= spr_val
;
234 emulated
= kvmppc_e500_emul_mt_mmucsr0(vcpu_e500
,
238 /* extra exceptions */
240 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_UNAVAIL
] = spr_val
;
243 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_DATA
] = spr_val
;
246 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_ROUND
] = spr_val
;
249 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PERFORMANCE_MONITOR
] = spr_val
;
251 #ifdef CONFIG_KVM_BOOKE_HV
253 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL
] = spr_val
;
256 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL_CRIT
] = spr_val
;
260 emulated
= kvmppc_booke_emulate_mtspr(vcpu
, sprn
, spr_val
);
266 int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu
*vcpu
, int sprn
, ulong
*spr_val
)
268 struct kvmppc_vcpu_e500
*vcpu_e500
= to_e500(vcpu
);
269 int emulated
= EMULATE_DONE
;
272 #ifndef CONFIG_KVM_BOOKE_HV
274 *spr_val
= vcpu_e500
->pid
[0];
277 *spr_val
= vcpu_e500
->pid
[1];
280 *spr_val
= vcpu_e500
->pid
[2];
283 *spr_val
= vcpu
->arch
.shared
->mas0
;
286 *spr_val
= vcpu
->arch
.shared
->mas1
;
289 *spr_val
= vcpu
->arch
.shared
->mas2
;
292 *spr_val
= (u32
)vcpu
->arch
.shared
->mas7_3
;
295 *spr_val
= vcpu
->arch
.shared
->mas4
;
298 *spr_val
= vcpu
->arch
.shared
->mas6
;
301 *spr_val
= vcpu
->arch
.shared
->mas7_3
>> 32;
305 *spr_val
= vcpu
->arch
.decar
;
308 *spr_val
= vcpu
->arch
.tlbcfg
[0];
311 *spr_val
= vcpu
->arch
.tlbcfg
[1];
314 if (!has_feature(vcpu
, VCPU_FTR_MMU_V2
))
316 *spr_val
= vcpu
->arch
.tlbps
[0];
319 if (!has_feature(vcpu
, VCPU_FTR_MMU_V2
))
321 *spr_val
= vcpu
->arch
.tlbps
[1];
324 *spr_val
= vcpu_e500
->l1csr0
;
327 *spr_val
= vcpu_e500
->l1csr1
;
330 *spr_val
= vcpu_e500
->hid0
;
333 *spr_val
= vcpu_e500
->hid1
;
336 *spr_val
= vcpu_e500
->svr
;
344 *spr_val
= vcpu
->arch
.mmucfg
;
347 if (!has_feature(vcpu
, VCPU_FTR_MMU_V2
))
350 * Legacy Linux guests access EPTCFG register even if the E.PT
351 * category is disabled in the VM. Give them a chance to live.
353 *spr_val
= vcpu
->arch
.eptcfg
;
356 /* extra exceptions */
358 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_UNAVAIL
];
361 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_DATA
];
364 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SPE_FP_ROUND
];
367 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PERFORMANCE_MONITOR
];
369 #ifdef CONFIG_KVM_BOOKE_HV
371 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL
];
374 *spr_val
= vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DBELL_CRIT
];
378 emulated
= kvmppc_booke_emulate_mfspr(vcpu
, sprn
, spr_val
);