]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioGpuDxe/VirtioGpu.h
OvmfPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / OvmfPkg / VirtioGpuDxe / VirtioGpu.h
CommitLineData
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
b26f0cf9 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a2a4fa66
LE
8\r
9**/\r
10\r
11#ifndef _VIRTIO_GPU_DXE_H_\r
12#define _VIRTIO_GPU_DXE_H_\r
13\r
a66ea3b5 14#include <IndustryStandard/VirtioGpu.h>\r
5c8f091b 15#include <Library/BaseMemoryLib.h>\r
a2a4fa66
LE
16#include <Library/DebugLib.h>\r
17#include <Library/UefiLib.h>\r
8731debe 18#include <Protocol/GraphicsOutput.h>\r
a2a4fa66
LE
19#include <Protocol/VirtioDevice.h>\r
20\r
21//\r
22// Forward declaration of VGPU_GOP.\r
23//\r
24typedef struct VGPU_GOP_STRUCT VGPU_GOP;\r
25\r
26//\r
27// The abstraction that directly corresponds to a Virtio GPU device.\r
28//\r
29// This structure will be installed on the handle that has the VirtIo Device\r
30// Protocol interface, with GUID gEfiCallerIdGuid. A similar trick is employed\r
31// in TerminalDxe, and it is necessary so that we can look up VGPU_DEV just\r
32// from the VirtIo Device Protocol handle in the Component Name 2 Protocol\r
33// implementation.\r
34//\r
35typedef struct {\r
36 //\r
37 // VirtIo represents access to the Virtio GPU device. Never NULL.\r
38 //\r
39 VIRTIO_DEVICE_PROTOCOL *VirtIo;\r
40\r
41 //\r
42 // BusName carries a customized name for\r
43 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table\r
44 // form because it can theoretically support several languages. Never NULL.\r
45 //\r
46 EFI_UNICODE_STRING_TABLE *BusName;\r
47\r
c5f235bb
LE
48 //\r
49 // VirtIo ring used for VirtIo communication.\r
50 //\r
51 VRING Ring;\r
52\r
9bc5026c
LE
53 //\r
54 // Token associated with Ring's mapping for bus master common buffer\r
55 // operation, from VirtioRingMap().\r
56 //\r
57 VOID *RingMap;\r
58\r
c5f235bb
LE
59 //\r
60 // Event to be signaled at ExitBootServices().\r
61 //\r
62 EFI_EVENT ExitBoot;\r
63\r
a66ea3b5
LE
64 //\r
65 // Common running counter for all VirtIo GPU requests that ask for fencing.\r
66 //\r
67 UINT64 FenceId;\r
68\r
a2a4fa66
LE
69 //\r
70 // The Child field references the GOP wrapper structure. If this pointer is\r
71 // NULL, then the hybrid driver has bound (i.e., started) the\r
72 // VIRTIO_DEVICE_PROTOCOL controller without producing the child GOP\r
73 // controller (that is, after Start() was called with RemainingDevicePath\r
74 // pointing to and End of Device Path node). Child can be created and\r
75 // destroyed, even repeatedly, independently of VGPU_DEV.\r
76 //\r
77 // In practice, this field represents the single head (scanout) that we\r
78 // support.\r
79 //\r
80 VGPU_GOP *Child;\r
81} VGPU_DEV;\r
82\r
83//\r
84// The Graphics Output Protocol wrapper structure.\r
85//\r
86#define VGPU_GOP_SIG SIGNATURE_64 ('V', 'G', 'P', 'U', '_', 'G', 'O', 'P')\r
87\r
88struct VGPU_GOP_STRUCT {\r
89 UINT64 Signature;\r
90\r
91 //\r
92 // ParentBus points to the parent VGPU_DEV object. Never NULL.\r
93 //\r
94 VGPU_DEV *ParentBus;\r
95\r
96 //\r
97 // GopName carries a customized name for\r
98 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table\r
99 // form because it can theoretically support several languages. Never NULL.\r
100 //\r
101 EFI_UNICODE_STRING_TABLE *GopName;\r
102\r
103 //\r
104 // GopHandle is the UEFI child handle that carries the device path ending\r
105 // with the ACPI ADR node, and the Graphics Output Protocol. Never NULL.\r
106 //\r
107 EFI_HANDLE GopHandle;\r
108\r
109 //\r
110 // The GopDevicePath field is the device path installed on GopHandle,\r
111 // ending with an ACPI ADR node. Never NULL.\r
112 //\r
113 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;\r
114\r
115 //\r
116 // The Gop field is installed on the child handle as Graphics Output Protocol\r
117 // interface.\r
118 //\r
8731debe
LE
119 EFI_GRAPHICS_OUTPUT_PROTOCOL Gop;\r
120\r
121 //\r
122 // Referenced by Gop.Mode, GopMode provides a summary about the supported\r
123 // graphics modes, and the current mode.\r
124 //\r
125 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GopMode;\r
126\r
127 //\r
128 // Referenced by GopMode.Info, GopModeInfo provides detailed information\r
129 // about the current mode.\r
130 //\r
131 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION GopModeInfo;\r
132\r
133 //\r
134 // Identifier of the 2D host resource that is in use by this head (scanout)\r
135 // of the VirtIo GPU device. Zero until the first successful -- internal --\r
136 // Gop.SetMode() call, never zero afterwards.\r
137 //\r
138 UINT32 ResourceId;\r
139\r
a2a4fa66 140 //\r
8731debe
LE
141 // A number of whole pages providing the backing store for the 2D host\r
142 // resource identified by ResourceId above. NULL until the first successful\r
143 // -- internal -- Gop.SetMode() call, never NULL afterwards.\r
144 //\r
145 UINT32 *BackingStore;\r
146 UINTN NumberOfPages;\r
f10ae923
LE
147\r
148 //\r
149 // Token associated with BackingStore's mapping for bus master common\r
150 // buffer operation. BackingStoreMap is valid if, and only if,\r
151 // BackingStore is non-NULL.\r
152 //\r
153 VOID *BackingStoreMap;\r
a2a4fa66
LE
154};\r
155\r
c5f235bb
LE
156//\r
157// VirtIo GPU initialization, and commands (primitives) for the GPU device.\r
158//\r
159/**\r
160 Configure the VirtIo GPU device that underlies VgpuDev.\r
161\r
162 @param[in,out] VgpuDev The VGPU_DEV object to set up VirtIo messaging for.\r
163 On input, the caller is responsible for having\r
164 initialized VgpuDev->VirtIo. On output, VgpuDev->Ring\r
165 has been initialized, and synchronous VirtIo GPU\r
166 commands (primitives) can be submitted to the device.\r
167\r
168 @retval EFI_SUCCESS VirtIo GPU configuration successful.\r
169\r
170 @retval EFI_UNSUPPORTED The host-side configuration of the VirtIo GPU is not\r
171 supported by this driver.\r
172\r
173 @retval Error codes from underlying functions.\r
174**/\r
175EFI_STATUS\r
176VirtioGpuInit (\r
177 IN OUT VGPU_DEV *VgpuDev\r
178 );\r
179\r
180/**\r
181 De-configure the VirtIo GPU device that underlies VgpuDev.\r
182\r
183 @param[in,out] VgpuDev The VGPU_DEV object to tear down VirtIo messaging\r
184 for. On input, the caller is responsible for having\r
185 called VirtioGpuInit(). On output, VgpuDev->Ring has\r
186 been uninitialized; VirtIo GPU commands (primitives)\r
187 can no longer be submitted to the device.\r
188**/\r
189VOID\r
190VirtioGpuUninit (\r
191 IN OUT VGPU_DEV *VgpuDev\r
192 );\r
193\r
5c8f091b
LE
194/**\r
195 Allocate, zero and map memory, for bus master common buffer operation, to be\r
196 attached as backing store to a host-side VirtIo GPU resource.\r
197\r
198 @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
199 device.\r
200\r
201 @param[in] NumberOfPages The number of whole pages to allocate and map.\r
202\r
203 @param[out] HostAddress The system memory address of the allocated area.\r
204\r
205 @param[out] DeviceAddress The bus master device address of the allocated\r
206 area. The VirtIo GPU device may be programmed to\r
207 access the allocated area through DeviceAddress;\r
208 DeviceAddress is to be passed to the\r
209 VirtioGpuResourceAttachBacking() function, as the\r
210 BackingStoreDeviceAddress parameter.\r
211\r
212 @param[out] Mapping A resulting token to pass to\r
213 VirtioGpuUnmapAndFreeBackingStore().\r
214\r
215 @retval EFI_SUCCESS The requested number of pages has been allocated, zeroed\r
216 and mapped.\r
217\r
218 @return Status codes propagated from\r
219 VgpuDev->VirtIo->AllocateSharedPages() and\r
220 VirtioMapAllBytesInSharedBuffer().\r
221**/\r
222EFI_STATUS\r
223VirtioGpuAllocateZeroAndMapBackingStore (\r
224 IN VGPU_DEV *VgpuDev,\r
225 IN UINTN NumberOfPages,\r
226 OUT VOID **HostAddress,\r
227 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
228 OUT VOID **Mapping\r
229 );\r
230\r
231/**\r
232 Unmap and free memory originally allocated and mapped with\r
233 VirtioGpuAllocateZeroAndMapBackingStore().\r
234\r
235 If the memory allocated and mapped with\r
236 VirtioGpuAllocateZeroAndMapBackingStore() was attached to a host-side VirtIo\r
237 GPU resource with VirtioGpuResourceAttachBacking(), then the caller is\r
238 responsible for detaching the backing store from the same resource, with\r
239 VirtioGpuResourceDetachBacking(), before calling this function.\r
240\r
241 @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
242 device.\r
243\r
244 @param[in] NumberOfPages The NumberOfPages parameter originally passed to\r
245 VirtioGpuAllocateZeroAndMapBackingStore().\r
246\r
247 @param[in] HostAddress The HostAddress value originally output by\r
248 VirtioGpuAllocateZeroAndMapBackingStore().\r
249\r
250 @param[in] Mapping The token that was originally output by\r
251 VirtioGpuAllocateZeroAndMapBackingStore().\r
252**/\r
253VOID\r
254VirtioGpuUnmapAndFreeBackingStore (\r
255 IN VGPU_DEV *VgpuDev,\r
256 IN UINTN NumberOfPages,\r
257 IN VOID *HostAddress,\r
258 IN VOID *Mapping\r
259 );\r
260\r
c5f235bb
LE
261/**\r
262 EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the\r
263 VirtIo device, causing it to release its resources and to forget its\r
264 configuration.\r
265\r
266 This function may only be called (that is, VGPU_DEV.ExitBoot may only be\r
267 signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is\r
268 called.\r
269\r
270 @param[in] Event Event whose notification function is being invoked.\r
271\r
272 @param[in] Context Pointer to the associated VGPU_DEV object.\r
273**/\r
274VOID\r
275EFIAPI\r
276VirtioGpuExitBoot (\r
277 IN EFI_EVENT Event,\r
278 IN VOID *Context\r
279 );\r
280\r
a66ea3b5
LE
281/**\r
282 The following functions send requests to the VirtIo GPU device model, await\r
283 the answer from the host, and return a status. They share the following\r
284 interface details:\r
285\r
286 @param[in,out] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
287 device. The caller is responsible to have\r
288 successfully invoked VirtioGpuInit() on VgpuDev\r
289 previously, while VirtioGpuUninit() must not have\r
290 been called on VgpuDev.\r
291\r
292 @retval EFI_INVALID_PARAMETER Invalid command-specific parameters were\r
293 detected by this driver.\r
294\r
295 @retval EFI_SUCCESS Operation successful.\r
296\r
297 @retval EFI_DEVICE_ERROR The host rejected the request. The host error\r
298 code has been logged on the EFI_D_ERROR level.\r
299\r
300 @return Codes for unexpected errors in VirtIo\r
301 messaging.\r
302\r
303 For the command-specific parameters, please consult the GPU Device section of\r
304 the VirtIo 1.0 specification (see references in\r
305 "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").\r
306**/\r
307EFI_STATUS\r
308VirtioGpuResourceCreate2d (\r
309 IN OUT VGPU_DEV *VgpuDev,\r
310 IN UINT32 ResourceId,\r
311 IN VIRTIO_GPU_FORMATS Format,\r
312 IN UINT32 Width,\r
313 IN UINT32 Height\r
314 );\r
315\r
316EFI_STATUS\r
317VirtioGpuResourceUnref (\r
318 IN OUT VGPU_DEV *VgpuDev,\r
319 IN UINT32 ResourceId\r
320 );\r
321\r
322EFI_STATUS\r
323VirtioGpuResourceAttachBacking (\r
5409c6ab
LE
324 IN OUT VGPU_DEV *VgpuDev,\r
325 IN UINT32 ResourceId,\r
326 IN EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress,\r
327 IN UINTN NumberOfPages\r
a66ea3b5
LE
328 );\r
329\r
330EFI_STATUS\r
331VirtioGpuResourceDetachBacking (\r
332 IN OUT VGPU_DEV *VgpuDev,\r
333 IN UINT32 ResourceId\r
334 );\r
335\r
336EFI_STATUS\r
337VirtioGpuSetScanout (\r
338 IN OUT VGPU_DEV *VgpuDev,\r
339 IN UINT32 X,\r
340 IN UINT32 Y,\r
341 IN UINT32 Width,\r
342 IN UINT32 Height,\r
343 IN UINT32 ScanoutId,\r
344 IN UINT32 ResourceId\r
345 );\r
346\r
347EFI_STATUS\r
348VirtioGpuTransferToHost2d (\r
349 IN OUT VGPU_DEV *VgpuDev,\r
350 IN UINT32 X,\r
351 IN UINT32 Y,\r
352 IN UINT32 Width,\r
353 IN UINT32 Height,\r
354 IN UINT64 Offset,\r
355 IN UINT32 ResourceId\r
356 );\r
357\r
358EFI_STATUS\r
359VirtioGpuResourceFlush (\r
360 IN OUT VGPU_DEV *VgpuDev,\r
361 IN UINT32 X,\r
362 IN UINT32 Y,\r
363 IN UINT32 Width,\r
364 IN UINT32 Height,\r
365 IN UINT32 ResourceId\r
366 );\r
367\r
8731debe
LE
368/**\r
369 Release guest-side and host-side resources that are related to an initialized\r
370 VGPU_GOP.Gop.\r
371\r
372 param[in,out] VgpuGop The VGPU_GOP object to release resources for.\r
373\r
374 On input, the caller is responsible for having called\r
375 VgpuGop->Gop.SetMode() at least once successfully.\r
376 (This is equivalent to the requirement that\r
377 VgpuGop->BackingStore be non-NULL. It is also\r
378 equivalent to the requirement that VgpuGop->ResourceId\r
379 be nonzero.)\r
380\r
381 On output, resources will be released, and\r
382 VgpuGop->BackingStore and VgpuGop->ResourceId will be\r
383 nulled.\r
384\r
385 param[in] DisableHead Whether this head (scanout) currently references the\r
386 resource identified by VgpuGop->ResourceId. Only pass\r
387 FALSE when VgpuGop->Gop.SetMode() calls this function\r
388 while switching between modes, and set it to TRUE\r
389 every other time.\r
390**/\r
391VOID\r
392ReleaseGopResources (\r
393 IN OUT VGPU_GOP *VgpuGop,\r
394 IN BOOLEAN DisableHead\r
395 );\r
396\r
397//\r
398// Template for initializing VGPU_GOP.Gop.\r
399//\r
400extern CONST EFI_GRAPHICS_OUTPUT_PROTOCOL mGopTemplate;\r
401\r
a2a4fa66 402#endif // _VIRTIO_GPU_DXE_H_\r