From db895a1e6a97e919f9b86d60c969377357b05066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 25 Nov 2012 02:37:14 +0100 Subject: isa: Use realizefn for ISADevice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- hw/intc/i8259_common.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'hw/intc') diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c index c2ba6a5..a3dee38 100644 --- a/hw/intc/i8259_common.c +++ b/hw/intc/i8259_common.c @@ -66,7 +66,7 @@ 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); @@ -78,9 +78,7 @@ static int pic_init_common(ISADevice *dev) 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) @@ -135,13 +133,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 = { -- cgit v1.1 From d1eebf4e3df8882d7be6377e1251123b6c16b9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 25 Nov 2012 22:35:49 +0100 Subject: i8259: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant. Prepares for PIC realizefn. Signed-off-by: Andreas Färber --- hw/intc/i8259.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'hw/intc') diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c index fef00fc..1b513ff 100644 --- a/hw/intc/i8259.c +++ b/hw/intc/i8259.c @@ -41,6 +41,8 @@ //#define DEBUG_IRQ_LATENCY //#define DEBUG_IRQ_COUNT +#define TYPE_I8259 "isa-i8259" + #if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT) static int irq_level[16]; #endif @@ -448,25 +450,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); @@ -484,7 +489,7 @@ static void i8259_class_init(ObjectClass *klass, void *data) } static const TypeInfo i8259_info = { - .name = "isa-i8259", + .name = TYPE_I8259, .instance_size = sizeof(PICCommonState), .parent = TYPE_PIC_COMMON, .class_init = i8259_class_init, -- cgit v1.1 From d2628b7d18521dacd3d4d246602e9bb3fc2a43dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 25 Nov 2012 22:54:47 +0100 Subject: i8259: Convert PICCommonState to use QOM realizefn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of having the parent provide PICCommonClass::init, let the children override DeviceClass::realize themselves. This pushes the responsibility of saving and calling the parent's realizefn to the children. Signed-off-by: Andreas Färber --- hw/intc/i8259.c | 25 +++++++++++++++++++++---- hw/intc/i8259_common.c | 3 --- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'hw/intc') diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c index 1b513ff..192a0ba 100644 --- a/hw/intc/i8259.c +++ b/hw/intc/i8259.c @@ -42,6 +42,18 @@ //#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]; @@ -400,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) @@ -481,10 +496,11 @@ 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; } @@ -493,6 +509,7 @@ static const TypeInfo i8259_info = { .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 a3dee38..7613547 100644 --- a/hw/intc/i8259_common.c +++ b/hw/intc/i8259_common.c @@ -69,9 +69,6 @@ static int pic_dispatch_post_load(void *opaque, int version_id) 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) { -- cgit v1.1 From 4a17cc4f285d7ffe41847bf728cd88c736237416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 7 Jun 2013 13:49:13 +0200 Subject: isa: QOM'ify ISADevice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename its parent field and use DEVICE() where necessary. Signed-off-by: Andreas Färber --- hw/intc/i8259_common.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'hw/intc') diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c index 7613547..803d037 100644 --- a/hw/intc/i8259_common.c +++ b/hw/intc/i8259_common.c @@ -80,16 +80,18 @@ static void pic_common_realize(DeviceState *dev, Error **errp) 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 = { -- cgit v1.1