arch.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  1. /*
  2. * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2020-2022, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef ARCH_H
  8. #define ARCH_H
  9. #include <lib/utils_def.h>
  10. /*******************************************************************************
  11. * MIDR bit definitions
  12. ******************************************************************************/
  13. #define MIDR_IMPL_MASK U(0xff)
  14. #define MIDR_IMPL_SHIFT U(0x18)
  15. #define MIDR_VAR_SHIFT U(20)
  16. #define MIDR_VAR_BITS U(4)
  17. #define MIDR_VAR_MASK U(0xf)
  18. #define MIDR_REV_SHIFT U(0)
  19. #define MIDR_REV_BITS U(4)
  20. #define MIDR_REV_MASK U(0xf)
  21. #define MIDR_PN_MASK U(0xfff)
  22. #define MIDR_PN_SHIFT U(0x4)
  23. /*******************************************************************************
  24. * MPIDR macros
  25. ******************************************************************************/
  26. #define MPIDR_MT_MASK (ULL(1) << 24)
  27. #define MPIDR_CPU_MASK MPIDR_AFFLVL_MASK
  28. #define MPIDR_CLUSTER_MASK (MPIDR_AFFLVL_MASK << MPIDR_AFFINITY_BITS)
  29. #define MPIDR_AFFINITY_BITS U(8)
  30. #define MPIDR_AFFLVL_MASK ULL(0xff)
  31. #define MPIDR_AFF0_SHIFT U(0)
  32. #define MPIDR_AFF1_SHIFT U(8)
  33. #define MPIDR_AFF2_SHIFT U(16)
  34. #define MPIDR_AFF3_SHIFT U(32)
  35. #define MPIDR_AFF_SHIFT(_n) MPIDR_AFF##_n##_SHIFT
  36. #define MPIDR_AFFINITY_MASK ULL(0xff00ffffff)
  37. #define MPIDR_AFFLVL_SHIFT U(3)
  38. #define MPIDR_AFFLVL0 ULL(0x0)
  39. #define MPIDR_AFFLVL1 ULL(0x1)
  40. #define MPIDR_AFFLVL2 ULL(0x2)
  41. #define MPIDR_AFFLVL3 ULL(0x3)
  42. #define MPIDR_AFFLVL(_n) MPIDR_AFFLVL##_n
  43. #define MPIDR_AFFLVL0_VAL(mpidr) \
  44. (((mpidr) >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK)
  45. #define MPIDR_AFFLVL1_VAL(mpidr) \
  46. (((mpidr) >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK)
  47. #define MPIDR_AFFLVL2_VAL(mpidr) \
  48. (((mpidr) >> MPIDR_AFF2_SHIFT) & MPIDR_AFFLVL_MASK)
  49. #define MPIDR_AFFLVL3_VAL(mpidr) \
  50. (((mpidr) >> MPIDR_AFF3_SHIFT) & MPIDR_AFFLVL_MASK)
  51. /*
  52. * The MPIDR_MAX_AFFLVL count starts from 0. Take care to
  53. * add one while using this macro to define array sizes.
  54. * TODO: Support only the first 3 affinity levels for now.
  55. */
  56. #define MPIDR_MAX_AFFLVL U(2)
  57. #define MPID_MASK (MPIDR_MT_MASK | \
  58. (MPIDR_AFFLVL_MASK << MPIDR_AFF3_SHIFT) | \
  59. (MPIDR_AFFLVL_MASK << MPIDR_AFF2_SHIFT) | \
  60. (MPIDR_AFFLVL_MASK << MPIDR_AFF1_SHIFT) | \
  61. (MPIDR_AFFLVL_MASK << MPIDR_AFF0_SHIFT))
  62. #define MPIDR_AFF_ID(mpid, n) \
  63. (((mpid) >> MPIDR_AFF_SHIFT(n)) & MPIDR_AFFLVL_MASK)
  64. /*
  65. * An invalid MPID. This value can be used by functions that return an MPID to
  66. * indicate an error.
  67. */
  68. #define INVALID_MPID U(0xFFFFFFFF)
  69. /*******************************************************************************
  70. * Definitions for Exception vector offsets
  71. ******************************************************************************/
  72. #define CURRENT_EL_SP0 0x0
  73. #define CURRENT_EL_SPX 0x200
  74. #define LOWER_EL_AARCH64 0x400
  75. #define LOWER_EL_AARCH32 0x600
  76. #define SYNC_EXCEPTION 0x0
  77. #define IRQ_EXCEPTION 0x80
  78. #define FIQ_EXCEPTION 0x100
  79. #define SERROR_EXCEPTION 0x180
  80. /*******************************************************************************
  81. * Definitions for CPU system register interface to GICv3
  82. ******************************************************************************/
  83. #define ICC_IGRPEN1_EL1 S3_0_C12_C12_7
  84. #define ICC_SGI1R S3_0_C12_C11_5
  85. #define ICC_ASGI1R S3_0_C12_C11_6
  86. #define ICC_SRE_EL1 S3_0_C12_C12_5
  87. #define ICC_SRE_EL2 S3_4_C12_C9_5
  88. #define ICC_SRE_EL3 S3_6_C12_C12_5
  89. #define ICC_CTLR_EL1 S3_0_C12_C12_4
  90. #define ICC_CTLR_EL3 S3_6_C12_C12_4
  91. #define ICC_PMR_EL1 S3_0_C4_C6_0
  92. #define ICC_RPR_EL1 S3_0_C12_C11_3
  93. #define ICC_IGRPEN1_EL3 S3_6_c12_c12_7
  94. #define ICC_IGRPEN0_EL1 S3_0_c12_c12_6
  95. #define ICC_HPPIR0_EL1 S3_0_c12_c8_2
  96. #define ICC_HPPIR1_EL1 S3_0_c12_c12_2
  97. #define ICC_IAR0_EL1 S3_0_c12_c8_0
  98. #define ICC_IAR1_EL1 S3_0_c12_c12_0
  99. #define ICC_EOIR0_EL1 S3_0_c12_c8_1
  100. #define ICC_EOIR1_EL1 S3_0_c12_c12_1
  101. #define ICC_SGI0R_EL1 S3_0_c12_c11_7
  102. /*******************************************************************************
  103. * Definitions for EL2 system registers for save/restore routine
  104. ******************************************************************************/
  105. #define CNTPOFF_EL2 S3_4_C14_C0_6
  106. #define HAFGRTR_EL2 S3_4_C3_C1_6
  107. #define HDFGRTR_EL2 S3_4_C3_C1_4
  108. #define HDFGWTR_EL2 S3_4_C3_C1_5
  109. #define HFGITR_EL2 S3_4_C1_C1_6
  110. #define HFGRTR_EL2 S3_4_C1_C1_4
  111. #define HFGWTR_EL2 S3_4_C1_C1_5
  112. #define ICH_HCR_EL2 S3_4_C12_C11_0
  113. #define ICH_VMCR_EL2 S3_4_C12_C11_7
  114. #define MPAMVPM0_EL2 S3_4_C10_C6_0
  115. #define MPAMVPM1_EL2 S3_4_C10_C6_1
  116. #define MPAMVPM2_EL2 S3_4_C10_C6_2
  117. #define MPAMVPM3_EL2 S3_4_C10_C6_3
  118. #define MPAMVPM4_EL2 S3_4_C10_C6_4
  119. #define MPAMVPM5_EL2 S3_4_C10_C6_5
  120. #define MPAMVPM6_EL2 S3_4_C10_C6_6
  121. #define MPAMVPM7_EL2 S3_4_C10_C6_7
  122. #define MPAMVPMV_EL2 S3_4_C10_C4_1
  123. #define VNCR_EL2 S3_4_C2_C2_0
  124. #define PMSCR_EL2 S3_4_C9_C9_0
  125. #define TFSR_EL2 S3_4_C5_C6_0
  126. #define CONTEXTIDR_EL2 S3_4_C13_C0_1
  127. #define TTBR1_EL2 S3_4_C2_C0_1
  128. /*******************************************************************************
  129. * Generic timer memory mapped registers & offsets
  130. ******************************************************************************/
  131. #define CNTCR_OFF U(0x000)
  132. #define CNTCV_OFF U(0x008)
  133. #define CNTFID_OFF U(0x020)
  134. #define CNTCR_EN (U(1) << 0)
  135. #define CNTCR_HDBG (U(1) << 1)
  136. #define CNTCR_FCREQ(x) ((x) << 8)
  137. /*******************************************************************************
  138. * System register bit definitions
  139. ******************************************************************************/
  140. /* CLIDR definitions */
  141. #define LOUIS_SHIFT U(21)
  142. #define LOC_SHIFT U(24)
  143. #define CTYPE_SHIFT(n) U(3 * (n - 1))
  144. #define CLIDR_FIELD_WIDTH U(3)
  145. /* CSSELR definitions */
  146. #define LEVEL_SHIFT U(1)
  147. /* Data cache set/way op type defines */
  148. #define DCISW U(0x0)
  149. #define DCCISW U(0x1)
  150. #if ERRATA_A53_827319
  151. #define DCCSW DCCISW
  152. #else
  153. #define DCCSW U(0x2)
  154. #endif
  155. #define ID_REG_FIELD_MASK ULL(0xf)
  156. /* ID_AA64PFR0_EL1 definitions */
  157. #define ID_AA64PFR0_EL0_SHIFT U(0)
  158. #define ID_AA64PFR0_EL1_SHIFT U(4)
  159. #define ID_AA64PFR0_EL2_SHIFT U(8)
  160. #define ID_AA64PFR0_EL3_SHIFT U(12)
  161. #define ID_AA64PFR0_AMU_SHIFT U(44)
  162. #define ID_AA64PFR0_AMU_MASK ULL(0xf)
  163. #define ID_AA64PFR0_AMU_V1 ULL(0x1)
  164. #define ID_AA64PFR0_AMU_V1P1 U(0x2)
  165. #define ID_AA64PFR0_ELX_MASK ULL(0xf)
  166. #define ID_AA64PFR0_GIC_SHIFT U(24)
  167. #define ID_AA64PFR0_GIC_WIDTH U(4)
  168. #define ID_AA64PFR0_GIC_MASK ULL(0xf)
  169. #define ID_AA64PFR0_SVE_SHIFT U(32)
  170. #define ID_AA64PFR0_SVE_MASK ULL(0xf)
  171. #define ID_AA64PFR0_SVE_LENGTH U(4)
  172. #define SVE_IMPLEMENTED ULL(0x1)
  173. #define ID_AA64PFR0_SEL2_SHIFT U(36)
  174. #define ID_AA64PFR0_SEL2_MASK ULL(0xf)
  175. #define ID_AA64PFR0_MPAM_SHIFT U(40)
  176. #define ID_AA64PFR0_MPAM_MASK ULL(0xf)
  177. #define ID_AA64PFR0_DIT_SHIFT U(48)
  178. #define ID_AA64PFR0_DIT_MASK ULL(0xf)
  179. #define ID_AA64PFR0_DIT_LENGTH U(4)
  180. #define DIT_IMPLEMENTED ULL(1)
  181. #define ID_AA64PFR0_CSV2_SHIFT U(56)
  182. #define ID_AA64PFR0_CSV2_MASK ULL(0xf)
  183. #define ID_AA64PFR0_CSV2_LENGTH U(4)
  184. #define CSV2_2_IMPLEMENTED ULL(0x2)
  185. #define CSV2_3_IMPLEMENTED ULL(0x3)
  186. #define ID_AA64PFR0_FEAT_RME_SHIFT U(52)
  187. #define ID_AA64PFR0_FEAT_RME_MASK ULL(0xf)
  188. #define ID_AA64PFR0_FEAT_RME_LENGTH U(4)
  189. #define RME_NOT_IMPLEMENTED ULL(0)
  190. #define ID_AA64PFR0_RAS_SHIFT U(28)
  191. #define ID_AA64PFR0_RAS_MASK ULL(0xf)
  192. #define ID_AA64PFR0_RAS_LENGTH U(4)
  193. /* Exception level handling */
  194. #define EL_IMPL_NONE ULL(0)
  195. #define EL_IMPL_A64ONLY ULL(1)
  196. #define EL_IMPL_A64_A32 ULL(2)
  197. /* ID_AA64DFR0_EL1.TraceVer definitions */
  198. #define ID_AA64DFR0_TRACEVER_SHIFT U(4)
  199. #define ID_AA64DFR0_TRACEVER_MASK ULL(0xf)
  200. #define ID_AA64DFR0_TRACEVER_LENGTH U(4)
  201. #define ID_AA64DFR0_TRACEFILT_SHIFT U(40)
  202. #define ID_AA64DFR0_TRACEFILT_MASK U(0xf)
  203. #define ID_AA64DFR0_TRACEFILT_LENGTH U(4)
  204. #define TRACEFILT_IMPLEMENTED ULL(1)
  205. #define ID_AA64DFR0_PMUVER_LENGTH U(4)
  206. #define ID_AA64DFR0_PMUVER_SHIFT U(8)
  207. #define ID_AA64DFR0_PMUVER_MASK U(0xf)
  208. #define ID_AA64DFR0_PMUVER_PMUV3 U(1)
  209. #define ID_AA64DFR0_PMUVER_PMUV3P7 U(7)
  210. #define ID_AA64DFR0_PMUVER_IMP_DEF U(0xf)
  211. /* ID_AA64DFR0_EL1.SEBEP definitions */
  212. #define ID_AA64DFR0_SEBEP_SHIFT U(24)
  213. #define ID_AA64DFR0_SEBEP_MASK ULL(0xf)
  214. #define SEBEP_IMPLEMENTED ULL(1)
  215. /* ID_AA64DFR0_EL1.PMS definitions (for ARMv8.2+) */
  216. #define ID_AA64DFR0_PMS_SHIFT U(32)
  217. #define ID_AA64DFR0_PMS_MASK ULL(0xf)
  218. #define SPE_IMPLEMENTED ULL(0x1)
  219. #define SPE_NOT_IMPLEMENTED ULL(0x0)
  220. /* ID_AA64DFR0_EL1.TraceBuffer definitions */
  221. #define ID_AA64DFR0_TRACEBUFFER_SHIFT U(44)
  222. #define ID_AA64DFR0_TRACEBUFFER_MASK ULL(0xf)
  223. #define TRACEBUFFER_IMPLEMENTED ULL(1)
  224. /* ID_AA64DFR0_EL1.MTPMU definitions (for ARMv8.6+) */
  225. #define ID_AA64DFR0_MTPMU_SHIFT U(48)
  226. #define ID_AA64DFR0_MTPMU_MASK ULL(0xf)
  227. #define MTPMU_IMPLEMENTED ULL(1)
  228. #define MTPMU_NOT_IMPLEMENTED ULL(15)
  229. /* ID_AA64DFR0_EL1.BRBE definitions */
  230. #define ID_AA64DFR0_BRBE_SHIFT U(52)
  231. #define ID_AA64DFR0_BRBE_MASK ULL(0xf)
  232. #define BRBE_IMPLEMENTED ULL(1)
  233. /* ID_AA64DFR1_EL1 definitions */
  234. #define ID_AA64DFR1_EBEP_SHIFT U(48)
  235. #define ID_AA64DFR1_EBEP_MASK ULL(0xf)
  236. #define EBEP_IMPLEMENTED ULL(1)
  237. /* ID_AA64ISAR0_EL1 definitions */
  238. #define ID_AA64ISAR0_RNDR_SHIFT U(60)
  239. #define ID_AA64ISAR0_RNDR_MASK ULL(0xf)
  240. /* ID_AA64ISAR1_EL1 definitions */
  241. #define ID_AA64ISAR1_EL1 S3_0_C0_C6_1
  242. #define ID_AA64ISAR1_GPI_SHIFT U(28)
  243. #define ID_AA64ISAR1_GPI_MASK ULL(0xf)
  244. #define ID_AA64ISAR1_GPA_SHIFT U(24)
  245. #define ID_AA64ISAR1_GPA_MASK ULL(0xf)
  246. #define ID_AA64ISAR1_API_SHIFT U(8)
  247. #define ID_AA64ISAR1_API_MASK ULL(0xf)
  248. #define ID_AA64ISAR1_APA_SHIFT U(4)
  249. #define ID_AA64ISAR1_APA_MASK ULL(0xf)
  250. #define ID_AA64ISAR1_SB_SHIFT U(36)
  251. #define ID_AA64ISAR1_SB_MASK ULL(0xf)
  252. #define SB_IMPLEMENTED ULL(0x1)
  253. #define SB_NOT_IMPLEMENTED ULL(0x0)
  254. /* ID_AA64ISAR2_EL1 definitions */
  255. #define ID_AA64ISAR2_EL1 S3_0_C0_C6_2
  256. /* ID_AA64PFR2_EL1 definitions */
  257. #define ID_AA64PFR2_EL1 S3_0_C0_C4_2
  258. #define ID_AA64ISAR2_GPA3_SHIFT U(8)
  259. #define ID_AA64ISAR2_GPA3_MASK ULL(0xf)
  260. #define ID_AA64ISAR2_APA3_SHIFT U(12)
  261. #define ID_AA64ISAR2_APA3_MASK ULL(0xf)
  262. /* ID_AA64MMFR0_EL1 definitions */
  263. #define ID_AA64MMFR0_EL1_PARANGE_SHIFT U(0)
  264. #define ID_AA64MMFR0_EL1_PARANGE_MASK ULL(0xf)
  265. #define PARANGE_0000 U(32)
  266. #define PARANGE_0001 U(36)
  267. #define PARANGE_0010 U(40)
  268. #define PARANGE_0011 U(42)
  269. #define PARANGE_0100 U(44)
  270. #define PARANGE_0101 U(48)
  271. #define PARANGE_0110 U(52)
  272. #define ID_AA64MMFR0_EL1_ECV_SHIFT U(60)
  273. #define ID_AA64MMFR0_EL1_ECV_MASK ULL(0xf)
  274. #define ID_AA64MMFR0_EL1_ECV_SELF_SYNCH ULL(0x2)
  275. #define ECV_IMPLEMENTED ULL(0x1)
  276. #define ID_AA64MMFR0_EL1_FGT_SHIFT U(56)
  277. #define ID_AA64MMFR0_EL1_FGT_MASK ULL(0xf)
  278. #define FGT_IMPLEMENTED ULL(0x1)
  279. #define FGT_NOT_IMPLEMENTED ULL(0x0)
  280. #define ID_AA64MMFR0_EL1_TGRAN4_SHIFT U(28)
  281. #define ID_AA64MMFR0_EL1_TGRAN4_MASK ULL(0xf)
  282. #define ID_AA64MMFR0_EL1_TGRAN64_SHIFT U(24)
  283. #define ID_AA64MMFR0_EL1_TGRAN64_MASK ULL(0xf)
  284. #define ID_AA64MMFR0_EL1_TGRAN16_SHIFT U(20)
  285. #define ID_AA64MMFR0_EL1_TGRAN16_MASK ULL(0xf)
  286. #define TGRAN16_IMPLEMENTED ULL(0x1)
  287. /* ID_AA64MMFR1_EL1 definitions */
  288. #define ID_AA64MMFR1_EL1_TWED_SHIFT U(32)
  289. #define ID_AA64MMFR1_EL1_TWED_MASK ULL(0xf)
  290. #define TWED_IMPLEMENTED ULL(0x1)
  291. #define ID_AA64MMFR1_EL1_PAN_SHIFT U(20)
  292. #define ID_AA64MMFR1_EL1_PAN_MASK ULL(0xf)
  293. #define PAN_IMPLEMENTED ULL(0x1)
  294. #define PAN2_IMPLEMENTED ULL(0x2)
  295. #define PAN3_IMPLEMENTED ULL(0x3)
  296. #define ID_AA64MMFR1_EL1_VHE_SHIFT U(8)
  297. #define ID_AA64MMFR1_EL1_VHE_MASK ULL(0xf)
  298. #define ID_AA64MMFR1_EL1_HCX_SHIFT U(40)
  299. #define ID_AA64MMFR1_EL1_HCX_MASK ULL(0xf)
  300. #define HCX_IMPLEMENTED ULL(0x1)
  301. /* ID_AA64MMFR2_EL1 definitions */
  302. #define ID_AA64MMFR2_EL1 S3_0_C0_C7_2
  303. #define ID_AA64MMFR2_EL1_ST_SHIFT U(28)
  304. #define ID_AA64MMFR2_EL1_ST_MASK ULL(0xf)
  305. #define ID_AA64MMFR2_EL1_CCIDX_SHIFT U(20)
  306. #define ID_AA64MMFR2_EL1_CCIDX_MASK ULL(0xf)
  307. #define ID_AA64MMFR2_EL1_CCIDX_LENGTH U(4)
  308. #define ID_AA64MMFR2_EL1_UAO_SHIFT U(4)
  309. #define ID_AA64MMFR2_EL1_UAO_MASK ULL(0xf)
  310. #define ID_AA64MMFR2_EL1_CNP_SHIFT U(0)
  311. #define ID_AA64MMFR2_EL1_CNP_MASK ULL(0xf)
  312. #define ID_AA64MMFR2_EL1_NV_SHIFT U(24)
  313. #define ID_AA64MMFR2_EL1_NV_MASK ULL(0xf)
  314. #define NV2_IMPLEMENTED ULL(0x2)
  315. /* ID_AA64MMFR3_EL1 definitions */
  316. #define ID_AA64MMFR3_EL1 S3_0_C0_C7_3
  317. #define ID_AA64MMFR3_EL1_S2POE_SHIFT U(20)
  318. #define ID_AA64MMFR3_EL1_S2POE_MASK ULL(0xf)
  319. #define ID_AA64MMFR3_EL1_S1POE_SHIFT U(16)
  320. #define ID_AA64MMFR3_EL1_S1POE_MASK ULL(0xf)
  321. #define ID_AA64MMFR3_EL1_S2PIE_SHIFT U(12)
  322. #define ID_AA64MMFR3_EL1_S2PIE_MASK ULL(0xf)
  323. #define ID_AA64MMFR3_EL1_S1PIE_SHIFT U(8)
  324. #define ID_AA64MMFR3_EL1_S1PIE_MASK ULL(0xf)
  325. #define ID_AA64MMFR3_EL1_TCRX_SHIFT U(0)
  326. #define ID_AA64MMFR3_EL1_TCRX_MASK ULL(0xf)
  327. /* ID_AA64PFR1_EL1 definitions */
  328. #define ID_AA64PFR1_EL1_BT_SHIFT U(0)
  329. #define ID_AA64PFR1_EL1_BT_MASK ULL(0xf)
  330. #define BTI_IMPLEMENTED ULL(1) /* The BTI mechanism is implemented */
  331. #define ID_AA64PFR1_EL1_SSBS_SHIFT U(4)
  332. #define ID_AA64PFR1_EL1_SSBS_MASK ULL(0xf)
  333. #define SSBS_NOT_IMPLEMENTED ULL(0) /* No architectural SSBS support */
  334. #define ID_AA64PFR1_EL1_MTE_SHIFT U(8)
  335. #define ID_AA64PFR1_EL1_MTE_MASK ULL(0xf)
  336. #define ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT U(28)
  337. #define ID_AA64PFR1_EL1_RNDR_TRAP_MASK U(0xf)
  338. #define ID_AA64PFR1_EL1_NMI_SHIFT U(36)
  339. #define ID_AA64PFR1_EL1_NMI_MASK ULL(0xf)
  340. #define NMI_IMPLEMENTED ULL(1)
  341. #define ID_AA64PFR1_EL1_GCS_SHIFT U(44)
  342. #define ID_AA64PFR1_EL1_GCS_MASK ULL(0xf)
  343. #define GCS_IMPLEMENTED ULL(1)
  344. #define RNG_TRAP_IMPLEMENTED ULL(0x1)
  345. /* ID_AA64PFR2_EL1 definitions */
  346. #define ID_AA64PFR2_EL1_MTEPERM_SHIFT U(0)
  347. #define ID_AA64PFR2_EL1_MTEPERM_MASK ULL(0xf)
  348. #define ID_AA64PFR2_EL1_MTESTOREONLY_SHIFT U(4)
  349. #define ID_AA64PFR2_EL1_MTESTOREONLY_MASK ULL(0xf)
  350. #define ID_AA64PFR2_EL1_MTEFAR_SHIFT U(8)
  351. #define ID_AA64PFR2_EL1_MTEFAR_MASK ULL(0xf)
  352. #define VDISR_EL2 S3_4_C12_C1_1
  353. #define VSESR_EL2 S3_4_C5_C2_3
  354. /* Memory Tagging Extension is not implemented */
  355. #define MTE_UNIMPLEMENTED U(0)
  356. /* FEAT_MTE: MTE instructions accessible at EL0 are implemented */
  357. #define MTE_IMPLEMENTED_EL0 U(1)
  358. /* FEAT_MTE2: Full MTE is implemented */
  359. #define MTE_IMPLEMENTED_ELX U(2)
  360. /*
  361. * FEAT_MTE3: MTE is implemented with support for
  362. * asymmetric Tag Check Fault handling
  363. */
  364. #define MTE_IMPLEMENTED_ASY U(3)
  365. #define ID_AA64PFR1_MPAM_FRAC_SHIFT ULL(16)
  366. #define ID_AA64PFR1_MPAM_FRAC_MASK ULL(0xf)
  367. #define ID_AA64PFR1_EL1_SME_SHIFT U(24)
  368. #define ID_AA64PFR1_EL1_SME_MASK ULL(0xf)
  369. #define ID_AA64PFR1_EL1_SME_WIDTH U(4)
  370. #define SME_IMPLEMENTED ULL(0x1)
  371. #define SME2_IMPLEMENTED ULL(0x2)
  372. #define SME_NOT_IMPLEMENTED ULL(0x0)
  373. /* ID_PFR1_EL1 definitions */
  374. #define ID_PFR1_VIRTEXT_SHIFT U(12)
  375. #define ID_PFR1_VIRTEXT_MASK U(0xf)
  376. #define GET_VIRT_EXT(id) (((id) >> ID_PFR1_VIRTEXT_SHIFT) \
  377. & ID_PFR1_VIRTEXT_MASK)
  378. /* SCTLR definitions */
  379. #define SCTLR_EL2_RES1 ((U(1) << 29) | (U(1) << 28) | (U(1) << 23) | \
  380. (U(1) << 22) | (U(1) << 18) | (U(1) << 16) | \
  381. (U(1) << 11) | (U(1) << 5) | (U(1) << 4))
  382. #define SCTLR_EL1_RES1 ((UL(1) << 29) | (UL(1) << 28) | (UL(1) << 23) | \
  383. (UL(1) << 22) | (UL(1) << 20) | (UL(1) << 11))
  384. #define SCTLR_AARCH32_EL1_RES1 \
  385. ((U(1) << 23) | (U(1) << 22) | (U(1) << 11) | \
  386. (U(1) << 4) | (U(1) << 3))
  387. #define SCTLR_EL3_RES1 ((U(1) << 29) | (U(1) << 28) | (U(1) << 23) | \
  388. (U(1) << 22) | (U(1) << 18) | (U(1) << 16) | \
  389. (U(1) << 11) | (U(1) << 5) | (U(1) << 4))
  390. #define SCTLR_M_BIT (ULL(1) << 0)
  391. #define SCTLR_A_BIT (ULL(1) << 1)
  392. #define SCTLR_C_BIT (ULL(1) << 2)
  393. #define SCTLR_SA_BIT (ULL(1) << 3)
  394. #define SCTLR_SA0_BIT (ULL(1) << 4)
  395. #define SCTLR_CP15BEN_BIT (ULL(1) << 5)
  396. #define SCTLR_nAA_BIT (ULL(1) << 6)
  397. #define SCTLR_ITD_BIT (ULL(1) << 7)
  398. #define SCTLR_SED_BIT (ULL(1) << 8)
  399. #define SCTLR_UMA_BIT (ULL(1) << 9)
  400. #define SCTLR_EnRCTX_BIT (ULL(1) << 10)
  401. #define SCTLR_EOS_BIT (ULL(1) << 11)
  402. #define SCTLR_I_BIT (ULL(1) << 12)
  403. #define SCTLR_EnDB_BIT (ULL(1) << 13)
  404. #define SCTLR_DZE_BIT (ULL(1) << 14)
  405. #define SCTLR_UCT_BIT (ULL(1) << 15)
  406. #define SCTLR_NTWI_BIT (ULL(1) << 16)
  407. #define SCTLR_NTWE_BIT (ULL(1) << 18)
  408. #define SCTLR_WXN_BIT (ULL(1) << 19)
  409. #define SCTLR_TSCXT_BIT (ULL(1) << 20)
  410. #define SCTLR_IESB_BIT (ULL(1) << 21)
  411. #define SCTLR_EIS_BIT (ULL(1) << 22)
  412. #define SCTLR_SPAN_BIT (ULL(1) << 23)
  413. #define SCTLR_E0E_BIT (ULL(1) << 24)
  414. #define SCTLR_EE_BIT (ULL(1) << 25)
  415. #define SCTLR_UCI_BIT (ULL(1) << 26)
  416. #define SCTLR_EnDA_BIT (ULL(1) << 27)
  417. #define SCTLR_nTLSMD_BIT (ULL(1) << 28)
  418. #define SCTLR_LSMAOE_BIT (ULL(1) << 29)
  419. #define SCTLR_EnIB_BIT (ULL(1) << 30)
  420. #define SCTLR_EnIA_BIT (ULL(1) << 31)
  421. #define SCTLR_BT0_BIT (ULL(1) << 35)
  422. #define SCTLR_BT1_BIT (ULL(1) << 36)
  423. #define SCTLR_BT_BIT (ULL(1) << 36)
  424. #define SCTLR_ITFSB_BIT (ULL(1) << 37)
  425. #define SCTLR_TCF0_SHIFT U(38)
  426. #define SCTLR_TCF0_MASK ULL(3)
  427. #define SCTLR_ENTP2_BIT (ULL(1) << 60)
  428. #define SCTLR_SPINTMASK_BIT (ULL(1) << 62)
  429. /* Tag Check Faults in EL0 have no effect on the PE */
  430. #define SCTLR_TCF0_NO_EFFECT U(0)
  431. /* Tag Check Faults in EL0 cause a synchronous exception */
  432. #define SCTLR_TCF0_SYNC U(1)
  433. /* Tag Check Faults in EL0 are asynchronously accumulated */
  434. #define SCTLR_TCF0_ASYNC U(2)
  435. /*
  436. * Tag Check Faults in EL0 cause a synchronous exception on reads,
  437. * and are asynchronously accumulated on writes
  438. */
  439. #define SCTLR_TCF0_SYNCR_ASYNCW U(3)
  440. #define SCTLR_TCF_SHIFT U(40)
  441. #define SCTLR_TCF_MASK ULL(3)
  442. /* Tag Check Faults in EL1 have no effect on the PE */
  443. #define SCTLR_TCF_NO_EFFECT U(0)
  444. /* Tag Check Faults in EL1 cause a synchronous exception */
  445. #define SCTLR_TCF_SYNC U(1)
  446. /* Tag Check Faults in EL1 are asynchronously accumulated */
  447. #define SCTLR_TCF_ASYNC U(2)
  448. /*
  449. * Tag Check Faults in EL1 cause a synchronous exception on reads,
  450. * and are asynchronously accumulated on writes
  451. */
  452. #define SCTLR_TCF_SYNCR_ASYNCW U(3)
  453. #define SCTLR_ATA0_BIT (ULL(1) << 42)
  454. #define SCTLR_ATA_BIT (ULL(1) << 43)
  455. #define SCTLR_DSSBS_SHIFT U(44)
  456. #define SCTLR_DSSBS_BIT (ULL(1) << SCTLR_DSSBS_SHIFT)
  457. #define SCTLR_TWEDEn_BIT (ULL(1) << 45)
  458. #define SCTLR_TWEDEL_SHIFT U(46)
  459. #define SCTLR_TWEDEL_MASK ULL(0xf)
  460. #define SCTLR_EnASR_BIT (ULL(1) << 54)
  461. #define SCTLR_EnAS0_BIT (ULL(1) << 55)
  462. #define SCTLR_EnALS_BIT (ULL(1) << 56)
  463. #define SCTLR_EPAN_BIT (ULL(1) << 57)
  464. #define SCTLR_RESET_VAL SCTLR_EL3_RES1
  465. /* CPACR_EL1 definitions */
  466. #define CPACR_EL1_FPEN(x) ((x) << 20)
  467. #define CPACR_EL1_FP_TRAP_EL0 UL(0x1)
  468. #define CPACR_EL1_FP_TRAP_ALL UL(0x2)
  469. #define CPACR_EL1_FP_TRAP_NONE UL(0x3)
  470. #define CPACR_EL1_SMEN_SHIFT U(24)
  471. #define CPACR_EL1_SMEN_MASK ULL(0x3)
  472. /* SCR definitions */
  473. #define SCR_RES1_BITS ((U(1) << 4) | (U(1) << 5))
  474. #define SCR_NSE_SHIFT U(62)
  475. #define SCR_NSE_BIT (ULL(1) << SCR_NSE_SHIFT)
  476. #define SCR_GPF_BIT (UL(1) << 48)
  477. #define SCR_TWEDEL_SHIFT U(30)
  478. #define SCR_TWEDEL_MASK ULL(0xf)
  479. #define SCR_PIEN_BIT (UL(1) << 45)
  480. #define SCR_TCR2EN_BIT (UL(1) << 43)
  481. #define SCR_TRNDR_BIT (UL(1) << 40)
  482. #define SCR_GCSEn_BIT (UL(1) << 39)
  483. #define SCR_HXEn_BIT (UL(1) << 38)
  484. #define SCR_ENTP2_SHIFT U(41)
  485. #define SCR_ENTP2_BIT (UL(1) << SCR_ENTP2_SHIFT)
  486. #define SCR_AMVOFFEN_SHIFT U(35)
  487. #define SCR_AMVOFFEN_BIT (UL(1) << SCR_AMVOFFEN_SHIFT)
  488. #define SCR_TWEDEn_BIT (UL(1) << 29)
  489. #define SCR_ECVEN_BIT (UL(1) << 28)
  490. #define SCR_FGTEN_BIT (UL(1) << 27)
  491. #define SCR_ATA_BIT (UL(1) << 26)
  492. #define SCR_EnSCXT_BIT (UL(1) << 25)
  493. #define SCR_FIEN_BIT (UL(1) << 21)
  494. #define SCR_EEL2_BIT (UL(1) << 18)
  495. #define SCR_API_BIT (UL(1) << 17)
  496. #define SCR_APK_BIT (UL(1) << 16)
  497. #define SCR_TERR_BIT (UL(1) << 15)
  498. #define SCR_TWE_BIT (UL(1) << 13)
  499. #define SCR_TWI_BIT (UL(1) << 12)
  500. #define SCR_ST_BIT (UL(1) << 11)
  501. #define SCR_RW_BIT (UL(1) << 10)
  502. #define SCR_SIF_BIT (UL(1) << 9)
  503. #define SCR_HCE_BIT (UL(1) << 8)
  504. #define SCR_SMD_BIT (UL(1) << 7)
  505. #define SCR_EA_BIT (UL(1) << 3)
  506. #define SCR_FIQ_BIT (UL(1) << 2)
  507. #define SCR_IRQ_BIT (UL(1) << 1)
  508. #define SCR_NS_BIT (UL(1) << 0)
  509. #define SCR_VALID_BIT_MASK U(0x24000002F8F)
  510. #define SCR_RESET_VAL SCR_RES1_BITS
  511. /* MDCR_EL3 definitions */
  512. #define MDCR_EnPMSN_BIT (ULL(1) << 36)
  513. #define MDCR_MPMX_BIT (ULL(1) << 35)
  514. #define MDCR_MCCD_BIT (ULL(1) << 34)
  515. #define MDCR_SBRBE_SHIFT U(32)
  516. #define MDCR_SBRBE_MASK ULL(0x3)
  517. #define MDCR_NSTB(x) ((x) << 24)
  518. #define MDCR_NSTB_EL1 ULL(0x3)
  519. #define MDCR_NSTBE_BIT (ULL(1) << 26)
  520. #define MDCR_MTPME_BIT (ULL(1) << 28)
  521. #define MDCR_TDCC_BIT (ULL(1) << 27)
  522. #define MDCR_SCCD_BIT (ULL(1) << 23)
  523. #define MDCR_EPMAD_BIT (ULL(1) << 21)
  524. #define MDCR_EDAD_BIT (ULL(1) << 20)
  525. #define MDCR_TTRF_BIT (ULL(1) << 19)
  526. #define MDCR_STE_BIT (ULL(1) << 18)
  527. #define MDCR_SPME_BIT (ULL(1) << 17)
  528. #define MDCR_SDD_BIT (ULL(1) << 16)
  529. #define MDCR_SPD32(x) ((x) << 14)
  530. #define MDCR_SPD32_LEGACY ULL(0x0)
  531. #define MDCR_SPD32_DISABLE ULL(0x2)
  532. #define MDCR_SPD32_ENABLE ULL(0x3)
  533. #define MDCR_NSPB(x) ((x) << 12)
  534. #define MDCR_NSPB_EL1 ULL(0x3)
  535. #define MDCR_NSPBE_BIT (ULL(1) << 11)
  536. #define MDCR_TDOSA_BIT (ULL(1) << 10)
  537. #define MDCR_TDA_BIT (ULL(1) << 9)
  538. #define MDCR_TPM_BIT (ULL(1) << 6)
  539. #define MDCR_EL3_RESET_VAL MDCR_MTPME_BIT
  540. /* MDCR_EL2 definitions */
  541. #define MDCR_EL2_MTPME (U(1) << 28)
  542. #define MDCR_EL2_HLP_BIT (U(1) << 26)
  543. #define MDCR_EL2_E2TB(x) ((x) << 24)
  544. #define MDCR_EL2_E2TB_EL1 U(0x3)
  545. #define MDCR_EL2_HCCD_BIT (U(1) << 23)
  546. #define MDCR_EL2_TTRF (U(1) << 19)
  547. #define MDCR_EL2_HPMD_BIT (U(1) << 17)
  548. #define MDCR_EL2_TPMS (U(1) << 14)
  549. #define MDCR_EL2_E2PB(x) ((x) << 12)
  550. #define MDCR_EL2_E2PB_EL1 U(0x3)
  551. #define MDCR_EL2_TDRA_BIT (U(1) << 11)
  552. #define MDCR_EL2_TDOSA_BIT (U(1) << 10)
  553. #define MDCR_EL2_TDA_BIT (U(1) << 9)
  554. #define MDCR_EL2_TDE_BIT (U(1) << 8)
  555. #define MDCR_EL2_HPME_BIT (U(1) << 7)
  556. #define MDCR_EL2_TPM_BIT (U(1) << 6)
  557. #define MDCR_EL2_TPMCR_BIT (U(1) << 5)
  558. #define MDCR_EL2_HPMN_MASK U(0x1f)
  559. #define MDCR_EL2_RESET_VAL U(0x0)
  560. /* HSTR_EL2 definitions */
  561. #define HSTR_EL2_RESET_VAL U(0x0)
  562. #define HSTR_EL2_T_MASK U(0xff)
  563. /* CNTHP_CTL_EL2 definitions */
  564. #define CNTHP_CTL_ENABLE_BIT (U(1) << 0)
  565. #define CNTHP_CTL_RESET_VAL U(0x0)
  566. /* VTTBR_EL2 definitions */
  567. #define VTTBR_RESET_VAL ULL(0x0)
  568. #define VTTBR_VMID_MASK ULL(0xff)
  569. #define VTTBR_VMID_SHIFT U(48)
  570. #define VTTBR_BADDR_MASK ULL(0xffffffffffff)
  571. #define VTTBR_BADDR_SHIFT U(0)
  572. /* HCR definitions */
  573. #define HCR_RESET_VAL ULL(0x0)
  574. #define HCR_AMVOFFEN_SHIFT U(51)
  575. #define HCR_AMVOFFEN_BIT (ULL(1) << HCR_AMVOFFEN_SHIFT)
  576. #define HCR_TEA_BIT (ULL(1) << 47)
  577. #define HCR_API_BIT (ULL(1) << 41)
  578. #define HCR_APK_BIT (ULL(1) << 40)
  579. #define HCR_E2H_BIT (ULL(1) << 34)
  580. #define HCR_HCD_BIT (ULL(1) << 29)
  581. #define HCR_TGE_BIT (ULL(1) << 27)
  582. #define HCR_RW_SHIFT U(31)
  583. #define HCR_RW_BIT (ULL(1) << HCR_RW_SHIFT)
  584. #define HCR_TWE_BIT (ULL(1) << 14)
  585. #define HCR_TWI_BIT (ULL(1) << 13)
  586. #define HCR_AMO_BIT (ULL(1) << 5)
  587. #define HCR_IMO_BIT (ULL(1) << 4)
  588. #define HCR_FMO_BIT (ULL(1) << 3)
  589. /* ISR definitions */
  590. #define ISR_A_SHIFT U(8)
  591. #define ISR_I_SHIFT U(7)
  592. #define ISR_F_SHIFT U(6)
  593. /* CNTHCTL_EL2 definitions */
  594. #define CNTHCTL_RESET_VAL U(0x0)
  595. #define EVNTEN_BIT (U(1) << 2)
  596. #define EL1PCEN_BIT (U(1) << 1)
  597. #define EL1PCTEN_BIT (U(1) << 0)
  598. /* CNTKCTL_EL1 definitions */
  599. #define EL0PTEN_BIT (U(1) << 9)
  600. #define EL0VTEN_BIT (U(1) << 8)
  601. #define EL0PCTEN_BIT (U(1) << 0)
  602. #define EL0VCTEN_BIT (U(1) << 1)
  603. #define EVNTEN_BIT (U(1) << 2)
  604. #define EVNTDIR_BIT (U(1) << 3)
  605. #define EVNTI_SHIFT U(4)
  606. #define EVNTI_MASK U(0xf)
  607. /* CPTR_EL3 definitions */
  608. #define TCPAC_BIT (U(1) << 31)
  609. #define TAM_SHIFT U(30)
  610. #define TAM_BIT (U(1) << TAM_SHIFT)
  611. #define TTA_BIT (U(1) << 20)
  612. #define ESM_BIT (U(1) << 12)
  613. #define TFP_BIT (U(1) << 10)
  614. #define CPTR_EZ_BIT (U(1) << 8)
  615. #define CPTR_EL3_RESET_VAL ((TCPAC_BIT | TAM_BIT | TTA_BIT | TFP_BIT) & \
  616. ~(CPTR_EZ_BIT | ESM_BIT))
  617. /* CPTR_EL2 definitions */
  618. #define CPTR_EL2_RES1 ((U(1) << 13) | (U(1) << 12) | (U(0x3ff)))
  619. #define CPTR_EL2_TCPAC_BIT (U(1) << 31)
  620. #define CPTR_EL2_TAM_SHIFT U(30)
  621. #define CPTR_EL2_TAM_BIT (U(1) << CPTR_EL2_TAM_SHIFT)
  622. #define CPTR_EL2_SMEN_MASK ULL(0x3)
  623. #define CPTR_EL2_SMEN_SHIFT U(24)
  624. #define CPTR_EL2_TTA_BIT (U(1) << 20)
  625. #define CPTR_EL2_TSM_BIT (U(1) << 12)
  626. #define CPTR_EL2_TFP_BIT (U(1) << 10)
  627. #define CPTR_EL2_TZ_BIT (U(1) << 8)
  628. #define CPTR_EL2_RESET_VAL CPTR_EL2_RES1
  629. /* VTCR_EL2 definitions */
  630. #define VTCR_RESET_VAL U(0x0)
  631. #define VTCR_EL2_MSA (U(1) << 31)
  632. /* CPSR/SPSR definitions */
  633. #define DAIF_FIQ_BIT (U(1) << 0)
  634. #define DAIF_IRQ_BIT (U(1) << 1)
  635. #define DAIF_ABT_BIT (U(1) << 2)
  636. #define DAIF_DBG_BIT (U(1) << 3)
  637. #define SPSR_V_BIT (U(1) << 28)
  638. #define SPSR_C_BIT (U(1) << 29)
  639. #define SPSR_Z_BIT (U(1) << 30)
  640. #define SPSR_N_BIT (U(1) << 31)
  641. #define SPSR_DAIF_SHIFT U(6)
  642. #define SPSR_DAIF_MASK U(0xf)
  643. #define SPSR_AIF_SHIFT U(6)
  644. #define SPSR_AIF_MASK U(0x7)
  645. #define SPSR_E_SHIFT U(9)
  646. #define SPSR_E_MASK U(0x1)
  647. #define SPSR_E_LITTLE U(0x0)
  648. #define SPSR_E_BIG U(0x1)
  649. #define SPSR_T_SHIFT U(5)
  650. #define SPSR_T_MASK U(0x1)
  651. #define SPSR_T_ARM U(0x0)
  652. #define SPSR_T_THUMB U(0x1)
  653. #define SPSR_M_SHIFT U(4)
  654. #define SPSR_M_MASK U(0x1)
  655. #define SPSR_M_AARCH64 U(0x0)
  656. #define SPSR_M_AARCH32 U(0x1)
  657. #define SPSR_M_EL1H U(0x5)
  658. #define SPSR_M_EL2H U(0x9)
  659. #define SPSR_EL_SHIFT U(2)
  660. #define SPSR_EL_WIDTH U(2)
  661. #define SPSR_BTYPE_SHIFT_AARCH64 U(10)
  662. #define SPSR_BTYPE_MASK_AARCH64 U(0x3)
  663. #define SPSR_SSBS_SHIFT_AARCH64 U(12)
  664. #define SPSR_SSBS_BIT_AARCH64 (ULL(1) << SPSR_SSBS_SHIFT_AARCH64)
  665. #define SPSR_SSBS_SHIFT_AARCH32 U(23)
  666. #define SPSR_SSBS_BIT_AARCH32 (ULL(1) << SPSR_SSBS_SHIFT_AARCH32)
  667. #define SPSR_ALLINT_BIT_AARCH64 BIT_64(13)
  668. #define SPSR_IL_BIT BIT_64(20)
  669. #define SPSR_SS_BIT BIT_64(21)
  670. #define SPSR_PAN_BIT BIT_64(22)
  671. #define SPSR_UAO_BIT_AARCH64 BIT_64(23)
  672. #define SPSR_DIT_BIT BIT(24)
  673. #define SPSR_TCO_BIT_AARCH64 BIT_64(25)
  674. #define SPSR_PM_BIT_AARCH64 BIT_64(32)
  675. #define SPSR_PPEND_BIT BIT(33)
  676. #define SPSR_EXLOCK_BIT_AARCH64 BIT_64(34)
  677. #define SPSR_NZCV (SPSR_V_BIT | SPSR_C_BIT | SPSR_Z_BIT | SPSR_N_BIT)
  678. #define DISABLE_ALL_EXCEPTIONS \
  679. (DAIF_FIQ_BIT | DAIF_IRQ_BIT | DAIF_ABT_BIT | DAIF_DBG_BIT)
  680. #define DISABLE_INTERRUPTS (DAIF_FIQ_BIT | DAIF_IRQ_BIT)
  681. /*
  682. * RMR_EL3 definitions
  683. */
  684. #define RMR_EL3_RR_BIT (U(1) << 1)
  685. #define RMR_EL3_AA64_BIT (U(1) << 0)
  686. /*
  687. * HI-VECTOR address for AArch32 state
  688. */
  689. #define HI_VECTOR_BASE U(0xFFFF0000)
  690. /*
  691. * TCR definitions
  692. */
  693. #define TCR_EL3_RES1 ((ULL(1) << 31) | (ULL(1) << 23))
  694. #define TCR_EL2_RES1 ((ULL(1) << 31) | (ULL(1) << 23))
  695. #define TCR_EL1_IPS_SHIFT U(32)
  696. #define TCR_EL2_PS_SHIFT U(16)
  697. #define TCR_EL3_PS_SHIFT U(16)
  698. #define TCR_TxSZ_MIN ULL(16)
  699. #define TCR_TxSZ_MAX ULL(39)
  700. #define TCR_TxSZ_MAX_TTST ULL(48)
  701. #define TCR_T0SZ_SHIFT U(0)
  702. #define TCR_T1SZ_SHIFT U(16)
  703. /* (internal) physical address size bits in EL3/EL1 */
  704. #define TCR_PS_BITS_4GB ULL(0x0)
  705. #define TCR_PS_BITS_64GB ULL(0x1)
  706. #define TCR_PS_BITS_1TB ULL(0x2)
  707. #define TCR_PS_BITS_4TB ULL(0x3)
  708. #define TCR_PS_BITS_16TB ULL(0x4)
  709. #define TCR_PS_BITS_256TB ULL(0x5)
  710. #define ADDR_MASK_48_TO_63 ULL(0xFFFF000000000000)
  711. #define ADDR_MASK_44_TO_47 ULL(0x0000F00000000000)
  712. #define ADDR_MASK_42_TO_43 ULL(0x00000C0000000000)
  713. #define ADDR_MASK_40_TO_41 ULL(0x0000030000000000)
  714. #define ADDR_MASK_36_TO_39 ULL(0x000000F000000000)
  715. #define ADDR_MASK_32_TO_35 ULL(0x0000000F00000000)
  716. #define TCR_RGN_INNER_NC (ULL(0x0) << 8)
  717. #define TCR_RGN_INNER_WBA (ULL(0x1) << 8)
  718. #define TCR_RGN_INNER_WT (ULL(0x2) << 8)
  719. #define TCR_RGN_INNER_WBNA (ULL(0x3) << 8)
  720. #define TCR_RGN_OUTER_NC (ULL(0x0) << 10)
  721. #define TCR_RGN_OUTER_WBA (ULL(0x1) << 10)
  722. #define TCR_RGN_OUTER_WT (ULL(0x2) << 10)
  723. #define TCR_RGN_OUTER_WBNA (ULL(0x3) << 10)
  724. #define TCR_SH_NON_SHAREABLE (ULL(0x0) << 12)
  725. #define TCR_SH_OUTER_SHAREABLE (ULL(0x2) << 12)
  726. #define TCR_SH_INNER_SHAREABLE (ULL(0x3) << 12)
  727. #define TCR_RGN1_INNER_NC (ULL(0x0) << 24)
  728. #define TCR_RGN1_INNER_WBA (ULL(0x1) << 24)
  729. #define TCR_RGN1_INNER_WT (ULL(0x2) << 24)
  730. #define TCR_RGN1_INNER_WBNA (ULL(0x3) << 24)
  731. #define TCR_RGN1_OUTER_NC (ULL(0x0) << 26)
  732. #define TCR_RGN1_OUTER_WBA (ULL(0x1) << 26)
  733. #define TCR_RGN1_OUTER_WT (ULL(0x2) << 26)
  734. #define TCR_RGN1_OUTER_WBNA (ULL(0x3) << 26)
  735. #define TCR_SH1_NON_SHAREABLE (ULL(0x0) << 28)
  736. #define TCR_SH1_OUTER_SHAREABLE (ULL(0x2) << 28)
  737. #define TCR_SH1_INNER_SHAREABLE (ULL(0x3) << 28)
  738. #define TCR_TG0_SHIFT U(14)
  739. #define TCR_TG0_MASK ULL(3)
  740. #define TCR_TG0_4K (ULL(0) << TCR_TG0_SHIFT)
  741. #define TCR_TG0_64K (ULL(1) << TCR_TG0_SHIFT)
  742. #define TCR_TG0_16K (ULL(2) << TCR_TG0_SHIFT)
  743. #define TCR_TG1_SHIFT U(30)
  744. #define TCR_TG1_MASK ULL(3)
  745. #define TCR_TG1_16K (ULL(1) << TCR_TG1_SHIFT)
  746. #define TCR_TG1_4K (ULL(2) << TCR_TG1_SHIFT)
  747. #define TCR_TG1_64K (ULL(3) << TCR_TG1_SHIFT)
  748. #define TCR_EPD0_BIT (ULL(1) << 7)
  749. #define TCR_EPD1_BIT (ULL(1) << 23)
  750. #define MODE_SP_SHIFT U(0x0)
  751. #define MODE_SP_MASK U(0x1)
  752. #define MODE_SP_EL0 U(0x0)
  753. #define MODE_SP_ELX U(0x1)
  754. #define MODE_RW_SHIFT U(0x4)
  755. #define MODE_RW_MASK U(0x1)
  756. #define MODE_RW_64 U(0x0)
  757. #define MODE_RW_32 U(0x1)
  758. #define MODE_EL_SHIFT U(0x2)
  759. #define MODE_EL_MASK U(0x3)
  760. #define MODE_EL_WIDTH U(0x2)
  761. #define MODE_EL3 U(0x3)
  762. #define MODE_EL2 U(0x2)
  763. #define MODE_EL1 U(0x1)
  764. #define MODE_EL0 U(0x0)
  765. #define MODE32_SHIFT U(0)
  766. #define MODE32_MASK U(0xf)
  767. #define MODE32_usr U(0x0)
  768. #define MODE32_fiq U(0x1)
  769. #define MODE32_irq U(0x2)
  770. #define MODE32_svc U(0x3)
  771. #define MODE32_mon U(0x6)
  772. #define MODE32_abt U(0x7)
  773. #define MODE32_hyp U(0xa)
  774. #define MODE32_und U(0xb)
  775. #define MODE32_sys U(0xf)
  776. #define GET_RW(mode) (((mode) >> MODE_RW_SHIFT) & MODE_RW_MASK)
  777. #define GET_EL(mode) (((mode) >> MODE_EL_SHIFT) & MODE_EL_MASK)
  778. #define GET_SP(mode) (((mode) >> MODE_SP_SHIFT) & MODE_SP_MASK)
  779. #define GET_M32(mode) (((mode) >> MODE32_SHIFT) & MODE32_MASK)
  780. #define SPSR_64(el, sp, daif) \
  781. (((MODE_RW_64 << MODE_RW_SHIFT) | \
  782. (((el) & MODE_EL_MASK) << MODE_EL_SHIFT) | \
  783. (((sp) & MODE_SP_MASK) << MODE_SP_SHIFT) | \
  784. (((daif) & SPSR_DAIF_MASK) << SPSR_DAIF_SHIFT)) & \
  785. (~(SPSR_SSBS_BIT_AARCH64)))
  786. #define SPSR_MODE32(mode, isa, endian, aif) \
  787. (((MODE_RW_32 << MODE_RW_SHIFT) | \
  788. (((mode) & MODE32_MASK) << MODE32_SHIFT) | \
  789. (((isa) & SPSR_T_MASK) << SPSR_T_SHIFT) | \
  790. (((endian) & SPSR_E_MASK) << SPSR_E_SHIFT) | \
  791. (((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT)) & \
  792. (~(SPSR_SSBS_BIT_AARCH32)))
  793. /*
  794. * TTBR Definitions
  795. */
  796. #define TTBR_CNP_BIT ULL(0x1)
  797. /*
  798. * CTR_EL0 definitions
  799. */
  800. #define CTR_CWG_SHIFT U(24)
  801. #define CTR_CWG_MASK U(0xf)
  802. #define CTR_ERG_SHIFT U(20)
  803. #define CTR_ERG_MASK U(0xf)
  804. #define CTR_DMINLINE_SHIFT U(16)
  805. #define CTR_DMINLINE_MASK U(0xf)
  806. #define CTR_L1IP_SHIFT U(14)
  807. #define CTR_L1IP_MASK U(0x3)
  808. #define CTR_IMINLINE_SHIFT U(0)
  809. #define CTR_IMINLINE_MASK U(0xf)
  810. #define MAX_CACHE_LINE_SIZE U(0x800) /* 2KB */
  811. /* Physical timer control register bit fields shifts and masks */
  812. #define CNTP_CTL_ENABLE_SHIFT U(0)
  813. #define CNTP_CTL_IMASK_SHIFT U(1)
  814. #define CNTP_CTL_ISTATUS_SHIFT U(2)
  815. #define CNTP_CTL_ENABLE_MASK U(1)
  816. #define CNTP_CTL_IMASK_MASK U(1)
  817. #define CNTP_CTL_ISTATUS_MASK U(1)
  818. /* Physical timer control macros */
  819. #define CNTP_CTL_ENABLE_BIT (U(1) << CNTP_CTL_ENABLE_SHIFT)
  820. #define CNTP_CTL_IMASK_BIT (U(1) << CNTP_CTL_IMASK_SHIFT)
  821. /* Exception Syndrome register bits and bobs */
  822. #define ESR_EC_SHIFT U(26)
  823. #define ESR_EC_MASK U(0x3f)
  824. #define ESR_EC_LENGTH U(6)
  825. #define ESR_ISS_SHIFT U(0)
  826. #define ESR_ISS_LENGTH U(25)
  827. #define ESR_IL_BIT (U(1) << 25)
  828. #define EC_UNKNOWN U(0x0)
  829. #define EC_WFE_WFI U(0x1)
  830. #define EC_AARCH32_CP15_MRC_MCR U(0x3)
  831. #define EC_AARCH32_CP15_MRRC_MCRR U(0x4)
  832. #define EC_AARCH32_CP14_MRC_MCR U(0x5)
  833. #define EC_AARCH32_CP14_LDC_STC U(0x6)
  834. #define EC_FP_SIMD U(0x7)
  835. #define EC_AARCH32_CP10_MRC U(0x8)
  836. #define EC_AARCH32_CP14_MRRC_MCRR U(0xc)
  837. #define EC_ILLEGAL U(0xe)
  838. #define EC_AARCH32_SVC U(0x11)
  839. #define EC_AARCH32_HVC U(0x12)
  840. #define EC_AARCH32_SMC U(0x13)
  841. #define EC_AARCH64_SVC U(0x15)
  842. #define EC_AARCH64_HVC U(0x16)
  843. #define EC_AARCH64_SMC U(0x17)
  844. #define EC_AARCH64_SYS U(0x18)
  845. #define EC_IMP_DEF_EL3 U(0x1f)
  846. #define EC_IABORT_LOWER_EL U(0x20)
  847. #define EC_IABORT_CUR_EL U(0x21)
  848. #define EC_PC_ALIGN U(0x22)
  849. #define EC_DABORT_LOWER_EL U(0x24)
  850. #define EC_DABORT_CUR_EL U(0x25)
  851. #define EC_SP_ALIGN U(0x26)
  852. #define EC_AARCH32_FP U(0x28)
  853. #define EC_AARCH64_FP U(0x2c)
  854. #define EC_SERROR U(0x2f)
  855. #define EC_BRK U(0x3c)
  856. /*
  857. * External Abort bit in Instruction and Data Aborts synchronous exception
  858. * syndromes.
  859. */
  860. #define ESR_ISS_EABORT_EA_BIT U(9)
  861. #define EC_BITS(x) (((x) >> ESR_EC_SHIFT) & ESR_EC_MASK)
  862. /* Reset bit inside the Reset management register for EL3 (RMR_EL3) */
  863. #define RMR_RESET_REQUEST_SHIFT U(0x1)
  864. #define RMR_WARM_RESET_CPU (U(1) << RMR_RESET_REQUEST_SHIFT)
  865. /*******************************************************************************
  866. * Definitions of register offsets, fields and macros for CPU system
  867. * instructions.
  868. ******************************************************************************/
  869. #define TLBI_ADDR_SHIFT U(12)
  870. #define TLBI_ADDR_MASK ULL(0x00000FFFFFFFFFFF)
  871. #define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK)
  872. /*******************************************************************************
  873. * Definitions of register offsets and fields in the CNTCTLBase Frame of the
  874. * system level implementation of the Generic Timer.
  875. ******************************************************************************/
  876. #define CNTCTLBASE_CNTFRQ U(0x0)
  877. #define CNTNSAR U(0x4)
  878. #define CNTNSAR_NS_SHIFT(x) (x)
  879. #define CNTACR_BASE(x) (U(0x40) + ((x) << 2))
  880. #define CNTACR_RPCT_SHIFT U(0x0)
  881. #define CNTACR_RVCT_SHIFT U(0x1)
  882. #define CNTACR_RFRQ_SHIFT U(0x2)
  883. #define CNTACR_RVOFF_SHIFT U(0x3)
  884. #define CNTACR_RWVT_SHIFT U(0x4)
  885. #define CNTACR_RWPT_SHIFT U(0x5)
  886. /*******************************************************************************
  887. * Definitions of register offsets and fields in the CNTBaseN Frame of the
  888. * system level implementation of the Generic Timer.
  889. ******************************************************************************/
  890. /* Physical Count register. */
  891. #define CNTPCT_LO U(0x0)
  892. /* Counter Frequency register. */
  893. #define CNTBASEN_CNTFRQ U(0x10)
  894. /* Physical Timer CompareValue register. */
  895. #define CNTP_CVAL_LO U(0x20)
  896. /* Physical Timer Control register. */
  897. #define CNTP_CTL U(0x2c)
  898. /* PMCR_EL0 definitions */
  899. #define PMCR_EL0_RESET_VAL U(0x0)
  900. #define PMCR_EL0_N_SHIFT U(11)
  901. #define PMCR_EL0_N_MASK U(0x1f)
  902. #define PMCR_EL0_N_BITS (PMCR_EL0_N_MASK << PMCR_EL0_N_SHIFT)
  903. #define PMCR_EL0_LP_BIT (U(1) << 7)
  904. #define PMCR_EL0_LC_BIT (U(1) << 6)
  905. #define PMCR_EL0_DP_BIT (U(1) << 5)
  906. #define PMCR_EL0_X_BIT (U(1) << 4)
  907. #define PMCR_EL0_D_BIT (U(1) << 3)
  908. #define PMCR_EL0_C_BIT (U(1) << 2)
  909. #define PMCR_EL0_P_BIT (U(1) << 1)
  910. #define PMCR_EL0_E_BIT (U(1) << 0)
  911. /*******************************************************************************
  912. * Definitions for system register interface to SVE
  913. ******************************************************************************/
  914. #define ZCR_EL3 S3_6_C1_C2_0
  915. #define ZCR_EL2 S3_4_C1_C2_0
  916. /* ZCR_EL3 definitions */
  917. #define ZCR_EL3_LEN_MASK U(0xf)
  918. /* ZCR_EL2 definitions */
  919. #define ZCR_EL2_LEN_MASK U(0xf)
  920. /*******************************************************************************
  921. * Definitions for system register interface to SME as needed in EL3
  922. ******************************************************************************/
  923. #define ID_AA64SMFR0_EL1 S3_0_C0_C4_5
  924. #define SMCR_EL3 S3_6_C1_C2_6
  925. /* ID_AA64SMFR0_EL1 definitions */
  926. #define ID_AA64SMFR0_EL1_SME_FA64_SHIFT U(63)
  927. #define ID_AA64SMFR0_EL1_SME_FA64_MASK U(0x1)
  928. #define SME_FA64_IMPLEMENTED U(0x1)
  929. #define ID_AA64SMFR0_EL1_SME_VER_SHIFT U(55)
  930. #define ID_AA64SMFR0_EL1_SME_VER_MASK ULL(0xf)
  931. #define SME_INST_IMPLEMENTED ULL(0x0)
  932. #define SME2_INST_IMPLEMENTED ULL(0x1)
  933. /* SMCR_ELx definitions */
  934. #define SMCR_ELX_LEN_SHIFT U(0)
  935. #define SMCR_ELX_LEN_MAX U(0x1ff)
  936. #define SMCR_ELX_FA64_BIT (U(1) << 31)
  937. #define SMCR_ELX_EZT0_BIT (U(1) << 30)
  938. /*******************************************************************************
  939. * Definitions of MAIR encodings for device and normal memory
  940. ******************************************************************************/
  941. /*
  942. * MAIR encodings for device memory attributes.
  943. */
  944. #define MAIR_DEV_nGnRnE ULL(0x0)
  945. #define MAIR_DEV_nGnRE ULL(0x4)
  946. #define MAIR_DEV_nGRE ULL(0x8)
  947. #define MAIR_DEV_GRE ULL(0xc)
  948. /*
  949. * MAIR encodings for normal memory attributes.
  950. *
  951. * Cache Policy
  952. * WT: Write Through
  953. * WB: Write Back
  954. * NC: Non-Cacheable
  955. *
  956. * Transient Hint
  957. * NTR: Non-Transient
  958. * TR: Transient
  959. *
  960. * Allocation Policy
  961. * RA: Read Allocate
  962. * WA: Write Allocate
  963. * RWA: Read and Write Allocate
  964. * NA: No Allocation
  965. */
  966. #define MAIR_NORM_WT_TR_WA ULL(0x1)
  967. #define MAIR_NORM_WT_TR_RA ULL(0x2)
  968. #define MAIR_NORM_WT_TR_RWA ULL(0x3)
  969. #define MAIR_NORM_NC ULL(0x4)
  970. #define MAIR_NORM_WB_TR_WA ULL(0x5)
  971. #define MAIR_NORM_WB_TR_RA ULL(0x6)
  972. #define MAIR_NORM_WB_TR_RWA ULL(0x7)
  973. #define MAIR_NORM_WT_NTR_NA ULL(0x8)
  974. #define MAIR_NORM_WT_NTR_WA ULL(0x9)
  975. #define MAIR_NORM_WT_NTR_RA ULL(0xa)
  976. #define MAIR_NORM_WT_NTR_RWA ULL(0xb)
  977. #define MAIR_NORM_WB_NTR_NA ULL(0xc)
  978. #define MAIR_NORM_WB_NTR_WA ULL(0xd)
  979. #define MAIR_NORM_WB_NTR_RA ULL(0xe)
  980. #define MAIR_NORM_WB_NTR_RWA ULL(0xf)
  981. #define MAIR_NORM_OUTER_SHIFT U(4)
  982. #define MAKE_MAIR_NORMAL_MEMORY(inner, outer) \
  983. ((inner) | ((outer) << MAIR_NORM_OUTER_SHIFT))
  984. /* PAR_EL1 fields */
  985. #define PAR_F_SHIFT U(0)
  986. #define PAR_F_MASK ULL(0x1)
  987. #define PAR_ADDR_SHIFT U(12)
  988. #define PAR_ADDR_MASK (BIT(40) - ULL(1)) /* 40-bits-wide page address */
  989. /*******************************************************************************
  990. * Definitions for system register interface to SPE
  991. ******************************************************************************/
  992. #define PMBLIMITR_EL1 S3_0_C9_C10_0
  993. /*******************************************************************************
  994. * Definitions for system register interface, shifts and masks for MPAM
  995. ******************************************************************************/
  996. #define MPAMIDR_EL1 S3_0_C10_C4_4
  997. #define MPAM2_EL2 S3_4_C10_C5_0
  998. #define MPAMHCR_EL2 S3_4_C10_C4_0
  999. #define MPAM3_EL3 S3_6_C10_C5_0
  1000. #define MPAMIDR_EL1_VPMR_MAX_SHIFT ULL(18)
  1001. #define MPAMIDR_EL1_VPMR_MAX_MASK ULL(0x7)
  1002. /*******************************************************************************
  1003. * Definitions for system register interface to AMU for FEAT_AMUv1
  1004. ******************************************************************************/
  1005. #define AMCR_EL0 S3_3_C13_C2_0
  1006. #define AMCFGR_EL0 S3_3_C13_C2_1
  1007. #define AMCGCR_EL0 S3_3_C13_C2_2
  1008. #define AMUSERENR_EL0 S3_3_C13_C2_3
  1009. #define AMCNTENCLR0_EL0 S3_3_C13_C2_4
  1010. #define AMCNTENSET0_EL0 S3_3_C13_C2_5
  1011. #define AMCNTENCLR1_EL0 S3_3_C13_C3_0
  1012. #define AMCNTENSET1_EL0 S3_3_C13_C3_1
  1013. /* Activity Monitor Group 0 Event Counter Registers */
  1014. #define AMEVCNTR00_EL0 S3_3_C13_C4_0
  1015. #define AMEVCNTR01_EL0 S3_3_C13_C4_1
  1016. #define AMEVCNTR02_EL0 S3_3_C13_C4_2
  1017. #define AMEVCNTR03_EL0 S3_3_C13_C4_3
  1018. /* Activity Monitor Group 0 Event Type Registers */
  1019. #define AMEVTYPER00_EL0 S3_3_C13_C6_0
  1020. #define AMEVTYPER01_EL0 S3_3_C13_C6_1
  1021. #define AMEVTYPER02_EL0 S3_3_C13_C6_2
  1022. #define AMEVTYPER03_EL0 S3_3_C13_C6_3
  1023. /* Activity Monitor Group 1 Event Counter Registers */
  1024. #define AMEVCNTR10_EL0 S3_3_C13_C12_0
  1025. #define AMEVCNTR11_EL0 S3_3_C13_C12_1
  1026. #define AMEVCNTR12_EL0 S3_3_C13_C12_2
  1027. #define AMEVCNTR13_EL0 S3_3_C13_C12_3
  1028. #define AMEVCNTR14_EL0 S3_3_C13_C12_4
  1029. #define AMEVCNTR15_EL0 S3_3_C13_C12_5
  1030. #define AMEVCNTR16_EL0 S3_3_C13_C12_6
  1031. #define AMEVCNTR17_EL0 S3_3_C13_C12_7
  1032. #define AMEVCNTR18_EL0 S3_3_C13_C13_0
  1033. #define AMEVCNTR19_EL0 S3_3_C13_C13_1
  1034. #define AMEVCNTR1A_EL0 S3_3_C13_C13_2
  1035. #define AMEVCNTR1B_EL0 S3_3_C13_C13_3
  1036. #define AMEVCNTR1C_EL0 S3_3_C13_C13_4
  1037. #define AMEVCNTR1D_EL0 S3_3_C13_C13_5
  1038. #define AMEVCNTR1E_EL0 S3_3_C13_C13_6
  1039. #define AMEVCNTR1F_EL0 S3_3_C13_C13_7
  1040. /* Activity Monitor Group 1 Event Type Registers */
  1041. #define AMEVTYPER10_EL0 S3_3_C13_C14_0
  1042. #define AMEVTYPER11_EL0 S3_3_C13_C14_1
  1043. #define AMEVTYPER12_EL0 S3_3_C13_C14_2
  1044. #define AMEVTYPER13_EL0 S3_3_C13_C14_3
  1045. #define AMEVTYPER14_EL0 S3_3_C13_C14_4
  1046. #define AMEVTYPER15_EL0 S3_3_C13_C14_5
  1047. #define AMEVTYPER16_EL0 S3_3_C13_C14_6
  1048. #define AMEVTYPER17_EL0 S3_3_C13_C14_7
  1049. #define AMEVTYPER18_EL0 S3_3_C13_C15_0
  1050. #define AMEVTYPER19_EL0 S3_3_C13_C15_1
  1051. #define AMEVTYPER1A_EL0 S3_3_C13_C15_2
  1052. #define AMEVTYPER1B_EL0 S3_3_C13_C15_3
  1053. #define AMEVTYPER1C_EL0 S3_3_C13_C15_4
  1054. #define AMEVTYPER1D_EL0 S3_3_C13_C15_5
  1055. #define AMEVTYPER1E_EL0 S3_3_C13_C15_6
  1056. #define AMEVTYPER1F_EL0 S3_3_C13_C15_7
  1057. /* AMCNTENSET0_EL0 definitions */
  1058. #define AMCNTENSET0_EL0_Pn_SHIFT U(0)
  1059. #define AMCNTENSET0_EL0_Pn_MASK ULL(0xffff)
  1060. /* AMCNTENSET1_EL0 definitions */
  1061. #define AMCNTENSET1_EL0_Pn_SHIFT U(0)
  1062. #define AMCNTENSET1_EL0_Pn_MASK ULL(0xffff)
  1063. /* AMCNTENCLR0_EL0 definitions */
  1064. #define AMCNTENCLR0_EL0_Pn_SHIFT U(0)
  1065. #define AMCNTENCLR0_EL0_Pn_MASK ULL(0xffff)
  1066. /* AMCNTENCLR1_EL0 definitions */
  1067. #define AMCNTENCLR1_EL0_Pn_SHIFT U(0)
  1068. #define AMCNTENCLR1_EL0_Pn_MASK ULL(0xffff)
  1069. /* AMCFGR_EL0 definitions */
  1070. #define AMCFGR_EL0_NCG_SHIFT U(28)
  1071. #define AMCFGR_EL0_NCG_MASK U(0xf)
  1072. #define AMCFGR_EL0_N_SHIFT U(0)
  1073. #define AMCFGR_EL0_N_MASK U(0xff)
  1074. /* AMCGCR_EL0 definitions */
  1075. #define AMCGCR_EL0_CG0NC_SHIFT U(0)
  1076. #define AMCGCR_EL0_CG0NC_MASK U(0xff)
  1077. #define AMCGCR_EL0_CG1NC_SHIFT U(8)
  1078. #define AMCGCR_EL0_CG1NC_MASK U(0xff)
  1079. /* MPAM register definitions */
  1080. #define MPAM3_EL3_MPAMEN_BIT (ULL(1) << 63)
  1081. #define MPAM3_EL3_TRAPLOWER_BIT (ULL(1) << 62)
  1082. #define MPAMHCR_EL2_TRAP_MPAMIDR_EL1 (ULL(1) << 31)
  1083. #define MPAM3_EL3_RESET_VAL MPAM3_EL3_TRAPLOWER_BIT
  1084. #define MPAM2_EL2_TRAPMPAM0EL1 (ULL(1) << 49)
  1085. #define MPAM2_EL2_TRAPMPAM1EL1 (ULL(1) << 48)
  1086. #define MPAMIDR_HAS_HCR_BIT (ULL(1) << 17)
  1087. /*******************************************************************************
  1088. * Definitions for system register interface to AMU for FEAT_AMUv1p1
  1089. ******************************************************************************/
  1090. /* Definition for register defining which virtual offsets are implemented. */
  1091. #define AMCG1IDR_EL0 S3_3_C13_C2_6
  1092. #define AMCG1IDR_CTR_MASK ULL(0xffff)
  1093. #define AMCG1IDR_CTR_SHIFT U(0)
  1094. #define AMCG1IDR_VOFF_MASK ULL(0xffff)
  1095. #define AMCG1IDR_VOFF_SHIFT U(16)
  1096. /* New bit added to AMCR_EL0 */
  1097. #define AMCR_CG1RZ_SHIFT U(17)
  1098. #define AMCR_CG1RZ_BIT (ULL(0x1) << AMCR_CG1RZ_SHIFT)
  1099. /*
  1100. * Definitions for virtual offset registers for architected activity monitor
  1101. * event counters.
  1102. * AMEVCNTVOFF01_EL2 intentionally left undefined, as it does not exist.
  1103. */
  1104. #define AMEVCNTVOFF00_EL2 S3_4_C13_C8_0
  1105. #define AMEVCNTVOFF02_EL2 S3_4_C13_C8_2
  1106. #define AMEVCNTVOFF03_EL2 S3_4_C13_C8_3
  1107. /*
  1108. * Definitions for virtual offset registers for auxiliary activity monitor event
  1109. * counters.
  1110. */
  1111. #define AMEVCNTVOFF10_EL2 S3_4_C13_C10_0
  1112. #define AMEVCNTVOFF11_EL2 S3_4_C13_C10_1
  1113. #define AMEVCNTVOFF12_EL2 S3_4_C13_C10_2
  1114. #define AMEVCNTVOFF13_EL2 S3_4_C13_C10_3
  1115. #define AMEVCNTVOFF14_EL2 S3_4_C13_C10_4
  1116. #define AMEVCNTVOFF15_EL2 S3_4_C13_C10_5
  1117. #define AMEVCNTVOFF16_EL2 S3_4_C13_C10_6
  1118. #define AMEVCNTVOFF17_EL2 S3_4_C13_C10_7
  1119. #define AMEVCNTVOFF18_EL2 S3_4_C13_C11_0
  1120. #define AMEVCNTVOFF19_EL2 S3_4_C13_C11_1
  1121. #define AMEVCNTVOFF1A_EL2 S3_4_C13_C11_2
  1122. #define AMEVCNTVOFF1B_EL2 S3_4_C13_C11_3
  1123. #define AMEVCNTVOFF1C_EL2 S3_4_C13_C11_4
  1124. #define AMEVCNTVOFF1D_EL2 S3_4_C13_C11_5
  1125. #define AMEVCNTVOFF1E_EL2 S3_4_C13_C11_6
  1126. #define AMEVCNTVOFF1F_EL2 S3_4_C13_C11_7
  1127. /*******************************************************************************
  1128. * Realm management extension register definitions
  1129. ******************************************************************************/
  1130. #define GPCCR_EL3 S3_6_C2_C1_6
  1131. #define GPTBR_EL3 S3_6_C2_C1_4
  1132. #define SCXTNUM_EL2 S3_4_C13_C0_7
  1133. #define SCXTNUM_EL1 S3_0_C13_C0_7
  1134. #define SCXTNUM_EL0 S3_3_C13_C0_7
  1135. /*******************************************************************************
  1136. * RAS system registers
  1137. ******************************************************************************/
  1138. #define DISR_EL1 S3_0_C12_C1_1
  1139. #define DISR_A_BIT U(31)
  1140. #define ERRIDR_EL1 S3_0_C5_C3_0
  1141. #define ERRIDR_MASK U(0xffff)
  1142. #define ERRSELR_EL1 S3_0_C5_C3_1
  1143. /* System register access to Standard Error Record registers */
  1144. #define ERXFR_EL1 S3_0_C5_C4_0
  1145. #define ERXCTLR_EL1 S3_0_C5_C4_1
  1146. #define ERXSTATUS_EL1 S3_0_C5_C4_2
  1147. #define ERXADDR_EL1 S3_0_C5_C4_3
  1148. #define ERXPFGF_EL1 S3_0_C5_C4_4
  1149. #define ERXPFGCTL_EL1 S3_0_C5_C4_5
  1150. #define ERXPFGCDN_EL1 S3_0_C5_C4_6
  1151. #define ERXMISC0_EL1 S3_0_C5_C5_0
  1152. #define ERXMISC1_EL1 S3_0_C5_C5_1
  1153. #define ERXCTLR_ED_SHIFT U(0)
  1154. #define ERXCTLR_ED_BIT (U(1) << ERXCTLR_ED_SHIFT)
  1155. #define ERXCTLR_UE_BIT (U(1) << 4)
  1156. #define ERXPFGCTL_UC_BIT (U(1) << 1)
  1157. #define ERXPFGCTL_UEU_BIT (U(1) << 2)
  1158. #define ERXPFGCTL_CDEN_BIT (U(1) << 31)
  1159. /*******************************************************************************
  1160. * Armv8.3 Pointer Authentication Registers
  1161. ******************************************************************************/
  1162. #define APIAKeyLo_EL1 S3_0_C2_C1_0
  1163. #define APIAKeyHi_EL1 S3_0_C2_C1_1
  1164. #define APIBKeyLo_EL1 S3_0_C2_C1_2
  1165. #define APIBKeyHi_EL1 S3_0_C2_C1_3
  1166. #define APDAKeyLo_EL1 S3_0_C2_C2_0
  1167. #define APDAKeyHi_EL1 S3_0_C2_C2_1
  1168. #define APDBKeyLo_EL1 S3_0_C2_C2_2
  1169. #define APDBKeyHi_EL1 S3_0_C2_C2_3
  1170. #define APGAKeyLo_EL1 S3_0_C2_C3_0
  1171. #define APGAKeyHi_EL1 S3_0_C2_C3_1
  1172. /*******************************************************************************
  1173. * Armv8.4 Data Independent Timing Registers
  1174. ******************************************************************************/
  1175. #define DIT S3_3_C4_C2_5
  1176. #define DIT_BIT BIT(24)
  1177. /*******************************************************************************
  1178. * Armv8.5 - new MSR encoding to directly access PSTATE.SSBS field
  1179. ******************************************************************************/
  1180. #define SSBS S3_3_C4_C2_6
  1181. /*******************************************************************************
  1182. * Armv8.5 - Memory Tagging Extension Registers
  1183. ******************************************************************************/
  1184. #define TFSRE0_EL1 S3_0_C5_C6_1
  1185. #define TFSR_EL1 S3_0_C5_C6_0
  1186. #define RGSR_EL1 S3_0_C1_C0_5
  1187. #define GCR_EL1 S3_0_C1_C0_6
  1188. #define GCR_EL1_RRND_BIT (UL(1) << 16)
  1189. /*******************************************************************************
  1190. * Armv8.5 - Random Number Generator Registers
  1191. ******************************************************************************/
  1192. #define RNDR S3_3_C2_C4_0
  1193. #define RNDRRS S3_3_C2_C4_1
  1194. /*******************************************************************************
  1195. * FEAT_HCX - Extended Hypervisor Configuration Register
  1196. ******************************************************************************/
  1197. #define HCRX_EL2 S3_4_C1_C2_2
  1198. #define HCRX_EL2_MSCEn_BIT (UL(1) << 11)
  1199. #define HCRX_EL2_MCE2_BIT (UL(1) << 10)
  1200. #define HCRX_EL2_CMOW_BIT (UL(1) << 9)
  1201. #define HCRX_EL2_VFNMI_BIT (UL(1) << 8)
  1202. #define HCRX_EL2_VINMI_BIT (UL(1) << 7)
  1203. #define HCRX_EL2_TALLINT_BIT (UL(1) << 6)
  1204. #define HCRX_EL2_SMPME_BIT (UL(1) << 5)
  1205. #define HCRX_EL2_FGTnXS_BIT (UL(1) << 4)
  1206. #define HCRX_EL2_FnXS_BIT (UL(1) << 3)
  1207. #define HCRX_EL2_EnASR_BIT (UL(1) << 2)
  1208. #define HCRX_EL2_EnALS_BIT (UL(1) << 1)
  1209. #define HCRX_EL2_EnAS0_BIT (UL(1) << 0)
  1210. #define HCRX_EL2_INIT_VAL ULL(0x0)
  1211. /*******************************************************************************
  1212. * FEAT_FGT - Definitions for Fine-Grained Trap registers
  1213. ******************************************************************************/
  1214. #define HFGITR_EL2_INIT_VAL ULL(0x180000000000000)
  1215. #define HFGRTR_EL2_INIT_VAL ULL(0xC4000000000000)
  1216. #define HFGWTR_EL2_INIT_VAL ULL(0xC4000000000000)
  1217. /*******************************************************************************
  1218. * FEAT_TCR2 - Extended Translation Control Registers
  1219. ******************************************************************************/
  1220. #define TCR2_EL1 S3_0_C2_C0_3
  1221. #define TCR2_EL2 S3_4_C2_C0_3
  1222. /*******************************************************************************
  1223. * Permission indirection and overlay Registers
  1224. ******************************************************************************/
  1225. #define PIRE0_EL1 S3_0_C10_C2_2
  1226. #define PIRE0_EL2 S3_4_C10_C2_2
  1227. #define PIR_EL1 S3_0_C10_C2_3
  1228. #define PIR_EL2 S3_4_C10_C2_3
  1229. #define POR_EL1 S3_0_C10_C2_4
  1230. #define POR_EL2 S3_4_C10_C2_4
  1231. #define S2PIR_EL2 S3_4_C10_C2_5
  1232. #define S2POR_EL1 S3_0_C10_C2_5
  1233. /*******************************************************************************
  1234. * FEAT_GCS - Guarded Control Stack Registers
  1235. ******************************************************************************/
  1236. #define GCSCR_EL2 S3_4_C2_C5_0
  1237. #define GCSPR_EL2 S3_4_C2_C5_1
  1238. #define GCSCR_EL1 S3_0_C2_C5_0
  1239. #define GCSCRE0_EL1 S3_0_C2_C5_2
  1240. #define GCSPR_EL1 S3_0_C2_C5_1
  1241. #define GCSPR_EL0 S3_3_C2_C5_1
  1242. #define GCSCR_EXLOCK_EN_BIT (UL(1) << 6)
  1243. /*******************************************************************************
  1244. * FEAT_TRF - Trace Filter Control Registers
  1245. ******************************************************************************/
  1246. #define TRFCR_EL2 S3_4_C1_C2_1
  1247. #define TRFCR_EL1 S3_0_C1_C2_1
  1248. /*******************************************************************************
  1249. * Definitions for DynamicIQ Shared Unit registers
  1250. ******************************************************************************/
  1251. #define CLUSTERPWRDN_EL1 S3_0_c15_c3_6
  1252. /* CLUSTERPWRDN_EL1 register definitions */
  1253. #define DSU_CLUSTER_PWR_OFF 0
  1254. #define DSU_CLUSTER_PWR_ON 1
  1255. #define DSU_CLUSTER_PWR_MASK U(1)
  1256. #define DSU_CLUSTER_MEM_RET BIT(1)
  1257. /*******************************************************************************
  1258. * Definitions for CPU Power/Performance Management registers
  1259. ******************************************************************************/
  1260. #define CPUPPMCR_EL3 S3_6_C15_C2_0
  1261. #define CPUPPMCR_EL3_MPMMPINCTL_SHIFT UINT64_C(0)
  1262. #define CPUPPMCR_EL3_MPMMPINCTL_MASK UINT64_C(0x1)
  1263. #define CPUMPMMCR_EL3 S3_6_C15_C2_1
  1264. #define CPUMPMMCR_EL3_MPMM_EN_SHIFT UINT64_C(0)
  1265. #define CPUMPMMCR_EL3_MPMM_EN_MASK UINT64_C(0x1)
  1266. /* alternative system register encoding for the "sb" speculation barrier */
  1267. #define SYSREG_SB S0_3_C3_C0_7
  1268. #define CLUSTERPMCR_EL1 S3_0_C15_C5_0
  1269. #define CLUSTERPMCNTENSET_EL1 S3_0_C15_C5_1
  1270. #define CLUSTERPMCCNTR_EL1 S3_0_C15_C6_0
  1271. #define CLUSTERPMOVSSET_EL1 S3_0_C15_C5_3
  1272. #define CLUSTERPMOVSCLR_EL1 S3_0_C15_C5_4
  1273. #define CLUSTERPMSELR_EL1 S3_0_C15_C5_5
  1274. #define CLUSTERPMXEVTYPER_EL1 S3_0_C15_C6_1
  1275. #define CLUSTERPMXEVCNTR_EL1 S3_0_C15_C6_2
  1276. #define CLUSTERPMCR_E_BIT BIT(0)
  1277. #define CLUSTERPMCR_N_SHIFT U(11)
  1278. #define CLUSTERPMCR_N_MASK U(0x1f)
  1279. #endif /* ARCH_H */