Skip to content

Commit ddc94d0

Browse files
committed
dma-buf: Split out dma fence array create into alloc and arm functions
Useful to preallocate dma fence array and then arm in path of reclaim or a dma fence. v2: - s/arm/init (Christian) - Drop !array warn (Christian) v3: - Fix kernel doc typos (dim) Cc: Sumit Semwal <[email protected]> Cc: Christian König <[email protected]> Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Christian König <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 20f61c1 commit ddc94d0

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

drivers/dma-buf/dma-fence-array.c

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -144,37 +144,38 @@ const struct dma_fence_ops dma_fence_array_ops = {
144144
EXPORT_SYMBOL(dma_fence_array_ops);
145145

146146
/**
147-
* dma_fence_array_create - Create a custom fence array
147+
* dma_fence_array_alloc - Allocate a custom fence array
148+
* @num_fences: [in] number of fences to add in the array
149+
*
150+
* Return dma fence array on success, NULL on failure
151+
*/
152+
struct dma_fence_array *dma_fence_array_alloc(int num_fences)
153+
{
154+
struct dma_fence_array *array;
155+
156+
return kzalloc(struct_size(array, callbacks, num_fences), GFP_KERNEL);
157+
}
158+
EXPORT_SYMBOL(dma_fence_array_alloc);
159+
160+
/**
161+
* dma_fence_array_init - Init a custom fence array
162+
* @array: [in] dma fence array to arm
148163
* @num_fences: [in] number of fences to add in the array
149164
* @fences: [in] array containing the fences
150165
* @context: [in] fence context to use
151166
* @seqno: [in] sequence number to use
152167
* @signal_on_any: [in] signal on any fence in the array
153168
*
154-
* Allocate a dma_fence_array object and initialize the base fence with
155-
* dma_fence_init().
156-
* In case of error it returns NULL.
157-
*
158-
* The caller should allocate the fences array with num_fences size
159-
* and fill it with the fences it wants to add to the object. Ownership of this
160-
* array is taken and dma_fence_put() is used on each fence on release.
161-
*
162-
* If @signal_on_any is true the fence array signals if any fence in the array
163-
* signals, otherwise it signals when all fences in the array signal.
169+
* Implementation of @dma_fence_array_create without allocation. Useful to init
170+
* a preallocated dma fence array in the path of reclaim or dma fence signaling.
164171
*/
165-
struct dma_fence_array *dma_fence_array_create(int num_fences,
166-
struct dma_fence **fences,
167-
u64 context, unsigned seqno,
168-
bool signal_on_any)
172+
void dma_fence_array_init(struct dma_fence_array *array,
173+
int num_fences, struct dma_fence **fences,
174+
u64 context, unsigned seqno,
175+
bool signal_on_any)
169176
{
170-
struct dma_fence_array *array;
171-
172177
WARN_ON(!num_fences || !fences);
173178

174-
array = kzalloc(struct_size(array, callbacks, num_fences), GFP_KERNEL);
175-
if (!array)
176-
return NULL;
177-
178179
array->num_fences = num_fences;
179180

180181
spin_lock_init(&array->lock);
@@ -200,6 +201,41 @@ struct dma_fence_array *dma_fence_array_create(int num_fences,
200201
*/
201202
while (num_fences--)
202203
WARN_ON(dma_fence_is_container(fences[num_fences]));
204+
}
205+
EXPORT_SYMBOL(dma_fence_array_init);
206+
207+
/**
208+
* dma_fence_array_create - Create a custom fence array
209+
* @num_fences: [in] number of fences to add in the array
210+
* @fences: [in] array containing the fences
211+
* @context: [in] fence context to use
212+
* @seqno: [in] sequence number to use
213+
* @signal_on_any: [in] signal on any fence in the array
214+
*
215+
* Allocate a dma_fence_array object and initialize the base fence with
216+
* dma_fence_init().
217+
* In case of error it returns NULL.
218+
*
219+
* The caller should allocate the fences array with num_fences size
220+
* and fill it with the fences it wants to add to the object. Ownership of this
221+
* array is taken and dma_fence_put() is used on each fence on release.
222+
*
223+
* If @signal_on_any is true the fence array signals if any fence in the array
224+
* signals, otherwise it signals when all fences in the array signal.
225+
*/
226+
struct dma_fence_array *dma_fence_array_create(int num_fences,
227+
struct dma_fence **fences,
228+
u64 context, unsigned seqno,
229+
bool signal_on_any)
230+
{
231+
struct dma_fence_array *array;
232+
233+
array = dma_fence_array_alloc(num_fences);
234+
if (!array)
235+
return NULL;
236+
237+
dma_fence_array_init(array, num_fences, fences,
238+
context, seqno, signal_on_any);
203239

204240
return array;
205241
}

include/linux/dma-fence-array.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ to_dma_fence_array(struct dma_fence *fence)
7979
for (index = 0, fence = dma_fence_array_first(head); fence; \
8080
++(index), fence = dma_fence_array_next(head, index))
8181

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,
86+
bool signal_on_any);
87+
8288
struct dma_fence_array *dma_fence_array_create(int num_fences,
8389
struct dma_fence **fences,
8490
u64 context, unsigned seqno,

0 commit comments

Comments
 (0)