Skip to content

Commit 720419f

Browse files
codomaniaherbertx
authored andcommitted
crypto: ccp - Introduce the AMD Secure Processor device
The CCP device is part of the AMD Secure Processor. In order to expand the usage of the AMD Secure Processor, create a framework that allows functional components of the AMD Secure Processor to be initialized and handled appropriately. Signed-off-by: Brijesh Singh <[email protected]> Acked-by: Gary R Hook <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 970e830 commit 720419f

File tree

12 files changed

+463
-164
lines changed

12 files changed

+463
-164
lines changed

drivers/crypto/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,11 @@ config CRYPTO_DEV_ATMEL_ECC
540540
will be called atmel-ecc.
541541

542542
config CRYPTO_DEV_CCP
543-
bool "Support for AMD Cryptographic Coprocessor"
543+
bool "Support for AMD Secure Processor"
544544
depends on ((X86 && PCI) || (ARM64 && (OF_ADDRESS || ACPI))) && HAS_IOMEM
545545
help
546-
The AMD Cryptographic Coprocessor provides hardware offload support
547-
for encryption, hashing and related operations.
546+
The AMD Secure Processor provides support for the Cryptographic Coprocessor
547+
(CCP) and the Platform Security Processor (PSP) devices.
548548

549549
if CRYPTO_DEV_CCP
550550
source "drivers/crypto/ccp/Kconfig"

drivers/crypto/ccp/Kconfig

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
config CRYPTO_DEV_CCP_DD
2-
tristate "Cryptographic Coprocessor device driver"
3-
depends on CRYPTO_DEV_CCP
2+
tristate "Secure Processor device driver"
43
default m
4+
help
5+
Provides AMD Secure Processor device driver.
6+
If you choose 'M' here, this module will be called ccp.
7+
8+
config CRYPTO_DEV_SP_CCP
9+
bool "Cryptographic Coprocessor device"
10+
default y
11+
depends on CRYPTO_DEV_CCP_DD
512
select HW_RANDOM
613
select DMA_ENGINE
714
select DMADEVICES
815
select CRYPTO_SHA1
916
select CRYPTO_SHA256
1017
help
11-
Provides the interface to use the AMD Cryptographic Coprocessor
12-
which can be used to offload encryption operations such as SHA,
13-
AES and more. If you choose 'M' here, this module will be called
14-
ccp.
18+
Provides the support for AMD Cryptographic Coprocessor (CCP) device
19+
which can be used to offload encryption operations such as SHA, AES
20+
and more.
1521

1622
config CRYPTO_DEV_CCP_CRYPTO
1723
tristate "Encryption and hashing offload support"
18-
depends on CRYPTO_DEV_CCP_DD
1924
default m
25+
depends on CRYPTO_DEV_CCP_DD
26+
depends on CRYPTO_DEV_SP_CCP
2027
select CRYPTO_HASH
2128
select CRYPTO_BLKCIPHER
2229
select CRYPTO_AUTHENC

drivers/crypto/ccp/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
obj-$(CONFIG_CRYPTO_DEV_CCP_DD) += ccp.o
2-
ccp-objs := ccp-dev.o \
2+
ccp-objs := sp-dev.o ccp-platform.o
3+
ccp-$(CONFIG_CRYPTO_DEV_SP_CCP) += ccp-dev.o \
34
ccp-ops.o \
45
ccp-dev-v3.o \
56
ccp-dev-v5.o \
6-
ccp-platform.o \
77
ccp-dmaengine.o \
88
ccp-debugfs.o
99
ccp-$(CONFIG_PCI) += ccp-pci.o

drivers/crypto/ccp/ccp-dev-v3.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ static void ccp_irq_bh(unsigned long data)
359359

