From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (NAM02-BL2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.6321.1609930593240877652 for ; Wed, 06 Jan 2021 02:56:34 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=doVkwzVA; 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=AI6zOtIdCaQvENe2kitxaW4/uXzjn1coOR9N5eNhmgnkTUEWEIkI9vvvQpG7r8Nr3G6r/vYOBM+/d7wTyJvV1Pjmr/0fq1FstCB9uABI/GCV/bUZvwl66+fLP0WELhnCADCBSFM6DISJt0df3cbaaWI9hNm8FynKjexK3bnXWFMQ3o11KHQjdSc7/ng6JGRtG9hDo/Xhg0fpiv7FT1HaH9eoaWX4MS/sRte6b4ul1/KqcQe6mPbbhj+Cwj1FtkIDU8oSOCOyomFmP2ir5rsnwDX1b7X/Uc1Og8MwhwDdfFYQJG6j85L6g6tqBhOuLwJTRc1e/QKC35EIhyH4fnecFQ== 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=B71xAlQxz0pX24U7NxDzF1YyajO+rbQbSnfX/vwzKwY=; b=N9dKQaL0IfTwIC4EjofufoZJFty22eTxosdnDBrH7ArOD2yAMGWCVw+Mcr/YInGj7eyH/ieevjsQgvN8st7JjK1wjERNzMGqDrL6j9zK0wSQCrNu+wY+Qs5zfOHwht0OYpvOdOf3xDaiLP9yq4EnGFFqlEU8GnYqT2Vn9oOfenhSXb4UAkHbybIqPqlkUgGbpVu0ftxj4Og+Rkc/BM7DFnKpy5YF7H2GqqaBXJrCIAWZFbOvC+K5huPDB+3DTl9MqPVeP4fKd4orGytkSUBwKD/qKqeG6reACuSRd55M4jFJPWjaGMeUlmUFYGLwrzdNam3lp420ooUn4ce1Ac8Eew== 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=B71xAlQxz0pX24U7NxDzF1YyajO+rbQbSnfX/vwzKwY=; b=doVkwzVA5a6WzevHLzkdK0SiwGD7aF+JjSDhyn1vHLTzQwCYAAL1upJ7yP+n7HL9DlbzjU+utrMt5mIu3aL63aN0VRw+QKcSqL0U0BiDXsCICqd/+f/dl4YG+ggi5ovTkww+393uT9RyDtE55AMw+qxk6N7ASTtPwL959N4V2y4= 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 DM6PR01MB5051.prod.exchangelabs.com (2603:10b6:5:63::32) 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 10:56:33 +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 10:56:33 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: Nhi Pham , Leif Lindholm , Ard Biesheuvel Subject: [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Date: Wed, 6 Jan 2021 17:55:58 +0700 Message-Id: <20210106105558.9582-3-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210106105558.9582-1-nhi@os.amperecomputing.com> References: <20210106105558.9582-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK2PR06CA0008.apcprd06.prod.outlook.com (2603:1096:202:2e::20) 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 HK2PR06CA0008.apcprd06.prod.outlook.com (2603:1096:202:2e::20) 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 10:56:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e476e95c-a658-41f7-dd8a-08d8b231bb2d X-MS-TrafficTypeDiagnostic: DM6PR01MB5051: 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: EMJqgDGFdivnarlJEujubJC3Ydqkiw/UQAFfZfsRoaw90YJmaXC/qEruKFNYmsSwxUNu0ViUaZUZ/AWUYbjjpq5qXfG4EJu+CIYQE3cTSCIVSKQ1DnbNQfUjmOMfVQkwSw9WfpaByObZ+I9xeOH/fWQzrGeb+q3WpWpbsKrGYTVP2Ioq/5jPMyIY7kLJfbXdoj4fTbHCMjVZuvG2DKk29bWUO0iPpVDVCZcXuqr3hGU7DnFjcgCsPIaQBhXDFeve6Gv9ShhjTJRjRJNRRKRALOkZFqKsd1PaFX3HoZ25NAE4HmOKC9EhFdwbZ5N+RSFTX2wRB9ul1qGPnogUE97Bf+Futa1447xB4DcysFTavE+c9EejBhlMJZm7S/+3TpcLPPdvBfdNXYFV7N+hLb0o/ktTrN9UVbAF+RvXw8K9pprmUw54R6VbbohMVx+wEScjFmmzIv9n3RE9WwiyN6QX3V0Hs+/Z78gqxGP3TRDS0GQ= 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)(346002)(376002)(39850400004)(396003)(136003)(66556008)(956004)(2616005)(4326008)(54906003)(316002)(5660300002)(6506007)(26005)(52116002)(66946007)(69590400011)(66476007)(186003)(2906002)(16526019)(8936002)(86362001)(8676002)(6666004)(6486002)(6916009)(83380400001)(1076003)(478600001)(6512007)(213903007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ao+rItWGxouGfjNsToLBaeMXpYLKclBWkFRVt1pyTUqBmOzAUcGIqPT5pGFU?= =?us-ascii?Q?WXgUIPmY2oH8uP/wQE/Kp1ksRCCnnRlNtA5FaVfrN2qMcmBqaIWnze4IYhtx?= =?us-ascii?Q?W6c4t4vPH1Zo2WidI4T8BtHpf/0hLhlnXQCHzfXuPNNJ6yvgQQD52Jh+uf82?= =?us-ascii?Q?vw8exSwmv26kyas7nISsWE+hrXIgw8MT4na038U6+7UOPCAJmfDY7kF6sjHC?= =?us-ascii?Q?R2ehT12qgeuDXsKRv3c0ymxHlfVJiK2ndt9FnoJtpzlVKBAWG9oQmHHPy2Ae?= =?us-ascii?Q?Qv81i8/2nPudpsexNY6cschIT7AUTDTcHFtkxW+J8aWaRiBhfAqe4HIxiPkH?= =?us-ascii?Q?MAmzuPxdSB29vleRONR9GNTu53C1Mp2lJwzoDpMXi5XbrVQPyG7h5lmpUqKS?= =?us-ascii?Q?9p6GeWcMwp1HlJ6HkGKcFELgS8EWO8SWik4If6mSjdB+BbrJ4prPcQfbu5qh?= =?us-ascii?Q?ud5z+5rGAllw+XESBDc1x4cP/faaopK/J0G5KYaVWolVI1hmmZAmma7n/GAo?= =?us-ascii?Q?9JP2R+VIN85oksCb8IL0x30ZL0f5py2HACJXsOf2nSRFTjlp+fpk8Zyv63w+?= =?us-ascii?Q?xEtHWqNY88gRXQlvdiwZY9HeSISiciXeCRcZGHRhVyPnxntDB+Wq0MMf1IUz?= =?us-ascii?Q?74wSFqSUd6CGF/k9QFY6HSiyGGaLUBjPN0OZ/Uv7wYSufKigTeKRHYHIOMAM?= =?us-ascii?Q?UgEf39OPkWu70hVLBV9bPEBWR4DLTOVZRNkpKDBbt/ZLFTj5hd3nPQgOFEKN?= =?us-ascii?Q?jhf+kT1jd99RgjWQw+M0Z5pCUOHUyDhcaM3xII63rMQAAEMNkVF2OfKYqcDE?= =?us-ascii?Q?5q99/AItKfsDs9vFrlJiXdwdT/U3rmnLQsFH6LVVM+jTuBPnuYHwVd2C0Hd3?= =?us-ascii?Q?bXvl5YUEsdPYYQO841NozpsIU1utyoHrSTpO3spfTBP8YMu16dROoU8pmk4w?= =?us-ascii?Q?/khm6x+Kzrjq44NA/qXBIndeEB6csOgjf1GXF2zB7QR0DPIY0NTzX+O5rMUp?= =?us-ascii?Q?r8Dz?= 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 10:56:33.5702 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-Network-Message-Id: e476e95c-a658-41f7-dd8a-08d8b231bb2d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PRjCHFpXuWBTj31cBM6iAiwZURrralmGCVBqYMY3Kj40ZQSA6S5vs2U7QjFk7RBUJ+KRq1cpo7Ad3BS2TCi9HEoNQU8PVyoT+JKAQzrc2zI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5051 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..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.
# Copyright (c) 2017, Linaro, Ltd. All rights reserved.
+# Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
# # 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.
Copyright (c) 2017, Linaro, Ltd. All rights reserved.
+ Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -14,6 +15,7 @@ #include #include #include +#include #include 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