From nobody Mon Sep 16 19:46:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+114511+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706248965186631.8495148175778; Thu, 25 Jan 2024 22:02:45 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=mWmSzylAzkiih/0ZVDBH3XQwcl/Tlt4ER+WvlEw5Gpk=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1706248964; v=1; b=A3TWwbyMW6QXypc8aMPxVX0tB2Gy/+7mMzHGjLeNQX5hOaQpDKzmkk+n/ZPoPAZBgrHNRkh3 VP4Dvtvj3l3P9V2JxESdjoMEKc1mwpsIGcZZWyiTJOoFySrXMFMT4EbBAZIzlYtWEnLe5heQsgL yiEf25TVaMtOwbNChcffW8vc= X-Received: by 127.0.0.2 with SMTP id 7m8ZYY1788612xRc5Vb2dEZq; Thu, 25 Jan 2024 22:02:44 -0800 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (NAM02-SN1-obe.outbound.protection.outlook.com [40.107.96.78]) by mx.groups.io with SMTP id smtpd.web11.9694.1706248964117658832 for ; Thu, 25 Jan 2024 22:02:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gHA2pHBKUZ2M26cd4qkofa8AvFDnA6u3zQ6LjStIJzZ84PLDbwaCwcuziEV/V/ydtTH2ELt8NNxZmL2pEtGHxDJWg8wITn3VlE9KYu1lSefigX7c2+77j8zIiVbB1NP0KESNjx40dS14z4Jeq1mlC9Uaw7wG6ykDNP98yhLNpH77TxE7UEKy7RjPsqM/H6v7UYDvyz/jTo/Zpc22dhmLUXfRhXqG46c251SzHc5JzVeV3Qyj2nZNHOc8S9BioCP/jIoFp5ktnn8upUXm17pmPUUJ4TDYpnkUrJd0uPHU7J9MquSX6tKrLdfDO0LepoXU7bvS1zAfiZZfdsTwk7hkCg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aoYxEzn33Mn0Lcr3ycv0/QRu20bMvMmQVFEPoNdmYwU=; b=BGYPiHRvshf9g0/7iRd3SkajL7FmVFqzOWIARINWA5TvKwgUA4CdZlDKz1X8W0IoDLDItQtvklcxOP0dAKwFi99lcvqkq+5ejSYmpnPG9wm33r0IFI5a8Qb4b/6Lsa2A35Xdrg7AM5CFclzgq7kwPV2azL8yDQGen7yANfGKL4EILJqFLpUcTRlT0zCxF5Q0vTIskeRYHDiPEyoKJ5VChnlz72aCwB6pUs+bn25c0qQT0rMyv7pOh2R6/LuFXNXFRbRFyanT66jdngOHOTWFW78gJ0dcGRkmYBOBe1WhjmjmxHCsjTeP7+4XsJxvJ6/JCq+U8iSWgdwEwzZR9M0ldw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) X-Received: from DS7PR03CA0340.namprd03.prod.outlook.com (2603:10b6:8:55::21) by SN7PR12MB8434.namprd12.prod.outlook.com (2603:10b6:806:2e6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Fri, 26 Jan 2024 06:02:39 +0000 X-Received: from DS2PEPF00003440.namprd02.prod.outlook.com (2603:10b6:8:55:cafe::5f) by DS7PR03CA0340.outlook.office365.com (2603:10b6:8:55::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27 via Frontend Transport; Fri, 26 Jan 2024 06:02:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+114511+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF00003440.mail.protection.outlook.com (10.167.18.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7228.16 via Frontend Transport; Fri, 26 Jan 2024 06:02:39 +0000 X-Received: from SHA-LX-MINGXZHA.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 00:02:37 -0600 From: "Zhai, MingXin (Duke) via groups.io" To: CC: Eric Xing , Duke Zhai , Igniculus Fu , Abner Chang Subject: [edk2-devel] [PATCH V2 19/32] AMD/VanGoghBoard: Check in PcatRealTimeClockRuntimeDxe module Date: Fri, 26 Jan 2024 14:00:37 +0800 Message-ID: <20240126060050.1725-20-duke.zhai@amd.com> In-Reply-To: <20240126060050.1725-1-duke.zhai@amd.com> References: <20240126060050.1725-1-duke.zhai@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003440:EE_|SN7PR12MB8434:EE_ X-MS-Office365-Filtering-Correlation-Id: 23a7f1e2-d39e-4fb7-a969-08dc1e3466d6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: PbxGMLE2WO6SjzCHFsSJ0KHp5doOnNe4Q3f5PosvhFp0Kc1hkIlwckp+zm9GT99R16KXuxxiTCJgmfgaJGtPAKyJ3A3ork+eQYMzpGo0U29ysc9AYfMWcBILldPFBtjteWOTAdH9PaxE7WgNJcD96kGp0Sgo32DCtPGQsSafoi1B51qGFex5afAZOQ39NHgcFAlVz3WZNdl8NbeIbrsTfmnBtuk7Pf6U1hHD3e6W7jeHAmeOFOaAmNKWCYKvcT8CQfDhVf1K01QUq27+t532lflMBu1iirPlVzWPLVVXmGT9WUQGfGdlRfqd/JdXn0hK2yY76n3lbLkW5jAFogIXqLT1RRj1jn4BBmpSKVBTImLpDjKF8BfJ3OM4zADZ+WXOysCFbxM+cQAbM1kEpDMPuId4oGgrnEq5XyYHqfpaWwyEmI++7Oygwo3hW7OxNKgO4HqXuotTl7VQXqDiIE/UasOg+uLOTYk9HfTvT3bF/5v/rc5Clk92XsjfxX/+OtOPV++c8IBA8J8nCeRSq+9b0lkYUc4Et7R7e9IF26QEXzuPonYV5cEFz2Xu6ort6ps2hzoUBl+YDIXWAVXSg6VQV63ACjkeAGfIMnZlnsAncCwbk4XVuD0TIcPVvXwqRoyv8y0NJx/5QSCIHgEiVdgmm0i0iSzEvkqcO0I0lMngR2PqTTSuUmN46W1aQX+pGidFao6+8Z2StOURIQ23O/SOUW0XNYk5jWdc/vsZIwAXL8xP0rA2B+uQJMJbUkdzy7vfSE89Mmwt3kdw0XmNp92ZeGQeQb2HH2boqqPnNy09/GcbSC9KQ6FEEvwJvkLj2r3/oDgEdMvxECqc+soHHEQ1Tg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 06:02:39.1463 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23a7f1e2-d39e-4fb7-a969-08dc1e3466d6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003440.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8434 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,duke.zhai@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 9tG9AO4ANGYfcDIW0O1oQ2CIx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706248967197100003 Content-Type: text/plain; charset="utf-8" From: Duke Zhai BZ #:4640 In V2: Improve coding style. 1.Remove the leading underscore and use double underscore at trailing in = C header files. 2.Remove old tianocore licenses and redundant license description. 3.Improve coding style. For example: remove space between @param. In V1: This driver provides GetTime, SetTime, GetWakeupTime, SetWakeupTime servi= ces to Runtime Service Table. It will install a tagging protocol with gEfiRealTimeClockArchProtocolGuid. Signed-off-by: Ken Yao Cc: Eric Xing Cc: Duke Zhai Cc: Igniculus Fu Cc: Abner Chang --- .../PcatRealTimeClockRuntimeDxe/PcRtc.c | 1341 +++++++++++++++++ .../PcatRealTimeClockRuntimeDxe/PcRtc.h | 374 +++++ .../PcatRealTimeClockRuntimeDxe/PcRtc.uni | 17 + .../PcatRealTimeClockRuntimeDxe/PcRtcEntry.c | 171 +++ .../PcRtcExtra.uni | 15 + .../PcatRealTimeClockRuntimeDxe.inf | 77 + 6 files changed, 1995 insertions(+) create mode 100644 Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/= PcatRealTimeClockRuntimeDxe/PcRtc.c create mode 100644 Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/= PcatRealTimeClockRuntimeDxe/PcRtc.h create mode 100644 Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/= PcatRealTimeClockRuntimeDxe/PcRtc.uni create mode 100644 Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/= PcatRealTimeClockRuntimeDxe/PcRtcEntry.c create mode 100644 Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/= PcatRealTimeClockRuntimeDxe/PcRtcExtra.uni create mode 100644 Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/= PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf diff --git a/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRea= lTimeClockRuntimeDxe/PcRtc.c b/Platform/AMD/VanGoghBoard/Override/edk2/PcAt= ChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c new file mode 100644 index 0000000000..4e42d9d2ad --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRealTimeCl= ockRuntimeDxe/PcRtc.c @@ -0,0 +1,1341 @@ +/** @file + RTC Architectural Protocol GUID as defined in DxeCis 0.96. + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "PcRtc.h" + +// +// Days of month. +// +UINTN mDayOfMonth[] =3D { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 = }; + +// +// The name of NV variable to store the timezone and daylight saving infor= mation. +// +CHAR16 mTimeZoneVariableName[] =3D L"RTC"; + +/** + Compare the Hour, Minute and Second of the From time and the To time. + + Only compare H/M/S in EFI_TIME and ignore other fields here. + + @param From the first time + @param To the second time + + @return >0 The H/M/S of the From time is later than those of To time + @return =3D=3D0 The H/M/S of the From time is same as those of To time + @return <0 The H/M/S of the From time is earlier than those of To time +**/ +INTN +CompareHMS ( + IN EFI_TIME *From, + IN EFI_TIME *To + ); + +/** + To check if second date is later than first date within 24 hours. + + @param From the first date + @param To the second date + + @retval TRUE From is previous to To within 24 hours. + @retval FALSE From is later, or it is previous to To more than 24 hours. +**/ +BOOLEAN +IsWithinOneDay ( + IN EFI_TIME *From, + IN EFI_TIME *To + ); + +/** + Read RTC content through its registers. + + @param Address Address offset of RTC. It is recommended to use macros = such as + RTC_ADDRESS_SECONDS. + + @return The data of UINT8 type read from RTC. +**/ +UINT8 +RtcRead ( + IN UINT8 Address + ) +{ + IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8)(Address | (UINT8)(IoRead8 (= PCAT_RTC_ADDRESS_REGISTER) & 0x80))); + return IoRead8 (PCAT_RTC_DATA_REGISTER); +} + +/** + Write RTC through its registers. + + @param Address Address offset of RTC. It is recommended to use macros = such as + RTC_ADDRESS_SECONDS. + @param Data The content you want to write into RTC. + +**/ +VOID +RtcWrite ( + IN UINT8 Address, + IN UINT8 Data + ) +{ + IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8)(Address | (UINT8)(IoRead8 (= PCAT_RTC_ADDRESS_REGISTER) & 0x80))); + IoWrite8 (PCAT_RTC_DATA_REGISTER, Data); +} + +/** + Initialize RTC. + + @param Global For global use inside this module. + + @retval EFI_DEVICE_ERROR Initialization failed due to device error. + @retval EFI_SUCCESS Initialization successful. + +**/ +EFI_STATUS +PcRtcInit ( + IN PC_RTC_MODULE_GLOBALS *Global + ) +{ + EFI_STATUS Status; + RTC_REGISTER_B RegisterB; + EFI_TIME Time; + UINTN DataSize; + UINT32 TimerVar; + BOOLEAN Enabled; + BOOLEAN Pending; + + // + // Acquire RTC Lock to make access to RTC atomic + // + if (!EfiAtRuntime ()) { + EfiAcquireLock (&Global->RtcLock); + } + + // + // Wait for up to 0.1 seconds for the RTC to be updated + // + Status =3D RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); + if (EFI_ERROR (Status)) { + // + // Set the variable with default value if the RTC is functioning incor= rectly. + // + Global->SavedTimeZone =3D EFI_UNSPECIFIED_TIMEZONE; + Global->Daylight =3D 0; + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_DEVICE_ERROR; + } + + // + // Get the Time/Date/Daylight Savings values. + // + Time.Second =3D RtcRead (RTC_ADDRESS_SECONDS); + Time.Minute =3D RtcRead (RTC_ADDRESS_MINUTES); + Time.Hour =3D RtcRead (RTC_ADDRESS_HOURS); + Time.Day =3D RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); + Time.Month =3D RtcRead (RTC_ADDRESS_MONTH); + Time.Year =3D RtcRead (RTC_ADDRESS_YEAR); + + // + // Set RTC configuration after get original time + // The value of bit AIE should be reserved. + // + RegisterB.Data =3D FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (Registe= rB.Data & BIT5); + RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); + + // + // Release RTC Lock. + // + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + // + // Get the data of Daylight saving and time zone, if they have been + // stored in NV variable during previous boot. + // + DataSize =3D sizeof (UINT32); + Status =3D EfiGetVariable ( + mTimeZoneVariableName, + &gEfiCallerIdGuid, + NULL, + &DataSize, + &TimerVar + ); + if (!EFI_ERROR (Status)) { + Time.TimeZone =3D (INT16)TimerVar; + Time.Daylight =3D (UINT8)(TimerVar >> 16); + } else { + Time.TimeZone =3D EFI_UNSPECIFIED_TIMEZONE; + Time.Daylight =3D 0; + } + + // + // Validate time fields + // + Status =3D ConvertRtcTimeToEfiTime (&Time, RegisterB); + if (!EFI_ERROR (Status)) { + Status =3D RtcTimeFieldsValid (&Time); + } + + if (EFI_ERROR (Status)) { + // + // Report Status Code to indicate that the RTC has bad date and time + // + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_BAD_DATE_TIME) + ); + Time.Second =3D RTC_INIT_SECOND; + Time.Minute =3D RTC_INIT_MINUTE; + Time.Hour =3D RTC_INIT_HOUR; + Time.Day =3D RTC_INIT_DAY; + Time.Month =3D RTC_INIT_MONTH; + Time.Year =3D PcdGet16 (PcdMinimalValidYear); + Time.Nanosecond =3D 0; + Time.TimeZone =3D EFI_UNSPECIFIED_TIMEZONE; + Time.Daylight =3D 0; + } + + // + // Reset time value according to new RTC configuration + // + Status =3D PcRtcSetTime (&Time, Global); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + // + // Reset wakeup time value to valid state when wakeup alarm is disabled = and wakeup time is invalid. + // Global variable has already had valid SavedTimeZone and Daylight, + // so we can use them to get and set wakeup time. + // + Status =3D PcRtcGetWakeupTime (&Enabled, &Pending, &Time, Global); + if ((Enabled) || (!EFI_ERROR (Status))) { + return EFI_SUCCESS; + } + + // + // When wakeup time is disabled and invalid, reset wakeup time register = to valid state + // but keep wakeup alarm disabled. + // + Time.Second =3D RTC_INIT_SECOND; + Time.Minute =3D RTC_INIT_MINUTE; + Time.Hour =3D RTC_INIT_HOUR; + Time.Day =3D RTC_INIT_DAY; + Time.Month =3D RTC_INIT_MONTH; + Time.Year =3D PcdGet16 (PcdMinimalValidYear); + Time.Nanosecond =3D 0; + Time.TimeZone =3D Global->SavedTimeZone; + Time.Daylight =3D Global->Daylight; + + // + // Acquire RTC Lock to make access to RTC atomic + // + if (!EfiAtRuntime ()) { + EfiAcquireLock (&Global->RtcLock); + } + + // + // Wait for up to 0.1 seconds for the RTC to be updated + // + Status =3D RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); + if (EFI_ERROR (Status)) { + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_DEVICE_ERROR; + } + + ConvertEfiTimeToRtcTime (&Time, RegisterB); + + // + // Set the Y/M/D info to variable as it has no corresponding hw register= s. + // + Status =3D EfiSetVariable ( + L"RTCALARM", + &gEfiCallerIdGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCES= S | EFI_VARIABLE_NON_VOLATILE, + sizeof (Time), + &Time + ); + if (EFI_ERROR (Status)) { + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_DEVICE_ERROR; + } + + // + // Inhibit updates of the RTC + // + RegisterB.Bits.Set =3D 1; + RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); + + // + // Set RTC alarm time registers + // + RtcWrite (RTC_ADDRESS_SECONDS_ALARM, Time.Second); + RtcWrite (RTC_ADDRESS_MINUTES_ALARM, Time.Minute); + RtcWrite (RTC_ADDRESS_HOURS_ALARM, Time.Hour); + + // + // Allow updates of the RTC registers + // + RegisterB.Bits.Set =3D 0; + RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); + + // + // Release RTC Lock. + // + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_SUCCESS; +} + +/** + Returns the current time and date information, and the time-keeping capa= bilities + of the hardware platform. + + @param Time A pointer to storage to receive a snapshot of the = current time. + @param Capabilities An optional pointer to a buffer to receive the rea= l time clock + device's capabilities. + @param Global For global use inside this module. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to ha= rdware error. + +**/ +EFI_STATUS +PcRtcGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities, OPTIONAL + IN PC_RTC_MODULE_GLOBALS *Global + ) +{ + EFI_STATUS Status; + RTC_REGISTER_B RegisterB; + + // + // Check parameters for null pointer + // + if (Time =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Acquire RTC Lock to make access to RTC atomic + // + if (!EfiAtRuntime ()) { + EfiAcquireLock (&Global->RtcLock); + } + + // + // Wait for up to 0.1 seconds for the RTC to be updated + // + Status =3D RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); + if (EFI_ERROR (Status)) { + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return Status; + } + + // + // Read Register B + // + RegisterB.Data =3D RtcRead (RTC_ADDRESS_REGISTER_B); + + // + // Get the Time/Date/Daylight Savings values. + // + Time->Second =3D RtcRead (RTC_ADDRESS_SECONDS); + Time->Minute =3D RtcRead (RTC_ADDRESS_MINUTES); + Time->Hour =3D RtcRead (RTC_ADDRESS_HOURS); + Time->Day =3D RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); + Time->Month =3D RtcRead (RTC_ADDRESS_MONTH); + Time->Year =3D RtcRead (RTC_ADDRESS_YEAR); + + // + // Release RTC Lock. + // + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + // + // Get the variable that contains the TimeZone and Daylight fields + // + Time->TimeZone =3D Global->SavedTimeZone; + Time->Daylight =3D Global->Daylight; + + // + // Make sure all field values are in correct range + // + Status =3D ConvertRtcTimeToEfiTime (Time, RegisterB); + if (!EFI_ERROR (Status)) { + Status =3D RtcTimeFieldsValid (Time); + } + + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + // + // Fill in Capabilities if it was passed in + // + if (Capabilities !=3D NULL) { + Capabilities->Resolution =3D 1; + // + // 1 hertz + // + Capabilities->Accuracy =3D 50000000; + // + // 50 ppm + // + Capabilities->SetsToZero =3D FALSE; + } + + return EFI_SUCCESS; +} + +/** + Sets the current local time and date information. + + @param Time A pointer to the current time. + @param Global For global use inside this module. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The time could not be set due due to hardw= are error. + +**/ +EFI_STATUS +PcRtcSetTime ( + IN EFI_TIME *Time, + IN PC_RTC_MODULE_GLOBALS *Global + ) +{ + EFI_STATUS Status; + EFI_TIME RtcTime; + RTC_REGISTER_B RegisterB; + UINT32 TimerVar; + + if (Time =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Make sure that the time fields are valid + // + Status =3D RtcTimeFieldsValid (Time); + if (EFI_ERROR (Status)) { + return Status; + } + + CopyMem (&RtcTime, Time, sizeof (EFI_TIME)); + + // + // Acquire RTC Lock to make access to RTC atomic + // + if (!EfiAtRuntime ()) { + EfiAcquireLock (&Global->RtcLock); + } + + // + // Wait for up to 0.1 seconds for the RTC to be updated + // + Status =3D RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); + if (EFI_ERROR (Status)) { + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return Status; + } + + // + // Write timezone and daylight to RTC variable + // + if ((Time->TimeZone =3D=3D EFI_UNSPECIFIED_TIMEZONE) && (Time->Daylight = =3D=3D 0)) { + Status =3D EfiSetVariable ( + mTimeZoneVariableName, + &gEfiCallerIdGuid, + 0, + 0, + NULL + ); + if (Status =3D=3D EFI_NOT_FOUND) { + Status =3D EFI_SUCCESS; + } + } else { + TimerVar =3D Time->Daylight; + TimerVar =3D (UINT32)((TimerVar << 16) | (UINT16)(Time->TimeZone)); + Status =3D EfiSetVariable ( + mTimeZoneVariableName, + &gEfiCallerIdGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_AC= CESS | EFI_VARIABLE_NON_VOLATILE, + sizeof (TimerVar), + &TimerVar + ); + } + + if (EFI_ERROR (Status)) { + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_DEVICE_ERROR; + } + + // + // Read Register B, and inhibit updates of the RTC + // + RegisterB.Data =3D RtcRead (RTC_ADDRESS_REGISTER_B); + RegisterB.Bits.Set =3D 1; + RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); + + // + // Store the century value to RTC before converting to BCD format. + // + if (Global->CenturyRtcAddress !=3D 0) { + RtcWrite (Global->CenturyRtcAddress, DecimalToBcd8 ((UINT8)(RtcTime.Ye= ar / 100))); + } + + ConvertEfiTimeToRtcTime (&RtcTime, RegisterB); + + RtcWrite (RTC_ADDRESS_SECONDS, RtcTime.Second); + RtcWrite (RTC_ADDRESS_MINUTES, RtcTime.Minute); + RtcWrite (RTC_ADDRESS_HOURS, RtcTime.Hour); + RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH, RtcTime.Day); + RtcWrite (RTC_ADDRESS_MONTH, RtcTime.Month); + RtcWrite (RTC_ADDRESS_YEAR, (UINT8)RtcTime.Year); + + // + // Allow updates of the RTC registers + // + RegisterB.Bits.Set =3D 0; + RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); + + // + // Release RTC Lock. + // + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + // + // Set the variable that contains the TimeZone and Daylight fields + // + Global->SavedTimeZone =3D Time->TimeZone; + Global->Daylight =3D Time->Daylight; + + return EFI_SUCCESS; +} + +/** + Returns the current wakeup alarm clock setting. + + @param Enabled Indicates if the alarm is currently enabled or disabled. + @param Pending Indicates if the alarm signal is pending and requires a= cknowledgment. + @param Time The current alarm setting. + @param Global For global use inside this module. + + @retval EFI_SUCCESS The alarm settings were returned. + @retval EFI_INVALID_PARAMETER Enabled is NULL. + @retval EFI_INVALID_PARAMETER Pending is NULL. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due= to a hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this pl= atform. + +**/ +EFI_STATUS +PcRtcGetWakeupTime ( + OUT BOOLEAN *Enabled, + OUT BOOLEAN *Pending, + OUT EFI_TIME *Time, + IN PC_RTC_MODULE_GLOBALS *Global + ) +{ + EFI_STATUS Status; + RTC_REGISTER_B RegisterB; + RTC_REGISTER_C RegisterC; + EFI_TIME RtcTime; + UINTN DataSize; + + // + // Check parameters for null pointers + // + if ((Enabled =3D=3D NULL) || (Pending =3D=3D NULL) || (Time =3D=3D NULL)= ) { + return EFI_INVALID_PARAMETER; + } + + // + // Acquire RTC Lock to make access to RTC atomic + // + if (!EfiAtRuntime ()) { + EfiAcquireLock (&Global->RtcLock); + } + + // + // Wait for up to 0.1 seconds for the RTC to be updated + // + Status =3D RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); + if (EFI_ERROR (Status)) { + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_DEVICE_ERROR; + } + + // + // Read Register B and Register C + // + RegisterB.Data =3D RtcRead (RTC_ADDRESS_REGISTER_B); + RegisterC.Data =3D RtcRead (RTC_ADDRESS_REGISTER_C); + + // + // Get the Time/Date/Daylight Savings values. + // + *Enabled =3D RegisterB.Bits.Aie; + *Pending =3D RegisterC.Bits.Af; + + Time->Second =3D RtcRead (RTC_ADDRESS_SECONDS_ALARM); + Time->Minute =3D RtcRead (RTC_ADDRESS_MINUTES_ALARM); + Time->Hour =3D RtcRead (RTC_ADDRESS_HOURS_ALARM); + Time->Day =3D RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); + Time->Month =3D RtcRead (RTC_ADDRESS_MONTH); + Time->Year =3D RtcRead (RTC_ADDRESS_YEAR); + Time->TimeZone =3D Global->SavedTimeZone; + Time->Daylight =3D Global->Daylight; + + // + // Get the alarm info from variable + // + DataSize =3D sizeof (EFI_TIME); + Status =3D EfiGetVariable ( + L"RTCALARM", + &gEfiCallerIdGuid, + NULL, + &DataSize, + &RtcTime + ); + if (!EFI_ERROR (Status)) { + // + // The alarm variable exists. In this case, we read variable to get in= fo. + // + Time->Day =3D RtcTime.Day; + Time->Month =3D RtcTime.Month; + Time->Year =3D RtcTime.Year; + } + + // + // Release RTC Lock. + // + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + // + // Make sure all field values are in correct range + // + Status =3D ConvertRtcTimeToEfiTime (Time, RegisterB); + if (!EFI_ERROR (Status)) { + Status =3D RtcTimeFieldsValid (Time); + } + + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} + +/** + Sets the system wakeup alarm clock time. + + @param Enabled Enable or disable the wakeup alarm. + @param Time If Enable is TRUE, the time to set the wakeup alarm for. + If Enable is FALSE, then this parameter is optional, an= d may be NULL. + @param Global For global use inside this module. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm w= as enabled. + If Enable is FALSE, then the wakeup alarm = was disabled. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a = hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this pl= atform. + +**/ +EFI_STATUS +PcRtcSetWakeupTime ( + IN BOOLEAN Enable, + IN EFI_TIME *Time, OPTIONAL + IN PC_RTC_MODULE_GLOBALS *Global + ) +{ + EFI_STATUS Status; + EFI_TIME RtcTime; + RTC_REGISTER_B RegisterB; + EFI_TIME_CAPABILITIES Capabilities; + + ZeroMem (&RtcTime, sizeof (RtcTime)); + + if (Enable) { + if (Time =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Make sure that the time fields are valid + // + Status =3D RtcTimeFieldsValid (Time); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + + // + // Just support set alarm time within 24 hours + // + PcRtcGetTime (&RtcTime, &Capabilities, Global); + Status =3D RtcTimeFieldsValid (&RtcTime); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + if (!IsWithinOneDay (&RtcTime, Time)) { + return EFI_UNSUPPORTED; + } + + // + // Make a local copy of the time and date + // + CopyMem (&RtcTime, Time, sizeof (EFI_TIME)); + } + + // + // Acquire RTC Lock to make access to RTC atomic + // + if (!EfiAtRuntime ()) { + EfiAcquireLock (&Global->RtcLock); + } + + // + // Wait for up to 0.1 seconds for the RTC to be updated + // + Status =3D RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); + if (EFI_ERROR (Status)) { + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_DEVICE_ERROR; + } + + // + // Read Register B + // + RegisterB.Data =3D RtcRead (RTC_ADDRESS_REGISTER_B); + + if (Enable) { + ConvertEfiTimeToRtcTime (&RtcTime, RegisterB); + } else { + // + // if the alarm is disable, record the current setting. + // + RtcTime.Second =3D RtcRead (RTC_ADDRESS_SECONDS_ALARM); + RtcTime.Minute =3D RtcRead (RTC_ADDRESS_MINUTES_ALARM); + RtcTime.Hour =3D RtcRead (RTC_ADDRESS_HOURS_ALARM); + RtcTime.Day =3D RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); + RtcTime.Month =3D RtcRead (RTC_ADDRESS_MONTH); + RtcTime.Year =3D RtcRead (RTC_ADDRESS_YEAR); + RtcTime.TimeZone =3D Global->SavedTimeZone; + RtcTime.Daylight =3D Global->Daylight; + } + + // + // Set the Y/M/D info to variable as it has no corresponding hw register= s. + // + Status =3D EfiSetVariable ( + L"RTCALARM", + &gEfiCallerIdGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCES= S | EFI_VARIABLE_NON_VOLATILE, + sizeof (RtcTime), + &RtcTime + ); + if (EFI_ERROR (Status)) { + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_DEVICE_ERROR; + } + + // + // Inhibit updates of the RTC + // + RegisterB.Bits.Set =3D 1; + RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); + + if (Enable) { + // + // Set RTC alarm time + // + RtcWrite (RTC_ADDRESS_SECONDS_ALARM, RtcTime.Second); + RtcWrite (RTC_ADDRESS_MINUTES_ALARM, RtcTime.Minute); + RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour); + + RegisterB.Bits.Aie =3D 1; + } else { + RegisterB.Bits.Aie =3D 0; + } + + // + // Allow updates of the RTC registers + // + RegisterB.Bits.Set =3D 0; + RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); + + // + // Release RTC Lock. + // + if (!EfiAtRuntime ()) { + EfiReleaseLock (&Global->RtcLock); + } + + return EFI_SUCCESS; +} + +/** + Checks an 8-bit BCD value, and converts to an 8-bit value if valid. + + This function checks the 8-bit BCD value specified by Value. + If valid, the function converts it to an 8-bit value and returns it. + Otherwise, return 0xff. + + @param Value The 8-bit BCD value to check and convert + + @return The 8-bit value converted. Or 0xff if Value is invalid. + +**/ +UINT8 +CheckAndConvertBcd8ToDecimal8 ( + IN UINT8 Value + ) +{ + if ((Value < 0xa0) && ((Value & 0xf) < 0xa)) { + return BcdToDecimal8 (Value); + } + + return 0xff; +} + +/** + Converts time read from RTC to EFI_TIME format defined by UEFI spec. + + This function converts raw time data read from RTC to the EFI_TIME format + defined by UEFI spec. + If data mode of RTC is BCD, then converts it to decimal, + If RTC is in 12-hour format, then converts it to 24-hour format. + + @param Time On input, the time data read from RTC to convert + On output, the time converted to UEFI format + @param RegisterB Value of Register B of RTC, indicating data mode + and hour format. + + @retval EFI_INVALID_PARAMETER Parameters passed in are invalid. + @retval EFI_SUCCESS Convert RTC time to EFI time successfull= y. + +**/ +EFI_STATUS +ConvertRtcTimeToEfiTime ( + IN OUT EFI_TIME *Time, + IN RTC_REGISTER_B RegisterB + ) +{ + BOOLEAN IsPM; + UINT8 Century; + + if ((Time->Hour & 0x80) !=3D 0) { + IsPM =3D TRUE; + } else { + IsPM =3D FALSE; + } + + Time->Hour =3D (UINT8)(Time->Hour & 0x7f); + + if (RegisterB.Bits.Dm =3D=3D 0) { + Time->Year =3D CheckAndConvertBcd8ToDecimal8 ((UINT8)Time->Year); + Time->Month =3D CheckAndConvertBcd8ToDecimal8 (Time->Month); + Time->Day =3D CheckAndConvertBcd8ToDecimal8 (Time->Day); + Time->Hour =3D CheckAndConvertBcd8ToDecimal8 (Time->Hour); + Time->Minute =3D CheckAndConvertBcd8ToDecimal8 (Time->Minute); + Time->Second =3D CheckAndConvertBcd8ToDecimal8 (Time->Second); + } + + if ((Time->Year =3D=3D 0xff) || (Time->Month =3D=3D 0xff) || (Time->Day = =3D=3D 0xff) || + (Time->Hour =3D=3D 0xff) || (Time->Minute =3D=3D 0xff) || (Time->Sec= ond =3D=3D 0xff)) + { + return EFI_INVALID_PARAMETER; + } + + // + // For minimal/maximum year range [1970, 2069], + // Century is 19 if RTC year >=3D 70, + // Century is 20 otherwise. + // + Century =3D (UINT8)(PcdGet16 (PcdMinimalValidYear) / 100); + if (Time->Year < PcdGet16 (PcdMinimalValidYear) % 100) { + Century++; + } + + Time->Year =3D (UINT16)(Century * 100 + Time->Year); + + // + // If time is in 12 hour format, convert it to 24 hour format + // + if (RegisterB.Bits.Mil =3D=3D 0) { + if (IsPM && (Time->Hour < 12)) { + Time->Hour =3D (UINT8)(Time->Hour + 12); + } + + if (!IsPM && (Time->Hour =3D=3D 12)) { + Time->Hour =3D 0; + } + } + + Time->Nanosecond =3D 0; + + return EFI_SUCCESS; +} + +/** + Wait for a period for the RTC to be ready. + + @param Timeout Tell how long it should take to wait. + + @retval EFI_DEVICE_ERROR RTC device error. + @retval EFI_SUCCESS RTC is updated and ready. +**/ +EFI_STATUS +RtcWaitToUpdate ( + UINTN Timeout + ) +{ + RTC_REGISTER_A RegisterA; + RTC_REGISTER_D RegisterD; + + // + // See if the RTC is functioning correctly + // + RegisterD.Data =3D RtcRead (RTC_ADDRESS_REGISTER_D); + + if (RegisterD.Bits.Vrt =3D=3D 0) { + return EFI_DEVICE_ERROR; + } + + // + // Wait for up to 0.1 seconds for the RTC to be ready. + // + Timeout =3D (Timeout / 10) + 1; + RegisterA.Data =3D RtcRead (RTC_ADDRESS_REGISTER_A); + while (RegisterA.Bits.Uip =3D=3D 1 && Timeout > 0) { + MicroSecondDelay (10); + RegisterA.Data =3D RtcRead (RTC_ADDRESS_REGISTER_A); + Timeout--; + } + + RegisterD.Data =3D RtcRead (RTC_ADDRESS_REGISTER_D); + if ((Timeout =3D=3D 0) || (RegisterD.Bits.Vrt =3D=3D 0)) { + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} + +/** + See if all fields of a variable of EFI_TIME type is correct. + + @param Time The time to be checked. + + @retval EFI_INVALID_PARAMETER Some fields of Time are not correct. + @retval EFI_SUCCESS Time is a valid EFI_TIME variable. + +**/ +EFI_STATUS +RtcTimeFieldsValid ( + IN EFI_TIME *Time + ) +{ + if ((Time->Year < PcdGet16 (PcdMinimalValidYear)) || + (Time->Year > PcdGet16 (PcdMaximalValidYear)) || + (Time->Month < 1) || + (Time->Month > 12) || + (!DayValid (Time)) || + (Time->Hour > 23) || + (Time->Minute > 59) || + (Time->Second > 59) || + (Time->Nanosecond > 999999999) || + (!((Time->TimeZone =3D=3D EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZ= one >=3D -1440) && (Time->TimeZone <=3D 1440)))) || + ((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGH= T))) !=3D 0)) + { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** + See if field Day of an EFI_TIME is correct. + + @param Time Its Day field is to be checked. + + @retval TRUE Day field of Time is correct. + @retval FALSE Day field of Time is NOT correct. +**/ +BOOLEAN +DayValid ( + IN EFI_TIME *Time + ) +{ + // + // The validity of Time->Month field should be checked before + // + ASSERT (Time->Month >=3D 1); + ASSERT (Time->Month <=3D 12); + if ((Time->Day < 1) || + (Time->Day > mDayOfMonth[Time->Month - 1]) || + ((Time->Month =3D=3D 2) && (!IsLeapYear (Time) && (Time->Day > 28))) + ) + { + return FALSE; + } + + return TRUE; +} + +/** + Check if it is a leap year. + + @param Time The time to be checked. + + @retval TRUE It is a leap year. + @retval FALSE It is NOT a leap year. +**/ +BOOLEAN +IsLeapYear ( + IN EFI_TIME *Time + ) +{ + if (Time->Year % 4 =3D=3D 0) { + if (Time->Year % 100 =3D=3D 0) { + if (Time->Year % 400 =3D=3D 0) { + return TRUE; + } else { + return FALSE; + } + } else { + return TRUE; + } + } else { + return FALSE; + } +} + +/** + Converts time from EFI_TIME format defined by UEFI spec to RTC's. + + This function converts time from EFI_TIME format defined by UEFI spec to= RTC's. + If data mode of RTC is BCD, then converts EFI_TIME to it. + If RTC is in 12-hour format, then converts EFI_TIME to it. + + @param Time On input, the time data read from UEFI to convert + On output, the time converted to RTC format + @param RegisterB Value of Register B of RTC, indicating data mode +**/ +VOID +ConvertEfiTimeToRtcTime ( + IN OUT EFI_TIME *Time, + IN RTC_REGISTER_B RegisterB + ) +{ + BOOLEAN IsPM; + + IsPM =3D TRUE; + // + // Adjust hour field if RTC is in 12 hour mode + // + if (RegisterB.Bits.Mil =3D=3D 0) { + if (Time->Hour < 12) { + IsPM =3D FALSE; + } + + if (Time->Hour >=3D 13) { + Time->Hour =3D (UINT8)(Time->Hour - 12); + } else if (Time->Hour =3D=3D 0) { + Time->Hour =3D 12; + } + } + + // + // Set the Time/Date values. + // + Time->Year =3D (UINT16)(Time->Year % 100); + + if (RegisterB.Bits.Dm =3D=3D 0) { + Time->Year =3D DecimalToBcd8 ((UINT8)Time->Year); + Time->Month =3D DecimalToBcd8 (Time->Month); + Time->Day =3D DecimalToBcd8 (Time->Day); + Time->Hour =3D DecimalToBcd8 (Time->Hour); + Time->Minute =3D DecimalToBcd8 (Time->Minute); + Time->Second =3D DecimalToBcd8 (Time->Second); + } + + // + // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour f= ield. + // + if ((RegisterB.Bits.Mil =3D=3D 0) && IsPM) { + Time->Hour =3D (UINT8)(Time->Hour | 0x80); + } +} + +/** + Compare the Hour, Minute and Second of the From time and the To time. + + Only compare H/M/S in EFI_TIME and ignore other fields here. + + @param From the first time + @param To the second time + + @return >0 The H/M/S of the From time is later than those of To time + @return =3D=3D0 The H/M/S of the From time is same as those of To time + @return <0 The H/M/S of the From time is earlier than those of To time +**/ +INTN +CompareHMS ( + IN EFI_TIME *From, + IN EFI_TIME *To + ) +{ + if ((From->Hour > To->Hour) || + ((From->Hour =3D=3D To->Hour) && (From->Minute > To->Minute)) || + ((From->Hour =3D=3D To->Hour) && (From->Minute =3D=3D To->Minute) &&= (From->Second > To->Second))) + { + return 1; + } else if ((From->Hour =3D=3D To->Hour) && (From->Minute =3D=3D To->Minu= te) && (From->Second =3D=3D To->Second)) { + return 0; + } else { + return -1; + } +} + +/** + To check if second date is later than first date within 24 hours. + + @param From the first date + @param To the second date + + @retval TRUE From is previous to To within 24 hours. + @retval FALSE From is later, or it is previous to To more than 24 hours. +**/ +BOOLEAN +IsWithinOneDay ( + IN EFI_TIME *From, + IN EFI_TIME *To + ) +{ + BOOLEAN Adjacent; + + Adjacent =3D FALSE; + + // + // The validity of From->Month field should be checked before + // + ASSERT (From->Month >=3D 1); + ASSERT (From->Month <=3D 12); + + if (From->Year =3D=3D To->Year) { + if (From->Month =3D=3D To->Month) { + if ((From->Day + 1) =3D=3D To->Day) { + if ((CompareHMS (From, To) >=3D 0)) { + Adjacent =3D TRUE; + } + } else if (From->Day =3D=3D To->Day) { + if ((CompareHMS (From, To) <=3D 0)) { + Adjacent =3D TRUE; + } + } + } else if (((From->Month + 1) =3D=3D To->Month) && (To->Day =3D=3D 1))= { + if ((From->Month =3D=3D 2) && !IsLeapYear (From)) { + if (From->Day =3D=3D 28) { + if ((CompareHMS (From, To) >=3D 0)) { + Adjacent =3D TRUE; + } + } + } else if (From->Day =3D=3D mDayOfMonth[From->Month - 1]) { + if ((CompareHMS (From, To) >=3D 0)) { + Adjacent =3D TRUE; + } + } + } + } else if (((From->Year + 1) =3D=3D To->Year) && + (From->Month =3D=3D 12) && + (From->Day =3D=3D 31) && + (To->Month =3D=3D 1) && + (To->Day =3D=3D 1)) + { + if ((CompareHMS (From, To) >=3D 0)) { + Adjacent =3D TRUE; + } + } + + return Adjacent; +} + +/** + This function find ACPI table with the specified signature in RSDT or XS= DT. + + @param Sdt ACPI RSDT or XSDT. + @param Signature ACPI table signature. + @param TablePointerSize Size of table pointer: 4 or 8. + + @return ACPI table or NULL if not found. +**/ +VOID * +ScanTableInSDTRtc ( + IN EFI_ACPI_DESCRIPTION_HEADER *Sdt, + IN UINT32 Signature, + IN UINTN TablePointerSize + ) +{ + UINTN Index; + UINTN EntryCount; + UINTN EntryBase; + EFI_ACPI_DESCRIPTION_HEADER *Table; + + EntryCount =3D (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / Ta= blePointerSize; + + EntryBase =3D (UINTN)(Sdt + 1); + for (Index =3D 0; Index < EntryCount; Index++) { + // + // When TablePointerSize is 4 while sizeof (VOID *) is 8, make sure th= e upper 4 bytes are zero. + // + Table =3D 0; + CopyMem (&Table, (VOID *)(EntryBase + Index * TablePointerSize), Table= PointerSize); + + if (Table =3D=3D NULL) { + continue; + } + + if (Table->Signature =3D=3D Signature) { + return Table; + } + } + + return NULL; +} + +/** + Get the century RTC address from the ACPI FADT table. + + @return The century RTC address or 0 if not found. +**/ +UINT8 +GetCenturyRtcAddress ( + VOID + ) +{ + EFI_STATUS Status; + EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt; + + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)= &Rsdp); + if (EFI_ERROR (Status)) { + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpi10TableGuid, (VOID= **)&Rsdp); + } + + if (EFI_ERROR (Status) || (Rsdp =3D=3D NULL)) { + return 0; + } + + Fadt =3D NULL; + + // + // Find FADT in XSDT + // + if ((Rsdp->Revision >=3D EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_RE= VISION) && (Rsdp->XsdtAddress !=3D 0)) { + Fadt =3D ScanTableInSDTRtc ( + (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress, + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, + sizeof (UINTN) + ); + } + + // + // Find FADT in RSDT + // + if ((Fadt =3D=3D NULL) && (Rsdp->RsdtAddress !=3D 0)) { + Fadt =3D ScanTableInSDTRtc ( + (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress, + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, + sizeof (UINT32) + ); + } + + if ((Fadt !=3D NULL) && + (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80) + ) + { + return Fadt->Century; + } else { + return 0; + } +} + +/** + Notification function of ACPI Table change. + + This is a notification function registered on ACPI Table change event. + It saves the Century address stored in ACPI FADT table. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context. + +**/ +VOID +EFIAPI +PcRtcAcpiTableChangeCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EFI_TIME Time; + UINT8 CenturyRtcAddress; + UINT8 Century; + + CenturyRtcAddress =3D GetCenturyRtcAddress (); + if ((CenturyRtcAddress !=3D 0) && (mModuleGlobal.CenturyRtcAddress !=3D = CenturyRtcAddress)) { + mModuleGlobal.CenturyRtcAddress =3D CenturyRtcAddress; + Status =3D PcRtcGetTime (&Time, NULL, &mModul= eGlobal); + if (!EFI_ERROR (Status)) { + Century =3D (UINT8)(Time.Year / 100); + Century =3D DecimalToBcd8 (Century); + DEBUG ((DEBUG_INFO, "PcRtc: Write 0x%x to CMOS location 0x%x\n", Cen= tury, mModuleGlobal.CenturyRtcAddress)); + RtcWrite (mModuleGlobal.CenturyRtcAddress, Century); + } + } +} diff --git a/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRea= lTimeClockRuntimeDxe/PcRtc.h b/Platform/AMD/VanGoghBoard/Override/edk2/PcAt= ChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h new file mode 100644 index 0000000000..159bebf309 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRealTimeCl= ockRuntimeDxe/PcRtc.h @@ -0,0 +1,374 @@ +/** @file + Header file for real time clock driver. + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef RTC_H__ +#define RTC_H__ + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct { + EFI_LOCK RtcLock; + INT16 SavedTimeZone; + UINT8 Daylight; + UINT8 CenturyRtcAddress; +} PC_RTC_MODULE_GLOBALS; + +extern PC_RTC_MODULE_GLOBALS mModuleGlobal; + +#define PCAT_RTC_ADDRESS_REGISTER 0x70 +#define PCAT_RTC_DATA_REGISTER 0x71 + +// +// Dallas DS12C887 Real Time Clock +// +#define RTC_ADDRESS_SECONDS 0 // R/W Range 0..59 +#define RTC_ADDRESS_SECONDS_ALARM 1 // R/W Range 0..59 +#define RTC_ADDRESS_MINUTES 2 // R/W Range 0..59 +#define RTC_ADDRESS_MINUTES_ALARM 3 // R/W Range 0..59 +#define RTC_ADDRESS_HOURS 4 // R/W Range 1..12 or 0..23 Bit= 7 is AM/PM +#define RTC_ADDRESS_HOURS_ALARM 5 // R/W Range 1..12 or 0..23 Bit= 7 is AM/PM +#define RTC_ADDRESS_DAY_OF_THE_WEEK 6 // R/W Range 1..7 +#define RTC_ADDRESS_DAY_OF_THE_MONTH 7 // R/W Range 1..31 +#define RTC_ADDRESS_MONTH 8 // R/W Range 1..12 +#define RTC_ADDRESS_YEAR 9 // R/W Range 0..99 +#define RTC_ADDRESS_REGISTER_A 10 // R/W[0..6] R0[7] +#define RTC_ADDRESS_REGISTER_B 11 // R/W +#define RTC_ADDRESS_REGISTER_C 12 // RO +#define RTC_ADDRESS_REGISTER_D 13 // RO +// +// Date and time initial values. +// They are used if the RTC values are invalid during driver initialization +// +#define RTC_INIT_SECOND 0 +#define RTC_INIT_MINUTE 0 +#define RTC_INIT_HOUR 0 +#define RTC_INIT_DAY 1 +#define RTC_INIT_MONTH 1 + +#pragma pack(1) +// +// Register A +// +typedef struct { + UINT8 Rs : 4; // Rate Selection Bits + UINT8 Dv : 3; // Divisor + UINT8 Uip : 1; // Update in progress +} RTC_REGISTER_A_BITS; + +typedef union { + RTC_REGISTER_A_BITS Bits; + UINT8 Data; +} RTC_REGISTER_A; + +// +// Register B +// +typedef struct { + UINT8 Dse : 1; // 0 - Daylight saving disabled 1 - Daylight savings= enabled + UINT8 Mil : 1; // 0 - 12 hour mode 1 - 24 hour mode + UINT8 Dm : 1; // 0 - BCD Format 1 - Binary Format + UINT8 Sqwe : 1; // 0 - Disable SQWE output 1 - Enable SQWE outp= ut + UINT8 Uie : 1; // 0 - Update INT disabled 1 - Update INT enabl= ed + UINT8 Aie : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled + UINT8 Pie : 1; // 0 - Periodic INT disabled 1 - Periodic INT Ena= bled + UINT8 Set : 1; // 0 - Normal operation. 1 - Updates inhibited +} RTC_REGISTER_B_BITS; + +typedef union { + RTC_REGISTER_B_BITS Bits; + UINT8 Data; +} RTC_REGISTER_B; + +// +// Register C +// +typedef struct { + UINT8 Reserved : 4; // Read as zero. Can not be written. + UINT8 Uf : 1; // Update End Interrupt Flag + UINT8 Af : 1; // Alarm Interrupt Flag + UINT8 Pf : 1; // Periodic Interrupt Flag + UINT8 Irqf : 1; // Iterrupt Request Flag =3D PF & PIE | AF & AIE = | UF & UIE +} RTC_REGISTER_C_BITS; + +typedef union { + RTC_REGISTER_C_BITS Bits; + UINT8 Data; +} RTC_REGISTER_C; + +// +// Register D +// +typedef struct { + UINT8 Reserved : 7; // Read as zero. Can not be written. + UINT8 Vrt : 1; // Valid RAM and Time +} RTC_REGISTER_D_BITS; + +typedef union { + RTC_REGISTER_D_BITS Bits; + UINT8 Data; +} RTC_REGISTER_D; + +#pragma pack() + +/** + Initialize RTC. + + @param Global For global use inside this module. + + @retval EFI_DEVICE_ERROR Initialization failed due to device error. + @retval EFI_SUCCESS Initialization successful. + +**/ +EFI_STATUS +PcRtcInit ( + IN PC_RTC_MODULE_GLOBALS *Global + ); + +/** + Sets the current local time and date information. + + @param Time A pointer to the current time. + @param Global For global use inside this module. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The time could not be set due due to hardw= are error. + +**/ +EFI_STATUS +PcRtcSetTime ( + IN EFI_TIME *Time, + IN PC_RTC_MODULE_GLOBALS *Global + ); + +/** + Returns the current time and date information, and the time-keeping capa= bilities + of the hardware platform. + + @param Time A pointer to storage to receive a snapshot of the = current time. + @param Capabilities An optional pointer to a buffer to receive the rea= l time clock + device's capabilities. + @param Global For global use inside this module. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to ha= rdware error. + +**/ +EFI_STATUS +PcRtcGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities, OPTIONAL + IN PC_RTC_MODULE_GLOBALS *Global + ); + +/** + Sets the system wakeup alarm clock time. + + @param Enabled Enable or disable the wakeup alarm. + @param Time If Enable is TRUE, the time to set the wakeup alarm for. + If Enable is FALSE, then this parameter is optional, an= d may be NULL. + @param Global For global use inside this module. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm w= as enabled. + If Enable is FALSE, then the wakeup alarm = was disabled. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a = hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this pl= atform. + +**/ +EFI_STATUS +PcRtcSetWakeupTime ( + IN BOOLEAN Enable, + IN EFI_TIME *Time, OPTIONAL + IN PC_RTC_MODULE_GLOBALS *Global + ); + +/** + Returns the current wakeup alarm clock setting. + + @param Enabled Indicates if the alarm is currently enabled or disabled. + @param Pending Indicates if the alarm signal is pending and requires a= cknowledgement. + @param Time The current alarm setting. + @param Global For global use inside this module. + + @retval EFI_SUCCESS The alarm settings were returned. + @retval EFI_INVALID_PARAMETER Enabled is NULL. + @retval EFI_INVALID_PARAMETER Pending is NULL. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due= to a hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this pl= atform. + +**/ +EFI_STATUS +PcRtcGetWakeupTime ( + OUT BOOLEAN *Enabled, + OUT BOOLEAN *Pending, + OUT EFI_TIME *Time, + IN PC_RTC_MODULE_GLOBALS *Global + ); + +/** + The user Entry Point for PcRTC module. + + This is the entrhy point for PcRTC module. It installs the UEFI runtime = service + including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime(). + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Others Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +InitializePcRtc ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + See if all fields of a variable of EFI_TIME type is correct. + + @param Time The time to be checked. + + @retval EFI_INVALID_PARAMETER Some fields of Time are not correct. + @retval EFI_SUCCESS Time is a valid EFI_TIME variable. + +**/ +EFI_STATUS +RtcTimeFieldsValid ( + IN EFI_TIME *Time + ); + +/** + Converts time from EFI_TIME format defined by UEFI spec to RTC's. + + This function converts time from EFI_TIME format defined by UEFI spec to= RTC's. + If data mode of RTC is BCD, then converts EFI_TIME to it. + If RTC is in 12-hour format, then converts EFI_TIME to it. + + @param Time On input, the time data read from UEFI to convert + On output, the time converted to RTC format + @param RegisterB Value of Register B of RTC, indicating data mode +**/ +VOID +ConvertEfiTimeToRtcTime ( + IN OUT EFI_TIME *Time, + IN RTC_REGISTER_B RegisterB + ); + +/** + Converts time read from RTC to EFI_TIME format defined by UEFI spec. + + This function converts raw time data read from RTC to the EFI_TIME format + defined by UEFI spec. + If data mode of RTC is BCD, then converts it to decimal, + If RTC is in 12-hour format, then converts it to 24-hour format. + + @param Time On input, the time data read from RTC to convert + On output, the time converted to UEFI format + @param RegisterB Value of Register B of RTC, indicating data mode + and hour format. + + @retval EFI_INVALID_PARAMETER Parameters passed in are invalid. + @retval EFI_SUCCESS Convert RTC time to EFI time successfull= y. + +**/ +EFI_STATUS +ConvertRtcTimeToEfiTime ( + IN OUT EFI_TIME *Time, + IN RTC_REGISTER_B RegisterB + ); + +/** + Wait for a period for the RTC to be ready. + + @param Timeout Tell how long it should take to wait. + + @retval EFI_DEVICE_ERROR RTC device error. + @retval EFI_SUCCESS RTC is updated and ready. +**/ +EFI_STATUS +RtcWaitToUpdate ( + UINTN Timeout + ); + +/** + See if field Day of an EFI_TIME is correct. + + @param Time Its Day field is to be checked. + + @retval TRUE Day field of Time is correct. + @retval FALSE Day field of Time is NOT correct. +**/ +BOOLEAN +DayValid ( + IN EFI_TIME *Time + ); + +/** + Check if it is a leapyear. + + @param Time The time to be checked. + + @retval TRUE It is a leapyear. + @retval FALSE It is NOT a leapyear. +**/ +BOOLEAN +IsLeapYear ( + IN EFI_TIME *Time + ); + +/** + Get the century RTC address from the ACPI FADT table. + + @return The century RTC address or 0 if not found. +**/ +UINT8 +GetCenturyRtcAddress ( + VOID + ); + +/** + Notification function of ACPI Table change. + + This is a notification function registered on ACPI Table change event. + It saves the Century address stored in ACPI FADT table. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context. + +**/ +VOID +EFIAPI +PcRtcAcpiTableChangeCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ); + +#endif diff --git a/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRea= lTimeClockRuntimeDxe/PcRtc.uni b/Platform/AMD/VanGoghBoard/Override/edk2/Pc= AtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.uni new file mode 100644 index 0000000000..33d7211191 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRealTimeCl= ockRuntimeDxe/PcRtc.uni @@ -0,0 +1,17 @@ +// /** @file +// PcRtc driver to install EFI_REAL_TIME_CLOCK_ARCH_PROTOCOL +// This driver provides GetTime, SetTime, GetWakeupTime, SetWakeupTime ser= vices to Runtime Service Table. +// It will install a tagging protocol with gEfiRealTimeClockArchProtocolGu= id. +// +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "PcRtc driver to i= nstall EFI_REAL_TIME_CLOCK_ARCH_PROTOCOL" + +#string STR_MODULE_DESCRIPTION #language en-US "This driver provi= des GetTime, SetTime, GetWakeupTime, SetWakeupTime services to Runtime Serv= ice Table. It will install a tagging protocol with gEfiRealTimeClockArchPro= tocolGuid." + diff --git a/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRea= lTimeClockRuntimeDxe/PcRtcEntry.c b/Platform/AMD/VanGoghBoard/Override/edk2= /PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c new file mode 100644 index 0000000000..9ac9914fb2 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRealTimeCl= ockRuntimeDxe/PcRtcEntry.c @@ -0,0 +1,171 @@ +/** @file + Provides Set/Get time operations. + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "PcRtc.h" + +PC_RTC_MODULE_GLOBALS mModuleGlobal; + +EFI_HANDLE mHandle =3D NULL; + +/** + Returns the current time and date information, and the time-keeping capa= bilities + of the hardware platform. + + @param Time A pointer to storage to receive a snapshot of the = current time. + @param Capabilities An optional pointer to a buffer to receive the rea= l time + clock device's capabilities. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to ha= rdware error. + +**/ +EFI_STATUS +EFIAPI +PcRtcEfiGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL + ) +{ + return PcRtcGetTime (Time, Capabilities, &mModuleGlobal); +} + +/** + Sets the current local time and date information. + + @param Time A pointer to the current time. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The time could not be set due due to hard= ware error. + +**/ +EFI_STATUS +EFIAPI +PcRtcEfiSetTime ( + IN EFI_TIME *Time + ) +{ + return PcRtcSetTime (Time, &mModuleGlobal); +} + +/** + Returns the current wakeup alarm clock setting. + + @param Enabled Indicates if the alarm is currently enabled or disabled. + @param Pending Indicates if the alarm signal is pending and requires a= cknowledgement. + @param Time The current alarm setting. + + @retval EFI_SUCCESS The alarm settings were returned. + @retval EFI_INVALID_PARAMETER Enabled is NULL. + @retval EFI_INVALID_PARAMETER Pending is NULL. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due= to a hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this pl= atform. + +**/ +EFI_STATUS +EFIAPI +PcRtcEfiGetWakeupTime ( + OUT BOOLEAN *Enabled, + OUT BOOLEAN *Pending, + OUT EFI_TIME *Time + ) +{ + return PcRtcGetWakeupTime (Enabled, Pending, Time, &mModuleGlobal); +} + +/** + Sets the system wakeup alarm clock time. + + @param Enabled Enable or disable the wakeup alarm. + @param Time If Enable is TRUE, the time to set the wakeup alarm for. + If Enable is FALSE, then this parameter is optional, an= d may be NULL. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm = was enabled. + If Enable is FALSE, then the wakeup alarm= was disabled. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a= hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this p= latform. + +**/ +EFI_STATUS +EFIAPI +PcRtcEfiSetWakeupTime ( + IN BOOLEAN Enabled, + IN EFI_TIME *Time OPTIONAL + ) +{ + return PcRtcSetWakeupTime (Enabled, Time, &mModuleGlobal); +} + +/** + The user Entry Point for PcRTC module. + + This is the entrhy point for PcRTC module. It installs the UEFI runtime = service + including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime(). + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Others Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +InitializePcRtc ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT Event; + + EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK); + mModuleGlobal.CenturyRtcAddress =3D GetCenturyRtcAddress (); + + Status =3D PcRtcInit (&mModuleGlobal); + ASSERT_EFI_ERROR (Status); + + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + PcRtcAcpiTableChangeCallback, + NULL, + &gEfiAcpi10TableGuid, + &Event + ); + ASSERT_EFI_ERROR (Status); + + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + PcRtcAcpiTableChangeCallback, + NULL, + &gEfiAcpiTableGuid, + &Event + ); + ASSERT_EFI_ERROR (Status); + + gRT->GetTime =3D PcRtcEfiGetTime; + gRT->SetTime =3D PcRtcEfiSetTime; + gRT->GetWakeupTime =3D PcRtcEfiGetWakeupTime; + gRT->SetWakeupTime =3D PcRtcEfiSetWakeupTime; + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &mHandle, + &gEfiRealTimeClockArchProtocolGuid, + NULL, + NULL + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRea= lTimeClockRuntimeDxe/PcRtcExtra.uni b/Platform/AMD/VanGoghBoard/Override/ed= k2/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcExtra.uni new file mode 100644 index 0000000000..59f4ed64d1 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRealTimeCl= ockRuntimeDxe/PcRtcExtra.uni @@ -0,0 +1,15 @@ +// /** @file +// PcRtc Extra Localized Strings and Content +// +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US +"PCAT Real Time Clock DXE Driver" + + diff --git a/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRea= lTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf b/Platform/AMD/VanGogh= Board/Override/edk2/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTime= ClockRuntimeDxe.inf new file mode 100644 index 0000000000..99818777c8 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Override/edk2/PcAtChipsetPkg/PcatRealTimeCl= ockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf @@ -0,0 +1,77 @@ +## @file +# Pcat RealTimeClock Runtime Dxe +# This driver provides GetTime, SetTime, GetWakeupTime, SetWakeupTime serv= ices to Runtime Service Table. +# It will install a tagging protocol with gEfiRealTimeClockArchProtocolGui= d. +# +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PcRtc + MODULE_UNI_FILE =3D PcRtc.uni + FILE_GUID =3D 378D7B65-8DA9-4773-B6E4-A47826A833E1 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializePcRtc + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + PcRtcEntry.c + PcRtc.c + PcRtc.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + PcAtChipsetPkg/PcAtChipsetPkg.dec + +[LibraryClasses] + UefiRuntimeServicesTableLib + UefiRuntimeLib + UefiBootServicesTableLib + UefiDriverEntryPoint + TimerLib + IoLib + BaseMemoryLib + UefiLib + DebugLib + BaseLib + PcdLib + ReportStatusCodeLib + +[Protocols] + gEfiRealTimeClockArchProtocolGuid ## PRODUCES + +[Guids] + ## SOMETIMES_CONSUMES ## Event + ## SOMETIMES_CONSUMES ## SystemTable + gEfiAcpi10TableGuid + + ## SOMETIMES_CONSUMES ## Event + ## SOMETIMES_CONSUMES ## SystemTable + gEfiAcpiTableGuid + +[FixedPcd] + gPcAtChipsetPkgTokenSpaceGuid.PcdInitialValueRtcRegisterA ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdInitialValueRtcRegisterB ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdInitialValueRtcRegisterD ## CONSUMES + +[Pcd] + gPcAtChipsetPkgTokenSpaceGuid.PcdRealTimeClockUpdateTimeout ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdMinimalValidYear ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdMaximalValidYear ## CONSUMES + +[Depex] + gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid + +[UserExtensions.TianoCore."ExtraFiles"] + PcRtcExtra.uni -- 2.31.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114511): https://edk2.groups.io/g/devel/message/114511 Mute This Topic: https://groups.io/mt/103971408/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-