blob: ee1a22e0f29a815d7f69a9e8322d25d563ec5710 [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
Carter Cooper7e7f02e2012-02-15 09:36:31 -07005#define KGSL_VERSION_MINOR 10
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*/
115 KGSL_TIMESTAMP_MAX = 0x00000002,
116};
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,
Shubhraprakash Das2dfe5dd2012-02-10 13:49:53 -0700128 KGSL_PROP_GPU_RESET_STAT = 0x00000009
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129};
130
131struct kgsl_shadowprop {
132 unsigned int gpuaddr;
133 unsigned int size;
134 unsigned int flags; /* contains KGSL_FLAGS_ values */
135};
136
137struct kgsl_pwrlevel {
138 unsigned int gpu_freq;
139 unsigned int bus_freq;
Lucille Sylvester596d4c22011-10-19 18:04:01 -0600140 unsigned int io_fraction;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141};
142
143struct kgsl_version {
144 unsigned int drv_major;
145 unsigned int drv_minor;
146 unsigned int dev_major;
147 unsigned int dev_minor;
148};
149
150#ifdef __KERNEL__
151
152#define KGSL_3D0_REG_MEMORY "kgsl_3d0_reg_memory"
153#define KGSL_3D0_IRQ "kgsl_3d0_irq"
154#define KGSL_2D0_REG_MEMORY "kgsl_2d0_reg_memory"
155#define KGSL_2D0_IRQ "kgsl_2d0_irq"
156#define KGSL_2D1_REG_MEMORY "kgsl_2d1_reg_memory"
157#define KGSL_2D1_IRQ "kgsl_2d1_irq"
158
Jordan Crouse46cf4bb2012-02-21 08:54:52 -0700159struct kgsl_device_iommu_data {
160 const char **iommu_ctx_names;
161 int iommu_ctx_count;
162 unsigned int physstart;
163 unsigned int physend;
164};
165
Lucille Sylvesterdce84cd2011-10-12 14:15:37 -0600166struct kgsl_device_platform_data {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167 struct kgsl_pwrlevel pwrlevel[KGSL_MAX_PWRLEVELS];
168 int init_level;
169 int num_levels;
170 int (*set_grp_async)(void);
171 unsigned int idle_timeout;
Lynus Vazfe4bede2012-04-06 11:53:30 -0700172 bool strtstp_sleepwake;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700173 unsigned int nap_allowed;
Lucille Sylvesterdce84cd2011-10-12 14:15:37 -0600174 unsigned int clk_map;
Kedar Joshic11d0982012-02-07 10:59:49 +0530175 unsigned int idle_needed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176 struct msm_bus_scale_pdata *bus_scale_table;
Jordan Crouse46cf4bb2012-02-21 08:54:52 -0700177 struct kgsl_device_iommu_data *iommu_data;
178 int iommu_count;
Lucille Sylvester6e362412011-12-09 16:21:42 -0700179 struct msm_dcvs_core_info *core_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180};
181
182#endif
183
184/* structure holds list of ibs */
185struct kgsl_ibdesc {
186 unsigned int gpuaddr;
187 void *hostptr;
188 unsigned int sizedwords;
189 unsigned int ctrl;
190};
191
192/* ioctls */
193#define KGSL_IOC_TYPE 0x09
194
195/* get misc info about the GPU
196 type should be a value from enum kgsl_property_type
197 value points to a structure that varies based on type
198 sizebytes is sizeof() that structure
199 for KGSL_PROP_DEVICE_INFO, use struct kgsl_devinfo
200 this structure contaings hardware versioning info.
201 for KGSL_PROP_DEVICE_SHADOW, use struct kgsl_shadowprop
202 this is used to find mmap() offset and sizes for mapping
203 struct kgsl_memstore into userspace.
204*/
205struct kgsl_device_getproperty {
206 unsigned int type;
207 void *value;
208 unsigned int sizebytes;
209};
210
211#define IOCTL_KGSL_DEVICE_GETPROPERTY \
212 _IOWR(KGSL_IOC_TYPE, 0x2, struct kgsl_device_getproperty)
213
Harsh Vardhan Dwivedib6cebfe2012-03-15 18:20:59 -0600214/* IOCTL_KGSL_DEVICE_READ (0x3) - removed 03/2012
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700216
217/* block until the GPU has executed past a given timestamp
218 * timeout is in milliseconds.
219 */
220struct kgsl_device_waittimestamp {
221 unsigned int timestamp;
222 unsigned int timeout;
223};
224
225#define IOCTL_KGSL_DEVICE_WAITTIMESTAMP \
226 _IOW(KGSL_IOC_TYPE, 0x6, struct kgsl_device_waittimestamp)
227
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700228struct kgsl_device_waittimestamp_ctxtid {
229 unsigned int context_id;
230 unsigned int timestamp;
231 unsigned int timeout;
232};
233
234#define IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID \
235 _IOW(KGSL_IOC_TYPE, 0x7, struct kgsl_device_waittimestamp_ctxtid)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700236
237/* issue indirect commands to the GPU.
238 * drawctxt_id must have been created with IOCTL_KGSL_DRAWCTXT_CREATE
239 * ibaddr and sizedwords must specify a subset of a buffer created
240 * with IOCTL_KGSL_SHAREDMEM_FROM_PMEM
241 * flags may be a mask of KGSL_CONTEXT_ values
242 * timestamp is a returned counter value which can be passed to
243 * other ioctls to determine when the commands have been executed by
244 * the GPU.
245 */
246struct kgsl_ringbuffer_issueibcmds {
247 unsigned int drawctxt_id;
248 unsigned int ibdesc_addr;
249 unsigned int numibs;
250 unsigned int timestamp; /*output param */
251 unsigned int flags;
252};
253
254#define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS \
255 _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds)
256
257/* read the most recently executed timestamp value
258 * type should be a value from enum kgsl_timestamp_type
259 */
260struct kgsl_cmdstream_readtimestamp {
261 unsigned int type;
262 unsigned int timestamp; /*output param */
263};
264
Jason Varbedian80ba33d2011-07-11 17:29:05 -0700265#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700266 _IOR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp)
267
Jason Varbedian80ba33d2011-07-11 17:29:05 -0700268#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP \
269 _IOWR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp)
270
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700271/* free memory when the GPU reaches a given timestamp.
272 * gpuaddr specify a memory region created by a
273 * IOCTL_KGSL_SHAREDMEM_FROM_PMEM call
274 * type should be a value from enum kgsl_timestamp_type
275 */
276struct kgsl_cmdstream_freememontimestamp {
277 unsigned int gpuaddr;
278 unsigned int type;
279 unsigned int timestamp;
280};
281
282#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP \
283 _IOW(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp)
284
285/* Previous versions of this header had incorrectly defined
286 IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP as a read-only ioctl instead
287 of a write only ioctl. To ensure binary compatability, the following
288 #define will be used to intercept the incorrect ioctl
289*/
290
291#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_OLD \
292 _IOR(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp)
293
294/* create a draw context, which is used to preserve GPU state.
295 * The flags field may contain a mask KGSL_CONTEXT_* values
296 */
297struct kgsl_drawctxt_create {
298 unsigned int flags;
299 unsigned int drawctxt_id; /*output param */
300};
301
302#define IOCTL_KGSL_DRAWCTXT_CREATE \
303 _IOWR(KGSL_IOC_TYPE, 0x13, struct kgsl_drawctxt_create)
304
305/* destroy a draw context */
306struct kgsl_drawctxt_destroy {
307 unsigned int drawctxt_id;
308};
309
310#define IOCTL_KGSL_DRAWCTXT_DESTROY \
311 _IOW(KGSL_IOC_TYPE, 0x14, struct kgsl_drawctxt_destroy)
312
313/* add a block of pmem, fb, ashmem or user allocated address
314 * into the GPU address space */
315struct kgsl_map_user_mem {
316 int fd;
317 unsigned int gpuaddr; /*output param */
318 unsigned int len;
319 unsigned int offset;
320 unsigned int hostptr; /*input param */
321 enum kgsl_user_mem_type memtype;
322 unsigned int reserved; /* May be required to add
323 params for another mem type */
324};
325
326#define IOCTL_KGSL_MAP_USER_MEM \
327 _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem)
328
Carter Cooper7e7f02e2012-02-15 09:36:31 -0700329struct kgsl_cmdstream_readtimestamp_ctxtid {
330 unsigned int context_id;
331 unsigned int type;
332 unsigned int timestamp; /*output param */
333};
334
335#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID \
336 _IOWR(KGSL_IOC_TYPE, 0x16, struct kgsl_cmdstream_readtimestamp_ctxtid)
337
338struct kgsl_cmdstream_freememontimestamp_ctxtid {
339 unsigned int context_id;
340 unsigned int gpuaddr;
341 unsigned int type;
342 unsigned int timestamp;
343};
344
345#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID \
346 _IOW(KGSL_IOC_TYPE, 0x17, \
347 struct kgsl_cmdstream_freememontimestamp_ctxtid)
348
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700349/* add a block of pmem or fb into the GPU address space */
350struct kgsl_sharedmem_from_pmem {
351 int pmem_fd;
352 unsigned int gpuaddr; /*output param */
353 unsigned int len;
354 unsigned int offset;
355};
356
357#define IOCTL_KGSL_SHAREDMEM_FROM_PMEM \
358 _IOWR(KGSL_IOC_TYPE, 0x20, struct kgsl_sharedmem_from_pmem)
359
360/* remove memory from the GPU's address space */
361struct kgsl_sharedmem_free {
362 unsigned int gpuaddr;
363};
364
365#define IOCTL_KGSL_SHAREDMEM_FREE \
366 _IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free)
367
Sushmita Susheelendra41f8fa32011-05-11 17:15:58 -0600368struct kgsl_cff_user_event {
369 unsigned char cff_opcode;
370 unsigned int op1;
371 unsigned int op2;
372 unsigned int op3;
373 unsigned int op4;
374 unsigned int op5;
375 unsigned int __pad[2];
376};
377
378#define IOCTL_KGSL_CFF_USER_EVENT \
379 _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_cff_user_event)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700380
381struct kgsl_gmem_desc {
382 unsigned int x;
383 unsigned int y;
384 unsigned int width;
385 unsigned int height;
386 unsigned int pitch;
387};
388
389struct kgsl_buffer_desc {
390 void *hostptr;
391 unsigned int gpuaddr;
392 int size;
393 unsigned int format;
394 unsigned int pitch;
395 unsigned int enabled;
396};
397
398struct kgsl_bind_gmem_shadow {
399 unsigned int drawctxt_id;
400 struct kgsl_gmem_desc gmem_desc;
401 unsigned int shadow_x;
402 unsigned int shadow_y;
403 struct kgsl_buffer_desc shadow_buffer;
404 unsigned int buffer_id;
405};
406
407#define IOCTL_KGSL_DRAWCTXT_BIND_GMEM_SHADOW \
408 _IOW(KGSL_IOC_TYPE, 0x22, struct kgsl_bind_gmem_shadow)
409
410/* add a block of memory into the GPU address space */
411struct kgsl_sharedmem_from_vmalloc {
412 unsigned int gpuaddr; /*output param */
413 unsigned int hostptr;
414 unsigned int flags;
415};
416
417#define IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC \
418 _IOWR(KGSL_IOC_TYPE, 0x23, struct kgsl_sharedmem_from_vmalloc)
419
420#define IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE \
421 _IOW(KGSL_IOC_TYPE, 0x24, struct kgsl_sharedmem_free)
422
423struct kgsl_drawctxt_set_bin_base_offset {
424 unsigned int drawctxt_id;
425 unsigned int offset;
426};
427
428#define IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET \
429 _IOW(KGSL_IOC_TYPE, 0x25, struct kgsl_drawctxt_set_bin_base_offset)
430
431enum kgsl_cmdwindow_type {
432 KGSL_CMDWINDOW_MIN = 0x00000000,
433 KGSL_CMDWINDOW_2D = 0x00000000,
434 KGSL_CMDWINDOW_3D = 0x00000001, /* legacy */
435 KGSL_CMDWINDOW_MMU = 0x00000002,
436 KGSL_CMDWINDOW_ARBITER = 0x000000FF,
437 KGSL_CMDWINDOW_MAX = 0x000000FF,
438};
439
440/* write to the command window */
441struct kgsl_cmdwindow_write {
442 enum kgsl_cmdwindow_type target;
443 unsigned int addr;
444 unsigned int data;
445};
446
447#define IOCTL_KGSL_CMDWINDOW_WRITE \
448 _IOW(KGSL_IOC_TYPE, 0x2e, struct kgsl_cmdwindow_write)
449
450struct kgsl_gpumem_alloc {
451 unsigned long gpuaddr;
452 size_t size;
453 unsigned int flags;
454};
455
456#define IOCTL_KGSL_GPUMEM_ALLOC \
457 _IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc)
458
Jeremy Gebbena7423e42011-04-18 15:11:21 -0600459struct kgsl_cff_syncmem {
460 unsigned int gpuaddr;
461 unsigned int len;
462 unsigned int __pad[2]; /* For future binary compatibility */
463};
464
465#define IOCTL_KGSL_CFF_SYNCMEM \
466 _IOW(KGSL_IOC_TYPE, 0x30, struct kgsl_cff_syncmem)
467
Jordan Croused4bc9d22011-11-17 13:39:21 -0700468/*
469 * A timestamp event allows the user space to register an action following an
470 * expired timestamp.
471 */
472
473struct kgsl_timestamp_event {
474 int type; /* Type of event (see list below) */
475 unsigned int timestamp; /* Timestamp to trigger event on */
476 unsigned int context_id; /* Context for the timestamp */
477 void *priv; /* Pointer to the event specific blob */
478 size_t len; /* Size of the event specific blob */
479};
480
481#define IOCTL_KGSL_TIMESTAMP_EVENT \
482 _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_timestamp_event)
483
484/* A genlock timestamp event releases an existing lock on timestamp expire */
485
486#define KGSL_TIMESTAMP_EVENT_GENLOCK 1
487
488struct kgsl_timestamp_event_genlock {
489 int handle; /* Handle of the genlock lock to release */
490};
491
Jordan Crouseed7dd7f2012-03-29 13:16:02 -0600492/*
493 * Set a property within the kernel. Uses the same structure as
494 * IOCTL_KGSL_GETPROPERTY
495 */
496
497#define IOCTL_KGSL_SETPROPERTY \
498 _IOW(KGSL_IOC_TYPE, 0x32, struct kgsl_device_getproperty)
499
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700500#ifdef __KERNEL__
501#ifdef CONFIG_MSM_KGSL_DRM
502int kgsl_gem_obj_addr(int drm_fd, int handle, unsigned long *start,
503 unsigned long *len);
504#else
505#define kgsl_gem_obj_addr(...) 0
506#endif
507#endif
508#endif /* _MSM_KGSL_H */