--- /dev/null
+/** @file\r
+\r
+ Virtio GPU Device specific type and macro definitions.\r
+\r
+ At the time of this writing, the Virtio 1.0 specification has not\r
+ incorporated the GPU device yet. The following work-in-progress specification\r
+ is used as basis for the implementation:\r
+\r
+ - https://lists.oasis-open.org/archives/virtio-dev/201605/msg00002.html\r
+ - https://www.kraxel.org/virtio/\r
+\r
+ This header file is minimal, and only defines the types and macros that are\r
+ necessary for the OvmfPkg implementation.\r
+\r
+ Copyright (C) 2016, Red Hat, Inc.\r
+\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _VIRTIO_GPU_H_\r
+#define _VIRTIO_GPU_H_\r
+\r
+#include <IndustryStandard/Virtio.h>\r
+\r
+//\r
+// Queue number for sending control commands.\r
+//\r
+#define VIRTIO_GPU_CONTROL_QUEUE 0\r
+\r
+//\r
+// Command and response types.\r
+//\r
+typedef enum {\r
+ //\r
+ // Commands related to mode setup:\r
+ //\r
+ // - create/release a host-side 2D resource,\r
+ //\r
+ VirtioGpuCmdResourceCreate2d = 0x0101,\r
+ VirtioGpuCmdResourceUnref = 0x0102,\r
+ //\r
+ // - attach/detach guest RAM to/from a host-side 2D resource,\r
+ //\r
+ VirtioGpuCmdResourceAttachBacking = 0x0106,\r
+ VirtioGpuCmdResourceDetachBacking = 0x0107,\r
+ //\r
+ // - assign/unassign a host-side 2D resource to/from a scanout ("head").\r
+ //\r
+ VirtioGpuCmdSetScanout = 0x0103,\r
+\r
+ //\r
+ // Commands related to drawing:\r
+ //\r
+ // - transfer a guest RAM update to the host-side 2D resource (does not imply\r
+ // host display refresh),\r
+ //\r
+ VirtioGpuCmdTransferToHost2d = 0x0105,\r
+ //\r
+ // - trigger a host display refresh from the 2D resource.\r
+ //\r
+ VirtioGpuCmdResourceFlush = 0x0104,\r
+\r
+ //\r
+ // Success code for all of the above commands.\r
+ //\r
+ VirtioGpuRespOkNodata = 0x1100,\r
+} VIRTIO_GPU_CONTROL_TYPE;\r
+\r
+//\r
+// Common request/response header.\r
+//\r
+#define VIRTIO_GPU_FLAG_FENCE BIT0\r
+\r
+#pragma pack (1)\r
+typedef struct {\r
+ //\r
+ // The guest sets Type to VirtioGpuCmd* in the requests. The host sets Type\r
+ // to VirtioGpuResp* in the responses.\r
+ //\r
+ UINT32 Type;\r
+\r
+ //\r
+ // Fencing forces the host to complete the command before producing a\r
+ // response.\r
+ //\r
+ UINT32 Flags;\r
+ UINT64 FenceId;\r
+\r
+ //\r
+ // Unused.\r
+ //\r
+ UINT32 CtxId;\r
+ UINT32 Padding;\r
+} VIRTIO_GPU_CONTROL_HEADER;\r
+#pragma pack ()\r
+\r
+//\r
+// Rectangle structure used by several operations.\r
+//\r
+#pragma pack (1)\r
+typedef struct {\r
+ UINT32 X;\r
+ UINT32 Y;\r
+ UINT32 Width;\r
+ UINT32 Height;\r
+} VIRTIO_GPU_RECTANGLE;\r
+#pragma pack ()\r
+\r
+//\r
+// Request structure for VirtioGpuCmdResourceCreate2d.\r
+//\r
+typedef enum {\r
+ //\r
+ // 32-bit depth, BGRX component order, X component ignored.\r
+ //\r
+ VirtioGpuFormatB8G8R8X8Unorm = 2,\r
+} VIRTIO_GPU_FORMATS;\r
+\r
+#pragma pack (1)\r
+typedef struct {\r
+ VIRTIO_GPU_CONTROL_HEADER Header;\r
+ UINT32 ResourceId; // note: 0 is invalid\r
+ UINT32 Format; // from VIRTIO_GPU_FORMATS\r
+ UINT32 Width;\r
+ UINT32 Height;\r
+} VIRTIO_GPU_RESOURCE_CREATE_2D;\r
+#pragma pack ()\r
+\r
+//\r
+// Request structure for VirtioGpuCmdResourceUnref.\r
+//\r
+#pragma pack (1)\r
+typedef struct {\r
+ VIRTIO_GPU_CONTROL_HEADER Header;\r
+ UINT32 ResourceId;\r
+ UINT32 Padding;\r
+} VIRTIO_GPU_RESOURCE_UNREF;\r
+#pragma pack ()\r
+\r
+//\r
+// Request structure for VirtioGpuCmdResourceAttachBacking.\r
+//\r
+// The spec allows for a scatter-gather list, but for simplicity we hard-code a\r
+// single guest buffer.\r
+//\r
+#pragma pack (1)\r
+typedef struct {\r
+ UINT64 Addr;\r
+ UINT32 Length;\r
+ UINT32 Padding;\r
+} VIRTIO_GPU_MEM_ENTRY;\r
+\r
+typedef struct {\r
+ VIRTIO_GPU_CONTROL_HEADER Header;\r
+ UINT32 ResourceId;\r
+ UINT32 NrEntries; // number of entries: constant 1\r
+ VIRTIO_GPU_MEM_ENTRY Entry;\r
+} VIRTIO_GPU_RESOURCE_ATTACH_BACKING;\r
+#pragma pack ()\r
+\r
+//\r
+// Request structure for VirtioGpuCmdResourceDetachBacking.\r
+//\r
+#pragma pack (1)\r
+typedef struct {\r
+ VIRTIO_GPU_CONTROL_HEADER Header;\r
+ UINT32 ResourceId;\r
+ UINT32 Padding;\r
+} VIRTIO_GPU_RESOURCE_DETACH_BACKING;\r
+#pragma pack ()\r
+\r
+//\r
+// Request structure for VirtioGpuCmdSetScanout.\r
+//\r
+#pragma pack (1)\r
+typedef struct {\r
+ VIRTIO_GPU_CONTROL_HEADER Header;\r
+ VIRTIO_GPU_RECTANGLE Rectangle;\r
+ UINT32 ScanoutId;\r
+ UINT32 ResourceId;\r
+} VIRTIO_GPU_SET_SCANOUT;\r
+#pragma pack ()\r
+\r
+//\r
+// Request structure for VirtioGpuCmdTransferToHost2d.\r
+//\r
+#pragma pack (1)\r
+typedef struct {\r
+ VIRTIO_GPU_CONTROL_HEADER Header;\r
+ VIRTIO_GPU_RECTANGLE Rectangle;\r
+ UINT64 Offset;\r
+ UINT32 ResourceId;\r
+ UINT32 Padding;\r
+} VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D;\r
+#pragma pack ()\r
+\r
+//\r
+// Request structure for VirtioGpuCmdResourceFlush.\r
+//\r
+#pragma pack (1)\r
+typedef struct {\r
+ VIRTIO_GPU_CONTROL_HEADER Header;\r
+ VIRTIO_GPU_RECTANGLE Rectangle;\r
+ UINT32 ResourceId;\r
+ UINT32 Padding;\r
+} VIRTIO_GPU_RESOURCE_FLUSH;\r
+#pragma pack ()\r
+\r
+#endif // _VIRTIO_GPU_H_\r