Skip to content

Commit 884485e

Browse files
Russell King - ARM LinuxVinod Koul
authored andcommitted
dmaengine: consolidate assignment of DMA cookies
Everyone deals with assigning DMA cookies in the same way (it's part of the API so they should be), so lets consolidate the common code into a helper function to avoid this duplication. 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 d2ebfb3 commit 884485e

25 files changed

Lines changed: 52 additions & 272 deletions

‎drivers/dma/amba-pl08x.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,13 +921,10 @@ static dma_cookie_t pl08x_tx_submit(struct dma_async_tx_descriptor *tx)
921921
struct pl08x_dma_chan *plchan = to_pl08x_chan(tx->chan);
922922
struct pl08x_txd *txd = to_pl08x_txd(tx);
923923
unsigned long flags;
924+
dma_cookie_t cookie;
924925

925926
spin_lock_irqsave(&plchan->lock, flags);
926-
927-
plchan->chan.cookie += 1;
928-
if (plchan->chan.cookie < 0)
929-
plchan->chan.cookie = 1;
930-
tx->cookie = plchan->chan.cookie;
927+
cookie = dma_cookie_assign(tx);
931928

932929
/* Put this onto the pending list */
933930
list_add_tail(&txd->node, &plchan->pend_list);
@@ -947,7 +944,7 @@ static dma_cookie_t pl08x_tx_submit(struct dma_async_tx_descriptor *tx)
947944

948945
spin_unlock_irqrestore(&plchan->lock, flags);
949946

950-
return tx->cookie;
947+
return cookie;
951948
}
952949

953950
static struct dma_async_tx_descriptor *pl08x_prep_dma_interrupt(

‎drivers/dma/at_hdmac.c‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,27 +192,6 @@ static void atc_desc_chain(struct at_desc **first, struct at_desc **prev,
192192
*prev = desc;
193193
}
194194

195-
/**
196-
* atc_assign_cookie - compute and assign new cookie
197-
* @atchan: channel we work on
198-
* @desc: descriptor to assign cookie for
199-
*
200-
* Called with atchan->lock held and bh disabled
201-
*/
202-
static dma_cookie_t
203-
atc_assign_cookie(struct at_dma_chan *atchan, struct at_desc *desc)
204-
{
205-
dma_cookie_t cookie = atchan->chan_common.cookie;
206-
207-
if (++cookie < 0)
208-
cookie = 1;
209-
210-
atchan->chan_common.cookie = cookie;
211-
desc->txd.cookie = cookie;
212-
213-
return cookie;
214-
}
215-
216195
/**
217196
* atc_dostart - starts the DMA engine for real
218197
* @atchan: the channel we want to start
@@ -548,7 +527,7 @@ static dma_cookie_t atc_tx_submit(struct dma_async_tx_descriptor *tx)
548527
unsigned long flags;
549528

550529
spin_lock_irqsave(&atchan->lock, flags);
551-
cookie = atc_assign_cookie(atchan, desc);
530+
cookie = dma_cookie_assign(tx);
552531

553532
if (list_empty(&atchan->active_list)) {
554533
dev_vdbg(chan2dev(tx->chan), "tx_submit: started %u\n",

‎drivers/dma/coh901318.c‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -318,20 +318,6 @@ static int coh901318_prep_linked_list(struct coh901318_chan *cohc,
318318

319319
return 0;
320320
}
321-
static dma_cookie_t
322-
coh901318_assign_cookie(struct coh901318_chan *cohc,
323-
struct coh901318_desc *cohd)
324-
{
325-
dma_cookie_t cookie = cohc->chan.cookie;
326-
327-
if (++cookie < 0)
328-
cookie = 1;
329-
330-
cohc->chan.cookie = cookie;
331-
cohd->desc.cookie = cookie;
332-
333-
return cookie;
334-
}
335321

336322
static struct coh901318_desc *
337323
coh901318_desc_get(struct coh901318_chan *cohc)
@@ -966,16 +952,16 @@ coh901318_tx_submit(struct dma_async_tx_descriptor *tx)
966952
desc);
967953
struct coh901318_chan *cohc = to_coh901318_chan(tx->chan);
968954
unsigned long flags;
955+
dma_cookie_t cookie;
969956

970957
spin_lock_irqsave(&cohc->lock, flags);
971-
972-
tx->cookie = coh901318_assign_cookie(cohc, cohd);
958+
cookie = dma_cookie_assign(tx);
973959

974960
coh901318_desc_queue(cohc, cohd);
975961

976962
spin_unlock_irqrestore(&cohc->lock, flags);
977963

978-
return tx->cookie;
964+
return cookie;
979965
}
980966

981967
static struct dma_async_tx_descriptor *

‎drivers/dma/dmaengine.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,24 @@
77

88
#include <linux/dmaengine.h>
99

10+
/**
11+
* dma_cookie_assign - assign a DMA engine cookie to the descriptor
12+
* @tx: descriptor needing cookie
13+
*
14+
* Assign a unique non-zero per-channel cookie to the descriptor.
15+
* Note: caller is expected to hold a lock to prevent concurrency.
16+
*/
17+
static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx)
18+
{
19+
struct dma_chan *chan = tx->chan;
20+
dma_cookie_t cookie;
21+
22+
cookie = chan->cookie + 1;
23+
if (cookie < DMA_MIN_COOKIE)
24+
cookie = DMA_MIN_COOKIE;
25+
tx->cookie = chan->cookie = cookie;
26+
27+
return cookie;
28+
}
29+
1030
#endif

