TianoCore EDK2 master
Loading...
Searching...
No Matches
VirtioLib.h File Reference

Go to the source code of this file.

Data Structures

struct  DESC_INDICES
 

Functions

EFI_STATUS EFIAPI VirtioRingInit (IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT16 QueueSize, OUT VRING *Ring)
 
EFI_STATUS EFIAPI VirtioRingMap (IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN VRING *Ring, OUT UINT64 *RingBaseShift, OUT VOID **Mapping)
 
VOID EFIAPI VirtioRingUninit (IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN OUT VRING *Ring)
 
VOID EFIAPI VirtioPrepare (IN OUT VRING *Ring, OUT DESC_INDICES *Indices)
 
VOID EFIAPI VirtioAppendDesc (IN OUT VRING *Ring, IN UINT64 BufferDeviceAddress, IN UINT32 BufferSize, IN UINT16 Flags, IN OUT DESC_INDICES *Indices)
 
EFI_STATUS EFIAPI VirtioFlush (IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT16 VirtQueueId, IN OUT VRING *Ring, IN DESC_INDICES *Indices, OUT UINT32 *UsedLen OPTIONAL)
 
EFI_STATUS EFIAPI Virtio10WriteFeatures (IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT64 Features, IN OUT UINT8 *DeviceStatus)
 
