1 /*
2 *
3 * (C) COPYRIGHT 2010-2017 ARM Limited. All rights reserved.
4 *
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
8 * of such GNU licence.
9 *
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
13 *
14 */
15
16
17
18 #ifndef _KBASE_DMA_FENCE_H_
19 #define _KBASE_DMA_FENCE_H_
20
21 #ifdef CONFIG_MALI_DMA_FENCE
22
23 #include <linux/list.h>
24 #include <linux/reservation.h>
25 #include <mali_kbase_fence.h>
26
27
28 /* Forward declaration from mali_kbase_defs.h */
29 struct kbase_jd_atom;
30 struct kbase_context;
31
32 /**
33 * struct kbase_dma_fence_resv_info - Structure with list of reservation objects
34 * @resv_objs: Array of reservation objects to attach the
35 * new fence to.
36 * @dma_fence_resv_count: Number of reservation objects in the array.
37 * @dma_fence_excl_bitmap: Specifies which resv_obj are exclusive.
38 *
39 * This is used by some functions to pass around a collection of data about
40 * reservation objects.
41 */
42 struct kbase_dma_fence_resv_info {
43 struct reservation_object **resv_objs;
44 unsigned int dma_fence_resv_count;
45 unsigned long *dma_fence_excl_bitmap;
46 };
47
48 /**
49 * kbase_dma_fence_add_reservation() - Adds a resv to the array of resv_objs
50 * @resv: Reservation object to add to the array.
51 * @info: Pointer to struct with current reservation info
52 * @exclusive: Boolean indicating if exclusive access is needed
53 *
54 * The function adds a new reservation_object to an existing array of
55 * reservation_objects. At the same time keeps track of which objects require
56 * exclusive access in dma_fence_excl_bitmap.
57 */
58 void kbase_dma_fence_add_reservation(struct reservation_object *resv,
59 struct kbase_dma_fence_resv_info *info,
60 bool exclusive);
61
62 /**
63 * kbase_dma_fence_wait() - Creates a new fence and attaches it to the resv_objs
64 * @katom: Katom with the external dependency.
65 * @info: Pointer to struct with current reservation info
66 *
67 * Return: An error code or 0 if succeeds
68 */
69 int kbase_dma_fence_wait(struct kbase_jd_atom *katom,
70 struct kbase_dma_fence_resv_info *info);
71
72 /**
73 * kbase_dma_fence_cancel_ctx() - Cancel all dma-fences blocked atoms on kctx
74 * @kctx: Pointer to kbase context
75 *
76 * This function will cancel and clean up all katoms on @kctx that is waiting
77 * on dma-buf fences.
78 *
79 * Locking: jctx.lock needs to be held when calling this function.
80 */
81 void kbase_dma_fence_cancel_all_atoms(struct kbase_context *kctx);
82
83 /**
84 * kbase_dma_fence_cancel_callbacks() - Cancel only callbacks on katom
85 * @katom: Pointer to katom whose callbacks are to be canceled
86 *
87 * This function cancels all dma-buf fence callbacks on @katom, but does not
88 * cancel the katom itself.
89 *
90 * The caller is responsible for ensuring that jd_done_nolock is called on
91 * @katom.
92 *
93 * Locking: jctx.lock must be held when calling this function.
94 */
95 void kbase_dma_fence_cancel_callbacks(struct kbase_jd_atom *katom);
96
97 /**
98 * kbase_dma_fence_signal() - Signal katom's fence and clean up after wait
99 * @katom: Pointer to katom to signal and clean up
100 *
101 * This function will signal the @katom's fence, if it has one, and clean up
102 * the callback data from the katom's wait on earlier fences.
103 *
104 * Locking: jctx.lock must be held while calling this function.
105 */
106 void kbase_dma_fence_signal(struct kbase_jd_atom *katom);
107
108 /**
109 * kbase_dma_fence_term() - Terminate Mali dma-fence context
110 * @kctx: kbase context to terminate
111 */
112 void kbase_dma_fence_term(struct kbase_context *kctx);
113
114 /**
115 * kbase_dma_fence_init() - Initialize Mali dma-fence context
116 * @kctx: kbase context to initialize
117 */
118 int kbase_dma_fence_init(struct kbase_context *kctx);
119
120
121 #else /* CONFIG_MALI_DMA_FENCE */
122 /* Dummy functions for when dma-buf fence isn't enabled. */
123
kbase_dma_fence_init(struct kbase_context * kctx)124 static inline int kbase_dma_fence_init(struct kbase_context *kctx)
125 {
126 return 0;
127 }
128
kbase_dma_fence_term(struct kbase_context * kctx)129 static inline void kbase_dma_fence_term(struct kbase_context *kctx) {}
130 #endif /* CONFIG_MALI_DMA_FENCE */
131 #endif
132