Re: [PATCH] dmatest: flush and invalidate destination bufferbefore DMA

From: Atsushi Nemoto
Date: Sun Dec 28 2008 - 13:04:15 EST


On Sat, 27 Dec 2008 11:10:37 +0100, Haavard Skinnemoen <haavard.skinnemoen@xxxxxxxxx> wrote:
> Atsushi Nemoto wrote:
> > @@ -226,6 +227,12 @@ static int dmatest_func(void *data)
> >
> > dmatest_init_srcbuf(thread->srcbuf, src_off, len);
> > dmatest_init_dstbuf(thread->dstbuf, dst_off, len);
> > + /* flush and invalidate caches for whole dstbuf */
> > + dma_dest = dma_map_single(chan->device->dev,
> > + thread->dstbuf,
> > + test_buf_size, DMA_BIDIRECTIONAL);
> > + dma_unmap_single(chan->device->dev, dma_dest,
> > + test_buf_size, DMA_BIDIRECTIONAL);
>
> You're supposed to unmap after the DMA operation is done, not before
> it's submitted.
>
> In this case, the DMA engine framework will do the unmapping for you
> (probably using the wrong primitive, but they're really all the same in
> practice, right?) so you can just drop the unmap call.

Well, let me explain more.

On nono-coherent MIPS platforms, dma_map_single() for DMA_TO_DEVICE
writeback the cache, dma_map_single() for DMA_FROM_DEVICE invalidated
(without writeback) the cache. dma_unmap_simgle() is a nop.

If dst_off was not cacheline aligned, dma_map_single(...,
DMA_FROM_DEVICE) in dma_async_memcpy_buf_to_buf() invalidate whole
cachelines including dst_off. So, for example, the initialized data
at dst_off - 1 will be just discarded. This result mismatch error of
course. Same error can be happen at end of the real DMA area.

I added dma_map_single/dma_unmap_single to just flush all dstbuf to
main memory.

> Now, I suspect the dw_dmac driver maps the buffer when it's not
> supposed to, masking this kind of error...should probably get that
> fixed too.

I don't think so. But I'm not sure dma_map_sg() case in
dwc_prep_slave_sg().

---
Atsushi Nemoto
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/