drm/i915: Implement dma-buf mmap() on systems with LLC
Subsystems (2)
PATCH 1/1 drm/i915: Implement dma-buf mmap() on systems with LLC
From: Rob Bradford <[email protected]>
The LLC check echoes the check made by i915_gem_fault() which will handle the mapping the pages through the GTT.
The aim is that this is functionally equivalent to using the I915_GEM_MMAP_GTT ioctl and then mmaping using the offset returned.
--- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +19 -1
@@ -197,7 +197,25 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_nstatic int i915_gem_dmabuf_mmap (struct dma_buf *dma_buf,struct vm_area_struct *vma) { -return -EINVAL ; +struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf); +struct drm_device *dev = obj->base.dev; +int ret; + +if (!HAS_LLC (dev)) +return -EINVAL ; + + ret =i915_mutex_lock_interruptible (dev); +if (ret) + goto unlock; + + ret =drm_gem_mmap_obj (&obj->base,vma_pages (vma) <<PAGE_SHIFT , vma); + +if (ret) + goto unlock; + +unlock: +mutex_unlock (&dev->struct_mutex); +return ret; }static int i915_gem_begin_cpu_access (struct dma_buf *dma_buf,size_t start,size_t length,enum dma_data_direction direction)
Signature · 1 line
1.8.3.1
Quoted 24 lines · Rob Bradford
From: Rob Bradford <[email protected]>
The LLC check echoes the check made by
i915_gem_fault()which will handle the mapping the pages through the GTT.The aim is that this is functionally equivalent to using the
I915_GEM_MMAP_GTTioctl and then mmaping using the offset returned.Signed-off-by Rob Bradford <[email protected]>--- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/i915_gem_dmabuf.c +2
-1@@ -197,7 +197,25 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_nstatic int i915_gem_dmabuf_mmap (struct dma_buf *dma_buf,struct vm_area_struct *vma) { -return -EINVAL ; +struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf); +struct drm_device *dev = obj->base.dev;
drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n · line 211
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +10
-0+int ret; + +if (!HAS_LLC (dev)) +return -EINVAL ; + + ret =i915_mutex_lock_interruptible (dev); +if (ret) + goto unlock; + + ret =drm_gem_mmap_obj (&obj->base,vma_pages (vma) <<PAGE_SHIFT , vma);
The gtt memory mapping you're forwarding here to is actually always coherent, so the LLC test is redundant. The only issue is if you try to gtt mmap a coherent BO on pre-snb, iirc that can hang.
Another thing is the pte shootdown. I think to make that work you need to frob the vma -> mapping association a bit so that unmap_mapping_range works correctly. A testcase which dma-buf mmaps more data than we have cpu accessible gtt space should easily hit this.
Which brings up the last bit: This needs a prime_mmap testcase in igt ...
Cheers, Daniel
Quoted 17 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +7
-0+ +if (ret) + goto unlock; + +unlock: +mutex_unlock (&dev->struct_mutex); +return ret; }static int i915_gem_begin_cpu_access (struct dma_buf *dma_buf,size_t start,size_t length,enum dma_data_direction direction)Signature · 6 lines
1.8.3.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch