]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Include/Library/VirtioLib.h
OvmfPkg: rename AppendDesc to VirtioAppendDesc
[mirror_edk2.git] / OvmfPkg / Include / Library / VirtioLib.h
CommitLineData
263559b8 1/** @file\r
2\r
3 Declarations of utility functions used by virtio device drivers.\r
4\r
5 Copyright (C) 2012, Red Hat, Inc.\r
6\r
7 This program and the accompanying materials are licensed and made available\r
8 under the terms and conditions of the BSD License which accompanies this\r
9 distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
13 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#ifndef _VIRTIO_LIB_H_\r
18#define _VIRTIO_LIB_H_\r
19\r
20#include <Protocol/PciIo.h>\r
21#include <IndustryStandard/Virtio.h>\r
22\r
23/**\r
24\r
25 Write a word into Region 0 of the device specified by PciIo.\r
26\r
27 Region 0 must be an iomem region. This is an internal function for the\r
28 driver-specific VIRTIO_CFG_WRITE() macros.\r
29\r
30 @param[in] PciIo Target PCI device.\r
31\r
32 @param[in] FieldOffset Destination offset.\r
33\r
34 @param[in] FieldSize Destination field size, must be in { 1, 2, 4, 8 }.\r
35\r
36 @param[in] Value Little endian value to write, converted to UINT64.\r
37 The least significant FieldSize bytes will be used.\r
38\r
39\r
40 @return Status code returned by PciIo->Io.Write().\r
41\r
42**/\r
43EFIAPI\r
44EFI_STATUS\r
45VirtioWrite (\r
46 IN EFI_PCI_IO_PROTOCOL *PciIo,\r
47 IN UINTN FieldOffset,\r
48 IN UINTN FieldSize,\r
49 IN UINT64 Value\r
50 );\r
51\r
52\r
53/**\r
54\r
55 Read a word from Region 0 of the device specified by PciIo.\r
56\r
57 Region 0 must be an iomem region. This is an internal function for the\r
58 driver-specific VIRTIO_CFG_READ() macros.\r
59\r
60 @param[in] PciIo Source PCI device.\r
61\r
62 @param[in] FieldOffset Source offset.\r
63\r
64 @param[in] FieldSize Source field size, must be in { 1, 2, 4, 8 }.\r
65\r
66 @param[in] BufferSize Number of bytes available in the target buffer. Must\r
67 equal FieldSize.\r
68\r
69 @param[out] Buffer Target buffer.\r
70\r
71\r
72 @return Status code returned by PciIo->Io.Read().\r
73\r
74**/\r
75EFIAPI\r
76EFI_STATUS\r
77VirtioRead (\r
78 IN EFI_PCI_IO_PROTOCOL *PciIo,\r
79 IN UINTN FieldOffset,\r
80 IN UINTN FieldSize,\r
81 IN UINTN BufferSize,\r
82 OUT VOID *Buffer\r
83 );\r
84\r
85\r
86/**\r
87\r
88 Configure a virtio ring.\r
89\r
90 This function sets up internal storage (the guest-host communication area)\r
91 and lays out several "navigation" (ie. no-ownership) pointers to parts of\r
92 that storage.\r
93\r
94 Relevant sections from the virtio-0.9.5 spec:\r
95 - 1.1 Virtqueues,\r
96 - 2.3 Virtqueue Configuration.\r
97\r
98 @param[in] The number of descriptors to allocate for the\r
99 virtio ring, as requested by the host.\r
100\r
101 @param[out] Ring The virtio ring to set up.\r
102\r
103 @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous\r
104 pages for the requested QueueSize. Fields of\r
105 Ring have indeterminate value.\r
106\r
107 @retval EFI_SUCCESS Allocation and setup successful. Ring->Base\r
108 (and nothing else) is responsible for\r
109 deallocation.\r
110\r
111**/\r
112EFI_STATUS\r
113EFIAPI\r
114VirtioRingInit (\r
115 IN UINT16 QueueSize,\r
116 OUT VRING *Ring\r
117 );\r
118\r
119\r
120/**\r
121\r
122 Tear down the internal resources of a configured virtio ring.\r
123\r
124 The caller is responsible to stop the host from using this ring before\r
125 invoking this function: the VSTAT_DRIVER_OK bit must be clear in\r
126 VhdrDeviceStatus.\r
127\r
128 @param[out] Ring The virtio ring to clean up.\r
129\r
130**/\r
131VOID\r
132EFIAPI\r
133VirtioRingUninit (\r
134 IN OUT VRING *Ring\r
135 );\r
136\r
137\r
138/**\r
139\r
140 Append a contiguous buffer for transmission / reception via the virtio ring.\r
141\r
142 This function implements the following sections from virtio-0.9.5:\r
143 - 2.4.1.1 Placing Buffers into the Descriptor Table\r
144 - 2.4.1.2 Updating the Available Ring\r
145\r
146 Free space is taken as granted, since the individual drivers support only\r
147 synchronous requests and host side status is processed in lock-step with\r
148 request submission. It is the calling driver's responsibility to verify the\r
149 ring size in advance.\r
150\r
151 @param[in out] Ring The virtio ring to append the buffer to, as a\r
152 descriptor.\r
153\r
154 @param [in] BufferPhysAddr (Guest pseudo-physical) start address of the\r
155 transmit / receive buffer.\r
156\r
157 @param [in] BufferSize Number of bytes to transmit or receive.\r
158\r
159 @param [in] Flags A bitmask of VRING_DESC_F_* flags. The caller\r
160 computes this mask dependent on further buffers\r
161 to append and transfer direction.\r
162 VRING_DESC_F_INDIRECT is unsupported. The\r
163 VRING_DESC.Next field is always set, but the\r
164 host only interprets it dependent on\r
165 VRING_DESC_F_NEXT.\r
166\r
167 @param [in] HeadIdx The index identifying the head buffer (first\r
168 buffer appended) belonging to this same\r
169 request.\r
170\r
171 @param [in out] NextAvailIdx On input, the index identifying the next\r
172 descriptor available to carry the buffer. On\r
173 output, incremented by one, modulo 2^16.\r
174\r
175**/\r
176VOID\r
177EFIAPI\r
7fcacd6c 178VirtioAppendDesc (\r
263559b8 179 IN OUT VRING *Ring,\r
180 IN UINTN BufferPhysAddr,\r
181 IN UINT32 BufferSize,\r
182 IN UINT16 Flags,\r
183 IN UINT16 HeadIdx,\r
184 IN OUT UINT16 *NextAvailIdx\r
185 );\r
186\r
187#endif // _VIRTIO_LIB_H_\r