qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH ppc-next fixup] intc/openpic_kvm: Fix QOM and build


From: Andreas Färber
Subject: [Qemu-devel] [PATCH ppc-next fixup] intc/openpic_kvm: Fix QOM and build issues
Date: Sun, 16 Jun 2013 20:32:54 +0200

Signed-off-by: Andreas Färber <address@hidden>
---
 default-configs/ppcemb-softmmu.mak |  1 +
 hw/intc/openpic_kvm.c              | 50 +++++++++++++++++++++++---------------
 hw/ppc/e500.c                      |  2 +-
 include/hw/ppc/openpic.h           |  1 +
 4 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/default-configs/ppcemb-softmmu.mak 
b/default-configs/ppcemb-softmmu.mak
index be93e03..97be9f6 100644
--- a/default-configs/ppcemb-softmmu.mak
+++ b/default-configs/ppcemb-softmmu.mak
@@ -38,5 +38,6 @@ CONFIG_XILINX=y
 CONFIG_XILINX_ETHLITE=y
 CONFIG_OPENPIC=y
 CONFIG_E500=$(CONFIG_FDT)
+CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM))
 # For PReP
 CONFIG_MC146818RTC=y
diff --git a/hw/intc/openpic_kvm.c b/hw/intc/openpic_kvm.c
index 17d0a35..8818b5d 100644
--- a/hw/intc/openpic_kvm.c
+++ b/hw/intc/openpic_kvm.c
@@ -31,8 +31,14 @@
 #include "sysemu/kvm.h"
 #include "qemu/log.h"
 
+#define KVM_OPENPIC(obj) \
+    OBJECT_CHECK(KVMOpenPICState, (obj), TYPE_KVM_OPENPIC)
+
 typedef struct KVMOpenPICState {
+    /*< private >*/
     SysBusDevice busdev;
+    /*< public >*/
+
     MemoryRegion mem;
     MemoryListener mem_listener;
     uint32_t fd;
@@ -145,16 +151,26 @@ static void kvm_openpic_region_del(MemoryListener 
*listener,
     }
 }
 
-static int kvm_openpic_init(SysBusDevice *dev)
+static void kvm_openpic_init(Object *obj)
+{
+    KVMOpenPICState *opp = KVM_OPENPIC(obj);
+
+    memory_region_init_io(&opp->mem, &kvm_openpic_mem_ops, opp,
+                          "kvm-openpic", 0x40000);
+}
+
+static void kvm_openpic_realize(DeviceState *dev, Error **errp)
 {
+    SysBusDevice *d = SYS_BUS_DEVICE(dev);
+    KVMOpenPICState *opp = KVM_OPENPIC(dev);
     KVMState *s = kvm_state;
-    KVMOpenPICState *opp = FROM_SYSBUS(typeof(*opp), dev);
     int kvm_openpic_model;
     struct kvm_create_device cd = {0};
     int ret, i;
 
     if (!kvm_check_extension(s, KVM_CAP_DEVICE_CTRL)) {
-        return -EINVAL;
+        error_setg(errp, "Kernel is lacking Device Control API");
+        return;
     }
 
     switch (opp->model) {
@@ -167,23 +183,21 @@ static int kvm_openpic_init(SysBusDevice *dev)
         break;
 
     default:
-        return -EINVAL;
+        error_setg(errp, "Unsupported OpenPIC model %" PRIu32, opp->model);
+        return;
     }
 
     cd.type = kvm_openpic_model;
     ret = kvm_vm_ioctl(s, KVM_CREATE_DEVICE, &cd);
     if (ret < 0) {
-        qemu_log_mask(LOG_UNIMP, "%s: can't create device %d: %s\n",
-                      __func__, cd.type, strerror(errno));
-        return -EINVAL;
+        error_setg(errp, "Can't create device %d: %s",
+                   cd.type, strerror(errno));
+        return;
     }
     opp->fd = cd.fd;
 
-    memory_region_init_io(&opp->mem, &kvm_openpic_mem_ops, opp,
-                          "kvm-openpic", 0x40000);
-
-    sysbus_init_mmio(dev, &opp->mem);
-    qdev_init_gpio_in(&dev->qdev, kvm_openpic_set_irq, OPENPIC_MAX_IRQ);
+    sysbus_init_mmio(d, &opp->mem);
+    qdev_init_gpio_in(dev, kvm_openpic_set_irq, OPENPIC_MAX_IRQ);
 
     opp->mem_listener.region_add = kvm_openpic_region_add;
     opp->mem_listener.region_add = kvm_openpic_region_del;
@@ -205,8 +219,6 @@ static int kvm_openpic_init(SysBusDevice *dev)
     kvm_gsi_routing_allowed = true;
 
     kvm_irqchip_commit_routes(s);
-
-    return 0;
 }
 
 int kvm_openpic_connect_vcpu(DeviceState *d, CPUState *cs)
@@ -227,20 +239,20 @@ static Property kvm_openpic_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void kvm_openpic_class_init(ObjectClass *klass, void *data)
+static void kvm_openpic_class_init(ObjectClass *oc, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(oc);
 
-    k->init = kvm_openpic_init;
+    dc->realize = kvm_openpic_realize;
     dc->props = kvm_openpic_properties;
     dc->reset = kvm_openpic_reset;
 }
 
 static const TypeInfo kvm_openpic_info = {
-    .name          = "kvm-openpic",
+    .name          = TYPE_KVM_OPENPIC,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(KVMOpenPICState),
+    .instance_init = kvm_openpic_init,
     .class_init    = kvm_openpic_class_init,
 };
 
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index d38a688..47e8cb6 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -504,7 +504,7 @@ static DeviceState *ppce500_init_mpic_kvm(PPCE500Params 
*params,
     CPUState *cs;
     int r;
 
-    dev = qdev_create(NULL, "kvm-openpic");
+    dev = qdev_create(NULL, TYPE_KVM_OPENPIC);
     qdev_prop_set_uint32(dev, "model", params->mpic_version);
 
     r = qdev_init(dev);
diff --git a/include/hw/ppc/openpic.h b/include/hw/ppc/openpic.h
index 1fe4865..9628277 100644
--- a/include/hw/ppc/openpic.h
+++ b/include/hw/ppc/openpic.h
@@ -24,6 +24,7 @@ enum {
 #define OPENPIC_MAX_IRQ     (OPENPIC_MAX_SRC + OPENPIC_MAX_IPI + \
                              OPENPIC_MAX_TMR)
 
+#define TYPE_KVM_OPENPIC "kvm-openpic"
 int kvm_openpic_connect_vcpu(DeviceState *d, CPUState *cs);
 
 #endif /* __OPENPIC_H__ */
-- 
1.8.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]