]> git.proxmox.com Git - mirror_edk2.git/blame - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
EDK II Contributions.txt: Update patch format information
[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
b422b62c 4 Copyright (c) 2010 - 2013, 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
20**/\r
21VOID\r
22InitializeDebugTimer (\r
23 VOID\r
24 )\r
25{\r
26 UINTN ApicTimerDivisor;\r
27 UINT32 InitialCount;\r
28\r
29 GetApicTimerState (&ApicTimerDivisor, NULL, NULL);\r
30\r
31 //\r
32 // Cpu Local Apic timer interrupt frequency, it is set to 0.1s\r
33 //\r
34 InitialCount = (UINT32)DivU64x32 (\r
35 MultU64x64 (\r
36 PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor,\r
37 100\r
38 ),\r
39 1000\r
40 );\r
41\r
42 InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);\r
43\r
b422b62c 44 if (MultiProcessorDebugSupport()) {\r
18b144ea 45 mDebugMpContext.DebugTimerInitCount = InitialCount;\r
46 }\r
47}\r
48\r
49/**\r
50 Enable/Disable the interrupt of debug timer and return the interrupt state\r
51 prior to the operation.\r
52\r
53 If EnableStatus is TRUE, enable the interrupt of debug timer.\r
54 If EnableStatus is FALSE, disable the interrupt of debug timer.\r
55\r
56 @param[in] EnableStatus Enable/Disable.\r
57\r
58 @retval TRUE Debug timer interrupt were enabled on entry to this call.\r
59 @retval FALSE Debug timer interrupt were disabled on entry to this call.\r
60\r
61**/\r
62BOOLEAN\r
63EFIAPI\r
64SaveAndSetDebugTimerInterrupt (\r
65 IN BOOLEAN EnableStatus\r
66 )\r
67{\r
18b144ea 68 BOOLEAN OldDebugTimerInterruptState;\r
69\r
18b144ea 70 OldDebugTimerInterruptState = GetApicTimerInterruptState ();\r
71 \r
b422b62c 72 if (OldDebugTimerInterruptState != EnableStatus) {\r
73 if (EnableStatus) {\r
74 EnableApicTimerInterrupt ();\r
75 } else {\r
76 DisableApicTimerInterrupt ();\r
77 }\r
78 //\r
79 // Validate the Debug Timer interrupt state\r
80 // This will make additional delay after Local Apic Timer interrupt state is changed.\r
81 // Thus, CPU could handle the potential pending interrupt of Local Apic timer.\r
82 //\r
83 while (GetApicTimerInterruptState () != EnableStatus) {\r
84 CpuPause ();\r
85 }\r
18b144ea 86 }\r
b422b62c 87 \r
18b144ea 88 return OldDebugTimerInterruptState;\r
89}\r
90\r