1 /******************************************************************************
3 * Module Name: exsystem - Interface to OS services
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 #define __EXSYSTEM_C__
50 #define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exsystem")
54 /*******************************************************************************
56 * FUNCTION: AcpiExSystemWaitSemaphore
58 * PARAMETERS: Semaphore - Semaphore to wait on
59 * Timeout - Max time to wait
63 * DESCRIPTION: Implements a semaphore wait with a check to see if the
64 * semaphore is available immediately. If it is not, the
65 * interpreter is released before waiting.
67 ******************************************************************************/
70 AcpiExSystemWaitSemaphore (
71 ACPI_SEMAPHORE Semaphore
,
77 ACPI_FUNCTION_TRACE (ExSystemWaitSemaphore
);
80 Status
= AcpiOsWaitSemaphore (Semaphore
, 1, ACPI_DO_NOT_WAIT
);
81 if (ACPI_SUCCESS (Status
))
83 return_ACPI_STATUS (Status
);
86 if (Status
== AE_TIME
)
88 /* We must wait, so unlock the interpreter */
90 AcpiExRelinquishInterpreter ();
92 Status
= AcpiOsWaitSemaphore (Semaphore
, 1, Timeout
);
94 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
95 "*** Thread awake after blocking, %s\n",
96 AcpiFormatException (Status
)));
98 /* Reacquire the interpreter */
100 AcpiExReacquireInterpreter ();
103 return_ACPI_STATUS (Status
);
107 /*******************************************************************************
109 * FUNCTION: AcpiExSystemWaitMutex
111 * PARAMETERS: Mutex - Mutex to wait on
112 * Timeout - Max time to wait
116 * DESCRIPTION: Implements a mutex wait with a check to see if the
117 * mutex is available immediately. If it is not, the
118 * interpreter is released before waiting.
120 ******************************************************************************/
123 AcpiExSystemWaitMutex (
130 ACPI_FUNCTION_TRACE (ExSystemWaitMutex
);
133 Status
= AcpiOsAcquireMutex (Mutex
, ACPI_DO_NOT_WAIT
);
134 if (ACPI_SUCCESS (Status
))
136 return_ACPI_STATUS (Status
);
139 if (Status
== AE_TIME
)
141 /* We must wait, so unlock the interpreter */
143 AcpiExRelinquishInterpreter ();
145 Status
= AcpiOsAcquireMutex (Mutex
, Timeout
);
147 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
148 "*** Thread awake after blocking, %s\n",
149 AcpiFormatException (Status
)));
151 /* Reacquire the interpreter */
153 AcpiExReacquireInterpreter ();
156 return_ACPI_STATUS (Status
);
160 /*******************************************************************************
162 * FUNCTION: AcpiExSystemDoStall
164 * PARAMETERS: HowLong - The amount of time to stall,
169 * DESCRIPTION: Suspend running thread for specified amount of time.
170 * Note: ACPI specification requires that Stall() does not
171 * relinquish the processor, and delays longer than 100 usec
172 * should use Sleep() instead. We allow stalls up to 255 usec
173 * for compatibility with other interpreters and existing BIOSs.
175 ******************************************************************************/
178 AcpiExSystemDoStall (
181 ACPI_STATUS Status
= AE_OK
;
184 ACPI_FUNCTION_ENTRY ();
187 if (HowLong
> 255) /* 255 microseconds */
190 * Longer than 255 usec, this is an error
192 * (ACPI specifies 100 usec as max, but this gives some slack in
193 * order to support existing BIOSs)
195 ACPI_ERROR ((AE_INFO
, "Time parameter is too large (%u)",
197 Status
= AE_AML_OPERAND_VALUE
;
201 AcpiOsStall (HowLong
);
208 /*******************************************************************************
210 * FUNCTION: AcpiExSystemDoSleep
212 * PARAMETERS: HowLong - The amount of time to sleep,
217 * DESCRIPTION: Sleep the running thread for specified amount of time.
219 ******************************************************************************/
222 AcpiExSystemDoSleep (
225 ACPI_FUNCTION_ENTRY ();
228 /* Since this thread will sleep, we must release the interpreter */
230 AcpiExRelinquishInterpreter ();
233 * For compatibility with other ACPI implementations and to prevent
234 * accidental deep sleeps, limit the sleep time to something reasonable.
236 if (HowLong
> ACPI_MAX_SLEEP
)
238 HowLong
= ACPI_MAX_SLEEP
;
241 AcpiOsSleep (HowLong
);
243 /* And now we must get the interpreter again */
245 AcpiExReacquireInterpreter ();
250 /*******************************************************************************
252 * FUNCTION: AcpiExSystemSignalEvent
254 * PARAMETERS: ObjDesc - The object descriptor for this op
258 * DESCRIPTION: Provides an access point to perform synchronization operations
261 ******************************************************************************/
264 AcpiExSystemSignalEvent (
265 ACPI_OPERAND_OBJECT
*ObjDesc
)
267 ACPI_STATUS Status
= AE_OK
;
270 ACPI_FUNCTION_TRACE (ExSystemSignalEvent
);
275 Status
= AcpiOsSignalSemaphore (ObjDesc
->Event
.OsSemaphore
, 1);
278 return_ACPI_STATUS (Status
);
282 /*******************************************************************************
284 * FUNCTION: AcpiExSystemWaitEvent
286 * PARAMETERS: TimeDesc - The 'time to delay' object descriptor
287 * ObjDesc - The object descriptor for this op
291 * DESCRIPTION: Provides an access point to perform synchronization operations
292 * within the AML. This operation is a request to wait for an
295 ******************************************************************************/
298 AcpiExSystemWaitEvent (
299 ACPI_OPERAND_OBJECT
*TimeDesc
,
300 ACPI_OPERAND_OBJECT
*ObjDesc
)
302 ACPI_STATUS Status
= AE_OK
;
305 ACPI_FUNCTION_TRACE (ExSystemWaitEvent
);
310 Status
= AcpiExSystemWaitSemaphore (ObjDesc
->Event
.OsSemaphore
,
311 (UINT16
) TimeDesc
->Integer
.Value
);
314 return_ACPI_STATUS (Status
);
318 /*******************************************************************************
320 * FUNCTION: AcpiExSystemResetEvent
322 * PARAMETERS: ObjDesc - The object descriptor for this op
326 * DESCRIPTION: Reset an event to a known state.
328 ******************************************************************************/
331 AcpiExSystemResetEvent (
332 ACPI_OPERAND_OBJECT
*ObjDesc
)
334 ACPI_STATUS Status
= AE_OK
;
335 ACPI_SEMAPHORE TempSemaphore
;
338 ACPI_FUNCTION_ENTRY ();
342 * We are going to simply delete the existing semaphore and
345 Status
= AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT
, 0, &TempSemaphore
);
346 if (ACPI_SUCCESS (Status
))
348 (void) AcpiOsDeleteSemaphore (ObjDesc
->Event
.OsSemaphore
);
349 ObjDesc
->Event
.OsSemaphore
= TempSemaphore
;