3 Internal type and macro definitions for the Virtio GPU hybrid driver.
5 Copyright (C) 2016, Red Hat, Inc.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _VIRTIO_GPU_DXE_H_
12 #define _VIRTIO_GPU_DXE_H_
14 #include <IndustryStandard/VirtioGpu.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/UefiLib.h>
18 #include <Protocol/GraphicsOutput.h>
19 #include <Protocol/VirtioDevice.h>
22 // Forward declaration of VGPU_GOP.
24 typedef struct VGPU_GOP_STRUCT VGPU_GOP
;
27 // The abstraction that directly corresponds to a Virtio GPU device.
29 // This structure will be installed on the handle that has the VirtIo Device
30 // Protocol interface, with GUID gEfiCallerIdGuid. A similar trick is employed
31 // in TerminalDxe, and it is necessary so that we can look up VGPU_DEV just
32 // from the VirtIo Device Protocol handle in the Component Name 2 Protocol
37 // VirtIo represents access to the Virtio GPU device. Never NULL.
39 VIRTIO_DEVICE_PROTOCOL
*VirtIo
;
42 // BusName carries a customized name for
43 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table
44 // form because it can theoretically support several languages. Never NULL.
46 EFI_UNICODE_STRING_TABLE
*BusName
;
49 // VirtIo ring used for VirtIo communication.
54 // Token associated with Ring's mapping for bus master common buffer
55 // operation, from VirtioRingMap().
60 // Event to be signaled at ExitBootServices().
65 // Common running counter for all VirtIo GPU requests that ask for fencing.
70 // The Child field references the GOP wrapper structure. If this pointer is
71 // NULL, then the hybrid driver has bound (i.e., started) the
72 // VIRTIO_DEVICE_PROTOCOL controller without producing the child GOP
73 // controller (that is, after Start() was called with RemainingDevicePath
74 // pointing to and End of Device Path node). Child can be created and
75 // destroyed, even repeatedly, independently of VGPU_DEV.
77 // In practice, this field represents the single head (scanout) that we
84 // The Graphics Output Protocol wrapper structure.
86 #define VGPU_GOP_SIG SIGNATURE_64 ('V', 'G', 'P', 'U', '_', 'G', 'O', 'P')
88 struct VGPU_GOP_STRUCT
{
92 // ParentBus points to the parent VGPU_DEV object. Never NULL.
97 // GopName carries a customized name for
98 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table
99 // form because it can theoretically support several languages. Never NULL.
101 EFI_UNICODE_STRING_TABLE
*GopName
;
104 // GopHandle is the UEFI child handle that carries the device path ending
105 // with the ACPI ADR node, and the Graphics Output Protocol. Never NULL.
107 EFI_HANDLE GopHandle
;
110 // The GopDevicePath field is the device path installed on GopHandle,
111 // ending with an ACPI ADR node. Never NULL.
113 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
116 // The Gop field is installed on the child handle as Graphics Output Protocol
119 EFI_GRAPHICS_OUTPUT_PROTOCOL Gop
;
122 // Referenced by Gop.Mode, GopMode provides a summary about the supported
123 // graphics modes, and the current mode.
125 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GopMode
;
128 // Referenced by GopMode.Info, GopModeInfo provides detailed information
129 // about the current mode.
131 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION GopModeInfo
;
134 // Identifier of the 2D host resource that is in use by this head (scanout)
135 // of the VirtIo GPU device. Zero until the first successful -- internal --
136 // Gop.SetMode() call, never zero afterwards.
141 // A number of whole pages providing the backing store for the 2D host
142 // resource identified by ResourceId above. NULL until the first successful
143 // -- internal -- Gop.SetMode() call, never NULL afterwards.
145 UINT32
*BackingStore
;
149 // Token associated with BackingStore's mapping for bus master common
150 // buffer operation. BackingStoreMap is valid if, and only if,
151 // BackingStore is non-NULL.
153 VOID
*BackingStoreMap
;
156 // native display resolution
163 // VirtIo GPU initialization, and commands (primitives) for the GPU device.
167 Configure the VirtIo GPU device that underlies VgpuDev.
169 @param[in,out] VgpuDev The VGPU_DEV object to set up VirtIo messaging for.
170 On input, the caller is responsible for having
171 initialized VgpuDev->VirtIo. On output, VgpuDev->Ring
172 has been initialized, and synchronous VirtIo GPU
173 commands (primitives) can be submitted to the device.
175 @retval EFI_SUCCESS VirtIo GPU configuration successful.
177 @retval EFI_UNSUPPORTED The host-side configuration of the VirtIo GPU is not
178 supported by this driver.
180 @retval Error codes from underlying functions.
184 IN OUT VGPU_DEV
*VgpuDev
188 De-configure the VirtIo GPU device that underlies VgpuDev.
190 @param[in,out] VgpuDev The VGPU_DEV object to tear down VirtIo messaging
191 for. On input, the caller is responsible for having
192 called VirtioGpuInit(). On output, VgpuDev->Ring has
193 been uninitialized; VirtIo GPU commands (primitives)
194 can no longer be submitted to the device.
198 IN OUT VGPU_DEV
*VgpuDev
202 Allocate, zero and map memory, for bus master common buffer operation, to be
203 attached as backing store to a host-side VirtIo GPU resource.
205 @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU
208 @param[in] NumberOfPages The number of whole pages to allocate and map.
210 @param[out] HostAddress The system memory address of the allocated area.
212 @param[out] DeviceAddress The bus master device address of the allocated
213 area. The VirtIo GPU device may be programmed to
214 access the allocated area through DeviceAddress;
215 DeviceAddress is to be passed to the
216 VirtioGpuResourceAttachBacking() function, as the
217 BackingStoreDeviceAddress parameter.
219 @param[out] Mapping A resulting token to pass to
220 VirtioGpuUnmapAndFreeBackingStore().
222 @retval EFI_SUCCESS The requested number of pages has been allocated, zeroed
225 @return Status codes propagated from
226 VgpuDev->VirtIo->AllocateSharedPages() and
227 VirtioMapAllBytesInSharedBuffer().
230 VirtioGpuAllocateZeroAndMapBackingStore (
231 IN VGPU_DEV
*VgpuDev
,
232 IN UINTN NumberOfPages
,
233 OUT VOID
**HostAddress
,
234 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
239 Unmap and free memory originally allocated and mapped with
240 VirtioGpuAllocateZeroAndMapBackingStore().
242 If the memory allocated and mapped with
243 VirtioGpuAllocateZeroAndMapBackingStore() was attached to a host-side VirtIo
244 GPU resource with VirtioGpuResourceAttachBacking(), then the caller is
245 responsible for detaching the backing store from the same resource, with
246 VirtioGpuResourceDetachBacking(), before calling this function.
248 @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU
251 @param[in] NumberOfPages The NumberOfPages parameter originally passed to
252 VirtioGpuAllocateZeroAndMapBackingStore().
254 @param[in] HostAddress The HostAddress value originally output by
255 VirtioGpuAllocateZeroAndMapBackingStore().
257 @param[in] Mapping The token that was originally output by
258 VirtioGpuAllocateZeroAndMapBackingStore().
261 VirtioGpuUnmapAndFreeBackingStore (
262 IN VGPU_DEV
*VgpuDev
,
263 IN UINTN NumberOfPages
,
264 IN VOID
*HostAddress
,
269 EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the
270 VirtIo device, causing it to release its resources and to forget its
273 This function may only be called (that is, VGPU_DEV.ExitBoot may only be
274 signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is
277 @param[in] Event Event whose notification function is being invoked.
279 @param[in] Context Pointer to the associated VGPU_DEV object.
289 The following functions send requests to the VirtIo GPU device model, await
290 the answer from the host, and return a status. They share the following
293 @param[in,out] VgpuDev The VGPU_DEV object that represents the VirtIo GPU
294 device. The caller is responsible to have
295 successfully invoked VirtioGpuInit() on VgpuDev
296 previously, while VirtioGpuUninit() must not have
297 been called on VgpuDev.
299 @retval EFI_INVALID_PARAMETER Invalid command-specific parameters were
300 detected by this driver.
302 @retval EFI_SUCCESS Operation successful.
304 @retval EFI_DEVICE_ERROR The host rejected the request. The host error
305 code has been logged on the DEBUG_ERROR level.
307 @return Codes for unexpected errors in VirtIo
310 For the command-specific parameters, please consult the GPU Device section of
311 the VirtIo 1.0 specification (see references in
312 "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").
315 VirtioGpuResourceCreate2d (
316 IN OUT VGPU_DEV
*VgpuDev
,
317 IN UINT32 ResourceId
,
318 IN VIRTIO_GPU_FORMATS Format
,
324 VirtioGpuResourceUnref (
325 IN OUT VGPU_DEV
*VgpuDev
,
330 VirtioGpuResourceAttachBacking (
331 IN OUT VGPU_DEV
*VgpuDev
,
332 IN UINT32 ResourceId
,
333 IN EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress
,
334 IN UINTN NumberOfPages
338 VirtioGpuResourceDetachBacking (
339 IN OUT VGPU_DEV
*VgpuDev
,
344 VirtioGpuSetScanout (
345 IN OUT VGPU_DEV
*VgpuDev
,
355 VirtioGpuTransferToHost2d (
356 IN OUT VGPU_DEV
*VgpuDev
,
366 VirtioGpuResourceFlush (
367 IN OUT VGPU_DEV
*VgpuDev
,
376 VirtioGpuGetDisplayInfo (
377 IN OUT VGPU_DEV
*VgpuDev
,
378 volatile VIRTIO_GPU_RESP_DISPLAY_INFO
*Response
382 Release guest-side and host-side resources that are related to an initialized
385 param[in,out] VgpuGop The VGPU_GOP object to release resources for.
387 On input, the caller is responsible for having called
388 VgpuGop->Gop.SetMode() at least once successfully.
389 (This is equivalent to the requirement that
390 VgpuGop->BackingStore be non-NULL. It is also
391 equivalent to the requirement that VgpuGop->ResourceId
394 On output, resources will be released, and
395 VgpuGop->BackingStore and VgpuGop->ResourceId will be
398 param[in] DisableHead Whether this head (scanout) currently references the
399 resource identified by VgpuGop->ResourceId. Only pass
400 FALSE when VgpuGop->Gop.SetMode() calls this function
401 while switching between modes, and set it to TRUE
405 ReleaseGopResources (
406 IN OUT VGPU_GOP
*VgpuGop
,
407 IN BOOLEAN DisableHead
411 // Template for initializing VGPU_GOP.Gop.
413 extern CONST EFI_GRAPHICS_OUTPUT_PROTOCOL mGopTemplate
;
415 #endif // _VIRTIO_GPU_DXE_H_