Patchwork [RFC,08/13] qdev-core: isolate reset register/unregister code

login
register
mail settings
Submitter Eduardo Habkost
Date Oct. 4, 2012, 7:15 p.m.
Message ID <1349378133-25644-9-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/189307/
State New
Headers show

Comments

Eduardo Habkost - Oct. 4, 2012, 7:15 p.m.
The reset register/unregister code is specific to qemu-system-*, so
isolate it so it can be moved to qdev-system.c.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/qdev-core.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

Patch

diff --git a/hw/qdev-core.c b/hw/qdev-core.c
index a5cac45..1b45e51 100644
--- a/hw/qdev-core.c
+++ b/hw/qdev-core.c
@@ -47,6 +47,21 @@  void GCC_WEAK qdev_finalize_vmstate(DeviceState *dev)
 {
 }
 
+static void qbus_register_reset(BusState *bus)
+{
+    if (bus != sysbus_get_default()) {
+        /* TODO: once all bus devices are qdevified,
+           only reset handler for main_system_bus should be registered here. */
+        qemu_register_reset(qbus_reset_all_fn, bus);
+    }
+}
+
+static void qbus_unregister_reset(BusState *bus)
+{
+    assert(bus != sysbus_get_default()); /* main_system_bus is never freed */
+    qemu_unregister_reset(qbus_reset_all_fn, bus);
+}
+
 const char *qdev_fw_name(DeviceState *dev)
 {
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
@@ -348,10 +363,8 @@  static void qbus_realize(BusState *bus)
         QLIST_INSERT_HEAD(&bus->parent->child_bus, bus, sibling);
         bus->parent->num_child_bus++;
         object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(bus), NULL);
-    } else if (bus != sysbus_get_default()) {
-        /* TODO: once all bus devices are qdevified,
-           only reset handler for main_system_bus should be registered here. */
-        qemu_register_reset(qbus_reset_all_fn, bus);
+    } else {
+        qbus_register_reset(bus);
     }
 }
 
@@ -685,8 +698,7 @@  static void qbus_finalize(Object *obj)
         QLIST_REMOVE(bus, sibling);
         bus->parent->num_child_bus--;
     } else {
-        assert(bus != sysbus_get_default()); /* main_system_bus is never freed */
-        qemu_unregister_reset(qbus_reset_all_fn, bus);
+        qbus_unregister_reset(bus);
     }
     g_free((char *)bus->name);
 }