public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] gpu: host1x: Use direct DMA with IOMMU API usage
@ 2019-02-06 22:08 Guenter Roeck
  2019-02-07  8:51 ` Thierry Reding
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2019-02-06 22:08 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-kernel

On Fri, Feb 01, 2019 at 02:28:26PM +0100, Thierry Reding wrote:
> If we use the IOMMU API directly to map buffers into host1x' IOVA space,
> we must make sure that the DMA API doesn't already set up a mapping, or
> else translation will fail.
> 
> The direct DMA API allows us to allocate memory that will not be mapped
> through an IOMMU automatically.
> 
> Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

arm64:defconfig:

ERROR: "dma_direct_free" [drivers/gpu/host1x/host1x.ko] undefined!
ERROR: "dma_direct_alloc" [drivers/gpu/host1x/host1x.ko] undefined!

Guenter

> ---
>  drivers/gpu/host1x/cdma.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/host1x/cdma.c b/drivers/gpu/host1x/cdma.c
> index 64099cc1964b..e22c1133a4c5 100644
> --- a/drivers/gpu/host1x/cdma.c
> +++ b/drivers/gpu/host1x/cdma.c
> @@ -19,6 +19,7 @@
>  
>  #include <asm/cacheflush.h>
>  #include <linux/device.h>
> +#include <linux/dma-direct.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/host1x.h>
>  #include <linux/interrupt.h>
> @@ -70,6 +71,7 @@ static void host1x_pushbuffer_destroy(struct push_buffer *pb)
>   */
>  static int host1x_pushbuffer_init(struct push_buffer *pb)
>  {
> +	unsigned long attrs = DMA_ATTR_WRITE_COMBINE;
>  	struct host1x_cdma *cdma = pb_to_cdma(pb);
>  	struct host1x *host1x = cdma_to_host1x(cdma);
>  	struct iova *alloc;
> @@ -91,8 +93,8 @@ static int host1x_pushbuffer_init(struct push_buffer *pb)
>  
>  		size = iova_align(&host1x->iova, size);
>  
> -		pb->mapped = dma_alloc_wc(host1x->dev, size, &pb->phys,
> -					  GFP_KERNEL);
> +		pb->mapped = dma_direct_alloc(host1x->dev, size, &pb->phys,
> +					      GFP_KERNEL, attrs);
>  		if (!pb->mapped)
>  			return -ENOMEM;
>  
> @@ -127,7 +129,10 @@ static int host1x_pushbuffer_init(struct push_buffer *pb)
>  iommu_free_iova:
>  	__free_iova(&host1x->iova, alloc);
>  iommu_free_mem:
> -	dma_free_wc(host1x->dev, size, pb->mapped, pb->phys);
> +	if (host1x->domain)
> +		dma_direct_free(host1x->dev, size, pb->mapped, pb->phys, attrs);
> +	else
> +		dma_free_wc(host1x->dev, size, pb->mapped, pb->phys);
>  
>  	return err;
>  }
> -- 
> 2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gpu: host1x: Use direct DMA with IOMMU API usage
  2019-02-06 22:08 [PATCH] gpu: host1x: Use direct DMA with IOMMU API usage Guenter Roeck
@ 2019-02-07  8:51 ` Thierry Reding
  0 siblings, 0 replies; 2+ messages in thread
From: Thierry Reding @ 2019-02-07  8:51 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

On Wed, Feb 06, 2019 at 02:08:33PM -0800, Guenter Roeck wrote:
> On Fri, Feb 01, 2019 at 02:28:26PM +0100, Thierry Reding wrote:
> > If we use the IOMMU API directly to map buffers into host1x' IOVA space,
> > we must make sure that the DMA API doesn't already set up a mapping, or
> > else translation will fail.
> > 
> > The direct DMA API allows us to allocate memory that will not be mapped
> > through an IOMMU automatically.
> > 
> > Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> 
> arm64:defconfig:
> 
> ERROR: "dma_direct_free" [drivers/gpu/host1x/host1x.ko] undefined!
> ERROR: "dma_direct_alloc" [drivers/gpu/host1x/host1x.ko] undefined!

Hi Guenter,

I sent out a fix to export dma_direct_alloc() and dma_direct_free() but
Christoph preferred not to merge that, so I'm currently working on a
different solution for this. I hope to have a fix for this by the end of
the day, but if not I'll back out the above commit.

Thanks,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-07  8:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-06 22:08 [PATCH] gpu: host1x: Use direct DMA with IOMMU API usage Guenter Roeck
2019-02-07  8:51 ` Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox