Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
qdev: Add a bus child add/remove handler
Add a way for a bus to detect when something is added or
removed from it.  This way the I2C mux can know when to
add itself to the master bus.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
  • Loading branch information
cminyard committed Apr 5, 2021
1 parent 2f6c7c3 commit c7f696d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hw/core/qdev.c
Expand Up @@ -757,6 +757,10 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
}
}

if (dev->parent_bus && dev->parent_bus->child_added) {
dev->parent_bus->child_added(dev->parent_bus, dev);
}

if (dc->realize) {
dc->realize(dev, &local_err);
if (local_err != NULL) {
Expand Down Expand Up @@ -849,6 +853,9 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
if (dc->unrealize) {
dc->unrealize(dev);
}
if (dev->parent_bus && dev->parent_bus->child_removed) {
dev->parent_bus->child_removed(dev->parent_bus, dev);
}
dev->pending_deleted_event = true;
DEVICE_LISTENER_CALL(unrealize, Reverse, dev);
}
Expand Down
2 changes: 2 additions & 0 deletions include/hw/qdev-core.h
Expand Up @@ -274,6 +274,8 @@ struct BusState {
QTAILQ_HEAD(, BusChild) children;
QLIST_ENTRY(BusState) sibling;
ResettableState reset;
void (*child_added)(BusState *bus, DeviceState *child);
void (*child_removed)(BusState *bus, DeviceState *child);
};

/**
Expand Down

0 comments on commit c7f696d

Please sign in to comment.