]> git.proxmox.com Git - mirror_edk2.git/commitdiff
PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib
authorKun Qin <kun.q@outlook.com>
Thu, 17 Dec 2020 22:47:07 +0000 (14:47 -0800)
committerKun Qin <kun.q@outlook.com>
Mon, 1 Feb 2021 18:03:35 +0000 (10:03 -0800)
This change added a new instance of AcpiTimerLib for StandaloneMm core
and drivers. It centralizes the common routines into shared files and
abstract the library constructor into corresponding files to accommodate
each constructor function prototypes.

Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c [new file with mode: 0644]
PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h [new file with mode: 0644]
PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c [new file with mode: 0644]
PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf [new file with mode: 0644]
PcAtChipsetPkg/PcAtChipsetPkg.dsc

index 3ad831b15e8ada72a2e74ea6f3a794b0d29a4bd1..9ac2a446e365ffb587b9595985d41044623a98f6 100644 (file)
@@ -2,72 +2,14 @@
   ACPI Timer implements one instance of Timer Library.\r
 \r
   Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) Microsoft Corporation.\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \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
-\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
-// Cached performance counter frequency\r
-//\r
-UINT64  mPerformanceCounterFrequency = 0;\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
-  return  mPerformanceCounterFrequency;\r
-}\r
+#include "DxeStandaloneMmAcpiTimerLib.h"\r
 \r
 /**\r
   The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.\r
@@ -85,22 +27,5 @@ DxeAcpiTimerLibConstructor (
   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
-\r
-  return EFI_SUCCESS;\r
+  return CommonAcpiTimerLibConstructor ();\r
 }\r
index d86356f4ff17c9a7449eab7e4f0a561288ff41f3..93972e53c9c50fa63ba6af1206bc06a8f3449661 100644 (file)
@@ -25,6 +25,8 @@
 [Sources]\r
   AcpiTimerLib.c\r
   DxeAcpiTimerLib.c\r
+  DxeStandaloneMmAcpiTimerLib.c\r
+  DxeStandaloneMmAcpiTimerLib.h\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
new file mode 100644 (file)
index 0000000..0e40119
--- /dev/null
@@ -0,0 +1,101 @@
+/** @file\r
+  ACPI Timer implements one instance of Timer Library.\r
+\r
+  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\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
+\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
+// Cached performance counter frequency\r
+//\r
+UINT64  mPerformanceCounterFrequency = 0;\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
+  return  mPerformanceCounterFrequency;\r
+}\r
+\r
+/**\r
+  The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+CommonAcpiTimerLibConstructor (\r
+  VOID\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
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
new file mode 100644 (file)
index 0000000..6015d68
--- /dev/null
@@ -0,0 +1,24 @@
+/** @file\r
+  Header file internal to ACPI TimerLib.\r
+\r
+Copyright (c) Microsoft Corporation.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+\r
+#ifndef _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_\r
+#define _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_\r
+\r
+/**\r
+  The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+CommonAcpiTimerLibConstructor (\r
+  VOID\r
+  );\r
+\r
+#endif\r
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c
new file mode 100644 (file)
index 0000000..97aca56
--- /dev/null
@@ -0,0 +1,31 @@
+/** @file\r
+  ACPI Timer implements one instance of Timer Library.\r
+\r
+  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) Microsoft Corporation.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <PiMm.h>\r
+\r
+#include "DxeStandaloneMmAcpiTimerLib.h"\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
+StandaloneMmAcpiTimerLibConstructor (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_MM_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  return CommonAcpiTimerLibConstructor ();\r
+}\r
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
new file mode 100644 (file)
index 0000000..c5efdd1
--- /dev/null
@@ -0,0 +1,53 @@
+## @file\r
+#  Standalone MM 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
+#  Copyright (c) Microsoft Corporation.\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = StandaloneMmAcpiTimerLib\r
+  FILE_GUID                      = C771858D-AF09-4D1A-B2F3-C7F081C3F076\r
+  MODULE_TYPE                    = MM_STANDALONE\r
+  VERSION_STRING                 = 1.0\r
+  PI_SPECIFICATION_VERSION       = 0x00010032\r
+  LIBRARY_CLASS                  = TimerLib|MM_CORE_STANDALONE MM_STANDALONE\r
+  CONSTRUCTOR                    = StandaloneMmAcpiTimerLibConstructor\r
+\r
+[Sources]\r
+  AcpiTimerLib.c\r
+  StandaloneMmAcpiTimerLib.c\r
+  DxeStandaloneMmAcpiTimerLib.c\r
+  DxeStandaloneMmAcpiTimerLib.h\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
index b61b7d1f528ea3043e99a30231207e6c0a2abd6a..3d1fb816f54f75c0183b75c2e276210aeeca09d8 100644 (file)
@@ -53,6 +53,7 @@
   PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf\r
   PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf\r
   PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf\r
+  PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf\r
   PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf\r
 \r
 [BuildOptions]\r