]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/SecPeiDxeTimerLibCpu/IpfTimerLib.c
updated the comment according to latest version of MWG.
[mirror_edk2.git] / MdePkg / Library / SecPeiDxeTimerLibCpu / IpfTimerLib.c
... / ...
CommitLineData
1/** @file\r
2 Timer Library functions built upon ITC on IPF.\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 Module Name: IpfTimerLib.c\r
14\r
15**/\r
16\r
17\r
18\r
19\r
20/**\r
21 Performs a delay measured as number of ticks.\r
22\r
23 An internal function to perform a delay measured as number of ticks. It's\r
24 invoked by MicroSecondDelay() and NanoSecondDelay().\r
25\r
26 @param Delay Number of ticks to delay.\r
27\r
28**/\r
29STATIC\r
30VOID\r
31InternalIpfDelay (\r
32 IN INT64 Delay\r
33 )\r
34{\r
35 INT64 Ticks;\r
36\r
37 //\r
38 // The target timer count is calculated here\r
39 //\r
40 Ticks = IpfReadItc () + Delay;\r
41\r
42 //\r
43 // Wait until time out\r
44 // Delay > 2^63 could not be handled by this function\r
45 // Timer wrap-arounds are handled correctly by this function\r
46 //\r
47 while (Ticks - IpfReadItc () >= 0);\r
48}\r
49\r
50/**\r
51 Stalls the CPU for at least the given number of microseconds.\r
52\r
53 Stalls the CPU for the number of microseconds specified by MicroSeconds.\r
54\r
55 @param MicroSeconds The minimum number of microseconds to delay.\r
56\r
57 @return MicroSeconds\r
58\r
59**/\r
60UINTN\r
61EFIAPI\r
62MicroSecondDelay (\r
63 IN UINTN MicroSeconds\r
64 )\r
65{\r
66 InternalIpfDelay (\r
67 GetPerformanceCounterProperties (NULL, NULL) *\r
68 MicroSeconds /\r
69 1000000\r
70 );\r
71 return MicroSeconds;\r
72}\r
73\r
74/**\r
75 Stalls the CPU for at least the given number of nanoseconds.\r
76\r
77 Stalls the CPU for the number of nanoseconds specified by NanoSeconds.\r
78\r
79 @param NanoSeconds The minimum number of nanoseconds to delay.\r
80\r
81 @return NanoSeconds\r
82\r
83**/\r
84UINTN\r
85EFIAPI\r
86NanoSecondDelay (\r
87 IN UINTN NanoSeconds\r
88 )\r
89{\r
90 InternalIpfDelay (\r
91 GetPerformanceCounterProperties (NULL, NULL) *\r
92 NanoSeconds /\r
93 1000000000\r
94 );\r
95 return NanoSeconds;\r
96}\r
97\r
98/**\r
99 Retrieves the current value of a 64-bit free running performance counter.\r
100\r
101 Retrieves the current value of a 64-bit free running performance counter. The\r
102 counter can either count up by 1 or count down by 1. If the physical\r
103 performance counter counts by a larger increment, then the counter values\r
104 must be translated. The properties of the counter can be retrieved from\r
105 GetPerformanceCounterProperties().\r
106\r
107 @return The current value of the free running performance counter.\r
108\r
109**/\r
110UINT64\r
111EFIAPI\r
112GetPerformanceCounter (\r
113 VOID\r
114 )\r
115{\r
116 return IpfReadItc ();\r
117}\r
118\r
119/**\r
120 Retrieves the 64-bit frequency in Hz and the range of performance counter\r
121 values.\r
122\r
123 If StartValue is not NULL, then the value that the performance counter starts\r
124 with immediately after is it rolls over is returned in StartValue. If\r
125 EndValue is not NULL, then the value that the performance counter end with\r
126 immediately before it rolls over is returned in EndValue. The 64-bit\r
127 frequency of the performance counter in Hz is always returned. If StartValue\r
128 is less than EndValue, then the performance counter counts up. If StartValue\r
129 is greater than EndValue, then the performance counter counts down. For\r
130 example, a 64-bit free running counter that counts up would have a StartValue\r
131 of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter\r
132 that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.\r
133\r
134 @param StartValue The value the performance counter starts with when it\r
135 rolls over.\r
136 @param EndValue The value that the performance counter ends with before\r
137 it rolls over.\r
138\r
139 @return The frequency in Hz.\r
140\r
141**/\r
142UINT64\r
143EFIAPI\r
144GetPerformanceCounterProperties (\r
145 OUT UINT64 *StartValue, OPTIONAL\r
146 OUT UINT64 *EndValue OPTIONAL\r
147 )\r
148{\r
149 PAL_PROC_RETURN PalRet;\r
150 UINT64 BaseFrequence;\r
151\r
152 PalRet = PalCallStatic (NULL, 13, 0, 0, 0);\r
153 ASSERT (PalRet.Status == 0);\r
154 BaseFrequence = PalRet.r9;\r
155\r
156 PalRet = PalCallStatic (NULL, 14, 0, 0, 0);\r
157 ASSERT (PalRet.Status == 0);\r
158\r
159 if (StartValue != NULL) {\r
160 *StartValue = 0;\r
161 }\r
162\r
163 if (EndValue != NULL) {\r
164 *EndValue = (UINT64)(-1);\r
165 }\r
166\r
167 return BaseFrequence * (PalRet.r11 >> 32) / (UINT32)PalRet.r11;\r
168}\r