Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: dsmethod - Parser/Interpreter interface - control method parsing | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
4a90c7e8 | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
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. | |
25 | * | |
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. | |
29 | * | |
30 | * NO WARRANTY | |
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. | |
42 | */ | |
43 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/acparser.h> | |
46 | #include <acpi/amlcode.h> | |
47 | #include <acpi/acdispat.h> | |
48 | #include <acpi/acinterp.h> | |
49 | #include <acpi/acnamesp.h> | |
defba1d8 | 50 | #include <acpi/acdisasm.h> |
1da177e4 | 51 | |
1da177e4 | 52 | #define _COMPONENT ACPI_DISPATCHER |
4be44fcd | 53 | ACPI_MODULE_NAME("dsmethod") |
1da177e4 | 54 | |
defba1d8 BM |
55 | /******************************************************************************* |
56 | * | |
57 | * FUNCTION: acpi_ds_method_error | |
58 | * | |
59 | * PARAMETERS: Status - Execution status | |
60 | * walk_state - Current state | |
61 | * | |
62 | * RETURN: Status | |
63 | * | |
64 | * DESCRIPTION: Called on method error. Invoke the global exception handler if | |
65 | * present, dump the method data if the disassembler is configured | |
66 | * | |
67 | * Note: Allows the exception handler to change the status code | |
68 | * | |
69 | ******************************************************************************/ | |
70 | acpi_status | |
71 | acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state) | |
72 | { | |
73 | ACPI_FUNCTION_ENTRY(); | |
74 | ||
75 | /* Ignore AE_OK and control exception codes */ | |
76 | ||
77 | if (ACPI_SUCCESS(status) || (status & AE_CODE_CONTROL)) { | |
78 | return (status); | |
79 | } | |
80 | ||
81 | /* Invoke the global exception handler */ | |
82 | ||
83 | if (acpi_gbl_exception_handler) { | |
52fc0b02 | 84 | |
defba1d8 BM |
85 | /* Exit the interpreter, allow handler to execute methods */ |
86 | ||
87 | acpi_ex_exit_interpreter(); | |
88 | ||
89 | /* | |
90 | * Handler can map the exception code to anything it wants, including | |
91 | * AE_OK, in which case the executing method will not be aborted. | |
92 | */ | |
93 | status = acpi_gbl_exception_handler(status, | |
94 | walk_state->method_node ? | |
95 | walk_state->method_node-> | |
96 | name.integer : 0, | |
97 | walk_state->opcode, | |
98 | walk_state->aml_offset, | |
99 | NULL); | |
100 | (void)acpi_ex_enter_interpreter(); | |
101 | } | |
102 | #ifdef ACPI_DISASSEMBLER | |
103 | if (ACPI_FAILURE(status)) { | |
52fc0b02 | 104 | |
defba1d8 BM |
105 | /* Display method locals/args if disassembler is present */ |
106 | ||
107 | acpi_dm_dump_method_info(status, walk_state, walk_state->op); | |
108 | } | |
109 | #endif | |
110 | ||
111 | return (status); | |
112 | } | |
113 | ||
1da177e4 LT |
114 | /******************************************************************************* |
115 | * | |
116 | * FUNCTION: acpi_ds_begin_method_execution | |
117 | * | |
118 | * PARAMETERS: method_node - Node of the method | |
119 | * obj_desc - The method object | |
120 | * calling_method_node - Caller of this method (if non-null) | |
121 | * | |
122 | * RETURN: Status | |
123 | * | |
124 | * DESCRIPTION: Prepare a method for execution. Parses the method if necessary, | |
125 | * increments the thread count, and waits at the method semaphore | |
126 | * for clearance to execute. | |
127 | * | |
128 | ******************************************************************************/ | |
defba1d8 | 129 | |
1da177e4 | 130 | acpi_status |
defba1d8 BM |
131 | acpi_ds_begin_method_execution(struct acpi_namespace_node * method_node, |
132 | union acpi_operand_object * obj_desc, | |
133 | struct acpi_namespace_node * calling_method_node) | |
1da177e4 | 134 | { |
4be44fcd | 135 | acpi_status status = AE_OK; |
1da177e4 | 136 | |
b229cf92 | 137 | ACPI_FUNCTION_TRACE_PTR(ds_begin_method_execution, method_node); |
1da177e4 LT |
138 | |
139 | if (!method_node) { | |
4be44fcd | 140 | return_ACPI_STATUS(AE_NULL_ENTRY); |
1da177e4 LT |
141 | } |
142 | ||
aff8c277 RM |
143 | /* Prevent wraparound of thread count */ |
144 | ||
145 | if (obj_desc->method.thread_count == ACPI_UINT8_MAX) { | |
b8e4d893 BM |
146 | ACPI_ERROR((AE_INFO, |
147 | "Method reached maximum reentrancy limit (255)")); | |
aff8c277 RM |
148 | return_ACPI_STATUS(AE_AML_METHOD_LIMIT); |
149 | } | |
150 | ||
1da177e4 LT |
151 | /* |
152 | * If there is a concurrency limit on this method, we need to | |
153 | * obtain a unit from the method semaphore. | |
154 | */ | |
155 | if (obj_desc->method.semaphore) { | |
156 | /* | |
157 | * Allow recursive method calls, up to the reentrancy/concurrency | |
158 | * limit imposed by the SERIALIZED rule and the sync_level method | |
159 | * parameter. | |
160 | * | |
161 | * The point of this code is to avoid permanently blocking a | |
162 | * thread that is making recursive method calls. | |
163 | */ | |
164 | if (method_node == calling_method_node) { | |
4be44fcd LB |
165 | if (obj_desc->method.thread_count >= |
166 | obj_desc->method.concurrency) { | |
167 | return_ACPI_STATUS(AE_AML_METHOD_LIMIT); | |
1da177e4 LT |
168 | } |
169 | } | |
170 | ||
171 | /* | |
172 | * Get a unit from the method semaphore. This releases the | |
b229cf92 | 173 | * interpreter if we block (then reacquires it) |
1da177e4 | 174 | */ |
4be44fcd LB |
175 | status = |
176 | acpi_ex_system_wait_semaphore(obj_desc->method.semaphore, | |
177 | ACPI_WAIT_FOREVER); | |
b229cf92 BM |
178 | if (ACPI_FAILURE(status)) { |
179 | return_ACPI_STATUS(status); | |
180 | } | |
1da177e4 LT |
181 | } |
182 | ||
aff8c277 RM |
183 | /* |
184 | * Allocate an Owner ID for this method, only if this is the first thread | |
185 | * to begin concurrent execution. We only need one owner_id, even if the | |
186 | * method is invoked recursively. | |
187 | */ | |
188 | if (!obj_desc->method.owner_id) { | |
189 | status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); | |
190 | if (ACPI_FAILURE(status)) { | |
b229cf92 | 191 | goto cleanup; |
aff8c277 RM |
192 | } |
193 | } | |
194 | ||
1da177e4 LT |
195 | /* |
196 | * Increment the method parse tree thread count since it has been | |
197 | * reentered one more time (even if it is the same thread) | |
198 | */ | |
199 | obj_desc->method.thread_count++; | |
4be44fcd | 200 | return_ACPI_STATUS(status); |
b229cf92 BM |
201 | |
202 | cleanup: | |
203 | /* On error, must signal the method semaphore if present */ | |
204 | ||
205 | if (obj_desc->method.semaphore) { | |
206 | (void)acpi_os_signal_semaphore(obj_desc->method.semaphore, 1); | |
207 | } | |
208 | return_ACPI_STATUS(status); | |
1da177e4 LT |
209 | } |
210 | ||
1da177e4 LT |
211 | /******************************************************************************* |
212 | * | |
213 | * FUNCTION: acpi_ds_call_control_method | |
214 | * | |
215 | * PARAMETERS: Thread - Info for this thread | |
216 | * this_walk_state - Current walk state | |
217 | * Op - Current Op to be walked | |
218 | * | |
219 | * RETURN: Status | |
220 | * | |
221 | * DESCRIPTION: Transfer execution to a called control method | |
222 | * | |
223 | ******************************************************************************/ | |
224 | ||
225 | acpi_status | |
4be44fcd LB |
226 | acpi_ds_call_control_method(struct acpi_thread_state *thread, |
227 | struct acpi_walk_state *this_walk_state, | |
228 | union acpi_parse_object *op) | |
1da177e4 | 229 | { |
4be44fcd LB |
230 | acpi_status status; |
231 | struct acpi_namespace_node *method_node; | |
232 | struct acpi_walk_state *next_walk_state = NULL; | |
233 | union acpi_operand_object *obj_desc; | |
234 | struct acpi_parameter_info info; | |
235 | u32 i; | |
1da177e4 | 236 | |
b229cf92 | 237 | ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state); |
1da177e4 | 238 | |
4be44fcd LB |
239 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
240 | "Execute method %p, currentstate=%p\n", | |
241 | this_walk_state->prev_op, this_walk_state)); | |
1da177e4 LT |
242 | |
243 | /* | |
244 | * Get the namespace entry for the control method we are about to call | |
245 | */ | |
246 | method_node = this_walk_state->method_call_node; | |
247 | if (!method_node) { | |
4be44fcd | 248 | return_ACPI_STATUS(AE_NULL_ENTRY); |
1da177e4 LT |
249 | } |
250 | ||
4be44fcd | 251 | obj_desc = acpi_ns_get_attached_object(method_node); |
1da177e4 | 252 | if (!obj_desc) { |
4be44fcd | 253 | return_ACPI_STATUS(AE_NULL_OBJECT); |
1da177e4 LT |
254 | } |
255 | ||
b229cf92 | 256 | /* Init for new method, possibly wait on concurrency semaphore */ |
1da177e4 | 257 | |
4be44fcd LB |
258 | status = acpi_ds_begin_method_execution(method_node, obj_desc, |
259 | this_walk_state->method_node); | |
260 | if (ACPI_FAILURE(status)) { | |
b229cf92 | 261 | return_ACPI_STATUS(status); |
1da177e4 LT |
262 | } |
263 | ||
b229cf92 BM |
264 | /* |
265 | * 1) Parse the method. All "normal" methods are parsed for each execution. | |
266 | * Internal methods (_OSI, etc.) do not require parsing. | |
267 | */ | |
1da177e4 | 268 | if (!(obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY)) { |
52fc0b02 | 269 | |
b229cf92 | 270 | /* Create a new walk state for the parse */ |
1da177e4 | 271 | |
4be44fcd LB |
272 | next_walk_state = |
273 | acpi_ds_create_walk_state(obj_desc->method.owner_id, op, | |
274 | obj_desc, NULL); | |
1da177e4 | 275 | if (!next_walk_state) { |
b229cf92 BM |
276 | status = AE_NO_MEMORY; |
277 | goto cleanup; | |
1da177e4 LT |
278 | } |
279 | ||
b229cf92 | 280 | /* Create and init a parse tree root */ |
1da177e4 | 281 | |
4be44fcd | 282 | op = acpi_ps_create_scope_op(); |
1da177e4 LT |
283 | if (!op) { |
284 | status = AE_NO_MEMORY; | |
285 | goto cleanup; | |
286 | } | |
287 | ||
4be44fcd LB |
288 | status = acpi_ds_init_aml_walk(next_walk_state, op, method_node, |
289 | obj_desc->method.aml_start, | |
290 | obj_desc->method.aml_length, | |
291 | NULL, 1); | |
292 | if (ACPI_FAILURE(status)) { | |
b229cf92 | 293 | acpi_ps_delete_parse_tree(op); |
1da177e4 LT |
294 | goto cleanup; |
295 | } | |
296 | ||
b229cf92 | 297 | /* Begin AML parse (deletes next_walk_state) */ |
1da177e4 | 298 | |
4be44fcd LB |
299 | status = acpi_ps_parse_aml(next_walk_state); |
300 | acpi_ps_delete_parse_tree(op); | |
b229cf92 BM |
301 | if (ACPI_FAILURE(status)) { |
302 | goto cleanup; | |
303 | } | |
1da177e4 LT |
304 | } |
305 | ||
b229cf92 | 306 | /* 2) Begin method execution. Create a new walk state */ |
1da177e4 | 307 | |
4be44fcd LB |
308 | next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id, |
309 | NULL, obj_desc, thread); | |
1da177e4 LT |
310 | if (!next_walk_state) { |
311 | status = AE_NO_MEMORY; | |
312 | goto cleanup; | |
313 | } | |
b229cf92 | 314 | |
1da177e4 LT |
315 | /* |
316 | * The resolved arguments were put on the previous walk state's operand | |
aff8c277 RM |
317 | * stack. Operands on the previous walk state stack always |
318 | * start at index 0. Also, null terminate the list of arguments | |
1da177e4 | 319 | */ |
4be44fcd | 320 | this_walk_state->operands[this_walk_state->num_operands] = NULL; |
1da177e4 LT |
321 | |
322 | info.parameters = &this_walk_state->operands[0]; | |
323 | info.parameter_type = ACPI_PARAM_ARGS; | |
324 | ||
4be44fcd LB |
325 | status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node, |
326 | obj_desc->method.aml_start, | |
327 | obj_desc->method.aml_length, &info, 3); | |
328 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
329 | goto cleanup; |
330 | } | |
331 | ||
332 | /* | |
333 | * Delete the operands on the previous walkstate operand stack | |
334 | * (they were copied to new objects) | |
335 | */ | |
336 | for (i = 0; i < obj_desc->method.param_count; i++) { | |
4be44fcd LB |
337 | acpi_ut_remove_reference(this_walk_state->operands[i]); |
338 | this_walk_state->operands[i] = NULL; | |
1da177e4 LT |
339 | } |
340 | ||
341 | /* Clear the operand stack */ | |
342 | ||
343 | this_walk_state->num_operands = 0; | |
344 | ||
4be44fcd LB |
345 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
346 | "Starting nested execution, newstate=%p\n", | |
347 | next_walk_state)); | |
1da177e4 | 348 | |
b229cf92 BM |
349 | /* Invoke an internal method if necessary */ |
350 | ||
1da177e4 | 351 | if (obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY) { |
4be44fcd | 352 | status = obj_desc->method.implementation(next_walk_state); |
1da177e4 LT |
353 | } |
354 | ||
aff8c277 | 355 | return_ACPI_STATUS(status); |
a94f1881 LB |
356 | |
357 | cleanup: | |
a94f1881 | 358 | |
b229cf92 | 359 | /* On error, we must terminate the method properly */ |
aff8c277 | 360 | |
b229cf92 BM |
361 | acpi_ds_terminate_control_method(obj_desc, next_walk_state); |
362 | if (next_walk_state) { | |
363 | acpi_ds_delete_walk_state(next_walk_state); | |
364 | } | |
aff8c277 | 365 | |
4be44fcd | 366 | return_ACPI_STATUS(status); |
1da177e4 LT |
367 | } |
368 | ||
1da177e4 LT |
369 | /******************************************************************************* |
370 | * | |
371 | * FUNCTION: acpi_ds_restart_control_method | |
372 | * | |
373 | * PARAMETERS: walk_state - State for preempted method (caller) | |
374 | * return_desc - Return value from the called method | |
375 | * | |
376 | * RETURN: Status | |
377 | * | |
378 | * DESCRIPTION: Restart a method that was preempted by another (nested) method | |
379 | * invocation. Handle the return value (if any) from the callee. | |
380 | * | |
381 | ******************************************************************************/ | |
382 | ||
383 | acpi_status | |
4be44fcd LB |
384 | acpi_ds_restart_control_method(struct acpi_walk_state *walk_state, |
385 | union acpi_operand_object *return_desc) | |
1da177e4 | 386 | { |
4be44fcd | 387 | acpi_status status; |
1da177e4 | 388 | |
b229cf92 | 389 | ACPI_FUNCTION_TRACE_PTR(ds_restart_control_method, walk_state); |
1da177e4 | 390 | |
4be44fcd | 391 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
b229cf92 | 392 | "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n", |
4be44fcd LB |
393 | (char *)&walk_state->method_node->name, |
394 | walk_state->method_call_op, return_desc)); | |
1da177e4 | 395 | |
4be44fcd | 396 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
b229cf92 | 397 | " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n", |
4be44fcd LB |
398 | walk_state->return_used, |
399 | walk_state->results, walk_state)); | |
1da177e4 LT |
400 | |
401 | /* Did the called method return a value? */ | |
402 | ||
403 | if (return_desc) { | |
52fc0b02 | 404 | |
1da177e4 LT |
405 | /* Are we actually going to use the return value? */ |
406 | ||
407 | if (walk_state->return_used) { | |
52fc0b02 | 408 | |
1da177e4 LT |
409 | /* Save the return value from the previous method */ |
410 | ||
4be44fcd LB |
411 | status = acpi_ds_result_push(return_desc, walk_state); |
412 | if (ACPI_FAILURE(status)) { | |
413 | acpi_ut_remove_reference(return_desc); | |
414 | return_ACPI_STATUS(status); | |
1da177e4 LT |
415 | } |
416 | ||
417 | /* | |
418 | * Save as THIS method's return value in case it is returned | |
419 | * immediately to yet another method | |
420 | */ | |
421 | walk_state->return_desc = return_desc; | |
422 | } | |
423 | ||
424 | /* | |
425 | * The following code is the | |
426 | * optional support for a so-called "implicit return". Some AML code | |
427 | * assumes that the last value of the method is "implicitly" returned | |
428 | * to the caller. Just save the last result as the return value. | |
429 | * NOTE: this is optional because the ASL language does not actually | |
430 | * support this behavior. | |
431 | */ | |
4be44fcd LB |
432 | else if (!acpi_ds_do_implicit_return |
433 | (return_desc, walk_state, FALSE)) { | |
1da177e4 LT |
434 | /* |
435 | * Delete the return value if it will not be used by the | |
436 | * calling method | |
437 | */ | |
4be44fcd | 438 | acpi_ut_remove_reference(return_desc); |
1da177e4 LT |
439 | } |
440 | } | |
441 | ||
4be44fcd | 442 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
443 | } |
444 | ||
1da177e4 LT |
445 | /******************************************************************************* |
446 | * | |
447 | * FUNCTION: acpi_ds_terminate_control_method | |
448 | * | |
b229cf92 BM |
449 | * PARAMETERS: method_desc - Method object |
450 | * walk_state - State associated with the method | |
1da177e4 | 451 | * |
aff8c277 | 452 | * RETURN: None |
1da177e4 LT |
453 | * |
454 | * DESCRIPTION: Terminate a control method. Delete everything that the method | |
455 | * created, delete all locals and arguments, and delete the parse | |
456 | * tree if requested. | |
457 | * | |
458 | ******************************************************************************/ | |
459 | ||
b229cf92 BM |
460 | void |
461 | acpi_ds_terminate_control_method(union acpi_operand_object *method_desc, | |
462 | struct acpi_walk_state *walk_state) | |
1da177e4 | 463 | { |
4be44fcd LB |
464 | struct acpi_namespace_node *method_node; |
465 | acpi_status status; | |
1da177e4 | 466 | |
b229cf92 | 467 | ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state); |
1da177e4 | 468 | |
b229cf92 | 469 | /* method_desc is required, walk_state is optional */ |
1da177e4 | 470 | |
b229cf92 | 471 | if (!method_desc) { |
aff8c277 | 472 | return_VOID; |
1da177e4 LT |
473 | } |
474 | ||
b229cf92 | 475 | if (walk_state) { |
1da177e4 | 476 | |
b229cf92 BM |
477 | /* Delete all arguments and locals */ |
478 | ||
479 | acpi_ds_method_data_delete_all(walk_state); | |
480 | } | |
1da177e4 LT |
481 | |
482 | /* | |
483 | * Lock the parser while we terminate this method. | |
484 | * If this is the last thread executing the method, | |
485 | * we have additional cleanup to perform | |
486 | */ | |
4be44fcd LB |
487 | status = acpi_ut_acquire_mutex(ACPI_MTX_PARSER); |
488 | if (ACPI_FAILURE(status)) { | |
aff8c277 | 489 | return_VOID; |
1da177e4 LT |
490 | } |
491 | ||
492 | /* Signal completion of the execution of this method if necessary */ | |
493 | ||
b229cf92 | 494 | if (method_desc->method.semaphore) { |
4be44fcd | 495 | status = |
b229cf92 | 496 | acpi_os_signal_semaphore(method_desc->method.semaphore, 1); |
4be44fcd | 497 | if (ACPI_FAILURE(status)) { |
1da177e4 | 498 | |
b229cf92 BM |
499 | /* Ignore error and continue */ |
500 | ||
501 | ACPI_EXCEPTION((AE_INFO, status, | |
502 | "Could not signal method semaphore")); | |
1da177e4 LT |
503 | } |
504 | } | |
505 | ||
b229cf92 BM |
506 | if (walk_state) { |
507 | /* | |
508 | * Delete any objects created by this method during execution. | |
509 | * The method Node is stored in the walk state | |
510 | */ | |
511 | method_node = walk_state->method_node; | |
28f55ebc | 512 | |
b229cf92 | 513 | /* Lock namespace for possible update */ |
28f55ebc | 514 | |
b229cf92 BM |
515 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
516 | if (ACPI_FAILURE(status)) { | |
517 | goto exit; | |
518 | } | |
28f55ebc | 519 | |
b229cf92 BM |
520 | /* |
521 | * Delete any namespace entries created immediately underneath | |
522 | * the method | |
523 | */ | |
524 | if (method_node && method_node->child) { | |
525 | acpi_ns_delete_namespace_subtree(method_node); | |
526 | } | |
527 | ||
528 | /* | |
529 | * Delete any namespace entries created anywhere else within | |
530 | * the namespace by the execution of this method | |
531 | */ | |
532 | acpi_ns_delete_namespace_by_owner(method_desc->method.owner_id); | |
533 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
28f55ebc BM |
534 | } |
535 | ||
b229cf92 BM |
536 | /* Decrement the thread count on the method */ |
537 | ||
538 | if (method_desc->method.thread_count) { | |
539 | method_desc->method.thread_count--; | |
540 | } else { | |
541 | ACPI_ERROR((AE_INFO, "Invalid zero thread count in method")); | |
542 | } | |
28f55ebc BM |
543 | |
544 | /* Are there any other threads currently executing this method? */ | |
545 | ||
b229cf92 | 546 | if (method_desc->method.thread_count) { |
28f55ebc BM |
547 | /* |
548 | * Additional threads. Do not release the owner_id in this case, | |
549 | * we immediately reuse it for the next thread executing this method | |
550 | */ | |
4be44fcd | 551 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
28f55ebc | 552 | "*** Completed execution of one thread, %d threads remaining\n", |
b229cf92 | 553 | method_desc->method.thread_count)); |
28f55ebc BM |
554 | } else { |
555 | /* This is the only executing thread for this method */ | |
1da177e4 | 556 | |
1da177e4 LT |
557 | /* |
558 | * Support to dynamically change a method from not_serialized to | |
28f55ebc | 559 | * Serialized if it appears that the method is incorrectly written and |
1da177e4 LT |
560 | * does not support multiple thread execution. The best example of this |
561 | * is if such a method creates namespace objects and blocks. A second | |
562 | * thread will fail with an AE_ALREADY_EXISTS exception | |
563 | * | |
564 | * This code is here because we must wait until the last thread exits | |
565 | * before creating the synchronization semaphore. | |
566 | */ | |
b229cf92 BM |
567 | if ((method_desc->method.concurrency == 1) && |
568 | (!method_desc->method.semaphore)) { | |
4be44fcd | 569 | status = acpi_os_create_semaphore(1, 1, |
b229cf92 | 570 | &method_desc->method. |
4be44fcd | 571 | semaphore); |
1da177e4 LT |
572 | } |
573 | ||
28f55ebc | 574 | /* No more threads, we can free the owner_id */ |
1da177e4 | 575 | |
b229cf92 | 576 | acpi_ut_release_owner_id(&method_desc->method.owner_id); |
1da177e4 | 577 | } |
a94f1881 | 578 | |
aff8c277 RM |
579 | exit: |
580 | (void)acpi_ut_release_mutex(ACPI_MTX_PARSER); | |
581 | return_VOID; | |
1da177e4 | 582 | } |
28f55ebc BM |
583 | |
584 | #ifdef ACPI_INIT_PARSE_METHODS | |
585 | /* | |
586 | * Note 11/2005: Removed this code to parse all methods during table | |
587 | * load because it causes problems if there are any errors during the | |
588 | * parse. Also, it seems like overkill and we probably don't want to | |
589 | * abort a table load because of an issue with a single method. | |
590 | */ | |
591 | ||
592 | /******************************************************************************* | |
593 | * | |
594 | * FUNCTION: acpi_ds_parse_method | |
595 | * | |
596 | * PARAMETERS: Node - Method node | |
597 | * | |
598 | * RETURN: Status | |
599 | * | |
600 | * DESCRIPTION: Parse the AML that is associated with the method. | |
601 | * | |
602 | * MUTEX: Assumes parser is locked | |
603 | * | |
604 | ******************************************************************************/ | |
605 | ||
606 | acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node) | |
607 | { | |
608 | acpi_status status; | |
609 | union acpi_operand_object *obj_desc; | |
610 | union acpi_parse_object *op; | |
611 | struct acpi_walk_state *walk_state; | |
612 | ||
b229cf92 | 613 | ACPI_FUNCTION_TRACE_PTR(ds_parse_method, node); |
28f55ebc BM |
614 | |
615 | /* Parameter Validation */ | |
616 | ||
617 | if (!node) { | |
618 | return_ACPI_STATUS(AE_NULL_ENTRY); | |
619 | } | |
620 | ||
621 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, | |
b229cf92 | 622 | "**** Parsing [%4.4s] **** NamedObj=%p\n", |
28f55ebc BM |
623 | acpi_ut_get_node_name(node), node)); |
624 | ||
625 | /* Extract the method object from the method Node */ | |
626 | ||
627 | obj_desc = acpi_ns_get_attached_object(node); | |
628 | if (!obj_desc) { | |
629 | return_ACPI_STATUS(AE_NULL_OBJECT); | |
630 | } | |
631 | ||
632 | /* Create a mutex for the method if there is a concurrency limit */ | |
633 | ||
634 | if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) && | |
635 | (!obj_desc->method.semaphore)) { | |
636 | status = acpi_os_create_semaphore(obj_desc->method.concurrency, | |
637 | obj_desc->method.concurrency, | |
638 | &obj_desc->method.semaphore); | |
639 | if (ACPI_FAILURE(status)) { | |
640 | return_ACPI_STATUS(status); | |
641 | } | |
642 | } | |
643 | ||
644 | /* | |
645 | * Allocate a new parser op to be the root of the parsed | |
646 | * method tree | |
647 | */ | |
648 | op = acpi_ps_alloc_op(AML_METHOD_OP); | |
649 | if (!op) { | |
650 | return_ACPI_STATUS(AE_NO_MEMORY); | |
651 | } | |
652 | ||
653 | /* Init new op with the method name and pointer back to the Node */ | |
654 | ||
655 | acpi_ps_set_name(op, node->name.integer); | |
656 | op->common.node = node; | |
657 | ||
658 | /* | |
659 | * Get a new owner_id for objects created by this method. Namespace | |
660 | * objects (such as Operation Regions) can be created during the | |
661 | * first pass parse. | |
662 | */ | |
663 | status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); | |
664 | if (ACPI_FAILURE(status)) { | |
665 | goto cleanup; | |
666 | } | |
667 | ||
668 | /* Create and initialize a new walk state */ | |
669 | ||
670 | walk_state = | |
671 | acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL, | |
672 | NULL); | |
673 | if (!walk_state) { | |
674 | status = AE_NO_MEMORY; | |
675 | goto cleanup2; | |
676 | } | |
677 | ||
678 | status = acpi_ds_init_aml_walk(walk_state, op, node, | |
679 | obj_desc->method.aml_start, | |
680 | obj_desc->method.aml_length, NULL, 1); | |
681 | if (ACPI_FAILURE(status)) { | |
682 | acpi_ds_delete_walk_state(walk_state); | |
683 | goto cleanup2; | |
684 | } | |
685 | ||
686 | /* | |
687 | * Parse the method, first pass | |
688 | * | |
689 | * The first pass load is where newly declared named objects are added into | |
690 | * the namespace. Actual evaluation of the named objects (what would be | |
691 | * called a "second pass") happens during the actual execution of the | |
692 | * method so that operands to the named objects can take on dynamic | |
693 | * run-time values. | |
694 | */ | |
695 | status = acpi_ps_parse_aml(walk_state); | |
696 | if (ACPI_FAILURE(status)) { | |
697 | goto cleanup2; | |
698 | } | |
699 | ||
700 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, | |
b229cf92 | 701 | "**** [%4.4s] Parsed **** NamedObj=%p Op=%p\n", |
28f55ebc BM |
702 | acpi_ut_get_node_name(node), node, op)); |
703 | ||
704 | /* | |
705 | * Delete the parse tree. We simply re-parse the method for every | |
706 | * execution since there isn't much overhead (compared to keeping lots | |
707 | * of parse trees around) | |
708 | */ | |
709 | acpi_ns_delete_namespace_subtree(node); | |
710 | acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id); | |
711 | ||
712 | cleanup2: | |
713 | acpi_ut_release_owner_id(&obj_desc->method.owner_id); | |
714 | ||
715 | cleanup: | |
716 | acpi_ps_delete_parse_tree(op); | |
717 | return_ACPI_STATUS(status); | |
718 | } | |
719 | #endif |