drm/i915: Implement dma-buf mmap() for userspace access
Subsystems (2)
PATCH v3 1/1 drm/i915: Implement dma-buf mmap() for userspace access
From: Rob Bradford <[email protected]>
The aim is that this is functionally equivalent to using the I915_GEM_MMAP ioctl.
v2: Add aperture check limit, limit to SNB+ and improve error handling.
v3 (anderco): Map without using the GTT.
--- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +18 -1
@@ -193,7 +193,24 @@ 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; +struct drm_i915_private *dev_priv = dev->dev_private; +int ret; + +if (INTEL_INFO (dev)->gen <6 ) +return -EINVAL ; + + ret =i915_mutex_lock_interruptible (dev); +if (ret) +return ret; + + ret = obj->base.filp->f_op->mmap (obj->base.filp, vma); +fput (vma->vm_file); + vma->vm_file =get_file (obj->base.filp); + +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.2
Quoted 8 lines · Ander Conselvan de Oliveira
From: Rob Bradford <[email protected]>
The aim is that this is functionally equivalent to using the
I915_GEM_MMAPioctl.v2: Add aperture check limit, limit to SNB+ and improve error handling.
v3 (anderco): Map without using the GTT.
Why that? This means you'll have a non-coherent mapping and atm dma-buf doesn't expose and invalidate/flushing ioctls. Which really you want for this.
-Daniel
Quoted 44 lines
Signed-off-by Rob Bradford <[email protected]>Signed-off-by Ander Conselvan de Oliveira <[email protected]>--- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/i915_gem_dmabuf.c +18
-1@@ -193,7 +193,24 @@ 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; +struct drm_i915_private *dev_priv = dev->dev_private; +int ret; + +if (INTEL_INFO (dev)->gen <6 ) +return -EINVAL ; + + ret =i915_mutex_lock_interruptible (dev); +if (ret) +return ret; + + ret = obj->base.filp->f_op->mmap (obj->base.filp, vma); +fput (vma->vm_file); + vma->vm_file =get_file (obj->base.filp); + +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.2 _______________________________________________ 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
Quoted 6 lines · Daniel Vetter
Quoted 5 lines · Ander Conselvan de Oliveira
From: Rob Bradford <[email protected]>
The aim is that this is functionally equivalent to using the
I915_GEM_MMAPioctl.
Quoted 7 lines
Quoted 3 lines
v2: Add aperture check limit, limit to SNB+ and improve error handling.
v3 (anderco): Map without using the GTT.
Why that? This means you'll have a non-coherent mapping and atm dma-buf doesn't expose and invalidate/flushing ioctls. Which really you want for this.
Hmm. I completely overlooked that important detail. In a discussion with Rob, we came to the conclusion we didn't want to use the GTT because of the performance penalty. Now I see that just modifying the mmap() support is not enough.
Thanks,
Ander
Quoted 47 lines
-Daniel
Quoted 44 lines
Signed-off-by Rob Bradford <[email protected]>Signed-off-by Ander Conselvan de Oliveira <[email protected]>--- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/i915_gem_dmabuf.c +18
-2@@ -193,7 +193,24 @@ 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; +struct drm_i915_private *dev_priv = dev->dev_private; +int ret; + +if (INTEL_INFO (dev)->gen <6 ) +return -EINVAL ; + + ret =i915_mutex_lock_interruptible (dev); +if (ret) +return ret; + + ret = obj->base.filp->f_op->mmap (obj->base.filp, vma); +fput (vma->vm_file); + vma->vm_file =get_file (obj->base.filp); + +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) --1.8.3.2
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 21 lines · Ander Conselvan de Oliveira
From: Rob Bradford <[email protected]>
The aim is that this is functionally equivalent to using the
I915_GEM_MMAPioctl.v2: Add aperture check limit, limit to SNB+ and improve error handling.
v3 (anderco): Map without using the GTT.
Signed-off-by Rob Bradford <[email protected]>Signed-off-by Ander Conselvan de Oliveira <[email protected]>--- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/i915_gem_dmabuf.c +0
-0@@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n · line 202
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +7
-1static 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; +struct drm_i915_private *dev_priv = dev->dev_private; +int ret; + +if (INTEL_INFO (dev)->gen <6 ) +return -EINVAL ;
For cpu mmapings, the check can die.
drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n · line 206
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +4
-0+ + ret =i915_mutex_lock_interruptible (dev); +if (ret) +return ret;
This lock doesn't actually do anything useful.
obj->base.filp can be NULL.
drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n · line 210
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +4
-0+ + ret = obj->base.filp->f_op->mmap (obj->base.filp, vma); +fput (vma->vm_file); + vma->vm_file =get_file (obj->base.filp);
Talk to me about how the user is expected to control coherency since that appears to be outside of the scope of this function. -Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre