From patchwork Mon Jun 20 14:29:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9187657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D6695601C0 for ; Mon, 20 Jun 2016 14:42:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C423B2793D for ; Mon, 20 Jun 2016 14:42:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8E3327A98; Mon, 20 Jun 2016 14:42:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 531B12793D for ; Mon, 20 Jun 2016 14:42:01 +0000 (UTC) Received: from localhost ([::1]:44052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0Om-0004OE-1a for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jun 2016 10:42:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CR-00083x-C9 for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bF0CO-0003BR-6Z for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:14 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:35319) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CN-0003BN-W3 for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:12 -0400 Received: by mail-wm0-x242.google.com with SMTP id a66so9445883wme.2 for ; Mon, 20 Jun 2016 07:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=v+1PdBBc5U507oqiX/JgM994C4h9ywqaD2uOjoBD5F4=; b=UUjHwuffXyKjAajXV12G1h5GCDmcpMiNMc37AlPee0oT6wShStm0q03aIocqM1p3ny 3kLr/gYI+hdxnCSVX/Wy1IhS5nrou5IrxnOnudnsszAUJ/Ni5QJIsdeFLpaZPOW95UU3 3t4hPvclTdk+X7OKR5oJy623o0hJKVvUguQ9V0TS1aR1Kd8/wdq7K/VZx22djVf/4m24 L0FC9QOqnwIp8uouw55gfcwDisSvOMNZi2rdojQGFTrT0jahcm1PU6cpSYXhtwH98w4m qK4vU00GW4eMhCf7VX4FakZJib8e69qhmpEv+N5kfxarwCj9mgDOHoSSEjVN5cFTQRU1 stag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=v+1PdBBc5U507oqiX/JgM994C4h9ywqaD2uOjoBD5F4=; b=LLDG0zJy3fXvjOcLn50Y+am7ZgYPev0OCDX4Ic0LzPiV2p6P9w4ETrgOzg5X5v/539 QgxyGoOwRbfSCGvtjyxklyRWbqFqdUhJ6N57r89XAkgYD2TWRExgwfoXx/Hj4rAyOwcy Xnv02DZwHaynU6ngaujSnccEUEp0CbRoFR5pQTXEYVIf+TCxmNBACKOLAFSTla/bKUSb JB3NKFoCGV1Icdsm6TI9kPPD3Ca7TJ3AwgUwqCGA1RtUXkDbmMlr8Vo1LQkqtzOusf+e Epanm6wkiMAuwPKQR5TlfwRjnBuyn8qG+fRNA49O1zXHMZzw1RSvfeUugxY4sbZo77G9 6yYA== X-Gm-Message-State: ALyK8tLTNZDIWY4crBX7Q4HJ2rYg+uBI8ACaCCzYaBOjjDxz6yduNVRbft6MyCFuTWt10w== X-Received: by 10.194.102.133 with SMTP id fo5mr9964884wjb.34.1466432951110; Mon, 20 Jun 2016 07:29:11 -0700 (PDT) Received: from donizetti.lan (94-39-188-118.adsl-ull.clienti.tiscali.it. [94.39.188.118]) by smtp.gmail.com with ESMTPSA id bb4sm24359892wjb.32.2016.06.20.07.29.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 07:29:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 20 Jun 2016 16:29:02 +0200 Message-Id: <1466432945-28682-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466432945-28682-1-git-send-email-pbonzini@redhat.com> References: <1466432945-28682-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH 3/6] serial: separate serial_xmit and serial_watch_cb X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bcketchum@gmail.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP serial_xmit starts transmission of whatever is in the FIFO or THR; serial_watch_cb is a wrapper around it. Signed-off-by: Paolo Bonzini Reviewed-by: Dr. David Alan Gilbert --- hw/char/serial.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hw/char/serial.c b/hw/char/serial.c index 6f0a49e..4196a2e 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -106,6 +106,7 @@ do {} while (0) #endif static void serial_receive1(void *opaque, const uint8_t *buf, int size); +static void serial_xmit(SerialState *s); static inline void recv_fifo_put(SerialState *s, uint8_t chr) { @@ -223,10 +224,16 @@ static void serial_update_msl(SerialState *s) } } -static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque) +static gboolean serial_watch_cb(GIOChannel *chan, GIOCondition cond, + void *opaque) { SerialState *s = opaque; + serial_xmit(s); + return FALSE; +} +static void serial_xmit(SerialState *s) +{ do { assert(!(s->lsr & UART_LSR_TEMT)); if (s->tsr_retry == 0) { @@ -254,9 +261,9 @@ static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque) } else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1) { if (s->tsr_retry < MAX_XMIT_RETRY && qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, - serial_xmit, s) > 0) { + serial_watch_cb, s) > 0) { s->tsr_retry++; - return FALSE; + return; } s->tsr_retry = 0; } else { @@ -269,11 +276,8 @@ static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque) s->last_xmit_ts = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); s->lsr |= UART_LSR_TEMT; - - return FALSE; } - /* Setter for FCR. is_load flag means, that value is set while loading VM state and interrupt should not be invoked */ @@ -331,7 +335,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val, s->lsr &= ~UART_LSR_TEMT; serial_update_irq(s); if (s->tsr_retry == 0) { - serial_xmit(NULL, G_IO_OUT, s); + serial_xmit(s); } } break; @@ -647,7 +651,8 @@ static int serial_post_load(void *opaque, int version_id) } assert(s->watch_tag == 0); - s->watch_tag = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, serial_xmit, s); + s->watch_tag = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, + serial_watch_cb, s); } else { /* tsr_retry == 0 implies LSR.TEMT = 1 (transmitter empty). */ if (!(s->lsr & UART_LSR_TEMT)) {