On 31/03/2025 16.00, Shalini Chellathurai Saroja wrote:
Add Control-Program Identification (CPI) device to QOM only when the virtual
machine supports CPI. CPI is supported from "s390-ccw-virtio-10.0" machine
and higher.

Signed-off-by: Shalini Chellathurai Saroja <shal...@linux.ibm.com>
---
  hw/s390x/event-facility.c  | 27 ++++++++++++++++++++++-----
  hw/s390x/s390-virtio-ccw.c |  1 +
  2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c
index c0fb6e098c..cb23bbc54b 100644
--- a/hw/s390x/event-facility.c
+++ b/hw/s390x/event-facility.c
@@ -22,6 +22,7 @@
  #include "hw/s390x/sclp.h"
  #include "migration/vmstate.h"
  #include "hw/s390x/event-facility.h"
+#include "hw/qdev-properties.h"
typedef struct SCLPEventsBus {
      BusState qbus;
@@ -54,6 +55,7 @@ struct SCLPEventFacility {
      bool allow_all_mask_sizes;
      /* length of the receive mask */
      uint16_t mask_length;
+    bool use_cpi;
  };
/* return true if any child has event pending set */
@@ -455,11 +457,20 @@ static void realize_event_facility(DeviceState *dev, 
Error **errp)
          qdev_unrealize(DEVICE(&event_facility->quiesce));
          return;
      }
-    if (!qdev_realize(DEVICE(&event_facility->cpi),
-                      BUS(&event_facility->sbus), errp)) {
-        qdev_unrealize(DEVICE(&event_facility->quiesce));
-        qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
-        return;
+    /*
+     * Add sclpcpi device to QOM only when the virtual machine supports
+     * Control-Program Identification. It is supported by 
"s390-ccw-virtio-10.0"
+     * machine and higher.
+     */
+    if (!event_facility->use_cpi) {
+        object_unparent(OBJECT(&event_facility->cpi));
+    } else {
+        if (!qdev_realize(DEVICE(&event_facility->cpi),
+                          BUS(&event_facility->sbus), errp)) {
+            qdev_unrealize(DEVICE(&event_facility->quiesce));
+            qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
+            return;
+        }

Hmm, first doing object_initialize_child() in init_event_facility() and then unparenting it here again in case we are running with an older machine type is a little bit ugly. I wonder whether it would be nicer to add the QOM object from ccw_init() init instead, similar to what we do with the SCLP-console in s390_create_sclpconsole() ? If you've got some spare minutes, could you please give it a try whether that looks nicer?

 Thanks,
  Thomas


Reply via email to