From 477a72a1eff40639761e103f5b7652af7746c48e Mon Sep 17 00:00:00 2001 From: Heinz Graalfs Date: Wed, 18 Dec 2013 10:10:49 +0100 Subject: s390x/event-facility: code restructure Code restructure in order to simplify class hierarchy - remove S390SCLPDevice abstract base class and move function pointers into new SCLPEventFacilityClass - implement SCLPEventFacility as SysBusDevice - use define constants for instance creation strings The following ascii-art shows the class structure wrt the SCLP EventFacility before (CURRENT) and after the restructure (NEW): ---- CURRENT: "s390-sclp-events-bus" +-------------------------+ | SCLPEventsBus | |-------------------------| |BusState qbus | +-------------------------+ +-------------------------+ | SCLPEventFacility | - to be replaced by new SCLPEventFacility, |-------------------------| which will be a SysBusDevice |SCLPEventsBus sbus | |DeviceState *qdev | |unsigned int receive_mask| +-------------------------+ +-------------------------+ | S390SCLPDeviceClass | - to be replaced by new SCLPEventFacilityClass |-------------------------| |DeviceClass qdev | |*(init)() | +-------------------------+ "s390-sclp-event-facility" | instance-of | V "s390-sclp-device" - this is an abstract class +-------------------------+ | S390SCLPDevice (A)| - to be replaced by new SCLPEventFacility |-------------------------| |SysBusDevice busdev | |SCLPEventFacility *ef | | | |*(sclp_command_handler)()| - these 2 go to new SCLPEventFacilityClass |*(event_pending)() | +-------------------------+ ---- NEW: "s390-sclp-events-bus" +-------------------------+ | SCLPEventsBus | |-------------------------| |BusState qbus | +-------------------------+ +-------------------------+ | SCLPEventFacilityClass | |-------------------------| |DeviceClass parent_class | | | |*(init)() | |*(command_handler)() | |*(event_pending)() | +-------------------------+ "s390-sclp-event-facility" +-------------------------+ | SCLPEventFacility | |-------------------------| |SysBusDevice parent_class| |SCLPEventsBus sbus | |unsigned int receive_mask| +-------------------------+ Signed-off-by: Heinz Graalfs Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/event-facility.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'hw/s390x/event-facility.c') diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index e0ee7379e2..8ad2dc4094 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -26,8 +26,8 @@ typedef struct SCLPEventsBus { } SCLPEventsBus; struct SCLPEventFacility { + SysBusDevice parent_obj; SCLPEventsBus sbus; - DeviceState *qdev; /* guest' receive mask */ unsigned int receive_mask; }; @@ -315,21 +315,15 @@ static void command_handler(SCLPEventFacility *ef, SCCB *sccb, uint64_t code) } } -static int init_event_facility(S390SCLPDevice *sdev) +static int init_event_facility(SCLPEventFacility *event_facility) { - SCLPEventFacility *event_facility; + DeviceState *sdev = DEVICE(event_facility); DeviceState *quiesce; - event_facility = g_malloc0(sizeof(SCLPEventFacility)); - sdev->ef = event_facility; - sdev->sclp_command_handler = command_handler; - sdev->event_pending = event_pending; - - /* Spawn a new sclp-events facility */ + /* Spawn a new bus for SCLP events */ qbus_create_inplace(&event_facility->sbus, sizeof(event_facility->sbus), - TYPE_SCLP_EVENTS_BUS, DEVICE(sdev), NULL); + TYPE_SCLP_EVENTS_BUS, sdev, NULL); event_facility->sbus.qbus.allow_hotplug = 0; - event_facility->qdev = (DeviceState *) sdev; quiesce = qdev_create(&event_facility->sbus.qbus, "sclpquiesce"); if (!quiesce) { @@ -346,25 +340,29 @@ static int init_event_facility(S390SCLPDevice *sdev) static void reset_event_facility(DeviceState *dev) { - S390SCLPDevice *sdev = SCLP_S390_DEVICE(dev); + SCLPEventFacility *sdev = EVENT_FACILITY(dev); - sdev->ef->receive_mask = 0; + sdev->receive_mask = 0; } static void init_event_facility_class(ObjectClass *klass, void *data) { - DeviceClass *dc = DEVICE_CLASS(klass); - S390SCLPDeviceClass *k = SCLP_S390_DEVICE_CLASS(klass); + SysBusDeviceClass *sbdc = SYS_BUS_DEVICE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(sbdc); + SCLPEventFacilityClass *k = EVENT_FACILITY_CLASS(dc); dc->reset = reset_event_facility; k->init = init_event_facility; + k->command_handler = command_handler; + k->event_pending = event_pending; } static const TypeInfo sclp_event_facility_info = { - .name = "s390-sclp-event-facility", - .parent = TYPE_DEVICE_S390_SCLP, - .instance_size = sizeof(S390SCLPDevice), + .name = TYPE_SCLP_EVENT_FACILITY, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(SCLPEventFacility), .class_init = init_event_facility_class, + .class_size = sizeof(SCLPEventFacilityClass), }; static int event_qdev_init(DeviceState *qdev) -- cgit v1.2.3