Skip to content

Commit 7536f8b

Browse files
nxpfranklivinodkoul
authored andcommitted
dmaengine: fsl-edma: move tcd into struct fsl_dma_chan
Relocates the tcd into the fsl_dma_chan structure. This adjustment reduces the need to reference back to fsl_edma_engine, paving the way for EDMA V3 support. Unified the edma_writel and edma_writew functions for accessing TCD (Transfer Control Descriptor) registers. A new macro is added that can automatically detect whether a 32-bit or 16-bit access should be used based on the structure field definition. This provide better support 64-bit TCD with future v5 version. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202305271951.gmRobs3a-lkp@intel.com/ Signed-off-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20230821161617.2142561-11-Frank.Li@nxp.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 9b05554 commit 7536f8b

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

drivers/dma/fsl-edma-common.c

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
#define EDMA64_ERRH 0x28
4141
#define EDMA64_ERRL 0x2c
4242

43-
#define EDMA_TCD 0x1000
44-
4543
void fsl_edma_tx_chan_handler(struct fsl_edma_chan *fsl_chan)
4644
{
4745
spin_lock(&fsl_chan->vchan.lock);
@@ -285,8 +283,6 @@ static size_t fsl_edma_desc_residue(struct fsl_edma_chan *fsl_chan,
285283
struct virt_dma_desc *vdesc, bool in_progress)
286284
{
287285
struct fsl_edma_desc *edesc = fsl_chan->edesc;
288-
struct edma_regs *regs = &fsl_chan->edma->regs;
289-
u32 ch = fsl_chan->vchan.chan.chan_id;
290286
enum dma_transfer_direction dir = edesc->dirn;
291287
dma_addr_t cur_addr, dma_addr;
292288
size_t len, size;
@@ -301,9 +297,9 @@ static size_t fsl_edma_desc_residue(struct fsl_edma_chan *fsl_chan,
301297
return len;
302298

303299
if (dir == DMA_MEM_TO_DEV)
304-
cur_addr = edma_readl(fsl_chan->edma, &regs->tcd[ch].saddr);
300+
cur_addr = edma_read_tcdreg(fsl_chan, saddr);
305301
else
306-
cur_addr = edma_readl(fsl_chan->edma, &regs->tcd[ch].daddr);
302+
cur_addr = edma_read_tcdreg(fsl_chan, daddr);
307303

308304
/* figure out the finished and calculate the residue */
309305
for (i = 0; i < fsl_chan->edesc->n_tcds; i++) {
@@ -358,9 +354,6 @@ enum dma_status fsl_edma_tx_status(struct dma_chan *chan,
358354
static void fsl_edma_set_tcd_regs(struct fsl_edma_chan *fsl_chan,
359355
struct fsl_edma_hw_tcd *tcd)
360356
{
361-
struct fsl_edma_engine *edma = fsl_chan->edma;
362-
struct edma_regs *regs = &fsl_chan->edma->regs;
363-
u32 ch = fsl_chan->vchan.chan.chan_id;
364357
u16 csr = 0;
365358

366359
/*
@@ -369,31 +362,30 @@ static void fsl_edma_set_tcd_regs(struct fsl_edma_chan *fsl_chan,
369362
* big- or little-endian obeying the eDMA engine model endian,
370363
* and this is performed from specific edma_write functions
371364
*/
372-
edma_writew(edma, 0, &regs->tcd[ch].csr);
365+
edma_write_tcdreg(fsl_chan, 0, csr);
373366

374-
edma_writel(edma, (s32)tcd->saddr, &regs->tcd[ch].saddr);
375-
edma_writel(edma, (s32)tcd->daddr, &regs->tcd[ch].daddr);
367+
edma_write_tcdreg(fsl_chan, tcd->saddr, saddr);
368+
edma_write_tcdreg(fsl_chan, tcd->daddr, daddr);
376369

377-
edma_writew(edma, (s16)tcd->attr, &regs->tcd[ch].attr);
378-
edma_writew(edma, tcd->soff, &regs->tcd[ch].soff);
370+
edma_write_tcdreg(fsl_chan, tcd->attr, attr);
371+
edma_write_tcdreg(fsl_chan, tcd->soff, soff);
379372

380-
edma_writel(edma, (s32)tcd->nbytes, &regs->tcd[ch].nbytes);
381-
edma_writel(edma, (s32)tcd->slast, &regs->tcd[ch].slast);
373+
edma_write_tcdreg(fsl_chan, tcd->nbytes, nbytes);
374+
edma_write_tcdreg(fsl_chan, tcd->slast, slast);
382375

383-
edma_writew(edma, (s16)tcd->citer, &regs->tcd[ch].citer);
384-
edma_writew(edma, (s16)tcd->biter, &regs->tcd[ch].biter);
385-
edma_writew(edma, (s16)tcd->doff, &regs->tcd[ch].doff);
376+
edma_write_tcdreg(fsl_chan, tcd->citer, citer);
377+
edma_write_tcdreg(fsl_chan, tcd->biter, biter);
378+
edma_write_tcdreg(fsl_chan, tcd->doff, doff);
386379

387-
edma_writel(edma, (s32)tcd->dlast_sga,
388-
&regs->tcd[ch].dlast_sga);
380+
edma_write_tcdreg(fsl_chan, tcd->dlast_sga, dlast_sga);
389381

390382
if (fsl_chan->is_sw) {
391383
csr = le16_to_cpu(tcd->csr);
392384
csr |= EDMA_TCD_CSR_START;
393385
tcd->csr = cpu_to_le16(csr);
394386
}
395387

396-
edma_writew(edma, (s16)tcd->csr, &regs->tcd[ch].csr);
388+
edma_write_tcdreg(fsl_chan, tcd->csr, csr);
397389
}
398390

399391
static inline
@@ -736,8 +728,6 @@ void fsl_edma_setup_regs(struct fsl_edma_engine *edma)
736728
edma->regs.errh = edma->membase + EDMA64_ERRH;
737729
edma->regs.inth = edma->membase + EDMA64_INTH;
738730
}
739-
740-
edma->regs.tcd = edma->membase + EDMA_TCD;
741731
}
742732

743733
MODULE_LICENSE("GPL v2");

drivers/dma/fsl-edma-common.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
#define DMAMUX_NR 2
5050

51+
#define EDMA_TCD 0x1000
52+
5153
#define FSL_EDMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
5254
BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
5355
BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | \
@@ -93,7 +95,6 @@ struct edma_regs {
9395
void __iomem *intl;
9496
void __iomem *errh;
9597
void __iomem *errl;
96-
struct fsl_edma_hw_tcd __iomem *tcd;
9798
};
9899

99100
struct fsl_edma_sw_tcd {
@@ -117,6 +118,7 @@ struct fsl_edma_chan {
117118
u32 dma_dev_size;
118119
enum dma_data_direction dma_dir;
119120
char chan_name[32];
121+
struct fsl_edma_hw_tcd __iomem *tcd;
120122
};
121123

122124
struct fsl_edma_desc {
@@ -156,6 +158,16 @@ struct fsl_edma_engine {
156158
struct fsl_edma_chan chans[];
157159
};
158160

161+
#define edma_read_tcdreg(chan, __name) \
162+
(sizeof(chan->tcd->__name) == sizeof(u32) ? \
163+
edma_readl(chan->edma, &chan->tcd->__name) : \
164+
edma_readw(chan->edma, &chan->tcd->__name))
165+
166+
#define edma_write_tcdreg(chan, val, __name) \
167+
(sizeof(chan->tcd->__name) == sizeof(u32) ? \
168+
edma_writel(chan->edma, (u32 __force)val, &chan->tcd->__name) : \
169+
edma_writew(chan->edma, (u16 __force)val, &chan->tcd->__name))
170+
159171
/*
160172
* R/W functions for big- or little-endian registers:
161173
* The eDMA controller's endian is independent of the CPU core's endian.
@@ -170,6 +182,14 @@ static inline u32 edma_readl(struct fsl_edma_engine *edma, void __iomem *addr)
170182
return ioread32(addr);
171183
}
172184

185+
static inline u16 edma_readw(struct fsl_edma_engine *edma, void __iomem *addr)
186+
{
187+
if (edma->big_endian)
188+
return ioread16be(addr);
189+
else
190+
return ioread16(addr);
191+
}
192+
173193
static inline void edma_writeb(struct fsl_edma_engine *edma,
174194
u8 val, void __iomem *addr)
175195
{

drivers/dma/fsl-edma-main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,11 @@ static int fsl_edma_probe(struct platform_device *pdev)
320320
fsl_chan->idle = true;
321321
fsl_chan->dma_dir = DMA_NONE;
322322
fsl_chan->vchan.desc_free = fsl_edma_free_desc;
323+
fsl_chan->tcd = fsl_edma->membase + EDMA_TCD
324+
+ i * sizeof(struct fsl_edma_hw_tcd);
323325
vchan_init(&fsl_chan->vchan, &fsl_edma->dma_dev);
324326

325-
edma_writew(fsl_edma, 0x0, &regs->tcd[i].csr);
327+
edma_write_tcdreg(fsl_chan, 0, csr);
326328
fsl_edma_chan_mux(fsl_chan, 0, false);
327329
}
328330

@@ -430,7 +432,7 @@ static int fsl_edma_resume_early(struct device *dev)
430432
for (i = 0; i < fsl_edma->n_chans; i++) {
431433
fsl_chan = &fsl_edma->chans[i];
432434
fsl_chan->pm_state = RUNNING;
433-
edma_writew(fsl_edma, 0x0, &regs->tcd[i].csr);
435+
edma_write_tcdreg(fsl_chan, 0, csr);
434436
if (fsl_chan->slave_id != 0)
435437
fsl_edma_chan_mux(fsl_chan, fsl_chan->slave_id, true);
436438
}

drivers/dma/mcf-edma-main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ static int mcf_edma_probe(struct platform_device *pdev)
199199
mcf_chan->dma_dir = DMA_NONE;
200200
mcf_chan->vchan.desc_free = fsl_edma_free_desc;
201201
vchan_init(&mcf_chan->vchan, &mcf_edma->dma_dev);
202-
iowrite32(0x0, &regs->tcd[i].csr);
202+
mcf_chan->tcd = mcf_edma->membase + EDMA_TCD
203+
+ i * sizeof(struct fsl_edma_hw_tcd);
204+
iowrite32(0x0, &mcf_chan->tcd->csr);
203205
}
204206

205207
iowrite32(~0, regs->inth);

0 commit comments

Comments
 (0)