EFI_STATUS EFIAPI VirtioMapAllBytesInSharedBuffer (IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN VIRTIO_MAP_OPERATION Operation, IN VOID *HostAddress, IN UINTN NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
 

Detailed Description

Declarations of utility functions used by virtio device drivers.

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

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

Definition in file VirtioLib.h.

Function Documentation

◆ Virtio10WriteFeatures()

EFI_STATUS EFIAPI Virtio10WriteFeatures ( IN VIRTIO_DEVICE_PROTOCOL VirtIo,
IN UINT64  Features,
IN OUT UINT8 *  DeviceStatus 
)

Report the feature bits to the VirtIo 1.0 device that the VirtIo 1.0 driver understands.

In VirtIo 1.0, a device can reject a self-inconsistent feature bitmap through the new VSTAT_FEATURES_OK status bit. (For example if the driver requests a higher level feature but clears a prerequisite feature.) This function is a small wrapper around VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures() that also verifies if the VirtIo 1.0 device accepts the feature bitmap.

Parameters
[in]VirtIoReport feature bits to this device.
[in]FeaturesThe set of feature bits that the driver wishes to report. The caller is responsible to perform any masking before calling this function; the value is directly written with VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures().
[in,out]DeviceStatusOn input, the status byte most recently written to the device's status register. On output (even on error), DeviceStatus will be updated so that it is suitable for further status bit manipulation and writing to the device's status register.
Return values
EFI_SUCCESSThe device accepted the configuration in Features.
Returns
EFI_UNSUPPORTED The device rejected the configuration in Features.
Return values
EFI_UNSUPPORTEDVirtIo->Revision is smaller than 1.0.0.
Returns
Error codes from the SetGuestFeatures(), SetDeviceStatus(), GetDeviceStatus() member functions.

Definition at line 391 of file VirtioLib.c.

◆ VirtioAppendDesc()

VOID EFIAPI VirtioAppendDesc ( IN OUT VRING Ring,
IN UINT64  BufferDeviceAddress,
IN UINT32  BufferSize,
IN UINT16  Flags,
IN OUT DESC_INDICES Indices 
)

Append a contiguous buffer for transmission / reception via the virtio ring.

This function implements the following section from virtio-0.9.5:

  • 2.4.1.1 Placing Buffers into the Descriptor Table

Free space is taken as granted, since the individual drivers support only synchronous requests and host side status is processed in lock-step with request submission. It is the calling driver's responsibility to verify the ring size in advance.

The caller is responsible for initializing *Indices with VirtioPrepare() first.

Parameters
[in,out]RingThe virtio ring to append the buffer to, as a descriptor.
[in]BufferDeviceAddress(Bus master device) start address of the transmit / receive buffer.
[in]BufferSizeNumber of bytes to transmit or receive.
[in]FlagsA bitmask of VRING_DESC_F_* flags. The caller computes this mask dependent on further buffers to append and transfer direction. VRING_DESC_F_INDIRECT is unsupported. The VRING_DESC.Next field is always set, but the host only interprets it dependent on VRING_DESC_F_NEXT.
[in,out]IndicesIndices->HeadDescIdx is not accessed. On input, Indices->NextDescIdx identifies the next descriptor to carry the buffer. On output, Indices->NextDescIdx is incremented by one, modulo 2^16.

Definition at line 228 of file VirtioLib.c.

◆ VirtioFlush()

EFI_STATUS EFIAPI VirtioFlush ( IN VIRTIO_DEVICE_PROTOCOL VirtIo,
IN UINT16  VirtQueueId,
IN OUT VRING Ring,
IN DESC_INDICES Indices,
OUT UINT32 *UsedLen  OPTIONAL 
)

Notify the host about the descriptor chain just built, and wait until the host processes it.

Parameters
[in]VirtIoThe target virtio device to notify.
[in]VirtQueueIdIdentifies the queue for the target device.
[in,out]RingThe virtio ring with descriptors to submit.
[in]IndicesIndices->NextDescIdx is not accessed. Indices->HeadDescIdx identifies the head descriptor of the descriptor chain.
[out]UsedLenOn success, the total number of bytes, consecutively across the buffers linked by the descriptor chain, that the host wrote. May be NULL if the caller doesn't care, or can compute the same information from device-specific request structures linked by the descriptor chain.
Returns
Error code from VirtIo->SetQueueNotify() if it fails.
Return values
EFI_SUCCESSOtherwise, the host processed all descriptors.

Definition at line 274 of file VirtioLib.c.

◆ VirtioMapAllBytesInSharedBuffer()

EFI_STATUS EFIAPI VirtioMapAllBytesInSharedBuffer ( IN VIRTIO_DEVICE_PROTOCOL VirtIo,
IN VIRTIO_MAP_OPERATION  Operation,
IN VOID *  HostAddress,
IN UINTN  NumberOfBytes,
OUT EFI_PHYSICAL_ADDRESS DeviceAddress,
OUT VOID **  Mapping 
)

Provides the virtio device address required to access system memory from a DMA bus master.

The interface follows the same usage pattern as defined in UEFI spec 2.6 (Section 13.2 PCI Root Bridge I/O Protocol)

The VirtioMapAllBytesInSharedBuffer() is similar to VIRTIO_MAP_SHARED with exception that NumberOfBytes is IN-only parameter. The function maps all the bytes specified in NumberOfBytes param in one consecutive range.

Parameters
[in]VirtIoThe virtio device for which the mapping is requested.
[in]OperationIndicates if the bus master is going to read or write to system memory.
[in]HostAddressThe system memory address to map to shared buffer address.
[in]NumberOfBytesNumber of bytes to map.
[out]DeviceAddressThe resulting shared map address for the bus master to access the hosts HostAddress.
[out]MappingA resulting token to pass to VIRTIO_UNMAP_SHARED.
Return values
EFI_SUCCESSThe NumberOfBytes is successfully mapped.
EFI_UNSUPPORTEDThe HostAddress cannot be mapped as a common buffer.
EFI_INVALID_PARAMETEROne or more parameters are invalid.
EFI_OUT_OF_RESOURCESThe request could not be completed due to a lack of resources. This includes the case when NumberOfBytes bytes cannot be mapped in one consecutive range.
EFI_DEVICE_ERRORThe system hardware could not map the requested address.

Definition at line 469 of file VirtioLib.c.

◆ VirtioPrepare()

VOID EFIAPI VirtioPrepare ( IN OUT VRING Ring,
OUT DESC_INDICES Indices 
)

Turn off interrupt notifications from the host, and prepare for appending multiple descriptors to the virtio ring.

The calling driver must be in VSTAT_DRIVER_OK state.

Parameters
[in,out]RingThe virtio ring we intend to append descriptors to.
[out]IndicesThe DESC_INDICES structure to initialize.

Definition at line 167 of file VirtioLib.c.

◆ VirtioRingInit()

EFI_STATUS EFIAPI VirtioRingInit ( IN VIRTIO_DEVICE_PROTOCOL VirtIo,
IN UINT16  QueueSize,
OUT VRING Ring 
)

Configure a virtio ring.

This function sets up internal storage (the guest-host communication area) and lays out several "navigation" (ie. no-ownership) pointers to parts of that storage.

Relevant sections from the virtio-0.9.5 spec:

  • 1.1 Virtqueues,
  • 2.3 Virtqueue Configuration.
Parameters
[in]VirtIoThe virtio device which will use the ring.
[in]Thenumber of descriptors to allocate for the virtio ring, as requested by the host.
[out]RingThe virtio ring to set up.
Returns
Status codes propagated from VirtIo->AllocateSharedPages().
Return values
EFI_SUCCESSAllocation and setup successful. Ring->Base (and nothing else) is responsible for deallocation.

Definition at line 49 of file VirtioLib.c.

◆ VirtioRingMap()

EFI_STATUS EFIAPI VirtioRingMap ( IN VIRTIO_DEVICE_PROTOCOL VirtIo,
IN VRING Ring,
OUT UINT64 *  RingBaseShift,
OUT VOID **  Mapping 
)

Map the ring buffer so that it can be accessed equally by both guest and hypervisor.

Parameters
[in]VirtIoThe virtio device instance.
[in]RingThe virtio ring to map.
[out]RingBaseShiftA resulting translation offset, to be passed to VirtIo->SetQueueAddress().
[out]MappingA resulting token to pass to VirtIo->UnmapSharedBuffer().
Returns
Status code from VirtIo->MapSharedBuffer()

Definition at line 529 of file VirtioLib.c.

◆ VirtioRingUninit()

VOID EFIAPI VirtioRingUninit ( IN VIRTIO_DEVICE_PROTOCOL VirtIo,
IN OUT VRING Ring 
)

Tear down the internal resources of a configured virtio ring.

The caller is responsible to stop the host from using this ring before invoking this function: the VSTAT_DRIVER_OK bit must be clear in VhdrDeviceStatus.

Parameters
[in]VirtIoThe virtio device which was using the ring.
[out]RingThe virtio ring to clean up.

Definition at line 144 of file VirtioLib.c.