blob: 81e6e0d1d3600c8a90d83ce8f444a8106d28e546 [file] [log] [blame]
Rob Clark7198e6b2013-07-19 12:59:32 -04001/*
2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __MSM_DRM_H__
19#define __MSM_DRM_H__
20
Gabriel Laskar06577d02015-11-30 15:10:49 +010021#include "drm.h"
Rob Clark7198e6b2013-07-19 12:59:32 -040022
23/* Please note that modifications to all structs defined here are
24 * subject to backwards-compatibility constraints:
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020025 * 1) Do not use pointers, use __u64 instead for 32 bit / 64 bit
Rob Clark7198e6b2013-07-19 12:59:32 -040026 * user/kernel compatibility
27 * 2) Keep fields aligned to their size
28 * 3) Because of how drm_ioctl() works, we can add new fields at
29 * the end of an ioctl if some care is taken: drm_ioctl() will
30 * zero out the new fields at the tail of the ioctl, so a zero
31 * value should have a backwards compatible meaning. And for
32 * output params, userspace won't see the newly added output
33 * fields.. so that has to be somehow ok.
34 */
35
36#define MSM_PIPE_NONE 0x00
37#define MSM_PIPE_2D0 0x01
38#define MSM_PIPE_2D1 0x02
39#define MSM_PIPE_3D0 0x10
40
41/* timeouts are specified in clock-monotonic absolute times (to simplify
42 * restarting interrupted ioctls). The following struct is logically the
43 * same as 'struct timespec' but 32/64b ABI safe.
44 */
45struct drm_msm_timespec {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020046 __s64 tv_sec; /* seconds */
47 __s64 tv_nsec; /* nanoseconds */
Rob Clark7198e6b2013-07-19 12:59:32 -040048};
49
50#define MSM_PARAM_GPU_ID 0x01
51#define MSM_PARAM_GMEM_SIZE 0x02
Rob Clark4e1cbaa2014-02-04 14:16:04 -050052#define MSM_PARAM_CHIP_ID 0x03
Rob Clark7198e6b2013-07-19 12:59:32 -040053
54struct drm_msm_param {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020055 __u32 pipe; /* in, MSM_PIPE_x */
56 __u32 param; /* in, MSM_PARAM_x */
57 __u64 value; /* out (get_param) or in (set_param) */
Rob Clark7198e6b2013-07-19 12:59:32 -040058};
59
60/*
61 * GEM buffers:
62 */
63
64#define MSM_BO_SCANOUT 0x00000001 /* scanout capable */
65#define MSM_BO_GPU_READONLY 0x00000002
66#define MSM_BO_CACHE_MASK 0x000f0000
67/* cache modes */
68#define MSM_BO_CACHED 0x00010000
69#define MSM_BO_WC 0x00020000
70#define MSM_BO_UNCACHED 0x00040000
71
Rob Clark93ddb0d2014-03-03 09:42:33 -050072#define MSM_BO_FLAGS (MSM_BO_SCANOUT | \
73 MSM_BO_GPU_READONLY | \
74 MSM_BO_CACHED | \
75 MSM_BO_WC | \
76 MSM_BO_UNCACHED)
77
Rob Clark7198e6b2013-07-19 12:59:32 -040078struct drm_msm_gem_new {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020079 __u64 size; /* in */
80 __u32 flags; /* in, mask of MSM_BO_x */
81 __u32 handle; /* out */
Rob Clark7198e6b2013-07-19 12:59:32 -040082};
83
84struct drm_msm_gem_info {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020085 __u32 handle; /* in */
86 __u32 pad;
87 __u64 offset; /* out, offset to pass to mmap() */
Rob Clark7198e6b2013-07-19 12:59:32 -040088};
89
90#define MSM_PREP_READ 0x01
91#define MSM_PREP_WRITE 0x02
92#define MSM_PREP_NOSYNC 0x04
93
Rob Clark93ddb0d2014-03-03 09:42:33 -050094#define MSM_PREP_FLAGS (MSM_PREP_READ | MSM_PREP_WRITE | MSM_PREP_NOSYNC)
95
Rob Clark7198e6b2013-07-19 12:59:32 -040096struct drm_msm_gem_cpu_prep {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020097 __u32 handle; /* in */
98 __u32 op; /* in, mask of MSM_PREP_x */
Rob Clark7198e6b2013-07-19 12:59:32 -040099 struct drm_msm_timespec timeout; /* in */
100};
101
102struct drm_msm_gem_cpu_fini {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200103 __u32 handle; /* in */
Rob Clark7198e6b2013-07-19 12:59:32 -0400104};
105
106/*
107 * Cmdstream Submission:
108 */
109
110/* The value written into the cmdstream is logically:
111 *
112 * ((relocbuf->gpuaddr + reloc_offset) << shift) | or
113 *
114 * When we have GPU's w/ >32bit ptrs, it should be possible to deal
115 * with this by emit'ing two reloc entries with appropriate shift
116 * values. Or a new MSM_SUBMIT_CMD_x type would also be an option.
117 *
118 * NOTE that reloc's must be sorted by order of increasing submit_offset,
119 * otherwise EINVAL.
120 */
121struct drm_msm_gem_submit_reloc {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200122 __u32 submit_offset; /* in, offset from submit_bo */
123 __u32 or; /* in, value OR'd with result */
Rob Clark8979a052015-12-14 09:59:56 -0500124 __s32 shift; /* in, amount of left shift (can be negative) */
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200125 __u32 reloc_idx; /* in, index of reloc_bo buffer */
126 __u64 reloc_offset; /* in, offset from start of reloc_bo */
Rob Clark7198e6b2013-07-19 12:59:32 -0400127};
128
129/* submit-types:
130 * BUF - this cmd buffer is executed normally.
131 * IB_TARGET_BUF - this cmd buffer is an IB target. Reloc's are
132 * processed normally, but the kernel does not setup an IB to
133 * this buffer in the first-level ringbuffer
134 * CTX_RESTORE_BUF - only executed if there has been a GPU context
135 * switch since the last SUBMIT ioctl
136 */
137#define MSM_SUBMIT_CMD_BUF 0x0001
138#define MSM_SUBMIT_CMD_IB_TARGET_BUF 0x0002
139#define MSM_SUBMIT_CMD_CTX_RESTORE_BUF 0x0003
140struct drm_msm_gem_submit_cmd {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200141 __u32 type; /* in, one of MSM_SUBMIT_CMD_x */
142 __u32 submit_idx; /* in, index of submit_bo cmdstream buffer */
143 __u32 submit_offset; /* in, offset into submit_bo */
144 __u32 size; /* in, cmdstream size */
145 __u32 pad;
146 __u32 nr_relocs; /* in, number of submit_reloc's */
147 __u64 __user relocs; /* in, ptr to array of submit_reloc's */
Rob Clark7198e6b2013-07-19 12:59:32 -0400148};
149
150/* Each buffer referenced elsewhere in the cmdstream submit (ie. the
151 * cmdstream buffer(s) themselves or reloc entries) has one (and only
152 * one) entry in the submit->bos[] table.
153 *
154 * As a optimization, the current buffer (gpu virtual address) can be
155 * passed back through the 'presumed' field. If on a subsequent reloc,
156 * userspace passes back a 'presumed' address that is still valid,
157 * then patching the cmdstream for this entry is skipped. This can
158 * avoid kernel needing to map/access the cmdstream bo in the common
159 * case.
160 */
161#define MSM_SUBMIT_BO_READ 0x0001
162#define MSM_SUBMIT_BO_WRITE 0x0002
Rob Clark93ddb0d2014-03-03 09:42:33 -0500163
164#define MSM_SUBMIT_BO_FLAGS (MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE)
165
Rob Clark7198e6b2013-07-19 12:59:32 -0400166struct drm_msm_gem_submit_bo {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200167 __u32 flags; /* in, mask of MSM_SUBMIT_BO_x */
168 __u32 handle; /* in, GEM handle */
169 __u64 presumed; /* in/out, presumed buffer address */
Rob Clark7198e6b2013-07-19 12:59:32 -0400170};
171
172/* Each cmdstream submit consists of a table of buffers involved, and
173 * one or more cmdstream buffers. This allows for conditional execution
174 * (context-restore), and IB buffers needed for per tile/bin draw cmds.
175 */
176struct drm_msm_gem_submit {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200177 __u32 pipe; /* in, MSM_PIPE_x */
178 __u32 fence; /* out */
179 __u32 nr_bos; /* in, number of submit_bo's */
180 __u32 nr_cmds; /* in, number of submit_cmd's */
181 __u64 __user bos; /* in, ptr to array of submit_bo's */
182 __u64 __user cmds; /* in, ptr to array of submit_cmd's */
Rob Clark7198e6b2013-07-19 12:59:32 -0400183};
184
185/* The normal way to synchronize with the GPU is just to CPU_PREP on
186 * a buffer if you need to access it from the CPU (other cmdstream
187 * submission from same or other contexts, PAGE_FLIP ioctl, etc, all
188 * handle the required synchronization under the hood). This ioctl
189 * mainly just exists as a way to implement the gallium pipe_fence
190 * APIs without requiring a dummy bo to synchronize on.
191 */
192struct drm_msm_wait_fence {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200193 __u32 fence; /* in */
194 __u32 pad;
Rob Clark7198e6b2013-07-19 12:59:32 -0400195 struct drm_msm_timespec timeout; /* in */
196};
197
198#define DRM_MSM_GET_PARAM 0x00
199/* placeholder:
200#define DRM_MSM_SET_PARAM 0x01
201 */
202#define DRM_MSM_GEM_NEW 0x02
203#define DRM_MSM_GEM_INFO 0x03
204#define DRM_MSM_GEM_CPU_PREP 0x04
205#define DRM_MSM_GEM_CPU_FINI 0x05
206#define DRM_MSM_GEM_SUBMIT 0x06
207#define DRM_MSM_WAIT_FENCE 0x07
208#define DRM_MSM_NUM_IOCTLS 0x08
209
210#define DRM_IOCTL_MSM_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GET_PARAM, struct drm_msm_param)
211#define DRM_IOCTL_MSM_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_NEW, struct drm_msm_gem_new)
212#define DRM_IOCTL_MSM_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_INFO, struct drm_msm_gem_info)
213#define DRM_IOCTL_MSM_GEM_CPU_PREP DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_PREP, struct drm_msm_gem_cpu_prep)
214#define DRM_IOCTL_MSM_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_FINI, struct drm_msm_gem_cpu_fini)
215#define DRM_IOCTL_MSM_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_SUBMIT, struct drm_msm_gem_submit)
216#define DRM_IOCTL_MSM_WAIT_FENCE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_WAIT_FENCE, struct drm_msm_wait_fence)
217
218#endif /* __MSM_DRM_H__ */