@@ -245,32 +245,37 @@ static void milkymist_softusb_reset(DeviceState *d)
s->regs[R_CTRL] = CTRL_RESET;
}
-static int milkymist_softusb_init(SysBusDevice *dev)
+static void milkymist_softusb_init(Object *obj)
{
+ SysBusDevice *dev = SYS_BUS_DEVICE(obj);
MilkymistSoftUsbState *s = MILKYMIST_SOFTUSB(dev);
sysbus_init_irq(dev, &s->irq);
- memory_region_init_io(&s->regs_region, OBJECT(s), &softusb_mmio_ops, s,
+ memory_region_init_io(&s->regs_region, obj, &softusb_mmio_ops, s,
"milkymist-softusb", R_MAX * 4);
sysbus_init_mmio(dev, &s->regs_region);
+}
+
+static void milkymist_softusb_realize(DeviceState *dev, Error **errp)
+{
+ MilkymistSoftUsbState *s = MILKYMIST_SOFTUSB(dev);
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
/* register pmem and dmem */
memory_region_init_ram(&s->pmem, OBJECT(s), "milkymist-softusb.pmem",
s->pmem_size, &error_fatal);
vmstate_register_ram_global(&s->pmem);
s->pmem_ptr = memory_region_get_ram_ptr(&s->pmem);
- sysbus_init_mmio(dev, &s->pmem);
+ sysbus_init_mmio(sbd, &s->pmem);
memory_region_init_ram(&s->dmem, OBJECT(s), "milkymist-softusb.dmem",
s->dmem_size, &error_fatal);
vmstate_register_ram_global(&s->dmem);
s->dmem_ptr = memory_region_get_ram_ptr(&s->dmem);
- sysbus_init_mmio(dev, &s->dmem);
+ sysbus_init_mmio(sbd, &s->dmem);
hid_init(&s->hid_kbd, HID_KEYBOARD, softusb_kbd_hid_datain);
hid_init(&s->hid_mouse, HID_MOUSE, softusb_mouse_hid_datain);
-
- return 0;
}
static const VMStateDescription vmstate_milkymist_softusb = {
@@ -296,9 +301,8 @@ static Property milkymist_softusb_properties[] = {
static void milkymist_softusb_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
- k->init = milkymist_softusb_init;
+ dc->realize = milkymist_softusb_realize;
dc->reset = milkymist_softusb_reset;
dc->vmsd = &vmstate_milkymist_softusb;
dc->props = milkymist_softusb_properties;
@@ -308,6 +312,7 @@ static const TypeInfo milkymist_softusb_info = {
.name = TYPE_MILKYMIST_SOFTUSB,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(MilkymistSoftUsbState),
+ .instance_init = milkymist_softusb_init,
.class_init = milkymist_softusb_class_init,
};
split the old SysBus init function into an instance_init and Device realize function Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com> --- hw/input/milkymist-softusb.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)