diff options
author | Blue Swirl <blauwirbel@gmail.com> | 2013-06-15 10:53:44 +0000 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2013-06-15 10:53:44 +0000 |
commit | 371a775dc18ece3ff7d77328d1ee28cb2d473706 (patch) | |
tree | 328c5e856f25c5f0176d9361b641e8061e093ae2 /hw/audio | |
parent | 22bfa16ed3d4c9d534dcfe6f2381a654f32296b9 (diff) | |
parent | fef7fbc92496f5f6d2b7395263830bce15ebf410 (diff) |
Merge branch 'realize-isa.v2' of git://github.com/afaerber/qemu-cpu
* 'realize-isa.v2' of git://github.com/afaerber/qemu-cpu:
qdev: Drop FROM_QBUS() macro
isa: QOM'ify ISADevice
isa: QOM'ify ISABus
i8259: Convert PICCommonState to use QOM realizefn
kvm/i8259: QOM'ify some more
i8259: QOM'ify some more
i8254: Convert PITCommonState to QOM realizefn
kvm/i8254: QOM'ify some more
i8254: QOM'ify some more
isa: Use realizefn for ISADevice
cs4231a: QOM'ify some more
gus: QOM'ify some more
Diffstat (limited to 'hw/audio')
-rw-r--r-- | hw/audio/adlib.c | 23 | ||||
-rw-r--r-- | hw/audio/cs4231a.c | 38 | ||||
-rw-r--r-- | hw/audio/gus.c | 27 | ||||
-rw-r--r-- | hw/audio/pcspk.c | 19 | ||||
-rw-r--r-- | hw/audio/sb16.c | 21 |
5 files changed, 75 insertions, 53 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/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, }; |