blob: d49dc66ab3c38a4095e5eae0324a87511172ee25 [file] [log] [blame]
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001/*
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.
5 *
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.
10 *
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.
14 *
15 * Copyright IBM Corp. 2007
16 *
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18 */
19
20#include <linux/types.h>
21#include <linux/string.h>
Jerone Young31711f22008-07-14 14:00:03 +020022#include <linux/kvm.h>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050023#include <linux/kvm_host.h>
24#include <linux/highmem.h>
25#include <asm/mmu-44x.h>
26#include <asm/kvm_ppc.h>
Hollis Blancharddb93f572008-11-05 09:36:18 -060027#include <asm/kvm_44x.h>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050028
29#include "44x_tlb.h"
30
Hollis Blanchard89168612008-12-02 15:51:53 -060031#ifndef PPC44x_TLBE_SIZE
32#define PPC44x_TLBE_SIZE PPC44x_TLB_4K
33#endif
34
35#define PAGE_SIZE_4K (1<<12)
36#define PAGE_MASK_4K (~(PAGE_SIZE_4K - 1))
37
Hollis Blancharddf9b8562008-11-10 14:57:35 -060038#define PPC44x_TLB_UATTR_MASK \
39 (PPC44x_TLB_U0|PPC44x_TLB_U1|PPC44x_TLB_U2|PPC44x_TLB_U3)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050040#define PPC44x_TLB_USER_PERM_MASK (PPC44x_TLB_UX|PPC44x_TLB_UR|PPC44x_TLB_UW)
41#define PPC44x_TLB_SUPER_PERM_MASK (PPC44x_TLB_SX|PPC44x_TLB_SR|PPC44x_TLB_SW)
42
43static unsigned int kvmppc_tlb_44x_pos;
44
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -060045#ifdef DEBUG
46void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
47{
48 struct kvmppc_44x_tlbe *tlbe;
49 int i;
50
51 printk("vcpu %d TLB dump:\n", vcpu->vcpu_id);
52 printk("| %2s | %3s | %8s | %8s | %8s |\n",
53 "nr", "tid", "word0", "word1", "word2");
54
55 for (i = 0; i < PPC44x_TLB_SIZE; i++) {
Hollis Blancharddb93f572008-11-05 09:36:18 -060056 tlbe = &vcpu_44x->guest_tlb[i];
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -060057 if (tlbe->word0 & PPC44x_TLB_VALID)
58 printk(" G%2d | %02X | %08X | %08X | %08X |\n",
59 i, tlbe->tid, tlbe->word0, tlbe->word1,
60 tlbe->word2);
61 }
62
63 for (i = 0; i < PPC44x_TLB_SIZE; i++) {
Hollis Blancharddb93f572008-11-05 09:36:18 -060064 tlbe = &vcpu_44x->shadow_tlb[i];
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -060065 if (tlbe->word0 & PPC44x_TLB_VALID)
66 printk(" S%2d | %02X | %08X | %08X | %08X |\n",
67 i, tlbe->tid, tlbe->word0, tlbe->word1,
68 tlbe->word2);
69 }
70}
71#endif
72
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050073static u32 kvmppc_44x_tlb_shadow_attrib(u32 attrib, int usermode)
74{
Hollis Blancharddf9b8562008-11-10 14:57:35 -060075 /* We only care about the guest's permission and user bits. */
76 attrib &= PPC44x_TLB_PERM_MASK|PPC44x_TLB_UATTR_MASK;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050077
78 if (!usermode) {
79 /* Guest is in supervisor mode, so we need to translate guest
80 * supervisor permissions into user permissions. */
81 attrib &= ~PPC44x_TLB_USER_PERM_MASK;
82 attrib |= (attrib & PPC44x_TLB_SUPER_PERM_MASK) << 3;
83 }
84
85 /* Make sure host can always access this memory. */
86 attrib |= PPC44x_TLB_SX|PPC44x_TLB_SR|PPC44x_TLB_SW;
87
Hollis Blancharddf9b8562008-11-10 14:57:35 -060088 /* WIMGE = 0b00100 */
89 attrib |= PPC44x_TLB_M;
90
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050091 return attrib;
92}
93
94/* Search the guest TLB for a matching entry. */
95int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr, unsigned int pid,
96 unsigned int as)
97{
Hollis Blancharddb93f572008-11-05 09:36:18 -060098 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050099 int i;
100
101 /* XXX Replace loop with fancy data structures. */
102 for (i = 0; i < PPC44x_TLB_SIZE; i++) {
Hollis Blancharddb93f572008-11-05 09:36:18 -0600103 struct kvmppc_44x_tlbe *tlbe = &vcpu_44x->guest_tlb[i];
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500104 unsigned int tid;
105
106 if (eaddr < get_tlb_eaddr(tlbe))
107 continue;
108
109 if (eaddr > get_tlb_end(tlbe))
110 continue;
111
112 tid = get_tlb_tid(tlbe);
113 if (tid && (tid != pid))
114 continue;
115
116 if (!get_tlb_v(tlbe))
117 continue;
118
119 if (get_tlb_ts(tlbe) != as)
120 continue;
121
122 return i;
123 }
124
125 return -1;
126}
127
Hollis Blanchard0f55dc42008-11-05 09:36:12 -0600128struct kvmppc_44x_tlbe *kvmppc_44x_itlb_search(struct kvm_vcpu *vcpu,
129 gva_t eaddr)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500130{
Hollis Blancharddb93f572008-11-05 09:36:18 -0600131 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500132 unsigned int as = !!(vcpu->arch.msr & MSR_IS);
133 unsigned int index;
134
135 index = kvmppc_44x_tlb_index(vcpu, eaddr, vcpu->arch.pid, as);
136 if (index == -1)
137 return NULL;
Hollis Blancharddb93f572008-11-05 09:36:18 -0600138 return &vcpu_44x->guest_tlb[index];
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500139}
140
Hollis Blanchard0f55dc42008-11-05 09:36:12 -0600141struct kvmppc_44x_tlbe *kvmppc_44x_dtlb_search(struct kvm_vcpu *vcpu,
142 gva_t eaddr)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500143{
Hollis Blancharddb93f572008-11-05 09:36:18 -0600144 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500145 unsigned int as = !!(vcpu->arch.msr & MSR_DS);
146 unsigned int index;
147
148 index = kvmppc_44x_tlb_index(vcpu, eaddr, vcpu->arch.pid, as);
149 if (index == -1)
150 return NULL;
Hollis Blancharddb93f572008-11-05 09:36:18 -0600151 return &vcpu_44x->guest_tlb[index];
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500152}
153
Hollis Blanchard0f55dc42008-11-05 09:36:12 -0600154static int kvmppc_44x_tlbe_is_writable(struct kvmppc_44x_tlbe *tlbe)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500155{
156 return tlbe->word2 & (PPC44x_TLB_SW|PPC44x_TLB_UW);
157}
158
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500159static void kvmppc_44x_shadow_release(struct kvm_vcpu *vcpu,
160 unsigned int index)
161{
Hollis Blancharddb93f572008-11-05 09:36:18 -0600162 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
163 struct kvmppc_44x_tlbe *stlbe = &vcpu_44x->shadow_tlb[index];
164 struct page *page = vcpu_44x->shadow_pages[index];
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500165
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500166 if (get_tlb_v(stlbe)) {
167 if (kvmppc_44x_tlbe_is_writable(stlbe))
168 kvm_release_page_dirty(page);
169 else
170 kvm_release_page_clean(page);
171 }
172}
173
Hollis Blanchardc30f8a62008-11-24 11:37:38 -0600174void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu)
175{
176 int i;
177
178 for (i = 0; i <= tlb_44x_hwater; i++)
179 kvmppc_44x_shadow_release(vcpu, i);
180}
181
Hollis Blanchard83aae4a2008-07-25 13:54:52 -0500182void kvmppc_tlbe_set_modified(struct kvm_vcpu *vcpu, unsigned int i)
183{
Hollis Blancharddb93f572008-11-05 09:36:18 -0600184 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
185
186 vcpu_44x->shadow_tlb_mod[i] = 1;
Hollis Blanchard83aae4a2008-07-25 13:54:52 -0500187}
188
Hollis Blanchard89168612008-12-02 15:51:53 -0600189/**
190 * kvmppc_mmu_map -- create a host mapping for guest memory
191 *
192 * If the guest wanted a larger page than the host supports, only the first
193 * host page is mapped here and the rest are demand faulted.
194 *
195 * If the guest wanted a smaller page than the host page size, we map only the
196 * guest-size page (i.e. not a full host page mapping).
197 *
198 * Caller must ensure that the specified guest TLB entry is safe to insert into
199 * the shadow TLB.
200 */
201void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr, u64 asid,
202 u32 flags, u32 max_bytes)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500203{
Hollis Blancharddb93f572008-11-05 09:36:18 -0600204 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500205 struct page *new_page;
Hollis Blanchard0f55dc42008-11-05 09:36:12 -0600206 struct kvmppc_44x_tlbe *stlbe;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500207 hpa_t hpaddr;
Hollis Blanchard89168612008-12-02 15:51:53 -0600208 gfn_t gfn;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500209 unsigned int victim;
210
211 /* Future optimization: don't overwrite the TLB entry containing the
212 * current PC (or stack?). */
213 victim = kvmppc_tlb_44x_pos++;
214 if (kvmppc_tlb_44x_pos > tlb_44x_hwater)
215 kvmppc_tlb_44x_pos = 0;
Hollis Blancharddb93f572008-11-05 09:36:18 -0600216 stlbe = &vcpu_44x->shadow_tlb[victim];
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500217
218 /* Get reference to new page. */
Hollis Blanchard89168612008-12-02 15:51:53 -0600219 gfn = gpaddr >> PAGE_SHIFT;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500220 new_page = gfn_to_page(vcpu->kvm, gfn);
221 if (is_error_page(new_page)) {
Hollis Blanchard9dcb40e2008-05-21 18:22:55 -0500222 printk(KERN_ERR "Couldn't get guest page for gfn %lx!\n", gfn);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500223 kvm_release_page_clean(new_page);
224 return;
225 }
226 hpaddr = page_to_phys(new_page);
227
228 /* Drop reference to old page. */
229 kvmppc_44x_shadow_release(vcpu, victim);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500230
Hollis Blancharddb93f572008-11-05 09:36:18 -0600231 vcpu_44x->shadow_pages[victim] = new_page;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500232
233 /* XXX Make sure (va, size) doesn't overlap any other
234 * entries. 440x6 user manual says the result would be
235 * "undefined." */
236
237 /* XXX what about AS? */
238
Hollis Blanchard49dd2c42008-07-25 13:54:53 -0500239 stlbe->tid = !(asid & 0xff);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500240
241 /* Force TS=1 for all guest mappings. */
Hollis Blanchard89168612008-12-02 15:51:53 -0600242 stlbe->word0 = PPC44x_TLB_VALID | PPC44x_TLB_TS;
243
244 if (max_bytes >= PAGE_SIZE) {
245 /* Guest mapping is larger than or equal to host page size. We can use
246 * a "native" host mapping. */
247 stlbe->word0 |= (gvaddr & PAGE_MASK) | PPC44x_TLBE_SIZE;
248 } else {
249 /* Guest mapping is smaller than host page size. We must restrict the
250 * size of the mapping to be at most the smaller of the two, but for
251 * simplicity we fall back to a 4K mapping (this is probably what the
252 * guest is using anyways). */
253 stlbe->word0 |= (gvaddr & PAGE_MASK_4K) | PPC44x_TLB_4K;
254
255 /* 'hpaddr' is a host page, which is larger than the mapping we're
256 * inserting here. To compensate, we must add the in-page offset to the
257 * sub-page. */
258 hpaddr |= gpaddr & (PAGE_MASK ^ PAGE_MASK_4K);
259 }
260
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500261 stlbe->word1 = (hpaddr & 0xfffffc00) | ((hpaddr >> 32) & 0xf);
262 stlbe->word2 = kvmppc_44x_tlb_shadow_attrib(flags,
263 vcpu->arch.msr & MSR_PR);
Hollis Blanchard83aae4a2008-07-25 13:54:52 -0500264 kvmppc_tlbe_set_modified(vcpu, victim);
Jerone Young31711f22008-07-14 14:00:03 +0200265
266 KVMTRACE_5D(STLB_WRITE, vcpu, victim,
267 stlbe->tid, stlbe->word0, stlbe->word1, stlbe->word2,
268 handler);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500269}
270
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600271static void kvmppc_mmu_invalidate(struct kvm_vcpu *vcpu, gva_t eaddr,
272 gva_t eend, u32 asid)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500273{
Hollis Blancharddb93f572008-11-05 09:36:18 -0600274 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
Hollis Blanchard49dd2c42008-07-25 13:54:53 -0500275 unsigned int pid = !(asid & 0xff);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500276 int i;
277
278 /* XXX Replace loop with fancy data structures. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500279 for (i = 0; i <= tlb_44x_hwater; i++) {
Hollis Blancharddb93f572008-11-05 09:36:18 -0600280 struct kvmppc_44x_tlbe *stlbe = &vcpu_44x->shadow_tlb[i];
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500281 unsigned int tid;
282
283 if (!get_tlb_v(stlbe))
284 continue;
285
Hollis Blanchardcc044542008-07-25 13:54:50 -0500286 if (eend < get_tlb_eaddr(stlbe))
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500287 continue;
288
289 if (eaddr > get_tlb_end(stlbe))
290 continue;
291
292 tid = get_tlb_tid(stlbe);
293 if (tid && (tid != pid))
294 continue;
295
296 kvmppc_44x_shadow_release(vcpu, i);
297 stlbe->word0 = 0;
Hollis Blanchard83aae4a2008-07-25 13:54:52 -0500298 kvmppc_tlbe_set_modified(vcpu, i);
Jerone Young31711f22008-07-14 14:00:03 +0200299 KVMTRACE_5D(STLB_INVAL, vcpu, i,
300 stlbe->tid, stlbe->word0, stlbe->word1,
301 stlbe->word2, handler);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500302 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500303}
304
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500305void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode)
306{
Hollis Blanchardfe4e7712008-11-10 14:57:36 -0600307 vcpu->arch.shadow_pid = !usermode;
308}
309
310void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 new_pid)
311{
Hollis Blancharddb93f572008-11-05 09:36:18 -0600312 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500313 int i;
314
Hollis Blanchardfe4e7712008-11-10 14:57:36 -0600315 if (unlikely(vcpu->arch.pid == new_pid))
316 return;
Jerone Young31711f22008-07-14 14:00:03 +0200317
Hollis Blanchardfe4e7712008-11-10 14:57:36 -0600318 vcpu->arch.pid = new_pid;
319
320 /* Guest userspace runs with TID=0 mappings and PID=0, to make sure it
321 * can't access guest kernel mappings (TID=1). When we switch to a new
322 * guest PID, which will also use host PID=0, we must discard the old guest
323 * userspace mappings. */
324 for (i = 0; i < ARRAY_SIZE(vcpu_44x->shadow_tlb); i++) {
325 struct kvmppc_44x_tlbe *stlbe = &vcpu_44x->shadow_tlb[i];
326
327 if (get_tlb_tid(stlbe) == 0) {
Hollis Blanchard49dd2c42008-07-25 13:54:53 -0500328 kvmppc_44x_shadow_release(vcpu, i);
329 stlbe->word0 = 0;
330 kvmppc_tlbe_set_modified(vcpu, i);
Hollis Blanchard49dd2c42008-07-25 13:54:53 -0500331 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500332 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500333}
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600334
335static int tlbe_is_host_safe(const struct kvm_vcpu *vcpu,
Hollis Blanchard0f55dc42008-11-05 09:36:12 -0600336 const struct kvmppc_44x_tlbe *tlbe)
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600337{
338 gpa_t gpa;
339
340 if (!get_tlb_v(tlbe))
341 return 0;
342
343 /* Does it match current guest AS? */
344 /* XXX what about IS != DS? */
345 if (get_tlb_ts(tlbe) != !!(vcpu->arch.msr & MSR_IS))
346 return 0;
347
348 gpa = get_tlb_raddr(tlbe);
349 if (!gfn_to_memslot(vcpu->kvm, gpa >> PAGE_SHIFT))
350 /* Mapping is not for RAM. */
351 return 0;
352
353 return 1;
354}
355
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600356int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws)
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600357{
Hollis Blancharddb93f572008-11-05 09:36:18 -0600358 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
Hollis Blanchard89168612008-12-02 15:51:53 -0600359 gva_t eaddr;
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600360 u64 asid;
Hollis Blanchard0f55dc42008-11-05 09:36:12 -0600361 struct kvmppc_44x_tlbe *tlbe;
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600362 unsigned int index;
363
364 index = vcpu->arch.gpr[ra];
365 if (index > PPC44x_TLB_SIZE) {
366 printk("%s: index %d\n", __func__, index);
367 kvmppc_dump_vcpu(vcpu);
368 return EMULATE_FAIL;
369 }
370
Hollis Blancharddb93f572008-11-05 09:36:18 -0600371 tlbe = &vcpu_44x->guest_tlb[index];
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600372
373 /* Invalidate shadow mappings for the about-to-be-clobbered TLBE. */
374 if (tlbe->word0 & PPC44x_TLB_VALID) {
375 eaddr = get_tlb_eaddr(tlbe);
376 asid = (tlbe->word0 & PPC44x_TLB_TS) | tlbe->tid;
377 kvmppc_mmu_invalidate(vcpu, eaddr, get_tlb_end(tlbe), asid);
378 }
379
380 switch (ws) {
381 case PPC44x_TLB_PAGEID:
Hollis Blanchardbf5d4022008-11-10 14:57:34 -0600382 tlbe->tid = get_mmucr_stid(vcpu);
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600383 tlbe->word0 = vcpu->arch.gpr[rs];
384 break;
385
386 case PPC44x_TLB_XLAT:
387 tlbe->word1 = vcpu->arch.gpr[rs];
388 break;
389
390 case PPC44x_TLB_ATTRIB:
391 tlbe->word2 = vcpu->arch.gpr[rs];
392 break;
393
394 default:
395 return EMULATE_FAIL;
396 }
397
398 if (tlbe_is_host_safe(vcpu, tlbe)) {
Hollis Blanchard89168612008-12-02 15:51:53 -0600399 gpa_t gpaddr;
400 u32 flags;
401 u32 bytes;
402
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600403 eaddr = get_tlb_eaddr(tlbe);
Hollis Blanchard89168612008-12-02 15:51:53 -0600404 gpaddr = get_tlb_raddr(tlbe);
405
406 /* Use the advertised page size to mask effective and real addrs. */
407 bytes = get_tlb_bytes(tlbe);
408 eaddr &= ~(bytes - 1);
409 gpaddr &= ~(bytes - 1);
410
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600411 asid = (tlbe->word0 & PPC44x_TLB_TS) | tlbe->tid;
412 flags = tlbe->word2 & 0xffff;
413
Hollis Blanchard89168612008-12-02 15:51:53 -0600414 kvmppc_mmu_map(vcpu, eaddr, gpaddr, asid, flags, bytes);
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600415 }
416
417 KVMTRACE_5D(GTLB_WRITE, vcpu, index,
418 tlbe->tid, tlbe->word0, tlbe->word1, tlbe->word2,
419 handler);
420
421 return EMULATE_DONE;
422}
423
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600424int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb, u8 rc)
Hollis Blancharda0d7b9f2008-11-05 09:36:11 -0600425{
426 u32 ea;
427 int index;
428 unsigned int as = get_mmucr_sts(vcpu);
429 unsigned int pid = get_mmucr_stid(vcpu);
430
431 ea = vcpu->arch.gpr[rb];
432 if (ra)
433 ea += vcpu->arch.gpr[ra];
434
435 index = kvmppc_44x_tlb_index(vcpu, ea, pid, as);
436 if (rc) {
437 if (index < 0)
438 vcpu->arch.cr &= ~0x20000000;
439 else
440 vcpu->arch.cr |= 0x20000000;
441 }
442 vcpu->arch.gpr[rt] = index;
443
444 return EMULATE_DONE;
445}