drm/shmem-helper: Pass GEM shmem object in public interfaces

Change all GEM SHMEM object functions that receive a GEM object
of type struct drm_gem_object to expect an object of type
struct drm_gem_shmem_object instead.

This change reduces the number of upcasts from struct drm_gem_object
by moving them into callers. The C compiler can now verify that the
GEM SHMEM functions are called with the correct type.

For consistency, the patch also renames drm_gem_shmem_free_object to
drm_gem_shmem_free. It further updates documentation for a number of
functions.

v3:
	* fix docs for drm_gem_shmem_object_free()
v2:
	* mention _object_ callbacks in docs (Daniel)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20211108093149.7226-4-tzimmermann@suse.de
This commit is contained in:
Thomas Zimmermann 2021-11-08 10:31:49 +01:00
parent c7fbcb7149
commit a193f3b4e0
11 changed files with 107 additions and 102 deletions

View File

@ -27,6 +27,11 @@
* *
* This library provides helpers for GEM objects backed by shmem buffers * This library provides helpers for GEM objects backed by shmem buffers
* allocated using anonymous pageable memory. * allocated using anonymous pageable memory.
*
* Functions that operate on the GEM object receive struct &drm_gem_shmem_object.
* For GEM callback helpers in struct &drm_gem_object functions, see likewise
* named functions with an _object_ infix (e.g., drm_gem_shmem_object_vmap() wraps
* drm_gem_shmem_vmap()). These helpers perform the necessary type conversion.
*/ */
static const struct drm_gem_object_funcs drm_gem_shmem_funcs = { static const struct drm_gem_object_funcs drm_gem_shmem_funcs = {
@ -117,15 +122,15 @@ struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t
EXPORT_SYMBOL_GPL(drm_gem_shmem_create); EXPORT_SYMBOL_GPL(drm_gem_shmem_create);
/** /**
* drm_gem_shmem_free_object - Free resources associated with a shmem GEM object * drm_gem_shmem_free - Free resources associated with a shmem GEM object
* @obj: GEM object to free * @shmem: shmem GEM object to free
* *
* This function cleans up the GEM object state and frees the memory used to * This function cleans up the GEM object state and frees the memory used to
* store the object itself. * store the object itself.
*/ */
void drm_gem_shmem_free_object(struct drm_gem_object *obj) void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem)
{ {
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); struct drm_gem_object *obj = &shmem->base;
WARN_ON(shmem->vmap_use_count); WARN_ON(shmem->vmap_use_count);
@ -149,7 +154,7 @@ void drm_gem_shmem_free_object(struct drm_gem_object *obj)
mutex_destroy(&shmem->vmap_lock); mutex_destroy(&shmem->vmap_lock);
kfree(shmem); kfree(shmem);
} }
EXPORT_SYMBOL_GPL(drm_gem_shmem_free_object); EXPORT_SYMBOL_GPL(drm_gem_shmem_free);
static int drm_gem_shmem_get_pages_locked(struct drm_gem_shmem_object *shmem) static int drm_gem_shmem_get_pages_locked(struct drm_gem_shmem_object *shmem)
{ {
@ -244,7 +249,7 @@ EXPORT_SYMBOL(drm_gem_shmem_put_pages);
/** /**
* drm_gem_shmem_pin - Pin backing pages for a shmem GEM object * drm_gem_shmem_pin - Pin backing pages for a shmem GEM object
* @obj: GEM object * @shmem: shmem GEM object
* *
* This function makes sure the backing pages are pinned in memory while the * This function makes sure the backing pages are pinned in memory while the
* buffer is exported. * buffer is exported.
@ -252,10 +257,8 @@ EXPORT_SYMBOL(drm_gem_shmem_put_pages);
* Returns: * Returns:
* 0 on success or a negative error code on failure. * 0 on success or a negative error code on failure.
*/ */
int drm_gem_shmem_pin(struct drm_gem_object *obj) int drm_gem_shmem_pin(struct drm_gem_shmem_object *shmem)
{ {
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
WARN_ON(shmem->base.import_attach); WARN_ON(shmem->base.import_attach);
return drm_gem_shmem_get_pages(shmem); return drm_gem_shmem_get_pages(shmem);
@ -264,15 +267,13 @@ EXPORT_SYMBOL(drm_gem_shmem_pin);
/** /**
* drm_gem_shmem_unpin - Unpin backing pages for a shmem GEM object * drm_gem_shmem_unpin - Unpin backing pages for a shmem GEM object
* @obj: GEM object * @shmem: shmem GEM object
* *
* This function removes the requirement that the backing pages are pinned in * This function removes the requirement that the backing pages are pinned in
* memory. * memory.
*/ */
void drm_gem_shmem_unpin(struct drm_gem_object *obj) void drm_gem_shmem_unpin(struct drm_gem_shmem_object *shmem)
{ {
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
WARN_ON(shmem->base.import_attach); WARN_ON(shmem->base.import_attach);
drm_gem_shmem_put_pages(shmem); drm_gem_shmem_put_pages(shmem);
@ -346,9 +347,8 @@ err_zero_use:
* Returns: * Returns:
* 0 on success or a negative error code on failure. * 0 on success or a negative error code on failure.
*/ */
int drm_gem_shmem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) int drm_gem_shmem_vmap(struct drm_gem_shmem_object *shmem, struct dma_buf_map *map)
{ {
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
int ret; int ret;
ret = mutex_lock_interruptible(&shmem->vmap_lock); ret = mutex_lock_interruptible(&shmem->vmap_lock);
@ -394,10 +394,8 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
* This function hides the differences between dma-buf imported and natively * This function hides the differences between dma-buf imported and natively
* allocated objects. * allocated objects.
*/ */
void drm_gem_shmem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map) void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem, struct dma_buf_map *map)
{ {
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
mutex_lock(&shmem->vmap_lock); mutex_lock(&shmem->vmap_lock);
drm_gem_shmem_vunmap_locked(shmem, map); drm_gem_shmem_vunmap_locked(shmem, map);
mutex_unlock(&shmem->vmap_lock); mutex_unlock(&shmem->vmap_lock);
@ -432,10 +430,8 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
/* Update madvise status, returns true if not purged, else /* Update madvise status, returns true if not purged, else
* false or -errno. * false or -errno.
*/ */
int drm_gem_shmem_madvise(struct drm_gem_object *obj, int madv) int drm_gem_shmem_madvise(struct drm_gem_shmem_object *shmem, int madv)
{ {
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
mutex_lock(&shmem->pages_lock); mutex_lock(&shmem->pages_lock);
if (shmem->madv >= 0) if (shmem->madv >= 0)
@ -449,14 +445,14 @@ int drm_gem_shmem_madvise(struct drm_gem_object *obj, int madv)
} }
EXPORT_SYMBOL(drm_gem_shmem_madvise); EXPORT_SYMBOL(drm_gem_shmem_madvise);
void drm_gem_shmem_purge_locked(struct drm_gem_object *obj) void drm_gem_shmem_purge_locked(struct drm_gem_shmem_object *shmem)
{ {
struct drm_gem_object *obj = &shmem->base;
struct drm_device *dev = obj->dev; struct drm_device *dev = obj->dev;
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
WARN_ON(!drm_gem_shmem_is_purgeable(shmem)); WARN_ON(!drm_gem_shmem_is_purgeable(shmem));
dma_unmap_sgtable(obj->dev->dev, shmem->sgt, DMA_BIDIRECTIONAL, 0); dma_unmap_sgtable(dev->dev, shmem->sgt, DMA_BIDIRECTIONAL, 0);
sg_free_table(shmem->sgt); sg_free_table(shmem->sgt);
kfree(shmem->sgt); kfree(shmem->sgt);
shmem->sgt = NULL; shmem->sgt = NULL;
@ -475,18 +471,15 @@ void drm_gem_shmem_purge_locked(struct drm_gem_object *obj)
*/ */
shmem_truncate_range(file_inode(obj->filp), 0, (loff_t)-1); shmem_truncate_range(file_inode(obj->filp), 0, (loff_t)-1);
invalidate_mapping_pages(file_inode(obj->filp)->i_mapping, invalidate_mapping_pages(file_inode(obj->filp)->i_mapping, 0, (loff_t)-1);
0, (loff_t)-1);
} }
EXPORT_SYMBOL(drm_gem_shmem_purge_locked); EXPORT_SYMBOL(drm_gem_shmem_purge_locked);
bool drm_gem_shmem_purge(struct drm_gem_object *obj) bool drm_gem_shmem_purge(struct drm_gem_shmem_object *shmem)
{ {
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
if (!mutex_trylock(&shmem->pages_lock)) if (!mutex_trylock(&shmem->pages_lock))
return false; return false;
drm_gem_shmem_purge_locked(obj); drm_gem_shmem_purge_locked(shmem);
mutex_unlock(&shmem->pages_lock); mutex_unlock(&shmem->pages_lock);
return true; return true;
@ -594,7 +587,7 @@ static const struct vm_operations_struct drm_gem_shmem_vm_ops = {
/** /**
* drm_gem_shmem_mmap - Memory-map a shmem GEM object * drm_gem_shmem_mmap - Memory-map a shmem GEM object
* @obj: gem object * @shmem: shmem GEM object
* @vma: VMA for the area to be mapped * @vma: VMA for the area to be mapped
* *
* This function implements an augmented version of the GEM DRM file mmap * This function implements an augmented version of the GEM DRM file mmap
@ -603,9 +596,9 @@ static const struct vm_operations_struct drm_gem_shmem_vm_ops = {
* Returns: * Returns:
* 0 on success or a negative error code on failure. * 0 on success or a negative error code on failure.
*/ */
int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) int drm_gem_shmem_mmap(struct drm_gem_shmem_object *shmem, struct vm_area_struct *vma)
{ {
struct drm_gem_shmem_object *shmem; struct drm_gem_object *obj = &shmem->base;
int ret; int ret;
if (obj->import_attach) { if (obj->import_attach) {
@ -616,8 +609,6 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
return dma_buf_mmap(obj->dma_buf, vma, 0); return dma_buf_mmap(obj->dma_buf, vma, 0);
} }
shmem = to_drm_gem_shmem_obj(obj);
ret = drm_gem_shmem_get_pages(shmem); ret = drm_gem_shmem_get_pages(shmem);
if (ret) { if (ret) {
drm_gem_vm_close(vma); drm_gem_vm_close(vma);
@ -636,15 +627,13 @@ EXPORT_SYMBOL_GPL(drm_gem_shmem_mmap);
/** /**
* drm_gem_shmem_print_info() - Print &drm_gem_shmem_object info for debugfs * drm_gem_shmem_print_info() - Print &drm_gem_shmem_object info for debugfs
* @shmem: shmem GEM object
* @p: DRM printer * @p: DRM printer
* @indent: Tab indentation level * @indent: Tab indentation level
* @obj: GEM object
*/ */
void drm_gem_shmem_print_info(struct drm_printer *p, unsigned int indent, void drm_gem_shmem_print_info(const struct drm_gem_shmem_object *shmem,
const struct drm_gem_object *obj) struct drm_printer *p, unsigned int indent)
{ {
const struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
drm_printf_indent(p, indent, "pages_use_count=%u\n", shmem->pages_use_count); drm_printf_indent(p, indent, "pages_use_count=%u\n", shmem->pages_use_count);
drm_printf_indent(p, indent, "vmap_use_count=%u\n", shmem->vmap_use_count); drm_printf_indent(p, indent, "vmap_use_count=%u\n", shmem->vmap_use_count);
drm_printf_indent(p, indent, "vaddr=%p\n", shmem->vaddr); drm_printf_indent(p, indent, "vaddr=%p\n", shmem->vaddr);
@ -654,7 +643,7 @@ EXPORT_SYMBOL(drm_gem_shmem_print_info);
/** /**
* drm_gem_shmem_get_sg_table - Provide a scatter/gather table of pinned * drm_gem_shmem_get_sg_table - Provide a scatter/gather table of pinned
* pages for a shmem GEM object * pages for a shmem GEM object
* @obj: GEM object * @shmem: shmem GEM object
* *
* This function exports a scatter/gather table suitable for PRIME usage by * This function exports a scatter/gather table suitable for PRIME usage by
* calling the standard DMA mapping API. * calling the standard DMA mapping API.
@ -665,9 +654,9 @@ EXPORT_SYMBOL(drm_gem_shmem_print_info);
* Returns: * Returns:
* A pointer to the scatter/gather table of pinned pages or NULL on failure. * A pointer to the scatter/gather table of pinned pages or NULL on failure.
*/ */
struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_object *obj) struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_shmem_object *shmem)
{ {
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); struct drm_gem_object *obj = &shmem->base;
WARN_ON(shmem->base.import_attach); WARN_ON(shmem->base.import_attach);
@ -678,7 +667,7 @@ EXPORT_SYMBOL_GPL(drm_gem_shmem_get_sg_table);
/** /**
* drm_gem_shmem_get_pages_sgt - Pin pages, dma map them, and return a * drm_gem_shmem_get_pages_sgt - Pin pages, dma map them, and return a
* scatter/gather table for a shmem GEM object. * scatter/gather table for a shmem GEM object.
* @obj: GEM object * @shmem: shmem GEM object
* *
* This function returns a scatter/gather table suitable for driver usage. If * This function returns a scatter/gather table suitable for driver usage. If
* the sg table doesn't exist, the pages are pinned, dma-mapped, and a sg * the sg table doesn't exist, the pages are pinned, dma-mapped, and a sg
@ -691,10 +680,10 @@ EXPORT_SYMBOL_GPL(drm_gem_shmem_get_sg_table);
* Returns: * Returns:
* A pointer to the scatter/gather table of pinned pages or errno on failure. * A pointer to the scatter/gather table of pinned pages or errno on failure.
*/ */
struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_object *obj) struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_shmem_object *shmem)
{ {
struct drm_gem_object *obj = &shmem->base;
int ret; int ret;
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
struct sg_table *sgt; struct sg_table *sgt;
if (shmem->sgt) if (shmem->sgt)
@ -706,7 +695,7 @@ struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_object *obj)
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
sgt = drm_gem_shmem_get_sg_table(&shmem->base); sgt = drm_gem_shmem_get_sg_table(shmem);
if (IS_ERR(sgt)) { if (IS_ERR(sgt)) {
ret = PTR_ERR(sgt); ret = PTR_ERR(sgt);
goto err_put_pages; goto err_put_pages;

View File

@ -127,7 +127,7 @@ int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
if (err) if (err)
goto out; goto out;
} else { } else {
struct sg_table *sgt = drm_gem_shmem_get_pages_sgt(obj); struct sg_table *sgt = drm_gem_shmem_get_pages_sgt(shmem);
if (IS_ERR(sgt)) { if (IS_ERR(sgt)) {
err = PTR_ERR(sgt); err = PTR_ERR(sgt);
@ -151,7 +151,7 @@ static void lima_gem_free_object(struct drm_gem_object *obj)
if (!list_empty(&bo->va)) if (!list_empty(&bo->va))
dev_err(obj->dev->dev, "lima gem free bo still has va\n"); dev_err(obj->dev->dev, "lima gem free bo still has va\n");
drm_gem_shmem_free_object(obj); drm_gem_shmem_free(&bo->base);
} }
static int lima_gem_object_open(struct drm_gem_object *obj, struct drm_file *file) static int lima_gem_object_open(struct drm_gem_object *obj, struct drm_file *file)
@ -179,7 +179,7 @@ static int lima_gem_pin(struct drm_gem_object *obj)
if (bo->heap_size) if (bo->heap_size)
return -EINVAL; return -EINVAL;
return drm_gem_shmem_pin(obj); return drm_gem_shmem_pin(&bo->base);
} }
static int lima_gem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) static int lima_gem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)
@ -189,7 +189,7 @@ static int lima_gem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)
if (bo->heap_size) if (bo->heap_size)
return -EINVAL; return -EINVAL;
return drm_gem_shmem_vmap(obj, map); return drm_gem_shmem_vmap(&bo->base, map);
} }
static int lima_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) static int lima_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
@ -199,7 +199,7 @@ static int lima_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
if (bo->heap_size) if (bo->heap_size)
return -EINVAL; return -EINVAL;
return drm_gem_shmem_mmap(obj, vma); return drm_gem_shmem_mmap(&bo->base, vma);
} }
static const struct drm_gem_object_funcs lima_gem_funcs = { static const struct drm_gem_object_funcs lima_gem_funcs = {

View File

@ -371,7 +371,7 @@ static void lima_sched_build_error_task_list(struct lima_sched_task *task)
} else { } else {
buffer_chunk->size = lima_bo_size(bo); buffer_chunk->size = lima_bo_size(bo);
ret = drm_gem_shmem_vmap(&bo->base.base, &map); ret = drm_gem_shmem_vmap(&bo->base, &map);
if (ret) { if (ret) {
kvfree(et); kvfree(et);
goto out; goto out;
@ -379,7 +379,7 @@ static void lima_sched_build_error_task_list(struct lima_sched_task *task)
memcpy(buffer_chunk + 1, map.vaddr, buffer_chunk->size); memcpy(buffer_chunk + 1, map.vaddr, buffer_chunk->size);
drm_gem_shmem_vunmap(&bo->base.base, &map); drm_gem_shmem_vunmap(&bo->base, &map);
} }
buffer_chunk = (void *)(buffer_chunk + 1) + buffer_chunk->size; buffer_chunk = (void *)(buffer_chunk + 1) + buffer_chunk->size;

View File

@ -427,7 +427,7 @@ static int panfrost_ioctl_madvise(struct drm_device *dev, void *data,
} }
} }
args->retained = drm_gem_shmem_madvise(gem_obj, args->madv); args->retained = drm_gem_shmem_madvise(&bo->base, args->madv);
if (args->retained) { if (args->retained) {
if (args->madv == PANFROST_MADV_DONTNEED) if (args->madv == PANFROST_MADV_DONTNEED)

View File

@ -49,7 +49,7 @@ static void panfrost_gem_free_object(struct drm_gem_object *obj)
kvfree(bo->sgts); kvfree(bo->sgts);
} }
drm_gem_shmem_free_object(obj); drm_gem_shmem_free(&bo->base);
} }
struct panfrost_gem_mapping * struct panfrost_gem_mapping *
@ -187,10 +187,12 @@ void panfrost_gem_close(struct drm_gem_object *obj, struct drm_file *file_priv)
static int panfrost_gem_pin(struct drm_gem_object *obj) static int panfrost_gem_pin(struct drm_gem_object *obj)
{ {
if (to_panfrost_bo(obj)->is_heap) struct panfrost_gem_object *bo = to_panfrost_bo(obj);
if (bo->is_heap)
return -EINVAL; return -EINVAL;
return drm_gem_shmem_pin(obj); return drm_gem_shmem_pin(&bo->base);
} }
static const struct drm_gem_object_funcs panfrost_gem_funcs = { static const struct drm_gem_object_funcs panfrost_gem_funcs = {

View File

@ -52,7 +52,7 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj)
goto unlock_mappings; goto unlock_mappings;
panfrost_gem_teardown_mappings_locked(bo); panfrost_gem_teardown_mappings_locked(bo);
drm_gem_shmem_purge_locked(obj); drm_gem_shmem_purge_locked(&bo->base);
ret = true; ret = true;
mutex_unlock(&shmem->pages_lock); mutex_unlock(&shmem->pages_lock);

View File

@ -304,7 +304,8 @@ static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu,
int panfrost_mmu_map(struct panfrost_gem_mapping *mapping) int panfrost_mmu_map(struct panfrost_gem_mapping *mapping)
{ {
struct panfrost_gem_object *bo = mapping->obj; struct panfrost_gem_object *bo = mapping->obj;
struct drm_gem_object *obj = &bo->base.base; struct drm_gem_shmem_object *shmem = &bo->base;
struct drm_gem_object *obj = &shmem->base;
struct panfrost_device *pfdev = to_panfrost_device(obj->dev); struct panfrost_device *pfdev = to_panfrost_device(obj->dev);
struct sg_table *sgt; struct sg_table *sgt;
int prot = IOMMU_READ | IOMMU_WRITE; int prot = IOMMU_READ | IOMMU_WRITE;
@ -315,7 +316,7 @@ int panfrost_mmu_map(struct panfrost_gem_mapping *mapping)
if (bo->noexec) if (bo->noexec)
prot |= IOMMU_NOEXEC; prot |= IOMMU_NOEXEC;
sgt = drm_gem_shmem_get_pages_sgt(obj); sgt = drm_gem_shmem_get_pages_sgt(shmem);
if (WARN_ON(IS_ERR(sgt))) if (WARN_ON(IS_ERR(sgt)))
return PTR_ERR(sgt); return PTR_ERR(sgt);

View File

@ -105,7 +105,7 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,
goto err_close_bo; goto err_close_bo;
} }
ret = drm_gem_shmem_vmap(&bo->base, &map); ret = drm_gem_shmem_vmap(bo, &map);
if (ret) if (ret)
goto err_put_mapping; goto err_put_mapping;
perfcnt->buf = map.vaddr; perfcnt->buf = map.vaddr;
@ -164,7 +164,7 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,
return 0; return 0;
err_vunmap: err_vunmap:
drm_gem_shmem_vunmap(&bo->base, &map); drm_gem_shmem_vunmap(bo, &map);
err_put_mapping: err_put_mapping:
panfrost_gem_mapping_put(perfcnt->mapping); panfrost_gem_mapping_put(perfcnt->mapping);
err_close_bo: err_close_bo:
@ -194,7 +194,7 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,
GPU_PERFCNT_CFG_MODE(GPU_PERFCNT_CFG_MODE_OFF)); GPU_PERFCNT_CFG_MODE(GPU_PERFCNT_CFG_MODE_OFF));
perfcnt->user = NULL; perfcnt->user = NULL;
drm_gem_shmem_vunmap(&perfcnt->mapping->obj->base.base, &map); drm_gem_shmem_vunmap(&perfcnt->mapping->obj->base, &map);
perfcnt->buf = NULL; perfcnt->buf = NULL;
panfrost_gem_close(&perfcnt->mapping->obj->base.base, file_priv); panfrost_gem_close(&perfcnt->mapping->obj->base.base, file_priv);
panfrost_mmu_as_put(pfdev, perfcnt->mapping->mmu); panfrost_mmu_as_put(pfdev, perfcnt->mapping->mmu);

View File

@ -47,7 +47,7 @@ void v3d_free_object(struct drm_gem_object *obj)
/* GPU execution may have dirtied any pages in the BO. */ /* GPU execution may have dirtied any pages in the BO. */
bo->base.pages_mark_dirty_on_put = true; bo->base.pages_mark_dirty_on_put = true;
drm_gem_shmem_free_object(obj); drm_gem_shmem_free(&bo->base);
} }
static const struct drm_gem_object_funcs v3d_gem_funcs = { static const struct drm_gem_object_funcs v3d_gem_funcs = {
@ -95,7 +95,7 @@ v3d_bo_create_finish(struct drm_gem_object *obj)
/* So far we pin the BO in the MMU for its lifetime, so use /* So far we pin the BO in the MMU for its lifetime, so use
* shmem's helper for getting a lifetime sgt. * shmem's helper for getting a lifetime sgt.
*/ */
sgt = drm_gem_shmem_get_pages_sgt(&bo->base.base); sgt = drm_gem_shmem_get_pages_sgt(&bo->base);
if (IS_ERR(sgt)) if (IS_ERR(sgt))
return PTR_ERR(sgt); return PTR_ERR(sgt);
@ -141,7 +141,7 @@ struct v3d_bo *v3d_bo_create(struct drm_device *dev, struct drm_file *file_priv,
return bo; return bo;
free_obj: free_obj:
drm_gem_shmem_free_object(&shmem_obj->base); drm_gem_shmem_free(shmem_obj);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
@ -159,7 +159,7 @@ v3d_prime_import_sg_table(struct drm_device *dev,
ret = v3d_bo_create_finish(obj); ret = v3d_bo_create_finish(obj);
if (ret) { if (ret) {
drm_gem_shmem_free_object(obj); drm_gem_shmem_free(&to_v3d_bo(obj)->base);
return ERR_PTR(ret); return ERR_PTR(ret);
} }

View File

@ -79,10 +79,10 @@ void virtio_gpu_cleanup_object(struct virtio_gpu_object *bo)
sg_free_table(shmem->pages); sg_free_table(shmem->pages);
kfree(shmem->pages); kfree(shmem->pages);
shmem->pages = NULL; shmem->pages = NULL;
drm_gem_shmem_unpin(&bo->base.base); drm_gem_shmem_unpin(&bo->base);
} }
drm_gem_shmem_free_object(&bo->base.base); drm_gem_shmem_free(&bo->base);
} else if (virtio_gpu_is_vram(bo)) { } else if (virtio_gpu_is_vram(bo)) {
struct virtio_gpu_object_vram *vram = to_virtio_gpu_vram(bo); struct virtio_gpu_object_vram *vram = to_virtio_gpu_vram(bo);
@ -156,7 +156,7 @@ static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
struct scatterlist *sg; struct scatterlist *sg;
int si, ret; int si, ret;
ret = drm_gem_shmem_pin(&bo->base.base); ret = drm_gem_shmem_pin(&bo->base);
if (ret < 0) if (ret < 0)
return -EINVAL; return -EINVAL;
@ -166,9 +166,9 @@ static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
* dma-ops. This is discouraged for other drivers, but should be fine * dma-ops. This is discouraged for other drivers, but should be fine
* since virtio_gpu doesn't support dma-buf import from other devices. * since virtio_gpu doesn't support dma-buf import from other devices.
*/ */
shmem->pages = drm_gem_shmem_get_sg_table(&bo->base.base); shmem->pages = drm_gem_shmem_get_sg_table(&bo->base);
if (!shmem->pages) { if (!shmem->pages) {
drm_gem_shmem_unpin(&bo->base.base); drm_gem_shmem_unpin(&bo->base);
return -EINVAL; return -EINVAL;
} }
@ -276,6 +276,6 @@ err_put_objs:
err_put_id: err_put_id:
virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle); virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
err_free_gem: err_free_gem:
drm_gem_shmem_free_object(&shmem_obj->base); drm_gem_shmem_free(shmem_obj);
return ret; return ret;
} }

