kvm_host.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  3. * Author: Christoffer Dall <c.dall@virtualopensystems.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License, version 2, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef __ARM_KVM_HOST_H__
  19. #define __ARM_KVM_HOST_H__
  20. #include <linux/types.h>
  21. #include <linux/kvm_types.h>
  22. #include <asm/kvm.h>
  23. #include <asm/kvm_asm.h>
  24. #include <asm/kvm_mmio.h>
  25. #include <asm/fpstate.h>
  26. #include <kvm/arm_arch_timer.h>
  27. #if defined(CONFIG_KVM_ARM_MAX_VCPUS)
  28. #define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS
  29. #else
  30. #define KVM_MAX_VCPUS 0
  31. #endif
  32. #define KVM_USER_MEM_SLOTS 32
  33. #define KVM_PRIVATE_MEM_SLOTS 4
  34. #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
  35. #define KVM_HAVE_ONE_REG
  36. #define KVM_VCPU_MAX_FEATURES 2
  37. #include <kvm/arm_vgic.h>
  38. u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
  39. int __attribute_const__ kvm_target_cpu(void);
  40. int kvm_reset_vcpu(struct kvm_vcpu *vcpu);
  41. void kvm_reset_coprocs(struct kvm_vcpu *vcpu);
  42. struct kvm_arch {
  43. /* VTTBR value associated with below pgd and vmid */
  44. u64 vttbr;
  45. /* Timer */
  46. struct arch_timer_kvm timer;
  47. /*
  48. * Anything that is not used directly from assembly code goes
  49. * here.
  50. */
  51. /* The VMID generation used for the virt. memory system */
  52. u64 vmid_gen;
  53. u32 vmid;
  54. /* Stage-2 page table */
  55. pgd_t *pgd;
  56. /* Interrupt controller */
  57. struct vgic_dist vgic;
  58. };
  59. #define KVM_NR_MEM_OBJS 40
  60. /*
  61. * We don't want allocation failures within the mmu code, so we preallocate
  62. * enough memory for a single page fault in a cache.
  63. */
  64. struct kvm_mmu_memory_cache {
  65. int nobjs;
  66. void *objects[KVM_NR_MEM_OBJS];
  67. };
  68. struct kvm_vcpu_fault_info {
  69. u32 hsr; /* Hyp Syndrome Register */
  70. u32 hxfar; /* Hyp Data/Inst. Fault Address Register */
  71. u32 hpfar; /* Hyp IPA Fault Address Register */
  72. u32 hyp_pc; /* PC when exception was taken from Hyp mode */
  73. };
  74. typedef struct vfp_hard_struct kvm_cpu_context_t;
  75. struct kvm_vcpu_arch {
  76. struct kvm_regs regs;
  77. int target; /* Processor target */
  78. DECLARE_BITMAP(features, KVM_VCPU_MAX_FEATURES);
  79. /* System control coprocessor (cp15) */
  80. u32 cp15[NR_CP15_REGS];
  81. /* The CPU type we expose to the VM */
  82. u32 midr;
  83. /* HYP trapping configuration */
  84. u32 hcr;
  85. /* Interrupt related fields */
  86. u32 irq_lines; /* IRQ and FIQ levels */
  87. /* Exception Information */
  88. struct kvm_vcpu_fault_info fault;
  89. /* Floating point registers (VFP and Advanced SIMD/NEON) */
  90. struct vfp_hard_struct vfp_guest;
  91. /* Host FP context */
  92. kvm_cpu_context_t *host_cpu_context;
  93. /* VGIC state */
  94. struct vgic_cpu vgic_cpu;
  95. struct arch_timer_cpu timer_cpu;
  96. /*
  97. * Anything that is not used directly from assembly code goes
  98. * here.
  99. */
  100. /* Don't run the guest on this vcpu */
  101. bool pause;
  102. /* IO related fields */
  103. struct kvm_decode mmio_decode;
  104. /* Cache some mmu pages needed inside spinlock regions */
  105. struct kvm_mmu_memory_cache mmu_page_cache;
  106. /* Detect first run of a vcpu */
  107. bool has_run_once;
  108. };
  109. struct kvm_vm_stat {
  110. u32 remote_tlb_flush;
  111. };
  112. struct kvm_vcpu_stat {
  113. u32 halt_wakeup;
  114. };
  115. int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
  116. unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
  117. int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
  118. int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
  119. int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
  120. u64 kvm_call_hyp(void *hypfn, ...);
  121. void force_vm_exit(const cpumask_t *mask);
  122. #define KVM_ARCH_WANT_MMU_NOTIFIER
  123. int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
  124. int kvm_unmap_hva_range(struct kvm *kvm,
  125. unsigned long start, unsigned long end);
  126. void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
  127. unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
  128. int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
  129. /* We do not have shadow page tables, hence the empty hooks */
  130. static inline int kvm_age_hva(struct kvm *kvm, unsigned long start,
  131. unsigned long end)
  132. {
  133. return 0;
  134. }
  135. static inline int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)
  136. {
  137. return 0;
  138. }
  139. static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
  140. unsigned long address)
  141. {
  142. }
  143. struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
  144. struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
  145. int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
  146. unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu);
  147. int kvm_arm_coproc_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
  148. int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
  149. int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
  150. int exception_index);
  151. static inline void __cpu_init_hyp_mode(phys_addr_t boot_pgd_ptr,
  152. phys_addr_t pgd_ptr,
  153. unsigned long hyp_stack_ptr,
  154. unsigned long vector_ptr)
  155. {
  156. /*
  157. * Call initialization code, and switch to the full blown HYP
  158. * code. The init code doesn't need to preserve these
  159. * registers as r0-r3 are already callee saved according to
  160. * the AAPCS.
  161. * Note that we slightly misuse the prototype by casing the
  162. * stack pointer to a void *.
  163. *
  164. * We don't have enough registers to perform the full init in
  165. * one go. Install the boot PGD first, and then install the
  166. * runtime PGD, stack pointer and vectors. The PGDs are always
  167. * passed as the third argument, in order to be passed into
  168. * r2-r3 to the init code (yes, this is compliant with the
  169. * PCS!).
  170. */
  171. kvm_call_hyp(NULL, 0, boot_pgd_ptr);
  172. kvm_call_hyp((void*)hyp_stack_ptr, vector_ptr, pgd_ptr);
  173. }
  174. static inline int kvm_arch_dev_ioctl_check_extension(long ext)
  175. {
  176. return 0;
  177. }
  178. static inline void vgic_arch_setup(const struct vgic_params *vgic)
  179. {
  180. BUG_ON(vgic->type != VGIC_V2);
  181. }
  182. int kvm_perf_init(void);
  183. int kvm_perf_teardown(void);
  184. static inline void kvm_arch_hardware_disable(void) {}
  185. static inline void kvm_arch_hardware_unsetup(void) {}
  186. static inline void kvm_arch_sync_events(struct kvm *kvm) {}
  187. static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
  188. static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
  189. #endif /* __ARM_KVM_HOST_H__ */