From: Dave Airlie <airlied@gmail.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH 6/8] drm/syncobj: add semaphore support helpers.
Date: Tue, 4 Apr 2017 14:27:31 +1000 [thread overview]
Message-ID: <20170404042733.17203-7-airlied@gmail.com> (raw)
In-Reply-To: <20170404042733.17203-1-airlied@gmail.com>
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.
Signed-off-by: Dave Airlie <airlied@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
@@ -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);
+
+ if (!sync_file)
+ return -EINVAL;
+
+ *old_fence = sync_file_replace_fence(sync_file, fence);
+ 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: 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;
+ */
+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@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2017-04-04 4:27 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-04 4:27 [RFC] DRM synchronisation objects Dave Airlie
2017-04-04 4:27 ` [PATCH 1/8] sync_file: add type/flags to sync file object creation Dave Airlie
2017-04-04 7:08 ` Daniel Vetter
2017-04-04 4:27 ` [PATCH 2/8] sync_file: export some interfaces needed by drm sync objects Dave Airlie
2017-04-04 7:10 ` Daniel Vetter
2017-04-04 4:27 ` [PATCH 3/8] drm: introduce sync objects as sync file objects with no fd Dave Airlie
2017-04-04 7:42 ` Daniel Vetter
[not found] ` <CAPM=9tyj6k4hqJWrwDW8Ch+TZCOoXRuAK2g71ciUm5vxpwmkuw@mail.gmail.com>
[not found] ` <CAKMK7uFoFvsREVtSxsoOeM6OPDM-iGOATtcAK6p65LzG39D6oQ@mail.gmail.com>
2017-04-11 6:00 ` Daniel Vetter
2017-04-04 4:27 ` [PATCH 4/8] sync_file: add a mutex to protect fence and callback members. (v4) Dave Airlie
2017-04-04 7:52 ` Daniel Vetter
2017-04-04 8:07 ` Christian König
2017-04-11 2:57 ` Dave Airlie
2017-04-04 4:27 ` [PATCH 5/8] sync_file: add support for a semaphore object Dave Airlie
2017-04-04 7:59 ` Daniel Vetter
2017-04-04 11:52 ` Chris Wilson
2017-04-04 11:59 ` Chris Wilson
2017-04-04 4:27 ` Dave Airlie [this message]
2017-04-04 8:07 ` [PATCH 6/8] drm/syncobj: add semaphore support helpers Daniel Vetter
2017-04-04 4:27 ` [PATCH 7/8] amdgpu/cs: split out fence dependency checking Dave Airlie
2017-04-04 7:37 ` Christian König
2017-04-04 4:27 ` [PATCH 8/8] amdgpu: use sync file for shared semaphores (v2) Dave Airlie
2017-04-04 7:40 ` Christian König
2017-04-04 8:10 ` Daniel Vetter
2017-04-04 11:05 ` Christian König
2017-04-11 3:18 ` Dave Airlie
2017-04-11 6:55 ` Christian König
2017-04-04 4:35 ` [RFC] DRM synchronisation objects Dave Airlie
2017-04-04 8:02 ` Christian König
2017-04-04 8:11 ` Daniel Vetter
-- strict thread matches above, loose matches on Subject: below --
2017-04-11 3:22 [repost] drm sync objects cleaned up Dave Airlie
[not found] ` <20170411032220.21101-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-11 3:22 ` [PATCH 6/8] drm/syncobj: add semaphore support helpers 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=20170404042733.17203-7-airlied@gmail.com \
--to=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.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