mirror of https://github.com/xqemu/xqemu.git
qdev: Prepare realize/unrealize hooks for BusState
Add a "realized" property calling realize/unrealize hooks as for devices. Signed-off-by: Bandan Das <bsd@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
04e9a20b49
commit
02e7f85dac
|
@ -501,6 +501,45 @@ static void bus_unparent(Object *obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool bus_get_realized(Object *obj, Error **err)
|
||||||
|
{
|
||||||
|
BusState *bus = BUS(obj);
|
||||||
|
|
||||||
|
return bus->realized;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void bus_set_realized(Object *obj, bool value, Error **err)
|
||||||
|
{
|
||||||
|
BusState *bus = BUS(obj);
|
||||||
|
BusClass *bc = BUS_GET_CLASS(bus);
|
||||||
|
Error *local_err = NULL;
|
||||||
|
|
||||||
|
if (value && !bus->realized) {
|
||||||
|
if (bc->realize) {
|
||||||
|
bc->realize(bus, &local_err);
|
||||||
|
|
||||||
|
if (local_err != NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (!value && bus->realized) {
|
||||||
|
if (bc->unrealize) {
|
||||||
|
bc->unrealize(bus, &local_err);
|
||||||
|
|
||||||
|
if (local_err != NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bus->realized = value;
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
error_propagate(err, local_err);
|
||||||
|
}
|
||||||
|
|
||||||
void qbus_create_inplace(void *bus, size_t size, const char *typename,
|
void qbus_create_inplace(void *bus, size_t size, const char *typename,
|
||||||
DeviceState *parent, const char *name)
|
DeviceState *parent, const char *name)
|
||||||
{
|
{
|
||||||
|
@ -889,6 +928,8 @@ static void qbus_initfn(Object *obj)
|
||||||
object_property_add_link(obj, QDEV_HOTPLUG_HANDLER_PROPERTY,
|
object_property_add_link(obj, QDEV_HOTPLUG_HANDLER_PROPERTY,
|
||||||
TYPE_HOTPLUG_HANDLER,
|
TYPE_HOTPLUG_HANDLER,
|
||||||
(Object **)&bus->hotplug_handler, NULL);
|
(Object **)&bus->hotplug_handler, NULL);
|
||||||
|
object_property_add_bool(obj, "realized",
|
||||||
|
bus_get_realized, bus_set_realized, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *default_bus_get_fw_dev_path(DeviceState *dev)
|
static char *default_bus_get_fw_dev_path(DeviceState *dev)
|
||||||
|
|
|
@ -36,6 +36,8 @@ typedef int (*qdev_event)(DeviceState *dev);
|
||||||
typedef void (*qdev_resetfn)(DeviceState *dev);
|
typedef void (*qdev_resetfn)(DeviceState *dev);
|
||||||
typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
|
typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
|
||||||
typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
|
typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
|
||||||
|
typedef void (*BusRealize)(BusState *bus, Error **errp);
|
||||||
|
typedef void (*BusUnrealize)(BusState *bus, Error **errp);
|
||||||
|
|
||||||
struct VMStateDescription;
|
struct VMStateDescription;
|
||||||
|
|
||||||
|
@ -174,6 +176,9 @@ struct BusClass {
|
||||||
*/
|
*/
|
||||||
char *(*get_fw_dev_path)(DeviceState *dev);
|
char *(*get_fw_dev_path)(DeviceState *dev);
|
||||||
void (*reset)(BusState *bus);
|
void (*reset)(BusState *bus);
|
||||||
|
BusRealize realize;
|
||||||
|
BusUnrealize unrealize;
|
||||||
|
|
||||||
/* maximum devices allowed on the bus, 0: no limit. */
|
/* maximum devices allowed on the bus, 0: no limit. */
|
||||||
int max_dev;
|
int max_dev;
|
||||||
/* number of automatically allocated bus ids (e.g. ide.0) */
|
/* number of automatically allocated bus ids (e.g. ide.0) */
|
||||||
|
@ -199,6 +204,7 @@ struct BusState {
|
||||||
int allow_hotplug;
|
int allow_hotplug;
|
||||||
HotplugHandler *hotplug_handler;
|
HotplugHandler *hotplug_handler;
|
||||||
int max_index;
|
int max_index;
|
||||||
|
bool realized;
|
||||||
QTAILQ_HEAD(ChildrenHead, BusChild) children;
|
QTAILQ_HEAD(ChildrenHead, BusChild) children;
|
||||||
QLIST_ENTRY(BusState) sibling;
|
QLIST_ENTRY(BusState) sibling;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue