1 /* 2 * SPDX-License-Identifier: BSD-3-Clause 3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. 4 */ 5 6 #ifndef ARCH_H 7 #define ARCH_H 8 9 #include <utils_def.h> 10 11 /* Cache line size */ 12 #define CACHE_WRITEBACK_GRANULE UL(64) 13 14 /* Timer interrupt IDs defined by the Server Base System Architecture */ 15 #define EL1_VIRT_TIMER_PPI UL(27) 16 #define EL1_PHYS_TIMER_PPI UL(30) 17 18 /* Counter-timer Physical Offset register */ 19 #define CNTPOFF_EL2 S3_4_C14_C0_6 20 21 /* MPAM0 Register */ 22 #define MPAM0_EL1 S3_0_C10_C5_1 23 24 /* Interrupt Controller registers */ 25 #define ICC_HPPIR1_EL1 S3_0_C12_C12_2 26 #define ICC_SRE_EL2 S3_4_C12_C9_5 27 28 /* Interrupt Controller Control Register */ 29 #define ICC_CTLR_EL1 S3_0_C12_C12_4 30 31 #define ICC_CTLR_EL1_EXT_RANGE_SHIFT UL(19) 32 #define ICC_CTLR_EL1_EXT_RANGE_BIT INPLACE(ICC_CTLR_EL1_EXT_RANGE, UL(1)) 33 34 /* Virtual GIC registers */ 35 #define ICH_AP0R0_EL2 S3_4_C12_C8_0 36 #define ICH_AP0R1_EL2 S3_4_C12_C8_1 37 #define ICH_AP0R2_EL2 S3_4_C12_C8_2 38 #define ICH_AP0R3_EL2 S3_4_C12_C8_3 39 #define ICH_AP1R0_EL2 S3_4_C12_C9_0 40 #define ICH_AP1R1_EL2 S3_4_C12_C9_1 41 #define ICH_AP1R2_EL2 S3_4_C12_C9_2 42 #define ICH_AP1R3_EL2 S3_4_C12_C9_3 43 44 #define ICH_LR0_EL2 S3_4_C12_C12_0 45 #define ICH_LR1_EL2 S3_4_C12_C12_1 46 #define ICH_LR2_EL2 S3_4_C12_C12_2 47 #define ICH_LR3_EL2 S3_4_C12_C12_3 48 #define ICH_LR4_EL2 S3_4_C12_C12_4 49 #define ICH_LR5_EL2 S3_4_C12_C12_5 50 #define ICH_LR6_EL2 S3_4_C12_C12_6 51 #define ICH_LR7_EL2 S3_4_C12_C12_7 52 #define ICH_LR8_EL2 S3_4_C12_C13_0 53 #define ICH_LR9_EL2 S3_4_C12_C13_1 54 #define ICH_LR10_EL2 S3_4_C12_C13_2 55 #define ICH_LR11_EL2 S3_4_C12_C13_3 56 #define ICH_LR12_EL2 S3_4_C12_C13_4 57 #define ICH_LR13_EL2 S3_4_C12_C13_5 58 #define ICH_LR14_EL2 S3_4_C12_C13_6 59 #define ICH_LR15_EL2 S3_4_C12_C13_7 60 61 #define ICH_HCR_EL2 S3_4_C12_C11_0 62 #define ICH_VTR_EL2 S3_4_C12_C11_1 63 #define ICH_MISR_EL2 S3_4_C12_C11_2 64 #define ICH_VMCR_EL2 S3_4_C12_C11_7 65 66 /* RNDR definition */ 67 #define RNDR S3_3_C2_C4_0 68 69 /* CLIDR definitions */ 70 #define LOC_SHIFT U(24) 71 #define CTYPE_SHIFT(n) U(3 * ((n) - 1)) 72 #define CLIDR_FIELD_WIDTH U(3) 73 74 /* CSSELR definitions */ 75 #define LEVEL_SHIFT U(1) 76 77 /* Data cache set/way op type defines */ 78 #define DCISW U(0x0) 79 #define DCCISW U(0x1) 80 #define DCCSW U(0x2) 81 82 #define TCR_EL2_T0SZ_SHIFT UL(0) 83 #define TCR_EL2_T0SZ_WIDTH UL(6) 84 #define TCR_EL2_T0SZ_MASK MASK(TCR_EL2_T0SZ) 85 86 #define TCR_EL2_T1SZ_SHIFT UL(16) 87 #define TCR_EL2_T1SZ_WIDTH UL(6) 88 #define TCR_EL2_T1SZ_MASK MASK(TCR_EL2_T0SZ) 89 90 #define TCR_EL2_EPD0_SHIFT UL(7) 91 #define TCR_EL2_EPD0_WIDTH UL(1) 92 #define TCR_EL2_EPD0_BIT INPLACE(TCR_EL2_EPD0, UL(1)) 93 94 #define TCR_EL2_IRGN0_SHIFT UL(8) 95 #define TCR_EL2_IRGN0_WIDTH UL(2) 96 #define TCR_EL2_IRGN0_WBWA INPLACE(TCR_EL2_IRGN0, UL(1)) 97 98 #define TCR_EL2_ORGN0_SHIFT UL(10) 99 #define TCR_EL2_ORGN0_WIDTH UL(2) 100 #define TCR_EL2_ORGN0_WBWA INPLACE(TCR_EL2_ORGN0, UL(1)) 101 102 #define TCR_EL2_IRGN1_SHIFT UL(24) 103 #define TCR_EL2_IRGN1_WIDTH UL(2) 104 #define TCR_EL2_IRGN1_WBWA INPLACE(TCR_EL2_IRGN1, UL(1)) 105 106 #define TCR_EL2_ORGN1_SHIFT UL(26) 107 #define TCR_EL2_ORGN1_WIDTH UL(2) 108 #define TCR_EL2_ORGN1_WBWA INPLACE(TCR_EL2_ORGN1, UL(1)) 109 110 #define TCR_EL2_SH0_SHIFT UL(12) 111 #define TCR_EL2_SH0_WIDTH UL(2) 112 #define TCR_EL2_SH0_IS INPLACE(TCR_EL2_SH0, UL(3)) 113 114 #define TCR_EL2_SH1_SHIFT UL(28) 115 #define TCR_EL2_SH1_WIDTH UL(2) 116 #define TCR_EL2_SH1_IS INPLACE(TCR_EL2_SH1, UL(3)) 117 118 #define TCR_EL2_TG0_SHIFT UL(14) 119 #define TCR_EL2_TG0_WIDTH UL(2) 120 #define TCR_EL2_TG0_4K INPLACE(TCR_EL2_TG0, UL(0)) 121 122 #define TCR_EL2_TG1_SHIFT UL(30) 123 #define TCR_EL2_TG1_WIDTH UL(2) 124 #define TCR_EL2_TG1_4K INPLACE(TCR_EL2_TG1, UL(0)) 125 126 #define TCR_EL2_IPS_SHIFT UL(32) 127 #define TCR_EL2_IPS_WIDTH UL(3) 128 #define TCR_PS_BITS_4GB INPLACE(TCR_EL2_IPS, UL(0)) 129 #define TCR_PS_BITS_64GB INPLACE(TCR_EL2_IPS, UL(1)) 130 #define TCR_PS_BITS_1TB INPLACE(TCR_EL2_IPS, UL(2)) 131 #define TCR_PS_BITS_4TB INPLACE(TCR_EL2_IPS, UL(3)) 132 #define TCR_PS_BITS_16TB INPLACE(TCR_EL2_IPS, UL(4)) 133 #define TCR_PS_BITS_256TB INPLACE(TCR_EL2_IPS, UL(5)) 134 135 #define ADDR_MASK_48_TO_63 ULL(0xFFFF000000000000) 136 #define ADDR_MASK_44_TO_47 ULL(0x0000F00000000000) 137 #define ADDR_MASK_42_TO_43 ULL(0x00000C0000000000) 138 #define ADDR_MASK_40_TO_41 ULL(0x0000030000000000) 139 #define ADDR_MASK_36_TO_39 ULL(0x000000F000000000) 140 #define ADDR_MASK_32_TO_35 ULL(0x0000000F00000000) 141 142 #define TCR_EL2_AS (UL(1) << 36) 143 #define TCR_EL2_HPD0 (UL(1) << 41) 144 #define TCR_EL2_HPD1 (UL(1) << 42) 145 #define TCR_EL2_E0PD1 (UL(1) << 56) /* TODO: ARMv8.5-E0PD, otherwise RES0 */ 146 147 #define TCR_TxSZ_MIN UL(16) 148 #define TCR_TxSZ_MAX UL(39) 149 #define TCR_TxSZ_MAX_TTST UL(48) 150 151 /* HCR definitions */ 152 #define HCR_FWB (UL(1) << 46) 153 #define HCR_TEA (UL(1) << 37) 154 #define HCR_API (UL(1) << 41) 155 #define HCR_APK (UL(1) << 40) 156 #define HCR_TERR (UL(1) << 36) 157 #define HCR_TLOR (UL(1) << 35) 158 #define HCR_E2H (UL(1) << 34) 159 #define HCR_RW (UL(1) << 31) 160 #define HCR_TGE (UL(1) << 27) 161 #define HCR_TSW (UL(1) << 22) 162 #define HCR_TACR (UL(1) << 21) 163 #define HCR_TIDCP (UL(1) << 20) 164 #define HCR_TSC (UL(1) << 19) 165 #define HCR_TID3 (UL(1) << 18) 166 #define HCR_TWE (UL(1) << 14) 167 #define HCR_TWI (UL(1) << 13) 168 #define HCR_VSE (UL(1) << 8) 169 170 #define HCR_BSU_SHIFT 10 171 #define HCR_BSU_WIDTH 2 172 #define HCR_BSU_IS INPLACE(HCR_BSU, 1) /* Barriers are promoted to IS */ 173 174 #define HCR_FB (UL(1) << 9) 175 #define HCR_VI (UL(1) << 7) 176 #define HCR_AMO (UL(1) << 5) 177 #define HCR_IMO (UL(1) << 4) 178 #define HCR_FMO (UL(1) << 3) 179 #define HCR_PTW (UL(1) << 2) 180 #define HCR_SWIO (UL(1) << 1) 181 #define HCR_VM (UL(1) << 0) 182 183 /* TODO verify that all the traps are enabled */ 184 #define HCR_FLAGS (HCR_FWB | HCR_E2H | HCR_RW | HCR_TSC | HCR_AMO | \ 185 HCR_BSU_IS | HCR_IMO | HCR_FMO | HCR_PTW | HCR_SWIO | HCR_VM | \ 186 HCR_TID3 | HCR_TEA) 187 188 #define HCR_EL2_INIT (HCR_TGE | HCR_E2H | HCR_TEA) 189 190 #define MAIR_ELx_ATTR0_SHIFT 0 191 #define MAIR_ELx_ATTR0_WIDTH 8 192 #define MAIR_ELx_ATTR0_MASK MASK(MAIR_ELx_ATTR0) 193 194 /******************************************************************************* 195 * Definitions of MAIR encodings for device and normal memory 196 ******************************************************************************/ 197 /* 198 * MAIR encodings for device memory attributes. 199 */ 200 #define MAIR_DEV_NGNRNE UL(0x0) /* Device nGnRnE */ 201 #define MAIR_DEV_NGNRNE_IDX 0x1 202 203 #define MAIR_DEV_NGNRE UL(0x4) 204 205 #define MAIR_NIOWBNTRW 0xff 206 #define MAIR_NIOWBNTRW_IDX 0x0 207 208 /* 209 * MAIR encodings for normal memory attributes. 210 * 211 * Cache Policy 212 * WT: Write Through 213 * WB: Write Back 214 * NC: Non-Cacheable 215 * 216 * Transient Hint 217 * NTR: Non-Transient 218 * TR: Transient 219 * 220 * Allocation Policy 221 * RA: Read Allocate 222 * WA: Write Allocate 223 * RWA: Read and Write Allocate 224 * NA: No Allocation 225 */ 226 #define MAIR_NORM_WT_TR_WA UL(0x1) 227 #define MAIR_NORM_WT_TR_RA UL(0x2) 228 #define MAIR_NORM_WT_TR_RWA UL(0x3) 229 #define MAIR_NORM_NC UL(0x4) 230 #define MAIR_NORM_WB_TR_WA UL(0x5) 231 #define MAIR_NORM_WB_TR_RA UL(0x6) 232 #define MAIR_NORM_WB_TR_RWA UL(0x7) 233 #define MAIR_NORM_WT_NTR_NA UL(0x8) 234 #define MAIR_NORM_WT_NTR_WA UL(0x9) 235 #define MAIR_NORM_WT_NTR_RA UL(0xa) 236 #define MAIR_NORM_WT_NTR_RWA UL(0xb) 237 #define MAIR_NORM_WB_NTR_NA UL(0xc) 238 #define MAIR_NORM_WB_NTR_WA UL(0xd) 239 #define MAIR_NORM_WB_NTR_RA UL(0xe) 240 #define MAIR_NORM_WB_NTR_RWA UL(0xf) 241 242 #define MAIR_NORM_OUTER_SHIFT U(4) 243 244 #define MAKE_MAIR_NORMAL_MEMORY(inner, outer) \ 245 ((inner) | ((outer) << MAIR_NORM_OUTER_SHIFT)) 246 247 #define MAKE_MAIR_NORMAL_MEMORY_IO(_mair) \ 248 MAKE_MAIR_NORMAL_MEMORY(_mair, _mair) 249 250 /* 251 * TTBR Definitions 252 */ 253 #define TTBR_CNP_BIT UL(0x1) 254 255 #define TTBRx_EL2_CnP_SHIFT 0 256 #define TTBRx_EL2_CnP_WIDTH 1 257 258 #define TTBRx_EL2_BADDR_SHIFT 1 259 #define TTBRx_EL2_BADDR_WIDTH 47 260 261 #define TTBRx_EL2_ASID_SHIFT 48 262 #define TTBRx_EL2_ASID_WIDTH 16 263 264 /* 265 * VTTBR Definitions 266 */ 267 #define VTTBR_EL2_VMID_SHIFT 48 268 #define VTTBR_EL2_VMID_WIDTH 16 269 270 /* 271 * ESR Definitions 272 */ 273 #define ESR_EL2_EC_SHIFT 26 274 #define ESR_EL2_EC_WIDTH 6 275 #define ESR_EL2_EC_MASK MASK(ESR_EL2_EC) 276 277 #define ESR_EL2_IL_SHIFT 25 278 #define ESR_EL2_IL_WIDTH 1 279 #define ESR_EL2_IL_MASK MASK(ESR_EL2_IL) 280 281 #define ESR_EL2_ISS_SHIFT 0 282 #define ESR_EL2_ISS_WIDTH 25 283 #define ESR_EL2_ISS_MASK MASK(ESR_EL2_ISS) 284 285 #define ESR_EL2_EC_UNKNOWN INPLACE(ESR_EL2_EC, 0) 286 #define ESR_EL2_EC_WFX INPLACE(ESR_EL2_EC, 1) 287 #define ESR_EL2_EC_FPU INPLACE(ESR_EL2_EC, 7) 288 #define ESR_EL2_EC_SVC INPLACE(ESR_EL2_EC, 21) 289 #define ESR_EL2_EC_HVC INPLACE(ESR_EL2_EC, 22) 290 #define ESR_EL2_EC_SMC INPLACE(ESR_EL2_EC, 23) 291 #define ESR_EL2_EC_SYSREG INPLACE(ESR_EL2_EC, 24) 292 #define ESR_EL2_EC_SVE INPLACE(ESR_EL2_EC, 25) 293 #define ESR_EL2_EC_INST_ABORT INPLACE(ESR_EL2_EC, 32) 294 #define ESR_EL2_EC_INST_ABORT_SEL INPLACE(ESR_EL2_EC, 33) 295 #define ESR_EL2_EC_DATA_ABORT INPLACE(ESR_EL2_EC, 36) 296 #define ESR_EL2_EC_DATA_ABORT_SEL INPLACE(ESR_EL2_EC, 37) 297 #define ESR_EL2_EC_SERROR INPLACE(ESR_EL2_EC, 47) 298 299 /* Data/Instruction Abort ESR fields */ 300 #define ESR_EL2_ABORT_ISV_BIT (1UL << 24) 301 302 #define ESR_EL2_ABORT_SAS_SHIFT 22 303 #define ESR_EL2_ABORT_SAS_WIDTH 2 304 #define ESR_EL2_ABORT_SAS_MASK MASK(ESR_EL2_ABORT_SAS) 305 306 #define ESR_EL2_ABORT_SAS_BYTE_VAL 0 307 #define ESR_EL2_ABORT_SAS_HWORD_VAL 1 308 #define ESR_EL2_ABORT_SAS_WORD_VAL 2 309 #define ESR_EL2_ABORT_SAS_DWORD_VAL 3 310 311 #define ESR_EL2_ABORT_SSE_BIT (1UL << 21) 312 313 #define ESR_EL2_ABORT_SRT_SHIFT 16 314 #define ESR_EL2_ABORT_SRT_WIDTH 5 315 #define ESR_EL2_ABORT_SRT_MASK MASK(ESR_EL2_ABORT_SRT) 316 317 #define ESR_EL2_ABORT_SET_SHIFT 11 318 #define ESR_EL2_ABORT_SET_WIDTH 2 319 #define ESR_EL2_ABORT_SET_MASK MASK(ESR_EL2_ABORT_SET) 320 #define ESR_EL2_ABORT_SET_UER INPLACE(ESR_EL2_ABORT_SET, 0) 321 #define ESR_EL2_ABORT_SET_UC INPLACE(ESR_EL2_ABORT_SET, 2) 322 #define ESR_EL2_ABORT_SET_UEO INPLACE(ESR_EL2_ABORT_SET, 3) 323 324 #define ESR_EL2_ABORT_SF_BIT (1UL << 15) 325 #define ESR_EL2_ABORT_FNV_BIT (1UL << 10) 326 #define ESR_EL2_ABORT_EA_BIT (1UL << 9) 327 #define ESR_EL2_ABORT_S1PTW_BIT (1UL << 7) 328 #define ESR_EL2_ABORT_WNR_BIT (1UL << 6) 329 #define ESR_EL2_ABORT_FSC_SHIFT 0 330 #define ESR_EL2_ABORT_FSC_WIDTH 6 331 #define ESR_EL2_ABORT_FSC_MASK MASK(ESR_EL2_ABORT_FSC) 332 333 #define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT 0x04 334 #define ESR_EL2_ABORT_FSC_PERMISSION_FAULT 0x0c 335 #define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT_L0 0x04 336 #define ESR_EL2_ABORT_FSC_SEA 0x10 337 #define ESR_EL2_ABORT_FSC_SEA_TTW_START 0x13 338 #define ESR_EL2_ABORT_FSC_SEA_TTW_END 0x17 339 #define ESR_EL2_ABORT_FSC_GPF 0x28 340 #define ESR_EL2_ABORT_FSC_LEVEL_SHIFT 0 341 #define ESR_EL2_ABORT_FSC_LEVEL_WIDTH 2 342 #define ESR_EL2_ABORT_FSC_LEVEL_MASK MASK(ESR_EL2_ABORT_FSC_LEVEL) 343 344 /* The ESR fields that are reported to the host on Instr./Data Synchronous Abort */ 345 #define ESR_NONEMULATED_ABORT_MASK ( \ 346 ESR_EL2_EC_MASK | \ 347 ESR_EL2_ABORT_SET_MASK | \ 348 ESR_EL2_ABORT_FNV_BIT | \ 349 ESR_EL2_ABORT_EA_BIT | \ 350 ESR_EL2_ABORT_FSC_MASK) 351 352 #define ESR_EMULATED_ABORT_MASK ( \ 353 ESR_NONEMULATED_ABORT_MASK | \ 354 ESR_EL2_ABORT_ISV_BIT | \ 355 ESR_EL2_ABORT_SAS_MASK | \ 356 ESR_EL2_ABORT_SF_BIT | \ 357 ESR_EL2_ABORT_WNR_BIT) 358 359 #define ESR_EL2_SERROR_DFSC_SHIFT 0 360 #define ESR_EL2_SERROR_DFSC_WIDTH 6 361 #define ESR_EL2_SERROR_DFSC_MASK MASK(ESR_EL2_SERROR_DFSC) 362 #define ESR_EL2_SERROR_DFSC_UNCAT INPLACE(ESR_EL2_SERROR_DFSC, 0) 363 #define ESR_EL2_SERROR_DFSC_ASYNC INPLACE(ESR_EL2_SERROR_DFSC, 1) 364 365 #define ESR_EL2_SERROR_EA_BIT (1UL << 9) 366 367 #define ESR_EL2_SERROR_AET_SHIFT 10 368 #define ESR_EL2_SERROR_AET_WIDTH 3 369 #define ESR_EL2_SERROR_AET_MASK MASK(ESR_EL2_SERROR_AET) 370 #define ESR_EL2_SERROR_AET_UC INPLACE(ESR_EL2_SERROR_AET, 0) 371 #define ESR_EL2_SERROR_AET_UEU INPLACE(ESR_EL2_SERROR_AET, 1) 372 #define ESR_EL2_SERROR_AET_UEO INPLACE(ESR_EL2_SERROR_AET, 2) 373 #define ESR_EL2_SERROR_AET_UER INPLACE(ESR_EL2_SERROR_AET, 3) 374 #define ESR_EL2_SERROR_AET_CE INPLACE(ESR_EL2_SERROR_AET, 6) 375 376 #define ESR_EL2_SERROR_IESB_BIT (1UL << 13) 377 #define ESR_EL2_SERROR_IDS_BIT (1UL << 24) 378 379 /* The ESR fields that are reported to the host on SError */ 380 #define ESR_SERROR_MASK ( \ 381 ESR_EL2_SERROR_IDS_BIT | \ 382 ESR_EL2_SERROR_AET_MASK | \ 383 ESR_EL2_SERROR_EA_BIT | \ 384 ESR_EL2_SERROR_DFSC_MASK) 385 386 #define ESR_EL2_SYSREG_TRAP_OP0_SHIFT 20 387 #define ESR_EL2_SYSREG_TRAP_OP0_WIDTH 2 388 #define ESR_EL2_SYSREG_TRAP_OP0_MASK MASK(ESR_EL2_SYSREG_TRAP_OP0) 389 390 #define ESR_EL2_SYSREG_TRAP_OP2_SHIFT 17 391 #define ESR_EL2_SYSREG_TRAP_OP2_WIDTH 3 392 #define ESR_EL2_SYSREG_TRAP_OP2_MASK MASK(ESR_EL2_SYSREG_TRAP_OP2) 393 394 #define ESR_EL2_SYSREG_TRAP_OP1_SHIFT 14 395 #define ESR_EL2_SYSREG_TRAP_OP1_WIDTH 3 396 #define ESR_EL2_SYSREG_TRAP_OP1_MASK MASK(ESR_EL2_SYSREG_TRAP_OP1) 397 398 #define ESR_EL2_SYSREG_TRAP_CRN_SHIFT 10 399 #define ESR_EL2_SYSREG_TRAP_CRN_WIDTH 4 400 #define ESR_EL2_SYSREG_TRAP_CRN_MASK MASK(ESR_EL2_SYSREG_TRAP_CRN) 401 402 #define ESR_EL2_SYSREG_TRAP_RT_SHIFT 5 403 #define ESR_EL2_SYSREG_TRAP_RT_WIDTH 5 404 #define ESR_EL2_SYSREG_TRAP_RT_MASK MASK(ESR_EL2_SYSREG_TRAP_RT) 405 406 #define ESR_EL2_SYSREG_TRAP_CRM_SHIFT 1 407 #define ESR_EL2_SYSREG_TRAP_CRM_WIDTH 4 408 #define ESR_EL2_SYSREG_TRAP_CRM_MASK MASK(ESR_EL2_SYSREG_TRAP_CRM) 409 410 /* WFx ESR fields */ 411 #define ESR_EL2_WFx_TI_BIT (1UL << 0) 412 413 /* xVC ESR fields */ 414 #define ESR_EL2_xVC_IMM_SHIFT 0 415 #define ESR_EL2_xVC_IMM_WIDTH 16 416 #define ESR_EL2_xVC_IMM_MASK MASK(ESR_EL2_xVC_IMM) 417 418 /* ID_AA64PFR0_EL1 definitions */ 419 #define ID_AA64PFR0_EL1_SVE_SHIFT UL(32) 420 #define ID_AA64PFR0_EL1_SVE_WIDTH UL(4) 421 #define ID_AA64PFR0_EL1_SVE_MASK UL(0xf) 422 423 #define ID_AA64PFR0_EL1_AMU_SHIFT UL(44) 424 #define ID_AA64PFR0_EL1_AMU_WIDTH 4 425 426 /* ID_AA64MMFR0_EL1 definitions */ 427 #define ID_AA64MMFR0_EL1_PARANGE_SHIFT U(0) 428 #define ID_AA64MMFR0_EL1_PARANGE_MASK ULL(0xf) 429 430 #define PARANGE_0000_WIDTH U(32) 431 #define PARANGE_0001_WIDTH U(36) 432 #define PARANGE_0010_WIDTH U(40) 433 #define PARANGE_0011_WIDTH U(42) 434 #define PARANGE_0100_WIDTH U(44) 435 #define PARANGE_0101_WIDTH U(48) 436 #define PARANGE_0110_WIDTH U(52) 437 438 #define ID_AA64MMFR0_EL1_ECV_SHIFT U(60) 439 #define ID_AA64MMFR0_EL1_ECV_MASK ULL(0xf) 440 #define ID_AA64MMFR0_EL1_ECV_NOT_SUPPORTED ULL(0x0) 441 #define ID_AA64MMFR0_EL1_ECV_SUPPORTED ULL(0x1) 442 #define ID_AA64MMFR0_EL1_ECV_SELF_SYNCH ULL(0x2) 443 444 #define ID_AA64MMFR0_EL1_FGT_SHIFT U(56) 445 #define ID_AA64MMFR0_EL1_FGT_MASK ULL(0xf) 446 #define ID_AA64MMFR0_EL1_FGT_SUPPORTED ULL(0x1) 447 #define ID_AA64MMFR0_EL1_FGT_NOT_SUPPORTED ULL(0x0) 448 449 #define ID_AA64MMFR0_EL1_TGRAN4_2_SHIFT U(40) 450 #define ID_AA64MMFR0_EL1_TGRAN4_2_MASK ULL(0xf) 451 #define ID_AA64MMFR0_EL1_TGRAN4_2_TGRAN4 ULL(0x0) 452 #define ID_AA64MMFR0_EL1_TGRAN4_2_NOT_SUPPORTED ULL(0x1) 453 #define ID_AA64MMFR0_EL1_TGRAN4_2_SUPPORTED ULL(0x2) 454 #define ID_AA64MMFR0_EL1_TGRAN4_2_LPA2 ULL(0x3) 455 456 #define ID_AA64MMFR0_EL1_TGRAN16_2_SHIFT U(32) 457 #define ID_AA64MMFR0_EL1_TGRAN16_2_MASK ULL(0xf) 458 #define ID_AA64MMFR0_EL1_TGRAN16_2_TGRAN16 ULL(0x0) 459 #define ID_AA64MMFR0_EL1_TGRAN16_2_NOT_SUPPORTED ULL(0x1) 460 #define ID_AA64MMFR0_EL1_TGRAN16_2_SUPPORTED ULL(0x2) 461 #define ID_AA64MMFR0_EL1_TGRAN16_2_LPA2 ULL(0x3) 462 463 #define ID_AA64MMFR0_EL1_TGRAN4_SHIFT U(28) 464 #define ID_AA64MMFR0_EL1_TGRAN4_MASK ULL(0xf) 465 #define ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED ULL(0x0) 466 #define ID_AA64MMFR0_EL1_TGRAN4_LPA2 ULL(0x1) 467 #define ID_AA64MMFR0_EL1_TGRAN4_NOT_SUPPORTED ULL(0xf) 468 469 #define ID_AA64MMFR0_EL1_TGRAN64_SHIFT UL(24) 470 #define ID_AA64MMFR0_EL1_TGRAN64_MASK UL(0xf) 471 #define ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED UL(0x0) 472 #define ID_AA64MMFR0_EL1_TGRAN64_NOT_SUPPORTED UL(0xf) 473 474 #define ID_AA64MMFR0_EL1_TGRAN16_SHIFT UL(20) 475 #define ID_AA64MMFR0_EL1_TGRAN16_MASK UL(0xf) 476 #define ID_AA64MMFR0_EL1_TGRAN16_NOT_SUPPORTED UL(0x0) 477 #define ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED UL(0x1) 478 #define ID_AA64MMFR0_EL1_TGRAN16_LPA2 UL(0x2) 479 480 /* RNDR definitions */ 481 #define ID_AA64ISAR0_RNDR_SHIFT UL(60) 482 #define ID_AA64ISAR0_RNDR_MASK UL(0xF) 483 484 /* ID_AA64MMFR1_EL1 definitions */ 485 #define ID_AA64MMFR1_EL1_VMIDBits_SHIFT UL(4) 486 #define ID_AA64MMFR1_EL1_VMIDBits_MASK UL(0xf) 487 #define ID_AA64MMFR1_EL1_VMIDBits_8 UL(0) 488 #define ID_AA64MMFR1_EL1_VMIDBits_16 UL(2) 489 490 /* HPFAR_EL2 definitions */ 491 #define HPFAR_EL2_FIPA_SHIFT 4 492 #define HPFAR_EL2_FIPA_WIDTH 40 493 #define HPFAR_EL2_FIPA_MASK MASK(HPFAR_EL2_FIPA) 494 #define HPFAR_EL2_FIPA_OFFSET 8 495 496 /* SPSR definitions */ 497 #define SPSR_EL2_MODE_SHIFT 0 498 #define SPSR_EL2_MODE_WIDTH 4 499 #define SPSR_EL2_MODE_EL0t INPLACE(SPSR_EL2_MODE, 0) 500 501 #define SPSR_EL2_MODE_SHIFT 0 502 #define SPSR_EL2_MODE_WIDTH 4 503 #define SPSR_EL2_MODE_EL1h INPLACE(SPSR_EL2_MODE, 5) 504 #define SPSR_EL2_MODE_EL1t INPLACE(SPSR_EL2_MODE, 4) 505 506 /* FIXME: DAIF definitions are redundant here. Might need unification. */ 507 #define SPSR_EL2_nRW_SHIFT 4 508 #define SPSR_EL2_nRW_WIDTH 1 509 #define SPSR_EL2_nRW_AARCH64 INPLACE(SPSR_EL2_nRW, 0) 510 #define SPSR_EL2_nRW_AARCH32 INPLACE(SPSR_EL2_nRW, 1) 511 512 #define SPSR_EL2_DAIF_SHIFT U(6) 513 #define SPSR_EL2_DAIF_MASK U(0xf) 514 515 #define SPSR_EL2_AIF_SHIFT U(6) 516 #define SPSR_EL2_AIF_MASK U(0x7) 517 518 #define SPSR_EL2_F_SHIFT 6 519 #define SPSR_EL2_F_WIDTH 1 520 #define SPSR_EL2_F_BIT INPLACE(SPSR_EL2_F, 1) 521 #define DAIF_FIQ_BIT (U(1) << 0) 522 523 #define SPSR_EL2_I_SHIFT 7 524 #define SPSR_EL2_I_WIDTH 1 525 #define SPSR_EL2_I_BIT INPLACE(SPSR_EL2_I, 1) 526 #define DAIF_IRQ_BIT (U(1) << 1) 527 528 #define SPSR_EL2_A_SHIFT 8 529 #define SPSR_EL2_A_WIDTH 1 530 #define SPSR_EL2_A_BIT INPLACE(SPSR_EL2_A, 1) 531 #define DAIF_ABT_BIT (U(1) << 2) 532 533 #define SPSR_EL2_D_SHIFT 9 534 #define SPSR_EL2_D_WIDTH 1 535 #define SPSR_EL2_D_BIT INPLACE(SPSR_EL2_D, 1) 536 #define DAIF_DBG_BIT (U(1) << 3) 537 538 #define SPSR_EL2_SSBS_SHIFT 12 539 #define SPSR_EL2_SSBS_WIDTH 1 540 #define SPSR_EL2_SSBS_BIT INPLACE(SPSR_EL2_SSBS, 1) 541 542 #define SPSR_EL2_IL_SHIFT 20 543 #define SPSR_EL2_IL_WIDTH 1 544 #define SPSR_EL2_IL_BIT INPLACE(SPSR_EL2_IL, 1) 545 546 #define SPSR_EL2_SS_SHIFT 21 547 #define SPSR_EL2_SS_WIDTH 1 548 #define SPSR_EL2_SS_BIT INPLACE(SPSR_EL2_SS, 1) 549 550 #define SPSR_EL2_PAN_SHIFT 22 551 #define SPSR_EL2_PAN_WIDTH 1 552 #define SPSR_EL2_PAN_BIT INPLACE(SPSR_EL2_PAN, 1) 553 554 #define SPSR_EL2_UAO_SHIFT 23 555 #define SPSR_EL2_UAO_WIDTH 1 556 #define SPSR_EL2_UAO_BIT INPLACE(SPSR_EL2_UAO, 1) 557 558 #define SPSR_EL2_V_SHIFT 28 559 #define SPSR_EL2_V_WIDTH 1 560 #define SPSR_EL2_V_BIT INPLACE(SPSR_EL2_V, 1) 561 562 #define SPSR_EL2_C_SHIFT 29 563 #define SPSR_EL2_C_WIDTH 1 564 #define SPSR_EL2_C_BIT INPLACE(SPSR_EL2_C, 1) 565 566 #define SPSR_EL2_Z_SHIFT 30 567 #define SPSR_EL2_Z_WIDTH 1 568 #define SPSR_EL2_Z_BIT INPLACE(SPSR_EL2_Z, 1) 569 570 #define SPSR_EL2_N_SHIFT 31 571 #define SPSR_EL2_N_WIDTH 1 572 #define SPSR_EL2_N_BIT INPLACE(SPSR_EL2_N, 1) 573 574 /* VTCR definitions */ 575 #define VTCR_T0SZ_SHIFT 0 576 #define VTCR_T0SZ_WIDTH 6 577 578 #define VTCR_SL0_SHIFT 6 579 #define VTCR_SL0_WIDTH 2 580 581 #define VTCR_SL0_4K_L2 INPLACE(VTCR_SL0, 0) 582 #define VTCR_SL0_4K_L1 INPLACE(VTCR_SL0, 1) 583 #define VTCR_SL0_4K_L0 INPLACE(VTCR_SL0, 2) 584 #define VTCR_SL0_4K_L3 INPLACE(VTCR_SL0, 3) 585 586 #define VTCR_IRGN0_SHIFT 8 587 #define VTCR_IRGN0_WIDTH 2 588 #define VTCR_IRGN0_WBRAWA INPLACE(VTCR_IRGN0, 1) 589 590 #define VTCR_ORGN0_SHIFT 10 591 #define VTCR_ORGN0_WIDTH 2 592 #define VTCR_ORGN0_WBRAWA INPLACE(VTCR_ORGN0, 1) 593 594 #define VTCR_SH0_SHIFT 12 595 #define VTCR_SH0_WIDTH 2 596 #define VTCR_SH0_IS INPLACE(VTCR_SH0, 3) 597 598 #define VTCR_TG0_SHIFT 14 599 #define VTCR_TG0_WIDTH 2 600 #define VTCR_TG0_4K INPLACE(VTCR_TG0, 0) 601 602 #define VTCR_PS_SHIFT 16 603 #define VTCR_PS_WIDTH 3 604 #define VTCR_PS_40 INPLACE(VTCR_PS, 2) 605 606 #define VTCR_VS (UL(1) << 19) 607 #define VTCR_NSA (UL(1) << 30) 608 #define VTCR_RES1 (UL(1) << 31) 609 610 #define VTCR_FLAGS ( \ 611 VTCR_IRGN0_WBRAWA | /* PTW inner cache attr. is WB RAWA*/ \ 612 VTCR_ORGN0_WBRAWA | /* PTW outer cache attr. is WB RAWA*/ \ 613 VTCR_SH0_IS | /* PTW shareability attr. is Outer Sharable*/\ 614 VTCR_TG0_4K | /* 4K granule size in non-secure PT*/ \ 615 VTCR_PS_40 | /* size(PA) = 40 */ \ 616 /* VS = 0 size(VMID) = 8 */ \ 617 /* NSW = 0 non-secure s2 is made of secure pages*/ \ 618 VTCR_NSA | /* non-secure IPA maps to non-secure PA */ \ 619 VTCR_RES1 \ 620 ) 621 622 623 /* SCTLR definitions */ 624 #define SCTLR_EL1_EE (UL(1) << 25) 625 #define SCTLR_EL1_SPAN (UL(1) << 23) 626 #define SCTLR_EL1_EIS (UL(1) << 22) 627 #define SCTLR_EL1_nTWE (UL(1) << 18) 628 #define SCTLR_EL1_nTWI (UL(1) << 16) 629 #define SCTLR_EL1_EOS (UL(1) << 11) 630 #define SCTLR_EL1_nAA (UL(1) << 6) 631 #define SCTLR_EL1_CP15BEN (UL(1) << 5) 632 #define SCTLR_EL1_SA0 (UL(1) << 4) 633 #define SCTLR_EL1_SA (UL(1) << 3) 634 635 #define SCTLR_EL1_FLAGS (SCTLR_EL1_SPAN | SCTLR_EL1_EIS | SCTLR_EL1_nTWE | \ 636 SCTLR_EL1_nTWI | SCTLR_EL1_EOS | SCTLR_EL1_nAA | SCTLR_EL1_CP15BEN | \ 637 SCTLR_EL1_SA0 | SCTLR_EL1_SA) 638 639 /* PMCR_EL0 Definitions */ 640 #define PMCR_EL0_LC_SHIFT 6 641 #define PMCR_EL0_LC_WIDTH 1 642 #define PMCR_EL0_LC_BIT INPLACE(PMCR_EL0_LC, 1) 643 644 #define PMCR_EL0_RES1 PMCR_EL0_LC_BIT 645 646 647 /* MDSCR_EL1 Definitions */ 648 #define MDSCR_EL1_TDCC_SHIFT 12 649 #define MDSCR_EL1_TDCC_WIDTH 1 650 #define MDSCR_EL1_TDCC_BIT INPLACE(MDSCR_EL1_TDCC, 1) 651 652 /* SCTLR register definitions */ 653 #define SCTLR_EL2_RES1 ((UL(1) << 22) /* TODO: ARMv8.5-CSEH, otherwise RES1 */ | \ 654 (1U << 11) /* TODO: ARMv8.5-CSEH, otherwise RES1 */) 655 656 #define SCTLR_EL2_M (UL(1) << 0) 657 #define SCTLR_EL2_C (UL(1) << 2) 658 #define SCTLR_EL2_SA (UL(1) << 3) 659 #define SCTLR_EL2_SA0 (UL(1) << 4) 660 #define SCTLR_EL2_SED (UL(1) << 8) 661 /* TODO: ARMv8.5-CSEH, otherwise RES1 */ 662 /* #define SCTLR_EL2_EOS (UL(1) << 11) */ 663 #define SCTLR_EL2_I (UL(1) << 12) 664 #define SCTLR_EL2_DZE (UL(1) << 14) 665 #define SCTLR_EL2_UCT (UL(1) << 15) 666 #define SCTLR_EL2_NTWI (UL(1) << 16) 667 #define SCTLR_EL2_NTWE (UL(1) << 18) 668 #define SCTLR_EL2_WXN (UL(1) << 19) 669 #define SCTLR_EL2_TSCXT (UL(1) << 20) 670 /* TODO: ARMv8.5-CSEH, otherwise RES1 */ 671 /* #define SCTLR_EL2_EIS (UL(1) << 22) */ 672 #define SCTLR_EL2_SPAN (UL(1) << 23) 673 #define SCTLR_EL2_UCI (UL(1) << 26) 674 #define SCTLR_EL2_NTLSMD (UL(1) << 28) 675 #define SCTLR_EL2_LSMAOE (UL(1) << 29) 676 /* HCR_EL2.E2H == 0b1 and HCR_EL2.TGE == 0b1 */ 677 #define SECURE_SCTLR_EL2_RES1 ((UL(1) << 22) /* TODO: ARMv8.5-CSEH, otherwise RES1 */ | \ 678 (UL(1) << 11) /* TODO: ARMv8.5-CSEH, otherwise RES1 */) 679 680 #define SCTLR_EL2_INIT (/* SCTLR_EL2_M = 0 (MMU disabled) */ \ 681 /* SCTLR_EL2_A = 0 (No alignment checks) */ \ 682 SCTLR_EL2_C /* Data accesses are cacheable 683 * as per translation tables */ | \ 684 SCTLR_EL2_SA /* SP aligned at EL2 */ | \ 685 SCTLR_EL2_SA0 /* SP Alignment check enable for EL0 */ \ 686 /* SCTLR_EL2_CP15BEN = 0 (EL0 using AArch32: 687 * EL0 execution of the CP15DMB, CP15DSB, and 688 * CP15ISB instructions is UNDEFINED. */ \ 689 /* SCTLR_EL2_NAA = 0 (unaligned MA fault at EL2 and EL0) */ \ 690 /* SCTLR_EL2_ITD = 0 (A32 Only) */ | \ 691 SCTLR_EL2_SED /* A32 Only, RES1 for non-A32 systems */ \ 692 /* SCTLR_EL2_EOS TODO: ARMv8.5-CSEH, otherwise RES1 */ | \ 693 SCTLR_EL2_I /* I$ is ON for EL2 and EL0 */ | \ 694 SCTLR_EL2_DZE /* Do not trap DC ZVA */ | \ 695 SCTLR_EL2_UCT /* Allow EL0 access to CTR_EL0 */ | \ 696 SCTLR_EL2_NTWI /* Don't trap WFI from EL0 to EL2 */ | \ 697 SCTLR_EL2_NTWE /* Don't trap WFE from EL0 to EL2 */ | \ 698 SCTLR_EL2_WXN /* W implies XN */ | \ 699 SCTLR_EL2_TSCXT /* Trap EL0 accesss to SCXTNUM_EL0 */ \ 700 /* SCTLR_EL2_EIS EL2 exception is context 701 * synchronizing 702 * TODO: ARMv8.5-CSEH, otherwise RES1 */ \ 703 /* SCTLR_EL2_SPAN = 0 (Set PSTATE.PAN = 1 on 704 * exceptions to EL2)) */ | \ 705 SCTLR_EL2_UCI /* Allow cache maintenance 706 * instructions at EL0 */ | \ 707 SCTLR_EL2_NTLSMD /* A32/T32 only */ | \ 708 SCTLR_EL2_LSMAOE /* A32/T32 only */ | \ 709 SECURE_SCTLR_EL2_RES1) 710 711 #define SCTLR_EL2_RUNTIME (SCTLR_EL2_INIT| \ 712 SCTLR_EL2_M /* MMU enabled */) 713 714 /* CPTR_EL2 definitions */ 715 #define CPTR_EL2_RES1 ((UL(1) << 13) | (UL(1) << 12) | (UL(1) << 9) | 0xff) 716 #define CPTR_EL2_FPEN (UL(1) << 20) 717 #define CPTR_EL2_TTA (UL(1) << 28) 718 #define CPTR_EL2_TAM (UL(1) << 30) 719 #define CPTR_EL2_FPEN_SHIFT 20 720 #define CPTR_EL2_FPEN_MASK 0x3 721 #define CPTR_EL2_FPEN_TRAP_ALL_00 0x0 722 #define CPTR_EL2_FPEN_TRAP_TGE_01 0x1 723 #define CPTR_EL2_FPEN_TRAP_ALL_10 0x2 724 #define CPTR_EL2_FPEN_NO_TRAP_11 0x3 725 #define CPTR_EL2_ZEN_SHIFT UL(16) 726 #define CPTR_EL2_ZEN_MASK UL(0x3) 727 #define CPTR_EL2_ZEN_TRAP_ALL_00 UL(0x0) 728 #define CPTR_EL2_ZEN_NO_TRAP_11 UL(0x3) 729 /* Trap all FPU/SVE accesses */ 730 #define CPTR_EL2_INIT ((CPTR_EL2_ZEN_TRAP_ALL_00 << \ 731 CPTR_EL2_ZEN_SHIFT) | \ 732 (CPTR_EL2_FPEN_TRAP_ALL_00 << CPTR_EL2_FPEN_SHIFT) | \ 733 CPTR_EL2_TTA /* trap trace access */ | \ 734 CPTR_EL2_TAM /* trap AMU access */ | \ 735 CPTR_EL2_RES1) 736 737 /* MDCR_EL2 definitions */ 738 #define MDCR_EL2_HLP (U(1) << 26) 739 #define MDCR_EL2_HCCD (U(1) << 23) 740 #define MDCR_EL2_TTRF (U(1) << 19) 741 #define MDCR_EL2_HPMD (U(1) << 17) 742 #define MDCR_EL2_TPMS (U(1) << 14) 743 #define MDCR_EL2_E2PB(x) ((x) << 12) 744 #define MDCR_EL2_E2PB_EL1 U(0x3) 745 #define MDCR_EL2_TDRA_BIT (U(1) << 11) 746 #define MDCR_EL2_TDOSA_BIT (U(1) << 10) 747 #define MDCR_EL2_TDA_BIT (U(1) << 9) 748 #define MDCR_EL2_TDE_BIT (U(1) << 8) 749 #define MDCR_EL2_HPME_BIT (U(1) << 7) 750 #define MDCR_EL2_TPM_BIT (U(1) << 6) 751 #define MDCR_EL2_TPMCR_BIT (U(1) << 5) 752 #define MDCR_EL2_INIT (MDCR_EL2_TPMCR_BIT \ 753 | MDCR_EL2_TPM_BIT \ 754 | MDCR_EL2_TDA_BIT) 755 756 /* MPIDR definitions */ 757 #define MPIDR_EL1_AFF_MASK 0xFF 758 #define MPIDR_EL1_AFF0_SHIFT 0 759 #define MPIDR_EL1_AFF1_SHIFT 8 760 #define MPIDR_EL1_AFF2_SHIFT 16 761 #define MPIDR_EL1_AFF3_SHIFT 32 762 #define MPIDR_EL1_MT_MASK (UL(1) << 24) 763 #define MPIDR_EL1_AFFINITY_BITS 8 764 765 #define MPIDR_EL1_AFF0 INPLACE(MPIDR_EL1_AFF0, MPIDR_EL1_AFF_MASK) 766 #define MPIDR_EL1_AFF1 INPLACE(MPIDR_EL1_AFF1, MPIDR_EL1_AFF_MASK) 767 #define MPIDR_EL1_AFF2 INPLACE(MPIDR_EL1_AFF2, MPIDR_EL1_AFF_MASK) 768 #define MPIDR_EL1_AFF3 INPLACE(MPIDR_EL1_AFF3, MPIDR_EL1_AFF_MASK) 769 770 /* 771 * RmiRecMpidr type definitions. 772 * 773 * 'MPIDR_EL2_AFF<n>_VAL_SHIFT' constants specify the right shift 774 * for affinity field <n> that gives the field's actual value. 775 * 776 * Aff0[3:0] - Affinity level 0 777 * For compatibility with GICv3 only Aff0[3:0] field is used, 778 * and Aff0[7:4] of a REC MPIDR value is RES0. 779 */ 780 #define MPIDR_EL2_AFF0_SHIFT 0 781 #define MPIDR_EL2_AFF0_WIDTH 4 782 #define MPIDR_EL2_AFF0_VAL_SHIFT 0 783 784 /* Aff1[15:8] - Affinity level 1 */ 785 #define MPIDR_EL2_AFF1_SHIFT 8 786 #define MPIDR_EL2_AFF1_WIDTH 8 787 #define MPIDR_EL2_AFF1_VAL_SHIFT 4 788 789 /* Aff2[23:16] - Affinity level 2 */ 790 #define MPIDR_EL2_AFF2_SHIFT 16 791 #define MPIDR_EL2_AFF2_WIDTH 8 792 #define MPIDR_EL2_AFF2_VAL_SHIFT 4 793 794 /* Aff3[39:32] - Affinity level 3 */ 795 #define MPIDR_EL2_AFF3_SHIFT 32 796 #define MPIDR_EL2_AFF3_WIDTH 8 797 #define MPIDR_EL2_AFF3_VAL_SHIFT 12 798 799 /* 800 * Extract the value of Aff<n> register field shifted right 801 * so it can be evaluated directly. 802 */ 803 #define MPIDR_EL2_AFF(n, reg) \ 804 (((reg) & MASK(MPIDR_EL2_AFF##n)) >> MPIDR_EL2_AFF##n##_VAL_SHIFT) 805 806 /* VMPIDR_EL2 bit [31] = RES1 */ 807 #define VMPIDR_EL2_RES1 (UL(1) << 31) 808 809 /* ICC_SRE_EL2 defintions */ 810 #define ICC_SRE_EL2_ENABLE (UL(1) << 3) /* Enable lower EL access to ICC_SRE_EL1 */ 811 #define ICC_SRE_EL2_DIB (UL(1) << 2) /* Disable IRQ bypass */ 812 #define ICC_SRE_EL2_DFB (UL(1) << 1) /* Disable FIQ bypass */ 813 #define ICC_SRE_EL2_SRE (UL(1) << 0) /* Enable sysreg access */ 814 815 #define ICC_SRE_EL2_INIT (ICC_SRE_EL2_ENABLE | ICC_SRE_EL2_DIB | \ 816 ICC_SRE_EL2_DFB | ICC_SRE_EL2_SRE) 817 818 /* MPAM definitions */ 819 #define MPAM2_EL2_INIT 0x0 820 #define MPAMHCR_EL2_INIT 0x0 821 822 #define PMSCR_EL2_INIT 0x0 823 824 #define SYSREG_ESR(op0, op1, crn, crm, op2) \ 825 (((op0) << ESR_EL2_SYSREG_TRAP_OP0_SHIFT) | \ 826 ((op1) << ESR_EL2_SYSREG_TRAP_OP1_SHIFT) | \ 827 ((crn) << ESR_EL2_SYSREG_TRAP_CRN_SHIFT) | \ 828 ((crm) << ESR_EL2_SYSREG_TRAP_CRM_SHIFT) | \ 829 ((op2) << ESR_EL2_SYSREG_TRAP_OP2_SHIFT)) 830 831 #define ESR_EL2_SYSREG_MASK SYSREG_ESR(3, 7, 15, 15, 7) 832 833 #define ESR_EL2_SYSREG_ID_MASK SYSREG_ESR(3, 7, 15, 0, 0) 834 #define ESR_EL2_SYSREG_ID SYSREG_ESR(3, 0, 0, 0, 0) 835 836 #define ESR_EL2_SYSREG_ID_AA64PFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 0) 837 #define ESR_EL2_SYSREG_ID_AA64PFR1_EL1 SYSREG_ESR(3, 0, 0, 4, 1) 838 #define ESR_EL2_SYSREG_ID_AA64ZFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 4) 839 840 #define ESR_EL2_SYSREG_ID_AA64DFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 0) 841 #define ESR_EL2_SYSREG_ID_AA64DFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 1) 842 843 #define ESR_EL2_SYSREG_ID_AA64AFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 4) 844 #define ESR_EL2_SYSREG_ID_AA64AFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 5) 845 846 #define ESR_EL2_SYSREG_ID_AA64ISAR0_EL1 SYSREG_ESR(3, 0, 0, 6, 0) 847 #define ESR_EL2_SYSREG_ID_AA64ISAR1_EL1 SYSREG_ESR(3, 0, 0, 6, 1) 848 849 #define ESR_EL2_SYSREG_ID_AA64MMFR0_EL1 SYSREG_ESR(3, 0, 0, 7, 0) 850 #define ESR_EL2_SYSREG_ID_AA64MMFR1_EL1 SYSREG_ESR(3, 0, 0, 7, 1) 851 #define ESR_EL2_SYSREG_ID_AA64MMFR2_EL1 SYSREG_ESR(3, 0, 0, 7, 2) 852 853 #define ESR_EL2_SYSREG_ID_AA64ISAR1_GPI_SHIFT 28 854 #define ESR_EL2_SYSREG_ID_AA64ISAR1_GPA_SHIFT 24 855 #define ESR_EL2_SYSREG_ID_AA64ISAR1_API_SHIFT 8 856 #define ESR_EL2_SYSREG_ID_AA64ISAR1_APA_SHIFT 4 857 858 #define ESR_EL2_SYSREG_TIMERS_MASK SYSREG_ESR(3, 3, 15, 12, 0) 859 #define ESR_EL2_SYSREG_TIMERS SYSREG_ESR(3, 3, 14, 0, 0) 860 861 #define ESR_EL2_SYSREG_TIMER_CNTP_TVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 0) 862 #define ESR_EL2_SYSREG_TIMER_CNTP_CTL_EL0 SYSREG_ESR(3, 3, 14, 2, 1) 863 #define ESR_EL2_SYSREG_TIMER_CNTP_CVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 2) 864 #define ESR_EL2_SYSREG_TIMER_CNTV_TVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 0) 865 #define ESR_EL2_SYSREG_TIMER_CNTV_CTL_EL0 SYSREG_ESR(3, 3, 14, 3, 1) 866 #define ESR_EL2_SYSREG_TIMER_CNTV_CVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 2) 867 868 #define ESR_EL2_SYSREG_ICC_PMR_EL1 SYSREG_ESR(3, 0, 4, 6, 0) 869 870 /* 871 * GIC system registers encoding mask for registers from 872 * ICC_IAR0_EL1(3, 0, 12, 8, 0) to ICC_IGRPEN1_EL1(3, 0, 12, 12, 7). 873 */ 874 #define ESR_EL2_SYSREG_ICC_EL1_MASK SYSREG_ESR(3, 3, 15, 8, 0) 875 #define ESR_EL2_SYSREG_ICC_EL1 SYSREG_ESR(3, 0, 12, 8, 0) 876 877 #define ESR_EL2_SYSREG_ICC_DIR SYSREG_ESR(3, 0, 12, 11, 1) 878 #define ESR_EL2_SYSREG_ICC_SGI1R_EL1 SYSREG_ESR(3, 0, 12, 11, 5) 879 #define ESR_EL2_SYSREG_ICC_SGI0R_EL1 SYSREG_ESR(3, 0, 12, 11, 7) 880 881 #define ESR_EL2_SYSREG_DIRECTION (UL(1) << 0) 882 #define ESR_EL2_SYSREG_IS_WRITE(esr) (!((esr) & ESR_EL2_SYSREG_DIRECTION)) 883 884 #define ESR_IL(esr) ((esr) & ESR_EL2_IL_MASK) 885 #define ESR_ISS(esr) ((esr) & ESR_EL2_ISS_MASK) 886 887 #define ESR_EL2_SYSREG_ISS_RT(esr) \ 888 ((ESR_ISS(esr) & ESR_EL2_SYSREG_TRAP_RT_MASK) >> ESR_EL2_SYSREG_TRAP_RT_SHIFT) 889 890 #define ICC_HPPIR1_EL1_INTID_SHIFT 0 891 #define ICC_HPPIR1_EL1_INTID_WIDTH 24 892 #define ICC_HPPIR1_EL1_INTID_MASK MASK(ICC_HPPIR1_EL1_INTID) 893 894 #define CNTHCTL_EL2_EL0PCTEN (UL(1) << UL(0)) 895 #define CNTHCTL_EL2_EL0VCTEN (UL(1) << UL(1)) 896 #define CNTHCTL_EL2_EL1PCTEN (UL(1) << 10) 897 #define CNTHCTL_EL2_EL1PTEN (UL(1) << 11) 898 #define CNTHCTL_EL2_EL1TVT (UL(1) << 13) 899 #define CNTHCTL_EL2_EL1TVCT (UL(1) << 14) 900 #define CNTHCTL_EL2_CNTVMASK (UL(1) << 18) 901 #define CNTHCTL_EL2_CNTPMASK (UL(1) << 19) 902 903 #define CNTHCTL_EL2_INIT (CNTHCTL_EL2_EL0VCTEN | CNTHCTL_EL2_EL0PCTEN) 904 905 #define CNTHCTL_EL2_NO_TRAPS (CNTHCTL_EL2_EL1PCTEN | \ 906 CNTHCTL_EL2_EL1PTEN) 907 908 #define CNTx_CTL_ENABLE (UL(1) << 0) 909 #define CNTx_CTL_IMASK (UL(1) << 1) 910 #define CNTx_CTL_ISTATUS (UL(1) << 2) 911 912 /******************************************************************************* 913 * Definitions of register offsets, fields and macros for CPU system 914 * instructions. 915 ******************************************************************************/ 916 917 #define TLBI_ADDR_SHIFT U(12) 918 #define TLBI_ADDR_MASK U(0x0FFFFFFFFFFF) 919 #define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK) 920 921 /* ID_AA64MMFR2_EL1 definitions */ 922 #define ID_AA64MMFR2_EL1_ST_SHIFT U(28) 923 #define ID_AA64MMFR2_EL1_ST_MASK ULL(0xf) 924 925 #define ID_AA64MMFR2_EL1_CNP_SHIFT U(0) 926 #define ID_AA64MMFR2_EL1_CNP_MASK ULL(0xf) 927 928 /* Custom defined values to indicate the vector offset to exception handlers */ 929 #define ARM_EXCEPTION_SYNC_LEL 0 930 #define ARM_EXCEPTION_IRQ_LEL 1 931 #define ARM_EXCEPTION_FIQ_LEL 2 932 #define ARM_EXCEPTION_SERROR_LEL 3 933 934 #define VBAR_CEL_SP_EL0_OFFSET 0x0 935 #define VBAR_CEL_SP_ELx_OFFSET 0x200 936 #define VBAR_LEL_AA64_OFFSET 0x400 937 #define VBAR_LEL_AA32_OFFSET 0x600 938 939 #endif /* ARCH_H */ 940