From nobody Fri Apr 19 08:49:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+59807+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+59807+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1589886980; cv=none; d=zohomail.com; s=zohoarc; b=XwobKnzt0OMFvqadoIlEWsHtFxk4dsDtbuQCMGNZ8YfDPPZcZwFHwSQmCJIjiYDgRcfpWL7Y/LPl0DNQC1VTd6jCF6Zdi2il6j9SfrFkfbjLnC4oZank1kAKqUbQHpA2UY9zoLI3V4JXLdAsSRrtYdkPXafa/sG8NtF4Yf+5dZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589886980; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=pvdTy5AwN6a6JsSmsWLjEZaYNHo21W6YkEgGTmyL0ds=; b=D9UZmvKKa3KAgkzB9kEI4+xNmQ3StSF8Cl2VO4wkW7yf8KtJftRtifF5LyL/3SCbREvXZO43zWMqem5263uFtPKszI4nMevlK6su31lutze+bB2ErH6s/x4a0/8JFtLvwWYkMPr3xKBLd9nnabr2SawqQ4xkc1s+iAdZFG2hS/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+59807+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1589886980812125.8193381471524; Tue, 19 May 2020 04:16:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YHFdYY1788612xXjE0auMGI5; Tue, 19 May 2020 04:16:20 -0700 X-Received: from huawei.com (huawei.com [45.249.212.190]) by mx.groups.io with SMTP id smtpd.web12.9703.1589886650526540545 for ; Tue, 19 May 2020 04:10:51 -0700 X-Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7EC1148D09386B2AD310; Tue, 19 May 2020 19:10:47 +0800 (CST) X-Received: from HGH1000039998.huawei.com (10.184.68.188) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Tue, 19 May 2020 19:10:41 +0800 From: Ming Huang To: , , CC: , , , , Subject: [edk2-devel] [RFC edk2-platforms v2 2/3] Hisilicon/Library: Move two functions to RtcHelperLib Date: Tue, 19 May 2020 19:08:40 +0800 Message-ID: <1589886521-82250-3-git-send-email-huangming23@huawei.com> In-Reply-To: <1589886521-82250-1-git-send-email-huangming23@huawei.com> References: <1589886521-82250-1-git-send-email-huangming23@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.184.68.188] X-CFilter-Loop: Reflected Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,huangming23@huawei.com X-Gm-Message-State: tNkYiz5tgsmVxpKQszDvK4t1x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589886980; bh=MpxypRAVX+zyrgwjKW/ivrV4tRv06rG/Q1udMkxgbuA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=nhjR5kvyaMuMVQ97/vhBfCR4kGAz2DfqymU0K8OwFI3BbdYcpp1sDE9oSEMzjQSPVto 0o0Mk99mjjxv6FEdKFE3+Ce1BrEhpa0e7S22cBEn3rsy+pBsUybxccg51REzJtQ4oBwzM GbITjBLebgCrPMtO4dAT8PbbsqbezlIRvbY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The functions of acquiring ownership of RTC will be used for other RTC library, so move them to RtcHelperLib. Rename them by add leading Oem for uniform. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ming Huang --- Platform/Hisilicon/D06/D06.dsc = | 1 + Silicon/Hisilicon/Include/Library/RtcHelperLib.h = | 29 ++++++ Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h = | 7 -- Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c = | 92 ++----------------- Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.in= f | 1 + Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c = | 94 ++++++++++++++++++++ Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf = | 32 +++++++ 7 files changed, 164 insertions(+), 92 deletions(-) diff --git a/Platform/Hisilicon/D06/D06.dsc b/Platform/Hisilicon/D06/D06.dsc index 000a4ee..eb20224 100644 --- a/Platform/Hisilicon/D06/D06.dsc +++ b/Platform/Hisilicon/D06/D06.dsc @@ -54,6 +54,7 @@ CpldIoLib|Silicon/Hisilicon/Library/CpldIoLib/CpldIoLib.inf =20 TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf + RtcHelperLib|Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf RealTimeClockLib|Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83= RealTimeClockLib.inf OemMiscLib|Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.inf OemAddressMapLib|Platform/Hisilicon/D06/Library/OemAddressMapD06/OemAddr= essMapD06.inf diff --git a/Silicon/Hisilicon/Include/Library/RtcHelperLib.h b/Silicon/His= ilicon/Include/Library/RtcHelperLib.h new file mode 100644 index 0000000..29ec900 --- /dev/null +++ b/Silicon/Hisilicon/Include/Library/RtcHelperLib.h @@ -0,0 +1,29 @@ +/** @file + + Copyright (c) 2018, Hisilicon Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef RTC_HELPER_LIB_H__ +#define RTC_HELPER_LIB_H__ + +// The delay is need for cpld and I2C. This is a empirical value. MemoryFe= nce is no need. +#define RTC_DELAY_30_MS 30000 +// The delay is need for cpld and I2C. This is a empirical value. MemoryFe= nce is no need. +#define RTC_DELAY_1000_MICROSECOND 1000 +// The delay is need for cpld and I2C. This is a empirical value. MemoryFe= nce is no need. +#define RTC_DELAY_2_MICROSECOND 2 + +EFI_STATUS +OemSwitchRtcI2cChannelAndLock ( + VOID + ); + +VOID +OemReleaseOwnershipOfRtc ( + VOID + ); + +#endif diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTim= eClock.h b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeC= lock.h index 81ff459..09329c4 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h @@ -10,13 +10,6 @@ #ifndef __M41T83_REAL_TIME_CLOCK_H__ #define __M41T83_REAL_TIME_CLOCK_H__ =20 -// The delay is need for cpld and I2C. This is a empirical value. MemoryFe= nce is no need. -#define RTC_DELAY_30_MS 30000 -// The delay is need for cpld and I2C. This is a empirical value. MemoryFe= nce is no need. -#define RTC_DELAY_1000_MICROSECOND 1000 -// The delay is need for cpld and I2C. This is a empirical value. MemoryFe= nce is no need. -#define RTC_DELAY_2_MICROSECOND 2 - #define M41T83_REGADDR_DOTSECONDS 0x00 #define M41T83_REGADDR_SECONDS 0x01 #define M41T83_REGADDR_MINUTES 0x02 diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTim= eClockLib.c b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTi= meClockLib.c index f339bcc..db356ca 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockL= ib.c +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockL= ib.c @@ -11,10 +11,9 @@ #include #include #include -#include -#include #include #include +#include #include #include #include @@ -26,70 +25,6 @@ extern I2C_DEVICE gRtcDevice; =20 STATIC EFI_LOCK mRtcLock; =20 -EFI_STATUS -SwitchRtcI2cChannelAndLock ( - VOID - ) -{ - UINT8 Temp; - UINT8 Count; - - for (Count =3D 0; Count < 100; Count++) { - // To get the other side's state is idle first - Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - if ((Temp & BIT3) !=3D 0) { - (VOID) MicroSecondDelay (RTC_DELAY_30_MS); - // Try 100 times, if BMC has not released the bus, return preemption= failed - if (Count =3D=3D 99) { - if (!EfiAtRuntime ()) { - DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state 100 tim= es fail!\n", - __FUNCTION__, __LINE__)); - } - return EFI_DEVICE_ERROR; - } - continue; - } - - // if BMC free the bus, can be set 1 preemption - Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - Temp =3D Temp | CPU_GET_I2C_CONTROL; - // CPU occupied RTC I2C State - WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); - (VOID) MicroSecondDelay (RTC_DELAY_2_MICROSECOND); - Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - // Is preempt success - if(CPU_GET_I2C_CONTROL =3D=3D (Temp & CPU_GET_I2C_CONTROL)) { - break; - } - if (Count =3D=3D 99) { - if (!EfiAtRuntime ()) { - DEBUG((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state fail !!! = \n", - __FUNCTION__, __LINE__)); - } - return EFI_DEVICE_ERROR; - } - (VOID) MicroSecondDelay (RTC_DELAY_30_MS); - } - - //Polling BMC RTC I2C status - for (Count =3D 0; Count < 100; Count++) { - Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - if ((Temp & BIT3) =3D=3D 0) { - return EFI_SUCCESS; - } - (VOID) MicroSecondDelay (RTC_DELAY_30_MS); - } - - //If the BMC occupies the RTC I2C Channel, write back the CPU side is id= le - // or the subsequent BMC will not preempt - Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - Temp =3D Temp & (~CPU_GET_I2C_CONTROL); - WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); - - return EFI_NOT_READY; -} - - /** Read RTC content through its registers. =20 @@ -136,19 +71,6 @@ RtcWrite ( return Status; } =20 -VOID -ReleaseOwnershipOfRtc ( - VOID - ) -{ - UINT8 Temp; - - Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - Temp =3D Temp & ~CPU_GET_I2C_CONTROL; - WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); -} - - EFI_STATUS InitializeM41T83 ( VOID @@ -172,7 +94,7 @@ InitializeM41T83 ( return Status; } =20 - Status =3D SwitchRtcI2cChannelAndLock (); + Status =3D OemSwitchRtcI2cChannelAndLock (); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Get i2c preemption failed: %r\n", Status)); if (!EfiAtRuntime ()) { @@ -225,7 +147,7 @@ InitializeM41T83 ( =20 Exit: // Release RTC Lock. - ReleaseOwnershipOfRtc (); + OemReleaseOwnershipOfRtc (); if (!EfiAtRuntime ()) { EfiReleaseLock (&mRtcLock); } @@ -268,7 +190,7 @@ LibSetTime ( return EFI_INVALID_PARAMETER; } =20 - Status =3D SwitchRtcI2cChannelAndLock (); + Status =3D OemSwitchRtcI2cChannelAndLock (); if (EFI_ERROR (Status)) { return Status; } @@ -326,7 +248,7 @@ LibSetTime ( } =20 Exit: - ReleaseOwnershipOfRtc (); + OemReleaseOwnershipOfRtc (); // Release RTC Lock. if (!EfiAtRuntime ()) { if (EFI_ERROR (Status)) { @@ -371,7 +293,7 @@ LibGetTime ( return EFI_INVALID_PARAMETER; } =20 - Status =3D SwitchRtcI2cChannelAndLock (); + Status =3D OemSwitchRtcI2cChannelAndLock (); if (EFI_ERROR (Status)) { return Status; } @@ -416,7 +338,7 @@ LibGetTime ( } =20 Exit: - ReleaseOwnershipOfRtc (); + OemReleaseOwnershipOfRtc (); // Release RTC Lock. if (!EfiAtRuntime ()) { if (EFI_ERROR (Status)) { diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTim= eClockLib.inf b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83Real= TimeClockLib.inf index 9344c6d..5970c0e 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockL= ib.inf +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockL= ib.inf @@ -31,6 +31,7 @@ I2CLib IoLib PcdLib + RtcHelperLib TimeBaseLib TimerLib UefiLib diff --git a/Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c b/Silico= n/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c new file mode 100644 index 0000000..af6b8dc --- /dev/null +++ b/Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c @@ -0,0 +1,94 @@ +/** @file + + Copyright (c) 2020, Hisilicon Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +EFI_STATUS +OemSwitchRtcI2cChannelAndLock ( + VOID + ) +{ + UINT8 Temp; + UINT8 Count; + + for (Count =3D 0; Count < 100; Count++) { + // To get the other side's state is idle first + Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + if ((Temp & BIT3) !=3D 0) { + (VOID) MicroSecondDelay (RTC_DELAY_30_MS); + // Try 100 times, if BMC has not released the bus, return preemption= failed + if (Count =3D=3D 99) { + if (!EfiAtRuntime ()) { + DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state 100 tim= es fail!\n", + __FUNCTION__, __LINE__)); + } + return EFI_DEVICE_ERROR; + } + continue; + } + + // if BMC free the bus, can be set 1 preemption + Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + Temp =3D Temp | CPU_GET_I2C_CONTROL; + // CPU occupied RTC I2C State + WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); + (VOID)MicroSecondDelay (RTC_DELAY_2_MICROSECOND); + Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + // Is preempt success + if (CPU_GET_I2C_CONTROL =3D=3D (Temp & CPU_GET_I2C_CONTROL)) { + break; + } + if (Count =3D=3D 99) { + if (!EfiAtRuntime ()) { + DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state fail !!!= \n", + __FUNCTION__, __LINE__)); + } + return EFI_DEVICE_ERROR; + } + (VOID)MicroSecondDelay (RTC_DELAY_30_MS); + } + + //Polling BMC RTC I2C status + for (Count =3D 0; Count < 100; Count++) { + Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + if ((Temp & BIT3) =3D=3D 0) { + return EFI_SUCCESS; + } + (VOID)MicroSecondDelay (RTC_DELAY_30_MS); + } + + //If the BMC occupies the RTC I2C Channel, write back the CPU side is id= le + // or the subsequent BMC will not preempt + Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + Temp =3D Temp & (~CPU_GET_I2C_CONTROL); + WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); + + return EFI_NOT_READY; +} + +VOID +OemReleaseOwnershipOfRtc ( + VOID + ) +{ + UINT8 Temp; + + Temp =3D ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + Temp =3D Temp & ~CPU_GET_I2C_CONTROL; + WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); + return ; +} diff --git a/Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf b/Sili= con/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf new file mode 100644 index 0000000..1a36e64 --- /dev/null +++ b/Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf @@ -0,0 +1,32 @@ +#/** @file +# +# Copyright (c) 2020, Hisilicon Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D RtcHelperLib + FILE_GUID =3D 5cb1a98f-2408-4fef-b68f-d5d04ff6a91f + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RtcHelperLib + +[Sources.common] + RtcHelperLib.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + Platform/Hisilicon/D06/D06.dec + Silicon/Hisilicon/HisiPkg.dec + +[LibraryClasses] + CpldIoLib + DebugLib + IoLib + +[Depex] + TRUE --=20 2.8.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#59807): https://edk2.groups.io/g/devel/message/59807 Mute This Topic: https://groups.io/mt/74322489/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-