powerpc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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/hrtimer.h>
  26. #include <linux/fs.h>
  27. #include <linux/slab.h>
  28. #include <asm/cputable.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/kvm_ppc.h>
  31. #include <asm/tlbflush.h>
  32. #include <asm/cputhreads.h>
  33. #include "timing.h"
  34. #include "../mm/mmu_decl.h"
  35. #define CREATE_TRACE_POINTS
  36. #include "trace.h"
  37. int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
  38. {
  39. #ifndef CONFIG_KVM_BOOK3S_64_HV
  40. return !(v->arch.shared->msr & MSR_WE) ||
  41. !!(v->arch.pending_exceptions);
  42. #else
  43. return !(v->arch.ceded) || !!(v->arch.pending_exceptions);
  44. #endif
  45. }
  46. int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
  47. {
  48. int nr = kvmppc_get_gpr(vcpu, 11);
  49. int r;
  50. unsigned long __maybe_unused param1 = kvmppc_get_gpr(vcpu, 3);
  51. unsigned long __maybe_unused param2 = kvmppc_get_gpr(vcpu, 4);
  52. unsigned long __maybe_unused param3 = kvmppc_get_gpr(vcpu, 5);
  53. unsigned long __maybe_unused param4 = kvmppc_get_gpr(vcpu, 6);
  54. unsigned long r2 = 0;
  55. if (!(vcpu->arch.shared->msr & MSR_SF)) {
  56. /* 32 bit mode */
  57. param1 &= 0xffffffff;
  58. param2 &= 0xffffffff;
  59. param3 &= 0xffffffff;
  60. param4 &= 0xffffffff;
  61. }
  62. switch (nr) {
  63. case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
  64. {
  65. vcpu->arch.magic_page_pa = param1;
  66. vcpu->arch.magic_page_ea = param2;
  67. r2 = KVM_MAGIC_FEAT_SR;
  68. r = HC_EV_SUCCESS;
  69. break;
  70. }
  71. case HC_VENDOR_KVM | KVM_HC_FEATURES:
  72. r = HC_EV_SUCCESS;
  73. #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500)
  74. /* XXX Missing magic page on 44x */
  75. r2 |= (1 << KVM_FEATURE_MAGIC_PAGE);
  76. #endif
  77. /* Second return value is in r4 */
  78. break;
  79. default:
  80. r = HC_EV_UNIMPLEMENTED;
  81. break;
  82. }
  83. kvmppc_set_gpr(vcpu, 4, r2);
  84. return r;
  85. }
  86. int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu)
  87. {
  88. enum emulation_result er;
  89. int r;
  90. er = kvmppc_emulate_instruction(run, vcpu);
  91. switch (er) {
  92. case EMULATE_DONE:
  93. /* Future optimization: only reload non-volatiles if they were
  94. * actually modified. */
  95. r = RESUME_GUEST_NV;
  96. break;
  97. case EMULATE_DO_MMIO:
  98. run->exit_reason = KVM_EXIT_MMIO;
  99. /* We must reload nonvolatiles because "update" load/store
  100. * instructions modify register state. */
  101. /* Future optimization: only reload non-volatiles if they were
  102. * actually modified. */
  103. r = RESUME_HOST_NV;
  104. break;
  105. case EMULATE_FAIL:
  106. /* XXX Deliver Program interrupt to guest. */
  107. printk(KERN_EMERG "%s: emulation failed (%08x)\n", __func__,
  108. kvmppc_get_last_inst(vcpu));
  109. r = RESUME_HOST;
  110. break;
  111. default:
  112. BUG();
  113. }
  114. return r;
  115. }
  116. int kvm_arch_hardware_enable(void *garbage)
  117. {
  118. return 0;
  119. }
  120. void kvm_arch_hardware_disable(void *garbage)
  121. {
  122. }
  123. int kvm_arch_hardware_setup(void)
  124. {
  125. return 0;
  126. }
  127. void kvm_arch_hardware_unsetup(void)
  128. {
  129. }
  130. void kvm_arch_check_processor_compat(void *rtn)
  131. {
  132. *(int *)rtn = kvmppc_core_check_processor_compat();
  133. }
  134. int kvm_arch_init_vm(struct kvm *kvm)
  135. {
  136. return kvmppc_core_init_vm(kvm);
  137. }
  138. void kvm_arch_destroy_vm(struct kvm *kvm)
  139. {
  140. unsigned int i;
  141. struct kvm_vcpu *vcpu;
  142. kvm_for_each_vcpu(i, vcpu, kvm)
  143. kvm_arch_vcpu_free(vcpu);
  144. mutex_lock(&kvm->lock);
  145. for (i = 0; i < atomic_read(&kvm->online_vcpus); i++)
  146. kvm->vcpus[i] = NULL;
  147. atomic_set(&kvm->online_vcpus, 0);
  148. kvmppc_core_destroy_vm(kvm);
  149. mutex_unlock(&kvm->lock);
  150. }
  151. void kvm_arch_sync_events(struct kvm *kvm)
  152. {
  153. }
  154. int kvm_dev_ioctl_check_extension(long ext)
  155. {
  156. int r;
  157. switch (ext) {
  158. #ifdef CONFIG_BOOKE
  159. case KVM_CAP_PPC_BOOKE_SREGS:
  160. #else
  161. case KVM_CAP_PPC_SEGSTATE:
  162. #endif
  163. case KVM_CAP_PPC_UNSET_IRQ:
  164. case KVM_CAP_PPC_IRQ_LEVEL:
  165. case KVM_CAP_ENABLE_CAP:
  166. r = 1;
  167. break;
  168. #ifndef CONFIG_KVM_BOOK3S_64_HV
  169. case KVM_CAP_PPC_PAIRED_SINGLES:
  170. case KVM_CAP_PPC_OSI:
  171. case KVM_CAP_PPC_GET_PVINFO:
  172. r = 1;
  173. break;
  174. case KVM_CAP_COALESCED_MMIO:
  175. r = KVM_COALESCED_MMIO_PAGE_OFFSET;
  176. break;
  177. #endif
  178. #ifdef CONFIG_KVM_BOOK3S_64_HV
  179. case KVM_CAP_SPAPR_TCE:
  180. r = 1;
  181. break;
  182. case KVM_CAP_PPC_SMT:
  183. r = threads_per_core;
  184. break;
  185. #endif
  186. default:
  187. r = 0;
  188. break;
  189. }
  190. return r;
  191. }
  192. long kvm_arch_dev_ioctl(struct file *filp,
  193. unsigned int ioctl, unsigned long arg)
  194. {
  195. return -EINVAL;
  196. }
  197. int kvm_arch_prepare_memory_region(struct kvm *kvm,
  198. struct kvm_memory_slot *memslot,
  199. struct kvm_memory_slot old,
  200. struct kvm_userspace_memory_region *mem,
  201. int user_alloc)
  202. {
  203. return kvmppc_core_prepare_memory_region(kvm, mem);
  204. }
  205. void kvm_arch_commit_memory_region(struct kvm *kvm,
  206. struct kvm_userspace_memory_region *mem,
  207. struct kvm_memory_slot old,
  208. int user_alloc)
  209. {
  210. kvmppc_core_commit_memory_region(kvm, mem);
  211. }
  212. void kvm_arch_flush_shadow(struct kvm *kvm)
  213. {
  214. }
  215. struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
  216. {
  217. struct kvm_vcpu *vcpu;
  218. vcpu = kvmppc_core_vcpu_create(kvm, id);
  219. if (!IS_ERR(vcpu))
  220. kvmppc_create_vcpu_debugfs(vcpu, id);
  221. return vcpu;
  222. }
  223. void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
  224. {
  225. /* Make sure we're not using the vcpu anymore */
  226. hrtimer_cancel(&vcpu->arch.dec_timer);
  227. tasklet_kill(&vcpu->arch.tasklet);
  228. kvmppc_remove_vcpu_debugfs(vcpu);
  229. kvmppc_core_vcpu_free(vcpu);
  230. }
  231. void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
  232. {
  233. kvm_arch_vcpu_free(vcpu);
  234. }
  235. int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
  236. {
  237. return kvmppc_core_pending_dec(vcpu);
  238. }
  239. static void kvmppc_decrementer_func(unsigned long data)
  240. {
  241. struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
  242. kvmppc_core_queue_dec(vcpu);
  243. if (waitqueue_active(&vcpu->wq)) {
  244. wake_up_interruptible(&vcpu->wq);
  245. vcpu->stat.halt_wakeup++;
  246. }
  247. }
  248. /*
  249. * low level hrtimer wake routine. Because this runs in hardirq context
  250. * we schedule a tasklet to do the real work.
  251. */
  252. enum hrtimer_restart kvmppc_decrementer_wakeup(struct hrtimer *timer)
  253. {
  254. struct kvm_vcpu *vcpu;
  255. vcpu = container_of(timer, struct kvm_vcpu, arch.dec_timer);
  256. tasklet_schedule(&vcpu->arch.tasklet);
  257. return HRTIMER_NORESTART;
  258. }
  259. int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
  260. {
  261. hrtimer_init(&vcpu->arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
  262. tasklet_init(&vcpu->arch.tasklet, kvmppc_decrementer_func, (ulong)vcpu);
  263. vcpu->arch.dec_timer.function = kvmppc_decrementer_wakeup;
  264. vcpu->arch.dec_expires = ~(u64)0;
  265. #ifdef CONFIG_KVM_EXIT_TIMING
  266. mutex_init(&vcpu->arch.exit_timing_lock);
  267. #endif
  268. return 0;
  269. }
  270. void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
  271. {
  272. kvmppc_mmu_destroy(vcpu);
  273. }
  274. void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
  275. {
  276. #ifdef CONFIG_BOOKE
  277. /*
  278. * vrsave (formerly usprg0) isn't used by Linux, but may
  279. * be used by the guest.
  280. *
  281. * On non-booke this is associated with Altivec and
  282. * is handled by code in book3s.c.
  283. */
  284. mtspr(SPRN_VRSAVE, vcpu->arch.vrsave);
  285. #endif
  286. kvmppc_core_vcpu_load(vcpu, cpu);
  287. vcpu->cpu = smp_processor_id();
  288. }
  289. void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
  290. {
  291. kvmppc_core_vcpu_put(vcpu);
  292. #ifdef CONFIG_BOOKE
  293. vcpu->arch.vrsave = mfspr(SPRN_VRSAVE);
  294. #endif
  295. vcpu->cpu = -1;
  296. }
  297. int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
  298. struct kvm_guest_debug *dbg)
  299. {
  300. return -EINVAL;
  301. }
  302. static void kvmppc_complete_dcr_load(struct kvm_vcpu *vcpu,
  303. struct kvm_run *run)
  304. {
  305. kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, run->dcr.data);
  306. }
  307. static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,
  308. struct kvm_run *run)
  309. {
  310. u64 uninitialized_var(gpr);
  311. if (run->mmio.len > sizeof(gpr)) {
  312. printk(KERN_ERR "bad MMIO length: %d\n", run->mmio.len);
  313. return;
  314. }
  315. if (vcpu->arch.mmio_is_bigendian) {
  316. switch (run->mmio.len) {
  317. case 8: gpr = *(u64 *)run->mmio.data; break;
  318. case 4: gpr = *(u32 *)run->mmio.data; break;
  319. case 2: gpr = *(u16 *)run->mmio.data; break;
  320. case 1: gpr = *(u8 *)run->mmio.data; break;
  321. }
  322. } else {
  323. /* Convert BE data from userland back to LE. */
  324. switch (run->mmio.len) {
  325. case 4: gpr = ld_le32((u32 *)run->mmio.data); break;
  326. case 2: gpr = ld_le16((u16 *)run->mmio.data); break;
  327. case 1: gpr = *(u8 *)run->mmio.data; break;
  328. }
  329. }
  330. if (vcpu->arch.mmio_sign_extend) {
  331. switch (run->mmio.len) {
  332. #ifdef CONFIG_PPC64
  333. case 4:
  334. gpr = (s64)(s32)gpr;
  335. break;
  336. #endif
  337. case 2:
  338. gpr = (s64)(s16)gpr;
  339. break;
  340. case 1:
  341. gpr = (s64)(s8)gpr;
  342. break;
  343. }
  344. }
  345. kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, gpr);
  346. switch (vcpu->arch.io_gpr & KVM_REG_EXT_MASK) {
  347. case KVM_REG_GPR:
  348. kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, gpr);
  349. break;
  350. case KVM_REG_FPR:
  351. vcpu->arch.fpr[vcpu->arch.io_gpr & KVM_REG_MASK] = gpr;
  352. break;
  353. #ifdef CONFIG_PPC_BOOK3S
  354. case KVM_REG_QPR:
  355. vcpu->arch.qpr[vcpu->arch.io_gpr & KVM_REG_MASK] = gpr;
  356. break;
  357. case KVM_REG_FQPR:
  358. vcpu->arch.fpr[vcpu->arch.io_gpr & KVM_REG_MASK] = gpr;
  359. vcpu->arch.qpr[vcpu->arch.io_gpr & KVM_REG_MASK] = gpr;
  360. break;
  361. #endif
  362. default:
  363. BUG();
  364. }
  365. }
  366. int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
  367. unsigned int rt, unsigned int bytes, int is_bigendian)
  368. {
  369. if (bytes > sizeof(run->mmio.data)) {
  370. printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__,
  371. run->mmio.len);
  372. }
  373. run->mmio.phys_addr = vcpu->arch.paddr_accessed;
  374. run->mmio.len = bytes;
  375. run->mmio.is_write = 0;
  376. vcpu->arch.io_gpr = rt;
  377. vcpu->arch.mmio_is_bigendian = is_bigendian;
  378. vcpu->mmio_needed = 1;
  379. vcpu->mmio_is_write = 0;
  380. vcpu->arch.mmio_sign_extend = 0;
  381. return EMULATE_DO_MMIO;
  382. }
  383. /* Same as above, but sign extends */
  384. int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,
  385. unsigned int rt, unsigned int bytes, int is_bigendian)
  386. {
  387. int r;
  388. r = kvmppc_handle_load(run, vcpu, rt, bytes, is_bigendian);
  389. vcpu->arch.mmio_sign_extend = 1;
  390. return r;
  391. }
  392. int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
  393. u64 val, unsigned int bytes, int is_bigendian)
  394. {
  395. void *data = run->mmio.data;
  396. if (bytes > sizeof(run->mmio.data)) {
  397. printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__,
  398. run->mmio.len);
  399. }
  400. run->mmio.phys_addr = vcpu->arch.paddr_accessed;
  401. run->mmio.len = bytes;
  402. run->mmio.is_write = 1;
  403. vcpu->mmio_needed = 1;
  404. vcpu->mmio_is_write = 1;
  405. /* Store the value at the lowest bytes in 'data'. */
  406. if (is_bigendian) {
  407. switch (bytes) {
  408. case 8: *(u64 *)data = val; break;
  409. case 4: *(u32 *)data = val; break;
  410. case 2: *(u16 *)data = val; break;
  411. case 1: *(u8 *)data = val; break;
  412. }
  413. } else {
  414. /* Store LE value into 'data'. */
  415. switch (bytes) {
  416. case 4: st_le32(data, val); break;
  417. case 2: st_le16(data, val); break;
  418. case 1: *(u8 *)data = val; break;
  419. }
  420. }
  421. return EMULATE_DO_MMIO;
  422. }
  423. int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  424. {
  425. int r;
  426. sigset_t sigsaved;
  427. if (vcpu->sigset_active)
  428. sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
  429. if (vcpu->mmio_needed) {
  430. if (!vcpu->mmio_is_write)
  431. kvmppc_complete_mmio_load(vcpu, run);
  432. vcpu->mmio_needed = 0;
  433. } else if (vcpu->arch.dcr_needed) {
  434. if (!vcpu->arch.dcr_is_write)
  435. kvmppc_complete_dcr_load(vcpu, run);
  436. vcpu->arch.dcr_needed = 0;
  437. } else if (vcpu->arch.osi_needed) {
  438. u64 *gprs = run->osi.gprs;
  439. int i;
  440. for (i = 0; i < 32; i++)
  441. kvmppc_set_gpr(vcpu, i, gprs[i]);
  442. vcpu->arch.osi_needed = 0;
  443. } else if (vcpu->arch.hcall_needed) {
  444. int i;
  445. kvmppc_set_gpr(vcpu, 3, run->papr_hcall.ret);
  446. for (i = 0; i < 9; ++i)
  447. kvmppc_set_gpr(vcpu, 4 + i, run->papr_hcall.args[i]);
  448. vcpu->arch.hcall_needed = 0;
  449. }
  450. kvmppc_core_deliver_interrupts(vcpu);
  451. r = kvmppc_vcpu_run(run, vcpu);
  452. if (vcpu->sigset_active)
  453. sigprocmask(SIG_SETMASK, &sigsaved, NULL);
  454. return r;
  455. }
  456. int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq)
  457. {
  458. if (irq->irq == KVM_INTERRUPT_UNSET)
  459. kvmppc_core_dequeue_external(vcpu, irq);
  460. else
  461. kvmppc_core_queue_external(vcpu, irq);
  462. if (waitqueue_active(&vcpu->wq)) {
  463. wake_up_interruptible(&vcpu->wq);
  464. vcpu->stat.halt_wakeup++;
  465. } else if (vcpu->cpu != -1) {
  466. smp_send_reschedule(vcpu->cpu);
  467. }
  468. return 0;
  469. }
  470. static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
  471. struct kvm_enable_cap *cap)
  472. {
  473. int r;
  474. if (cap->flags)
  475. return -EINVAL;
  476. switch (cap->cap) {
  477. case KVM_CAP_PPC_OSI:
  478. r = 0;
  479. vcpu->arch.osi_enabled = true;
  480. break;
  481. default:
  482. r = -EINVAL;
  483. break;
  484. }
  485. return r;
  486. }
  487. int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
  488. struct kvm_mp_state *mp_state)
  489. {
  490. return -EINVAL;
  491. }
  492. int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
  493. struct kvm_mp_state *mp_state)
  494. {
  495. return -EINVAL;
  496. }
  497. long kvm_arch_vcpu_ioctl(struct file *filp,
  498. unsigned int ioctl, unsigned long arg)
  499. {
  500. struct kvm_vcpu *vcpu = filp->private_data;
  501. void __user *argp = (void __user *)arg;
  502. long r;
  503. switch (ioctl) {
  504. case KVM_INTERRUPT: {
  505. struct kvm_interrupt irq;
  506. r = -EFAULT;
  507. if (copy_from_user(&irq, argp, sizeof(irq)))
  508. goto out;
  509. r = kvm_vcpu_ioctl_interrupt(vcpu, &irq);
  510. goto out;
  511. }
  512. case KVM_ENABLE_CAP:
  513. {
  514. struct kvm_enable_cap cap;
  515. r = -EFAULT;
  516. if (copy_from_user(&cap, argp, sizeof(cap)))
  517. goto out;
  518. r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
  519. break;
  520. }
  521. default:
  522. r = -EINVAL;
  523. }
  524. out:
  525. return r;
  526. }
  527. static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
  528. {
  529. u32 inst_lis = 0x3c000000;
  530. u32 inst_ori = 0x60000000;
  531. u32 inst_nop = 0x60000000;
  532. u32 inst_sc = 0x44000002;
  533. u32 inst_imm_mask = 0xffff;
  534. /*
  535. * The hypercall to get into KVM from within guest context is as
  536. * follows:
  537. *
  538. * lis r0, r0, KVM_SC_MAGIC_R0@h
  539. * ori r0, KVM_SC_MAGIC_R0@l
  540. * sc
  541. * nop
  542. */
  543. pvinfo->hcall[0] = inst_lis | ((KVM_SC_MAGIC_R0 >> 16) & inst_imm_mask);
  544. pvinfo->hcall[1] = inst_ori | (KVM_SC_MAGIC_R0 & inst_imm_mask);
  545. pvinfo->hcall[2] = inst_sc;
  546. pvinfo->hcall[3] = inst_nop;
  547. return 0;
  548. }
  549. long kvm_arch_vm_ioctl(struct file *filp,
  550. unsigned int ioctl, unsigned long arg)
  551. {
  552. void __user *argp = (void __user *)arg;
  553. long r;
  554. switch (ioctl) {
  555. case KVM_PPC_GET_PVINFO: {
  556. struct kvm_ppc_pvinfo pvinfo;
  557. memset(&pvinfo, 0, sizeof(pvinfo));
  558. r = kvm_vm_ioctl_get_pvinfo(&pvinfo);
  559. if (copy_to_user(argp, &pvinfo, sizeof(pvinfo))) {
  560. r = -EFAULT;
  561. goto out;
  562. }
  563. break;
  564. }
  565. #ifdef CONFIG_KVM_BOOK3S_64_HV
  566. case KVM_CREATE_SPAPR_TCE: {
  567. struct kvm_create_spapr_tce create_tce;
  568. struct kvm *kvm = filp->private_data;
  569. r = -EFAULT;
  570. if (copy_from_user(&create_tce, argp, sizeof(create_tce)))
  571. goto out;
  572. r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce);
  573. goto out;
  574. }
  575. #endif /* CONFIG_KVM_BOOK3S_64_HV */
  576. default:
  577. r = -ENOTTY;
  578. }
  579. out:
  580. return r;
  581. }
  582. int kvm_arch_init(void *opaque)
  583. {
  584. return 0;
  585. }
  586. void kvm_arch_exit(void)
  587. {
  588. }