From owner-svn-src-head@freebsd.org Thu Sep 10 01:49:54 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8E1233E44D0; Thu, 10 Sep 2020 01:49:54 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Bn1zQ3FXdz4Fl0; Thu, 10 Sep 2020 01:49:54 +0000 (UTC) (envelope-from bdragon@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 52DF2B05C; Thu, 10 Sep 2020 01:49:54 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 08A1nsn6045127; Thu, 10 Sep 2020 01:49:54 GMT (envelope-from bdragon@FreeBSD.org) Received: (from bdragon@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 08A1nsou045126; Thu, 10 Sep 2020 01:49:54 GMT (envelope-from bdragon@FreeBSD.org) Message-Id: <202009100149.08A1nsou045126@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdragon set sender to bdragon@FreeBSD.org using -f From: Brandon Bergren Date: Thu, 10 Sep 2020 01:49:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r365548 - head/sys/powerpc/powernv X-SVN-Group: head X-SVN-Commit-Author: bdragon X-SVN-Commit-Paths: head/sys/powerpc/powernv X-SVN-Commit-Revision: 365548 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.33 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: Thu, 10 Sep 2020 01:49:54 -0000 Author: bdragon Date: Thu Sep 10 01:49:53 2020 New Revision: 365548 URL: https://svnweb.freebsd.org/changeset/base/365548 Log: [PowerPC] Fix setting of time in OPAL There were multiple bugs in the OPAL RTC code which had never been discovered, as the default configuration of OPAL machines is to have the BMC / FSP control the RTC. * Fix calling convention for setting the time -- the variables are passed directly in CPU registers, not via memory. * Fix bug in the bcd encoding routines. (from jhibbits) Tested on POWER9 Talos II (BE) and POWER9 Blackbird (LE). Reviewed by: jhibbits (in irc) Sponsored by: Tag1 Consulting, Inc. Modified: head/sys/powerpc/powernv/opal_dev.c Modified: head/sys/powerpc/powernv/opal_dev.c ============================================================================== --- head/sys/powerpc/powernv/opal_dev.c Thu Sep 10 00:50:18 2020 (r365547) +++ head/sys/powerpc/powernv/opal_dev.c Thu Sep 10 01:49:53 2020 (r365548) @@ -256,15 +256,15 @@ bin2bcd32(int bin) int tmp; tmp = bin % 100; - out += bin2bcd(tmp) * 1; + out += bin2bcd(tmp) * 0x1; bin = bin / 100; tmp = bin % 100; - out += bin2bcd(tmp) * 100; + out += bin2bcd(tmp) * 0x100; bin = bin / 100; tmp = bin % 100; - out += bin2bcd(tmp) * 10000; + out += bin2bcd(tmp) * 0x10000; return (out); } @@ -297,7 +297,7 @@ opal_gettime(device_t dev, struct timespec *ts) ct.day = bcd2bin((ymd & 0x000000ff) >> 0); ct.mon = bcd2bin((ymd & 0x0000ff00) >> 8); - ct.year = bcd2bin32((ymd & 0xffff0000) >> 16); + ct.year = bcd2bin32((ymd & 0xffff0000) >> 16); return (clock_ct_to_ts(&ct, ts)); } @@ -321,11 +321,12 @@ opal_settime(device_t dev, struct timespec *ts) hmsm |= ((uint64_t)bin2bcd(ct.min) << 48); hmsm |= ((uint64_t)bin2bcd(ct.hour) << 56); - hmsm = htobe64(hmsm); - ymd = htobe32(ymd); - + /* + * We do NOT swap endian here, because the values are being sent + * via registers instead of indirect via memory. + */ do { - rv = opal_call(OPAL_RTC_WRITE, vtophys(&ymd), vtophys(&hmsm)); + rv = opal_call(OPAL_RTC_WRITE, ymd, hmsm); if (rv == OPAL_BUSY_EVENT) { rv = opal_call(OPAL_POLL_EVENTS, 0); pause("opalrtc", 1);