162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright 2013 Red Hat 362306a36Sopenharmony_ci * All Rights Reserved. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 662306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 762306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 862306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 962306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 1062306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the next 1362306a36Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 1462306a36Sopenharmony_ci * Software. 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1762306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1862306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1962306a36Sopenharmony_ci * THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 2062306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2162306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2262306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 2362306a36Sopenharmony_ci */ 2462306a36Sopenharmony_ci#ifndef VIRTGPU_DRM_H 2562306a36Sopenharmony_ci#define VIRTGPU_DRM_H 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#include "drm.h" 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#if defined(__cplusplus) 3062306a36Sopenharmony_ciextern "C" { 3162306a36Sopenharmony_ci#endif 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci/* Please note that modifications to all structs defined here are 3462306a36Sopenharmony_ci * subject to backwards-compatibility constraints. 3562306a36Sopenharmony_ci * 3662306a36Sopenharmony_ci * Do not use pointers, use __u64 instead for 32 bit / 64 bit user/kernel 3762306a36Sopenharmony_ci * compatibility Keep fields aligned to their size 3862306a36Sopenharmony_ci */ 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#define DRM_VIRTGPU_MAP 0x01 4162306a36Sopenharmony_ci#define DRM_VIRTGPU_EXECBUFFER 0x02 4262306a36Sopenharmony_ci#define DRM_VIRTGPU_GETPARAM 0x03 4362306a36Sopenharmony_ci#define DRM_VIRTGPU_RESOURCE_CREATE 0x04 4462306a36Sopenharmony_ci#define DRM_VIRTGPU_RESOURCE_INFO 0x05 4562306a36Sopenharmony_ci#define DRM_VIRTGPU_TRANSFER_FROM_HOST 0x06 4662306a36Sopenharmony_ci#define DRM_VIRTGPU_TRANSFER_TO_HOST 0x07 4762306a36Sopenharmony_ci#define DRM_VIRTGPU_WAIT 0x08 4862306a36Sopenharmony_ci#define DRM_VIRTGPU_GET_CAPS 0x09 4962306a36Sopenharmony_ci#define DRM_VIRTGPU_RESOURCE_CREATE_BLOB 0x0a 5062306a36Sopenharmony_ci#define DRM_VIRTGPU_CONTEXT_INIT 0x0b 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define VIRTGPU_EXECBUF_FENCE_FD_IN 0x01 5362306a36Sopenharmony_ci#define VIRTGPU_EXECBUF_FENCE_FD_OUT 0x02 5462306a36Sopenharmony_ci#define VIRTGPU_EXECBUF_RING_IDX 0x04 5562306a36Sopenharmony_ci#define VIRTGPU_EXECBUF_FLAGS (\ 5662306a36Sopenharmony_ci VIRTGPU_EXECBUF_FENCE_FD_IN |\ 5762306a36Sopenharmony_ci VIRTGPU_EXECBUF_FENCE_FD_OUT |\ 5862306a36Sopenharmony_ci VIRTGPU_EXECBUF_RING_IDX |\ 5962306a36Sopenharmony_ci 0) 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_cistruct drm_virtgpu_map { 6262306a36Sopenharmony_ci __u64 offset; /* use for mmap system call */ 6362306a36Sopenharmony_ci __u32 handle; 6462306a36Sopenharmony_ci __u32 pad; 6562306a36Sopenharmony_ci}; 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#define VIRTGPU_EXECBUF_SYNCOBJ_RESET 0x01 6862306a36Sopenharmony_ci#define VIRTGPU_EXECBUF_SYNCOBJ_FLAGS ( \ 6962306a36Sopenharmony_ci VIRTGPU_EXECBUF_SYNCOBJ_RESET | \ 7062306a36Sopenharmony_ci 0) 7162306a36Sopenharmony_cistruct drm_virtgpu_execbuffer_syncobj { 7262306a36Sopenharmony_ci __u32 handle; 7362306a36Sopenharmony_ci __u32 flags; 7462306a36Sopenharmony_ci __u64 point; 7562306a36Sopenharmony_ci}; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* fence_fd is modified on success if VIRTGPU_EXECBUF_FENCE_FD_OUT flag is set. */ 7862306a36Sopenharmony_cistruct drm_virtgpu_execbuffer { 7962306a36Sopenharmony_ci __u32 flags; 8062306a36Sopenharmony_ci __u32 size; 8162306a36Sopenharmony_ci __u64 command; /* void* */ 8262306a36Sopenharmony_ci __u64 bo_handles; 8362306a36Sopenharmony_ci __u32 num_bo_handles; 8462306a36Sopenharmony_ci __s32 fence_fd; /* in/out fence fd (see VIRTGPU_EXECBUF_FENCE_FD_IN/OUT) */ 8562306a36Sopenharmony_ci __u32 ring_idx; /* command ring index (see VIRTGPU_EXECBUF_RING_IDX) */ 8662306a36Sopenharmony_ci __u32 syncobj_stride; /* size of @drm_virtgpu_execbuffer_syncobj */ 8762306a36Sopenharmony_ci __u32 num_in_syncobjs; 8862306a36Sopenharmony_ci __u32 num_out_syncobjs; 8962306a36Sopenharmony_ci __u64 in_syncobjs; 9062306a36Sopenharmony_ci __u64 out_syncobjs; 9162306a36Sopenharmony_ci}; 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci#define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */ 9462306a36Sopenharmony_ci#define VIRTGPU_PARAM_CAPSET_QUERY_FIX 2 /* do we have the capset fix */ 9562306a36Sopenharmony_ci#define VIRTGPU_PARAM_RESOURCE_BLOB 3 /* DRM_VIRTGPU_RESOURCE_CREATE_BLOB */ 9662306a36Sopenharmony_ci#define VIRTGPU_PARAM_HOST_VISIBLE 4 /* Host blob resources are mappable */ 9762306a36Sopenharmony_ci#define VIRTGPU_PARAM_CROSS_DEVICE 5 /* Cross virtio-device resource sharing */ 9862306a36Sopenharmony_ci#define VIRTGPU_PARAM_CONTEXT_INIT 6 /* DRM_VIRTGPU_CONTEXT_INIT */ 9962306a36Sopenharmony_ci#define VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs 7 /* Bitmask of supported capability set ids */ 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_cistruct drm_virtgpu_getparam { 10262306a36Sopenharmony_ci __u64 param; 10362306a36Sopenharmony_ci __u64 value; 10462306a36Sopenharmony_ci}; 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci/* NO_BO flags? NO resource flag? */ 10762306a36Sopenharmony_ci/* resource flag for y_0_top */ 10862306a36Sopenharmony_cistruct drm_virtgpu_resource_create { 10962306a36Sopenharmony_ci __u32 target; 11062306a36Sopenharmony_ci __u32 format; 11162306a36Sopenharmony_ci __u32 bind; 11262306a36Sopenharmony_ci __u32 width; 11362306a36Sopenharmony_ci __u32 height; 11462306a36Sopenharmony_ci __u32 depth; 11562306a36Sopenharmony_ci __u32 array_size; 11662306a36Sopenharmony_ci __u32 last_level; 11762306a36Sopenharmony_ci __u32 nr_samples; 11862306a36Sopenharmony_ci __u32 flags; 11962306a36Sopenharmony_ci __u32 bo_handle; /* if this is set - recreate a new resource attached to this bo ? */ 12062306a36Sopenharmony_ci __u32 res_handle; /* returned by kernel */ 12162306a36Sopenharmony_ci __u32 size; /* validate transfer in the host */ 12262306a36Sopenharmony_ci __u32 stride; /* validate transfer in the host */ 12362306a36Sopenharmony_ci}; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_cistruct drm_virtgpu_resource_info { 12662306a36Sopenharmony_ci __u32 bo_handle; 12762306a36Sopenharmony_ci __u32 res_handle; 12862306a36Sopenharmony_ci __u32 size; 12962306a36Sopenharmony_ci __u32 blob_mem; 13062306a36Sopenharmony_ci}; 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_cistruct drm_virtgpu_3d_box { 13362306a36Sopenharmony_ci __u32 x; 13462306a36Sopenharmony_ci __u32 y; 13562306a36Sopenharmony_ci __u32 z; 13662306a36Sopenharmony_ci __u32 w; 13762306a36Sopenharmony_ci __u32 h; 13862306a36Sopenharmony_ci __u32 d; 13962306a36Sopenharmony_ci}; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_cistruct drm_virtgpu_3d_transfer_to_host { 14262306a36Sopenharmony_ci __u32 bo_handle; 14362306a36Sopenharmony_ci struct drm_virtgpu_3d_box box; 14462306a36Sopenharmony_ci __u32 level; 14562306a36Sopenharmony_ci __u32 offset; 14662306a36Sopenharmony_ci __u32 stride; 14762306a36Sopenharmony_ci __u32 layer_stride; 14862306a36Sopenharmony_ci}; 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_cistruct drm_virtgpu_3d_transfer_from_host { 15162306a36Sopenharmony_ci __u32 bo_handle; 15262306a36Sopenharmony_ci struct drm_virtgpu_3d_box box; 15362306a36Sopenharmony_ci __u32 level; 15462306a36Sopenharmony_ci __u32 offset; 15562306a36Sopenharmony_ci __u32 stride; 15662306a36Sopenharmony_ci __u32 layer_stride; 15762306a36Sopenharmony_ci}; 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci#define VIRTGPU_WAIT_NOWAIT 1 /* like it */ 16062306a36Sopenharmony_cistruct drm_virtgpu_3d_wait { 16162306a36Sopenharmony_ci __u32 handle; /* 0 is an invalid handle */ 16262306a36Sopenharmony_ci __u32 flags; 16362306a36Sopenharmony_ci}; 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_cistruct drm_virtgpu_get_caps { 16662306a36Sopenharmony_ci __u32 cap_set_id; 16762306a36Sopenharmony_ci __u32 cap_set_ver; 16862306a36Sopenharmony_ci __u64 addr; 16962306a36Sopenharmony_ci __u32 size; 17062306a36Sopenharmony_ci __u32 pad; 17162306a36Sopenharmony_ci}; 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_cistruct drm_virtgpu_resource_create_blob { 17462306a36Sopenharmony_ci#define VIRTGPU_BLOB_MEM_GUEST 0x0001 17562306a36Sopenharmony_ci#define VIRTGPU_BLOB_MEM_HOST3D 0x0002 17662306a36Sopenharmony_ci#define VIRTGPU_BLOB_MEM_HOST3D_GUEST 0x0003 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci#define VIRTGPU_BLOB_FLAG_USE_MAPPABLE 0x0001 17962306a36Sopenharmony_ci#define VIRTGPU_BLOB_FLAG_USE_SHAREABLE 0x0002 18062306a36Sopenharmony_ci#define VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE 0x0004 18162306a36Sopenharmony_ci /* zero is invalid blob_mem */ 18262306a36Sopenharmony_ci __u32 blob_mem; 18362306a36Sopenharmony_ci __u32 blob_flags; 18462306a36Sopenharmony_ci __u32 bo_handle; 18562306a36Sopenharmony_ci __u32 res_handle; 18662306a36Sopenharmony_ci __u64 size; 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci /* 18962306a36Sopenharmony_ci * for 3D contexts with VIRTGPU_BLOB_MEM_HOST3D_GUEST and 19062306a36Sopenharmony_ci * VIRTGPU_BLOB_MEM_HOST3D otherwise, must be zero. 19162306a36Sopenharmony_ci */ 19262306a36Sopenharmony_ci __u32 pad; 19362306a36Sopenharmony_ci __u32 cmd_size; 19462306a36Sopenharmony_ci __u64 cmd; 19562306a36Sopenharmony_ci __u64 blob_id; 19662306a36Sopenharmony_ci}; 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci#define VIRTGPU_CONTEXT_PARAM_CAPSET_ID 0x0001 19962306a36Sopenharmony_ci#define VIRTGPU_CONTEXT_PARAM_NUM_RINGS 0x0002 20062306a36Sopenharmony_ci#define VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK 0x0003 20162306a36Sopenharmony_cistruct drm_virtgpu_context_set_param { 20262306a36Sopenharmony_ci __u64 param; 20362306a36Sopenharmony_ci __u64 value; 20462306a36Sopenharmony_ci}; 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_cistruct drm_virtgpu_context_init { 20762306a36Sopenharmony_ci __u32 num_params; 20862306a36Sopenharmony_ci __u32 pad; 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci /* pointer to drm_virtgpu_context_set_param array */ 21162306a36Sopenharmony_ci __u64 ctx_set_params; 21262306a36Sopenharmony_ci}; 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci/* 21562306a36Sopenharmony_ci * Event code that's given when VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK is in 21662306a36Sopenharmony_ci * effect. The event size is sizeof(drm_event), since there is no additional 21762306a36Sopenharmony_ci * payload. 21862306a36Sopenharmony_ci */ 21962306a36Sopenharmony_ci#define VIRTGPU_EVENT_FENCE_SIGNALED 0x90000000 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_MAP \ 22262306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_MAP, struct drm_virtgpu_map) 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_EXECBUFFER \ 22562306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\ 22662306a36Sopenharmony_ci struct drm_virtgpu_execbuffer) 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_GETPARAM \ 22962306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_GETPARAM,\ 23062306a36Sopenharmony_ci struct drm_virtgpu_getparam) 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_RESOURCE_CREATE \ 23362306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_CREATE, \ 23462306a36Sopenharmony_ci struct drm_virtgpu_resource_create) 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_RESOURCE_INFO \ 23762306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_INFO, \ 23862306a36Sopenharmony_ci struct drm_virtgpu_resource_info) 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_TRANSFER_FROM_HOST \ 24162306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_TRANSFER_FROM_HOST, \ 24262306a36Sopenharmony_ci struct drm_virtgpu_3d_transfer_from_host) 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_TRANSFER_TO_HOST \ 24562306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_TRANSFER_TO_HOST, \ 24662306a36Sopenharmony_ci struct drm_virtgpu_3d_transfer_to_host) 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_WAIT \ 24962306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_WAIT, \ 25062306a36Sopenharmony_ci struct drm_virtgpu_3d_wait) 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_GET_CAPS \ 25362306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_GET_CAPS, \ 25462306a36Sopenharmony_ci struct drm_virtgpu_get_caps) 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB \ 25762306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_CREATE_BLOB, \ 25862306a36Sopenharmony_ci struct drm_virtgpu_resource_create_blob) 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci#define DRM_IOCTL_VIRTGPU_CONTEXT_INIT \ 26162306a36Sopenharmony_ci DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_CONTEXT_INIT, \ 26262306a36Sopenharmony_ci struct drm_virtgpu_context_init) 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci#if defined(__cplusplus) 26562306a36Sopenharmony_ci} 26662306a36Sopenharmony_ci#endif 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci#endif 269