From owner-svn-src-head@freebsd.org Tue Jan 16 03:02:42 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 45D59EBE3CB; Tue, 16 Jan 2018 03:02:42 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 200CC80432; Tue, 16 Jan 2018 03:02:42 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 68BA51A6F5; Tue, 16 Jan 2018 03:02:41 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w0G32fvk016740; Tue, 16 Jan 2018 03:02:41 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0G32ffX016739; Tue, 16 Jan 2018 03:02:41 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201801160302.w0G32ffX016739@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Tue, 16 Jan 2018 03:02:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328039 - head/sys/x86/isa X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: head/sys/x86/isa X-SVN-Commit-Revision: 328039 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jan 2018 03:02:42 -0000 Author: ian Date: Tue Jan 16 03:02:41 2018 New Revision: 328039 URL: https://svnweb.freebsd.org/changeset/base/328039 Log: Add static inline rtcin_locked() and rtcout_locked() functions for doing a related series of operations without doing a lock/unlock for each byte. Use them when reading and writing the entire set of time registers. The original rtcin() and writertc() functions which do lock/unlock on each byte still exist, because they are public and called by outside code. Modified: head/sys/x86/isa/atrtc.c Modified: head/sys/x86/isa/atrtc.c ============================================================================== --- head/sys/x86/isa/atrtc.c Tue Jan 16 02:56:27 2018 (r328038) +++ head/sys/x86/isa/atrtc.c Tue Jan 16 03:02:41 2018 (r328039) @@ -76,28 +76,23 @@ static u_char rtc_statusb = RTCSB_24HR; * RTC support routines */ -int -rtcin(int reg) +static inline u_char +rtcin_locked(int reg) { - u_char val; - RTC_LOCK; if (rtc_reg != reg) { inb(0x84); outb(IO_RTC, reg); rtc_reg = reg; inb(0x84); } - val = inb(IO_RTC + 1); - RTC_UNLOCK; - return (val); + return (inb(IO_RTC + 1)); } -void -writertc(int reg, u_char val) +static inline void +rtcout_locked(int reg, u_char val) { - RTC_LOCK; if (rtc_reg != reg) { inb(0x84); outb(IO_RTC, reg); @@ -106,9 +101,28 @@ writertc(int reg, u_char val) } outb(IO_RTC + 1, val); inb(0x84); +} + +int +rtcin(int reg) +{ + u_char val; + + RTC_LOCK; + val = rtcin_locked(reg); RTC_UNLOCK; + return (val); } +void +writertc(int reg, u_char val) +{ + + RTC_LOCK; + rtcout_locked(reg, val); + RTC_UNLOCK; +} + static void atrtc_start(void) { @@ -163,25 +177,28 @@ atrtc_set(struct timespec *ts) clock_ts_to_bcd(ts, &ct, false); mtx_lock(&atrtc_time_lock); + RTC_LOCK; /* Disable RTC updates and interrupts. */ - writertc(RTC_STATUSB, RTCSB_HALT | RTCSB_24HR); + rtcout_locked(RTC_STATUSB, RTCSB_HALT | RTCSB_24HR); - writertc(RTC_SEC, ct.sec); /* Write back Seconds */ - writertc(RTC_MIN, ct.min); /* Write back Minutes */ - writertc(RTC_HRS, ct.hour); /* Write back Hours */ - writertc(RTC_WDAY, ct.dow + 1); /* Write back Weekday */ - writertc(RTC_DAY, ct.day); /* Write back Day */ - writertc(RTC_MONTH, ct.mon); /* Write back Month */ - writertc(RTC_YEAR, ct.year & 0xff); /* Write back Year */ + /* Write all the time registers. */ + rtcout_locked(RTC_SEC, ct.sec); + rtcout_locked(RTC_MIN, ct.min); + rtcout_locked(RTC_HRS, ct.hour); + rtcout_locked(RTC_WDAY, ct.dow + 1); + rtcout_locked(RTC_DAY, ct.day); + rtcout_locked(RTC_MONTH, ct.mon); + rtcout_locked(RTC_YEAR, ct.year & 0xff); #ifdef USE_RTC_CENTURY - writertc(RTC_CENTURY, ct.year >> 8); /* ... and Century */ + rtcout_locked(RTC_CENTURY, ct.year >> 8); #endif /* Re-enable RTC updates and interrupts. */ - writertc(RTC_STATUSB, rtc_statusb); - rtcin(RTC_INTR); + rtcout_locked(RTC_STATUSB, rtc_statusb); + rtcin_locked(RTC_INTR); + RTC_UNLOCK; mtx_unlock(&atrtc_time_lock); } @@ -358,15 +375,17 @@ atrtc_gettime(device_t dev, struct timespec *ts) while (rtcin(RTC_STATUSA) & RTCSA_TUP) continue; critical_enter(); - ct.sec = rtcin(RTC_SEC); - ct.min = rtcin(RTC_MIN); - ct.hour = rtcin(RTC_HRS); - ct.day = rtcin(RTC_DAY); - ct.mon = rtcin(RTC_MONTH); - ct.year = rtcin(RTC_YEAR); + RTC_LOCK; + ct.sec = rtcin_locked(RTC_SEC); + ct.min = rtcin_locked(RTC_MIN); + ct.hour = rtcin_locked(RTC_HRS); + ct.day = rtcin_locked(RTC_DAY); + ct.mon = rtcin_locked(RTC_MONTH); + ct.year = rtcin_locked(RTC_YEAR); #ifdef USE_RTC_CENTURY - ct.year |= rtcin(RTC_CENTURY) << 8; + ct.year |= rtcin_locked(RTC_CENTURY) << 8; #endif + RTC_UNLOCK; critical_exit(); mtx_unlock(&atrtc_time_lock); /* dow is unused in timespec conversion and we have no nsec info. */