]>
git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Include/Library/VirtioLib.h
3 Declarations of utility functions used by virtio device drivers.
5 Copyright (C) 2012, 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_LIB_H_
18 #define _VIRTIO_LIB_H_
20 #include <Protocol/PciIo.h>
21 #include <IndustryStandard/Virtio.h>
25 Write a word into Region 0 of the device specified by PciIo.
27 Region 0 must be an iomem region. This is an internal function for the
28 driver-specific VIRTIO_CFG_WRITE() macros.
30 @param[in] PciIo Target PCI device.
32 @param[in] FieldOffset Destination offset.
34 @param[in] FieldSize Destination field size, must be in { 1, 2, 4, 8 }.
36 @param[in] Value Little endian value to write, converted to UINT64.
37 The least significant FieldSize bytes will be used.
40 @return Status code returned by PciIo->Io.Write().
46 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
55 Read a word from Region 0 of the device specified by PciIo.
57 Region 0 must be an iomem region. This is an internal function for the
58 driver-specific VIRTIO_CFG_READ() macros.
60 @param[in] PciIo Source PCI device.
62 @param[in] FieldOffset Source offset.
64 @param[in] FieldSize Source field size, must be in { 1, 2, 4, 8 }.
66 @param[in] BufferSize Number of bytes available in the target buffer. Must
69 @param[out] Buffer Target buffer.
72 @return Status code returned by PciIo->Io.Read().
78 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
88 Configure a virtio ring.
90 This function sets up internal storage (the guest-host communication area)
91 and lays out several "navigation" (ie. no-ownership) pointers to parts of
94 Relevant sections from the virtio-0.9.5 spec:
96 - 2.3 Virtqueue Configuration.
98 @param[in] The number of descriptors to allocate for the
99 virtio ring, as requested by the host.
101 @param[out] Ring The virtio ring to set up.
103 @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous
104 pages for the requested QueueSize. Fields of
105 Ring have indeterminate value.
107 @retval EFI_SUCCESS Allocation and setup successful. Ring->Base
108 (and nothing else) is responsible for
122 Tear down the internal resources of a configured virtio ring.
124 The caller is responsible to stop the host from using this ring before
125 invoking this function: the VSTAT_DRIVER_OK bit must be clear in
128 @param[out] Ring The virtio ring to clean up.
140 Append a contiguous buffer for transmission / reception via the virtio ring.
142 This function implements the following sections from virtio-0.9.5:
143 - 2.4.1.1 Placing Buffers into the Descriptor Table
144 - 2.4.1.2 Updating the Available Ring
146 Free space is taken as granted, since the individual drivers support only
147 synchronous requests and host side status is processed in lock-step with
148 request submission. It is the calling driver's responsibility to verify the
149 ring size in advance.
151 @param[in out] Ring The virtio ring to append the buffer to, as a
154 @param [in] BufferPhysAddr (Guest pseudo-physical) start address of the
155 transmit / receive buffer.
157 @param [in] BufferSize Number of bytes to transmit or receive.
159 @param [in] Flags A bitmask of VRING_DESC_F_* flags. The caller
160 computes this mask dependent on further buffers
161 to append and transfer direction.
162 VRING_DESC_F_INDIRECT is unsupported. The
163 VRING_DESC.Next field is always set, but the
164 host only interprets it dependent on
167 @param [in] HeadIdx The index identifying the head buffer (first
168 buffer appended) belonging to this same
171 @param [in out] NextAvailIdx On input, the index identifying the next
172 descriptor available to carry the buffer. On
173 output, incremented by one, modulo 2^16.
180 IN UINTN BufferPhysAddr
,
181 IN UINT32 BufferSize
,
184 IN OUT UINT16
*NextAvailIdx
187 #endif // _VIRTIO_LIB_H_