* [PATCH 0/2] Reduce duplicate code in RTC modules
@ 2021-01-06 10:55 Nhi Pham
2021-01-06 10:55 ` [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Nhi Pham
2021-01-06 10:55 ` [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
0 siblings, 2 replies; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 10:55 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 (2):
EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from
TimeBaseLib
.../RealTimeClockRuntimeDxe.inf | 2 +
EmbeddedPkg/Include/Library/TimeBaseLib.h | 13 +++
EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 47 +++++++---
.../RealTimeClockRuntimeDxe/RealTimeClock.c | 88 +------------------
4 files changed, 51 insertions(+), 99 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
2021-01-06 10:55 [PATCH 0/2] Reduce duplicate code in RTC modules Nhi Pham
@ 2021-01-06 10:55 ` Nhi Pham
2021-01-06 13:03 ` Leif Lindholm
2021-01-06 10:55 ` [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
1 sibling, 1 reply; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 10:55 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 | 13 ++++++
EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 47 ++++++++++++++------
2 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
index 90853c3f4b93..8bebf5886db8 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) 2020, Ampere Computing LLC. All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*
@@ -64,6 +65,18 @@ IsDayValid (
IN EFI_TIME *Time
);
+BOOLEAN
+EFIAPI
+IsValidTimeZone (
+ IN INT16 TimeZone
+ );
+
+BOOLEAN
+EFIAPI
+IsValidDaylight (
+ IN INT8 Daylight
+ );
+
BOOLEAN
EFIAPI
IsTimeValid (
diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index 78fc7b6cd2e5..02d9901338b9 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) 2020, Ampere Computing LLC. All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*
@@ -173,23 +174,43 @@ IsDayValid (
BOOLEAN
EFIAPI
-IsTimeValid(
+IsValidTimeZone (
+ IN INT16 TimeZone
+ )
+{
+ return TimeZone == EFI_UNSPECIFIED_TIMEZONE ||
+ (TimeZone >= -1440 && TimeZone <= 1440);
+}
+
+BOOLEAN
+EFIAPI
+IsValidDaylight (
+ IN INT8 Daylight
+ )
+{
+ return Daylight == 0 ||
+ Daylight == EFI_TIME_ADJUST_DAYLIGHT ||
+ Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT);
+}
+
+BOOLEAN
+EFIAPI
+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) ||
- (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||
- (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))
- ) {
+ 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) ||
+ (!IsValidTimeZone(Time->TimeZone)) ||
+ (!IsValidDaylight(Time->Daylight))) {
return FALSE;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib
2021-01-06 10:55 [PATCH 0/2] Reduce duplicate code in RTC modules Nhi Pham
2021-01-06 10:55 ` [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Nhi Pham
@ 2021-01-06 10:55 ` Nhi Pham
2021-01-06 13:05 ` Leif Lindholm
1 sibling, 1 reply; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 10:55 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..c0e44033af3a 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) 2020, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -31,6 +32,7 @@ [LibraryClasses]
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiRuntimeLib
+ TimeBaseLib
[Protocols]
gEfiRealTimeClockArchProtocolGuid
diff --git a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
index 20f1fa640ecc..8ae4e9315be5 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) 2020, Ampere Computing LLC. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -14,6 +15,7 @@
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeLib.h>
+#include <Library/TimeBaseLib.h>
#include <Protocol/RealTimeClock.h>
EFI_HANDLE mHandle = NULL;
@@ -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 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
2021-01-06 10:55 ` [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Nhi Pham
@ 2021-01-06 13:03 ` Leif Lindholm
0 siblings, 0 replies; 6+ messages in thread
From: Leif Lindholm @ 2021-01-06 13:03 UTC (permalink / raw)
To: Nhi Pham; +Cc: devel, Ard Biesheuvel
Hi Nhi,
On Wed, Jan 06, 2021 at 17:55:57 +0700, Nhi Pham wrote:
> 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 | 13 ++++++
> EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 47 ++++++++++++++------
> 2 files changed, 47 insertions(+), 13 deletions(-)
>
> diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
> index 90853c3f4b93..8bebf5886db8 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) 2020, Ampere Computing LLC. All rights reserved.
2021? :)
> *
> * SPDX-License-Identifier: BSD-2-Clause-Patent
> *
> @@ -64,6 +65,18 @@ IsDayValid (
> IN EFI_TIME *Time
> );
>
> +BOOLEAN
> +EFIAPI
> +IsValidTimeZone (
> + IN INT16 TimeZone
> + );
> +
> +BOOLEAN
> +EFIAPI
> +IsValidDaylight (
> + IN INT8 Daylight
> + );
> +
Could you please add doxygen comment blocks to these new functions
(and repeat them in the .c)?
I know we've been lax about this in the past, but I would like for us
to start improving (especially in common libraries).
> BOOLEAN
> EFIAPI
> IsTimeValid (
> diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
> index 78fc7b6cd2e5..02d9901338b9 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) 2020, Ampere Computing LLC. All rights reserved.
> *
> * SPDX-License-Identifier: BSD-2-Clause-Patent
> *
> @@ -173,23 +174,43 @@ IsDayValid (
>
> BOOLEAN
> EFIAPI
> -IsTimeValid(
> +IsValidTimeZone (
> + IN INT16 TimeZone
> + )
> +{
> + return TimeZone == EFI_UNSPECIFIED_TIMEZONE ||
> + (TimeZone >= -1440 && TimeZone <= 1440);
> +}
> +
> +BOOLEAN
> +EFIAPI
> +IsValidDaylight (
> + IN INT8 Daylight
> + )
> +{
> + return Daylight == 0 ||
> + Daylight == EFI_TIME_ADJUST_DAYLIGHT ||
> + Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT);
> +}
> +
> +BOOLEAN
> +EFIAPI
> +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) ||
> - (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||
> - (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))
> - ) {
> + 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) ||
> + (!IsValidTimeZone(Time->TimeZone)) ||
> + (!IsValidDaylight(Time->Daylight))) {
Can you split the tidying of unchanged lines up into a separate
preceding patch please?
Best Regards,
Leif
p.s.
I have now cleared my backlog after getting back from Christmas and am
just about to get back to reviewing the massive mt-jade platform port.
Apologies for the delay on this.
> return FALSE;
> }
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib
2021-01-06 10:55 ` [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
@ 2021-01-06 13:05 ` Leif Lindholm
2021-01-06 13:39 ` Nhi Pham
0 siblings, 1 reply; 6+ messages in thread
From: Leif Lindholm @ 2021-01-06 13:05 UTC (permalink / raw)
To: Nhi Pham; +Cc: devel, Ard Biesheuvel
On Wed, Jan 06, 2021 at 17:55:58 +0700, Nhi Pham wrote:
> 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..c0e44033af3a 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) 2020, Ampere Computing LLC. All rights reserved.<BR>
2021?
> #
> # SPDX-License-Identifier: BSD-2-Clause-Patent
> #
> @@ -31,6 +32,7 @@ [LibraryClasses]
> UefiBootServicesTableLib
> UefiDriverEntryPoint
> UefiRuntimeLib
> + TimeBaseLib
Please insert alphabetically sorted.
>
> [Protocols]
> gEfiRealTimeClockArchProtocolGuid
> diff --git a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
> index 20f1fa640ecc..8ae4e9315be5 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) 2020, Ampere Computing LLC. All rights reserved.<BR>
2021?
>
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
> @@ -14,6 +15,7 @@
> #include <Library/UefiLib.h>
> #include <Library/UefiBootServicesTableLib.h>
> #include <Library/UefiRuntimeLib.h>
> +#include <Library/TimeBaseLib.h>
Please insert alphabetically sorted.
This set looks a nice bit of cleanup, though - thanks!
/
Leif
> #include <Protocol/RealTimeClock.h>
>
> EFI_HANDLE mHandle = NULL;
> @@ -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 [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib
2021-01-06 13:05 ` Leif Lindholm
@ 2021-01-06 13:39 ` Nhi Pham
0 siblings, 0 replies; 6+ messages in thread
From: Nhi Pham @ 2021-01-06 13:39 UTC (permalink / raw)
To: Leif Lindholm; +Cc: devel, Ard Biesheuvel
Thanks. I will fix all comments in the v2.
-Nhi
On 1/6/21 20:05, Leif Lindholm wrote:
> On Wed, Jan 06, 2021 at 17:55:58 +0700, Nhi Pham wrote:
>> 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..c0e44033af3a 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) 2020, Ampere Computing LLC. All rights reserved.<BR>
> 2021?
>
>> #
>> # SPDX-License-Identifier: BSD-2-Clause-Patent
>> #
>> @@ -31,6 +32,7 @@ [LibraryClasses]
>> UefiBootServicesTableLib
>> UefiDriverEntryPoint
>> UefiRuntimeLib
>> + TimeBaseLib
> Please insert alphabetically sorted.
>
>>
>> [Protocols]
>> gEfiRealTimeClockArchProtocolGuid
>> diff --git a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
>> index 20f1fa640ecc..8ae4e9315be5 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) 2020, Ampere Computing LLC. All rights reserved.<BR>
> 2021?
>
>>
>> SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>> @@ -14,6 +15,7 @@
>> #include <Library/UefiLib.h>
>> #include <Library/UefiBootServicesTableLib.h>
>> #include <Library/UefiRuntimeLib.h>
>> +#include <Library/TimeBaseLib.h>
> Please insert alphabetically sorted.
>
> This set looks a nice bit of cleanup, though - thanks!
>
> /
> Leif
>
>> #include <Protocol/RealTimeClock.h>
>>
>> EFI_HANDLE mHandle = NULL;
>> @@ -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 [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-06 13:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-06 10:55 [PATCH 0/2] Reduce duplicate code in RTC modules Nhi Pham
2021-01-06 10:55 ` [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Nhi Pham
2021-01-06 13:03 ` Leif Lindholm
2021-01-06 10:55 ` [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
2021-01-06 13:05 ` Leif Lindholm
2021-01-06 13:39 ` Nhi Pham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox