Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/sysbus.h | 4 ++++
hw/core/sysbus.c | 23 +++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index e88bb6dae0..c87a6df29e 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -40,6 +40,10 @@ typedef struct SysBusDeviceClass {
DeviceClass parent_class;
/*< public >*/
+ void (*realize)(SysBusDevice *dev, Error **errp);
+ void (*unrealize)(SysBusDevice *dev, Error **errp);
+
+ /* TODO remove, once users are converted to realize */
int (*init)(SysBusDevice *dev);
/*
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 5d0887f499..04d6061f76 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -200,6 +200,7 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size)
}
}
+/* TODO remove, once users are converted to realize */
static int sysbus_device_init(DeviceState *dev)
{
SysBusDevice *sd = SYS_BUS_DEVICE(dev);
@@ -211,6 +212,26 @@ static int sysbus_device_init(DeviceState *dev)
return sbc->init(sd);
}
+static void sysbus_realize(DeviceState *dev, Error **errp)
+{
+ SysBusDevice *sd = SYS_BUS_DEVICE(dev);
+ SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
+
+ if (sbc->realize) {
+ sbc->realize(sd, errp);
+ }
+}
+
+static void sysbus_unrealize(DeviceState *dev, Error **errp)
+{
+ SysBusDevice *sd = SYS_BUS_DEVICE(dev);
+ SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
+
+ if (sbc->unrealize) {
+ sbc->unrealize(sd, errp);
+ }
+}
+
DeviceState *sysbus_create_varargs(const char *name,
hwaddr addr, ...)
{
@@ -325,6 +346,8 @@ static void sysbus_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
k->init = sysbus_device_init;
+ k->realize = sysbus_realize;
+ k->unrealize = sysbus_unrealize;
k->bus_type = TYPE_SYSTEM_BUS;
/*
* device_add plugs devices into a suitable bus. For "real" buses,
--
2.15.1