[PATCH 1/2] dma-buf: add dma_fence_chain_for_each_unwrap helper
Christian König
ckoenig.leichtzumerken at gmail.com
Tue Jul 30 12:15:53 UTC 2019
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 at 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 93c42078cb57..6c3a615731b4 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
More information about the dri-devel
mailing list