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