Skip to content

Commit

Permalink
Merge branch 'realize-isa.v2' of git://github.com/afaerber/qemu-cpu
Browse files Browse the repository at this point in the history
* '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
  • Loading branch information
blueswirl committed Jun 15, 2013
2 parents 22bfa16 + fef7fbc commit 371a775
Show file tree
Hide file tree
Showing 53 changed files with 535 additions and 391 deletions.
23 changes: 11 additions & 12 deletions hw/audio/adlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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[] = {
Expand All @@ -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;
}
Expand Down
38 changes: 23 additions & 15 deletions hw/audio/cs4231a.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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,
};

Expand Down
27 changes: 15 additions & 12 deletions hw/audio/gus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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,
Expand Down
19 changes: 12 additions & 7 deletions hw/audio/pcspk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand All @@ -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;
}
Expand All @@ -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,
};

Expand Down
21 changes: 14 additions & 7 deletions hw/audio/sb16.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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,
};

Expand Down
Loading

0 comments on commit 371a775

Please sign in to comment.