1 1.1 riastrad /* $NetBSD: v3d_drm.h,v 1.2 2021/12/18 23:45:46 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2014-2018 Broadcom 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice (including the next 14 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 15 1.1 riastrad * Software. 16 1.1 riastrad * 17 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 1.1 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 1.1 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 1.1 riastrad * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 1.1 riastrad * IN THE SOFTWARE. 24 1.1 riastrad */ 25 1.1 riastrad 26 1.1 riastrad #ifndef _V3D_DRM_H_ 27 1.1 riastrad #define _V3D_DRM_H_ 28 1.1 riastrad 29 1.1 riastrad #include "drm.h" 30 1.1 riastrad 31 1.1 riastrad #if defined(__cplusplus) 32 1.1 riastrad extern "C" { 33 1.1 riastrad #endif 34 1.1 riastrad 35 1.1 riastrad #define DRM_V3D_SUBMIT_CL 0x00 36 1.1 riastrad #define DRM_V3D_WAIT_BO 0x01 37 1.1 riastrad #define DRM_V3D_CREATE_BO 0x02 38 1.1 riastrad #define DRM_V3D_MMAP_BO 0x03 39 1.1 riastrad #define DRM_V3D_GET_PARAM 0x04 40 1.1 riastrad #define DRM_V3D_GET_BO_OFFSET 0x05 41 1.1 riastrad #define DRM_V3D_SUBMIT_TFU 0x06 42 1.1 riastrad #define DRM_V3D_SUBMIT_CSD 0x07 43 1.1 riastrad 44 1.1 riastrad #define DRM_IOCTL_V3D_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CL, struct drm_v3d_submit_cl) 45 1.1 riastrad #define DRM_IOCTL_V3D_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_WAIT_BO, struct drm_v3d_wait_bo) 46 1.1 riastrad #define DRM_IOCTL_V3D_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_CREATE_BO, struct drm_v3d_create_bo) 47 1.1 riastrad #define DRM_IOCTL_V3D_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_MMAP_BO, struct drm_v3d_mmap_bo) 48 1.1 riastrad #define DRM_IOCTL_V3D_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_GET_PARAM, struct drm_v3d_get_param) 49 1.1 riastrad #define DRM_IOCTL_V3D_GET_BO_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_GET_BO_OFFSET, struct drm_v3d_get_bo_offset) 50 1.1 riastrad #define DRM_IOCTL_V3D_SUBMIT_TFU DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_TFU, struct drm_v3d_submit_tfu) 51 1.1 riastrad #define DRM_IOCTL_V3D_SUBMIT_CSD DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CSD, struct drm_v3d_submit_csd) 52 1.1 riastrad 53 1.1 riastrad #define DRM_V3D_SUBMIT_CL_FLUSH_CACHE 0x01 54 1.1 riastrad 55 1.1 riastrad /** 56 1.1 riastrad * struct drm_v3d_submit_cl - ioctl argument for submitting commands to the 3D 57 1.1 riastrad * engine. 58 1.1 riastrad * 59 1.1 riastrad * This asks the kernel to have the GPU execute an optional binner 60 1.1 riastrad * command list, and a render command list. 61 1.1 riastrad * 62 1.1 riastrad * The L1T, slice, L2C, L2T, and GCA caches will be flushed before 63 1.1 riastrad * each CL executes. The VCD cache should be flushed (if necessary) 64 1.1 riastrad * by the submitted CLs. The TLB writes are guaranteed to have been 65 1.1 riastrad * flushed by the time the render done IRQ happens, which is the 66 1.1 riastrad * trigger for out_sync. Any dirtying of cachelines by the job (only 67 1.1 riastrad * possible using TMU writes) must be flushed by the caller using the 68 1.1 riastrad * DRM_V3D_SUBMIT_CL_FLUSH_CACHE_FLAG flag. 69 1.1 riastrad */ 70 1.1 riastrad struct drm_v3d_submit_cl { 71 1.1 riastrad /* Pointer to the binner command list. 72 1.1 riastrad * 73 1.1 riastrad * This is the first set of commands executed, which runs the 74 1.1 riastrad * coordinate shader to determine where primitives land on the screen, 75 1.1 riastrad * then writes out the state updates and draw calls necessary per tile 76 1.1 riastrad * to the tile allocation BO. 77 1.1 riastrad * 78 1.1 riastrad * This BCL will block on any previous BCL submitted on the 79 1.1 riastrad * same FD, but not on any RCL or BCLs submitted by other 80 1.1 riastrad * clients -- that is left up to the submitter to control 81 1.1 riastrad * using in_sync_bcl if necessary. 82 1.1 riastrad */ 83 1.1 riastrad __u32 bcl_start; 84 1.1 riastrad 85 1.1 riastrad /** End address of the BCL (first byte after the BCL) */ 86 1.1 riastrad __u32 bcl_end; 87 1.1 riastrad 88 1.1 riastrad /* Offset of the render command list. 89 1.1 riastrad * 90 1.1 riastrad * This is the second set of commands executed, which will either 91 1.1 riastrad * execute the tiles that have been set up by the BCL, or a fixed set 92 1.1 riastrad * of tiles (in the case of RCL-only blits). 93 1.1 riastrad * 94 1.1 riastrad * This RCL will block on this submit's BCL, and any previous 95 1.1 riastrad * RCL submitted on the same FD, but not on any RCL or BCLs 96 1.1 riastrad * submitted by other clients -- that is left up to the 97 1.1 riastrad * submitter to control using in_sync_rcl if necessary. 98 1.1 riastrad */ 99 1.1 riastrad __u32 rcl_start; 100 1.1 riastrad 101 1.1 riastrad /** End address of the RCL (first byte after the RCL) */ 102 1.1 riastrad __u32 rcl_end; 103 1.1 riastrad 104 1.1 riastrad /** An optional sync object to wait on before starting the BCL. */ 105 1.1 riastrad __u32 in_sync_bcl; 106 1.1 riastrad /** An optional sync object to wait on before starting the RCL. */ 107 1.1 riastrad __u32 in_sync_rcl; 108 1.1 riastrad /** An optional sync object to place the completion fence in. */ 109 1.1 riastrad __u32 out_sync; 110 1.1 riastrad 111 1.1 riastrad /* Offset of the tile alloc memory 112 1.1 riastrad * 113 1.1 riastrad * This is optional on V3D 3.3 (where the CL can set the value) but 114 1.1 riastrad * required on V3D 4.1. 115 1.1 riastrad */ 116 1.1 riastrad __u32 qma; 117 1.1 riastrad 118 1.1 riastrad /** Size of the tile alloc memory. */ 119 1.1 riastrad __u32 qms; 120 1.1 riastrad 121 1.1 riastrad /** Offset of the tile state data array. */ 122 1.1 riastrad __u32 qts; 123 1.1 riastrad 124 1.1 riastrad /* Pointer to a u32 array of the BOs that are referenced by the job. 125 1.1 riastrad */ 126 1.1 riastrad __u64 bo_handles; 127 1.1 riastrad 128 1.1 riastrad /* Number of BO handles passed in (size is that times 4). */ 129 1.1 riastrad __u32 bo_handle_count; 130 1.1 riastrad 131 1.1 riastrad __u32 flags; 132 1.1 riastrad }; 133 1.1 riastrad 134 1.1 riastrad /** 135 1.1 riastrad * struct drm_v3d_wait_bo - ioctl argument for waiting for 136 1.1 riastrad * completion of the last DRM_V3D_SUBMIT_CL on a BO. 137 1.1 riastrad * 138 1.1 riastrad * This is useful for cases where multiple processes might be 139 1.1 riastrad * rendering to a BO and you want to wait for all rendering to be 140 1.1 riastrad * completed. 141 1.1 riastrad */ 142 1.1 riastrad struct drm_v3d_wait_bo { 143 1.1 riastrad __u32 handle; 144 1.1 riastrad __u32 pad; 145 1.1 riastrad __u64 timeout_ns; 146 1.1 riastrad }; 147 1.1 riastrad 148 1.1 riastrad /** 149 1.1 riastrad * struct drm_v3d_create_bo - ioctl argument for creating V3D BOs. 150 1.1 riastrad * 151 1.1 riastrad * There are currently no values for the flags argument, but it may be 152 1.1 riastrad * used in a future extension. 153 1.1 riastrad */ 154 1.1 riastrad struct drm_v3d_create_bo { 155 1.1 riastrad __u32 size; 156 1.1 riastrad __u32 flags; 157 1.1 riastrad /** Returned GEM handle for the BO. */ 158 1.1 riastrad __u32 handle; 159 1.1 riastrad /** 160 1.1 riastrad * Returned offset for the BO in the V3D address space. This offset 161 1.1 riastrad * is private to the DRM fd and is valid for the lifetime of the GEM 162 1.1 riastrad * handle. 163 1.1 riastrad * 164 1.1 riastrad * This offset value will always be nonzero, since various HW 165 1.1 riastrad * units treat 0 specially. 166 1.1 riastrad */ 167 1.1 riastrad __u32 offset; 168 1.1 riastrad }; 169 1.1 riastrad 170 1.1 riastrad /** 171 1.1 riastrad * struct drm_v3d_mmap_bo - ioctl argument for mapping V3D BOs. 172 1.1 riastrad * 173 1.1 riastrad * This doesn't actually perform an mmap. Instead, it returns the 174 1.1 riastrad * offset you need to use in an mmap on the DRM device node. This 175 1.1 riastrad * means that tools like valgrind end up knowing about the mapped 176 1.1 riastrad * memory. 177 1.1 riastrad * 178 1.1 riastrad * There are currently no values for the flags argument, but it may be 179 1.1 riastrad * used in a future extension. 180 1.1 riastrad */ 181 1.1 riastrad struct drm_v3d_mmap_bo { 182 1.1 riastrad /** Handle for the object being mapped. */ 183 1.1 riastrad __u32 handle; 184 1.1 riastrad __u32 flags; 185 1.1 riastrad /** offset into the drm node to use for subsequent mmap call. */ 186 1.1 riastrad __u64 offset; 187 1.1 riastrad }; 188 1.1 riastrad 189 1.1 riastrad enum drm_v3d_param { 190 1.1 riastrad DRM_V3D_PARAM_V3D_UIFCFG, 191 1.1 riastrad DRM_V3D_PARAM_V3D_HUB_IDENT1, 192 1.1 riastrad DRM_V3D_PARAM_V3D_HUB_IDENT2, 193 1.1 riastrad DRM_V3D_PARAM_V3D_HUB_IDENT3, 194 1.1 riastrad DRM_V3D_PARAM_V3D_CORE0_IDENT0, 195 1.1 riastrad DRM_V3D_PARAM_V3D_CORE0_IDENT1, 196 1.1 riastrad DRM_V3D_PARAM_V3D_CORE0_IDENT2, 197 1.1 riastrad DRM_V3D_PARAM_SUPPORTS_TFU, 198 1.1 riastrad DRM_V3D_PARAM_SUPPORTS_CSD, 199 1.1 riastrad DRM_V3D_PARAM_SUPPORTS_CACHE_FLUSH, 200 1.1 riastrad }; 201 1.1 riastrad 202 1.1 riastrad struct drm_v3d_get_param { 203 1.1 riastrad __u32 param; 204 1.1 riastrad __u32 pad; 205 1.1 riastrad __u64 value; 206 1.1 riastrad }; 207 1.1 riastrad 208 1.1 riastrad /** 209 1.1 riastrad * Returns the offset for the BO in the V3D address space for this DRM fd. 210 1.1 riastrad * This is the same value returned by drm_v3d_create_bo, if that was called 211 1.1 riastrad * from this DRM fd. 212 1.1 riastrad */ 213 1.1 riastrad struct drm_v3d_get_bo_offset { 214 1.1 riastrad __u32 handle; 215 1.1 riastrad __u32 offset; 216 1.1 riastrad }; 217 1.1 riastrad 218 1.1 riastrad struct drm_v3d_submit_tfu { 219 1.1 riastrad __u32 icfg; 220 1.1 riastrad __u32 iia; 221 1.1 riastrad __u32 iis; 222 1.1 riastrad __u32 ica; 223 1.1 riastrad __u32 iua; 224 1.1 riastrad __u32 ioa; 225 1.1 riastrad __u32 ios; 226 1.1 riastrad __u32 coef[4]; 227 1.1 riastrad /* First handle is the output BO, following are other inputs. 228 1.1 riastrad * 0 for unused. 229 1.1 riastrad */ 230 1.1 riastrad __u32 bo_handles[4]; 231 1.1 riastrad /* sync object to block on before running the TFU job. Each TFU 232 1.1 riastrad * job will execute in the order submitted to its FD. Synchronization 233 1.1 riastrad * against rendering jobs requires using sync objects. 234 1.1 riastrad */ 235 1.1 riastrad __u32 in_sync; 236 1.1 riastrad /* Sync object to signal when the TFU job is done. */ 237 1.1 riastrad __u32 out_sync; 238 1.1 riastrad }; 239 1.1 riastrad 240 1.1 riastrad /* Submits a compute shader for dispatch. This job will block on any 241 1.1 riastrad * previous compute shaders submitted on this fd, and any other 242 1.1 riastrad * synchronization must be performed with in_sync/out_sync. 243 1.1 riastrad */ 244 1.1 riastrad struct drm_v3d_submit_csd { 245 1.1 riastrad __u32 cfg[7]; 246 1.1 riastrad __u32 coef[4]; 247 1.1 riastrad 248 1.1 riastrad /* Pointer to a u32 array of the BOs that are referenced by the job. 249 1.1 riastrad */ 250 1.1 riastrad __u64 bo_handles; 251 1.1 riastrad 252 1.1 riastrad /* Number of BO handles passed in (size is that times 4). */ 253 1.1 riastrad __u32 bo_handle_count; 254 1.1 riastrad 255 1.1 riastrad /* sync object to block on before running the CSD job. Each 256 1.1 riastrad * CSD job will execute in the order submitted to its FD. 257 1.1 riastrad * Synchronization against rendering/TFU jobs or CSD from 258 1.1 riastrad * other fds requires using sync objects. 259 1.1 riastrad */ 260 1.1 riastrad __u32 in_sync; 261 1.1 riastrad /* Sync object to signal when the CSD job is done. */ 262 1.1 riastrad __u32 out_sync; 263 1.1 riastrad }; 264 1.1 riastrad 265 1.1 riastrad #if defined(__cplusplus) 266 1.1 riastrad } 267 1.1 riastrad #endif 268 1.1 riastrad 269 1.1 riastrad #endif /* _V3D_DRM_H_ */ 270