[PATCH v4 16/19] crypto: talitos - Introduce is_sec1() helper with static key support
Paul Louvel <[email protected]>
| Newsgroups | org.kernel.vger.linux-crypto,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
In preparation for per-SEC-version code paths, introduce an is_sec1() inline helper that abstracts the SEC version check behind a static key. The goal is to remove all bool is_sec1 parameters from the call chain via the is_sec1() helper. Signed-off-by: Paul Louvel <[email protected]> --- drivers/crypto/talitos/talitos.c | 10 +++++++++- drivers/crypto/talitos/talitos.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/talitos/talitos.c b/drivers/crypto/talitos/talitos.c index ff938cc4e837..c93e3b551f6d 100644 --- a/drivers/crypto/talitos/talitos.c +++ b/drivers/crypto/talitos/talitos.c @@ -1196,8 +1196,12 @@ static int talitos_probe(struct platform_device *ofdev) TALITOS_FTR_SHA224_HWINIT | TALITOS_FTR_HMAC_OK; - if (of_device_is_compatible(np, "fsl,sec1.0")) + if (of_device_is_compatible(np, "fsl,sec1.0")) { priv->features |= TALITOS_FTR_SEC1; + talitos_init_branch(true); + } else { + talitos_init_branch(false); + } if (of_device_is_compatible(np, "fsl,sec1.2")) { priv->reg_deu = priv->reg + TALITOS12_DEU; @@ -1317,6 +1321,10 @@ static int talitos_probe(struct platform_device *ofdev) return err; } +#if defined(CONFIG_CRYPTO_DEV_TALITOS1) && defined(CONFIG_CRYPTO_DEV_TALITOS2) +DEFINE_STATIC_KEY_FALSE(talitos_is_sec1); +#endif + static const struct of_device_id talitos_match[] = { #ifdef CONFIG_CRYPTO_DEV_TALITOS1 { diff --git a/drivers/crypto/talitos/talitos.h b/drivers/crypto/talitos/talitos.h index 3cbce0be705d..b0d176c7dab2 100644 --- a/drivers/crypto/talitos/talitos.h +++ b/drivers/crypto/talitos/talitos.h @@ -14,6 +14,7 @@ #include <linux/dma-mapping.h> #include <linux/hw_random.h> #include <linux/interrupt.h> +#include <linux/jump_label.h> #include <linux/scatterlist.h> #include <linux/types.h> @@ -224,6 +225,33 @@ struct talitos_crypto_alg { #define TALITOS_FTR_HMAC_OK 0x00000008 #define TALITOS_FTR_SEC1 0x00000010 +#if defined(CONFIG_CRYPTO_DEV_TALITOS1) && defined(CONFIG_CRYPTO_DEV_TALITOS2) +DECLARE_STATIC_KEY_FALSE(talitos_is_sec1); + +static __always_inline bool is_sec1(void) +{ + return static_branch_unlikely(&talitos_is_sec1); +} + +static inline void talitos_init_branch(bool sec1) +{ + if (sec1) + static_branch_enable(&talitos_is_sec1); +} + +#else + +static __always_inline bool is_sec1(void) +{ + return IS_ENABLED(CONFIG_CRYPTO_DEV_TALITOS1); +} + +static inline void talitos_init_branch(bool sec1) +{ +} + +#endif + /* * If both CONFIG_CRYPTO_DEV_TALITOS1 and CONFIG_CRYPTO_DEV_TALITOS2 are * defined, we check the features which are set according to the device tree. -- 2.55.0