arch.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /*
  2. * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef ARCH_H
  7. #define ARCH_H
  8. #include <lib/utils_def.h>
  9. /*******************************************************************************
  10. * MIDR bit definitions
  11. ******************************************************************************/
  12. #define MIDR_IMPL_MASK U(0xff)
  13. #define MIDR_IMPL_SHIFT U(24)
  14. #define MIDR_VAR_SHIFT U(20)
  15. #define MIDR_VAR_BITS U(4)
  16. #define MIDR_VAR_MASK U(0xf)
  17. #define MIDR_REV_SHIFT U(0)
  18. #define MIDR_REV_BITS U(4)
  19. #define MIDR_REV_MASK U(0xf)
  20. #define MIDR_PN_MASK U(0xfff)
  21. #define MIDR_PN_SHIFT U(4)
  22. /*******************************************************************************
  23. * MPIDR macros
  24. ******************************************************************************/
  25. #define MPIDR_MT_MASK (U(1) << 24)
  26. #define MPIDR_CPU_MASK MPIDR_AFFLVL_MASK
  27. #define MPIDR_CLUSTER_MASK (MPIDR_AFFLVL_MASK << MPIDR_AFFINITY_BITS)
  28. #define MPIDR_AFFINITY_BITS U(8)
  29. #define MPIDR_AFFLVL_MASK U(0xff)
  30. #define MPIDR_AFFLVL_SHIFT U(3)
  31. #define MPIDR_AFF0_SHIFT U(0)
  32. #define MPIDR_AFF1_SHIFT U(8)
  33. #define MPIDR_AFF2_SHIFT U(16)
  34. #define MPIDR_AFF_SHIFT(_n) MPIDR_AFF##_n##_SHIFT
  35. #define MPIDR_AFFINITY_MASK U(0x00ffffff)
  36. #define MPIDR_AFFLVL0 U(0)
  37. #define MPIDR_AFFLVL1 U(1)
  38. #define MPIDR_AFFLVL2 U(2)
  39. #define MPIDR_AFFLVL(_n) MPIDR_AFFLVL##_n
  40. #define MPIDR_AFFLVL0_VAL(mpidr) \
  41. (((mpidr) >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK)
  42. #define MPIDR_AFFLVL1_VAL(mpidr) \
  43. (((mpidr) >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK)
  44. #define MPIDR_AFFLVL2_VAL(mpidr) \
  45. (((mpidr) >> MPIDR_AFF2_SHIFT) & MPIDR_AFFLVL_MASK)
  46. #define MPIDR_AFFLVL3_VAL(mpidr) U(0)
  47. #define MPIDR_AFF_ID(mpid, n) \
  48. (((mpid) >> MPIDR_AFF_SHIFT(n)) & MPIDR_AFFLVL_MASK)
  49. #define MPID_MASK (MPIDR_MT_MASK |\
  50. (MPIDR_AFFLVL_MASK << MPIDR_AFF2_SHIFT)|\
  51. (MPIDR_AFFLVL_MASK << MPIDR_AFF1_SHIFT)|\
  52. (MPIDR_AFFLVL_MASK << MPIDR_AFF0_SHIFT))
  53. /*
  54. * An invalid MPID. This value can be used by functions that return an MPID to
  55. * indicate an error.
  56. */
  57. #define INVALID_MPID U(0xFFFFFFFF)
  58. /*
  59. * The MPIDR_MAX_AFFLVL count starts from 0. Take care to
  60. * add one while using this macro to define array sizes.
  61. */
  62. #define MPIDR_MAX_AFFLVL U(2)
  63. /* Data Cache set/way op type defines */
  64. #define DC_OP_ISW U(0x0)
  65. #define DC_OP_CISW U(0x1)
  66. #if ERRATA_A53_827319
  67. #define DC_OP_CSW DC_OP_CISW
  68. #else
  69. #define DC_OP_CSW U(0x2)
  70. #endif
  71. /*******************************************************************************
  72. * Generic timer memory mapped registers & offsets
  73. ******************************************************************************/
  74. #define CNTCR_OFF U(0x000)
  75. /* Counter Count Value Lower register */
  76. #define CNTCVL_OFF U(0x008)
  77. /* Counter Count Value Upper register */
  78. #define CNTCVU_OFF U(0x00C)
  79. #define CNTFID_OFF U(0x020)
  80. #define CNTCR_EN (U(1) << 0)
  81. #define CNTCR_HDBG (U(1) << 1)
  82. #define CNTCR_FCREQ(x) ((x) << 8)
  83. /*******************************************************************************
  84. * System register bit definitions
  85. ******************************************************************************/
  86. /* CLIDR definitions */
  87. #define LOUIS_SHIFT U(21)
  88. #define LOC_SHIFT U(24)
  89. #define CLIDR_FIELD_WIDTH U(3)
  90. /* CSSELR definitions */
  91. #define LEVEL_SHIFT U(1)
  92. /* ID_DFR0 definitions */
  93. #define ID_DFR0_PERFMON_SHIFT U(24)
  94. #define ID_DFR0_PERFMON_MASK U(0xf)
  95. #define ID_DFR0_PERFMON_PMUV3 U(3)
  96. #define ID_DFR0_PERFMON_PMUV3P5 U(6)
  97. #define ID_DFR0_COPTRC_SHIFT U(12)
  98. #define ID_DFR0_COPTRC_MASK U(0xf)
  99. #define COPTRC_IMPLEMENTED U(1)
  100. #define ID_DFR0_COPTRC_LENGTH U(4)
  101. #define ID_DFR0_TRACEFILT_SHIFT U(28)
  102. #define ID_DFR0_TRACEFILT_MASK U(0xf)
  103. #define TRACEFILT_IMPLEMENTED U(1)
  104. #define ID_DFR0_TRACEFILT_LENGTH U(4)
  105. /* ID_DFR1_EL1 definitions */
  106. #define ID_DFR1_MTPMU_SHIFT U(0)
  107. #define ID_DFR1_MTPMU_MASK U(0xf)
  108. #define MTPMU_IMPLEMENTED U(1)
  109. #define MTPMU_NOT_IMPLEMENTED U(15)
  110. /* ID_MMFR3 definitions */
  111. #define ID_MMFR3_PAN_SHIFT U(16)
  112. #define ID_MMFR3_PAN_MASK U(0xf)
  113. /* ID_MMFR4 definitions */
  114. #define ID_MMFR4_CNP_SHIFT U(12)
  115. #define ID_MMFR4_CNP_LENGTH U(4)
  116. #define ID_MMFR4_CNP_MASK U(0xf)
  117. #define ID_MMFR4_CCIDX_SHIFT U(24)
  118. #define ID_MMFR4_CCIDX_LENGTH U(4)
  119. #define ID_MMFR4_CCIDX_MASK U(0xf)
  120. /* ID_PFR0 definitions */
  121. #define ID_PFR0_AMU_SHIFT U(20)
  122. #define ID_PFR0_AMU_LENGTH U(4)
  123. #define ID_PFR0_AMU_MASK U(0xf)
  124. #define ID_PFR0_AMU_V1 U(0x1)
  125. #define ID_PFR0_AMU_V1P1 U(0x2)
  126. #define ID_PFR0_DIT_SHIFT U(24)
  127. #define ID_PFR0_DIT_LENGTH U(4)
  128. #define ID_PFR0_DIT_MASK U(0xf)
  129. #define DIT_IMPLEMENTED (U(1) << ID_PFR0_DIT_SHIFT)
  130. /* ID_PFR1 definitions */
  131. #define ID_PFR1_VIRTEXT_SHIFT U(12)
  132. #define ID_PFR1_VIRTEXT_MASK U(0xf)
  133. #define GET_VIRT_EXT(id) (((id) >> ID_PFR1_VIRTEXT_SHIFT) \
  134. & ID_PFR1_VIRTEXT_MASK)
  135. #define ID_PFR1_GENTIMER_SHIFT U(16)
  136. #define ID_PFR1_GENTIMER_MASK U(0xf)
  137. #define ID_PFR1_GIC_SHIFT U(28)
  138. #define ID_PFR1_GIC_MASK U(0xf)
  139. #define ID_PFR1_SEC_SHIFT U(4)
  140. #define ID_PFR1_SEC_MASK U(0xf)
  141. #define ID_PFR1_ELx_ENABLED U(1)
  142. /* ID_PFR2 definitions */
  143. #define ID_PFR2_SSBS_SHIFT U(4)
  144. #define ID_PFR2_SSBS_MASK U(0xf)
  145. #define SSBS_NOT_IMPLEMENTED U(0)
  146. /* SCTLR definitions */
  147. #define SCTLR_RES1_DEF ((U(1) << 23) | (U(1) << 22) | (U(1) << 4) | \
  148. (U(1) << 3))
  149. #if ARM_ARCH_MAJOR == 7
  150. #define SCTLR_RES1 SCTLR_RES1_DEF
  151. #else
  152. #define SCTLR_RES1 (SCTLR_RES1_DEF | (U(1) << 11))
  153. #endif
  154. #define SCTLR_M_BIT (U(1) << 0)
  155. #define SCTLR_A_BIT (U(1) << 1)
  156. #define SCTLR_C_BIT (U(1) << 2)
  157. #define SCTLR_CP15BEN_BIT (U(1) << 5)
  158. #define SCTLR_ITD_BIT (U(1) << 7)
  159. #define SCTLR_Z_BIT (U(1) << 11)
  160. #define SCTLR_I_BIT (U(1) << 12)
  161. #define SCTLR_V_BIT (U(1) << 13)
  162. #define SCTLR_RR_BIT (U(1) << 14)
  163. #define SCTLR_NTWI_BIT (U(1) << 16)
  164. #define SCTLR_NTWE_BIT (U(1) << 18)
  165. #define SCTLR_WXN_BIT (U(1) << 19)
  166. #define SCTLR_UWXN_BIT (U(1) << 20)
  167. #define SCTLR_EE_BIT (U(1) << 25)
  168. #define SCTLR_TRE_BIT (U(1) << 28)
  169. #define SCTLR_AFE_BIT (U(1) << 29)
  170. #define SCTLR_TE_BIT (U(1) << 30)
  171. #define SCTLR_DSSBS_BIT (U(1) << 31)
  172. #define SCTLR_RESET_VAL (SCTLR_RES1 | SCTLR_NTWE_BIT | \
  173. SCTLR_NTWI_BIT | SCTLR_CP15BEN_BIT)
  174. /* SDCR definitions */
  175. #define SDCR_SPD(x) ((x) << 14)
  176. #define SDCR_SPD_LEGACY U(0x0)
  177. #define SDCR_SPD_DISABLE U(0x2)
  178. #define SDCR_SPD_ENABLE U(0x3)
  179. #define SDCR_SPME_BIT (U(1) << 17)
  180. #define SDCR_TTRF_BIT (U(1) << 19)
  181. #define SDCR_SCCD_BIT (U(1) << 23)
  182. #define SDCR_MTPME_BIT (U(1) << 28)
  183. #define SDCR_RESET_VAL U(0x0)
  184. /* HSCTLR definitions */
  185. #define HSCTLR_RES1 ((U(1) << 29) | (U(1) << 28) | (U(1) << 23) | \
  186. (U(1) << 22) | (U(1) << 18) | (U(1) << 16) | \
  187. (U(1) << 11) | (U(1) << 4) | (U(1) << 3))
  188. #define HSCTLR_M_BIT (U(1) << 0)
  189. #define HSCTLR_A_BIT (U(1) << 1)
  190. #define HSCTLR_C_BIT (U(1) << 2)
  191. #define HSCTLR_CP15BEN_BIT (U(1) << 5)
  192. #define HSCTLR_ITD_BIT (U(1) << 7)
  193. #define HSCTLR_SED_BIT (U(1) << 8)
  194. #define HSCTLR_I_BIT (U(1) << 12)
  195. #define HSCTLR_WXN_BIT (U(1) << 19)
  196. #define HSCTLR_EE_BIT (U(1) << 25)
  197. #define HSCTLR_TE_BIT (U(1) << 30)
  198. /* CPACR definitions */
  199. #define CPACR_FPEN(x) ((x) << 20)
  200. #define CPACR_FP_TRAP_PL0 UL(0x1)
  201. #define CPACR_FP_TRAP_ALL UL(0x2)
  202. #define CPACR_FP_TRAP_NONE UL(0x3)
  203. /* SCR definitions */
  204. #define SCR_TWE_BIT (UL(1) << 13)
  205. #define SCR_TWI_BIT (UL(1) << 12)
  206. #define SCR_SIF_BIT (UL(1) << 9)
  207. #define SCR_HCE_BIT (UL(1) << 8)
  208. #define SCR_SCD_BIT (UL(1) << 7)
  209. #define SCR_NET_BIT (UL(1) << 6)
  210. #define SCR_AW_BIT (UL(1) << 5)
  211. #define SCR_FW_BIT (UL(1) << 4)
  212. #define SCR_EA_BIT (UL(1) << 3)
  213. #define SCR_FIQ_BIT (UL(1) << 2)
  214. #define SCR_IRQ_BIT (UL(1) << 1)
  215. #define SCR_NS_BIT (UL(1) << 0)
  216. #define SCR_VALID_BIT_MASK U(0x33ff)
  217. #define SCR_RESET_VAL U(0x0)
  218. #define GET_NS_BIT(scr) ((scr) & SCR_NS_BIT)
  219. /* HCR definitions */
  220. #define HCR_TGE_BIT (U(1) << 27)
  221. #define HCR_AMO_BIT (U(1) << 5)
  222. #define HCR_IMO_BIT (U(1) << 4)
  223. #define HCR_FMO_BIT (U(1) << 3)
  224. #define HCR_RESET_VAL U(0x0)
  225. /* CNTHCTL definitions */
  226. #define CNTHCTL_RESET_VAL U(0x0)
  227. #define PL1PCEN_BIT (U(1) << 1)
  228. #define PL1PCTEN_BIT (U(1) << 0)
  229. /* CNTKCTL definitions */
  230. #define PL0PTEN_BIT (U(1) << 9)
  231. #define PL0VTEN_BIT (U(1) << 8)
  232. #define PL0PCTEN_BIT (U(1) << 0)
  233. #define PL0VCTEN_BIT (U(1) << 1)
  234. #define EVNTEN_BIT (U(1) << 2)
  235. #define EVNTDIR_BIT (U(1) << 3)
  236. #define EVNTI_SHIFT U(4)
  237. #define EVNTI_MASK U(0xf)
  238. /* HCPTR definitions */
  239. #define HCPTR_RES1 ((U(1) << 13) | (U(1) << 12) | U(0x3ff))
  240. #define TCPAC_BIT (U(1) << 31)
  241. #define TAM_SHIFT U(30)
  242. #define TAM_BIT (U(1) << TAM_SHIFT)
  243. #define TTA_BIT (U(1) << 20)
  244. #define TCP11_BIT (U(1) << 11)
  245. #define TCP10_BIT (U(1) << 10)
  246. #define HCPTR_RESET_VAL HCPTR_RES1
  247. /* VTTBR definitions */
  248. #define VTTBR_RESET_VAL ULL(0x0)
  249. #define VTTBR_VMID_MASK ULL(0xff)
  250. #define VTTBR_VMID_SHIFT U(48)
  251. #define VTTBR_BADDR_MASK ULL(0xffffffffffff)
  252. #define VTTBR_BADDR_SHIFT U(0)
  253. /* HDCR definitions */
  254. #define HDCR_MTPME_BIT (U(1) << 28)
  255. #define HDCR_HLP_BIT (U(1) << 26)
  256. #define HDCR_HPME_BIT (U(1) << 7)
  257. #define HDCR_RESET_VAL U(0x0)
  258. /* HSTR definitions */
  259. #define HSTR_RESET_VAL U(0x0)
  260. /* CNTHP_CTL definitions */
  261. #define CNTHP_CTL_RESET_VAL U(0x0)
  262. /* NSACR definitions */
  263. #define NSASEDIS_BIT (U(1) << 15)
  264. #define NSTRCDIS_BIT (U(1) << 20)
  265. #define NSACR_CP11_BIT (U(1) << 11)
  266. #define NSACR_CP10_BIT (U(1) << 10)
  267. #define NSACR_IMP_DEF_MASK (U(0x7) << 16)
  268. #define NSACR_ENABLE_FP_ACCESS (NSACR_CP11_BIT | NSACR_CP10_BIT)
  269. #define NSACR_RESET_VAL U(0x0)
  270. /* CPACR definitions */
  271. #define ASEDIS_BIT (U(1) << 31)
  272. #define TRCDIS_BIT (U(1) << 28)
  273. #define CPACR_CP11_SHIFT U(22)
  274. #define CPACR_CP10_SHIFT U(20)
  275. #define CPACR_ENABLE_FP_ACCESS ((U(0x3) << CPACR_CP11_SHIFT) |\
  276. (U(0x3) << CPACR_CP10_SHIFT))
  277. #define CPACR_RESET_VAL U(0x0)
  278. /* FPEXC definitions */
  279. #define FPEXC_RES1 ((U(1) << 10) | (U(1) << 9) | (U(1) << 8))
  280. #define FPEXC_EN_BIT (U(1) << 30)
  281. #define FPEXC_RESET_VAL FPEXC_RES1
  282. /* SPSR/CPSR definitions */
  283. #define SPSR_FIQ_BIT (U(1) << 0)
  284. #define SPSR_IRQ_BIT (U(1) << 1)
  285. #define SPSR_ABT_BIT (U(1) << 2)
  286. #define SPSR_AIF_SHIFT U(6)
  287. #define SPSR_AIF_MASK U(0x7)
  288. #define SPSR_E_SHIFT U(9)
  289. #define SPSR_E_MASK U(0x1)
  290. #define SPSR_E_LITTLE U(0)
  291. #define SPSR_E_BIG U(1)
  292. #define SPSR_T_SHIFT U(5)
  293. #define SPSR_T_MASK U(0x1)
  294. #define SPSR_T_ARM U(0)
  295. #define SPSR_T_THUMB U(1)
  296. #define SPSR_MODE_SHIFT U(0)
  297. #define SPSR_MODE_MASK U(0x7)
  298. #define SPSR_SSBS_BIT BIT_32(23)
  299. #define DISABLE_ALL_EXCEPTIONS \
  300. (SPSR_FIQ_BIT | SPSR_IRQ_BIT | SPSR_ABT_BIT)
  301. #define CPSR_DIT_BIT (U(1) << 21)
  302. /*
  303. * TTBCR definitions
  304. */
  305. #define TTBCR_EAE_BIT (U(1) << 31)
  306. #define TTBCR_SH1_NON_SHAREABLE (U(0x0) << 28)
  307. #define TTBCR_SH1_OUTER_SHAREABLE (U(0x2) << 28)
  308. #define TTBCR_SH1_INNER_SHAREABLE (U(0x3) << 28)
  309. #define TTBCR_RGN1_OUTER_NC (U(0x0) << 26)
  310. #define TTBCR_RGN1_OUTER_WBA (U(0x1) << 26)
  311. #define TTBCR_RGN1_OUTER_WT (U(0x2) << 26)
  312. #define TTBCR_RGN1_OUTER_WBNA (U(0x3) << 26)
  313. #define TTBCR_RGN1_INNER_NC (U(0x0) << 24)
  314. #define TTBCR_RGN1_INNER_WBA (U(0x1) << 24)
  315. #define TTBCR_RGN1_INNER_WT (U(0x2) << 24)
  316. #define TTBCR_RGN1_INNER_WBNA (U(0x3) << 24)
  317. #define TTBCR_EPD1_BIT (U(1) << 23)
  318. #define TTBCR_A1_BIT (U(1) << 22)
  319. #define TTBCR_T1SZ_SHIFT U(16)
  320. #define TTBCR_T1SZ_MASK U(0x7)
  321. #define TTBCR_TxSZ_MIN U(0)
  322. #define TTBCR_TxSZ_MAX U(7)
  323. #define TTBCR_SH0_NON_SHAREABLE (U(0x0) << 12)
  324. #define TTBCR_SH0_OUTER_SHAREABLE (U(0x2) << 12)
  325. #define TTBCR_SH0_INNER_SHAREABLE (U(0x3) << 12)
  326. #define TTBCR_RGN0_OUTER_NC (U(0x0) << 10)
  327. #define TTBCR_RGN0_OUTER_WBA (U(0x1) << 10)
  328. #define TTBCR_RGN0_OUTER_WT (U(0x2) << 10)
  329. #define TTBCR_RGN0_OUTER_WBNA (U(0x3) << 10)
  330. #define TTBCR_RGN0_INNER_NC (U(0x0) << 8)
  331. #define TTBCR_RGN0_INNER_WBA (U(0x1) << 8)
  332. #define TTBCR_RGN0_INNER_WT (U(0x2) << 8)
  333. #define TTBCR_RGN0_INNER_WBNA (U(0x3) << 8)
  334. #define TTBCR_EPD0_BIT (U(1) << 7)
  335. #define TTBCR_T0SZ_SHIFT U(0)
  336. #define TTBCR_T0SZ_MASK U(0x7)
  337. /*
  338. * HTCR definitions
  339. */
  340. #define HTCR_RES1 ((U(1) << 31) | (U(1) << 23))
  341. #define HTCR_SH0_NON_SHAREABLE (U(0x0) << 12)
  342. #define HTCR_SH0_OUTER_SHAREABLE (U(0x2) << 12)
  343. #define HTCR_SH0_INNER_SHAREABLE (U(0x3) << 12)
  344. #define HTCR_RGN0_OUTER_NC (U(0x0) << 10)
  345. #define HTCR_RGN0_OUTER_WBA (U(0x1) << 10)
  346. #define HTCR_RGN0_OUTER_WT (U(0x2) << 10)
  347. #define HTCR_RGN0_OUTER_WBNA (U(0x3) << 10)
  348. #define HTCR_RGN0_INNER_NC (U(0x0) << 8)
  349. #define HTCR_RGN0_INNER_WBA (U(0x1) << 8)
  350. #define HTCR_RGN0_INNER_WT (U(0x2) << 8)
  351. #define HTCR_RGN0_INNER_WBNA (U(0x3) << 8)
  352. #define HTCR_T0SZ_SHIFT U(0)
  353. #define HTCR_T0SZ_MASK U(0x7)
  354. #define MODE_RW_SHIFT U(0x4)
  355. #define MODE_RW_MASK U(0x1)
  356. #define MODE_RW_32 U(0x1)
  357. #define MODE32_SHIFT U(0)
  358. #define MODE32_MASK U(0x1f)
  359. #define MODE32_usr U(0x10)
  360. #define MODE32_fiq U(0x11)
  361. #define MODE32_irq U(0x12)
  362. #define MODE32_svc U(0x13)
  363. #define MODE32_mon U(0x16)
  364. #define MODE32_abt U(0x17)
  365. #define MODE32_hyp U(0x1a)
  366. #define MODE32_und U(0x1b)
  367. #define MODE32_sys U(0x1f)
  368. #define GET_M32(mode) (((mode) >> MODE32_SHIFT) & MODE32_MASK)
  369. #define SPSR_MODE32(mode, isa, endian, aif) \
  370. ( \
  371. ( \
  372. (MODE_RW_32 << MODE_RW_SHIFT) | \
  373. (((mode) & MODE32_MASK) << MODE32_SHIFT) | \
  374. (((isa) & SPSR_T_MASK) << SPSR_T_SHIFT) | \
  375. (((endian) & SPSR_E_MASK) << SPSR_E_SHIFT) | \
  376. (((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT) \
  377. ) & \
  378. (~(SPSR_SSBS_BIT)) \
  379. )
  380. /*
  381. * TTBR definitions
  382. */
  383. #define TTBR_CNP_BIT ULL(0x1)
  384. /*
  385. * CTR definitions
  386. */
  387. #define CTR_CWG_SHIFT U(24)
  388. #define CTR_CWG_MASK U(0xf)
  389. #define CTR_ERG_SHIFT U(20)
  390. #define CTR_ERG_MASK U(0xf)
  391. #define CTR_DMINLINE_SHIFT U(16)
  392. #define CTR_DMINLINE_WIDTH U(4)
  393. #define CTR_DMINLINE_MASK ((U(1) << 4) - U(1))
  394. #define CTR_L1IP_SHIFT U(14)
  395. #define CTR_L1IP_MASK U(0x3)
  396. #define CTR_IMINLINE_SHIFT U(0)
  397. #define CTR_IMINLINE_MASK U(0xf)
  398. #define MAX_CACHE_LINE_SIZE U(0x800) /* 2KB */
  399. /* PMCR definitions */
  400. #define PMCR_N_SHIFT U(11)
  401. #define PMCR_N_MASK U(0x1f)
  402. #define PMCR_N_BITS (PMCR_N_MASK << PMCR_N_SHIFT)
  403. #define PMCR_LP_BIT (U(1) << 7)
  404. #define PMCR_LC_BIT (U(1) << 6)
  405. #define PMCR_DP_BIT (U(1) << 5)
  406. #define PMCR_X_BIT (U(1) << 4)
  407. #define PMCR_C_BIT (U(1) << 2)
  408. #define PMCR_P_BIT (U(1) << 1)
  409. #define PMCR_E_BIT (U(1) << 0)
  410. #define PMCR_RESET_VAL U(0x0)
  411. /*******************************************************************************
  412. * Definitions of register offsets, fields and macros for CPU system
  413. * instructions.
  414. ******************************************************************************/
  415. #define TLBI_ADDR_SHIFT U(0)
  416. #define TLBI_ADDR_MASK U(0xFFFFF000)
  417. #define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK)
  418. /*******************************************************************************
  419. * Definitions of register offsets and fields in the CNTCTLBase Frame of the
  420. * system level implementation of the Generic Timer.
  421. ******************************************************************************/
  422. #define CNTCTLBASE_CNTFRQ U(0x0)
  423. #define CNTNSAR U(0x4)
  424. #define CNTNSAR_NS_SHIFT(x) (x)
  425. #define CNTACR_BASE(x) (U(0x40) + ((x) << 2))
  426. #define CNTACR_RPCT_SHIFT U(0x0)
  427. #define CNTACR_RVCT_SHIFT U(0x1)
  428. #define CNTACR_RFRQ_SHIFT U(0x2)
  429. #define CNTACR_RVOFF_SHIFT U(0x3)
  430. #define CNTACR_RWVT_SHIFT U(0x4)
  431. #define CNTACR_RWPT_SHIFT U(0x5)
  432. /*******************************************************************************
  433. * Definitions of register offsets and fields in the CNTBaseN Frame of the
  434. * system level implementation of the Generic Timer.
  435. ******************************************************************************/
  436. /* Physical Count register. */
  437. #define CNTPCT_LO U(0x0)
  438. /* Counter Frequency register. */
  439. #define CNTBASEN_CNTFRQ U(0x10)
  440. /* Physical Timer CompareValue register. */
  441. #define CNTP_CVAL_LO U(0x20)
  442. /* Physical Timer Control register. */
  443. #define CNTP_CTL U(0x2c)
  444. /* Physical timer control register bit fields shifts and masks */
  445. #define CNTP_CTL_ENABLE_SHIFT 0
  446. #define CNTP_CTL_IMASK_SHIFT 1
  447. #define CNTP_CTL_ISTATUS_SHIFT 2
  448. #define CNTP_CTL_ENABLE_MASK U(1)
  449. #define CNTP_CTL_IMASK_MASK U(1)
  450. #define CNTP_CTL_ISTATUS_MASK U(1)
  451. /* MAIR macros */
  452. #define MAIR0_ATTR_SET(attr, index) ((attr) << ((index) << U(3)))
  453. #define MAIR1_ATTR_SET(attr, index) ((attr) << (((index) - U(3)) << U(3)))
  454. /* System register defines The format is: coproc, opt1, CRn, CRm, opt2 */
  455. #define SCR p15, 0, c1, c1, 0
  456. #define SCTLR p15, 0, c1, c0, 0
  457. #define ACTLR p15, 0, c1, c0, 1
  458. #define SDCR p15, 0, c1, c3, 1
  459. #define MPIDR p15, 0, c0, c0, 5
  460. #define MIDR p15, 0, c0, c0, 0
  461. #define HVBAR p15, 4, c12, c0, 0
  462. #define VBAR p15, 0, c12, c0, 0
  463. #define MVBAR p15, 0, c12, c0, 1
  464. #define NSACR p15, 0, c1, c1, 2
  465. #define CPACR p15, 0, c1, c0, 2
  466. #define DCCIMVAC p15, 0, c7, c14, 1
  467. #define DCCMVAC p15, 0, c7, c10, 1
  468. #define DCIMVAC p15, 0, c7, c6, 1
  469. #define DCCISW p15, 0, c7, c14, 2
  470. #define DCCSW p15, 0, c7, c10, 2
  471. #define DCISW p15, 0, c7, c6, 2
  472. #define CTR p15, 0, c0, c0, 1
  473. #define CNTFRQ p15, 0, c14, c0, 0
  474. #define ID_MMFR3 p15, 0, c0, c1, 7
  475. #define ID_MMFR4 p15, 0, c0, c2, 6
  476. #define ID_DFR0 p15, 0, c0, c1, 2
  477. #define ID_DFR1 p15, 0, c0, c3, 5
  478. #define ID_PFR0 p15, 0, c0, c1, 0
  479. #define ID_PFR1 p15, 0, c0, c1, 1
  480. #define ID_PFR2 p15, 0, c0, c3, 4
  481. #define MAIR0 p15, 0, c10, c2, 0
  482. #define MAIR1 p15, 0, c10, c2, 1
  483. #define TTBCR p15, 0, c2, c0, 2
  484. #define TTBR0 p15, 0, c2, c0, 0
  485. #define TTBR1 p15, 0, c2, c0, 1
  486. #define TLBIALL p15, 0, c8, c7, 0
  487. #define TLBIALLH p15, 4, c8, c7, 0
  488. #define TLBIALLIS p15, 0, c8, c3, 0
  489. #define TLBIMVA p15, 0, c8, c7, 1
  490. #define TLBIMVAA p15, 0, c8, c7, 3
  491. #define TLBIMVAAIS p15, 0, c8, c3, 3
  492. #define TLBIMVAHIS p15, 4, c8, c3, 1
  493. #define BPIALLIS p15, 0, c7, c1, 6
  494. #define BPIALL p15, 0, c7, c5, 6
  495. #define ICIALLU p15, 0, c7, c5, 0
  496. #define HSCTLR p15, 4, c1, c0, 0
  497. #define HCR p15, 4, c1, c1, 0
  498. #define HCPTR p15, 4, c1, c1, 2
  499. #define HSTR p15, 4, c1, c1, 3
  500. #define CNTHCTL p15, 4, c14, c1, 0
  501. #define CNTKCTL p15, 0, c14, c1, 0
  502. #define VPIDR p15, 4, c0, c0, 0
  503. #define VMPIDR p15, 4, c0, c0, 5
  504. #define ISR p15, 0, c12, c1, 0
  505. #define CLIDR p15, 1, c0, c0, 1
  506. #define CSSELR p15, 2, c0, c0, 0
  507. #define CCSIDR p15, 1, c0, c0, 0
  508. #define CCSIDR2 p15, 1, c0, c0, 2
  509. #define HTCR p15, 4, c2, c0, 2
  510. #define HMAIR0 p15, 4, c10, c2, 0
  511. #define ATS1CPR p15, 0, c7, c8, 0
  512. #define ATS1HR p15, 4, c7, c8, 0
  513. #define DBGOSDLR p14, 0, c1, c3, 4
  514. /* Debug register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
  515. #define HDCR p15, 4, c1, c1, 1
  516. #define PMCR p15, 0, c9, c12, 0
  517. #define CNTHP_TVAL p15, 4, c14, c2, 0
  518. #define CNTHP_CTL p15, 4, c14, c2, 1
  519. /* AArch32 coproc registers for 32bit MMU descriptor support */
  520. #define PRRR p15, 0, c10, c2, 0
  521. #define NMRR p15, 0, c10, c2, 1
  522. #define DACR p15, 0, c3, c0, 0
  523. /* GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
  524. #define ICC_IAR1 p15, 0, c12, c12, 0
  525. #define ICC_IAR0 p15, 0, c12, c8, 0
  526. #define ICC_EOIR1 p15, 0, c12, c12, 1
  527. #define ICC_EOIR0 p15, 0, c12, c8, 1
  528. #define ICC_HPPIR1 p15, 0, c12, c12, 2
  529. #define ICC_HPPIR0 p15, 0, c12, c8, 2
  530. #define ICC_BPR1 p15, 0, c12, c12, 3
  531. #define ICC_BPR0 p15, 0, c12, c8, 3
  532. #define ICC_DIR p15, 0, c12, c11, 1
  533. #define ICC_PMR p15, 0, c4, c6, 0
  534. #define ICC_RPR p15, 0, c12, c11, 3
  535. #define ICC_CTLR p15, 0, c12, c12, 4
  536. #define ICC_MCTLR p15, 6, c12, c12, 4
  537. #define ICC_SRE p15, 0, c12, c12, 5
  538. #define ICC_HSRE p15, 4, c12, c9, 5
  539. #define ICC_MSRE p15, 6, c12, c12, 5
  540. #define ICC_IGRPEN0 p15, 0, c12, c12, 6
  541. #define ICC_IGRPEN1 p15, 0, c12, c12, 7
  542. #define ICC_MGRPEN1 p15, 6, c12, c12, 7
  543. /* 64 bit system register defines The format is: coproc, opt1, CRm */
  544. #define TTBR0_64 p15, 0, c2
  545. #define TTBR1_64 p15, 1, c2
  546. #define CNTVOFF_64 p15, 4, c14
  547. #define VTTBR_64 p15, 6, c2
  548. #define CNTPCT_64 p15, 0, c14
  549. #define HTTBR_64 p15, 4, c2
  550. #define CNTHP_CVAL_64 p15, 6, c14
  551. #define PAR_64 p15, 0, c7
  552. /* 64 bit GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRm */
  553. #define ICC_SGI1R_EL1_64 p15, 0, c12
  554. #define ICC_ASGI1R_EL1_64 p15, 1, c12
  555. #define ICC_SGI0R_EL1_64 p15, 2, c12
  556. /* Fault registers. The format is: coproc, opt1, CRn, CRm, opt2 */
  557. #define DFSR p15, 0, c5, c0, 0
  558. #define IFSR p15, 0, c5, c0, 1
  559. #define DFAR p15, 0, c6, c0, 0
  560. #define IFAR p15, 0, c6, c0, 2
  561. /*******************************************************************************
  562. * Definitions of MAIR encodings for device and normal memory
  563. ******************************************************************************/
  564. /*
  565. * MAIR encodings for device memory attributes.
  566. */
  567. #define MAIR_DEV_nGnRnE U(0x0)
  568. #define MAIR_DEV_nGnRE U(0x4)
  569. #define MAIR_DEV_nGRE U(0x8)
  570. #define MAIR_DEV_GRE U(0xc)
  571. /*
  572. * MAIR encodings for normal memory attributes.
  573. *
  574. * Cache Policy
  575. * WT: Write Through
  576. * WB: Write Back
  577. * NC: Non-Cacheable
  578. *
  579. * Transient Hint
  580. * NTR: Non-Transient
  581. * TR: Transient
  582. *
  583. * Allocation Policy
  584. * RA: Read Allocate
  585. * WA: Write Allocate
  586. * RWA: Read and Write Allocate
  587. * NA: No Allocation
  588. */
  589. #define MAIR_NORM_WT_TR_WA U(0x1)
  590. #define MAIR_NORM_WT_TR_RA U(0x2)
  591. #define MAIR_NORM_WT_TR_RWA U(0x3)
  592. #define MAIR_NORM_NC U(0x4)
  593. #define MAIR_NORM_WB_TR_WA U(0x5)
  594. #define MAIR_NORM_WB_TR_RA U(0x6)
  595. #define MAIR_NORM_WB_TR_RWA U(0x7)
  596. #define MAIR_NORM_WT_NTR_NA U(0x8)
  597. #define MAIR_NORM_WT_NTR_WA U(0x9)
  598. #define MAIR_NORM_WT_NTR_RA U(0xa)
  599. #define MAIR_NORM_WT_NTR_RWA U(0xb)
  600. #define MAIR_NORM_WB_NTR_NA U(0xc)
  601. #define MAIR_NORM_WB_NTR_WA U(0xd)
  602. #define MAIR_NORM_WB_NTR_RA U(0xe)
  603. #define MAIR_NORM_WB_NTR_RWA U(0xf)
  604. #define MAIR_NORM_OUTER_SHIFT U(4)
  605. #define MAKE_MAIR_NORMAL_MEMORY(inner, outer) \
  606. ((inner) | ((outer) << MAIR_NORM_OUTER_SHIFT))
  607. /* PAR fields */
  608. #define PAR_F_SHIFT U(0)
  609. #define PAR_F_MASK ULL(0x1)
  610. #define PAR_ADDR_MASK GENMASK_64(39, 12) /* 28-bits-wide page address */
  611. /*******************************************************************************
  612. * Definitions for system register interface to AMU for FEAT_AMUv1
  613. ******************************************************************************/
  614. #define AMCR p15, 0, c13, c2, 0
  615. #define AMCFGR p15, 0, c13, c2, 1
  616. #define AMCGCR p15, 0, c13, c2, 2
  617. #define AMUSERENR p15, 0, c13, c2, 3
  618. #define AMCNTENCLR0 p15, 0, c13, c2, 4
  619. #define AMCNTENSET0 p15, 0, c13, c2, 5
  620. #define AMCNTENCLR1 p15, 0, c13, c3, 0
  621. #define AMCNTENSET1 p15, 0, c13, c3, 1
  622. /* Activity Monitor Group 0 Event Counter Registers */
  623. #define AMEVCNTR00 p15, 0, c0
  624. #define AMEVCNTR01 p15, 1, c0
  625. #define AMEVCNTR02 p15, 2, c0
  626. #define AMEVCNTR03 p15, 3, c0
  627. /* Activity Monitor Group 0 Event Type Registers */
  628. #define AMEVTYPER00 p15, 0, c13, c6, 0
  629. #define AMEVTYPER01 p15, 0, c13, c6, 1
  630. #define AMEVTYPER02 p15, 0, c13, c6, 2
  631. #define AMEVTYPER03 p15, 0, c13, c6, 3
  632. /* Activity Monitor Group 1 Event Counter Registers */
  633. #define AMEVCNTR10 p15, 0, c4
  634. #define AMEVCNTR11 p15, 1, c4
  635. #define AMEVCNTR12 p15, 2, c4
  636. #define AMEVCNTR13 p15, 3, c4
  637. #define AMEVCNTR14 p15, 4, c4
  638. #define AMEVCNTR15 p15, 5, c4
  639. #define AMEVCNTR16 p15, 6, c4
  640. #define AMEVCNTR17 p15, 7, c4
  641. #define AMEVCNTR18 p15, 0, c5
  642. #define AMEVCNTR19 p15, 1, c5
  643. #define AMEVCNTR1A p15, 2, c5
  644. #define AMEVCNTR1B p15, 3, c5
  645. #define AMEVCNTR1C p15, 4, c5
  646. #define AMEVCNTR1D p15, 5, c5
  647. #define AMEVCNTR1E p15, 6, c5
  648. #define AMEVCNTR1F p15, 7, c5
  649. /* Activity Monitor Group 1 Event Type Registers */
  650. #define AMEVTYPER10 p15, 0, c13, c14, 0
  651. #define AMEVTYPER11 p15, 0, c13, c14, 1
  652. #define AMEVTYPER12 p15, 0, c13, c14, 2
  653. #define AMEVTYPER13 p15, 0, c13, c14, 3
  654. #define AMEVTYPER14 p15, 0, c13, c14, 4
  655. #define AMEVTYPER15 p15, 0, c13, c14, 5
  656. #define AMEVTYPER16 p15, 0, c13, c14, 6
  657. #define AMEVTYPER17 p15, 0, c13, c14, 7
  658. #define AMEVTYPER18 p15, 0, c13, c15, 0
  659. #define AMEVTYPER19 p15, 0, c13, c15, 1
  660. #define AMEVTYPER1A p15, 0, c13, c15, 2
  661. #define AMEVTYPER1B p15, 0, c13, c15, 3
  662. #define AMEVTYPER1C p15, 0, c13, c15, 4
  663. #define AMEVTYPER1D p15, 0, c13, c15, 5
  664. #define AMEVTYPER1E p15, 0, c13, c15, 6
  665. #define AMEVTYPER1F p15, 0, c13, c15, 7
  666. /* AMCNTENSET0 definitions */
  667. #define AMCNTENSET0_Pn_SHIFT U(0)
  668. #define AMCNTENSET0_Pn_MASK U(0xffff)
  669. /* AMCNTENSET1 definitions */
  670. #define AMCNTENSET1_Pn_SHIFT U(0)
  671. #define AMCNTENSET1_Pn_MASK U(0xffff)
  672. /* AMCNTENCLR0 definitions */
  673. #define AMCNTENCLR0_Pn_SHIFT U(0)
  674. #define AMCNTENCLR0_Pn_MASK U(0xffff)
  675. /* AMCNTENCLR1 definitions */
  676. #define AMCNTENCLR1_Pn_SHIFT U(0)
  677. #define AMCNTENCLR1_Pn_MASK U(0xffff)
  678. /* AMCR definitions */
  679. #define AMCR_CG1RZ_SHIFT U(17)
  680. #define AMCR_CG1RZ_BIT (ULL(1) << AMCR_CG1RZ_SHIFT)
  681. /* AMCFGR definitions */
  682. #define AMCFGR_NCG_SHIFT U(28)
  683. #define AMCFGR_NCG_MASK U(0xf)
  684. #define AMCFGR_N_SHIFT U(0)
  685. #define AMCFGR_N_MASK U(0xff)
  686. /* AMCGCR definitions */
  687. #define AMCGCR_CG0NC_SHIFT U(0)
  688. #define AMCGCR_CG0NC_MASK U(0xff)
  689. #define AMCGCR_CG1NC_SHIFT U(8)
  690. #define AMCGCR_CG1NC_MASK U(0xff)
  691. /*******************************************************************************
  692. * Definitions for DynamicIQ Shared Unit registers
  693. ******************************************************************************/
  694. #define CLUSTERPWRDN p15, 0, c15, c3, 6
  695. #define CLUSTERPMCR p15, 0, c15, c5, 0
  696. #define CLUSTERPMCNTENSET p15, 0, c15, c5, 1
  697. #define CLUSTERPMCCNTR p15, 0, c15, c6, 0
  698. #define CLUSTERPMOVSSET p15, 0, c15, c5, 3
  699. #define CLUSTERPMOVSCLR p15, 0, c15, c5, 4
  700. #define CLUSTERPMSELR p15, 0, c15, c5, 5
  701. #define CLUSTERPMXEVTYPER p15, 0, c15, c6, 1
  702. #define CLUSTERPMXEVCNTR p15, 0, c15, c6, 2
  703. /* CLUSTERPMCR register definitions */
  704. #define CLUSTERPMCR_E_BIT BIT(0)
  705. #define CLUSTERPMCR_N_SHIFT U(11)
  706. #define CLUSTERPMCR_N_MASK U(0x1f)
  707. /* CLUSTERPWRDN register definitions */
  708. #define DSU_CLUSTER_PWR_OFF 0
  709. #define DSU_CLUSTER_PWR_ON 1
  710. #define DSU_CLUSTER_PWR_MASK U(1)
  711. #define DSU_CLUSTER_MEM_RET BIT(1)
  712. #endif /* ARCH_H */