aboutsummaryrefslogtreecommitdiff
path: root/hw/timer/i8254.c
diff options
context:
space:
mode:
authorAndreas Färber <afaerber@suse.de>2012-11-25 18:47:58 +0100
committerAndreas Färber <afaerber@suse.de>2013-06-07 14:55:24 +0200
commita15d09127b104d1c35fc22bdd65263fe62462b30 (patch)
tree6e1c6bc2916319b3c581442907c1c8b680b6f378 /hw/timer/i8254.c
parent58cd986422d7353e7fac56969ac59daab3cdca67 (diff)
i8254: Convert PITCommonState to QOM realizefn
Instead of having the parent provide PITCommonClass::init, let the children override DeviceClass::realize themselves. This pushes the responsibility for saving and calling the parent's realizefn to the children. Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'hw/timer/i8254.c')
-rw-r--r--hw/timer/i8254.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/hw/timer/i8254.c b/hw/timer/i8254.c
index efbca19df7..16c8dd687f 100644
--- a/hw/timer/i8254.c
+++ b/hw/timer/i8254.c
@@ -35,6 +35,15 @@
#define RW_STATE_WORD0 3
#define RW_STATE_WORD1 4
+#define PIT_CLASS(class) OBJECT_CLASS_CHECK(PITClass, (class), TYPE_I8254)
+#define PIT_GET_CLASS(obj) OBJECT_GET_CLASS(PITClass, (obj), TYPE_I8254)
+
+typedef struct PITClass {
+ PITCommonClass parent_class;
+
+ DeviceRealize parent_realize;
+} PITClass;
+
static void pit_irq_timer_update(PITChannelState *s, int64_t current_time);
static int pit_get_count(PITChannelState *s)
@@ -313,20 +322,22 @@ static void pit_post_load(PITCommonState *s)
}
}
-static int pit_initfn(PITCommonState *pit)
+static void pit_realizefn(DeviceState *dev, Error **err)
{
+ PITCommonState *pit = PIT_COMMON(dev);
+ PITClass *pc = PIT_GET_CLASS(dev);
PITChannelState *s;
s = &pit->channels[0];
/* the timer 0 is connected to an IRQ */
s->irq_timer = qemu_new_timer_ns(vm_clock, pit_irq_timer, s);
- qdev_init_gpio_out(&pit->dev.qdev, &s->irq, 1);
+ qdev_init_gpio_out(dev, &s->irq, 1);
memory_region_init_io(&pit->ioports, &pit_ioport_ops, pit, "pit", 4);
- qdev_init_gpio_in(&pit->dev.qdev, pit_irq_control, 1);
+ qdev_init_gpio_in(dev, pit_irq_control, 1);
- return 0;
+ pc->parent_realize(dev, err);
}
static Property pit_properties[] = {
@@ -336,10 +347,12 @@ static Property pit_properties[] = {
static void pit_class_initfn(ObjectClass *klass, void *data)
{
+ PITClass *pc = PIT_CLASS(klass);
PITCommonClass *k = PIT_COMMON_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
- k->init = pit_initfn;
+ pc->parent_realize = dc->realize;
+ dc->realize = pit_realizefn;
k->set_channel_gate = pit_set_channel_gate;
k->get_channel_info = pit_get_channel_info_common;
k->post_load = pit_post_load;
@@ -352,6 +365,7 @@ static const TypeInfo pit_info = {
.parent = TYPE_PIT_COMMON,
.instance_size = sizeof(PITCommonState),
.class_init = pit_class_initfn,
+ .class_size = sizeof(PITClass),
};
static void pit_register_types(void)