blob: eb7e0c67ecfcbe4f38ba2da52b26629bcf1b1179 [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"
Alan Kwongbb27c092016-07-20 16:41:25 -040022#include "sde_drm.h"
Rob Clark7198e6b2013-07-19 12:59:32 -040023
Emil Velikova62424e2016-04-07 19:03:46 +010024#if defined(__cplusplus)
25extern "C" {
26#endif
27
Rob Clark7198e6b2013-07-19 12:59:32 -040028/* Please note that modifications to all structs defined here are
29 * subject to backwards-compatibility constraints:
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020030 * 1) Do not use pointers, use __u64 instead for 32 bit / 64 bit
Rob Clark7198e6b2013-07-19 12:59:32 -040031 * user/kernel compatibility
32 * 2) Keep fields aligned to their size
33 * 3) Because of how drm_ioctl() works, we can add new fields at
34 * the end of an ioctl if some care is taken: drm_ioctl() will
35 * zero out the new fields at the tail of the ioctl, so a zero
36 * value should have a backwards compatible meaning. And for
37 * output params, userspace won't see the newly added output
38 * fields.. so that has to be somehow ok.
39 */
40
41#define MSM_PIPE_NONE 0x00
42#define MSM_PIPE_2D0 0x01
43#define MSM_PIPE_2D1 0x02
44#define MSM_PIPE_3D0 0x10
45
Rob Clarkd9c181e2016-04-23 10:08:59 -040046/* The pipe-id just uses the lower bits, so can be OR'd with flags in
47 * the upper 16 bits (which could be extended further, if needed, maybe
48 * we extend/overload the pipe-id some day to deal with multiple rings,
49 * but even then I don't think we need the full lower 16 bits).
50 */
51#define MSM_PIPE_ID_MASK 0xffff
52#define MSM_PIPE_ID(x) ((x) & MSM_PIPE_ID_MASK)
53#define MSM_PIPE_FLAGS(x) ((x) & ~MSM_PIPE_ID_MASK)
54
Rob Clark7198e6b2013-07-19 12:59:32 -040055/* timeouts are specified in clock-monotonic absolute times (to simplify
56 * restarting interrupted ioctls). The following struct is logically the
57 * same as 'struct timespec' but 32/64b ABI safe.
58 */
59struct drm_msm_timespec {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020060 __s64 tv_sec; /* seconds */
61 __s64 tv_nsec; /* nanoseconds */
Rob Clark7198e6b2013-07-19 12:59:32 -040062};
63
64#define MSM_PARAM_GPU_ID 0x01
65#define MSM_PARAM_GMEM_SIZE 0x02
Rob Clark4e1cbaa2014-02-04 14:16:04 -050066#define MSM_PARAM_CHIP_ID 0x03
Rob Clark4102a9e2016-02-09 12:05:30 -050067#define MSM_PARAM_MAX_FREQ 0x04
Rob Clark6c77d1a2016-02-22 06:26:21 -050068#define MSM_PARAM_TIMESTAMP 0x05
Rob Clark7198e6b2013-07-19 12:59:32 -040069
70struct drm_msm_param {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020071 __u32 pipe; /* in, MSM_PIPE_x */
72 __u32 param; /* in, MSM_PARAM_x */
73 __u64 value; /* out (get_param) or in (set_param) */
Rob Clark7198e6b2013-07-19 12:59:32 -040074};
75
76/*
77 * GEM buffers:
78 */
79
80#define MSM_BO_SCANOUT 0x00000001 /* scanout capable */
81#define MSM_BO_GPU_READONLY 0x00000002
82#define MSM_BO_CACHE_MASK 0x000f0000
83/* cache modes */
84#define MSM_BO_CACHED 0x00010000
85#define MSM_BO_WC 0x00020000
86#define MSM_BO_UNCACHED 0x00040000
87
Rob Clark93ddb0d2014-03-03 09:42:33 -050088#define MSM_BO_FLAGS (MSM_BO_SCANOUT | \
89 MSM_BO_GPU_READONLY | \
90 MSM_BO_CACHED | \
91 MSM_BO_WC | \
92 MSM_BO_UNCACHED)
93
Rob Clark7198e6b2013-07-19 12:59:32 -040094struct drm_msm_gem_new {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +020095 __u64 size; /* in */
96 __u32 flags; /* in, mask of MSM_BO_x */
97 __u32 handle; /* out */
Rob Clark7198e6b2013-07-19 12:59:32 -040098};
99
100struct drm_msm_gem_info {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200101 __u32 handle; /* in */
102 __u32 pad;
103 __u64 offset; /* out, offset to pass to mmap() */
Rob Clark7198e6b2013-07-19 12:59:32 -0400104};
105
106#define MSM_PREP_READ 0x01
107#define MSM_PREP_WRITE 0x02
108#define MSM_PREP_NOSYNC 0x04
109
Rob Clark93ddb0d2014-03-03 09:42:33 -0500110#define MSM_PREP_FLAGS (MSM_PREP_READ | MSM_PREP_WRITE | MSM_PREP_NOSYNC)
111
Rob Clark7198e6b2013-07-19 12:59:32 -0400112struct drm_msm_gem_cpu_prep {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200113 __u32 handle; /* in */
114 __u32 op; /* in, mask of MSM_PREP_x */
Rob Clark7198e6b2013-07-19 12:59:32 -0400115 struct drm_msm_timespec timeout; /* in */
116};
117
118struct drm_msm_gem_cpu_fini {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200119 __u32 handle; /* in */
Rob Clark7198e6b2013-07-19 12:59:32 -0400120};
121
122/*
123 * Cmdstream Submission:
124 */
125
126/* The value written into the cmdstream is logically:
127 *
128 * ((relocbuf->gpuaddr + reloc_offset) << shift) | or
129 *
130 * When we have GPU's w/ >32bit ptrs, it should be possible to deal
131 * with this by emit'ing two reloc entries with appropriate shift
132 * values. Or a new MSM_SUBMIT_CMD_x type would also be an option.
133 *
134 * NOTE that reloc's must be sorted by order of increasing submit_offset,
135 * otherwise EINVAL.
136 */
137struct drm_msm_gem_submit_reloc {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200138 __u32 submit_offset; /* in, offset from submit_bo */
139 __u32 or; /* in, value OR'd with result */
Rob Clark8979a052015-12-14 09:59:56 -0500140 __s32 shift; /* in, amount of left shift (can be negative) */
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200141 __u32 reloc_idx; /* in, index of reloc_bo buffer */
142 __u64 reloc_offset; /* in, offset from start of reloc_bo */
Rob Clark7198e6b2013-07-19 12:59:32 -0400143};
144
145/* submit-types:
146 * BUF - this cmd buffer is executed normally.
147 * IB_TARGET_BUF - this cmd buffer is an IB target. Reloc's are
148 * processed normally, but the kernel does not setup an IB to
149 * this buffer in the first-level ringbuffer
150 * CTX_RESTORE_BUF - only executed if there has been a GPU context
151 * switch since the last SUBMIT ioctl
152 */
153#define MSM_SUBMIT_CMD_BUF 0x0001
154#define MSM_SUBMIT_CMD_IB_TARGET_BUF 0x0002
155#define MSM_SUBMIT_CMD_CTX_RESTORE_BUF 0x0003
156struct drm_msm_gem_submit_cmd {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200157 __u32 type; /* in, one of MSM_SUBMIT_CMD_x */
158 __u32 submit_idx; /* in, index of submit_bo cmdstream buffer */
159 __u32 submit_offset; /* in, offset into submit_bo */
160 __u32 size; /* in, cmdstream size */
161 __u32 pad;
162 __u32 nr_relocs; /* in, number of submit_reloc's */
163 __u64 __user relocs; /* in, ptr to array of submit_reloc's */
Rob Clark7198e6b2013-07-19 12:59:32 -0400164};
165
166/* Each buffer referenced elsewhere in the cmdstream submit (ie. the
167 * cmdstream buffer(s) themselves or reloc entries) has one (and only
168 * one) entry in the submit->bos[] table.
169 *
170 * As a optimization, the current buffer (gpu virtual address) can be
171 * passed back through the 'presumed' field. If on a subsequent reloc,
172 * userspace passes back a 'presumed' address that is still valid,
173 * then patching the cmdstream for this entry is skipped. This can
174 * avoid kernel needing to map/access the cmdstream bo in the common
175 * case.
176 */
177#define MSM_SUBMIT_BO_READ 0x0001
178#define MSM_SUBMIT_BO_WRITE 0x0002
Rob Clark93ddb0d2014-03-03 09:42:33 -0500179
180#define MSM_SUBMIT_BO_FLAGS (MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE)
181
Rob Clark7198e6b2013-07-19 12:59:32 -0400182struct drm_msm_gem_submit_bo {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200183 __u32 flags; /* in, mask of MSM_SUBMIT_BO_x */
184 __u32 handle; /* in, GEM handle */
185 __u64 presumed; /* in/out, presumed buffer address */
Rob Clark7198e6b2013-07-19 12:59:32 -0400186};
187
Rob Clarkd9c181e2016-04-23 10:08:59 -0400188/* Valid submit ioctl flags: */
Rob Clarkf0a42bb2016-06-16 16:08:19 -0400189#define MSM_SUBMIT_NO_IMPLICIT 0x80000000 /* disable implicit sync */
190#define MSM_SUBMIT_FENCE_FD_IN 0x40000000 /* enable input fence_fd */
Rob Clark4cd09452016-06-16 16:43:49 -0400191#define MSM_SUBMIT_FENCE_FD_OUT 0x20000000 /* enable output fence_fd */
Rob Clarkf0a42bb2016-06-16 16:08:19 -0400192#define MSM_SUBMIT_FLAGS ( \
193 MSM_SUBMIT_NO_IMPLICIT | \
194 MSM_SUBMIT_FENCE_FD_IN | \
Rob Clark4cd09452016-06-16 16:43:49 -0400195 MSM_SUBMIT_FENCE_FD_OUT | \
Rob Clarkf0a42bb2016-06-16 16:08:19 -0400196 0)
Rob Clarkd9c181e2016-04-23 10:08:59 -0400197
Rob Clark7198e6b2013-07-19 12:59:32 -0400198/* Each cmdstream submit consists of a table of buffers involved, and
199 * one or more cmdstream buffers. This allows for conditional execution
200 * (context-restore), and IB buffers needed for per tile/bin draw cmds.
201 */
202struct drm_msm_gem_submit {
Rob Clarkd9c181e2016-04-23 10:08:59 -0400203 __u32 flags; /* MSM_PIPE_x | MSM_SUBMIT_x */
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200204 __u32 fence; /* out */
205 __u32 nr_bos; /* in, number of submit_bo's */
206 __u32 nr_cmds; /* in, number of submit_cmd's */
207 __u64 __user bos; /* in, ptr to array of submit_bo's */
208 __u64 __user cmds; /* in, ptr to array of submit_cmd's */
Rob Clark4cd09452016-06-16 16:43:49 -0400209 __s32 fence_fd; /* in/out fence fd (see MSM_SUBMIT_FENCE_FD_IN/OUT) */
Rob Clark7198e6b2013-07-19 12:59:32 -0400210};
211
212/* The normal way to synchronize with the GPU is just to CPU_PREP on
213 * a buffer if you need to access it from the CPU (other cmdstream
214 * submission from same or other contexts, PAGE_FLIP ioctl, etc, all
215 * handle the required synchronization under the hood). This ioctl
216 * mainly just exists as a way to implement the gallium pipe_fence
217 * APIs without requiring a dummy bo to synchronize on.
218 */
219struct drm_msm_wait_fence {
Mikko Rapeli7f8fc882015-05-30 17:38:08 +0200220 __u32 fence; /* in */
221 __u32 pad;
Rob Clark7198e6b2013-07-19 12:59:32 -0400222 struct drm_msm_timespec timeout; /* in */
223};
224
Rob Clark4cd33c42016-05-17 15:44:49 -0400225/* madvise provides a way to tell the kernel in case a buffers contents
226 * can be discarded under memory pressure, which is useful for userspace
227 * bo cache where we want to optimistically hold on to buffer allocate
228 * and potential mmap, but allow the pages to be discarded under memory
229 * pressure.
230 *
231 * Typical usage would involve madvise(DONTNEED) when buffer enters BO
232 * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
233 * In the WILLNEED case, 'retained' indicates to userspace whether the
234 * backing pages still exist.
235 */
236#define MSM_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */
237#define MSM_MADV_DONTNEED 1 /* backing pages not needed */
238#define __MSM_MADV_PURGED 2 /* internal state */
239
240struct drm_msm_gem_madvise {
241 __u32 handle; /* in, GEM handle */
242 __u32 madv; /* in, MSM_MADV_x */
243 __u32 retained; /* out, whether backing store still exists */
244};
245
Ping Li898b1bf2017-02-09 18:03:28 -0800246/* HDR WRGB x and y index */
247#define DISPLAY_PRIMARIES_WX 0
248#define DISPLAY_PRIMARIES_WY 1
249#define DISPLAY_PRIMARIES_RX 2
250#define DISPLAY_PRIMARIES_RY 3
251#define DISPLAY_PRIMARIES_GX 4
252#define DISPLAY_PRIMARIES_GY 5
253#define DISPLAY_PRIMARIES_BX 6
254#define DISPLAY_PRIMARIES_BY 7
255#define DISPLAY_PRIMARIES_MAX 8
256
257struct drm_panel_hdr_properties {
258 __u32 hdr_enabled;
259
260 /* WRGB X and y values arrayed in format */
261 /* [WX, WY, RX, RY, GX, GY, BX, BY] */
262 __u32 display_primaries[DISPLAY_PRIMARIES_MAX];
263
264 /* peak brightness supported by panel */
265 __u32 peak_brightness;
266 /* Blackness level supported by panel */
267 __u32 blackness_level;
268};
269
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700270/**
271 * struct drm_msm_event_req - Payload to event enable/disable ioctls.
272 * @object_id: DRM object id. e.g.: for crtc pass crtc id.
273 * @object_type: DRM object type. e.g.: for crtc set it to DRM_MODE_OBJECT_CRTC.
274 * @event: Event for which notification is being enabled/disabled.
275 * e.g.: for Histogram set - DRM_EVENT_HISTOGRAM.
276 * @client_context: Opaque pointer that will be returned during event response
277 * notification.
278 * @index: Object index(e.g.: crtc index), optional for user-space to set.
279 * Driver will override value based on object_id and object_type.
280 */
281struct drm_msm_event_req {
282 __u32 object_id;
283 __u32 object_type;
284 __u32 event;
285 __u64 client_context;
286 __u32 index;
287};
288
289/**
290 * struct drm_msm_event_resp - payload returned when read is called for
291 * custom notifications.
292 * @base: Event type and length of complete notification payload.
293 * @info: Contains information about DRM that which raised this event.
294 * @data: Custom payload that driver returns for event type.
295 * size of data = base.length - (sizeof(base) + sizeof(info))
296 */
297struct drm_msm_event_resp {
298 struct drm_event base;
299 struct drm_msm_event_req info;
300 __u8 data[];
301};
302
Rob Clark7198e6b2013-07-19 12:59:32 -0400303#define DRM_MSM_GET_PARAM 0x00
304/* placeholder:
305#define DRM_MSM_SET_PARAM 0x01
306 */
307#define DRM_MSM_GEM_NEW 0x02
308#define DRM_MSM_GEM_INFO 0x03
309#define DRM_MSM_GEM_CPU_PREP 0x04
310#define DRM_MSM_GEM_CPU_FINI 0x05
311#define DRM_MSM_GEM_SUBMIT 0x06
312#define DRM_MSM_WAIT_FENCE 0x07
Rob Clark4cd33c42016-05-17 15:44:49 -0400313#define DRM_MSM_GEM_MADVISE 0x08
Jordan Crouse119a1ce2017-03-07 11:14:03 -0700314
315#define DRM_SDE_WB_CONFIG 0x40
316#define DRM_MSM_REGISTER_EVENT 0x41
317#define DRM_MSM_DEREGISTER_EVENT 0x42
Lloyd Atkinsonf76121a2017-01-30 17:30:55 -0500318#define DRM_MSM_RMFB2 0x43
Rob Clark7198e6b2013-07-19 12:59:32 -0400319
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700320/* sde custom events */
321#define DRM_EVENT_HISTOGRAM 0x80000000
322#define DRM_EVENT_AD_BACKLIGHT 0x80000001
Gopikrishnaiah Anandan84b4f672017-04-26 10:28:51 -0700323#define DRM_EVENT_CRTC_POWER 0x80000002
324#define DRM_EVENT_SYS_BACKLIGHT 0x80000003
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700325
Rob Clark7198e6b2013-07-19 12:59:32 -0400326#define DRM_IOCTL_MSM_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GET_PARAM, struct drm_msm_param)
327#define DRM_IOCTL_MSM_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_NEW, struct drm_msm_gem_new)
328#define DRM_IOCTL_MSM_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_INFO, struct drm_msm_gem_info)
329#define DRM_IOCTL_MSM_GEM_CPU_PREP DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_PREP, struct drm_msm_gem_cpu_prep)
330#define DRM_IOCTL_MSM_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_FINI, struct drm_msm_gem_cpu_fini)
331#define DRM_IOCTL_MSM_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_SUBMIT, struct drm_msm_gem_submit)
332#define DRM_IOCTL_MSM_WAIT_FENCE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_WAIT_FENCE, struct drm_msm_wait_fence)
Rob Clark4cd33c42016-05-17 15:44:49 -0400333#define DRM_IOCTL_MSM_GEM_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_MADVISE, struct drm_msm_gem_madvise)
Alan Kwongbb27c092016-07-20 16:41:25 -0400334#define DRM_IOCTL_SDE_WB_CONFIG \
335 DRM_IOW((DRM_COMMAND_BASE + DRM_SDE_WB_CONFIG), struct sde_drm_wb_cfg)
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700336#define DRM_IOCTL_MSM_REGISTER_EVENT DRM_IOW((DRM_COMMAND_BASE + \
337 DRM_MSM_REGISTER_EVENT), struct drm_msm_event_req)
338#define DRM_IOCTL_MSM_DEREGISTER_EVENT DRM_IOW((DRM_COMMAND_BASE + \
339 DRM_MSM_DEREGISTER_EVENT), struct drm_msm_event_req)
Lloyd Atkinsonf76121a2017-01-30 17:30:55 -0500340#define DRM_IOCTL_MSM_RMFB2 DRM_IOW((DRM_COMMAND_BASE + \
341 DRM_MSM_RMFB2), unsigned int)
Rob Clark7198e6b2013-07-19 12:59:32 -0400342
Emil Velikova62424e2016-04-07 19:03:46 +0100343#if defined(__cplusplus)
344}
345#endif
346
Rob Clark7198e6b2013-07-19 12:59:32 -0400347#endif /* __MSM_DRM_H__ */