Skip to content

Commit e067485

Browse files
1991Joyzouvinodkoul
authored andcommitted
dmaengine: fsl-edma: support edma memcpy
Add memcpy in edma. The edma has the capability to transfer data by software trigger so that it could be used for memory copy. Enable MEMCPY for edma driver and it could be test directly by dmatest. Signed-off-by: Joy Zou <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent a3e340c commit e067485

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

drivers/dma/fsl-edma-common.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ static void fsl_edma_set_tcd_regs(struct fsl_edma_chan *fsl_chan,
348348
struct fsl_edma_engine *edma = fsl_chan->edma;
349349
struct edma_regs *regs = &fsl_chan->edma->regs;
350350
u32 ch = fsl_chan->vchan.chan.chan_id;
351+
u16 csr = 0;
351352

352353
/*
353354
* TCD parameters are stored in struct fsl_edma_hw_tcd in little
@@ -373,6 +374,12 @@ static void fsl_edma_set_tcd_regs(struct fsl_edma_chan *fsl_chan,
373374
edma_writel(edma, (s32)tcd->dlast_sga,
374375
&regs->tcd[ch].dlast_sga);
375376

377+
if (fsl_chan->is_sw) {
378+
csr = le16_to_cpu(tcd->csr);
379+
csr |= EDMA_TCD_CSR_START;
380+
tcd->csr = cpu_to_le16(csr);
381+
}
382+
376383
edma_writew(edma, (s16)tcd->csr, &regs->tcd[ch].csr);
377384
}
378385

@@ -587,6 +594,29 @@ struct dma_async_tx_descriptor *fsl_edma_prep_slave_sg(
587594
}
588595
EXPORT_SYMBOL_GPL(fsl_edma_prep_slave_sg);
589596

597+
struct dma_async_tx_descriptor *fsl_edma_prep_memcpy(struct dma_chan *chan,
598+
dma_addr_t dma_dst, dma_addr_t dma_src,
599+
size_t len, unsigned long flags)
600+
{
601+
struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan);
602+
struct fsl_edma_desc *fsl_desc;
603+
604+
fsl_desc = fsl_edma_alloc_desc(fsl_chan, 1);
605+
if (!fsl_desc)
606+
return NULL;
607+
fsl_desc->iscyclic = false;
608+
609+
fsl_chan->is_sw = true;
610+
611+
/* To match with copy_align and max_seg_size so 1 tcd is enough */
612+
fsl_edma_fill_tcd(fsl_desc->tcd[0].vtcd, dma_src, dma_dst,
613+
EDMA_TCD_ATTR_SSIZE_32BYTE | EDMA_TCD_ATTR_DSIZE_32BYTE,
614+
32, len, 0, 1, 1, 32, 0, true, true, false);
615+
616+
return vchan_tx_prep(&fsl_chan->vchan, &fsl_desc->vdesc, flags);
617+
}
618+
EXPORT_SYMBOL_GPL(fsl_edma_prep_memcpy);
619+
590620
void fsl_edma_xfer_desc(struct fsl_edma_chan *fsl_chan)
591621
{
592622
struct virt_dma_desc *vdesc;
@@ -654,6 +684,7 @@ void fsl_edma_free_chan_resources(struct dma_chan *chan)
654684
vchan_dma_desc_free_list(&fsl_chan->vchan, &head);
655685
dma_pool_destroy(fsl_chan->tcd_pool);
656686
fsl_chan->tcd_pool = NULL;
687+
fsl_chan->is_sw = false;
657688
}
658689
EXPORT_SYMBOL_GPL(fsl_edma_free_chan_resources);
659690

drivers/dma/fsl-edma-common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct fsl_edma_chan {
121121
struct fsl_edma_desc *edesc;
122122
struct dma_slave_config cfg;
123123
u32 attr;
124+
bool is_sw;
124125
struct dma_pool *tcd_pool;
125126
dma_addr_t dma_dev_addr;
126127
u32 dma_dev_size;
@@ -240,6 +241,9 @@ struct dma_async_tx_descriptor *fsl_edma_prep_slave_sg(
240241
struct dma_chan *chan, struct scatterlist *sgl,
241242
unsigned int sg_len, enum dma_transfer_direction direction,
242243
unsigned long flags, void *context);
244+
struct dma_async_tx_descriptor *fsl_edma_prep_memcpy(
245+
struct dma_chan *chan, dma_addr_t dma_dst, dma_addr_t dma_src,
246+
size_t len, unsigned long flags);
243247
void fsl_edma_xfer_desc(struct fsl_edma_chan *fsl_chan);
244248
void fsl_edma_issue_pending(struct dma_chan *chan);
245249
int fsl_edma_alloc_chan_resources(struct dma_chan *chan);

drivers/dma/fsl-edma.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/of_address.h>
1818
#include <linux/of_irq.h>
1919
#include <linux/of_dma.h>
20+
#include <linux/dma-mapping.h>
2021

2122
#include "fsl-edma-common.h"
2223

@@ -372,6 +373,7 @@ static int fsl_edma_probe(struct platform_device *pdev)
372373
dma_cap_set(DMA_PRIVATE, fsl_edma->dma_dev.cap_mask);
373374
dma_cap_set(DMA_SLAVE, fsl_edma->dma_dev.cap_mask);
374375
dma_cap_set(DMA_CYCLIC, fsl_edma->dma_dev.cap_mask);
376+
dma_cap_set(DMA_MEMCPY, fsl_edma->dma_dev.cap_mask);
375377

376378
fsl_edma->dma_dev.dev = &pdev->dev;
377379
fsl_edma->dma_dev.device_alloc_chan_resources
@@ -381,6 +383,7 @@ static int fsl_edma_probe(struct platform_device *pdev)
381383
fsl_edma->dma_dev.device_tx_status = fsl_edma_tx_status;
382384
fsl_edma->dma_dev.device_prep_slave_sg = fsl_edma_prep_slave_sg;
383385
fsl_edma->dma_dev.device_prep_dma_cyclic = fsl_edma_prep_dma_cyclic;
386+
fsl_edma->dma_dev.device_prep_dma_memcpy = fsl_edma_prep_memcpy;
384387
fsl_edma->dma_dev.device_config = fsl_edma_slave_config;
385388
fsl_edma->dma_dev.device_pause = fsl_edma_pause;
386389
fsl_edma->dma_dev.device_resume = fsl_edma_resume;
@@ -392,6 +395,10 @@ static int fsl_edma_probe(struct platform_device *pdev)
392395
fsl_edma->dma_dev.dst_addr_widths = FSL_EDMA_BUSWIDTHS;
393396
fsl_edma->dma_dev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
394397

398+
fsl_edma->dma_dev.copy_align = DMAENGINE_ALIGN_32_BYTES;
399+
/* Per worst case 'nbytes = 1' take CITER as the max_seg_size */
400+
dma_set_max_seg_size(fsl_edma->dma_dev.dev, 0x3fff);
401+
395402
platform_set_drvdata(pdev, fsl_edma);
396403

397404
ret = dma_async_device_register(&fsl_edma->dma_dev);

0 commit comments

Comments
 (0)