Skip to contentSkip to conversation

s390x: Simplify SCLPDevice usage

PATCH In review Cédric Le Goater 2 participants 7 messages May 2, 2024

lore
Share & tools
lore
#0 lore raw

cover s390x: Simplify SCLPDevice usage

Hello,

Here is a little series reworking the SCLPDevice initialization in the machine to simplify its use.

Applies on top of :

https://lore.kernel.org/qemu-devel/[email protected]/

Thanks,

C.

Cédric Le Goater (3):
s390x: Introduce a SCLPDevice pointer under the machine s390x/event-facility: Simplify sclp_get_event_facility_bus() s390x/sclp: Simplify get_sclp_device()

 include/hw/s390x/event-facility.h  |  2 +-
 include/hw/s390x/s390-virtio-ccw.h |  3 +++
 include/hw/s390x/sclp.h            |  2 --
 hw/s390x/event-facility.c          | 13 ++-----------
 hw/s390x/s390-virtio-ccw.c         | 18 ++++++++++++------
 hw/s390x/sclp.c                    | 15 +++------------
 6 files changed, 21 insertions(+), 32 deletions(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH 1/3 s390x: Introduce a SCLPDevice pointer under the machine

Initialize directly SCLPDevice from the machine init handler and remove s390_sclp_init(). We will use the SCLPDevice pointer later to create the consoles.

---
 include/hw/s390x/s390-virtio-ccw.h |  3 +++
 include/hw/s390x/sclp.h            |  2 --
 hw/s390x/s390-virtio-ccw.c         |  6 +++++-
 hw/s390x/sclp.c                    | 10 ----------
 4 files changed, 8 insertions(+), 13 deletions(-)
include/hw/s390x/s390-virtio-ccw.h +3 -0
index c1d46e78af8524802225fb192ffd9f6a5bc4434e..7605d06bff18a6075728f3bb462284eaf211b3cb 100644
@@ -13,6 +13,7 @@
 
 #include "hw/boards.h"
 #include "qom/object.h"
+#include "hw/s390x/sclp.h"
 
 #define TYPE_S390_CCW_MACHINE               "s390-ccw-machine"
 
@@ -28,6 +29,8 @@ struct S390CcwMachineState {
     bool dea_key_wrap;
     bool pv;
     uint8_t loadparm[8];
+
+    SCLPDevice *sclp;
 };
 
 #define S390_PTF_REASON_NONE (0x00 << 8)
include/hw/s390x/sclp.h +0 -2
index b405a387b6780ea8f11a062fc02296f633171676..d32f6180e0d3e7ecca09e97ce4b9740360a69692 100644
@@ -221,8 +221,6 @@ static inline int sccb_data_len(SCCB *sccb)
     return be16_to_cpu(sccb->h.length) - sizeof(sccb->h);
 }
 
-
-void s390_sclp_init(void);
 void sclp_service_interrupt(uint32_t sccb);
 void raise_irq_cpu_hotplug(void);
 int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code);
hw/s390x/s390-virtio-ccw.c +5 -1
index 726c2ab4363be30fe6b674d1ee697bb7d2e6352d..159f67d05c1e534800427ce46afcdaa526fd5902 100644
@@ -251,11 +251,15 @@ static void s390_create_sclpconsole(const char *type, Chardev *chardev)
 static void ccw_init(MachineState *machine)
 {
     MachineClass *mc = MACHINE_GET_CLASS(machine);
+    S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
     int ret;
     VirtualCssBus *css_bus;
     DeviceState *dev;
 
-    s390_sclp_init();
+    ms->sclp = SCLP(object_new(TYPE_SCLP));
+    object_property_add_child(OBJECT(machine), TYPE_SCLP, OBJECT(ms->sclp));
+    qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal);
+
     /* init memory + setup max page size. Required for the CPU model */
     s390_memory_init(machine->ram);
 
hw/s390x/sclp.c +0 -10
index 893e71a41b2ddd88a007bd7d395895fc4d444540..d236dbaf0bdd15c3fc07749a98a5813e05cfb9a1 100644
@@ -378,16 +378,6 @@ void sclp_service_interrupt(uint32_t sccb)
 }
 
 /* qemu object creation and initialization functions */
-
-void s390_sclp_init(void)
-{
-    Object *new = object_new(TYPE_SCLP);
-
-    object_property_add_child(qdev_get_machine(), TYPE_SCLP, new);
-    object_unref(new);
-    qdev_realize(DEVICE(new), NULL, &error_fatal);
-}
-
 static void sclp_realize(DeviceState *dev, Error **errp)
 {
     MachineState *machine = MACHINE(qdev_get_machine());
Signature · 1 line
2.44.0
#3 lore raw

PATCH 2/3 s390x/event-facility: Simplify sclp_get_event_facility_bus()

In reply to Cédric Le Goater

sclp_get_event_facility_bus() scans the whole machine to find a TYPE_SCLP_EVENTS_BUS object. The SCLPDevice instance is now available under the machine state, use it to simplify the lookup and adjust the creation of the consoles.

---
 include/hw/s390x/event-facility.h |  2 +-
 hw/s390x/event-facility.c         | 13 ++-----------
 hw/s390x/s390-virtio-ccw.c        | 12 +++++++-----
 3 files changed, 10 insertions(+), 17 deletions(-)
include/hw/s390x/event-facility.h +1 -1
index 3ffd575d8ff09863e17f96d1bdb56a2ca6c2aa56..ff874e792d32ffa4089bb4cb40ab9eb34c889b0c 100644
@@ -203,6 +203,6 @@ struct SCLPEventFacilityClass {
     bool (*event_pending)(SCLPEventFacility *ef);
 };
 
-BusState *sclp_get_event_facility_bus(void);
+BusState *sclp_get_event_facility_bus(SCLPEventFacility *ef);
 
 #endif
hw/s390x/event-facility.c +2 -11
index f9829de9532b65466a65443cecd9609198c5c026..06c1da0ecedcb307c77672097323954c6e7ccaf2 100644
@@ -523,16 +523,7 @@ static void register_types(void)
 
 type_init(register_types)
 
-BusState *sclp_get_event_facility_bus(void)
+BusState *sclp_get_event_facility_bus(SCLPEventFacility *ef)
 {
-    Object *busobj;
-    SCLPEventsBus *sbus;
-
-    busobj = object_resolve_path_type("", TYPE_SCLP_EVENTS_BUS, NULL);
-    sbus = OBJECT_CHECK(SCLPEventsBus, busobj, TYPE_SCLP_EVENTS_BUS);
-    if (!sbus) {
-        return NULL;
-    }
-
-    return &sbus->qbus;
+    return BUS(&ef->sbus);
 }
hw/s390x/s390-virtio-ccw.c +7 -5
index 159f67d05c1e534800427ce46afcdaa526fd5902..2afaf45ce606b2bf7e67dc890339f6c5dd917eca 100644
@@ -237,13 +237,15 @@ static void s390_create_virtio_net(BusState *bus, const char *name)
     }
 }
 
