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 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
18 |
|
---|
19 | **/
|
---|
20 |
|
---|
21 | #ifndef _VIRTIO_GPU_H_
|
---|
22 | #define _VIRTIO_GPU_H_
|
---|
23 |
|
---|
24 | #include <IndustryStandard/Virtio.h>
|
---|
25 |
|
---|
26 | //
|
---|
27 | // Queue number for sending control commands.
|
---|
28 | //
|
---|
29 | #define VIRTIO_GPU_CONTROL_QUEUE 0
|
---|
30 |
|
---|
31 | //
|
---|
32 | // Command and response types.
|
---|
33 | //
|
---|
34 | typedef enum {
|
---|
35 | //
|
---|
36 | // Commands related to mode setup:
|
---|
37 | //
|
---|
38 | // - create/release a host-side 2D resource,
|
---|
39 | //
|
---|
40 | VirtioGpuCmdGetDisplayInfo = 0x0100,
|
---|
41 | VirtioGpuCmdResourceCreate2d = 0x0101,
|
---|
42 | VirtioGpuCmdResourceUnref = 0x0102,
|
---|
43 | //
|
---|
44 | // - attach/detach guest RAM to/from a host-side 2D resource,
|
---|
45 | //
|
---|
46 | VirtioGpuCmdResourceAttachBacking = 0x0106,
|
---|
47 | VirtioGpuCmdResourceDetachBacking = 0x0107,
|
---|
48 | //
|
---|
49 | // - assign/unassign a host-side 2D resource to/from a scanout ("head").
|
---|
50 | //
|
---|
51 | VirtioGpuCmdSetScanout = 0x0103,
|
---|
52 |
|
---|
53 | //
|
---|
54 | // Commands related to drawing:
|
---|
55 | //
|
---|
56 | // - transfer a guest RAM update to the host-side 2D resource (does not imply
|
---|
57 | // host display refresh),
|
---|
58 | //
|
---|
59 | VirtioGpuCmdTransferToHost2d = 0x0105,
|
---|
60 | //
|
---|
61 | // - trigger a host display refresh from the 2D resource.
|
---|
62 | //
|
---|
63 | VirtioGpuCmdResourceFlush = 0x0104,
|
---|
64 |
|
---|
65 | //
|
---|
66 | // Success code for all of the above commands.
|
---|
67 | //
|
---|
68 | VirtioGpuRespOkNodata = 0x1100,
|
---|
69 | VirtioGpuRespOkDisplayInfo = 0x1101,
|
---|
70 | } VIRTIO_GPU_CONTROL_TYPE;
|
---|
71 |
|
---|
72 | //
|
---|
73 | // Common request/response header.
|
---|
74 | //
|
---|
75 | #define VIRTIO_GPU_FLAG_FENCE BIT0
|
---|
76 |
|
---|
77 | #pragma pack (1)
|
---|
78 | typedef struct {
|
---|
79 | //
|
---|
80 | // The guest sets Type to VirtioGpuCmd* in the requests. The host sets Type
|
---|
81 | // to VirtioGpuResp* in the responses.
|
---|
82 | //
|
---|
83 | UINT32 Type;
|
---|
84 |
|
---|
85 | //
|
---|
86 | // Fencing forces the host to complete the command before producing a
|
---|
87 | // response.
|
---|
88 | //
|
---|
89 | UINT32 Flags;
|
---|
90 | UINT64 FenceId;
|
---|
91 |
|
---|
92 | //
|
---|
93 | // Unused.
|
---|
94 | //
|
---|
95 | UINT32 CtxId;
|
---|
96 | UINT32 Padding;
|
---|
97 | } VIRTIO_GPU_CONTROL_HEADER;
|
---|
98 | #pragma pack ()
|
---|
99 |
|
---|
100 | //
|
---|
101 | // Rectangle structure used by several operations.
|
---|
102 | //
|
---|
103 | #pragma pack (1)
|
---|
104 | typedef struct {
|
---|
105 | UINT32 X;
|
---|
106 | UINT32 Y;
|
---|
107 | UINT32 Width;
|
---|
108 | UINT32 Height;
|
---|
109 | } VIRTIO_GPU_RECTANGLE;
|
---|
110 | #pragma pack ()
|
---|
111 |
|
---|
112 | //
|
---|
113 | // Request structure for VirtioGpuCmdResourceCreate2d.
|
---|
114 | //
|
---|
115 | typedef enum {
|
---|
116 | //
|
---|
117 | // 32-bit depth, BGRX component order, X component ignored.
|
---|
118 | //
|
---|
119 | VirtioGpuFormatB8G8R8X8Unorm = 2,
|
---|
120 | } VIRTIO_GPU_FORMATS;
|
---|
121 |
|
---|
122 | #pragma pack (1)
|
---|
123 | typedef struct {
|
---|
124 | VIRTIO_GPU_CONTROL_HEADER Header;
|
---|
125 | UINT32 ResourceId; // note: 0 is invalid
|
---|
126 | UINT32 Format; // from VIRTIO_GPU_FORMATS
|
---|
127 | UINT32 Width;
|
---|
128 | UINT32 Height;
|
---|
129 | } VIRTIO_GPU_RESOURCE_CREATE_2D;
|
---|
130 | #pragma pack ()
|
---|
131 |
|
---|
132 | //
|
---|
133 | // Request structure for VirtioGpuCmdResourceUnref.
|
---|
134 | //
|
---|
135 | #pragma pack (1)
|
---|
136 | typedef struct {
|
---|
137 | VIRTIO_GPU_CONTROL_HEADER Header;
|
---|
138 | UINT32 ResourceId;
|
---|
139 | UINT32 Padding;
|
---|
140 | } VIRTIO_GPU_RESOURCE_UNREF;
|
---|
141 | #pragma pack ()
|
---|
142 |
|
---|
143 | //
|
---|
144 | // Request structure for VirtioGpuCmdResourceAttachBacking.
|
---|
145 | //
|
---|
146 | // The spec allows for a scatter-gather list, but for simplicity we hard-code a
|
---|
147 | // single guest buffer.
|
---|
148 | //
|
---|
149 | #pragma pack (1)
|
---|
150 | typedef struct {
|
---|
151 | UINT64 Addr;
|
---|
152 | UINT32 Length;
|
---|
153 | UINT32 Padding;
|
---|
154 | } VIRTIO_GPU_MEM_ENTRY;
|
---|
155 |
|
---|
156 | typedef struct {
|
---|
157 | VIRTIO_GPU_CONTROL_HEADER Header;
|
---|
158 | UINT32 ResourceId;
|
---|
159 | UINT32 NrEntries; // number of entries: constant 1
|
---|
160 | VIRTIO_GPU_MEM_ENTRY Entry;
|
---|
161 | } VIRTIO_GPU_RESOURCE_ATTACH_BACKING;
|
---|
162 | #pragma pack ()
|
---|
163 |
|
---|
164 | //
|
---|
165 | // Request structure for VirtioGpuCmdResourceDetachBacking.
|
---|
166 | //
|
---|
167 | #pragma pack (1)
|
---|
168 | typedef struct {
|
---|
169 | VIRTIO_GPU_CONTROL_HEADER Header;
|
---|
170 | UINT32 ResourceId;
|
---|
171 | UINT32 Padding;
|
---|
172 | } VIRTIO_GPU_RESOURCE_DETACH_BACKING;
|
---|
173 | #pragma pack ()
|
---|
174 |
|
---|
175 | //
|
---|
176 | // Request structure for VirtioGpuCmdSetScanout.
|
---|
177 | //
|
---|
178 | #pragma pack (1)
|
---|
179 | typedef struct {
|
---|
180 | VIRTIO_GPU_CONTROL_HEADER Header;
|
---|
181 | VIRTIO_GPU_RECTANGLE Rectangle;
|
---|
182 | UINT32 ScanoutId;
|
---|
183 | UINT32 ResourceId;
|
---|
184 | } VIRTIO_GPU_SET_SCANOUT;
|
---|
185 | #pragma pack ()
|
---|
186 |
|
---|
187 | //
|
---|
188 | // Request structure for VirtioGpuCmdTransferToHost2d.
|
---|
189 | //
|
---|
190 | #pragma pack (1)
|
---|
191 | typedef struct {
|
---|
192 | VIRTIO_GPU_CONTROL_HEADER Header;
|
---|
193 | VIRTIO_GPU_RECTANGLE Rectangle;
|
---|
194 | UINT64 Offset;
|
---|
195 | UINT32 ResourceId;
|
---|
196 | UINT32 Padding;
|
---|
197 | } VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D;
|
---|
198 | #pragma pack ()
|
---|
199 |
|
---|
200 | //
|
---|
201 | // Request structure for VirtioGpuCmdResourceFlush.
|
---|
202 | //
|
---|
203 | #pragma pack (1)
|
---|
204 | typedef struct {
|
---|
205 | VIRTIO_GPU_CONTROL_HEADER Header;
|
---|
206 | VIRTIO_GPU_RECTANGLE Rectangle;
|
---|
207 | UINT32 ResourceId;
|
---|
208 | UINT32 Padding;
|
---|
209 | } VIRTIO_GPU_RESOURCE_FLUSH;
|
---|
210 | #pragma pack ()
|
---|
211 |
|
---|
212 | //
|
---|
213 | // Response structure for VirtioGpuCmdGetDisplayInfo
|
---|
214 | //
|
---|
215 | #define VIRTIO_GPU_MAX_SCANOUTS 16
|
---|
216 | #pragma pack (1)
|
---|
217 | typedef struct {
|
---|
218 | VIRTIO_GPU_CONTROL_HEADER Header;
|
---|
219 | struct {
|
---|
220 | VIRTIO_GPU_RECTANGLE Rectangle;
|
---|
221 | UINT32 Enabled;
|
---|
222 | UINT32 Flags;
|
---|
223 | } Pmodes[VIRTIO_GPU_MAX_SCANOUTS];
|
---|
224 | } VIRTIO_GPU_RESP_DISPLAY_INFO;
|
---|
225 | #pragma pack ()
|
---|
226 |
|
---|
227 | #endif // _VIRTIO_GPU_H_
|
---|