TianoCore EDK2 master
Loading...
Searching...
No Matches
Commands.c File Reference
#include <Library/VirtioLib.h>
#include "VirtioGpu.h"

Go to the source code of this file.

Functions

EFI_STATUS VirtioGpuInit (IN OUT VGPU_DEV *VgpuDev)
 
VOID VirtioGpuUninit (IN OUT VGPU_DEV *VgpuDev)
 
EFI_STATUS VirtioGpuAllocateZeroAndMapBackingStore (IN VGPU_DEV *VgpuDev, IN UINTN NumberOfPages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
 
VOID VirtioGpuUnmapAndFreeBackingStore (IN VGPU_DEV *VgpuDev, IN UINTN NumberOfPages, IN VOID *HostAddress, IN VOID *Mapping)
 
VOID EFIAPI VirtioGpuExitBoot (IN EFI_EVENT Event, IN VOID *Context)
 
STATIC EFI_STATUS VirtioGpuSendCommandWithReply (IN OUT VGPU_DEV *VgpuDev, IN VIRTIO_GPU_CONTROL_TYPE RequestType, IN BOOLEAN Fence, IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Header, IN UINTN RequestSize, IN VIRTIO_GPU_CONTROL_TYPE ResponseType, IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Response, IN UINTN ResponseSize)
 
STATIC EFI_STATUS VirtioGpuSendCommand (IN OUT VGPU_DEV *VgpuDev, IN VIRTIO_GPU_CONTROL_TYPE RequestType, IN BOOLEAN Fence, IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Header, IN UINTN RequestSize)
 
EFI_STATUS VirtioGpuResourceCreate2d (IN OUT VGPU_DEV *VgpuDev, IN UINT32 ResourceId, IN VIRTIO_GPU_FORMATS Format, IN UINT32 Width, IN UINT32 Height)
 
EFI_STATUS VirtioGpuResourceUnref (IN OUT VGPU_DEV *VgpuDev, IN UINT32 ResourceId)
 
EFI_STATUS VirtioGpuResourceAttachBacking (IN OUT VGPU_DEV *VgpuDev, IN UINT32 ResourceId, IN EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress, IN UINTN NumberOfPages)
 
EFI_STATUS VirtioGpuResourceDetachBacking (IN OUT VGPU_DEV *VgpuDev, IN UINT32 ResourceId)
 
EFI_STATUS VirtioGpuSetScanout (IN OUT VGPU_DEV *VgpuDev, IN UINT32 X, IN UINT32 Y, IN UINT32 Width, IN UINT32 Height, IN UINT32 ScanoutId, IN UINT32 ResourceId)
 
EFI_STATUS VirtioGpuTransferToHost2d (IN OUT VGPU_DEV *VgpuDev, IN UINT32 X, IN UINT32 Y, IN UINT32 Width, IN UINT32 Height, IN UINT64 Offset, IN UINT32 ResourceId)
 
EFI_STATUS VirtioGpuResourceFlush (IN OUT VGPU_DEV *VgpuDev, IN UINT32 X, IN UINT32 Y, IN UINT32 Width, IN UINT32 Height, IN UINT32 ResourceId)
 
EFI_STATUS VirtioGpuGetDisplayInfo (IN OUT VGPU_DEV *VgpuDev, volatile VIRTIO_GPU_RESP_DISPLAY_INFO *Response)
 

Detailed Description

VirtIo GPU initialization, and commands (primitives) for the GPU device.

Copyright (C) 2016, Red Hat, Inc. Copyright (c) 2017, AMD Inc, All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Commands.c.

Function Documentation

◆ VirtioGpuAllocateZeroAndMapBackingStore()

EFI_STATUS VirtioGpuAllocateZeroAndMapBackingStore ( IN VGPU_DEV VgpuDev,
IN UINTN  NumberOfPages,
OUT VOID **  HostAddress,
OUT EFI_PHYSICAL_ADDRESS DeviceAddress,
OUT VOID **  Mapping 
)

Allocate, zero and map memory, for bus master common buffer operation, to be attached as backing store to a host-side VirtIo GPU resource.

Parameters
[in]VgpuDevThe VGPU_DEV object that represents the VirtIo GPU device.
[in]NumberOfPagesThe number of whole pages to allocate and map.
[out]HostAddressThe system memory address of the allocated area.
[out]DeviceAddressThe bus master device address of the allocated area. The VirtIo GPU device may be programmed to access the allocated area through DeviceAddress; DeviceAddress is to be passed to the VirtioGpuResourceAttachBacking() function, as the BackingStoreDeviceAddress parameter.
[out]MappingA resulting token to pass to VirtioGpuUnmapAndFreeBackingStore().
Return values
EFI_SUCCESSThe requested number of pages has been allocated, zeroed and mapped.
Returns
Status codes propagated from VgpuDev->VirtIo->AllocateSharedPages() and VirtioMapAllBytesInSharedBuffer().

Definition at line 244 of file Commands.c.

◆ VirtioGpuExitBoot()

VOID EFIAPI VirtioGpuExitBoot ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the VirtIo device, causing it to release its resources and to forget its configuration.

This function may only be called (that is, VGPU_DEV.ExitBoot may only be signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is called.

Parameters
[in]EventEvent whose notification function is being invoked.
[in]ContextPointer to the associated VGPU_DEV object.

Definition at line 350 of file Commands.c.

◆ VirtioGpuGetDisplayInfo()

EFI_STATUS VirtioGpuGetDisplayInfo ( IN OUT VGPU_DEV VgpuDev,
volatile VIRTIO_GPU_RESP_DISPLAY_INFO Response 
)

Definition at line 833 of file Commands.c.

◆ VirtioGpuInit()

EFI_STATUS VirtioGpuInit ( IN OUT VGPU_DEV VgpuDev)

Configure the VirtIo GPU device that underlies VgpuDev.

Parameters
[in,out]VgpuDevThe VGPU_DEV object to set up VirtIo messaging for. On input, the caller is responsible for having initialized VgpuDev->VirtIo. On output, VgpuDev->Ring has been initialized, and synchronous VirtIo GPU commands (primitives) can be submitted to the device.
Return values
EFI_SUCCESSVirtIo GPU configuration successful.
EFI_UNSUPPORTEDThe host-side configuration of the VirtIo GPU is not supported by this driver.
Errorcodes from underlying functions.

Definition at line 33 of file Commands.c.

◆ VirtioGpuResourceAttachBacking()

EFI_STATUS VirtioGpuResourceAttachBacking ( IN OUT VGPU_DEV VgpuDev,
IN UINT32  ResourceId,
IN EFI_PHYSICAL_ADDRESS  BackingStoreDeviceAddress,
IN UINTN  NumberOfPages 
)

Definition at line 675 of file Commands.c.

◆ VirtioGpuResourceCreate2d()

EFI_STATUS VirtioGpuResourceCreate2d ( IN OUT VGPU_DEV VgpuDev,
IN UINT32  ResourceId,
IN VIRTIO_GPU_FORMATS  Format,
IN UINT32  Width,
IN UINT32  Height 
)

The following functions send requests to the VirtIo GPU device model, await the answer from the host, and return a status. They share the following interface details:

Parameters
[in,out]VgpuDevThe VGPU_DEV object that represents the VirtIo GPU device. The caller is responsible to have successfully invoked VirtioGpuInit() on VgpuDev previously, while VirtioGpuUninit() must not have been called on VgpuDev.
Return values
EFI_INVALID_PARAMETERInvalid command-specific parameters were detected by this driver.
EFI_SUCCESSOperation successful.
EFI_DEVICE_ERRORThe host rejected the request. The host error code has been logged on the DEBUG_ERROR level.
Returns
Codes for unexpected errors in VirtIo messaging.

For the command-specific parameters, please consult the GPU Device section of the VirtIo 1.0 specification (see references in "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").

Definition at line 622 of file Commands.c.

◆ VirtioGpuResourceDetachBacking()

EFI_STATUS VirtioGpuResourceDetachBacking ( IN OUT VGPU_DEV VgpuDev,
IN UINT32  ResourceId 
)

Definition at line 704 of file Commands.c.

◆ VirtioGpuResourceFlush()

EFI_STATUS VirtioGpuResourceFlush ( IN OUT VGPU_DEV VgpuDev,
IN UINT32  X,
IN UINT32  Y,
IN UINT32  Width,
IN UINT32  Height,
IN UINT32  ResourceId 
)

Definition at line 801 of file Commands.c.

◆ VirtioGpuResourceUnref()

EFI_STATUS VirtioGpuResourceUnref ( IN OUT VGPU_DEV VgpuDev,
IN UINT32  ResourceId 
)

Definition at line 651 of file Commands.c.

◆ VirtioGpuSendCommand()

STATIC EFI_STATUS VirtioGpuSendCommand ( IN OUT VGPU_DEV VgpuDev,
IN VIRTIO_GPU_CONTROL_TYPE  RequestType,
IN BOOLEAN  Fence,
IN OUT volatile VIRTIO_GPU_CONTROL_HEADER Header,
IN UINTN  RequestSize 
)

Simplified version of VirtioGpuSendCommandWithReply() for commands which do not send back any data.

Definition at line 573 of file Commands.c.

◆ VirtioGpuSendCommandWithReply()

STATIC EFI_STATUS VirtioGpuSendCommandWithReply ( IN OUT VGPU_DEV VgpuDev,
IN VIRTIO_GPU_CONTROL_TYPE  RequestType,
IN BOOLEAN  Fence,
IN OUT volatile VIRTIO_GPU_CONTROL_HEADER Header,
IN UINTN  RequestSize,
IN VIRTIO_GPU_CONTROL_TYPE  ResponseType,
IN OUT volatile VIRTIO_GPU_CONTROL_HEADER Response,
IN UINTN  ResponseSize 
)

Internal utility function that sends a request to the VirtIo GPU device model, awaits the answer from the host, and returns a status.

Parameters
[in,out]VgpuDevThe VGPU_DEV object that represents the VirtIo GPU device. The caller is responsible to have successfully invoked VirtioGpuInit() on VgpuDev previously, while VirtioGpuUninit() must not have been called on VgpuDev.
[in]RequestTypeThe type of the request. The caller is responsible for providing a VirtioGpuCmd* RequestType which, on success, elicits a VirtioGpuRespOkNodata response from the host.
[in]FenceWhether to enable fencing for this request. Fencing forces the host to complete the command before producing a response. If Fence is TRUE, then VgpuDev->FenceId is consumed, and incremented.
[in,out]HeaderPointer to the caller-allocated request object. The request must start with VIRTIO_GPU_CONTROL_HEADER. This function overwrites all fields of Header before submitting the request to the host:
  • it sets Type from RequestType,
  • it sets Flags and FenceId based on Fence,
  • it zeroes CtxId and Padding.
Parameters
[in]RequestSizeSize of the entire caller-allocated request object, including the leading VIRTIO_GPU_CONTROL_HEADER.
[in]ResponseTypeThe type of the response (VirtioGpuResp*).
[in,out]ResponsePointer to the caller-allocated response object. The request must start with VIRTIO_GPU_CONTROL_HEADER.
[in]ResponseSizeSize of the entire caller-allocated response object, including the leading VIRTIO_GPU_CONTROL_HEADER.
Return values
EFI_SUCCESSOperation successful.
EFI_DEVICE_ERRORThe host rejected the request. The host error code has been logged on the DEBUG_ERROR level.
Returns
Codes for unexpected errors in VirtIo messaging, or request/response mapping/unmapping.

Definition at line 415 of file Commands.c.

◆ VirtioGpuSetScanout()

EFI_STATUS VirtioGpuSetScanout ( IN OUT VGPU_DEV VgpuDev,
IN UINT32  X,
IN UINT32  Y,
IN UINT32  Width,
IN UINT32  Height,
IN UINT32  ScanoutId,
IN UINT32  ResourceId 
)

Definition at line 734 of file Commands.c.

◆ VirtioGpuTransferToHost2d()

EFI_STATUS VirtioGpuTransferToHost2d ( IN OUT VGPU_DEV VgpuDev,
IN UINT32  X,
IN UINT32  Y,
IN UINT32  Width,
IN UINT32  Height,
IN UINT64  Offset,
IN UINT32  ResourceId 
)

Definition at line 767 of file Commands.c.

◆ VirtioGpuUninit()

VOID VirtioGpuUninit ( IN OUT VGPU_DEV VgpuDev)

De-configure the VirtIo GPU device that underlies VgpuDev.

Parameters
[in,out]VgpuDevThe VGPU_DEV object to tear down VirtIo messaging for. On input, the caller is responsible for having called VirtioGpuInit(). On output, VgpuDev->Ring has been uninitialized; VirtIo GPU commands (primitives) can no longer be submitted to the device.

Definition at line 202 of file Commands.c.

◆ VirtioGpuUnmapAndFreeBackingStore()

VOID VirtioGpuUnmapAndFreeBackingStore ( IN VGPU_DEV VgpuDev,
IN UINTN  NumberOfPages,
IN VOID *  HostAddress,
IN VOID *  Mapping 
)

Unmap and free memory originally allocated and mapped with VirtioGpuAllocateZeroAndMapBackingStore().

If the memory allocated and mapped with VirtioGpuAllocateZeroAndMapBackingStore() was attached to a host-side VirtIo GPU resource with VirtioGpuResourceAttachBacking(), then the caller is responsible for detaching the backing store from the same resource, with VirtioGpuResourceDetachBacking(), before calling this function.

Parameters
[in]VgpuDevThe VGPU_DEV object that represents the VirtIo GPU device.
[in]NumberOfPagesThe NumberOfPages parameter originally passed to VirtioGpuAllocateZeroAndMapBackingStore().
[in]HostAddressThe HostAddress value originally output by VirtioGpuAllocateZeroAndMapBackingStore().
[in]MappingThe token that was originally output by VirtioGpuAllocateZeroAndMapBackingStore().

Definition at line 317 of file Commands.c.