All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Ben Widawsky <ben@bwidawsk.net>, dri-devel@lists.freedesktop.org
Cc: linaro-mm-sig@lists.linaro.org, Dave Airlie <airlied@redhat.com>
Subject: Re: [Linaro-mm-sig] [PATCH 5/7] drm/vgem: prime export support
Date: Thu, 23 Feb 2012 19:00:53 +0000	[thread overview]
Message-ID: <c55c5d$22cajd@AZSMGA002.ch.intel.com> (raw)
In-Reply-To: <1329938960-4903-7-git-send-email-ben@bwidawsk.net>

[-- Attachment #1: Type: text/plain, Size: 4595 bytes --]

On Wed, 22 Feb 2012 20:29:18 +0100, Ben Widawsky <ben@bwidawsk.net> wrote:
> dma-buf export implementation. Heavily influenced by Dave Airlie's proof
> of concept work.
> 
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Dave Airlie <airlied@redhat.com>
> Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
> ---
>  drivers/gpu/drm/vgem/Makefile       |    2 +-
>  drivers/gpu/drm/vgem/vgem_dma_buf.c |  128 +++++++++++++++++++++++++++++++++++
>  drivers/gpu/drm/vgem/vgem_drv.c     |    6 ++
>  drivers/gpu/drm/vgem/vgem_drv.h     |    7 ++
>  4 files changed, 142 insertions(+), 1 deletions(-)
>  create mode 100644 drivers/gpu/drm/vgem/vgem_dma_buf.c
> 
> diff --git a/drivers/gpu/drm/vgem/Makefile b/drivers/gpu/drm/vgem/Makefile
> index 3f4c7b8..1055cb7 100644
> --- a/drivers/gpu/drm/vgem/Makefile
> +++ b/drivers/gpu/drm/vgem/Makefile
> @@ -1,4 +1,4 @@
>  ccflags-y := -Iinclude/drm
> -vgem-y := vgem_drv.o
> +vgem-y := vgem_drv.o vgem_dma_buf.o
>  
>  obj-$(CONFIG_DRM_VGEM)	+= vgem.o
> diff --git a/drivers/gpu/drm/vgem/vgem_dma_buf.c b/drivers/gpu/drm/vgem/vgem_dma_buf.c
> new file mode 100644
> index 0000000..eca9445
> --- /dev/null
> +++ b/drivers/gpu/drm/vgem/vgem_dma_buf.c
> @@ -0,0 +1,128 @@
> +/*
> + * Copyright © 2012 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + * Authors:
> + *    Ben Widawsky <ben@bwidawsk.net>
> + *
> + */
> +
> +#include <linux/dma-buf.h>
> +#include "vgem_drv.h"
> +
> +#define VGEM_FD_PERMS 0600
> +
> +struct sg_table *vgem_gem_map_dma_buf(struct dma_buf_attachment *attachment,
> +                                      enum dma_data_direction dir)
I guess I'm just not quite happy with the dma-buf interface, but I'd
have liked to have avoided the whole sg_table allocation and have made
the dma_buf embeddable. Daniel is slacking!

> +int vgem_prime_to_fd(struct drm_device *dev, struct drm_file *file,
> +		     uint32_t handle, int *prime_fd)
> +{
> +	struct drm_vgem_file_private *file_priv = file->driver_priv;
> +	struct drm_vgem_gem_object *obj;
> +	int ret;
> +
> +	DRM_DEBUG_PRIME("Request fd for handle %d\n", handle);
> +
> +	obj = to_vgem_bo(drm_gem_object_lookup(dev, file, handle));
> +	if (!obj)
> +		return -EBADF;
-ENOENT; EBADF is for reporting that ioctl was itself called on an invalid fd.

locking fail.

> +	/* This means a user has already called get_fd on this */
> +	if (obj->base.prime_fd != -1) {
> +		DRM_DEBUG_PRIME("User requested a previously exported buffer "
> +				"%d %d\n", handle, obj->base.prime_fd);
> +		drm_gem_object_unreference(&obj->base);
> +		goto out_fd;
> +	}
> +
> +	/* Make a dma buf out of our vgem object */
> +	obj->base.export_dma_buf = dma_buf_export(obj, &vgem_dmabuf_ops,
> +						  obj->base.size,
> +						  VGEM_FD_PERMS);
locking fail.

> +	if (IS_ERR(obj->base.export_dma_buf)) {
> +		DRM_DEBUG_PRIME("export fail\n");
> +		return PTR_ERR(obj->base.export_dma_buf);
> +	} else
> +		obj->base.prime_fd = dma_buf_fd(obj->base.export_dma_buf);
locking fail... ;-)

> +
> +	mutex_lock(&dev->prime_mutex);
Per-device mutex for a per-file hash-table?

> +	ret = drm_prime_insert_fd_handle_mapping(&file_priv->prime,
> +						 obj->base.export_dma_buf,
> +						 handle);
> +	WARN_ON(ret);
> +	ret = drm_prime_add_dma_buf(dev, &obj->base);
> +	mutex_unlock(&dev->prime_mutex);
> +	if (ret)
> +		return ret;
> +
> +out_fd:
> +	*prime_fd = obj->base.prime_fd;
> +
> +	return 0;
> +}
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2012-02-23 19:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-22 19:29 [PATCH 0/7] RFCv3 VGEM Prime (dma-buf) Ben Widawsky
2012-02-22 19:29 ` [PATCH 1/7] drm: base prime support Ben Widawsky
2012-02-22 19:58   ` Kristian Høgsberg
2012-02-27  2:49   ` InKi Dae
2012-02-22 19:29 ` [PATCH 2/7] DRM_DEBUG_PRIME Ben Widawsky
2012-02-22 19:29 ` [PATCH 2/7] drm: DRM_DEBUG_PRIME Ben Widawsky
2012-02-22 19:29 ` [PATCH 3/7] drm/vgem: virtual GEM provider Ben Widawsky
2012-02-22 19:29 ` [PATCH 4/7] drm: per device prime dma buf hash Ben Widawsky
2012-02-22 19:29 ` [PATCH 5/7] drm/vgem: prime export support Ben Widawsky
2012-02-23 19:00   ` Chris Wilson [this message]
2012-02-27 13:37   ` Tomasz Stanislawski
2012-02-27 15:43   ` Tomasz Stanislawski
2012-02-29 15:50     ` Daniel Vetter
2012-02-22 19:29 ` [PATCH 6/7] drm/vgem: import support Ben Widawsky
2012-02-23 19:10   ` [Linaro-mm-sig] " Chris Wilson
2012-02-23 23:00   ` Chris Wilson
2012-02-22 19:29 ` [PATCH 7/7] drm: actually enable PRIME Ben Widawsky

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='c55c5d$22cajd@AZSMGA002.ch.intel.com' \
    --to=chris@chris-wilson.co.uk \
    --cc=airlied@redhat.com \
    --cc=ben@bwidawsk.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.