]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/PL031RealTimeClockLib: remove validation and DST handling
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Sun, 5 Nov 2017 16:31:23 +0000 (16:31 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 13 Nov 2017 13:33:39 +0000 (13:33 +0000)
This library, which is intended to encapsulate the hardware specifics
of the ARM PL031 RTC, also implements its own input validation routines
and record the timezone and DST settings in its own set of EFI variables.

This functionality has recently been added to the core driver, so let's
remove it here.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c

index 41ebcb95ab8514d5a1954add3fe1e64345c8dc5c..f1eb0deb324931f4f7b3c79905e49226d0d208ce 100644 (file)
@@ -40,8 +40,6 @@
 \r
 #include <ArmPlatform.h>\r
 \r
-STATIC CONST CHAR16           mTimeZoneVariableName[] = L"PL031RtcTimeZone";\r
-STATIC CONST CHAR16           mDaylightVariableName[] = L"PL031RtcDaylight";\r
 STATIC BOOLEAN                mPL031Initialized = FALSE;\r
 STATIC EFI_EVENT              mRtcVirtualAddrChangeEvent;\r
 STATIC UINTN                  mPL031RtcBase;\r
@@ -134,15 +132,12 @@ LibGetTime (
 {\r
   EFI_STATUS  Status = EFI_SUCCESS;\r
   UINT32      EpochSeconds;\r
-  INT16       TimeZone;\r
-  UINT8       Daylight;\r
-  UINTN       Size;\r
 \r
   // Initialize the hardware if not already done\r
   if (!mPL031Initialized) {\r
     Status = InitializePL031 ();\r
     if (EFI_ERROR (Status)) {\r
-      goto EXIT;\r
+      return Status;\r
     }\r
   }\r
 \r
@@ -156,7 +151,7 @@ LibGetTime (
     Status = EFI_SUCCESS;\r
   } else if (EFI_ERROR (Status)) {\r
     // Battery backed up hardware RTC exists but could not be read due to error. Abort.\r
-    goto EXIT;\r
+    return Status;\r
   } else {\r
     // Battery backed up hardware RTC exists and we read the time correctly from it.\r
     // Now sync the PL031 to the new time.\r
@@ -165,107 +160,18 @@ LibGetTime (
 \r
   // Ensure Time is a valid pointer\r
   if (Time == NULL) {\r
-    Status = EFI_INVALID_PARAMETER;\r
-    goto EXIT;\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  // Get the current time zone information from non-volatile storage\r
-  Size = sizeof (TimeZone);\r
-  Status = EfiGetVariable (\r
-                  (CHAR16 *)mTimeZoneVariableName,\r
-                  &gEfiCallerIdGuid,\r
-                  NULL,\r
-                  &Size,\r
-                  (VOID *)&TimeZone\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    ASSERT(Status != EFI_INVALID_PARAMETER);\r
-    ASSERT(Status != EFI_BUFFER_TOO_SMALL);\r
-\r
-    if (Status != EFI_NOT_FOUND)\r
-      goto EXIT;\r
-\r
-    // The time zone variable does not exist in non-volatile storage, so create it.\r
-    Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
-    // Store it\r
-    Status = EfiSetVariable (\r
-                    (CHAR16 *)mTimeZoneVariableName,\r
-                    &gEfiCallerIdGuid,\r
-                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                    Size,\r
-                    (VOID *)&(Time->TimeZone)\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      DEBUG ((\r
-        EFI_D_ERROR,\r
-        "LibGetTime: Failed to save %s variable to non-volatile storage, Status = %r\n",\r
-        mTimeZoneVariableName,\r
-        Status\r
-        ));\r
-      goto EXIT;\r
-    }\r
-  } else {\r
-    // Got the time zone\r
-    Time->TimeZone = TimeZone;\r
-\r
-    // Check TimeZone bounds:   -1440 to 1440 or 2047\r
-    if (((Time->TimeZone < -1440) || (Time->TimeZone > 1440))\r
-        && (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE)) {\r
-      Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
-    }\r
-\r
-    // Adjust for the correct time zone\r
-    if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r
-      EpochSeconds += Time->TimeZone * SEC_PER_MIN;\r
-    }\r
+  // Adjust for the correct time zone\r
+  if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r
+    EpochSeconds += Time->TimeZone * SEC_PER_MIN;\r
   }\r
 \r
-  // Get the current daylight information from non-volatile storage\r
-  Size = sizeof (Daylight);\r
-  Status = EfiGetVariable (\r
-                  (CHAR16 *)mDaylightVariableName,\r
-                  &gEfiCallerIdGuid,\r
-                  NULL,\r
-                  &Size,\r
-                  (VOID *)&Daylight\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    ASSERT(Status != EFI_INVALID_PARAMETER);\r
-    ASSERT(Status != EFI_BUFFER_TOO_SMALL);\r
-\r
-    if (Status != EFI_NOT_FOUND)\r
-      goto EXIT;\r
-\r
-    // The daylight variable does not exist in non-volatile storage, so create it.\r
-    Time->Daylight = 0;\r
-    // Store it\r
-    Status = EfiSetVariable (\r
-                    (CHAR16 *)mDaylightVariableName,\r
-                    &gEfiCallerIdGuid,\r
-                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                    Size,\r
-                    (VOID *)&(Time->Daylight)\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      DEBUG ((\r
-        EFI_D_ERROR,\r
-        "LibGetTime: Failed to save %s variable to non-volatile storage, Status = %r\n",\r
-        mDaylightVariableName,\r
-        Status\r
-        ));\r
-      goto EXIT;\r
-    }\r
-  } else {\r
-    // Got the daylight information\r
-    Time->Daylight = Daylight;\r
-\r
-    // Adjust for the correct period\r
-    if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {\r
-      // Convert to adjusted time, i.e. spring forwards one hour\r
-      EpochSeconds += SEC_PER_HOUR;\r
-    }\r
+  // Adjust for the correct period\r
+  if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {\r
+    // Convert to adjusted time, i.e. spring forwards one hour\r
+    EpochSeconds += SEC_PER_HOUR;\r
   }\r
 \r
   // Convert from internal 32-bit time to UEFI time\r
@@ -281,8 +187,7 @@ LibGetTime (
     Capabilities->SetsToZero  = FALSE;\r
   }\r
 \r
-  EXIT:\r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r
@@ -305,37 +210,19 @@ LibSetTime (
   EFI_STATUS  Status;\r
   UINTN       EpochSeconds;\r
 \r
-  // Check the input parameters are within the range specified by UEFI\r
-  if ((Time->Year   < 1900) ||\r
-       (Time->Year   > 9999) ||\r
-       (Time->Month  < 1   ) ||\r
-       (Time->Month  > 12  ) ||\r
-       (!IsDayValid (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
-    ) {\r
-    Status = EFI_INVALID_PARAMETER;\r
-    goto EXIT;\r
-  }\r
-\r
   // Because the PL031 is a 32-bit counter counting seconds,\r
   // the maximum time span is just over 136 years.\r
   // Time is stored in Unix Epoch format, so it starts in 1970,\r
   // Therefore it can not exceed the year 2106.\r
   if ((Time->Year < 1970) || (Time->Year >= 2106)) {\r
-    Status = EFI_UNSUPPORTED;\r
-    goto EXIT;\r
+    return EFI_UNSUPPORTED;\r
   }\r
 \r
   // Initialize the hardware if not already done\r
   if (!mPL031Initialized) {\r
     Status = InitializePL031 ();\r
     if (EFI_ERROR (Status)) {\r
-      goto EXIT;\r
+      return Status;\r
     }\r
   }\r
 \r
@@ -346,8 +233,6 @@ LibSetTime (
     EpochSeconds -= Time->TimeZone * SEC_PER_MIN;\r
   }\r
 \r
-  // TODO: Automatic Daylight activation\r
-\r
   // Adjust for the correct period\r
   if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {\r
     // Convert to un-adjusted time, i.e. fall back one hour\r
@@ -364,54 +249,13 @@ LibSetTime (
   Status = ArmPlatformSysConfigSet (SYS_CFG_RTC, EpochSeconds);\r
   if ((EFI_ERROR (Status)) && (Status != EFI_UNSUPPORTED)){\r
     // Any status message except SUCCESS and UNSUPPORTED indicates a hardware failure.\r
-    goto EXIT;\r
+    return Status;\r
   }\r
 \r
-\r
   // Set the PL031\r
   MmioWrite32 (mPL031RtcBase + PL031_RTC_LR_LOAD_REGISTER, EpochSeconds);\r
 \r
-  // The accesses to Variable Services can be very slow, because we may be writing to Flash.\r
-  // Do this after having set the RTC.\r
-\r
-  // Save the current time zone information into non-volatile storage\r
-  Status = EfiSetVariable (\r
-                  (CHAR16 *)mTimeZoneVariableName,\r
-                  &gEfiCallerIdGuid,\r
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  sizeof (Time->TimeZone),\r
-                  (VOID *)&(Time->TimeZone)\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-      DEBUG ((\r
-        EFI_D_ERROR,\r
-        "LibSetTime: Failed to save %s variable to non-volatile storage, Status = %r\n",\r
-        mTimeZoneVariableName,\r
-        Status\r
-        ));\r
-    goto EXIT;\r
-  }\r
-\r
-  // Save the current daylight information into non-volatile storage\r
-  Status = EfiSetVariable (\r
-                  (CHAR16 *)mDaylightVariableName,\r
-                  &gEfiCallerIdGuid,\r
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  sizeof(Time->Daylight),\r
-                  (VOID *)&(Time->Daylight)\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((\r
-      EFI_D_ERROR,\r
-      "LibSetTime: Failed to save %s variable to non-volatile storage, Status = %r\n",\r
-      mDaylightVariableName,\r
-      Status\r
-      ));\r
-    goto EXIT;\r
-  }\r
-\r
-  EXIT:\r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r