From: Daniel Vetter <daniel@ffwll.ch>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org,
Zach Reizner <zachr@google.com>,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm/vgem: Enable dmabuf interface for export
Date: Tue, 12 Jul 2016 12:45:31 +0200 [thread overview]
Message-ID: <20160712104531.GC23520@phenom.ffwll.local> (raw)
In-Reply-To: <1468242488-1505-3-git-send-email-chris@chris-wilson.co.uk>
On Mon, Jul 11, 2016 at 02:08:07PM +0100, Chris Wilson wrote:
> Enable the standard GEM dma-buf interface provided by the DRM core, but
> only for exporting the VGEM object. This allows passing around the VGEM
> objects created from the dumb interface and using them as sources
> elsewhere. Creating a VGEM object for a foriegn handle is not supported.
>
> v2: With additional completeness.
> v3: Need to clear the CPU cache upon exporting the dma-addresses.
> v4: Use drm_gem_put_pages() as well.
> v5: Use drm_prime_pages_to_sg()
>
> Testcase: igt/vgem_basic/dmabuf-*
> Testcase: igt/prime_vgem
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Sean Paul <seanpaul@chromium.org>
> Cc: Zach Reizner <zachr@google.com>
> Acked-by: Zach Reizner <zachr@google.com>
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Merged the first 2 patches from this series.
-Daniel
> ---
> drivers/gpu/drm/vgem/vgem_drv.c | 89 ++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 88 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
> index c161b6d7e427..b5fb968d2d5c 100644
> --- a/drivers/gpu/drm/vgem/vgem_drv.c
> +++ b/drivers/gpu/drm/vgem/vgem_drv.c
> @@ -192,14 +192,101 @@ static const struct file_operations vgem_driver_fops = {
> .release = drm_release,
> };
>
> +static int vgem_prime_pin(struct drm_gem_object *obj)
> +{
> + long n_pages = obj->size >> PAGE_SHIFT;
> + struct page **pages;
> +
> + /* Flush the object from the CPU cache so that importers can rely
> + * on coherent indirect access via the exported dma-address.
> + */
> + pages = drm_gem_get_pages(obj);
> + if (IS_ERR(pages))
> + return PTR_ERR(pages);
> +
> + drm_clflush_pages(pages, n_pages);
> + drm_gem_put_pages(obj, pages, true, false);
> +
> + return 0;
> +}
> +
> +static struct sg_table *vgem_prime_get_sg_table(struct drm_gem_object *obj)
> +{
> + struct sg_table *st;
> + struct page **pages;
> +
> + pages = drm_gem_get_pages(obj);
> + if (IS_ERR(pages))
> + return ERR_CAST(pages);
> +
> + st = drm_prime_pages_to_sg(pages, obj->size >> PAGE_SHIFT);
> + drm_gem_put_pages(obj, pages, false, false);
> +
> + return st;
> +}
> +
> +static void *vgem_prime_vmap(struct drm_gem_object *obj)
> +{
> + long n_pages = obj->size >> PAGE_SHIFT;
> + struct page **pages;
> + void *addr;
> +
> + pages = drm_gem_get_pages(obj);
> + if (IS_ERR(pages))
> + return NULL;
> +
> + addr = vmap(pages, n_pages, 0, pgprot_writecombine(PAGE_KERNEL_IO));
> + drm_gem_put_pages(obj, pages, false, false);
> +
> + return addr;
> +}
> +
> +static void vgem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
> +{
> + vunmap(vaddr);
> +}
> +
> +static int vgem_prime_mmap(struct drm_gem_object *obj,
> + struct vm_area_struct *vma)
> +{
> + int ret;
> +
> + if (obj->size < vma->vm_end - vma->vm_start)
> + return -EINVAL;
> +
> + if (!obj->filp)
> + return -ENODEV;
> +
> + ret = obj->filp->f_op->mmap(obj->filp, vma);
> + if (ret)
> + return ret;
> +
> + fput(vma->vm_file);
> + vma->vm_file = get_file(obj->filp);
> + vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> + vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
> +
> + return 0;
> +}
> +
> static struct drm_driver vgem_driver = {
> - .driver_features = DRIVER_GEM,
> + .driver_features = DRIVER_GEM | DRIVER_PRIME,
> .gem_free_object_unlocked = vgem_gem_free_object,
> .gem_vm_ops = &vgem_gem_vm_ops,
> .ioctls = vgem_ioctls,
> .fops = &vgem_driver_fops,
> +
> .dumb_create = vgem_gem_dumb_create,
> .dumb_map_offset = vgem_gem_dumb_map,
> +
> + .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
> + .gem_prime_pin = vgem_prime_pin,
> + .gem_prime_export = drm_gem_prime_export,
> + .gem_prime_get_sg_table = vgem_prime_get_sg_table,
> + .gem_prime_vmap = vgem_prime_vmap,
> + .gem_prime_vunmap = vgem_prime_vunmap,
> + .gem_prime_mmap = vgem_prime_mmap,
> +
> .name = DRIVER_NAME,
> .desc = DRIVER_DESC,
> .date = DRIVER_DATE,
> --
> 2.8.1
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-07-12 10:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-11 13:08 drm/vgem fixes and new ioctl for testing prime Chris Wilson
2016-07-11 13:08 ` [PATCH 1/3] drm/vgem: Fix mmaping Chris Wilson
2016-07-11 13:08 ` [PATCH 2/3] drm/vgem: Enable dmabuf interface for export Chris Wilson
2016-07-12 10:45 ` Daniel Vetter [this message]
2016-07-11 13:08 ` [PATCH 3/3] drm/vgem: Attach sw fences to exported vGEM dma-buf (ioctl) Chris Wilson
2016-07-11 15:10 ` Gustavo Padovan
2016-07-11 15:24 ` Chris Wilson
2016-07-12 10:44 ` Daniel Vetter
2016-07-12 11:04 ` Chris Wilson
2016-07-12 14:23 ` Daniel Vetter
-- strict thread matches above, loose matches on Subject: below --
2016-06-23 14:35 [PATCH 1/3] drm/vgem: Fix mmaping Chris Wilson
2016-06-23 14:35 ` [PATCH 2/3] drm/vgem: Enable dmabuf interface for export Chris Wilson
2016-07-01 16:56 ` Matthew Auld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160712104531.GC23520@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=chris@chris-wilson.co.uk \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=zachr@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox