aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/cdv/imgv/psb_ttm_fence_api.h
blob: d42904c4ec2f13238681020f2d968a6a2838ecb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/**************************************************************************
 *
 * Copyright (c) 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA
 * All Rights Reserved.
 * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 **************************************************************************/
/*
 * Authors: Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
 */
#ifndef _TTM_FENCE_API_H_
#define _TTM_FENCE_API_H_

#include <linux/list.h>
#include <linux/kref.h>

#define TTM_FENCE_FLAG_EMIT (1 << 0)
#define TTM_FENCE_TYPE_EXE  (1 << 0)

struct ttm_fence_device;

/**
 * struct ttm_fence_info
 *
 * @fence_class:    The fence class.
 * @fence_type:     Bitfield indicating types for this fence.
 * @signaled_types: Bitfield indicating which types are signaled.
 * @error:          Last error reported from the device.
 *
 * Used as output from the ttm_fence_get_info
 */

struct ttm_fence_info {
	uint32_t signaled_types;
	uint32_t error;
};

/**
 * struct ttm_fence_object
 *
 * @fdev:            Pointer to the fence device struct.
 * @kref:            Holds the reference count of this fence object.
 * @ring:            List head used for the circular list of not-completely
 *                   signaled fences.
 * @info:            Data for fast retrieval using the ttm_fence_get_info()
 * function.
 * @timeout_jiffies: Absolute jiffies value indicating when this fence
 *                   object times out and, if waited on, calls ttm_fence_lockup
 *                   to check for and resolve a GPU lockup.
 * @sequence:        Fence sequence number.
 * @waiting_types:   Types currently waited on.
 * @destroy:         Called to free the fence object, when its refcount has
 *                   reached zero. If NULL, kfree is used.
 *
 * This struct is provided in the driver interface so that drivers can
 * derive from it and create their own fence implementation. All members
 * are private to the fence implementation and the fence driver callbacks.
 * Otherwise a driver may access the derived object using container_of().
 */

struct ttm_fence_object {
	struct ttm_fence_device *fdev;
	struct kref kref;
	uint32_t fence_class;
	uint32_t fence_type;

	/*
	 * The below fields are protected by the fence class
	 * manager spinlock.
	 */

	struct list_head ring;
	struct ttm_fence_info info;
	unsigned long timeout_jiffies;
	uint32_t sequence;
	uint32_t waiting_types;
	void (*destroy) (struct ttm_fence_object *);
};

/**
 * ttm_fence_object_init
 *
 * @fdev: Pointer to a struct ttm_fence_device.
 * @fence_class: Fence class for this fence.
 * @type: Fence type for this fence.
 * @create_flags: Flags indicating varios actions at init time. At this point
 * there's only TTM_FENCE_FLAG_EMIT, which triggers a sequence emission to
 * the command stream.
 * @destroy: Destroy function. If NULL, kfree() is used.
 * @fence: The struct ttm_fence_object to initialize.
 *
 * Initialize a pre-allocated fence object. This function, together with the
 * destroy function makes it possible to derive driver-specific fence objects.
 */

extern int
ttm_fence_object_init(struct ttm_fence_device *fdev,
		      uint32_t fence_class,
		      uint32_t type,
		      uint32_t create_flags,
		      void (*destroy) (struct ttm_fence_object *fence),
		      struct ttm_fence_object *fence);

/**
 * ttm_fence_object_create
 *
 * @fdev: Pointer to a struct ttm_fence_device.
 * @fence_class: Fence class for this fence.
 * @type: Fence type for this fence.
 * @create_flags: Flags indicating varios actions at init time. At this point
 * there's only TTM_FENCE_FLAG_EMIT, which triggers a sequence emission to
 * the command stream.
 * @c_fence: On successful termination, *(@c_fence) will point to the created
 * fence object.
 *
 * Create and initialize a struct ttm_fence_object. The destroy function will
 * be set to kfree().
 */

extern int
ttm_fence_object_create(struct ttm_fence_device *fdev,
			uint32_t fence_class,
			uint32_t type,
			uint32_t create_flags,
			struct ttm_fence_object **c_fence);

