Received: from eggs.gnu.org ([2001:4830:134:3::10]:46584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VvVIh-0003eH-Jb for qemu-devel@nongnu.org; Tue, 24 Dec 2013 11:57:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VvVIO-00023H-Us for qemu-devel@nongnu.org; Tue, 24 Dec 2013 11:57:47 -0500 Received: from cantor2.suse.de ([195.135.220.15]:54247 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VvVIO-00022W-Jy for qemu-devel@nongnu.org; Tue, 24 Dec 2013 11:57:28 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 24 Dec 2013 17:57:16 +0100 Message-Id: <1387904237-6941-24-git-send-email-afaerber@suse.de> In-Reply-To: <1387904237-6941-1-git-send-email-afaerber@suse.de> References: <1387904237-6941-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] [PULL 23/24] ioapic: QOM'ify ioapic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: xiaoqiang zhao , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori , "Michael S. Tsirkin" From: xiaoqiang zhao Convert 'init' function to QOM's 'realize' for ioapic and kvm-ioapic. Change variable 'ioapic_no' from static to global. Then we can drop the 'instance_no' function argument. Signed-off-by: xiaoqiang zhao Signed-off-by: Andreas F=C3=A4rber --- hw/i386/kvm/ioapic.c | 6 +++--- hw/intc/ioapic.c | 11 +++++++---- hw/intc/ioapic_common.c | 11 +++++++++-- include/hw/i386/ioapic_internal.h | 3 ++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c index 772a712..d2a6c4c 100644 --- a/hw/i386/kvm/ioapic.c +++ b/hw/i386/kvm/ioapic.c @@ -127,9 +127,9 @@ static void kvm_ioapic_set_irq(void *opaque, int irq,= int level) apic_report_irq_delivered(delivered); } =20 -static void kvm_ioapic_init(IOAPICCommonState *s, int instance_no) +static void kvm_ioapic_realize(DeviceState *dev, Error **errp) { - DeviceState *dev =3D DEVICE(s); + IOAPICCommonState *s =3D IOAPIC_COMMON(dev); =20 memory_region_init_reservation(&s->io_memory, NULL, "kvm-ioapic", 0x= 1000); =20 @@ -146,7 +146,7 @@ static void kvm_ioapic_class_init(ObjectClass *klass,= void *data) IOAPICCommonClass *k =3D IOAPIC_COMMON_CLASS(klass); DeviceClass *dc =3D DEVICE_CLASS(klass); =20 - k->init =3D kvm_ioapic_init; + k->realize =3D kvm_ioapic_realize; k->pre_save =3D kvm_ioapic_get; k->post_load =3D kvm_ioapic_put; dc->reset =3D kvm_ioapic_reset; diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c index 8842845..652dd47 100644 --- a/hw/intc/ioapic.c +++ b/hw/intc/ioapic.c @@ -36,6 +36,9 @@ =20 static IOAPICCommonState *ioapics[MAX_IOAPICS]; =20 +/* global variable from ioapic_common.c */ +extern int ioapic_no; + static void ioapic_service(IOAPICCommonState *s) { uint8_t i; @@ -225,16 +228,16 @@ static const MemoryRegionOps ioapic_io_ops =3D { .endianness =3D DEVICE_NATIVE_ENDIAN, }; =20 -static void ioapic_init(IOAPICCommonState *s, int instance_no) +static void ioapic_realize(DeviceState *dev, Error **errp) { - DeviceState *dev =3D DEVICE(s); + IOAPICCommonState *s =3D IOAPIC_COMMON(dev); =20 memory_region_init_io(&s->io_memory, OBJECT(s), &ioapic_io_ops, s, "ioapic", 0x1000); =20 qdev_init_gpio_in(dev, ioapic_set_irq, IOAPIC_NUM_PINS); =20 - ioapics[instance_no] =3D s; + ioapics[ioapic_no] =3D s; } =20 static void ioapic_class_init(ObjectClass *klass, void *data) @@ -242,7 +245,7 @@ static void ioapic_class_init(ObjectClass *klass, voi= d *data) IOAPICCommonClass *k =3D IOAPIC_COMMON_CLASS(klass); DeviceClass *dc =3D DEVICE_CLASS(klass); =20 - k->init =3D ioapic_init; + k->realize =3D ioapic_realize; dc->reset =3D ioapic_reset_common; } =20 diff --git a/hw/intc/ioapic_common.c b/hw/intc/ioapic_common.c index 4611f7f..4d3d309 100644 --- a/hw/intc/ioapic_common.c +++ b/hw/intc/ioapic_common.c @@ -23,6 +23,14 @@ #include "hw/i386/ioapic_internal.h" #include "hw/sysbus.h" =20 +/* ioapic_no count start from 0 to MAX_IOAPICS, + * remove as static variable from ioapic_common_init. + * now as a global variable, let child to increase the counter + * then we can drop the 'instance_no' argument + * and convert to our QOM's realize function + */ +int ioapic_no; + void ioapic_reset_common(DeviceState *dev) { IOAPICCommonState *s =3D IOAPIC_COMMON(dev); @@ -61,7 +69,6 @@ static void ioapic_common_realize(DeviceState *dev, Err= or **errp) { IOAPICCommonState *s =3D IOAPIC_COMMON(dev); IOAPICCommonClass *info; - static int ioapic_no; =20 if (ioapic_no >=3D MAX_IOAPICS) { error_setg(errp, "Only %d ioapics allowed", MAX_IOAPICS); @@ -69,7 +76,7 @@ static void ioapic_common_realize(DeviceState *dev, Err= or **errp) } =20 info =3D IOAPIC_COMMON_GET_CLASS(s); - info->init(s, ioapic_no); + info->realize(dev, errp); =20 sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->io_memory); ioapic_no++; diff --git a/include/hw/i386/ioapic_internal.h b/include/hw/i386/ioapic_i= nternal.h index 25576c8..3be3352 100644 --- a/include/hw/i386/ioapic_internal.h +++ b/include/hw/i386/ioapic_internal.h @@ -83,7 +83,8 @@ typedef struct IOAPICCommonState IOAPICCommonState; =20 typedef struct IOAPICCommonClass { SysBusDeviceClass parent_class; - void (*init)(IOAPICCommonState *s, int instance_no); + + DeviceRealize realize; void (*pre_save)(IOAPICCommonState *s); void (*post_load)(IOAPICCommonState *s); } IOAPICCommonClass; --=20 1.8.4