| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Virtual DMA channel support for DMAengine |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Russell King |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | 6 | */ |
|---|
| 10 | 7 | #ifndef VIRT_DMA_H |
|---|
| 11 | 8 | #define VIRT_DMA_H |
|---|
| .. | .. |
|---|
| 17 | 14 | |
|---|
| 18 | 15 | struct virt_dma_desc { |
|---|
| 19 | 16 | struct dma_async_tx_descriptor tx; |
|---|
| 17 | + struct dmaengine_result tx_result; |
|---|
| 20 | 18 | /* protected by vc.lock */ |
|---|
| 21 | 19 | struct list_head node; |
|---|
| 22 | 20 | }; |
|---|
| .. | .. |
|---|
| 33 | 31 | struct list_head desc_submitted; |
|---|
| 34 | 32 | struct list_head desc_issued; |
|---|
| 35 | 33 | struct list_head desc_completed; |
|---|
| 34 | + struct list_head desc_terminated; |
|---|
| 36 | 35 | |
|---|
| 37 | 36 | struct virt_dma_desc *cyclic; |
|---|
| 38 | | - struct virt_dma_desc *vd_terminated; |
|---|
| 39 | 37 | }; |
|---|
| 40 | 38 | |
|---|
| 41 | 39 | static inline struct virt_dma_chan *to_virt_chan(struct dma_chan *chan) |
|---|
| .. | .. |
|---|
| 64 | 62 | vd->tx.flags = tx_flags; |
|---|
| 65 | 63 | vd->tx.tx_submit = vchan_tx_submit; |
|---|
| 66 | 64 | vd->tx.desc_free = vchan_tx_desc_free; |
|---|
| 65 | + |
|---|
| 66 | + vd->tx_result.result = DMA_TRANS_NOERROR; |
|---|
| 67 | + vd->tx_result.residue = 0; |
|---|
| 67 | 68 | |
|---|
| 68 | 69 | spin_lock_irqsave(&vc->lock, flags); |
|---|
| 69 | 70 | list_add_tail(&vd->node, &vc->desc_allocated); |
|---|
| .. | .. |
|---|
| 112 | 113 | { |
|---|
| 113 | 114 | struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan); |
|---|
| 114 | 115 | |
|---|
| 115 | | - if (dmaengine_desc_test_reuse(&vd->tx)) |
|---|
| 116 | + if (dmaengine_desc_test_reuse(&vd->tx)) { |
|---|
| 117 | + unsigned long flags; |
|---|
| 118 | + |
|---|
| 119 | + spin_lock_irqsave(&vc->lock, flags); |
|---|
| 116 | 120 | list_add(&vd->node, &vc->desc_allocated); |
|---|
| 117 | | - else |
|---|
| 121 | + spin_unlock_irqrestore(&vc->lock, flags); |
|---|
| 122 | + } else { |
|---|
| 118 | 123 | vc->desc_free(vd); |
|---|
| 124 | + } |
|---|
| 119 | 125 | } |
|---|
| 120 | 126 | |
|---|
| 121 | 127 | /** |
|---|
| .. | .. |
|---|
| 140 | 146 | { |
|---|
| 141 | 147 | struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan); |
|---|
| 142 | 148 | |
|---|
| 143 | | - /* free up stuck descriptor */ |
|---|
| 144 | | - if (vc->vd_terminated) |
|---|
| 145 | | - vchan_vdesc_fini(vc->vd_terminated); |
|---|
| 149 | + list_add_tail(&vd->node, &vc->desc_terminated); |
|---|
| 146 | 150 | |
|---|
| 147 | | - vc->vd_terminated = vd; |
|---|
| 148 | 151 | if (vc->cyclic == vd) |
|---|
| 149 | 152 | vc->cyclic = NULL; |
|---|
| 150 | 153 | } |
|---|
| .. | .. |
|---|
| 178 | 181 | list_splice_tail_init(&vc->desc_submitted, head); |
|---|
| 179 | 182 | list_splice_tail_init(&vc->desc_issued, head); |
|---|
| 180 | 183 | list_splice_tail_init(&vc->desc_completed, head); |
|---|
| 184 | + list_splice_tail_init(&vc->desc_terminated, head); |
|---|
| 181 | 185 | } |
|---|
| 182 | 186 | |
|---|
| 183 | 187 | static inline void vchan_free_chan_resources(struct virt_dma_chan *vc) |
|---|
| .. | .. |
|---|
| 206 | 210 | */ |
|---|
| 207 | 211 | static inline void vchan_synchronize(struct virt_dma_chan *vc) |
|---|
| 208 | 212 | { |
|---|
| 213 | + LIST_HEAD(head); |
|---|
| 209 | 214 | unsigned long flags; |
|---|
| 210 | 215 | |
|---|
| 211 | 216 | tasklet_kill(&vc->task); |
|---|
| 212 | 217 | |
|---|
| 213 | 218 | spin_lock_irqsave(&vc->lock, flags); |
|---|
| 214 | | - if (vc->vd_terminated) { |
|---|
| 215 | | - vchan_vdesc_fini(vc->vd_terminated); |
|---|
| 216 | | - vc->vd_terminated = NULL; |
|---|
| 217 | | - } |
|---|
| 219 | + |
|---|
| 220 | + list_splice_tail_init(&vc->desc_terminated, &head); |
|---|
| 221 | + |
|---|
| 218 | 222 | spin_unlock_irqrestore(&vc->lock, flags); |
|---|
| 223 | + |
|---|
| 224 | + vchan_dma_desc_free_list(vc, &head); |
|---|
| 219 | 225 | } |
|---|
| 220 | 226 | |
|---|
| 221 | 227 | #endif |
|---|