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