Sync ACPICA with Intel's version 20170831.
[dragonfly.git] / sys / contrib / dev / acpica / source / compiler / asltree.c
blob084bc4d59ac98b52e7938dc563059514e00488ba
1 /******************************************************************************
3 * Module Name: asltree - Parse tree management
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2017, 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 "aslcompiler.h"
153 #include "aslcompiler.y.h"
154 #include "acapps.h"
156 #define _COMPONENT ACPI_COMPILER
157 ACPI_MODULE_NAME ("asltree")
160 /*******************************************************************************
162 * FUNCTION: TrSetOpIntegerValue
164 * PARAMETERS: ParseOpcode - New opcode to be assigned to the op
165 * Op - An existing parse op
167 * RETURN: The updated op
169 * DESCRIPTION: Used to set the integer value of a op,
170 * usually to a specific size (8, 16, 32, or 64 bits)
172 ******************************************************************************/
174 ACPI_PARSE_OBJECT *
175 TrSetOpIntegerValue (
176 UINT32 ParseOpcode,
177 ACPI_PARSE_OBJECT *Op)
180 if (!Op)
182 return (NULL);
185 DbgPrint (ASL_PARSE_OUTPUT,
186 "\nUpdateOp: Old - %s, New - %s\n",
187 UtGetOpName (Op->Asl.ParseOpcode),
188 UtGetOpName (ParseOpcode));
190 /* Assign new opcode and name */
192 if (Op->Asl.ParseOpcode == PARSEOP_ONES)
194 switch (ParseOpcode)
196 case PARSEOP_BYTECONST:
198 Op->Asl.Value.Integer = ACPI_UINT8_MAX;
199 break;
201 case PARSEOP_WORDCONST:
203 Op->Asl.Value.Integer = ACPI_UINT16_MAX;
204 break;
206 case PARSEOP_DWORDCONST:
208 Op->Asl.Value.Integer = ACPI_UINT32_MAX;
209 break;
211 /* Don't need to do the QWORD case */
213 default:
215 /* Don't care about others */
216 break;
220 Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
221 UtSetParseOpName (Op);
224 * For the BYTE, WORD, and DWORD constants, make sure that the integer
225 * that was passed in will actually fit into the data type
227 switch (ParseOpcode)
229 case PARSEOP_BYTECONST:
231 UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX);
232 Op->Asl.Value.Integer &= ACPI_UINT8_MAX;
233 break;
235 case PARSEOP_WORDCONST:
237 UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX);
238 Op->Asl.Value.Integer &= ACPI_UINT16_MAX;
239 break;
241 case PARSEOP_DWORDCONST:
243 UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX);
244 Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
245 break;
247 default:
249 /* Don't care about others, don't need to check QWORD */
251 break;
254 /* Converter: if this is a method invocation, turn off capture comments */
256 if (Gbl_CaptureComments &&
257 (ParseOpcode == PARSEOP_METHODCALL))
259 Gbl_CommentState.CaptureComments = FALSE;
262 return (Op);
266 /*******************************************************************************
268 * FUNCTION: TrSetOpFlags
270 * PARAMETERS: Op - An existing parse op
271 * Flags - New flags word
273 * RETURN: The updated parser op
275 * DESCRIPTION: Set bits in the op flags word. Will not clear bits, only set
277 ******************************************************************************/
279 ACPI_PARSE_OBJECT *
280 TrSetOpFlags (
281 ACPI_PARSE_OBJECT *Op,
282 UINT32 Flags)
285 if (!Op)
287 return (NULL);
290 DbgPrint (ASL_PARSE_OUTPUT,
291 "\nSetOpFlags: %s Op %p, %8.8X", Op->Asl.ParseOpName, Op, Flags);
293 TrPrintOpFlags (Flags, ASL_PARSE_OUTPUT);
294 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
296 Op->Asl.CompileFlags |= Flags;
297 return (Op);
301 /*******************************************************************************
303 * FUNCTION: TrSetOpAmlLength
305 * PARAMETERS: Op - An existing parse op
306 * Length - AML Length
308 * RETURN: The updated parser op
310 * DESCRIPTION: Set the AML Length in a op. Used by the parser to indicate
311 * the presence of a op that must be reduced to a fixed length
312 * constant.
314 ******************************************************************************/
316 ACPI_PARSE_OBJECT *
317 TrSetOpAmlLength (
318 ACPI_PARSE_OBJECT *Op,
319 UINT32 Length)
322 DbgPrint (ASL_PARSE_OUTPUT,
323 "\nSetOpAmlLength: Op %p, %8.8X\n", Op, Length);
325 if (!Op)
327 return (NULL);
330 Op->Asl.AmlLength = Length;
331 return (Op);
335 /*******************************************************************************
337 * FUNCTION: TrSetOpParent
339 * PARAMETERS: Op - To be set to new parent
340 * ParentOp - The parent
342 * RETURN: None, sets Op parent directly
344 * DESCRIPTION: Change the parent of a parse op.
346 ******************************************************************************/
348 void
349 TrSetOpParent (
350 ACPI_PARSE_OBJECT *Op,
351 ACPI_PARSE_OBJECT *ParentOp)
354 Op->Asl.Parent = ParentOp;
358 /*******************************************************************************
360 * FUNCTION: TrSetOpCurrentFilename
362 * PARAMETERS: Op - An existing parse op
364 * RETURN: None
366 * DESCRIPTION: Save the include file filename. Used for debug output only.
368 ******************************************************************************/
370 void
371 TrSetOpCurrentFilename (
372 ACPI_PARSE_OBJECT *Op)
375 Op->Asl.Filename = Gbl_PreviousIncludeFilename;
379 /*******************************************************************************
381 * FUNCTION: TrSetOpIntegerWidth
383 * PARAMETERS: Op - An existing parse op
385 * RETURN: None
387 * DESCRIPTION:
389 ******************************************************************************/
391 void
392 TrSetOpIntegerWidth (
393 ACPI_PARSE_OBJECT *TableSignatureOp,
394 ACPI_PARSE_OBJECT *RevisionOp)
397 /* TBD: Check table sig? (DSDT vs. SSDT) */
399 /* Handle command-line version override */
401 if (Gbl_RevisionOverride)
403 AcpiUtSetIntegerWidth (Gbl_RevisionOverride);
405 else
407 AcpiUtSetIntegerWidth ((UINT8) RevisionOp->Asl.Value.Integer);
412 /*******************************************************************************
414 * FUNCTION: TrSetOpEndLineNumber
416 * PARAMETERS: Op - An existing parse op
418 * RETURN: None.
420 * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
421 * parse op to the current line numbers.
423 ******************************************************************************/
425 void
426 TrSetOpEndLineNumber (
427 ACPI_PARSE_OBJECT *Op)
430 /* If the end line # is already set, just return */
432 if (Op->Asl.EndLine)
434 return;
437 Op->Asl.EndLine = Gbl_CurrentLineNumber;
438 Op->Asl.EndLogicalLine = Gbl_LogicalLineNumber;
442 /*******************************************************************************
444 * FUNCTION: TrLinkOpChildren
446 * PARAMETERS: Op - An existing parse op
447 * NumChildren - Number of children to follow
448 * ... - A list of child ops to link to the new
449 * op. NumChildren long.
451 * RETURN: The updated (linked) op
453 * DESCRIPTION: Link a group of ops to an existing parse op
455 ******************************************************************************/
457 ACPI_PARSE_OBJECT *
458 TrLinkOpChildren (
459 ACPI_PARSE_OBJECT *Op,
460 UINT32 NumChildren,
461 ...)
463 ACPI_PARSE_OBJECT *Child;
464 ACPI_PARSE_OBJECT *PrevChild;
465 va_list ap;
466 UINT32 i;
467 BOOLEAN FirstChild;
470 va_start (ap, NumChildren);
472 TrSetOpEndLineNumber (Op);
474 DbgPrint (ASL_PARSE_OUTPUT,
475 "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ",
476 Op->Asl.LineNumber, Op->Asl.EndLine,
477 Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode));
479 switch (Op->Asl.ParseOpcode)
481 case PARSEOP_ASL_CODE:
483 Gbl_ParseTreeRoot = Op;
484 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
485 DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");
486 break;
488 case PARSEOP_DEFINITION_BLOCK:
490 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
491 break;
493 case PARSEOP_OPERATIONREGION:
495 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
496 break;
498 case PARSEOP_OR:
500 DbgPrint (ASL_PARSE_OUTPUT, "OR->");
501 break;
503 default:
505 /* Nothing to do for other opcodes */
507 break;
510 /* The following is for capturing comments */
512 if(Gbl_CaptureComments)
515 * If there are "regular comments" detected at this point,
516 * then is an endBlk comment. Categorize it as so and distribute
517 * all regular comments to this parse op.
519 if (Gbl_CommentListHead)
521 Op->Asl.EndBlkComment = Gbl_CommentListHead;
522 CvDbgPrint ("EndBlk Comment for %s: %s",
523 Op->Asl.ParseOpName, Gbl_CommentListHead->Comment);
524 Gbl_CommentListHead = NULL;
525 Gbl_CommentListTail = NULL;
529 /* Link the new op to it's children */
531 PrevChild = NULL;
532 FirstChild = TRUE;
533 for (i = 0; i < NumChildren; i++)
535 Child = va_arg (ap, ACPI_PARSE_OBJECT *);
537 if ((Child == PrevChild) && (Child != NULL))
539 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child,
540 "Child op list invalid");
541 va_end(ap);
542 return (Op);
545 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
548 * If child is NULL, this means that an optional argument
549 * was omitted. We must create a placeholder with a special
550 * opcode (DEFAULT_ARG) so that the code generator will know
551 * that it must emit the correct default for this argument
553 if (!Child)
555 Child = TrAllocateOp (PARSEOP_DEFAULT_ARG);
558 /* Link first child to parent */
560 if (FirstChild)
562 FirstChild = FALSE;
563 Op->Asl.Child = Child;
566 /* Point all children to parent */
568 Child->Asl.Parent = Op;
570 /* Link children in a peer list */
572 if (PrevChild)
574 PrevChild->Asl.Next = Child;
578 * This child might be a list, point all ops in the list
579 * to the same parent
581 while (Child->Asl.Next)
583 Child = Child->Asl.Next;
584 Child->Asl.Parent = Op;
587 PrevChild = Child;
590 va_end(ap);
591 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
593 if(Gbl_CaptureComments)
595 Gbl_CommentState.LatestParseOp = Op;
596 CvDbgPrint ("TrLinkOpChildren=====Set latest parse op to this op.\n");
599 return (Op);
603 /*******************************************************************************
605 * FUNCTION: TrLinkPeerOp
607 * PARAMETERS: Op1 - First peer
608 * Op2 - Second peer
610 * RETURN: Op1 or the non-null op.
612 * DESCRIPTION: Link two ops as peers. Handles cases where one peer is null.
614 ******************************************************************************/
616 ACPI_PARSE_OBJECT *
617 TrLinkPeerOp (
618 ACPI_PARSE_OBJECT *Op1,
619 ACPI_PARSE_OBJECT *Op2)
621 ACPI_PARSE_OBJECT *Next;
624 DbgPrint (ASL_PARSE_OUTPUT,
625 "\nLinkPeerOp: 1=%p (%s), 2=%p (%s)\n",
626 Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL,
627 Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL);
630 if ((!Op1) && (!Op2))
632 DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null ops!\n");
633 return (Op1);
636 /* If one of the ops is null, just return the non-null op */
638 if (!Op2)
640 return (Op1);
643 if (!Op1)
645 return (Op2);
648 if (Op1 == Op2)
650 DbgPrint (ASL_DEBUG_OUTPUT,
651 "\n************* Internal error, linking op to itself %p\n",
652 Op1);
653 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1,
654 "Linking op to itself");
655 return (Op1);
658 Op1->Asl.Parent = Op2->Asl.Parent;
661 * Op 1 may already have a peer list (such as an IF/ELSE pair),
662 * so we must walk to the end of the list and attach the new
663 * peer at the end
665 Next = Op1;
666 while (Next->Asl.Next)
668 Next = Next->Asl.Next;
671 Next->Asl.Next = Op2;
672 return (Op1);
676 /*******************************************************************************
678 * FUNCTION: TrLinkPeerOps
680 * PARAMETERS: NumPeers - The number of ops in the list to follow
681 * ... - A list of ops to link together as peers
683 * RETURN: The first op in the list (head of the peer list)
685 * DESCRIPTION: Link together an arbitrary number of peer ops.
687 ******************************************************************************/
689 ACPI_PARSE_OBJECT *
690 TrLinkPeerOps (
691 UINT32 NumPeers,
692 ...)
694 ACPI_PARSE_OBJECT *This;
695 ACPI_PARSE_OBJECT *Next;
696 va_list ap;
697 UINT32 i;
698 ACPI_PARSE_OBJECT *Start;
701 DbgPrint (ASL_PARSE_OUTPUT,
702 "\nLinkPeerOps: (%u) ", NumPeers);
704 va_start (ap, NumPeers);
705 This = va_arg (ap, ACPI_PARSE_OBJECT *);
706 Start = This;
709 * Link all peers
711 for (i = 0; i < (NumPeers -1); i++)
713 DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This);
715 while (This->Asl.Next)
717 This = This->Asl.Next;
720 /* Get another peer op */
722 Next = va_arg (ap, ACPI_PARSE_OBJECT *);
723 if (!Next)
725 Next = TrAllocateOp (PARSEOP_DEFAULT_ARG);
728 /* link new op to the current op */
730 This->Asl.Next = Next;
731 This = Next;
734 va_end (ap);
735 DbgPrint (ASL_PARSE_OUTPUT,"\n");
736 return (Start);
740 /*******************************************************************************
742 * FUNCTION: TrLinkChildOp
744 * PARAMETERS: Op1 - Parent op
745 * Op2 - Op to become a child
747 * RETURN: The parent op
749 * DESCRIPTION: Link two ops together as a parent and child
751 ******************************************************************************/
753 ACPI_PARSE_OBJECT *
754 TrLinkChildOp (
755 ACPI_PARSE_OBJECT *Op1,
756 ACPI_PARSE_OBJECT *Op2)
758 ACPI_PARSE_OBJECT *Next;
761 DbgPrint (ASL_PARSE_OUTPUT,
762 "\nLinkChildOp: Parent=%p (%s), Child=%p (%s)\n",
763 Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL,
764 Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL);
767 * Converter: if TrLinkChildOp is called to link a method call,
768 * turn on capture comments as it signifies that we are done parsing
769 * a method call.
771 if (Gbl_CaptureComments && Op1)
773 if (Op1->Asl.ParseOpcode == PARSEOP_METHODCALL)
775 Gbl_CommentState.CaptureComments = TRUE;
777 Gbl_CommentState.LatestParseOp = Op1;
780 if (!Op1 || !Op2)
782 return (Op1);
785 Op1->Asl.Child = Op2;
787 /* Set the child and all peers of the child to point to the parent */
789 Next = Op2;
790 while (Next)
792 Next->Asl.Parent = Op1;
793 Next = Next->Asl.Next;
796 return (Op1);
800 /*******************************************************************************
802 * FUNCTION: TrWalkParseTree
804 * PARAMETERS: Op - Walk starting point
805 * Visitation - Type of walk
806 * DescendingCallback - Called during tree descent
807 * AscendingCallback - Called during tree ascent
808 * Context - To be passed to the callbacks
810 * RETURN: Status from callback(s)
812 * DESCRIPTION: Walk the entire parse tree.
814 ******************************************************************************/
816 ACPI_STATUS
817 TrWalkParseTree (
818 ACPI_PARSE_OBJECT *Op,
819 UINT32 Visitation,
820 ASL_WALK_CALLBACK DescendingCallback,
821 ASL_WALK_CALLBACK AscendingCallback,
822 void *Context)
824 UINT32 Level;
825 BOOLEAN OpPreviouslyVisited;
826 ACPI_PARSE_OBJECT *StartOp = Op;
827 ACPI_STATUS Status;
830 if (!Gbl_ParseTreeRoot)
832 return (AE_OK);
835 Level = 0;
836 OpPreviouslyVisited = FALSE;
838 switch (Visitation)
840 case ASL_WALK_VISIT_DOWNWARD:
842 while (Op)
844 if (!OpPreviouslyVisited)
846 /* Let the callback process the op. */
848 Status = DescendingCallback (Op, Level, Context);
849 if (ACPI_SUCCESS (Status))
851 /* Visit children first, once */
853 if (Op->Asl.Child)
855 Level++;
856 Op = Op->Asl.Child;
857 continue;
860 else if (Status != AE_CTRL_DEPTH)
862 /* Exit immediately on any error */
864 return (Status);
868 /* Terminate walk at start op */
870 if (Op == StartOp)
872 break;
875 /* No more children, visit peers */
877 if (Op->Asl.Next)
879 Op = Op->Asl.Next;
880 OpPreviouslyVisited = FALSE;
882 else
884 /* No children or peers, re-visit parent */
886 if (Level != 0 )
888 Level--;
890 Op = Op->Asl.Parent;
891 OpPreviouslyVisited = TRUE;
894 break;
896 case ASL_WALK_VISIT_UPWARD:
898 while (Op)
900 /* Visit leaf op (no children) or parent op on return trip */
902 if ((!Op->Asl.Child) ||
903 (OpPreviouslyVisited))
905 /* Let the callback process the op. */
907 Status = AscendingCallback (Op, Level, Context);
908 if (ACPI_FAILURE (Status))
910 return (Status);
913 else
915 /* Visit children first, once */
917 Level++;
918 Op = Op->Asl.Child;
919 continue;
922 /* Terminate walk at start op */
924 if (Op == StartOp)
926 break;
929 /* No more children, visit peers */
931 if (Op->Asl.Next)
933 Op = Op->Asl.Next;
934 OpPreviouslyVisited = FALSE;
936 else
938 /* No children or peers, re-visit parent */
940 if (Level != 0 )
942 Level--;
944 Op = Op->Asl.Parent;
945 OpPreviouslyVisited = TRUE;
948 break;
950 case ASL_WALK_VISIT_TWICE:
952 while (Op)
954 if (OpPreviouslyVisited)
956 Status = AscendingCallback (Op, Level, Context);
957 if (ACPI_FAILURE (Status))
959 return (Status);
962 else
964 /* Let the callback process the op. */
966 Status = DescendingCallback (Op, Level, Context);
967 if (ACPI_SUCCESS (Status))
969 /* Visit children first, once */
971 if (Op->Asl.Child)
973 Level++;
974 Op = Op->Asl.Child;
975 continue;
978 else if (Status != AE_CTRL_DEPTH)
980 /* Exit immediately on any error */
982 return (Status);
986 /* Terminate walk at start op */
988 if (Op == StartOp)
990 break;
993 /* No more children, visit peers */
995 if (Op->Asl.Next)
997 Op = Op->Asl.Next;
998 OpPreviouslyVisited = FALSE;
1000 else
1002 /* No children or peers, re-visit parent */
1004 if (Level != 0 )
1006 Level--;
1008 Op = Op->Asl.Parent;
1009 OpPreviouslyVisited = TRUE;
1012 break;
1014 default:
1015 /* No other types supported */
1016 break;
1019 /* If we get here, the walk completed with no errors */
1021 return (AE_OK);