]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Include/IndustryStandard/Virtio.h
OvmfPkg/Virtio.h: Added VirtIo Subsystem IDs
[mirror_edk2.git] / OvmfPkg / Include / IndustryStandard / Virtio.h
1 /** @file
2
3 Generic type and macro definitions corresponding to the virtio-0.9.5
4 specification.
5
6 Copyright (C) 2012, Red Hat, Inc.
7
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #ifndef _VIRTIO_H_
19 #define _VIRTIO_H_
20
21 #include <Base.h>
22
23 //
24 // VirtIo Subsystem Device IDs
25 //
26 #define VIRTIO_SUBSYSTEM_NETWORK_CARD 1
27 #define VIRTIO_SUBSYSTEM_BLOCK_DEVICE 2
28 #define VIRTIO_SUBSYSTEM_CONSOLE 3
29 #define VIRTIO_SUBSYSTEM_ENTROPY_SOURCE 4
30 #define VIRTIO_SUBSYSTEM_MEMORY_BALLOONING 5
31 #define VIRTIO_SUBSYSTEM_IO_MEMORY 6
32 #define VIRTIO_SUBSYSTEM_RPMSG 7
33 #define VIRTIO_SUBSYSTEM_SCSI_HOST 8
34 #define VIRTIO_SUBSYSTEM_9P_TRANSPORT 9
35 #define VIRTIO_SUBSYSTEM_MAC80211_WLAN 10
36
37 //
38 // Data in the communication area is defined as packed and accessed as
39 // volatile.
40 //
41 // Some structures contain arrays with dynamically determined size. In such
42 // cases the array and its sibling fields are replaced with pointers.
43 //
44 // All indices (variables and fields named *Idx) are free-running and wrap
45 // around after 0xFFFF. The queue size reported by the host is always an
46 // integral power of 2, not greater than 32768. Actual array indices are
47 // consistently calculated by taking the remainder of a given Idx object modulo
48 // QueueSize. Since 0x10000 is an integral multiple of the QueueSize, UINT16
49 // wraparound is a correct wraparound modulo QueueSize too (it doesn't offset
50 // the remainder class).
51 //
52 // virtio-0.9.5, 2.3.4 Available Ring
53 //
54 #define VRING_AVAIL_F_NO_INTERRUPT BIT0
55
56 typedef struct {
57 volatile UINT16 *Flags;
58 volatile UINT16 *Idx;
59
60 volatile UINT16 *Ring; // QueueSize elements
61 volatile UINT16 *UsedEvent; // unused as per negotiation
62 } VRING_AVAIL;
63
64
65 //
66 // virtio-0.9.5, 2.3.5 Used Ring
67 //
68 #define VRING_USED_F_NO_NOTIFY BIT0
69
70 #pragma pack(1)
71 typedef struct {
72 UINT32 Id;
73 UINT32 Len;
74 } VRING_USED_ELEM;
75 #pragma pack()
76
77 typedef struct {
78 volatile UINT16 *Flags;
79 volatile UINT16 *Idx;
80 volatile VRING_USED_ELEM *UsedElem; // QueueSize elements
81 volatile UINT16 *AvailEvent; // unused as per negotiation
82 } VRING_USED;
83
84
85 //
86 // virtio-0.9.5, 2.3.2 Descriptor Table
87 //
88 #define VRING_DESC_F_NEXT BIT0 // more descriptors in this request
89 #define VRING_DESC_F_WRITE BIT1 // buffer to be written *by the host*
90 #define VRING_DESC_F_INDIRECT BIT2 // unused
91
92 #pragma pack(1)
93 typedef struct {
94 UINT64 Addr;
95 UINT32 Len;
96 UINT16 Flags;
97 UINT16 Next;
98 } VRING_DESC;
99 #pragma pack()
100
101 typedef struct {
102 UINTN NumPages;
103 VOID *Base; // deallocate only this field
104 volatile VRING_DESC *Desc; // QueueSize elements
105 VRING_AVAIL Avail;
106 VRING_USED Used;
107 UINT16 QueueSize;
108 } VRING;
109
110
111 //
112 // virtio-0.9.5, 2.2.2 Virtio Header -- no MSI-X
113 //
114 #pragma pack(1)
115 typedef struct {
116 UINT32 VhdrDeviceFeatureBits;
117 UINT32 VhdrGuestFeatureBits;
118 UINT32 VhdrQueueAddress;
119 UINT16 VhdrQueueSize;
120 UINT16 VhdrQueueSelect;
121 UINT16 VhdrQueueNotify;
122 UINT8 VhdrDeviceStatus;
123 UINT8 VhdrISR;
124 } VIRTIO_HDR;
125 #pragma pack()
126
127
128 //
129 // virtio-0.9.5, 2.2.2.1 Device Status
130 //
131 #define VSTAT_ACK BIT0
132 #define VSTAT_DRIVER BIT1
133 #define VSTAT_DRIVER_OK BIT2
134 #define VSTAT_FAILED BIT7
135
136 //
137 // virtio-0.9.5, Appendix B: Reserved (Device-Independent) Feature Bits
138 //
139 #define VIRTIO_F_NOTIFY_ON_EMPTY BIT24
140 #define VIRTIO_F_RING_INDIRECT_DESC BIT28
141 #define VIRTIO_F_RING_EVENT_IDX BIT29
142
143
144 #endif // _VIRTIO_H_