67d9b11389464f53812a75770a41b31a8d75d4b7
[dragonfly.git] / sys / contrib / dev / acpica-unix / common / adwalk.c
1 /******************************************************************************
2  *
3  * Module Name: adwalk - Application-level disassembler parse tree walk routines
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights.  You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code.  No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision.  In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change.  Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee.  Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution.  In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government.  In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115
116
117 #include "acpi.h"
118 #include "accommon.h"
119 #include "acparser.h"
120 #include "amlcode.h"
121 #include "acdebug.h"
122 #include "acdisasm.h"
123 #include "acdispat.h"
124 #include "acnamesp.h"
125 #include "acapps.h"
126
127
128 #define _COMPONENT          ACPI_TOOLS
129         ACPI_MODULE_NAME    ("adwalk")
130
131 /*
132  * aslmap - opcode mappings and reserved method names
133  */
134 ACPI_OBJECT_TYPE
135 AslMapNamedOpcodeToDataType (
136     UINT16                  Opcode);
137
138 /* Local prototypes */
139
140 static ACPI_STATUS
141 AcpiDmFindOrphanDescending (
142     ACPI_PARSE_OBJECT       *Op,
143     UINT32                  Level,
144     void                    *Context);
145
146 static ACPI_STATUS
147 AcpiDmDumpDescending (
148     ACPI_PARSE_OBJECT       *Op,
149     UINT32                  Level,
150     void                    *Context);
151
152 static ACPI_STATUS
153 AcpiDmXrefDescendingOp (
154     ACPI_PARSE_OBJECT       *Op,
155     UINT32                  Level,
156     void                    *Context);
157
158 static ACPI_STATUS
159 AcpiDmCommonAscendingOp (
160     ACPI_PARSE_OBJECT       *Op,
161     UINT32                  Level,
162     void                    *Context);
163
164 static ACPI_STATUS
165 AcpiDmLoadDescendingOp (
166     ACPI_PARSE_OBJECT       *Op,
167     UINT32                  Level,
168     void                    *Context);
169
170 static UINT32
171 AcpiDmInspectPossibleArgs (
172     UINT32                  CurrentOpArgCount,
173     UINT32                  TargetCount,
174     ACPI_PARSE_OBJECT       *Op);
175
176 static ACPI_STATUS
177 AcpiDmResourceDescendingOp (
178     ACPI_PARSE_OBJECT       *Op,
179     UINT32                  Level,
180     void                    *Context);
181
182
183 /*******************************************************************************
184  *
185  * FUNCTION:    AcpiDmDumpTree
186  *
187  * PARAMETERS:  Origin          - Starting object
188  *
189  * RETURN:      None
190  *
191  * DESCRIPTION: Parse tree walk to format and output the nodes
192  *
193  ******************************************************************************/
194
195 void
196 AcpiDmDumpTree (
197     ACPI_PARSE_OBJECT       *Origin)
198 {
199     ACPI_OP_WALK_INFO       Info;
200
201
202     if (!Origin)
203     {
204         return;
205     }
206
207     AcpiOsPrintf ("/*\nAML Parse Tree\n\n");
208     Info.Flags = 0;
209     Info.Count = 0;
210     Info.Level = 0;
211     Info.WalkState = NULL;
212     AcpiDmWalkParseTree (Origin, AcpiDmDumpDescending, NULL, &Info);
213     AcpiOsPrintf ("*/\n\n");
214 }
215
216
217 /*******************************************************************************
218  *
219  * FUNCTION:    AcpiDmFindOrphanMethods
220  *
221  * PARAMETERS:  Origin          - Starting object
222  *
223  * RETURN:      None
224  *
225  * DESCRIPTION: Parse tree walk to find "orphaned" method invocations -- methods
226  *              that are not resolved in the namespace
227  *
228  ******************************************************************************/
229
230 void
231 AcpiDmFindOrphanMethods (
232     ACPI_PARSE_OBJECT       *Origin)
233 {
234     ACPI_OP_WALK_INFO       Info;
235
236
237     if (!Origin)
238     {
239         return;
240     }
241
242     Info.Flags = 0;
243     Info.Level = 0;
244     Info.WalkState = NULL;
245     AcpiDmWalkParseTree (Origin, AcpiDmFindOrphanDescending, NULL, &Info);
246 }
247
248
249 /*******************************************************************************
250  *
251  * FUNCTION:    AcpiDmFinishNamespaceLoad
252  *
253  * PARAMETERS:  ParseTreeRoot       - Root of the parse tree
254  *              NamespaceRoot       - Root of the internal namespace
255  *              OwnerId             - OwnerId of the table to be disassembled
256  *
257  * RETURN:      None
258  *
259  * DESCRIPTION: Load all namespace items that are created within control
260  *              methods. Used before namespace cross reference
261  *
262  ******************************************************************************/
263
264 void
265 AcpiDmFinishNamespaceLoad (
266     ACPI_PARSE_OBJECT       *ParseTreeRoot,
267     ACPI_NAMESPACE_NODE     *NamespaceRoot,
268     ACPI_OWNER_ID           OwnerId)
269 {
270     ACPI_STATUS             Status;
271     ACPI_OP_WALK_INFO       Info;
272     ACPI_WALK_STATE         *WalkState;
273
274
275     if (!ParseTreeRoot)
276     {
277         return;
278     }
279
280     /* Create and initialize a new walk state */
281
282     WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
283     if (!WalkState)
284     {
285         return;
286     }
287
288     Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
289     if (ACPI_FAILURE (Status))
290     {
291         return;
292     }
293
294     Info.Flags = 0;
295     Info.Level = 0;
296     Info.WalkState = WalkState;
297     AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmLoadDescendingOp,
298         AcpiDmCommonAscendingOp, &Info);
299     ACPI_FREE (WalkState);
300 }
301
302
303 /*******************************************************************************
304  *
305  * FUNCTION:    AcpiDmCrossReferenceNamespace
306  *
307  * PARAMETERS:  ParseTreeRoot       - Root of the parse tree
308  *              NamespaceRoot       - Root of the internal namespace
309  *              OwnerId             - OwnerId of the table to be disassembled
310  *
311  * RETURN:      None
312  *
313  * DESCRIPTION: Cross reference the namespace to create externals
314  *
315  ******************************************************************************/
316
317 void
318 AcpiDmCrossReferenceNamespace (
319     ACPI_PARSE_OBJECT       *ParseTreeRoot,
320     ACPI_NAMESPACE_NODE     *NamespaceRoot,
321     ACPI_OWNER_ID           OwnerId)
322 {
323     ACPI_STATUS             Status;
324     ACPI_OP_WALK_INFO       Info;
325     ACPI_WALK_STATE         *WalkState;
326
327
328     if (!ParseTreeRoot)
329     {
330         return;
331     }
332
333     /* Create and initialize a new walk state */
334
335     WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
336     if (!WalkState)
337     {
338         return;
339     }
340
341     Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
342     if (ACPI_FAILURE (Status))
343     {
344         return;
345     }
346
347     Info.Flags = 0;
348     Info.Level = 0;
349     Info.WalkState = WalkState;
350     AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmXrefDescendingOp,
351         AcpiDmCommonAscendingOp, &Info);
352     ACPI_FREE (WalkState);
353 }
354
355
356 /*******************************************************************************
357  *
358  * FUNCTION:    AcpiDmConvertResourceIndexes
359  *
360  * PARAMETERS:  ParseTreeRoot       - Root of the parse tree
361  *              NamespaceRoot       - Root of the internal namespace
362  *
363  * RETURN:      None
364  *
365  * DESCRIPTION: Convert fixed-offset references to resource descriptors to
366  *              symbolic references. Should only be called after namespace has
367  *              been cross referenced.
368  *
369  ******************************************************************************/
370
371 void
372 AcpiDmConvertResourceIndexes (
373     ACPI_PARSE_OBJECT       *ParseTreeRoot,
374     ACPI_NAMESPACE_NODE     *NamespaceRoot)
375 {
376     ACPI_STATUS             Status;
377     ACPI_OP_WALK_INFO       Info;
378     ACPI_WALK_STATE         *WalkState;
379
380
381     if (!ParseTreeRoot)
382     {
383         return;
384     }
385
386     /* Create and initialize a new walk state */
387
388     WalkState = AcpiDsCreateWalkState (0, ParseTreeRoot, NULL, NULL);
389     if (!WalkState)
390     {
391         return;
392     }
393
394     Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
395     if (ACPI_FAILURE (Status))
396     {
397         return;
398     }
399
400     Info.Flags = 0;
401     Info.Level = 0;
402     Info.WalkState = WalkState;
403     AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmResourceDescendingOp,
404         AcpiDmCommonAscendingOp, &Info);
405     ACPI_FREE (WalkState);
406     return;
407 }
408
409
410 /*******************************************************************************
411  *
412  * FUNCTION:    AcpiDmDumpDescending
413  *
414  * PARAMETERS:  ASL_WALK_CALLBACK
415  *
416  * RETURN:      Status
417  *
418  * DESCRIPTION: Format and print contents of one parse Op.
419  *
420  ******************************************************************************/
421
422 static ACPI_STATUS
423 AcpiDmDumpDescending (
424     ACPI_PARSE_OBJECT       *Op,
425     UINT32                  Level,
426     void                    *Context)
427 {
428     ACPI_OP_WALK_INFO       *Info = Context;
429     const ACPI_OPCODE_INFO  *OpInfo;
430     char                    *Path;
431
432
433     if (!Op)
434     {
435         return (AE_OK);
436     }
437
438     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
439     Info->Count++;
440
441     /* Most of the information (count, level, name) here */
442
443     AcpiOsPrintf ("% 5d [%2.2d] ", Info->Count, Level);
444     AcpiDmIndent (Level);
445     AcpiOsPrintf ("%-28s", AcpiPsGetOpcodeName (Op->Common.AmlOpcode));
446
447     /* Extra info is helpful */
448
449     switch (Op->Common.AmlOpcode)
450     {
451     case AML_BYTE_OP:
452     case AML_WORD_OP:
453     case AML_DWORD_OP:
454         AcpiOsPrintf ("%X", (UINT32) Op->Common.Value.Integer);
455         break;
456
457     case AML_INT_NAMEPATH_OP:
458         if (Op->Common.Value.String)
459         {
460             AcpiNsExternalizeName (ACPI_UINT32_MAX, Op->Common.Value.String,
461                             NULL, &Path);
462             AcpiOsPrintf ("%s %p", Path, Op->Common.Node);
463             ACPI_FREE (Path);
464         }
465         else
466         {
467             AcpiOsPrintf ("[NULL]");
468         }
469         break;
470
471     case AML_NAME_OP:
472     case AML_METHOD_OP:
473     case AML_DEVICE_OP:
474     case AML_INT_NAMEDFIELD_OP:
475         AcpiOsPrintf ("%4.4s", &Op->Named.Name);
476         break;
477
478     default:
479         break;
480     }
481
482     AcpiOsPrintf ("\n");
483     return (AE_OK);
484 }
485
486
487 /*******************************************************************************
488  *
489  * FUNCTION:    AcpiDmFindOrphanDescending
490  *
491  * PARAMETERS:  ASL_WALK_CALLBACK
492  *
493  * RETURN:      Status
494  *
495  * DESCRIPTION: Check namepath Ops for orphaned method invocations
496  *
497  * Note: Experimental.
498  *
499  ******************************************************************************/
500
501 static ACPI_STATUS
502 AcpiDmFindOrphanDescending (
503     ACPI_PARSE_OBJECT       *Op,
504     UINT32                  Level,
505     void                    *Context)
506 {
507     const ACPI_OPCODE_INFO  *OpInfo;
508     ACPI_PARSE_OBJECT       *ChildOp;
509     ACPI_PARSE_OBJECT       *NextOp;
510     ACPI_PARSE_OBJECT       *ParentOp;
511     UINT32                  ArgCount;
512
513
514     if (!Op)
515     {
516         return (AE_OK);
517     }
518
519     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
520
521     switch (Op->Common.AmlOpcode)
522     {
523 #ifdef ACPI_UNDER_DEVELOPMENT
524     case AML_ADD_OP:
525         ChildOp = Op->Common.Value.Arg;
526         if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
527             !ChildOp->Common.Node)
528         {
529             AcpiNsExternalizeName (ACPI_UINT32_MAX, ChildOp->Common.Value.String,
530                             NULL, &Path);
531             AcpiOsPrintf ("/* %-16s A-NAMEPATH: %s  */\n", Op->Common.AmlOpName, Path);
532             ACPI_FREE (Path);
533
534             NextOp = Op->Common.Next;
535             if (!NextOp)
536             {
537                 /* This NamePath has no args, assume it is an integer */
538
539                 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0);
540                 return (AE_OK);
541             }
542
543             ArgCount = AcpiDmInspectPossibleArgs (3, 1, NextOp);
544             AcpiOsPrintf ("/* A-CHILDREN: %d Actual %d */\n", ArgCount, AcpiDmCountChildren (Op));
545
546             if (ArgCount < 1)
547             {
548                 /* One Arg means this is just a Store(Name,Target) */
549
550                 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0);
551                 return (AE_OK);
552             }
553
554             AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount);
555         }
556         break;
557 #endif
558
559     case AML_STORE_OP:
560
561         ChildOp = Op->Common.Value.Arg;
562         if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
563             !ChildOp->Common.Node)
564         {
565             NextOp = Op->Common.Next;
566             if (!NextOp)
567             {
568                 /* This NamePath has no args, assume it is an integer */
569
570                 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0);
571                 return (AE_OK);
572             }
573
574             ArgCount = AcpiDmInspectPossibleArgs (2, 1, NextOp);
575             if (ArgCount <= 1)
576             {
577                 /* One Arg means this is just a Store(Name,Target) */
578
579                 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0);
580                 return (AE_OK);
581             }
582
583             AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount);
584         }
585         break;
586
587     case AML_INT_NAMEPATH_OP:
588
589         /* Must examine parent to see if this namepath is an argument */
590
591         ParentOp = Op->Common.Parent;
592         OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
593
594         if ((OpInfo->Class != AML_CLASS_EXECUTE) &&
595             (OpInfo->Class != AML_CLASS_CREATE) &&
596             (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
597             !Op->Common.Node)
598         {
599             ArgCount = AcpiDmInspectPossibleArgs (0, 0, Op->Common.Next);
600
601             /*
602              * Check if namepath is a predicate for if/while or lone parameter to
603              * a return.
604              */
605             if (ArgCount == 0)
606             {
607                 if (((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
608                      (ParentOp->Common.AmlOpcode == AML_WHILE_OP) ||
609                      (ParentOp->Common.AmlOpcode == AML_RETURN_OP)) &&
610
611                      /* And namepath is the first argument */
612                      (ParentOp->Common.Value.Arg == Op))
613                 {
614                     AcpiDmAddToExternalList (Op->Common.Value.String, ACPI_TYPE_INTEGER, 0);
615                     break;
616                 }
617             }
618
619             /*
620              * This is a standalone namestring (not a parameter to another
621              * operator) - it *must* be a method invocation, nothing else is
622              * grammatically possible.
623              */
624             AcpiDmAddToExternalList (Op->Common.Value.String, ACPI_TYPE_METHOD, ArgCount);
625
626         }
627         break;
628
629     default:
630         break;
631     }
632
633     return (AE_OK);
634 }
635
636
637 /*******************************************************************************
638  *
639  * FUNCTION:    AcpiDmLoadDescendingOp
640  *
641  * PARAMETERS:  ASL_WALK_CALLBACK
642  *
643  * RETURN:      Status
644  *
645  * DESCRIPTION: Descending handler for namespace control method object load
646  *
647  ******************************************************************************/
648
649 static ACPI_STATUS
650 AcpiDmLoadDescendingOp (
651     ACPI_PARSE_OBJECT       *Op,
652     UINT32                  Level,
653     void                    *Context)
654 {
655     ACPI_OP_WALK_INFO       *Info = Context;
656     const ACPI_OPCODE_INFO  *OpInfo;
657     ACPI_WALK_STATE         *WalkState;
658     ACPI_OBJECT_TYPE        ObjectType;
659     ACPI_STATUS             Status;
660     char                    *Path = NULL;
661     ACPI_PARSE_OBJECT       *NextOp;
662     ACPI_NAMESPACE_NODE     *Node;
663     char                    FieldPath[5];
664     BOOLEAN                 PreDefined = FALSE;
665     UINT8                   PreDefineIndex = 0;
666
667
668     WalkState = Info->WalkState;
669     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
670     ObjectType = OpInfo->ObjectType;
671     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
672
673     /* Only interested in operators that create new names */
674
675     if (!(OpInfo->Flags & AML_NAMED) &&
676         !(OpInfo->Flags & AML_CREATE))
677     {
678         goto Exit;
679     }
680
681     /* Get the NamePath from the appropriate place */
682
683     if (OpInfo->Flags & AML_NAMED)
684     {
685         /* For all named operators, get the new name */
686
687         Path = (char *) Op->Named.Path;
688
689         if (!Path && Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
690         {
691             *ACPI_CAST_PTR (UINT32, &FieldPath[0]) = Op->Named.Name;
692             FieldPath[4] = 0;
693             Path = FieldPath;
694         }
695     }
696     else if (OpInfo->Flags & AML_CREATE)
697     {
698         /* New name is the last child */
699
700         NextOp = Op->Common.Value.Arg;
701
702         while (NextOp->Common.Next)
703         {
704             NextOp = NextOp->Common.Next;
705         }
706         Path = NextOp->Common.Value.String;
707     }
708
709     if (!Path)
710     {
711         goto Exit;
712     }
713
714     /* Insert the name into the namespace */
715
716     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
717                 ACPI_IMODE_LOAD_PASS2, ACPI_NS_DONT_OPEN_SCOPE,
718                 WalkState, &Node);
719
720     Op->Common.Node = Node;
721
722     if (ACPI_SUCCESS (Status))
723     {
724         /* Check if it's a predefined node */
725
726         while (AcpiGbl_PreDefinedNames[PreDefineIndex].Name)
727         {
728             if (!ACPI_STRNCMP (Node->Name.Ascii,
729                 AcpiGbl_PreDefinedNames[PreDefineIndex].Name, 4))
730             {
731                 PreDefined = TRUE;
732                 break;
733             }
734
735             PreDefineIndex++;
736         }
737
738         /*
739          * Set node owner id if it satisfies all the following conditions:
740          * 1) Not a predefined node, _SB_ etc
741          * 2) Not the root node
742          * 3) Not a node created by Scope
743          */
744
745         if (!PreDefined && Node != AcpiGbl_RootNode &&
746             Op->Common.AmlOpcode != AML_SCOPE_OP)
747         {
748             Node->OwnerId = WalkState->OwnerId;
749         }
750     }
751
752
753 Exit:
754
755     if (AcpiNsOpensScope (ObjectType))
756     {
757         if (Op->Common.Node)
758         {
759             Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
760             if (ACPI_FAILURE (Status))
761             {
762                 return (Status);
763             }
764         }
765     }
766
767     return (AE_OK);
768 }
769
770
771 /*******************************************************************************
772  *
773  * FUNCTION:    AcpiDmXrefDescendingOp
774  *
775  * PARAMETERS:  ASL_WALK_CALLBACK
776  *
777  * RETURN:      Status
778  *
779  * DESCRIPTION: Descending handler for namespace cross reference
780  *
781  ******************************************************************************/
782
783 static ACPI_STATUS
784 AcpiDmXrefDescendingOp (
785     ACPI_PARSE_OBJECT       *Op,
786     UINT32                  Level,
787     void                    *Context)
788 {
789     ACPI_OP_WALK_INFO       *Info = Context;
790     const ACPI_OPCODE_INFO  *OpInfo;
791     ACPI_WALK_STATE         *WalkState;
792     ACPI_OBJECT_TYPE        ObjectType;
793     ACPI_OBJECT_TYPE        ObjectType2;
794     ACPI_STATUS             Status;
795     char                    *Path = NULL;
796     ACPI_PARSE_OBJECT       *NextOp;
797     ACPI_NAMESPACE_NODE     *Node;
798     ACPI_OPERAND_OBJECT     *Object;
799
800
801     WalkState = Info->WalkState;
802     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
803     ObjectType = OpInfo->ObjectType;
804     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
805
806     if ((!(OpInfo->Flags & AML_NAMED)) &&
807         (!(OpInfo->Flags & AML_CREATE)) &&
808         (Op->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
809     {
810         goto Exit;
811     }
812
813     /* Get the NamePath from the appropriate place */
814
815     if (OpInfo->Flags & AML_NAMED)
816     {
817         if ((Op->Common.AmlOpcode == AML_ALIAS_OP) ||
818             (Op->Common.AmlOpcode == AML_SCOPE_OP))
819         {
820             /*
821              * Only these two operators refer to an existing name,
822              * first argument
823              */
824             Path = (char *) Op->Named.Path;
825         }
826     }
827     else if (OpInfo->Flags & AML_CREATE)
828     {
829         /* Referenced Buffer Name is the first child */
830
831         NextOp = Op->Common.Value.Arg;
832         if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
833         {
834             Path = NextOp->Common.Value.String;
835         }
836     }
837     else
838     {
839         Path = Op->Common.Value.String;
840     }
841
842     if (!Path)
843     {
844         goto Exit;
845     }
846
847     /*
848      * Lookup the name in the namespace.  Name must exist at this point, or it
849      * is an invalid reference.
850      *
851      * The namespace is also used as a lookup table for references to resource
852      * descriptors and the fields within them.
853      */
854     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
855                 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
856                 WalkState, &Node);
857     if (ACPI_FAILURE (Status))
858     {
859         if (Status == AE_NOT_FOUND)
860         {
861             AcpiDmAddToExternalList (Path, (UINT8) ObjectType, 0);
862
863             /*
864              * We could install this into the namespace, but we catch duplicate
865              * externals when they are added to the list.
866              */
867 #if 0
868             Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
869                        ACPI_IMODE_LOAD_PASS1, ACPI_NS_DONT_OPEN_SCOPE,
870                        WalkState, &Node);
871 #endif
872         }
873     }
874
875     /*
876      * Found the node in external table, add it to external list
877      * Node->OwnerId == 0 indicates built-in ACPI Names, _OS_ etc
878      */
879     else if (Node->OwnerId && WalkState->OwnerId != Node->OwnerId)
880     {
881         ObjectType2 = ObjectType;
882
883         Object = AcpiNsGetAttachedObject (Node);
884         if (Object)
885         {
886             ObjectType2 = Object->Common.Type;
887         }
888
889         if (ObjectType2 == ACPI_TYPE_METHOD)
890         {
891             AcpiDmAddToExternalList (Path, ACPI_TYPE_METHOD,
892                 Object->Method.ParamCount);
893         }
894         else
895         {
896             AcpiDmAddToExternalList (Path, (UINT8) ObjectType2, 0);
897         }
898
899         Op->Common.Node = Node;
900     }
901     else
902     {
903         Op->Common.Node = Node;
904     }
905
906
907 Exit:
908     /* Open new scope if necessary */
909
910     if (AcpiNsOpensScope (ObjectType))
911     {
912         if (Op->Common.Node)
913         {
914             Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
915             if (ACPI_FAILURE (Status))
916             {
917                 return (Status);
918             }
919         }
920     }
921
922     return (AE_OK);
923 }
924
925
926 /*******************************************************************************
927  *
928  * FUNCTION:    AcpiDmResourceDescendingOp
929  *
930  * PARAMETERS:  ASL_WALK_CALLBACK
931  *
932  * RETURN:      None
933  *
934  * DESCRIPTION: Process one parse op during symbolic resource index conversion.
935  *
936  ******************************************************************************/
937
938 static ACPI_STATUS
939 AcpiDmResourceDescendingOp (
940     ACPI_PARSE_OBJECT       *Op,
941     UINT32                  Level,
942     void                    *Context)
943 {
944     ACPI_OP_WALK_INFO       *Info = Context;
945     const ACPI_OPCODE_INFO  *OpInfo;
946     ACPI_WALK_STATE         *WalkState;
947     ACPI_OBJECT_TYPE        ObjectType;
948     ACPI_STATUS             Status;
949
950
951     WalkState = Info->WalkState;
952     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
953
954     /* Open new scope if necessary */
955
956     ObjectType = OpInfo->ObjectType;
957     if (AcpiNsOpensScope (ObjectType))
958     {
959         if (Op->Common.Node)
960         {
961
962             Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
963             if (ACPI_FAILURE (Status))
964             {
965                 return (Status);
966             }
967         }
968     }
969
970     /*
971      * Check if this operator contains a reference to a resource descriptor.
972      * If so, convert the reference into a symbolic reference.
973      */
974     AcpiDmCheckResourceReference (Op, WalkState);
975     return (AE_OK);
976 }
977
978
979 /*******************************************************************************
980  *
981  * FUNCTION:    AcpiDmCommonAscendingOp
982  *
983  * PARAMETERS:  ASL_WALK_CALLBACK
984  *
985  * RETURN:      None
986  *
987  * DESCRIPTION: Ascending handler for combined parse/namespace walks. Closes
988  *              scope if necessary.
989  *
990  ******************************************************************************/
991
992 static ACPI_STATUS
993 AcpiDmCommonAscendingOp (
994     ACPI_PARSE_OBJECT       *Op,
995     UINT32                  Level,
996     void                    *Context)
997 {
998     ACPI_OP_WALK_INFO       *Info = Context;
999     const ACPI_OPCODE_INFO  *OpInfo;
1000     ACPI_OBJECT_TYPE        ObjectType;
1001
1002
1003     /* Close scope if necessary */
1004
1005     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1006     ObjectType = OpInfo->ObjectType;
1007     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1008
1009     if (AcpiNsOpensScope (ObjectType))
1010     {
1011         (void) AcpiDsScopeStackPop (Info->WalkState);
1012     }
1013
1014     return (AE_OK);
1015 }
1016
1017
1018 /*******************************************************************************
1019  *
1020  * FUNCTION:    AcpiDmInspectPossibleArgs
1021  *
1022  * PARAMETERS:  CurrentOpArgCount   - Which arg of the current op was the
1023  *                                    possible method invocation found
1024  *              TargetCount         - Number of targets (0,1,2) for this op
1025  *              Op                  - Parse op
1026  *
1027  * RETURN:      Status
1028  *
1029  * DESCRIPTION: Examine following args and next ops for possible arguments
1030  *              for an unrecognized method invocation.
1031  *
1032  ******************************************************************************/
1033
1034 static UINT32
1035 AcpiDmInspectPossibleArgs (
1036     UINT32                  CurrentOpArgCount,
1037     UINT32                  TargetCount,
1038     ACPI_PARSE_OBJECT       *Op)
1039 {
1040     const ACPI_OPCODE_INFO  *OpInfo;
1041     UINT32                  i;
1042     UINT32                  Last = 0;
1043     UINT32                  Lookahead;
1044
1045
1046     Lookahead = (ACPI_METHOD_NUM_ARGS + TargetCount) - CurrentOpArgCount;
1047
1048     /* Lookahead for the maximum number of possible arguments */
1049
1050     for (i = 0; i < Lookahead; i++)
1051     {
1052         if (!Op)
1053         {
1054             break;
1055         }
1056
1057         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1058
1059         /*
1060          * Any one of these operators is "very probably" not a method arg
1061          */
1062         if ((Op->Common.AmlOpcode == AML_STORE_OP) ||
1063             (Op->Common.AmlOpcode == AML_NOTIFY_OP))
1064         {
1065             break;
1066         }
1067
1068         if ((OpInfo->Class != AML_CLASS_EXECUTE) &&
1069             (OpInfo->Class != AML_CLASS_CONTROL))
1070         {
1071             Last = i+1;
1072         }
1073
1074         Op = Op->Common.Next;
1075     }
1076
1077     return (Last);
1078 }
1079
1080