Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions drivers/crypto/ccp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ ccp-$(CONFIG_CRYPTO_DEV_SP_CCP) += ccp-dev.o \
ccp-dev-v5.o \
ccp-dmaengine.o
ccp-$(CONFIG_CRYPTO_DEV_CCP_DEBUGFS) += ccp-debugfs.o
ccp-$(CONFIG_PCI) += sp-pci.o
ccp-$(CONFIG_PCI) += sp-pci.o \
hygon/sp-pci.o
ccp-$(CONFIG_CRYPTO_DEV_SP_PSP) += psp-dev.o \
sev-dev.o \
tee-dev.o \
platform-access.o \
dbc.o
dbc.o \
hygon/psp-dev.o

obj-$(CONFIG_CRYPTO_DEV_CCP_CRYPTO) += ccp-crypto.o
ccp-crypto-objs := ccp-crypto-main.o \
Expand Down
30 changes: 30 additions & 0 deletions drivers/crypto/ccp/hygon/psp-dev.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* HYGON Platform Security Processor (PSP) interface
*
* Copyright (C) 2024 Hygon Info Technologies Ltd.
*
* Author: Liyang Han <hanliyang@hygon.cn>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#include <linux/psp-hygon.h>

#include "psp-dev.h"

/* Function and variable pointers for hooks */
struct hygon_psp_hooks_table hygon_psp_hooks;

int fixup_hygon_psp_caps(struct psp_device *psp)
{
/* the hygon psp is unavailable if bit0 is cleared in feature reg */
if (!(psp->capability & PSP_CAPABILITY_SEV))
return -ENODEV;

psp->capability &= ~(PSP_CAPABILITY_TEE |
PSP_CAPABILITY_PSP_SECURITY_REPORTING);
return 0;
}
32 changes: 32 additions & 0 deletions drivers/crypto/ccp/hygon/psp-dev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* HYGON Platform Security Processor (PSP) driver interface
*
* Copyright (C) 2024 Hygon Info Technologies Ltd.
*
* Author: Liyang Han <hanliyang@hygon.cn>
*/

#ifndef __CCP_HYGON_PSP_DEV_H__
#define __CCP_HYGON_PSP_DEV_H__

#include <linux/mutex.h>

#include "sp-dev.h"

#include "../psp-dev.h"
#include "../sev-dev.h"

/*
* Hooks table: a table of function and variable pointers filled in
* when psp init.
*/
extern struct hygon_psp_hooks_table {
bool sev_dev_hooks_installed;
struct mutex *sev_cmd_mutex;
int (*__sev_do_cmd_locked)(int cmd, void *data, int *psp_ret);
} hygon_psp_hooks;

int fixup_hygon_psp_caps(struct psp_device *psp);

#endif /* __CCP_HYGON_PSP_DEV_H__ */
30 changes: 30 additions & 0 deletions drivers/crypto/ccp/hygon/sp-dev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* HYGON Secure Processor interface
*
* Copyright (C) 2024 Hygon Info Technologies Ltd.
*
* Author: Liyang Han <hanliyang@hygon.cn>
*/

#ifndef __CCP_HYGON_SP_DEV_H__
#define __CCP_HYGON_SP_DEV_H__

#include <linux/processor.h>
#include <linux/ccp.h>

#include "../ccp-dev.h"
#include "../sp-dev.h"

#ifdef CONFIG_X86_64
static inline bool is_vendor_hygon(void)
{
return boot_cpu_data.x86_vendor == X86_VENDOR_HYGON;
}
#else
static inline bool is_vendor_hygon(void) { return false; }
#endif

extern const struct sp_dev_vdata hygon_dev_vdata[];

#endif /* __CCP_HYGON_SP_DEV_H__ */
65 changes: 65 additions & 0 deletions drivers/crypto/ccp/hygon/sp-pci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* HYGON Secure Processor interface driver
*
* Copyright (C) 2024 Hygon Info Technologies Ltd.
*
* Author: Liyang Han <hanliyang@hygon.cn>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#include "sp-dev.h"

#ifdef CONFIG_CRYPTO_DEV_SP_PSP
static const struct sev_vdata csvv1 = {
.cmdresp_reg = 0x10580, /* C2PMSG_32 */
.cmdbuff_addr_lo_reg = 0x105e0, /* C2PMSG_56 */
.cmdbuff_addr_hi_reg = 0x105e4, /* C2PMSG_57 */
};

static const struct psp_vdata pspv1 = {
.sev = &csvv1,
.bootloader_info_reg = 0x105ec, /* C2PMSG_59 */
.feature_reg = 0x105fc, /* C2PMSG_63 */
.inten_reg = 0x10610, /* P2CMSG_INTEN */
.intsts_reg = 0x10614, /* P2CMSG_INTSTS */
};

static const struct psp_vdata pspv2 = {
.sev = &csvv1,
.feature_reg = 0x105fc,
.inten_reg = 0x10670,
.intsts_reg = 0x10674,
};

#endif

