From patchwork Wed Feb 10 22:37:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Justin T. Gibbs" X-Patchwork-Id: 45109 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 C49F7B7CB6 for ; Thu, 11 Feb 2010 14:42:14 +1100 (EST) Received: from localhost ([127.0.0.1]:51171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfPrk-00083f-8s for incoming@patchwork.ozlabs.org; Wed, 10 Feb 2010 22:37:20 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NfLBH-0001hp-R7 for qemu-devel@nongnu.org; Wed, 10 Feb 2010 17:37:11 -0500 Received: from [199.232.76.173] (port=48291 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfLBH-0001hH-7X for qemu-devel@nongnu.org; Wed, 10 Feb 2010 17:37:11 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NfLBF-0007NG-RN for qemu-devel@nongnu.org; Wed, 10 Feb 2010 17:37:10 -0500 Received: from ns1.scsiguy.com ([70.89.174.89]:18828 helo=aslan.scsiguy.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NfLBF-0007Mk-CJ for qemu-devel@nongnu.org; Wed, 10 Feb 2010 17:37:09 -0500 Received: from [192.168.3.59] (mail4.spectralogic.com [207.225.98.253]) (authenticated bits=0) by aslan.scsiguy.com (8.14.3/8.14.3) with ESMTP id o1AMb3K7027075 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Wed, 10 Feb 2010 15:37:04 -0700 (MST) (envelope-from gibbs@scsiguy.com) Message-ID: <4B73350F.9090304@scsiguy.com> Date: Wed, 10 Feb 2010 15:37:03 -0700 From: "Justin T. Gibbs" Organization: SCSIGuy.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1 MIME-Version: 1.0 To: qemu-devel@nongnu.org References: <4B621A1B.6090309@FreeBSD.org> In-Reply-To: <4B621A1B.6090309@FreeBSD.org> X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-Mailman-Approved-At: Wed, 10 Feb 2010 22:30:21 -0500 Subject: [Qemu-devel] Re: [PATCH] Fix lost serial TX interrupts. Report receive overruns. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: gibbs@freebsd.org 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 Properly formatted patch now attached. --- Justin From 7a941b3fcd298b60bb14744b8fae422d86298197 Mon Sep 17 00:00:00 2001 From: Justin T. Gibbs Date: Wed, 10 Feb 2010 14:35:54 -0700 Subject: [PATCH] Fix lost serial TX interrupts. Report receive overruns. o Implement receive overrun status. The FreeBSD uart driver relies on this status in it's probe routine to determine the size of the FIFO supported. o As per the 16550 spec, do not overwrite the RX FIFO on an RX overrun. o Do not allow TX or RX FIFO overruns to increment the data valid count beyond the size of the FIFO. o For reads of the IIR register, only clear the "TX holding register emtpy interrupt" if the read reports this interrupt. This is required by the specification and avoids losing TX interrupts when other, higher priority interrupts (usually RX) are reported first. Signed-off-by: Justin T. Gibbs --- hw/serial.c | 28 ++++++++++++++++++++-------- 1 files changed, 20 insertions(+), 8 deletions(-) diff --git a/hw/serial.c b/hw/serial.c index e7538ac..df67383 100644 --- a/hw/serial.c +++ b/hw/serial.c @@ -169,11 +169,19 @@ static int fifo_put(SerialState *s, int fifo, uint8_t chr) { SerialFIFO *f = (fifo) ? &s->recv_fifo : &s->xmit_fifo; - f->data[f->head++] = chr; + /* Receive overruns do not overwrite FIFO contents. */ + if (fifo == XMIT_FIFO || f->count < UART_FIFO_LENGTH) { - if (f->head == UART_FIFO_LENGTH) - f->head = 0; - f->count++; + f->data[f->head++] = chr; + + if (f->head == UART_FIFO_LENGTH) + f->head = 0; + } + + if (f->count < UART_FIFO_LENGTH) + f->count++; + else if (fifo == RECV_FIFO) + s->lsr |= UART_LSR_OE; return 1; } @@ -533,8 +541,10 @@ static uint32_t serial_ioport_read(void *opaque, uint32_t addr) break; case 2: ret = s->iir; + if (ret & UART_IIR_THRI) { s->thr_ipending = 0; - serial_update_irq(s); + serial_update_irq(s); + } break; case 3: ret = s->lcr; @@ -544,9 +554,9 @@ static uint32_t serial_ioport_read(void *opaque, uint32_t addr) break; case 5: ret = s->lsr; - /* Clear break interrupt */ - if (s->lsr & UART_LSR_BI) { - s->lsr &= ~UART_LSR_BI; + /* Clear break and overrun interrupts */ + if (s->lsr & (UART_LSR_BI|UART_LSR_OE)) { + s->lsr &= ~(UART_LSR_BI|UART_LSR_OE); serial_update_irq(s); } break; @@ -629,6 +639,8 @@ static void serial_receive1(void *opaque, const uint8_t *buf, int size) /* call the timeout receive callback in 4 char transmit time */ qemu_mod_timer(s->fifo_timeout_timer, qemu_get_clock (vm_clock) + s->char_transmit_time * 4); } else { + if (s->lsr & UART_LSR_DR) + s->lsr |= UART_LSR_OE; s->rbr = buf[0]; s->lsr |= UART_LSR_DR; }