[PATCH 10/10] dmabuf-sync

Chris Wilson chris at chris-wilson.co.uk
Fri Jan 1 22:24:39 UTC 2021


---
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 44 +++++++++++-----------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
index 04e9c04545ad..4d78a988f7f1 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
@@ -119,47 +119,49 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *
 	return 0;
 }
 
-static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction)
+static int cpu_sync(struct drm_i915_gem_object *obj, unsigned int flags)
 {
-	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
-	bool write = (direction == DMA_BIDIRECTIONAL || direction == DMA_TO_DEVICE);
 	int err;
 
 	err = i915_gem_object_pin_pages(obj);
 	if (err)
 		return err;
 
-	err = i915_gem_object_lock_interruptible(obj, NULL);
-	if (err)
-		goto out;
+	if ((obj->cache_coherent & flags) != flags)
+		drm_clflush_sg(obj->mm.pages);
 
-	err = i915_gem_object_set_to_cpu_domain(obj, write);
-	i915_gem_object_unlock(obj);
-
-out:
 	i915_gem_object_unpin_pages(obj);
-	return err;
+	return 0;
+}
+
+static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction)
+{
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
+
+	if (direction == DMA_BIDIRECTIONAL || direction == DMA_TO_DEVICE)
+		i915_gem_object_invalidate_frontbuffer(obj, ORIGIN_CPU);
+
+	return cpu_sync(obj, I915_BO_CACHE_COHERENT_FOR_READ);
 }
 
 static int i915_gem_end_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction)
 {
 	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
+	unsigned int flags;
 	int err;
 
-	err = i915_gem_object_pin_pages(obj);
-	if (err)
-		return err;
+	flags = I915_BO_CACHE_COHERENT_FOR_READ;
+	if (direction == DMA_BIDIRECTIONAL || direction == DMA_TO_DEVICE)
+		flags |= I915_BO_CACHE_COHERENT_FOR_WRITE;
 
-	err = i915_gem_object_lock_interruptible(obj, NULL);
+	err = cpu_sync(obj, flags);
 	if (err)
-		goto out;
+		return err;
 
-	err = i915_gem_object_set_to_gtt_domain(obj, false);
-	i915_gem_object_unlock(obj);
+	if (flags & I915_BO_CACHE_COHERENT_FOR_WRITE)
+		i915_gem_object_flush_frontbuffer(obj, ORIGIN_CPU);
 
-out:
-	i915_gem_object_unpin_pages(obj);
-	return err;
+	return 0;
 }
 
 static const struct dma_buf_ops i915_dmabuf_ops =  {
-- 
2.20.1



More information about the Intel-gfx-trybot mailing list