From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (EUR02-HE1-obe.outbound.protection.outlook.com [40.107.1.89]) by mx.groups.io with SMTP id smtpd.web11.13560.1593005712969325109 for ; Wed, 24 Jun 2020 06:35:14 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=yLBI9L2c; spf=pass (domain: arm.com, ip: 40.107.1.89, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wRvPTbSW6GATa7UeGE1oHx1d8D3NB2Ex5DDqdVOMIFI=; b=yLBI9L2c3WEv3j9K+SrCBY4hBgQVkUDEmn0cGddzf8jWcatSyFQCV0Q8OspMsFUZeUJrblNUsK1+v6AMKzKYVn7DwyxAszCq5cDc+OwlmT0QVk325mHe21yjft7UCkS0O05CVtsCFPkL/LHI1hMtI7uQw3bqe90rU44Xkdazk6A= Received: from AM6P195CA0012.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:81::25) by AM4PR08MB2852.eurprd08.prod.outlook.com (2603:10a6:205:e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.26; Wed, 24 Jun 2020 13:35:10 +0000 Received: from AM5EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:81:cafe::f) by AM6P195CA0012.outlook.office365.com (2603:10a6:209:81::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Wed, 24 Jun 2020 13:35:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT064.mail.protection.outlook.com (10.152.17.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Wed, 24 Jun 2020 13:35:09 +0000 Received: ("Tessian outbound da41658aa5d4:v59"); Wed, 24 Jun 2020 13:35:09 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 618613406a851a1e X-CR-MTA-TID: 64aa7808 Received: from 0d99594e3aa2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E682D425-02EA-4803-958D-31201ED7ACE9.1; Wed, 24 Jun 2020 13:35:04 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 0d99594e3aa2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 24 Jun 2020 13:35:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gr1I77sKEycGvdc1X++MDo9kZq7quUeGaC8sPxV6MdVEnw1zkgg3euwd0dCwXVuz2RHRH6iv9e/uyB3shZgtDFyWRNWQDwMfaMoPSCyibYD7D4Kwppp1RQQH4yENsY9z5/Hi8kVR4V0zMAyrJjTsi1sm1iMvk71/22YZ9Fe2ZVAjt8wOa4W5b7I8wI6Af5aN2jG0Qa1NpGAXoLVmQAWcM/rmn2iUfeN7oqvvTpU7QStFJ0cVnrpe5iBO9pQ2mARwJJYGz+YM/uQD65Gbgi45pEV1uFgY9CzCGEbqLDijOBs0rRD+05CjxnaggFdhUP3CbVR+MUolmBwe9ThrwDGQWw== 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=wRvPTbSW6GATa7UeGE1oHx1d8D3NB2Ex5DDqdVOMIFI=; b=MFf5iWdVblbmdggrri8Xo9UkbRO2cajWIEL7/uZw1e2IEeRqmGMvD/v2YItvXcZSQT5oiEATxTl+Sf59H8XudJQACJUUalR5OM2p4pZbQIv7OF2BNUUn0j2XT8E5Hzgz8gXnR/tN87hya/ora0CDLLcPFoB/y2O+BKagLDBNmh+7DQIoQ1r0xyEc+Sm0fZRqmX+0yryyWkh+r7JHwpgcVrts78milGcuT/KtogeY3Ojk6P6qdwS0kXAX0l6fLHBB06z3O8Pq/akzrQ7W9DIeCMIPnSckOO5jWNIwH3lFCLSIB6d5LTVrprMFXMVr80/xAvkpqBWLRDRpuxmI+MvB6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wRvPTbSW6GATa7UeGE1oHx1d8D3NB2Ex5DDqdVOMIFI=; b=yLBI9L2c3WEv3j9K+SrCBY4hBgQVkUDEmn0cGddzf8jWcatSyFQCV0Q8OspMsFUZeUJrblNUsK1+v6AMKzKYVn7DwyxAszCq5cDc+OwlmT0QVk325mHe21yjft7UCkS0O05CVtsCFPkL/LHI1hMtI7uQw3bqe90rU44Xkdazk6A= Received: from AM5PR0601CA0067.eurprd06.prod.outlook.com (2603:10a6:206::32) by AM6PR08MB5190.eurprd08.prod.outlook.com (2603:10a6:20b:e8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21; Wed, 24 Jun 2020 13:35:02 +0000 Received: from AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:0:cafe::9c) by AM5PR0601CA0067.outlook.office365.com (2603:10a6:206::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21 via Frontend Transport; Wed, 24 Jun 2020 13:35:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT039.mail.protection.outlook.com (10.152.17.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3131.20 via Frontend Transport; Wed, 24 Jun 2020 13:35:02 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Wed, 24 Jun 2020 13:35:01 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1779.2; Wed, 24 Jun 2020 13:35:00 +0000 Received: from E107187.Arm.com (10.57.22.181) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Wed, 24 Jun 2020 13:34:59 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , Subject: [PATCH v3 01/15] PcAtChipsetPkg: Add MMIO Support to RTC driver Date: Wed, 24 Jun 2020 14:34:44 +0100 Message-ID: <20200624133458.61920-2-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20200624133458.61920-1-sami.mujawar@arm.com> References: <20200624133458.61920-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(6029001)(4636009)(346002)(39860400002)(136003)(376002)(396003)(46966005)(356005)(83380400001)(44832011)(26005)(82310400002)(4326008)(7696005)(36756003)(81166007)(478600001)(966005)(186003)(70586007)(2906002)(426003)(70206006)(2616005)(316002)(54906003)(82740400003)(336012)(47076004)(30864003)(6666004)(6916009)(5660300002)(1076003)(19627235002)(8676002)(86362001)(8936002);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fba8db3-85d9-4d98-05cc-08d818436a5f X-MS-TrafficTypeDiagnostic: AM6PR08MB5190:|AM4PR08MB2852: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:4941;OLM:4941; X-Forefront-PRVS: 0444EB1997 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: SYkQngdeH/KmJuYzPh9hyAeLyNj/RfnmwkN4D7QARf9CTBSbZW2Dx7XjyqXdhUhPFQyRkA0Xg7o6ZMkp/TFjUcd22fCmQybaEcZQsq0E4sLAviVFFI8W9/TePxdAX8OVvmjWn23yWL0k9PBUvC072jniRKq4OUBqFy3NDboLUM9ByCbzot7mS3sXfa0Vpw2WT4xytlkMLzey2xZe33Y66+WxwNjDSaIbWv1eQ6OToxCCZn+yGCHbnNQD6szzqVdN3eHmIEsY7edzwHeWQnSUC0cHE5djlmKCG4B9XwDS7/wFe8ryMk9KWIBmKnXsB6+RrWzpav0qmWQ1S85IgUuV7hEEgW+wxCtnLk+QhH+vUAiWH0jM2gf6S1I9qP/HRnEsR25CiDYY+HvOooHhdbhc3NW49mlE7n3y5G/tXHqR+iLb6YExCyekv/YenzLO4bkVAIwUEh7HwaITGeNygrMnnd9WVPWI5S2ndtPofLjSzdc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5190 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(6029001)(4636009)(136003)(396003)(376002)(346002)(39860400002)(46966005)(7696005)(2906002)(8676002)(186003)(6916009)(83380400001)(8936002)(82310400002)(36906005)(316002)(19627235002)(44832011)(1076003)(478600001)(426003)(6666004)(26005)(54906003)(30864003)(336012)(2616005)(70206006)(81166007)(82740400003)(5660300002)(47076004)(70586007)(966005)(86362001)(36756003)(4326008);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 308e3085-d65f-4ca9-1d41-08d8184365c4 X-Forefront-PRVS: 0444EB1997 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZmCLWP2dOoHYMjszw2bavL1C0f4++m1ArM8koDGWalKEkUOC9wQ7mBu2gVEsWDmemlZYAAsMzRrNxu9hP9D/9wwIw9Ihz0tu8ihu7L52gUZsNdVSmvLoAisgt0SGQOioaH86SP1RIBaztVLmBio0aFGOyb8s1OL7lNHLO87QuDJHNg3VWnxD2/UxChG+UCCZAPtSxtKXoWHnCefN47Zl9WF/aedYFjQ0SlG/LQVBpv0f89aQtMEtTPDDXrmDavn5tWAdk6orcmtvkn2okAKCWCou/D7n2UXXPN2SOKnlOtHgriq4Q7BN2TLdOmUr+ShhQ0+fdazRHFLFaYRetdYwEyXxEj2Cc5zU3CmkkMGSZMVzfAXopL8chHRHIIAxCzqrr5OvyCitm9zyE8cBcr2up1ECXFauXieiLlscyt3rFFeXC9jG+9GnNz/cgmtlNMzhVN2UcfnaTUH4JKBo6mpvmufPyDhpVeAcnv487mXrIqs= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2020 13:35:09.8643 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2fba8db3-85d9-4d98-05cc-08d818436a5f X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2852 Content-Type: text/plain Some virtual machine managers like Kvmtool emulate the MC146818 RTC controller in the MMIO space so that architectures that do not support I/O Mapped I/O can use the RTC. This patch adds MMIO support to the RTC controller driver. The PCD PcdRtcUseMmio has been added to select I/O or MMIO support. If PcdRtcUseMmio is: TRUE - Indicates the RTC port registers are in MMIO space. FALSE - Indicates the RTC port registers are in I/O space. Default is I/O space. Additionally two new PCDs PcdRtcIndexRegister64 and PcdRtcTargetRegister64 have been introduced to provide the base address for the RTC registers in the MMIO space. When MMIO support is selected (PcdRtcUseMmio == TRUE) the driver converts the pointers to the RTC MMIO registers so that the RTC registers are accessible post ExitBootServices. Signed-off-by: Sami Mujawar --- Notes: v3: - Make PcdRtcUseMmio a feature PCD. [Sami] - Read the RTC MMIO base address from the DT. [Andre] - Introduce PCDs for RTC Index and Target register base [Sami] address in the MMIO space. - Move RTC MMIO region mapping code to a separate platform [Sami] specific library. This library also reads the base addresses for the RTC from DT and configures the RTC Index and Target register PCDs. Ref: https://edk2.groups.io/g/devel/topic/74200905#60307 v2: - Code review comments incorporated. [Sami] v1: - Add support to read/write from RTC registers using MMIO access [Sami] - Use wrapper functions for RtcRead/Write accessors [Leif] Ref: https://edk2.groups.io/g/devel/topic/30915281#30695 PcAtChipsetPkg/PcAtChipsetPkg.dec | 16 +++ PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c | 119 +++++++++++++++++--- PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h | 31 +++++ PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c | 72 +++++++++++- PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf | 8 ++ 5 files changed, 230 insertions(+), 16 deletions(-) diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dec b/PcAtChipsetPkg/PcAtChipsetPkg.dec index 88de5cceea593176c3a2425a5963b66b789f2b9e..ed2d95550b8d153995b30cdc290cf3bb905e211b 100644 --- a/PcAtChipsetPkg/PcAtChipsetPkg.dec +++ b/PcAtChipsetPkg/PcAtChipsetPkg.dec @@ -6,6 +6,7 @@ # # Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.
# Copyright (c) 2017, AMD Inc. All rights reserved.
+# Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -41,6 +42,13 @@ [PcdsFeatureFlag] # @Prompt Configure HPET to use MSI. gPcAtChipsetPkgTokenSpaceGuid.PcdHpetMsiEnable|TRUE|BOOLEAN|0x00001000 + ## Indicates the RTC port registers are in MMIO space, or in I/O space. + # Default is I/O space.

+ # TRUE - RTC port registers are in MMIO space.
+ # FALSE - RTC port registers are in I/O space.
+ # @Prompt RTC port registers use MMIO. + gPcAtChipsetPkgTokenSpaceGuid.PcdRtcUseMmio|FALSE|BOOLEAN|0x00000021 + [PcdsFixedAtBuild, PcdsDynamic, PcdsDynamicEx, PcdsPatchableInModule] ## This PCD specifies the base address of the HPET timer. # @Prompt HPET base address. @@ -68,6 +76,14 @@ [PcdsFixedAtBuild, PcdsDynamic, PcdsDynamicEx, PcdsPatchableInModule] # @Expression 0x80000001 | gPcAtChipsetPkgTokenSpaceGuid.PcdMaximalValidYear < gPcAtChipsetPkgTokenSpaceGuid.PcdMinimalValidYear + 100 gPcAtChipsetPkgTokenSpaceGuid.PcdMaximalValidYear|2097|UINT16|0x0000000E + ## Specifies RTC Index Register address in MMIO space. + # @Prompt RTC Index Register address + gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister64|0x0|UINT64|0x00000022 + + ## Specifies RTC Target Register address in MMIO space. + # @Prompt RTC Target Register address + gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister64|0x0|UINT64|0x00000023 + [PcdsFixedAtBuild, PcdsPatchableInModule] ## Defines the ACPI register set base address. # The invalid 0xFFFF is as its default value. It must be configured to the real value. diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c index 52af17941786ef81c3911512ee64551724e67209..5ddc06549103ce9944054d3a05b73803f7037ec2 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c @@ -3,6 +3,7 @@ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Inc. All rights reserved.
+Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -10,6 +11,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "PcRtc.h" +extern UINTN mRtcIndexRegister; +extern UINTN mRtcTargetRegister; + // // Days of month. // @@ -21,6 +25,28 @@ UINTN mDayOfMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; CHAR16 mTimeZoneVariableName[] = L"RTC"; /** + A function pointer that evaluates to a function that reads the RTC content + through its registers either using IO or MMIO access. + + @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. +**/ +RTC_READ RtcRead; + +/** + A function pointer that evaluates to a function that reads the RTC content + through its registers either using IO or MMIO access. + + @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. +**/ +RTC_WRITE RtcWrite; + +/** 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. @@ -54,41 +80,96 @@ IsWithinOneDay ( ); /** - Read RTC content through its registers. + Read RTC content through its registers using IO access. - @param Address Address offset of RTC. It is recommended to use macros such as - RTC_ADDRESS_SECONDS. + @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. **/ +STATIC UINT8 -RtcRead ( - IN UINT8 Address +EFIAPI +IoRtcRead ( + IN UINTN Address ) { - IoWrite8 (PcdGet8 (PcdRtcIndexRegister), (UINT8) (Address | (UINT8) (IoRead8 (PcdGet8 (PcdRtcIndexRegister)) & 0x80))); + IoWrite8 ( + PcdGet8 (PcdRtcIndexRegister), + (UINT8)(Address | (UINT8)(IoRead8 (PcdGet8 (PcdRtcIndexRegister)) & 0x80)) + ); return IoRead8 (PcdGet8 (PcdRtcTargetRegister)); } /** - Write RTC through its registers. + Write RTC through its registers using IO access. - @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. + @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. **/ +STATIC VOID -RtcWrite ( - IN UINT8 Address, +EFIAPI +IoRtcWrite ( + IN UINTN Address, IN UINT8 Data ) { - IoWrite8 (PcdGet8 (PcdRtcIndexRegister), (UINT8) (Address | (UINT8) (IoRead8 (PcdGet8 (PcdRtcIndexRegister)) & 0x80))); + IoWrite8 ( + PcdGet8 (PcdRtcIndexRegister), + (UINT8)(Address | (UINT8)(IoRead8 (PcdGet8 (PcdRtcIndexRegister)) & 0x80)) + ); IoWrite8 (PcdGet8 (PcdRtcTargetRegister), Data); } /** + Read RTC content through its registers using MMIO access. + + @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. +**/ +STATIC +UINT8 +EFIAPI +MmioRtcRead ( + IN UINTN Address + ) +{ + MmioWrite8 ( + mRtcIndexRegister, + (UINT8)(Address | (UINT8)(MmioRead8 (mRtcIndexRegister) & 0x80)) + ); + return MmioRead8 (mRtcTargetRegister); +} + +/** + Write RTC through its registers using MMIO access. + + @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. + +**/ +STATIC +VOID +EFIAPI +MmioRtcWrite ( + IN UINTN Address, + IN UINT8 Data + ) +{ + MmioWrite8 ( + mRtcIndexRegister, + (UINT8)(Address | (UINT8)(MmioRead8 (mRtcIndexRegister) & 0x80)) + ); + MmioWrite8 (mRtcTargetRegister, Data); +} + +/** Initialize RTC. @param Global For global use inside this module. @@ -113,6 +194,18 @@ PcRtcInit ( BOOLEAN Pending; // + // Initialize the RtcRead and RtcWrite functions + // based on the chosen IO/MMIO access. + // + if (FeaturePcdGet (PcdRtcUseMmio)) { + RtcRead = MmioRtcRead; + RtcWrite = MmioRtcWrite; + } else { + RtcRead = IoRtcRead; + RtcWrite = IoRtcWrite; + } + + // // Acquire RTC Lock to make access to RTC atomic // if (!EfiAtRuntime ()) { diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h index 47293ce44c5a1f4792892892f7da40d7f0a5a001..4074261c2ca5dbc7b0727ea7961154eaf41c0e38 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.h @@ -3,6 +3,7 @@ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Inc. All rights reserved.
+Copyright (c) 2019 - 2020, ARM Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -371,4 +372,34 @@ PcRtcAcpiTableChangeCallback ( IN EFI_EVENT Event, IN VOID *Context ); + +/** + Function pointer 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. +**/ +typedef +UINT8 +(EFIAPI *RTC_READ) ( + IN UINTN Address + ); + +/** + Function pointer to 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. + +**/ +typedef +VOID +(EFIAPI *RTC_WRITE) ( + IN UINTN Address, + IN UINT8 Data + ); + #endif diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c index ccda6331373bfe4069b0a59495b5e5cc731c8fc8..e30883e53333aae655bbf891f86d1a6ed739715f 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c @@ -2,16 +2,33 @@ Provides Set/Get time operations. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include "PcRtc.h" PC_RTC_MODULE_GLOBALS mModuleGlobal; EFI_HANDLE mHandle = NULL; +STATIC EFI_EVENT mVirtualAddrChangeEvent; + +UINTN mRtcIndexRegister; +UINTN mRtcTargetRegister; + +// +// Function pointer for the Rtc Read interface function +// +extern RTC_READ RtcRead; + +// +// Function pointer for the Rtc Write interface function +// +extern RTC_WRITE RtcWrite; + /** Returns the current time and date information, and the time-keeping capabilities of the hardware platform. @@ -106,6 +123,34 @@ PcRtcEfiSetWakeupTime ( } /** + Fixup internal data so that EFI can be called in virtual mode. + Call the passed in Child Notify event and convert any pointers in + lib to virtual mode. + + @param[in] Event The Event that is being processed + @param[in] Context Event Context +**/ +VOID +EFIAPI +LibRtcVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // Only needed if you are going to support the OS calling RTC functions in + // virtual mode. You will need to call EfiConvertPointer (). To convert any + // stored physical addresses to virtual address. After the OS transitions to + // calling in virtual mode, all future runtime calls will be made in virtual + // mode. + EfiConvertPointer (0x0, (VOID**)&mRtcIndexRegister); + EfiConvertPointer (0x0, (VOID**)&mRtcTargetRegister); + + // Convert the RtcRead and RtcWrite pointers for runtime use. + EfiConvertPointer (0x0, (VOID**)&RtcRead); + EfiConvertPointer (0x0, (VOID**)&RtcWrite); +} + +/** The user Entry Point for PcRTC module. This is the entry point for PcRTC module. It installs the UEFI runtime service @@ -125,12 +170,17 @@ InitializePcRtc ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - EFI_EVENT Event; + EFI_STATUS Status; + EFI_EVENT Event; EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK); mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress (); + if (FeaturePcdGet (PcdRtcUseMmio)) { + mRtcIndexRegister = (UINTN)PcdGet64 (PcdRtcIndexRegister64); + mRtcTargetRegister = (UINTN)PcdGet64 (PcdRtcTargetRegister64); + } + Status = PcRtcInit (&mModuleGlobal); ASSERT_EFI_ERROR (Status); @@ -165,7 +215,23 @@ InitializePcRtc ( NULL, NULL ); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + if (FeaturePcdGet (PcdRtcUseMmio)) { + // Register for the virtual address change event + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + LibRtcVirtualNotifyEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mVirtualAddrChangeEvent + ); + ASSERT_EFI_ERROR (Status); + } return Status; } diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf index c73ee98105e510f9e4e23c1a6c1e5c505325d2c9..0d8eca28b65954b073a72fc4fe5ad6247320e79d 100644 --- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf +++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf @@ -6,6 +6,7 @@ # # Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
# Copyright (c) 2017, AMD Inc. All rights reserved.
+# Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -61,6 +62,11 @@ [Guids] ## SOMETIMES_CONSUMES ## SystemTable gEfiAcpiTableGuid + gEfiEventVirtualAddressChangeGuid + +[FeaturePcd] + gPcAtChipsetPkgTokenSpaceGuid.PcdRtcUseMmio ## CONSUMES + [FixedPcd] gPcAtChipsetPkgTokenSpaceGuid.PcdInitialValueRtcRegisterA ## CONSUMES gPcAtChipsetPkgTokenSpaceGuid.PcdInitialValueRtcRegisterB ## CONSUMES @@ -72,6 +78,8 @@ [Pcd] gPcAtChipsetPkgTokenSpaceGuid.PcdMaximalValidYear ## CONSUMES gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister ## CONSUMES gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister64 ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister64 ## CONSUMES [Depex] gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'