Skip to content

Commit fba194e

Browse files
hanliyangWangYuli
authored andcommitted
crypto: ccp: Support DOWNLOAD_FIRMWARE when detect CSV
hygon inclusion category: feature CVE: NA --------------------------- When ccp driver detect CSV support on Hygon CPU, it should try to update the latest CSV firmware on the system paths. Signed-off-by: hanliyang <hanliyang@hygon.cn>
1 parent a97e352 commit fba194e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

drivers/crypto/ccp/hygon/csv-dev.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@
1313
#include <linux/fs.h>
1414
#include <linux/psp-sev.h>
1515

16+
#define CSV_FW_FILE "hygon/csv.fw"
17+
1618
extern u32 hygon_csv_build;
1719
extern const struct file_operations csv_fops;
1820

1921
void csv_update_api_version(struct sev_user_data_status *status);
2022
int csv_cmd_buffer_len(int cmd);
2123

24+
static inline bool csv_version_greater_or_equal(u32 build)
25+
{
26+
return hygon_csv_build >= build;
27+
}
28+
2229
#endif /* __CCP_HYGON_CSV_DEV_H__ */

drivers/crypto/ccp/sev-dev.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,14 @@ static int sev_get_firmware(struct device *dev,
758758
char fw_name_specific[SEV_FW_NAME_SIZE];
759759
char fw_name_subset[SEV_FW_NAME_SIZE];
760760

761+
if (is_vendor_hygon()) {
762+
/* Check for CSV FW to using generic name: csv.fw */
763+
if (firmware_request_nowarn(firmware, CSV_FW_FILE, dev) >= 0)
764+
return 0;
765+
else
766+
return -ENOENT;
767+
}
768+
761769
snprintf(fw_name_specific, sizeof(fw_name_specific),
762770
"amd/amd_sev_fam%.2xh_model%.2xh.sbin",
763771
boot_cpu_data.x86, boot_cpu_data.x86_model);
@@ -796,13 +804,15 @@ static int sev_update_firmware(struct device *dev)
796804
struct page *p;
797805
u64 data_size;
798806

799-
if (!sev_version_greater_or_equal(0, 15)) {
807+
if (!sev_version_greater_or_equal(0, 15) &&
808+
!(is_vendor_hygon() && csv_version_greater_or_equal(1667))) {
800809
dev_dbg(dev, "DOWNLOAD_FIRMWARE not supported\n");
801810
return -1;
802811
}
803812

804813
if (sev_get_firmware(dev, &firmware) == -ENOENT) {
805-
dev_dbg(dev, "No SEV firmware file present\n");
814+
dev_dbg(dev, "No %s firmware file present\n",
815+
is_vendor_hygon() ? "CSV" : "SEV");
806816
return -1;
807817
}
808818

@@ -842,9 +852,11 @@ static int sev_update_firmware(struct device *dev)
842852
ret = sev_do_cmd(SEV_CMD_DOWNLOAD_FIRMWARE, data, &error);
843853

844854
if (ret)
845-
dev_dbg(dev, "Failed to update SEV firmware: %#x\n", error);
855+
dev_dbg(dev, "Failed to update %s firmware: %#x\n",
856+
is_vendor_hygon() ? "CSV" : "SEV", error);
846857
else
847-
dev_info(dev, "SEV firmware update successful\n");
858+
dev_info(dev, "%s firmware update successful\n",
859+
is_vendor_hygon() ? "CSV" : "SEV");
848860

849861
__free_pages(p, order);
850862

0 commit comments

Comments
 (0)