X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=OvmfPkg%2FInclude%2FLibrary%2FVirtioLib.h;h=bca58cdeb2aa1fdfe5f49a7f72a64d4aaf42002e;hb=61a044c6c15f5806a30ff23409ba5287d9d07163;hp=9a502f3e6776453b2864ba06c732ab119de8d711;hpb=f2965f4e263274d27e2d9a1291a60785543f3e0c;p=mirror_edk2.git diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h index 9a502f3e67..bca58cdeb2 100644 --- a/OvmfPkg/Include/Library/VirtioLib.h +++ b/OvmfPkg/Include/Library/VirtioLib.h @@ -2,7 +2,8 @@ Declarations of utility functions used by virtio device drivers. - Copyright (C) 2012, Red Hat, Inc. + Copyright (C) 2012-2016, Red Hat, Inc. + Copyright (C) 2017, AMD Inc, All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this @@ -17,70 +18,9 @@ #ifndef _VIRTIO_LIB_H_ #define _VIRTIO_LIB_H_ -#include -#include - -/** - - Write a word into Region 0 of the device specified by PciIo. - - Region 0 must be an iomem region. This is an internal function for the - driver-specific VIRTIO_CFG_WRITE() macros. - - @param[in] PciIo Target PCI device. - - @param[in] FieldOffset Destination offset. - - @param[in] FieldSize Destination field size, must be in { 1, 2, 4, 8 }. - - @param[in] Value Little endian value to write, converted to UINT64. - The least significant FieldSize bytes will be used. - - - @return Status code returned by PciIo->Io.Write(). - -**/ -EFI_STATUS -EFIAPI -VirtioWrite ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN UINTN FieldOffset, - IN UINTN FieldSize, - IN UINT64 Value - ); - - -/** - - Read a word from Region 0 of the device specified by PciIo. - - Region 0 must be an iomem region. This is an internal function for the - driver-specific VIRTIO_CFG_READ() macros. +#include - @param[in] PciIo Source PCI device. - - @param[in] FieldOffset Source offset. - - @param[in] FieldSize Source field size, must be in { 1, 2, 4, 8 }. - - @param[in] BufferSize Number of bytes available in the target buffer. Must - equal FieldSize. - - @param[out] Buffer Target buffer. - - - @return Status code returned by PciIo->Io.Read(). - -**/ -EFI_STATUS -EFIAPI -VirtioRead ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN UINTN FieldOffset, - IN UINTN FieldSize, - IN UINTN BufferSize, - OUT VOID *Buffer - ); +#include /** @@ -95,14 +35,15 @@ VirtioRead ( - 1.1 Virtqueues, - 2.3 Virtqueue Configuration. + @param[in] VirtIo The virtio device which will use the ring. + @param[in] The number of descriptors to allocate for the virtio ring, as requested by the host. @param[out] Ring The virtio ring to set up. - @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous - pages for the requested QueueSize. Fields of - Ring have indeterminate value. + @return Status codes propagated from + VirtIo->AllocateSharedPages(). @retval EFI_SUCCESS Allocation and setup successful. Ring->Base (and nothing else) is responsible for @@ -112,11 +53,38 @@ VirtioRead ( EFI_STATUS EFIAPI VirtioRingInit ( - IN UINT16 QueueSize, - OUT VRING *Ring + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINT16 QueueSize, + OUT VRING *Ring ); +/** + + Map the ring buffer so that it can be accessed equally by both guest + and hypervisor. + + @param[in] VirtIo The virtio device instance. + + @param[in] Ring The virtio ring to map. + + @param[out] RingBaseShift A resulting translation offset, to be + passed to VirtIo->SetQueueAddress(). + + @param[out] Mapping A resulting token to pass to + VirtIo->UnmapSharedBuffer(). + + @return Status code from VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioRingMap ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VRING *Ring, + OUT UINT64 *RingBaseShift, + OUT VOID **Mapping + ); + /** Tear down the internal resources of a configured virtio ring. @@ -125,13 +93,16 @@ VirtioRingInit ( invoking this function: the VSTAT_DRIVER_OK bit must be clear in VhdrDeviceStatus. - @param[out] Ring The virtio ring to clean up. + @param[in] VirtIo The virtio device which was using the ring. + + @param[out] Ring The virtio ring to clean up. **/ VOID EFIAPI VirtioRingUninit ( - IN OUT VRING *Ring + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN OUT VRING *Ring ); @@ -180,34 +151,34 @@ VirtioPrepare ( The caller is responsible for initializing *Indices with VirtioPrepare() first. - @param[in out] Ring The virtio ring to append the buffer to, as a - descriptor. - - @param [in] BufferPhysAddr (Guest pseudo-physical) start address of the - transmit / receive buffer. + @param[in,out] Ring The virtio ring to append the buffer to, + as a descriptor. - @param [in] BufferSize Number of bytes to transmit or receive. + @param[in] BufferDeviceAddress (Bus master device) start address of the + transmit / receive buffer. - @param [in] Flags A 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. + @param[in] BufferSize Number of bytes to transmit or receive. - In *Indices: + @param[in] Flags A 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. - @param [in out] NextDescIdx On input, the index identifying the next - descriptor to carry the buffer. On output, - incremented by one, modulo 2^16. + @param[in,out] Indices Indices->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. **/ VOID EFIAPI VirtioAppendDesc ( IN OUT VRING *Ring, - IN UINTN BufferPhysAddr, + IN UINT64 BufferDeviceAddress, IN UINT32 BufferSize, IN UINT16 Flags, IN OUT DESC_INDICES *Indices @@ -219,19 +190,24 @@ VirtioAppendDesc ( Notify the host about the descriptor chain just built, and wait until the host processes it. - @param[in] PciIo The target virtio PCI device to notify. + @param[in] VirtIo The target virtio device to notify. @param[in] VirtQueueId Identifies the queue for the target device. - @param[in out] Ring The virtio ring with descriptors to submit. - - In *Indices: + @param[in,out] Ring The virtio ring with descriptors to submit. - @param[in] HeadDescIdx Identifies the head descriptor of the descriptor - chain. + @param[in] Indices Indices->NextDescIdx is not accessed. + Indices->HeadDescIdx identifies the head descriptor + of the descriptor chain. + @param[out] UsedLen On 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. - @return Error code from VirtioWrite() if it fails. + @return Error code from VirtIo->SetQueueNotify() if it fails. @retval EFI_SUCCESS Otherwise, the host processed all descriptors. @@ -239,10 +215,108 @@ VirtioAppendDesc ( EFI_STATUS EFIAPI VirtioFlush ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN UINT16 VirtQueueId, - IN OUT VRING *Ring, - IN DESC_INDICES *Indices + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINT16 VirtQueueId, + IN OUT VRING *Ring, + IN DESC_INDICES *Indices, + OUT UINT32 *UsedLen OPTIONAL + ); + + +/** + + 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. + + @param[in] VirtIo Report feature bits to this device. + + @param[in] Features The 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(). + + @param[in,out] DeviceStatus On 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. + + @retval EFI_SUCCESS The device accepted the configuration in Features. + + @return EFI_UNSUPPORTED The device rejected the configuration in Features. + + @retval EFI_UNSUPPORTED VirtIo->Revision is smaller than 1.0.0. + + @return Error codes from the SetGuestFeatures(), + SetDeviceStatus(), GetDeviceStatus() member + functions. + +**/ +EFI_STATUS +EFIAPI +Virtio10WriteFeatures ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINT64 Features, + IN OUT UINT8 *DeviceStatus ); +/** + 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. + + @param[in] VirtIo The virtio device for which the mapping is + requested. + + @param[in] Operation Indicates if the bus master is going to + read or write to system memory. + + @param[in] HostAddress The system memory address to map to shared + buffer address. + + @param[in] NumberOfBytes Number of bytes to map. + + @param[out] DeviceAddress The resulting shared map address for the + bus master to access the hosts HostAddress. + + @param[out] Mapping A resulting token to pass to + VIRTIO_UNMAP_SHARED. + + + @retval EFI_SUCCESS The NumberOfBytes is succesfully mapped. + @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a + common buffer. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The 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. + @retval EFI_DEVICE_ERROR The system hardware could not map the + requested address. +**/ +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 + ); #endif // _VIRTIO_LIB_H_