xref: /linux/include/uapi/drm/panfrost_drm.h (revision 52e6b198833411564e0b9ce6e96bbd3d72f961e7)
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 #define DRM_PANFROST_SET_LABEL_BO		0x09
25 #define DRM_PANFROST_JM_CTX_CREATE		0x0a
26 #define DRM_PANFROST_JM_CTX_DESTROY		0x0b
27 
28 #define DRM_IOCTL_PANFROST_SUBMIT		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit)
29 #define DRM_IOCTL_PANFROST_WAIT_BO		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo)
30 #define DRM_IOCTL_PANFROST_CREATE_BO		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_CREATE_BO, struct drm_panfrost_create_bo)
31 #define DRM_IOCTL_PANFROST_MMAP_BO		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MMAP_BO, struct drm_panfrost_mmap_bo)
32 #define DRM_IOCTL_PANFROST_GET_PARAM		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_PARAM, struct drm_panfrost_get_param)
33 #define DRM_IOCTL_PANFROST_GET_BO_OFFSET	DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_BO_OFFSET, struct drm_panfrost_get_bo_offset)
34 #define DRM_IOCTL_PANFROST_MADVISE		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MADVISE, struct drm_panfrost_madvise)
35 #define DRM_IOCTL_PANFROST_SET_LABEL_BO		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_SET_LABEL_BO, struct drm_panfrost_set_label_bo)
36 #define DRM_IOCTL_PANFROST_JM_CTX_CREATE	DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_JM_CTX_CREATE, struct drm_panfrost_jm_ctx_create)
37 #define DRM_IOCTL_PANFROST_JM_CTX_DESTROY	DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_JM_CTX_DESTROY, struct drm_panfrost_jm_ctx_destroy)
38 
39 /*
40  * Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module
41  * param is set to true.
42  * All these ioctl(s) are subject to deprecation, so please don't rely on
43  * them for anything but debugging purpose.
44  */
45 #define DRM_IOCTL_PANFROST_PERFCNT_ENABLE	DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable)
46 #define DRM_IOCTL_PANFROST_PERFCNT_DUMP		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)
47 
48 #define PANFROST_JD_REQ_FS (1 << 0)
49 #define PANFROST_JD_REQ_CYCLE_COUNT (1 << 1)
50 /**
51  * struct drm_panfrost_submit - ioctl argument for submitting commands to the 3D
52  * engine.
53  *
54  * This asks the kernel to have the GPU execute a render command list.
55  */
56 struct drm_panfrost_submit {
57 
58 	/** Address to GPU mapping of job descriptor */
59 	__u64 jc;
60 
61 	/** An optional array of sync objects to wait on before starting this job. */
62 	__u64 in_syncs;
63 
64 	/** Number of sync objects to wait on before starting this job. */
65 	__u32 in_sync_count;
66 
67 	/** An optional sync object to place the completion fence in. */
68 	__u32 out_sync;
69 
70 	/** Pointer to a u32 array of the BOs that are referenced by the job. */
71 	__u64 bo_handles;
72 
73 	/** Number of BO handles passed in (size is that times 4). */
74 	__u32 bo_handle_count;
75 
76 	/** A combination of PANFROST_JD_REQ_* */
77 	__u32 requirements;
78 
79 	/** JM context handle. Zero if you want to use the default context. */
80 	__u32 jm_ctx_handle;
81 
82 	/** Padding field. MBZ. */
83 	__u32 pad;
84 };
85 
86 /**
87  * struct drm_panfrost_wait_bo - ioctl argument for waiting for
88  * completion of the last DRM_PANFROST_SUBMIT on a BO.
89  *
90  * This is useful for cases where multiple processes might be
91  * rendering to a BO and you want to wait for all rendering to be
92  * completed.
93  */
94 struct drm_panfrost_wait_bo {
95 	__u32 handle;
96 	__u32 pad;
97 	__s64 timeout_ns;	/* absolute */
98 };
99 
100 /* Valid flags to pass to drm_panfrost_create_bo */
101 #define PANFROST_BO_NOEXEC	1
102 #define PANFROST_BO_HEAP	2
103 
104 /**
105  * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.
106  *
107  * The flags argument is a bit mask of PANFROST_BO_* flags.
108  */
109 struct drm_panfrost_create_bo {
110 	__u32 size;
111 	__u32 flags;
112 	/** Returned GEM handle for the BO. */
113 	__u32 handle;
114 	/* Pad, must be zero-filled. */
115 	__u32 pad;
116 	/**
117 	 * Returned offset for the BO in the GPU address space.  This offset
118 	 * is private to the DRM fd and is valid for the lifetime of the GEM
119 	 * handle.
120 	 *
121 	 * This offset value will always be nonzero, since various HW
122 	 * units treat 0 specially.
123 	 */
124 	__u64 offset;
125 };
126 
127 /**
128  * struct drm_panfrost_mmap_bo - ioctl argument for mapping Panfrost BOs.
129  *
130  * This doesn't actually perform an mmap.  Instead, it returns the
131  * offset you need to use in an mmap on the DRM device node.  This
132  * means that tools like valgrind end up knowing about the mapped
133  * memory.
134  *
135  * There are currently no values for the flags argument, but it may be
136  * used in a future extension.
137  */
138 struct drm_panfrost_mmap_bo {
139 	/** Handle for the object being mapped. */
140 	__u32 handle;
141 	__u32 flags;
142 	/** offset into the drm node to use for subsequent mmap call. */
143 	__u64 offset;
144 };
145 
146 enum drm_panfrost_param {
147 	DRM_PANFROST_PARAM_GPU_PROD_ID,
148 	DRM_PANFROST_PARAM_GPU_REVISION,
149 	DRM_PANFROST_PARAM_SHADER_PRESENT,
150 	DRM_PANFROST_PARAM_TILER_PRESENT,
151 	DRM_PANFROST_PARAM_L2_PRESENT,
152 	DRM_PANFROST_PARAM_STACK_PRESENT,
153 	DRM_PANFROST_PARAM_AS_PRESENT,
154 	DRM_PANFROST_PARAM_JS_PRESENT,
155 	DRM_PANFROST_PARAM_L2_FEATURES,
156 	DRM_PANFROST_PARAM_CORE_FEATURES,
157 	DRM_PANFROST_PARAM_TILER_FEATURES,
158 	DRM_PANFROST_PARAM_MEM_FEATURES,
159 	DRM_PANFROST_PARAM_MMU_FEATURES,
160 	DRM_PANFROST_PARAM_THREAD_FEATURES,
161 	DRM_PANFROST_PARAM_MAX_THREADS,
162 	DRM_PANFROST_PARAM_THREAD_MAX_WORKGROUP_SZ,
163 	DRM_PANFROST_PARAM_THREAD_MAX_BARRIER_SZ,
164 	DRM_PANFROST_PARAM_COHERENCY_FEATURES,
165 	DRM_PANFROST_PARAM_TEXTURE_FEATURES0,
166 	DRM_PANFROST_PARAM_TEXTURE_FEATURES1,
167 	DRM_PANFROST_PARAM_TEXTURE_FEATURES2,
168 	DRM_PANFROST_PARAM_TEXTURE_FEATURES3,
169 	DRM_PANFROST_PARAM_JS_FEATURES0,
170 	DRM_PANFROST_PARAM_JS_FEATURES1,
171 	DRM_PANFROST_PARAM_JS_FEATURES2,
172 	DRM_PANFROST_PARAM_JS_FEATURES3,
173 	DRM_PANFROST_PARAM_JS_FEATURES4,
174 	DRM_PANFROST_PARAM_JS_FEATURES5,
175 	DRM_PANFROST_PARAM_JS_FEATURES6,
176 	DRM_PANFROST_PARAM_JS_FEATURES7,
177 	DRM_PANFROST_PARAM_JS_FEATURES8,
178 	DRM_PANFROST_PARAM_JS_FEATURES9,
179 	DRM_PANFROST_PARAM_JS_FEATURES10,
180 	DRM_PANFROST_PARAM_JS_FEATURES11,
181 	DRM_PANFROST_PARAM_JS_FEATURES12,
182 	DRM_PANFROST_PARAM_JS_FEATURES13,
183 	DRM_PANFROST_PARAM_JS_FEATURES14,
184 	DRM_PANFROST_PARAM_JS_FEATURES15,
185 	DRM_PANFROST_PARAM_NR_CORE_GROUPS,
186 	DRM_PANFROST_PARAM_THREAD_TLS_ALLOC,
187 	DRM_PANFROST_PARAM_AFBC_FEATURES,
188 	DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP,
189 	DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP_FREQUENCY,
190 	DRM_PANFROST_PARAM_ALLOWED_JM_CTX_PRIORITIES,
191 };
192 
193 struct drm_panfrost_get_param {
194 	__u32 param;
195 	__u32 pad;
196 	__u64 value;
197 };
198 
199 /**
200  * Returns the offset for the BO in the GPU address space for this DRM fd.
201  * This is the same value returned by drm_panfrost_create_bo, if that was called
202  * from this DRM fd.
203  */
204 struct drm_panfrost_get_bo_offset {
205 	__u32 handle;
206 	__u32 pad;
207 	__u64 offset;
208 };
209 
210 struct drm_panfrost_perfcnt_enable {
211 	__u32 enable;
212 	/*
213 	 * On bifrost we have 2 sets of counters, this parameter defines the
214 	 * one to track.
215 	 */
216 	__u32 counterset;
217 };
218 
219 struct drm_panfrost_perfcnt_dump {
220 	__u64 buf_ptr;
221 };
222 
223 /* madvise provides a way to tell the kernel in case a buffers contents
224  * can be discarded under memory pressure, which is useful for userspace
225  * bo cache where we want to optimistically hold on to buffer allocate
226  * and potential mmap, but allow the pages to be discarded under memory
227  * pressure.
228  *
229  * Typical usage would involve madvise(DONTNEED) when buffer enters BO
230  * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
231  * In the WILLNEED case, 'retained' indicates to userspace whether the
232  * backing pages still exist.
233  */
234 #define PANFROST_MADV_WILLNEED 0	/* backing pages are needed, status returned in 'retained' */
235 #define PANFROST_MADV_DONTNEED 1	/* backing pages not needed */
236 
237 struct drm_panfrost_madvise {
238 	__u32 handle;         /* in, GEM handle */
239 	__u32 madv;           /* in, PANFROST_MADV_x */
240 	__u32 retained;       /* out, whether backing store still exists */
241 };
242 
243 /**
244  * struct drm_panfrost_set_label_bo - ioctl argument for labelling Panfrost BOs.
245  */
246 struct drm_panfrost_set_label_bo {
247 	/** @handle: Handle of the buffer object to label. */
248 	__u32 handle;
249 
250 	/**  @pad: MBZ. */
251 	__u32 pad;
252 
253 	/**
254 	 * @label: User pointer to a NUL-terminated string
255 	 *
256 	 * Length cannot be greater than 4096.
257 	 * NULL is permitted and means clear the label.
258 	 */
259 	__u64 label;
260 };
261 
262 /* Definitions for coredump decoding in user space */
263 #define PANFROSTDUMP_MAJOR 1
264 #define PANFROSTDUMP_MINOR 0
265 
266 #define PANFROSTDUMP_MAGIC 0x464E4150 /* PANF */
267 
268 #define PANFROSTDUMP_BUF_REG 0
269 #define PANFROSTDUMP_BUF_BOMAP (PANFROSTDUMP_BUF_REG + 1)
270 #define PANFROSTDUMP_BUF_BO (PANFROSTDUMP_BUF_BOMAP + 1)
271 #define PANFROSTDUMP_BUF_TRAILER (PANFROSTDUMP_BUF_BO + 1)
272 
273 /*
274  * This structure is the native endianness of the dumping machine, tools can
275  * detect the endianness by looking at the value in 'magic'.
276  */
277 struct panfrost_dump_object_header {
278 	__u32 magic;
279 	__u32 type;
280 	__u32 file_size;
281 	__u32 file_offset;
282 
283 	union {
284 		struct {
285 			__u64 jc;
286 			__u32 gpu_id;
287 			__u32 major;
288 			__u32 minor;
289 			__u64 nbos;
290 		} reghdr;
291 
292 		struct {
293 			__u32 valid;
294 			__u64 iova;
295 			__u32 data[2];
296 		} bomap;
297 
298 		/*
299 		 * Force same size in case we want to expand the header
300 		 * with new fields and also keep it 512-byte aligned
301 		 */
302 
303 		__u32 sizer[496];
304 	};
305 };
306 
307 /* Registers object, an array of these */
308 struct panfrost_dump_registers {
309 	__u32 reg;
310 	__u32 value;
311 };
312 
313 enum drm_panfrost_jm_ctx_priority {
314 	/**
315 	 * @PANFROST_JM_CTX_PRIORITY_LOW: Low priority context.
316 	 */
317 	PANFROST_JM_CTX_PRIORITY_LOW = 0,
318 
319 	/**
320 	 * @PANFROST_JM_CTX_PRIORITY_MEDIUM: Medium priority context.
321 	 */
322 	PANFROST_JM_CTX_PRIORITY_MEDIUM,
323 
324 	/**
325 	 * @PANFROST_JM_CTX_PRIORITY_HIGH: High priority context.
326 	 *
327 	 * Requires CAP_SYS_NICE or DRM_MASTER.
328 	 */
329 	PANFROST_JM_CTX_PRIORITY_HIGH,
330 };
331 
332 struct drm_panfrost_jm_ctx_create {
333 	/** @handle: Handle of the created JM context */
334 	__u32 handle;
335 
336 	/** @priority: Context priority (see enum drm_panfrost_jm_ctx_priority). */
337 	__u32 priority;
338 };
339 
340 struct drm_panfrost_jm_ctx_destroy {
341 	/**
342 	 * @handle: Handle of the JM context to destroy.
343 	 *
344 	 * Must be a valid context handle returned by DRM_IOCTL_PANTHOR_JM_CTX_CREATE.
345 	 */
346 	__u32 handle;
347 
348 	/** @pad: Padding field, MBZ. */
349 	__u32 pad;
350 };
351 
352 #if defined(__cplusplus)
353 }
354 #endif
355 
356 #endif /* _PANFROST_DRM_H_ */
357