aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/virtual
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-05-21 22:46:09 -0400
committerRusty Russell <rusty@rustcorp.com.au>2012-05-21 22:46:09 -0400
commit33950c6e2269f516059e2fa777f8c7559dfa31a5 (patch)
tree3823b5c6609b3b08551ea0cffb0ab7c3a3a4b754 /Documentation/virtual
parent76e10d158efb6d4516018846f60c2ab5501900bc (diff)
virtio: update documentation to v0.9.5 of spec
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'Documentation/virtual')
-rw-r--r--Documentation/virtual/virtio-spec.txt1164
1 files changed, 1087 insertions, 77 deletions
diff --git a/Documentation/virtual/virtio-spec.txt b/Documentation/virtual/virtio-spec.txt
index da094737e2f8..0d6ec85481cb 100644
--- a/Documentation/virtual/virtio-spec.txt
+++ b/Documentation/virtual/virtio-spec.txt
@@ -1,11 +1,11 @@
1[Generated file: see http://ozlabs.org/~rusty/virtio-spec/] 1[Generated file: see http://ozlabs.org/~rusty/virtio-spec/]
2Virtio PCI Card Specification 2Virtio PCI Card Specification
3v0.9.1 DRAFT 3v0.9.5 DRAFT
4- 4-
5 5
6Rusty Russell <rusty@rustcorp.com.au>IBM Corporation (Editor) 6Rusty Russell <rusty@rustcorp.com.au> IBM Corporation (Editor)
7 7
82011 August 1. 82012 May 7.
9 9
10Purpose and Description 10Purpose and Description
11 11
@@ -68,11 +68,11 @@ and consists of three parts:
68+-------------------+-----------------------------------+-----------+ 68+-------------------+-----------------------------------+-----------+
69 69
70 70
71When the driver wants to send buffers to the device, it puts them 71When the driver wants to send a buffer to the device, it fills in
72in one or more slots in the descriptor table, and writes the 72a slot in the descriptor table (or chains several together), and
73descriptor indices into the available ring. It then notifies the 73writes the descriptor index into the available ring. It then
74device. When the device has finished with the buffers, it writes 74notifies the device. When the device has finished a buffer, it
75the descriptors into the used ring, and sends an interrupt. 75writes the descriptor into the used ring, and sends an interrupt.
76 76
77Specification 77Specification
78 78
@@ -106,8 +106,14 @@ for informational purposes by the guest).
106+----------------------+--------------------+---------------+ 106+----------------------+--------------------+---------------+
107| 6 | ioMemory | - | 107| 6 | ioMemory | - |
108+----------------------+--------------------+---------------+ 108+----------------------+--------------------+---------------+
109| 7 | rpmsg | Appendix H |
110+----------------------+--------------------+---------------+
111| 8 | SCSI host | Appendix I |
112+----------------------+--------------------+---------------+
109| 9 | 9P transport | - | 113| 9 | 9P transport | - |
110+----------------------+--------------------+---------------+ 114+----------------------+--------------------+---------------+
115| 10 | mac80211 wlan | - |
116+----------------------+--------------------+---------------+
111 117
112 118
113 Device Configuration 119 Device Configuration
@@ -127,7 +133,7 @@ Note that this is possible because while the virtio header is PCI
127the native endian of the guest (where such distinction is 133the native endian of the guest (where such distinction is
128applicable). 134applicable).
129 135
130 Device Initialization Sequence 136 Device Initialization Sequence<sub:Device-Initialization-Sequence>
131 137
132We start with an overview of device initialization, then expand 138We start with an overview of device initialization, then expand
133on the details of the device and how each step is preformed. 139on the details of the device and how each step is preformed.
@@ -177,7 +183,10 @@ The virtio header looks as follows:
177 183
178 184
179If MSI-X is enabled for the device, two additional fields 185If MSI-X is enabled for the device, two additional fields
180immediately follow this header: 186immediately follow this header:[footnote:
187ie. once you enable MSI-X on the device, the other fields move.
188If you turn it off again, they move back!
189]
181 190
182 191
183+------------++----------------+--------+ 192+------------++----------------+--------+
@@ -191,20 +200,6 @@ immediately follow this header:
191+------------++----------------+--------+ 200+------------++----------------+--------+
192 201
193 202
194Finally, if feature bits (VIRTIO_F_FEATURES_HI) this is
195immediately followed by two additional fields:
196
197
198+------------++----------------------+----------------------
199| Bits || 32 | 32
200+------------++----------------------+----------------------
201| Read/Write || R | R+W
202+------------++----------------------+----------------------
203| Purpose || Device | Guest
204| || Features bits 32:63 | Features bits 32:63
205+------------++----------------------+----------------------
206
207
208Immediately following these general headers, there may be 203Immediately following these general headers, there may be
209device-specific headers: 204device-specific headers:
210 205
@@ -238,31 +233,25 @@ at least one bit should be set:
238 may be a significant (or infinite) delay before setting this 233 may be a significant (or infinite) delay before setting this
239 bit. 234 bit.
240 235
241 DRIVER_OK (3) Indicates that the driver is set up and ready to 236 DRIVER_OK (4) Indicates that the driver is set up and ready to
242 drive the device. 237 drive the device.
243 238
244 FAILED (8) Indicates that something went wrong in the guest, 239 FAILED (128) Indicates that something went wrong in the guest,
245 and it has given up on the device. This could be an internal 240 and it has given up on the device. This could be an internal
246 error, or the driver didn't like the device for some reason, or 241 error, or the driver didn't like the device for some reason, or
247 even a fatal error during device operation. The device must be 242 even a fatal error during device operation. The device must be
248 reset before attempting to re-initialize. 243 reset before attempting to re-initialize.
249 244
250 Feature Bits 245 Feature Bits<sub:Feature-Bits>
251 246
252The least significant 31 bits of the first configuration field 247Thefirst configuration field indicates the features that the
253indicates the features that the device supports (the high bit is 248device supports. The bits are allocated as follows:
254reserved, and will be used to indicate the presence of future
255feature bits elsewhere). If more than 31 feature bits are
256supported, the device indicates so by setting feature bit 31 (see
257[cha:Reserved-Feature-Bits]). The bits are allocated as follows:
258 249
259 0 to 23 Feature bits for the specific device type 250 0 to 23 Feature bits for the specific device type
260 251
261 24 to 40 Feature bits reserved for extensions to the queue and 252 24 to 32 Feature bits reserved for extensions to the queue and
262 feature negotiation mechanisms 253 feature negotiation mechanisms
263 254
264 41 to 63 Feature bits reserved for future extensions
265
266For example, feature bit 0 for a network device (i.e. Subsystem 255For example, feature bit 0 for a network device (i.e. Subsystem
267Device ID 1) indicates that the device supports checksumming of 256Device ID 1) indicates that the device supports checksumming of
268packets. 257packets.
@@ -286,10 +275,6 @@ will not see that feature bit in the Device Features field and
286can go into backwards compatibility mode (or, for poor 275can go into backwards compatibility mode (or, for poor
287implementations, set the FAILED Device Status bit). 276implementations, set the FAILED Device Status bit).
288 277
289Access to feature bits 32 to 63 is enabled by Guest by setting
290feature bit 31. If this bit is unset, Device must assume that all
291feature bits > 31 are unset.
292
293 Configuration/Queue Vectors 278 Configuration/Queue Vectors
294 279
295When MSI-X capability is present and enabled in the device 280When MSI-X capability is present and enabled in the device
@@ -324,7 +309,7 @@ success, the previously written value is returned, and on
324failure, NO_VECTOR is returned. If a mapping failure is detected, 309failure, NO_VECTOR is returned. If a mapping failure is detected,
325the driver can retry mapping with fewervectors, or disable MSI-X. 310the driver can retry mapping with fewervectors, or disable MSI-X.
326 311
327 Virtqueue Configuration 312 Virtqueue Configuration<sec:Virtqueue-Configuration>
328 313
329As a device can have zero or more virtqueues for bulk data 314As a device can have zero or more virtqueues for bulk data
330transport (for example, the network driver has two), the driver 315transport (for example, the network driver has two), the driver
@@ -587,7 +572,7 @@ and Red Hat under the (3-clause) BSD license so that it can be
587freely used by all other projects, and is reproduced (with slight 572freely used by all other projects, and is reproduced (with slight
588variation to remove Linux assumptions) in Appendix A. 573variation to remove Linux assumptions) in Appendix A.
589 574
590 Device Operation 575 Device Operation<sec:Device-Operation>
591 576
592There are two parts to device operation: supplying new buffers to 577There are two parts to device operation: supplying new buffers to
593the device, and processing used buffers from the device. As an 578the device, and processing used buffers from the device. As an
@@ -813,7 +798,7 @@ vring.used->ring[vq->last_seen_used%vsz];
813 798
814} 799}
815 800
816 Dealing With Configuration Changes 801 Dealing With Configuration Changes<sub:Dealing-With-Configuration>
817 802
818Some virtio PCI devices can change the device configuration 803Some virtio PCI devices can change the device configuration
819state, as reflected in the virtio header in the PCI configuration 804state, as reflected in the virtio header in the PCI configuration
@@ -1260,18 +1245,6 @@ Currently there are five device-independent feature bits defined:
1260 driver should ignore the used_event field; the device should 1245 driver should ignore the used_event field; the device should
1261 ignore the avail_event field; the flags field is used 1246 ignore the avail_event field; the flags field is used
1262 1247
1263 VIRTIO_F_BAD_FEATURE(30) This feature should never be
1264 negotiated by the guest; doing so is an indication that the
1265 guest is faulty[footnote:
1266An experimental virtio PCI driver contained in Linux version
12672.6.25 had this problem, and this feature bit can be used to
1268detect it.
1269]
1270
1271 VIRTIO_F_FEATURES_HIGH(31) This feature indicates that the
1272 device supports feature bits 32:63. If unset, feature bits
1273 32:63 are unset.
1274
1275Appendix C: Network Device 1248Appendix C: Network Device
1276 1249
1277The virtio network device is a virtual ethernet card, and is the 1250The virtio network device is a virtual ethernet card, and is the
@@ -1335,11 +1308,17 @@ were required.
1335 1308
1336 VIRTIO_NET_F_CTRL_VLAN (19) Control channel VLAN filtering. 1309 VIRTIO_NET_F_CTRL_VLAN (19) Control channel VLAN filtering.
1337 1310
1311 VIRTIO_NET_F_GUEST_ANNOUNCE(21) Guest can send gratuitous
1312 packets.
1313
1338 Device configuration layout Two configuration fields are 1314 Device configuration layout Two configuration fields are
1339 currently defined. The mac address field always exists (though 1315 currently defined. The mac address field always exists (though
1340 is only valid if VIRTIO_NET_F_MAC is set), and the status field 1316 is only valid if VIRTIO_NET_F_MAC is set), and the status field
1341 only exists if VIRTIO_NET_F_STATUS is set. Only one bit is 1317 only exists if VIRTIO_NET_F_STATUS is set. Two read-only bits
1342 currently defined for the status field: VIRTIO_NET_S_LINK_UP. #define VIRTIO_NET_S_LINK_UP 1 1318 are currently defined for the status field:
1319 VIRTIO_NET_S_LINK_UP and VIRTIO_NET_S_ANNOUNCE. #define VIRTIO_NET_S_LINK_UP 1
1320
1321#define VIRTIO_NET_S_ANNOUNCE 2
1343 1322
1344 1323
1345 1324
@@ -1377,12 +1356,19 @@ struct virtio_net_config {
1377 packets by negotating the VIRTIO_NET_F_CSUM feature. This “ 1356 packets by negotating the VIRTIO_NET_F_CSUM feature. This “
1378 checksum offload” is a common feature on modern network cards. 1357 checksum offload” is a common feature on modern network cards.
1379 1358
1380 If that feature is negotiated, a driver can use TCP or UDP 1359 If that feature is negotiated[footnote:
1381 segmentation offload by negotiating the VIRTIO_NET_F_HOST_TSO4 1360ie. VIRTIO_NET_F_HOST_TSO* and VIRTIO_NET_F_HOST_UFO are
1382 (IPv4 TCP), VIRTIO_NET_F_HOST_TSO6 (IPv6 TCP) and 1361dependent on VIRTIO_NET_F_CSUM; a dvice which offers the offload
1383 VIRTIO_NET_F_HOST_UFO (UDP fragmentation) features. It should 1362features must offer the checksum feature, and a driver which
1384 not send TCP packets requiring segmentation offload which have 1363accepts the offload features must accept the checksum feature.
1385 the Explicit Congestion Notification bit set, unless the 1364Similar logic applies to the VIRTIO_NET_F_GUEST_TSO4 features
1365depending on VIRTIO_NET_F_GUEST_CSUM.
1366], a driver can use TCP or UDP segmentation offload by
1367 negotiating the VIRTIO_NET_F_HOST_TSO4 (IPv4 TCP),
1368 VIRTIO_NET_F_HOST_TSO6 (IPv6 TCP) and VIRTIO_NET_F_HOST_UFO
1369 (UDP fragmentation) features. It should not send TCP packets
1370 requiring segmentation offload which have the Explicit
1371 Congestion Notification bit set, unless the
1386 VIRTIO_NET_F_HOST_ECN feature is negotiated.[footnote: 1372 VIRTIO_NET_F_HOST_ECN feature is negotiated.[footnote:
1387This is a common restriction in real, older network cards. 1373This is a common restriction in real, older network cards.
1388] 1374]
@@ -1403,7 +1389,7 @@ segmentation, if both guests are amenable.
1403 1389
1404Packets are transmitted by placing them in the transmitq, and 1390Packets are transmitted by placing them in the transmitq, and
1405buffers for incoming packets are placed in the receiveq. In each 1391buffers for incoming packets are placed in the receiveq. In each
1406case, the packet itself is preceded by a header: 1392case, the packet itself is preceeded by a header:
1407 1393
1408struct virtio_net_hdr { 1394struct virtio_net_hdr {
1409 1395
@@ -1462,9 +1448,10 @@ It will have a 14 byte ethernet header and 20 byte IP header
1462followed by the TCP header (with the TCP checksum field 16 bytes 1448followed by the TCP header (with the TCP checksum field 16 bytes
1463into that header). csum_start will be 14+20 = 34 (the TCP 1449into that header). csum_start will be 14+20 = 34 (the TCP
1464checksum includes the header), and csum_offset will be 16. The 1450checksum includes the header), and csum_offset will be 16. The
1465value in the TCP checksum field will be the sum of the TCP pseudo 1451value in the TCP checksum field should be initialized to the sum
1466header, so that replacing it by the ones' complement checksum of 1452of the TCP pseudo header, so that replacing it by the ones'
1467the TCP header and body will give the correct result. 1453complement checksum of the TCP header and body will give the
1454correct result.
1468] 1455]
1469 1456
1470 <enu:If-the-driver>If the driver negotiated 1457 <enu:If-the-driver>If the driver negotiated
@@ -1483,8 +1470,8 @@ Due to various bugs in implementations, this field is not useful
1483as a guarantee of the transport header size. 1470as a guarantee of the transport header size.
1484] 1471]
1485 1472
1486 gso_size is the size of the packet beyond that header (ie. 1473 gso_size is the maximum size of each packet beyond that header
1487 MSS). 1474 (ie. MSS).
1488 1475
1489 If the driver negotiated the VIRTIO_NET_F_HOST_ECN feature, the 1476 If the driver negotiated the VIRTIO_NET_F_HOST_ECN feature, the
1490 VIRTIO_NET_HDR_GSO_ECN bit may be set in “gso_type” as well, 1477 VIRTIO_NET_HDR_GSO_ECN bit may be set in “gso_type” as well,
@@ -1567,7 +1554,9 @@ Processing packet involves:
1567 If the VIRTIO_NET_F_GUEST_TSO4, TSO6 or UFO options were 1554 If the VIRTIO_NET_F_GUEST_TSO4, TSO6 or UFO options were
1568 negotiated, then the “gso_type” may be something other than 1555 negotiated, then the “gso_type” may be something other than
1569 VIRTIO_NET_HDR_GSO_NONE, and the “gso_size” field indicates the 1556 VIRTIO_NET_HDR_GSO_NONE, and the “gso_size” field indicates the
1570 desired MSS (see [enu:If-the-driver]).Control Virtqueue 1557 desired MSS (see [enu:If-the-driver]).
1558
1559 Control Virtqueue
1571 1560
1572The driver uses the control virtqueue (if VIRTIO_NET_F_VTRL_VQ is 1561The driver uses the control virtqueue (if VIRTIO_NET_F_VTRL_VQ is
1573negotiated) to send commands to manipulate various features of 1562negotiated) to send commands to manipulate various features of
@@ -1642,7 +1631,7 @@ struct virtio_net_ctrl_mac {
1642 1631
1643The device can filter incoming packets by any number of 1632The device can filter incoming packets by any number of
1644destination MAC addresses.[footnote: 1633destination MAC addresses.[footnote:
1645Since there are no guarantees, it can use a hash filter 1634Since there are no guarentees, it can use a hash filter
1646orsilently switch to allmulti or promiscuous mode if it is given 1635orsilently switch to allmulti or promiscuous mode if it is given
1647too many addresses. 1636too many addresses.
1648] This table is set using the class VIRTIO_NET_CTRL_MAC and the 1637] This table is set using the class VIRTIO_NET_CTRL_MAC and the
@@ -1665,6 +1654,38 @@ can control a VLAN filter table in the device.
1665Both the VIRTIO_NET_CTRL_VLAN_ADD and VIRTIO_NET_CTRL_VLAN_DEL 1654Both the VIRTIO_NET_CTRL_VLAN_ADD and VIRTIO_NET_CTRL_VLAN_DEL
1666command take a 16-bit VLAN id as the command-specific-data. 1655command take a 16-bit VLAN id as the command-specific-data.
1667 1656
1657 Gratuitous Packet Sending
1658
1659If the driver negotiates the VIRTIO_NET_F_GUEST_ANNOUNCE (depends
1660on VIRTIO_NET_F_CTRL_VQ), it can ask the guest to send gratuitous
1661packets; this is usually done after the guest has been physically
1662migrated, and needs to announce its presence on the new network
1663links. (As hypervisor does not have the knowledge of guest
1664network configuration (eg. tagged vlan) it is simplest to prod
1665the guest in this way).
1666
1667#define VIRTIO_NET_CTRL_ANNOUNCE 3
1668
1669 #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0
1670
1671The Guest needs to check VIRTIO_NET_S_ANNOUNCE bit in status
1672field when it notices the changes of device configuration. The
1673command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that
1674driver has recevied the notification and device would clear the
1675VIRTIO_NET_S_ANNOUNCE bit in the status filed after it received
1676this command.
1677
1678Processing this notification involves:
1679
1680 Sending the gratuitous packets or marking there are pending
1681 gratuitous packets to be sent and letting deferred routine to
1682 send them.
1683
1684 Sending VIRTIO_NET_CTRL_ANNOUNCE_ACK command through control
1685 vq.
1686
1687 .
1688
1668Appendix D: Block Device 1689Appendix D: Block Device
1669 1690
1670The virtio block device is a simple virtual block device (ie. 1691The virtio block device is a simple virtual block device (ie.
@@ -1699,8 +1720,6 @@ device except where noted.
1699 1720
1700 VIRTIO_BLK_F_FLUSH (9) Cache flush command support. 1721 VIRTIO_BLK_F_FLUSH (9) Cache flush command support.
1701 1722
1702
1703
1704 Device configuration layout The capacity of the device 1723 Device configuration layout The capacity of the device
1705 (expressed in 512-byte sectors) is always present. The 1724 (expressed in 512-byte sectors) is always present. The
1706 availability of the others all depend on various feature bits 1725 availability of the others all depend on various feature bits
@@ -1743,8 +1762,6 @@ device except where noted.
1743 If the VIRTIO_BLK_F_RO feature is set by the device, any write 1762 If the VIRTIO_BLK_F_RO feature is set by the device, any write
1744 requests will fail. 1763 requests will fail.
1745 1764
1746
1747
1748 Device Operation 1765 Device Operation
1749 1766
1750The driver queues requests to the virtqueue, and they are used by 1767The driver queues requests to the virtqueue, and they are used by
@@ -1805,7 +1822,7 @@ the FLUSH and FLUSH_OUT types are equivalent, the device does not
1805distinguish between them 1822distinguish between them
1806]). If the device has VIRTIO_BLK_F_BARRIER feature the high bit 1823]). If the device has VIRTIO_BLK_F_BARRIER feature the high bit
1807(VIRTIO_BLK_T_BARRIER) indicates that this request acts as a 1824(VIRTIO_BLK_T_BARRIER) indicates that this request acts as a
1808barrier and that all preceding requests must be complete before 1825barrier and that all preceeding requests must be complete before
1809this one, and all following requests must not be started until 1826this one, and all following requests must not be started until
1810this is complete. Note that a barrier does not flush caches in 1827this is complete. Note that a barrier does not flush caches in
1811the underlying backend device in host, and thus does not serve as 1828the underlying backend device in host, and thus does not serve as
@@ -2118,7 +2135,7 @@ This is historical, and independent of the guest page size
2118 2135
2119 Otherwise, the guest may begin to re-use pages previously given 2136 Otherwise, the guest may begin to re-use pages previously given
2120 to the balloon before the device has acknowledged their 2137 to the balloon before the device has acknowledged their
2121 withdrawal. [footnote: 2138 withdrawl. [footnote:
2122In this case, deflation advice is merely a courtesy 2139In this case, deflation advice is merely a courtesy
2123] 2140]
2124 2141
@@ -2198,3 +2215,996 @@ as follows:
2198 VIRTIO_BALLOON_S_MEMTOT The total amount of memory available 2215 VIRTIO_BALLOON_S_MEMTOT The total amount of memory available
2199 (in bytes). 2216 (in bytes).
2200 2217
2218Appendix H: Rpmsg: Remote Processor Messaging
2219
2220Virtio rpmsg devices represent remote processors on the system
2221which run in asymmetric multi-processing (AMP) configuration, and
2222which are usually used to offload cpu-intensive tasks from the
2223main application processor (a typical SoC methodology).
2224
2225Virtio is being used to communicate with those remote processors;
2226empty buffers are placed in one virtqueue for receiving messages,
2227and non-empty buffers, containing outbound messages, are enqueued
2228in a second virtqueue for transmission.
2229
2230Numerous communication channels can be multiplexed over those two
2231virtqueues, so different entities, running on the application and
2232remote processor, can directly communicate in a point-to-point
2233fashion.
2234
2235 Configuration
2236
2237 Subsystem Device ID 7
2238
2239 Virtqueues 0:receiveq. 1:transmitq.
2240
2241 Feature bits
2242
2243 VIRTIO_RPMSG_F_NS (0) Device sends (and capable of receiving)
2244 name service messages announcing the creation (or
2245 destruction) of a channel:/**
2246
2247 * struct rpmsg_ns_msg - dynamic name service announcement
2248message
2249
2250 * @name: name of remote service that is published
2251
2252 * @addr: address of remote service that is published
2253
2254 * @flags: indicates whether service is created or destroyed
2255
2256 *
2257
2258 * This message is sent across to publish a new service (or
2259announce
2260
2261 * about its removal). When we receives these messages, an
2262appropriate
2263
2264 * rpmsg channel (i.e device) is created/destroyed.
2265
2266 */
2267
2268struct rpmsg_ns_msgoon_config {
2269
2270 char name[RPMSG_NAME_SIZE];
2271
2272 u32 addr;
2273
2274 u32 flags;
2275
2276} __packed;
2277
2278
2279
2280/**
2281
2282 * enum rpmsg_ns_flags - dynamic name service announcement flags
2283
2284 *
2285
2286 * @RPMSG_NS_CREATE: a new remote service was just created
2287
2288 * @RPMSG_NS_DESTROY: a remote service was just destroyed
2289
2290 */
2291
2292enum rpmsg_ns_flags {
2293
2294 RPMSG_NS_CREATE = 0,
2295
2296 RPMSG_NS_DESTROY = 1,
2297
2298};
2299
2300 Device configuration layout
2301
2302At his point none currently defined.
2303
2304 Device Initialization
2305
2306 The initialization routine should identify the receive and
2307 transmission virtqueues.
2308
2309 The receive virtqueue should be filled with receive buffers.
2310
2311 Device Operation
2312
2313Messages are transmitted by placing them in the transmitq, and
2314buffers for inbound messages are placed in the receiveq. In any
2315case, messages are always preceded by the following header: /**
2316
2317 * struct rpmsg_hdr - common header for all rpmsg messages
2318
2319 * @src: source address
2320
2321 * @dst: destination address
2322
2323 * @reserved: reserved for future use
2324
2325 * @len: length of payload (in bytes)
2326
2327 * @flags: message flags
2328
2329 * @data: @len bytes of message payload data
2330
2331 *
2332
2333 * Every message sent(/received) on the rpmsg bus begins with
2334this header.
2335
2336 */
2337
2338struct rpmsg_hdr {
2339
2340 u32 src;
2341
2342 u32 dst;
2343
2344 u32 reserved;
2345
2346 u16 len;
2347
2348 u16 flags;
2349
2350 u8 data[0];
2351
2352} __packed;
2353
2354Appendix I: SCSI Host Device
2355
2356The virtio SCSI host device groups together one or more virtual
2357logical units (such as disks), and allows communicating to them
2358using the SCSI protocol. An instance of the device represents a
2359SCSI host to which many targets and LUNs are attached.
2360
2361The virtio SCSI device services two kinds of requests:
2362
2363 command requests for a logical unit;
2364
2365 task management functions related to a logical unit, target or
2366 command.
2367
2368The device is also able to send out notifications about added and
2369removed logical units. Together, these capabilities provide a
2370SCSI transport protocol that uses virtqueues as the transfer
2371medium. In the transport protocol, the virtio driver acts as the
2372initiator, while the virtio SCSI host provides one or more
2373targets that receive and process the requests.
2374
2375 Configuration
2376
2377 Subsystem Device ID 8
2378
2379 Virtqueues 0:controlq; 1:eventq; 2..n:request queues.
2380
2381 Feature bits
2382
2383 VIRTIO_SCSI_F_INOUT (0) A single request can include both
2384 read-only and write-only data buffers.
2385
2386 VIRTIO_SCSI_F_HOTPLUG (1) The host should enable
2387 hot-plug/hot-unplug of new LUNs and targets on the SCSI bus.
2388
2389 Device configuration layout All fields of this configuration
2390 are always available. sense_size and cdb_size are writable by
2391 the guest.struct virtio_scsi_config {
2392
2393 u32 num_queues;
2394
2395 u32 seg_max;
2396
2397 u32 max_sectors;
2398
2399 u32 cmd_per_lun;
2400
2401 u32 event_info_size;
2402
2403 u32 sense_size;
2404
2405 u32 cdb_size;
2406
2407 u16 max_channel;
2408
2409 u16 max_target;
2410
2411 u32 max_lun;
2412
2413};
2414
2415 num_queues is the total number of request virtqueues exposed by
2416 the device. The driver is free to use only one request queue,
2417 or it can use more to achieve better performance.
2418
2419 seg_max is the maximum number of segments that can be in a
2420 command. A bidirectional command can include seg_max input
2421 segments and seg_max output segments.
2422
2423 max_sectors is a hint to the guest about the maximum transfer
2424 size it should use.
2425
2426 cmd_per_lun is a hint to the guest about the maximum number of
2427 linked commands it should send to one LUN. The actual value
2428 to be used is the minimum of cmd_per_lun and the virtqueue
2429 size.
2430
2431 event_info_size is the maximum size that the device will fill
2432 for buffers that the driver places in the eventq. The driver
2433 should always put buffers at least of this size. It is
2434 written by the device depending on the set of negotated
2435 features.
2436
2437 sense_size is the maximum size of the sense data that the
2438 device will write. The default value is written by the device
2439 and will always be 96, but the driver can modify it. It is
2440 restored to the default when the device is reset.
2441
2442 cdb_size is the maximum size of the CDB that the driver will
2443 write. The default value is written by the device and will
2444 always be 32, but the driver can likewise modify it. It is
2445 restored to the default when the device is reset.
2446
2447 max_channel, max_target and max_lun can be used by the driver
2448 as hints to constrain scanning the logical units on the
2449 host.h
2450
2451 Device Initialization
2452
2453The initialization routine should first of all discover the
2454device's virtqueues.
2455
2456If the driver uses the eventq, it should then place at least a
2457buffer in the eventq.
2458
2459The driver can immediately issue requests (for example, INQUIRY
2460or REPORT LUNS) or task management functions (for example, I_T
2461RESET).
2462
2463 Device Operation: request queues
2464
2465The driver queues requests to an arbitrary request queue, and
2466they are used by the device on that same queue. It is the
2467responsibility of the driver to ensure strict request ordering
2468for commands placed on different queues, because they will be
2469consumed with no order constraints.
2470
2471Requests have the following format:
2472
2473struct virtio_scsi_req_cmd {
2474
2475 // Read-only
2476
2477 u8 lun[8];
2478
2479 u64 id;
2480
2481 u8 task_attr;
2482
2483 u8 prio;
2484
2485 u8 crn;
2486
2487 char cdb[cdb_size];
2488
2489 char dataout[];
2490
2491 // Write-only part
2492
2493 u32 sense_len;
2494
2495 u32 residual;
2496
2497 u16 status_qualifier;
2498
2499 u8 status;
2500
2501 u8 response;
2502
2503 u8 sense[sense_size];
2504
2505 char datain[];
2506
2507};
2508
2509
2510
2511/* command-specific response values */
2512
2513#define VIRTIO_SCSI_S_OK 0
2514
2515#define VIRTIO_SCSI_S_OVERRUN 1
2516
2517#define VIRTIO_SCSI_S_ABORTED 2
2518
2519#define VIRTIO_SCSI_S_BAD_TARGET 3
2520
2521#define VIRTIO_SCSI_S_RESET 4
2522
2523#define VIRTIO_SCSI_S_BUSY 5
2524
2525#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
2526
2527#define VIRTIO_SCSI_S_TARGET_FAILURE 7
2528
2529#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
2530
2531#define VIRTIO_SCSI_S_FAILURE 9
2532
2533
2534
2535/* task_attr */
2536
2537#define VIRTIO_SCSI_S_SIMPLE 0
2538
2539#define VIRTIO_SCSI_S_ORDERED 1
2540
2541#define VIRTIO_SCSI_S_HEAD 2
2542
2543#define VIRTIO_SCSI_S_ACA 3
2544
2545The lun field addresses a target and logical unit in the
2546virtio-scsi device's SCSI domain. The only supported format for
2547the LUN field is: first byte set to 1, second byte set to target,
2548third and fourth byte representing a single level LUN structure,
2549followed by four zero bytes. With this representation, a
2550virtio-scsi device can serve up to 256 targets and 16384 LUNs per
2551target.
2552
2553The id field is the command identifier (“tag”).
2554
2555task_attr, prio and crn should be left to zero. task_attr defines
2556the task attribute as in the table above, but all task attributes
2557may be mapped to SIMPLE by the device; crn may also be provided
2558by clients, but is generally expected to be 0. The maximum CRN
2559value defined by the protocol is 255, since CRN is stored in an
25608-bit integer.
2561
2562All of these fields are defined in SAM. They are always
2563read-only, as are the cdb and dataout field. The cdb_size is
2564taken from the configuration space.
2565
2566sense and subsequent fields are always write-only. The sense_len
2567field indicates the number of bytes actually written to the sense
2568buffer. The residual field indicates the residual size,
2569calculated as “data_length - number_of_transferred_bytes”, for
2570read or write operations. For bidirectional commands, the
2571number_of_transferred_bytes includes both read and written bytes.
2572A residual field that is less than the size of datain means that
2573the dataout field was processed entirely. A residual field that
2574exceeds the size of datain means that the dataout field was
2575processed partially and the datain field was not processed at
2576all.
2577
2578The status byte is written by the device to be the status code as
2579defined in SAM.
2580
2581The response byte is written by the device to be one of the
2582following:
2583
2584 VIRTIO_SCSI_S_OK when the request was completed and the status
2585 byte is filled with a SCSI status code (not necessarily
2586 "GOOD").
2587
2588 VIRTIO_SCSI_S_OVERRUN if the content of the CDB requires
2589 transferring more data than is available in the data buffers.
2590
2591 VIRTIO_SCSI_S_ABORTED if the request was cancelled due to an
2592 ABORT TASK or ABORT TASK SET task management function.
2593
2594 VIRTIO_SCSI_S_BAD_TARGET if the request was never processed
2595 because the target indicated by the lun field does not exist.
2596
2597 VIRTIO_SCSI_S_RESET if the request was cancelled due to a bus
2598 or device reset (including a task management function).
2599
2600 VIRTIO_SCSI_S_TRANSPORT_FAILURE if the request failed due to a
2601 problem in the connection between the host and the target
2602 (severed link).
2603
2604 VIRTIO_SCSI_S_TARGET_FAILURE if the target is suffering a
2605 failure and the guest should not retry on other paths.
2606
2607 VIRTIO_SCSI_S_NEXUS_FAILURE if the nexus is suffering a failure
2608 but retrying on other paths might yield a different result.
2609
2610 VIRTIO_SCSI_S_BUSY if the request failed but retrying on the
2611 same path should work.
2612
2613 VIRTIO_SCSI_S_FAILURE for other host or guest error. In
2614 particular, if neither dataout nor datain is empty, and the
2615 VIRTIO_SCSI_F_INOUT feature has not been negotiated, the
2616 request will be immediately returned with a response equal to
2617 VIRTIO_SCSI_S_FAILURE.
2618
2619 Device Operation: controlq
2620
2621The controlq is used for other SCSI transport operations.
2622Requests have the following format:
2623
2624struct virtio_scsi_ctrl {
2625
2626 u32 type;
2627
2628 ...
2629
2630 u8 response;
2631
2632};
2633
2634
2635
2636/* response values valid for all commands */
2637
2638#define VIRTIO_SCSI_S_OK 0
2639
2640#define VIRTIO_SCSI_S_BAD_TARGET 3
2641
2642#define VIRTIO_SCSI_S_BUSY 5
2643
2644#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
2645
2646#define VIRTIO_SCSI_S_TARGET_FAILURE 7
2647
2648#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
2649
2650#define VIRTIO_SCSI_S_FAILURE 9
2651
2652#define VIRTIO_SCSI_S_INCORRECT_LUN 12
2653
2654The type identifies the remaining fields.
2655
2656The following commands are defined:
2657
2658 Task management function
2659#define VIRTIO_SCSI_T_TMF 0
2660
2661
2662
2663#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
2664
2665#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
2666
2667#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
2668
2669#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
2670
2671#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
2672
2673#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
2674
2675#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
2676
2677#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
2678
2679
2680
2681struct virtio_scsi_ctrl_tmf
2682
2683{
2684
2685 // Read-only part
2686
2687 u32 type;
2688
2689 u32 subtype;
2690
2691 u8 lun[8];
2692
2693 u64 id;
2694
2695 // Write-only part
2696
2697 u8 response;
2698
2699}
2700
2701
2702
2703/* command-specific response values */
2704
2705#define VIRTIO_SCSI_S_FUNCTION_COMPLETE 0
2706
2707#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
2708
2709#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
2710
2711 The type is VIRTIO_SCSI_T_TMF; the subtype field defines. All
2712 fields except response are filled by the driver. The subtype
2713 field must always be specified and identifies the requested
2714 task management function.
2715
2716 Other fields may be irrelevant for the requested TMF; if so,
2717 they are ignored but they should still be present. The lun
2718 field is in the same format specified for request queues; the
2719 single level LUN is ignored when the task management function
2720 addresses a whole I_T nexus. When relevant, the value of the id
2721 field is matched against the id values passed on the requestq.
2722
2723 The outcome of the task management function is written by the
2724 device in the response field. The command-specific response
2725 values map 1-to-1 with those defined in SAM.
2726
2727 Asynchronous notification query
2728#define VIRTIO_SCSI_T_AN_QUERY 1
2729
2730
2731
2732struct virtio_scsi_ctrl_an {
2733
2734 // Read-only part
2735
2736 u32 type;
2737
2738 u8 lun[8];
2739
2740 u32 event_requested;
2741
2742 // Write-only part
2743
2744 u32 event_actual;
2745
2746 u8 response;
2747
2748}
2749
2750
2751
2752#define VIRTIO_SCSI_EVT_ASYNC_OPERATIONAL_CHANGE 2
2753
2754#define VIRTIO_SCSI_EVT_ASYNC_POWER_MGMT 4
2755
2756#define VIRTIO_SCSI_EVT_ASYNC_EXTERNAL_REQUEST 8
2757
2758#define VIRTIO_SCSI_EVT_ASYNC_MEDIA_CHANGE 16
2759
2760#define VIRTIO_SCSI_EVT_ASYNC_MULTI_HOST 32
2761
2762#define VIRTIO_SCSI_EVT_ASYNC_DEVICE_BUSY 64
2763
2764 By sending this command, the driver asks the device which
2765 events the given LUN can report, as described in paragraphs 6.6
2766 and A.6 of the SCSI MMC specification. The driver writes the
2767 events it is interested in into the event_requested; the device
2768 responds by writing the events that it supports into
2769 event_actual.
2770
2771 The type is VIRTIO_SCSI_T_AN_QUERY. The lun and event_requested
2772 fields are written by the driver. The event_actual and response
2773 fields are written by the device.
2774
2775 No command-specific values are defined for the response byte.
2776
2777 Asynchronous notification subscription
2778#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
2779
2780
2781
2782struct virtio_scsi_ctrl_an {
2783
2784 // Read-only part
2785
2786 u32 type;
2787
2788 u8 lun[8];
2789
2790 u32 event_requested;
2791
2792 // Write-only part
2793
2794 u32 event_actual;
2795
2796 u8 response;
2797
2798}
2799
2800 By sending this command, the driver asks the specified LUN to
2801 report events for its physical interface, again as described in
2802 the SCSI MMC specification. The driver writes the events it is
2803 interested in into the event_requested; the device responds by
2804 writing the events that it supports into event_actual.
2805
2806 Event types are the same as for the asynchronous notification
2807 query message.
2808
2809 The type is VIRTIO_SCSI_T_AN_SUBSCRIBE. The lun and
2810 event_requested fields are written by the driver. The
2811 event_actual and response fields are written by the device.
2812
2813 No command-specific values are defined for the response byte.
2814
2815 Device Operation: eventq
2816
2817The eventq is used by the device to report information on logical
2818units that are attached to it. The driver should always leave a
2819few buffers ready in the eventq. In general, the device will not
2820queue events to cope with an empty eventq, and will end up
2821dropping events if it finds no buffer ready. However, when
2822reporting events for many LUNs (e.g. when a whole target
2823disappears), the device can throttle events to avoid dropping
2824them. For this reason, placing 10-15 buffers on the event queue
2825should be enough.
2826
2827Buffers are placed in the eventq and filled by the device when
2828interesting events occur. The buffers should be strictly
2829write-only (device-filled) and the size of the buffers should be
2830at least the value given in the device's configuration
2831information.
2832
2833Buffers returned by the device on the eventq will be referred to
2834as "events" in the rest of this section. Events have the
2835following format:
2836
2837#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
2838
2839
2840
2841struct virtio_scsi_event {
2842
2843 // Write-only part
2844
2845 u32 event;
2846
2847 ...
2848
2849}
2850
2851If bit 31 is set in the event field, the device failed to report
2852an event due to missing buffers. In this case, the driver should
2853poll the logical units for unit attention conditions, and/or do
2854whatever form of bus scan is appropriate for the guest operating
2855system.
2856
2857Other data that the device writes to the buffer depends on the
2858contents of the event field. The following events are defined:
2859
2860 No event
2861#define VIRTIO_SCSI_T_NO_EVENT 0
2862
2863 This event is fired in the following cases:
2864
2865 When the device detects in the eventq a buffer that is shorter
2866 than what is indicated in the configuration field, it might
2867 use it immediately and put this dummy value in the event
2868 field. A well-written driver will never observe this
2869 situation.
2870
2871 When events are dropped, the device may signal this event as
2872 soon as the drivers makes a buffer available, in order to
2873 request action from the driver. In this case, of course, this
2874 event will be reported with the VIRTIO_SCSI_T_EVENTS_MISSED
2875 flag.
2876
2877 Transport reset
2878#define VIRTIO_SCSI_T_TRANSPORT_RESET 1
2879
2880
2881
2882struct virtio_scsi_event_reset {
2883
2884 // Write-only part
2885
2886 u32 event;
2887
2888 u8 lun[8];
2889
2890 u32 reason;
2891
2892}
2893
2894
2895
2896#define VIRTIO_SCSI_EVT_RESET_HARD 0
2897
2898#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
2899
2900#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
2901
2902 By sending this event, the device signals that a logical unit
2903 on a target has been reset, including the case of a new device
2904 appearing or disappearing on the bus.The device fills in all
2905 fields. The event field is set to
2906 VIRTIO_SCSI_T_TRANSPORT_RESET. The lun field addresses a
2907 logical unit in the SCSI host.
2908
2909 The reason value is one of the three #define values appearing
2910 above:
2911
2912 VIRTIO_SCSI_EVT_RESET_REMOVED (“LUN/target removed”) is used if
2913 the target or logical unit is no longer able to receive
2914 commands.
2915
2916 VIRTIO_SCSI_EVT_RESET_HARD (“LUN hard reset”) is used if the
2917 logical unit has been reset, but is still present.
2918
2919 VIRTIO_SCSI_EVT_RESET_RESCAN (“rescan LUN/target”) is used if a
2920 target or logical unit has just appeared on the device.
2921
2922 The “removed” and “rescan” events, when sent for LUN 0, may
2923 apply to the entire target. After receiving them the driver
2924 should ask the initiator to rescan the target, in order to
2925 detect the case when an entire target has appeared or
2926 disappeared. These two events will never be reported unless the
2927 VIRTIO_SCSI_F_HOTPLUG feature was negotiated between the host
2928 and the guest.
2929
2930 Events will also be reported via sense codes (this obviously
2931 does not apply to newly appeared buses or targets, since the
2932 application has never discovered them):
2933
2934 “LUN/target removed” maps to sense key ILLEGAL REQUEST, asc
2935 0x25, ascq 0x00 (LOGICAL UNIT NOT SUPPORTED)
2936
2937 “LUN hard reset” maps to sense key UNIT ATTENTION, asc 0x29
2938 (POWER ON, RESET OR BUS DEVICE RESET OCCURRED)
2939
2940 “rescan LUN/target” maps to sense key UNIT ATTENTION, asc 0x3f,
2941 ascq 0x0e (REPORTED LUNS DATA HAS CHANGED)
2942
2943 The preferred way to detect transport reset is always to use
2944 events, because sense codes are only seen by the driver when it
2945 sends a SCSI command to the logical unit or target. However, in
2946 case events are dropped, the initiator will still be able to
2947 synchronize with the actual state of the controller if the
2948 driver asks the initiator to rescan of the SCSI bus. During the
2949 rescan, the initiator will be able to observe the above sense
2950 codes, and it will process them as if it the driver had
2951 received the equivalent event.
2952
2953 Asynchronous notification
2954#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
2955
2956
2957
2958struct virtio_scsi_event_an {
2959
2960 // Write-only part
2961
2962 u32 event;
2963
2964 u8 lun[8];
2965
2966 u32 reason;
2967
2968}
2969
2970 By sending this event, the device signals that an asynchronous
2971 event was fired from a physical interface.
2972
2973 All fields are written by the device. The event field is set to
2974 VIRTIO_SCSI_T_ASYNC_NOTIFY. The lun field addresses a logical
2975 unit in the SCSI host. The reason field is a subset of the
2976 events that the driver has subscribed to via the "Asynchronous
2977 notification subscription" command.
2978
2979 When dropped events are reported, the driver should poll for
2980 asynchronous events manually using SCSI commands.
2981
2982Appendix X: virtio-mmio
2983
2984Virtual environments without PCI support (a common situation in
2985embedded devices models) might use simple memory mapped device (“
2986virtio-mmio”) instead of the PCI device.
2987
2988The memory mapped virtio device behaviour is based on the PCI
2989device specification. Therefore most of operations like device
2990initialization, queues configuration and buffer transfers are
2991nearly identical. Existing differences are described in the
2992following sections.
2993
2994 Device Initialization
2995
2996Instead of using the PCI IO space for virtio header, the “
2997virtio-mmio” device provides a set of memory mapped control
2998registers, all 32 bits wide, followed by device-specific
2999configuration space. The following list presents their layout:
3000
3001 Offset from the device base address | Direction | Name
3002 Description
3003
3004 0x000 | R | MagicValue
3005 “virt” string.
3006
3007 0x004 | R | Version
3008 Device version number. Currently must be 1.
3009
3010 0x008 | R | DeviceID
3011 Virtio Subsystem Device ID (ie. 1 for network card).
3012
3013 0x00c | R | VendorID
3014 Virtio Subsystem Vendor ID.
3015
3016 0x010 | R | HostFeatures
3017 Flags representing features the device supports.
3018 Reading from this register returns 32 consecutive flag bits,
3019 first bit depending on the last value written to
3020 HostFeaturesSel register. Access to this register returns bits HostFeaturesSel*32
3021
3022 to (HostFeaturesSel*32)+31
3023, eg. feature bits 0 to 31 if
3024 HostFeaturesSel is set to 0 and features bits 32 to 63 if
3025 HostFeaturesSel is set to 1. Also see [sub:Feature-Bits]
3026
3027 0x014 | W | HostFeaturesSel
3028 Device (Host) features word selection.
3029 Writing to this register selects a set of 32 device feature bits
3030 accessible by reading from HostFeatures register. Device driver
3031 must write a value to the HostFeaturesSel register before
3032 reading from the HostFeatures register.
3033
3034 0x020 | W | GuestFeatures
3035 Flags representing device features understood and activated by
3036 the driver.
3037 Writing to this register sets 32 consecutive flag bits, first
3038 bit depending on the last value written to GuestFeaturesSel
3039 register. Access to this register sets bits GuestFeaturesSel*32
3040
3041 to (GuestFeaturesSel*32)+31
3042, eg. feature bits 0 to 31 if
3043 GuestFeaturesSel is set to 0 and features bits 32 to 63 if
3044 GuestFeaturesSel is set to 1. Also see [sub:Feature-Bits]
3045
3046 0x024 | W | GuestFeaturesSel
3047 Activated (Guest) features word selection.
3048 Writing to this register selects a set of 32 activated feature
3049 bits accessible by writing to the GuestFeatures register.
3050 Device driver must write a value to the GuestFeaturesSel
3051 register before writing to the GuestFeatures register.
3052
3053 0x028 | W | GuestPageSize
3054 Guest page size.
3055 Device driver must write the guest page size in bytes to the
3056 register during initialization, before any queues are used.
3057 This value must be a power of 2 and is used by the Host to
3058 calculate Guest address of the first queue page (see QueuePFN).
3059
3060 0x030 | W | QueueSel
3061 Virtual queue index (first queue is 0).
3062 Writing to this register selects the virtual queue that the
3063 following operations on QueueNum, QueueAlign and QueuePFN apply
3064 to.
3065
3066 0x034 | R | QueueNumMax
3067 Maximum virtual queue size.
3068 Reading from the register returns the maximum size of the queue
3069 the Host is ready to process or zero (0x0) if the queue is not
3070 available. This applies to the queue selected by writing to
3071 QueueSel and is allowed only when QueuePFN is set to zero
3072 (0x0), so when the queue is not actively used.
3073
3074 0x038 | W | QueueNum
3075 Virtual queue size.
3076 Queue size is a number of elements in the queue, therefore size
3077 of the descriptor table and both available and used rings.
3078 Writing to this register notifies the Host what size of the
3079 queue the Guest will use. This applies to the queue selected by
3080 writing to QueueSel.
3081
3082 0x03c | W | QueueAlign
3083 Used Ring alignment in the virtual queue.
3084 Writing to this register notifies the Host about alignment
3085 boundary of the Used Ring in bytes. This value must be a power
3086 of 2 and applies to the queue selected by writing to QueueSel.
3087
3088 0x040 | RW | QueuePFN
3089 Guest physical page number of the virtual queue.
3090 Writing to this register notifies the host about location of the
3091 virtual queue in the Guest's physical address space. This value
3092 is the index number of a page starting with the queue
3093 Descriptor Table. Value zero (0x0) means physical address zero
3094 (0x00000000) and is illegal. When the Guest stops using the
3095 queue it must write zero (0x0) to this register.
3096 Reading from this register returns the currently used page
3097 number of the queue, therefore a value other than zero (0x0)
3098 means that the queue is in use.
3099 Both read and write accesses apply to the queue selected by
3100 writing to QueueSel.
3101
3102 0x050 | W | QueueNotify
3103 Queue notifier.
3104 Writing a queue index to this register notifies the Host that
3105 there are new buffers to process in the queue.
3106
3107 0x60 | R | InterruptStatus
3108Interrupt status.
3109Reading from this register returns a bit mask of interrupts
3110 asserted by the device. An interrupt is asserted if the
3111 corresponding bit is set, ie. equals one (1).
3112
3113 Bit 0 | Used Ring Update
3114This interrupt is asserted when the Host has updated the Used
3115 Ring in at least one of the active virtual queues.
3116
3117 Bit 1 | Configuration change
3118This interrupt is asserted when configuration of the device has
3119 changed.
3120
3121 0x064 | W | InterruptACK
3122 Interrupt acknowledge.
3123 Writing to this register notifies the Host that the Guest
3124 finished handling interrupts. Set bits in the value clear the
3125 corresponding bits of the InterruptStatus register.
3126
3127 0x070 | RW | Status
3128 Device status.
3129 Reading from this register returns the current device status
3130 flags.
3131 Writing non-zero values to this register sets the status flags,
3132 indicating the Guest progress. Writing zero (0x0) to this
3133 register triggers a device reset.
3134 Also see [sub:Device-Initialization-Sequence]
3135
3136 0x100+ | RW | Config
3137 Device-specific configuration space starts at an offset 0x100
3138 and is accessed with byte alignment. Its meaning and size
3139 depends on the device and the driver.
3140
3141Virtual queue size is a number of elements in the queue,
3142therefore size of the descriptor table and both available and
3143used rings.
3144
3145The endianness of the registers follows the native endianness of
3146the Guest. Writing to registers described as “R” and reading from
3147registers described as “W” is not permitted and can cause
3148undefined behavior.
3149
3150The device initialization is performed as described in [sub:Device-Initialization-Sequence]
3151 with one exception: the Guest must notify the Host about its
3152page size, writing the size in bytes to GuestPageSize register
3153before the initialization is finished.
3154
3155The memory mapped virtio devices generate single interrupt only,
3156therefore no special configuration is required.
3157
3158 Virtqueue Configuration
3159
3160The virtual queue configuration is performed in a similar way to
3161the one described in [sec:Virtqueue-Configuration] with a few
3162additional operations:
3163
3164 Select the queue writing its index (first queue is 0) to the
3165 QueueSel register.
3166
3167 Check if the queue is not already in use: read QueuePFN
3168 register, returned value should be zero (0x0).
3169
3170 Read maximum queue size (number of elements) from the
3171 QueueNumMax register. If the returned value is zero (0x0) the
3172 queue is not available.
3173
3174 Allocate and zero the queue pages in contiguous virtual memory,
3175 aligning the Used Ring to an optimal boundary (usually page
3176 size). Size of the allocated queue may be smaller than or equal
3177 to the maximum size returned by the Host.
3178
3179 Notify the Host about the queue size by writing the size to
3180 QueueNum register.
3181
3182 Notify the Host about the used alignment by writing its value
3183 in bytes to QueueAlign register.
3184
3185 Write the physical number of the first page of the queue to the
3186 QueuePFN register.
3187
3188The queue and the device are ready to begin normal operations
3189now.
3190
3191 Device Operation
3192
3193The memory mapped virtio device behaves in the same way as
3194described in [sec:Device-Operation], with the following
3195exceptions:
3196
3197 The device is notified about new buffers available in a queue
3198 by writing the queue index to register QueueNum instead of the
3199 virtio header in PCI I/O space ([sub:Notifying-The-Device]).
3200
3201 The memory mapped virtio device is using single, dedicated
3202 interrupt signal, which is raised when at least one of the
3203 interrupts described in the InterruptStatus register
3204 description is asserted. After receiving an interrupt, the
3205 driver must read the InterruptStatus register to check what
3206 caused the interrupt (see the register description). After the
3207 interrupt is handled, the driver must acknowledge it by writing
3208 a bit mask corresponding to the serviced interrupt to the
3209 InterruptACK register.
3210