//\r
// Acquire RTC Lock to make access to RTC atomic\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiAcquireLock (&Global->RtcLock);\r
}\r
//\r
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
Time.Month = RtcRead (RTC_ADDRESS_MONTH);\r
Time.Year = RtcRead (RTC_ADDRESS_YEAR);\r
\r
- if (RtcTestCenturyRegister () == EFI_SUCCESS) {\r
- Century = (UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f);\r
- } else {\r
- Century = RtcRead (RTC_ADDRESS_CENTURY);\r
- }\r
-\r
+ Century = RtcRead (RTC_ADDRESS_CENTURY);\r
+ Time.Year = (UINT16) (Century * 100 + Time.Year);\r
+ \r
//\r
// Set RTC configuration after get original time\r
// The value of bit AIE should be reserved.\r
//\r
// Release RTC Lock.\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
- //\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
//\r
DataSize = sizeof (UINT32);\r
Status = EfiGetVariable (\r
- L"TimerVar",\r
- &gEfiGenericPlatformVariableGuid,\r
+ L"RTC",\r
+ &gEfiCallerIdGuid,\r
NULL,\r
&DataSize,\r
(VOID *) &TimerVar\r
//\r
// Acquire RTC Lock to make access to RTC atomic\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiAcquireLock (&Global->RtcLock);\r
}\r
//\r
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
Time->Month = RtcRead (RTC_ADDRESS_MONTH);\r
Time->Year = RtcRead (RTC_ADDRESS_YEAR);\r
\r
- if (RtcTestCenturyRegister () == EFI_SUCCESS) {\r
- Century = (UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f);\r
- } else {\r
- Century = RtcRead (RTC_ADDRESS_CENTURY);\r
- }\r
-\r
+ Century = RtcRead (RTC_ADDRESS_CENTURY);\r
+ Time->Year = (UINT16) (Century * 100 + Time->Year);\r
+ \r
//\r
// Release RTC Lock.\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
//\r
- // Get the variable that containts the TimeZone and Daylight fields\r
+ // Get the variable that contains the TimeZone and Daylight fields\r
//\r
Time->TimeZone = Global->SavedTimeZone;\r
Time->Daylight = Global->Daylight;\r
//\r
// Acquire RTC Lock to make access to RTC atomic\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiAcquireLock (&Global->RtcLock);\r
}\r
//\r
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
+ EfiReleaseLock (&Global->RtcLock);\r
}\r
return Status;\r
}\r
RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH, RtcTime.Day);\r
RtcWrite (RTC_ADDRESS_MONTH, RtcTime.Month);\r
RtcWrite (RTC_ADDRESS_YEAR, (UINT8) RtcTime.Year);\r
- if (RtcTestCenturyRegister () == EFI_SUCCESS) {\r
- Century = (UINT8) ((Century & 0x7f) | (RtcRead (RTC_ADDRESS_CENTURY) & 0x80));\r
- }\r
-\r
RtcWrite (RTC_ADDRESS_CENTURY, Century);\r
\r
//\r
//\r
// Release RTC Lock.\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
//\r
- // Set the variable that containts the TimeZone and Daylight fields\r
+ // Set the variable that contains the TimeZone and Daylight fields\r
//\r
Global->SavedTimeZone = Time->TimeZone;\r
Global->Daylight = Time->Daylight;\r
TimerVar = Time->Daylight;\r
TimerVar = (UINT32) ((TimerVar << 16) | Time->TimeZone);\r
Status = EfiSetVariable (\r
- L"TimerVar",\r
- &gEfiGenericPlatformVariableGuid,\r
+ L"RTC",\r
+ &gEfiCallerIdGuid,\r
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
sizeof (TimerVar),\r
&TimerVar\r
Returns the current wakeup alarm clock setting.\r
\r
@param Enabled Indicates if the alarm is currently enabled or disabled.\r
- @param Pending Indicates if the alarm signal is pending and requires acknowledgement.\r
+ @param Pending Indicates if the alarm signal is pending and requires acknowledgment.\r
@param Time The current alarm setting.\r
@param Global For global use inside this module.\r
\r
UINT8 Century;\r
\r
//\r
- // Check paramters for null pointers\r
+ // Check parameters for null pointers\r
//\r
if ((Enabled == NULL) || (Pending == NULL) || (Time == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
//\r
// Acquire RTC Lock to make access to RTC atomic\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiAcquireLock (&Global->RtcLock);\r
}\r
//\r
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
Time->Year = RtcRead (RTC_ADDRESS_YEAR);\r
}\r
\r
- if (RtcTestCenturyRegister () == EFI_SUCCESS) {\r
- Century = (UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f);\r
- } else {\r
- Century = RtcRead (RTC_ADDRESS_CENTURY);\r
- }\r
-\r
+ Century = RtcRead (RTC_ADDRESS_CENTURY);\r
+ Time->Year = (UINT16) (Century * 100 + Time->Year);\r
+ \r
//\r
// Release RTC Lock.\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
// Just support set alarm time within 24 hours\r
//\r
PcRtcGetTime (&RtcTime, &Capabilities, Global);\r
+ Status = RtcTimeFieldsValid (&RtcTime);\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
if (!IsWithinOneDay (&RtcTime, Time)) {\r
return EFI_UNSUPPORTED;\r
}\r
//\r
// Acquire RTC Lock to make access to RTC atomic\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiAcquireLock (&Global->RtcLock);\r
}\r
//\r
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
//\r
// Release RTC Lock.\r
//\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
+ //Code here doesn't consider the runtime environment.\r
if (!EfiAtRuntime ()) {\r
EfiReleaseLock (&Global->RtcLock);\r
}\r
return EFI_SUCCESS;\r
}\r
\r
-/**\r
- See if centry register of RTC is valid.\r
-\r
- @retval EFI_SUCCESS Century register is valid.\r
- @retval EFI_DEVICE_ERROR Century register is NOT valid.\r
-**/\r
-EFI_STATUS\r
-RtcTestCenturyRegister (\r
- VOID\r
- )\r
-{\r
- UINT8 Century;\r
- UINT8 Temp;\r
-\r
- Century = RtcRead (RTC_ADDRESS_CENTURY);\r
- Temp = (UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f);\r
- RtcWrite (RTC_ADDRESS_CENTURY, Century);\r
- if (Temp == 0x19 || Temp == 0x20) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- return EFI_DEVICE_ERROR;\r
-}\r
\r
/**\r
Checks an 8-bit BCD value, and converts to an 8-bit value if valid.\r
{\r
BOOLEAN IsPM;\r
\r
- if ((Time->Hour) & 0x80) {\r
+ if ((Time->Hour & 0x80) != 0) {\r
IsPM = TRUE;\r
} else {\r
IsPM = FALSE;\r
Time->Year > 2099 ||\r
Time->Month < 1 ||\r
Time->Month > 12 ||\r
- (!DayValid (Time)) ||\r
Time->Hour > 23 ||\r
Time->Minute > 59 ||\r
Time->Second > 59 ||\r
Time->Nanosecond > 999999999 ||\r
(!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
- (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r
+ ((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0)\r
) {\r
- return EFI_INVALID_PARAMETER;\r
+ if (!DayValid (Time)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
}\r
\r
return EFI_SUCCESS;\r
DayOfMonth[10] = 30;\r
DayOfMonth[11] = 31;\r
\r
+ //\r
+ // The validity of Time->Month field should be checked before\r
+ //\r
+ ASSERT (Time->Month >=1);\r
+ ASSERT (Time->Month <=12);\r
if (Time->Day < 1 ||\r
Time->Day > DayOfMonth[Time->Month - 1] ||\r
(Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
}\r
\r
/**\r
- Check if it is a leapyear.\r
+ Check if it is a leap year.\r
\r
@param Time The time to be checked.\r
\r
- @retval TRUE It is a leapyear.\r
- @retval FALSE It is NOT a leapyear.\r
+ @retval TRUE It is a leap year.\r
+ @retval FALSE It is NOT a leap year.\r
**/\r
BOOLEAN\r
IsLeapYear (\r
\r
Adjacent = FALSE;\r
\r
+ //\r
+ // The validity of From->Month field should be checked before\r
+ //\r
+ ASSERT (From->Month >=1);\r
+ ASSERT (From->Month <=12);\r
+ \r
if (From->Year == To->Year) {\r
if (From->Month == To->Month) {\r
if ((From->Day + 1) == To->Day) {\r