booke_guest.c 16 KB

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