]> git.proxmox.com Git - mirror_edk2.git/commitdiff
PcAtChipsetPkg: Add PeiAcpiTimerLib to save Frequency in HOB
authorLiming Gao <liming.gao@intel.com>
Tue, 23 Jan 2018 02:24:04 +0000 (10:24 +0800)
committerLiming Gao <liming.gao@intel.com>
Tue, 6 Feb 2018 05:37:01 +0000 (13:37 +0800)
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 <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c
PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c [new file with mode: 0644]
PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf [new file with mode: 0644]
PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni [new file with mode: 0644]
PcAtChipsetPkg/PcAtChipsetPkg.dsc

index 792781a33f3fb03ee97a6b74f1cbabc227802465..2f3cb4bca4b5913430ac4e1f6dfbfed99ced21a4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   ACPI Timer implements one instance of Timer Library.\r
 \r
-  Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -21,6 +21,8 @@
 #include <Library/DebugLib.h>\r
 #include <IndustryStandard/Acpi.h>\r
 \r
+GUID mFrequencyHobGuid = { 0x3fca54f6, 0xe1a2, 0x4b20, { 0xbe, 0x76, 0x92, 0x6b, 0x4b, 0x48, 0xbf, 0xaa }};\r
+\r
 /**\r
   Internal function to retrieves the 64-bit frequency in Hz.\r
 \r
index b141c680fb823c59f08efd624d46a9731b3ff224..67e18a13607fbf82f55741d612e0eb844bab276d 100644 (file)
 \r
 **/\r
 \r
-#include <Base.h>\r
+#include <PiDxe.h>\r
 #include <Library/TimerLib.h>\r
 #include <Library/BaseLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+extern GUID mFrequencyHobGuid;\r
