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 #include <IndustryStandard/Virtio.h>
25 // VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0]
27 #define VIRTIO_SPEC_REVISION(major,minor,revision) \
28 ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))
30 #define VIRTIO_DEVICE_PROTOCOL_GUID { \
31 0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\
34 typedef struct _VIRTIO_DEVICE_PROTOCOL VIRTIO_DEVICE_PROTOCOL
;
38 Read a word from the device-specific I/O region of the Virtio Header.
40 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
42 @param[in] FieldOffset Source offset.
44 @param[in] FieldSize Source field size in bytes, must be in {1, 2, 4, 8}.
46 @param[in] BufferSize Number of bytes available in the target buffer. Must
49 @param[out] Buffer Target buffer.
51 @retval EFI_SUCCESS The data was read successfully.
52 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
53 provided address offset and read size.
54 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
56 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
61 (EFIAPI
*VIRTIO_DEVICE_READ
) (
62 IN VIRTIO_DEVICE_PROTOCOL
*This
,
71 Write a word to the device-specific I/O region of the Virtio Header.
73 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
75 @param[in] FieldOffset Destination offset.
77 @param[in] FieldSize Destination field size in bytes,
78 must be in {1, 2, 4, 8}.
80 @param[out] Value Value to write.
82 @retval EFI_SUCCESS The data was written successfully.
83 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
84 provided address offset and write size.
85 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
87 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
92 (EFIAPI
*VIRTIO_DEVICE_WRITE
) (
93 IN VIRTIO_DEVICE_PROTOCOL
*This
,
100 Read the device features field from the Virtio Header.
102 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
104 @param[out] DeviceFeatures The device features field.
106 @retval EFI_SUCCESS The data was read successfully.
107 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
108 provided address offset and read size.
109 @retval EFI_INVALID_PARAMETER DeviceFeatures is NULL
113 (EFIAPI
*VIRTIO_GET_DEVICE_FEATURES
) (
114 IN VIRTIO_DEVICE_PROTOCOL
*This
,
115 OUT UINT64
*DeviceFeatures
119 Write the guest features field in the Virtio Header.
121 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
123 @param[in] Features The guest features field
128 (EFIAPI
*VIRTIO_SET_GUEST_FEATURES
) (
129 IN VIRTIO_DEVICE_PROTOCOL
*This
,
134 Write the queue address field(s) in the Virtio Header.
136 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
138 @param[in] Ring The initialized VRING object to take the
141 @retval EFI_SUCCESS The data was written successfully.
142 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
143 provided address offset and write size.
147 (EFIAPI
*VIRTIO_SET_QUEUE_ADDRESS
) (
148 IN VIRTIO_DEVICE_PROTOCOL
*This
,
154 Write the queue select field in the Virtio Header.
156 Writing to the queue select field sets the index of the queue to which
157 operations such as SetQueueAlign and GetQueueNumMax apply.
159 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
161 @param[in] Index The index of the queue to select
163 @retval EFI_SUCCESS The data was written successfully.
164 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
165 provided address offset and write size.
169 (EFIAPI
*VIRTIO_SET_QUEUE_SEL
) (
170 IN VIRTIO_DEVICE_PROTOCOL
*This
,
176 Write the queue notify field in the Virtio Header.
178 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
180 @param[in] Address The 32-bit Queue Notify field
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_NOTIFY
) (
189 IN VIRTIO_DEVICE_PROTOCOL
*This
,
194 Write the queue alignment field in the Virtio Header.
196 The queue to which the alignment applies is selected by the Queue Select
199 Note: This operation is not implemented by the VirtIo over PCI. The PCI
200 implementation of this protocol returns EFI_SUCCESS.
202 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
204 @param[in] Alignment The alignment boundary of the Used Ring in bytes.
205 Must be a power of 2.
207 @retval EFI_SUCCESS The data was written successfully.
208 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
209 provided address offset and write size.
213 (EFIAPI
*VIRTIO_SET_QUEUE_ALIGN
) (
214 IN VIRTIO_DEVICE_PROTOCOL
*This
,
219 Write the guest page size.
221 Note: This operation is not implemented by the VirtIo over PCI. The PCI
222 implementation of this protocol returns EFI_SUCCESS.
224 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
226 @param[in] PageSize Size of the Guest page in bytes.
227 Must be a power of 2.
229 @retval EFI_SUCCESS The data was written successfully.
230 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
231 provided address offset and write size.
235 (EFIAPI
*VIRTIO_SET_PAGE_SIZE
) (
236 IN VIRTIO_DEVICE_PROTOCOL
*This
,
242 Get the size of the virtqueue selected by the queue select field.
244 See Virtio spec Section 2.3
246 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
248 @param[out] QueueNumMax The size of the virtqueue in bytes.
251 @retval EFI_SUCCESS The data was read successfully.
252 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
253 provided address offset and read size.
254 @retval EFI_INVALID_PARAMETER QueueNumMax is NULL
258 (EFIAPI
*VIRTIO_GET_QUEUE_NUM_MAX
) (
259 IN VIRTIO_DEVICE_PROTOCOL
*This
,
260 OUT UINT16
*QueueNumMax
265 Write to the QueueNum field in the Virtio Header.
267 This function only applies to Virtio-MMIO and may be a stub for other
268 implementations. See Virtio Spec appendix X.
270 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
272 @param[in] QueueSize The number of elements in the queue.
274 @retval EFI_SUCCESS The data was written successfully.
275 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
276 provided address offset and write size.
280 (EFIAPI
*VIRTIO_SET_QUEUE_NUM
) (
281 IN VIRTIO_DEVICE_PROTOCOL
*This
,
287 Get the DeviceStatus field from the Virtio Header.
289 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
291 @param[out] DeviceStatus The 8-bit value for the Device status field
293 @retval EFI_SUCCESS The data was read successfully.
294 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
295 provided address offset and read size.
296 @retval EFI_INVALID_PARAMETER DeviceStatus is NULL
300 (EFIAPI
*VIRTIO_GET_DEVICE_STATUS
) (
301 IN VIRTIO_DEVICE_PROTOCOL
*This
,
302 OUT UINT8
*DeviceStatus
307 Write the DeviceStatus field in the Virtio Header.
309 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
311 @param[in] DeviceStatus The 8-bit value for the Device status field
313 @retval EFI_SUCCESS The data was written successfully.
314 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
315 provided address offset and write size.
319 (EFIAPI
*VIRTIO_SET_DEVICE_STATUS
) (
320 IN VIRTIO_DEVICE_PROTOCOL
*This
,
321 IN UINT8 DeviceStatus
326 /// This protocol provides an abstraction over the VirtIo transport layer
328 /// DISCLAIMER: this protocol is a work in progress, and should not be used
329 /// outside of the EDK II tree.
331 struct _VIRTIO_DEVICE_PROTOCOL
{
333 // VirtIo Specification Revision encoded with VIRTIO_SPEC_REVISION()
337 // From the Virtio Spec
339 INT32 SubSystemDeviceId
;
341 VIRTIO_GET_DEVICE_FEATURES GetDeviceFeatures
;
342 VIRTIO_SET_GUEST_FEATURES SetGuestFeatures
;
344 VIRTIO_SET_QUEUE_ADDRESS SetQueueAddress
;
346 VIRTIO_SET_QUEUE_SEL SetQueueSel
;
348 VIRTIO_SET_QUEUE_NOTIFY SetQueueNotify
;
350 VIRTIO_SET_QUEUE_ALIGN SetQueueAlign
;
351 VIRTIO_SET_PAGE_SIZE SetPageSize
;
353 VIRTIO_GET_QUEUE_NUM_MAX GetQueueNumMax
;
354 VIRTIO_SET_QUEUE_NUM SetQueueNum
;
356 VIRTIO_GET_DEVICE_STATUS GetDeviceStatus
;
357 VIRTIO_SET_DEVICE_STATUS SetDeviceStatus
;
360 // Functions to read/write Device Specific headers
362 VIRTIO_DEVICE_WRITE WriteDevice
;
363 VIRTIO_DEVICE_READ ReadDevice
;
366 extern EFI_GUID gVirtioDeviceProtocolGuid
;