From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtLTW-0008H1-3M for qemu-devel@nongnu.org; Wed, 18 Dec 2013 13:04:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtLTO-0004bJ-Pq for qemu-devel@nongnu.org; Wed, 18 Dec 2013 13:04:02 -0500 Received: from cantor2.suse.de ([195.135.220.15]:43886 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtLTO-0004b2-Gg for qemu-devel@nongnu.org; Wed, 18 Dec 2013 13:03:54 -0500 Message-ID: <52B1E385.4030303@suse.de> Date: Wed, 18 Dec 2013 19:03:49 +0100 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1383646565-13774-1-git-send-email-zxq_yx_007@163.com> <1383646565-13774-5-git-send-email-zxq_yx_007@163.com> In-Reply-To: <1383646565-13774-5-git-send-email-zxq_yx_007@163.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 4/4] ioapic: QOM'ify ioapic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xiaoqiang zhao , Paolo Bonzini , Anthony Liguori Cc: qemu-devel@nongnu.org Am 05.11.2013 11:16, schrieb xiaoqiang zhao: > changes: > 1. use type constant for kvm_ioapic and ioapic > 2. convert 'init' to QOM's 'realize' for ioapic and kvm_ioapic > For QOM'ify, I move variable 'ioapic_no' from static to global. > Then we can drop the 'instance_no' argument. Now, it's child > that increase 'ioapic_no' counter. >=20 > Signed-off-by: xiaoqiang zhao > --- > hw/i386/kvm/ioapic.c | 15 +++++++++------ > hw/intc/ioapic.c | 19 +++++++++++++------ > hw/intc/ioapic_common.c | 13 ++++++++++--- > include/hw/i386/ioapic_internal.h | 3 ++- > 4 files changed, 34 insertions(+), 16 deletions(-) >=20 > diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c > index 772a712..36f7de2 100644 > --- a/hw/i386/kvm/ioapic.c > +++ b/hw/i386/kvm/ioapic.c > @@ -15,6 +15,8 @@ > #include "hw/i386/apic_internal.h" > #include "sysemu/kvm.h" > =20 > +#define TYPE_KVM_IOAPIC "kvm-ioapic" > + > /* PC Utility function */ > void kvm_pc_setup_irq_routing(bool pci_enabled) > { > @@ -127,12 +129,12 @@ 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); > - > - memory_region_init_reservation(&s->io_memory, NULL, "kvm-ioapic", = 0x1000); > + IOAPICCommonState *s =3D IOAPIC_COMMON(dev); > =20 > + memory_region_init_reservation(&s->io_memory, NULL, > + TYPE_KVM_IOAPIC, 0x1000); > qdev_init_gpio_in(dev, kvm_ioapic_set_irq, IOAPIC_NUM_PINS); > } > =20 > @@ -143,10 +145,11 @@ static Property kvm_ioapic_properties[] =3D { > =20 > 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; > @@ -154,7 +157,7 @@ static void kvm_ioapic_class_init(ObjectClass *klas= s, void *data) > } > =20 > static const TypeInfo kvm_ioapic_info =3D { > - .name =3D "kvm-ioapic", > + .name =3D TYPE_KVM_IOAPIC, > .parent =3D TYPE_IOAPIC_COMMON, > .instance_size =3D sizeof(KVMIOAPICState), > .class_init =3D kvm_ioapic_class_init, > diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c > index 8842845..885f385 100644 > --- a/hw/intc/ioapic.c > +++ b/hw/intc/ioapic.c > @@ -36,6 +36,10 @@ > =20 > static IOAPICCommonState *ioapics[MAX_IOAPICS]; > =20 > +#define TYPE_IOAPIC "ioapic" > +/* global variable from ioapic_common.c */ > +extern int ioapic_no; > + > static void ioapic_service(IOAPICCommonState *s) > { > uint8_t i; > @@ -225,16 +229,19 @@ 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); > + TYPE_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; > + > + /* increase the counter */ > + ioapic_no++; This increment used to happen in common code before, now it's done for the non-KVM version only ... > } > =20 > static void ioapic_class_init(ObjectClass *klass, void *data) > @@ -242,12 +249,12 @@ static void ioapic_class_init(ObjectClass *klass,= void *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 > static const TypeInfo ioapic_info =3D { > - .name =3D "ioapic", > + .name =3D TYPE_IOAPIC, > .parent =3D TYPE_IOAPIC_COMMON, > .instance_size =3D sizeof(IOAPICCommonState), > .class_init =3D ioapic_class_init, > diff --git a/hw/intc/ioapic_common.c b/hw/intc/ioapic_common.c > index e55c6d1..aac0402 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, E= rror **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); ... while the check for max. IOAPICs still happens in common code. Do we need to count KVM IOAPICs as well? Or can we consolidate this into the non-KVM version and keep it static there? Regards, Andreas > @@ -69,10 +76,10 @@ static void ioapic_common_realize(DeviceState *dev,= Error **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++; > + > } > =20 > static const VMStateDescription vmstate_ioapic_common =3D { > diff --git a/include/hw/i386/ioapic_internal.h b/include/hw/i386/ioapic= _internal.h > index 25576c8..cbe4744 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); > + /* QOM realize */ > + DeviceRealize realize; > void (*pre_save)(IOAPICCommonState *s); > void (*post_load)(IOAPICCommonState *s); > } IOAPICCommonClass; --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg