aboutsummaryrefslogtreecommitdiff
path: root/hw/audio
diff options
context:
space:
mode:
authorAndreas Färber <afaerber@suse.de>2012-11-25 02:37:14 +0100
committerAndreas Färber <afaerber@suse.de>2013-06-07 12:14:45 +0200
commitdb895a1e6a97e919f9b86d60c969377357b05066 (patch)
tree72f6786abe90f7fa77d2f10416df73cb9d62e35a /hw/audio
parenta3dcca567a1d4a5c79fb9c8fe2d9a21a4a7cebd5 (diff)
downloadqemu-db895a1e6a97e919f9b86d60c969377357b05066.zip
qemu-db895a1e6a97e919f9b86d60c969377357b05066.tar.gz
qemu-db895a1e6a97e919f9b86d60c969377357b05066.tar.bz2
isa: Use realizefn for ISADevice
Drop ISADeviceClass::init and the resulting no-op initfn and let children implement their own realizefn. Adapt error handling. Split off an instance_init where sensible. Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'hw/audio')
-rw-r--r--hw/audio/adlib.c23
-rw-r--r--hw/audio/cs4231a.c21
-rw-r--r--hw/audio/gus.c18
-rw-r--r--hw/audio/pcspk.c19
-rw-r--r--hw/audio/sb16.c21
5 files changed, 60 insertions, 42 deletions
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index fc20857..6a7d377 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 d3ce739..605dad4 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -644,19 +644,25 @@ static const MemoryRegionOps cs_ioport_ops = {
}
};
-static int cs4231a_initfn (ISADevice *dev)
+static void cs4231a_initfn (Object *obj)
{
+ CSState *s = CS4231A (obj);
+
+ memory_region_init_io (&s->ioports, &cs_ioport_ops, s, "cs4231a", 4);
+}
+
+static void cs4231a_realizefn (DeviceState *dev, Error **errp)
+{
+ ISADevice *d = ISA_DEVICE (dev);
CSState *s = CS4231A (dev);
- isa_init_irq (dev, &s->pic, s->irq);
+ isa_init_irq (d, &s->pic, s->irq);
- memory_region_init_io (&s->ioports, &cs_ioport_ops, s, "cs4231a", 4);
- isa_register_ioport (dev, &s->ioports, s->port);
+ 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)
@@ -675,8 +681,8 @@ 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;
@@ -687,6 +693,7 @@ static const TypeInfo cs4231a_info = {
.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 e0aea26..f45ed0b 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -251,8 +251,9 @@ static const MemoryRegionPortio gus_portio_list2[] = {
PORTIO_END_OF_LIST (),
};
-static int gus_initfn (ISADevice *dev)
+static void gus_realizefn (DeviceState *dev, Error **errp)
{
+ ISADevice *d = ISA_DEVICE(dev);
GUSState *s = GUS (dev);
struct audsettings as;
@@ -274,26 +275,25 @@ 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)
@@ -313,8 +313,8 @@ 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;
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 3a7285f..5dde0e7 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 6ddc0ac..e697bc1 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,
};