booke_guest.c 17 KB

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