]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
feat(rng-trap): add EL3 support for FEAT_RNG_TRAP
authorJuan Pablo Conde <juanpablo.conde@arm.com>
Tue, 12 Jul 2022 20:40:29 +0000 (16:40 -0400)
committerJuan Pablo Conde <juanpablo.conde@arm.com>
Thu, 18 Aug 2022 19:53:54 +0000 (15:53 -0400)
FEAT_RNG_TRAP introduces support for EL3 trapping of reads of the
RNDR and RNDRRS registers, which is enabled by setting the
SCR_EL3.TRNDR bit. This patch adds a new build flag
ENABLE_FEAT_RNG_TRAP that enables the feature.
This feature is supported only in AArch64 state from Armv8.5 onwards.

Signed-off-by: Juan Pablo Conde <juanpablo.conde@arm.com>
Change-Id: Ia9f17aef3444d3822bf03809036a1f668c9f2d89

Makefile
changelog.yaml
common/feat_detect.c
docs/getting_started/build-options.rst
include/arch/aarch64/arch.h
include/arch/aarch64/arch_features.h
lib/el3_runtime/aarch64/context_mgmt.c
make_helpers/defaults.mk

index ee5e2e7a86e2808d7aea2d6c86b2d09bcd7109fa..8d8facdfb4f166b97ada6c9c088aca350bfc24e8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -788,11 +788,15 @@ ifeq (${ARCH},aarch32)
         $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
     endif
 
-    # BRBE is not supported in Aarch32
+    # BRBE is not supported in AArch32
     ifeq (${ENABLE_BRBE_FOR_NS},1)
         $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
     endif
 
+    # FEAT_RNG_TRAP is not supported in AArch32
+    ifeq (${ENABLE_FEAT_RNG_TRAP},1)
+        $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
+    endif
 endif
 
 # Ensure ENABLE_RME is not used with SME
@@ -1073,6 +1077,7 @@ $(eval $(call assert_numerics,\
         ENABLE_FEAT_HCX \
         ENABLE_FEAT_PAN \
         ENABLE_FEAT_RNG \
+        ENABLE_FEAT_RNG_TRAP \
         ENABLE_FEAT_SB \
         ENABLE_FEAT_SEL2 \
         ENABLE_FEAT_VHE \
@@ -1183,6 +1188,7 @@ $(eval $(call add_defines,\
         COT_DESC_IN_DTB \
         USE_SP804_TIMER \
         ENABLE_FEAT_RNG \
+        ENABLE_FEAT_RNG_TRAP \
         ENABLE_FEAT_SB \
         ENABLE_FEAT_DIT \
         NR_OF_FW_BANKS \
index c4028c4f9094d235808c8e32fe4444d868f9fa70..986d303f44f757cf88b178ecb046c1af632ec09e 100644 (file)
@@ -125,6 +125,9 @@ subsections:
       - title: Extended Cache Index (FEAT_CCIDX)
         scope: ccidx
 
+      - title: Trapping support for RNDR/RNDRRS (FEAT_RNG_TRAP)
+        scope: rng-trap
+
   - title: Platforms
 
     subsections:
index be3e20e6f976090854b73f1aea9d3c10631e4d1c..ee34588658b81cf7d65498b051d5528c2247c371 100644 (file)
@@ -254,6 +254,16 @@ static void read_feat_trbe(void)
 #endif
 }
 
+/******************************************************************
+ * Feature : FEAT_RNG_TRAP (Trapping support for RNDR/RNDRRS)
+ *****************************************************************/
+static void read_feat_rng_trap(void)
+{
+#if (ENABLE_FEAT_RNG_TRAP == FEAT_STATE_1)
+       feat_detect_panic(is_feat_rng_trap_present(), "RNG_TRAP");
+#endif
+}
+
 /***********************************************************************************
  * TF-A supports many Arm architectural features starting from arch version
  * (8.0 till 8.7+). These features are mostly enabled through build flags. This
@@ -304,6 +314,7 @@ void detect_arch_features(void)
        read_feat_mte();
        read_feat_rng();
        read_feat_bti();
+       read_feat_rng_trap();
 
        /* v8.6 features */
        read_feat_amuv1p1();
index b291d626b8cd7c916c5a4afe1b37c43c40d45792..80593a1f980b258fd3e03c82f57d7de8fdcc8363 100644 (file)
@@ -313,7 +313,13 @@ Common build options
 -  ``ENABLE_FEAT_RNG``: Numeric value to enable the ``FEAT_RNG`` extension.
    ``FEAT_RNG`` is an optional feature available on Arm v8.5 onwards. This
    flag can take the values 0 to 2, to align with the ``FEATURE_DETECTION``
-   mechanism. Default is ``0``.
+   mechanism. Default value is ``0``.
+
+-  ``ENABLE_FEAT_RNG_TRAP``: Numeric value to enable the ``FEAT_RNG_TRAP``
+   extension. This feature is only supported in AArch64 state. This flag can
+   take values 0 to 2, to align with the ``FEATURE_DETECTION`` mechanism.
+   Default value is ``0``. ``FEAT_RNG_TRAP`` is an optional feature from
+   Armv8.5 onwards.
 
 -  ``ENABLE_FEAT_SB``: Numeric value to enable the ``FEAT_SB`` (Speculation
    Barrier) extension allowing access to ``sb`` instruction. ``FEAT_SB`` is an
index e55d33fd39d6f31cdc4cd406340620b563ea4aa2..3a2a032fdb7b6439530ca5cddea10edf295250a9 100644 (file)
 #define ID_AA64PFR1_EL1_MTE_SHIFT      U(8)
 #define ID_AA64PFR1_EL1_MTE_MASK       ULL(0xf)
 
+#define ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT        U(28)
+#define ID_AA64PFR1_EL1_RNDR_TRAP_MASK U(0xf)
+
+#define ID_AA64PFR1_EL1_RNG_TRAP_SUPPORTED     ULL(0x1)
+#define ID_AA64PFR1_EL1_RNG_TRAP_NOT_SUPPORTED ULL(0x0)
+
 /* Memory Tagging Extension is not implemented */
 #define MTE_UNIMPLEMENTED      U(0)
 /* FEAT_MTE: MTE instructions accessible at EL0 are implemented */
 #define SCR_GPF_BIT            (UL(1) << 48)
 #define SCR_TWEDEL_SHIFT       U(30)
 #define SCR_TWEDEL_MASK                ULL(0xf)
+#define SCR_TRNDR_BIT          (UL(1) << 40)
 #define SCR_HXEn_BIT           (UL(1) << 38)
 #define SCR_ENTP2_SHIFT                U(41)
 #define SCR_ENTP2_BIT          (UL(1) << SCR_ENTP2_SHIFT)
index 79a61b5bb9343b2b06e5116f9a70935ef6af2309..0af5b747d46d96d7086ada187b2640af22bbe706 100644 (file)
@@ -129,6 +129,13 @@ static inline bool is_feat_hcx_present(void)
                ID_AA64MMFR1_EL1_HCX_MASK) == ID_AA64MMFR1_EL1_HCX_SUPPORTED);
 }
 
