@@ -80,7 +80,8 @@ static int fence_cmp(const void *_a, const void *_b)
}
/* Implementation for the dma_fence_merge() marco, don't use directly */
-struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
+struct dma_fence *__dma_fence_unwrap_merge(u64 context,
+ unsigned int num_fences,
struct dma_fence **fences,
struct dma_fence_unwrap *iter)
{
@@ -156,9 +157,8 @@ struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
count = ++j;
if (count > 1) {
- result = dma_fence_array_create(count, array,
- dma_fence_context_alloc(1),
- 1, false);
+ result = dma_fence_array_create(count, array, context, 1,
+ false);
if (!result) {
for (i = 0; i < count; i++)
dma_fence_put(array[i]);
@@ -8,6 +8,8 @@
#ifndef __LINUX_DMA_FENCE_UNWRAP_H
#define __LINUX_DMA_FENCE_UNWRAP_H
+#include <linux/types.h>
+
struct dma_fence;
/**
@@ -48,7 +50,8 @@ struct dma_fence *dma_fence_unwrap_next(struct dma_fence_unwrap *cursor);
for (fence = dma_fence_unwrap_first(head, cursor); fence; \
fence = dma_fence_unwrap_next(cursor))
-struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
+struct dma_fence *__dma_fence_unwrap_merge(u64 context,
+ unsigned int num_fences,
struct dma_fence **fences,
struct dma_fence_unwrap *cursors);
@@ -69,7 +72,31 @@ struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
struct dma_fence *__f[] = { __VA_ARGS__ }; \
struct dma_fence_unwrap __c[ARRAY_SIZE(__f)]; \
\
- __dma_fence_unwrap_merge(ARRAY_SIZE(__f), __f, __c); \
+ __dma_fence_unwrap_merge(dma_fence_context_alloc(1), \
+ ARRAY_SIZE(__f), __f, __c); \
+ })
+
+/**
+ * dma_fence_unwrap_merge_context - unwrap and merge fences with context
+ *
+ * All fences given as parameters are unwrapped and merged back together as flat
+ * dma_fence_array. Useful if multiple containers need to be merged together.
+ *
+ * Implemented as a macro to allocate the necessary arrays on the stack and
+ * account the stack frame size to the caller.
+ *
+ * Fence context is passed in and not automatically allocated.
+ *
+ * Returns NULL on memory allocation failure, a dma_fence object representing
+ * all the given fences otherwise.
+ */
+#define dma_fence_unwrap_merge_context(context, ...) \
+ ({ \
+ struct dma_fence *__f[] = { __VA_ARGS__ }; \
+ struct dma_fence_unwrap __c[ARRAY_SIZE(__f)]; \
+ \
+ __dma_fence_unwrap_merge((context), \
+ ARRAY_SIZE(__f), __f, __c); \
})
#endif