/* C Interrupt Handler called in the interrupt context when Source interrupt is active. */
VOID EFIAPI TimerInterruptHandler(IN HARDWARE_INTERRUPT_SOURCE Source, IN EFI_SYSTEM_CONTEXT SystemContext)
/* C Interrupt Handler called in the interrupt context when Source interrupt is active. */
VOID EFIAPI TimerInterruptHandler(IN HARDWARE_INTERRUPT_SOURCE Source, IN EFI_SYSTEM_CONTEXT SystemContext)
{
  EFI_TPL  OriginalTPL;
  UINT64   CurrentValue;
  UINT64   CompareValue;
  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
  gInterrupt->EndOfInterrupt (gInterrupt, Source);
  if ((ArmGenericTimerGetTimerCtrlReg ()) & ARM_ARCH_TIMER_ISTATUS) {
    if (mTimerNotifyFunction != 0) {
      mTimerNotifyFunction (mTimerPeriod * mElapsedPeriod);
    }
    CurrentValue = ArmGenericTimerGetSystemCount ();
    CompareValue = ArmGenericTimerGetCompareVal ();
    mElapsedPeriod = 0;
    do {
      CompareValue += mTimerTicks;
      mElapsedPeriod++;
    } while (CompareValue < CurrentValue);
    ArmGenericTimerSetCompareVal (CompareValue);
    ArmGenericTimerReenableTimer ();
    ArmInstructionSynchronizationBarrier ();
  }
  gBS->RestoreTPL (OriginalTPL);
}