From patchwork Mon Jan 7 18:40:46 2013 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: 210081 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 C46272C0090 for ; Tue, 8 Jan 2013 06:58:02 +1100 (EST) Received: from localhost ([::1]:50390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsHfN-0006JW-Dg for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 13:43:21 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsHeU-0005DR-Tg for qemu-devel@nongnu.org; Mon, 07 Jan 2013 13:42:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsHeT-0005vd-Fq for qemu-devel@nongnu.org; Mon, 07 Jan 2013 13:42:26 -0500 Received: from greensocs.com ([87.106.252.221]:52936 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsHeT-0005vX-6m for qemu-devel@nongnu.org; Mon, 07 Jan 2013 13:42:25 -0500 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id A79B5400091; Mon, 7 Jan 2013 18:42:24 +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 aJrYBWyyPIEb; Mon, 7 Jan 2013 19:42:19 +0100 (CET) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id A7A88439E33; Mon, 7 Jan 2013 19:42:14 +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 BC693439E3F; Mon, 7 Jan 2013 19:42:12 +0100 (CET) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org, aliguori@us.ibm.com Date: Mon, 7 Jan 2013 19:40:46 +0100 Message-Id: <1357584074-10852-34-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1357584074-10852-1-git-send-email-fred.konrad@greensocs.com> References: <1357584074-10852-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: kwolf@redhat.com, peter.maydell@linaro.org, e.voevodin@samsung.com, mst@redhat.com, mark.burton@greensocs.com, agraf@suse.de, amit.shah@redhat.com, aneesh.kumar@linux.vnet.ibm.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com, afaerber@suse.de, fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH 33/61] virtio-balloon : add the virtio-balloon 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 Create virtio-balloon which extends virtio-device, so it can be connected on virtio-bus. Signed-off-by: KONRAD Frederic --- hw/virtio-balloon.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++---- hw/virtio-balloon.h | 4 +++ hw/virtio-pci.c | 6 ++++ 3 files changed, 102 insertions(+), 7 deletions(-) diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 3ea1790..fc94e3e 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -27,6 +27,11 @@ #include #endif +#include "virtio-bus.h" + +/* + * Will be modified later in the serie. + */ static VirtIOBalloon *to_virtio_balloon(VirtIODevice *vdev) { return (VirtIOBalloon *)vdev; @@ -219,25 +224,45 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id) return 0; } -VirtIODevice *virtio_balloon_init(DeviceState *dev) +static VirtIODevice *virtio_balloon_common_init(DeviceState *dev, + VirtIOBalloon **ps) { - VirtIOBalloon *s; + VirtIOBalloon *s = *ps; int ret; - s = (VirtIOBalloon *)virtio_common_init("virtio-balloon", - VIRTIO_ID_BALLOON, - 8, sizeof(VirtIOBalloon)); - + /* + * We have two cases here : the old virtio-balloon-x device, and the + * refactored virtio-balloon. + * This will disappear later in the serie. + */ + int old_device = (s == NULL); + if (s == NULL) { + /* old virtio-balloon-pci or virtio-balloon-s390, no memory allocated */ + s = (VirtIOBalloon *)virtio_common_init("virtio-balloon", + VIRTIO_ID_BALLOON, + 8, sizeof(VirtIOBalloon)); + } else { + /* new API virtio-balloon. ( memory allocated by qdev ) */ + virtio_init(VIRTIO_DEVICE(s), "virtio-balloon", VIRTIO_ID_BALLOON, 8); + } + /* + * This will disappear later in the serie. + * We will use VirtioDeviceClass instead. + */ s->vdev.get_config = virtio_balloon_get_config; s->vdev.set_config = virtio_balloon_set_config; s->vdev.get_features = virtio_balloon_get_features; ret = qemu_add_balloon_handler(virtio_balloon_to_target, virtio_balloon_stat, s); - if (ret < 0) { + if ((ret < 0) && (old_device)) { virtio_cleanup(&s->vdev); return NULL; } + if (ret < 0) { + virtio_common_cleanup(VIRTIO_DEVICE(s)); + return NULL; + } s->ivq = virtio_add_queue(&s->vdev, 128, virtio_balloon_handle_output); s->dvq = virtio_add_queue(&s->vdev, 128, virtio_balloon_handle_output); @@ -252,6 +277,15 @@ VirtIODevice *virtio_balloon_init(DeviceState *dev) return &s->vdev; } +/* + * This two functions will be removed later in the serie. + */ +VirtIODevice *virtio_balloon_init(DeviceState *dev) +{ + VirtIOBalloon *s = NULL; + return virtio_balloon_common_init(dev, &s); +} + void virtio_balloon_exit(VirtIODevice *vdev) { VirtIOBalloon *s = DO_UPCAST(VirtIOBalloon, vdev, vdev); @@ -260,3 +294,54 @@ void virtio_balloon_exit(VirtIODevice *vdev) unregister_savevm(s->qdev, "virtio-balloon", s); virtio_cleanup(vdev); } + +static int virtio_balloon_device_init(VirtIODevice *vdev) +{ + DeviceState *qdev = DEVICE(vdev); + VirtIOBalloon *s = VIRTIO_BALLOON(vdev); + if (virtio_balloon_common_init(qdev, &s) == NULL) { + return -1; + } + return 0; +} + +static int virtio_balloon_device_exit(DeviceState *qdev) +{ + VirtIOBalloon *s = VIRTIO_BALLOON(qdev); + VirtIODevice *vdev = VIRTIO_DEVICE(qdev); + + qemu_remove_balloon_handler(s); + unregister_savevm(qdev, "virtio-balloon", s); + virtio_common_cleanup(vdev); + return 0; +} + +static Property virtio_balloon_properties[] = { + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_balloon_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + dc->exit = virtio_balloon_device_exit; + dc->props = virtio_balloon_properties; + vdc->init = virtio_balloon_device_init; + vdc->get_config = virtio_balloon_get_config; + vdc->set_config = virtio_balloon_set_config; + vdc->get_features = virtio_balloon_get_features; +} + +static const TypeInfo virtio_balloon_info = { + .name = TYPE_VIRTIO_BALLOON, + .parent = TYPE_VIRTIO_DEVICE, + .instance_size = sizeof(VirtIOBalloon), + .class_init = virtio_balloon_class_init, +}; + +static void virtio_register_types(void) +{ + type_register_static(&virtio_balloon_info); +} + +type_init(virtio_register_types) diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h index 0cd211e..c106026 100644 --- a/hw/virtio-balloon.h +++ b/hw/virtio-balloon.h @@ -18,6 +18,10 @@ #include "virtio.h" #include "pci/pci.h" +#define TYPE_VIRTIO_BALLOON "virtio-balloon" +#define VIRTIO_BALLOON(obj) \ + OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON) + /* from Linux's linux/virtio_balloon.h */ /* The ID for virtio_balloon */ diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index bbdb576..7c48eab 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -22,6 +22,7 @@ #include "virtio-net.h" #include "virtio-serial.h" #include "virtio-scsi.h" +#include "virtio-balloon.h" #include "pci/pci.h" #include "qemu/error-report.h" #include "pci/msi.h" @@ -1008,6 +1009,11 @@ static void virtio_pci_device_plugged(DeviceState *d) PCI_DEVICE_ID_VIRTIO_SCSI); pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI); break; + case VIRTIO_ID_BALLOON: + pci_config_set_device_id(proxy->pci_dev.config, + PCI_DEVICE_ID_VIRTIO_BALLOON); + pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_OTHERS); + break; default: error_report("unknown device id\n"); break;