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
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 59f0fce..5baec1c 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -57,7 +57,7 @@
 ################################################################################

 [LibraryClasses]

   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

-  TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf

+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf

   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

   BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf

   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf

@@ -131,6 +131,7 @@
 !endif

 

 [LibraryClasses.common.SEC]

+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf

   QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf

 !ifdef $(DEBUG_ON_SERIAL_PORT)

   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

@@ -149,6 +150,7 @@
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf

 

 [LibraryClasses.common.PEI_CORE]

+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf

   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf

   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

@@ -165,6 +167,7 @@
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf

 

 [LibraryClasses.common.PEIM]

+  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf

   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf

   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

@@ -203,6 +206,7 @@
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf

 

 [LibraryClasses.common.DXE_RUNTIME_DRIVER]

+  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf

   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

@@ -232,6 +236,7 @@
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf

 

 [LibraryClasses.common.DXE_DRIVER]

+  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf

   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf

   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

@@ -411,19 +416,10 @@
       PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf

   }

   PcAtChipsetPkg/KbcResetDxe/Reset.inf

-  MdeModulePkg/Universal/Metronome/Metronome.inf {

-    <LibraryClasses>

-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf

-  }

-

-  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf {

-    <LibraryClasses>

-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf

-  }

-

+  MdeModulePkg/Universal/Metronome/Metronome.inf

+  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf

   IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf {

     <LibraryClasses>

-      TimerLib|OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.inf

 !ifdef $(CSM_ENABLE)

       NULL|OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf

 !endif