2017-04-04 06:26:24 +03:00
|
|
|
/*
|
|
|
|
* 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__
|
|
|
|
|
2018-12-28 11:28:15 +03:00
|
|
|
#include <linux/dma-fence.h>
|
2019-04-01 12:50:56 +03:00
|
|
|
#include <linux/dma-fence-chain.h>
|
2018-12-28 11:28:15 +03:00
|
|
|
|
|
|
|
struct drm_file;
|
2017-04-04 06:26:24 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct drm_syncobj - sync object.
|
|
|
|
*
|
2018-11-08 19:04:22 +03:00
|
|
|
* This structure defines a generic sync object which wraps a &dma_fence.
|
2017-04-04 06:26:24 +03:00
|
|
|
*/
|
|
|
|
struct drm_syncobj {
|
|
|
|
/**
|
2017-12-14 23:30:52 +03:00
|
|
|
* @refcount: Reference count of this object.
|
2017-04-04 06:26:24 +03:00
|
|
|
*/
|
|
|
|
struct kref refcount;
|
|
|
|
/**
|
2018-11-08 19:04:22 +03:00
|
|
|
* @fence:
|
|
|
|
* NULL or a pointer to the fence bound to this object.
|
|
|
|
*
|
|
|
|
* This field should not be used directly. Use drm_syncobj_fence_get()
|
|
|
|
* and drm_syncobj_replace_fence() instead.
|
2017-08-28 17:39:25 +03:00
|
|
|
*/
|
2018-11-08 19:04:22 +03:00
|
|
|
struct dma_fence __rcu *fence;
|
drm: add syncobj timeline support v9
This patch is for VK_KHR_timeline_semaphore extension, semaphore is called syncobj in kernel side:
This extension introduces a new type of syncobj that has an integer payload
identifying a point in a timeline. Such timeline syncobjs support the
following operations:
* CPU query - A host operation that allows querying the payload of the
timeline syncobj.
* CPU wait - A host operation that allows a blocking wait for a
timeline syncobj to reach a specified value.
* Device wait - A device operation that allows waiting for a
timeline syncobj to reach a specified value.
* Device signal - A device operation that allows advancing the
timeline syncobj to a specified value.
v1:
Since it's a timeline, that means the front time point(PT) always is signaled before the late PT.
a. signal PT design:
Signal PT fence N depends on PT[N-1] fence and signal opertion fence, when PT[N] fence is signaled,
the timeline will increase to value of PT[N].
b. wait PT design:
Wait PT fence is signaled by reaching timeline point value, when timeline is increasing, will compare
wait PTs value with new timeline value, if PT value is lower than timeline value, then wait PT will be
signaled, otherwise keep in list. syncobj wait operation can wait on any point of timeline,
so need a RB tree to order them. And wait PT could ahead of signal PT, we need a sumission fence to
perform that.
v2:
1. remove unused DRM_SYNCOBJ_CREATE_TYPE_NORMAL. (Christian)
2. move unexposed denitions to .c file. (Daniel Vetter)
3. split up the change to drm_syncobj_find_fence() in a separate patch. (Christian)
4. split up the change to drm_syncobj_replace_fence() in a separate patch.
5. drop the submission_fence implementation and instead use wait_event() for that. (Christian)
6. WARN_ON(point != 0) for NORMAL type syncobj case. (Daniel Vetter)
v3:
1. replace normal syncobj with timeline implemenation. (Vetter and Christian)
a. normal syncobj signal op will create a signal PT to tail of signal pt list.
b. normal syncobj wait op will create a wait pt with last signal point, and this wait PT is only signaled by related signal point PT.
2. many bug fix and clean up
3. stub fence moving is moved to other patch.
v4:
1. fix RB tree loop with while(node=rb_first(...)). (Christian)
2. fix syncobj lifecycle. (Christian)
3. only enable_signaling when there is wait_pt. (Christian)
4. fix timeline path issues.
5. write a timeline test in libdrm
v5: (Christian)
1. semaphore is called syncobj in kernel side.
2. don't need 'timeline' characters in some function name.
3. keep syncobj cb.
v6: (Christian)
1. merge syncobj_timeline to syncobj structure.
2. simplify some check sentences.
3. some misc change.
4. fix CTS failed issue.
v7: (Christian)
1. error handling when creating signal pt.
2. remove timeline naming in func.
3. export flags in find_fence.
4. allow reset timeline.
v8:
1. use wait_event_interruptible without timeout
2. rename _TYPE_INDIVIDUAL to _TYPE_BINARY
v9:
1. rename signal_pt->base to signal_pt->fence_array to avoid misleading
2. improve kerneldoc
individual syncobj is tested by ./deqp-vk -n dEQP-VK*semaphore*
timeline syncobj is tested by ./amdgpu_test -s 9
Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
Cc: Christian Konig <christian.koenig@amd.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Daniel Rakos <Daniel.Rakos@amd.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Cc: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Christian König <christian.koenig@amd.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/257258/
2018-10-18 09:18:36 +03:00
|
|
|
/**
|
2018-11-08 19:04:22 +03:00
|
|
|
* @cb_list: List of callbacks to call when the &fence gets replaced.
|
drm: add syncobj timeline support v9
This patch is for VK_KHR_timeline_semaphore extension, semaphore is called syncobj in kernel side:
This extension introduces a new type of syncobj that has an integer payload
identifying a point in a timeline. Such timeline syncobjs support the
following operations:
* CPU query - A host operation that allows querying the payload of the
timeline syncobj.
* CPU wait - A host operation that allows a blocking wait for a
timeline syncobj to reach a specified value.
* Device wait - A device operation that allows waiting for a
timeline syncobj to reach a specified value.
* Device signal - A device operation that allows advancing the
timeline syncobj to a specified value.
v1:
Since it's a timeline, that means the front time point(PT) always is signaled before the late PT.
a. signal PT design:
Signal PT fence N depends on PT[N-1] fence and signal opertion fence, when PT[N] fence is signaled,
the timeline will increase to value of PT[N].
b. wait PT design:
Wait PT fence is signaled by reaching timeline point value, when timeline is increasing, will compare
wait PTs value with new timeline value, if PT value is lower than timeline value, then wait PT will be
signaled, otherwise keep in list. syncobj wait operation can wait on any point of timeline,
so need a RB tree to order them. And wait PT could ahead of signal PT, we need a sumission fence to
perform that.
v2:
1. remove unused DRM_SYNCOBJ_CREATE_TYPE_NORMAL. (Christian)
2. move unexposed denitions to .c file. (Daniel Vetter)
3. split up the change to drm_syncobj_find_fence() in a separate patch. (Christian)
4. split up the change to drm_syncobj_replace_fence() in a separate patch.
5. drop the submission_fence implementation and instead use wait_event() for that. (Christian)
6. WARN_ON(point != 0) for NORMAL type syncobj case. (Daniel Vetter)
v3:
1. replace normal syncobj with timeline implemenation. (Vetter and Christian)
a. normal syncobj signal op will create a signal PT to tail of signal pt list.
b. normal syncobj wait op will create a wait pt with last signal point, and this wait PT is only signaled by related signal point PT.
2. many bug fix and clean up
3. stub fence moving is moved to other patch.
v4:
1. fix RB tree loop with while(node=rb_first(...)). (Christian)
2. fix syncobj lifecycle. (Christian)
3. only enable_signaling when there is wait_pt. (Christian)
4. fix timeline path issues.
5. write a timeline test in libdrm
v5: (Christian)
1. semaphore is called syncobj in kernel side.
2. don't need 'timeline' characters in some function name.
3. keep syncobj cb.
v6: (Christian)
1. merge syncobj_timeline to syncobj structure.
2. simplify some check sentences.
3. some misc change.
4. fix CTS failed issue.
v7: (Christian)
1. error handling when creating signal pt.
2. remove timeline naming in func.
3. export flags in find_fence.
4. allow reset timeline.
v8:
1. use wait_event_interruptible without timeout
2. rename _TYPE_INDIVIDUAL to _TYPE_BINARY
v9:
1. rename signal_pt->base to signal_pt->fence_array to avoid misleading
2. improve kerneldoc
individual syncobj is tested by ./deqp-vk -n dEQP-VK*semaphore*
timeline syncobj is tested by ./amdgpu_test -s 9
Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
Cc: Christian Konig <christian.koenig@amd.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Daniel Rakos <Daniel.Rakos@amd.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Cc: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Christian König <christian.koenig@amd.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/257258/
2018-10-18 09:18:36 +03:00
|
|
|
*/
|
2017-08-28 17:39:25 +03:00
|
|
|
struct list_head cb_list;
|
|
|
|
/**
|
2018-11-08 19:04:22 +03:00
|
|
|
* @lock: Protects &cb_list and write-locks &fence.
|
2018-10-23 12:37:45 +03:00
|
|
|
*/
|
2018-11-08 19:04:22 +03:00
|
|
|
spinlock_t lock;
|
2017-04-04 06:26:24 +03:00
|
|
|
/**
|
2017-12-14 23:30:52 +03:00
|
|
|
* @file: A file backing for this syncobj.
|
2017-04-04 06:26:24 +03:00
|
|
|
*/
|
|
|
|
struct file *file;
|
|
|
|
};
|
|
|
|
|
|
|
|
void drm_syncobj_free(struct kref *kref);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_syncobj_get - acquire a syncobj reference
|
|
|
|
* @obj: sync object
|
|
|
|
*
|
2017-12-14 23:30:52 +03:00
|
|
|
* This acquires an additional reference to @obj. It is illegal to call this
|
2017-04-04 06:26:24 +03:00
|
|
|
* without already holding a reference. No locks required.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
drm_syncobj_get(struct drm_syncobj *obj)
|
|
|
|
{
|
|
|
|
kref_get(&obj->refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_syncobj_put - release a reference to a sync object.
|
|
|
|
* @obj: sync object.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
drm_syncobj_put(struct drm_syncobj *obj)
|
|
|
|
{
|
|
|
|
kref_put(&obj->refcount, drm_syncobj_free);
|
|
|
|
}
|
|
|
|
|
2018-11-08 19:04:22 +03:00
|
|
|
/**
|
|
|
|
* drm_syncobj_fence_get - get a reference to a fence in a sync object
|
|
|
|
* @syncobj: sync object.
|
|
|
|
*
|
|
|
|
* This acquires additional reference to &drm_syncobj.fence contained in @obj,
|
|
|
|
* if not NULL. It is illegal to call this without already holding a reference.
|
|
|
|
* No locks required.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Either the fence of @obj or NULL if there's none.
|
|
|
|
*/
|
|
|
|
static inline struct dma_fence *
|
|
|
|
drm_syncobj_fence_get(struct drm_syncobj *syncobj)
|
|
|
|
{
|
|
|
|
struct dma_fence *fence;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
fence = dma_fence_get_rcu_safe(&syncobj->fence);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return fence;
|
|
|
|
}
|
|
|
|
|
2017-04-04 06:26:24 +03:00
|
|
|
struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
|
|
|
|
u32 handle);
|
2019-04-01 12:50:56 +03:00
|
|
|
void drm_syncobj_add_point(struct drm_syncobj *syncobj,
|
|
|
|
struct dma_fence_chain *chain,
|
|
|
|
struct dma_fence *fence,
|
|
|
|
uint64_t point);
|
2018-11-14 16:24:27 +03:00
|
|
|
void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
|
2017-04-04 06:26:24 +03:00
|
|
|
struct dma_fence *fence);
|
2017-08-25 20:52:19 +03:00
|
|
|
int drm_syncobj_find_fence(struct drm_file *file_private,
|
2018-10-15 11:55:47 +03:00
|
|
|
u32 handle, u64 point, u64 flags,
|
2017-08-25 20:52:19 +03:00
|
|
|
struct dma_fence **fence);
|
2017-04-04 06:26:24 +03:00
|
|
|
void drm_syncobj_free(struct kref *kref);
|
2017-09-12 23:42:12 +03:00
|
|
|
int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
|
|
|
|
struct dma_fence *fence);
|
|
|
|
int drm_syncobj_get_handle(struct drm_file *file_private,
|
|
|
|
struct drm_syncobj *syncobj, u32 *handle);
|
2017-09-12 23:42:13 +03:00
|
|
|
int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);
|
2017-04-04 06:26:24 +03:00
|
|
|
|
|
|
|
#endif
|