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