2 Provide constructor and GetTick for Dxe instance of ACPI Timer Library
4 Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/DebugLib.h>
10 #include <Library/IoLib.h>
11 #include <Library/PcdLib.h>
12 #include <Library/PciLib.h>
13 #include <OvmfPlatforms.h>
16 // Cached ACPI Timer IO Address
18 STATIC UINT32 mAcpiTimerIoAddr
;
21 The constructor function caches the ACPI tick counter address
23 At the time this constructor runs (DXE_CORE or later), ACPI IO space
24 has already been enabled by either PlatformPei or by the "Base"
25 instance of this library.
26 In order to avoid querying the underlying platform type during each
27 tick counter read operation, we cache the counter address during
28 initialization of this instance of the Timer Library.
30 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
35 AcpiTimerLibConstructor (
39 UINT16 HostBridgeDevId
;
43 // Query Host Bridge DID to determine platform type
45 HostBridgeDevId
= PcdGet16 (PcdOvmfHostBridgePciDevId
);
46 switch (HostBridgeDevId
) {
47 case INTEL_82441_DEVICE_ID
:
48 Pmba
= POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA
);
50 case INTEL_Q35_MCH_DEVICE_ID
:
51 Pmba
= POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE
);
56 "%a: Unknown Host Bridge Device ID: 0x%04x\n",
61 return RETURN_UNSUPPORTED
;
64 mAcpiTimerIoAddr
= (PciRead32 (Pmba
) & ~PMBA_RTE
) + ACPI_TIMER_OFFSET
;
66 return RETURN_SUCCESS
;
70 Internal function to read the current tick counter of ACPI.
72 Read the current ACPI tick counter using the counter address cached
73 by this instance's constructor.
75 @return The tick counter read.
79 InternalAcpiGetTimerTick (
84 // Return the current ACPI timer value.
86 return IoRead32 (mAcpiTimerIoAddr
);