]>
git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
cce46fb366e185e3559d56d68759c85cea2987bf
2 A non-functional instance of the Timer Library.
4 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/TimerLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/PeiServicesLib.h>
14 #include <Ppi/EmuThunk.h>
15 #include <Protocol/EmuThunk.h>
18 Stalls the CPU for at least the given number of microseconds.
20 Stalls the CPU for the number of microseconds specified by MicroSeconds.
22 @param MicroSeconds The minimum number of microseconds to delay.
24 @return The value of MicroSeconds inputted.
33 return NanoSecondDelay (MicroSeconds
* 1000);
37 Stalls the CPU for at least the given number of nanoseconds.
39 Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
41 @param NanoSeconds The minimum number of nanoseconds to delay.
43 @return The value of NanoSeconds inputted.
52 EMU_THUNK_PPI
*ThunkPpi
;
54 EMU_THUNK_PROTOCOL
*Thunk
;
57 // Locate EmuThunkPpi for
59 Status
= PeiServicesLocatePpi (
65 if (!EFI_ERROR (Status
)) {
66 Thunk
= (EMU_THUNK_PROTOCOL
*)ThunkPpi
->Thunk ();
67 Thunk
->Sleep (NanoSeconds
* 100);
75 Retrieves the current value of a 64-bit free running performance counter.
77 The counter can either count up by 1 or count down by 1. If the physical
78 performance counter counts by a larger increment, then the counter values
79 must be translated. The properties of the counter can be retrieved from
80 GetPerformanceCounterProperties().
82 @return The current value of the free running performance counter.
87 GetPerformanceCounter (
91 EMU_THUNK_PPI
*ThunkPpi
;
93 EMU_THUNK_PROTOCOL
*Thunk
;
96 // Locate EmuThunkPpi for
98 Status
= PeiServicesLocatePpi (
104 if (!EFI_ERROR (Status
)) {
105 Thunk
= (EMU_THUNK_PROTOCOL
*)ThunkPpi
->Thunk ();
106 return Thunk
->QueryPerformanceCounter ();
113 Retrieves the 64-bit frequency in Hz and the range of performance counter
116 If StartValue is not NULL, then the value that the performance counter starts
117 with immediately after is it rolls over is returned in StartValue. If
118 EndValue is not NULL, then the value that the performance counter end with
119 immediately before it rolls over is returned in EndValue. The 64-bit
120 frequency of the performance counter in Hz is always returned. If StartValue
121 is less than EndValue, then the performance counter counts up. If StartValue
122 is greater than EndValue, then the performance counter counts down. For
123 example, a 64-bit free running counter that counts up would have a StartValue
124 of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
125 that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
127 @param StartValue The value the performance counter starts with when it
129 @param EndValue The value that the performance counter ends with before
132 @return The frequency in Hz.
137 GetPerformanceCounterProperties (
138 OUT UINT64
*StartValue
, OPTIONAL
139 OUT UINT64
*EndValue OPTIONAL
142 EMU_THUNK_PPI
*ThunkPpi
;
144 EMU_THUNK_PROTOCOL
*Thunk
;
147 // Locate EmuThunkPpi for
149 Status
= PeiServicesLocatePpi (
155 if (!EFI_ERROR (Status
)) {
156 if (StartValue
!= NULL
) {
159 if (EndValue
!= NULL
) {
160 *EndValue
= (UINT64
)-1LL;
163 Thunk
= (EMU_THUNK_PROTOCOL
*)ThunkPpi
->Thunk ();
164 return Thunk
->QueryPerformanceFrequency ();