summaryrefslogtreecommitdiff
path: root/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c
diff options
context:
space:
mode:
authorGabriel Somlo <somlo@cmu.edu>2014-11-14 00:38:17 +0000
committerjljusten <jljusten@Edk2>2014-11-14 00:38:17 +0000
commit170ef2d91612350fd1d1bac9d77b3ce0bffda714 (patch)
treefa1e67115eefa994c76501526e67940dabc18f97 /OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c
parent72a1100171a627ce26789c193ca7036eb8a5364a (diff)
downloadedk2-platforms-170ef2d91612350fd1d1bac9d77b3ce0bffda714.tar.xz
OvmfPkg: AcpiTimerLib: Split into multiple phase-specific instances
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
Diffstat (limited to 'OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c')
-rw-r--r--OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c147
1 files changed, 2 insertions, 145 deletions
diff --git a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c
index 7d324cb815..938b77cdc6 100644
--- a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c
+++ b/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c
@@ -14,160 +14,17 @@
**/
-#include <Base.h>
-#include <Library/TimerLib.h>
-#include <Library/BaseLib.h>
-#include <Library/IoLib.h>
-#include <Library/PciLib.h>
#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-#include <IndustryStandard/Pci22.h>
+#include <Library/BaseLib.h>
#include <IndustryStandard/Acpi.h>
-//
-// PCI Location of PIIX4 Power Management PCI Configuration Registers
-//
-#define PIIX4_POWER_MANAGEMENT_BUS 0x00
-#define PIIX4_POWER_MANAGEMENT_DEVICE 0x01
-#define PIIX4_POWER_MANAGEMENT_FUNCTION 0x03
-
-//
-// Macro to access PIIX4 Power Management PCI Configuration Registers
-//
-#define PIIX4_PCI_POWER_MANAGEMENT_REGISTER(Register) \
- PCI_LIB_ADDRESS ( \
- PIIX4_POWER_MANAGEMENT_BUS, \
- PIIX4_POWER_MANAGEMENT_DEVICE, \
- PIIX4_POWER_MANAGEMENT_FUNCTION, \
- Register \
- )
-
-//
-// PCI Location of Q35 Power Management PCI Configuration Registers
-//
-#define Q35_POWER_MANAGEMENT_BUS 0x00
-#define Q35_POWER_MANAGEMENT_DEVICE 0x1f
-#define Q35_POWER_MANAGEMENT_FUNCTION 0x00
-
-//
-// Macro to access Q35 Power Management PCI Configuration Registers
-//
-#define Q35_PCI_POWER_MANAGEMENT_REGISTER(Register) \
- PCI_LIB_ADDRESS ( \
- Q35_POWER_MANAGEMENT_BUS, \
- Q35_POWER_MANAGEMENT_DEVICE, \
- Q35_POWER_MANAGEMENT_FUNCTION, \
- Register \
- )
-
-//
-// PCI Location of Host Bridge PCI Configuration Registers
-//
-#define HOST_BRIDGE_BUS 0x00
-#define HOST_BRIDGE_DEVICE 0x00
-#define HOST_BRIDGE_FUNCTION 0x00
-
-//
-// Macro to access Host Bridge Configuration Registers
-//
-#define HOST_BRIDGE_REGISTER(Register) \
- PCI_LIB_ADDRESS ( \
- HOST_BRIDGE_BUS, \
- HOST_BRIDGE_DEVICE, \
- HOST_BRIDGE_FUNCTION, \
- Register \
- )
-
-//
-// Host Bridge Device ID (DID) Register
-//
-#define HOST_BRIDGE_DID HOST_BRIDGE_REGISTER (0x02)
-
-//
-// Host Bridge DID Register values
-//
-#define PCI_DEVICE_ID_INTEL_82441 0x1237 // DID value for PIIX4
-#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29C0 // DID value for Q35
-
-//
-// Access Power Management PCI Config Regs based on Host Bridge type
-//
-#define PCI_POWER_MANAGEMENT_REGISTER(Register) \
- ((PciRead16 (HOST_BRIDGE_DID) == PCI_DEVICE_ID_INTEL_Q35_MCH) ? \
- Q35_PCI_POWER_MANAGEMENT_REGISTER (Register) : \
- PIIX4_PCI_POWER_MANAGEMENT_REGISTER (Register))
-
-//
-// Power Management PCI Configuration Registers
-//
-#define PMBA PCI_POWER_MANAGEMENT_REGISTER (0x40)
-#define PMBA_RTE BIT0
-#define PMREGMISC PCI_POWER_MANAGEMENT_REGISTER (0x80)
-#define PMIOSE BIT0
+#include "AcpiTimerLib.h"
//
// The ACPI Time is a 24-bit counter
//
#define ACPI_TIMER_COUNT_SIZE BIT24
-//
-// Offset in the Power Management Base Address to the ACPI Timer
-//
-#define ACPI_TIMER_OFFSET 0x8
-
-/**
- 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
- )
-{
- //
- // Check to see if the Power Management Base Address is already enabled
- //
- if ((PciRead8 (PMREGMISC) & PMIOSE) == 0) {
- //
- // If the Power Management Base Address is not programmed,
- // then program the Power Management Base Address from a PCD.
- //
- PciAndThenOr32 (PMBA, (UINT32)(~0x0000FFC0), PcdGet16 (PcdAcpiPmBaseAddress));
-
- //
- // Enable PMBA I/O port decodes in PMREGMISC
- //
- PciOr8 (PMREGMISC, PMIOSE);
- }
-
- return RETURN_SUCCESS;
-}
-
-/**
- Internal function to read the current tick counter of ACPI.
-
- Internal function to read the current tick counter of ACPI.
-
- @return The tick counter read.
-
-**/
-UINT32
-InternalAcpiGetTimerTick (
- VOID
- )
-{
- //
- // Read PMBA to read and return the current ACPI timer value.
- //
- return IoRead32 ((PciRead32 (PMBA) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);
-}
-
/**
Stalls the CPU for at least the given number of ticks.