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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Dave Airlie <airlied@xxxxxxxxxx>

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 | 77 +++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_syncobj.h     | 37 +++++++++++++++++++++
 2 files changed, 114 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 9985893..6b8f544 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -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_get(struct drm_file *file_private,
 					 u32 handle)
@@ -57,6 +58,82 @@ static struct sync_file *drm_syncobj_get(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_get(file_private, handle);
+
+	if (!sync_file)
+		return -EINVAL;
+
+	*old_fence = sync_file_replace_fence(sync_file, fence);
+	fput(sync_file->file);
+	return 0;
+}
+
+/**
+ * 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:
+ * 0 on success, or -EINVAL when the handle doesn't point at a valid
+ * sync_file with %SYNC_FILE_TYPE_SEMAPHORE.
+ *
+ * This function is used to swap the fence backing the sync object
+ * with a new one, it returns the old fence in old_fence;
+ */
+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 when the handle doesn't point at a valid
+ * sync_file with %SYNC_FILE_TYPE_SEMAPHORE.
+ *
+ * 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



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux