Message ID | 20200628142429.17111-9-peter.maydell@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | spitz: fix hacks, fix CID 1421913, various cleanups | expand |
On 6/28/20 4:24 PM, Peter Maydell wrote: > Add an ssi_realize_and_unref(), for the benefit of callers > who want to be able to create an SSI device, set QOM properties > on it, and then do the realize-and-unref afterwards. > > The API works on the same principle as the recently added > qdev_realize_and_undef(), sysbus_realize_and_undef(), etc. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> > --- > include/hw/ssi/ssi.h | 26 ++++++++++++++++++++++++++ > hw/ssi/ssi.c | 7 ++++++- > 2 files changed, 32 insertions(+), 1 deletion(-) > > diff --git a/include/hw/ssi/ssi.h b/include/hw/ssi/ssi.h > index 93f2b8b0beb..4be5325e654 100644 > --- a/include/hw/ssi/ssi.h > +++ b/include/hw/ssi/ssi.h > @@ -79,6 +79,32 @@ extern const VMStateDescription vmstate_ssi_slave; > } > > DeviceState *ssi_create_slave(SSIBus *bus, const char *name); > +/** > + * ssi_realize_and_unref: realize and unref an SSI slave device > + * @dev: SSI slave device to realize > + * @bus: SSI bus to put it on > + * @errp: error pointer > + * > + * Call 'realize' on @dev, put it on the specified @bus, and drop the > + * reference to it. Errors are reported via @errp and by returning > + * false. > + * > + * This function is useful if you have created @dev via qdev_new() > + * (which takes a reference to the device it returns to you), so that > + * you can set properties on it before realizing it. If you don't need > + * to set properties then ssi_create_slave() is probably better (as it > + * does the create, init and realize in one step). > + * > + * If you are embedding the SSI slave into another QOM device and > + * initialized it via some variant on object_initialize_child() then > + * do not use this function, because that family of functions arrange > + * for the only reference to the child device to be held by the parent > + * via the child<> property, and so the reference-count-drop done here > + * would be incorrect. (Instead you would want ssi_realize(), which > + * doesn't currently exist but would be trivial to create if we had > + * any code that wanted it.) > + */ > +bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp); > > /* Master interface. */ > SSIBus *ssi_create_bus(DeviceState *parent, const char *name); > diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c > index 67b48c31cd6..a35d7ebb266 100644 > --- a/hw/ssi/ssi.c > +++ b/hw/ssi/ssi.c > @@ -90,11 +90,16 @@ static const TypeInfo ssi_slave_info = { > .abstract = true, > }; > > +bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp) > +{ > + return qdev_realize_and_unref(dev, &bus->parent_obj, errp); > +} > + > DeviceState *ssi_create_slave(SSIBus *bus, const char *name) > { > DeviceState *dev = qdev_new(name); > > - qdev_realize_and_unref(dev, &bus->parent_obj, &error_fatal); > + ssi_realize_and_unref(dev, bus, &error_fatal); > return dev; > } > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
On Sun, Jun 28, 2020 at 7:27 AM Peter Maydell <peter.maydell@linaro.org> wrote: > > Add an ssi_realize_and_unref(), for the benefit of callers > who want to be able to create an SSI device, set QOM properties > on it, and then do the realize-and-unref afterwards. > > The API works on the same principle as the recently added > qdev_realize_and_undef(), sysbus_realize_and_undef(), etc. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Alistair > --- > include/hw/ssi/ssi.h | 26 ++++++++++++++++++++++++++ > hw/ssi/ssi.c | 7 ++++++- > 2 files changed, 32 insertions(+), 1 deletion(-) > > diff --git a/include/hw/ssi/ssi.h b/include/hw/ssi/ssi.h > index 93f2b8b0beb..4be5325e654 100644 > --- a/include/hw/ssi/ssi.h > +++ b/include/hw/ssi/ssi.h > @@ -79,6 +79,32 @@ extern const VMStateDescription vmstate_ssi_slave; > } > > DeviceState *ssi_create_slave(SSIBus *bus, const char *name); > +/** > + * ssi_realize_and_unref: realize and unref an SSI slave device > + * @dev: SSI slave device to realize > + * @bus: SSI bus to put it on > + * @errp: error pointer > + * > + * Call 'realize' on @dev, put it on the specified @bus, and drop the > + * reference to it. Errors are reported via @errp and by returning > + * false. > + * > + * This function is useful if you have created @dev via qdev_new() > + * (which takes a reference to the device it returns to you), so that > + * you can set properties on it before realizing it. If you don't need > + * to set properties then ssi_create_slave() is probably better (as it > + * does the create, init and realize in one step). > + * > + * If you are embedding the SSI slave into another QOM device and > + * initialized it via some variant on object_initialize_child() then > + * do not use this function, because that family of functions arrange > + * for the only reference to the child device to be held by the parent > + * via the child<> property, and so the reference-count-drop done here > + * would be incorrect. (Instead you would want ssi_realize(), which > + * doesn't currently exist but would be trivial to create if we had > + * any code that wanted it.) > + */ > +bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp); > > /* Master interface. */ > SSIBus *ssi_create_bus(DeviceState *parent, const char *name); > diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c > index 67b48c31cd6..a35d7ebb266 100644 > --- a/hw/ssi/ssi.c > +++ b/hw/ssi/ssi.c > @@ -90,11 +90,16 @@ static const TypeInfo ssi_slave_info = { > .abstract = true, > }; > > +bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp) > +{ > + return qdev_realize_and_unref(dev, &bus->parent_obj, errp); > +} > + > DeviceState *ssi_create_slave(SSIBus *bus, const char *name) > { > DeviceState *dev = qdev_new(name); > > - qdev_realize_and_unref(dev, &bus->parent_obj, &error_fatal); > + ssi_realize_and_unref(dev, bus, &error_fatal); > return dev; > } > > -- > 2.20.1 > >
diff --git a/include/hw/ssi/ssi.h b/include/hw/ssi/ssi.h index 93f2b8b0beb..4be5325e654 100644 --- a/include/hw/ssi/ssi.h +++ b/include/hw/ssi/ssi.h @@ -79,6 +79,32 @@ extern const VMStateDescription vmstate_ssi_slave; } DeviceState *ssi_create_slave(SSIBus *bus, const char *name); +/** + * ssi_realize_and_unref: realize and unref an SSI slave device + * @dev: SSI slave device to realize + * @bus: SSI bus to put it on + * @errp: error pointer + * + * Call 'realize' on @dev, put it on the specified @bus, and drop the + * reference to it. Errors are reported via @errp and by returning + * false. + * + * This function is useful if you have created @dev via qdev_new() + * (which takes a reference to the device it returns to you), so that + * you can set properties on it before realizing it. If you don't need + * to set properties then ssi_create_slave() is probably better (as it + * does the create, init and realize in one step). + * + * If you are embedding the SSI slave into another QOM device and + * initialized it via some variant on object_initialize_child() then + * do not use this function, because that family of functions arrange + * for the only reference to the child device to be held by the parent + * via the child<> property, and so the reference-count-drop done here + * would be incorrect. (Instead you would want ssi_realize(), which + * doesn't currently exist but would be trivial to create if we had + * any code that wanted it.) + */ +bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp); /* Master interface. */ SSIBus *ssi_create_bus(DeviceState *parent, const char *name); diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c index 67b48c31cd6..a35d7ebb266 100644 --- a/hw/ssi/ssi.c +++ b/hw/ssi/ssi.c @@ -90,11 +90,16 @@ static const TypeInfo ssi_slave_info = { .abstract = true, }; +bool ssi_realize_and_unref(DeviceState *dev, SSIBus *bus, Error **errp) +{ + return qdev_realize_and_unref(dev, &bus->parent_obj, errp); +} + DeviceState *ssi_create_slave(SSIBus *bus, const char *name) { DeviceState *dev = qdev_new(name); - qdev_realize_and_unref(dev, &bus->parent_obj, &error_fatal); + ssi_realize_and_unref(dev, bus, &error_fatal); return dev; }
Add an ssi_realize_and_unref(), for the benefit of callers who want to be able to create an SSI device, set QOM properties on it, and then do the realize-and-unref afterwards. The API works on the same principle as the recently added qdev_realize_and_undef(), sysbus_realize_and_undef(), etc. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- include/hw/ssi/ssi.h | 26 ++++++++++++++++++++++++++ hw/ssi/ssi.c | 7 ++++++- 2 files changed, 32 insertions(+), 1 deletion(-) -- 2.20.1