Patchwork [54/61] virtio-9p-pci : switch to the new API.

login
register
mail settings
Submitter fred.konrad@greensocs.com
Date Jan. 7, 2013, 6:41 p.m.
Message ID <1357584074-10852-55-git-send-email-fred.konrad@greensocs.com>
Download mbox | patch
Permalink /patch/210052/
State New
Headers show

Comments

fred.konrad@greensocs.com - Jan. 7, 2013, 6:41 p.m.
From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-9p-pci is modified for the new API. The device
virtio-9p-pci extends virtio-pci. It creates and connects a virtio-9p
during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/9pfs/virtio-9p-device.c | 48 +++++++++++++++++++++++++---------------------
 hw/9pfs/virtio-9p.h        | 14 ++++++++++++++
 hw/virtio-pci.h            |  3 ---
 3 files changed, 40 insertions(+), 25 deletions(-)

Patch

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 8a88739..7e4b239 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -164,45 +164,49 @@  VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
     return virtio_9p_common_init(dev, conf, &s);
 }
 
-static int virtio_9p_init_pci(PCIDevice *pci_dev)
+static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev)
 {
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
-    vdev->nvectors = proxy->nvectors;
-    virtio_init_pci(proxy, vdev);
-    /* make the actual value visible */
-    proxy->nvectors = vdev->nvectors;
+    V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+
+    virtio_9p_set_conf(vdev, &(dev->fsconf));
+    qdev_set_parent_bus(vdev, BUS(vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
     return 0;
 }
 
 static Property virtio_9p_pci_properties[] = {
-    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
     DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_VIRTIO_9P_PROPERTIES(VirtIOPCIProxy, fsconf),
+    DEFINE_VIRTIO_9P_PROPERTIES(V9fsPCIState, fsconf),
     DEFINE_PROP_END_OF_LIST(),
 };
 
 static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
 
     k->init = virtio_9p_init_pci;
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = 0x1009;
-    k->revision = VIRTIO_PCI_ABI_VERSION;
-    k->class_id = 0x2;
     dc->props = virtio_9p_pci_properties;
-    dc->reset = virtio_pci_reset;
 }
 
-static TypeInfo virtio_9p_info = {
-    .name          = "virtio-9p-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
+static void virtio_9p_pci_instance_init(Object *obj)
+{
+    V9fsPCIState *dev = VIRTIO_9P_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_9P);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static TypeInfo virtio_9p_pci_info = {
+    .name          = TYPE_VIRTIO_9P_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(V9fsPCIState),
+    .instance_init = virtio_9p_pci_instance_init,
     .class_init    = virtio_9p_pci_class_init,
 };
 
@@ -244,7 +248,7 @@  static const TypeInfo virtio_device_info = {
 static void virtio_9p_register_types(void)
 {
     type_register_static(&virtio_device_info);
-    type_register_static(&virtio_9p_info);
+    type_register_static(&virtio_9p_pci_info);
     virtio_9p_set_fd_limit();
 }
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 3be634f..9b342dc 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -11,6 +11,7 @@ 
 #include "fsdev/virtio-9p-marshal.h"
 #include "qemu/thread.h"
 #include "block/coroutine.h"
+#include "hw/virtio-pci.h"
 
 
 /* The feature bitmap for virtio 9P */
@@ -413,4 +414,17 @@  extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
 
 void virtio_9p_set_conf(DeviceState *dev, V9fsConf *conf);
 
+/*
+ * virtio-9p-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
+#define VIRTIO_9P_PCI(obj) \
+        OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
+
+typedef struct V9fsPCIState {
+    VirtIOPCIProxy parent_obj;
+    V9fsState vdev;
+    V9fsConf fsconf;
+} V9fsPCIState;
+
 #endif
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 98b51d8..e251d93 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -76,9 +76,6 @@  struct VirtIOPCIProxy {
     uint32_t class_code;
     uint32_t nvectors;
     uint32_t host_features;
-#ifdef CONFIG_LINUX
-    V9fsConf fsconf;
-#endif
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;