2 /******************************************************************************
4 * Module Name: exsystem - Interface to OS services
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2005, R. Byron Moore
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.
46 #include <acpi/acpi.h>
47 #include <acpi/acinterp.h>
48 #include <acpi/acevents.h>
50 #define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exsystem")
54 /*******************************************************************************
56 * FUNCTION: acpi_ex_system_wait_semaphore
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.
67 ******************************************************************************/
70 acpi_ex_system_wait_semaphore (
71 acpi_handle semaphore,
78 ACPI_FUNCTION_TRACE ("ex_system_wait_semaphore");
81 status = acpi_os_wait_semaphore (semaphore, 1, 0);
82 if (ACPI_SUCCESS (status)) {
83 return_ACPI_STATUS (status);
86 if (status == AE_TIME) {
87 /* We must wait, so unlock the interpreter */
89 acpi_ex_exit_interpreter ();
91 status = acpi_os_wait_semaphore (semaphore, 1, timeout);
93 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
94 "*** Thread awake after blocking, %s\n",
95 acpi_format_exception (status)));
97 /* Reacquire the interpreter */
99 status2 = acpi_ex_enter_interpreter ();
100 if (ACPI_FAILURE (status2)) {
101 /* Report fatal error, could not acquire interpreter */
103 return_ACPI_STATUS (status2);
107 return_ACPI_STATUS (status);
111 /*******************************************************************************
113 * FUNCTION: acpi_ex_system_do_stall
115 * PARAMETERS: how_long - The amount of time to stall,
120 * DESCRIPTION: Suspend running thread for specified amount of time.
121 * Note: ACPI specification requires that Stall() does not
122 * relinquish the processor, and delays longer than 100 usec
123 * should use Sleep() instead. We allow stalls up to 255 usec
124 * for compatibility with other interpreters and existing BIOSs.
126 ******************************************************************************/
129 acpi_ex_system_do_stall (
132 acpi_status status = AE_OK;
135 ACPI_FUNCTION_ENTRY ();
138 if (how_long > 255) /* 255 microseconds */ {
140 * Longer than 255 usec, this is an error
142 * (ACPI specifies 100 usec as max, but this gives some slack in
143 * order to support existing BIOSs)
145 ACPI_REPORT_ERROR (("Stall: Time parameter is too large (%d)\n",
147 status = AE_AML_OPERAND_VALUE;
150 acpi_os_stall (how_long);
157 /*******************************************************************************
159 * FUNCTION: acpi_ex_system_do_suspend
161 * PARAMETERS: how_long - The amount of time to suspend,
166 * DESCRIPTION: Suspend running thread for specified amount of time.
168 ******************************************************************************/
171 acpi_ex_system_do_suspend (
172 acpi_integer how_long)
177 ACPI_FUNCTION_ENTRY ();
180 /* Since this thread will sleep, we must release the interpreter */
182 acpi_ex_exit_interpreter ();
184 acpi_os_sleep (how_long);
186 /* And now we must get the interpreter again */
188 status = acpi_ex_enter_interpreter ();
193 /*******************************************************************************
195 * FUNCTION: acpi_ex_system_acquire_mutex
197 * PARAMETERS: time_desc - The 'time to delay' object descriptor
198 * obj_desc - The object descriptor for this op
202 * DESCRIPTION: Provides an access point to perform synchronization operations
203 * within the AML. This function will cause a lock to be generated
204 * for the Mutex pointed to by obj_desc.
206 ******************************************************************************/
209 acpi_ex_system_acquire_mutex (
210 union acpi_operand_object *time_desc,
211 union acpi_operand_object *obj_desc)
213 acpi_status status = AE_OK;
216 ACPI_FUNCTION_TRACE_PTR ("ex_system_acquire_mutex", obj_desc);
220 return_ACPI_STATUS (AE_BAD_PARAMETER);
223 /* Support for the _GL_ Mutex object -- go get the global lock */
225 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
226 status = acpi_ev_acquire_global_lock ((u16) time_desc->integer.value);
227 return_ACPI_STATUS (status);
230 status = acpi_ex_system_wait_semaphore (obj_desc->mutex.semaphore,
231 (u16) time_desc->integer.value);
232 return_ACPI_STATUS (status);
236 /*******************************************************************************
238 * FUNCTION: acpi_ex_system_release_mutex
240 * PARAMETERS: obj_desc - The object descriptor for this op
244 * DESCRIPTION: Provides an access point to perform synchronization operations
245 * within the AML. This operation is a request to release a
246 * previously acquired Mutex. If the Mutex variable is set then
247 * it will be decremented.
249 ******************************************************************************/
252 acpi_ex_system_release_mutex (
253 union acpi_operand_object *obj_desc)
255 acpi_status status = AE_OK;
258 ACPI_FUNCTION_TRACE ("ex_system_release_mutex");
262 return_ACPI_STATUS (AE_BAD_PARAMETER);
265 /* Support for the _GL_ Mutex object -- release the global lock */
267 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
268 status = acpi_ev_release_global_lock ();
269 return_ACPI_STATUS (status);
272 status = acpi_os_signal_semaphore (obj_desc->mutex.semaphore, 1);
273 return_ACPI_STATUS (status);
277 /*******************************************************************************
279 * FUNCTION: acpi_ex_system_signal_event
281 * PARAMETERS: obj_desc - The object descriptor for this op
285 * DESCRIPTION: Provides an access point to perform synchronization operations
288 ******************************************************************************/
291 acpi_ex_system_signal_event (
292 union acpi_operand_object *obj_desc)
294 acpi_status status = AE_OK;
297 ACPI_FUNCTION_TRACE ("ex_system_signal_event");
301 status = acpi_os_signal_semaphore (obj_desc->event.semaphore, 1);
304 return_ACPI_STATUS (status);
308 /*******************************************************************************
310 * FUNCTION: acpi_ex_system_wait_event
312 * PARAMETERS: time_desc - The 'time to delay' object descriptor
313 * obj_desc - The object descriptor for this op
317 * DESCRIPTION: Provides an access point to perform synchronization operations
318 * within the AML. This operation is a request to wait for an
321 ******************************************************************************/
324 acpi_ex_system_wait_event (
325 union acpi_operand_object *time_desc,
326 union acpi_operand_object *obj_desc)
328 acpi_status status = AE_OK;
331 ACPI_FUNCTION_TRACE ("ex_system_wait_event");
335 status = acpi_ex_system_wait_semaphore (obj_desc->event.semaphore,
336 (u16) time_desc->integer.value);
339 return_ACPI_STATUS (status);
343 /*******************************************************************************
345 * FUNCTION: acpi_ex_system_reset_event
347 * PARAMETERS: obj_desc - The object descriptor for this op
351 * DESCRIPTION: Reset an event to a known state.
353 ******************************************************************************/
356 acpi_ex_system_reset_event (
357 union acpi_operand_object *obj_desc)
359 acpi_status status = AE_OK;
360 void *temp_semaphore;
363 ACPI_FUNCTION_ENTRY ();
367 * We are going to simply delete the existing semaphore and
370 status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore);
371 if (ACPI_SUCCESS (status)) {
372 (void) acpi_os_delete_semaphore (obj_desc->event.semaphore);
373 obj_desc->event.semaphore = temp_semaphore;