kvm_arm.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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_ARM_H__
  19. #define __ARM_KVM_ARM_H__
  20. #include <linux/const.h>
  21. #include <linux/types.h>
  22. /* Hyp Configuration Register (HCR) bits */
  23. #define HCR_TGE (1 << 27)
  24. #define HCR_TVM (1 << 26)
  25. #define HCR_TTLB (1 << 25)
  26. #define HCR_TPU (1 << 24)
  27. #define HCR_TPC (1 << 23)
  28. #define HCR_TSW (1 << 22)
  29. #define HCR_TAC (1 << 21)
  30. #define HCR_TIDCP (1 << 20)
  31. #define HCR_TSC (1 << 19)
  32. #define HCR_TID3 (1 << 18)
  33. #define HCR_TID2 (1 << 17)
  34. #define HCR_TID1 (1 << 16)
  35. #define HCR_TID0 (1 << 15)
  36. #define HCR_TWE (1 << 14)
  37. #define HCR_TWI (1 << 13)
  38. #define HCR_DC (1 << 12)
  39. #define HCR_BSU (3 << 10)
  40. #define HCR_BSU_IS (1 << 10)
  41. #define HCR_FB (1 << 9)
  42. #define HCR_VA (1 << 8)
  43. #define HCR_VI (1 << 7)
  44. #define HCR_VF (1 << 6)
  45. #define HCR_AMO (1 << 5)
  46. #define HCR_IMO (1 << 4)
  47. #define HCR_FMO (1 << 3)
  48. #define HCR_PTW (1 << 2)
  49. #define HCR_SWIO (1 << 1)
  50. #define HCR_VM 1
  51. /*
  52. * The bits we set in HCR:
  53. * TAC: Trap ACTLR
  54. * TSC: Trap SMC
  55. * TVM: Trap VM ops (until MMU and caches are on)
  56. * TSW: Trap cache operations by set/way
  57. * TWI: Trap WFI
  58. * TWE: Trap WFE
  59. * TIDCP: Trap L2CTLR/L2ECTLR
  60. * BSU_IS: Upgrade barriers to the inner shareable domain
  61. * FB: Force broadcast of all maintainance operations
  62. * AMO: Override CPSR.A and enable signaling with VA
  63. * IMO: Override CPSR.I and enable signaling with VI
  64. * FMO: Override CPSR.F and enable signaling with VF
  65. * SWIO: Turn set/way invalidates into set/way clean+invalidate
  66. */
  67. #define HCR_GUEST_MASK (HCR_TSC | HCR_TSW | HCR_TWI | HCR_VM | HCR_BSU_IS | \
  68. HCR_FB | HCR_TAC | HCR_AMO | HCR_IMO | HCR_FMO | \
  69. HCR_TVM | HCR_TWE | HCR_SWIO | HCR_TIDCP)
  70. /* System Control Register (SCTLR) bits */
  71. #define SCTLR_TE (1 << 30)
  72. #define SCTLR_EE (1 << 25)
  73. #define SCTLR_V (1 << 13)
  74. /* Hyp System Control Register (HSCTLR) bits */
  75. #define HSCTLR_TE (1 << 30)
  76. #define HSCTLR_EE (1 << 25)
  77. #define HSCTLR_FI (1 << 21)
  78. #define HSCTLR_WXN (1 << 19)
  79. #define HSCTLR_I (1 << 12)
  80. #define HSCTLR_C (1 << 2)
  81. #define HSCTLR_A (1 << 1)
  82. #define HSCTLR_M 1
  83. #define HSCTLR_MASK (HSCTLR_M | HSCTLR_A | HSCTLR_C | HSCTLR_I | \
  84. HSCTLR_WXN | HSCTLR_FI | HSCTLR_EE | HSCTLR_TE)
  85. /* TTBCR and HTCR Registers bits */
  86. #define TTBCR_EAE (1 << 31)
  87. #define TTBCR_IMP (1 << 30)
  88. #define TTBCR_SH1 (3 << 28)
  89. #define TTBCR_ORGN1 (3 << 26)
  90. #define TTBCR_IRGN1 (3 << 24)
  91. #define TTBCR_EPD1 (1 << 23)
  92. #define TTBCR_A1 (1 << 22)
  93. #define TTBCR_T1SZ (7 << 16)
  94. #define TTBCR_SH0 (3 << 12)
  95. #define TTBCR_ORGN0 (3 << 10)
  96. #define TTBCR_IRGN0 (3 << 8)
  97. #define TTBCR_EPD0 (1 << 7)
  98. #define TTBCR_T0SZ (7 << 0)
  99. #define HTCR_MASK (TTBCR_T0SZ | TTBCR_IRGN0 | TTBCR_ORGN0 | TTBCR_SH0)
  100. /* Hyp System Trap Register */
  101. #define HSTR_T(x) (1 << x)
  102. #define HSTR_TTEE (1 << 16)
  103. #define HSTR_TJDBX (1 << 17)
  104. /* Hyp Coprocessor Trap Register */
  105. #define HCPTR_TCP(x) (1 << x)
  106. #define HCPTR_TCP_MASK (0x3fff)
  107. #define HCPTR_TASE (1 << 15)
  108. #define HCPTR_TTA (1 << 20)
  109. #define HCPTR_TCPAC (1 << 31)
  110. /* Hyp Debug Configuration Register bits */
  111. #define HDCR_TDRA (1 << 11)
  112. #define HDCR_TDOSA (1 << 10)
  113. #define HDCR_TDA (1 << 9)
  114. #define HDCR_TDE (1 << 8)
  115. #define HDCR_HPME (1 << 7)
  116. #define HDCR_TPM (1 << 6)
  117. #define HDCR_TPMCR (1 << 5)
  118. #define HDCR_HPMN_MASK (0x1F)
  119. /*
  120. * The architecture supports 40-bit IPA as input to the 2nd stage translations
  121. * and PTRS_PER_S2_PGD becomes 1024, because each entry covers 1GB of address
  122. * space.
  123. */
  124. #define KVM_PHYS_SHIFT (40)
  125. #define KVM_PHYS_SIZE (_AC(1, ULL) << KVM_PHYS_SHIFT)
  126. #define KVM_PHYS_MASK (KVM_PHYS_SIZE - _AC(1, ULL))
  127. #define PTRS_PER_S2_PGD (_AC(1, ULL) << (KVM_PHYS_SHIFT - 30))
  128. /* Virtualization Translation Control Register (VTCR) bits */
  129. #define VTCR_SH0 (3 << 12)
  130. #define VTCR_ORGN0 (3 << 10)
  131. #define VTCR_IRGN0 (3 << 8)
  132. #define VTCR_SL0 (3 << 6)
  133. #define VTCR_S (1 << 4)
  134. #define VTCR_T0SZ (0xf)
  135. #define VTCR_MASK (VTCR_SH0 | VTCR_ORGN0 | VTCR_IRGN0 | VTCR_SL0 | \
  136. VTCR_S | VTCR_T0SZ)
  137. #define VTCR_HTCR_SH (VTCR_SH0 | VTCR_ORGN0 | VTCR_IRGN0)
  138. #define VTCR_SL_L2 (0 << 6) /* Starting-level: 2 */
  139. #define VTCR_SL_L1 (1 << 6) /* Starting-level: 1 */
  140. #define KVM_VTCR_SL0 VTCR_SL_L1
  141. /* stage-2 input address range defined as 2^(32-T0SZ) */
  142. #define KVM_T0SZ (32 - KVM_PHYS_SHIFT)
  143. #define KVM_VTCR_T0SZ (KVM_T0SZ & VTCR_T0SZ)
  144. #define KVM_VTCR_S ((KVM_VTCR_T0SZ << 1) & VTCR_S)
  145. /* Virtualization Translation Table Base Register (VTTBR) bits */
  146. #if KVM_VTCR_SL0 == VTCR_SL_L2 /* see ARM DDI 0406C: B4-1720 */
  147. #define VTTBR_X (14 - KVM_T0SZ)
  148. #else
  149. #define VTTBR_X (5 - KVM_T0SZ)
  150. #endif
  151. #define VTTBR_BADDR_MASK (((_AC(1, ULL) << (40 - VTTBR_X)) - 1) << VTTBR_X)
  152. #define VTTBR_VMID_SHIFT _AC(48, ULL)
  153. #define VTTBR_VMID_MASK(size) (_AT(u64, (1 << size) - 1) << VTTBR_VMID_SHIFT)
  154. /* Hyp Syndrome Register (HSR) bits */
  155. #define HSR_EC_SHIFT (26)
  156. #define HSR_EC (_AC(0x3f, UL) << HSR_EC_SHIFT)
  157. #define HSR_IL (_AC(1, UL) << 25)
  158. #define HSR_ISS (HSR_IL - 1)
  159. #define HSR_ISV_SHIFT (24)
  160. #define HSR_ISV (_AC(1, UL) << HSR_ISV_SHIFT)
  161. #define HSR_SRT_SHIFT (16)
  162. #define HSR_SRT_MASK (0xf << HSR_SRT_SHIFT)
  163. #define HSR_FSC (0x3f)
  164. #define HSR_FSC_TYPE (0x3c)
  165. #define HSR_SSE (1 << 21)
  166. #define HSR_WNR (1 << 6)
  167. #define HSR_CV_SHIFT (24)
  168. #define HSR_CV (_AC(1, UL) << HSR_CV_SHIFT)
  169. #define HSR_COND_SHIFT (20)
  170. #define HSR_COND (_AC(0xf, UL) << HSR_COND_SHIFT)
  171. #define FSC_FAULT (0x04)
  172. #define FSC_ACCESS (0x08)
  173. #define FSC_PERM (0x0c)
  174. /* Hyp Prefetch Fault Address Register (HPFAR/HDFAR) */
  175. #define HPFAR_MASK (~0xf)
  176. #define HSR_EC_UNKNOWN (0x00)
  177. #define HSR_EC_WFI (0x01)
  178. #define HSR_EC_CP15_32 (0x03)
  179. #define HSR_EC_CP15_64 (0x04)
  180. #define HSR_EC_CP14_MR (0x05)
  181. #define HSR_EC_CP14_LS (0x06)
  182. #define HSR_EC_CP_0_13 (0x07)
  183. #define HSR_EC_CP10_ID (0x08)
  184. #define HSR_EC_JAZELLE (0x09)
  185. #define HSR_EC_BXJ (0x0A)
  186. #define HSR_EC_CP14_64 (0x0C)
  187. #define HSR_EC_SVC_HYP (0x11)
  188. #define HSR_EC_HVC (0x12)
  189. #define HSR_EC_SMC (0x13)
  190. #define HSR_EC_IABT (0x20)
  191. #define HSR_EC_IABT_HYP (0x21)
  192. #define HSR_EC_DABT (0x24)
  193. #define HSR_EC_DABT_HYP (0x25)
  194. #define HSR_EC_MAX (0x3f)
  195. #define HSR_WFI_IS_WFE (_AC(1, UL) << 0)
  196. #define HSR_HVC_IMM_MASK ((_AC(1, UL) << 16) - 1)
  197. #define HSR_DABT_S1PTW (_AC(1, UL) << 7)
  198. #define HSR_DABT_CM (_AC(1, UL) << 8)
  199. #define HSR_DABT_EA (_AC(1, UL) << 9)
  200. #define kvm_arm_exception_type \
  201. {0, "RESET" }, \
  202. {1, "UNDEFINED" }, \
  203. {2, "SOFTWARE" }, \
  204. {3, "PREF_ABORT" }, \
  205. {4, "DATA_ABORT" }, \
  206. {5, "IRQ" }, \
  207. {6, "FIQ" }, \
  208. {7, "HVC" }
  209. #define HSRECN(x) { HSR_EC_##x, #x }
  210. #define kvm_arm_exception_class \
  211. HSRECN(UNKNOWN), HSRECN(WFI), HSRECN(CP15_32), HSRECN(CP15_64), \
  212. HSRECN(CP14_MR), HSRECN(CP14_LS), HSRECN(CP_0_13), HSRECN(CP10_ID), \
  213. HSRECN(JAZELLE), HSRECN(BXJ), HSRECN(CP14_64), HSRECN(SVC_HYP), \
  214. HSRECN(HVC), HSRECN(SMC), HSRECN(IABT), HSRECN(IABT_HYP), \
  215. HSRECN(DABT), HSRECN(DABT_HYP)
  216. #endif /* __ARM_KVM_ARM_H__ */