X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=PcAtChipsetPkg%2FPcatRealTimeClockRuntimeDxe%2FPcRtc.c;h=52af17941786ef81c3911512ee64551724e67209;hp=ebc2f3aa8bdf20af382da350abad85cdb2d915af;hb=HEAD;hpb=237295f46d83bf9e384103aaa77d9cf19dcc50b2 diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c index ebc2f3aa8b..9242a2e826 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c @@ -17,12 +17,12 @@ extern UINTN mRtcTargetRegister; // // Days of month. // -UINTN mDayOfMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; +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"; +CHAR16 mTimeZoneVariableName[] = L"RTC"; /** Compare the Hour, Minute and Second of the From time and the To time. @@ -38,8 +38,8 @@ CHAR16 mTimeZoneVariableName[] = L"RTC"; **/ INTN CompareHMS ( - IN EFI_TIME *From, - IN EFI_TIME *To + IN EFI_TIME *From, + IN EFI_TIME *To ); /** @@ -53,8 +53,8 @@ CompareHMS ( **/ BOOLEAN IsWithinOneDay ( - IN EFI_TIME *From, - IN EFI_TIME *To + IN EFI_TIME *From, + IN EFI_TIME *To ); /** @@ -68,7 +68,7 @@ IsWithinOneDay ( STATIC UINT8 IoRtcRead ( - IN UINTN Address + IN UINTN Address ) { IoWrite8 ( @@ -89,8 +89,8 @@ IoRtcRead ( STATIC VOID IoRtcWrite ( - IN UINTN Address, - IN UINT8 Data + IN UINTN Address, + IN UINT8 Data ) { IoWrite8 ( @@ -111,7 +111,7 @@ IoRtcWrite ( STATIC UINT8 MmioRtcRead ( - IN UINTN Address + IN UINTN Address ) { MmioWrite8 ( @@ -132,8 +132,8 @@ MmioRtcRead ( STATIC VOID MmioRtcWrite ( - IN UINTN Address, - IN UINT8 Data + IN UINTN Address, + IN UINT8 Data ) { MmioWrite8 ( @@ -154,7 +154,7 @@ MmioRtcWrite ( STATIC UINT8 RtcRead ( - IN UINTN Address + IN UINTN Address ) { if (FeaturePcdGet (PcdRtcUseMmio)) { @@ -175,8 +175,8 @@ RtcRead ( STATIC VOID RtcWrite ( - IN UINTN Address, - IN UINT8 Data + IN UINTN Address, + IN UINT8 Data ) { if (FeaturePcdGet (PcdRtcUseMmio)) { @@ -216,6 +216,7 @@ PcRtcInit ( if (!EfiAtRuntime ()) { EfiAcquireLock (&Global->RtcLock); } + // // Initialize RTC Register // @@ -254,8 +255,10 @@ PcRtcInit ( if (!EfiAtRuntime ()) { EfiReleaseLock (&Global->RtcLock); } + return EFI_DEVICE_ERROR; } + // // Get the Time/Date/Daylight Savings values. // @@ -266,13 +269,6 @@ PcRtcInit ( Time.Month = RtcRead (RTC_ADDRESS_MONTH); Time.Year = RtcRead (RTC_ADDRESS_YEAR); - // - // Set RTC configuration after get original time - // The value of bit AIE should be reserved. - // - RegisterB.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (RegisterB.Data & BIT5); - RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); - // // Release RTC Lock. // @@ -285,16 +281,16 @@ PcRtcInit ( // stored in NV variable during previous boot. // DataSize = sizeof (UINT32); - Status = EfiGetVariable ( - mTimeZoneVariableName, - &gEfiCallerIdGuid, - NULL, - &DataSize, - &TimerVar - ); + Status = EfiGetVariable ( + mTimeZoneVariableName, + &gEfiCallerIdGuid, + NULL, + &DataSize, + &TimerVar + ); if (!EFI_ERROR (Status)) { - Time.TimeZone = (INT16) TimerVar; - Time.Daylight = (UINT8) (TimerVar >> 16); + Time.TimeZone = (INT16)TimerVar; + Time.Daylight = (UINT8)(TimerVar >> 16); } else { Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE; Time.Daylight = 0; @@ -307,6 +303,7 @@ PcRtcInit ( if (!EFI_ERROR (Status)) { Status = RtcTimeFieldsValid (&Time); } + if (EFI_ERROR (Status)) { // // Report Status Code to indicate that the RTC has bad date and time @@ -315,17 +312,24 @@ PcRtcInit ( EFI_ERROR_CODE | EFI_ERROR_MINOR, (EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_BAD_DATE_TIME) ); - Time.Second = RTC_INIT_SECOND; - Time.Minute = RTC_INIT_MINUTE; - Time.Hour = RTC_INIT_HOUR; - Time.Day = RTC_INIT_DAY; - Time.Month = RTC_INIT_MONTH; - Time.Year = PcdGet16 (PcdMinimalValidYear); - Time.Nanosecond = 0; - Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE; - Time.Daylight = 0; + Time.Second = RTC_INIT_SECOND; + Time.Minute = RTC_INIT_MINUTE; + Time.Hour = RTC_INIT_HOUR; + Time.Day = RTC_INIT_DAY; + Time.Month = RTC_INIT_MONTH; + Time.Year = PcdGet16 (PcdMinimalValidYear); + Time.Nanosecond = 0; + Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE; + Time.Daylight = 0; } + // + // Set RTC configuration after get original time + // The value of bit AIE should be reserved. + // + RegisterB.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (RegisterB.Data & BIT5); + RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); + // // Reset time value according to new RTC configuration // @@ -348,15 +352,15 @@ PcRtcInit ( // When wakeup time is disabled and invalid, reset wakeup time register to valid state // but keep wakeup alarm disabled. // - Time.Second = RTC_INIT_SECOND; - Time.Minute = RTC_INIT_MINUTE; - Time.Hour = RTC_INIT_HOUR; - Time.Day = RTC_INIT_DAY; - Time.Month = RTC_INIT_MONTH; - Time.Year = PcdGet16 (PcdMinimalValidYear); - Time.Nanosecond = 0; - Time.TimeZone = Global->SavedTimeZone; - Time.Daylight = Global->Daylight;; + Time.Second = RTC_INIT_SECOND; + Time.Minute = RTC_INIT_MINUTE; + Time.Hour = RTC_INIT_HOUR; + Time.Day = RTC_INIT_DAY; + Time.Month = RTC_INIT_MONTH; + Time.Year = PcdGet16 (PcdMinimalValidYear); + Time.Nanosecond = 0; + Time.TimeZone = Global->SavedTimeZone; + Time.Daylight = Global->Daylight; // // Acquire RTC Lock to make access to RTC atomic @@ -364,14 +368,16 @@ PcRtcInit ( if (!EfiAtRuntime ()) { EfiAcquireLock (&Global->RtcLock); } + // // Wait for up to 0.1 seconds for the RTC to be updated // Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); if (EFI_ERROR (Status)) { if (!EfiAtRuntime ()) { - EfiReleaseLock (&Global->RtcLock); + EfiReleaseLock (&Global->RtcLock); } + return EFI_DEVICE_ERROR; } @@ -391,13 +397,14 @@ PcRtcInit ( if (!EfiAtRuntime ()) { EfiReleaseLock (&Global->RtcLock); } + return EFI_DEVICE_ERROR; } // // Inhibit updates of the RTC // - RegisterB.Bits.Set = 1; + RegisterB.Bits.Set = 1; RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); // @@ -419,6 +426,7 @@ PcRtcInit ( if (!EfiAtRuntime ()) { EfiReleaseLock (&Global->RtcLock); } + return EFI_SUCCESS; } @@ -451,24 +459,27 @@ PcRtcGetTime ( // if (Time == NULL) { return EFI_INVALID_PARAMETER; - } + // // Acquire RTC Lock to make access to RTC atomic // if (!EfiAtRuntime ()) { EfiAcquireLock (&Global->RtcLock); } + // // Wait for up to 0.1 seconds for the RTC to be updated // Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); if (EFI_ERROR (Status)) { - if (!EfiAtRuntime ()) { - EfiReleaseLock (&Global->RtcLock); - } + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + return Status; } + // // Read Register B // @@ -477,12 +488,12 @@ PcRtcGetTime ( // // Get the Time/Date/Daylight Savings values. // - Time->Second = RtcRead (RTC_ADDRESS_SECONDS); - Time->Minute = RtcRead (RTC_ADDRESS_MINUTES); - Time->Hour = RtcRead (RTC_ADDRESS_HOURS); - Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); - Time->Month = RtcRead (RTC_ADDRESS_MONTH); - Time->Year = RtcRead (RTC_ADDRESS_YEAR); + Time->Second = RtcRead (RTC_ADDRESS_SECONDS); + Time->Minute = RtcRead (RTC_ADDRESS_MINUTES); + Time->Hour = RtcRead (RTC_ADDRESS_HOURS); + Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); + Time->Month = RtcRead (RTC_ADDRESS_MONTH); + Time->Year = RtcRead (RTC_ADDRESS_YEAR); // // Release RTC Lock. @@ -494,8 +505,8 @@ PcRtcGetTime ( // // Get the variable that contains the TimeZone and Daylight fields // - Time->TimeZone = Global->SavedTimeZone; - Time->Daylight = Global->Daylight; + Time->TimeZone = Global->SavedTimeZone; + Time->Daylight = Global->Daylight; // // Make sure all field values are in correct range @@ -504,6 +515,7 @@ PcRtcGetTime ( if (!EFI_ERROR (Status)) { Status = RtcTimeFieldsValid (Time); } + if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } @@ -539,8 +551,8 @@ PcRtcGetTime ( **/ EFI_STATUS PcRtcSetTime ( - IN EFI_TIME *Time, - IN PC_RTC_MODULE_GLOBALS *Global + IN EFI_TIME *Time, + IN PC_RTC_MODULE_GLOBALS *Global ) { EFI_STATUS Status; @@ -551,6 +563,7 @@ PcRtcSetTime ( if (Time == NULL) { return EFI_INVALID_PARAMETER; } + // // Make sure that the time fields are valid // @@ -567,14 +580,16 @@ PcRtcSetTime ( if (!EfiAtRuntime ()) { EfiAcquireLock (&Global->RtcLock); } + // // Wait for up to 0.1 seconds for the RTC to be updated // Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); if (EFI_ERROR (Status)) { - if (!EfiAtRuntime ()) { - EfiReleaseLock (&Global->RtcLock); - } + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + return Status; } @@ -594,35 +609,36 @@ PcRtcSetTime ( } } 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 - ); + 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); } + return EFI_DEVICE_ERROR; } // // Read Register B, and inhibit updates of the RTC // - RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); - RegisterB.Bits.Set = 1; + RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); + RegisterB.Bits.Set = 1; RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); // // Store the century value to RTC before converting to BCD format. // if (Global->CenturyRtcAddress != 0) { - RtcWrite (Global->CenturyRtcAddress, DecimalToBcd8 ((UINT8) (RtcTime.Year / 100))); + RtcWrite (Global->CenturyRtcAddress, DecimalToBcd8 ((UINT8)(RtcTime.Year / 100))); } ConvertEfiTimeToRtcTime (&RtcTime, RegisterB); @@ -632,7 +648,7 @@ PcRtcSetTime ( RtcWrite (RTC_ADDRESS_HOURS, RtcTime.Hour); RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH, RtcTime.Day); RtcWrite (RTC_ADDRESS_MONTH, RtcTime.Month); - RtcWrite (RTC_ADDRESS_YEAR, (UINT8) RtcTime.Year); + RtcWrite (RTC_ADDRESS_YEAR, (UINT8)RtcTime.Year); // // Allow updates of the RTC registers @@ -646,6 +662,7 @@ PcRtcSetTime ( if (!EfiAtRuntime ()) { EfiReleaseLock (&Global->RtcLock); } + // // Set the variable that contains the TimeZone and Daylight fields // @@ -690,29 +707,32 @@ PcRtcGetWakeupTime ( // if ((Enabled == NULL) || (Pending == NULL) || (Time == NULL)) { return EFI_INVALID_PARAMETER; - } + // // Acquire RTC Lock to make access to RTC atomic // if (!EfiAtRuntime ()) { EfiAcquireLock (&Global->RtcLock); } + // // Wait for up to 0.1 seconds for the RTC to be updated // Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); if (EFI_ERROR (Status)) { if (!EfiAtRuntime ()) { - EfiReleaseLock (&Global->RtcLock); + EfiReleaseLock (&Global->RtcLock); } + return EFI_DEVICE_ERROR; } + // // Read Register B and Register C // - RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); - RegisterC.Data = RtcRead (RTC_ADDRESS_REGISTER_C); + RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); + RegisterC.Data = RtcRead (RTC_ADDRESS_REGISTER_C); // // Get the Time/Date/Daylight Savings values. @@ -720,12 +740,12 @@ PcRtcGetWakeupTime ( *Enabled = RegisterB.Bits.Aie; *Pending = RegisterC.Bits.Af; - Time->Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM); - Time->Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM); - Time->Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM); - Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); - Time->Month = RtcRead (RTC_ADDRESS_MONTH); - Time->Year = RtcRead (RTC_ADDRESS_YEAR); + Time->Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM); + Time->Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM); + Time->Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM); + Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); + Time->Month = RtcRead (RTC_ADDRESS_MONTH); + Time->Year = RtcRead (RTC_ADDRESS_YEAR); Time->TimeZone = Global->SavedTimeZone; Time->Daylight = Global->Daylight; @@ -733,13 +753,13 @@ PcRtcGetWakeupTime ( // Get the alarm info from variable // DataSize = sizeof (EFI_TIME); - Status = EfiGetVariable ( - L"RTCALARM", - &gEfiCallerIdGuid, - NULL, - &DataSize, - &RtcTime - ); + Status = EfiGetVariable ( + L"RTCALARM", + &gEfiCallerIdGuid, + NULL, + &DataSize, + &RtcTime + ); if (!EFI_ERROR (Status)) { // // The alarm variable exists. In this case, we read variable to get info. @@ -763,6 +783,7 @@ PcRtcGetWakeupTime ( if (!EFI_ERROR (Status)) { Status = RtcTimeFieldsValid (Time); } + if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } @@ -792,18 +813,18 @@ PcRtcSetWakeupTime ( IN PC_RTC_MODULE_GLOBALS *Global ) { - EFI_STATUS Status; - EFI_TIME RtcTime; - RTC_REGISTER_B RegisterB; - EFI_TIME_CAPABILITIES Capabilities; + EFI_STATUS Status; + EFI_TIME RtcTime; + RTC_REGISTER_B RegisterB; + EFI_TIME_CAPABILITIES Capabilities; ZeroMem (&RtcTime, sizeof (RtcTime)); if (Enable) { - if (Time == NULL) { return EFI_INVALID_PARAMETER; } + // // Make sure that the time fields are valid // @@ -811,6 +832,7 @@ PcRtcSetWakeupTime ( if (EFI_ERROR (Status)) { return EFI_INVALID_PARAMETER; } + // // Just support set alarm time within 24 hours // @@ -819,31 +841,36 @@ PcRtcSetWakeupTime ( if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } + if (!IsWithinOneDay (&RtcTime, Time)) { return EFI_UNSUPPORTED; } + // // Make a local copy of the time and date // CopyMem (&RtcTime, Time, sizeof (EFI_TIME)); - } + // // Acquire RTC Lock to make access to RTC atomic // if (!EfiAtRuntime ()) { EfiAcquireLock (&Global->RtcLock); } + // // Wait for up to 0.1 seconds for the RTC to be updated // Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); if (EFI_ERROR (Status)) { if (!EfiAtRuntime ()) { - EfiReleaseLock (&Global->RtcLock); + EfiReleaseLock (&Global->RtcLock); } + return EFI_DEVICE_ERROR; } + // // Read Register B // @@ -855,12 +882,12 @@ PcRtcSetWakeupTime ( // // if the alarm is disable, record the current setting. // - RtcTime.Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM); - RtcTime.Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM); - RtcTime.Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM); - RtcTime.Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); - RtcTime.Month = RtcRead (RTC_ADDRESS_MONTH); - RtcTime.Year = RtcRead (RTC_ADDRESS_YEAR); + RtcTime.Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM); + RtcTime.Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM); + RtcTime.Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM); + RtcTime.Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); + RtcTime.Month = RtcRead (RTC_ADDRESS_MONTH); + RtcTime.Year = RtcRead (RTC_ADDRESS_YEAR); RtcTime.TimeZone = Global->SavedTimeZone; RtcTime.Daylight = Global->Daylight; } @@ -879,13 +906,14 @@ PcRtcSetWakeupTime ( if (!EfiAtRuntime ()) { EfiReleaseLock (&Global->RtcLock); } + return EFI_DEVICE_ERROR; } // // Inhibit updates of the RTC // - RegisterB.Bits.Set = 1; + RegisterB.Bits.Set = 1; RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); if (Enable) { @@ -897,10 +925,10 @@ PcRtcSetWakeupTime ( RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour); RegisterB.Bits.Aie = 1; - } else { RegisterB.Bits.Aie = 0; } + // // Allow updates of the RTC registers // @@ -913,10 +941,10 @@ PcRtcSetWakeupTime ( if (!EfiAtRuntime ()) { EfiReleaseLock (&Global->RtcLock); } + return EFI_SUCCESS; } - /** Checks an 8-bit BCD value, and converts to an 8-bit value if valid. @@ -964,28 +992,32 @@ ConvertRtcTimeToEfiTime ( IN RTC_REGISTER_B RegisterB ) { - BOOLEAN IsPM; - UINT8 Century; + BOOLEAN IsPM; + UINT8 Century; - if ((Time->Hour & 0x80) != 0) { - IsPM = TRUE; - } else { - IsPM = FALSE; - } + // IsPM only makes sense for 12-hour format. + if (RegisterB.Bits.Mil == 0) { + if ((Time->Hour & 0x80) != 0) { + IsPM = TRUE; + } else { + IsPM = FALSE; + } - Time->Hour = (UINT8) (Time->Hour & 0x7f); + Time->Hour = (UINT8)(Time->Hour & 0x7f); + } if (RegisterB.Bits.Dm == 0) { - Time->Year = CheckAndConvertBcd8ToDecimal8 ((UINT8) Time->Year); - Time->Month = CheckAndConvertBcd8ToDecimal8 (Time->Month); - Time->Day = CheckAndConvertBcd8ToDecimal8 (Time->Day); - Time->Hour = CheckAndConvertBcd8ToDecimal8 (Time->Hour); - Time->Minute = CheckAndConvertBcd8ToDecimal8 (Time->Minute); - Time->Second = CheckAndConvertBcd8ToDecimal8 (Time->Second); + Time->Year = CheckAndConvertBcd8ToDecimal8 ((UINT8)Time->Year); + Time->Month = CheckAndConvertBcd8ToDecimal8 (Time->Month); + Time->Day = CheckAndConvertBcd8ToDecimal8 (Time->Day); + Time->Hour = CheckAndConvertBcd8ToDecimal8 (Time->Hour); + Time->Minute = CheckAndConvertBcd8ToDecimal8 (Time->Minute); + Time->Second = CheckAndConvertBcd8ToDecimal8 (Time->Second); } - if (Time->Year == 0xff || Time->Month == 0xff || Time->Day == 0xff || - Time->Hour == 0xff || Time->Minute == 0xff || Time->Second == 0xff) { + if ((Time->Year == 0xff) || (Time->Month == 0xff) || (Time->Day == 0xff) || + (Time->Hour == 0xff) || (Time->Minute == 0xff) || (Time->Second == 0xff)) + { return EFI_INVALID_PARAMETER; } @@ -994,26 +1026,27 @@ ConvertRtcTimeToEfiTime ( // Century is 19 if RTC year >= 70, // Century is 20 otherwise. // - Century = (UINT8) (PcdGet16 (PcdMinimalValidYear) / 100); + Century = (UINT8)(PcdGet16 (PcdMinimalValidYear) / 100); if (Time->Year < PcdGet16 (PcdMinimalValidYear) % 100) { Century++; } - Time->Year = (UINT16) (Century * 100 + Time->Year); + + Time->Year = (UINT16)(Century * 100 + Time->Year); // // If time is in 12 hour format, convert it to 24 hour format // if (RegisterB.Bits.Mil == 0) { - if (IsPM && Time->Hour < 12) { - Time->Hour = (UINT8) (Time->Hour + 12); + if (IsPM && (Time->Hour < 12)) { + Time->Hour = (UINT8)(Time->Hour + 12); } - if (!IsPM && Time->Hour == 12) { + if (!IsPM && (Time->Hour == 12)) { Time->Hour = 0; } } - Time->Nanosecond = 0; + Time->Nanosecond = 0; return EFI_SUCCESS; } @@ -1028,7 +1061,7 @@ ConvertRtcTimeToEfiTime ( **/ EFI_STATUS RtcWaitToUpdate ( - UINTN Timeout + UINTN Timeout ) { RTC_REGISTER_A RegisterA; @@ -1042,11 +1075,12 @@ RtcWaitToUpdate ( if (RegisterD.Bits.Vrt == 0) { return EFI_DEVICE_ERROR; } + // // Wait for up to 0.1 seconds for the RTC to be ready. // - Timeout = (Timeout / 10) + 1; - RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A); + Timeout = (Timeout / 10) + 1; + RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A); while (RegisterA.Bits.Uip == 1 && Timeout > 0) { MicroSecondDelay (10); RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A); @@ -1054,7 +1088,7 @@ RtcWaitToUpdate ( } RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D); - if (Timeout == 0 || RegisterD.Bits.Vrt == 0) { + if ((Timeout == 0) || (RegisterD.Bits.Vrt == 0)) { return EFI_DEVICE_ERROR; } @@ -1072,20 +1106,21 @@ RtcWaitToUpdate ( **/ EFI_STATUS RtcTimeFieldsValid ( - IN EFI_TIME *Time + IN EFI_TIME *Time ) { - if (Time->Year < PcdGet16 (PcdMinimalValidYear) || - Time->Year > PcdGet16 (PcdMaximalValidYear) || - Time->Month < 1 || - Time->Month > 12 || + if ((Time->Year < PcdGet16 (PcdMinimalValidYear)) || + (Time->Year > PcdGet16 (PcdMaximalValidYear)) || + (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)) { + (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)) + { return EFI_INVALID_PARAMETER; } @@ -1108,12 +1143,13 @@ DayValid ( // // The validity of Time->Month field should be checked before // - ASSERT (Time->Month >=1); - ASSERT (Time->Month <=12); - if (Time->Day < 1 || - Time->Day > mDayOfMonth[Time->Month - 1] || - (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28)) - ) { + ASSERT (Time->Month >= 1); + ASSERT (Time->Month <= 12); + if ((Time->Day < 1) || + (Time->Day > mDayOfMonth[Time->Month - 1]) || + ((Time->Month == 2) && (!IsLeapYear (Time) && (Time->Day > 28))) + ) + { return FALSE; } @@ -1130,7 +1166,7 @@ DayValid ( **/ BOOLEAN IsLeapYear ( - IN EFI_TIME *Time + IN EFI_TIME *Time ) { if (Time->Year % 4 == 0) { @@ -1165,7 +1201,7 @@ ConvertEfiTimeToRtcTime ( IN RTC_REGISTER_B RegisterB ) { - BOOLEAN IsPM; + BOOLEAN IsPM; IsPM = TRUE; // @@ -1177,29 +1213,31 @@ ConvertEfiTimeToRtcTime ( } if (Time->Hour >= 13) { - Time->Hour = (UINT8) (Time->Hour - 12); + Time->Hour = (UINT8)(Time->Hour - 12); } else if (Time->Hour == 0) { Time->Hour = 12; } } + // // Set the Time/Date values. // - Time->Year = (UINT16) (Time->Year % 100); + Time->Year = (UINT16)(Time->Year % 100); if (RegisterB.Bits.Dm == 0) { - Time->Year = DecimalToBcd8 ((UINT8) Time->Year); - Time->Month = DecimalToBcd8 (Time->Month); - Time->Day = DecimalToBcd8 (Time->Day); - Time->Hour = DecimalToBcd8 (Time->Hour); - Time->Minute = DecimalToBcd8 (Time->Minute); - Time->Second = DecimalToBcd8 (Time->Second); + Time->Year = DecimalToBcd8 ((UINT8)Time->Year); + Time->Month = DecimalToBcd8 (Time->Month); + Time->Day = DecimalToBcd8 (Time->Day); + Time->Hour = DecimalToBcd8 (Time->Hour); + Time->Minute = DecimalToBcd8 (Time->Minute); + Time->Second = DecimalToBcd8 (Time->Second); } + // // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field. // - if (RegisterB.Bits.Mil == 0 && IsPM) { - Time->Hour = (UINT8) (Time->Hour | 0x80); + if ((RegisterB.Bits.Mil == 0) && IsPM) { + Time->Hour = (UINT8)(Time->Hour | 0x80); } } @@ -1217,13 +1255,14 @@ ConvertEfiTimeToRtcTime ( **/ INTN CompareHMS ( - IN EFI_TIME *From, - IN EFI_TIME *To + IN EFI_TIME *From, + IN EFI_TIME *To ) { if ((From->Hour > To->Hour) || - ((From->Hour == To->Hour) && (From->Minute > To->Minute)) || - ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second > To->Second))) { + ((From->Hour == To->Hour) && (From->Minute > To->Minute)) || + ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second > To->Second))) + { return 1; } else if ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second == To->Second)) { return 0; @@ -1247,37 +1286,37 @@ IsWithinOneDay ( IN EFI_TIME *To ) { - BOOLEAN Adjacent; + BOOLEAN Adjacent; Adjacent = FALSE; // // The validity of From->Month field should be checked before // - ASSERT (From->Month >=1); - ASSERT (From->Month <=12); + ASSERT (From->Month >= 1); + ASSERT (From->Month <= 12); if (From->Year == To->Year) { if (From->Month == To->Month) { if ((From->Day + 1) == To->Day) { - if ((CompareHMS(From, To) >= 0)) { + if ((CompareHMS (From, To) >= 0)) { Adjacent = TRUE; } } else if (From->Day == To->Day) { - if ((CompareHMS(From, To) <= 0)) { + if ((CompareHMS (From, To) <= 0)) { Adjacent = TRUE; } } } else if (((From->Month + 1) == To->Month) && (To->Day == 1)) { - if ((From->Month == 2) && !IsLeapYear(From)) { + if ((From->Month == 2) && !IsLeapYear (From)) { if (From->Day == 28) { - if ((CompareHMS(From, To) >= 0)) { + if ((CompareHMS (From, To) >= 0)) { Adjacent = TRUE; } } } else if (From->Day == mDayOfMonth[From->Month - 1]) { - if ((CompareHMS(From, To) >= 0)) { - Adjacent = TRUE; + if ((CompareHMS (From, To) >= 0)) { + Adjacent = TRUE; } } } @@ -1285,8 +1324,9 @@ IsWithinOneDay ( (From->Month == 12) && (From->Day == 31) && (To->Month == 1) && - (To->Day == 1)) { - if ((CompareHMS(From, To) >= 0)) { + (To->Day == 1)) + { + if ((CompareHMS (From, To) >= 0)) { Adjacent = TRUE; } } @@ -1304,15 +1344,16 @@ GetCenturyRtcAddress ( VOID ) { - EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt; + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt; - Fadt = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) EfiLocateFirstAcpiTable ( - EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE - ); + Fadt = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *)EfiLocateFirstAcpiTable ( + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE + ); if ((Fadt != NULL) && (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80) - ) { + ) + { return Fadt->Century; } else { return 0; @@ -1332,21 +1373,21 @@ GetCenturyRtcAddress ( VOID EFIAPI PcRtcAcpiTableChangeCallback ( - IN EFI_EVENT Event, - IN VOID *Context + IN EFI_EVENT Event, + IN VOID *Context ) { - EFI_STATUS Status; - EFI_TIME Time; - UINT8 CenturyRtcAddress; - UINT8 Century; + EFI_STATUS Status; + EFI_TIME Time; + UINT8 CenturyRtcAddress; + UINT8 Century; CenturyRtcAddress = GetCenturyRtcAddress (); if ((CenturyRtcAddress != 0) && (mModuleGlobal.CenturyRtcAddress != CenturyRtcAddress)) { mModuleGlobal.CenturyRtcAddress = CenturyRtcAddress; - Status = PcRtcGetTime (&Time, NULL, &mModuleGlobal); + Status = PcRtcGetTime (&Time, NULL, &mModuleGlobal); if (!EFI_ERROR (Status)) { - Century = (UINT8) (Time.Year / 100); + Century = (UINT8)(Time.Year / 100); Century = DecimalToBcd8 (Century); DEBUG ((DEBUG_INFO, "PcRtc: Write 0x%x to CMOS location 0x%x\n", Century, mModuleGlobal.CenturyRtcAddress)); RtcWrite (mModuleGlobal.CenturyRtcAddress, Century);