]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/SecPeiDxeTimerLibCpu/X86TimerLib.c
Minor grammatical work--mostly adding periods. Items with ONLY period added did...
[mirror_edk2.git] / MdePkg / Library / SecPeiDxeTimerLibCpu / X86TimerLib.c
index 7319524596f493baa2622f6ca2e83af23c2c3617..6d4b0938e9de6ee345e891ef820ddca97b8a3a5a 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
   Timer Library functions built upon local APIC on IA32/x64.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
+  http://opensource.org/licenses/bsd-license.php.\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 #include <Library/BaseLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
 \r
+#define APIC_LVTERR     0x370\r
+#define APIC_TMICT      0x380\r
+#define APIC_TMCCT      0x390\r
+#define APIC_TDCR       0x3e0\r
 \r
 //\r
 // The following array is used in calculating the frequency of local APIC\r
@@ -62,7 +67,7 @@ InternalX86GetTimerFrequency (
 {\r
   return\r
     PcdGet32(PcdFSBClock) /\r
-    mTimerLibLocalApicDivisor[MmioBitFieldRead32 (ApicBase + 0x3e0, 0, 3)];\r
+    mTimerLibLocalApicDivisor[MmioBitFieldRead32 (ApicBase + APIC_TDCR, 0, 3)];\r
 }\r
 \r
 /**\r
@@ -79,7 +84,7 @@ InternalX86GetTimerTick (
   IN      UINTN                     ApicBase\r
   )\r
 {\r
-  return MmioRead32 (ApicBase + 0x390);\r
+  return MmioRead32 (ApicBase + APIC_TMCCT);\r
 }\r
 \r
 /**\r
@@ -100,6 +105,7 @@ InternalX86Delay (
   )\r
 {\r
   INT32                             Ticks;\r
+  UINT32                            PowerOfTwoCounter;\r
 \r
   //\r
   // The target timer count is calculated here\r
@@ -111,7 +117,10 @@ InternalX86Delay (
   // Delay > 2^31 could not be handled by this function\r
   // Timer wrap-arounds are handled correctly by this function\r
   //\r
-  while (InternalX86GetTimerTick (ApicBase) - Ticks >= 0);\r
+  PowerOfTwoCounter = GetPowerOfTwo32 (MmioRead32 (ApicBase + APIC_TMICT));\r
+  while (((UINT32)(InternalX86GetTimerTick (ApicBase) - Ticks) & PowerOfTwoCounter) == 0) {\r
+    CpuPause ();\r
+  }\r
 }\r
 \r
 /**\r
@@ -121,7 +130,7 @@ InternalX86Delay (
 \r
   @param  MicroSeconds  The minimum number of microseconds to delay.\r
 \r
-  @return MicroSeconds\r
+  @return The value of MicroSeconds inputted.\r
 \r
 **/\r
 UINTN\r
@@ -153,7 +162,7 @@ MicroSecondDelay (
 \r
   @param  NanoSeconds The minimum number of nanoseconds to delay.\r
 \r
-  @return NanoSeconds\r
+  @return The value of NanoSeconds inputted.\r
 \r
 **/\r
 UINTN\r
@@ -181,8 +190,7 @@ NanoSecondDelay (
 /**\r
   Retrieves the current value of a 64-bit free running performance counter.\r
 \r
-  Retrieves the current value of a 64-bit free running performance counter. The\r
-  counter can either count up by 1 or count down by 1. If the physical\r
+  The counter can either count up by 1 or count down by 1. If the physical\r
   performance counter counts by a larger increment, then the counter values\r
   must be translated. The properties of the counter can be retrieved from\r
   GetPerformanceCounterProperties().\r
@@ -234,12 +242,16 @@ GetPerformanceCounterProperties (
   ApicBase = InternalX86GetApicBase ();\r
 \r
   if (StartValue != NULL) {\r
-    *StartValue = MmioRead32 (ApicBase + 0x380);\r
+    *StartValue = MmioRead32 (ApicBase + APIC_TMICT);\r
+    //\r
+    // make sure StartValue is all 1s from High Bit\r
+    //\r
+    ASSERT ((*StartValue & (*StartValue + 1)) == 0);\r
   }\r
 \r
   if (EndValue != NULL) {\r
     *EndValue = 0;\r
   }\r
 \r
-  return (UINT64) InternalX86GetTimerFrequency (ApicBase);;\r
+  return (UINT64) InternalX86GetTimerFrequency (ApicBase);\r
 }\r