dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Dave Airlie <airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH 3/5] drm/syncobj: add sync_file interaction.
Date: Wed, 24 May 2017 17:06:13 +1000	[thread overview]
Message-ID: <20170524070615.1634-4-airlied@gmail.com> (raw)
In-Reply-To: <20170524070615.1634-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

From: Dave Airlie <airlied@redhat.com>

This interface allows importing the fence from a sync_file into
an existing drm sync object, or exporting the fence attached to
an existing drm sync object into a new sync file object.

This should only be used to interact with sync files where necessary.

Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/drm_syncobj.c | 64 +++++++++++++++++++++++++++++++++++++++++--
 include/uapi/drm/drm.h        |  2 ++
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 8b87594..54d751e 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -50,6 +50,7 @@
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/anon_inodes.h>
+#include <linux/sync_file.h>
 
 #include "drm_internal.h"
 #include <drm/drm_syncobj.h>
@@ -276,6 +277,48 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
 	return 0;
 }
 
+int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,
+				       int fd, int handle)
+{
+	struct dma_fence *fence = sync_file_get_fence(fd);
+	if (!fence)
+		return -EINVAL;
+
+	return drm_syncobj_replace_fence(file_private, handle, fence);
+}
+
+int drm_syncobj_export_sync_file(struct drm_file *file_private,
+				 int handle, int *p_fd)
+{
+	int ret;
+	struct dma_fence *fence;
+	struct sync_file *sync_file;
+	int fd = get_unused_fd_flags(O_CLOEXEC);
+
+	if (fd < 0)
+		return fd;
+
+	ret = drm_syncobj_fence_get(file_private, handle, &fence);
+	if (ret)
+		goto err_put_fd;
+
+	sync_file = sync_file_create(fence);
+	if (!sync_file) {
+		ret = -EINVAL;
+		goto err_fence_put;
+	}
+
+	fd_install(fd, sync_file->file);
+
+	dma_fence_put(fence);
+	*p_fd = fd;
+	return 0;
+err_fence_put:
+	dma_fence_put(fence);
+err_put_fd:
+	put_unused_fd(fd);
+	return ret;
+}
 /**
  * drm_syncobj_open - initalizes syncobj file-private structures at devnode open time
  * @dev: drm_device which is being opened by userspace
@@ -358,9 +401,17 @@ drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
 	if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
 		return -ENODEV;
 
-	if (args->pad || args->flags)
+	if (args->pad)
+		return -EINVAL;
+
+	if (args->flags != 0 &&
+	    args->flags != DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_FENCE_SYNC_FILE)
 		return -EINVAL;
 
+	if (args->flags & DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_FENCE_SYNC_FILE)
+		return drm_syncobj_export_sync_file(file_private, args->handle,
+						    &args->fd);
+
 	return drm_syncobj_handle_to_fd(file_private, args->handle,
 					&args->fd);
 }
@@ -374,9 +425,18 @@ drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
 	if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
 		return -ENODEV;
 
-	if (args->pad || args->flags)
+	if (args->pad)
 		return -EINVAL;
 
+	if (args->flags != 0 &&
+	    args->flags != DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE_FENCE)
+		return -EINVAL;
+
+	if (args->flags & DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE_FENCE)
+		return drm_syncobj_import_sync_file_fence(file_private,
+							  args->fd,
+							  args->handle);
+
 	return drm_syncobj_fd_to_handle(file_private, args->fd,
 					&args->handle);
 }
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index d6e2f62..94c75be 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -708,6 +708,8 @@ struct drm_syncobj_destroy {
 	__u32 pad;
 };
 
+#define DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE_FENCE (1 << 0)
+#define DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_FENCE_SYNC_FILE (1 << 0)
 struct drm_syncobj_handle {
 	__u32 handle;
 	__u32 flags;
-- 
2.9.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-05-24  7:06 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24  7:06 drm syncobj - final posting I hope Dave Airlie
2017-05-24  7:06 ` [PATCH 1/5] drm: introduce sync objects (v3) Dave Airlie
2017-05-24 17:34   ` Jason Ekstrand
2017-05-25  8:30   ` Chris Wilson
     [not found]     ` <20170525083015.GK10827-aII6DKEyn0pWYbfKqPwjAkR8Iwp7RQ6xAL8bYrjMMd8@public.gmane.org>
2017-05-26  4:36       ` Dave Airlie
2017-05-24  7:06 ` [PATCH 2/5] drm/syncobj: add sync obj wait interface. (v3) Dave Airlie
     [not found]   ` <20170524070615.1634-3-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-05-24 17:25     ` Jason Ekstrand
2017-05-24 17:33       ` Jason Ekstrand
2017-05-29  4:39       ` Dave Airlie
2017-05-25  8:47   ` Chris Wilson
     [not found]     ` <20170525084754.GL10827-aII6DKEyn0pWYbfKqPwjAkR8Iwp7RQ6xAL8bYrjMMd8@public.gmane.org>
2017-05-25 16:42       ` Christian König
2017-05-29  6:52     ` Dave Airlie
     [not found] ` <20170524070615.1634-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-05-24  7:06   ` Dave Airlie [this message]
     [not found]     ` <20170524070615.1634-4-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-05-24 17:34       ` [PATCH 3/5] drm/syncobj: add sync_file interaction Jason Ekstrand
2017-05-25  8:54     ` Chris Wilson
2017-05-24  7:06   ` [PATCH 4/5] amdgpu/cs: split out fence dependency checking Dave Airlie
2017-05-24  7:06   ` [PATCH 5/5] amdgpu: use drm sync objects for shared semaphores (v5) Dave Airlie
     [not found]     ` <20170524070615.1634-6-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-05-24  7:25       ` zhoucm1
     [not found]         ` <5925355C.4080904-5C7GfCeVMHo@public.gmane.org>
2017-05-24  8:41           ` Christian König
  -- strict thread matches above, loose matches on Subject: below --
2017-05-12  0:34 drm syncobj - can we get some r-b/a-bs? Dave Airlie
     [not found] ` <20170512003457.24936-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-05-12  0:34   ` [PATCH 3/5] drm/syncobj: add sync_file interaction Dave Airlie
     [not found]     ` <20170512003457.24936-4-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-05-12  8:01       ` Daniel Vetter
2017-05-12 13:38       ` Sean Paul
2017-08-03 16:25       ` Chris Wilson
2017-08-03 23:01         ` Dave Airlie
     [not found]           ` <CAPM=9tw8kFhHWp1tVhmBRqBqX4WnaSvQtLd0OD_U=CNpDROsBQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-08-03 23:22             ` Chris Wilson
     [not found]               ` <150180256673.14563.14290309660718108784-M6iVdVfohj6unts5RBS2dVaTQe2KTcn/@public.gmane.org>
2017-08-04  1:03                 ` Dave Airlie
2017-04-26  3:28 [rfc] drm sync objects (search for spock) Dave Airlie
     [not found] ` <20170426032833.1455-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-26  3:28   ` [PATCH 3/5] drm/syncobj: add sync_file interaction Dave Airlie

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=20170524070615.1634-4-airlied@gmail.com \
    --to=airlied-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).