[RFC PATCH v2 040/137] hw/i3c: Give onboard devices a QOM parent

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
Convert the *_orphan() device-creation calls in hw/i3c to the new
parented API introduced earlier in this series, so every onboard
device gets a stable path in the composition tree instead of landing
in /machine/unattached with an unstable device[N] name.

The parent for each device is the object that owns its lifetime: the
machine for board-created devices, the containing device for
composite children.  Names follow existing QOM conventions.

Per-site rationale (reviewers: dispute the modeling here):

hw/i3c/core.c:550 | qdev_new | parent | id | public helper; thread Object *parent + const char *id through i3c_target_new() and its caller i3c_target_create_simple()
hw/i3c/core.c:626 | i2c_slave_new | parent | id | public helper; thread Object *parent + const char *id through legacy_i2c_device_create_simple()

Link: https://lore.kernel.org/qemu-devel/[email protected]/
AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/i3c/core.c        | 19 +++++++++++--------
 include/hw/i3c/i3c.h |  9 ++++++---
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/hw/i3c/core.c b/hw/i3c/core.c
index 469d66f1fb..23b32290e5 100644
--- a/hw/i3c/core.c
+++ b/hw/i3c/core.c
@@ -542,12 +542,13 @@ static bool i3c_addr_is_rsvd(uint8_t addr)
     return is_rsvd[addr];
 }
 
-I3CTarget *i3c_target_new(const char *name, uint8_t addr, uint8_t dcr,
+I3CTarget *i3c_target_new(Object *parent, const char *id,
+                          const char *name, uint8_t addr, uint8_t dcr,
                           uint8_t bcr, uint64_t pid)
 {
     DeviceState *dev;
 
-    dev = qdev_new_orphan(name);
+    dev = qdev_new(parent, id, name);
     qdev_prop_set_uint8(dev, "static-address", addr);
     qdev_prop_set_uint8(dev, "dcr", dcr);
     qdev_prop_set_uint8(dev, "bcr", bcr);
@@ -566,12 +567,13 @@ bool i3c_target_realize_and_unref(I3CTarget *dev, I3CBus *bus, Error **errp)
     return qdev_realize_and_unref(&dev->parent_obj, &bus->parent_obj, errp);
 }
 
-I3CTarget *i3c_target_create_simple(I3CBus *bus, const char *name, uint8_t addr,
+I3CTarget *i3c_target_create_simple(Object *parent, const char *id,
+                                    I3CBus *bus, const char *name, uint8_t addr,
                                     uint8_t dcr, uint8_t bcr, uint64_t pid)
 {
-    I3CTarget *dev = i3c_target_new(name, addr, dcr, bcr, pid);
+    I3CTarget *dev = i3c_target_new(parent, id, name, addr, dcr, bcr, pid);
     dev->address = 0;
-    i3c_target_realize_and_unref(dev, bus, &error_abort);
+    qdev_realize(DEVICE(dev), BUS(bus), &error_abort);
 
     return dev;
 }
@@ -620,12 +622,13 @@ void legacy_i2c_end_transfer(I3CBus *bus)
     i2c_end_transfer(bus->i2c_bus);
 }
 
-I2CSlave *legacy_i2c_device_create_simple(I3CBus *bus, const char *name,
+I2CSlave *legacy_i2c_device_create_simple(Object *parent, const char *id,
+                                          I3CBus *bus, const char *name,
                                           uint8_t addr)
 {
-    I2CSlave *dev = i2c_slave_new_orphan(name, addr);
+    I2CSlave *dev = i2c_slave_new(parent, id, name, addr);
 
-    i2c_slave_realize_and_unref(dev, bus->i2c_bus, &error_abort);
+    qdev_realize(DEVICE(dev), BUS(bus->i2c_bus), &error_abort);
     return dev;
 }
 
diff --git a/include/hw/i3c/i3c.h b/include/hw/i3c/i3c.h
index dcf8d9b143..d0edf7d8bd 100644
--- a/include/hw/i3c/i3c.h
+++ b/include/hw/i3c/i3c.h
@@ -257,7 +257,8 @@ int legacy_i2c_start_transfer(I3CBus *bus, uint8_t address, bool is_recv);
 int legacy_i2c_start_recv(I3CBus *bus, uint8_t address);
 int legacy_i2c_start_send(I3CBus *bus, uint8_t address);
 void legacy_i2c_end_transfer(I3CBus *bus);
-I2CSlave *legacy_i2c_device_create_simple(I3CBus *bus, const char *name,
+I2CSlave *legacy_i2c_device_create_simple(Object *parent, const char *id,
+                                          I3CBus *bus, const char *name,
                                           uint8_t addr);
 
 /**
@@ -265,7 +266,8 @@ I2CSlave *legacy_i2c_device_create_simple(I3CBus *bus, const char *name,
  *
  * The target returned from this function still needs to be realized.
  */
-I3CTarget *i3c_target_new(const char *name, uint8_t addr, uint8_t dcr,
+I3CTarget *i3c_target_new(Object *parent, const char *id,
+                          const char *name, uint8_t addr, uint8_t dcr,
                           uint8_t bcr, uint64_t pid);
 
 /**
@@ -274,7 +276,8 @@ I3CTarget *i3c_target_new(const char *name, uint8_t addr, uint8_t dcr,
  * Create the target, initialize it, put it on the specified I3C bus, and
  * realize it.
  */
-I3CTarget *i3c_target_create_simple(I3CBus *bus, const char *name,
+I3CTarget *i3c_target_create_simple(Object *parent, const char *id,
+                                    I3CBus *bus, const char *name,
                                     uint8_t addr, uint8_t dcr, uint8_t bcr,
                                     uint64_t pid);
 
-- 
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.