qdev: Simplify the SysBusDeviceClass::init path
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 Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20180419212727.26095-4-f4bug@amsat.org> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Removal of DeviceClass::init() moved into next patch, sysbus_realize() tweaked for clarity] Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20180528144509.15812-4-armbru@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
c8c9e10394
commit
dbfe00130e
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
#include "hw/sysbus.h"
|
#include "hw/sysbus.h"
|
||||||
#include "monitor/monitor.h"
|
#include "monitor/monitor.h"
|
||||||
#include "exec/address-spaces.h"
|
#include "exec/address-spaces.h"
|
||||||
@ -200,15 +201,18 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sysbus_device_init(DeviceState *dev)
|
/* TODO remove once all sysbus devices have been converted to realize */
|
||||||
|
static void sysbus_realize(DeviceState *dev, Error **errp)
|
||||||
{
|
{
|
||||||
SysBusDevice *sd = SYS_BUS_DEVICE(dev);
|
SysBusDevice *sd = SYS_BUS_DEVICE(dev);
|
||||||
SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
|
SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
|
||||||
|
|
||||||
if (!sbc->init) {
|
if (!sbc->init) {
|
||||||
return 0;
|
return;
|
||||||
|
}
|
||||||
|
if (sbc->init(sd) < 0) {
|
||||||
|
error_setg(errp, "Device initialization failed");
|
||||||
}
|
}
|
||||||
return sbc->init(sd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceState *sysbus_create_varargs(const char *name,
|
DeviceState *sysbus_create_varargs(const char *name,
|
||||||
@ -324,7 +328,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev)
|
|||||||
static void sysbus_device_class_init(ObjectClass *klass, void *data)
|
static void sysbus_device_class_init(ObjectClass *klass, void *data)
|
||||||
{
|
{
|
||||||
DeviceClass *k = DEVICE_CLASS(klass);
|
DeviceClass *k = DEVICE_CLASS(klass);
|
||||||
k->init = sysbus_device_init;
|
k->realize = sysbus_realize;
|
||||||
k->bus_type = TYPE_SYSTEM_BUS;
|
k->bus_type = TYPE_SYSTEM_BUS;
|
||||||
/*
|
/*
|
||||||
* device_add plugs devices into a suitable bus. For "real" buses,
|
* device_add plugs devices into a suitable bus. For "real" buses,
|
||||||
|
Loading…
Reference in New Issue
Block a user