blob: 244b957b0e1a6c969e6125666895932792853ed9 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001#ifndef _MSM_KGSL_H
2#define _MSM_KGSL_H
3
4#define KGSL_VERSION_MAJOR 3
Jordan Crousef7370f82012-04-18 09:31:07 -06005#define KGSL_VERSION_MINOR 11
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006
7/*context flags */
Carter Cooper7e7f02e2012-02-15 09:36:31 -07008#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
16#define KGSL_CONTEXT_INVALID 0xffffffff
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070017
18/* Memory allocayion flags */
19#define KGSL_MEMFLAGS_GPUREADONLY 0x01000000
20
21/* generic flag values */
22#define KGSL_FLAGS_NORMALMODE 0x00000000
23#define KGSL_FLAGS_SAFEMODE 0x00000001
24#define KGSL_FLAGS_INITIALIZED0 0x00000002
25#define KGSL_FLAGS_INITIALIZED 0x00000004
26#define KGSL_FLAGS_STARTED 0x00000008
27#define KGSL_FLAGS_ACTIVE 0x00000010
28#define KGSL_FLAGS_RESERVED0 0x00000020
29#define KGSL_FLAGS_RESERVED1 0x00000040
30#define KGSL_FLAGS_RESERVED2 0x00000080
31#define KGSL_FLAGS_SOFT_RESET 0x00000100
Carter Cooper7e7f02e2012-02-15 09:36:31 -070032#define KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS 0x00000200
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033
Lucille Sylvesterdce84cd2011-10-12 14:15:37 -060034/* Clock flags to show which clocks should be controled by a given platform */
35#define KGSL_CLK_SRC 0x00000001
36#define KGSL_CLK_CORE 0x00000002
37#define KGSL_CLK_IFACE 0x00000004
38#define KGSL_CLK_MEM 0x00000008
39#define KGSL_CLK_MEM_IFACE 0x00000010
40#define KGSL_CLK_AXI 0x00000020
41
Shubhraprakash Das2dfe5dd2012-02-10 13:49:53 -070042/*
43 * Reset status values for context
44 */
45enum kgsl_ctx_reset_stat {
46 KGSL_CTX_STAT_NO_ERROR = 0x00000000,
47 KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT = 0x00000001,
48 KGSL_CTX_STAT_INNOCENT_CONTEXT_RESET_EXT = 0x00000002,
49 KGSL_CTX_STAT_UNKNOWN_CONTEXT_RESET_EXT = 0x00000003
50};
51
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052#define KGSL_MAX_PWRLEVELS 5
53
Suman Tatiraju0123d182011-09-30 14:59:06 -070054#define KGSL_CONVERT_TO_MBPS(val) \
55 (val*1000*1000U)
56
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057/* device id */
58enum kgsl_deviceid {
59 KGSL_DEVICE_3D0 = 0x00000000,
60 KGSL_DEVICE_2D0 = 0x00000001,
61 KGSL_DEVICE_2D1 = 0x00000002,
62 KGSL_DEVICE_MAX = 0x00000003
63};
64
65enum kgsl_user_mem_type {
66 KGSL_USER_MEM_TYPE_PMEM = 0x00000000,
67 KGSL_USER_MEM_TYPE_ASHMEM = 0x00000001,
Jordan Crouse8eab35a2011-10-12 16:57:48 -060068 KGSL_USER_MEM_TYPE_ADDR = 0x00000002,
69 KGSL_USER_MEM_TYPE_ION = 0x00000003,
Lynus Vaz31b5290e2012-01-18 19:20:24 +053070 KGSL_USER_MEM_TYPE_MAX = 0x00000004,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071};
72
73struct kgsl_devinfo {
74
75 unsigned int device_id;
76 /* chip revision id
77 * coreid:8 majorrev:8 minorrev:8 patch:8
78 */
79 unsigned int chip_id;
80 unsigned int mmu_enabled;
81 unsigned int gmem_gpubaseaddr;
82 /*
83 * This field contains the adreno revision
84 * number 200, 205, 220, etc...
85 */
86 unsigned int gpu_id;
87 unsigned int gmem_sizebytes;
88};
89
90/* this structure defines the region of memory that can be mmap()ed from this
91 driver. The timestamp fields are volatile because they are written by the
92 GPU
93*/
94struct kgsl_devmemstore {
95 volatile unsigned int soptimestamp;
96 unsigned int sbz;
97 volatile unsigned int eoptimestamp;
98 unsigned int sbz2;
99 volatile unsigned int ts_cmp_enable;
100 unsigned int sbz3;
101 volatile unsigned int ref_wait_ts;
102 unsigned int sbz4;
103 unsigned int current_context;
104 unsigned int sbz5;
105};
106
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700107#define KGSL_MEMSTORE_OFFSET(ctxt_id, field) \
108 ((ctxt_id)*sizeof(struct kgsl_devmemstore) + \
109 offsetof(struct kgsl_devmemstore, field))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700110
111/* timestamp id*/
112enum kgsl_timestamp_type {
113 KGSL_TIMESTAMP_CONSUMED = 0x00000001, /* start-of-pipeline timestamp */
114 KGSL_TIMESTAMP_RETIRED = 0x00000002, /* end-of-pipeline timestamp*/
Jordan Crousec659f382012-04-16 11:10:41 -0600115 KGSL_TIMESTAMP_QUEUED = 0x00000003,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116};
117
118/* property types - used with kgsl_device_getproperty */
119enum kgsl_property_type {
120 KGSL_PROP_DEVICE_INFO = 0x00000001,
121 KGSL_PROP_DEVICE_SHADOW = 0x00000002,
122 KGSL_PROP_DEVICE_POWER = 0x00000003,
123 KGSL_PROP_SHMEM = 0x00000004,
124 KGSL_PROP_SHMEM_APERTURES = 0x00000005,
125 KGSL_PROP_MMU_ENABLE = 0x00000006,
126 KGSL_PROP_INTERRUPT_WAITS = 0x00000007,
127 KGSL_PROP_VERSION = 0x00000008,
Jordan Crousef7370f82012-04-18 09:31:07 -0600128 KGSL_PROP_GPU_RESET_STAT = 0x00000009,
129 KGSL_PROP_PWRCTRL = 0x0000000E,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130};
131
132struct kgsl_shadowprop {
133 unsigned int gpuaddr;
134 unsigned int size;
135 unsigned int flags; /* contains KGSL_FLAGS_ values */
136};
137
138struct kgsl_pwrlevel {
139 unsigned int gpu_freq;
140 unsigned int bus_freq;
Lucille Sylvester596d4c22011-10-19 18:04:01 -0600141 unsigned int io_fraction;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700142};
143
144struct kgsl_version {
145 unsigned int drv_major;
146 unsigned int drv_minor;
147 unsigned int dev_major;
148 unsigned int dev_minor;
149};
150
151#ifdef __KERNEL__
152
153#define KGSL_3D0_REG_MEMORY "kgsl_3d0_reg_memory"
154#define KGSL_3D0_IRQ "kgsl_3d0_irq"
155#define KGSL_2D0_REG_MEMORY "kgsl_2d0_reg_memory"
156#define KGSL_2D0_IRQ "kgsl_2d0_irq"
157#define KGSL_2D1_REG_MEMORY "kgsl_2d1_reg_memory"
158#define KGSL_2D1_IRQ "kgsl_2d1_irq"
159
Jordan Crouse46cf4bb2012-02-21 08:54:52 -0700160struct kgsl_device_iommu_data {
161 const char **iommu_ctx_names;
162 int iommu_ctx_count;
163 unsigned int physstart;
164 unsigned int physend;
165};
166
Lucille Sylvesterdce84cd2011-10-12 14:15:37 -0600167struct kgsl_device_platform_data {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700168 struct kgsl_pwrlevel pwrlevel[KGSL_MAX_PWRLEVELS];
169 int init_level;
170 int num_levels;
171 int (*set_grp_async)(void);
172 unsigned int idle_timeout;
Lynus Vazfe4bede2012-04-06 11:53:30 -0700173 bool strtstp_sleepwake;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 unsigned int nap_allowed;
Lucille Sylvesterdce84cd2011-10-12 14:15:37 -0600175 unsigned int clk_map;
Kedar Joshic11d0982012-02-07 10:59:49 +0530176 unsigned int idle_needed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700177 struct msm_bus_scale_pdata *bus_scale_table;
Jordan Crouse46cf4bb2012-02-21 08:54:52 -0700178 struct kgsl_device_iommu_data *iommu_data;
179 int iommu_count;
Lucille Sylvester6e362412011-12-09 16:21:42 -0700180 struct msm_dcvs_core_info *core_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181};
182
183#endif
184
185/* structure holds list of ibs */
186struct kgsl_ibdesc {
187 unsigned int gpuaddr;
188 void *hostptr;
189 unsigned int sizedwords;
190 unsigned int ctrl;
191};
192
193/* ioctls */
194#define KGSL_IOC_TYPE 0x09
195
196/* get misc info about the GPU
197 type should be a value from enum kgsl_property_type
198 value points to a structure that varies based on type
199 sizebytes is sizeof() that structure
200 for KGSL_PROP_DEVICE_INFO, use struct kgsl_devinfo
201 this structure contaings hardware versioning info.
202 for KGSL_PROP_DEVICE_SHADOW, use struct kgsl_shadowprop
203 this is used to find mmap() offset and sizes for mapping
204 struct kgsl_memstore into userspace.
205*/
206struct kgsl_device_getproperty {
207 unsigned int type;
208 void *value;
209 unsigned int sizebytes;
210};
211
212#define IOCTL_KGSL_DEVICE_GETPROPERTY \
213 _IOWR(KGSL_IOC_TYPE, 0x2, struct kgsl_device_getproperty)
214
Harsh Vardhan Dwivedib6cebfe2012-03-15 18:20:59 -0600215/* IOCTL_KGSL_DEVICE_READ (0x3) - removed 03/2012
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700216 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700217
218/* block until the GPU has executed past a given timestamp
219 * timeout is in milliseconds.
220 */
221struct kgsl_device_waittimestamp {
222 unsigned int timestamp;
223 unsigned int timeout;
224};
225
226#define IOCTL_KGSL_DEVICE_WAITTIMESTAMP \
227 _IOW(KGSL_IOC_TYPE, 0x6, struct kgsl_device_waittimestamp)
228
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700229struct kgsl_device_waittimestamp_ctxtid {
230 unsigned int context_id;
231 unsigned int timestamp;
232 unsigned int timeout;
233};
234
235#define IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID \
236 _IOW(KGSL_IOC_TYPE, 0x7, struct kgsl_device_waittimestamp_ctxtid)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700237
238/* issue indirect commands to the GPU.
239 * drawctxt_id must have been created with IOCTL_KGSL_DRAWCTXT_CREATE
240 * ibaddr and sizedwords must specify a subset of a buffer created
241 * with IOCTL_KGSL_SHAREDMEM_FROM_PMEM
242 * flags may be a mask of KGSL_CONTEXT_ values
243 * timestamp is a returned counter value which can be passed to
244 * other ioctls to determine when the commands have been executed by
245 * the GPU.
246 */
247struct kgsl_ringbuffer_issueibcmds {
248 unsigned int drawctxt_id;
249 unsigned int ibdesc_addr;
250 unsigned int numibs;
251 unsigned int timestamp; /*output param */
252 unsigned int flags;
253};
254
255#define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS \
256 _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds)
257
258/* read the most recently executed timestamp value
259 * type should be a value from enum kgsl_timestamp_type
260 */
261struct kgsl_cmdstream_readtimestamp {
262 unsigned int type;
263 unsigned int timestamp; /*output param */
264};
265
Jason Varbedian80ba33d2011-07-11 17:29:05 -0700266#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700267 _IOR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp)
268
Jason Varbedian80ba33d2011-07-11 17:29:05 -0700269#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP \
270 _IOWR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp)
271
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272/* free memory when the GPU reaches a given timestamp.
273 * gpuaddr specify a memory region created by a
274 * IOCTL_KGSL_SHAREDMEM_FROM_PMEM call
275 * type should be a value from enum kgsl_timestamp_type
276 */
277struct kgsl_cmdstream_freememontimestamp {
278 unsigned int gpuaddr;
279 unsigned int type;
280 unsigned int timestamp;
281};
282
283#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP \
284 _IOW(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp)
285
286/* Previous versions of this header had incorrectly defined
287 IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP as a read-only ioctl instead
288 of a write only ioctl. To ensure binary compatability, the following
289 #define will be used to intercept the incorrect ioctl
290*/
291
292#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_OLD \
293 _IOR(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp)
294
295/* create a draw context, which is used to preserve GPU state.
296 * The flags field may contain a mask KGSL_CONTEXT_* values
297 */
298struct kgsl_drawctxt_create {
299 unsigned int flags;
300 unsigned int drawctxt_id; /*output param */
301};
302
303#define IOCTL_KGSL_DRAWCTXT_CREATE \
304 _IOWR(KGSL_IOC_TYPE, 0x13, struct kgsl_drawctxt_create)
305
306/* destroy a draw context */
307struct kgsl_drawctxt_destroy {
308 unsigned int drawctxt_id;
309};
310
311#define IOCTL_KGSL_DRAWCTXT_DESTROY \
312 _IOW(KGSL_IOC_TYPE, 0x14, struct kgsl_drawctxt_destroy)
313
314/* add a block of pmem, fb, ashmem or user allocated address
315 * into the GPU address space */
316struct kgsl_map_user_mem {
317 int fd;
318 unsigned int gpuaddr; /*output param */
319 unsigned int len;
320 unsigned int offset;
321 unsigned int hostptr; /*input param */
322 enum kgsl_user_mem_type memtype;
323 unsigned int reserved; /* May be required to add
324 params for another mem type */
325};
326
327#define IOCTL_KGSL_MAP_USER_MEM \
328 _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem)
329
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700330struct kgsl_cmdstream_readtimestamp_ctxtid {
331 unsigned int context_id;
332 unsigned int type;
333 unsigned int timestamp; /*output param */
334};
335
336#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID \
337 _IOWR(KGSL_IOC_TYPE, 0x16, struct kgsl_cmdstream_readtimestamp_ctxtid)
338
339struct kgsl_cmdstream_freememontimestamp_ctxtid {
340 unsigned int context_id;
341 unsigned int gpuaddr;
342 unsigned int type;
343 unsigned int timestamp;
344};
345
346#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID \
347 _IOW(KGSL_IOC_TYPE, 0x17, \
348 struct kgsl_cmdstream_freememontimestamp_ctxtid)
349
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700350/* add a block of pmem or fb into the GPU address space */
351struct kgsl_sharedmem_from_pmem {
352 int pmem_fd;
353 unsigned int gpuaddr; /*output param */
354 unsigned int len;
355 unsigned int offset;
356};
357
358#define IOCTL_KGSL_SHAREDMEM_FROM_PMEM \
359 _IOWR(KGSL_IOC_TYPE, 0x20, struct kgsl_sharedmem_from_pmem)
360
361/* remove memory from the GPU's address space */
362struct kgsl_sharedmem_free {
363 unsigned int gpuaddr;
364};
365
366#define IOCTL_KGSL_SHAREDMEM_FREE \
367 _IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free)
368
Sushmita Susheelendra41f8fa32011-05-11 17:15:58 -0600369struct kgsl_cff_user_event {
370 unsigned char cff_opcode;
371 unsigned int op1;
372 unsigned int op2;
373 unsigned int op3;
374 unsigned int op4;
375 unsigned int op5;
376 unsigned int __pad[2];
377};
378
379#define IOCTL_KGSL_CFF_USER_EVENT \
380 _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_cff_user_event)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700381
382struct kgsl_gmem_desc {
383 unsigned int x;
384 unsigned int y;
385 unsigned int width;
386 unsigned int height;
387 unsigned int pitch;
388};
389
390struct kgsl_buffer_desc {
391 void *hostptr;
392 unsigned int gpuaddr;
393 int size;
394 unsigned int format;
395 unsigned int pitch;
396 unsigned int enabled;
397};
398
399struct kgsl_bind_gmem_shadow {
400 unsigned int drawctxt_id;
401 struct kgsl_gmem_desc gmem_desc;
402 unsigned int shadow_x;
403 unsigned int shadow_y;
404 struct kgsl_buffer_desc shadow_buffer;
405 unsigned int buffer_id;
406};
407
408#define IOCTL_KGSL_DRAWCTXT_BIND_GMEM_SHADOW \
409 _IOW(KGSL_IOC_TYPE, 0x22, struct kgsl_bind_gmem_shadow)
410
411/* add a block of memory into the GPU address space */
412struct kgsl_sharedmem_from_vmalloc {
413 unsigned int gpuaddr; /*output param */
414 unsigned int hostptr;
415 unsigned int flags;
416};
417
418#define IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC \
419 _IOWR(KGSL_IOC_TYPE, 0x23, struct kgsl_sharedmem_from_vmalloc)
420
421#define IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE \
422 _IOW(KGSL_IOC_TYPE, 0x24, struct kgsl_sharedmem_free)
423
424struct kgsl_drawctxt_set_bin_base_offset {
425 unsigned int drawctxt_id;
426 unsigned int offset;
427};
428
429#define IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET \
430 _IOW(KGSL_IOC_TYPE, 0x25, struct kgsl_drawctxt_set_bin_base_offset)
431
432enum kgsl_cmdwindow_type {
433 KGSL_CMDWINDOW_MIN = 0x00000000,
434 KGSL_CMDWINDOW_2D = 0x00000000,
435 KGSL_CMDWINDOW_3D = 0x00000001, /* legacy */
436 KGSL_CMDWINDOW_MMU = 0x00000002,
437 KGSL_CMDWINDOW_ARBITER = 0x000000FF,
438 KGSL_CMDWINDOW_MAX = 0x000000FF,
439};
440
441/* write to the command window */
442struct kgsl_cmdwindow_write {
443 enum kgsl_cmdwindow_type target;
444 unsigned int addr;
445 unsigned int data;
446};
447
448#define IOCTL_KGSL_CMDWINDOW_WRITE \
449 _IOW(KGSL_IOC_TYPE, 0x2e, struct kgsl_cmdwindow_write)
450
451struct kgsl_gpumem_alloc {
452 unsigned long gpuaddr;
453 size_t size;
454 unsigned int flags;
455};
456
457#define IOCTL_KGSL_GPUMEM_ALLOC \
458 _IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc)
459
Jeremy Gebbena7423e42011-04-18 15:11:21 -0600460struct kgsl_cff_syncmem {
461 unsigned int gpuaddr;
462 unsigned int len;
463 unsigned int __pad[2]; /* For future binary compatibility */
464};
465
466#define IOCTL_KGSL_CFF_SYNCMEM \
467 _IOW(KGSL_IOC_TYPE, 0x30, struct kgsl_cff_syncmem)
468
Jordan Croused4bc9d22011-11-17 13:39:21 -0700469/*
470 * A timestamp event allows the user space to register an action following an
471 * expired timestamp.
472 */
473
474struct kgsl_timestamp_event {
475 int type; /* Type of event (see list below) */
476 unsigned int timestamp; /* Timestamp to trigger event on */
477 unsigned int context_id; /* Context for the timestamp */
478 void *priv; /* Pointer to the event specific blob */
479 size_t len; /* Size of the event specific blob */
480};
481
482#define IOCTL_KGSL_TIMESTAMP_EVENT \
483 _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_timestamp_event)
484
485/* A genlock timestamp event releases an existing lock on timestamp expire */
486
487#define KGSL_TIMESTAMP_EVENT_GENLOCK 1
488
489struct kgsl_timestamp_event_genlock {
490 int handle; /* Handle of the genlock lock to release */
491};
492
Jordan Crouseed7dd7f2012-03-29 13:16:02 -0600493/*
494 * Set a property within the kernel. Uses the same structure as
495 * IOCTL_KGSL_GETPROPERTY
496 */
497
498#define IOCTL_KGSL_SETPROPERTY \
499 _IOW(KGSL_IOC_TYPE, 0x32, struct kgsl_device_getproperty)
500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700501#ifdef __KERNEL__
502#ifdef CONFIG_MSM_KGSL_DRM
503int kgsl_gem_obj_addr(int drm_fd, int handle, unsigned long *start,
504 unsigned long *len);
505#else
506#define kgsl_gem_obj_addr(...) 0
507#endif
508#endif
509#endif /* _MSM_KGSL_H */