xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/mali/linux/mali_dma_fence.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2012-2017 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10 
11 /**
12  * @file mali_dma_fence.h
13  *
14  * Mali interface for Linux dma buf fence objects.
15  */
16 
17 #ifndef _MALI_DMA_FENCE_H_
18 #define _MALI_DMA_FENCE_H_
19 
20 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)
21 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
22 #include <linux/dma-fence.h>
23 #else
24 #include <linux/fence.h>
25 #endif
26 #include <linux/reservation.h>
27 #endif
28 
29 struct mali_dma_fence_context;
30 
31 /* The mali dma fence context callback function */
32 typedef void (*mali_dma_fence_context_callback_func_t)(void *pp_job_ptr);
33 
34 struct mali_dma_fence_waiter {
35 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
36 	struct dma_fence *fence;
37 	struct dma_fence_cb base;
38 #else
39 	struct fence_cb base;
40 	struct fence *fence;
41 #endif
42 	struct mali_dma_fence_context *parent;
43 };
44 
45 struct mali_dma_fence_context {
46 	struct work_struct work_handle;
47 	struct mali_dma_fence_waiter **mali_dma_fence_waiters;
48 	u32 num_dma_fence_waiter;
49 	atomic_t count;
50 	void *pp_job_ptr; /* the mali pp job pointer */;
51 	mali_dma_fence_context_callback_func_t cb_func;
52 };
53 
54 /* Create a dma fence
55  * @param context The execution context this fence is run on
56  * @param seqno A linearly increasing sequence number for this context
57  * @return the new dma fence if success, or NULL on failure.
58  */
59 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
60 struct dma_fence *mali_dma_fence_new(u32  context, u32 seqno);
61 #else
62 struct fence *mali_dma_fence_new(u32  context, u32 seqno);
63 #endif
64 /* Signal and put dma fence
65  * @param fence The dma fence to signal and put
66  */
67 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
68 void mali_dma_fence_signal_and_put(struct dma_fence **fence);
69 #else
70 void mali_dma_fence_signal_and_put(struct fence **fence);
71 #endif
72 /**
73  * Initialize a mali dma fence context for pp job.
74  * @param dma_fence_context The mali dma fence context to initialize.
75  * @param cb_func The dma fence context callback function to call when all dma fence release.
76  * @param pp_job_ptr The pp_job to call function with.
77  */
78 void mali_dma_fence_context_init(struct mali_dma_fence_context *dma_fence_context,
79 				 mali_dma_fence_context_callback_func_t  cb_func,
80 				 void *pp_job_ptr);
81 
82 /**
83  * Add new mali dma fence waiter into mali dma fence context
84  * @param dma_fence_context The mali dma fence context
85  * @param dma_reservation_object the reservation object to create new mali dma fence waiters
86  * @return _MALI_OSK_ERR_OK if success, or not.
87  */
88 _mali_osk_errcode_t mali_dma_fence_context_add_waiters(struct mali_dma_fence_context *dma_fence_context,
89 		struct reservation_object *dma_reservation_object);
90 
91 /**
92  * Release the dma fence context
93  * @param dma_fence_text The mali dma fence context.
94  */
95 void mali_dma_fence_context_term(struct mali_dma_fence_context *dma_fence_context);
96 
97 /**
98  * Decrease the dma fence context atomic count
99  * @param dma_fence_text The mali dma fence context.
100  */
101 void mali_dma_fence_context_dec_count(struct mali_dma_fence_context *dma_fence_context);
102 
103 /**
104  * Get all reservation object
105  * @param dma_reservation_object The reservation object to add into the reservation object list
106  * @param dma_reservation_object_list The reservation object list to store all reservation object
107  * @param num_dma_reservation_object The number of all reservation object
108  */
109 void mali_dma_fence_add_reservation_object_list(struct reservation_object *dma_reservation_object,
110 		struct reservation_object **dma_reservation_object_list,
111 		u32 *num_dma_reservation_object);
112 
113 /**
114  * Wait/wound mutex lock to lock all reservation object.
115  */
116 int mali_dma_fence_lock_reservation_object_list(struct reservation_object **dma_reservation_object_list,
117 		u32  num_dma_reservation_object, struct ww_acquire_ctx *ww_actx);
118 
119 /**
120  * Wait/wound mutex lock to unlock all reservation object.
121  */
122 void mali_dma_fence_unlock_reservation_object_list(struct reservation_object **dma_reservation_object_list,
123 		u32 num_dma_reservation_object, struct ww_acquire_ctx *ww_actx);
124 #endif
125