2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 * Copyright IBM Corp. 2008
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
20 #include <asm/kvm_ppc.h>
22 #include <asm/dcr-regs.h>
23 #include <asm/disassemble.h>
24 #include <asm/kvm_44x.h>
30 #define XOP_MFDCRX 259
32 #define XOP_MTDCRX 387
38 static int emulate_mtdcr(struct kvm_vcpu
*vcpu
, int rs
, int dcrn
)
40 /* emulate some access in kernel */
42 case DCRN_CPR0_CONFIG_ADDR
:
43 vcpu
->arch
.cpr0_cfgaddr
= kvmppc_get_gpr(vcpu
, rs
);
46 vcpu
->run
->dcr
.dcrn
= dcrn
;
47 vcpu
->run
->dcr
.data
= kvmppc_get_gpr(vcpu
, rs
);
48 vcpu
->run
->dcr
.is_write
= 1;
49 vcpu
->arch
.dcr_is_write
= 1;
50 vcpu
->arch
.dcr_needed
= 1;
51 kvmppc_account_exit(vcpu
, DCR_EXITS
);
52 return EMULATE_DO_DCR
;
56 static int emulate_mfdcr(struct kvm_vcpu
*vcpu
, int rt
, int dcrn
)
58 /* The guest may access CPR0 registers to determine the timebase
59 * frequency, and it must know the real host frequency because it
60 * can directly access the timebase registers.
62 * It would be possible to emulate those accesses in userspace,
63 * but userspace can really only figure out the end frequency.
64 * We could decompose that into the factors that compute it, but
65 * that's tricky math, and it's easier to just report the real
69 case DCRN_CPR0_CONFIG_ADDR
:
70 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.cpr0_cfgaddr
);
72 case DCRN_CPR0_CONFIG_DATA
:
74 mtdcr(DCRN_CPR0_CONFIG_ADDR
,
75 vcpu
->arch
.cpr0_cfgaddr
);
76 kvmppc_set_gpr(vcpu
, rt
,
77 mfdcr(DCRN_CPR0_CONFIG_DATA
));
81 vcpu
->run
->dcr
.dcrn
= dcrn
;
82 vcpu
->run
->dcr
.data
= 0;
83 vcpu
->run
->dcr
.is_write
= 0;
84 vcpu
->arch
.dcr_is_write
= 0;
85 vcpu
->arch
.io_gpr
= rt
;
86 vcpu
->arch
.dcr_needed
= 1;
87 kvmppc_account_exit(vcpu
, DCR_EXITS
);
88 return EMULATE_DO_DCR
;
94 int kvmppc_core_emulate_op_44x(struct kvm_run
*run
, struct kvm_vcpu
*vcpu
,
95 unsigned int inst
, int *advance
)
97 int emulated
= EMULATE_DONE
;
98 int dcrn
= get_dcrn(inst
);
99 int ra
= get_ra(inst
);
100 int rb
= get_rb(inst
);
101 int rc
= get_rc(inst
);
102 int rs
= get_rs(inst
);
103 int rt
= get_rt(inst
);
104 int ws
= get_ws(inst
);
106 switch (get_op(inst
)) {
108 switch (get_xop(inst
)) {
111 emulated
= emulate_mfdcr(vcpu
, rt
, dcrn
);
115 emulated
= emulate_mfdcr(vcpu
, rt
,
116 kvmppc_get_gpr(vcpu
, ra
));
120 emulated
= emulate_mtdcr(vcpu
, rs
, dcrn
);
124 emulated
= emulate_mtdcr(vcpu
, rs
,
125 kvmppc_get_gpr(vcpu
, ra
));
129 emulated
= kvmppc_44x_emul_tlbwe(vcpu
, ra
, rs
, ws
);
133 emulated
= kvmppc_44x_emul_tlbsx(vcpu
, rt
, ra
, rb
, rc
);
140 emulated
= EMULATE_FAIL
;
146 emulated
= EMULATE_FAIL
;
149 if (emulated
== EMULATE_FAIL
)
150 emulated
= kvmppc_booke_emulate_op(run
, vcpu
, inst
, advance
);
155 int kvmppc_core_emulate_mtspr_44x(struct kvm_vcpu
*vcpu
, int sprn
, ulong spr_val
)
157 int emulated
= EMULATE_DONE
;
161 kvmppc_set_pid(vcpu
, spr_val
); break;
163 vcpu
->arch
.mmucr
= spr_val
; break;
165 vcpu
->arch
.ccr0
= spr_val
; break;
167 vcpu
->arch
.ccr1
= spr_val
; break;
169 emulated
= kvmppc_booke_emulate_mtspr(vcpu
, sprn
, spr_val
);
175 int kvmppc_core_emulate_mfspr_44x(struct kvm_vcpu
*vcpu
, int sprn
, ulong
*spr_val
)
177 int emulated
= EMULATE_DONE
;
181 *spr_val
= vcpu
->arch
.pid
; break;
183 *spr_val
= vcpu
->arch
.mmucr
; break;
185 *spr_val
= vcpu
->arch
.ccr0
; break;
187 *spr_val
= vcpu
->arch
.ccr1
; break;
189 emulated
= kvmppc_booke_emulate_mfspr(vcpu
, sprn
, spr_val
);