|
@@ -80,6 +80,46 @@ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(drm_syncobj_find);
|
|
EXPORT_SYMBOL(drm_syncobj_find);
|
|
|
|
|
|
|
|
+static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj,
|
|
|
|
+ struct drm_syncobj_cb *cb,
|
|
|
|
+ drm_syncobj_func_t func)
|
|
|
|
+{
|
|
|
|
+ cb->func = func;
|
|
|
|
+ list_add_tail(&cb->node, &syncobj->cb_list);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * drm_syncobj_add_callback - adds a callback to syncobj::cb_list
|
|
|
|
+ * @syncobj: Sync object to which to add the callback
|
|
|
|
+ * @cb: Callback to add
|
|
|
|
+ * @func: Func to use when initializing the drm_syncobj_cb struct
|
|
|
|
+ *
|
|
|
|
+ * This adds a callback to be called next time the fence is replaced
|
|
|
|
+ */
|
|
|
|
+void drm_syncobj_add_callback(struct drm_syncobj *syncobj,
|
|
|
|
+ struct drm_syncobj_cb *cb,
|
|
|
|
+ drm_syncobj_func_t func)
|
|
|
|
+{
|
|
|
|
+ spin_lock(&syncobj->lock);
|
|
|
|
+ drm_syncobj_add_callback_locked(syncobj, cb, func);
|
|
|
|
+ spin_unlock(&syncobj->lock);
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(drm_syncobj_add_callback);
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * drm_syncobj_add_callback - removes a callback to syncobj::cb_list
|
|
|
|
+ * @syncobj: Sync object from which to remove the callback
|
|
|
|
+ * @cb: Callback to remove
|
|
|
|
+ */
|
|
|
|
+void drm_syncobj_remove_callback(struct drm_syncobj *syncobj,
|
|
|
|
+ struct drm_syncobj_cb *cb)
|
|
|
|
+{
|
|
|
|
+ spin_lock(&syncobj->lock);
|
|
|
|
+ list_del_init(&cb->node);
|
|
|
|
+ spin_unlock(&syncobj->lock);
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(drm_syncobj_remove_callback);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* drm_syncobj_replace_fence - replace fence in a sync object.
|
|
* drm_syncobj_replace_fence - replace fence in a sync object.
|
|
* @syncobj: Sync object to replace fence in
|
|
* @syncobj: Sync object to replace fence in
|
|
@@ -91,10 +131,24 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
|
|
struct dma_fence *fence)
|
|
struct dma_fence *fence)
|
|
{
|
|
{
|
|
struct dma_fence *old_fence;
|
|
struct dma_fence *old_fence;
|
|
|
|
+ struct drm_syncobj_cb *cur, *tmp;
|
|
|
|
|
|
if (fence)
|
|
if (fence)
|
|
dma_fence_get(fence);
|
|
dma_fence_get(fence);
|
|
- old_fence = xchg(&syncobj->fence, fence);
|
|
|
|
|
|
+
|
|
|
|
+ spin_lock(&syncobj->lock);
|
|
|
|
+
|
|
|
|
+ old_fence = syncobj->fence;
|
|
|
|
+ syncobj->fence = fence;
|
|
|
|
+
|
|
|
|
+ if (fence != old_fence) {
|
|
|
|
+ list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) {
|
|
|
|
+ list_del_init(&cur->node);
|
|
|
|
+ cur->func(syncobj, cur);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ spin_unlock(&syncobj->lock);
|
|
|
|
|
|
dma_fence_put(old_fence);
|
|
dma_fence_put(old_fence);
|
|
}
|
|
}
|
|
@@ -130,7 +184,7 @@ void drm_syncobj_free(struct kref *kref)
|
|
struct drm_syncobj *syncobj = container_of(kref,
|
|
struct drm_syncobj *syncobj = container_of(kref,
|
|
struct drm_syncobj,
|
|
struct drm_syncobj,
|
|
refcount);
|
|
refcount);
|
|
- dma_fence_put(syncobj->fence);
|
|
|
|
|
|
+ drm_syncobj_replace_fence(syncobj, NULL);
|
|
kfree(syncobj);
|
|
kfree(syncobj);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(drm_syncobj_free);
|
|
EXPORT_SYMBOL(drm_syncobj_free);
|
|
@@ -146,6 +200,8 @@ static int drm_syncobj_create(struct drm_file *file_private,
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
|
|
|
kref_init(&syncobj->refcount);
|
|
kref_init(&syncobj->refcount);
|
|
|
|
+ INIT_LIST_HEAD(&syncobj->cb_list);
|
|
|
|
+ spin_lock_init(&syncobj->lock);
|
|
|
|
|
|
idr_preload(GFP_KERNEL);
|
|
idr_preload(GFP_KERNEL);
|
|
spin_lock(&file_private->syncobj_table_lock);
|
|
spin_lock(&file_private->syncobj_table_lock);
|