From: "Andreas Färber" <afaerber@suse.de>
To: xiaoqiang zhao <zxq_yx_007@163.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Anthony Liguori <aliguori@amazon.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 4/4] ioapic: QOM'ify ioapic
Date: Wed, 18 Dec 2013 19:03:49 +0100 [thread overview]
Message-ID: <52B1E385.4030303@suse.de> (raw)
In-Reply-To: <1383646565-13774-5-git-send-email-zxq_yx_007@163.com>
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.
>
> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
> ---
> 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(-)
>
> 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"
>
> +#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);
> }
>
> -static void kvm_ioapic_init(IOAPICCommonState *s, int instance_no)
> +static void kvm_ioapic_realize(DeviceState *dev, Error **errp)
> {
> - DeviceState *dev = DEVICE(s);
> -
> - memory_region_init_reservation(&s->io_memory, NULL, "kvm-ioapic", 0x1000);
> + IOAPICCommonState *s = IOAPIC_COMMON(dev);
>
> + memory_region_init_reservation(&s->io_memory, NULL,
> + TYPE_KVM_IOAPIC, 0x1000);
> qdev_init_gpio_in(dev, kvm_ioapic_set_irq, IOAPIC_NUM_PINS);
> }
>
> @@ -143,10 +145,11 @@ static Property kvm_ioapic_properties[] = {
>
> static void kvm_ioapic_class_init(ObjectClass *klass, void *data)
> {
> +
> IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass);
> DeviceClass *dc = DEVICE_CLASS(klass);
>
> - k->init = kvm_ioapic_init;
> + k->realize = kvm_ioapic_realize;
> k->pre_save = kvm_ioapic_get;
> k->post_load = kvm_ioapic_put;
> dc->reset = kvm_ioapic_reset;
> @@ -154,7 +157,7 @@ static void kvm_ioapic_class_init(ObjectClass *klass, void *data)
> }
>
> static const TypeInfo kvm_ioapic_info = {
> - .name = "kvm-ioapic",
> + .name = TYPE_KVM_IOAPIC,
> .parent = TYPE_IOAPIC_COMMON,
> .instance_size = sizeof(KVMIOAPICState),
> .class_init = 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 @@
>
> static IOAPICCommonState *ioapics[MAX_IOAPICS];
>
> +#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 = {
> .endianness = DEVICE_NATIVE_ENDIAN,
> };
>
> -static void ioapic_init(IOAPICCommonState *s, int instance_no)
> +static void ioapic_realize(DeviceState *dev, Error **errp)
> {
> - DeviceState *dev = DEVICE(s);
> + IOAPICCommonState *s = IOAPIC_COMMON(dev);
>
> memory_region_init_io(&s->io_memory, OBJECT(s), &ioapic_io_ops, s,
> - "ioapic", 0x1000);
> + TYPE_IOAPIC, 0x1000);
>
> qdev_init_gpio_in(dev, ioapic_set_irq, IOAPIC_NUM_PINS);
>
> - ioapics[instance_no] = s;
> + ioapics[ioapic_no] = 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 ...
> }
>
> static void ioapic_class_init(ObjectClass *klass, void *data)
> @@ -242,12 +249,12 @@ static void ioapic_class_init(ObjectClass *klass, void *data)
> IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass);
> DeviceClass *dc = DEVICE_CLASS(klass);
>
> - k->init = ioapic_init;
> + k->realize = ioapic_realize;
> dc->reset = ioapic_reset_common;
> }
>
> static const TypeInfo ioapic_info = {
> - .name = "ioapic",
> + .name = TYPE_IOAPIC,
> .parent = TYPE_IOAPIC_COMMON,
> .instance_size = sizeof(IOAPICCommonState),
> .class_init = 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"
>
> +/* 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 = IOAPIC_COMMON(dev);
> @@ -61,7 +69,6 @@ static void ioapic_common_realize(DeviceState *dev, Error **errp)
> {
> IOAPICCommonState *s = IOAPIC_COMMON(dev);
> IOAPICCommonClass *info;
> - static int ioapic_no;
>
> if (ioapic_no >= 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)
> }
>
> info = IOAPIC_COMMON_GET_CLASS(s);
> - info->init(s, ioapic_no);
> + info->realize(dev, errp);
>
> sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->io_memory);
> - ioapic_no++;
> +
> }
>
> static const VMStateDescription vmstate_ioapic_common = {
> 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;
>
> 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;
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
next prev parent reply other threads:[~2013-12-18 18:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-05 10:16 [Qemu-devel] [PATCH v3 0/4] QOM'ify apic and ioapic xiaoqiang zhao
2013-11-05 10:16 ` [Qemu-devel] [PATCH v3 1/4] apic: Cleanup for QOM'ify xiaoqiang zhao
2013-11-05 10:16 ` [Qemu-devel] [PATCH v3 2/4] apic: QOM'ify apic & icc_bus xiaoqiang zhao
2013-11-05 10:16 ` [Qemu-devel] [PATCH v3 3/4] ioapic: Cleanup for QOM'ify xiaoqiang zhao
2013-11-05 10:16 ` [Qemu-devel] [PATCH v3 4/4] ioapic: QOM'ify ioapic xiaoqiang zhao
2013-12-18 18:03 ` Andreas Färber [this message]
2013-12-19 2:28 ` Chen Fan
2013-12-19 2:42 ` 赵小强
2013-12-19 5:37 ` 赵小强
2013-12-19 14:20 ` Paolo Bonzini
2013-12-20 11:18 ` Andreas Färber
2013-12-20 23:02 ` <zxq_yx_007@163.com>
2013-12-18 17:57 ` [Qemu-devel] [PATCH v3 0/4] QOM'ify apic and ioapic Andreas Färber
2013-12-18 18:08 ` Andreas Färber
2013-12-18 19:20 ` Stefano Stabellini
2013-12-18 19:24 ` Andreas Färber
2013-12-18 19:29 ` Stefano Stabellini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52B1E385.4030303@suse.de \
--to=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zxq_yx_007@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.