[PATCH 10/10] dmabuf-sync

Chris Wilson chris at chris-wilson.co.uk
Fri Jan 1 16:45:16 UTC 2021


---
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 39 +++++++++-------------
 1 file changed, 15 insertions(+), 24 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..61b8a2e39dbc 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
@@ -119,47 +119,38 @@ 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_end_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction)
+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);
-	int err;
 
-	err = i915_gem_object_pin_pages(obj);
-	if (err)
-		return err;
+	return cpu_sync(obj, I915_BO_CACHE_COHERENT_FOR_READ);
+}
 
-	err = i915_gem_object_lock_interruptible(obj, NULL);
-	if (err)
-		goto out;
+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;
 
-	err = i915_gem_object_set_to_gtt_domain(obj, false);
-	i915_gem_object_unlock(obj);
+	flags = I915_BO_CACHE_COHERENT_FOR_READ;
+	if (direction == DMA_BIDIRECTIONAL || direction == DMA_TO_DEVICE)
+		flags |= I915_BO_CACHE_COHERENT_FOR_WRITE;
 
-out:
-	i915_gem_object_unpin_pages(obj);
-	return err;
+	return cpu_sync(obj, flags);
 }
 
 static const struct dma_buf_ops i915_dmabuf_ops =  {
-- 
2.20.1



More information about the Intel-gfx-trybot mailing list