···11+#ifndef _LINUX_VIRTIO_9P_H
22+#define _LINUX_VIRTIO_9P_H
33+/* This header is BSD licensed so anyone can use the definitions to implement
44+ * compatible drivers/servers.
55+ *
66+ * Redistribution and use in source and binary forms, with or without
77+ * modification, are permitted provided that the following conditions
88+ * are met:
99+ * 1. Redistributions of source code must retain the above copyright
1010+ * notice, this list of conditions and the following disclaimer.
1111+ * 2. Redistributions in binary form must reproduce the above copyright
1212+ * notice, this list of conditions and the following disclaimer in the
1313+ * documentation and/or other materials provided with the distribution.
1414+ * 3. Neither the name of IBM nor the names of its contributors
1515+ * may be used to endorse or promote products derived from this software
1616+ * without specific prior written permission.
1717+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
1818+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2020+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2121+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2222+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2424+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2626+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727+ * SUCH DAMAGE. */
2828+#include "standard-headers/linux/types.h"
2929+#include "standard-headers/linux/virtio_ids.h"
3030+#include "standard-headers/linux/virtio_config.h"
3131+3232+/* The feature bitmap for virtio 9P */
3333+3434+/* The mount point is specified in a config variable */
3535+#define VIRTIO_9P_MOUNT_TAG 0
3636+3737+struct virtio_9p_config {
3838+ /* length of the tag name */
3939+ uint16_t tag_len;
4040+ /* non-NULL terminated tag name */
4141+ uint8_t tag[0];
4242+} QEMU_PACKED;
4343+4444+#endif /* _LINUX_VIRTIO_9P_H */
+59
include/standard-headers/linux/virtio_balloon.h
···11+#ifndef _LINUX_VIRTIO_BALLOON_H
22+#define _LINUX_VIRTIO_BALLOON_H
33+/* This header is BSD licensed so anyone can use the definitions to implement
44+ * compatible drivers/servers.
55+ *
66+ * Redistribution and use in source and binary forms, with or without
77+ * modification, are permitted provided that the following conditions
88+ * are met:
99+ * 1. Redistributions of source code must retain the above copyright
1010+ * notice, this list of conditions and the following disclaimer.
1111+ * 2. Redistributions in binary form must reproduce the above copyright
1212+ * notice, this list of conditions and the following disclaimer in the
1313+ * documentation and/or other materials provided with the distribution.
1414+ * 3. Neither the name of IBM nor the names of its contributors
1515+ * may be used to endorse or promote products derived from this software
1616+ * without specific prior written permission.
1717+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
1818+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2020+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2121+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2222+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2424+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2626+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727+ * SUCH DAMAGE. */
2828+#include "standard-headers/linux/virtio_ids.h"
2929+#include "standard-headers/linux/virtio_config.h"
3030+3131+/* The feature bitmap for virtio balloon */
3232+#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
3333+#define VIRTIO_BALLOON_F_STATS_VQ 1 /* Memory Stats virtqueue */
3434+#define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon on OOM */
3535+3636+/* Size of a PFN in the balloon interface. */
3737+#define VIRTIO_BALLOON_PFN_SHIFT 12
3838+3939+struct virtio_balloon_config {
4040+ /* Number of pages host wants Guest to give up. */
4141+ uint32_t num_pages;
4242+ /* Number of pages we've actually got in balloon. */
4343+ uint32_t actual;
4444+};
4545+4646+#define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */
4747+#define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */
4848+#define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */
4949+#define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */
5050+#define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */
5151+#define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */
5252+#define VIRTIO_BALLOON_S_NR 6
5353+5454+struct virtio_balloon_stat {
5555+ uint16_t tag;
5656+ uint64_t val;
5757+} QEMU_PACKED;
5858+5959+#endif /* _LINUX_VIRTIO_BALLOON_H */
+143
include/standard-headers/linux/virtio_blk.h
···11+#ifndef _LINUX_VIRTIO_BLK_H
22+#define _LINUX_VIRTIO_BLK_H
33+/* This header is BSD licensed so anyone can use the definitions to implement
44+ * compatible drivers/servers.
55+ *
66+ * Redistribution and use in source and binary forms, with or without
77+ * modification, are permitted provided that the following conditions
88+ * are met:
99+ * 1. Redistributions of source code must retain the above copyright
1010+ * notice, this list of conditions and the following disclaimer.
1111+ * 2. Redistributions in binary form must reproduce the above copyright
1212+ * notice, this list of conditions and the following disclaimer in the
1313+ * documentation and/or other materials provided with the distribution.
1414+ * 3. Neither the name of IBM nor the names of its contributors
1515+ * may be used to endorse or promote products derived from this software
1616+ * without specific prior written permission.
1717+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
1818+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2020+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2121+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2222+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2424+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2626+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727+ * SUCH DAMAGE. */
2828+#include "standard-headers/linux/types.h"
2929+#include "standard-headers/linux/virtio_ids.h"
3030+#include "standard-headers/linux/virtio_config.h"
3131+#include "standard-headers/linux/virtio_types.h"
3232+3333+/* Feature bits */
3434+#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
3535+#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
3636+#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
3737+#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
3838+#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
3939+#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
4040+#define VIRTIO_BLK_F_MQ 12 /* support more than one vq */
4141+4242+/* Legacy feature bits */
4343+#ifndef VIRTIO_BLK_NO_LEGACY
4444+#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
4545+#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
4646+#define VIRTIO_BLK_F_WCE 9 /* Writeback mode enabled after reset */
4747+#define VIRTIO_BLK_F_CONFIG_WCE 11 /* Writeback mode available in config */
4848+/* Old (deprecated) name for VIRTIO_BLK_F_WCE. */
4949+#define VIRTIO_BLK_F_FLUSH VIRTIO_BLK_F_WCE
5050+#endif /* !VIRTIO_BLK_NO_LEGACY */
5151+5252+#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
5353+5454+struct virtio_blk_config {
5555+ /* The capacity (in 512-byte sectors). */
5656+ uint64_t capacity;
5757+ /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
5858+ uint32_t size_max;
5959+ /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
6060+ uint32_t seg_max;
6161+ /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
6262+ struct virtio_blk_geometry {
6363+ uint16_t cylinders;
6464+ uint8_t heads;
6565+ uint8_t sectors;
6666+ } geometry;
6767+6868+ /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
6969+ uint32_t blk_size;
7070+7171+ /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */
7272+ /* exponent for physical block per logical block. */
7373+ uint8_t physical_block_exp;
7474+ /* alignment offset in logical blocks. */
7575+ uint8_t alignment_offset;
7676+ /* minimum I/O size without performance penalty in logical blocks. */
7777+ uint16_t min_io_size;
7878+ /* optimal sustained I/O size in logical blocks. */
7979+ uint32_t opt_io_size;
8080+8181+ /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */
8282+ uint8_t wce;
8383+ uint8_t unused;
8484+8585+ /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */
8686+ uint16_t num_queues;
8787+} QEMU_PACKED;
8888+8989+/*
9090+ * Command types
9191+ *
9292+ * Usage is a bit tricky as some bits are used as flags and some are not.
9393+ *
9494+ * Rules:
9595+ * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or
9696+ * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own
9797+ * and may not be combined with any of the other flags.
9898+ */
9999+100100+/* These two define direction. */
101101+#define VIRTIO_BLK_T_IN 0
102102+#define VIRTIO_BLK_T_OUT 1
103103+104104+#ifndef VIRTIO_BLK_NO_LEGACY
105105+/* This bit says it's a scsi command, not an actual read or write. */
106106+#define VIRTIO_BLK_T_SCSI_CMD 2
107107+#endif /* VIRTIO_BLK_NO_LEGACY */
108108+109109+/* Cache flush command */
110110+#define VIRTIO_BLK_T_FLUSH 4
111111+112112+/* Get device ID command */
113113+#define VIRTIO_BLK_T_GET_ID 8
114114+115115+#ifndef VIRTIO_BLK_NO_LEGACY
116116+/* Barrier before this op. */
117117+#define VIRTIO_BLK_T_BARRIER 0x80000000
118118+#endif /* !VIRTIO_BLK_NO_LEGACY */
119119+120120+/* This is the first element of the read scatter-gather list. */
121121+struct virtio_blk_outhdr {
122122+ /* VIRTIO_BLK_T* */
123123+ __virtio32 type;
124124+ /* io priority. */
125125+ __virtio32 ioprio;
126126+ /* Sector (ie. 512 byte offset) */
127127+ __virtio64 sector;
128128+};
129129+130130+#ifndef VIRTIO_BLK_NO_LEGACY
131131+struct virtio_scsi_inhdr {
132132+ __virtio32 errors;
133133+ __virtio32 data_len;
134134+ __virtio32 sense_len;
135135+ __virtio32 residual;
136136+};
137137+#endif /* !VIRTIO_BLK_NO_LEGACY */
138138+139139+/* And this is the final byte of the write scatter-gather list. */
140140+#define VIRTIO_BLK_S_OK 0
141141+#define VIRTIO_BLK_S_IOERR 1
142142+#define VIRTIO_BLK_S_UNSUPP 2
143143+#endif /* _LINUX_VIRTIO_BLK_H */
+64
include/standard-headers/linux/virtio_config.h
···11+#ifndef _LINUX_VIRTIO_CONFIG_H
22+#define _LINUX_VIRTIO_CONFIG_H
33+/* This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
44+ * anyone can use the definitions to implement compatible drivers/servers.
55+ *
66+ * Redistribution and use in source and binary forms, with or without
77+ * modification, are permitted provided that the following conditions
88+ * are met:
99+ * 1. Redistributions of source code must retain the above copyright
1010+ * notice, this list of conditions and the following disclaimer.
1111+ * 2. Redistributions in binary form must reproduce the above copyright
1212+ * notice, this list of conditions and the following disclaimer in the
1313+ * documentation and/or other materials provided with the distribution.
1414+ * 3. Neither the name of IBM nor the names of its contributors
1515+ * may be used to endorse or promote products derived from this software
1616+ * without specific prior written permission.
1717+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
1818+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2020+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2121+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2222+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2424+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2626+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727+ * SUCH DAMAGE. */
2828+2929+/* Virtio devices use a standardized configuration space to define their
3030+ * features and pass configuration information, but each implementation can
3131+ * store and access that space differently. */
3232+#include "standard-headers/linux/types.h"
3333+3434+/* Status byte for guest to report progress, and synchronize features. */
3535+/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
3636+#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
3737+/* We have found a driver for the device. */
3838+#define VIRTIO_CONFIG_S_DRIVER 2
3939+/* Driver has used its parts of the config, and is happy */
4040+#define VIRTIO_CONFIG_S_DRIVER_OK 4
4141+/* Driver has finished configuring features */
4242+#define VIRTIO_CONFIG_S_FEATURES_OK 8
4343+/* We've given up on this device. */
4444+#define VIRTIO_CONFIG_S_FAILED 0x80
4545+4646+/* Some virtio feature bits (currently bits 28 through 32) are reserved for the
4747+ * transport being used (eg. virtio_ring), the rest are per-device feature
4848+ * bits. */
4949+#define VIRTIO_TRANSPORT_F_START 28
5050+#define VIRTIO_TRANSPORT_F_END 33
5151+5252+#ifndef VIRTIO_CONFIG_NO_LEGACY
5353+/* Do we get callbacks when the ring is completely used, even if we've
5454+ * suppressed them? */
5555+#define VIRTIO_F_NOTIFY_ON_EMPTY 24
5656+5757+/* Can the device handle any descriptor layout? */
5858+#define VIRTIO_F_ANY_LAYOUT 27
5959+#endif /* VIRTIO_CONFIG_NO_LEGACY */
6060+6161+/* v1.0 compliant. */
6262+#define VIRTIO_F_VERSION_1 32
6363+6464+#endif /* _LINUX_VIRTIO_CONFIG_H */
+78
include/standard-headers/linux/virtio_console.h
···11+/*
22+ * This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
33+ * anyone can use the definitions to implement compatible drivers/servers:
44+ *
55+ *
66+ * Redistribution and use in source and binary forms, with or without
77+ * modification, are permitted provided that the following conditions
88+ * are met:
99+ * 1. Redistributions of source code must retain the above copyright
1010+ * notice, this list of conditions and the following disclaimer.
1111+ * 2. Redistributions in binary form must reproduce the above copyright
1212+ * notice, this list of conditions and the following disclaimer in the
1313+ * documentation and/or other materials provided with the distribution.
1414+ * 3. Neither the name of IBM nor the names of its contributors
1515+ * may be used to endorse or promote products derived from this software
1616+ * without specific prior written permission.
1717+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
1818+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2020+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2121+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2222+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2424+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2626+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727+ * SUCH DAMAGE.
2828+ *
2929+ * Copyright (C) Red Hat, Inc., 2009, 2010, 2011
3030+ * Copyright (C) Amit Shah <amit.shah@redhat.com>, 2009, 2010, 2011
3131+ */
3232+#ifndef _LINUX_VIRTIO_CONSOLE_H
3333+#define _LINUX_VIRTIO_CONSOLE_H
3434+#include "standard-headers/linux/types.h"
3535+#include "standard-headers/linux/virtio_types.h"
3636+#include "standard-headers/linux/virtio_ids.h"
3737+#include "standard-headers/linux/virtio_config.h"
3838+3939+/* Feature bits */
4040+#define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */
4141+#define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */
4242+#define VIRTIO_CONSOLE_F_EMERG_WRITE 2 /* Does host support emergency write? */
4343+4444+#define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0)
4545+4646+struct virtio_console_config {
4747+ /* colums of the screens */
4848+ uint16_t cols;
4949+ /* rows of the screens */
5050+ uint16_t rows;
5151+ /* max. number of ports this device can hold */
5252+ uint32_t max_nr_ports;
5353+ /* emergency write register */
5454+ uint32_t emerg_wr;
5555+} QEMU_PACKED;
5656+5757+/*
5858+ * A message that's passed between the Host and the Guest for a
5959+ * particular port.
6060+ */
6161+struct virtio_console_control {
6262+ __virtio32 id; /* Port number */
6363+ __virtio16 event; /* The kind of control event (see below) */
6464+ __virtio16 value; /* Extra information for the key */
6565+};
6666+6767+/* Some events for control messages */
6868+#define VIRTIO_CONSOLE_DEVICE_READY 0
6969+#define VIRTIO_CONSOLE_PORT_ADD 1
7070+#define VIRTIO_CONSOLE_PORT_REMOVE 2
7171+#define VIRTIO_CONSOLE_PORT_READY 3
7272+#define VIRTIO_CONSOLE_CONSOLE_PORT 4
7373+#define VIRTIO_CONSOLE_RESIZE 5
7474+#define VIRTIO_CONSOLE_PORT_OPEN 6
7575+#define VIRTIO_CONSOLE_PORT_NAME 7
7676+7777+7878+#endif /* _LINUX_VIRTIO_CONSOLE_H */
+43
include/standard-headers/linux/virtio_ids.h
···11+#ifndef _LINUX_VIRTIO_IDS_H
22+#define _LINUX_VIRTIO_IDS_H
33+/*
44+ * Virtio IDs
55+ *
66+ * This header is BSD licensed so anyone can use the definitions to implement
77+ * compatible drivers/servers.
88+ *
99+ * Redistribution and use in source and binary forms, with or without
1010+ * modification, are permitted provided that the following conditions
1111+ * are met:
1212+ * 1. Redistributions of source code must retain the above copyright
1313+ * notice, this list of conditions and the following disclaimer.
1414+ * 2. Redistributions in binary form must reproduce the above copyright
1515+ * notice, this list of conditions and the following disclaimer in the
1616+ * documentation and/or other materials provided with the distribution.
1717+ * 3. Neither the name of IBM nor the names of its contributors
1818+ * may be used to endorse or promote products derived from this software
1919+ * without specific prior written permission.
2020+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
2121+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2222+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2323+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2424+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2525+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2626+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2727+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2828+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2929+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3030+ * SUCH DAMAGE. */
3131+3232+#define VIRTIO_ID_NET 1 /* virtio net */
3333+#define VIRTIO_ID_BLOCK 2 /* virtio block */
3434+#define VIRTIO_ID_CONSOLE 3 /* virtio console */
3535+#define VIRTIO_ID_RNG 4 /* virtio rng */
3636+#define VIRTIO_ID_BALLOON 5 /* virtio balloon */
3737+#define VIRTIO_ID_RPMSG 7 /* virtio remote processor messaging */
3838+#define VIRTIO_ID_SCSI 8 /* virtio scsi */
3939+#define VIRTIO_ID_9P 9 /* 9p virtio console */
4040+#define VIRTIO_ID_RPROC_SERIAL 11 /* virtio remoteproc serial link */
4141+#define VIRTIO_ID_CAIF 12 /* Virtio caif */
4242+4343+#endif /* _LINUX_VIRTIO_IDS_H */
+233
include/standard-headers/linux/virtio_net.h
···11+#ifndef _LINUX_VIRTIO_NET_H
22+#define _LINUX_VIRTIO_NET_H
33+/* This header is BSD licensed so anyone can use the definitions to implement
44+ * compatible drivers/servers.
55+ *
66+ * Redistribution and use in source and binary forms, with or without
77+ * modification, are permitted provided that the following conditions
88+ * are met:
99+ * 1. Redistributions of source code must retain the above copyright
1010+ * notice, this list of conditions and the following disclaimer.
1111+ * 2. Redistributions in binary form must reproduce the above copyright
1212+ * notice, this list of conditions and the following disclaimer in the
1313+ * documentation and/or other materials provided with the distribution.
1414+ * 3. Neither the name of IBM nor the names of its contributors
1515+ * may be used to endorse or promote products derived from this software
1616+ * without specific prior written permission.
1717+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
1818+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2020+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2121+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2222+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2424+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2626+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727+ * SUCH DAMAGE. */
2828+#include "standard-headers/linux/types.h"
2929+#include "standard-headers/linux/virtio_ids.h"
3030+#include "standard-headers/linux/virtio_config.h"
3131+#include "standard-headers/linux/virtio_types.h"
3232+#include "standard-headers/linux/if_ether.h"
3333+3434+/* The feature bitmap for virtio net */
3535+#define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */
3636+#define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */
3737+#define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */
3838+#define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */
3939+#define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */
4040+#define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */
4141+#define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */
4242+#define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */
4343+#define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */
4444+#define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */
4545+#define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */
4646+#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */
4747+#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
4848+#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
4949+#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */
5050+#define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */
5151+#define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */
5252+#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce device on the
5353+ * network */
5454+#define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow
5555+ * Steering */
5656+#define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */
5757+5858+#ifndef VIRTIO_NET_NO_LEGACY
5959+#define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */
6060+#endif /* VIRTIO_NET_NO_LEGACY */
6161+6262+#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
6363+#define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */
6464+6565+struct virtio_net_config {
6666+ /* The config defining mac address (if VIRTIO_NET_F_MAC) */
6767+ uint8_t mac[ETH_ALEN];
6868+ /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
6969+ uint16_t status;
7070+ /* Maximum number of each of transmit and receive queues;
7171+ * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ.
7272+ * Legal values are between 1 and 0x8000
7373+ */
7474+ uint16_t max_virtqueue_pairs;
7575+} QEMU_PACKED;
7676+7777+#ifndef VIRTIO_NET_NO_LEGACY
7878+/* This header comes first in the scatter-gather list.
7979+ * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must
8080+ * be the first element of the scatter-gather list. If you don't
8181+ * specify GSO or CSUM features, you can simply ignore the header. */
8282+struct virtio_net_hdr {
8383+#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset
8484+#define VIRTIO_NET_HDR_F_DATA_VALID 2 // Csum is valid
8585+ uint8_t flags;
8686+#define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame
8787+#define VIRTIO_NET_HDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO)
8888+#define VIRTIO_NET_HDR_GSO_UDP 3 // GSO frame, IPv4 UDP (UFO)
8989+#define VIRTIO_NET_HDR_GSO_TCPV6 4 // GSO frame, IPv6 TCP
9090+#define VIRTIO_NET_HDR_GSO_ECN 0x80 // TCP has ECN set
9191+ uint8_t gso_type;
9292+ __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */
9393+ __virtio16 gso_size; /* Bytes to append to hdr_len per frame */
9494+ __virtio16 csum_start; /* Position to start checksumming from */
9595+ __virtio16 csum_offset; /* Offset after that to place checksum */
9696+};
9797+9898+/* This is the version of the header to use when the MRG_RXBUF
9999+ * feature has been negotiated. */
100100+struct virtio_net_hdr_mrg_rxbuf {
101101+ struct virtio_net_hdr hdr;
102102+ __virtio16 num_buffers; /* Number of merged rx buffers */
103103+};
104104+#else /* ... VIRTIO_NET_NO_LEGACY */
105105+/*
106106+ * This header comes first in the scatter-gather list. If you don't
107107+ * specify GSO or CSUM features, you can simply ignore the header.
108108+ *
109109+ * This is bitwise-equivalent to the legacy struct virtio_net_hdr_mrg_rxbuf.
110110+ */
111111+struct virtio_net_hdr_v1 {
112112+#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start, csum_offset */
113113+#define VIRTIO_NET_HDR_F_DATA_VALID 2 /* Csum is valid */
114114+ uint8_t flags;
115115+#define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */
116116+#define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */
117117+#define VIRTIO_NET_HDR_GSO_UDP 3 /* GSO frame, IPv4 UDP (UFO) */
118118+#define VIRTIO_NET_HDR_GSO_TCPV6 4 /* GSO frame, IPv6 TCP */
119119+#define VIRTIO_NET_HDR_GSO_ECN 0x80 /* TCP has ECN set */
120120+ uint8_t gso_type;
121121+ __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */
122122+ __virtio16 gso_size; /* Bytes to append to hdr_len per frame */
123123+ __virtio16 csum_start; /* Position to start checksumming from */
124124+ __virtio16 csum_offset; /* Offset after that to place checksum */
125125+ __virtio16 num_buffers; /* Number of merged rx buffers */
126126+};
127127+#endif /* ...VIRTIO_NET_NO_LEGACY */
128128+129129+/*
130130+ * Control virtqueue data structures
131131+ *
132132+ * The control virtqueue expects a header in the first sg entry
133133+ * and an ack/status response in the last entry. Data for the
134134+ * command goes in between.
135135+ */
136136+struct virtio_net_ctrl_hdr {
137137+ uint8_t class;
138138+ uint8_t cmd;
139139+} QEMU_PACKED;
140140+141141+typedef uint8_t virtio_net_ctrl_ack;
142142+143143+#define VIRTIO_NET_OK 0
144144+#define VIRTIO_NET_ERR 1
145145+146146+/*
147147+ * Control the RX mode, ie. promisucous, allmulti, etc...
148148+ * All commands require an "out" sg entry containing a 1 byte
149149+ * state value, zero = disable, non-zero = enable. Commands
150150+ * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
151151+ * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
152152+ */
153153+#define VIRTIO_NET_CTRL_RX 0
154154+ #define VIRTIO_NET_CTRL_RX_PROMISC 0
155155+ #define VIRTIO_NET_CTRL_RX_ALLMULTI 1
156156+ #define VIRTIO_NET_CTRL_RX_ALLUNI 2
157157+ #define VIRTIO_NET_CTRL_RX_NOMULTI 3
158158+ #define VIRTIO_NET_CTRL_RX_NOUNI 4
159159+ #define VIRTIO_NET_CTRL_RX_NOBCAST 5
160160+161161+/*
162162+ * Control the MAC
163163+ *
164164+ * The MAC filter table is managed by the hypervisor, the guest should
165165+ * assume the size is infinite. Filtering should be considered
166166+ * non-perfect, ie. based on hypervisor resources, the guest may
167167+ * received packets from sources not specified in the filter list.
168168+ *
169169+ * In addition to the class/cmd header, the TABLE_SET command requires
170170+ * two out scatterlists. Each contains a 4 byte count of entries followed
171171+ * by a concatenated byte stream of the ETH_ALEN MAC addresses. The
172172+ * first sg list contains unicast addresses, the second is for multicast.
173173+ * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
174174+ * is available.
175175+ *
176176+ * The ADDR_SET command requests one out scatterlist, it contains a
177177+ * 6 bytes MAC address. This functionality is present if the
178178+ * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
179179+ */
180180+struct virtio_net_ctrl_mac {
181181+ __virtio32 entries;
182182+ uint8_t macs[][ETH_ALEN];
183183+} QEMU_PACKED;
184184+185185+#define VIRTIO_NET_CTRL_MAC 1
186186+ #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
187187+ #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1
188188+189189+/*
190190+ * Control VLAN filtering
191191+ *
192192+ * The VLAN filter table is controlled via a simple ADD/DEL interface.
193193+ * VLAN IDs not added may be filterd by the hypervisor. Del is the
194194+ * opposite of add. Both commands expect an out entry containing a 2
195195+ * byte VLAN ID. VLAN filterting is available with the
196196+ * VIRTIO_NET_F_CTRL_VLAN feature bit.
197197+ */
198198+#define VIRTIO_NET_CTRL_VLAN 2
199199+ #define VIRTIO_NET_CTRL_VLAN_ADD 0
200200+ #define VIRTIO_NET_CTRL_VLAN_DEL 1
201201+202202+/*
203203+ * Control link announce acknowledgement
204204+ *
205205+ * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that
206206+ * driver has recevied the notification; device would clear the
207207+ * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives
208208+ * this command.
209209+ */
210210+#define VIRTIO_NET_CTRL_ANNOUNCE 3
211211+ #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0
212212+213213+/*
214214+ * Control Receive Flow Steering
215215+ *
216216+ * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
217217+ * enables Receive Flow Steering, specifying the number of the transmit and
218218+ * receive queues that will be used. After the command is consumed and acked by
219219+ * the device, the device will not steer new packets on receive virtqueues
220220+ * other than specified nor read from transmit virtqueues other than specified.
221221+ * Accordingly, driver should not transmit new packets on virtqueues other than
222222+ * specified.
223223+ */
224224+struct virtio_net_ctrl_mq {
225225+ __virtio16 virtqueue_pairs;
226226+};
227227+228228+#define VIRTIO_NET_CTRL_MQ 4
229229+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0
230230+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1
231231+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000
232232+233233+#endif /* _LINUX_VIRTIO_NET_H */
+193
include/standard-headers/linux/virtio_pci.h
···11+/*
22+ * Virtio PCI driver
33+ *
44+ * This module allows virtio devices to be used over a virtual PCI device.
55+ * This can be used with QEMU based VMMs like KVM or Xen.
66+ *
77+ * Copyright IBM Corp. 2007
88+ *
99+ * Authors:
1010+ * Anthony Liguori <aliguori@us.ibm.com>
1111+ *
1212+ * This header is BSD licensed so anyone can use the definitions to implement
1313+ * compatible drivers/servers.
1414+ *
1515+ * Redistribution and use in source and binary forms, with or without
1616+ * modification, are permitted provided that the following conditions
1717+ * are met:
1818+ * 1. Redistributions of source code must retain the above copyright
1919+ * notice, this list of conditions and the following disclaimer.
2020+ * 2. Redistributions in binary form must reproduce the above copyright
2121+ * notice, this list of conditions and the following disclaimer in the
2222+ * documentation and/or other materials provided with the distribution.
2323+ * 3. Neither the name of IBM nor the names of its contributors
2424+ * may be used to endorse or promote products derived from this software
2525+ * without specific prior written permission.
2626+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
2727+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2828+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2929+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
3030+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3131+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3232+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3333+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3434+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3535+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3636+ * SUCH DAMAGE.
3737+ */
3838+3939+#ifndef _LINUX_VIRTIO_PCI_H
4040+#define _LINUX_VIRTIO_PCI_H
4141+4242+#include "standard-headers/linux/types.h"
4343+4444+#ifndef VIRTIO_PCI_NO_LEGACY
4545+4646+/* A 32-bit r/o bitmask of the features supported by the host */
4747+#define VIRTIO_PCI_HOST_FEATURES 0
4848+4949+/* A 32-bit r/w bitmask of features activated by the guest */
5050+#define VIRTIO_PCI_GUEST_FEATURES 4
5151+5252+/* A 32-bit r/w PFN for the currently selected queue */
5353+#define VIRTIO_PCI_QUEUE_PFN 8
5454+5555+/* A 16-bit r/o queue size for the currently selected queue */
5656+#define VIRTIO_PCI_QUEUE_NUM 12
5757+5858+/* A 16-bit r/w queue selector */
5959+#define VIRTIO_PCI_QUEUE_SEL 14
6060+6161+/* A 16-bit r/w queue notifier */
6262+#define VIRTIO_PCI_QUEUE_NOTIFY 16
6363+6464+/* An 8-bit device status register. */
6565+#define VIRTIO_PCI_STATUS 18
6666+6767+/* An 8-bit r/o interrupt status register. Reading the value will return the
6868+ * current contents of the ISR and will also clear it. This is effectively
6969+ * a read-and-acknowledge. */
7070+#define VIRTIO_PCI_ISR 19
7171+7272+/* MSI-X registers: only enabled if MSI-X is enabled. */
7373+/* A 16-bit vector for configuration changes. */
7474+#define VIRTIO_MSI_CONFIG_VECTOR 20
7575+/* A 16-bit vector for selected queue notifications. */
7676+#define VIRTIO_MSI_QUEUE_VECTOR 22
7777+7878+/* The remaining space is defined by each driver as the per-driver
7979+ * configuration space */
8080+#define VIRTIO_PCI_CONFIG_OFF(msix_enabled) ((msix_enabled) ? 24 : 20)
8181+/* Deprecated: please use VIRTIO_PCI_CONFIG_OFF instead */
8282+#define VIRTIO_PCI_CONFIG(dev) VIRTIO_PCI_CONFIG_OFF((dev)->msix_enabled)
8383+8484+/* Virtio ABI version, this must match exactly */
8585+#define VIRTIO_PCI_ABI_VERSION 0
8686+8787+/* How many bits to shift physical queue address written to QUEUE_PFN.
8888+ * 12 is historical, and due to x86 page size. */
8989+#define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
9090+9191+/* The alignment to use between consumer and producer parts of vring.
9292+ * x86 pagesize again. */
9393+#define VIRTIO_PCI_VRING_ALIGN 4096
9494+9595+#endif /* VIRTIO_PCI_NO_LEGACY */
9696+9797+/* The bit of the ISR which indicates a device configuration change. */
9898+#define VIRTIO_PCI_ISR_CONFIG 0x2
9999+/* Vector value used to disable MSI for queue */
100100+#define VIRTIO_MSI_NO_VECTOR 0xffff
101101+102102+#ifndef VIRTIO_PCI_NO_MODERN
103103+104104+/* IDs for different capabilities. Must all exist. */
105105+106106+/* Common configuration */
107107+#define VIRTIO_PCI_CAP_COMMON_CFG 1
108108+/* Notifications */
109109+#define VIRTIO_PCI_CAP_NOTIFY_CFG 2
110110+/* ISR access */
111111+#define VIRTIO_PCI_CAP_ISR_CFG 3
112112+/* Device specific configuration */
113113+#define VIRTIO_PCI_CAP_DEVICE_CFG 4
114114+/* PCI configuration access */
115115+#define VIRTIO_PCI_CAP_PCI_CFG 5
116116+117117+/* This is the PCI capability header: */
118118+struct virtio_pci_cap {
119119+ uint8_t cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */
120120+ uint8_t cap_next; /* Generic PCI field: next ptr. */
121121+ uint8_t cap_len; /* Generic PCI field: capability length */
122122+ uint8_t cfg_type; /* Identifies the structure. */
123123+ uint8_t bar; /* Where to find it. */
124124+ uint8_t padding[3]; /* Pad to full dword. */
125125+ uint32_t offset; /* Offset within bar. */
126126+ uint32_t length; /* Length of the structure, in bytes. */
127127+};
128128+129129+struct virtio_pci_notify_cap {
130130+ struct virtio_pci_cap cap;
131131+ uint32_t notify_off_multiplier; /* Multiplier for queue_notify_off. */
132132+};
133133+134134+/* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
135135+struct virtio_pci_common_cfg {
136136+ /* About the whole device. */
137137+ uint32_t device_feature_select; /* read-write */
138138+ uint32_t device_feature; /* read-only */
139139+ uint32_t guest_feature_select; /* read-write */
140140+ uint32_t guest_feature; /* read-write */
141141+ uint16_t msix_config; /* read-write */
142142+ uint16_t num_queues; /* read-only */
143143+ uint8_t device_status; /* read-write */
144144+ uint8_t config_generation; /* read-only */
145145+146146+ /* About a specific virtqueue. */
147147+ uint16_t queue_select; /* read-write */
148148+ uint16_t queue_size; /* read-write, power of 2. */
149149+ uint16_t queue_msix_vector; /* read-write */
150150+ uint16_t queue_enable; /* read-write */
151151+ uint16_t queue_notify_off; /* read-only */
152152+ uint32_t queue_desc_lo; /* read-write */
153153+ uint32_t queue_desc_hi; /* read-write */
154154+ uint32_t queue_avail_lo; /* read-write */
155155+ uint32_t queue_avail_hi; /* read-write */
156156+ uint32_t queue_used_lo; /* read-write */
157157+ uint32_t queue_used_hi; /* read-write */
158158+};
159159+160160+/* Macro versions of offsets for the Old Timers! */
161161+#define VIRTIO_PCI_CAP_VNDR 0
162162+#define VIRTIO_PCI_CAP_NEXT 1
163163+#define VIRTIO_PCI_CAP_LEN 2
164164+#define VIRTIO_PCI_CAP_CFG_TYPE 3
165165+#define VIRTIO_PCI_CAP_BAR 4
166166+#define VIRTIO_PCI_CAP_OFFSET 8
167167+#define VIRTIO_PCI_CAP_LENGTH 12
168168+169169+#define VIRTIO_PCI_NOTIFY_CAP_MULT 16
170170+171171+#define VIRTIO_PCI_COMMON_DFSELECT 0
172172+#define VIRTIO_PCI_COMMON_DF 4
173173+#define VIRTIO_PCI_COMMON_GFSELECT 8
174174+#define VIRTIO_PCI_COMMON_GF 12
175175+#define VIRTIO_PCI_COMMON_MSIX 16
176176+#define VIRTIO_PCI_COMMON_NUMQ 18
177177+#define VIRTIO_PCI_COMMON_STATUS 20
178178+#define VIRTIO_PCI_COMMON_CFGGENERATION 21
179179+#define VIRTIO_PCI_COMMON_Q_SELECT 22
180180+#define VIRTIO_PCI_COMMON_Q_SIZE 24
181181+#define VIRTIO_PCI_COMMON_Q_MSIX 26
182182+#define VIRTIO_PCI_COMMON_Q_ENABLE 28
183183+#define VIRTIO_PCI_COMMON_Q_NOFF 30
184184+#define VIRTIO_PCI_COMMON_Q_DESCLO 32
185185+#define VIRTIO_PCI_COMMON_Q_DESCHI 36
186186+#define VIRTIO_PCI_COMMON_Q_AVAILLO 40
187187+#define VIRTIO_PCI_COMMON_Q_AVAILHI 44
188188+#define VIRTIO_PCI_COMMON_Q_USEDLO 48
189189+#define VIRTIO_PCI_COMMON_Q_USEDHI 52
190190+191191+#endif /* VIRTIO_PCI_NO_MODERN */
192192+193193+#endif
+171
include/standard-headers/linux/virtio_ring.h
···11+#ifndef _LINUX_VIRTIO_RING_H
22+#define _LINUX_VIRTIO_RING_H
33+/* An interface for efficient virtio implementation, currently for use by KVM
44+ * and lguest, but hopefully others soon. Do NOT change this since it will
55+ * break existing servers and clients.
66+ *
77+ * This header is BSD licensed so anyone can use the definitions to implement
88+ * compatible drivers/servers.
99+ *
1010+ * Redistribution and use in source and binary forms, with or without
1111+ * modification, are permitted provided that the following conditions
1212+ * are met:
1313+ * 1. Redistributions of source code must retain the above copyright
1414+ * notice, this list of conditions and the following disclaimer.
1515+ * 2. Redistributions in binary form must reproduce the above copyright
1616+ * notice, this list of conditions and the following disclaimer in the
1717+ * documentation and/or other materials provided with the distribution.
1818+ * 3. Neither the name of IBM nor the names of its contributors
1919+ * may be used to endorse or promote products derived from this software
2020+ * without specific prior written permission.
2121+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
2222+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2323+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2424+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2525+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2626+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2727+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2828+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2929+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3030+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3131+ * SUCH DAMAGE.
3232+ *
3333+ * Copyright Rusty Russell IBM Corporation 2007. */
3434+#include "standard-headers/linux/types.h"
3535+#include "standard-headers/linux/virtio_types.h"
3636+3737+/* This marks a buffer as continuing via the next field. */
3838+#define VRING_DESC_F_NEXT 1
3939+/* This marks a buffer as write-only (otherwise read-only). */
4040+#define VRING_DESC_F_WRITE 2
4141+/* This means the buffer contains a list of buffer descriptors. */
4242+#define VRING_DESC_F_INDIRECT 4
4343+4444+/* The Host uses this in used->flags to advise the Guest: don't kick me when
4545+ * you add a buffer. It's unreliable, so it's simply an optimization. Guest
4646+ * will still kick if it's out of buffers. */
4747+#define VRING_USED_F_NO_NOTIFY 1
4848+/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
4949+ * when you consume a buffer. It's unreliable, so it's simply an
5050+ * optimization. */
5151+#define VRING_AVAIL_F_NO_INTERRUPT 1
5252+5353+/* We support indirect buffer descriptors */
5454+#define VIRTIO_RING_F_INDIRECT_DESC 28
5555+5656+/* The Guest publishes the used index for which it expects an interrupt
5757+ * at the end of the avail ring. Host should ignore the avail->flags field. */
5858+/* The Host publishes the avail index for which it expects a kick
5959+ * at the end of the used ring. Guest should ignore the used->flags field. */
6060+#define VIRTIO_RING_F_EVENT_IDX 29
6161+6262+/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
6363+struct vring_desc {
6464+ /* Address (guest-physical). */
6565+ __virtio64 addr;
6666+ /* Length. */
6767+ __virtio32 len;
6868+ /* The flags as indicated above. */
6969+ __virtio16 flags;
7070+ /* We chain unused descriptors via this, too */
7171+ __virtio16 next;
7272+};
7373+7474+struct vring_avail {
7575+ __virtio16 flags;
7676+ __virtio16 idx;
7777+ __virtio16 ring[];
7878+};
7979+8080+/* u32 is used here for ids for padding reasons. */
8181+struct vring_used_elem {
8282+ /* Index of start of used descriptor chain. */
8383+ __virtio32 id;
8484+ /* Total length of the descriptor chain which was used (written to) */
8585+ __virtio32 len;
8686+};
8787+8888+struct vring_used {
8989+ __virtio16 flags;
9090+ __virtio16 idx;
9191+ struct vring_used_elem ring[];
9292+};
9393+9494+struct vring {
9595+ unsigned int num;
9696+9797+ struct vring_desc *desc;
9898+9999+ struct vring_avail *avail;
100100+101101+ struct vring_used *used;
102102+};
103103+104104+/* Alignment requirements for vring elements.
105105+ * When using pre-virtio 1.0 layout, these fall out naturally.
106106+ */
107107+#define VRING_AVAIL_ALIGN_SIZE 2
108108+#define VRING_USED_ALIGN_SIZE 4
109109+#define VRING_DESC_ALIGN_SIZE 16
110110+111111+/* The standard layout for the ring is a continuous chunk of memory which looks
112112+ * like this. We assume num is a power of 2.
113113+ *
114114+ * struct vring
115115+ * {
116116+ * // The actual descriptors (16 bytes each)
117117+ * struct vring_desc desc[num];
118118+ *
119119+ * // A ring of available descriptor heads with free-running index.
120120+ * __virtio16 avail_flags;
121121+ * __virtio16 avail_idx;
122122+ * __virtio16 available[num];
123123+ * __virtio16 used_event_idx;
124124+ *
125125+ * // Padding to the next align boundary.
126126+ * char pad[];
127127+ *
128128+ * // A ring of used descriptor heads with free-running index.
129129+ * __virtio16 used_flags;
130130+ * __virtio16 used_idx;
131131+ * struct vring_used_elem used[num];
132132+ * __virtio16 avail_event_idx;
133133+ * };
134134+ */
135135+/* We publish the used event index at the end of the available ring, and vice
136136+ * versa. They are at the end for backwards compatibility. */
137137+#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
138138+#define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num])
139139+140140+static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
141141+ unsigned long align)
142142+{
143143+ vr->num = num;
144144+ vr->desc = p;
145145+ vr->avail = p + num*sizeof(struct vring_desc);
146146+ vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__virtio16)
147147+ + align-1) & ~(align - 1));
148148+}
149149+150150+static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
151151+{
152152+ return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num)
153153+ + align - 1) & ~(align - 1))
154154+ + sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num;
155155+}
156156+157157+/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
158158+/* Assuming a given event_idx value from the other size, if
159159+ * we have just incremented index from old to new_idx,
160160+ * should we trigger an event? */
161161+static __inline__ int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
162162+{
163163+ /* Note: Xen has similar logic for notification hold-off
164164+ * in include/xen/interface/io/ring.h with req_event and req_prod
165165+ * corresponding to event_idx + 1 and new_idx respectively.
166166+ * Note also that req_event and req_prod in Xen start at 1,
167167+ * event indexes in virtio start at 0. */
168168+ return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
169169+}
170170+171171+#endif /* _LINUX_VIRTIO_RING_H */
+8
include/standard-headers/linux/virtio_rng.h
···11+#ifndef _LINUX_VIRTIO_RNG_H
22+#define _LINUX_VIRTIO_RNG_H
33+/* This header is BSD licensed so anyone can use the definitions to implement
44+ * compatible drivers/servers. */
55+#include "standard-headers/linux/virtio_ids.h"
66+#include "standard-headers/linux/virtio_config.h"
77+88+#endif /* _LINUX_VIRTIO_RNG_H */
+164
include/standard-headers/linux/virtio_scsi.h
···11+/*
22+ * This header is BSD licensed so anyone can use the definitions to implement
33+ * compatible drivers/servers.
44+ *
55+ * Redistribution and use in source and binary forms, with or without
66+ * modification, are permitted provided that the following conditions
77+ * are met:
88+ * 1. Redistributions of source code must retain the above copyright
99+ * notice, this list of conditions and the following disclaimer.
1010+ * 2. Redistributions in binary form must reproduce the above copyright
1111+ * notice, this list of conditions and the following disclaimer in the
1212+ * documentation and/or other materials provided with the distribution.
1313+ *
1414+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1515+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1616+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1717+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
1818+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1919+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2020+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2121+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2222+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2323+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2424+ * SUCH DAMAGE.
2525+ */
2626+2727+#ifndef _LINUX_VIRTIO_SCSI_H
2828+#define _LINUX_VIRTIO_SCSI_H
2929+3030+#include "standard-headers/linux/virtio_types.h"
3131+3232+#define VIRTIO_SCSI_CDB_SIZE 32
3333+#define VIRTIO_SCSI_SENSE_SIZE 96
3434+3535+/* SCSI command request, followed by data-out */
3636+struct virtio_scsi_cmd_req {
3737+ uint8_t lun[8]; /* Logical Unit Number */
3838+ __virtio64 tag; /* Command identifier */
3939+ uint8_t task_attr; /* Task attribute */
4040+ uint8_t prio; /* SAM command priority field */
4141+ uint8_t crn;
4242+ uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
4343+} QEMU_PACKED;
4444+4545+/* SCSI command request, followed by protection information */
4646+struct virtio_scsi_cmd_req_pi {
4747+ uint8_t lun[8]; /* Logical Unit Number */
4848+ __virtio64 tag; /* Command identifier */
4949+ uint8_t task_attr; /* Task attribute */
5050+ uint8_t prio; /* SAM command priority field */
5151+ uint8_t crn;
5252+ __virtio32 pi_bytesout; /* DataOUT PI Number of bytes */
5353+ __virtio32 pi_bytesin; /* DataIN PI Number of bytes */
5454+ uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
5555+} QEMU_PACKED;
5656+5757+/* Response, followed by sense data and data-in */
5858+struct virtio_scsi_cmd_resp {
5959+ __virtio32 sense_len; /* Sense data length */
6060+ __virtio32 resid; /* Residual bytes in data buffer */
6161+ __virtio16 status_qualifier; /* Status qualifier */
6262+ uint8_t status; /* Command completion status */
6363+ uint8_t response; /* Response values */
6464+ uint8_t sense[VIRTIO_SCSI_SENSE_SIZE];
6565+} QEMU_PACKED;
6666+6767+/* Task Management Request */
6868+struct virtio_scsi_ctrl_tmf_req {
6969+ __virtio32 type;
7070+ __virtio32 subtype;
7171+ uint8_t lun[8];
7272+ __virtio64 tag;
7373+} QEMU_PACKED;
7474+7575+struct virtio_scsi_ctrl_tmf_resp {
7676+ uint8_t response;
7777+} QEMU_PACKED;
7878+7979+/* Asynchronous notification query/subscription */
8080+struct virtio_scsi_ctrl_an_req {
8181+ __virtio32 type;
8282+ uint8_t lun[8];
8383+ __virtio32 event_requested;
8484+} QEMU_PACKED;
8585+8686+struct virtio_scsi_ctrl_an_resp {
8787+ __virtio32 event_actual;
8888+ uint8_t response;
8989+} QEMU_PACKED;
9090+9191+struct virtio_scsi_event {
9292+ __virtio32 event;
9393+ uint8_t lun[8];
9494+ __virtio32 reason;
9595+} QEMU_PACKED;
9696+9797+struct virtio_scsi_config {
9898+ uint32_t num_queues;
9999+ uint32_t seg_max;
100100+ uint32_t max_sectors;
101101+ uint32_t cmd_per_lun;
102102+ uint32_t event_info_size;
103103+ uint32_t sense_size;
104104+ uint32_t cdb_size;
105105+ uint16_t max_channel;
106106+ uint16_t max_target;
107107+ uint32_t max_lun;
108108+} QEMU_PACKED;
109109+110110+/* Feature Bits */
111111+#define VIRTIO_SCSI_F_INOUT 0
112112+#define VIRTIO_SCSI_F_HOTPLUG 1
113113+#define VIRTIO_SCSI_F_CHANGE 2
114114+#define VIRTIO_SCSI_F_T10_PI 3
115115+116116+/* Response codes */
117117+#define VIRTIO_SCSI_S_OK 0
118118+#define VIRTIO_SCSI_S_OVERRUN 1
119119+#define VIRTIO_SCSI_S_ABORTED 2
120120+#define VIRTIO_SCSI_S_BAD_TARGET 3
121121+#define VIRTIO_SCSI_S_RESET 4
122122+#define VIRTIO_SCSI_S_BUSY 5
123123+#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
124124+#define VIRTIO_SCSI_S_TARGET_FAILURE 7
125125+#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
126126+#define VIRTIO_SCSI_S_FAILURE 9
127127+#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
128128+#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
129129+#define VIRTIO_SCSI_S_INCORRECT_LUN 12
130130+131131+/* Controlq type codes. */
132132+#define VIRTIO_SCSI_T_TMF 0
133133+#define VIRTIO_SCSI_T_AN_QUERY 1
134134+#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
135135+136136+/* Valid TMF subtypes. */
137137+#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
138138+#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
139139+#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
140140+#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
141141+#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
142142+#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
143143+#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
144144+#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
145145+146146+/* Events. */
147147+#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
148148+#define VIRTIO_SCSI_T_NO_EVENT 0
149149+#define VIRTIO_SCSI_T_TRANSPORT_RESET 1
150150+#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
151151+#define VIRTIO_SCSI_T_PARAM_CHANGE 3
152152+153153+/* Reasons of transport reset event */
154154+#define VIRTIO_SCSI_EVT_RESET_HARD 0
155155+#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
156156+#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
157157+158158+#define VIRTIO_SCSI_S_SIMPLE 0
159159+#define VIRTIO_SCSI_S_ORDERED 1
160160+#define VIRTIO_SCSI_S_HEAD 2
161161+#define VIRTIO_SCSI_S_ACA 3
162162+163163+164164+#endif /* _LINUX_VIRTIO_SCSI_H */
+46
include/standard-headers/linux/virtio_types.h
···11+#ifndef _LINUX_VIRTIO_TYPES_H
22+#define _LINUX_VIRTIO_TYPES_H
33+/* Type definitions for virtio implementations.
44+ *
55+ * This header is BSD licensed so anyone can use the definitions to implement
66+ * compatible drivers/servers.
77+ *
88+ * Redistribution and use in source and binary forms, with or without
99+ * modification, are permitted provided that the following conditions
1010+ * are met:
1111+ * 1. Redistributions of source code must retain the above copyright
1212+ * notice, this list of conditions and the following disclaimer.
1313+ * 2. Redistributions in binary form must reproduce the above copyright
1414+ * notice, this list of conditions and the following disclaimer in the
1515+ * documentation and/or other materials provided with the distribution.
1616+ * 3. Neither the name of IBM nor the names of its contributors
1717+ * may be used to endorse or promote products derived from this software
1818+ * without specific prior written permission.
1919+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
2020+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2121+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2222+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2323+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2424+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2525+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2626+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2727+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2828+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2929+ * SUCH DAMAGE.
3030+ *
3131+ * Copyright (C) 2014 Red Hat, Inc.
3232+ * Author: Michael S. Tsirkin <mst@redhat.com>
3333+ */
3434+#include "standard-headers/linux/types.h"
3535+3636+/*
3737+ * __virtio{16,32,64} have the following meaning:
3838+ * - __u{16,32,64} for virtio devices in legacy mode, accessed in native endian
3939+ * - __le{16,32,64} for standard-compliant virtio devices
4040+ */
4141+4242+typedef uint16_t __virtio16;
4343+typedef uint32_t __virtio32;
4444+typedef uint64_t __virtio64;
4545+4646+#endif /* _LINUX_VIRTIO_TYPES_H */