From patchwork Mon Oct 29 03:32:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Huang X-Patchwork-Id: 149621 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3598119ljp; Sun, 28 Oct 2018 20:33:22 -0700 (PDT) X-Google-Smtp-Source: AJdET5eGXatXMFcipq79EITI7d5mUwCNLWTu5OMYd2g5HffSHzvSQGSmyh0k4q15jU+fFut9mCwp X-Received: by 2002:ae9:f50d:: with SMTP id o13mr8150005qkg.137.1540784002423; Sun, 28 Oct 2018 20:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540784002; cv=none; d=google.com; s=arc-20160816; b=OaEyvbBY2VRiPgCNRPFxD1NJZPq2mdd4Wlz+ED+MV5+GEySR5n2ERtcQFVFwQMOpD2 R2wF1cD4mDsGwHGcbye1ZJgreNCO94TnzOLR+0TKAckN6ArCs3Ff2dWx/I6LObVt6SXv jal5OPaQYkEBPauULA4TOKvi1OrEmodDRehGMuaBONmpUg+WlqI5dO1p9hxZjh5R98ww CJXloJODDi/fWFMgAm6PdZeRKWxcLMQbj7f2zpWaRrGQW3CsFN549A9ok2QKC60Lm70b EK1Y9xJ3KnA+Yq/YnyBWS+8FddnvUaiCd7VGzThyWyxOUnnN8U8avKrSNSFyksQP90zN P6+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=1ibsHPaCtfSYPgqdA9UgseoQZcVyLO7ZV31ScUoxXdk=; b=epEuHYEG0FKy5b4SPSLuKg/pNKufgOofmR72qL7CXhH+FXepLzVCmYGtQ71rhxPDr7 XIs4NP2lm4s0kX30C3mmUruTIdoiIcbCWrg5+ol511smcuDrpaOIpvuHUhpP9uRd0lZd qRt5dqPmRgJYOIedLknYbp+Id7AO+/l4pwX1xJii29WLC63YJqPE1qgAJeegQjqsFN9S 4TH6cAmhWHci/oZH7alaEMgU6n1BJ9oWglFlmNSnNW6ZHi6MnhDBsX56pt18had9VG9F Aoi+NgynIr8JijZ9fdohxGvLFpog/6RbasUIRM1OwKRQPV5DQxcKmpBLu5VfYkJswb15 ENAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Fj5QupSf; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id b7si4170185qvi.27.2018.10.28.20.33.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Oct 2018 20:33:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Fj5QupSf; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A5B9521184ACB; Sun, 28 Oct 2018 20:33:19 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::62a; helo=mail-pl1-x62a.google.com; envelope-from=ming.huang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 302112117FD5E for ; Sun, 28 Oct 2018 20:33:18 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id f10-v6so3120670plr.1 for ; Sun, 28 Oct 2018 20:33:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KoDFckvlfV4+802VaAqbzUWmCBz2s00v/bCGJdzyEPo=; b=Fj5QupSf/Dp8YEVJBvobhEbafAMIXDN4NT59m2VLHN/s0M0ZmY58Kw99KMLjLtREhW VLipPZSksFF32AYVZKsT6rlqSHfABr4Rtlho5yN8JISXPfJRwHfLVtTA5Q3ugw/M/tfK j/mR2JqdIiLQOBWzoWMiEcsa8qgz5vv6sjBMs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KoDFckvlfV4+802VaAqbzUWmCBz2s00v/bCGJdzyEPo=; b=QEJRB3wGVTFzXA+1gaDhJO3dE/g0n2uL4bIwA0+35Dc0W3sxqCdcz+3b3xHxVLxvSj xqUVw1CVlrFyXqd7rUAiPRGoyl/J9QZ4i2b3uqjrdP4TB/LPOfMLvJ2D47dj75/zHPAM 6VZu2jiSz0P5ULJuVTyAZ5XL26sTtCosVJ9o2cyXQPoSsUUqXohPEpQ2Ck15kArfMZpd KYtabpS88c1C4H74af/2On1hMkgCdTqPDdVytrJweoir7jqsA0wllnAe77h/7SM6KhK5 6UhxE199FhZnOopwH2DoUuYCuahA/RDHhdIgSlMmSormUei211kTfp6u8eCNP3g/3eDt MyHA== X-Gm-Message-State: AGRZ1gKOOk3O0OWMGjlHQ2c54gSQXstZRbfBnE+uHmaM6X+AuYdwXHxu YRKam60dUOW5KlXcNnvr4c6oVGjXDOY= X-Received: by 2002:a17:902:7108:: with SMTP id a8-v6mr4396666pll.290.1540783997768; Sun, 28 Oct 2018 20:33:17 -0700 (PDT) Received: from localhost.localdomain ([120.31.149.194]) by smtp.gmail.com with ESMTPSA id j5-v6sm22318872pgm.79.2018.10.28.20.33.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Oct 2018 20:33:17 -0700 (PDT) From: Ming Huang To: leif.lindholm@linaro.org, linaro-uefi@lists.linaro.org, edk2-devel@lists.01.org, graeme.gregory@linaro.org Date: Mon, 29 Oct 2018 11:32:43 +0800 Message-Id: <20181029033249.45363-7-ming.huang@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181029033249.45363-1-ming.huang@linaro.org> References: <20181029033249.45363-1-ming.huang@linaro.org> Subject: [edk2] [PATCH edk2-platforms v1 06/12] Silicon/Hisilicon: Modify for SBBR fwts SetTime_Func test case X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huangming23@huawei.com, xinliang.liu@linaro.org, john.garry@huawei.com, zhangjinsong2@huawei.com, huangdaode@hisilicon.com, zhangfeng56@huawei.com, michael.d.kinney@intel.com, lersek@redhat.com, wanghuiqiang@huawei.com MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" There is no variable to keep timezone and daylight, so read it from the hardware first and create a new variable to keep it for the next gettime process. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ming Huang --- Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf | 2 +- Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h | 4 + Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c | 175 +++++++++++++++++++- 3 files changed, 179 insertions(+), 2 deletions(-) -- 2.18.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf index 4e963fd453..8e559d7b70 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf @@ -42,4 +42,4 @@ UefiRuntimeLib # Use EFiAtRuntime to check stage [Depex] - gEfiCpuArchProtocolGuid + gEfiCpuArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h index f329108858..b95ebc654a 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h @@ -41,6 +41,10 @@ #define M41T83_REGADDR_ALARM2DATE 0x15 #define M41T83_REGADDR_ALARM2MONTH 0x14 +//UEFI SPEC 2.7,page 295 +#define TIME_ZONE_MIN -1440 +#define TIME_ZONE_MAX 1440 + typedef union { struct { UINT8 TD0:1; diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c index 1f50ad4b64..a2063aff76 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c @@ -32,6 +32,9 @@ extern I2C_DEVICE gRtcDevice; STATIC EFI_LOCK mRtcLock; +STATIC CONST CHAR16 mTimeZoneVariableName[] = L"M41T83RtcTimeZone"; +STATIC CONST CHAR16 mDaylightVariableName[] = L"M41T83RtcDaylight"; + /** Read RTC content through its registers. @@ -182,6 +185,7 @@ LibSetTime ( RTC_M41T83_TIME BcdTime; UINT16 CenturyBase = 2000; UINTN LineNum = 0; + UINTN EpochSeconds; if (NULL == Time) { return EFI_INVALID_PARAMETER; @@ -206,6 +210,21 @@ LibSetTime ( SetMem (&BcdTime, sizeof (RTC_M41T83_TIME), 0); + EpochSeconds = EfiTimeToEpoch (Time); + + // Adjust for the correct time zone, i.e. convert to UTC time zone + if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) { + EpochSeconds -= Time->TimeZone * SEC_PER_MIN; + } + + // Adjust for the correct period + if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) { + // Convert to un-adjusted time, i.e. fall back one hour + EpochSeconds -= SEC_PER_HOUR; + } + + EpochToEfiTime (EpochSeconds, Time); + // Acquire RTC Lock to make access to RTC atomic if (!EfiAtRuntime ()) { EfiAcquireLock (&mRtcLock); @@ -254,6 +273,43 @@ LibSetTime ( LineNum = __LINE__; goto Exit; } + // Save the current time zone information into non-volatile storage + Status = EfiSetVariable ( + (CHAR16 *)mTimeZoneVariableName, + &gEfiCallerIdGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + sizeof (Time->TimeZone), + (VOID *)&(Time->TimeZone) + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "LibSetTime: can not save %s variable to non-volatile storage, Status = %r\n", + mTimeZoneVariableName, + Status + )); + LineNum = __LINE__; + goto Exit; + } + + // Save the current daylight information into non-volatile storage + Status = EfiSetVariable ( + (CHAR16 *)mDaylightVariableName, + &gEfiCallerIdGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + sizeof (Time->Daylight), + (VOID *)&(Time->Daylight) + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "LibSetTime: can not to save %s variable to non-volatile storage, Status = %r\n", + mDaylightVariableName, + Status + )); + LineNum = __LINE__; + goto Exit; + } Exit: OemReleaseOwnershipOfRtc (); @@ -295,6 +351,10 @@ LibGetTime ( UINTN LineNum = 0; BOOLEAN IsTimeInvalid = FALSE; UINT8 TimeTemp[7] = {0}; + UINTN EpochSeconds; + INT16 TimeZone; + UINT8 Daylight; + UINTN Size; // Ensure Time is a valid pointer if (Time == NULL) { @@ -336,7 +396,6 @@ LibGetTime ( Time->Hour = BcdToDecimal8 (BcdTime.Hour.Bits.Hours); Time->Minute = BcdToDecimal8 (BcdTime.Minute.Bits.Minutes); Time->Second = BcdToDecimal8 (BcdTime.Second.Bits.Seconds); - Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE; if (!IsTimeValid (Time)) { Status = EFI_DEVICE_ERROR; @@ -345,6 +404,120 @@ LibGetTime ( goto Exit; } + EpochSeconds = EfiTimeToEpoch (Time); + + Size = sizeof (TimeZone); + Status = EfiGetVariable ( + (CHAR16 *)mTimeZoneVariableName, + &gEfiCallerIdGuid, + NULL, + &Size, + (VOID *)&TimeZone + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "LibGetTime: can not get %s variable, Status = %r\n", + mTimeZoneVariableName, + Status + )); + if (Status != EFI_NOT_FOUND) { + LineNum = __LINE__; + goto Exit; + } + + // The time zone variable does not exist in non-volatile storage, so create it. + Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE; + // Store it + Status = EfiSetVariable ( + (CHAR16 *)mTimeZoneVariableName, + &gEfiCallerIdGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + Size, + (VOID *)&(Time->TimeZone) + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "LibGetTime: can not save %s variable to non-volatile storage, Status = %r\n", + mTimeZoneVariableName, + Status + )); + LineNum = __LINE__; + goto Exit; + } + } else { + // Got the time zone + Time->TimeZone = TimeZone; + + // Check TimeZone bounds: -1440 to 1440 or 2047 + if (((Time->TimeZone < TIME_ZONE_MIN) || (Time->TimeZone > TIME_ZONE_MAX)) + && (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE)) { + Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE; + } + + // Adjust for the correct time zone + if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) { + EpochSeconds += Time->TimeZone * SEC_PER_MIN; + } + } + + // Get the current daylight information from non-volatile storage + Size = sizeof (Daylight); + Status = EfiGetVariable ( + (CHAR16 *)mDaylightVariableName, + &gEfiCallerIdGuid, + NULL, + &Size, + (VOID *)&Daylight + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "LibGetTime: Failed to get %s variable, Status = %r\n", + mDaylightVariableName, + Status + )); + if (Status != EFI_NOT_FOUND) { + goto Exit; + } + // The daylight variable does not exist in non-volatile storage, so create it. + Time->Daylight = 0; + // Store it + Status = EfiSetVariable ( + (CHAR16 *)mDaylightVariableName, + &gEfiCallerIdGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + Size, + (VOID *)&(Time->Daylight) + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "LibGetTime: can not save %s variable to non-volatile storage, Status = %r\n", + mDaylightVariableName, + Status + )); + LineNum = __LINE__; + goto Exit; + } + } else { + // Got the daylight information + Time->Daylight = Daylight; + + // Adjust for the correct period + if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) { + // Convert to adjusted time, i.e. spring forwards one hour + EpochSeconds += SEC_PER_HOUR; + } + } + + // Convert from internal 32-bit time to UEFI time + EpochToEfiTime (EpochSeconds, Time); + Exit: OemReleaseOwnershipOfRtc (); // Release RTC Lock.