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