hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/crypto/ccp/ccp-dmaengine.c
....@@ -1,17 +1,15 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AMD Cryptographic Coprocessor (CCP) driver
34 *
4
- * Copyright (C) 2016,2017 Advanced Micro Devices, Inc.
5
+ * Copyright (C) 2016,2019 Advanced Micro Devices, Inc.
56 *
67 * Author: Gary R Hook <gary.hook@amd.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/module.h>
1411 #include <linux/kernel.h>
12
+#include <linux/dma-mapping.h>
1513 #include <linux/dmaengine.h>
1614 #include <linux/spinlock.h>
1715 #include <linux/mutex.h>
....@@ -37,6 +35,10 @@
3735 static unsigned int dma_chan_attr = CCP_DMA_DFLT;
3836 module_param(dma_chan_attr, uint, 0444);
3937 MODULE_PARM_DESC(dma_chan_attr, "Set DMA channel visibility: 0 (default) = device defaults, 1 = make private, 2 = make public");
38
+
39
+static unsigned int dmaengine = 1;
40
+module_param(dmaengine, uint, 0444);
41
+MODULE_PARM_DESC(dmaengine, "Register services with the DMA subsystem (any non-zero value, default: 1)");
4042
4143 static unsigned int ccp_get_dma_chan_attr(struct ccp_device *ccp)
4244 {
....@@ -631,6 +633,36 @@
631633 return 0;
632634 }
633635
636
+static void ccp_dma_release(struct ccp_device *ccp)
637
+{
638
+ struct ccp_dma_chan *chan;
639
+ struct dma_chan *dma_chan;
640
+ unsigned int i;
641
+
642
+ for (i = 0; i < ccp->cmd_q_count; i++) {
643
+ chan = ccp->ccp_dma_chan + i;
644
+ dma_chan = &chan->dma_chan;
645
+
646
+ tasklet_kill(&chan->cleanup_tasklet);
647
+ list_del_rcu(&dma_chan->device_node);
648
+ }
649
+}
650
+
651
+static void ccp_dma_release_channels(struct ccp_device *ccp)
652
+{
653
+ struct ccp_dma_chan *chan;
654
+ struct dma_chan *dma_chan;
655
+ unsigned int i;
656
+
657
+ for (i = 0; i < ccp->cmd_q_count; i++) {
658
+ chan = ccp->ccp_dma_chan + i;
659
+ dma_chan = &chan->dma_chan;
660
+
661
+ if (dma_chan->client_count)
662
+ dma_release_channel(dma_chan);
663
+ }
664
+}
665
+
634666 int ccp_dmaengine_register(struct ccp_device *ccp)
635667 {
636668 struct ccp_dma_chan *chan;
....@@ -640,6 +672,9 @@
640672 char *dma_desc_cache_name;
641673 unsigned int i;
642674 int ret;
675
+
676
+ if (!dmaengine)
677
+ return 0;
643678
644679 ccp->ccp_dma_chan = devm_kcalloc(ccp->dev, ccp->cmd_q_count,
645680 sizeof(*(ccp->ccp_dma_chan)),
....@@ -732,6 +767,7 @@
732767 return 0;
733768
734769 err_reg:
770
+ ccp_dma_release(ccp);
735771 kmem_cache_destroy(ccp->dma_desc_cache);
736772
737773 err_cache:
....@@ -744,7 +780,12 @@
744780 {
745781 struct dma_device *dma_dev = &ccp->dma_dev;
746782
783
+ if (!dmaengine)
784
+ return;
785
+
786
+ ccp_dma_release_channels(ccp);
747787 dma_async_device_unregister(dma_dev);
788
+ ccp_dma_release(ccp);
748789
749790 kmem_cache_destroy(ccp->dma_desc_cache);
750791 kmem_cache_destroy(ccp->dma_cmd_cache);