2 Code for debug timer to support debug agent library implementation.
4 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "DebugAgent.h"
18 Initialize CPU local APIC timer.
20 @param[out] TimerFrequency Local APIC timer frequency returned.
22 @return 32-bit Local APIC timer init count.
25 InitializeDebugTimer (
26 OUT UINT32
*TimerFrequency
29 UINTN ApicTimerDivisor
;
31 UINT32 ApicTimerFrequency
;
33 GetApicTimerState (&ApicTimerDivisor
, NULL
, NULL
);
34 ApicTimerFrequency
= PcdGet32(PcdFSBClock
) / (UINT32
)ApicTimerDivisor
;
36 // Cpu Local Apic timer interrupt frequency, it is set to 0.1s
38 InitialCount
= (UINT32
)DivU64x32 (
46 InitializeApicTimer (ApicTimerDivisor
, InitialCount
, TRUE
, DEBUG_TIMER_VECTOR
);
48 DEBUG ((EFI_D_INFO
, "Debug Timer: FSB Clock = %d\n", PcdGet32(PcdFSBClock
)));
49 DEBUG ((EFI_D_INFO
, "Debug Timer: Divisor = %d\n", ApicTimerDivisor
));
50 DEBUG ((EFI_D_INFO
, "Debug Timer: Frequency = %d\n", ApicTimerFrequency
));
51 DEBUG ((EFI_D_INFO
, "Debug Timer: InitialCount = %d\n", InitialCount
));
53 if (TimerFrequency
!= NULL
) {
54 *TimerFrequency
= ApicTimerFrequency
;
60 Enable/Disable the interrupt of debug timer and return the interrupt state
61 prior to the operation.
63 If EnableStatus is TRUE, enable the interrupt of debug timer.
64 If EnableStatus is FALSE, disable the interrupt of debug timer.
66 @param[in] EnableStatus Enable/Disable.
68 @retval TRUE Debug timer interrupt were enabled on entry to this call.
69 @retval FALSE Debug timer interrupt were disabled on entry to this call.
74 SaveAndSetDebugTimerInterrupt (
75 IN BOOLEAN EnableStatus
78 BOOLEAN OldDebugTimerInterruptState
;
80 OldDebugTimerInterruptState
= GetApicTimerInterruptState ();
82 if (OldDebugTimerInterruptState
!= EnableStatus
) {
84 EnableApicTimerInterrupt ();
86 DisableApicTimerInterrupt ();
89 // Validate the Debug Timer interrupt state
90 // This will make additional delay after Local Apic Timer interrupt state is changed.
91 // Thus, CPU could handle the potential pending interrupt of Local Apic timer.
93 while (GetApicTimerInterruptState () != EnableStatus
) {
98 return OldDebugTimerInterruptState
;
102 Check if the timer is time out.
104 @param[in] TimerCycle Timer total count.
105 @param[in] Timer The start timer from the begin.
106 @param[in] TimeoutTicker Ticker number need time out.
108 @return TRUE Timer time out occurs.
109 @retval FALSE Timer does not time out.
113 IsDebugTimerTimeout (
114 IN UINT32 TimerCycle
,
116 IN UINT32 TimeoutTicker
122 CurrentTimer
= GetApicTimerCurrentCount ();
125 // This timer counter counts down. Check for roll over condition.
127 if (CurrentTimer
< Timer
) {
128 Delta
= Timer
- CurrentTimer
;
131 // Handle one roll-over.
133 Delta
= TimerCycle
- (CurrentTimer
- Timer
);
136 return (BOOLEAN
) (Delta
>= TimeoutTicker
);