From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 57F8A2238B58E for ; Thu, 25 Jan 2018 21:51:57 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 21:57:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,415,1511856000"; d="scan'208";a="13184768" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga008.jf.intel.com with ESMTP; 25 Jan 2018 21:57:26 -0800 Received: from fmsmsx114.amr.corp.intel.com (10.18.116.8) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 25 Jan 2018 21:57:26 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX114.amr.corp.intel.com (10.18.116.8) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 25 Jan 2018 21:57:25 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.192]) with mapi id 14.03.0319.002; Fri, 26 Jan 2018 13:57:24 +0800 From: "Zeng, Star" To: "Gao, Liming" , "edk2-devel@lists.01.org" CC: "Zeng, Star" Thread-Topic: [edk2] [PATCH v2] PcAtChipsetPkg: Add PeiAcpiTimerLib to save PerformanceCounterFrequency in HOB Thread-Index: AQHTk/FGbxQ/UFP2Kk+9aFkOaR8jvKOFrGvw Date: Fri, 26 Jan 2018 05:57:24 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BA13D1B@shsmsx102.ccr.corp.intel.com> References: <20180123022404.17360-1-liming.gao@intel.com> In-Reply-To: <20180123022404.17360-1-liming.gao@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2] PcAtChipsetPkg: Add PeiAcpiTimerLib to save PerformanceCounterFrequency in HOB X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Jan 2018 05:51:57 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Liming, Reviewed-by: Star Zeng Two minor comments. Just for your information. 1. Notice the title, it may be too long. 2. In PeiAcpiTimerLib.c, you may need to add ASSERT (PerformanceCounterFreq= uency !=3D NULL) after BuildGuidHob. And you can move " PerformanceCounterFrequency =3D (UINT64*)GET_GUID_HOB_DA= TA (GuidHob); " to the else condition, then only one "return" is needed. + PerformanceCounterFrequency =3D NULL; + GuidHob =3D GetFirstGuidHob (&mFrequencyHobGuid); + if (GuidHob =3D=3D NULL) { + PerformanceCounterFrequency =3D (UINT64*)BuildGuidHob(&mFrequencyHobG= uid, sizeof (*PerformanceCounterFrequency)); + *PerformanceCounterFrequency =3D InternalCalculateTscFrequency (); + return *PerformanceCounterFrequency; + } + PerformanceCounterFrequency =3D (UINT64*)GET_GUID_HOB_DATA (GuidHob); + + return *PerformanceCounterFrequency; +} Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Limi= ng Gao Sent: Tuesday, January 23, 2018 10:24 AM To: edk2-devel@lists.01.org Cc: Zeng, Star Subject: [edk2] [PATCH v2] PcAtChipsetPkg: Add PeiAcpiTimerLib to save Perf= ormanceCounterFrequency in HOB In V2: 1) Update PeiAcpiTimerLib base name to PeiAcpiTimerLib 2) Update PeiAcpiTimerLib to add the missing constructor to enable ACPI IO = space 3) Update DxeAcpiTimerLib to cache frequency in constructor. PeiAcpiTimerLib caches PerformanceCounterFrequency in HOB, then Pei and Dxe AcpiTimerLib can share the same PerformanceCounterFrequency. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao Cc: Star Zeng --- PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c | 4 +- .../Library/AcpiTimerLib/DxeAcpiTimerLib.c | 57 +++++++++++++++++- .../Library/AcpiTimerLib/DxeAcpiTimerLib.inf | 7 ++- .../Library/AcpiTimerLib/PeiAcpiTimerLib.c | 68 ++++++++++++++++++= ++++ .../Library/AcpiTimerLib/PeiAcpiTimerLib.inf | 56 ++++++++++++++++++ .../Library/AcpiTimerLib/PeiAcpiTimerLib.uni | 23 ++++++++ PcAtChipsetPkg/PcAtChipsetPkg.dsc | 4 +- 7 files changed, 211 insertions(+), 8 deletions(-) create mode 100644 PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c create mode 100644 PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf create mode 100644 PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c b/PcAtChips= etPkg/Library/AcpiTimerLib/AcpiTimerLib.c index 792781a33f..2f3cb4bca4 100644 --- a/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c @@ -1,7 +1,7 @@ /** @file ACPI Timer implements one instance of Timer Library. =20 - Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -21,6 +21,8 @@ #include #include =20 +GUID mFrequencyHobGuid =3D { 0x3fca54f6, 0xe1a2, 0x4b20, { 0xbe, 0x76, 0x9= 2, 0x6b, 0x4b, 0x48, 0xbf, 0xaa }}; + /** Internal function to retrieves the 64-bit frequency in Hz. =20 diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtCh= ipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c index b141c680fb..67e18a1360 100644 --- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c @@ -12,9 +12,27 @@ =20 **/ =20 -#include +#include #include #include +#include + +extern GUID mFrequencyHobGuid; + +/** + The constructor function enables ACPI IO space. + + If ACPI I/O space not enabled, this function will enable it. + It will always return RETURN_SUCCESS. + + @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. + +**/ +RETURN_STATUS +EFIAPI +AcpiTimerLibConstructor ( + VOID + ); =20 /** Calculate TSC frequency. @@ -54,8 +72,41 @@ InternalGetPerformanceCounterFrequency ( VOID )=20 { - if (mPerformanceCounterFrequency =3D=3D 0) { + return mPerformanceCounterFrequency; +} + +/** + The constructor function enables ACPI IO space, and caches PerformanceCo= unterFrequency.=20 + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +DxeAcpiTimerLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + + // + // Enable ACPI IO space. + // + AcpiTimerLibConstructor (); + + // + // Initialize PerformanceCounterFrequency + // + GuidHob =3D GetFirstGuidHob (&mFrequencyHobGuid); + if (GuidHob !=3D NULL) { + mPerformanceCounterFrequency =3D *(UINT64*)GET_GUID_HOB_DATA (GuidHob)= ; + } else { mPerformanceCounterFrequency =3D InternalCalculateTscFrequency (); } - return mPerformanceCounterFrequency; + + return EFI_SUCCESS; } diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAt= ChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf index 2c1cc7d33c..601041c801 100644 --- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf @@ -7,7 +7,7 @@ # Note: The implementation uses the lower 24-bits of the ACPI timer and # is compatible with both 24-bit and 32-bit ACPI timers. # -# Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the B= SD License # which accompanies this distribution. The full text of the license may = be found at @@ -22,10 +22,10 @@ INF_VERSION =3D 0x00010005 BASE_NAME =3D DxeAcpiTimerLib FILE_GUID =3D E624B98C-845A-4b94-9B50-B20475D552B9 - MODULE_TYPE =3D BASE + MODULE_TYPE =3D DXE_DRIVER VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D TimerLib|DXE_CORE DXE_DRIVER DXE_RUNT= IME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE - CONSTRUCTOR =3D AcpiTimerLibConstructor + CONSTRUCTOR =3D DxeAcpiTimerLibConstructor MODULE_UNI_FILE =3D DxeAcpiTimerLib.uni =20 [Sources] @@ -42,6 +42,7 @@ PciLib IoLib DebugLib + HobLib =20 [Pcd] gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSU= MES diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c b/PcAtCh= ipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c new file mode 100644 index 0000000000..a4ed6a4434 --- /dev/null +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c @@ -0,0 +1,68 @@ +/** @file + ACPI Timer implements one instance of Timer Library. + + Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include +#include +#include +#include + +extern GUID mFrequencyHobGuid; + +/** + Calculate TSC frequency. + + The TSC counting frequency is determined by comparing how far it counts + during a 101.4 us period as determined by the ACPI timer. + The ACPI timer is used because it counts at a known frequency. + The TSC is sampled, followed by waiting 363 counts of the ACPI timer, + or 101.4 us. The TSC is then sampled again. The difference multiplied by + 9861 is the TSC frequency. There will be a small error because of the + overhead of reading the ACPI timer. An attempt is made to determine and + compensate for this error. + + @return The number of TSC counts per second. + +**/ +UINT64 +InternalCalculateTscFrequency ( + VOID + ); + +/** + Internal function to retrieves the 64-bit frequency in Hz. + + Internal function to retrieves the 64-bit frequency in Hz. + + @return The frequency in Hz. + +**/ +UINT64 +InternalGetPerformanceCounterFrequency ( + VOID + ) +{ + UINT64 *PerformanceCounterFrequency; + EFI_HOB_GUID_TYPE *GuidHob; + + PerformanceCounterFrequency =3D NULL; + GuidHob =3D GetFirstGuidHob (&mFrequencyHobGuid); + if (GuidHob =3D=3D NULL) { + PerformanceCounterFrequency =3D (UINT64*)BuildGuidHob(&mFrequencyHobG= uid, sizeof (*PerformanceCounterFrequency)); + *PerformanceCounterFrequency =3D InternalCalculateTscFrequency (); + return *PerformanceCounterFrequency; + } + PerformanceCounterFrequency =3D (UINT64*)GET_GUID_HOB_DATA (GuidHob); + + return *PerformanceCounterFrequency; +} diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf b/PcAt= ChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf new file mode 100644 index 0000000000..1d8c95a3ec --- /dev/null +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf @@ -0,0 +1,56 @@ +## @file +# PEI ACPI Timer Library +# +# Provides basic timer support using the ACPI timer hardware. The perfor= mance +# counter features are provided by the processors time stamp counter. +# +# Note: The implementation uses the lower 24-bits of the ACPI timer and +# is compatible with both 24-bit and 32-bit ACPI timers. +# +# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PeiAcpiTimerLib + FILE_GUID =3D 3FCA54F6-E1A2-4B20-BE76-926B4B48BFAA + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TimerLib|PEI_CORE PEIM + CONSTRUCTOR =3D AcpiTimerLibConstructor + MODULE_UNI_FILE =3D PeiAcpiTimerLib.uni + +[Sources] + AcpiTimerLib.c + PeiAcpiTimerLib.c + +[Packages] + MdePkg/MdePkg.dec + PcAtChipsetPkg/PcAtChipsetPkg.dec + +[LibraryClasses] + BaseLib + PcdLib + PciLib + IoLib + DebugLib + HobLib + +[Pcd] + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSU= MES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciDeviceNumber ## CONSU= MES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciFunctionNumber ## CONSU= MES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciEnableRegisterOffset ## CONSU= MES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoBarEnableMask ## CONSU= MES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBarRegisterOffset ## CONSU= MES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddress ## CONSU= MES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiPm1TmrOffset ## CONSU= MES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddressMask ## CONSU= MES diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni b/PcAt= ChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni new file mode 100644 index 0000000000..668161b14a --- /dev/null +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni @@ -0,0 +1,23 @@ +// /** @file +// PEI ACPI Timer Library +// +// Provides basic timer support using the ACPI timer hardware. The perfor= mance +// counter features are provided by the processors time stamp counter. +// +// Copyright (c) 2018, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD License +// which accompanies this distribution. The full text of the license may = be found at +// http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "ACPI Timer Librar= y" + +#string STR_MODULE_DESCRIPTION #language en-US "Provides basic ti= mer support using the ACPI timer hardware." + diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipset= Pkg.dsc index b740f00e63..2395e9cf26 100644 --- a/PcAtChipsetPkg/PcAtChipsetPkg.dsc +++ b/PcAtChipsetPkg/PcAtChipsetPkg.dsc @@ -1,7 +1,7 @@ ## @file # PC/AT Chipset Package # -# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the B= SD License @@ -46,6 +46,7 @@ IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseRepor= tStatusCodeLibNull.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf =20 [Components] PcAtChipsetPkg/8254TimerDxe/8254Timer.inf @@ -57,6 +58,7 @@ PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf + PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.i= nf =20 [BuildOptions] --=20 2.11.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel