virtio: import headers from linux
cover virtio: import headers from linux
I'm working on adding new virtio layout to qemu. The job is complicated by the fact that qemu has its own copy of the virtio headers, sometimes with slightly different names and structure.
Import headers from linux instead.
Michael S. Tsirkin (10):
scripts/update-linux-headers.sh: add virtio
virtio-9p: switch to linux-headers virtio-net, eth: use linux-headers
virtio-blk: switch to linux-headers
virtio-balloon: switch to linux-headers
virtio-rng: switch to linux-headers
virtio-console: switch to linux-headers
virtio: add virtio_ids from linux-headers
virtio-pci: switch to linux-headers
virtio: use ring structure from linux-headers
hw/9pfs/virtio-9p.h | 13 +-- hw/block/dataplane/virtio-blk.c | 12 +-- hw/block/virtio-blk.c | 10 +- hw/virtio/virtio-balloon.c | 2 +- hw/virtio/virtio-pci.c | 49 +-------- hw/virtio/virtio.c | 23 +--- include/hw/virtio/virtio-balloon.h | 37 +------ include/hw/virtio/virtio-blk.h | 86 +-------------- include/hw/virtio/virtio-net.h | 138 +----------------------- include/hw/virtio/virtio-rng.h | 5 +- include/hw/virtio/virtio-serial.h | 38 +------ include/hw/virtio/virtio.h | 45 +------- include/net/eth.h | 5 +- include/net/tap.h | 24 +---- linux-headers/linux/if_ether.h | 140 ++++++++++++++++++++++++ linux-headers/linux/virtio_9p.h | 44 ++++++++ linux-headers/linux/virtio_balloon.h | 59 ++++++++++ linux-headers/linux/virtio_blk.h | 128 ++++++++++++++++++++++ linux-headers/linux/virtio_console.h | 74 +++++++++++++ linux-headers/linux/virtio_ids.h | 43 ++++++++ linux-headers/linux/virtio_net.h | 202 +++++++++++++++++++++++++++++++++++ linux-headers/linux/virtio_pci.h | 97 +++++++++++++++++ linux-headers/linux/virtio_rng.h | 8 ++ scripts/update-linux-headers.sh | 17 ++- 24 files changed, 852 insertions(+), 447 deletions(-) create mode 100644 linux-headers/linux/if_ether.h create mode 100644 linux-headers/linux/virtio_9p.h create mode 100644 linux-headers/linux/virtio_balloon.h create mode 100644 linux-headers/linux/virtio_blk.h create mode 100644 linux-headers/linux/virtio_console.h create mode 100644 linux-headers/linux/virtio_ids.h create mode 100644 linux-headers/linux/virtio_net.h create mode 100644 linux-headers/linux/virtio_pci.h create mode 100644 linux-headers/linux/virtio_rng.h
Signature · 1 line
MST
PATCH 1/10 scripts/update-linux-headers.sh: add virtio
Add virtio headers to make it easy to keep
things in sync.
--- scripts/update-linux-headers.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
scripts/update-linux-headers.sh +16 -1
@@ -61,7 +61,22 @@ done rm -rf "$output/linux-headers/linux" mkdir -p "$output/linux-headers/linux" -for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h; do +for header in \ + kvm.h \ + kvm_para.h \ + vfio.h \ + vhost.h \ + virtio_9p.h \ + virtio_balloon.h \ + virtio_blk.h \ + virtio_config.h \ + virtio_console.h \ + virtio_ids.h \ + virtio_net.h \ + virtio_pci.h \ + virtio_ring.h \ + virtio_rng.h \ + ; do cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux" done rm -rf "$output/linux-headers/asm-generic"
Signature · 1 line
MST
PATCH 2/10 virtio-9p: switch to linux-headers
In reply to Michael S. TsirkinIt's easier to keep everything in sync if
we just use linux headers for virtio constants.
Add virtio-9p header from linux 3.10-rc1, and
remove duplicate symbols from virtio-9p.h
--- hw/9pfs/virtio-9p.h | 13 +----------- linux-headers/linux/virtio_9p.h | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 linux-headers/linux/virtio_9p.h
hw/9pfs/virtio-9p.h +1 -12
@@ -11,10 +11,7 @@#include "fsdev/virtio-9p-marshal.h" #include "qemu/thread.h" #include "block/coroutine.h" - -/* The feature bitmap for virtio 9P */ -/* The mount point is specified in a config variable */ -#define VIRTIO_9P_MOUNT_TAG 0 +#include "linux/virtio_9p.h" enum {P9_TLERROR =6 ,
@@ -277,14 +274,6 @@ typedef struct V9fsWriteState {int cnt; } V9fsWriteState; -struct virtio_9p_config -{ -/* number of characters in tag */ -uint16_t tag_len; -/* Variable size tag name */ -uint8_t tag[0 ]; -}QEMU_PACKED ; - typedef struct V9fsMkState { V9fsPDU *pdu; size_t offset;
linux-headers/linux/virtio_9p.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
MST
PATCH 3/10 virtio-net, eth: use linux-headers
In reply to Michael S. TsirkinIt's easier to keep everything virtio in sync if
we just use headers exported from linux kernel.
Import linux/virtio_net.h and linux/if_ether.h
that it depends on. Switch to symbols from
that header for stuff that was
duplicated in tap.h and eth.h
--- include/hw/virtio/virtio-net.h | 138 +------------------------- include/net/eth.h | 5 +- include/net/tap.h | 24 +---- linux-headers/linux/if_ether.h | 140 +++++++++++++++++++++++++++ linux-headers/linux/virtio_net.h | 202 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 346 insertions(+), 163 deletions(-) create mode 100644 linux-headers/linux/if_ether.h create mode 100644 linux-headers/linux/virtio_net.h
include/hw/virtio/virtio-net.h +2 -136
@@ -16,44 +16,13 @@#include "hw/virtio/virtio.h" #include "hw/pci/pci.h" +#include "linux/virtio_net.h" +#include "linux/virtio_ids.h" #define TYPE_VIRTIO_NET "virtio-net-device"#define VIRTIO_NET (obj) \ OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET) -#define ETH_ALEN 6 - -/* from Linux's virtio_net.h */ - -/* The ID for virtio_net */ -#define VIRTIO_ID_NET 1 - -/* The feature bitmap for virtio net */ -#define VIRTIO_NET_F_CSUM 0/* Host handles pkts w/ partial csum */ -#define VIRTIO_NET_F_GUEST_CSUM 1/* Guest handles pkts w/ partial csum */ -#define VIRTIO_NET_F_MAC 5/* Host has given MAC address. */ -#define VIRTIO_NET_F_GSO 6/* Host handles pkts w/ any GSO type */ -#define VIRTIO_NET_F_GUEST_TSO4 7/* Guest can handle TSOv4 in. */ -#define VIRTIO_NET_F_GUEST_TSO6 8/* Guest can handle TSOv6 in. */ -#define VIRTIO_NET_F_GUEST_ECN 9/* Guest can handle TSO[6] w/ ECN in. */ -#define VIRTIO_NET_F_GUEST_UFO 10/* Guest can handle UFO in. */ -#define VIRTIO_NET_F_HOST_TSO4 11/* Host can handle TSOv4 in. */ -#define VIRTIO_NET_F_HOST_TSO6 12/* Host can handle TSOv6 in. */ -#define VIRTIO_NET_F_HOST_ECN 13/* Host can handle TSO[6] w/ ECN in. */ -#define VIRTIO_NET_F_HOST_UFO 14/* Host can handle UFO in. */ -#define VIRTIO_NET_F_MRG_RXBUF 15/* Host can merge receive buffers. */ -#define VIRTIO_NET_F_STATUS 16/* virtio_net_config.status available */ -#define VIRTIO_NET_F_CTRL_VQ 17/* Control channel available */ -#define VIRTIO_NET_F_CTRL_RX 18/* Control channel RX mode support */ -#define VIRTIO_NET_F_CTRL_VLAN 19/* Control channel VLAN filtering */ -#define VIRTIO_NET_F_CTRL_RX_EXTRA 20/* Extra RX mode control support */ -#define VIRTIO_NET_F_MQ 22/* Device supports Receive Flow -* Steering */ - -#define VIRTIO_NET_F_CTRL_MAC_ADDR 23/* Set MAC address */ - -#define VIRTIO_NET_S_LINK_UP 1/* Link is up */ -#define TX_TIMER_INTERVAL 150000/* 150 us */ /* Limit the number of packets that can be sent via a single flush
@@ -73,72 +42,6 @@ typedef struct virtio_net_conf/* Maximum packet size we can receive from tap device: header + 64k */ #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10)) -struct virtio_net_config -{ -/* The config defining mac address ($ETH_ALEN bytes) */ -uint8_t mac[ETH_ALEN ]; -/* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ -uint16_t status; -/* Max virtqueue pairs supported by the device */ -uint16_t max_virtqueue_pairs; -}QEMU_PACKED ; - -/* -* Control virtqueue data structures -* -* The control virtqueue expects a header in the first sg entry -* and an ack/status response in the last entry. Data for the -* command goes in between. -*/ -struct virtio_net_ctrl_hdr { -uint8_t class; -uint8_t cmd; -}; - -typedef uint8_t virtio_net_ctrl_ack ; - -#define VIRTIO_NET_OK 0 -#define VIRTIO_NET_ERR 1 - -/* -* Control the RX mode, ie. promisucous, allmulti, etc... -* All commands require an "out" sg entry containing a 1 byte -* state value, zero = disable, non-zero = enable. Commands -* 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature. -* Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA. -*/ -#define VIRTIO_NET_CTRL_RX 0 -#define VIRTIO_NET_CTRL_RX_PROMISC 0 -#define VIRTIO_NET_CTRL_RX_ALLMULTI 1 -#define VIRTIO_NET_CTRL_RX_ALLUNI 2 -#define VIRTIO_NET_CTRL_RX_NOMULTI 3 -#define VIRTIO_NET_CTRL_RX_NOUNI 4 -#define VIRTIO_NET_CTRL_RX_NOBCAST 5 - -/* -* Control the MAC -* -* The MAC filter table is managed by the hypervisor, the guest should -* assume the size is infinite. Filtering should be considered -* non-perfect, ie. based on hypervisor resources, the guest may -* received packets from sources not specified in the filter list. -* -* In addition to the class/cmd header, the TABLE_SET command requires -* two out scatterlists. Each contains a 4 byte count of entries followed -* by a concatenated byte stream of the ETH_ALEN MAC addresses. The -* first sg list contains unicast addresses, the second is for multicast. -* This functionality is present if the VIRTIO_NET_F_CTRL_RX feature -* is available. -* -* The ADDR_SET command requests one out scatterlist, it contains a -* 6 bytes MAC address. This functionality is present if the -* VIRTIO_NET_F_CTRL_MAC_ADDR feature is available. -*/ -struct virtio_net_ctrl_mac { -uint32_t entries; -uint8_t macs[][ETH_ALEN ]; -}; - typedef struct VirtIONetQueue { VirtQueue *rx_vq; VirtQueue *tx_vq;
@@ -192,43 +95,6 @@ typedef struct VirtIONet {char *netclient_type; } VirtIONet; -#define VIRTIO_NET_CTRL_MAC 1 -#define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 -#define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 - -/* -* Control VLAN filtering -* -* The VLAN filter table is controlled via a simple ADD/DEL interface. -* VLAN IDs not added may be filterd by the hypervisor. Del is the -* opposite of add. Both commands expect an out entry containing a 2 -* byte VLAN ID. VLAN filterting is available with the -* VIRTIO_NET_F_CTRL_VLAN feature bit. -*/ -#define VIRTIO_NET_CTRL_VLAN 2 -#define VIRTIO_NET_CTRL_VLAN_ADD 0 -#define VIRTIO_NET_CTRL_VLAN_DEL 1 - -/* -* Control Multiqueue -* -* The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET -* enables multiqueue, specifying the number of the transmit and -* receive queues that will be used. After the command is consumed and acked by -* the device, the device will not steer new packets on receive virtqueues -* other than specified nor read from transmit virtqueues other than specified. -* Accordingly, driver should not transmit new packets on virtqueues other than -* specified. -*/ -struct virtio_net_ctrl_mq { -uint16_t virtqueue_pairs; -}; - -#define VIRTIO_NET_CTRL_MQ 4 -#define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 -#define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 -#define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 -#define DEFINE_VIRTIO_NET_FEATURES (_state, _field) \ DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \ DEFINE_PROP_BIT("csum", _state, _field, VIRTIO_NET_F_CSUM, true), \
include/net/eth.h +1 -4
@@ -26,13 +26,12 @@ #ifndef QEMU_ETH_H #define QEMU_ETH_H +#include <linux/if_ether.h> #include <sys/types.h> #include <string.h> #include "qemu/bswap.h" #include "qemu/iov.h" -#define ETH_ALEN 6 - struct eth_header { uint8_t h_dest[ETH_ALEN]; /* destination eth addr */ uint8_t h_source[ETH_ALEN]; /* source ether addr */
@@ -170,8 +169,6 @@ struct tcp_hdr {#define IP_HEADER_VERSION (ip) \ ((ip->ip_ver_len >> 4)&0xf) -#define ETH_P_IP (0x0800) -#define ETH_P_IPV6 (0x86dd)#define ETH_P_VLAN (0x8100)#define ETH_P_DVLAN (0x88a8)#define VLAN_VID_MASK 0x0fff
include/net/tap.h +1 -23
@@ -28,6 +28,7 @@#include "qemu-common.h" #include "qapi-types.h" +#include "linux/virtio_net.h" bool tap_has_ufo (NetClientState *nc);int tap_has_vnet_hdr (NetClientState *nc);
@@ -43,27 +44,4 @@ int tap_get_fd(NetClientState *nc);struct vhost_net ;struct vhost_net *tap_get_vhost_net (NetClientState *nc); -struct virtio_net_hdr -{ -#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset -#define VIRTIO_NET_HDR_F_DATA_VALID 2 // Csum is valid -uint8_t flags; -#define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame -#define VIRTIO_NET_HDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO) -#define VIRTIO_NET_HDR_GSO_UDP 3 // GSO frame, IPv4 UDP (UFO) -#define VIRTIO_NET_HDR_GSO_TCPV6 4 // GSO frame, IPv6 TCP -#define VIRTIO_NET_HDR_GSO_ECN 0x80 // TCP has ECN set -uint8_t gso_type; -uint16_t hdr_len; -uint16_t gso_size; -uint16_t csum_start; -uint16_t csum_offset; -}; - -struct virtio_net_hdr_mrg_rxbuf -{ -struct virtio_net_hdr hdr; -uint16_t num_buffers;/* Number of merged rx buffers */ -}; -#endif /* QEMU_NET_TAP_H */
linux-headers/linux/if_ether.h new file +140 -0
140 lines not on this page · raw message
linux-headers/linux/virtio_net.h new file +202 -0
202 lines not on this page · raw message
Signature · 1 line
MST
PATCH 4/10 virtio-blk: switch to linux-headers
In reply to Michael S. TsirkinIt's easier to keep everything in sync if
we just use linux headers for virtio constants.
Add virtio_blk.h header from linux 3.10-rc1, and
remove duplicate symbols from virtio-blk.h
In particular, it turns out that linux does not have struct virtio_blk_inhdr for the status field, so make this struct match the qemu coding style.
--- hw/block/dataplane/virtio-blk.c | 12 ++-- hw/block/virtio-blk.c | 10 +-- include/hw/virtio/virtio-blk.h | 86 ++------------------------ linux-headers/linux/virtio_blk.h | 128 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 92 deletions(-) create mode 100644 linux-headers/linux/virtio_blk.h
hw/block/dataplane/virtio-blk.c +6 -6
@@ -87,7 +87,7 @@ static void complete_request(struct iocb *iocb, ssize_t ret, void *opaque) {VirtIOBlockDataPlane *s = opaque;VirtIOBlockRequest *req =container_of (iocb, VirtIOBlockRequest, iocb); -struct virtio_blk_inhdr hdr; +VirtIOBlockInHdr hdr;int len;if (likely (ret >=0 )) {
@@ -128,7 +128,7 @@ static void complete_request(struct iocb *iocb, ssize_t ret, void *opaque)static void complete_request_early (VirtIOBlockDataPlane *s,unsigned int head,QEMUIOVector *inhdr,unsigned char status) { -struct virtio_blk_inhdr hdr = { +VirtIOBlockInHdr hdr = { .status = status, };
@@ -215,16 +215,16 @@ static int process_request(IOQueue *ioq, struct iovec iov[],/* Grab inhdr for later */ in_size =iov_size (in_iov, in_num); -if (in_size <sizeof (struct virtio_blk_inhdr )) { +if (in_size <sizeof (VirtIOBlockInHdr)) {error_report ("virtio_blk request inhdr too short" );return -EFAULT ; } inhdr =g_slice_new (QEMUIOVector);qemu_iovec_init (inhdr,1 );qemu_iovec_concat_iov (inhdr, in_iov, in_num, - in_size -sizeof (struct virtio_blk_inhdr ), -sizeof (struct virtio_blk_inhdr )); -iov_discard_back (in_iov, &in_num,sizeof (struct virtio_blk_inhdr )); + in_size -sizeof (VirtIOBlockInHdr), +sizeof (VirtIOBlockInHdr)); +iov_discard_back (in_iov, &in_num,sizeof (VirtIOBlockInHdr));/* TODO Linux sets the barrier bit even when not advertised! */ outhdr.type &= ~VIRTIO_BLK_T_BARRIER ;
hw/block/virtio-blk.c +5 -5
@@ -30,7 +30,7 @@ typedef struct VirtIOBlockReq {VirtIOBlock *dev;VirtQueueElement elem; -struct virtio_blk_inhdr *in; +VirtIOBlockInHdr *in;struct virtio_blk_outhdr *out;struct virtio_scsi_inhdr *scsi;QEMUIOVector qiov;
@@ -487,11 +487,11 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)memset (&blkcfg,0 ,sizeof (blkcfg));stq_raw (&blkcfg.capacity, capacity);stl_raw (&blkcfg.seg_max,128 -2 ); -stw_raw (&blkcfg.cylinders, s->conf->cyls); +stw_raw (&blkcfg.geometry.cylinders, s->conf->cyls);stl_raw (&blkcfg.blk_size, blk_size);stw_raw (&blkcfg.min_io_size, s->conf->min_io_size / blk_size);stw_raw (&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size); - blkcfg.heads = s->conf->heads; + blkcfg.geometry.heads = s->conf->heads;/* * We must ensure that the block device capacity is a multiple of * the logical block size. If that is not the case, let's use
@@ -504,9 +504,9 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)* per track (cylinder). */ if (bdrv_getlength (s->bs) / s->conf->heads / s->conf->secs % blk_size) { - blkcfg.sectors = s->conf->secs & ~s->sector_mask; + blkcfg.geometry.sectors = s->conf->secs & ~s->sector_mask; }else { - blkcfg.sectors = s->conf->secs; + blkcfg.geometry.sectors = s->conf->secs; } blkcfg.size_max =0 ; blkcfg.physical_block_exp =get_physical_block_exp (s->conf);
include/hw/virtio/virtio-blk.h +5 -81
100 lines not on this page · raw message
linux-headers/linux/virtio_blk.h new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
MST
PATCH 5/10 virtio-balloon: switch to linux-headers
In reply to Michael S. TsirkinIt's easier to keep everything in sync if
we just use linux headers for virtio constants. Add virtio_balloon.h header from linux 3.10-rc1, and remove duplicate symbols from virtio-balloon.h
--- hw/virtio/virtio-balloon.c | 2 +- include/hw/virtio/virtio-balloon.h | 37 ++-------------------- linux-headers/linux/virtio_balloon.h | 59 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 35 deletions(-) create mode 100644 linux-headers/linux/virtio_balloon.h
hw/virtio/virtio-balloon.c +1 -1
@@ -216,7 +216,7 @@ static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq) {VirtIOBalloon *s =VIRTIO_BALLOON (vdev);VirtQueueElement *elem = &s->stats_vq_elem; -VirtIOBalloonStat stat; +struct virtio_balloon_stat stat;size_t offset =0 ;qemu_timeval tv;
include/hw/virtio/virtio-balloon.h +3 -34
@@ -17,45 +17,14 @@#include "hw/virtio/virtio.h" #include "hw/pci/pci.h" +#include "linux/virtio_balloon.h" +#include "linux/virtio_ids.h" +#define TYPE_VIRTIO_BALLOON "virtio-balloon-device"#define VIRTIO_BALLOON (obj) \ OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON) -/* from Linux's linux/virtio_balloon.h */ - -/* The ID for virtio_balloon */ -#define VIRTIO_ID_BALLOON 5 - -/* The feature bitmap for virtio balloon */ -#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0/* Tell before reclaiming pages */ -#define VIRTIO_BALLOON_F_STATS_VQ 1/* Memory stats virtqueue */ - -/* Size of a PFN in the balloon interface. */ -#define VIRTIO_BALLOON_PFN_SHIFT 12 - -struct virtio_balloon_config -{ -/* Number of pages host wants Guest to give up. */ -uint32_t num_pages; -/* Number of pages we've actually got in balloon. */ -uint32_t actual; -}; - -/* Memory Statistics */ -#define VIRTIO_BALLOON_S_SWAP_IN 0/* Amount of memory swapped in */ -#define VIRTIO_BALLOON_S_SWAP_OUT 1/* Amount of memory swapped out */ -#define VIRTIO_BALLOON_S_MAJFLT 2/* Number of major faults */ -#define VIRTIO_BALLOON_S_MINFLT 3/* Number of minor faults */ -#define VIRTIO_BALLOON_S_MEMFREE 4/* Total amount of free memory */ -#define VIRTIO_BALLOON_S_MEMTOT 5/* Total amount of memory */ -#define VIRTIO_BALLOON_S_NR 6 - -typedef struct VirtIOBalloonStat { -uint16_t tag; -uint64_t val; -} QEMU_PACKED VirtIOBalloonStat; - typedef struct VirtIOBalloon { VirtIODevice parent_obj; VirtQueue *ivq, *dvq, *svq;
linux-headers/linux/virtio_balloon.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
MST
PATCH 6/10 virtio-rng: switch to linux-headers
In reply to Michael S. TsirkinIt's easier to keep everything in sync if
we just use linux headers for virtio constants.
Add virtio_rng.h header from linux 3.10-rc1, and
remove duplicate symbols from virtio-rng.h
--- include/hw/virtio/virtio-rng.h | 5 ++--- linux-headers/linux/virtio_rng.h | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 linux-headers/linux/virtio_rng.h
include/hw/virtio/virtio-rng.h +2 -3
@@ -14,14 +14,13 @@#include "sysemu/rng.h" #include "sysemu/rng-random.h" +#include "linux/virtio_rng.h" +#include "linux/virtio_ids.h" #define TYPE_VIRTIO_RNG "virtio-rng-device"#define VIRTIO_RNG (obj) \ OBJECT_CHECK(VirtIORNG, (obj), TYPE_VIRTIO_RNG) -/* The Virtio ID for the virtio rng device */ -#define VIRTIO_ID_RNG 4 -struct VirtIORNGConf {RngBackend *rng;uint64_t max_bytes;
linux-headers/linux/virtio_rng.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef _LINUX_VIRTIO_RNG_H +#define _LINUX_VIRTIO_RNG_H +/* This header is BSD licensed so anyone can use the definitions to implement +* compatible drivers/servers. */ +#include <linux/virtio_ids.h> +#include <linux/virtio_config.h> + +#endif /* _LINUX_VIRTIO_RNG_H */
Signature · 1 line
MST
PATCH 7/10 virtio-console: switch to linux-headers
In reply to Michael S. TsirkinIt's easier to keep everything in sync if
we just use linux headers for virtio constants. Add virtio_console.h header from linux 3.10-rc1, and remove duplicate symbols from virtio-serial.h
--- include/hw/virtio/virtio-serial.h | 38 +----------------- linux-headers/linux/virtio_console.h | 74 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 37 deletions(-) create mode 100644 linux-headers/linux/virtio_console.h
include/hw/virtio/virtio-serial.h +1 -37
@@ -17,49 +17,13 @@#include "hw/qdev.h" #include "hw/virtio/virtio.h" - -/* == Interface shared between the guest kernel and qemu == */ - -/* The Virtio ID for virtio console / serial ports */ -#define VIRTIO_ID_CONSOLE 3 - -/* Features supported */ -#define VIRTIO_CONSOLE_F_MULTIPORT 1 - -#define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0) - -struct virtio_console_config { -/* -* These two fields are used by VIRTIO_CONSOLE_F_SIZE which -* isn't implemented here yet -*/ -uint16_t cols; -uint16_t rows; - -uint32_t max_nr_ports; -}QEMU_PACKED ; - -struct virtio_console_control { -uint32_t id;/* Port number */ -uint16_t event;/* The kind of control event (see below) */ -uint16_t value;/* Extra information for the key */ -}; +#include "linux/virtio_console.h" struct virtio_serial_conf {/* Max. number of ports we can have for a virtio-serial device */ uint32_t max_virtserial_ports; }; -/* Some events for the internal messages (control packets) */ -#define VIRTIO_CONSOLE_DEVICE_READY 0 -#define VIRTIO_CONSOLE_PORT_ADD 1 -#define VIRTIO_CONSOLE_PORT_REMOVE 2 -#define VIRTIO_CONSOLE_PORT_READY 3 -#define VIRTIO_CONSOLE_CONSOLE_PORT 4 -#define VIRTIO_CONSOLE_RESIZE 5 -#define VIRTIO_CONSOLE_PORT_OPEN 6 -#define VIRTIO_CONSOLE_PORT_NAME 7 -/* == In-qemu interface == */ #define TYPE_VIRTIO_SERIAL_PORT "virtio-serial-port"
linux-headers/linux/virtio_console.h new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
MST
PATCH 8/10 virtio: add virtio_ids from linux-headers
In reply to Michael S. TsirkinAll imported headers will use it.
--- linux-headers/linux/virtio_ids.h | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 linux-headers/linux/virtio_ids.h
linux-headers/linux/virtio_ids.h new file +43 -0
@@ -0,0 +1,43 @@ +#ifndef _LINUX_VIRTIO_IDS_H +#define _LINUX_VIRTIO_IDS_H +/* +* Virtio IDs +* +* This header is BSD licensed so anyone can use the definitions to implement +* compatible drivers/servers. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* 3. Neither the name of IBM nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. */ + +#define VIRTIO_ID_NET 1/* virtio net */ +#define VIRTIO_ID_BLOCK 2/* virtio block */ +#define VIRTIO_ID_CONSOLE 3/* virtio console */ +#define VIRTIO_ID_RNG 4/* virtio rng */ +#define VIRTIO_ID_BALLOON 5/* virtio balloon */ +#define VIRTIO_ID_RPMSG 7/* virtio remote processor messaging */ +#define VIRTIO_ID_SCSI 8/* virtio scsi */ +#define VIRTIO_ID_9P 9/* 9p virtio console */ +#define VIRTIO_ID_RPROC_SERIAL 11/* virtio remoteproc serial link */ +#define VIRTIO_ID_CAIF 12/* Virtio caif */ + +#endif /* _LINUX_VIRTIO_IDS_H */
Signature · 1 line
MST
PATCH 9/10 virtio-pci: switch to linux-headers
In reply to Michael S. TsirkinIt's easier to keep everything in sync if
we just use linux headers for virtio constants.
Add virtio_pci.h header from linux 3.10-rc1, and
remove duplicate symbols from virtio-pci.h
--- hw/virtio/virtio-pci.c | 49 +++----------------- linux-headers/linux/virtio_pci.h | 97 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 44 deletions(-) create mode 100644 linux-headers/linux/virtio_pci.h
hw/virtio/virtio-pci.c +5 -44
@@ -34,53 +34,14 @@#include "qemu/range.h" #include "hw/virtio/virtio-bus.h" #include "qapi/visitor.h" - -/* from Linux's linux/virtio_pci.h */ - -/* A 32-bit r/o bitmask of the features supported by the host */ -#define VIRTIO_PCI_HOST_FEATURES 0 - -/* A 32-bit r/w bitmask of features activated by the guest */ -#define VIRTIO_PCI_GUEST_FEATURES 4 - -/* A 32-bit r/w PFN for the currently selected queue */ -#define VIRTIO_PCI_QUEUE_PFN 8 - -/* A 16-bit r/o queue size for the currently selected queue */ -#define VIRTIO_PCI_QUEUE_NUM 12 - -/* A 16-bit r/w queue selector */ -#define VIRTIO_PCI_QUEUE_SEL 14 - -/* A 16-bit r/w queue notifier */ -#define VIRTIO_PCI_QUEUE_NOTIFY 16 - -/* An 8-bit device status register. */ -#define VIRTIO_PCI_STATUS 18 - -/* An 8-bit r/o interrupt status register. Reading the value will return the -* current contents of the ISR and will also clear it. This is effectively -* a read-and-acknowledge. */ -#define VIRTIO_PCI_ISR 19 - -/* MSI-X registers: only enabled if MSI-X is enabled. */ -/* A 16-bit vector for configuration changes. */ -#define VIRTIO_MSI_CONFIG_VECTOR 20 -/* A 16-bit vector for selected queue notifications. */ -#define VIRTIO_MSI_QUEUE_VECTOR 22 +#include "linux/virtio_pci.h" /* Config space size */ -#define VIRTIO_PCI_CONFIG_NOMSI 20 -#define VIRTIO_PCI_CONFIG_MSI 24 -#define VIRTIO_PCI_REGION_SIZE (dev) (msix_present(dev) ? \ - VIRTIO_PCI_CONFIG_MSI : \ - VIRTIO_PCI_CONFIG_NOMSI) +#define VIRTIO_PCI_REGION_SIZE (dev) VIRTIO_PCI_CONFIG_OFF(msix_present(dev))/* The remaining space is defined by each driver as the per-driver * configuration space */ -#define VIRTIO_PCI_CONFIG (dev) (msix_enabled(dev) ? \ - VIRTIO_PCI_CONFIG_MSI : \ - VIRTIO_PCI_CONFIG_NOMSI) +#define VIRTIO_PCI_CONFIG_SIZE (dev) VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev))/* How many bits to shift physical queue address written to QUEUE_PFN. * 12 is historical, and due to x86 page size. */
@@ -386,7 +347,7 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr, unsigned size) {VirtIOPCIProxy *proxy = opaque; -uint32_t config =VIRTIO_PCI_CONFIG (&proxy->pci_dev); +uint32_t config =VIRTIO_PCI_CONFIG_SIZE (&proxy->pci_dev);uint64_t val =0 ;if (addr < config) {return virtio_ioport_read (proxy, addr);
@@ -417,7 +378,7 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) {VirtIOPCIProxy *proxy = opaque; -uint32_t config =VIRTIO_PCI_CONFIG (&proxy->pci_dev); +uint32_t config =VIRTIO_PCI_CONFIG_SIZE (&proxy->pci_dev);if (addr < config) {virtio_ioport_write (proxy, addr, val);return ;
linux-headers/linux/virtio_pci.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
MST
PATCH 10/10 virtio: use ring structure from linux-headers
In reply to Michael S. TsirkinWe already have ring structure in virtio-ring.h for use by dataplane. Use it in virtio.h as well, renaming some conflicting functions.
--- hw/virtio/virtio.c | 23 +++++------------------ include/hw/virtio/virtio.h | 45 +++------------------------------------------ 2 files changed, 8 insertions(+), 60 deletions(-)
hw/virtio/virtio.c +5 -18
@@ -145,7 +145,7 @@ static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)return lduw_phys (pa); } -static inline uint16_t vring_used_event (VirtQueue *vq) +static inline uint16_t vring_used_event_idx (VirtQueue *vq) {return vring_avail_ring (vq, vq->vring.num); }
@@ -192,7 +192,7 @@ static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask)stw_phys (pa,lduw_phys (pa) & ~mask); } -static inline void vring_avail_event (VirtQueue *vq,uint16_t val) +static inline void vring_avail_event_idx (VirtQueue *vq,uint16_t val) {hwaddr pa;if (!vq->notification) {
@@ -206,7 +206,7 @@ void virtio_queue_set_notification(VirtQueue *vq, int enable) { vq->notification = enable;if (vq->vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { -vring_avail_event (vq,vring_avail_idx (vq)); +vring_avail_event_idx (vq,vring_avail_idx (vq)); }else if (enable) {vring_used_flags_unset_bit (vq,VRING_USED_F_NO_NOTIFY ); }else {
@@ -448,7 +448,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) i = head =virtqueue_get_head (vq, vq->last_avail_idx++);if (vq->vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { -vring_avail_event (vq,vring_avail_idx (vq)); +vring_avail_event_idx (vq,vring_avail_idx (vq)); }if (vring_desc_flags (desc_pa, i) &VRING_DESC_F_INDIRECT ) {
@@ -740,19 +740,6 @@ void virtio_irq(VirtQueue *vq)virtio_notify_vector (vq->vdev, vq->vector); } -/* Assuming a given event_idx value from the other size, if -* we have just incremented index from old to new_idx, -* should we trigger an event? */ -static inline int vring_need_event (uint16_t event,uint16_t new,uint16_t old) -{ -/* Note: Xen has similar logic for notification hold-off -* in include/xen/interface/io/ring.h with req_event and req_prod -* corresponding to event_idx + 1 and new respectively. -* Note also that req_event and req_prod in Xen start at 1, -* event indexes in virtio start at 0. */ -return (uint16_t )(new - event -1 ) < (uint16_t )(new - old); -} -static bool vring_notify (VirtIODevice *vdev,VirtQueue *vq) {uint16_t old, new;
@@ -773,7 +760,7 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq) vq->signalled_used_valid = true; old = vq->signalled_used; new = vq->signalled_used =vring_used_idx (vq); -return !v ||vring_need_event (vring_used_event (vq), new, old); +return !v ||vring_need_event (vring_used_event_idx (vq), new, old); }void virtio_notify (VirtIODevice *vdev,VirtQueue *vq)
include/hw/virtio/virtio.h +3 -42
53 lines not on this page · raw message
Signature · 1 line
MST
Quoted 6 lines · Michael S. Tsirkin
I'm working on adding new virtio layout to qemu. The job is complicated by the fact that qemu has its own copy of the virtio headers, sometimes with slightly different names and structure.
Import headers from linux instead.
Do the kernel guys guarantee that their headers will compile on all the platforms QEMU supports? [eg windows] (this isn't an issue for the current uses of linux-headers because we only use it for KVM support, and if KVM is enabled you're definitely on a Linux host.)
thanks
-- PMM
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Michael S. Tsirkin
I'm working on adding new virtio layout to qemu. The job is complicated by the fact that qemu has its own copy of the virtio headers, sometimes with slightly different names and structure.
Import headers from linux instead.
Quoted 8 lines
Do the kernel guys guarantee that their headers will compile on all the platforms QEMU supports? [eg windows] (this isn't an issue for the current uses of linux-headers because we only use it for KVM support, and if KVM is enabled you're definitely on a Linux host.)
thanks
-- PMM
No but at the moment there's nothing there besides harmless defines.
But it's not like we update these things automatically.
If/when things break, we can change update-headers to strip problematic stuff out of there.
Signature · 1 line
MST
Quoted 18 lines · Michael S. Tsirkin
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Michael S. Tsirkin
I'm working on adding new virtio layout to qemu. The job is complicated by the fact that qemu has its own copy of the virtio headers, sometimes with slightly different names and structure.
Import headers from linux instead.Quoted 8 lines
Do the kernel guys guarantee that their headers will compile on all the platforms QEMU supports? [eg windows] (this isn't an issue for the current uses of linux-headers because we only use it for KVM support, and if KVM is enabled you're definitely on a Linux host.)
thanks
-- PMM
Quoted 7 lines
No but at the moment there's nothing there besides harmless defines.
But it's not like we update these things automatically.
If/when things break, we can change update-headers to strip problematic stuff out of there.
Or so I thought but in practice there's a dependency on linux/types.h
However, that's pretty easy to address.
I can think of two ways:
- strip linux/types.h in update_headers
- add a stub linux/types.h for non linux platforms
Preferences?
Quoted 2 lines
Signature · 1 line
MST
Il 23/05/2013 17:32, Michael S. Tsirkin ha scritto:
Quoted 27 lines · Michael S. Tsirkin
Quoted 18 lines · Peter Maydell
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines
I'm working on adding new virtio layout to qemu. The job is complicated by the fact that qemu has its own copy of the virtio headers, sometimes with slightly different names and structure.
Import headers from linux instead.Quoted 8 lines
Do the kernel guys guarantee that their headers will compile on all the platforms QEMU supports? [eg windows] (this isn't an issue for the current uses of linux-headers because we only use it for KVM support, and if KVM is enabled you're definitely on a Linux host.)
thanks
-- PMMQuoted 7 lines
No but at the moment there's nothing there besides harmless defines.
But it's not like we update these things automatically.
If/when things break, we can change update-headers to strip problematic stuff out of there.
Quoted 6 lines
Or so I thought but in practice there's a dependency on
linux/types.h
However, that's pretty easy to address.
I can think of two ways:
- striplinux/types.hinupdate_headers
- add a stublinux/types.hfor non linux platforms
The latter, using stdint.h types, would be fine.
Paolo