From patchwork Wed Mar 27 09:49:11 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: 231637 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 3D0722C00A7 for ; Wed, 27 Mar 2013 20:50:34 +1100 (EST) Received: from localhost ([::1]:52995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKn01-0005af-QU for incoming@patchwork.ozlabs.org; Wed, 27 Mar 2013 05:50:29 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKmzK-0005Op-FZ for qemu-devel@nongnu.org; Wed, 27 Mar 2013 05:49:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKmzI-0000vL-JO for qemu-devel@nongnu.org; Wed, 27 Mar 2013 05:49:46 -0400 Received: from greensocs.com ([87.106.252.221]:43077 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKmzI-0000vG-9i for qemu-devel@nongnu.org; Wed, 27 Mar 2013 05:49:44 -0400 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id ACD4643EE3F; Wed, 27 Mar 2013 09:49: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 8q3F6mQoJE8k; Wed, 27 Mar 2013 10:49:40 +0100 (CET) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id A072D43EE34; Wed, 27 Mar 2013 10:49:40 +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 E4E8143EE34; Wed, 27 Mar 2013 10:49:39 +0100 (CET) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org, aliguori@us.ibm.com Date: Wed, 27 Mar 2013 10:49:11 +0100 Message-Id: <1364377755-15508-3-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1364377755-15508-1-git-send-email-fred.konrad@greensocs.com> References: <1364377755-15508-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: cornelia.huck@de.ibm.com, peter.maydell@linaro.org, mark.burton@greensocs.com, fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH v3 2/6] virtio-balloon-pci: switch to the new API. 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 Here the virtio-balloon-pci is modified for the new API. The device virtio-balloon-pci extends virtio-pci. It creates and connects a virtio-balloon during the init. The properties are not changed. Signed-off-by: KONRAD Frederic --- hw/virtio-pci.c | 111 ++++++++++++++++++++++++++++---------------------------- hw/virtio-pci.h | 14 +++++++ 2 files changed, 69 insertions(+), 56 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 736a9bf..fb20722 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -22,6 +22,7 @@ #include "hw/virtio-net.h" #include "hw/virtio-serial.h" #include "hw/virtio-scsi.h" +#include "hw/virtio-balloon.h" #include "hw/pci/pci.h" #include "qemu/error-report.h" #include "hw/pci/msi.h" @@ -1000,33 +1001,6 @@ static void virtio_net_exit_pci(PCIDevice *pci_dev) virtio_exit_pci(pci_dev); } -static int virtio_balloon_init_pci(PCIDevice *pci_dev) -{ - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); - VirtIODevice *vdev; - - if (proxy->class_code != PCI_CLASS_OTHERS && - proxy->class_code != PCI_CLASS_MEMORY_RAM) { /* qemu < 1.1 */ - proxy->class_code = PCI_CLASS_OTHERS; - } - - vdev = virtio_balloon_init(&pci_dev->qdev); - if (!vdev) { - return -1; - } - virtio_init_pci(proxy, vdev); - return 0; -} - -static void virtio_balloon_exit_pci(PCIDevice *pci_dev) -{ - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); - - virtio_pci_stop_ioeventfd(proxy); - virtio_balloon_exit(proxy->vdev); - virtio_exit_pci(pci_dev); -} - static int virtio_rng_init_pci(PCIDevice *pci_dev) { VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); @@ -1127,34 +1101,6 @@ static const TypeInfo virtio_serial_info = { .class_init = virtio_serial_class_init, }; -static Property virtio_balloon_properties[] = { - DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features), - DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), - DEFINE_PROP_END_OF_LIST(), -}; - -static void virtio_balloon_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - - k->init = virtio_balloon_init_pci; - k->exit = virtio_balloon_exit_pci; - k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; - k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON; - k->revision = VIRTIO_PCI_ABI_VERSION; - k->class_id = PCI_CLASS_OTHERS; - dc->reset = virtio_pci_reset; - dc->props = virtio_balloon_properties; -} - -static const TypeInfo virtio_balloon_info = { - .name = "virtio-balloon-pci", - .parent = TYPE_PCI_DEVICE, - .instance_size = sizeof(VirtIOPCIProxy), - .class_init = virtio_balloon_class_init, -}; - static void virtio_rng_initfn(Object *obj) { PCIDevice *pci_dev = PCI_DEVICE(obj); @@ -1461,6 +1407,59 @@ static const TypeInfo virtio_scsi_pci_info = { .class_init = virtio_scsi_pci_class_init, }; +/* virtio-balloon-pci */ + +static Property virtio_balloon_pci_properties[] = { + DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features), + DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static int virtio_balloon_pci_init(VirtIOPCIProxy *vpci_dev) +{ + VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&dev->vdev); + + if (vpci_dev->class_code != PCI_CLASS_OTHERS && + vpci_dev->class_code != PCI_CLASS_MEMORY_RAM) { /* qemu < 1.1 */ + vpci_dev->class_code = PCI_CLASS_OTHERS; + } + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + if (qdev_init(vdev) < 0) { + return -1; + } + return 0; +} + +static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + k->init = virtio_balloon_pci_init; + dc->props = virtio_balloon_pci_properties; + pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON; + pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id = PCI_CLASS_OTHERS; +} + +static void virtio_balloon_pci_instance_init(Object *obj) +{ + VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj); + object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BALLOON); + object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL); +} + +static const TypeInfo virtio_balloon_pci_info = { + .name = TYPE_VIRTIO_BALLOON_PCI, + .parent = TYPE_VIRTIO_PCI, + .instance_size = sizeof(VirtIOBalloonPCI), + .instance_init = virtio_balloon_pci_instance_init, + .class_init = virtio_balloon_pci_class_init, +}; + /* virtio-pci-bus */ void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev) @@ -1501,7 +1500,6 @@ static void virtio_pci_register_types(void) { type_register_static(&virtio_net_info); type_register_static(&virtio_serial_info); - type_register_static(&virtio_balloon_info); type_register_static(&virtio_rng_info); type_register_static(&virtio_pci_bus_info); type_register_static(&virtio_pci_info); @@ -1510,6 +1508,7 @@ static void virtio_pci_register_types(void) #endif type_register_static(&virtio_blk_pci_info); type_register_static(&virtio_scsi_pci_info); + type_register_static(&virtio_balloon_pci_info); } type_init(virtio_pci_register_types) diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h index bfe7a8e..f99f2eb 100644 --- a/hw/virtio-pci.h +++ b/hw/virtio-pci.h @@ -21,12 +21,14 @@ #include "hw/virtio-rng.h" #include "hw/virtio-serial.h" #include "hw/virtio-scsi.h" +#include "hw/virtio-balloon.h" #include "hw/virtio-bus.h" #include "hw/9pfs/virtio-9p-device.h" typedef struct VirtIOPCIProxy VirtIOPCIProxy; typedef struct VirtIOBlkPCI VirtIOBlkPCI; typedef struct VirtIOSCSIPCI VirtIOSCSIPCI; +typedef struct VirtIOBalloonPCI VirtIOBalloonPCI; /* virtio-pci-bus */ @@ -116,6 +118,18 @@ struct VirtIOBlkPCI { VirtIOBlkConf blk; }; +/* + * virtio-balloon-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci" +#define VIRTIO_BALLOON_PCI(obj) \ + OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI) + +struct VirtIOBalloonPCI { + VirtIOPCIProxy parent_obj; + VirtIOBalloon vdev; +}; + void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev); void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);