1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: dswload - Dispatcher first pass namespace load callbacks
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
18 #ifdef ACPI_ASL_COMPILER
22 #define _COMPONENT ACPI_DISPATCHER
23 ACPI_MODULE_NAME("dswload")
25 /*******************************************************************************
27 * FUNCTION: acpi_ds_init_callbacks
29 * PARAMETERS: walk_state - Current state of the parse tree walk
30 * pass_number - 1, 2, or 3
34 * DESCRIPTION: Init walk state callbacks
36 ******************************************************************************/
38 acpi_ds_init_callbacks(struct acpi_walk_state
*walk_state
, u32 pass_number
)
41 switch (pass_number
) {
44 /* Parse only - caller will setup callbacks */
46 walk_state
->parse_flags
= ACPI_PARSE_LOAD_PASS1
|
47 ACPI_PARSE_DELETE_TREE
| ACPI_PARSE_DISASSEMBLE
;
48 walk_state
->descending_callback
= NULL
;
49 walk_state
->ascending_callback
= NULL
;
56 walk_state
->parse_flags
= ACPI_PARSE_LOAD_PASS1
|
57 ACPI_PARSE_DELETE_TREE
;
58 walk_state
->descending_callback
= acpi_ds_load1_begin_op
;
59 walk_state
->ascending_callback
= acpi_ds_load1_end_op
;
66 walk_state
->parse_flags
= ACPI_PARSE_LOAD_PASS1
|
67 ACPI_PARSE_DELETE_TREE
;
68 walk_state
->descending_callback
= acpi_ds_load2_begin_op
;
69 walk_state
->ascending_callback
= acpi_ds_load2_end_op
;
76 #ifndef ACPI_NO_METHOD_EXECUTION
77 walk_state
->parse_flags
|= ACPI_PARSE_EXECUTE
|
78 ACPI_PARSE_DELETE_TREE
;
79 walk_state
->descending_callback
= acpi_ds_exec_begin_op
;
80 walk_state
->ascending_callback
= acpi_ds_exec_end_op
;
86 return (AE_BAD_PARAMETER
);
92 /*******************************************************************************
94 * FUNCTION: acpi_ds_load1_begin_op
96 * PARAMETERS: walk_state - Current state of the parse tree walk
97 * out_op - Where to return op if a new one is created
101 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
103 ******************************************************************************/
106 acpi_ds_load1_begin_op(struct acpi_walk_state
*walk_state
,
107 union acpi_parse_object
**out_op
)
109 union acpi_parse_object
*op
;
110 struct acpi_namespace_node
*node
;
112 acpi_object_type object_type
;
116 ACPI_FUNCTION_TRACE_PTR(ds_load1_begin_op
, walk_state
->op
);
119 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Op=%p State=%p\n", op
,
122 /* We are only interested in opcodes that have an associated name */
125 if (!(walk_state
->op_info
->flags
& AML_NAMED
)) {
127 return_ACPI_STATUS(AE_OK
);
130 /* Check if this object has already been installed in the namespace */
132 if (op
->common
.node
) {
134 return_ACPI_STATUS(AE_OK
);
138 path
= acpi_ps_get_next_namestring(&walk_state
->parser_state
);
140 /* Map the raw opcode into an internal object type */
142 object_type
= walk_state
->op_info
->object_type
;
144 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
145 "State=%p Op=%p [%s]\n", walk_state
, op
,
146 acpi_ut_get_type_name(object_type
)));
148 switch (walk_state
->opcode
) {
151 * The target name of the Scope() operator must exist at this point so
152 * that we can actually open the scope to enter new names underneath it.
153 * Allow search-to-root for single namesegs.
156 acpi_ns_lookup(walk_state
->scope_info
, path
, object_type
,
157 ACPI_IMODE_EXECUTE
, ACPI_NS_SEARCH_PARENT
,
158 walk_state
, &(node
));
159 #ifdef ACPI_ASL_COMPILER
160 if (status
== AE_NOT_FOUND
) {
163 * Target of Scope() not found. Generate an External for it, and
164 * insert the name into the namespace.
166 acpi_dm_add_op_to_external_list(op
, path
,
167 ACPI_TYPE_DEVICE
, 0, 0);
169 acpi_ns_lookup(walk_state
->scope_info
, path
,
170 object_type
, ACPI_IMODE_LOAD_PASS1
,
171 ACPI_NS_SEARCH_PARENT
, walk_state
,
175 if (ACPI_FAILURE(status
)) {
176 ACPI_ERROR_NAMESPACE(walk_state
->scope_info
, path
,
178 return_ACPI_STATUS(status
);
182 * Check to make sure that the target is
183 * one of the opcodes that actually opens a scope
185 switch (node
->type
) {
187 case ACPI_TYPE_LOCAL_SCOPE
: /* Scope */
188 case ACPI_TYPE_DEVICE
:
189 case ACPI_TYPE_POWER
:
190 case ACPI_TYPE_PROCESSOR
:
191 case ACPI_TYPE_THERMAL
:
193 /* These are acceptable types */
196 case ACPI_TYPE_INTEGER
:
197 case ACPI_TYPE_STRING
:
198 case ACPI_TYPE_BUFFER
:
200 * These types we will allow, but we will change the type.
201 * This enables some existing code of the form:
204 * Scope (DEB) { ... }
206 * Note: silently change the type here. On the second pass,
207 * we will report a warning
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
210 "Type override - [%4.4s] had invalid type (%s) "
211 "for Scope operator, changed to type ANY\n",
212 acpi_ut_get_node_name(node
),
213 acpi_ut_get_type_name(node
->type
)));
215 node
->type
= ACPI_TYPE_ANY
;
216 walk_state
->scope_info
->common
.value
= ACPI_TYPE_ANY
;
219 case ACPI_TYPE_METHOD
:
221 * Allow scope change to root during execution of module-level
222 * code. Root is typed METHOD during this time.
224 if ((node
== acpi_gbl_root_node
) &&
226 parse_flags
& ACPI_PARSE_MODULE_LEVEL
)) {
230 /*lint -fallthrough */
234 /* All other types are an error */
237 "Invalid type (%s) for target of "
238 "Scope operator [%4.4s] (Cannot override)",
239 acpi_ut_get_type_name(node
->type
),
240 acpi_ut_get_node_name(node
)));
242 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
248 * For all other named opcodes, we will enter the name into
251 * Setup the search flags.
252 * Since we are entering a name into the namespace, we do not want to
253 * enable the search-to-root upsearch.
255 * There are only two conditions where it is acceptable that the name
257 * 1) the Scope() operator can reopen a scoping object that was
258 * previously defined (Scope, Method, Device, etc.)
259 * 2) Whenever we are parsing a deferred opcode (op_region, Buffer,
260 * buffer_field, or Package), the name of the object is already
263 if (walk_state
->deferred_node
) {
265 /* This name is already in the namespace, get the node */
267 node
= walk_state
->deferred_node
;
273 * If we are executing a method, do not create any namespace objects
274 * during the load phase, only during execution.
276 if (walk_state
->method_node
) {
282 flags
= ACPI_NS_NO_UPSEARCH
;
283 if ((walk_state
->opcode
!= AML_SCOPE_OP
) &&
284 (!(walk_state
->parse_flags
& ACPI_PARSE_DEFERRED_OP
))) {
285 if (walk_state
->namespace_override
) {
286 flags
|= ACPI_NS_OVERRIDE_IF_FOUND
;
287 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
288 "[%s] Override allowed\n",
289 acpi_ut_get_type_name
292 flags
|= ACPI_NS_ERROR_IF_FOUND
;
293 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
294 "[%s] Cannot already exist\n",
295 acpi_ut_get_type_name
299 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
300 "[%s] Both Find or Create allowed\n",
301 acpi_ut_get_type_name(object_type
)));
305 * Enter the named type into the internal namespace. We enter the name
306 * as we go downward in the parse tree. Any necessary subobjects that
307 * involve arguments to the opcode must be created as we go back up the
311 acpi_ns_lookup(walk_state
->scope_info
, path
, object_type
,
312 ACPI_IMODE_LOAD_PASS1
, flags
, walk_state
,
314 if (ACPI_FAILURE(status
)) {
315 if (status
== AE_ALREADY_EXISTS
) {
317 /* The name already exists in this scope */
319 if (node
->flags
& ANOBJ_IS_EXTERNAL
) {
321 * Allow one create on an object or segment that was
322 * previously declared External
324 node
->flags
&= ~ANOBJ_IS_EXTERNAL
;
325 node
->type
= (u8
) object_type
;
327 /* Just retyped a node, probably will need to open a scope */
329 if (acpi_ns_opens_scope(object_type
)) {
331 acpi_ds_scope_stack_push
334 if (ACPI_FAILURE(status
)) {
344 if (ACPI_FAILURE(status
)) {
345 ACPI_ERROR_NAMESPACE(walk_state
->scope_info
,
347 return_ACPI_STATUS(status
);
357 /* Create a new op */
359 op
= acpi_ps_alloc_op(walk_state
->opcode
, walk_state
->aml
);
361 return_ACPI_STATUS(AE_NO_MEMORY
);
365 /* Initialize the op */
367 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
368 op
->named
.path
= path
;
373 * Put the Node in the "op" object that the parser uses, so we
374 * can get it again quickly when this scope is closed
376 op
->common
.node
= node
;
377 op
->named
.name
= node
->name
.integer
;
380 acpi_ps_append_arg(acpi_ps_get_parent_scope(&walk_state
->parser_state
),
383 return_ACPI_STATUS(status
);
386 /*******************************************************************************
388 * FUNCTION: acpi_ds_load1_end_op
390 * PARAMETERS: walk_state - Current state of the parse tree walk
394 * DESCRIPTION: Ascending callback used during the loading of the namespace,
395 * both control methods and everything else.
397 ******************************************************************************/
399 acpi_status
acpi_ds_load1_end_op(struct acpi_walk_state
*walk_state
)
401 union acpi_parse_object
*op
;
402 acpi_object_type object_type
;
403 acpi_status status
= AE_OK
;
405 #ifdef ACPI_ASL_COMPILER
409 ACPI_FUNCTION_TRACE(ds_load1_end_op
);
412 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Op=%p State=%p\n", op
,
415 /* We are only interested in opcodes that have an associated name */
417 if (!(walk_state
->op_info
->flags
& (AML_NAMED
| AML_FIELD
))) {
418 return_ACPI_STATUS(AE_OK
);
421 /* Get the object type to determine if we should pop the scope */
423 object_type
= walk_state
->op_info
->object_type
;
425 #ifndef ACPI_NO_METHOD_EXECUTION
426 if (walk_state
->op_info
->flags
& AML_FIELD
) {
428 * If we are executing a method, do not create any namespace objects
429 * during the load phase, only during execution.
431 if (!walk_state
->method_node
) {
432 if (walk_state
->opcode
== AML_FIELD_OP
||
433 walk_state
->opcode
== AML_BANK_FIELD_OP
||
434 walk_state
->opcode
== AML_INDEX_FIELD_OP
) {
436 acpi_ds_init_field_objects(op
, walk_state
);
439 return_ACPI_STATUS(status
);
443 * If we are executing a method, do not create any namespace objects
444 * during the load phase, only during execution.
446 if (!walk_state
->method_node
) {
447 if (op
->common
.aml_opcode
== AML_REGION_OP
) {
449 acpi_ex_create_region(op
->named
.data
,
451 (acpi_adr_space_type
)
452 ((op
->common
.value
.arg
)->
453 common
.value
.integer
),
455 if (ACPI_FAILURE(status
)) {
456 return_ACPI_STATUS(status
);
458 } else if (op
->common
.aml_opcode
== AML_DATA_REGION_OP
) {
460 acpi_ex_create_region(op
->named
.data
,
462 ACPI_ADR_SPACE_DATA_TABLE
,
464 if (ACPI_FAILURE(status
)) {
465 return_ACPI_STATUS(status
);
471 if (op
->common
.aml_opcode
== AML_NAME_OP
) {
473 /* For Name opcode, get the object type from the argument */
475 if (op
->common
.value
.arg
) {
476 object_type
= (acpi_ps_get_opcode_info((op
->common
.
482 /* Set node type if we have a namespace node */
484 if (op
->common
.node
) {
485 op
->common
.node
->type
= (u8
) object_type
;
489 #ifdef ACPI_ASL_COMPILER
491 * For external opcode, get the object type from the argument and
492 * get the parameter count from the argument's next.
494 if (acpi_gbl_disasm_flag
&&
495 op
->common
.node
&& op
->common
.aml_opcode
== AML_EXTERNAL_OP
) {
497 * Note, if this external is not a method
498 * Op->Common.Value.Arg->Common.Next->Common.Value.Integer == 0
499 * Therefore, param_count will be 0.
502 (u8
)op
->common
.value
.arg
->common
.next
->common
.value
.integer
;
503 object_type
= (u8
)op
->common
.value
.arg
->common
.value
.integer
;
504 op
->common
.node
->flags
|= ANOBJ_IS_EXTERNAL
;
505 op
->common
.node
->type
= (u8
)object_type
;
507 acpi_dm_create_subobject_for_external((u8
)object_type
,
512 * Add the external to the external list because we may be
513 * emitting code based off of the items within the external list.
515 acpi_dm_add_op_to_external_list(op
, op
->named
.path
,
516 (u8
)object_type
, param_count
,
517 ACPI_EXT_ORIGIN_FROM_OPCODE
|
518 ACPI_EXT_RESOLVED_REFERENCE
);
523 * If we are executing a method, do not create any namespace objects
524 * during the load phase, only during execution.
526 if (!walk_state
->method_node
) {
527 if (op
->common
.aml_opcode
== AML_METHOD_OP
) {
529 * method_op pkg_length name_string method_flags term_list
531 * Note: We must create the method node/object pair as soon as we
532 * see the method declaration. This allows later pass1 parsing
533 * of invocations of the method (need to know the number of
536 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
537 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
538 walk_state
, op
, op
->named
.node
));
540 if (!acpi_ns_get_attached_object(op
->named
.node
)) {
541 walk_state
->operands
[0] =
542 ACPI_CAST_PTR(void, op
->named
.node
);
543 walk_state
->num_operands
= 1;
546 acpi_ds_create_operands(walk_state
,
549 if (ACPI_SUCCESS(status
)) {
551 acpi_ex_create_method(op
->named
.
558 walk_state
->operands
[0] = NULL
;
559 walk_state
->num_operands
= 0;
561 if (ACPI_FAILURE(status
)) {
562 return_ACPI_STATUS(status
);
568 /* Pop the scope stack (only if loading a table) */
570 if (!walk_state
->method_node
&&
571 op
->common
.aml_opcode
!= AML_EXTERNAL_OP
&&
572 acpi_ns_opens_scope(object_type
)) {
573 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
574 "(%s): Popping scope for Op %p\n",
575 acpi_ut_get_type_name(object_type
), op
));
577 status
= acpi_ds_scope_stack_pop(walk_state
);
580 return_ACPI_STATUS(status
);