/** @file\r
Code for debug timer to support debug agent library implementation.\r
\r
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2010 - 2015, 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
/**\r
Initialize CPU local APIC timer.\r
\r
+ @param[out] TimerFrequency Local APIC timer frequency returned.\r
+ @param[in] DumpFlag If TRUE, dump Local APIC timer's parameter.\r
+ \r
+ @return 32-bit Local APIC timer init count.\r
**/\r
-VOID\r
+UINT32\r
InitializeDebugTimer (\r
- VOID\r
+ OUT UINT32 *TimerFrequency,\r
+ IN BOOLEAN DumpFlag\r
)\r
{\r
UINTN ApicTimerDivisor;\r
UINT32 InitialCount;\r
+ UINT32 ApicTimerFrequency;\r
\r
GetApicTimerState (&ApicTimerDivisor, NULL, NULL);\r
-\r
+ ApicTimerFrequency = PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor;\r
//\r
// Cpu Local Apic timer interrupt frequency, it is set to 0.1s\r
//\r
InitialCount = (UINT32)DivU64x32 (\r
MultU64x64 (\r
- PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor,\r
- 100\r
+ ApicTimerFrequency,\r
+ DEBUG_TIMER_INTERVAL\r
),\r
- 1000\r
+ 1000000u\r
);\r
\r
InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);\r
\r
- if (MultiProcessorDebugSupport) {\r
- mDebugMpContext.DebugTimerInitCount = InitialCount;\r
+ if (DumpFlag) {\r
+ DEBUG ((EFI_D_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32(PcdFSBClock)));\r
+ DEBUG ((EFI_D_INFO, "Debug Timer: Divisor = %d\n", ApicTimerDivisor));\r
+ DEBUG ((EFI_D_INFO, "Debug Timer: Frequency = %d\n", ApicTimerFrequency));\r
+ DEBUG ((EFI_D_INFO, "Debug Timer: InitialCount = %d\n", InitialCount));\r
+ }\r
+ if (TimerFrequency != NULL) {\r
+ *TimerFrequency = ApicTimerFrequency;\r
}\r
+ return InitialCount;\r
}\r
\r
/**\r
IN BOOLEAN EnableStatus\r
)\r
{\r
- BOOLEAN OldInterruptState;\r
BOOLEAN OldDebugTimerInterruptState;\r
\r
- OldInterruptState = SaveAndDisableInterrupts ();\r
OldDebugTimerInterruptState = GetApicTimerInterruptState ();\r
- \r
- if (EnableStatus) {\r
- EnableApicTimerInterrupt ();\r
- } else {\r
- DisableApicTimerInterrupt ();\r
+\r
+ if (OldDebugTimerInterruptState != EnableStatus) {\r
+ if (EnableStatus) {\r
+ EnableApicTimerInterrupt ();\r
+ } else {\r
+ DisableApicTimerInterrupt ();\r
+ }\r
+ //\r
+ // Validate the Debug Timer interrupt state\r
+ // This will make additional delay after Local Apic Timer interrupt state is changed.\r
+ // Thus, CPU could handle the potential pending interrupt of Local Apic timer.\r
+ //\r
+ while (GetApicTimerInterruptState () != EnableStatus) {\r
+ CpuPause ();\r
+ }\r
}\r
\r
- SetInterruptState (OldInterruptState);\r
return OldDebugTimerInterruptState;\r
}\r
\r
+/**\r
+ Check if the timer is time out.\r
+ \r
+ @param[in] TimerCycle Timer total count.\r
+ @param[in] Timer The start timer from the begin.\r
+ @param[in] TimeoutTicker Ticker number need time out.\r
+\r
+ @return TRUE Timer time out occurs.\r
+ @retval FALSE Timer does not time out.\r
+\r
+**/\r
+BOOLEAN\r
+IsDebugTimerTimeout (\r
+ IN UINT32 TimerCycle,\r
+ IN UINT32 Timer,\r
+ IN UINT32 TimeoutTicker\r
+ )\r
+{\r
+ UINT64 CurrentTimer;\r
+ UINT64 Delta;\r
+\r
+ CurrentTimer = GetApicTimerCurrentCount ();\r
+\r
+ //\r
+ // This timer counter counts down. Check for roll over condition.\r
+ //\r
+ if (CurrentTimer < Timer) {\r
+ Delta = Timer - CurrentTimer;\r
+ } else {\r
+ //\r
+ // Handle one roll-over. \r
+ //\r
+ Delta = TimerCycle - (CurrentTimer - Timer);\r
+ }\r
+ \r
+ return (BOOLEAN) (Delta >= TimeoutTicker);\r
+}\r
+\r