+\r
+/**\r
+  The constructor function enables ACPI IO space.\r
+\r
+  If ACPI I/O space not enabled, this function will enable it.\r
+  It will always return RETURN_SUCCESS.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AcpiTimerLibConstructor (\r
+  VOID\r
+  );\r
 \r
 /**\r
   Calculate TSC frequency.\r
@@ -54,8 +72,41 @@ InternalGetPerformanceCounterFrequency (
   VOID\r
   ) \r
 {\r
-  if (mPerformanceCounterFrequency == 0) {\r
+  return  mPerformanceCounterFrequency;\r
+}\r
+\r
+/**\r
+  The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency. \r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeAcpiTimerLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE   *GuidHob;\r
+\r
+  //\r
+  // Enable ACPI IO space.\r
+  //\r
+  AcpiTimerLibConstructor ();\r
+\r
+  //\r
+  // Initialize PerformanceCounterFrequency\r
+  //\r
+  GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);\r
+  if (GuidHob != NULL) {\r
+    mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob);\r
+  } else {\r
     mPerformanceCounterFrequency = InternalCalculateTscFrequency ();\r
   }\r
-  return  mPerformanceCounterFrequency;\r
+\r
+  return EFI_SUCCESS;\r
 }\r
index 2c1cc7d33cdbb4c725fe7d88f1ce32f3026bbd1a..601041c8013765ce8dacf698c96be6d6c1f2a773 100644 (file)
@@ -7,7 +7,7 @@
 #  Note: The implementation uses the lower 24-bits of the ACPI timer and\r
 #  is compatible with both 24-bit and 32-bit ACPI timers.\r
 #\r
-#  Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
   INF_VERSION                    = 0x00010005\r
   BASE_NAME                      = DxeAcpiTimerLib\r
   FILE_GUID                      = E624B98C-845A-4b94-9B50-B20475D552B9\r
-  MODULE_TYPE                    = BASE\r
+  MODULE_TYPE                    = DXE_DRIVER\r
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE\r
-  CONSTRUCTOR                    = AcpiTimerLibConstructor\r
+  CONSTRUCTOR                    = DxeAcpiTimerLibConstructor\r
   MODULE_UNI_FILE                = DxeAcpiTimerLib.uni\r
 \r
 [Sources]\r
@@ -42,6 +42,7 @@
   PciLib\r
   IoLib\r
   DebugLib\r
+  HobLib\r
 \r
 [Pcd]\r
   gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber             ## CONSUMES\r
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c
new file mode 100644 (file)
index 0000000..45a341f
--- /dev/null
@@ -0,0 +1,69 @@
+/** @file\r
+  ACPI Timer implements one instance of Timer Library.\r
+\r
+  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+extern GUID mFrequencyHobGuid;\r
+\r
+/**\r
+  Calculate TSC frequency.\r
+\r
+  The TSC counting frequency is determined by comparing how far it counts\r
+  during a 101.4 us period as determined by the ACPI timer.\r
+  The ACPI timer is used because it counts at a known frequency.\r
+  The TSC is sampled, followed by waiting 363 counts of the ACPI timer,\r
+  or 101.4 us. The TSC is then sampled again. The difference multiplied by\r
+  9861 is the TSC frequency. There will be a small error because of the\r
+  overhead of reading the ACPI timer. An attempt is made to determine and\r
+  compensate for this error.\r
+\r
+  @return The number of TSC counts per second.\r
+\r
+**/\r
+UINT64\r
+InternalCalculateTscFrequency (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Internal function to retrieves the 64-bit frequency in Hz.\r
+\r
+  Internal function to retrieves the 64-bit frequency in Hz.\r
+\r
+  @return The frequency in Hz.\r
+\r
+**/\r
+UINT64\r
+InternalGetPerformanceCounterFrequency (\r
+  VOID\r
+  )\r
+{\r
+  UINT64              *PerformanceCounterFrequency;\r
+  EFI_HOB_GUID_TYPE   *GuidHob;\r
+\r
+  PerformanceCounterFrequency = NULL;\r
+  GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);\r
+  if (GuidHob == NULL) {\r
+    PerformanceCounterFrequency  = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));\r
+    ASSERT (PerformanceCounterFrequency != NULL);\r
+    *PerformanceCounterFrequency = InternalCalculateTscFrequency ();\r
+  } else {\r
+    PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob);\r
+  }\r
+\r
+  return  *PerformanceCounterFrequency;\r
+}\r
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf
new file mode 100644 (file)
index 0000000..1d8c95a
--- /dev/null
@@ -0,0 +1,56 @@
+## @file\r
+#  PEI ACPI Timer Library\r
+#\r
+#  Provides basic timer support using the ACPI timer hardware.  The performance\r
+#  counter features are provided by the processors time stamp counter.\r
+#\r
+#  Note: The implementation uses the lower 24-bits of the ACPI timer and\r
+#  is compatible with both 24-bit and 32-bit ACPI timers.\r
+#\r
+#  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiAcpiTimerLib\r
+  FILE_GUID                      = 3FCA54F6-E1A2-4B20-BE76-926B4B48BFAA\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = TimerLib|PEI_CORE PEIM\r
+  CONSTRUCTOR                    = AcpiTimerLibConstructor\r
+  MODULE_UNI_FILE                = PeiAcpiTimerLib.uni\r
+\r
+[Sources]\r
+  AcpiTimerLib.c\r
+  PeiAcpiTimerLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  PcAtChipsetPkg/PcAtChipsetPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  PcdLib\r
+  PciLib\r
+  IoLib\r
+  DebugLib\r
+  HobLib\r
+\r
+[Pcd]\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBusNumber             ## CONSUMES\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciDeviceNumber          ## CONSUMES\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciFunctionNumber        ## CONSUMES\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciEnableRegisterOffset  ## CONSUMES\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoBarEnableMask            ## CONSUMES\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPciBarRegisterOffset     ## CONSUMES\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddress          ## CONSUMES\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiPm1TmrOffset               ## CONSUMES\r
+  gPcAtChipsetPkgTokenSpaceGuid.PcdAcpiIoPortBaseAddressMask      ## CONSUMES\r
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.uni
new file mode 100644 (file)
index 0000000..668161b
--- /dev/null
@@ -0,0 +1,23 @@
+// /** @file\r
+// PEI ACPI Timer Library\r
+//\r
+// Provides basic timer support using the ACPI timer hardware.  The performance\r
+// counter features are provided by the processors time stamp counter.\r
+//\r
+// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "ACPI Timer Library"\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "Provides basic timer support using the ACPI timer hardware."\r
+\r
index b740f00e635a0149953f729593716f9ff67c69cd..2395e9cf268eb26455612a20c383da91878dcaa8 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  PC/AT Chipset Package\r
 #\r
-#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -46,6 +46,7 @@
   IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf\r
   LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf\r
   ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
 \r
 [Components]\r
   PcAtChipsetPkg/8254TimerDxe/8254Timer.inf\r
@@ -57,6 +58,7 @@
   PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf\r
   PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf\r
   PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf\r
+  PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf\r
   PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf\r
 \r
 [BuildOptions]\r