| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * AMD Cryptographic Coprocessor (CCP) driver |
|---|
| 3 | 4 | * |
|---|
| 4 | | - * Copyright (C) 2016,2017 Advanced Micro Devices, Inc. |
|---|
| 5 | + * Copyright (C) 2016,2019 Advanced Micro Devices, Inc. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * 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. |
|---|
| 11 | 8 | */ |
|---|
| 12 | 9 | |
|---|
| 13 | 10 | #include <linux/module.h> |
|---|
| 14 | 11 | #include <linux/kernel.h> |
|---|
| 12 | +#include <linux/dma-mapping.h> |
|---|
| 15 | 13 | #include <linux/dmaengine.h> |
|---|
| 16 | 14 | #include <linux/spinlock.h> |
|---|
| 17 | 15 | #include <linux/mutex.h> |
|---|
| .. | .. |
|---|
| 37 | 35 | static unsigned int dma_chan_attr = CCP_DMA_DFLT; |
|---|
| 38 | 36 | module_param(dma_chan_attr, uint, 0444); |
|---|
| 39 | 37 | 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)"); |
|---|
| 40 | 42 | |
|---|
| 41 | 43 | static unsigned int ccp_get_dma_chan_attr(struct ccp_device *ccp) |
|---|
| 42 | 44 | { |
|---|
| .. | .. |
|---|
| 631 | 633 | return 0; |
|---|
| 632 | 634 | } |
|---|
| 633 | 635 | |
|---|
| 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 | + |
|---|
| 634 | 654 | int ccp_dmaengine_register(struct ccp_device *ccp) |
|---|
| 635 | 655 | { |
|---|
| 636 | 656 | struct ccp_dma_chan *chan; |
|---|
| .. | .. |
|---|
| 640 | 660 | char *dma_desc_cache_name; |
|---|
| 641 | 661 | unsigned int i; |
|---|
| 642 | 662 | int ret; |
|---|
| 663 | + |
|---|
| 664 | + if (!dmaengine) |
|---|
| 665 | + return 0; |
|---|
| 643 | 666 | |
|---|
| 644 | 667 | ccp->ccp_dma_chan = devm_kcalloc(ccp->dev, ccp->cmd_q_count, |
|---|
| 645 | 668 | sizeof(*(ccp->ccp_dma_chan)), |
|---|
| .. | .. |
|---|
| 732 | 755 | return 0; |
|---|
| 733 | 756 | |
|---|
| 734 | 757 | err_reg: |
|---|
| 758 | + ccp_dma_release(ccp); |
|---|
| 735 | 759 | kmem_cache_destroy(ccp->dma_desc_cache); |
|---|
| 736 | 760 | |
|---|
| 737 | 761 | err_cache: |
|---|
| .. | .. |
|---|
| 744 | 768 | { |
|---|
| 745 | 769 | struct dma_device *dma_dev = &ccp->dma_dev; |
|---|
| 746 | 770 | |
|---|
| 771 | + if (!dmaengine) |
|---|
| 772 | + return; |
|---|
| 773 | + |
|---|
| 774 | + ccp_dma_release(ccp); |
|---|
| 747 | 775 | dma_async_device_unregister(dma_dev); |
|---|
| 748 | 776 | |
|---|
| 749 | 777 | kmem_cache_destroy(ccp->dma_desc_cache); |
|---|