From d242128c1dc87f2c0e25e2c4e84c5668a6c397a3 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Tue, 15 Nov 2022 11:45:19 +0000 Subject: [PATCH] refactor(cpufeat): convert FEAT_HCX to new scheme Use the generic check function in feat_detect.c, and split the feature check into two functions, as done for FEAT_FGT before. Signed-off-by: Andre Przywara Change-Id: I0a4f973427c10d5d15c414ff5e12b18b7e645fae --- bl31/bl31_main.c | 2 +- common/feat_detect.c | 12 +----------- include/arch/aarch64/arch_features.h | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/bl31/bl31_main.c b/bl31/bl31_main.c index 2a3d838e4..a4640b1b9 100644 --- a/bl31/bl31_main.c +++ b/bl31/bl31_main.c @@ -99,7 +99,7 @@ void bl31_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, * an exception would occur during context save/restore if enabled but * not supported. */ - assert(is_feat_hcx_present()); + assert(is_feat_hcx_supported()); #endif /* ENABLE_FEAT_HCX */ #if CTX_INCLUDE_PAUTH_REGS diff --git a/common/feat_detect.c b/common/feat_detect.c index 9544b4f63..a8c40f70d 100644 --- a/common/feat_detect.c +++ b/common/feat_detect.c @@ -228,16 +228,6 @@ static void read_feat_twed(void) #endif } -/****************************************************************** - * Feature : FEAT_HCX (Extended Hypervisor Configuration Register) - *****************************************************************/ -static void read_feat_hcx(void) -{ -#if (ENABLE_FEAT_HCX == FEAT_STATE_ALWAYS) - feat_detect_panic(is_feat_hcx_present(), "HCX"); -#endif -} - /************************************************** * Feature : FEAT_RME (Realm Management Extension) *************************************************/ @@ -341,7 +331,7 @@ void detect_arch_features(void) read_feat_twed(); /* v8.7 features */ - read_feat_hcx(); + check_feature(ENABLE_FEAT_HCX, read_feat_hcx_id_field(), "HCX"); /* v9.0 features */ read_feat_brbe(); diff --git a/include/arch/aarch64/arch_features.h b/include/arch/aarch64/arch_features.h index e95970825..2b801ac84 100644 --- a/include/arch/aarch64/arch_features.h +++ b/include/arch/aarch64/arch_features.h @@ -173,10 +173,23 @@ static inline unsigned int get_mpam_version(void) ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK)); } -static inline bool is_feat_hcx_present(void) +static inline unsigned int read_feat_hcx_id_field(void) { - return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_HCX_SHIFT) & - ID_AA64MMFR1_EL1_HCX_MASK) == ID_AA64MMFR1_EL1_HCX_SUPPORTED); + return (read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_HCX_SHIFT) & + ID_AA64MMFR1_EL1_HCX_MASK; +} + +static inline bool is_feat_hcx_supported(void) +{ + if (ENABLE_FEAT_HCX == FEAT_STATE_DISABLED) { + return false; + } + + if (ENABLE_FEAT_HCX == FEAT_STATE_ALWAYS) { + return true; + } + + return read_feat_hcx_id_field() != 0U; } static inline bool is_feat_rng_trap_present(void)