public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules
@ 2021-01-06 16:08 Nhi Pham
  2021-01-06 16:09 ` [PATCH v2 1/4] EmbeddedPkg/TimeBaseLib: Update comment blocks for API functions Nhi Pham
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 16:08 UTC (permalink / raw)
  To: devel; +Cc: Nhi Pham, Leif Lindholm, Ard Biesheuvel

This patch series replaces all time checking functions and leverage
the helper function in TimeBaseLib library.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>

Nhi Pham (4):
  EmbeddedPkg/TimeBaseLib: Update comment blocks for API functions
  EmbeddedPkg/TimeBaseLib: Fix for minor code formatting
  EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
  EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from
    TimeBaseLib

 .../RealTimeClockRuntimeDxe.inf               |   2 +
 EmbeddedPkg/Include/Library/TimeBaseLib.h     |  90 +++++++++++-
 EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 134 +++++++++++++++---
 .../RealTimeClockRuntimeDxe/RealTimeClock.c   |  88 +-----------
 4 files changed, 201 insertions(+), 113 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/4] EmbeddedPkg/TimeBaseLib: Update comment blocks for API functions
  2021-01-06 16:08 [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Nhi Pham
@ 2021-01-06 16:09 ` Nhi Pham
  2021-01-06 16:09 ` [PATCH v2 2/4] EmbeddedPkg/TimeBaseLib: Fix for minor code formatting Nhi Pham
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 16:09 UTC (permalink / raw)
  To: devel; +Cc: Nhi Pham, Leif Lindholm, Ard Biesheuvel

This updates Doxygen comment blocks for API library functions.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 EmbeddedPkg/Include/Library/TimeBaseLib.h     | 54 +++++++++++++++--
 EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 64 +++++++++++++++++---
 2 files changed, 104 insertions(+), 14 deletions(-)

diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
index 90853c3f4b93..a9f3c6588b75 100644
--- a/EmbeddedPkg/Include/Library/TimeBaseLib.h
+++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h
@@ -2,6 +2,7 @@
 *
 *  Copyright (c) 2016, Hisilicon Limited. All rights reserved.
 *  Copyright (c) 2016-2019, Linaro Limited. All rights reserved.
+*  Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
@@ -52,18 +53,45 @@
 #define SEC_PER_HOUR                                    ((UINTN)  3600)
 #define SEC_PER_DAY                                     ((UINTN) 86400)
 
+/**
+  Check if it is a leap year.
+
+  @param    Time  The UEFI time to be checked.
+
+  @retval   TRUE  It is a leap year.
+  @retval   FALSE It is NOT a leap year.
+
+**/
 BOOLEAN
 EFIAPI
 IsLeapYear (
   IN  EFI_TIME  *Time
   );
 
+/**
+  Check if the day in the UEFI time is valid.
+
+  @param    Time    The UEFI time to be checked.
+
+  @retval   TRUE    Valid.
+  @retval   FALSE   Invalid.
+
+**/
 BOOLEAN
 EFIAPI
 IsDayValid (
   IN  EFI_TIME  *Time
   );
 
+/**
+  Check if the UEFI time is valid.
+
+  @param    Time    The UEFI time to be checked.
+
+  @retval   TRUE    Valid.
+  @retval   FALSE   Invalid.
+
+**/
 BOOLEAN
 EFIAPI
 IsTimeValid (
@@ -71,8 +99,12 @@ IsTimeValid (
   );
 
 /**
-  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME
- **/
+  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME.
+
+  @param  EpochSeconds   Epoch seconds.
+  @param  Time           The time converted to UEFI format.
+
+**/
 VOID
 EFIAPI
 EpochToEfiTime (
@@ -81,8 +113,13 @@ EpochToEfiTime (
   );
 
 /**
-  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
- **/
+  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC).
+
+  @param    Time  The UEFI time to be converted.
+
+  @return   Number of seconds.
+
+**/
 UINTN
 EFIAPI
 EfiTimeToEpoch (
@@ -90,8 +127,13 @@ EfiTimeToEpoch (
   );
 
 /**
-  returns Day of the week [0-6] 0=Sunday
- **/
+  Get the day of the week from the UEFI time.
+
+  @param    Time  The UEFI time to be calculated.
+
+  @return   The day of the week: Sunday=0, Monday=1, ... Saturday=6
+
+**/
 UINTN
 EfiTimeToWday (
   IN  EFI_TIME  *Time
diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index 78fc7b6cd2e5..c9048d765960 100644
--- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
+++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
@@ -2,6 +2,7 @@
 *
 *  Copyright (c) 2016, Hisilicon Limited. All rights reserved.
 *  Copyright (c) 2016-2019, Linaro Limited. All rights reserved.
+*  Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
@@ -13,8 +14,12 @@
 #include <Library/TimeBaseLib.h>
 
 /**
-  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME
- **/
+  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME.
+
+  @param  EpochSeconds   Epoch seconds.
+  @param  Time           The time converted to UEFI format.
+
+**/
 VOID
 EFIAPI
 EpochToEfiTime (
@@ -71,8 +76,13 @@ EpochToEfiTime (
 }
 
 /**
-  Calculate Epoch days
- **/
+  Calculate Epoch days.
+
+  @param    Time  The UEFI time to be calculated.
+
+  @return   Number of days.
+
+**/
 UINTN
 EFIAPI
 EfiGetEpochDays (
@@ -96,9 +106,15 @@ EfiGetEpochDays (
 
   return EpochDays;
 }
+
 /**
-  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
- **/
+  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC).
+
+  @param    Time  The UEFI time to be converted.
+
+  @return   Number of seconds.
+
+**/
 UINTN
 EFIAPI
 EfiTimeToEpoch (
@@ -116,8 +132,13 @@ EfiTimeToEpoch (
 }
 
 /**
-  returns Day of the week [0-6] 0=Sunday
- **/
+  Get the day of the week from the UEFI time.
+
+  @param    Time  The UEFI time to be calculated.
+
+  @return   The day of the week: Sunday=0, Monday=1, ... Saturday=6
+
+**/
 UINTN
 EfiTimeToWday (
   IN  EFI_TIME  *Time
@@ -132,6 +153,15 @@ EfiTimeToWday (
   return (EpochDays + 4) % 7;
 }
 
+/**
+  Check if it is a leap year.
+
+  @param    Time  The UEFI time to be checked.
+
+  @retval   TRUE  It is a leap year.
+  @retval   FALSE It is NOT a leap year.
+
+**/
 BOOLEAN
 EFIAPI
 IsLeapYear (
@@ -153,6 +183,15 @@ IsLeapYear (
   }
 }
 
+/**
+  Check if the day in the UEFI time is valid.
+
+  @param    Time    The UEFI time to be checked.
+
+  @retval   TRUE    Valid.
+  @retval   FALSE   Invalid.
+
+**/
 BOOLEAN
 EFIAPI
 IsDayValid (
@@ -171,6 +210,15 @@ IsDayValid (
   return TRUE;
 }
 
+/**
+  Check if the UEFI time is valid.
+
+  @param    Time    The UEFI time to be checked.
+
+  @retval   TRUE    Valid.
+  @retval   FALSE   Invalid.
+
+**/
 BOOLEAN
 EFIAPI
 IsTimeValid(
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/4] EmbeddedPkg/TimeBaseLib: Fix for minor code formatting
  2021-01-06 16:08 [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Nhi Pham
  2021-01-06 16:09 ` [PATCH v2 1/4] EmbeddedPkg/TimeBaseLib: Update comment blocks for API functions Nhi Pham
