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.
24 // Data in the communication area is defined as packed and accessed as
27 // Some structures contain arrays with dynamically determined size. In such
28 // cases the array and its sibling fields are replaced with pointers.
30 // All indices (variables and fields named *Idx) are free-running and wrap
31 // around after 0xFFFF. The queue size reported by the host is always an
32 // integral power of 2, not greater than 32768. Actual array indices are
33 // consistently calculated by taking the remainder of a given Idx object modulo
34 // QueueSize. Since 0x10000 is an integral multiple of the QueueSize, UINT16
35 // wraparound is a correct wraparound modulo QueueSize too (it doesn't offset
36 // the remainder class).
38 // virtio-0.9.5, 2.3.4 Available Ring
40 #define VRING_AVAIL_F_NO_INTERRUPT BIT0
43 volatile UINT16
*Flags
;
46 volatile UINT16
*Ring
; // QueueSize elements
47 volatile UINT16
*UsedEvent
; // unused as per negotiation
52 // virtio-0.9.5, 2.3.5 Used Ring
54 #define VRING_USED_F_NO_NOTIFY BIT0
64 volatile UINT16
*Flags
;
66 volatile VRING_USED_ELEM
*UsedElem
; // QueueSize elements
67 volatile UINT16
*AvailEvent
; // unused as per negotiation
72 // virtio-0.9.5, 2.3.2 Descriptor Table
74 #define VRING_DESC_F_NEXT BIT0 // more descriptors in this request
75 #define VRING_DESC_F_WRITE BIT1 // buffer to be written *by the host*
76 #define VRING_DESC_F_INDIRECT BIT2 // unused
89 VOID
*Base
; // deallocate only this field
90 volatile VRING_DESC
*Desc
; // QueueSize elements
98 // virtio-0.9.5, 2.2.2 Virtio Header -- no MSI-X
99 // virtio-0.9.5, Appendix D
103 UINT32 VhdrDeviceFeatureBits
;
104 UINT32 VhdrGuestFeatureBits
;
105 UINT32 VhdrQueueAddress
;
106 UINT16 VhdrQueueSize
;
107 UINT16 VhdrQueueSelect
;
108 UINT16 VhdrQueueNotify
;
109 UINT8 VhdrDeviceStatus
;
114 UINT16 VhdrCylinders
;
121 #define OFFSET_OF_VHDR(Field) OFFSET_OF (VBLK_HDR, Field)
122 #define SIZE_OF_VHDR(Field) (sizeof ((VBLK_HDR *) 0)->Field)
126 // virtio-0.9.5, 2.2.2.1 Device Status
128 #define VSTAT_ACK BIT0
129 #define VSTAT_DRIVER BIT1
130 #define VSTAT_DRIVER_OK BIT2
131 #define VSTAT_FAILED BIT7
134 // virtio-0.9.5, Appendix B: Reserved (Device-Independent) Feature Bits
136 #define VIRTIO_F_NOTIFY_ON_EMPTY BIT24
137 #define VIRTIO_F_RING_INDIRECT_DESC BIT28
138 #define VIRTIO_F_RING_EVENT_IDX BIT29
141 // virtio-0.9.5, Appendix D: Block Device
143 #define VIRTIO_BLK_F_BARRIER BIT0
144 #define VIRTIO_BLK_F_SIZE_MAX BIT1
145 #define VIRTIO_BLK_F_SEG_MAX BIT2
146 #define VIRTIO_BLK_F_GEOMETRY BIT4
147 #define VIRTIO_BLK_F_RO BIT5
148 #define VIRTIO_BLK_F_BLK_SIZE BIT6 // treated as "logical block size" in
149 // practice; actual host side implementation
150 // negotiates "optimal" block size
152 #define VIRTIO_BLK_F_SCSI BIT7
153 #define VIRTIO_BLK_F_FLUSH BIT9 // identical to "write cache enabled"
157 // We keep the status byte separate from the rest of the virtio-blk request
158 // header. See description of historical scattering at the end of Appendix D:
159 // we're going to put the status byte in a separate VRING_DESC.
169 #define VIRTIO_BLK_T_IN 0x00000000
170 #define VIRTIO_BLK_T_OUT 0x00000001
171 #define VIRTIO_BLK_T_SCSI_CMD 0x00000002
172 #define VIRTIO_BLK_T_SCSI_CMD_OUT 0x00000003
173 #define VIRTIO_BLK_T_FLUSH 0x00000004
174 #define VIRTIO_BLK_T_FLUSH_OUT 0x00000005
175 #define VIRTIO_BLK_T_BARRIER BIT31
177 #define VIRTIO_BLK_S_OK 0x00
178 #define VIRTIO_BLK_S_IOERR 0x01
179 #define VIRTIO_BLK_S_UNSUPP 0x02