From patchwork Thu Nov 22 14:50:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fred.konrad@greensocs.com X-Patchwork-Id: 201063 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 26CD02C00A8 for ; Fri, 23 Nov 2012 02:17:04 +1100 (EST) Received: from localhost ([::1]:48427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbY8x-0005tx-18 for incoming@patchwork.ozlabs.org; Thu, 22 Nov 2012 09:52:43 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbY8E-0004rz-MN for qemu-devel@nongnu.org; Thu, 22 Nov 2012 09:52:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbY85-0007Vr-41 for qemu-devel@nongnu.org; Thu, 22 Nov 2012 09:51:58 -0500 Received: from greensocs.com ([87.106.252.221]:35676 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbY84-0007UF-Pr for qemu-devel@nongnu.org; Thu, 22 Nov 2012 09:51:49 -0500 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id 6017440F4C9; Thu, 22 Nov 2012 14:51:43 +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 lrmaVPc3fr+W; Thu, 22 Nov 2012 15:51:37 +0100 (CET) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id F2D1040F4C8; Thu, 22 Nov 2012 15:51:36 +0100 (CET) Received: from compaq.katmai.xl.cx.katmai.xl.cx (bon31-2-82-224-104-128.fbx.proxad.net [82.224.104.128]) by s15328186.onlinehome-server.info (Postfix) with ESMTPSA id 115B440F4C8; Thu, 22 Nov 2012 15:51:36 +0100 (CET) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2012 15:50:52 +0100 Message-Id: <1353595852-30776-4-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1353595852-30776-1-git-send-email-fred.konrad@greensocs.com> References: <1353595852-30776-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 87.106.252.221 Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, e.voevodin@samsung.com, mark.burton@greensocs.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, afaerber@suse.de, fred.konrad@greensocs.com Subject: [Qemu-devel] [RFC PATCH v2 3/3] virtio-blk : add the virtio-blk device. 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 This patch just add the virtio-blk device which can connect on a Virtio-Bus. The initialization fail if no free VirtioBus are present. Signed-off-by: KONRAD Frederic --- hw/virtio-blk.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-blk.h | 10 +++++++ 2 files changed, 92 insertions(+) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index e25cc96..d8263c3 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -17,6 +17,8 @@ #include "hw/block-common.h" #include "blockdev.h" #include "virtio-blk.h" +#include "virtio-bus.h" +#include "hw/pci.h" /* for PCI IDs */ #include "scsi-defs.h" #ifdef __linux__ # include @@ -656,3 +658,83 @@ void virtio_blk_exit(VirtIODevice *vdev) blockdev_mark_auto_del(s->bs); virtio_cleanup(vdev); } + +static int virtio_blk_qdev_init(DeviceState *qdev) +{ + VirtIOBLKState *s = VIRTIO_BLK(qdev); + /* + * When the 'bus=' option is not set, the default bus is the last created. + * This is a problem because only one VirtIODevice can be plugged. + */ + VirtioBus *bus = VIRTIO_BUS(qdev_get_parent_bus(qdev)); + + /* init the device. */ + VirtIODevice *vdev = virtio_blk_init(qdev, &s->blk); + if (!vdev) { + return -1; + } + + /* Plug the device */ + if (virtio_bus_plug_device(bus, vdev) != 0) { + /* this can happen when the bus is not free */ + return -1; + } + + return 0; +} + +static int virtio_blk_qdev_exit(DeviceState *qdev) +{ + VirtioBus *bus = DO_UPCAST(VirtioBus, qbus, qdev->parent_bus); + virtio_bus_exit_cb(bus); + virtio_blk_exit(bus->vdev); + return 0; +} + +static Property virtio_blk_properties[] = { + DEFINE_BLOCK_PROPERTIES(VirtIOBLKState, blk.conf), + DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBLKState, blk.conf), + DEFINE_PROP_STRING("serial", VirtIOBLKState, blk.serial), +#ifdef __linux__ + DEFINE_PROP_BIT("scsi", VirtIOBLKState, blk.scsi, 0, true), +#endif + DEFINE_PROP_BIT("config-wce", VirtIOBLKState, blk.config_wce, 0, true), + /* + * Theses one are PCI related. + * DEFINE_PROP_BIT("ioeventfd", VirtIOBLKState, flags, + * VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), + * DEFINE_PROP_UINT32("vectors", VirtIOBLKState, nvectors, 2), + */ + DEFINE_VIRTIO_BLK_FEATURES(VirtIOBLKState, host_features), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_blk_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *k = DEVICE_CLASS(klass); + k->bus_type = TYPE_VIRTIO_BUS; + k->init = virtio_blk_qdev_init; + k->exit = virtio_blk_qdev_exit; + /* + * k->unplug = ? + */ + k->props = virtio_blk_properties; +} + +static TypeInfo virtio_blk_info = { + .name = "virtio-blk", + .parent = TYPE_DEVICE, + .instance_size = sizeof(VirtIOBLKState), + /* + * .abstract = true, + * .class_size = sizeof(?), + */ + .class_init = virtio_blk_class_init, +}; + +static void virtio_blk_register_types(void) +{ + type_register_static(&virtio_blk_info); +} + +type_init(virtio_blk_register_types) diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h index f0740d0..cb2ea8c 100644 --- a/hw/virtio-blk.h +++ b/hw/virtio-blk.h @@ -16,6 +16,7 @@ #include "virtio.h" #include "hw/block-common.h" +#include "virtio-bus.h" /* from Linux's linux/virtio_blk.h */ @@ -107,6 +108,15 @@ struct VirtIOBlkConf uint32_t config_wce; }; +typedef struct { + DeviceState qdev; + uint32_t host_features; + VirtIOBlkConf blk; +} VirtIOBLKState; + +#define TYPE_VIRTIO_BLK "virtio-blk" +#define VIRTIO_BLK(obj) OBJECT_CHECK(VirtIOBLKState, (obj), TYPE_VIRTIO_BLK) + #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \ DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \ DEFINE_PROP_BIT("config-wce", _state, _field, VIRTIO_BLK_F_CONFIG_WCE, true)