diff options
author | Brijesh Singh <brijesh.singh@amd.com> | 2017-07-06 09:59:14 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-07-18 17:51:19 +0800 |
commit | 720419f01832f7e697cb80480b97b2a1e96045cd (patch) | |
tree | 1275fa5e6cf63b7bb9db6ab2e191d4b7d076ca4f /drivers/crypto/ccp/ccp-dev.c | |
parent | 970e8303cb8d6d8e77402345abbdd83862e800ac (diff) | |
download | linux-720419f01832f7e697cb80480b97b2a1e96045cd.tar.gz linux-720419f01832f7e697cb80480b97b2a1e96045cd.tar.bz2 linux-720419f01832f7e697cb80480b97b2a1e96045cd.zip |
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 <brijesh.singh@amd.com>
Acked-by: Gary R Hook <gary.hook@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/ccp/ccp-dev.c')
-rw-r--r-- | drivers/crypto/ccp/ccp-dev.c | 106 |
1 files changed, 43 insertions, 63 deletions
diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c index 83a0ce5661ad..6b4315f8dad9 100644 --- a/drivers/crypto/ccp/ccp-dev.c +++ b/drivers/crypto/ccp/ccp-dev.c @@ -111,13 +111,6 @@ static LIST_HEAD(ccp_units); static DEFINE_SPINLOCK(ccp_rr_lock); static struct ccp_device *ccp_rr; -/* Ever-increasing value to produce unique unit numbers */ -static atomic_t ccp_unit_ordinal; -static unsigned int ccp_increment_unit_ordinal(void) -{ - return atomic_inc_return(&ccp_unit_ordinal); -} - /** * ccp_add_device - add a CCP device to the list * @@ -465,14 +458,17 @@ int ccp_cmd_queue_thread(void *data) * * @dev: device struct of the CCP */ -struct ccp_device *ccp_alloc_struct(struct device *dev) +struct ccp_device *ccp_alloc_struct(struct sp_device *sp) { + struct device *dev = sp->dev; struct ccp_device *ccp; ccp = devm_kzalloc(dev, sizeof(*ccp), GFP_KERNEL); if (!ccp) return NULL; ccp->dev = dev; + ccp->sp = sp; + ccp->axcache = sp->axcache; INIT_LIST_HEAD(&ccp->cmd); INIT_LIST_HEAD(&ccp->backlog); @@ -487,9 +483,8 @@ struct ccp_device *ccp_alloc_struct(struct device *dev) init_waitqueue_head(&ccp->sb_queue); init_waitqueue_head(&ccp->suspend_queue); - ccp->ord = ccp_increment_unit_ordinal(); - snprintf(ccp->name, MAX_CCP_NAME_LEN, "ccp-%u", ccp->ord); - snprintf(ccp->rngname, MAX_CCP_NAME_LEN, "ccp-%u-rng", ccp->ord); + snprintf(ccp->name, MAX_CCP_NAME_LEN, "ccp-%u", sp->ord); + snprintf(ccp->rngname, MAX_CCP_NAME_LEN, "ccp-%u-rng", sp->ord); return ccp; } @@ -540,8 +535,9 @@ bool ccp_queues_suspended(struct ccp_device *ccp) return ccp->cmd_q_count == suspended; } -int ccp_dev_suspend(struct ccp_device *ccp, pm_message_t state) +int ccp_dev_suspend(struct sp_device *sp, pm_message_t state) { + struct ccp_device *ccp = sp->ccp_data; unsigned long flags; unsigned int i; @@ -563,8 +559,9 @@ int ccp_dev_suspend(struct ccp_device *ccp, pm_message_t state) return 0; } -int ccp_dev_resume(struct ccp_device *ccp) +int ccp_dev_resume(struct sp_device *sp) { + struct ccp_device *ccp = sp->ccp_data; unsigned long flags; unsigned int i; @@ -584,71 +581,54 @@ int ccp_dev_resume(struct ccp_device *ccp) } #endif -int ccp_dev_init(struct ccp_device *ccp) +int ccp_dev_init(struct sp_device *sp) { - ccp->io_regs = ccp->io_map + ccp->vdata->offset; - - if (ccp->vdata->setup) - ccp->vdata->setup(ccp); - - return ccp->vdata->perform->init(ccp); -} + struct device *dev = sp->dev; + struct ccp_device *ccp; + int ret; -void ccp_dev_destroy(struct ccp_device *ccp) -{ + ret = -ENOMEM; + ccp = ccp_alloc_struct(sp); if (!ccp) - return; + goto e_err; + sp->ccp_data = ccp; + + ccp->vdata = (struct ccp_vdata *)sp->dev_vdata->ccp_vdata; + if (!ccp->vdata || !ccp->vdata->version) { + ret = -ENODEV; + dev_err(dev, "missing driver data\n"); + goto e_err; + } - ccp->vdata->perform->destroy(ccp); -} + ccp->get_irq = sp->get_irq; + ccp->free_irq = sp->free_irq; -static int __init ccp_mod_init(void) -{ -#ifdef CONFIG_X86 - int ret; + ccp->io_regs = sp->io_map + ccp->vdata->offset; + if (ccp->vdata->setup) + ccp->vdata->setup(ccp); - ret = ccp_pci_init(); + ret = ccp->vdata->perform->init(ccp); if (ret) - return ret; + goto e_err; - /* Don't leave the driver loaded if init failed */ - if (ccp_present() != 0) { - ccp_pci_exit(); - return -ENODEV; - } + dev_notice(dev, "ccp enabled\n"); return 0; -#endif - -#ifdef CONFIG_ARM64 - int ret; - ret = ccp_platform_init(); - if (ret) - return ret; +e_err: + sp->ccp_data = NULL; - /* Don't leave the driver loaded if init failed */ - if (ccp_present() != 0) { - ccp_platform_exit(); - return -ENODEV; - } - - return 0; -#endif + dev_notice(dev, "ccp initialization failed\n"); - return -ENODEV; + return ret; } -static void __exit ccp_mod_exit(void) +void ccp_dev_destroy(struct sp_device *sp) { -#ifdef CONFIG_X86 - ccp_pci_exit(); -#endif + struct ccp_device *ccp = sp->ccp_data; -#ifdef CONFIG_ARM64 - ccp_platform_exit(); -#endif -} + if (!ccp) + return; -module_init(ccp_mod_init); -module_exit(ccp_mod_exit); + ccp->vdata->perform->destroy(ccp); +} |