From patchwork Mon May 3 04:58:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kusanagi Kouichi X-Patchwork-Id: 51473 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2BE6CB7D40 for ; Mon, 3 May 2010 15:06:09 +1000 (EST) Received: from localhost ([127.0.0.1]:45598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8nl4-0006sS-KD for incoming@patchwork.ozlabs.org; Mon, 03 May 2010 00:59:54 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O8njf-0006re-Mn for qemu-devel@nongnu.org; Mon, 03 May 2010 00:58:27 -0400 Received: from [140.186.70.92] (port=58868 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8njd-0006qp-RQ for qemu-devel@nongnu.org; Mon, 03 May 2010 00:58:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O8njc-0005Mo-9a for qemu-devel@nongnu.org; Mon, 03 May 2010 00:58:25 -0400 Received: from msa102.auone-net.jp ([61.117.18.162]:45363) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O8njb-0005Lf-RR for qemu-devel@nongnu.org; Mon, 03 May 2010 00:58:24 -0400 Received: from ppp.dion.ne.jp (ZJ080070.ppp.dion.ne.jp [222.4.80.70]) by msa102.auone-net.jp (au one net msa) with ESMTP id 0AE306AC03C; Mon, 3 May 2010 13:58:13 +0900 (JST) Date: Mon, 3 May 2010 13:58:13 +0900 From: Kusanagi Kouichi To: Amit Shah References: <20100416114248.A001562C03A@msa106.auone-net.jp> <20100416130219.GE21268@amit-x200.redhat.com> <20100429071239.6854F6FC039@msa105.auone-net.jp> <20100429104718.GB21309@amit-x200.redhat.com> <20100429123631.130366AC03A@msa102.auone-net.jp> <20100429124917.GC21309@amit-x200.redhat.com> <20100430081220.2178A6AC03A@msa102.auone-net.jp> <20100430104338.GA27314@amit-x200.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100430104338.GA27314@amit-x200.redhat.com> User-Agent: Mutt/1.5.20 (2009-06-14) Message-Id: <20100503045814.0AE306AC03C@msa102.auone-net.jp> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH v3 2/2] virtio-console: Notify resize to the guest. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org I tested this patch as follows: I put printf()s into involved functions. Then ran qemu on a terminal emulator, and resized it. The guest kernel gets initial size, and follows host resize. Both singleport and multiport work. v3: If multiport is enabled, send the control message. If not, send a config space update. v2: Rename virtio_serial_resize to virtio_serial_resize_console. Signed-off-by: Kusanagi Kouichi --- hw/virtio-console.c | 3 +++ hw/virtio-serial-bus.c | 15 +++++++++++++++ hw/virtio-serial.h | 11 +++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hw/virtio-console.c b/hw/virtio-console.c index caea11f..58246d1 100644 --- a/hw/virtio-console.c +++ b/hw/virtio-console.c @@ -55,6 +55,9 @@ static void chr_event(void *opaque, int event) case CHR_EVENT_CLOSED: virtio_serial_close(&vcon->port); break; + case CHR_EVENT_RESIZE: + virtio_serial_resize_console(&vcon->port, vcon->chr->rows, vcon->chr->cols); + break; } } diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 97694d5..8766f1d 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -205,6 +205,20 @@ int virtio_serial_close(VirtIOSerialPort *port) return 0; } +void virtio_serial_resize_console(VirtIOSerialPort *port, int rows, int cols) +{ + VirtIOSerial *vser = port->vser; + + vser->config.rows = rows; + vser->config.cols = cols; + + if (use_multiport(vser)) { + send_control_event(port, VIRTIO_CONSOLE_RESIZE, 0); + } else { + virtio_notify_config(&vser->vdev); + } +} + /* Individual ports/apps call this function to write to the guest. */ ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf, size_t size) @@ -425,6 +439,7 @@ static uint32_t get_features(VirtIODevice *vdev, uint32_t features) vser = DO_UPCAST(VirtIOSerial, vdev, vdev); + features |= (1 << VIRTIO_CONSOLE_F_SIZE); if (vser->bus->max_nr_ports > 1) { features |= (1 << VIRTIO_CONSOLE_F_MULTIPORT); } diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h index a93b545..b51a040 100644 --- a/hw/virtio-serial.h +++ b/hw/virtio-serial.h @@ -25,14 +25,16 @@ #define VIRTIO_ID_CONSOLE 3 /* Features supported */ +#define VIRTIO_CONSOLE_F_SIZE 0 #define VIRTIO_CONSOLE_F_MULTIPORT 1 #define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0) struct virtio_console_config { /* - * These two fields are used by VIRTIO_CONSOLE_F_SIZE which - * isn't implemented here yet + * These two fields hold the size of the underlying chardev. + * When it resized, the guest is notified by the control message + * if multiport is enabled, or by a config space update if not. */ uint16_t cols; uint16_t rows; @@ -165,6 +167,11 @@ int virtio_serial_open(VirtIOSerialPort *port); int virtio_serial_close(VirtIOSerialPort *port); /* + * Notify resize to the guest + */ +void virtio_serial_resize_console(VirtIOSerialPort *port, int rows, int cols); + +/* * Send data to Guest */ ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,