From: "Nhi Pham" <nhi@os.amperecomputing.com>
To: devel@edk2.groups.io
Cc: Nhi Pham <nhi@os.amperecomputing.com>,
Leif Lindholm <leif@nuviainc.com>,
Ard Biesheuvel <ard.biesheuvel@arm.com>
Subject: [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib
Date: Wed, 6 Jan 2021 17:55:58 +0700 [thread overview]
Message-ID: <20210106105558.9582-3-nhi@os.amperecomputing.com> (raw)
In-Reply-To: <20210106105558.9582-1-nhi@os.amperecomputing.com>
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
next prev parent reply other threads:[~2021-01-06 10:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Nhi Pham [this message]
2021-01-06 13:05 ` [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Leif Lindholm
2021-01-06 13:39 ` Nhi Pham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210106105558.9582-3-nhi@os.amperecomputing.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox