1 /******************************************************************************
3 * Module Name: exsystem - Interface to OS services
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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.
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 ();
89 Status
= AcpiOsWaitSemaphore (Semaphore
, 1, Timeout
);
91 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
92 "*** Thread awake after blocking, %s\n",
93 AcpiFormatException (Status
)));
95 /* Reacquire the interpreter */
97 AcpiExEnterInterpreter ();
100 return_ACPI_STATUS (Status
);
104 /*******************************************************************************
106 * FUNCTION: AcpiExSystemWaitMutex
108 * PARAMETERS: Mutex - Mutex to wait on
109 * Timeout - Max time to wait
113 * DESCRIPTION: Implements a mutex wait with a check to see if the
114 * mutex is available immediately. If it is not, the
115 * interpreter is released before waiting.
117 ******************************************************************************/
120 AcpiExSystemWaitMutex (
127 ACPI_FUNCTION_TRACE (ExSystemWaitMutex
);
130 Status
= AcpiOsAcquireMutex (Mutex
, ACPI_DO_NOT_WAIT
);
131 if (ACPI_SUCCESS (Status
))
133 return_ACPI_STATUS (Status
);
136 if (Status
== AE_TIME
)
138 /* We must wait, so unlock the interpreter */
140 AcpiExExitInterpreter ();
141 Status
= AcpiOsAcquireMutex (Mutex
, Timeout
);
143 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
144 "*** Thread awake after blocking, %s\n",
145 AcpiFormatException (Status
)));
147 /* Reacquire the interpreter */
149 AcpiExEnterInterpreter ();
152 return_ACPI_STATUS (Status
);
156 /*******************************************************************************
158 * FUNCTION: AcpiExSystemDoStall
160 * PARAMETERS: HowLong - The amount of time to stall,
165 * DESCRIPTION: Suspend running thread for specified amount of time.
166 * Note: ACPI specification requires that Stall() does not
167 * relinquish the processor, and delays longer than 100 usec
168 * should use Sleep() instead. We allow stalls up to 255 usec
169 * for compatibility with other interpreters and existing BIOSs.
171 ******************************************************************************/
174 AcpiExSystemDoStall (
177 ACPI_STATUS Status
= AE_OK
;
180 ACPI_FUNCTION_ENTRY ();
183 if (HowLong
> 255) /* 255 microseconds */
186 * Longer than 255 usec, this is an error
188 * (ACPI specifies 100 usec as max, but this gives some slack in
189 * order to support existing BIOSs)
191 ACPI_ERROR ((AE_INFO
,
192 "Time parameter is too large (%u)", HowLong
));
193 Status
= AE_AML_OPERAND_VALUE
;
197 AcpiOsStall (HowLong
);
204 /*******************************************************************************
206 * FUNCTION: AcpiExSystemDoSleep
208 * PARAMETERS: HowLong - The amount of time to sleep,
213 * DESCRIPTION: Sleep the running thread for specified amount of time.
215 ******************************************************************************/
218 AcpiExSystemDoSleep (
221 ACPI_FUNCTION_ENTRY ();
224 /* Since this thread will sleep, we must release the interpreter */
226 AcpiExExitInterpreter ();
229 * For compatibility with other ACPI implementations and to prevent
230 * accidental deep sleeps, limit the sleep time to something reasonable.
232 if (HowLong
> ACPI_MAX_SLEEP
)
234 HowLong
= ACPI_MAX_SLEEP
;
237 AcpiOsSleep (HowLong
);
239 /* And now we must get the interpreter again */
241 AcpiExEnterInterpreter ();
246 /*******************************************************************************
248 * FUNCTION: AcpiExSystemSignalEvent
250 * PARAMETERS: ObjDesc - The object descriptor for this op
254 * DESCRIPTION: Provides an access point to perform synchronization operations
257 ******************************************************************************/
260 AcpiExSystemSignalEvent (
261 ACPI_OPERAND_OBJECT
*ObjDesc
)
263 ACPI_STATUS Status
= AE_OK
;
266 ACPI_FUNCTION_TRACE (ExSystemSignalEvent
);
271 Status
= AcpiOsSignalSemaphore (ObjDesc
->Event
.OsSemaphore
, 1);
274 return_ACPI_STATUS (Status
);
278 /*******************************************************************************
280 * FUNCTION: AcpiExSystemWaitEvent
282 * PARAMETERS: TimeDesc - The 'time to delay' object descriptor
283 * ObjDesc - The object descriptor for this op
287 * DESCRIPTION: Provides an access point to perform synchronization operations
288 * within the AML. This operation is a request to wait for an
291 ******************************************************************************/
294 AcpiExSystemWaitEvent (
295 ACPI_OPERAND_OBJECT
*TimeDesc
,
296 ACPI_OPERAND_OBJECT
*ObjDesc
)
298 ACPI_STATUS Status
= AE_OK
;
301 ACPI_FUNCTION_TRACE (ExSystemWaitEvent
);
306 Status
= AcpiExSystemWaitSemaphore (ObjDesc
->Event
.OsSemaphore
,
307 (UINT16
) TimeDesc
->Integer
.Value
);
310 return_ACPI_STATUS (Status
);
314 /*******************************************************************************
316 * FUNCTION: AcpiExSystemResetEvent
318 * PARAMETERS: ObjDesc - The object descriptor for this op
322 * DESCRIPTION: Reset an event to a known state.
324 ******************************************************************************/
327 AcpiExSystemResetEvent (
328 ACPI_OPERAND_OBJECT
*ObjDesc
)
330 ACPI_STATUS Status
= AE_OK
;
331 ACPI_SEMAPHORE TempSemaphore
;
334 ACPI_FUNCTION_ENTRY ();
338 * We are going to simply delete the existing semaphore and
341 Status
= AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT
, 0, &TempSemaphore
);
342 if (ACPI_SUCCESS (Status
))
344 (void) AcpiOsDeleteSemaphore (ObjDesc
->Event
.OsSemaphore
);
345 ObjDesc
->Event
.OsSemaphore
= TempSemaphore
;