[PATCH 6/8] drm/syncobj: add semaphore support helpers.

Daniel Vetter daniel at ffwll.ch
Tue Apr 4 08:07:31 UTC 2017


On Tue, Apr 04, 2017 at 02:27:31PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
> 
> This just adds two helper interfaces to bridge the gap from
> drivers to sync_file for the semaphore objects.
> 
> These will be used by the amdgpu driver.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  drivers/gpu/drm/drm_syncobj.c | 72 +++++++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_syncobj.h     | 37 ++++++++++++++++++++++
>  2 files changed, 109 insertions(+)
>  create mode 100644 include/drm/drm_syncobj.h
> 
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index a3a1ace..6f1b61f 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c

Kernel-doc stanza for you to pull in:

diff --git a/Documentation/gpu/drm-mm.rst b/Documentation/gpu/drm-mm.rst
index 96b9c34c21e4..d55a22efb7c3 100644
--- a/Documentation/gpu/drm-mm.rst
+++ b/Documentation/gpu/drm-mm.rst
@@ -455,6 +455,12 @@ PRIME Function References
 .. kernel-doc:: drivers/gpu/drm/drm_prime.c
    :export:
 
+DRM Syncobjects
+===============
+
+.. kernel-doc:: drivers/gpu/drm/drm_syncobj.c
+   :export:
+
 DRM MM Range Allocator
 ======================

A few links to &struct sync_file and &SYNC_FILE_TYPE_SEMAPHORE sprinkled
into the kerneldoc of the two functions would spice it up a bit :-)

 
> @@ -39,6 +39,7 @@
>  #include <drm/drmP.h>
>  #include <linux/sync_file.h>
>  #include "drm_internal.h"
> +#include <drm/drm_syncobj.h>
>  
>  static struct sync_file *drm_syncobj_file_lookup(struct drm_file *file_private,
>  						 u32 handle)
> @@ -55,6 +56,77 @@ static struct sync_file *drm_syncobj_file_lookup(struct drm_file *file_private,
>  	return sync_file;
>  }
>  
> +static int drm_syncobj_swap_fences_nocheck(struct drm_file *file_private,
> +					   uint32_t handle,
> +					   struct dma_fence *fence,
> +					   struct dma_fence **old_fence)
> +{
> +	struct sync_file *sync_file = drm_syncobj_file_lookup(file_private, handle);

Needs the refcount dance I mentioned in the previous drm_syncobj patch.

> +
> +	if (!sync_file)
> +		return -EINVAL;
> +
> +	*old_fence = sync_file_replace_fence(sync_file, fence);
> +	return 0;
> +}

If we restrict drm_syncobj to semas, then we can add the WARN_ON in the
previous patch and forgo this unchecked version here.

> +
> +/**
> + * drm_syncobj_swap_fences - lookup and replace fence in a sync object.
> + * @file_private - drm file private pointer.
> + * @handle - sync object handle
> + * @fence - new fence (or NULL) to back sync object.
> + * @old_fence - old fence backing sync object.
> + * Returns: Old fence
> + *
> + * This function is used to swap the fence backing the sync object
> + * with a new one, it returns the old fence in old_fence;

Please add.

Returns:

0 on success, or -EINVAL when the handle doesn't point at a valid
sync_file with %SYNC_FILE_TYPE_SEMAPHORE.

Same below.

Cheers, Daniel

> + */
> +int drm_syncobj_swap_fences(struct drm_file *file_private,
> +			    uint32_t handle,
> +			    struct dma_fence *fence,
> +			    struct dma_fence **old_fence)
> +{
> +	int r;
> +
> +	r = drm_syncobj_swap_fences_nocheck(file_private,
> +					    handle,
> +					    fence,
> +					    old_fence);
> +	if (r)
> +		return r;
> +
> +
> +	if (!*old_fence)
> +		return -EINVAL;
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_syncobj_swap_fences);
> +
> +/**
> + * drm_syncobj_replace_fence - lookup and replace fence in a sync object.
> + * @file_private - drm file private pointer.
> + * @handle - syncobj handle to lookup
> + * @fence - fence to install in sync file.
> + * Returns: 0 on success or -EINVAL on error
> + *
> + * This looks up a sync object and replaces the fence on it, freeing
> + * the old one.
> + */
> +int drm_syncobj_replace_fence(struct drm_file *file_private,
> +			      u32 handle,
> +			      struct dma_fence *fence)
> +{
> +	struct dma_fence *old_fence;
> +	int r;
> +
> +	r = drm_syncobj_swap_fences_nocheck(file_private, handle, fence, &old_fence);
> +	if (r)
> +		return r;
> +	dma_fence_put(old_fence);
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_syncobj_replace_fence);
> +
>  static int drm_syncobj_create(struct drm_file *file_private,
>  				  unsigned type,
>  				  unsigned flags, u32 *handle)
> diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
> new file mode 100644
> index 0000000..f614e06
> --- /dev/null
> +++ b/include/drm/drm_syncobj.h
> @@ -0,0 +1,37 @@
> +/*
> + * Copyright © 2017 Red Hat
> + *
> + * 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:
> + *
> + */
> +#ifndef __DRM_SYNCOBJ_H__
> +#define __DRM_SYNCOBJ_H__
> +
> +int drm_syncobj_swap_fences(struct drm_file *file_private,
> +			    uint32_t handle,
> +			    struct dma_fence *fence,
> +			    struct dma_fence **old_fence);
> +int drm_syncobj_replace_fence(struct drm_file *file_private,
> +			      u32 handle,
> +			      struct dma_fence *fence);
> +
> +#endif
> -- 
> 2.9.3
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list