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 #include <lib/cpus/errata.h> 15 #include <lib/el3_runtime/context_mgmt.h> 16 #include <lib/el3_runtime/cpu_data.h> 17 18 #if ENABLE_RME 19 #define FEAT_ENABLE_ALL_WORLDS \ 20 ((1u << CPU_CONTEXT_SECURE) | \ 21 (1u << CPU_CONTEXT_NS) | \ 22 (1u << CPU_CONTEXT_REALM)) 23 #define FEAT_ENABLE_REALM (1 << CPU_CONTEXT_REALM) 24 #else 25 #define FEAT_ENABLE_ALL_WORLDS \ 26 ((1u << CPU_CONTEXT_SECURE) | \ 27 (1u << CPU_CONTEXT_NS)) 28 #define FEAT_ENABLE_REALM U(0) 29 #endif 30 31 #define FEAT_ENABLE_SECURE (1 << CPU_CONTEXT_SECURE) 32 #define FEAT_ENABLE_NS (1 << CPU_CONTEXT_NS) 33 34 #define ISOLATE_FIELD(reg, feat, mask) \ 35 ((unsigned int)(((reg) >> (feat)) & mask)) 36 37 #define SHOULD_ID_FIELD_DISABLE(guard, enabled_worlds, world) \ 38 (((guard) == 0U) || ((((enabled_worlds) >> (world)) & 1U) == 0U)) 39 40 41 #define CREATE_FEATURE_SUPPORTED(name, read_func, guard) \ 42 __attribute__((always_inline)) \ 43 static inline bool is_ ## name ## _supported(void) \ 44 { \ 45 if ((guard) == FEAT_STATE_DISABLED) { \ 46 return false; \ 47 } \ 48 if ((guard) == FEAT_STATE_ALWAYS) { \ 49 return true; \ 50 } \ 51 return read_func(); \ 52 } 53 54 /* 55 * CREATE_IDREG_UPDATE and CREATE_PERCPU_IDREG_UPDATE are two macros that 56 * generate the update_feat_abc_idreg_field() function based on how its 57 * corresponding ID register is cached. 58 * The function disables ID register fields related to a feature if the build 59 * flag for that feature is 0 or if the feature should be disabled for that 60 * world. If the particular field has to be disabled, its field in the cached 61 * ID register is set to 0. 62 * 63 * Note: For most ID register fields, a value of 0 represents 64 * the Unimplemented state, and hence we use this macro to show features 65 * disabled in EL3 as unimplemented to lower ELs. However, certain feature's 66 * ID Register fields (like ID_AA64MMFR4_EL1.E2H0) deviate from this convention, 67 * where 0 does not represent Unimplemented. 68 * For those features, a custom update_feat_abc_idreg_field() 69 * needs to be created. This custom function should set the field to the 70 * feature's unimplemented state value if the feature is disabled in EL3. 71 * 72 * For example: 73 * 74 * __attribute__((always_inline)) 75 * static inline void update_feat_abc_idreg_field(size_t security_state) 76 * { 77 * if (SHOULD_ID_FIELD_DISABLE(guard, enabled_worlds, security_state)) { 78 * per_world_context_t *per_world_ctx = 79 * &per_world_context[security_state]; 80 * perworld_idregs_t *perworld_idregs = &(per_world_ctx->idregs); 81 * 82 * perworld_idregs->idreg &= 83 * ~((u_register_t)mask << idfield); 84 * perworld_idregs->idreg |= 85 * (((u_register_t)<unimplemented state value> & mask) << idfield); 86 * } 87 * } 88 */ 89 90 #if (ENABLE_FEAT_IDTE3 && IMAGE_BL31) 91 #define CREATE_IDREG_UPDATE(name, idreg, idfield, mask, guard, enabled_worlds) \ 92 __attribute__((always_inline)) \ 93 static inline void update_ ## name ## _idreg_field(size_t security_state) \ 94 { \ 95 if (SHOULD_ID_FIELD_DISABLE(guard, enabled_worlds, security_state)) { \ 96 per_world_context_t *per_world_ctx = \ 97 &per_world_context[security_state]; \ 98 perworld_idregs_t *perworld_idregs = &(per_world_ctx->idregs); \ 99 perworld_idregs->idreg &= ~((u_register_t)mask << idfield); \ 100 } \ 101 } 102 #define CREATE_PERCPU_IDREG_UPDATE(name, idreg, idfield, mask, guard, \ 103 enabled_worlds) \ 104 __attribute__((always_inline)) \ 105 static inline void update_ ## name ## _idreg_field(size_t security_state) \ 106 { \ 107 if (SHOULD_ID_FIELD_DISABLE(guard, enabled_worlds, security_state)) { \ 108 percpu_idregs_t *percpu_idregs = \ 109 &(get_cpu_data(idregs[security_state]));\ 110 percpu_idregs->idreg &= ~((u_register_t)mask << idfield); \ 111 } \ 112 } 113 #else 114 #define CREATE_IDREG_UPDATE(name, idreg, idfield, mask, guard, enabled_worlds) 115 #define CREATE_PERCPU_IDREG_UPDATE(name, idreg, idfield, mask, guard, \ 116 enabled_worlds) 117 #endif 118 119 #define _CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \ 120 __attribute__((always_inline)) \ 121 static inline bool is_ ## name ## _present(void) \ 122 { \ 123 return (ISOLATE_FIELD(read_ ## idreg(), idfield, mask) >= idval) \ 124 ? true : false; \ 125 } 126 127 #define CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval, \ 128 enabled_worlds) \ 129 _CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \ 130 CREATE_IDREG_UPDATE(name, idreg, idfield, mask, 1U, enabled_worlds) 131 132 #define CREATE_PERCPU_FEATURE_PRESENT(name, idreg, idfield, mask, idval, \ 133 enabled_worlds) \ 134 _CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \ 135 CREATE_PERCPU_IDREG_UPDATE(name, idreg, idfield, mask, 1U, \ 136 enabled_worlds) 137 138 #define CREATE_FEATURE_FUNCS(name, idreg, idfield, mask, idval, guard, \ 139 enabled_worlds) \ 140 CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval, \ 141 enabled_worlds) \ 142 CREATE_FEATURE_SUPPORTED(name, is_ ## name ## _present, guard) 143 144 #define CREATE_PERCPU_FEATURE_FUNCS(name, idreg, idfield, mask, idval, guard, \ 145 enabled_worlds) \ 146 CREATE_PERCPU_FEATURE_PRESENT(name, idreg, idfield, mask, idval, \ 147 enabled_worlds) \ 148 CREATE_FEATURE_SUPPORTED(name, is_ ## name ## _present, guard) 149 150 /* +----------------------------+ 151 * | Features supported | 152 * +----------------------------+ 153 * | GENTIMER | 154 * +----------------------------+ 155 * | FEAT_PAN | 156 * +----------------------------+ 157 * | FEAT_VHE | 158 * +----------------------------+ 159 * | FEAT_TTCNP | 160 * +----------------------------+ 161 * | FEAT_UAO | 162 * +----------------------------+ 163 * | FEAT_PACQARMA3 | 164 * +----------------------------+ 165 * | FEAT_PAUTH | 166 * +----------------------------+ 167 * | FEAT_TTST | 168 * +----------------------------+ 169 * | FEAT_BTI | 170 * +----------------------------+ 171 * | FEAT_MTE2 | 172 * +----------------------------+ 173 * | FEAT_SSBS | 174 * +----------------------------+ 175 * | FEAT_NMI | 176 * +----------------------------+ 177 * | FEAT_GCS | 178 * +----------------------------+ 179 * | FEAT_EBEP | 180 * +----------------------------+ 181 * | FEAT_SEBEP | 182 * +----------------------------+ 183 * | FEAT_SEL2 | 184 * +----------------------------+ 185 * | FEAT_TWED | 186 * +----------------------------+ 187 * | FEAT_FGT | 188 * +----------------------------+ 189 * | FEAT_EC/ECV2 | 190 * +----------------------------+ 191 * | FEAT_RNG | 192 * +----------------------------+ 193 * | FEAT_TCR2 | 194 * +----------------------------+ 195 * | FEAT_S2POE | 196 * +----------------------------+ 197 * | FEAT_S1POE | 198 * +----------------------------+ 199 * | FEAT_S2PIE | 200 * +----------------------------+ 201 * | FEAT_S1PIE | 202 * +----------------------------+ 203 * | FEAT_AMU/AMUV1P1 | 204 * +----------------------------+ 205 * | FEAT_MPAM | 206 * +----------------------------+ 207 * | FEAT_HCX | 208 * +----------------------------+ 209 * | FEAT_RNG_TRAP | 210 * +----------------------------+ 211 * | FEAT_RME | 212 * +----------------------------+ 213 * | FEAT_SB | 214 * +----------------------------+ 215 * | FEAT_CSV2/CSV3 | 216 * +----------------------------+ 217 * | FEAT_SPE | 218 * +----------------------------+ 219 * | FEAT_SVE | 220 * +----------------------------+ 221 * | FEAT_RAS | 222 * +----------------------------+ 223 * | FEAT_DIT | 224 * +----------------------------+ 225 * | FEAT_SYS_REG_TRACE | 226 * +----------------------------+ 227 * | FEAT_TRF | 228 * +----------------------------+ 229 * | FEAT_NV2 | 230 * +----------------------------+ 231 * | FEAT_BRBE | 232 * +----------------------------+ 233 * | FEAT_TRBE | 234 * +----------------------------+ 235 * | FEAT_SME/SME2 | 236 * +----------------------------+ 237 * | FEAT_PMUV3 | 238 * +----------------------------+ 239 * | FEAT_MTPMU | 240 * +----------------------------+ 241 * | FEAT_FGT2 | 242 * +----------------------------+ 243 * | FEAT_THE | 244 * +----------------------------+ 245 * | FEAT_SCTLR2 | 246 * +----------------------------+ 247 * | FEAT_D128 | 248 * +----------------------------+ 249 * | FEAT_LS64_ACCDATA | 250 * +----------------------------+ 251 * | FEAT_FPMR | 252 * +----------------------------+ 253 * | FEAT_MOPS | 254 * +----------------------------+ 255 * | FEAT_PAUTH_LR | 256 * +----------------------------+ 257 * | FEAT_FGWTE3 | 258 * +----------------------------+ 259 * | FEAT_MPAM_PE_BW_CTRL | 260 * +----------------------------+ 261 * | FEAT_CPA2 | 262 * +----------------------------+ 263 * | FEAT_AIE | 264 * +----------------------------+ 265 * | FEAT_PFAR | 266 * +----------------------------+ 267 * | FEAT_RME_GPC2 | 268 * +----------------------------+ 269 * | FEAT_RME_GDI | 270 * +----------------------------+ 271 * | FEAT_IDTE3 | 272 * +----------------------------+ 273 */ 274 275 __attribute__((always_inline)) 276 static inline bool is_armv7_gentimer_present(void) 277 { 278 /* The Generic Timer is always present in an ARMv8-A implementation */ 279 return true; 280 } 281 282 /* FEAT_PAN: Privileged access never */ 283 CREATE_FEATURE_FUNCS(feat_pan, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_PAN_SHIFT, 284 ID_AA64MMFR1_EL1_PAN_MASK, 1U, ENABLE_FEAT_PAN, 285 FEAT_ENABLE_ALL_WORLDS) 286 287 /* FEAT_VHE: Virtualization Host Extensions */ 288 CREATE_FEATURE_FUNCS(feat_vhe, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_VHE_SHIFT, 289 ID_AA64MMFR1_EL1_VHE_MASK, 1U, ENABLE_FEAT_VHE, 290 FEAT_ENABLE_ALL_WORLDS) 291 292 /* FEAT_TTCNP: Translation table common not private */ 293 CREATE_FEATURE_PRESENT(feat_ttcnp, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_CNP_SHIFT, 294 ID_AA64MMFR2_EL1_CNP_MASK, 1U, 295 FEAT_ENABLE_ALL_WORLDS) 296 297 /* FEAT_UAO: User access override */ 298 CREATE_FEATURE_PRESENT(feat_uao, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_UAO_SHIFT, 299 ID_AA64MMFR2_EL1_UAO_MASK, 1U, 300 FEAT_ENABLE_ALL_WORLDS) 301 302 /* If any of the fields is not zero, QARMA3 algorithm is present */ 303 CREATE_FEATURE_PRESENT(feat_pacqarma3, id_aa64isar2_el1, 0, 304 ((ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_SHIFT) | 305 (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_SHIFT)), 1U, 306 FEAT_ENABLE_ALL_WORLDS) 307 308 /* FEAT_PAUTH: Pointer Authentication */ 309 __attribute__((always_inline)) 310 static inline bool is_feat_pauth_present(void) 311 { 312 uint64_t mask_id_aa64isar1 = 313 (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) | 314 (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) | 315 (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) | 316 (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT); 317 318 /* 319 * If any of the fields is not zero or QARMA3 is present, 320 * PAuth is present 321 */ 322 return ((read_id_aa64isar1_el1() & mask_id_aa64isar1) != 0U || 323 is_feat_pacqarma3_present()); 324 } 325 CREATE_FEATURE_SUPPORTED(feat_pauth, is_feat_pauth_present, ENABLE_PAUTH) 326 CREATE_FEATURE_SUPPORTED(ctx_pauth, is_feat_pauth_present, CTX_INCLUDE_PAUTH_REGS) 327 328 #if (ENABLE_FEAT_IDTE3 && IMAGE_BL31) 329 __attribute__((always_inline)) 330 static inline void update_feat_pauth_idreg_field(size_t security_state) 331 { 332 uint64_t mask_id_aa64isar1 = 333 (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) | 334 (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) | 335 (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) | 336 (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT); 337 338 uint64_t mask_id_aa64isar2 = 339 (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_MASK) | 340 (ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_MASK); 341 342 per_world_context_t *per_world_ctx = &per_world_context[security_state]; 343 perworld_idregs_t *perworld_idregs = 344 &(per_world_ctx->idregs); 345 346 if ((SHOULD_ID_FIELD_DISABLE(ENABLE_PAUTH, FEAT_ENABLE_NS, 347 security_state)) && 348 (SHOULD_ID_FIELD_DISABLE(CTX_INCLUDE_PAUTH_REGS, 349 FEAT_ENABLE_ALL_WORLDS, 350 security_state))) { 351 perworld_idregs->id_aa64isar1_el1 &= ~(mask_id_aa64isar1); 352 perworld_idregs->id_aa64isar2_el1 &= ~(mask_id_aa64isar2); 353 } 354 } 355 #endif 356 357 /* 358 * FEAT_PAUTH_LR 359 * This feature has a non-standard discovery method so define this function 360 * manually then call use the CREATE_FEATURE_SUPPORTED macro with it. This 361 * feature is enabled with ENABLE_PAUTH when present. 362 */ 363 __attribute__((always_inline)) 364 static inline bool is_feat_pauth_lr_present(void) 365 { 366 /* 367 * FEAT_PAUTH_LR support is indicated by up to 3 fields, if one or more 368 * of these is 0b0110 then the feature is present. 369 * 1) id_aa64isr1_el1.api 370 * 2) id_aa64isr1_el1.apa 371 * 3) id_aa64isr2_el1.apa3 372 */ 373 if (ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_API_SHIFT, ID_AA64ISAR1_API_MASK) == 0b0110) { 374 return true; 375 } 376 if (ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_APA_SHIFT, ID_AA64ISAR1_APA_MASK) == 0b0110) { 377 return true; 378 } 379 if (ISOLATE_FIELD(read_id_aa64isar2_el1(), ID_AA64ISAR2_APA3_SHIFT, ID_AA64ISAR2_APA3_MASK) == 0b0110) { 380 return true; 381 } 382 return false; 383 } 384 CREATE_FEATURE_SUPPORTED(feat_pauth_lr, is_feat_pauth_lr_present, ENABLE_FEAT_PAUTH_LR) 385 386 /* FEAT_TTST: Small translation tables */ 387 CREATE_FEATURE_PRESENT(feat_ttst, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_ST_SHIFT, 388 ID_AA64MMFR2_EL1_ST_MASK, 1U, 389 FEAT_ENABLE_ALL_WORLDS) 390 391 /* FEAT_BTI: Branch target identification */ 392 CREATE_FEATURE_FUNCS(feat_bti, id_aa64pfr1_el1, ID_AA64PFR1_EL1_BT_SHIFT, 393 ID_AA64PFR1_EL1_BT_MASK, BTI_IMPLEMENTED, ENABLE_BTI, 394 FEAT_ENABLE_ALL_WORLDS) 395 396 /* FEAT_MTE2: Memory tagging extension */ 397 CREATE_FEATURE_FUNCS(feat_mte2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_MTE_SHIFT, 398 ID_AA64PFR1_EL1_MTE_MASK, MTE_IMPLEMENTED_ELX, ENABLE_FEAT_MTE2, 399 FEAT_ENABLE_SECURE | FEAT_ENABLE_NS) 400 401 /* FEAT_SSBS: Speculative store bypass safe */ 402 CREATE_FEATURE_PRESENT(feat_ssbs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SSBS_SHIFT, 403 ID_AA64PFR1_EL1_SSBS_MASK, 1U, 404 FEAT_ENABLE_ALL_WORLDS) 405 406 /* FEAT_NMI: Non-maskable interrupts */ 407 CREATE_FEATURE_PRESENT(feat_nmi, id_aa64pfr1_el1, ID_AA64PFR1_EL1_NMI_SHIFT, 408 ID_AA64PFR1_EL1_NMI_MASK, NMI_IMPLEMENTED, 409 FEAT_ENABLE_ALL_WORLDS) 410 411 /* FEAT_EBEP */ 412 CREATE_PERCPU_FEATURE_FUNCS(feat_ebep, id_aa64dfr1_el1, ID_AA64DFR1_EBEP_SHIFT, 413 ID_AA64DFR1_EBEP_MASK, 1U, ENABLE_FEAT_EBEP, 414 FEAT_ENABLE_ALL_WORLDS) 415 416 /* FEAT_SEBEP */ 417 CREATE_PERCPU_FEATURE_PRESENT(feat_sebep, id_aa64dfr0_el1, ID_AA64DFR0_SEBEP_SHIFT, 418 ID_AA64DFR0_SEBEP_MASK, SEBEP_IMPLEMENTED, 419 FEAT_ENABLE_ALL_WORLDS) 420 421 /* FEAT_SEL2: Secure EL2 */ 422 CREATE_FEATURE_FUNCS(feat_sel2, id_aa64pfr0_el1, ID_AA64PFR0_SEL2_SHIFT, 423 ID_AA64PFR0_SEL2_MASK, 1U, ENABLE_FEAT_SEL2, 424 FEAT_ENABLE_ALL_WORLDS) 425 426 /* FEAT_TWED: Delayed trapping of WFE */ 427 CREATE_FEATURE_FUNCS(feat_twed, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_TWED_SHIFT, 428 ID_AA64MMFR1_EL1_TWED_MASK, 1U, ENABLE_FEAT_TWED, 429 FEAT_ENABLE_ALL_WORLDS) 430 431 /* FEAT_FGT: Fine-grained traps */ 432 CREATE_FEATURE_FUNCS(feat_fgt, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT, 433 ID_AA64MMFR0_EL1_FGT_MASK, 1U, ENABLE_FEAT_FGT, 434 FEAT_ENABLE_ALL_WORLDS) 435 436 /* FEAT_FGT2: Fine-grained traps extended */ 437 CREATE_FEATURE_FUNCS(feat_fgt2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT, 438 ID_AA64MMFR0_EL1_FGT_MASK, FGT2_IMPLEMENTED, ENABLE_FEAT_FGT2, 439 FEAT_ENABLE_ALL_WORLDS) 440 441 /* FEAT_FGWTE3: Fine-grained write traps EL3 */ 442 CREATE_FEATURE_FUNCS(feat_fgwte3, id_aa64mmfr4_el1, ID_AA64MMFR4_EL1_FGWTE3_SHIFT, 443 ID_AA64MMFR4_EL1_FGWTE3_MASK, FGWTE3_IMPLEMENTED, 444 ENABLE_FEAT_FGWTE3, FEAT_ENABLE_ALL_WORLDS) 445 446 /* FEAT_ECV: Enhanced Counter Virtualization */ 447 CREATE_FEATURE_FUNCS(feat_ecv, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT, 448 ID_AA64MMFR0_EL1_ECV_MASK, 1U, ENABLE_FEAT_ECV, 449 FEAT_ENABLE_ALL_WORLDS) 450 CREATE_FEATURE_FUNCS(feat_ecv_v2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT, 451 ID_AA64MMFR0_EL1_ECV_MASK, ID_AA64MMFR0_EL1_ECV_SELF_SYNCH, 452 ENABLE_FEAT_ECV, FEAT_ENABLE_ALL_WORLDS) 453 454 /* FEAT_RNG: Random number generator */ 455 CREATE_FEATURE_FUNCS(feat_rng, id_aa64isar0_el1, ID_AA64ISAR0_RNDR_SHIFT, 456 ID_AA64ISAR0_RNDR_MASK, 1U, ENABLE_FEAT_RNG, 457 FEAT_ENABLE_ALL_WORLDS) 458 459 /* FEAT_TCR2: Support TCR2_ELx regs */ 460 CREATE_FEATURE_FUNCS(feat_tcr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_TCRX_SHIFT, 461 ID_AA64MMFR3_EL1_TCRX_MASK, 1U, ENABLE_FEAT_TCR2, 462 FEAT_ENABLE_ALL_WORLDS) 463 464 /* FEAT_S2POE */ 465 CREATE_FEATURE_FUNCS(feat_s2poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2POE_SHIFT, 466 ID_AA64MMFR3_EL1_S2POE_MASK, 1U, ENABLE_FEAT_S2POE, 467 FEAT_ENABLE_ALL_WORLDS) 468 469 /* FEAT_S1POE */ 470 CREATE_FEATURE_FUNCS(feat_s1poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1POE_SHIFT, 471 ID_AA64MMFR3_EL1_S1POE_MASK, 1U, ENABLE_FEAT_S1POE, 472 FEAT_ENABLE_ALL_WORLDS) 473 474 __attribute__((always_inline)) 475 static inline bool is_feat_sxpoe_supported(void) 476 { 477 return is_feat_s1poe_supported() || is_feat_s2poe_supported(); 478 } 479 480 /* FEAT_S2PIE */ 481 CREATE_FEATURE_FUNCS(feat_s2pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2PIE_SHIFT, 482 ID_AA64MMFR3_EL1_S2PIE_MASK, 1U, ENABLE_FEAT_S2PIE, 483 FEAT_ENABLE_ALL_WORLDS) 484 485 /* FEAT_S1PIE */ 486 CREATE_FEATURE_FUNCS(feat_s1pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1PIE_SHIFT, 487 ID_AA64MMFR3_EL1_S1PIE_MASK, 1U, ENABLE_FEAT_S1PIE, 488 FEAT_ENABLE_ALL_WORLDS) 489 490 /* FEAT_THE: Translation Hardening Extension */ 491 CREATE_FEATURE_FUNCS(feat_the, id_aa64pfr1_el1, ID_AA64PFR1_EL1_THE_SHIFT, 492 ID_AA64PFR1_EL1_THE_MASK, THE_IMPLEMENTED, ENABLE_FEAT_THE, 493 FEAT_ENABLE_NS) 494 495 /* FEAT_SCTLR2 */ 496 CREATE_FEATURE_FUNCS(feat_sctlr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_SCTLR2_SHIFT, 497 ID_AA64MMFR3_EL1_SCTLR2_MASK, SCTLR2_IMPLEMENTED, 498 ENABLE_FEAT_SCTLR2, 499 FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 500 501 /* FEAT_D128 */ 502 CREATE_FEATURE_FUNCS(feat_d128, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_D128_SHIFT, 503 ID_AA64MMFR3_EL1_D128_MASK, D128_IMPLEMENTED, 504 ENABLE_FEAT_D128, FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 505 506 /* FEAT_RME_GPC2 */ 507 _CREATE_FEATURE_PRESENT(feat_rme_gpc2, id_aa64pfr0_el1, 508 ID_AA64PFR0_FEAT_RME_SHIFT, ID_AA64PFR0_FEAT_RME_MASK, 509 RME_GPC2_IMPLEMENTED) 510 511 /* FEAT_RME_GDI */ 512 CREATE_FEATURE_FUNCS(feat_rme_gdi, id_aa64mmfr4_el1, 513 ID_AA64MMFR4_EL1_RME_GDI_SHIFT, 514 ID_AA64MMFR4_EL1_RME_GDI_MASK, RME_GDI_IMPLEMENTED, 515 ENABLE_FEAT_RME_GDI, FEAT_ENABLE_ALL_WORLDS) 516 517 /* FEAT_FPMR */ 518 CREATE_FEATURE_FUNCS(feat_fpmr, id_aa64pfr2_el1, ID_AA64PFR2_EL1_FPMR_SHIFT, 519 ID_AA64PFR2_EL1_FPMR_MASK, FPMR_IMPLEMENTED, 520 ENABLE_FEAT_FPMR, FEAT_ENABLE_NS) 521 /* FEAT_MOPS */ 522 CREATE_FEATURE_FUNCS(feat_mops, id_aa64isar2_el1, ID_AA64ISAR2_EL1_MOPS_SHIFT, 523 ID_AA64ISAR2_EL1_MOPS_MASK, MOPS_IMPLEMENTED, 524 ENABLE_FEAT_MOPS, FEAT_ENABLE_ALL_WORLDS) 525 526 __attribute__((always_inline)) 527 static inline bool is_feat_sxpie_supported(void) 528 { 529 return is_feat_s1pie_supported() || is_feat_s2pie_supported(); 530 } 531 532 /* FEAT_GCS: Guarded Control Stack */ 533 CREATE_FEATURE_FUNCS(feat_gcs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_GCS_SHIFT, 534 ID_AA64PFR1_EL1_GCS_MASK, 1U, ENABLE_FEAT_GCS, 535 FEAT_ENABLE_ALL_WORLDS) 536 537 /* FEAT_AMU: Activity Monitors Extension */ 538 CREATE_FEATURE_FUNCS(feat_amu, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT, 539 ID_AA64PFR0_AMU_MASK, 1U, ENABLE_FEAT_AMU, 540 FEAT_ENABLE_NS) 541 542 /* Auxiliary counters for FEAT_AMU */ 543 _CREATE_FEATURE_PRESENT(feat_amu_aux, amcfgr_el0, 544 AMCFGR_EL0_NCG_SHIFT, AMCFGR_EL0_NCG_MASK, 1U) 545 546 CREATE_FEATURE_SUPPORTED(feat_amu_aux, is_feat_amu_aux_present, 547 ENABLE_AMU_AUXILIARY_COUNTERS) 548 549 /* FEAT_AMUV1P1: AMU Extension v1.1 */ 550 CREATE_FEATURE_FUNCS(feat_amuv1p1, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT, 551 ID_AA64PFR0_AMU_MASK, ID_AA64PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1, 552 FEAT_ENABLE_NS) 553 554 /* 555 * Return MPAM version: 556 * 557 * 0x00: None Armv8.0 or later 558 * 0x01: v0.1 Armv8.4 or later 559 * 0x10: v1.0 Armv8.2 or later 560 * 0x11: v1.1 Armv8.4 or later 561 * 562 */ 563 __attribute__((always_inline)) 564 static inline bool is_feat_mpam_present(void) 565 { 566 unsigned int ret = (unsigned int)((((read_id_aa64pfr0_el1() >> 567 ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) | 568 ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_MPAM_FRAC_SHIFT) 569 & ID_AA64PFR1_MPAM_FRAC_MASK)); 570 return ret; 571 } 572 573 CREATE_FEATURE_SUPPORTED(feat_mpam, is_feat_mpam_present, ENABLE_FEAT_MPAM) 574 575 576 #if (ENABLE_FEAT_IDTE3 && IMAGE_BL31) 577 __attribute__((always_inline)) 578 static inline void update_feat_mpam_idreg_field(size_t security_state) 579 { 580 if (SHOULD_ID_FIELD_DISABLE(ENABLE_FEAT_MPAM, 581 FEAT_ENABLE_NS | FEAT_ENABLE_REALM, security_state)) { 582 per_world_context_t *per_world_ctx = 583 &per_world_context[security_state]; 584 perworld_idregs_t *perworld_idregs = 585 &(per_world_ctx->idregs); 586 587 perworld_idregs->id_aa64pfr0_el1 &= 588 ~((u_register_t)ID_AA64PFR0_MPAM_MASK 589 << ID_AA64PFR0_MPAM_SHIFT); 590 591 perworld_idregs->id_aa64pfr1_el1 &= 592 ~((u_register_t)ID_AA64PFR1_MPAM_FRAC_MASK 593 << ID_AA64PFR1_MPAM_FRAC_SHIFT); 594 } 595 } 596 #endif 597 598 /* FEAT_MPAM_PE_BW_CTRL: MPAM PE-side bandwidth controls */ 599 __attribute__((always_inline)) 600 static inline bool is_feat_mpam_pe_bw_ctrl_present(void) 601 { 602 if (is_feat_mpam_present()) { 603 return ((unsigned long long)(read_mpamidr_el1() & 604 MPAMIDR_HAS_BW_CTRL_BIT) != 0U); 605 } 606 return false; 607 } 608 609 CREATE_FEATURE_SUPPORTED(feat_mpam_pe_bw_ctrl, is_feat_mpam_pe_bw_ctrl_present, 610 ENABLE_FEAT_MPAM_PE_BW_CTRL) 611 612 /* 613 * FEAT_DebugV8P9: Debug extension. This function checks the field 3:0 of 614 * ID_AA64DFR0 Aarch64 Debug Feature Register 0 for the version of 615 * Feat_Debug supported. The value of the field determines feature presence 616 * 617 * 0b0110 - Arm v8.0 debug 618 * 0b0111 - Arm v8.0 debug architecture with Virtualization host extensions 619 * 0x1000 - FEAT_Debugv8p2 is supported 620 * 0x1001 - FEAT_Debugv8p4 is supported 621 * 0x1010 - FEAT_Debugv8p8 is supported 622 * 0x1011 - FEAT_Debugv8p9 is supported 623 * 624 */ 625 CREATE_PERCPU_FEATURE_FUNCS(feat_debugv8p9, id_aa64dfr0_el1, 626 ID_AA64DFR0_DEBUGVER_SHIFT, ID_AA64DFR0_DEBUGVER_MASK, 627 DEBUGVER_V8P9_IMPLEMENTED, ENABLE_FEAT_DEBUGV8P9, 628 FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 629 630 /* FEAT_HCX: Extended Hypervisor Configuration Register */ 631 CREATE_FEATURE_FUNCS(feat_hcx, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_HCX_SHIFT, 632 ID_AA64MMFR1_EL1_HCX_MASK, 1U, ENABLE_FEAT_HCX, 633 FEAT_ENABLE_ALL_WORLDS) 634 635 /* FEAT_RNG_TRAP: Trapping support */ 636 CREATE_FEATURE_FUNCS(feat_rng_trap, id_aa64pfr1_el1, ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT, 637 ID_AA64PFR1_EL1_RNDR_TRAP_MASK, RNG_TRAP_IMPLEMENTED, ENABLE_FEAT_RNG_TRAP, 638 FEAT_ENABLE_ALL_WORLDS) 639 640 /* Return the RME version, zero if not supported. */ 641 _CREATE_FEATURE_PRESENT(feat_rme, id_aa64pfr0_el1, 642 ID_AA64PFR0_FEAT_RME_SHIFT, ID_AA64PFR0_FEAT_RME_MASK, 1U) 643 644 CREATE_FEATURE_SUPPORTED(feat_rme, is_feat_rme_present, ENABLE_RME) 645 646 /* FEAT_SB: Speculation barrier instruction */ 647 CREATE_FEATURE_PRESENT(feat_sb, id_aa64isar1_el1, ID_AA64ISAR1_SB_SHIFT, 648 ID_AA64ISAR1_SB_MASK, 1U, 649 FEAT_ENABLE_ALL_WORLDS) 650 651 /* FEAT_MEC: Memory Encryption Contexts */ 652 CREATE_FEATURE_FUNCS(feat_mec, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_MEC_SHIFT, 653 ID_AA64MMFR3_EL1_MEC_MASK, 1U, ENABLE_FEAT_MEC, 654 FEAT_ENABLE_ALL_WORLDS) 655 656 /* 657 * FEAT_CSV2: Cache Speculation Variant 2. This checks bit fields[56-59] 658 * of id_aa64pfr0_el1 register and can be used to check for below features: 659 * FEAT_CSV2_2: Cache Speculation Variant CSV2_2. 660 * FEAT_CSV2_3: Cache Speculation Variant CSV2_3. 661 * 0b0000 - Feature FEAT_CSV2 is not implemented. 662 * 0b0001 - Feature FEAT_CSV2 is implemented, but FEAT_CSV2_2 and FEAT_CSV2_3 663 * are not implemented. 664 * 0b0010 - Feature FEAT_CSV2_2 is implemented but FEAT_CSV2_3 is not 665 * implemented. 666 * 0b0011 - Feature FEAT_CSV2_3 is implemented. 667 */ 668 669 CREATE_FEATURE_FUNCS(feat_csv2_2, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT, 670 ID_AA64PFR0_CSV2_MASK, CSV2_2_IMPLEMENTED, ENABLE_FEAT_CSV2_2, 671 FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 672 CREATE_FEATURE_FUNCS(feat_csv2_3, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT, 673 ID_AA64PFR0_CSV2_MASK, CSV2_3_IMPLEMENTED, ENABLE_FEAT_CSV2_3, 674 FEAT_ENABLE_ALL_WORLDS) 675 676 /* FEAT_SPE: Statistical Profiling Extension */ 677 CREATE_PERCPU_FEATURE_FUNCS(feat_spe, id_aa64dfr0_el1, ID_AA64DFR0_PMS_SHIFT, 678 ID_AA64DFR0_PMS_MASK, 1U, ENABLE_SPE_FOR_NS, 679 FEAT_ENABLE_ALL_WORLDS) 680 681 /* FEAT_SVE: Scalable Vector Extension */ 682 CREATE_FEATURE_FUNCS(feat_sve, id_aa64pfr0_el1, ID_AA64PFR0_SVE_SHIFT, 683 ID_AA64PFR0_SVE_MASK, 1U, ENABLE_SVE_FOR_NS, 684 FEAT_ENABLE_ALL_WORLDS) 685 686 /* FEAT_RAS: Reliability, Accessibility, Serviceability */ 687 CREATE_FEATURE_FUNCS(feat_ras, id_aa64pfr0_el1, ID_AA64PFR0_RAS_SHIFT, 688 ID_AA64PFR0_RAS_MASK, 1U, ENABLE_FEAT_RAS, 689 FEAT_ENABLE_ALL_WORLDS) 690 691 /* FEAT_DIT: Data Independent Timing instructions */ 692 CREATE_FEATURE_FUNCS(feat_dit, id_aa64pfr0_el1, ID_AA64PFR0_DIT_SHIFT, 693 ID_AA64PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT, 694 FEAT_ENABLE_ALL_WORLDS) 695 696 /* FEAT_SYS_REG_TRACE */ 697 CREATE_PERCPU_FEATURE_FUNCS(feat_sys_reg_trace, id_aa64dfr0_el1, 698 ID_AA64DFR0_TRACEVER_SHIFT, ID_AA64DFR0_TRACEVER_MASK, 699 1U, ENABLE_SYS_REG_TRACE_FOR_NS, 700 FEAT_ENABLE_ALL_WORLDS) 701 702 /* FEAT_TRF: TraceFilter */ 703 CREATE_PERCPU_FEATURE_FUNCS(feat_trf, id_aa64dfr0_el1, ID_AA64DFR0_TRACEFILT_SHIFT, 704 ID_AA64DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS, 705 FEAT_ENABLE_ALL_WORLDS) 706 707 /* FEAT_NV2: Enhanced Nested Virtualization */ 708 CREATE_FEATURE_FUNCS(feat_nv2, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_NV_SHIFT, 709 ID_AA64MMFR2_EL1_NV_MASK, NV2_IMPLEMENTED, CTX_INCLUDE_NEVE_REGS, 710 FEAT_ENABLE_ALL_WORLDS) 711 712 /* FEAT_BRBE: Branch Record Buffer Extension */ 713 CREATE_PERCPU_FEATURE_FUNCS(feat_brbe, id_aa64dfr0_el1, ID_AA64DFR0_BRBE_SHIFT, 714 ID_AA64DFR0_BRBE_MASK, 1U, ENABLE_BRBE_FOR_NS, 715 FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 716 717 /* FEAT_TRBE: Trace Buffer Extension */ 718 _CREATE_FEATURE_PRESENT(feat_trbe, id_aa64dfr0_el1, ID_AA64DFR0_TRACEBUFFER_SHIFT, 719 ID_AA64DFR0_TRACEBUFFER_MASK, 1U) 720 721 CREATE_FEATURE_SUPPORTED(feat_trbe, is_feat_trbe_present, ENABLE_TRBE_FOR_NS) 722 723 CREATE_PERCPU_IDREG_UPDATE(feat_trbe, id_aa64dfr0_el1, ID_AA64DFR0_TRACEBUFFER_SHIFT, 724 ID_AA64DFR0_TRACEBUFFER_MASK, 725 ENABLE_TRBE_FOR_NS && !check_if_trbe_disable_affected_core(), 726 FEAT_ENABLE_NS) 727 728 /* FEAT_SME_FA64: Full A64 Instruction support in streaming SVE mode */ 729 CREATE_FEATURE_PRESENT(feat_sme_fa64, id_aa64smfr0_el1, ID_AA64SMFR0_EL1_SME_FA64_SHIFT, 730 ID_AA64SMFR0_EL1_SME_FA64_MASK, 1U, 731 FEAT_ENABLE_ALL_WORLDS) 732 733 /* FEAT_SMEx: Scalar Matrix Extension */ 734 CREATE_FEATURE_FUNCS(feat_sme, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT, 735 ID_AA64PFR1_EL1_SME_MASK, 1U, ENABLE_SME_FOR_NS, 736 FEAT_ENABLE_ALL_WORLDS) 737 738 CREATE_FEATURE_FUNCS(feat_sme2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT, 739 ID_AA64PFR1_EL1_SME_MASK, SME2_IMPLEMENTED, ENABLE_SME2_FOR_NS, 740 FEAT_ENABLE_ALL_WORLDS) 741 742 /* FEAT_LS64_ACCDATA: */ 743 CREATE_FEATURE_FUNCS(feat_ls64_accdata, id_aa64isar1_el1, ID_AA64ISAR1_LS64_SHIFT, 744 ID_AA64ISAR1_LS64_MASK, LS64_ACCDATA_IMPLEMENTED, 745 ENABLE_FEAT_LS64_ACCDATA, FEAT_ENABLE_ALL_WORLDS) 746 747 /* FEAT_AIE: */ 748 CREATE_FEATURE_FUNCS(feat_aie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_AIE_SHIFT, 749 ID_AA64MMFR3_EL1_AIE_MASK, 1U, ENABLE_FEAT_AIE, 750 FEAT_ENABLE_NS) 751 752 /* FEAT_PFAR: */ 753 CREATE_FEATURE_FUNCS(feat_pfar, id_aa64pfr1_el1, ID_AA64PFR1_EL1_PFAR_SHIFT, 754 ID_AA64PFR1_EL1_PFAR_MASK, 1U, ENABLE_FEAT_PFAR, 755 FEAT_ENABLE_NS) 756 757 /* FEAT_IDTE3: Trapping lower EL ID Register access to EL3 */ 758 CREATE_FEATURE_FUNCS(feat_idte3, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_IDS_SHIFT, 759 ID_AA64MMFR2_EL1_IDS_MASK, 2U, ENABLE_FEAT_IDTE3, 760 FEAT_ENABLE_ALL_WORLDS) 761 762 /******************************************************************************* 763 * Function to get hardware granularity support 764 ******************************************************************************/ 765 766 __attribute__((always_inline)) 767 static inline bool is_feat_tgran4K_present(void) 768 { 769 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(), 770 ID_AA64MMFR0_EL1_TGRAN4_SHIFT, ID_REG_FIELD_MASK); 771 return (tgranx < 8U); 772 } 773 774 CREATE_FEATURE_PRESENT(feat_tgran16K, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_TGRAN16_SHIFT, 775 ID_AA64MMFR0_EL1_TGRAN16_MASK, TGRAN16_IMPLEMENTED, 776 FEAT_ENABLE_ALL_WORLDS) 777 778 __attribute__((always_inline)) 779 static inline bool is_feat_tgran64K_present(void) 780 { 781 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(), 782 ID_AA64MMFR0_EL1_TGRAN64_SHIFT, ID_REG_FIELD_MASK); 783 return (tgranx < 8U); 784 } 785 786 /* FEAT_PMUV3 */ 787 _CREATE_FEATURE_PRESENT(feat_pmuv3, id_aa64dfr0_el1, ID_AA64DFR0_PMUVER_SHIFT, 788 ID_AA64DFR0_PMUVER_MASK, 1U) 789 790 /* FEAT_MTPMU */ 791 __attribute__((always_inline)) 792 static inline bool is_feat_mtpmu_present(void) 793 { 794 unsigned int mtpmu = ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_MTPMU_SHIFT, 795 ID_AA64DFR0_MTPMU_MASK); 796 return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED); 797 } 798 799 CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU) 800 801 CREATE_PERCPU_IDREG_UPDATE(feat_mtpmu, id_aa64dfr0_el1, ID_AA64DFR0_MTPMU_SHIFT, 802 ID_AA64DFR0_MTPMU_MASK, DISABLE_MTPMU, 803 FEAT_ENABLE_ALL_WORLDS) 804 805 /************************************************************************* 806 * Function to identify the presence of FEAT_GCIE (GICv5 CPU interface 807 * extension). 808 ************************************************************************/ 809 CREATE_FEATURE_FUNCS(feat_gcie, id_aa64pfr2_el1, ID_AA64PFR2_EL1_GCIE_SHIFT, 810 ID_AA64PFR2_EL1_GCIE_MASK, 1U, ENABLE_FEAT_GCIE, 811 FEAT_ENABLE_ALL_WORLDS) 812 813 CREATE_FEATURE_FUNCS(feat_cpa2, id_aa64isar3_el1, ID_AA64ISAR3_EL1_CPA_SHIFT, 814 ID_AA64ISAR3_EL1_CPA_MASK, CPA2_IMPLEMENTED, 815 ENABLE_FEAT_CPA2, FEAT_ENABLE_ALL_WORLDS) 816 817 #endif /* ARCH_FEATURES_H */ 818