[PATCH 09/11] crypto: ccp - detect the Hygon CCP engines from the version register
From: Depei Yang
Date: Wed Nov 25 2026 - 02:47:41 EST
The Hygon CCP reports the engines it implements in the upper bits of the
CCP version register, starting at bit 6: SM2, SM3, SM4, SM4-CTR, ECC,
AES, SHA2, TRNG and SM4-GCM.
Translate the presence bits into engine capabilities in
ccp5_hygon_get_caps(). The same function stores the raw register value
and the engine version read from the new CMD5_PSP_CCP_ENG_VERSION
register; neither is used yet. Only the SM engines are advertised for
now; the other presence bits are defined but not translated until those
engines are enabled.
Reviewed-by: Shan Chen <chenshan@xxxxxxxx>
Tested-by: Yongwei Xu <xuyongwei@xxxxxxxx>
Signed-off-by: Depei Yang <yangdepei@xxxxxxxx>
---
drivers/crypto/ccp/ccp-dev-v5.c | 42 +++++++++++++++++++++++++++++----
drivers/crypto/ccp/ccp-dev.h | 1 +
2 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
index d2586625700b..0284be103ad1 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -1203,13 +1203,47 @@ const struct ccp_vdata ccpv5b = {
* Hygon CCP is a v5 derivative with the SM3/SM4 engines added. It
* uses the same queue, LSB and interrupt model as the AMD v5 CCP.
*
- * TODO: derive the legacy engines from the Hygon engine register once
- * its layout is confirmed. Until then only the engines that cannot be
- * detected from a register are advertised.
+ * Engine presence is reported by the bits 6 and above of the CCP
+ * version register; the layout differs from the AMD one.
*/
+#define HYGON_RI_SM2 BIT(6)
+#define HYGON_RI_SM3 BIT(7)
+#define HYGON_RI_SM4 BIT(8)
+#define HYGON_RI_SM4_CTR BIT(9)
+#define HYGON_RI_ECC BIT(10)
+#define HYGON_RI_AES BIT(11)
+#define HYGON_RI_SHA2 BIT(12)
+#define HYGON_RI_TRNG BIT(13)
+#define HYGON_RI_SM4_GCM BIT(14)
+
static void ccp5_hygon_get_caps(struct ccp_device *ccp)
{
- ccp->caps.engines = CCP_CAPS_SM3 | CCP_CAPS_SM4 | CCP_CAPS_SM4_CTR;
+ /*
+ * Only the SM engines are advertised for now. SM2, ECC, AES,
+ * SHA2, TRNG and SM4-GCM are not enabled for the Hygon CCP yet;
+ * they will be added to the table once the driver supports them
+ * on this hardware.
+ */
+ static const struct {
+ u32 presence;
+ u32 cap;
+ } engines[] = {
+ { HYGON_RI_SM3, CCP_CAPS_SM3 },
+ { HYGON_RI_SM4, CCP_CAPS_SM4 },
+ { HYGON_RI_SM4_CTR, CCP_CAPS_SM4_CTR },
+ };
+ u32 version;
+ unsigned int i;
+
+ version = ioread32(ccp->io_regs + CMD5_PSP_CCP_VERSION);
+ ccp->caps.ccp_version = version;
+ ccp->caps.engine_version =
+ ioread32(ccp->io_regs + CMD5_PSP_CCP_ENG_VERSION);
+ ccp->caps.engines = 0;
+
+ for (i = 0; i < ARRAY_SIZE(engines); i++)
+ if (version & engines[i].presence)
+ ccp->caps.engines |= engines[i].cap;
}
const struct ccp_vdata ccpv5a_hygon = {
diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
index f499e6868d82..c2b8068bc123 100644
--- a/drivers/crypto/ccp/ccp-dev.h
+++ b/drivers/crypto/ccp/ccp-dev.h
@@ -71,6 +71,7 @@
#define LSB_PRIVATE_MASK_LO_OFFSET 0x20
#define LSB_PRIVATE_MASK_HI_OFFSET 0x24
#define CMD5_PSP_CCP_VERSION 0x100
+#define CMD5_PSP_CCP_ENG_VERSION 0x104
#define CMD5_Q_CONTROL_BASE 0x0000
#define CMD5_Q_TAIL_LO_BASE 0x0004
--
2.34.1