]>
git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
2 A non-functional instance of the Timer Library.
4 Copyright (c) 2007 - 2010, 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.
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.
16 #include <Library/TimerLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/PeiServicesLib.h>
20 #include <Ppi/EmuThunk.h>
21 #include <Protocol/EmuThunk.h>
24 Stalls the CPU for at least the given number of microseconds.
26 Stalls the CPU for the number of microseconds specified by MicroSeconds.
28 @param MicroSeconds The minimum number of microseconds to delay.
30 @return The value of MicroSeconds inputted.
39 return NanoSecondDelay (MicroSeconds
* 1000);
43 Stalls the CPU for at least the given number of nanoseconds.
45 Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
47 @param NanoSeconds The minimum number of nanoseconds to delay.
49 @return The value of NanoSeconds inputted.
58 EMU_THUNK_PPI
*ThunkPpi
;
60 EMU_THUNK_PROTOCOL
*Thunk
;
63 // Locate EmuThunkPpi for
65 Status
= PeiServicesLocatePpi (
71 if (!EFI_ERROR (Status
)) {
72 Thunk
= (EMU_THUNK_PROTOCOL
*)ThunkPpi
->Thunk ();
73 Thunk
->Sleep (NanoSeconds
* 100);
81 Retrieves the current value of a 64-bit free running performance counter.
83 The counter can either count up by 1 or count down by 1. If the physical
84 performance counter counts by a larger increment, then the counter values
85 must be translated. The properties of the counter can be retrieved from
86 GetPerformanceCounterProperties().
88 @return The current value of the free running performance counter.
93 GetPerformanceCounter (
97 EMU_THUNK_PPI
*ThunkPpi
;
99 EMU_THUNK_PROTOCOL
*Thunk
;
102 // Locate EmuThunkPpi for
104 Status
= PeiServicesLocatePpi (
110 if (!EFI_ERROR (Status
)) {
111 Thunk
= (EMU_THUNK_PROTOCOL
*)ThunkPpi
->Thunk ();
112 return Thunk
->QueryPerformanceCounter ();
119 Retrieves the 64-bit frequency in Hz and the range of performance counter
122 If StartValue is not NULL, then the value that the performance counter starts
123 with immediately after is it rolls over is returned in StartValue. If
124 EndValue is not NULL, then the value that the performance counter end with
125 immediately before it rolls over is returned in EndValue. The 64-bit
126 frequency of the performance counter in Hz is always returned. If StartValue
127 is less than EndValue, then the performance counter counts up. If StartValue
128 is greater than EndValue, then the performance counter counts down. For
129 example, a 64-bit free running counter that counts up would have a StartValue
130 of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
131 that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
133 @param StartValue The value the performance counter starts with when it
135 @param EndValue The value that the performance counter ends with before
138 @return The frequency in Hz.
143 GetPerformanceCounterProperties (
144 OUT UINT64
*StartValue
, OPTIONAL
145 OUT UINT64
*EndValue OPTIONAL
148 EMU_THUNK_PPI
*ThunkPpi
;
150 EMU_THUNK_PROTOCOL
*Thunk
;
153 // Locate EmuThunkPpi for
155 Status
= PeiServicesLocatePpi (
161 if (!EFI_ERROR (Status
)) {
162 if (StartValue
!= NULL
) {
165 if (EndValue
!= NULL
) {
166 *EndValue
= (UINT64
)-1LL;
169 Thunk
= (EMU_THUNK_PROTOCOL
*)ThunkPpi
->Thunk ();
170 return Thunk
->QueryPerformanceFrequency ();