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