1 /** @file 2 3 Virtio GPU Device specific type and macro definitions. 4 5 At the time of this writing, the Virtio 1.0 specification has not 6 incorporated the GPU device yet. The following work-in-progress specification 7 is used as basis for the implementation: 8 9 - https://lists.oasis-open.org/archives/virtio-dev/201605/msg00002.html 10 - https://www.kraxel.org/virtio/ 11 12 This header file is minimal, and only defines the types and macros that are 13 necessary for the OvmfPkg implementation. 14 15 Copyright (C) 2016, Red Hat, Inc. 16 17 This program and the accompanying materials are licensed and made available 18 under the terms and conditions of the BSD License which accompanies this 19 distribution. The full text of the license may be found at 20 http://opensource.org/licenses/bsd-license.php 21 22 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT 23 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 24 25 **/ 26 27 #ifndef _VIRTIO_GPU_H_ 28 #define _VIRTIO_GPU_H_ 29 30 #include <IndustryStandard/Virtio.h> 31 32 // 33 // Queue number for sending control commands. 34 // 35 #define VIRTIO_GPU_CONTROL_QUEUE 0 36 37 // 38 // Command and response types. 39 // 40 typedef enum { 41 // 42 // Commands related to mode setup: 43 // 44 // - create/release a host-side 2D resource, 45 // 46 VirtioGpuCmdResourceCreate2d = 0x0101, 47 VirtioGpuCmdResourceUnref = 0x0102, 48 // 49 // - attach/detach guest RAM to/from a host-side 2D resource, 50 // 51 VirtioGpuCmdResourceAttachBacking = 0x0106, 52 VirtioGpuCmdResourceDetachBacking = 0x0107, 53 // 54 // - assign/unassign a host-side 2D resource to/from a scanout ("head"). 55 // 56 VirtioGpuCmdSetScanout = 0x0103, 57 58 // 59 // Commands related to drawing: 60 // 61 // - transfer a guest RAM update to the host-side 2D resource (does not imply 62 // host display refresh), 63 // 64 VirtioGpuCmdTransferToHost2d = 0x0105, 65 // 66 // - trigger a host display refresh from the 2D resource. 67 // 68 VirtioGpuCmdResourceFlush = 0x0104, 69 70 // 71 // Success code for all of the above commands. 72 // 73 VirtioGpuRespOkNodata = 0x1100, 74 } VIRTIO_GPU_CONTROL_TYPE; 75 76 // 77 // Common request/response header. 78 // 79 #define VIRTIO_GPU_FLAG_FENCE BIT0 80 81 #pragma pack (1) 82 typedef struct { 83 // 84 // The guest sets Type to VirtioGpuCmd* in the requests. The host sets Type 85 // to VirtioGpuResp* in the responses. 86 // 87 UINT32 Type; 88 89 // 90 // Fencing forces the host to complete the command before producing a 91 // response. 92 // 93 UINT32 Flags; 94 UINT64 FenceId; 95 96 // 97 // Unused. 98 // 99 UINT32 CtxId; 100 UINT32 Padding; 101 } VIRTIO_GPU_CONTROL_HEADER; 102 #pragma pack () 103 104 // 105 // Rectangle structure used by several operations. 106 // 107 #pragma pack (1) 108 typedef struct { 109 UINT32 X; 110 UINT32 Y; 111 UINT32 Width; 112 UINT32 Height; 113 } VIRTIO_GPU_RECTANGLE; 114 #pragma pack () 115 116 // 117 // Request structure for VirtioGpuCmdResourceCreate2d. 118 // 119 typedef enum { 120 // 121 // 32-bit depth, BGRX component order, X component ignored. 122 // 123 VirtioGpuFormatB8G8R8X8Unorm = 2, 124 } VIRTIO_GPU_FORMATS; 125 126 #pragma pack (1) 127 typedef struct { 128 VIRTIO_GPU_CONTROL_HEADER Header; 129 UINT32 ResourceId; // note: 0 is invalid 130 UINT32 Format; // from VIRTIO_GPU_FORMATS 131 UINT32 Width; 132 UINT32 Height; 133 } VIRTIO_GPU_RESOURCE_CREATE_2D; 134 #pragma pack () 135 136 // 137 // Request structure for VirtioGpuCmdResourceUnref. 138 // 139 #pragma pack (1) 140 typedef struct { 141 VIRTIO_GPU_CONTROL_HEADER Header; 142 UINT32 ResourceId; 143 UINT32 Padding; 144 } VIRTIO_GPU_RESOURCE_UNREF; 145 #pragma pack () 146 147 // 148 // Request structure for VirtioGpuCmdResourceAttachBacking. 149 // 150 // The spec allows for a scatter-gather list, but for simplicity we hard-code a 151 // single guest buffer. 152 // 153 #pragma pack (1) 154 typedef struct { 155 UINT64 Addr; 156 UINT32 Length; 157 UINT32 Padding; 158 } VIRTIO_GPU_MEM_ENTRY; 159 160 typedef struct { 161 VIRTIO_GPU_CONTROL_HEADER Header; 162 UINT32 ResourceId; 163 UINT32 NrEntries; // number of entries: constant 1 164 VIRTIO_GPU_MEM_ENTRY Entry; 165 } VIRTIO_GPU_RESOURCE_ATTACH_BACKING; 166 #pragma pack () 167 168 // 169 // Request structure for VirtioGpuCmdResourceDetachBacking. 170 // 171 #pragma pack (1) 172 typedef struct { 173 VIRTIO_GPU_CONTROL_HEADER Header; 174 UINT32 ResourceId; 175 UINT32 Padding; 176 } VIRTIO_GPU_RESOURCE_DETACH_BACKING; 177 #pragma pack () 178 179 // 180 // Request structure for VirtioGpuCmdSetScanout. 181 // 182 #pragma pack (1) 183 typedef struct { 184 VIRTIO_GPU_CONTROL_HEADER Header; 185 VIRTIO_GPU_RECTANGLE Rectangle; 186 UINT32 ScanoutId; 187 UINT32 ResourceId; 188 } VIRTIO_GPU_SET_SCANOUT; 189 #pragma pack () 190 191 // 192 // Request structure for VirtioGpuCmdTransferToHost2d. 193 // 194 #pragma pack (1) 195 typedef struct { 196 VIRTIO_GPU_CONTROL_HEADER Header; 197 VIRTIO_GPU_RECTANGLE Rectangle; 198 UINT64 Offset; 199 UINT32 ResourceId; 200 UINT32 Padding; 201 } VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D; 202 #pragma pack () 203 204 // 205 // Request structure for VirtioGpuCmdResourceFlush. 206 // 207 #pragma pack (1) 208 typedef struct { 209 VIRTIO_GPU_CONTROL_HEADER Header; 210 VIRTIO_GPU_RECTANGLE Rectangle; 211 UINT32 ResourceId; 212 UINT32 Padding; 213 } VIRTIO_GPU_RESOURCE_FLUSH; 214 #pragma pack () 215 216 #endif // _VIRTIO_GPU_H_ 217