]>
Commit | Line | Data |
---|---|---|
263559b8 | 1 | /** @file\r |
2 | \r | |
3 | Declarations of utility functions used by virtio device drivers.\r | |
4 | \r | |
8bc951a2 | 5 | Copyright (C) 2012-2016, Red Hat, Inc.\r |
263559b8 | 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 | |
56f65ed8 OM |
20 | #include <Protocol/VirtioDevice.h>\r |
21 | \r | |
263559b8 | 22 | #include <IndustryStandard/Virtio.h>\r |
23 | \r | |
263559b8 | 24 | \r |
25 | /**\r | |
26 | \r | |
27 | Configure a virtio ring.\r | |
28 | \r | |
29 | This function sets up internal storage (the guest-host communication area)\r | |
30 | and lays out several "navigation" (ie. no-ownership) pointers to parts of\r | |
31 | that storage.\r | |
32 | \r | |
33 | Relevant sections from the virtio-0.9.5 spec:\r | |
34 | - 1.1 Virtqueues,\r | |
35 | - 2.3 Virtqueue Configuration.\r | |
36 | \r | |
37 | @param[in] The number of descriptors to allocate for the\r | |
38 | virtio ring, as requested by the host.\r | |
39 | \r | |
40 | @param[out] Ring The virtio ring to set up.\r | |
41 | \r | |
42 | @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous\r | |
43 | pages for the requested QueueSize. Fields of\r | |
44 | Ring have indeterminate value.\r | |
45 | \r | |
46 | @retval EFI_SUCCESS Allocation and setup successful. Ring->Base\r | |
47 | (and nothing else) is responsible for\r | |
48 | deallocation.\r | |
49 | \r | |
50 | **/\r | |
51 | EFI_STATUS\r | |
52 | EFIAPI\r | |
53 | VirtioRingInit (\r | |
54 | IN UINT16 QueueSize,\r | |
55 | OUT VRING *Ring\r | |
56 | );\r | |
57 | \r | |
58 | \r | |
59 | /**\r | |
60 | \r | |
61 | Tear down the internal resources of a configured virtio ring.\r | |
62 | \r | |
63 | The caller is responsible to stop the host from using this ring before\r | |
64 | invoking this function: the VSTAT_DRIVER_OK bit must be clear in\r | |
65 | VhdrDeviceStatus.\r | |
66 | \r | |
67 | @param[out] Ring The virtio ring to clean up.\r | |
68 | \r | |
69 | **/\r | |
70 | VOID\r | |
71 | EFIAPI\r | |
72 | VirtioRingUninit (\r | |
73 | IN OUT VRING *Ring\r | |
74 | );\r | |
75 | \r | |
76 | \r | |
e371e7e5 | 77 | //\r |
78 | // Internal use structure for tracking the submission of a multi-descriptor\r | |
79 | // request.\r | |
80 | //\r | |
81 | typedef struct {\r | |
635a3ca2 | 82 | UINT16 HeadDescIdx;\r |
83 | UINT16 NextDescIdx;\r | |
e371e7e5 | 84 | } DESC_INDICES;\r |
85 | \r | |
86 | \r | |
87 | /**\r | |
88 | \r | |
89 | Turn off interrupt notifications from the host, and prepare for appending\r | |
90 | multiple descriptors to the virtio ring.\r | |
91 | \r | |
92 | The calling driver must be in VSTAT_DRIVER_OK state.\r | |
93 | \r | |
f2965f4e | 94 | @param[in,out] Ring The virtio ring we intend to append descriptors to.\r |
e371e7e5 | 95 | \r |
96 | @param[out] Indices The DESC_INDICES structure to initialize.\r | |
97 | \r | |
98 | **/\r | |
99 | VOID\r | |
100 | EFIAPI\r | |
101 | VirtioPrepare (\r | |
102 | IN OUT VRING *Ring,\r | |
103 | OUT DESC_INDICES *Indices\r | |
104 | );\r | |
105 | \r | |
106 | \r | |
263559b8 | 107 | /**\r |
108 | \r | |
109 | Append a contiguous buffer for transmission / reception via the virtio ring.\r | |
110 | \r | |
635a3ca2 | 111 | This function implements the following section from virtio-0.9.5:\r |
263559b8 | 112 | - 2.4.1.1 Placing Buffers into the Descriptor Table\r |
263559b8 | 113 | \r |
114 | Free space is taken as granted, since the individual drivers support only\r | |
115 | synchronous requests and host side status is processed in lock-step with\r | |
116 | request submission. It is the calling driver's responsibility to verify the\r | |
117 | ring size in advance.\r | |
118 | \r | |
e371e7e5 | 119 | The caller is responsible for initializing *Indices with VirtioPrepare()\r |
120 | first.\r | |
121 | \r | |
11a5fdf4 | 122 | @param[in,out] Ring The virtio ring to append the buffer to, as a\r |
123 | descriptor.\r | |
124 | \r | |
125 | @param[in] BufferPhysAddr (Guest pseudo-physical) start address of the\r | |
126 | transmit / receive buffer.\r | |
127 | \r | |
128 | @param[in] BufferSize Number of bytes to transmit or receive.\r | |
129 | \r | |
130 | @param[in] Flags A bitmask of VRING_DESC_F_* flags. The caller\r | |
131 | computes this mask dependent on further buffers to\r | |
132 | append and transfer direction.\r | |
133 | VRING_DESC_F_INDIRECT is unsupported. The\r | |
134 | VRING_DESC.Next field is always set, but the host\r | |
135 | only interprets it dependent on VRING_DESC_F_NEXT.\r | |
136 | \r | |
137 | @param[in,out] Indices Indices->HeadDescIdx is not accessed.\r | |
138 | On input, Indices->NextDescIdx identifies the next\r | |
139 | descriptor to carry the buffer. On output,\r | |
140 | Indices->NextDescIdx is incremented by one, modulo\r | |
141 | 2^16.\r | |
263559b8 | 142 | \r |
143 | **/\r | |
144 | VOID\r | |
145 | EFIAPI\r | |
7fcacd6c | 146 | VirtioAppendDesc (\r |
e371e7e5 | 147 | IN OUT VRING *Ring,\r |
148 | IN UINTN BufferPhysAddr,\r | |
149 | IN UINT32 BufferSize,\r | |
150 | IN UINT16 Flags,\r | |
151 | IN OUT DESC_INDICES *Indices\r | |
152 | );\r | |
153 | \r | |
154 | \r | |
155 | /**\r | |
156 | \r | |
635a3ca2 | 157 | Notify the host about the descriptor chain just built, and wait until the\r |
158 | host processes it.\r | |
e371e7e5 | 159 | \r |
56f65ed8 | 160 | @param[in] VirtIo The target virtio device to notify.\r |
e371e7e5 | 161 | \r |
162 | @param[in] VirtQueueId Identifies the queue for the target device.\r | |
163 | \r | |
a7615fa8 | 164 | @param[in,out] Ring The virtio ring with descriptors to submit.\r |
e371e7e5 | 165 | \r |
a7615fa8 | 166 | @param[in] Indices Indices->NextDescIdx is not accessed.\r |
167 | Indices->HeadDescIdx identifies the head descriptor\r | |
168 | of the descriptor chain.\r | |
e371e7e5 | 169 | \r |
8bc951a2 LE |
170 | @param[out] UsedLen On success, the total number of bytes, consecutively\r |
171 | across the buffers linked by the descriptor chain,\r | |
172 | that the host wrote. May be NULL if the caller\r | |
173 | doesn't care, or can compute the same information\r | |
174 | from device-specific request structures linked by the\r | |
175 | descriptor chain.\r | |
e371e7e5 | 176 | \r |
56f65ed8 | 177 | @return Error code from VirtIo->SetQueueNotify() if it fails.\r |
e371e7e5 | 178 | \r |
179 | @retval EFI_SUCCESS Otherwise, the host processed all descriptors.\r | |
180 | \r | |
181 | **/\r | |
182 | EFI_STATUS\r | |
183 | EFIAPI\r | |
184 | VirtioFlush (\r | |
56f65ed8 OM |
185 | IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r |
186 | IN UINT16 VirtQueueId,\r | |
187 | IN OUT VRING *Ring,\r | |
8bc951a2 LE |
188 | IN DESC_INDICES *Indices,\r |
189 | OUT UINT32 *UsedLen OPTIONAL\r | |
263559b8 | 190 | );\r |
191 | \r | |
d0ece0d8 LE |
192 | \r |
193 | /**\r | |
194 | \r | |
195 | Report the feature bits to the VirtIo 1.0 device that the VirtIo 1.0 driver\r | |
196 | understands.\r | |
197 | \r | |
198 | In VirtIo 1.0, a device can reject a self-inconsistent feature bitmap through\r | |
199 | the new VSTAT_FEATURES_OK status bit. (For example if the driver requests a\r | |
200 | higher level feature but clears a prerequisite feature.) This function is a\r | |
201 | small wrapper around VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures() that also\r | |
202 | verifies if the VirtIo 1.0 device accepts the feature bitmap.\r | |
203 | \r | |
204 | @param[in] VirtIo Report feature bits to this device.\r | |
205 | \r | |
206 | @param[in] Features The set of feature bits that the driver wishes\r | |
207 | to report. The caller is responsible to perform\r | |
208 | any masking before calling this function; the\r | |
209 | value is directly written with\r | |
210 | VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures().\r | |
211 | \r | |
212 | @param[in,out] DeviceStatus On input, the status byte most recently written\r | |
213 | to the device's status register. On output (even\r | |
214 | on error), DeviceStatus will be updated so that\r | |
215 | it is suitable for further status bit\r | |
216 | manipulation and writing to the device's status\r | |
217 | register.\r | |
218 | \r | |
219 | @retval EFI_SUCCESS The device accepted the configuration in Features.\r | |
220 | \r | |
221 | @return EFI_UNSUPPORTED The device rejected the configuration in Features.\r | |
222 | \r | |
223 | @retval EFI_UNSUPPORTED VirtIo->Revision is smaller than 1.0.0.\r | |
224 | \r | |
225 | @return Error codes from the SetGuestFeatures(),\r | |
226 | SetDeviceStatus(), GetDeviceStatus() member\r | |
227 | functions.\r | |
228 | \r | |
229 | **/\r | |
230 | EFI_STATUS\r | |
231 | EFIAPI\r | |
232 | Virtio10WriteFeatures (\r | |
233 | IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r | |
234 | IN UINT64 Features,\r | |
235 | IN OUT UINT8 *DeviceStatus\r | |
236 | );\r | |
237 | \r | |
263559b8 | 238 | #endif // _VIRTIO_LIB_H_\r |