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/char | |
parent | 22bfa16ed3d4c9d534dcfe6f2381a654f32296b9 (diff) | |
parent | fef7fbc92496f5f6d2b7395263830bce15ebf410 (diff) | |
download | qemu-371a775dc18ece3ff7d77328d1ee28cb2d473706.zip qemu-371a775dc18ece3ff7d77328d1ee28cb2d473706.tar.gz qemu-371a775dc18ece3ff7d77328d1ee28cb2d473706.tar.bz2 |
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/char')
-rw-r--r-- | hw/char/debugcon.c | 23 | ||||
-rw-r--r-- | hw/char/parallel.c | 29 | ||||
-rw-r--r-- | hw/char/serial-isa.c | 34 | ||||
-rw-r--r-- | hw/char/serial-pci.c | 17 | ||||
-rw-r--r-- | hw/char/serial.c | 22 |
5 files changed, 82 insertions, 43 deletions
diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c index 3b0637d..f254841 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 8e48284..caa9eb4 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 342b4cc..e06a802 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 2138e35..3bec8eb 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 017610e..b537e42 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -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, |