diff options
Diffstat (limited to 'roms/edk2/OvmfPkg/Library/AcpiTimerLib')
10 files changed, 700 insertions, 0 deletions
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c new file mode 100644 index 000000000..2ed1baeeb --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c @@ -0,0 +1,210 @@ +/** @file
+ ACPI Timer implements one instance of Timer Library.
+
+ Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <IndustryStandard/Acpi.h>
+
+#include "AcpiTimerLib.h"
+
+//
+// The ACPI Time is a 24-bit counter
+//
+#define ACPI_TIMER_COUNT_SIZE BIT24
+
+/**
+ Stalls the CPU for at least the given number of ticks.
+
+ Stalls the CPU for at least the given number of ticks. It's invoked by
+ MicroSecondDelay() and NanoSecondDelay().
+
+ @param Delay A period of time to delay in ticks.
+
+**/
+VOID
+InternalAcpiDelay (
+ IN UINT32 Delay
+ )
+{
+ UINT32 Ticks;
+ UINT32 Times;
+
+ Times = Delay >> 22;
+ Delay &= BIT22 - 1;
+ do {
+ //
+ // The target timer count is calculated here
+ //
+ Ticks = InternalAcpiGetTimerTick () + Delay;
+ Delay = BIT22;
+ //
+ // Wait until time out
+ // Delay >= 2^23 could not be handled by this function
+ // Timer wrap-arounds are handled correctly by this function
+ //
+ while (((Ticks - InternalAcpiGetTimerTick ()) & BIT23) == 0) {
+ CpuPause ();
+ }
+ } while (Times-- > 0);
+}
+
+/**
+ Stalls the CPU for at least the given number of microseconds.
+
+ Stalls the CPU for the number of microseconds specified by MicroSeconds.
+
+ @param MicroSeconds The minimum number of microseconds to delay.
+
+ @return MicroSeconds
+
+**/
+UINTN
+EFIAPI
+MicroSecondDelay (
+ IN UINTN MicroSeconds
+ )
+{
+ InternalAcpiDelay (
+ (UINT32)DivU64x32 (
+ MultU64x32 (
+ MicroSeconds,
+ ACPI_TIMER_FREQUENCY
+ ),
+ 1000000u
+ )
+ );
+ return MicroSeconds;
+}
+
+/**
+ Stalls the CPU for at least the given number of nanoseconds.
+
+ Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
+
+ @param NanoSeconds The minimum number of nanoseconds to delay.
+
+ @return NanoSeconds
+
+**/
+UINTN
+EFIAPI
+NanoSecondDelay (
+ IN UINTN NanoSeconds
+ )
+{
+ InternalAcpiDelay (
+ (UINT32)DivU64x32 (
+ MultU64x32 (
+ NanoSeconds,
+ ACPI_TIMER_FREQUENCY
+ ),
+ 1000000000u
+ )
+ );
+ return NanoSeconds;
+}
+
+/**
+ Retrieves the current value of a 64-bit free running performance counter.
+
+ Retrieves the current value of a 64-bit free running performance counter. The
+ counter can either count up by 1 or count down by 1. If the physical
+ performance counter counts by a larger increment, then the counter values
+ must be translated. The properties of the counter can be retrieved from
+ GetPerformanceCounterProperties().
+
+ @return The current value of the free running performance counter.
+
+**/
+UINT64
+EFIAPI
+GetPerformanceCounter (
+ VOID
+ )
+{
+ return (UINT64)InternalAcpiGetTimerTick ();
+}
+
+/**
+ Retrieves the 64-bit frequency in Hz and the range of performance counter
+ values.
+
+ If StartValue is not NULL, then the value that the performance counter starts
+ with immediately after is it rolls over is returned in StartValue. If
+ EndValue is not NULL, then the value that the performance counter end with
+ immediately before it rolls over is returned in EndValue. The 64-bit
+ frequency of the performance counter in Hz is always returned. If StartValue
+ is less than EndValue, then the performance counter counts up. If StartValue
+ is greater than EndValue, then the performance counter counts down. For
+ example, a 64-bit free running counter that counts up would have a StartValue
+ of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
+ that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
+
+ @param StartValue The value the performance counter starts with when it
+ rolls over.
+ @param EndValue The value that the performance counter ends with before
+ it rolls over.
+
+ @return The frequency in Hz.
+
+**/
+UINT64
+EFIAPI
+GetPerformanceCounterProperties (
+ OUT UINT64 *StartValue, OPTIONAL
+ OUT UINT64 *EndValue OPTIONAL
+ )
+{
+ if (StartValue != NULL) {
+ *StartValue = 0;
+ }
+
+ if (EndValue != NULL) {
+ *EndValue = ACPI_TIMER_COUNT_SIZE - 1;
+ }
+
+ return ACPI_TIMER_FREQUENCY;
+}
+
+/**
+ Converts elapsed ticks of performance counter to time in nanoseconds.
+
+ This function converts the elapsed ticks of running performance counter to
+ time value in unit of nanoseconds.
+
+ @param Ticks The number of elapsed ticks of running performance counter.
+
+ @return The elapsed time in nanoseconds.
+
+**/
+UINT64
+EFIAPI
+GetTimeInNanoSecond (
+ IN UINT64 Ticks
+ )
+{
+ UINT64 NanoSeconds;
+ UINT32 Remainder;
+
+ //
+ // Ticks
+ // Time = --------- x 1,000,000,000
+ // Frequency
+ //
+ NanoSeconds = MultU64x32 (DivU64x32Remainder (Ticks, ACPI_TIMER_FREQUENCY, &Remainder), 1000000000u);
+
+ //
+ // Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000)
+ // will not overflow 64-bit.
+ //
+ NanoSeconds += DivU64x32 (MultU64x32 ((UINT64) Remainder, 1000000000u), ACPI_TIMER_FREQUENCY);
+
+ return NanoSeconds;
+}
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h new file mode 100644 index 000000000..0ac990284 --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h @@ -0,0 +1,23 @@ +/** @file
+ Internal definitions for ACPI Timer Library
+
+ Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef _ACPI_TIMER_LIB_INTERNAL_H_
+#define _ACPI_TIMER_LIB_INTERNAL_H_
+
+/**
+ Internal function to read the current tick counter of ACPI.
+
+ @return The tick counter read.
+
+**/
+UINT32
+InternalAcpiGetTimerTick (
+ VOID
+ );
+
+#endif // _ACPI_TIMER_LIB_INTERNAL_H_
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c new file mode 100644 index 000000000..7c593e8be --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c @@ -0,0 +1,103 @@ +/** @file
+ Provide constructor and GetTick for Base instance of ACPI Timer Library
+
+ Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/PciLib.h>
+#include <OvmfPlatforms.h>
+
+//
+// Cached ACPI Timer IO Address
+//
+STATIC UINT32 mAcpiTimerIoAddr;
+
+/**
+ The constructor function caches the ACPI tick counter address, and,
+ if necessary, enables ACPI IO space.
+
+ @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
+
+**/
+RETURN_STATUS
+EFIAPI
+AcpiTimerLibConstructor (
+ VOID
+ )
+{
+ UINT16 HostBridgeDevId;
+ UINTN Pmba;
+ UINT32 PmbaAndVal;
+ UINT32 PmbaOrVal;
+ UINTN AcpiCtlReg;
+ UINT8 AcpiEnBit;
+
+ //
+ // Query Host Bridge DID to determine platform type
+ //
+ HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
+ switch (HostBridgeDevId) {
+ case INTEL_82441_DEVICE_ID:
+ Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
+ PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;
+ PmbaOrVal = PIIX4_PMBA_VALUE;
+ AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);
+ AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;
+ break;
+ case INTEL_Q35_MCH_DEVICE_ID:
+ Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
+ PmbaAndVal = ~(UINT32)ICH9_PMBASE_MASK;
+ PmbaOrVal = ICH9_PMBASE_VALUE;
+ AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);
+ AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;
+ break;
+ default:
+ DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
+ __FUNCTION__, HostBridgeDevId));
+ ASSERT (FALSE);
+ return RETURN_UNSUPPORTED;
+ }
+
+ //
+ // Check to see if the Power Management Base Address is already enabled
+ //
+ if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {
+ //
+ // If the Power Management Base Address is not programmed,
+ // then program it now.
+ //
+ PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);
+
+ //
+ // Enable PMBA I/O port decodes
+ //
+ PciOr8 (AcpiCtlReg, AcpiEnBit);
+ }
+
+ mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;
+ return RETURN_SUCCESS;
+}
+
+/**
+ Internal function to read the current tick counter of ACPI.
+
+ Read the current ACPI tick counter using the counter address cached
+ by this instance's constructor.
+
+ @return The tick counter read.
+
+**/
+UINT32
+InternalAcpiGetTimerTick (
+ VOID
+ )
+{
+ //
+ // Return the current ACPI timer value.
+ //
+ return IoRead32 (mAcpiTimerIoAddr);
+}
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf new file mode 100644 index 000000000..21bf79c33 --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf @@ -0,0 +1,32 @@ +## @file
+# Base ACPI Timer Library Instance.
+#
+# Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseAcpiTimerLib
+ FILE_GUID = FB648CF5-91BE-4737-9023-FD807AC6D96D
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = TimerLib|PEI_CORE PEIM DXE_CORE
+ CONSTRUCTOR = AcpiTimerLibConstructor
+
+[Sources]
+ AcpiTimerLib.c
+ AcpiTimerLib.h
+ BaseAcpiTimerLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ PciLib
+ IoLib
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLibBhyve.c b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLibBhyve.c new file mode 100644 index 000000000..f927e2718 --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLibBhyve.c @@ -0,0 +1,32 @@ +/** @file
+ Provide InternalAcpiGetTimerTick for the bhyve instance of the
+ Base ACPI Timer Library
+
+ Copyright (C) 2020, Rebecca Cran <rebecca@bsdio.com>
+ Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/IoLib.h>
+#include <OvmfPlatforms.h>
+
+/**
+ Internal function to read the current tick counter of ACPI.
+
+ Read the current ACPI tick counter using the counter address cached
+ by this instance's constructor.
+
+ @return The tick counter read.
+
+**/
+UINT32
+InternalAcpiGetTimerTick (
+ VOID
+ )
+{
+ //
+ // Return the current ACPI timer value.
+ //
+ return IoRead32 (BHYVE_ACPI_TIMER_IO_ADDR);
+}
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLibBhyve.inf b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLibBhyve.inf new file mode 100644 index 000000000..14b7479e6 --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLibBhyve.inf @@ -0,0 +1,30 @@ +## @file
+# Base ACPI Timer Library Instance for Bhyve.
+#
+# Copyright (C) 2020, Rebecca Cran <rebecca@bsdio.com>
+# Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseAcpiTimerLibBhyve
+ FILE_GUID = A5E3B247-7302-11EA-9C04-3CECEF0C1C08
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = TimerLib
+
+[Sources]
+ AcpiTimerLib.c
+ AcpiTimerLib.h
+ BaseAcpiTimerLibBhyve.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ IoLib
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c new file mode 100644 index 000000000..52f3ea2db --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c @@ -0,0 +1,121 @@ +/** @file
+ Provide constructor and GetTick for BaseRom instance of ACPI Timer Library
+
+ Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/PciLib.h>
+#include <OvmfPlatforms.h>
+
+/**
+ The constructor function enables ACPI IO space.
+
+ If ACPI I/O space not enabled, this function will enable it.
+ It will always return RETURN_SUCCESS.
+
+ @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
+
+**/
+RETURN_STATUS
+EFIAPI
+AcpiTimerLibConstructor (
+ VOID
+ )
+{
+ UINT16 HostBridgeDevId;
+ UINTN Pmba;
+ UINT32 PmbaAndVal;
+ UINT32 PmbaOrVal;
+ UINTN AcpiCtlReg;
+ UINT8 AcpiEnBit;
+
+ //
+ // Query Host Bridge DID to determine platform type
+ //
+ HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
+ switch (HostBridgeDevId) {
+ case INTEL_82441_DEVICE_ID:
+ Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
+ PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;
+ PmbaOrVal = PIIX4_PMBA_VALUE;
+ AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);
+ AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;
+ break;
+ case INTEL_Q35_MCH_DEVICE_ID:
+ Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
+ PmbaAndVal = ~(UINT32)ICH9_PMBASE_MASK;
+ PmbaOrVal = ICH9_PMBASE_VALUE;
+ AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);
+ AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;
+ break;
+ default:
+ DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
+ __FUNCTION__, HostBridgeDevId));
+ ASSERT (FALSE);
+ return RETURN_UNSUPPORTED;
+ }
+
+ //
+ // Check to see if the Power Management Base Address is already enabled
+ //
+ if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {
+ //
+ // If the Power Management Base Address is not programmed,
+ // then program it now.
+ //
+ PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);
+
+ //
+ // Enable PMBA I/O port decodes
+ //
+ PciOr8 (AcpiCtlReg, AcpiEnBit);
+ }
+
+ return RETURN_SUCCESS;
+}
+
+/**
+ Internal function to read the current tick counter of ACPI.
+
+ Dynamically compute the address of the ACPI tick counter based on the
+ properties of the underlying platform, to avoid relying on global variables.
+
+ @return The tick counter read.
+
+**/
+UINT32
+InternalAcpiGetTimerTick (
+ VOID
+ )
+{
+ UINT16 HostBridgeDevId;
+ UINTN Pmba;
+
+ //
+ // Query Host Bridge DID to determine platform type
+ //
+ HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
+ switch (HostBridgeDevId) {
+ case INTEL_82441_DEVICE_ID:
+ Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
+ break;
+ case INTEL_Q35_MCH_DEVICE_ID:
+ Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
+ break;
+ default:
+ DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
+ __FUNCTION__, HostBridgeDevId));
+ ASSERT (FALSE);
+ return 0;
+ }
+
+ //
+ // Read PMBA to read and return the current ACPI timer value.
+ //
+ return IoRead32 ((PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);
+}
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf new file mode 100644 index 000000000..8f9bedbfe --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf @@ -0,0 +1,31 @@ +## @file
+# BaseRom ACPI Timer Library Instance.
+#
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseRomAcpiTimerLib
+ FILE_GUID = CDD9D74F-213E-4c28-98F7-8B4A167DB936
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = TimerLib|SEC
+ CONSTRUCTOR = AcpiTimerLibConstructor
+
+[Sources]
+ AcpiTimerLib.c
+ AcpiTimerLib.h
+ BaseRomAcpiTimerLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ PciLib
+ IoLib
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c new file mode 100644 index 000000000..09076c0ad --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c @@ -0,0 +1,83 @@ +/** @file
+ Provide constructor and GetTick for Dxe instance of ACPI Timer Library
+
+ Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PciLib.h>
+#include <OvmfPlatforms.h>
+
+//
+// Cached ACPI Timer IO Address
+//
+STATIC UINT32 mAcpiTimerIoAddr;
+
+/**
+ The constructor function caches the ACPI tick counter address
+
+ At the time this constructor runs (DXE_CORE or later), ACPI IO space
+ has already been enabled by either PlatformPei or by the "Base"
+ instance of this library.
+ In order to avoid querying the underlying platform type during each
+ tick counter read operation, we cache the counter address during
+ initialization of this instance of the Timer Library.
+
+ @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
+
+**/
+RETURN_STATUS
+EFIAPI
+AcpiTimerLibConstructor (
+ VOID
+ )
+{
+ UINT16 HostBridgeDevId;
+ UINTN Pmba;
+
+ //
+ // Query Host Bridge DID to determine platform type
+ //
+ HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);
+ switch (HostBridgeDevId) {
+ case INTEL_82441_DEVICE_ID:
+ Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
+ break;
+ case INTEL_Q35_MCH_DEVICE_ID:
+ Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
+ break;
+ default:
+ DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
+ __FUNCTION__, HostBridgeDevId));
+ ASSERT (FALSE);
+ return RETURN_UNSUPPORTED;
+ }
+
+ mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;
+
+ return RETURN_SUCCESS;
+}
+
+/**
+ Internal function to read the current tick counter of ACPI.
+
+ Read the current ACPI tick counter using the counter address cached
+ by this instance's constructor.
+
+ @return The tick counter read.
+
+**/
+UINT32
+InternalAcpiGetTimerTick (
+ VOID
+ )
+{
+ //
+ // Return the current ACPI timer value.
+ //
+ return IoRead32 (mAcpiTimerIoAddr);
+}
diff --git a/roms/edk2/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf new file mode 100644 index 000000000..e29872add --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf @@ -0,0 +1,35 @@ +## @file
+# DXE ACPI Timer Library Instance.
+#
+# Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
+# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DxeAcpiTimerLib
+ FILE_GUID = 52DECA02-2EE8-4EAA-8EAD-1AB83F8A5955
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = TimerLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION SMM_CORE
+ CONSTRUCTOR = AcpiTimerLibConstructor
+
+[Sources]
+ AcpiTimerLib.c
+ AcpiTimerLib.h
+ DxeAcpiTimerLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[Pcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
+
+[LibraryClasses]
+ BaseLib
+ PciLib
+ IoLib
|