1ddbd7b91SNathan Whitehorn/******************************************************************************
2ddbd7b91SNathan Whitehorn *
3ddbd7b91SNathan Whitehorn * Module Name: pswalk - Parser routines to walk parsed op tree(s)
4ddbd7b91SNathan Whitehorn *
5ddbd7b91SNathan Whitehorn *****************************************************************************/
6ddbd7b91SNathan Whitehorn
7ddbd7b91SNathan Whitehorn/******************************************************************************
8ddbd7b91SNathan Whitehorn *
9ddbd7b91SNathan Whitehorn * 1. Copyright Notice
10ddbd7b91SNathan Whitehorn *
11ff2e2f81SFredrik Holmqvist * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12ddbd7b91SNathan Whitehorn * All rights reserved.
13ddbd7b91SNathan Whitehorn *
14ddbd7b91SNathan Whitehorn * 2. License
15ddbd7b91SNathan Whitehorn *
16ddbd7b91SNathan Whitehorn * 2.1. This is your license from Intel Corp. under its intellectual property
179b0d045cSFredrik Holmqvist * rights. You may have additional license terms from the party that provided
18ddbd7b91SNathan Whitehorn * you this software, covering your right to use that party's intellectual
19ddbd7b91SNathan Whitehorn * property rights.
20ddbd7b91SNathan Whitehorn *
21ddbd7b91SNathan Whitehorn * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22ddbd7b91SNathan Whitehorn * copy of the source code appearing in this file ("Covered Code") an
23ddbd7b91SNathan Whitehorn * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24ddbd7b91SNathan Whitehorn * base code distributed originally by Intel ("Original Intel Code") to copy,
25ddbd7b91SNathan Whitehorn * make derivatives, distribute, use and display any portion of the Covered
26ddbd7b91SNathan Whitehorn * Code in any form, with the right to sublicense such rights; and
27ddbd7b91SNathan Whitehorn *
28ddbd7b91SNathan Whitehorn * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29ddbd7b91SNathan Whitehorn * license (with the right to sublicense), under only those claims of Intel
30ddbd7b91SNathan Whitehorn * patents that are infringed by the Original Intel Code, to make, use, sell,
31ddbd7b91SNathan Whitehorn * offer to sell, and import the Covered Code and derivative works thereof
32ddbd7b91SNathan Whitehorn * solely to the minimum extent necessary to exercise the above copyright
33ddbd7b91SNathan Whitehorn * license, and in no event shall the patent license extend to any additions
349b0d045cSFredrik Holmqvist * to or modifications of the Original Intel Code. No other license or right
35ddbd7b91SNathan Whitehorn * is granted directly or by implication, estoppel or otherwise;
36ddbd7b91SNathan Whitehorn *
37ddbd7b91SNathan Whitehorn * The above copyright and patent license is granted only if the following
38ddbd7b91SNathan Whitehorn * conditions are met:
39ddbd7b91SNathan Whitehorn *
40ddbd7b91SNathan Whitehorn * 3. Conditions
41ddbd7b91SNathan Whitehorn *
42ddbd7b91SNathan Whitehorn * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43ddbd7b91SNathan Whitehorn * Redistribution of source code of any substantial portion of the Covered
44ddbd7b91SNathan Whitehorn * Code or modification with rights to further distribute source must include
45ddbd7b91SNathan Whitehorn * the above Copyright Notice, the above License, this list of Conditions,
469b0d045cSFredrik Holmqvist * and the following Disclaimer and Export Compliance provision. In addition,
47ddbd7b91SNathan Whitehorn * Licensee must cause all Covered Code to which Licensee contributes to
48ddbd7b91SNathan Whitehorn * contain a file documenting the changes Licensee made to create that Covered
499b0d045cSFredrik Holmqvist * Code and the date of any change. Licensee must include in that file the
509b0d045cSFredrik Holmqvist * documentation of any changes made by any predecessor Licensee. Licensee
51ddbd7b91SNathan Whitehorn * must include a prominent statement that the modification is derived,
52ddbd7b91SNathan Whitehorn * directly or indirectly, from Original Intel Code.
53ddbd7b91SNathan Whitehorn *
54ddbd7b91SNathan Whitehorn * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55ddbd7b91SNathan Whitehorn * Redistribution of source code of any substantial portion of the Covered
56ddbd7b91SNathan Whitehorn * Code or modification without rights to further distribute source must
57ddbd7b91SNathan Whitehorn * include the following Disclaimer and Export Compliance provision in the
589b0d045cSFredrik Holmqvist * documentation and/or other materials provided with distribution. In
59ddbd7b91SNathan Whitehorn * addition, Licensee may not authorize further sublicense of source of any
60ddbd7b91SNathan Whitehorn * portion of the Covered Code, and must include terms to the effect that the
61ddbd7b91SNathan Whitehorn * license from Licensee to its licensee is limited to the intellectual
62ddbd7b91SNathan Whitehorn * property embodied in the software Licensee provides to its licensee, and
63ddbd7b91SNathan Whitehorn * not to intellectual property embodied in modifications its licensee may
64ddbd7b91SNathan Whitehorn * make.
65ddbd7b91SNathan Whitehorn *
66ddbd7b91SNathan Whitehorn * 3.3. Redistribution of Executable. Redistribution in executable form of any
67ddbd7b91SNathan Whitehorn * substantial portion of the Covered Code or modification must reproduce the
68ddbd7b91SNathan Whitehorn * above Copyright Notice, and the following Disclaimer and Export Compliance
69ddbd7b91SNathan Whitehorn * provision in the documentation and/or other materials provided with the
70ddbd7b91SNathan Whitehorn * distribution.
71ddbd7b91SNathan Whitehorn *
72ddbd7b91SNathan Whitehorn * 3.4. Intel retains all right, title, and interest in and to the Original
73ddbd7b91SNathan Whitehorn * Intel Code.
74ddbd7b91SNathan Whitehorn *
75ddbd7b91SNathan Whitehorn * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76ddbd7b91SNathan Whitehorn * Intel shall be used in advertising or otherwise to promote the sale, use or
77ddbd7b91SNathan Whitehorn * other dealings in products derived from or relating to the Covered Code
78ddbd7b91SNathan Whitehorn * without prior written authorization from Intel.
79ddbd7b91SNathan Whitehorn *
80ddbd7b91SNathan Whitehorn * 4. Disclaimer and Export Compliance
81ddbd7b91SNathan Whitehorn *
82ddbd7b91SNathan Whitehorn * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
839b0d045cSFredrik Holmqvist * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
849b0d045cSFredrik Holmqvist * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
859b0d045cSFredrik Holmqvist * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
869b0d045cSFredrik Holmqvist * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87ddbd7b91SNathan Whitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88ddbd7b91SNathan Whitehorn * PARTICULAR PURPOSE.
89ddbd7b91SNathan Whitehorn *
90ddbd7b91SNathan Whitehorn * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91ddbd7b91SNathan Whitehorn * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92ddbd7b91SNathan Whitehorn * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93ddbd7b91SNathan Whitehorn * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94ddbd7b91SNathan Whitehorn * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
959b0d045cSFredrik Holmqvist * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96ddbd7b91SNathan Whitehorn * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97ddbd7b91SNathan Whitehorn * LIMITED REMEDY.
98ddbd7b91SNathan Whitehorn *
99ddbd7b91SNathan Whitehorn * 4.3. Licensee shall not export, either directly or indirectly, any of this
100ddbd7b91SNathan Whitehorn * software or system incorporating such software without first obtaining any
101ddbd7b91SNathan Whitehorn * required license or other approval from the U. S. Department of Commerce or
1029b0d045cSFredrik Holmqvist * any other agency or department of the United States Government. In the
103ddbd7b91SNathan Whitehorn * event Licensee exports any such software from the United States or
104ddbd7b91SNathan Whitehorn * re-exports any such software from a foreign destination, Licensee shall
105ddbd7b91SNathan Whitehorn * ensure that the distribution and export/re-export of the software is in
106ddbd7b91SNathan Whitehorn * compliance with all laws, regulations, orders, or other restrictions of the
107ddbd7b91SNathan Whitehorn * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108ddbd7b91SNathan Whitehorn * any of its subsidiaries will export/re-export any technical data, process,
109ddbd7b91SNathan Whitehorn * software, or service, directly or indirectly, to any country for which the
110ddbd7b91SNathan Whitehorn * United States government or any agency thereof requires an export license,
111ddbd7b91SNathan Whitehorn * other governmental approval, or letter of assurance, without first obtaining
112ddbd7b91SNathan Whitehorn * such license, approval or letter.
113ddbd7b91SNathan Whitehorn *
114ff2e2f81SFredrik Holmqvist *****************************************************************************
115ff2e2f81SFredrik Holmqvist *
116ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist * following license:
118ff2e2f81SFredrik Holmqvist *
119ff2e2f81SFredrik Holmqvist * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist * are met:
122ff2e2f81SFredrik Holmqvist * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist *    notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist *    without modification.
125ff2e2f81SFredrik Holmqvist * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist *    substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist *    ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist *    including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist *    binary redistribution.
130ff2e2f81SFredrik Holmqvist * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist *    of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist *    from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist *
134ff2e2f81SFredrik Holmqvist * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist *
146ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist * Software Foundation.
149ff2e2f81SFredrik Holmqvist *
150ddbd7b91SNathan Whitehorn *****************************************************************************/
151ddbd7b91SNathan Whitehorn
152ddbd7b91SNathan Whitehorn#include "acpi.h"
15380377d9aSJérôme Duval#include "accommon.h"
154ddbd7b91SNathan Whitehorn#include "acparser.h"
155ddbd7b91SNathan Whitehorn
156ddbd7b91SNathan Whitehorn#define _COMPONENT          ACPI_PARSER
157ddbd7b91SNathan Whitehorn        ACPI_MODULE_NAME    ("pswalk")
158ddbd7b91SNathan Whitehorn
159ddbd7b91SNathan Whitehorn
160ddbd7b91SNathan Whitehorn/*******************************************************************************
161ddbd7b91SNathan Whitehorn *
16252c415a8SNathan Whitehorn * FUNCTION:    AcpiPsDeleteParseTree
163ddbd7b91SNathan Whitehorn *
16452c415a8SNathan Whitehorn * PARAMETERS:  SubtreeRoot         - Root of tree (or subtree) to delete
165ddbd7b91SNathan Whitehorn *
16652c415a8SNathan Whitehorn * RETURN:      None
167ddbd7b91SNathan Whitehorn *
16852c415a8SNathan Whitehorn * DESCRIPTION: Delete a portion of or an entire parse tree.
169ddbd7b91SNathan Whitehorn *
170ddbd7b91SNathan Whitehorn ******************************************************************************/
171ddbd7b91SNathan Whitehorn
17208c9948cSFredrik Holmqvist#include "amlcode.h"
17308c9948cSFredrik Holmqvist
17452c415a8SNathan Whitehornvoid
17552c415a8SNathan WhitehornAcpiPsDeleteParseTree (
17652c415a8SNathan Whitehorn    ACPI_PARSE_OBJECT       *SubtreeRoot)
177ddbd7b91SNathan Whitehorn{
17852c415a8SNathan Whitehorn    ACPI_PARSE_OBJECT       *Op = SubtreeRoot;
17952c415a8SNathan Whitehorn    ACPI_PARSE_OBJECT       *Next = NULL;
18052c415a8SNathan Whitehorn    ACPI_PARSE_OBJECT       *Parent = NULL;
18108c9948cSFredrik Holmqvist    UINT32                  Level = 0;
182ddbd7b91SNathan Whitehorn
183ddbd7b91SNathan Whitehorn
18443547dbeSJérôme Duval    ACPI_FUNCTION_TRACE_PTR (PsDeleteParseTree, SubtreeRoot);
185ddbd7b91SNathan Whitehorn
18608c9948cSFredrik Holmqvist    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE_TREES,
18708c9948cSFredrik Holmqvist        " root %p\n", SubtreeRoot));
188ddbd7b91SNathan Whitehorn
18952c415a8SNathan Whitehorn    /* Visit all nodes in the subtree */
190ddbd7b91SNathan Whitehorn
19152c415a8SNathan Whitehorn    while (Op)
192ddbd7b91SNathan Whitehorn    {
19352c415a8SNathan Whitehorn        if (Op != Parent)
194ddbd7b91SNathan Whitehorn        {
19508c9948cSFredrik Holmqvist            /* This is the descending case */
19608c9948cSFredrik Holmqvist
19708c9948cSFredrik Holmqvist            if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_PARSE_TREES, _COMPONENT))
19808c9948cSFredrik Holmqvist            {
19908c9948cSFredrik Holmqvist                /* This debug option will print the entire parse tree */
20008c9948cSFredrik Holmqvist
20108c9948cSFredrik Holmqvist                AcpiOsPrintf ("        %*.s%s %p", (Level * 4), " ",
20208c9948cSFredrik Holmqvist                    AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Op);
20308c9948cSFredrik Holmqvist
20408c9948cSFredrik Holmqvist                if (Op->Named.AmlOpcode == AML_INT_NAMEPATH_OP)
20508c9948cSFredrik Holmqvist                {
20608c9948cSFredrik Holmqvist                    AcpiOsPrintf ("    %4.4s", Op->Common.Value.String);
20708c9948cSFredrik Holmqvist                }
20808c9948cSFredrik Holmqvist                if (Op->Named.AmlOpcode == AML_STRING_OP)
20908c9948cSFredrik Holmqvist                {
21008c9948cSFredrik Holmqvist                    AcpiOsPrintf ("    %s", Op->Common.Value.String);
21108c9948cSFredrik Holmqvist                }
21208c9948cSFredrik Holmqvist                AcpiOsPrintf ("\n");
21308c9948cSFredrik Holmqvist            }
21408c9948cSFredrik Holmqvist
21552c415a8SNathan Whitehorn            /* Look for an argument or child of the current op */
216ddbd7b91SNathan Whitehorn
21752c415a8SNathan Whitehorn            Next = AcpiPsGetArg (Op, 0);
21852c415a8SNathan Whitehorn            if (Next)
21952c415a8SNathan Whitehorn            {
22052c415a8SNathan Whitehorn                /* Still going downward in tree (Op is not completed yet) */
221ddbd7b91SNathan Whitehorn
22252c415a8SNathan Whitehorn                Op = Next;
22308c9948cSFredrik Holmqvist                Level++;
22452c415a8SNathan Whitehorn                continue;
22552c415a8SNathan Whitehorn            }
226ddbd7b91SNathan Whitehorn        }
227ddbd7b91SNathan Whitehorn
22843547dbeSJérôme Duval        /* No more children, this Op is complete. */
22943547dbeSJérôme Duval
23052c415a8SNathan Whitehorn        Next = Op->Common.Next;
23152c415a8SNathan Whitehorn        Parent = Op->Common.Parent;
232ddbd7b91SNathan Whitehorn
23352c415a8SNathan Whitehorn        AcpiPsFreeOp (Op);
234ddbd7b91SNathan Whitehorn
23543547dbeSJérôme Duval        /* If we are back to the starting point, the walk is complete. */
23643547dbeSJérôme Duval
23752c415a8SNathan Whitehorn        if (Op == SubtreeRoot)
238ddbd7b91SNathan Whitehorn        {
23952c415a8SNathan Whitehorn            return_VOID;
240ddbd7b91SNathan Whitehorn        }
241b64e8511SFredrik Holmqvist
242ddbd7b91SNathan Whitehorn        if (Next)
243ddbd7b91SNathan Whitehorn        {
24452c415a8SNathan Whitehorn            Op = Next;
245ddbd7b91SNathan Whitehorn        }
24652c415a8SNathan Whitehorn        else
247ddbd7b91SNathan Whitehorn        {
24808c9948cSFredrik Holmqvist            Level--;
24952c415a8SNathan Whitehorn            Op = Parent;
250ddbd7b91SNathan Whitehorn        }
251ddbd7b91SNathan Whitehorn    }
25243547dbeSJérôme Duval
253ddbd7b91SNathan Whitehorn    return_VOID;
254ddbd7b91SNathan Whitehorn}
255