]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/Library/DuetTimerLib/X86TimerLib.c
1, Remove DxeReportStatus driver, because DxeIpl has published a instance from hob...
[mirror_edk2.git] / DuetPkg / Library / DuetTimerLib / X86TimerLib.c
1 /** @file
2 Timer Library functions built upon local APIC on IA32/x64.
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. 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 <Base.h>
16 #include <Library/TimerLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
20
21 #include <Protocol/Metronome.h>
22
23 /**
24 EFI_METRONOME_ARCH_PROTOCOL *gDuetMetronome = NULL;
25
26 EFI_METRONOME_ARCH_PROTOCOL*
27 GetMetronomeArchProtocol (
28 VOID
29 )
30 {
31 if (gDuetMetronome == NULL) {
32 gBS->LocateProtocol (&gEfiMetronomeArchProtocolGuid, NULL, (VOID**) &gDuetMetronome);
33 }
34
35 return gDuetMetronome;
36 }
37 **/
38
39 /**
40 Stalls the CPU for at least the given number of microseconds.
41
42 Stalls the CPU for the number of microseconds specified by MicroSeconds.
43
44 @param MicroSeconds The minimum number of microseconds to delay.
45
46 @return MicroSeconds
47
48 **/
49 UINTN
50 EFIAPI
51 MicroSecondDelay (
52 IN UINTN MicroSeconds
53 )
54 {
55 gBS->Stall (MicroSeconds);
56 /**
57 EFI_METRONOME_ARCH_PROTOCOL *mMetronome;
58 UINT32 Counter;
59 UINTN Remainder;
60
61 if ((mMetronome = GetMetronomeArchProtocol()) == NULL) {
62 return MicroSeconds;
63 }
64
65 //
66 // Calculate the number of ticks by dividing the number of microseconds by
67 // the TickPeriod.
68 // Calculation is based on 100ns unit.
69 //
70 Counter = (UINT32) DivU64x32Remainder (
71 MicroSeconds * 10,
72 mMetronome->TickPeriod,
73 &Remainder
74 );
75 //
76 // Call WaitForTick for Counter + 1 ticks to try to guarantee Counter tick
77 // periods, thus attempting to ensure Microseconds of stall time.
78 //
79 if (Remainder != 0) {
80 Counter++;
81 }
82
83 mMetronome->WaitForTick (mMetronome, Counter);
84 **/
85 return MicroSeconds;
86 }
87
88 /**
89 Stalls the CPU for at least the given number of nanoseconds.
90
91 Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
92
93 @param NanoSeconds The minimum number of nanoseconds to delay.
94
95 @return NanoSeconds
96
97 **/
98 UINTN
99 EFIAPI
100 NanoSecondDelay (
101 IN UINTN NanoSeconds
102 )
103 {
104 //
105 // Duet platform need *not* this interface.
106 //
107 //ASSERT (FALSE);
108 return 0;
109 }
110
111 /**
112 Retrieves the current value of a 64-bit free running performance counter.
113
114 Retrieves the current value of a 64-bit free running performance counter. The
115 counter can either count up by 1 or count down by 1. If the physical
116 performance counter counts by a larger increment, then the counter values
117 must be translated. The properties of the counter can be retrieved from
118 GetPerformanceCounterProperties().
119
120 @return The current value of the free running performance counter.
121
122 **/
123 UINT64
124 EFIAPI
125 GetPerformanceCounter (
126 VOID
127 )
128 {
129 //
130 // Duet platform need *not* this interface.
131 //
132 //ASSERT (FALSE);
133 return 0;
134 }
135
136 /**
137 Retrieves the 64-bit frequency in Hz and the range of performance counter
138 values.
139
140 If StartValue is not NULL, then the value that the performance counter starts
141 with immediately after is it rolls over is returned in StartValue. If
142 EndValue is not NULL, then the value that the performance counter end with
143 immediately before it rolls over is returned in EndValue. The 64-bit
144 frequency of the performance counter in Hz is always returned. If StartValue
145 is less than EndValue, then the performance counter counts up. If StartValue
146 is greater than EndValue, then the performance counter counts down. For
147 example, a 64-bit free running counter that counts up would have a StartValue
148 of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
149 that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
150
151 @param StartValue The value the performance counter starts with when it
152 rolls over.
153 @param EndValue The value that the performance counter ends with before
154 it rolls over.
155
156 @return The frequency in Hz.
157
158 **/
159 UINT64
160 EFIAPI
161 GetPerformanceCounterProperties (
162 OUT UINT64 *StartValue, OPTIONAL
163 OUT UINT64 *EndValue OPTIONAL
164 )
165 {
166 //
167 // Duet platform need *not* this interface.
168 //
169 //ASSERT (FALSE);
170 return 0;
171 }