BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / bus_managers / acpi / acpica / common / adwalk.c
blob808e4e2258e9ecdf95bb36f5db6008561c7aa197
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 - 2014, 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 "acdisasm.h"
122 #include "acdispat.h"
123 #include "acnamesp.h"
124 #include "acapps.h"
127 #define _COMPONENT ACPI_TOOLS
128 ACPI_MODULE_NAME ("adwalk")
131 * aslmap - opcode mappings and reserved method names
133 ACPI_OBJECT_TYPE
134 AslMapNamedOpcodeToDataType (
135 UINT16 Opcode);
137 /* Local prototypes */
139 static ACPI_STATUS
140 AcpiDmFindOrphanDescending (
141 ACPI_PARSE_OBJECT *Op,
142 UINT32 Level,
143 void *Context);
145 static ACPI_STATUS
146 AcpiDmDumpDescending (
147 ACPI_PARSE_OBJECT *Op,
148 UINT32 Level,
149 void *Context);
151 static ACPI_STATUS
152 AcpiDmXrefDescendingOp (
153 ACPI_PARSE_OBJECT *Op,
154 UINT32 Level,
155 void *Context);
157 static ACPI_STATUS
158 AcpiDmCommonAscendingOp (
159 ACPI_PARSE_OBJECT *Op,
160 UINT32 Level,
161 void *Context);
163 static ACPI_STATUS
164 AcpiDmLoadDescendingOp (
165 ACPI_PARSE_OBJECT *Op,
166 UINT32 Level,
167 void *Context);
169 static UINT32
170 AcpiDmInspectPossibleArgs (
171 UINT32 CurrentOpArgCount,
172 UINT32 TargetCount,
173 ACPI_PARSE_OBJECT *Op);
175 static ACPI_STATUS
176 AcpiDmResourceDescendingOp (
177 ACPI_PARSE_OBJECT *Op,
178 UINT32 Level,
179 void *Context);
182 /*******************************************************************************
184 * FUNCTION: AcpiDmDumpTree
186 * PARAMETERS: Origin - Starting object
188 * RETURN: None
190 * DESCRIPTION: Parse tree walk to format and output the nodes
192 ******************************************************************************/
194 void
195 AcpiDmDumpTree (
196 ACPI_PARSE_OBJECT *Origin)
198 ACPI_OP_WALK_INFO Info;
201 if (!Origin)
203 return;
206 AcpiOsPrintf ("/*\nAML Parse Tree\n\n");
207 Info.Flags = 0;
208 Info.Count = 0;
209 Info.Level = 0;
210 Info.WalkState = NULL;
211 AcpiDmWalkParseTree (Origin, AcpiDmDumpDescending, NULL, &Info);
212 AcpiOsPrintf ("*/\n\n");
216 /*******************************************************************************
218 * FUNCTION: AcpiDmFindOrphanMethods
220 * PARAMETERS: Origin - Starting object
222 * RETURN: None
224 * DESCRIPTION: Parse tree walk to find "orphaned" method invocations -- methods
225 * that are not resolved in the namespace
227 ******************************************************************************/
229 void
230 AcpiDmFindOrphanMethods (
231 ACPI_PARSE_OBJECT *Origin)
233 ACPI_OP_WALK_INFO Info;
236 if (!Origin)
238 return;
241 Info.Flags = 0;
242 Info.Level = 0;
243 Info.WalkState = NULL;
244 AcpiDmWalkParseTree (Origin, AcpiDmFindOrphanDescending, NULL, &Info);
248 /*******************************************************************************
250 * FUNCTION: AcpiDmFinishNamespaceLoad
252 * PARAMETERS: ParseTreeRoot - Root of the parse tree
253 * NamespaceRoot - Root of the internal namespace
254 * OwnerId - OwnerId of the table to be disassembled
256 * RETURN: None
258 * DESCRIPTION: Load all namespace items that are created within control
259 * methods. Used before namespace cross reference
261 ******************************************************************************/
263 void
264 AcpiDmFinishNamespaceLoad (
265 ACPI_PARSE_OBJECT *ParseTreeRoot,
266 ACPI_NAMESPACE_NODE *NamespaceRoot,
267 ACPI_OWNER_ID OwnerId)
269 ACPI_STATUS Status;
270 ACPI_OP_WALK_INFO Info;
271 ACPI_WALK_STATE *WalkState;
274 if (!ParseTreeRoot)
276 return;
279 /* Create and initialize a new walk state */
281 WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
282 if (!WalkState)
284 return;
287 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
288 if (ACPI_FAILURE (Status))
290 return;
293 Info.Flags = 0;
294 Info.Level = 0;
295 Info.WalkState = WalkState;
296 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmLoadDescendingOp,
297 AcpiDmCommonAscendingOp, &Info);
298 ACPI_FREE (WalkState);
302 /*******************************************************************************
304 * FUNCTION: AcpiDmCrossReferenceNamespace
306 * PARAMETERS: ParseTreeRoot - Root of the parse tree
307 * NamespaceRoot - Root of the internal namespace
308 * OwnerId - OwnerId of the table to be disassembled
310 * RETURN: None
312 * DESCRIPTION: Cross reference the namespace to create externals
314 ******************************************************************************/
316 void
317 AcpiDmCrossReferenceNamespace (
318 ACPI_PARSE_OBJECT *ParseTreeRoot,
319 ACPI_NAMESPACE_NODE *NamespaceRoot,
320 ACPI_OWNER_ID OwnerId)
322 ACPI_STATUS Status;
323 ACPI_OP_WALK_INFO Info;
324 ACPI_WALK_STATE *WalkState;
327 if (!ParseTreeRoot)
329 return;
332 /* Create and initialize a new walk state */
334 WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
335 if (!WalkState)
337 return;
340 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
341 if (ACPI_FAILURE (Status))
343 return;
346 Info.Flags = 0;
347 Info.Level = 0;
348 Info.WalkState = WalkState;
349 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmXrefDescendingOp,
350 AcpiDmCommonAscendingOp, &Info);
351 ACPI_FREE (WalkState);
355 /*******************************************************************************
357 * FUNCTION: AcpiDmConvertResourceIndexes
359 * PARAMETERS: ParseTreeRoot - Root of the parse tree
360 * NamespaceRoot - Root of the internal namespace
362 * RETURN: None
364 * DESCRIPTION: Convert fixed-offset references to resource descriptors to
365 * symbolic references. Should only be called after namespace has
366 * been cross referenced.
368 ******************************************************************************/
370 void
371 AcpiDmConvertResourceIndexes (
372 ACPI_PARSE_OBJECT *ParseTreeRoot,
373 ACPI_NAMESPACE_NODE *NamespaceRoot)
375 ACPI_STATUS Status;
376 ACPI_OP_WALK_INFO Info;
377 ACPI_WALK_STATE *WalkState;
380 if (!ParseTreeRoot)
382 return;
385 /* Create and initialize a new walk state */
387 WalkState = AcpiDsCreateWalkState (0, ParseTreeRoot, NULL, NULL);
388 if (!WalkState)
390 return;
393 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type, WalkState);
394 if (ACPI_FAILURE (Status))
396 return;
399 Info.Flags = 0;
400 Info.Level = 0;
401 Info.WalkState = WalkState;
402 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmResourceDescendingOp,
403 AcpiDmCommonAscendingOp, &Info);
404 ACPI_FREE (WalkState);
405 return;
409 /*******************************************************************************
411 * FUNCTION: AcpiDmDumpDescending
413 * PARAMETERS: ASL_WALK_CALLBACK
415 * RETURN: Status
417 * DESCRIPTION: Format and print contents of one parse Op.
419 ******************************************************************************/
421 static ACPI_STATUS
422 AcpiDmDumpDescending (
423 ACPI_PARSE_OBJECT *Op,
424 UINT32 Level,
425 void *Context)
427 ACPI_OP_WALK_INFO *Info = Context;
428 char *Path;
431 if (!Op)
433 return (AE_OK);
436 /* Most of the information (count, level, name) here */
438 Info->Count++;
439 AcpiOsPrintf ("% 5d [%2.2d] ", Info->Count, Level);
440 AcpiDmIndent (Level);
441 AcpiOsPrintf ("%-28s", AcpiPsGetOpcodeName (Op->Common.AmlOpcode));
443 /* Extra info is helpful */
445 switch (Op->Common.AmlOpcode)
447 case AML_BYTE_OP:
449 AcpiOsPrintf ("%2.2X", (UINT32) Op->Common.Value.Integer);
450 break;
452 case AML_WORD_OP:
454 AcpiOsPrintf ("%4.4X", (UINT32) Op->Common.Value.Integer);
455 break;
457 case AML_DWORD_OP:
459 AcpiOsPrintf ("%8.8X", (UINT32) Op->Common.Value.Integer);
460 break;
462 case AML_QWORD_OP:
464 AcpiOsPrintf ("%8.8X%8.8X", ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));
465 break;
467 case AML_INT_NAMEPATH_OP:
469 if (Op->Common.Value.String)
471 AcpiNsExternalizeName (ACPI_UINT32_MAX, Op->Common.Value.String,
472 NULL, &Path);
473 AcpiOsPrintf ("%s %p", Path, Op->Common.Node);
474 ACPI_FREE (Path);
476 else
478 AcpiOsPrintf ("[NULL]");
480 break;
482 case AML_NAME_OP:
483 case AML_METHOD_OP:
484 case AML_DEVICE_OP:
485 case AML_INT_NAMEDFIELD_OP:
487 AcpiOsPrintf ("%4.4s", ACPI_CAST_PTR (char, &Op->Named.Name));
488 break;
490 default:
492 break;
495 AcpiOsPrintf ("\n");
496 return (AE_OK);
500 /*******************************************************************************
502 * FUNCTION: AcpiDmFindOrphanDescending
504 * PARAMETERS: ASL_WALK_CALLBACK
506 * RETURN: Status
508 * DESCRIPTION: Check namepath Ops for orphaned method invocations
510 * Note: Experimental.
512 ******************************************************************************/
514 static ACPI_STATUS
515 AcpiDmFindOrphanDescending (
516 ACPI_PARSE_OBJECT *Op,
517 UINT32 Level,
518 void *Context)
520 const ACPI_OPCODE_INFO *OpInfo;
521 ACPI_PARSE_OBJECT *ChildOp;
522 ACPI_PARSE_OBJECT *NextOp;
523 ACPI_PARSE_OBJECT *ParentOp;
524 UINT32 ArgCount;
527 if (!Op)
529 return (AE_OK);
532 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
534 switch (Op->Common.AmlOpcode)
536 #ifdef ACPI_UNDER_DEVELOPMENT
537 case AML_ADD_OP:
539 ChildOp = Op->Common.Value.Arg;
540 if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
541 !ChildOp->Common.Node)
543 AcpiNsExternalizeName (ACPI_UINT32_MAX, ChildOp->Common.Value.String,
544 NULL, &Path);
545 AcpiOsPrintf ("/* %-16s A-NAMEPATH: %s */\n",
546 Op->Common.AmlOpName, Path);
547 ACPI_FREE (Path);
549 NextOp = Op->Common.Next;
550 if (!NextOp)
552 /* This NamePath has no args, assume it is an integer */
554 AcpiDmAddOpToExternalList (ChildOp,
555 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
556 return (AE_OK);
559 ArgCount = AcpiDmInspectPossibleArgs (3, 1, NextOp);
560 AcpiOsPrintf ("/* A-CHILDREN: %u Actual %u */\n",
561 ArgCount, AcpiDmCountChildren (Op));
563 if (ArgCount < 1)
565 /* One Arg means this is just a Store(Name,Target) */
567 AcpiDmAddOpToExternalList (ChildOp,
568 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
569 return (AE_OK);
572 AcpiDmAddOpToExternalList (ChildOp,
573 ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
575 break;
576 #endif
578 case AML_STORE_OP:
580 ChildOp = Op->Common.Value.Arg;
581 if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
582 !ChildOp->Common.Node)
584 NextOp = Op->Common.Next;
585 if (!NextOp)
587 /* This NamePath has no args, assume it is an integer */
589 AcpiDmAddOpToExternalList (ChildOp,
590 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
591 return (AE_OK);
594 ArgCount = AcpiDmInspectPossibleArgs (2, 1, NextOp);
595 if (ArgCount <= 1)
597 /* One Arg means this is just a Store(Name,Target) */
599 AcpiDmAddOpToExternalList (ChildOp,
600 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
601 return (AE_OK);
604 AcpiDmAddOpToExternalList (ChildOp,
605 ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
607 break;
609 case AML_INT_NAMEPATH_OP:
611 /* Must examine parent to see if this namepath is an argument */
613 ParentOp = Op->Common.Parent;
614 OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
616 if ((OpInfo->Class != AML_CLASS_EXECUTE) &&
617 (OpInfo->Class != AML_CLASS_CREATE) &&
618 (OpInfo->ObjectType != ACPI_TYPE_LOCAL_ALIAS) &&
619 (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
620 !Op->Common.Node)
622 ArgCount = AcpiDmInspectPossibleArgs (0, 0, Op->Common.Next);
625 * Check if namepath is a predicate for if/while or lone parameter to
626 * a return.
628 if (ArgCount == 0)
630 if (((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
631 (ParentOp->Common.AmlOpcode == AML_WHILE_OP) ||
632 (ParentOp->Common.AmlOpcode == AML_RETURN_OP)) &&
634 /* And namepath is the first argument */
635 (ParentOp->Common.Value.Arg == Op))
637 AcpiDmAddOpToExternalList (Op,
638 Op->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
639 break;
644 * This is a standalone namestring (not a parameter to another
645 * operator) - it *must* be a method invocation, nothing else is
646 * grammatically possible.
648 AcpiDmAddOpToExternalList (Op,
649 Op->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
651 break;
653 default:
655 break;
658 return (AE_OK);
662 /*******************************************************************************
664 * FUNCTION: AcpiDmLoadDescendingOp
666 * PARAMETERS: ASL_WALK_CALLBACK
668 * RETURN: Status
670 * DESCRIPTION: Descending handler for namespace control method object load
672 ******************************************************************************/
674 static ACPI_STATUS
675 AcpiDmLoadDescendingOp (
676 ACPI_PARSE_OBJECT *Op,
677 UINT32 Level,
678 void *Context)
680 ACPI_OP_WALK_INFO *Info = Context;
681 const ACPI_OPCODE_INFO *OpInfo;
682 ACPI_WALK_STATE *WalkState;
683 ACPI_OBJECT_TYPE ObjectType;
684 ACPI_STATUS Status;
685 char *Path = NULL;
686 ACPI_PARSE_OBJECT *NextOp;
687 ACPI_NAMESPACE_NODE *Node;
688 char FieldPath[5];
689 BOOLEAN PreDefined = FALSE;
690 UINT8 PreDefineIndex = 0;
693 WalkState = Info->WalkState;
694 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
695 ObjectType = OpInfo->ObjectType;
696 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
698 /* Only interested in operators that create new names */
700 if (!(OpInfo->Flags & AML_NAMED) &&
701 !(OpInfo->Flags & AML_CREATE))
703 goto Exit;
706 /* Get the NamePath from the appropriate place */
708 if (OpInfo->Flags & AML_NAMED)
710 /* For all named operators, get the new name */
712 Path = (char *) Op->Named.Path;
714 if (!Path && Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
716 *ACPI_CAST_PTR (UINT32, &FieldPath[0]) = Op->Named.Name;
717 FieldPath[4] = 0;
718 Path = FieldPath;
721 else if (OpInfo->Flags & AML_CREATE)
723 /* New name is the last child */
725 NextOp = Op->Common.Value.Arg;
727 while (NextOp->Common.Next)
729 NextOp = NextOp->Common.Next;
731 Path = NextOp->Common.Value.String;
734 if (!Path)
736 goto Exit;
739 /* Insert the name into the namespace */
741 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
742 ACPI_IMODE_LOAD_PASS2, ACPI_NS_DONT_OPEN_SCOPE,
743 WalkState, &Node);
745 Op->Common.Node = Node;
747 if (ACPI_SUCCESS (Status))
749 /* Check if it's a predefined node */
751 while (AcpiGbl_PreDefinedNames[PreDefineIndex].Name)
753 if (ACPI_COMPARE_NAME (Node->Name.Ascii,
754 AcpiGbl_PreDefinedNames[PreDefineIndex].Name))
756 PreDefined = TRUE;
757 break;
760 PreDefineIndex++;
764 * Set node owner id if it satisfies all the following conditions:
765 * 1) Not a predefined node, _SB_ etc
766 * 2) Not the root node
767 * 3) Not a node created by Scope
770 if (!PreDefined && Node != AcpiGbl_RootNode &&
771 Op->Common.AmlOpcode != AML_SCOPE_OP)
773 Node->OwnerId = WalkState->OwnerId;
778 Exit:
780 if (AcpiNsOpensScope (ObjectType))
782 if (Op->Common.Node)
784 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
785 if (ACPI_FAILURE (Status))
787 return (Status);
792 return (AE_OK);
796 /*******************************************************************************
798 * FUNCTION: AcpiDmXrefDescendingOp
800 * PARAMETERS: ASL_WALK_CALLBACK
802 * RETURN: Status
804 * DESCRIPTION: Descending handler for namespace cross reference
806 ******************************************************************************/
808 static ACPI_STATUS
809 AcpiDmXrefDescendingOp (
810 ACPI_PARSE_OBJECT *Op,
811 UINT32 Level,
812 void *Context)
814 ACPI_OP_WALK_INFO *Info = Context;
815 const ACPI_OPCODE_INFO *OpInfo;
816 ACPI_WALK_STATE *WalkState;
817 ACPI_OBJECT_TYPE ObjectType;
818 ACPI_OBJECT_TYPE ObjectType2;
819 ACPI_STATUS Status;
820 char *Path = NULL;
821 ACPI_PARSE_OBJECT *NextOp;
822 ACPI_NAMESPACE_NODE *Node;
823 ACPI_OPERAND_OBJECT *Object;
824 UINT32 ParamCount = 0;
825 char *Pathname;
828 WalkState = Info->WalkState;
829 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
830 ObjectType = OpInfo->ObjectType;
831 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
833 if ((!(OpInfo->Flags & AML_NAMED)) &&
834 (!(OpInfo->Flags & AML_CREATE)) &&
835 (Op->Common.AmlOpcode != AML_INT_NAMEPATH_OP) &&
836 (Op->Common.AmlOpcode != AML_NOTIFY_OP))
838 goto Exit;
842 /* Get the NamePath from the appropriate place */
844 if (OpInfo->Flags & AML_NAMED)
847 * Only these two operators (Alias, Scope) refer to an existing
848 * name, it is the first argument
850 if (Op->Common.AmlOpcode == AML_ALIAS_OP)
852 ObjectType = ACPI_TYPE_ANY;
854 NextOp = Op->Common.Value.Arg;
855 NextOp = NextOp->Common.Value.Arg;
856 if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
858 Path = NextOp->Common.Value.String;
861 else if (Op->Common.AmlOpcode == AML_SCOPE_OP)
863 Path = (char *) Op->Named.Path;
866 else if (OpInfo->Flags & AML_CREATE)
868 /* Referenced Buffer Name is the first child */
870 ObjectType = ACPI_TYPE_BUFFER; /* Change from TYPE_BUFFER_FIELD */
872 NextOp = Op->Common.Value.Arg;
873 if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
875 Path = NextOp->Common.Value.String;
878 else if (Op->Common.AmlOpcode == AML_NOTIFY_OP)
880 Path = Op->Common.Value.Arg->Asl.Value.String;
882 else
884 Path = Op->Common.Value.String;
887 if (!Path)
889 goto Exit;
893 * Lookup the name in the namespace. Name must exist at this point, or it
894 * is an invalid reference.
896 * The namespace is also used as a lookup table for references to resource
897 * descriptors and the fields within them.
899 Node = NULL;
900 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
901 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
902 WalkState, &Node);
903 if (ACPI_SUCCESS (Status) && (Node->Flags & ANOBJ_IS_EXTERNAL))
905 /* Node was created by an External() statement */
907 Status = AE_NOT_FOUND;
910 if (ACPI_FAILURE (Status))
912 if (Status == AE_NOT_FOUND)
915 * Add this symbol as an external declaration, except if the
916 * parent is a CondRefOf operator. For this operator, we do not
917 * need an external, nor do we want one, since this can cause
918 * disassembly problems if the symbol is actually a control
919 * method.
921 if (!(Op->Asl.Parent &&
922 (Op->Asl.Parent->Asl.AmlOpcode == AML_COND_REF_OF_OP)))
924 if (Node)
926 AcpiDmAddNodeToExternalList (Node,
927 (UINT8) ObjectType, 0, 0);
929 else
931 AcpiDmAddOpToExternalList (Op, Path,
932 (UINT8) ObjectType, 0, 0);
939 * Found the node, but check if it came from an external table.
940 * Add it to external list. Note: Node->OwnerId == 0 indicates
941 * one of the built-in ACPI Names (_OS_ etc.) which can safely
942 * be ignored.
944 else if (Node->OwnerId &&
945 (WalkState->OwnerId != Node->OwnerId))
947 ObjectType2 = ObjectType;
949 Object = AcpiNsGetAttachedObject (Node);
950 if (Object)
952 ObjectType2 = Object->Common.Type;
953 if (ObjectType2 == ACPI_TYPE_METHOD)
955 ParamCount = Object->Method.ParamCount;
959 Pathname = AcpiNsGetExternalPathname (Node);
960 if (!Pathname)
962 return (AE_NO_MEMORY);
965 AcpiDmAddNodeToExternalList (Node, (UINT8) ObjectType2,
966 ParamCount, ACPI_EXT_RESOLVED_REFERENCE);
968 ACPI_FREE (Pathname);
969 Op->Common.Node = Node;
971 else
973 Op->Common.Node = Node;
977 Exit:
978 /* Open new scope if necessary */
980 if (AcpiNsOpensScope (ObjectType))
982 if (Op->Common.Node)
984 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
985 if (ACPI_FAILURE (Status))
987 return (Status);
992 return (AE_OK);
996 /*******************************************************************************
998 * FUNCTION: AcpiDmResourceDescendingOp
1000 * PARAMETERS: ASL_WALK_CALLBACK
1002 * RETURN: None
1004 * DESCRIPTION: Process one parse op during symbolic resource index conversion.
1006 ******************************************************************************/
1008 static ACPI_STATUS
1009 AcpiDmResourceDescendingOp (
1010 ACPI_PARSE_OBJECT *Op,
1011 UINT32 Level,
1012 void *Context)
1014 ACPI_OP_WALK_INFO *Info = Context;
1015 const ACPI_OPCODE_INFO *OpInfo;
1016 ACPI_WALK_STATE *WalkState;
1017 ACPI_OBJECT_TYPE ObjectType;
1018 ACPI_STATUS Status;
1021 WalkState = Info->WalkState;
1022 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1024 /* Open new scope if necessary */
1026 ObjectType = OpInfo->ObjectType;
1027 if (AcpiNsOpensScope (ObjectType))
1029 if (Op->Common.Node)
1032 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType, WalkState);
1033 if (ACPI_FAILURE (Status))
1035 return (Status);
1041 * Check if this operator contains a reference to a resource descriptor.
1042 * If so, convert the reference into a symbolic reference.
1044 AcpiDmCheckResourceReference (Op, WalkState);
1045 return (AE_OK);
1049 /*******************************************************************************
1051 * FUNCTION: AcpiDmCommonAscendingOp
1053 * PARAMETERS: ASL_WALK_CALLBACK
1055 * RETURN: None
1057 * DESCRIPTION: Ascending handler for combined parse/namespace walks. Closes
1058 * scope if necessary.
1060 ******************************************************************************/
1062 static ACPI_STATUS
1063 AcpiDmCommonAscendingOp (
1064 ACPI_PARSE_OBJECT *Op,
1065 UINT32 Level,
1066 void *Context)
1068 ACPI_OP_WALK_INFO *Info = Context;
1069 const ACPI_OPCODE_INFO *OpInfo;
1070 ACPI_OBJECT_TYPE ObjectType;
1073 /* Close scope if necessary */
1075 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1076 ObjectType = OpInfo->ObjectType;
1077 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1079 if (AcpiNsOpensScope (ObjectType))
1081 (void) AcpiDsScopeStackPop (Info->WalkState);
1084 return (AE_OK);
1088 /*******************************************************************************
1090 * FUNCTION: AcpiDmInspectPossibleArgs
1092 * PARAMETERS: CurrentOpArgCount - Which arg of the current op was the
1093 * possible method invocation found
1094 * TargetCount - Number of targets (0,1,2) for this op
1095 * Op - Parse op
1097 * RETURN: Status
1099 * DESCRIPTION: Examine following args and next ops for possible arguments
1100 * for an unrecognized method invocation.
1102 ******************************************************************************/
1104 static UINT32
1105 AcpiDmInspectPossibleArgs (
1106 UINT32 CurrentOpArgCount,
1107 UINT32 TargetCount,
1108 ACPI_PARSE_OBJECT *Op)
1110 const ACPI_OPCODE_INFO *OpInfo;
1111 UINT32 i;
1112 UINT32 Last = 0;
1113 UINT32 Lookahead;
1116 Lookahead = (ACPI_METHOD_NUM_ARGS + TargetCount) - CurrentOpArgCount;
1118 /* Lookahead for the maximum number of possible arguments */
1120 for (i = 0; i < Lookahead; i++)
1122 if (!Op)
1124 break;
1127 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1130 * Any one of these operators is "very probably" not a method arg
1132 if ((Op->Common.AmlOpcode == AML_STORE_OP) ||
1133 (Op->Common.AmlOpcode == AML_NOTIFY_OP))
1135 break;
1138 if ((OpInfo->Class != AML_CLASS_EXECUTE) &&
1139 (OpInfo->Class != AML_CLASS_CONTROL))
1141 Last = i+1;
1144 Op = Op->Common.Next;
1147 return (Last);