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 "acparser.h"
47#include "amlcode.h"
48#include "acdispat.h"
49#include "acinterp.h"
50#include "acnamesp.h"
51#include "acevents.h"
52
53#define _COMPONENT ACPI_DISPATCHER
54ACPI_MODULE_NAME("dswload2")
55
56
57
58
59
60
61
62
63
64
65
66
67
68acpi_status
69acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
70 union acpi_parse_object **out_op)
71{
72 union acpi_parse_object *op;
73 struct acpi_namespace_node *node;
74 acpi_status status;
75 acpi_object_type object_type;
76 char *buffer_ptr;
77 u32 flags;
78
79 ACPI_FUNCTION_TRACE(ds_load2_begin_op);
80
81 op = walk_state->op;
82 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
83 walk_state));
84
85 if (op) {
86 if ((walk_state->control_state) &&
87 (walk_state->control_state->common.state ==
88 ACPI_CONTROL_CONDITIONAL_EXECUTING)) {
89
90
91
92 status = acpi_ds_exec_begin_op(walk_state, out_op);
93 return_ACPI_STATUS(status);
94 }
95
96
97
98 if ((!(walk_state->op_info->flags & AML_NSOPCODE) &&
99 (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
100 (!(walk_state->op_info->flags & AML_NAMED))) {
101 return_ACPI_STATUS(AE_OK);
102 }
103
104
105
106 if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
107
108
109
110 buffer_ptr = op->common.value.string;
111 if (!buffer_ptr) {
112
113
114
115 return_ACPI_STATUS(AE_OK);
116 }
117 } else {
118
119
120 buffer_ptr = ACPI_CAST_PTR(char, &op->named.name);
121 }
122 } else {
123
124
125 buffer_ptr =
126 acpi_ps_get_next_namestring(&walk_state->parser_state);
127 }
128
129
130
131 object_type = walk_state->op_info->object_type;
132
133 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
134 "State=%p Op=%p Type=%X\n", walk_state, op,
135 object_type));
136
137 switch (walk_state->opcode) {
138 case AML_FIELD_OP:
139 case AML_BANK_FIELD_OP:
140 case AML_INDEX_FIELD_OP:
141
142 node = NULL;
143 status = AE_OK;
144 break;
145
146 case AML_INT_NAMEPATH_OP:
147
148
149
150
151
152 status =
153 acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
154 object_type, ACPI_IMODE_EXECUTE,
155 ACPI_NS_SEARCH_PARENT, walk_state, &(node));
156 break;
157
158 case AML_SCOPE_OP:
159
160
161
162 if (op && (op->named.node == acpi_gbl_root_node)) {
163 node = op->named.node;
164
165 status =
166 acpi_ds_scope_stack_push(node, object_type,
167 walk_state);
168 if (ACPI_FAILURE(status)) {
169 return_ACPI_STATUS(status);
170 }
171 } else {
172
173
174
175
176
177 status =
178 acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
179 object_type, ACPI_IMODE_EXECUTE,
180 ACPI_NS_SEARCH_PARENT, walk_state,
181 &(node));
182 if (ACPI_FAILURE(status)) {
183#ifdef ACPI_ASL_COMPILER
184 if (status == AE_NOT_FOUND) {
185 status = AE_OK;
186 } else {
187 ACPI_ERROR_NAMESPACE(buffer_ptr,
188 status);
189 }
190#else
191 ACPI_ERROR_NAMESPACE(buffer_ptr, status);
192#endif
193 return_ACPI_STATUS(status);
194 }
195 }
196
197
198
199
200
201 switch (node->type) {
202 case ACPI_TYPE_ANY:
203 case ACPI_TYPE_LOCAL_SCOPE:
204 case ACPI_TYPE_DEVICE:
205 case ACPI_TYPE_POWER:
206 case ACPI_TYPE_PROCESSOR:
207 case ACPI_TYPE_THERMAL:
208
209
210 break;
211
212 case ACPI_TYPE_INTEGER:
213 case ACPI_TYPE_STRING:
214 case ACPI_TYPE_BUFFER:
215
216
217
218
219
220
221
222
223 ACPI_WARNING((AE_INFO,
224 "Type override - [%4.4s] had invalid type (%s) "
225 "for Scope operator, changed to type ANY",
226 acpi_ut_get_node_name(node),
227 acpi_ut_get_type_name(node->type)));
228
229 node->type = ACPI_TYPE_ANY;
230 walk_state->scope_info->common.value = ACPI_TYPE_ANY;
231 break;
232
233 case ACPI_TYPE_METHOD:
234
235
236
237
238
239 if ((node == acpi_gbl_root_node) &&
240 (walk_state->
241 parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
242 break;
243 }
244
245
246
247 default:
248
249
250
251 ACPI_ERROR((AE_INFO,
252 "Invalid type (%s) for target of "
253 "Scope operator [%4.4s] (Cannot override)",
254 acpi_ut_get_type_name(node->type),
255 acpi_ut_get_node_name(node)));
256
257 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
258 }
259 break;
260
261 default:
262
263
264
265 if (op && op->common.node) {
266
267
268
269 node = op->common.node;
270
271 if (acpi_ns_opens_scope(object_type)) {
272 status =
273 acpi_ds_scope_stack_push(node, object_type,
274 walk_state);
275 if (ACPI_FAILURE(status)) {
276 return_ACPI_STATUS(status);
277 }
278 }
279
280 return_ACPI_STATUS(AE_OK);
281 }
282
283
284
285
286
287
288
289
290
291 if (walk_state->deferred_node) {
292
293
294
295 node = walk_state->deferred_node;
296 status = AE_OK;
297 break;
298 }
299
300 flags = ACPI_NS_NO_UPSEARCH;
301 if (walk_state->pass_number == ACPI_IMODE_EXECUTE) {
302
303
304
305 flags |= ACPI_NS_ERROR_IF_FOUND;
306
307 if (!
308 (walk_state->
309 parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
310 flags |= ACPI_NS_TEMPORARY;
311 }
312 }
313
314
315
316 status =
317 acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
318 object_type, ACPI_IMODE_LOAD_PASS2, flags,
319 walk_state, &node);
320
321 if (ACPI_SUCCESS(status) && (flags & ACPI_NS_TEMPORARY)) {
322 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
323 "***New Node [%4.4s] %p is temporary\n",
324 acpi_ut_get_node_name(node), node));
325 }
326 break;
327 }
328
329 if (ACPI_FAILURE(status)) {
330 ACPI_ERROR_NAMESPACE(buffer_ptr, status);
331 return_ACPI_STATUS(status);
332 }
333
334 if (!op) {
335
336
337
338 op = acpi_ps_alloc_op(walk_state->opcode);
339 if (!op) {
340 return_ACPI_STATUS(AE_NO_MEMORY);
341 }
342
343
344
345 if (node) {
346 op->named.name = node->name.integer;
347 }
348 *out_op = op;
349 }
350
351
352
353
354
355 op->common.node = node;
356 return_ACPI_STATUS(status);
357}
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
373{
374 union acpi_parse_object *op;
375 acpi_status status = AE_OK;
376 acpi_object_type object_type;
377 struct acpi_namespace_node *node;
378 union acpi_parse_object *arg;
379 struct acpi_namespace_node *new_node;
380#ifndef ACPI_NO_METHOD_EXECUTION
381 u32 i;
382 u8 region_space;
383#endif
384
385 ACPI_FUNCTION_TRACE(ds_load2_end_op);
386
387 op = walk_state->op;
388 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
389 walk_state->op_info->name, op, walk_state));
390
391
392
393 if (!(walk_state->op_info->flags & AML_NSOBJECT)) {
394 return_ACPI_STATUS(AE_OK);
395 }
396
397 if (op->common.aml_opcode == AML_SCOPE_OP) {
398 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
399 "Ending scope Op=%p State=%p\n", op,
400 walk_state));
401 }
402
403 object_type = walk_state->op_info->object_type;
404
405
406
407
408
409 node = op->common.node;
410
411
412
413
414
415 walk_state->operands[0] = (void *)node;
416 walk_state->num_operands = 1;
417
418
419
420 if (acpi_ns_opens_scope(object_type) &&
421 (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
422 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
423 "(%s) Popping scope for Op %p\n",
424 acpi_ut_get_type_name(object_type), op));
425
426 status = acpi_ds_scope_stack_pop(walk_state);
427 if (ACPI_FAILURE(status)) {
428 goto cleanup;
429 }
430 }
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
461 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
462 acpi_ps_get_opcode_name(op->common.aml_opcode),
463 walk_state, op, node));
464
465
466
467 arg = op->common.value.arg;
468
469 switch (walk_state->op_info->type) {
470#ifndef ACPI_NO_METHOD_EXECUTION
471
472 case AML_TYPE_CREATE_FIELD:
473
474
475
476
477 status = acpi_ds_create_buffer_field(op, walk_state);
478 break;
479
480 case AML_TYPE_NAMED_FIELD:
481
482
483
484 if (walk_state->method_node) {
485 status = acpi_ds_init_field_objects(op, walk_state);
486 }
487
488 switch (op->common.aml_opcode) {
489 case AML_INDEX_FIELD_OP:
490
491 status =
492 acpi_ds_create_index_field(op,
493 (acpi_handle) arg->
494 common.node, walk_state);
495 break;
496
497 case AML_BANK_FIELD_OP:
498
499 status =
500 acpi_ds_create_bank_field(op, arg->common.node,
501 walk_state);
502 break;
503
504 case AML_FIELD_OP:
505
506 status =
507 acpi_ds_create_field(op, arg->common.node,
508 walk_state);
509 break;
510
511 default:
512
513 break;
514 }
515 break;
516
517 case AML_TYPE_NAMED_SIMPLE:
518
519 status = acpi_ds_create_operands(walk_state, arg);
520 if (ACPI_FAILURE(status)) {
521 goto cleanup;
522 }
523
524 switch (op->common.aml_opcode) {
525 case AML_PROCESSOR_OP:
526
527 status = acpi_ex_create_processor(walk_state);
528 break;
529
530 case AML_POWER_RES_OP:
531
532 status = acpi_ex_create_power_resource(walk_state);
533 break;
534
535 case AML_MUTEX_OP:
536
537 status = acpi_ex_create_mutex(walk_state);
538 break;
539
540 case AML_EVENT_OP:
541
542 status = acpi_ex_create_event(walk_state);
543 break;
544
545 case AML_ALIAS_OP:
546
547 status = acpi_ex_create_alias(walk_state);
548 break;
549
550 default:
551
552
553 status = AE_OK;
554 goto cleanup;
555 }
556
557
558
559 for (i = 1; i < walk_state->num_operands; i++) {
560 acpi_ut_remove_reference(walk_state->operands[i]);
561 walk_state->operands[i] = NULL;
562 }
563
564 break;
565#endif
566
567 case AML_TYPE_NAMED_COMPLEX:
568
569 switch (op->common.aml_opcode) {
570#ifndef ACPI_NO_METHOD_EXECUTION
571 case AML_REGION_OP:
572 case AML_DATA_REGION_OP:
573
574 if (op->common.aml_opcode == AML_REGION_OP) {
575 region_space = (acpi_adr_space_type)
576 ((op->common.value.arg)->common.value.
577 integer);
578 } else {
579 region_space = ACPI_ADR_SPACE_DATA_TABLE;
580 }
581
582
583
584
585
586
587
588
589
590
591
592
593
594 if (walk_state->method_node) {
595
596
597
598
599 status =
600 acpi_ex_create_region(op->named.data,
601 op->named.length,
602 region_space,
603 walk_state);
604 if (ACPI_FAILURE(status)) {
605 return_ACPI_STATUS(status);
606 }
607
608 acpi_ex_exit_interpreter();
609 }
610
611 status =
612 acpi_ev_initialize_region
613 (acpi_ns_get_attached_object(node), FALSE);
614 if (walk_state->method_node) {
615 acpi_ex_enter_interpreter();
616 }
617
618 if (ACPI_FAILURE(status)) {
619
620
621
622
623
624 if (AE_NOT_EXIST == status) {
625 status = AE_OK;
626 }
627 }
628 break;
629
630 case AML_NAME_OP:
631
632 status = acpi_ds_create_node(walk_state, node, op);
633 break;
634
635 case AML_METHOD_OP:
636
637
638
639
640
641
642
643
644 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
645 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
646 walk_state, op, op->named.node));
647
648 if (!acpi_ns_get_attached_object(op->named.node)) {
649 walk_state->operands[0] =
650 ACPI_CAST_PTR(void, op->named.node);
651 walk_state->num_operands = 1;
652
653 status =
654 acpi_ds_create_operands(walk_state,
655 op->common.value.
656 arg);
657 if (ACPI_SUCCESS(status)) {
658 status =
659 acpi_ex_create_method(op->named.
660 data,
661 op->named.
662 length,
663 walk_state);
664 }
665 walk_state->operands[0] = NULL;
666 walk_state->num_operands = 0;
667
668 if (ACPI_FAILURE(status)) {
669 return_ACPI_STATUS(status);
670 }
671 }
672 break;
673
674#endif
675
676 default:
677
678 break;
679 }
680 break;
681
682 case AML_CLASS_INTERNAL:
683
684
685 break;
686
687 case AML_CLASS_METHOD_CALL:
688
689 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
690 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
691 walk_state, op, node));
692
693
694
695
696 status =
697 acpi_ns_lookup(walk_state->scope_info,
698 arg->common.value.string, ACPI_TYPE_ANY,
699 ACPI_IMODE_LOAD_PASS2,
700 ACPI_NS_SEARCH_PARENT |
701 ACPI_NS_DONT_OPEN_SCOPE, walk_state,
702 &(new_node));
703 if (ACPI_SUCCESS(status)) {
704
705
706
707
708
709 if (new_node->type != ACPI_TYPE_METHOD) {
710 status = AE_AML_OPERAND_TYPE;
711 }
712
713
714
715
716
717 op->common.node = new_node;
718 } else {
719 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
720 }
721 break;
722
723 default:
724 break;
725 }
726
727 cleanup:
728
729
730
731 walk_state->operands[0] = NULL;
732 walk_state->num_operands = 0;
733 return_ACPI_STATUS(status);
734}
735