View File

@ -107,16 +107,17 @@ struct drm_gem_shmem_object {
container_of(obj, struct drm_gem_shmem_object, base) container_of(obj, struct drm_gem_shmem_object, base)
struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t size); struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t size);
void drm_gem_shmem_free_object(struct drm_gem_object *obj); void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem);
int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem); int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem);
void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem); void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem);
int drm_gem_shmem_pin(struct drm_gem_object *obj); int drm_gem_shmem_pin(struct drm_gem_shmem_object *shmem);
void drm_gem_shmem_unpin(struct drm_gem_object *obj); void drm_gem_shmem_unpin(struct drm_gem_shmem_object *shmem);
int drm_gem_shmem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map); int drm_gem_shmem_vmap(struct drm_gem_shmem_object *shmem, struct dma_buf_map *map);
void drm_gem_shmem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map); void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem, struct dma_buf_map *map);
int drm_gem_shmem_mmap(struct drm_gem_shmem_object *shmem, struct vm_area_struct *vma);
int drm_gem_shmem_madvise(struct drm_gem_object *obj, int madv); int drm_gem_shmem_madvise(struct drm_gem_shmem_object *shmem, int madv);
static inline bool drm_gem_shmem_is_purgeable(struct drm_gem_shmem_object *shmem) static inline bool drm_gem_shmem_is_purgeable(struct drm_gem_shmem_object *shmem)
{ {
@ -125,33 +126,31 @@ static inline bool drm_gem_shmem_is_purgeable(struct drm_gem_shmem_object *shmem
!shmem->base.dma_buf && !shmem->base.import_attach; !shmem->base.dma_buf && !shmem->base.import_attach;
} }
void drm_gem_shmem_purge_locked(struct drm_gem_object *obj); void drm_gem_shmem_purge_locked(struct drm_gem_shmem_object *shmem);
bool drm_gem_shmem_purge(struct drm_gem_object *obj); bool drm_gem_shmem_purge(struct drm_gem_shmem_object *shmem);
int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev, struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_shmem_object *shmem);
struct drm_mode_create_dumb *args); struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_shmem_object *shmem);
int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma); void drm_gem_shmem_print_info(const struct drm_gem_shmem_object *shmem,
struct drm_printer *p, unsigned int indent);
void drm_gem_shmem_print_info(struct drm_printer *p, unsigned int indent,
const struct drm_gem_object *obj);
struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_object *obj);
/* /*
* GEM object functions * GEM object functions
*/ */
/** /**
* drm_gem_shmem_object_free - GEM object function for drm_gem_shmem_free_object() * drm_gem_shmem_object_free - GEM object function for drm_gem_shmem_free()
* @obj: GEM object to free * @obj: GEM object to free
* *
* This function wraps drm_gem_shmem_free_object(). Drivers that employ the shmem helpers * This function wraps drm_gem_shmem_free(). Drivers that employ the shmem helpers
* should use it as their &drm_gem_object_funcs.free handler. * should use it as their &drm_gem_object_funcs.free handler.
*/ */
static inline void drm_gem_shmem_object_free(struct drm_gem_object *obj) static inline void drm_gem_shmem_object_free(struct drm_gem_object *obj)
{ {
drm_gem_shmem_free_object(obj); struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
drm_gem_shmem_free(shmem);
} }
/** /**
@ -166,7 +165,9 @@ static inline void drm_gem_shmem_object_free(struct drm_gem_object *obj)
static inline void drm_gem_shmem_object_print_info(struct drm_printer *p, unsigned int indent, static inline void drm_gem_shmem_object_print_info(struct drm_printer *p, unsigned int indent,
const struct drm_gem_object *obj) const struct drm_gem_object *obj)
{ {
drm_gem_shmem_print_info(p, indent, obj); const struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
drm_gem_shmem_print_info(shmem, p, indent);
} }
/** /**
@ -178,7 +179,9 @@ static inline void drm_gem_shmem_object_print_info(struct drm_printer *p, unsign
*/ */
static inline int drm_gem_shmem_object_pin(struct drm_gem_object *obj) static inline int drm_gem_shmem_object_pin(struct drm_gem_object *obj)
{ {
return drm_gem_shmem_pin(obj); struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
return drm_gem_shmem_pin(shmem);
} }
/** /**
@ -190,7 +193,9 @@ static inline int drm_gem_shmem_object_pin(struct drm_gem_object *obj)
*/ */
static inline void drm_gem_shmem_object_unpin(struct drm_gem_object *obj) static inline void drm_gem_shmem_object_unpin(struct drm_gem_object *obj)
{ {
drm_gem_shmem_unpin(obj); struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
drm_gem_shmem_unpin(shmem);
} }
/** /**
@ -205,7 +210,9 @@ static inline void drm_gem_shmem_object_unpin(struct drm_gem_object *obj)
*/ */
static inline struct sg_table *drm_gem_shmem_object_get_sg_table(struct drm_gem_object *obj) static inline struct sg_table *drm_gem_shmem_object_get_sg_table(struct drm_gem_object *obj)
{ {
return drm_gem_shmem_get_sg_table(obj); struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
return drm_gem_shmem_get_sg_table(shmem);
} }
/* /*
@ -221,7 +228,9 @@ static inline struct sg_table *drm_gem_shmem_object_get_sg_table(struct drm_gem_
*/ */
static inline int drm_gem_shmem_object_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) static inline int drm_gem_shmem_object_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)
{ {
return drm_gem_shmem_vmap(obj, map); struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
return drm_gem_shmem_vmap(shmem, map);
} }
/* /*
@ -234,7 +243,9 @@ static inline int drm_gem_shmem_object_vmap(struct drm_gem_object *obj, struct d
*/ */
static inline void drm_gem_shmem_object_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map) static inline void drm_gem_shmem_object_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map)
{ {
drm_gem_shmem_vunmap(obj, map); struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
drm_gem_shmem_vunmap(shmem, map);
} }
/** /**
@ -250,7 +261,9 @@ static inline void drm_gem_shmem_object_vunmap(struct drm_gem_object *obj, struc
*/ */
static inline int drm_gem_shmem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) static inline int drm_gem_shmem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
{ {
return drm_gem_shmem_mmap(obj, vma); struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
return drm_gem_shmem_mmap(shmem, vma);
} }
/* /*
@ -261,8 +274,8 @@ struct drm_gem_object *
drm_gem_shmem_prime_import_sg_table(struct drm_device *dev, drm_gem_shmem_prime_import_sg_table(struct drm_device *dev,
struct dma_buf_attachment *attach, struct dma_buf_attachment *attach,
struct sg_table *sgt); struct sg_table *sgt);
int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_object *obj); struct drm_mode_create_dumb *args);
/** /**
* DRM_GEM_SHMEM_DRIVER_OPS - Default shmem GEM operations * DRM_GEM_SHMEM_DRIVER_OPS - Default shmem GEM operations