]>
Commit | Line | Data |
---|---|---|
a2a4fa66 LE |
1 | /** @file\r |
2 | \r | |
3 | Internal type and macro definitions for the Virtio GPU hybrid driver.\r | |
4 | \r | |
5 | Copyright (C) 2016, Red Hat, Inc.\r | |
6 | \r | |
7 | This program and the accompanying materials are licensed and made available\r | |
8 | under the terms and conditions of the BSD License which accompanies this\r | |
9 | distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r | |
13 | WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef _VIRTIO_GPU_DXE_H_\r | |
18 | #define _VIRTIO_GPU_DXE_H_\r | |
19 | \r | |
a66ea3b5 | 20 | #include <IndustryStandard/VirtioGpu.h>\r |
a2a4fa66 LE |
21 | #include <Library/DebugLib.h>\r |
22 | #include <Library/UefiLib.h>\r | |
8731debe | 23 | #include <Protocol/GraphicsOutput.h>\r |
a2a4fa66 LE |
24 | #include <Protocol/VirtioDevice.h>\r |
25 | \r | |
26 | //\r | |
27 | // Forward declaration of VGPU_GOP.\r | |
28 | //\r | |
29 | typedef struct VGPU_GOP_STRUCT VGPU_GOP;\r | |
30 | \r | |
31 | //\r | |
32 | // The abstraction that directly corresponds to a Virtio GPU device.\r | |
33 | //\r | |
34 | // This structure will be installed on the handle that has the VirtIo Device\r | |
35 | // Protocol interface, with GUID gEfiCallerIdGuid. A similar trick is employed\r | |
36 | // in TerminalDxe, and it is necessary so that we can look up VGPU_DEV just\r | |
37 | // from the VirtIo Device Protocol handle in the Component Name 2 Protocol\r | |
38 | // implementation.\r | |
39 | //\r | |
40 | typedef struct {\r | |
41 | //\r | |
42 | // VirtIo represents access to the Virtio GPU device. Never NULL.\r | |
43 | //\r | |
44 | VIRTIO_DEVICE_PROTOCOL *VirtIo;\r | |
45 | \r | |
46 | //\r | |
47 | // BusName carries a customized name for\r | |
48 | // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table\r | |
49 | // form because it can theoretically support several languages. Never NULL.\r | |
50 | //\r | |
51 | EFI_UNICODE_STRING_TABLE *BusName;\r | |
52 | \r | |
c5f235bb LE |
53 | //\r |
54 | // VirtIo ring used for VirtIo communication.\r | |
55 | //\r | |
56 | VRING Ring;\r | |
57 | \r | |
58 | //\r | |
59 | // Event to be signaled at ExitBootServices().\r | |
60 | //\r | |
61 | EFI_EVENT ExitBoot;\r | |
62 | \r | |
a66ea3b5 LE |
63 | //\r |
64 | // Common running counter for all VirtIo GPU requests that ask for fencing.\r | |
65 | //\r | |
66 | UINT64 FenceId;\r | |
67 | \r | |
a2a4fa66 LE |
68 | //\r |
69 | // The Child field references the GOP wrapper structure. If this pointer is\r | |
70 | // NULL, then the hybrid driver has bound (i.e., started) the\r | |
71 | // VIRTIO_DEVICE_PROTOCOL controller without producing the child GOP\r | |
72 | // controller (that is, after Start() was called with RemainingDevicePath\r | |
73 | // pointing to and End of Device Path node). Child can be created and\r | |
74 | // destroyed, even repeatedly, independently of VGPU_DEV.\r | |
75 | //\r | |
76 | // In practice, this field represents the single head (scanout) that we\r | |
77 | // support.\r | |
78 | //\r | |
79 | VGPU_GOP *Child;\r | |
80 | } VGPU_DEV;\r | |
81 | \r | |
82 | //\r | |
83 | // The Graphics Output Protocol wrapper structure.\r | |
84 | //\r | |
85 | #define VGPU_GOP_SIG SIGNATURE_64 ('V', 'G', 'P', 'U', '_', 'G', 'O', 'P')\r | |
86 | \r | |
87 | struct VGPU_GOP_STRUCT {\r | |
88 | UINT64 Signature;\r | |
89 | \r | |
90 | //\r | |
91 | // ParentBus points to the parent VGPU_DEV object. Never NULL.\r | |
92 | //\r | |
93 | VGPU_DEV *ParentBus;\r | |
94 | \r | |
95 | //\r | |
96 | // GopName carries a customized name for\r | |
97 | // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table\r | |
98 | // form because it can theoretically support several languages. Never NULL.\r | |
99 | //\r | |
100 | EFI_UNICODE_STRING_TABLE *GopName;\r | |
101 | \r | |
102 | //\r | |
103 | // GopHandle is the UEFI child handle that carries the device path ending\r | |
104 | // with the ACPI ADR node, and the Graphics Output Protocol. Never NULL.\r | |
105 | //\r | |
106 | EFI_HANDLE GopHandle;\r | |
107 | \r | |
108 | //\r | |
109 | // The GopDevicePath field is the device path installed on GopHandle,\r | |
110 | // ending with an ACPI ADR node. Never NULL.\r | |
111 | //\r | |
112 | EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;\r | |
113 | \r | |
114 | //\r | |
115 | // The Gop field is installed on the child handle as Graphics Output Protocol\r | |
116 | // interface.\r | |
117 | //\r | |
8731debe LE |
118 | EFI_GRAPHICS_OUTPUT_PROTOCOL Gop;\r |
119 | \r | |
120 | //\r | |
121 | // Referenced by Gop.Mode, GopMode provides a summary about the supported\r | |
122 | // graphics modes, and the current mode.\r | |
123 | //\r | |
124 | EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GopMode;\r | |
125 | \r | |
126 | //\r | |
127 | // Referenced by GopMode.Info, GopModeInfo provides detailed information\r | |
128 | // about the current mode.\r | |
129 | //\r | |
130 | EFI_GRAPHICS_OUTPUT_MODE_INFORMATION GopModeInfo;\r | |
131 | \r | |
132 | //\r | |
133 | // Identifier of the 2D host resource that is in use by this head (scanout)\r | |
134 | // of the VirtIo GPU device. Zero until the first successful -- internal --\r | |
135 | // Gop.SetMode() call, never zero afterwards.\r | |
136 | //\r | |
137 | UINT32 ResourceId;\r | |
138 | \r | |
a2a4fa66 | 139 | //\r |
8731debe LE |
140 | // A number of whole pages providing the backing store for the 2D host\r |
141 | // resource identified by ResourceId above. NULL until the first successful\r | |
142 | // -- internal -- Gop.SetMode() call, never NULL afterwards.\r | |
143 | //\r | |
144 | UINT32 *BackingStore;\r | |
145 | UINTN NumberOfPages;\r | |
a2a4fa66 LE |
146 | };\r |
147 | \r | |
c5f235bb LE |
148 | //\r |
149 | // VirtIo GPU initialization, and commands (primitives) for the GPU device.\r | |
150 | //\r | |
151 | /**\r | |
152 | Configure the VirtIo GPU device that underlies VgpuDev.\r | |
153 | \r | |
154 | @param[in,out] VgpuDev The VGPU_DEV object to set up VirtIo messaging for.\r | |
155 | On input, the caller is responsible for having\r | |
156 | initialized VgpuDev->VirtIo. On output, VgpuDev->Ring\r | |
157 | has been initialized, and synchronous VirtIo GPU\r | |
158 | commands (primitives) can be submitted to the device.\r | |
159 | \r | |
160 | @retval EFI_SUCCESS VirtIo GPU configuration successful.\r | |
161 | \r | |
162 | @retval EFI_UNSUPPORTED The host-side configuration of the VirtIo GPU is not\r | |
163 | supported by this driver.\r | |
164 | \r | |
165 | @retval Error codes from underlying functions.\r | |
166 | **/\r | |
167 | EFI_STATUS\r | |
168 | VirtioGpuInit (\r | |
169 | IN OUT VGPU_DEV *VgpuDev\r | |
170 | );\r | |
171 | \r | |
172 | /**\r | |
173 | De-configure the VirtIo GPU device that underlies VgpuDev.\r | |
174 | \r | |
175 | @param[in,out] VgpuDev The VGPU_DEV object to tear down VirtIo messaging\r | |
176 | for. On input, the caller is responsible for having\r | |
177 | called VirtioGpuInit(). On output, VgpuDev->Ring has\r | |
178 | been uninitialized; VirtIo GPU commands (primitives)\r | |
179 | can no longer be submitted to the device.\r | |
180 | **/\r | |
181 | VOID\r | |
182 | VirtioGpuUninit (\r | |
183 | IN OUT VGPU_DEV *VgpuDev\r | |
184 | );\r | |
185 | \r | |
186 | /**\r | |
187 | EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the\r | |
188 | VirtIo device, causing it to release its resources and to forget its\r | |
189 | configuration.\r | |
190 | \r | |
191 | This function may only be called (that is, VGPU_DEV.ExitBoot may only be\r | |
192 | signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is\r | |
193 | called.\r | |
194 | \r | |
195 | @param[in] Event Event whose notification function is being invoked.\r | |
196 | \r | |
197 | @param[in] Context Pointer to the associated VGPU_DEV object.\r | |
198 | **/\r | |
199 | VOID\r | |
200 | EFIAPI\r | |
201 | VirtioGpuExitBoot (\r | |
202 | IN EFI_EVENT Event,\r | |
203 | IN VOID *Context\r | |
204 | );\r | |
205 | \r | |
a66ea3b5 LE |
206 | /**\r |
207 | The following functions send requests to the VirtIo GPU device model, await\r | |
208 | the answer from the host, and return a status. They share the following\r | |
209 | interface details:\r | |
210 | \r | |
211 | @param[in,out] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r | |
212 | device. The caller is responsible to have\r | |
213 | successfully invoked VirtioGpuInit() on VgpuDev\r | |
214 | previously, while VirtioGpuUninit() must not have\r | |
215 | been called on VgpuDev.\r | |
216 | \r | |
217 | @retval EFI_INVALID_PARAMETER Invalid command-specific parameters were\r | |
218 | detected by this driver.\r | |
219 | \r | |
220 | @retval EFI_SUCCESS Operation successful.\r | |
221 | \r | |
222 | @retval EFI_DEVICE_ERROR The host rejected the request. The host error\r | |
223 | code has been logged on the EFI_D_ERROR level.\r | |
224 | \r | |
225 | @return Codes for unexpected errors in VirtIo\r | |
226 | messaging.\r | |
227 | \r | |
228 | For the command-specific parameters, please consult the GPU Device section of\r | |
229 | the VirtIo 1.0 specification (see references in\r | |
230 | "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").\r | |
231 | **/\r | |
232 | EFI_STATUS\r | |
233 | VirtioGpuResourceCreate2d (\r | |
234 | IN OUT VGPU_DEV *VgpuDev,\r | |
235 | IN UINT32 ResourceId,\r | |
236 | IN VIRTIO_GPU_FORMATS Format,\r | |
237 | IN UINT32 Width,\r | |
238 | IN UINT32 Height\r | |
239 | );\r | |
240 | \r | |
241 | EFI_STATUS\r | |
242 | VirtioGpuResourceUnref (\r | |
243 | IN OUT VGPU_DEV *VgpuDev,\r | |
244 | IN UINT32 ResourceId\r | |
245 | );\r | |
246 | \r | |
247 | EFI_STATUS\r | |
248 | VirtioGpuResourceAttachBacking (\r | |
249 | IN OUT VGPU_DEV *VgpuDev,\r | |
250 | IN UINT32 ResourceId,\r | |
251 | IN VOID *FirstBackingPage,\r | |
252 | IN UINTN NumberOfPages\r | |
253 | );\r | |
254 | \r | |
255 | EFI_STATUS\r | |
256 | VirtioGpuResourceDetachBacking (\r | |
257 | IN OUT VGPU_DEV *VgpuDev,\r | |
258 | IN UINT32 ResourceId\r | |
259 | );\r | |
260 | \r | |
261 | EFI_STATUS\r | |
262 | VirtioGpuSetScanout (\r | |
263 | IN OUT VGPU_DEV *VgpuDev,\r | |
264 | IN UINT32 X,\r | |
265 | IN UINT32 Y,\r | |
266 | IN UINT32 Width,\r | |
267 | IN UINT32 Height,\r | |
268 | IN UINT32 ScanoutId,\r | |
269 | IN UINT32 ResourceId\r | |
270 | );\r | |
271 | \r | |
272 | EFI_STATUS\r | |
273 | VirtioGpuTransferToHost2d (\r | |
274 | IN OUT VGPU_DEV *VgpuDev,\r | |
275 | IN UINT32 X,\r | |
276 | IN UINT32 Y,\r | |
277 | IN UINT32 Width,\r | |
278 | IN UINT32 Height,\r | |
279 | IN UINT64 Offset,\r | |
280 | IN UINT32 ResourceId\r | |
281 | );\r | |
282 | \r | |
283 | EFI_STATUS\r | |
284 | VirtioGpuResourceFlush (\r | |
285 | IN OUT VGPU_DEV *VgpuDev,\r | |
286 | IN UINT32 X,\r | |
287 | IN UINT32 Y,\r | |
288 | IN UINT32 Width,\r | |
289 | IN UINT32 Height,\r | |
290 | IN UINT32 ResourceId\r | |
291 | );\r | |
292 | \r | |
8731debe LE |
293 | /**\r |
294 | Release guest-side and host-side resources that are related to an initialized\r | |
295 | VGPU_GOP.Gop.\r | |
296 | \r | |
297 | param[in,out] VgpuGop The VGPU_GOP object to release resources for.\r | |
298 | \r | |
299 | On input, the caller is responsible for having called\r | |
300 | VgpuGop->Gop.SetMode() at least once successfully.\r | |
301 | (This is equivalent to the requirement that\r | |
302 | VgpuGop->BackingStore be non-NULL. It is also\r | |
303 | equivalent to the requirement that VgpuGop->ResourceId\r | |
304 | be nonzero.)\r | |
305 | \r | |
306 | On output, resources will be released, and\r | |
307 | VgpuGop->BackingStore and VgpuGop->ResourceId will be\r | |
308 | nulled.\r | |
309 | \r | |
310 | param[in] DisableHead Whether this head (scanout) currently references the\r | |
311 | resource identified by VgpuGop->ResourceId. Only pass\r | |
312 | FALSE when VgpuGop->Gop.SetMode() calls this function\r | |
313 | while switching between modes, and set it to TRUE\r | |
314 | every other time.\r | |
315 | **/\r | |
316 | VOID\r | |
317 | ReleaseGopResources (\r | |
318 | IN OUT VGPU_GOP *VgpuGop,\r | |
319 | IN BOOLEAN DisableHead\r | |
320 | );\r | |
321 | \r | |
322 | //\r | |
323 | // Template for initializing VGPU_GOP.Gop.\r | |
324 | //\r | |
325 | extern CONST EFI_GRAPHICS_OUTPUT_PROTOCOL mGopTemplate;\r | |
326 | \r | |
a2a4fa66 | 327 | #endif // _VIRTIO_GPU_DXE_H_\r |