Eliminate DO_UPCAST() for PICCommonState. Prepares for ISA realizefn.

Also give the i8259_common type registration functions unique names
while at it.

Signed-off-by: Andreas Färber <afaer...@suse.de>
---
 hw/i8259.c          |   18 ++++++++++--------
 hw/i8259_common.c   |   10 +++++-----
 hw/i8259_internal.h |    3 ++-
 hw/kvm/i8259.c      |    4 ++--
 4 Dateien geändert, 19 Zeilen hinzugefügt(+), 16 Zeilen entfernt(-)

diff --git a/hw/i8259.c b/hw/i8259.c
index af0ba4d..55c2cb9 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -182,7 +182,7 @@ static void pic_intack(PICCommonState *s, int irq)
 
 int pic_read_irq(DeviceState *d)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, d);
+    PICCommonState *s = PIC_COMMON(d);
     int irq, irq2, intno;
 
     irq = pic_get_irq(s);
@@ -229,7 +229,7 @@ static void pic_init_reset(PICCommonState *s)
 
 static void pic_reset(DeviceState *dev)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, dev);
+    PICCommonState *s = PIC_COMMON(dev);
 
     s->elcr = 0;
     pic_init_reset(s);
@@ -361,7 +361,7 @@ static uint64_t pic_ioport_read(void *opaque, hwaddr addr,
 
 int pic_get_output(DeviceState *d)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, d);
+    PICCommonState *s = PIC_COMMON(d);
 
     return (pic_get_irq(s) >= 0);
 }
@@ -400,11 +400,13 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {
 
 static void pic_init(PICCommonState *s)
 {
+    DeviceState *dev = DEVICE(s);
+
     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(&s->dev.qdev, s->int_out, ARRAY_SIZE(s->int_out));
-    qdev_init_gpio_in(&s->dev.qdev, pic_set_irq, 8);
+    qdev_init_gpio_out(dev, s->int_out, ARRAY_SIZE(s->int_out));
+    qdev_init_gpio_in(dev, pic_set_irq, 8);
 }
 
 void pic_info(Monitor *mon)
@@ -416,7 +418,7 @@ void pic_info(Monitor *mon)
         return;
     }
     for (i = 0; i < 2; i++) {
-        s = i == 0 ? DO_UPCAST(PICCommonState, dev.qdev, isa_pic) : slave_pic;
+        s = i == 0 ? PIC_COMMON(isa_pic) : slave_pic;
         monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
                        "irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
                        i, s->irr, s->imr, s->isr, s->priority_add,
@@ -467,7 +469,7 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
         irq_set[i + 8] = qdev_get_gpio_in(&dev->qdev, i);
     }
 
-    slave_pic = DO_UPCAST(PICCommonState, dev, dev);
+    slave_pic = PIC_COMMON(dev);
 
     return irq_set;
 }
@@ -481,7 +483,7 @@ static void i8259_class_init(ObjectClass *klass, void *data)
     dc->reset = pic_reset;
 }
 
-static TypeInfo i8259_info = {
+static const TypeInfo i8259_info = {
     .name       = "isa-i8259",
     .instance_size = sizeof(PICCommonState),
     .parent     = TYPE_PIC_COMMON,
diff --git a/hw/i8259_common.c b/hw/i8259_common.c
index ab3d98b..418c485 100644
--- a/hw/i8259_common.c
+++ b/hw/i8259_common.c
@@ -68,7 +68,7 @@ static int pic_dispatch_post_load(void *opaque, int 
version_id)
 
 static int pic_init_common(ISADevice *dev)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev, dev);
+    PICCommonState *s = PIC_COMMON(dev);
     PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
 
     info->init(s);
@@ -78,7 +78,7 @@ static int pic_init_common(ISADevice *dev)
         isa_register_ioport(NULL, &s->elcr_io, s->elcr_addr);
     }
 
-    qdev_set_legacy_instance_id(&s->dev.qdev, s->iobase, 1);
+    qdev_set_legacy_instance_id(DEVICE(dev), s->iobase, 1);
 
     return 0;
 }
@@ -144,7 +144,7 @@ static void pic_common_class_init(ObjectClass *klass, void 
*data)
     ic->init = pic_init_common;
 }
 
-static TypeInfo pic_common_type = {
+static const TypeInfo pic_common_type = {
     .name = TYPE_PIC_COMMON,
     .parent = TYPE_ISA_DEVICE,
     .instance_size = sizeof(PICCommonState),
@@ -153,9 +153,9 @@ static TypeInfo pic_common_type = {
     .abstract = true,
 };
 
-static void register_types(void)
+static void pic_common_register_types(void)
 {
     type_register_static(&pic_common_type);
 }
 
-type_init(register_types);
+type_init(pic_common_register_types);
diff --git a/hw/i8259_internal.h b/hw/i8259_internal.h
index 8785b1d..32e48c3 100644
--- a/hw/i8259_internal.h
+++ b/hw/i8259_internal.h
@@ -48,7 +48,8 @@ typedef struct PICCommonClass
 } PICCommonClass;
 
 struct PICCommonState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     uint8_t last_irr; /* edge detection */
     uint8_t irr; /* interrupt request register */
     uint8_t imr; /* interrupt mask register */
diff --git a/hw/kvm/i8259.c b/hw/kvm/i8259.c
index 1e24cd4..2aaf14a 100644
--- a/hw/kvm/i8259.c
+++ b/hw/kvm/i8259.c
@@ -82,7 +82,7 @@ static void kvm_pic_put(PICCommonState *s)
 
 static void kvm_pic_reset(DeviceState *dev)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, dev);
+    PICCommonState *s = PIC_COMMON(dev);
 
     s->elcr = 0;
     pic_reset_common(s);
@@ -123,7 +123,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, void 
*data)
     k->post_load  = kvm_pic_put;
 }
 
-static TypeInfo kvm_i8259_info = {
+static const TypeInfo kvm_i8259_info = {
     .name  = "kvm-i8259",
     .parent = TYPE_PIC_COMMON,
     .instance_size = sizeof(PICCommonState),
-- 
1.7.10.4


Reply via email to