aboutsummaryrefslogtreecommitdiff
path: root/hw/i386/kvm/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/i386/kvm/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/i386/kvm/i8254.c')
-rw-r--r--hw/i386/kvm/i8254.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/hw/i386/kvm/i8254.c b/hw/i386/kvm/i8254.c
index 4ac555126b..93a3669746 100644
--- a/hw/i386/kvm/i8254.c
+++ b/hw/i386/kvm/i8254.c
@@ -33,6 +33,10 @@
#define CALIBRATION_ROUNDS 3
#define KVM_PIT(obj) OBJECT_CHECK(KVMPITState, (obj), TYPE_KVM_I8254)
+#define KVM_PIT_CLASS(class) \
+ OBJECT_CLASS_CHECK(KVMPITClass, (class), TYPE_KVM_I8254)
+#define KVM_PIT_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(KVMPITClass, (obj), TYPE_KVM_I8254)
typedef struct KVMPITState {
PITCommonState parent_obj;
@@ -42,6 +46,12 @@ typedef struct KVMPITState {
int64_t kernel_clock_offset;
} KVMPITState;
+typedef struct KVMPITClass {
+ PITCommonClass parent_class;
+
+ DeviceRealize parent_realize;
+} KVMPITClass;
+
static int64_t abs64(int64_t v)
{
return v < 0 ? -v : v;
@@ -237,8 +247,10 @@ static void kvm_pit_vm_state_change(void *opaque, int running,
}
}
-static int kvm_pit_initfn(PITCommonState *pit)
+static void kvm_pit_realizefn(DeviceState *dev, Error **errp)
{
+ PITCommonState *pit = PIT_COMMON(dev);
+ KVMPITClass *kpc = KVM_PIT_GET_CLASS(dev);
KVMPITState *s = KVM_PIT(pit);
struct kvm_pit_config config = {
.flags = 0,
@@ -251,9 +263,9 @@ static int kvm_pit_initfn(PITCommonState *pit)
ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_PIT);
}
if (ret < 0) {
- fprintf(stderr, "Create kernel PIC irqchip failed: %s\n",
- strerror(ret));
- return ret;
+ error_setg(errp, "Create kernel PIC irqchip failed: %s",
+ strerror(ret));
+ return;
}
switch (s->lost_tick_policy) {
case LOST_TICK_DELAY:
@@ -264,24 +276,25 @@ static int kvm_pit_initfn(PITCommonState *pit)
ret = kvm_vm_ioctl(kvm_state, KVM_REINJECT_CONTROL, &control);
if (ret < 0) {
- fprintf(stderr,
- "Can't disable in-kernel PIT reinjection: %s\n",
- strerror(ret));
- return ret;
+ error_setg(errp,
+ "Can't disable in-kernel PIT reinjection: %s",
+ strerror(ret));
+ return;
}
}
break;
default:
- return -EINVAL;
+ error_setg(errp, "Lost tick policy not supported.");
+ return;
}
memory_region_init_reservation(&pit->ioports, "kvm-pit", 4);
- qdev_init_gpio_in(&pit->dev.qdev, kvm_pit_irq_control, 1);
+ qdev_init_gpio_in(dev, kvm_pit_irq_control, 1);
qemu_add_vm_change_state_handler(kvm_pit_vm_state_change, s);
- return 0;
+ kpc->parent_realize(dev, errp);
}
static Property kvm_pit_properties[] = {
@@ -293,10 +306,12 @@ static Property kvm_pit_properties[] = {
static void kvm_pit_class_init(ObjectClass *klass, void *data)
{
+ KVMPITClass *kpc = KVM_PIT_CLASS(klass);
PITCommonClass *k = PIT_COMMON_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
- k->init = kvm_pit_initfn;
+ kpc->parent_realize = dc->realize;
+ dc->realize = kvm_pit_realizefn;
k->set_channel_gate = kvm_pit_set_gate;
k->get_channel_info = kvm_pit_get_channel_info;
k->pre_save = kvm_pit_get;
@@ -310,6 +325,7 @@ static const TypeInfo kvm_pit_info = {
.parent = TYPE_PIT_COMMON,
.instance_size = sizeof(KVMPITState),
.class_init = kvm_pit_class_init,
+ .class_size = sizeof(KVMPITClass),
};
static void kvm_pit_register(void)