From nobody Thu Oct 31 23:49:31 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=yadro.com ARC-Seal: i=1; a=rsa-sha256; t=1592047296; cv=none; d=zohomail.com; s=zohoarc; b=RdvZuAZFbJ2vo26blCGEFl+mXVg0Kiq9U+9LjBeOC1jEPK1JY+Cq2SsKZ0SWKD84L9OrgSIwji38CufefUMZHSgQPfrsOIkuxy44RtOkf5Z+jOrfZ8eJ6fSQ6Jy11/Oenv6fp64K1SQDnO6SMs5OOXD9zOJ7oZg7OWuFfzsR1MY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592047296; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:To; bh=grIc9fE15xhhk7L77xmLmVByr8Pd3o78eXOx8e20k+I=; b=hXhCGENgW6d1totU41iuA15gV1hshT2Rqi6DtfGXo7os1o8rTe70ve1PBTJOOQrTQw5ZRiOZIqLs6H9S2bEtccafIfzSqg238RTBw4IKS//Gspq4iUjmJcieb1awy6qTaPcjSSAWfKRTmUocsJ+VRf/mwNz9jg3mt7d9a2PfFBw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1592047296029878.8002051209786; Sat, 13 Jun 2020 04:21:36 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id E889D10C1B93; Sat, 13 Jun 2020 11:21:31 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 4060110C1B8A for ; Sat, 13 Jun 2020 11:21:17 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mta-01.yadro.com (Postfix) with ESMTP id 851D14C83C; Sat, 13 Jun 2020 11:21:16 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5aMpPov6ypGO; Sat, 13 Jun 2020 14:21:15 +0300 (MSK) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 8C29F47D0B; Sat, 13 Jun 2020 14:21:14 +0300 (MSK) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Sat, 13 Jun 2020 14:21:14 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-transfer-encoding:content-type:content-type:mime-version :x-mailer:message-id:date:date:subject:subject:from:from :received:received:received; s=mta-01; t=1592047275; x= 1593861676; bh=alsXcJxWknvFuPc/oEcJ3hyIN36XcRR6QP0Aas7G7Cs=; b=s AksLQWofu2EMdvsmWBztHW7XAAWHgSIs6d6AHFWTIsRKb6vKibmov397Xfl2NG1S sTSiZl7OzZL2r24NPd1CrVnlvXS6QaJGr8JNfjdic/rwPL0X/1S0LaGwHtCTEO1A xGP0oLUMTZb46rvP0iUAPE+kIMKPNM0dBh5ofy0GDw= X-Virus-Scanned: amavisd-new at yadro.com From: Roman Bolshakov To: Date: Sat, 13 Jun 2020 14:19:12 +0300 Message-ID: <20200613111911.65497-1-r.bolshakov@yadro.com> MIME-Version: 1.0 X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) Message-ID-Hash: XPKQNLVWZX55TSLSXZVY5S5DMFYS4CNO X-Message-ID-Hash: XPKQNLVWZX55TSLSXZVY5S5DMFYS4CNO X-MailFrom: r.bolshakov@yadro.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: qemu-devel@nongnu.org, Roman Bolshakov X-Mailman-Version: 3.3.1 Precedence: list Subject: [SeaBIOS] [PATCH] timer: Handle decrements of PIT counter List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ++++ X-Spam-Level: **** Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: fail (Header signature does not verify) There's a fallback to PIT if TSC is not present but it doesn't work properly. It prevents boot from floppy on isapc and 486 cpu [1][2]. SeaBIOS configures PIT in Mode 2. PIT counter is decremented in the mode but timer_adjust_bits() thinks that the counter overflows and increases 32-bit tick counter on each detected "overflow". Invalid overflow detection results in 55ms time advance (1 / 18.2Hz) on each read from PIT counter. So all timers expire much faster and 5-second floppy timeout expires in 83 real microseconds (or just a bit longer). Provide counter direction to timer_adjust_bits() and normalize the counter to advance ticks in monotonically increasing TimerLast. 1. https://bugs.launchpad.net/seabios/+bug/1840719 2. https://lists.gnu.org/archive/html/qemu-devel/2019-08/msg03924.html Fixes: eac11944019 ("Unify pmtimer_read() and pittimer_read() code.") Reported-by: Philippe Mathieu-Daud=C3=A9 Cc: Kevin O'Connor Signed-off-by: Roman Bolshakov Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov --- src/hw/timer.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/hw/timer.c b/src/hw/timer.c index 56bb289..2441402 100644 --- a/src/hw/timer.c +++ b/src/hw/timer.c @@ -156,10 +156,15 @@ u32 TimerLast VARLOW; =20 // Add extra high bits to timers that have less than 32bits of precision. static u32 -timer_adjust_bits(u32 value, u32 validbits) +timer_adjust_bits(u32 value, u32 validbits, u8 countup) { u32 last =3D GET_LOW(TimerLast); - value =3D (last & ~validbits) | (value & validbits); + u32 validvalue; + if (countup) + validvalue =3D value & validbits; + else + validvalue =3D validbits - (value & validbits); + value =3D (last & ~validbits) | validvalue; if (value < last) value +=3D validbits + 1; SET_LOW(TimerLast, value); @@ -176,11 +181,11 @@ timer_read(void) return rdtscll() >> GET_GLOBAL(ShiftTSC); if (CONFIG_PMTIMER && port !=3D PORT_PIT_COUNTER0) // Read from PMTIMER - return timer_adjust_bits(inl(port), 0xffffff); + return timer_adjust_bits(inl(port), 0xffffff, 1); // Read from PIT. outb(PM_SEL_READBACK | PM_READ_VALUE | PM_READ_COUNTER0, PORT_PIT_MODE= ); u16 v =3D inb(PORT_PIT_COUNTER0) | (inb(PORT_PIT_COUNTER0) << 8); - return timer_adjust_bits(v, 0xffff); + return timer_adjust_bits(v, 0xffff, 0); } =20 // Return the TSC value that is 'msecs' time in the future. --=20 2.26.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org