/**
 * ttm_fence_object_wait
 *
 * @fence: The fence object to wait on.
 * @lazy: Allow sleeps to reduce the cpu-usage if polling.
 * @interruptible: Sleep interruptible when waiting.
 * @type_mask: Wait for the given type_mask to signal.
 *
 * Wait for a fence to signal the given type_mask. The function will
 * perform a fence_flush using type_mask. (See ttm_fence_object_flush).
 *
 * Returns
 * -ERESTART if interrupted by a signal.
 * May return driver-specific error codes if timed-out.
 */

extern int
ttm_fence_object_wait(struct ttm_fence_object *fence,
		      bool lazy, bool interruptible, uint32_t type_mask);

/**
 * ttm_fence_object_flush
 *
 * @fence: The fence object to flush.
 * @flush_mask: Fence types to flush.
 *
 * Make sure that the given fence eventually signals the
 * types indicated by @flush_mask. Note that this may or may not
 * map to a CPU or GPU flush.
 */

extern int
ttm_fence_object_flush(struct ttm_fence_object *fence, uint32_t flush_mask);

/**
 * ttm_fence_get_info
 *
 * @fence: The fence object.
 *
 * Copy the info block from the fence while holding relevant locks.
 */

struct ttm_fence_info ttm_fence_get_info(struct ttm_fence_object *fence);

/**
 * ttm_fence_object_ref
 *
 * @fence: The fence object.
 *
 * Return a ref-counted pointer to the fence object indicated by @fence.
 */

static inline struct ttm_fence_object *ttm_fence_object_ref(struct
							    ttm_fence_object
							    *fence)
{
	kref_get(&fence->kref);
	return fence;
}

/**
 * ttm_fence_object_unref
 *
 * @p_fence: Pointer to a ref-counted pinter to a struct ttm_fence_object.
 *
 * Unreference the fence object pointed to by *(@p_fence), clearing
 * *(p_fence).
 */

extern void ttm_fence_object_unref(struct ttm_fence_object **p_fence);

/**
 * ttm_fence_object_signaled
 *
 * @fence: Pointer to the struct ttm_fence_object.
 * @mask: Type mask to check whether signaled.
 *
 * This function checks (without waiting) whether the fence object
 * pointed to by @fence has signaled the types indicated by @mask,
 * and returns 1 if true, 0 if false. This function does NOT perform
 * an implicit fence flush.
 */

extern bool
ttm_fence_object_signaled(struct ttm_fence_object *fence, uint32_t mask);

/**
 * ttm_fence_class
 *
 * @fence: Pointer to the struct ttm_fence_object.
 *
 * Convenience function that returns the fence class of a
 * struct ttm_fence_object.
 */

static inline uint32_t ttm_fence_class(const struct ttm_fence_object *fence)
{
	return fence->fence_class;
}

/**
 * ttm_fence_types
 *
 * @fence: Pointer to the struct ttm_fence_object.
 *
 * Convenience function that returns the fence types of a
 * struct ttm_fence_object.
 */

static inline uint32_t ttm_fence_types(const struct ttm_fence_object *fence)
{
	return fence->fence_type;
}

/*
 * The functions below are wrappers to the above functions, with
 * similar names but with sync_obj omitted. These wrappers are intended
 * to be plugged directly into the buffer object driver's sync object
 * API, if the driver chooses to use ttm_fence_objects as buffer object
 * sync objects. In the prototypes below, a sync_obj is cast to a
 * struct ttm_fence_object, whereas a sync_arg is cast to an
 * uint32_t representing a fence_type argument.
 */

extern bool ttm_fence_sync_obj_signaled(void *sync_obj, void *sync_arg);
extern int ttm_fence_sync_obj_wait(void *sync_obj, void *sync_arg,
				   bool lazy, bool interruptible);
extern int ttm_fence_sync_obj_flush(void *sync_obj, void *sync_arg);
extern void ttm_fence_sync_obj_unref(void **sync_obj);
extern void *ttm_fence_sync_obj_ref(void *sync_obj);

#endif