]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/TimerLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Include / Library / TimerLib.h
1 /** @file
2 Provides calibrated delay and performance counter services.
3
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef __TIMER_LIB__
10 #define __TIMER_LIB__
11
12 /**
13 Stalls the CPU for at least the given number of microseconds.
14
15 Stalls the CPU for the number of microseconds specified by MicroSeconds.
16
17 @param MicroSeconds The minimum number of microseconds to delay.
18
19 @return The value of MicroSeconds inputted.
20
21 **/
22 UINTN
23 EFIAPI
24 MicroSecondDelay (
25 IN UINTN MicroSeconds
26 );
27
28 /**
29 Stalls the CPU for at least the given number of nanoseconds.
30
31 Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
32
33 @param NanoSeconds The minimum number of nanoseconds to delay.
34
35 @return The value of NanoSeconds inputted.
36
37 **/
38 UINTN
39 EFIAPI
40 NanoSecondDelay (
41 IN UINTN NanoSeconds
42 );
43
44 /**
45 Retrieves the current value of a 64-bit free running performance counter.
46
47 The counter can either count up by 1 or count down by 1. If the physical
48 performance counter counts by a larger increment, then the counter values
49 must be translated. The properties of the counter can be retrieved from
50 GetPerformanceCounterProperties().
51
52 @return The current value of the free running performance counter.
53
54 **/
55 UINT64
56 EFIAPI
57 GetPerformanceCounter (
58 VOID
59 );
60
61 /**
62 Retrieves the 64-bit frequency in Hz and the range of performance counter
63 values.
64
65 If StartValue is not NULL, then the value that the performance counter starts
66 with immediately after is it rolls over is returned in StartValue. If
67 EndValue is not NULL, then the value that the performance counter end with
68 immediately before it rolls over is returned in EndValue. The 64-bit
69 frequency of the performance counter in Hz is always returned. If StartValue
70 is less than EndValue, then the performance counter counts up. If StartValue
71 is greater than EndValue, then the performance counter counts down. For
72 example, a 64-bit free running counter that counts up would have a StartValue
73 of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
74 that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
75
76 @param StartValue The value the performance counter starts with when it
77 rolls over.
78 @param EndValue The value that the performance counter ends with before
79 it rolls over.
80
81 @return The frequency in Hz.
82
83 **/
84 UINT64
85 EFIAPI
86 GetPerformanceCounterProperties (
87 OUT UINT64 *StartValue, OPTIONAL
88 OUT UINT64 *EndValue OPTIONAL
89 );
90
91 /**
92 Converts elapsed ticks of performance counter to time in nanoseconds.
93
94 This function converts the elapsed ticks of running performance counter to
95 time value in unit of nanoseconds.
96
97 @param Ticks The number of elapsed ticks of running performance counter.
98
99 @return The elapsed time in nanoseconds.
100
101 **/
102 UINT64
103 EFIAPI
104 GetTimeInNanoSecond (
105 IN UINT64 Ticks
106 );
107
108 #endif