blob: 6a2a26539adf8008f70d3409d8283c3fbf145394 [file] [log] [blame]
Rob Clarkf17d4172013-07-20 20:35:31 -04001/*
2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
4 *
Rob Clark128e74c2014-01-31 11:58:30 -05005 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
Rob Clarkf17d4172013-07-20 20:35:31 -040011 *
Rob Clark128e74c2014-01-31 11:58:30 -050012 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
Rob Clarkf17d4172013-07-20 20:35:31 -040015 *
Rob Clark128e74c2014-01-31 11:58:30 -050016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
Rob Clarkf17d4172013-07-20 20:35:31 -040023 */
24
25#ifndef __MSM_DRM_H__
26#define __MSM_DRM_H__
27
28#include <stddef.h>
Emil Velikov126c4582013-08-29 21:31:52 +010029#include "drm.h"
Rob Clarkf17d4172013-07-20 20:35:31 -040030
31/* Please note that modifications to all structs defined here are
32 * subject to backwards-compatibility constraints:
33 * 1) Do not use pointers, use uint64_t instead for 32 bit / 64 bit
34 * user/kernel compatibility
35 * 2) Keep fields aligned to their size
36 * 3) Because of how drm_ioctl() works, we can add new fields at
37 * the end of an ioctl if some care is taken: drm_ioctl() will
38 * zero out the new fields at the tail of the ioctl, so a zero
39 * value should have a backwards compatible meaning. And for
40 * output params, userspace won't see the newly added output
41 * fields.. so that has to be somehow ok.
42 */
43
44#define MSM_PIPE_NONE 0x00
45#define MSM_PIPE_2D0 0x01
46#define MSM_PIPE_2D1 0x02
47#define MSM_PIPE_3D0 0x10
48
49/* timeouts are specified in clock-monotonic absolute times (to simplify
50 * restarting interrupted ioctls). The following struct is logically the
51 * same as 'struct timespec' but 32/64b ABI safe.
52 */
53struct drm_msm_timespec {
54 int64_t tv_sec; /* seconds */
55 int64_t tv_nsec; /* nanoseconds */
56};
57
58#define MSM_PARAM_GPU_ID 0x01
59#define MSM_PARAM_GMEM_SIZE 0x02
Rob Clark09db8012014-06-18 09:42:11 -040060#define MSM_PARAM_CHIP_ID 0x03
Rob Clarkc47385c2016-02-10 12:26:20 -050061#define MSM_PARAM_MAX_FREQ 0x04
Rob Clark67e71032016-02-23 11:39:53 -050062#define MSM_PARAM_TIMESTAMP 0x05
Rob Clarkf17d4172013-07-20 20:35:31 -040063
64struct drm_msm_param {
65 uint32_t pipe; /* in, MSM_PIPE_x */
66 uint32_t param; /* in, MSM_PARAM_x */
67 uint64_t value; /* out (get_param) or in (set_param) */
68};
69
70/*
71 * GEM buffers:
72 */
73
74#define MSM_BO_SCANOUT 0x00000001 /* scanout capable */
75#define MSM_BO_GPU_READONLY 0x00000002
76#define MSM_BO_CACHE_MASK 0x000f0000
77/* cache modes */
78#define MSM_BO_CACHED 0x00010000
79#define MSM_BO_WC 0x00020000
80#define MSM_BO_UNCACHED 0x00040000
81
Rob Clark09db8012014-06-18 09:42:11 -040082#define MSM_BO_FLAGS (MSM_BO_SCANOUT | \
83 MSM_BO_GPU_READONLY | \
84 MSM_BO_CACHED | \
85 MSM_BO_WC | \
86 MSM_BO_UNCACHED)
87
Rob Clarkf17d4172013-07-20 20:35:31 -040088struct drm_msm_gem_new {
89 uint64_t size; /* in */
90 uint32_t flags; /* in, mask of MSM_BO_x */
91 uint32_t handle; /* out */
92};
93
94struct drm_msm_gem_info {
95 uint32_t handle; /* in */
96 uint32_t pad;
97 uint64_t offset; /* out, offset to pass to mmap() */
98};
99
100#define MSM_PREP_READ 0x01
101#define MSM_PREP_WRITE 0x02
102#define MSM_PREP_NOSYNC 0x04
103
Rob Clark09db8012014-06-18 09:42:11 -0400104#define MSM_PREP_FLAGS (MSM_PREP_READ | MSM_PREP_WRITE | MSM_PREP_NOSYNC)
105
Rob Clarkf17d4172013-07-20 20:35:31 -0400106struct drm_msm_gem_cpu_prep {
107 uint32_t handle; /* in */
108 uint32_t op; /* in, mask of MSM_PREP_x */
109 struct drm_msm_timespec timeout; /* in */
110};
111
112struct drm_msm_gem_cpu_fini {
113 uint32_t handle; /* in */
114};
115
116/*
117 * Cmdstream Submission:
118 */
119
120/* The value written into the cmdstream is logically:
121 *
122 * ((relocbuf->gpuaddr + reloc_offset) << shift) | or
123 *
124 * When we have GPU's w/ >32bit ptrs, it should be possible to deal
125 * with this by emit'ing two reloc entries with appropriate shift
126 * values. Or a new MSM_SUBMIT_CMD_x type would also be an option.
127 *
128 * NOTE that reloc's must be sorted by order of increasing submit_offset,
129 * otherwise EINVAL.
130 */
131struct drm_msm_gem_submit_reloc {
132 uint32_t submit_offset; /* in, offset from submit_bo */
133 uint32_t or; /* in, value OR'd with result */
134 int32_t shift; /* in, amount of left shift (can be negative) */
135 uint32_t reloc_idx; /* in, index of reloc_bo buffer */
136 uint64_t reloc_offset; /* in, offset from start of reloc_bo */
137};
138
139/* submit-types:
140 * BUF - this cmd buffer is executed normally.
141 * IB_TARGET_BUF - this cmd buffer is an IB target. Reloc's are
142 * processed normally, but the kernel does not setup an IB to
143 * this buffer in the first-level ringbuffer
144 * CTX_RESTORE_BUF - only executed if there has been a GPU context
145 * switch since the last SUBMIT ioctl
146 */
147#define MSM_SUBMIT_CMD_BUF 0x0001
148#define MSM_SUBMIT_CMD_IB_TARGET_BUF 0x0002
149#define MSM_SUBMIT_CMD_CTX_RESTORE_BUF 0x0003
150struct drm_msm_gem_submit_cmd {
151 uint32_t type; /* in, one of MSM_SUBMIT_CMD_x */
152 uint32_t submit_idx; /* in, index of submit_bo cmdstream buffer */
153 uint32_t submit_offset; /* in, offset into submit_bo */
154 uint32_t size; /* in, cmdstream size */
155 uint32_t pad;
156 uint32_t nr_relocs; /* in, number of submit_reloc's */
157 uint64_t __user relocs; /* in, ptr to array of submit_reloc's */
158};
159
160/* Each buffer referenced elsewhere in the cmdstream submit (ie. the
161 * cmdstream buffer(s) themselves or reloc entries) has one (and only
162 * one) entry in the submit->bos[] table.
163 *
164 * As a optimization, the current buffer (gpu virtual address) can be
165 * passed back through the 'presumed' field. If on a subsequent reloc,
166 * userspace passes back a 'presumed' address that is still valid,
167 * then patching the cmdstream for this entry is skipped. This can
168 * avoid kernel needing to map/access the cmdstream bo in the common
169 * case.
170 */
171#define MSM_SUBMIT_BO_READ 0x0001
172#define MSM_SUBMIT_BO_WRITE 0x0002
Rob Clark09db8012014-06-18 09:42:11 -0400173
174#define MSM_SUBMIT_BO_FLAGS (MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE)
175
Rob Clarkf17d4172013-07-20 20:35:31 -0400176struct drm_msm_gem_submit_bo {
177 uint32_t flags; /* in, mask of MSM_SUBMIT_BO_x */
178 uint32_t handle; /* in, GEM handle */
179 uint64_t presumed; /* in/out, presumed buffer address */
180};
181
182/* Each cmdstream submit consists of a table of buffers involved, and
183 * one or more cmdstream buffers. This allows for conditional execution
184 * (context-restore), and IB buffers needed for per tile/bin draw cmds.
185 */
186struct drm_msm_gem_submit {
187 uint32_t pipe; /* in, MSM_PIPE_x */
188 uint32_t fence; /* out */
189 uint32_t nr_bos; /* in, number of submit_bo's */
190 uint32_t nr_cmds; /* in, number of submit_cmd's */
191 uint64_t __user bos; /* in, ptr to array of submit_bo's */
192 uint64_t __user cmds; /* in, ptr to array of submit_cmd's */
193};
194
195/* The normal way to synchronize with the GPU is just to CPU_PREP on
196 * a buffer if you need to access it from the CPU (other cmdstream
197 * submission from same or other contexts, PAGE_FLIP ioctl, etc, all
198 * handle the required synchronization under the hood). This ioctl
199 * mainly just exists as a way to implement the gallium pipe_fence
200 * APIs without requiring a dummy bo to synchronize on.
201 */
202struct drm_msm_wait_fence {
203 uint32_t fence; /* in */
204 uint32_t pad;
205 struct drm_msm_timespec timeout; /* in */
206};
207
208#define DRM_MSM_GET_PARAM 0x00
209/* placeholder:
210#define DRM_MSM_SET_PARAM 0x01
211 */
212#define DRM_MSM_GEM_NEW 0x02
213#define DRM_MSM_GEM_INFO 0x03
214#define DRM_MSM_GEM_CPU_PREP 0x04
215#define DRM_MSM_GEM_CPU_FINI 0x05
216#define DRM_MSM_GEM_SUBMIT 0x06
217#define DRM_MSM_WAIT_FENCE 0x07
218#define DRM_MSM_NUM_IOCTLS 0x08
219
220#define DRM_IOCTL_MSM_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GET_PARAM, struct drm_msm_param)
221#define DRM_IOCTL_MSM_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_NEW, struct drm_msm_gem_new)
222#define DRM_IOCTL_MSM_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_INFO, struct drm_msm_gem_info)
223#define DRM_IOCTL_MSM_GEM_CPU_PREP DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_PREP, struct drm_msm_gem_cpu_prep)
224#define DRM_IOCTL_MSM_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_FINI, struct drm_msm_gem_cpu_fini)
225#define DRM_IOCTL_MSM_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_SUBMIT, struct drm_msm_gem_submit)
226#define DRM_IOCTL_MSM_WAIT_FENCE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_WAIT_FENCE, struct drm_msm_wait_fence)
227
228#endif /* __MSM_DRM_H__ */