]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: AcpiTimerLib: Split into multiple phase-specific instances
authorGabriel Somlo <somlo@cmu.edu>
Fri, 14 Nov 2014 00:38:17 +0000 (00:38 +0000)
committerjljusten <jljusten@Edk2>
Fri, 14 Nov 2014 00:38:17 +0000 (00:38 +0000)
Remove local power management register access macros in favor of
factored-out ones in OvmfPkg/Include/OvmfPlatforms.h

Next, AcpiTimerLib is split out into three instances, for use during
various stages:

  - BaseRom: used during SEC, PEI_CORE, and PEIM;
  - Dxe:     used during DXE_DRIVER and DXE_RUNTIME_DRIVER;
  - Base:    used by default during all other stages.

Most of the code remains in AcpiTimerLib.c, to be shared by all
instances. The two platform-dependent methods (constructor and
InternalAcpiGetTimerTick) are provided separately by source files
specific to each instance, namely [BaseRom|Base|Dxe]AcpiTimerLib.c.

Since pre-DXE stages can't rely on storing data in global variables,
methods specific to the "BaseRom" instance will call platform
detection macros each time they're invoked.

The "Base" instance calls platform detection macros only from its
constructor, and caches the address required by InternalAcpiTimerTick
in a global variable.

The "Dxe" instance is very similar to "Base", except no platform
detection macros are called at all; instead, the platform type is
read via a dynamic PCD set from PlatformPei.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16376 6f19259b-4bc3-4df7-8a09-765794883524

12 files changed:
OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c
OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h [new file with mode: 0644]
OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf [deleted file]
OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c [new file with mode: 0644]
OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf [new file with mode: 0644]
OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c [new file with mode: 0644]
OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf [new file with mode: 0644]
OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c [new file with mode: 0644]
OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf [new file with mode: 0644]
OvmfPkg/OvmfPkgIa32.dsc
OvmfPkg/OvmfPkgIa32X64.dsc
OvmfPkg/OvmfPkgX64.dsc

index 7d324cb81589fde540c13ede0b005297ca1bc7e4..938b77cdc66ca26b60ca4c59d699be4eb6b01fca 100644 (file)
 \r
 **/\r
 \r
-#include <Base.h>\r
-#include <Library/TimerLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/IoLib.h>\r
-#include <Library/PciLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <IndustryStandard/Pci22.h>\r
+#include <Library/BaseLib.h>\r
 #include <IndustryStandard/Acpi.h>\r
 \r
