booke.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 "timing.h"
  30. #include <asm/cacheflush.h>
  31. #include "booke.h"
  32. unsigned long kvmppc_booke_handlers;
  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. struct kvm_stats_debugfs_item debugfs_entries[] = {
  36. { "mmio", VCPU_STAT(mmio_exits) },
  37. { "dcr", VCPU_STAT(dcr_exits) },
  38. { "sig", VCPU_STAT(signal_exits) },
  39. { "itlb_r", VCPU_STAT(itlb_real_miss_exits) },
  40. { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) },
  41. { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) },
  42. { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) },
  43. { "sysc", VCPU_STAT(syscall_exits) },
  44. { "isi", VCPU_STAT(isi_exits) },
  45. { "dsi", VCPU_STAT(dsi_exits) },
  46. { "inst_emu", VCPU_STAT(emulated_inst_exits) },
  47. { "dec", VCPU_STAT(dec_exits) },
  48. { "ext_intr", VCPU_STAT(ext_intr_exits) },
  49. { "halt_wakeup", VCPU_STAT(halt_wakeup) },
  50. { NULL }
  51. };
  52. /* TODO: use vcpu_printf() */
  53. void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu)
  54. {
  55. int i;
  56. printk("pc: %08lx msr: %08lx\n", vcpu->arch.pc, vcpu->arch.msr);
  57. printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr);
  58. printk("srr0: %08lx srr1: %08lx\n", vcpu->arch.srr0, vcpu->arch.srr1);
  59. printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions);
  60. for (i = 0; i < 32; i += 4) {
  61. printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i,
  62. kvmppc_get_gpr(vcpu, i),
  63. kvmppc_get_gpr(vcpu, i+1),
  64. kvmppc_get_gpr(vcpu, i+2),
  65. kvmppc_get_gpr(vcpu, i+3));
  66. }
  67. }
  68. static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
  69. unsigned int priority)
  70. {
  71. set_bit(priority, &vcpu->arch.pending_exceptions);
  72. }
  73. static void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu,
  74. ulong dear_flags, ulong esr_flags)
  75. {
  76. vcpu->arch.queued_dear = dear_flags;
  77. vcpu->arch.queued_esr = esr_flags;
  78. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS);
  79. }
  80. static void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu,
  81. ulong dear_flags, ulong esr_flags)
  82. {
  83. vcpu->arch.queued_dear = dear_flags;
  84. vcpu->arch.queued_esr = esr_flags;
  85. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
  86. }
  87. static void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu,
  88. ulong esr_flags)
  89. {
  90. vcpu->arch.queued_esr = esr_flags;
  91. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
  92. }
  93. void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags)
  94. {
  95. vcpu->arch.queued_esr = esr_flags;
  96. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
  97. }
  98. void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu)
  99. {
  100. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER);
  101. }
  102. int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
  103. {
  104. return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
  105. }
  106. void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
  107. {
  108. clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
  109. }
  110. void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
  111. struct kvm_interrupt *irq)
  112. {
  113. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_EXTERNAL);
  114. }
  115. /* Deliver the interrupt of the corresponding priority, if possible. */
  116. static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
  117. unsigned int priority)
  118. {
  119. int allowed = 0;
  120. ulong msr_mask;
  121. bool update_esr = false, update_dear = false;
  122. switch (priority) {
  123. case BOOKE_IRQPRIO_DTLB_MISS:
  124. case BOOKE_IRQPRIO_DATA_STORAGE:
  125. update_dear = true;
  126. /* fall through */
  127. case BOOKE_IRQPRIO_INST_STORAGE:
  128. case BOOKE_IRQPRIO_PROGRAM:
  129. update_esr = true;
  130. /* fall through */
  131. case BOOKE_IRQPRIO_ITLB_MISS:
  132. case BOOKE_IRQPRIO_SYSCALL:
  133. case BOOKE_IRQPRIO_FP_UNAVAIL:
  134. case BOOKE_IRQPRIO_SPE_UNAVAIL:
  135. case BOOKE_IRQPRIO_SPE_FP_DATA:
  136. case BOOKE_IRQPRIO_SPE_FP_ROUND:
  137. case BOOKE_IRQPRIO_AP_UNAVAIL:
  138. case BOOKE_IRQPRIO_ALIGNMENT:
  139. allowed = 1;
  140. msr_mask = MSR_CE|MSR_ME|MSR_DE;
  141. break;
  142. case BOOKE_IRQPRIO_CRITICAL:
  143. case BOOKE_IRQPRIO_WATCHDOG:
  144. allowed = vcpu->arch.msr & MSR_CE;
  145. msr_mask = MSR_ME;
  146. break;
  147. case BOOKE_IRQPRIO_MACHINE_CHECK:
  148. allowed = vcpu->arch.msr & MSR_ME;
  149. msr_mask = 0;
  150. break;
  151. case BOOKE_IRQPRIO_EXTERNAL:
  152. case BOOKE_IRQPRIO_DECREMENTER:
  153. case BOOKE_IRQPRIO_FIT:
  154. allowed = vcpu->arch.msr & MSR_EE;
  155. msr_mask = MSR_CE|MSR_ME|MSR_DE;
  156. break;
  157. case BOOKE_IRQPRIO_DEBUG:
  158. allowed = vcpu->arch.msr & MSR_DE;
  159. msr_mask = MSR_ME;
  160. break;
  161. }
  162. if (allowed) {
  163. vcpu->arch.srr0 = vcpu->arch.pc;
  164. vcpu->arch.srr1 = vcpu->arch.msr;
  165. vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority];
  166. if (update_esr == true)
  167. vcpu->arch.esr = vcpu->arch.queued_esr;
  168. if (update_dear == true)
  169. vcpu->arch.dear = vcpu->arch.queued_dear;
  170. kvmppc_set_msr(vcpu, vcpu->arch.msr & msr_mask);
  171. clear_bit(priority, &vcpu->arch.pending_exceptions);
  172. }
  173. return allowed;
  174. }
  175. /* Check pending exceptions and deliver one, if possible. */
  176. void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
  177. {
  178. unsigned long *pending = &vcpu->arch.pending_exceptions;
  179. unsigned int priority;
  180. priority = __ffs(*pending);
  181. while (priority <= BOOKE_IRQPRIO_MAX) {
  182. if (kvmppc_booke_irqprio_deliver(vcpu, priority))
  183. break;
  184. priority = find_next_bit(pending,
  185. BITS_PER_BYTE * sizeof(*pending),
  186. priority + 1);
  187. }
  188. }
  189. /**
  190. * kvmppc_handle_exit
  191. *
  192. * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
  193. */
  194. int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
  195. unsigned int exit_nr)
  196. {
  197. enum emulation_result er;
  198. int r = RESUME_HOST;
  199. /* update before a new last_exit_type is rewritten */
  200. kvmppc_update_timing_stats(vcpu);
  201. local_irq_enable();
  202. run->exit_reason = KVM_EXIT_UNKNOWN;
  203. run->ready_for_interrupt_injection = 1;
  204. switch (exit_nr) {
  205. case BOOKE_INTERRUPT_MACHINE_CHECK:
  206. printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR));
  207. kvmppc_dump_vcpu(vcpu);
  208. r = RESUME_HOST;
  209. break;
  210. case BOOKE_INTERRUPT_EXTERNAL:
  211. kvmppc_account_exit(vcpu, EXT_INTR_EXITS);
  212. if (need_resched())
  213. cond_resched();
  214. r = RESUME_GUEST;
  215. break;
  216. case BOOKE_INTERRUPT_DECREMENTER:
  217. /* Since we switched IVPR back to the host's value, the host
  218. * handled this interrupt the moment we enabled interrupts.
  219. * Now we just offer it a chance to reschedule the guest. */
  220. kvmppc_account_exit(vcpu, DEC_EXITS);
  221. if (need_resched())
  222. cond_resched();
  223. r = RESUME_GUEST;
  224. break;
  225. case BOOKE_INTERRUPT_PROGRAM:
  226. if (vcpu->arch.msr & MSR_PR) {
  227. /* Program traps generated by user-level software must be handled
  228. * by the guest kernel. */
  229. kvmppc_core_queue_program(vcpu, vcpu->arch.fault_esr);
  230. r = RESUME_GUEST;
  231. kvmppc_account_exit(vcpu, USR_PR_INST);
  232. break;
  233. }
  234. er = kvmppc_emulate_instruction(run, vcpu);
  235. switch (er) {
  236. case EMULATE_DONE:
  237. /* don't overwrite subtypes, just account kvm_stats */
  238. kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS);
  239. /* Future optimization: only reload non-volatiles if
  240. * they were actually modified by emulation. */
  241. r = RESUME_GUEST_NV;
  242. break;
  243. case EMULATE_DO_DCR:
  244. run->exit_reason = KVM_EXIT_DCR;
  245. r = RESUME_HOST;
  246. break;
  247. case EMULATE_FAIL:
  248. /* XXX Deliver Program interrupt to guest. */
  249. printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n",
  250. __func__, vcpu->arch.pc, vcpu->arch.last_inst);
  251. /* For debugging, encode the failing instruction and
  252. * report it to userspace. */
  253. run->hw.hardware_exit_reason = ~0ULL << 32;
  254. run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
  255. r = RESUME_HOST;
  256. break;
  257. default:
  258. BUG();
  259. }
  260. break;
  261. case BOOKE_INTERRUPT_FP_UNAVAIL:
  262. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL);
  263. kvmppc_account_exit(vcpu, FP_UNAVAIL);
  264. r = RESUME_GUEST;
  265. break;
  266. case BOOKE_INTERRUPT_SPE_UNAVAIL:
  267. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_UNAVAIL);
  268. r = RESUME_GUEST;
  269. break;
  270. case BOOKE_INTERRUPT_SPE_FP_DATA:
  271. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA);
  272. r = RESUME_GUEST;
  273. break;
  274. case BOOKE_INTERRUPT_SPE_FP_ROUND:
  275. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND);
  276. r = RESUME_GUEST;
  277. break;
  278. case BOOKE_INTERRUPT_DATA_STORAGE:
  279. kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear,
  280. vcpu->arch.fault_esr);
  281. kvmppc_account_exit(vcpu, DSI_EXITS);
  282. r = RESUME_GUEST;
  283. break;
  284. case BOOKE_INTERRUPT_INST_STORAGE:
  285. kvmppc_core_queue_inst_storage(vcpu, vcpu->arch.fault_esr);
  286. kvmppc_account_exit(vcpu, ISI_EXITS);
  287. r = RESUME_GUEST;
  288. break;
  289. case BOOKE_INTERRUPT_SYSCALL:
  290. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL);
  291. kvmppc_account_exit(vcpu, SYSCALL_EXITS);
  292. r = RESUME_GUEST;
  293. break;
  294. case BOOKE_INTERRUPT_DTLB_MISS: {
  295. unsigned long eaddr = vcpu->arch.fault_dear;
  296. int gtlb_index;
  297. gpa_t gpaddr;
  298. gfn_t gfn;
  299. /* Check the guest TLB. */
  300. gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr);
  301. if (gtlb_index < 0) {
  302. /* The guest didn't have a mapping for it. */
  303. kvmppc_core_queue_dtlb_miss(vcpu,
  304. vcpu->arch.fault_dear,
  305. vcpu->arch.fault_esr);
  306. kvmppc_mmu_dtlb_miss(vcpu);
  307. kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS);
  308. r = RESUME_GUEST;
  309. break;
  310. }
  311. gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
  312. gfn = gpaddr >> PAGE_SHIFT;
  313. if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
  314. /* The guest TLB had a mapping, but the shadow TLB
  315. * didn't, and it is RAM. This could be because:
  316. * a) the entry is mapping the host kernel, or
  317. * b) the guest used a large mapping which we're faking
  318. * Either way, we need to satisfy the fault without
  319. * invoking the guest. */
  320. kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
  321. kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS);
  322. r = RESUME_GUEST;
  323. } else {
  324. /* Guest has mapped and accessed a page which is not
  325. * actually RAM. */
  326. vcpu->arch.paddr_accessed = gpaddr;
  327. r = kvmppc_emulate_mmio(run, vcpu);
  328. kvmppc_account_exit(vcpu, MMIO_EXITS);
  329. }
  330. break;
  331. }
  332. case BOOKE_INTERRUPT_ITLB_MISS: {
  333. unsigned long eaddr = vcpu->arch.pc;
  334. gpa_t gpaddr;
  335. gfn_t gfn;
  336. int gtlb_index;
  337. r = RESUME_GUEST;
  338. /* Check the guest TLB. */
  339. gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr);
  340. if (gtlb_index < 0) {
  341. /* The guest didn't have a mapping for it. */
  342. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS);
  343. kvmppc_mmu_itlb_miss(vcpu);
  344. kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS);
  345. break;
  346. }
  347. kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS);
  348. gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
  349. gfn = gpaddr >> PAGE_SHIFT;
  350. if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
  351. /* The guest TLB had a mapping, but the shadow TLB
  352. * didn't. This could be because:
  353. * a) the entry is mapping the host kernel, or
  354. * b) the guest used a large mapping which we're faking
  355. * Either way, we need to satisfy the fault without
  356. * invoking the guest. */
  357. kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
  358. } else {
  359. /* Guest mapped and leaped at non-RAM! */
  360. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK);
  361. }
  362. break;
  363. }
  364. case BOOKE_INTERRUPT_DEBUG: {
  365. u32 dbsr;
  366. vcpu->arch.pc = mfspr(SPRN_CSRR0);
  367. /* clear IAC events in DBSR register */
  368. dbsr = mfspr(SPRN_DBSR);
  369. dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
  370. mtspr(SPRN_DBSR, dbsr);
  371. run->exit_reason = KVM_EXIT_DEBUG;
  372. kvmppc_account_exit(vcpu, DEBUG_EXITS);
  373. r = RESUME_HOST;
  374. break;
  375. }
  376. default:
  377. printk(KERN_EMERG "exit_nr %d\n", exit_nr);
  378. BUG();
  379. }
  380. local_irq_disable();
  381. kvmppc_core_deliver_interrupts(vcpu);
  382. if (!(r & RESUME_HOST)) {
  383. /* To avoid clobbering exit_reason, only check for signals if
  384. * we aren't already exiting to userspace for some other
  385. * reason. */
  386. if (signal_pending(current)) {
  387. run->exit_reason = KVM_EXIT_INTR;
  388. r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
  389. kvmppc_account_exit(vcpu, SIGNAL_EXITS);
  390. }
  391. }
  392. return r;
  393. }
  394. /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */
  395. int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
  396. {
  397. vcpu->arch.pc = 0;
  398. vcpu->arch.msr = 0;
  399. kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */
  400. vcpu->arch.shadow_pid = 1;
  401. /* Eye-catching number so we know if the guest takes an interrupt
  402. * before it's programmed its own IVPR. */
  403. vcpu->arch.ivpr = 0x55550000;
  404. kvmppc_init_timing_stats(vcpu);
  405. return kvmppc_core_vcpu_setup(vcpu);
  406. }
  407. int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  408. {
  409. int i;
  410. regs->pc = vcpu->arch.pc;
  411. regs->cr = kvmppc_get_cr(vcpu);
  412. regs->ctr = vcpu->arch.ctr;
  413. regs->lr = vcpu->arch.lr;
  414. regs->xer = kvmppc_get_xer(vcpu);
  415. regs->msr = vcpu->arch.msr;
  416. regs->srr0 = vcpu->arch.srr0;
  417. regs->srr1 = vcpu->arch.srr1;
  418. regs->pid = vcpu->arch.pid;
  419. regs->sprg0 = vcpu->arch.sprg0;
  420. regs->sprg1 = vcpu->arch.sprg1;
  421. regs->sprg2 = vcpu->arch.sprg2;
  422. regs->sprg3 = vcpu->arch.sprg3;
  423. regs->sprg5 = vcpu->arch.sprg4;
  424. regs->sprg6 = vcpu->arch.sprg5;
  425. regs->sprg7 = vcpu->arch.sprg6;
  426. for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
  427. regs->gpr[i] = kvmppc_get_gpr(vcpu, i);
  428. return 0;
  429. }
  430. int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  431. {
  432. int i;
  433. vcpu->arch.pc = regs->pc;
  434. kvmppc_set_cr(vcpu, regs->cr);
  435. vcpu->arch.ctr = regs->ctr;
  436. vcpu->arch.lr = regs->lr;
  437. kvmppc_set_xer(vcpu, regs->xer);
  438. kvmppc_set_msr(vcpu, regs->msr);
  439. vcpu->arch.srr0 = regs->srr0;
  440. vcpu->arch.srr1 = regs->srr1;
  441. vcpu->arch.sprg0 = regs->sprg0;
  442. vcpu->arch.sprg1 = regs->sprg1;
  443. vcpu->arch.sprg2 = regs->sprg2;
  444. vcpu->arch.sprg3 = regs->sprg3;
  445. vcpu->arch.sprg5 = regs->sprg4;
  446. vcpu->arch.sprg6 = regs->sprg5;
  447. vcpu->arch.sprg7 = regs->sprg6;
  448. for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
  449. kvmppc_set_gpr(vcpu, i, regs->gpr[i]);
  450. return 0;
  451. }
  452. int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
  453. struct kvm_sregs *sregs)
  454. {
  455. return -ENOTSUPP;
  456. }
  457. int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
  458. struct kvm_sregs *sregs)
  459. {
  460. return -ENOTSUPP;
  461. }
  462. int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  463. {
  464. return -ENOTSUPP;
  465. }
  466. int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  467. {
  468. return -ENOTSUPP;
  469. }
  470. int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
  471. struct kvm_translation *tr)
  472. {
  473. return kvmppc_core_vcpu_translate(vcpu, tr);
  474. }
  475. int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
  476. {
  477. return -ENOTSUPP;
  478. }
  479. int __init kvmppc_booke_init(void)
  480. {
  481. unsigned long ivor[16];
  482. unsigned long max_ivor = 0;
  483. int i;
  484. /* We install our own exception handlers by hijacking IVPR. IVPR must
  485. * be 16-bit aligned, so we need a 64KB allocation. */
  486. kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO,
  487. VCPU_SIZE_ORDER);
  488. if (!kvmppc_booke_handlers)
  489. return -ENOMEM;
  490. /* XXX make sure our handlers are smaller than Linux's */
  491. /* Copy our interrupt handlers to match host IVORs. That way we don't
  492. * have to swap the IVORs on every guest/host transition. */
  493. ivor[0] = mfspr(SPRN_IVOR0);
  494. ivor[1] = mfspr(SPRN_IVOR1);
  495. ivor[2] = mfspr(SPRN_IVOR2);
  496. ivor[3] = mfspr(SPRN_IVOR3);
  497. ivor[4] = mfspr(SPRN_IVOR4);
  498. ivor[5] = mfspr(SPRN_IVOR5);
  499. ivor[6] = mfspr(SPRN_IVOR6);
  500. ivor[7] = mfspr(SPRN_IVOR7);
  501. ivor[8] = mfspr(SPRN_IVOR8);
  502. ivor[9] = mfspr(SPRN_IVOR9);
  503. ivor[10] = mfspr(SPRN_IVOR10);
  504. ivor[11] = mfspr(SPRN_IVOR11);
  505. ivor[12] = mfspr(SPRN_IVOR12);
  506. ivor[13] = mfspr(SPRN_IVOR13);
  507. ivor[14] = mfspr(SPRN_IVOR14);
  508. ivor[15] = mfspr(SPRN_IVOR15);
  509. for (i = 0; i < 16; i++) {
  510. if (ivor[i] > max_ivor)
  511. max_ivor = ivor[i];
  512. memcpy((void *)kvmppc_booke_handlers + ivor[i],
  513. kvmppc_handlers_start + i * kvmppc_handler_len,
  514. kvmppc_handler_len);
  515. }
  516. flush_icache_range(kvmppc_booke_handlers,
  517. kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
  518. return 0;
  519. }
  520. void __exit kvmppc_booke_exit(void)
  521. {
  522. free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER);
  523. kvm_exit();
  524. }