exsystem.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 * Module Name: exsystem - Interface to OS services
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 #define __EXSYSTEM_C__
46 1.1.1.2.4.2 rmind
47 1.1.1.2.4.2 rmind #include "acpi.h"
48 1.1.1.2.4.2 rmind #include "accommon.h"
49 1.1.1.2.4.2 rmind #include "acinterp.h"
50 1.1.1.2.4.2 rmind
51 1.1.1.2.4.2 rmind #define _COMPONENT ACPI_EXECUTER
52 1.1.1.2.4.2 rmind ACPI_MODULE_NAME ("exsystem")
53 1.1.1.2.4.2 rmind
54 1.1.1.2.4.2 rmind
55 1.1.1.2.4.2 rmind /*******************************************************************************
56 1.1.1.2.4.2 rmind *
57 1.1.1.2.4.2 rmind * FUNCTION: AcpiExSystemWaitSemaphore
58 1.1.1.2.4.2 rmind *
59 1.1.1.2.4.2 rmind * PARAMETERS: Semaphore - Semaphore to wait on
60 1.1.1.2.4.2 rmind * Timeout - Max time to wait
61 1.1.1.2.4.2 rmind *
62 1.1.1.2.4.2 rmind * RETURN: Status
63 1.1.1.2.4.2 rmind *
64 1.1.1.2.4.2 rmind * DESCRIPTION: Implements a semaphore wait with a check to see if the
65 1.1.1.2.4.2 rmind * semaphore is available immediately. If it is not, the
66 1.1.1.2.4.2 rmind * interpreter is released before waiting.
67 1.1.1.2.4.2 rmind *
68 1.1.1.2.4.2 rmind ******************************************************************************/
69 1.1.1.2.4.2 rmind
70 1.1.1.2.4.2 rmind ACPI_STATUS
71 1.1.1.2.4.2 rmind AcpiExSystemWaitSemaphore (
72 1.1.1.2.4.2 rmind ACPI_SEMAPHORE Semaphore,
73 1.1.1.2.4.2 rmind UINT16 Timeout)
74 1.1.1.2.4.2 rmind {
75 1.1.1.2.4.2 rmind ACPI_STATUS Status;
76 1.1.1.2.4.2 rmind
77 1.1.1.2.4.2 rmind
78 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (ExSystemWaitSemaphore);
79 1.1.1.2.4.2 rmind
80 1.1.1.2.4.2 rmind
81 1.1.1.2.4.2 rmind Status = AcpiOsWaitSemaphore (Semaphore, 1, ACPI_DO_NOT_WAIT);
82 1.1.1.2.4.2 rmind if (ACPI_SUCCESS (Status))
83 1.1.1.2.4.2 rmind {
84 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
85 1.1.1.2.4.2 rmind }
86 1.1.1.2.4.2 rmind
87 1.1.1.2.4.2 rmind if (Status == AE_TIME)
88 1.1.1.2.4.2 rmind {
89 1.1.1.2.4.2 rmind /* We must wait, so unlock the interpreter */
90 1.1.1.2.4.2 rmind
91 1.1.1.2.4.2 rmind AcpiExRelinquishInterpreter ();
92 1.1.1.2.4.2 rmind
93 1.1.1.2.4.2 rmind Status = AcpiOsWaitSemaphore (Semaphore, 1, Timeout);
94 1.1.1.2.4.2 rmind
95 1.1.1.2.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
96 1.1.1.2.4.2 rmind "*** Thread awake after blocking, %s\n",
97 1.1.1.2.4.2 rmind AcpiFormatException (Status)));
98 1.1.1.2.4.2 rmind
99 1.1.1.2.4.2 rmind /* Reacquire the interpreter */
100 1.1.1.2.4.2 rmind
101 1.1.1.2.4.2 rmind AcpiExReacquireInterpreter ();
102 1.1.1.2.4.2 rmind }
103 1.1.1.2.4.2 rmind
104 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
105 1.1.1.2.4.2 rmind }
106 1.1.1.2.4.2 rmind
107 1.1.1.2.4.2 rmind
108 1.1.1.2.4.2 rmind /*******************************************************************************
109 1.1.1.2.4.2 rmind *
110 1.1.1.2.4.2 rmind * FUNCTION: AcpiExSystemWaitMutex
111 1.1.1.2.4.2 rmind *
112 1.1.1.2.4.2 rmind * PARAMETERS: Mutex - Mutex to wait on
113 1.1.1.2.4.2 rmind * Timeout - Max time to wait
114 1.1.1.2.4.2 rmind *
115 1.1.1.2.4.2 rmind * RETURN: Status
116 1.1.1.2.4.2 rmind *
117 1.1.1.2.4.2 rmind * DESCRIPTION: Implements a mutex wait with a check to see if the
118 1.1.1.2.4.2 rmind * mutex is available immediately. If it is not, the
119 1.1.1.2.4.2 rmind * interpreter is released before waiting.
120 1.1.1.2.4.2 rmind *
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_STATUS
124 1.1.1.2.4.2 rmind AcpiExSystemWaitMutex (
125 1.1.1.2.4.2 rmind ACPI_MUTEX Mutex,
126 1.1.1.2.4.2 rmind UINT16 Timeout)
127 1.1.1.2.4.2 rmind {
128 1.1.1.2.4.2 rmind ACPI_STATUS Status;
129 1.1.1.2.4.2 rmind
130 1.1.1.2.4.2 rmind
131 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (ExSystemWaitMutex);
132 1.1.1.2.4.2 rmind
133 1.1.1.2.4.2 rmind
134 1.1.1.2.4.2 rmind Status = AcpiOsAcquireMutex (Mutex, ACPI_DO_NOT_WAIT);
135 1.1.1.2.4.2 rmind if (ACPI_SUCCESS (Status))
136 1.1.1.2.4.2 rmind {
137 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
138 1.1.1.2.4.2 rmind }
139 1.1.1.2.4.2 rmind
140 1.1.1.2.4.2 rmind if (Status == AE_TIME)
141 1.1.1.2.4.2 rmind {
142 1.1.1.2.4.2 rmind /* We must wait, so unlock the interpreter */
143 1.1.1.2.4.2 rmind
144 1.1.1.2.4.2 rmind AcpiExRelinquishInterpreter ();
145 1.1.1.2.4.2 rmind
146 1.1.1.2.4.2 rmind Status = AcpiOsAcquireMutex (Mutex, Timeout);
147 1.1.1.2.4.2 rmind
148 1.1.1.2.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
149 1.1.1.2.4.2 rmind "*** Thread awake after blocking, %s\n",
150 1.1.1.2.4.2 rmind AcpiFormatException (Status)));
151 1.1.1.2.4.2 rmind
152 1.1.1.2.4.2 rmind /* Reacquire the interpreter */
153 1.1.1.2.4.2 rmind
154 1.1.1.2.4.2 rmind AcpiExReacquireInterpreter ();
155 1.1.1.2.4.2 rmind }
156 1.1.1.2.4.2 rmind
157 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
158 1.1.1.2.4.2 rmind }
159 1.1.1.2.4.2 rmind
160 1.1.1.2.4.2 rmind
161 1.1.1.2.4.2 rmind /*******************************************************************************
162 1.1.1.2.4.2 rmind *
163 1.1.1.2.4.2 rmind * FUNCTION: AcpiExSystemDoStall
164 1.1.1.2.4.2 rmind *
165 1.1.1.2.4.2 rmind * PARAMETERS: HowLong - The amount of time to stall,
166 1.1.1.2.4.2 rmind * in microseconds
167 1.1.1.2.4.2 rmind *
168 1.1.1.2.4.2 rmind * RETURN: Status
169 1.1.1.2.4.2 rmind *
170 1.1.1.2.4.2 rmind * DESCRIPTION: Suspend running thread for specified amount of time.
171 1.1.1.2.4.2 rmind * Note: ACPI specification requires that Stall() does not
172 1.1.1.2.4.2 rmind * relinquish the processor, and delays longer than 100 usec
173 1.1.1.2.4.2 rmind * should use Sleep() instead. We allow stalls up to 255 usec
174 1.1.1.2.4.2 rmind * for compatibility with other interpreters and existing BIOSs.
175 1.1.1.2.4.2 rmind *
176 1.1.1.2.4.2 rmind ******************************************************************************/
177 1.1.1.2.4.2 rmind
178 1.1.1.2.4.2 rmind ACPI_STATUS
179 1.1.1.2.4.2 rmind AcpiExSystemDoStall (
180 1.1.1.2.4.2 rmind UINT32 HowLong)
181 1.1.1.2.4.2 rmind {
182 1.1.1.2.4.2 rmind ACPI_STATUS Status = AE_OK;
183 1.1.1.2.4.2 rmind
184 1.1.1.2.4.2 rmind
185 1.1.1.2.4.2 rmind ACPI_FUNCTION_ENTRY ();
186 1.1.1.2.4.2 rmind
187 1.1.1.2.4.2 rmind
188 1.1.1.2.4.2 rmind if (HowLong > 255) /* 255 microseconds */
189 1.1.1.2.4.2 rmind {
190 1.1.1.2.4.2 rmind /*
191 1.1.1.2.4.2 rmind * Longer than 255 usec, this is an error
192 1.1.1.2.4.2 rmind *
193 1.1.1.2.4.2 rmind * (ACPI specifies 100 usec as max, but this gives some slack in
194 1.1.1.2.4.2 rmind * order to support existing BIOSs)
195 1.1.1.2.4.2 rmind */
196 1.1.1.2.4.2 rmind ACPI_ERROR ((AE_INFO, "Time parameter is too large (%u)",
197 1.1.1.2.4.2 rmind HowLong));
198 1.1.1.2.4.2 rmind Status = AE_AML_OPERAND_VALUE;
199 1.1.1.2.4.2 rmind }
200 1.1.1.2.4.2 rmind else
201 1.1.1.2.4.2 rmind {
202 1.1.1.2.4.2 rmind AcpiOsStall (HowLong);
203 1.1.1.2.4.2 rmind }
204 1.1.1.2.4.2 rmind
205 1.1.1.2.4.2 rmind return (Status);
206 1.1.1.2.4.2 rmind }
207 1.1.1.2.4.2 rmind
208 1.1.1.2.4.2 rmind
209 1.1.1.2.4.2 rmind /*******************************************************************************
210 1.1.1.2.4.2 rmind *
211 1.1.1.2.4.2 rmind * FUNCTION: AcpiExSystemDoSleep
212 1.1.1.2.4.2 rmind *
213 1.1.1.2.4.2 rmind * PARAMETERS: HowLong - The amount of time to sleep,
214 1.1.1.2.4.2 rmind * in milliseconds
215 1.1.1.2.4.2 rmind *
216 1.1.1.2.4.2 rmind * RETURN: None
217 1.1.1.2.4.2 rmind *
218 1.1.1.2.4.2 rmind * DESCRIPTION: Sleep the running thread for specified amount of time.
219 1.1.1.2.4.2 rmind *
220 1.1.1.2.4.2 rmind ******************************************************************************/
221 1.1.1.2.4.2 rmind
222 1.1.1.2.4.2 rmind ACPI_STATUS
223 1.1.1.2.4.2 rmind AcpiExSystemDoSleep (
224 1.1.1.2.4.2 rmind UINT64 HowLong)
225 1.1.1.2.4.2 rmind {
226 1.1.1.2.4.2 rmind ACPI_FUNCTION_ENTRY ();
227 1.1.1.2.4.2 rmind
228 1.1.1.2.4.2 rmind
229 1.1.1.2.4.2 rmind /* Since this thread will sleep, we must release the interpreter */
230 1.1.1.2.4.2 rmind
231 1.1.1.2.4.2 rmind AcpiExRelinquishInterpreter ();
232 1.1.1.2.4.2 rmind
233 1.1.1.2.4.2 rmind /*
234 1.1.1.2.4.2 rmind * For compatibility with other ACPI implementations and to prevent
235 1.1.1.2.4.2 rmind * accidental deep sleeps, limit the sleep time to something reasonable.
236 1.1.1.2.4.2 rmind */
237 1.1.1.2.4.2 rmind if (HowLong > ACPI_MAX_SLEEP)
238 1.1.1.2.4.2 rmind {
239 1.1.1.2.4.2 rmind HowLong = ACPI_MAX_SLEEP;
240 1.1.1.2.4.2 rmind }
241 1.1.1.2.4.2 rmind
242 1.1.1.2.4.2 rmind AcpiOsSleep (HowLong);
243 1.1.1.2.4.2 rmind
244 1.1.1.2.4.2 rmind /* And now we must get the interpreter again */
245 1.1.1.2.4.2 rmind
246 1.1.1.2.4.2 rmind AcpiExReacquireInterpreter ();
247 1.1.1.2.4.2 rmind return (AE_OK);
248 1.1.1.2.4.2 rmind }
249 1.1.1.2.4.2 rmind
250 1.1.1.2.4.2 rmind
251 1.1.1.2.4.2 rmind /*******************************************************************************
252 1.1.1.2.4.2 rmind *
253 1.1.1.2.4.2 rmind * FUNCTION: AcpiExSystemSignalEvent
254 1.1.1.2.4.2 rmind *
255 1.1.1.2.4.2 rmind * PARAMETERS: ObjDesc - The object descriptor for this op
256 1.1.1.2.4.2 rmind *
257 1.1.1.2.4.2 rmind * RETURN: Status
258 1.1.1.2.4.2 rmind *
259 1.1.1.2.4.2 rmind * DESCRIPTION: Provides an access point to perform synchronization operations
260 1.1.1.2.4.2 rmind * within the AML.
261 1.1.1.2.4.2 rmind *
262 1.1.1.2.4.2 rmind ******************************************************************************/
263 1.1.1.2.4.2 rmind
264 1.1.1.2.4.2 rmind ACPI_STATUS
265 1.1.1.2.4.2 rmind AcpiExSystemSignalEvent (
266 1.1.1.2.4.2 rmind ACPI_OPERAND_OBJECT *ObjDesc)
267 1.1.1.2.4.2 rmind {
268 1.1.1.2.4.2 rmind ACPI_STATUS Status = AE_OK;
269 1.1.1.2.4.2 rmind
270 1.1.1.2.4.2 rmind
271 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (ExSystemSignalEvent);
272 1.1.1.2.4.2 rmind
273 1.1.1.2.4.2 rmind
274 1.1.1.2.4.2 rmind if (ObjDesc)
275 1.1.1.2.4.2 rmind {
276 1.1.1.2.4.2 rmind Status = AcpiOsSignalSemaphore (ObjDesc->Event.OsSemaphore, 1);
277 1.1.1.2.4.2 rmind }
278 1.1.1.2.4.2 rmind
279 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
280 1.1.1.2.4.2 rmind }
281 1.1.1.2.4.2 rmind
282 1.1.1.2.4.2 rmind
283 1.1.1.2.4.2 rmind /*******************************************************************************
284 1.1.1.2.4.2 rmind *
285 1.1.1.2.4.2 rmind * FUNCTION: AcpiExSystemWaitEvent
286 1.1.1.2.4.2 rmind *
287 1.1.1.2.4.2 rmind * PARAMETERS: TimeDesc - The 'time to delay' object descriptor
288 1.1.1.2.4.2 rmind * ObjDesc - The object descriptor for this op
289 1.1.1.2.4.2 rmind *
290 1.1.1.2.4.2 rmind * RETURN: Status
291 1.1.1.2.4.2 rmind *
292 1.1.1.2.4.2 rmind * DESCRIPTION: Provides an access point to perform synchronization operations
293 1.1.1.2.4.2 rmind * within the AML. This operation is a request to wait for an
294 1.1.1.2.4.2 rmind * event.
295 1.1.1.2.4.2 rmind *
296 1.1.1.2.4.2 rmind ******************************************************************************/
297 1.1.1.2.4.2 rmind
298 1.1.1.2.4.2 rmind ACPI_STATUS
299 1.1.1.2.4.2 rmind AcpiExSystemWaitEvent (
300 1.1.1.2.4.2 rmind ACPI_OPERAND_OBJECT *TimeDesc,
301 1.1.1.2.4.2 rmind ACPI_OPERAND_OBJECT *ObjDesc)
302 1.1.1.2.4.2 rmind {
303 1.1.1.2.4.2 rmind ACPI_STATUS Status = AE_OK;
304 1.1.1.2.4.2 rmind
305 1.1.1.2.4.2 rmind
306 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (ExSystemWaitEvent);
307 1.1.1.2.4.2 rmind
308 1.1.1.2.4.2 rmind
309 1.1.1.2.4.2 rmind if (ObjDesc)
310 1.1.1.2.4.2 rmind {
311 1.1.1.2.4.2 rmind Status = AcpiExSystemWaitSemaphore (ObjDesc->Event.OsSemaphore,
312 1.1.1.2.4.2 rmind (UINT16) TimeDesc->Integer.Value);
313 1.1.1.2.4.2 rmind }
314 1.1.1.2.4.2 rmind
315 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
316 1.1.1.2.4.2 rmind }
317 1.1.1.2.4.2 rmind
318 1.1.1.2.4.2 rmind
319 1.1.1.2.4.2 rmind /*******************************************************************************
320 1.1.1.2.4.2 rmind *
321 1.1.1.2.4.2 rmind * FUNCTION: AcpiExSystemResetEvent
322 1.1.1.2.4.2 rmind *
323 1.1.1.2.4.2 rmind * PARAMETERS: ObjDesc - The object descriptor for this op
324 1.1.1.2.4.2 rmind *
325 1.1.1.2.4.2 rmind * RETURN: Status
326 1.1.1.2.4.2 rmind *
327 1.1.1.2.4.2 rmind * DESCRIPTION: Reset an event to a known state.
328 1.1.1.2.4.2 rmind *
329 1.1.1.2.4.2 rmind ******************************************************************************/
330 1.1.1.2.4.2 rmind
331 1.1.1.2.4.2 rmind ACPI_STATUS
332 1.1.1.2.4.2 rmind AcpiExSystemResetEvent (
333 1.1.1.2.4.2 rmind ACPI_OPERAND_OBJECT *ObjDesc)
334 1.1.1.2.4.2 rmind {
335 1.1.1.2.4.2 rmind ACPI_STATUS Status = AE_OK;
336 1.1.1.2.4.2 rmind ACPI_SEMAPHORE TempSemaphore;
337 1.1.1.2.4.2 rmind
338 1.1.1.2.4.2 rmind
339 1.1.1.2.4.2 rmind ACPI_FUNCTION_ENTRY ();
340 1.1.1.2.4.2 rmind
341 1.1.1.2.4.2 rmind
342 1.1.1.2.4.2 rmind /*
343 1.1.1.2.4.2 rmind * We are going to simply delete the existing semaphore and
344 1.1.1.2.4.2 rmind * create a new one!
345 1.1.1.2.4.2 rmind */
346 1.1.1.2.4.2 rmind Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0, &TempSemaphore);
347 1.1.1.2.4.2 rmind if (ACPI_SUCCESS (Status))
348 1.1.1.2.4.2 rmind {
349 1.1.1.2.4.2 rmind (void) AcpiOsDeleteSemaphore (ObjDesc->Event.OsSemaphore);
350 1.1.1.2.4.2 rmind ObjDesc->Event.OsSemaphore = TempSemaphore;
351 1.1.1.2.4.2 rmind }
352 1.1.1.2.4.2 rmind
353 1.1.1.2.4.2 rmind return (Status);
354 1.1.1.2.4.2 rmind }
355 1.1.1.2.4.2 rmind
356