--- /dev/null
+/** @file\r
+ Virtio Device\r
+\r
+ DISCLAIMER: the VIRTIO_DEVICE_PROTOCOL introduced here is a work in progress,\r
+ and should not be used outside of the EDK II tree.\r
+\r
+ Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __VIRTIO_DEVICE_H__\r
+#define __VIRTIO_DEVICE_H__\r
+\r
+// VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0\r
+#define VIRTIO_SPEC_REVISION(major,minor,revision) \\r
+ ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))\r
+\r
+#define VIRTIO_DEVICE_PROTOCOL_GUID { \\r
+ 0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\\r
+ }\r
+\r
+typedef struct _VIRTIO_DEVICE_PROTOCOL VIRTIO_DEVICE_PROTOCOL;\r
+\r
+/**\r
+\r
+ Read a word from the device-specific I/O region of the Virtio Header.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] FieldOffset Source offset.\r
+\r
+ @param[in] FieldSize Source field size in bytes, must be in {1, 2, 4, 8}.\r
+\r
+ @param[in] BufferSize Number of bytes available in the target buffer. Must\r
+ equal FieldSize.\r
+\r
+ @param[out] Buffer Target buffer.\r
+\r
+ @retval EFI_SUCCESS The data was read successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and read size.\r
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a\r
+ lack of resources.\r
+ @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_DEVICE_READ) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINTN FieldOffset,\r
+ IN UINTN FieldSize,\r
+ IN UINTN BufferSize,\r
+ OUT VOID *Buffer\r
+ );\r
+\r
+/**\r
+\r
+ Write a word to the device-specific I/O region of the Virtio Header.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] FieldOffset Destination offset.\r
+\r
+ @param[in] FieldSize Destination field size in bytes,\r
+ must be in {1, 2, 4, 8}.\r
+\r
+ @param[out] Value Value to write.\r
+\r
+ @retval EFI_SUCCESS The data was written successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and write size.\r
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a\r
+ lack of resources.\r
+ @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_DEVICE_WRITE) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINTN FieldOffset,\r
+ IN UINTN FieldSize,\r
+ IN UINT64 Value\r
+ );\r
+\r
+/**\r
+ Read the device features field from the Virtio Header.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[out] DeviceFeatures The 32-bit device features field.\r
+\r
+ @retval EFI_SUCCESS The data was read successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and read size.\r
+ @retval EFI_INVALID_PARAMETER DeviceFeatures is NULL\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_GET_DEVICE_FEATURES) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ OUT UINT32 *DeviceFeatures\r
+ );\r
+\r
+/**\r
+ Write the guest features field in the Virtio Header.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] Features The 32-bit guest guest features field\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_SET_GUEST_FEATURES) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINT32 Features\r
+ );\r
+\r
+/**\r
+ Read the queue address field from the Virtio Header.\r
+\r
+ QueueAddress is the address of the virtqueue divided by 4096.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[out] QueueAddress The 32-bit queue address field.\r
+\r
+ @retval EFI_SUCCESS The data was read successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and read size.\r
+ @retval EFI_INVALID_PARAMETER QueueAddress is NULL\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_GET_QUEUE_ADDRESS) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ OUT UINT32 *QueueAddress\r
+ );\r
+\r
+/**\r
+ Write the queue address field in the Virtio Header.\r
+\r
+ The parameter Address must be the base address of the virtqueue divided\r
+ by 4096.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] Address The 32-bit Queue Address field\r
+\r
+ @retval EFI_SUCCESS The data was written successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and write size.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_SET_QUEUE_ADDRESS) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINT32 Address\r
+ );\r
+\r
+/**\r
+\r
+ Write the queue select field in the Virtio Header.\r
+\r
+ Writing to the queue select field sets the index of the queue to which\r
+ operations such as SetQueueAlign and GetQueueNumMax apply.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] Index The index of the queue to select\r
+\r
+ @retval EFI_SUCCESS The data was written successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and write size.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_SET_QUEUE_SEL) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINT16 Index\r
+ );\r
+\r
+/**\r
+\r
+ Write the queue notify field in the Virtio Header.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] Address The 32-bit Queue Notify field\r
+\r
+ @retval EFI_SUCCESS The data was written successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and write size.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_SET_QUEUE_NOTIFY) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINT16 Index\r
+ );\r
+\r
+/**\r
+ Write the queue alignment field in the Virtio Header.\r
+\r
+ The queue to which the alignment applies is selected by the Queue Select\r
+ field.\r
+\r
+ Note: This operation is not implemented by the VirtIo over PCI. The PCI\r
+ implementation of this protocol returns EFI_SUCCESS.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] Alignment The alignment boundary of the Used Ring in bytes.\r
+ Must be a power of 2.\r
+\r
+ @retval EFI_SUCCESS The data was written successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and write size.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_SET_QUEUE_ALIGN) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINT32 Alignment\r
+ );\r
+\r
+/**\r
+ Write the guest page size.\r
+\r
+ Note: This operation is not implemented by the VirtIo over PCI. The PCI\r
+ implementation of this protocol returns EFI_SUCCESS.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] PageSize Size of the Guest page in bytes.\r
+ Must be a power of 2.\r
+\r
+ @retval EFI_SUCCESS The data was written successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and write size.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_SET_PAGE_SIZE) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINT32 PageSize\r
+ );\r
+\r
+/**\r
+\r
+ Get the size of the virtqueue selected by the queue select field.\r
+\r
+ See Virtio spec Section 2.3\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[out] QueueNumMax The size of the virtqueue in bytes.\r
+ Always a power of 2.\r
+\r
+ @retval EFI_SUCCESS The data was read successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and read size.\r
+ @retval EFI_INVALID_PARAMETER QueueNumMax is NULL\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_GET_QUEUE_NUM_MAX) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ OUT UINT16 *QueueNumMax\r
+ );\r
+\r
+/**\r
+\r
+ Write to the QueueNum field in the Virtio Header.\r
+\r
+ This function only applies to Virtio-MMIO and may be a stub for other\r
+ implementations. See Virtio Spec appendix X.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] QueueSize The number of elements in the queue.\r
+\r
+ @retval EFI_SUCCESS The data was written successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and write size.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_SET_QUEUE_NUM) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINT16 QueueSize\r
+ );\r
+\r
+/**\r
+\r
+ Get the DeviceStatus field from the Virtio Header.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[out] DeviceStatus The 8-bit value for the Device status field\r
+\r
+ @retval EFI_SUCCESS The data was read successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and read size.\r
+ @retval EFI_INVALID_PARAMETER DeviceStatus is NULL\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_GET_DEVICE_STATUS) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ OUT UINT8 *DeviceStatus\r
+ );\r
+\r
+/**\r
+\r
+ Write the DeviceStatus field in the Virtio Header.\r
+\r
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL\r
+\r
+ @param[in] DeviceStatus The 8-bit value for the Device status field\r
+\r
+ @retval EFI_SUCCESS The data was written successfully.\r
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the\r
+ provided address offset and write size.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *VIRTIO_SET_DEVICE_STATUS) (\r
+ IN VIRTIO_DEVICE_PROTOCOL *This,\r
+ IN UINT8 DeviceStatus\r
+ );\r
+\r
+\r
+///\r
+/// This protocol provides an abstraction over the VirtIo transport layer\r
+///\r
+/// DISCLAIMER: this protocol is a work in progress, and should not be used\r
+/// outside of the EDK II tree.\r
+///\r
+struct _VIRTIO_DEVICE_PROTOCOL {\r
+ /// VirtIo Specification Revision encoded with VIRTIO_SPEC_REVISION()\r
+ UINT32 Revision;\r
+ /// From the Virtio Spec\r
+ INT32 SubSystemDeviceId;\r
+\r
+ VIRTIO_GET_DEVICE_FEATURES GetDeviceFeatures;\r
+ VIRTIO_SET_GUEST_FEATURES SetGuestFeatures;\r
+\r
+ VIRTIO_GET_QUEUE_ADDRESS GetQueueAddress;\r
+ VIRTIO_SET_QUEUE_ADDRESS SetQueueAddress;\r
+\r
+ VIRTIO_SET_QUEUE_SEL SetQueueSel;\r
+\r
+ VIRTIO_SET_QUEUE_NOTIFY SetQueueNotify;\r
+\r
+ VIRTIO_SET_QUEUE_ALIGN SetQueueAlign;\r
+ VIRTIO_SET_PAGE_SIZE SetPageSize;\r
+\r
+ VIRTIO_GET_QUEUE_NUM_MAX GetQueueNumMax;\r
+ VIRTIO_SET_QUEUE_NUM SetQueueNum;\r
+\r
+ VIRTIO_GET_DEVICE_STATUS GetDeviceStatus;\r
+ VIRTIO_SET_DEVICE_STATUS SetDeviceStatus;\r
+\r
+ // Functions to read/write Device Specific headers\r
+ VIRTIO_DEVICE_WRITE WriteDevice;\r
+ VIRTIO_DEVICE_READ ReadDevice;\r
+};\r
+\r
+extern EFI_GUID gVirtioDeviceProtocolGuid;\r
+\r
+#endif\r