1 /* 2 * Copyright (c) 2019-2025, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef ARCH_FEATURES_H 8 #define ARCH_FEATURES_H 9 10 #include <stdbool.h> 11 12 #include <arch_helpers.h> 13 #include <common/feat_detect.h> 14 15 #define ISOLATE_FIELD(reg, feat, mask) \ 16 ((unsigned int)(((reg) >> (feat)) & mask)) 17 18 #define CREATE_FEATURE_SUPPORTED(name, read_func, guard) \ 19 __attribute__((always_inline)) \ 20 static inline bool is_ ## name ## _supported(void) \ 21 { \ 22 if ((guard) == FEAT_STATE_DISABLED) { \ 23 return false; \ 24 } \ 25 if ((guard) == FEAT_STATE_ALWAYS) { \ 26 return true; \ 27 } \ 28 return read_func(); \ 29 } 30 31 #define CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \ 32 __attribute__((always_inline)) \ 33 static inline bool is_ ## name ## _present(void) \ 34 { \ 35 return (ISOLATE_FIELD(read_ ## idreg(), idfield, mask) >= idval) \ 36 ? true : false; \ 37 } 38 39 #define CREATE_FEATURE_FUNCS(name, idreg, idfield, mask, idval, guard) \ 40 CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \ 41 CREATE_FEATURE_SUPPORTED(name, is_ ## name ## _present, guard) 42 43 44 /* +----------------------------+ 45 * | Features supported | 46 * +----------------------------+ 47 * | GENTIMER | 48 * +----------------------------+ 49 * | FEAT_PAN | 50 * +----------------------------+ 51 * | FEAT_VHE | 52 * +----------------------------+ 53 * | FEAT_TTCNP | 54 * +----------------------------+ 55 * | FEAT_UAO | 56 * +----------------------------+ 57 * | FEAT_PACQARMA3 | 58 * +----------------------------+ 59 * | FEAT_PAUTH | 60 * +----------------------------+ 61 * | FEAT_TTST | 62 * +----------------------------+ 63 * | FEAT_BTI | 64 * +----------------------------+ 65 * | FEAT_MTE2 | 66 * +----------------------------+ 67 * | FEAT_SSBS | 68 * +----------------------------+ 69 * | FEAT_NMI | 70 * +----------------------------+ 71 * | FEAT_GCS | 72 * +----------------------------+ 73 * | FEAT_EBEP | 74 * +----------------------------+ 75 * | FEAT_SEBEP | 76 * +----------------------------+ 77 * | FEAT_SEL2 | 78 * +----------------------------+ 79 * | FEAT_TWED | 80 * +----------------------------+ 81 * | FEAT_FGT | 82 * +----------------------------+ 83 * | FEAT_EC/ECV2 | 84 * +----------------------------+ 85 * | FEAT_RNG | 86 * +----------------------------+ 87 * | FEAT_TCR2 | 88 * +----------------------------+ 89 * | FEAT_S2POE | 90 * +----------------------------+ 91 * | FEAT_S1POE | 92 * +----------------------------+ 93 * | FEAT_S2PIE | 94 * +----------------------------+ 95 * | FEAT_S1PIE | 96 * +----------------------------+ 97 * | FEAT_AMU/AMUV1P1 | 98 * +----------------------------+ 99 * | FEAT_MPAM | 100 * +----------------------------+ 101 * | FEAT_HCX | 102 * +----------------------------+ 103 * | FEAT_RNG_TRAP | 104 * +----------------------------+ 105 * | FEAT_RME | 106 * +----------------------------+ 107 * | FEAT_SB | 108 * +----------------------------+ 109 * | FEAT_CSV2/CSV3 | 110 * +----------------------------+ 111 * | FEAT_SPE | 112 * +----------------------------+ 113 * | FEAT_SVE | 114 * +----------------------------+ 115 * | FEAT_RAS | 116 * +----------------------------+ 117 * | FEAT_DIT | 118 * +----------------------------+ 119 * | FEAT_SYS_REG_TRACE | 120 * +----------------------------+ 121 * | FEAT_TRF | 122 * +----------------------------+ 123 * | FEAT_NV/NV2 | 124 * +----------------------------+ 125 * | FEAT_BRBE | 126 * +----------------------------+ 127 * | FEAT_TRBE | 128 * +----------------------------+ 129 * | FEAT_SME/SME2 | 130 * +----------------------------+ 131 * | FEAT_PMUV3 | 132 * +----------------------------+ 133 * | FEAT_MTPMU | 134 * +----------------------------+ 135 * | FEAT_FGT2 | 136 * +----------------------------+ 137 * | FEAT_THE | 138 * +----------------------------+ 139 * | FEAT_SCTLR2 | 140 * +----------------------------+ 141 * | FEAT_D128 | 142 * +----------------------------+ 143 * | FEAT_LS64_ACCDATA | 144 * +----------------------------+ 145 * | FEAT_FPMR | 146 * +----------------------------+ 147 * | FEAT_MOPS | 148 * +----------------------------+ 149 * | FEAT_PAUTH_LR | 150 * +----------------------------+ 151 * | FEAT_FGWTE3 | 152 * +----------------------------+ 153 * | FEAT_MPAM_PE_BW_CTRL | 154 * +----------------------------+ 155 */ 156 157 __attribute__((always_inline)) 158 static inline bool is_armv7_gentimer_present(void) 159 { 160 /* The Generic Timer is always present in an ARMv8-A implementation */ 161 return true; 162 } 163 164 /* FEAT_PAN: Privileged access never */ 165 CREATE_FEATURE_FUNCS(feat_pan, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_PAN_SHIFT, 166 ID_AA64MMFR1_EL1_PAN_MASK, 1U, ENABLE_FEAT_PAN) 167 168 /* FEAT_VHE: Virtualization Host Extensions */ 169 CREATE_FEATURE_FUNCS(feat_vhe, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_VHE_SHIFT, 170 ID_AA64MMFR1_EL1_VHE_MASK, 1U, ENABLE_FEAT_VHE) 171 172 /* FEAT_TTCNP: Translation table common not private */ 173 CREATE_FEATURE_PRESENT(feat_ttcnp, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_CNP_SHIFT, 174 ID_AA64MMFR2_EL1_CNP_MASK, 1U) 175 176 /* FEAT_UAO: User access override */ 177 CREATE_FEATURE_PRESENT(feat_uao, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_UAO_SHIFT, 178 ID_AA64MMFR2_EL1_UAO_MASK, 1U) 179 180 /* If any of the fields is not zero, QARMA3 algorithm is present */ 181 CREATE_FEATURE_PRESENT(feat_pacqarma3, id_aa64isar2_el1, 0, 182 ((ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_SHIFT) | 183 (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_SHIFT)), 1U) 184 185 /* FEAT_PAUTH: Pointer Authentication */ 186 __attribute__((always_inline)) 187 static inline bool is_feat_pauth_present(void) 188 { 189 uint64_t mask_id_aa64isar1 = 190 (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) | 191 (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) | 192 (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) | 193 (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT); 194 195 /* 196 * If any of the fields is not zero or QARMA3 is present, 197 * PAuth is present 198 */ 199 return ((read_id_aa64isar1_el1() & mask_id_aa64isar1) != 0U || 200 is_feat_pacqarma3_present()); 201 } 202 CREATE_FEATURE_SUPPORTED(feat_pauth, is_feat_pauth_present, ENABLE_PAUTH) 203 CREATE_FEATURE_SUPPORTED(ctx_pauth, is_feat_pauth_present, CTX_INCLUDE_PAUTH_REGS) 204 205 /* 206 * FEAT_PAUTH_LR 207 * This feature has a non-standard discovery method so define this function 208 * manually then call use the CREATE_FEATURE_SUPPORTED macro with it. This 209 * feature is enabled with ENABLE_PAUTH when present. 210 */ 211 __attribute__((always_inline)) 212 static inline bool is_feat_pauth_lr_present(void) 213 { 214 /* 215 * FEAT_PAUTH_LR support is indicated by up to 3 fields, if one or more 216 * of these is 0b0110 then the feature is present. 217 * 1) id_aa64isr1_el1.api 218 * 2) id_aa64isr1_el1.apa 219 * 3) id_aa64isr2_el1.apa3 220 */ 221 if (ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_API_SHIFT, ID_AA64ISAR1_API_MASK) == 0b0110) { 222 return true; 223 } 224 if (ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_APA_SHIFT, ID_AA64ISAR1_APA_MASK) == 0b0110) { 225 return true; 226 } 227 if (ISOLATE_FIELD(read_id_aa64isar2_el1(), ID_AA64ISAR2_APA3_SHIFT, ID_AA64ISAR2_APA3_MASK) == 0b0110) { 228 return true; 229 } 230 return false; 231 } 232 CREATE_FEATURE_SUPPORTED(feat_pauth_lr, is_feat_pauth_lr_present, ENABLE_FEAT_PAUTH_LR) 233 234 /* FEAT_TTST: Small translation tables */ 235 CREATE_FEATURE_PRESENT(feat_ttst, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_ST_SHIFT, 236 ID_AA64MMFR2_EL1_ST_MASK, 1U) 237 238 /* FEAT_BTI: Branch target identification */ 239 CREATE_FEATURE_FUNCS(feat_bti, id_aa64pfr1_el1, ID_AA64PFR1_EL1_BT_SHIFT, 240 ID_AA64PFR1_EL1_BT_MASK, BTI_IMPLEMENTED, ENABLE_BTI) 241 242 /* FEAT_MTE2: Memory tagging extension */ 243 CREATE_FEATURE_FUNCS(feat_mte2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_MTE_SHIFT, 244 ID_AA64PFR1_EL1_MTE_MASK, MTE_IMPLEMENTED_ELX, ENABLE_FEAT_MTE2) 245 246 /* FEAT_SSBS: Speculative store bypass safe */ 247 CREATE_FEATURE_PRESENT(feat_ssbs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SSBS_SHIFT, 248 ID_AA64PFR1_EL1_SSBS_MASK, 1U) 249 250 /* FEAT_NMI: Non-maskable interrupts */ 251 CREATE_FEATURE_PRESENT(feat_nmi, id_aa64pfr1_el1, ID_AA64PFR1_EL1_NMI_SHIFT, 252 ID_AA64PFR1_EL1_NMI_MASK, NMI_IMPLEMENTED) 253 254 /* FEAT_EBEP */ 255 CREATE_FEATURE_PRESENT(feat_ebep, id_aa64dfr1_el1, ID_AA64DFR1_EBEP_SHIFT, 256 ID_AA64DFR1_EBEP_MASK, EBEP_IMPLEMENTED) 257 258 /* FEAT_SEBEP */ 259 CREATE_FEATURE_PRESENT(feat_sebep, id_aa64dfr0_el1, ID_AA64DFR0_SEBEP_SHIFT, 260 ID_AA64DFR0_SEBEP_MASK, SEBEP_IMPLEMENTED) 261 262 /* FEAT_SEL2: Secure EL2 */ 263 CREATE_FEATURE_FUNCS(feat_sel2, id_aa64pfr0_el1, ID_AA64PFR0_SEL2_SHIFT, 264 ID_AA64PFR0_SEL2_MASK, 1U, ENABLE_FEAT_SEL2) 265 266 /* FEAT_TWED: Delayed trapping of WFE */ 267 CREATE_FEATURE_FUNCS(feat_twed, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_TWED_SHIFT, 268 ID_AA64MMFR1_EL1_TWED_MASK, 1U, ENABLE_FEAT_TWED) 269 270 /* FEAT_FGT: Fine-grained traps */ 271 CREATE_FEATURE_FUNCS(feat_fgt, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT, 272 ID_AA64MMFR0_EL1_FGT_MASK, 1U, ENABLE_FEAT_FGT) 273 274 /* FEAT_FGT2: Fine-grained traps extended */ 275 CREATE_FEATURE_FUNCS(feat_fgt2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT, 276 ID_AA64MMFR0_EL1_FGT_MASK, FGT2_IMPLEMENTED, ENABLE_FEAT_FGT2) 277 278 /* FEAT_FGWTE3: Fine-grained write traps EL3 */ 279 CREATE_FEATURE_FUNCS(feat_fgwte3, id_aa64mmfr4_el1, ID_AA64MMFR4_EL1_FGWTE3_SHIFT, 280 ID_AA64MMFR4_EL1_FGWTE3_MASK, FGWTE3_IMPLEMENTED, 281 ENABLE_FEAT_FGWTE3) 282 283 /* FEAT_ECV: Enhanced Counter Virtualization */ 284 CREATE_FEATURE_FUNCS(feat_ecv, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT, 285 ID_AA64MMFR0_EL1_ECV_MASK, 1U, ENABLE_FEAT_ECV) 286 CREATE_FEATURE_FUNCS(feat_ecv_v2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT, 287 ID_AA64MMFR0_EL1_ECV_MASK, ID_AA64MMFR0_EL1_ECV_SELF_SYNCH, ENABLE_FEAT_ECV) 288 289 /* FEAT_RNG: Random number generator */ 290 CREATE_FEATURE_FUNCS(feat_rng, id_aa64isar0_el1, ID_AA64ISAR0_RNDR_SHIFT, 291 ID_AA64ISAR0_RNDR_MASK, 1U, ENABLE_FEAT_RNG) 292 293 /* FEAT_TCR2: Support TCR2_ELx regs */ 294 CREATE_FEATURE_FUNCS(feat_tcr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_TCRX_SHIFT, 295 ID_AA64MMFR3_EL1_TCRX_MASK, 1U, ENABLE_FEAT_TCR2) 296 297 /* FEAT_S2POE */ 298 CREATE_FEATURE_FUNCS(feat_s2poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2POE_SHIFT, 299 ID_AA64MMFR3_EL1_S2POE_MASK, 1U, ENABLE_FEAT_S2POE) 300 301 /* FEAT_S1POE */ 302 CREATE_FEATURE_FUNCS(feat_s1poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1POE_SHIFT, 303 ID_AA64MMFR3_EL1_S1POE_MASK, 1U, ENABLE_FEAT_S1POE) 304 305 __attribute__((always_inline)) 306 static inline bool is_feat_sxpoe_supported(void) 307 { 308 return is_feat_s1poe_supported() || is_feat_s2poe_supported(); 309 } 310 311 /* FEAT_S2PIE */ 312 CREATE_FEATURE_FUNCS(feat_s2pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2PIE_SHIFT, 313 ID_AA64MMFR3_EL1_S2PIE_MASK, 1U, ENABLE_FEAT_S2PIE) 314 315 /* FEAT_S1PIE */ 316 CREATE_FEATURE_FUNCS(feat_s1pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1PIE_SHIFT, 317 ID_AA64MMFR3_EL1_S1PIE_MASK, 1U, ENABLE_FEAT_S1PIE) 318 319 /* FEAT_THE: Translation Hardening Extension */ 320 CREATE_FEATURE_FUNCS(feat_the, id_aa64pfr1_el1, ID_AA64PFR1_EL1_THE_SHIFT, 321 ID_AA64PFR1_EL1_THE_MASK, THE_IMPLEMENTED, ENABLE_FEAT_THE) 322 323 /* FEAT_SCTLR2 */ 324 CREATE_FEATURE_FUNCS(feat_sctlr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_SCTLR2_SHIFT, 325 ID_AA64MMFR3_EL1_SCTLR2_MASK, SCTLR2_IMPLEMENTED, 326 ENABLE_FEAT_SCTLR2) 327 328 /* FEAT_D128 */ 329 CREATE_FEATURE_FUNCS(feat_d128, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_D128_SHIFT, 330 ID_AA64MMFR3_EL1_D128_MASK, D128_IMPLEMENTED, 331 ENABLE_FEAT_D128) 332 333 /* FEAT_FPMR */ 334 CREATE_FEATURE_FUNCS(feat_fpmr, id_aa64pfr2_el1, ID_AA64PFR2_EL1_FPMR_SHIFT, 335 ID_AA64PFR2_EL1_FPMR_MASK, FPMR_IMPLEMENTED, 336 ENABLE_FEAT_FPMR) 337 /* FEAT_MOPS */ 338 CREATE_FEATURE_FUNCS(feat_mops, id_aa64isar2_el1, ID_AA64ISAR2_EL1_MOPS_SHIFT, 339 ID_AA64ISAR2_EL1_MOPS_MASK, MOPS_IMPLEMENTED, 340 ENABLE_FEAT_MOPS) 341 342 __attribute__((always_inline)) 343 static inline bool is_feat_sxpie_supported(void) 344 { 345 return is_feat_s1pie_supported() || is_feat_s2pie_supported(); 346 } 347 348 /* FEAT_GCS: Guarded Control Stack */ 349 CREATE_FEATURE_FUNCS(feat_gcs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_GCS_SHIFT, 350 ID_AA64PFR1_EL1_GCS_MASK, 1U, ENABLE_FEAT_GCS) 351 352 /* FEAT_AMU: Activity Monitors Extension */ 353 CREATE_FEATURE_FUNCS(feat_amu, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT, 354 ID_AA64PFR0_AMU_MASK, 1U, ENABLE_FEAT_AMU) 355 356 /* Auxiliary counters for FEAT_AMU */ 357 CREATE_FEATURE_FUNCS(feat_amu_aux, amcfgr_el0, AMCFGR_EL0_NCG_SHIFT, 358 AMCFGR_EL0_NCG_MASK, 1U, ENABLE_AMU_AUXILIARY_COUNTERS) 359 360 /* FEAT_AMUV1P1: AMU Extension v1.1 */ 361 CREATE_FEATURE_FUNCS(feat_amuv1p1, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT, 362 ID_AA64PFR0_AMU_MASK, ID_AA64PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1) 363 364 /* 365 * Return MPAM version: 366 * 367 * 0x00: None Armv8.0 or later 368 * 0x01: v0.1 Armv8.4 or later 369 * 0x10: v1.0 Armv8.2 or later 370 * 0x11: v1.1 Armv8.4 or later 371 * 372 */ 373 __attribute__((always_inline)) 374 static inline bool is_feat_mpam_present(void) 375 { 376 unsigned int ret = (unsigned int)((((read_id_aa64pfr0_el1() >> 377 ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) | 378 ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_MPAM_FRAC_SHIFT) 379 & ID_AA64PFR1_MPAM_FRAC_MASK)); 380 return ret; 381 } 382 383 CREATE_FEATURE_SUPPORTED(feat_mpam, is_feat_mpam_present, ENABLE_FEAT_MPAM) 384 385 386 387 /* FEAT_MPAM_PE_BW_CTRL: MPAM PE-side bandwidth controls */ 388 __attribute__((always_inline)) 389 static inline bool is_feat_mpam_pe_bw_ctrl_present(void) 390 { 391 if (is_feat_mpam_present()) { 392 return ((unsigned long long)(read_mpamidr_el1() & 393 MPAMIDR_HAS_BW_CTRL_BIT) != 0U); 394 } 395 return false; 396 } 397 398 CREATE_FEATURE_SUPPORTED(feat_mpam_pe_bw_ctrl, is_feat_mpam_pe_bw_ctrl_present, 399 ENABLE_FEAT_MPAM_PE_BW_CTRL) 400 401 /* 402 * FEAT_DebugV8P9: Debug extension. This function checks the field 3:0 of 403 * ID_AA64DFR0 Aarch64 Debug Feature Register 0 for the version of 404 * Feat_Debug supported. The value of the field determines feature presence 405 * 406 * 0b0110 - Arm v8.0 debug 407 * 0b0111 - Arm v8.0 debug architecture with Virtualization host extensions 408 * 0x1000 - FEAT_Debugv8p2 is supported 409 * 0x1001 - FEAT_Debugv8p4 is supported 410 * 0x1010 - FEAT_Debugv8p8 is supported 411 * 0x1011 - FEAT_Debugv8p9 is supported 412 * 413 */ 414 CREATE_FEATURE_FUNCS(feat_debugv8p9, id_aa64dfr0_el1, ID_AA64DFR0_DEBUGVER_SHIFT, 415 ID_AA64DFR0_DEBUGVER_MASK, DEBUGVER_V8P9_IMPLEMENTED, 416 ENABLE_FEAT_DEBUGV8P9) 417 418 /* FEAT_HCX: Extended Hypervisor Configuration Register */ 419 CREATE_FEATURE_FUNCS(feat_hcx, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_HCX_SHIFT, 420 ID_AA64MMFR1_EL1_HCX_MASK, 1U, ENABLE_FEAT_HCX) 421 422 /* FEAT_RNG_TRAP: Trapping support */ 423 CREATE_FEATURE_FUNCS(feat_rng_trap, id_aa64pfr1_el1, ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT, 424 ID_AA64PFR1_EL1_RNDR_TRAP_MASK, RNG_TRAP_IMPLEMENTED, ENABLE_FEAT_RNG_TRAP) 425 426 /* Return the RME version, zero if not supported. */ 427 CREATE_FEATURE_FUNCS(feat_rme, id_aa64pfr0_el1, ID_AA64PFR0_FEAT_RME_SHIFT, 428 ID_AA64PFR0_FEAT_RME_MASK, 1U, ENABLE_RME) 429 430 /* FEAT_SB: Speculation barrier instruction */ 431 CREATE_FEATURE_PRESENT(feat_sb, id_aa64isar1_el1, ID_AA64ISAR1_SB_SHIFT, 432 ID_AA64ISAR1_SB_MASK, 1U) 433 434 /* FEAT_MEC: Memory Encryption Contexts */ 435 CREATE_FEATURE_FUNCS(feat_mec, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_MEC_SHIFT, 436 ID_AA64MMFR3_EL1_MEC_MASK, 1U, ENABLE_FEAT_MEC) 437 438 /* 439 * FEAT_CSV2: Cache Speculation Variant 2. This checks bit fields[56-59] 440 * of id_aa64pfr0_el1 register and can be used to check for below features: 441 * FEAT_CSV2_2: Cache Speculation Variant CSV2_2. 442 * FEAT_CSV2_3: Cache Speculation Variant CSV2_3. 443 * 0b0000 - Feature FEAT_CSV2 is not implemented. 444 * 0b0001 - Feature FEAT_CSV2 is implemented, but FEAT_CSV2_2 and FEAT_CSV2_3 445 * are not implemented. 446 * 0b0010 - Feature FEAT_CSV2_2 is implemented but FEAT_CSV2_3 is not 447 * implemented. 448 * 0b0011 - Feature FEAT_CSV2_3 is implemented. 449 */ 450 451 CREATE_FEATURE_FUNCS(feat_csv2_2, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT, 452 ID_AA64PFR0_CSV2_MASK, CSV2_2_IMPLEMENTED, ENABLE_FEAT_CSV2_2) 453 CREATE_FEATURE_FUNCS(feat_csv2_3, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT, 454 ID_AA64PFR0_CSV2_MASK, CSV2_3_IMPLEMENTED, ENABLE_FEAT_CSV2_3) 455 456 /* FEAT_SPE: Statistical Profiling Extension */ 457 CREATE_FEATURE_FUNCS(feat_spe, id_aa64dfr0_el1, ID_AA64DFR0_PMS_SHIFT, 458 ID_AA64DFR0_PMS_MASK, 1U, ENABLE_SPE_FOR_NS) 459 460 /* FEAT_SVE: Scalable Vector Extension */ 461 CREATE_FEATURE_FUNCS(feat_sve, id_aa64pfr0_el1, ID_AA64PFR0_SVE_SHIFT, 462 ID_AA64PFR0_SVE_MASK, 1U, ENABLE_SVE_FOR_NS) 463 464 /* FEAT_RAS: Reliability, Accessibility, Serviceability */ 465 CREATE_FEATURE_FUNCS(feat_ras, id_aa64pfr0_el1, ID_AA64PFR0_RAS_SHIFT, 466 ID_AA64PFR0_RAS_MASK, 1U, ENABLE_FEAT_RAS) 467 468 /* FEAT_DIT: Data Independent Timing instructions */ 469 CREATE_FEATURE_FUNCS(feat_dit, id_aa64pfr0_el1, ID_AA64PFR0_DIT_SHIFT, 470 ID_AA64PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT) 471 472 /* FEAT_SYS_REG_TRACE */ 473 CREATE_FEATURE_FUNCS(feat_sys_reg_trace, id_aa64dfr0_el1, ID_AA64DFR0_TRACEVER_SHIFT, 474 ID_AA64DFR0_TRACEVER_MASK, 1U, ENABLE_SYS_REG_TRACE_FOR_NS) 475 476 /* FEAT_TRF: TraceFilter */ 477 CREATE_FEATURE_FUNCS(feat_trf, id_aa64dfr0_el1, ID_AA64DFR0_TRACEFILT_SHIFT, 478 ID_AA64DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS) 479 480 /* FEAT_NV2: Enhanced Nested Virtualization */ 481 CREATE_FEATURE_FUNCS(feat_nv, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_NV_SHIFT, 482 ID_AA64MMFR2_EL1_NV_MASK, 1U, 0U) 483 CREATE_FEATURE_FUNCS(feat_nv2, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_NV_SHIFT, 484 ID_AA64MMFR2_EL1_NV_MASK, NV2_IMPLEMENTED, CTX_INCLUDE_NEVE_REGS) 485 486 /* FEAT_BRBE: Branch Record Buffer Extension */ 487 CREATE_FEATURE_FUNCS(feat_brbe, id_aa64dfr0_el1, ID_AA64DFR0_BRBE_SHIFT, 488 ID_AA64DFR0_BRBE_MASK, 1U, ENABLE_BRBE_FOR_NS) 489 490 /* FEAT_TRBE: Trace Buffer Extension */ 491 CREATE_FEATURE_FUNCS(feat_trbe, id_aa64dfr0_el1, ID_AA64DFR0_TRACEBUFFER_SHIFT, 492 ID_AA64DFR0_TRACEBUFFER_MASK, 1U, ENABLE_TRBE_FOR_NS) 493 494 /* FEAT_SME_FA64: Full A64 Instruction support in streaming SVE mode */ 495 CREATE_FEATURE_PRESENT(feat_sme_fa64, id_aa64smfr0_el1, ID_AA64SMFR0_EL1_SME_FA64_SHIFT, 496 ID_AA64SMFR0_EL1_SME_FA64_MASK, 1U) 497 498 /* FEAT_SMEx: Scalar Matrix Extension */ 499 CREATE_FEATURE_FUNCS(feat_sme, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT, 500 ID_AA64PFR1_EL1_SME_MASK, 1U, ENABLE_SME_FOR_NS) 501 502 CREATE_FEATURE_FUNCS(feat_sme2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT, 503 ID_AA64PFR1_EL1_SME_MASK, SME2_IMPLEMENTED, ENABLE_SME2_FOR_NS) 504 505 /* FEAT_LS64_ACCDATA: */ 506 CREATE_FEATURE_FUNCS(feat_ls64_accdata, id_aa64isar1_el1, ID_AA64ISAR1_LS64_SHIFT, 507 ID_AA64ISAR1_LS64_MASK, LS64_ACCDATA_IMPLEMENTED, 508 ENABLE_FEAT_LS64_ACCDATA) 509 510 /******************************************************************************* 511 * Function to get hardware granularity support 512 ******************************************************************************/ 513 514 __attribute__((always_inline)) 515 static inline bool is_feat_tgran4K_present(void) 516 { 517 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(), 518 ID_AA64MMFR0_EL1_TGRAN4_SHIFT, ID_REG_FIELD_MASK); 519 return (tgranx < 8U); 520 } 521 522 CREATE_FEATURE_PRESENT(feat_tgran16K, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_TGRAN16_SHIFT, 523 ID_AA64MMFR0_EL1_TGRAN16_MASK, TGRAN16_IMPLEMENTED) 524 525 __attribute__((always_inline)) 526 static inline bool is_feat_tgran64K_present(void) 527 { 528 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(), 529 ID_AA64MMFR0_EL1_TGRAN64_SHIFT, ID_REG_FIELD_MASK); 530 return (tgranx < 8U); 531 } 532 533 /* FEAT_PMUV3 */ 534 CREATE_FEATURE_PRESENT(feat_pmuv3, id_aa64dfr0_el1, ID_AA64DFR0_PMUVER_SHIFT, 535 ID_AA64DFR0_PMUVER_MASK, 1U) 536 537 /* FEAT_MTPMU */ 538 __attribute__((always_inline)) 539 static inline bool is_feat_mtpmu_present(void) 540 { 541 unsigned int mtpmu = ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_MTPMU_SHIFT, 542 ID_AA64DFR0_MTPMU_MASK); 543 return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED); 544 } 545 546 CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU) 547 548 /************************************************************************* 549 * Function to identify the presence of FEAT_GCIE (GICv5 CPU interface 550 * extension). 551 ************************************************************************/ 552 CREATE_FEATURE_FUNCS(feat_gcie, id_aa64pfr2_el1, ID_AA64PFR2_EL1_GCIE_SHIFT, 553 ID_AA64PFR2_EL1_GCIE_MASK, 1U, ENABLE_FEAT_GCIE) 554 555 #endif /* ARCH_FEATURES_H */ 556