drivers: video: tegra: change buffer gpu cacheable and add flush
[linux-3.10.git] / include / linux / nvhost_ioctl.h
1 /*
2  * include/linux/nvhost_ioctl.h
3  *
4  * Tegra graphics host driver
5  *
6  * Copyright (c) 2009-2013, NVIDIA Corporation.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  * more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  */
22
23 #ifndef __LINUX_NVHOST_IOCTL_H
24 #define __LINUX_NVHOST_IOCTL_H
25
26 #include <linux/ioctl.h>
27 #include <linux/types.h>
28
29 #if !defined(__KERNEL__)
30 #define __user
31 #endif
32
33 #define NVHOST_INVALID_SYNCPOINT 0xFFFFFFFF
34 #define NVHOST_NO_TIMEOUT (-1)
35 #define NVHOST_NO_CONTEXT 0x0
36 #define NVHOST_IOCTL_MAGIC 'H'
37 #define NVHOST_PRIORITY_LOW 50
38 #define NVHOST_PRIORITY_MEDIUM 100
39 #define NVHOST_PRIORITY_HIGH 150
40
41 #define NVHOST_TIMEOUT_FLAG_DISABLE_DUMP        0
42
43 /* version 0 header (used with write() submit interface) */
44 struct nvhost_submit_hdr {
45         __u32 syncpt_id;
46         __u32 syncpt_incrs;
47         __u32 num_cmdbufs;
48         __u32 num_relocs;
49 };
50
51 #define NVHOST_SUBMIT_VERSION_V0                0x0
52 #define NVHOST_SUBMIT_VERSION_V1                0x1
53 #define NVHOST_SUBMIT_VERSION_V2                0x2
54 #define NVHOST_SUBMIT_VERSION_MAX_SUPPORTED     NVHOST_SUBMIT_VERSION_V2
55
56 /* version 1 header (used with ioctl() submit interface) */
57 struct nvhost_submit_hdr_ext {
58         __u32 syncpt_id;        /* version 0 fields */
59         __u32 syncpt_incrs;
60         __u32 num_cmdbufs;
61         __u32 num_relocs;
62         __u32 submit_version;   /* version 1 fields */
63         __u32 num_waitchks;
64         __u32 waitchk_mask;
65         __u32 pad[5];           /* future expansion */
66 };
67
68 struct nvhost_cmdbuf {
69         __u32 mem;
70         __u32 offset;
71         __u32 words;
72 } __packed;
73
74 struct nvhost_reloc {
75         __u32 cmdbuf_mem;
76         __u32 cmdbuf_offset;
77         __u32 target;
78         __u32 target_offset;
79 };
80
81 struct nvhost_reloc_shift {
82         __u32 shift;
83 } __packed;
84
85 struct nvhost_waitchk {
86         __u32 mem;
87         __u32 offset;
88         __u32 syncpt_id;
89         __u32 thresh;
90 };
91
92 struct nvhost_syncpt_incr {
93         __u32 syncpt_id;
94         __u32 syncpt_incrs;
95 };
96
97 struct nvhost_gpfifo {
98         __u64 gpu_va;
99         __u32 words;
100 };
101
102 struct nvhost_get_param_args {
103         __u32 value;
104 } __packed;
105
106 struct nvhost_get_param_arg {
107         __u32 param;
108         __u32 value;
109 };
110
111 struct nvhost_set_nvmap_fd_args {
112         __u32 fd;
113 } __packed;
114
115 struct nvhost_alloc_obj_ctx_args {
116         __u32 class_num; /* kepler3d, 2d, compute, etc       */
117         __u32 obj_id;    /* output, used to free later       */
118         __u32 vaspace_share; /*XXX to be removed */
119 };
120
121 struct nvhost_free_obj_ctx_args {
122         __u32 obj_id; /* obj ctx to free */
123 };
124
125 struct nvhost_alloc_gpfifo_args {
126         __u32 num_entries;
127 #define NVHOST_ALLOC_GPFIFO_FLAGS_VPR_ENABLED   (1 << 0) /* set owner channel of this gpfifo as a vpr channel */
128         __u32 flags;
129
130 };
131
132 struct nvhost_fence {
133         __u32 syncpt_id; /* syncpoint id */
134         __u32 value;     /* syncpoint value to wait or value for other to wait */
135 };
136
137 struct nvhost_submit_gpfifo_args {
138         struct nvhost_gpfifo *gpfifo;
139         __u32 num_entries;
140         struct nvhost_fence fence;
141         __u32 flags;
142 /* insert a wait on the fance before submitting gpfifo */
143 #define NVHOST_SUBMIT_GPFIFO_FLAGS_FENCE_WAIT   BIT(0)
144  /* insert an fence update after submitting gpfifo and
145     return the new fence for other to wait on */
146 #define NVHOST_SUBMIT_GPFIFO_FLAGS_FENCE_GET    BIT(1)
147 };
148
149 struct nvhost_map_buffer_args {
150         __u32 flags;
151 #define NVHOST_MAP_BUFFER_FLAGS_ALIGN           0x0
152 #define NVHOST_MAP_BUFFER_FLAGS_OFFSET          BIT(0)
153 #define NVHOST_MAP_BUFFER_FLAGS_KIND_PITCH      0x0
154 #define NVHOST_MAP_BUFFER_FLAGS_KIND_SPECIFIED  BIT(1)
155 #define NVHOST_MAP_BUFFER_FLAGS_CACHEABLE_FALSE 0x0
156 #define NVHOST_MAP_BUFFER_FLAGS_CACHEABLE_TRUE  BIT(2)
157         __u32 nvmap_handle;
158         union {
159                 __u64 offset; /* valid if _offset flag given (in|out) */
160                 __u64 align;  /* alignment multiple (0:={1 or n/a})   */
161         } offset_alignment;
162         __u32 kind;
163 #define NVHOST_MAP_BUFFER_KIND_GENERIC_16BX2 0xfe
164 };
165
166 struct nvhost_unmap_buffer_args {
167         __u64 offset;
168 };
169
170 struct nvhost_wait_args {
171 #define NVHOST_WAIT_TYPE_NOTIFIER       0x0
172 #define NVHOST_WAIT_TYPE_SEMAPHORE      0x1
173         __u32 type;
174         __u32 timeout;
175         union {
176                 struct {
177                         /* handle and offset for notifier memory */
178                         __u32 nvmap_handle;
179                         __u32 offset;
180                 } notifier;
181                 struct {
182                         /* handle and offset for semaphore memory */
183                         __u32 nvmap_handle;
184                         __u32 offset;
185                         /* semaphore payload to wait for */
186                         __u32 payload;
187                 } semaphore;
188         } condition; /* determined by type field */
189 };
190
191 struct nvhost_read_3d_reg_args {
192         __u32 offset;
193         __u32 value;
194 };
195
196 enum nvhost_clk_attr {
197         NVHOST_CLOCK = 0,
198         NVHOST_BW,
199 };
200
201 /*
202  * moduleid[15:0]  => module id
203  * moduleid[24:31] => nvhost_clk_attr
204  */
205 #define NVHOST_MODULE_ID_BIT_POS        0
206 #define NVHOST_MODULE_ID_BIT_WIDTH      16
207 #define NVHOST_CLOCK_ATTR_BIT_POS       24
208 #define NVHOST_CLOCK_ATTR_BIT_WIDTH     8
209 struct nvhost_clk_rate_args {
210         __u32 rate;
211         __u32 moduleid;
212 };
213
214 struct nvhost_set_timeout_args {
215         __u32 timeout;
216 } __packed;
217
218 struct nvhost_set_timeout_ex_args {
219         __u32 timeout;
220         __u32 flags;
221 };
222
223 struct nvhost_set_priority_args {
224         __u32 priority;
225 } __packed;
226
227 struct nvhost_zcull_get_size_args {
228         __u32 size;
229 };
230
231 #define NVHOST_ZCULL_MODE_GLOBAL                0
232 #define NVHOST_ZCULL_MODE_NO_CTXSW              1
233 #define NVHOST_ZCULL_MODE_SEPARATE_BUFFER       2
234 #define NVHOST_ZCULL_MODE_PART_OF_REGULAR_BUF   3
235
236 struct nvhost_zcull_bind_args {
237         __u64 gpu_va;
238         __u32 mode;
239 };
240
241 struct nvhost_zcull_get_info_args {
242         __u32 width_align_pixels;
243         __u32 height_align_pixels;
244         __u32 pixel_squares_by_aliquots;
245         __u32 aliquot_total;
246         __u32 region_byte_multiplier;
247         __u32 region_header_size;
248         __u32 subregion_header_size;
249         __u32 subregion_width_align_pixels;
250         __u32 subregion_height_align_pixels;
251         __u32 subregion_count;
252 };
253
254 #define NVHOST_ZBC_COLOR_VALUE_SIZE     4
255 #define NVHOST_ZBC_TYPE_INVALID         0
256 #define NVHOST_ZBC_TYPE_COLOR           1
257 #define NVHOST_ZBC_TYPE_DEPTH           2
258
259 struct nvhost_zbc_set_table_args {
260         __u32 color_ds[NVHOST_ZBC_COLOR_VALUE_SIZE];
261         __u32 color_l2[NVHOST_ZBC_COLOR_VALUE_SIZE];
262         __u32 depth;
263         __u32 format;
264         __u32 type;     /* color or depth */
265 };
266
267 struct nvhost_zbc_query_table_args {
268         __u32 color_ds[NVHOST_ZBC_COLOR_VALUE_SIZE];
269         __u32 color_l2[NVHOST_ZBC_COLOR_VALUE_SIZE];
270         __u32 depth;
271         __u32 ref_cnt;
272         __u32 format;
273         __u32 type;             /* color or depth */
274         __u32 index_size;       /* [out] size, [in] index */
275 };
276
277 struct nvhost_ctrl_module_regrdwr_args {
278         __u32 id;
279         __u32 num_offsets;
280         __u32 block_size;
281         __u32 offsets;
282         __u32 values;
283         __u32 write;
284 };
285
286 struct nvhost_submit_args {
287         __u32 submit_version;
288         __u32 num_syncpt_incrs;
289         __u32 num_cmdbufs;
290         __u32 num_relocs;
291         __u32 num_waitchks;
292         __u32 timeout;
293         __u32 syncpt_incrs;
294         __u32 cmdbufs;
295         __u32 relocs;
296         __u32 reloc_shifts;
297         __u32 waitchks;
298         __u32 waitbases;
299
300         __u32 pad[3];           /* future expansion */
301         __u32 fences;
302         __u32 fence;            /* Return value */
303 } __packed;
304
305 struct nvhost_set_ctxswitch_args {
306         __u32 num_cmdbufs_save;
307         __u32 num_save_incrs;
308         __u32 save_incrs;
309         __u32 save_waitbases;
310         __u32 cmdbuf_save;
311         __u32 num_cmdbufs_restore;
312         __u32 num_restore_incrs;
313         __u32 restore_incrs;
314         __u32 restore_waitbases;
315         __u32 cmdbuf_restore;
316         __u32 num_relocs;
317         __u32 relocs;
318         __u32 reloc_shifts;
319
320         __u32 pad;
321 };
322
323 #define NVHOST_IOCTL_CHANNEL_FLUSH              \
324         _IOR(NVHOST_IOCTL_MAGIC, 1, struct nvhost_get_param_args)
325 #define NVHOST_IOCTL_CHANNEL_GET_SYNCPOINTS     \
326         _IOR(NVHOST_IOCTL_MAGIC, 2, struct nvhost_get_param_args)
327 #define NVHOST_IOCTL_CHANNEL_GET_WAITBASES      \
328         _IOR(NVHOST_IOCTL_MAGIC, 3, struct nvhost_get_param_args)
329 #define NVHOST_IOCTL_CHANNEL_GET_MODMUTEXES     \
330         _IOR(NVHOST_IOCTL_MAGIC, 4, struct nvhost_get_param_args)
331 #define NVHOST_IOCTL_CHANNEL_SET_NVMAP_FD       \
332         _IOW(NVHOST_IOCTL_MAGIC, 5, struct nvhost_set_nvmap_fd_args)
333 #define NVHOST_IOCTL_CHANNEL_NULL_KICKOFF       \
334         _IOR(NVHOST_IOCTL_MAGIC, 6, struct nvhost_get_param_args)
335 #define NVHOST_IOCTL_CHANNEL_SUBMIT_EXT         \
336         _IOW(NVHOST_IOCTL_MAGIC, 7, struct nvhost_submit_hdr_ext)
337 #define NVHOST_IOCTL_CHANNEL_READ_3D_REG \
338         _IOWR(NVHOST_IOCTL_MAGIC, 8, struct nvhost_read_3d_reg_args)
339 #define NVHOST_IOCTL_CHANNEL_GET_CLK_RATE               \
340         _IOR(NVHOST_IOCTL_MAGIC, 9, struct nvhost_clk_rate_args)
341 #define NVHOST_IOCTL_CHANNEL_SET_CLK_RATE               \
342         _IOW(NVHOST_IOCTL_MAGIC, 10, struct nvhost_clk_rate_args)
343 #define NVHOST_IOCTL_CHANNEL_SET_TIMEOUT        \
344         _IOW(NVHOST_IOCTL_MAGIC, 11, struct nvhost_set_timeout_args)
345 #define NVHOST_IOCTL_CHANNEL_GET_TIMEDOUT       \
346         _IOR(NVHOST_IOCTL_MAGIC, 12, struct nvhost_get_param_args)
347 #define NVHOST_IOCTL_CHANNEL_SET_PRIORITY       \
348         _IOW(NVHOST_IOCTL_MAGIC, 13, struct nvhost_set_priority_args)
349 #define NVHOST_IOCTL_CHANNEL_MODULE_REGRDWR     \
350         _IOWR(NVHOST_IOCTL_MAGIC, 14, struct nvhost_ctrl_module_regrdwr_args)
351 #define NVHOST_IOCTL_CHANNEL_SUBMIT             \
352         _IOWR(NVHOST_IOCTL_MAGIC, 15, struct nvhost_submit_args)
353 #define NVHOST_IOCTL_CHANNEL_GET_SYNCPOINT      \
354         _IOWR(NVHOST_IOCTL_MAGIC, 16, struct nvhost_get_param_arg)
355 #define NVHOST_IOCTL_CHANNEL_GET_WAITBASE       \
356         _IOWR(NVHOST_IOCTL_MAGIC, 17, struct nvhost_get_param_arg)
357 #define NVHOST_IOCTL_CHANNEL_SET_TIMEOUT_EX     \
358         _IOWR(NVHOST_IOCTL_MAGIC, 18, struct nvhost_set_timeout_ex_args)
359 #define NVHOST_IOCTL_CHANNEL_GET_MODMUTEX       \
360         _IOWR(NVHOST_IOCTL_MAGIC, 23, struct nvhost_get_param_arg)
361 #define NVHOST_IOCTL_CHANNEL_SET_CTXSWITCH      \
362         _IOWR(NVHOST_IOCTL_MAGIC, 25, struct nvhost_set_ctxswitch_args)
363
364 /* START of T124 IOCTLS */
365 #define NVHOST_IOCTL_CHANNEL_ALLOC_GPFIFO       \
366         _IOW(NVHOST_IOCTL_MAGIC,  100, struct nvhost_alloc_gpfifo_args)
367 #define NVHOST_IOCTL_CHANNEL_SUBMIT_GPFIFO      \
368         _IOWR(NVHOST_IOCTL_MAGIC, 101, struct nvhost_submit_gpfifo_args)
369 #define NVHOST_IOCTL_CHANNEL_WAIT               \
370         _IOWR(NVHOST_IOCTL_MAGIC, 102, struct nvhost_wait_args)
371 #define NVHOST_IOCTL_CHANNEL_ZCULL_BIND         \
372         _IOWR(NVHOST_IOCTL_MAGIC, 103, struct nvhost_zcull_bind_args)
373 #define NVHOST_IOCTL_CHANNEL_ALLOC_OBJ_CTX      \
374         _IOWR(NVHOST_IOCTL_MAGIC, 104, struct nvhost_alloc_obj_ctx_args)
375 #define NVHOST_IOCTL_CHANNEL_FREE_OBJ_CTX       \
376         _IOR(NVHOST_IOCTL_MAGIC,  105, struct nvhost_free_obj_ctx_args)
377
378 #define NVHOST_IOCTL_CHANNEL_MAP_BUFFER        \
379         _IOWR(NVHOST_IOCTL_MAGIC, 118, struct nvhost_map_buffer_args)
380 #define NVHOST_IOCTL_CHANNEL_UNMAP_BUFFER \
381         _IOWR(NVHOST_IOCTL_MAGIC, 119, struct nvhost_unmap_buffer_args)
382 #define NVHOST_IOCTL_CHANNEL_ZCULL_GET_SIZE    \
383         _IOWR(NVHOST_IOCTL_MAGIC, 123, struct nvhost_zcull_get_size_args)
384 #define NVHOST_IOCTL_CHANNEL_ZCULL_GET_INFO    \
385         _IOWR(NVHOST_IOCTL_MAGIC, 125, struct nvhost_zcull_get_info_args)
386 #define NVHOST_IOCTL_CHANNEL_ZBC_SET_TABLE     \
387         _IOWR(NVHOST_IOCTL_MAGIC, 126, struct nvhost_zbc_set_table_args)
388 #define NVHOST_IOCTL_CHANNEL_ZBC_QUERY_TABLE   \
389         _IOWR(NVHOST_IOCTL_MAGIC, 127, struct nvhost_zbc_query_table_args)
390
391 #define NVHOST_IOCTL_CHANNEL_LAST               \
392         _IOC_NR(NVHOST_IOCTL_CHANNEL_ZBC_QUERY_TABLE)
393
394 #define NVHOST_IOCTL_CHANNEL_MAX_ARG_SIZE sizeof(struct nvhost_zbc_query_table_args)
395
396 struct nvhost_ctrl_syncpt_read_args {
397         __u32 id;
398         __u32 value;
399 };
400
401 struct nvhost_ctrl_syncpt_incr_args {
402         __u32 id;
403 } __packed;
404
405 struct nvhost_ctrl_syncpt_wait_args {
406         __u32 id;
407         __u32 thresh;
408         __s32 timeout;
409 } __packed;
410
411 struct nvhost_ctrl_syncpt_waitex_args {
412         __u32 id;
413         __u32 thresh;
414         __s32 timeout;
415         __u32 value;
416 };
417
418 struct nvhost_ctrl_syncpt_waitmex_args {
419         __u32 id;
420         __u32 thresh;
421         __s32 timeout;
422         __u32 value;
423         __u32 tv_sec;
424         __u32 tv_nsec;
425         __u32 reserved_1;
426         __u32 reserved_2;
427 };
428
429 struct nvhost_ctrl_sync_fence_info {
430         __u32 id;
431         __u32 thresh;
432 };
433
434 struct nvhost_ctrl_sync_fence_create_args {
435         __u32 num_pts;
436         __u64 pts; /* struct nvhost_ctrl_sync_fence_info* */
437         __u64 name; /* const char* */
438         __s32 fence_fd; /* fd of new fence */
439 };
440
441 struct nvhost_ctrl_module_mutex_args {
442         __u32 id;
443         __u32 lock;
444 };
445
446 enum nvhost_module_id {
447         NVHOST_MODULE_NONE = -1,
448         NVHOST_MODULE_DISPLAY_A = 0,
449         NVHOST_MODULE_DISPLAY_B,
450         NVHOST_MODULE_VI,
451         NVHOST_MODULE_ISP,
452         NVHOST_MODULE_MPE,
453         NVHOST_MODULE_MSENC,
454         NVHOST_MODULE_TSEC,
455         NVHOST_MODULE_GPU,
456         NVHOST_MODULE_VIC,
457 };
458
459 #define NVHOST_IOCTL_CTRL_SYNCPT_READ           \
460         _IOWR(NVHOST_IOCTL_MAGIC, 1, struct nvhost_ctrl_syncpt_read_args)
461 #define NVHOST_IOCTL_CTRL_SYNCPT_INCR           \
462         _IOW(NVHOST_IOCTL_MAGIC, 2, struct nvhost_ctrl_syncpt_incr_args)
463 #define NVHOST_IOCTL_CTRL_SYNCPT_WAIT           \
464         _IOW(NVHOST_IOCTL_MAGIC, 3, struct nvhost_ctrl_syncpt_wait_args)
465
466 #define NVHOST_IOCTL_CTRL_MODULE_MUTEX          \
467         _IOWR(NVHOST_IOCTL_MAGIC, 4, struct nvhost_ctrl_module_mutex_args)
468 #define NVHOST_IOCTL_CTRL_MODULE_REGRDWR        \
469         _IOWR(NVHOST_IOCTL_MAGIC, 5, struct nvhost_ctrl_module_regrdwr_args)
470
471 #define NVHOST_IOCTL_CTRL_SYNCPT_WAITEX         \
472         _IOWR(NVHOST_IOCTL_MAGIC, 6, struct nvhost_ctrl_syncpt_waitex_args)
473
474 #define NVHOST_IOCTL_CTRL_GET_VERSION   \
475         _IOR(NVHOST_IOCTL_MAGIC, 7, struct nvhost_get_param_args)
476
477 #define NVHOST_IOCTL_CTRL_SYNCPT_READ_MAX       \
478         _IOWR(NVHOST_IOCTL_MAGIC, 8, struct nvhost_ctrl_syncpt_read_args)
479
480 #define NVHOST_IOCTL_CTRL_SYNCPT_WAITMEX        \
481         _IOWR(NVHOST_IOCTL_MAGIC, 9, struct nvhost_ctrl_syncpt_waitmex_args)
482
483 #define NVHOST_IOCTL_CTRL_SYNC_FENCE_CREATE     \
484         _IOWR(NVHOST_IOCTL_MAGIC, 10, struct nvhost_ctrl_sync_fence_create_args)
485
486 #define NVHOST_IOCTL_CTRL_LAST                  \
487         _IOC_NR(NVHOST_IOCTL_CTRL_SYNC_FENCE_CREATE)
488 #define NVHOST_IOCTL_CTRL_MAX_ARG_SIZE  \
489         sizeof(struct nvhost_ctrl_syncpt_waitmex_args)
490
491 #endif