From f0deb4c8c7126bf0a2b99629486923b1a0d9dc42 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Thu, 10 Nov 2022 14:41:07 +0000 Subject: [PATCH] refactor(amu): convert FEAT_AMUv1 to new scheme For the FGT context save/restore operation, we need to look at the AMUv1 feature, so migrate this one over to the new scheme. This uses the generic check function in feat_detect.c, and splits the feature check into two functions, as was done before for FEAT_FGT. Signed-off-by: Andre Przywara Change-Id: I95ad797f15001b2c9d1800c9d4af33fba79e136f --- common/feat_detect.c | 12 +--------- include/arch/aarch64/arch_features.h | 35 ++++++++++++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/common/feat_detect.c b/common/feat_detect.c index cbbee9771..9544b4f63 100644 --- a/common/feat_detect.c +++ b/common/feat_detect.c @@ -121,16 +121,6 @@ static void read_feat_dit(void) #endif } -/********************************************************* - * Feature : FEAT_AMUv1 (Activity Monitors Extensions v1) - ********************************************************/ -static void read_feat_amuv1(void) -{ -#if (ENABLE_FEAT_AMUv1 == FEAT_STATE_ALWAYS) - feat_detect_panic(is_armv8_4_feat_amuv1_present(), "AMUv1"); -#endif -} - /**************************************************************************** * Feature : FEAT_MPAM (Memory Partitioning and Monitoring (MPAM) Extension) ***************************************************************************/ @@ -332,7 +322,7 @@ void detect_arch_features(void) /* v8.4 features */ read_feat_dit(); - read_feat_amuv1(); + check_feature(ENABLE_FEAT_AMUv1, read_feat_amu_id_field(), "AMUv1"); read_feat_mpam(); read_feat_nv2(); read_feat_sel2(); diff --git a/include/arch/aarch64/arch_features.h b/include/arch/aarch64/arch_features.h index 73dfcef26..e95970825 100644 --- a/include/arch/aarch64/arch_features.h +++ b/include/arch/aarch64/arch_features.h @@ -129,10 +129,31 @@ static inline bool is_armv8_5_rng_present(void) ID_AA64ISAR0_RNDR_MASK); } +/******************************************************************************* + * Functions to identify the presence of the Activity Monitors Extension + ******************************************************************************/ +static unsigned int read_feat_amu_id_field(void) +{ + return (read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) & + ID_AA64PFR0_AMU_MASK; +} + +static inline bool is_feat_amu_supported(void) +{ + if (ENABLE_FEAT_AMUv1 == FEAT_STATE_DISABLED) { + return false; + } + + if (ENABLE_FEAT_AMUv1 == FEAT_STATE_ALWAYS) { + return true; + } + + return read_feat_amu_id_field() >= ID_AA64PFR0_AMU_V1; +} + static inline bool is_armv8_6_feat_amuv1p1_present(void) { - return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) & - ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1P1); + return read_feat_amu_id_field() >= ID_AA64PFR0_AMU_V1P1; } /* @@ -240,16 +261,6 @@ static inline bool is_arm8_4_feat_trf_present(void) ID_AA64DFR0_TRACEFILT_MASK) == ID_AA64DFR0_TRACEFILT_SUPPORTED); } -/******************************************************************************* - * Function to identify the presence of FEAT_AMUv1 (Activity Monitors- - * Extension v1) - ******************************************************************************/ -static inline bool is_armv8_4_feat_amuv1_present(void) -{ - return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) & - ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1); -} - /******************************************************************************** * Function to identify the presence of FEAT_NV2 (Enhanced Nested Virtualization * Support)