-//\r
-// PCI Location of PIIX4 Power Management PCI Configuration Registers\r
-//\r
-#define PIIX4_POWER_MANAGEMENT_BUS       0x00\r
-#define PIIX4_POWER_MANAGEMENT_DEVICE    0x01\r
-#define PIIX4_POWER_MANAGEMENT_FUNCTION  0x03\r
-\r
-//\r
-// Macro to access PIIX4 Power Management PCI Configuration Registers\r
-//\r
-#define PIIX4_PCI_POWER_MANAGEMENT_REGISTER(Register) \\r
-  PCI_LIB_ADDRESS (                                   \\r
-    PIIX4_POWER_MANAGEMENT_BUS,                       \\r
-    PIIX4_POWER_MANAGEMENT_DEVICE,                    \\r
-    PIIX4_POWER_MANAGEMENT_FUNCTION,                  \\r
-    Register                                          \\r
-    )\r
-\r
-//\r
-// PCI Location of Q35 Power Management PCI Configuration Registers\r
-//\r
-#define Q35_POWER_MANAGEMENT_BUS       0x00\r
-#define Q35_POWER_MANAGEMENT_DEVICE    0x1f\r
-#define Q35_POWER_MANAGEMENT_FUNCTION  0x00\r
-\r
-//\r
-// Macro to access Q35 Power Management PCI Configuration Registers\r
-//\r
-#define Q35_PCI_POWER_MANAGEMENT_REGISTER(Register) \\r
-  PCI_LIB_ADDRESS (                                 \\r
-    Q35_POWER_MANAGEMENT_BUS,                       \\r
-    Q35_POWER_MANAGEMENT_DEVICE,                    \\r
-    Q35_POWER_MANAGEMENT_FUNCTION,                  \\r
-    Register                                        \\r
-    )\r
-\r
-//\r
-// PCI Location of Host Bridge PCI Configuration Registers\r
-//\r
-#define HOST_BRIDGE_BUS       0x00\r
-#define HOST_BRIDGE_DEVICE    0x00\r
-#define HOST_BRIDGE_FUNCTION  0x00\r
-\r
-//\r
-// Macro to access Host Bridge Configuration Registers\r
-//\r
-#define HOST_BRIDGE_REGISTER(Register) \\r
-  PCI_LIB_ADDRESS (                    \\r
-    HOST_BRIDGE_BUS,                   \\r
-    HOST_BRIDGE_DEVICE,                \\r
-    HOST_BRIDGE_FUNCTION,              \\r
-    Register                           \\r
-    )\r
-\r
-//\r
-// Host Bridge Device ID (DID) Register\r
-//\r
-#define HOST_BRIDGE_DID  HOST_BRIDGE_REGISTER (0x02)\r
-\r
-//\r
-// Host Bridge DID Register values\r
-//\r
-#define PCI_DEVICE_ID_INTEL_82441    0x1237  // DID value for PIIX4\r
-#define PCI_DEVICE_ID_INTEL_Q35_MCH  0x29C0  // DID value for Q35\r
-\r
-//\r
-// Access Power Management PCI Config Regs based on Host Bridge type\r
-//\r
-#define PCI_POWER_MANAGEMENT_REGISTER(Register)                   \\r
-  ((PciRead16 (HOST_BRIDGE_DID) == PCI_DEVICE_ID_INTEL_Q35_MCH) ? \\r
-    Q35_PCI_POWER_MANAGEMENT_REGISTER (Register) :                \\r
-    PIIX4_PCI_POWER_MANAGEMENT_REGISTER (Register))\r
-\r
-//\r
-// Power Management PCI Configuration Registers\r
-//\r
-#define PMBA                PCI_POWER_MANAGEMENT_REGISTER (0x40)\r
-#define   PMBA_RTE          BIT0\r
-#define PMREGMISC           PCI_POWER_MANAGEMENT_REGISTER (0x80)\r
-#define   PMIOSE            BIT0\r
+#include "AcpiTimerLib.h"\r
 \r
 //\r
 // The ACPI Time is a 24-bit counter\r
 //\r
 #define ACPI_TIMER_COUNT_SIZE  BIT24\r
 \r
