1 /* 2 * Copyright 2013 Red Hat 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 #ifndef VIRTGPU_DRM_H 25 #define VIRTGPU_DRM_H 26 27 #include "drm.h" 28 29 #if defined(__cplusplus) 30 extern "C" { 31 #endif 32 33 /* Please note that modifications to all structs defined here are 34 * subject to backwards-compatibility constraints. 35 * 36 * Do not use pointers, use __u64 instead for 32 bit / 64 bit user/kernel 37 * compatibility Keep fields aligned to their size 38 */ 39 40 #define DRM_VIRTGPU_MAP 0x01 41 #define DRM_VIRTGPU_EXECBUFFER 0x02 42 #define DRM_VIRTGPU_GETPARAM 0x03 43 #define DRM_VIRTGPU_RESOURCE_CREATE 0x04 44 #define DRM_VIRTGPU_RESOURCE_INFO 0x05 45 #define DRM_VIRTGPU_TRANSFER_FROM_HOST 0x06 46 #define DRM_VIRTGPU_TRANSFER_TO_HOST 0x07 47 #define DRM_VIRTGPU_WAIT 0x08 48 #define DRM_VIRTGPU_GET_CAPS 0x09 49 #define DRM_VIRTGPU_RESOURCE_CREATE_BLOB 0x0a 50 51 #define VIRTGPU_EXECBUF_FENCE_FD_IN 0x01 52 #define VIRTGPU_EXECBUF_FENCE_FD_OUT 0x02 53 #define VIRTGPU_EXECBUF_FLAGS (\ 54 VIRTGPU_EXECBUF_FENCE_FD_IN |\ 55 VIRTGPU_EXECBUF_FENCE_FD_OUT |\ 56 0) 57 58 struct drm_virtgpu_map { 59 __u64 offset; /* use for mmap system call */ 60 __u32 handle; 61 __u32 pad; 62 }; 63 64 struct drm_virtgpu_execbuffer { 65 __u32 flags; 66 __u32 size; 67 __u64 command; /* void* */ 68 __u64 bo_handles; 69 __u32 num_bo_handles; 70 __s32 fence_fd; /* in/out fence fd (see VIRTGPU_EXECBUF_FENCE_FD_IN/OUT) */ 71 }; 72 73 #define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */ 74 #define VIRTGPU_PARAM_CAPSET_QUERY_FIX 2 /* do we have the capset fix */ 75 #define VIRTGPU_PARAM_RESOURCE_BLOB 3 /* DRM_VIRTGPU_RESOURCE_CREATE_BLOB */ 76 77 struct drm_virtgpu_getparam { 78 __u64 param; 79 __u64 value; 80 }; 81 82 /* NO_BO flags? NO resource flag? */ 83 /* resource flag for y_0_top */ 84 struct drm_virtgpu_resource_create { 85 __u32 target; 86 __u32 format; 87 __u32 bind; 88 __u32 width; 89 __u32 height; 90 __u32 depth; 91 __u32 array_size; 92 __u32 last_level; 93 __u32 nr_samples; 94 __u32 flags; 95 __u32 bo_handle; /* if this is set - recreate a new resource attached to this bo ? */ 96 __u32 res_handle; /* returned by kernel */ 97 __u32 size; /* validate transfer in the host */ 98 __u32 stride; /* validate transfer in the host */ 99 }; 100 101 struct drm_virtgpu_resource_info { 102 __u32 bo_handle; 103 __u32 res_handle; 104 __u32 size; 105 __u32 blob_mem; 106 }; 107 108 struct drm_virtgpu_3d_box { 109 __u32 x; 110 __u32 y; 111 __u32 z; 112 __u32 w; 113 __u32 h; 114 __u32 d; 115 }; 116 117 struct drm_virtgpu_3d_transfer_to_host { 118 __u32 bo_handle; 119 struct drm_virtgpu_3d_box box; 120 __u32 level; 121 __u32 offset; 122 __u32 stride; 123 __u32 layer_stride; 124 }; 125 126 struct drm_virtgpu_3d_transfer_from_host { 127 __u32 bo_handle; 128 struct drm_virtgpu_3d_box box; 129 __u32 level; 130 __u32 offset; 131 __u32 stride; 132 __u32 layer_stride; 133 }; 134 135 #define VIRTGPU_WAIT_NOWAIT 1 /* like it */ 136 struct drm_virtgpu_3d_wait { 137 __u32 handle; /* 0 is an invalid handle */ 138 __u32 flags; 139 }; 140 141 struct drm_virtgpu_get_caps { 142 __u32 cap_set_id; 143 __u32 cap_set_ver; 144 __u64 addr; 145 __u32 size; 146 __u32 pad; 147 }; 148 149 struct drm_virtgpu_resource_create_blob { 150 #define VIRTGPU_BLOB_MEM_GUEST 0x0001 151 #define VIRTGPU_BLOB_MEM_HOST3D 0x0002 152 #define VIRTGPU_BLOB_MEM_HOST3D_GUEST 0x0003 153 154 #define VIRTGPU_BLOB_FLAG_USE_MAPPABLE 0x0001 155 #define VIRTGPU_BLOB_FLAG_USE_SHAREABLE 0x0002 156 #define VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE 0x0004 157 /* zero is invalid blob_mem */ 158 __u32 blob_mem; 159 __u32 blob_flags; 160 __u32 bo_handle; 161 __u32 res_handle; 162 __u64 size; 163 164 /* 165 * for 3D contexts with VIRTGPU_BLOB_MEM_HOST3D_GUEST and 166 * VIRTGPU_BLOB_MEM_HOST3D otherwise, must be zero. 167 */ 168 __u32 pad; 169 __u32 cmd_size; 170 __u64 cmd; 171 __u64 blob_id; 172 }; 173 174 #define DRM_IOCTL_VIRTGPU_MAP \ 175 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_MAP, struct drm_virtgpu_map) 176 177 #define DRM_IOCTL_VIRTGPU_EXECBUFFER \ 178 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\ 179 struct drm_virtgpu_execbuffer) 180 181 #define DRM_IOCTL_VIRTGPU_GETPARAM \ 182 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_GETPARAM,\ 183 struct drm_virtgpu_getparam) 184 185 #define DRM_IOCTL_VIRTGPU_RESOURCE_CREATE \ 186 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_CREATE, \ 187 struct drm_virtgpu_resource_create) 188 189 #define DRM_IOCTL_VIRTGPU_RESOURCE_INFO \ 190 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_INFO, \ 191 struct drm_virtgpu_resource_info) 192 193 #define DRM_IOCTL_VIRTGPU_TRANSFER_FROM_HOST \ 194 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_TRANSFER_FROM_HOST, \ 195 struct drm_virtgpu_3d_transfer_from_host) 196 197 #define DRM_IOCTL_VIRTGPU_TRANSFER_TO_HOST \ 198 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_TRANSFER_TO_HOST, \ 199 struct drm_virtgpu_3d_transfer_to_host) 200 201 #define DRM_IOCTL_VIRTGPU_WAIT \ 202 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_WAIT, \ 203 struct drm_virtgpu_3d_wait) 204 205 #define DRM_IOCTL_VIRTGPU_GET_CAPS \ 206 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_GET_CAPS, \ 207 struct drm_virtgpu_get_caps) 208 209 #define DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB \ 210 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_CREATE_BLOB, \ 211 struct drm_virtgpu_resource_create_blob) 212 213 #if defined(__cplusplus) 214 } 215 #endif 216 217 #endif 218