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 Write the queue address field in the Virtio Header.
132 The parameter Address must be the base address of the virtqueue divided
135 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
137 @param[in] Address The 32-bit Queue Address field
139 @retval EFI_SUCCESS The data was written successfully.
140 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
141 provided address offset and write size.
145 (EFIAPI
*VIRTIO_SET_QUEUE_ADDRESS
) (
146 IN VIRTIO_DEVICE_PROTOCOL
*This
,
152 Write the queue select field in the Virtio Header.
154 Writing to the queue select field sets the index of the queue to which
155 operations such as SetQueueAlign and GetQueueNumMax apply.
157 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
159 @param[in] Index The index of the queue to select
161 @retval EFI_SUCCESS The data was written successfully.
162 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
163 provided address offset and write size.
167 (EFIAPI
*VIRTIO_SET_QUEUE_SEL
) (
168 IN VIRTIO_DEVICE_PROTOCOL
*This
,
174 Write the queue notify field in the Virtio Header.
176 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
178 @param[in] Address The 32-bit Queue Notify field
180 @retval EFI_SUCCESS The data was written successfully.
181 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
182 provided address offset and write size.
186 (EFIAPI
*VIRTIO_SET_QUEUE_NOTIFY
) (
187 IN VIRTIO_DEVICE_PROTOCOL
*This
,
192 Write the queue alignment field in the Virtio Header.
194 The queue to which the alignment applies is selected by the Queue Select
197 Note: This operation is not implemented by the VirtIo over PCI. The PCI
198 implementation of this protocol returns EFI_SUCCESS.
200 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
202 @param[in] Alignment The alignment boundary of the Used Ring in bytes.
203 Must be a power of 2.
205 @retval EFI_SUCCESS The data was written successfully.
206 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
207 provided address offset and write size.
211 (EFIAPI
*VIRTIO_SET_QUEUE_ALIGN
) (
212 IN VIRTIO_DEVICE_PROTOCOL
*This
,
217 Write the guest page size.
219 Note: This operation is not implemented by the VirtIo over PCI. The PCI
220 implementation of this protocol returns EFI_SUCCESS.
222 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
224 @param[in] PageSize Size of the Guest page in bytes.
225 Must be a power of 2.
227 @retval EFI_SUCCESS The data was written successfully.
228 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
229 provided address offset and write size.
233 (EFIAPI
*VIRTIO_SET_PAGE_SIZE
) (
234 IN VIRTIO_DEVICE_PROTOCOL
*This
,
240 Get the size of the virtqueue selected by the queue select field.
242 See Virtio spec Section 2.3
244 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
246 @param[out] QueueNumMax The size of the virtqueue in bytes.
249 @retval EFI_SUCCESS The data was read successfully.
250 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
251 provided address offset and read size.
252 @retval EFI_INVALID_PARAMETER QueueNumMax is NULL
256 (EFIAPI
*VIRTIO_GET_QUEUE_NUM_MAX
) (
257 IN VIRTIO_DEVICE_PROTOCOL
*This
,
258 OUT UINT16
*QueueNumMax
263 Write to the QueueNum field in the Virtio Header.
265 This function only applies to Virtio-MMIO and may be a stub for other
266 implementations. See Virtio Spec appendix X.
268 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
270 @param[in] QueueSize The number of elements in the queue.
272 @retval EFI_SUCCESS The data was written successfully.
273 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
274 provided address offset and write size.
278 (EFIAPI
*VIRTIO_SET_QUEUE_NUM
) (
279 IN VIRTIO_DEVICE_PROTOCOL
*This
,
285 Get the DeviceStatus field from the Virtio Header.
287 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
289 @param[out] DeviceStatus The 8-bit value for the Device status field
291 @retval EFI_SUCCESS The data was read successfully.
292 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
293 provided address offset and read size.
294 @retval EFI_INVALID_PARAMETER DeviceStatus is NULL
298 (EFIAPI
*VIRTIO_GET_DEVICE_STATUS
) (
299 IN VIRTIO_DEVICE_PROTOCOL
*This
,
300 OUT UINT8
*DeviceStatus
305 Write the DeviceStatus field in the Virtio Header.
307 @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
309 @param[in] DeviceStatus The 8-bit value for the Device status field
311 @retval EFI_SUCCESS The data was written successfully.
312 @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
313 provided address offset and write size.
317 (EFIAPI
*VIRTIO_SET_DEVICE_STATUS
) (
318 IN VIRTIO_DEVICE_PROTOCOL
*This
,
319 IN UINT8 DeviceStatus
324 /// This protocol provides an abstraction over the VirtIo transport layer
326 /// DISCLAIMER: this protocol is a work in progress, and should not be used
327 /// outside of the EDK II tree.
329 struct _VIRTIO_DEVICE_PROTOCOL
{
330 /// VirtIo Specification Revision encoded with VIRTIO_SPEC_REVISION()
332 /// From the Virtio Spec
333 INT32 SubSystemDeviceId
;
335 VIRTIO_GET_DEVICE_FEATURES GetDeviceFeatures
;
336 VIRTIO_SET_GUEST_FEATURES SetGuestFeatures
;
338 VIRTIO_SET_QUEUE_ADDRESS SetQueueAddress
;
340 VIRTIO_SET_QUEUE_SEL SetQueueSel
;
342 VIRTIO_SET_QUEUE_NOTIFY SetQueueNotify
;
344 VIRTIO_SET_QUEUE_ALIGN SetQueueAlign
;
345 VIRTIO_SET_PAGE_SIZE SetPageSize
;
347 VIRTIO_GET_QUEUE_NUM_MAX GetQueueNumMax
;
348 VIRTIO_SET_QUEUE_NUM SetQueueNum
;
350 VIRTIO_GET_DEVICE_STATUS GetDeviceStatus
;
351 VIRTIO_SET_DEVICE_STATUS SetDeviceStatus
;
353 // Functions to read/write Device Specific headers
354 VIRTIO_DEVICE_WRITE WriteDevice
;
355 VIRTIO_DEVICE_READ ReadDevice
;
358 extern EFI_GUID gVirtioDeviceProtocolGuid
;