1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2014-2018 Broadcom
4 * Copyright © 2019 Collabora ltd.
6 #ifndef _PANFROST_DRM_H_
7 #define _PANFROST_DRM_H_
11 #if defined(__cplusplus)
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
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)
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.
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)
42 #define PANFROST_JD_REQ_FS (1 << 0)
44 * struct drm_panfrost_submit - ioctl argument for submitting commands to the 3D
47 * This asks the kernel to have the GPU execute a render command list.
49 struct drm_panfrost_submit {
51 /** Address to GPU mapping of job descriptor */
54 /** An optional array of sync objects to wait on before starting this job. */
57 /** Number of sync objects to wait on before starting this job. */
60 /** An optional sync object to place the completion fence in. */
63 /** Pointer to a u32 array of the BOs that are referenced by the job. */
66 /** Number of BO handles passed in (size is that times 4). */
67 __u32 bo_handle_count;
69 /** A combination of PANFROST_JD_REQ_* */
74 * struct drm_panfrost_wait_bo - ioctl argument for waiting for
75 * completion of the last DRM_PANFROST_SUBMIT on a BO.
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
81 struct drm_panfrost_wait_bo {
84 __s64 timeout_ns; /* absolute */
87 /* Valid flags to pass to drm_panfrost_create_bo */
88 #define PANFROST_BO_NOEXEC 1
89 #define PANFROST_BO_HEAP 2
92 * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.
94 * The flags argument is a bit mask of PANFROST_BO_* flags.
96 struct drm_panfrost_create_bo {
99 /** Returned GEM handle for the BO. */
101 /* Pad, must be zero-filled. */
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
108 * This offset value will always be nonzero, since various HW
109 * units treat 0 specially.
115 * struct drm_panfrost_mmap_bo - ioctl argument for mapping Panfrost BOs.
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
122 * There are currently no values for the flags argument, but it may be
123 * used in a future extension.
125 struct drm_panfrost_mmap_bo {
126 /** Handle for the object being mapped. */
129 /** offset into the drm node to use for subsequent mmap call. */
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,
177 struct drm_panfrost_get_param {
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
188 struct drm_panfrost_get_bo_offset {
194 struct drm_panfrost_perfcnt_enable {
197 * On bifrost we have 2 sets of counters, this parameter defines the
203 struct drm_panfrost_perfcnt_dump {
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
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.
218 #define PANFROST_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */
219 #define PANFROST_MADV_DONTNEED 1 /* backing pages not needed */
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 */
227 /* Definitions for coredump decoding in user space */
228 #define PANFROSTDUMP_MAJOR 1
229 #define PANFROSTDUMP_MINOR 0
231 #define PANFROSTDUMP_MAGIC 0x464E4150 /* PANF */
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)
239 * This structure is the native endianness of the dumping machine, tools can
240 * detect the endianness by looking at the value in 'magic'.
242 struct panfrost_dump_object_header {
264 * Force same size in case we want to expand the header
265 * with new fields and also keep it 512-byte aligned
272 /* Registers object, an array of these */
273 struct panfrost_dump_registers {
278 #if defined(__cplusplus)
282 #endif /* _PANFROST_DRM_H_ */