‎drivers/dma/dw_dmac.c‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,6 @@ static void dwc_desc_put(struct dw_dma_chan *dwc, struct dw_desc *desc)
157157
}
158158
}
159159

160-
/* Called with dwc->lock held and bh disabled */
161-
static dma_cookie_t
162-
dwc_assign_cookie(struct dw_dma_chan *dwc, struct dw_desc *desc)
163-
{
164-
dma_cookie_t cookie = dwc->chan.cookie;
165-
166-
if (++cookie < 0)
167-
cookie = 1;
168-
169-
dwc->chan.cookie = cookie;
170-
desc->txd.cookie = cookie;
171-
172-
return cookie;
173-
}
174-
175160
static void dwc_initialize(struct dw_dma_chan *dwc)
176161
{
177162
struct dw_dma *dw = to_dw_dma(dwc->chan.device);
@@ -603,7 +588,7 @@ static dma_cookie_t dwc_tx_submit(struct dma_async_tx_descriptor *tx)
603588
unsigned long flags;
604589

605590
spin_lock_irqsave(&dwc->lock, flags);
606-
cookie = dwc_assign_cookie(dwc, desc);
591+
cookie = dma_cookie_assign(tx);
607592

608593
/*
609594
* REVISIT: We should attempt to chain as many descriptors as

‎drivers/dma/ep93xx_dma.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -783,17 +783,10 @@ static dma_cookie_t ep93xx_dma_tx_submit(struct dma_async_tx_descriptor *tx)
783783
unsigned long flags;
784784

785785
spin_lock_irqsave(&edmac->lock, flags);
786-
787-
cookie = edmac->chan.cookie;
788-
789-
if (++cookie < 0)
790-
cookie = 1;
786+
cookie = dma_cookie_assign(tx);
791787

792788
desc = container_of(tx, struct ep93xx_dma_desc, txd);
793789

794-
edmac->chan.cookie = cookie;
795-
desc->txd.cookie = cookie;
796-
797790
/*
798791
* If nothing is currently prosessed, we push this descriptor
799792
* directly to the hardware. Otherwise we put the descriptor

‎drivers/dma/fsldma.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,10 @@ static dma_cookie_t fsl_dma_tx_submit(struct dma_async_tx_descriptor *tx)
414414
* assign cookies to all of the software descriptors
415415
* that make up this transaction
416416
*/
417-
cookie = chan->common.cookie;
418417
list_for_each_entry(child, &desc->tx_list, node) {
419-
cookie++;
420-
if (cookie < DMA_MIN_COOKIE)
421-
cookie = DMA_MIN_COOKIE;
422-
423-
child->async_tx.cookie = cookie;
418+
cookie = dma_cookie_assign(&child->async_tx);
424419
}
425420

426-
chan->common.cookie = cookie;
427-
428421
/* put this transaction onto the tail of the pending queue */
429422
append_ld_queue(chan, desc);
430423

‎drivers/dma/imx-dma.c‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,14 @@ static enum dma_status imxdma_tx_status(struct dma_chan *chan,
165165
return ret;
166166
}
167167

168-
static dma_cookie_t imxdma_assign_cookie(struct imxdma_channel *imxdma)
169-
{
170-
dma_cookie_t cookie = imxdma->chan.cookie;
171-
172-
if (++cookie < 0)
173-
cookie = 1;
174-
175-
imxdma->chan.cookie = cookie;
176-
imxdma->desc.cookie = cookie;
177-
178-
return cookie;
179-
}
180-
181168
static dma_cookie_t imxdma_tx_submit(struct dma_async_tx_descriptor *tx)
182169
{
183170
struct imxdma_channel *imxdmac = to_imxdma_chan(tx->chan);
184171
dma_cookie_t cookie;
185172

186173
spin_lock_irq(&imxdmac->lock);
187174

188-
cookie = imxdma_assign_cookie(imxdmac);
175+
cookie = dma_cookie_assign(tx);
189176

190177
spin_unlock_irq(&imxdmac->lock);
191178

‎drivers/dma/imx-sdma.c‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -815,19 +815,6 @@ static int sdma_request_channel(struct sdma_channel *sdmac)
815815
return ret;
816816
}
817817

818-
static dma_cookie_t sdma_assign_cookie(struct sdma_channel *sdmac)
819-
{
820-
dma_cookie_t cookie = sdmac->chan.cookie;
821-
822-
if (++cookie < 0)
823-
cookie = 1;
824-
825-
sdmac->chan.cookie = cookie;
826-
sdmac->desc.cookie = cookie;
827-
828-
return cookie;
829-
}
830-
831818
static struct sdma_channel *to_sdma_chan(struct dma_chan *chan)
832819
{
833820
return container_of(chan, struct sdma_channel, chan);
@@ -841,7 +828,7 @@ static dma_cookie_t sdma_tx_submit(struct dma_async_tx_descriptor *tx)
841828

842829
spin_lock_irqsave(&sdmac->lock, flags);
843830

844-
cookie = sdma_assign_cookie(sdmac);
831+
cookie = dma_cookie_assign(tx);
845832

846833
spin_unlock_irqrestore(&sdmac->lock, flags);
847834

@@ -1140,7 +1127,6 @@ static void sdma_issue_pending(struct dma_chan *chan)
11401127
struct sdma_engine *sdma = sdmac->sdma;
11411128

11421129
if (sdmac->status == DMA_IN_PROGRESS)
1143-
sdma_enable_channel(sdma, sdmac->channel);
11441130
}
11451131

11461132
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1 34

‎drivers/dma/intel_mid_dma.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,7 @@ static dma_cookie_t intel_mid_dma_tx_submit(struct dma_async_tx_descriptor *tx)
436436
dma_cookie_t cookie;
437437

438438
spin_lock_bh(&midc->lock);
439-
cookie = midc->chan.cookie;
440-
441-
if (++cookie < 0)
442-
cookie = 1;
443-
444-
midc->chan.cookie = cookie;
445-
desc->txd.cookie = cookie;
446-
439+
cookie = dma_cookie_assign(tx);
447440

448441
if (list_empty(&midc->active_list))
449442
list_add_tail(&desc->desc_node, &midc->active_list);

0 commit comments

Comments
 (0)