Skip to content

Commit 05f0db2

Browse files
hanliyangopsiff
authored andcommitted
crypto: ccp: Introduce hygon specific interface to support driver
hygon inclusion category: feature CVE: NA --------------------------- Hygon secure processors provide a lot of security functions, which require a lot of code to support. In order to prevent Hygon function code from invading the driver's native code, we introduce specific files for Hygon. We'll leave the native code unchanged as much as possible. In this patch, we add files as below: a. files for codes to support Hygon secure processor: drivers/crypto/ccp/hygon/sp-dev.h drivers/crypto/ccp/hygon/sp-pci.c drivers/crypto/ccp/hygon/psp-dev.c drivers/crypto/ccp/hygon/psp-dev.h b. header file to define data types and structures for HYGON Platform Security Processor: include/linux/psp-hygon.h c. header file to define userspace interface for HYGON Platform Security Processor: include/uapi/linux/psp-hygon.h We'll add more Hygon specific code in the following commits. Signed-off-by: hanliyang <[email protected]>
1 parent 2730144 commit 05f0db2

File tree

8 files changed

+182
-2
lines changed

8 files changed

+182
-2
lines changed

drivers/crypto/ccp/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ ccp-$(CONFIG_CRYPTO_DEV_SP_CCP) += ccp-dev.o \
77
ccp-dev-v5.o \
88
ccp-dmaengine.o
99
ccp-$(CONFIG_CRYPTO_DEV_CCP_DEBUGFS) += ccp-debugfs.o
10-
ccp-$(CONFIG_PCI) += sp-pci.o
10+
ccp-$(CONFIG_PCI) += sp-pci.o \
11+
hygon/sp-pci.o
1112
ccp-$(CONFIG_CRYPTO_DEV_SP_PSP) += psp-dev.o \
1213
sev-dev.o \
1314
tee-dev.o \
1415
platform-access.o \
15-
dbc.o
16+
dbc.o \
17+
hygon/psp-dev.o
1618

1719
obj-$(CONFIG_CRYPTO_DEV_CCP_CRYPTO) += ccp-crypto.o
1820
ccp-crypto-objs := ccp-crypto-main.o \

drivers/crypto/ccp/hygon/psp-dev.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* HYGON Platform Security Processor (PSP) interface
4+
*
5+
* Copyright (C) 2024 Hygon Info Technologies Ltd.
6+
*
7+
* Author: Liyang Han <[email protected]>
8+
*
9+
* This program is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License version 2 as
11+
* published by the Free Software Foundation.
12+
*/
13+
14+
#include <linux/psp-hygon.h>
15+
16+
#include "psp-dev.h"
17+
18+
/* Function and variable pointers for hooks */
19+
struct hygon_psp_hooks_table hygon_psp_hooks;

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* HYGON Platform Security Processor (PSP) driver interface
4+
*
5+
* Copyright (C) 2024 Hygon Info Technologies Ltd.
6+
*
7+
* Author: Liyang Han <[email protected]>
8+
*/
9+
10+
#ifndef __CCP_HYGON_PSP_DEV_H__
11+
#define __CCP_HYGON_PSP_DEV_H__
12+
13+
#include <linux/mutex.h>
14+
15+
#include "sp-dev.h"
16+
17+
#include "../psp-dev.h"
18+
#include "../sev-dev.h"
19+
20+
/*
21+
* Hooks table: a table of function and variable pointers filled in
22+
* when psp init.
23+
*/
24+
extern struct hygon_psp_hooks_table {
25+
bool sev_dev_hooks_installed;
26+
struct mutex *sev_cmd_mutex;
27+
int (*__sev_do_cmd_locked)(int cmd, void *data, int *psp_ret);
28+
} hygon_psp_hooks;
29+
30+
#endif /* __CCP_HYGON_PSP_DEV_H__ */

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* HYGON Secure Processor interface
4+
*
5+
* Copyright (C) 2024 Hygon Info Technologies Ltd.
6+
*
7+
* Author: Liyang Han <[email protected]>
8+
*/
9+
10+
#ifndef __CCP_HYGON_SP_DEV_H__
11+
#define __CCP_HYGON_SP_DEV_H__
12+
13+
#include <linux/processor.h>
14+
#include <linux/ccp.h>
15+
16+
#include "../ccp-dev.h"
17+
#include "../sp-dev.h"
18+
19+
#ifdef CONFIG_X86_64
20+
static inline bool is_vendor_hygon(void)
21+
{
22+
return boot_cpu_data.x86_vendor == X86_VENDOR_HYGON;
23+
}
24+
#else
25+
static inline bool is_vendor_hygon(void) { return false; }
26+
#endif
27+
28+
extern const struct sp_dev_vdata hygon_dev_vdata[];
29+
30+
#endif /* __CCP_HYGON_SP_DEV_H__ */

