]> asedeno.scripts.mit.edu Git - linux.git/blob - include/linux/dma-fence-chain.h
powerpc/mm/hash: Fix get_region_id() for invalid addresses
[linux.git] / include / linux / dma-fence-chain.h
1 /*
2  * fence-chain: chain fences together in a timeline
3  *
4  * Copyright (C) 2018 Advanced Micro Devices, Inc.
5  * Authors:
6  *      Christian König <christian.koenig@amd.com>
7  *
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.
11  *
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
15  * more details.
16  */
17
18 #ifndef __LINUX_DMA_FENCE_CHAIN_H
19 #define __LINUX_DMA_FENCE_CHAIN_H
20
21 #include <linux/dma-fence.h>
22 #include <linux/irq_work.h>
23
24 /**
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
33  */
34 struct dma_fence_chain {
35         struct dma_fence base;
36         spinlock_t lock;
37         struct dma_fence __rcu *prev;
38         u64 prev_seqno;
39         struct dma_fence *fence;
40         struct dma_fence_cb cb;
41         struct irq_work work;
42 };
43
44 extern const struct dma_fence_ops dma_fence_chain_ops;
45
46 /**
47  * to_dma_fence_chain - cast a fence to a dma_fence_chain
48  * @fence: fence to cast to a dma_fence_array
49  *
50  * Returns NULL if the fence is not a dma_fence_chain,
51  * or the dma_fence_chain otherwise.
52  */
53 static inline struct dma_fence_chain *
54 to_dma_fence_chain(struct dma_fence *fence)
55 {
56         if (!fence || fence->ops != &dma_fence_chain_ops)
57                 return NULL;
58
59         return container_of(fence, struct dma_fence_chain, base);
60 }
61
62 /**
63  * dma_fence_chain_for_each - iterate over all fences in chain
64  * @iter: current fence
65  * @head: starting point
66  *
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.
69  */
70 #define dma_fence_chain_for_each(iter, head)    \
71         for (iter = dma_fence_get(head); iter; \
72              iter = dma_fence_chain_walk(iter))
73
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,
79                           uint64_t seqno);
80
81 #endif /* __LINUX_DMA_FENCE_CHAIN_H */