diff mbox series

[3/6] drm/cma-helper: Use the dma_*_attr API variant

Message ID 20191021214550.1461-4-robh@kernel.org
State New
Headers show
Series drm: Support CMA per allocation kernel mappings | expand

Commit Message

Rob Herring Oct. 21, 2019, 9:45 p.m. UTC
In preparation to allow DRM CMA users to adjust the DMA_ATTR_* flags,
convert the CMA helper code to use the dma_*_attr APIs instead of the
dma_*_wc variants.

Only the DMA_ATTR_WRITE_COMBINE and DMA_ATTR_NO_WARN attributes are set
in this commit, so there's no functional change.

Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Sean Paul <sean@poorly.run>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/gpu/drm/drm_gem_cma_helper.c | 20 ++++++++++++--------
 include/drm/drm_gem_cma_helper.h     |  1 +
 2 files changed, 13 insertions(+), 8 deletions(-)

--
2.20.1

Comments

Laurent Pinchart Oct. 22, 2019, 11:18 a.m. UTC | #1
Hi Rob,

Thank you for the patch.

On Mon, Oct 21, 2019 at 04:45:47PM -0500, Rob Herring wrote:
> In preparation to allow DRM CMA users to adjust the DMA_ATTR_* flags,
> convert the CMA helper code to use the dma_*_attr APIs instead of the
> dma_*_wc variants.
> 
> Only the DMA_ATTR_WRITE_COMBINE and DMA_ATTR_NO_WARN attributes are set
> in this commit, so there's no functional change.

Apart from the documentation issue reported by kbuild,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: Sean Paul <sean@poorly.run>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  drivers/gpu/drm/drm_gem_cma_helper.c | 20 ++++++++++++--------
>  include/drm/drm_gem_cma_helper.h     |  1 +
>  2 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
> index 12e98fb28229..4cebfe01e6ea 100644
> --- a/drivers/gpu/drm/drm_gem_cma_helper.c
> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
> @@ -70,6 +70,7 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size)
>  		goto error;
>  	}
> 
> +	cma_obj->dma_attrs |= DMA_ATTR_NO_WARN | DMA_ATTR_WRITE_COMBINE;
>  	return cma_obj;
> 
>  error:
> @@ -102,8 +103,9 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
>  	if (IS_ERR(cma_obj))
>  		return cma_obj;
> 
> -	cma_obj->vaddr = dma_alloc_wc(drm->dev, size, &cma_obj->paddr,
> -				      GFP_KERNEL | __GFP_NOWARN);
> +	cma_obj->vaddr = dma_alloc_attrs(drm->dev, size, &cma_obj->paddr,
> +					 GFP_KERNEL | __GFP_NOWARN,
> +					 cma_obj->dma_attrs);
>  	if (!cma_obj->vaddr) {
>  		dev_dbg(drm->dev, "failed to allocate buffer with size %zu\n",
>  			size);
> @@ -184,8 +186,9 @@ void drm_gem_cma_free_object(struct drm_gem_object *gem_obj)
>  			dma_buf_vunmap(gem_obj->import_attach->dmabuf, cma_obj->vaddr);
>  		drm_prime_gem_destroy(gem_obj, cma_obj->sgt);
>  	} else if (cma_obj->vaddr) {
> -		dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
> -			    cma_obj->vaddr, cma_obj->paddr);
> +		dma_free_attrs(gem_obj->dev->dev, cma_obj->base.size,
> +			       cma_obj->vaddr, cma_obj->paddr,
> +			       cma_obj->dma_attrs);
>  	}
> 
>  	drm_gem_object_release(gem_obj);
> @@ -279,8 +282,9 @@ static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj,
>  	vma->vm_flags &= ~VM_PFNMAP;
>  	vma->vm_pgoff = 0;
> 
> -	ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr,
> -			  cma_obj->paddr, vma->vm_end - vma->vm_start);
> +	ret = dma_mmap_attrs(cma_obj->base.dev->dev, vma, cma_obj->vaddr,
> +			     cma_obj->paddr, vma->vm_end - vma->vm_start,
> +			     cma_obj->dma_attrs);
>  	if (ret)
>  		drm_gem_vm_close(vma);
> 
> @@ -434,8 +438,8 @@ struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
>  	if (!sgt)
>  		return ERR_PTR(-ENOMEM);
> 
> -	ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
> -			      cma_obj->paddr, obj->size);
> +	ret = dma_get_sgtable_attrs(obj->dev->dev, sgt, cma_obj->vaddr,
> +			      cma_obj->paddr, obj->size, cma_obj->dma_attrs);
>  	if (ret < 0)
>  		goto out;
> 
> diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h
> index 947ac95eb24a..d042213c3595 100644
> --- a/include/drm/drm_gem_cma_helper.h
> +++ b/include/drm/drm_gem_cma_helper.h
> @@ -24,6 +24,7 @@ struct drm_gem_cma_object {
> 
>  	/* For objects with DMA memory allocated by GEM CMA */
>  	void *vaddr;
> +	unsigned long dma_attrs;
>  };
> 
>  #define to_drm_gem_cma_obj(gem_obj) \
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
index 12e98fb28229..4cebfe01e6ea 100644
--- a/drivers/gpu/drm/drm_gem_cma_helper.c
+++ b/drivers/gpu/drm/drm_gem_cma_helper.c
@@ -70,6 +70,7 @@  __drm_gem_cma_create(struct drm_device *drm, size_t size)
 		goto error;
 	}

