1 /******************************************************************************
3 * Module Name: dswload - Dispatcher namespace load callbacks
6 *****************************************************************************/
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #define _COMPONENT DISPATCHER
37 MODULE_NAME ("dswload")
40 /*****************************************************************************
42 * FUNCTION: Acpi_ds_load1_begin_op
44 * PARAMETERS: Walk_state - Current state of the parse tree walk
45 * Op - Op that has been just been reached in the
46 * walk; Arguments have not been evaluated yet.
50 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
52 ****************************************************************************/
55 acpi_ds_load1_begin_op (
57 ACPI_PARSE_OBJECT
*op
,
58 ACPI_WALK_STATE
*walk_state
,
59 ACPI_PARSE_OBJECT
**out_op
)
61 ACPI_NAMESPACE_NODE
*node
;
63 OBJECT_TYPE_INTERNAL data_type
;
67 /* We are only interested in opcodes that have an associated name */
69 if (!acpi_ps_is_named_op (opcode
)) {
75 /* Check if this object has already been installed in the namespace */
82 path
= acpi_ps_get_next_namestring (walk_state
->parser_state
);
84 /* Map the raw opcode into an internal object type */
86 data_type
= acpi_ds_map_named_opcode_to_data_type (opcode
);
91 * Enter the named type into the internal namespace. We enter the name
92 * as we go downward in the parse tree. Any necessary subobjects that involve
93 * arguments to the opcode must be created as we go back up the parse tree later.
95 status
= acpi_ns_lookup (walk_state
->scope_info
, path
,
96 data_type
, IMODE_LOAD_PASS1
,
97 NS_NO_UPSEARCH
, walk_state
, &(node
));
99 if (ACPI_FAILURE (status
)) {
104 /* Create a new op */
106 op
= acpi_ps_alloc_op (opcode
);
108 return (AE_NO_MEMORY
);
114 ((ACPI_PARSE2_OBJECT
*)op
)->name
= node
->name
;
117 * Put the Node in the "op" object that the parser uses, so we
118 * can get it again quickly when this scope is closed
123 acpi_ps_append_arg (acpi_ps_get_parent_scope (walk_state
->parser_state
), op
);
131 /*****************************************************************************
133 * FUNCTION: Acpi_ds_load1_end_op
135 * PARAMETERS: Walk_state - Current state of the parse tree walk
136 * Op - Op that has been just been completed in the
137 * walk; Arguments have now been evaluated.
141 * DESCRIPTION: Ascending callback used during the loading of the namespace,
142 * both control methods and everything else.
144 ****************************************************************************/
147 acpi_ds_load1_end_op (
148 ACPI_WALK_STATE
*walk_state
,
149 ACPI_PARSE_OBJECT
*op
)
151 OBJECT_TYPE_INTERNAL data_type
;
154 /* We are only interested in opcodes that have an associated name */
156 if (!acpi_ps_is_named_op (op
->opcode
)) {
161 /* Get the type to determine if we should pop the scope */
163 data_type
= acpi_ds_map_named_opcode_to_data_type (op
->opcode
);
165 if (op
->opcode
== AML_NAME_OP
) {
166 /* For Name opcode, check the argument */
169 data_type
= acpi_ds_map_opcode_to_data_type (
170 (op
->value
.arg
)->opcode
, NULL
);
171 ((ACPI_NAMESPACE_NODE
*)op
->node
)->type
=
177 /* Pop the scope stack */
179 if (acpi_ns_opens_scope (data_type
)) {
181 acpi_ds_scope_stack_pop (walk_state
);
189 /*****************************************************************************
191 * FUNCTION: Acpi_ds_load2_begin_op
193 * PARAMETERS: Walk_state - Current state of the parse tree walk
194 * Op - Op that has been just been reached in the
195 * walk; Arguments have not been evaluated yet.
199 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
201 ****************************************************************************/
204 acpi_ds_load2_begin_op (
206 ACPI_PARSE_OBJECT
*op
,
207 ACPI_WALK_STATE
*walk_state
,
208 ACPI_PARSE_OBJECT
**out_op
)
210 ACPI_NAMESPACE_NODE
*node
;
212 OBJECT_TYPE_INTERNAL data_type
;
213 NATIVE_CHAR
*buffer_ptr
;
214 void *original
= NULL
;
217 /* We only care about Namespace opcodes here */
219 if (!acpi_ps_is_namespace_op (opcode
) &&
220 opcode
!= AML_NAMEPATH_OP
)
226 /* Temp! same code as in psparse */
228 if (!acpi_ps_is_named_op (opcode
)) {
234 * Get the name we are going to enter or lookup in the namespace
236 if (opcode
== AML_NAMEPATH_OP
) {
237 /* For Namepath op, get the path string */
239 buffer_ptr
= op
->value
.string
;
241 /* No name, just exit */
248 /* Get name from the op */
250 buffer_ptr
= (NATIVE_CHAR
*) &((ACPI_PARSE2_OBJECT
*)op
)->name
;
255 buffer_ptr
= acpi_ps_get_next_namestring (walk_state
->parser_state
);
259 /* Map the raw opcode into an internal object type */
261 data_type
= acpi_ds_map_named_opcode_to_data_type (opcode
);
264 if (opcode
== AML_DEF_FIELD_OP
||
265 opcode
== AML_BANK_FIELD_OP
||
266 opcode
== AML_INDEX_FIELD_OP
)
272 else if (opcode
== AML_NAMEPATH_OP
) {
274 * The Name_path is an object reference to an existing object. Don't enter the
275 * name into the namespace, but look it up for use later
277 status
= acpi_ns_lookup (walk_state
->scope_info
, buffer_ptr
,
278 data_type
, IMODE_EXECUTE
,
279 NS_SEARCH_PARENT
, walk_state
,
284 if (op
&& op
->node
) {
288 if (acpi_ns_opens_scope (data_type
)) {
289 status
= acpi_ds_scope_stack_push (node
,
292 if (ACPI_FAILURE (status
)) {
301 * Enter the named type into the internal namespace. We enter the name
302 * as we go downward in the parse tree. Any necessary subobjects that involve
303 * arguments to the opcode must be created as we go back up the parse tree later.
305 status
= acpi_ns_lookup (walk_state
->scope_info
, buffer_ptr
,
306 data_type
, IMODE_EXECUTE
,
307 NS_NO_UPSEARCH
, walk_state
,
311 if (ACPI_SUCCESS (status
)) {
313 /* Create a new op */
315 op
= acpi_ps_alloc_op (opcode
);
317 return (AE_NO_MEMORY
);
322 ((ACPI_PARSE2_OBJECT
*)op
)->name
= node
->name
;
328 * Put the Node in the "op" object that the parser uses, so we
329 * can get it again quickly when this scope is closed
340 /*****************************************************************************
342 * FUNCTION: Acpi_ds_load2_end_op
344 * PARAMETERS: Walk_state - Current state of the parse tree walk
345 * Op - Op that has been just been completed in the
346 * walk; Arguments have now been evaluated.
350 * DESCRIPTION: Ascending callback used during the loading of the namespace,
351 * both control methods and everything else.
353 ****************************************************************************/
356 acpi_ds_load2_end_op (
357 ACPI_WALK_STATE
*walk_state
,
358 ACPI_PARSE_OBJECT
*op
)
360 ACPI_STATUS status
= AE_OK
;
361 OBJECT_TYPE_INTERNAL data_type
;
362 ACPI_NAMESPACE_NODE
*node
;
363 ACPI_PARSE_OBJECT
*arg
;
364 ACPI_NAMESPACE_NODE
*new_node
;
367 if (!acpi_ps_is_namespace_object_op (op
->opcode
)) {
371 if (op
->opcode
== AML_SCOPE_OP
) {
372 if (((ACPI_PARSE2_OBJECT
*)op
)->name
== -1) {
378 data_type
= acpi_ds_map_named_opcode_to_data_type (op
->opcode
);
381 * Get the Node/name from the earlier lookup
382 * (It was saved in the *op structure)
387 * Put the Node on the object stack (Contains the ACPI Name of
391 walk_state
->operands
[0] = (void *) node
;
392 walk_state
->num_operands
= 1;
394 /* Pop the scope stack */
396 if (acpi_ns_opens_scope (data_type
)) {
398 acpi_ds_scope_stack_pop (walk_state
);
403 * Named operations are as follows:
422 * AML_CREATEBYTEFIELD
423 * AML_CREATEWORDFIELD
424 * AML_CREATEDWORDFIELD
429 /* Decode the opcode */
436 case AML_CREATE_FIELD_OP
:
437 case AML_BIT_FIELD_OP
:
438 case AML_BYTE_FIELD_OP
:
439 case AML_WORD_FIELD_OP
:
440 case AML_DWORD_FIELD_OP
:
443 * Create the field object, but the field buffer and index must
444 * be evaluated later during the execution phase
447 /* Get the Name_string argument */
449 if (op
->opcode
== AML_CREATE_FIELD_OP
) {
450 arg
= acpi_ps_get_arg (op
, 3);
453 /* Create Bit/Byte/Word/Dword field */
455 arg
= acpi_ps_get_arg (op
, 2);
459 * Enter the Name_string into the namespace
462 status
= acpi_ns_lookup (walk_state
->scope_info
,
464 INTERNAL_TYPE_DEF_ANY
,
466 NS_NO_UPSEARCH
| NS_DONT_OPEN_SCOPE
,
467 walk_state
, &(new_node
));
469 if (ACPI_SUCCESS (status
)) {
470 /* We could put the returned object (Node) on the object stack for later, but
471 * for now, we will put it in the "op" object that the parser uses, so we
472 * can get it again at the end of this scope
477 * If there is no object attached to the node, this node was just created and
478 * we need to create the field object. Otherwise, this was a lookup of an
479 * existing node and we don't want to create the field object again.
481 if (!new_node
->object
) {
483 * The Field definition is not fully parsed at this time.
484 * (We must save the address of the AML for the buffer and index operands)
486 status
= acpi_aml_exec_create_field (((ACPI_PARSE2_OBJECT
*) op
)->data
,
487 ((ACPI_PARSE2_OBJECT
*) op
)->length
,
488 new_node
, walk_state
);
496 case AML_METHODCALL_OP
:
499 * Lookup the method name and save the Node
502 status
= acpi_ns_lookup (walk_state
->scope_info
, arg
->value
.string
,
503 ACPI_TYPE_ANY
, IMODE_LOAD_PASS2
,
504 NS_SEARCH_PARENT
| NS_DONT_OPEN_SCOPE
,
505 walk_state
, &(new_node
));
507 if (ACPI_SUCCESS (status
)) {
509 /* has name already been resolved by here ??*/
511 /* TBD: [Restructure] Make sure that what we found is indeed a method! */
512 /* We didn't search for a method on purpose, to see if the name would resolve! */
514 /* We could put the returned object (Node) on the object stack for later, but
515 * for now, we will put it in the "op" object that the parser uses, so we
516 * can get it again at the end of this scope
525 case AML_PROCESSOR_OP
:
527 /* Nothing to do other than enter object into namespace */
529 status
= acpi_aml_exec_create_processor (op
, (ACPI_HANDLE
) node
);
530 if (ACPI_FAILURE (status
)) {
537 case AML_POWER_RES_OP
:
539 /* Nothing to do other than enter object into namespace */
541 status
= acpi_aml_exec_create_power_resource (op
, (ACPI_HANDLE
) node
);
542 if (ACPI_FAILURE (status
)) {
549 case AML_THERMAL_ZONE_OP
:
551 /* Nothing to do other than enter object into namespace */
556 case AML_DEF_FIELD_OP
:
560 status
= acpi_ds_create_field (op
,
566 case AML_INDEX_FIELD_OP
:
570 status
= acpi_ds_create_index_field (op
,
571 (ACPI_HANDLE
) arg
->node
,
576 case AML_BANK_FIELD_OP
:
579 status
= acpi_ds_create_bank_field (op
,
586 * Method_op Pkg_length Names_string Method_flags Term_list
591 status
= acpi_aml_exec_create_method (((ACPI_PARSE2_OBJECT
*) op
)->data
,
592 ((ACPI_PARSE2_OBJECT
*) op
)->length
,
593 arg
->value
.integer
, (ACPI_HANDLE
) node
);
601 status
= acpi_ds_create_operands (walk_state
, arg
);
602 if (ACPI_FAILURE (status
)) {
606 status
= acpi_aml_exec_create_mutex (walk_state
);
612 status
= acpi_ds_create_operands (walk_state
, arg
);
613 if (ACPI_FAILURE (status
)) {
617 status
= acpi_aml_exec_create_event (walk_state
);
629 * The Op_region is not fully parsed at this time. Only valid argument is the Space_id.
630 * (We must save the address of the AML of the address and length operands)
633 status
= acpi_aml_exec_create_region (((ACPI_PARSE2_OBJECT
*) op
)->data
,
634 ((ACPI_PARSE2_OBJECT
*) op
)->length
,
635 (ACPI_ADDRESS_SPACE_TYPE
) arg
->value
.integer
,
641 /* Namespace Modifier Opcodes */
645 status
= acpi_ds_create_operands (walk_state
, arg
);
646 if (ACPI_FAILURE (status
)) {
650 status
= acpi_aml_exec_create_alias (walk_state
);
657 * Because of the execution pass through the non-control-method
658 * parts of the table, we can arrive here twice. Only init
659 * the named object node the first time through
663 status
= acpi_ds_create_node (walk_state
, node
, op
);
669 case AML_NAMEPATH_OP
:
681 /* Remove the Node pushed at the very beginning */
683 acpi_ds_obj_stack_pop (1, walk_state
);