]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
refactor(trbe): enable FEAT_TRBE for FEAT_STATE_CHECKED
authorAndre Przywara <andre.przywara@arm.com>
Thu, 17 Nov 2022 16:42:09 +0000 (16:42 +0000)
committerAndre Przywara <andre.przywara@arm.com>
Mon, 27 Feb 2023 18:04:14 +0000 (18:04 +0000)
At the moment we only support FEAT_TRBE to be either unconditionally
compiled in, or to be not supported at all.

Add support for runtime detection (ENABLE_TRBE_FOR_NS=2), by splitting
is_feat_trbe_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 access TRBE related registers.

The FVP platform decided to compile in support unconditionally (=1),
even though FEAT_TRBE is an ARMv9 feature, so is not available with the
FVP model's default command line.
Change that to the now supported dynamic option (=2), so the right
decision can be made by the code at runtime.

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

index e6609fe863a10dbbda7da197f67f6bbce79b05df..4d2fc874dbef1eacdbb9e7773360cc3da03f064a 100644 (file)
@@ -112,7 +112,7 @@ ifeq (${ENABLE_MPAM_FOR_LOWER_ELS},1)
 BL31_SOURCES           +=      lib/extensions/mpam/mpam.c
 endif
 
-ifeq (${ENABLE_TRBE_FOR_NS},1)
+ifneq (${ENABLE_TRBE_FOR_NS},0)
 BL31_SOURCES           +=      lib/extensions/trbe/trbe.c
 endif
 
index cbe78c057f9c9f65a457a6e6f39eec47218453ee..3012c8bbe68ce1868de612c39a5c69ab3df51ca1 100644 (file)
@@ -258,16 +258,6 @@ static void read_feat_brbe(void)
 #endif
 }
 
-/******************************************************
- * Feature : FEAT_TRBE (Trace Buffer Extension)
- *****************************************************/
-static void read_feat_trbe(void)
-{
-#if (ENABLE_TRBE_FOR_NS == FEAT_STATE_ALWAYS)
-       feat_detect_panic(is_feat_trbe_present(), "TRBE");
-#endif
-}
-
 /******************************************************************
  * Feature : FEAT_RNG_TRAP (Trapping support for RNDR/RNDRRS)
  *****************************************************************/
@@ -345,7 +335,8 @@ void detect_arch_features(void)
 
        /* v9.0 features */
        read_feat_brbe();
-       read_feat_trbe();
+       check_feature(ENABLE_TRBE_FOR_NS, read_feat_trbe_id_field(),
+                     "TRBE", 1, 1);
 
        /* v9.2 features */
        read_feat_rme();
index 14f5cc775255b48cc643a2b59af5001cb781e4c3..ded42d477c4f6b62023b595192c4ab89049bb4f8 100644 (file)
@@ -297,10 +297,22 @@ static inline bool is_feat_brbe_present(void)
 /*******************************************************************************
  * Function to identify the presence of FEAT_TRBE (Trace Buffer Extension)
  ******************************************************************************/
-static inline bool is_feat_trbe_present(void)
+static inline unsigned int read_feat_trbe_id_field(void)
 {
-       return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_TRACEBUFFER_SHIFT) &
-               ID_AA64DFR0_TRACEBUFFER_MASK) == ID_AA64DFR0_TRACEBUFFER_SUPPORTED);
+       return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_TRACEBUFFER);
 }
 
+static inline bool is_feat_trbe_supported(void)
+{
+       if (ENABLE_TRBE_FOR_NS == FEAT_STATE_DISABLED) {
+               return false;
+       }
+
+       if (ENABLE_TRBE_FOR_NS == FEAT_STATE_ALWAYS) {
+               return true;
+       }
+
+       return read_feat_trbe_id_field() != 0U;
+
+}
 #endif /* ARCH_FEATURES_H */
index 341c4a5d024499df138de08c171c81cce7108b80..1dfb71f76b36d19e7176d1ceed60a66ee5767ef7 100644 (file)
@@ -495,9 +495,9 @@ static void manage_extensions_nonsecure(bool el2_unused, cpu_context_t *ctx)
        mpam_enable(el2_unused);
 #endif
 
-#if ENABLE_TRBE_FOR_NS
-       trbe_enable();
-#endif /* ENABLE_TRBE_FOR_NS */
+       if (is_feat_trbe_supported()) {
+               trbe_enable();
+       }
 
 #if ENABLE_BRBE_FOR_NS
        brbe_enable();
index b3463872ba6456386efd9906810b08fab5b7c216..fa139cad22729c936c822688adcb9bb0cc2cc21e 100644 (file)
@@ -23,22 +23,20 @@ void trbe_enable(void)
 {
        uint64_t val;
 
-       if (is_feat_trbe_present()) {
-               /*
-                * MDCR_EL3.NSTB = 0b11
-                * Allow access of trace buffer control registers from NS-EL1
-                * and NS-EL2, tracing is prohibited in Secure and Realm state
-                * (if implemented).
-                */
-               val = read_mdcr_el3();
-               val |= MDCR_NSTB(MDCR_NSTB_EL1);
-               write_mdcr_el3(val);
-       }
+       /*
+        * MDCR_EL3.NSTB = 0b11
+        * Allow access of trace buffer control registers from NS-EL1
+        * and NS-EL2, tracing is prohibited in Secure and Realm state
+        * (if implemented).
+        */
+       val = read_mdcr_el3();
+       val |= MDCR_NSTB(MDCR_NSTB_EL1);
+       write_mdcr_el3(val);
 }
 
 static void *trbe_drain_trace_buffers_hook(const void *arg __unused)
 {
-       if (is_feat_trbe_present()) {
+       if (is_feat_trbe_supported()) {
                /*
                 * Before switching from normal world to secure world
                 * the trace buffers need to be drained out to memory. This is
index efbf68f00526ad77ab2108051884dde35ed708e8..7991c14f6bee6c0253c5ff27d8277256eada6cc1 100644 (file)
@@ -446,7 +446,7 @@ DYN_DISABLE_AUTH    :=      1
 endif
 
 # enable trace buffer control registers access to NS by default
-ENABLE_TRBE_FOR_NS             := 1
+ENABLE_TRBE_FOR_NS             := 2
 
 # enable branch record buffer control registers access in NS by default
 # only enable for aarch64