1 |
1275 |
phoenix |
|
2 |
|
|
/******************************************************************************
|
3 |
|
|
*
|
4 |
|
|
* Module Name: exsystem - Interface to OS services
|
5 |
|
|
*
|
6 |
|
|
*****************************************************************************/
|
7 |
|
|
|
8 |
|
|
/*
|
9 |
|
|
* Copyright (C) 2000 - 2004, R. Byron Moore
|
10 |
|
|
* All rights reserved.
|
11 |
|
|
*
|
12 |
|
|
* Redistribution and use in source and binary forms, with or without
|
13 |
|
|
* modification, are permitted provided that the following conditions
|
14 |
|
|
* are met:
|
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.
|
26 |
|
|
*
|
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.
|
30 |
|
|
*
|
31 |
|
|
* NO WARRANTY
|
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.
|
43 |
|
|
*/
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
#include <acpi/acpi.h>
|
47 |
|
|
#include <acpi/acinterp.h>
|
48 |
|
|
#include <acpi/acevents.h>
|
49 |
|
|
|
50 |
|
|
#define _COMPONENT ACPI_EXECUTER
|
51 |
|
|
ACPI_MODULE_NAME ("exsystem")
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
/*******************************************************************************
|
55 |
|
|
*
|
56 |
|
|
* FUNCTION: acpi_ex_system_wait_semaphore
|
57 |
|
|
*
|
58 |
|
|
* PARAMETERS: Semaphore - OSD semaphore to wait on
|
59 |
|
|
* Timeout - Max time to wait
|
60 |
|
|
*
|
61 |
|
|
* RETURN: Status
|
62 |
|
|
*
|
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.
|
66 |
|
|
*
|
67 |
|
|
******************************************************************************/
|
68 |
|
|
|
69 |
|
|
acpi_status
|
70 |
|
|
acpi_ex_system_wait_semaphore (
|
71 |
|
|
acpi_handle semaphore,
|
72 |
|
|
u16 timeout)
|
73 |
|
|
{
|
74 |
|
|
acpi_status status;
|
75 |
|
|
acpi_status status2;
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
ACPI_FUNCTION_TRACE ("ex_system_wait_semaphore");
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
status = acpi_os_wait_semaphore (semaphore, 1, 0);
|
82 |
|
|
if (ACPI_SUCCESS (status)) {
|
83 |
|
|
return_ACPI_STATUS (status);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
if (status == AE_TIME) {
|
87 |
|
|
/* We must wait, so unlock the interpreter */
|
88 |
|
|
|
89 |
|
|
acpi_ex_exit_interpreter ();
|
90 |
|
|
|
91 |
|
|
status = acpi_os_wait_semaphore (semaphore, 1, timeout);
|
92 |
|
|
|
93 |
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*** Thread awake after blocking, %s\n",
|
94 |
|
|
acpi_format_exception (status)));
|
95 |
|
|
|
96 |
|
|
/* Reacquire the interpreter */
|
97 |
|
|
|
98 |
|
|
status2 = acpi_ex_enter_interpreter ();
|
99 |
|
|
if (ACPI_FAILURE (status2)) {
|
100 |
|
|
/* Report fatal error, could not acquire interpreter */
|
101 |
|
|
|
102 |
|
|
return_ACPI_STATUS (status2);
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
return_ACPI_STATUS (status);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
/*******************************************************************************
|
111 |
|
|
*
|
112 |
|
|
* FUNCTION: acpi_ex_system_do_stall
|
113 |
|
|
*
|
114 |
|
|
* PARAMETERS: how_long - The amount of time to stall,
|
115 |
|
|
* in microseconds
|
116 |
|
|
*
|
117 |
|
|
* RETURN: Status
|
118 |
|
|
*
|
119 |
|
|
* DESCRIPTION: Suspend running thread for specified amount of time.
|
120 |
|
|
* Note: ACPI specification requires that Stall() does not
|
121 |
|
|
* relinquish the processor, and delays longer than 100 usec
|
122 |
|
|
* should use Sleep() instead. We allow stalls up to 255 usec
|
123 |
|
|
* for compatibility with other interpreters and existing BIOSs.
|
124 |
|
|
*
|
125 |
|
|
******************************************************************************/
|
126 |
|
|
|
127 |
|
|
acpi_status
|
128 |
|
|
acpi_ex_system_do_stall (
|
129 |
|
|
u32 how_long)
|
130 |
|
|
{
|
131 |
|
|
acpi_status status = AE_OK;
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
ACPI_FUNCTION_ENTRY ();
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
if (how_long > 255) /* 255 microseconds */ {
|
138 |
|
|
/*
|
139 |
|
|
* Longer than 255 usec, this is an error
|
140 |
|
|
*
|
141 |
|
|
* (ACPI specifies 100 usec as max, but this gives some slack in
|
142 |
|
|
* order to support existing BIOSs)
|
143 |
|
|
*/
|
144 |
|
|
ACPI_REPORT_ERROR (("Stall: Time parameter is too large (%d)\n", how_long));
|
145 |
|
|
status = AE_AML_OPERAND_VALUE;
|
146 |
|
|
}
|
147 |
|
|
else {
|
148 |
|
|
acpi_os_stall (how_long);
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
return (status);
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
/*******************************************************************************
|
156 |
|
|
*
|
157 |
|
|
* FUNCTION: acpi_ex_system_do_suspend
|
158 |
|
|
*
|
159 |
|
|
* PARAMETERS: how_long - The amount of time to suspend,
|
160 |
|
|
* in milliseconds
|
161 |
|
|
*
|
162 |
|
|
* RETURN: None
|
163 |
|
|
*
|
164 |
|
|
* DESCRIPTION: Suspend running thread for specified amount of time.
|
165 |
|
|
*
|
166 |
|
|
******************************************************************************/
|
167 |
|
|
|
168 |
|
|
acpi_status
|
169 |
|
|
acpi_ex_system_do_suspend (
|
170 |
|
|
u32 how_long)
|
171 |
|
|
{
|
172 |
|
|
acpi_status status;
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
ACPI_FUNCTION_ENTRY ();
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
/* Since this thread will sleep, we must release the interpreter */
|
179 |
|
|
|
180 |
|
|
acpi_ex_exit_interpreter ();
|
181 |
|
|
|
182 |
|
|
acpi_os_sleep ((u16) (how_long / (u32) 1000),
|
183 |
|
|
(u16) (how_long % (u32) 1000));
|
184 |
|
|
|
185 |
|
|
/* And now we must get the interpreter again */
|
186 |
|
|
|
187 |
|
|
status = acpi_ex_enter_interpreter ();
|
188 |
|
|
return (status);
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
/*******************************************************************************
|
193 |
|
|
*
|
194 |
|
|
* FUNCTION: acpi_ex_system_acquire_mutex
|
195 |
|
|
*
|
196 |
|
|
* PARAMETERS: *time_desc - The 'time to delay' object descriptor
|
197 |
|
|
* *obj_desc - The object descriptor for this op
|
198 |
|
|
*
|
199 |
|
|
* RETURN: Status
|
200 |
|
|
*
|
201 |
|
|
* DESCRIPTION: Provides an access point to perform synchronization operations
|
202 |
|
|
* within the AML. This function will cause a lock to be generated
|
203 |
|
|
* for the Mutex pointed to by obj_desc.
|
204 |
|
|
*
|
205 |
|
|
******************************************************************************/
|
206 |
|
|
|
207 |
|
|
acpi_status
|
208 |
|
|
acpi_ex_system_acquire_mutex (
|
209 |
|
|
union acpi_operand_object *time_desc,
|
210 |
|
|
union acpi_operand_object *obj_desc)
|
211 |
|
|
{
|
212 |
|
|
acpi_status status = AE_OK;
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
ACPI_FUNCTION_TRACE_PTR ("ex_system_acquire_mutex", obj_desc);
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
if (!obj_desc) {
|
219 |
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
/*
|
223 |
|
|
* Support for the _GL_ Mutex object -- go get the global lock
|
224 |
|
|
*/
|
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);
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
status = acpi_ex_system_wait_semaphore (obj_desc->mutex.semaphore,
|
231 |
|
|
(u16) time_desc->integer.value);
|
232 |
|
|
return_ACPI_STATUS (status);
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
/*******************************************************************************
|
237 |
|
|
*
|
238 |
|
|
* FUNCTION: acpi_ex_system_release_mutex
|
239 |
|
|
*
|
240 |
|
|
* PARAMETERS: *obj_desc - The object descriptor for this op
|
241 |
|
|
*
|
242 |
|
|
* RETURN: Status
|
243 |
|
|
*
|
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.
|
248 |
|
|
*
|
249 |
|
|
******************************************************************************/
|
250 |
|
|
|
251 |
|
|
acpi_status
|
252 |
|
|
acpi_ex_system_release_mutex (
|
253 |
|
|
union acpi_operand_object *obj_desc)
|
254 |
|
|
{
|
255 |
|
|
acpi_status status = AE_OK;
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
ACPI_FUNCTION_TRACE ("ex_system_release_mutex");
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
if (!obj_desc) {
|
262 |
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
263 |
|
|
}
|
264 |
|
|
|
265 |
|
|
/*
|
266 |
|
|
* Support for the _GL_ Mutex object -- release the global lock
|
267 |
|
|
*/
|
268 |
|
|
if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
|
269 |
|
|
status = acpi_ev_release_global_lock ();
|
270 |
|
|
return_ACPI_STATUS (status);
|
271 |
|
|
}
|
272 |
|
|
|
273 |
|
|
status = acpi_os_signal_semaphore (obj_desc->mutex.semaphore, 1);
|
274 |
|
|
return_ACPI_STATUS (status);
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
/*******************************************************************************
|
279 |
|
|
*
|
280 |
|
|
* FUNCTION: acpi_ex_system_signal_event
|
281 |
|
|
*
|
282 |
|
|
* PARAMETERS: *obj_desc - The object descriptor for this op
|
283 |
|
|
*
|
284 |
|
|
* RETURN: AE_OK
|
285 |
|
|
*
|
286 |
|
|
* DESCRIPTION: Provides an access point to perform synchronization operations
|
287 |
|
|
* within the AML.
|
288 |
|
|
*
|
289 |
|
|
******************************************************************************/
|
290 |
|
|
|
291 |
|
|
acpi_status
|
292 |
|
|
acpi_ex_system_signal_event (
|
293 |
|
|
union acpi_operand_object *obj_desc)
|
294 |
|
|
{
|
295 |
|
|
acpi_status status = AE_OK;
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
ACPI_FUNCTION_TRACE ("ex_system_signal_event");
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
if (obj_desc) {
|
302 |
|
|
status = acpi_os_signal_semaphore (obj_desc->event.semaphore, 1);
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
return_ACPI_STATUS (status);
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
/*******************************************************************************
|
310 |
|
|
*
|
311 |
|
|
* FUNCTION: acpi_ex_system_wait_event
|
312 |
|
|
*
|
313 |
|
|
* PARAMETERS: *time_desc - The 'time to delay' object descriptor
|
314 |
|
|
* *obj_desc - The object descriptor for this op
|
315 |
|
|
*
|
316 |
|
|
* RETURN: Status
|
317 |
|
|
*
|
318 |
|
|
* DESCRIPTION: Provides an access point to perform synchronization operations
|
319 |
|
|
* within the AML. This operation is a request to wait for an
|
320 |
|
|
* event.
|
321 |
|
|
*
|
322 |
|
|
******************************************************************************/
|
323 |
|
|
|
324 |
|
|
acpi_status
|
325 |
|
|
acpi_ex_system_wait_event (
|
326 |
|
|
union acpi_operand_object *time_desc,
|
327 |
|
|
union acpi_operand_object *obj_desc)
|
328 |
|
|
{
|
329 |
|
|
acpi_status status = AE_OK;
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
ACPI_FUNCTION_TRACE ("ex_system_wait_event");
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
if (obj_desc) {
|
336 |
|
|
status = acpi_ex_system_wait_semaphore (obj_desc->event.semaphore,
|
337 |
|
|
(u16) time_desc->integer.value);
|
338 |
|
|
}
|
339 |
|
|
|
340 |
|
|
return_ACPI_STATUS (status);
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
|
344 |
|
|
/*******************************************************************************
|
345 |
|
|
*
|
346 |
|
|
* FUNCTION: acpi_ex_system_reset_event
|
347 |
|
|
*
|
348 |
|
|
* PARAMETERS: *obj_desc - The object descriptor for this op
|
349 |
|
|
*
|
350 |
|
|
* RETURN: Status
|
351 |
|
|
*
|
352 |
|
|
* DESCRIPTION: Reset an event to a known state.
|
353 |
|
|
*
|
354 |
|
|
******************************************************************************/
|
355 |
|
|
|
356 |
|
|
acpi_status
|
357 |
|
|
acpi_ex_system_reset_event (
|
358 |
|
|
union acpi_operand_object *obj_desc)
|
359 |
|
|
{
|
360 |
|
|
acpi_status status = AE_OK;
|
361 |
|
|
void *temp_semaphore;
|
362 |
|
|
|
363 |
|
|
|
364 |
|
|
ACPI_FUNCTION_ENTRY ();
|
365 |
|
|
|
366 |
|
|
|
367 |
|
|
/*
|
368 |
|
|
* We are going to simply delete the existing semaphore and
|
369 |
|
|
* create a new one!
|
370 |
|
|
*/
|
371 |
|
|
status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore);
|
372 |
|
|
if (ACPI_SUCCESS (status)) {
|
373 |
|
|
(void) acpi_os_delete_semaphore (obj_desc->event.semaphore);
|
374 |
|
|
obj_desc->event.semaphore = temp_semaphore;
|
375 |
|
|
}
|
376 |
|
|
|
377 |
|
|
return (status);
|
378 |
|
|
}
|
379 |
|
|
|