+static inline bool is_feat_rng_trap_present(void)
+{
+       return (((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT) &
+                       ID_AA64PFR1_EL1_RNDR_TRAP_MASK)
+                       == ID_AA64PFR1_EL1_RNG_TRAP_SUPPORTED);
+}
+
 static inline unsigned int get_armv9_2_feat_rme_support(void)
 {
        /*
index da610d06b68328587eec91ba103bcd4eb0b2b582..68aacc1bbfa6c1bbc17732458c2b2f915339603e 100644 (file)
@@ -299,6 +299,14 @@ static void setup_context_common(cpu_context_t *ctx, const entry_point_info_t *e
        scr_el3 |= SCR_HXEn_BIT;
 #endif
 
+       /*
+        * If FEAT_RNG_TRAP is enabled, all reads of the RNDR and RNDRRS
+        * registers are trapped to EL3.
+        */
+#if ENABLE_FEAT_RNG_TRAP
+       scr_el3 |= SCR_TRNDR_BIT;
+#endif
+
 #if RAS_TRAP_LOWER_EL_ERR_ACCESS
        /*
         * SCR_EL3.TERR: Trap Error record accesses. Accesses to the RAS ERR
index fab6bf6dae42a3819581b7bb7d4eb4ec543bd324..42ebd33c47f0f73c5ec0459193c00d91baee8ad8 100644 (file)
@@ -160,6 +160,10 @@ ENABLE_FEAT_PAN                    := 0
 # Flag to enable access to the Random Number Generator registers
 ENABLE_FEAT_RNG                        := 0
 
+# Flag to enable support for EL3 trapping of reads of the RNDR and RNDRRS
+# registers, by setting SCR_EL3.TRNDR.
+ENABLE_FEAT_RNG_TRAP           := 0
+
 # Flag to enable Speculation Barrier Instruction
 ENABLE_FEAT_SB                 := 0