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 - 2019, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
19 #define _COMPONENT ACPI_DISPATCHER
20 ACPI_MODULE_NAME("dswload2")
22 /*******************************************************************************
24 * FUNCTION: acpi_ds_load2_begin_op
26 * PARAMETERS: walk_state - Current state of the parse tree walk
27 * out_op - Where to return op if a new one is created
31 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
33 ******************************************************************************/
35 acpi_ds_load2_begin_op(struct acpi_walk_state
*walk_state
,
36 union acpi_parse_object
**out_op
)
38 union acpi_parse_object
*op
;
39 struct acpi_namespace_node
*node
;
41 acpi_object_type object_type
;
45 ACPI_FUNCTION_TRACE(ds_load2_begin_op
);
48 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Op=%p State=%p\n", op
,
52 if ((walk_state
->control_state
) &&
53 (walk_state
->control_state
->common
.state
==
54 ACPI_CONTROL_CONDITIONAL_EXECUTING
)) {
56 /* We are executing a while loop outside of a method */
58 status
= acpi_ds_exec_begin_op(walk_state
, out_op
);
59 return_ACPI_STATUS(status
);
62 /* We only care about Namespace opcodes here */
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
);
70 /* Get the name we are going to enter or lookup in the namespace */
72 if (walk_state
->opcode
== AML_INT_NAMEPATH_OP
) {
74 /* For Namepath op, get the path string */
76 buffer_ptr
= op
->common
.value
.string
;
79 /* No name, just exit */
81 return_ACPI_STATUS(AE_OK
);
84 /* Get name from the op */
86 buffer_ptr
= ACPI_CAST_PTR(char, &op
->named
.name
);
89 /* Get the namestring from the raw AML */
92 acpi_ps_get_next_namestring(&walk_state
->parser_state
);
95 /* Map the opcode into an internal object type */
97 object_type
= walk_state
->op_info
->object_type
;
99 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
100 "State=%p Op=%p Type=%X\n", walk_state
, op
,
103 switch (walk_state
->opcode
) {
105 case AML_BANK_FIELD_OP
:
106 case AML_INDEX_FIELD_OP
:
112 case AML_INT_NAMEPATH_OP
:
114 * The name_path is an object reference to an existing object.
115 * Don't enter the name into the namespace, but look it up
119 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
120 object_type
, ACPI_IMODE_EXECUTE
,
121 ACPI_NS_SEARCH_PARENT
, walk_state
, &(node
));
126 /* Special case for Scope(\) -> refers to the Root node */
128 if (op
&& (op
->named
.node
== acpi_gbl_root_node
)) {
129 node
= op
->named
.node
;
132 acpi_ds_scope_stack_push(node
, object_type
,
134 if (ACPI_FAILURE(status
)) {
135 return_ACPI_STATUS(status
);
139 * The Path is an object reference to an existing object.
140 * Don't enter the name into the namespace, but look it up
144 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
145 object_type
, ACPI_IMODE_EXECUTE
,
146 ACPI_NS_SEARCH_PARENT
, walk_state
,
148 if (ACPI_FAILURE(status
)) {
149 #ifdef ACPI_ASL_COMPILER
150 if (status
== AE_NOT_FOUND
) {
153 ACPI_ERROR_NAMESPACE(walk_state
->
159 ACPI_ERROR_NAMESPACE(walk_state
->scope_info
,
162 return_ACPI_STATUS(status
);
167 * We must check to make sure that the target is
168 * one of the opcodes that actually opens a scope
170 switch (node
->type
) {
172 case ACPI_TYPE_LOCAL_SCOPE
: /* Scope */
173 case ACPI_TYPE_DEVICE
:
174 case ACPI_TYPE_POWER
:
175 case ACPI_TYPE_PROCESSOR
:
176 case ACPI_TYPE_THERMAL
:
178 /* These are acceptable types */
181 case ACPI_TYPE_INTEGER
:
182 case ACPI_TYPE_STRING
:
183 case ACPI_TYPE_BUFFER
:
186 * These types we will allow, but we will change the type.
187 * This enables some existing code of the form:
190 * Scope (DEB) { ... }
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
)));
198 node
->type
= ACPI_TYPE_ANY
;
199 walk_state
->scope_info
->common
.value
= ACPI_TYPE_ANY
;
202 case ACPI_TYPE_METHOD
:
205 * Allow scope change to root during execution of module-level
206 * code. Root is typed METHOD during this time.
208 if ((node
== acpi_gbl_root_node
) &&
210 parse_flags
& ACPI_PARSE_MODULE_LEVEL
)) {
214 /*lint -fallthrough */
218 /* All other types are an error */
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
)));
226 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
232 /* All other opcodes */
234 if (op
&& op
->common
.node
) {
236 /* This op/node was previously entered into the namespace */
238 node
= op
->common
.node
;
240 if (acpi_ns_opens_scope(object_type
)) {
242 acpi_ds_scope_stack_push(node
, object_type
,
244 if (ACPI_FAILURE(status
)) {
245 return_ACPI_STATUS(status
);
249 return_ACPI_STATUS(AE_OK
);
253 * Enter the named type into the internal namespace. We enter the name
254 * as we go downward in the parse tree. Any necessary subobjects that
255 * involve arguments to the opcode must be created as we go back up the
258 * Note: Name may already exist if we are executing a deferred opcode.
260 if (walk_state
->deferred_node
) {
262 /* This name is already in the namespace, get the node */
264 node
= walk_state
->deferred_node
;
269 flags
= ACPI_NS_NO_UPSEARCH
;
270 if (walk_state
->pass_number
== ACPI_IMODE_EXECUTE
) {
272 /* Execution mode, node cannot already exist, node is temporary */
274 flags
|= ACPI_NS_ERROR_IF_FOUND
;
278 parse_flags
& ACPI_PARSE_MODULE_LEVEL
)) {
279 flags
|= ACPI_NS_TEMPORARY
;
282 #ifdef ACPI_ASL_COMPILER
285 * Do not open a scope for AML_EXTERNAL_OP
286 * acpi_ns_lookup can open a new scope based on the object type
287 * of this op. AML_EXTERNAL_OP is a declaration rather than a
288 * definition. In the case that this external is a method object,
289 * acpi_ns_lookup will open a new scope. However, an AML_EXTERNAL_OP
290 * associated with the ACPI_TYPE_METHOD is a declaration, rather than
291 * a definition. Flags is set to avoid opening a scope for any
294 if (walk_state
->opcode
== AML_EXTERNAL_OP
) {
295 flags
|= ACPI_NS_DONT_OPEN_SCOPE
;
300 * For name creation opcodes, the full namepath prefix must
301 * exist, except for the final (new) nameseg.
303 if (walk_state
->op_info
->flags
& AML_NAMED
) {
304 flags
|= ACPI_NS_PREFIX_MUST_EXIST
;
307 /* Add new entry or lookup existing entry */
310 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
311 object_type
, ACPI_IMODE_LOAD_PASS2
, flags
,
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
));
322 if (ACPI_FAILURE(status
)) {
323 ACPI_ERROR_NAMESPACE(walk_state
->scope_info
,
325 return_ACPI_STATUS(status
);
330 /* Create a new op */
332 op
= acpi_ps_alloc_op(walk_state
->opcode
, walk_state
->aml
);
334 return_ACPI_STATUS(AE_NO_MEMORY
);
337 /* Initialize the new op */
340 op
->named
.name
= node
->name
.integer
;
346 * Put the Node in the "op" object that the parser uses, so we
347 * can get it again quickly when this scope is closed
349 op
->common
.node
= node
;
350 return_ACPI_STATUS(status
);
353 /*******************************************************************************
355 * FUNCTION: acpi_ds_load2_end_op
357 * PARAMETERS: walk_state - Current state of the parse tree walk
361 * DESCRIPTION: Ascending callback used during the loading of the namespace,
362 * both control methods and everything else.
364 ******************************************************************************/
366 acpi_status
acpi_ds_load2_end_op(struct acpi_walk_state
*walk_state
)
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
;
377 ACPI_FUNCTION_TRACE(ds_load2_end_op
);
380 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Opcode [%s] Op %p State %p\n",
381 walk_state
->op_info
->name
, op
, walk_state
));
383 /* Check if opcode had an associated namespace object */
385 if (!(walk_state
->op_info
->flags
& AML_NSOBJECT
)) {
386 return_ACPI_STATUS(AE_OK
);
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
,
395 object_type
= walk_state
->op_info
->object_type
;
398 * Get the Node/name from the earlier lookup
399 * (It was saved in the *op structure)
401 node
= op
->common
.node
;
404 * Put the Node on the object stack (Contains the ACPI Name of
407 walk_state
->operands
[0] = (void *)node
;
408 walk_state
->num_operands
= 1;
410 /* Pop the scope stack */
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
));
418 status
= acpi_ds_scope_stack_pop(walk_state
);
419 if (ACPI_FAILURE(status
)) {
425 * Named operations are as follows:
430 * AML_CREATEBYTEFIELD
431 * AML_CREATEDWORDFIELD
433 * AML_CREATEQWORDFIELD
434 * AML_CREATEWORDFIELD
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
));
457 /* Decode the opcode */
459 arg
= op
->common
.value
.arg
;
461 switch (walk_state
->op_info
->type
) {
463 case AML_TYPE_CREATE_FIELD
:
465 * Create the field object, but the field buffer and index must
466 * be evaluated later during the execution phase
468 status
= acpi_ds_create_buffer_field(op
, walk_state
);
471 case AML_TYPE_NAMED_FIELD
:
473 * If we are executing a method, initialize the field
475 if (walk_state
->method_node
) {
476 status
= acpi_ds_init_field_objects(op
, walk_state
);
479 switch (op
->common
.aml_opcode
) {
480 case AML_INDEX_FIELD_OP
:
483 acpi_ds_create_index_field(op
,
484 (acpi_handle
)arg
->common
.
488 case AML_BANK_FIELD_OP
:
491 acpi_ds_create_bank_field(op
, arg
->common
.node
,
498 acpi_ds_create_field(op
, arg
->common
.node
,
504 /* All NAMED_FIELD opcodes must be handled above */
509 case AML_TYPE_NAMED_SIMPLE
:
511 status
= acpi_ds_create_operands(walk_state
, arg
);
512 if (ACPI_FAILURE(status
)) {
516 switch (op
->common
.aml_opcode
) {
517 case AML_PROCESSOR_OP
:
519 status
= acpi_ex_create_processor(walk_state
);
522 case AML_POWER_RESOURCE_OP
:
524 status
= acpi_ex_create_power_resource(walk_state
);
529 status
= acpi_ex_create_mutex(walk_state
);
534 status
= acpi_ex_create_event(walk_state
);
539 status
= acpi_ex_create_alias(walk_state
);
550 /* Delete operands */
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
;
559 case AML_TYPE_NAMED_COMPLEX
:
561 switch (op
->common
.aml_opcode
) {
563 case AML_DATA_REGION_OP
:
565 if (op
->common
.aml_opcode
== AML_REGION_OP
) {
566 region_space
= (acpi_adr_space_type
)
567 ((op
->common
.value
.arg
)->common
.value
.
570 region_space
= ACPI_ADR_SPACE_DATA_TABLE
;
574 * The op_region is not fully parsed at this time. The only valid
575 * argument is the space_id. (We must save the address of the
576 * AML of the address and length operands)
578 * If we have a valid region, initialize it. The namespace is
579 * unlocked at this point.
581 * Need to unlock interpreter if it is locked (if we are running
582 * a control method), in order to allow _REG methods to be run
583 * during acpi_ev_initialize_region.
585 if (walk_state
->method_node
) {
587 * Executing a method: initialize the region and unlock
590 status
= acpi_ex_create_region(op
->named
.data
,
594 if (ACPI_FAILURE(status
)) {
595 return_ACPI_STATUS(status
);
600 acpi_ev_initialize_region
601 (acpi_ns_get_attached_object(node
));
606 status
= acpi_ds_create_node(walk_state
, node
, op
);
611 * method_op pkg_length name_string method_flags term_list
613 * Note: We must create the method node/object pair as soon as we
614 * see the method declaration. This allows later pass1 parsing
615 * of invocations of the method (need to know the number of
618 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
619 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
620 walk_state
, op
, op
->named
.node
));
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;
628 acpi_ds_create_operands(walk_state
,
631 if (ACPI_SUCCESS(status
)) {
633 acpi_ex_create_method(op
->named
.
640 walk_state
->operands
[0] = NULL
;
641 walk_state
->num_operands
= 0;
643 if (ACPI_FAILURE(status
)) {
644 return_ACPI_STATUS(status
);
651 /* All NAMED_COMPLEX opcodes must be handled above */
656 case AML_CLASS_INTERNAL
:
658 /* case AML_INT_NAMEPATH_OP: */
661 case AML_CLASS_METHOD_CALL
:
663 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
664 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
665 walk_state
, op
, node
));
668 * Lookup the method name and save the Node
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
,
677 if (ACPI_SUCCESS(status
)) {
679 * Make sure that what we found is indeed a method
680 * We didn't search for a method on purpose, to see if the name
683 if (new_node
->type
!= ACPI_TYPE_METHOD
) {
684 status
= AE_AML_OPERAND_TYPE
;
687 /* We could put the returned object (Node) on the object stack for
688 * later, but for now, we will put it in the "op" object that the
689 * parser uses, so we can get it again at the end of this scope
691 op
->common
.node
= new_node
;
693 ACPI_ERROR_NAMESPACE(walk_state
->scope_info
,
694 arg
->common
.value
.string
, status
);
705 /* Remove the Node pushed at the very beginning */
707 walk_state
->operands
[0] = NULL
;
708 walk_state
->num_operands
= 0;
709 return_ACPI_STATUS(status
);