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