Commit f7fbce07 authored by Russell King - ARM Linux's avatar Russell King - ARM Linux Committed by Vinod Koul

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: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
Tested-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarJassi Brar <jassisinghbrar@gmail.com>
[imx-sdma.c & mxs-dma.c]
Tested-by: default avatarShawn Guo <shawn.guo@linaro.org>
Signed-off-by: default avatarVinod Koul <vinod.koul@linux.intel.com>
parent 884485e1
...@@ -1542,7 +1542,7 @@ static void pl08x_tasklet(unsigned long data) ...@@ -1542,7 +1542,7 @@ static void pl08x_tasklet(unsigned long data)
if (txd) { if (txd) {
/* Update last completed */ /* Update last completed */
plchan->chan.completed_cookie = txd->tx.cookie; dma_cookie_complete(&txd->tx);
} }
/* If a new descriptor is queued, set it up plchan->at is NULL here */ /* If a new descriptor is queued, set it up plchan->at is NULL here */
......
...@@ -249,7 +249,7 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc) ...@@ -249,7 +249,7 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc)
dev_vdbg(chan2dev(&atchan->chan_common), dev_vdbg(chan2dev(&atchan->chan_common),
"descriptor %u complete\n", txd->cookie); "descriptor %u complete\n", txd->cookie);
atchan->chan_common.completed_cookie = txd->cookie; dma_cookie_complete(txd);
/* move children to free_list */ /* move children to free_list */
list_splice_init(&desc->tx_list, &atchan->free_list); list_splice_init(&desc->tx_list, &atchan->free_list);
......
...@@ -691,7 +691,7 @@ static void dma_tasklet(unsigned long data) ...@@ -691,7 +691,7 @@ static void dma_tasklet(unsigned long data)
callback_param = cohd_fin->desc.callback_param; callback_param = cohd_fin->desc.callback_param;
/* sign this job as completed on the channel */ /* sign this job as completed on the channel */
cohc->chan.completed_cookie = cohd_fin->desc.cookie; dma_cookie_complete(&cohd_fin->desc);
/* release the lli allocation and remove the descriptor */ /* release the lli allocation and remove the descriptor */
coh901318_lli_free(&cohc->base->pool, &cohd_fin->lli); coh901318_lli_free(&cohc->base->pool, &cohd_fin->lli);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef DMAENGINE_H #ifndef DMAENGINE_H
#define DMAENGINE_H #define DMAENGINE_H
#include <linux/bug.h>
#include <linux/dmaengine.h> #include <linux/dmaengine.h>
/** /**
...@@ -27,4 +28,21 @@ static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx) ...@@ -27,4 +28,21 @@ static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx)
return cookie; return cookie;
} }
/**
* dma_cookie_complete - complete a descriptor
* @tx: descriptor to complete
*
* Mark this descriptor complete by updating the channels completed
* cookie marker. Zero the descriptors cookie to prevent accidental
* repeated completions.
*
* Note: caller is expected to hold a lock to prevent concurrency.
*/
static inline void dma_cookie_complete(struct dma_async_tx_descriptor *tx)
{
BUG_ON(tx->cookie < DMA_MIN_COOKIE);
tx->chan->completed_cookie = tx->cookie;
tx->cookie = 0;
}
#endif #endif
...@@ -235,7 +235,7 @@ dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc, ...@@ -235,7 +235,7 @@ dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc,
dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie); dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie);
spin_lock_irqsave(&dwc->lock, flags); spin_lock_irqsave(&dwc->lock, flags);
dwc->chan.completed_cookie = txd->cookie; dma_cookie_complete(txd);
if (callback_required) { if (callback_required) {
callback = txd->callback; callback = txd->callback;
param = txd->callback_param; param = txd->callback_param;
......
...@@ -703,7 +703,7 @@ static void ep93xx_dma_tasklet(unsigned long data) ...@@ -703,7 +703,7 @@ static void ep93xx_dma_tasklet(unsigned long data)
desc = ep93xx_dma_get_active(edmac); desc = ep93xx_dma_get_active(edmac);
if (desc) { if (desc) {
if (desc->complete) { if (desc->complete) {
edmac->chan.completed_cookie = desc->txd.cookie; dma_cookie_complete(&desc->txd);
list_splice_init(&edmac->active, &list); list_splice_init(&edmac->active, &list);
} }
callback = desc->txd.callback; callback = desc->txd.callback;
......
...@@ -1081,8 +1081,8 @@ static void dma_do_tasklet(unsigned long data) ...@@ -1081,8 +1081,8 @@ static void dma_do_tasklet(unsigned long data)
desc = to_fsl_desc(chan->ld_running.prev); desc = to_fsl_desc(chan->ld_running.prev);
cookie = desc->async_tx.cookie; cookie = desc->async_tx.cookie;
dma_cookie_complete(&desc->async_tx);
chan->common.completed_cookie = cookie;
chan_dbg(chan, "completed_cookie=%d\n", cookie); chan_dbg(chan, "completed_cookie=%d\n", cookie);
} }
......
...@@ -66,7 +66,7 @@ static void imxdma_handle(struct imxdma_channel *imxdmac) ...@@ -66,7 +66,7 @@ static void imxdma_handle(struct imxdma_channel *imxdmac)
{ {
if (imxdmac->desc.callback) if (imxdmac->desc.callback)
imxdmac->desc.callback(imxdmac->desc.callback_param); imxdmac->desc.callback(imxdmac->desc.callback_param);
imxdmac->chan.completed_cookie = imxdmac->desc.cookie; dma_cookie_complete(&imxdmac->desc);
} }
static void imxdma_irq_handler(int channel, void *data) static void imxdma_irq_handler(int channel, void *data)
......
...@@ -530,7 +530,7 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac) ...@@ -530,7 +530,7 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)
else else
sdmac->status = DMA_SUCCESS; sdmac->status = DMA_SUCCESS;
sdmac->chan.completed_cookie = sdmac->desc.cookie; dma_cookie_complete(&sdmac->desc);
if (sdmac->desc.callback) if (sdmac->desc.callback)
sdmac->desc.callback(sdmac->desc.callback_param); sdmac->desc.callback(sdmac->desc.callback_param);
} }
......
...@@ -290,7 +290,7 @@ static void midc_descriptor_complete(struct intel_mid_dma_chan *midc, ...@@ -290,7 +290,7 @@ static void midc_descriptor_complete(struct intel_mid_dma_chan *midc,
struct intel_mid_dma_lli *llitem; struct intel_mid_dma_lli *llitem;
void *param_txd = NULL; void *param_txd = NULL;
midc->chan.completed_cookie = txd->cookie; dma_cookie_complete(txd);
callback_txd = txd->callback; callback_txd = txd->callback;
param_txd = txd->callback_param; param_txd = txd->callback_param;
......
...@@ -600,8 +600,7 @@ static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete) ...@@ -600,8 +600,7 @@ static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete)
*/ */
dump_desc_dbg(ioat, desc); dump_desc_dbg(ioat, desc);
if (tx->cookie) { if (tx->cookie) {
chan->common.completed_cookie = tx->cookie; dma_cookie_complete(tx);
tx->cookie = 0;
ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw); ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
ioat->active -= desc->hw->tx_cnt; ioat->active -= desc->hw->tx_cnt;
if (tx->callback) { if (tx->callback) {
......
...@@ -149,8 +149,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete) ...@@ -149,8 +149,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
dump_desc_dbg(ioat, desc); dump_desc_dbg(ioat, desc);
if (tx->cookie) { if (tx->cookie) {
ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw); ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
chan->common.completed_cookie = tx->cookie; dma_cookie_complete(tx);
tx->cookie = 0;
if (tx->callback) { if (tx->callback) {
tx->callback(tx->callback_param); tx->callback(tx->callback_param);
tx->callback = NULL; tx->callback = NULL;
......
...@@ -277,9 +277,8 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete) ...@@ -277,9 +277,8 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
dump_desc_dbg(ioat, desc); dump_desc_dbg(ioat, desc);
tx = &desc->txd; tx = &desc->txd;
if (tx->cookie) { if (tx->cookie) {
chan->common.completed_cookie = tx->cookie; dma_cookie_complete(tx);
ioat3_dma_unmap(ioat, desc, idx + i); ioat3_dma_unmap(ioat, desc, idx + i);
tx->cookie = 0;
if (tx->callback) { if (tx->callback) {
tx->callback(tx->callback_param); tx->callback(tx->callback_param);
tx->callback = NULL; tx->callback = NULL;
......
...@@ -1289,7 +1289,7 @@ static irqreturn_t idmac_interrupt(int irq, void *dev_id) ...@@ -1289,7 +1289,7 @@ static irqreturn_t idmac_interrupt(int irq, void *dev_id)
/* Flip the active buffer - even if update above failed */ /* Flip the active buffer - even if update above failed */
ichan->active_buffer = !ichan->active_buffer; ichan->active_buffer = !ichan->active_buffer;
if (done) if (done)
ichan->dma_chan.completed_cookie = desc->txd.cookie; dma_cookie_complete(&desc->txd);
callback = desc->txd.callback; callback = desc->txd.callback;
callback_param = desc->txd.callback_param; callback_param = desc->txd.callback_param;
......
...@@ -262,7 +262,7 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id) ...@@ -262,7 +262,7 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
stat1 &= ~(1 << channel); stat1 &= ~(1 << channel);
if (mxs_chan->status == DMA_SUCCESS) if (mxs_chan->status == DMA_SUCCESS)
mxs_chan->chan.completed_cookie = mxs_chan->desc.cookie; dma_cookie_complete(&mxs_chan->desc);
/* schedule tasklet on this channel */ /* schedule tasklet on this channel */
tasklet_schedule(&mxs_chan->tasklet); tasklet_schedule(&mxs_chan->tasklet);
......
...@@ -233,7 +233,7 @@ static void pl330_tasklet(unsigned long data) ...@@ -233,7 +233,7 @@ static void pl330_tasklet(unsigned long data)
/* Pick up ripe tomatoes */ /* Pick up ripe tomatoes */
list_for_each_entry_safe(desc, _dt, &pch->work_list, node) list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
if (desc->status == DONE) { if (desc->status == DONE) {
pch->chan.completed_cookie = desc->txd.cookie; dma_cookie_complete(&desc->txd);
list_move_tail(&desc->node, &list); list_move_tail(&desc->node, &list);
} }
......
...@@ -1347,7 +1347,7 @@ static void dma_tasklet(unsigned long data) ...@@ -1347,7 +1347,7 @@ static void dma_tasklet(unsigned long data)
goto err; goto err;
if (!d40d->cyclic) if (!d40d->cyclic)
d40c->chan.completed_cookie = d40d->txd.cookie; dma_cookie_complete(&d40d->txd);
/* /*
* If terminating a channel pending_tx is set to zero. * If terminating a channel pending_tx is set to zero.
......
...@@ -285,7 +285,7 @@ static void __td_finish(struct timb_dma_chan *td_chan) ...@@ -285,7 +285,7 @@ static void __td_finish(struct timb_dma_chan *td_chan)
else else
iowrite32(0, td_chan->membase + TIMBDMA_OFFS_TX_DLAR); iowrite32(0, td_chan->membase + TIMBDMA_OFFS_TX_DLAR);
*/ */
td_chan->chan.completed_cookie = txd->cookie; dma_cookie_complete(txd);
td_chan->ongoing = false; td_chan->ongoing = false;
callback = txd->callback; callback = txd->callback;
......
...@@ -411,7 +411,7 @@ txx9dmac_descriptor_complete(struct txx9dmac_chan *dc, ...@@ -411,7 +411,7 @@ txx9dmac_descriptor_complete(struct txx9dmac_chan *dc,
dev_vdbg(chan2dev(&dc->chan), "descriptor %u %p complete\n", dev_vdbg(chan2dev(&dc->chan), "descriptor %u %p complete\n",
txd->cookie, desc); txd->cookie, desc);
dc->chan.completed_cookie = txd->cookie; dma_cookie_complete(txd);
callback = txd->callback; callback = txd->callback;
param = txd->callback_param; param = txd->callback_param;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment