Skip to content

Commit f7fbce0

Browse files
Russell King - ARM LinuxVinod Koul
authored andcommitted
dmaengine: provide a common function for completing a dma descriptor
Provide a common function to do the cookie mechanics for completing a DMA descriptor. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> Tested-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Jassi Brar <jassisinghbrar@gmail.com> [imx-sdma.c & mxs-dma.c] Tested-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
1 parent 884485e commit f7fbce0

19 files changed

Lines changed: 36 additions & 21 deletions

‎drivers/dma/amba-pl08x.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ static void pl08x_tasklet(unsigned long data)
15421542

15431543
if (txd) {
15441544
/* Update last completed */
1545-
plchan->chan.completed_cookie = txd->tx.cookie;
1545+
dma_cookie_complete(&txd->tx);
15461546
}
15471547

15481548
/* If a new descriptor is queued, set it up plchan->at is NULL here */

‎drivers/dma/at_hdmac.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc)
249249
dev_vdbg(chan2dev(&atchan->chan_common),
250250
"descriptor %u complete\n", txd->cookie);
251251

252-
atchan->chan_common.completed_cookie = txd->cookie;
252+
dma_cookie_complete(txd);
253253

254254
/* move children to free_list */
255255
list_splice_init(&desc->tx_list, &atchan->free_list);

‎drivers/dma/coh901318.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static void dma_tasklet(unsigned long data)
691691
callback_param = cohd_fin->desc.callback_param;
692692

693693
/* sign this job as completed on the channel */
694-
cohc->chan.completed_cookie = cohd_fin->desc.cookie;
694+
dma_cookie_complete(&cohd_fin->desc);
695695

696696
/* release the lli allocation and remove the descriptor */
697697
coh901318_lli_free(&cohc->base->pool, &cohd_fin->lli);

‎drivers/dma/dmaengine.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef DMAENGINE_H
66
#define DMAENGINE_H
77

8+
#include <linux/bug.h>
89
#include <linux/dmaengine.h>
910

1011
/**
@@ -27,4 +28,21 @@ static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx)
2728
return cookie;
2829
}
2930

31+
/**
32+
* dma_cookie_complete - complete a descriptor
33+
* @tx: descriptor to complete
34+
*
35+
* Mark this descriptor complete by updating the channels completed
36+
* cookie marker. Zero the descriptors cookie to prevent accidental
37+
* repeated completions.
38+
*
39+
* Note: caller is expected to hold a lock to prevent concurrency.
40+
*/
41+
static inline void dma_cookie_complete(struct dma_async_tx_descriptor *tx)
42+
{
43+
BUG_ON(tx->cookie < DMA_MIN_COOKIE);
44+
tx->chan->completed_cookie = tx->cookie;
45+
tx->cookie = 0;
46+
}
47+
3048
#endif

‎drivers/dma/dw_dmac.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc,
235235
dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie);
236236

237237
spin_lock_irqsave(&dwc->lock, flags);
238-
dwc->chan.completed_cookie = txd->cookie;
238+
dma_cookie_complete(txd);
239239
if (callback_required) {
240240
callback = txd->callback;
241241
param = txd->callback_param;

‎drivers/dma/ep93xx_dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static void ep93xx_dma_tasklet(unsigned long data)
703703
desc = ep93xx_dma_get_active(edmac);
704704
if (desc) {
705705
if (desc->complete) {
706-
edmac->chan.completed_cookie = desc->txd.cookie;
706+
dma_cookie_complete(&desc->txd);
707707
list_splice_init(&edmac->active, &list);
708708
}
709709
callback = desc->txd.callback;

‎drivers/dma/fsldma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,8 @@ static void dma_do_tasklet(unsigned long data)
10811081

10821082
desc = to_fsl_desc(chan->ld_running.prev);
10831083
cookie = desc->async_tx.cookie;
1084+
dma_cookie_complete(&desc->async_tx);
10841085

1085-
chan->common.completed_cookie = cookie;
10861086
chan_dbg(chan, "completed_cookie=%d\n", cookie);
10871087
}
10881088

‎drivers/dma/imx-dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void imxdma_handle(struct imxdma_channel *imxdmac)
6666
{
6767
if (imxdmac->desc.callback)
6868
imxdmac->desc.callback(imxdmac->desc.callback_param);
69-
imxdmac->chan.completed_cookie = imxdmac->desc.cookie;
69+
dma_cookie_complete(&imxdmac->desc);
7070
}
7171

7272
static void imxdma_irq_handler(int channel, void *data)

‎drivers/dma/imx-sdma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)
530530
else
531531
sdmac->status = DMA_SUCCESS;
532532

533-
sdmac->chan.completed_cookie = sdmac->desc.cookie;
533+
dma_cookie_complete(&sdmac->desc);
534534
if (sdmac->desc.callback)
535535
sdmac->desc.callback(sdmac->desc.callback_param);
536536
}

‎drivers/dma/intel_mid_dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static void midc_descriptor_complete(struct intel_mid_dma_chan *midc,
290290
struct intel_mid_dma_lli *llitem;
291291
void *param_txd = NULL;
292292

293-
midc->chan.completed_cookie = txd->cookie;
293+
dma_cookie_complete(txd);
294294
callback_txd = txd->callback;
295295
param_txd = txd->callback_param;
296296

0 commit comments

Comments
 (0)