diff mbox

[03/22] qdev: make DeviceInfo private

Message ID 1328125863-6203-4-git-send-email-aliguori@us.ibm.com
State New
Headers show

Commit Message

Anthony Liguori Feb. 1, 2012, 7:50 p.m. UTC
Introduce accessors and remove any code that directly accesses DeviceInfo
members.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/pci.c             |   13 ++++++++-----
 hw/qdev-properties.c |    4 ++--
 hw/qdev.c            |   30 +++++++++++++++++++++++++++++-
 hw/qdev.h            |   24 +++++++++---------------
 4 files changed, 48 insertions(+), 23 deletions(-)
diff mbox

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 6a0b1f5..235ea00 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1673,6 +1673,7 @@  static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
     char *path;
     void *ptr;
     char name[32];
+    const VMStateDescription *vmsd;
 
     if (!pdev->romfile)
         return 0;
@@ -1709,10 +1710,13 @@  static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
         size = 1 << qemu_fls(size);
     }
 
-    if (qdev_get_info(&pdev->qdev)->vmsd)
-        snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->vmsd->name);
-    else
+    vmsd = qdev_get_vmsd(DEVICE(pdev));
+
+    if (vmsd) {
+        snprintf(name, sizeof(name), "%s.rom", vmsd->name);
+    } else {
         snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev)));
+    }
     pdev->has_rom = true;
     memory_region_init_ram(&pdev->rom, name, size);
     vmstate_register_ram(&pdev->rom, &pdev->qdev);
@@ -1953,8 +1957,7 @@  static int pci_qdev_find_recursive(PCIBus *bus,
     }
 
     /* roughly check if given qdev is pci device */
-    if (qdev_get_info(qdev)->init == &pci_qdev_init &&
-        qdev->parent_bus->info == &pci_bus_info) {
+    if (object_dynamic_cast(OBJECT(qdev), TYPE_PCI_DEVICE)) {
         *pdev = PCI_DEVICE(qdev);
         return 0;
     }
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index c98219a..724dce5 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -966,7 +966,7 @@  static Property *qdev_prop_find(DeviceState *dev, const char *name)
     Property *prop;
 
     /* device properties */
-    prop = qdev_prop_walk(qdev_get_info(dev)->props, name);
+    prop = qdev_prop_walk(qdev_get_props(dev), name);
     if (prop)
         return prop;
 
@@ -1166,7 +1166,7 @@  void qdev_prop_set_globals(DeviceState *dev)
 
     QTAILQ_FOREACH(prop, &global_props, next) {
         if (strcmp(object_get_typename(OBJECT(dev)), prop->driver) != 0 &&
-            strcmp(qdev_get_info(dev)->bus_info->name, prop->driver) != 0) {
+            strcmp(qdev_get_bus_info(dev)->name, prop->driver) != 0) {
             continue;
         }
         if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
diff --git a/hw/qdev.c b/hw/qdev.c
index a8c24de..18c5876 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -60,11 +60,39 @@  static void qdev_subclass_init(ObjectClass *klass, void *data)
     }
 }
 
-DeviceInfo *qdev_get_info(DeviceState *dev)
+static DeviceInfo *qdev_get_info(DeviceState *dev)
 {
     return DEVICE_GET_CLASS(dev)->info;
 }
 
+const VMStateDescription *qdev_get_vmsd(DeviceState *dev)
+{
+    return qdev_get_info(dev)->vmsd;
+}
+
+BusInfo *qdev_get_bus_info(DeviceState *dev)
+{
+    return qdev_get_info(dev)->bus_info;
+}
+
+Property *qdev_get_props(DeviceState *dev)
+{
+    return qdev_get_info(dev)->props;
+}
+
+const char *qdev_fw_name(DeviceState *dev)
+{
+    DeviceInfo *info = qdev_get_info(dev);
+
+    if (info->fw_name) {
+        return info->fw_name;
+    } else if (info->alias) {
+        return info->alias;
+    }
+
+    return object_get_typename(OBJECT(dev));
+}
+
 void qdev_register_subclass(DeviceInfo *info, const char *parent)
 {
     TypeInfo type_info = {};
diff --git a/hw/qdev.h b/hw/qdev.h
index c9572a5..dc6a6fe 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -398,22 +398,8 @@  void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
-DeviceInfo *qdev_get_info(DeviceState *dev);
-
-static inline const char *qdev_fw_name(DeviceState *dev)
-{
-    DeviceInfo *info = qdev_get_info(dev);
-
-    if (info->fw_name) {
-        return info->fw_name;
-    } else if (info->alias) {
-        return info->alias;
-    }
-
-    return object_get_typename(OBJECT(dev));
-}
-
 char *qdev_get_fw_dev_path(DeviceState *dev);
+
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 extern struct BusInfo system_bus_info;
 
@@ -661,4 +647,12 @@  void qdev_machine_init(void);
  */
 void device_reset(DeviceState *dev);
 
+const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
+
+const char *qdev_fw_name(DeviceState *dev);
+
+BusInfo *qdev_get_bus_info(DeviceState *dev);
+
+Property *qdev_get_props(DeviceState *dev);
+
 #endif