Skip to content

Commit e469b3d

Browse files
committed
crypto: ccp - Represent capabilities register as a union
JIRA: https://issues.redhat.com/browse/RHEL-85131 Upstream Status: merged into the linux.git commit 8609dd2 Author: Mario Limonciello <[email protected]> Date: Tue May 28 16:07:08 2024 -0500 crypto: ccp - Represent capabilities register as a union Making the capabilities register a union makes it easier to refer to the members instead of always doing bit shifts. No intended functional changes. Acked-by: Tom Lendacky <[email protected]> Suggested-by: Yazen Ghannam <[email protected]> Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Vladis Dronov <[email protected]>
1 parent bca3536 commit e469b3d

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

drivers/crypto/ccp/dbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int dbc_dev_init(struct psp_device *psp)
223223
dbc_dev->dev = dev;
224224
dbc_dev->psp = psp;
225225

226-
if (PSP_CAPABILITY(psp, DBC_THRU_EXT)) {
226+
if (psp->capability.dbc_thru_ext) {
227227
dbc_dev->use_ext = true;
228228
dbc_dev->payload_size = &dbc_dev->mbox->ext_req.header.payload_size;
229229
dbc_dev->result = &dbc_dev->mbox->ext_req.header.status;

drivers/crypto/ccp/psp-dev.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,10 @@ static unsigned int psp_get_capability(struct psp_device *psp)
154154
dev_notice(psp->dev, "psp: unable to access the device: you might be running a broken BIOS.\n");
155155
return -ENODEV;
156156
}
157-
psp->capability = val;
157+
psp->capability.raw = val;
158158

159159
/* Detect TSME and/or SME status */
160-
if (PSP_CAPABILITY(psp, PSP_SECURITY_REPORTING) &&
161-
psp->capability & (PSP_SECURITY_TSME_STATUS << PSP_CAPABILITY_PSP_SECURITY_OFFSET)) {
160+
if (psp->capability.security_reporting && psp->capability.tsme_status) {
162161
if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
163162
dev_notice(psp->dev, "psp: Both TSME and SME are active, SME is unnecessary when TSME is active.\n");
164163
else
@@ -171,7 +170,7 @@ static unsigned int psp_get_capability(struct psp_device *psp)
171170
static int psp_check_sev_support(struct psp_device *psp)
172171
{
173172
/* Check if device supports SEV feature */
174-
if (!PSP_CAPABILITY(psp, SEV)) {
173+
if (!psp->capability.sev) {
175174
dev_dbg(psp->dev, "psp does not support SEV\n");
176175
return -ENODEV;
177176
}
@@ -182,7 +181,7 @@ static int psp_check_sev_support(struct psp_device *psp)
182181
static int psp_check_tee_support(struct psp_device *psp)
183182
{
184183
/* Check if device supports TEE feature */
185-
if (!PSP_CAPABILITY(psp, TEE)) {
184+
if (!psp->capability.tee) {
186185
dev_dbg(psp->dev, "psp does not support TEE\n");
187186
return -ENODEV;
188187
}
@@ -214,7 +213,7 @@ static int psp_init(struct psp_device *psp)
214213

215214
/* dbc must come after platform access as it tests the feature */
216215
if (PSP_FEATURE(psp, DBC) ||
217-
PSP_CAPABILITY(psp, DBC_THRU_EXT)) {
216+
psp->capability.dbc_thru_ext) {
218217
ret = dbc_dev_init(psp);
219218
if (ret)
220219
return ret;

drivers/crypto/ccp/psp-dev.h

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ extern struct psp_device *psp_master;
2626

2727
typedef void (*psp_irq_handler_t)(int, void *, unsigned int);
2828

29+
union psp_cap_register {
30+
unsigned int raw;
31+
struct {
32+
unsigned int sev :1,
33+
tee :1,
34+
dbc_thru_ext :1,
35+
rsvd1 :4,
36+
security_reporting :1,
37+
fused_part :1,
38+
rsvd2 :1,
39+
debug_lock_on :1,
40+
rsvd3 :2,
41+
tsme_status :1,
42+
rsvd4 :1,
43+
anti_rollback_status :1,
44+
rpmc_production_enabled :1,
45+
rpmc_spirom_available :1,
46+
hsp_tpm_available :1,
47+
rom_armor_enforced :1,
48+
rsvd5 :12;
49+
};
50+
};
51+
2952
struct psp_device {
3053
struct list_head entry;
3154

@@ -46,7 +69,7 @@ struct psp_device {
4669
void *platform_access_data;
4770
void *dbc_data;
4871

49-
unsigned int capability;
72+
union psp_cap_register capability;
5073
};
5174

5275
void psp_set_sev_irq_handler(struct psp_device *psp, psp_irq_handler_t handler,
@@ -55,26 +78,7 @@ void psp_clear_sev_irq_handler(struct psp_device *psp);
5578

5679
struct psp_device *psp_get_master_device(void);
5780

58-
#define PSP_CAPABILITY_SEV BIT(0)
59-
#define PSP_CAPABILITY_TEE BIT(1)
60-
#define PSP_CAPABILITY_DBC_THRU_EXT BIT(2)
61-
#define PSP_CAPABILITY_PSP_SECURITY_REPORTING BIT(7)
62-
6381
#define PSP_CAPABILITY_PSP_SECURITY_OFFSET 8
64-
/*
65-
* The PSP doesn't directly store these bits in the capability register
66-
* but instead copies them from the results of query command.
67-
*
68-
* The offsets from the query command are below, and shifted when used.
69-
*/
70-
#define PSP_SECURITY_FUSED_PART BIT(0)
71-
#define PSP_SECURITY_DEBUG_LOCK_ON BIT(2)
72-
#define PSP_SECURITY_TSME_STATUS BIT(5)
73-
#define PSP_SECURITY_ANTI_ROLLBACK_STATUS BIT(7)
74-
#define PSP_SECURITY_RPMC_PRODUCTION_ENABLED BIT(8)
75-
#define PSP_SECURITY_RPMC_SPIROM_AVAILABLE BIT(9)
76-
#define PSP_SECURITY_HSP_TPM_AVAILABLE BIT(10)
77-
#define PSP_SECURITY_ROM_ARMOR_ENFORCED BIT(11)
7882

7983
/**
8084
* enum psp_cmd - PSP mailbox commands

drivers/crypto/ccp/sp-dev.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#define PLATFORM_FEATURE_DBC 0x1
3232

33-
#define PSP_CAPABILITY(psp, cap) (psp->capability & PSP_CAPABILITY_##cap)
3433
#define PSP_FEATURE(psp, feat) (psp->vdata && psp->vdata->platform_features & PLATFORM_FEATURE_##feat)
3534

3635
/* Structure to hold CCP device data */

drivers/crypto/ccp/sp-pci.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,30 @@ struct sp_pci {
3939
};
4040
static struct sp_device *sp_dev_master;
4141

42-
#define security_attribute_show(name, def) \
42+
#define security_attribute_show(name) \
4343
static ssize_t name##_show(struct device *d, struct device_attribute *attr, \
4444
char *buf) \
4545
{ \
4646
struct sp_device *sp = dev_get_drvdata(d); \
4747
struct psp_device *psp = sp->psp_data; \
48-
int bit = PSP_SECURITY_##def << PSP_CAPABILITY_PSP_SECURITY_OFFSET; \
49-
return sysfs_emit(buf, "%d\n", (psp->capability & bit) > 0); \
48+
return sysfs_emit(buf, "%d\n", psp->capability.name); \
5049
}
5150

52-
security_attribute_show(fused_part, FUSED_PART)
51+
security_attribute_show(fused_part)
5352
static DEVICE_ATTR_RO(fused_part);
54-
security_attribute_show(debug_lock_on, DEBUG_LOCK_ON)
53+
security_attribute_show(debug_lock_on)
5554
static DEVICE_ATTR_RO(debug_lock_on);
56-
security_attribute_show(tsme_status, TSME_STATUS)
55+
security_attribute_show(tsme_status)
5756
static DEVICE_ATTR_RO(tsme_status);
58-
security_attribute_show(anti_rollback_status, ANTI_ROLLBACK_STATUS)
57+
security_attribute_show(anti_rollback_status)
5958
static DEVICE_ATTR_RO(anti_rollback_status);
60-
security_attribute_show(rpmc_production_enabled, RPMC_PRODUCTION_ENABLED)
59+
security_attribute_show(rpmc_production_enabled)
6160
static DEVICE_ATTR_RO(rpmc_production_enabled);
62-
security_attribute_show(rpmc_spirom_available, RPMC_SPIROM_AVAILABLE)
61+
security_attribute_show(rpmc_spirom_available)
6362
static DEVICE_ATTR_RO(rpmc_spirom_available);
64-
security_attribute_show(hsp_tpm_available, HSP_TPM_AVAILABLE)
63+
security_attribute_show(hsp_tpm_available)
6564
static DEVICE_ATTR_RO(hsp_tpm_available);
66-
security_attribute_show(rom_armor_enforced, ROM_ARMOR_ENFORCED)
65+
security_attribute_show(rom_armor_enforced)
6766
static DEVICE_ATTR_RO(rom_armor_enforced);
6867

6968
static struct attribute *psp_security_attrs[] = {
@@ -84,7 +83,7 @@ static umode_t psp_security_is_visible(struct kobject *kobj, struct attribute *a
8483
struct sp_device *sp = dev_get_drvdata(dev);
8584
struct psp_device *psp = sp->psp_data;
8685

87-
if (psp && PSP_CAPABILITY(psp, PSP_SECURITY_REPORTING))
86+
if (psp && psp->capability.security_reporting)
8887
return 0444;
8988

9089
return 0;
@@ -134,8 +133,7 @@ static umode_t psp_firmware_is_visible(struct kobject *kobj, struct attribute *a
134133
psp->vdata->bootloader_info_reg)
135134
val = ioread32(psp->io_regs + psp->vdata->bootloader_info_reg);
136135

137-
if (attr == &dev_attr_tee_version.attr &&
138-
PSP_CAPABILITY(psp, TEE) &&
136+
if (attr == &dev_attr_tee_version.attr && psp->capability.tee &&
139137
psp->vdata->tee->info_reg)
140138
val = ioread32(psp->io_regs + psp->vdata->tee->info_reg);
141139

0 commit comments

Comments
 (0)