arch.h 52 KB

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