360360
static irqreturn_t ccp_irq_handler(int irq, void *data)
361361
{
362-
struct device *dev = data;
363-
struct ccp_device *ccp = dev_get_drvdata(dev);
362+
struct ccp_device *ccp = (struct ccp_device *)data;
364363

365364
ccp_disable_queue_interrupts(ccp);
366365
if (ccp->use_tasklet)
@@ -597,6 +596,5 @@ const struct ccp_vdata ccpv3 = {
597596
.version = CCP_VERSION(3, 0),
598597
.setup = NULL,
599598
.perform = &ccp3_actions,
600-
.bar = 2,
601599
.offset = 0x20000,
602600
};

drivers/crypto/ccp/ccp-dev-v5.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,7 @@ static void ccp5_irq_bh(unsigned long data)
769769

770770
static irqreturn_t ccp5_irq_handler(int irq, void *data)
771771
{
772-
struct device *dev = data;
773-
struct ccp_device *ccp = dev_get_drvdata(dev);
772+
struct ccp_device *ccp = (struct ccp_device *)data;
774773

775774
ccp5_disable_queue_interrupts(ccp);
776775
ccp->total_interrupts++;
@@ -1113,7 +1112,6 @@ const struct ccp_vdata ccpv5a = {
11131112
.version = CCP_VERSION(5, 0),
11141113
.setup = ccp5_config,
11151114
.perform = &ccp5_actions,
1116-
.bar = 2,
11171115
.offset = 0x0,
11181116
};
11191117

@@ -1122,6 +1120,5 @@ const struct ccp_vdata ccpv5b = {
11221120
.dma_chan_attr = DMA_PRIVATE,
11231121
.setup = ccp5other_config,
11241122
.perform = &ccp5_actions,
1125-
.bar = 2,
11261123
.offset = 0x0,
11271124
};

drivers/crypto/ccp/ccp-dev.c

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,6 @@ static LIST_HEAD(ccp_units);
111111
static DEFINE_SPINLOCK(ccp_rr_lock);
112112
static struct ccp_device *ccp_rr;
113113

114-
/* Ever-increasing value to produce unique unit numbers */
115-
static atomic_t ccp_unit_ordinal;
116-
static unsigned int ccp_increment_unit_ordinal(void)
117-
{
118-
return atomic_inc_return(&ccp_unit_ordinal);
119-
}
120-
121114
/**
122115
* ccp_add_device - add a CCP device to the list
123116
*
@@ -465,14 +458,17 @@ int ccp_cmd_queue_thread(void *data)
465458
*
466459
* @dev: device struct of the CCP
467460
*/
468-
struct ccp_device *ccp_alloc_struct(struct device *dev)
461+
struct ccp_device *ccp_alloc_struct(struct sp_device *sp)
469462
{
463+
struct device *dev = sp->dev;
470464
struct ccp_device *ccp;
471465

472466
ccp = devm_kzalloc(dev, sizeof(*ccp), GFP_KERNEL);
473467
if (!ccp)
474468
return NULL;
475469
ccp->dev = dev;
470+
ccp->sp = sp;
471+
ccp->axcache = sp->axcache;
476472

477473
INIT_LIST_HEAD(&ccp->cmd);
478474
INIT_LIST_HEAD(&ccp->backlog);
@@ -487,9 +483,8 @@ struct ccp_device *ccp_alloc_struct(struct device *dev)
487483
init_waitqueue_head(&ccp->sb_queue);
488484
init_waitqueue_head(&ccp->suspend_queue);
489485

490-
ccp->ord = ccp_increment_unit_ordinal();
491-
snprintf(ccp->name, MAX_CCP_NAME_LEN, "ccp-%u", ccp->ord);
492-
snprintf(ccp->rngname, MAX_CCP_NAME_LEN, "ccp-%u-rng", ccp->ord);
486+
snprintf(ccp->name, MAX_CCP_NAME_LEN, "ccp-%u", sp->ord);
487+
snprintf(ccp->rngname, MAX_CCP_NAME_LEN, "ccp-%u-rng", sp->ord);
493488

494489
return ccp;
495490
}
@@ -540,8 +535,9 @@ bool ccp_queues_suspended(struct ccp_device *ccp)
540535
return ccp->cmd_q_count == suspended;
541536
}
542537

543-
int ccp_dev_suspend(struct ccp_device *ccp, pm_message_t state)
538+
int ccp_dev_suspend(struct sp_device *sp, pm_message_t state)
544539
{
540+
struct ccp_device *ccp = sp->ccp_data;
545541
unsigned long flags;
546542
unsigned int i;
547543

@@ -563,8 +559,9 @@ int ccp_dev_suspend(struct ccp_device *ccp, pm_message_t state)
563559
return 0;
564560
}
565561

566-
int ccp_dev_resume(struct ccp_device *ccp)
562+
int ccp_dev_resume(struct sp_device *sp)
567563
{
564+
struct ccp_device *ccp = sp->ccp_data;
568565
unsigned long flags;
569566
unsigned int i;
570567

@@ -584,71 +581,54 @@ int ccp_dev_resume(struct ccp_device *ccp)
584581
}
585582
#endif
586583

587-
int ccp_dev_init(struct ccp_device *ccp)
584+
int ccp_dev_init(struct sp_device *sp)
588585
{
589-
ccp->io_regs = ccp->io_map + ccp->vdata->offset;
590-
591-
if (ccp->vdata->setup)
592-
ccp->vdata->setup(ccp);
593-
594-
return ccp->vdata->perform->init(ccp);
595-
}
586+
struct device *dev = sp->dev;
587+
struct ccp_device *ccp;
588+
int ret;
596589

597-
void ccp_dev_destroy(struct ccp_device *ccp)
598-
{
590+
ret = -ENOMEM;
591+
ccp = ccp_alloc_struct(sp);
599592
if (!ccp)
600-
return;
593+
goto e_err;
594+
sp->ccp_data = ccp;
595+
596+
ccp->vdata = (struct ccp_vdata *)sp->dev_vdata->ccp_vdata;
597+
if (!ccp->vdata || !ccp->vdata->version) {
598+
ret = -ENODEV;
599+
dev_err(dev, "missing driver data\n");
600+
goto e_err;
601+
}
601602

602-
ccp->vdata->perform->destroy(ccp);
603-
}
603+
ccp->get_irq = sp->get_irq;
604+
ccp->free_irq = sp->free_irq;
604605

605-
static int __init ccp_mod_init(void)
606-
{
607-
#ifdef CONFIG_X86
608-
int ret;
606+
ccp->io_regs = sp->io_map + ccp->vdata->offset;
607+
if (ccp->vdata->setup)
608+
ccp->vdata->setup(ccp);
609609

610-
ret = ccp_pci_init();
610+
ret = ccp->vdata->perform->init(ccp);
611611
if (ret)
612-
return ret;
612+
goto e_err;
613613

614-
/* Don't leave the driver loaded if init failed */
615-
if (ccp_present() != 0) {
616-
ccp_pci_exit();
617-
return -ENODEV;
618-
}
614+
dev_notice(dev, "ccp enabled\n");
619615

620616
return 0;
621-
#endif
622-
623-
#ifdef CONFIG_ARM64
624-
int ret;
625617

626-
ret = ccp_platform_init();
627-
if (ret)
628-
return ret;
618+
e_err:
619+
sp->ccp_data = NULL;
629620

630-
/* Don't leave the driver loaded if init failed */
631-
if (ccp_present() != 0) {
632-
ccp_platform_exit();
633-
return -ENODEV;
634-
}
635-
636-
return 0;
637-
#endif
621+
dev_notice(dev, "ccp initialization failed\n");
638622

639-
return -ENODEV;
623+
return ret;
640624
}
641625

642-
static void __exit ccp_mod_exit(void)
626+
void ccp_dev_destroy(struct sp_device *sp)
643627
{
644-
#ifdef CONFIG_X86
645-
ccp_pci_exit();
646-
#endif
628+
struct ccp_device *ccp = sp->ccp_data;
647629

648-
#ifdef CONFIG_ARM64
649-
ccp_platform_exit();
650-
#endif
651-
}
630+
if (!ccp)
631+
return;
652632

653-
module_init(ccp_mod_init);
654-
module_exit(ccp_mod_exit);
633+
ccp->vdata->perform->destroy(ccp);
634+
}

