2 /******************************************************************************
4 * Module Name: exsystem - Interface to OS services
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #define __EXSYSTEM_C__
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acinterp.h>
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("exsystem")
55 /*******************************************************************************
57 * FUNCTION: AcpiExSystemWaitSemaphore
59 * PARAMETERS: Semaphore - Semaphore to wait on
60 * Timeout - Max time to wait
64 * DESCRIPTION: Implements a semaphore wait with a check to see if the
65 * semaphore is available immediately. If it is not, the
66 * interpreter is released before waiting.
68 ******************************************************************************/
71 AcpiExSystemWaitSemaphore (
72 ACPI_SEMAPHORE Semaphore,
78 ACPI_FUNCTION_TRACE (ExSystemWaitSemaphore);
81 Status = AcpiOsWaitSemaphore (Semaphore, 1, ACPI_DO_NOT_WAIT);
82 if (ACPI_SUCCESS (Status))
84 return_ACPI_STATUS (Status);
87 if (Status == AE_TIME)
89 /* We must wait, so unlock the interpreter */
91 AcpiExRelinquishInterpreter ();
93 Status = AcpiOsWaitSemaphore (Semaphore, 1, Timeout);
95 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
96 "*** Thread awake after blocking, %s\n",
97 AcpiFormatException (Status)));
99 /* Reacquire the interpreter */
101 AcpiExReacquireInterpreter ();
104 return_ACPI_STATUS (Status);
108 /*******************************************************************************
110 * FUNCTION: AcpiExSystemWaitMutex
112 * PARAMETERS: Mutex - Mutex to wait on
113 * Timeout - Max time to wait
117 * DESCRIPTION: Implements a mutex wait with a check to see if the
118 * mutex is available immediately. If it is not, the
119 * interpreter is released before waiting.
121 ******************************************************************************/
124 AcpiExSystemWaitMutex (
131 ACPI_FUNCTION_TRACE (ExSystemWaitMutex);
134 Status = AcpiOsAcquireMutex (Mutex, ACPI_DO_NOT_WAIT);
135 if (ACPI_SUCCESS (Status))
137 return_ACPI_STATUS (Status);
140 if (Status == AE_TIME)
142 /* We must wait, so unlock the interpreter */
144 AcpiExRelinquishInterpreter ();
146 Status = AcpiOsAcquireMutex (Mutex, Timeout);
148 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
149 "*** Thread awake after blocking, %s\n",
150 AcpiFormatException (Status)));
152 /* Reacquire the interpreter */
154 AcpiExReacquireInterpreter ();
157 return_ACPI_STATUS (Status);
161 /*******************************************************************************
163 * FUNCTION: AcpiExSystemDoStall
165 * PARAMETERS: HowLong - The amount of time to stall,
170 * DESCRIPTION: Suspend running thread for specified amount of time.
171 * Note: ACPI specification requires that Stall() does not
172 * relinquish the processor, and delays longer than 100 usec
173 * should use Sleep() instead. We allow stalls up to 255 usec
174 * for compatibility with other interpreters and existing BIOSs.
176 ******************************************************************************/
179 AcpiExSystemDoStall (
182 ACPI_STATUS Status = AE_OK;
185 ACPI_FUNCTION_ENTRY ();
188 if (HowLong > 255) /* 255 microseconds */
191 * Longer than 255 usec, this is an error
193 * (ACPI specifies 100 usec as max, but this gives some slack in
194 * order to support existing BIOSs)
196 ACPI_ERROR ((AE_INFO, "Time parameter is too large (%u)",
198 Status = AE_AML_OPERAND_VALUE;
202 AcpiOsStall (HowLong);
209 /*******************************************************************************
211 * FUNCTION: AcpiExSystemDoSleep
213 * PARAMETERS: HowLong - The amount of time to sleep,
218 * DESCRIPTION: Sleep the running thread for specified amount of time.
220 ******************************************************************************/
223 AcpiExSystemDoSleep (
226 ACPI_FUNCTION_ENTRY ();
229 /* Since this thread will sleep, we must release the interpreter */
231 AcpiExRelinquishInterpreter ();
234 * For compatibility with other ACPI implementations and to prevent
235 * accidental deep sleeps, limit the sleep time to something reasonable.
237 if (HowLong > ACPI_MAX_SLEEP)
239 HowLong = ACPI_MAX_SLEEP;
242 AcpiOsSleep (HowLong);
244 /* And now we must get the interpreter again */
246 AcpiExReacquireInterpreter ();
251 /*******************************************************************************
253 * FUNCTION: AcpiExSystemSignalEvent
255 * PARAMETERS: ObjDesc - The object descriptor for this op
259 * DESCRIPTION: Provides an access point to perform synchronization operations
262 ******************************************************************************/
265 AcpiExSystemSignalEvent (
266 ACPI_OPERAND_OBJECT *ObjDesc)
268 ACPI_STATUS Status = AE_OK;
271 ACPI_FUNCTION_TRACE (ExSystemSignalEvent);
276 Status = AcpiOsSignalSemaphore (ObjDesc->Event.OsSemaphore, 1);
279 return_ACPI_STATUS (Status);
283 /*******************************************************************************
285 * FUNCTION: AcpiExSystemWaitEvent
287 * PARAMETERS: TimeDesc - The 'time to delay' object descriptor
288 * ObjDesc - The object descriptor for this op
292 * DESCRIPTION: Provides an access point to perform synchronization operations
293 * within the AML. This operation is a request to wait for an
296 ******************************************************************************/
299 AcpiExSystemWaitEvent (
300 ACPI_OPERAND_OBJECT *TimeDesc,
301 ACPI_OPERAND_OBJECT *ObjDesc)
303 ACPI_STATUS Status = AE_OK;
306 ACPI_FUNCTION_TRACE (ExSystemWaitEvent);
311 Status = AcpiExSystemWaitSemaphore (ObjDesc->Event.OsSemaphore,
312 (UINT16) TimeDesc->Integer.Value);
315 return_ACPI_STATUS (Status);
319 /*******************************************************************************
321 * FUNCTION: AcpiExSystemResetEvent
323 * PARAMETERS: ObjDesc - The object descriptor for this op
327 * DESCRIPTION: Reset an event to a known state.
329 ******************************************************************************/
332 AcpiExSystemResetEvent (
333 ACPI_OPERAND_OBJECT *ObjDesc)
335 ACPI_STATUS Status = AE_OK;
336 ACPI_SEMAPHORE TempSemaphore;
339 ACPI_FUNCTION_ENTRY ();
343 * We are going to simply delete the existing semaphore and
346 Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0, &TempSemaphore);
347 if (ACPI_SUCCESS (Status))
349 (void) AcpiOsDeleteSemaphore (ObjDesc->Event.OsSemaphore);
350 ObjDesc->Event.OsSemaphore = TempSemaphore;