-static void s390_create_sclpconsole(const char *type, Chardev *chardev)
+static void s390_create_sclpconsole(SCLPDevice *sclp,
+                                    const char *type, Chardev *chardev)
 {
-    BusState *ev_fac_bus = sclp_get_event_facility_bus();
+    SCLPEventFacility *ef = sclp->event_facility;
+    BusState *ev_fac_bus = sclp_get_event_facility_bus(ef);
     DeviceState *dev;
 
     dev = qdev_new(type);
-    object_property_add_child(OBJECT(ev_fac_bus->parent), type, OBJECT(dev));
+    object_property_add_child(OBJECT(ef), type, OBJECT(dev));
     qdev_prop_set_chr(dev, "chardev", chardev);
     qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal);
 }
@@ -308,10 +310,10 @@ static void ccw_init(MachineState *machine)
 
     /* init consoles */
     if (serial_hd(0)) {
-        s390_create_sclpconsole("sclpconsole", serial_hd(0));
+        s390_create_sclpconsole(ms->sclp, "sclpconsole", serial_hd(0));
     }
     if (serial_hd(1)) {
-        s390_create_sclpconsole("sclplmconsole", serial_hd(1));
+        s390_create_sclpconsole(ms->sclp, "sclplmconsole", serial_hd(1));
     }
 
     /* init the TOD clock */
Signature · 1 line
2.44.0
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] s390x/event-facility: Simplify sclp_get_event_facility_bus()

Quoted 11 lines · Cédric Le Goater

sclp_get_event_facility_bus() scans the whole machine to find a TYPE_SCLP_EVENTS_BUS object. The SCLPDevice instance is now available under the machine state, use it to simplify the lookup and adjust the creation of the consoles.

---
  include/hw/s390x/event-facility.h |  2 +-
  hw/s390x/event-facility.c         | 13 ++-----------
  hw/s390x/s390-virtio-ccw.c        | 12 +++++++-----
  3 files changed, 10 insertions(+), 17 deletions(-)
#5 lore raw

PATCH 3/3 s390x/sclp: Simplify get_sclp_device()

In reply to Cédric Le Goater

get_sclp_device() scans the whole machine to find a TYPE_SCLP object. Now that the SCLPDevice instance is available under the machine state, use it to simplify the lookup. While at it, remove the inline to let the compiler decide on how to optimize.

---
 hw/s390x/sclp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +3 -2
index d236dbaf0bdd15c3fc07749a98a5813e05cfb9a1..e725dcd5fdfd159f20307e930a38bed3326c9e0e 100644
@@ -21,13 +21,14 @@
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
 #include "hw/s390x/cpu-topology.h"
+#include "hw/s390x/s390-virtio-ccw.h"
 
-static inline SCLPDevice *get_sclp_device(void)
+static SCLPDevice *get_sclp_device(void)
 {
     static SCLPDevice *sclp;
 
     if (!sclp) {
-        sclp = SCLP(object_resolve_path_type("", TYPE_SCLP, NULL));
+        sclp = S390_CCW_MACHINE(qdev_get_machine())->sclp;
     }
     return sclp;
 }
Signature · 1 line
2.44.0
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] s390x/sclp: Simplify get_sclp_device()

Quoted 21 lines · Cédric Le Goater

get_sclp_device() scans the whole machine to find a TYPE_SCLP object. Now that the SCLPDevice instance is available under the machine state, use it to simplify the lookup. While at it, remove the inline to let the compiler decide on how to optimize.

---
  hw/s390x/sclp.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +1 -1
index d236dbaf0bdd15c3fc07749a98a5813e05cfb9a1..e725dcd5fdfd159f20307e930a38bed3326c9e0e 100644
@@ -21,13 +21,14 @@
  #include "hw/s390x/s390-pci-bus.h"
  #include "hw/s390x/ipl.h"
  #include "hw/s390x/cpu-topology.h"
+#include "hw/s390x/s390-virtio-ccw.h"
 
-static inline SCLPDevice *get_sclp_device(void)

hw/s390x/sclp.c line 34

Quoted 10 lines
hw/s390x/sclp.c +2 -1
+static SCLPDevice *get_sclp_device(void)
  {
      static SCLPDevice *sclp;
 
      if (!sclp) {
-        sclp = SCLP(object_resolve_path_type("", TYPE_SCLP, NULL));
+        sclp = S390_CCW_MACHINE(qdev_get_machine())->sclp;
      }
      return sclp;
  }