crypto: ccp - Add a macro to check capabilities register
authorMario Limonciello <mario.limonciello@amd.com>
Thu, 7 Sep 2023 18:48:45 +0000 (13:48 -0500)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 15 Sep 2023 10:29:46 +0000 (18:29 +0800)
Offsets are checked by the capabilities register in multiple places.
To make the code more readable add a macro.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/ccp/psp-dev.c
drivers/crypto/ccp/sp-dev.h
drivers/crypto/ccp/sp-pci.c

index f9f3b3404f87bedccd48b8ce5a12c73dd2c7f02f..5f61b23695d5a8b81ae3e415460f96c0113ebd31 100644 (file)
@@ -157,7 +157,7 @@ static unsigned int psp_get_capability(struct psp_device *psp)
        psp->capability = val;
 
        /* Detect if TSME and SME are both enabled */
-       if (psp->capability & PSP_CAPABILITY_PSP_SECURITY_REPORTING &&
+       if (PSP_CAPABILITY(psp, PSP_SECURITY_REPORTING) &&
            psp->capability & (PSP_SECURITY_TSME_STATUS << PSP_CAPABILITY_PSP_SECURITY_OFFSET) &&
            cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
                dev_notice(psp->dev, "psp: Both TSME and SME are active, SME is unnecessary when TSME is active.\n");
@@ -168,7 +168,7 @@ static unsigned int psp_get_capability(struct psp_device *psp)
 static int psp_check_sev_support(struct psp_device *psp)
 {
        /* Check if device supports SEV feature */
-       if (!(psp->capability & PSP_CAPABILITY_SEV)) {
+       if (!PSP_CAPABILITY(psp, SEV)) {
                dev_dbg(psp->dev, "psp does not support SEV\n");
                return -ENODEV;
        }
@@ -179,7 +179,7 @@ static int psp_check_sev_support(struct psp_device *psp)
 static int psp_check_tee_support(struct psp_device *psp)
 {
        /* Check if device supports TEE feature */
-       if (!(psp->capability & PSP_CAPABILITY_TEE)) {
+       if (!PSP_CAPABILITY(psp, TEE)) {
                dev_dbg(psp->dev, "psp does not support TEE\n");
                return -ENODEV;
        }
index c4e125efe6c706147f35dc605871912199e0405f..03d5b9e04084828f8437eb78ad8dcb3a5d1ad739 100644 (file)
@@ -30,6 +30,7 @@
 
 #define PLATFORM_FEATURE_DBC           0x1
 
+#define PSP_CAPABILITY(psp, cap) (psp->capability & PSP_CAPABILITY_##cap)
 #define PSP_FEATURE(psp, feat) (psp->vdata && psp->vdata->platform_features & PLATFORM_FEATURE_##feat)
 
 /* Structure to hold CCP device data */
index d1aedc5c1a681d0ba8d80e6c407a7f19f54eda70..300dda14182b8e08dd89bee6d16862ec6a80270d 100644 (file)
@@ -84,7 +84,7 @@ static umode_t psp_security_is_visible(struct kobject *kobj, struct attribute *a
        struct sp_device *sp = dev_get_drvdata(dev);
        struct psp_device *psp = sp->psp_data;
 
-       if (psp && (psp->capability & PSP_CAPABILITY_PSP_SECURITY_REPORTING))
+       if (psp && PSP_CAPABILITY(psp, PSP_SECURITY_REPORTING))
                return 0444;
 
        return 0;
@@ -135,7 +135,7 @@ static umode_t psp_firmware_is_visible(struct kobject *kobj, struct attribute *a
                val = ioread32(psp->io_regs + psp->vdata->bootloader_info_reg);
 
        if (attr == &dev_attr_tee_version.attr &&
-           psp->capability & PSP_CAPABILITY_TEE &&
+           PSP_CAPABILITY(psp, TEE) &&
            psp->vdata->tee->info_reg)
                val = ioread32(psp->io_regs + psp->vdata->tee->info_reg);