From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web08.10245.1609949375406160676 for ; Wed, 06 Jan 2021 08:09:35 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=eEJ3G2Ay; spf=fail (domain: os.amperecomputing.com, ip: , mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IKD4NM2YIS8Azg08uWKaTgXISynOfVxI8zrzg7LKOqD59kIrtCFdpKBzTnXd7soeUJalnmpSKtT3XdcpgamNz3JywXq4LSLEmev+9V/qPpwWPWJx5ayiZ9czAHQm4V6t+ib6I2n9nFk5rCvruBwfQ5hpACWZpDCi6MxJ/Zbz4vRANpHmLf//bGacc4DpHsfyHrbFbAMyMqtAzloJQ5Q551JuIMbWZPfTWMId9wowU0CrAfsAqXNAlvZdRLquDo/WaqPaFxYKDU/ZwmESkUlKH88XoYy7hklxyL8Dbv7+0N0BurxI7q4U8SeoY6PyKU21b9quHlBrYfNhKqw8yL9Qkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ov1HRFNYC5dmRz4htLvatG0J0FLWmX2Q4zfNW8O9lOU=; b=QhKf3NqxTPLU0pehuLpoz0omkNtr2BulBO7gPMcVKCrwaJb7vQjxO24cbXvJZiUSlwD3w9LO1HFOL1QzxlUk+AJJEGU+G30ueF/Mro3YTcDz89Ft85Ke//BqHRVTsUCbS3aGHU0P5LtJIEdX7/90k+2eeq8OTEDXygKT+oDATvhKlu7o6yCOHM32+IwhSGs+r7lIlir7sW3hVWpgSLewq9pQbb2d+aenDGIW2jPW+WmUr8GcXXM1KtTmEVtpYFVVrCjTzLyGYu1w+vxzqvUtvknKSf5TKnJVHKi/zy3xoCCkjcPrjIPpv5d2Cr0/rWL5Yga+/UtTUJWXLv2GrF0dAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ov1HRFNYC5dmRz4htLvatG0J0FLWmX2Q4zfNW8O9lOU=; b=eEJ3G2AyLIxhbha+50xIZDPKLUWf5JalhbRkQacLiVj8bZSWxTR7Y5V1SWMfNKS6RVL3YuGra03WUWdxBTSfIXuUDhzBXvwuILwjkMy7etwfFxQN9LoWUxvG5P8wcBmrEUwfjhIq54awY7pLCLXfZLfviL7+55o0HNupnDe+/GE= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM5PR01MB2538.prod.exchangelabs.com (2603:10b6:3:3e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 16:09:34 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076%5]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 16:09:34 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: Nhi Pham , Leif Lindholm , Ard Biesheuvel Subject: [PATCH v2 4/4] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Date: Wed, 6 Jan 2021 23:09:03 +0700 Message-Id: <20210106160903.27679-5-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210106160903.27679-1-nhi@os.amperecomputing.com> References: <20210106160903.27679-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK2PR02CA0220.apcprd02.prod.outlook.com (2603:1096:201:20::32) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (118.69.219.201) by HK2PR02CA0220.apcprd02.prod.outlook.com (2603:1096:201:20::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 16:09:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7da13fd3-7af6-42a7-4186-08d8b25d75a4 X-MS-TrafficTypeDiagnostic: DM5PR01MB2538: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z6XJHZ+7gfPvEEjkooSYM7UM3DEW2OXrWrb037UBYvqUsUWLkpYOyF4j7z7eWB7DVUdA5tOpBMGb4VAghCtcQziHeUw6orz+dr2D1arn0VNcg9vto0bzusDVlgAtoohC4wzt4yexiNFgmAhnhIkArWcgUpA7wxoMVUbDJ/SaGFK6iqz/75I/eIk+yGO+pRqyAM6Xc9mll079rccQTSlZEK/mFGmaf44XSAWsfylyPdmYr0pS5NVNvMCydkpmm5g+lu3YK56FIsO8MVf0Gmr3aIPqsOYqplYZdd4LoSZw2LWtQh9y5p9siSMpgTpu4efS7nrn7Sn/OmNZTowPp8oPaeDaSrG5Qe+WxUOTqy66nJD/F+VB+jukM3okUAmzkQNSrP3PytVbErWH0shaIbH8nkeBB7WBPT9s7kbwUV+TOyhBQItlqif8Op/U8aD2P+k19xYdZAwyxCJ1/oP1yX0cyroIZnCcHNT/gHicKRNR0x0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(136003)(376002)(346002)(396003)(39850400004)(2616005)(6506007)(956004)(316002)(1076003)(6666004)(69590400011)(2906002)(8676002)(478600001)(6486002)(8936002)(54906003)(186003)(26005)(83380400001)(16526019)(6916009)(66556008)(6512007)(86362001)(4326008)(66476007)(52116002)(5660300002)(66946007)(213903007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?k9q4U5X/0bpjLNOszN4fCmye3tY9baJicQXDqohueO8fzcp1un2jVbDJnv50?= =?us-ascii?Q?VcvcmGAYkSHA7bAVKweosdoiQIZOz08fdojus8nk6zuhizSgCr/njHWJOVna?= =?us-ascii?Q?hLW1sC31sGOvmtHE/CIrdD+JV3cyLwkwbpkRxfC+5n53FUmN34/5u0ziLqls?= =?us-ascii?Q?AB2yWWqra7wfduzKjW+yMVW9Rd6nOhkwFWB92FICF/oqAFuGpbRAMA2xTW9v?= =?us-ascii?Q?DwCX6ZTDDUW3YSsiStKlb0EQBWiWaRAd/xtEJezFzHHJnKyM61iKEiCGRucx?= =?us-ascii?Q?zIVjw+pcwYAzeGv+xGyApTVpi7qaovkliqS4fsWHJFvdDz8NI4SghSyxDxK0?= =?us-ascii?Q?wrNx3HZoy3tTmNoP1lKncY2JKJQ/R39v2ehL42BAJeFG3PCbmcWvH+U5mvLH?= =?us-ascii?Q?5qBRgU2H5M14dNgpZLF5IKmRfdiTzcOsyyRmrrIntCuQahMdCPFhxyxWDUZJ?= =?us-ascii?Q?P5hBZ6vrLgQw/g/IN6+/WqXRiTUf+vKJvlDVFYxtnTcnl3mEIl6/kJOyJP9n?= =?us-ascii?Q?Y6X6VoTsQqMFCSCLURknqc4Nh1a1P8F+ETi16FzKB01KVpH7ztkZq3xsnx23?= =?us-ascii?Q?Hubw9hKHMyF2067paxHX8uQtCGvtv0YP/0IVw0HUcM7hsLYM3b4abThZfgSB?= =?us-ascii?Q?T2Rau13S3INQBMJz10f/hRwMNeXlkq4EUlcrplDbKAXmuiRsubCRvugfVblf?= =?us-ascii?Q?Xaxhek2tkF3WZP3M3y9RFeBjvbWwA91AI5+Xf15eb84doM+GS8tnaOoazJ2j?= =?us-ascii?Q?jXL+26tmFBCZ0D43bFumJCiKo7tyiqvQ8TVLNq123qdtBU7xdDMwkewM1jJl?= =?us-ascii?Q?35RZczs4YM7gG8WdpSnyUe61GRA8N6QS/L7b/YhOHLOhKtBjQ9cqMOC/xLl/?= =?us-ascii?Q?wfahjQTWH5j4CZB5raKVD9ezSMVHbDXwufU82q4OJ3EqgJnwgnQkhYl9vH3P?= =?us-ascii?Q?JvAWyXYNZ5boPQQa4gJEtH2Z7aKzU0/FIgZsg2Izhf7AU2PL1rlQx3xqn2bB?= =?us-ascii?Q?Xn3q?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 16:09:33.8142 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-Network-Message-Id: 7da13fd3-7af6-42a7-4186-08d8b25d75a4 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EfUFAsxZYkAU8vsp/RenOPQVSwIEpjNhGztsGS+ZA0/Ppk9jJlZ80eFp4XQl1wZTpXsfNkNGfqSenqyEbYrbjzsK+yichH7OOxAGx/vO4RI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR01MB2538 Content-Type: text/plain This patch replaces all time checking functions and leverage the helper functions in TimeBaseLib library. Cc: Leif Lindholm Cc: Ard Biesheuvel Signed-off-by: Nhi Pham --- 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.
# Copyright (c) 2017, Linaro, Ltd. All rights reserved.
+# Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
# # 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.
Copyright (c) 2017, Linaro, Ltd. All rights reserved.
+ Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -11,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -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