hwtimer.c revision 1.1.1.2.4.2 1 1.1.1.2.4.2 rmind
2 1.1.1.2.4.2 rmind /******************************************************************************
3 1.1.1.2.4.2 rmind *
4 1.1.1.2.4.2 rmind * Name: hwtimer.c - ACPI Power Management Timer Interface
5 1.1.1.2.4.2 rmind *
6 1.1.1.2.4.2 rmind *****************************************************************************/
7 1.1.1.2.4.2 rmind
8 1.1.1.2.4.2 rmind /*
9 1.1.1.2.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.4.2 rmind * All rights reserved.
11 1.1.1.2.4.2 rmind *
12 1.1.1.2.4.2 rmind * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.4.2 rmind * modification, are permitted provided that the following conditions
14 1.1.1.2.4.2 rmind * are met:
15 1.1.1.2.4.2 rmind * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.4.2 rmind * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.4.2 rmind * without modification.
18 1.1.1.2.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.4.2 rmind * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.4.2 rmind * binary redistribution.
23 1.1.1.2.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.4.2 rmind * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.4.2 rmind * from this software without specific prior written permission.
26 1.1.1.2.4.2 rmind *
27 1.1.1.2.4.2 rmind * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.4.2 rmind * Software Foundation.
30 1.1.1.2.4.2 rmind *
31 1.1.1.2.4.2 rmind * NO WARRANTY
32 1.1.1.2.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.4.2 rmind */
44 1.1.1.2.4.2 rmind
45 1.1.1.2.4.2 rmind #include "acpi.h"
46 1.1.1.2.4.2 rmind #include "accommon.h"
47 1.1.1.2.4.2 rmind
48 1.1.1.2.4.2 rmind #define _COMPONENT ACPI_HARDWARE
49 1.1.1.2.4.2 rmind ACPI_MODULE_NAME ("hwtimer")
50 1.1.1.2.4.2 rmind
51 1.1.1.2.4.2 rmind
52 1.1.1.2.4.2 rmind /******************************************************************************
53 1.1.1.2.4.2 rmind *
54 1.1.1.2.4.2 rmind * FUNCTION: AcpiGetTimerResolution
55 1.1.1.2.4.2 rmind *
56 1.1.1.2.4.2 rmind * PARAMETERS: Resolution - Where the resolution is returned
57 1.1.1.2.4.2 rmind *
58 1.1.1.2.4.2 rmind * RETURN: Status and timer resolution
59 1.1.1.2.4.2 rmind *
60 1.1.1.2.4.2 rmind * DESCRIPTION: Obtains resolution of the ACPI PM Timer (24 or 32 bits).
61 1.1.1.2.4.2 rmind *
62 1.1.1.2.4.2 rmind ******************************************************************************/
63 1.1.1.2.4.2 rmind
64 1.1.1.2.4.2 rmind ACPI_STATUS
65 1.1.1.2.4.2 rmind AcpiGetTimerResolution (
66 1.1.1.2.4.2 rmind UINT32 *Resolution)
67 1.1.1.2.4.2 rmind {
68 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (AcpiGetTimerResolution);
69 1.1.1.2.4.2 rmind
70 1.1.1.2.4.2 rmind
71 1.1.1.2.4.2 rmind if (!Resolution)
72 1.1.1.2.4.2 rmind {
73 1.1.1.2.4.2 rmind return_ACPI_STATUS (AE_BAD_PARAMETER);
74 1.1.1.2.4.2 rmind }
75 1.1.1.2.4.2 rmind
76 1.1.1.2.4.2 rmind if ((AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER) == 0)
77 1.1.1.2.4.2 rmind {
78 1.1.1.2.4.2 rmind *Resolution = 24;
79 1.1.1.2.4.2 rmind }
80 1.1.1.2.4.2 rmind else
81 1.1.1.2.4.2 rmind {
82 1.1.1.2.4.2 rmind *Resolution = 32;
83 1.1.1.2.4.2 rmind }
84 1.1.1.2.4.2 rmind
85 1.1.1.2.4.2 rmind return_ACPI_STATUS (AE_OK);
86 1.1.1.2.4.2 rmind }
87 1.1.1.2.4.2 rmind
88 1.1.1.2.4.2 rmind ACPI_EXPORT_SYMBOL (AcpiGetTimerResolution)
89 1.1.1.2.4.2 rmind
90 1.1.1.2.4.2 rmind
91 1.1.1.2.4.2 rmind /******************************************************************************
92 1.1.1.2.4.2 rmind *
93 1.1.1.2.4.2 rmind * FUNCTION: AcpiGetTimer
94 1.1.1.2.4.2 rmind *
95 1.1.1.2.4.2 rmind * PARAMETERS: Ticks - Where the timer value is returned
96 1.1.1.2.4.2 rmind *
97 1.1.1.2.4.2 rmind * RETURN: Status and current timer value (ticks)
98 1.1.1.2.4.2 rmind *
99 1.1.1.2.4.2 rmind * DESCRIPTION: Obtains current value of ACPI PM Timer (in ticks).
100 1.1.1.2.4.2 rmind *
101 1.1.1.2.4.2 rmind ******************************************************************************/
102 1.1.1.2.4.2 rmind
103 1.1.1.2.4.2 rmind ACPI_STATUS
104 1.1.1.2.4.2 rmind AcpiGetTimer (
105 1.1.1.2.4.2 rmind UINT32 *Ticks)
106 1.1.1.2.4.2 rmind {
107 1.1.1.2.4.2 rmind ACPI_STATUS Status;
108 1.1.1.2.4.2 rmind
109 1.1.1.2.4.2 rmind
110 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (AcpiGetTimer);
111 1.1.1.2.4.2 rmind
112 1.1.1.2.4.2 rmind
113 1.1.1.2.4.2 rmind if (!Ticks)
114 1.1.1.2.4.2 rmind {
115 1.1.1.2.4.2 rmind return_ACPI_STATUS (AE_BAD_PARAMETER);
116 1.1.1.2.4.2 rmind }
117 1.1.1.2.4.2 rmind
118 1.1.1.2.4.2 rmind Status = AcpiHwRead (Ticks, &AcpiGbl_FADT.XPmTimerBlock);
119 1.1.1.2.4.2 rmind
120 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
121 1.1.1.2.4.2 rmind }
122 1.1.1.2.4.2 rmind
123 1.1.1.2.4.2 rmind ACPI_EXPORT_SYMBOL (AcpiGetTimer)
124 1.1.1.2.4.2 rmind
125 1.1.1.2.4.2 rmind
126 1.1.1.2.4.2 rmind /******************************************************************************
127 1.1.1.2.4.2 rmind *
128 1.1.1.2.4.2 rmind * FUNCTION: AcpiGetTimerDuration
129 1.1.1.2.4.2 rmind *
130 1.1.1.2.4.2 rmind * PARAMETERS: StartTicks - Starting timestamp
131 1.1.1.2.4.2 rmind * EndTicks - End timestamp
132 1.1.1.2.4.2 rmind * TimeElapsed - Where the elapsed time is returned
133 1.1.1.2.4.2 rmind *
134 1.1.1.2.4.2 rmind * RETURN: Status and TimeElapsed
135 1.1.1.2.4.2 rmind *
136 1.1.1.2.4.2 rmind * DESCRIPTION: Computes the time elapsed (in microseconds) between two
137 1.1.1.2.4.2 rmind * PM Timer time stamps, taking into account the possibility of
138 1.1.1.2.4.2 rmind * rollovers, the timer resolution, and timer frequency.
139 1.1.1.2.4.2 rmind *
140 1.1.1.2.4.2 rmind * The PM Timer's clock ticks at roughly 3.6 times per
141 1.1.1.2.4.2 rmind * _microsecond_, and its clock continues through Cx state
142 1.1.1.2.4.2 rmind * transitions (unlike many CPU timestamp counters) -- making it
143 1.1.1.2.4.2 rmind * a versatile and accurate timer.
144 1.1.1.2.4.2 rmind *
145 1.1.1.2.4.2 rmind * Note that this function accommodates only a single timer
146 1.1.1.2.4.2 rmind * rollover. Thus for 24-bit timers, this function should only
147 1.1.1.2.4.2 rmind * be used for calculating durations less than ~4.6 seconds
148 1.1.1.2.4.2 rmind * (~20 minutes for 32-bit timers) -- calculations below:
149 1.1.1.2.4.2 rmind *
150 1.1.1.2.4.2 rmind * 2**24 Ticks / 3,600,000 Ticks/Sec = 4.66 sec
151 1.1.1.2.4.2 rmind * 2**32 Ticks / 3,600,000 Ticks/Sec = 1193 sec or 19.88 minutes
152 1.1.1.2.4.2 rmind *
153 1.1.1.2.4.2 rmind ******************************************************************************/
154 1.1.1.2.4.2 rmind
155 1.1.1.2.4.2 rmind ACPI_STATUS
156 1.1.1.2.4.2 rmind AcpiGetTimerDuration (
157 1.1.1.2.4.2 rmind UINT32 StartTicks,
158 1.1.1.2.4.2 rmind UINT32 EndTicks,
159 1.1.1.2.4.2 rmind UINT32 *TimeElapsed)
160 1.1.1.2.4.2 rmind {
161 1.1.1.2.4.2 rmind ACPI_STATUS Status;
162 1.1.1.2.4.2 rmind UINT32 DeltaTicks;
163 1.1.1.2.4.2 rmind UINT64 Quotient;
164 1.1.1.2.4.2 rmind
165 1.1.1.2.4.2 rmind
166 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (AcpiGetTimerDuration);
167 1.1.1.2.4.2 rmind
168 1.1.1.2.4.2 rmind
169 1.1.1.2.4.2 rmind if (!TimeElapsed)
170 1.1.1.2.4.2 rmind {
171 1.1.1.2.4.2 rmind return_ACPI_STATUS (AE_BAD_PARAMETER);
172 1.1.1.2.4.2 rmind }
173 1.1.1.2.4.2 rmind
174 1.1.1.2.4.2 rmind /*
175 1.1.1.2.4.2 rmind * Compute Tick Delta:
176 1.1.1.2.4.2 rmind * Handle (max one) timer rollovers on 24-bit versus 32-bit timers.
177 1.1.1.2.4.2 rmind */
178 1.1.1.2.4.2 rmind if (StartTicks < EndTicks)
179 1.1.1.2.4.2 rmind {
180 1.1.1.2.4.2 rmind DeltaTicks = EndTicks - StartTicks;
181 1.1.1.2.4.2 rmind }
182 1.1.1.2.4.2 rmind else if (StartTicks > EndTicks)
183 1.1.1.2.4.2 rmind {
184 1.1.1.2.4.2 rmind if ((AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER) == 0)
185 1.1.1.2.4.2 rmind {
186 1.1.1.2.4.2 rmind /* 24-bit Timer */
187 1.1.1.2.4.2 rmind
188 1.1.1.2.4.2 rmind DeltaTicks = (((0x00FFFFFF - StartTicks) + EndTicks) & 0x00FFFFFF);
189 1.1.1.2.4.2 rmind }
190 1.1.1.2.4.2 rmind else
191 1.1.1.2.4.2 rmind {
192 1.1.1.2.4.2 rmind /* 32-bit Timer */
193 1.1.1.2.4.2 rmind
194 1.1.1.2.4.2 rmind DeltaTicks = (0xFFFFFFFF - StartTicks) + EndTicks;
195 1.1.1.2.4.2 rmind }
196 1.1.1.2.4.2 rmind }
197 1.1.1.2.4.2 rmind else /* StartTicks == EndTicks */
198 1.1.1.2.4.2 rmind {
199 1.1.1.2.4.2 rmind *TimeElapsed = 0;
200 1.1.1.2.4.2 rmind return_ACPI_STATUS (AE_OK);
201 1.1.1.2.4.2 rmind }
202 1.1.1.2.4.2 rmind
203 1.1.1.2.4.2 rmind /*
204 1.1.1.2.4.2 rmind * Compute Duration (Requires a 64-bit multiply and divide):
205 1.1.1.2.4.2 rmind *
206 1.1.1.2.4.2 rmind * TimeElapsed = (DeltaTicks * 1000000) / PM_TIMER_FREQUENCY;
207 1.1.1.2.4.2 rmind */
208 1.1.1.2.4.2 rmind Status = AcpiUtShortDivide (((UINT64) DeltaTicks) * 1000000,
209 1.1.1.2.4.2 rmind PM_TIMER_FREQUENCY, &Quotient, NULL);
210 1.1.1.2.4.2 rmind
211 1.1.1.2.4.2 rmind *TimeElapsed = (UINT32) Quotient;
212 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
213 1.1.1.2.4.2 rmind }
214 1.1.1.2.4.2 rmind
215 1.1.1.2.4.2 rmind ACPI_EXPORT_SYMBOL (AcpiGetTimerDuration)
216 1.1.1.2.4.2 rmind
217