booke.c 16 KB

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