X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=PcAtChipsetPkg%2FPcatRealTimeClockRuntimeDxe%2FPcRtc.c;h=2105acf35f7b78f75172a18ea14f49e0e1fbd461;hp=e122ae16990a51324e13935441de6b9a5d5efb32;hb=76c09700edc67686b29662e81a3ca7d947594ce5;hpb=41628cbc7cb267f35db4ba2efca833aa39198cba diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c index e122ae1699..2105acf35f 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c @@ -1,7 +1,9 @@ /** @file RTC Architectural Protocol GUID as defined in DxeCis 0.96. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2017, AMD Inc. All rights reserved.
+ 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,9 +16,19 @@ 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. - + Only compare H/M/S in EFI_TIME and ignore other fields here. @param From the first time @@ -60,8 +72,8 @@ RtcRead ( IN UINT8 Address ) { - IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80))); - return IoRead8 (PCAT_RTC_DATA_REGISTER); + IoWrite8 (PcdGet8 (PcdRtcIndexRegister), (UINT8) (Address | (UINT8) (IoRead8 (PcdGet8 (PcdRtcIndexRegister)) & 0x80))); + return IoRead8 (PcdGet8 (PcdRtcTargetRegister)); } /** @@ -78,8 +90,8 @@ RtcWrite ( IN UINT8 Data ) { - IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80))); - IoWrite8 (PCAT_RTC_DATA_REGISTER, Data); + IoWrite8 (PcdGet8 (PcdRtcIndexRegister), (UINT8) (Address | (UINT8) (IoRead8 (PcdGet8 (PcdRtcIndexRegister)) & 0x80))); + IoWrite8 (PcdGet8 (PcdRtcTargetRegister), Data); } /** @@ -118,7 +130,7 @@ PcRtcInit ( // Make sure Division Chain is properly configured, // or RTC clock won't "tick" -- time won't increment // - RegisterA.Data = RTC_INIT_REGISTER_A; + RegisterA.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterA); RtcWrite (RTC_ADDRESS_REGISTER_A, RegisterA.Data); // @@ -134,7 +146,7 @@ PcRtcInit ( // // Clear RTC register D // - RegisterD.Data = RTC_INIT_REGISTER_D; + RegisterD.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterD); RtcWrite (RTC_ADDRESS_REGISTER_D, RegisterD.Data); // @@ -166,7 +178,7 @@ PcRtcInit ( // Set RTC configuration after get original time // The value of bit AIE should be reserved. // - RegisterB.Data = RTC_INIT_REGISTER_B | (RegisterB.Data & BIT5); + RegisterB.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (RegisterB.Data & BIT5); RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); // @@ -175,25 +187,25 @@ PcRtcInit ( 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", + mTimeZoneVariableName, &gEfiCallerIdGuid, NULL, &DataSize, - (VOID *) &TimerVar + &TimerVar ); if (!EFI_ERROR (Status)) { Time.TimeZone = (INT16) TimerVar; Time.Daylight = (UINT8) (TimerVar >> 16); } else { Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE; - Time.Daylight = 0; + Time.Daylight = 0; } // @@ -229,7 +241,7 @@ PcRtcInit ( if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } - + // // Reset wakeup time value to valid state when wakeup alarm is disabled and wakeup time is invalid. // Global variable has already had valid SavedTimeZone and Daylight, @@ -239,9 +251,9 @@ PcRtcInit ( if ((Enabled) || (!EFI_ERROR (Status))) { return EFI_SUCCESS; } - + // - // When wakeup time is disabled and invalid, reset wakeup time register to valid state + // When wakeup time is disabled and invalid, reset wakeup time register to valid state // but keep wakeup alarm disabled. // Time.Second = RTC_INIT_SECOND; @@ -289,13 +301,13 @@ PcRtcInit ( } return EFI_DEVICE_ERROR; } - + // // Inhibit updates of the RTC // RegisterB.Bits.Set = 1; RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); - + // // Set RTC alarm time registers // @@ -308,7 +320,7 @@ PcRtcInit ( // RegisterB.Bits.Set = 0; RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); - + // // Release RTC Lock. // @@ -473,19 +485,33 @@ PcRtcSetTime ( } return Status; } - + // // 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) && (Time->Daylight == 0)) { + 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); @@ -763,7 +789,7 @@ PcRtcSetWakeupTime ( } return EFI_DEVICE_ERROR; } - + // // Inhibit updates of the RTC // @@ -906,7 +932,7 @@ ConvertRtcTimeToEfiTime ( @param Timeout Tell how long it should take to wait. @retval EFI_DEVICE_ERROR RTC device error. - @retval EFI_SUCCESS RTC is updated and ready. + @retval EFI_SUCCESS RTC is updated and ready. **/ EFI_STATUS RtcWaitToUpdate ( @@ -987,28 +1013,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; @@ -1102,7 +1113,7 @@ ConvertEfiTimeToRtcTime ( /** Compare the Hour, Minute and Second of the From time and the To time. - + Only compare H/M/S in EFI_TIME and ignore other fields here. @param From the first time @@ -1144,22 +1155,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; // @@ -1167,7 +1164,7 @@ IsWithinOneDay ( // ASSERT (From->Month >=1); ASSERT (From->Month <=12); - + if (From->Year == To->Year) { if (From->Month == To->Month) { if ((From->Day + 1) == To->Day) { @@ -1186,7 +1183,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; } @@ -1235,6 +1232,11 @@ ScanTableInSDT ( // Table = 0; CopyMem (&Table, (VOID *) (EntryBase + Index * TablePointerSize), TablePointerSize); + + if (Table == NULL) { + continue; + } + if (Table->Signature == Signature) { return Table; } @@ -1244,61 +1246,86 @@ ScanTableInSDT ( } /** - Notification function of ACPI Table change. - - This is a notification function registered on ACPI Table change event. - It saves the Century address stored in ACPI FADT table. - - @param Event Event whose notification function is being invoked. - @param Context Pointer to the notification function's context. + Get the century RTC address from the ACPI FADT table. + @return The century RTC address or 0 if not found. **/ -VOID -EFIAPI -PcRtcAcpiTableChangeCallback ( - IN EFI_EVENT Event, - IN VOID *Context +UINT8 +GetCenturyRtcAddress ( + VOID ) { EFI_STATUS Status; EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; - EFI_ACPI_DESCRIPTION_HEADER *Rsdt; - EFI_ACPI_DESCRIPTION_HEADER *Xsdt; EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt; - EFI_TIME Time; - UINT8 Century; Status = EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **) &Rsdp); if (EFI_ERROR (Status)) { Status = EfiGetSystemConfigurationTable (&gEfiAcpi10TableGuid, (VOID **) &Rsdp); } - if (EFI_ERROR (Status)) { - return; + if (EFI_ERROR (Status) || (Rsdp == NULL)) { + return 0; } + Fadt = NULL; + // // Find FADT in XSDT // - Fadt = NULL; - if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) { - Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->XsdtAddress; - Fadt = ScanTableInSDT (Xsdt, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, sizeof (UINT64)); + if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION && Rsdp->XsdtAddress != 0) { + Fadt = ScanTableInSDT ( + (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->XsdtAddress, + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, + sizeof (UINTN) + ); } - if (Fadt == NULL) { - // - // Find FADT in RSDT - // - Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress; - Fadt = ScanTableInSDT (Rsdt, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, sizeof (UINT32)); + // + // Find FADT in RSDT + // + if (Fadt == NULL && Rsdp->RsdtAddress != 0) { + Fadt = ScanTableInSDT ( + (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress, + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, + sizeof (UINT32) + ); } if ((Fadt != NULL) && - (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80) && - (mModuleGlobal.CenturyRtcAddress != Fadt->Century) + (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80) ) { - mModuleGlobal.CenturyRtcAddress = Fadt->Century; + return Fadt->Century; + } else { + return 0; + } +} + +/** + Notification function of ACPI Table change. + + This is a notification function registered on ACPI Table change event. + It saves the Century address stored in ACPI FADT table. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context. + +**/ +VOID +EFIAPI +PcRtcAcpiTableChangeCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + 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); if (!EFI_ERROR (Status)) { Century = (UINT8) (Time.Year / 100);