]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
CryptoPkg/BaseCryptLib: Make HMAC_CTX size backward compatible
[mirror_edk2.git] / EmulatorPkg / Library / DxeCoreTimerLib / DxeCoreTimerLib.c
1 /** @file
2 A non-functional instance of the Timer Library.
3
4 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiPei.h>
10 #include <Library/TimerLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/EmuThunkLib.h>
13 #include <Library/UefiBootServicesTableLib.h>
14 #include <Library/UefiLib.h>
15
16 #include <Protocol/Timer.h>
17
18
19
20 /**
21 Stalls the CPU for at least the given number of microseconds.
22
23 Stalls the CPU for the number of microseconds specified by MicroSeconds.
24
25 @param MicroSeconds The minimum number of microseconds to delay.
26
27 @return The value of MicroSeconds inputted.
28
29 **/
30 UINTN
31 EFIAPI
32 MicroSecondDelay (
33 IN UINTN MicroSeconds
34 )
35 {
36 return NanoSecondDelay (MicroSeconds * 1000);
37 }
38
39
40 /**
41 Stalls the CPU for at least the given number of nanoseconds.
42
43 Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
44
45 @param NanoSeconds The minimum number of nanoseconds to delay.
46
47 @return The value of NanoSeconds inputted.
48
49 **/
50 UINTN
51 EFIAPI
52 NanoSecondDelay (
53 IN UINTN NanoSeconds
54 )
55 {
56 gEmuThunk->Sleep (NanoSeconds);
57 return NanoSeconds;
58 }
59
60
61 /**
62 Retrieves the current value of a 64-bit free running performance counter.
63
64 The counter can either count up by 1 or count down by 1. If the physical
65 performance counter counts by a larger increment, then the counter values
66 must be translated. The properties of the counter can be retrieved from
67 GetPerformanceCounterProperties().
68
69 @return The current value of the free running performance counter.
70
71 **/
72 UINT64
73 EFIAPI
74 GetPerformanceCounter (
75 VOID
76 )
77 {
78 return gEmuThunk->QueryPerformanceCounter ();
79 }
80
81 /**
82 Retrieves the 64-bit frequency in Hz and the range of performance counter
83 values.
84
85 If StartValue is not NULL, then the value that the performance counter starts
86 with immediately after is it rolls over is returned in StartValue. If
87 EndValue is not NULL, then the value that the performance counter end with
88 immediately before it rolls over is returned in EndValue. The 64-bit
89 frequency of the performance counter in Hz is always returned. If StartValue
90 is less than EndValue, then the performance counter counts up. If StartValue
91 is greater than EndValue, then the performance counter counts down. For
92 example, a 64-bit free running counter that counts up would have a StartValue
93 of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
94 that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
95
96 @param StartValue The value the performance counter starts with when it
97 rolls over.
98 @param EndValue The value that the performance counter ends with before
99 it rolls over.
100
101 @return The frequency in Hz.
102
103 **/
104 UINT64
105 EFIAPI
106 GetPerformanceCounterProperties (
107 OUT UINT64 *StartValue, OPTIONAL
108 OUT UINT64 *EndValue OPTIONAL
109 )
110 {
111
112 if (StartValue != NULL) {
113 *StartValue = 0ULL;
114 }
115 if (EndValue != NULL) {
116 *EndValue = (UINT64)-1LL;
117 }
118
119 return gEmuThunk->QueryPerformanceFrequency ();
120 }
121
122