Lines Matching full:fence

3  * Fence mechanism for dma-buf to allow for asynchronous dma access
31 * @refcount: refcount for this fence
32 * @ops: dma_fence_ops associated with this fence
33 * @rcu: used for releasing fence with kfree_rcu
36 * @context: execution context this fence belongs to, returned by
38 * @seqno: the sequence number of this fence inside the execution context,
39 * can be compared to decide which fence would be signaled later.
41 * @timestamp: Timestamp when the fence was signaled.
43 * dma_fence_signal, indicates that the fence has completed with an error.
49 * DMA_FENCE_FLAG_SIGNALED_BIT - fence is already signaled
50 * DMA_FENCE_FLAG_TIMESTAMP_BIT - timestamp recorded for fence signaling
53 * implementer of the fence for its own purposes. Can be used in different
54 * ways by different fence implementers, so do not rely on this.
70 * release the fence it is unused. No one should be adding to the
79 * and to read either you *must* hold a reference to the fence,
105 typedef void (*dma_fence_func_t)(struct dma_fence *fence,
110 * @node: used by dma_fence_add_callback() to append this struct to fence::cb_list
122 * struct dma_fence_ops - operations implemented for fence
139 * for each fence, or build a cache of some sort.
143 const char * (*get_driver_name)(struct dma_fence *fence);
148 * Return the name of the context this fence belongs to. This is a
150 * having it to store permanently for each fence, or build a cache of
155 const char * (*get_timeline_name)(struct dma_fence *fence);
160 * Enable software signaling of fence.
162 * For fence implementations that have the capability for hw->hw
167 * dma_fence_wait() or dma_fence_add_callback() path to let the fence
174 * A return value of false indicates the fence already passed,
183 * dma_fence_signal() might result in the final fence reference being
186 * released when the fence is signalled (through e.g. the interrupt
192 bool (*enable_signaling)(struct dma_fence *fence);
197 * Peek whether the fence is signaled, as a fastpath optimization for
199 * callback does not need to make any guarantees beyond that a fence
201 * callback. This callback may return false even if the fence has
209 bool (*signaled)(struct dma_fence *fence);
222 * interrupted, and remaining jiffies if fence has signaled, or 0 if wait
224 * which should be treated as if the fence is signaled. For example a hardware
227 signed long (*wait)(struct dma_fence *fence,
233 * Called on destruction of fence to release additional resources.
238 void (*release)(struct dma_fence *fence);
243 * Callback to fill in free-form debug info specific to this fence, like
248 void (*fence_value_str)(struct dma_fence *fence, char *str, int size);
254 * sequence number. Note that the specific fence passed to this function
258 void (*timeline_value_str)(struct dma_fence *fence,
264 * Callback to allow a fence waiter to inform the fence signaler of
266 * would prefer the fence to be signaled by. This is intended to
267 * give feedback to the fence signaler to aid in power management
279 void (*set_deadline)(struct dma_fence *fence, ktime_t deadline);
282 void dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
286 void dma_fence_free(struct dma_fence *fence);
287 void dma_fence_describe(struct dma_fence *fence, struct seq_file *seq);
290 * dma_fence_put - decreases refcount of the fence
291 * @fence: fence to reduce refcount of
293 static inline void dma_fence_put(struct dma_fence *fence) in dma_fence_put() argument
295 if (fence) in dma_fence_put()
296 kref_put(&fence->refcount, dma_fence_release); in dma_fence_put()
300 * dma_fence_get - increases refcount of the fence
301 * @fence: fence to increase refcount of
303 * Returns the same fence, with refcount increased by 1.
305 static inline struct dma_fence *dma_fence_get(struct dma_fence *fence) in dma_fence_get() argument
307 if (fence) in dma_fence_get()
308 kref_get(&fence->refcount); in dma_fence_get()
309 return fence; in dma_fence_get()
313 * dma_fence_get_rcu - get a fence from a dma_resv_list with
315 * @fence: fence to increase refcount of
317 * Function returns NULL if no refcount could be obtained, or the fence.
319 static inline struct dma_fence *dma_fence_get_rcu(struct dma_fence *fence) in dma_fence_get_rcu() argument
321 if (kref_get_unless_zero(&fence->refcount)) in dma_fence_get_rcu()
322 return fence; in dma_fence_get_rcu()
328 * dma_fence_get_rcu_safe - acquire a reference to an RCU tracked fence
329 * @fencep: pointer to fence to increase refcount of
331 * Function returns NULL if no refcount could be obtained, or the fence.
332 * This function handles acquiring a reference to a fence that may be
334 * so long as the caller is using RCU on the pointer to the fence.
339 * fence is acquired (as shown here).
347 struct dma_fence *fence; in dma_fence_get_rcu_safe() local
349 fence = rcu_dereference(*fencep); in dma_fence_get_rcu_safe()
350 if (!fence) in dma_fence_get_rcu_safe()
353 if (!dma_fence_get_rcu(fence)) in dma_fence_get_rcu_safe()
359 * to the __rcu protected fence pointer so that if that in dma_fence_get_rcu_safe()
360 * pointer still matches the current fence, we know we in dma_fence_get_rcu_safe()
365 * fence remains valid for the RCU grace period, but it in dma_fence_get_rcu_safe()
368 * the right fence, as below. in dma_fence_get_rcu_safe()
370 if (fence == rcu_access_pointer(*fencep)) in dma_fence_get_rcu_safe()
371 return rcu_pointer_handoff(fence); in dma_fence_get_rcu_safe()
373 dma_fence_put(fence); in dma_fence_get_rcu_safe()
390 int dma_fence_signal(struct dma_fence *fence);
391 int dma_fence_signal_locked(struct dma_fence *fence);
392 int dma_fence_signal_timestamp(struct dma_fence *fence, ktime_t timestamp);
393 int dma_fence_signal_timestamp_locked(struct dma_fence *fence,
395 signed long dma_fence_default_wait(struct dma_fence *fence,
397 int dma_fence_add_callback(struct dma_fence *fence,
400 bool dma_fence_remove_callback(struct dma_fence *fence,
402 void dma_fence_enable_sw_signaling(struct dma_fence *fence);
405 * dma_fence_is_signaled_locked - Return an indication if the fence
407 * @fence: the fence to check
409 * Returns true if the fence was already signaled, false if not. Since this
419 dma_fence_is_signaled_locked(struct dma_fence *fence) in dma_fence_is_signaled_locked() argument
421 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) in dma_fence_is_signaled_locked()
424 if (fence->ops->signaled && fence->ops->signaled(fence)) { in dma_fence_is_signaled_locked()
425 dma_fence_signal_locked(fence); in dma_fence_is_signaled_locked()
433 * dma_fence_is_signaled - Return an indication if the fence is signaled yet.
434 * @fence: the fence to check
436 * Returns true if the fence was already signaled, false if not. Since this
449 dma_fence_is_signaled(struct dma_fence *fence) in dma_fence_is_signaled() argument
451 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) in dma_fence_is_signaled()
454 if (fence->ops->signaled && fence->ops->signaled(fence)) { in dma_fence_is_signaled()
455 dma_fence_signal(fence); in dma_fence_is_signaled()
464 * @f1: the first fence's seqno
465 * @f2: the second fence's seqno from the same context
486 * @f1: the first fence from the same context
487 * @f2: the second fence from the same context
502 * dma_fence_later - return the chronologically later fence
503 * @f1: the first fence from the same context
504 * @f2: the second fence from the same context
506 * Returns NULL if both fences are signaled, otherwise the fence that would be
529 * @fence: the dma_fence to query
532 * the fence (to indicate whether the fence was completed due to an error
534 * if the fence has been signaled, dma_fence_get_status_locked() first checks
537 * Returns 0 if the fence has not yet been signaled, 1 if the fence has
539 * if the fence has been completed in err.
541 static inline int dma_fence_get_status_locked(struct dma_fence *fence) in dma_fence_get_status_locked() argument
543 if (dma_fence_is_signaled_locked(fence)) in dma_fence_get_status_locked()
544 return fence->error ?: 1; in dma_fence_get_status_locked()
549 int dma_fence_get_status(struct dma_fence *fence);
552 * dma_fence_set_error - flag an error condition on the fence
553 * @fence: the dma_fence
557 * the fence, to indicate that the fence was completed due to an error
562 static inline void dma_fence_set_error(struct dma_fence *fence, in dma_fence_set_error() argument
565 WARN_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)); in dma_fence_set_error()
568 fence->error = error; in dma_fence_set_error()
572 * dma_fence_timestamp - helper to get the completion timestamp of a fence
573 * @fence: fence to get the timestamp from.
575 * After a fence is signaled the timestamp is updated with the signaling time,
579 static inline ktime_t dma_fence_timestamp(struct dma_fence *fence) in dma_fence_timestamp() argument
581 if (WARN_ON(!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))) in dma_fence_timestamp()
584 while (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags)) in dma_fence_timestamp()
587 return fence->timestamp; in dma_fence_timestamp()
598 * dma_fence_wait - sleep until the fence gets signaled
599 * @fence: the fence to wait on
603 * or 0 if the fence was signaled. Other error values may be
606 * Performs a synchronous wait on this fence. It is assumed the caller
607 * directly or indirectly holds a reference to the fence, otherwise the
608 * fence might be freed before return, resulting in undefined behavior.
612 static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr) in dma_fence_wait() argument
620 ret = dma_fence_wait_timeout(fence, intr, MAX_SCHEDULE_TIMEOUT); in dma_fence_wait()
625 void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline);
635 * dma_fence_is_array - check if a fence is from the array subclass
636 * @fence: the fence to test
640 static inline bool dma_fence_is_array(struct dma_fence *fence) in dma_fence_is_array() argument
642 return fence->ops == &dma_fence_array_ops; in dma_fence_is_array()
646 * dma_fence_is_chain - check if a fence is from the chain subclass
647 * @fence: the fence to test
651 static inline bool dma_fence_is_chain(struct dma_fence *fence) in dma_fence_is_chain() argument
653 return fence->ops == &dma_fence_chain_ops; in dma_fence_is_chain()
657 * dma_fence_is_container - check if a fence is a container for other fences
658 * @fence: the fence to test
660 * Return true if this fence is a container for other fences, false otherwise.
661 * This is important since we can't build up large fence structure or otherwise
664 static inline bool dma_fence_is_container(struct dma_fence *fence) in dma_fence_is_container() argument
666 return dma_fence_is_array(fence) || dma_fence_is_chain(fence); in dma_fence_is_container()