booke_guest.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. static int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu)
  206. {
  207. enum emulation_result er;
  208. int r;
  209. er = kvmppc_emulate_instruction(run, vcpu);
  210. switch (er) {
  211. case EMULATE_DONE:
  212. /* Future optimization: only reload non-volatiles if they were
  213. * actually modified. */
  214. r = RESUME_GUEST_NV;
  215. break;
  216. case EMULATE_DO_MMIO:
  217. run->exit_reason = KVM_EXIT_MMIO;
  218. /* We must reload nonvolatiles because "update" load/store
  219. * instructions modify register state. */
  220. /* Future optimization: only reload non-volatiles if they were
  221. * actually modified. */
  222. r = RESUME_HOST_NV;
  223. break;
  224. case EMULATE_FAIL:
  225. /* XXX Deliver Program interrupt to guest. */
  226. printk(KERN_EMERG "%s: emulation failed (%08x)\n", __func__,
  227. vcpu->arch.last_inst);
  228. r = RESUME_HOST;
  229. break;
  230. default:
  231. BUG();
  232. }
  233. return r;
  234. }
  235. /**
  236. * kvmppc_handle_exit
  237. *
  238. * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
  239. */
  240. int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
  241. unsigned int exit_nr)
  242. {
  243. enum emulation_result er;
  244. int r = RESUME_HOST;
  245. local_irq_enable();
  246. run->exit_reason = KVM_EXIT_UNKNOWN;
  247. run->ready_for_interrupt_injection = 1;
  248. switch (exit_nr) {
  249. case BOOKE_INTERRUPT_MACHINE_CHECK:
  250. printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR));
  251. kvmppc_dump_vcpu(vcpu);
  252. r = RESUME_HOST;
  253. break;
  254. case BOOKE_INTERRUPT_EXTERNAL:
  255. case BOOKE_INTERRUPT_DECREMENTER:
  256. /* Since we switched IVPR back to the host's value, the host
  257. * handled this interrupt the moment we enabled interrupts.
  258. * Now we just offer it a chance to reschedule the guest. */
  259. /* XXX At this point the TLB still holds our shadow TLB, so if
  260. * we do reschedule the host will fault over it. Perhaps we
  261. * should politely restore the host's entries to minimize
  262. * misses before ceding control. */
  263. if (need_resched())
  264. cond_resched();
  265. if (exit_nr == BOOKE_INTERRUPT_DECREMENTER)
  266. vcpu->stat.dec_exits++;
  267. else
  268. vcpu->stat.ext_intr_exits++;
  269. r = RESUME_GUEST;
  270. break;
  271. case BOOKE_INTERRUPT_PROGRAM:
  272. if (vcpu->arch.msr & MSR_PR) {
  273. /* Program traps generated by user-level software must be handled
  274. * by the guest kernel. */
  275. vcpu->arch.esr = vcpu->arch.fault_esr;
  276. kvmppc_queue_exception(vcpu, BOOKE_INTERRUPT_PROGRAM);
  277. r = RESUME_GUEST;
  278. break;
  279. }
  280. er = kvmppc_emulate_instruction(run, vcpu);
  281. switch (er) {
  282. case EMULATE_DONE:
  283. /* Future optimization: only reload non-volatiles if
  284. * they were actually modified by emulation. */
  285. vcpu->stat.emulated_inst_exits++;
  286. r = RESUME_GUEST_NV;
  287. break;
  288. case EMULATE_DO_DCR:
  289. run->exit_reason = KVM_EXIT_DCR;
  290. r = RESUME_HOST;
  291. break;
  292. case EMULATE_FAIL:
  293. /* XXX Deliver Program interrupt to guest. */
  294. printk(KERN_CRIT "%s: emulation at %x failed (%08x)\n",
  295. __func__, vcpu->arch.pc, vcpu->arch.last_inst);
  296. /* For debugging, encode the failing instruction and
  297. * report it to userspace. */
  298. run->hw.hardware_exit_reason = ~0ULL << 32;
  299. run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
  300. r = RESUME_HOST;
  301. break;
  302. default:
  303. BUG();
  304. }
  305. break;
  306. case BOOKE_INTERRUPT_FP_UNAVAIL:
  307. kvmppc_queue_exception(vcpu, exit_nr);
  308. r = RESUME_GUEST;
  309. break;
  310. case BOOKE_INTERRUPT_DATA_STORAGE:
  311. vcpu->arch.dear = vcpu->arch.fault_dear;
  312. vcpu->arch.esr = vcpu->arch.fault_esr;
  313. kvmppc_queue_exception(vcpu, exit_nr);
  314. vcpu->stat.dsi_exits++;
  315. r = RESUME_GUEST;
  316. break;
  317. case BOOKE_INTERRUPT_INST_STORAGE:
  318. vcpu->arch.esr = vcpu->arch.fault_esr;
  319. kvmppc_queue_exception(vcpu, exit_nr);
  320. vcpu->stat.isi_exits++;
  321. r = RESUME_GUEST;
  322. break;
  323. case BOOKE_INTERRUPT_SYSCALL:
  324. kvmppc_queue_exception(vcpu, exit_nr);
  325. vcpu->stat.syscall_exits++;
  326. r = RESUME_GUEST;
  327. break;
  328. case BOOKE_INTERRUPT_DTLB_MISS: {
  329. struct tlbe *gtlbe;
  330. unsigned long eaddr = vcpu->arch.fault_dear;
  331. gfn_t gfn;
  332. /* Check the guest TLB. */
  333. gtlbe = kvmppc_44x_dtlb_search(vcpu, eaddr);
  334. if (!gtlbe) {
  335. /* The guest didn't have a mapping for it. */
  336. kvmppc_queue_exception(vcpu, exit_nr);
  337. vcpu->arch.dear = vcpu->arch.fault_dear;
  338. vcpu->arch.esr = vcpu->arch.fault_esr;
  339. vcpu->stat.dtlb_real_miss_exits++;
  340. r = RESUME_GUEST;
  341. break;
  342. }
  343. vcpu->arch.paddr_accessed = tlb_xlate(gtlbe, eaddr);
  344. gfn = vcpu->arch.paddr_accessed >> PAGE_SHIFT;
  345. if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
  346. /* The guest TLB had a mapping, but the shadow TLB
  347. * didn't, and it is RAM. This could be because:
  348. * a) the entry is mapping the host kernel, or
  349. * b) the guest used a large mapping which we're faking
  350. * Either way, we need to satisfy the fault without
  351. * invoking the guest. */
  352. kvmppc_mmu_map(vcpu, eaddr, gfn, gtlbe->tid,
  353. gtlbe->word2);
  354. vcpu->stat.dtlb_virt_miss_exits++;
  355. r = RESUME_GUEST;
  356. } else {
  357. /* Guest has mapped and accessed a page which is not
  358. * actually RAM. */
  359. r = kvmppc_emulate_mmio(run, vcpu);
  360. }
  361. break;
  362. }
  363. case BOOKE_INTERRUPT_ITLB_MISS: {
  364. struct tlbe *gtlbe;
  365. unsigned long eaddr = vcpu->arch.pc;
  366. gfn_t gfn;
  367. r = RESUME_GUEST;
  368. /* Check the guest TLB. */
  369. gtlbe = kvmppc_44x_itlb_search(vcpu, eaddr);
  370. if (!gtlbe) {
  371. /* The guest didn't have a mapping for it. */
  372. kvmppc_queue_exception(vcpu, exit_nr);
  373. vcpu->stat.itlb_real_miss_exits++;
  374. break;
  375. }
  376. vcpu->stat.itlb_virt_miss_exits++;
  377. gfn = tlb_xlate(gtlbe, eaddr) >> PAGE_SHIFT;
  378. if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
  379. /* The guest TLB had a mapping, but the shadow TLB
  380. * didn't. This could be because:
  381. * a) the entry is mapping the host kernel, or
  382. * b) the guest used a large mapping which we're faking
  383. * Either way, we need to satisfy the fault without
  384. * invoking the guest. */
  385. kvmppc_mmu_map(vcpu, eaddr, gfn, gtlbe->tid,
  386. gtlbe->word2);
  387. } else {
  388. /* Guest mapped and leaped at non-RAM! */
  389. kvmppc_queue_exception(vcpu,
  390. BOOKE_INTERRUPT_MACHINE_CHECK);
  391. }
  392. break;
  393. }
  394. default:
  395. printk(KERN_EMERG "exit_nr %d\n", exit_nr);
  396. BUG();
  397. }
  398. local_irq_disable();
  399. kvmppc_check_and_deliver_interrupts(vcpu);
  400. /* Do some exit accounting. */
  401. vcpu->stat.sum_exits++;
  402. if (!(r & RESUME_HOST)) {
  403. /* To avoid clobbering exit_reason, only check for signals if
  404. * we aren't already exiting to userspace for some other
  405. * reason. */
  406. if (signal_pending(current)) {
  407. run->exit_reason = KVM_EXIT_INTR;
  408. r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
  409. vcpu->stat.signal_exits++;
  410. } else {
  411. vcpu->stat.light_exits++;
  412. }
  413. } else {
  414. switch (run->exit_reason) {
  415. case KVM_EXIT_MMIO:
  416. vcpu->stat.mmio_exits++;
  417. break;
  418. case KVM_EXIT_DCR:
  419. vcpu->stat.dcr_exits++;
  420. break;
  421. case KVM_EXIT_INTR:
  422. vcpu->stat.signal_exits++;
  423. break;
  424. }
  425. }
  426. return r;
  427. }
  428. /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */
  429. int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
  430. {
  431. struct tlbe *tlbe = &vcpu->arch.guest_tlb[0];
  432. tlbe->tid = 0;
  433. tlbe->word0 = PPC44x_TLB_16M | PPC44x_TLB_VALID;
  434. tlbe->word1 = 0;
  435. tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR;
  436. tlbe++;
  437. tlbe->tid = 0;
  438. tlbe->word0 = 0xef600000 | PPC44x_TLB_4K | PPC44x_TLB_VALID;
  439. tlbe->word1 = 0xef600000;
  440. tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR
  441. | PPC44x_TLB_I | PPC44x_TLB_G;
  442. vcpu->arch.pc = 0;
  443. vcpu->arch.msr = 0;
  444. vcpu->arch.gpr[1] = (16<<20) - 8; /* -8 for the callee-save LR slot */
  445. /* Eye-catching number so we know if the guest takes an interrupt
  446. * before it's programmed its own IVPR. */
  447. vcpu->arch.ivpr = 0x55550000;
  448. /* Since the guest can directly access the timebase, it must know the
  449. * real timebase frequency. Accordingly, it must see the state of
  450. * CCR1[TCS]. */
  451. vcpu->arch.ccr1 = mfspr(SPRN_CCR1);
  452. return 0;
  453. }
  454. int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  455. {
  456. int i;
  457. regs->pc = vcpu->arch.pc;
  458. regs->cr = vcpu->arch.cr;
  459. regs->ctr = vcpu->arch.ctr;
  460. regs->lr = vcpu->arch.lr;
  461. regs->xer = vcpu->arch.xer;
  462. regs->msr = vcpu->arch.msr;
  463. regs->srr0 = vcpu->arch.srr0;
  464. regs->srr1 = vcpu->arch.srr1;
  465. regs->pid = vcpu->arch.pid;
  466. regs->sprg0 = vcpu->arch.sprg0;
  467. regs->sprg1 = vcpu->arch.sprg1;
  468. regs->sprg2 = vcpu->arch.sprg2;
  469. regs->sprg3 = vcpu->arch.sprg3;
  470. regs->sprg5 = vcpu->arch.sprg4;
  471. regs->sprg6 = vcpu->arch.sprg5;
  472. regs->sprg7 = vcpu->arch.sprg6;
  473. for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
  474. regs->gpr[i] = vcpu->arch.gpr[i];
  475. return 0;
  476. }
  477. int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  478. {
  479. int i;
  480. vcpu->arch.pc = regs->pc;
  481. vcpu->arch.cr = regs->cr;
  482. vcpu->arch.ctr = regs->ctr;
  483. vcpu->arch.lr = regs->lr;
  484. vcpu->arch.xer = regs->xer;
  485. vcpu->arch.msr = regs->msr;
  486. vcpu->arch.srr0 = regs->srr0;
  487. vcpu->arch.srr1 = regs->srr1;
  488. vcpu->arch.sprg0 = regs->sprg0;
  489. vcpu->arch.sprg1 = regs->sprg1;
  490. vcpu->arch.sprg2 = regs->sprg2;
  491. vcpu->arch.sprg3 = regs->sprg3;
  492. vcpu->arch.sprg5 = regs->sprg4;
  493. vcpu->arch.sprg6 = regs->sprg5;
  494. vcpu->arch.sprg7 = regs->sprg6;
  495. for (i = 0; i < ARRAY_SIZE(vcpu->arch.gpr); i++)
  496. vcpu->arch.gpr[i] = regs->gpr[i];
  497. return 0;
  498. }
  499. int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
  500. struct kvm_sregs *sregs)
  501. {
  502. return -ENOTSUPP;
  503. }
  504. int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
  505. struct kvm_sregs *sregs)
  506. {
  507. return -ENOTSUPP;
  508. }
  509. int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  510. {
  511. return -ENOTSUPP;
  512. }
  513. int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  514. {
  515. return -ENOTSUPP;
  516. }
  517. /* 'linear_address' is actually an encoding of AS|PID|EADDR . */
  518. int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
  519. struct kvm_translation *tr)
  520. {
  521. struct tlbe *gtlbe;
  522. int index;
  523. gva_t eaddr;
  524. u8 pid;
  525. u8 as;
  526. eaddr = tr->linear_address;
  527. pid = (tr->linear_address >> 32) & 0xff;
  528. as = (tr->linear_address >> 40) & 0x1;
  529. index = kvmppc_44x_tlb_index(vcpu, eaddr, pid, as);
  530. if (index == -1) {
  531. tr->valid = 0;
  532. return 0;
  533. }
  534. gtlbe = &vcpu->arch.guest_tlb[index];
  535. tr->physical_address = tlb_xlate(gtlbe, eaddr);
  536. /* XXX what does "writeable" and "usermode" even mean? */
  537. tr->valid = 1;
  538. return 0;
  539. }