booke.c 17 KB

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