vcpu.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. /*
  2. * vcpu.h: vcpu routines
  3. * Copyright (c) 2005, Intel Corporation.
  4. * Xuefei Xu (Anthony Xu) (Anthony.xu@intel.com)
  5. * Yaozu Dong (Eddie Dong) (Eddie.dong@intel.com)
  6. *
  7. * Copyright (c) 2007, Intel Corporation.
  8. * Xuefei Xu (Anthony Xu) (Anthony.xu@intel.com)
  9. * Xiantao Zhang (xiantao.zhang@intel.com)
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms and conditions of the GNU General Public License,
  13. * version 2, as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  18. * more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along with
  21. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  22. * Place - Suite 330, Boston, MA 02111-1307 USA.
  23. *
  24. */
  25. #ifndef __KVM_VCPU_H__
  26. #define __KVM_VCPU_H__
  27. #include <asm/types.h>
  28. #include <asm/fpu.h>
  29. #include <asm/processor.h>
  30. #ifndef __ASSEMBLY__
  31. #include "vti.h"
  32. #include <linux/kvm_host.h>
  33. #include <linux/spinlock.h>
  34. typedef unsigned long IA64_INST;
  35. typedef union U_IA64_BUNDLE {
  36. unsigned long i64[2];
  37. struct { unsigned long template:5, slot0:41, slot1a:18,
  38. slot1b:23, slot2:41; };
  39. /* NOTE: following doesn't work because bitfields can't cross natural
  40. size boundaries
  41. struct { unsigned long template:5, slot0:41, slot1:41, slot2:41; }; */
  42. } IA64_BUNDLE;
  43. typedef union U_INST64_A5 {
  44. IA64_INST inst;
  45. struct { unsigned long qp:6, r1:7, imm7b:7, r3:2, imm5c:5,
  46. imm9d:9, s:1, major:4; };
  47. } INST64_A5;
  48. typedef union U_INST64_B4 {
  49. IA64_INST inst;
  50. struct { unsigned long qp:6, btype:3, un3:3, p:1, b2:3, un11:11, x6:6,
  51. wh:2, d:1, un1:1, major:4; };
  52. } INST64_B4;
  53. typedef union U_INST64_B8 {
  54. IA64_INST inst;
  55. struct { unsigned long qp:6, un21:21, x6:6, un4:4, major:4; };
  56. } INST64_B8;
  57. typedef union U_INST64_B9 {
  58. IA64_INST inst;
  59. struct { unsigned long qp:6, imm20:20, :1, x6:6, :3, i:1, major:4; };
  60. } INST64_B9;
  61. typedef union U_INST64_I19 {
  62. IA64_INST inst;
  63. struct { unsigned long qp:6, imm20:20, :1, x6:6, x3:3, i:1, major:4; };
  64. } INST64_I19;
  65. typedef union U_INST64_I26 {
  66. IA64_INST inst;
  67. struct { unsigned long qp:6, :7, r2:7, ar3:7, x6:6, x3:3, :1, major:4; };
  68. } INST64_I26;
  69. typedef union U_INST64_I27 {
  70. IA64_INST inst;
  71. struct { unsigned long qp:6, :7, imm:7, ar3:7, x6:6, x3:3, s:1, major:4; };
  72. } INST64_I27;
  73. typedef union U_INST64_I28 { /* not privileged (mov from AR) */
  74. IA64_INST inst;
  75. struct { unsigned long qp:6, r1:7, :7, ar3:7, x6:6, x3:3, :1, major:4; };
  76. } INST64_I28;
  77. typedef union U_INST64_M28 {
  78. IA64_INST inst;
  79. struct { unsigned long qp:6, :14, r3:7, x6:6, x3:3, :1, major:4; };
  80. } INST64_M28;
  81. typedef union U_INST64_M29 {
  82. IA64_INST inst;
  83. struct { unsigned long qp:6, :7, r2:7, ar3:7, x6:6, x3:3, :1, major:4; };
  84. } INST64_M29;
  85. typedef union U_INST64_M30 {
  86. IA64_INST inst;
  87. struct { unsigned long qp:6, :7, imm:7, ar3:7, x4:4, x2:2,
  88. x3:3, s:1, major:4; };
  89. } INST64_M30;
  90. typedef union U_INST64_M31 {
  91. IA64_INST inst;
  92. struct { unsigned long qp:6, r1:7, :7, ar3:7, x6:6, x3:3, :1, major:4; };
  93. } INST64_M31;
  94. typedef union U_INST64_M32 {
  95. IA64_INST inst;
  96. struct { unsigned long qp:6, :7, r2:7, cr3:7, x6:6, x3:3, :1, major:4; };
  97. } INST64_M32;
  98. typedef union U_INST64_M33 {
  99. IA64_INST inst;
  100. struct { unsigned long qp:6, r1:7, :7, cr3:7, x6:6, x3:3, :1, major:4; };
  101. } INST64_M33;
  102. typedef union U_INST64_M35 {
  103. IA64_INST inst;
  104. struct { unsigned long qp:6, :7, r2:7, :7, x6:6, x3:3, :1, major:4; };
  105. } INST64_M35;
  106. typedef union U_INST64_M36 {
  107. IA64_INST inst;
  108. struct { unsigned long qp:6, r1:7, :14, x6:6, x3:3, :1, major:4; };
  109. } INST64_M36;
  110. typedef union U_INST64_M37 {
  111. IA64_INST inst;
  112. struct { unsigned long qp:6, imm20a:20, :1, x4:4, x2:2, x3:3,
  113. i:1, major:4; };
  114. } INST64_M37;
  115. typedef union U_INST64_M41 {
  116. IA64_INST inst;
  117. struct { unsigned long qp:6, :7, r2:7, :7, x6:6, x3:3, :1, major:4; };
  118. } INST64_M41;
  119. typedef union U_INST64_M42 {
  120. IA64_INST inst;
  121. struct { unsigned long qp:6, :7, r2:7, r3:7, x6:6, x3:3, :1, major:4; };
  122. } INST64_M42;
  123. typedef union U_INST64_M43 {
  124. IA64_INST inst;
  125. struct { unsigned long qp:6, r1:7, :7, r3:7, x6:6, x3:3, :1, major:4; };
  126. } INST64_M43;
  127. typedef union U_INST64_M44 {
  128. IA64_INST inst;
  129. struct { unsigned long qp:6, imm:21, x4:4, i2:2, x3:3, i:1, major:4; };
  130. } INST64_M44;
  131. typedef union U_INST64_M45 {
  132. IA64_INST inst;
  133. struct { unsigned long qp:6, :7, r2:7, r3:7, x6:6, x3:3, :1, major:4; };
  134. } INST64_M45;
  135. typedef union U_INST64_M46 {
  136. IA64_INST inst;
  137. struct { unsigned long qp:6, r1:7, un7:7, r3:7, x6:6,
  138. x3:3, un1:1, major:4; };
  139. } INST64_M46;
  140. typedef union U_INST64_M47 {
  141. IA64_INST inst;
  142. struct { unsigned long qp:6, un14:14, r3:7, x6:6, x3:3, un1:1, major:4; };
  143. } INST64_M47;
  144. typedef union U_INST64_M1{
  145. IA64_INST inst;
  146. struct { unsigned long qp:6, r1:7, un7:7, r3:7, x:1, hint:2,
  147. x6:6, m:1, major:4; };
  148. } INST64_M1;
  149. typedef union U_INST64_M2{
  150. IA64_INST inst;
  151. struct { unsigned long qp:6, r1:7, r2:7, r3:7, x:1, hint:2,
  152. x6:6, m:1, major:4; };
  153. } INST64_M2;
  154. typedef union U_INST64_M3{
  155. IA64_INST inst;
  156. struct { unsigned long qp:6, r1:7, imm7:7, r3:7, i:1, hint:2,
  157. x6:6, s:1, major:4; };
  158. } INST64_M3;
  159. typedef union U_INST64_M4 {
  160. IA64_INST inst;
  161. struct { unsigned long qp:6, un7:7, r2:7, r3:7, x:1, hint:2,
  162. x6:6, m:1, major:4; };
  163. } INST64_M4;
  164. typedef union U_INST64_M5 {
  165. IA64_INST inst;
  166. struct { unsigned long qp:6, imm7:7, r2:7, r3:7, i:1, hint:2,
  167. x6:6, s:1, major:4; };
  168. } INST64_M5;
  169. typedef union U_INST64_M6 {
  170. IA64_INST inst;
  171. struct { unsigned long qp:6, f1:7, un7:7, r3:7, x:1, hint:2,
  172. x6:6, m:1, major:4; };
  173. } INST64_M6;
  174. typedef union U_INST64_M9 {
  175. IA64_INST inst;
  176. struct { unsigned long qp:6, :7, f2:7, r3:7, x:1, hint:2,
  177. x6:6, m:1, major:4; };
  178. } INST64_M9;
  179. typedef union U_INST64_M10 {
  180. IA64_INST inst;
  181. struct { unsigned long qp:6, imm7:7, f2:7, r3:7, i:1, hint:2,
  182. x6:6, s:1, major:4; };
  183. } INST64_M10;
  184. typedef union U_INST64_M12 {
  185. IA64_INST inst;
  186. struct { unsigned long qp:6, f1:7, f2:7, r3:7, x:1, hint:2,
  187. x6:6, m:1, major:4; };
  188. } INST64_M12;
  189. typedef union U_INST64_M15 {
  190. IA64_INST inst;
  191. struct { unsigned long qp:6, :7, imm7:7, r3:7, i:1, hint:2,
  192. x6:6, s:1, major:4; };
  193. } INST64_M15;
  194. typedef union U_INST64 {
  195. IA64_INST inst;
  196. struct { unsigned long :37, major:4; } generic;
  197. INST64_A5 A5; /* used in build_hypercall_bundle only */
  198. INST64_B4 B4; /* used in build_hypercall_bundle only */
  199. INST64_B8 B8; /* rfi, bsw.[01] */
  200. INST64_B9 B9; /* break.b */
  201. INST64_I19 I19; /* used in build_hypercall_bundle only */
  202. INST64_I26 I26; /* mov register to ar (I unit) */
  203. INST64_I27 I27; /* mov immediate to ar (I unit) */
  204. INST64_I28 I28; /* mov from ar (I unit) */
  205. INST64_M1 M1; /* ld integer */
  206. INST64_M2 M2;
  207. INST64_M3 M3;
  208. INST64_M4 M4; /* st integer */
  209. INST64_M5 M5;
  210. INST64_M6 M6; /* ldfd floating pointer */
  211. INST64_M9 M9; /* stfd floating pointer */
  212. INST64_M10 M10; /* stfd floating pointer */
  213. INST64_M12 M12; /* ldfd pair floating pointer */
  214. INST64_M15 M15; /* lfetch + imm update */
  215. INST64_M28 M28; /* purge translation cache entry */
  216. INST64_M29 M29; /* mov register to ar (M unit) */
  217. INST64_M30 M30; /* mov immediate to ar (M unit) */
  218. INST64_M31 M31; /* mov from ar (M unit) */
  219. INST64_M32 M32; /* mov reg to cr */
  220. INST64_M33 M33; /* mov from cr */
  221. INST64_M35 M35; /* mov to psr */
  222. INST64_M36 M36; /* mov from psr */
  223. INST64_M37 M37; /* break.m */
  224. INST64_M41 M41; /* translation cache insert */
  225. INST64_M42 M42; /* mov to indirect reg/translation reg insert*/
  226. INST64_M43 M43; /* mov from indirect reg */
  227. INST64_M44 M44; /* set/reset system mask */
  228. INST64_M45 M45; /* translation purge */
  229. INST64_M46 M46; /* translation access (tpa,tak) */
  230. INST64_M47 M47; /* purge translation entry */
  231. } INST64;
  232. #define MASK_41 ((unsigned long)0x1ffffffffff)
  233. /* Virtual address memory attributes encoding */
  234. #define VA_MATTR_WB 0x0
  235. #define VA_MATTR_UC 0x4
  236. #define VA_MATTR_UCE 0x5
  237. #define VA_MATTR_WC 0x6
  238. #define VA_MATTR_NATPAGE 0x7
  239. #define PMASK(size) (~((size) - 1))
  240. #define PSIZE(size) (1UL<<(size))
  241. #define CLEARLSB(ppn, nbits) (((ppn) >> (nbits)) << (nbits))
  242. #define PAGEALIGN(va, ps) CLEARLSB(va, ps)
  243. #define PAGE_FLAGS_RV_MASK (0x2|(0x3UL<<50)|(((1UL<<11)-1)<<53))
  244. #define _PAGE_MA_ST (0x1 << 2) /* is reserved for software use */
  245. #define ARCH_PAGE_SHIFT 12
  246. #define INVALID_TI_TAG (1UL << 63)
  247. #define VTLB_PTE_P_BIT 0
  248. #define VTLB_PTE_IO_BIT 60
  249. #define VTLB_PTE_IO (1UL<<VTLB_PTE_IO_BIT)
  250. #define VTLB_PTE_P (1UL<<VTLB_PTE_P_BIT)
  251. #define vcpu_quick_region_check(_tr_regions,_ifa) \
  252. (_tr_regions & (1 << ((unsigned long)_ifa >> 61)))
  253. #define vcpu_quick_region_set(_tr_regions,_ifa) \
  254. do {_tr_regions |= (1 << ((unsigned long)_ifa >> 61)); } while (0)
  255. static inline void vcpu_set_tr(struct thash_data *trp, u64 pte, u64 itir,
  256. u64 va, u64 rid)
  257. {
  258. trp->page_flags = pte;
  259. trp->itir = itir;
  260. trp->vadr = va;
  261. trp->rid = rid;
  262. }
  263. extern u64 kvm_get_mpt_entry(u64 gpfn);
  264. /* Return I/ */
  265. static inline u64 __gpfn_is_io(u64 gpfn)
  266. {
  267. u64 pte;
  268. pte = kvm_get_mpt_entry(gpfn);
  269. if (!(pte & GPFN_INV_MASK)) {
  270. pte = pte & GPFN_IO_MASK;
  271. if (pte != GPFN_PHYS_MMIO)
  272. return pte;
  273. }
  274. return 0;
  275. }
  276. #endif
  277. #define IA64_NO_FAULT 0
  278. #define IA64_FAULT 1
  279. #define VMM_RBS_OFFSET ((VMM_TASK_SIZE + 15) & ~15)
  280. #define SW_BAD 0 /* Bad mode transitition */
  281. #define SW_V2P 1 /* Physical emulatino is activated */
  282. #define SW_P2V 2 /* Exit physical mode emulation */
  283. #define SW_SELF 3 /* No mode transition */
  284. #define SW_NOP 4 /* Mode transition, but without action required */
  285. #define GUEST_IN_PHY 0x1
  286. #define GUEST_PHY_EMUL 0x2
  287. #define current_vcpu ((struct kvm_vcpu *) ia64_getreg(_IA64_REG_TP))
  288. #define VRN_SHIFT 61
  289. #define VRN_MASK 0xe000000000000000
  290. #define VRN0 0x0UL
  291. #define VRN1 0x1UL
  292. #define VRN2 0x2UL
  293. #define VRN3 0x3UL
  294. #define VRN4 0x4UL
  295. #define VRN5 0x5UL
  296. #define VRN6 0x6UL
  297. #define VRN7 0x7UL
  298. #define IRQ_NO_MASKED 0
  299. #define IRQ_MASKED_BY_VTPR 1
  300. #define IRQ_MASKED_BY_INSVC 2 /* masked by inservice IRQ */
  301. #define PTA_BASE_SHIFT 15
  302. #define IA64_PSR_VM_BIT 46
  303. #define IA64_PSR_VM (__IA64_UL(1) << IA64_PSR_VM_BIT)
  304. /* Interruption Function State */
  305. #define IA64_IFS_V_BIT 63
  306. #define IA64_IFS_V (__IA64_UL(1) << IA64_IFS_V_BIT)
  307. #define PHY_PAGE_UC (_PAGE_A|_PAGE_D|_PAGE_P|_PAGE_MA_UC|_PAGE_AR_RWX)
  308. #define PHY_PAGE_WB (_PAGE_A|_PAGE_D|_PAGE_P|_PAGE_MA_WB|_PAGE_AR_RWX)
  309. #ifndef __ASSEMBLY__
  310. #include <asm/gcc_intrin.h>
  311. #define is_physical_mode(v) \
  312. ((v->arch.mode_flags) & GUEST_IN_PHY)
  313. #define is_virtual_mode(v) \
  314. (!is_physical_mode(v))
  315. #define MODE_IND(psr) \
  316. (((psr).it << 2) + ((psr).dt << 1) + (psr).rt)
  317. #ifndef CONFIG_SMP
  318. #define _vmm_raw_spin_lock(x) do {}while(0)
  319. #define _vmm_raw_spin_unlock(x) do {}while(0)
  320. #else
  321. typedef struct {
  322. volatile unsigned int lock;
  323. } vmm_spinlock_t;
  324. #define _vmm_raw_spin_lock(x) \
  325. do { \
  326. __u32 *ia64_spinlock_ptr = (__u32 *) (x); \
  327. __u64 ia64_spinlock_val; \
  328. ia64_spinlock_val = ia64_cmpxchg4_acq(ia64_spinlock_ptr, 1, 0);\
  329. if (unlikely(ia64_spinlock_val)) { \
  330. do { \
  331. while (*ia64_spinlock_ptr) \
  332. ia64_barrier(); \
  333. ia64_spinlock_val = \
  334. ia64_cmpxchg4_acq(ia64_spinlock_ptr, 1, 0);\
  335. } while (ia64_spinlock_val); \
  336. } \
  337. } while (0)
  338. #define _vmm_raw_spin_unlock(x) \
  339. do { barrier(); \
  340. ((vmm_spinlock_t *)x)->lock = 0; } \
  341. while (0)
  342. #endif
  343. void vmm_spin_lock(vmm_spinlock_t *lock);
  344. void vmm_spin_unlock(vmm_spinlock_t *lock);
  345. enum {
  346. I_TLB = 1,
  347. D_TLB = 2
  348. };
  349. union kvm_va {
  350. struct {
  351. unsigned long off : 60; /* intra-region offset */
  352. unsigned long reg : 4; /* region number */
  353. } f;
  354. unsigned long l;
  355. void *p;
  356. };
  357. #define __kvm_pa(x) ({union kvm_va _v; _v.l = (long) (x); \
  358. _v.f.reg = 0; _v.l; })
  359. #define __kvm_va(x) ({union kvm_va _v; _v.l = (long) (x); \
  360. _v.f.reg = -1; _v.p; })
  361. #define _REGION_ID(x) ({union ia64_rr _v; _v.val = (long)(x); \
  362. _v.rid; })
  363. #define _REGION_PAGE_SIZE(x) ({union ia64_rr _v; _v.val = (long)(x); \
  364. _v.ps; })
  365. #define _REGION_HW_WALKER(x) ({union ia64_rr _v; _v.val = (long)(x); \
  366. _v.ve; })
  367. enum vhpt_ref{ DATA_REF, NA_REF, INST_REF, RSE_REF };
  368. enum tlb_miss_type { INSTRUCTION, DATA, REGISTER };
  369. #define VCPU(_v, _x) ((_v)->arch.vpd->_x)
  370. #define VMX(_v, _x) ((_v)->arch._x)
  371. #define VLSAPIC_INSVC(vcpu, i) ((vcpu)->arch.insvc[i])
  372. #define VLSAPIC_XTP(_v) VMX(_v, xtp)
  373. static inline unsigned long itir_ps(unsigned long itir)
  374. {
  375. return ((itir >> 2) & 0x3f);
  376. }
  377. /**************************************************************************
  378. VCPU control register access routines
  379. **************************************************************************/
  380. static inline u64 vcpu_get_itir(struct kvm_vcpu *vcpu)
  381. {
  382. return ((u64)VCPU(vcpu, itir));
  383. }
  384. static inline void vcpu_set_itir(struct kvm_vcpu *vcpu, u64 val)
  385. {
  386. VCPU(vcpu, itir) = val;
  387. }
  388. static inline u64 vcpu_get_ifa(struct kvm_vcpu *vcpu)
  389. {
  390. return ((u64)VCPU(vcpu, ifa));
  391. }
  392. static inline void vcpu_set_ifa(struct kvm_vcpu *vcpu, u64 val)
  393. {
  394. VCPU(vcpu, ifa) = val;
  395. }
  396. static inline u64 vcpu_get_iva(struct kvm_vcpu *vcpu)
  397. {
  398. return ((u64)VCPU(vcpu, iva));
  399. }
  400. static inline u64 vcpu_get_pta(struct kvm_vcpu *vcpu)
  401. {
  402. return ((u64)VCPU(vcpu, pta));
  403. }
  404. static inline u64 vcpu_get_lid(struct kvm_vcpu *vcpu)
  405. {
  406. return ((u64)VCPU(vcpu, lid));
  407. }
  408. static inline u64 vcpu_get_tpr(struct kvm_vcpu *vcpu)
  409. {
  410. return ((u64)VCPU(vcpu, tpr));
  411. }
  412. static inline u64 vcpu_get_eoi(struct kvm_vcpu *vcpu)
  413. {
  414. return (0UL); /*reads of eoi always return 0 */
  415. }
  416. static inline u64 vcpu_get_irr0(struct kvm_vcpu *vcpu)
  417. {
  418. return ((u64)VCPU(vcpu, irr[0]));
  419. }
  420. static inline u64 vcpu_get_irr1(struct kvm_vcpu *vcpu)
  421. {
  422. return ((u64)VCPU(vcpu, irr[1]));
  423. }
  424. static inline u64 vcpu_get_irr2(struct kvm_vcpu *vcpu)
  425. {
  426. return ((u64)VCPU(vcpu, irr[2]));
  427. }
  428. static inline u64 vcpu_get_irr3(struct kvm_vcpu *vcpu)
  429. {
  430. return ((u64)VCPU(vcpu, irr[3]));
  431. }
  432. static inline void vcpu_set_dcr(struct kvm_vcpu *vcpu, u64 val)
  433. {
  434. ia64_setreg(_IA64_REG_CR_DCR, val);
  435. }
  436. static inline void vcpu_set_isr(struct kvm_vcpu *vcpu, u64 val)
  437. {
  438. VCPU(vcpu, isr) = val;
  439. }
  440. static inline void vcpu_set_lid(struct kvm_vcpu *vcpu, u64 val)
  441. {
  442. VCPU(vcpu, lid) = val;
  443. }
  444. static inline void vcpu_set_ipsr(struct kvm_vcpu *vcpu, u64 val)
  445. {
  446. VCPU(vcpu, ipsr) = val;
  447. }
  448. static inline void vcpu_set_iip(struct kvm_vcpu *vcpu, u64 val)
  449. {
  450. VCPU(vcpu, iip) = val;
  451. }
  452. static inline void vcpu_set_ifs(struct kvm_vcpu *vcpu, u64 val)
  453. {
  454. VCPU(vcpu, ifs) = val;
  455. }
  456. static inline void vcpu_set_iipa(struct kvm_vcpu *vcpu, u64 val)
  457. {
  458. VCPU(vcpu, iipa) = val;
  459. }
  460. static inline void vcpu_set_iha(struct kvm_vcpu *vcpu, u64 val)
  461. {
  462. VCPU(vcpu, iha) = val;
  463. }
  464. static inline u64 vcpu_get_rr(struct kvm_vcpu *vcpu, u64 reg)
  465. {
  466. return vcpu->arch.vrr[reg>>61];
  467. }
  468. /**************************************************************************
  469. VCPU debug breakpoint register access routines
  470. **************************************************************************/
  471. static inline void vcpu_set_dbr(struct kvm_vcpu *vcpu, u64 reg, u64 val)
  472. {
  473. __ia64_set_dbr(reg, val);
  474. }
  475. static inline void vcpu_set_ibr(struct kvm_vcpu *vcpu, u64 reg, u64 val)
  476. {
  477. ia64_set_ibr(reg, val);
  478. }
  479. static inline u64 vcpu_get_dbr(struct kvm_vcpu *vcpu, u64 reg)
  480. {
  481. return ((u64)__ia64_get_dbr(reg));
  482. }
  483. static inline u64 vcpu_get_ibr(struct kvm_vcpu *vcpu, u64 reg)
  484. {
  485. return ((u64)ia64_get_ibr(reg));
  486. }
  487. /**************************************************************************
  488. VCPU performance monitor register access routines
  489. **************************************************************************/
  490. static inline void vcpu_set_pmc(struct kvm_vcpu *vcpu, u64 reg, u64 val)
  491. {
  492. /* NOTE: Writes to unimplemented PMC registers are discarded */
  493. ia64_set_pmc(reg, val);
  494. }
  495. static inline void vcpu_set_pmd(struct kvm_vcpu *vcpu, u64 reg, u64 val)
  496. {
  497. /* NOTE: Writes to unimplemented PMD registers are discarded */
  498. ia64_set_pmd(reg, val);
  499. }
  500. static inline u64 vcpu_get_pmc(struct kvm_vcpu *vcpu, u64 reg)
  501. {
  502. /* NOTE: Reads from unimplemented PMC registers return zero */
  503. return ((u64)ia64_get_pmc(reg));
  504. }
  505. static inline u64 vcpu_get_pmd(struct kvm_vcpu *vcpu, u64 reg)
  506. {
  507. /* NOTE: Reads from unimplemented PMD registers return zero */
  508. return ((u64)ia64_get_pmd(reg));
  509. }
  510. static inline unsigned long vrrtomrr(unsigned long val)
  511. {
  512. union ia64_rr rr;
  513. rr.val = val;
  514. rr.rid = (rr.rid << 4) | 0xe;
  515. if (rr.ps > PAGE_SHIFT)
  516. rr.ps = PAGE_SHIFT;
  517. rr.ve = 1;
  518. return rr.val;
  519. }
  520. static inline int highest_bits(int *dat)
  521. {
  522. u32 bits, bitnum;
  523. int i;
  524. /* loop for all 256 bits */
  525. for (i = 7; i >= 0 ; i--) {
  526. bits = dat[i];
  527. if (bits) {
  528. bitnum = fls(bits);
  529. return i * 32 + bitnum - 1;
  530. }
  531. }
  532. return NULL_VECTOR;
  533. }
  534. /*
  535. * The pending irq is higher than the inservice one.
  536. *
  537. */
  538. static inline int is_higher_irq(int pending, int inservice)
  539. {
  540. return ((pending > inservice)
  541. || ((pending != NULL_VECTOR)
  542. && (inservice == NULL_VECTOR)));
  543. }
  544. static inline int is_higher_class(int pending, int mic)
  545. {
  546. return ((pending >> 4) > mic);
  547. }
  548. /*
  549. * Return 0-255 for pending irq.
  550. * NULL_VECTOR: when no pending.
  551. */
  552. static inline int highest_pending_irq(struct kvm_vcpu *vcpu)
  553. {
  554. if (VCPU(vcpu, irr[0]) & (1UL<<NMI_VECTOR))
  555. return NMI_VECTOR;
  556. if (VCPU(vcpu, irr[0]) & (1UL<<ExtINT_VECTOR))
  557. return ExtINT_VECTOR;
  558. return highest_bits((int *)&VCPU(vcpu, irr[0]));
  559. }
  560. static inline int highest_inservice_irq(struct kvm_vcpu *vcpu)
  561. {
  562. if (VMX(vcpu, insvc[0]) & (1UL<<NMI_VECTOR))
  563. return NMI_VECTOR;
  564. if (VMX(vcpu, insvc[0]) & (1UL<<ExtINT_VECTOR))
  565. return ExtINT_VECTOR;
  566. return highest_bits((int *)&(VMX(vcpu, insvc[0])));
  567. }
  568. extern void vcpu_get_fpreg(struct kvm_vcpu *vcpu, unsigned long reg,
  569. struct ia64_fpreg *val);
  570. extern void vcpu_set_fpreg(struct kvm_vcpu *vcpu, unsigned long reg,
  571. struct ia64_fpreg *val);
  572. extern u64 vcpu_get_gr(struct kvm_vcpu *vcpu, unsigned long reg);
  573. extern void vcpu_set_gr(struct kvm_vcpu *vcpu, unsigned long reg,
  574. u64 val, int nat);
  575. extern unsigned long vcpu_get_psr(struct kvm_vcpu *vcpu);
  576. extern void vcpu_set_psr(struct kvm_vcpu *vcpu, unsigned long val);
  577. extern u64 vcpu_thash(struct kvm_vcpu *vcpu, u64 vadr);
  578. extern void vcpu_bsw0(struct kvm_vcpu *vcpu);
  579. extern void thash_vhpt_insert(struct kvm_vcpu *v, u64 pte,
  580. u64 itir, u64 va, int type);
  581. extern struct thash_data *vhpt_lookup(u64 va);
  582. extern u64 guest_vhpt_lookup(u64 iha, u64 *pte);
  583. extern void thash_purge_entries(struct kvm_vcpu *v, u64 va, u64 ps);
  584. extern void thash_purge_entries_remote(struct kvm_vcpu *v, u64 va, u64 ps);
  585. extern u64 translate_phy_pte(u64 *pte, u64 itir, u64 va);
  586. extern void thash_purge_and_insert(struct kvm_vcpu *v, u64 pte,
  587. u64 itir, u64 ifa, int type);
  588. extern void thash_purge_all(struct kvm_vcpu *v);
  589. extern struct thash_data *vtlb_lookup(struct kvm_vcpu *v,
  590. u64 va, int is_data);
  591. extern int vtr_find_overlap(struct kvm_vcpu *vcpu, u64 va,
  592. u64 ps, int is_data);
  593. extern void vcpu_increment_iip(struct kvm_vcpu *v);
  594. extern void vcpu_decrement_iip(struct kvm_vcpu *vcpu);
  595. extern void vcpu_pend_interrupt(struct kvm_vcpu *vcpu, u8 vec);
  596. extern void vcpu_unpend_interrupt(struct kvm_vcpu *vcpu, u8 vec);
  597. extern void data_page_not_present(struct kvm_vcpu *vcpu, u64 vadr);
  598. extern void dnat_page_consumption(struct kvm_vcpu *vcpu, u64 vadr);
  599. extern void alt_dtlb(struct kvm_vcpu *vcpu, u64 vadr);
  600. extern void nested_dtlb(struct kvm_vcpu *vcpu);
  601. extern void dvhpt_fault(struct kvm_vcpu *vcpu, u64 vadr);
  602. extern int vhpt_enabled(struct kvm_vcpu *vcpu, u64 vadr, enum vhpt_ref ref);
  603. extern void update_vhpi(struct kvm_vcpu *vcpu, int vec);
  604. extern int irq_masked(struct kvm_vcpu *vcpu, int h_pending, int h_inservice);
  605. extern int fetch_code(struct kvm_vcpu *vcpu, u64 gip, IA64_BUNDLE *pbundle);
  606. extern void emulate_io_inst(struct kvm_vcpu *vcpu, u64 padr, u64 ma);
  607. extern void vmm_transition(struct kvm_vcpu *vcpu);
  608. extern void vmm_trampoline(union context *from, union context *to);
  609. extern int vmm_entry(void);
  610. extern u64 vcpu_get_itc(struct kvm_vcpu *vcpu);
  611. extern void vmm_reset_entry(void);
  612. void kvm_init_vtlb(struct kvm_vcpu *v);
  613. void kvm_init_vhpt(struct kvm_vcpu *v);
  614. void thash_init(struct thash_cb *hcb, u64 sz);
  615. void panic_vm(struct kvm_vcpu *v, const char *fmt, ...);
  616. u64 kvm_gpa_to_mpa(u64 gpa);
  617. extern u64 ia64_call_vsa(u64 proc, u64 arg1, u64 arg2, u64 arg3,
  618. u64 arg4, u64 arg5, u64 arg6, u64 arg7);
  619. extern long vmm_sanity;
  620. #endif
  621. #endif /* __VCPU_H__ */