From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkwFY-00013t-5P for qemu-devel@nongnu.org; Fri, 07 Jun 2013 08:58:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkwFQ-00085a-E3 for qemu-devel@nongnu.org; Fri, 07 Jun 2013 08:58:36 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53796 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkwFQ-00084n-0d for qemu-devel@nongnu.org; Fri, 07 Jun 2013 08:58:28 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 7 Jun 2013 14:58:14 +0200 Message-Id: <1370609900-21998-7-git-send-email-afaerber@suse.de> In-Reply-To: <1370609900-21998-1-git-send-email-afaerber@suse.de> References: <1370609900-21998-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 06/12] i8254: Convert PITCommonState to QOM realizefn List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , anthony@codemonkey.ws 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=C3=A4rber --- hw/i386/kvm/i8254.c | 40 +++++++++++++++++++++++++++------= ------ hw/timer/i8254.c | 24 ++++++++++++++++++----- hw/timer/i8254_common.c | 8 -------- include/hw/timer/i8254_internal.h | 1 - 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/hw/i386/kvm/i8254.c b/hw/i386/kvm/i8254.c index 4ac5551..93a3669 100644 --- a/hw/i386/kvm/i8254.c +++ b/hw/i386/kvm/i8254.c @@ -33,6 +33,10 @@ #define CALIBRATION_ROUNDS 3 =20 #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) =20 typedef struct KVMPITState { PITCommonState parent_obj; @@ -42,6 +46,12 @@ typedef struct KVMPITState { int64_t kernel_clock_offset; } KVMPITState; =20 +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, in= t running, } } =20 -static int kvm_pit_initfn(PITCommonState *pit) +static void kvm_pit_realizefn(DeviceState *dev, Error **errp) { + PITCommonState *pit =3D PIT_COMMON(dev); + KVMPITClass *kpc =3D KVM_PIT_GET_CLASS(dev); KVMPITState *s =3D KVM_PIT(pit); struct kvm_pit_config config =3D { .flags =3D 0, @@ -251,9 +263,9 @@ static int kvm_pit_initfn(PITCommonState *pit) ret =3D 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) =20 ret =3D kvm_vm_ioctl(kvm_state, KVM_REINJECT_CONTROL, &contr= ol); 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; } =20 memory_region_init_reservation(&pit->ioports, "kvm-pit", 4); =20 - qdev_init_gpio_in(&pit->dev.qdev, kvm_pit_irq_control, 1); + qdev_init_gpio_in(dev, kvm_pit_irq_control, 1); =20 qemu_add_vm_change_state_handler(kvm_pit_vm_state_change, s); =20 - return 0; + kpc->parent_realize(dev, errp); } =20 static Property kvm_pit_properties[] =3D { @@ -293,10 +306,12 @@ static Property kvm_pit_properties[] =3D { =20 static void kvm_pit_class_init(ObjectClass *klass, void *data) { + KVMPITClass *kpc =3D KVM_PIT_CLASS(klass); PITCommonClass *k =3D PIT_COMMON_CLASS(klass); DeviceClass *dc =3D DEVICE_CLASS(klass); =20 - k->init =3D kvm_pit_initfn; + kpc->parent_realize =3D dc->realize; + dc->realize =3D kvm_pit_realizefn; k->set_channel_gate =3D kvm_pit_set_gate; k->get_channel_info =3D kvm_pit_get_channel_info; k->pre_save =3D kvm_pit_get; @@ -310,6 +325,7 @@ static const TypeInfo kvm_pit_info =3D { .parent =3D TYPE_PIT_COMMON, .instance_size =3D sizeof(KVMPITState), .class_init =3D kvm_pit_class_init, + .class_size =3D sizeof(KVMPITClass), }; =20 static void kvm_pit_register(void) diff --git a/hw/timer/i8254.c b/hw/timer/i8254.c index efbca19..16c8dd6 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 =20 +#define PIT_CLASS(class) OBJECT_CLASS_CHECK(PITClass, (class), TYPE_I825= 4) +#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_tim= e); =20 static int pit_get_count(PITChannelState *s) @@ -313,20 +322,22 @@ static void pit_post_load(PITCommonState *s) } } =20 -static int pit_initfn(PITCommonState *pit) +static void pit_realizefn(DeviceState *dev, Error **err) { + PITCommonState *pit =3D PIT_COMMON(dev); + PITClass *pc =3D PIT_GET_CLASS(dev); PITChannelState *s; =20 s =3D &pit->channels[0]; /* the timer 0 is connected to an IRQ */ s->irq_timer =3D 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); =20 memory_region_init_io(&pit->ioports, &pit_ioport_ops, pit, "pit", 4)= ; =20 - qdev_init_gpio_in(&pit->dev.qdev, pit_irq_control, 1); + qdev_init_gpio_in(dev, pit_irq_control, 1); =20 - return 0; + pc->parent_realize(dev, err); } =20 static Property pit_properties[] =3D { @@ -336,10 +347,12 @@ static Property pit_properties[] =3D { =20 static void pit_class_initfn(ObjectClass *klass, void *data) { + PITClass *pc =3D PIT_CLASS(klass); PITCommonClass *k =3D PIT_COMMON_CLASS(klass); DeviceClass *dc =3D DEVICE_CLASS(klass); =20 - k->init =3D pit_initfn; + pc->parent_realize =3D dc->realize; + dc->realize =3D pit_realizefn; k->set_channel_gate =3D pit_set_channel_gate; k->get_channel_info =3D pit_get_channel_info_common; k->post_load =3D pit_post_load; @@ -352,6 +365,7 @@ static const TypeInfo pit_info =3D { .parent =3D TYPE_PIT_COMMON, .instance_size =3D sizeof(PITCommonState), .class_init =3D pit_class_initfn, + .class_size =3D sizeof(PITClass), }; =20 static void pit_register_types(void) diff --git a/hw/timer/i8254_common.c b/hw/timer/i8254_common.c index 36eed80..4e5bf0b 100644 --- a/hw/timer/i8254_common.c +++ b/hw/timer/i8254_common.c @@ -170,14 +170,6 @@ static void pit_common_realize(DeviceState *dev, Err= or **errp) { ISADevice *isadev =3D ISA_DEVICE(dev); PITCommonState *pit =3D PIT_COMMON(dev); - PITCommonClass *c =3D PIT_COMMON_GET_CLASS(pit); - int ret; - - ret =3D c->init(pit); - if (ret < 0) { - error_setg(errp, "PIT init failed."); - return; - } =20 isa_register_ioport(isadev, &pit->ioports, pit->iobase); =20 diff --git a/include/hw/timer/i8254_internal.h b/include/hw/timer/i8254_i= nternal.h index e0cff0c..61a1bfb 100644 --- a/include/hw/timer/i8254_internal.h +++ b/include/hw/timer/i8254_internal.h @@ -68,7 +68,6 @@ typedef struct PITCommonState { typedef struct PITCommonClass { ISADeviceClass parent_class; =20 - int (*init)(PITCommonState *s); void (*set_channel_gate)(PITCommonState *s, PITChannelState *sc, int= val); void (*get_channel_info)(PITCommonState *s, PITChannelState *sc, PITChannelInfo *info); --=20 1.8.1.4