ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / acpi / dispatcher / dswload.c
1 /******************************************************************************
2  *
3  * Module Name: dswload - Dispatcher namespace load callbacks
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2004, R. Byron Moore
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
25  *
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.
29  *
30  * NO WARRANTY
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.
42  */
43
44
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/amlcode.h>
48 #include <acpi/acdispat.h>
49 #include <acpi/acinterp.h>
50 #include <acpi/acnamesp.h>
51 #include <acpi/acevents.h>
52
53
54 #define _COMPONENT          ACPI_DISPATCHER
55          ACPI_MODULE_NAME    ("dswload")
56
57
58 /*******************************************************************************
59  *
60  * FUNCTION:    acpi_ds_init_callbacks
61  *
62  * PARAMETERS:  walk_state      - Current state of the parse tree walk
63  *              pass_number     - 1, 2, or 3
64  *
65  * RETURN:      Status
66  *
67  * DESCRIPTION: Init walk state callbacks
68  *
69  ******************************************************************************/
70
71 acpi_status
72 acpi_ds_init_callbacks (
73         struct acpi_walk_state          *walk_state,
74         u32                             pass_number)
75 {
76
77         switch (pass_number) {
78         case 1:
79                 walk_state->parse_flags       = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE;
80                 walk_state->descending_callback = acpi_ds_load1_begin_op;
81                 walk_state->ascending_callback = acpi_ds_load1_end_op;
82                 break;
83
84         case 2:
85                 walk_state->parse_flags       = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE;
86                 walk_state->descending_callback = acpi_ds_load2_begin_op;
87                 walk_state->ascending_callback = acpi_ds_load2_end_op;
88                 break;
89
90         case 3:
91 #ifndef ACPI_NO_METHOD_EXECUTION
92                 walk_state->parse_flags      |= ACPI_PARSE_EXECUTE  | ACPI_PARSE_DELETE_TREE;
93                 walk_state->descending_callback = acpi_ds_exec_begin_op;
94                 walk_state->ascending_callback = acpi_ds_exec_end_op;
95 #endif
96                 break;
97
98         default:
99                 return (AE_BAD_PARAMETER);
100         }
101
102         return (AE_OK);
103 }
104
105
106 /*******************************************************************************
107  *
108  * FUNCTION:    acpi_ds_load1_begin_op
109  *
110  * PARAMETERS:  walk_state      - Current state of the parse tree walk
111  *              Op              - Op that has been just been reached in the
112  *                                walk;  Arguments have not been evaluated yet.
113  *
114  * RETURN:      Status
115  *
116  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
117  *
118  ******************************************************************************/
119
120 acpi_status
121 acpi_ds_load1_begin_op (
122         struct acpi_walk_state          *walk_state,
123         union acpi_parse_object         **out_op)
124 {
125         union acpi_parse_object         *op;
126         struct acpi_namespace_node      *node;
127         acpi_status                     status;
128         acpi_object_type                object_type;
129         char                            *path;
130         u32                             flags;
131
132
133         ACPI_FUNCTION_NAME ("ds_load1_begin_op");
134
135
136         op = walk_state->op;
137         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state));
138
139         /* We are only interested in opcodes that have an associated name */
140
141         if (op) {
142                 if (!(walk_state->op_info->flags & AML_NAMED)) {
143 #if 0
144                         if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
145                                 (walk_state->op_info->class == AML_CLASS_CONTROL)) {
146                                 acpi_os_printf ("\n\n***EXECUTABLE OPCODE %s***\n\n", walk_state->op_info->name);
147                                 *out_op = op;
148                                 return (AE_CTRL_SKIP);
149                         }
150 #endif
151                         *out_op = op;
152                         return (AE_OK);
153                 }
154
155                 /* Check if this object has already been installed in the namespace */
156
157                 if (op->common.node) {
158                         *out_op = op;
159                         return (AE_OK);
160                 }
161         }
162
163         path = acpi_ps_get_next_namestring (&walk_state->parser_state);
164
165         /* Map the raw opcode into an internal object type */
166
167         object_type = walk_state->op_info->object_type;
168
169         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
170                 "State=%p Op=%p [%s]\n", walk_state, op, acpi_ut_get_type_name (object_type)));
171
172         switch (walk_state->opcode) {
173         case AML_SCOPE_OP:
174
175                 /*
176                  * The target name of the Scope() operator must exist at this point so
177                  * that we can actually open the scope to enter new names underneath it.
178                  * Allow search-to-root for single namesegs.
179                  */
180                 status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
181                                   ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node));
182                 if (ACPI_FAILURE (status)) {
183                         ACPI_REPORT_NSERROR (path, status);
184                         return (status);
185                 }
186
187                 /*
188                  * Check to make sure that the target is
189                  * one of the opcodes that actually opens a scope
190                  */
191                 switch (node->type) {
192                 case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
193                 case ACPI_TYPE_DEVICE:
194                 case ACPI_TYPE_POWER:
195                 case ACPI_TYPE_PROCESSOR:
196                 case ACPI_TYPE_THERMAL:
197
198                         /* These are acceptable types */
199                         break;
200
201                 case ACPI_TYPE_INTEGER:
202                 case ACPI_TYPE_STRING:
203                 case ACPI_TYPE_BUFFER:
204
205                         /*
206                          * These types we will allow, but we will change the type.  This
207                          * enables some existing code of the form:
208                          *
209                          *  Name (DEB, 0)
210                          *  Scope (DEB) { ... }
211                          *
212                          * Note: silently change the type here.  On the second pass, we will report a warning
213                          */
214
215                         ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
216                                 path, acpi_ut_get_type_name (node->type)));
217
218                         node->type = ACPI_TYPE_ANY;
219                         walk_state->scope_info->common.value = ACPI_TYPE_ANY;
220                         break;
221
222                 default:
223
224                         /* All other types are an error */
225
226                         ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n",
227                                 acpi_ut_get_type_name (node->type), path));
228
229                         return (AE_AML_OPERAND_TYPE);
230                 }
231                 break;
232
233
234         default:
235
236                 /*
237                  * For all other named opcodes, we will enter the name into the namespace.
238                  *
239                  * Setup the search flags.
240                  * Since we are entering a name into the namespace, we do not want to
241                  * enable the search-to-root upsearch.
242                  *
243                  * There are only two conditions where it is acceptable that the name
244                  * already exists:
245                  *    1) the Scope() operator can reopen a scoping object that was
246                  *       previously defined (Scope, Method, Device, etc.)
247                  *    2) Whenever we are parsing a deferred opcode (op_region, Buffer,
248                  *       buffer_field, or Package), the name of the object is already
249                  *       in the namespace.
250                  */
251                 if (walk_state->deferred_node) {
252                         /* This name is already in the namespace, get the node */
253
254                         node = walk_state->deferred_node;
255                         status = AE_OK;
256                         break;
257                 }
258
259                 flags = ACPI_NS_NO_UPSEARCH;
260                 if ((walk_state->opcode != AML_SCOPE_OP) &&
261                         (!(walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP))) {
262                         flags |= ACPI_NS_ERROR_IF_FOUND;
263                         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
264                                         acpi_ut_get_type_name (object_type)));
265                 }
266                 else {
267                         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Both Find or Create allowed\n",
268                                         acpi_ut_get_type_name (object_type)));
269                 }
270
271                 /*
272                  * Enter the named type into the internal namespace.  We enter the name
273                  * as we go downward in the parse tree.  Any necessary subobjects that involve
274                  * arguments to the opcode must be created as we go back up the parse tree later.
275                  */
276                 status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
277                                   ACPI_IMODE_LOAD_PASS1, flags, walk_state, &(node));
278                 if (ACPI_FAILURE (status)) {
279                         ACPI_REPORT_NSERROR (path, status);
280                         return (status);
281                 }
282                 break;
283         }
284
285
286         /* Common exit */
287
288         if (!op) {
289                 /* Create a new op */
290
291                 op = acpi_ps_alloc_op (walk_state->opcode);
292                 if (!op) {
293                         return (AE_NO_MEMORY);
294                 }
295         }
296
297         /* Initialize */
298
299         op->named.name = node->name.integer;
300
301 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
302         op->named.path = (u8 *) path;
303 #endif
304
305
306         /*
307          * Put the Node in the "op" object that the parser uses, so we
308          * can get it again quickly when this scope is closed
309          */
310         op->common.node = node;
311         acpi_ps_append_arg (acpi_ps_get_parent_scope (&walk_state->parser_state), op);
312
313         *out_op = op;
314         return (status);
315 }
316
317
318 /*******************************************************************************
319  *
320  * FUNCTION:    acpi_ds_load1_end_op
321  *
322  * PARAMETERS:  walk_state      - Current state of the parse tree walk
323  *              Op              - Op that has been just been completed in the
324  *                                walk;  Arguments have now been evaluated.
325  *
326  * RETURN:      Status
327  *
328  * DESCRIPTION: Ascending callback used during the loading of the namespace,
329  *              both control methods and everything else.
330  *
331  ******************************************************************************/
332
333 acpi_status
334 acpi_ds_load1_end_op (
335         struct acpi_walk_state          *walk_state)
336 {
337         union acpi_parse_object         *op;
338         acpi_object_type                object_type;
339         acpi_status                     status = AE_OK;
340
341
342         ACPI_FUNCTION_NAME ("ds_load1_end_op");
343
344
345         op = walk_state->op;
346         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state));
347
348         /* We are only interested in opcodes that have an associated name */
349
350         if (!(walk_state->op_info->flags & (AML_NAMED | AML_FIELD))) {
351                 return (AE_OK);
352         }
353
354         /* Get the object type to determine if we should pop the scope */
355
356         object_type = walk_state->op_info->object_type;
357
358 #ifndef ACPI_NO_METHOD_EXECUTION
359         if (walk_state->op_info->flags & AML_FIELD) {
360                 if (walk_state->opcode == AML_FIELD_OP         ||
361                         walk_state->opcode == AML_BANK_FIELD_OP    ||
362                         walk_state->opcode == AML_INDEX_FIELD_OP) {
363                         status = acpi_ds_init_field_objects (op, walk_state);
364                 }
365                 return (status);
366         }
367
368
369         if (op->common.aml_opcode == AML_REGION_OP) {
370                 status = acpi_ex_create_region (op->named.data, op->named.length,
371                                    (acpi_adr_space_type) ((op->common.value.arg)->common.value.integer), walk_state);
372                 if (ACPI_FAILURE (status)) {
373                         return (status);
374                 }
375         }
376 #endif
377
378         if (op->common.aml_opcode == AML_NAME_OP) {
379                 /* For Name opcode, get the object type from the argument */
380
381                 if (op->common.value.arg) {
382                         object_type = (acpi_ps_get_opcode_info ((op->common.value.arg)->common.aml_opcode))->object_type;
383                         op->common.node->type = (u8) object_type;
384                 }
385         }
386
387         if (op->common.aml_opcode == AML_METHOD_OP) {
388                 /*
389                  * method_op pkg_length name_string method_flags term_list
390                  *
391                  * Note: We must create the method node/object pair as soon as we
392                  * see the method declaration.  This allows later pass1 parsing
393                  * of invocations of the method (need to know the number of
394                  * arguments.)
395                  */
396                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
397                         "LOADING-Method: State=%p Op=%p named_obj=%p\n",
398                         walk_state, op, op->named.node));
399
400                 if (!acpi_ns_get_attached_object (op->named.node)) {
401                         walk_state->operands[0] = (void *) op->named.node;
402                         walk_state->num_operands = 1;
403
404                         status = acpi_ds_create_operands (walk_state, op->common.value.arg);
405                         if (ACPI_SUCCESS (status)) {
406                                 status = acpi_ex_create_method (op->named.data,
407                                                    op->named.length, walk_state);
408                         }
409                         walk_state->operands[0] = NULL;
410                         walk_state->num_operands = 0;
411
412                         if (ACPI_FAILURE (status)) {
413                                 return (status);
414                         }
415                 }
416         }
417
418         /* Pop the scope stack */
419
420         if (acpi_ns_opens_scope (object_type)) {
421                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
422                         acpi_ut_get_type_name (object_type), op));
423
424                 status = acpi_ds_scope_stack_pop (walk_state);
425         }
426
427         return (status);
428 }
429
430
431 /*******************************************************************************
432  *
433  * FUNCTION:    acpi_ds_load2_begin_op
434  *
435  * PARAMETERS:  walk_state      - Current state of the parse tree walk
436  *              Op              - Op that has been just been reached in the
437  *                                walk;  Arguments have not been evaluated yet.
438  *
439  * RETURN:      Status
440  *
441  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
442  *
443  ******************************************************************************/
444
445 acpi_status
446 acpi_ds_load2_begin_op (
447         struct acpi_walk_state          *walk_state,
448         union acpi_parse_object         **out_op)
449 {
450         union acpi_parse_object         *op;
451         struct acpi_namespace_node      *node;
452         acpi_status                     status;
453         acpi_object_type                object_type;
454         char                            *buffer_ptr;
455
456
457         ACPI_FUNCTION_TRACE ("ds_load2_begin_op");
458
459
460         op = walk_state->op;
461         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state));
462
463         if (op) {
464                 /* We only care about Namespace opcodes here */
465
466                 if ((!(walk_state->op_info->flags & AML_NSOPCODE) && (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
467                         (!(walk_state->op_info->flags & AML_NAMED))) {
468                         return_ACPI_STATUS (AE_OK);
469                 }
470
471                 /*
472                  * Get the name we are going to enter or lookup in the namespace
473                  */
474                 if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
475                         /* For Namepath op, get the path string */
476
477                         buffer_ptr = op->common.value.string;
478                         if (!buffer_ptr) {
479                                 /* No name, just exit */
480
481                                 return_ACPI_STATUS (AE_OK);
482                         }
483                 }
484                 else {
485                         /* Get name from the op */
486
487                         buffer_ptr = (char *) &op->named.name;
488                 }
489         }
490         else {
491                 /* Get the namestring from the raw AML */
492
493                 buffer_ptr = acpi_ps_get_next_namestring (&walk_state->parser_state);
494         }
495
496         /* Map the opcode into an internal object type */
497
498         object_type = walk_state->op_info->object_type;
499
500         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
501                 "State=%p Op=%p Type=%X\n", walk_state, op, object_type));
502
503
504         switch (walk_state->opcode) {
505         case AML_FIELD_OP:
506         case AML_BANK_FIELD_OP:
507         case AML_INDEX_FIELD_OP:
508
509                 node = NULL;
510                 status = AE_OK;
511                 break;
512
513         case AML_INT_NAMEPATH_OP:
514
515                 /*
516                  * The name_path is an object reference to an existing object. Don't enter the
517                  * name into the namespace, but look it up for use later
518                  */
519                 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
520                                   ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node));
521                 break;
522
523         case AML_SCOPE_OP:
524
525                 /*
526                  * The Path is an object reference to an existing object.  Don't enter the
527                  * name into the namespace, but look it up for use later
528                  */
529                 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
530                                   ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node));
531                 if (ACPI_FAILURE (status)) {
532                         ACPI_REPORT_NSERROR (buffer_ptr, status);
533                         return_ACPI_STATUS (status);
534                 }
535                 /*
536                  * We must check to make sure that the target is
537                  * one of the opcodes that actually opens a scope
538                  */
539                 switch (node->type) {
540                 case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
541                 case ACPI_TYPE_DEVICE:
542                 case ACPI_TYPE_POWER:
543                 case ACPI_TYPE_PROCESSOR:
544                 case ACPI_TYPE_THERMAL:
545
546                         /* These are acceptable types */
547                         break;
548
549                 case ACPI_TYPE_INTEGER:
550                 case ACPI_TYPE_STRING:
551                 case ACPI_TYPE_BUFFER:
552
553                         /*
554                          * These types we will allow, but we will change the type.  This
555                          * enables some existing code of the form:
556                          *
557                          *  Name (DEB, 0)
558                          *  Scope (DEB) { ... }
559                          */
560
561                         ACPI_REPORT_WARNING (("Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
562                                 buffer_ptr, acpi_ut_get_type_name (node->type)));
563
564                         node->type = ACPI_TYPE_ANY;
565                         walk_state->scope_info->common.value = ACPI_TYPE_ANY;
566                         break;
567
568                 default:
569
570                         /* All other types are an error */
571
572                         ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s]\n",
573                                 acpi_ut_get_type_name (node->type), buffer_ptr));
574
575                         return (AE_AML_OPERAND_TYPE);
576                 }
577                 break;
578
579         default:
580
581                 /* All other opcodes */
582
583                 if (op && op->common.node) {
584                         /* This op/node was previously entered into the namespace */
585
586                         node = op->common.node;
587
588                         if (acpi_ns_opens_scope (object_type)) {
589                                 status = acpi_ds_scope_stack_push (node, object_type, walk_state);
590                                 if (ACPI_FAILURE (status)) {
591                                         return_ACPI_STATUS (status);
592                                 }
593
594                         }
595                         return_ACPI_STATUS (AE_OK);
596                 }
597
598                 /*
599                  * Enter the named type into the internal namespace.  We enter the name
600                  * as we go downward in the parse tree.  Any necessary subobjects that involve
601                  * arguments to the opcode must be created as we go back up the parse tree later.
602                  *
603                  * Note: Name may already exist if we are executing a deferred opcode.
604                  */
605                 if (walk_state->deferred_node) {
606                         /* This name is already in the namespace, get the node */
607
608                         node = walk_state->deferred_node;
609                         status = AE_OK;
610                         break;
611                 }
612
613                 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
614                                   ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, walk_state, &(node));
615                 break;
616         }
617
618         if (ACPI_FAILURE (status)) {
619                 ACPI_REPORT_NSERROR (buffer_ptr, status);
620                 return_ACPI_STATUS (status);
621         }
622
623
624         if (!op) {
625                 /* Create a new op */
626
627                 op = acpi_ps_alloc_op (walk_state->opcode);
628                 if (!op) {
629                         return_ACPI_STATUS (AE_NO_MEMORY);
630                 }
631
632                 /* Initialize the new op */
633
634                 if (node) {
635                         op->named.name = node->name.integer;
636                 }
637                 if (out_op) {
638                         *out_op = op;
639                 }
640         }
641
642         /*
643          * Put the Node in the "op" object that the parser uses, so we
644          * can get it again quickly when this scope is closed
645          */
646         op->common.node = node;
647
648         return_ACPI_STATUS (status);
649 }
650
651
652 /*******************************************************************************
653  *
654  * FUNCTION:    acpi_ds_load2_end_op
655  *
656  * PARAMETERS:  walk_state      - Current state of the parse tree walk
657  *              Op              - Op that has been just been completed in the
658  *                                walk;  Arguments have now been evaluated.
659  *
660  * RETURN:      Status
661  *
662  * DESCRIPTION: Ascending callback used during the loading of the namespace,
663  *              both control methods and everything else.
664  *
665  ******************************************************************************/
666
667 acpi_status
668 acpi_ds_load2_end_op (
669         struct acpi_walk_state          *walk_state)
670 {
671         union acpi_parse_object         *op;
672         acpi_status                     status = AE_OK;
673         acpi_object_type                object_type;
674         struct acpi_namespace_node      *node;
675         union acpi_parse_object         *arg;
676         struct acpi_namespace_node      *new_node;
677 #ifndef ACPI_NO_METHOD_EXECUTION
678         u32                             i;
679 #endif
680
681
682         ACPI_FUNCTION_TRACE ("ds_load2_end_op");
683
684         op = walk_state->op;
685         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
686                         walk_state->op_info->name, op, walk_state));
687
688         /* Only interested in opcodes that have namespace objects */
689
690         if (!(walk_state->op_info->flags & AML_NSOBJECT)) {
691                 return_ACPI_STATUS (AE_OK);
692         }
693
694         if (op->common.aml_opcode == AML_SCOPE_OP) {
695                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
696                         "Ending scope Op=%p State=%p\n", op, walk_state));
697         }
698
699
700         object_type = walk_state->op_info->object_type;
701
702         /*
703          * Get the Node/name from the earlier lookup
704          * (It was saved in the *op structure)
705          */
706         node = op->common.node;
707
708         /*
709          * Put the Node on the object stack (Contains the ACPI Name of
710          * this object)
711          */
712         walk_state->operands[0] = (void *) node;
713         walk_state->num_operands = 1;
714
715         /* Pop the scope stack */
716
717         if (acpi_ns_opens_scope (object_type) && (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
718                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
719                         acpi_ut_get_type_name (object_type), op));
720
721                 status = acpi_ds_scope_stack_pop (walk_state);
722                 if (ACPI_FAILURE (status)) {
723                         goto cleanup;
724                 }
725         }
726
727         /*
728          * Named operations are as follows:
729          *
730          * AML_ALIAS
731          * AML_BANKFIELD
732          * AML_CREATEBITFIELD
733          * AML_CREATEBYTEFIELD
734          * AML_CREATEDWORDFIELD
735          * AML_CREATEFIELD
736          * AML_CREATEQWORDFIELD
737          * AML_CREATEWORDFIELD
738          * AML_DATA_REGION
739          * AML_DEVICE
740          * AML_EVENT
741          * AML_FIELD
742          * AML_INDEXFIELD
743          * AML_METHOD
744          * AML_METHODCALL
745          * AML_MUTEX
746          * AML_NAME
747          * AML_NAMEDFIELD
748          * AML_OPREGION
749          * AML_POWERRES
750          * AML_PROCESSOR
751          * AML_SCOPE
752          * AML_THERMALZONE
753          */
754
755         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
756                 "Create-Load [%s] State=%p Op=%p named_obj=%p\n",
757                 acpi_ps_get_opcode_name (op->common.aml_opcode), walk_state, op, node));
758
759         /* Decode the opcode */
760
761         arg = op->common.value.arg;
762
763         switch (walk_state->op_info->type) {
764 #ifndef ACPI_NO_METHOD_EXECUTION
765
766         case AML_TYPE_CREATE_FIELD:
767
768                 /*
769                  * Create the field object, but the field buffer and index must
770                  * be evaluated later during the execution phase
771                  */
772                 status = acpi_ds_create_buffer_field (op, walk_state);
773                 break;
774
775
776          case AML_TYPE_NAMED_FIELD:
777
778                 switch (op->common.aml_opcode) {
779                 case AML_INDEX_FIELD_OP:
780
781                         status = acpi_ds_create_index_field (op, (acpi_handle) arg->common.node,
782                                            walk_state);
783                         break;
784
785                 case AML_BANK_FIELD_OP:
786
787                         status = acpi_ds_create_bank_field (op, arg->common.node, walk_state);
788                         break;
789
790                 case AML_FIELD_OP:
791
792                         status = acpi_ds_create_field (op, arg->common.node, walk_state);
793                         break;
794
795                 default:
796                         /* All NAMED_FIELD opcodes must be handled above */
797                         break;
798                 }
799                 break;
800
801
802          case AML_TYPE_NAMED_SIMPLE:
803
804                 status = acpi_ds_create_operands (walk_state, arg);
805                 if (ACPI_FAILURE (status)) {
806                         goto cleanup;
807                 }
808
809                 switch (op->common.aml_opcode) {
810                 case AML_PROCESSOR_OP:
811
812                         status = acpi_ex_create_processor (walk_state);
813                         break;
814
815                 case AML_POWER_RES_OP:
816
817                         status = acpi_ex_create_power_resource (walk_state);
818                         break;
819
820                 case AML_MUTEX_OP:
821
822                         status = acpi_ex_create_mutex (walk_state);
823                         break;
824
825                 case AML_EVENT_OP:
826
827                         status = acpi_ex_create_event (walk_state);
828                         break;
829
830                 case AML_DATA_REGION_OP:
831
832                         status = acpi_ex_create_table_region (walk_state);
833                         break;
834
835                 case AML_ALIAS_OP:
836
837                         status = acpi_ex_create_alias (walk_state);
838                         break;
839
840                 default:
841                         /* Unknown opcode */
842
843                         status = AE_OK;
844                         goto cleanup;
845                 }
846
847                 /* Delete operands */
848
849                 for (i = 1; i < walk_state->num_operands; i++) {
850                         acpi_ut_remove_reference (walk_state->operands[i]);
851                         walk_state->operands[i] = NULL;
852                 }
853
854                 break;
855 #endif /* ACPI_NO_METHOD_EXECUTION */
856
857         case AML_TYPE_NAMED_COMPLEX:
858
859                 switch (op->common.aml_opcode) {
860 #ifndef ACPI_NO_METHOD_EXECUTION
861                 case AML_REGION_OP:
862                         /*
863                          * The op_region is not fully parsed at this time. Only valid argument is the space_id.
864                          * (We must save the address of the AML of the address and length operands)
865                          */
866                         /*
867                          * If we have a valid region, initialize it
868                          * Namespace is NOT locked at this point.
869                          */
870                         status = acpi_ev_initialize_region (acpi_ns_get_attached_object (node), FALSE);
871                         if (ACPI_FAILURE (status)) {
872                                 /*
873                                  *  If AE_NOT_EXIST is returned, it is not fatal
874                                  *  because many regions get created before a handler
875                                  *  is installed for said region.
876                                  */
877                                 if (AE_NOT_EXIST == status) {
878                                         status = AE_OK;
879                                 }
880                         }
881                         break;
882
883
884                 case AML_NAME_OP:
885
886                         status = acpi_ds_create_node (walk_state, node, op);
887                         break;
888 #endif /* ACPI_NO_METHOD_EXECUTION */
889
890
891                 default:
892                         /* All NAMED_COMPLEX opcodes must be handled above */
893                         /* Note: Method objects were already created in Pass 1 */
894                         break;
895                 }
896                 break;
897
898
899         case AML_CLASS_INTERNAL:
900
901                 /* case AML_INT_NAMEPATH_OP: */
902                 break;
903
904
905         case AML_CLASS_METHOD_CALL:
906
907                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
908                         "RESOLVING-method_call: State=%p Op=%p named_obj=%p\n",
909                         walk_state, op, node));
910
911                 /*
912                  * Lookup the method name and save the Node
913                  */
914                 status = acpi_ns_lookup (walk_state->scope_info, arg->common.value.string,
915                                   ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
916                                   ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
917                                   walk_state, &(new_node));
918                 if (ACPI_SUCCESS (status)) {
919                         /*
920                          * Make sure that what we found is indeed a method
921                          * We didn't search for a method on purpose, to see if the name would resolve
922                          */
923                         if (new_node->type != ACPI_TYPE_METHOD) {
924                                 status = AE_AML_OPERAND_TYPE;
925                         }
926
927                         /* We could put the returned object (Node) on the object stack for later, but
928                          * for now, we will put it in the "op" object that the parser uses, so we
929                          * can get it again at the end of this scope
930                          */
931                         op->common.node = new_node;
932                 }
933                 else {
934                         ACPI_REPORT_NSERROR (arg->common.value.string, status);
935                 }
936                 break;
937
938
939         default:
940                 break;
941         }
942
943 cleanup:
944
945         /* Remove the Node pushed at the very beginning */
946
947         walk_state->operands[0] = NULL;
948         walk_state->num_operands = 0;
949         return_ACPI_STATUS (status);
950 }
951
952