Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1262191

Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in _dma_page_cpu_to_dev()

From Will Deacon <will.deacon@arm.com>
Newsgroups linux.kernel
Subject Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in _dma_page_cpu_to_dev()
Date 2015-11-04 11:40 +0100
Message-ID <qr3DX-7Fs-7@gated-at.bofh.it> (permalink)
References <qr31h-7c0-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Nov 04, 2015 at 03:26:48PM +0530, Sanjeev Sharma wrote:
> _dma_page_cpu_to_dev() treat DMA_BIDIRECTIONAL similar to DMA_TO_DEVICE
> which means that destination buffer is device memory,means cpu may have
> written some data to source buffer and data may be in cache line.For
> cleaner operation we need to call outer_flush_range() which will
> clean and invalidate outer cache lines.

Why isn't the clean sufficient in this case? We're mapping the buffer
to the device, so we clean the dirty lines in the CPU caches and make
them visible to the device. If the CPU later wants to read the buffer
(i.e. after the device has DMA'd into it), you'll need to map the
buffer to the CPU, which will perform the invalidation of the CPU caches.

Will

> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index e62400e..e195235 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -850,12 +850,20 @@ static void __dma_page_cpu_to_dev(struct page *page, unsigned long off,
>  	dma_cache_maint_page(page, off, size, dir, dmac_map_area);
>  
>  	paddr = page_to_phys(page) + off;
> -	if (dir == DMA_FROM_DEVICE) {
> -		outer_inv_range(paddr, paddr + size);
> -	} else {
> -		outer_clean_range(paddr, paddr + size);
> +
> +	switch (dir) {
> +	case DMA_FROM_DEVICE:
> +			outer_inv_range(paddr, paddr + size);
> +			break;
> +	case DMA_TO_DEVICE:
> +			outer_clean_range(paddr, paddr + size);
> +			break;
> +	case DMA_BIDIRECTIONAL:
> +			outer_flush_range(paddr, paddr + size);
> +			break;
> +	default:
> +			break;
>  	}
> -	/* FIXME: non-speculating: flush on bidirectional mappings? */
>  }
>  
>  static void __dma_page_dev_to_cpu(struct page *page, unsigned long off,
> -- 
> 1.7.11.7
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in _dma_page_cpu_to_dev() Sanjeev Sharma <sanjeev_sharma@mentor.com> - 2015-11-04 11:00 +0100
  Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Will Deacon <will.deacon@arm.com> - 2015-11-04 11:40 +0100
    Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-11-04 12:00 +0100
      RE: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() "Sharma, Sanjeev" <Sanjeev_Sharma@mentor.com> - 2015-11-05 07:00 +0100
        Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Will Deacon <will.deacon@arm.com> - 2015-11-09 11:10 +0100
          RE: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() "Sharma, Sanjeev" <Sanjeev_Sharma@mentor.com> - 2015-11-09 11:20 +0100
            Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Robin Murphy <robin.murphy@arm.com> - 2015-11-09 12:00 +0100
            Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-11-09 13:10 +0100

csiph-web