TianoCore EDK2 master
Loading...
Searching...
No Matches
DebugTimer.c
Go to the documentation of this file.
1
9#include "DebugAgent.h"
10
19UINT32
21 OUT UINT32 *TimerFrequency,
22 IN BOOLEAN DumpFlag
23 )
24{
25 UINTN ApicTimerDivisor;
26 UINT32 InitialCount;
27 UINT32 ApicTimerFrequency;
28
30 GetApicTimerState (&ApicTimerDivisor, NULL, NULL);
31 ApicTimerFrequency = PcdGet32 (PcdFSBClock) / (UINT32)ApicTimerDivisor;
32 //
33 // Cpu Local Apic timer interrupt frequency, it is set to 0.1s
34 //
35 InitialCount = (UINT32)DivU64x32 (
37 ApicTimerFrequency,
38 DEBUG_TIMER_INTERVAL
39 ),
40 1000000u
41 );
42
43 InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);
44 //
45 // Disable Debug Timer interrupt to avoid it is delivered before Debug Port
46 // is initialized
47 //
49
50 if (DumpFlag) {
51 DEBUG ((DEBUG_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32 (PcdFSBClock)));
52 DEBUG ((DEBUG_INFO, "Debug Timer: Divisor = %d\n", ApicTimerDivisor));
53 DEBUG ((DEBUG_INFO, "Debug Timer: Frequency = %d\n", ApicTimerFrequency));
54 DEBUG ((DEBUG_INFO, "Debug Timer: InitialCount = %d\n", InitialCount));
55 }
56
57 if (TimerFrequency != NULL) {
58 *TimerFrequency = ApicTimerFrequency;
59 }
60
61 return InitialCount;
62}
63
77BOOLEAN
78EFIAPI
80 IN BOOLEAN EnableStatus
81 )
82{
83 BOOLEAN OldDebugTimerInterruptState;
84
85 OldDebugTimerInterruptState = GetApicTimerInterruptState ();
86
87 if (OldDebugTimerInterruptState != EnableStatus) {
88 if (EnableStatus) {
90 } else {
92 }
93
94 //
95 // Validate the Debug Timer interrupt state
96 // This will make additional delay after Local Apic Timer interrupt state is changed.
97 // Thus, CPU could handle the potential pending interrupt of Local Apic timer.
98 //
99 while (GetApicTimerInterruptState () != EnableStatus) {
100 CpuPause ();
101 }
102 }
103
104 return OldDebugTimerInterruptState;
105}
106
118BOOLEAN
120 IN UINT32 TimerCycle,
121 IN UINT32 Timer,
122 IN UINT32 TimeoutTicker
123 )
124{
125 UINT64 CurrentTimer;
126 UINT64 Delta;
127
128 CurrentTimer = GetApicTimerCurrentCount ();
129
130 //
131 // This timer counter counts down. Check for roll over condition.
132 // If CurrentTimer is equal to Timer, it does not mean that roll over
133 // happened.
134 //
135 if (CurrentTimer <= Timer) {
136 Delta = Timer - CurrentTimer;
137 } else {
138 //
139 // Handle one roll-over.
140 //
141 Delta = TimerCycle - (CurrentTimer - Timer) + 1;
142 }
143
144 return (BOOLEAN)(Delta >= TimeoutTicker);
145}
UINT64 UINTN
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
UINT64 EFIAPI MultU64x64(IN UINT64 Multiplicand, IN UINT64 Multiplier)
Definition: MultU64x64.c:27
VOID EFIAPI CpuPause(VOID)
BOOLEAN EFIAPI SaveAndSetDebugTimerInterrupt(IN BOOLEAN EnableStatus)
Definition: DebugTimer.c:79
UINT32 InitializeDebugTimer(OUT UINT32 *TimerFrequency, IN BOOLEAN DumpFlag)
Definition: DebugTimer.c:20
BOOLEAN IsDebugTimerTimeout(IN UINT32 TimerCycle, IN UINT32 Timer, IN UINT32 TimeoutTicker)
Definition: DebugTimer.c:119
VOID EFIAPI InitializeLocalApicSoftwareEnable(IN BOOLEAN Enable)
Definition: BaseXApicLib.c:600
BOOLEAN EFIAPI GetApicTimerInterruptState(VOID)
Definition: BaseXApicLib.c:870
VOID EFIAPI GetApicTimerState(OUT UINTN *DivideValue OPTIONAL, OUT BOOLEAN *PeriodicMode OPTIONAL, OUT UINT8 *Vector OPTIONAL)
Definition: BaseXApicLib.c:790
VOID EFIAPI EnableApicTimerInterrupt(VOID)
Definition: BaseXApicLib.c:835
VOID EFIAPI InitializeApicTimer(IN UINTN DivideValue, IN UINT32 InitCount, IN BOOLEAN PeriodicMode, IN UINT8 Vector)
Definition: BaseXApicLib.c:732
UINT32 EFIAPI GetApicTimerCurrentCount(VOID)
Definition: BaseXApicLib.c:712
VOID EFIAPI DisableApicTimerInterrupt(VOID)
Definition: BaseXApicLib.c:851
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet32(TokenName)
Definition: PcdLib.h:362