1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
22 #define _COMPONENT ACPI_DISPATCHER
23 ACPI_MODULE_NAME("dswload2")
25 /*******************************************************************************
27 * FUNCTION: acpi_ds_load2_begin_op
29 * PARAMETERS: walk_state - Current state of the parse tree walk
30 * out_op - Where to return op if a new one is created
34 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
36 ******************************************************************************/
38 acpi_ds_load2_begin_op(struct acpi_walk_state
*walk_state
,
39 union acpi_parse_object
**out_op
)
41 union acpi_parse_object
*op
;
42 struct acpi_namespace_node
*node
;
44 acpi_object_type object_type
;
48 ACPI_FUNCTION_TRACE(ds_load2_begin_op
);
51 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Op=%p State=%p\n", op
,
55 if ((walk_state
->control_state
) &&
56 (walk_state
->control_state
->common
.state
==
57 ACPI_CONTROL_CONDITIONAL_EXECUTING
)) {
59 /* We are executing a while loop outside of a method */
61 status
= acpi_ds_exec_begin_op(walk_state
, out_op
);
62 return_ACPI_STATUS(status
);
65 /* We only care about Namespace opcodes here */
67 if ((!(walk_state
->op_info
->flags
& AML_NSOPCODE
) &&
68 (walk_state
->opcode
!= AML_INT_NAMEPATH_OP
)) ||
69 (!(walk_state
->op_info
->flags
& AML_NAMED
))) {
70 return_ACPI_STATUS(AE_OK
);
73 /* Get the name we are going to enter or lookup in the namespace */
75 if (walk_state
->opcode
== AML_INT_NAMEPATH_OP
) {
77 /* For Namepath op, get the path string */
79 buffer_ptr
= op
->common
.value
.string
;
82 /* No name, just exit */
84 return_ACPI_STATUS(AE_OK
);
87 /* Get name from the op */
89 buffer_ptr
= ACPI_CAST_PTR(char, &op
->named
.name
);
92 /* Get the namestring from the raw AML */
95 acpi_ps_get_next_namestring(&walk_state
->parser_state
);
98 /* Map the opcode into an internal object type */
100 object_type
= walk_state
->op_info
->object_type
;
102 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
103 "State=%p Op=%p Type=%X\n", walk_state
, op
,
106 switch (walk_state
->opcode
) {
108 case AML_BANK_FIELD_OP
:
109 case AML_INDEX_FIELD_OP
:
115 case AML_INT_NAMEPATH_OP
:
117 * The name_path is an object reference to an existing object.
118 * Don't enter the name into the namespace, but look it up
122 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
123 object_type
, ACPI_IMODE_EXECUTE
,
124 ACPI_NS_SEARCH_PARENT
, walk_state
, &(node
));
129 /* Special case for Scope(\) -> refers to the Root node */
131 if (op
&& (op
->named
.node
== acpi_gbl_root_node
)) {
132 node
= op
->named
.node
;
135 acpi_ds_scope_stack_push(node
, object_type
,
137 if (ACPI_FAILURE(status
)) {
138 return_ACPI_STATUS(status
);
142 * The Path is an object reference to an existing object.
143 * Don't enter the name into the namespace, but look it up
147 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
148 object_type
, ACPI_IMODE_EXECUTE
,
149 ACPI_NS_SEARCH_PARENT
, walk_state
,
151 if (ACPI_FAILURE(status
)) {
152 #ifdef ACPI_ASL_COMPILER
153 if (status
== AE_NOT_FOUND
) {
156 ACPI_ERROR_NAMESPACE(walk_state
->
162 ACPI_ERROR_NAMESPACE(walk_state
->scope_info
,
165 return_ACPI_STATUS(status
);
170 * We must check to make sure that the target is
171 * one of the opcodes that actually opens a scope
173 switch (node
->type
) {
175 case ACPI_TYPE_LOCAL_SCOPE
: /* Scope */
176 case ACPI_TYPE_DEVICE
:
177 case ACPI_TYPE_POWER
:
178 case ACPI_TYPE_PROCESSOR
:
179 case ACPI_TYPE_THERMAL
:
181 /* These are acceptable types */
184 case ACPI_TYPE_INTEGER
:
185 case ACPI_TYPE_STRING
:
186 case ACPI_TYPE_BUFFER
:
189 * These types we will allow, but we will change the type.
190 * This enables some existing code of the form:
193 * Scope (DEB) { ... }
195 ACPI_WARNING((AE_INFO
,
196 "Type override - [%4.4s] had invalid type (%s) "
197 "for Scope operator, changed to type ANY",
198 acpi_ut_get_node_name(node
),
199 acpi_ut_get_type_name(node
->type
)));
201 node
->type
= ACPI_TYPE_ANY
;
202 walk_state
->scope_info
->common
.value
= ACPI_TYPE_ANY
;
205 case ACPI_TYPE_METHOD
:
208 * Allow scope change to root during execution of module-level
209 * code. Root is typed METHOD during this time.
211 if ((node
== acpi_gbl_root_node
) &&
213 parse_flags
& ACPI_PARSE_MODULE_LEVEL
)) {
217 /*lint -fallthrough */
221 /* All other types are an error */
224 "Invalid type (%s) for target of "
225 "Scope operator [%4.4s] (Cannot override)",
226 acpi_ut_get_type_name(node
->type
),
227 acpi_ut_get_node_name(node
)));
229 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
235 /* All other opcodes */
237 if (op
&& op
->common
.node
) {
239 /* This op/node was previously entered into the namespace */
241 node
= op
->common
.node
;
243 if (acpi_ns_opens_scope(object_type
)) {
245 acpi_ds_scope_stack_push(node
, object_type
,
247 if (ACPI_FAILURE(status
)) {
248 return_ACPI_STATUS(status
);
252 return_ACPI_STATUS(AE_OK
);
256 * Enter the named type into the internal namespace. We enter the name
257 * as we go downward in the parse tree. Any necessary subobjects that
258 * involve arguments to the opcode must be created as we go back up the
261 * Note: Name may already exist if we are executing a deferred opcode.
263 if (walk_state
->deferred_node
) {
265 /* This name is already in the namespace, get the node */
267 node
= walk_state
->deferred_node
;
272 flags
= ACPI_NS_NO_UPSEARCH
;
273 if (walk_state
->pass_number
== ACPI_IMODE_EXECUTE
) {
275 /* Execution mode, node cannot already exist, node is temporary */
277 flags
|= ACPI_NS_ERROR_IF_FOUND
;
281 parse_flags
& ACPI_PARSE_MODULE_LEVEL
)) {
282 flags
|= ACPI_NS_TEMPORARY
;
285 #ifdef ACPI_ASL_COMPILER
288 * Do not open a scope for AML_EXTERNAL_OP
289 * acpi_ns_lookup can open a new scope based on the object type
290 * of this op. AML_EXTERNAL_OP is a declaration rather than a
291 * definition. In the case that this external is a method object,
292 * acpi_ns_lookup will open a new scope. However, an AML_EXTERNAL_OP
293 * associated with the ACPI_TYPE_METHOD is a declaration, rather than
294 * a definition. Flags is set to avoid opening a scope for any
297 if (walk_state
->opcode
== AML_EXTERNAL_OP
) {
298 flags
|= ACPI_NS_DONT_OPEN_SCOPE
;
303 * For name creation opcodes, the full namepath prefix must
304 * exist, except for the final (new) nameseg.
306 if (walk_state
->op_info
->flags
& AML_NAMED
) {
307 flags
|= ACPI_NS_PREFIX_MUST_EXIST
;
310 /* Add new entry or lookup existing entry */
313 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
314 object_type
, ACPI_IMODE_LOAD_PASS2
, flags
,
317 if (ACPI_SUCCESS(status
) && (flags
& ACPI_NS_TEMPORARY
)) {
318 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
319 "***New Node [%4.4s] %p is temporary\n",
320 acpi_ut_get_node_name(node
), node
));
325 if (ACPI_FAILURE(status
)) {
326 ACPI_ERROR_NAMESPACE(walk_state
->scope_info
,
328 return_ACPI_STATUS(status
);
333 /* Create a new op */
335 op
= acpi_ps_alloc_op(walk_state
->opcode
, walk_state
->aml
);
337 return_ACPI_STATUS(AE_NO_MEMORY
);
340 /* Initialize the new op */
343 op
->named
.name
= node
->name
.integer
;
349 * Put the Node in the "op" object that the parser uses, so we
350 * can get it again quickly when this scope is closed
352 op
->common
.node
= node
;
353 return_ACPI_STATUS(status
);
356 /*******************************************************************************
358 * FUNCTION: acpi_ds_load2_end_op
360 * PARAMETERS: walk_state - Current state of the parse tree walk
364 * DESCRIPTION: Ascending callback used during the loading of the namespace,
365 * both control methods and everything else.
367 ******************************************************************************/
369 acpi_status
acpi_ds_load2_end_op(struct acpi_walk_state
*walk_state
)
371 union acpi_parse_object
*op
;
372 acpi_status status
= AE_OK
;
373 acpi_object_type object_type
;
374 struct acpi_namespace_node
*node
;
375 union acpi_parse_object
*arg
;
376 struct acpi_namespace_node
*new_node
;
380 union acpi_operand_object
*obj_desc
;
384 ACPI_FUNCTION_TRACE(ds_load2_end_op
);
387 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Opcode [%s] Op %p State %p\n",
388 walk_state
->op_info
->name
, op
, walk_state
));
390 /* Check if opcode had an associated namespace object */
392 if (!(walk_state
->op_info
->flags
& AML_NSOBJECT
)) {
393 return_ACPI_STATUS(AE_OK
);
396 if (op
->common
.aml_opcode
== AML_SCOPE_OP
) {
397 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
398 "Ending scope Op=%p State=%p\n", op
,
402 object_type
= walk_state
->op_info
->object_type
;
405 * Get the Node/name from the earlier lookup
406 * (It was saved in the *op structure)
408 node
= op
->common
.node
;
411 * Put the Node on the object stack (Contains the ACPI Name of
414 walk_state
->operands
[0] = (void *)node
;
415 walk_state
->num_operands
= 1;
417 /* Pop the scope stack */
419 if (acpi_ns_opens_scope(object_type
) &&
420 (op
->common
.aml_opcode
!= AML_INT_METHODCALL_OP
)) {
421 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
422 "(%s) Popping scope for Op %p\n",
423 acpi_ut_get_type_name(object_type
), op
));
425 status
= acpi_ds_scope_stack_pop(walk_state
);
426 if (ACPI_FAILURE(status
)) {
432 * Named operations are as follows:
437 * AML_CREATEBYTEFIELD
438 * AML_CREATEDWORDFIELD
440 * AML_CREATEQWORDFIELD
441 * AML_CREATEWORDFIELD
459 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
460 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
461 acpi_ps_get_opcode_name(op
->common
.aml_opcode
),
462 walk_state
, op
, node
));
464 /* Decode the opcode */
466 arg
= op
->common
.value
.arg
;
468 switch (walk_state
->op_info
->type
) {
470 case AML_TYPE_CREATE_FIELD
:
472 * Create the field object, but the field buffer and index must
473 * be evaluated later during the execution phase
475 status
= acpi_ds_create_buffer_field(op
, walk_state
);
476 if (ACPI_FAILURE(status
)) {
477 ACPI_EXCEPTION((AE_INFO
, status
,
478 "CreateBufferField failure"));
483 case AML_TYPE_NAMED_FIELD
:
485 * If we are executing a method, initialize the field
487 if (walk_state
->method_node
) {
488 status
= acpi_ds_init_field_objects(op
, walk_state
);
491 switch (op
->common
.aml_opcode
) {
492 case AML_INDEX_FIELD_OP
:
495 acpi_ds_create_index_field(op
,
496 (acpi_handle
)arg
->common
.
500 case AML_BANK_FIELD_OP
:
503 acpi_ds_create_bank_field(op
, arg
->common
.node
,
510 acpi_ds_create_field(op
, arg
->common
.node
,
516 /* All NAMED_FIELD opcodes must be handled above */
521 case AML_TYPE_NAMED_SIMPLE
:
523 status
= acpi_ds_create_operands(walk_state
, arg
);
524 if (ACPI_FAILURE(status
)) {
528 switch (op
->common
.aml_opcode
) {
529 case AML_PROCESSOR_OP
:
531 status
= acpi_ex_create_processor(walk_state
);
534 case AML_POWER_RESOURCE_OP
:
536 status
= acpi_ex_create_power_resource(walk_state
);
541 status
= acpi_ex_create_mutex(walk_state
);
546 status
= acpi_ex_create_event(walk_state
);
551 status
= acpi_ex_create_alias(walk_state
);
562 /* Delete operands */
564 for (i
= 1; i
< walk_state
->num_operands
; i
++) {
565 acpi_ut_remove_reference(walk_state
->operands
[i
]);
566 walk_state
->operands
[i
] = NULL
;
571 case AML_TYPE_NAMED_COMPLEX
:
573 switch (op
->common
.aml_opcode
) {
575 case AML_DATA_REGION_OP
:
577 if (op
->common
.aml_opcode
== AML_REGION_OP
) {
578 region_space
= (acpi_adr_space_type
)
579 ((op
->common
.value
.arg
)->common
.value
.
582 region_space
= ACPI_ADR_SPACE_DATA_TABLE
;
586 * The op_region is not fully parsed at this time. The only valid
587 * argument is the space_id. (We must save the address of the
588 * AML of the address and length operands)
590 * If we have a valid region, initialize it. The namespace is
591 * unlocked at this point.
593 * Need to unlock interpreter if it is locked (if we are running
594 * a control method), in order to allow _REG methods to be run
595 * during acpi_ev_initialize_region.
597 if (walk_state
->method_node
) {
599 * Executing a method: initialize the region and unlock
602 status
= acpi_ex_create_region(op
->named
.data
,
606 if (ACPI_FAILURE(status
)) {
607 return_ACPI_STATUS(status
);
612 acpi_ev_initialize_region
613 (acpi_ns_get_attached_object(node
));
618 status
= acpi_ds_create_node(walk_state
, node
, op
);
619 if (ACPI_FAILURE(status
)) {
624 * acpi_exec support for namespace initialization file (initialize
625 * Name opcodes in this code.)
627 namepath
= acpi_ns_get_external_pathname(node
);
628 status
= ae_lookup_init_file_entry(namepath
, &obj_desc
);
629 if (ACPI_SUCCESS(status
)) {
631 /* Detach any existing object, attach new object */
634 acpi_ns_detach_object(node
);
636 acpi_ns_attach_object(node
, obj_desc
,
637 obj_desc
->common
.type
);
646 * method_op pkg_length name_string method_flags term_list
648 * Note: We must create the method node/object pair as soon as we
649 * see the method declaration. This allows later pass1 parsing
650 * of invocations of the method (need to know the number of
653 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
654 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
655 walk_state
, op
, op
->named
.node
));
657 if (!acpi_ns_get_attached_object(op
->named
.node
)) {
658 walk_state
->operands
[0] =
659 ACPI_CAST_PTR(void, op
->named
.node
);
660 walk_state
->num_operands
= 1;
663 acpi_ds_create_operands(walk_state
,
666 if (ACPI_SUCCESS(status
)) {
668 acpi_ex_create_method(op
->named
.
675 walk_state
->operands
[0] = NULL
;
676 walk_state
->num_operands
= 0;
678 if (ACPI_FAILURE(status
)) {
679 return_ACPI_STATUS(status
);
686 /* All NAMED_COMPLEX opcodes must be handled above */
691 case AML_CLASS_INTERNAL
:
693 /* case AML_INT_NAMEPATH_OP: */
696 case AML_CLASS_METHOD_CALL
:
698 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
699 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
700 walk_state
, op
, node
));
703 * Lookup the method name and save the Node
706 acpi_ns_lookup(walk_state
->scope_info
,
707 arg
->common
.value
.string
, ACPI_TYPE_ANY
,
708 ACPI_IMODE_LOAD_PASS2
,
709 ACPI_NS_SEARCH_PARENT
|
710 ACPI_NS_DONT_OPEN_SCOPE
, walk_state
,
712 if (ACPI_SUCCESS(status
)) {
714 * Make sure that what we found is indeed a method
715 * We didn't search for a method on purpose, to see if the name
718 if (new_node
->type
!= ACPI_TYPE_METHOD
) {
719 status
= AE_AML_OPERAND_TYPE
;
722 /* We could put the returned object (Node) on the object stack for
723 * later, but for now, we will put it in the "op" object that the
724 * parser uses, so we can get it again at the end of this scope
726 op
->common
.node
= new_node
;
728 ACPI_ERROR_NAMESPACE(walk_state
->scope_info
,
729 arg
->common
.value
.string
, status
);
740 /* Remove the Node pushed at the very beginning */
742 walk_state
->operands
[0] = NULL
;
743 walk_state
->num_operands
= 0;
744 return_ACPI_STATUS(status
);