aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.19.8/3155-dma-buf-add-dma_fence_chain_for_each_unwrap-helper.patch
blob: 7a313a768a10795d054f2678cd9d08638c8bae83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From 64652321fc6b7ce743e7184a66bbe7a053862024 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20K=C3=B6nig?= <christian.koenig@amd.com>
Date: Mon, 22 Jul 2019 14:20:47 +0200
Subject: [PATCH 3155/4256] dma-buf: add dma_fence_chain_for_each_unwrap helper
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add another for_each helper to iterate over all the fences in a chain
with unwrapping each chain node.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/dma-buf/dma-fence-chain.c | 11 ++++------
 include/linux/dma-fence-chain.h   | 34 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c
index c729f98a7bd3..c13ddc62107b 100644
--- a/drivers/dma-buf/dma-fence-chain.c
+++ b/drivers/dma-buf/dma-fence-chain.c
@@ -151,12 +151,10 @@ static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb)
 static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
 {
 	struct dma_fence_chain *head = to_dma_fence_chain(fence);
+	struct dma_fence *f;
 
 	dma_fence_get(&head->base);
-	dma_fence_chain_for_each(fence, &head->base) {
-		struct dma_fence_chain *chain = to_dma_fence_chain(fence);
-		struct dma_fence *f = chain ? chain->fence : fence;
-
+	dma_fence_chain_for_each_unwrap(f, fence, &head->base) {
 		dma_fence_get(f);
 		if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) {
 			dma_fence_put(fence);
@@ -170,10 +168,9 @@ static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
 
 static bool dma_fence_chain_signaled(struct dma_fence *fence)
 {
-	dma_fence_chain_for_each(fence, fence) {
-		struct dma_fence_chain *chain = to_dma_fence_chain(fence);
-		struct dma_fence *f = chain ? chain->fence : fence;
+	struct dma_fence *f;
 
+	dma_fence_chain_for_each_unwrap(f, fence, fence) {
 		if (!dma_fence_is_signaled(f)) {
 			dma_fence_put(fence);
 			return false;
diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h
index 934a442db8ac..7466d7b8837e 100644
--- a/include/linux/dma-fence-chain.h
+++ b/include/linux/dma-fence-chain.h
@@ -59,6 +59,24 @@ to_dma_fence_chain(struct dma_fence *fence)
 	return container_of(fence, struct dma_fence_chain, base);
 }
 
+/**
+ * dma_fence_chain_unwrap - unwrap chain node
+ * @fence: fence which could be a chain node
+ *
+ * If the paramter is a chain node return the cotained fence, otherwise return
+ * the parameter itself.
+ */
+static inline struct dma_fence *
+dma_fence_chain_unwrap(struct dma_fence *fence)
+{
+	struct dma_fence_chain *chain = to_dma_fence_chain(fence);
+
+	if (!chain)
+		return fence;
+
+	return chain->fence;
+}
+
 /**
  * dma_fence_chain_for_each - iterate over all fences in chain
  * @iter: current fence
@@ -71,6 +89,22 @@ to_dma_fence_chain(struct dma_fence *fence)
 	for (iter = dma_fence_get(head); iter; \
 	     iter = dma_fence_chain_walk(iter))
 
+/**
+ * dma_fence_chain_for_each_unwrap - iterate over all unwrapped fences in chain
+ * @fence: the unwrapped fence
+ * @iter: current fence
+ * @head: starting point
+ *
+ * Iterate over all fences in the chain with unwrapping. We keep a reference to
+ * the current fence while inside the loop which must be dropped when breaking
+ * out.
+ */
+#define dma_fence_chain_for_each_unwrap(fence, iter, head)	\
+	for (iter = dma_fence_get(head),			\
+	     fence = dma_fence_chain_unwrap(iter);		\
+	     iter; iter = dma_fence_chain_walk(iter),		\
+	     fence = dma_fence_chain_unwrap(iter))
+
 struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence);
 int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno);
 void dma_fence_chain_init(struct dma_fence_chain *chain,
-- 
2.17.1