1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * fence-chain: chain fences together in a timeline
5 * Copyright (C) 2018 Advanced Micro Devices, Inc.
7 * Christian König <christian.koenig@amd.com>
10 #ifndef __LINUX_DMA_FENCE_CHAIN_H
11 #define __LINUX_DMA_FENCE_CHAIN_H
13 #include <linux/dma-fence.h>
14 #include <linux/irq_work.h>
17 * struct dma_fence_chain - fence to represent an node of a fence chain
18 * @base: fence base class
19 * @lock: spinlock for fence handling
20 * @prev: previous fence of the chain
21 * @prev_seqno: original previous seqno before garbage collection
22 * @fence: encapsulated fence
23 * @cb: callback structure for signaling
24 * @work: irq work item for signaling
26 struct dma_fence_chain
{
27 struct dma_fence base
;
29 struct dma_fence __rcu
*prev
;
31 struct dma_fence
*fence
;
32 struct dma_fence_cb cb
;
36 extern const struct dma_fence_ops dma_fence_chain_ops
;
39 * to_dma_fence_chain - cast a fence to a dma_fence_chain
40 * @fence: fence to cast to a dma_fence_array
42 * Returns NULL if the fence is not a dma_fence_chain,
43 * or the dma_fence_chain otherwise.
45 static inline struct dma_fence_chain
*
46 to_dma_fence_chain(struct dma_fence
*fence
)
48 if (!fence
|| fence
->ops
!= &dma_fence_chain_ops
)
51 return container_of(fence
, struct dma_fence_chain
, base
);
55 * dma_fence_chain_for_each - iterate over all fences in chain
56 * @iter: current fence
57 * @head: starting point
59 * Iterate over all fences in the chain. We keep a reference to the current
60 * fence while inside the loop which must be dropped when breaking out.
62 #define dma_fence_chain_for_each(iter, head) \
63 for (iter = dma_fence_get(head); iter; \
64 iter = dma_fence_chain_walk(iter))
66 struct dma_fence
*dma_fence_chain_walk(struct dma_fence
*fence
);
67 int dma_fence_chain_find_seqno(struct dma_fence
**pfence
, uint64_t seqno
);
68 void dma_fence_chain_init(struct dma_fence_chain
*chain
,
69 struct dma_fence
*prev
,
70 struct dma_fence
*fence
,
73 #endif /* __LINUX_DMA_FENCE_CHAIN_H */