]>
Commit | Line | Data |
---|---|---|
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 |
86d13652 | 21 | @param[in] DumpFlag If TRUE, dump Local APIC timer's parameter.\r |
08021523 | 22 | \r |
4fe43eb3 | 23 | @return 32-bit Local APIC timer init count.\r |
18b144ea | 24 | **/\r |
4fe43eb3 | 25 | UINT32\r |
18b144ea | 26 | InitializeDebugTimer (\r |
86d13652 JF |
27 | OUT UINT32 *TimerFrequency,\r |
28 | IN BOOLEAN DumpFlag\r | |
18b144ea | 29 | )\r |
30 | {\r | |
31 | UINTN ApicTimerDivisor;\r | |
32 | UINT32 InitialCount;\r | |
08021523 | 33 | UINT32 ApicTimerFrequency;\r |
18b144ea | 34 | \r |
35 | GetApicTimerState (&ApicTimerDivisor, NULL, NULL);\r | |
08021523 | 36 | ApicTimerFrequency = PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor;\r |
18b144ea | 37 | //\r |
38 | // Cpu Local Apic timer interrupt frequency, it is set to 0.1s\r | |
39 | //\r | |
40 | InitialCount = (UINT32)DivU64x32 (\r | |
41 | MultU64x64 (\r | |
08021523 JF |
42 | ApicTimerFrequency,\r |
43 | DEBUG_TIMER_INTERVAL\r | |
18b144ea | 44 | ),\r |
08021523 | 45 | 1000000u\r |
18b144ea | 46 | );\r |
47 | \r | |
48 | InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);\r | |
49 | \r | |
86d13652 JF |
50 | if (DumpFlag) {\r |
51 | DEBUG ((EFI_D_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32(PcdFSBClock)));\r | |
52 | DEBUG ((EFI_D_INFO, "Debug Timer: Divisor = %d\n", ApicTimerDivisor));\r | |
53 | DEBUG ((EFI_D_INFO, "Debug Timer: Frequency = %d\n", ApicTimerFrequency));\r | |
54 | DEBUG ((EFI_D_INFO, "Debug Timer: InitialCount = %d\n", InitialCount));\r | |
55 | }\r | |
08021523 JF |
56 | if (TimerFrequency != NULL) {\r |
57 | *TimerFrequency = ApicTimerFrequency;\r | |
58 | }\r | |
4fe43eb3 | 59 | return InitialCount;\r |
18b144ea | 60 | }\r |
61 | \r | |
62 | /**\r | |
63 | Enable/Disable the interrupt of debug timer and return the interrupt state\r | |
64 | prior to the operation.\r | |
65 | \r | |
66 | If EnableStatus is TRUE, enable the interrupt of debug timer.\r | |
67 | If EnableStatus is FALSE, disable the interrupt of debug timer.\r | |
68 | \r | |
69 | @param[in] EnableStatus Enable/Disable.\r | |
70 | \r | |
71 | @retval TRUE Debug timer interrupt were enabled on entry to this call.\r | |
72 | @retval FALSE Debug timer interrupt were disabled on entry to this call.\r | |
73 | \r | |
74 | **/\r | |
75 | BOOLEAN\r | |
76 | EFIAPI\r | |
77 | SaveAndSetDebugTimerInterrupt (\r | |
78 | IN BOOLEAN EnableStatus\r | |
79 | )\r | |
80 | {\r | |
18b144ea | 81 | BOOLEAN OldDebugTimerInterruptState;\r |
82 | \r | |
18b144ea | 83 | OldDebugTimerInterruptState = GetApicTimerInterruptState ();\r |
4fe43eb3 | 84 | \r |
b422b62c | 85 | if (OldDebugTimerInterruptState != EnableStatus) {\r |
86 | if (EnableStatus) {\r | |
87 | EnableApicTimerInterrupt ();\r | |
88 | } else {\r | |
89 | DisableApicTimerInterrupt ();\r | |
90 | }\r | |
91 | //\r | |
92 | // Validate the Debug Timer interrupt state\r | |
93 | // This will make additional delay after Local Apic Timer interrupt state is changed.\r | |
94 | // Thus, CPU could handle the potential pending interrupt of Local Apic timer.\r | |
95 | //\r | |
96 | while (GetApicTimerInterruptState () != EnableStatus) {\r | |
97 | CpuPause ();\r | |
98 | }\r | |
18b144ea | 99 | }\r |
4fe43eb3 | 100 | \r |
18b144ea | 101 | return OldDebugTimerInterruptState;\r |
102 | }\r | |
103 | \r | |
08021523 JF |
104 | /**\r |
105 | Check if the timer is time out.\r | |
106 | \r | |
107 | @param[in] TimerCycle Timer total count.\r | |
108 | @param[in] Timer The start timer from the begin.\r | |
109 | @param[in] TimeoutTicker Ticker number need time out.\r | |
110 | \r | |
111 | @return TRUE Timer time out occurs.\r | |
112 | @retval FALSE Timer does not time out.\r | |
113 | \r | |
114 | **/\r | |
115 | BOOLEAN\r | |
116 | IsDebugTimerTimeout (\r | |
117 | IN UINT32 TimerCycle,\r | |
118 | IN UINT32 Timer,\r | |
119 | IN UINT32 TimeoutTicker\r | |
120 | )\r | |
121 | {\r | |
122 | UINT64 CurrentTimer;\r | |
123 | UINT64 Delta;\r | |
124 | \r | |
125 | CurrentTimer = GetApicTimerCurrentCount ();\r | |
126 | \r | |
127 | //\r | |
128 | // This timer counter counts down. Check for roll over condition.\r | |
129 | //\r | |
130 | if (CurrentTimer < Timer) {\r | |
131 | Delta = Timer - CurrentTimer;\r | |
132 | } else {\r | |
133 | //\r | |
134 | // Handle one roll-over. \r | |
135 | //\r | |
136 | Delta = TimerCycle - (CurrentTimer - Timer);\r | |
137 | }\r | |
138 | \r | |
139 | return (BOOLEAN) (Delta >= TimeoutTicker);\r | |
140 | }\r | |
141 | \r |