panfrost_gem_sync() has the same code as the function drm_gem_shmem_sync().
Translate the UAPI sync type to the common shmem type and use the shmem
helper instead.

Signed-off-by: Maíra Canal <[email protected]>
---
 drivers/gpu/drm/panfrost/panfrost_gem.c | 74 +++------------------------------
 1 file changed, 5 insertions(+), 69 deletions(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c 
b/drivers/gpu/drm/panfrost/panfrost_gem.c
index 5f099c478edd..80a4a1771ce7 100644
--- a/drivers/gpu/drm/panfrost/panfrost_gem.c
+++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
@@ -460,84 +460,20 @@ int
 panfrost_gem_sync(struct drm_gem_object *obj, u32 type, u32 offset, u32 size)
 {
        struct panfrost_gem_object *bo = to_panfrost_bo(obj);
-       struct drm_gem_shmem_object *shmem = &bo->base;
-       const struct drm_device *dev = shmem->base.dev;
-       struct sg_table *sgt;
-       struct scatterlist *sgl;
-       unsigned int count;
-
-       /* Make sure the range is in bounds. */
-       if (offset + size < offset || offset + size > shmem->base.size)
-               return -EINVAL;
-
-       /* Disallow CPU-cache maintenance on imported buffers. */
-       if (drm_gem_is_imported(&shmem->base))
-               return -EINVAL;
+       enum drm_gem_shmem_sync_type shmem_type;
 
        switch (type) {
        case PANFROST_BO_SYNC_CPU_CACHE_FLUSH:
+               shmem_type = DRM_GEM_SHMEM_SYNC_CPU_CACHE_FLUSH;
+               break;
        case PANFROST_BO_SYNC_CPU_CACHE_FLUSH_AND_INVALIDATE:
+               shmem_type = DRM_GEM_SHMEM_SYNC_CPU_CACHE_FLUSH_AND_INVALIDATE;
                break;
-
        default:
                return -EINVAL;
        }
 
-       /* Don't bother if it's WC-mapped */
-       if (shmem->map_wc)
-               return 0;
-
-       /* Nothing to do if the size is zero. */
-       if (size == 0)
-               return 0;
-
-       sgt = drm_gem_shmem_get_pages_sgt(shmem);
-       if (IS_ERR(sgt))
-               return PTR_ERR(sgt);
-
-       for_each_sgtable_dma_sg(sgt, sgl, count) {
-               if (size == 0)
-                       break;
-
-               dma_addr_t paddr = sg_dma_address(sgl);
-               size_t len = sg_dma_len(sgl);
-
-               if (len <= offset) {
-                       offset -= len;
-                       continue;
-               }
-
-               paddr += offset;
-               len -= offset;
-               len = min_t(size_t, len, size);
-               size -= len;
-               offset = 0;
-
-               /* It's unclear whether dma_sync_xxx() is the right API to do 
CPU
-                * cache maintenance given an IOMMU can register their own
-                * implementation doing more than just CPU cache 
flushes/invalidation,
-                * and what we really care about here is CPU caches only, but 
that's
-                * the best we have that is both arch-agnostic and does at 
least the
-                * CPU cache maintenance on a <page,offset,size> tuple.
-                *
-                * Also, I wish we could do a single
-                *
-                *      dma_sync_single_for_device(BIDIR)
-                *
-                * and get a flush+invalidate, but that's not how it's 
implemented
-                * in practice (at least on arm64), so we have to make it
-                *
-                *      dma_sync_single_for_device(TO_DEVICE)
-                *      dma_sync_single_for_cpu(FROM_DEVICE)
-                *
-                * for the flush+invalidate case.
-                */
-               dma_sync_single_for_device(dev->dev, paddr, len, DMA_TO_DEVICE);
-               if (type == PANFROST_BO_SYNC_CPU_CACHE_FLUSH_AND_INVALIDATE)
-                       dma_sync_single_for_cpu(dev->dev, paddr, len, 
DMA_FROM_DEVICE);
-       }
-
-       return 0;
+       return drm_gem_shmem_sync(&bo->base, offset, size, shmem_type);
 }
 
 void

-- 
2.56.0

Reply via email to