3 Internal type and macro definitions for the Virtio GPU hybrid driver.
5 Copyright (C) 2016, Red Hat, Inc.
7 This program and the accompanying materials are licensed and made available
8 under the terms and conditions of the BSD License which accompanies this
9 distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
13 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef _VIRTIO_GPU_DXE_H_
18 #define _VIRTIO_GPU_DXE_H_
20 #include <IndustryStandard/VirtioGpu.h>
21 #include <Library/DebugLib.h>
22 #include <Library/UefiLib.h>
23 #include <Protocol/GraphicsOutput.h>
24 #include <Protocol/VirtioDevice.h>
27 // Forward declaration of VGPU_GOP.
29 typedef struct VGPU_GOP_STRUCT VGPU_GOP
;
32 // The abstraction that directly corresponds to a Virtio GPU device.
34 // This structure will be installed on the handle that has the VirtIo Device
35 // Protocol interface, with GUID gEfiCallerIdGuid. A similar trick is employed
36 // in TerminalDxe, and it is necessary so that we can look up VGPU_DEV just
37 // from the VirtIo Device Protocol handle in the Component Name 2 Protocol
42 // VirtIo represents access to the Virtio GPU device. Never NULL.
44 VIRTIO_DEVICE_PROTOCOL
*VirtIo
;
47 // BusName carries a customized name for
48 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table
49 // form because it can theoretically support several languages. Never NULL.
51 EFI_UNICODE_STRING_TABLE
*BusName
;
54 // VirtIo ring used for VirtIo communication.
59 // Token associated with Ring's mapping for bus master common buffer
60 // operation, from VirtioRingMap().
65 // Event to be signaled at ExitBootServices().
70 // Common running counter for all VirtIo GPU requests that ask for fencing.
75 // The Child field references the GOP wrapper structure. If this pointer is
76 // NULL, then the hybrid driver has bound (i.e., started) the
77 // VIRTIO_DEVICE_PROTOCOL controller without producing the child GOP
78 // controller (that is, after Start() was called with RemainingDevicePath
79 // pointing to and End of Device Path node). Child can be created and
80 // destroyed, even repeatedly, independently of VGPU_DEV.
82 // In practice, this field represents the single head (scanout) that we
89 // The Graphics Output Protocol wrapper structure.
91 #define VGPU_GOP_SIG SIGNATURE_64 ('V', 'G', 'P', 'U', '_', 'G', 'O', 'P')
93 struct VGPU_GOP_STRUCT
{
97 // ParentBus points to the parent VGPU_DEV object. Never NULL.
102 // GopName carries a customized name for
103 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table
104 // form because it can theoretically support several languages. Never NULL.
106 EFI_UNICODE_STRING_TABLE
*GopName
;
109 // GopHandle is the UEFI child handle that carries the device path ending
110 // with the ACPI ADR node, and the Graphics Output Protocol. Never NULL.
112 EFI_HANDLE GopHandle
;
115 // The GopDevicePath field is the device path installed on GopHandle,
116 // ending with an ACPI ADR node. Never NULL.
118 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
121 // The Gop field is installed on the child handle as Graphics Output Protocol
124 EFI_GRAPHICS_OUTPUT_PROTOCOL Gop
;
127 // Referenced by Gop.Mode, GopMode provides a summary about the supported
128 // graphics modes, and the current mode.
130 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GopMode
;
133 // Referenced by GopMode.Info, GopModeInfo provides detailed information
134 // about the current mode.
136 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION GopModeInfo
;
139 // Identifier of the 2D host resource that is in use by this head (scanout)
140 // of the VirtIo GPU device. Zero until the first successful -- internal --
141 // Gop.SetMode() call, never zero afterwards.
146 // A number of whole pages providing the backing store for the 2D host
147 // resource identified by ResourceId above. NULL until the first successful
148 // -- internal -- Gop.SetMode() call, never NULL afterwards.
150 UINT32
*BackingStore
;
155 // VirtIo GPU initialization, and commands (primitives) for the GPU device.
158 Configure the VirtIo GPU device that underlies VgpuDev.
160 @param[in,out] VgpuDev The VGPU_DEV object to set up VirtIo messaging for.
161 On input, the caller is responsible for having
162 initialized VgpuDev->VirtIo. On output, VgpuDev->Ring
163 has been initialized, and synchronous VirtIo GPU
164 commands (primitives) can be submitted to the device.
166 @retval EFI_SUCCESS VirtIo GPU configuration successful.
168 @retval EFI_UNSUPPORTED The host-side configuration of the VirtIo GPU is not
169 supported by this driver.
171 @retval Error codes from underlying functions.
175 IN OUT VGPU_DEV
*VgpuDev
179 De-configure the VirtIo GPU device that underlies VgpuDev.
181 @param[in,out] VgpuDev The VGPU_DEV object to tear down VirtIo messaging
182 for. On input, the caller is responsible for having
183 called VirtioGpuInit(). On output, VgpuDev->Ring has
184 been uninitialized; VirtIo GPU commands (primitives)
185 can no longer be submitted to the device.
189 IN OUT VGPU_DEV
*VgpuDev
193 EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the
194 VirtIo device, causing it to release its resources and to forget its
197 This function may only be called (that is, VGPU_DEV.ExitBoot may only be
198 signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is
201 @param[in] Event Event whose notification function is being invoked.
203 @param[in] Context Pointer to the associated VGPU_DEV object.
213 The following functions send requests to the VirtIo GPU device model, await
214 the answer from the host, and return a status. They share the following
217 @param[in,out] VgpuDev The VGPU_DEV object that represents the VirtIo GPU
218 device. The caller is responsible to have
219 successfully invoked VirtioGpuInit() on VgpuDev
220 previously, while VirtioGpuUninit() must not have
221 been called on VgpuDev.
223 @retval EFI_INVALID_PARAMETER Invalid command-specific parameters were
224 detected by this driver.
226 @retval EFI_SUCCESS Operation successful.
228 @retval EFI_DEVICE_ERROR The host rejected the request. The host error
229 code has been logged on the EFI_D_ERROR level.
231 @return Codes for unexpected errors in VirtIo
234 For the command-specific parameters, please consult the GPU Device section of
235 the VirtIo 1.0 specification (see references in
236 "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").
239 VirtioGpuResourceCreate2d (
240 IN OUT VGPU_DEV
*VgpuDev
,
241 IN UINT32 ResourceId
,
242 IN VIRTIO_GPU_FORMATS Format
,
248 VirtioGpuResourceUnref (
249 IN OUT VGPU_DEV
*VgpuDev
,
254 VirtioGpuResourceAttachBacking (
255 IN OUT VGPU_DEV
*VgpuDev
,
256 IN UINT32 ResourceId
,
257 IN EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress
,
258 IN UINTN NumberOfPages
262 VirtioGpuResourceDetachBacking (
263 IN OUT VGPU_DEV
*VgpuDev
,
268 VirtioGpuSetScanout (
269 IN OUT VGPU_DEV
*VgpuDev
,
279 VirtioGpuTransferToHost2d (
280 IN OUT VGPU_DEV
*VgpuDev
,
290 VirtioGpuResourceFlush (
291 IN OUT VGPU_DEV
*VgpuDev
,
300 Release guest-side and host-side resources that are related to an initialized
303 param[in,out] VgpuGop The VGPU_GOP object to release resources for.
305 On input, the caller is responsible for having called
306 VgpuGop->Gop.SetMode() at least once successfully.
307 (This is equivalent to the requirement that
308 VgpuGop->BackingStore be non-NULL. It is also
309 equivalent to the requirement that VgpuGop->ResourceId
312 On output, resources will be released, and
313 VgpuGop->BackingStore and VgpuGop->ResourceId will be
316 param[in] DisableHead Whether this head (scanout) currently references the
317 resource identified by VgpuGop->ResourceId. Only pass
318 FALSE when VgpuGop->Gop.SetMode() calls this function
319 while switching between modes, and set it to TRUE
323 ReleaseGopResources (
324 IN OUT VGPU_GOP
*VgpuGop
,
325 IN BOOLEAN DisableHead
329 // Template for initializing VGPU_GOP.Gop.
331 extern CONST EFI_GRAPHICS_OUTPUT_PROTOCOL mGopTemplate
;
333 #endif // _VIRTIO_GPU_DXE_H_