const struct sp_dev_vdata hygon_dev_vdata[] = {
{ /* 0 */
.bar = 2,
#ifdef CONFIG_CRYPTO_DEV_SP_CCP
.ccp_vdata = &ccpv5a,
#endif
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
.psp_vdata = &pspv1,
#endif
},
{ /* 1 */
.bar = 2,
#ifdef CONFIG_CRYPTO_DEV_SP_CCP
.ccp_vdata = &ccpv5b,
#endif
},
{ /* 2 */
.bar = 2,
#ifdef CONFIG_CRYPTO_DEV_SP_CCP
.ccp_vdata = &ccpv5a,
#endif
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
.psp_vdata = &pspv2,
#endif
},
};
13 changes: 13 additions & 0 deletions drivers/crypto/ccp/psp-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "platform-access.h"
#include "dbc.h"

#include "hygon/psp-dev.h"

struct psp_device *psp_master;

static struct psp_device *psp_alloc_struct(struct sp_device *sp)
Expand Down Expand Up @@ -73,6 +75,17 @@ static unsigned int psp_get_capability(struct psp_device *psp)
}
psp->capability = val;

/*
* Fix capability of Hygon psp, the meaning of Hygon psp feature
* register is not exactly the same as AMD.
* Return -ENODEV directly if hygon psp not configured with CSV
* capability.
*/
if (is_vendor_hygon()) {
if (fixup_hygon_psp_caps(psp))
return -ENODEV;
}

/* Detect if TSME and SME are both enabled */
if (psp->capability & PSP_CAPABILITY_PSP_SECURITY_REPORTING &&
psp->capability & (PSP_SECURITY_TSME_STATUS << PSP_CAPABILITY_PSP_SECURITY_OFFSET) &&
Expand Down
19 changes: 19 additions & 0 deletions drivers/crypto/ccp/sev-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "psp-dev.h"
#include "sev-dev.h"

#include "hygon/psp-dev.h"

#define DEVICE_NAME "sev"
#define SEV_FW_FILE "amd/sev.fw"
#define SEV_FW_NAME_SIZE 64
Expand Down Expand Up @@ -1216,12 +1218,29 @@ static int sev_misc_init(struct sev_device *sev)
return 0;
}

/* Code to set all of the function and variable pointers */
static void sev_dev_install_hooks(void)
{
hygon_psp_hooks.sev_cmd_mutex = &sev_cmd_mutex;
hygon_psp_hooks.__sev_do_cmd_locked = __sev_do_cmd_locked;

hygon_psp_hooks.sev_dev_hooks_installed = true;
}

int sev_dev_init(struct psp_device *psp)
{
struct device *dev = psp->dev;
struct sev_device *sev;
int ret = -ENOMEM;

/*
* Install sev-dev related function and variable pointers hooks only
* for Hygon vendor, install these hooks here, even though the
* following initialization fails.
*/
if (is_vendor_hygon())
sev_dev_install_hooks();

if (!boot_cpu_has(X86_FEATURE_SEV)) {
dev_info_once(dev, "SEV: memory encryption not enabled by BIOS\n");
return 0;
Expand Down
7 changes: 7 additions & 0 deletions drivers/crypto/ccp/sp-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "ccp-dev.h"
#include "psp-dev.h"

#include "hygon/sp-dev.h"

/* used for version string AA.BB.CC.DD */
#define AA GENMASK(31, 24)
#define BB GENMASK(23, 16)
Expand Down Expand Up @@ -576,6 +578,11 @@ static const struct pci_device_id sp_pci_table[] = {
{ PCI_VDEVICE(AMD, 0x1649), (kernel_ulong_t)&dev_vdata[6] },
{ PCI_VDEVICE(AMD, 0x17E0), (kernel_ulong_t)&dev_vdata[7] },
{ PCI_VDEVICE(AMD, 0x156E), (kernel_ulong_t)&dev_vdata[8] },
{ PCI_VDEVICE(HYGON, 0x1456), (kernel_ulong_t)&hygon_dev_vdata[0] },
{ PCI_VDEVICE(HYGON, 0x1468), (kernel_ulong_t)&hygon_dev_vdata[1] },
{ PCI_VDEVICE(HYGON, 0x1486), (kernel_ulong_t)&hygon_dev_vdata[2] },
{ PCI_VDEVICE(HYGON, 0x14b8), (kernel_ulong_t)&hygon_dev_vdata[1] },
{ PCI_VDEVICE(HYGON, 0x14a6), (kernel_ulong_t)&hygon_dev_vdata[2] },
/* Last entry must be zero */
{ 0, }
};
Expand Down
17 changes: 17 additions & 0 deletions include/linux/psp-hygon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* HYGON Platform Security Processor (PSP) driver interface
*
* Copyright (C) 2024 Hygon Info Technologies Ltd.
*
* Author: Liyang Han <hanliyang@hygon.cn>
*/

#ifndef __PSP_HYGON_H__
#define __PSP_HYGON_H__

#ifdef CONFIG_CRYPTO_DEV_SP_PSP
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
#endif /* CONFIG_CRYPTO_DEV_SP_PSP */

#endif /* __PSP_HYGON_H__ */
14 changes: 14 additions & 0 deletions include/uapi/linux/psp-hygon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
/*
* Userspace interface for HYGON Platform Security Processor (PSP)
* commands.
*
* Copyright (C) 2024 Hygon Info Technologies Ltd.
*
* Author: Liyang Han <hanliyang@hygon.cn>
*/

#ifndef __PSP_HYGON_USER_H__
#define __PSP_HYGON_USER_H__

#endif /* __PSP_HYGON_USER_H__ */