]> git.proxmox.com Git - mirror_edk2.git/blob - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
SourceLevelDebugPkg: Fix typo.
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugTimer.c
1 /** @file
2 Code for debug timer to support debug agent library implementation.
3
4 Copyright (c) 2010 - 2014, 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.
9
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.
12
13 **/
14
15 #include "DebugAgent.h"
16
17 /**
18 Initialize CPU local APIC timer.
19
20 @return 32-bit Local APIC timer init count.
21 **/
22 UINT32
23 InitializeDebugTimer (
24 VOID
25 )
26 {
27 UINTN ApicTimerDivisor;
28 UINT32 InitialCount;
29
30 GetApicTimerState (&ApicTimerDivisor, NULL, NULL);
31
32 //
33 // Cpu Local Apic timer interrupt frequency, it is set to 0.1s
34 //
35 InitialCount = (UINT32)DivU64x32 (
36 MultU64x64 (
37 PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor,
38 100
39 ),
40 1000
41 );
42
43 InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);
44
45 return InitialCount;
46 }
47
48 /**
49 Enable/Disable the interrupt of debug timer and return the interrupt state
50 prior to the operation.
51
52 If EnableStatus is TRUE, enable the interrupt of debug timer.
53 If EnableStatus is FALSE, disable the interrupt of debug timer.
54
55 @param[in] EnableStatus Enable/Disable.
56
57 @retval TRUE Debug timer interrupt were enabled on entry to this call.
58 @retval FALSE Debug timer interrupt were disabled on entry to this call.
59
60 **/
61 BOOLEAN
62 EFIAPI
63 SaveAndSetDebugTimerInterrupt (
64 IN BOOLEAN EnableStatus
65 )
66 {
67 BOOLEAN OldDebugTimerInterruptState;
68
69 OldDebugTimerInterruptState = GetApicTimerInterruptState ();
70
71 if (OldDebugTimerInterruptState != EnableStatus) {
72 if (EnableStatus) {
73 EnableApicTimerInterrupt ();
74 } else {
75 DisableApicTimerInterrupt ();
76 }
77 //
78 // Validate the Debug Timer interrupt state
79 // This will make additional delay after Local Apic Timer interrupt state is changed.
80 // Thus, CPU could handle the potential pending interrupt of Local Apic timer.
81 //
82 while (GetApicTimerInterruptState () != EnableStatus) {
83 CpuPause ();
84 }
85 }
86
87 return OldDebugTimerInterruptState;
88 }
89