From patchwork Mon Sep 17 10:00:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Voevodin X-Patchwork-Id: 184368 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 A3CA92C0086 for ; Mon, 17 Sep 2012 20:28:04 +1000 (EST) Received: from localhost ([::1]:35984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDY9P-0007zf-Hp for incoming@patchwork.ozlabs.org; Mon, 17 Sep 2012 06:01:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDY8Z-0006Sr-Tu for qemu-devel@nongnu.org; Mon, 17 Sep 2012 06:01:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TDY8Q-00053C-2O for qemu-devel@nongnu.org; Mon, 17 Sep 2012 06:01:07 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:35110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDY8P-00052u-Rz for qemu-devel@nongnu.org; Mon, 17 Sep 2012 06:00:57 -0400 Received: from eusync3.samsung.com (mailout3.w1.samsung.com [210.118.77.13]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MAH00EA6NUF0B80@mailout3.w1.samsung.com> for qemu-devel@nongnu.org; Mon, 17 Sep 2012 11:01:27 +0100 (BST) Received: from evvoevodinPC.rnd.samsung.ru ([106.109.8.14]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0MAH00DV7NT8FQ90@eusync3.samsung.com> for qemu-devel@nongnu.org; Mon, 17 Sep 2012 11:00:56 +0100 (BST) From: Evgeny Voevodin To: qemu-devel@nongnu.org Date: Mon, 17 Sep 2012 14:00:40 +0400 Message-id: <1347876042-22609-11-git-send-email-e.voevodin@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1347876042-22609-1-git-send-email-e.voevodin@samsung.com> References: <1347876042-22609-1-git-send-email-e.voevodin@samsung.com> X-TM-AS-MML: No X-detected-operating-system: by eggs.gnu.org: Solaris 10 (1203?) X-Received-From: 210.118.77.13 Cc: peter.maydell@linaro.org, kyungmin.park@samsung.com, aliguori@us.ibm.com, Evgeny Voevodin Subject: [Qemu-devel] [RFC v2 10/12] hw/virtio-blk.c: Add 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 Signed-off-by: Evgeny Voevodin --- hw/virtio-blk.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-blk.h | 15 +++++++++++++ 2 files changed, 80 insertions(+) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 6f6d172..0a23352 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -16,6 +16,8 @@ #include "trace.h" #include "hw/block-common.h" #include "blockdev.h" +#include "virtio-transport.h" +#include "virtio-pci.h" #include "virtio-blk.h" #include "scsi-defs.h" #ifdef __linux__ @@ -665,3 +667,66 @@ void virtio_blk_exit(VirtIODevice *vdev) blockdev_mark_auto_del(s->bs); virtio_cleanup(vdev); } + +/******************** VirtIOBlk Device **********************/ + +static int virtio_blkdev_init(DeviceState *dev) +{ + VirtIODevice *vdev; + VirtIOBlockState *s = VIRTIO_BLK_FROM_QDEV(dev); + + assert(s->trl != NULL); + + vdev = virtio_blk_init(dev, &s->blk); + if (!vdev) { + return -1; + } + + /* Pass default host_features to transport */ + s->trl->host_features = s->host_features; + + if (virtio_call_backend_init_cb(dev, s->trl, vdev) != 0) { + return -1; + } + + /* Binding should be ready here, let's get final features */ + if (vdev->binding->get_features) { + s->host_features = vdev->binding->get_features(vdev->binding_opaque); + } + return 0; +} + +static Property virtio_blkdev_properties[] = { + DEFINE_BLOCK_PROPERTIES(VirtIOBlockState, blk.conf), + DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlockState, blk.conf), + DEFINE_PROP_STRING("serial", VirtIOBlockState, blk.serial), +#ifdef __linux__ + DEFINE_PROP_BIT("scsi", VirtIOBlockState, blk.scsi, 0, true), +#endif + DEFINE_PROP_BIT("config-wce", VirtIOBlockState, blk.config_wce, 0, true), + DEFINE_VIRTIO_BLK_FEATURES(VirtIOBlockState, host_features), + + DEFINE_PROP_TRANSPORT("transport", VirtIOBlockState, trl), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_blkdev_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + dc->init = virtio_blkdev_init; + dc->props = virtio_blkdev_properties; +} + +static TypeInfo virtio_blkdev_info = { + .name = "virtio-blk", + .parent = TYPE_DEVICE, + .instance_size = sizeof(VirtIOBlockState), + .class_init = virtio_blkdev_class_init, +}; + +static void virtio_blk_register_types(void) +{ + type_register_static(&virtio_blkdev_info); +} + +type_init(virtio_blk_register_types) diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h index f0740d0..0886818 100644 --- a/hw/virtio-blk.h +++ b/hw/virtio-blk.h @@ -14,7 +14,9 @@ #ifndef _QEMU_VIRTIO_BLK_H #define _QEMU_VIRTIO_BLK_H +#include "sysbus.h" #include "virtio.h" +#include "virtio-transport.h" #include "hw/block-common.h" /* from Linux's linux/virtio_blk.h */ @@ -111,4 +113,17 @@ struct VirtIOBlkConf DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \ DEFINE_PROP_BIT("config-wce", _state, _field, VIRTIO_BLK_F_CONFIG_WCE, true) + +typedef struct { + DeviceState qdev; + /* virtio-blk */ + VirtIOBlkConf blk; + + uint32_t host_features; + + VirtIOTransportLink *trl; +} VirtIOBlockState; + +#define VIRTIO_BLK_FROM_QDEV(dev) DO_UPCAST(VirtIOBlockState, qdev, dev) + #endif