diff options
Diffstat (limited to 'hw')
47 files changed, 538 insertions, 394 deletions
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c index fc20857f45..6a7d377fd9 100644 --- a/hw/audio/adlib.c +++ b/hw/audio/adlib.c @@ -283,21 +283,21 @@ static void Adlib_fini (AdlibState *s) AUD_remove_card (&s->card); } -static int Adlib_initfn (ISADevice *dev) +static void adlib_realizefn (DeviceState *dev, Error **errp) { AdlibState *s = ADLIB(dev); struct audsettings as; if (glob_adlib) { - dolog ("Cannot create more than 1 adlib device\n"); - return -1; + error_setg (errp, "Cannot create more than 1 adlib device"); + return; } glob_adlib = s; #ifdef HAS_YMF262 if (YMF262Init (1, 14318180, s->freq)) { - dolog ("YMF262Init %d failed\n", s->freq); - return -1; + error_setg (errp, "YMF262Init %d failed", s->freq); + return; } else { YMF262SetTimerHandler (0, timer_handler, 0); @@ -306,8 +306,8 @@ static int Adlib_initfn (ISADevice *dev) #else s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, s->freq); if (!s->opl) { - dolog ("OPLCreate %d failed\n", s->freq); - return -1; + error_setg (errp, "OPLCreate %d failed", s->freq); + return; } else { OPLSetTimerHandler (s->opl, timer_handler, 0); @@ -332,7 +332,8 @@ static int Adlib_initfn (ISADevice *dev) ); if (!s->voice) { Adlib_fini (s); - return -1; + error_setg (errp, "Initializing audio voice failed"); + return; } s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT; @@ -346,8 +347,6 @@ static int Adlib_initfn (ISADevice *dev) register_ioport_read (s->port + 8, 2, 1, adlib_read, s); register_ioport_write (s->port + 8, 2, 1, adlib_write, s); - - return 0; } static Property adlib_properties[] = { @@ -359,8 +358,8 @@ static Property adlib_properties[] = { static void adlib_class_initfn (ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS (klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS (klass); - ic->init = Adlib_initfn; + + dc->realize = adlib_realizefn; dc->desc = ADLIB_DESC; dc->props = adlib_properties; } diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c index cc605e59a5..605dad4988 100644 --- a/hw/audio/cs4231a.c +++ b/hw/audio/cs4231a.c @@ -56,6 +56,9 @@ static struct { #define CS_REGS 16 #define CS_DREGS 32 +#define TYPE_CS4231A "cs4231a" +#define CS4231A(obj) OBJECT_CHECK (CSState, (obj), TYPE_CS4231A) + typedef struct CSState { ISADevice dev; QEMUSoundCard card; @@ -208,9 +211,9 @@ static int16_t ALawDecompressTable[256] = 944, 912, 1008, 976, 816, 784, 880, 848 }; -static void cs_reset (void *opaque) +static void cs4231a_reset (DeviceState *dev) { - CSState *s = opaque; + CSState *s = CS4231A (dev); s->regs[Index_Address] = 0x40; s->regs[Index_Data] = 0x00; @@ -641,27 +644,30 @@ static const MemoryRegionOps cs_ioport_ops = { } }; -static int cs4231a_initfn (ISADevice *dev) +static void cs4231a_initfn (Object *obj) { - CSState *s = DO_UPCAST (CSState, dev, dev); - - isa_init_irq (dev, &s->pic, s->irq); + CSState *s = CS4231A (obj); memory_region_init_io (&s->ioports, &cs_ioport_ops, s, "cs4231a", 4); - isa_register_ioport (dev, &s->ioports, s->port); +} - DMA_register_channel (s->dma, cs_dma_read, s); +static void cs4231a_realizefn (DeviceState *dev, Error **errp) +{ + ISADevice *d = ISA_DEVICE (dev); + CSState *s = CS4231A (dev); - qemu_register_reset (cs_reset, s); - cs_reset (s); + isa_init_irq (d, &s->pic, s->irq); + + isa_register_ioport (d, &s->ioports, s->port); + + DMA_register_channel (s->dma, cs_dma_read, s); AUD_register_card ("cs4231a", &s->card); - return 0; } static int cs4231a_init (ISABus *bus) { - isa_create_simple (bus, "cs4231a"); + isa_create_simple (bus, TYPE_CS4231A); return 0; } @@ -675,17 +681,19 @@ static Property cs4231a_properties[] = { static void cs4231a_class_initfn (ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS (klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS (klass); - ic->init = cs4231a_initfn; + + dc->realize = cs4231a_realizefn; + dc->reset = cs4231a_reset; dc->desc = "Crystal Semiconductor CS4231A"; dc->vmsd = &vmstate_cs4231a; dc->props = cs4231a_properties; } static const TypeInfo cs4231a_info = { - .name = "cs4231a", + .name = TYPE_CS4231A, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof (CSState), + .instance_init = cs4231a_initfn, .class_init = cs4231a_class_initfn, }; diff --git a/hw/audio/gus.c b/hw/audio/gus.c index a91921c77d..f45ed0b0e9 100644 --- a/hw/audio/gus.c +++ b/hw/audio/gus.c @@ -46,6 +46,9 @@ #define IO_WRITE_PROTO(name) \ static void name (void *opaque, uint32_t nport, uint32_t val) +#define TYPE_GUS "gus" +#define GUS(obj) OBJECT_CHECK (GUSState, (obj), TYPE_GUS) + typedef struct GUSState { ISADevice dev; GUSEmuState emu; @@ -248,9 +251,10 @@ static const MemoryRegionPortio gus_portio_list2[] = { PORTIO_END_OF_LIST (), }; -static int gus_initfn (ISADevice *dev) +static void gus_realizefn (DeviceState *dev, Error **errp) { - GUSState *s = DO_UPCAST (GUSState, dev, dev); + ISADevice *d = ISA_DEVICE(dev); + GUSState *s = GUS (dev); struct audsettings as; AUD_register_card ("gus", &s->card); @@ -271,31 +275,30 @@ static int gus_initfn (ISADevice *dev) if (!s->voice) { AUD_remove_card (&s->card); - return -1; + error_setg(errp, "No voice"); + return; } s->shift = 2; s->samples = AUD_get_buffer_size_out (s->voice) >> s->shift; s->mixbuf = g_malloc0 (s->samples << s->shift); - isa_register_portio_list (dev, s->port, gus_portio_list1, s, "gus"); - isa_register_portio_list (dev, (s->port + 0x100) & 0xf00, + isa_register_portio_list (d, s->port, gus_portio_list1, s, "gus"); + isa_register_portio_list (d, (s->port + 0x100) & 0xf00, gus_portio_list2, s, "gus"); DMA_register_channel (s->emu.gusdma, GUS_read_DMA, s); s->emu.himemaddr = s->himem; s->emu.gusdatapos = s->emu.himemaddr + 1024 * 1024 + 32; s->emu.opaque = s; - isa_init_irq (dev, &s->pic, s->emu.gusirq); + isa_init_irq (d, &s->pic, s->emu.gusirq); AUD_set_active_out (s->voice, 1); - - return 0; } static int GUS_init (ISABus *bus) { - isa_create_simple (bus, "gus"); + isa_create_simple (bus, TYPE_GUS); return 0; } @@ -310,15 +313,15 @@ static Property gus_properties[] = { static void gus_class_initfn (ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS (klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS (klass); - ic->init = gus_initfn; + + dc->realize = gus_realizefn; dc->desc = "Gravis Ultrasound GF1"; dc->vmsd = &vmstate_gus; dc->props = gus_properties; } static const TypeInfo gus_info = { - .name = "gus", + .name = TYPE_GUS, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof (GUSState), .class_init = gus_class_initfn, diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c index 1016af0204..3ac90d510d 100644 --- a/hw/audio/intel-hda.c +++ b/hw/audio/intel-hda.c @@ -189,6 +189,11 @@ struct IntelHDAState { uint32_t msi; }; +#define TYPE_INTEL_HDA_GENERIC "intel-hda-generic" + +#define INTEL_HDA(obj) \ + OBJECT_CHECK(IntelHDAState, (obj), TYPE_INTEL_HDA_GENERIC) + struct IntelHDAReg { const char *name; /* register name */ uint32_t size; /* size in bytes */ @@ -498,7 +503,7 @@ static void intel_hda_notify_codecs(IntelHDAState *d, uint32_t stream, bool runn static void intel_hda_set_g_ctl(IntelHDAState *d, const IntelHDAReg *reg, uint32_t old) { if ((d->g_ctl & ICH6_GCTL_RESET) == 0) { - intel_hda_reset(&d->pci.qdev); + intel_hda_reset(DEVICE(d)); } } @@ -1102,7 +1107,7 @@ static const MemoryRegionOps intel_hda_mmio_ops = { static void intel_hda_reset(DeviceState *dev) { BusChild *kid; - IntelHDAState *d = DO_UPCAST(IntelHDAState, pci.qdev, dev); + IntelHDAState *d = INTEL_HDA(dev); HDACodecDevice *cdev; intel_hda_regs_reset(d); @@ -1120,7 +1125,7 @@ static void intel_hda_reset(DeviceState *dev) static int intel_hda_init(PCIDevice *pci) { - IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci); + IntelHDAState *d = INTEL_HDA(pci); uint8_t *conf = d->pci.config; d->name = object_get_typename(OBJECT(d)); @@ -1137,7 +1142,7 @@ static int intel_hda_init(PCIDevice *pci) msi_init(&d->pci, 0x50, 1, true, false); } - hda_codec_bus_init(&d->pci.qdev, &d->codecs, + hda_codec_bus_init(DEVICE(pci), &d->codecs, intel_hda_response, intel_hda_xfer); return 0; @@ -1145,7 +1150,7 @@ static int intel_hda_init(PCIDevice *pci) static void intel_hda_exit(PCIDevice *pci) { - IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci); + IntelHDAState *d = INTEL_HDA(pci); msi_uninit(&d->pci); memory_region_destroy(&d->mmio); @@ -1232,7 +1237,7 @@ static Property intel_hda_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void intel_hda_class_init_common(ObjectClass *klass) +static void intel_hda_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); @@ -1251,7 +1256,6 @@ static void intel_hda_class_init_ich6(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - intel_hda_class_init_common(klass); k->device_id = 0x2668; k->revision = 1; dc->desc = "Intel HD Audio Controller (ich6)"; @@ -1262,23 +1266,28 @@ static void intel_hda_class_init_ich9(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - intel_hda_class_init_common(klass); k->device_id = 0x293e; k->revision = 3; dc->desc = "Intel HD Audio Controller (ich9)"; } -static const TypeInfo intel_hda_info_ich6 = { - .name = "intel-hda", +static const TypeInfo intel_hda_info = { + .name = TYPE_INTEL_HDA_GENERIC, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(IntelHDAState), + .class_init = intel_hda_class_init, + .abstract = true, +}; + +static const TypeInfo intel_hda_info_ich6 = { + .name = "intel-hda", + .parent = TYPE_INTEL_HDA_GENERIC, .class_init = intel_hda_class_init_ich6, }; static const TypeInfo intel_hda_info_ich9 = { .name = "ich9-intel-hda", - .parent = TYPE_PCI_DEVICE, - .instance_size = sizeof(IntelHDAState), + .parent = TYPE_INTEL_HDA_GENERIC, .class_init = intel_hda_class_init_ich9, }; @@ -1306,12 +1315,12 @@ static const TypeInfo hda_codec_device_type_info = { */ static int intel_hda_and_codec_init(PCIBus *bus) { - PCIDevice *controller; + DeviceState *controller; BusState *hdabus; DeviceState *codec; - controller = pci_create_simple(bus, -1, "intel-hda"); - hdabus = QLIST_FIRST(&controller->qdev.child_bus); + controller = DEVICE(pci_create_simple(bus, -1, "intel-hda")); + hdabus = QLIST_FIRST(&controller->child_bus); codec = qdev_create(hdabus, "hda-duplex"); qdev_init_nofail(codec); return 0; @@ -1320,6 +1329,7 @@ static int intel_hda_and_codec_init(PCIBus *bus) static void intel_hda_register_types(void) { type_register_static(&hda_codec_bus_info); + type_register_static(&intel_hda_info); type_register_static(&intel_hda_info_ich6); type_register_static(&intel_hda_info_ich9); type_register_static(&hda_codec_device_type_info); diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c index 3a7285f14f..5dde0e75da 100644 --- a/hw/audio/pcspk.c +++ b/hw/audio/pcspk.c @@ -163,16 +163,21 @@ static const MemoryRegionOps pcspk_io_ops = { }, }; -static int pcspk_initfn(ISADevice *dev) +static void pcspk_initfn(Object *obj) { - PCSpkState *s = PC_SPEAKER(dev); + PCSpkState *s = PC_SPEAKER(obj); memory_region_init_io(&s->ioport, &pcspk_io_ops, s, "elcr", 1); - isa_register_ioport(dev, &s->ioport, s->iobase); +} - pcspk_state = s; +static void pcspk_realizefn(DeviceState *dev, Error **errp) +{ + ISADevice *isadev = ISA_DEVICE(dev); + PCSpkState *s = PC_SPEAKER(dev); - return 0; + isa_register_ioport(isadev, &s->ioport, s->iobase); + + pcspk_state = s; } static Property pcspk_properties[] = { @@ -184,9 +189,8 @@ static Property pcspk_properties[] = { static void pcspk_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = pcspk_initfn; + dc->realize = pcspk_realizefn; dc->no_user = 1; dc->props = pcspk_properties; } @@ -195,6 +199,7 @@ static const TypeInfo pcspk_info = { .name = TYPE_PC_SPEAKER, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof(PCSpkState), + .instance_init = pcspk_initfn, .class_init = pcspk_class_initfn, }; diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c index 6ddc0ac258..e697bc1498 100644 --- a/hw/audio/sb16.c +++ b/hw/audio/sb16.c @@ -1356,12 +1356,19 @@ static const MemoryRegionPortio sb16_ioport_list[] = { }; -static int sb16_initfn (ISADevice *dev) +static void sb16_initfn (Object *obj) { - SB16State *s = SB16 (dev); + SB16State *s = SB16 (obj); s->cmd = -1; - isa_init_irq (dev, &s->pic, s->irq); +} + +static void sb16_realizefn (DeviceState *dev, Error **errp) +{ + ISADevice *isadev = ISA_DEVICE (dev); + SB16State *s = SB16 (dev); + + isa_init_irq (isadev, &s->pic, s->irq); s->mixer_regs[0x80] = magic_of_irq (s->irq); s->mixer_regs[0x81] = (1 << s->dma) | (1 << s->hdma); @@ -1376,14 +1383,13 @@ static int sb16_initfn (ISADevice *dev) dolog ("warning: Could not create auxiliary timer\n"); } - isa_register_portio_list (dev, s->port, sb16_ioport_list, s, "sb16"); + isa_register_portio_list (isadev, s->port, sb16_ioport_list, s, "sb16"); DMA_register_channel (s->hdma, SB_read_DMA, s); DMA_register_channel (s->dma, SB_read_DMA, s); s->can_write = 1; AUD_register_card ("sb16", &s->card); - return 0; } static int SB16_init (ISABus *bus) @@ -1404,8 +1410,8 @@ static Property sb16_properties[] = { static void sb16_class_initfn (ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS (klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS (klass); - ic->init = sb16_initfn; + + dc->realize = sb16_realizefn; dc->desc = "Creative Sound Blaster 16"; dc->vmsd = &vmstate_sb16; dc->props = sb16_properties; @@ -1415,6 +1421,7 @@ static const TypeInfo sb16_info = { .name = TYPE_SB16, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof (SB16State), + .instance_init = sb16_initfn, .class_init = sb16_class_initfn, }; diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 0888652fe8..930f191d9e 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -2022,22 +2022,24 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl) ISADevice *fdctrl_init_isa(ISABus *bus, DriveInfo **fds) { - ISADevice *dev; + DeviceState *dev; + ISADevice *isadev; - dev = isa_try_create(bus, TYPE_ISA_FDC); - if (!dev) { + isadev = isa_try_create(bus, TYPE_ISA_FDC); + if (!isadev) { return NULL; } + dev = DEVICE(isadev); if (fds[0]) { - qdev_prop_set_drive_nofail(&dev->qdev, "driveA", fds[0]->bdrv); + qdev_prop_set_drive_nofail(dev, "driveA", fds[0]->bdrv); } if (fds[1]) { - qdev_prop_set_drive_nofail(&dev->qdev, "driveB", fds[1]->bdrv); + qdev_prop_set_drive_nofail(dev, "driveB", fds[1]->bdrv); } - qdev_init_nofail(&dev->qdev); + qdev_init_nofail(dev); - return dev; + return isadev; } void fdctrl_init_sysbus(qemu_irq irq, int dma_chann, @@ -2117,24 +2119,28 @@ static const MemoryRegionPortio fdc_portio_list[] = { PORTIO_END_OF_LIST(), }; -static int isabus_fdc_init1(ISADevice *dev) +static void isabus_fdc_realize(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); FDCtrlISABus *isa = ISA_FDC(dev); FDCtrl *fdctrl = &isa->state; int ret; - isa_register_portio_list(dev, isa->iobase, fdc_portio_list, fdctrl, "fdc"); + isa_register_portio_list(isadev, isa->iobase, fdc_portio_list, fdctrl, + "fdc"); - isa_init_irq(dev, &fdctrl->irq, isa->irq); + isa_init_irq(isadev, &fdctrl->irq, isa->irq); fdctrl->dma_chann = isa->dma; - qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 2); + qdev_set_legacy_instance_id(dev, isa->iobase, 2); ret = fdctrl_init_common(fdctrl); + if (ret < 0) { + error_setg(errp, "Floppy init failed."); + return; + } - add_boot_device_path(isa->bootindexA, &dev->qdev, "/floppy@0"); - add_boot_device_path(isa->bootindexB, &dev->qdev, "/floppy@1"); - - return ret; + add_boot_device_path(isa->bootindexA, dev, "/floppy@0"); + add_boot_device_path(isa->bootindexB, dev, "/floppy@1"); } static int sysbus_fdc_init1(SysBusDevice *dev) @@ -2203,8 +2209,8 @@ static Property isa_fdc_properties[] = { static void isabus_fdc_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = isabus_fdc_init1; + + dc->realize = isabus_fdc_realize; dc->fw_name = "fdc"; dc->no_user = 1; dc->reset = fdctrl_external_reset_isa; diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c index 3b0637d44f..f254841aec 100644 --- a/hw/char/debugcon.c +++ b/hw/char/debugcon.c @@ -81,27 +81,32 @@ static const MemoryRegionOps debugcon_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static void debugcon_init_core(DebugconState *s) +static void debugcon_realize_core(DebugconState *s, Error **errp) { if (!s->chr) { - fprintf(stderr, "Can't create debugcon device, empty char device\n"); - exit(1); + error_setg(errp, "Can't create debugcon device, empty char device"); + return; } qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s); } -static int debugcon_isa_initfn(ISADevice *dev) +static void debugcon_isa_realizefn(DeviceState *dev, Error **errp) { + ISADevice *d = ISA_DEVICE(dev); ISADebugconState *isa = ISA_DEBUGCON_DEVICE(dev); DebugconState *s = &isa->state; + Error *err = NULL; - debugcon_init_core(s); + debugcon_realize_core(s, &err); + if (err != NULL) { + error_propagate(errp, err); + return; + } memory_region_init_io(&s->io, &debugcon_ops, s, TYPE_ISA_DEBUGCON_DEVICE, 1); - memory_region_add_subregion(isa_address_space_io(dev), + memory_region_add_subregion(isa_address_space_io(d), isa->iobase, &s->io); - return 0; } static Property debugcon_isa_properties[] = { @@ -114,8 +119,8 @@ static Property debugcon_isa_properties[] = { static void debugcon_isa_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = debugcon_isa_initfn; + + dc->realize = debugcon_isa_realizefn; dc->props = debugcon_isa_properties; } diff --git a/hw/char/parallel.c b/hw/char/parallel.c index 8e48284520..caa9eb4de4 100644 --- a/hw/char/parallel.c +++ b/hw/char/parallel.c @@ -477,29 +477,35 @@ static const MemoryRegionPortio isa_parallel_portio_sw_list[] = { PORTIO_END_OF_LIST(), }; -static int parallel_isa_initfn(ISADevice *dev) +static void parallel_isa_realizefn(DeviceState *dev, Error **errp) { static int index; + ISADevice *isadev = ISA_DEVICE(dev); ISAParallelState *isa = ISA_PARALLEL(dev); ParallelState *s = &isa->state; int base; uint8_t dummy; if (!s->chr) { - fprintf(stderr, "Can't create parallel device, empty char device\n"); - exit(1); + error_setg(errp, "Can't create parallel device, empty char device"); + return; } - if (isa->index == -1) + if (isa->index == -1) { isa->index = index; - if (isa->index >= MAX_PARALLEL_PORTS) - return -1; - if (isa->iobase == -1) + } + if (isa->index >= MAX_PARALLEL_PORTS) { + error_setg(errp, "Max. supported number of parallel ports is %d.", + MAX_PARALLEL_PORTS); + return; + } + if (isa->iobase == -1) { isa->iobase = isa_parallel_io[isa->index]; + } index++; base = isa->iobase; - isa_init_irq(dev, &s->irq, isa->isairq); + isa_init_irq(isadev, &s->irq, isa->isairq); qemu_register_reset(parallel_reset, s); if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) { @@ -507,12 +513,11 @@ static int parallel_isa_initfn(ISADevice *dev) s->status = dummy; } - isa_register_portio_list(dev, base, + isa_register_portio_list(isadev, base, (s->hw_driver ? &isa_parallel_portio_hw_list[0] : &isa_parallel_portio_sw_list[0]), s, "parallel"); - return 0; } /* Memory mapped interface */ @@ -599,8 +604,8 @@ static Property parallel_isa_properties[] = { static void parallel_isa_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = parallel_isa_initfn; + + dc->realize = parallel_isa_realizefn; dc->props = parallel_isa_properties; } diff --git a/hw/char/serial-isa.c b/hw/char/serial-isa.c index 342b4ccbe3..e06a802e24 100644 --- a/hw/char/serial-isa.c +++ b/hw/char/serial-isa.c @@ -44,9 +44,10 @@ static const int isa_serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 }; -static int serial_isa_initfn(ISADevice *dev) +static void serial_isa_realizefn(DeviceState *dev, Error **errp) { static int index; + ISADevice *isadev = ISA_DEVICE(dev); ISASerialState *isa = ISA_SERIAL(dev); SerialState *s = &isa->state; @@ -54,7 +55,9 @@ static int serial_isa_initfn(ISADevice *dev) isa->index = index; } if (isa->index >= MAX_SERIAL_PORTS) { - return -1; + error_setg(errp, "Max. supported number of ISA serial ports is %d.", + MAX_SERIAL_PORTS); + return; } if (isa->iobase == -1) { isa->iobase = isa_serial_io[isa->index]; @@ -65,13 +68,12 @@ static int serial_isa_initfn(ISADevice *dev) index++; s->baudbase = 115200; - isa_init_irq(dev, &s->irq, isa->isairq); - serial_init_core(s); - qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 3); + isa_init_irq(isadev, &s->irq, isa->isairq); + serial_realize_core(s, errp); + qdev_set_legacy_instance_id(dev, isa->iobase, 3); memory_region_init_io(&s->io, &serial_io_ops, s, "serial", 8); - isa_register_ioport(dev, &s->io, isa->iobase); - return 0; + isa_register_ioport(isadev, &s->io, isa->iobase); } static const VMStateDescription vmstate_isa_serial = { @@ -96,8 +98,8 @@ static Property serial_isa_properties[] = { static void serial_isa_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = serial_isa_initfn; + + dc->realize = serial_isa_realizefn; dc->vmsd = &vmstate_isa_serial; dc->props = serial_isa_properties; } @@ -118,15 +120,17 @@ type_init(serial_register_types) bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr) { - ISADevice *dev; + DeviceState *dev; + ISADevice *isadev; - dev = isa_try_create(bus, TYPE_ISA_SERIAL); - if (!dev) { + isadev = isa_try_create(bus, TYPE_ISA_SERIAL); + if (!isadev) { return false; } - qdev_prop_set_uint32(&dev->qdev, "index", index); - qdev_prop_set_chr(&dev->qdev, "chardev", chr); - if (qdev_init(&dev->qdev) < 0) { + dev = DEVICE(isadev); + qdev_prop_set_uint32(dev, "index", index); + qdev_prop_set_chr(dev, "chardev", chr); + if (qdev_init(dev) < 0) { return false; } return true; diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c index 2138e35851..3bec8ebe7b 100644 --- a/hw/char/serial-pci.c +++ b/hw/char/serial-pci.c @@ -27,6 +27,7 @@ #include "hw/char/serial.h" #include "hw/pci/pci.h" +#include "qapi/qmp/qerror.h" #define PCI_SERIAL_MAX_PORTS 4 @@ -49,9 +50,15 @@ static int serial_pci_init(PCIDevice *dev) { PCISerialState *pci = DO_UPCAST(PCISerialState, dev, dev); SerialState *s = &pci->state; + Error *err = NULL; s->baudbase = 115200; - serial_init_core(s); + serial_realize_core(s, &err); + if (err != NULL) { + qerror_report_err(err); + error_free(err); + return -1; + } pci->dev.config[PCI_INTERRUPT_PIN] = 0x01; s->irq = pci->dev.irq[0]; @@ -80,6 +87,7 @@ static int multi_serial_pci_init(PCIDevice *dev) PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev); SerialState *s; + Error *err = NULL; int i; switch (pc->device_id) { @@ -102,7 +110,12 @@ static int multi_serial_pci_init(PCIDevice *dev) for (i = 0; i < pci->ports; i++) { s = pci->state + i; s->baudbase = 115200; - serial_init_core(s); + serial_realize_core(s, &err); + if (err != NULL) { + qerror_report_err(err); + error_free(err); + return -1; + } s->irq = pci->irqs[i]; pci->name[i] = g_strdup_printf("uart #%d", i+1); memory_region_init_io(&s->io, &serial_io_ops, s, pci->name[i], 8); diff --git a/hw/char/serial.c b/hw/char/serial.c index 017610eb45..6382f98389 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -424,7 +424,7 @@ static uint64_t serial_ioport_read(void *opaque, hwaddr addr, unsigned size) ret = s->divider & 0xff; } else { if(s->fcr & UART_FCR_FE) { - ret = fifo8_is_full(&s->recv_fifo) ? + ret = fifo8_is_empty(&s->recv_fifo) ? 0 : fifo8_pop(&s->recv_fifo); if (s->recv_fifo.num == 0) { s->lsr &= ~(UART_LSR_DR | UART_LSR_BI); @@ -642,11 +642,11 @@ static void serial_reset(void *opaque) qemu_irq_lower(s->irq); } -void serial_init_core(SerialState *s) +void serial_realize_core(SerialState *s, Error **errp) { if (!s->chr) { - fprintf(stderr, "Can't create serial device, empty char device\n"); - exit(1); + error_setg(errp, "Can't create serial device, empty char device"); + return; } s->modem_status_poll = qemu_new_timer_ns(vm_clock, (QEMUTimerCB *) serial_update_msl, s); @@ -687,13 +687,19 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase, CharDriverState *chr, MemoryRegion *system_io) { SerialState *s; + Error *err = NULL; s = g_malloc0(sizeof(SerialState)); s->irq = irq; s->baudbase = baudbase; s->chr = chr; - serial_init_core(s); + serial_realize_core(s, &err); + if (err != NULL) { + fprintf(stderr, "%s\n", error_get_pretty(err)); + error_free(err); + exit(1); + } vmstate_register(NULL, base, &vmstate_serial, s); @@ -743,6 +749,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space, CharDriverState *chr, enum device_endian end) { SerialState *s; + Error *err = NULL; s = g_malloc0(sizeof(SerialState)); @@ -751,7 +758,12 @@ SerialState *serial_mm_init(MemoryRegion *address_space, s->baudbase = baudbase; s->chr = chr; - serial_init_core(s); + serial_realize_core(s, &err); + if (err != NULL) { + fprintf(stderr, "%s\n", error_get_pretty(err)); + error_free(err); + exit(1); + } vmstate_register(NULL, base, &vmstate_serial, s); memory_region_init_io(&s->io, &serial_mm_ops[end], s, diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index a5dbc39c21..0d9eee876a 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -2906,19 +2906,20 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci, * ***************************************/ -static int vga_initfn(ISADevice *dev) +static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev); VGACommonState *s = &d->cirrus_vga.vga; vga_common_init(s); cirrus_init_common(&d->cirrus_vga, CIRRUS_ID_CLGD5430, 0, - isa_address_space(dev), isa_address_space_io(dev)); - s->con = graphic_console_init(DEVICE(dev), s->hw_ops, s); + isa_address_space(isadev), + isa_address_space_io(isadev)); + s->con = graphic_console_init(dev, s->hw_ops, s); rom_add_vga(VGABIOS_CIRRUS_FILENAME); /* XXX ISA-LFB support */ /* FIXME not qdev yet */ - return 0; } static Property isa_cirrus_vga_properties[] = { @@ -2929,11 +2930,10 @@ static Property isa_cirrus_vga_properties[] = { static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data) { - ISADeviceClass *k = ISA_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &vmstate_cirrus_vga; - k->init = vga_initfn; + dc->realize = isa_cirrus_vga_realizefn; dc->props = isa_cirrus_vga_properties; } diff --git a/hw/display/vga-isa.c b/hw/display/vga-isa.c index 9e63b69e03..d1691a9f9b 100644 --- a/hw/display/vga-isa.c +++ b/hw/display/vga-isa.c @@ -48,30 +48,30 @@ static void vga_isa_reset(DeviceState *dev) vga_common_reset(s); } -static int vga_initfn(ISADevice *dev) +static void vga_isa_realizefn(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); ISAVGAState *d = ISA_VGA(dev); VGACommonState *s = &d->state; MemoryRegion *vga_io_memory; const MemoryRegionPortio *vga_ports, *vbe_ports; vga_common_init(s); - s->legacy_address_space = isa_address_space(dev); + s->legacy_address_space = isa_address_space(isadev); vga_io_memory = vga_init_io(s, &vga_ports, &vbe_ports); - isa_register_portio_list(dev, 0x3b0, vga_ports, s, "vga"); + isa_register_portio_list(isadev, 0x3b0, vga_ports, s, "vga"); if (vbe_ports) { - isa_register_portio_list(dev, 0x1ce, vbe_ports, s, "vbe"); + isa_register_portio_list(isadev, 0x1ce, vbe_ports, s, "vbe"); } - memory_region_add_subregion_overlap(isa_address_space(dev), + memory_region_add_subregion_overlap(isa_address_space(isadev), isa_mem_base + 0x000a0000, vga_io_memory, 1); memory_region_set_coalescing(vga_io_memory); s->con = graphic_console_init(DEVICE(dev), s->hw_ops, s); - vga_init_vbe(s, isa_address_space(dev)); + vga_init_vbe(s, isa_address_space(isadev)); /* ROM BIOS */ rom_add_vga(VGABIOS_FILENAME); - return 0; } static Property vga_isa_properties[] = { @@ -82,9 +82,8 @@ static Property vga_isa_properties[] = { static void vga_isa_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = vga_initfn; + dc->realize = vga_isa_realizefn; dc->reset = vga_isa_reset; dc->vmsd = &vmstate_vga_common; dc->props = vga_isa_properties; diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c index f3d1924109..6192780fda 100644 --- a/hw/dma/i82374.c +++ b/hw/dma/i82374.c @@ -98,7 +98,7 @@ static uint32_t i82374_read_descriptor(void *opaque, uint32_t nport) return val; } -static void i82374_init(I82374State *s) +static void i82374_realize(I82374State *s, Error **errp) { DMA_init(1, &s->out); memset(s->commands, 0, sizeof(s->commands)); @@ -124,7 +124,7 @@ static const VMStateDescription vmstate_isa_i82374 = { }, }; -static int i82374_isa_init(ISADevice *dev) +static void i82374_isa_realize(DeviceState *dev, Error **errp) { ISAi82374State *isa = I82374(dev); I82374State *s = &isa->state; @@ -135,11 +135,9 @@ static int i82374_isa_init(ISADevice *dev) register_ioport_write(isa->iobase + 0x20, 0x20, 1, i82374_write_descriptor, s); register_ioport_read(isa->iobase + 0x20, 0x20, 1, i82374_read_descriptor, s); - i82374_init(s); + i82374_realize(s, errp); - qdev_init_gpio_out(&dev->qdev, &s->out, 1); - - return 0; + qdev_init_gpio_out(dev, &s->out, 1); } static Property i82374_properties[] = { @@ -149,10 +147,9 @@ static Property i82374_properties[] = { static void i82374_class_init(ObjectClass *klass, void *data) { - ISADeviceClass *k = ISA_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - k->init = i82374_isa_init; + dc->realize = i82374_isa_realize; dc->vmsd = &vmstate_isa_i82374; dc->props = i82374_properties; } diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 0c4fc1dbaa..22ef3b9617 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -66,7 +66,7 @@ i2c_bus *i2c_init_bus(DeviceState *parent, const char *name) { i2c_bus *bus; - bus = FROM_QBUS(i2c_bus, qbus_create(TYPE_I2C_BUS, parent, name)); + bus = I2C_BUS(qbus_create(TYPE_I2C_BUS, parent, name)); vmstate_register(NULL, -1, &vmstate_i2c_bus, bus); return bus; } @@ -183,7 +183,7 @@ static int i2c_slave_post_load(void *opaque, int version_id) { I2CSlave *dev = opaque; i2c_bus *bus; - bus = FROM_QBUS(i2c_bus, qdev_get_parent_bus(&dev->qdev)); + bus = I2C_BUS(qdev_get_parent_bus(DEVICE(dev))); if (bus->saved_address == dev->address) { bus->current_dev = dev; } diff --git a/hw/i386/kvm/i8254.c b/hw/i386/kvm/i8254.c index da90711853..93a3669746 100644 --- a/hw/i386/kvm/i8254.c +++ b/hw/i386/kvm/i8254.c @@ -32,13 +32,26 @@ #define CALIBRATION_ROUNDS 3 +#define KVM_PIT(obj) OBJECT_CHECK(KVMPITState, (obj), TYPE_KVM_I8254) +#define KVM_PIT_CLASS(class) \ + OBJECT_CLASS_CHECK(KVMPITClass, (class), TYPE_KVM_I8254) +#define KVM_PIT_GET_CLASS(obj) \ + OBJECT_GET_CLASS(KVMPITClass, (obj), TYPE_KVM_I8254) + typedef struct KVMPITState { - PITCommonState pit; + PITCommonState parent_obj; + LostTickPolicy lost_tick_policy; bool vm_stopped; int64_t kernel_clock_offset; } KVMPITState; +typedef struct KVMPITClass { + PITCommonClass parent_class; + + DeviceRealize parent_realize; +} KVMPITClass; + static int64_t abs64(int64_t v) { return v < 0 ? -v : v; @@ -70,7 +83,7 @@ static void kvm_pit_update_clock_offset(KVMPITState *s) static void kvm_pit_get(PITCommonState *pit) { - KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit); + KVMPITState *s = KVM_PIT(pit); struct kvm_pit_state2 kpit; struct kvm_pit_channel_state *kchan; struct PITChannelState *sc; @@ -124,7 +137,7 @@ static void kvm_pit_get(PITCommonState *pit) static void kvm_pit_put(PITCommonState *pit) { - KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit); + KVMPITState *s = KVM_PIT(pit); struct kvm_pit_state2 kpit; struct kvm_pit_channel_state *kchan; struct PITChannelState *sc; @@ -200,7 +213,7 @@ static void kvm_pit_get_channel_info(PITCommonState *s, PITChannelState *sc, static void kvm_pit_reset(DeviceState *dev) { - PITCommonState *s = DO_UPCAST(PITCommonState, dev.qdev, dev); + PITCommonState *s = PIT_COMMON(dev); pit_reset_common(s); @@ -229,14 +242,16 @@ static void kvm_pit_vm_state_change(void *opaque, int running, s->vm_stopped = false; } else { kvm_pit_update_clock_offset(s); - kvm_pit_get(&s->pit); + kvm_pit_get(PIT_COMMON(s)); s->vm_stopped = true; } } -static int kvm_pit_initfn(PITCommonState *pit) +static void kvm_pit_realizefn(DeviceState *dev, Error **errp) { - KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit); + PITCommonState *pit = PIT_COMMON(dev); + KVMPITClass *kpc = KVM_PIT_GET_CLASS(dev); + KVMPITState *s = KVM_PIT(pit); struct kvm_pit_config config = { .flags = 0, }; @@ -248,9 +263,9 @@ static int kvm_pit_initfn(PITCommonState *pit) ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_PIT); } if (ret < 0) { - fprintf(stderr, "Create kernel PIC irqchip failed: %s\n", - strerror(ret)); - return ret; + error_setg(errp, "Create kernel PIC irqchip failed: %s", + strerror(ret)); + return; } switch (s->lost_tick_policy) { case LOST_TICK_DELAY: @@ -261,28 +276,29 @@ static int kvm_pit_initfn(PITCommonState *pit) ret = kvm_vm_ioctl(kvm_state, KVM_REINJECT_CONTROL, &control); if (ret < 0) { - fprintf(stderr, - "Can't disable in-kernel PIT reinjection: %s\n", - strerror(ret)); - return ret; + error_setg(errp, + "Can't disable in-kernel PIT reinjection: %s", + strerror(ret)); + return; } } break; default: - return -EINVAL; + error_setg(errp, "Lost tick policy not supported."); + return; } memory_region_init_reservation(&pit->ioports, "kvm-pit", 4); - qdev_init_gpio_in(&pit->dev.qdev, kvm_pit_irq_control, 1); + qdev_init_gpio_in(dev, kvm_pit_irq_control, 1); qemu_add_vm_change_state_handler(kvm_pit_vm_state_change, s); - return 0; + kpc->parent_realize(dev, errp); } static Property kvm_pit_properties[] = { - DEFINE_PROP_HEX32("iobase", KVMPITState, pit.iobase, -1), + DEFINE_PROP_HEX32("iobase", PITCommonState, iobase, -1), DEFINE_PROP_LOSTTICKPOLICY("lost_tick_policy", KVMPITState, lost_tick_policy, LOST_TICK_DELAY), DEFINE_PROP_END_OF_LIST(), @@ -290,10 +306,12 @@ static Property kvm_pit_properties[] = { static void kvm_pit_class_init(ObjectClass *klass, void *data) { + KVMPITClass *kpc = KVM_PIT_CLASS(klass); PITCommonClass *k = PIT_COMMON_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - k->init = kvm_pit_initfn; + kpc->parent_realize = dc->realize; + dc->realize = kvm_pit_realizefn; k->set_channel_gate = kvm_pit_set_gate; k->get_channel_info = kvm_pit_get_channel_info; k->pre_save = kvm_pit_get; @@ -303,10 +321,11 @@ static void kvm_pit_class_init(ObjectClass *klass, void *data) } static const TypeInfo kvm_pit_info = { - .name = "kvm-pit", + .name = TYPE_KVM_I8254, .parent = TYPE_PIT_COMMON, .instance_size = sizeof(KVMPITState), .class_init = kvm_pit_class_init, + .class_size = sizeof(KVMPITClass), }; static void kvm_pit_register(void) diff --git a/hw/i386/kvm/i8259.c b/hw/i386/kvm/i8259.c index d961ecabbd..125022422a 100644 --- a/hw/i386/kvm/i8259.c +++ b/hw/i386/kvm/i8259.c @@ -13,6 +13,22 @@ #include "hw/i386/apic_internal.h" #include "sysemu/kvm.h" +#define TYPE_KVM_I8259 "kvm-i8259" +#define KVM_PIC_CLASS(class) \ + OBJECT_CLASS_CHECK(KVMPICClass, (class), TYPE_KVM_I8259) +#define KVM_PIC_GET_CLASS(obj) \ + OBJECT_GET_CLASS(KVMPICClass, (obj), TYPE_KVM_I8259) + +/** + * KVMPICClass: + * @parent_realize: The parent's realizefn. + */ +typedef struct KVMPICClass { + PICCommonClass parent_class; + + DeviceRealize parent_realize; +} KVMPICClass; + static void kvm_pic_get(PICCommonState *s) { struct kvm_irqchip chip; @@ -98,36 +114,44 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level) apic_report_irq_delivered(delivered); } -static void kvm_pic_init(PICCommonState *s) +static void kvm_pic_realize(DeviceState *dev, Error **errp) { + PICCommonState *s = PIC_COMMON(dev); + KVMPICClass *kpc = KVM_PIC_GET_CLASS(dev); + memory_region_init_reservation(&s->base_io, "kvm-pic", 2); memory_region_init_reservation(&s->elcr_io, "kvm-elcr", 1); + + kpc->parent_realize(dev, errp); } qemu_irq *kvm_i8259_init(ISABus *bus) { - i8259_init_chip("kvm-i8259", bus, true); - i8259_init_chip("kvm-i8259", bus, false); + i8259_init_chip(TYPE_KVM_I8259, bus, true); + i8259_init_chip(TYPE_KVM_I8259, bus, false); return qemu_allocate_irqs(kvm_pic_set_irq, NULL, ISA_NUM_IRQS); } static void kvm_i8259_class_init(ObjectClass *klass, void *data) { + KVMPICClass *kpc = KVM_PIC_CLASS(klass); PICCommonClass *k = PIC_COMMON_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); dc->reset = kvm_pic_reset; - k->init = kvm_pic_init; + kpc->parent_realize = dc->realize; + dc->realize = kvm_pic_realize; k->pre_save = kvm_pic_get; k->post_load = kvm_pic_put; } static const TypeInfo kvm_i8259_info = { - .name = "kvm-i8259", + .name = TYPE_KVM_I8259, .parent = TYPE_PIC_COMMON, .instance_size = sizeof(PICCommonState), .class_init = kvm_i8259_class_init, + .class_size = sizeof(KVMPICClass), }; static void kvm_pic_register_types(void) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 553becbd42..e0fbb860ed 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -522,23 +522,29 @@ static const MemoryRegionOps port92_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static int port92_initfn(ISADevice *dev) +static void port92_initfn(Object *obj) { - Port92State *s = PORT92(dev); + Port92State *s = PORT92(obj); memory_region_init_io(&s->io, &port92_ops, s, "port92", 1); - isa_register_ioport(dev, &s->io, 0x92); s->outport = 0; - return 0; +} + +static void port92_realizefn(DeviceState *dev, Error **errp) +{ + ISADevice *isadev = ISA_DEVICE(dev); + Port92State *s = PORT92(dev); + + isa_register_ioport(isadev, &s->io, 0x92); } static void port92_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = port92_initfn; + dc->no_user = 1; + dc->realize = port92_realizefn; dc->reset = port92_reset; dc->vmsd = &vmstate_port92_isa; } @@ -547,6 +553,7 @@ static const TypeInfo port92_info = { .name = TYPE_PORT92, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof(Port92State), + .instance_init = port92_initfn, .class_init = port92_class_initfn, }; @@ -1093,7 +1100,7 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus) dev = pcidev ? &pcidev->qdev : NULL; } else if (isa_bus) { ISADevice *isadev = isa_vga_init(isa_bus); - dev = isadev ? &isadev->qdev : NULL; + dev = isadev ? DEVICE(isadev) : NULL; } return dev; } @@ -1180,7 +1187,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, } if (hpet) { /* connect PIT to output control line of the HPET */ - qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(&pit->qdev, 0)); + qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0)); } pcspk_init(isa_bus, pit); } @@ -1208,8 +1215,9 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, vmmouse = NULL; } if (vmmouse) { - qdev_prop_set_ptr(&vmmouse->qdev, "ps2_mouse", i8042); - qdev_init_nofail(&vmmouse->qdev); + DeviceState *dev = DEVICE(vmmouse); + qdev_prop_set_ptr(dev, "ps2_mouse", i8042); + qdev_init_nofail(dev); } port92 = isa_create_simple(isa_bus, "port92"); port92_init(port92, &a20_line[1]); diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 69eb2a17be..97362f2c26 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -199,7 +199,7 @@ static void pc_init1(MemoryRegion *system_memory, dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i], hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); - idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0"); + idebus[i] = qdev_get_child_bus(DEVICE(dev), "ide.0"); } } diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c index c00bb2fad8..e708cb8919 100644 --- a/hw/i386/smbios.c +++ b/hw/i386/smbios.c @@ -13,6 +13,7 @@ * GNU GPL, version 2 or (at your option) any later version. */ +#include "qemu/error-report.h" #include "sysemu/sysemu.h" #include "hw/i386/smbios.h" #include "hw/loader.h" @@ -48,8 +49,7 @@ static int smbios_type4_count = 0; static void smbios_validate_table(void) { if (smbios_type4_count && smbios_type4_count != smp_cpus) { - fprintf(stderr, - "Number of SMBIOS Type 4 tables must match cpu count.\n"); + error_report("Number of SMBIOS Type 4 tables must match cpu count"); exit(1); } } @@ -82,16 +82,16 @@ static void smbios_check_collision(int type, int entry) if (entry == SMBIOS_TABLE_ENTRY && header->type == SMBIOS_FIELD_ENTRY) { struct smbios_field *field = (void *)header; if (type == field->type) { - fprintf(stderr, "SMBIOS type %d field already defined, " - "cannot add table\n", type); + error_report("SMBIOS type %d field already defined, " + "cannot add table", type); exit(1); } } else if (entry == SMBIOS_FIELD_ENTRY && header->type == SMBIOS_TABLE_ENTRY) { struct smbios_structure_header *table = (void *)(header + 1); if (type == table->type) { - fprintf(stderr, "SMBIOS type %d table already defined, " - "cannot add field\n", type); + error_report("SMBIOS type %d table already defined, " + "cannot add field", type); exit(1); } } @@ -99,7 +99,7 @@ static void smbios_check_collision(int type, int entry) } } -void smbios_add_field(int type, int offset, int len, void *data) +void smbios_add_field(int type, int offset, const void *data, size_t len) { struct smbios_field *field; @@ -127,24 +127,29 @@ void smbios_add_field(int type, int offset, int len, void *data) static void smbios_build_type_0_fields(const char *t) { char buf[1024]; + unsigned char major, minor; if (get_param_value(buf, sizeof(buf), "vendor", t)) smbios_add_field(0, offsetof(struct smbios_type_0, vendor_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); if (get_param_value(buf, sizeof(buf), "version", t)) smbios_add_field(0, offsetof(struct smbios_type_0, bios_version_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); if (get_param_value(buf, sizeof(buf), "date", t)) smbios_add_field(0, offsetof(struct smbios_type_0, bios_release_date_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); if (get_param_value(buf, sizeof(buf), "release", t)) { - int major, minor; - sscanf(buf, "%d.%d", &major, &minor); + if (sscanf(buf, "%hhu.%hhu", &major, &minor) != 2) { + error_report("Invalid release"); + exit(1); + } smbios_add_field(0, offsetof(struct smbios_type_0, - system_bios_major_release), 1, &major); + system_bios_major_release), + &major, 1); smbios_add_field(0, offsetof(struct smbios_type_0, - system_bios_minor_release), 1, &minor); + system_bios_minor_release), + &minor, 1); } } @@ -154,28 +159,28 @@ static void smbios_build_type_1_fields(const char *t) if (get_param_value(buf, sizeof(buf), "manufacturer", t)) smbios_add_field(1, offsetof(struct smbios_type_1, manufacturer_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); if (get_param_value(buf, sizeof(buf), "product", t)) smbios_add_field(1, offsetof(struct smbios_type_1, product_name_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); if (get_param_value(buf, sizeof(buf), "version", t)) smbios_add_field(1, offsetof(struct smbios_type_1, version_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); if (get_param_value(buf, sizeof(buf), "serial", t)) smbios_add_field(1, offsetof(struct smbios_type_1, serial_number_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); if (get_param_value(buf, sizeof(buf), "uuid", t)) { if (qemu_uuid_parse(buf, qemu_uuid) != 0) { - fprintf(stderr, "Invalid SMBIOS UUID string\n"); + error_report("Invalid UUID"); exit(1); } } if (get_param_value(buf, sizeof(buf), "sku", t)) smbios_add_field(1, offsetof(struct smbios_type_1, sku_number_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); if (get_param_value(buf, sizeof(buf), "family", t)) smbios_add_field(1, offsetof(struct smbios_type_1, family_str), - strlen(buf) + 1, buf); + buf, strlen(buf) + 1); } int smbios_entry_add(const char *t) @@ -188,7 +193,7 @@ int smbios_entry_add(const char *t) int size = get_image_size(buf); if (size == -1 || size < sizeof(struct smbios_structure_header)) { - fprintf(stderr, "Cannot read smbios file %s\n", buf); + error_report("Cannot read SMBIOS file %s", buf); exit(1); } @@ -204,7 +209,7 @@ int smbios_entry_add(const char *t) table->header.length = cpu_to_le16(sizeof(*table) + size); if (load_image(buf, table->data) != size) { - fprintf(stderr, "Failed to load smbios file %s", buf); + error_report("Failed to load SMBIOS file %s", buf); exit(1); } @@ -230,12 +235,12 @@ int smbios_entry_add(const char *t) smbios_build_type_1_fields(t); return 0; default: - fprintf(stderr, "Don't know how to build fields for SMBIOS type " - "%ld\n", type); + error_report("Don't know how to build fields for SMBIOS type %ld", + type); exit(1); } } - fprintf(stderr, "smbios: must specify type= or file=\n"); + error_report("Must specify type= or file="); return -1; } diff --git a/hw/ide/isa.c b/hw/ide/isa.c index 369a7fa58a..7243c82c0f 100644 --- a/hw/ide/isa.c +++ b/hw/ide/isa.c @@ -65,16 +65,16 @@ static const VMStateDescription vmstate_ide_isa = { } }; -static int isa_ide_initfn(ISADevice *dev) +static void isa_ide_realizefn(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); ISAIDEState *s = ISA_IDE(dev); - ide_bus_new(&s->bus, DEVICE(dev), 0, 2); - ide_init_ioport(&s->bus, dev, s->iobase, s->iobase2); - isa_init_irq(dev, &s->irq, s->isairq); + ide_bus_new(&s->bus, dev, 0, 2); + ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2); + isa_init_irq(isadev, &s->irq, s->isairq); ide_init2(&s->bus, s->irq); - vmstate_register(&dev->qdev, 0, &vmstate_ide_isa, s); - return 0; + vmstate_register(dev, 0, &vmstate_ide_isa, s); }; ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq, @@ -113,8 +113,8 @@ static Property isa_ide_properties[] = { static void isa_ide_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = isa_ide_initfn; + + dc->realize = isa_ide_realizefn; dc->fw_name = "ide"; dc->reset = isa_ide_reset; dc->props = isa_ide_properties; diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index 17a56140de..fff0a4d1f8 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -489,31 +489,37 @@ static const MemoryRegionOps i8042_cmd_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static int i8042_initfn(ISADevice *dev) +static void i8042_initfn(Object *obj) { - ISAKBDState *isa_s = I8042(dev); + ISAKBDState *isa_s = I8042(obj); KBDState *s = &isa_s->kbd; - isa_init_irq(dev, &s->irq_kbd, 1); - isa_init_irq(dev, &s->irq_mouse, 12); - memory_region_init_io(isa_s->io + 0, &i8042_data_ops, s, "i8042-data", 1); - isa_register_ioport(dev, isa_s->io + 0, 0x60); - memory_region_init_io(isa_s->io + 1, &i8042_cmd_ops, s, "i8042-cmd", 1); - isa_register_ioport(dev, isa_s->io + 1, 0x64); +} + +static void i8042_realizefn(DeviceState *dev, Error **errp) +{ + ISADevice *isadev = ISA_DEVICE(dev); + ISAKBDState *isa_s = I8042(dev); + KBDState *s = &isa_s->kbd; + + isa_init_irq(isadev, &s->irq_kbd, 1); + isa_init_irq(isadev, &s->irq_mouse, 12); + + isa_register_ioport(isadev, isa_s->io + 0, 0x60); + isa_register_ioport(isadev, isa_s->io + 1, 0x64); s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s); s->mouse = ps2_mouse_init(kbd_update_aux_irq, s); qemu_register_reset(kbd_reset, s); - return 0; } static void i8042_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = i8042_initfn; + + dc->realize = i8042_realizefn; dc->no_user = 1; dc->vmsd = &vmstate_kbd_isa; } @@ -522,6 +528,7 @@ static const TypeInfo i8042_info = { .name = TYPE_I8042, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof(ISAKBDState), + .instance_init = i8042_initfn, .class_init = i8042_class_initfn, }; diff --git a/hw/input/vmmouse.c b/hw/input/vmmouse.c index a610738374..abd032b794 100644 --- a/hw/input/vmmouse.c +++ b/hw/input/vmmouse.c @@ -261,7 +261,7 @@ static void vmmouse_reset(DeviceState *d) vmmouse_disable(s); } -static int vmmouse_initfn(ISADevice *dev) +static void vmmouse_realizefn(DeviceState *dev, Error **errp) { VMMouseState *s = VMMOUSE(dev); @@ -270,8 +270,6 @@ static int vmmouse_initfn(ISADevice *dev) vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s); vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s); vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s); - - return 0; } static Property vmmouse_properties[] = { @@ -282,8 +280,8 @@ static Property vmmouse_properties[] = { static void vmmouse_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = vmmouse_initfn; + + dc->realize = vmmouse_realizefn; dc->no_user = 1; dc->reset = vmmouse_reset; dc->vmsd = &vmstate_vmmouse; diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c index fef00fca75..192a0ba68f 100644 --- a/hw/intc/i8259.c +++ b/hw/intc/i8259.c @@ -41,6 +41,20 @@ //#define DEBUG_IRQ_LATENCY //#define DEBUG_IRQ_COUNT +#define TYPE_I8259 "isa-i8259" +#define PIC_CLASS(class) OBJECT_CLASS_CHECK(PICClass, (class), TYPE_I8259) +#define PIC_GET_CLASS(obj) OBJECT_GET_CLASS(PICClass, (obj), TYPE_I8259) + +/** + * PICClass: + * @parent_realize: The parent's realizefn. + */ +typedef struct PICClass { + PICCommonClass parent_class; + + DeviceRealize parent_realize; +} PICClass; + #if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT) static int irq_level[16]; #endif @@ -398,15 +412,18 @@ static const MemoryRegionOps pic_elcr_ioport_ops = { }, }; -static void pic_init(PICCommonState *s) +static void pic_realize(DeviceState *dev, Error **err) { - DeviceState *dev = DEVICE(s); + PICCommonState *s = PIC_COMMON(dev); + PICClass *pc = PIC_GET_CLASS(dev); memory_region_init_io(&s->base_io, &pic_base_ioport_ops, s, "pic", 2); memory_region_init_io(&s->elcr_io, &pic_elcr_ioport_ops, s, "elcr", 1); qdev_init_gpio_out(dev, s->int_out, ARRAY_SIZE(s->int_out)); qdev_init_gpio_in(dev, pic_set_irq, 8); + + pc->parent_realize(dev, err); } void pic_info(Monitor *mon, const QDict *qdict) @@ -448,25 +465,28 @@ void irq_info(Monitor *mon, const QDict *qdict) qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq) { qemu_irq *irq_set; - ISADevice *dev; + DeviceState *dev; + ISADevice *isadev; int i; irq_set = g_malloc(ISA_NUM_IRQS * sizeof(qemu_irq)); - dev = i8259_init_chip("isa-i8259", bus, true); + isadev = i8259_init_chip(TYPE_I8259, bus, true); + dev = DEVICE(isadev); - qdev_connect_gpio_out(&dev->qdev, 0, parent_irq); + qdev_connect_gpio_out(dev, 0, parent_irq); for (i = 0 ; i < 8; i++) { - irq_set[i] = qdev_get_gpio_in(&dev->qdev, i); + irq_set[i] = qdev_get_gpio_in(dev, i); } - isa_pic = &dev->qdev; + isa_pic = dev; - dev = i8259_init_chip("isa-i8259", bus, false); + isadev = i8259_init_chip(TYPE_I8259, bus, false); + dev = DEVICE(isadev); - qdev_connect_gpio_out(&dev->qdev, 0, irq_set[2]); + qdev_connect_gpio_out(dev, 0, irq_set[2]); for (i = 0 ; i < 8; i++) { - irq_set[i + 8] = qdev_get_gpio_in(&dev->qdev, i); + irq_set[i + 8] = qdev_get_gpio_in(dev, i); } slave_pic = PIC_COMMON(dev); @@ -476,18 +496,20 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq) static void i8259_class_init(ObjectClass *klass, void *data) { - PICCommonClass *k = PIC_COMMON_CLASS(klass); + PICClass *k = PIC_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - k->init = pic_init; + k->parent_realize = dc->realize; + dc->realize = pic_realize; dc->reset = pic_reset; } static const TypeInfo i8259_info = { - .name = "isa-i8259", + .name = TYPE_I8259, .instance_size = sizeof(PICCommonState), .parent = TYPE_PIC_COMMON, .class_init = i8259_class_init, + .class_size = sizeof(PICClass), }; static void pic_register_types(void) diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c index c2ba6a5ad9..803d037f68 100644 --- a/hw/intc/i8259_common.c +++ b/hw/intc/i8259_common.c @@ -66,35 +66,32 @@ static int pic_dispatch_post_load(void *opaque, int version_id) return 0; } -static int pic_init_common(ISADevice *dev) +static void pic_common_realize(DeviceState *dev, Error **errp) { PICCommonState *s = PIC_COMMON(dev); - PICCommonClass *info = PIC_COMMON_GET_CLASS(s); - - info->init(s); isa_register_ioport(NULL, &s->base_io, s->iobase); if (s->elcr_addr != -1) { isa_register_ioport(NULL, &s->elcr_io, s->elcr_addr); } - qdev_set_legacy_instance_id(DEVICE(dev), s->iobase, 1); - - return 0; + qdev_set_legacy_instance_id(dev, s->iobase, 1); } ISADevice *i8259_init_chip(const char *name, ISABus *bus, bool master) { - ISADevice *dev; - - dev = isa_create(bus, name); - qdev_prop_set_uint32(&dev->qdev, "iobase", master ? 0x20 : 0xa0); - qdev_prop_set_uint32(&dev->qdev, "elcr_addr", master ? 0x4d0 : 0x4d1); - qdev_prop_set_uint8(&dev->qdev, "elcr_mask", master ? 0xf8 : 0xde); - qdev_prop_set_bit(&dev->qdev, "master", master); - qdev_init_nofail(&dev->qdev); - - return dev; + DeviceState *dev; + ISADevice *isadev; + + isadev = isa_create(bus, name); + dev = DEVICE(isadev); + qdev_prop_set_uint32(dev, "iobase", master ? 0x20 : 0xa0); + qdev_prop_set_uint32(dev, "elcr_addr", master ? 0x4d0 : 0x4d1); + qdev_prop_set_uint8(dev, "elcr_mask", master ? 0xf8 : 0xde); + qdev_prop_set_bit(dev, "master", master); + qdev_init_nofail(dev); + + return isadev; } static const VMStateDescription vmstate_pic_common = { @@ -135,13 +132,12 @@ static Property pic_properties_common[] = { static void pic_common_class_init(ObjectClass *klass, void *data) { - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &vmstate_pic_common; dc->no_user = 1; dc->props = pic_properties_common; - ic->init = pic_init_common; + dc->realize = pic_common_realize; } static const TypeInfo pic_common_type = { diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c index cced9aff26..a24cb98cba 100644 --- a/hw/isa/i82378.c +++ b/hw/isa/i82378.c @@ -168,7 +168,7 @@ static void i82378_request_pic_irq(void *opaque, int irq, int level) static void i82378_init(DeviceState *dev, I82378State *s) { - ISABus *isabus = DO_UPCAST(ISABus, qbus, qdev_get_child_bus(dev, "isa.0")); + ISABus *isabus = ISA_BUS(qdev_get_child_bus(dev, "isa.0")); ISADevice *pit; ISADevice *isa; qemu_irq *out0_irq; @@ -201,7 +201,7 @@ static void i82378_init(DeviceState *dev, I82378State *s) /* 2 82C37 (dma) */ isa = isa_create_simple(isabus, "i82374"); - qdev_connect_gpio_out(&isa->qdev, 0, s->out[1]); + qdev_connect_gpio_out(DEVICE(isa), 0, s->out[1]); /* timer */ isa_create_simple(isabus, "mc146818rtc"); diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c index 7860b17d66..136d17ede0 100644 --- a/hw/isa/isa-bus.c +++ b/hw/isa/isa-bus.c @@ -55,7 +55,7 @@ ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io) qdev_init_nofail(dev); } - isabus = FROM_QBUS(ISABus, qbus_create(TYPE_ISA_BUS, dev, NULL)); + isabus = ISA_BUS(qbus_create(TYPE_ISA_BUS, dev, NULL)); isabus->address_space_io = address_space_io; return isabus; } @@ -76,7 +76,7 @@ void isa_bus_irqs(ISABus *bus, qemu_irq *irqs) */ qemu_irq isa_get_irq(ISADevice *dev, int isairq) { - assert(!dev || DO_UPCAST(ISABus, qbus, dev->qdev.parent_bus) == isabus); + assert(!dev || ISA_BUS(qdev_get_parent_bus(DEVICE(dev))) == isabus); if (isairq < 0 || isairq > 15) { hw_error("isa irq %d invalid", isairq); } @@ -119,18 +119,6 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start, portio_list_add(piolist, isabus->address_space_io, start); } -static int isa_qdev_init(DeviceState *qdev) -{ - ISADevice *dev = ISA_DEVICE(qdev); - ISADeviceClass *klass = ISA_DEVICE_GET_CLASS(dev); - - if (klass->init) { - return klass->init(dev); - } - - return 0; -} - static void isa_device_init(Object *obj) { ISADevice *dev = ISA_DEVICE(obj); @@ -147,7 +135,7 @@ ISADevice *isa_create(ISABus *bus, const char *name) hw_error("Tried to create isa device %s with no isa bus present.", name); } - dev = qdev_create(&bus->qbus, name); + dev = qdev_create(BUS(bus), name); return ISA_DEVICE(dev); } @@ -159,7 +147,7 @@ ISADevice *isa_try_create(ISABus *bus, const char *name) hw_error("Tried to create isa device %s with no isa bus present.", name); } - dev = qdev_try_create(&bus->qbus, name); + dev = qdev_try_create(BUS(bus), name); return ISA_DEVICE(dev); } @@ -168,7 +156,7 @@ ISADevice *isa_create_simple(ISABus *bus, const char *name) ISADevice *dev; dev = isa_create(bus, name); - qdev_init_nofail(&dev->qdev); + qdev_init_nofail(DEVICE(dev)); return dev; } @@ -230,7 +218,6 @@ static const TypeInfo isabus_bridge_info = { static void isa_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k = DEVICE_CLASS(klass); - k->init = isa_qdev_init; k->bus_type = TYPE_ISA_BUS; } @@ -253,7 +240,7 @@ static void isabus_register_types(void) static char *isabus_get_fw_dev_path(DeviceState *dev) { - ISADevice *d = (ISADevice*)dev; + ISADevice *d = ISA_DEVICE(dev); char path[40]; int off; diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c index 82f7c80f9c..cc426df7f8 100644 --- a/hw/isa/pc87312.c +++ b/hw/isa/pc87312.c @@ -264,7 +264,7 @@ static void pc87312_reset(DeviceState *d) pc87312_soft_reset(s); } -static int pc87312_init(ISADevice *dev) +static void pc87312_realize(DeviceState *dev, Error **errp) { PC87312State *s; DeviceState *d; @@ -276,9 +276,10 @@ static int pc87312_init(ISADevice *dev) int i; s = PC87312(dev); - bus = isa_bus_from_device(dev); + isa = ISA_DEVICE(dev); + bus = isa_bus_from_device(isa); + isa_register_ioport(isa, &s->io, s->iobase); pc87312_hard_reset(s); - isa_register_ioport(dev, &s->io, s->iobase); if (is_parallel_enabled(s)) { chr = parallel_hds[0]; @@ -345,8 +346,6 @@ static int pc87312_init(ISADevice *dev) s->ide.dev = isa; trace_pc87312_info_ide(get_ide_iobase(s)); } - - return 0; } static void pc87312_initfn(Object *obj) @@ -378,9 +377,8 @@ static Property pc87312_properties[] = { static void pc87312_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = pc87312_init; + dc->realize = pc87312_realize; dc->reset = pc87312_reset; dc->vmsd = &vmstate_pc87312; dc->props = pc87312_properties; diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c index d750413a7e..1a1d4518ce 100644 --- a/hw/isa/piix4.c +++ b/hw/isa/piix4.c @@ -98,7 +98,7 @@ int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn) PCIDevice *d; d = pci_create_simple_multifunction(bus, devfn, true, "PIIX4"); - *isa_bus = DO_UPCAST(ISABus, qbus, qdev_get_child_bus(&d->qdev, "isa.0")); + *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(d), "isa.0")); return d->devfn; } diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 52619276bd..391d90d14a 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -450,7 +450,7 @@ ISABus *vt82c686b_init(PCIBus *bus, int devfn) d = pci_create_simple_multifunction(bus, devfn, true, "VT82C686B"); - return DO_UPCAST(ISABus, qbus, qdev_get_child_bus(&d->qdev, "isa.0")); + return ISA_BUS(qdev_get_child_bus(DEVICE(d), "isa.0")); } static void via_class_init(ObjectClass *klass, void *data) diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c index 78904a816b..46f4fbd005 100644 --- a/hw/misc/applesmc.c +++ b/hw/misc/applesmc.c @@ -201,7 +201,7 @@ static void qdev_applesmc_isa_reset(DeviceState *dev) applesmc_add_key(s, "MSSD", 1, "\0x3"); } -static int applesmc_isa_init(ISADevice *dev) +static void applesmc_isa_realize(DeviceState *dev, Error **errp) { AppleSMCState *s = APPLE_SMC(dev); @@ -220,9 +220,7 @@ static int applesmc_isa_init(ISADevice *dev) } QLIST_INIT(&s->data_def); - qdev_applesmc_isa_reset(&dev->qdev); - - return 0; + qdev_applesmc_isa_reset(dev); } static Property applesmc_isa_properties[] = { @@ -235,8 +233,8 @@ static Property applesmc_isa_properties[] = { static void qdev_applesmc_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = applesmc_isa_init; + + dc->realize = applesmc_isa_realize; dc->reset = qdev_applesmc_isa_reset; dc->props = applesmc_isa_properties; } diff --git a/hw/misc/debugexit.c b/hw/misc/debugexit.c index 59bed5bff5..ee254e46d2 100644 --- a/hw/misc/debugexit.c +++ b/hw/misc/debugexit.c @@ -35,15 +35,15 @@ static const MemoryRegionOps debug_exit_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static int debug_exit_initfn(ISADevice *dev) +static void debug_exit_realizefn(DeviceState *d, Error **errp) { - ISADebugExitState *isa = ISA_DEBUG_EXIT_DEVICE(dev); + ISADevice *dev = ISA_DEVICE(d); + ISADebugExitState *isa = ISA_DEBUG_EXIT_DEVICE(d); memory_region_init_io(&isa->io, &debug_exit_ops, isa, TYPE_ISA_DEBUG_EXIT_DEVICE, isa->iosize); memory_region_add_subregion(isa_address_space_io(dev), isa->iobase, &isa->io); - return 0; } static Property debug_exit_properties[] = { @@ -55,8 +55,8 @@ static Property debug_exit_properties[] = { static void debug_exit_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = debug_exit_initfn; + + dc->realize = debug_exit_realizefn; dc->props = debug_exit_properties; } diff --git a/hw/misc/pc-testdev.c b/hw/misc/pc-testdev.c index 32df175c10..e6707d69d4 100644 --- a/hw/misc/pc-testdev.c +++ b/hw/misc/pc-testdev.c @@ -142,9 +142,10 @@ static const MemoryRegionOps test_iomem_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static int init_test_device(ISADevice *isa) +static void testdev_realizefn(DeviceState *d, Error **errp) { - PCTestdev *dev = TESTDEV(isa); + ISADevice *isa = ISA_DEVICE(d); + PCTestdev *dev = TESTDEV(d); MemoryRegion *mem = isa_address_space(isa); MemoryRegion *io = isa_address_space_io(isa); @@ -161,15 +162,13 @@ static int init_test_device(ISADevice *isa) memory_region_add_subregion(io, 0xe4, &dev->flush); memory_region_add_subregion(io, 0x2000, &dev->irq); memory_region_add_subregion(mem, 0xff000000, &dev->iomem); - - return 0; } static void testdev_class_init(ObjectClass *klass, void *data) { - ISADeviceClass *k = ISA_DEVICE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); - k->init = init_test_device; + dc->realize = testdev_realizefn; } static const TypeInfo testdev_info = { diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c index 910e44f9d2..060099b553 100644 --- a/hw/misc/pvpanic.c +++ b/hw/misc/pvpanic.c @@ -86,14 +86,21 @@ static const MemoryRegionOps pvpanic_ops = { }, }; -static int pvpanic_isa_initfn(ISADevice *dev) +static void pvpanic_isa_initfn(Object *obj) { + PVPanicState *s = ISA_PVPANIC_DEVICE(obj); + + memory_region_init_io(&s->io, &pvpanic_ops, s, "pvpanic", 1); +} + +static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp) +{ + ISADevice *d = ISA_DEVICE(dev); PVPanicState *s = ISA_PVPANIC_DEVICE(dev); static bool port_configured; FWCfgState *fw_cfg; - memory_region_init_io(&s->io, &pvpanic_ops, s, "pvpanic", 1); - isa_register_ioport(dev, &s->io, s->ioport); + isa_register_ioport(d, &s->io, s->ioport); if (!port_configured) { fw_cfg = fw_cfg_find(); @@ -104,8 +111,6 @@ static int pvpanic_isa_initfn(ISADevice *dev) port_configured = true; } } - - return 0; } int pvpanic_init(ISABus *bus) @@ -122,9 +127,8 @@ static Property pvpanic_isa_properties[] = { static void pvpanic_isa_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = pvpanic_isa_initfn; + dc->realize = pvpanic_isa_realizefn; dc->no_user = 1; dc->props = pvpanic_isa_properties; } @@ -133,6 +137,7 @@ static TypeInfo pvpanic_isa_info = { .name = TYPE_ISA_PVPANIC_DEVICE, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof(PVPanicState), + .instance_init = pvpanic_isa_initfn, .class_init = pvpanic_isa_class_init, }; diff --git a/hw/misc/sga.c b/hw/misc/sga.c index c842190999..08803e7ddc 100644 --- a/hw/misc/sga.c +++ b/hw/misc/sga.c @@ -38,17 +38,16 @@ typedef struct ISASGAState { ISADevice parent_obj; } ISASGAState; -static int sga_initfn(ISADevice *dev) +static void sga_realizefn(DeviceState *dev, Error **errp) { rom_add_vga(SGABIOS_FILENAME); - return 0; } static void sga_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = sga_initfn; + + dc->realize = sga_realizefn; dc->desc = "Serial Graphics Adapter"; } diff --git a/hw/misc/vmport.c b/hw/misc/vmport.c index c14612905b..57b71f5248 100644 --- a/hw/misc/vmport.c +++ b/hw/misc/vmport.c @@ -137,25 +137,25 @@ static const MemoryRegionOps vmport_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static int vmport_initfn(ISADevice *dev) +static void vmport_realizefn(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); VMPortState *s = VMPORT(dev); memory_region_init_io(&s->io, &vmport_ops, s, "vmport", 1); - isa_register_ioport(dev, &s->io, 0x5658); + isa_register_ioport(isadev, &s->io, 0x5658); port_state = s; /* Register some generic port commands */ vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL); vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL); - return 0; } static void vmport_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = vmport_initfn; + + dc->realize = vmport_realizefn; dc->no_user = 1; } diff --git a/hw/net/ne2000-isa.c b/hw/net/ne2000-isa.c index f8e610cfa2..9232abd466 100644 --- a/hw/net/ne2000-isa.c +++ b/hw/net/ne2000-isa.c @@ -66,24 +66,23 @@ static const VMStateDescription vmstate_isa_ne2000 = { } }; -static int isa_ne2000_initfn(ISADevice *dev) +static void isa_ne2000_realizefn(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); ISANE2000State *isa = ISA_NE2000(dev); NE2000State *s = &isa->ne2000; ne2000_setup_io(s, 0x20); - isa_register_ioport(dev, &s->io, isa->iobase); + isa_register_ioport(isadev, &s->io, isa->iobase); - isa_init_irq(dev, &s->irq, isa->isairq); + isa_init_irq(isadev, &s->irq, isa->isairq); qemu_macaddr_default_if_unset(&s->c.macaddr); ne2000_reset(s); s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c, - object_get_typename(OBJECT(dev)), dev->qdev.id, s); + object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a); - - return 0; } static Property ne2000_isa_properties[] = { @@ -96,8 +95,8 @@ static Property ne2000_isa_properties[] = { static void isa_ne2000_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = isa_ne2000_initfn; + + dc->realize = isa_ne2000_realizefn; dc->props = ne2000_isa_properties; } diff --git a/hw/pci/pci.c b/hw/pci/pci.c index bb3879bd88..a3eb19ead2 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1700,7 +1700,7 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS; } - bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev)); + bus = PCI_BUS(qdev_get_parent_bus(qdev)); pci_dev = do_pci_register_device(pci_dev, bus, object_get_typename(OBJECT(qdev)), pci_dev->devfn); diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index be8a50ec4a..4fdc1649fd 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -601,12 +601,13 @@ static void ppc_prep_init(QEMUMachineInitArgs *args) sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11)); sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9)); sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11)); - isa_bus = DO_UPCAST(ISABus, qbus, qdev_get_child_bus(&pci->qdev, "isa.0")); + isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci), "isa.0")); /* Super I/O (parallel + serial ports) */ isa = isa_create(isa_bus, TYPE_PC87312); - qdev_prop_set_uint8(&isa->qdev, "config", 13); /* fdc, ser0, ser1, par0 */ - qdev_init_nofail(&isa->qdev); + dev = DEVICE(isa); + qdev_prop_set_uint8(dev, "config", 13); /* fdc, ser0, ser1, par0 */ + qdev_init_nofail(dev); /* Register 8 MB of ISA IO space (needed for non-contiguous map) */ memory_region_init_io(PPC_io_memory, &PPC_prep_io_ops, sysctrl, diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index 2c2a111711..a6a3b76a76 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -585,8 +585,7 @@ pci_ebus_init(PCIBus *bus, int devfn, qemu_irq *irqs) ISABus *isa_bus; pci_dev = pci_create_simple(bus, devfn, "ebus"); - isa_bus = DO_UPCAST(ISABus, qbus, - qdev_get_child_bus(&pci_dev->qdev, "isa.0")); + isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci_dev), "isa.0")); isa_irq = qemu_allocate_irqs(isa_irq_handler, irqs, 16); isa_bus_irqs(isa_bus, isa_irq); return isa_bus; diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c index 1264d9da23..2c25260875 100644 --- a/hw/ssi/ssi.c +++ b/hw/ssi/ssi.c @@ -103,7 +103,7 @@ SSIBus *ssi_create_bus(DeviceState *parent, const char *name) { BusState *bus; bus = qbus_create(TYPE_SSI_BUS, parent, name); - return FROM_QBUS(SSIBus, bus); + return SSI_BUS(bus); } uint32_t ssi_transfer(SSIBus *bus, uint32_t val) diff --git a/hw/timer/i8254.c b/hw/timer/i8254.c index 20c0c3601d..16c8dd687f 100644 --- a/hw/timer/i8254.c +++ b/hw/timer/i8254.c @@ -35,6 +35,15 @@ #define RW_STATE_WORD0 3 #define RW_STATE_WORD1 4 +#define PIT_CLASS(class) OBJECT_CLASS_CHECK(PITClass, (class), TYPE_I8254) +#define PIT_GET_CLASS(obj) OBJECT_GET_CLASS(PITClass, (obj), TYPE_I8254) + +typedef struct PITClass { + PITCommonClass parent_class; + + DeviceRealize parent_realize; +} PITClass; + static void pit_irq_timer_update(PITChannelState *s, int64_t current_time); static int pit_get_count(PITChannelState *s) @@ -265,7 +274,7 @@ static void pit_irq_timer(void *opaque) static void pit_reset(DeviceState *dev) { - PITCommonState *pit = DO_UPCAST(PITCommonState, dev.qdev, dev); + PITCommonState *pit = PIT_COMMON(dev); PITChannelState *s; pit_reset_common(pit); @@ -313,20 +322,22 @@ static void pit_post_load(PITCommonState *s) } } -static int pit_initfn(PITCommonState *pit) +static void pit_realizefn(DeviceState *dev, Error **err) { + PITCommonState *pit = PIT_COMMON(dev); + PITClass *pc = PIT_GET_CLASS(dev); PITChannelState *s; s = &pit->channels[0]; /* the timer 0 is connected to an IRQ */ s->irq_timer = qemu_new_timer_ns(vm_clock, pit_irq_timer, s); - qdev_init_gpio_out(&pit->dev.qdev, &s->irq, 1); + qdev_init_gpio_out(dev, &s->irq, 1); memory_region_init_io(&pit->ioports, &pit_ioport_ops, pit, "pit", 4); - qdev_init_gpio_in(&pit->dev.qdev, pit_irq_control, 1); + qdev_init_gpio_in(dev, pit_irq_control, 1); - return 0; + pc->parent_realize(dev, err); } static Property pit_properties[] = { @@ -336,10 +347,12 @@ static Property pit_properties[] = { static void pit_class_initfn(ObjectClass *klass, void *data) { + PITClass *pc = PIT_CLASS(klass); PITCommonClass *k = PIT_COMMON_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - k->init = pit_initfn; + pc->parent_realize = dc->realize; + dc->realize = pit_realizefn; k->set_channel_gate = pit_set_channel_gate; k->get_channel_info = pit_get_channel_info_common; k->post_load = pit_post_load; @@ -348,10 +361,11 @@ static void pit_class_initfn(ObjectClass *klass, void *data) } static const TypeInfo pit_info = { - .name = "isa-pit", + .name = TYPE_I8254, .parent = TYPE_PIT_COMMON, .instance_size = sizeof(PITCommonState), .class_init = pit_class_initfn, + .class_size = sizeof(PITClass), }; static void pit_register_types(void) diff --git a/hw/timer/i8254_common.c b/hw/timer/i8254_common.c index 5342df4a34..4e5bf0b63c 100644 --- a/hw/timer/i8254_common.c +++ b/hw/timer/i8254_common.c @@ -166,22 +166,14 @@ void pit_reset_common(PITCommonState *pit) } } -static int pit_init_common(ISADevice *dev) +static void pit_common_realize(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); PITCommonState *pit = PIT_COMMON(dev); - PITCommonClass *c = PIT_COMMON_GET_CLASS(pit); - int ret; - - ret = c->init(pit); - if (ret < 0) { - return ret; - } - isa_register_ioport(dev, &pit->ioports, pit->iobase); + isa_register_ioport(isadev, &pit->ioports, pit->iobase); - qdev_set_legacy_instance_id(&dev->qdev, pit->iobase, 2); - - return 0; + qdev_set_legacy_instance_id(dev, pit->iobase, 2); } static const VMStateDescription vmstate_pit_channel = { @@ -286,10 +278,9 @@ static const VMStateDescription vmstate_pit_common = { static void pit_common_class_init(ObjectClass *klass, void *data) { - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - ic->init = pit_init_common; + dc->realize = pit_common_realize; dc->vmsd = &vmstate_pit_common; dc->no_user = 1; } diff --git a/hw/timer/m48t59.c b/hw/timer/m48t59.c index 45753d88c5..bf6c4c876c 100644 --- a/hw/timer/m48t59.c +++ b/hw/timer/m48t59.c @@ -691,7 +691,7 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size, return s; } -static void m48t59_init_common(M48t59State *s) +static void m48t59_realize_common(M48t59State *s, Error **errp) { s->buffer = g_malloc0(s->size); if (s->model == 59) { @@ -703,27 +703,31 @@ static void m48t59_init_common(M48t59State *s) vmstate_register(NULL, -1, &vmstate_m48t59, s); } -static int m48t59_init_isa1(ISADevice *dev) +static void m48t59_isa_realize(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); M48t59ISAState *d = ISA_M48T59(dev); M48t59State *s = &d->state; - isa_init_irq(dev, &s->IRQ, 8); - m48t59_init_common(s); - - return 0; + isa_init_irq(isadev, &s->IRQ, 8); + m48t59_realize_common(s, errp); } static int m48t59_init1(SysBusDevice *dev) { M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev); M48t59State *s = &d->state; + Error *err = NULL; sysbus_init_irq(dev, &s->IRQ); memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size); sysbus_init_mmio(dev, &s->iomem); - m48t59_init_common(s); + m48t59_realize_common(s, &err); + if (err != NULL) { + error_free(err); + return -1; + } return 0; } @@ -738,8 +742,8 @@ static Property m48t59_isa_properties[] = { static void m48t59_isa_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = m48t59_init_isa1; + + dc->realize = m48t59_isa_realize; dc->no_user = 1; dc->reset = m48t59_reset_isa; dc->props = m48t59_isa_properties; diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 481604de35..9c4a7bd074 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -814,8 +814,9 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque, visit_end_struct(v, errp); } -static int rtc_initfn(ISADevice *dev) +static void rtc_realizefn(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); RTCState *s = MC146818_RTC(dev); int base = 0x70; @@ -836,7 +837,7 @@ static int rtc_initfn(ISADevice *dev) s->base_year = 0; } - rtc_set_date_from_host(dev); + rtc_set_date_from_host(isadev); #ifdef TARGET_I386 switch (s->lost_tick_policy) { @@ -847,7 +848,8 @@ static int rtc_initfn(ISADevice *dev) case LOST_TICK_DISCARD: break; default: - return -EINVAL; + error_setg(errp, "Invalid lost tick policy."); + return; } #endif @@ -862,15 +864,13 @@ static int rtc_initfn(ISADevice *dev) qemu_register_suspend_notifier(&s->suspend_notifier); memory_region_init_io(&s->io, &cmos_ops, s, "rtc", 2); - isa_register_ioport(dev, &s->io, base); + isa_register_ioport(isadev, &s->io, base); - qdev_set_legacy_instance_id(&dev->qdev, base, 3); + qdev_set_legacy_instance_id(dev, base, 3); qemu_register_reset(rtc_reset, s); object_property_add(OBJECT(s), "date", "struct tm", rtc_get_date, NULL, NULL, s, NULL); - - return 0; } ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq) @@ -902,8 +902,8 @@ static Property mc146818rtc_properties[] = { static void rtc_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = rtc_initfn; + + dc->realize = rtc_realizefn; dc->no_user = 1; dc->vmsd = &vmstate_rtc; dc->props = mc146818rtc_properties; diff --git a/hw/watchdog/wdt_ib700.c b/hw/watchdog/wdt_ib700.c index 6b8e33a286..d85c8945ec 100644 --- a/hw/watchdog/wdt_ib700.c +++ b/hw/watchdog/wdt_ib700.c @@ -97,7 +97,7 @@ static const VMStateDescription vmstate_ib700 = { } }; -static int wdt_ib700_init(ISADevice *dev) +static void wdt_ib700_realize(DeviceState *dev, Error **errp) { IB700State *s = IB700(dev); @@ -106,8 +106,6 @@ static int wdt_ib700_init(ISADevice *dev) s->timer = qemu_new_timer_ns(vm_clock, ib700_timer_expired, s); register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, s); register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, s); - - return 0; } static void wdt_ib700_reset(DeviceState *dev) @@ -127,8 +125,8 @@ static WatchdogTimerModel model = { static void wdt_ib700_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = wdt_ib700_init; + + dc->realize = wdt_ib700_realize; dc->reset = wdt_ib700_reset; dc->vmsd = &vmstate_ib700; } |