drivers/crypto/ccp/hygon/sp-pci.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* HYGON Secure Processor interface driver
4+
*
5+
* Copyright (C) 2024 Hygon Info Technologies Ltd.
6+
*
7+
* Author: Liyang Han <[email protected]>
8+
*
9+
* This program is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License version 2 as
11+
* published by the Free Software Foundation.
12+
*/
13+
14+
#include "sp-dev.h"
15+
16+
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
17+
static const struct sev_vdata csvv1 = {
18+
.cmdresp_reg = 0x10580, /* C2PMSG_32 */
19+
.cmdbuff_addr_lo_reg = 0x105e0, /* C2PMSG_56 */
20+
.cmdbuff_addr_hi_reg = 0x105e4, /* C2PMSG_57 */
21+
};
22+
23+
static const struct psp_vdata pspv1 = {
24+
.sev = &csvv1,
25+
.bootloader_info_reg = 0x105ec, /* C2PMSG_59 */
26+
.feature_reg = 0x105fc, /* C2PMSG_63 */
27+
.inten_reg = 0x10610, /* P2CMSG_INTEN */
28+
.intsts_reg = 0x10614, /* P2CMSG_INTSTS */
29+
};
30+
31+
#endif
32+
33+
const struct sp_dev_vdata hygon_dev_vdata[] = {
34+
{ /* 0 */
35+
.bar = 2,
36+
#ifdef CONFIG_CRYPTO_DEV_SP_CCP
37+
.ccp_vdata = &ccpv5a,
38+
#endif
39+
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
40+
.psp_vdata = &pspv1,
41+
#endif
42+
},
43+
{ /* 1 */
44+
.bar = 2,
45+
#ifdef CONFIG_CRYPTO_DEV_SP_CCP
46+
.ccp_vdata = &ccpv5b,
47+
#endif
48+
},
49+
};

drivers/crypto/ccp/sev-dev.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "psp-dev.h"
3434
#include "sev-dev.h"
3535

36+
#include "hygon/psp-dev.h"
37+
3638
#define DEVICE_NAME "sev"
3739
#define SEV_FW_FILE "amd/sev.fw"
3840
#define SEV_FW_NAME_SIZE 64
@@ -1216,12 +1218,29 @@ static int sev_misc_init(struct sev_device *sev)
12161218
return 0;
12171219
}
12181220

1221+
/* Code to set all of the function and variable pointers */
1222+
static void sev_dev_install_hooks(void)
1223+
{
1224+
hygon_psp_hooks.sev_cmd_mutex = &sev_cmd_mutex;
1225+
hygon_psp_hooks.__sev_do_cmd_locked = __sev_do_cmd_locked;
1226+
1227+
hygon_psp_hooks.sev_dev_hooks_installed = true;
1228+
}
1229+
12191230
int sev_dev_init(struct psp_device *psp)
12201231
{
12211232
struct device *dev = psp->dev;
12221233
struct sev_device *sev;
12231234
int ret = -ENOMEM;
12241235

1236+
/*
1237+
* Install sev-dev related function and variable pointers hooks only
1238+
* for Hygon vendor, install these hooks here, even though the
1239+
* following initialization fails.
1240+
*/
1241+
if (is_vendor_hygon())
1242+
sev_dev_install_hooks();
1243+
12251244
if (!boot_cpu_has(X86_FEATURE_SEV)) {
12261245
dev_info_once(dev, "SEV: memory encryption not enabled by BIOS\n");
12271246
return 0;

include/linux/psp-hygon.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* HYGON Platform Security Processor (PSP) driver interface
4+
*
5+
* Copyright (C) 2024 Hygon Info Technologies Ltd.
6+
*
7+
* Author: Liyang Han <[email protected]>
8+
*/
9+
10+
#ifndef __PSP_HYGON_H__
11+
#define __PSP_HYGON_H__
12+
13+
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
14+
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
15+
#endif /* CONFIG_CRYPTO_DEV_SP_PSP */
16+
17+
#endif /* __PSP_HYGON_H__ */

include/uapi/linux/psp-hygon.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2+
/*
3+
* Userspace interface for HYGON Platform Security Processor (PSP)
4+
* commands.
5+
*
6+
* Copyright (C) 2024 Hygon Info Technologies Ltd.
7+
*
8+
* Author: Liyang Han <[email protected]>
9+
*/
10+
11+
#ifndef __PSP_HYGON_USER_H__
12+
#define __PSP_HYGON_USER_H__
13+
14+
#endif /* __PSP_HYGON_USER_H__ */

0 commit comments

Comments
 (0)