Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2022 Advanced Micro Devices, Inc.
0004  * Authors:
0005  *  Christian König <christian.koenig@amd.com>
0006  */
0007 
0008 #ifndef __LINUX_DMA_FENCE_UNWRAP_H
0009 #define __LINUX_DMA_FENCE_UNWRAP_H
0010 
0011 struct dma_fence;
0012 
0013 /**
0014  * struct dma_fence_unwrap - cursor into the container structure
0015  *
0016  * Should be used with dma_fence_unwrap_for_each() iterator macro.
0017  */
0018 struct dma_fence_unwrap {
0019     /**
0020      * @chain: potential dma_fence_chain, but can be other fence as well
0021      */
0022     struct dma_fence *chain;
0023     /**
0024      * @array: potential dma_fence_array, but can be other fence as well
0025      */
0026     struct dma_fence *array;
0027     /**
0028      * @index: last returned index if @array is really a dma_fence_array
0029      */
0030     unsigned int index;
0031 };
0032 
0033 struct dma_fence *dma_fence_unwrap_first(struct dma_fence *head,
0034                      struct dma_fence_unwrap *cursor);
0035 struct dma_fence *dma_fence_unwrap_next(struct dma_fence_unwrap *cursor);
0036 
0037 /**
0038  * dma_fence_unwrap_for_each - iterate over all fences in containers
0039  * @fence: current fence
0040  * @cursor: current position inside the containers
0041  * @head: starting point for the iterator
0042  *
0043  * Unwrap dma_fence_chain and dma_fence_array containers and deep dive into all
0044  * potential fences in them. If @head is just a normal fence only that one is
0045  * returned.
0046  */
0047 #define dma_fence_unwrap_for_each(fence, cursor, head)          \
0048     for (fence = dma_fence_unwrap_first(head, cursor); fence;   \
0049          fence = dma_fence_unwrap_next(cursor))
0050 
0051 struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
0052                        struct dma_fence **fences,
0053                        struct dma_fence_unwrap *cursors);
0054 
0055 /**
0056  * dma_fence_unwrap_merge - unwrap and merge fences
0057  *
0058  * All fences given as parameters are unwrapped and merged back together as flat
0059  * dma_fence_array. Useful if multiple containers need to be merged together.
0060  *
0061  * Implemented as a macro to allocate the necessary arrays on the stack and
0062  * account the stack frame size to the caller.
0063  *
0064  * Returns NULL on memory allocation failure, a dma_fence object representing
0065  * all the given fences otherwise.
0066  */
0067 #define dma_fence_unwrap_merge(...)                 \
0068     ({                              \
0069         struct dma_fence *__f[] = { __VA_ARGS__ };      \
0070         struct dma_fence_unwrap __c[ARRAY_SIZE(__f)];       \
0071                                     \
0072         __dma_fence_unwrap_merge(ARRAY_SIZE(__f), __f, __c);    \
0073     })
0074 
0075 #endif