]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / PcAtChipsetPkg / HpetTimerDxe / HpetTimer.c
index c62c3a9b2b98d23dd6f30f1bf291201af85fa2f2..427572c2ff6da4609d9ccd0b14aa59aa1ffdef16 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
-  Timer Architectural Protocol module using High Precesion Event Timer (HPET)\r
+  Timer Architectural Protocol module using High Precision Event Timer (HPET)\r
 \r
-  Copyright (c) 2011 - 2016, 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
-\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
+  Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
   is returned.\r
 \r
   @param  This            The EFI_TIMER_ARCH_PROTOCOL instance.\r
-  @param  NotifyFunction  The function to call when a timer interrupt fires.  \r
-                          This function executes at TPL_HIGH_LEVEL.  The DXE \r
-                          Core will register a handler for the timer interrupt, \r
-                          so it can know how much time has passed.  This \r
-                          information is used to signal timer based events.  \r
+  @param  NotifyFunction  The function to call when a timer interrupt fires.\r
+                          This function executes at TPL_HIGH_LEVEL.  The DXE\r
+                          Core will register a handler for the timer interrupt,\r
+                          so it can know how much time has passed.  This\r
+                          information is used to signal timer based events.\r
                           NULL will unregister the handler.\r
 \r
   @retval  EFI_SUCCESS            The timer handler was registered.\r
