* [PATCH v3] drm/i915: Implement dma-buf mmap() for userspace access
@ 2014-06-19 12:34 Ander Conselvan de Oliveira
2014-06-19 12:37 ` Daniel Vetter
2014-06-19 12:49 ` Chris Wilson
0 siblings, 2 replies; 4+ messages in thread
From: Ander Conselvan de Oliveira @ 2014-06-19 12:34 UTC (permalink / raw)
To: intel-gfx; +Cc: Ander Conselvan de Oliveira
From: Rob Bradford <rob@linux.intel.com>
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.
Signed-off-by: Rob Bradford <rob@linux.intel.com>
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
---
drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
index 580aa42..2d31fca 100644
--- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
@@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
static 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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v3] drm/i915: Implement dma-buf mmap() for userspace access
2014-06-19 12:34 [PATCH v3] drm/i915: Implement dma-buf mmap() for userspace access Ander Conselvan de Oliveira
@ 2014-06-19 12:37 ` Daniel Vetter
2014-06-23 11:25 ` Ander Conselvan de Oliveira
2014-06-19 12:49 ` Chris Wilson
1 sibling, 1 reply; 4+ messages in thread
From: Daniel Vetter @ 2014-06-19 12:37 UTC (permalink / raw)
To: Ander Conselvan de Oliveira; +Cc: Ander Conselvan de Oliveira, intel-gfx
On Thu, Jun 19, 2014 at 03:34:34PM +0300, Ander Conselvan de Oliveira wrote:
> From: Rob Bradford <rob@linux.intel.com>
>
> 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.
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
>
> Signed-off-by: Rob Bradford <rob@linux.intel.com>
> Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
> ---
> drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> index 580aa42..2d31fca 100644
> --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> @@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
>
> static 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
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v3] drm/i915: Implement dma-buf mmap() for userspace access
2014-06-19 12:37 ` Daniel Vetter
@ 2014-06-23 11:25 ` Ander Conselvan de Oliveira
0 siblings, 0 replies; 4+ messages in thread
From: Ander Conselvan de Oliveira @ 2014-06-23 11:25 UTC (permalink / raw)
To: Daniel Vetter; +Cc: intel-gfx
On 06/19/2014 03:37 PM, Daniel Vetter wrote:
> On Thu, Jun 19, 2014 at 03:34:34PM +0300, Ander Conselvan de Oliveira wrote:
>> From: Rob Bradford <rob@linux.intel.com>
>>
>> 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.
>
> 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
> -Daniel
>
>>
>> Signed-off-by: Rob Bradford <rob@linux.intel.com>
>> Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
>> ---
>> drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++-
>> 1 file changed, 18 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
>> index 580aa42..2d31fca 100644
>> --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
>> +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
>> @@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
>>
>> static 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
>> Intel-gfx@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] drm/i915: Implement dma-buf mmap() for userspace access
2014-06-19 12:34 [PATCH v3] drm/i915: Implement dma-buf mmap() for userspace access Ander Conselvan de Oliveira
2014-06-19 12:37 ` Daniel Vetter
@ 2014-06-19 12:49 ` Chris Wilson
1 sibling, 0 replies; 4+ messages in thread
From: Chris Wilson @ 2014-06-19 12:49 UTC (permalink / raw)
To: Ander Conselvan de Oliveira; +Cc: Ander Conselvan de Oliveira, intel-gfx
On Thu, Jun 19, 2014 at 03:34:34PM +0300, Ander Conselvan de Oliveira wrote:
> From: Rob Bradford <rob@linux.intel.com>
>
> 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.
>
> Signed-off-by: Rob Bradford <rob@linux.intel.com>
> Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
> ---
> drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> index 580aa42..2d31fca 100644
> --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> @@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
>
> static 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.
> +
> + ret = i915_mutex_lock_interruptible(dev);
> + if (ret)
> + return ret;
This lock doesn't actually do anything useful.
obj->base.filp can be NULL.
> +
> + 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
--
Chris Wilson, Intel Open Source Technology Centre
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-06-23 11:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-19 12:34 [PATCH v3] drm/i915: Implement dma-buf mmap() for userspace access Ander Conselvan de Oliveira
2014-06-19 12:37 ` Daniel Vetter
2014-06-23 11:25 ` Ander Conselvan de Oliveira
2014-06-19 12:49 ` Chris Wilson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox