]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PcAtChipsetPkg/HpetTimerDxe/HpetTimer.c
PcAtChipsetPkg/HpetTimerDxe: Fix race condition in SetTimerPeriod()
[mirror_edk2.git] / PcAtChipsetPkg / HpetTimerDxe / HpetTimer.c
index b9bf080c74ea03b9b600887b9254137aef51888f..c62c3a9b2b98d23dd6f30f1bf291201af85fa2f2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Timer Architectural Protocol module using High Precesion Event Timer (HPET)\r
 \r
-  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\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
@@ -142,7 +142,7 @@ TimerDriverGetTimerPeriod (
   @param  This  The EFI_TIMER_ARCH_PROTOCOL instance.\r
 \r
   @retval  EFI_SUCCESS       The soft timer interrupt was generated.\r
-  @retval  EFI_UNSUPPORTEDT  The platform does not support the generation of soft \r
+  @retval  EFI_UNSUPPORTED   The platform does not support the generation of soft\r
                              timer interrupts.\r
 \r
 **/\r
@@ -492,11 +492,17 @@ TimerDriverSetTimerPeriod (
   IN UINT64                   TimerPeriod\r
   )\r
 {\r
+  EFI_TPL                        Tpl;\r
   UINT64                         MainCounter;\r
   UINT64                         Delta;\r
   UINT64                         CurrentComparator;\r
   HPET_TIMER_MSI_ROUTE_REGISTER  HpetTimerMsiRoute;\r
-  \r
+\r
+  //\r
+  // Disable interrupts\r
+  //\r
+  Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
   //\r
   // Disable HPET timer when adjusting the timer period\r
   //\r
@@ -594,6 +600,7 @@ TimerDriverSetTimerPeriod (
       // Program IOAPIC register with APIC ID of current BSP in case BSP has been switched\r
       //\r
       IoApicConfigureInterrupt (mTimerIrq, PcdGet8 (PcdHpetLocalApicVector), IO_APIC_DELIVERY_MODE_LOWEST_PRIORITY, TRUE, FALSE);\r
+      IoApicEnableInterrupt (mTimerIrq, TRUE);\r
     }\r
 \r
     //\r
@@ -615,7 +622,12 @@ TimerDriverSetTimerPeriod (
   // is disabled.\r
   //\r
   HpetEnable (TRUE);\r
-  \r
+\r
+  //\r
+  // Restore interrupts\r
+  //\r
+  gBS->RestoreTPL (Tpl);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -661,7 +673,7 @@ TimerDriverGetTimerPeriod (
   @param  This  The EFI_TIMER_ARCH_PROTOCOL instance.\r
 \r
   @retval  EFI_SUCCESS       The soft timer interrupt was generated.\r
-  @retval  EFI_UNSUPPORTEDT  The platform does not support the generation of soft \r
+  @retval  EFI_UNSUPPORTED   The platform does not support the generation of soft\r
                              timer interrupts.\r
 \r
 **/\r