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/BaseMemoryLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiLib.h>
24 #include <Protocol/GraphicsOutput.h>
25 #include <Protocol/VirtioDevice.h>
28 // Forward declaration of VGPU_GOP.
30 typedef struct VGPU_GOP_STRUCT VGPU_GOP
;
33 // The abstraction that directly corresponds to a Virtio GPU device.
35 // This structure will be installed on the handle that has the VirtIo Device
36 // Protocol interface, with GUID gEfiCallerIdGuid. A similar trick is employed
37 // in TerminalDxe, and it is necessary so that we can look up VGPU_DEV just
38 // from the VirtIo Device Protocol handle in the Component Name 2 Protocol
43 // VirtIo represents access to the Virtio GPU device. Never NULL.
45 VIRTIO_DEVICE_PROTOCOL
*VirtIo
;
48 // BusName carries a customized name for
49 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table
50 // form because it can theoretically support several languages. Never NULL.
52 EFI_UNICODE_STRING_TABLE
*BusName
;
55 // VirtIo ring used for VirtIo communication.
60 // Token associated with Ring's mapping for bus master common buffer
61 // operation, from VirtioRingMap().
66 // Event to be signaled at ExitBootServices().
71 // Common running counter for all VirtIo GPU requests that ask for fencing.
76 // The Child field references the GOP wrapper structure. If this pointer is
77 // NULL, then the hybrid driver has bound (i.e., started) the
78 // VIRTIO_DEVICE_PROTOCOL controller without producing the child GOP
79 // controller (that is, after Start() was called with RemainingDevicePath
80 // pointing to and End of Device Path node). Child can be created and
81 // destroyed, even repeatedly, independently of VGPU_DEV.
83 // In practice, this field represents the single head (scanout) that we
90 // The Graphics Output Protocol wrapper structure.
92 #define VGPU_GOP_SIG SIGNATURE_64 ('V', 'G', 'P', 'U', '_', 'G', 'O', 'P')
94 struct VGPU_GOP_STRUCT
{
98 // ParentBus points to the parent VGPU_DEV object. Never NULL.
103 // GopName carries a customized name for
104 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table
105 // form because it can theoretically support several languages. Never NULL.
107 EFI_UNICODE_STRING_TABLE
*GopName
;
110 // GopHandle is the UEFI child handle that carries the device path ending
111 // with the ACPI ADR node, and the Graphics Output Protocol. Never NULL.
113 EFI_HANDLE GopHandle
;
116 // The GopDevicePath field is the device path installed on GopHandle,
117 // ending with an ACPI ADR node. Never NULL.
119 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
122 // The Gop field is installed on the child handle as Graphics Output Protocol
125 EFI_GRAPHICS_OUTPUT_PROTOCOL Gop
;
128 // Referenced by Gop.Mode, GopMode provides a summary about the supported
129 // graphics modes, and the current mode.
131 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GopMode
;
134 // Referenced by GopMode.Info, GopModeInfo provides detailed information
135 // about the current mode.
137 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION GopModeInfo
;
140 // Identifier of the 2D host resource that is in use by this head (scanout)
141 // of the VirtIo GPU device. Zero until the first successful -- internal --
142 // Gop.SetMode() call, never zero afterwards.
147 // A number of whole pages providing the backing store for the 2D host
148 // resource identified by ResourceId above. NULL until the first successful
149 // -- internal -- Gop.SetMode() call, never NULL afterwards.
151 UINT32
*BackingStore
;
155 // Token associated with BackingStore's mapping for bus master common
156 // buffer operation. BackingStoreMap is valid if, and only if,
157 // BackingStore is non-NULL.
159 VOID
*BackingStoreMap
;
163 // VirtIo GPU initialization, and commands (primitives) for the GPU device.
166 Configure the VirtIo GPU device that underlies VgpuDev.
168 @param[in,out] VgpuDev The VGPU_DEV object to set up VirtIo messaging for.
169 On input, the caller is responsible for having
170 initialized VgpuDev->VirtIo. On output, VgpuDev->Ring
171 has been initialized, and synchronous VirtIo GPU
172 commands (primitives) can be submitted to the device.
174 @retval EFI_SUCCESS VirtIo GPU configuration successful.
176 @retval EFI_UNSUPPORTED The host-side configuration of the VirtIo GPU is not
177 supported by this driver.
179 @retval Error codes from underlying functions.
183 IN OUT VGPU_DEV
*VgpuDev
187 De-configure the VirtIo GPU device that underlies VgpuDev.
189 @param[in,out] VgpuDev The VGPU_DEV object to tear down VirtIo messaging
190 for. On input, the caller is responsible for having
191 called VirtioGpuInit(). On output, VgpuDev->Ring has
192 been uninitialized; VirtIo GPU commands (primitives)
193 can no longer be submitted to the device.
197 IN OUT VGPU_DEV
*VgpuDev
201 Allocate, zero and map memory, for bus master common buffer operation, to be
202 attached as backing store to a host-side VirtIo GPU resource.
204 @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU
207 @param[in] NumberOfPages The number of whole pages to allocate and map.
209 @param[out] HostAddress The system memory address of the allocated area.
211 @param[out] DeviceAddress The bus master device address of the allocated
212 area. The VirtIo GPU device may be programmed to
213 access the allocated area through DeviceAddress;
214 DeviceAddress is to be passed to the
215 VirtioGpuResourceAttachBacking() function, as the
216 BackingStoreDeviceAddress parameter.
218 @param[out] Mapping A resulting token to pass to
219 VirtioGpuUnmapAndFreeBackingStore().
221 @retval EFI_SUCCESS The requested number of pages has been allocated, zeroed
224 @return Status codes propagated from
225 VgpuDev->VirtIo->AllocateSharedPages() and
226 VirtioMapAllBytesInSharedBuffer().
229 VirtioGpuAllocateZeroAndMapBackingStore (
230 IN VGPU_DEV
*VgpuDev
,
231 IN UINTN NumberOfPages
,
232 OUT VOID
**HostAddress
,
233 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
238 Unmap and free memory originally allocated and mapped with
239 VirtioGpuAllocateZeroAndMapBackingStore().
241 If the memory allocated and mapped with
242 VirtioGpuAllocateZeroAndMapBackingStore() was attached to a host-side VirtIo
243 GPU resource with VirtioGpuResourceAttachBacking(), then the caller is
244 responsible for detaching the backing store from the same resource, with
245 VirtioGpuResourceDetachBacking(), before calling this function.
247 @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU
250 @param[in] NumberOfPages The NumberOfPages parameter originally passed to
251 VirtioGpuAllocateZeroAndMapBackingStore().
253 @param[in] HostAddress The HostAddress value originally output by
254 VirtioGpuAllocateZeroAndMapBackingStore().
256 @param[in] Mapping The token that was originally output by
257 VirtioGpuAllocateZeroAndMapBackingStore().
260 VirtioGpuUnmapAndFreeBackingStore (
261 IN VGPU_DEV
*VgpuDev
,
262 IN UINTN NumberOfPages
,
263 IN VOID
*HostAddress
,
268 EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the
269 VirtIo device, causing it to release its resources and to forget its
272 This function may only be called (that is, VGPU_DEV.ExitBoot may only be
273 signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is
276 @param[in] Event Event whose notification function is being invoked.
278 @param[in] Context Pointer to the associated VGPU_DEV object.
288 The following functions send requests to the VirtIo GPU device model, await
289 the answer from the host, and return a status. They share the following
292 @param[in,out] VgpuDev The VGPU_DEV object that represents the VirtIo GPU
293 device. The caller is responsible to have
294 successfully invoked VirtioGpuInit() on VgpuDev
295 previously, while VirtioGpuUninit() must not have
296 been called on VgpuDev.
298 @retval EFI_INVALID_PARAMETER Invalid command-specific parameters were
299 detected by this driver.
301 @retval EFI_SUCCESS Operation successful.
303 @retval EFI_DEVICE_ERROR The host rejected the request. The host error
304 code has been logged on the EFI_D_ERROR level.
306 @return Codes for unexpected errors in VirtIo
309 For the command-specific parameters, please consult the GPU Device section of
310 the VirtIo 1.0 specification (see references in
311 "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").
314 VirtioGpuResourceCreate2d (
315 IN OUT VGPU_DEV
*VgpuDev
,
316 IN UINT32 ResourceId
,
317 IN VIRTIO_GPU_FORMATS Format
,
323 VirtioGpuResourceUnref (
324 IN OUT VGPU_DEV
*VgpuDev
,
329 VirtioGpuResourceAttachBacking (
330 IN OUT VGPU_DEV
*VgpuDev
,
331 IN UINT32 ResourceId
,
332 IN EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress
,
333 IN UINTN NumberOfPages
337 VirtioGpuResourceDetachBacking (
338 IN OUT VGPU_DEV
*VgpuDev
,
343 VirtioGpuSetScanout (
344 IN OUT VGPU_DEV
*VgpuDev
,
354 VirtioGpuTransferToHost2d (
355 IN OUT VGPU_DEV
*VgpuDev
,
365 VirtioGpuResourceFlush (
366 IN OUT VGPU_DEV
*VgpuDev
,
375 Release guest-side and host-side resources that are related to an initialized
378 param[in,out] VgpuGop The VGPU_GOP object to release resources for.
380 On input, the caller is responsible for having called
381 VgpuGop->Gop.SetMode() at least once successfully.
382 (This is equivalent to the requirement that
383 VgpuGop->BackingStore be non-NULL. It is also
384 equivalent to the requirement that VgpuGop->ResourceId
387 On output, resources will be released, and
388 VgpuGop->BackingStore and VgpuGop->ResourceId will be
391 param[in] DisableHead Whether this head (scanout) currently references the
392 resource identified by VgpuGop->ResourceId. Only pass
393 FALSE when VgpuGop->Gop.SetMode() calls this function
394 while switching between modes, and set it to TRUE
398 ReleaseGopResources (
399 IN OUT VGPU_GOP
*VgpuGop
,
400 IN BOOLEAN DisableHead
404 // Template for initializing VGPU_GOP.Gop.
406 extern CONST EFI_GRAPHICS_OUTPUT_PROTOCOL mGopTemplate
;
408 #endif // _VIRTIO_GPU_DXE_H_