[PATCH 1/6] drm: Add helper to check exporting driver of a DMA-buf

Christian König deathsimple at vodafone.de
Thu Jul 6 20:25:23 UTC 2017


Am 06.07.2017 um 22:16 schrieb Felix Kuehling:
> This allows drivers to check if a DMA-buf contains a GEM object and
> whether it comes from the same driver. It may be from the same or a
> different device.
>
> Signed-off-by: Felix Kuehling <Felix.Kuehling at amd.com>

I think Daniel/Dave hadmore a function which returns the casted GEM 
object or NULL in mind, but that should o it as well.

Patch is Reviewed-by: Christian König <christian.koenig at amd.com>

Regards,
Christian.

> ---
>   drivers/gpu/drm/drm_prime.c | 24 ++++++++++++++++++++++++
>   include/drm/drmP.h          |  2 ++
>   2 files changed, 26 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> index 25aa455..a50baec 100644
> --- a/drivers/gpu/drm/drm_prime.c
> +++ b/drivers/gpu/drm/drm_prime.c
> @@ -594,6 +594,30 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,
>   EXPORT_SYMBOL(drm_gem_prime_handle_to_fd);
>   
>   /**
> + * drm_gem_prime_dmabuf_is_from_driver - check exporting driver of a dma-buf
> + * @dma_buf: dma-buf object to check
> + * @driver: driver that is the expected exporter of the dma-buf
> + *
> + * Returns true if @driver exported @dma_buf. Returns false if
> + * @dma_buf was exported by a different driver.
> + */
> +bool drm_gem_prime_dmabuf_is_from_driver(const struct dma_buf *dma_buf,
> +					 const struct drm_driver *driver)
> +{
> +	struct drm_gem_object *obj;
> +
> +	if (dma_buf->ops != &drm_gem_prime_dmabuf_ops)
> +		return false;
> +
> +	obj = dma_buf->priv;
> +	if (obj->dev->driver != driver)
> +		return false;
> +
> +	return true;
> +}
> +EXPORT_SYMBOL(drm_gem_prime_dmabuf_is_from_driver);
> +
> +/**
>    * 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..052f747 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 bool drm_gem_prime_dmabuf_is_from_driver(const struct dma_buf *dma_buf,
> +		const 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,




More information about the dri-devel mailing list