kvm_host.h 6.7 KB

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