1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "amlcode.h"
47#include "acdispat.h"
48#include "acinterp.h"
49#include "acnamesp.h"
50#ifdef ACPI_DISASSEMBLER
51#include <acpi/acdisasm.h>
52#endif
53
54#define _COMPONENT ACPI_DISPATCHER
55ACPI_MODULE_NAME("dsmethod")
56
57
58static acpi_status
59acpi_ds_create_method_mutex(union acpi_operand_object *method_desc);
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77acpi_status
78acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
79{
80 ACPI_FUNCTION_ENTRY();
81
82
83
84 if (ACPI_SUCCESS(status) || (status & AE_CODE_CONTROL)) {
85 return (status);
86 }
87
88
89
90 if (acpi_gbl_exception_handler) {
91
92
93
94 acpi_ex_exit_interpreter();
95
96
97
98
99
100 status = acpi_gbl_exception_handler(status,
101 walk_state->method_node ?
102 walk_state->method_node->
103 name.integer : 0,
104 walk_state->opcode,
105 walk_state->aml_offset,
106 NULL);
107 acpi_ex_enter_interpreter();
108 }
109
110 acpi_ds_clear_implicit_return(walk_state);
111
112#ifdef ACPI_DISASSEMBLER
113 if (ACPI_FAILURE(status)) {
114
115
116
117 acpi_dm_dump_method_info(status, walk_state, walk_state->op);
118 }
119#endif
120
121 return (status);
122}
123
124
125
126
127
128
129
130
131
132
133
134
135
136static acpi_status
137acpi_ds_create_method_mutex(union acpi_operand_object *method_desc)
138{
139 union acpi_operand_object *mutex_desc;
140 acpi_status status;
141
142 ACPI_FUNCTION_TRACE(ds_create_method_mutex);
143
144
145
146 mutex_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
147 if (!mutex_desc) {
148 return_ACPI_STATUS(AE_NO_MEMORY);
149 }
150
151
152
153 status = acpi_os_create_mutex(&mutex_desc->mutex.os_mutex);
154 if (ACPI_FAILURE(status)) {
155 return_ACPI_STATUS(status);
156 }
157
158 mutex_desc->mutex.sync_level = method_desc->method.sync_level;
159 method_desc->method.mutex = mutex_desc;
160 return_ACPI_STATUS(AE_OK);
161}
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180acpi_status
181acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
182 union acpi_operand_object *obj_desc,
183 struct acpi_walk_state *walk_state)
184{
185 acpi_status status = AE_OK;
186
187 ACPI_FUNCTION_TRACE_PTR(ds_begin_method_execution, method_node);
188
189 if (!method_node) {
190 return_ACPI_STATUS(AE_NULL_ENTRY);
191 }
192
193
194
195 if (obj_desc->method.thread_count == ACPI_UINT8_MAX) {
196 ACPI_ERROR((AE_INFO,
197 "Method reached maximum reentrancy limit (255)"));
198 return_ACPI_STATUS(AE_AML_METHOD_LIMIT);
199 }
200
201
202
203
204 if (obj_desc->method.method_flags & AML_METHOD_SERIALIZED) {
205
206
207
208
209
210 if (!obj_desc->method.mutex) {
211 status = acpi_ds_create_method_mutex(obj_desc);
212 if (ACPI_FAILURE(status)) {
213 return_ACPI_STATUS(status);
214 }
215 }
216
217
218
219
220
221
222
223
224 if (walk_state &&
225 (walk_state->thread->current_sync_level >
226 obj_desc->method.mutex->mutex.sync_level)) {
227 ACPI_ERROR((AE_INFO,
228 "Cannot acquire Mutex for method [%4.4s], current SyncLevel is too large (%d)",
229 acpi_ut_get_node_name(method_node),
230 walk_state->thread->current_sync_level));
231
232 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
233 }
234
235
236
237
238
239 if (!walk_state ||
240 !obj_desc->method.mutex->mutex.thread_id ||
241 (walk_state->thread->thread_id !=
242 obj_desc->method.mutex->mutex.thread_id)) {
243
244
245
246
247 status =
248 acpi_ex_system_wait_mutex(obj_desc->method.mutex->
249 mutex.os_mutex,
250 ACPI_WAIT_FOREVER);
251 if (ACPI_FAILURE(status)) {
252 return_ACPI_STATUS(status);
253 }
254
255
256
257 if (walk_state) {
258 obj_desc->method.mutex->mutex.
259 original_sync_level =
260 walk_state->thread->current_sync_level;
261
262 obj_desc->method.mutex->mutex.thread_id =
263 walk_state->thread->thread_id;
264 walk_state->thread->current_sync_level =
265 obj_desc->method.sync_level;
266 } else {
267 obj_desc->method.mutex->mutex.
268 original_sync_level =
269 obj_desc->method.mutex->mutex.sync_level;
270 }
271 }
272
273
274
275 obj_desc->method.mutex->mutex.acquisition_depth++;
276 }
277
278
279
280
281
282
283 if (!obj_desc->method.owner_id) {
284 status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
285 if (ACPI_FAILURE(status)) {
286 goto cleanup;
287 }
288 }
289
290
291
292
293
294 obj_desc->method.thread_count++;
295 return_ACPI_STATUS(status);
296
297 cleanup:
298
299
300 if (obj_desc->method.mutex) {
301 acpi_os_release_mutex(obj_desc->method.mutex->mutex.os_mutex);
302 }
303 return_ACPI_STATUS(status);
304}
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320acpi_status
321acpi_ds_call_control_method(struct acpi_thread_state *thread,
322 struct acpi_walk_state *this_walk_state,
323 union acpi_parse_object *op)
324{
325 acpi_status status;
326 struct acpi_namespace_node *method_node;
327 struct acpi_walk_state *next_walk_state = NULL;
328 union acpi_operand_object *obj_desc;
329 struct acpi_evaluate_info *info;
330 u32 i;
331
332 ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state);
333
334 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
335 "Calling method %p, currentstate=%p\n",
336 this_walk_state->prev_op, this_walk_state));
337
338
339
340
341 method_node = this_walk_state->method_call_node;
342 if (!method_node) {
343 return_ACPI_STATUS(AE_NULL_ENTRY);
344 }
345
346 obj_desc = acpi_ns_get_attached_object(method_node);
347 if (!obj_desc) {
348 return_ACPI_STATUS(AE_NULL_OBJECT);
349 }
350
351
352
353 status = acpi_ds_begin_method_execution(method_node, obj_desc,
354 this_walk_state);
355 if (ACPI_FAILURE(status)) {
356 return_ACPI_STATUS(status);
357 }
358
359
360
361 next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id,
362 NULL, obj_desc, thread);
363 if (!next_walk_state) {
364 status = AE_NO_MEMORY;
365 goto cleanup;
366 }
367
368
369
370
371
372
373 this_walk_state->operands[this_walk_state->num_operands] = NULL;
374
375
376
377
378
379
380 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
381 if (!info) {
382 return_ACPI_STATUS(AE_NO_MEMORY);
383 }
384
385 info->parameters = &this_walk_state->operands[0];
386
387 status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
388 obj_desc->method.aml_start,
389 obj_desc->method.aml_length, info,
390 ACPI_IMODE_EXECUTE);
391
392 ACPI_FREE(info);
393 if (ACPI_FAILURE(status)) {
394 goto cleanup;
395 }
396
397
398
399
400
401 for (i = 0; i < obj_desc->method.param_count; i++) {
402 acpi_ut_remove_reference(this_walk_state->operands[i]);
403 this_walk_state->operands[i] = NULL;
404 }
405
406
407
408 this_walk_state->num_operands = 0;
409
410 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
411 "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
412 method_node->name.ascii, next_walk_state));
413
414
415
416 if (obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY) {
417 status = obj_desc->method.implementation(next_walk_state);
418 if (status == AE_OK) {
419 status = AE_CTRL_TERMINATE;
420 }
421 }
422
423 return_ACPI_STATUS(status);
424
425 cleanup:
426
427
428
429 acpi_ds_terminate_control_method(obj_desc, next_walk_state);
430 if (next_walk_state) {
431 acpi_ds_delete_walk_state(next_walk_state);
432 }
433
434 return_ACPI_STATUS(status);
435}
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451acpi_status
452acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
453 union acpi_operand_object *return_desc)
454{
455 acpi_status status;
456 int same_as_implicit_return;
457
458 ACPI_FUNCTION_TRACE_PTR(ds_restart_control_method, walk_state);
459
460 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
461 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
462 acpi_ut_get_node_name(walk_state->method_node),
463 walk_state->method_call_op, return_desc));
464
465 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
466 " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
467 walk_state->return_used,
468 walk_state->results, walk_state));
469
470
471
472 if (return_desc) {
473
474
475
476 same_as_implicit_return =
477 (walk_state->implicit_return_obj == return_desc);
478
479
480
481 if (walk_state->return_used) {
482
483
484
485 status = acpi_ds_result_push(return_desc, walk_state);
486 if (ACPI_FAILURE(status)) {
487 acpi_ut_remove_reference(return_desc);
488 return_ACPI_STATUS(status);
489 }
490
491
492
493
494
495 walk_state->return_desc = return_desc;
496 }
497
498
499
500
501
502
503
504
505
506
507
508
509 else if (!acpi_ds_do_implicit_return
510 (return_desc, walk_state, FALSE)
511 || same_as_implicit_return) {
512
513
514
515
516
517 acpi_ut_remove_reference(return_desc);
518 }
519 }
520
521 return_ACPI_STATUS(AE_OK);
522}
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541void
542acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
543 struct acpi_walk_state *walk_state)
544{
545
546 ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state);
547
548
549
550 if (!method_desc) {
551 return_VOID;
552 }
553
554 if (walk_state) {
555
556
557
558 acpi_ds_method_data_delete_all(walk_state);
559
560
561
562
563
564 if (method_desc->method.mutex) {
565
566
567
568 method_desc->method.mutex->mutex.acquisition_depth--;
569 if (!method_desc->method.mutex->mutex.acquisition_depth) {
570 walk_state->thread->current_sync_level =
571 method_desc->method.mutex->mutex.
572 original_sync_level;
573
574 acpi_os_release_mutex(method_desc->method.
575 mutex->mutex.os_mutex);
576 method_desc->method.mutex->mutex.thread_id = NULL;
577 }
578 }
579
580
581
582
583
584
585
586 if (!(method_desc->method.flags & AOPOBJ_MODULE_LEVEL)) {
587 acpi_ns_delete_namespace_by_owner(method_desc->method.
588 owner_id);
589 }
590 }
591
592
593
594 if (method_desc->method.thread_count) {
595 method_desc->method.thread_count--;
596 } else {
597 ACPI_ERROR((AE_INFO, "Invalid zero thread count in method"));
598 }
599
600
601
602 if (method_desc->method.thread_count) {
603
604
605
606
607 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
608 "*** Completed execution of one thread, %d threads remaining\n",
609 method_desc->method.thread_count));
610 } else {
611
612
613
614
615
616
617
618
619
620
621
622
623 if ((method_desc->method.method_flags & AML_METHOD_SERIALIZED)
624 && (!method_desc->method.mutex)) {
625 (void)acpi_ds_create_method_mutex(method_desc);
626 }
627
628
629
630 if (!(method_desc->method.flags & AOPOBJ_MODULE_LEVEL)) {
631 acpi_ut_release_owner_id(&method_desc->method.owner_id);
632 }
633 }
634
635 return_VOID;
636}
637