xref: /haiku/headers/private/virtio/virtio_defs.h (revision a127b88ecbfab58f64944c98aa47722a18e363b2)
1 /*
2  * Copyright 2021, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef _VIRTIO_DEFS_H_
7 #define _VIRTIO_DEFS_H_
8 
9 
10 #include <SupportDefs.h>
11 
12 
13 enum {
14 	kVirtioRegsSize = 0x1000,
15 	kVirtioSignature = 0x74726976,
16 	kVirtioVendorId = 0x554d4551,
17 };
18 
19 enum {
20 	kVirtioDevNet     =  1,
21 	kVirtioDevBlock   =  2,
22 	kVirtioDevConsole =  3,
23 	kVirtioDev9p      =  9,
24 	kVirtioDevInput   = 18,
25 };
26 
27 enum {
28 	kVirtioConfigSAcknowledge = 1 << 0,
29 	kVirtioConfigSDriver      = 1 << 1,
30 	kVirtioConfigSDriverOk    = 1 << 2,
31 	kVirtioConfigSFeaturesOk  = 1 << 3,
32 };
33 
34 // VirtioRegs.interruptStatus, interruptAck
35 enum {
36 	kVirtioIntQueue  = 1 << 0,
37 	kVirtioIntConfig = 1 << 1,
38 };
39 
40 enum {
41 	kVringDescFlagsNext     = 1 << 0,
42 	kVringDescFlagsWrite    = 1 << 1,
43 	kVringDescFlagsIndirect = 1 << 2,
44 };
45 
46 struct VirtioRegs {
47 	uint32 signature;
48 	uint32 version;
49 	uint32 deviceId;
50 	uint32 vendorId;
51 	uint32 deviceFeatures;
52 	uint32 unknown1[3];
53 	uint32 driverFeatures;
54 	uint32 unknown2[1];
55 	uint32 guestPageSize; /* version 1 only */
56 	uint32 unknown3[1];
57 	uint32 queueSel;
58 	uint32 queueNumMax;
59 	uint32 queueNum;
60 	uint32 queueAlign;    /* version 1 only */
61 	uint32 queuePfn;      /* version 1 only */
62 	uint32 queueReady;
63 	uint32 unknown4[2];
64 	uint32 queueNotify;
65 	uint32 unknown5[3];
66 	uint32 interruptStatus;
67 	uint32 interruptAck;
68 	uint32 unknown6[2];
69 	uint32 status;
70 	uint32 unknown7[3];
71 	uint32 queueDescLow;
72 	uint32 queueDescHi;
73 	uint32 unknown8[2];
74 	uint32 queueAvailLow;
75 	uint32 queueAvailHi;
76 	uint32 unknown9[2];
77 	uint32 queueUsedLow;
78 	uint32 queueUsedHi;
79 	uint32 unknown10[21];
80 	uint32 configGeneration;
81 	uint8 config[3840];
82 };
83 
84 struct VirtioDesc {
85 	uint64 addr;
86 	uint32 len;
87 	uint16 flags;
88 	uint16 next;
89 };
90 
91 // filled by driver
92 struct VirtioAvail {
93 	uint16 flags;
94 	uint16 idx;
95 	uint16 ring[0];
96 };
97 
98 struct VirtioUsedItem
99 {
100 	uint32 id;
101 	uint32 len;
102 };
103 
104 // filled by device
105 struct VirtioUsed {
106 	uint16 flags;
107 	uint16 idx;
108 	VirtioUsedItem ring[0];
109 };
110 
111 
112 // Input
113 
114 // VirtioInputConfig::select
115 enum {
116 	kVirtioInputCfgUnset    = 0x00,
117 	kVirtioInputCfgIdName   = 0x01,
118 	kVirtioInputCfgIdSerial = 0x02,
119 	kVirtioInputCfgIdDevids = 0x03,
120 	kVirtioInputCfgPropBits = 0x10,
121 	kVirtioInputCfgEvBits   = 0x11, // subsel: kVirtioInputEv*
122 	kVirtioInputCfgAbsInfo  = 0x12, // subsel: kVirtioInputAbs*
123 };
124 
125 enum {
126 	kVirtioInputEvSyn = 0,
127 	kVirtioInputEvKey = 1,
128 	kVirtioInputEvRel = 2,
129 	kVirtioInputEvAbs = 3,
130 	kVirtioInputEvRep = 4,
131 };
132 
133 enum {
134 	kVirtioInputBtnLeft     = 0x110,
135 	kVirtioInputBtnRight    = 0x111,
136 	kVirtioInputBtnMiddle   = 0x112,
137 	kVirtioInputBtnGearDown = 0x150,
138 	kVirtioInputBtnGearUp   = 0x151,
139 };
140 
141 enum {
142 	kVirtioInputRelX     = 0,
143 	kVirtioInputRelY     = 1,
144 	kVirtioInputRelZ     = 2,
145 	kVirtioInputRelWheel = 8,
146 };
147 
148 enum {
149 	kVirtioInputAbsX = 0,
150 	kVirtioInputAbsY = 1,
151 	kVirtioInputAbsZ = 2,
152 };
153 
154 
155 struct VirtioInputAbsinfo {
156 	int32 min;
157 	int32 max;
158 	int32 fuzz;
159 	int32 flat;
160 	int32 res;
161 };
162 
163 struct VirtioInputDevids {
164 	uint16 bustype;
165 	uint16 vendor;
166 	uint16 product;
167 	uint16 version;
168 };
169 
170 struct VirtioInputConfig {
171 	uint8 select; // in
172 	uint8 subsel; // in
173 	uint8 size;   // out, size of reply
174 	uint8 reserved[5];
175 	union {
176 		char  string[128];
177 		uint8 bitmap[128];
178 		VirtioInputAbsinfo abs;
179 		VirtioInputDevids ids;
180 	};
181 };
182 
183 struct VirtioInputPacket {
184 	uint16 type;
185 	uint16 code;
186 	int32 value;
187 };
188 
189 
190 // Block
191 
192 enum {
193 	kVirtioBlockTypeIn       = 0,
194 	kVirtioBlockTypeOut      = 1,
195 	kVirtioBlockTypeFlush    = 4,
196 	kVirtioBlockTypeFlushOut = 5,
197 };
198 
199 enum {
200 	kVirtioBlockStatusOk          = 0,
201 	kVirtioBlockStatusIoError     = 1,
202 	kVirtioBlockStatusUnsupported = 2,
203 };
204 
205 enum {
206 	kVirtioBlockSectorSize = 512,
207 };
208 
209 struct VirtioBlockRequest {
210 	uint32 type;
211 	uint32 ioprio;
212 	uint64 sectorNum;
213 };
214 
215 
216 #endif	// _VIRTIO_DEFS_H_
217