]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
refactor(cpufeat): enable FEAT_TWED for FEAT_STATE_CHECKED
authorAndre Przywara <andre.przywara@arm.com>
Fri, 27 Jan 2023 12:25:49 +0000 (12:25 +0000)
committerAndre Przywara <andre.przywara@arm.com>
Wed, 22 Mar 2023 13:33:22 +0000 (13:33 +0000)
At the moment we only support FEAT_TWED to be either unconditionally
compiled in, or to be not supported at all.

Add support for runtime detection (ENABLE_FEAT_TWED=2), by splitting
is_armv8_6_twed_present() into an ID register reading function and a
second function to report the support status. That function considers
both build time settings and runtime information (if needed), and is
used before we set the trap delay time.

Change the FVP platform default to the now supported dynamic option (=2),
so the right decision can be made by the code at runtime.

Change-Id: I58626230ef0af49886c0a197abace01e81f661d2
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
common/feat_detect.c
include/arch/aarch64/arch_features.h
lib/el3_runtime/aarch64/context_mgmt.c
plat/arm/board/fvp/platform.mk

index bdadde1f41d00b30968e9de4fc76d2202992393d..b335a610f6c453ee94a0c8a90537461cb98535dd 100644 (file)
@@ -154,16 +154,6 @@ static void read_feat_amuv1p1(void)
 #endif
 }
 
-/***********************************************************
- * Feature : FEAT_TWED (Delayed Trapping of WFE Instruction)
- **********************************************************/
-static void read_feat_twed(void)
-{
-#if (ENABLE_FEAT_TWED == FEAT_STATE_ALWAYS)
-       feat_detect_panic(is_armv8_6_twed_present(), "TWED");
-#endif
-}
-
 /**************************************************
  * Feature : FEAT_RME (Realm Management Extension)
  *************************************************/
@@ -248,7 +238,8 @@ void detect_arch_features(void)
        read_feat_amuv1p1();
        check_feature(ENABLE_FEAT_FGT, read_feat_fgt_id_field(), "FGT", 1, 1);
        check_feature(ENABLE_FEAT_ECV, read_feat_ecv_id_field(), "ECV", 1, 2);
-       read_feat_twed();
+       check_feature(ENABLE_FEAT_TWED, read_feat_twed_id_field(),
+                     "TWED", 1, 1);
 
        /* v8.7 features */
        check_feature(ENABLE_FEAT_HCX, read_feat_hcx_id_field(), "HCX", 1, 1);
index 0342d2f7cf0f6447b3d22282a1f03823efad3e4d..fa80154761cc35c853f0c063c518b4201f34f94a 100644 (file)
@@ -119,10 +119,22 @@ static inline bool is_armv8_4_sel2_present(void)
                ID_AA64PFR0_SEL2_MASK) == 1ULL;
 }
 
-static inline bool is_armv8_6_twed_present(void)
+static inline unsigned int read_feat_twed_id_field(void)
 {
-       return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_TWED_SHIFT) &
-               ID_AA64MMFR1_EL1_TWED_MASK) == ID_AA64MMFR1_EL1_TWED_SUPPORTED);
+       return ISOLATE_FIELD(read_id_aa64mmfr1_el1(), ID_AA64MMFR1_EL1_TWED);
+}
+
+static inline bool is_feat_twed_supported(void)
+{
+       if (ENABLE_FEAT_TWED == FEAT_STATE_DISABLED) {
+               return false;
+       }
+
+       if (ENABLE_FEAT_TWED == FEAT_STATE_ALWAYS) {
+               return true;
+       }
+
+       return read_feat_twed_id_field() != 0U;
 }
 
 static unsigned int read_feat_fgt_id_field(void)
index 8430c06e8a15bf15b07aad46f14a170a5d1f0540..8f46b80dc306d1d2a8761bc76c7703a068a0ef27 100644 (file)
@@ -385,16 +385,16 @@ static void setup_context_common(cpu_context_t *ctx, const entry_point_info_t *e
                }
        }
 
-#if ENABLE_FEAT_TWED
        /* Enable WFE trap delay in SCR_EL3 if supported and configured */
-       /* Set delay in SCR_EL3 */
-       scr_el3 &= ~(SCR_TWEDEL_MASK << SCR_TWEDEL_SHIFT);
-       scr_el3 |= ((TWED_DELAY & SCR_TWEDEL_MASK)
-                       << SCR_TWEDEL_SHIFT);
-
-       /* Enable WFE delay */
-       scr_el3 |= SCR_TWEDEn_BIT;
-#endif /* ENABLE_FEAT_TWED */
+       if (is_feat_twed_supported()) {
+               /* Set delay in SCR_EL3 */
+               scr_el3 &= ~(SCR_TWEDEL_MASK << SCR_TWEDEL_SHIFT);
+               scr_el3 |= ((TWED_DELAY & SCR_TWEDEL_MASK)
+                               << SCR_TWEDEL_SHIFT);
+
+               /* Enable WFE delay */
+               scr_el3 |= SCR_TWEDEn_BIT;
+       }
 
        /*
         * Populate EL3 state so that we've the right context
index 03fe9cc0b760e62b08134b7b4e2559e48e678c09..a6f8eaf64345bee7acd9ef1c6a0e951899ff1e57 100644 (file)
@@ -473,6 +473,7 @@ ENABLE_FEAT_TCR2            := 2
 ENABLE_FEAT_CSV2_2             := 2
 ENABLE_FEAT_ECV                        := 2
 ENABLE_FEAT_PAN                        := 2
+ENABLE_FEAT_TWED               := 2
 ENABLE_FEAT_VHE                        := 2
 ENABLE_MPAM_FOR_LOWER_ELS      := 2