Message ID | 20180116131555.14242-7-f4bug@amsat.org |
---|---|
State | Superseded, archived |
Headers | show |
Series | qdev: remove DeviceClass::init/exit() | expand |
On Tue, Jan 16, 2018 at 10:15:50AM -0300, Philippe Mathieu-Daudé wrote: [...] > +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); > + } > +} Why not just let the subclasses set DeviceClass::realize and DeviceClass::unrealize directly? > + > 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 > >
On 01/19/2018 03:03 PM, Eduardo Habkost wrote: > On Tue, Jan 16, 2018 at 10:15:50AM -0300, Philippe Mathieu-Daudé wrote: > [...] >> +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); >> + } >> +} > > Why not just let the subclasses set DeviceClass::realize and > DeviceClass::unrealize directly? yes, clever :) > >> + >> 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 >> >> >
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,
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> --- include/hw/sysbus.h | 4 ++++ hw/core/sysbus.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)