3 Type and macro definitions corresponding to the virtio-0.9.5 specification.
5 Copyright (C) 2012, Red Hat, Inc.
7 This program and the accompanying materials are licensed and made available
8 under the terms and conditions of the BSD License which accompanies this
9 distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
13 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 // Data in the communication area is defined as packed and accessed as
24 // Some structures contain arrays with dynamically determined size. In such
25 // cases the array and its sibling fields are replaced with pointers.
27 // All indices (variables and fields named *Idx) are free-running and wrap
28 // around after 0xFFFF. The queue size reported by the host is always an
29 // integral power of 2, not greater than 32768. Actual array indices are
30 // consistently calculated by taking the remainder of a given Idx object modulo
31 // QueueSize. Since 0x10000 is an integral multiple of the QueueSize, UINT16
32 // wraparound is a correct wraparound modulo QueueSize too (it doesn't offset
33 // the remainder class).
35 // virtio-0.9.5, 2.3.4 Available Ring
37 #define VRING_AVAIL_F_NO_INTERRUPT BIT0
40 volatile UINT16
*Flags
;
43 volatile UINT16
*Ring
; // QueueSize elements
44 volatile UINT16
*UsedEvent
; // unused as per negotiation
49 // virtio-0.9.5, 2.3.5 Used Ring
51 #define VRING_USED_F_NO_NOTIFY BIT0
61 volatile UINT16
*Flags
;
63 volatile VRING_USED_ELEM
*UsedElem
; // QueueSize elements
64 volatile UINT16
*AvailEvent
; // unused as per negotiation
69 // virtio-0.9.5, 2.3.2 Descriptor Table
71 #define VRING_DESC_F_NEXT BIT0 // more descriptors in this request
72 #define VRING_DESC_F_WRITE BIT1 // buffer to be written *by the host*
73 #define VRING_DESC_F_INDIRECT BIT2 // unused
86 VOID
*Base
; // deallocate only this field
87 volatile VRING_DESC
*Desc
; // QueueSize elements
95 // virtio-0.9.5, 2.2.2 Virtio Header -- no MSI-X
96 // virtio-0.9.5, Appendix D
100 UINT32 VhdrDeviceFeatureBits
;
101 UINT32 VhdrGuestFeatureBits
;
102 UINT32 VhdrQueueAddress
;
103 UINT16 VhdrQueueSize
;
104 UINT16 VhdrQueueSelect
;
105 UINT16 VhdrQueueNotify
;
106 UINT8 VhdrDeviceStatus
;
111 UINT16 VhdrCylinders
;
118 #define OFFSET_OF_VHDR(Field) ((UINTN)(UINT8 *)&((VBLK_HDR *) 0)->Field)
119 #define SIZE_OF_VHDR(Field) (sizeof ((VBLK_HDR *) 0)->Field)
123 // virtio-0.9.5, 2.2.2.1 Device Status
125 #define VSTAT_ACK BIT0
126 #define VSTAT_DRIVER BIT1
127 #define VSTAT_DRIVER_OK BIT2
128 #define VSTAT_FAILED BIT7
131 // virtio-0.9.5, Appendix B: Reserved (Device-Independent) Feature Bits
133 #define VIRTIO_F_NOTIFY_ON_EMPTY BIT24
134 #define VIRTIO_F_RING_INDIRECT_DESC BIT28
135 #define VIRTIO_F_RING_EVENT_IDX BIT29
138 // virtio-0.9.5, Appendix D: Block Device
140 #define VIRTIO_BLK_F_BARRIER BIT0
141 #define VIRTIO_BLK_F_SIZE_MAX BIT1
142 #define VIRTIO_BLK_F_SEG_MAX BIT2
143 #define VIRTIO_BLK_F_GEOMETRY BIT4
144 #define VIRTIO_BLK_F_RO BIT5
145 #define VIRTIO_BLK_F_BLK_SIZE BIT6 // treated as "logical block size" in
146 // practice; actual host side implementation
147 // negotiates "optimal" block size
149 #define VIRTIO_BLK_F_SCSI BIT7
150 #define VIRTIO_BLK_F_FLUSH BIT9 // identical to "write cache enabled"
154 // We keep the status byte separate from the rest of the virtio-blk request
155 // header. See description of historical scattering at the end of Appendix D:
156 // we're going to put the status byte in a separate VRING_DESC.
166 #define VIRTIO_BLK_T_IN 0x00000000
167 #define VIRTIO_BLK_T_OUT 0x00000001
168 #define VIRTIO_BLK_T_SCSI_CMD 0x00000002
169 #define VIRTIO_BLK_T_SCSI_CMD_OUT 0x00000003
170 #define VIRTIO_BLK_T_FLUSH 0x00000004
171 #define VIRTIO_BLK_T_FLUSH_OUT 0x00000005
172 #define VIRTIO_BLK_T_BARRIER BIT31
174 #define VIRTIO_BLK_S_OK 0x00
175 #define VIRTIO_BLK_S_IOERR 0x01
176 #define VIRTIO_BLK_S_UNSUPP 0x02