diff --git a/Makefile b/Makefile index da3e4931e..15340b455 100644 --- a/Makefile +++ b/Makefile @@ -1061,6 +1061,8 @@ $(eval $(call assert_numerics,\ NR_OF_FW_BANKS \ NR_OF_IMAGES_IN_FW_BANK \ RAS_EXTENSION \ + TWED_DELAY \ + ENABLE_FEAT_TWED \ ))) ifdef KEY_SIZE @@ -1176,6 +1178,8 @@ $(eval $(call add_defines,\ ENABLE_FEAT_CSV2_2 \ ENABLE_FEAT_PAN \ FEATURE_DETECTION \ + TWED_DELAY \ + ENABLE_FEAT_TWED \ ))) ifeq (${SANITIZE_UB},trap) diff --git a/common/feat_detect.c b/common/feat_detect.c index ef09b8657..8f98876ac 100644 --- a/common/feat_detect.c +++ b/common/feat_detect.c @@ -203,6 +203,16 @@ static void read_feat_ecv(void) #endif } +/*********************************************************** + * Feature : FEAT_TWED (Delayed Trapping of WFE Instruction) + **********************************************************/ +static void read_feat_twed(void) +{ +#if (ENABLE_FEAT_TWED == FEAT_STATE_1) + feat_detect_panic(is_armv8_6_twed_present(), "TWED"); +#endif +} + /****************************************************************** * Feature : FEAT_HCX (Extended Hypervisor Configuration Register) *****************************************************************/ @@ -279,6 +289,7 @@ void detect_arch_features(void) read_feat_amuv1p1(); read_feat_fgt(); read_feat_ecv(); + read_feat_twed(); /* v8.7 features */ read_feat_hcx(); diff --git a/docs/getting_started/build-options.rst b/docs/getting_started/build-options.rst index 4dbf5cb9f..176ec2704 100644 --- a/docs/getting_started/build-options.rst +++ b/docs/getting_started/build-options.rst @@ -327,6 +327,14 @@ Common build options This flag can take values 0 to 2, to align with the ``FEATURE_DETECTION`` mechanism. Default is ``0``. +- ``ENABLE_FEAT_TWED``: Numeric value to enable the ``FEAT_TWED`` (Delayed + trapping of WFE Instruction) extension. ``FEAT_TWED`` is a optional feature + available on Arm v8.6. This flag can take values 0 to 2, to align with the + ``FEATURE_DETECTION`` mechanism. Default is ``0``. + + When ``ENABLE_FEAT_TWED`` is set to ``1``, WFE instruction trapping gets + delayed by the amount of value in ``TWED_DELAY``. + - ``ENABLE_FEAT_VHE``: Numeric value to enable the ``FEAT_VHE`` (Virtualization Host Extensions) extension. It allows access to CONTEXTIDR_EL2 register during EL2 context save/restore operations.``FEAT_VHE`` is a mandatory @@ -838,6 +846,12 @@ Common build options When ``EL3_EXCEPTION_HANDLING`` is ``1``, ``TSP_NS_INTR_ASYNC_PREEMPT`` must also be set to ``1``. +- ``TWED_DELAY``: Numeric value to be set in order to delay the trapping of + WFE instruction. ``ENABLE_FEAT_TWED`` build option must be enabled to set + this delay. It can take values in the range (0-15). Default value is ``0`` + and based on this value, 2^(TWED_DELAY + 8) cycles will be delayed. + Platforms need to explicitly update this value based on their requirements. + - ``USE_ARM_LINK``: This flag determines whether to enable support for ARM linker. When the ``LINKER`` build variable points to the armlink linker, this flag is enabled automatically. To enable support for armlink, platforms diff --git a/docs/getting_started/porting-guide.rst b/docs/getting_started/porting-guide.rst index 3d3b2e3e3..2c6a0059e 100644 --- a/docs/getting_started/porting-guide.rst +++ b/docs/getting_started/porting-guide.rst @@ -2118,21 +2118,6 @@ frequency for the CPU's generic timer. This value will be programmed into the of the system counter, which is retrieved from the first entry in the frequency modes table. -Function : plat_arm_set_twedel_scr_el3() [optional] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -:: - - Argument : void - Return : uint32_t - -This function is used in v8.6+ systems to set the WFE trap delay value in -SCR_EL3. If this function returns TWED_DISABLED or is left unimplemented, this -feature is not enabled. The only hook provided is to set the TWED fields in -SCR_EL3, there are similar fields in HCR_EL2, SCTLR_EL2, and SCTLR_EL1 to adjust -the WFE trap delays in lower ELs and these fields should be set by the -appropriate EL2 or EL1 code depending on the platform configuration. - #define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/lib/extensions/twed.h b/include/lib/extensions/twed.h deleted file mode 100644 index eac4aa314..000000000 --- a/include/lib/extensions/twed.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2020, Arm Limited. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef TWED_H -#define TWED_H - -#include - -#define TWED_DISABLED U(0xFFFFFFFF) - -uint32_t plat_arm_set_twedel_scr_el3(void); - -#endif /* TWEDE_H */ diff --git a/lib/el3_runtime/aarch64/context_mgmt.c b/lib/el3_runtime/aarch64/context_mgmt.c index 459ca2ce4..47e7d8c31 100644 --- a/lib/el3_runtime/aarch64/context_mgmt.c +++ b/lib/el3_runtime/aarch64/context_mgmt.c @@ -27,11 +27,14 @@ #include #include #include -#include #include -static void manage_extensions_secure(cpu_context_t *ctx); +#if ENABLE_FEAT_TWED +/* Make sure delay value fits within the range(0-15) */ +CASSERT(((TWED_DELAY & ~SCR_TWEDEL_MASK) == 0U), assert_twed_delay_value_check); +#endif /* ENABLE_FEAT_TWED */ +static void manage_extensions_secure(cpu_context_t *ctx); /****************************************************************************** * This function performs initializations that are specific to SECURE state * and updates the cpu context specified by 'ctx'. @@ -329,23 +332,16 @@ static void setup_context_common(cpu_context_t *ctx, const entry_point_info_t *e sctlr_elx |= SCTLR_IESB_BIT; #endif +#if ENABLE_FEAT_TWED /* Enable WFE trap delay in SCR_EL3 if supported and configured */ - if (is_armv8_6_twed_present()) { - uint32_t delay = plat_arm_set_twedel_scr_el3(); + /* Set delay in SCR_EL3 */ + scr_el3 &= ~(SCR_TWEDEL_MASK << SCR_TWEDEL_SHIFT); + scr_el3 |= ((TWED_DELAY & SCR_TWEDEL_MASK) + << SCR_TWEDEL_SHIFT); - if (delay != TWED_DISABLED) { - /* Make sure delay value fits */ - assert((delay & ~SCR_TWEDEL_MASK) == 0U); - - /* Set delay in SCR_EL3 */ - scr_el3 &= ~(SCR_TWEDEL_MASK << SCR_TWEDEL_SHIFT); - scr_el3 |= ((delay & SCR_TWEDEL_MASK) - << SCR_TWEDEL_SHIFT); - - /* Enable WFE delay */ - scr_el3 |= SCR_TWEDEn_BIT; - } - } + /* Enable WFE delay */ + scr_el3 |= SCR_TWEDEn_BIT; +#endif /* ENABLE_FEAT_TWED */ /* * Store the initialised SCTLR_EL1 value in the cpu_context - SCTLR_EL2 diff --git a/make_helpers/defaults.mk b/make_helpers/defaults.mk index 99f44a4ec..1b55782d9 100644 --- a/make_helpers/defaults.mk +++ b/make_helpers/defaults.mk @@ -169,6 +169,9 @@ ENABLE_FEAT_SEL2 := 0 # Flag to enable Virtualization Host Extensions ENABLE_FEAT_VHE := 0 +# Flag to enable delayed trapping of WFE instruction (FEAT_TWED) +ENABLE_FEAT_TWED := 0 + # By default BL31 encryption disabled ENCRYPT_BL31 := 0 @@ -440,3 +443,9 @@ ENABLE_SYS_REG_TRACE_FOR_NS := 0 # lower ELs, i.e. NS-EL2, or NS-EL1 if NS-EL2 implemented but unused # if FEAT_TRF is implemented. ENABLE_TRF_FOR_NS := 0 + +# In v8.6+ platforms with delayed trapping of WFE being supported +# via FEAT_TWED, this flag takes the delay value to be set in the +# SCR_EL3.TWEDEL(4bit) field, when FEAT_TWED is implemented. +# By default it takes 0, and need to be updated by the platforms. +TWED_DELAY := 0 diff --git a/plat/common/aarch64/plat_common.c b/plat/common/aarch64/plat_common.c index 38a57861f..e807660d8 100644 --- a/plat/common/aarch64/plat_common.c +++ b/plat/common/aarch64/plat_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2014-2022, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -13,7 +13,6 @@ #if RAS_EXTENSION #include #endif -#include #include #include @@ -23,7 +22,6 @@ * platforms but may also be overridden by a platform if required. */ #pragma weak bl31_plat_runtime_setup -#pragma weak plat_arm_set_twedel_scr_el3 #if SDEI_SUPPORT #pragma weak plat_sdei_handle_masked_trigger @@ -105,16 +103,3 @@ void plat_default_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *co #endif panic(); } - -/******************************************************************************* - * In v8.6+ platforms with delayed trapping of WFE this hook sets the delay. It - * is a weak function definition so can be overridden depending on the - * requirements of a platform. The only hook provided is for the TWED fields - * in SCR_EL3, the TWED fields in HCR_EL2, SCTLR_EL2, and SCTLR_EL1 should be - * configured as needed in lower exception levels. - ******************************************************************************/ - -uint32_t plat_arm_set_twedel_scr_el3(void) -{ - return TWED_DISABLED; -}