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