Fix common misspellings
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / gma500 / psb_ttm_fence_driver.h
1 /**************************************************************************
2 *
3 * Copyright (c) 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA
4 * All Rights Reserved.
5 * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA
6 * All Rights Reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 **************************************************************************/
22 /*
23 * Authors: Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
24 */
25 #ifndef _TTM_FENCE_DRIVER_H_
26 #define _TTM_FENCE_DRIVER_H_
27
28 #include <linux/kref.h>
29 #include <linux/spinlock.h>
30 #include <linux/wait.h>
31 #include "psb_ttm_fence_api.h"
32 #include "ttm/ttm_memory.h"
33
34 /** @file ttm_fence_driver.h
35 *
36 * Definitions needed for a driver implementing the
37 * ttm_fence subsystem.
38 */
39
40 /**
41 * struct ttm_fence_class_manager:
42 *
43 * @wrap_diff: Sequence difference to catch 32-bit wrapping.
44 * if (seqa - seqb) > @wrap_diff, then seqa < seqb.
45 * @flush_diff: Sequence difference to trigger fence flush.
46 * if (cur_seq - seqa) > @flush_diff, then consider fence object with
47 * seqa as old an needing a flush.
48 * @sequence_mask: Mask of valid bits in a fence sequence.
49 * @lock: Lock protecting this struct as well as fence objects
50 * associated with this struct.
51 * @ring: Circular sequence-ordered list of fence objects.
52 * @pending_flush: Fence types currently needing a flush.
53 * @waiting_types: Fence types that are currently waited for.
54 * @fence_queue: Queue of waiters on fences belonging to this fence class.
55 * @highest_waiting_sequence: Sequence number of the fence with highest
56 * sequence number and that is waited for.
57 * @latest_queued_sequence: Sequence number of the fence latest queued
58 * on the ring.
59 */
60
61 struct ttm_fence_class_manager {
62
63 /*
64 * Unprotected constant members.
65 */
66
67 uint32_t wrap_diff;
68 uint32_t flush_diff;
69 uint32_t sequence_mask;
70
71 /*
72 * The rwlock protects this structure as well as
73 * the data in all fence objects belonging to this
74 * class. This should be OK as most fence objects are
75 * only read from once they're created.
76 */
77
78 rwlock_t lock;
79 struct list_head ring;
80 uint32_t pending_flush;
81 uint32_t waiting_types;
82 wait_queue_head_t fence_queue;
83 uint32_t highest_waiting_sequence;
84 uint32_t latest_queued_sequence;
85 };
86
87 /**
88 * struct ttm_fence_device
89 *
90 * @fence_class: Array of fence class managers.
91 * @num_classes: Array dimension of @fence_class.
92 * @count: Current number of fence objects for statistics.
93 * @driver: Driver struct.
94 *
95 * Provided in the driver interface so that the driver can derive
96 * from this struct for its driver_private, and accordingly
97 * access the driver_private from the fence driver callbacks.
98 *
99 * All members except "count" are initialized at creation and
100 * never touched after that. No protection needed.
101 *
102 * This struct is private to the fence implementation and to the fence
103 * driver callbacks, and may otherwise be used by drivers only to
104 * obtain the derived device_private object using container_of().
105 */
106
107 struct ttm_fence_device {
108 struct ttm_mem_global *mem_glob;
109 struct ttm_fence_class_manager *fence_class;
110 uint32_t num_classes;
111 atomic_t count;
112 const struct ttm_fence_driver *driver;
113 };
114
115 /**
116 * struct ttm_fence_class_init
117 *
118 * @wrap_diff: Fence sequence number wrap indicator. If
119 * (sequence1 - sequence2) > @wrap_diff, then sequence1 is
120 * considered to be older than sequence2.
121 * @flush_diff: Fence sequence number flush indicator.
122 * If a non-completely-signaled fence has a fence sequence number
123 * sequence1 and (sequence1 - current_emit_sequence) > @flush_diff,
124 * the fence is considered too old and it will be flushed upon the
125 * next call of ttm_fence_flush_old(), to make sure no fences with
126 * stale sequence numbers remains unsignaled. @flush_diff should
127 * be sufficiently less than @wrap_diff.
128 * @sequence_mask: Mask with valid bits of the fence sequence
129 * number set to 1.
130 *
131 * This struct is used as input to ttm_fence_device_init.
132 */
133
134 struct ttm_fence_class_init {
135 uint32_t wrap_diff;
136 uint32_t flush_diff;
137 uint32_t sequence_mask;
138 };
139
140 /**
141 * struct ttm_fence_driver
142 *
143 * @has_irq: Called by a potential waiter. Should return 1 if a
144 * fence object with indicated parameters is expected to signal
145 * automatically, and 0 if the fence implementation needs to
146 * repeatedly call @poll to make it signal.
147 * @emit: Make sure a fence with the given parameters is
148 * present in the indicated command stream. Return its sequence number
149 * in "breadcrumb".
150 * @poll: Check and report sequences of the given "fence_class"
151 * that have signaled "types"
152 * @flush: Make sure that the types indicated by the bitfield
153 * ttm_fence_class_manager::pending_flush will eventually
154 * signal. These bits have been put together using the
155 * result from the needed_flush function described below.
156 * @needed_flush: Given the fence_class and fence_types indicated by
157 * "fence", and the last received fence sequence of this
158 * fence class, indicate what types need a fence flush to
159 * signal. Return as a bitfield.
160 * @wait: Set to non-NULL if the driver wants to override the fence
161 * wait implementation. Return 0 on success, -EBUSY on failure,
162 * and -ERESTART if interruptible and a signal is pending.
163 * @signaled: Driver callback that is called whenever a
164 * ttm_fence_object::signaled_types has changed status.
165 * This function is called from atomic context,
166 * with the ttm_fence_class_manager::lock held in write mode.
167 * @lockup: Driver callback that is called whenever a wait has exceeded
168 * the lifetime of a fence object.
169 * If there is a GPU lockup,
170 * this function should, if possible, reset the GPU,
171 * call the ttm_fence_handler with an error status, and
172 * return. If no lockup was detected, simply extend the
173 * fence timeout_jiffies and return. The driver might
174 * want to protect the lockup check with a mutex and cache a
175 * non-locked-up status for a while to avoid an excessive
176 * amount of lockup checks from every waiting thread.
177 */
178
179 struct ttm_fence_driver {
180 bool (*has_irq) (struct ttm_fence_device *fdev,
181 uint32_t fence_class, uint32_t flags);
182 int (*emit) (struct ttm_fence_device *fdev,
183 uint32_t fence_class,
184 uint32_t flags,
185 uint32_t *breadcrumb, unsigned long *timeout_jiffies);
186 void (*flush) (struct ttm_fence_device *fdev, uint32_t fence_class);
187 void (*poll) (struct ttm_fence_device *fdev,
188 uint32_t fence_class, uint32_t types);
189 uint32_t(*needed_flush)
190 (struct ttm_fence_object *fence);
191 int (*wait) (struct ttm_fence_object *fence, bool lazy,
192 bool interruptible, uint32_t mask);
193 void (*signaled) (struct ttm_fence_object *fence);
194 void (*lockup) (struct ttm_fence_object *fence, uint32_t fence_types);
195 };
196
197 /**
198 * function ttm_fence_device_init
199 *
200 * @num_classes: Number of fence classes for this fence implementation.
201 * @mem_global: Pointer to the global memory accounting info.
202 * @fdev: Pointer to an uninitialised struct ttm_fence_device.
203 * @init: Array of initialization info for each fence class.
204 * @replicate_init: Use the first @init initialization info for all classes.
205 * @driver: Driver callbacks.
206 *
207 * Initialize a struct ttm_fence_driver structure. Returns -ENOMEM if
208 * out-of-memory. Otherwise returns 0.
209 */
210 extern int
211 ttm_fence_device_init(int num_classes,
212 struct ttm_mem_global *mem_glob,
213 struct ttm_fence_device *fdev,
214 const struct ttm_fence_class_init *init,
215 bool replicate_init,
216 const struct ttm_fence_driver *driver);
217
218 /**
219 * function ttm_fence_device_release
220 *
221 * @fdev: Pointer to the fence device.
222 *
223 * Release all resources held by a fence device. Note that before
224 * this function is called, the caller must have made sure all fence
225 * objects belonging to this fence device are completely signaled.
226 */
227
228 extern void ttm_fence_device_release(struct ttm_fence_device *fdev);
229
230 /**
231 * ttm_fence_handler - the fence handler.
232 *
233 * @fdev: Pointer to the fence device.
234 * @fence_class: Fence class that signals.
235 * @sequence: Signaled sequence.
236 * @type: Types that signal.
237 * @error: Error from the engine.
238 *
239 * This function signals all fences with a sequence previous to the
240 * @sequence argument, and belonging to @fence_class. The signaled fence
241 * types are provided in @type. If error is non-zero, the error member
242 * of the fence with sequence = @sequence is set to @error. This value
243 * may be reported back to user-space, indicating, for example an illegal
244 * 3D command or illegal mpeg data.
245 *
246 * This function is typically called from the driver::poll method when the
247 * command sequence preceding the fence marker has executed. It should be
248 * called with the ttm_fence_class_manager::lock held in write mode and
249 * may be called from interrupt context.
250 */
251
252 extern void
253 ttm_fence_handler(struct ttm_fence_device *fdev,
254 uint32_t fence_class,
255 uint32_t sequence, uint32_t type, uint32_t error);
256
257 /**
258 * ttm_fence_driver_from_dev
259 *
260 * @fdev: The ttm fence device.
261 *
262 * Returns a pointer to the fence driver struct.
263 */
264
265 static inline const struct ttm_fence_driver *ttm_fence_driver_from_dev(
266 struct ttm_fence_device *fdev)
267 {
268 return fdev->driver;
269 }
270
271 /**
272 * ttm_fence_driver
273 *
274 * @fence: Pointer to a ttm fence object.
275 *
276 * Returns a pointer to the fence driver struct.
277 */
278
279 static inline const struct ttm_fence_driver *ttm_fence_driver(struct
280 ttm_fence_object
281 *fence)
282 {
283 return ttm_fence_driver_from_dev(fence->fdev);
284 }
285
286 /**
287 * ttm_fence_fc
288 *
289 * @fence: Pointer to a ttm fence object.
290 *
291 * Returns a pointer to the struct ttm_fence_class_manager for the
292 * fence class of @fence.
293 */
294
295 static inline struct ttm_fence_class_manager *ttm_fence_fc(struct
296 ttm_fence_object
297 *fence)
298 {
299 return &fence->fdev->fence_class[fence->fence_class];
300 }
301
302 #endif