-//\r
-// Offset in the Power Management Base Address to the ACPI Timer\r
-//\r
-#define ACPI_TIMER_OFFSET      0x8\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
-  // Check to see if the Power Management Base Address is already enabled\r
-  //\r
-  if ((PciRead8 (PMREGMISC) & PMIOSE) == 0) {\r
-    //\r
-    // If the Power Management Base Address is not programmed,\r
-    // then program the Power Management Base Address from a PCD.\r
-    //\r
-    PciAndThenOr32 (PMBA, (UINT32)(~0x0000FFC0), PcdGet16 (PcdAcpiPmBaseAddress));\r
-\r
-    //\r
-    // Enable PMBA I/O port decodes in PMREGMISC\r
-    //\r
-    PciOr8 (PMREGMISC, PMIOSE);\r
-  }\r
-  \r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-/**\r
-  Internal function to read the current tick counter of ACPI.\r
-\r
-  Internal function to read the current tick counter of ACPI.\r
-\r
-  @return The tick counter read.\r
-\r
-**/\r
-UINT32\r
-InternalAcpiGetTimerTick (\r
-  VOID\r
-  )\r
-{\r
-  //\r
-  //   Read PMBA to read and return the current ACPI timer value.\r
-  //\r
-  return IoRead32 ((PciRead32 (PMBA) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);\r
-}\r
-\r
 /**\r
   Stalls the CPU for at least the given number of ticks.\r
 \r
diff --git a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h b/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h
new file mode 100644 (file)
index 0000000..475da70
--- /dev/null
@@ -0,0 +1,29 @@
+/** @file\r
+  Internal definitions for ACPI Timer Library\r
+\r
+  Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r
+\r
+  This program and the accompanying materials are licensed and made\r
+  available under the terms and conditions of the BSD License which\r
+  accompanies this distribution.   The full text of the license may\r
+  be found at 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
+#ifndef _ACPI_TIMER_LIB_INTERNAL_H_\r
+#define _ACPI_TIMER_LIB_INTERNAL_H_\r
+\r
+/**\r
+  Internal function to read the current tick counter of ACPI.\r
+\r
+  @return The tick counter read.\r
+\r
+**/\r
+UINT32\r
+InternalAcpiGetTimerTick (\r
+  VOID\r
+  );\r
+\r
+#endif // _ACPI_TIMER_LIB_INTERNAL_H_\r
diff --git a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf b/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf
deleted file mode 100644 (file)
index da88668..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-## @file\r
-#  ACPI Timer Library Instance.\r
-#\r
-#  Copyright (c) 2008 - 2010, 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                      = AcpiTimerLib\r
-  FILE_GUID                      = CDD9D74F-213E-4c28-98F7-8B4A167DB936\r
-  MODULE_TYPE                    = BASE\r
-  VERSION_STRING                 = 1.0\r
-  LIBRARY_CLASS                  = TimerLib\r
-\r
-  CONSTRUCTOR                    = AcpiTimerLibConstructor\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
-#\r
-\r
-[Sources]\r
-  AcpiTimerLib.c\r
-\r
-[Packages]\r
-  MdePkg/MdePkg.dec\r
-  OvmfPkg/OvmfPkg.dec\r
-\r
-[Pcd]\r
-  gUefiOvmfPkgTokenSpaceGuid.PcdAcpiPmBaseAddress\r
-\r
-[LibraryClasses]\r
-  BaseLib\r
-  PciLib\r
-  IoLib\r
diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c
new file mode 100644 (file)
index 0000000..05b0257
--- /dev/null
@@ -0,0 +1,98 @@
+/** @file\r
+  Provide constructor and GetTick for Base instance of ACPI Timer Library\r
+\r
+  Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r
+\r
+  This program and the accompanying materials are licensed and made\r
+  available under the terms and conditions of the BSD License which\r
+  accompanies this distribution.   The full text of the license may\r
+  be found at 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
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PciLib.h>\r
+#include <OvmfPlatforms.h>\r
+\r
+//\r
+// Power Management PCI Configuration Register fields\r
+//\r
+#define PMBA_RTE  BIT0\r
+\r
+//\r
+// Offset in the Power Management Base Address to the ACPI Timer\r
+//\r
+#define ACPI_TIMER_OFFSET  0x8\r
+\r
+//\r
+// Cached ACPI Timer IO Address\r
+//\r
+STATIC UINT32 mAcpiTimerIoAddr;\r
+\r
+/**\r
+  The constructor function caches the ACPI tick counter address\r
+\r
+  At the time this constructor runs (DXE_CORE or later), ACPI IO space\r
+  has already been enabled by either PlatformPei or by the "Base"\r
+  instance of this library.\r
+  In order to avoid querying the underlying platform type during each\r
+  tick counter read operation, we cache the counter address during\r
+  initialization of this instance of the Timer Library.\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
+  UINT16 HostBridgeDevId;\r
+  UINTN Pmba;\r
+\r
+  //\r
+  // Query Host Bridge DID to determine platform type\r
+  //\r
+  HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
+  switch (HostBridgeDevId) {\r
+    case INTEL_82441_DEVICE_ID:\r
+      Pmba = POWER_MGMT_REGISTER_PIIX4 (0x40);\r
+      break;\r
+    case INTEL_Q35_MCH_DEVICE_ID:\r
+      Pmba = POWER_MGMT_REGISTER_Q35 (0x40);\r
+      break;\r
+    default:\r
+      DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
+        __FUNCTION__, HostBridgeDevId));\r
+      ASSERT (FALSE);\r
+      return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Internal function to read the current tick counter of ACPI.\r
+\r
+  Read the current ACPI tick counter using the counter address cached\r
+  by this instance's constructor.\r
+\r
+  @return The tick counter read.\r
+\r
+**/\r
+UINT32\r
+InternalAcpiGetTimerTick (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  //   Return the current ACPI timer value.\r
+  //\r
+  return IoRead32 (mAcpiTimerIoAddr);\r
+}\r
diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf b/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf
new file mode 100644 (file)
index 0000000..35c6edc
--- /dev/null
@@ -0,0 +1,37 @@
+## @file\r
+#  Base ACPI Timer Library Instance.\r
+#\r
+#  Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r
+#  Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.\r
+#\r
+#  This program and the accompanying materials are licensed and made\r
+#  available under the terms and conditions of the BSD License which\r
+#  accompanies this distribution.   The full text of the license may\r
+#  be found at 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      = BaseAcpiTimerLib\r
+  FILE_GUID      = FB648CF5-91BE-4737-9023-FD807AC6D96D\r
+  MODULE_TYPE    = BASE\r
+  VERSION_STRING = 1.0\r
+  LIBRARY_CLASS  = TimerLib|DXE_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION SMM_CORE\r
+  CONSTRUCTOR    = AcpiTimerLibConstructor\r
+\r
+[Sources]\r
+  AcpiTimerLib.c\r
+  BaseAcpiTimerLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  PciLib\r
+  IoLib\r
diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c
new file mode 100644 (file)
index 0000000..05b14d7
--- /dev/null
@@ -0,0 +1,130 @@
+/** @file\r
+  Provide constructor and GetTick for BaseRom instance of ACPI Timer Library\r
+\r
+  Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.\r
+  Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>\r
+\r
+  This program and the accompanying materials are licensed and made\r
+  available under the terms and conditions of the BSD License which\r
+  accompanies this distribution.   The full text of the license may\r
+  be found at 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
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PciLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <OvmfPlatforms.h>\r
+\r
+//\r
+// Power Management PCI Configuration Register fields\r
+//\r
+#define PMBA_RTE  BIT0\r
+#define PMIOSE    BIT0\r
+\r
+//\r
+// Offset in the Power Management Base Address to the ACPI Timer\r
+//\r
+#define ACPI_TIMER_OFFSET      0x8\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
+  UINT16 HostBridgeDevId;\r
+  UINTN Pmba;\r
+  UINTN PmRegMisc;\r
+\r
+  //\r
+  // Query Host Bridge DID to determine platform type\r
+  //\r
+  HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
+  switch (HostBridgeDevId) {\r
+    case INTEL_82441_DEVICE_ID:\r
+      Pmba      = POWER_MGMT_REGISTER_PIIX4 (0x40);\r
+      PmRegMisc = POWER_MGMT_REGISTER_PIIX4 (0x80);\r
+      break;\r
+    case INTEL_Q35_MCH_DEVICE_ID:\r
+      Pmba      = POWER_MGMT_REGISTER_Q35 (0x40);\r
+      PmRegMisc = POWER_MGMT_REGISTER_Q35 (0x80);\r
+      break;\r
+    default:\r
+      DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
+        __FUNCTION__, HostBridgeDevId));\r
+      ASSERT (FALSE);\r
+      return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Check to see if the Power Management Base Address is already enabled\r
+  //\r
+  if ((PciRead8 (PmRegMisc) & PMIOSE) == 0) {\r
+    //\r
+    // If the Power Management Base Address is not programmed,\r
+    // then program the Power Management Base Address from a PCD.\r
+    //\r
+    PciAndThenOr32 (Pmba, (UINT32) ~0xFFC0, PcdGet16 (PcdAcpiPmBaseAddress));\r
+\r
+    //\r
+    // Enable PMBA I/O port decodes in PMREGMISC\r
+    //\r
+    PciOr8 (PmRegMisc, PMIOSE);\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Internal function to read the current tick counter of ACPI.\r
+\r
+  Dynamically compute the address of the ACPI tick counter based on the\r
+  properties of the underlying platform, to avoid relying on global variables.\r
+\r
+  @return The tick counter read.\r
+\r
+**/\r
+UINT32\r
+InternalAcpiGetTimerTick (\r
+  VOID\r
+  )\r
+{\r
+  UINT16 HostBridgeDevId;\r
+  UINTN Pmba;\r
+\r
+  //\r
+  // Query Host Bridge DID to determine platform type\r
+  //\r
+  HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
+  switch (HostBridgeDevId) {\r
+    case INTEL_82441_DEVICE_ID:\r
+      Pmba = POWER_MGMT_REGISTER_PIIX4 (0x40);\r
+      break;\r
+    case INTEL_Q35_MCH_DEVICE_ID:\r
+      Pmba = POWER_MGMT_REGISTER_Q35 (0x40);\r
+      break;\r
+    default:\r
+      DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
+        __FUNCTION__, HostBridgeDevId));\r
+      ASSERT (FALSE);\r
+      return 0;\r
+  }\r
+\r
+  //\r
+  //   Read PMBA to read and return the current ACPI timer value.\r
+  //\r
+  return IoRead32 ((PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);\r
+}\r
diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf b/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
new file mode 100644 (file)
index 0000000..2a3016f
--- /dev/null
@@ -0,0 +1,39 @@
+## @file\r
+#  BaseRom ACPI Timer Library Instance.\r
+#\r
+#  Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.\r
+#\r
+#  This program and the accompanying materials are licensed and made\r
+#  available under the terms and conditions of the BSD License which\r
+#  accompanies this distribution.   The full text of the license may\r
+#  be found at 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      = BaseRomAcpiTimerLib\r
+  FILE_GUID      = CDD9D74F-213E-4c28-98F7-8B4A167DB936\r
+  MODULE_TYPE    = BASE\r
+  VERSION_STRING = 1.0\r
+  LIBRARY_CLASS  = TimerLib|SEC PEI_CORE PEIM\r
+  CONSTRUCTOR    = AcpiTimerLibConstructor\r
+\r
+[Sources]\r
+  AcpiTimerLib.c\r
+  BaseRomAcpiTimerLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[Pcd]\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdAcpiPmBaseAddress\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  PciLib\r
+  IoLib\r
diff --git a/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
new file mode 100644 (file)
index 0000000..2be0793
--- /dev/null
@@ -0,0 +1,99 @@
+/** @file\r
+  Provide constructor and GetTick for Dxe instance of ACPI Timer Library\r
+\r
+  Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r
+\r
+  This program and the accompanying materials are licensed and made\r
+  available under the terms and conditions of the BSD License which\r
+  accompanies this distribution.   The full text of the license may\r
+  be found at 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
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/PciLib.h>\r
+#include <OvmfPlatforms.h>\r
+\r
+//\r
+// Power Management PCI Configuration Register fields\r
+//\r
+#define PMBA_RTE  BIT0\r
+\r
+//\r
+// Offset in the Power Management Base Address to the ACPI Timer\r
+//\r
+#define ACPI_TIMER_OFFSET  0x8\r
+\r
+//\r
+// Cached ACPI Timer IO Address\r
+//\r
+STATIC UINT32 mAcpiTimerIoAddr;\r
+\r
+/**\r
+  The constructor function caches the ACPI tick counter address\r
+\r
+  At the time this constructor runs (DXE_CORE or later), ACPI IO space\r
+  has already been enabled by either PlatformPei or by the "Base"\r
+  instance of this library.\r
+  In order to avoid querying the underlying platform type during each\r
+  tick counter read operation, we cache the counter address during\r
+  initialization of this instance of the Timer Library.\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
+  UINT16 HostBridgeDevId;\r
+  UINTN Pmba;\r
+\r
+  //\r
+  // Query Host Bridge DID to determine platform type\r
+  //\r
+  HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);\r
+  switch (HostBridgeDevId) {\r
+    case INTEL_82441_DEVICE_ID:\r
+      Pmba = POWER_MGMT_REGISTER_PIIX4 (0x40);\r
+      break;\r
+    case INTEL_Q35_MCH_DEVICE_ID:\r
+      Pmba = POWER_MGMT_REGISTER_Q35 (0x40);\r
+      break;\r
+    default:\r
+      DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
+        __FUNCTION__, HostBridgeDevId));\r
+      ASSERT (FALSE);\r
+      return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Internal function to read the current tick counter of ACPI.\r
+\r
+  Read the current ACPI tick counter using the counter address cached\r
+  by this instance's constructor.\r
+\r
+  @return The tick counter read.\r
+\r
+**/\r
+UINT32\r
+InternalAcpiGetTimerTick (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  //   Return the current ACPI timer value.\r
+  //\r
+  return IoRead32 (mAcpiTimerIoAddr);\r
+}\r
diff --git a/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
new file mode 100644 (file)
index 0000000..b7e8bfc
--- /dev/null
@@ -0,0 +1,40 @@
+## @file\r
+#  DXE ACPI Timer Library Instance.\r
+#\r
+#  Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r
+#  Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.\r
+#\r
+#  This program and the accompanying materials are licensed and made\r
+#  available under the terms and conditions of the BSD License which\r
+#  accompanies this distribution.   The full text of the license may\r
+#  be found at 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      = DxeAcpiTimerLib\r
+  FILE_GUID      = 52DECA02-2EE8-4EAA-8EAD-1AB83F8A5955\r
+  MODULE_TYPE    = BASE\r
+  VERSION_STRING = 1.0\r
+  LIBRARY_CLASS  = TimerLib|DXE_DRIVER DXE_RUNTIME_DRIVER\r
+  CONSTRUCTOR    = AcpiTimerLibConstructor\r
+\r
+[Sources]\r
+  AcpiTimerLib.c\r
+  DxeAcpiTimerLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[Pcd]\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  PciLib\r
+  IoLib\r
index 59f0fcea246e8bb63ae4c868918a8c4d1b164035..5baec1cfc848dbf3b973b034e0ff17a283fcc001 100644 (file)
@@ -57,7 +57,7 @@
 ################################################################################\r
 [LibraryClasses]\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf\r
   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
   BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf\r
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
 !endif\r
 \r
 [LibraryClasses.common.SEC]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf\r
 !ifdef $(DEBUG_ON_SERIAL_PORT)\r
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf\r
 \r
 [LibraryClasses.common.PEI_CORE]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf\r
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
 \r
 [LibraryClasses.common.PEIM]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf\r
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
       PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   }\r
   PcAtChipsetPkg/KbcResetDxe/Reset.inf\r
