[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/2] ioapic use QOM style
From: |
xiaoqiang zhao |
Subject: |
[Qemu-devel] [PATCH 2/2] ioapic use QOM style |
Date: |
Fri, 27 Sep 2013 13:30:52 +0800 |
Change intc/ioapic kvm/ioapic to use QOM' realizefn.
To achive this, I move variable 'ioapic_no' from static to global.
Then, ioapic_realize and kvm_ioapic_realize can drop the 'instance_no'
argument. Instead of parent, child increase ioapic_no now.
Signed-off-by: xiaoqiang zhao <address@hidden>
---
hw/i386/kvm/ioapic.c | 35 ++++++++++++++++++++++++++-----
hw/intc/ioapic.c | 41 ++++++++++++++++++++++++++++++-------
hw/intc/ioapic_common.c | 17 +++++++++------
include/hw/i386/ioapic_internal.h | 1 -
4 files changed, 75 insertions(+), 19 deletions(-)
diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c
index f11a540..b08865d 100644
--- a/hw/i386/kvm/ioapic.c
+++ b/hw/i386/kvm/ioapic.c
@@ -15,6 +15,22 @@
#include "hw/i386/apic_internal.h"
#include "sysemu/kvm.h"
+#define TYPE_KVM_IOAPIC "kvm-ioapic"
+#define KVM_IOAPIC_CLASS(class) \
+ OBJECT_CLASS_CHECK(KVMIOAPICClass, (class), TYPE_KVM_IOAPIC)
+#define KVM_IOAPIC_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(KVMIOAPICClass, (obj), TYPE_KVM_IOAPIC)
+
+/**
+ * KVMIOAPICClass:
+ * @parent_ralize: The parent's ralizefn
+ */
+typedef struct KVMIOAPICClass {
+ IOAPICCommonClass parent_class;
+
+ DeviceRealize parent_realize;
+} KVMIOAPICClass;
+
/* PC Utility function */
void kvm_pc_setup_irq_routing(bool pci_enabled)
{
@@ -127,11 +143,16 @@ 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)
{
- memory_region_init_reservation(&s->io_memory, NULL, "kvm-ioapic", 0x1000);
+ IOAPICCommonState *s = IOAPIC_COMMON(dev);
+ KVMIOAPICClass *kic = KVM_IOAPIC_GET_CLASS(dev);
- qdev_init_gpio_in(DEVICE(s), kvm_ioapic_set_irq, IOAPIC_NUM_PINS);
+ memory_region_init_reservation(&s->io_memory, NULL, TYPE_KVM_IOAPIC,
0x1000);
+
+ qdev_init_gpio_in(dev, kvm_ioapic_set_irq, IOAPIC_NUM_PINS);
+
+ kic->parent_realize(dev, errp);
}
static Property kvm_ioapic_properties[] = {
@@ -143,19 +164,23 @@ static void kvm_ioapic_class_init(ObjectClass *klass,
void *data)
{
IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
+ KVMIOAPICClass *kic = KVM_IOAPIC_CLASS(klass);
- k->init = kvm_ioapic_init;
k->pre_save = kvm_ioapic_get;
k->post_load = kvm_ioapic_put;
dc->reset = kvm_ioapic_reset;
dc->props = kvm_ioapic_properties;
+
+ kic->parent_realize = dc->realize;
+ dc->realize = kvm_ioapic_realize;
}
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,
+ .class_size = sizeof(KVMIOAPICClass),
};
static void kvm_ioapic_register_types(void)
diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c
index d866e00..aeb3ed1 100644
--- a/hw/intc/ioapic.c
+++ b/hw/intc/ioapic.c
@@ -27,6 +27,24 @@
//#define DEBUG_IOAPIC
+#define TYPE_IOAPIC "ioapic"
+#define IOAPIC_CLASS(class) \
+ OBJECT_CLASS_CHECK(IOAPICClass, (class), TYPE_IOAPIC)
+#define IOAPIC_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(IOAPICClass, (obj), TYPE_IOAPIC)
+
+/**
+ * IOAPICClass:
+ * @parent_realize: The parent's ralizefn
+ */
+typedef struct IOAPICClass {
+ IOAPICCommonClass parent_class;
+
+ DeviceRealize parent_realize;
+} IOAPICClass;
+
+extern int ioapic_no;
+
#ifdef DEBUG_IOAPIC
#define DPRINTF(fmt, ...) \
do { printf("ioapic: " fmt , ## __VA_ARGS__); } while (0)
@@ -225,30 +243,39 @@ 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)
{
+ IOAPICCommonState *s = IOAPIC_COMMON(dev);
+ IOAPICClass *ic = IOAPIC_GET_CLASS(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);
- qdev_init_gpio_in(DEVICE(s), ioapic_set_irq, IOAPIC_NUM_PINS);
+ ioapics[ioapic_no] = s;
+ ic->parent_realize(dev, errp);
- ioapics[instance_no] = s;
+ /* increase the counter */
+ ioapic_no++;
}
static void ioapic_class_init(ObjectClass *klass, void *data)
{
- IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass);
+ IOAPICClass *ic = IOAPIC_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
- k->init = ioapic_init;
dc->reset = ioapic_reset_common;
+ ic->parent_realize = dc->realize;
+ dc->realize = ioapic_realize;
}
static const TypeInfo ioapic_info = {
- .name = "ioapic",
+ .name = TYPE_IOAPIC,
.parent = TYPE_IOAPIC_COMMON,
.instance_size = sizeof(IOAPICCommonState),
.class_init = ioapic_class_init,
+ .class_size = sizeof(IOAPICClass),
};
static void ioapic_register_types(void)
diff --git a/hw/intc/ioapic_common.c b/hw/intc/ioapic_common.c
index 6b705c1..1dde813 100644
--- a/hw/intc/ioapic_common.c
+++ b/hw/intc/ioapic_common.c
@@ -23,6 +23,13 @@
#include "hw/i386/ioapic_internal.h"
#include "hw/sysbus.h"
+/* ioapic_no count start from 0 to MAX_IOAPICS
+ * remove from static variable in ioapic_common_init
+ * now as a global variable, let child to increase the counter
+ * then we can convert to our ralizefn style
+ */
+int ioapic_no = 0;
+
void ioapic_reset_common(DeviceState *dev)
{
IOAPICCommonState *s = IOAPIC_COMMON(dev);
@@ -61,7 +68,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);
@@ -69,10 +75,9 @@ static void ioapic_common_realize(DeviceState *dev, Error
**errp)
}
info = IOAPIC_COMMON_GET_CLASS(s);
- info->init(s, ioapic_no);
-
+
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->io_memory);
- ioapic_no++;
+
}
static const VMStateDescription vmstate_ioapic_common = {
@@ -110,9 +115,9 @@ static const TypeInfo ioapic_common_type = {
.abstract = true,
};
-static void register_types(void)
+static void ioapic_common_register_types(void)
{
type_register_static(&ioapic_common_type);
}
-type_init(register_types)
+type_init(ioapic_common_register_types)
diff --git a/include/hw/i386/ioapic_internal.h
b/include/hw/i386/ioapic_internal.h
index 25576c8..34d77eb 100644
--- a/include/hw/i386/ioapic_internal.h
+++ b/include/hw/i386/ioapic_internal.h
@@ -83,7 +83,6 @@ typedef struct IOAPICCommonState IOAPICCommonState;
typedef struct IOAPICCommonClass {
SysBusDeviceClass parent_class;
- void (*init)(IOAPICCommonState *s, int instance_no);
void (*pre_save)(IOAPICCommonState *s);
void (*post_load)(IOAPICCommonState *s);
} IOAPICCommonClass;
--
1.7.10.4