1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * fence-array: aggregates fence to be waited together
5 * Copyright (C) 2016 Collabora Ltd
6 * Copyright (C) 2016 Advanced Micro Devices, Inc.
8 * Gustavo Padovan <gustavo@padovan.org>
9 * Christian König <christian.koenig@amd.com>
12 #ifndef __LINUX_DMA_FENCE_ARRAY_H
13 #define __LINUX_DMA_FENCE_ARRAY_H
15 #include <linux/dma-fence.h>
16 #include <linux/irq_work.h>
19 * struct dma_fence_array_cb - callback helper for fence array
20 * @cb: fence callback structure for signaling
21 * @array: reference to the parent fence array object
23 struct dma_fence_array_cb
{
24 struct dma_fence_cb cb
;
25 struct dma_fence_array
*array
;
29 * struct dma_fence_array - fence to represent an array of fences
30 * @base: fence base class
31 * @lock: spinlock for fence handling
32 * @num_fences: number of fences in the array
33 * @num_pending: fences in the array still pending
34 * @fences: array of the fences
35 * @work: internal irq_work function
36 * @callbacks: array of callback helpers
38 struct dma_fence_array
{
39 struct dma_fence base
;
44 struct dma_fence
**fences
;
48 struct dma_fence_array_cb callbacks
[] __counted_by(num_fences
);
52 * to_dma_fence_array - cast a fence to a dma_fence_array
53 * @fence: fence to cast to a dma_fence_array
55 * Returns NULL if the fence is not a dma_fence_array,
56 * or the dma_fence_array otherwise.
58 static inline struct dma_fence_array
*
59 to_dma_fence_array(struct dma_fence
*fence
)
61 if (!fence
|| !dma_fence_is_array(fence
))
64 return container_of(fence
, struct dma_fence_array
, base
);
68 * dma_fence_array_for_each - iterate over all fences in array
69 * @fence: current fence
70 * @index: index into the array
71 * @head: potential dma_fence_array object
73 * Test if @array is a dma_fence_array object and if yes iterate over all fences
74 * in the array. If not just iterate over the fence in @array itself.
76 * For a deep dive iterator see dma_fence_unwrap_for_each().
78 #define dma_fence_array_for_each(fence, index, head) \
79 for (index = 0, fence = dma_fence_array_first(head); fence; \
80 ++(index), fence = dma_fence_array_next(head, index))
82 struct dma_fence_array
*dma_fence_array_alloc(int num_fences
);
83 void dma_fence_array_init(struct dma_fence_array
*array
,
84 int num_fences
, struct dma_fence
**fences
,
85 u64 context
, unsigned seqno
,
88 struct dma_fence_array
*dma_fence_array_create(int num_fences
,
89 struct dma_fence
**fences
,
90 u64 context
, unsigned seqno
,
93 bool dma_fence_match_context(struct dma_fence
*fence
, u64 context
);
95 struct dma_fence
*dma_fence_array_first(struct dma_fence
*head
);
96 struct dma_fence
*dma_fence_array_next(struct dma_fence
*head
,
99 #endif /* __LINUX_DMA_FENCE_ARRAY_H */