From nobody Wed Nov 5 02:07:34 2025 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; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531840539769850.751171506115; Tue, 17 Jul 2018 08:15:39 -0700 (PDT) Received: from localhost ([::1]:59906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffRhO-0003cA-Jr for importer@patchew.org; Tue, 17 Jul 2018 11:15:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffRZH-00059X-Va for qemu-devel@nongnu.org; Tue, 17 Jul 2018 11:07:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffRZG-0007Fh-GO for qemu-devel@nongnu.org; Tue, 17 Jul 2018 11:07:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54088 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ffRZG-0007FT-B8 for qemu-devel@nongnu.org; Tue, 17 Jul 2018 11:07:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECA0B4075789; Tue, 17 Jul 2018 15:07:09 +0000 (UTC) Received: from 640k.localdomain.com (ovpn-112-17.ams2.redhat.com [10.36.112.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A7702026D68; Tue, 17 Jul 2018 15:07:08 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 17 Jul 2018 17:06:48 +0200 Message-Id: <1531840015-28804-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1531840015-28804-1-git-send-email-pbonzini@redhat.com> References: <1531840015-28804-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 17 Jul 2018 15:07:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 17 Jul 2018 15:07:09 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 06/13] 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Calvin Lee 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 Message-Id: <20180512000545.966-2-cyrus296@gmail.com> Signed-off-by: Paolo Bonzini --- 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 cd7d747..d3b75f0 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 1.8.3.1