xref: /dflybsd-src/sys/dev/drm/include/linux/dma-fence-array.h (revision 789731325bde747251c28a37e0a00ed4efb88c46)
1e2a4a6b1SFrançois Tigeot /*
2e2a4a6b1SFrançois Tigeot  * Copyright (c) 2020 François Tigeot <ftigeot@wolfpond.org>
3e2a4a6b1SFrançois Tigeot  * All rights reserved.
4e2a4a6b1SFrançois Tigeot  *
5e2a4a6b1SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
6e2a4a6b1SFrançois Tigeot  * modification, are permitted provided that the following conditions
7e2a4a6b1SFrançois Tigeot  * are met:
8e2a4a6b1SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
9e2a4a6b1SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
10e2a4a6b1SFrançois Tigeot  *    disclaimer.
11e2a4a6b1SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
12e2a4a6b1SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
13e2a4a6b1SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
14e2a4a6b1SFrançois Tigeot  *
15e2a4a6b1SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16e2a4a6b1SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17e2a4a6b1SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18e2a4a6b1SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19e2a4a6b1SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20e2a4a6b1SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21e2a4a6b1SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22e2a4a6b1SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23e2a4a6b1SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24e2a4a6b1SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25e2a4a6b1SFrançois Tigeot  */
26e2a4a6b1SFrançois Tigeot 
27e2a4a6b1SFrançois Tigeot #ifndef _LINUX_DMA_FENCE_ARRAY_H_
28e2a4a6b1SFrançois Tigeot #define _LINUX_DMA_FENCE_ARRAY_H_
29e2a4a6b1SFrançois Tigeot 
30e2a4a6b1SFrançois Tigeot #include <linux/dma-fence.h>
31*78973132SSergey Zigachev #include <linux/irq_work.h>
32e2a4a6b1SFrançois Tigeot 
33*78973132SSergey Zigachev /**
34*78973132SSergey Zigachev  * struct dma_fence_array - fence to represent an array of fences
35*78973132SSergey Zigachev  * @base: fence base class
36*78973132SSergey Zigachev  * @lock: spinlock for fence handling
37*78973132SSergey Zigachev  * @num_fences: number of fences in the array
38*78973132SSergey Zigachev  * @num_pending: fences in the array still pending
39*78973132SSergey Zigachev  * @fences: array of the fences
40*78973132SSergey Zigachev  * @work: internal irq_work function
41*78973132SSergey Zigachev  */
42e2a4a6b1SFrançois Tigeot struct dma_fence_array {
43*78973132SSergey Zigachev         struct dma_fence base;
44*78973132SSergey Zigachev 
45*78973132SSergey Zigachev         spinlock_t lock;
46e2a4a6b1SFrançois Tigeot         unsigned num_fences;
47*78973132SSergey Zigachev         atomic_t num_pending;
48e2a4a6b1SFrançois Tigeot         struct dma_fence **fences;
49*78973132SSergey Zigachev 
50*78973132SSergey Zigachev         struct irq_work work;
51e2a4a6b1SFrançois Tigeot };
52e2a4a6b1SFrançois Tigeot 
53*78973132SSergey Zigachev extern const struct dma_fence_ops dma_fence_array_ops;
54*78973132SSergey Zigachev 
55*78973132SSergey Zigachev /**
56*78973132SSergey Zigachev  * struct dma_fence_array_cb - callback helper for fence array
57*78973132SSergey Zigachev  * @cb: fence callback structure for signaling
58*78973132SSergey Zigachev  * @array: reference to the parent fence array object
59*78973132SSergey Zigachev  */
60*78973132SSergey Zigachev struct dma_fence_array_cb {
61*78973132SSergey Zigachev         struct dma_fence_cb cb;
62*78973132SSergey Zigachev         struct dma_fence_array *array;
63*78973132SSergey Zigachev };
64*78973132SSergey Zigachev 
65*78973132SSergey Zigachev /**
66*78973132SSergey Zigachev  * dma_fence_is_array - check if a fence is from the array subsclass
67*78973132SSergey Zigachev  * @fence: fence to test
68*78973132SSergey Zigachev  *
69*78973132SSergey Zigachev  * Return true if it is a dma_fence_array and false otherwise.
70*78973132SSergey Zigachev  */
dma_fence_is_array(struct dma_fence * fence)71*78973132SSergey Zigachev static inline bool dma_fence_is_array(struct dma_fence *fence)
72e2a4a6b1SFrançois Tigeot {
73*78973132SSergey Zigachev         return fence->ops == &dma_fence_array_ops;
74e2a4a6b1SFrançois Tigeot }
75e2a4a6b1SFrançois Tigeot 
76*78973132SSergey Zigachev /**
77*78973132SSergey Zigachev  * to_dma_fence_array - cast a fence to a dma_fence_array
78*78973132SSergey Zigachev  * @fence: fence to cast to a dma_fence_array
79*78973132SSergey Zigachev  *
80*78973132SSergey Zigachev  * Returns NULL if the fence is not a dma_fence_array,
81*78973132SSergey Zigachev  * or the dma_fence_array otherwise.
82*78973132SSergey Zigachev  */
83e2a4a6b1SFrançois Tigeot static inline struct dma_fence_array *
to_dma_fence_array(struct dma_fence * fence)84e2a4a6b1SFrançois Tigeot to_dma_fence_array(struct dma_fence *fence)
85e2a4a6b1SFrançois Tigeot {
86*78973132SSergey Zigachev         if (fence->ops != &dma_fence_array_ops)
87e2a4a6b1SFrançois Tigeot                 return NULL;
88*78973132SSergey Zigachev 
89*78973132SSergey Zigachev         return container_of(fence, struct dma_fence_array, base);
90e2a4a6b1SFrançois Tigeot }
91e2a4a6b1SFrançois Tigeot 
92*78973132SSergey Zigachev struct dma_fence_array *dma_fence_array_create(int num_fences,
93*78973132SSergey Zigachev                                                struct dma_fence **fences,
94*78973132SSergey Zigachev                                                u64 context, unsigned seqno,
95*78973132SSergey Zigachev                                                bool signal_on_any);
96*78973132SSergey Zigachev 
97e2a4a6b1SFrançois Tigeot #endif	/* _LINUX_DMA_FENCE_ARRAY_H_ */
98