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