From patchwork Fri Jun 7 18:19:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 249788 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C49522C0095 for ; Sat, 8 Jun 2013 04:22:48 +1000 (EST) Received: from localhost ([::1]:54208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul1JE-0008K5-Nk for incoming@patchwork.ozlabs.org; Fri, 07 Jun 2013 14:22:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul1Fk-0003eM-E2 for qemu-devel@nongnu.org; Fri, 07 Jun 2013 14:19:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ul1Fh-0007l2-TR for qemu-devel@nongnu.org; Fri, 07 Jun 2013 14:19:08 -0400 Received: from cantor2.suse.de ([195.135.220.15]:37140 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul1Fh-0007kp-HR for qemu-devel@nongnu.org; Fri, 07 Jun 2013 14:19:05 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 55FBEA5554; Fri, 7 Jun 2013 20:19:04 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Fri, 7 Jun 2013 20:19:00 +0200 Message-Id: <1370629140-30841-6-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1370629140-30841-1-git-send-email-afaerber@suse.de> References: <1370629140-30841-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: Anthony Liguori , jlarrew@linux.vnet.ibm.com, anthony@codemonkey.ws, Amit Shah , =?UTF-8?q?Andreas=20F=C3=A4rber?= , fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH RFT 5/5] virtio-serial-port: Convert to QOM realize/unrealize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Note: virtconsole's/virtserialport's realizefn now registers its handlers before VirtIOSerialPort's realizefn. Signed-off-by: Andreas Färber --- hw/char/virtio-console.c | 71 ++++++++++++++++++++++++++++----------- hw/char/virtio-serial-bus.c | 45 ++++++++++--------------- include/hw/virtio/virtio-serial.h | 11 ------ 3 files changed, 68 insertions(+), 59 deletions(-) diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c index 73e18f2..ab8b902 100644 --- a/hw/char/virtio-console.c +++ b/hw/char/virtio-console.c @@ -18,6 +18,10 @@ #define TYPE_VIRTIO_CONSOLE "virtconsole" #define VIRTIO_CONSOLE(obj) \ OBJECT_CHECK(VirtConsole, (obj), TYPE_VIRTIO_CONSOLE) +#define VIRTIO_CONSOLE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(VirtConsoleClass, (obj), TYPE_VIRTIO_CONSOLE) +#define VIRTIO_CONSOLE_CLASS(cls) \ + OBJECT_CLASS_CHECK(VirtConsoleClass, (cls), TYPE_VIRTIO_CONSOLE) typedef struct VirtConsole { VirtIOSerialPort parent_obj; @@ -26,6 +30,13 @@ typedef struct VirtConsole { guint watch; } VirtConsole; +typedef struct VirtConsoleClass { + VirtIOSerialPortClass parent_class; + + DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; +} VirtConsoleClass; + /* * Callback function that's called from chardevs when backend becomes * writable. @@ -126,14 +137,17 @@ static void chr_event(void *opaque, int event) } } -static int virtconsole_initfn(VirtIOSerialPort *port) +static void virtconsole_realize(DeviceState *dev, Error **errp) { - VirtConsole *vcon = VIRTIO_CONSOLE(port); - VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port); + VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev); + VirtConsole *vcon = VIRTIO_CONSOLE(dev); + VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(dev); + VirtConsoleClass *vcc = VIRTIO_CONSOLE_GET_CLASS(dev); if (port->id == 0 && !k->is_console) { - error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility."); - return -1; + error_setg(errp, "Port number 0 on virtio-serial devices reserved " + "for virtconsole devices for backward compatibility."); + return; } if (vcon->chr) { @@ -142,18 +156,24 @@ static int virtconsole_initfn(VirtIOSerialPort *port) vcon); } - return 0; + vcc->parent_realize(dev, errp); } -static int virtconsole_exitfn(VirtIOSerialPort *port) +static void virtconsole_unrealize(DeviceState *dev, Error **errp) { - VirtConsole *vcon = VIRTIO_CONSOLE(port); + VirtConsole *vcon = VIRTIO_CONSOLE(dev); + VirtConsoleClass *vcc = VIRTIO_CONSOLE_GET_CLASS(dev); + Error *err = NULL; + + vcc->parent_unrealize(dev, &err); + if (err != NULL) { + error_propagate(errp, err); + return; + } if (vcon->watch) { g_source_remove(vcon->watch); } - - return 0; } static Property virtconsole_properties[] = { @@ -161,14 +181,19 @@ static Property virtconsole_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void virtconsole_class_init(ObjectClass *klass, void *data) +static void virtconsole_class_init(ObjectClass *oc, void *data) { - DeviceClass *dc = DEVICE_CLASS(klass); - VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(oc); + VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(oc); + VirtConsoleClass *vcc = VIRTIO_CONSOLE_CLASS(oc); + + vcc->parent_realize = dc->realize; + dc->realize = virtconsole_realize; + + vcc->parent_unrealize = dc->unrealize; + dc->unrealize = virtconsole_unrealize; k->is_console = true; - k->init = virtconsole_initfn; - k->exit = virtconsole_exitfn; k->have_data = flush_buf; k->set_guest_connected = set_guest_connected; dc->props = virtconsole_properties; @@ -179,6 +204,7 @@ static const TypeInfo virtconsole_info = { .parent = TYPE_VIRTIO_SERIAL_PORT, .instance_size = sizeof(VirtConsole), .class_init = virtconsole_class_init, + .class_size = sizeof(VirtConsoleClass), }; static Property virtserialport_properties[] = { @@ -186,13 +212,18 @@ static Property virtserialport_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void virtserialport_class_init(ObjectClass *klass, void *data) +static void virtserialport_class_init(ObjectClass *oc, void *data) { - DeviceClass *dc = DEVICE_CLASS(klass); - VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(oc); + VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(oc); + VirtConsoleClass *vcc = VIRTIO_CONSOLE_CLASS(oc); + + vcc->parent_realize = dc->realize; + dc->realize = virtconsole_realize; + + vcc->parent_unrealize = dc->unrealize; + dc->unrealize = virtconsole_unrealize; - k->init = virtconsole_initfn; - k->exit = virtconsole_exitfn; k->have_data = flush_buf; k->set_guest_connected = set_guest_connected; dc->props = virtserialport_properties; diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 1cdd659..90592d8 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -808,12 +808,12 @@ static void remove_port(VirtIOSerial *vser, uint32_t port_id) send_control_event(vser, port->id, VIRTIO_CONSOLE_PORT_REMOVE, 1); } -static int virtser_port_qdev_init(DeviceState *qdev) +static void virtser_port_device_realize(DeviceState *dev, Error **errp) { - VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev); + VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev); VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); - VirtIOSerialBus *bus = DO_UPCAST(VirtIOSerialBus, qbus, qdev->parent_bus); - int ret, max_nr_ports; + VirtIOSerialBus *bus = VIRTIO_SERIAL_BUS(qdev_get_parent_bus(dev)); + int max_nr_ports; bool plugging_port0; port->vser = bus->vser; @@ -829,9 +829,9 @@ static int virtser_port_qdev_init(DeviceState *qdev) plugging_port0 = vsc->is_console && !find_port_by_id(port->vser, 0); if (find_port_by_id(port->vser, port->id)) { - error_report("virtio-serial-bus: A port already exists at id %u", - port->id); - return -1; + error_setg(errp, "virtio-serial-bus: A port already exists at id %u", + port->id); + return; } if (port->id == VIRTIO_CONSOLE_BAD_ID) { @@ -840,22 +840,19 @@ static int virtser_port_qdev_init(DeviceState *qdev) } else { port->id = find_free_port_id(port->vser); if (port->id == VIRTIO_CONSOLE_BAD_ID) { - error_report("virtio-serial-bus: Maximum port limit for this device reached"); - return -1; + error_setg(errp, "virtio-serial-bus: Maximum port limit for " + "this device reached"); + return; } } } max_nr_ports = tswap32(port->vser->config.max_nr_ports); if (port->id >= max_nr_ports) { - error_report("virtio-serial-bus: Out-of-range port id specified, max. allowed: %u", + error_setg(errp, "virtio-serial-bus: Out-of-range port id specified, " + "max. allowed: %u", max_nr_ports - 1); - return -1; - } - - ret = vsc->init(port); - if (ret) { - return ret; + return; } port->elem.out_num = 0; @@ -868,25 +865,17 @@ static int virtser_port_qdev_init(DeviceState *qdev) /* Send an update to the guest about this new port added */ virtio_notify_config(VIRTIO_DEVICE(port->vser)); - - return ret; } -static int virtser_port_qdev_exit(DeviceState *qdev) +static void virtser_port_device_unrealize(DeviceState *dev, Error **errp) { - VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev); - VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); + VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev); VirtIOSerial *vser = port->vser; qemu_bh_delete(port->bh); remove_port(port->vser, port->id); QTAILQ_REMOVE(&vser->ports, port, next); - - if (vsc->exit) { - vsc->exit(port); - } - return 0; } static void virtio_serial_device_realize(DeviceState *dev, Error **errp) @@ -974,9 +963,9 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp) static void virtio_serial_port_class_init(ObjectClass *klass, void *data) { DeviceClass *k = DEVICE_CLASS(klass); - k->init = virtser_port_qdev_init; k->bus_type = TYPE_VIRTIO_SERIAL_BUS; - k->exit = virtser_port_qdev_exit; + k->realize = virtser_port_device_realize; + k->unrealize = virtser_port_device_unrealize; k->unplug = qdev_simple_unplug_cb; k->props = virtser_props; } diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h index 49af9e3..8d309a4 100644 --- a/include/hw/virtio/virtio-serial.h +++ b/include/hw/virtio/virtio-serial.h @@ -80,17 +80,6 @@ typedef struct VirtIOSerialPortClass { /* Is this a device that binds with hvc in the guest? */ bool is_console; - /* - * The per-port (or per-app) init function that's called when a - * new device is found on the bus. - */ - int (*init)(VirtIOSerialPort *port); - /* - * Per-port exit function that's called when a port gets - * hot-unplugged or removed. - */ - int (*exit)(VirtIOSerialPort *port); - /* Callbacks for guest events */ /* Guest opened/closed device. */ void (*set_guest_connected)(VirtIOSerialPort *port, int guest_connected);