1 /******************************************************************************
2  *
3  * Module Name: dswload - Dispatcher namespace load callbacks
4  *              $Revision: 96 $
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 #define __DSWLOAD_C__
118 
119 #include "acpi.h"
120 #include "acparser.h"
121 #include "amlcode.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
125 #include "acevents.h"
126 
127 #ifdef ACPI_ASL_COMPILER
128 #include "acdisasm.h"
129 #endif
130 
131 #define _COMPONENT          ACPI_DISPATCHER
132         ACPI_MODULE_NAME    ("dswload")
133 
134 
135 /*******************************************************************************
136  *
137  * FUNCTION:    AcpiDsInitCallbacks
138  *
139  * PARAMETERS:  WalkState       - Current state of the parse tree walk
140  *              PassNumber      - 1, 2, or 3
141  *
142  * RETURN:      Status
143  *
144  * DESCRIPTION: Init walk state callbacks
145  *
146  ******************************************************************************/
147 
148 ACPI_STATUS
149 AcpiDsInitCallbacks (
150     ACPI_WALK_STATE         *WalkState,
151     UINT32                  PassNumber)
152 {
153 
154     switch (PassNumber)
155     {
156     case 1:
157         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
158                                         ACPI_PARSE_DELETE_TREE;
159         WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
160         WalkState->AscendingCallback  = AcpiDsLoad1EndOp;
161         break;
162 
163     case 2:
164         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
165                                         ACPI_PARSE_DELETE_TREE;
166         WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
167         WalkState->AscendingCallback  = AcpiDsLoad2EndOp;
168         break;
169 
170     case 3:
171 #ifndef ACPI_NO_METHOD_EXECUTION
172         WalkState->ParseFlags        |= ACPI_PARSE_EXECUTE  |
173                                         ACPI_PARSE_DELETE_TREE;
174         WalkState->DescendingCallback = AcpiDsExecBeginOp;
175         WalkState->AscendingCallback  = AcpiDsExecEndOp;
176 #endif
177         break;
178 
179     default:
180         return (AE_BAD_PARAMETER);
181     }
182 
183     return (AE_OK);
184 }
185 
186 
187 /*******************************************************************************
188  *
189  * FUNCTION:    AcpiDsLoad1BeginOp
190  *
191  * PARAMETERS:  WalkState       - Current state of the parse tree walk
192  *              OutOp           - Where to return op if a new one is created
193  *
194  * RETURN:      Status
195  *
196  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
197  *
198  ******************************************************************************/
199 
200 ACPI_STATUS
201 AcpiDsLoad1BeginOp (
202     ACPI_WALK_STATE         *WalkState,
203     ACPI_PARSE_OBJECT       **OutOp)
204 {
205     ACPI_PARSE_OBJECT       *Op;
206     ACPI_NAMESPACE_NODE     *Node;
207     ACPI_STATUS             Status;
208     ACPI_OBJECT_TYPE        ObjectType;
209     char                    *Path;
210     UINT32                  Flags;
211 
212 
213     ACPI_FUNCTION_NAME ("DsLoad1BeginOp");
214 
215 
216     Op = WalkState->Op;
217     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
218 
219     /* We are only interested in opcodes that have an associated name */
220 
221     if (Op)
222     {
223         if (!(WalkState->OpInfo->Flags & AML_NAMED))
224         {
225             *OutOp = Op;
226             return (AE_OK);
227         }
228 
229         /* Check if this object has already been installed in the namespace */
230 
231         if (Op->Common.Node)
232         {
233             *OutOp = Op;
234             return (AE_OK);
235         }
236     }
237 
238     Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
239 
240     /* Map the raw opcode into an internal object type */
241 
242     ObjectType = WalkState->OpInfo->ObjectType;
243 
244     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
245         "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
246 
247     switch (WalkState->Opcode)
248     {
249     case AML_SCOPE_OP:
250 
251         /*
252          * The target name of the Scope() operator must exist at this point so
253          * that we can actually open the scope to enter new names underneath it.
254          * Allow search-to-root for single namesegs.
255          */
256         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
257                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
258 #ifdef ACPI_ASL_COMPILER
259         if (Status == AE_NOT_FOUND)
260         {
261             /*
262              * Table disassembly:
263              * Target of Scope() not found.  Generate an External for it, and
264              * insert the name into the namespace.
265              */
266             AcpiDmAddToExternalList (Path);
267             Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
268                        ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
269                        WalkState, &(Node));
270         }
271 #endif
272         if (ACPI_FAILURE (Status))
273         {
274             ACPI_REPORT_NSERROR (Path, Status);
275             return (Status);
276         }
277 
278         /*
279          * Check to make sure that the target is
280          * one of the opcodes that actually opens a scope
281          */
282         switch (Node->Type)
283         {
284         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
285         case ACPI_TYPE_DEVICE:
286         case ACPI_TYPE_POWER:
287         case ACPI_TYPE_PROCESSOR:
288         case ACPI_TYPE_THERMAL:
289 
290             /* These are acceptable types */
291             break;
292 
293         case ACPI_TYPE_INTEGER:
294         case ACPI_TYPE_STRING:
295         case ACPI_TYPE_BUFFER:
296 
297             /*
298              * These types we will allow, but we will change the type.  This
299              * enables some existing code of the form:
300              *
301              *  Name (DEB, 0)
302              *  Scope (DEB) { ... }
303              *
304              * Note: silently change the type here.  On the second pass, we will report
305              * a warning
306              */
307 
308             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
309                 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
310                 Path, AcpiUtGetTypeName (Node->Type)));
311 
312             Node->Type = ACPI_TYPE_ANY;
313             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
314             break;
315 
316         default:
317 
318             /* All other types are an error */
319 
320             ACPI_REPORT_ERROR ((
321                 "Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n",
322                 AcpiUtGetTypeName (Node->Type), Path));
323 
324             return (AE_AML_OPERAND_TYPE);
325         }
326         break;
327 
328 
329     default:
330 
331         /*
332          * For all other named opcodes, we will enter the name into
333          * the namespace.
334          *
335          * Setup the search flags.
336          * Since we are entering a name into the namespace, we do not want to
337          * enable the search-to-root upsearch.
338          *
339          * There are only two conditions where it is acceptable that the name
340          * already exists:
341          *    1) the Scope() operator can reopen a scoping object that was
342          *       previously defined (Scope, Method, Device, etc.)
343          *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
344          *       BufferField, or Package), the name of the object is already
345          *       in the namespace.
346          */
347         if (WalkState->DeferredNode)
348         {
349             /* This name is already in the namespace, get the node */
350 
351             Node = WalkState->DeferredNode;
352             Status = AE_OK;
353             break;
354         }
355 
356         Flags = ACPI_NS_NO_UPSEARCH;
357         if ((WalkState->Opcode != AML_SCOPE_OP) &&
358             (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
359         {
360             Flags |= ACPI_NS_ERROR_IF_FOUND;
361             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
362                     AcpiUtGetTypeName (ObjectType)));
363         }
364         else
365         {
366             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
367                 "[%s] Both Find or Create allowed\n",
368                     AcpiUtGetTypeName (ObjectType)));
369         }
370 
371         /*
372          * Enter the named type into the internal namespace.  We enter the name
373          * as we go downward in the parse tree.  Any necessary subobjects that
374          * involve arguments to the opcode must be created as we go back up the
375          * parse tree later.
376          */
377         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
378                         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &(Node));
379         if (ACPI_FAILURE (Status))
380         {
381             ACPI_REPORT_NSERROR (Path, Status);
382             return (Status);
383         }
384         break;
385     }
386 
387 
388     /* Common exit */
389 
390     if (!Op)
391     {
392         /* Create a new op */
393 
394         Op = AcpiPsAllocOp (WalkState->Opcode);
395         if (!Op)
396         {
397             return (AE_NO_MEMORY);
398         }
399     }
400 
401     /* Initialize */
402 
403     Op->Named.Name = Node->Name.Integer;
404 
405 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
406     Op->Named.Path = (UINT8 *) Path;
407 #endif
408 
409 
410     /*
411      * Put the Node in the "op" object that the parser uses, so we
412      * can get it again quickly when this scope is closed
413      */
414     Op->Common.Node = Node;
415     AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
416 
417     *OutOp = Op;
418     return (Status);
419 }
420 
421 
422 /*******************************************************************************
423  *
424  * FUNCTION:    AcpiDsLoad1EndOp
425  *
426  * PARAMETERS:  WalkState       - Current state of the parse tree walk
427  *
428  * RETURN:      Status
429  *
430  * DESCRIPTION: Ascending callback used during the loading of the namespace,
431  *              both control methods and everything else.
432  *
433  ******************************************************************************/
434 
435 ACPI_STATUS
436 AcpiDsLoad1EndOp (
437     ACPI_WALK_STATE         *WalkState)
438 {
439     ACPI_PARSE_OBJECT       *Op;
440     ACPI_OBJECT_TYPE        ObjectType;
441     ACPI_STATUS             Status = AE_OK;
442 
443 
444     ACPI_FUNCTION_NAME ("DsLoad1EndOp");
445 
446 
447     Op = WalkState->Op;
448     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
449 
450     /* We are only interested in opcodes that have an associated name */
451 
452     if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
453     {
454         return (AE_OK);
455     }
456 
457     /* Get the object type to determine if we should pop the scope */
458 
459     ObjectType = WalkState->OpInfo->ObjectType;
460 
461 #ifndef ACPI_NO_METHOD_EXECUTION
462     if (WalkState->OpInfo->Flags & AML_FIELD)
463     {
464         if (WalkState->Opcode == AML_FIELD_OP          ||
465             WalkState->Opcode == AML_BANK_FIELD_OP     ||
466             WalkState->Opcode == AML_INDEX_FIELD_OP)
467         {
468             Status = AcpiDsInitFieldObjects (Op, WalkState);
469         }
470         return (Status);
471     }
472 
473 
474     if (Op->Common.AmlOpcode == AML_REGION_OP)
475     {
476         Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
477                          (ACPI_ADR_SPACE_TYPE)
478                             ((Op->Common.Value.Arg)->Common.Value.Integer),
479                             WalkState);
480         if (ACPI_FAILURE (Status))
481         {
482             return (Status);
483         }
484     }
485 #endif
486 
487     if (Op->Common.AmlOpcode == AML_NAME_OP)
488     {
489         /* For Name opcode, get the object type from the argument */
490 
491         if (Op->Common.Value.Arg)
492         {
493             ObjectType = (AcpiPsGetOpcodeInfo (
494                 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
495             Op->Common.Node->Type = (UINT8) ObjectType;
496         }
497     }
498 
499     if (Op->Common.AmlOpcode == AML_METHOD_OP)
500     {
501         /*
502          * MethodOp PkgLength NameString MethodFlags TermList
503          *
504          * Note: We must create the method node/object pair as soon as we
505          * see the method declaration.  This allows later pass1 parsing
506          * of invocations of the method (need to know the number of
507          * arguments.)
508          */
509         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
510             "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
511             WalkState, Op, Op->Named.Node));
512 
513         if (!AcpiNsGetAttachedObject (Op->Named.Node))
514         {
515             WalkState->Operands[0] = (void *) Op->Named.Node;
516             WalkState->NumOperands = 1;
517 
518             Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
519             if (ACPI_SUCCESS (Status))
520             {
521                 Status = AcpiExCreateMethod (Op->Named.Data,
522                                     Op->Named.Length, WalkState);
523             }
524             WalkState->Operands[0] = NULL;
525             WalkState->NumOperands = 0;
526 
527             if (ACPI_FAILURE (Status))
528             {
529                 return (Status);
530             }
531         }
532     }
533 
534     /* Pop the scope stack */
535 
536     if (AcpiNsOpensScope (ObjectType))
537     {
538         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
539             AcpiUtGetTypeName (ObjectType), Op));
540 
541         Status = AcpiDsScopeStackPop (WalkState);
542     }
543 
544     return (Status);
545 }
546 
547 
548 /*******************************************************************************
549  *
550  * FUNCTION:    AcpiDsLoad2BeginOp
551  *
552  * PARAMETERS:  WalkState       - Current state of the parse tree walk
553  *              OutOp           - Wher to return op if a new one is created
554  *
555  * RETURN:      Status
556  *
557  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
558  *
559  ******************************************************************************/
560 
561 ACPI_STATUS
562 AcpiDsLoad2BeginOp (
563     ACPI_WALK_STATE         *WalkState,
564     ACPI_PARSE_OBJECT       **OutOp)
565 {
566     ACPI_PARSE_OBJECT       *Op;
567     ACPI_NAMESPACE_NODE     *Node;
568     ACPI_STATUS             Status;
569     ACPI_OBJECT_TYPE        ObjectType;
570     char                    *BufferPtr;
571 
572 
573     ACPI_FUNCTION_TRACE ("DsLoad2BeginOp");
574 
575 
576     Op = WalkState->Op;
577     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
578 
579     if (Op)
580     {
581         if ((WalkState->ControlState) &&
582             (WalkState->ControlState->Common.State ==
583                 ACPI_CONTROL_CONDITIONAL_EXECUTING))
584         {
585             /* We are executing a while loop outside of a method */
586 
587             Status = AcpiDsExecBeginOp (WalkState, OutOp);
588             return_ACPI_STATUS (Status);
589         }
590 
591         /* We only care about Namespace opcodes here */
592 
593         if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE)   &&
594               (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
595             (!(WalkState->OpInfo->Flags & AML_NAMED)))
596         {
597             if ((WalkState->OpInfo->Class == AML_CLASS_EXECUTE) ||
598                 (WalkState->OpInfo->Class == AML_CLASS_CONTROL))
599             {
600                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
601                     "Begin/EXEC: %s (fl %8.8X)\n", WalkState->OpInfo->Name,
602                     WalkState->OpInfo->Flags));
603 
604                 /* Executing a type1 or type2 opcode outside of a method */
605 
606                 Status = AcpiDsExecBeginOp (WalkState, OutOp);
607                 return_ACPI_STATUS (Status);
608             }
609             return_ACPI_STATUS (AE_OK);
610         }
611 
612         /* Get the name we are going to enter or lookup in the namespace */
613 
614         if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
615         {
616             /* For Namepath op, get the path string */
617 
618             BufferPtr = Op->Common.Value.String;
619             if (!BufferPtr)
620             {
621                 /* No name, just exit */
622 
623                 return_ACPI_STATUS (AE_OK);
624             }
625         }
626         else
627         {
628             /* Get name from the op */
629 
630             BufferPtr = (char *) &Op->Named.Name;
631         }
632     }
633     else
634     {
635         /* Get the namestring from the raw AML */
636 
637         BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
638     }
639 
640     /* Map the opcode into an internal object type */
641 
642     ObjectType = WalkState->OpInfo->ObjectType;
643 
644     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
645         "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
646 
647 
648     switch (WalkState->Opcode)
649     {
650     case AML_FIELD_OP:
651     case AML_BANK_FIELD_OP:
652     case AML_INDEX_FIELD_OP:
653 
654         Node = NULL;
655         Status = AE_OK;
656         break;
657 
658     case AML_INT_NAMEPATH_OP:
659 
660         /*
661          * The NamePath is an object reference to an existing object.
662          * Don't enter the name into the namespace, but look it up
663          * for use later.
664          */
665         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
666                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
667                         WalkState, &(Node));
668         break;
669 
670     case AML_SCOPE_OP:
671 
672         /*
673          * The Path is an object reference to an existing object.
674          * Don't enter the name into the namespace, but look it up
675          * for use later.
676          */
677         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
678                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
679                         WalkState, &(Node));
680         if (ACPI_FAILURE (Status))
681         {
682 #ifdef ACPI_ASL_COMPILER
683             if (Status == AE_NOT_FOUND)
684             {
685                 Status = AE_OK;
686             }
687             else
688             {
689                 ACPI_REPORT_NSERROR (BufferPtr, Status);
690             }
691 #else
692             ACPI_REPORT_NSERROR (BufferPtr, Status);
693 #endif
694             return_ACPI_STATUS (Status);
695         }
696         /*
697          * We must check to make sure that the target is
698          * one of the opcodes that actually opens a scope
699          */
700         switch (Node->Type)
701         {
702         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
703         case ACPI_TYPE_DEVICE:
704         case ACPI_TYPE_POWER:
705         case ACPI_TYPE_PROCESSOR:
706         case ACPI_TYPE_THERMAL:
707 
708             /* These are acceptable types */
709             break;
710 
711         case ACPI_TYPE_INTEGER:
712         case ACPI_TYPE_STRING:
713         case ACPI_TYPE_BUFFER:
714 
715             /*
716              * These types we will allow, but we will change the type.  This
717              * enables some existing code of the form:
718              *
719              *  Name (DEB, 0)
720              *  Scope (DEB) { ... }
721              */
722 
723             ACPI_REPORT_WARNING ((
724                 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
725                 BufferPtr, AcpiUtGetTypeName (Node->Type)));
726 
727             Node->Type = ACPI_TYPE_ANY;
728             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
729             break;
730 
731         default:
732 
733             /* All other types are an error */
734 
735             ACPI_REPORT_ERROR ((
736                 "Invalid type (%s) for target of Scope operator [%4.4s]\n",
737                 AcpiUtGetTypeName (Node->Type), BufferPtr));
738 
739             return (AE_AML_OPERAND_TYPE);
740         }
741         break;
742 
743     default:
744 
745         /* All other opcodes */
746 
747         if (Op && Op->Common.Node)
748         {
749             /* This op/node was previously entered into the namespace */
750 
751             Node = Op->Common.Node;
752 
753             if (AcpiNsOpensScope (ObjectType))
754             {
755                 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
756                 if (ACPI_FAILURE (Status))
757                 {
758                     return_ACPI_STATUS (Status);
759                 }
760 
761             }
762             return_ACPI_STATUS (AE_OK);
763         }
764 
765         /*
766          * Enter the named type into the internal namespace.  We enter the name
767          * as we go downward in the parse tree.  Any necessary subobjects that
768          * involve arguments to the opcode must be created as we go back up the
769          * parse tree later.
770          *
771          * Note: Name may already exist if we are executing a deferred opcode.
772          */
773         if (WalkState->DeferredNode)
774         {
775             /* This name is already in the namespace, get the node */
776 
777             Node = WalkState->DeferredNode;
778             Status = AE_OK;
779             break;
780         }
781 
782         /* Add new entry into namespace */
783 
784         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
785                         ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH,
786                         WalkState, &(Node));
787         break;
788     }
789 
790     if (ACPI_FAILURE (Status))
791     {
792         ACPI_REPORT_NSERROR (BufferPtr, Status);
793         return_ACPI_STATUS (Status);
794     }
795 
796     if (!Op)
797     {
798         /* Create a new op */
799 
800         Op = AcpiPsAllocOp (WalkState->Opcode);
801         if (!Op)
802         {
803             return_ACPI_STATUS (AE_NO_MEMORY);
804         }
805 
806         /* Initialize the new op */
807 
808         if (Node)
809         {
810             Op->Named.Name = Node->Name.Integer;
811         }
812         *OutOp = Op;
813     }
814 
815     /*
816      * Put the Node in the "op" object that the parser uses, so we
817      * can get it again quickly when this scope is closed
818      */
819     Op->Common.Node = Node;
820 
821     return_ACPI_STATUS (Status);
822 }
823 
824 
825 /*******************************************************************************
826  *
827  * FUNCTION:    AcpiDsLoad2EndOp
828  *
829  * PARAMETERS:  WalkState       - Current state of the parse tree walk
830  *
831  * RETURN:      Status
832  *
833  * DESCRIPTION: Ascending callback used during the loading of the namespace,
834  *              both control methods and everything else.
835  *
836  ******************************************************************************/
837 
838 ACPI_STATUS
839 AcpiDsLoad2EndOp (
840     ACPI_WALK_STATE         *WalkState)
841 {
842     ACPI_PARSE_OBJECT       *Op;
843     ACPI_STATUS             Status = AE_OK;
844     ACPI_OBJECT_TYPE        ObjectType;
845     ACPI_NAMESPACE_NODE     *Node;
846     ACPI_PARSE_OBJECT       *Arg;
847     ACPI_NAMESPACE_NODE     *NewNode;
848 #ifndef ACPI_NO_METHOD_EXECUTION
849     UINT32                  i;
850 #endif
851 
852 
853     ACPI_FUNCTION_TRACE ("DsLoad2EndOp");
854 
855     Op = WalkState->Op;
856     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
857             WalkState->OpInfo->Name, Op, WalkState));
858 
859     /* Check if opcode had an associated namespace object */
860 
861     if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
862     {
863 #ifndef ACPI_NO_METHOD_EXECUTION
864         /* No namespace object. Executable opcode? */
865 
866         if ((WalkState->OpInfo->Class == AML_CLASS_EXECUTE) ||
867             (WalkState->OpInfo->Class == AML_CLASS_CONTROL))
868         {
869             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
870                 "End/EXEC:   %s (fl %8.8X)\n", WalkState->OpInfo->Name,
871                 WalkState->OpInfo->Flags));
872 
873             /* Executing a type1 or type2 opcode outside of a method */
874 
875             Status = AcpiDsExecEndOp (WalkState);
876             return_ACPI_STATUS (Status);
877         }
878 #endif
879         return_ACPI_STATUS (AE_OK);
880     }
881 
882     if (Op->Common.AmlOpcode == AML_SCOPE_OP)
883     {
884         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
885             "Ending scope Op=%p State=%p\n", Op, WalkState));
886     }
887 
888     ObjectType = WalkState->OpInfo->ObjectType;
889 
890     /*
891      * Get the Node/name from the earlier lookup
892      * (It was saved in the *op structure)
893      */
894     Node = Op->Common.Node;
895 
896     /*
897      * Put the Node on the object stack (Contains the ACPI Name of
898      * this object)
899      */
900     WalkState->Operands[0] = (void *) Node;
901     WalkState->NumOperands = 1;
902 
903     /* Pop the scope stack */
904 
905     if (AcpiNsOpensScope (ObjectType) &&
906        (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
907     {
908         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
909             AcpiUtGetTypeName (ObjectType), Op));
910 
911         Status = AcpiDsScopeStackPop (WalkState);
912         if (ACPI_FAILURE (Status))
913         {
914             goto Cleanup;
915         }
916     }
917 
918     /*
919      * Named operations are as follows:
920      *
921      * AML_ALIAS
922      * AML_BANKFIELD
923      * AML_CREATEBITFIELD
924      * AML_CREATEBYTEFIELD
925      * AML_CREATEDWORDFIELD
926      * AML_CREATEFIELD
927      * AML_CREATEQWORDFIELD
928      * AML_CREATEWORDFIELD
929      * AML_DATA_REGION
930      * AML_DEVICE
931      * AML_EVENT
932      * AML_FIELD
933      * AML_INDEXFIELD
934      * AML_METHOD
935      * AML_METHODCALL
936      * AML_MUTEX
937      * AML_NAME
938      * AML_NAMEDFIELD
939      * AML_OPREGION
940      * AML_POWERRES
941      * AML_PROCESSOR
942      * AML_SCOPE
943      * AML_THERMALZONE
944      */
945 
946     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
947         "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
948         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
949 
950     /* Decode the opcode */
951 
952     Arg = Op->Common.Value.Arg;
953 
954     switch (WalkState->OpInfo->Type)
955     {
956 #ifndef ACPI_NO_METHOD_EXECUTION
957 
958     case AML_TYPE_CREATE_FIELD:
959 
960         /*
961          * Create the field object, but the field buffer and index must
962          * be evaluated later during the execution phase
963          */
964         Status = AcpiDsCreateBufferField (Op, WalkState);
965         break;
966 
967 
968      case AML_TYPE_NAMED_FIELD:
969 
970         switch (Op->Common.AmlOpcode)
971         {
972         case AML_INDEX_FIELD_OP:
973 
974             Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
975                         WalkState);
976             break;
977 
978         case AML_BANK_FIELD_OP:
979 
980             Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
981             break;
982 
983         case AML_FIELD_OP:
984 
985             Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
986             break;
987 
988         default:
989             /* All NAMED_FIELD opcodes must be handled above */
990             break;
991         }
992         break;
993 
994 
995      case AML_TYPE_NAMED_SIMPLE:
996 
997         Status = AcpiDsCreateOperands (WalkState, Arg);
998         if (ACPI_FAILURE (Status))
999         {
1000             goto Cleanup;
1001         }
1002 
1003         switch (Op->Common.AmlOpcode)
1004         {
1005         case AML_PROCESSOR_OP:
1006 
1007             Status = AcpiExCreateProcessor (WalkState);
1008             break;
1009 
1010         case AML_POWER_RES_OP:
1011 
1012             Status = AcpiExCreatePowerResource (WalkState);
1013             break;
1014 
1015         case AML_MUTEX_OP:
1016 
1017             Status = AcpiExCreateMutex (WalkState);
1018             break;
1019 
1020         case AML_EVENT_OP:
1021 
1022             Status = AcpiExCreateEvent (WalkState);
1023             break;
1024 
1025         case AML_DATA_REGION_OP:
1026 
1027             Status = AcpiExCreateTableRegion (WalkState);
1028             break;
1029 
1030         case AML_ALIAS_OP:
1031 
1032             Status = AcpiExCreateAlias (WalkState);
1033             break;
1034 
1035         default:
1036             /* Unknown opcode */
1037 
1038             Status = AE_OK;
1039             goto Cleanup;
1040         }
1041 
1042         /* Delete operands */
1043 
1044         for (i = 1; i < WalkState->NumOperands; i++)
1045         {
1046             AcpiUtRemoveReference (WalkState->Operands[i]);
1047             WalkState->Operands[i] = NULL;
1048         }
1049 
1050         break;
1051 #endif /* ACPI_NO_METHOD_EXECUTION */
1052 
1053     case AML_TYPE_NAMED_COMPLEX:
1054 
1055         switch (Op->Common.AmlOpcode)
1056         {
1057 #ifndef ACPI_NO_METHOD_EXECUTION
1058         case AML_REGION_OP:
1059             /*
1060              * The OpRegion is not fully parsed at this time.  Only valid
1061              * argument is the SpaceId. (We must save the address of the
1062              * AML of the address and length operands)
1063              */
1064             /*
1065              * If we have a valid region, initialize it
1066              * Namespace is NOT locked at this point.
1067              */
1068             Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node),
1069                         FALSE);
1070             if (ACPI_FAILURE (Status))
1071             {
1072                 /*
1073                  *  If AE_NOT_EXIST is returned, it is not fatal
1074                  *  because many regions get created before a handler
1075                  *  is installed for said region.
1076                  */
1077                 if (AE_NOT_EXIST == Status)
1078                 {
1079                     Status = AE_OK;
1080                 }
1081             }
1082             break;
1083 
1084 
1085         case AML_NAME_OP:
1086 
1087             Status = AcpiDsCreateNode (WalkState, Node, Op);
1088             break;
1089 #endif /* ACPI_NO_METHOD_EXECUTION */
1090 
1091 
1092         default:
1093             /* All NAMED_COMPLEX opcodes must be handled above */
1094             /* Note: Method objects were already created in Pass 1 */
1095             break;
1096         }
1097         break;
1098 
1099 
1100     case AML_CLASS_INTERNAL:
1101 
1102         /* case AML_INT_NAMEPATH_OP: */
1103         break;
1104 
1105 
1106     case AML_CLASS_METHOD_CALL:
1107 
1108         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1109             "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
1110             WalkState, Op, Node));
1111 
1112         /*
1113          * Lookup the method name and save the Node
1114          */
1115         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
1116                         ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
1117                         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1118                         WalkState, &(NewNode));
1119         if (ACPI_SUCCESS (Status))
1120         {
1121             /*
1122              * Make sure that what we found is indeed a method
1123              * We didn't search for a method on purpose, to see if the name
1124              * would resolve
1125              */
1126             if (NewNode->Type != ACPI_TYPE_METHOD)
1127             {
1128                 Status = AE_AML_OPERAND_TYPE;
1129             }
1130 
1131             /* We could put the returned object (Node) on the object stack for
1132              * later, but for now, we will put it in the "op" object that the
1133              * parser uses, so we can get it again at the end of this scope
1134              */
1135             Op->Common.Node = NewNode;
1136         }
1137         else
1138         {
1139             ACPI_REPORT_NSERROR (Arg->Common.Value.String, Status);
1140         }
1141         break;
1142 
1143 
1144     default:
1145         break;
1146     }
1147 
1148 Cleanup:
1149 
1150     /* Remove the Node pushed at the very beginning */
1151 
1152     WalkState->Operands[0] = NULL;
1153     WalkState->NumOperands = 0;
1154     return_ACPI_STATUS (Status);
1155 }
1156 
1157 
1158