Revision: 16377
          http://sourceforge.net/p/edk2/code/16377
Author:   jljusten
Date:     2014-11-14 00:38:35 +0000 (Fri, 14 Nov 2014)
Log Message:
-----------
OvmfPkg: AcpiTimerLib: Use global variable during PEI_CORE and PEIM

Since in OVMF both PEI_CORE and PEIM run from RAM, and thus may
utilize global variables, use the "Base" AcpiTimerLib instance
(instead of BaseRom) to take advantage of the improved efficiency
of storing the timer register IO address in a global variable.

This leaves only SEC using the BaseRomAcpiTimerLib instance.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Gabriel Somlo <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>

Modified Paths:
--------------
    trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c
    trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf
    trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
    trunk/edk2/OvmfPkg/OvmfPkgIa32.dsc
    trunk/edk2/OvmfPkg/OvmfPkgIa32X64.dsc
    trunk/edk2/OvmfPkg/OvmfPkgX64.dsc

Modified: trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c
===================================================================
--- trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c  2014-11-14 
00:38:17 UTC (rev 16376)
+++ trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c  2014-11-14 
00:38:35 UTC (rev 16377)
@@ -15,12 +15,14 @@
 #include <Library/DebugLib.h>
 #include <Library/IoLib.h>
 #include <Library/PciLib.h>
+#include <Library/PcdLib.h>
 #include <OvmfPlatforms.h>
 
 //
 // Power Management PCI Configuration Register fields
 //
 #define PMBA_RTE  BIT0
+#define PMIOSE    BIT0
 
 //
 // Offset in the Power Management Base Address to the ACPI Timer
@@ -33,15 +35,9 @@
 STATIC UINT32 mAcpiTimerIoAddr;
 
 /**
-  The constructor function caches the ACPI tick counter address
+  The constructor function caches the ACPI tick counter address, and,
+  if necessary, enables ACPI IO space.
 
-  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.
 
 **/
@@ -53,6 +49,7 @@
 {
   UINT16 HostBridgeDevId;
   UINTN Pmba;
+  UINTN PmRegMisc;
 
   //
   // Query Host Bridge DID to determine platform type
@@ -60,10 +57,12 @@
   HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
   switch (HostBridgeDevId) {
     case INTEL_82441_DEVICE_ID:
-      Pmba = POWER_MGMT_REGISTER_PIIX4 (0x40);
+      Pmba      = POWER_MGMT_REGISTER_PIIX4 (0x40);
+      PmRegMisc = POWER_MGMT_REGISTER_PIIX4 (0x80);
       break;
     case INTEL_Q35_MCH_DEVICE_ID:
-      Pmba = POWER_MGMT_REGISTER_Q35 (0x40);
+      Pmba      = POWER_MGMT_REGISTER_Q35 (0x40);
+      PmRegMisc = POWER_MGMT_REGISTER_Q35 (0x80);
       break;
     default:
       DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
@@ -74,6 +73,22 @@
 
   mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;
 
+  //
+  // 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) ~0xFFC0, PcdGet16 (PcdAcpiPmBaseAddress));
+
+    //
+    // Enable PMBA I/O port decodes in PMREGMISC
+    //
+    PciOr8 (PmRegMisc, PMIOSE);
+  }
+
   return RETURN_SUCCESS;
 }
 

Modified: trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf
===================================================================
--- trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf        
2014-11-14 00:38:17 UTC (rev 16376)
+++ trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf        
2014-11-14 00:38:35 UTC (rev 16377)
@@ -20,7 +20,7 @@
   FILE_GUID      = FB648CF5-91BE-4737-9023-FD807AC6D96D
   MODULE_TYPE    = BASE
   VERSION_STRING = 1.0
-  LIBRARY_CLASS  = TimerLib|DXE_CORE DXE_SMM_DRIVER UEFI_DRIVER 
UEFI_APPLICATION SMM_CORE
+  LIBRARY_CLASS  = TimerLib|PEI_CORE PEIM DXE_CORE DXE_SMM_DRIVER UEFI_DRIVER 
UEFI_APPLICATION SMM_CORE
   CONSTRUCTOR    = AcpiTimerLibConstructor
 
 [Sources]
@@ -31,6 +31,9 @@
   MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
 
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdAcpiPmBaseAddress
+
 [LibraryClasses]
   BaseLib
   PciLib

Modified: trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
===================================================================
--- trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf     
2014-11-14 00:38:17 UTC (rev 16376)
+++ trunk/edk2/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf     
2014-11-14 00:38:35 UTC (rev 16377)
@@ -19,7 +19,7 @@
   FILE_GUID      = CDD9D74F-213E-4c28-98F7-8B4A167DB936
   MODULE_TYPE    = BASE
   VERSION_STRING = 1.0
-  LIBRARY_CLASS  = TimerLib|SEC PEI_CORE PEIM
+  LIBRARY_CLASS  = TimerLib|SEC
   CONSTRUCTOR    = AcpiTimerLibConstructor
 
 [Sources]

Modified: trunk/edk2/OvmfPkg/OvmfPkgIa32.dsc
===================================================================
--- trunk/edk2/OvmfPkg/OvmfPkgIa32.dsc  2014-11-14 00:38:17 UTC (rev 16376)
+++ trunk/edk2/OvmfPkg/OvmfPkgIa32.dsc  2014-11-14 00:38:35 UTC (rev 16377)
@@ -150,7 +150,6 @@
   
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
@@ -167,7 +166,6 @@
   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

Modified: trunk/edk2/OvmfPkg/OvmfPkgIa32X64.dsc
===================================================================
--- trunk/edk2/OvmfPkg/OvmfPkgIa32X64.dsc       2014-11-14 00:38:17 UTC (rev 
16376)
+++ trunk/edk2/OvmfPkg/OvmfPkgIa32X64.dsc       2014-11-14 00:38:35 UTC (rev 
16377)
@@ -155,7 +155,6 @@
   
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
@@ -172,7 +171,6 @@
   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

Modified: trunk/edk2/OvmfPkg/OvmfPkgX64.dsc
===================================================================
--- trunk/edk2/OvmfPkg/OvmfPkgX64.dsc   2014-11-14 00:38:17 UTC (rev 16376)
+++ trunk/edk2/OvmfPkg/OvmfPkgX64.dsc   2014-11-14 00:38:35 UTC (rev 16377)
@@ -155,7 +155,6 @@
   
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
@@ -172,7 +171,6 @@
   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


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to