@@ -90,11 +84,11 @@ TimerDriverRegisterHandler (
 \r
   @param  This         The EFI_TIMER_ARCH_PROTOCOL instance.\r
   @param  TimerPeriod  The rate to program the timer interrupt in 100 nS units.\r
-                       If the timer hardware is not programmable, then \r
-                       EFI_UNSUPPORTED is returned.  If the timer is programmable, \r
-                       then the timer period will be rounded up to the nearest \r
-                       timer period that is supported by the timer hardware.  \r
-                       If TimerPeriod is set to 0, then the timer interrupts \r
+                       If the timer hardware is not programmable, then\r
+                       EFI_UNSUPPORTED is returned.  If the timer is programmable,\r
+                       then the timer period will be rounded up to the nearest\r
+                       timer period that is supported by the timer hardware.\r
+                       If TimerPeriod is set to 0, then the timer interrupts\r
                        will be disabled.\r
 \r
   @retval  EFI_SUCCESS       The timer period was changed.\r
@@ -126,8 +120,8 @@ TimerDriverSetTimerPeriod (
 EFI_STATUS\r
 EFIAPI\r
 TimerDriverGetTimerPeriod (\r
-  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
-  OUT UINT64                   *TimerPeriod\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  OUT UINT64                  *TimerPeriod\r
   );\r
 \r
 /**\r
@@ -151,11 +145,11 @@ EFIAPI
 TimerDriverGenerateSoftInterrupt (\r
   IN EFI_TIMER_ARCH_PROTOCOL  *This\r
   );\r
-  \r
+\r
 ///\r
 /// The handle onto which the Timer Architectural Protocol will be installed.\r
 ///\r
-EFI_HANDLE   mTimerHandle = NULL;\r
+EFI_HANDLE  mTimerHandle = NULL;\r
 \r
 ///\r
 /// The Timer Architectural Protocol that this driver produces.\r
@@ -222,7 +216,7 @@ HPET_GENERAL_CAPABILITIES_ID_REGISTER  mHpetGeneralCapabilities;
 HPET_GENERAL_CONFIGURATION_REGISTER  mHpetGeneralConfiguration;\r
 \r
 ///\r
-/// Cached state of the Configuration register for the HPET Timer managed by \r
+/// Cached state of the Configuration register for the HPET Timer managed by\r
 /// this driver.  Caching the state reduces the number of times the configuration\r
 /// register is read.\r
 ///\r
@@ -252,7 +246,7 @@ HpetRead (
 /**\r
   Write a 64-bit HPET register.\r
 \r
-  @param  Offset  Specifies the ofsfert of the HPET register to write.\r
+  @param  Offset  Specifies the offset of the HPET register to write.\r
   @param  Value   Specifies the value to write to the HPET register specified by Offset.\r
 \r
   @return  The 64-bit value written to HPET register specified by Offset.\r
@@ -277,7 +271,7 @@ HpetEnable (
   IN BOOLEAN  Enable\r
   )\r
 {\r
-  mHpetGeneralConfiguration.Bits.MainCounterEnable = Enable ? 1 : 0;  \r
+  mHpetGeneralConfiguration.Bits.MainCounterEnable = Enable ? 1 : 0;\r
   HpetWrite (HPET_GENERAL_CONFIGURATION_OFFSET, mHpetGeneralConfiguration.Uint64);\r
 }\r
 \r
@@ -286,16 +280,16 @@ HpetEnable (
   and computes the amount of time that has passed since the last HPET timer interrupt.\r
   If a notification function is registered, then the amount of time since the last\r
   HPET interrupt is passed to that notification function in 100 ns units.  The HPET\r
-  time is updated to generate another interrupt in the required time period. \r
+  time is updated to generate another interrupt in the required time period.\r
 \r
-  @param  InterruptType  The type of interrupt that occured.\r
-  @param  SystemContext  A pointer to the system context when the interrupt occured.\r
+  @param  InterruptType  The type of interrupt that occurred.\r
+  @param  SystemContext  A pointer to the system context when the interrupt occurred.\r
 **/\r
 VOID\r
 EFIAPI\r
 TimerInterruptHandler (\r
-  IN EFI_EXCEPTION_TYPE   InterruptType,\r
-  IN EFI_SYSTEM_CONTEXT   SystemContext\r
+  IN EFI_EXCEPTION_TYPE  InterruptType,\r
+  IN EFI_SYSTEM_CONTEXT  SystemContext\r
   )\r
 {\r
   UINT64  MainCounter;\r
@@ -306,7 +300,9 @@ TimerInterruptHandler (
   //\r
   // Count number of ticks\r
   //\r
-  DEBUG_CODE (mNumTicks++;);\r
+  DEBUG_CODE (\r
+    mNumTicks++;\r
+    );\r
 \r
   //\r
   // Clear HPET timer interrupt status\r
@@ -322,7 +318,7 @@ TimerInterruptHandler (
   // Disable HPET timer when adjusting the COMPARATOR value to prevent a missed interrupt\r
   //\r
   HpetEnable (FALSE);\r
-  \r
+\r
   //\r
   // Capture main counter value\r
   //\r
@@ -363,13 +359,13 @@ TimerInterruptHandler (
   // Enable the HPET counter once the new COMPARATOR value has been set.\r
   //\r
   HpetEnable (TRUE);\r
-  \r
+\r
   //\r
   // Check to see if there is a registered notification function\r
   //\r
   if (mTimerNotifyFunction != NULL) {\r
     //\r
-    // Compute time since last notification in 100 ns units (10 ^ -7) \r
+    // Compute time since last notification in 100 ns units (10 ^ -7)\r
     //\r
     if (MainCounter > mPreviousMainCounter) {\r
       //\r
@@ -382,21 +378,22 @@ TimerInterruptHandler (
       //\r
       Delta = (mCounterMask - mPreviousMainCounter) + MainCounter;\r
     }\r
+\r
     TimerPeriod = DivU64x32 (\r
                     MultU64x32 (\r
                       Delta & mCounterMask,\r
                       mHpetGeneralCapabilities.Bits.CounterClockPeriod\r
-                      ), \r
+                      ),\r
                     100000000\r
                     );\r
-                    \r
+\r
     //\r
     // Call registered notification function passing in the time since the last\r
     // interrupt in 100 ns units.\r
-    //    \r
+    //\r
     mTimerNotifyFunction (TimerPeriod);\r
   }\r
-  \r
+\r
   //\r
   // Save main counter value\r
   //\r
@@ -417,11 +414,11 @@ TimerInterruptHandler (
   is returned.\r
 \r
   @param  This            The EFI_TIMER_ARCH_PROTOCOL instance.\r
-  @param  NotifyFunction  The function to call when a timer interrupt fires.  \r
-                          This function executes at TPL_HIGH_LEVEL.  The DXE \r
-                          Core will register a handler for the timer interrupt, \r
-                          so it can know how much time has passed.  This \r
-                          information is used to signal timer based events.  \r
+  @param  NotifyFunction  The function to call when a timer interrupt fires.\r
+                          This function executes at TPL_HIGH_LEVEL.  The DXE\r
+                          Core will register a handler for the timer interrupt,\r
+                          so it can know how much time has passed.  This\r
+                          information is used to signal timer based events.\r
                           NULL will unregister the handler.\r
 \r
   @retval  EFI_SUCCESS            The timer handler was registered.\r
@@ -443,10 +440,11 @@ TimerDriverRegisterHandler (
   //\r
   // Check for invalid parameters\r
   //\r
-  if (NotifyFunction == NULL && mTimerNotifyFunction == NULL) {\r
+  if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  if (NotifyFunction != NULL && mTimerNotifyFunction != NULL) {\r
+\r
+  if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {\r
     return EFI_ALREADY_STARTED;\r
   }\r
 \r
@@ -473,11 +471,11 @@ TimerDriverRegisterHandler (
 \r
   @param  This         The EFI_TIMER_ARCH_PROTOCOL instance.\r
   @param  TimerPeriod  The rate to program the timer interrupt in 100 nS units.\r
-                       If the timer hardware is not programmable, then \r
-                       EFI_UNSUPPORTED is returned.  If the timer is programmable, \r
-                       then the timer period will be rounded up to the nearest \r
-                       timer period that is supported by the timer hardware.  \r
-                       If TimerPeriod is set to 0, then the timer interrupts \r
+                       If the timer hardware is not programmable, then\r
+                       EFI_UNSUPPORTED is returned.  If the timer is programmable,\r
+                       then the timer period will be rounded up to the nearest\r
+                       timer period that is supported by the timer hardware.\r
+                       If TimerPeriod is set to 0, then the timer interrupts\r
                        will be disabled.\r
 \r
   @retval  EFI_SUCCESS       The timer period was changed.\r
@@ -507,7 +505,7 @@ TimerDriverSetTimerPeriod (
   // Disable HPET timer when adjusting the timer period\r
   //\r
   HpetEnable (FALSE);\r
-  \r
+\r
   if (TimerPeriod == 0) {\r
     if (mTimerPeriod != 0) {\r
       //\r
@@ -516,9 +514,10 @@ TimerDriverSetTimerPeriod (
       MainCounter = HpetRead (HPET_MAIN_COUNTER_OFFSET);\r
       if (MainCounter < mPreviousMainCounter) {\r
         Delta = (mCounterMask - mPreviousMainCounter) + MainCounter;\r
-      } else { \r
+      } else {\r
         Delta = MainCounter - mPreviousMainCounter;\r
       }\r
+\r
       if ((Delta & mCounterMask) >= mTimerCount) {\r
         //\r
         // Interrupt still happens after disable HPET, wait to be processed\r
@@ -527,7 +526,7 @@ TimerDriverSetTimerPeriod (
         CurrentComparator = HpetRead (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);\r
         while (CurrentComparator == mPreviousComparator) {\r
           CurrentComparator = HpetRead (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);\r
-          CpuPause();\r
+          CpuPause ();\r
         }\r
       }\r
     }\r
@@ -535,8 +534,8 @@ TimerDriverSetTimerPeriod (
     //\r
     // If TimerPeriod is 0, then mask HPET Timer interrupts\r
     //\r
-    \r
-    if (mTimerConfiguration.Bits.MsiInterruptCapablity != 0 && FeaturePcdGet (PcdHpetMsiEnable)) {\r
+\r
+    if ((mTimerConfiguration.Bits.MsiInterruptCapability != 0) && FeaturePcdGet (PcdHpetMsiEnable)) {\r
       //\r
       // Disable HPET MSI interrupt generation\r
       //\r
@@ -547,18 +546,18 @@ TimerDriverSetTimerPeriod (
       //\r
       IoApicEnableInterrupt (mTimerIrq, FALSE);\r
     }\r
-    \r
+\r
     //\r
-    // Disable HPET timer interrupt \r
+    // Disable HPET timer interrupt\r
     //\r
     mTimerConfiguration.Bits.InterruptEnable = 0;\r
     HpetWrite (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE, mTimerConfiguration.Uint64);\r
   } else {\r
     //\r
-    // Convert TimerPeriod to femtoseconds and divide by the number if femtoseconds \r
+    // Convert TimerPeriod to femtoseconds and divide by the number if femtoseconds\r
     // per tick of the HPET counter to determine the number of HPET counter ticks\r
     // in TimerPeriod 100 ns units.\r
-    // \r
+    //\r
     mTimerCount = DivU64x32 (\r
                     MultU64x32 (TimerPeriod, 100000000),\r
                     mHpetGeneralCapabilities.Bits.CounterClockPeriod\r
@@ -570,19 +569,20 @@ TimerDriverSetTimerPeriod (
     MainCounter = HpetRead (HPET_MAIN_COUNTER_OFFSET);\r
     if (MainCounter > mPreviousMainCounter) {\r
       Delta = MainCounter - mPreviousMainCounter;\r
-    } else { \r
+    } else {\r
       Delta = (mCounterMask - mPreviousMainCounter) + MainCounter;\r
     }\r
+\r
     if ((Delta & mCounterMask) >= mTimerCount) {\r
       HpetWrite (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE, (MainCounter + 1) & mCounterMask);\r
-    } else {  \r
+    } else {\r
       HpetWrite (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE, (mPreviousMainCounter + mTimerCount) & mCounterMask);\r
     }\r
-    \r
+\r
     //\r
     // Enable HPET Timer interrupt generation\r
     //\r
-    if (mTimerConfiguration.Bits.MsiInterruptCapablity != 0 && FeaturePcdGet (PcdHpetMsiEnable)) {\r
+    if ((mTimerConfiguration.Bits.MsiInterruptCapability != 0) && FeaturePcdGet (PcdHpetMsiEnable)) {\r
       //\r
       // Program MSI Address and MSI Data values in the selected HPET Timer\r
       // Program HPET register with APIC ID of current BSP in case BSP has been switched\r
@@ -609,7 +609,7 @@ TimerDriverSetTimerPeriod (
     mTimerConfiguration.Bits.InterruptEnable = 1;\r
     HpetWrite (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE, mTimerConfiguration.Uint64);\r
   }\r
-    \r
+\r
   //\r
   // Save the new timer period\r
   //\r
@@ -648,8 +648,8 @@ TimerDriverSetTimerPeriod (
 EFI_STATUS\r
 EFIAPI\r
 TimerDriverGetTimerPeriod (\r
-  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
-  OUT UINT64                   *TimerPeriod\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  OUT UINT64                  *TimerPeriod\r
   )\r
 {\r
   if (TimerPeriod == NULL) {\r
@@ -690,9 +690,9 @@ TimerDriverGenerateSoftInterrupt (
 \r
   //\r
   // Disable interrupts\r
-  //  \r
+  //\r
   Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
-  \r
+\r
   //\r
   // Capture main counter value\r
   //\r
@@ -703,7 +703,7 @@ TimerDriverGenerateSoftInterrupt (
   //\r
   if (mTimerNotifyFunction != NULL) {\r
     //\r
-    // Compute time since last interrupt in 100 ns units (10 ^ -7) \r
+    // Compute time since last interrupt in 100 ns units (10 ^ -7)\r
     //\r
     if (MainCounter > mPreviousMainCounter) {\r
       //\r
@@ -721,14 +721,14 @@ TimerDriverGenerateSoftInterrupt (
                     MultU64x32 (\r
                       Delta & mCounterMask,\r
                       mHpetGeneralCapabilities.Bits.CounterClockPeriod\r
-                      ), \r
+                      ),\r
                     100000000\r
                     );\r
-                    \r
+\r
     //\r
     // Call registered notification function passing in the time since the last\r
     // interrupt in 100 ns units.\r
-    //    \r
+    //\r
     mTimerNotifyFunction (TimerPeriod);\r
   }\r
 \r
@@ -736,12 +736,12 @@ TimerDriverGenerateSoftInterrupt (
   // Save main counter value\r
   //\r
   mPreviousMainCounter = MainCounter;\r
-  \r
+\r
   //\r
   // Restore interrupts\r
-  //  \r
+  //\r
   gBS->RestoreTPL (Tpl);\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -753,7 +753,7 @@ TimerDriverGenerateSoftInterrupt (
 \r
   @retval  EFI_SUCCESS           Timer Architectural Protocol created\r
   @retval  EFI_OUT_OF_RESOURCES  Not enough resources available to initialize driver.\r
-  @retval  EFI_DEVICE_ERROR      A device error occured attempting to initialize the driver.\r
+  @retval  EFI_DEVICE_ERROR      A device error occurred attempting to initialize the driver.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -763,10 +763,10 @@ TimerDriverInitialize (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
-  EFI_STATUS                             Status;\r
-  UINTN                                  TimerIndex;\r
-  UINTN                                  MsiTimerIndex;\r
-  HPET_TIMER_MSI_ROUTE_REGISTER          HpetTimerMsiRoute;\r
+  EFI_STATUS                     Status;\r
+  UINTN                          TimerIndex;\r
+  UINTN                          MsiTimerIndex;\r
+  HPET_TIMER_MSI_ROUTE_REGISTER  HpetTimerMsiRoute;\r
 \r
   DEBUG ((DEBUG_INFO, "Init HPET Timer Driver\n"));\r
 \r
@@ -778,22 +778,22 @@ TimerDriverInitialize (
   //\r
   // Find the CPU architectural protocol.\r
   //\r
-  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **) &mCpu);\r
+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&mCpu);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Retrieve HPET Capabilities and Configuration Information\r
-  //  \r
+  //\r
   mHpetGeneralCapabilities.Uint64  = HpetRead (HPET_GENERAL_CAPABILITIES_ID_OFFSET);\r
   mHpetGeneralConfiguration.Uint64 = HpetRead (HPET_GENERAL_CONFIGURATION_OFFSET);\r
\r
+\r
   //\r
-  // If Revision is not valid, then ASSERT() and unload the driver because the HPET \r
+  // If Revision is not valid, then ASSERT() and unload the driver because the HPET\r
   // device is not present.\r
-  //  \r
+  //\r
   ASSERT (mHpetGeneralCapabilities.Uint64 != 0);\r
   ASSERT (mHpetGeneralCapabilities.Uint64 != 0xFFFFFFFFFFFFFFFFULL);\r
-  if (mHpetGeneralCapabilities.Uint64 == 0 || mHpetGeneralCapabilities.Uint64 == 0xFFFFFFFFFFFFFFFFULL) {\r
+  if ((mHpetGeneralCapabilities.Uint64 == 0) || (mHpetGeneralCapabilities.Uint64 == 0xFFFFFFFFFFFFFFFFULL)) {\r
     DEBUG ((DEBUG_ERROR, "HPET device is not present.  Unload HPET driver.\n"));\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -805,30 +805,31 @@ TimerDriverInitialize (
 \r
   //\r
   // Dump HPET Configuration Information\r
-  //  \r
-  DEBUG_CODE (\r
-    DEBUG ((DEBUG_INFO, "HPET Base Address = 0x%08x\n", PcdGet32 (PcdHpetBaseAddress)));\r
-    DEBUG ((DEBUG_INFO, "  HPET_GENERAL_CAPABILITIES_ID  = 0x%016lx\n", mHpetGeneralCapabilities));\r
-    DEBUG ((DEBUG_INFO, "  HPET_GENERAL_CONFIGURATION    = 0x%016lx\n", mHpetGeneralConfiguration.Uint64));\r
-    DEBUG ((DEBUG_INFO, "  HPET_GENERAL_INTERRUPT_STATUS = 0x%016lx\n", HpetRead (HPET_GENERAL_INTERRUPT_STATUS_OFFSET)));\r
-    DEBUG ((DEBUG_INFO, "  HPET_MAIN_COUNTER             = 0x%016lx\n", HpetRead (HPET_MAIN_COUNTER_OFFSET)));\r
-    DEBUG ((DEBUG_INFO, "  HPET Main Counter Period      = %d (fs)\n", mHpetGeneralCapabilities.Bits.CounterClockPeriod));\r
-    for (TimerIndex = 0; TimerIndex <= mHpetGeneralCapabilities.Bits.NumberOfTimers; TimerIndex++) {\r
-      DEBUG ((DEBUG_INFO, "  HPET_TIMER%d_CONFIGURATION     = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + TimerIndex * HPET_TIMER_STRIDE)));\r
-      DEBUG ((DEBUG_INFO, "  HPET_TIMER%d_COMPARATOR        = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_COMPARATOR_OFFSET    + TimerIndex * HPET_TIMER_STRIDE)));\r
-      DEBUG ((DEBUG_INFO, "  HPET_TIMER%d_MSI_ROUTE         = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET     + TimerIndex * HPET_TIMER_STRIDE)));\r
-    }\r
-  );\r
-  \r
+  //\r
+  DEBUG_CODE_BEGIN ();\r
+  DEBUG ((DEBUG_INFO, "HPET Base Address = 0x%08x\n", PcdGet32 (PcdHpetBaseAddress)));\r
+  DEBUG ((DEBUG_INFO, "  HPET_GENERAL_CAPABILITIES_ID  = 0x%016lx\n", mHpetGeneralCapabilities));\r
+  DEBUG ((DEBUG_INFO, "  HPET_GENERAL_CONFIGURATION    = 0x%016lx\n", mHpetGeneralConfiguration.Uint64));\r
+  DEBUG ((DEBUG_INFO, "  HPET_GENERAL_INTERRUPT_STATUS = 0x%016lx\n", HpetRead (HPET_GENERAL_INTERRUPT_STATUS_OFFSET)));\r
+  DEBUG ((DEBUG_INFO, "  HPET_MAIN_COUNTER             = 0x%016lx\n", HpetRead (HPET_MAIN_COUNTER_OFFSET)));\r
+  DEBUG ((DEBUG_INFO, "  HPET Main Counter Period      = %d (fs)\n", mHpetGeneralCapabilities.Bits.CounterClockPeriod));\r
+  for (TimerIndex = 0; TimerIndex <= mHpetGeneralCapabilities.Bits.NumberOfTimers; TimerIndex++) {\r
+    DEBUG ((DEBUG_INFO, "  HPET_TIMER%d_CONFIGURATION     = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + TimerIndex * HPET_TIMER_STRIDE)));\r
+    DEBUG ((DEBUG_INFO, "  HPET_TIMER%d_COMPARATOR        = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_COMPARATOR_OFFSET    + TimerIndex * HPET_TIMER_STRIDE)));\r
+    DEBUG ((DEBUG_INFO, "  HPET_TIMER%d_MSI_ROUTE         = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET     + TimerIndex * HPET_TIMER_STRIDE)));\r
+  }\r
+\r
+  DEBUG_CODE_END ();\r
+\r
   //\r
   // Capture the current HPET main counter value.\r
   //\r
   mPreviousMainCounter = HpetRead (HPET_MAIN_COUNTER_OFFSET);\r
-  \r
+\r
   //\r
-  // Determine the interrupt mode to use for the HPET Timer.  \r
+  // Determine the interrupt mode to use for the HPET Timer.\r
   // Look for MSI first, then unused PIC mode interrupt, then I/O APIC mode interrupt\r
-  //  \r
+  //\r
   MsiTimerIndex = HPET_INVALID_TIMER_INDEX;\r
   mTimerIndex   = HPET_INVALID_TIMER_INDEX;\r
   for (TimerIndex = 0; TimerIndex <= mHpetGeneralCapabilities.Bits.NumberOfTimers; TimerIndex++) {\r
@@ -836,11 +837,11 @@ TimerDriverInitialize (
     // Read the HPET Timer Capabilities and Configuration register\r
     //\r
     mTimerConfiguration.Uint64 = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + TimerIndex * HPET_TIMER_STRIDE);\r
-    \r
+\r
     //\r
-    // Check to see if this HPET Timer supports MSI \r
+    // Check to see if this HPET Timer supports MSI\r
     //\r
-    if (mTimerConfiguration.Bits.MsiInterruptCapablity != 0) {\r
+    if (mTimerConfiguration.Bits.MsiInterruptCapability != 0) {\r
       //\r
       // Save the index of the first HPET Timer that supports MSI interrupts\r
       //\r
@@ -848,7 +849,7 @@ TimerDriverInitialize (
         MsiTimerIndex = TimerIndex;\r
       }\r
     }\r
-    \r
+\r
     //\r
     // Check to see if this HPET Timer supports I/O APIC interrupts\r
     //\r
@@ -863,11 +864,11 @@ TimerDriverInitialize (
     }\r
   }\r
 \r
-  if (FeaturePcdGet (PcdHpetMsiEnable) && MsiTimerIndex != HPET_INVALID_TIMER_INDEX) {\r
+  if (FeaturePcdGet (PcdHpetMsiEnable) && (MsiTimerIndex != HPET_INVALID_TIMER_INDEX)) {\r
     //\r
     // Use MSI interrupt if supported\r
     //\r
-    mTimerIndex  = MsiTimerIndex;\r
+    mTimerIndex = MsiTimerIndex;\r
 \r
     //\r
     // Program MSI Address and MSI Data values in the selected HPET Timer\r
@@ -880,7 +881,7 @@ TimerDriverInitialize (
     // Read the HPET Timer Capabilities and Configuration register and initialize for MSI mode\r
     //   Clear LevelTriggeredInterrupt to use edge triggered interrupts when in MSI mode\r
     //\r
-    mTimerConfiguration.Uint64 = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);\r
+    mTimerConfiguration.Uint64                       = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);\r
     mTimerConfiguration.Bits.LevelTriggeredInterrupt = 0;\r
   } else {\r
     //\r
@@ -891,7 +892,7 @@ TimerDriverInitialize (
       DEBUG ((DEBUG_ERROR, "No HPET timers support MSI or I/O APIC mode.  Unload HPET driver.\n"));\r
       return EFI_DEVICE_ERROR;\r
     }\r
-    \r
+\r
     //\r
     // Initialize I/O APIC entry for HPET Timer Interrupt\r
     //   Fixed Delivery Mode, Level Triggered, Asserted Low\r
@@ -904,22 +905,22 @@ TimerDriverInitialize (
     //   Set LevelTriggeredInterrupt to use level triggered interrupts when in I/O APIC mode\r
     //   Set InterruptRoute field based in mTimerIrq\r
     //\r
-    mTimerConfiguration.Uint64 = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);\r
+    mTimerConfiguration.Uint64                       = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);\r
     mTimerConfiguration.Bits.LevelTriggeredInterrupt = 1;\r
     mTimerConfiguration.Bits.InterruptRoute          = mTimerIrq;\r
   }\r
 \r
   //\r
   // Configure the selected HPET Timer with settings common to both MSI mode and I/O APIC mode\r
-  //   Clear InterruptEnable to keep interrupts disabled until full init is complete \r
-  //   Clear PeriodicInterruptEnable to use one-shot mode \r
-  //   Configure as a 32-bit counter  \r
+  //   Clear InterruptEnable to keep interrupts disabled until full init is complete\r
+  //   Clear PeriodicInterruptEnable to use one-shot mode\r
+  //   Configure as a 32-bit counter\r
   //\r
   mTimerConfiguration.Bits.InterruptEnable         = 0;\r
   mTimerConfiguration.Bits.PeriodicInterruptEnable = 0;\r
   mTimerConfiguration.Bits.CounterSizeEnable       = 1;\r
   HpetWrite (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE, mTimerConfiguration.Uint64);\r
-  \r
+\r
   //\r
   // Read the HPET Timer Capabilities and Configuration register back again.\r
   // CounterSizeEnable will be read back as a 0 if it is a 32-bit only timer\r
@@ -964,33 +965,37 @@ TimerDriverInitialize (
   //\r
   // Show state of enabled HPET timer\r
   //\r
-  DEBUG_CODE (\r
-    if (mTimerConfiguration.Bits.MsiInterruptCapablity != 0 && FeaturePcdGet (PcdHpetMsiEnable)) {\r
-      DEBUG ((DEBUG_INFO, "HPET Interrupt Mode MSI\n"));\r
-    } else {\r
-      DEBUG ((DEBUG_INFO, "HPET Interrupt Mode I/O APIC\n"));\r
-      DEBUG ((DEBUG_INFO, "HPET I/O APIC IRQ         = 0x%02x\n",  mTimerIrq));\r
-    }  \r
-    DEBUG ((DEBUG_INFO, "HPET Interrupt Vector     = 0x%02x\n",    PcdGet8 (PcdHpetLocalApicVector)));\r
-    DEBUG ((DEBUG_INFO, "HPET Counter Mask         = 0x%016lx\n",  mCounterMask));\r
-    DEBUG ((DEBUG_INFO, "HPET Timer Period         = %d\n",        mTimerPeriod));\r
-    DEBUG ((DEBUG_INFO, "HPET Timer Count          = 0x%016lx\n",  mTimerCount));\r
-    DEBUG ((DEBUG_INFO, "HPET_TIMER%d_CONFIGURATION = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE)));\r
-    DEBUG ((DEBUG_INFO, "HPET_TIMER%d_COMPARATOR    = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_COMPARATOR_OFFSET    + mTimerIndex * HPET_TIMER_STRIDE)));\r
-    DEBUG ((DEBUG_INFO, "HPET_TIMER%d_MSI_ROUTE     = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET     + mTimerIndex * HPET_TIMER_STRIDE)));\r
-\r
-    //\r
-    // Wait for a few timer interrupts to fire before continuing\r
-    // \r
-    while (mNumTicks < 10);\r
-  );\r
\r
+  DEBUG_CODE_BEGIN ();\r
+  if ((mTimerConfiguration.Bits.MsiInterruptCapability != 0) && FeaturePcdGet (PcdHpetMsiEnable)) {\r
+    DEBUG ((DEBUG_INFO, "HPET Interrupt Mode MSI\n"));\r
+  } else {\r
+    DEBUG ((DEBUG_INFO, "HPET Interrupt Mode I/O APIC\n"));\r
+    DEBUG ((DEBUG_INFO, "HPET I/O APIC IRQ         = 0x%02x\n", mTimerIrq));\r
+  }\r
+\r
+  DEBUG ((DEBUG_INFO, "HPET Interrupt Vector     = 0x%02x\n", PcdGet8 (PcdHpetLocalApicVector)));\r
+  DEBUG ((DEBUG_INFO, "HPET Counter Mask         = 0x%016lx\n", mCounterMask));\r
+  DEBUG ((DEBUG_INFO, "HPET Timer Period         = %d\n", mTimerPeriod));\r
+  DEBUG ((DEBUG_INFO, "HPET Timer Count          = 0x%016lx\n", mTimerCount));\r
+  DEBUG ((DEBUG_INFO, "HPET_TIMER%d_CONFIGURATION = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE)));\r
+  DEBUG ((DEBUG_INFO, "HPET_TIMER%d_COMPARATOR    = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_COMPARATOR_OFFSET    + mTimerIndex * HPET_TIMER_STRIDE)));\r
+  DEBUG ((DEBUG_INFO, "HPET_TIMER%d_MSI_ROUTE     = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET     + mTimerIndex * HPET_TIMER_STRIDE)));\r
+\r
+  //\r
+  // Wait for a few timer interrupts to fire before continuing\r
+  //\r
+  while (mNumTicks < 10) {\r
+  }\r
+\r
+  DEBUG_CODE_END ();\r
+\r
   //\r
   // Install the Timer Architectural Protocol onto a new handle\r
   //\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &mTimerHandle,\r
-                  &gEfiTimerArchProtocolGuid, &mTimer,\r
+                  &gEfiTimerArchProtocolGuid,\r
+                  &mTimer,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r