VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c@ 109019

Last change on this file since 109019 was 108794, checked in by vboxsync, 4 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1/** @file
2SMM Timer feature support
3
4Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved.<BR>
5SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include "PiSmmCpuCommon.h"
10
11UINT64 mTimeoutTicker = 0;
12
13UINT64 mTimeoutTicker2 = 0;
14
15//
16// Number of counts in a roll-over cycle of the performance counter.
17//
18UINT64 mCycle = 0;
19//
20// Flag to indicate the performance counter is count-up or count-down.
21//
22BOOLEAN mCountDown;
23
24/**
25 Initialize Timer for SMM AP Sync.
26
27**/
28VOID
29InitializeSmmTimer (
30 VOID
31 )
32{
33 UINT64 TimerFrequency;
34 UINT64 SyncTimeout;
35 UINT64 SyncTimeout2;
36 UINT64 Start;
37 UINT64 End;
38
39 SyncTimeout = 0;
40 SyncTimeout2 = 0;
41 GetSmmCpuSyncConfigData (NULL, &SyncTimeout, &SyncTimeout2);
42
43 TimerFrequency = GetPerformanceCounterProperties (&Start, &End);
44 mTimeoutTicker = DivU64x32 (
45 MultU64x64 (TimerFrequency, SyncTimeout),
46 1000 * 1000
47 );
48 mTimeoutTicker2 = DivU64x32 (
49 MultU64x64 (TimerFrequency, SyncTimeout2),
50 1000 * 1000
51 );
52 if (End < Start) {
53 mCountDown = TRUE;
54 mCycle = Start - End;
55 } else {
56 mCountDown = FALSE;
57 mCycle = End - Start;
58 }
59}
60
61/**
62 Start Timer for SMM AP Sync.
63
64**/
65UINT64
66EFIAPI
67StartSyncTimer (
68 VOID
69 )
70{
71 return GetPerformanceCounter ();
72}
73
74/**
75 Check if the SMM AP Sync Timer is timeout specified by Timeout.
76
77 @param Timer The start timer from the begin.
78 @param Timeout The timeout ticker to wait.
79
80**/
81BOOLEAN
82EFIAPI
83IsSyncTimerTimeout (
84 IN UINT64 Timer,
85 IN UINT64 Timeout
86 )
87{
88 UINT64 CurrentTimer;
89 UINT64 Delta;
90
91 CurrentTimer = GetPerformanceCounter ();
92 //
93 // We need to consider the case that CurrentTimer is equal to Timer
94 // when some timer runs too slow and CPU runs fast. We think roll over
95 // condition does not happen on this case.
96 //
97 if (mCountDown) {
98 //
99 // The performance counter counts down. Check for roll over condition.
100 //
101 if (CurrentTimer <= Timer) {
102 Delta = Timer - CurrentTimer;
103 } else {
104 //
105 // Handle one roll-over.
106 //
107 Delta = mCycle - (CurrentTimer - Timer) + 1;
108 }
109 } else {
110 //
111 // The performance counter counts up. Check for roll over condition.
112 //
113 if (CurrentTimer >= Timer) {
114 Delta = CurrentTimer - Timer;
115 } else {
116 //
117 // Handle one roll-over.
118 //
119 Delta = mCycle - (Timer - CurrentTimer) + 1;
120 }
121 }
122
123 return (BOOLEAN)(Delta >= Timeout);
124}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette