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>
36 int kvmppc_core_emulate_op(struct kvm_run
*run
, struct kvm_vcpu
*vcpu
,
37 unsigned int inst
, int *advance
)
39 int emulated
= EMULATE_DONE
;
48 switch (get_op(inst
)) {
50 switch (get_xop(inst
)) {
53 dcrn
= get_dcrn(inst
);
56 /* The guest may access CPR0 registers to determine the timebase
57 * frequency, and it must know the real host frequency because it
58 * can directly access the timebase registers.
60 * It would be possible to emulate those accesses in userspace,
61 * but userspace can really only figure out the end frequency.
62 * We could decompose that into the factors that compute it, but
63 * that's tricky math, and it's easier to just report the real
67 case DCRN_CPR0_CONFIG_ADDR
:
68 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.cpr0_cfgaddr
);
70 case DCRN_CPR0_CONFIG_DATA
:
72 mtdcr(DCRN_CPR0_CONFIG_ADDR
,
73 vcpu
->arch
.cpr0_cfgaddr
);
74 kvmppc_set_gpr(vcpu
, rt
,
75 mfdcr(DCRN_CPR0_CONFIG_DATA
));
81 run
->dcr
.is_write
= 0;
82 vcpu
->arch
.io_gpr
= rt
;
83 vcpu
->arch
.dcr_needed
= 1;
84 kvmppc_account_exit(vcpu
, DCR_EXITS
);
85 emulated
= EMULATE_DO_DCR
;
91 dcrn
= get_dcrn(inst
);
94 /* emulate some access in kernel */
96 case DCRN_CPR0_CONFIG_ADDR
:
97 vcpu
->arch
.cpr0_cfgaddr
= kvmppc_get_gpr(vcpu
, rs
);
100 run
->dcr
.dcrn
= dcrn
;
101 run
->dcr
.data
= kvmppc_get_gpr(vcpu
, rs
);
102 run
->dcr
.is_write
= 1;
103 vcpu
->arch
.dcr_needed
= 1;
104 kvmppc_account_exit(vcpu
, DCR_EXITS
);
105 emulated
= EMULATE_DO_DCR
;
114 emulated
= kvmppc_44x_emul_tlbwe(vcpu
, ra
, rs
, ws
);
122 emulated
= kvmppc_44x_emul_tlbsx(vcpu
, rt
, ra
, rb
, rc
);
129 emulated
= EMULATE_FAIL
;
135 emulated
= EMULATE_FAIL
;
138 if (emulated
== EMULATE_FAIL
)
139 emulated
= kvmppc_booke_emulate_op(run
, vcpu
, inst
, advance
);
144 int kvmppc_core_emulate_mtspr(struct kvm_vcpu
*vcpu
, int sprn
, int rs
)
146 int emulated
= EMULATE_DONE
;
150 kvmppc_set_pid(vcpu
, kvmppc_get_gpr(vcpu
, rs
)); break;
152 vcpu
->arch
.mmucr
= kvmppc_get_gpr(vcpu
, rs
); break;
154 vcpu
->arch
.ccr0
= kvmppc_get_gpr(vcpu
, rs
); break;
156 vcpu
->arch
.ccr1
= kvmppc_get_gpr(vcpu
, rs
); break;
158 emulated
= kvmppc_booke_emulate_mtspr(vcpu
, sprn
, rs
);
161 kvmppc_set_exit_type(vcpu
, EMULATED_MTSPR_EXITS
);
165 int kvmppc_core_emulate_mfspr(struct kvm_vcpu
*vcpu
, int sprn
, int rt
)
167 int emulated
= EMULATE_DONE
;
171 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.pid
); break;
173 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.mmucr
); break;
175 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ccr0
); break;
177 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ccr1
); break;
179 emulated
= kvmppc_booke_emulate_mfspr(vcpu
, sprn
, rt
);
182 kvmppc_set_exit_type(vcpu
, EMULATED_MFSPR_EXITS
);