Lines Matching refs:fence
16 #include <linux/dma-fence.h>
30 * fence context counter: each execution context should have its own
31 * fence context, this allows checking if fences belong to the same
44 * A fence is initialized using dma_fence_init() and completed using
59 * fence to be updated.
68 * DOC: fence cross-driver contract
94 * This means any code required for fence completion cannot acquire a
99 * callbacks. This means any code required for fence completion cannot
104 * for fence completeion cannot allocate memory with GFP_NOFS or GFP_NOIO.
113 static const char *dma_fence_stub_get_name(struct dma_fence *fence)
124 * dma_fence_get_stub - return a signaled fence
126 * Return a stub fence which is already signaled.
145 * dma_fence_context_alloc - allocate an array of fence contexts
148 * This function will return the first index of the number of fence contexts
149 * allocated. The fence context is used for setting &dma_fence.context to a
160 * DOC: fence signalling annotation
200 * prevents it from signalling the fence the previous thread is stuck waiting
221 * point where a fence is accessible to other threads, to the point where
254 * dma_fence_begin_signalling - begin a critical DMA fence signalling section
285 * dma_fence_end_signalling - end a critical DMA fence signalling section
315 * dma_fence_signal_locked - signal completion of a fence
316 * @fence: the fence to signal
318 * Signal completion for software callbacks on a fence, this will unblock
320 * dma_fence_add_callback(). Can be called multiple times, but since a fence
327 * Returns 0 on success and a negative error value when @fence has been
330 int dma_fence_signal_locked(struct dma_fence *fence)
335 lockdep_assert_held(fence->lock);
338 &fence->flags)))
342 list_replace(&fence->cb_list, &cb_list);
344 fence->timestamp = ktime_get();
345 set_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags);
346 trace_dma_fence_signaled(fence);
350 cur->func(fence, cur);
358 * dma_fence_signal - signal completion of a fence
359 * @fence: the fence to signal
361 * Signal completion for software callbacks on a fence, this will unblock
363 * dma_fence_add_callback(). Can be called multiple times, but since a fence
367 * Returns 0 on success and a negative error value when @fence has been
370 int dma_fence_signal(struct dma_fence *fence)
376 if (!fence)
381 spin_lock_irqsave(fence->lock, flags);
382 ret = dma_fence_signal_locked(fence);
383 spin_unlock_irqrestore(fence->lock, flags);
392 * dma_fence_wait_timeout - sleep until the fence gets signaled
394 * @fence: the fence to wait on
402 * Performs a synchronous wait on this fence. It is assumed the caller
404 * holds a reference to the fence, otherwise the fence might be
410 dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout)
421 trace_dma_fence_wait_start(fence);
422 if (fence->ops->wait)
423 ret = fence->ops->wait(fence, intr, timeout);
425 ret = dma_fence_default_wait(fence, intr, timeout);
426 trace_dma_fence_wait_end(fence);
440 struct dma_fence *fence =
443 trace_dma_fence_destroy(fence);
445 if (WARN(!list_empty(&fence->cb_list) &&
446 !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags),
448 fence->ops->get_driver_name(fence),
449 fence->ops->get_timeline_name(fence),
450 fence->context, fence->seqno)) {
460 spin_lock_irqsave(fence->lock, flags);
461 fence->error = -EDEADLK;
462 dma_fence_signal_locked(fence);
463 spin_unlock_irqrestore(fence->lock, flags);
466 if (fence->ops->release)
467 fence->ops->release(fence);
469 dma_fence_free(fence);
475 * @fence: fence to release
478 * kfree_rcu() on @fence.
480 void dma_fence_free(struct dma_fence *fence)
482 kfree_rcu(fence, rcu);
486 static bool __dma_fence_enable_signaling(struct dma_fence *fence)
490 lockdep_assert_held(fence->lock);
493 &fence->flags);
495 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
498 if (!was_set && fence->ops->enable_signaling) {
499 trace_dma_fence_enable_signal(fence);
501 if (!fence->ops->enable_signaling(fence)) {
502 dma_fence_signal_locked(fence);
511 * dma_fence_enable_sw_signaling - enable signaling on fence
512 * @fence: the fence to enable
514 * This will request for sw signaling to be enabled, to make the fence
518 void dma_fence_enable_sw_signaling(struct dma_fence *fence)
522 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
525 spin_lock_irqsave(fence->lock, flags);
526 __dma_fence_enable_signaling(fence);
527 spin_unlock_irqrestore(fence->lock, flags);
532 * dma_fence_add_callback - add a callback to be called when the fence
534 * @fence: the fence to wait on
540 * to a fence, but a callback can only be registered to one fence at a time.
543 * fence is already signaled, this function will return -ENOENT (and
546 * Add a software callback to the fence. Same restrictions apply to
548 * keep a refcount to fence afterward dma_fence_add_callback() has returned:
549 * when software access is enabled, the creator of the fence is required to keep
550 * the fence alive until after it signals with dma_fence_signal(). The callback
553 * Returns 0 in case of success, -ENOENT if the fence is already signaled
556 int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
562 if (WARN_ON(!fence || !func))
565 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
570 spin_lock_irqsave(fence->lock, flags);
572 if (__dma_fence_enable_signaling(fence)) {
574 list_add_tail(&cb->node, &fence->cb_list);
580 spin_unlock_irqrestore(fence->lock, flags);
588 * @fence: the dma_fence to query
591 * condition on a signaled fence. See dma_fence_get_status_locked() for more
594 * Returns 0 if the fence has not yet been signaled, 1 if the fence has
596 * if the fence has been completed in err.
598 int dma_fence_get_status(struct dma_fence *fence)
603 spin_lock_irqsave(fence->lock, flags);
604 status = dma_fence_get_status_locked(fence);
605 spin_unlock_irqrestore(fence->lock, flags);
613 * @fence: the fence to wait on
616 * Remove a previously queued callback from the fence. This function returns
617 * true if the callback is successfully removed, or false if the fence has
624 * with a reference held to the fence.
626 * Behaviour is undefined if @cb has not been added to @fence using
630 dma_fence_remove_callback(struct dma_fence *fence, struct dma_fence_cb *cb)
635 spin_lock_irqsave(fence->lock, flags);
641 spin_unlock_irqrestore(fence->lock, flags);
653 dma_fence_default_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
662 * dma_fence_default_wait - default sleep until the fence gets signaled
664 * @fence: the fence to wait on
670 * returned if the fence is already signaled for consistency with other
674 dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)
680 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
683 spin_lock_irqsave(fence->lock, flags);
690 if (!__dma_fence_enable_signaling(fence))
700 list_add(&cb.base.node, &fence->cb_list);
702 while (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags) && ret > 0) {
707 spin_unlock_irqrestore(fence->lock, flags);
711 spin_lock_irqsave(fence->lock, flags);
721 spin_unlock_irqrestore(fence->lock, flags);
733 struct dma_fence *fence = fences[i];
734 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
744 * dma_fence_wait_any_timeout - sleep until any fence gets signaled
750 * @idx: used to store the first signaled fence index, meaningful only on
753 * Returns -EINVAL on custom fence wait implementation, -ERESTARTSYS if
757 * Synchronous waits for the first fence in the array to be signaled. The
759 * fence might be freed before return, resulting in undefined behavior.
792 struct dma_fence *fence = fences[i];
795 if (dma_fence_add_callback(fence, &cb[i].base,
797 /* This fence is already signaled */
833 * dma_fence_init - Initialize a custom fence.
834 * @fence: the fence to initialize
835 * @ops: the dma_fence_ops for operations on this fence
836 * @lock: the irqsafe spinlock to use for locking this fence
837 * @context: the execution context this fence is run on
840 * Initializes an allocated fence, the caller doesn't have to keep its
841 * refcount after committing with this fence, but it will need to hold a
845 * to check which fence is later by simply using dma_fence_later().
848 dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
854 kref_init(&fence->refcount);
855 fence->ops = ops;
856 INIT_LIST_HEAD(&fence->cb_list);
857 fence->lock = lock;
858 fence->context = context;
859 fence->seqno = seqno;
860 fence->flags = 0UL;
861 fence->error = 0;
863 trace_dma_fence_init(fence);