VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c@ 86173

Last change on this file since 86173 was 80721, checked in by vboxsync, 5 years ago

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

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

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