1 #ifndef _MSM_KGSL_H
2 #define _MSM_KGSL_H
3 
4 #define KGSL_VERSION_MAJOR        3
5 #define KGSL_VERSION_MINOR        14
6 
7 /*context flags */
8 #define KGSL_CONTEXT_SAVE_GMEM		0x00000001
9 #define KGSL_CONTEXT_NO_GMEM_ALLOC	0x00000002
10 #define KGSL_CONTEXT_SUBMIT_IB_LIST	0x00000004
11 #define KGSL_CONTEXT_CTX_SWITCH		0x00000008
12 #define KGSL_CONTEXT_PREAMBLE		0x00000010
13 #define KGSL_CONTEXT_TRASH_STATE	0x00000020
14 #define KGSL_CONTEXT_PER_CONTEXT_TS	0x00000040
15 #define KGSL_CONTEXT_USER_GENERATED_TS	0x00000080
16 
17 #define KGSL_CONTEXT_INVALID 0xffffffff
18 
19 /* Memory allocayion flags */
20 #define KGSL_MEMFLAGS_GPUREADONLY	0x01000000
21 
22 #define KGSL_MEMTYPE_MASK		0x0000FF00
23 #define KGSL_MEMTYPE_SHIFT		8
24 
25 /* Memory types for which allocations are made */
26 #define KGSL_MEMTYPE_OBJECTANY			0
27 #define KGSL_MEMTYPE_FRAMEBUFFER		1
28 #define KGSL_MEMTYPE_RENDERBUFFER		2
29 #define KGSL_MEMTYPE_ARRAYBUFFER		3
30 #define KGSL_MEMTYPE_ELEMENTARRAYBUFFER		4
31 #define KGSL_MEMTYPE_VERTEXARRAYBUFFER		5
32 #define KGSL_MEMTYPE_TEXTURE			6
33 #define KGSL_MEMTYPE_SURFACE			7
34 #define KGSL_MEMTYPE_EGL_SURFACE		8
35 #define KGSL_MEMTYPE_GL				9
36 #define KGSL_MEMTYPE_CL				10
37 #define KGSL_MEMTYPE_CL_BUFFER_MAP		11
38 #define KGSL_MEMTYPE_CL_BUFFER_NOMAP		12
39 #define KGSL_MEMTYPE_CL_IMAGE_MAP		13
40 #define KGSL_MEMTYPE_CL_IMAGE_NOMAP		14
41 #define KGSL_MEMTYPE_CL_KERNEL_STACK		15
42 #define KGSL_MEMTYPE_COMMAND			16
43 #define KGSL_MEMTYPE_2D				17
44 #define KGSL_MEMTYPE_EGL_IMAGE			18
45 #define KGSL_MEMTYPE_EGL_SHADOW			19
46 #define KGSL_MEMTYPE_MULTISAMPLE		20
47 #define KGSL_MEMTYPE_KERNEL			255
48 
49 /*
50  * Alignment hint, passed as the power of 2 exponent.
51  * i.e 4k (2^12) would be 12, 64k (2^16)would be 16.
52  */
53 #define KGSL_MEMALIGN_MASK		0x00FF0000
54 #define KGSL_MEMALIGN_SHIFT		16
55 
56 /* generic flag values */
57 #define KGSL_FLAGS_NORMALMODE  0x00000000
58 #define KGSL_FLAGS_SAFEMODE    0x00000001
59 #define KGSL_FLAGS_INITIALIZED0 0x00000002
60 #define KGSL_FLAGS_INITIALIZED 0x00000004
61 #define KGSL_FLAGS_STARTED     0x00000008
62 #define KGSL_FLAGS_ACTIVE      0x00000010
63 #define KGSL_FLAGS_RESERVED0   0x00000020
64 #define KGSL_FLAGS_RESERVED1   0x00000040
65 #define KGSL_FLAGS_RESERVED2   0x00000080
66 #define KGSL_FLAGS_SOFT_RESET  0x00000100
67 #define KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS 0x00000200
68 
69 /* Clock flags to show which clocks should be controled by a given platform */
70 #define KGSL_CLK_SRC	0x00000001
71 #define KGSL_CLK_CORE	0x00000002
72 #define KGSL_CLK_IFACE	0x00000004
73 #define KGSL_CLK_MEM	0x00000008
74 #define KGSL_CLK_MEM_IFACE 0x00000010
75 #define KGSL_CLK_AXI	0x00000020
76 
77 /* Server Side Sync Timeout in milliseconds */
78 #define KGSL_SYNCOBJ_SERVER_TIMEOUT 2000
79 
80 /*
81  * Reset status values for context
82  */
83 enum kgsl_ctx_reset_stat {
84 	KGSL_CTX_STAT_NO_ERROR				= 0x00000000,
85 	KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT		= 0x00000001,
86 	KGSL_CTX_STAT_INNOCENT_CONTEXT_RESET_EXT	= 0x00000002,
87 	KGSL_CTX_STAT_UNKNOWN_CONTEXT_RESET_EXT		= 0x00000003
88 };
89 
90 #define KGSL_CONVERT_TO_MBPS(val) \
91 	(val*1000*1000U)
92 
93 /* device id */
94 enum kgsl_deviceid {
95 	KGSL_DEVICE_3D0		= 0x00000000,
96 	KGSL_DEVICE_2D0		= 0x00000001,
97 	KGSL_DEVICE_2D1		= 0x00000002,
98 	KGSL_DEVICE_MAX		= 0x00000003
99 };
100 
101 enum kgsl_user_mem_type {
102 	KGSL_USER_MEM_TYPE_PMEM		= 0x00000000,
103 	KGSL_USER_MEM_TYPE_ASHMEM	= 0x00000001,
104 	KGSL_USER_MEM_TYPE_ADDR		= 0x00000002,
105 	KGSL_USER_MEM_TYPE_ION		= 0x00000003,
106 	KGSL_USER_MEM_TYPE_MAX		= 0x00000004,
107 };
108 
109 struct kgsl_devinfo {
110 
111 	unsigned int device_id;
112 	/* chip revision id
113 	* coreid:8 majorrev:8 minorrev:8 patch:8
114 	*/
115 	unsigned int chip_id;
116 	unsigned int mmu_enabled;
117 	unsigned int gmem_gpubaseaddr;
118 	/*
119 	* This field contains the adreno revision
120 	* number 200, 205, 220, etc...
121 	*/
122 	unsigned int gpu_id;
123 	unsigned int gmem_sizebytes;
124 };
125 
126 /* this structure defines the region of memory that can be mmap()ed from this
127    driver. The timestamp fields are volatile because they are written by the
128    GPU
129 */
130 struct kgsl_devmemstore {
131 	volatile unsigned int soptimestamp;
132 	unsigned int sbz;
133 	volatile unsigned int eoptimestamp;
134 	unsigned int sbz2;
135 	volatile unsigned int ts_cmp_enable;
136 	unsigned int sbz3;
137 	volatile unsigned int ref_wait_ts;
138 	unsigned int sbz4;
139 	unsigned int current_context;
140 	unsigned int sbz5;
141 };
142 
143 #define KGSL_MEMSTORE_OFFSET(ctxt_id, field) \
144 	((ctxt_id)*sizeof(struct kgsl_devmemstore) + \
145 	 offsetof(struct kgsl_devmemstore, field))
146 
147 /* timestamp id*/
148 enum kgsl_timestamp_type {
149 	KGSL_TIMESTAMP_CONSUMED = 0x00000001, /* start-of-pipeline timestamp */
150 	KGSL_TIMESTAMP_RETIRED  = 0x00000002, /* end-of-pipeline timestamp*/
151 	KGSL_TIMESTAMP_QUEUED   = 0x00000003,
152 };
153 
154 /* property types - used with kgsl_device_getproperty */
155 enum kgsl_property_type {
156 	KGSL_PROP_DEVICE_INFO     = 0x00000001,
157 	KGSL_PROP_DEVICE_SHADOW   = 0x00000002,
158 	KGSL_PROP_DEVICE_POWER    = 0x00000003,
159 	KGSL_PROP_SHMEM           = 0x00000004,
160 	KGSL_PROP_SHMEM_APERTURES = 0x00000005,
161 	KGSL_PROP_MMU_ENABLE 	  = 0x00000006,
162 	KGSL_PROP_INTERRUPT_WAITS = 0x00000007,
163 	KGSL_PROP_VERSION         = 0x00000008,
164 	KGSL_PROP_GPU_RESET_STAT  = 0x00000009,
165 	KGSL_PROP_PWRCTRL         = 0x0000000E,
166 };
167 
168 struct kgsl_shadowprop {
169 	unsigned int gpuaddr;
170 	unsigned int size;
171 	unsigned int flags; /* contains KGSL_FLAGS_ values */
172 };
173 
174 struct kgsl_version {
175 	unsigned int drv_major;
176 	unsigned int drv_minor;
177 	unsigned int dev_major;
178 	unsigned int dev_minor;
179 };
180 
181 /* structure holds list of ibs */
182 struct kgsl_ibdesc {
183 	unsigned int gpuaddr;
184 	void *hostptr;
185 	unsigned int sizedwords;
186 	unsigned int ctrl;
187 };
188 
189 /* ioctls */
190 #define KGSL_IOC_TYPE 0x09
191 
192 /* get misc info about the GPU
193    type should be a value from enum kgsl_property_type
194    value points to a structure that varies based on type
195    sizebytes is sizeof() that structure
196    for KGSL_PROP_DEVICE_INFO, use struct kgsl_devinfo
197    this structure contaings hardware versioning info.
198    for KGSL_PROP_DEVICE_SHADOW, use struct kgsl_shadowprop
199    this is used to find mmap() offset and sizes for mapping
200    struct kgsl_memstore into userspace.
201 */
202 struct kgsl_device_getproperty {
203 	unsigned int type;
204 	void  *value;
205 	unsigned int sizebytes;
206 };
207 
208 #define IOCTL_KGSL_DEVICE_GETPROPERTY \
209 	_IOWR(KGSL_IOC_TYPE, 0x2, struct kgsl_device_getproperty)
210 
211 /* IOCTL_KGSL_DEVICE_READ (0x3) - removed 03/2012
212  */
213 
214 /* block until the GPU has executed past a given timestamp
215  * timeout is in milliseconds.
216  */
217 struct kgsl_device_waittimestamp {
218 	unsigned int timestamp;
219 	unsigned int timeout;
220 };
221 
222 #define IOCTL_KGSL_DEVICE_WAITTIMESTAMP \
223 	_IOW(KGSL_IOC_TYPE, 0x6, struct kgsl_device_waittimestamp)
224 
225 struct kgsl_device_waittimestamp_ctxtid {
226 	unsigned int context_id;
227 	unsigned int timestamp;
228 	unsigned int timeout;
229 };
230 
231 #define IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID \
232 	_IOW(KGSL_IOC_TYPE, 0x7, struct kgsl_device_waittimestamp_ctxtid)
233 
234 /* issue indirect commands to the GPU.
235  * drawctxt_id must have been created with IOCTL_KGSL_DRAWCTXT_CREATE
236  * ibaddr and sizedwords must specify a subset of a buffer created
237  * with IOCTL_KGSL_SHAREDMEM_FROM_PMEM
238  * flags may be a mask of KGSL_CONTEXT_ values
239  * timestamp is a returned counter value which can be passed to
240  * other ioctls to determine when the commands have been executed by
241  * the GPU.
242  */
243 struct kgsl_ringbuffer_issueibcmds {
244 	unsigned int drawctxt_id;
245 	unsigned int ibdesc_addr;
246 	unsigned int numibs;
247 	unsigned int timestamp; /*output param */
248 	unsigned int flags;
249 };
250 
251 #define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS \
252 	_IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds)
253 
254 /* read the most recently executed timestamp value
255  * type should be a value from enum kgsl_timestamp_type
256  */
257 struct kgsl_cmdstream_readtimestamp {
258 	unsigned int type;
259 	unsigned int timestamp; /*output param */
260 };
261 
262 #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD \
263 	_IOR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp)
264 
265 #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP \
266 	_IOWR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp)
267 
268 /* free memory when the GPU reaches a given timestamp.
269  * gpuaddr specify a memory region created by a
270  * IOCTL_KGSL_SHAREDMEM_FROM_PMEM call
271  * type should be a value from enum kgsl_timestamp_type
272  */
273 struct kgsl_cmdstream_freememontimestamp {
274 	unsigned int gpuaddr;
275 	unsigned int type;
276 	unsigned int timestamp;
277 };
278 
279 #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP \
280 	_IOW(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp)
281 
282 /* Previous versions of this header had incorrectly defined
283    IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP as a read-only ioctl instead
284    of a write only ioctl.  To ensure binary compatability, the following
285    #define will be used to intercept the incorrect ioctl
286 */
287 
288 #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_OLD \
289 	_IOR(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp)
290 
291 /* create a draw context, which is used to preserve GPU state.
292  * The flags field may contain a mask KGSL_CONTEXT_*  values
293  */
294 struct kgsl_drawctxt_create {
295 	unsigned int flags;
296 	unsigned int drawctxt_id; /*output param */
297 };
298 
299 #define IOCTL_KGSL_DRAWCTXT_CREATE \
300 	_IOWR(KGSL_IOC_TYPE, 0x13, struct kgsl_drawctxt_create)
301 
302 /* destroy a draw context */
303 struct kgsl_drawctxt_destroy {
304 	unsigned int drawctxt_id;
305 };
306 
307 #define IOCTL_KGSL_DRAWCTXT_DESTROY \
308 	_IOW(KGSL_IOC_TYPE, 0x14, struct kgsl_drawctxt_destroy)
309 
310 /* add a block of pmem, fb, ashmem or user allocated address
311  * into the GPU address space */
312 struct kgsl_map_user_mem {
313 	int fd;
314 	unsigned int gpuaddr;   /*output param */
315 	unsigned int len;
316 	unsigned int offset;
317 	unsigned int hostptr;   /*input param */
318 	enum kgsl_user_mem_type memtype;
319 	unsigned int flags;
320 };
321 
322 #define IOCTL_KGSL_MAP_USER_MEM \
323 	_IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem)
324 
325 struct kgsl_cmdstream_readtimestamp_ctxtid {
326 	unsigned int context_id;
327 	unsigned int type;
328 	unsigned int timestamp; /*output param */
329 };
330 
331 #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID \
332 	_IOWR(KGSL_IOC_TYPE, 0x16, struct kgsl_cmdstream_readtimestamp_ctxtid)
333 
334 struct kgsl_cmdstream_freememontimestamp_ctxtid {
335 	unsigned int context_id;
336 	unsigned int gpuaddr;
337 	unsigned int type;
338 	unsigned int timestamp;
339 };
340 
341 #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID \
342 	_IOW(KGSL_IOC_TYPE, 0x17, \
343 	struct kgsl_cmdstream_freememontimestamp_ctxtid)
344 
345 /* add a block of pmem or fb into the GPU address space */
346 struct kgsl_sharedmem_from_pmem {
347 	int pmem_fd;
348 	unsigned int gpuaddr;	/*output param */
349 	unsigned int len;
350 	unsigned int offset;
351 };
352 
353 #define IOCTL_KGSL_SHAREDMEM_FROM_PMEM \
354 	_IOWR(KGSL_IOC_TYPE, 0x20, struct kgsl_sharedmem_from_pmem)
355 
356 /* remove memory from the GPU's address space */
357 struct kgsl_sharedmem_free {
358 	unsigned int gpuaddr;
359 };
360 
361 #define IOCTL_KGSL_SHAREDMEM_FREE \
362 	_IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free)
363 
364 struct kgsl_cff_user_event {
365 	unsigned char cff_opcode;
366 	unsigned int op1;
367 	unsigned int op2;
368 	unsigned int op3;
369 	unsigned int op4;
370 	unsigned int op5;
371 	unsigned int __pad[2];
372 };
373 
374 #define IOCTL_KGSL_CFF_USER_EVENT \
375 	_IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_cff_user_event)
376 
377 struct kgsl_gmem_desc {
378 	unsigned int x;
379 	unsigned int y;
380 	unsigned int width;
381 	unsigned int height;
382 	unsigned int pitch;
383 };
384 
385 struct kgsl_buffer_desc {
386 	void 			*hostptr;
387 	unsigned int	gpuaddr;
388 	int				size;
389 	unsigned int	format;
390 	unsigned int  	pitch;
391 	unsigned int  	enabled;
392 };
393 
394 struct kgsl_bind_gmem_shadow {
395 	unsigned int drawctxt_id;
396 	struct kgsl_gmem_desc gmem_desc;
397 	unsigned int shadow_x;
398 	unsigned int shadow_y;
399 	struct kgsl_buffer_desc shadow_buffer;
400 	unsigned int buffer_id;
401 };
402 
403 #define IOCTL_KGSL_DRAWCTXT_BIND_GMEM_SHADOW \
404     _IOW(KGSL_IOC_TYPE, 0x22, struct kgsl_bind_gmem_shadow)
405 
406 /* add a block of memory into the GPU address space */
407 
408 /*
409  * IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC deprecated 09/2012
410  * use IOCTL_KGSL_GPUMEM_ALLOC instead
411  */
412 
413 struct kgsl_sharedmem_from_vmalloc {
414 	unsigned int gpuaddr;	/*output param */
415 	unsigned int hostptr;
416 	unsigned int flags;
417 };
418 
419 #define IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC \
420 	_IOWR(KGSL_IOC_TYPE, 0x23, struct kgsl_sharedmem_from_vmalloc)
421 
422 #define IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE \
423 	_IOW(KGSL_IOC_TYPE, 0x24, struct kgsl_sharedmem_free)
424 
425 struct kgsl_drawctxt_set_bin_base_offset {
426 	unsigned int drawctxt_id;
427 	unsigned int offset;
428 };
429 
430 #define IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET \
431 	_IOW(KGSL_IOC_TYPE, 0x25, struct kgsl_drawctxt_set_bin_base_offset)
432 
433 enum kgsl_cmdwindow_type {
434 	KGSL_CMDWINDOW_MIN     = 0x00000000,
435 	KGSL_CMDWINDOW_2D      = 0x00000000,
436 	KGSL_CMDWINDOW_3D      = 0x00000001, /* legacy */
437 	KGSL_CMDWINDOW_MMU     = 0x00000002,
438 	KGSL_CMDWINDOW_ARBITER = 0x000000FF,
439 	KGSL_CMDWINDOW_MAX     = 0x000000FF,
440 };
441 
442 /* write to the command window */
443 struct kgsl_cmdwindow_write {
444 	enum kgsl_cmdwindow_type target;
445 	unsigned int addr;
446 	unsigned int data;
447 };
448 
449 #define IOCTL_KGSL_CMDWINDOW_WRITE \
450 	_IOW(KGSL_IOC_TYPE, 0x2e, struct kgsl_cmdwindow_write)
451 
452 struct kgsl_gpumem_alloc {
453 	unsigned long gpuaddr;
454 	size_t size;
455 	unsigned int flags;
456 };
457 
458 #define IOCTL_KGSL_GPUMEM_ALLOC \
459 	_IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc)
460 
461 struct kgsl_cff_syncmem {
462 	unsigned int gpuaddr;
463 	unsigned int len;
464 	unsigned int __pad[2]; /* For future binary compatibility */
465 };
466 
467 #define IOCTL_KGSL_CFF_SYNCMEM \
468 	_IOW(KGSL_IOC_TYPE, 0x30, struct kgsl_cff_syncmem)
469 
470 /*
471  * A timestamp event allows the user space to register an action following an
472  * expired timestamp. Note IOCTL_KGSL_TIMESTAMP_EVENT has been redefined to
473  * _IOWR to support fences which need to return a fd for the priv parameter.
474  */
475 
476 struct kgsl_timestamp_event {
477 	int type;                /* Type of event (see list below) */
478 	unsigned int timestamp;  /* Timestamp to trigger event on */
479 	unsigned int context_id; /* Context for the timestamp */
480 	void *priv;              /* Pointer to the event specific blob */
481 	size_t len;              /* Size of the event specific blob */
482 };
483 
484 #define IOCTL_KGSL_TIMESTAMP_EVENT_OLD \
485 	_IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_timestamp_event)
486 
487 /* A genlock timestamp event releases an existing lock on timestamp expire */
488 
489 #define KGSL_TIMESTAMP_EVENT_GENLOCK 1
490 
491 struct kgsl_timestamp_event_genlock {
492 	int handle; /* Handle of the genlock lock to release */
493 };
494 
495 /* A fence timestamp event releases an existing lock on timestamp expire */
496 
497 #define KGSL_TIMESTAMP_EVENT_FENCE 2
498 
499 struct kgsl_timestamp_event_fence {
500 	int fence_fd; /* Fence to signal */
501 };
502 
503 /*
504  * Set a property within the kernel.  Uses the same structure as
505  * IOCTL_KGSL_GETPROPERTY
506  */
507 
508 #define IOCTL_KGSL_SETPROPERTY \
509 	_IOW(KGSL_IOC_TYPE, 0x32, struct kgsl_device_getproperty)
510 
511 #define IOCTL_KGSL_TIMESTAMP_EVENT \
512 	_IOWR(KGSL_IOC_TYPE, 0x33, struct kgsl_timestamp_event)
513 
514 #ifdef __KERNEL__
515 #ifdef CONFIG_MSM_KGSL_DRM
516 int kgsl_gem_obj_addr(int drm_fd, int handle, unsigned long *start,
517 			unsigned long *len);
518 #else
519 #define kgsl_gem_obj_addr(...) 0
520 #endif
521 #endif
522 #endif /* _MSM_KGSL_H */
523