\r
Copyright (C) 2016, Red Hat, Inc.\r
\r
- This program and the accompanying materials are licensed and made available\r
- under the terms and conditions of the BSD License which accompanies this\r
- distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
- WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#ifndef _VIRTIO_GPU_DXE_H_\r
#define _VIRTIO_GPU_DXE_H_\r
\r
+#include <IndustryStandard/VirtioGpu.h>\r
+#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/UefiLib.h>\r
+#include <Protocol/GraphicsOutput.h>\r
#include <Protocol/VirtioDevice.h>\r
\r
//\r
//\r
VRING Ring;\r
\r
+ //\r
+ // Token associated with Ring's mapping for bus master common buffer\r
+ // operation, from VirtioRingMap().\r
+ //\r
+ VOID *RingMap;\r
+\r
//\r
// Event to be signaled at ExitBootServices().\r
//\r
EFI_EVENT ExitBoot;\r
\r
+ //\r
+ // Common running counter for all VirtIo GPU requests that ask for fencing.\r
+ //\r
+ UINT64 FenceId;\r
+\r
//\r
// The Child field references the GOP wrapper structure. If this pointer is\r
// NULL, then the hybrid driver has bound (i.e., started) the\r
// The Gop field is installed on the child handle as Graphics Output Protocol\r
// interface.\r
//\r
- // For now it is just a placeholder.\r
+ EFI_GRAPHICS_OUTPUT_PROTOCOL Gop;\r
+\r
+ //\r
+ // Referenced by Gop.Mode, GopMode provides a summary about the supported\r
+ // graphics modes, and the current mode.\r
+ //\r
+ EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GopMode;\r
+\r
+ //\r
+ // Referenced by GopMode.Info, GopModeInfo provides detailed information\r
+ // about the current mode.\r
+ //\r
+ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION GopModeInfo;\r
+\r
+ //\r
+ // Identifier of the 2D host resource that is in use by this head (scanout)\r
+ // of the VirtIo GPU device. Zero until the first successful -- internal --\r
+ // Gop.SetMode() call, never zero afterwards.\r
+ //\r
+ UINT32 ResourceId;\r
+\r
+ //\r
+ // A number of whole pages providing the backing store for the 2D host\r
+ // resource identified by ResourceId above. NULL until the first successful\r
+ // -- internal -- Gop.SetMode() call, never NULL afterwards.\r
+ //\r
+ UINT32 *BackingStore;\r
+ UINTN NumberOfPages;\r
+\r
+ //\r
+ // Token associated with BackingStore's mapping for bus master common\r
+ // buffer operation. BackingStoreMap is valid if, and only if,\r
+ // BackingStore is non-NULL.\r
//\r
- UINT8 Gop;\r
+ VOID *BackingStoreMap;\r
};\r
\r
//\r
IN OUT VGPU_DEV *VgpuDev\r
);\r
\r
+/**\r
+ Allocate, zero and map memory, for bus master common buffer operation, to be\r
+ attached as backing store to a host-side VirtIo GPU resource.\r
+\r
+ @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
+ device.\r
+\r
+ @param[in] NumberOfPages The number of whole pages to allocate and map.\r
+\r
+ @param[out] HostAddress The system memory address of the allocated area.\r
+\r
+ @param[out] DeviceAddress The bus master device address of the allocated\r
+ area. The VirtIo GPU device may be programmed to\r
+ access the allocated area through DeviceAddress;\r
+ DeviceAddress is to be passed to the\r
+ VirtioGpuResourceAttachBacking() function, as the\r
+ BackingStoreDeviceAddress parameter.\r
+\r
+ @param[out] Mapping A resulting token to pass to\r
+ VirtioGpuUnmapAndFreeBackingStore().\r
+\r
+ @retval EFI_SUCCESS The requested number of pages has been allocated, zeroed\r
+ and mapped.\r
+\r
+ @return Status codes propagated from\r
+ VgpuDev->VirtIo->AllocateSharedPages() and\r
+ VirtioMapAllBytesInSharedBuffer().\r
+**/\r
+EFI_STATUS\r
+VirtioGpuAllocateZeroAndMapBackingStore (\r
+ IN VGPU_DEV *VgpuDev,\r
+ IN UINTN NumberOfPages,\r
+ OUT VOID **HostAddress,\r
+ OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
+ OUT VOID **Mapping\r
+ );\r
+\r
+/**\r
+ Unmap and free memory originally allocated and mapped with\r
+ VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+ If the memory allocated and mapped with\r
+ VirtioGpuAllocateZeroAndMapBackingStore() was attached to a host-side VirtIo\r
+ GPU resource with VirtioGpuResourceAttachBacking(), then the caller is\r
+ responsible for detaching the backing store from the same resource, with\r
+ VirtioGpuResourceDetachBacking(), before calling this function.\r
+\r
+ @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
+ device.\r
+\r
+ @param[in] NumberOfPages The NumberOfPages parameter originally passed to\r
+ VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+ @param[in] HostAddress The HostAddress value originally output by\r
+ VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+ @param[in] Mapping The token that was originally output by\r
+ VirtioGpuAllocateZeroAndMapBackingStore().\r
+**/\r
+VOID\r
+VirtioGpuUnmapAndFreeBackingStore (\r
+ IN VGPU_DEV *VgpuDev,\r
+ IN UINTN NumberOfPages,\r
+ IN VOID *HostAddress,\r
+ IN VOID *Mapping\r
+ );\r
+\r
/**\r
EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the\r
VirtIo device, causing it to release its resources and to forget its\r
IN VOID *Context\r
);\r
\r
+/**\r
+ The following functions send requests to the VirtIo GPU device model, await\r
+ the answer from the host, and return a status. They share the following\r
+ interface details:\r
+\r
+ @param[in,out] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
+ device. The caller is responsible to have\r
+ successfully invoked VirtioGpuInit() on VgpuDev\r
+ previously, while VirtioGpuUninit() must not have\r
+ been called on VgpuDev.\r
+\r
+ @retval EFI_INVALID_PARAMETER Invalid command-specific parameters were\r
+ detected by this driver.\r
+\r
+ @retval EFI_SUCCESS Operation successful.\r
+\r
+ @retval EFI_DEVICE_ERROR The host rejected the request. The host error\r
+ code has been logged on the EFI_D_ERROR level.\r
+\r
+ @return Codes for unexpected errors in VirtIo\r
+ messaging.\r
+\r
+ For the command-specific parameters, please consult the GPU Device section of\r
+ the VirtIo 1.0 specification (see references in\r
+ "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").\r
+**/\r
+EFI_STATUS\r
+VirtioGpuResourceCreate2d (\r
+ IN OUT VGPU_DEV *VgpuDev,\r
+ IN UINT32 ResourceId,\r
+ IN VIRTIO_GPU_FORMATS Format,\r
+ IN UINT32 Width,\r
+ IN UINT32 Height\r
+ );\r
+\r
+EFI_STATUS\r
+VirtioGpuResourceUnref (\r
+ IN OUT VGPU_DEV *VgpuDev,\r
+ IN UINT32 ResourceId\r
+ );\r
+\r
+EFI_STATUS\r
+VirtioGpuResourceAttachBacking (\r
+ IN OUT VGPU_DEV *VgpuDev,\r
+ IN UINT32 ResourceId,\r
+ IN EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress,\r
+ IN UINTN NumberOfPages\r
+ );\r
+\r
+EFI_STATUS\r
+VirtioGpuResourceDetachBacking (\r
+ IN OUT VGPU_DEV *VgpuDev,\r
+ IN UINT32 ResourceId\r
+ );\r
+\r
+EFI_STATUS\r
+VirtioGpuSetScanout (\r
+ IN OUT VGPU_DEV *VgpuDev,\r
+ IN UINT32 X,\r
+ IN UINT32 Y,\r
+ IN UINT32 Width,\r
+ IN UINT32 Height,\r
+ IN UINT32 ScanoutId,\r
+ IN UINT32 ResourceId\r
+ );\r
+\r
+EFI_STATUS\r
+VirtioGpuTransferToHost2d (\r
+ IN OUT VGPU_DEV *VgpuDev,\r
+ IN UINT32 X,\r
+ IN UINT32 Y,\r
+ IN UINT32 Width,\r
+ IN UINT32 Height,\r
+ IN UINT64 Offset,\r
+ IN UINT32 ResourceId\r
+ );\r
+\r
+EFI_STATUS\r
+VirtioGpuResourceFlush (\r
+ IN OUT VGPU_DEV *VgpuDev,\r
+ IN UINT32 X,\r
+ IN UINT32 Y,\r
+ IN UINT32 Width,\r
+ IN UINT32 Height,\r
+ IN UINT32 ResourceId\r
+ );\r
+\r
+/**\r
+ Release guest-side and host-side resources that are related to an initialized\r
+ VGPU_GOP.Gop.\r
+\r
+ param[in,out] VgpuGop The VGPU_GOP object to release resources for.\r
+\r
+ On input, the caller is responsible for having called\r
+ VgpuGop->Gop.SetMode() at least once successfully.\r
+ (This is equivalent to the requirement that\r
+ VgpuGop->BackingStore be non-NULL. It is also\r
+ equivalent to the requirement that VgpuGop->ResourceId\r
+ be nonzero.)\r
+\r
+ On output, resources will be released, and\r
+ VgpuGop->BackingStore and VgpuGop->ResourceId will be\r
+ nulled.\r
+\r
+ param[in] DisableHead Whether this head (scanout) currently references the\r
+ resource identified by VgpuGop->ResourceId. Only pass\r
+ FALSE when VgpuGop->Gop.SetMode() calls this function\r
+ while switching between modes, and set it to TRUE\r
+ every other time.\r
+**/\r
+VOID\r
+ReleaseGopResources (\r
+ IN OUT VGPU_GOP *VgpuGop,\r
+ IN BOOLEAN DisableHead\r
+ );\r
+\r
+//\r
+// Template for initializing VGPU_GOP.Gop.\r
+//\r
+extern CONST EFI_GRAPHICS_OUTPUT_PROTOCOL mGopTemplate;\r
+\r
#endif // _VIRTIO_GPU_DXE_H_\r