4 DISCLAIMER: the VIRTIO_DEVICE_PROTOCOL introduced here is a work in progress,
5 and should not be used outside of the EDK II tree.
7 Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
9 This program and the accompanying materials are licensed and made available
10 under the terms and conditions of the BSD License which accompanies this
11 distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
15 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #ifndef __VIRTIO_DEVICE_H__
20 #define __VIRTIO_DEVICE_H__
22 // VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0
23 #define VIRTIO_SPEC_REVISION(major,minor,revision) \
24 ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))
26 #define VIRTIO_DEVICE_PROTOCOL_GUID { \
27 0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\
30 typedef struct _VIRTIO_DEVICE_PROTOCOL VIRTIO_DEVICE_PROTOCOL
;
34 Read a word from the device-specific I/O region of the Virtio Header.
36 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
38 @param[in] FieldOffset Source offset.
40 @param[in] FieldSize Source field size in bytes, must be in {1, 2, 4, 8}.
42 @param[in] BufferSize Number of bytes available in the target buffer. Must
45 @param[out] Buffer Target buffer.
47 @retval EFI_SUCCESS The data was read successfully.
48 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
49 provided address offset and read size.
50 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
52 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
57 (EFIAPI
*VIRTIO_DEVICE_READ
) (
58 IN VIRTIO_DEVICE_PROTOCOL
*This
,
67 Write a word to the device-specific I/O region of the Virtio Header.
69 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
71 @param[in] FieldOffset Destination offset.
73 @param[in] FieldSize Destination field size in bytes,
74 must be in {1, 2, 4, 8}.
76 @param[out] Value Value to write.
78 @retval EFI_SUCCESS The data was written successfully.
79 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
80 provided address offset and write size.
81 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
83 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
88 (EFIAPI
*VIRTIO_DEVICE_WRITE
) (
89 IN VIRTIO_DEVICE_PROTOCOL
*This
,
96 Read the device features field from the Virtio Header.
98 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
100 @param[out] DeviceFeatures The device features field.
102 @retval EFI_SUCCESS The data was read successfully.
103 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
104 provided address offset and read size.
105 @retval EFI_INVALID_PARAMETER DeviceFeatures is NULL
109 (EFIAPI
*VIRTIO_GET_DEVICE_FEATURES
) (
110 IN VIRTIO_DEVICE_PROTOCOL
*This
,
111 OUT UINT64
*DeviceFeatures
115 Write the guest features field in the Virtio Header.
117 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
119 @param[in] Features The guest features field
124 (EFIAPI
*VIRTIO_SET_GUEST_FEATURES
) (
125 IN VIRTIO_DEVICE_PROTOCOL
*This
,
130 Read the queue address field from the Virtio Header.
132 QueueAddress is the address of the virtqueue divided by 4096.
134 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
136 @param[out] QueueAddress The 32-bit queue address field.
138 @retval EFI_SUCCESS The data was read successfully.
139 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
140 provided address offset and read size.
141 @retval EFI_INVALID_PARAMETER QueueAddress is NULL
145 (EFIAPI
*VIRTIO_GET_QUEUE_ADDRESS
) (
146 IN VIRTIO_DEVICE_PROTOCOL
*This
,
147 OUT UINT32
*QueueAddress
151 Write the queue address field in the Virtio Header.
153 The parameter Address must be the base address of the virtqueue divided
156 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
158 @param[in] Address The 32-bit Queue Address field
160 @retval EFI_SUCCESS The data was written successfully.
161 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
162 provided address offset and write size.
166 (EFIAPI
*VIRTIO_SET_QUEUE_ADDRESS
) (
167 IN VIRTIO_DEVICE_PROTOCOL
*This
,
173 Write the queue select field in the Virtio Header.
175 Writing to the queue select field sets the index of the queue to which
176 operations such as SetQueueAlign and GetQueueNumMax apply.
178 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
180 @param[in] Index The index of the queue to select
182 @retval EFI_SUCCESS The data was written successfully.
183 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
184 provided address offset and write size.
188 (EFIAPI
*VIRTIO_SET_QUEUE_SEL
) (
189 IN VIRTIO_DEVICE_PROTOCOL
*This
,
195 Write the queue notify field in the Virtio Header.
197 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
199 @param[in] Address The 32-bit Queue Notify field
201 @retval EFI_SUCCESS The data was written successfully.
202 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
203 provided address offset and write size.
207 (EFIAPI
*VIRTIO_SET_QUEUE_NOTIFY
) (
208 IN VIRTIO_DEVICE_PROTOCOL
*This
,
213 Write the queue alignment field in the Virtio Header.
215 The queue to which the alignment applies is selected by the Queue Select
218 Note: This operation is not implemented by the VirtIo over PCI. The PCI
219 implementation of this protocol returns EFI_SUCCESS.
221 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
223 @param[in] Alignment The alignment boundary of the Used Ring in bytes.
224 Must be a power of 2.
226 @retval EFI_SUCCESS The data was written successfully.
227 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
228 provided address offset and write size.
232 (EFIAPI
*VIRTIO_SET_QUEUE_ALIGN
) (
233 IN VIRTIO_DEVICE_PROTOCOL
*This
,
238 Write the guest page size.
240 Note: This operation is not implemented by the VirtIo over PCI. The PCI
241 implementation of this protocol returns EFI_SUCCESS.
243 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
245 @param[in] PageSize Size of the Guest page in bytes.
246 Must be a power of 2.
248 @retval EFI_SUCCESS The data was written successfully.
249 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
250 provided address offset and write size.
254 (EFIAPI
*VIRTIO_SET_PAGE_SIZE
) (
255 IN VIRTIO_DEVICE_PROTOCOL
*This
,
261 Get the size of the virtqueue selected by the queue select field.
263 See Virtio spec Section 2.3
265 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
267 @param[out] QueueNumMax The size of the virtqueue in bytes.
270 @retval EFI_SUCCESS The data was read successfully.
271 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
272 provided address offset and read size.
273 @retval EFI_INVALID_PARAMETER QueueNumMax is NULL
277 (EFIAPI
*VIRTIO_GET_QUEUE_NUM_MAX
) (
278 IN VIRTIO_DEVICE_PROTOCOL
*This
,
279 OUT UINT16
*QueueNumMax
284 Write to the QueueNum field in the Virtio Header.
286 This function only applies to Virtio-MMIO and may be a stub for other
287 implementations. See Virtio Spec appendix X.
289 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
291 @param[in] QueueSize The number of elements in the queue.
293 @retval EFI_SUCCESS The data was written successfully.
294 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
295 provided address offset and write size.
299 (EFIAPI
*VIRTIO_SET_QUEUE_NUM
) (
300 IN VIRTIO_DEVICE_PROTOCOL
*This
,
306 Get the DeviceStatus field from the Virtio Header.
308 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
310 @param[out] DeviceStatus The 8-bit value for the Device status field
312 @retval EFI_SUCCESS The data was read successfully.
313 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
314 provided address offset and read size.
315 @retval EFI_INVALID_PARAMETER DeviceStatus is NULL
319 (EFIAPI
*VIRTIO_GET_DEVICE_STATUS
) (
320 IN VIRTIO_DEVICE_PROTOCOL
*This
,
321 OUT UINT8
*DeviceStatus
326 Write the DeviceStatus field in the Virtio Header.
328 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
330 @param[in] DeviceStatus The 8-bit value for the Device status field
332 @retval EFI_SUCCESS The data was written successfully.
333 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
334 provided address offset and write size.
338 (EFIAPI
*VIRTIO_SET_DEVICE_STATUS
) (
339 IN VIRTIO_DEVICE_PROTOCOL
*This
,
340 IN UINT8 DeviceStatus
345 /// This protocol provides an abstraction over the VirtIo transport layer
347 /// DISCLAIMER: this protocol is a work in progress, and should not be used
348 /// outside of the EDK II tree.
350 struct _VIRTIO_DEVICE_PROTOCOL
{
351 /// VirtIo Specification Revision encoded with VIRTIO_SPEC_REVISION()
353 /// From the Virtio Spec
354 INT32 SubSystemDeviceId
;
356 VIRTIO_GET_DEVICE_FEATURES GetDeviceFeatures
;
357 VIRTIO_SET_GUEST_FEATURES SetGuestFeatures
;
359 VIRTIO_GET_QUEUE_ADDRESS GetQueueAddress
;
360 VIRTIO_SET_QUEUE_ADDRESS SetQueueAddress
;
362 VIRTIO_SET_QUEUE_SEL SetQueueSel
;
364 VIRTIO_SET_QUEUE_NOTIFY SetQueueNotify
;
366 VIRTIO_SET_QUEUE_ALIGN SetQueueAlign
;
367 VIRTIO_SET_PAGE_SIZE SetPageSize
;
369 VIRTIO_GET_QUEUE_NUM_MAX GetQueueNumMax
;
370 VIRTIO_SET_QUEUE_NUM SetQueueNum
;
372 VIRTIO_GET_DEVICE_STATUS GetDeviceStatus
;
373 VIRTIO_SET_DEVICE_STATUS SetDeviceStatus
;
375 // Functions to read/write Device Specific headers
376 VIRTIO_DEVICE_WRITE WriteDevice
;
377 VIRTIO_DEVICE_READ ReadDevice
;
380 extern EFI_GUID gVirtioDeviceProtocolGuid
;