[PATCH 1/2] drm/shmem: add support for per object dma api operations
Gurchetan Singh
gurchetansingh at chromium.org
Fri Jun 12 01:36:24 UTC 2020
This is useful for the next patch. Also, should we only unmap the
amount entries that we mapped with the dma-api?
Signed-off-by: Gurchetan Singh <gurchetansingh at chromium.org>
---
drivers/gpu/drm/drm_gem_shmem_helper.c | 16 +++++++++++-----
include/drm/drm_gem_shmem_helper.h | 10 ++++++++++
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index 0a7e3b664bc2..d439074ad7b5 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -124,8 +124,10 @@ void drm_gem_shmem_free_object(struct drm_gem_object *obj)
drm_prime_gem_destroy(obj, shmem->sgt);
} else {
if (shmem->sgt) {
- dma_unmap_sg(obj->dev->dev, shmem->sgt->sgl,
- shmem->sgt->nents, DMA_BIDIRECTIONAL);
+ if (!shmem->skip_dma_api)
+ dma_unmap_sg(obj->dev->dev, shmem->sgt->sgl,
+ shmem->dma_map_count,
+ DMA_BIDIRECTIONAL);
sg_free_table(shmem->sgt);
kfree(shmem->sgt);
}
@@ -422,8 +424,9 @@ void drm_gem_shmem_purge_locked(struct drm_gem_object *obj)
WARN_ON(!drm_gem_shmem_is_purgeable(shmem));
- dma_unmap_sg(obj->dev->dev, shmem->sgt->sgl,
- shmem->sgt->nents, DMA_BIDIRECTIONAL);
+ if (!shmem->skip_dma_api)
+ dma_unmap_sg(obj->dev->dev, shmem->sgt->sgl,
+ shmem->dma_map_count, DMA_BIDIRECTIONAL);
sg_free_table(shmem->sgt);
kfree(shmem->sgt);
shmem->sgt = NULL;
@@ -695,7 +698,10 @@ struct sg_table *drm_gem_shmem_get_pages_sgt(struct drm_gem_object *obj)
goto err_put_pages;
}
/* Map the pages for use by the h/w. */
- dma_map_sg(obj->dev->dev, sgt->sgl, sgt->nents, DMA_BIDIRECTIONAL);
+ if (!shmem->skip_dma_api)
+ shmem->dma_map_count = dma_map_sg(obj->dev->dev, sgt->sgl,
+ sgt->nents,
+ DMA_BIDIRECTIONAL);
shmem->sgt = sgt;
diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h
index 5381f0c8cf6f..2669d87cbfdd 100644
--- a/include/drm/drm_gem_shmem_helper.h
+++ b/include/drm/drm_gem_shmem_helper.h
@@ -101,6 +101,16 @@ struct drm_gem_shmem_object {
* @map_cached: map object cached (instead of using writecombine).
*/
bool map_cached;
+
+ /**
+ * @skip_dma_api: skip using dma api in certain places.
+ */
+ bool skip_dma_api;
+
+ /**
+ * @skip_dma_api: number of pages mapped by dma-api.
+ */
+ bool dma_map_count;
};
#define to_drm_gem_shmem_obj(obj) \
--
2.25.1
More information about the dri-devel
mailing list