PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c | 4 +- .../Library/AcpiTimerLib/DxeAcpiTimerLib.c | 14 ++++- .../Library/AcpiTimerLib/DxeAcpiTimerLib.inf | 3 +- .../Library/AcpiTimerLib/PeiAcpiTimerLib.c | 68 ++++++++++++++++++++++ .../Library/AcpiTimerLib/PeiAcpiTimerLib.inf | 55 +++++++++++++++++ .../Library/AcpiTimerLib/PeiAcpiTimerLib.uni | 23 ++++++++ PcAtChipsetPkg/PcAtChipsetPkg.dsc | 4 +- 7 files changed, 166 insertions(+), 5 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
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 <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c | 4 +-
.../Library/AcpiTimerLib/DxeAcpiTimerLib.c | 14 ++++-
.../Library/AcpiTimerLib/DxeAcpiTimerLib.inf | 3 +-
.../Library/AcpiTimerLib/PeiAcpiTimerLib.c | 68 ++++++++++++++++++++++
.../Library/AcpiTimerLib/PeiAcpiTimerLib.inf | 55 +++++++++++++++++
.../Library/AcpiTimerLib/PeiAcpiTimerLib.uni | 23 ++++++++
PcAtChipsetPkg/PcAtChipsetPkg.dsc | 4 +-
7 files changed, 166 insertions(+), 5 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/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c
index 792781a..2f3cb4b 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.
- Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -21,6 +21,8 @@
#include <Library/DebugLib.h>
#include <IndustryStandard/Acpi.h>
+GUID mFrequencyHobGuid = { 0x3fca54f6, 0xe1a2, 0x4b20, { 0xbe, 0x76, 0x92, 0x6b, 0x4b, 0x48, 0xbf, 0xaa }};
+
/**
Internal function to retrieves the 64-bit frequency in Hz.
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
index b141c68..9b912c0 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
@@ -12,9 +12,12 @@
**/
-#include <Base.h>
+#include <PiDxe.h>
#include <Library/TimerLib.h>
#include <Library/BaseLib.h>
+#include <Library/HobLib.h>
+
+extern GUID mFrequencyHobGuid;
/**
Calculate TSC frequency.
@@ -54,8 +57,15 @@ InternalGetPerformanceCounterFrequency (
VOID
)
{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
if (mPerformanceCounterFrequency == 0) {
- mPerformanceCounterFrequency = InternalCalculateTscFrequency ();
+ GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
+ if (GuidHob != NULL) {
+ mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob);
+ } else {
+ mPerformanceCounterFrequency = InternalCalculateTscFrequency ();
+ }
}
return mPerformanceCounterFrequency;
}
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
index 2c1cc7d..307e3f9 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.<BR>
+# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -42,6 +42,7 @@
PciLib
IoLib
DebugLib
+ HobLib
[Pcd]
gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSUMES
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c
new file mode 100644
index 0000000..a4ed6a4
--- /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.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD 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 IMPLIED.
+
+**/
+
+#include <PiPei.h>
+#include <Library/TimerLib.h>
+#include <Library/BaseLib.h>
+#include <Library/HobLib.h>
+
+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 = NULL;
+ GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
+ if (GuidHob == NULL) {
+ PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));
+ *PerformanceCounterFrequency = InternalCalculateTscFrequency ();
+ return *PerformanceCounterFrequency;
+ }
+ PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob);
+
+ return *PerformanceCounterFrequency;
+}
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf
new file mode 100644
index 0000000..794d2a3
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf
@@ -0,0 +1,55 @@
+## @file
+# PEI ACPI Timer Library
+#
+# Provides basic timer support using the ACPI timer hardware. The performance
+# 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.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD 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 IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DxeAcpiTimerLib
+ FILE_GUID = 3FCA54F6-E1A2-4B20-BE76-926B4B48BFAA
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = TimerLib|PEI_CORE PEIM
+ MODULE_UNI_FILE = PeiAcpiTimerLib.uni
+
+[Sources]
+ AcpiTimerLib.c
+ PeiAcpiTimerLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ PcAtChipsetPkg/PcAtChipsetPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ PcdLib
+ PciLib
+ IoLib
+ DebugLib
+ HobLib
+
+[Pcd]
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSUMES
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciDeviceNumber ## CONSUMES
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciFunctionNumber ## CONSUMES
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciEnableRegisterOffset ## CONSUMES
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoBarEnableMask ## CONSUMES
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBarRegisterOffset ## CONSUMES
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddress ## CONSUMES
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiPm1TmrOffset ## CONSUMES
+ gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddressMask ## CONSUMES
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni
new file mode 100644
index 0000000..668161b
--- /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 performance
+// counter features are provided by the processors time stamp counter.
+//
+// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD 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 IMPLIED.
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "ACPI Timer Library"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Provides basic timer support using the ACPI timer hardware."
+
diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc
index b740f00..2395e9c 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.<BR>
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -46,6 +46,7 @@
IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf
LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
+ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
[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.inf
[BuildOptions]
--
2.8.0.windows.1
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
How could PeiAcpiTimerLib build pass with DxeHobLib Why the BASE_NAME is DxeAcpiTimerLib in PeiAcpiTimerLib.inf? Thanks, Star -----Original Message----- From: Gao, Liming Sent: Monday, January 22, 2018 1:39 PM To: edk2-devel@lists.01.org Cc: Zeng, Star <star.zeng@intel.com> Subject: [Patch] PcAtChipsetPkg: Add PeiAcpiTimerLib to save PerformanceCounterFrequency in HOB 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 <liming.gao@intel.com> Cc: Star Zeng <star.zeng@intel.com> --- PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c | 4 +- .../Library/AcpiTimerLib/DxeAcpiTimerLib.c | 14 ++++- .../Library/AcpiTimerLib/DxeAcpiTimerLib.inf | 3 +- .../Library/AcpiTimerLib/PeiAcpiTimerLib.c | 68 ++++++++++++++++++++++ .../Library/AcpiTimerLib/PeiAcpiTimerLib.inf | 55 +++++++++++++++++ .../Library/AcpiTimerLib/PeiAcpiTimerLib.uni | 23 ++++++++ PcAtChipsetPkg/PcAtChipsetPkg.dsc | 4 +- 7 files changed, 166 insertions(+), 5 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/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c index 792781a..2f3cb4b 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. - Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2013 - 2018, Intel Corporation. All rights + reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -21,6 +21,8 @@ #include <Library/DebugLib.h> #include <IndustryStandard/Acpi.h> +GUID mFrequencyHobGuid = { 0x3fca54f6, 0xe1a2, 0x4b20, { 0xbe, 0x76, +0x92, 0x6b, 0x4b, 0x48, 0xbf, 0xaa }}; + /** Internal function to retrieves the 64-bit frequency in Hz. diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c index b141c68..9b912c0 100644 --- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c @@ -12,9 +12,12 @@ **/ -#include <Base.h> +#include <PiDxe.h> #include <Library/TimerLib.h> #include <Library/BaseLib.h> +#include <Library/HobLib.h> + +extern GUID mFrequencyHobGuid; /** Calculate TSC frequency. @@ -54,8 +57,15 @@ InternalGetPerformanceCounterFrequency ( VOID ) { + EFI_HOB_GUID_TYPE *GuidHob; + if (mPerformanceCounterFrequency == 0) { - mPerformanceCounterFrequency = InternalCalculateTscFrequency (); + GuidHob = GetFirstGuidHob (&mFrequencyHobGuid); + if (GuidHob != NULL) { + mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob); + } else { + mPerformanceCounterFrequency = InternalCalculateTscFrequency (); + } } return mPerformanceCounterFrequency; } diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf index 2c1cc7d..307e3f9 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.<BR> +# Copyright (c) 2013 - 2018, Intel Corporation. All rights +reserved.<BR> # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -42,6 +42,7 @@ PciLib IoLib DebugLib + HobLib [Pcd] gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSUMES diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c new file mode 100644 index 0000000..a4ed6a4 --- /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.<BR> This program and the accompanying materials are + licensed and made available under the terms and conditions of the BSD + 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 IMPLIED. + +**/ + +#include <PiPei.h> +#include <Library/TimerLib.h> +#include <Library/BaseLib.h> +#include <Library/HobLib.h> + +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 = NULL; + GuidHob = GetFirstGuidHob (&mFrequencyHobGuid); if (GuidHob == NULL) + { + PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency)); + *PerformanceCounterFrequency = InternalCalculateTscFrequency (); + return *PerformanceCounterFrequency; } + PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob); + + return *PerformanceCounterFrequency; } diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf new file mode 100644 index 0000000..794d2a3 --- /dev/null +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf @@ -0,0 +1,55 @@ +## @file +# PEI ACPI Timer Library +# +# Provides basic timer support using the ACPI timer hardware. The +performance # 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.<BR> # This program and the accompanying materials # are +licensed and made available under the terms and conditions of the BSD +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 IMPLIED. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeAcpiTimerLib + FILE_GUID = 3FCA54F6-E1A2-4B20-BE76-926B4B48BFAA + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = TimerLib|PEI_CORE PEIM + MODULE_UNI_FILE = PeiAcpiTimerLib.uni + +[Sources] + AcpiTimerLib.c + PeiAcpiTimerLib.c + +[Packages] + MdePkg/MdePkg.dec + PcAtChipsetPkg/PcAtChipsetPkg.dec + +[LibraryClasses] + BaseLib + PcdLib + PciLib + IoLib + DebugLib + HobLib + +[Pcd] + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciDeviceNumber ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciFunctionNumber ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciEnableRegisterOffset ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoBarEnableMask ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBarRegisterOffset ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddress ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiPm1TmrOffset ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddressMask ## CONSUMES diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni new file mode 100644 index 0000000..668161b --- /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 +performance // counter features are provided by the processors time stamp counter. +// +// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR> // +// This program and the accompanying materials // are licensed and made +available under the terms and conditions of the BSD 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 IMPLIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "ACPI Timer Library" + +#string STR_MODULE_DESCRIPTION #language en-US "Provides basic timer support using the ACPI timer hardware." + diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc index b740f00..2395e9c 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.<BR> +# Copyright (c) 2007 - 2018, Intel Corporation. All rights +reserved.<BR> # # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -46,6 +46,7 @@ IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf [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.inf [BuildOptions] -- 2.8.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Star: PeiAcpiTimerLib just build, no link. PcAtChipsetPkg has no PEIM to build. So, no PEI hob library instance is specified. For INF base name, I will update it. And, I will update DXE Constructor to cache the Frequency in the entry point. Please help review my V2 patch. Thanks Liming > -----Original Message----- > From: Zeng, Star > Sent: Monday, January 22, 2018 10:06 PM > To: Gao, Liming <liming.gao@intel.com>; edk2-devel@lists.01.org > Cc: Zeng, Star <star.zeng@intel.com> > Subject: RE: [Patch] PcAtChipsetPkg: Add PeiAcpiTimerLib to save PerformanceCounterFrequency in HOB > > How could PeiAcpiTimerLib build pass with DxeHobLib > > Why the BASE_NAME is DxeAcpiTimerLib in PeiAcpiTimerLib.inf? > > > Thanks, > Star > -----Original Message----- > From: Gao, Liming > Sent: Monday, January 22, 2018 1:39 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star <star.zeng@intel.com> > Subject: [Patch] PcAtChipsetPkg: Add PeiAcpiTimerLib to save PerformanceCounterFrequency in HOB > > 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 <liming.gao@intel.com> > Cc: Star Zeng <star.zeng@intel.com> > --- > PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c | 4 +- > .../Library/AcpiTimerLib/DxeAcpiTimerLib.c | 14 ++++- > .../Library/AcpiTimerLib/DxeAcpiTimerLib.inf | 3 +- > .../Library/AcpiTimerLib/PeiAcpiTimerLib.c | 68 ++++++++++++++++++++++ > .../Library/AcpiTimerLib/PeiAcpiTimerLib.inf | 55 +++++++++++++++++ > .../Library/AcpiTimerLib/PeiAcpiTimerLib.uni | 23 ++++++++ > PcAtChipsetPkg/PcAtChipsetPkg.dsc | 4 +- > 7 files changed, 166 insertions(+), 5 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/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c > index 792781a..2f3cb4b 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. > > - Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR> > + Copyright (c) 2013 - 2018, Intel Corporation. All rights > + reserved.<BR> > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD License > which accompanies this distribution. The full text of the license may be found at @@ -21,6 +21,8 @@ #include > <Library/DebugLib.h> #include <IndustryStandard/Acpi.h> > > +GUID mFrequencyHobGuid = { 0x3fca54f6, 0xe1a2, 0x4b20, { 0xbe, 0x76, > +0x92, 0x6b, 0x4b, 0x48, 0xbf, 0xaa }}; > + > /** > Internal function to retrieves the 64-bit frequency in Hz. > > diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c > index b141c68..9b912c0 100644 > --- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c > +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c > @@ -12,9 +12,12 @@ > > **/ > > -#include <Base.h> > +#include <PiDxe.h> > #include <Library/TimerLib.h> > #include <Library/BaseLib.h> > +#include <Library/HobLib.h> > + > +extern GUID mFrequencyHobGuid; > > /** > Calculate TSC frequency. > @@ -54,8 +57,15 @@ InternalGetPerformanceCounterFrequency ( > VOID > ) > { > + EFI_HOB_GUID_TYPE *GuidHob; > + > if (mPerformanceCounterFrequency == 0) { > - mPerformanceCounterFrequency = InternalCalculateTscFrequency (); > + GuidHob = GetFirstGuidHob (&mFrequencyHobGuid); > + if (GuidHob != NULL) { > + mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob); > + } else { > + mPerformanceCounterFrequency = InternalCalculateTscFrequency (); > + } > } > return mPerformanceCounterFrequency; } diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > index 2c1cc7d..307e3f9 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.<BR> > +# Copyright (c) 2013 - 2018, Intel Corporation. All rights > +reserved.<BR> > # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD > License # which accompanies this distribution. The full text of the license may be found at @@ -42,6 +42,7 @@ > PciLib > IoLib > DebugLib > + HobLib > > [Pcd] > gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSUMES > diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c > new file mode 100644 > index 0000000..a4ed6a4 > --- /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.<BR> This program and the accompanying materials are > + licensed and made available under the terms and conditions of the BSD > + 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 IMPLIED. > + > +**/ > + > +#include <PiPei.h> > +#include <Library/TimerLib.h> > +#include <Library/BaseLib.h> > +#include <Library/HobLib.h> > + > +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 = NULL; > + GuidHob = GetFirstGuidHob (&mFrequencyHobGuid); if (GuidHob == NULL) > + { > + PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency)); > + *PerformanceCounterFrequency = InternalCalculateTscFrequency (); > + return *PerformanceCounterFrequency; } > + PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob); > + > + return *PerformanceCounterFrequency; } > diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf > new file mode 100644 > index 0000000..794d2a3 > --- /dev/null > +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf > @@ -0,0 +1,55 @@ > +## @file > +# PEI ACPI Timer Library > +# > +# Provides basic timer support using the ACPI timer hardware. The > +performance # 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.<BR> # This program and the accompanying materials # are > +licensed and made available under the terms and conditions of the BSD > +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 IMPLIED. > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = DxeAcpiTimerLib > + FILE_GUID = 3FCA54F6-E1A2-4B20-BE76-926B4B48BFAA > + MODULE_TYPE = PEIM > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = TimerLib|PEI_CORE PEIM > + MODULE_UNI_FILE = PeiAcpiTimerLib.uni > + > +[Sources] > + AcpiTimerLib.c > + PeiAcpiTimerLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + PcAtChipsetPkg/PcAtChipsetPkg.dec > + > +[LibraryClasses] > + BaseLib > + PcdLib > + PciLib > + IoLib > + DebugLib > + HobLib > + > +[Pcd] > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciDeviceNumber ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciFunctionNumber ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciEnableRegisterOffset ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoBarEnableMask ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBarRegisterOffset ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddress ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiPm1TmrOffset ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddressMask ## CONSUMES > diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni > new file mode 100644 > index 0000000..668161b > --- /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 > +performance // counter features are provided by the processors time stamp counter. > +// > +// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR> // > +// This program and the accompanying materials // are licensed and made > +available under the terms and conditions of the BSD 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 IMPLIED. > +// > +// **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "ACPI Timer Library" > + > +#string STR_MODULE_DESCRIPTION #language en-US "Provides basic timer support using the ACPI timer hardware." > + > diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc > index b740f00..2395e9c 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.<BR> > +# Copyright (c) 2007 - 2018, Intel Corporation. All rights > +reserved.<BR> > # > # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD > License @@ -46,6 +46,7 @@ > IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf > LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf > ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf > + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > > [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.inf > > [BuildOptions] > -- > 2.8.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Got it. Thanks, Star -----Original Message----- From: Gao, Liming Sent: Monday, January 22, 2018 11:24 PM To: Zeng, Star <star.zeng@intel.com>; edk2-devel@lists.01.org Subject: RE: [Patch] PcAtChipsetPkg: Add PeiAcpiTimerLib to save PerformanceCounterFrequency in HOB Star: PeiAcpiTimerLib just build, no link. PcAtChipsetPkg has no PEIM to build. So, no PEI hob library instance is specified. For INF base name, I will update it. And, I will update DXE Constructor to cache the Frequency in the entry point. Please help review my V2 patch. Thanks Liming > -----Original Message----- > From: Zeng, Star > Sent: Monday, January 22, 2018 10:06 PM > To: Gao, Liming <liming.gao@intel.com>; edk2-devel@lists.01.org > Cc: Zeng, Star <star.zeng@intel.com> > Subject: RE: [Patch] PcAtChipsetPkg: Add PeiAcpiTimerLib to save > PerformanceCounterFrequency in HOB > > How could PeiAcpiTimerLib build pass with DxeHobLib > > Why the BASE_NAME is DxeAcpiTimerLib in PeiAcpiTimerLib.inf? > > > Thanks, > Star > -----Original Message----- > From: Gao, Liming > Sent: Monday, January 22, 2018 1:39 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star <star.zeng@intel.com> > Subject: [Patch] PcAtChipsetPkg: Add PeiAcpiTimerLib to save > PerformanceCounterFrequency in HOB > > 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 <liming.gao@intel.com> > Cc: Star Zeng <star.zeng@intel.com> > --- > PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c | 4 +- > .../Library/AcpiTimerLib/DxeAcpiTimerLib.c | 14 ++++- > .../Library/AcpiTimerLib/DxeAcpiTimerLib.inf | 3 +- > .../Library/AcpiTimerLib/PeiAcpiTimerLib.c | 68 ++++++++++++++++++++++ > .../Library/AcpiTimerLib/PeiAcpiTimerLib.inf | 55 +++++++++++++++++ > .../Library/AcpiTimerLib/PeiAcpiTimerLib.uni | 23 ++++++++ > PcAtChipsetPkg/PcAtChipsetPkg.dsc | 4 +- > 7 files changed, 166 insertions(+), 5 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/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c > index 792781a..2f3cb4b 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. > > - Copyright (c) 2013 - 2016, Intel Corporation. All rights > reserved.<BR> > + Copyright (c) 2013 - 2018, Intel Corporation. All rights > + reserved.<BR> > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD License > which accompanies this distribution. The full text of the license > may be found at @@ -21,6 +21,8 @@ #include <Library/DebugLib.h> > #include <IndustryStandard/Acpi.h> > > +GUID mFrequencyHobGuid = { 0x3fca54f6, 0xe1a2, 0x4b20, { 0xbe, 0x76, > +0x92, 0x6b, 0x4b, 0x48, 0xbf, 0xaa }}; > + > /** > Internal function to retrieves the 64-bit frequency in Hz. > > diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c > b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c > index b141c68..9b912c0 100644 > --- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c > +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c > @@ -12,9 +12,12 @@ > > **/ > > -#include <Base.h> > +#include <PiDxe.h> > #include <Library/TimerLib.h> > #include <Library/BaseLib.h> > +#include <Library/HobLib.h> > + > +extern GUID mFrequencyHobGuid; > > /** > Calculate TSC frequency. > @@ -54,8 +57,15 @@ InternalGetPerformanceCounterFrequency ( > VOID > ) > { > + EFI_HOB_GUID_TYPE *GuidHob; > + > if (mPerformanceCounterFrequency == 0) { > - mPerformanceCounterFrequency = InternalCalculateTscFrequency (); > + GuidHob = GetFirstGuidHob (&mFrequencyHobGuid); > + if (GuidHob != NULL) { > + mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob); > + } else { > + mPerformanceCounterFrequency = InternalCalculateTscFrequency (); > + } > } > return mPerformanceCounterFrequency; } diff --git > a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > index 2c1cc7d..307e3f9 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.<BR> > +# Copyright (c) 2013 - 2018, Intel Corporation. All rights > +reserved.<BR> > # This program and the accompanying materials # are licensed and > made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -42,6 +42,7 @@ > PciLib > IoLib > DebugLib > + HobLib > > [Pcd] > gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSUMES > diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c > b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c > new file mode 100644 > index 0000000..a4ed6a4 > --- /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.<BR> This program and the accompanying materials are > + licensed and made available under the terms and conditions of the > + BSD 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 IMPLIED. > + > +**/ > + > +#include <PiPei.h> > +#include <Library/TimerLib.h> > +#include <Library/BaseLib.h> > +#include <Library/HobLib.h> > + > +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 = NULL; GuidHob = GetFirstGuidHob > + (&mFrequencyHobGuid); if (GuidHob == NULL) { > + PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency)); > + *PerformanceCounterFrequency = InternalCalculateTscFrequency (); > + return *PerformanceCounterFrequency; } > + PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob); > + > + return *PerformanceCounterFrequency; } > diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf > b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf > new file mode 100644 > index 0000000..794d2a3 > --- /dev/null > +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf > @@ -0,0 +1,55 @@ > +## @file > +# PEI ACPI Timer Library > +# > +# Provides basic timer support using the ACPI timer hardware. The > +performance # 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.<BR> # This program and the accompanying materials # are > +licensed and made available under the terms and conditions of the BSD > +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 IMPLIED. > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = DxeAcpiTimerLib > + FILE_GUID = 3FCA54F6-E1A2-4B20-BE76-926B4B48BFAA > + MODULE_TYPE = PEIM > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = TimerLib|PEI_CORE PEIM > + MODULE_UNI_FILE = PeiAcpiTimerLib.uni > + > +[Sources] > + AcpiTimerLib.c > + PeiAcpiTimerLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + PcAtChipsetPkg/PcAtChipsetPkg.dec > + > +[LibraryClasses] > + BaseLib > + PcdLib > + PciLib > + IoLib > + DebugLib > + HobLib > + > +[Pcd] > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciDeviceNumber ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciFunctionNumber ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciEnableRegisterOffset ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoBarEnableMask ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBarRegisterOffset ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddress ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiPm1TmrOffset ## CONSUMES > + gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddressMask ## CONSUMES > diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni > b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni > new file mode 100644 > index 0000000..668161b > --- /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 > +performance // counter features are provided by the processors time stamp counter. > +// > +// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR> // > +// This program and the accompanying materials // are licensed and > +made available under the terms and conditions of the BSD 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 IMPLIED. > +// > +// **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "ACPI Timer Library" > + > +#string STR_MODULE_DESCRIPTION #language en-US "Provides basic timer support using the ACPI timer hardware." > + > diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc > b/PcAtChipsetPkg/PcAtChipsetPkg.dsc > index b740f00..2395e9c 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.<BR> > +# Copyright (c) 2007 - 2018, Intel Corporation. All rights > +reserved.<BR> > # > # This program and the accompanying materials # are licensed and > made available under the terms and conditions of the BSD License @@ -46,6 +46,7 @@ > IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf > LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf > > ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseRep > ortStatusCodeLibNull.inf > + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > > [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 > .inf > > [BuildOptions] > -- > 2.8.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
© 2016 - 2024 Red Hat, Inc.