kvm_host.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. */
  19. #ifndef __POWERPC_KVM_HOST_H__
  20. #define __POWERPC_KVM_HOST_H__
  21. #include <linux/mutex.h>
  22. #include <linux/hrtimer.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/types.h>
  25. #include <linux/kvm_types.h>
  26. #include <linux/kvm_para.h>
  27. #include <asm/kvm_asm.h>
  28. #define KVM_MAX_VCPUS 1
  29. #define KVM_MEMORY_SLOTS 32
  30. /* memory slots that does not exposed to userspace */
  31. #define KVM_PRIVATE_MEM_SLOTS 4
  32. #ifdef CONFIG_KVM_MMIO
  33. #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
  34. #endif
  35. /* We don't currently support large pages. */
  36. #define KVM_HPAGE_GFN_SHIFT(x) 0
  37. #define KVM_NR_PAGE_SIZES 1
  38. #define KVM_PAGES_PER_HPAGE(x) (1UL<<31)
  39. #define HPTEG_CACHE_NUM (1 << 15)
  40. #define HPTEG_HASH_BITS_PTE 13
  41. #define HPTEG_HASH_BITS_PTE_LONG 12
  42. #define HPTEG_HASH_BITS_VPTE 13
  43. #define HPTEG_HASH_BITS_VPTE_LONG 5
  44. #define HPTEG_HASH_NUM_PTE (1 << HPTEG_HASH_BITS_PTE)
  45. #define HPTEG_HASH_NUM_PTE_LONG (1 << HPTEG_HASH_BITS_PTE_LONG)
  46. #define HPTEG_HASH_NUM_VPTE (1 << HPTEG_HASH_BITS_VPTE)
  47. #define HPTEG_HASH_NUM_VPTE_LONG (1 << HPTEG_HASH_BITS_VPTE_LONG)
  48. /* Physical Address Mask - allowed range of real mode RAM access */
  49. #define KVM_PAM 0x0fffffffffffffffULL
  50. struct kvm;
  51. struct kvm_run;
  52. struct kvm_vcpu;
  53. struct kvm_vm_stat {
  54. u32 remote_tlb_flush;
  55. };
  56. struct kvm_vcpu_stat {
  57. u32 sum_exits;
  58. u32 mmio_exits;
  59. u32 dcr_exits;
  60. u32 signal_exits;
  61. u32 light_exits;
  62. /* Account for special types of light exits: */
  63. u32 itlb_real_miss_exits;
  64. u32 itlb_virt_miss_exits;
  65. u32 dtlb_real_miss_exits;
  66. u32 dtlb_virt_miss_exits;
  67. u32 syscall_exits;
  68. u32 isi_exits;
  69. u32 dsi_exits;
  70. u32 emulated_inst_exits;
  71. u32 dec_exits;
  72. u32 ext_intr_exits;
  73. u32 halt_wakeup;
  74. #ifdef CONFIG_PPC_BOOK3S
  75. u32 pf_storage;
  76. u32 pf_instruc;
  77. u32 sp_storage;
  78. u32 sp_instruc;
  79. u32 queue_intr;
  80. u32 ld;
  81. u32 ld_slow;
  82. u32 st;
  83. u32 st_slow;
  84. #endif
  85. };
  86. enum kvm_exit_types {
  87. MMIO_EXITS,
  88. DCR_EXITS,
  89. SIGNAL_EXITS,
  90. ITLB_REAL_MISS_EXITS,
  91. ITLB_VIRT_MISS_EXITS,
  92. DTLB_REAL_MISS_EXITS,
  93. DTLB_VIRT_MISS_EXITS,
  94. SYSCALL_EXITS,
  95. ISI_EXITS,
  96. DSI_EXITS,
  97. EMULATED_INST_EXITS,
  98. EMULATED_MTMSRWE_EXITS,
  99. EMULATED_WRTEE_EXITS,
  100. EMULATED_MTSPR_EXITS,
  101. EMULATED_MFSPR_EXITS,
  102. EMULATED_MTMSR_EXITS,
  103. EMULATED_MFMSR_EXITS,
  104. EMULATED_TLBSX_EXITS,
  105. EMULATED_TLBWE_EXITS,
  106. EMULATED_RFI_EXITS,
  107. DEC_EXITS,
  108. EXT_INTR_EXITS,
  109. HALT_WAKEUP,
  110. USR_PR_INST,
  111. FP_UNAVAIL,
  112. DEBUG_EXITS,
  113. TIMEINGUEST,
  114. __NUMBER_OF_KVM_EXIT_TYPES
  115. };
  116. /* allow access to big endian 32bit upper/lower parts and 64bit var */
  117. struct kvmppc_exit_timing {
  118. union {
  119. u64 tv64;
  120. struct {
  121. u32 tbu, tbl;
  122. } tv32;
  123. };
  124. };
  125. struct kvmppc_pginfo {
  126. unsigned long pfn;
  127. atomic_t refcnt;
  128. };
  129. struct kvm_arch {
  130. #ifdef CONFIG_KVM_BOOK3S_64_HV
  131. unsigned long hpt_virt;
  132. unsigned long ram_npages;
  133. unsigned long ram_psize;
  134. unsigned long ram_porder;
  135. struct kvmppc_pginfo *ram_pginfo;
  136. unsigned int lpid;
  137. unsigned int host_lpid;
  138. unsigned long host_lpcr;
  139. unsigned long sdr1;
  140. unsigned long host_sdr1;
  141. int tlbie_lock;
  142. unsigned short last_vcpu[NR_CPUS];
  143. #endif /* CONFIG_KVM_BOOK3S_64_HV */
  144. };
  145. struct kvmppc_pte {
  146. ulong eaddr;
  147. u64 vpage;
  148. ulong raddr;
  149. bool may_read : 1;
  150. bool may_write : 1;
  151. bool may_execute : 1;
  152. };
  153. struct kvmppc_mmu {
  154. /* book3s_64 only */
  155. void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs);
  156. u64 (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr);
  157. u64 (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr);
  158. void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr);
  159. void (*slbia)(struct kvm_vcpu *vcpu);
  160. /* book3s */
  161. void (*mtsrin)(struct kvm_vcpu *vcpu, u32 srnum, ulong value);
  162. u32 (*mfsrin)(struct kvm_vcpu *vcpu, u32 srnum);
  163. int (*xlate)(struct kvm_vcpu *vcpu, gva_t eaddr, struct kvmppc_pte *pte, bool data);
  164. void (*reset_msr)(struct kvm_vcpu *vcpu);
  165. void (*tlbie)(struct kvm_vcpu *vcpu, ulong addr, bool large);
  166. int (*esid_to_vsid)(struct kvm_vcpu *vcpu, ulong esid, u64 *vsid);
  167. u64 (*ea_to_vp)(struct kvm_vcpu *vcpu, gva_t eaddr, bool data);
  168. bool (*is_dcbz32)(struct kvm_vcpu *vcpu);
  169. };
  170. struct kvmppc_slb {
  171. u64 esid;
  172. u64 vsid;
  173. u64 orige;
  174. u64 origv;
  175. bool valid : 1;
  176. bool Ks : 1;
  177. bool Kp : 1;
  178. bool nx : 1;
  179. bool large : 1; /* PTEs are 16MB */
  180. bool tb : 1; /* 1TB segment */
  181. bool class : 1;
  182. };
  183. struct kvm_vcpu_arch {
  184. ulong host_stack;
  185. u32 host_pid;
  186. #ifdef CONFIG_PPC_BOOK3S
  187. ulong host_msr;
  188. ulong host_r2;
  189. void *host_retip;
  190. ulong trampoline_lowmem;
  191. ulong trampoline_enter;
  192. ulong highmem_handler;
  193. ulong rmcall;
  194. ulong host_paca_phys;
  195. struct kvmppc_slb slb[64];
  196. int slb_max; /* 1 + index of last valid entry in slb[] */
  197. int slb_nr; /* total number of entries in SLB */
  198. struct kvmppc_mmu mmu;
  199. #endif
  200. ulong gpr[32];
  201. u64 fpr[32];
  202. u64 fpscr;
  203. #ifdef CONFIG_SPE
  204. ulong evr[32];
  205. ulong spefscr;
  206. ulong host_spefscr;
  207. u64 acc;
  208. #endif
  209. #ifdef CONFIG_ALTIVEC
  210. vector128 vr[32];
  211. vector128 vscr;
  212. #endif
  213. #ifdef CONFIG_VSX
  214. u64 vsr[64];
  215. #endif
  216. #ifdef CONFIG_PPC_BOOK3S
  217. /* For Gekko paired singles */
  218. u32 qpr[32];
  219. #endif
  220. ulong pc;
  221. ulong ctr;
  222. ulong lr;
  223. ulong xer;
  224. u32 cr;
  225. #ifdef CONFIG_PPC_BOOK3S
  226. ulong hflags;
  227. ulong guest_owned_ext;
  228. ulong purr;
  229. ulong spurr;
  230. ulong lpcr;
  231. ulong dscr;
  232. ulong amr;
  233. ulong uamor;
  234. u32 ctrl;
  235. ulong dabr;
  236. #endif
  237. u32 vrsave; /* also USPRG0 */
  238. u32 mmucr;
  239. ulong shadow_msr;
  240. ulong sprg4;
  241. ulong sprg5;
  242. ulong sprg6;
  243. ulong sprg7;
  244. ulong csrr0;
  245. ulong csrr1;
  246. ulong dsrr0;
  247. ulong dsrr1;
  248. ulong mcsrr0;
  249. ulong mcsrr1;
  250. ulong mcsr;
  251. ulong esr;
  252. u32 dec;
  253. u32 decar;
  254. u32 tbl;
  255. u32 tbu;
  256. u32 tcr;
  257. u32 tsr;
  258. u32 ivor[64];
  259. ulong ivpr;
  260. u32 pir;
  261. u32 pvr;
  262. u32 shadow_pid;
  263. u32 shadow_pid1;
  264. u32 pid;
  265. u32 swap_pid;
  266. u32 ccr0;
  267. u32 ccr1;
  268. u32 dbcr0;
  269. u32 dbcr1;
  270. u32 dbsr;
  271. u64 mmcr[3];
  272. u32 pmc[6];
  273. #ifdef CONFIG_KVM_EXIT_TIMING
  274. struct mutex exit_timing_lock;
  275. struct kvmppc_exit_timing timing_exit;
  276. struct kvmppc_exit_timing timing_last_enter;
  277. u32 last_exit_type;
  278. u32 timing_count_type[__NUMBER_OF_KVM_EXIT_TYPES];
  279. u64 timing_sum_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  280. u64 timing_sum_quad_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  281. u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  282. u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  283. u64 timing_last_exit;
  284. struct dentry *debugfs_exit_timing;
  285. #endif
  286. #ifdef CONFIG_PPC_BOOK3S
  287. ulong fault_dar;
  288. u32 fault_dsisr;
  289. #endif
  290. #ifdef CONFIG_BOOKE
  291. ulong fault_dear;
  292. ulong fault_esr;
  293. ulong queued_dear;
  294. ulong queued_esr;
  295. #endif
  296. gpa_t paddr_accessed;
  297. u8 io_gpr; /* GPR used as IO source/target */
  298. u8 mmio_is_bigendian;
  299. u8 mmio_sign_extend;
  300. u8 dcr_needed;
  301. u8 dcr_is_write;
  302. u8 osi_needed;
  303. u8 osi_enabled;
  304. u8 hcall_needed;
  305. u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
  306. struct hrtimer dec_timer;
  307. struct tasklet_struct tasklet;
  308. u64 dec_jiffies;
  309. u64 dec_expires;
  310. unsigned long pending_exceptions;
  311. u16 last_cpu;
  312. u32 last_inst;
  313. int trap;
  314. struct kvm_vcpu_arch_shared *shared;
  315. unsigned long magic_page_pa; /* phys addr to map the magic page to */
  316. unsigned long magic_page_ea; /* effect. addr to map the magic page to */
  317. #ifdef CONFIG_KVM_BOOK3S_64_HV
  318. struct kvm_vcpu_arch_shared shregs;
  319. #endif
  320. };
  321. #endif /* __POWERPC_KVM_HOST_H__ */