etnaviv_drm.h revision 00a23bda
1037b3c26Smrg/*
2037b3c26Smrg * Copyright (C) 2015 Etnaviv Project
3037b3c26Smrg *
4037b3c26Smrg * This program is free software; you can redistribute it and/or modify it
5037b3c26Smrg * under the terms of the GNU General Public License version 2 as published by
6037b3c26Smrg * the Free Software Foundation.
7037b3c26Smrg *
8037b3c26Smrg * This program is distributed in the hope that it will be useful, but WITHOUT
9037b3c26Smrg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10037b3c26Smrg * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11037b3c26Smrg * more details.
12037b3c26Smrg *
13037b3c26Smrg * You should have received a copy of the GNU General Public License along with
14037b3c26Smrg * this program.  If not, see <http://www.gnu.org/licenses/>.
15037b3c26Smrg */
16037b3c26Smrg
17037b3c26Smrg#ifndef __ETNAVIV_DRM_H__
18037b3c26Smrg#define __ETNAVIV_DRM_H__
19037b3c26Smrg
20037b3c26Smrg#include "drm.h"
21037b3c26Smrg
22037b3c26Smrg#if defined(__cplusplus)
23037b3c26Smrgextern "C" {
24037b3c26Smrg#endif
25037b3c26Smrg
26037b3c26Smrg/* Please note that modifications to all structs defined here are
27037b3c26Smrg * subject to backwards-compatibility constraints:
28037b3c26Smrg *  1) Do not use pointers, use __u64 instead for 32 bit / 64 bit
29037b3c26Smrg *     user/kernel compatibility
30037b3c26Smrg *  2) Keep fields aligned to their size
31037b3c26Smrg *  3) Because of how drm_ioctl() works, we can add new fields at
32037b3c26Smrg *     the end of an ioctl if some care is taken: drm_ioctl() will
33037b3c26Smrg *     zero out the new fields at the tail of the ioctl, so a zero
34037b3c26Smrg *     value should have a backwards compatible meaning.  And for
35037b3c26Smrg *     output params, userspace won't see the newly added output
36037b3c26Smrg *     fields.. so that has to be somehow ok.
37037b3c26Smrg */
38037b3c26Smrg
39037b3c26Smrg/* timeouts are specified in clock-monotonic absolute times (to simplify
40037b3c26Smrg * restarting interrupted ioctls).  The following struct is logically the
41037b3c26Smrg * same as 'struct timespec' but 32/64b ABI safe.
42037b3c26Smrg */
43037b3c26Smrgstruct drm_etnaviv_timespec {
44037b3c26Smrg	__s64 tv_sec;          /* seconds */
45037b3c26Smrg	__s64 tv_nsec;         /* nanoseconds */
46037b3c26Smrg};
47037b3c26Smrg
48037b3c26Smrg#define ETNAVIV_PARAM_GPU_MODEL                     0x01
49037b3c26Smrg#define ETNAVIV_PARAM_GPU_REVISION                  0x02
50037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_0                0x03
51037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_1                0x04
52037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_2                0x05
53037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_3                0x06
54037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_4                0x07
55037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_5                0x08
56037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_6                0x09
57037b3c26Smrg
58037b3c26Smrg#define ETNAVIV_PARAM_GPU_STREAM_COUNT              0x10
59037b3c26Smrg#define ETNAVIV_PARAM_GPU_REGISTER_MAX              0x11
60037b3c26Smrg#define ETNAVIV_PARAM_GPU_THREAD_COUNT              0x12
61037b3c26Smrg#define ETNAVIV_PARAM_GPU_VERTEX_CACHE_SIZE         0x13
62037b3c26Smrg#define ETNAVIV_PARAM_GPU_SHADER_CORE_COUNT         0x14
63037b3c26Smrg#define ETNAVIV_PARAM_GPU_PIXEL_PIPES               0x15
64037b3c26Smrg#define ETNAVIV_PARAM_GPU_VERTEX_OUTPUT_BUFFER_SIZE 0x16
65037b3c26Smrg#define ETNAVIV_PARAM_GPU_BUFFER_SIZE               0x17
66037b3c26Smrg#define ETNAVIV_PARAM_GPU_INSTRUCTION_COUNT         0x18
67037b3c26Smrg#define ETNAVIV_PARAM_GPU_NUM_CONSTANTS             0x19
68037b3c26Smrg#define ETNAVIV_PARAM_GPU_NUM_VARYINGS              0x1a
69037b3c26Smrg
70037b3c26Smrg#define ETNA_MAX_PIPES 4
71037b3c26Smrg
72037b3c26Smrgstruct drm_etnaviv_param {
73037b3c26Smrg	__u32 pipe;           /* in */
74037b3c26Smrg	__u32 param;          /* in, ETNAVIV_PARAM_x */
75037b3c26Smrg	__u64 value;          /* out (get_param) or in (set_param) */
76037b3c26Smrg};
77037b3c26Smrg
78037b3c26Smrg/*
79037b3c26Smrg * GEM buffers:
80037b3c26Smrg */
81037b3c26Smrg
82037b3c26Smrg#define ETNA_BO_CACHE_MASK   0x000f0000
83037b3c26Smrg/* cache modes */
84037b3c26Smrg#define ETNA_BO_CACHED       0x00010000
85037b3c26Smrg#define ETNA_BO_WC           0x00020000
86037b3c26Smrg#define ETNA_BO_UNCACHED     0x00040000
87037b3c26Smrg/* map flags */
88037b3c26Smrg#define ETNA_BO_FORCE_MMU    0x00100000
89037b3c26Smrg
90037b3c26Smrgstruct drm_etnaviv_gem_new {
91037b3c26Smrg	__u64 size;           /* in */
92037b3c26Smrg	__u32 flags;          /* in, mask of ETNA_BO_x */
93037b3c26Smrg	__u32 handle;         /* out */
94037b3c26Smrg};
95037b3c26Smrg
96037b3c26Smrgstruct drm_etnaviv_gem_info {
97037b3c26Smrg	__u32 handle;         /* in */
98037b3c26Smrg	__u32 pad;
99037b3c26Smrg	__u64 offset;         /* out, offset to pass to mmap() */
100037b3c26Smrg};
101037b3c26Smrg
102037b3c26Smrg#define ETNA_PREP_READ        0x01
103037b3c26Smrg#define ETNA_PREP_WRITE       0x02
104037b3c26Smrg#define ETNA_PREP_NOSYNC      0x04
105037b3c26Smrg
106037b3c26Smrgstruct drm_etnaviv_gem_cpu_prep {
107037b3c26Smrg	__u32 handle;         /* in */
108037b3c26Smrg	__u32 op;             /* in, mask of ETNA_PREP_x */
109037b3c26Smrg	struct drm_etnaviv_timespec timeout;   /* in */
110037b3c26Smrg};
111037b3c26Smrg
112037b3c26Smrgstruct drm_etnaviv_gem_cpu_fini {
113037b3c26Smrg	__u32 handle;         /* in */
114037b3c26Smrg	__u32 flags;          /* in, placeholder for now, no defined values */
115037b3c26Smrg};
116037b3c26Smrg
117037b3c26Smrg/*
118037b3c26Smrg * Cmdstream Submission:
119037b3c26Smrg */
120037b3c26Smrg
121037b3c26Smrg/* The value written into the cmdstream is logically:
122037b3c26Smrg * relocbuf->gpuaddr + reloc_offset
123037b3c26Smrg *
124037b3c26Smrg * NOTE that reloc's must be sorted by order of increasing submit_offset,
125037b3c26Smrg * otherwise EINVAL.
126037b3c26Smrg */
127037b3c26Smrgstruct drm_etnaviv_gem_submit_reloc {
128037b3c26Smrg	__u32 submit_offset;  /* in, offset from submit_bo */
129037b3c26Smrg	__u32 reloc_idx;      /* in, index of reloc_bo buffer */
130037b3c26Smrg	__u64 reloc_offset;   /* in, offset from start of reloc_bo */
131037b3c26Smrg	__u32 flags;          /* in, placeholder for now, no defined values */
132037b3c26Smrg};
133037b3c26Smrg
134037b3c26Smrg/* Each buffer referenced elsewhere in the cmdstream submit (ie. the
135037b3c26Smrg * cmdstream buffer(s) themselves or reloc entries) has one (and only
136037b3c26Smrg * one) entry in the submit->bos[] table.
137037b3c26Smrg *
138037b3c26Smrg * As a optimization, the current buffer (gpu virtual address) can be
139037b3c26Smrg * passed back through the 'presumed' field.  If on a subsequent reloc,
140037b3c26Smrg * userspace passes back a 'presumed' address that is still valid,
141037b3c26Smrg * then patching the cmdstream for this entry is skipped.  This can
142037b3c26Smrg * avoid kernel needing to map/access the cmdstream bo in the common
143037b3c26Smrg * case.
144037b3c26Smrg */
145037b3c26Smrg#define ETNA_SUBMIT_BO_READ             0x0001
146037b3c26Smrg#define ETNA_SUBMIT_BO_WRITE            0x0002
147037b3c26Smrgstruct drm_etnaviv_gem_submit_bo {
148037b3c26Smrg	__u32 flags;          /* in, mask of ETNA_SUBMIT_BO_x */
149037b3c26Smrg	__u32 handle;         /* in, GEM handle */
150037b3c26Smrg	__u64 presumed;       /* in/out, presumed buffer address */
151037b3c26Smrg};
152037b3c26Smrg
15300a23bdaSmrg/* performance monitor request (pmr) */
15400a23bdaSmrg#define ETNA_PM_PROCESS_PRE             0x0001
15500a23bdaSmrg#define ETNA_PM_PROCESS_POST            0x0002
15600a23bdaSmrgstruct drm_etnaviv_gem_submit_pmr {
15700a23bdaSmrg	__u32 flags;          /* in, when to process request (ETNA_PM_PROCESS_x) */
15800a23bdaSmrg	__u8  domain;         /* in, pm domain */
15900a23bdaSmrg	__u8  pad;
16000a23bdaSmrg	__u16 signal;         /* in, pm signal */
16100a23bdaSmrg	__u32 sequence;       /* in, sequence number */
16200a23bdaSmrg	__u32 read_offset;    /* in, offset from read_bo */
16300a23bdaSmrg	__u32 read_idx;       /* in, index of read_bo buffer */
16400a23bdaSmrg};
16500a23bdaSmrg
166037b3c26Smrg/* Each cmdstream submit consists of a table of buffers involved, and
167037b3c26Smrg * one or more cmdstream buffers.  This allows for conditional execution
168037b3c26Smrg * (context-restore), and IB buffers needed for per tile/bin draw cmds.
169037b3c26Smrg */
170d8807b2fSmrg#define ETNA_SUBMIT_NO_IMPLICIT         0x0001
171d8807b2fSmrg#define ETNA_SUBMIT_FENCE_FD_IN         0x0002
172d8807b2fSmrg#define ETNA_SUBMIT_FENCE_FD_OUT        0x0004
173d8807b2fSmrg#define ETNA_SUBMIT_FLAGS		(ETNA_SUBMIT_NO_IMPLICIT | \
174d8807b2fSmrg					 ETNA_SUBMIT_FENCE_FD_IN | \
175d8807b2fSmrg					 ETNA_SUBMIT_FENCE_FD_OUT)
176037b3c26Smrg#define ETNA_PIPE_3D      0x00
177037b3c26Smrg#define ETNA_PIPE_2D      0x01
178037b3c26Smrg#define ETNA_PIPE_VG      0x02
179037b3c26Smrgstruct drm_etnaviv_gem_submit {
180037b3c26Smrg	__u32 fence;          /* out */
181037b3c26Smrg	__u32 pipe;           /* in */
182037b3c26Smrg	__u32 exec_state;     /* in, initial execution state (ETNA_PIPE_x) */
183037b3c26Smrg	__u32 nr_bos;         /* in, number of submit_bo's */
184037b3c26Smrg	__u32 nr_relocs;      /* in, number of submit_reloc's */
185037b3c26Smrg	__u32 stream_size;    /* in, cmdstream size */
186037b3c26Smrg	__u64 bos;            /* in, ptr to array of submit_bo's */
187037b3c26Smrg	__u64 relocs;         /* in, ptr to array of submit_reloc's */
188037b3c26Smrg	__u64 stream;         /* in, ptr to cmdstream */
189d8807b2fSmrg	__u32 flags;          /* in, mask of ETNA_SUBMIT_x */
190d8807b2fSmrg	__s32 fence_fd;       /* in/out, fence fd (see ETNA_SUBMIT_FENCE_FD_x) */
19100a23bdaSmrg	__u64 pmrs;           /* in, ptr to array of submit_pmr's */
19200a23bdaSmrg	__u32 nr_pmrs;        /* in, number of submit_pmr's */
19300a23bdaSmrg	__u32 pad;
194037b3c26Smrg};
195037b3c26Smrg
196037b3c26Smrg/* The normal way to synchronize with the GPU is just to CPU_PREP on
197037b3c26Smrg * a buffer if you need to access it from the CPU (other cmdstream
198037b3c26Smrg * submission from same or other contexts, PAGE_FLIP ioctl, etc, all
199037b3c26Smrg * handle the required synchronization under the hood).  This ioctl
200037b3c26Smrg * mainly just exists as a way to implement the gallium pipe_fence
201037b3c26Smrg * APIs without requiring a dummy bo to synchronize on.
202037b3c26Smrg */
203037b3c26Smrg#define ETNA_WAIT_NONBLOCK      0x01
204037b3c26Smrgstruct drm_etnaviv_wait_fence {
205037b3c26Smrg	__u32 pipe;           /* in */
206037b3c26Smrg	__u32 fence;          /* in */
207037b3c26Smrg	__u32 flags;          /* in, mask of ETNA_WAIT_x */
208037b3c26Smrg	__u32 pad;
209037b3c26Smrg	struct drm_etnaviv_timespec timeout;   /* in */
210037b3c26Smrg};
211037b3c26Smrg
212037b3c26Smrg#define ETNA_USERPTR_READ	0x01
213037b3c26Smrg#define ETNA_USERPTR_WRITE	0x02
214037b3c26Smrgstruct drm_etnaviv_gem_userptr {
215037b3c26Smrg	__u64 user_ptr;	/* in, page aligned user pointer */
216037b3c26Smrg	__u64 user_size;	/* in, page aligned user size */
217037b3c26Smrg	__u32 flags;		/* in, flags */
218037b3c26Smrg	__u32 handle;	/* out, non-zero handle */
219037b3c26Smrg};
220037b3c26Smrg
221037b3c26Smrgstruct drm_etnaviv_gem_wait {
222037b3c26Smrg	__u32 pipe;				/* in */
223037b3c26Smrg	__u32 handle;				/* in, bo to be waited for */
224037b3c26Smrg	__u32 flags;				/* in, mask of ETNA_WAIT_x  */
225037b3c26Smrg	__u32 pad;
226037b3c26Smrg	struct drm_etnaviv_timespec timeout;	/* in */
227037b3c26Smrg};
228037b3c26Smrg
22900a23bdaSmrg/*
23000a23bdaSmrg * Performance Monitor (PM):
23100a23bdaSmrg */
23200a23bdaSmrg
23300a23bdaSmrgstruct drm_etnaviv_pm_domain {
23400a23bdaSmrg	__u32 pipe;       /* in */
23500a23bdaSmrg	__u8  iter;       /* in/out, select pm domain at index iter */
23600a23bdaSmrg	__u8  id;         /* out, id of domain */
23700a23bdaSmrg	__u16 nr_signals; /* out, how many signals does this domain provide */
23800a23bdaSmrg	char  name[64];   /* out, name of domain */
23900a23bdaSmrg};
24000a23bdaSmrg
24100a23bdaSmrgstruct drm_etnaviv_pm_signal {
24200a23bdaSmrg	__u32 pipe;       /* in */
24300a23bdaSmrg	__u8  domain;     /* in, pm domain index */
24400a23bdaSmrg	__u8  pad;
24500a23bdaSmrg	__u16 iter;       /* in/out, select pm source at index iter */
24600a23bdaSmrg	__u16 id;         /* out, id of signal */
24700a23bdaSmrg	char  name[64];   /* out, name of domain */
24800a23bdaSmrg};
24900a23bdaSmrg
250037b3c26Smrg#define DRM_ETNAVIV_GET_PARAM          0x00
251037b3c26Smrg/* placeholder:
252037b3c26Smrg#define DRM_ETNAVIV_SET_PARAM          0x01
253037b3c26Smrg */
254037b3c26Smrg#define DRM_ETNAVIV_GEM_NEW            0x02
255037b3c26Smrg#define DRM_ETNAVIV_GEM_INFO           0x03
256037b3c26Smrg#define DRM_ETNAVIV_GEM_CPU_PREP       0x04
257037b3c26Smrg#define DRM_ETNAVIV_GEM_CPU_FINI       0x05
258037b3c26Smrg#define DRM_ETNAVIV_GEM_SUBMIT         0x06
259037b3c26Smrg#define DRM_ETNAVIV_WAIT_FENCE         0x07
260037b3c26Smrg#define DRM_ETNAVIV_GEM_USERPTR        0x08
261037b3c26Smrg#define DRM_ETNAVIV_GEM_WAIT           0x09
26200a23bdaSmrg#define DRM_ETNAVIV_PM_QUERY_DOM       0x0a
26300a23bdaSmrg#define DRM_ETNAVIV_PM_QUERY_SIG       0x0b
26400a23bdaSmrg#define DRM_ETNAVIV_NUM_IOCTLS         0x0c
265037b3c26Smrg
266037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GET_PARAM    DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GET_PARAM, struct drm_etnaviv_param)
267037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_NEW      DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_NEW, struct drm_etnaviv_gem_new)
268037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_INFO     DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_INFO, struct drm_etnaviv_gem_info)
269037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_CPU_PREP DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_CPU_PREP, struct drm_etnaviv_gem_cpu_prep)
270037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_CPU_FINI DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_CPU_FINI, struct drm_etnaviv_gem_cpu_fini)
271037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_SUBMIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_SUBMIT, struct drm_etnaviv_gem_submit)
272037b3c26Smrg#define DRM_IOCTL_ETNAVIV_WAIT_FENCE   DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_WAIT_FENCE, struct drm_etnaviv_wait_fence)
273037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_USERPTR  DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_USERPTR, struct drm_etnaviv_gem_userptr)
274037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_WAIT     DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_WAIT, struct drm_etnaviv_gem_wait)
27500a23bdaSmrg#define DRM_IOCTL_ETNAVIV_PM_QUERY_DOM DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_PM_QUERY_DOM, struct drm_etnaviv_pm_domain)
27600a23bdaSmrg#define DRM_IOCTL_ETNAVIV_PM_QUERY_SIG DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_PM_QUERY_SIG, struct drm_etnaviv_pm_signal)
277037b3c26Smrg
278037b3c26Smrg#if defined(__cplusplus)
279037b3c26Smrg}
280037b3c26Smrg#endif
281037b3c26Smrg
282037b3c26Smrg#endif /* __ETNAVIV_DRM_H__ */
283