summary refs log tree commit diff stats
path: root/hw/apic_common.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2012-01-24 13:12:29 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2012-01-27 10:50:50 -0600
commit999e12bbe85c5dcf49bef13bce4f97399c7105f4 (patch)
tree73b6ed8633a73134e9f728baa1ed2b1dab58b5b0 /hw/apic_common.c
parent40021f08882aaef93c66c8c740087b6d3031b63a (diff)
downloadfocaccia-qemu-999e12bbe85c5dcf49bef13bce4f97399c7105f4.tar.gz
focaccia-qemu-999e12bbe85c5dcf49bef13bce4f97399c7105f4.zip
sysbus: apic: ioapic: convert to QEMU Object Model
This converts three devices because apic and ioapic are subclasses of sysbus.
Converting subclasses independently of their base class is prohibitively hard.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/apic_common.c')
-rw-r--r--hw/apic_common.c88
1 files changed, 56 insertions, 32 deletions
diff --git a/hw/apic_common.c b/hw/apic_common.c
index ac06147e64..9a3b1c512d 100644
--- a/hw/apic_common.c
+++ b/hw/apic_common.c
@@ -25,35 +25,40 @@ static int apic_irq_delivered;
 
 void cpu_set_apic_base(DeviceState *d, uint64_t val)
 {
-    APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
-    APICCommonInfo *info;
-
     trace_cpu_set_apic_base(val);
 
-    if (s) {
-        info = DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
+    if (d) {
+        APICCommonState *s = APIC_COMMON(d);
+        APICCommonClass *info = APIC_COMMON_GET_CLASS(s);
         info->set_base(s, val);
     }
 }
 
 uint64_t cpu_get_apic_base(DeviceState *d)
 {
-    APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
-
-    trace_cpu_get_apic_base(s ? (uint64_t)s->apicbase : 0);
-
-    return s ? s->apicbase : 0;
+    if (d) {
+        APICCommonState *s = APIC_COMMON(d);
+        trace_cpu_get_apic_base((uint64_t)s->apicbase);
+        return s->apicbase;
+    } else {
+        trace_cpu_get_apic_base(0);
+        return 0;
+    }
 }
 
 void cpu_set_apic_tpr(DeviceState *d, uint8_t val)
 {
-    APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
-    APICCommonInfo *info;
+    APICCommonState *s;
+    APICCommonClass *info;
 
-    if (s) {
-        info = DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
-        info->set_tpr(s, val);
+    if (!d) {
+        return;
     }
+
+    s = APIC_COMMON(d);
+    info = APIC_COMMON_GET_CLASS(s);
+
+    info->set_tpr(s, val);
 }
 
 uint8_t cpu_get_apic_tpr(DeviceState *d)
@@ -86,10 +91,9 @@ int apic_get_irq_delivered(void)
 
 void apic_deliver_nmi(DeviceState *d)
 {
-    APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
-    APICCommonInfo *info;
+    APICCommonState *s = APIC_COMMON(d);
+    APICCommonClass *info = APIC_COMMON_GET_CLASS(s);
 
-    info = DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
     info->external_nmi(s);
 }
 
@@ -223,8 +227,8 @@ static int apic_load_old(QEMUFile *f, void *opaque, int version_id)
 
 static int apic_init_common(SysBusDevice *dev)
 {
-    APICCommonState *s = FROM_SYSBUS(APICCommonState, dev);
-    APICCommonInfo *info;
+    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonClass *info;
     static int apic_no;
 
     if (apic_no >= MAX_APICS) {
@@ -232,7 +236,7 @@ static int apic_init_common(SysBusDevice *dev)
     }
     s->idx = apic_no++;
 
-    info = DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
+    info = APIC_COMMON_GET_CLASS(s);
     info->init(s);
 
     sysbus_init_mmio(&s->busdev, &s->io_memory);
@@ -241,9 +245,8 @@ static int apic_init_common(SysBusDevice *dev)
 
 static int apic_dispatch_post_load(void *opaque, int version_id)
 {
-    APICCommonState *s = opaque;
-    APICCommonInfo *info =
-        DO_UPCAST(APICCommonInfo, busdev.qdev, qdev_get_info(&s->busdev.qdev));
+    APICCommonState *s = APIC_COMMON(opaque);
+    APICCommonClass *info = APIC_COMMON_GET_CLASS(s);
 
     if (info->post_load) {
         info->post_load(s);
@@ -289,14 +292,35 @@ static Property apic_properties_common[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static void apic_common_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sc->init = apic_init_common;
+}
 
-void apic_qdev_register(APICCommonInfo *info)
+static TypeInfo apic_common_type = {
+    .name = TYPE_APIC_COMMON,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(APICCommonState),
+    .class_size = sizeof(APICCommonClass),
+    .class_init = apic_common_class_init,
+    .abstract = true,
+};
+
+void apic_qdev_register(DeviceInfo *info)
 {
-    info->busdev.init = apic_init_common;
-    info->busdev.qdev.size = sizeof(APICCommonState),
-    info->busdev.qdev.vmsd = &vmstate_apic_common;
-    info->busdev.qdev.reset = apic_reset_common;
-    info->busdev.qdev.no_user = 1;
-    info->busdev.qdev.props = apic_properties_common;
-    sysbus_register_withprop(&info->busdev);
+    info->size = sizeof(APICCommonState),
+    info->vmsd = &vmstate_apic_common;
+    info->reset = apic_reset_common;
+    info->no_user = 1;
+    info->props = apic_properties_common;
+    sysbus_qdev_register_subclass(info, TYPE_APIC_COMMON);
 }
+
+static void register_devices(void)
+{
+    type_register_static(&apic_common_type);
+}
+
+device_init(register_devices);