Re: [Qemu-devel] [PATCH 6/8] s390: sclp event facility and signal quiesce support via system_powerdown
Alex, thanks for the comments, On Tue, 2012-06-12 at 13:38 +0200, Alexander Graf wrote: On 06/06/2012 02:05 PM, Jens Freimann wrote: From: Heinz Graalfsgraa...@linux.vnet.ibm.com This patch implements a subset of the sclp event facility as well as the signal quiesce event. This allows to gracefully shutdown a guest by using system_powerdown. This sends a signal quiesce signal that is interpreted by linux guests as ctrl-alt-del. In addition the event facility is modeled using the QOM. Signed-off-by: Heinz Graalfsgraa...@linux.vnet.ibm.com Signed-off-by: Christian Borntraegerborntrae...@de.ibm.com Signed-off-by: Jens Freimannjf...@de.ibm.com Andreas, I'm always getting headaches reviewing qdev and/or qom patches. Could you please check this for layering violations? --- Makefile.target |1 + hw/s390-event-facility.c | 232 + hw/s390-event-facility.h | 54 ++ hw/s390-sclp.c | 256 +- hw/s390-sclp.h | 98 +- hw/s390-virtio.c | 11 +- target-s390x/op_helper.c |3 + 7 files changed, 649 insertions(+), 6 deletions(-) create mode 100644 hw/s390-event-facility.c create mode 100644 hw/s390-event-facility.h diff --git a/Makefile.target b/Makefile.target index fed2d72..f939c3a 100644 --- a/Makefile.target +++ b/Makefile.target @@ -375,6 +375,7 @@ obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o obj-m68k-y += m68k-semi.o dummy_m68k.o obj-s390x-y = s390-virtio-bus.o s390-virtio.o s390-sclp.o +obj-s390x-y += s390-event-facility.o obj-alpha-y = mc146818rtc.o obj-alpha-y += alpha_pci.o alpha_dp264.o alpha_typhoon.o diff --git a/hw/s390-event-facility.c b/hw/s390-event-facility.c new file mode 100644 index 000..b8106a6 --- /dev/null +++ b/hw/s390-event-facility.c @@ -0,0 +1,232 @@ +/* + * SCLP Event Facility + * + * Copyright IBM Corp. 2007,2012 + * Author: Heinz Graalfsgraa...@de.ibm.com + * + * This file is licensed under the terms of the GNU General Public License(GPL) + */ + +#include iov.h +#include monitor.h +#include qemu-queue.h +#include sysbus.h +#include sysemu.h + +#include s390-sclp.h +#include s390-event-facility.h + +struct SCLPDevice { +const char *name; +bool vm_running; +}; + +struct SCLP { +BusState qbus; +SCLPEventFacility *event_facility; +}; + +struct SCLPEventFacility { +SCLPDevice sdev; +SCLP sbus; +DeviceState *qdev; +void *opaque; +}; + +typedef struct SCLPConsole { +SCLPEvent event; +CharDriverState *chr; +} SCLPConsole; + +static void sclpef_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) +{ +SCLPEvent *event = DO_UPCAST(SCLPEvent, dev, qdev); + +monitor_printf(mon, %*sid %d\n, indent, , event-id); +} + +static unsigned int send_mask_quiesce(void) +{ +return SCLP_EVENT_MASK_SIGNAL_QUIESCE; +} + +static unsigned int receive_mask_quiesce(void) +{ +return 0; +} + +static void s390_signal_quiesce(void *opaque, int n, int level) +{ +sclp_enable_signal_quiesce(); +sclp_service_interrupt(opaque, 0); +} + +unsigned int sclpef_send_mask(SCLPDevice *sdev) +{ +unsigned int mask; +DeviceState *dev; +SCLPEventFacility *event_facility; +SCLPEventClass *cons; + +event_facility = DO_UPCAST(SCLPEventFacility, sdev, sdev); + +mask = 0; + +QTAILQ_FOREACH(dev,event_facility-sbus.qbus.children, sibling) { +cons = SCLP_EVENT_GET_CLASS((SCLPEvent *) dev); +mask |= cons-get_send_mask(); +} +return mask; +} + +unsigned int sclpef_receive_mask(SCLPDevice *sdev) +{ +unsigned int mask; +DeviceState *dev; +SCLPEventClass *cons; +SCLPEventFacility *event_facility; + +event_facility = DO_UPCAST(SCLPEventFacility, sdev, sdev); + +mask = 0; + +QTAILQ_FOREACH(dev,event_facility-sbus.qbus.children, sibling) { +cons = SCLP_EVENT_GET_CLASS((SCLPEvent *) dev); +mask |= cons-get_receive_mask(); +} +return mask; +} + +static struct BusInfo sclp_bus_info = { +.name = s390-sclp-bus, +.size = sizeof(SCLPS390Bus), +.print_dev = sclpef_bus_dev_print, +.props = (Property[]) { +DEFINE_PROP_STRING(name, SCLPEvent, name), +DEFINE_PROP_END_OF_LIST() +} +}; + +static int sclpef_qdev_init(DeviceState *qdev) +{ +int rc; +SCLPEvent *event = DO_UPCAST(SCLPEvent, dev, qdev); +SCLPEventClass *cons = SCLP_EVENT_GET_CLASS(event); +SCLP *bus = DO_UPCAST(SCLP, qbus, qdev-parent_bus); + +event-evt_fac = bus-event_facility; +rc = cons-init(event); + +return rc;
Re: [Qemu-devel] [PATCH 6/8] s390: sclp event facility and signal quiesce support via system_powerdown
Am 13.06.2012 09:00, schrieb Heinz Graalfs: Alex, thanks for the comments, On Tue, 2012-06-12 at 13:38 +0200, Alexander Graf wrote: On 06/06/2012 02:05 PM, Jens Freimann wrote: +static SCLPDevice *sclpef_common_init(const char *name, size_t struct_size) +{ +SCLPDevice *sdev; + +sdev = malloc(struct_size); g_malloc please. I suppose even g_malloc0? OK, I will look into this Careful: The equivalent of malloc() and a NULL check is g_try_malloc(). g_malloc() aborts on failure to allocate. The line to draw is whether this only happens at startup or whether this is called at runtime *and* you are willing to consequently handle the possible NULL return in all callers. Regards, Andreas -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 6/8] s390: sclp event facility and signal quiesce support via system_powerdown
On 06/06/2012 02:05 PM, Jens Freimann wrote: From: Heinz Graalfsgraa...@linux.vnet.ibm.com This patch implements a subset of the sclp event facility as well as the signal quiesce event. This allows to gracefully shutdown a guest by using system_powerdown. This sends a signal quiesce signal that is interpreted by linux guests as ctrl-alt-del. In addition the event facility is modeled using the QOM. Signed-off-by: Heinz Graalfsgraa...@linux.vnet.ibm.com Signed-off-by: Christian Borntraegerborntrae...@de.ibm.com Signed-off-by: Jens Freimannjf...@de.ibm.com Andreas, I'm always getting headaches reviewing qdev and/or qom patches. Could you please check this for layering violations? --- Makefile.target |1 + hw/s390-event-facility.c | 232 + hw/s390-event-facility.h | 54 ++ hw/s390-sclp.c | 256 +- hw/s390-sclp.h | 98 +- hw/s390-virtio.c | 11 +- target-s390x/op_helper.c |3 + 7 files changed, 649 insertions(+), 6 deletions(-) create mode 100644 hw/s390-event-facility.c create mode 100644 hw/s390-event-facility.h diff --git a/Makefile.target b/Makefile.target index fed2d72..f939c3a 100644 --- a/Makefile.target +++ b/Makefile.target @@ -375,6 +375,7 @@ obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o obj-m68k-y += m68k-semi.o dummy_m68k.o obj-s390x-y = s390-virtio-bus.o s390-virtio.o s390-sclp.o +obj-s390x-y += s390-event-facility.o obj-alpha-y = mc146818rtc.o obj-alpha-y += alpha_pci.o alpha_dp264.o alpha_typhoon.o diff --git a/hw/s390-event-facility.c b/hw/s390-event-facility.c new file mode 100644 index 000..b8106a6 --- /dev/null +++ b/hw/s390-event-facility.c @@ -0,0 +1,232 @@ +/* + * SCLP Event Facility + * + * Copyright IBM Corp. 2007,2012 + * Author: Heinz Graalfsgraa...@de.ibm.com + * + * This file is licensed under the terms of the GNU General Public License(GPL) + */ + +#include iov.h +#include monitor.h +#include qemu-queue.h +#include sysbus.h +#include sysemu.h + +#include s390-sclp.h +#include s390-event-facility.h + +struct SCLPDevice { +const char *name; +bool vm_running; +}; + +struct SCLP { +BusState qbus; +SCLPEventFacility *event_facility; +}; + +struct SCLPEventFacility { +SCLPDevice sdev; +SCLP sbus; +DeviceState *qdev; +void *opaque; +}; + +typedef struct SCLPConsole { +SCLPEvent event; +CharDriverState *chr; +} SCLPConsole; + +static void sclpef_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) +{ +SCLPEvent *event = DO_UPCAST(SCLPEvent, dev, qdev); + +monitor_printf(mon, %*sid %d\n, indent, , event-id); +} + +static unsigned int send_mask_quiesce(void) +{ +return SCLP_EVENT_MASK_SIGNAL_QUIESCE; +} + +static unsigned int receive_mask_quiesce(void) +{ +return 0; +} + +static void s390_signal_quiesce(void *opaque, int n, int level) +{ +sclp_enable_signal_quiesce(); +sclp_service_interrupt(opaque, 0); +} + +unsigned int sclpef_send_mask(SCLPDevice *sdev) +{ +unsigned int mask; +DeviceState *dev; +SCLPEventFacility *event_facility; +SCLPEventClass *cons; + +event_facility = DO_UPCAST(SCLPEventFacility, sdev, sdev); + +mask = 0; + +QTAILQ_FOREACH(dev,event_facility-sbus.qbus.children, sibling) { +cons = SCLP_EVENT_GET_CLASS((SCLPEvent *) dev); +mask |= cons-get_send_mask(); +} +return mask; +} + +unsigned int sclpef_receive_mask(SCLPDevice *sdev) +{ +unsigned int mask; +DeviceState *dev; +SCLPEventClass *cons; +SCLPEventFacility *event_facility; + +event_facility = DO_UPCAST(SCLPEventFacility, sdev, sdev); + +mask = 0; + +QTAILQ_FOREACH(dev,event_facility-sbus.qbus.children, sibling) { +cons = SCLP_EVENT_GET_CLASS((SCLPEvent *) dev); +mask |= cons-get_receive_mask(); +} +return mask; +} + +static struct BusInfo sclp_bus_info = { +.name = s390-sclp-bus, +.size = sizeof(SCLPS390Bus), +.print_dev = sclpef_bus_dev_print, +.props = (Property[]) { +DEFINE_PROP_STRING(name, SCLPEvent, name), +DEFINE_PROP_END_OF_LIST() +} +}; + +static int sclpef_qdev_init(DeviceState *qdev) +{ +int rc; +SCLPEvent *event = DO_UPCAST(SCLPEvent, dev, qdev); +SCLPEventClass *cons = SCLP_EVENT_GET_CLASS(event); +SCLP *bus = DO_UPCAST(SCLP, qbus, qdev-parent_bus); + +event-evt_fac = bus-event_facility; +rc = cons-init(event); + +return rc; +} + +static int sclpef_qdev_exit(DeviceState *qdev) +{ +SCLPEvent *event = DO_UPCAST(SCLPEvent, dev, qdev); +SCLPEventClass *cons = SCLP_EVENT_GET_CLASS(event); +if (cons-exit) { +cons-exit(event); +} +return 0; +} + +static SCLPDevice *sclpef_common_init(const char *name, size_t struct_size) +{ +SCLPDevice *sdev; + +sdev = malloc(struct_size); g_malloc please. I suppose even
[Qemu-devel] [PATCH 6/8] s390: sclp event facility and signal quiesce support via system_powerdown
From: Heinz Graalfs graa...@linux.vnet.ibm.com This patch implements a subset of the sclp event facility as well as the signal quiesce event. This allows to gracefully shutdown a guest by using system_powerdown. This sends a signal quiesce signal that is interpreted by linux guests as ctrl-alt-del. In addition the event facility is modeled using the QOM. Signed-off-by: Heinz Graalfs graa...@linux.vnet.ibm.com Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com Signed-off-by: Jens Freimann jf...@de.ibm.com --- Makefile.target |1 + hw/s390-event-facility.c | 232 + hw/s390-event-facility.h | 54 ++ hw/s390-sclp.c | 256 +- hw/s390-sclp.h | 98 +- hw/s390-virtio.c | 11 +- target-s390x/op_helper.c |3 + 7 files changed, 649 insertions(+), 6 deletions(-) create mode 100644 hw/s390-event-facility.c create mode 100644 hw/s390-event-facility.h diff --git a/Makefile.target b/Makefile.target index fed2d72..f939c3a 100644 --- a/Makefile.target +++ b/Makefile.target @@ -375,6 +375,7 @@ obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o obj-m68k-y += m68k-semi.o dummy_m68k.o obj-s390x-y = s390-virtio-bus.o s390-virtio.o s390-sclp.o +obj-s390x-y += s390-event-facility.o obj-alpha-y = mc146818rtc.o obj-alpha-y += alpha_pci.o alpha_dp264.o alpha_typhoon.o diff --git a/hw/s390-event-facility.c b/hw/s390-event-facility.c new file mode 100644 index 000..b8106a6 --- /dev/null +++ b/hw/s390-event-facility.c @@ -0,0 +1,232 @@ +/* + * SCLP Event Facility + * + * Copyright IBM Corp. 2007,2012 + * Author: Heinz Graalfs graa...@de.ibm.com + * + * This file is licensed under the terms of the GNU General Public License(GPL) + */ + +#include iov.h +#include monitor.h +#include qemu-queue.h +#include sysbus.h +#include sysemu.h + +#include s390-sclp.h +#include s390-event-facility.h + +struct SCLPDevice { +const char *name; +bool vm_running; +}; + +struct SCLP { +BusState qbus; +SCLPEventFacility *event_facility; +}; + +struct SCLPEventFacility { +SCLPDevice sdev; +SCLP sbus; +DeviceState *qdev; +void *opaque; +}; + +typedef struct SCLPConsole { +SCLPEvent event; +CharDriverState *chr; +} SCLPConsole; + +static void sclpef_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) +{ +SCLPEvent *event = DO_UPCAST(SCLPEvent, dev, qdev); + +monitor_printf(mon, %*sid %d\n, indent, , event-id); +} + +static unsigned int send_mask_quiesce(void) +{ +return SCLP_EVENT_MASK_SIGNAL_QUIESCE; +} + +static unsigned int receive_mask_quiesce(void) +{ +return 0; +} + +static void s390_signal_quiesce(void *opaque, int n, int level) +{ +sclp_enable_signal_quiesce(); +sclp_service_interrupt(opaque, 0); +} + +unsigned int sclpef_send_mask(SCLPDevice *sdev) +{ +unsigned int mask; +DeviceState *dev; +SCLPEventFacility *event_facility; +SCLPEventClass *cons; + +event_facility = DO_UPCAST(SCLPEventFacility, sdev, sdev); + +mask = 0; + +QTAILQ_FOREACH(dev, event_facility-sbus.qbus.children, sibling) { +cons = SCLP_EVENT_GET_CLASS((SCLPEvent *) dev); +mask |= cons-get_send_mask(); +} +return mask; +} + +unsigned int sclpef_receive_mask(SCLPDevice *sdev) +{ +unsigned int mask; +DeviceState *dev; +SCLPEventClass *cons; +SCLPEventFacility *event_facility; + +event_facility = DO_UPCAST(SCLPEventFacility, sdev, sdev); + +mask = 0; + +QTAILQ_FOREACH(dev, event_facility-sbus.qbus.children, sibling) { +cons = SCLP_EVENT_GET_CLASS((SCLPEvent *) dev); +mask |= cons-get_receive_mask(); +} +return mask; +} + +static struct BusInfo sclp_bus_info = { +.name = s390-sclp-bus, +.size = sizeof(SCLPS390Bus), +.print_dev = sclpef_bus_dev_print, +.props = (Property[]) { +DEFINE_PROP_STRING(name, SCLPEvent, name), +DEFINE_PROP_END_OF_LIST() +} +}; + +static int sclpef_qdev_init(DeviceState *qdev) +{ +int rc; +SCLPEvent *event = DO_UPCAST(SCLPEvent, dev, qdev); +SCLPEventClass *cons = SCLP_EVENT_GET_CLASS(event); +SCLP *bus = DO_UPCAST(SCLP, qbus, qdev-parent_bus); + +event-evt_fac = bus-event_facility; +rc = cons-init(event); + +return rc; +} + +static int sclpef_qdev_exit(DeviceState *qdev) +{ +SCLPEvent *event = DO_UPCAST(SCLPEvent, dev, qdev); +SCLPEventClass *cons = SCLP_EVENT_GET_CLASS(event); +if (cons-exit) { +cons-exit(event); +} +return 0; +} + +static SCLPDevice *sclpef_common_init(const char *name, size_t struct_size) +{ +SCLPDevice *sdev; + +sdev = malloc(struct_size); +if (!sdev) { +return NULL; +} +sdev-vm_running = runstate_is_running(); +sdev-name = name; + +return sdev; +} + +void sclpef_enable_irqs(SCLPDevice *sdev, void *opaque) +{ +