Re: [PATCH 1/3] drm: Add and export function drm_gem_cma_create_noalloc
From: Daniel Vetter
Date: Thu Oct 01 2020 - 04:51:54 EST
On Wed, Sep 30, 2020 at 07:16:42PM +0200, Paul Cercueil wrote:
> Add and export the function drm_gem_cma_create_noalloc(), which is just
> __drm_gem_cma_create() renamed.
>
> This function can be used by drivers that need to create a GEM object
> without allocating the backing memory.
>
> Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx>
> ---
> drivers/gpu/drm/drm_gem_cma_helper.c | 11 ++++++-----
> include/drm/drm_gem_cma_helper.h | 3 +++
> 2 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
> index 59b9ca207b42..6abc4b306832 100644
> --- a/drivers/gpu/drm/drm_gem_cma_helper.c
> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
> @@ -34,7 +34,7 @@
> */
>
> /**
> - * __drm_gem_cma_create - Create a GEM CMA object without allocating memory
> + * drm_gem_cma_create_noalloc - Create a GEM CMA object without allocating memory
> * @drm: DRM device
> * @size: size of the object to allocate
> *
> @@ -45,8 +45,8 @@
> * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative
> * error code on failure.
> */
> -static struct drm_gem_cma_object *
> -__drm_gem_cma_create(struct drm_device *drm, size_t size)
> +struct drm_gem_cma_object *
> +drm_gem_cma_create_noalloc(struct drm_device *drm, size_t size)
> {
> struct drm_gem_cma_object *cma_obj;
> struct drm_gem_object *gem_obj;
> @@ -76,6 +76,7 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size)
> kfree(cma_obj);
> return ERR_PTR(ret);
> }
> +EXPORT_SYMBOL_GPL(drm_gem_cma_create_noalloc);
This feels a bit awkward, since for drivers who want to roll their own we
can do that already.
I think the better approach is to export a cma function which allocates
non-coherent dma memory.
-Daniel
>
> /**
> * drm_gem_cma_create - allocate an object with the given size
> @@ -98,7 +99,7 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
>
> size = round_up(size, PAGE_SIZE);
>
> - cma_obj = __drm_gem_cma_create(drm, size);
> + cma_obj = drm_gem_cma_create_noalloc(drm, size);
> if (IS_ERR(cma_obj))
> return cma_obj;
>
> @@ -476,7 +477,7 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
> return ERR_PTR(-EINVAL);
>
> /* Create a CMA GEM buffer. */
> - cma_obj = __drm_gem_cma_create(dev, attach->dmabuf->size);
> + cma_obj = drm_gem_cma_create_noalloc(dev, attach->dmabuf->size);
> if (IS_ERR(cma_obj))
> return ERR_CAST(cma_obj);
>
> diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h
> index 2bfa2502607a..be2b8e3a8ab2 100644
> --- a/include/drm/drm_gem_cma_helper.h
> +++ b/include/drm/drm_gem_cma_helper.h
> @@ -83,6 +83,9 @@ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma);
> struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
> size_t size);
>
> +struct drm_gem_cma_object *
> +drm_gem_cma_create_noalloc(struct drm_device *drm, size_t size);
> +
> extern const struct vm_operations_struct drm_gem_cma_vm_ops;
>
> #ifndef CONFIG_MMU
> --
> 2.28.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch