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 "acdispat.h"
47#include "acinterp.h"
48#include "acnamesp.h"
49#ifdef ACPI_DISASSEMBLER
50#include "acdisasm.h"
51#endif
52
53#define _COMPONENT ACPI_DISPATCHER
54ACPI_MODULE_NAME("dsmethod")
55
56
57static acpi_status
58acpi_ds_create_method_mutex(union acpi_operand_object *method_desc);
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76acpi_status
77acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
78{
79 ACPI_FUNCTION_ENTRY();
80
81
82
83 if (ACPI_SUCCESS(status) || (status & AE_CODE_CONTROL)) {
84 return (status);
85 }
86
87
88
89 if (acpi_gbl_exception_handler) {
90
91
92
93 acpi_ex_exit_interpreter();
94
95
96
97
98
99 status = acpi_gbl_exception_handler(status,
100 walk_state->method_node ?
101 walk_state->method_node->
102 name.integer : 0,
103 walk_state->opcode,
104 walk_state->aml_offset,
105 NULL);
106 acpi_ex_enter_interpreter();
107 }
108
109 acpi_ds_clear_implicit_return(walk_state);
110
111#ifdef ACPI_DISASSEMBLER
112 if (ACPI_FAILURE(status)) {
113
114
115
116 acpi_dm_dump_method_info(status, walk_state, walk_state->op);
117 }
118#endif
119
120 return (status);
121}
122
123
124
125
126
127
128
129
130
131
132
133
134
135static acpi_status
136acpi_ds_create_method_mutex(union acpi_operand_object *method_desc)
137{
138 union acpi_operand_object *mutex_desc;
139 acpi_status status;
140
141 ACPI_FUNCTION_TRACE(ds_create_method_mutex);
142
143
144
145 mutex_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
146 if (!mutex_desc) {
147 return_ACPI_STATUS(AE_NO_MEMORY);
148 }
149
150
151
152 status = acpi_os_create_mutex(&mutex_desc->mutex.os_mutex);
153 if (ACPI_FAILURE(status)) {
154 acpi_ut_delete_object_desc(mutex_desc);
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.info_flags & ACPI_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 (%u)",
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 status = AE_NO_MEMORY;
383 goto cleanup;
384 }
385
386 info->parameters = &this_walk_state->operands[0];
387
388 status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
389 obj_desc->method.aml_start,
390 obj_desc->method.aml_length, info,
391 ACPI_IMODE_EXECUTE);
392
393 ACPI_FREE(info);
394 if (ACPI_FAILURE(status)) {
395 goto cleanup;
396 }
397
398
399
400
401
402 for (i = 0; i < obj_desc->method.param_count; i++) {
403 acpi_ut_remove_reference(this_walk_state->operands[i]);
404 this_walk_state->operands[i] = NULL;
405 }
406
407
408
409 this_walk_state->num_operands = 0;
410
411 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
412 "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
413 method_node->name.ascii, next_walk_state));
414
415
416
417 if (obj_desc->method.info_flags & ACPI_METHOD_INTERNAL_ONLY) {
418 status =
419 obj_desc->method.dispatch.implementation(next_walk_state);
420 if (status == AE_OK) {
421 status = AE_CTRL_TERMINATE;
422 }
423 }
424
425 return_ACPI_STATUS(status);
426
427 cleanup:
428
429
430
431 acpi_ds_terminate_control_method(obj_desc, next_walk_state);
432 if (next_walk_state) {
433 acpi_ds_delete_walk_state(next_walk_state);
434 }
435
436 return_ACPI_STATUS(status);
437}
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453acpi_status
454acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
455 union acpi_operand_object *return_desc)
456{
457 acpi_status status;
458 int same_as_implicit_return;
459
460 ACPI_FUNCTION_TRACE_PTR(ds_restart_control_method, walk_state);
461
462 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
463 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
464 acpi_ut_get_node_name(walk_state->method_node),
465 walk_state->method_call_op, return_desc));
466
467 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
468 " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
469 walk_state->return_used,
470 walk_state->results, walk_state));
471
472
473
474 if (return_desc) {
475
476
477
478 same_as_implicit_return =
479 (walk_state->implicit_return_obj == return_desc);
480
481
482
483 if (walk_state->return_used) {
484
485
486
487 status = acpi_ds_result_push(return_desc, walk_state);
488 if (ACPI_FAILURE(status)) {
489 acpi_ut_remove_reference(return_desc);
490 return_ACPI_STATUS(status);
491 }
492
493
494
495
496
497 walk_state->return_desc = return_desc;
498 }
499
500
501
502
503
504
505
506
507
508
509
510
511 else if (!acpi_ds_do_implicit_return
512 (return_desc, walk_state, FALSE)
513 || same_as_implicit_return) {
514
515
516
517
518
519 acpi_ut_remove_reference(return_desc);
520 }
521 }
522
523 return_ACPI_STATUS(AE_OK);
524}
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543void
544acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
545 struct acpi_walk_state *walk_state)
546{
547
548 ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state);
549
550
551
552 if (!method_desc) {
553 return_VOID;
554 }
555
556 if (walk_state) {
557
558
559
560 acpi_ds_method_data_delete_all(walk_state);
561
562
563
564
565
566 if (method_desc->method.mutex) {
567
568
569
570 method_desc->method.mutex->mutex.acquisition_depth--;
571 if (!method_desc->method.mutex->mutex.acquisition_depth) {
572 walk_state->thread->current_sync_level =
573 method_desc->method.mutex->mutex.
574 original_sync_level;
575
576 acpi_os_release_mutex(method_desc->method.
577 mutex->mutex.os_mutex);
578 method_desc->method.mutex->mutex.thread_id = 0;
579 }
580 }
581
582
583
584
585
586
587
588
589
590 if (!(method_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL)
591 && (method_desc->method.thread_count == 1)) {
592
593
594
595 acpi_ns_delete_namespace_subtree(walk_state->
596 method_node);
597
598
599
600
601
602
603
604
605 if (method_desc->method.
606 info_flags & ACPI_METHOD_MODIFIED_NAMESPACE) {
607 acpi_ns_delete_namespace_by_owner(method_desc->
608 method.
609 owner_id);
610 method_desc->method.info_flags &=
611 ~ACPI_METHOD_MODIFIED_NAMESPACE;
612 }
613 }
614 }
615
616
617
618 if (method_desc->method.thread_count) {
619 method_desc->method.thread_count--;
620 } else {
621 ACPI_ERROR((AE_INFO, "Invalid zero thread count in method"));
622 }
623
624
625
626 if (method_desc->method.thread_count) {
627
628
629
630
631 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
632 "*** Completed execution of one thread, %u threads remaining\n",
633 method_desc->method.thread_count));
634 } else {
635
636
637
638
639
640
641
642
643
644
645
646
647 if (method_desc->method.
648 info_flags & ACPI_METHOD_SERIALIZED_PENDING) {
649 if (walk_state) {
650 ACPI_INFO((AE_INFO,
651 "Marking method %4.4s as Serialized because of AE_ALREADY_EXISTS error",
652 walk_state->method_node->name.
653 ascii));
654 }
655
656
657
658
659
660
661
662
663
664
665
666
667 method_desc->method.info_flags &=
668 ~ACPI_METHOD_SERIALIZED_PENDING;
669 method_desc->method.info_flags |=
670 ACPI_METHOD_SERIALIZED;
671 method_desc->method.sync_level = 0;
672 }
673
674
675
676 if (!
677 (method_desc->method.
678 info_flags & ACPI_METHOD_MODULE_LEVEL)) {
679 acpi_ut_release_owner_id(&method_desc->method.owner_id);
680 }
681 }
682
683 return_VOID;
684}
685