mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Vladimir Murzin <vladimir.murzin@arm.com>, linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk,
	sza@esh.hu, arnd@arndb.de, gregkh@linuxfoundation.org,
	akpm@linux-foundation.org, alexandre.torgue@st.com,
	kbuild-all@01.org, benjamin.gaignard@linaro.org, hch@lst.de,
	m.szyprowski@samsung.com, vitaly_kuzmichev@mentor.com,
	george_davis@mentor.com
Subject: Re: [PATCH 2/2] ARM: NOMMU: Wire-up default DMA interface
Date: Thu, 20 Jul 2017 14:48:58 +0100	[thread overview]
Message-ID: <3872d014-7782-eac1-29ce-098d7e70ae07@arm.com> (raw)
In-Reply-To: <1500545999-17177-3-git-send-email-vladimir.murzin@arm.com>

On 20/07/17 11:19, Vladimir Murzin wrote:
> The way how default DMA pool is exposed has changed and now we need to
> use dedicated interface to work with it. This patch makes alloc/release
> operations to use such interface. Since, default DMA pool is not
> handled by generic code anymore we have to implement our own mmap
> operation.
> 
> Tested-by: Andras Szemzo <sza@esh.hu>
> Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>

Looks like the right thing to do :)

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> ---
>  arch/arm/mm/dma-mapping-nommu.c | 45 ++++++++++++++++++++++++++++++++---------
>  1 file changed, 36 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nommu.c
> index 90ee354..6db5fc2 100644
> --- a/arch/arm/mm/dma-mapping-nommu.c
> +++ b/arch/arm/mm/dma-mapping-nommu.c
> @@ -40,9 +40,21 @@ static void *arm_nommu_dma_alloc(struct device *dev, size_t size,
>  
>  {
>  	const struct dma_map_ops *ops = &dma_noop_ops;
> +	void *ret;
>  
>  	/*
> -	 * We are here because:
> +	 * Try generic allocator first if we are advertised that
> +	 * consistency is not required.
> +	 */
> +
> +	if (attrs & DMA_ATTR_NON_CONSISTENT)
> +		return ops->alloc(dev, size, dma_handle, gfp, attrs);
> +
> +	ret = dma_alloc_from_global_coherent(size, dma_handle);
> +
> +	/*
> +	 * dma_alloc_from_global_coherent() may fail because:
> +	 *
>  	 * - no consistent DMA region has been defined, so we can't
>  	 *   continue.
>  	 * - there is no space left in consistent DMA region, so we
> @@ -50,11 +62,8 @@ static void *arm_nommu_dma_alloc(struct device *dev, size_t size,
>  	 *   advertised that consistency is not required.
>  	 */
>  
> -	if (attrs & DMA_ATTR_NON_CONSISTENT)
> -		return ops->alloc(dev, size, dma_handle, gfp, attrs);
> -
> -	WARN_ON_ONCE(1);
> -	return NULL;
> +	WARN_ON_ONCE(ret == NULL);
> +	return ret;
>  }
>  
>  static void arm_nommu_dma_free(struct device *dev, size_t size,
> @@ -63,14 +72,31 @@ static void arm_nommu_dma_free(struct device *dev, size_t size,
>  {
>  	const struct dma_map_ops *ops = &dma_noop_ops;
>  
> -	if (attrs & DMA_ATTR_NON_CONSISTENT)
> +	if (attrs & DMA_ATTR_NON_CONSISTENT) {
>  		ops->free(dev, size, cpu_addr, dma_addr, attrs);
> -	else
> -		WARN_ON_ONCE(1);
> +	} else {
> +		int ret = dma_release_from_global_coherent(get_order(size),
> +							   cpu_addr);
> +
> +		WARN_ON_ONCE(ret == 0);
> +	}
>  
>  	return;
>  }
>  
> +static int arm_nommu_dma_mmap(struct device *dev, struct vm_area_struct *vma,
> +			      void *cpu_addr, dma_addr_t dma_addr, size_t size,
> +			      unsigned long attrs)
> +{
> +	int ret;
> +
> +	if (dma_mmap_from_global_coherent(vma, cpu_addr, size, &ret))
> +		return ret;
> +
> +	return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
> +}
> +
> +
>  static void __dma_page_cpu_to_dev(phys_addr_t paddr, size_t size,
>  				  enum dma_data_direction dir)
>  {
> @@ -173,6 +199,7 @@ static void arm_nommu_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist
>  const struct dma_map_ops arm_nommu_dma_ops = {
>  	.alloc			= arm_nommu_dma_alloc,
>  	.free			= arm_nommu_dma_free,
> +	.mmap			= arm_nommu_dma_mmap,
>  	.map_page		= arm_nommu_dma_map_page,
>  	.unmap_page		= arm_nommu_dma_unmap_page,
>  	.map_sg			= arm_nommu_dma_map_sg,
> 

      reply	other threads:[~2017-07-20 13:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-20 10:19 [PATCH 0/2] Introduce interface for default DMA pool Vladimir Murzin
2017-07-20 10:19 ` [PATCH 1/2] drivers: dma-coherent: " Vladimir Murzin
2017-07-20 13:45   ` Robin Murphy
2017-07-20 14:11     ` Christoph Hellwig
2017-07-20 10:19 ` [PATCH 2/2] ARM: NOMMU: Wire-up default DMA interface Vladimir Murzin
2017-07-20 13:48   ` Robin Murphy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3872d014-7782-eac1-29ce-098d7e70ae07@arm.com \
    --to=robin.murphy@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexandre.torgue@st.com \
    --cc=arnd@arndb.de \
    --cc=benjamin.gaignard@linaro.org \
    --cc=george_davis@mentor.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=kbuild-all@01.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=sza@esh.hu \
    --cc=vitaly_kuzmichev@mentor.com \
    --cc=vladimir.murzin@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome