blob: b55cfe18f43fa03df282e4f27490f53fec28e923 [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
Sushmita Susheelendra41f8fa32011-05-11 17:15:58 -06005#define KGSL_VERSION_MINOR 7
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006
7/*context flags */
8#define KGSL_CONTEXT_SAVE_GMEM 1
9#define KGSL_CONTEXT_NO_GMEM_ALLOC 2
10#define KGSL_CONTEXT_SUBMIT_IB_LIST 4
11#define KGSL_CONTEXT_CTX_SWITCH 8
12
13/* Memory allocayion flags */
14#define KGSL_MEMFLAGS_GPUREADONLY 0x01000000
15
16/* generic flag values */
17#define KGSL_FLAGS_NORMALMODE 0x00000000
18#define KGSL_FLAGS_SAFEMODE 0x00000001
19#define KGSL_FLAGS_INITIALIZED0 0x00000002
20#define KGSL_FLAGS_INITIALIZED 0x00000004
21#define KGSL_FLAGS_STARTED 0x00000008
22#define KGSL_FLAGS_ACTIVE 0x00000010
23#define KGSL_FLAGS_RESERVED0 0x00000020
24#define KGSL_FLAGS_RESERVED1 0x00000040
25#define KGSL_FLAGS_RESERVED2 0x00000080
26#define KGSL_FLAGS_SOFT_RESET 0x00000100
27
28#define KGSL_MAX_PWRLEVELS 5
29
Suman Tatiraju0123d182011-09-30 14:59:06 -070030#define KGSL_CONVERT_TO_MBPS(val) \
31 (val*1000*1000U)
32
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033/* device id */
34enum kgsl_deviceid {
35 KGSL_DEVICE_3D0 = 0x00000000,
36 KGSL_DEVICE_2D0 = 0x00000001,
37 KGSL_DEVICE_2D1 = 0x00000002,
38 KGSL_DEVICE_MAX = 0x00000003
39};
40
41enum kgsl_user_mem_type {
42 KGSL_USER_MEM_TYPE_PMEM = 0x00000000,
43 KGSL_USER_MEM_TYPE_ASHMEM = 0x00000001,
44 KGSL_USER_MEM_TYPE_ADDR = 0x00000002
45};
46
47struct kgsl_devinfo {
48
49 unsigned int device_id;
50 /* chip revision id
51 * coreid:8 majorrev:8 minorrev:8 patch:8
52 */
53 unsigned int chip_id;
54 unsigned int mmu_enabled;
55 unsigned int gmem_gpubaseaddr;
56 /*
57 * This field contains the adreno revision
58 * number 200, 205, 220, etc...
59 */
60 unsigned int gpu_id;
61 unsigned int gmem_sizebytes;
62};
63
64/* this structure defines the region of memory that can be mmap()ed from this
65 driver. The timestamp fields are volatile because they are written by the
66 GPU
67*/
68struct kgsl_devmemstore {
69 volatile unsigned int soptimestamp;
70 unsigned int sbz;
71 volatile unsigned int eoptimestamp;
72 unsigned int sbz2;
73 volatile unsigned int ts_cmp_enable;
74 unsigned int sbz3;
75 volatile unsigned int ref_wait_ts;
76 unsigned int sbz4;
77 unsigned int current_context;
78 unsigned int sbz5;
79};
80
81#define KGSL_DEVICE_MEMSTORE_OFFSET(field) \
82 offsetof(struct kgsl_devmemstore, field)
83
84
85/* timestamp id*/
86enum kgsl_timestamp_type {
87 KGSL_TIMESTAMP_CONSUMED = 0x00000001, /* start-of-pipeline timestamp */
88 KGSL_TIMESTAMP_RETIRED = 0x00000002, /* end-of-pipeline timestamp*/
89 KGSL_TIMESTAMP_MAX = 0x00000002,
90};
91
92/* property types - used with kgsl_device_getproperty */
93enum kgsl_property_type {
94 KGSL_PROP_DEVICE_INFO = 0x00000001,
95 KGSL_PROP_DEVICE_SHADOW = 0x00000002,
96 KGSL_PROP_DEVICE_POWER = 0x00000003,
97 KGSL_PROP_SHMEM = 0x00000004,
98 KGSL_PROP_SHMEM_APERTURES = 0x00000005,
99 KGSL_PROP_MMU_ENABLE = 0x00000006,
100 KGSL_PROP_INTERRUPT_WAITS = 0x00000007,
101 KGSL_PROP_VERSION = 0x00000008,
102};
103
104struct kgsl_shadowprop {
105 unsigned int gpuaddr;
106 unsigned int size;
107 unsigned int flags; /* contains KGSL_FLAGS_ values */
108};
109
110struct kgsl_pwrlevel {
111 unsigned int gpu_freq;
112 unsigned int bus_freq;
113};
114
115struct kgsl_version {
116 unsigned int drv_major;
117 unsigned int drv_minor;
118 unsigned int dev_major;
119 unsigned int dev_minor;
120};
121
122#ifdef __KERNEL__
123
124#define KGSL_3D0_REG_MEMORY "kgsl_3d0_reg_memory"
125#define KGSL_3D0_IRQ "kgsl_3d0_irq"
126#define KGSL_2D0_REG_MEMORY "kgsl_2d0_reg_memory"
127#define KGSL_2D0_IRQ "kgsl_2d0_irq"
128#define KGSL_2D1_REG_MEMORY "kgsl_2d1_reg_memory"
129#define KGSL_2D1_IRQ "kgsl_2d1_irq"
130
131struct kgsl_grp_clk_name {
132 const char *clk;
133 const char *pclk;
134};
135
136struct kgsl_device_pwr_data {
137 struct kgsl_pwrlevel pwrlevel[KGSL_MAX_PWRLEVELS];
138 int init_level;
139 int num_levels;
140 int (*set_grp_async)(void);
141 unsigned int idle_timeout;
142 unsigned int nap_allowed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700143};
144
145struct kgsl_clk_data {
146 struct kgsl_grp_clk_name name;
147 struct msm_bus_scale_pdata *bus_scale_table;
148};
149
150struct kgsl_device_platform_data {
151 struct kgsl_device_pwr_data pwr_data;
152 struct kgsl_clk_data clk;
153 /* imem_clk_name is for 3d only, not used in 2d devices */
154 struct kgsl_grp_clk_name imem_clk_name;
Shubhraprakash Das767fdda2011-08-15 15:49:45 -0600155 const char *iommu_user_ctx_name;
156 const char *iommu_priv_ctx_name;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700157};
158
159#endif
160
161/* structure holds list of ibs */
162struct kgsl_ibdesc {
163 unsigned int gpuaddr;
164 void *hostptr;
165 unsigned int sizedwords;
166 unsigned int ctrl;
167};
168
169/* ioctls */
170#define KGSL_IOC_TYPE 0x09
171
172/* get misc info about the GPU
173 type should be a value from enum kgsl_property_type
174 value points to a structure that varies based on type
175 sizebytes is sizeof() that structure
176 for KGSL_PROP_DEVICE_INFO, use struct kgsl_devinfo
177 this structure contaings hardware versioning info.
178 for KGSL_PROP_DEVICE_SHADOW, use struct kgsl_shadowprop
179 this is used to find mmap() offset and sizes for mapping
180 struct kgsl_memstore into userspace.
181*/
182struct kgsl_device_getproperty {
183 unsigned int type;
184 void *value;
185 unsigned int sizebytes;
186};
187
188#define IOCTL_KGSL_DEVICE_GETPROPERTY \
189 _IOWR(KGSL_IOC_TYPE, 0x2, struct kgsl_device_getproperty)
190
191
192/* read a GPU register.
193 offsetwords it the 32 bit word offset from the beginning of the
194 GPU register space.
195 */
196struct kgsl_device_regread {
197 unsigned int offsetwords;
198 unsigned int value; /* output param */
199};
200
201#define IOCTL_KGSL_DEVICE_REGREAD \
202 _IOWR(KGSL_IOC_TYPE, 0x3, struct kgsl_device_regread)
203
204
205/* block until the GPU has executed past a given timestamp
206 * timeout is in milliseconds.
207 */
208struct kgsl_device_waittimestamp {
209 unsigned int timestamp;
210 unsigned int timeout;
211};
212
213#define IOCTL_KGSL_DEVICE_WAITTIMESTAMP \
214 _IOW(KGSL_IOC_TYPE, 0x6, struct kgsl_device_waittimestamp)
215
216
217/* issue indirect commands to the GPU.
218 * drawctxt_id must have been created with IOCTL_KGSL_DRAWCTXT_CREATE
219 * ibaddr and sizedwords must specify a subset of a buffer created
220 * with IOCTL_KGSL_SHAREDMEM_FROM_PMEM
221 * flags may be a mask of KGSL_CONTEXT_ values
222 * timestamp is a returned counter value which can be passed to
223 * other ioctls to determine when the commands have been executed by
224 * the GPU.
225 */
226struct kgsl_ringbuffer_issueibcmds {
227 unsigned int drawctxt_id;
228 unsigned int ibdesc_addr;
229 unsigned int numibs;
230 unsigned int timestamp; /*output param */
231 unsigned int flags;
232};
233
234#define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS \
235 _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds)
236
237/* read the most recently executed timestamp value
238 * type should be a value from enum kgsl_timestamp_type
239 */
240struct kgsl_cmdstream_readtimestamp {
241 unsigned int type;
242 unsigned int timestamp; /*output param */
243};
244
Jason Varbedian80ba33d2011-07-11 17:29:05 -0700245#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700246 _IOR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp)
247
Jason Varbedian80ba33d2011-07-11 17:29:05 -0700248#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP \
249 _IOWR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp)
250
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700251/* free memory when the GPU reaches a given timestamp.
252 * gpuaddr specify a memory region created by a
253 * IOCTL_KGSL_SHAREDMEM_FROM_PMEM call
254 * type should be a value from enum kgsl_timestamp_type
255 */
256struct kgsl_cmdstream_freememontimestamp {
257 unsigned int gpuaddr;
258 unsigned int type;
259 unsigned int timestamp;
260};
261
262#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP \
263 _IOW(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp)
264
265/* Previous versions of this header had incorrectly defined
266 IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP as a read-only ioctl instead
267 of a write only ioctl. To ensure binary compatability, the following
268 #define will be used to intercept the incorrect ioctl
269*/
270
271#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_OLD \
272 _IOR(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp)
273
274/* create a draw context, which is used to preserve GPU state.
275 * The flags field may contain a mask KGSL_CONTEXT_* values
276 */
277struct kgsl_drawctxt_create {
278 unsigned int flags;
279 unsigned int drawctxt_id; /*output param */
280};
281
282#define IOCTL_KGSL_DRAWCTXT_CREATE \
283 _IOWR(KGSL_IOC_TYPE, 0x13, struct kgsl_drawctxt_create)
284
285/* destroy a draw context */
286struct kgsl_drawctxt_destroy {
287 unsigned int drawctxt_id;
288};
289
290#define IOCTL_KGSL_DRAWCTXT_DESTROY \
291 _IOW(KGSL_IOC_TYPE, 0x14, struct kgsl_drawctxt_destroy)
292
293/* add a block of pmem, fb, ashmem or user allocated address
294 * into the GPU address space */
295struct kgsl_map_user_mem {
296 int fd;
297 unsigned int gpuaddr; /*output param */
298 unsigned int len;
299 unsigned int offset;
300 unsigned int hostptr; /*input param */
301 enum kgsl_user_mem_type memtype;
302 unsigned int reserved; /* May be required to add
303 params for another mem type */
304};
305
306#define IOCTL_KGSL_MAP_USER_MEM \
307 _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem)
308
309/* add a block of pmem or fb into the GPU address space */
310struct kgsl_sharedmem_from_pmem {
311 int pmem_fd;
312 unsigned int gpuaddr; /*output param */
313 unsigned int len;
314 unsigned int offset;
315};
316
317#define IOCTL_KGSL_SHAREDMEM_FROM_PMEM \
318 _IOWR(KGSL_IOC_TYPE, 0x20, struct kgsl_sharedmem_from_pmem)
319
320/* remove memory from the GPU's address space */
321struct kgsl_sharedmem_free {
322 unsigned int gpuaddr;
323};
324
325#define IOCTL_KGSL_SHAREDMEM_FREE \
326 _IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free)
327
Sushmita Susheelendra41f8fa32011-05-11 17:15:58 -0600328struct kgsl_cff_user_event {
329 unsigned char cff_opcode;
330 unsigned int op1;
331 unsigned int op2;
332 unsigned int op3;
333 unsigned int op4;
334 unsigned int op5;
335 unsigned int __pad[2];
336};
337
338#define IOCTL_KGSL_CFF_USER_EVENT \
339 _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_cff_user_event)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700340
341struct kgsl_gmem_desc {
342 unsigned int x;
343 unsigned int y;
344 unsigned int width;
345 unsigned int height;
346 unsigned int pitch;
347};
348
349struct kgsl_buffer_desc {
350 void *hostptr;
351 unsigned int gpuaddr;
352 int size;
353 unsigned int format;
354 unsigned int pitch;
355 unsigned int enabled;
356};
357
358struct kgsl_bind_gmem_shadow {
359 unsigned int drawctxt_id;
360 struct kgsl_gmem_desc gmem_desc;
361 unsigned int shadow_x;
362 unsigned int shadow_y;
363 struct kgsl_buffer_desc shadow_buffer;
364 unsigned int buffer_id;
365};
366
367#define IOCTL_KGSL_DRAWCTXT_BIND_GMEM_SHADOW \
368 _IOW(KGSL_IOC_TYPE, 0x22, struct kgsl_bind_gmem_shadow)
369
370/* add a block of memory into the GPU address space */
371struct kgsl_sharedmem_from_vmalloc {
372 unsigned int gpuaddr; /*output param */
373 unsigned int hostptr;
374 unsigned int flags;
375};
376
377#define IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC \
378 _IOWR(KGSL_IOC_TYPE, 0x23, struct kgsl_sharedmem_from_vmalloc)
379
380#define IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE \
381 _IOW(KGSL_IOC_TYPE, 0x24, struct kgsl_sharedmem_free)
382
383struct kgsl_drawctxt_set_bin_base_offset {
384 unsigned int drawctxt_id;
385 unsigned int offset;
386};
387
388#define IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET \
389 _IOW(KGSL_IOC_TYPE, 0x25, struct kgsl_drawctxt_set_bin_base_offset)
390
391enum kgsl_cmdwindow_type {
392 KGSL_CMDWINDOW_MIN = 0x00000000,
393 KGSL_CMDWINDOW_2D = 0x00000000,
394 KGSL_CMDWINDOW_3D = 0x00000001, /* legacy */
395 KGSL_CMDWINDOW_MMU = 0x00000002,
396 KGSL_CMDWINDOW_ARBITER = 0x000000FF,
397 KGSL_CMDWINDOW_MAX = 0x000000FF,
398};
399
400/* write to the command window */
401struct kgsl_cmdwindow_write {
402 enum kgsl_cmdwindow_type target;
403 unsigned int addr;
404 unsigned int data;
405};
406
407#define IOCTL_KGSL_CMDWINDOW_WRITE \
408 _IOW(KGSL_IOC_TYPE, 0x2e, struct kgsl_cmdwindow_write)
409
410struct kgsl_gpumem_alloc {
411 unsigned long gpuaddr;
412 size_t size;
413 unsigned int flags;
414};
415
416#define IOCTL_KGSL_GPUMEM_ALLOC \
417 _IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc)
418
Jeremy Gebbena7423e42011-04-18 15:11:21 -0600419struct kgsl_cff_syncmem {
420 unsigned int gpuaddr;
421 unsigned int len;
422 unsigned int __pad[2]; /* For future binary compatibility */
423};
424
425#define IOCTL_KGSL_CFF_SYNCMEM \
426 _IOW(KGSL_IOC_TYPE, 0x30, struct kgsl_cff_syncmem)
427
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700428#ifdef __KERNEL__
429#ifdef CONFIG_MSM_KGSL_DRM
430int kgsl_gem_obj_addr(int drm_fd, int handle, unsigned long *start,
431 unsigned long *len);
432#else
433#define kgsl_gem_obj_addr(...) 0
434#endif
435#endif
436#endif /* _MSM_KGSL_H */