xref: /freebsd/sys/contrib/dev/acpica/common/adwalk.c (revision ca86bcf2531c7b149c95244a67853d44323e7855)
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 - 2017, 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  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/amlcode.h>
156 #include <contrib/dev/acpica/include/acdisasm.h>
157 #include <contrib/dev/acpica/include/acdispat.h>
158 #include <contrib/dev/acpica/include/acnamesp.h>
159 #include <contrib/dev/acpica/include/acapps.h>
160 
161 
162 #define _COMPONENT          ACPI_TOOLS
163         ACPI_MODULE_NAME    ("adwalk")
164 
165 /*
166  * aslmap - opcode mappings and reserved method names
167  */
168 ACPI_OBJECT_TYPE
169 AslMapNamedOpcodeToDataType (
170     UINT16                  Opcode);
171 
172 /* Local prototypes */
173 
174 static ACPI_STATUS
175 AcpiDmFindOrphanDescending (
176     ACPI_PARSE_OBJECT       *Op,
177     UINT32                  Level,
178     void                    *Context);
179 
180 static ACPI_STATUS
181 AcpiDmDumpDescending (
182     ACPI_PARSE_OBJECT       *Op,
183     UINT32                  Level,
184     void                    *Context);
185 
186 static ACPI_STATUS
187 AcpiDmXrefDescendingOp (
188     ACPI_PARSE_OBJECT       *Op,
189     UINT32                  Level,
190     void                    *Context);
191 
192 static ACPI_STATUS
193 AcpiDmCommonAscendingOp (
194     ACPI_PARSE_OBJECT       *Op,
195     UINT32                  Level,
196     void                    *Context);
197 
198 static ACPI_STATUS
199 AcpiDmLoadDescendingOp (
200     ACPI_PARSE_OBJECT       *Op,
201     UINT32                  Level,
202     void                    *Context);
203 
204 static UINT32
205 AcpiDmInspectPossibleArgs (
206     UINT32                  CurrentOpArgCount,
207     UINT32                  TargetCount,
208     ACPI_PARSE_OBJECT       *Op);
209 
210 static ACPI_STATUS
211 AcpiDmResourceDescendingOp (
212     ACPI_PARSE_OBJECT       *Op,
213     UINT32                  Level,
214     void                    *Context);
215 
216 
217 /*******************************************************************************
218  *
219  * FUNCTION:    AcpiDmDumpTree
220  *
221  * PARAMETERS:  Origin              - Starting object
222  *
223  * RETURN:      None
224  *
225  * DESCRIPTION: Parse tree walk to format and output the nodes
226  *
227  ******************************************************************************/
228 
229 void
230 AcpiDmDumpTree (
231     ACPI_PARSE_OBJECT       *Origin)
232 {
233     ACPI_OP_WALK_INFO       Info;
234 
235 
236     if (!Origin)
237     {
238         return;
239     }
240 
241     AcpiOsPrintf ("/*\nAML Parse Tree\n\n");
242     Info.Flags = 0;
243     Info.Count = 0;
244     Info.Level = 0;
245     Info.WalkState = NULL;
246 
247     AcpiDmWalkParseTree (Origin, AcpiDmDumpDescending, NULL, &Info);
248     AcpiOsPrintf ("*/\n\n");
249 }
250 
251 
252 /*******************************************************************************
253  *
254  * FUNCTION:    AcpiDmFindOrphanMethods
255  *
256  * PARAMETERS:  Origin              - Starting object
257  *
258  * RETURN:      None
259  *
260  * DESCRIPTION: Parse tree walk to find "orphaned" method invocations -- methods
261  *              that are not resolved in the namespace
262  *
263  ******************************************************************************/
264 
265 void
266 AcpiDmFindOrphanMethods (
267     ACPI_PARSE_OBJECT       *Origin)
268 {
269     ACPI_OP_WALK_INFO       Info;
270 
271 
272     if (!Origin)
273     {
274         return;
275     }
276 
277     Info.Flags = 0;
278     Info.Level = 0;
279     Info.WalkState = NULL;
280 
281     AcpiDmWalkParseTree (Origin, AcpiDmFindOrphanDescending, NULL, &Info);
282 }
283 
284 
285 /*******************************************************************************
286  *
287  * FUNCTION:    AcpiDmFinishNamespaceLoad
288  *
289  * PARAMETERS:  ParseTreeRoot       - Root of the parse tree
290  *              NamespaceRoot       - Root of the internal namespace
291  *              OwnerId             - OwnerId of the table to be disassembled
292  *
293  * RETURN:      None
294  *
295  * DESCRIPTION: Load all namespace items that are created within control
296  *              methods. Used before namespace cross reference
297  *
298  ******************************************************************************/
299 
300 void
301 AcpiDmFinishNamespaceLoad (
302     ACPI_PARSE_OBJECT       *ParseTreeRoot,
303     ACPI_NAMESPACE_NODE     *NamespaceRoot,
304     ACPI_OWNER_ID           OwnerId)
305 {
306     ACPI_STATUS             Status;
307     ACPI_OP_WALK_INFO       Info;
308     ACPI_WALK_STATE         *WalkState;
309 
310 
311     if (!ParseTreeRoot)
312     {
313         return;
314     }
315 
316     /* Create and initialize a new walk state */
317 
318     WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
319     if (!WalkState)
320     {
321         return;
322     }
323 
324     Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
325         WalkState);
326     if (ACPI_FAILURE (Status))
327     {
328         return;
329     }
330 
331     Info.Flags = 0;
332     Info.Level = 0;
333     Info.WalkState = WalkState;
334 
335     AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmLoadDescendingOp,
336         AcpiDmCommonAscendingOp, &Info);
337     ACPI_FREE (WalkState);
338 }
339 
340 
341 /*******************************************************************************
342  *
343  * FUNCTION:    AcpiDmCrossReferenceNamespace
344  *
345  * PARAMETERS:  ParseTreeRoot       - Root of the parse tree
346  *              NamespaceRoot       - Root of the internal namespace
347  *              OwnerId             - OwnerId of the table to be disassembled
348  *
349  * RETURN:      None
350  *
351  * DESCRIPTION: Cross reference the namespace to create externals
352  *
353  ******************************************************************************/
354 
355 void
356 AcpiDmCrossReferenceNamespace (
357     ACPI_PARSE_OBJECT       *ParseTreeRoot,
358     ACPI_NAMESPACE_NODE     *NamespaceRoot,
359     ACPI_OWNER_ID           OwnerId)
360 {
361     ACPI_STATUS             Status;
362     ACPI_OP_WALK_INFO       Info;
363     ACPI_WALK_STATE         *WalkState;
364 
365 
366     if (!ParseTreeRoot)
367     {
368         return;
369     }
370 
371     /* Create and initialize a new walk state */
372 
373     WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
374     if (!WalkState)
375     {
376         return;
377     }
378 
379     Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
380         WalkState);
381     if (ACPI_FAILURE (Status))
382     {
383         return;
384     }
385 
386     Info.Flags = 0;
387     Info.Level = 0;
388     Info.WalkState = WalkState;
389 
390     AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmXrefDescendingOp,
391         AcpiDmCommonAscendingOp, &Info);
392     ACPI_FREE (WalkState);
393 }
394 
395 
396 /*******************************************************************************
397  *
398  * FUNCTION:    AcpiDmConvertResourceIndexes
399  *
400  * PARAMETERS:  ParseTreeRoot       - Root of the parse tree
401  *              NamespaceRoot       - Root of the internal namespace
402  *
403  * RETURN:      None
404  *
405  * DESCRIPTION: Convert fixed-offset references to resource descriptors to
406  *              symbolic references. Should only be called after namespace has
407  *              been cross referenced.
408  *
409  ******************************************************************************/
410 
411 void
412 AcpiDmConvertResourceIndexes (
413     ACPI_PARSE_OBJECT       *ParseTreeRoot,
414     ACPI_NAMESPACE_NODE     *NamespaceRoot)
415 {
416     ACPI_STATUS             Status;
417     ACPI_OP_WALK_INFO       Info;
418     ACPI_WALK_STATE         *WalkState;
419 
420 
421     if (!ParseTreeRoot)
422     {
423         return;
424     }
425 
426     /* Create and initialize a new walk state */
427 
428     WalkState = AcpiDsCreateWalkState (0, ParseTreeRoot, NULL, NULL);
429     if (!WalkState)
430     {
431         return;
432     }
433 
434     Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
435         WalkState);
436     if (ACPI_FAILURE (Status))
437     {
438         ACPI_FREE (WalkState);
439         return;
440     }
441 
442     Info.Flags = 0;
443     Info.Level = 0;
444     Info.WalkState = WalkState;
445 
446     AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmResourceDescendingOp,
447         AcpiDmCommonAscendingOp, &Info);
448     ACPI_FREE (WalkState);
449     return;
450 }
451 
452 
453 /*******************************************************************************
454  *
455  * FUNCTION:    AcpiDmDumpDescending
456  *
457  * PARAMETERS:  ASL_WALK_CALLBACK
458  *
459  * RETURN:      Status
460  *
461  * DESCRIPTION: Format and print contents of one parse Op.
462  *
463  ******************************************************************************/
464 
465 static ACPI_STATUS
466 AcpiDmDumpDescending (
467     ACPI_PARSE_OBJECT       *Op,
468     UINT32                  Level,
469     void                    *Context)
470 {
471     ACPI_OP_WALK_INFO       *Info = Context;
472     char                    *Path;
473 
474 
475     if (!Op)
476     {
477         return (AE_OK);
478     }
479 
480     /* Most of the information (count, level, name) here */
481 
482     Info->Count++;
483     AcpiOsPrintf ("% 5d [%2.2d] ", Info->Count, Level);
484     AcpiDmIndent (Level);
485     AcpiOsPrintf ("%-28s", AcpiPsGetOpcodeName (Op->Common.AmlOpcode));
486 
487     /* Extra info is helpful */
488 
489     switch (Op->Common.AmlOpcode)
490     {
491     case AML_BYTE_OP:
492 
493         AcpiOsPrintf ("%2.2X", (UINT32) Op->Common.Value.Integer);
494         break;
495 
496     case AML_WORD_OP:
497 
498         AcpiOsPrintf ("%4.4X", (UINT32) Op->Common.Value.Integer);
499         break;
500 
501     case AML_DWORD_OP:
502 
503         AcpiOsPrintf ("%8.8X", (UINT32) Op->Common.Value.Integer);
504         break;
505 
506     case AML_QWORD_OP:
507 
508         AcpiOsPrintf ("%8.8X%8.8X", ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));
509         break;
510 
511     case AML_INT_NAMEPATH_OP:
512 
513         if (Op->Common.Value.String)
514         {
515             AcpiNsExternalizeName (ACPI_UINT32_MAX, Op->Common.Value.String,
516                 NULL, &Path);
517             AcpiOsPrintf ("%s %p", Path, Op->Common.Node);
518             ACPI_FREE (Path);
519         }
520         else
521         {
522             AcpiOsPrintf ("[NULL]");
523         }
524         break;
525 
526     case AML_NAME_OP:
527     case AML_METHOD_OP:
528     case AML_DEVICE_OP:
529     case AML_INT_NAMEDFIELD_OP:
530 
531         AcpiOsPrintf ("%4.4s", ACPI_CAST_PTR (char, &Op->Named.Name));
532         break;
533 
534     default:
535 
536         break;
537     }
538 
539     AcpiOsPrintf ("\n");
540     return (AE_OK);
541 }
542 
543 
544 /*******************************************************************************
545  *
546  * FUNCTION:    AcpiDmFindOrphanDescending
547  *
548  * PARAMETERS:  ASL_WALK_CALLBACK
549  *
550  * RETURN:      Status
551  *
552  * DESCRIPTION: Check namepath Ops for orphaned method invocations
553  *
554  * Note: Parts of this are experimental, under possible further development.
555  *
556  ******************************************************************************/
557 
558 static ACPI_STATUS
559 AcpiDmFindOrphanDescending (
560     ACPI_PARSE_OBJECT       *Op,
561     UINT32                  Level,
562     void                    *Context)
563 {
564     const ACPI_OPCODE_INFO  *OpInfo;
565     ACPI_PARSE_OBJECT       *ChildOp;
566     ACPI_PARSE_OBJECT       *NextOp;
567     ACPI_PARSE_OBJECT       *ParentOp;
568     UINT32                  ArgCount;
569 
570 
571     if (!Op)
572     {
573         return (AE_OK);
574     }
575 
576     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
577 
578     switch (Op->Common.AmlOpcode)
579     {
580 #ifdef ACPI_UNDER_DEVELOPMENT
581     case AML_ADD_OP:
582 
583         ChildOp = Op->Common.Value.Arg;
584         if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
585             !ChildOp->Common.Node)
586         {
587             AcpiNsExternalizeName (ACPI_UINT32_MAX, ChildOp->Common.Value.String,
588                 NULL, &Path);
589             AcpiOsPrintf ("/* %-16s A-NAMEPATH: %s  */\n",
590                 Op->Common.AmlOpName, Path);
591             ACPI_FREE (Path);
592 
593             NextOp = Op->Common.Next;
594             if (!NextOp)
595             {
596                 /* This NamePath has no args, assume it is an integer */
597 
598                 AcpiDmAddOpToExternalList (ChildOp,
599                     ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
600                 return (AE_OK);
601             }
602 
603             ArgCount = AcpiDmInspectPossibleArgs (3, 1, NextOp);
604             AcpiOsPrintf ("/* A-CHILDREN: %u Actual %u */\n",
605                 ArgCount, AcpiDmCountChildren (Op));
606 
607             if (ArgCount < 1)
608             {
609                 /* One Arg means this is just a Store(Name,Target) */
610 
611                 AcpiDmAddOpToExternalList (ChildOp,
612                     ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
613                 return (AE_OK);
614             }
615 
616             AcpiDmAddOpToExternalList (ChildOp,
617                 ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
618         }
619         break;
620 
621 #endif
622 
623     case AML_STORE_OP:
624 
625         ChildOp = Op->Common.Value.Arg;
626         if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
627             !ChildOp->Common.Node)
628         {
629             NextOp = Op->Common.Next;
630             if (!NextOp)
631             {
632                 /* This NamePath has no args, assume it is an integer */
633 
634                 AcpiDmAddOpToExternalList (ChildOp,
635                     ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
636                 return (AE_OK);
637             }
638 
639             ArgCount = AcpiDmInspectPossibleArgs (2, 1, NextOp);
640             if (ArgCount <= 1)
641             {
642                 /* One Arg means this is just a Store(Name,Target) */
643 
644                 AcpiDmAddOpToExternalList (ChildOp,
645                     ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, ArgCount, 0);
646                 return (AE_OK);
647             }
648 
649             AcpiDmAddOpToExternalList (ChildOp,
650                 ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
651         }
652         break;
653 
654     case AML_INT_NAMEPATH_OP:
655 
656         /* Must examine parent to see if this namepath is an argument */
657 
658         ParentOp = Op->Common.Parent;
659         OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
660 
661         if ((OpInfo->Class != AML_CLASS_EXECUTE) &&
662             (OpInfo->Class != AML_CLASS_CREATE) &&
663             (OpInfo->ObjectType != ACPI_TYPE_LOCAL_ALIAS) &&
664             (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
665             !Op->Common.Node)
666         {
667             ArgCount = AcpiDmInspectPossibleArgs (0, 0, Op);
668 
669             /*
670              * Check if namepath is a predicate for if/while or lone parameter to
671              * a return.
672              */
673             if (ArgCount == 0)
674             {
675                 if (((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
676                      (ParentOp->Common.AmlOpcode == AML_WHILE_OP) ||
677                      (ParentOp->Common.AmlOpcode == AML_RETURN_OP)) &&
678 
679                      /* And namepath is the first argument */
680                      (ParentOp->Common.Value.Arg == Op))
681                 {
682                     AcpiDmAddOpToExternalList (Op,
683                         Op->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
684                     break;
685                 }
686             }
687 
688             /*
689              * This is a standalone namestring (not a parameter to another
690              * operator) - it *must* be a method invocation, nothing else is
691              * grammatically possible.
692              */
693             AcpiDmAddOpToExternalList (Op,
694                 Op->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
695         }
696         break;
697 
698     default:
699 
700         break;
701     }
702 
703     return (AE_OK);
704 }
705 
706 
707 /*******************************************************************************
708  *
709  * FUNCTION:    AcpiDmLoadDescendingOp
710  *
711  * PARAMETERS:  ASL_WALK_CALLBACK
712  *
713  * RETURN:      Status
714  *
715  * DESCRIPTION: Descending handler for namespace control method object load
716  *
717  ******************************************************************************/
718 
719 static ACPI_STATUS
720 AcpiDmLoadDescendingOp (
721     ACPI_PARSE_OBJECT       *Op,
722     UINT32                  Level,
723     void                    *Context)
724 {
725     ACPI_OP_WALK_INFO       *Info = Context;
726     const ACPI_OPCODE_INFO  *OpInfo;
727     ACPI_WALK_STATE         *WalkState;
728     ACPI_OBJECT_TYPE        ObjectType;
729     ACPI_STATUS             Status;
730     char                    *Path = NULL;
731     ACPI_PARSE_OBJECT       *NextOp;
732     ACPI_NAMESPACE_NODE     *Node;
733     char                    FieldPath[5];
734     BOOLEAN                 PreDefined = FALSE;
735     UINT8                   PreDefineIndex = 0;
736 
737 
738     WalkState = Info->WalkState;
739     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
740     ObjectType = OpInfo->ObjectType;
741     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
742 
743     /* Only interested in operators that create new names */
744 
745     if (!(OpInfo->Flags & AML_NAMED) &&
746         !(OpInfo->Flags & AML_CREATE))
747     {
748         goto Exit;
749     }
750 
751     /* Get the NamePath from the appropriate place */
752 
753     if (OpInfo->Flags & AML_NAMED)
754     {
755         /* For all named operators, get the new name */
756 
757         Path = (char *) Op->Named.Path;
758 
759         if (!Path && Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
760         {
761             *ACPI_CAST_PTR (UINT32, &FieldPath[0]) = Op->Named.Name;
762             FieldPath[4] = 0;
763             Path = FieldPath;
764         }
765     }
766     else if (OpInfo->Flags & AML_CREATE)
767     {
768         /* New name is the last child */
769 
770         NextOp = Op->Common.Value.Arg;
771 
772         while (NextOp->Common.Next)
773         {
774             NextOp = NextOp->Common.Next;
775         }
776 
777         Path = NextOp->Common.Value.String;
778     }
779 
780     if (!Path)
781     {
782         goto Exit;
783     }
784 
785     /* Insert the name into the namespace */
786 
787     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
788         ACPI_IMODE_LOAD_PASS2, ACPI_NS_DONT_OPEN_SCOPE,
789         WalkState, &Node);
790 
791     Op->Common.Node = Node;
792 
793     if (ACPI_SUCCESS (Status))
794     {
795         /* Check if it's a predefined node */
796 
797         while (AcpiGbl_PreDefinedNames[PreDefineIndex].Name)
798         {
799             if (ACPI_COMPARE_NAME (Node->Name.Ascii,
800                 AcpiGbl_PreDefinedNames[PreDefineIndex].Name))
801             {
802                 PreDefined = TRUE;
803                 break;
804             }
805 
806             PreDefineIndex++;
807         }
808 
809         /*
810          * Set node owner id if it satisfies all the following conditions:
811          * 1) Not a predefined node, _SB_ etc
812          * 2) Not the root node
813          * 3) Not a node created by Scope
814          */
815 
816         if (!PreDefined && Node != AcpiGbl_RootNode &&
817             Op->Common.AmlOpcode != AML_SCOPE_OP)
818         {
819             Node->OwnerId = WalkState->OwnerId;
820         }
821     }
822 
823 
824 Exit:
825 
826     if (AcpiNsOpensScope (ObjectType))
827     {
828         if (Op->Common.Node)
829         {
830             Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
831                 WalkState);
832             if (ACPI_FAILURE (Status))
833             {
834                 return (Status);
835             }
836         }
837     }
838 
839     return (AE_OK);
840 }
841 
842 
843 /*******************************************************************************
844  *
845  * FUNCTION:    AcpiDmXrefDescendingOp
846  *
847  * PARAMETERS:  ASL_WALK_CALLBACK
848  *
849  * RETURN:      Status
850  *
851  * DESCRIPTION: Descending handler for namespace cross reference
852  *
853  ******************************************************************************/
854 
855 static ACPI_STATUS
856 AcpiDmXrefDescendingOp (
857     ACPI_PARSE_OBJECT       *Op,
858     UINT32                  Level,
859     void                    *Context)
860 {
861     ACPI_OP_WALK_INFO       *Info = Context;
862     const ACPI_OPCODE_INFO  *OpInfo;
863     ACPI_WALK_STATE         *WalkState;
864     ACPI_OBJECT_TYPE        ObjectType;
865     ACPI_OBJECT_TYPE        ObjectType2;
866     ACPI_STATUS             Status;
867     char                    *Path = NULL;
868     ACPI_PARSE_OBJECT       *NextOp;
869     ACPI_NAMESPACE_NODE     *Node;
870     ACPI_OPERAND_OBJECT     *Object;
871     UINT32                  ParamCount = 0;
872     char                    *Pathname;
873     UINT16                  Flags = 0;
874 
875 
876     WalkState = Info->WalkState;
877     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
878     ObjectType = OpInfo->ObjectType;
879     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
880 
881     if ((!(OpInfo->Flags & AML_NAMED)) &&
882         (!(OpInfo->Flags & AML_CREATE)) &&
883         (Op->Common.AmlOpcode != AML_INT_NAMEPATH_OP) &&
884         (Op->Common.AmlOpcode != AML_NOTIFY_OP))
885     {
886         goto Exit;
887     }
888     else if (Op->Common.Parent &&
889              Op->Common.Parent->Common.AmlOpcode == AML_EXTERNAL_OP)
890     {
891         /* External() NamePath */
892 
893         Path = Op->Common.Value.String;
894         ObjectType = (ACPI_OBJECT_TYPE) Op->Common.Next->Common.Value.Integer;
895         if (ObjectType == ACPI_TYPE_METHOD)
896         {
897             ParamCount = (UINT32)
898                 Op->Common.Next->Common.Next->Common.Value.Integer;
899         }
900 
901         Flags |= ACPI_EXT_RESOLVED_REFERENCE | ACPI_EXT_ORIGIN_FROM_OPCODE;
902         AcpiDmAddOpToExternalList (Op, Path,
903             (UINT8) ObjectType, ParamCount, Flags);
904 
905         goto Exit;
906     }
907 
908     /* Get the NamePath from the appropriate place */
909 
910     if (OpInfo->Flags & AML_NAMED)
911     {
912         /*
913          * Only these two operators (Alias, Scope) refer to an existing
914          * name, it is the first argument
915          */
916         if (Op->Common.AmlOpcode == AML_ALIAS_OP)
917         {
918             ObjectType = ACPI_TYPE_ANY;
919 
920             NextOp = Op->Common.Value.Arg;
921             NextOp = NextOp->Common.Value.Arg;
922             if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
923             {
924                 Path = NextOp->Common.Value.String;
925             }
926         }
927         else if (Op->Common.AmlOpcode == AML_SCOPE_OP)
928         {
929             Path = (char *) Op->Named.Path;
930         }
931     }
932     else if (OpInfo->Flags & AML_CREATE)
933     {
934         /* Referenced Buffer Name is the first child */
935 
936         ObjectType = ACPI_TYPE_BUFFER; /* Change from TYPE_BUFFER_FIELD */
937 
938         NextOp = Op->Common.Value.Arg;
939         if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
940         {
941             Path = NextOp->Common.Value.String;
942         }
943     }
944     else if (Op->Common.AmlOpcode == AML_NOTIFY_OP)
945     {
946         Path = Op->Common.Value.Arg->Asl.Value.String;
947     }
948     else
949     {
950         Path = Op->Common.Value.String;
951     }
952 
953     if (!Path)
954     {
955         goto Exit;
956     }
957 
958     /*
959      * Lookup the name in the namespace. Name must exist at this point, or it
960      * is an invalid reference.
961      *
962      * The namespace is also used as a lookup table for references to resource
963      * descriptors and the fields within them.
964      */
965     Node = NULL;
966     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
967         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
968         WalkState, &Node);
969 
970     if (ACPI_SUCCESS (Status) && (Node->Flags & ANOBJ_IS_EXTERNAL))
971     {
972         /* Node was created by an External() statement */
973 
974         Status = AE_NOT_FOUND;
975     }
976 
977     if (ACPI_FAILURE (Status))
978     {
979         if (Status == AE_NOT_FOUND)
980         {
981             /*
982              * Add this symbol as an external declaration, except if the
983              * parent is a CondRefOf operator. For this operator, we do not
984              * need an external, nor do we want one, since this can cause
985              * disassembly problems if the symbol is actually a control
986              * method.
987              */
988             if (!(Op->Asl.Parent &&
989                 (Op->Asl.Parent->Asl.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)))
990             {
991                 if (Node)
992                 {
993                     AcpiDmAddNodeToExternalList (Node,
994                         (UINT8) ObjectType, 7, Flags);
995                 }
996                 else
997                 {
998                     AcpiDmAddOpToExternalList (Op, Path,
999                         (UINT8) ObjectType, 7, Flags);
1000                 }
1001             }
1002         }
1003     }
1004 
1005     /*
1006      * Found the node, but check if it came from an external table.
1007      * Add it to external list. Note: Node->OwnerId == 0 indicates
1008      * one of the built-in ACPI Names (_OS_ etc.) which can safely
1009      * be ignored.
1010      */
1011     else if (Node->OwnerId &&
1012             (WalkState->OwnerId != Node->OwnerId))
1013     {
1014         ObjectType2 = ObjectType;
1015 
1016         Object = AcpiNsGetAttachedObject (Node);
1017         if (Object)
1018         {
1019             ObjectType2 = Object->Common.Type;
1020             if (ObjectType2 == ACPI_TYPE_METHOD)
1021             {
1022                 ParamCount = Object->Method.ParamCount;
1023             }
1024         }
1025 
1026         Pathname = AcpiNsGetExternalPathname (Node);
1027         if (!Pathname)
1028         {
1029             return (AE_NO_MEMORY);
1030         }
1031 
1032         AcpiDmAddNodeToExternalList (Node, (UINT8) ObjectType2,
1033             ParamCount, ACPI_EXT_RESOLVED_REFERENCE);
1034 
1035         ACPI_FREE (Pathname);
1036         Op->Common.Node = Node;
1037     }
1038     else
1039     {
1040         Op->Common.Node = Node;
1041     }
1042 
1043 
1044 Exit:
1045     /* Open new scope if necessary */
1046 
1047     if (AcpiNsOpensScope (ObjectType))
1048     {
1049         if (Op->Common.Node)
1050         {
1051             Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
1052                 WalkState);
1053             if (ACPI_FAILURE (Status))
1054             {
1055                 return (Status);
1056             }
1057         }
1058     }
1059 
1060     return (AE_OK);
1061 }
1062 
1063 
1064 /*******************************************************************************
1065  *
1066  * FUNCTION:    AcpiDmResourceDescendingOp
1067  *
1068  * PARAMETERS:  ASL_WALK_CALLBACK
1069  *
1070  * RETURN:      None
1071  *
1072  * DESCRIPTION: Process one parse op during symbolic resource index conversion.
1073  *
1074  ******************************************************************************/
1075 
1076 static ACPI_STATUS
1077 AcpiDmResourceDescendingOp (
1078     ACPI_PARSE_OBJECT       *Op,
1079     UINT32                  Level,
1080     void                    *Context)
1081 {
1082     ACPI_OP_WALK_INFO       *Info = Context;
1083     const ACPI_OPCODE_INFO  *OpInfo;
1084     ACPI_WALK_STATE         *WalkState;
1085     ACPI_OBJECT_TYPE        ObjectType;
1086     ACPI_STATUS             Status;
1087 
1088 
1089     WalkState = Info->WalkState;
1090     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1091 
1092     /* Open new scope if necessary */
1093 
1094     ObjectType = OpInfo->ObjectType;
1095     if (AcpiNsOpensScope (ObjectType))
1096     {
1097         if (Op->Common.Node)
1098         {
1099 
1100             Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
1101                 WalkState);
1102             if (ACPI_FAILURE (Status))
1103             {
1104                 return (Status);
1105             }
1106         }
1107     }
1108 
1109     /*
1110      * Check if this operator contains a reference to a resource descriptor.
1111      * If so, convert the reference into a symbolic reference.
1112      */
1113     AcpiDmCheckResourceReference (Op, WalkState);
1114     return (AE_OK);
1115 }
1116 
1117 
1118 /*******************************************************************************
1119  *
1120  * FUNCTION:    AcpiDmCommonAscendingOp
1121  *
1122  * PARAMETERS:  ASL_WALK_CALLBACK
1123  *
1124  * RETURN:      None
1125  *
1126  * DESCRIPTION: Ascending handler for combined parse/namespace walks. Closes
1127  *              scope if necessary.
1128  *
1129  ******************************************************************************/
1130 
1131 static ACPI_STATUS
1132 AcpiDmCommonAscendingOp (
1133     ACPI_PARSE_OBJECT       *Op,
1134     UINT32                  Level,
1135     void                    *Context)
1136 {
1137     ACPI_OP_WALK_INFO       *Info = Context;
1138     const ACPI_OPCODE_INFO  *OpInfo;
1139     ACPI_OBJECT_TYPE        ObjectType;
1140 
1141 
1142     /* Close scope if necessary */
1143 
1144     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1145     ObjectType = OpInfo->ObjectType;
1146     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1147 
1148     if (AcpiNsOpensScope (ObjectType))
1149     {
1150         (void) AcpiDsScopeStackPop (Info->WalkState);
1151     }
1152 
1153     return (AE_OK);
1154 }
1155 
1156 
1157 /*******************************************************************************
1158  *
1159  * FUNCTION:    AcpiDmInspectPossibleArgs
1160  *
1161  * PARAMETERS:  CurrentOpArgCount   - Which arg of the current op was the
1162  *                                    possible method invocation found
1163  *              TargetCount         - Number of targets (0,1,2) for this op
1164  *              Op                  - Parse op
1165  *
1166  * RETURN:      Status
1167  *
1168  * DESCRIPTION: Examine following args and next ops for possible arguments
1169  *              for an unrecognized method invocation.
1170  *
1171  ******************************************************************************/
1172 
1173 static UINT32
1174 AcpiDmInspectPossibleArgs (
1175     UINT32                  CurrentOpArgCount,
1176     UINT32                  TargetCount,
1177     ACPI_PARSE_OBJECT       *Op)
1178 {
1179     const ACPI_OPCODE_INFO  *OpInfo;
1180     UINT32                  i;
1181     UINT32                  ArgumentCount = 0;
1182     ACPI_PARSE_OBJECT       *NextOp;
1183     ACPI_PARSE_OBJECT       *ExecuteOp;
1184 
1185 
1186     if (!Op)
1187     {
1188         return (0);
1189     }
1190 
1191     /* Lookahead for the maximum number of possible arguments */
1192 
1193     NextOp = Op->Common.Next;
1194 
1195     for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && NextOp; i++)
1196     {
1197         OpInfo = AcpiPsGetOpcodeInfo (NextOp->Common.AmlOpcode);
1198 
1199         /* Any one of these operators is "very probably" not a method arg */
1200 
1201         if ((NextOp->Common.AmlOpcode == AML_STORE_OP) ||
1202             (NextOp->Common.AmlOpcode == AML_NOTIFY_OP) ||
1203             (OpInfo->Class == AML_CLASS_CONTROL) ||
1204             (OpInfo->Class == AML_CLASS_CREATE) ||
1205             (OpInfo->Class == AML_CLASS_NAMED_OBJECT))
1206         {
1207             break;
1208         }
1209 
1210         if (OpInfo->Class == AML_CLASS_EXECUTE)
1211         {
1212             /* Probable that this is method arg if there is no target */
1213 
1214             ExecuteOp = NextOp->Common.Value.Arg;
1215             while (ExecuteOp)
1216             {
1217                 if ((ExecuteOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
1218                     (ExecuteOp->Common.Value.Arg == NULL))
1219                 {
1220                     /* No target, could be a method arg */
1221 
1222                     break;
1223                 }
1224 
1225                 if (NextOp->Common.AmlOpcode == AML_REF_OF_OP)
1226                 {
1227                     break;
1228                 }
1229 
1230                 ExecuteOp = ExecuteOp->Common.Next;
1231             }
1232 
1233             if (!ExecuteOp)
1234             {
1235                 /* Has a target, not method arg */
1236 
1237                 return (ArgumentCount);
1238             }
1239         }
1240 
1241         ArgumentCount++;
1242         NextOp = NextOp->Common.Next;
1243     }
1244 
1245     return (ArgumentCount);
1246 }
1247