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