From 07881e992a211893c7a9b0970d977e5bfdd8f0f7 Mon Sep 17 00:00:00 2001 From: Igor Opaniuk Date: Sat, 17 Feb 2024 16:31:18 +0100 Subject: [PATCH] core: arm: add helper functions for checking CE support Add helper functions for checking implementation of SHA1, SHA256, SHA512, SHA3, SM3, SM4 instructions. Acked-by: Etienne Carriere Signed-off-by: Igor Opaniuk --- core/arch/arm/include/arm.h | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/core/arch/arm/include/arm.h b/core/arch/arm/include/arm.h index 1ec019f8ea0..f859a694564 100644 --- a/core/arch/arm/include/arm.h +++ b/core/arch/arm/include/arm.h @@ -187,6 +187,70 @@ static inline bool feat_crc32_implemented(void) #endif } +static inline bool feat_aes_implemented(void) +{ +#ifdef ARM32 + return read_id_isar5() & ID_ISAR5_AES; +#else + return read_id_aa64isar0_el1() & ID_AA64ISAR0_AES; +#endif +} + +static inline bool feat_sha1_implemented(void) +{ +#ifdef ARM32 + return read_id_isar5() & ID_ISAR5_SHA1; +#else + return read_id_aa64isar0_el1() & ID_AA64ISAR0_SHA1; +#endif +} + +static inline bool feat_sha256_implemented(void) +{ +#ifdef ARM32 + return read_id_isar5() & ID_ISAR5_SHA2; +#else + return read_id_aa64isar0_el1() & ID_AA64ISAR0_SHA2; +#endif +} + +static inline bool feat_sha512_implemented(void) +{ +#ifdef ARM32 + return false; +#else + return ((read_id_aa64isar0_el1() & ID_AA64ISAR0_SHA2) >> + ID_AA64ISAR0_SHA2_SHIFT) == ID_AA64ISAR0_SHA2_FEAT_SHA512; +#endif +} + +static inline bool feat_sha3_implemented(void) +{ +#ifdef ARM32 + return false; +#else + return read_id_aa64isar0_el1() & ID_AA64ISAR0_SHA3; +#endif +} + +static inline bool feat_sm3_implemented(void) +{ +#ifdef ARM32 + return false; +#else + return read_id_aa64isar0_el1() & ID_AA64ISAR0_SM3; +#endif +} + +static inline bool feat_sm4_implemented(void) +{ +#ifdef ARM32 + return false; +#else + return read_id_aa64isar0_el1() & ID_AA64ISAR0_SM4; +#endif +} + static inline bool feat_pauth_is_implemented(void) { #ifdef ARM32