qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

include: import virtio headers from linux 4.0

Add files imported from linux-next (what will become linux 4.0) using
scripts/update-linux-headers.sh

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>


+1249
+1
include/standard-headers/linux/if_ether.h
··· 1 + #define ETH_ALEN 6
+2
include/standard-headers/linux/types.h
··· 1 + #include <inttypes.h> 2 + #include "qemu/compiler.h"
+44
include/standard-headers/linux/virtio_9p.h
··· 1 + #ifndef _LINUX_VIRTIO_9P_H 2 + #define _LINUX_VIRTIO_9P_H 3 + /* This header is BSD licensed so anyone can use the definitions to implement 4 + * compatible drivers/servers. 5 + * 6 + * Redistribution and use in source and binary forms, with or without 7 + * modification, are permitted provided that the following conditions 8 + * are met: 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of IBM nor the names of its contributors 15 + * may be used to endorse or promote products derived from this software 16 + * without specific prior written permission. 17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 + * SUCH DAMAGE. */ 28 + #include "standard-headers/linux/types.h" 29 + #include "standard-headers/linux/virtio_ids.h" 30 + #include "standard-headers/linux/virtio_config.h" 31 + 32 + /* The feature bitmap for virtio 9P */ 33 + 34 + /* The mount point is specified in a config variable */ 35 + #define VIRTIO_9P_MOUNT_TAG 0 36 + 37 + struct virtio_9p_config { 38 + /* length of the tag name */ 39 + uint16_t tag_len; 40 + /* non-NULL terminated tag name */ 41 + uint8_t tag[0]; 42 + } QEMU_PACKED; 43 + 44 + #endif /* _LINUX_VIRTIO_9P_H */
+59
include/standard-headers/linux/virtio_balloon.h
··· 1 + #ifndef _LINUX_VIRTIO_BALLOON_H 2 + #define _LINUX_VIRTIO_BALLOON_H 3 + /* This header is BSD licensed so anyone can use the definitions to implement 4 + * compatible drivers/servers. 5 + * 6 + * Redistribution and use in source and binary forms, with or without 7 + * modification, are permitted provided that the following conditions 8 + * are met: 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of IBM nor the names of its contributors 15 + * may be used to endorse or promote products derived from this software 16 + * without specific prior written permission. 17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 + * SUCH DAMAGE. */ 28 + #include "standard-headers/linux/virtio_ids.h" 29 + #include "standard-headers/linux/virtio_config.h" 30 + 31 + /* The feature bitmap for virtio balloon */ 32 + #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */ 33 + #define VIRTIO_BALLOON_F_STATS_VQ 1 /* Memory Stats virtqueue */ 34 + #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon on OOM */ 35 + 36 + /* Size of a PFN in the balloon interface. */ 37 + #define VIRTIO_BALLOON_PFN_SHIFT 12 38 + 39 + struct virtio_balloon_config { 40 + /* Number of pages host wants Guest to give up. */ 41 + uint32_t num_pages; 42 + /* Number of pages we've actually got in balloon. */ 43 + uint32_t actual; 44 + }; 45 + 46 + #define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */ 47 + #define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */ 48 + #define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */ 49 + #define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */ 50 + #define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */ 51 + #define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */ 52 + #define VIRTIO_BALLOON_S_NR 6 53 + 54 + struct virtio_balloon_stat { 55 + uint16_t tag; 56 + uint64_t val; 57 + } QEMU_PACKED; 58 + 59 + #endif /* _LINUX_VIRTIO_BALLOON_H */
+143
include/standard-headers/linux/virtio_blk.h
··· 1 + #ifndef _LINUX_VIRTIO_BLK_H 2 + #define _LINUX_VIRTIO_BLK_H 3 + /* This header is BSD licensed so anyone can use the definitions to implement 4 + * compatible drivers/servers. 5 + * 6 + * Redistribution and use in source and binary forms, with or without 7 + * modification, are permitted provided that the following conditions 8 + * are met: 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of IBM nor the names of its contributors 15 + * may be used to endorse or promote products derived from this software 16 + * without specific prior written permission. 17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 + * SUCH DAMAGE. */ 28 + #include "standard-headers/linux/types.h" 29 + #include "standard-headers/linux/virtio_ids.h" 30 + #include "standard-headers/linux/virtio_config.h" 31 + #include "standard-headers/linux/virtio_types.h" 32 + 33 + /* Feature bits */ 34 + #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ 35 + #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ 36 + #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ 37 + #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ 38 + #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ 39 + #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */ 40 + #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */ 41 + 42 + /* Legacy feature bits */ 43 + #ifndef VIRTIO_BLK_NO_LEGACY 44 + #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */ 45 + #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ 46 + #define VIRTIO_BLK_F_WCE 9 /* Writeback mode enabled after reset */ 47 + #define VIRTIO_BLK_F_CONFIG_WCE 11 /* Writeback mode available in config */ 48 + /* Old (deprecated) name for VIRTIO_BLK_F_WCE. */ 49 + #define VIRTIO_BLK_F_FLUSH VIRTIO_BLK_F_WCE 50 + #endif /* !VIRTIO_BLK_NO_LEGACY */ 51 + 52 + #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ 53 + 54 + struct virtio_blk_config { 55 + /* The capacity (in 512-byte sectors). */ 56 + uint64_t capacity; 57 + /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ 58 + uint32_t size_max; 59 + /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ 60 + uint32_t seg_max; 61 + /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ 62 + struct virtio_blk_geometry { 63 + uint16_t cylinders; 64 + uint8_t heads; 65 + uint8_t sectors; 66 + } geometry; 67 + 68 + /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ 69 + uint32_t blk_size; 70 + 71 + /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */ 72 + /* exponent for physical block per logical block. */ 73 + uint8_t physical_block_exp; 74 + /* alignment offset in logical blocks. */ 75 + uint8_t alignment_offset; 76 + /* minimum I/O size without performance penalty in logical blocks. */ 77 + uint16_t min_io_size; 78 + /* optimal sustained I/O size in logical blocks. */ 79 + uint32_t opt_io_size; 80 + 81 + /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */ 82 + uint8_t wce; 83 + uint8_t unused; 84 + 85 + /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */ 86 + uint16_t num_queues; 87 + } QEMU_PACKED; 88 + 89 + /* 90 + * Command types 91 + * 92 + * Usage is a bit tricky as some bits are used as flags and some are not. 93 + * 94 + * Rules: 95 + * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or 96 + * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own 97 + * and may not be combined with any of the other flags. 98 + */ 99 + 100 + /* These two define direction. */ 101 + #define VIRTIO_BLK_T_IN 0 102 + #define VIRTIO_BLK_T_OUT 1 103 + 104 + #ifndef VIRTIO_BLK_NO_LEGACY 105 + /* This bit says it's a scsi command, not an actual read or write. */ 106 + #define VIRTIO_BLK_T_SCSI_CMD 2 107 + #endif /* VIRTIO_BLK_NO_LEGACY */ 108 + 109 + /* Cache flush command */ 110 + #define VIRTIO_BLK_T_FLUSH 4 111 + 112 + /* Get device ID command */ 113 + #define VIRTIO_BLK_T_GET_ID 8 114 + 115 + #ifndef VIRTIO_BLK_NO_LEGACY 116 + /* Barrier before this op. */ 117 + #define VIRTIO_BLK_T_BARRIER 0x80000000 118 + #endif /* !VIRTIO_BLK_NO_LEGACY */ 119 + 120 + /* This is the first element of the read scatter-gather list. */ 121 + struct virtio_blk_outhdr { 122 + /* VIRTIO_BLK_T* */ 123 + __virtio32 type; 124 + /* io priority. */ 125 + __virtio32 ioprio; 126 + /* Sector (ie. 512 byte offset) */ 127 + __virtio64 sector; 128 + }; 129 + 130 + #ifndef VIRTIO_BLK_NO_LEGACY 131 + struct virtio_scsi_inhdr { 132 + __virtio32 errors; 133 + __virtio32 data_len; 134 + __virtio32 sense_len; 135 + __virtio32 residual; 136 + }; 137 + #endif /* !VIRTIO_BLK_NO_LEGACY */ 138 + 139 + /* And this is the final byte of the write scatter-gather list. */ 140 + #define VIRTIO_BLK_S_OK 0 141 + #define VIRTIO_BLK_S_IOERR 1 142 + #define VIRTIO_BLK_S_UNSUPP 2 143 + #endif /* _LINUX_VIRTIO_BLK_H */
+64
include/standard-headers/linux/virtio_config.h
··· 1 + #ifndef _LINUX_VIRTIO_CONFIG_H 2 + #define _LINUX_VIRTIO_CONFIG_H 3 + /* This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so 4 + * anyone can use the definitions to implement compatible drivers/servers. 5 + * 6 + * Redistribution and use in source and binary forms, with or without 7 + * modification, are permitted provided that the following conditions 8 + * are met: 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of IBM nor the names of its contributors 15 + * may be used to endorse or promote products derived from this software 16 + * without specific prior written permission. 17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 + * SUCH DAMAGE. */ 28 + 29 + /* Virtio devices use a standardized configuration space to define their 30 + * features and pass configuration information, but each implementation can 31 + * store and access that space differently. */ 32 + #include "standard-headers/linux/types.h" 33 + 34 + /* Status byte for guest to report progress, and synchronize features. */ 35 + /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */ 36 + #define VIRTIO_CONFIG_S_ACKNOWLEDGE 1 37 + /* We have found a driver for the device. */ 38 + #define VIRTIO_CONFIG_S_DRIVER 2 39 + /* Driver has used its parts of the config, and is happy */ 40 + #define VIRTIO_CONFIG_S_DRIVER_OK 4 41 + /* Driver has finished configuring features */ 42 + #define VIRTIO_CONFIG_S_FEATURES_OK 8 43 + /* We've given up on this device. */ 44 + #define VIRTIO_CONFIG_S_FAILED 0x80 45 + 46 + /* Some virtio feature bits (currently bits 28 through 32) are reserved for the 47 + * transport being used (eg. virtio_ring), the rest are per-device feature 48 + * bits. */ 49 + #define VIRTIO_TRANSPORT_F_START 28 50 + #define VIRTIO_TRANSPORT_F_END 33 51 + 52 + #ifndef VIRTIO_CONFIG_NO_LEGACY 53 + /* Do we get callbacks when the ring is completely used, even if we've 54 + * suppressed them? */ 55 + #define VIRTIO_F_NOTIFY_ON_EMPTY 24 56 + 57 + /* Can the device handle any descriptor layout? */ 58 + #define VIRTIO_F_ANY_LAYOUT 27 59 + #endif /* VIRTIO_CONFIG_NO_LEGACY */ 60 + 61 + /* v1.0 compliant. */ 62 + #define VIRTIO_F_VERSION_1 32 63 + 64 + #endif /* _LINUX_VIRTIO_CONFIG_H */
+78
include/standard-headers/linux/virtio_console.h
··· 1 + /* 2 + * This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so 3 + * anyone can use the definitions to implement compatible drivers/servers: 4 + * 5 + * 6 + * Redistribution and use in source and binary forms, with or without 7 + * modification, are permitted provided that the following conditions 8 + * are met: 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of IBM nor the names of its contributors 15 + * may be used to endorse or promote products derived from this software 16 + * without specific prior written permission. 17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 + * SUCH DAMAGE. 28 + * 29 + * Copyright (C) Red Hat, Inc., 2009, 2010, 2011 30 + * Copyright (C) Amit Shah <amit.shah@redhat.com>, 2009, 2010, 2011 31 + */ 32 + #ifndef _LINUX_VIRTIO_CONSOLE_H 33 + #define _LINUX_VIRTIO_CONSOLE_H 34 + #include "standard-headers/linux/types.h" 35 + #include "standard-headers/linux/virtio_types.h" 36 + #include "standard-headers/linux/virtio_ids.h" 37 + #include "standard-headers/linux/virtio_config.h" 38 + 39 + /* Feature bits */ 40 + #define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */ 41 + #define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */ 42 + #define VIRTIO_CONSOLE_F_EMERG_WRITE 2 /* Does host support emergency write? */ 43 + 44 + #define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0) 45 + 46 + struct virtio_console_config { 47 + /* colums of the screens */ 48 + uint16_t cols; 49 + /* rows of the screens */ 50 + uint16_t rows; 51 + /* max. number of ports this device can hold */ 52 + uint32_t max_nr_ports; 53 + /* emergency write register */ 54 + uint32_t emerg_wr; 55 + } QEMU_PACKED; 56 + 57 + /* 58 + * A message that's passed between the Host and the Guest for a 59 + * particular port. 60 + */ 61 + struct virtio_console_control { 62 + __virtio32 id; /* Port number */ 63 + __virtio16 event; /* The kind of control event (see below) */ 64 + __virtio16 value; /* Extra information for the key */ 65 + }; 66 + 67 + /* Some events for control messages */ 68 + #define VIRTIO_CONSOLE_DEVICE_READY 0 69 + #define VIRTIO_CONSOLE_PORT_ADD 1 70 + #define VIRTIO_CONSOLE_PORT_REMOVE 2 71 + #define VIRTIO_CONSOLE_PORT_READY 3 72 + #define VIRTIO_CONSOLE_CONSOLE_PORT 4 73 + #define VIRTIO_CONSOLE_RESIZE 5 74 + #define VIRTIO_CONSOLE_PORT_OPEN 6 75 + #define VIRTIO_CONSOLE_PORT_NAME 7 76 + 77 + 78 + #endif /* _LINUX_VIRTIO_CONSOLE_H */
+43
include/standard-headers/linux/virtio_ids.h
··· 1 + #ifndef _LINUX_VIRTIO_IDS_H 2 + #define _LINUX_VIRTIO_IDS_H 3 + /* 4 + * Virtio IDs 5 + * 6 + * This header is BSD licensed so anyone can use the definitions to implement 7 + * compatible drivers/servers. 8 + * 9 + * Redistribution and use in source and binary forms, with or without 10 + * modification, are permitted provided that the following conditions 11 + * are met: 12 + * 1. Redistributions of source code must retain the above copyright 13 + * notice, this list of conditions and the following disclaimer. 14 + * 2. Redistributions in binary form must reproduce the above copyright 15 + * notice, this list of conditions and the following disclaimer in the 16 + * documentation and/or other materials provided with the distribution. 17 + * 3. Neither the name of IBM nor the names of its contributors 18 + * may be used to endorse or promote products derived from this software 19 + * without specific prior written permission. 20 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 21 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 24 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 + * SUCH DAMAGE. */ 31 + 32 + #define VIRTIO_ID_NET 1 /* virtio net */ 33 + #define VIRTIO_ID_BLOCK 2 /* virtio block */ 34 + #define VIRTIO_ID_CONSOLE 3 /* virtio console */ 35 + #define VIRTIO_ID_RNG 4 /* virtio rng */ 36 + #define VIRTIO_ID_BALLOON 5 /* virtio balloon */ 37 + #define VIRTIO_ID_RPMSG 7 /* virtio remote processor messaging */ 38 + #define VIRTIO_ID_SCSI 8 /* virtio scsi */ 39 + #define VIRTIO_ID_9P 9 /* 9p virtio console */ 40 + #define VIRTIO_ID_RPROC_SERIAL 11 /* virtio remoteproc serial link */ 41 + #define VIRTIO_ID_CAIF 12 /* Virtio caif */ 42 + 43 + #endif /* _LINUX_VIRTIO_IDS_H */
+233
include/standard-headers/linux/virtio_net.h
··· 1 + #ifndef _LINUX_VIRTIO_NET_H 2 + #define _LINUX_VIRTIO_NET_H 3 + /* This header is BSD licensed so anyone can use the definitions to implement 4 + * compatible drivers/servers. 5 + * 6 + * Redistribution and use in source and binary forms, with or without 7 + * modification, are permitted provided that the following conditions 8 + * are met: 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of IBM nor the names of its contributors 15 + * may be used to endorse or promote products derived from this software 16 + * without specific prior written permission. 17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 + * SUCH DAMAGE. */ 28 + #include "standard-headers/linux/types.h" 29 + #include "standard-headers/linux/virtio_ids.h" 30 + #include "standard-headers/linux/virtio_config.h" 31 + #include "standard-headers/linux/virtio_types.h" 32 + #include "standard-headers/linux/if_ether.h" 33 + 34 + /* The feature bitmap for virtio net */ 35 + #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ 36 + #define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ 37 + #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ 38 + #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ 39 + #define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ 40 + #define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */ 41 + #define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */ 42 + #define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */ 43 + #define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */ 44 + #define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */ 45 + #define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */ 46 + #define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */ 47 + #define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */ 48 + #define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */ 49 + #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ 50 + #define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */ 51 + #define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */ 52 + #define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce device on the 53 + * network */ 54 + #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow 55 + * Steering */ 56 + #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ 57 + 58 + #ifndef VIRTIO_NET_NO_LEGACY 59 + #define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ 60 + #endif /* VIRTIO_NET_NO_LEGACY */ 61 + 62 + #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ 63 + #define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */ 64 + 65 + struct virtio_net_config { 66 + /* The config defining mac address (if VIRTIO_NET_F_MAC) */ 67 + uint8_t mac[ETH_ALEN]; 68 + /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ 69 + uint16_t status; 70 + /* Maximum number of each of transmit and receive queues; 71 + * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ. 72 + * Legal values are between 1 and 0x8000 73 + */ 74 + uint16_t max_virtqueue_pairs; 75 + } QEMU_PACKED; 76 + 77 + #ifndef VIRTIO_NET_NO_LEGACY 78 + /* This header comes first in the scatter-gather list. 79 + * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must 80 + * be the first element of the scatter-gather list. If you don't 81 + * specify GSO or CSUM features, you can simply ignore the header. */ 82 + struct virtio_net_hdr { 83 + #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset 84 + #define VIRTIO_NET_HDR_F_DATA_VALID 2 // Csum is valid 85 + uint8_t flags; 86 + #define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame 87 + #define VIRTIO_NET_HDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO) 88 + #define VIRTIO_NET_HDR_GSO_UDP 3 // GSO frame, IPv4 UDP (UFO) 89 + #define VIRTIO_NET_HDR_GSO_TCPV6 4 // GSO frame, IPv6 TCP 90 + #define VIRTIO_NET_HDR_GSO_ECN 0x80 // TCP has ECN set 91 + uint8_t gso_type; 92 + __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */ 93 + __virtio16 gso_size; /* Bytes to append to hdr_len per frame */ 94 + __virtio16 csum_start; /* Position to start checksumming from */ 95 + __virtio16 csum_offset; /* Offset after that to place checksum */ 96 + }; 97 + 98 + /* This is the version of the header to use when the MRG_RXBUF 99 + * feature has been negotiated. */ 100 + struct virtio_net_hdr_mrg_rxbuf { 101 + struct virtio_net_hdr hdr; 102 + __virtio16 num_buffers; /* Number of merged rx buffers */ 103 + }; 104 + #else /* ... VIRTIO_NET_NO_LEGACY */ 105 + /* 106 + * This header comes first in the scatter-gather list. If you don't 107 + * specify GSO or CSUM features, you can simply ignore the header. 108 + * 109 + * This is bitwise-equivalent to the legacy struct virtio_net_hdr_mrg_rxbuf. 110 + */ 111 + struct virtio_net_hdr_v1 { 112 + #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start, csum_offset */ 113 + #define VIRTIO_NET_HDR_F_DATA_VALID 2 /* Csum is valid */ 114 + uint8_t flags; 115 + #define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */ 116 + #define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */ 117 + #define VIRTIO_NET_HDR_GSO_UDP 3 /* GSO frame, IPv4 UDP (UFO) */ 118 + #define VIRTIO_NET_HDR_GSO_TCPV6 4 /* GSO frame, IPv6 TCP */ 119 + #define VIRTIO_NET_HDR_GSO_ECN 0x80 /* TCP has ECN set */ 120 + uint8_t gso_type; 121 + __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */ 122 + __virtio16 gso_size; /* Bytes to append to hdr_len per frame */ 123 + __virtio16 csum_start; /* Position to start checksumming from */ 124 + __virtio16 csum_offset; /* Offset after that to place checksum */ 125 + __virtio16 num_buffers; /* Number of merged rx buffers */ 126 + }; 127 + #endif /* ...VIRTIO_NET_NO_LEGACY */ 128 + 129 + /* 130 + * Control virtqueue data structures 131 + * 132 + * The control virtqueue expects a header in the first sg entry 133 + * and an ack/status response in the last entry. Data for the 134 + * command goes in between. 135 + */ 136 + struct virtio_net_ctrl_hdr { 137 + uint8_t class; 138 + uint8_t cmd; 139 + } QEMU_PACKED; 140 + 141 + typedef uint8_t virtio_net_ctrl_ack; 142 + 143 + #define VIRTIO_NET_OK 0 144 + #define VIRTIO_NET_ERR 1 145 + 146 + /* 147 + * Control the RX mode, ie. promisucous, allmulti, etc... 148 + * All commands require an "out" sg entry containing a 1 byte 149 + * state value, zero = disable, non-zero = enable. Commands 150 + * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature. 151 + * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA. 152 + */ 153 + #define VIRTIO_NET_CTRL_RX 0 154 + #define VIRTIO_NET_CTRL_RX_PROMISC 0 155 + #define VIRTIO_NET_CTRL_RX_ALLMULTI 1 156 + #define VIRTIO_NET_CTRL_RX_ALLUNI 2 157 + #define VIRTIO_NET_CTRL_RX_NOMULTI 3 158 + #define VIRTIO_NET_CTRL_RX_NOUNI 4 159 + #define VIRTIO_NET_CTRL_RX_NOBCAST 5 160 + 161 + /* 162 + * Control the MAC 163 + * 164 + * The MAC filter table is managed by the hypervisor, the guest should 165 + * assume the size is infinite. Filtering should be considered 166 + * non-perfect, ie. based on hypervisor resources, the guest may 167 + * received packets from sources not specified in the filter list. 168 + * 169 + * In addition to the class/cmd header, the TABLE_SET command requires 170 + * two out scatterlists. Each contains a 4 byte count of entries followed 171 + * by a concatenated byte stream of the ETH_ALEN MAC addresses. The 172 + * first sg list contains unicast addresses, the second is for multicast. 173 + * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature 174 + * is available. 175 + * 176 + * The ADDR_SET command requests one out scatterlist, it contains a 177 + * 6 bytes MAC address. This functionality is present if the 178 + * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available. 179 + */ 180 + struct virtio_net_ctrl_mac { 181 + __virtio32 entries; 182 + uint8_t macs[][ETH_ALEN]; 183 + } QEMU_PACKED; 184 + 185 + #define VIRTIO_NET_CTRL_MAC 1 186 + #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 187 + #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 188 + 189 + /* 190 + * Control VLAN filtering 191 + * 192 + * The VLAN filter table is controlled via a simple ADD/DEL interface. 193 + * VLAN IDs not added may be filterd by the hypervisor. Del is the 194 + * opposite of add. Both commands expect an out entry containing a 2 195 + * byte VLAN ID. VLAN filterting is available with the 196 + * VIRTIO_NET_F_CTRL_VLAN feature bit. 197 + */ 198 + #define VIRTIO_NET_CTRL_VLAN 2 199 + #define VIRTIO_NET_CTRL_VLAN_ADD 0 200 + #define VIRTIO_NET_CTRL_VLAN_DEL 1 201 + 202 + /* 203 + * Control link announce acknowledgement 204 + * 205 + * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that 206 + * driver has recevied the notification; device would clear the 207 + * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives 208 + * this command. 209 + */ 210 + #define VIRTIO_NET_CTRL_ANNOUNCE 3 211 + #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0 212 + 213 + /* 214 + * Control Receive Flow Steering 215 + * 216 + * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 217 + * enables Receive Flow Steering, specifying the number of the transmit and 218 + * receive queues that will be used. After the command is consumed and acked by 219 + * the device, the device will not steer new packets on receive virtqueues 220 + * other than specified nor read from transmit virtqueues other than specified. 221 + * Accordingly, driver should not transmit new packets on virtqueues other than 222 + * specified. 223 + */ 224 + struct virtio_net_ctrl_mq { 225 + __virtio16 virtqueue_pairs; 226 + }; 227 + 228 + #define VIRTIO_NET_CTRL_MQ 4 229 + #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 230 + #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 231 + #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 232 + 233 + #endif /* _LINUX_VIRTIO_NET_H */
+193
include/standard-headers/linux/virtio_pci.h
··· 1 + /* 2 + * Virtio PCI driver 3 + * 4 + * This module allows virtio devices to be used over a virtual PCI device. 5 + * This can be used with QEMU based VMMs like KVM or Xen. 6 + * 7 + * Copyright IBM Corp. 2007 8 + * 9 + * Authors: 10 + * Anthony Liguori <aliguori@us.ibm.com> 11 + * 12 + * This header is BSD licensed so anyone can use the definitions to implement 13 + * compatible drivers/servers. 14 + * 15 + * Redistribution and use in source and binary forms, with or without 16 + * modification, are permitted provided that the following conditions 17 + * are met: 18 + * 1. Redistributions of source code must retain the above copyright 19 + * notice, this list of conditions and the following disclaimer. 20 + * 2. Redistributions in binary form must reproduce the above copyright 21 + * notice, this list of conditions and the following disclaimer in the 22 + * documentation and/or other materials provided with the distribution. 23 + * 3. Neither the name of IBM nor the names of its contributors 24 + * may be used to endorse or promote products derived from this software 25 + * without specific prior written permission. 26 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 27 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 30 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 + * SUCH DAMAGE. 37 + */ 38 + 39 + #ifndef _LINUX_VIRTIO_PCI_H 40 + #define _LINUX_VIRTIO_PCI_H 41 + 42 + #include "standard-headers/linux/types.h" 43 + 44 + #ifndef VIRTIO_PCI_NO_LEGACY 45 + 46 + /* A 32-bit r/o bitmask of the features supported by the host */ 47 + #define VIRTIO_PCI_HOST_FEATURES 0 48 + 49 + /* A 32-bit r/w bitmask of features activated by the guest */ 50 + #define VIRTIO_PCI_GUEST_FEATURES 4 51 + 52 + /* A 32-bit r/w PFN for the currently selected queue */ 53 + #define VIRTIO_PCI_QUEUE_PFN 8 54 + 55 + /* A 16-bit r/o queue size for the currently selected queue */ 56 + #define VIRTIO_PCI_QUEUE_NUM 12 57 + 58 + /* A 16-bit r/w queue selector */ 59 + #define VIRTIO_PCI_QUEUE_SEL 14 60 + 61 + /* A 16-bit r/w queue notifier */ 62 + #define VIRTIO_PCI_QUEUE_NOTIFY 16 63 + 64 + /* An 8-bit device status register. */ 65 + #define VIRTIO_PCI_STATUS 18 66 + 67 + /* An 8-bit r/o interrupt status register. Reading the value will return the 68 + * current contents of the ISR and will also clear it. This is effectively 69 + * a read-and-acknowledge. */ 70 + #define VIRTIO_PCI_ISR 19 71 + 72 + /* MSI-X registers: only enabled if MSI-X is enabled. */ 73 + /* A 16-bit vector for configuration changes. */ 74 + #define VIRTIO_MSI_CONFIG_VECTOR 20 75 + /* A 16-bit vector for selected queue notifications. */ 76 + #define VIRTIO_MSI_QUEUE_VECTOR 22 77 + 78 + /* The remaining space is defined by each driver as the per-driver 79 + * configuration space */ 80 + #define VIRTIO_PCI_CONFIG_OFF(msix_enabled) ((msix_enabled) ? 24 : 20) 81 + /* Deprecated: please use VIRTIO_PCI_CONFIG_OFF instead */ 82 + #define VIRTIO_PCI_CONFIG(dev) VIRTIO_PCI_CONFIG_OFF((dev)->msix_enabled) 83 + 84 + /* Virtio ABI version, this must match exactly */ 85 + #define VIRTIO_PCI_ABI_VERSION 0 86 + 87 + /* How many bits to shift physical queue address written to QUEUE_PFN. 88 + * 12 is historical, and due to x86 page size. */ 89 + #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12 90 + 91 + /* The alignment to use between consumer and producer parts of vring. 92 + * x86 pagesize again. */ 93 + #define VIRTIO_PCI_VRING_ALIGN 4096 94 + 95 + #endif /* VIRTIO_PCI_NO_LEGACY */ 96 + 97 + /* The bit of the ISR which indicates a device configuration change. */ 98 + #define VIRTIO_PCI_ISR_CONFIG 0x2 99 + /* Vector value used to disable MSI for queue */ 100 + #define VIRTIO_MSI_NO_VECTOR 0xffff 101 + 102 + #ifndef VIRTIO_PCI_NO_MODERN 103 + 104 + /* IDs for different capabilities. Must all exist. */ 105 + 106 + /* Common configuration */ 107 + #define VIRTIO_PCI_CAP_COMMON_CFG 1 108 + /* Notifications */ 109 + #define VIRTIO_PCI_CAP_NOTIFY_CFG 2 110 + /* ISR access */ 111 + #define VIRTIO_PCI_CAP_ISR_CFG 3 112 + /* Device specific configuration */ 113 + #define VIRTIO_PCI_CAP_DEVICE_CFG 4 114 + /* PCI configuration access */ 115 + #define VIRTIO_PCI_CAP_PCI_CFG 5 116 + 117 + /* This is the PCI capability header: */ 118 + struct virtio_pci_cap { 119 + uint8_t cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */ 120 + uint8_t cap_next; /* Generic PCI field: next ptr. */ 121 + uint8_t cap_len; /* Generic PCI field: capability length */ 122 + uint8_t cfg_type; /* Identifies the structure. */ 123 + uint8_t bar; /* Where to find it. */ 124 + uint8_t padding[3]; /* Pad to full dword. */ 125 + uint32_t offset; /* Offset within bar. */ 126 + uint32_t length; /* Length of the structure, in bytes. */ 127 + }; 128 + 129 + struct virtio_pci_notify_cap { 130 + struct virtio_pci_cap cap; 131 + uint32_t notify_off_multiplier; /* Multiplier for queue_notify_off. */ 132 + }; 133 + 134 + /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */ 135 + struct virtio_pci_common_cfg { 136 + /* About the whole device. */ 137 + uint32_t device_feature_select; /* read-write */ 138 + uint32_t device_feature; /* read-only */ 139 + uint32_t guest_feature_select; /* read-write */ 140 + uint32_t guest_feature; /* read-write */ 141 + uint16_t msix_config; /* read-write */ 142 + uint16_t num_queues; /* read-only */ 143 + uint8_t device_status; /* read-write */ 144 + uint8_t config_generation; /* read-only */ 145 + 146 + /* About a specific virtqueue. */ 147 + uint16_t queue_select; /* read-write */ 148 + uint16_t queue_size; /* read-write, power of 2. */ 149 + uint16_t queue_msix_vector; /* read-write */ 150 + uint16_t queue_enable; /* read-write */ 151 + uint16_t queue_notify_off; /* read-only */ 152 + uint32_t queue_desc_lo; /* read-write */ 153 + uint32_t queue_desc_hi; /* read-write */ 154 + uint32_t queue_avail_lo; /* read-write */ 155 + uint32_t queue_avail_hi; /* read-write */ 156 + uint32_t queue_used_lo; /* read-write */ 157 + uint32_t queue_used_hi; /* read-write */ 158 + }; 159 + 160 + /* Macro versions of offsets for the Old Timers! */ 161 + #define VIRTIO_PCI_CAP_VNDR 0 162 + #define VIRTIO_PCI_CAP_NEXT 1 163 + #define VIRTIO_PCI_CAP_LEN 2 164 + #define VIRTIO_PCI_CAP_CFG_TYPE 3 165 + #define VIRTIO_PCI_CAP_BAR 4 166 + #define VIRTIO_PCI_CAP_OFFSET 8 167 + #define VIRTIO_PCI_CAP_LENGTH 12 168 + 169 + #define VIRTIO_PCI_NOTIFY_CAP_MULT 16 170 + 171 + #define VIRTIO_PCI_COMMON_DFSELECT 0 172 + #define VIRTIO_PCI_COMMON_DF 4 173 + #define VIRTIO_PCI_COMMON_GFSELECT 8 174 + #define VIRTIO_PCI_COMMON_GF 12 175 + #define VIRTIO_PCI_COMMON_MSIX 16 176 + #define VIRTIO_PCI_COMMON_NUMQ 18 177 + #define VIRTIO_PCI_COMMON_STATUS 20 178 + #define VIRTIO_PCI_COMMON_CFGGENERATION 21 179 + #define VIRTIO_PCI_COMMON_Q_SELECT 22 180 + #define VIRTIO_PCI_COMMON_Q_SIZE 24 181 + #define VIRTIO_PCI_COMMON_Q_MSIX 26 182 + #define VIRTIO_PCI_COMMON_Q_ENABLE 28 183 + #define VIRTIO_PCI_COMMON_Q_NOFF 30 184 + #define VIRTIO_PCI_COMMON_Q_DESCLO 32 185 + #define VIRTIO_PCI_COMMON_Q_DESCHI 36 186 + #define VIRTIO_PCI_COMMON_Q_AVAILLO 40 187 + #define VIRTIO_PCI_COMMON_Q_AVAILHI 44 188 + #define VIRTIO_PCI_COMMON_Q_USEDLO 48 189 + #define VIRTIO_PCI_COMMON_Q_USEDHI 52 190 + 191 + #endif /* VIRTIO_PCI_NO_MODERN */ 192 + 193 + #endif
+171
include/standard-headers/linux/virtio_ring.h
··· 1 + #ifndef _LINUX_VIRTIO_RING_H 2 + #define _LINUX_VIRTIO_RING_H 3 + /* An interface for efficient virtio implementation, currently for use by KVM 4 + * and lguest, but hopefully others soon. Do NOT change this since it will 5 + * break existing servers and clients. 6 + * 7 + * This header is BSD licensed so anyone can use the definitions to implement 8 + * compatible drivers/servers. 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions and the following disclaimer. 15 + * 2. Redistributions in binary form must reproduce the above copyright 16 + * notice, this list of conditions and the following disclaimer in the 17 + * documentation and/or other materials provided with the distribution. 18 + * 3. Neither the name of IBM nor the names of its contributors 19 + * may be used to endorse or promote products derived from this software 20 + * without specific prior written permission. 21 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 22 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 25 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 + * SUCH DAMAGE. 32 + * 33 + * Copyright Rusty Russell IBM Corporation 2007. */ 34 + #include "standard-headers/linux/types.h" 35 + #include "standard-headers/linux/virtio_types.h" 36 + 37 + /* This marks a buffer as continuing via the next field. */ 38 + #define VRING_DESC_F_NEXT 1 39 + /* This marks a buffer as write-only (otherwise read-only). */ 40 + #define VRING_DESC_F_WRITE 2 41 + /* This means the buffer contains a list of buffer descriptors. */ 42 + #define VRING_DESC_F_INDIRECT 4 43 + 44 + /* The Host uses this in used->flags to advise the Guest: don't kick me when 45 + * you add a buffer. It's unreliable, so it's simply an optimization. Guest 46 + * will still kick if it's out of buffers. */ 47 + #define VRING_USED_F_NO_NOTIFY 1 48 + /* The Guest uses this in avail->flags to advise the Host: don't interrupt me 49 + * when you consume a buffer. It's unreliable, so it's simply an 50 + * optimization. */ 51 + #define VRING_AVAIL_F_NO_INTERRUPT 1 52 + 53 + /* We support indirect buffer descriptors */ 54 + #define VIRTIO_RING_F_INDIRECT_DESC 28 55 + 56 + /* The Guest publishes the used index for which it expects an interrupt 57 + * at the end of the avail ring. Host should ignore the avail->flags field. */ 58 + /* The Host publishes the avail index for which it expects a kick 59 + * at the end of the used ring. Guest should ignore the used->flags field. */ 60 + #define VIRTIO_RING_F_EVENT_IDX 29 61 + 62 + /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ 63 + struct vring_desc { 64 + /* Address (guest-physical). */ 65 + __virtio64 addr; 66 + /* Length. */ 67 + __virtio32 len; 68 + /* The flags as indicated above. */ 69 + __virtio16 flags; 70 + /* We chain unused descriptors via this, too */ 71 + __virtio16 next; 72 + }; 73 + 74 + struct vring_avail { 75 + __virtio16 flags; 76 + __virtio16 idx; 77 + __virtio16 ring[]; 78 + }; 79 + 80 + /* u32 is used here for ids for padding reasons. */ 81 + struct vring_used_elem { 82 + /* Index of start of used descriptor chain. */ 83 + __virtio32 id; 84 + /* Total length of the descriptor chain which was used (written to) */ 85 + __virtio32 len; 86 + }; 87 + 88 + struct vring_used { 89 + __virtio16 flags; 90 + __virtio16 idx; 91 + struct vring_used_elem ring[]; 92 + }; 93 + 94 + struct vring { 95 + unsigned int num; 96 + 97 + struct vring_desc *desc; 98 + 99 + struct vring_avail *avail; 100 + 101 + struct vring_used *used; 102 + }; 103 + 104 + /* Alignment requirements for vring elements. 105 + * When using pre-virtio 1.0 layout, these fall out naturally. 106 + */ 107 + #define VRING_AVAIL_ALIGN_SIZE 2 108 + #define VRING_USED_ALIGN_SIZE 4 109 + #define VRING_DESC_ALIGN_SIZE 16 110 + 111 + /* The standard layout for the ring is a continuous chunk of memory which looks 112 + * like this. We assume num is a power of 2. 113 + * 114 + * struct vring 115 + * { 116 + * // The actual descriptors (16 bytes each) 117 + * struct vring_desc desc[num]; 118 + * 119 + * // A ring of available descriptor heads with free-running index. 120 + * __virtio16 avail_flags; 121 + * __virtio16 avail_idx; 122 + * __virtio16 available[num]; 123 + * __virtio16 used_event_idx; 124 + * 125 + * // Padding to the next align boundary. 126 + * char pad[]; 127 + * 128 + * // A ring of used descriptor heads with free-running index. 129 + * __virtio16 used_flags; 130 + * __virtio16 used_idx; 131 + * struct vring_used_elem used[num]; 132 + * __virtio16 avail_event_idx; 133 + * }; 134 + */ 135 + /* We publish the used event index at the end of the available ring, and vice 136 + * versa. They are at the end for backwards compatibility. */ 137 + #define vring_used_event(vr) ((vr)->avail->ring[(vr)->num]) 138 + #define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num]) 139 + 140 + static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p, 141 + unsigned long align) 142 + { 143 + vr->num = num; 144 + vr->desc = p; 145 + vr->avail = p + num*sizeof(struct vring_desc); 146 + vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__virtio16) 147 + + align-1) & ~(align - 1)); 148 + } 149 + 150 + static __inline__ unsigned vring_size(unsigned int num, unsigned long align) 151 + { 152 + return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num) 153 + + align - 1) & ~(align - 1)) 154 + + sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num; 155 + } 156 + 157 + /* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */ 158 + /* Assuming a given event_idx value from the other size, if 159 + * we have just incremented index from old to new_idx, 160 + * should we trigger an event? */ 161 + static __inline__ int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old) 162 + { 163 + /* Note: Xen has similar logic for notification hold-off 164 + * in include/xen/interface/io/ring.h with req_event and req_prod 165 + * corresponding to event_idx + 1 and new_idx respectively. 166 + * Note also that req_event and req_prod in Xen start at 1, 167 + * event indexes in virtio start at 0. */ 168 + return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old); 169 + } 170 + 171 + #endif /* _LINUX_VIRTIO_RING_H */
+8
include/standard-headers/linux/virtio_rng.h
··· 1 + #ifndef _LINUX_VIRTIO_RNG_H 2 + #define _LINUX_VIRTIO_RNG_H 3 + /* This header is BSD licensed so anyone can use the definitions to implement 4 + * compatible drivers/servers. */ 5 + #include "standard-headers/linux/virtio_ids.h" 6 + #include "standard-headers/linux/virtio_config.h" 7 + 8 + #endif /* _LINUX_VIRTIO_RNG_H */
+164
include/standard-headers/linux/virtio_scsi.h
··· 1 + /* 2 + * This header is BSD licensed so anyone can use the definitions to implement 3 + * compatible drivers/servers. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 8 + * 1. Redistributions of source code must retain the above copyright 9 + * notice, this list of conditions and the following disclaimer. 10 + * 2. Redistributions in binary form must reproduce the above copyright 11 + * notice, this list of conditions and the following disclaimer in the 12 + * documentation and/or other materials provided with the distribution. 13 + * 14 + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 18 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 + * SUCH DAMAGE. 25 + */ 26 + 27 + #ifndef _LINUX_VIRTIO_SCSI_H 28 + #define _LINUX_VIRTIO_SCSI_H 29 + 30 + #include "standard-headers/linux/virtio_types.h" 31 + 32 + #define VIRTIO_SCSI_CDB_SIZE 32 33 + #define VIRTIO_SCSI_SENSE_SIZE 96 34 + 35 + /* SCSI command request, followed by data-out */ 36 + struct virtio_scsi_cmd_req { 37 + uint8_t lun[8]; /* Logical Unit Number */ 38 + __virtio64 tag; /* Command identifier */ 39 + uint8_t task_attr; /* Task attribute */ 40 + uint8_t prio; /* SAM command priority field */ 41 + uint8_t crn; 42 + uint8_t cdb[VIRTIO_SCSI_CDB_SIZE]; 43 + } QEMU_PACKED; 44 + 45 + /* SCSI command request, followed by protection information */ 46 + struct virtio_scsi_cmd_req_pi { 47 + uint8_t lun[8]; /* Logical Unit Number */ 48 + __virtio64 tag; /* Command identifier */ 49 + uint8_t task_attr; /* Task attribute */ 50 + uint8_t prio; /* SAM command priority field */ 51 + uint8_t crn; 52 + __virtio32 pi_bytesout; /* DataOUT PI Number of bytes */ 53 + __virtio32 pi_bytesin; /* DataIN PI Number of bytes */ 54 + uint8_t cdb[VIRTIO_SCSI_CDB_SIZE]; 55 + } QEMU_PACKED; 56 + 57 + /* Response, followed by sense data and data-in */ 58 + struct virtio_scsi_cmd_resp { 59 + __virtio32 sense_len; /* Sense data length */ 60 + __virtio32 resid; /* Residual bytes in data buffer */ 61 + __virtio16 status_qualifier; /* Status qualifier */ 62 + uint8_t status; /* Command completion status */ 63 + uint8_t response; /* Response values */ 64 + uint8_t sense[VIRTIO_SCSI_SENSE_SIZE]; 65 + } QEMU_PACKED; 66 + 67 + /* Task Management Request */ 68 + struct virtio_scsi_ctrl_tmf_req { 69 + __virtio32 type; 70 + __virtio32 subtype; 71 + uint8_t lun[8]; 72 + __virtio64 tag; 73 + } QEMU_PACKED; 74 + 75 + struct virtio_scsi_ctrl_tmf_resp { 76 + uint8_t response; 77 + } QEMU_PACKED; 78 + 79 + /* Asynchronous notification query/subscription */ 80 + struct virtio_scsi_ctrl_an_req { 81 + __virtio32 type; 82 + uint8_t lun[8]; 83 + __virtio32 event_requested; 84 + } QEMU_PACKED; 85 + 86 + struct virtio_scsi_ctrl_an_resp { 87 + __virtio32 event_actual; 88 + uint8_t response; 89 + } QEMU_PACKED; 90 + 91 + struct virtio_scsi_event { 92 + __virtio32 event; 93 + uint8_t lun[8]; 94 + __virtio32 reason; 95 + } QEMU_PACKED; 96 + 97 + struct virtio_scsi_config { 98 + uint32_t num_queues; 99 + uint32_t seg_max; 100 + uint32_t max_sectors; 101 + uint32_t cmd_per_lun; 102 + uint32_t event_info_size; 103 + uint32_t sense_size; 104 + uint32_t cdb_size; 105 + uint16_t max_channel; 106 + uint16_t max_target; 107 + uint32_t max_lun; 108 + } QEMU_PACKED; 109 + 110 + /* Feature Bits */ 111 + #define VIRTIO_SCSI_F_INOUT 0 112 + #define VIRTIO_SCSI_F_HOTPLUG 1 113 + #define VIRTIO_SCSI_F_CHANGE 2 114 + #define VIRTIO_SCSI_F_T10_PI 3 115 + 116 + /* Response codes */ 117 + #define VIRTIO_SCSI_S_OK 0 118 + #define VIRTIO_SCSI_S_OVERRUN 1 119 + #define VIRTIO_SCSI_S_ABORTED 2 120 + #define VIRTIO_SCSI_S_BAD_TARGET 3 121 + #define VIRTIO_SCSI_S_RESET 4 122 + #define VIRTIO_SCSI_S_BUSY 5 123 + #define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6 124 + #define VIRTIO_SCSI_S_TARGET_FAILURE 7 125 + #define VIRTIO_SCSI_S_NEXUS_FAILURE 8 126 + #define VIRTIO_SCSI_S_FAILURE 9 127 + #define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10 128 + #define VIRTIO_SCSI_S_FUNCTION_REJECTED 11 129 + #define VIRTIO_SCSI_S_INCORRECT_LUN 12 130 + 131 + /* Controlq type codes. */ 132 + #define VIRTIO_SCSI_T_TMF 0 133 + #define VIRTIO_SCSI_T_AN_QUERY 1 134 + #define VIRTIO_SCSI_T_AN_SUBSCRIBE 2 135 + 136 + /* Valid TMF subtypes. */ 137 + #define VIRTIO_SCSI_T_TMF_ABORT_TASK 0 138 + #define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1 139 + #define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2 140 + #define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3 141 + #define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4 142 + #define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5 143 + #define VIRTIO_SCSI_T_TMF_QUERY_TASK 6 144 + #define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7 145 + 146 + /* Events. */ 147 + #define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000 148 + #define VIRTIO_SCSI_T_NO_EVENT 0 149 + #define VIRTIO_SCSI_T_TRANSPORT_RESET 1 150 + #define VIRTIO_SCSI_T_ASYNC_NOTIFY 2 151 + #define VIRTIO_SCSI_T_PARAM_CHANGE 3 152 + 153 + /* Reasons of transport reset event */ 154 + #define VIRTIO_SCSI_EVT_RESET_HARD 0 155 + #define VIRTIO_SCSI_EVT_RESET_RESCAN 1 156 + #define VIRTIO_SCSI_EVT_RESET_REMOVED 2 157 + 158 + #define VIRTIO_SCSI_S_SIMPLE 0 159 + #define VIRTIO_SCSI_S_ORDERED 1 160 + #define VIRTIO_SCSI_S_HEAD 2 161 + #define VIRTIO_SCSI_S_ACA 3 162 + 163 + 164 + #endif /* _LINUX_VIRTIO_SCSI_H */
+46
include/standard-headers/linux/virtio_types.h
··· 1 + #ifndef _LINUX_VIRTIO_TYPES_H 2 + #define _LINUX_VIRTIO_TYPES_H 3 + /* Type definitions for virtio implementations. 4 + * 5 + * This header is BSD licensed so anyone can use the definitions to implement 6 + * compatible drivers/servers. 7 + * 8 + * Redistribution and use in source and binary forms, with or without 9 + * modification, are permitted provided that the following conditions 10 + * are met: 11 + * 1. Redistributions of source code must retain the above copyright 12 + * notice, this list of conditions and the following disclaimer. 13 + * 2. Redistributions in binary form must reproduce the above copyright 14 + * notice, this list of conditions and the following disclaimer in the 15 + * documentation and/or other materials provided with the distribution. 16 + * 3. Neither the name of IBM nor the names of its contributors 17 + * may be used to endorse or promote products derived from this software 18 + * without specific prior written permission. 19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 20 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 23 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 + * SUCH DAMAGE. 30 + * 31 + * Copyright (C) 2014 Red Hat, Inc. 32 + * Author: Michael S. Tsirkin <mst@redhat.com> 33 + */ 34 + #include "standard-headers/linux/types.h" 35 + 36 + /* 37 + * __virtio{16,32,64} have the following meaning: 38 + * - __u{16,32,64} for virtio devices in legacy mode, accessed in native endian 39 + * - __le{16,32,64} for standard-compliant virtio devices 40 + */ 41 + 42 + typedef uint16_t __virtio16; 43 + typedef uint32_t __virtio32; 44 + typedef uint64_t __virtio64; 45 + 46 + #endif /* _LINUX_VIRTIO_TYPES_H */