diff options
author | KONRAD Frederic <fred.konrad@greensocs.com> | 2013-03-27 10:49:11 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2013-03-28 12:57:41 -0500 |
commit | e378e88dfc2dec2a60a856dd478a4edfbc88efd0 (patch) | |
tree | ea7d8382dd9b67919ebb4dc2de36893477bf8bbf /hw/virtio-pci.c | |
parent | 1ab461b534b34838d1b21c056ab37413f54fefa6 (diff) | |
download | qemu-e378e88dfc2dec2a60a856dd478a4edfbc88efd0.tar.gz qemu-e378e88dfc2dec2a60a856dd478a4edfbc88efd0.tar.bz2 qemu-e378e88dfc2dec2a60a856dd478a4edfbc88efd0.zip |
virtio-balloon-pci: switch to the new API.
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 <fred.konrad@greensocs.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Message-id: 1364377755-15508-3-git-send-email-fred.konrad@greensocs.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio-pci.c')
-rw-r--r-- | hw/virtio-pci.c | 111 |
1 files changed, 55 insertions, 56 deletions
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 736a9bf07d..fb20722eaa 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) |