booke.c 15 KB

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