drivers/crypto/ccp/ccp-dev.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <linux/irqreturn.h>
2828
#include <linux/dmaengine.h>
2929

30+
#include "sp-dev.h"
31+
3032
#define MAX_CCP_NAME_LEN 16
3133
#define MAX_DMAPOOL_NAME_LEN 32
3234

@@ -344,6 +346,7 @@ struct ccp_device {
344346
char rngname[MAX_CCP_NAME_LEN];
345347

346348
struct device *dev;
349+
struct sp_device *sp;
347350

348351
/* Bus specific device information
349352
*/
@@ -362,7 +365,6 @@ struct ccp_device {
362365
* them.
363366
*/
364367
struct mutex req_mutex ____cacheline_aligned;
365-
void __iomem *io_map;
366368
void __iomem *io_regs;
367369

368370
/* Master lists that all cmds are queued on. Because there can be
@@ -637,7 +639,7 @@ void ccp_del_device(struct ccp_device *ccp);
637639

638640
extern void ccp_log_error(struct ccp_device *, int);
639641

640-
struct ccp_device *ccp_alloc_struct(struct device *dev);
642+
struct ccp_device *ccp_alloc_struct(struct sp_device *sp);
641643
bool ccp_queues_suspended(struct ccp_device *ccp);
642644
int ccp_cmd_queue_thread(void *data);
643645
int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait);
@@ -652,11 +654,6 @@ void ccp_dmaengine_unregister(struct ccp_device *ccp);
652654
void ccp5_debugfs_setup(struct ccp_device *ccp);
653655
void ccp5_debugfs_destroy(void);
654656

655-
int ccp_dev_init(struct ccp_device *ccp);
656-
void ccp_dev_destroy(struct ccp_device *ccp);
657-
int ccp_dev_suspend(struct ccp_device *ccp, pm_message_t state);
658-
int ccp_dev_resume(struct ccp_device *ccp);
659-
660657
/* Structure for computation functions that are device-specific */
661658
struct ccp_actions {
662659
int (*aes)(struct ccp_op *);
@@ -674,16 +671,6 @@ struct ccp_actions {
674671
irqreturn_t (*irqhandler)(int, void *);
675672
};
676673

677-
/* Structure to hold CCP version-specific values */
678-
struct ccp_vdata {
679-
const unsigned int version;
680-
const unsigned int dma_chan_attr;
681-
void (*setup)(struct ccp_device *);
682-
const struct ccp_actions *perform;
683-
const unsigned int bar;
684-
const unsigned int offset;
685-
};
686-
687674
extern const struct ccp_vdata ccpv3_platform;
688675
extern const struct ccp_vdata ccpv3;
689676
extern const struct ccp_vdata ccpv5a;

0 commit comments

Comments
 (0)