All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 1/6] drm: Add helper to cast DMA-buf to GEM object
Date: Wed, 12 Jul 2017 10:11:08 +0200	[thread overview]
Message-ID: <20170712081108.3yqdbmpxxvnm5kqz@phenom.ffwll.local> (raw)
In-Reply-To: <1499837367-8368-2-git-send-email-Felix.Kuehling@amd.com>

On Wed, Jul 12, 2017 at 01:29:22AM -0400, Felix Kuehling wrote:
> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
> ---
>  drivers/gpu/drm/drm_prime.c | 25 +++++++++++++++++++++++++
>  include/drm/drmP.h          |  2 ++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> index 25aa455..b1f8445 100644
> --- a/drivers/gpu/drm/drm_prime.c
> +++ b/drivers/gpu/drm/drm_prime.c
> @@ -594,6 +594,31 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,
>  EXPORT_SYMBOL(drm_gem_prime_handle_to_fd);
>  
>  /**
> + * drm_gem_prime_dmabuf_to_object - try to cast dmabuf to GEM object
> + * @dma_buf: dma-buf object to cast
> + * @driver: driver that is the expected exporter of the dma-buf
> + *
> + * If @dma_buf represents a GEM object, this function return a pointer
> + * to it. Optionally, if @driver is not NULL, it also checks that the
> + * object was exported by @driver. Otherwise it returns NULL.
> + */
> +struct drm_gem_object *drm_gem_prime_dmabuf_to_object(struct dma_buf *dma_buf,
> +						      struct drm_driver *driver)
> +{
> +	struct drm_gem_object *obj;
> +
> +	if (dma_buf->ops != &drm_gem_prime_dmabuf_ops)
> +		return NULL;
> +
> +	obj = dma_buf->priv;
> +	if (driver && obj->dev->driver != driver)
> +		return NULL;
> +
> +	return obj;
> +}
> +EXPORT_SYMBOL(drm_gem_prime_dmabuf_to_object);

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Bonus points bikeshed: Would be sweet to use that helper in drm_prime.c
itself, and iirc some drivers could use it too.
-Daniel

> +
> +/**
>   * drm_gem_prime_import - helper library implementation of the import callback
>   * @dev: drm_device to import into
>   * @dma_buf: dma-buf object to import
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index 6105c05..79c2b23 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -767,6 +767,8 @@ extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
>  extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
>  		struct drm_file *file_priv, uint32_t handle, uint32_t flags,
>  		int *prime_fd);
> +extern struct drm_gem_object *drm_gem_prime_dmabuf_to_object(
> +		struct dma_buf *dma_buf, struct drm_driver *driver);
>  extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
>  		struct dma_buf *dma_buf);
>  extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
> -- 
> 1.9.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
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

  parent reply	other threads:[~2017-07-12  8:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12  5:29 [PATCH 0/6] Experimental P2P buffer sharing v2 Felix Kuehling
     [not found] ` <1499837367-8368-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-07-12  5:29   ` [PATCH 1/6] drm: Add helper to cast DMA-buf to GEM object Felix Kuehling
     [not found]     ` <1499837367-8368-2-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-07-12  7:58       ` Christian König
2017-07-12  8:11     ` Daniel Vetter [this message]
     [not found]       ` <20170712081108.3yqdbmpxxvnm5kqz-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-07-12 21:44         ` Felix Kuehling
     [not found]           ` <3f277697-b5d1-2222-7edf-ec0b509d5453-5C7GfCeVMHo@public.gmane.org>
2017-07-13  6:01             ` Daniel Vetter
2017-07-12  5:29   ` [PATCH 2/6] drm/amdgpu: disallow foreign BOs for CS w/o GPUVM mapping Felix Kuehling
2017-07-12  5:29   ` [PATCH 3/6] drm/amdgpu: disallow foreign BOs in the display path v2 Felix Kuehling
2017-07-12  5:29   ` [PATCH 4/6] drm/amdgpu: separate BO from GEM object Felix Kuehling
2017-07-12  5:29   ` [PATCH 5/6] drm/amdgpu: handle foreign BOs in the VM mapping Felix Kuehling
2017-07-12  5:29   ` [PATCH 6/6] drm/amdgpu: enable foreign DMA-buf objects v2 Felix Kuehling

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=20170712081108.3yqdbmpxxvnm5kqz@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=Felix.Kuehling@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.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.