]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/powerpc/kvm/booke_guest.c
41bbf4c78f88d8cc5f065dcdc54eb2c17a59c4a0
[linux-2.6.git] / arch / powerpc / kvm / booke_guest.c
1 /*
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  *          Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
19  */
20
21 #include <linux/errno.h>
22 #include <linux/err.h>
23 #include <linux/kvm_host.h>
24 #include <linux/module.h>
25 #include <linux/vmalloc.h>
26 #include <linux/fs.h>
27 #include <asm/cputable.h>
28 #include <asm/uaccess.h>
29 #include <asm/kvm_ppc.h>
30
31 #include "44x_tlb.h"
32
33 #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
34 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
35
36 struct kvm_stats_debugfs_item debugfs_entries[] = {
37         { "exits",      VCPU_STAT(sum_exits) },
38         { "mmio",       VCPU_STAT(mmio_exits) },
39         { "dcr",        VCPU_STAT(dcr_exits) },
40         { "sig",        VCPU_STAT(signal_exits) },
41         { "light",      VCPU_STAT(light_exits) },
42         { "itlb_r",     VCPU_STAT(itlb_real_miss_exits) },
43         { "itlb_v",     VCPU_STAT(itlb_virt_miss_exits) },
44         { "dtlb_r",     VCPU_STAT(dtlb_real_miss_exits) },
45         { "dtlb_v",     VCPU_STAT(dtlb_virt_miss_exits) },
46         { "sysc",       VCPU_STAT(syscall_exits) },
47         { "isi",        VCPU_STAT(isi_exits) },
48         { "dsi",        VCPU_STAT(dsi_exits) },
49         { "inst_emu",   VCPU_STAT(emulated_inst_exits) },
50         { "dec",        VCPU_STAT(dec_exits) },
51         { "ext_intr",   VCPU_STAT(ext_intr_exits) },
52         { "halt_wakeup", VCPU_STAT(halt_wakeup) },
53         { NULL }
54 };
55
56 static const u32 interrupt_msr_mask[16] = {
57         [BOOKE_INTERRUPT_CRITICAL]      = MSR_ME,
58         [BOOKE_INTERRUPT_MACHINE_CHECK] = 0,
59         [BOOKE_INTERRUPT_DATA_STORAGE]  = MSR_CE|MSR_ME|MSR_DE,
60         [BOOKE_INTERRUPT_INST_STORAGE]  = MSR_CE|MSR_ME|MSR_DE,
61         [BOOKE_INTERRUPT_EXTERNAL]      = MSR_CE|MSR_ME|MSR_DE,
62         [BOOKE_INTERRUPT_ALIGNMENT]     = MSR_CE|MSR_ME|MSR_DE,
63         [BOOKE_INTERRUPT_PROGRAM]       = MSR_CE|MSR_ME|MSR_DE,
64         [BOOKE_INTERRUPT_FP_UNAVAIL]    = MSR_CE|MSR_ME|MSR_DE,
65         [BOOKE_INTERRUPT_SYSCALL]       = MSR_CE|MSR_ME|MSR_DE,
66         [BOOKE_INTERRUPT_AP_UNAVAIL]    = MSR_CE|MSR_ME|MSR_DE,
67         [BOOKE_INTERRUPT_DECREMENTER]   = MSR_CE|MSR_ME|MSR_DE,
68         [BOOKE_INTERRUPT_FIT]           = MSR_CE|MSR_ME|MSR_DE,
69         [BOOKE_INTERRUPT_WATCHDOG]      = MSR_ME,
70         [BOOKE_INTERRUPT_DTLB_MISS]     = MSR_CE|MSR_ME|MSR_DE,
71         [BOOKE_INTERRUPT_ITLB_MISS]     = MSR_CE|MSR_ME|MSR_DE,
72         [BOOKE_INTERRUPT_DEBUG]         = MSR_ME,
73 };
74
75 const unsigned char exception_priority[] = {
76         [BOOKE_INTERRUPT_DATA_STORAGE] = 0,
77         [BOOKE_INTERRUPT_INST_STORAGE] = 1,
78         [BOOKE_INTERRUPT_ALIGNMENT] = 2,
79         [BOOKE_INTERRUPT_PROGRAM] = 3,
80         [BOOKE_INTERRUPT_FP_UNAVAIL] = 4,
81         [BOOKE_INTERRUPT_SYSCALL] = 5,
82         [BOOKE_INTERRUPT_AP_UNAVAIL] = 6,
83         [BOOKE_INTERRUPT_DTLB_MISS] = 7,
84         [BOOKE_INTERRUPT_ITLB_MISS] = 8,
85         [BOOKE_INTERRUPT_MACHINE_CHECK] = 9,
86         [BOOKE_INTERRUPT_DEBUG] = 10,
87         [BOOKE_INTERRUPT_CRITICAL] = 11,
88         [BOOKE_INTERRUPT_WATCHDOG] = 12,
89         [BOOKE_INTERRUPT_EXTERNAL] = 13,
90         [BOOKE_INTERRUPT_FIT] = 14,
91         [BOOKE_INTERRUPT_DECREMENTER] = 15,
92 };
93
94 const unsigned char priority_exception[] = {
95         BOOKE_INTERRUPT_DATA_STORAGE,
96         BOOKE_INTERRUPT_INST_STORAGE,
97         BOOKE_INTERRUPT_ALIGNMENT,
98         BOOKE_INTERRUPT_PROGRAM,
99         BOOKE_INTERRUPT_FP_UNAVAIL,
100         BOOKE_INTERRUPT_SYSCALL,
101         BOOKE_INTERRUPT_AP_UNAVAIL,
102         BOOKE_INTERRUPT_DTLB_MISS,
103         BOOKE_INTERRUPT_ITLB_MISS,
104         BOOKE_INTERRUPT_MACHINE_CHECK,
105         BOOKE_INTERRUPT_DEBUG,
106         BOOKE_INTERRUPT_CRITICAL,
107         BOOKE_INTERRUPT_WATCHDOG,
108         BOOKE_INTERRUPT_EXTERNAL,
109         BOOKE_INTERRUPT_FIT,
110         BOOKE_INTERRUPT_DECREMENTER,
111 };
112
113
114 /* TODO: use vcpu_printf() */
115 void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu)
116 {
117         int i;
118
119         printk("pc:   %08x msr:  %08x\n", vcpu->arch.pc, vcpu->arch.msr);
120         printk("lr:   %08x ctr:  %08x\n", vcpu->arch.lr, vcpu->arch.ctr);
121         printk("srr0: %08x srr1: %08x\n", vcpu->arch.srr0, vcpu->arch.srr1);
122
123         printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions);
124
125         for (i = 0; i < 32; i += 4) {
126                 printk("gpr%02d: %08x %08x %08x %08x\n", i,
127                        vcpu->arch.gpr[i],
128                        vcpu->arch.gpr[i+1],
129                        vcpu->arch.gpr[i+2],
130                        vcpu->arch.gpr[i+3]);
131         }
132 }
133
134 /* Check if we are ready to deliver the interrupt */
135 static int kvmppc_can_deliver_interrupt(struct kvm_vcpu *vcpu, int interrupt)
136 {
137         int r;
138
139         switch (interrupt) {
140         case BOOKE_INTERRUPT_CRITICAL:
141                 r = vcpu->arch.msr & MSR_CE;
142                 break;
143         case BOOKE_INTERRUPT_MACHINE_CHECK:
144                 r = vcpu->arch.msr & MSR_ME;
145                 break;
146         case BOOKE_INTERRUPT_EXTERNAL:
147                 r = vcpu->arch.msr & MSR_EE;
148                 break;
149         case BOOKE_INTERRUPT_DECREMENTER:
150                 r = vcpu->arch.msr & MSR_EE;
151                 break;
152         case BOOKE_INTERRUPT_FIT:
153                 r = vcpu->arch.msr & MSR_EE;
154                 break;
155         case BOOKE_INTERRUPT_WATCHDOG:
156                 r = vcpu->arch.msr & MSR_CE;
157                 break;
158         case BOOKE_INTERRUPT_DEBUG:
159                 r = vcpu->arch.msr & MSR_DE;
160                 break;
161         default:
162                 r = 1;
163         }
164
165         return r;
166 }
167
168 static void kvmppc_deliver_interrupt(struct kvm_vcpu *vcpu, int interrupt)
169 {
170         switch (interrupt) {
171         case BOOKE_INTERRUPT_DECREMENTER:
172                 vcpu->arch.tsr |= TSR_DIS;
173                 break;
174         }
175
176         vcpu->arch.srr0 = vcpu->arch.pc;
177         vcpu->arch.srr1 = vcpu->arch.msr;
178         vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[interrupt];
179         kvmppc_set_msr(vcpu, vcpu->arch.msr & interrupt_msr_mask[interrupt]);
180 }
181
182 /* Check pending exceptions and deliver one, if possible. */
183 void kvmppc_check_and_deliver_interrupts(struct kvm_vcpu *vcpu)
184 {
185         unsigned long *pending = &vcpu->arch.pending_exceptions;
186         unsigned int exception;
187         unsigned int priority;
188
189         priority = find_first_bit(pending, BITS_PER_BYTE * sizeof(*pending));
190         while (priority <= BOOKE_MAX_INTERRUPT) {
191                 exception = priority_exception[priority];
192                 if (kvmppc_can_deliver_interrupt(vcpu, exception)) {
193                         kvmppc_clear_exception(vcpu, exception);
194                         kvmppc_deliver_interrupt(vcpu, exception);
195                         break;
196                 }
197
198                 priority = find_next_bit(pending,
199                                          BITS_PER_BYTE * sizeof(*pending),
200                                          priority + 1);
201         }
202 }
203
204 /**
205  * kvmppc_handle_exit
206  *
207  * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
208  */
209 int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
210                        unsigned int exit_nr)
211 {
212         enum emulation_result er;
213         int r = RESUME_HOST;
214
215         local_irq_enable();
216
217         run->exit_reason = KVM_EXIT_UNKNOWN;
218         run->ready_for_interrupt_injection = 1;
219
220         switch (exit_nr) {
221         case BOOKE_INTERRUPT_MACHINE_CHECK:
222                 printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR));
223                 kvmppc_dump_vcpu(vcpu);
224                 r = RESUME_HOST;
225                 break;
226
227         case BOOKE_INTERRUPT_EXTERNAL:
228         case BOOKE_INTERRUPT_DECREMENTER:
229                 /* Since we switched IVPR back to the host's value, the host
230                  * handled this interrupt the moment we enabled interrupts.
231                  * Now we just offer it a chance to reschedule the guest. */
232
233                 /* XXX At this point the TLB still holds our shadow TLB, so if
234                  * we do reschedule the host will fault over it. Perhaps we
235                  * should politely restore the host's entries to minimize
236                  * misses before ceding control. */
237                 if (need_resched())
238                         cond_resched();
239                 if (exit_nr == BOOKE_INTERRUPT_DECREMENTER)
240                         vcpu->stat.dec_exits++;
241                 else
242                         vcpu->stat.ext_intr_exits++;
243                 r = RESUME_GUEST;
244                 break;
245
246         case BOOKE_INTERRUPT_PROGRAM:
247                 if (vcpu->arch.msr & MSR_PR) {
248                         /* Program traps generated by user-level software must be handled
249                          * by the guest kernel. */
250                         vcpu->arch.esr = vcpu->arch.fault_esr;
251                         kvmppc_queue_exception(vcpu, BOOKE_INTERRUPT_PROGRAM);
252                         r = RESUME_GUEST;
253                         break;
254                 }
255
256                 er = kvmppc_emulate_instruction(run, vcpu);
257                 switch (er) {
258                 case EMULATE_DONE:
259                         /* Future optimization: only reload non-volatiles if
260                          * they were actually modified by emulation. */
261                         vcpu->stat.emulated_inst_exits++;
262                         r = RESUME_GUEST_NV;
263                         break;
264                 case EMULATE_DO_DCR:
265                         run->exit_reason = KVM_EXIT_DCR;
266                         r = RESUME_HOST;
267                         break;
268                 case EMULATE_FAIL:
269                         /* XXX Deliver Program interrupt to guest. */
270                         printk(KERN_CRIT "%s: emulation at %x failed (%08x)\n",
271                                __func__, vcpu->arch.pc, vcpu->arch.last_inst);
272                         /* For debugging, encode the failing instruction and
273                          * report it to userspace. */
274                         run->hw.hardware_exit_reason = ~0ULL << 32;
275                         run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
276                         r = RESUME_HOST;
277                         break;
278                 default:
279                         BUG();
280                 }
281                 break;
282
283         case BOOKE_INTERRUPT_FP_UNAVAIL:
284                 kvmppc_queue_exception(vcpu, exit_nr);
285                 r = RESUME_GUEST;
286                 break;
287
288         case BOOKE_INTERRUPT_DATA_STORAGE:
289                 vcpu->arch.dear = vcpu->arch.fault_dear;
290                 vcpu->arch.esr = vcpu->arch.fault_esr;
291                 kvmppc_queue_exception(vcpu, exit_nr);
292                 vcpu->stat.dsi_exits++;
293                 r = RESUME_GUEST;
294                 break;
295
296         case BOOKE_INTERRUPT_INST_STORAGE:
297                 vcpu->arch.esr = vcpu->arch.fault_esr;
298                 kvmppc_queue_exception(vcpu, exit_nr);
299                 vcpu->stat.isi_exits++;
300                 r = RESUME_GUEST;
301                 break;
302
303         case BOOKE_INTERRUPT_SYSCALL:
304                 kvmppc_queue_exception(vcpu, exit_nr);
305                 vcpu->stat.syscall_exits++;
306                 r = RESUME_GUEST;
307                 break;
308
309         case BOOKE_INTERRUPT_DTLB_MISS: {
310                 struct kvmppc_44x_tlbe *gtlbe;
311                 unsigned long eaddr = vcpu->arch.fault_dear;
312                 gfn_t gfn;
313
314                 /* Check the guest TLB. */
315                 gtlbe = kvmppc_44x_dtlb_search(vcpu, eaddr);
316                 if (!gtlbe) {
317                         /* The guest didn't have a mapping for it. */
318                         kvmppc_queue_exception(vcpu, exit_nr);
319                         vcpu->arch.dear = vcpu->arch.fault_dear;
320                         vcpu->arch.esr = vcpu->arch.fault_esr;
321                         vcpu->stat.dtlb_real_miss_exits++;
322                         r = RESUME_GUEST;
323                         break;
324                 }
325
326                 vcpu->arch.paddr_accessed = tlb_xlate(gtlbe, eaddr);
327                 gfn = vcpu->arch.paddr_accessed >> PAGE_SHIFT;
328
329                 if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
330                         /* The guest TLB had a mapping, but the shadow TLB
331                          * didn't, and it is RAM. This could be because:
332                          * a) the entry is mapping the host kernel, or
333                          * b) the guest used a large mapping which we're faking
334                          * Either way, we need to satisfy the fault without
335                          * invoking the guest. */
336                         kvmppc_mmu_map(vcpu, eaddr, gfn, gtlbe->tid,
337                                        gtlbe->word2);
338                         vcpu->stat.dtlb_virt_miss_exits++;
339                         r = RESUME_GUEST;
340                 } else {
341                         /* Guest has mapped and accessed a page which is not
342                          * actually RAM. */
343                         r = kvmppc_emulate_mmio(run, vcpu);
344                 }
345
346                 break;
347         }
348
349         case BOOKE_INTERRUPT_ITLB_MISS: {
350                 struct kvmppc_44x_tlbe *gtlbe;
351                 unsigned long eaddr = vcpu->arch.pc;
352                 gfn_t gfn;
353
354                 r = RESUME_GUEST;
355
356                 /* Check the guest TLB. */
357                 gtlbe = kvmppc_44x_itlb_search(vcpu, eaddr);
358                 if (!gtlbe) {
359                         /* The guest didn't have a mapping for it. */
360                         kvmppc_queue_exception(vcpu, exit_nr);
361                         vcpu->stat.itlb_real_miss_exits++;
362                         break;
363                 }
364
365                 vcpu->stat.itlb_virt_miss_exits++;
366
367                 gfn = tlb_xlate(gtlbe, eaddr) >> PAGE_SHIFT;
368
369                 if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
370                         /* The guest TLB had a mapping, but the shadow TLB
371                          * didn't. This could be because:
372                          * a) the entry is mapping the host kernel, or
373                          * b) the guest used a large mapping which we're faking
374                          * Either way, we need to satisfy the fault without
375                          * invoking the guest. */
376                         kvmppc_mmu_map(vcpu, eaddr, gfn, gtlbe->tid,
377                                        gtlbe->word2);
378                 } else {
379                         /* Guest mapped and leaped at non-RAM! */
380                         kvmppc_queue_exception(vcpu,
381                                                BOOKE_INTERRUPT_MACHINE_CHECK);
382                 }
383
384                 break;
385         }
386
387         case BOOKE_INTERRUPT_DEBUG: {
388                 u32 dbsr;
389
390                 vcpu->arch.pc = mfspr(SPRN_CSRR0);
391
392                 /* clear IAC events in DBSR register */
393                 dbsr = mfspr(SPRN_DBSR);
394                 dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
395                 mtspr(SPRN_DBSR, dbsr);
396
397                 run->exit_reason = KVM_EXIT_DEBUG;
398                 r = RESUME_HOST;
399                 break;
400         }
401
402         default:
403                 printk(KERN_EMERG "exit_nr %d\n", exit_nr);
404                 BUG();
405         }
406
407         local_irq_disable();
408
409         kvmppc_check_and_deliver_interrupts(vcpu);
410
411         /* Do some exit accounting. */
412         vcpu->stat.sum_exits++;
413         if (!(r & RESUME_HOST)) {
414                 /* To avoid clobbering exit_reason, only check for signals if
415                  * we aren't already exiting to userspace for some other
416                  * reason. */
417                 if (signal_pending(current)) {
418                         run->exit_reason = KVM_EXIT_INTR;
419                         r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
420
421                         vcpu->stat.signal_exits++;
422                 } else {
423                         vcpu->stat.light_exits++;
424                 }
425         } else {
426                 switch (run->exit_reason) {
427                 case KVM_EXIT_MMIO:
428                         vcpu->stat.mmio_exits++;
429                         break;
430                 case KVM_EXIT_DCR:
431                         vcpu->stat.dcr_exits++;
432                         break;
433                 case KVM_EXIT_INTR:
434                         vcpu->stat.signal_exits++;
435                         break;
436                 }
437         }
438
439         return r;
440 }
441
442 /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */
443 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
444 {
445         struct kvmppc_44x_tlbe *tlbe = &vcpu->arch.guest_tlb[0];
446
447         tlbe->tid = 0;
448         tlbe->word0 = PPC44x_TLB_16M | PPC44x_TLB_VALID;
449         tlbe->word1 = 0;
450         tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR;
451
452         tlbe++;
453         tlbe->tid = 0;
454         tlbe->word0 = 0xef600000 | PPC44x_TLB_4K | PPC44x_TLB_VALID;
455         tlbe->word1 = 0xef600000;
456         tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR
457                       | PPC44x_TLB_I | PPC44x_TLB_G;
458
459         vcpu->arch.pc = 0;
460         vcpu->arch.msr = 0;
461         vcpu->arch.gpr[1] = (16<<20) - 8; /* -8 for the callee-save LR slot */
462
463         vcpu->arch.shadow_pid = 1;
464
465         /* Eye-catching number so we know if the guest takes an interrupt
466          * before it's programmed its own IVPR. */
467         vcpu->arch.ivpr = 0x55550000;
468
469         /* Since the guest can directly access the timebase, it must know the
470          * real timebase frequency. Accordingly, it must see the state of
471          * CCR1[TCS]. */
472         vcpu->arch.ccr1 = mfspr(SPRN_CCR1);
473
474         return 0;
475 }
476
477 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
478 {
479         int i;
480
481         regs->pc = vcpu->arch.pc;
482         regs->cr = vcpu->arch.cr;
483         regs->ctr = vcpu->arch.ctr;
484         regs->lr = vcpu->arch.lr;
485         regs->xer = vcpu->arch.xer;
486         regs->msr = vcpu->arch.msr;
487         regs->srr0 = vcpu->arch.srr0;
488         regs->srr1 = vcpu->arch.srr1;
489         regs->pid = vcpu->arch.pid;
490         regs->sprg0 = vcpu->arch.sprg0;
491         regs->sprg1 = vcpu->arch.sprg1;
492         regs->sprg2 = vcpu->arch.sprg2;
493         regs->sprg3 = vcpu->arch.sprg3;
494         regs->sprg5 = vcpu->arch.sprg4;
495         regs->sprg6 = vcpu->arch.sprg5;
496         regs->sprg7 = vcpu->arch.sprg6;
497
498         for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
499                 regs->gpr[i] = vcpu->arch.gpr[i];
500
501         return 0;
502 }
503
504 int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
505 {
506         int i;
507
508         vcpu->arch.pc = regs->pc;
509         vcpu->arch.cr = regs->cr;
510         vcpu->arch.ctr = regs->ctr;
511         vcpu->arch.lr = regs->lr;
512         vcpu->arch.xer = regs->xer;
513         vcpu->arch.msr = regs->msr;
514         vcpu->arch.srr0 = regs->srr0;
515         vcpu->arch.srr1 = regs->srr1;
516         vcpu->arch.sprg0 = regs->sprg0;
517         vcpu->arch.sprg1 = regs->sprg1;
518         vcpu->arch.sprg2 = regs->sprg2;
519         vcpu->arch.sprg3 = regs->sprg3;
520         vcpu->arch.sprg5 = regs->sprg4;
521         vcpu->arch.sprg6 = regs->sprg5;
522         vcpu->arch.sprg7 = regs->sprg6;
523
524         for (i = 0; i < ARRAY_SIZE(vcpu->arch.gpr); i++)
525                 vcpu->arch.gpr[i] = regs->gpr[i];
526
527         return 0;
528 }
529
530 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
531                                   struct kvm_sregs *sregs)
532 {
533         return -ENOTSUPP;
534 }
535
536 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
537                                   struct kvm_sregs *sregs)
538 {
539         return -ENOTSUPP;
540 }
541
542 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
543 {
544         return -ENOTSUPP;
545 }
546
547 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
548 {
549         return -ENOTSUPP;
550 }
551
552 /* 'linear_address' is actually an encoding of AS|PID|EADDR . */
553 int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
554                                   struct kvm_translation *tr)
555 {
556         struct kvmppc_44x_tlbe *gtlbe;
557         int index;
558         gva_t eaddr;
559         u8 pid;
560         u8 as;
561
562         eaddr = tr->linear_address;
563         pid = (tr->linear_address >> 32) & 0xff;
564         as = (tr->linear_address >> 40) & 0x1;
565
566         index = kvmppc_44x_tlb_index(vcpu, eaddr, pid, as);
567         if (index == -1) {
568                 tr->valid = 0;
569                 return 0;
570         }
571
572         gtlbe = &vcpu->arch.guest_tlb[index];
573
574         tr->physical_address = tlb_xlate(gtlbe, eaddr);
575         /* XXX what does "writeable" and "usermode" even mean? */
576         tr->valid = 1;
577
578         return 0;
579 }