Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / source / common / adwalk.c
blob6463ee51e1eabe2b2cb416d0360339133f105253
1 /******************************************************************************
3 * Module Name: adwalk - Application-level disassembler parse tree walk routines
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
14 * 2. License
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.
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
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;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
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.
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.
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.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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.
80 * 4. Disclaimer and Export Compliance
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.
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.
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
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.
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.
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.
150 *****************************************************************************/
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"
162 #define _COMPONENT ACPI_TOOLS
163 ACPI_MODULE_NAME ("adwalk")
166 * aslmap - opcode mappings and reserved method names
168 ACPI_OBJECT_TYPE
169 AslMapNamedOpcodeToDataType (
170 UINT16 Opcode);
172 /* Local prototypes */
174 static ACPI_STATUS
175 AcpiDmFindOrphanDescending (
176 ACPI_PARSE_OBJECT *Op,
177 UINT32 Level,
178 void *Context);
180 static ACPI_STATUS
181 AcpiDmDumpDescending (
182 ACPI_PARSE_OBJECT *Op,
183 UINT32 Level,
184 void *Context);
186 static ACPI_STATUS
187 AcpiDmXrefDescendingOp (
188 ACPI_PARSE_OBJECT *Op,
189 UINT32 Level,
190 void *Context);
192 static ACPI_STATUS
193 AcpiDmCommonAscendingOp (
194 ACPI_PARSE_OBJECT *Op,
195 UINT32 Level,
196 void *Context);
198 static ACPI_STATUS
199 AcpiDmLoadDescendingOp (
200 ACPI_PARSE_OBJECT *Op,
201 UINT32 Level,
202 void *Context);
204 static UINT32
205 AcpiDmInspectPossibleArgs (
206 UINT32 CurrentOpArgCount,
207 UINT32 TargetCount,
208 ACPI_PARSE_OBJECT *Op);
210 static ACPI_STATUS
211 AcpiDmCommonDescendingOp (
212 ACPI_PARSE_OBJECT *Op,
213 UINT32 Level,
214 void *Context);
216 static ACPI_STATUS
217 AcpiDmProcessResourceDescriptors (
218 ACPI_PARSE_OBJECT *Op,
219 UINT32 Level,
220 void *Context);
222 /*******************************************************************************
224 * FUNCTION: AcpiDmDumpTree
226 * PARAMETERS: Origin - Starting object
228 * RETURN: None
230 * DESCRIPTION: Parse tree walk to format and output the nodes
232 ******************************************************************************/
234 void
235 AcpiDmDumpTree (
236 ACPI_PARSE_OBJECT *Origin)
238 ACPI_OP_WALK_INFO Info;
241 if (!Origin)
243 return;
246 AcpiOsPrintf ("/*\nAML Parse Tree\n\n");
247 Info.Flags = 0;
248 Info.Count = 0;
249 Info.Level = 0;
250 Info.WalkState = NULL;
252 AcpiDmWalkParseTree (Origin, AcpiDmDumpDescending, NULL, &Info);
253 AcpiOsPrintf ("*/\n\n");
257 /*******************************************************************************
259 * FUNCTION: AcpiDmFindOrphanMethods
261 * PARAMETERS: Origin - Starting object
263 * RETURN: None
265 * DESCRIPTION: Parse tree walk to find "orphaned" method invocations -- methods
266 * that are not resolved in the namespace
268 ******************************************************************************/
270 void
271 AcpiDmFindOrphanMethods (
272 ACPI_PARSE_OBJECT *Origin)
274 ACPI_OP_WALK_INFO Info;
277 if (!Origin)
279 return;
282 Info.Flags = 0;
283 Info.Level = 0;
284 Info.WalkState = NULL;
286 AcpiDmWalkParseTree (Origin, AcpiDmFindOrphanDescending, NULL, &Info);
290 /*******************************************************************************
292 * FUNCTION: AcpiDmFinishNamespaceLoad
294 * PARAMETERS: ParseTreeRoot - Root of the parse tree
295 * NamespaceRoot - Root of the internal namespace
296 * OwnerId - OwnerId of the table to be disassembled
298 * RETURN: None
300 * DESCRIPTION: Load all namespace items that are created within control
301 * methods. Used before namespace cross reference
303 ******************************************************************************/
305 void
306 AcpiDmFinishNamespaceLoad (
307 ACPI_PARSE_OBJECT *ParseTreeRoot,
308 ACPI_NAMESPACE_NODE *NamespaceRoot,
309 ACPI_OWNER_ID OwnerId)
311 ACPI_STATUS Status;
312 ACPI_OP_WALK_INFO Info;
313 ACPI_WALK_STATE *WalkState;
316 if (!ParseTreeRoot)
318 return;
321 /* Create and initialize a new walk state */
323 WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
324 if (!WalkState)
326 return;
329 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
330 WalkState);
331 if (ACPI_FAILURE (Status))
333 return;
336 Info.Flags = 0;
337 Info.Level = 0;
338 Info.WalkState = WalkState;
340 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmLoadDescendingOp,
341 AcpiDmCommonAscendingOp, &Info);
342 ACPI_FREE (WalkState);
346 /*******************************************************************************
348 * FUNCTION: AcpiDmCrossReferenceNamespace
350 * PARAMETERS: ParseTreeRoot - Root of the parse tree
351 * NamespaceRoot - Root of the internal namespace
352 * OwnerId - OwnerId of the table to be disassembled
354 * RETURN: None
356 * DESCRIPTION: Cross reference the namespace to create externals
358 ******************************************************************************/
360 void
361 AcpiDmCrossReferenceNamespace (
362 ACPI_PARSE_OBJECT *ParseTreeRoot,
363 ACPI_NAMESPACE_NODE *NamespaceRoot,
364 ACPI_OWNER_ID OwnerId)
366 ACPI_STATUS Status;
367 ACPI_OP_WALK_INFO Info;
368 ACPI_WALK_STATE *WalkState;
371 if (!ParseTreeRoot)
373 return;
376 /* Create and initialize a new walk state */
378 WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
379 if (!WalkState)
381 return;
384 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
385 WalkState);
386 if (ACPI_FAILURE (Status))
388 return;
391 Info.Flags = 0;
392 Info.Level = 0;
393 Info.WalkState = WalkState;
395 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmXrefDescendingOp,
396 AcpiDmCommonAscendingOp, &Info);
397 ACPI_FREE (WalkState);
401 /*******************************************************************************
403 * FUNCTION: AcpiDmConvertParseObjects
405 * PARAMETERS: ParseTreeRoot - Root of the parse tree
406 * NamespaceRoot - Root of the internal namespace
408 * RETURN: None
410 * DESCRIPTION: Begin parse tree walk to perform conversions needed for
411 * disassembly. These include resource descriptors and switch/case
412 * operations.
414 ******************************************************************************/
416 void
417 AcpiDmConvertParseObjects (
418 ACPI_PARSE_OBJECT *ParseTreeRoot,
419 ACPI_NAMESPACE_NODE *NamespaceRoot)
421 ACPI_STATUS Status;
422 ACPI_OP_WALK_INFO Info;
423 ACPI_WALK_STATE *WalkState;
426 if (!ParseTreeRoot)
428 return;
431 /* Create and initialize a new walk state */
433 WalkState = AcpiDsCreateWalkState (0, ParseTreeRoot, NULL, NULL);
434 if (!WalkState)
436 return;
439 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
440 WalkState);
441 if (ACPI_FAILURE (Status))
443 ACPI_FREE (WalkState);
444 return;
447 Info.Flags = 0;
448 Info.Level = 0;
449 Info.WalkState = WalkState;
451 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmCommonDescendingOp,
452 AcpiDmCommonAscendingOp, &Info);
453 ACPI_FREE (WalkState);
455 if (AcpiGbl_TempListHead) {
456 AcpiDmClearTempList();
459 return;
463 /*******************************************************************************
465 * FUNCTION: AcpiDmDumpDescending
467 * PARAMETERS: ASL_WALK_CALLBACK
469 * RETURN: Status
471 * DESCRIPTION: Format and print contents of one parse Op.
473 ******************************************************************************/
475 static ACPI_STATUS
476 AcpiDmDumpDescending (
477 ACPI_PARSE_OBJECT *Op,
478 UINT32 Level,
479 void *Context)
481 ACPI_OP_WALK_INFO *Info = Context;
482 char *Path;
485 if (!Op)
487 return (AE_OK);
490 /* Most of the information (count, level, name) here */
492 Info->Count++;
493 AcpiOsPrintf ("% 5d [%2.2d] ", Info->Count, Level);
494 AcpiDmIndent (Level);
495 AcpiOsPrintf ("%-28s", AcpiPsGetOpcodeName (Op->Common.AmlOpcode));
497 /* Extra info is helpful */
499 switch (Op->Common.AmlOpcode)
501 case AML_BYTE_OP:
503 AcpiOsPrintf ("%2.2X", (UINT32) Op->Common.Value.Integer);
504 break;
506 case AML_WORD_OP:
508 AcpiOsPrintf ("%4.4X", (UINT32) Op->Common.Value.Integer);
509 break;
511 case AML_DWORD_OP:
513 AcpiOsPrintf ("%8.8X", (UINT32) Op->Common.Value.Integer);
514 break;
516 case AML_QWORD_OP:
518 AcpiOsPrintf ("%8.8X%8.8X", ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));
519 break;
521 case AML_INT_NAMEPATH_OP:
523 if (Op->Common.Value.String)
525 AcpiNsExternalizeName (ACPI_UINT32_MAX, Op->Common.Value.String,
526 NULL, &Path);
527 AcpiOsPrintf ("%s %p", Path, Op->Common.Node);
528 ACPI_FREE (Path);
530 else
532 AcpiOsPrintf ("[NULL]");
534 break;
536 case AML_NAME_OP:
537 case AML_METHOD_OP:
538 case AML_DEVICE_OP:
540 AcpiOsPrintf ("%4.4s",
541 ACPI_CAST_PTR (char, &Op->Named.Name));
542 break;
544 case AML_INT_NAMEDFIELD_OP:
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;
553 default:
555 break;
558 AcpiOsPrintf ("\n");
559 return (AE_OK);
563 /*******************************************************************************
565 * FUNCTION: AcpiDmFindOrphanDescending
567 * PARAMETERS: ASL_WALK_CALLBACK
569 * RETURN: Status
571 * DESCRIPTION: Check namepath Ops for orphaned method invocations
573 * Note: Parts of this are experimental, under possible further development.
575 ******************************************************************************/
577 static ACPI_STATUS
578 AcpiDmFindOrphanDescending (
579 ACPI_PARSE_OBJECT *Op,
580 UINT32 Level,
581 void *Context)
583 const ACPI_OPCODE_INFO *OpInfo;
584 ACPI_PARSE_OBJECT *ChildOp;
585 ACPI_PARSE_OBJECT *NextOp;
586 ACPI_PARSE_OBJECT *ParentOp;
587 UINT32 ArgCount;
590 if (!Op)
592 return (AE_OK);
595 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
597 switch (Op->Common.AmlOpcode)
599 #ifdef ACPI_UNDER_DEVELOPMENT
600 case AML_ADD_OP:
602 ChildOp = Op->Common.Value.Arg;
603 if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
604 !ChildOp->Common.Node)
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);
612 NextOp = Op->Common.Next;
613 if (!NextOp)
615 /* This NamePath has no args, assume it is an integer */
617 AcpiDmAddOpToExternalList (ChildOp,
618 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
619 return (AE_OK);
622 ArgCount = AcpiDmInspectPossibleArgs (3, 1, NextOp);
623 AcpiOsPrintf ("/* A-CHILDREN: %u Actual %u */\n",
624 ArgCount, AcpiDmCountChildren (Op));
626 if (ArgCount < 1)
628 /* One Arg means this is just a Store(Name,Target) */
630 AcpiDmAddOpToExternalList (ChildOp,
631 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
632 return (AE_OK);
635 AcpiDmAddOpToExternalList (ChildOp,
636 ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
638 break;
640 #endif
642 case AML_STORE_OP:
644 ChildOp = Op->Common.Value.Arg;
645 if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
646 !ChildOp->Common.Node)
648 NextOp = Op->Common.Next;
649 if (!NextOp)
651 /* This NamePath has no args, assume it is an integer */
653 AcpiDmAddOpToExternalList (ChildOp,
654 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
655 return (AE_OK);
658 ArgCount = AcpiDmInspectPossibleArgs (2, 1, NextOp);
659 if (ArgCount <= 1)
661 /* One Arg means this is just a Store(Name,Target) */
663 AcpiDmAddOpToExternalList (ChildOp,
664 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, ArgCount, 0);
665 return (AE_OK);
668 AcpiDmAddOpToExternalList (ChildOp,
669 ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
671 break;
673 case AML_INT_NAMEPATH_OP:
675 /* Must examine parent to see if this namepath is an argument */
677 ParentOp = Op->Common.Parent;
678 OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
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)
686 ArgCount = AcpiDmInspectPossibleArgs (0, 0, Op);
689 * Check if namepath is a predicate for if/while or lone parameter to
690 * a return.
692 if (ArgCount == 0)
694 if (((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
695 (ParentOp->Common.AmlOpcode == AML_WHILE_OP) ||
696 (ParentOp->Common.AmlOpcode == AML_RETURN_OP)) &&
698 /* And namepath is the first argument */
699 (ParentOp->Common.Value.Arg == Op))
701 AcpiDmAddOpToExternalList (Op,
702 Op->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
703 break;
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.
712 AcpiDmAddOpToExternalList (Op,
713 Op->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
715 break;
717 default:
719 break;
722 return (AE_OK);
726 /*******************************************************************************
728 * FUNCTION: AcpiDmLoadDescendingOp
730 * PARAMETERS: ASL_WALK_CALLBACK
732 * RETURN: Status
734 * DESCRIPTION: Descending handler for namespace control method object load
736 ******************************************************************************/
738 static ACPI_STATUS
739 AcpiDmLoadDescendingOp (
740 ACPI_PARSE_OBJECT *Op,
741 UINT32 Level,
742 void *Context)
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;
757 WalkState = Info->WalkState;
758 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
759 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
761 /* Only interested in operators that create new names */
763 if (!(OpInfo->Flags & AML_NAMED) &&
764 !(OpInfo->Flags & AML_CREATE))
766 goto Exit;
769 /* Get the NamePath from the appropriate place */
771 if (OpInfo->Flags & AML_NAMED)
773 /* For all named operators, get the new name */
775 Path = Op->Named.Path;
777 if (!Path && Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
779 *ACPI_CAST_PTR (UINT32, &FieldPath[0]) = Op->Named.Name;
780 FieldPath[4] = 0;
781 Path = FieldPath;
784 else if (OpInfo->Flags & AML_CREATE)
786 /* New name is the last child */
788 NextOp = Op->Common.Value.Arg;
790 while (NextOp->Common.Next)
792 NextOp = NextOp->Common.Next;
795 Path = NextOp->Common.Value.String;
798 if (!Path)
800 goto Exit;
803 /* Insert the name into the namespace */
805 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
806 ACPI_IMODE_LOAD_PASS2, ACPI_NS_DONT_OPEN_SCOPE,
807 WalkState, &Node);
809 Op->Common.Node = Node;
811 if (ACPI_SUCCESS (Status))
813 /* Check if it's a predefined node */
815 while (AcpiGbl_PreDefinedNames[PreDefineIndex].Name)
817 if (ACPI_COMPARE_NAME (Node->Name.Ascii,
818 AcpiGbl_PreDefinedNames[PreDefineIndex].Name))
820 PreDefined = TRUE;
821 break;
824 PreDefineIndex++;
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
834 if (!PreDefined && Node != AcpiGbl_RootNode &&
835 Op->Common.AmlOpcode != AML_SCOPE_OP)
837 Node->OwnerId = WalkState->OwnerId;
842 Exit:
844 if (AcpiNsOpensScope (ObjectType))
846 if (Op->Common.Node)
848 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
849 WalkState);
850 if (ACPI_FAILURE (Status))
852 return (Status);
857 return (AE_OK);
861 /*******************************************************************************
863 * FUNCTION: AcpiDmXrefDescendingOp
865 * PARAMETERS: ASL_WALK_CALLBACK
867 * RETURN: Status
869 * DESCRIPTION: Descending handler for namespace cross reference
871 ******************************************************************************/
873 static ACPI_STATUS
874 AcpiDmXrefDescendingOp (
875 ACPI_PARSE_OBJECT *Op,
876 UINT32 Level,
877 void *Context)
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;
894 WalkState = Info->WalkState;
895 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
896 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
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))
903 goto Exit;
906 /* Get the NamePath from the appropriate place */
908 if (OpInfo->Flags & AML_NAMED)
911 * Only these two operators (Alias, Scope) refer to an existing
912 * name, it is the first argument
914 if (Op->Common.AmlOpcode == AML_ALIAS_OP)
916 ObjectType = ACPI_TYPE_ANY;
918 NextOp = Op->Common.Value.Arg;
919 NextOp = NextOp->Common.Value.Arg;
920 if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
922 Path = NextOp->Common.Value.String;
925 else if (Op->Common.AmlOpcode == AML_SCOPE_OP ||
926 Op->Common.AmlOpcode == AML_EXTERNAL_OP)
928 Path = Op->Named.Path;
931 else if (OpInfo->Flags & AML_CREATE)
933 /* Referenced Buffer Name is the first child */
935 ObjectType = ACPI_TYPE_BUFFER; /* Change from TYPE_BUFFER_FIELD */
937 NextOp = Op->Common.Value.Arg;
938 if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
940 Path = NextOp->Common.Value.String;
943 else if (Op->Common.AmlOpcode == AML_NOTIFY_OP)
945 Path = Op->Common.Value.Arg->Asl.Value.String;
947 else
949 Path = Op->Common.Value.String;
952 if (!Path)
954 goto Exit;
958 * Lookup the name in the namespace. Name must exist at this point, or it
959 * is an invalid reference.
961 * The namespace is also used as a lookup table for references to resource
962 * descriptors and the fields within them.
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);
969 if (ACPI_SUCCESS (Status) && (Node->Flags & ANOBJ_IS_EXTERNAL))
971 /* Node was created by an External() statement */
973 Status = AE_NOT_FOUND;
976 if (ACPI_FAILURE (Status))
978 if (Status == AE_NOT_FOUND)
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.
987 if (!(Op->Asl.Parent &&
988 (Op->Asl.Parent->Asl.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)))
990 if (Node)
992 AcpiDmAddNodeToExternalList (Node,
993 (UINT8) ObjectType, 7, Flags);
995 else
997 AcpiDmAddOpToExternalList (Op, Path,
998 (UINT8) ObjectType, 7, Flags);
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.
1010 else if (Node->OwnerId &&
1011 (WalkState->OwnerId != Node->OwnerId))
1013 ObjectType2 = ObjectType;
1015 Object = AcpiNsGetAttachedObject (Node);
1016 if (Object)
1018 ObjectType2 = Object->Common.Type;
1019 if (ObjectType2 == ACPI_TYPE_METHOD)
1021 ParamCount = Object->Method.ParamCount;
1025 Pathname = AcpiNsGetExternalPathname (Node);
1026 if (!Pathname)
1028 return (AE_NO_MEMORY);
1031 AcpiDmAddNodeToExternalList (Node, (UINT8) ObjectType2,
1032 ParamCount, ACPI_EXT_RESOLVED_REFERENCE);
1034 ACPI_FREE (Pathname);
1035 Op->Common.Node = Node;
1037 else
1039 Op->Common.Node = Node;
1043 Exit:
1044 /* Open new scope if necessary */
1046 if (AcpiNsOpensScope (ObjectType))
1048 if (Op->Common.Node)
1050 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
1051 WalkState);
1052 if (ACPI_FAILURE (Status))
1054 return (Status);
1059 return (AE_OK);
1062 /*******************************************************************************
1064 * FUNCTION: AcpiDmCommonDescendingOp
1066 * PARAMETERS: ASL_WALK_CALLBACK
1068 * RETURN: ACPI_STATUS
1070 * DESCRIPTION: Perform parse tree preprocessing before main disassembly walk.
1072 ******************************************************************************/
1074 static ACPI_STATUS
1075 AcpiDmCommonDescendingOp (
1076 ACPI_PARSE_OBJECT *Op,
1077 UINT32 Level,
1078 void *Context)
1080 ACPI_STATUS Status;
1083 /* Resource descriptor conversion */
1085 Status = AcpiDmProcessResourceDescriptors (Op, Level, Context);
1086 if (ACPI_FAILURE (Status))
1088 return (Status);
1091 /* Switch/Case conversion */
1093 Status = AcpiDmProcessSwitch (Op);
1094 return (AE_OK);
1098 /*******************************************************************************
1100 * FUNCTION: AcpiDmProcessResourceDescriptors
1102 * PARAMETERS: ASL_WALK_CALLBACK
1104 * RETURN: ACPI_STATUS
1106 * DESCRIPTION: Convert fixed-offset references to resource descriptors to
1107 * symbolic references. Should only be called after namespace has
1108 * been cross referenced.
1110 ******************************************************************************/
1112 static ACPI_STATUS
1113 AcpiDmProcessResourceDescriptors (
1114 ACPI_PARSE_OBJECT *Op,
1115 UINT32 Level,
1116 void *Context)
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;
1125 WalkState = Info->WalkState;
1126 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1128 /* Open new scope if necessary */
1130 ObjectType = OpInfo->ObjectType;
1131 if (AcpiNsOpensScope (ObjectType))
1133 if (Op->Common.Node)
1136 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
1137 WalkState);
1138 if (ACPI_FAILURE (Status))
1140 return (Status);
1146 * Check if this operator contains a reference to a resource descriptor.
1147 * If so, convert the reference into a symbolic reference.
1149 AcpiDmCheckResourceReference (Op, WalkState);
1150 return (AE_OK);
1153 /*******************************************************************************
1155 * FUNCTION: AcpiDmCommonAscendingOp
1157 * PARAMETERS: ASL_WALK_CALLBACK
1159 * RETURN: None
1161 * DESCRIPTION: Ascending handler for combined parse/namespace walks. Closes
1162 * scope if necessary.
1164 ******************************************************************************/
1166 static ACPI_STATUS
1167 AcpiDmCommonAscendingOp (
1168 ACPI_PARSE_OBJECT *Op,
1169 UINT32 Level,
1170 void *Context)
1172 ACPI_OP_WALK_INFO *Info = Context;
1173 ACPI_OBJECT_TYPE ObjectType;
1176 /* Close scope if necessary */
1178 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1180 if (AcpiNsOpensScope (ObjectType))
1182 (void) AcpiDsScopeStackPop (Info->WalkState);
1185 return (AE_OK);
1188 /*******************************************************************************
1190 * FUNCTION: AcpiDmInspectPossibleArgs
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
1197 * RETURN: Status
1199 * DESCRIPTION: Examine following args and next ops for possible arguments
1200 * for an unrecognized method invocation.
1202 ******************************************************************************/
1204 static UINT32
1205 AcpiDmInspectPossibleArgs (
1206 UINT32 CurrentOpArgCount,
1207 UINT32 TargetCount,
1208 ACPI_PARSE_OBJECT *Op)
1210 const ACPI_OPCODE_INFO *OpInfo;
1211 UINT32 i;
1212 UINT32 ArgumentCount = 0;
1213 ACPI_PARSE_OBJECT *NextOp;
1214 ACPI_PARSE_OBJECT *ExecuteOp;
1217 if (!Op)
1219 return (0);
1222 /* Lookahead for the maximum number of possible arguments */
1224 NextOp = Op->Common.Next;
1226 for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && NextOp; i++)
1228 OpInfo = AcpiPsGetOpcodeInfo (NextOp->Common.AmlOpcode);
1230 /* Any one of these operators is "very probably" not a method arg */
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))
1238 break;
1241 if (OpInfo->Class == AML_CLASS_EXECUTE)
1243 /* Probable that this is method arg if there is no target */
1245 ExecuteOp = NextOp->Common.Value.Arg;
1246 while (ExecuteOp)
1248 if ((ExecuteOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
1249 (ExecuteOp->Common.Value.Arg == NULL))
1251 /* No target, could be a method arg */
1253 break;
1256 if (NextOp->Common.AmlOpcode == AML_REF_OF_OP)
1258 break;
1261 ExecuteOp = ExecuteOp->Common.Next;
1264 if (!ExecuteOp)
1266 /* Has a target, not method arg */
1268 return (ArgumentCount);
1272 ArgumentCount++;
1273 NextOp = NextOp->Common.Next;
1276 return (ArgumentCount);