xref: /linux/include/uapi/drm/panfrost_drm.h (revision 8e07e0e3964ca4e23ce7b68e2096fe660a888942)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2014-2018 Broadcom
4  * Copyright © 2019 Collabora ltd.
5  */
6 #ifndef _PANFROST_DRM_H_
7 #define _PANFROST_DRM_H_
8 
9 #include "drm.h"
10 
11 #if defined(__cplusplus)
12 extern "C" {
13 #endif
14 
15 #define DRM_PANFROST_SUBMIT			0x00
16 #define DRM_PANFROST_WAIT_BO			0x01
17 #define DRM_PANFROST_CREATE_BO			0x02
18 #define DRM_PANFROST_MMAP_BO			0x03
19 #define DRM_PANFROST_GET_PARAM			0x04
20 #define DRM_PANFROST_GET_BO_OFFSET		0x05
21 #define DRM_PANFROST_PERFCNT_ENABLE		0x06
22 #define DRM_PANFROST_PERFCNT_DUMP		0x07
23 #define DRM_PANFROST_MADVISE			0x08
24 
25 #define DRM_IOCTL_PANFROST_SUBMIT		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit)
26 #define DRM_IOCTL_PANFROST_WAIT_BO		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo)
27 #define DRM_IOCTL_PANFROST_CREATE_BO		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_CREATE_BO, struct drm_panfrost_create_bo)
28 #define DRM_IOCTL_PANFROST_MMAP_BO		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MMAP_BO, struct drm_panfrost_mmap_bo)
29 #define DRM_IOCTL_PANFROST_GET_PARAM		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_PARAM, struct drm_panfrost_get_param)
30 #define DRM_IOCTL_PANFROST_GET_BO_OFFSET	DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_BO_OFFSET, struct drm_panfrost_get_bo_offset)
31 #define DRM_IOCTL_PANFROST_MADVISE		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MADVISE, struct drm_panfrost_madvise)
32 
33 /*
34  * Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module
35  * param is set to true.
36  * All these ioctl(s) are subject to deprecation, so please don't rely on
37  * them for anything but debugging purpose.
38  */
39 #define DRM_IOCTL_PANFROST_PERFCNT_ENABLE	DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable)
40 #define DRM_IOCTL_PANFROST_PERFCNT_DUMP		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)
41 
42 #define PANFROST_JD_REQ_FS (1 << 0)
43 /**
44  * struct drm_panfrost_submit - ioctl argument for submitting commands to the 3D
45  * engine.
46  *
47  * This asks the kernel to have the GPU execute a render command list.
48  */
49 struct drm_panfrost_submit {
50 
51 	/** Address to GPU mapping of job descriptor */
52 	__u64 jc;
53 
54 	/** An optional array of sync objects to wait on before starting this job. */
55 	__u64 in_syncs;
56 
57 	/** Number of sync objects to wait on before starting this job. */
58 	__u32 in_sync_count;
59 
60 	/** An optional sync object to place the completion fence in. */
61 	__u32 out_sync;
62 
63 	/** Pointer to a u32 array of the BOs that are referenced by the job. */
64 	__u64 bo_handles;
65 
66 	/** Number of BO handles passed in (size is that times 4). */
67 	__u32 bo_handle_count;
68 
69 	/** A combination of PANFROST_JD_REQ_* */
70 	__u32 requirements;
71 };
72 
73 /**
74  * struct drm_panfrost_wait_bo - ioctl argument for waiting for
75  * completion of the last DRM_PANFROST_SUBMIT on a BO.
76  *
77  * This is useful for cases where multiple processes might be
78  * rendering to a BO and you want to wait for all rendering to be
79  * completed.
80  */
81 struct drm_panfrost_wait_bo {
82 	__u32 handle;
83 	__u32 pad;
84 	__s64 timeout_ns;	/* absolute */
85 };
86 
87 /* Valid flags to pass to drm_panfrost_create_bo */
88 #define PANFROST_BO_NOEXEC	1
89 #define PANFROST_BO_HEAP	2
90 
91 /**
92  * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.
93  *
94  * The flags argument is a bit mask of PANFROST_BO_* flags.
95  */
96 struct drm_panfrost_create_bo {
97 	__u32 size;
98 	__u32 flags;
99 	/** Returned GEM handle for the BO. */
100 	__u32 handle;
101 	/* Pad, must be zero-filled. */
102 	__u32 pad;
103 	/**
104 	 * Returned offset for the BO in the GPU address space.  This offset
105 	 * is private to the DRM fd and is valid for the lifetime of the GEM
106 	 * handle.
107 	 *
108 	 * This offset value will always be nonzero, since various HW
109 	 * units treat 0 specially.
110 	 */
111 	__u64 offset;
112 };
113 
114 /**
115  * struct drm_panfrost_mmap_bo - ioctl argument for mapping Panfrost BOs.
116  *
117  * This doesn't actually perform an mmap.  Instead, it returns the
118  * offset you need to use in an mmap on the DRM device node.  This
119  * means that tools like valgrind end up knowing about the mapped
120  * memory.
121  *
122  * There are currently no values for the flags argument, but it may be
123  * used in a future extension.
124  */
125 struct drm_panfrost_mmap_bo {
126 	/** Handle for the object being mapped. */
127 	__u32 handle;
128 	__u32 flags;
129 	/** offset into the drm node to use for subsequent mmap call. */
130 	__u64 offset;
131 };
132 
133 enum drm_panfrost_param {
134 	DRM_PANFROST_PARAM_GPU_PROD_ID,
135 	DRM_PANFROST_PARAM_GPU_REVISION,
136 	DRM_PANFROST_PARAM_SHADER_PRESENT,
137 	DRM_PANFROST_PARAM_TILER_PRESENT,
138 	DRM_PANFROST_PARAM_L2_PRESENT,
139 	DRM_PANFROST_PARAM_STACK_PRESENT,
140 	DRM_PANFROST_PARAM_AS_PRESENT,
141 	DRM_PANFROST_PARAM_JS_PRESENT,
142 	DRM_PANFROST_PARAM_L2_FEATURES,
143 	DRM_PANFROST_PARAM_CORE_FEATURES,
144 	DRM_PANFROST_PARAM_TILER_FEATURES,
145 	DRM_PANFROST_PARAM_MEM_FEATURES,
146 	DRM_PANFROST_PARAM_MMU_FEATURES,
147 	DRM_PANFROST_PARAM_THREAD_FEATURES,
148 	DRM_PANFROST_PARAM_MAX_THREADS,
149 	DRM_PANFROST_PARAM_THREAD_MAX_WORKGROUP_SZ,
150 	DRM_PANFROST_PARAM_THREAD_MAX_BARRIER_SZ,
151 	DRM_PANFROST_PARAM_COHERENCY_FEATURES,
152 	DRM_PANFROST_PARAM_TEXTURE_FEATURES0,
153 	DRM_PANFROST_PARAM_TEXTURE_FEATURES1,
154 	DRM_PANFROST_PARAM_TEXTURE_FEATURES2,
155 	DRM_PANFROST_PARAM_TEXTURE_FEATURES3,
156 	DRM_PANFROST_PARAM_JS_FEATURES0,
157 	DRM_PANFROST_PARAM_JS_FEATURES1,
158 	DRM_PANFROST_PARAM_JS_FEATURES2,
159 	DRM_PANFROST_PARAM_JS_FEATURES3,
160 	DRM_PANFROST_PARAM_JS_FEATURES4,
161 	DRM_PANFROST_PARAM_JS_FEATURES5,
162 	DRM_PANFROST_PARAM_JS_FEATURES6,
163 	DRM_PANFROST_PARAM_JS_FEATURES7,
164 	DRM_PANFROST_PARAM_JS_FEATURES8,
165 	DRM_PANFROST_PARAM_JS_FEATURES9,
166 	DRM_PANFROST_PARAM_JS_FEATURES10,
167 	DRM_PANFROST_PARAM_JS_FEATURES11,
168 	DRM_PANFROST_PARAM_JS_FEATURES12,
169 	DRM_PANFROST_PARAM_JS_FEATURES13,
170 	DRM_PANFROST_PARAM_JS_FEATURES14,
171 	DRM_PANFROST_PARAM_JS_FEATURES15,
172 	DRM_PANFROST_PARAM_NR_CORE_GROUPS,
173 	DRM_PANFROST_PARAM_THREAD_TLS_ALLOC,
174 	DRM_PANFROST_PARAM_AFBC_FEATURES,
175 };
176 
177 struct drm_panfrost_get_param {
178 	__u32 param;
179 	__u32 pad;
180 	__u64 value;
181 };
182 
183 /**
184  * Returns the offset for the BO in the GPU address space for this DRM fd.
185  * This is the same value returned by drm_panfrost_create_bo, if that was called
186  * from this DRM fd.
187  */
188 struct drm_panfrost_get_bo_offset {
189 	__u32 handle;
190 	__u32 pad;
191 	__u64 offset;
192 };
193 
194 struct drm_panfrost_perfcnt_enable {
195 	__u32 enable;
196 	/*
197 	 * On bifrost we have 2 sets of counters, this parameter defines the
198 	 * one to track.
199 	 */
200 	__u32 counterset;
201 };
202 
203 struct drm_panfrost_perfcnt_dump {
204 	__u64 buf_ptr;
205 };
206 
207 /* madvise provides a way to tell the kernel in case a buffers contents
208  * can be discarded under memory pressure, which is useful for userspace
209  * bo cache where we want to optimistically hold on to buffer allocate
210  * and potential mmap, but allow the pages to be discarded under memory
211  * pressure.
212  *
213  * Typical usage would involve madvise(DONTNEED) when buffer enters BO
214  * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
215  * In the WILLNEED case, 'retained' indicates to userspace whether the
216  * backing pages still exist.
217  */
218 #define PANFROST_MADV_WILLNEED 0	/* backing pages are needed, status returned in 'retained' */
219 #define PANFROST_MADV_DONTNEED 1	/* backing pages not needed */
220 
221 struct drm_panfrost_madvise {
222 	__u32 handle;         /* in, GEM handle */
223 	__u32 madv;           /* in, PANFROST_MADV_x */
224 	__u32 retained;       /* out, whether backing store still exists */
225 };
226 
227 /* Definitions for coredump decoding in user space */
228 #define PANFROSTDUMP_MAJOR 1
229 #define PANFROSTDUMP_MINOR 0
230 
231 #define PANFROSTDUMP_MAGIC 0x464E4150 /* PANF */
232 
233 #define PANFROSTDUMP_BUF_REG 0
234 #define PANFROSTDUMP_BUF_BOMAP (PANFROSTDUMP_BUF_REG + 1)
235 #define PANFROSTDUMP_BUF_BO (PANFROSTDUMP_BUF_BOMAP + 1)
236 #define PANFROSTDUMP_BUF_TRAILER (PANFROSTDUMP_BUF_BO + 1)
237 
238 /*
239  * This structure is the native endianness of the dumping machine, tools can
240  * detect the endianness by looking at the value in 'magic'.
241  */
242 struct panfrost_dump_object_header {
243 	__u32 magic;
244 	__u32 type;
245 	__u32 file_size;
246 	__u32 file_offset;
247 
248 	union {
249 		struct {
250 			__u64 jc;
251 			__u32 gpu_id;
252 			__u32 major;
253 			__u32 minor;
254 			__u64 nbos;
255 		} reghdr;
256 
257 		struct {
258 			__u32 valid;
259 			__u64 iova;
260 			__u32 data[2];
261 		} bomap;
262 
263 		/*
264 		 * Force same size in case we want to expand the header
265 		 * with new fields and also keep it 512-byte aligned
266 		 */
267 
268 		__u32 sizer[496];
269 	};
270 };
271 
272 /* Registers object, an array of these */
273 struct panfrost_dump_registers {
274 	__u32 reg;
275 	__u32 value;
276 };
277 
278 #if defined(__cplusplus)
279 }
280 #endif
281 
282 #endif /* _PANFROST_DRM_H_ */
283