1 /******************************************************************************
3 * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
53 #define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME("dswload2")
56 /*******************************************************************************
58 * FUNCTION: acpi_ds_load2_begin_op
60 * PARAMETERS: walk_state - Current state of the parse tree walk
61 * out_op - Wher to return op if a new one is created
65 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
67 ******************************************************************************/
69 acpi_ds_load2_begin_op(struct acpi_walk_state
*walk_state
,
70 union acpi_parse_object
**out_op
)
72 union acpi_parse_object
*op
;
73 struct acpi_namespace_node
*node
;
75 acpi_object_type object_type
;
79 ACPI_FUNCTION_TRACE(ds_load2_begin_op
);
82 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Op=%p State=%p\n", op
,
86 if ((walk_state
->control_state
) &&
87 (walk_state
->control_state
->common
.state
==
88 ACPI_CONTROL_CONDITIONAL_EXECUTING
)) {
90 /* We are executing a while loop outside of a method */
92 status
= acpi_ds_exec_begin_op(walk_state
, out_op
);
93 return_ACPI_STATUS(status
);
96 /* We only care about Namespace opcodes here */
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
);
104 /* Get the name we are going to enter or lookup in the namespace */
106 if (walk_state
->opcode
== AML_INT_NAMEPATH_OP
) {
108 /* For Namepath op, get the path string */
110 buffer_ptr
= op
->common
.value
.string
;
113 /* No name, just exit */
115 return_ACPI_STATUS(AE_OK
);
118 /* Get name from the op */
120 buffer_ptr
= ACPI_CAST_PTR(char, &op
->named
.name
);
123 /* Get the namestring from the raw AML */
126 acpi_ps_get_next_namestring(&walk_state
->parser_state
);
129 /* Map the opcode into an internal object type */
131 object_type
= walk_state
->op_info
->object_type
;
133 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
134 "State=%p Op=%p Type=%X\n", walk_state
, op
,
137 switch (walk_state
->opcode
) {
139 case AML_BANK_FIELD_OP
:
140 case AML_INDEX_FIELD_OP
:
146 case AML_INT_NAMEPATH_OP
:
148 * The name_path is an object reference to an existing object.
149 * Don't enter the name into the namespace, but look it up
153 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
154 object_type
, ACPI_IMODE_EXECUTE
,
155 ACPI_NS_SEARCH_PARENT
, walk_state
, &(node
));
160 /* Special case for Scope(\) -> refers to the Root node */
162 if (op
&& (op
->named
.node
== acpi_gbl_root_node
)) {
163 node
= op
->named
.node
;
166 acpi_ds_scope_stack_push(node
, object_type
,
168 if (ACPI_FAILURE(status
)) {
169 return_ACPI_STATUS(status
);
173 * The Path is an object reference to an existing object.
174 * Don't enter the name into the namespace, but look it up
178 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
179 object_type
, ACPI_IMODE_EXECUTE
,
180 ACPI_NS_SEARCH_PARENT
, walk_state
,
182 if (ACPI_FAILURE(status
)) {
183 #ifdef ACPI_ASL_COMPILER
184 if (status
== AE_NOT_FOUND
) {
187 ACPI_ERROR_NAMESPACE(buffer_ptr
,
191 ACPI_ERROR_NAMESPACE(buffer_ptr
, status
);
193 return_ACPI_STATUS(status
);
198 * We must check to make sure that the target is
199 * one of the opcodes that actually opens a scope
201 switch (node
->type
) {
203 case ACPI_TYPE_LOCAL_SCOPE
: /* Scope */
204 case ACPI_TYPE_DEVICE
:
205 case ACPI_TYPE_POWER
:
206 case ACPI_TYPE_PROCESSOR
:
207 case ACPI_TYPE_THERMAL
:
209 /* These are acceptable types */
212 case ACPI_TYPE_INTEGER
:
213 case ACPI_TYPE_STRING
:
214 case ACPI_TYPE_BUFFER
:
217 * These types we will allow, but we will change the type.
218 * This enables some existing code of the form:
221 * Scope (DEB) { ... }
223 ACPI_WARNING((AE_INFO
,
224 "Type override - [%4.4s] had invalid type (%s) "
225 "for Scope operator, changed to type ANY\n",
226 acpi_ut_get_node_name(node
),
227 acpi_ut_get_type_name(node
->type
)));
229 node
->type
= ACPI_TYPE_ANY
;
230 walk_state
->scope_info
->common
.value
= ACPI_TYPE_ANY
;
235 /* All other types are an error */
238 "Invalid type (%s) for target of "
239 "Scope operator [%4.4s] (Cannot override)",
240 acpi_ut_get_type_name(node
->type
),
241 acpi_ut_get_node_name(node
)));
243 return (AE_AML_OPERAND_TYPE
);
249 /* All other opcodes */
251 if (op
&& op
->common
.node
) {
253 /* This op/node was previously entered into the namespace */
255 node
= op
->common
.node
;
257 if (acpi_ns_opens_scope(object_type
)) {
259 acpi_ds_scope_stack_push(node
, object_type
,
261 if (ACPI_FAILURE(status
)) {
262 return_ACPI_STATUS(status
);
266 return_ACPI_STATUS(AE_OK
);
270 * Enter the named type into the internal namespace. We enter the name
271 * as we go downward in the parse tree. Any necessary subobjects that
272 * involve arguments to the opcode must be created as we go back up the
275 * Note: Name may already exist if we are executing a deferred opcode.
277 if (walk_state
->deferred_node
) {
279 /* This name is already in the namespace, get the node */
281 node
= walk_state
->deferred_node
;
286 flags
= ACPI_NS_NO_UPSEARCH
;
287 if (walk_state
->pass_number
== ACPI_IMODE_EXECUTE
) {
289 /* Execution mode, node cannot already exist, node is temporary */
291 flags
|= ACPI_NS_ERROR_IF_FOUND
;
295 parse_flags
& ACPI_PARSE_MODULE_LEVEL
)) {
296 flags
|= ACPI_NS_TEMPORARY
;
300 /* Add new entry or lookup existing entry */
303 acpi_ns_lookup(walk_state
->scope_info
, buffer_ptr
,
304 object_type
, ACPI_IMODE_LOAD_PASS2
, flags
,
307 if (ACPI_SUCCESS(status
) && (flags
& ACPI_NS_TEMPORARY
)) {
308 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
309 "***New Node [%4.4s] %p is temporary\n",
310 acpi_ut_get_node_name(node
), node
));
315 if (ACPI_FAILURE(status
)) {
316 ACPI_ERROR_NAMESPACE(buffer_ptr
, status
);
317 return_ACPI_STATUS(status
);
322 /* Create a new op */
324 op
= acpi_ps_alloc_op(walk_state
->opcode
);
326 return_ACPI_STATUS(AE_NO_MEMORY
);
329 /* Initialize the new op */
332 op
->named
.name
= node
->name
.integer
;
338 * Put the Node in the "op" object that the parser uses, so we
339 * can get it again quickly when this scope is closed
341 op
->common
.node
= node
;
342 return_ACPI_STATUS(status
);
345 /*******************************************************************************
347 * FUNCTION: acpi_ds_load2_end_op
349 * PARAMETERS: walk_state - Current state of the parse tree walk
353 * DESCRIPTION: Ascending callback used during the loading of the namespace,
354 * both control methods and everything else.
356 ******************************************************************************/
358 acpi_status
acpi_ds_load2_end_op(struct acpi_walk_state
*walk_state
)
360 union acpi_parse_object
*op
;
361 acpi_status status
= AE_OK
;
362 acpi_object_type object_type
;
363 struct acpi_namespace_node
*node
;
364 union acpi_parse_object
*arg
;
365 struct acpi_namespace_node
*new_node
;
366 #ifndef ACPI_NO_METHOD_EXECUTION
371 ACPI_FUNCTION_TRACE(ds_load2_end_op
);
374 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Opcode [%s] Op %p State %p\n",
375 walk_state
->op_info
->name
, op
, walk_state
));
377 /* Check if opcode had an associated namespace object */
379 if (!(walk_state
->op_info
->flags
& AML_NSOBJECT
)) {
380 return_ACPI_STATUS(AE_OK
);
383 if (op
->common
.aml_opcode
== AML_SCOPE_OP
) {
384 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
385 "Ending scope Op=%p State=%p\n", op
,
389 object_type
= walk_state
->op_info
->object_type
;
392 * Get the Node/name from the earlier lookup
393 * (It was saved in the *op structure)
395 node
= op
->common
.node
;
398 * Put the Node on the object stack (Contains the ACPI Name of
401 walk_state
->operands
[0] = (void *)node
;
402 walk_state
->num_operands
= 1;
404 /* Pop the scope stack */
406 if (acpi_ns_opens_scope(object_type
) &&
407 (op
->common
.aml_opcode
!= AML_INT_METHODCALL_OP
)) {
408 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
409 "(%s) Popping scope for Op %p\n",
410 acpi_ut_get_type_name(object_type
), op
));
412 status
= acpi_ds_scope_stack_pop(walk_state
);
413 if (ACPI_FAILURE(status
)) {
419 * Named operations are as follows:
424 * AML_CREATEBYTEFIELD
425 * AML_CREATEDWORDFIELD
427 * AML_CREATEQWORDFIELD
428 * AML_CREATEWORDFIELD
446 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
447 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
448 acpi_ps_get_opcode_name(op
->common
.aml_opcode
),
449 walk_state
, op
, node
));
451 /* Decode the opcode */
453 arg
= op
->common
.value
.arg
;
455 switch (walk_state
->op_info
->type
) {
456 #ifndef ACPI_NO_METHOD_EXECUTION
458 case AML_TYPE_CREATE_FIELD
:
460 * Create the field object, but the field buffer and index must
461 * be evaluated later during the execution phase
463 status
= acpi_ds_create_buffer_field(op
, walk_state
);
466 case AML_TYPE_NAMED_FIELD
:
468 * If we are executing a method, initialize the field
470 if (walk_state
->method_node
) {
471 status
= acpi_ds_init_field_objects(op
, walk_state
);
474 switch (op
->common
.aml_opcode
) {
475 case AML_INDEX_FIELD_OP
:
478 acpi_ds_create_index_field(op
,
480 common
.node
, walk_state
);
483 case AML_BANK_FIELD_OP
:
486 acpi_ds_create_bank_field(op
, arg
->common
.node
,
493 acpi_ds_create_field(op
, arg
->common
.node
,
498 /* All NAMED_FIELD opcodes must be handled above */
503 case AML_TYPE_NAMED_SIMPLE
:
505 status
= acpi_ds_create_operands(walk_state
, arg
);
506 if (ACPI_FAILURE(status
)) {
510 switch (op
->common
.aml_opcode
) {
511 case AML_PROCESSOR_OP
:
513 status
= acpi_ex_create_processor(walk_state
);
516 case AML_POWER_RES_OP
:
518 status
= acpi_ex_create_power_resource(walk_state
);
523 status
= acpi_ex_create_mutex(walk_state
);
528 status
= acpi_ex_create_event(walk_state
);
533 status
= acpi_ex_create_alias(walk_state
);
543 /* Delete operands */
545 for (i
= 1; i
< walk_state
->num_operands
; i
++) {
546 acpi_ut_remove_reference(walk_state
->operands
[i
]);
547 walk_state
->operands
[i
] = NULL
;
551 #endif /* ACPI_NO_METHOD_EXECUTION */
553 case AML_TYPE_NAMED_COMPLEX
:
555 switch (op
->common
.aml_opcode
) {
556 #ifndef ACPI_NO_METHOD_EXECUTION
558 case AML_DATA_REGION_OP
:
560 if (op
->common
.aml_opcode
== AML_REGION_OP
) {
561 region_space
= (acpi_adr_space_type
)
562 ((op
->common
.value
.arg
)->common
.value
.
565 region_space
= ACPI_ADR_SPACE_DATA_TABLE
;
569 * The op_region is not fully parsed at this time. The only valid
570 * argument is the space_id. (We must save the address of the
571 * AML of the address and length operands)
573 * If we have a valid region, initialize it. The namespace is
574 * unlocked at this point.
576 * Need to unlock interpreter if it is locked (if we are running
577 * a control method), in order to allow _REG methods to be run
578 * during acpi_ev_initialize_region.
580 if (walk_state
->method_node
) {
582 * Executing a method: initialize the region and unlock
586 acpi_ex_create_region(op
->named
.data
,
590 if (ACPI_FAILURE(status
)) {
594 acpi_ex_exit_interpreter();
598 acpi_ev_initialize_region
599 (acpi_ns_get_attached_object(node
), FALSE
);
600 if (walk_state
->method_node
) {
601 acpi_ex_enter_interpreter();
604 if (ACPI_FAILURE(status
)) {
606 * If AE_NOT_EXIST is returned, it is not fatal
607 * because many regions get created before a handler
608 * is installed for said region.
610 if (AE_NOT_EXIST
== status
) {
618 status
= acpi_ds_create_node(walk_state
, node
, op
);
623 * method_op pkg_length name_string method_flags term_list
625 * Note: We must create the method node/object pair as soon as we
626 * see the method declaration. This allows later pass1 parsing
627 * of invocations of the method (need to know the number of
630 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
631 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
632 walk_state
, op
, op
->named
.node
));
634 if (!acpi_ns_get_attached_object(op
->named
.node
)) {
635 walk_state
->operands
[0] =
636 ACPI_CAST_PTR(void, op
->named
.node
);
637 walk_state
->num_operands
= 1;
640 acpi_ds_create_operands(walk_state
,
643 if (ACPI_SUCCESS(status
)) {
645 acpi_ex_create_method(op
->named
.
651 walk_state
->operands
[0] = NULL
;
652 walk_state
->num_operands
= 0;
654 if (ACPI_FAILURE(status
)) {
655 return_ACPI_STATUS(status
);
660 #endif /* ACPI_NO_METHOD_EXECUTION */
663 /* All NAMED_COMPLEX opcodes must be handled above */
668 case AML_CLASS_INTERNAL
:
670 /* case AML_INT_NAMEPATH_OP: */
673 case AML_CLASS_METHOD_CALL
:
675 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
676 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
677 walk_state
, op
, node
));
680 * Lookup the method name and save the Node
683 acpi_ns_lookup(walk_state
->scope_info
,
684 arg
->common
.value
.string
, ACPI_TYPE_ANY
,
685 ACPI_IMODE_LOAD_PASS2
,
686 ACPI_NS_SEARCH_PARENT
|
687 ACPI_NS_DONT_OPEN_SCOPE
, walk_state
,
689 if (ACPI_SUCCESS(status
)) {
691 * Make sure that what we found is indeed a method
692 * We didn't search for a method on purpose, to see if the name
695 if (new_node
->type
!= ACPI_TYPE_METHOD
) {
696 status
= AE_AML_OPERAND_TYPE
;
699 /* We could put the returned object (Node) on the object stack for
700 * later, but for now, we will put it in the "op" object that the
701 * parser uses, so we can get it again at the end of this scope
703 op
->common
.node
= new_node
;
705 ACPI_ERROR_NAMESPACE(arg
->common
.value
.string
, status
);
715 /* Remove the Node pushed at the very beginning */
717 walk_state
->operands
[0] = NULL
;
718 walk_state
->num_operands
= 0;
719 return_ACPI_STATUS(status
);