diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2016-02-01 02:32:44 +0000 |
---|---|---|
committer | niruiyu <niruiyu@Edk2> | 2016-02-01 02:32:44 +0000 |
commit | bf46bd46188fd002b3bc7e15d8de50be23c1fd04 (patch) | |
tree | 9cc07b76ee58f8fa838ddb0cb582b8236d2a16b9 /PcAtChipsetPkg | |
parent | 39bbd1fbbf26851646d75a0a57883ab80da9a858 (diff) | |
download | edk2-bf46bd46188fd002b3bc7e15d8de50be23c1fd04.tar.gz edk2-bf46bd46188fd002b3bc7e15d8de50be23c1fd04.tar.bz2 edk2-bf46bd46188fd002b3bc7e15d8de50be23c1fd04.zip |
PcAtChipsetPkg/Rtc: Don't unnecessarily create timezone variable.
When SetTime() is called with EFI_UNSPECIFIED_TIMEZONE, the code
can optimally not create the private timezone variable because
absence of timezone variable indicates the timezone is unspecified.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19783 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'PcAtChipsetPkg')
-rw-r--r-- | PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c | 81 |
1 files changed, 38 insertions, 43 deletions
diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c index bf221768c8..acc70a67b7 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c @@ -1,7 +1,7 @@ /** @file
RTC Architectural Protocol GUID as defined in DxeCis 0.96.
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -14,6 +14,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "PcRtc.h"
+//
+// Days of month.
+//
+UINTN mDayOfMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+//
+// The name of NV variable to store the timezone and daylight saving information.
+//
+CHAR16 mTimeZoneVariableName[] = L"RTC";
+
/**
Compare the Hour, Minute and Second of the From time and the To time.
@@ -182,11 +192,11 @@ PcRtcInit ( //
DataSize = sizeof (UINT32);
Status = EfiGetVariable (
- L"RTC",
+ mTimeZoneVariableName,
&gEfiCallerIdGuid,
NULL,
&DataSize,
- (VOID *) &TimerVar
+ &TimerVar
);
if (!EFI_ERROR (Status)) {
Time.TimeZone = (INT16) TimerVar;
@@ -477,15 +487,29 @@ PcRtcSetTime ( //
// Write timezone and daylight to RTC variable
//
- TimerVar = Time->Daylight;
- TimerVar = (UINT32) ((TimerVar << 16) | (UINT16)(Time->TimeZone));
- Status = EfiSetVariable (
- L"RTC",
- &gEfiCallerIdGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- sizeof (TimerVar),
- &TimerVar
- );
+ if (Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) {
+ Status = EfiSetVariable (
+ mTimeZoneVariableName,
+ &gEfiCallerIdGuid,
+ 0,
+ 0,
+ NULL
+ );
+ if (Status == EFI_NOT_FOUND) {
+ Status = EFI_SUCCESS;
+ }
+ } else {
+ TimerVar = Time->Daylight;
+ TimerVar = (UINT32) ((TimerVar << 16) | (UINT16)(Time->TimeZone));
+ Status = EfiSetVariable (
+ mTimeZoneVariableName,
+ &gEfiCallerIdGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ sizeof (TimerVar),
+ &TimerVar
+ );
+ }
+
if (EFI_ERROR (Status)) {
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
@@ -987,28 +1011,13 @@ DayValid ( IN EFI_TIME *Time
)
{
- INTN DayOfMonth[12];
-
- DayOfMonth[0] = 31;
- DayOfMonth[1] = 29;
- DayOfMonth[2] = 31;
- DayOfMonth[3] = 30;
- DayOfMonth[4] = 31;
- DayOfMonth[5] = 30;
- DayOfMonth[6] = 31;
- DayOfMonth[7] = 31;
- DayOfMonth[8] = 30;
- DayOfMonth[9] = 31;
- DayOfMonth[10] = 30;
- DayOfMonth[11] = 31;
-
//
// The validity of Time->Month field should be checked before
//
ASSERT (Time->Month >=1);
ASSERT (Time->Month <=12);
if (Time->Day < 1 ||
- Time->Day > DayOfMonth[Time->Month - 1] ||
+ Time->Day > mDayOfMonth[Time->Month - 1] ||
(Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
) {
return FALSE;
@@ -1144,22 +1153,8 @@ IsWithinOneDay ( IN EFI_TIME *To
)
{
- UINT8 DayOfMonth[12];
BOOLEAN Adjacent;
- DayOfMonth[0] = 31;
- DayOfMonth[1] = 29;
- DayOfMonth[2] = 31;
- DayOfMonth[3] = 30;
- DayOfMonth[4] = 31;
- DayOfMonth[5] = 30;
- DayOfMonth[6] = 31;
- DayOfMonth[7] = 31;
- DayOfMonth[8] = 30;
- DayOfMonth[9] = 31;
- DayOfMonth[10] = 30;
- DayOfMonth[11] = 31;
-
Adjacent = FALSE;
//
@@ -1186,7 +1181,7 @@ IsWithinOneDay ( Adjacent = TRUE;
}
}
- } else if (From->Day == DayOfMonth[From->Month - 1]) {
+ } else if (From->Day == mDayOfMonth[From->Month - 1]) {
if ((CompareHMS(From, To) >= 0)) {
Adjacent = TRUE;
}
|