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