17cdc0497Smrg/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2037b3c26Smrg/*
3037b3c26Smrg * Copyright (C) 2015 Etnaviv Project
4037b3c26Smrg *
5037b3c26Smrg * This program is free software; you can redistribute it and/or modify it
6037b3c26Smrg * under the terms of the GNU General Public License version 2 as published by
7037b3c26Smrg * the Free Software Foundation.
8037b3c26Smrg *
9037b3c26Smrg * This program is distributed in the hope that it will be useful, but WITHOUT
10037b3c26Smrg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11037b3c26Smrg * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12037b3c26Smrg * more details.
13037b3c26Smrg *
14037b3c26Smrg * You should have received a copy of the GNU General Public License along with
15037b3c26Smrg * this program.  If not, see <http://www.gnu.org/licenses/>.
16037b3c26Smrg */
17037b3c26Smrg
18037b3c26Smrg#ifndef __ETNAVIV_DRM_H__
19037b3c26Smrg#define __ETNAVIV_DRM_H__
20037b3c26Smrg
21037b3c26Smrg#include "drm.h"
22037b3c26Smrg
23037b3c26Smrg#if defined(__cplusplus)
24037b3c26Smrgextern "C" {
25037b3c26Smrg#endif
26037b3c26Smrg
27037b3c26Smrg/* Please note that modifications to all structs defined here are
28037b3c26Smrg * subject to backwards-compatibility constraints:
29037b3c26Smrg *  1) Do not use pointers, use __u64 instead for 32 bit / 64 bit
30037b3c26Smrg *     user/kernel compatibility
31037b3c26Smrg *  2) Keep fields aligned to their size
32037b3c26Smrg *  3) Because of how drm_ioctl() works, we can add new fields at
33037b3c26Smrg *     the end of an ioctl if some care is taken: drm_ioctl() will
34037b3c26Smrg *     zero out the new fields at the tail of the ioctl, so a zero
35037b3c26Smrg *     value should have a backwards compatible meaning.  And for
36037b3c26Smrg *     output params, userspace won't see the newly added output
37037b3c26Smrg *     fields.. so that has to be somehow ok.
38037b3c26Smrg */
39037b3c26Smrg
40037b3c26Smrg/* timeouts are specified in clock-monotonic absolute times (to simplify
41037b3c26Smrg * restarting interrupted ioctls).  The following struct is logically the
42037b3c26Smrg * same as 'struct timespec' but 32/64b ABI safe.
43037b3c26Smrg */
44037b3c26Smrgstruct drm_etnaviv_timespec {
45037b3c26Smrg	__s64 tv_sec;          /* seconds */
46037b3c26Smrg	__s64 tv_nsec;         /* nanoseconds */
47037b3c26Smrg};
48037b3c26Smrg
49037b3c26Smrg#define ETNAVIV_PARAM_GPU_MODEL                     0x01
50037b3c26Smrg#define ETNAVIV_PARAM_GPU_REVISION                  0x02
51037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_0                0x03
52037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_1                0x04
53037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_2                0x05
54037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_3                0x06
55037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_4                0x07
56037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_5                0x08
57037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_6                0x09
587cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_7                0x0a
597cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_8                0x0b
607cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_9                0x0c
617cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_10               0x0d
627cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_11               0x0e
637cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_12               0x0f
64037b3c26Smrg
65037b3c26Smrg#define ETNAVIV_PARAM_GPU_STREAM_COUNT              0x10
66037b3c26Smrg#define ETNAVIV_PARAM_GPU_REGISTER_MAX              0x11
67037b3c26Smrg#define ETNAVIV_PARAM_GPU_THREAD_COUNT              0x12
68037b3c26Smrg#define ETNAVIV_PARAM_GPU_VERTEX_CACHE_SIZE         0x13
69037b3c26Smrg#define ETNAVIV_PARAM_GPU_SHADER_CORE_COUNT         0x14
70037b3c26Smrg#define ETNAVIV_PARAM_GPU_PIXEL_PIPES               0x15
71037b3c26Smrg#define ETNAVIV_PARAM_GPU_VERTEX_OUTPUT_BUFFER_SIZE 0x16
72037b3c26Smrg#define ETNAVIV_PARAM_GPU_BUFFER_SIZE               0x17
73037b3c26Smrg#define ETNAVIV_PARAM_GPU_INSTRUCTION_COUNT         0x18
74037b3c26Smrg#define ETNAVIV_PARAM_GPU_NUM_CONSTANTS             0x19
75037b3c26Smrg#define ETNAVIV_PARAM_GPU_NUM_VARYINGS              0x1a
7649ef06a4Smrg#define ETNAVIV_PARAM_SOFTPIN_START_ADDR            0x1b
7749ef06a4Smrg#define ETNAVIV_PARAM_GPU_PRODUCT_ID                0x1c
7849ef06a4Smrg#define ETNAVIV_PARAM_GPU_CUSTOMER_ID               0x1d
7949ef06a4Smrg#define ETNAVIV_PARAM_GPU_ECO_ID                    0x1e
80037b3c26Smrg
81037b3c26Smrg#define ETNA_MAX_PIPES 4
82037b3c26Smrg
83037b3c26Smrgstruct drm_etnaviv_param {
84037b3c26Smrg	__u32 pipe;           /* in */
85037b3c26Smrg	__u32 param;          /* in, ETNAVIV_PARAM_x */
86037b3c26Smrg	__u64 value;          /* out (get_param) or in (set_param) */
87037b3c26Smrg};
88037b3c26Smrg
89037b3c26Smrg/*
90037b3c26Smrg * GEM buffers:
91037b3c26Smrg */
92037b3c26Smrg
93037b3c26Smrg#define ETNA_BO_CACHE_MASK   0x000f0000
94037b3c26Smrg/* cache modes */
95037b3c26Smrg#define ETNA_BO_CACHED       0x00010000
96037b3c26Smrg#define ETNA_BO_WC           0x00020000
97037b3c26Smrg#define ETNA_BO_UNCACHED     0x00040000
98037b3c26Smrg/* map flags */
99037b3c26Smrg#define ETNA_BO_FORCE_MMU    0x00100000
100037b3c26Smrg
101037b3c26Smrgstruct drm_etnaviv_gem_new {
102037b3c26Smrg	__u64 size;           /* in */
103037b3c26Smrg	__u32 flags;          /* in, mask of ETNA_BO_x */
104037b3c26Smrg	__u32 handle;         /* out */
105037b3c26Smrg};
106037b3c26Smrg
107037b3c26Smrgstruct drm_etnaviv_gem_info {
108037b3c26Smrg	__u32 handle;         /* in */
109037b3c26Smrg	__u32 pad;
110037b3c26Smrg	__u64 offset;         /* out, offset to pass to mmap() */
111037b3c26Smrg};
112037b3c26Smrg
113037b3c26Smrg#define ETNA_PREP_READ        0x01
114037b3c26Smrg#define ETNA_PREP_WRITE       0x02
115037b3c26Smrg#define ETNA_PREP_NOSYNC      0x04
116037b3c26Smrg
117037b3c26Smrgstruct drm_etnaviv_gem_cpu_prep {
118037b3c26Smrg	__u32 handle;         /* in */
119037b3c26Smrg	__u32 op;             /* in, mask of ETNA_PREP_x */
120037b3c26Smrg	struct drm_etnaviv_timespec timeout;   /* in */
121037b3c26Smrg};
122037b3c26Smrg
123037b3c26Smrgstruct drm_etnaviv_gem_cpu_fini {
124037b3c26Smrg	__u32 handle;         /* in */
125037b3c26Smrg	__u32 flags;          /* in, placeholder for now, no defined values */
126037b3c26Smrg};
127037b3c26Smrg
128037b3c26Smrg/*
129037b3c26Smrg * Cmdstream Submission:
130037b3c26Smrg */
131037b3c26Smrg
132037b3c26Smrg/* The value written into the cmdstream is logically:
133037b3c26Smrg * relocbuf->gpuaddr + reloc_offset
134037b3c26Smrg *
135037b3c26Smrg * NOTE that reloc's must be sorted by order of increasing submit_offset,
136037b3c26Smrg * otherwise EINVAL.
137037b3c26Smrg */
138037b3c26Smrgstruct drm_etnaviv_gem_submit_reloc {
139037b3c26Smrg	__u32 submit_offset;  /* in, offset from submit_bo */
140037b3c26Smrg	__u32 reloc_idx;      /* in, index of reloc_bo buffer */
141037b3c26Smrg	__u64 reloc_offset;   /* in, offset from start of reloc_bo */
142037b3c26Smrg	__u32 flags;          /* in, placeholder for now, no defined values */
143037b3c26Smrg};
144037b3c26Smrg
145037b3c26Smrg/* Each buffer referenced elsewhere in the cmdstream submit (ie. the
146037b3c26Smrg * cmdstream buffer(s) themselves or reloc entries) has one (and only
147037b3c26Smrg * one) entry in the submit->bos[] table.
148037b3c26Smrg *
149037b3c26Smrg * As a optimization, the current buffer (gpu virtual address) can be
150037b3c26Smrg * passed back through the 'presumed' field.  If on a subsequent reloc,
151037b3c26Smrg * userspace passes back a 'presumed' address that is still valid,
152037b3c26Smrg * then patching the cmdstream for this entry is skipped.  This can
153037b3c26Smrg * avoid kernel needing to map/access the cmdstream bo in the common
154037b3c26Smrg * case.
15549ef06a4Smrg * If the submit is a softpin submit (ETNA_SUBMIT_SOFTPIN) the 'presumed'
15649ef06a4Smrg * field is interpreted as the fixed location to map the bo into the gpu
15749ef06a4Smrg * virtual address space. If the kernel is unable to map the buffer at
15849ef06a4Smrg * this location the submit will fail. This means userspace is responsible
15949ef06a4Smrg * for the whole gpu virtual address management.
160037b3c26Smrg */
161037b3c26Smrg#define ETNA_SUBMIT_BO_READ             0x0001
162037b3c26Smrg#define ETNA_SUBMIT_BO_WRITE            0x0002
163037b3c26Smrgstruct drm_etnaviv_gem_submit_bo {
164037b3c26Smrg	__u32 flags;          /* in, mask of ETNA_SUBMIT_BO_x */
165037b3c26Smrg	__u32 handle;         /* in, GEM handle */
166037b3c26Smrg	__u64 presumed;       /* in/out, presumed buffer address */
167037b3c26Smrg};
168037b3c26Smrg
16900a23bdaSmrg/* performance monitor request (pmr) */
17000a23bdaSmrg#define ETNA_PM_PROCESS_PRE             0x0001
17100a23bdaSmrg#define ETNA_PM_PROCESS_POST            0x0002
17200a23bdaSmrgstruct drm_etnaviv_gem_submit_pmr {
17300a23bdaSmrg	__u32 flags;          /* in, when to process request (ETNA_PM_PROCESS_x) */
17400a23bdaSmrg	__u8  domain;         /* in, pm domain */
17500a23bdaSmrg	__u8  pad;
17600a23bdaSmrg	__u16 signal;         /* in, pm signal */
17700a23bdaSmrg	__u32 sequence;       /* in, sequence number */
17800a23bdaSmrg	__u32 read_offset;    /* in, offset from read_bo */
17900a23bdaSmrg	__u32 read_idx;       /* in, index of read_bo buffer */
18000a23bdaSmrg};
18100a23bdaSmrg
182037b3c26Smrg/* Each cmdstream submit consists of a table of buffers involved, and
183037b3c26Smrg * one or more cmdstream buffers.  This allows for conditional execution
184037b3c26Smrg * (context-restore), and IB buffers needed for per tile/bin draw cmds.
185037b3c26Smrg */
186d8807b2fSmrg#define ETNA_SUBMIT_NO_IMPLICIT         0x0001
187d8807b2fSmrg#define ETNA_SUBMIT_FENCE_FD_IN         0x0002
188d8807b2fSmrg#define ETNA_SUBMIT_FENCE_FD_OUT        0x0004
18949ef06a4Smrg#define ETNA_SUBMIT_SOFTPIN             0x0008
190d8807b2fSmrg#define ETNA_SUBMIT_FLAGS		(ETNA_SUBMIT_NO_IMPLICIT | \
191d8807b2fSmrg					 ETNA_SUBMIT_FENCE_FD_IN | \
19249ef06a4Smrg					 ETNA_SUBMIT_FENCE_FD_OUT| \
19349ef06a4Smrg					 ETNA_SUBMIT_SOFTPIN)
194037b3c26Smrg#define ETNA_PIPE_3D      0x00
195037b3c26Smrg#define ETNA_PIPE_2D      0x01
196037b3c26Smrg#define ETNA_PIPE_VG      0x02
197037b3c26Smrgstruct drm_etnaviv_gem_submit {
198037b3c26Smrg	__u32 fence;          /* out */
199037b3c26Smrg	__u32 pipe;           /* in */
200037b3c26Smrg	__u32 exec_state;     /* in, initial execution state (ETNA_PIPE_x) */
201037b3c26Smrg	__u32 nr_bos;         /* in, number of submit_bo's */
202037b3c26Smrg	__u32 nr_relocs;      /* in, number of submit_reloc's */
203037b3c26Smrg	__u32 stream_size;    /* in, cmdstream size */
204037b3c26Smrg	__u64 bos;            /* in, ptr to array of submit_bo's */
205037b3c26Smrg	__u64 relocs;         /* in, ptr to array of submit_reloc's */
206037b3c26Smrg	__u64 stream;         /* in, ptr to cmdstream */
207d8807b2fSmrg	__u32 flags;          /* in, mask of ETNA_SUBMIT_x */
208d8807b2fSmrg	__s32 fence_fd;       /* in/out, fence fd (see ETNA_SUBMIT_FENCE_FD_x) */
20900a23bdaSmrg	__u64 pmrs;           /* in, ptr to array of submit_pmr's */
21000a23bdaSmrg	__u32 nr_pmrs;        /* in, number of submit_pmr's */
21100a23bdaSmrg	__u32 pad;
212037b3c26Smrg};
213037b3c26Smrg
214037b3c26Smrg/* The normal way to synchronize with the GPU is just to CPU_PREP on
215037b3c26Smrg * a buffer if you need to access it from the CPU (other cmdstream
216037b3c26Smrg * submission from same or other contexts, PAGE_FLIP ioctl, etc, all
217037b3c26Smrg * handle the required synchronization under the hood).  This ioctl
218037b3c26Smrg * mainly just exists as a way to implement the gallium pipe_fence
219037b3c26Smrg * APIs without requiring a dummy bo to synchronize on.
220037b3c26Smrg */
221037b3c26Smrg#define ETNA_WAIT_NONBLOCK      0x01
222037b3c26Smrgstruct drm_etnaviv_wait_fence {
223037b3c26Smrg	__u32 pipe;           /* in */
224037b3c26Smrg	__u32 fence;          /* in */
225037b3c26Smrg	__u32 flags;          /* in, mask of ETNA_WAIT_x */
226037b3c26Smrg	__u32 pad;
227037b3c26Smrg	struct drm_etnaviv_timespec timeout;   /* in */
228037b3c26Smrg};
229037b3c26Smrg
230037b3c26Smrg#define ETNA_USERPTR_READ	0x01
231037b3c26Smrg#define ETNA_USERPTR_WRITE	0x02
232037b3c26Smrgstruct drm_etnaviv_gem_userptr {
233037b3c26Smrg	__u64 user_ptr;	/* in, page aligned user pointer */
234037b3c26Smrg	__u64 user_size;	/* in, page aligned user size */
235037b3c26Smrg	__u32 flags;		/* in, flags */
236037b3c26Smrg	__u32 handle;	/* out, non-zero handle */
237037b3c26Smrg};
238037b3c26Smrg
239037b3c26Smrgstruct drm_etnaviv_gem_wait {
240037b3c26Smrg	__u32 pipe;				/* in */
241037b3c26Smrg	__u32 handle;				/* in, bo to be waited for */
242037b3c26Smrg	__u32 flags;				/* in, mask of ETNA_WAIT_x  */
243037b3c26Smrg	__u32 pad;
244037b3c26Smrg	struct drm_etnaviv_timespec timeout;	/* in */
245037b3c26Smrg};
246037b3c26Smrg
24700a23bdaSmrg/*
24800a23bdaSmrg * Performance Monitor (PM):
24900a23bdaSmrg */
25000a23bdaSmrg
25100a23bdaSmrgstruct drm_etnaviv_pm_domain {
25200a23bdaSmrg	__u32 pipe;       /* in */
25300a23bdaSmrg	__u8  iter;       /* in/out, select pm domain at index iter */
25400a23bdaSmrg	__u8  id;         /* out, id of domain */
25500a23bdaSmrg	__u16 nr_signals; /* out, how many signals does this domain provide */
25600a23bdaSmrg	char  name[64];   /* out, name of domain */
25700a23bdaSmrg};
25800a23bdaSmrg
25900a23bdaSmrgstruct drm_etnaviv_pm_signal {
26000a23bdaSmrg	__u32 pipe;       /* in */
26100a23bdaSmrg	__u8  domain;     /* in, pm domain index */
26200a23bdaSmrg	__u8  pad;
26300a23bdaSmrg	__u16 iter;       /* in/out, select pm source at index iter */
26400a23bdaSmrg	__u16 id;         /* out, id of signal */
26500a23bdaSmrg	char  name[64];   /* out, name of domain */
26600a23bdaSmrg};
26700a23bdaSmrg
268037b3c26Smrg#define DRM_ETNAVIV_GET_PARAM          0x00
269037b3c26Smrg/* placeholder:
270037b3c26Smrg#define DRM_ETNAVIV_SET_PARAM          0x01
271037b3c26Smrg */
272037b3c26Smrg#define DRM_ETNAVIV_GEM_NEW            0x02
273037b3c26Smrg#define DRM_ETNAVIV_GEM_INFO           0x03
274037b3c26Smrg#define DRM_ETNAVIV_GEM_CPU_PREP       0x04
275037b3c26Smrg#define DRM_ETNAVIV_GEM_CPU_FINI       0x05
276037b3c26Smrg#define DRM_ETNAVIV_GEM_SUBMIT         0x06
277037b3c26Smrg#define DRM_ETNAVIV_WAIT_FENCE         0x07
278037b3c26Smrg#define DRM_ETNAVIV_GEM_USERPTR        0x08
279037b3c26Smrg#define DRM_ETNAVIV_GEM_WAIT           0x09
28000a23bdaSmrg#define DRM_ETNAVIV_PM_QUERY_DOM       0x0a
28100a23bdaSmrg#define DRM_ETNAVIV_PM_QUERY_SIG       0x0b
28200a23bdaSmrg#define DRM_ETNAVIV_NUM_IOCTLS         0x0c
283037b3c26Smrg
284037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GET_PARAM    DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GET_PARAM, struct drm_etnaviv_param)
285037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_NEW      DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_NEW, struct drm_etnaviv_gem_new)
286037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_INFO     DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_INFO, struct drm_etnaviv_gem_info)
287037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_CPU_PREP DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_CPU_PREP, struct drm_etnaviv_gem_cpu_prep)
288037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_CPU_FINI DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_CPU_FINI, struct drm_etnaviv_gem_cpu_fini)
289037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_SUBMIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_SUBMIT, struct drm_etnaviv_gem_submit)
290037b3c26Smrg#define DRM_IOCTL_ETNAVIV_WAIT_FENCE   DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_WAIT_FENCE, struct drm_etnaviv_wait_fence)
291037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_USERPTR  DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_USERPTR, struct drm_etnaviv_gem_userptr)
292037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_WAIT     DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_WAIT, struct drm_etnaviv_gem_wait)
29300a23bdaSmrg#define DRM_IOCTL_ETNAVIV_PM_QUERY_DOM DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_PM_QUERY_DOM, struct drm_etnaviv_pm_domain)
29400a23bdaSmrg#define DRM_IOCTL_ETNAVIV_PM_QUERY_SIG DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_PM_QUERY_SIG, struct drm_etnaviv_pm_signal)
295037b3c26Smrg
296037b3c26Smrg#if defined(__cplusplus)
297037b3c26Smrg}
298037b3c26Smrg#endif
299037b3c26Smrg
300037b3c26Smrg#endif /* __ETNAVIV_DRM_H__ */
301