]> git.proxmox.com Git - mirror_edk2.git/blame - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
Add missing parameter in function header.
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugTimer.c
CommitLineData
18b144ea 1/** @file\r
2 Code for debug timer to support debug agent library implementation.\r
3\r
08021523 4 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
18b144ea 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "DebugAgent.h"\r
16\r
17/**\r
18 Initialize CPU local APIC timer.\r
19\r
99b98734 20 @param[out] TimerFrequency Local APIC timer frequency returned.\r
08021523 21 \r
4fe43eb3 22 @return 32-bit Local APIC timer init count.\r
18b144ea 23**/\r
4fe43eb3 24UINT32\r
18b144ea 25InitializeDebugTimer (\r
08021523 26 OUT UINT32 *TimerFrequency\r
18b144ea 27 )\r
28{\r
29 UINTN ApicTimerDivisor;\r
30 UINT32 InitialCount;\r
08021523 31 UINT32 ApicTimerFrequency;\r
18b144ea 32\r
33 GetApicTimerState (&ApicTimerDivisor, NULL, NULL);\r
08021523 34 ApicTimerFrequency = PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor;\r
18b144ea 35 //\r
36 // Cpu Local Apic timer interrupt frequency, it is set to 0.1s\r
37 //\r
38 InitialCount = (UINT32)DivU64x32 (\r
39 MultU64x64 (\r
08021523
JF
40 ApicTimerFrequency,\r
41 DEBUG_TIMER_INTERVAL\r
18b144ea 42 ),\r
08021523 43 1000000u\r
18b144ea 44 );\r
45\r
46 InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);\r
47\r
08021523
JF
48 DEBUG ((EFI_D_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32(PcdFSBClock))); \r
49 DEBUG ((EFI_D_INFO, "Debug Timer: Divisor = %d\n", ApicTimerDivisor)); \r
50 DEBUG ((EFI_D_INFO, "Debug Timer: Frequency = %d\n", ApicTimerFrequency)); \r
51 DEBUG ((EFI_D_INFO, "Debug Timer: InitialCount = %d\n", InitialCount)); \r
52\r
53 if (TimerFrequency != NULL) {\r
54 *TimerFrequency = ApicTimerFrequency;\r
55 }\r
4fe43eb3 56 return InitialCount;\r
18b144ea 57}\r
58\r
59/**\r
60 Enable/Disable the interrupt of debug timer and return the interrupt state\r
61 prior to the operation.\r
62\r
63 If EnableStatus is TRUE, enable the interrupt of debug timer.\r
64 If EnableStatus is FALSE, disable the interrupt of debug timer.\r
65\r
66 @param[in] EnableStatus Enable/Disable.\r
67\r
68 @retval TRUE Debug timer interrupt were enabled on entry to this call.\r
69 @retval FALSE Debug timer interrupt were disabled on entry to this call.\r
70\r
71**/\r
72BOOLEAN\r
73EFIAPI\r
74SaveAndSetDebugTimerInterrupt (\r
75 IN BOOLEAN EnableStatus\r
76 )\r
77{\r
18b144ea 78 BOOLEAN OldDebugTimerInterruptState;\r
79\r
18b144ea 80 OldDebugTimerInterruptState = GetApicTimerInterruptState ();\r
4fe43eb3 81\r
b422b62c 82 if (OldDebugTimerInterruptState != EnableStatus) {\r
83 if (EnableStatus) {\r
84 EnableApicTimerInterrupt ();\r
85 } else {\r
86 DisableApicTimerInterrupt ();\r
87 }\r
88 //\r
89 // Validate the Debug Timer interrupt state\r
90 // This will make additional delay after Local Apic Timer interrupt state is changed.\r
91 // Thus, CPU could handle the potential pending interrupt of Local Apic timer.\r
92 //\r
93 while (GetApicTimerInterruptState () != EnableStatus) {\r
94 CpuPause ();\r
95 }\r
18b144ea 96 }\r
4fe43eb3 97\r
18b144ea 98 return OldDebugTimerInterruptState;\r
99}\r
100\r
08021523
JF
101/**\r
102 Check if the timer is time out.\r
103 \r
104 @param[in] TimerCycle Timer total count.\r
105 @param[in] Timer The start timer from the begin.\r
106 @param[in] TimeoutTicker Ticker number need time out.\r
107\r
108 @return TRUE Timer time out occurs.\r
109 @retval FALSE Timer does not time out.\r
110\r
111**/\r
112BOOLEAN\r
113IsDebugTimerTimeout (\r
114 IN UINT32 TimerCycle,\r
115 IN UINT32 Timer,\r
116 IN UINT32 TimeoutTicker\r
117 )\r
118{\r
119 UINT64 CurrentTimer;\r
120 UINT64 Delta;\r
121\r
122 CurrentTimer = GetApicTimerCurrentCount ();\r
123\r
124 //\r
125 // This timer counter counts down. Check for roll over condition.\r
126 //\r
127 if (CurrentTimer < Timer) {\r
128 Delta = Timer - CurrentTimer;\r
129 } else {\r
130 //\r
131 // Handle one roll-over. \r
132 //\r
133 Delta = TimerCycle - (CurrentTimer - Timer);\r
134 }\r
135 \r
136 return (BOOLEAN) (Delta >= TimeoutTicker);\r
137}\r
138\r