1 /******************************************************************************
3 * Module Name: exsystem - Interface to OS services
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acinterp.h>
48 #define _COMPONENT ACPI_EXECUTER
49 ACPI_MODULE_NAME ("exsystem")
52 /*******************************************************************************
54 * FUNCTION: AcpiExSystemWaitSemaphore
56 * PARAMETERS: Semaphore - Semaphore to wait on
57 * Timeout - Max time to wait
61 * DESCRIPTION: Implements a semaphore wait with a check to see if the
62 * semaphore is available immediately. If it is not, the
63 * interpreter is released before waiting.
65 ******************************************************************************/
68 AcpiExSystemWaitSemaphore (
69 ACPI_SEMAPHORE Semaphore,
75 ACPI_FUNCTION_TRACE (ExSystemWaitSemaphore);
78 Status = AcpiOsWaitSemaphore (Semaphore, 1, ACPI_DO_NOT_WAIT);
79 if (ACPI_SUCCESS (Status))
81 return_ACPI_STATUS (Status);
84 if (Status == AE_TIME)
86 /* We must wait, so unlock the interpreter */
88 AcpiExExitInterpreter ();
90 Status = AcpiOsWaitSemaphore (Semaphore, 1, Timeout);
92 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
93 "*** Thread awake after blocking, %s\n",
94 AcpiFormatException (Status)));
96 /* Reacquire the interpreter */
98 AcpiExEnterInterpreter ();
101 return_ACPI_STATUS (Status);
105 /*******************************************************************************
107 * FUNCTION: AcpiExSystemWaitMutex
109 * PARAMETERS: Mutex - Mutex to wait on
110 * Timeout - Max time to wait
114 * DESCRIPTION: Implements a mutex wait with a check to see if the
115 * mutex is available immediately. If it is not, the
116 * interpreter is released before waiting.
118 ******************************************************************************/
121 AcpiExSystemWaitMutex (
128 ACPI_FUNCTION_TRACE (ExSystemWaitMutex);
131 Status = AcpiOsAcquireMutex (Mutex, ACPI_DO_NOT_WAIT);
132 if (ACPI_SUCCESS (Status))
134 return_ACPI_STATUS (Status);
137 if (Status == AE_TIME)
139 /* We must wait, so unlock the interpreter */
141 AcpiExExitInterpreter ();
143 Status = AcpiOsAcquireMutex (Mutex, Timeout);
145 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
146 "*** Thread awake after blocking, %s\n",
147 AcpiFormatException (Status)));
149 /* Reacquire the interpreter */
151 AcpiExEnterInterpreter ();
154 return_ACPI_STATUS (Status);
158 /*******************************************************************************
160 * FUNCTION: AcpiExSystemDoStall
162 * PARAMETERS: HowLong - The amount of time to stall,
167 * DESCRIPTION: Suspend running thread for specified amount of time.
168 * Note: ACPI specification requires that Stall() does not
169 * relinquish the processor, and delays longer than 100 usec
170 * should use Sleep() instead. We allow stalls up to 255 usec
171 * for compatibility with other interpreters and existing BIOSs.
173 ******************************************************************************/
176 AcpiExSystemDoStall (
179 ACPI_STATUS Status = AE_OK;
182 ACPI_FUNCTION_ENTRY ();
185 if (HowLong > 255) /* 255 microseconds */
188 * Longer than 255 usec, this is an error
190 * (ACPI specifies 100 usec as max, but this gives some slack in
191 * order to support existing BIOSs)
193 ACPI_ERROR ((AE_INFO, "Time parameter is too large (%u)",
195 Status = AE_AML_OPERAND_VALUE;
199 AcpiOsStall (HowLong);
206 /*******************************************************************************
208 * FUNCTION: AcpiExSystemDoSleep
210 * PARAMETERS: HowLong - The amount of time to sleep,
215 * DESCRIPTION: Sleep the running thread for specified amount of time.
217 ******************************************************************************/
220 AcpiExSystemDoSleep (
223 ACPI_FUNCTION_ENTRY ();
226 /* Since this thread will sleep, we must release the interpreter */
228 AcpiExExitInterpreter ();
231 * For compatibility with other ACPI implementations and to prevent
232 * accidental deep sleeps, limit the sleep time to something reasonable.
234 if (HowLong > ACPI_MAX_SLEEP)
236 HowLong = ACPI_MAX_SLEEP;
239 AcpiOsSleep (HowLong);
241 /* And now we must get the interpreter again */
243 AcpiExEnterInterpreter ();
248 /*******************************************************************************
250 * FUNCTION: AcpiExSystemSignalEvent
252 * PARAMETERS: ObjDesc - The object descriptor for this op
256 * DESCRIPTION: Provides an access point to perform synchronization operations
259 ******************************************************************************/
262 AcpiExSystemSignalEvent (
263 ACPI_OPERAND_OBJECT *ObjDesc)
265 ACPI_STATUS Status = AE_OK;
268 ACPI_FUNCTION_TRACE (ExSystemSignalEvent);
273 Status = AcpiOsSignalSemaphore (ObjDesc->Event.OsSemaphore, 1);
276 return_ACPI_STATUS (Status);
280 /*******************************************************************************
282 * FUNCTION: AcpiExSystemWaitEvent
284 * PARAMETERS: TimeDesc - The 'time to delay' object descriptor
285 * ObjDesc - The object descriptor for this op
289 * DESCRIPTION: Provides an access point to perform synchronization operations
290 * within the AML. This operation is a request to wait for an
293 ******************************************************************************/
296 AcpiExSystemWaitEvent (
297 ACPI_OPERAND_OBJECT *TimeDesc,
298 ACPI_OPERAND_OBJECT *ObjDesc)
300 ACPI_STATUS Status = AE_OK;
303 ACPI_FUNCTION_TRACE (ExSystemWaitEvent);
308 Status = AcpiExSystemWaitSemaphore (ObjDesc->Event.OsSemaphore,
309 (UINT16) TimeDesc->Integer.Value);
312 return_ACPI_STATUS (Status);
316 /*******************************************************************************
318 * FUNCTION: AcpiExSystemResetEvent
320 * PARAMETERS: ObjDesc - The object descriptor for this op
324 * DESCRIPTION: Reset an event to a known state.
326 ******************************************************************************/
329 AcpiExSystemResetEvent (
330 ACPI_OPERAND_OBJECT *ObjDesc)
332 ACPI_STATUS Status = AE_OK;
333 ACPI_SEMAPHORE TempSemaphore;
336 ACPI_FUNCTION_ENTRY ();
340 * We are going to simply delete the existing semaphore and
343 Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0, &TempSemaphore);
344 if (ACPI_SUCCESS (Status))
346 (void) AcpiOsDeleteSemaphore (ObjDesc->Event.OsSemaphore);
347 ObjDesc->Event.OsSemaphore = TempSemaphore;