From nobody Sun Feb 8 10:43:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526078138004905.1609241863116; Fri, 11 May 2018 15:35:38 -0700 (PDT) Received: from localhost ([::1]:50376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHGdV-0001Dq-5H for importer@patchew.org; Fri, 11 May 2018 18:35:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHF6r-0002AS-HJ for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fHF6q-000547-FW for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:49 -0400 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]:33900) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fHF6q-00053z-BI for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:48 -0400 Received: by mail-io0-x244.google.com with SMTP id p124-v6so8516445iod.1 for ; Fri, 11 May 2018 13:57:48 -0700 (PDT) Received: from localhost.localdomain (c-24-11-27-195.hsd1.ut.comcast.net. [24.11.27.195]) by smtp.gmail.com with ESMTPSA id n64-v6sm1128000itc.32.2018.05.11.13.57.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 13:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wEzkG7XiPR6N4VSx5jf9hXc5flKbnEVBuOQkdXU//OE=; b=lmviZmDgVqfrwc+4/de3poG9El82EvhejjthRqM5SywM1ycnl/RSlvWmaFxkkWfCbs O1eBLjAoLJHrQQT4Qvir4Fsl6BKqCIYei5CzxZvOHp+HYePOdS5WTH1vdJMua4HDsYFp 90s2BaeQvBC3iwSF8ingtaB6ACkSAhWF+tDrAg15QkYKNHlIwQM/NaW0ibcTaS8Pv7I+ zDlEYJhIx9Mq0ryRFOtxYsuT682J71Bb+0wblEVIWdk1vuxbFghkmq2H08laL+S1Hwkr 82TSTvSPAimWVKIZ417otd16f6m6PFaDvClKh170KL+5dj33hUkzgTqSJ2CoW6Pzn9gR 3wdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wEzkG7XiPR6N4VSx5jf9hXc5flKbnEVBuOQkdXU//OE=; b=bUjKZpWaEzRCMzbG4ZHlEvbLWzd/Lm4EdrVspm42KkmJYe3NPKVOcfOTMQO4IoIoZe q/Bep2iWPVpcGNEURgD7el5PLcGqtqW2v2fb6avOmbPE+d+1nuQ/HnJ1g/L72ZqZhffV WOk2mQDqDxOBpSK7P1R/5lxIuTBZd0By1A7fKmupZHaxV529QLZ8HevvC2M+reQ73TDK AwJKktUvxfdusoDtivR9RG03qjfMMGJakx1tGP1L0IysEoJd3n+nEbZ52fvMsUbsA7RY 8lCvrDmFnY/WuR6+ptZuWH5H2kIahDyR8+ukmhWxDTor0v/W7SNoV9bYSJl6Gu/Ub8VL XM3g== X-Gm-Message-State: ALKqPwfUc+6q/S0hBZR+t6L6tIKTF0dLOUoEv9Z4JlwhcA2StBNKugJT ZVao9z5dJix5CRuaGy/OoDr/44SC X-Google-Smtp-Source: AB8JxZo5LN+So9HtBdzkSX5v215zy0xsPOJYOVGq+9P1LOHXoEc827vGJVb5H3Jo0laQhWkEl51/YQ== X-Received: by 2002:a6b:b889:: with SMTP id i131-v6mr7616755iof.300.1526072267413; Fri, 11 May 2018 13:57:47 -0700 (PDT) From: Calvin Lee To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 14:57:23 -0600 Message-Id: <20180511205724.4039-2-cyrus296@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511205724.4039-1-cyrus296@gmail.com> References: <20180511205724.4039-1-cyrus296@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::244 X-Mailman-Approved-At: Fri, 11 May 2018 18:28:34 -0400 Subject: [Qemu-devel] [PATCH RFC 1/2] PC Chipset: Improve serial divisor calculation 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: Calvin Lee , pbonzini@redhat.com, dgilbert@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes several problems I found in the UART serial implementation. Now all divisor values are allowed, while before divisor values of zero and below the base baud rate were rejected. All changes are in reference to http://www.sci.muni.cz/docs/pc/serport.txt Signed-off-by: Calvin Lee --- I included a slight code-style change in this commit because it seemed close enough to the code I was editing to be relevant. If not, I can change the commit to not include this change. hw/char/serial.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/hw/char/serial.c b/hw/char/serial.c index 2c080c9862..4159a46a2f 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -150,13 +150,10 @@ static void serial_update_irq(SerialState *s) =20 static void serial_update_parameters(SerialState *s) { - int speed, parity, data_bits, stop_bits, frame_size; + float speed; + int parity, data_bits, stop_bits, frame_size; QEMUSerialSetParams ssp; =20 - if (s->divider =3D=3D 0 || s->divider > s->baudbase) { - return; - } - /* Start bit. */ frame_size =3D 1; if (s->lcr & 0x08) { @@ -169,14 +166,16 @@ static void serial_update_parameters(SerialState *s) } else { parity =3D 'N'; } - if (s->lcr & 0x04) + if (s->lcr & 0x04) { stop_bits =3D 2; - else + } else { stop_bits =3D 1; + } =20 data_bits =3D (s->lcr & 0x03) + 5; frame_size +=3D data_bits + stop_bits; - speed =3D s->baudbase / s->divider; + /* Zero divisor should give about 3500 baud */ + speed =3D (s->divider =3D=3D 0) ? 3500 : (float) s->baudbase / s->divi= der; ssp.speed =3D speed; ssp.parity =3D parity; ssp.data_bits =3D data_bits; @@ -184,7 +183,7 @@ static void serial_update_parameters(SerialState *s) s->char_transmit_time =3D (NANOSECONDS_PER_SECOND / speed) * frame_si= ze; qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp); =20 - DPRINTF("speed=3D%d parity=3D%c data=3D%d stop=3D%d\n", + DPRINTF("speed=3D%.2f parity=3D%c data=3D%d stop=3D%d\n", speed, parity, data_bits, stop_bits); } =20 @@ -341,7 +340,11 @@ static void serial_ioport_write(void *opaque, hwaddr a= ddr, uint64_t val, default: case 0: if (s->lcr & UART_LCR_DLAB) { - s->divider =3D (s->divider & 0xff00) | val; + if (size =3D=3D 2) { + s->divider =3D (s->divider & 0xff00) | val; + } else if (size =3D=3D 4) { + s->divider =3D val; + } serial_update_parameters(s); } else { s->thr =3D (uint8_t) val; --=20 2.17.0 From nobody Sun Feb 8 10:43:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152607783510454.02104108730475; Fri, 11 May 2018 15:30:35 -0700 (PDT) Received: from localhost ([::1]:50241 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHGYc-0004oH-4U for importer@patchew.org; Fri, 11 May 2018 18:30:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHF6x-0002Do-2l for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fHF6w-00055X-0r for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:55 -0400 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:54641) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fHF6v-00055T-S9 for qemu-devel@nongnu.org; Fri, 11 May 2018 16:57:53 -0400 Received: by mail-it0-x244.google.com with SMTP id z6-v6so3560869iti.4 for ; Fri, 11 May 2018 13:57:53 -0700 (PDT) Received: from localhost.localdomain (c-24-11-27-195.hsd1.ut.comcast.net. [24.11.27.195]) by smtp.gmail.com with ESMTPSA id n64-v6sm1128000itc.32.2018.05.11.13.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 13:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yCRJ1oE0jwu5Nd67aIPTuaf4MMC75ottj2xuSOAnfg0=; b=Wgesa4lHCNts0QT233e1JJlvBIm4sIHZcrkD1V7WNRPmehXc70/m/JLlprY0L75//C NWv4/3TIAtGwfgFS/1hB684lpBq4Cido99NkPZ2wWWR+1aK3Ux7qoghEiA7W8GL2IPlY m/reTMWsP5B7sYUQkeP+Q0k9Wk/34IlOLCn18bG98IJaPl0Kcb16jn3/y4e5b5ztFJ8f vwhFxXRyHLCCtAUrvfenchfwhwkJZUOXLQyexLpzS3IYiykvGeg3CuEm7MmS4OtOTv1r Hvwjp+bNxXNqXniEMRGJLWg6qSEujqLvbOfTnJpYOhcZhTVY7/OKnPD+EOcuw+X3wfFn RD6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yCRJ1oE0jwu5Nd67aIPTuaf4MMC75ottj2xuSOAnfg0=; b=OsVUU7cmTS7PvbCeGMAbvkddpPGh/DOVPkKaXxFBSv47FPwQrq9DMMJFhtPvn2IBG7 67SMAQaOguMhd4j0TY/lRZd+7XDt0OO5NHjRLC/q7GsBhriwNfMjG2wbDdzBYJgW15Pr CPmPUCvH/x7J++Fb+j1Suf0Cb2aNZBVDlz+QxbV5NElRsNujpAXcMmRA1ver8Pq3JIMI etAByQJxYDAyIT8M9c2rhLv/7RjkXC9xN0t04/hswBBaJVhWy3zeBdcW00dPBuevoY98 Kg1ADgr/sshJbJzlmHBCNYwjinROHt3xaUtj0XdpLyOBGFB9C1B1yl2kmHD5goNW6Wx/ qWgA== X-Gm-Message-State: ALKqPwfCdRP3O2jFEbvys9pdaH/rbwTvYPYvlrGkq8NitFODtzbYJiW5 GJ4z7DcE0ZjKY7LiH3u1CzauzAnm X-Google-Smtp-Source: AB8JxZpITNygtPH1dWrzyogspNBKLBIOElc8uN1qD7mmfadw5RtfcJrjObII//eUc+YZKaXUNZz2NA== X-Received: by 2002:a24:4651:: with SMTP id j78-v6mr4940190itb.111.1526072272906; Fri, 11 May 2018 13:57:52 -0700 (PDT) From: Calvin Lee To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 14:57:24 -0600 Message-Id: <20180511205724.4039-3-cyrus296@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511205724.4039-1-cyrus296@gmail.com> References: <20180511205724.4039-1-cyrus296@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::244 X-Mailman-Approved-At: Fri, 11 May 2018 18:28:34 -0400 Subject: [Qemu-devel] [PATCH RFC 2/2] PC Chipset: Send serial bytes at correct rate 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: Calvin Lee , pbonzini@redhat.com, dgilbert@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes bug in QEMU such that UART bytes would be sent immediatly after being put in the THR regardless of the UART frequency (and divisor). Now they will be sent at the appropriate rate. Signed-off-by: Calvin Lee --- I am not sure about VM migration here. I want to move a struct field from one VMStateDescription to a new one. I did this by bumping the version number on the old VMStateDescription, and kept the field as `_TEST`. If this is incorrect please let me know. hw/char/serial.c | 47 +++++++++++++++++++++++++++++++++++----- include/hw/char/serial.h | 2 ++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/hw/char/serial.c b/hw/char/serial.c index 4159a46a2f..b621d99f28 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -359,9 +359,8 @@ static void serial_ioport_write(void *opaque, hwaddr ad= dr, uint64_t val, s->lsr &=3D ~UART_LSR_THRE; s->lsr &=3D ~UART_LSR_TEMT; serial_update_irq(s); - if (s->tsr_retry =3D=3D 0) { - serial_xmit(s); - } + timer_mod(s->xmit_timeout_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->char_transmit_t= ime); } break; case 1: @@ -586,6 +585,15 @@ static void serial_receive_break(SerialState *s) serial_update_irq(s); } =20 +/* There is data to be sent in xmit_fifo or the thr */ +static void xmit_timeout_int(void *opaque) +{ + SerialState *s =3D opaque; + if (s->tsr_retry =3D=3D 0) { + serial_xmit(s); + } +} + /* There's data in recv_fifo and s->rbr has not been read for 4 char trans= mit times */ static void fifo_timeout_int (void *opaque) { SerialState *s =3D opaque; @@ -726,12 +734,13 @@ static bool serial_tsr_needed(void *opaque) =20 static const VMStateDescription vmstate_serial_tsr =3D { .name =3D "serial/tsr", - .version_id =3D 1, + .version_id =3D 2, .minimum_version_id =3D 1, .needed =3D serial_tsr_needed, .fields =3D (VMStateField[]) { VMSTATE_UINT32(tsr_retry, SerialState), - VMSTATE_UINT8(thr, SerialState), + /* Moved to `xmit_timeout_timer` */ + VMSTATE_UINT8_TEST(thr, SerialState, 1); VMSTATE_UINT8(tsr, SerialState), VMSTATE_END_OF_LIST() } @@ -772,6 +781,24 @@ static const VMStateDescription vmstate_serial_xmit_fi= fo =3D { } }; =20 +static bool serial_xmit_timeout_timer_needed(void *opaque) +{ + SerialState *s =3D (SerialState *)opaque; + return timer_pending(s->xmit_timeout_timer); +} + +static const VMStateDescription vmstate_serial_xmit_timeout_timer =3D { + .name =3D "serial/xmit_timeout_timer", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D serial_xmit_timeout_timer_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8(thr, SerialState), + VMSTATE_TIMER_PTR(xmit_timeout_timer, SerialState), + VMSTATE_END_OF_LIST() + } +}; + static bool serial_fifo_timeout_timer_needed(void *opaque) { SerialState *s =3D (SerialState *)opaque; @@ -849,6 +876,7 @@ const VMStateDescription vmstate_serial =3D { &vmstate_serial_tsr, &vmstate_serial_recv_fifo, &vmstate_serial_xmit_fifo, + &vmstate_serial_xmit_timeout_timer, &vmstate_serial_fifo_timeout_timer, &vmstate_serial_timeout_ipending, &vmstate_serial_poll, @@ -880,6 +908,7 @@ static void serial_reset(void *opaque) s->poll_msl =3D 0; =20 s->timeout_ipending =3D 0; + timer_del(s->xmit_timeout_timer); timer_del(s->fifo_timeout_timer); timer_del(s->modem_status_poll); =20 @@ -928,7 +957,10 @@ void serial_realize_core(SerialState *s, Error **errp) { s->modem_status_poll =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB= *) serial_update_msl, s); =20 - s->fifo_timeout_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerC= B *) fifo_timeout_int, s); + s->xmit_timeout_timer =3D + timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) xmit_timeout_int,= s); + s->fifo_timeout_timer =3D + timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int,= s); qemu_register_reset(serial_reset, s); =20 qemu_chr_fe_set_handlers(&s->chr, serial_can_receive1, serial_receive1, @@ -945,6 +977,9 @@ void serial_exit_core(SerialState *s) timer_del(s->modem_status_poll); timer_free(s->modem_status_poll); =20 + timer_del(s->xmit_timeout_timer); + timer_free(s->xmit_timeout_timer); + timer_del(s->fifo_timeout_timer); timer_free(s->fifo_timeout_timer); =20 diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 0acfbbc382..09aece90fb 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -65,6 +65,8 @@ struct SerialState { /* Time when the last byte was successfully sent out of the tsr */ uint64_t last_xmit_ts; Fifo8 recv_fifo; + /* Time to read the next byte from the thr */ + QEMUTimer *xmit_timeout_timer; Fifo8 xmit_fifo; /* Interrupt trigger level for recv_fifo */ uint8_t recv_fifo_itl; --=20 2.17.0