[RFC PATCH 18/20] hw/virtio-balloon.c: Split virtio-balloon-pci device.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: KONRAD Frederic <fred.konrad@xxxxxxxxxxxxx>

Split the old virtio-balloon-pci device into virtio-pci and virtio-balloon. The old virtio-balloon-pci is removed from virtio-pci.c.

Signed-off-by: KONRAD Frederic <fred.konrad@xxxxxxxxxxxxx>
---
 hw/virtio-balloon.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.c     | 56 ----------------------------------------
 2 files changed, 74 insertions(+), 56 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index ed9e8b3..f6737e4 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -329,9 +329,83 @@ static TypeInfo virtio_balloon_info = {
     .class_init = virtio_balloon_class_init,
 };
 
+/**************** VirtIOBALLOON-PCI Device *******************/
+/* This device create virtio-pci and virtio-balloon device   */
+
+
+static int virtio_balloon_pcidev_init(DeviceState *dev)
+{
+    VirtIODevice *vdev;
+    VirtIOBaloonState *s = VIRTIO_BALLOON_FROM_QDEV(dev);
+    PCIBus *rootpcibus;
+    PCIDevice *vpcidev;
+
+    /* We have to create a new virtio-pci */
+    rootpcibus = pci_find_root_bus(0);
+    if (rootpcibus==NULL)
+    {
+      /* No PCI BUS ? */
+      return -1;
+    }
+
+    vpcidev = pci_create_simple(rootpcibus, -1, "virtio-pci");
+    if (vpcidev==NULL)
+    {
+      return -1;
+    }
+
+    /* Link Virtio BALLOON to Virtio PCI */
+    s->trl = virtio_find_transport_by_device_state(&(vpcidev->qdev));
+
+    vdev = virtio_balloon_init(dev);
+    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_balloon_pci_properties[] =
+{
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOBaloonState, host_features),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->init = virtio_balloon_pcidev_init;
+    dc->props = virtio_balloon_pci_properties;
+}
+
+static TypeInfo virtio_balloon_pci_info =
+{
+    .name = "virtio-balloon-pci",
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIOBaloonState),
+    .class_init = virtio_balloon_pci_class_init,
+};
+
+/*************************************************************/
+
 static void virtio_baloon_register_types(void)
 {
     type_register_static(&virtio_balloon_info);
+    type_register_static(&virtio_balloon_pci_info);
 }
 
 type_init(virtio_baloon_register_types)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 807f67f..b066f20 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -768,64 +768,8 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
     msix_uninit_exclusive_bar(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 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 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_pci_register_types(void)
 {
-    type_register_static(&virtio_balloon_info);
 }
 
 type_init(virtio_pci_register_types)
-- 
1.7.11.7

_______________________________________________
kvmarm mailing list
kvmarm@xxxxxxxxxxxxxxxxxxxxx
https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm


[Index of Archives]     [Linux KVM]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux