From patchwork Wed May 5 20:48:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 51766 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 76540B7D51 for ; Thu, 6 May 2010 09:46:42 +1000 (EST) Received: from localhost ([127.0.0.1]:52186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9oIZ-00048C-MX for incoming@patchwork.ozlabs.org; Wed, 05 May 2010 19:46:39 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9lY1-0005xd-G4 for qemu-devel@nongnu.org; Wed, 05 May 2010 16:50:25 -0400 Received: from [140.186.70.92] (port=50615 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9lXz-0005vW-UW for qemu-devel@nongnu.org; Wed, 05 May 2010 16:50:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9lXx-0001kq-K2 for qemu-devel@nongnu.org; Wed, 05 May 2010 16:50:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40022) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9lXx-0001kg-83 for qemu-devel@nongnu.org; Wed, 05 May 2010 16:50:21 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o45Ko9Kb029422 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 5 May 2010 16:50:09 -0400 Received: from localhost (vpn-240-233.phx2.redhat.com [10.3.240.233]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o45Ko6nj016496; Wed, 5 May 2010 16:50:07 -0400 From: Amit Shah To: Anthony Liguori Date: Thu, 6 May 2010 02:18:25 +0530 Message-Id: <1273092505-22783-1-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Kusanagi Kouichi , qemu list Subject: [Qemu-devel] [PATCH] virtio-serial: Send per-console port resize notifications to 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 From: Kusanagi Kouichi Add a new API, virtio_serial_resize_console(port, rows, cols), to notify the guest of console size updates. This works for both, !MULTIPORT and MULTIPORT cases. For the former case, we send updates via virtio config changes, whereas in the latter, the config changes are deprecated and the VIRTIO_CONSOLE_RESIZE control message is used instead. [Amit: Add per-port row,col notification to the guest via control message, split off virtio-console.c patch] Signed-off-by: Kusanagi Kouichi Signed-off-by: Amit Shah --- hw/virtio-serial-bus.c | 36 ++++++++++++++++++++++++++++++++++++ hw/virtio-serial.h | 13 +++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 3ce95e8..52649b4 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -205,6 +205,41 @@ int virtio_serial_close(VirtIOSerialPort *port) return 0; } +void virtio_serial_resize_console(VirtIOSerialPort *port, int rows, int cols) +{ + struct virtio_console_control cpkt; + struct { + uint16_t rows; + uint16_t cols; + } size; + uint8_t *buffer; + size_t buffer_len; + + if (!use_multiport(port->vser)) { + port->vser->config.rows = rows; + port->vser->config.cols = cols; + + virtio_notify_config(&port->vser->vdev); + return; + } + + /* For MULTIPORT case, each port can have a different size */ + stw_p(&cpkt.event, VIRTIO_CONSOLE_RESIZE); + stw_p(&cpkt.value, 1); + + stw_p(&size.rows, rows); + stw_p(&size.cols, cols); + + buffer_len = sizeof(cpkt) + sizeof(size); + buffer = qemu_malloc(buffer_len); + + memcpy(buffer, &cpkt, sizeof(cpkt)); + memcpy(buffer + sizeof(cpkt), &size, sizeof(size)); + + send_control_msg(port, buffer, buffer_len); + qemu_free(buffer); +} + /* 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 +460,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..912287c 100644 --- a/hw/virtio-serial.h +++ b/hw/virtio-serial.h @@ -25,14 +25,18 @@ #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 are unused if multiport is enabled. When + * multiport is disabled, they hold the size of the underlying + * chardev. When a chardev is resized, the guest is notified by a + * config space update. When multiport is enabled, a control + * message is sent instead. */ uint16_t cols; uint16_t rows; @@ -165,6 +169,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,