From: Dave Airlie <airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH 6/8] drm/syncobj: add semaphore support helpers. (v2)
Date: Wed, 12 Apr 2017 14:57:24 +1000 [thread overview]
Message-ID: <20170412045726.13689-7-airlied@gmail.com> (raw)
In-Reply-To: <20170412045726.13689-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
From: Dave Airlie <airlied@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.
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@redhat.com>
---
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
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2017-04-12 4:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-12 4:57 drm sync objects (vn+1) Dave Airlie
2017-04-12 4:57 ` [PATCH 2/8] sync_file: export some interfaces needed by drm sync objects Dave Airlie
[not found] ` <20170412045726.13689-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-12 4:57 ` [PATCH 1/8] sync_file: add type/flags to sync file object creation Dave Airlie
2017-04-12 4:57 ` [PATCH 3/8] drm: introduce sync objects as sync file objects with no fd (v2.1) Dave Airlie
2017-04-12 13:08 ` Emil Velikov
2017-04-12 4:57 ` [PATCH 4/8] sync_file: add a mutex to protect fence and callback members. (v4) Dave Airlie
2017-04-12 4:57 ` Dave Airlie [this message]
2017-04-12 4:57 ` [PATCH 7/8] amdgpu/cs: split out fence dependency checking Dave Airlie
2017-04-12 4:57 ` [PATCH 8/8] amdgpu: use sync file for shared semaphores (v3) Dave Airlie
[not found] ` <20170412045726.13689-9-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-12 9:55 ` Christian König
[not found] ` <43ed515c-7278-3687-022b-9ecd650669fb-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-04-12 10:18 ` Chris Wilson
2017-04-12 10:25 ` Christian König
2017-04-12 15:31 ` Alex Deucher
2017-04-12 4:57 ` [PATCH 5/8] sync_file: add support for a semaphore object (v2) 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=20170412045726.13689-7-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