-  MdeModulePkg/Universal/Metronome/Metronome.inf {\r
-    <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
-  }\r
-\r
-  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf {\r
-    <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
-  }\r
-\r
+  MdeModulePkg/Universal/Metronome/Metronome.inf\r
+  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf\r
   IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf {\r
     <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
 !ifdef $(CSM_ENABLE)\r
       NULL|OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf\r
 !endif\r
index ab6feae6c6e37563a4cf4c92724a6ea6af8bc7b7..c7a18d0907251d82b168e95d7a31a2ba81bd6588 100644 (file)
@@ -62,7 +62,7 @@
 ################################################################################\r
 [LibraryClasses]\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf\r
   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
   BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf\r
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
 !endif\r
 \r
 [LibraryClasses.common.SEC]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf\r
 !ifdef $(DEBUG_ON_SERIAL_PORT)\r
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf\r
 \r
 [LibraryClasses.common.PEI_CORE]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf\r
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
 \r
 [LibraryClasses.common.PEIM]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf\r
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
       PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   }\r
   PcAtChipsetPkg/KbcResetDxe/Reset.inf\r
-  MdeModulePkg/Universal/Metronome/Metronome.inf {\r
-    <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
-  }\r
-\r
-  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf {\r
-    <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
-  }\r
-\r
+  MdeModulePkg/Universal/Metronome/Metronome.inf\r
+  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf\r
   IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf {\r
     <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
 !ifdef $(CSM_ENABLE)\r
       NULL|OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf\r
 !endif\r
index 26d5655f9e537f6a8c339eb283c9895c1b887448..7cafcaccef9da7241751eeb1f0927e1254658c78 100644 (file)
@@ -62,7 +62,7 @@
 ################################################################################\r
 [LibraryClasses]\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf\r
   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
   BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf\r
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
 !endif\r
 \r
 [LibraryClasses.common.SEC]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf\r
 !ifdef $(DEBUG_ON_SERIAL_PORT)\r
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf\r
 \r
 [LibraryClasses.common.PEI_CORE]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf\r
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
 \r
 [LibraryClasses.common.PEIM]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf\r
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
+  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
       PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   }\r
   PcAtChipsetPkg/KbcResetDxe/Reset.inf\r
-  MdeModulePkg/Universal/Metronome/Metronome.inf {\r
-    <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
-  }\r
-\r
-  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf {\r
-    <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
-  }\r
-\r
+  MdeModulePkg/Universal/Metronome/Metronome.inf\r
+  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf\r
   IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf {\r
     <LibraryClasses>\r
-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf\r
 !ifdef $(CSM_ENABLE)\r
       NULL|OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf\r
 !endif\r