@ 2021-01-06 16:09 ` Nhi Pham
  2021-01-06 16:09 ` [PATCH v2 3/4] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Nhi Pham
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 16:09 UTC (permalink / raw)
  To: devel; +Cc: Nhi Pham, Leif Lindholm, Ard Biesheuvel

There is no functional modification in this change.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 23 ++++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index c9048d765960..17466c1e6c67 100644
--- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
+++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
@@ -221,23 +221,22 @@ IsDayValid (
 **/
 BOOLEAN
 EFIAPI
-IsTimeValid(
+IsTimeValid (
   IN EFI_TIME *Time
   )
 {
   // Check the input parameters are within the range specified by UEFI
-  if ((Time->Year   < 2000) ||
-     (Time->Year   > 2099) ||
-     (Time->Month  < 1   ) ||
-     (Time->Month  > 12  ) ||
-     (!IsDayValid (Time)    ) ||
-     (Time->Hour   > 23  ) ||
-     (Time->Minute > 59  ) ||
-     (Time->Second > 59  ) ||
-     (Time->Nanosecond > 999999999) ||
+  if ((Time->Year  < 2000)              ||
+     (Time->Year   > 2099)              ||
+     (Time->Month  < 1   )              ||
+     (Time->Month  > 12  )              ||
+     (!IsDayValid (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)))
-  ) {
+     (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))) {
     return FALSE;
   }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/4] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
  2021-01-06 16:08 [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Nhi Pham
  2021-01-06 16:09 ` [PATCH v2 1/4] EmbeddedPkg/TimeBaseLib: Update comment blocks for API functions Nhi Pham
  2021-01-06 16:09 ` [PATCH v2 2/4] EmbeddedPkg/TimeBaseLib: Fix for minor code formatting Nhi Pham
@ 2021-01-06 16:09 ` Nhi Pham
  2021-01-06 16:09 ` [PATCH v2 4/4] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
  2021-01-07 17:42 ` [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Leif Lindholm
  4 siblings, 0 replies; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 16:09 UTC (permalink / raw)
  To: devel; +Cc: Nhi Pham, Leif Lindholm, Ard Biesheuvel

This adds two functions IsValidTimeZone() and IsValidDaylight() to check
the time zone and daylight value from EFI time. These functions are
retrieved from the RealTimeClockRuntimeDxe module as they reduce
duplicated code in RTC modules.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 EmbeddedPkg/Include/Library/TimeBaseLib.h     | 36 ++++++++++++++
 EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 49 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
index a9f3c6588b75..10700d1a649a 100644
--- a/EmbeddedPkg/Include/Library/TimeBaseLib.h
+++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h
@@ -83,6 +83,42 @@ IsDayValid (
   IN  EFI_TIME  *Time
   );
 
+/**
+  Check if the time zone is valid.
+  Valid values are between -1440 and 1440 or 2047 (EFI_UNSPECIFIED_TIMEZONE).
+
+  @param    TimeZone    The time zone to be checked.
+
+  @retval   TRUE    Valid.
+  @retval   FALSE   Invalid.
+
+**/
+BOOLEAN
+EFIAPI
+IsValidTimeZone (
+  IN  INT16  TimeZone
+  );
+
+/**
+  Check if the daylight is valid.
+  Valid values are:
+    0 : Time is not affected.
+    1 : Time is affected, and has not been adjusted for daylight savings.
+    3 : Time is affected, and has been adjusted for daylight savings.
+  All other values are invalid.
+
+  @param    Daylight    The daylight to be checked.
+
+  @retval   TRUE    Valid.
+  @retval   FALSE   Invalid.
+
+**/
+BOOLEAN
+EFIAPI
+IsValidDaylight (
+  IN  INT8  Daylight
+  );
+
 /**
   Check if the UEFI time is valid.
 
diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index 17466c1e6c67..210d0b2bf17d 100644
--- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
+++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
@@ -210,6 +210,51 @@ IsDayValid (
   return TRUE;
 }
 
+/**
+  Check if the time zone is valid.
+  Valid values are between -1440 and 1440 or 2047 (EFI_UNSPECIFIED_TIMEZONE).
+
+  @param    TimeZone    The time zone to be checked.
+
+  @retval   TRUE    Valid.
+  @retval   FALSE   Invalid.
+
+**/
+BOOLEAN
+EFIAPI
+IsValidTimeZone (
+  IN  INT16  TimeZone
+  )
+{
+  return TimeZone == EFI_UNSPECIFIED_TIMEZONE ||
+         (TimeZone >= -1440 && TimeZone <= 1440);
+}
+
+/**
+  Check if the daylight is valid.
+  Valid values are:
+    0 : Time is not affected.
+    1 : Time is affected, and has not been adjusted for daylight savings.
+    3 : Time is affected, and has been adjusted for daylight savings.
+  All other values are invalid.
+
+  @param    Daylight    The daylight to be checked.
+
+  @retval   TRUE    Valid.
+  @retval   FALSE   Invalid.
+
+**/
+BOOLEAN
+EFIAPI
+IsValidDaylight (
+  IN  INT8  Daylight
+  )
+{
+  return Daylight == 0 ||
+         Daylight == EFI_TIME_ADJUST_DAYLIGHT ||
+         Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT);
+}
+
 /**
   Check if the UEFI time is valid.
 
@@ -235,8 +280,8 @@ IsTimeValid (
      (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)))) {
+     (!IsValidTimeZone(Time->TimeZone)) ||
+     (!IsValidDaylight(Time->Daylight))) {
     return FALSE;
   }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 4/4] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib
  2021-01-06 16:08 [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Nhi Pham
                   ` (2 preceding siblings ...)
  2021-01-06 16:09 ` [PATCH v2 3/4] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Nhi Pham
@ 2021-01-06 16:09 ` Nhi Pham
  2021-01-07 17:42 ` [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Leif Lindholm
  4 siblings, 0 replies; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 16:09 UTC (permalink / raw)
  To: devel; +Cc: Nhi Pham, Leif Lindholm, Ard Biesheuvel

This patch replaces all time checking functions and leverage the helper
functions in TimeBaseLib library.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf |  2 +
 EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c             | 88 +-------------------
 2 files changed, 4 insertions(+), 86 deletions(-)

diff --git a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
index c9cd052adef4..fec53c79d335 100644
--- a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
+++ b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
@@ -3,6 +3,7 @@
 #
 #  Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
 #  Copyright (c) 2017, Linaro, Ltd. All rights reserved.<BR>
+#  Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -28,6 +29,7 @@ [Packages]
 [LibraryClasses]
   DebugLib
   RealTimeClockLib
+  TimeBaseLib
   UefiBootServicesTableLib
   UefiDriverEntryPoint
   UefiRuntimeLib
diff --git a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
index 20f1fa640ecc..e59036badc91 100644
--- a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
+++ b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
@@ -3,6 +3,7 @@
 
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
   Copyright (c) 2017, Linaro, Ltd. All rights reserved.<BR>
+  Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -11,6 +12,7 @@
 #include <PiDxe.h>
 #include <Library/DebugLib.h>
 #include <Library/RealTimeClockLib.h>
+#include <Library/TimeBaseLib.h>
 #include <Library/UefiLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiRuntimeLib.h>
@@ -31,92 +33,6 @@ typedef struct {
 STATIC CONST CHAR16 mTimeSettingsVariableName[] = L"RtcTimeSettings";
 STATIC NON_VOLATILE_TIME_SETTINGS mTimeSettings;
 
-STATIC
-BOOLEAN
-IsValidTimeZone (
-  IN  INT16  TimeZone
-  )
-{
-  return TimeZone == EFI_UNSPECIFIED_TIMEZONE ||
-         (TimeZone >= -1440 && TimeZone <= 1440);
-}
-
-STATIC
-BOOLEAN
-IsValidDaylight (
-  IN  INT8  Daylight
-  )
-{
-  return Daylight == 0 ||
-         Daylight == EFI_TIME_ADJUST_DAYLIGHT ||
-         Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT);
-}
-
-STATIC
-BOOLEAN
-EFIAPI
-IsLeapYear (
-  IN EFI_TIME   *Time
-  )
-{
-  if (Time->Year % 4 == 0) {
-    if (Time->Year % 100 == 0) {
-      if (Time->Year % 400 == 0) {
-        return TRUE;
-      } else {
-        return FALSE;
-      }
-    } else {
-      return TRUE;
-    }
-  } else {
-    return FALSE;
-  }
-}
-
-STATIC CONST INTN mDayOfMonth[12] = {
-  31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
-STATIC
-BOOLEAN
-EFIAPI
-IsDayValid (
-  IN  EFI_TIME  *Time
-  )
-{
-  if (Time->Day < 1 ||
-      Time->Day > mDayOfMonth[Time->Month - 1] ||
-      (Time->Month == 2 && !IsLeapYear (Time) && Time->Day > 28)) {
-    return FALSE;
-  }
-  return TRUE;
-}
-
-STATIC
-BOOLEAN
-EFIAPI
-IsTimeValid(
-  IN EFI_TIME *Time
-  )
-{
-  // Check the input parameters are within the range specified by UEFI
-  if (Time->Year   < 1900               ||
-      Time->Year   > 9999               ||
-      Time->Month  < 1                  ||
-      Time->Month  > 12                 ||
-      !IsDayValid (Time)                ||
-      Time->Hour   > 23                 ||
-      Time->Minute > 59                 ||
-      Time->Second > 59                 ||
-      Time->Nanosecond > 999999999      ||
-      !IsValidTimeZone (Time->TimeZone) ||
-      !IsValidDaylight (Time->Daylight)) {
-    return FALSE;
-  }
-  return TRUE;
-}
-
 /**
   Returns the current time and date information, and the time-keeping capabilities
   of the hardware platform.
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules
  2021-01-06 16:08 [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Nhi Pham
                   ` (3 preceding siblings ...)
  2021-01-06 16:09 ` [PATCH v2 4/4] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
@ 2021-01-07 17:42 ` Leif Lindholm
  4 siblings, 0 replies; 6+ messages in thread
From: Leif Lindholm @ 2021-01-07 17:42 UTC (permalink / raw)
  To: Nhi Pham; +Cc: devel, Ard Biesheuvel

On Wed, Jan 06, 2021 at 23:08:59 +0700, Nhi Pham wrote:
> This patch series replaces all time checking functions and leverage
> the helper function in TimeBaseLib library.
> 
> Cc: Leif Lindholm <leif@nuviainc.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>

For the series:
Reviewed-by: Leif Lindholm <leif@nuviainc.com>

Pushed as 8015f3f6d400..55ee36b0c490.

Many thanks for this cleanup, especially for adding the doxygen
comments to the pre-existing functions.

> Nhi Pham (4):
>   EmbeddedPkg/TimeBaseLib: Update comment blocks for API functions
>   EmbeddedPkg/TimeBaseLib: Fix for minor code formatting
>   EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
>   EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from
>     TimeBaseLib
> 
>  .../RealTimeClockRuntimeDxe.inf               |   2 +
>  EmbeddedPkg/Include/Library/TimeBaseLib.h     |  90 +++++++++++-
>  EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 134 +++++++++++++++---
>  .../RealTimeClockRuntimeDxe/RealTimeClock.c   |  88 +-----------
>  4 files changed, 201 insertions(+), 113 deletions(-)
> 
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-07 17:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-06 16:08 [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Nhi Pham
2021-01-06 16:09 ` [PATCH v2 1/4] EmbeddedPkg/TimeBaseLib: Update comment blocks for API functions Nhi Pham
2021-01-06 16:09 ` [PATCH v2 2/4] EmbeddedPkg/TimeBaseLib: Fix for minor code formatting Nhi Pham
2021-01-06 16:09 ` [PATCH v2 3/4] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Nhi Pham
2021-01-06 16:09 ` [PATCH v2 4/4] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
2021-01-07 17:42 ` [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Leif Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox