Merge "refactor(twed): improve TWED enablement in EL-3" into integration

This commit is contained in:
Manish Pandey 2022-04-27 11:01:52 +02:00 committed by TrustedFirmware Code Review
commit 9284d2129e
8 changed files with 52 additions and 64 deletions

View File

@ -1068,6 +1068,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
@ -1184,6 +1186,8 @@ $(eval $(call add_defines,\
ENABLE_FEAT_CSV2_2 \
ENABLE_FEAT_PAN \
FEATURE_DETECTION \
TWED_DELAY \
ENABLE_FEAT_TWED \
)))
ifeq (${SANITIZE_UB},trap)

View File

@ -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();

View File

@ -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
@ -845,6 +853,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

View File

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -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 */

View File

@ -27,11 +27,14 @@
#include <lib/extensions/sys_reg_trace.h>
#include <lib/extensions/trbe.h>
#include <lib/extensions/trf.h>
#include <lib/extensions/twed.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
* 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

View File

@ -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
@ -443,3 +446,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

View File

@ -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 <lib/extensions/ras.h>
#endif
#include <lib/extensions/twed.h>
#include <lib/xlat_tables/xlat_mmu_helpers.h>
#include <plat/common/platform.h>
@ -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;
}