forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
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,24 @@
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
+ if (dma_chan->client_count)
647
+ dma_release_channel(dma_chan);
648
+
649
+ tasklet_kill(&chan->cleanup_tasklet);
650
+ list_del_rcu(&dma_chan->device_node);
651
+ }
652
+}
653
+
634654 int ccp_dmaengine_register(struct ccp_device *ccp)
635655 {
636656 struct ccp_dma_chan *chan;
....@@ -640,6 +660,9 @@
640660 char *dma_desc_cache_name;
641661 unsigned int i;
642662 int ret;
663
+
664
+ if (!dmaengine)
665
+ return 0;
643666
644667 ccp->ccp_dma_chan = devm_kcalloc(ccp->dev, ccp->cmd_q_count,
645668 sizeof(*(ccp->ccp_dma_chan)),
....@@ -732,6 +755,7 @@
732755 return 0;
733756
734757 err_reg:
758
+ ccp_dma_release(ccp);
735759 kmem_cache_destroy(ccp->dma_desc_cache);
736760
737761 err_cache:
....@@ -744,6 +768,10 @@
744768 {
745769 struct dma_device *dma_dev = &ccp->dma_dev;
746770
771
+ if (!dmaengine)
772
+ return;
773
+
774
+ ccp_dma_release(ccp);
747775 dma_async_device_unregister(dma_dev);
748776
749777 kmem_cache_destroy(ccp->dma_desc_cache);