xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/mali/linux/mali_internal_sync.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2012-2015, 2017-2018 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_internal_sync.h
13  *
14  * Mali internal structure/interface for sync.
15  */
16 
17 #ifndef _MALI_INTERNAL_SYNC_H
18 #define _MALI_INTERNAL_SYNC_H
19 #include <linux/version.h>
20 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
21 #include <linux/types.h>
22 #include <linux/kref.h>
23 #include <linux/list.h>
24 #include <linux/spinlock.h>
25 #include <linux/wait.h>
26 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
27 #include <sync.h>
28 #else
29 #include <linux/sync_file.h>
30 #endif
31 
32 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
33 #include <linux/dma-fence.h>
34 #else
35 #include <linux/fence.h>
36 #endif
37 
38 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
39 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
40 #include <linux/fence-array.h>
41 #else
42 #include <linux/dma-fence-array.h>
43 #endif
44 #endif
45 
46 struct mali_internal_sync_timeline;
47 struct mali_internal_sync_point;
48 struct mali_internal_sync_fence;
49 
50 struct mali_internal_sync_timeline_ops {
51 	const char *driver_name;
52 	int (*has_signaled)(struct mali_internal_sync_point *pt);
53 	void (*free_pt)(struct mali_internal_sync_point *sync_pt);
54 	void (*release_obj)(struct mali_internal_sync_timeline *sync_timeline);
55 	void (*print_sync_pt)(struct mali_internal_sync_point *sync_pt);
56 };
57 
58 struct mali_internal_sync_timeline {
59 	struct kref             kref_count;
60 	const struct mali_internal_sync_timeline_ops  *ops;
61 	char                    name[32];
62 	bool                    destroyed;
63 	int                     fence_context;
64 	int                     value;
65 	spinlock_t              sync_pt_list_lock;
66 	struct list_head        sync_pt_list_head;
67 };
68 
69 struct mali_internal_sync_point {
70 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
71 	struct dma_fence base;
72 #else
73 	struct fence base;
74 #endif
75 	struct list_head        sync_pt_list;
76 };
77 
78 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)
79 struct mali_internal_sync_fence_cb {
80 	struct fence_cb cb;
81 	struct fence *fence;
82 	struct mali_internal_sync_fence *sync_file;
83 };
84 #endif
85 
86 struct mali_internal_sync_fence {
87 	struct file             *file;
88 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)
89 	struct kref             kref;
90 #endif
91 	char            name[32];
92 #ifdef CONFIG_DEBUG_FS
93 	struct list_head        sync_file_list;
94 #endif
95 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)
96 	int num_fences;
97 #endif
98 	wait_queue_head_t       wq;
99 #if LINUX_VERSION_CODE > KERNEL_VERSION(4, 12, 0)
100 	unsigned long		flags;
101 #endif
102 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)
103 	atomic_t                status;
104 	struct mali_internal_sync_fence_cb    cbs[];
105 #elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
106 	struct fence *fence;
107 	struct fence_cb cb;
108 #else
109 	struct dma_fence *fence;
110 	struct dma_fence_cb cb;
111 #endif
112 };
113 
114 struct mali_internal_sync_fence_waiter;
115 
116 typedef void (*mali_internal_sync_callback_t)(struct mali_internal_sync_fence *sync_fence,
117 		struct mali_internal_sync_fence_waiter *waiter);
118 
119 struct mali_internal_sync_fence_waiter {
120 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
121 	wait_queue_entry_t work;
122 #else
123 	wait_queue_t work;
124 #endif
125 	mali_internal_sync_callback_t callback;
126 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
127 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
128 	struct fence_cb cb;
129 #else
130 	struct dma_fence_cb cb;
131 #endif
132 #endif
133 };
134 
135 /**
136  * Create a mali internal sync timeline.
137  * @param ops The implementation ops for the mali internal sync timeline
138  * @param size The size to allocate
139  * @param name The sync_timeline name
140  * @return The new mali internal sync timeline if successful, NULL if not.
141  */
142 struct mali_internal_sync_timeline *mali_internal_sync_timeline_create(const struct mali_internal_sync_timeline_ops *ops,
143 		int size, const char *name);
144 
145 /**
146  * Destroy one mali internal sync timeline.
147  * @param sync_timeline The mali internal sync timeline to destroy.
148  */
149 void mali_internal_sync_timeline_destroy(struct mali_internal_sync_timeline *sync_timeline);
150 
151 /**
152  * Signal one mali internal sync timeline.
153  * @param sync_timeline The mali internal sync timeline to signal.
154  */
155 void mali_internal_sync_timeline_signal(struct mali_internal_sync_timeline *sync_timeline);
156 
157 /**
158  * Create one mali internal sync point.
159  * @param sync_timeline The mali internal sync timeline to add this mali internal sync point.
160   * @return the new mali internal sync point if successful, NULL if not.
161  */
162 struct mali_internal_sync_point *mali_internal_sync_point_create(struct mali_internal_sync_timeline *sync_timeline, int size);
163 
164 /**
165  * Merge mali internal sync fences
166  * @param sync_fence1 The mali internal sync fence to merge
167  * @param sync_fence2 The mali internal sync fence to merge
168  * @return the new mali internal sync fence if successful, NULL if not.
169  */
170 struct mali_internal_sync_fence *mali_internal_sync_fence_merge(struct mali_internal_sync_fence *sync_fence1,
171 		struct mali_internal_sync_fence *sync_fence2);
172 
173 /**
174  * Get the mali internal sync fence from sync fd
175  * @param fd The sync handle to get the mali internal sync fence
176  * @return the mali internal sync fence if successful, NULL if not.
177  */
178 struct mali_internal_sync_fence *mali_internal_sync_fence_fdget(int fd);
179 
180 
181 void mali_internal_sync_fence_waiter_init(struct mali_internal_sync_fence_waiter *waiter,
182 		mali_internal_sync_callback_t callback);
183 
184 int mali_internal_sync_fence_wait_async(struct mali_internal_sync_fence *sync_fence,
185 					struct mali_internal_sync_fence_waiter *waiter);
186 
187 int mali_internal_sync_fence_cancel_async(struct mali_internal_sync_fence *sync_fence,
188 		struct mali_internal_sync_fence_waiter *waiter);
189 
190 #endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)*/
191 #endif /* _MALI_INTERNAL_SYNC_H */
192