summaryrefslogtreecommitdiff
path: root/edk2/OvmfPkg/Include/IndustryStandard
diff options
context:
space:
mode:
Diffstat (limited to 'edk2/OvmfPkg/Include/IndustryStandard')
-rw-r--r--edk2/OvmfPkg/Include/IndustryStandard/Virtio.h131
-rw-r--r--edk2/OvmfPkg/Include/IndustryStandard/VirtioBlk.h80
-rw-r--r--edk2/OvmfPkg/Include/IndustryStandard/VirtioScsi.h100
3 files changed, 311 insertions, 0 deletions
diff --git a/edk2/OvmfPkg/Include/IndustryStandard/Virtio.h b/edk2/OvmfPkg/Include/IndustryStandard/Virtio.h
new file mode 100644
index 000000000..05c658fa5
--- /dev/null
+++ b/edk2/OvmfPkg/Include/IndustryStandard/Virtio.h
@@ -0,0 +1,131 @@
+/** @file
+
+ Generic type and macro definitions corresponding to the virtio-0.9.5
+ specification.
+
+ Copyright (C) 2012, Red Hat, Inc.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _VIRTIO_H_
+#define _VIRTIO_H_
+
+#include <Base.h>
+
+
+//
+// Data in the communication area is defined as packed and accessed as
+// volatile.
+//
+// Some structures contain arrays with dynamically determined size. In such
+// cases the array and its sibling fields are replaced with pointers.
+//
+// All indices (variables and fields named *Idx) are free-running and wrap
+// around after 0xFFFF. The queue size reported by the host is always an
+// integral power of 2, not greater than 32768. Actual array indices are
+// consistently calculated by taking the remainder of a given Idx object modulo
+// QueueSize. Since 0x10000 is an integral multiple of the QueueSize, UINT16
+// wraparound is a correct wraparound modulo QueueSize too (it doesn't offset
+// the remainder class).
+//
+// virtio-0.9.5, 2.3.4 Available Ring
+//
+#define VRING_AVAIL_F_NO_INTERRUPT BIT0
+
+typedef struct {
+ volatile UINT16 *Flags;
+ volatile UINT16 *Idx;
+
+ volatile UINT16 *Ring; // QueueSize elements
+ volatile UINT16 *UsedEvent; // unused as per negotiation
+} VRING_AVAIL;
+
+
+//
+// virtio-0.9.5, 2.3.5 Used Ring
+//
+#define VRING_USED_F_NO_NOTIFY BIT0
+
+#pragma pack(1)
+typedef struct {
+ UINT32 Id;
+ UINT32 Len;
+} VRING_USED_ELEM;
+#pragma pack()
+
+typedef struct {
+ volatile UINT16 *Flags;
+ volatile UINT16 *Idx;
+ volatile VRING_USED_ELEM *UsedElem; // QueueSize elements
+ volatile UINT16 *AvailEvent; // unused as per negotiation
+} VRING_USED;
+
+
+//
+// virtio-0.9.5, 2.3.2 Descriptor Table
+//
+#define VRING_DESC_F_NEXT BIT0 // more descriptors in this request
+#define VRING_DESC_F_WRITE BIT1 // buffer to be written *by the host*
+#define VRING_DESC_F_INDIRECT BIT2 // unused
+
+#pragma pack(1)
+typedef struct {
+ UINT64 Addr;
+ UINT32 Len;
+ UINT16 Flags;
+ UINT16 Next;
+} VRING_DESC;
+#pragma pack()
+
+typedef struct {
+ UINTN NumPages;
+ VOID *Base; // deallocate only this field
+ volatile VRING_DESC *Desc; // QueueSize elements
+ VRING_AVAIL Avail;
+ VRING_USED Used;
+ UINT16 QueueSize;
+} VRING;
+
+
+//
+// virtio-0.9.5, 2.2.2 Virtio Header -- no MSI-X
+//
+#pragma pack(1)
+typedef struct {
+ UINT32 VhdrDeviceFeatureBits;
+ UINT32 VhdrGuestFeatureBits;
+ UINT32 VhdrQueueAddress;
+ UINT16 VhdrQueueSize;
+ UINT16 VhdrQueueSelect;
+ UINT16 VhdrQueueNotify;
+ UINT8 VhdrDeviceStatus;
+ UINT8 VhdrISR;
+} VIRTIO_HDR;
+#pragma pack()
+
+
+//
+// virtio-0.9.5, 2.2.2.1 Device Status
+//
+#define VSTAT_ACK BIT0
+#define VSTAT_DRIVER BIT1
+#define VSTAT_DRIVER_OK BIT2
+#define VSTAT_FAILED BIT7
+
+//
+// virtio-0.9.5, Appendix B: Reserved (Device-Independent) Feature Bits
+//
+#define VIRTIO_F_NOTIFY_ON_EMPTY BIT24
+#define VIRTIO_F_RING_INDIRECT_DESC BIT28
+#define VIRTIO_F_RING_EVENT_IDX BIT29
+
+
+#endif // _VIRTIO_H_
diff --git a/edk2/OvmfPkg/Include/IndustryStandard/VirtioBlk.h b/edk2/OvmfPkg/Include/IndustryStandard/VirtioBlk.h
new file mode 100644
index 000000000..b71f224b6
--- /dev/null
+++ b/edk2/OvmfPkg/Include/IndustryStandard/VirtioBlk.h
@@ -0,0 +1,80 @@
+/** @file
+
+ Virtio Block Device specific type and macro definitions corresponding to the
+ virtio-0.9.5 specification.
+
+ Copyright (C) 2012, Red Hat, Inc.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _VIRTIO_BLK_H_
+#define _VIRTIO_BLK_H_
+
+#include <IndustryStandard/Virtio.h>
+
+
+//
+// virtio-0.9.5, Appendix D: Block Device
+//
+#pragma pack(1)
+typedef struct {
+ VIRTIO_HDR Generic;
+ UINT64 VhdrCapacity;
+ UINT32 VhdrSizeMax;
+ UINT32 VhdrSegMax;
+ UINT16 VhdrCylinders;
+ UINT8 VhdrHeads;
+ UINT8 VhdrSectors;
+ UINT32 VhdrBlkSize;
+} VBLK_HDR;
+#pragma pack()
+
+#define OFFSET_OF_VBLK(Field) OFFSET_OF (VBLK_HDR, Field)
+#define SIZE_OF_VBLK(Field) (sizeof ((VBLK_HDR *) 0)->Field)
+
+#define VIRTIO_BLK_F_BARRIER BIT0
+#define VIRTIO_BLK_F_SIZE_MAX BIT1
+#define VIRTIO_BLK_F_SEG_MAX BIT2
+#define VIRTIO_BLK_F_GEOMETRY BIT4
+#define VIRTIO_BLK_F_RO BIT5
+#define VIRTIO_BLK_F_BLK_SIZE BIT6 // treated as "logical block size" in
+ // practice; actual host side implementation
+ // negotiates "optimal" block size
+ // separately
+#define VIRTIO_BLK_F_SCSI BIT7
+#define VIRTIO_BLK_F_FLUSH BIT9 // identical to "write cache enabled"
+
+//
+// We keep the status byte separate from the rest of the virtio-blk request
+// header. See description of historical scattering at the end of Appendix D:
+// we're going to put the status byte in a separate VRING_DESC.
+//
+#pragma pack(1)
+typedef struct {
+ UINT32 Type;
+ UINT32 IoPrio;
+ UINT64 Sector;
+} VIRTIO_BLK_REQ;
+#pragma pack()
+
+#define VIRTIO_BLK_T_IN 0x00000000
+#define VIRTIO_BLK_T_OUT 0x00000001
+#define VIRTIO_BLK_T_SCSI_CMD 0x00000002
+#define VIRTIO_BLK_T_SCSI_CMD_OUT 0x00000003
+#define VIRTIO_BLK_T_FLUSH 0x00000004
+#define VIRTIO_BLK_T_FLUSH_OUT 0x00000005
+#define VIRTIO_BLK_T_BARRIER BIT31
+
+#define VIRTIO_BLK_S_OK 0x00
+#define VIRTIO_BLK_S_IOERR 0x01
+#define VIRTIO_BLK_S_UNSUPP 0x02
+
+#endif // _VIRTIO_BLK_H_
diff --git a/edk2/OvmfPkg/Include/IndustryStandard/VirtioScsi.h b/edk2/OvmfPkg/Include/IndustryStandard/VirtioScsi.h
new file mode 100644
index 000000000..59ce97e07
--- /dev/null
+++ b/edk2/OvmfPkg/Include/IndustryStandard/VirtioScsi.h
@@ -0,0 +1,100 @@
+/** @file
+
+ Virtio SCSI Host Device specific type and macro definitions corresponding to
+ the virtio-0.9.5 specification.
+
+ Copyright (C) 2012, Red Hat, Inc.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _VIRTIO_SCSI_H_
+#define _VIRTIO_SCSI_H_
+
+#include <IndustryStandard/Virtio.h>
+
+
+//
+// virtio-0.9.5, Appendix I: SCSI Host Device
+//
+#pragma pack(1)
+typedef struct {
+ VIRTIO_HDR Generic;
+ UINT32 VhdrNumQueues;
+ UINT32 VhdrSegMax;
+ UINT32 VhdrMaxSectors;
+ UINT32 VhdrCmdPerLun;
+ UINT32 VhdrEventInfoSize;
+ UINT32 VhdrSenseSize;
+ UINT32 VhdrCdbSize;
+ UINT16 VhdrMaxChannel;
+ UINT16 VhdrMaxTarget;
+ UINT32 VhdrMaxLun;
+} VSCSI_HDR;
+#pragma pack()
+
+#define OFFSET_OF_VSCSI(Field) OFFSET_OF (VSCSI_HDR, Field)
+#define SIZE_OF_VSCSI(Field) (sizeof ((VSCSI_HDR *) 0)->Field)
+
+#define VIRTIO_SCSI_F_INOUT BIT0
+#define VIRTIO_SCSI_F_HOTPLUG BIT1
+
+//
+// We expect these maximum sizes from the host. Also we force the CdbLength and
+// SenseDataLength parameters of EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() not
+// to exceed these limits. See UEFI 2.3.1 errata C 14.7.
+//
+#define VIRTIO_SCSI_CDB_SIZE 32
+#define VIRTIO_SCSI_SENSE_SIZE 96
+
+//
+// We pass the dynamically sized buffers ("dataout", "datain") in separate ring
+// descriptors.
+//
+#pragma pack(1)
+typedef struct {
+ UINT8 Lun[8];
+ UINT64 Id;
+ UINT8 TaskAttr;
+ UINT8 Prio;
+ UINT8 Crn;
+ UINT8 Cdb[VIRTIO_SCSI_CDB_SIZE];
+} VIRTIO_SCSI_REQ;
+
+typedef struct {
+ UINT32 SenseLen;
+ UINT32 Residual;
+ UINT16 StatusQualifier;
+ UINT8 Status;
+ UINT8 Response;
+ UINT8 Sense[VIRTIO_SCSI_SENSE_SIZE];
+} VIRTIO_SCSI_RESP;
+#pragma pack()
+
+//
+// selector of first virtio queue usable for request transfer
+//
+#define VIRTIO_SCSI_REQUEST_QUEUE 2
+
+//
+// host response codes
+//
+#define VIRTIO_SCSI_S_OK 0
+#define VIRTIO_SCSI_S_OVERRUN 1
+#define VIRTIO_SCSI_S_ABORTED 2
+#define VIRTIO_SCSI_S_BAD_TARGET 3
+#define VIRTIO_SCSI_S_RESET 4
+#define VIRTIO_SCSI_S_BUSY 5
+#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
+#define VIRTIO_SCSI_S_TARGET_FAILURE 7
+#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
+#define VIRTIO_SCSI_S_FAILURE 9
+
+#endif // _VIRTIO_SCSI_H_