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_2/CSV2_3 | 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 * | FEAT_UINJ | 274 * +----------------------------+ 275 */ 276 277 __attribute__((always_inline)) 278 static inline bool is_armv7_gentimer_present(void) 279 { 280 /* The Generic Timer is always present in an ARMv8-A implementation */ 281 return true; 282 } 283 284 /* FEAT_PAN: Privileged access never */ 285 CREATE_FEATURE_FUNCS(feat_pan, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_PAN_SHIFT, 286 ID_AA64MMFR1_EL1_PAN_MASK, 1U, ENABLE_FEAT_PAN, 287 FEAT_ENABLE_ALL_WORLDS) 288 289 /* FEAT_VHE: Virtualization Host Extensions */ 290 CREATE_FEATURE_FUNCS(feat_vhe, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_VHE_SHIFT, 291 ID_AA64MMFR1_EL1_VHE_MASK, 1U, ENABLE_FEAT_VHE, 292 FEAT_ENABLE_ALL_WORLDS) 293 294 /* FEAT_TTCNP: Translation table common not private */ 295 CREATE_FEATURE_PRESENT(feat_ttcnp, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_CNP_SHIFT, 296 ID_AA64MMFR2_EL1_CNP_MASK, 1U, 297 FEAT_ENABLE_ALL_WORLDS) 298 299 /* FEAT_UAO: User access override */ 300 CREATE_FEATURE_PRESENT(feat_uao, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_UAO_SHIFT, 301 ID_AA64MMFR2_EL1_UAO_MASK, 1U, 302 FEAT_ENABLE_ALL_WORLDS) 303 304 /* If any of the fields is not zero, QARMA3 algorithm is present */ 305 CREATE_FEATURE_PRESENT(feat_pacqarma3, id_aa64isar2_el1, 0, 306 ((ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_SHIFT) | 307 (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_SHIFT)), 1U, 308 FEAT_ENABLE_ALL_WORLDS) 309 310 /* FEAT_PAUTH: Pointer Authentication */ 311 __attribute__((always_inline)) 312 static inline bool is_feat_pauth_present(void) 313 { 314 uint64_t mask_id_aa64isar1 = 315 (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) | 316 (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) | 317 (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) | 318 (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT); 319 320 /* 321 * If any of the fields is not zero or QARMA3 is present, 322 * PAuth is present 323 */ 324 return ((read_id_aa64isar1_el1() & mask_id_aa64isar1) != 0U || 325 is_feat_pacqarma3_present()); 326 } 327 CREATE_FEATURE_SUPPORTED(feat_pauth, is_feat_pauth_present, ENABLE_PAUTH) 328 CREATE_FEATURE_SUPPORTED(ctx_pauth, is_feat_pauth_present, CTX_INCLUDE_PAUTH_REGS) 329 330 #if (ENABLE_FEAT_IDTE3 && IMAGE_BL31) 331 __attribute__((always_inline)) 332 static inline void update_feat_pauth_idreg_field(size_t security_state) 333 { 334 uint64_t mask_id_aa64isar1 = 335 (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) | 336 (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) | 337 (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) | 338 (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT); 339 340 uint64_t mask_id_aa64isar2 = 341 (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_MASK) | 342 (ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_MASK); 343 344 per_world_context_t *per_world_ctx = &per_world_context[security_state]; 345 perworld_idregs_t *perworld_idregs = 346 &(per_world_ctx->idregs); 347 348 if ((SHOULD_ID_FIELD_DISABLE(ENABLE_PAUTH, FEAT_ENABLE_NS, 349 security_state)) && 350 (SHOULD_ID_FIELD_DISABLE(CTX_INCLUDE_PAUTH_REGS, 351 FEAT_ENABLE_ALL_WORLDS, 352 security_state))) { 353 perworld_idregs->id_aa64isar1_el1 &= ~(mask_id_aa64isar1); 354 perworld_idregs->id_aa64isar2_el1 &= ~(mask_id_aa64isar2); 355 } 356 } 357 #endif 358 359 /* 360 * FEAT_PAUTH_LR 361 * This feature has a non-standard discovery method so define this function 362 * manually then call use the CREATE_FEATURE_SUPPORTED macro with it. This 363 * feature is enabled with ENABLE_PAUTH when present. 364 */ 365 __attribute__((always_inline)) 366 static inline bool is_feat_pauth_lr_present(void) 367 { 368 /* 369 * FEAT_PAUTH_LR support is indicated by up to 3 fields, if one or more 370 * of these is 0b0110 then the feature is present. 371 * 1) id_aa64isr1_el1.api 372 * 2) id_aa64isr1_el1.apa 373 * 3) id_aa64isr2_el1.apa3 374 */ 375 if (ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_API_SHIFT, ID_AA64ISAR1_API_MASK) == 0b0110) { 376 return true; 377 } 378 if (ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_APA_SHIFT, ID_AA64ISAR1_APA_MASK) == 0b0110) { 379 return true; 380 } 381 if (ISOLATE_FIELD(read_id_aa64isar2_el1(), ID_AA64ISAR2_APA3_SHIFT, ID_AA64ISAR2_APA3_MASK) == 0b0110) { 382 return true; 383 } 384 return false; 385 } 386 CREATE_FEATURE_SUPPORTED(feat_pauth_lr, is_feat_pauth_lr_present, ENABLE_FEAT_PAUTH_LR) 387 388 /* FEAT_TTST: Small translation tables */ 389 CREATE_FEATURE_PRESENT(feat_ttst, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_ST_SHIFT, 390 ID_AA64MMFR2_EL1_ST_MASK, 1U, 391 FEAT_ENABLE_ALL_WORLDS) 392 393 /* FEAT_BTI: Branch target identification */ 394 CREATE_FEATURE_FUNCS(feat_bti, id_aa64pfr1_el1, ID_AA64PFR1_EL1_BT_SHIFT, 395 ID_AA64PFR1_EL1_BT_MASK, BTI_IMPLEMENTED, ENABLE_BTI, 396 FEAT_ENABLE_ALL_WORLDS) 397 398 /* FEAT_MTE2: Memory tagging extension */ 399 CREATE_FEATURE_FUNCS(feat_mte2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_MTE_SHIFT, 400 ID_AA64PFR1_EL1_MTE_MASK, MTE_IMPLEMENTED_ELX, ENABLE_FEAT_MTE2, 401 FEAT_ENABLE_SECURE | FEAT_ENABLE_NS) 402 403 /* FEAT_SSBS: Speculative store bypass safe */ 404 CREATE_FEATURE_PRESENT(feat_ssbs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SSBS_SHIFT, 405 ID_AA64PFR1_EL1_SSBS_MASK, 1U, 406 FEAT_ENABLE_ALL_WORLDS) 407 408 /* FEAT_NMI: Non-maskable interrupts */ 409 CREATE_FEATURE_PRESENT(feat_nmi, id_aa64pfr1_el1, ID_AA64PFR1_EL1_NMI_SHIFT, 410 ID_AA64PFR1_EL1_NMI_MASK, NMI_IMPLEMENTED, 411 FEAT_ENABLE_ALL_WORLDS) 412 413 /* FEAT_EBEP */ 414 CREATE_PERCPU_FEATURE_FUNCS(feat_ebep, id_aa64dfr1_el1, ID_AA64DFR1_EBEP_SHIFT, 415 ID_AA64DFR1_EBEP_MASK, 1U, ENABLE_FEAT_EBEP, 416 FEAT_ENABLE_ALL_WORLDS) 417 418 /* FEAT_SEBEP */ 419 CREATE_PERCPU_FEATURE_PRESENT(feat_sebep, id_aa64dfr0_el1, ID_AA64DFR0_SEBEP_SHIFT, 420 ID_AA64DFR0_SEBEP_MASK, SEBEP_IMPLEMENTED, 421 FEAT_ENABLE_ALL_WORLDS) 422 423 /* FEAT_SEL2: Secure EL2 */ 424 CREATE_FEATURE_FUNCS(feat_sel2, id_aa64pfr0_el1, ID_AA64PFR0_SEL2_SHIFT, 425 ID_AA64PFR0_SEL2_MASK, 1U, ENABLE_FEAT_SEL2, 426 FEAT_ENABLE_ALL_WORLDS) 427 428 /* FEAT_TWED: Delayed trapping of WFE */ 429 CREATE_FEATURE_FUNCS(feat_twed, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_TWED_SHIFT, 430 ID_AA64MMFR1_EL1_TWED_MASK, 1U, ENABLE_FEAT_TWED, 431 FEAT_ENABLE_ALL_WORLDS) 432 433 /* FEAT_FGT: Fine-grained traps */ 434 CREATE_FEATURE_FUNCS(feat_fgt, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT, 435 ID_AA64MMFR0_EL1_FGT_MASK, 1U, ENABLE_FEAT_FGT, 436 FEAT_ENABLE_ALL_WORLDS) 437 438 /* FEAT_FGT2: Fine-grained traps extended */ 439 CREATE_FEATURE_FUNCS(feat_fgt2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT, 440 ID_AA64MMFR0_EL1_FGT_MASK, FGT2_IMPLEMENTED, ENABLE_FEAT_FGT2, 441 FEAT_ENABLE_ALL_WORLDS) 442 443 /* FEAT_FGWTE3: Fine-grained write traps EL3 */ 444 CREATE_FEATURE_FUNCS(feat_fgwte3, id_aa64mmfr4_el1, ID_AA64MMFR4_EL1_FGWTE3_SHIFT, 445 ID_AA64MMFR4_EL1_FGWTE3_MASK, FGWTE3_IMPLEMENTED, 446 ENABLE_FEAT_FGWTE3, FEAT_ENABLE_ALL_WORLDS) 447 448 /* FEAT_ECV: Enhanced Counter Virtualization */ 449 CREATE_FEATURE_FUNCS(feat_ecv, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT, 450 ID_AA64MMFR0_EL1_ECV_MASK, 1U, ENABLE_FEAT_ECV, 451 FEAT_ENABLE_ALL_WORLDS) 452 CREATE_FEATURE_FUNCS(feat_ecv_v2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT, 453 ID_AA64MMFR0_EL1_ECV_MASK, ID_AA64MMFR0_EL1_ECV_SELF_SYNCH, 454 ENABLE_FEAT_ECV, FEAT_ENABLE_ALL_WORLDS) 455 456 /* FEAT_RNG: Random number generator */ 457 CREATE_FEATURE_FUNCS(feat_rng, id_aa64isar0_el1, ID_AA64ISAR0_RNDR_SHIFT, 458 ID_AA64ISAR0_RNDR_MASK, 1U, ENABLE_FEAT_RNG, 459 FEAT_ENABLE_ALL_WORLDS) 460 461 /* FEAT_TCR2: Support TCR2_ELx regs */ 462 CREATE_FEATURE_FUNCS(feat_tcr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_TCRX_SHIFT, 463 ID_AA64MMFR3_EL1_TCRX_MASK, 1U, ENABLE_FEAT_TCR2, 464 FEAT_ENABLE_ALL_WORLDS) 465 466 /* FEAT_S2POE */ 467 CREATE_FEATURE_FUNCS(feat_s2poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2POE_SHIFT, 468 ID_AA64MMFR3_EL1_S2POE_MASK, 1U, ENABLE_FEAT_S2POE, 469 FEAT_ENABLE_ALL_WORLDS) 470 471 /* FEAT_S1POE */ 472 CREATE_FEATURE_FUNCS(feat_s1poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1POE_SHIFT, 473 ID_AA64MMFR3_EL1_S1POE_MASK, 1U, ENABLE_FEAT_S1POE, 474 FEAT_ENABLE_ALL_WORLDS) 475 476 __attribute__((always_inline)) 477 static inline bool is_feat_sxpoe_supported(void) 478 { 479 return is_feat_s1poe_supported() || is_feat_s2poe_supported(); 480 } 481 482 /* FEAT_S2PIE */ 483 CREATE_FEATURE_FUNCS(feat_s2pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2PIE_SHIFT, 484 ID_AA64MMFR3_EL1_S2PIE_MASK, 1U, ENABLE_FEAT_S2PIE, 485 FEAT_ENABLE_ALL_WORLDS) 486 487 /* FEAT_S1PIE */ 488 CREATE_FEATURE_FUNCS(feat_s1pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1PIE_SHIFT, 489 ID_AA64MMFR3_EL1_S1PIE_MASK, 1U, ENABLE_FEAT_S1PIE, 490 FEAT_ENABLE_ALL_WORLDS) 491 492 /* FEAT_THE: Translation Hardening Extension */ 493 CREATE_FEATURE_FUNCS(feat_the, id_aa64pfr1_el1, ID_AA64PFR1_EL1_THE_SHIFT, 494 ID_AA64PFR1_EL1_THE_MASK, THE_IMPLEMENTED, ENABLE_FEAT_THE, 495 FEAT_ENABLE_NS) 496 497 /* FEAT_SCTLR2 */ 498 CREATE_FEATURE_FUNCS(feat_sctlr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_SCTLR2_SHIFT, 499 ID_AA64MMFR3_EL1_SCTLR2_MASK, SCTLR2_IMPLEMENTED, 500 ENABLE_FEAT_SCTLR2, 501 FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 502 503 /* FEAT_D128 */ 504 CREATE_FEATURE_FUNCS(feat_d128, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_D128_SHIFT, 505 ID_AA64MMFR3_EL1_D128_MASK, D128_IMPLEMENTED, 506 ENABLE_FEAT_D128, FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 507 508 /* FEAT_RME_GPC2 */ 509 _CREATE_FEATURE_PRESENT(feat_rme_gpc2, id_aa64pfr0_el1, 510 ID_AA64PFR0_FEAT_RME_SHIFT, ID_AA64PFR0_FEAT_RME_MASK, 511 RME_GPC2_IMPLEMENTED) 512 513 /* FEAT_RME_GDI */ 514 CREATE_FEATURE_FUNCS(feat_rme_gdi, id_aa64mmfr4_el1, 515 ID_AA64MMFR4_EL1_RME_GDI_SHIFT, 516 ID_AA64MMFR4_EL1_RME_GDI_MASK, RME_GDI_IMPLEMENTED, 517 ENABLE_FEAT_RME_GDI, FEAT_ENABLE_ALL_WORLDS) 518 519 /* FEAT_FPMR */ 520 CREATE_FEATURE_FUNCS(feat_fpmr, id_aa64pfr2_el1, ID_AA64PFR2_EL1_FPMR_SHIFT, 521 ID_AA64PFR2_EL1_FPMR_MASK, FPMR_IMPLEMENTED, 522 ENABLE_FEAT_FPMR, FEAT_ENABLE_NS) 523 /* FEAT_MOPS */ 524 CREATE_FEATURE_FUNCS(feat_mops, id_aa64isar2_el1, ID_AA64ISAR2_EL1_MOPS_SHIFT, 525 ID_AA64ISAR2_EL1_MOPS_MASK, MOPS_IMPLEMENTED, 526 ENABLE_FEAT_MOPS, FEAT_ENABLE_ALL_WORLDS) 527 528 __attribute__((always_inline)) 529 static inline bool is_feat_sxpie_supported(void) 530 { 531 return is_feat_s1pie_supported() || is_feat_s2pie_supported(); 532 } 533 534 /* FEAT_GCS: Guarded Control Stack */ 535 CREATE_FEATURE_FUNCS(feat_gcs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_GCS_SHIFT, 536 ID_AA64PFR1_EL1_GCS_MASK, 1U, ENABLE_FEAT_GCS, 537 FEAT_ENABLE_ALL_WORLDS) 538 539 /* FEAT_AMU: Activity Monitors Extension */ 540 CREATE_FEATURE_FUNCS(feat_amu, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT, 541 ID_AA64PFR0_AMU_MASK, 1U, ENABLE_FEAT_AMU, 542 FEAT_ENABLE_NS) 543 544 /* Auxiliary counters for FEAT_AMU */ 545 _CREATE_FEATURE_PRESENT(feat_amu_aux, amcfgr_el0, 546 AMCFGR_EL0_NCG_SHIFT, AMCFGR_EL0_NCG_MASK, 1U) 547 548 CREATE_FEATURE_SUPPORTED(feat_amu_aux, is_feat_amu_aux_present, 549 ENABLE_AMU_AUXILIARY_COUNTERS) 550 551 /* FEAT_AMUV1P1: AMU Extension v1.1 */ 552 CREATE_FEATURE_FUNCS(feat_amuv1p1, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT, 553 ID_AA64PFR0_AMU_MASK, ID_AA64PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1, 554 FEAT_ENABLE_NS) 555 556 /* 557 * Return MPAM version: 558 * 559 * 0x00: None Armv8.0 or later 560 * 0x01: v0.1 Armv8.4 or later 561 * 0x10: v1.0 Armv8.2 or later 562 * 0x11: v1.1 Armv8.4 or later 563 * 564 */ 565 __attribute__((always_inline)) 566 static inline bool is_feat_mpam_present(void) 567 { 568 unsigned int ret = (unsigned int)((((read_id_aa64pfr0_el1() >> 569 ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) | 570 ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_MPAM_FRAC_SHIFT) 571 & ID_AA64PFR1_MPAM_FRAC_MASK)); 572 return ret; 573 } 574 575 CREATE_FEATURE_SUPPORTED(feat_mpam, is_feat_mpam_present, ENABLE_FEAT_MPAM) 576 577 578 #if (ENABLE_FEAT_IDTE3 && IMAGE_BL31) 579 __attribute__((always_inline)) 580 static inline void update_feat_mpam_idreg_field(size_t security_state) 581 { 582 if (SHOULD_ID_FIELD_DISABLE(ENABLE_FEAT_MPAM, 583 FEAT_ENABLE_NS | FEAT_ENABLE_REALM, security_state)) { 584 per_world_context_t *per_world_ctx = 585 &per_world_context[security_state]; 586 perworld_idregs_t *perworld_idregs = 587 &(per_world_ctx->idregs); 588 589 perworld_idregs->id_aa64pfr0_el1 &= 590 ~((u_register_t)ID_AA64PFR0_MPAM_MASK 591 << ID_AA64PFR0_MPAM_SHIFT); 592 593 perworld_idregs->id_aa64pfr1_el1 &= 594 ~((u_register_t)ID_AA64PFR1_MPAM_FRAC_MASK 595 << ID_AA64PFR1_MPAM_FRAC_SHIFT); 596 } 597 } 598 #endif 599 600 /* FEAT_MPAM_PE_BW_CTRL: MPAM PE-side bandwidth controls */ 601 __attribute__((always_inline)) 602 static inline bool is_feat_mpam_pe_bw_ctrl_present(void) 603 { 604 if (is_feat_mpam_present()) { 605 return ((unsigned long long)(read_mpamidr_el1() & 606 MPAMIDR_HAS_BW_CTRL_BIT) != 0U); 607 } 608 return false; 609 } 610 611 CREATE_FEATURE_SUPPORTED(feat_mpam_pe_bw_ctrl, is_feat_mpam_pe_bw_ctrl_present, 612 ENABLE_FEAT_MPAM_PE_BW_CTRL) 613 614 /* 615 * FEAT_DebugV8P9: Debug extension. This function checks the field 3:0 of 616 * ID_AA64DFR0 Aarch64 Debug Feature Register 0 for the version of 617 * Feat_Debug supported. The value of the field determines feature presence 618 * 619 * 0b0110 - Arm v8.0 debug 620 * 0b0111 - Arm v8.0 debug architecture with Virtualization host extensions 621 * 0x1000 - FEAT_Debugv8p2 is supported 622 * 0x1001 - FEAT_Debugv8p4 is supported 623 * 0x1010 - FEAT_Debugv8p8 is supported 624 * 0x1011 - FEAT_Debugv8p9 is supported 625 * 626 */ 627 CREATE_PERCPU_FEATURE_FUNCS(feat_debugv8p9, id_aa64dfr0_el1, 628 ID_AA64DFR0_DEBUGVER_SHIFT, ID_AA64DFR0_DEBUGVER_MASK, 629 DEBUGVER_V8P9_IMPLEMENTED, ENABLE_FEAT_DEBUGV8P9, 630 FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 631 632 /* FEAT_HCX: Extended Hypervisor Configuration Register */ 633 CREATE_FEATURE_FUNCS(feat_hcx, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_HCX_SHIFT, 634 ID_AA64MMFR1_EL1_HCX_MASK, 1U, ENABLE_FEAT_HCX, 635 FEAT_ENABLE_ALL_WORLDS) 636 637 /* FEAT_RNG_TRAP: Trapping support */ 638 CREATE_FEATURE_FUNCS(feat_rng_trap, id_aa64pfr1_el1, ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT, 639 ID_AA64PFR1_EL1_RNDR_TRAP_MASK, RNG_TRAP_IMPLEMENTED, ENABLE_FEAT_RNG_TRAP, 640 FEAT_ENABLE_ALL_WORLDS) 641 642 /* Return the RME version, zero if not supported. */ 643 _CREATE_FEATURE_PRESENT(feat_rme, id_aa64pfr0_el1, 644 ID_AA64PFR0_FEAT_RME_SHIFT, ID_AA64PFR0_FEAT_RME_MASK, 1U) 645 646 CREATE_FEATURE_SUPPORTED(feat_rme, is_feat_rme_present, ENABLE_RME) 647 648 /* FEAT_SB: Speculation barrier instruction */ 649 CREATE_FEATURE_PRESENT(feat_sb, id_aa64isar1_el1, ID_AA64ISAR1_SB_SHIFT, 650 ID_AA64ISAR1_SB_MASK, 1U, 651 FEAT_ENABLE_ALL_WORLDS) 652 653 /* FEAT_MEC: Memory Encryption Contexts */ 654 CREATE_FEATURE_FUNCS(feat_mec, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_MEC_SHIFT, 655 ID_AA64MMFR3_EL1_MEC_MASK, 1U, ENABLE_FEAT_MEC, 656 FEAT_ENABLE_ALL_WORLDS) 657 658 /* 659 * FEAT_CSV2: Cache Speculation Variant 2. This checks bit fields[56-59] 660 * of id_aa64pfr0_el1 register and can be used to check for below features: 661 * FEAT_CSV2_2: Cache Speculation Variant CSV2_2. 662 * FEAT_CSV2_3: Cache Speculation Variant CSV2_3. 663 * 0b0000 - Feature FEAT_CSV2 is not implemented. 664 * 0b0001 - Feature FEAT_CSV2 is implemented, but FEAT_CSV2_2 and FEAT_CSV2_3 665 * are not implemented. 666 * 0b0010 - Feature FEAT_CSV2_2 is implemented but FEAT_CSV2_3 is not 667 * implemented. 668 * 0b0011 - Feature FEAT_CSV2_3 is implemented. 669 */ 670 671 CREATE_FEATURE_FUNCS(feat_csv2_2, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT, 672 ID_AA64PFR0_CSV2_MASK, CSV2_2_IMPLEMENTED, ENABLE_FEAT_CSV2_2, 673 FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 674 CREATE_FEATURE_FUNCS(feat_csv2_3, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT, 675 ID_AA64PFR0_CSV2_MASK, CSV2_3_IMPLEMENTED, ENABLE_FEAT_CSV2_3, 676 FEAT_ENABLE_ALL_WORLDS) 677 678 /* FEAT_SPE: Statistical Profiling Extension */ 679 CREATE_PERCPU_FEATURE_FUNCS(feat_spe, id_aa64dfr0_el1, ID_AA64DFR0_PMS_SHIFT, 680 ID_AA64DFR0_PMS_MASK, 1U, ENABLE_SPE_FOR_NS, 681 FEAT_ENABLE_ALL_WORLDS) 682 683 /* FEAT_SVE: Scalable Vector Extension */ 684 CREATE_FEATURE_FUNCS(feat_sve, id_aa64pfr0_el1, ID_AA64PFR0_SVE_SHIFT, 685 ID_AA64PFR0_SVE_MASK, 1U, ENABLE_SVE_FOR_NS, 686 FEAT_ENABLE_ALL_WORLDS) 687 688 /* FEAT_RAS: Reliability, Accessibility, Serviceability */ 689 CREATE_FEATURE_FUNCS(feat_ras, id_aa64pfr0_el1, ID_AA64PFR0_RAS_SHIFT, 690 ID_AA64PFR0_RAS_MASK, 1U, ENABLE_FEAT_RAS, 691 FEAT_ENABLE_ALL_WORLDS) 692 693 /* FEAT_DIT: Data Independent Timing instructions */ 694 CREATE_FEATURE_FUNCS(feat_dit, id_aa64pfr0_el1, ID_AA64PFR0_DIT_SHIFT, 695 ID_AA64PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT, 696 FEAT_ENABLE_ALL_WORLDS) 697 698 /* FEAT_SYS_REG_TRACE */ 699 CREATE_PERCPU_FEATURE_FUNCS(feat_sys_reg_trace, id_aa64dfr0_el1, 700 ID_AA64DFR0_TRACEVER_SHIFT, ID_AA64DFR0_TRACEVER_MASK, 701 1U, ENABLE_SYS_REG_TRACE_FOR_NS, 702 FEAT_ENABLE_ALL_WORLDS) 703 704 /* FEAT_TRF: TraceFilter */ 705 CREATE_PERCPU_FEATURE_FUNCS(feat_trf, id_aa64dfr0_el1, ID_AA64DFR0_TRACEFILT_SHIFT, 706 ID_AA64DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS, 707 FEAT_ENABLE_ALL_WORLDS) 708 709 /* FEAT_NV2: Enhanced Nested Virtualization */ 710 CREATE_FEATURE_FUNCS(feat_nv2, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_NV_SHIFT, 711 ID_AA64MMFR2_EL1_NV_MASK, NV2_IMPLEMENTED, CTX_INCLUDE_NEVE_REGS, 712 FEAT_ENABLE_ALL_WORLDS) 713 714 /* FEAT_BRBE: Branch Record Buffer Extension */ 715 CREATE_PERCPU_FEATURE_FUNCS(feat_brbe, id_aa64dfr0_el1, ID_AA64DFR0_BRBE_SHIFT, 716 ID_AA64DFR0_BRBE_MASK, 1U, ENABLE_BRBE_FOR_NS, 717 FEAT_ENABLE_NS | FEAT_ENABLE_REALM) 718 719 /* FEAT_TRBE: Trace Buffer Extension */ 720 _CREATE_FEATURE_PRESENT(feat_trbe, id_aa64dfr0_el1, ID_AA64DFR0_TRACEBUFFER_SHIFT, 721 ID_AA64DFR0_TRACEBUFFER_MASK, 1U) 722 723 CREATE_FEATURE_SUPPORTED(feat_trbe, is_feat_trbe_present, ENABLE_TRBE_FOR_NS) 724 725 CREATE_PERCPU_IDREG_UPDATE(feat_trbe, id_aa64dfr0_el1, ID_AA64DFR0_TRACEBUFFER_SHIFT, 726 ID_AA64DFR0_TRACEBUFFER_MASK, 727 ENABLE_TRBE_FOR_NS && !check_if_trbe_disable_affected_core(), 728 FEAT_ENABLE_NS) 729 730 /* FEAT_SME_FA64: Full A64 Instruction support in streaming SVE mode */ 731 CREATE_FEATURE_PRESENT(feat_sme_fa64, id_aa64smfr0_el1, ID_AA64SMFR0_EL1_SME_FA64_SHIFT, 732 ID_AA64SMFR0_EL1_SME_FA64_MASK, 1U, 733 FEAT_ENABLE_ALL_WORLDS) 734 735 /* FEAT_SMEx: Scalar Matrix Extension */ 736 CREATE_FEATURE_FUNCS(feat_sme, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT, 737 ID_AA64PFR1_EL1_SME_MASK, 1U, ENABLE_SME_FOR_NS, 738 FEAT_ENABLE_ALL_WORLDS) 739 740 CREATE_FEATURE_FUNCS(feat_sme2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT, 741 ID_AA64PFR1_EL1_SME_MASK, SME2_IMPLEMENTED, ENABLE_SME2_FOR_NS, 742 FEAT_ENABLE_ALL_WORLDS) 743 744 /* FEAT_LS64_ACCDATA: Support for 64-byte EL0 stores with status */ 745 CREATE_FEATURE_FUNCS(feat_ls64_accdata, id_aa64isar1_el1, ID_AA64ISAR1_LS64_SHIFT, 746 ID_AA64ISAR1_LS64_MASK, LS64_ACCDATA_IMPLEMENTED, 747 ENABLE_FEAT_LS64_ACCDATA, FEAT_ENABLE_ALL_WORLDS) 748 749 /* FEAT_AIE: Memory Attribute Index Enhancement */ 750 CREATE_FEATURE_FUNCS(feat_aie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_AIE_SHIFT, 751 ID_AA64MMFR3_EL1_AIE_MASK, 1U, ENABLE_FEAT_AIE, 752 FEAT_ENABLE_NS) 753 754 /* FEAT_PFAR: Physical Fault Address Register Extension */ 755 CREATE_FEATURE_FUNCS(feat_pfar, id_aa64pfr1_el1, ID_AA64PFR1_EL1_PFAR_SHIFT, 756 ID_AA64PFR1_EL1_PFAR_MASK, 1U, ENABLE_FEAT_PFAR, 757 FEAT_ENABLE_NS) 758 759 /* FEAT_IDTE3: Trapping lower EL ID Register access to EL3 */ 760 CREATE_FEATURE_FUNCS(feat_idte3, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_IDS_SHIFT, 761 ID_AA64MMFR2_EL1_IDS_MASK, 2U, ENABLE_FEAT_IDTE3, 762 FEAT_ENABLE_ALL_WORLDS) 763 764 /******************************************************************************* 765 * Function to get hardware granularity support 766 ******************************************************************************/ 767 768 __attribute__((always_inline)) 769 static inline bool is_feat_tgran4K_present(void) 770 { 771 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(), 772 ID_AA64MMFR0_EL1_TGRAN4_SHIFT, ID_REG_FIELD_MASK); 773 return (tgranx < 8U); 774 } 775 776 CREATE_FEATURE_PRESENT(feat_tgran16K, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_TGRAN16_SHIFT, 777 ID_AA64MMFR0_EL1_TGRAN16_MASK, TGRAN16_IMPLEMENTED, 778 FEAT_ENABLE_ALL_WORLDS) 779 780 __attribute__((always_inline)) 781 static inline bool is_feat_tgran64K_present(void) 782 { 783 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(), 784 ID_AA64MMFR0_EL1_TGRAN64_SHIFT, ID_REG_FIELD_MASK); 785 return (tgranx < 8U); 786 } 787 788 /* FEAT_PMUV3 */ 789 _CREATE_FEATURE_PRESENT(feat_pmuv3, id_aa64dfr0_el1, ID_AA64DFR0_PMUVER_SHIFT, 790 ID_AA64DFR0_PMUVER_MASK, 1U) 791 792 /* FEAT_MTPMU */ 793 __attribute__((always_inline)) 794 static inline bool is_feat_mtpmu_present(void) 795 { 796 unsigned int mtpmu = ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_MTPMU_SHIFT, 797 ID_AA64DFR0_MTPMU_MASK); 798 return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED); 799 } 800 801 CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU) 802 803 CREATE_PERCPU_IDREG_UPDATE(feat_mtpmu, id_aa64dfr0_el1, ID_AA64DFR0_MTPMU_SHIFT, 804 ID_AA64DFR0_MTPMU_MASK, DISABLE_MTPMU, 805 FEAT_ENABLE_ALL_WORLDS) 806 807 /************************************************************************* 808 * Function to identify the presence of FEAT_GCIE (GICv5 CPU interface 809 * extension). 810 ************************************************************************/ 811 CREATE_FEATURE_FUNCS(feat_gcie, id_aa64pfr2_el1, ID_AA64PFR2_EL1_GCIE_SHIFT, 812 ID_AA64PFR2_EL1_GCIE_MASK, 1U, ENABLE_FEAT_GCIE, 813 FEAT_ENABLE_ALL_WORLDS) 814 815 CREATE_FEATURE_FUNCS(feat_cpa2, id_aa64isar3_el1, ID_AA64ISAR3_EL1_CPA_SHIFT, 816 ID_AA64ISAR3_EL1_CPA_MASK, CPA2_IMPLEMENTED, 817 ENABLE_FEAT_CPA2, FEAT_ENABLE_ALL_WORLDS) 818 819 /* FEAT_UINJ: Injection of Undefined Instruction exceptions */ 820 CREATE_FEATURE_FUNCS(feat_uinj, id_aa64pfr2_el1, ID_AA64PFR2_EL1_UINJ_SHIFT, 821 ID_AA64PFR2_EL1_UINJ_MASK, UINJ_IMPLEMENTED, 822 ENABLE_FEAT_UINJ, FEAT_ENABLE_ALL_WORLDS) 823 #endif /* ARCH_FEATURES_H */ 824