]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Include/Protocol/VirtioDevice.h
OvmfPkg: VIRTIO_DEVICE_PROTOCOL: pass VRING object to SetQueueAddress()
[mirror_edk2.git] / OvmfPkg / Include / Protocol / VirtioDevice.h
CommitLineData
fc4d1ce5
OM
1/** @file\r
2 Virtio Device\r
3\r
4 DISCLAIMER: the VIRTIO_DEVICE_PROTOCOL introduced here is a work in progress,\r
5 and should not be used outside of the EDK II tree.\r
6\r
7 Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>\r
8\r
9 This program and the accompanying materials are licensed and made available\r
10 under the terms and conditions of the BSD License which accompanies this\r
11 distribution. The full text of the license may be found at\r
12 http://opensource.org/licenses/bsd-license.php\r
13\r
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
15 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18\r
19#ifndef __VIRTIO_DEVICE_H__\r
20#define __VIRTIO_DEVICE_H__\r
21\r
07af4eee
LE
22#include <IndustryStandard/Virtio.h>\r
23\r
fc4d1ce5
OM
24// VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0\r
25#define VIRTIO_SPEC_REVISION(major,minor,revision) \\r
26 ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))\r
27\r
28#define VIRTIO_DEVICE_PROTOCOL_GUID { \\r
29 0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\\r
30 }\r
31\r
32typedef struct _VIRTIO_DEVICE_PROTOCOL VIRTIO_DEVICE_PROTOCOL;\r
33\r
34/**\r
35\r
36 Read a word from the device-specific I/O region of the Virtio Header.\r
37\r
38 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
39\r
40 @param[in] FieldOffset Source offset.\r
41\r
42 @param[in] FieldSize Source field size in bytes, must be in {1, 2, 4, 8}.\r
43\r
44 @param[in] BufferSize Number of bytes available in the target buffer. Must\r
45 equal FieldSize.\r
46\r
47 @param[out] Buffer Target buffer.\r
48\r
49 @retval EFI_SUCCESS The data was read successfully.\r
50 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
51 provided address offset and read size.\r
52 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a\r
53 lack of resources.\r
54 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
55\r
56**/\r
57typedef\r
58EFI_STATUS\r
59(EFIAPI *VIRTIO_DEVICE_READ) (\r
60 IN VIRTIO_DEVICE_PROTOCOL *This,\r
61 IN UINTN FieldOffset,\r
62 IN UINTN FieldSize,\r
63 IN UINTN BufferSize,\r
64 OUT VOID *Buffer\r
65 );\r
66\r
67/**\r
68\r
69 Write a word to the device-specific I/O region of the Virtio Header.\r
70\r
71 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
72\r
73 @param[in] FieldOffset Destination offset.\r
74\r
75 @param[in] FieldSize Destination field size in bytes,\r
76 must be in {1, 2, 4, 8}.\r
77\r
78 @param[out] Value Value to write.\r
79\r
80 @retval EFI_SUCCESS The data was written successfully.\r
81 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
82 provided address offset and write size.\r
83 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a\r
84 lack of resources.\r
85 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
86\r
87**/\r
88typedef\r
89EFI_STATUS\r
90(EFIAPI *VIRTIO_DEVICE_WRITE) (\r
91 IN VIRTIO_DEVICE_PROTOCOL *This,\r
92 IN UINTN FieldOffset,\r
93 IN UINTN FieldSize,\r
94 IN UINT64 Value\r
95 );\r
96\r
97/**\r
98 Read the device features field from the Virtio Header.\r
99\r
100 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
101\r
bc8fde6f 102 @param[out] DeviceFeatures The device features field.\r
fc4d1ce5
OM
103\r
104 @retval EFI_SUCCESS The data was read successfully.\r
105 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
106 provided address offset and read size.\r
107 @retval EFI_INVALID_PARAMETER DeviceFeatures is NULL\r
108**/\r
109typedef\r
110EFI_STATUS\r
111(EFIAPI *VIRTIO_GET_DEVICE_FEATURES) (\r
112 IN VIRTIO_DEVICE_PROTOCOL *This,\r
bc8fde6f 113 OUT UINT64 *DeviceFeatures\r
fc4d1ce5
OM
114 );\r
115\r
116/**\r
117 Write the guest features field in the Virtio Header.\r
118\r
119 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
120\r
bc8fde6f 121 @param[in] Features The guest features field\r
fc4d1ce5
OM
122\r
123**/\r
124typedef\r
125EFI_STATUS\r
126(EFIAPI *VIRTIO_SET_GUEST_FEATURES) (\r
127 IN VIRTIO_DEVICE_PROTOCOL *This,\r
bc8fde6f 128 IN UINT64 Features\r
fc4d1ce5
OM
129 );\r
130\r
fc4d1ce5 131/**\r
07af4eee 132 Write the queue address field(s) in the Virtio Header.\r
fc4d1ce5
OM
133\r
134 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
135\r
07af4eee
LE
136 @param[in] Ring The initialized VRING object to take the\r
137 addresses from.\r
fc4d1ce5
OM
138\r
139 @retval EFI_SUCCESS The data was written successfully.\r
140 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
141 provided address offset and write size.\r
142**/\r
143typedef\r
144EFI_STATUS\r
145(EFIAPI *VIRTIO_SET_QUEUE_ADDRESS) (\r
146 IN VIRTIO_DEVICE_PROTOCOL *This,\r
07af4eee 147 IN VRING *Ring\r
fc4d1ce5
OM
148 );\r
149\r
150/**\r
151\r
152 Write the queue select field in the Virtio Header.\r
153\r
154 Writing to the queue select field sets the index of the queue to which\r
155 operations such as SetQueueAlign and GetQueueNumMax apply.\r
156\r
157 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
158\r
159 @param[in] Index The index of the queue to select\r
160\r
161 @retval EFI_SUCCESS The data was written successfully.\r
162 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
163 provided address offset and write size.\r
164**/\r
165typedef\r
166EFI_STATUS\r
167(EFIAPI *VIRTIO_SET_QUEUE_SEL) (\r
168 IN VIRTIO_DEVICE_PROTOCOL *This,\r
169 IN UINT16 Index\r
170 );\r
171\r
172/**\r
173\r
174 Write the queue notify field in the Virtio Header.\r
175\r
176 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
177\r
178 @param[in] Address The 32-bit Queue Notify field\r
179\r
180 @retval EFI_SUCCESS The data was written successfully.\r
181 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
182 provided address offset and write size.\r
183**/\r
184typedef\r
185EFI_STATUS\r
186(EFIAPI *VIRTIO_SET_QUEUE_NOTIFY) (\r
187 IN VIRTIO_DEVICE_PROTOCOL *This,\r
188 IN UINT16 Index\r
189 );\r
190\r
191/**\r
192 Write the queue alignment field in the Virtio Header.\r
193\r
194 The queue to which the alignment applies is selected by the Queue Select\r
195 field.\r
196\r
197 Note: This operation is not implemented by the VirtIo over PCI. The PCI\r
198 implementation of this protocol returns EFI_SUCCESS.\r
199\r
200 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
201\r
202 @param[in] Alignment The alignment boundary of the Used Ring in bytes.\r
203 Must be a power of 2.\r
204\r
205 @retval EFI_SUCCESS The data was written successfully.\r
206 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
207 provided address offset and write size.\r
208**/\r
209typedef\r
210EFI_STATUS\r
211(EFIAPI *VIRTIO_SET_QUEUE_ALIGN) (\r
212 IN VIRTIO_DEVICE_PROTOCOL *This,\r
213 IN UINT32 Alignment\r
214 );\r
215\r
216/**\r
217 Write the guest page size.\r
218\r
219 Note: This operation is not implemented by the VirtIo over PCI. The PCI\r
220 implementation of this protocol returns EFI_SUCCESS.\r
221\r
222 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
223\r
224 @param[in] PageSize Size of the Guest page in bytes.\r
225 Must be a power of 2.\r
226\r
227 @retval EFI_SUCCESS The data was written successfully.\r
228 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
229 provided address offset and write size.\r
230**/\r
231typedef\r
232EFI_STATUS\r
233(EFIAPI *VIRTIO_SET_PAGE_SIZE) (\r
234 IN VIRTIO_DEVICE_PROTOCOL *This,\r
235 IN UINT32 PageSize\r
236 );\r
237\r
238/**\r
239\r
240 Get the size of the virtqueue selected by the queue select field.\r
241\r
242 See Virtio spec Section 2.3\r
243\r
244 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
245\r
246 @param[out] QueueNumMax The size of the virtqueue in bytes.\r
247 Always a power of 2.\r
248\r
249 @retval EFI_SUCCESS The data was read successfully.\r
250 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
251 provided address offset and read size.\r
252 @retval EFI_INVALID_PARAMETER QueueNumMax is NULL\r
253**/\r
254typedef\r
255EFI_STATUS\r
256(EFIAPI *VIRTIO_GET_QUEUE_NUM_MAX) (\r
257 IN VIRTIO_DEVICE_PROTOCOL *This,\r
258 OUT UINT16 *QueueNumMax\r
259 );\r
260\r
261/**\r
262\r
263 Write to the QueueNum field in the Virtio Header.\r
264\r
265 This function only applies to Virtio-MMIO and may be a stub for other\r
266 implementations. See Virtio Spec appendix X.\r
267\r
268 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
269\r
270 @param[in] QueueSize The number of elements in the queue.\r
271\r
272 @retval EFI_SUCCESS The data was written successfully.\r
273 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
274 provided address offset and write size.\r
275**/\r
276typedef\r
277EFI_STATUS\r
278(EFIAPI *VIRTIO_SET_QUEUE_NUM) (\r
279 IN VIRTIO_DEVICE_PROTOCOL *This,\r
280 IN UINT16 QueueSize\r
281 );\r
282\r
283/**\r
284\r
285 Get the DeviceStatus field from the Virtio Header.\r
286\r
287 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
288\r
289 @param[out] DeviceStatus The 8-bit value for the Device status field\r
290\r
291 @retval EFI_SUCCESS The data was read successfully.\r
292 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
293 provided address offset and read size.\r
294 @retval EFI_INVALID_PARAMETER DeviceStatus is NULL\r
295**/\r
296typedef\r
297EFI_STATUS\r
298(EFIAPI *VIRTIO_GET_DEVICE_STATUS) (\r
299 IN VIRTIO_DEVICE_PROTOCOL *This,\r
300 OUT UINT8 *DeviceStatus\r
301 );\r
302\r
303/**\r
304\r
305 Write the DeviceStatus field in the Virtio Header.\r
306\r
307 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
308\r
309 @param[in] DeviceStatus The 8-bit value for the Device status field\r
310\r
311 @retval EFI_SUCCESS The data was written successfully.\r
312 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
313 provided address offset and write size.\r
314**/\r
315typedef\r
316EFI_STATUS\r
317(EFIAPI *VIRTIO_SET_DEVICE_STATUS) (\r
318 IN VIRTIO_DEVICE_PROTOCOL *This,\r
319 IN UINT8 DeviceStatus\r
320 );\r
321\r
322\r
323///\r
324/// This protocol provides an abstraction over the VirtIo transport layer\r
325///\r
326/// DISCLAIMER: this protocol is a work in progress, and should not be used\r
327/// outside of the EDK II tree.\r
328///\r
329struct _VIRTIO_DEVICE_PROTOCOL {\r
330 /// VirtIo Specification Revision encoded with VIRTIO_SPEC_REVISION()\r
331 UINT32 Revision;\r
332 /// From the Virtio Spec\r
333 INT32 SubSystemDeviceId;\r
334\r
335 VIRTIO_GET_DEVICE_FEATURES GetDeviceFeatures;\r
336 VIRTIO_SET_GUEST_FEATURES SetGuestFeatures;\r
337\r
fc4d1ce5
OM
338 VIRTIO_SET_QUEUE_ADDRESS SetQueueAddress;\r
339\r
340 VIRTIO_SET_QUEUE_SEL SetQueueSel;\r
341\r
342 VIRTIO_SET_QUEUE_NOTIFY SetQueueNotify;\r
343\r
344 VIRTIO_SET_QUEUE_ALIGN SetQueueAlign;\r
345 VIRTIO_SET_PAGE_SIZE SetPageSize;\r
346\r
347 VIRTIO_GET_QUEUE_NUM_MAX GetQueueNumMax;\r
348 VIRTIO_SET_QUEUE_NUM SetQueueNum;\r
349\r
350 VIRTIO_GET_DEVICE_STATUS GetDeviceStatus;\r
351 VIRTIO_SET_DEVICE_STATUS SetDeviceStatus;\r
352\r
353 // Functions to read/write Device Specific headers\r
354 VIRTIO_DEVICE_WRITE WriteDevice;\r
355 VIRTIO_DEVICE_READ ReadDevice;\r
356};\r
357\r
358extern EFI_GUID gVirtioDeviceProtocolGuid;\r
359\r
360#endif\r