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