kvm_ppc.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. 2008
  16. *
  17. * Authors: Hollis Blanchard <hollisb@us.ibm.com>
  18. */
  19. #ifndef __POWERPC_KVM_PPC_H__
  20. #define __POWERPC_KVM_PPC_H__
  21. /* This file exists just so we can dereference kvm_vcpu, avoiding nested header
  22. * dependencies. */
  23. #include <linux/mutex.h>
  24. #include <linux/timer.h>
  25. #include <linux/types.h>
  26. #include <linux/kvm_types.h>
  27. #include <linux/kvm_host.h>
  28. #ifdef CONFIG_PPC_BOOK3S
  29. #include <asm/kvm_book3s.h>
  30. #else
  31. #include <asm/kvm_booke.h>
  32. #endif
  33. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  34. #include <asm/paca.h>
  35. #endif
  36. enum emulation_result {
  37. EMULATE_DONE, /* no further processing */
  38. EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */
  39. EMULATE_DO_DCR, /* kvm_run filled with DCR request */
  40. EMULATE_FAIL, /* can't emulate this instruction */
  41. EMULATE_AGAIN, /* something went wrong. go again */
  42. };
  43. extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
  44. extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
  45. extern char kvmppc_handlers_start[];
  46. extern unsigned long kvmppc_handler_len;
  47. extern void kvmppc_handler_highmem(void);
  48. extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
  49. extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
  50. unsigned int rt, unsigned int bytes,
  51. int is_bigendian);
  52. extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,
  53. unsigned int rt, unsigned int bytes,
  54. int is_bigendian);
  55. extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
  56. u64 val, unsigned int bytes, int is_bigendian);
  57. extern int kvmppc_emulate_instruction(struct kvm_run *run,
  58. struct kvm_vcpu *vcpu);
  59. extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
  60. extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
  61. extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
  62. extern void kvmppc_decrementer_func(unsigned long data);
  63. extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu);
  64. /* Core-specific hooks */
  65. extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr,
  66. unsigned int gtlb_idx);
  67. extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode);
  68. extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid);
  69. extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu);
  70. extern int kvmppc_mmu_init(struct kvm_vcpu *vcpu);
  71. extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
  72. extern int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
  73. extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index,
  74. gva_t eaddr);
  75. extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu);
  76. extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu);
  77. extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm,
  78. unsigned int id);
  79. extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu);
  80. extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu);
  81. extern int kvmppc_core_check_processor_compat(void);
  82. extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
  83. struct kvm_translation *tr);
  84. extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
  85. extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu);
  86. extern void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu);
  87. extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
  88. extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags);
  89. extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);
  90. extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu);
  91. extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
  92. struct kvm_interrupt *irq);
  93. extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
  94. struct kvm_interrupt *irq);
  95. extern int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
  96. unsigned int op, int *advance);
  97. extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs);
  98. extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt);
  99. extern int kvmppc_booke_init(void);
  100. extern void kvmppc_booke_exit(void);
  101. extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu);
  102. extern int kvmppc_kvm_pv(struct kvm_vcpu *vcpu);
  103. extern void kvmppc_map_magic(struct kvm_vcpu *vcpu);
  104. extern long kvmppc_alloc_hpt(struct kvm *kvm);
  105. extern void kvmppc_free_hpt(struct kvm *kvm);
  106. extern long kvmppc_prepare_vrma(struct kvm *kvm,
  107. struct kvm_userspace_memory_region *mem);
  108. extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu,
  109. struct kvm_memory_slot *memslot, unsigned long porder);
  110. extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu);
  111. extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
  112. struct kvm_create_spapr_tce *args);
  113. extern long kvm_vm_ioctl_allocate_rma(struct kvm *kvm,
  114. struct kvm_allocate_rma *rma);
  115. extern struct kvmppc_linear_info *kvm_alloc_rma(void);
  116. extern void kvm_release_rma(struct kvmppc_linear_info *ri);
  117. extern struct kvmppc_linear_info *kvm_alloc_hpt(void);
  118. extern void kvm_release_hpt(struct kvmppc_linear_info *li);
  119. extern int kvmppc_core_init_vm(struct kvm *kvm);
  120. extern void kvmppc_core_destroy_vm(struct kvm *kvm);
  121. extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
  122. struct kvm_userspace_memory_region *mem);
  123. extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
  124. struct kvm_userspace_memory_region *mem);
  125. /*
  126. * Cuts out inst bits with ordering according to spec.
  127. * That means the leftmost bit is zero. All given bits are included.
  128. */
  129. static inline u32 kvmppc_get_field(u64 inst, int msb, int lsb)
  130. {
  131. u32 r;
  132. u32 mask;
  133. BUG_ON(msb > lsb);
  134. mask = (1 << (lsb - msb + 1)) - 1;
  135. r = (inst >> (63 - lsb)) & mask;
  136. return r;
  137. }
  138. /*
  139. * Replaces inst bits with ordering according to spec.
  140. */
  141. static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
  142. {
  143. u32 r;
  144. u32 mask;
  145. BUG_ON(msb > lsb);
  146. mask = ((1 << (lsb - msb + 1)) - 1) << (63 - lsb);
  147. r = (inst & ~mask) | ((value << (63 - lsb)) & mask);
  148. return r;
  149. }
  150. void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
  151. int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
  152. void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
  153. int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
  154. int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
  155. int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
  156. void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);
  157. #ifdef CONFIG_KVM_BOOK3S_64_HV
  158. static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
  159. {
  160. paca[cpu].kvm_hstate.xics_phys = addr;
  161. }
  162. extern void kvm_linear_init(void);
  163. #else
  164. static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
  165. {}
  166. static inline void kvm_linear_init(void)
  167. {}
  168. #endif
  169. int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
  170. struct kvm_config_tlb *cfg);
  171. int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
  172. struct kvm_dirty_tlb *cfg);
  173. #endif /* __POWERPC_KVM_PPC_H__ */