diff options
author | Christian König <christian.koenig@amd.com> | 2022-04-25 14:22:12 +0200 |
---|---|---|
committer | Christian König <christian.koenig@amd.com> | 2022-05-30 14:24:04 +0200 |
commit | 245a4a7b531cffb41233a716497c25b06835cf4b (patch) | |
tree | d9da42cead12ac1cfc5583fd14751d99c4b39140 /include/linux/dma-fence-unwrap.h | |
parent | 8f61973718485f3e89bc4f408f929048b7b47c83 (diff) | |
download | lwn-245a4a7b531cffb41233a716497c25b06835cf4b.tar.gz lwn-245a4a7b531cffb41233a716497c25b06835cf4b.zip |
dma-buf: generalize dma_fence unwrap & merging v3
Introduce a dma_fence_unwrap_merge() macro which allows to unwrap fences
which potentially can be containers as well and then merge them back
together into a flat dma_fence_array.
v2: rename the function, add some more comments about how the wrapper is
used, move filtering of signaled fences into the unwrap iterator,
add complex selftest which covers more cases.
v3: fix signaled fence filtering once more
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20220518135844.3338-5-christian.koenig@amd.com
Diffstat (limited to 'include/linux/dma-fence-unwrap.h')
-rw-r--r-- | include/linux/dma-fence-unwrap.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/linux/dma-fence-unwrap.h b/include/linux/dma-fence-unwrap.h index a4d342fef8e0..390de1ee9d35 100644 --- a/include/linux/dma-fence-unwrap.h +++ b/include/linux/dma-fence-unwrap.h @@ -52,4 +52,28 @@ struct dma_fence *dma_fence_unwrap_next(struct dma_fence_unwrap *cursor); fence = dma_fence_unwrap_next(cursor)) \ if (!dma_fence_is_signaled(fence)) +struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences, + struct dma_fence **fences, + struct dma_fence_unwrap *cursors); + +/** + * dma_fence_unwrap_merge - unwrap and merge fences + * + * 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. + * + * Returns NULL on memory allocation failure, a dma_fence object representing + * all the given fences otherwise. + */ +#define dma_fence_unwrap_merge(...) \ + ({ \ + struct dma_fence *__f[] = { __VA_ARGS__ }; \ + struct dma_fence_unwrap __c[ARRAY_SIZE(__f)]; \ + \ + __dma_fence_unwrap_merge(ARRAY_SIZE(__f), __f, __c); \ + }) + #endif |