Message ID | 20180419212727.26095-4-f4bug@amsat.org |
---|---|
State | New |
Headers | show |
Series | qdev: remove DeviceClass::init/exit() | expand |
On 04/19/2018 06:27 PM, Philippe Mathieu-Daudé wrote: > The SysBusDevice is the last DeviceClass::init user. > > Instead of using > SysBusDeviceClass::realize > -> DeviceClass::realize > -> DeviceClass::init > -> sysbus_device_init > -> SysBusDeviceClass::init > > Simplify the path by directly calling SysBusDeviceClass::init > in SysBusDeviceClass::realize: > > SysBusDeviceClass::realize > -> SysBusDeviceClass::init > > Finally, remove the DeviceClass::init, there are no more users. > > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > include/hw/qdev-core.h | 2 -- > hw/core/qdev.c | 14 -------------- > hw/core/sysbus.c | 15 ++++++++++----- > 3 files changed, 10 insertions(+), 21 deletions(-) > > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h > index 9453588160..6f60748043 100644 > --- a/include/hw/qdev-core.h > +++ b/include/hw/qdev-core.h > @@ -29,7 +29,6 @@ typedef enum DeviceCategory { > DEVICE_CATEGORY_MAX > } DeviceCategory; > > -typedef int (*qdev_initfn)(DeviceState *dev); > typedef int (*qdev_event)(DeviceState *dev); > typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); > typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); > @@ -124,7 +123,6 @@ typedef struct DeviceClass { > const struct VMStateDescription *vmsd; > > /* Private to qdev / bus. */ > - qdev_initfn init; /* TODO remove, once users are converted to realize */ The DeviceClass documentation (top of this file) is now out of date :( If the maintainer taking this series prefer a respin, I plan to only remove the 'init' references in the big comment. > qdev_event exit; /* TODO remove, once users are converted to unrealize */ > const char *bus_type; > } DeviceClass; > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index f6f92473b8..4153b733c8 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -208,19 +208,6 @@ void device_listener_unregister(DeviceListener *listener) > QTAILQ_REMOVE(&device_listeners, listener, link); > } > > -static void device_realize(DeviceState *dev, Error **errp) > -{ > - DeviceClass *dc = DEVICE_GET_CLASS(dev); > - > - if (dc->init) { > - int rc = dc->init(dev); > - if (rc < 0) { > - error_setg(errp, "Device initialization failed."); > - return; > - } > - } > -} > - > static void device_unrealize(DeviceState *dev, Error **errp) > { > DeviceClass *dc = DEVICE_GET_CLASS(dev); > @@ -1065,7 +1052,6 @@ static void device_class_init(ObjectClass *class, void *data) > DeviceClass *dc = DEVICE_CLASS(class); > > class->unparent = device_unparent; > - dc->realize = device_realize; > dc->unrealize = device_unrealize; > > /* by default all devices were considered as hotpluggable, > diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c > index 5d0887f499..11f6d14b84 100644 > --- a/hw/core/sysbus.c > +++ b/hw/core/sysbus.c > @@ -18,6 +18,7 @@ > */ > > #include "qemu/osdep.h" > +#include "qapi/error.h" > #include "hw/sysbus.h" > #include "monitor/monitor.h" > #include "exec/address-spaces.h" > @@ -200,15 +201,19 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size) > } > } > > -static int sysbus_device_init(DeviceState *dev) > +static void sysbus_realize(DeviceState *dev, Error **errp) > { > SysBusDevice *sd = SYS_BUS_DEVICE(dev); > SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd); > > - if (!sbc->init) { > - return 0; > + /* TODO remove, once users are converted to realize */ > + if (sbc->init) { > + int rc = sbc->init(sd); > + if (rc < 0) { > + error_setg(errp, "Device initialization failed."); > + return; > + } > } > - return sbc->init(sd); > } > > DeviceState *sysbus_create_varargs(const char *name, > @@ -324,7 +329,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev) > 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->bus_type = TYPE_SYSTEM_BUS; > /* > * device_add plugs devices into a suitable bus. For "real" buses, >
Philippe Mathieu-Daudé <f4bug@amsat.org> writes: > On 04/19/2018 06:27 PM, Philippe Mathieu-Daudé wrote: >> The SysBusDevice is the last DeviceClass::init user. >> >> Instead of using >> SysBusDeviceClass::realize >> -> DeviceClass::realize >> -> DeviceClass::init >> -> sysbus_device_init >> -> SysBusDeviceClass::init >> >> Simplify the path by directly calling SysBusDeviceClass::init >> in SysBusDeviceClass::realize: >> >> SysBusDeviceClass::realize >> -> SysBusDeviceClass::init >> >> Finally, remove the DeviceClass::init, there are no more users. >> >> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> >> --- >> include/hw/qdev-core.h | 2 -- >> hw/core/qdev.c | 14 -------------- >> hw/core/sysbus.c | 15 ++++++++++----- >> 3 files changed, 10 insertions(+), 21 deletions(-) >> >> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h >> index 9453588160..6f60748043 100644 >> --- a/include/hw/qdev-core.h >> +++ b/include/hw/qdev-core.h >> @@ -29,7 +29,6 @@ typedef enum DeviceCategory { >> DEVICE_CATEGORY_MAX >> } DeviceCategory; >> >> -typedef int (*qdev_initfn)(DeviceState *dev); >> typedef int (*qdev_event)(DeviceState *dev); >> typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); >> typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); >> @@ -124,7 +123,6 @@ typedef struct DeviceClass { >> const struct VMStateDescription *vmsd; >> >> /* Private to qdev / bus. */ >> - qdev_initfn init; /* TODO remove, once users are converted to realize */ > > The DeviceClass documentation (top of this file) is now out of date :( > > If the maintainer taking this series prefer a respin, I plan to only > remove the 'init' references in the big comment. I'd move the actual removal into the next and final patch. Lets us fix up the comment in one go. >> qdev_event exit; /* TODO remove, once users are converted to unrealize */ >> const char *bus_type; >> } DeviceClass; [...]
On 04/20/2018 12:27 AM, Philippe Mathieu-Daudé wrote: > The SysBusDevice is the last DeviceClass::init user. > > Instead of using > SysBusDeviceClass::realize > -> DeviceClass::realize > -> DeviceClass::init > -> sysbus_device_init > -> SysBusDeviceClass::init > > Simplify the path by directly calling SysBusDeviceClass::init > in SysBusDeviceClass::realize: > > SysBusDeviceClass::realize > -> SysBusDeviceClass::init > > Finally, remove the DeviceClass::init, there are no more users. > > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > include/hw/qdev-core.h | 2 -- > hw/core/qdev.c | 14 -------------- > hw/core/sysbus.c | 15 ++++++++++----- > 3 files changed, 10 insertions(+), 21 deletions(-) > > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h > index 9453588160..6f60748043 100644 > --- a/include/hw/qdev-core.h > +++ b/include/hw/qdev-core.h > @@ -29,7 +29,6 @@ typedef enum DeviceCategory { > DEVICE_CATEGORY_MAX > } DeviceCategory; > > -typedef int (*qdev_initfn)(DeviceState *dev); > typedef int (*qdev_event)(DeviceState *dev); > typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); > typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); > @@ -124,7 +123,6 @@ typedef struct DeviceClass { > const struct VMStateDescription *vmsd; > > /* Private to qdev / bus. */ > - qdev_initfn init; /* TODO remove, once users are converted to realize */ > qdev_event exit; /* TODO remove, once users are converted to unrealize */ > const char *bus_type; > } DeviceClass; > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index f6f92473b8..4153b733c8 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -208,19 +208,6 @@ void device_listener_unregister(DeviceListener *listener) > QTAILQ_REMOVE(&device_listeners, listener, link); > } > > -static void device_realize(DeviceState *dev, Error **errp) > -{ > - DeviceClass *dc = DEVICE_GET_CLASS(dev); > - > - if (dc->init) { > - int rc = dc->init(dev); > - if (rc < 0) { > - error_setg(errp, "Device initialization failed."); > - return; > - } > - } > -} > - > static void device_unrealize(DeviceState *dev, Error **errp) > { > DeviceClass *dc = DEVICE_GET_CLASS(dev); > @@ -1065,7 +1052,6 @@ static void device_class_init(ObjectClass *class, void *data) > DeviceClass *dc = DEVICE_CLASS(class); > > class->unparent = device_unparent; > - dc->realize = device_realize; > dc->unrealize = device_unrealize; > > /* by default all devices were considered as hotpluggable, > diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c > index 5d0887f499..11f6d14b84 100644 > --- a/hw/core/sysbus.c > +++ b/hw/core/sysbus.c > @@ -18,6 +18,7 @@ > */ > > #include "qemu/osdep.h" > +#include "qapi/error.h" > #include "hw/sysbus.h" > #include "monitor/monitor.h" > #include "exec/address-spaces.h" > @@ -200,15 +201,19 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size) > } > } > > -static int sysbus_device_init(DeviceState *dev) > +static void sysbus_realize(DeviceState *dev, Error **errp) > { > SysBusDevice *sd = SYS_BUS_DEVICE(dev); > SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd); > > - if (!sbc->init) { > - return 0; Hello Philippe, is the purpose of this part to enable incremental conversion init->realize to SysBusDevices ?! Thanks, Yoni > + /* TODO remove, once users are converted to realize */ > + if (sbc->init) { > + int rc = sbc->init(sd); > + if (rc < 0) { > + error_setg(errp, "Device initialization failed."); > + return; > + } > } > - return sbc->init(sd); > } > > DeviceState *sysbus_create_varargs(const char *name, > @@ -324,7 +329,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev) > 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->bus_type = TYPE_SYSTEM_BUS; > /* > * device_add plugs devices into a suitable bus. For "real" buses,
On Fri, Apr 20, 2018 at 09:22:55AM +0200, Markus Armbruster wrote: > Philippe Mathieu-Daudé <f4bug@amsat.org> writes: > > > On 04/19/2018 06:27 PM, Philippe Mathieu-Daudé wrote: > >> The SysBusDevice is the last DeviceClass::init user. > >> > >> Instead of using > >> SysBusDeviceClass::realize > >> -> DeviceClass::realize > >> -> DeviceClass::init > >> -> sysbus_device_init > >> -> SysBusDeviceClass::init > >> > >> Simplify the path by directly calling SysBusDeviceClass::init > >> in SysBusDeviceClass::realize: > >> > >> SysBusDeviceClass::realize > >> -> SysBusDeviceClass::init > >> > >> Finally, remove the DeviceClass::init, there are no more users. > >> > >> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > >> --- > >> include/hw/qdev-core.h | 2 -- > >> hw/core/qdev.c | 14 -------------- > >> hw/core/sysbus.c | 15 ++++++++++----- > >> 3 files changed, 10 insertions(+), 21 deletions(-) > >> > >> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h > >> index 9453588160..6f60748043 100644 > >> --- a/include/hw/qdev-core.h > >> +++ b/include/hw/qdev-core.h > >> @@ -29,7 +29,6 @@ typedef enum DeviceCategory { > >> DEVICE_CATEGORY_MAX > >> } DeviceCategory; > >> > >> -typedef int (*qdev_initfn)(DeviceState *dev); > >> typedef int (*qdev_event)(DeviceState *dev); > >> typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); > >> typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); > >> @@ -124,7 +123,6 @@ typedef struct DeviceClass { > >> const struct VMStateDescription *vmsd; > >> > >> /* Private to qdev / bus. */ > >> - qdev_initfn init; /* TODO remove, once users are converted to realize */ > > > > The DeviceClass documentation (top of this file) is now out of date :( > > > > If the maintainer taking this series prefer a respin, I plan to only > > remove the 'init' references in the big comment. > > I'd move the actual removal into the next and final patch. Lets us fix > up the comment in one go. I'd prefer a respin, so we can ensure the documentation is updated and the removal of DeviceClass::init and DeviceClass::exit are done in the same patch. (Sorry for taking so long to reply.)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 9453588160..6f60748043 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -29,7 +29,6 @@ typedef enum DeviceCategory { DEVICE_CATEGORY_MAX } DeviceCategory; -typedef int (*qdev_initfn)(DeviceState *dev); typedef int (*qdev_event)(DeviceState *dev); typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); @@ -124,7 +123,6 @@ typedef struct DeviceClass { const struct VMStateDescription *vmsd; /* Private to qdev / bus. */ - qdev_initfn init; /* TODO remove, once users are converted to realize */ qdev_event exit; /* TODO remove, once users are converted to unrealize */ const char *bus_type; } DeviceClass; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f6f92473b8..4153b733c8 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -208,19 +208,6 @@ void device_listener_unregister(DeviceListener *listener) QTAILQ_REMOVE(&device_listeners, listener, link); } -static void device_realize(DeviceState *dev, Error **errp) -{ - DeviceClass *dc = DEVICE_GET_CLASS(dev); - - if (dc->init) { - int rc = dc->init(dev); - if (rc < 0) { - error_setg(errp, "Device initialization failed."); - return; - } - } -} - static void device_unrealize(DeviceState *dev, Error **errp) { DeviceClass *dc = DEVICE_GET_CLASS(dev); @@ -1065,7 +1052,6 @@ static void device_class_init(ObjectClass *class, void *data) DeviceClass *dc = DEVICE_CLASS(class); class->unparent = device_unparent; - dc->realize = device_realize; dc->unrealize = device_unrealize; /* by default all devices were considered as hotpluggable, diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index 5d0887f499..11f6d14b84 100644 --- a/hw/core/sysbus.c +++ b/hw/core/sysbus.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/sysbus.h" #include "monitor/monitor.h" #include "exec/address-spaces.h" @@ -200,15 +201,19 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size) } } -static int sysbus_device_init(DeviceState *dev) +static void sysbus_realize(DeviceState *dev, Error **errp) { SysBusDevice *sd = SYS_BUS_DEVICE(dev); SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd); - if (!sbc->init) { - return 0; + /* TODO remove, once users are converted to realize */ + if (sbc->init) { + int rc = sbc->init(sd); + if (rc < 0) { + error_setg(errp, "Device initialization failed."); + return; + } } - return sbc->init(sd); } DeviceState *sysbus_create_varargs(const char *name, @@ -324,7 +329,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev) 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->bus_type = TYPE_SYSTEM_BUS; /* * device_add plugs devices into a suitable bus. For "real" buses,
The SysBusDevice is the last DeviceClass::init user. Instead of using SysBusDeviceClass::realize -> DeviceClass::realize -> DeviceClass::init -> sysbus_device_init -> SysBusDeviceClass::init Simplify the path by directly calling SysBusDeviceClass::init in SysBusDeviceClass::realize: SysBusDeviceClass::realize -> SysBusDeviceClass::init Finally, remove the DeviceClass::init, there are no more users. Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> --- include/hw/qdev-core.h | 2 -- hw/core/qdev.c | 14 -------------- hw/core/sysbus.c | 15 ++++++++++----- 3 files changed, 10 insertions(+), 21 deletions(-)