Received: from eggs.gnu.org ([2001:4830:134:3::10]:32939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bosfq-0000SE-6r for qemu-devel@nongnu.org; Tue, 27 Sep 2016 09:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bosfk-0005jG-Rh for qemu-devel@nongnu.org; Tue, 27 Sep 2016 09:43:53 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46093) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bosfk-0005iw-IJ for qemu-devel@nongnu.org; Tue, 27 Sep 2016 09:43:48 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8RDhl8W001449 for ; Tue, 27 Sep 2016 09:43:47 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 25qrsauf94-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 27 Sep 2016 09:43:47 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 27 Sep 2016 14:43:45 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id ADCC217D8068 for ; Tue, 27 Sep 2016 14:45:44 +0100 (BST) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u8RDhhxN53805164 for ; Tue, 27 Sep 2016 13:43:43 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u8RChi2H027845 for ; Tue, 27 Sep 2016 06:43:44 -0600 From: Sascha Silbe Date: Tue, 27 Sep 2016 15:43:36 +0200 In-Reply-To: <1474983817-603-1-git-send-email-silbe@linux.vnet.ibm.com> References: <1474983817-603-1-git-send-email-silbe@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Message-Id: <1474983817-603-2-git-send-email-silbe@linux.vnet.ibm.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 1/2] virtio-serial: add plumbing for virtio console emergency write support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , Paolo Bonzini , Amit Shah Cc: Cornelia Huck , qemu-devel@nongnu.org Add the infrastructure required for the virtio 1.0 "emergency write" (VIRTIO_CONSOLE_F_EMERG_WRITE) feature. Because we don't touch the size of the configuration area, guests will not be able to actually make use of this without further patches. Reviewed-by: Cornelia Huck Signed-off-by: Sascha Silbe --- v1=E2=86=92v2: - rebased on current master (virtio-pci page-per-vq compat property) - split into two patches; no code changes (requested by Amit) hw/char/virtio-serial-bus.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index db57a38..57419b2 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -75,6 +75,19 @@ static VirtIOSerialPort *find_port_by_name(char *name) return NULL; } =20 +static VirtIOSerialPort *find_first_connected_console(VirtIOSerial *vser= ) +{ + VirtIOSerialPort *port; + + QTAILQ_FOREACH(port, &vser->ports, next) { + VirtIOSerialPortClass const *vsc =3D VIRTIO_SERIAL_PORT_GET_CLAS= S(port); + if (vsc->is_console && port->host_connected) { + return port; + } + } + return NULL; +} + static bool use_multiport(VirtIOSerial *vser) { VirtIODevice *vdev =3D VIRTIO_DEVICE(vser); @@ -547,6 +560,29 @@ static void get_config(VirtIODevice *vdev, uint8_t *= config_data) vser->serial.max_virtserial_po= rts); } =20 +/* Guest sent new config info */ +static void set_config(VirtIODevice *vdev, const uint8_t *config_data) +{ + VirtIOSerial *vser =3D VIRTIO_SERIAL(vdev); + struct virtio_console_config *config =3D + (struct virtio_console_config *)config_data; + uint8_t emerg_wr_lo =3D le32_to_cpu(config->emerg_wr); + VirtIOSerialPort *port =3D find_first_connected_console(vser); + VirtIOSerialPortClass *vsc; + + if (!config->emerg_wr) { + return; + } + /* Make sure we don't misdetect an emergency write when the guest + * does a short config write after an emergency write. */ + config->emerg_wr =3D 0; + if (!port) { + return; + } + vsc =3D VIRTIO_SERIAL_PORT_GET_CLASS(port); + (void)vsc->have_data(port, &emerg_wr_lo, 1); +} + static void guest_reset(VirtIOSerial *vser) { VirtIOSerialPort *port; @@ -1098,6 +1134,7 @@ static void virtio_serial_class_init(ObjectClass *k= lass, void *data) vdc->unrealize =3D virtio_serial_device_unrealize; vdc->get_features =3D get_features; vdc->get_config =3D get_config; + vdc->set_config =3D set_config; vdc->set_status =3D set_status; vdc->reset =3D vser_reset; vdc->save =3D virtio_serial_save_device; --=20 1.9.1