summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>2009-07-15 06:17:57 +0000
committerrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>2009-07-15 06:17:57 +0000
commit6bfa178ccaa1ec0fa2bfddf0a5ebbb931744e7a4 (patch)
treec2bc61981c6efeab3b6eb592a75cc69954fc37d6
parenta025815c58cd58a6119f87345fa28a0fbbf14c1c (diff)
downloadedk2-platforms-6bfa178ccaa1ec0fa2bfddf0a5ebbb931744e7a4.tar.xz
Fixed 2 bugs in the RTC driver of PcAtChipsetPkg.
1. RtcTimeFieldsValid() has bug checking the validity of TIME fields, which causes SetTime() will not return EFI_INVALID_PARAMETER when it is fed with invliad time fields. 2. Logical error in handling Time Zone and Day Light Saving.GetTime() won't return Time Zone and Day Light Saving set by last SetTime() call. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8948 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c72
1 files changed, 32 insertions, 40 deletions
diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
index d26e923605..a2a20c8e1c 100644
--- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
+++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
@@ -108,7 +108,6 @@ PcRtcInit (
//
// Acquire RTC Lock to make access to RTC atomic
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock);
}
@@ -142,7 +141,6 @@ PcRtcInit (
//
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
@@ -169,12 +167,31 @@ PcRtcInit (
//
// Release RTC Lock.
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
//
+ // Get the data of Daylight saving and time zone, if they have been
+ // stored in NV variable during previous boot.
+ //
+ DataSize = sizeof (UINT32);
+ Status = EfiGetVariable (
+ L"RTC",
+ &gEfiCallerIdGuid,
+ NULL,
+ &DataSize,
+ (VOID *) &TimerVar
+ );
+ if (!EFI_ERROR (Status)) {
+ Time.TimeZone = (INT16) TimerVar;
+ Time.Daylight = (UINT8) (TimerVar >> 16);
+ } else {
+ Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE;
+ Time.Daylight = 0;
+ }
+
+ //
// Validate time fields
//
Status = ConvertRtcTimeToEfiTime (&Time, Century, RegisterB);
@@ -189,25 +206,7 @@ PcRtcInit (
Time.Month = RTC_INIT_MONTH;
Time.Year = RTC_INIT_YEAR;
}
- //
- // Get the data of Daylight saving and time zone, if they have been
- // stored in NV variable during previous boot.
- //
- DataSize = sizeof (UINT32);
- Status = EfiGetVariable (
- L"RTC",
- &gEfiCallerIdGuid,
- NULL,
- &DataSize,
- (VOID *) &TimerVar
- );
- if (!EFI_ERROR (Status)) {
- Global->SavedTimeZone = (INT16) TimerVar;
- Global->Daylight = (UINT8) (TimerVar >> 16);
- Time.TimeZone = Global->SavedTimeZone;
- Time.Daylight = Global->Daylight;
- }
//
// Reset time value according to new RTC configuration
//
@@ -251,7 +250,6 @@ PcRtcGetTime (
//
// Acquire RTC Lock to make access to RTC atomic
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock);
}
@@ -260,7 +258,6 @@ PcRtcGetTime (
//
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
@@ -286,10 +283,10 @@ PcRtcGetTime (
//
// Release RTC Lock.
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
+
//
// Get the variable that contains the TimeZone and Daylight fields
//
@@ -306,6 +303,7 @@ PcRtcGetTime (
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
+
//
// Fill in Capabilities if it was passed in
//
@@ -363,7 +361,6 @@ PcRtcSetTime (
//
// Acquire RTC Lock to make access to RTC atomic
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock);
}
@@ -372,7 +369,6 @@ PcRtcSetTime (
//
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
@@ -404,7 +400,6 @@ PcRtcSetTime (
//
// Release RTC Lock.
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
@@ -467,7 +462,6 @@ PcRtcGetWakeupTime (
//
// Acquire RTC Lock to make access to RTC atomic
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock);
}
@@ -476,7 +470,6 @@ PcRtcGetWakeupTime (
//
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
@@ -513,10 +506,16 @@ PcRtcGetWakeupTime (
//
// Release RTC Lock.
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
+
+ //
+ // Get the variable that contains the TimeZone and Daylight fields
+ //
+ Time->TimeZone = Global->SavedTimeZone;
+ Time->Daylight = Global->Daylight;
+
//
// Make sure all field values are in correct range
//
@@ -593,7 +592,6 @@ PcRtcSetWakeupTime (
//
// Acquire RTC Lock to make access to RTC atomic
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock);
}
@@ -602,7 +600,6 @@ PcRtcSetWakeupTime (
//
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) {
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
@@ -640,7 +637,6 @@ PcRtcSetWakeupTime (
//
// Release RTC Lock.
//
- //Code here doesn't consider the runtime environment.
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
}
@@ -739,8 +735,6 @@ ConvertRtcTimeToEfiTime (
}
Time->Nanosecond = 0;
- Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;
- Time->Daylight = 0;
return EFI_SUCCESS;
}
@@ -806,16 +800,14 @@ RtcTimeFieldsValid (
Time->Year > 2099 ||
Time->Month < 1 ||
Time->Month > 12 ||
+ (!DayValid (Time)) ||
Time->Hour > 23 ||
Time->Minute > 59 ||
Time->Second > 59 ||
Time->Nanosecond > 999999999 ||
(!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||
- ((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0)
- ) {
- if (!DayValid (Time)) {
- return EFI_INVALID_PARAMETER;
- }
+ ((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0)) {
+ return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;