2 * fence-chain: chain fences together in a timeline
4 * Copyright (C) 2018 Advanced Micro Devices, Inc.
6 * Christian König <christian.koenig@amd.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 #ifndef __LINUX_DMA_FENCE_CHAIN_H
19 #define __LINUX_DMA_FENCE_CHAIN_H
21 #include <linux/dma-fence.h>
22 #include <linux/irq_work.h>
25 * struct dma_fence_chain - fence to represent an node of a fence chain
26 * @base: fence base class
27 * @lock: spinlock for fence handling
28 * @prev: previous fence of the chain
29 * @prev_seqno: original previous seqno before garbage collection
30 * @fence: encapsulated fence
31 * @cb: callback structure for signaling
32 * @work: irq work item for signaling
34 struct dma_fence_chain {
35 struct dma_fence base;
37 struct dma_fence __rcu *prev;
39 struct dma_fence *fence;
40 struct dma_fence_cb cb;
44 extern const struct dma_fence_ops dma_fence_chain_ops;
47 * to_dma_fence_chain - cast a fence to a dma_fence_chain
48 * @fence: fence to cast to a dma_fence_array
50 * Returns NULL if the fence is not a dma_fence_chain,
51 * or the dma_fence_chain otherwise.
53 static inline struct dma_fence_chain *
54 to_dma_fence_chain(struct dma_fence *fence)
56 if (!fence || fence->ops != &dma_fence_chain_ops)
59 return container_of(fence, struct dma_fence_chain, base);
63 * dma_fence_chain_for_each - iterate over all fences in chain
64 * @iter: current fence
65 * @head: starting point
67 * Iterate over all fences in the chain. We keep a reference to the current
68 * fence while inside the loop which must be dropped when breaking out.
70 #define dma_fence_chain_for_each(iter, head) \
71 for (iter = dma_fence_get(head); iter; \
72 iter = dma_fence_chain_walk(iter))
74 struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence);
75 int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno);
76 void dma_fence_chain_init(struct dma_fence_chain *chain,
77 struct dma_fence *prev,
78 struct dma_fence *fence,
81 #endif /* __LINUX_DMA_FENCE_CHAIN_H */