mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-17 10:04:26 +00:00
refactor(twed): improve TWED enablement in EL-3
The current implementation uses plat_arm API under generic code. "plat_arm" API is a convention used with Arm common platform layer and is reserved for that purpose. In addition, the function has a weak definition which is not encouraged in TF-A. Henceforth, removing the weak API with a configurable macro "TWED_DELAY" of numeric data type in generic code and simplifying the implementation. By default "TWED_DELAY" is defined to zero, and the delay value need to be explicitly set by the platforms during buildtime. Signed-off-by: Jayanth Dodderi Chidanand <jayanthdodderi.chidanand@arm.com> Change-Id: I25cd6f628e863dc40415ced3a82d0662fdf2d75a
This commit is contained in:
parent
863296898a
commit
781d07a421
8 changed files with 52 additions and 64 deletions
4
Makefile
4
Makefile
|
@ -1061,6 +1061,8 @@ $(eval $(call assert_numerics,\
|
||||||
NR_OF_FW_BANKS \
|
NR_OF_FW_BANKS \
|
||||||
NR_OF_IMAGES_IN_FW_BANK \
|
NR_OF_IMAGES_IN_FW_BANK \
|
||||||
RAS_EXTENSION \
|
RAS_EXTENSION \
|
||||||
|
TWED_DELAY \
|
||||||
|
ENABLE_FEAT_TWED \
|
||||||
)))
|
)))
|
||||||
|
|
||||||
ifdef KEY_SIZE
|
ifdef KEY_SIZE
|
||||||
|
@ -1176,6 +1178,8 @@ $(eval $(call add_defines,\
|
||||||
ENABLE_FEAT_CSV2_2 \
|
ENABLE_FEAT_CSV2_2 \
|
||||||
ENABLE_FEAT_PAN \
|
ENABLE_FEAT_PAN \
|
||||||
FEATURE_DETECTION \
|
FEATURE_DETECTION \
|
||||||
|
TWED_DELAY \
|
||||||
|
ENABLE_FEAT_TWED \
|
||||||
)))
|
)))
|
||||||
|
|
||||||
ifeq (${SANITIZE_UB},trap)
|
ifeq (${SANITIZE_UB},trap)
|
||||||
|
|
|
@ -203,6 +203,16 @@ static void read_feat_ecv(void)
|
||||||
#endif
|
#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)
|
* Feature : FEAT_HCX (Extended Hypervisor Configuration Register)
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
|
@ -279,6 +289,7 @@ void detect_arch_features(void)
|
||||||
read_feat_amuv1p1();
|
read_feat_amuv1p1();
|
||||||
read_feat_fgt();
|
read_feat_fgt();
|
||||||
read_feat_ecv();
|
read_feat_ecv();
|
||||||
|
read_feat_twed();
|
||||||
|
|
||||||
/* v8.7 features */
|
/* v8.7 features */
|
||||||
read_feat_hcx();
|
read_feat_hcx();
|
||||||
|
|
|
@ -327,6 +327,14 @@ Common build options
|
||||||
This flag can take values 0 to 2, to align with the ``FEATURE_DETECTION``
|
This flag can take values 0 to 2, to align with the ``FEATURE_DETECTION``
|
||||||
mechanism. Default is ``0``.
|
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
|
- ``ENABLE_FEAT_VHE``: Numeric value to enable the ``FEAT_VHE`` (Virtualization
|
||||||
Host Extensions) extension. It allows access to CONTEXTIDR_EL2 register
|
Host Extensions) extension. It allows access to CONTEXTIDR_EL2 register
|
||||||
during EL2 context save/restore operations.``FEAT_VHE`` is a mandatory
|
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``
|
When ``EL3_EXCEPTION_HANDLING`` is ``1``, ``TSP_NS_INTR_ASYNC_PREEMPT``
|
||||||
must also be set to ``1``.
|
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
|
- ``USE_ARM_LINK``: This flag determines whether to enable support for ARM
|
||||||
linker. When the ``LINKER`` build variable points to the armlink linker,
|
linker. When the ``LINKER`` build variable points to the armlink linker,
|
||||||
this flag is enabled automatically. To enable support for armlink, platforms
|
this flag is enabled automatically. To enable support for armlink, platforms
|
||||||
|
|
|
@ -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
|
of the system counter, which is retrieved from the first entry in the frequency
|
||||||
modes table.
|
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]
|
#define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional]
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -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 <stdint.h>
|
|
||||||
|
|
||||||
#define TWED_DISABLED U(0xFFFFFFFF)
|
|
||||||
|
|
||||||
uint32_t plat_arm_set_twedel_scr_el3(void);
|
|
||||||
|
|
||||||
#endif /* TWEDE_H */
|
|
|
@ -27,11 +27,14 @@
|
||||||
#include <lib/extensions/sys_reg_trace.h>
|
#include <lib/extensions/sys_reg_trace.h>
|
||||||
#include <lib/extensions/trbe.h>
|
#include <lib/extensions/trbe.h>
|
||||||
#include <lib/extensions/trf.h>
|
#include <lib/extensions/trf.h>
|
||||||
#include <lib/extensions/twed.h>
|
|
||||||
#include <lib/utils.h>
|
#include <lib/utils.h>
|
||||||
|
|
||||||
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
|
* This function performs initializations that are specific to SECURE state
|
||||||
* and updates the cpu context specified by 'ctx'.
|
* 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;
|
sctlr_elx |= SCTLR_IESB_BIT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_FEAT_TWED
|
||||||
/* Enable WFE trap delay in SCR_EL3 if supported and configured */
|
/* Enable WFE trap delay in SCR_EL3 if supported and configured */
|
||||||
if (is_armv8_6_twed_present()) {
|
/* Set delay in SCR_EL3 */
|
||||||
uint32_t delay = plat_arm_set_twedel_scr_el3();
|
scr_el3 &= ~(SCR_TWEDEL_MASK << SCR_TWEDEL_SHIFT);
|
||||||
|
scr_el3 |= ((TWED_DELAY & SCR_TWEDEL_MASK)
|
||||||
|
<< SCR_TWEDEL_SHIFT);
|
||||||
|
|
||||||
if (delay != TWED_DISABLED) {
|
/* Enable WFE delay */
|
||||||
/* Make sure delay value fits */
|
scr_el3 |= SCR_TWEDEn_BIT;
|
||||||
assert((delay & ~SCR_TWEDEL_MASK) == 0U);
|
#endif /* ENABLE_FEAT_TWED */
|
||||||
|
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Store the initialised SCTLR_EL1 value in the cpu_context - SCTLR_EL2
|
* Store the initialised SCTLR_EL1 value in the cpu_context - SCTLR_EL2
|
||||||
|
|
|
@ -169,6 +169,9 @@ ENABLE_FEAT_SEL2 := 0
|
||||||
# Flag to enable Virtualization Host Extensions
|
# Flag to enable Virtualization Host Extensions
|
||||||
ENABLE_FEAT_VHE := 0
|
ENABLE_FEAT_VHE := 0
|
||||||
|
|
||||||
|
# Flag to enable delayed trapping of WFE instruction (FEAT_TWED)
|
||||||
|
ENABLE_FEAT_TWED := 0
|
||||||
|
|
||||||
# By default BL31 encryption disabled
|
# By default BL31 encryption disabled
|
||||||
ENCRYPT_BL31 := 0
|
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
|
# lower ELs, i.e. NS-EL2, or NS-EL1 if NS-EL2 implemented but unused
|
||||||
# if FEAT_TRF is implemented.
|
# if FEAT_TRF is implemented.
|
||||||
ENABLE_TRF_FOR_NS := 0
|
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
|
||||||
|
|
|
@ -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
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,6 @@
|
||||||
#if RAS_EXTENSION
|
#if RAS_EXTENSION
|
||||||
#include <lib/extensions/ras.h>
|
#include <lib/extensions/ras.h>
|
||||||
#endif
|
#endif
|
||||||
#include <lib/extensions/twed.h>
|
|
||||||
#include <lib/xlat_tables/xlat_mmu_helpers.h>
|
#include <lib/xlat_tables/xlat_mmu_helpers.h>
|
||||||
#include <plat/common/platform.h>
|
#include <plat/common/platform.h>
|
||||||
|
|
||||||
|
@ -23,7 +22,6 @@
|
||||||
* platforms but may also be overridden by a platform if required.
|
* platforms but may also be overridden by a platform if required.
|
||||||
*/
|
*/
|
||||||
#pragma weak bl31_plat_runtime_setup
|
#pragma weak bl31_plat_runtime_setup
|
||||||
#pragma weak plat_arm_set_twedel_scr_el3
|
|
||||||
|
|
||||||
#if SDEI_SUPPORT
|
#if SDEI_SUPPORT
|
||||||
#pragma weak plat_sdei_handle_masked_trigger
|
#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
|
#endif
|
||||||
panic();
|
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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue