blob: d48ae396f41e96ab9f27996fd16fe42046e3227c [file] [log] [blame]
Hollis Blanchardbc8080c2009-01-03 16:23:10 -06001/*
Scott Wood5ce941e2011-04-27 17:24:21 -05002 * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
Hollis Blanchardbc8080c2009-01-03 16:23:10 -06003 *
4 * Author: Yu Liu, <yu.liu@freescale.com>
5 *
6 * Description:
7 * This file is derived from arch/powerpc/kvm/44x_emulate.c,
8 * by Hollis Blanchard <hollisb@us.ibm.com>.
9 *
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.
13 */
14
15#include <asm/kvm_ppc.h>
16#include <asm/disassemble.h>
17#include <asm/kvm_e500.h>
18
19#include "booke.h"
20#include "e500_tlb.h"
21
22#define XOP_TLBIVAX 786
23#define XOP_TLBSX 914
24#define XOP_TLBRE 946
25#define XOP_TLBWE 978
26
27int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
28 unsigned int inst, int *advance)
29{
30 int emulated = EMULATE_DONE;
31 int ra;
32 int rb;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060033
34 switch (get_op(inst)) {
35 case 31:
36 switch (get_xop(inst)) {
37
38 case XOP_TLBRE:
39 emulated = kvmppc_e500_emul_tlbre(vcpu);
40 break;
41
42 case XOP_TLBWE:
43 emulated = kvmppc_e500_emul_tlbwe(vcpu);
44 break;
45
46 case XOP_TLBSX:
47 rb = get_rb(inst);
48 emulated = kvmppc_e500_emul_tlbsx(vcpu,rb);
49 break;
50
51 case XOP_TLBIVAX:
52 ra = get_ra(inst);
53 rb = get_rb(inst);
54 emulated = kvmppc_e500_emul_tlbivax(vcpu, ra, rb);
55 break;
56
57 default:
58 emulated = EMULATE_FAIL;
59 }
60
61 break;
62
63 default:
64 emulated = EMULATE_FAIL;
65 }
66
67 if (emulated == EMULATE_FAIL)
68 emulated = kvmppc_booke_emulate_op(run, vcpu, inst, advance);
69
70 return emulated;
71}
72
73int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
74{
75 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
76 int emulated = EMULATE_DONE;
Alexander Graf8e5b26b2010-01-08 02:58:01 +010077 ulong spr_val = kvmppc_get_gpr(vcpu, rs);
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060078
79 switch (sprn) {
80 case SPRN_PID:
Scott Wood5ce941e2011-04-27 17:24:21 -050081 kvmppc_set_pid(vcpu, spr_val);
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060082 break;
83 case SPRN_PID1:
Liu Yudd9ebf1f2011-06-14 18:35:14 -050084 if (spr_val != 0)
85 return EMULATE_FAIL;
Alexander Graf8e5b26b2010-01-08 02:58:01 +010086 vcpu_e500->pid[1] = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060087 case SPRN_PID2:
Liu Yudd9ebf1f2011-06-14 18:35:14 -050088 if (spr_val != 0)
89 return EMULATE_FAIL;
Alexander Graf8e5b26b2010-01-08 02:58:01 +010090 vcpu_e500->pid[2] = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060091 case SPRN_MAS0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +010092 vcpu_e500->mas0 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060093 case SPRN_MAS1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +010094 vcpu_e500->mas1 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060095 case SPRN_MAS2:
Alexander Graf8e5b26b2010-01-08 02:58:01 +010096 vcpu_e500->mas2 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060097 case SPRN_MAS3:
Alexander Graf8e5b26b2010-01-08 02:58:01 +010098 vcpu_e500->mas3 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060099 case SPRN_MAS4:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100100 vcpu_e500->mas4 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600101 case SPRN_MAS6:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100102 vcpu_e500->mas6 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600103 case SPRN_MAS7:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100104 vcpu_e500->mas7 = spr_val; break;
Liu Yud86be072010-01-22 18:50:29 +0800105 case SPRN_L1CSR0:
106 vcpu_e500->l1csr0 = spr_val;
107 vcpu_e500->l1csr0 &= ~(L1CSR0_DCFI | L1CSR0_CLFC);
108 break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600109 case SPRN_L1CSR1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100110 vcpu_e500->l1csr1 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600111 case SPRN_HID0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100112 vcpu_e500->hid0 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600113 case SPRN_HID1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100114 vcpu_e500->hid1 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600115
Liu Yub0a18352009-02-17 16:52:08 +0800116 case SPRN_MMUCSR0:
117 emulated = kvmppc_e500_emul_mt_mmucsr0(vcpu_e500,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100118 spr_val);
Liu Yub0a18352009-02-17 16:52:08 +0800119 break;
120
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600121 /* extra exceptions */
122 case SPRN_IVOR32:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100123 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL] = spr_val;
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600124 break;
125 case SPRN_IVOR33:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100126 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA] = spr_val;
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600127 break;
128 case SPRN_IVOR34:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100129 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND] = spr_val;
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600130 break;
131 case SPRN_IVOR35:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100132 vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR] = spr_val;
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600133 break;
134
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600135 default:
136 emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, rs);
137 }
138
139 return emulated;
140}
141
142int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
143{
144 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
145 int emulated = EMULATE_DONE;
146
147 switch (sprn) {
148 case SPRN_PID:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100149 kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[0]); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600150 case SPRN_PID1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100151 kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[1]); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600152 case SPRN_PID2:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100153 kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[2]); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600154 case SPRN_MAS0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100155 kvmppc_set_gpr(vcpu, rt, vcpu_e500->mas0); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600156 case SPRN_MAS1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100157 kvmppc_set_gpr(vcpu, rt, vcpu_e500->mas1); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600158 case SPRN_MAS2:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100159 kvmppc_set_gpr(vcpu, rt, vcpu_e500->mas2); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600160 case SPRN_MAS3:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100161 kvmppc_set_gpr(vcpu, rt, vcpu_e500->mas3); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600162 case SPRN_MAS4:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100163 kvmppc_set_gpr(vcpu, rt, vcpu_e500->mas4); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600164 case SPRN_MAS6:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100165 kvmppc_set_gpr(vcpu, rt, vcpu_e500->mas6); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600166 case SPRN_MAS7:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100167 kvmppc_set_gpr(vcpu, rt, vcpu_e500->mas7); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600168
169 case SPRN_TLB0CFG:
Liu Yuda15bf42010-01-22 19:36:53 +0800170 kvmppc_set_gpr(vcpu, rt, vcpu_e500->tlb0cfg); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600171 case SPRN_TLB1CFG:
Liu Yuda15bf42010-01-22 19:36:53 +0800172 kvmppc_set_gpr(vcpu, rt, vcpu_e500->tlb1cfg); break;
Liu Yud86be072010-01-22 18:50:29 +0800173 case SPRN_L1CSR0:
174 kvmppc_set_gpr(vcpu, rt, vcpu_e500->l1csr0); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600175 case SPRN_L1CSR1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100176 kvmppc_set_gpr(vcpu, rt, vcpu_e500->l1csr1); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600177 case SPRN_HID0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100178 kvmppc_set_gpr(vcpu, rt, vcpu_e500->hid0); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600179 case SPRN_HID1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100180 kvmppc_set_gpr(vcpu, rt, vcpu_e500->hid1); break;
Scott Wood90d34b02011-03-29 16:49:10 -0500181 case SPRN_SVR:
182 kvmppc_set_gpr(vcpu, rt, vcpu_e500->svr); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600183
Liu Yub0a18352009-02-17 16:52:08 +0800184 case SPRN_MMUCSR0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100185 kvmppc_set_gpr(vcpu, rt, 0); break;
Liu Yub0a18352009-02-17 16:52:08 +0800186
Liu Yu06579dd2009-06-05 14:54:31 +0800187 case SPRN_MMUCFG:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100188 kvmppc_set_gpr(vcpu, rt, mfspr(SPRN_MMUCFG)); break;
Liu Yu06579dd2009-06-05 14:54:31 +0800189
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600190 /* extra exceptions */
191 case SPRN_IVOR32:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100192 kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL]);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600193 break;
194 case SPRN_IVOR33:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100195 kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA]);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600196 break;
197 case SPRN_IVOR34:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100198 kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND]);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600199 break;
200 case SPRN_IVOR35:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100201 kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR]);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600202 break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600203 default:
204 emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, rt);
205 }
206
207 return emulated;
208}
209