From patchwork Mon Mar 18 16:37:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: fred.konrad@greensocs.com X-Patchwork-Id: 228692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8DBDA2C009F for ; Tue, 19 Mar 2013 03:48:26 +1100 (EST) Received: from localhost ([::1]:49635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHdEW-00018q-Rc for incoming@patchwork.ozlabs.org; Mon, 18 Mar 2013 12:48:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHdEA-00018K-E8 for qemu-devel@nongnu.org; Mon, 18 Mar 2013 12:48:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UHd4E-0001gc-5T for qemu-devel@nongnu.org; Mon, 18 Mar 2013 12:37:54 -0400 Received: from greensocs.com ([87.106.252.221]:57955 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHd4D-0001gT-M1 for qemu-devel@nongnu.org; Mon, 18 Mar 2013 12:37:46 -0400 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id 8CD9C43EE3F; Mon, 18 Mar 2013 16:37:44 +0000 (UTC) Received: from s15328186.onlinehome-server.info ([127.0.0.1]) by localhost (s15328186.onlinehome-server.info [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DnpXs1zZPqdJ; Mon, 18 Mar 2013 17:37:42 +0100 (CET) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id DF9D943EE39; Mon, 18 Mar 2013 17:37:41 +0100 (CET) Received: from compaq.katmai.xl.cx.katmai.xl.cx (lan31-11-83-155-143-136.fbx.proxad.net [83.155.143.136]) by s15328186.onlinehome-server.info (Postfix) with ESMTPSA id A735643EE36; Mon, 18 Mar 2013 17:37:40 +0100 (CET) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org, aliguori@us.ibm.com Date: Mon, 18 Mar 2013 17:37:18 +0100 Message-Id: <1363624648-16906-2-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1363624648-16906-1-git-send-email-fred.konrad@greensocs.com> References: <1363624648-16906-1-git-send-email-fred.konrad@greensocs.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 87.106.252.221 Cc: Kevin Wolf , peter.maydell@linaro.org, mst@redhat.com, mark.burton@greensocs.com, Amit Shah , Stefan Hajnoczi , cornelia.huck@de.ibm.com, Paolo Bonzini , afaerber@suse.de, fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH v10 01/11] virtio: make virtio device's structures public. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: KONRAD Frederic These structures must be made public to avoid two memory allocations for refactored virtio devices. Signed-off-by: KONRAD Frederic Reviewed-by: Andreas Färber Reviewed-by: Peter Maydell Changes V4 <- V3: * Rebased on current git. Changes V3 <- V2: * Style correction spotted by Andreas (virtio-scsi.h). * Style correction for virtio-net.h. Changes V2 <- V1: * Move the dataplane include into the header (virtio-blk). --- hw/virtio-balloon.c | 15 --------------- hw/virtio-balloon.h | 14 ++++++++++++++ hw/virtio-blk.c | 20 -------------------- hw/virtio-blk.h | 19 +++++++++++++++++++ hw/virtio-net.c | 50 -------------------------------------------------- hw/virtio-net.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-rng.c | 19 ------------------- hw/virtio-rng.h | 19 +++++++++++++++++++ hw/virtio-scsi.c | 15 --------------- hw/virtio-scsi.h | 16 ++++++++++++++++ hw/virtio-serial-bus.c | 41 ----------------------------------------- hw/virtio-serial.h | 41 +++++++++++++++++++++++++++++++++++++++++ 12 files changed, 159 insertions(+), 160 deletions(-) diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 6bfcddc..54a4372 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -29,21 +29,6 @@ #include #endif -typedef struct VirtIOBalloon -{ - VirtIODevice vdev; - VirtQueue *ivq, *dvq, *svq; - uint32_t num_pages; - uint32_t actual; - uint64_t stats[VIRTIO_BALLOON_S_NR]; - VirtQueueElement stats_vq_elem; - size_t stats_vq_offset; - QEMUTimer *stats_timer; - int64_t stats_last_update; - int64_t stats_poll_interval; - DeviceState *qdev; -} VirtIOBalloon; - static VirtIOBalloon *to_virtio_balloon(VirtIODevice *vdev) { return (VirtIOBalloon *)vdev; diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h index f37f31b..b007042 100644 --- a/hw/virtio-balloon.h +++ b/hw/virtio-balloon.h @@ -52,4 +52,18 @@ typedef struct VirtIOBalloonStat { uint64_t val; } QEMU_PACKED VirtIOBalloonStat; +typedef struct VirtIOBalloon { + VirtIODevice vdev; + VirtQueue *ivq, *dvq, *svq; + uint32_t num_pages; + uint32_t actual; + uint64_t stats[VIRTIO_BALLOON_S_NR]; + VirtQueueElement stats_vq_elem; + size_t stats_vq_offset; + QEMUTimer *stats_timer; + int64_t stats_last_update; + int64_t stats_poll_interval; + DeviceState *qdev; +} VirtIOBalloon; + #endif diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 6b69236..6714b01 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -17,31 +17,11 @@ #include "hw/block-common.h" #include "sysemu/blockdev.h" #include "hw/virtio-blk.h" -#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE -#include "dataplane/virtio-blk.h" -#endif #include "hw/scsi-defs.h" #ifdef __linux__ # include #endif -typedef struct VirtIOBlock -{ - VirtIODevice vdev; - BlockDriverState *bs; - VirtQueue *vq; - void *rq; - QEMUBH *bh; - BlockConf *conf; - VirtIOBlkConf *blk; - unsigned short sector_mask; - DeviceState *qdev; - VMChangeStateEntry *change; -#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE - VirtIOBlockDataPlane *dataplane; -#endif -} VirtIOBlock; - static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) { return (VirtIOBlock *)vdev; diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h index 7ef2f35..19ec569 100644 --- a/hw/virtio-blk.h +++ b/hw/virtio-blk.h @@ -16,6 +16,9 @@ #include "hw/virtio.h" #include "hw/block-common.h" +#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE +#include "dataplane/virtio-blk.h" +#endif /* from Linux's linux/virtio_blk.h */ @@ -108,6 +111,22 @@ struct VirtIOBlkConf uint32_t data_plane; }; +typedef struct VirtIOBlock { + VirtIODevice vdev; + BlockDriverState *bs; + VirtQueue *vq; + void *rq; + QEMUBH *bh; + BlockConf *conf; + VirtIOBlkConf *blk; + unsigned short sector_mask; + DeviceState *qdev; + VMChangeStateEntry *change; +#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE + VirtIOBlockDataPlane *dataplane; +#endif +} VirtIOBlock; + #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \ DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 8c9d871..4bb49eb 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -26,56 +26,6 @@ #define MAC_TABLE_ENTRIES 64 #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */ -typedef struct VirtIONetQueue { - VirtQueue *rx_vq; - VirtQueue *tx_vq; - QEMUTimer *tx_timer; - QEMUBH *tx_bh; - int tx_waiting; - struct { - VirtQueueElement elem; - ssize_t len; - } async_tx; - struct VirtIONet *n; -} VirtIONetQueue; - -typedef struct VirtIONet -{ - VirtIODevice vdev; - uint8_t mac[ETH_ALEN]; - uint16_t status; - VirtIONetQueue *vqs; - VirtQueue *ctrl_vq; - NICState *nic; - uint32_t tx_timeout; - int32_t tx_burst; - uint32_t has_vnet_hdr; - size_t host_hdr_len; - size_t guest_hdr_len; - uint8_t has_ufo; - int mergeable_rx_bufs; - uint8_t promisc; - uint8_t allmulti; - uint8_t alluni; - uint8_t nomulti; - uint8_t nouni; - uint8_t nobcast; - uint8_t vhost_started; - struct { - int in_use; - int first_multi; - uint8_t multi_overflow; - uint8_t uni_overflow; - uint8_t *macs; - } mac_table; - uint32_t *vlans; - DeviceState *qdev; - int multiqueue; - uint16_t max_queues; - uint16_t curr_queues; - size_t config_size; -} VirtIONet; - /* * Calculate the number of bytes up to and including the given 'field' of * 'container'. diff --git a/hw/virtio-net.h b/hw/virtio-net.h index 0c83ca5..4d1a8cd 100644 --- a/hw/virtio-net.h +++ b/hw/virtio-net.h @@ -134,6 +134,56 @@ struct virtio_net_ctrl_mac { uint32_t entries; uint8_t macs[][ETH_ALEN]; }; + +typedef struct VirtIONetQueue { + VirtQueue *rx_vq; + VirtQueue *tx_vq; + QEMUTimer *tx_timer; + QEMUBH *tx_bh; + int tx_waiting; + struct { + VirtQueueElement elem; + ssize_t len; + } async_tx; + struct VirtIONet *n; +} VirtIONetQueue; + +typedef struct VirtIONet { + VirtIODevice vdev; + uint8_t mac[ETH_ALEN]; + uint16_t status; + VirtIONetQueue *vqs; + VirtQueue *ctrl_vq; + NICState *nic; + uint32_t tx_timeout; + int32_t tx_burst; + uint32_t has_vnet_hdr; + size_t host_hdr_len; + size_t guest_hdr_len; + uint8_t has_ufo; + int mergeable_rx_bufs; + uint8_t promisc; + uint8_t allmulti; + uint8_t alluni; + uint8_t nomulti; + uint8_t nouni; + uint8_t nobcast; + uint8_t vhost_started; + struct { + int in_use; + int first_multi; + uint8_t multi_overflow; + uint8_t uni_overflow; + uint8_t *macs; + } mac_table; + uint32_t *vlans; + DeviceState *qdev; + int multiqueue; + uint16_t max_queues; + uint16_t curr_queues; + size_t config_size; +} VirtIONet; + #define VIRTIO_NET_CTRL_MAC 1 #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c index 54c1421..fa8e8f3 100644 --- a/hw/virtio-rng.c +++ b/hw/virtio-rng.c @@ -16,25 +16,6 @@ #include "hw/virtio-rng.h" #include "qemu/rng.h" -typedef struct VirtIORNG { - VirtIODevice vdev; - - DeviceState *qdev; - - /* Only one vq - guest puts buffer(s) on it when it needs entropy */ - VirtQueue *vq; - - VirtIORNGConf *conf; - - RngBackend *rng; - - /* We purposefully don't migrate this state. The quota will reset on the - * destination as a result. Rate limiting is host state, not guest state. - */ - QEMUTimer *rate_limit_timer; - int64_t quota_remaining; -} VirtIORNG; - static bool is_guest_ready(VirtIORNG *vrng) { if (virtio_queue_ready(vrng->vq) diff --git a/hw/virtio-rng.h b/hw/virtio-rng.h index f42d748..3711c97 100644 --- a/hw/virtio-rng.h +++ b/hw/virtio-rng.h @@ -25,4 +25,23 @@ struct VirtIORNGConf { RndRandom *default_backend; }; +typedef struct VirtIORNG { + VirtIODevice vdev; + + DeviceState *qdev; + + /* Only one vq - guest puts buffer(s) on it when it needs entropy */ + VirtQueue *vq; + + VirtIORNGConf *conf; + + RngBackend *rng; + + /* We purposefully don't migrate this state. The quota will reset on the + * destination as a result. Rate limiting is host state, not guest state. + */ + QEMUTimer *rate_limit_timer; + int64_t quota_remaining; +} VirtIORNG; + #endif diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c index 72cc519..8620712 100644 --- a/hw/virtio-scsi.c +++ b/hw/virtio-scsi.c @@ -130,21 +130,6 @@ typedef struct { uint32_t max_lun; } QEMU_PACKED VirtIOSCSIConfig; -typedef struct { - VirtIODevice vdev; - DeviceState *qdev; - VirtIOSCSIConf *conf; - - SCSIBus bus; - uint32_t sense_size; - uint32_t cdb_size; - int resetting; - bool events_dropped; - VirtQueue *ctrl_vq; - VirtQueue *event_vq; - VirtQueue *cmd_vqs[0]; -} VirtIOSCSI; - typedef struct VirtIOSCSIReq { VirtIOSCSI *dev; VirtQueue *vq; diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h index 81b3279..ccf1e42 100644 --- a/hw/virtio-scsi.h +++ b/hw/virtio-scsi.h @@ -16,6 +16,7 @@ #include "hw/virtio.h" #include "hw/pci/pci.h" +#include "hw/scsi.h" /* The ID for virtio_scsi */ #define VIRTIO_ID_SCSI 8 @@ -31,6 +32,21 @@ struct VirtIOSCSIConf { uint32_t cmd_per_lun; }; +typedef struct VirtIOSCSI { + VirtIODevice vdev; + DeviceState *qdev; + VirtIOSCSIConf *conf; + + SCSIBus bus; + uint32_t sense_size; + uint32_t cdb_size; + int resetting; + bool events_dropped; + VirtQueue *ctrl_vq; + VirtQueue *event_vq; + VirtQueue *cmd_vqs[0]; +} VirtIOSCSI; + #define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _features_field, _conf_field) \ DEFINE_VIRTIO_COMMON_FEATURES(_state, _features_field), \ DEFINE_PROP_UINT32("num_queues", _state, _conf_field.num_queues, 1), \ diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 7d0515f..ab7168e 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -25,47 +25,6 @@ #include "trace.h" #include "hw/virtio-serial.h" -/* The virtio-serial bus on top of which the ports will ride as devices */ -struct VirtIOSerialBus { - BusState qbus; - - /* This is the parent device that provides the bus for ports. */ - VirtIOSerial *vser; - - /* The maximum number of ports that can ride on top of this bus */ - uint32_t max_nr_ports; -}; - -typedef struct VirtIOSerialPostLoad { - QEMUTimer *timer; - uint32_t nr_active_ports; - struct { - VirtIOSerialPort *port; - uint8_t host_connected; - } *connected; -} VirtIOSerialPostLoad; - -struct VirtIOSerial { - VirtIODevice vdev; - - VirtQueue *c_ivq, *c_ovq; - /* Arrays of ivqs and ovqs: one per port */ - VirtQueue **ivqs, **ovqs; - - VirtIOSerialBus bus; - - DeviceState *qdev; - - QTAILQ_HEAD(, VirtIOSerialPort) ports; - - /* bitmap for identifying active ports */ - uint32_t *ports_map; - - struct virtio_console_config config; - - struct VirtIOSerialPostLoad *post_load; -}; - static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id) { VirtIOSerialPort *port; diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h index d2d9fb7..484dcfe 100644 --- a/hw/virtio-serial.h +++ b/hw/virtio-serial.h @@ -173,6 +173,47 @@ struct VirtIOSerialPort { bool throttled; }; +/* The virtio-serial bus on top of which the ports will ride as devices */ +struct VirtIOSerialBus { + BusState qbus; + + /* This is the parent device that provides the bus for ports. */ + VirtIOSerial *vser; + + /* The maximum number of ports that can ride on top of this bus */ + uint32_t max_nr_ports; +}; + +typedef struct VirtIOSerialPostLoad { + QEMUTimer *timer; + uint32_t nr_active_ports; + struct { + VirtIOSerialPort *port; + uint8_t host_connected; + } *connected; +} VirtIOSerialPostLoad; + +struct VirtIOSerial { + VirtIODevice vdev; + + VirtQueue *c_ivq, *c_ovq; + /* Arrays of ivqs and ovqs: one per port */ + VirtQueue **ivqs, **ovqs; + + VirtIOSerialBus bus; + + DeviceState *qdev; + + QTAILQ_HEAD(, VirtIOSerialPort) ports; + + /* bitmap for identifying active ports */ + uint32_t *ports_map; + + struct virtio_console_config config; + + struct VirtIOSerialPostLoad *post_load; +}; + /* Interface to the virtio-serial bus */ /*