lkml.org 
[lkml]   [2017]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 13/31] nds32: DMA mapping API
On Wed, Nov 8, 2017 at 6:55 AM, Greentime Hu <green.hu@gmail.com> wrote:

> +static void consistent_sync(void *vaddr, size_t size, int direction)
> +{
> + unsigned long start = (unsigned long)vaddr;
> + unsigned long end = start + size;
> +
> + switch (direction) {
> + case DMA_FROM_DEVICE: /* invalidate only */
> + cpu_dma_inval_range(start, end);
> + break;
> + case DMA_TO_DEVICE: /* writeback only */
> + cpu_dma_wb_range(start, end);
> + break;
> + case DMA_BIDIRECTIONAL: /* writeback and invalidate */
> + cpu_dma_wbinval_range(start, end);
> + break;
> + default:
> + BUG();
> + }
> +}

> +
> +static void
> +nds32_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle,
> + size_t size, enum dma_data_direction dir)
> +{
> + consistent_sync((void *)dma_to_virt(dev, handle), size, dir);
> +}
> +
> +static void
> +nds32_dma_sync_single_for_device(struct device *dev, dma_addr_t handle,
> + size_t size, enum dma_data_direction dir)
> +{
> + consistent_sync((void *)dma_to_virt(dev, handle), size, dir);
> +}

You do the same cache operations for _to_cpu and _to_device, which
usually works,
but is more expensive than you need. It's better to take the ownership into
account and only do what you need.

Arnd

\
 
 \ /
  Last update: 2017-11-08 21:11    [W:0.669 / U:0.532 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site