Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / common / adwalk.c
blob67d9b11389464f53812a75770a41b31a8d75d4b7
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 - 2009, 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 *****************************************************************************/
117 #include "acpi.h"
118 #include "accommon.h"
119 #include "acparser.h"
120 #include "amlcode.h"
121 #include "acdebug.h"
122 #include "acdisasm.h"
123 #include "acdispat.h"
124 #include "acnamesp.h"
125 #include "acapps.h"
128 #define _COMPONENT ACPI_TOOLS
129 ACPI_MODULE_NAME ("adwalk")
132 * aslmap - opcode mappings and reserved method names
134 ACPI_OBJECT_TYPE
135 AslMapNamedOpcodeToDataType (
136 UINT16 Opcode);
138 /* Local prototypes */
140 static ACPI_STATUS
141 AcpiDmFindOrphanDescending (
142 ACPI_PARSE_OBJECT *Op,
143 UINT32 Level,
144 void *Context);
146 static ACPI_STATUS
147 AcpiDmDumpDescending (
148 ACPI_PARSE_OBJECT *Op,
149 UINT32 Level,
150 void *Context);
152 static ACPI_STATUS
153 AcpiDmXrefDescendingOp (
154 ACPI_PARSE_OBJECT *Op,
155 UINT32 Level,
156 void *Context);
158 static ACPI_STATUS
159 AcpiDmCommonAscendingOp (
160 ACPI_PARSE_OBJECT *Op,
161 UINT32 Level,
162 void *Context);
164 static ACPI_STATUS
165 AcpiDmLoadDescendingOp (
166 ACPI_PARSE_OBJECT *Op,
167 UINT32 Level,
168 void *Context);
170 static UINT32
171 AcpiDmInspectPossibleArgs (
172 UINT32 CurrentOpArgCount,
173 UINT32 TargetCount,
174 ACPI_PARSE_OBJECT *Op);
176 static ACPI_STATUS
177 AcpiDmResourceDescendingOp (
178 ACPI_PARSE_OBJECT *Op,
179 UINT32 Level,
180 void *Context);
183 /*******************************************************************************
185 * FUNCTION: AcpiDmDumpTree
187 * PARAMETERS: Origin - Starting object
189 * RETURN: None
191 * DESCRIPTION: Parse tree walk to format and output the nodes
193 ******************************************************************************/
195 void
196 AcpiDmDumpTree (
197 ACPI_PARSE_OBJECT *Origin)
199 ACPI_OP_WALK_INFO Info;
202 if (!Origin)
204 return;
207 AcpiOsPrintf ("/*\nAML Parse Tree\n\n");
208 Info.Flags = 0;
209 Info.Count = 0;
210 Info.Level = 0;
211 Info.WalkState = NULL;
212 AcpiDmWalkParseTree (Origin, AcpiDmDumpDescending, NULL, &Info);
213 AcpiOsPrintf ("*/\n\n");
217 /*******************************************************************************
219 * FUNCTION: AcpiDmFindOrphanMethods
221 * PARAMETERS: Origin - Starting object
223 * RETURN: None
225 * DESCRIPTION: Parse tree walk to find "orphaned" method invocations -- methods
226 * that are not resolved in the namespace
228 ******************************************************************************/
230 void
231 AcpiDmFindOrphanMethods (
232 ACPI_PARSE_OBJECT *Origin)
234 ACPI_OP_WALK_INFO Info;
237 if (!Origin)
239 return;
242 Info.Flags = 0;
243 Info.Level = 0;
244 Info.WalkState = NULL;
245 AcpiDmWalkParseTree (Origin, AcpiDmFindOrphanDescending, NULL, &Info);
249 /*******************************************************************************
251 * FUNCTION: AcpiDmFinishNamespaceLoad
253 * PARAMETERS: ParseTreeRoot - Root of the parse tree
254 * NamespaceRoot - Root of the internal namespace
255 * OwnerId - OwnerId of the table to be disassembled
257 * RETURN: None
259 * DESCRIPTION: Load all namespace items that are created within control
260 * methods. Used before namespace cross reference
262 ******************************************************************************/
264 void
265 AcpiDmFinishNamespaceLoad (
266 ACPI_PARSE_OBJECT *ParseTreeRoot,
267 ACPI_NAMESPACE_NODE *NamespaceRoot,
268 ACPI_OWNER_ID OwnerId)
270 ACPI_STATUS Status;
271 ACPI_OP_WALK_INFO Info;
272 ACPI_WALK_STATE *WalkState;
275 if (!ParseTreeRoot)
277 return;
280 /* Create and initialize a new walk state */
282 WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
283 if (!WalkState)
285 return;
288 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
289 if (ACPI_FAILURE (Status))
291 return;
294 Info.Flags = 0;
295 Info.Level = 0;
296 Info.WalkState = WalkState;
297 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmLoadDescendingOp,
298 AcpiDmCommonAscendingOp, &Info);
299 ACPI_FREE (WalkState);
303 /*******************************************************************************
305 * FUNCTION: AcpiDmCrossReferenceNamespace
307 * PARAMETERS: ParseTreeRoot - Root of the parse tree
308 * NamespaceRoot - Root of the internal namespace
309 * OwnerId - OwnerId of the table to be disassembled
311 * RETURN: None
313 * DESCRIPTION: Cross reference the namespace to create externals
315 ******************************************************************************/
317 void
318 AcpiDmCrossReferenceNamespace (
319 ACPI_PARSE_OBJECT *ParseTreeRoot,
320 ACPI_NAMESPACE_NODE *NamespaceRoot,
321 ACPI_OWNER_ID OwnerId)
323 ACPI_STATUS Status;
324 ACPI_OP_WALK_INFO Info;
325 ACPI_WALK_STATE *WalkState;
328 if (!ParseTreeRoot)
330 return;
333 /* Create and initialize a new walk state */
335 WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
336 if (!WalkState)
338 return;
341 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
342 if (ACPI_FAILURE (Status))
344 return;
347 Info.Flags = 0;
348 Info.Level = 0;
349 Info.WalkState = WalkState;
350 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmXrefDescendingOp,
351 AcpiDmCommonAscendingOp, &Info);
352 ACPI_FREE (WalkState);
356 /*******************************************************************************
358 * FUNCTION: AcpiDmConvertResourceIndexes
360 * PARAMETERS: ParseTreeRoot - Root of the parse tree
361 * NamespaceRoot - Root of the internal namespace
363 * RETURN: None
365 * DESCRIPTION: Convert fixed-offset references to resource descriptors to
366 * symbolic references. Should only be called after namespace has
367 * been cross referenced.
369 ******************************************************************************/
371 void
372 AcpiDmConvertResourceIndexes (
373 ACPI_PARSE_OBJECT *ParseTreeRoot,
374 ACPI_NAMESPACE_NODE *NamespaceRoot)
376 ACPI_STATUS Status;
377 ACPI_OP_WALK_INFO Info;
378 ACPI_WALK_STATE *WalkState;
381 if (!ParseTreeRoot)
383 return;
386 /* Create and initialize a new walk state */
388 WalkState = AcpiDsCreateWalkState (0, ParseTreeRoot, NULL, NULL);
389 if (!WalkState)
391 return;
394 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
395 if (ACPI_FAILURE (Status))
397 return;
400 Info.Flags = 0;
401 Info.Level = 0;
402 Info.WalkState = WalkState;
403 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmResourceDescendingOp,
404 AcpiDmCommonAscendingOp, &Info);
405 ACPI_FREE (WalkState);
406 return;
410 /*******************************************************************************
412 * FUNCTION: AcpiDmDumpDescending
414 * PARAMETERS: ASL_WALK_CALLBACK
416 * RETURN: Status
418 * DESCRIPTION: Format and print contents of one parse Op.
420 ******************************************************************************/
422 static ACPI_STATUS
423 AcpiDmDumpDescending (
424 ACPI_PARSE_OBJECT *Op,
425 UINT32 Level,
426 void *Context)
428 ACPI_OP_WALK_INFO *Info = Context;
429 const ACPI_OPCODE_INFO *OpInfo;
430 char *Path;
433 if (!Op)
435 return (AE_OK);
438 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
439 Info->Count++;
441 /* Most of the information (count, level, name) here */
443 AcpiOsPrintf ("% 5d [%2.2d] ", Info->Count, Level);
444 AcpiDmIndent (Level);
445 AcpiOsPrintf ("%-28s", AcpiPsGetOpcodeName (Op->Common.AmlOpcode));
447 /* Extra info is helpful */
449 switch (Op->Common.AmlOpcode)
451 case AML_BYTE_OP:
452 case AML_WORD_OP:
453 case AML_DWORD_OP:
454 AcpiOsPrintf ("%X", (UINT32) Op->Common.Value.Integer);
455 break;
457 case AML_INT_NAMEPATH_OP:
458 if (Op->Common.Value.String)
460 AcpiNsExternalizeName (ACPI_UINT32_MAX, Op->Common.Value.String,
461 NULL, &Path);
462 AcpiOsPrintf ("%s %p", Path, Op->Common.Node);
463 ACPI_FREE (Path);
465 else
467 AcpiOsPrintf ("[NULL]");
469 break;
471 case AML_NAME_OP:
472 case AML_METHOD_OP:
473 case AML_DEVICE_OP:
474 case AML_INT_NAMEDFIELD_OP:
475 AcpiOsPrintf ("%4.4s", &Op->Named.Name);
476 break;
478 default:
479 break;
482 AcpiOsPrintf ("\n");
483 return (AE_OK);
487 /*******************************************************************************
489 * FUNCTION: AcpiDmFindOrphanDescending
491 * PARAMETERS: ASL_WALK_CALLBACK
493 * RETURN: Status
495 * DESCRIPTION: Check namepath Ops for orphaned method invocations
497 * Note: Experimental.
499 ******************************************************************************/
501 static ACPI_STATUS
502 AcpiDmFindOrphanDescending (
503 ACPI_PARSE_OBJECT *Op,
504 UINT32 Level,
505 void *Context)
507 const ACPI_OPCODE_INFO *OpInfo;
508 ACPI_PARSE_OBJECT *ChildOp;
509 ACPI_PARSE_OBJECT *NextOp;
510 ACPI_PARSE_OBJECT *ParentOp;
511 UINT32 ArgCount;
514 if (!Op)
516 return (AE_OK);
519 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
521 switch (Op->Common.AmlOpcode)
523 #ifdef ACPI_UNDER_DEVELOPMENT
524 case AML_ADD_OP:
525 ChildOp = Op->Common.Value.Arg;
526 if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
527 !ChildOp->Common.Node)
529 AcpiNsExternalizeName (ACPI_UINT32_MAX, ChildOp->Common.Value.String,
530 NULL, &Path);
531 AcpiOsPrintf ("/* %-16s A-NAMEPATH: %s */\n", Op->Common.AmlOpName, Path);
532 ACPI_FREE (Path);
534 NextOp = Op->Common.Next;
535 if (!NextOp)
537 /* This NamePath has no args, assume it is an integer */
539 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0);
540 return (AE_OK);
543 ArgCount = AcpiDmInspectPossibleArgs (3, 1, NextOp);
544 AcpiOsPrintf ("/* A-CHILDREN: %d Actual %d */\n", ArgCount, AcpiDmCountChildren (Op));
546 if (ArgCount < 1)
548 /* One Arg means this is just a Store(Name,Target) */
550 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0);
551 return (AE_OK);
554 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount);
556 break;
557 #endif
559 case AML_STORE_OP:
561 ChildOp = Op->Common.Value.Arg;
562 if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
563 !ChildOp->Common.Node)
565 NextOp = Op->Common.Next;
566 if (!NextOp)
568 /* This NamePath has no args, assume it is an integer */
570 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0);
571 return (AE_OK);
574 ArgCount = AcpiDmInspectPossibleArgs (2, 1, NextOp);
575 if (ArgCount <= 1)
577 /* One Arg means this is just a Store(Name,Target) */
579 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0);
580 return (AE_OK);
583 AcpiDmAddToExternalList (ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount);
585 break;
587 case AML_INT_NAMEPATH_OP:
589 /* Must examine parent to see if this namepath is an argument */
591 ParentOp = Op->Common.Parent;
592 OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
594 if ((OpInfo->Class != AML_CLASS_EXECUTE) &&
595 (OpInfo->Class != AML_CLASS_CREATE) &&
596 (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
597 !Op->Common.Node)
599 ArgCount = AcpiDmInspectPossibleArgs (0, 0, Op->Common.Next);
602 * Check if namepath is a predicate for if/while or lone parameter to
603 * a return.
605 if (ArgCount == 0)
607 if (((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
608 (ParentOp->Common.AmlOpcode == AML_WHILE_OP) ||
609 (ParentOp->Common.AmlOpcode == AML_RETURN_OP)) &&
611 /* And namepath is the first argument */
612 (ParentOp->Common.Value.Arg == Op))
614 AcpiDmAddToExternalList (Op->Common.Value.String, ACPI_TYPE_INTEGER, 0);
615 break;
620 * This is a standalone namestring (not a parameter to another
621 * operator) - it *must* be a method invocation, nothing else is
622 * grammatically possible.
624 AcpiDmAddToExternalList (Op->Common.Value.String, ACPI_TYPE_METHOD, ArgCount);
627 break;
629 default:
630 break;
633 return (AE_OK);
637 /*******************************************************************************
639 * FUNCTION: AcpiDmLoadDescendingOp
641 * PARAMETERS: ASL_WALK_CALLBACK
643 * RETURN: Status
645 * DESCRIPTION: Descending handler for namespace control method object load
647 ******************************************************************************/
649 static ACPI_STATUS
650 AcpiDmLoadDescendingOp (
651 ACPI_PARSE_OBJECT *Op,
652 UINT32 Level,
653 void *Context)
655 ACPI_OP_WALK_INFO *Info = Context;
656 const ACPI_OPCODE_INFO *OpInfo;
657 ACPI_WALK_STATE *WalkState;
658 ACPI_OBJECT_TYPE ObjectType;
659 ACPI_STATUS Status;
660 char *Path = NULL;
661 ACPI_PARSE_OBJECT *NextOp;
662 ACPI_NAMESPACE_NODE *Node;
663 char FieldPath[5];
664 BOOLEAN PreDefined = FALSE;
665 UINT8 PreDefineIndex = 0;
668 WalkState = Info->WalkState;
669 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
670 ObjectType = OpInfo->ObjectType;
671 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
673 /* Only interested in operators that create new names */
675 if (!(OpInfo->Flags & AML_NAMED) &&
676 !(OpInfo->Flags & AML_CREATE))
678 goto Exit;
681 /* Get the NamePath from the appropriate place */
683 if (OpInfo->Flags & AML_NAMED)
685 /* For all named operators, get the new name */
687 Path = (char *) Op->Named.Path;
689 if (!Path && Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
691 *ACPI_CAST_PTR (UINT32, &FieldPath[0]) = Op->Named.Name;
692 FieldPath[4] = 0;
693 Path = FieldPath;
696 else if (OpInfo->Flags & AML_CREATE)
698 /* New name is the last child */
700 NextOp = Op->Common.Value.Arg;
702 while (NextOp->Common.Next)
704 NextOp = NextOp->Common.Next;
706 Path = NextOp->Common.Value.String;
709 if (!Path)
711 goto Exit;
714 /* Insert the name into the namespace */
716 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
717 ACPI_IMODE_LOAD_PASS2, ACPI_NS_DONT_OPEN_SCOPE,
718 WalkState, &Node);
720 Op->Common.Node = Node;
722 if (ACPI_SUCCESS (Status))
724 /* Check if it's a predefined node */
726 while (AcpiGbl_PreDefinedNames[PreDefineIndex].Name)
728 if (!ACPI_STRNCMP (Node->Name.Ascii,
729 AcpiGbl_PreDefinedNames[PreDefineIndex].Name, 4))
731 PreDefined = TRUE;
732 break;
735 PreDefineIndex++;
739 * Set node owner id if it satisfies all the following conditions:
740 * 1) Not a predefined node, _SB_ etc
741 * 2) Not the root node
742 * 3) Not a node created by Scope
745 if (!PreDefined && Node != AcpiGbl_RootNode &&
746 Op->Common.AmlOpcode != AML_SCOPE_OP)
748 Node->OwnerId = WalkState->OwnerId;
753 Exit:
755 if (AcpiNsOpensScope (ObjectType))
757 if (Op->Common.Node)
759 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
760 if (ACPI_FAILURE (Status))
762 return (Status);
767 return (AE_OK);
771 /*******************************************************************************
773 * FUNCTION: AcpiDmXrefDescendingOp
775 * PARAMETERS: ASL_WALK_CALLBACK
777 * RETURN: Status
779 * DESCRIPTION: Descending handler for namespace cross reference
781 ******************************************************************************/
783 static ACPI_STATUS
784 AcpiDmXrefDescendingOp (
785 ACPI_PARSE_OBJECT *Op,
786 UINT32 Level,
787 void *Context)
789 ACPI_OP_WALK_INFO *Info = Context;
790 const ACPI_OPCODE_INFO *OpInfo;
791 ACPI_WALK_STATE *WalkState;
792 ACPI_OBJECT_TYPE ObjectType;
793 ACPI_OBJECT_TYPE ObjectType2;
794 ACPI_STATUS Status;
795 char *Path = NULL;
796 ACPI_PARSE_OBJECT *NextOp;
797 ACPI_NAMESPACE_NODE *Node;
798 ACPI_OPERAND_OBJECT *Object;
801 WalkState = Info->WalkState;
802 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
803 ObjectType = OpInfo->ObjectType;
804 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
806 if ((!(OpInfo->Flags & AML_NAMED)) &&
807 (!(OpInfo->Flags & AML_CREATE)) &&
808 (Op->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
810 goto Exit;
813 /* Get the NamePath from the appropriate place */
815 if (OpInfo->Flags & AML_NAMED)
817 if ((Op->Common.AmlOpcode == AML_ALIAS_OP) ||
818 (Op->Common.AmlOpcode == AML_SCOPE_OP))
821 * Only these two operators refer to an existing name,
822 * first argument
824 Path = (char *) Op->Named.Path;
827 else if (OpInfo->Flags & AML_CREATE)
829 /* Referenced Buffer Name is the first child */
831 NextOp = Op->Common.Value.Arg;
832 if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
834 Path = NextOp->Common.Value.String;
837 else
839 Path = Op->Common.Value.String;
842 if (!Path)
844 goto Exit;
848 * Lookup the name in the namespace. Name must exist at this point, or it
849 * is an invalid reference.
851 * The namespace is also used as a lookup table for references to resource
852 * descriptors and the fields within them.
854 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
855 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
856 WalkState, &Node);
857 if (ACPI_FAILURE (Status))
859 if (Status == AE_NOT_FOUND)
861 AcpiDmAddToExternalList (Path, (UINT8) ObjectType, 0);
864 * We could install this into the namespace, but we catch duplicate
865 * externals when they are added to the list.
867 #if 0
868 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
869 ACPI_IMODE_LOAD_PASS1, ACPI_NS_DONT_OPEN_SCOPE,
870 WalkState, &Node);
871 #endif
876 * Found the node in external table, add it to external list
877 * Node->OwnerId == 0 indicates built-in ACPI Names, _OS_ etc
879 else if (Node->OwnerId && WalkState->OwnerId != Node->OwnerId)
881 ObjectType2 = ObjectType;
883 Object = AcpiNsGetAttachedObject (Node);
884 if (Object)
886 ObjectType2 = Object->Common.Type;
889 if (ObjectType2 == ACPI_TYPE_METHOD)
891 AcpiDmAddToExternalList (Path, ACPI_TYPE_METHOD,
892 Object->Method.ParamCount);
894 else
896 AcpiDmAddToExternalList (Path, (UINT8) ObjectType2, 0);
899 Op->Common.Node = Node;
901 else
903 Op->Common.Node = Node;
907 Exit:
908 /* Open new scope if necessary */
910 if (AcpiNsOpensScope (ObjectType))
912 if (Op->Common.Node)
914 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
915 if (ACPI_FAILURE (Status))
917 return (Status);
922 return (AE_OK);
926 /*******************************************************************************
928 * FUNCTION: AcpiDmResourceDescendingOp
930 * PARAMETERS: ASL_WALK_CALLBACK
932 * RETURN: None
934 * DESCRIPTION: Process one parse op during symbolic resource index conversion.
936 ******************************************************************************/
938 static ACPI_STATUS
939 AcpiDmResourceDescendingOp (
940 ACPI_PARSE_OBJECT *Op,
941 UINT32 Level,
942 void *Context)
944 ACPI_OP_WALK_INFO *Info = Context;
945 const ACPI_OPCODE_INFO *OpInfo;
946 ACPI_WALK_STATE *WalkState;
947 ACPI_OBJECT_TYPE ObjectType;
948 ACPI_STATUS Status;
951 WalkState = Info->WalkState;
952 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
954 /* Open new scope if necessary */
956 ObjectType = OpInfo->ObjectType;
957 if (AcpiNsOpensScope (ObjectType))
959 if (Op->Common.Node)
962 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
963 if (ACPI_FAILURE (Status))
965 return (Status);
971 * Check if this operator contains a reference to a resource descriptor.
972 * If so, convert the reference into a symbolic reference.
974 AcpiDmCheckResourceReference (Op, WalkState);
975 return (AE_OK);
979 /*******************************************************************************
981 * FUNCTION: AcpiDmCommonAscendingOp
983 * PARAMETERS: ASL_WALK_CALLBACK
985 * RETURN: None
987 * DESCRIPTION: Ascending handler for combined parse/namespace walks. Closes
988 * scope if necessary.
990 ******************************************************************************/
992 static ACPI_STATUS
993 AcpiDmCommonAscendingOp (
994 ACPI_PARSE_OBJECT *Op,
995 UINT32 Level,
996 void *Context)
998 ACPI_OP_WALK_INFO *Info = Context;
999 const ACPI_OPCODE_INFO *OpInfo;
1000 ACPI_OBJECT_TYPE ObjectType;
1003 /* Close scope if necessary */
1005 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1006 ObjectType = OpInfo->ObjectType;
1007 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1009 if (AcpiNsOpensScope (ObjectType))
1011 (void) AcpiDsScopeStackPop (Info->WalkState);
1014 return (AE_OK);
1018 /*******************************************************************************
1020 * FUNCTION: AcpiDmInspectPossibleArgs
1022 * PARAMETERS: CurrentOpArgCount - Which arg of the current op was the
1023 * possible method invocation found
1024 * TargetCount - Number of targets (0,1,2) for this op
1025 * Op - Parse op
1027 * RETURN: Status
1029 * DESCRIPTION: Examine following args and next ops for possible arguments
1030 * for an unrecognized method invocation.
1032 ******************************************************************************/
1034 static UINT32
1035 AcpiDmInspectPossibleArgs (
1036 UINT32 CurrentOpArgCount,
1037 UINT32 TargetCount,
1038 ACPI_PARSE_OBJECT *Op)
1040 const ACPI_OPCODE_INFO *OpInfo;
1041 UINT32 i;
1042 UINT32 Last = 0;
1043 UINT32 Lookahead;
1046 Lookahead = (ACPI_METHOD_NUM_ARGS + TargetCount) - CurrentOpArgCount;
1048 /* Lookahead for the maximum number of possible arguments */
1050 for (i = 0; i < Lookahead; i++)
1052 if (!Op)
1054 break;
1057 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1060 * Any one of these operators is "very probably" not a method arg
1062 if ((Op->Common.AmlOpcode == AML_STORE_OP) ||
1063 (Op->Common.AmlOpcode == AML_NOTIFY_OP))
1065 break;
1068 if ((OpInfo->Class != AML_CLASS_EXECUTE) &&
1069 (OpInfo->Class != AML_CLASS_CONTROL))
1071 Last = i+1;
1074 Op = Op->Common.Next;
1077 return (Last);