booke.c 17 KB

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