Lines Matching full:fence

3  * Fence mechanism for dma-buf to allow for asynchronous dma access
32 * @refcount: refcount for this fence
33 * @ops: dma_fence_ops associated with this fence
34 * @rcu: used for releasing fence with kfree_rcu
37 * @context: execution context this fence belongs to, returned by
39 * @seqno: the sequence number of this fence inside the execution context,
40 * can be compared to decide which fence would be signaled later.
42 * @timestamp: Timestamp when the fence was signaled.
44 * dma_fence_signal, indicates that the fence has completed with an error.
50 * DMA_FENCE_FLAG_SIGNALED_BIT - fence is already signaled
51 * DMA_FENCE_FLAG_TIMESTAMP_BIT - timestamp recorded for fence signaling
54 * implementer of the fence for its own purposes. Can be used in different
55 * ways by different fence implementers, so do not rely on this.
71 * release the fence it is unused. No one should be adding to the
80 * and to read either you *must* hold a reference to the fence,
106 typedef void (*dma_fence_func_t)(struct dma_fence *fence,
111 * @node: used by dma_fence_add_callback() to append this struct to fence::cb_list
123 * struct dma_fence_ops - operations implemented for fence
140 * for each fence, or build a cache of some sort.
144 const char * (*get_driver_name)(struct dma_fence *fence);
149 * Return the name of the context this fence belongs to. This is a
151 * having it to store permanently for each fence, or build a cache of
156 const char * (*get_timeline_name)(struct dma_fence *fence);
161 * Enable software signaling of fence.
163 * For fence implementations that have the capability for hw->hw
168 * dma_fence_wait() or dma_fence_add_callback() path to let the fence
175 * A return value of false indicates the fence already passed,
184 * dma_fence_signal() might result in the final fence reference being
187 * released when the fence is signalled (through e.g. the interrupt
193 bool (*enable_signaling)(struct dma_fence *fence);
198 * Peek whether the fence is signaled, as a fastpath optimization for
200 * callback does not need to make any guarantees beyond that a fence
202 * callback. This callback may return false even if the fence has
210 bool (*signaled)(struct dma_fence *fence);
223 * interrupted, and remaining jiffies if fence has signaled, or 0 if wait
225 * which should be treated as if the fence is signaled. For example a hardware
228 signed long (*wait)(struct dma_fence *fence,
234 * Called on destruction of fence to release additional resources.
239 void (*release)(struct dma_fence *fence);
244 * Callback to fill in free-form debug info specific to this fence, like
249 void (*fence_value_str)(struct dma_fence *fence, char *str, int size);
255 * sequence number. Note that the specific fence passed to this function
259 void (*timeline_value_str)(struct dma_fence *fence,
265 * Callback to allow a fence waiter to inform the fence signaler of
267 * would prefer the fence to be signaled by. This is intended to
268 * give feedback to the fence signaler to aid in power management
280 void (*set_deadline)(struct dma_fence *fence, ktime_t deadline);
283 void dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
287 void dma_fence_free(struct dma_fence *fence);
288 void dma_fence_describe(struct dma_fence *fence, struct seq_file *seq);
291 * dma_fence_put - decreases refcount of the fence
292 * @fence: fence to reduce refcount of
294 static inline void dma_fence_put(struct dma_fence *fence) in dma_fence_put() argument
296 if (fence) in dma_fence_put()
297 kref_put(&fence->refcount, dma_fence_release); in dma_fence_put()
301 * dma_fence_get - increases refcount of the fence
302 * @fence: fence to increase refcount of
304 * Returns the same fence, with refcount increased by 1.
306 static inline struct dma_fence *dma_fence_get(struct dma_fence *fence) in dma_fence_get() argument
308 if (fence) in dma_fence_get()
309 kref_get(&fence->refcount); in dma_fence_get()
310 return fence; in dma_fence_get()
314 * dma_fence_get_rcu - get a fence from a dma_resv_list with
316 * @fence: fence to increase refcount of
318 * Function returns NULL if no refcount could be obtained, or the fence.
320 static inline struct dma_fence *dma_fence_get_rcu(struct dma_fence *fence) in dma_fence_get_rcu() argument
322 if (kref_get_unless_zero(&fence->refcount)) in dma_fence_get_rcu()
323 return fence; in dma_fence_get_rcu()
329 * dma_fence_get_rcu_safe - acquire a reference to an RCU tracked fence
330 * @fencep: pointer to fence to increase refcount of
332 * Function returns NULL if no refcount could be obtained, or the fence.
333 * This function handles acquiring a reference to a fence that may be
335 * so long as the caller is using RCU on the pointer to the fence.
340 * fence is acquired (as shown here).
348 struct dma_fence *fence; in dma_fence_get_rcu_safe() local
350 fence = rcu_dereference(*fencep); in dma_fence_get_rcu_safe()
351 if (!fence) in dma_fence_get_rcu_safe()
354 if (!dma_fence_get_rcu(fence)) in dma_fence_get_rcu_safe()
360 * to the __rcu protected fence pointer so that if that in dma_fence_get_rcu_safe()
361 * pointer still matches the current fence, we know we in dma_fence_get_rcu_safe()
366 * fence remains valid for the RCU grace period, but it in dma_fence_get_rcu_safe()
369 * the right fence, as below. in dma_fence_get_rcu_safe()
371 if (fence == rcu_access_pointer(*fencep)) in dma_fence_get_rcu_safe()
372 return rcu_pointer_handoff(fence); in dma_fence_get_rcu_safe()
374 dma_fence_put(fence); in dma_fence_get_rcu_safe()
391 int dma_fence_signal(struct dma_fence *fence);
392 int dma_fence_signal_locked(struct dma_fence *fence);
393 int dma_fence_signal_timestamp(struct dma_fence *fence, ktime_t timestamp);
394 int dma_fence_signal_timestamp_locked(struct dma_fence *fence,
396 signed long dma_fence_default_wait(struct dma_fence *fence,
398 int dma_fence_add_callback(struct dma_fence *fence,
401 bool dma_fence_remove_callback(struct dma_fence *fence,
403 void dma_fence_enable_sw_signaling(struct dma_fence *fence);
406 * dma_fence_is_signaled_locked - Return an indication if the fence
408 * @fence: the fence to check
410 * Returns true if the fence was already signaled, false if not. Since this
420 dma_fence_is_signaled_locked(struct dma_fence *fence) in dma_fence_is_signaled_locked() argument
422 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) in dma_fence_is_signaled_locked()
425 if (fence->ops->signaled && fence->ops->signaled(fence)) { in dma_fence_is_signaled_locked()
426 dma_fence_signal_locked(fence); in dma_fence_is_signaled_locked()
434 * dma_fence_is_signaled - Return an indication if the fence is signaled yet.
435 * @fence: the fence to check
437 * Returns true if the fence was already signaled, false if not. Since this
450 dma_fence_is_signaled(struct dma_fence *fence) in dma_fence_is_signaled() argument
452 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) in dma_fence_is_signaled()
455 if (fence->ops->signaled && fence->ops->signaled(fence)) { in dma_fence_is_signaled()
456 dma_fence_signal(fence); in dma_fence_is_signaled()
465 * @f1: the first fence's seqno
466 * @f2: the second fence's seqno from the same context
487 * @f1: the first fence from the same context
488 * @f2: the second fence from the same context
504 * @f1: the first fence from the same context
505 * @f2: the second fence from the same context
507 * Returns true if f1 is chronologically later than f2 or the same fence. Both
518 * dma_fence_later - return the chronologically later fence
519 * @f1: the first fence from the same context
520 * @f2: the second fence from the same context
522 * Returns NULL if both fences are signaled, otherwise the fence that would be
545 * @fence: the dma_fence to query
548 * the fence (to indicate whether the fence was completed due to an error
550 * if the fence has been signaled, dma_fence_get_status_locked() first checks
553 * Returns 0 if the fence has not yet been signaled, 1 if the fence has
555 * if the fence has been completed in err.
557 static inline int dma_fence_get_status_locked(struct dma_fence *fence) in dma_fence_get_status_locked() argument
559 if (dma_fence_is_signaled_locked(fence)) in dma_fence_get_status_locked()
560 return fence->error ?: 1; in dma_fence_get_status_locked()
565 int dma_fence_get_status(struct dma_fence *fence);
568 * dma_fence_set_error - flag an error condition on the fence
569 * @fence: the dma_fence
573 * the fence, to indicate that the fence was completed due to an error
584 static inline void dma_fence_set_error(struct dma_fence *fence, in dma_fence_set_error() argument
587 WARN_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)); in dma_fence_set_error()
590 fence->error = error; in dma_fence_set_error()
594 * dma_fence_timestamp - helper to get the completion timestamp of a fence
595 * @fence: fence to get the timestamp from.
597 * After a fence is signaled the timestamp is updated with the signaling time,
601 static inline ktime_t dma_fence_timestamp(struct dma_fence *fence) in dma_fence_timestamp() argument
603 if (WARN_ON(!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))) in dma_fence_timestamp()
606 while (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags)) in dma_fence_timestamp()
609 return fence->timestamp; in dma_fence_timestamp()
620 * dma_fence_wait - sleep until the fence gets signaled
621 * @fence: the fence to wait on
625 * or 0 if the fence was signaled. Other error values may be
628 * Performs a synchronous wait on this fence. It is assumed the caller
629 * directly or indirectly holds a reference to the fence, otherwise the
630 * fence might be freed before return, resulting in undefined behavior.
634 static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr) in dma_fence_wait() argument
642 ret = dma_fence_wait_timeout(fence, intr, MAX_SCHEDULE_TIMEOUT); in dma_fence_wait()
647 void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline);
657 * dma_fence_is_array - check if a fence is from the array subclass
658 * @fence: the fence to test
662 static inline bool dma_fence_is_array(struct dma_fence *fence) in dma_fence_is_array() argument
664 return fence->ops == &dma_fence_array_ops; in dma_fence_is_array()
668 * dma_fence_is_chain - check if a fence is from the chain subclass
669 * @fence: the fence to test
673 static inline bool dma_fence_is_chain(struct dma_fence *fence) in dma_fence_is_chain() argument
675 return fence->ops == &dma_fence_chain_ops; in dma_fence_is_chain()
679 * dma_fence_is_container - check if a fence is a container for other fences
680 * @fence: the fence to test
682 * Return true if this fence is a container for other fences, false otherwise.
683 * This is important since we can't build up large fence structure or otherwise
686 static inline bool dma_fence_is_container(struct dma_fence *fence) in dma_fence_is_container() argument
688 return dma_fence_is_array(fence) || dma_fence_is_chain(fence); in dma_fence_is_container()