Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * fence-array: aggregates fence to be waited together
0004  *
0005  * Copyright (C) 2016 Collabora Ltd
0006  * Copyright (C) 2016 Advanced Micro Devices, Inc.
0007  * Authors:
0008  *  Gustavo Padovan <gustavo@padovan.org>
0009  *  Christian König <christian.koenig@amd.com>
0010  */
0011 
0012 #ifndef __LINUX_DMA_FENCE_ARRAY_H
0013 #define __LINUX_DMA_FENCE_ARRAY_H
0014 
0015 #include <linux/dma-fence.h>
0016 #include <linux/irq_work.h>
0017 
0018 /**
0019  * struct dma_fence_array_cb - callback helper for fence array
0020  * @cb: fence callback structure for signaling
0021  * @array: reference to the parent fence array object
0022  */
0023 struct dma_fence_array_cb {
0024     struct dma_fence_cb cb;
0025     struct dma_fence_array *array;
0026 };
0027 
0028 /**
0029  * struct dma_fence_array - fence to represent an array of fences
0030  * @base: fence base class
0031  * @lock: spinlock for fence handling
0032  * @num_fences: number of fences in the array
0033  * @num_pending: fences in the array still pending
0034  * @fences: array of the fences
0035  * @work: internal irq_work function
0036  */
0037 struct dma_fence_array {
0038     struct dma_fence base;
0039 
0040     spinlock_t lock;
0041     unsigned num_fences;
0042     atomic_t num_pending;
0043     struct dma_fence **fences;
0044 
0045     struct irq_work work;
0046 };
0047 
0048 /**
0049  * to_dma_fence_array - cast a fence to a dma_fence_array
0050  * @fence: fence to cast to a dma_fence_array
0051  *
0052  * Returns NULL if the fence is not a dma_fence_array,
0053  * or the dma_fence_array otherwise.
0054  */
0055 static inline struct dma_fence_array *
0056 to_dma_fence_array(struct dma_fence *fence)
0057 {
0058     if (!fence || !dma_fence_is_array(fence))
0059         return NULL;
0060 
0061     return container_of(fence, struct dma_fence_array, base);
0062 }
0063 
0064 /**
0065  * dma_fence_array_for_each - iterate over all fences in array
0066  * @fence: current fence
0067  * @index: index into the array
0068  * @head: potential dma_fence_array object
0069  *
0070  * Test if @array is a dma_fence_array object and if yes iterate over all fences
0071  * in the array. If not just iterate over the fence in @array itself.
0072  *
0073  * For a deep dive iterator see dma_fence_unwrap_for_each().
0074  */
0075 #define dma_fence_array_for_each(fence, index, head)            \
0076     for (index = 0, fence = dma_fence_array_first(head); fence; \
0077          ++(index), fence = dma_fence_array_next(head, index))
0078 
0079 struct dma_fence_array *dma_fence_array_create(int num_fences,
0080                            struct dma_fence **fences,
0081                            u64 context, unsigned seqno,
0082                            bool signal_on_any);
0083 
0084 bool dma_fence_match_context(struct dma_fence *fence, u64 context);
0085 
0086 struct dma_fence *dma_fence_array_first(struct dma_fence *head);
0087 struct dma_fence *dma_fence_array_next(struct dma_fence *head,
0088                        unsigned int index);
0089 
0090 #endif /* __LINUX_DMA_FENCE_ARRAY_H */