diff mbox series

[v3,24/35] spapr/xive: add common realize routine for KVM

Message ID 20180419124331.3915-25-clg@kaod.org
State New
Headers show
Series ppc: support for the XIVE interrupt controller (POWER9) | expand

Commit Message

Cédric Le Goater April 19, 2018, 12:43 p.m. UTC
The XiveSource and sPAPRXive device models will be shared between the
emulated and the KVM mode. The difference will reside in the way the
memory regions are initialized and in the qemu_irq handler. Introduce
common realize routines to share some code.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/intc/spapr_xive.c        | 17 +++++++++++++++--
 hw/intc/xive.c              | 21 ++++++++++++++++-----
 include/hw/ppc/spapr_xive.h |  1 +
 include/hw/ppc/xive.h       |  3 +++
 4 files changed, 35 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c
index f0c2fe52b3c6..bd604089ad49 100644
--- a/hw/intc/spapr_xive.c
+++ b/hw/intc/spapr_xive.c
@@ -84,9 +84,8 @@  static void spapr_xive_init(Object *obj)
     object_property_add_child(obj, "source", OBJECT(&xive->source), NULL);
 }
 
-static void spapr_xive_realize(DeviceState *dev, Error **errp)
+void spapr_xive_common_realize(sPAPRXive *xive, int esb_shift, Error **errp)
 {
-    sPAPRXive *xive = SPAPR_XIVE(dev);
     XiveSource *xsrc = &xive->source;
     Error *local_err = NULL;
 
@@ -105,6 +104,8 @@  static void spapr_xive_realize(DeviceState *dev, Error **errp)
                             &error_fatal);
     object_property_set_int(OBJECT(xsrc), xive->nr_irqs, "nr-irqs",
                             &error_fatal);
+    object_property_set_int(OBJECT(xsrc), esb_shift, "shift",
+                            &error_fatal);
     object_property_add_const_link(OBJECT(xsrc), "xive", OBJECT(xive),
                                    &error_fatal);
     object_property_set_bool(OBJECT(xsrc), true, "realized", &local_err);
@@ -122,6 +123,18 @@  static void spapr_xive_realize(DeviceState *dev, Error **errp)
      * level views of the TIMA.
      */
     xive->tm_base = XIVE_TM_BASE;
+}
+
+static void spapr_xive_realize(DeviceState *dev, Error **errp)
+{
+    sPAPRXive *xive = SPAPR_XIVE(dev);
+    Error *local_err = NULL;
+
+    spapr_xive_common_realize(xive, XIVE_ESB_64K_2PAGE, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
 
     memory_region_init_io(&xive->tm_mmio_user, OBJECT(xive),
                           &xive_tm_user_ops, xive, "xive.tima.user",
diff --git a/hw/intc/xive.c b/hw/intc/xive.c
index 11af3bf1184a..520b532dbf09 100644
--- a/hw/intc/xive.c
+++ b/hw/intc/xive.c
@@ -903,13 +903,13 @@  static void xive_source_reset(DeviceState *dev)
     }
 }
 
-static void xive_source_realize(DeviceState *dev, Error **errp)
+void xive_source_common_realize(XiveSource *xsrc, qemu_irq_handler handler,
+                                Error **errp)
 {
-    XiveSource *xsrc = XIVE_SOURCE(dev);
     Object *obj;
     Error *local_err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), "xive", &local_err);
+    obj = object_property_get_link(OBJECT(xsrc), "xive", &local_err);
     if (!obj) {
         error_propagate(errp, local_err);
         error_prepend(errp, "required link 'xive' not found: ");
@@ -931,13 +931,24 @@  static void xive_source_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    xsrc->qirqs = qemu_allocate_irqs(xive_source_set_irq, xsrc,
-                                     xsrc->nr_irqs);
+    xsrc->qirqs = qemu_allocate_irqs(handler, xsrc, xsrc->nr_irqs);
     xsrc->status = g_malloc0(xsrc->nr_irqs);
 
     /* Allocate the SBEs (State Bit Entry). 2 bits, so 4 entries per byte */
     xsrc->sbe_size = DIV_ROUND_UP(xsrc->nr_irqs, 4);
     xsrc->sbe = g_malloc0(xsrc->sbe_size);
+}
+
+static void xive_source_realize(DeviceState *dev, Error **errp)
+{
+    XiveSource *xsrc = XIVE_SOURCE(dev);
+    Error *local_err = NULL;
+
+    xive_source_common_realize(xsrc, xive_source_set_irq, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
 
     /* TODO: H_INT_ESB support, which removing the ESB MMIOs */
 
diff --git a/include/hw/ppc/spapr_xive.h b/include/hw/ppc/spapr_xive.h
index 41e2784403b2..f3ac084a71be 100644
--- a/include/hw/ppc/spapr_xive.h
+++ b/include/hw/ppc/spapr_xive.h
@@ -51,6 +51,7 @@  void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon);
 void spapr_xive_mmio_map(sPAPRXive *xive);
 void spapr_xive_mmio_unmap(sPAPRXive *xive);
 qemu_irq spapr_xive_qirq(sPAPRXive *xive, int lisn);
+void spapr_xive_common_realize(sPAPRXive *xive, int esb_shift, Error **errp);
 
 /*
  * sPAPR encoding of EQ indexes
diff --git a/include/hw/ppc/xive.h b/include/hw/ppc/xive.h
index 36de10af0109..b040cf580fc9 100644
--- a/include/hw/ppc/xive.h
+++ b/include/hw/ppc/xive.h
@@ -175,6 +175,9 @@  static inline qemu_irq xive_source_qirq(XiveSource *xsrc, uint32_t srcno)
     return xsrc->qirqs[srcno];
 }
 
+void xive_source_common_realize(XiveSource *xsrc, qemu_irq_handler handler,
+                                Error **errp);
+
 /*
  * XIVE Interrupt Presenter
  */