2 /******************************************************************************
4 * Module Name: amsystem - Interface to OS services
7 *****************************************************************************/
10 * Copyright (C) 2000, 2001 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define _COMPONENT ACPI_EXECUTER
35 MODULE_NAME ("amsystem")
38 /*******************************************************************************
40 * FUNCTION: Acpi_aml_system_wait_semaphore
42 * PARAMETERS: Semaphore - OSD semaphore to wait on
43 * Timeout - Max time to wait
47 * DESCRIPTION: Implements a semaphore wait with a check to see if the
48 * semaphore is available immediately. If it is not, the
49 * interpreter is released.
51 ******************************************************************************/
54 acpi_aml_system_wait_semaphore (
55 ACPI_HANDLE semaphore,
61 status = acpi_os_wait_semaphore (semaphore, 1, 0);
62 if (ACPI_SUCCESS (status)) {
66 if (status == AE_TIME) {
67 /* We must wait, so unlock the interpreter */
69 acpi_aml_exit_interpreter ();
71 status = acpi_os_wait_semaphore (semaphore, 1, timeout);
73 /* Reacquire the interpreter */
75 status = acpi_aml_enter_interpreter ();
76 if (ACPI_SUCCESS (status)) {
77 /* Restore the timeout exception */
87 /*******************************************************************************
89 * FUNCTION: Acpi_aml_system_do_stall
91 * PARAMETERS: How_long - The amount of time to stall
95 * DESCRIPTION: Suspend running thread for specified amount of time.
97 ******************************************************************************/
100 acpi_aml_system_do_stall (
104 if (how_long > 1000) /* 1 millisecond */ {
105 /* Since this thread will sleep, we must release the interpreter */
107 acpi_aml_exit_interpreter ();
109 acpi_os_sleep_usec (how_long);
111 /* And now we must get the interpreter again */
113 acpi_aml_enter_interpreter ();
117 acpi_os_sleep_usec (how_long);
122 /*******************************************************************************
124 * FUNCTION: Acpi_aml_system_do_suspend
126 * PARAMETERS: How_long - The amount of time to suspend
130 * DESCRIPTION: Suspend running thread for specified amount of time.
132 ******************************************************************************/
135 acpi_aml_system_do_suspend (
138 /* Since this thread will sleep, we must release the interpreter */
140 acpi_aml_exit_interpreter ();
142 acpi_os_sleep ((u16) (how_long / (u32) 1000),
143 (u16) (how_long % (u32) 1000));
145 /* And now we must get the interpreter again */
147 acpi_aml_enter_interpreter ();
151 /*******************************************************************************
153 * FUNCTION: Acpi_aml_system_acquire_mutex
155 * PARAMETERS: *Time_desc - The 'time to delay' object descriptor
156 * *Obj_desc - The object descriptor for this op
160 * DESCRIPTION: Provides an access point to perform synchronization operations
161 * within the AML. This function will cause a lock to be generated
162 * for the Mutex pointed to by Obj_desc.
164 ******************************************************************************/
167 acpi_aml_system_acquire_mutex (
168 ACPI_OPERAND_OBJECT *time_desc,
169 ACPI_OPERAND_OBJECT *obj_desc)
171 ACPI_STATUS status = AE_OK;
175 return (AE_BAD_PARAMETER);
179 * Support for the _GL_ Mutex object -- go get the global lock
182 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
183 status = acpi_ev_acquire_global_lock ();
187 status = acpi_aml_system_wait_semaphore (obj_desc->mutex.semaphore,
188 (u32) time_desc->integer.value);
193 /*******************************************************************************
195 * FUNCTION: Acpi_aml_system_release_mutex
197 * PARAMETERS: *Obj_desc - The object descriptor for this op
201 * DESCRIPTION: Provides an access point to perform synchronization operations
202 * within the AML. This operation is a request to release a
203 * previously acquired Mutex. If the Mutex variable is set then
204 * it will be decremented.
206 ******************************************************************************/
209 acpi_aml_system_release_mutex (
210 ACPI_OPERAND_OBJECT *obj_desc)
212 ACPI_STATUS status = AE_OK;
216 return (AE_BAD_PARAMETER);
220 * Support for the _GL_ Mutex object -- release the global lock
222 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
223 acpi_ev_release_global_lock ();
227 status = acpi_os_signal_semaphore (obj_desc->mutex.semaphore, 1);
232 /*******************************************************************************
234 * FUNCTION: Acpi_aml_system_signal_event
236 * PARAMETERS: *Obj_desc - The object descriptor for this op
240 * DESCRIPTION: Provides an access point to perform synchronization operations
243 ******************************************************************************/
246 acpi_aml_system_signal_event (
247 ACPI_OPERAND_OBJECT *obj_desc)
249 ACPI_STATUS status = AE_OK;
253 status = acpi_os_signal_semaphore (obj_desc->event.semaphore, 1);
260 /*******************************************************************************
262 * FUNCTION: Acpi_aml_system_wait_event
264 * PARAMETERS: *Time_desc - The 'time to delay' object descriptor
265 * *Obj_desc - The object descriptor for this op
269 * DESCRIPTION: Provides an access point to perform synchronization operations
270 * within the AML. This operation is a request to wait for an
273 ******************************************************************************/
276 acpi_aml_system_wait_event (
277 ACPI_OPERAND_OBJECT *time_desc,
278 ACPI_OPERAND_OBJECT *obj_desc)
280 ACPI_STATUS status = AE_OK;
284 status = acpi_aml_system_wait_semaphore (obj_desc->event.semaphore,
285 (u32) time_desc->integer.value);
293 /*******************************************************************************
295 * FUNCTION: Acpi_aml_system_reset_event
297 * PARAMETERS: *Obj_desc - The object descriptor for this op
301 * DESCRIPTION: Reset an event to a known state.
303 ******************************************************************************/
306 acpi_aml_system_reset_event (
307 ACPI_OPERAND_OBJECT *obj_desc)
309 ACPI_STATUS status = AE_OK;
310 void *temp_semaphore;
314 * We are going to simply delete the existing semaphore and
318 status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore);
319 if (ACPI_SUCCESS (status)) {
320 acpi_os_delete_semaphore (obj_desc->event.semaphore);
321 obj_desc->event.semaphore = temp_semaphore;