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

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

v2: drop one of the APIs and replace with a fence
lookup to make the amdgpu api more robust.

Signed-off-by: Dave Airlie <airlied@xxxxxxxxxx>
---
 drivers/gpu/drm/drm_syncobj.c | 60 +++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_syncobj.h     | 36 ++++++++++++++++++++++++++
 2 files changed, 96 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 4827f90..fb135ae 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,65 @@ 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);
+	int ret;
+
+	if (!sync_file)
+		return -EINVAL;
+
+	ret = sync_file_replace_fence(sync_file, fence, old_fence);
+	fput(sync_file->file);
+	return ret;
+}
+
+/**
+ * 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);
+
+int drm_syncobj_fence_get(struct drm_file *file_private,
+			  u32 handle,
+			  struct dma_fence **fence)
+{
+	struct sync_file *sync_file = drm_syncobj_get(file_private, handle);
+
+	if (!sync_file)
+		return -EINVAL;
+
+	*fence = sync_file_get_fence_from_sync_file(sync_file);
+	if (!*fence)
+		return -EINVAL;
+	return 0;
+}
+EXPORT_SYMBOL(drm_syncobj_fence_get);
+
 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..714b658
--- /dev/null
+++ b/include/drm/drm_syncobj.h
@@ -0,0 +1,36 @@
+/*
+ * 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_fence_get(struct drm_file *file_private,
+			  u32 handle,
+			  struct dma_fence **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@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux