[RFC PATCH v2 121/137] hw/core/reset: Give the root reset container and legacy shims a QOM path

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
The root ResettableContainer and the LegacyReset shim objects are
long-lived singletons held only by static pointers and refcounts.
Give them a canonical path in the composition tree so
qom-tree/qom-list can enumerate them and so device_set_realized()
can require a QOM parent for every object.

  /machine/reset-container                (ResettableContainer)
  /machine/reset-container/legacy-reset[N] (LegacyReset shims)

get_root_reset_container() is first reached from configure_accelerators()
or machine_run_board_init(), both of which run after qemu_create_machine(),
so qdev_get_machine() is available.  qemu_unregister_reset() switches
from object_unref() to object_unparent() to release the child<> ref.

AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/core/reset.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/hw/core/reset.c b/hw/core/reset.c
index e7230b49b7..34c1ab84d9 100644
--- a/hw/core/reset.c
+++ b/hw/core/reset.c
@@ -27,6 +27,7 @@
 #include "system/reset.h"
 #include "hw/core/resettable.h"
 #include "hw/core/resetcontainer.h"
+#include "hw/core/qdev.h"
 
 /*
  * Return a pointer to the singleton container that holds all the Resettable
@@ -38,7 +39,9 @@ static ResettableContainer *get_root_reset_container(void)
 
     if (!root_reset_container) {
         root_reset_container =
-            RESETTABLE_CONTAINER(object_new(TYPE_RESETTABLE_CONTAINER));
+            RESETTABLE_CONTAINER(object_new_child(qdev_get_machine(),
+                                          "reset-container",
+                                          TYPE_RESETTABLE_CONTAINER));
     }
     return root_reset_container;
 }
@@ -94,7 +97,8 @@ static void legacy_reset_class_init(ObjectClass *klass, const void *data)
 
 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
 {
-    Object *obj = object_new(TYPE_LEGACY_RESET);
+    Object *obj = object_new_child(OBJECT(get_root_reset_container()),
+                                   "legacy-reset[*]", TYPE_LEGACY_RESET);
     LegacyReset *lr = LEGACY_RESET(obj);
 
     lr->func = func;
@@ -104,7 +108,8 @@ void qemu_register_reset(QEMUResetHandler *func, void *opaque)
 
 void qemu_register_reset_nosnapshotload(QEMUResetHandler *func, void *opaque)
 {
-    Object *obj = object_new(TYPE_LEGACY_RESET);
+    Object *obj = object_new_child(OBJECT(get_root_reset_container()),
+                                   "legacy-reset[*]", TYPE_LEGACY_RESET);
     LegacyReset *lr = LEGACY_RESET(obj);
 
     lr->func = func;
@@ -156,7 +161,7 @@ void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
 
     if (obj) {
         qemu_unregister_resettable(obj);
-        object_unref(obj);
+        object_unparent(obj);
     }
 }
 
-- 
2.47.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.