+	cma_obj->dma_attrs |= DMA_ATTR_NO_WARN | DMA_ATTR_WRITE_COMBINE;
 	return cma_obj;

 error:
@@ -102,8 +103,9 @@  struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
 	if (IS_ERR(cma_obj))
 		return cma_obj;

-	cma_obj->vaddr = dma_alloc_wc(drm->dev, size, &cma_obj->paddr,
-				      GFP_KERNEL | __GFP_NOWARN);
+	cma_obj->vaddr = dma_alloc_attrs(drm->dev, size, &cma_obj->paddr,
+					 GFP_KERNEL | __GFP_NOWARN,
+					 cma_obj->dma_attrs);
 	if (!cma_obj->vaddr) {
 		dev_dbg(drm->dev, "failed to allocate buffer with size %zu\n",
 			size);
@@ -184,8 +186,9 @@  void drm_gem_cma_free_object(struct drm_gem_object *gem_obj)
 			dma_buf_vunmap(gem_obj->import_attach->dmabuf, cma_obj->vaddr);
 		drm_prime_gem_destroy(gem_obj, cma_obj->sgt);
 	} else if (cma_obj->vaddr) {
-		dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
-			    cma_obj->vaddr, cma_obj->paddr);
+		dma_free_attrs(gem_obj->dev->dev, cma_obj->base.size,
+			       cma_obj->vaddr, cma_obj->paddr,
+			       cma_obj->dma_attrs);
 	}

 	drm_gem_object_release(gem_obj);
@@ -279,8 +282,9 @@  static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj,
 	vma->vm_flags &= ~VM_PFNMAP;
 	vma->vm_pgoff = 0;

-	ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr,
-			  cma_obj->paddr, vma->vm_end - vma->vm_start);
+	ret = dma_mmap_attrs(cma_obj->base.dev->dev, vma, cma_obj->vaddr,
+			     cma_obj->paddr, vma->vm_end - vma->vm_start,
+			     cma_obj->dma_attrs);
 	if (ret)
 		drm_gem_vm_close(vma);

@@ -434,8 +438,8 @@  struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
 	if (!sgt)
 		return ERR_PTR(-ENOMEM);

-	ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
-			      cma_obj->paddr, obj->size);
+	ret = dma_get_sgtable_attrs(obj->dev->dev, sgt, cma_obj->vaddr,
+			      cma_obj->paddr, obj->size, cma_obj->dma_attrs);
 	if (ret < 0)
 		goto out;

diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h
index 947ac95eb24a..d042213c3595 100644
--- a/include/drm/drm_gem_cma_helper.h
+++ b/include/drm/drm_gem_cma_helper.h
@@ -24,6 +24,7 @@  struct drm_gem_cma_object {

 	/* For objects with DMA memory allocated by GEM CMA */
 	void *vaddr;
+	unsigned long dma_attrs;
 };

 #define to_drm_gem_cma_obj(gem_obj) \