s390x: Simplify SCLPDevice usage
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
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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH 1/3] s390x: Introduce a SCLPDevice pointer under the machine
Quoted 6 lines · Cédric Le Goater
Initialize directly SCLPDevice from the machine init handler and remove
s390_sclp_init(). We will use the SCLPDevice pointer later to create the consoles.Signed-off-by Cédric Le Goater <[email protected]>---
PATCH 2/3 s390x/event-facility: Simplify sclp_get_event_facility_bus()
In reply to Cédric Le Goatersclp_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
@@ -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
@@ -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
@@ -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
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 aTYPE_SCLP_EVENTS_BUSobject. The SCLPDevice instance is now available under the machine state, use it to simplify the lookup and adjust the creation of the consoles.Signed-off-by Cédric Le Goater <[email protected]>--- 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(-)
PATCH 3/3 s390x/sclp: Simplify get_sclp_device()
In reply to Cédric Le Goaterget_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
@@ -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
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 aTYPE_SCLPobject. 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.Signed-off-by Cédric Le Goater <[email protected]>--- hw/s390x/sclp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/s390x/sclp.c +1
-1@@ -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; }