feat(sys_reg_trace): enable trace system registers access from lower NS ELs

Introduced a build flag 'ENABLE_SYS_REG_TRACE_FOR_NS' to enable trace
system registers access in NS-EL2, or NS-EL1 (when NS-EL2 is
implemented but unused).

Change-Id: Idc1acede4186e101758cbf7bed5af7b634d7d18d
Signed-off-by: Manish V Badarkhe <Manish.Badarkhe@arm.com>
This commit is contained in:
Manish V Badarkhe 2021-06-29 11:44:20 +01:00
parent 2031d6166a
commit d4582d3088
11 changed files with 124 additions and 0 deletions

View File

@ -965,6 +965,7 @@ $(eval $(call assert_booleans,\
ENABLE_FEAT_SB \ ENABLE_FEAT_SB \
PSA_FWU_SUPPORT \ PSA_FWU_SUPPORT \
ENABLE_TRBE_FOR_NS \ ENABLE_TRBE_FOR_NS \
ENABLE_SYS_REG_TRACE_FOR_NS \
))) )))
$(eval $(call assert_numerics,\ $(eval $(call assert_numerics,\
@ -1066,6 +1067,7 @@ $(eval $(call add_defines,\
NR_OF_IMAGES_IN_FW_BANK \ NR_OF_IMAGES_IN_FW_BANK \
PSA_FWU_SUPPORT \ PSA_FWU_SUPPORT \
ENABLE_TRBE_FOR_NS \ ENABLE_TRBE_FOR_NS \
ENABLE_SYS_REG_TRACE_FOR_NS \
))) )))
ifeq (${SANITIZE_UB},trap) ifeq (${SANITIZE_UB},trap)

View File

@ -94,6 +94,10 @@ ifeq (${ENABLE_TRBE_FOR_NS},1)
BL31_SOURCES += lib/extensions/trbe/trbe.c BL31_SOURCES += lib/extensions/trbe/trbe.c
endif endif
ifeq (${ENABLE_SYS_REG_TRACE_FOR_NS},1)
BL31_SOURCES += lib/extensions/sys_reg_trace/aarch64/sys_reg_trace.c
endif
ifeq (${WORKAROUND_CVE_2017_5715},1) ifeq (${WORKAROUND_CVE_2017_5715},1)
BL31_SOURCES += lib/cpus/aarch64/wa_cve_2017_5715_bpiall.S \ BL31_SOURCES += lib/cpus/aarch64/wa_cve_2017_5715_bpiall.S \
lib/cpus/aarch64/wa_cve_2017_5715_mmu.S lib/cpus/aarch64/wa_cve_2017_5715_mmu.S

View File

@ -42,6 +42,10 @@ BL32_SOURCES += services/std_svc/trng/trng_main.c \
services/std_svc/trng/trng_entropy_pool.c services/std_svc/trng/trng_entropy_pool.c
endif endif
ifeq (${ENABLE_SYS_REG_TRACE_FOR_NS},1)
BL32_SOURCES += lib/extensions/sys_reg_trace/aarch32/sys_reg_trace.c
endif
BL32_LINKERFILE := bl32/sp_min/sp_min.ld.S BL32_LINKERFILE := bl32/sp_min/sp_min.ld.S
# Include the platform-specific SP_MIN Makefile # Include the platform-specific SP_MIN Makefile

View File

@ -781,6 +781,11 @@ Common build options
feature for AArch64. The default is 0 and it is automatically disabled when feature for AArch64. The default is 0 and it is automatically disabled when
the target architecture is AArch32. the target architecture is AArch32.
- ``ENABLE_SYS_REG_TRACE_FOR_NS``: Boolean option to enable trace system
registers access from NS ELs, NS-EL2 or NS-EL1 (when NS-EL2 is implemented
but unused). This feature is available if trace unit such as ETMv4.x, and
ETE(extending ETM feature) is implemented. This flag is disabled by default.
GICv3 driver options GICv3 driver options
-------------------- --------------------

View File

@ -217,6 +217,7 @@ DEFINE_SYSREG_RW_FUNCS(cpsr)
DEFINE_COPROCR_READ_FUNC(mpidr, MPIDR) DEFINE_COPROCR_READ_FUNC(mpidr, MPIDR)
DEFINE_COPROCR_READ_FUNC(midr, MIDR) DEFINE_COPROCR_READ_FUNC(midr, MIDR)
DEFINE_COPROCR_READ_FUNC(id_mmfr4, ID_MMFR4) DEFINE_COPROCR_READ_FUNC(id_mmfr4, ID_MMFR4)
DEFINE_COPROCR_READ_FUNC(id_dfr0, ID_DFR0)
DEFINE_COPROCR_READ_FUNC(id_pfr0, ID_PFR0) DEFINE_COPROCR_READ_FUNC(id_pfr0, ID_PFR0)
DEFINE_COPROCR_READ_FUNC(id_pfr1, ID_PFR1) DEFINE_COPROCR_READ_FUNC(id_pfr1, ID_PFR1)
DEFINE_COPROCR_READ_FUNC(isr, ISR) DEFINE_COPROCR_READ_FUNC(isr, ISR)

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SYS_REG_TRACE_H
#define SYS_REG_TRACE_H
#include <context.h>
#if __aarch64__
void sys_reg_trace_enable(cpu_context_t *context);
#else
void sys_reg_trace_enable(void);
#endif /* __aarch64__ */
#endif /* SYS_REG_TRACE_H */

