From patchwork Wed May 25 12:21:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 97368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2A890B6F84 for ; Thu, 26 May 2011 01:26:23 +1000 (EST) Received: from localhost ([::1]:44202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPFyW-0004G3-Cc for incoming@patchwork.ozlabs.org; Wed, 25 May 2011 11:26:20 -0400 Received: from eggs.gnu.org ([140.186.70.92]:52445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPFyE-0004Bu-Cs for qemu-devel@nongnu.org; Wed, 25 May 2011 11:26:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QPFyD-0006vC-1u for qemu-devel@nongnu.org; Wed, 25 May 2011 11:26:02 -0400 Received: from oxygen-new.pond.sub.org ([78.46.104.156]:36447 helo=oxygen.pond.sub.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPFyC-0006v5-Tb for qemu-devel@nongnu.org; Wed, 25 May 2011 11:26:01 -0400 Received: from oxygen-old.pond.sub.org (oxygen.pond.sub.org [IPv6:2a01:4f8:130:9021::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "oxygen.pond.sub.org", Issuer "CAcert Class 3 Root" (verified OK)) by oxygen.pond.sub.org (Postfix) with ESMTPS id 0A4A6A246A for ; Wed, 25 May 2011 14:21:16 +0200 (CEST) Received: from blackfin.pond.sub.org (p5B32BEFC.dip.t-dialin.net [91.50.190.252]) by oxygen-old.pond.sub.org (Postfix) with ESMTPA id DE30E277181 for ; Wed, 25 May 2011 14:21:15 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 04C9A2AC; Wed, 25 May 2011 14:21:15 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 25 May 2011 14:21:14 +0200 Message-Id: <1306326074-22737-6-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1306326074-22737-1-git-send-email-armbru@redhat.com> References: <1306326074-22737-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: amit.shah@redhat.com Subject: [Qemu-devel] [PATCH 5/5] virtio-console: Simplify init callbacks 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 Signed-off-by: Markus Armbruster --- hw/virtio-console.c | 35 +++++++++-------------------------- 1 files changed, 9 insertions(+), 26 deletions(-) diff --git a/hw/virtio-console.c b/hw/virtio-console.c index 713f6ef..b076331 100644 --- a/hw/virtio-console.c +++ b/hw/virtio-console.c @@ -74,11 +74,17 @@ static void chr_event(void *opaque, int event) } } -static int generic_port_init(VirtConsole *vcon, VirtIOSerialPort *port) +static int virtconsole_initfn(VirtIOSerialPort *port) { + VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port); VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev, vcon->port.dev.info); + if (port->id == 0 && !info->is_console) { + error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility."); + return -1; + } + if (vcon->chr) { qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event, vcon); @@ -86,15 +92,8 @@ static int generic_port_init(VirtConsole *vcon, VirtIOSerialPort *port) info->guest_open = guest_open; info->guest_close = guest_close; } - return 0; -} - -/* Virtio Console Ports */ -static int virtconsole_initfn(VirtIOSerialPort *port) -{ - VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port); - return generic_port_init(vcon, port); + return 0; } static int virtconsole_exitfn(VirtIOSerialPort *port) @@ -132,26 +131,10 @@ static void virtconsole_register(void) } device_init(virtconsole_register) -/* Generic Virtio Serial Ports */ -static int virtserialport_initfn(VirtIOSerialPort *port) -{ - VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port); - - if (port->id == 0) { - /* - * Disallow a generic port at id 0, that's reserved for - * console ports. - */ - error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility."); - return -1; - } - return generic_port_init(vcon, port); -} - static VirtIOSerialPortInfo virtserialport_info = { .qdev.name = "virtserialport", .qdev.size = sizeof(VirtConsole), - .init = virtserialport_initfn, + .init = virtconsole_initfn, .exit = virtconsole_exitfn, .qdev.props = (Property[]) { DEFINE_PROP_UINT32("nr", VirtConsole, port.id, VIRTIO_CONSOLE_BAD_ID),