View File

@ -16,6 +16,7 @@
#include <context.h> #include <context.h>
#include <lib/el3_runtime/context_mgmt.h> #include <lib/el3_runtime/context_mgmt.h>
#include <lib/extensions/amu.h> #include <lib/extensions/amu.h>
#include <lib/extensions/sys_reg_trace.h>
#include <lib/utils.h> #include <lib/utils.h>
/******************************************************************************* /*******************************************************************************
@ -136,6 +137,10 @@ static void enable_extensions_nonsecure(bool el2_unused)
#if ENABLE_AMU #if ENABLE_AMU
amu_enable(el2_unused); amu_enable(el2_unused);
#endif #endif
#if ENABLE_SYS_REG_TRACE_FOR_NS
sys_reg_trace_enable();
#endif /* ENABLE_SYS_REG_TRACE_FOR_NS */
#endif #endif
} }

View File

@ -22,6 +22,7 @@
#include <lib/extensions/mpam.h> #include <lib/extensions/mpam.h>
#include <lib/extensions/spe.h> #include <lib/extensions/spe.h>
#include <lib/extensions/sve.h> #include <lib/extensions/sve.h>
#include <lib/extensions/sys_reg_trace.h>
#include <lib/extensions/trbe.h> #include <lib/extensions/trbe.h>
#include <lib/extensions/twed.h> #include <lib/extensions/twed.h>
#include <lib/utils.h> #include <lib/utils.h>
@ -354,6 +355,10 @@ static void enable_extensions_nonsecure(bool el2_unused, cpu_context_t *ctx)
trbe_enable(); trbe_enable();
#endif /* ENABLE_TRBE_FOR_NS */ #endif /* ENABLE_TRBE_FOR_NS */
#if ENABLE_SYS_REG_TRACE_FOR_NS
sys_reg_trace_enable(ctx);
#endif /* ENABLE_SYS_REG_TRACE_FOR_NS */
#endif #endif
} }
@ -463,6 +468,8 @@ void cm_prepare_el3_exit(uint32_t security_state)
* CPTR_EL2.TTA: Set to zero so that Non-secure System * CPTR_EL2.TTA: Set to zero so that Non-secure System
* register accesses to the trace registers from both * register accesses to the trace registers from both
* Execution states do not trap to EL2. * Execution states do not trap to EL2.
* If PE trace unit System registers are not implemented
* then this bit is reserved, and must be set to zero.
* *
* CPTR_EL2.TFP: Set to zero so that Non-secure accesses * CPTR_EL2.TFP: Set to zero so that Non-secure accesses
* to SIMD and floating-point functionality from both * to SIMD and floating-point functionality from both

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdbool.h>
#include <arch.h>
#include <arch_helpers.h>
#include <lib/extensions/sys_reg_trace.h>
static bool sys_reg_trace_supported(void)
{
uint32_t features;
features = read_id_dfr0() >> ID_DFR0_COPTRC_SHIFT;
return ((features & ID_DFR0_COPTRC_MASK) ==
ID_DFR0_COPTRC_SUPPORTED);
}
void sys_reg_trace_enable(void)
{
uint32_t val;
if (sys_reg_trace_supported()) {
/*
* NSACR.NSTRCDIS = b0
* enable NS system register access to implemented trace
* registers.
*/
val = read_nsacr();
val &= ~NSTRCDIS_BIT;
write_nsacr(val);
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdbool.h>
#include <arch.h>
#include <arch_helpers.h>
#include <lib/extensions/sys_reg_trace.h>
static bool sys_reg_trace_supported(void)
{
uint64_t features;
features = read_id_aa64dfr0_el1() >> ID_AA64DFR0_TRACEVER_SHIFT;
return ((features & ID_AA64DFR0_TRACEVER_MASK) ==
ID_AA64DFR0_TRACEVER_SUPPORTED);
}
void sys_reg_trace_enable(cpu_context_t *ctx)
{
uint64_t val;
if (sys_reg_trace_supported()) {
/* Retrieve CPTR_EL3 value from the given context 'ctx',
* and update CPTR_EL3.TTA bit to 0.
* This function is called while switching context to NS to
* allow system trace register access to NS-EL2 and NS-EL1
* when NS-EL2 is implemented but not used.
*/
val = read_ctx_reg(get_el3state_ctx(ctx), CTX_CPTR_EL3);
val &= ~TTA_BIT;
write_ctx_reg(get_el3state_ctx(ctx), CTX_CPTR_EL3, val);
}
}

View File

@ -366,3 +366,8 @@ ifneq (${ARCH},aarch32)
else else
override ENABLE_TRBE_FOR_NS := 0 override ENABLE_TRBE_FOR_NS := 0
endif endif
# By default, disable access of trace system registers from NS lower
# ELs i.e. NS-EL2, or NS-EL1 if NS-EL2 implemented but unused if
# system register trace is implemented.
ENABLE_SYS_REG_TRACE_FOR_NS := 0