1ddbd7b91SNathan Whitehorn/******************************************************************************
2ddbd7b91SNathan Whitehorn *
3ddbd7b91SNathan Whitehorn * Module Name: pstree - Parser op tree manipulation/traversal/search
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#include "amlcode.h"
156ff2e2f81SFredrik Holmqvist#include "acconvert.h"
157ddbd7b91SNathan Whitehorn
158ddbd7b91SNathan Whitehorn#define _COMPONENT          ACPI_PARSER
159ddbd7b91SNathan Whitehorn        ACPI_MODULE_NAME    ("pstree")
160ddbd7b91SNathan Whitehorn
16143547dbeSJérôme Duval/* Local prototypes */
16243547dbeSJérôme Duval
16343547dbeSJérôme Duval#ifdef ACPI_OBSOLETE_FUNCTIONS
16443547dbeSJérôme DuvalACPI_PARSE_OBJECT *
16543547dbeSJérôme DuvalAcpiPsGetChild (
16643547dbeSJérôme Duval    ACPI_PARSE_OBJECT       *op);
16743547dbeSJérôme Duval#endif
16843547dbeSJérôme Duval
169ddbd7b91SNathan Whitehorn
170ddbd7b91SNathan Whitehorn/*******************************************************************************
171ddbd7b91SNathan Whitehorn *
172ddbd7b91SNathan Whitehorn * FUNCTION:    AcpiPsGetArg
173ddbd7b91SNathan Whitehorn *
174ddbd7b91SNathan Whitehorn * PARAMETERS:  Op              - Get an argument for this op
175ddbd7b91SNathan Whitehorn *              Argn            - Nth argument to get
176ddbd7b91SNathan Whitehorn *
17743547dbeSJérôme Duval * RETURN:      The argument (as an Op object). NULL if argument does not exist
178ddbd7b91SNathan Whitehorn *
179ddbd7b91SNathan Whitehorn * DESCRIPTION: Get the specified op's argument.
180ddbd7b91SNathan Whitehorn *
181ddbd7b91SNathan Whitehorn ******************************************************************************/
182ddbd7b91SNathan Whitehorn
183ddbd7b91SNathan WhitehornACPI_PARSE_OBJECT *
184ddbd7b91SNathan WhitehornAcpiPsGetArg (
185ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Op,
186ddbd7b91SNathan Whitehorn    UINT32                  Argn)
187ddbd7b91SNathan Whitehorn{
188ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Arg = NULL;
189ddbd7b91SNathan Whitehorn    const ACPI_OPCODE_INFO  *OpInfo;
190ddbd7b91SNathan Whitehorn
191ddbd7b91SNathan Whitehorn
192ddbd7b91SNathan Whitehorn    ACPI_FUNCTION_ENTRY ();
193ddbd7b91SNathan Whitehorn
1946822cda0SFredrik Holmqvist/*
1956822cda0SFredrik Holmqvist    if (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP)
1966822cda0SFredrik Holmqvist    {
1976822cda0SFredrik Holmqvist        return (Op->Common.Value.Arg);
1986822cda0SFredrik Holmqvist    }
1996822cda0SFredrik Holmqvist*/
200ddbd7b91SNathan Whitehorn    /* Get the info structure for this opcode */
201ddbd7b91SNathan Whitehorn
202ddbd7b91SNathan Whitehorn    OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
203ddbd7b91SNathan Whitehorn    if (OpInfo->Class == AML_CLASS_UNKNOWN)
204ddbd7b91SNathan Whitehorn    {
205ddbd7b91SNathan Whitehorn        /* Invalid opcode or ASCII character */
206ddbd7b91SNathan Whitehorn
207ddbd7b91SNathan Whitehorn        return (NULL);
208ddbd7b91SNathan Whitehorn    }
209ddbd7b91SNathan Whitehorn
210ddbd7b91SNathan Whitehorn    /* Check if this opcode requires argument sub-objects */
211ddbd7b91SNathan Whitehorn
212ddbd7b91SNathan Whitehorn    if (!(OpInfo->Flags & AML_HAS_ARGS))
213ddbd7b91SNathan Whitehorn    {
214ddbd7b91SNathan Whitehorn        /* Has no linked argument objects */
215ddbd7b91SNathan Whitehorn
216ddbd7b91SNathan Whitehorn        return (NULL);
217ddbd7b91SNathan Whitehorn    }
218ddbd7b91SNathan Whitehorn
219ddbd7b91SNathan Whitehorn    /* Get the requested argument object */
220ddbd7b91SNathan Whitehorn
221ddbd7b91SNathan Whitehorn    Arg = Op->Common.Value.Arg;
222ddbd7b91SNathan Whitehorn    while (Arg && Argn)
223ddbd7b91SNathan Whitehorn    {
224ddbd7b91SNathan Whitehorn        Argn--;
225ddbd7b91SNathan Whitehorn        Arg = Arg->Common.Next;
226ddbd7b91SNathan Whitehorn    }
227ddbd7b91SNathan Whitehorn
228ddbd7b91SNathan Whitehorn    return (Arg);
229ddbd7b91SNathan Whitehorn}
230ddbd7b91SNathan Whitehorn
231ddbd7b91SNathan Whitehorn
232ddbd7b91SNathan Whitehorn/*******************************************************************************
233ddbd7b91SNathan Whitehorn *
234ddbd7b91SNathan Whitehorn * FUNCTION:    AcpiPsAppendArg
235ddbd7b91SNathan Whitehorn *
236ddbd7b91SNathan Whitehorn * PARAMETERS:  Op              - Append an argument to this Op.
237ddbd7b91SNathan Whitehorn *              Arg             - Argument Op to append
238ddbd7b91SNathan Whitehorn *
239ddbd7b91SNathan Whitehorn * RETURN:      None.
240ddbd7b91SNathan Whitehorn *
241ddbd7b91SNathan Whitehorn * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
242ddbd7b91SNathan Whitehorn *
243ddbd7b91SNathan Whitehorn ******************************************************************************/
244ddbd7b91SNathan Whitehorn
245ddbd7b91SNathan Whitehornvoid
246ddbd7b91SNathan WhitehornAcpiPsAppendArg (
247ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Op,
248ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Arg)
249ddbd7b91SNathan Whitehorn{
250ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *PrevArg;
251ddbd7b91SNathan Whitehorn    const ACPI_OPCODE_INFO  *OpInfo;
252ddbd7b91SNathan Whitehorn
253ddbd7b91SNathan Whitehorn
254ff2e2f81SFredrik Holmqvist    ACPI_FUNCTION_TRACE (PsAppendArg);
255ddbd7b91SNathan Whitehorn
256ddbd7b91SNathan Whitehorn
257ddbd7b91SNathan Whitehorn    if (!Op)
258ddbd7b91SNathan Whitehorn    {
259ff2e2f81SFredrik Holmqvist        return_VOID;
260ddbd7b91SNathan Whitehorn    }
261ddbd7b91SNathan Whitehorn
262ddbd7b91SNathan Whitehorn    /* Get the info structure for this opcode */
263ddbd7b91SNathan Whitehorn
264ddbd7b91SNathan Whitehorn    OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
265ddbd7b91SNathan Whitehorn    if (OpInfo->Class == AML_CLASS_UNKNOWN)
266ddbd7b91SNathan Whitehorn    {
267ddbd7b91SNathan Whitehorn        /* Invalid opcode */
268ddbd7b91SNathan Whitehorn
26943547dbeSJérôme Duval        ACPI_ERROR ((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
270ddbd7b91SNathan Whitehorn            Op->Common.AmlOpcode));
271ff2e2f81SFredrik Holmqvist        return_VOID;
272ddbd7b91SNathan Whitehorn    }
273ddbd7b91SNathan Whitehorn
274ddbd7b91SNathan Whitehorn    /* Check if this opcode requires argument sub-objects */
275ddbd7b91SNathan Whitehorn
276ddbd7b91SNathan Whitehorn    if (!(OpInfo->Flags & AML_HAS_ARGS))
277ddbd7b91SNathan Whitehorn    {
278ddbd7b91SNathan Whitehorn        /* Has no linked argument objects */
279ddbd7b91SNathan Whitehorn
280ff2e2f81SFredrik Holmqvist        return_VOID;
281ddbd7b91SNathan Whitehorn    }
282ddbd7b91SNathan Whitehorn
283ddbd7b91SNathan Whitehorn    /* Append the argument to the linked argument list */
284ddbd7b91SNathan Whitehorn
285ddbd7b91SNathan Whitehorn    if (Op->Common.Value.Arg)
286ddbd7b91SNathan Whitehorn    {
287ddbd7b91SNathan Whitehorn        /* Append to existing argument list */
288ddbd7b91SNathan Whitehorn
289ddbd7b91SNathan Whitehorn        PrevArg = Op->Common.Value.Arg;
290ddbd7b91SNathan Whitehorn        while (PrevArg->Common.Next)
291ddbd7b91SNathan Whitehorn        {
292ddbd7b91SNathan Whitehorn            PrevArg = PrevArg->Common.Next;
293ddbd7b91SNathan Whitehorn        }
294ddbd7b91SNathan Whitehorn        PrevArg->Common.Next = Arg;
295ddbd7b91SNathan Whitehorn    }
296ddbd7b91SNathan Whitehorn    else
297ddbd7b91SNathan Whitehorn    {
298ddbd7b91SNathan Whitehorn        /* No argument list, this will be the first argument */
299ddbd7b91SNathan Whitehorn
300ddbd7b91SNathan Whitehorn        Op->Common.Value.Arg = Arg;
301ddbd7b91SNathan Whitehorn    }
302ddbd7b91SNathan Whitehorn
303ddbd7b91SNathan Whitehorn    /* Set the parent in this arg and any args linked after it */
304ddbd7b91SNathan Whitehorn
305ddbd7b91SNathan Whitehorn    while (Arg)
306ddbd7b91SNathan Whitehorn    {
307ddbd7b91SNathan Whitehorn        Arg->Common.Parent = Op;
308ddbd7b91SNathan Whitehorn        Arg = Arg->Common.Next;
3092608583eSJérôme Duval
3102608583eSJérôme Duval        Op->Common.ArgListLength++;
311ddbd7b91SNathan Whitehorn    }
312ff2e2f81SFredrik Holmqvist
313ff2e2f81SFredrik Holmqvist    return_VOID;
314ddbd7b91SNathan Whitehorn}
315ddbd7b91SNathan Whitehorn
316ddbd7b91SNathan Whitehorn
317ddbd7b91SNathan Whitehorn/*******************************************************************************
318ddbd7b91SNathan Whitehorn *
319ddbd7b91SNathan Whitehorn * FUNCTION:    AcpiPsGetDepthNext
320ddbd7b91SNathan Whitehorn *
321ddbd7b91SNathan Whitehorn * PARAMETERS:  Origin          - Root of subtree to search
322ddbd7b91SNathan Whitehorn *              Op              - Last (previous) Op that was found
323ddbd7b91SNathan Whitehorn *
324ddbd7b91SNathan Whitehorn * RETURN:      Next Op found in the search.
325ddbd7b91SNathan Whitehorn *
326ddbd7b91SNathan Whitehorn * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
327ddbd7b91SNathan Whitehorn *              Return NULL when reaching "origin" or when walking up from root
328ddbd7b91SNathan Whitehorn *
329ddbd7b91SNathan Whitehorn ******************************************************************************/
330ddbd7b91SNathan Whitehorn
331ddbd7b91SNathan WhitehornACPI_PARSE_OBJECT *
332ddbd7b91SNathan WhitehornAcpiPsGetDepthNext (
333ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Origin,
334ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Op)
335ddbd7b91SNathan Whitehorn{
336ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Next = NULL;
337ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Parent;
338ddbd7b91SNathan Whitehorn    ACPI_PARSE_OBJECT       *Arg;
339ddbd7b91SNathan Whitehorn
340ddbd7b91SNathan Whitehorn
341ddbd7b91SNathan Whitehorn    ACPI_FUNCTION_ENTRY ();
342ddbd7b91SNathan Whitehorn
343ddbd7b91SNathan Whitehorn
344ddbd7b91SNathan Whitehorn    if (!Op)
345ddbd7b91SNathan Whitehorn    {
346ddbd7b91SNathan Whitehorn        return (NULL);
347ddbd7b91SNathan Whitehorn    }
348ddbd7b91SNathan Whitehorn
34943547dbeSJérôme Duval    /* Look for an argument or child */
350ddbd7b91SNathan Whitehorn
351ddbd7b91SNathan Whitehorn    Next = AcpiPsGetArg (Op, 0);
352ddbd7b91SNathan Whitehorn    if (Next)
353ddbd7b91SNathan Whitehorn    {
354ff2e2f81SFredrik Holmqvist        ASL_CV_LABEL_FILENODE (Next);
355ddbd7b91SNathan Whitehorn        return (Next);
356ddbd7b91SNathan Whitehorn    }
357ddbd7b91SNathan Whitehorn
35843547dbeSJérôme Duval    /* Look for a sibling */
359ddbd7b91SNathan Whitehorn
360ddbd7b91SNathan Whitehorn    Next = Op->Common.Next;
361ddbd7b91SNathan Whitehorn    if (Next)
362ddbd7b91SNathan Whitehorn    {
363ff2e2f81SFredrik Holmqvist        ASL_CV_LABEL_FILENODE (Next);
364ddbd7b91SNathan Whitehorn        return (Next);
365ddbd7b91SNathan Whitehorn    }
366ddbd7b91SNathan Whitehorn
36743547dbeSJérôme Duval    /* Look for a sibling of parent */
368ddbd7b91SNathan Whitehorn
369ddbd7b91SNathan Whitehorn    Parent = Op->Common.Parent;
370ddbd7b91SNathan Whitehorn
371ddbd7b91SNathan Whitehorn    while (Parent)
372ddbd7b91SNathan Whitehorn    {
373ddbd7b91SNathan Whitehorn        Arg = AcpiPsGetArg (Parent, 0);
374ddbd7b91SNathan Whitehorn        while (Arg && (Arg != Origin) && (Arg != Op))
375ddbd7b91SNathan Whitehorn        {
376ff2e2f81SFredrik Holmqvist
377ff2e2f81SFredrik Holmqvist            ASL_CV_LABEL_FILENODE (Arg);
378ddbd7b91SNathan Whitehorn            Arg = Arg->Common.Next;
379ddbd7b91SNathan Whitehorn        }
380ddbd7b91SNathan Whitehorn
381ddbd7b91SNathan Whitehorn        if (Arg == Origin)
382ddbd7b91SNathan Whitehorn        {
38343547dbeSJérôme Duval            /* Reached parent of origin, end search */
384ddbd7b91SNathan Whitehorn
385ddbd7b91SNathan Whitehorn            return (NULL);
386ddbd7b91SNathan Whitehorn        }
387ddbd7b91SNathan Whitehorn
388ddbd7b91SNathan Whitehorn        if (Parent->Common.Next)
389ddbd7b91SNathan Whitehorn        {
39043547dbeSJérôme Duval            /* Found sibling of parent */
391ddbd7b91SNathan Whitehorn
392ff2e2f81SFredrik Holmqvist            ASL_CV_LABEL_FILENODE (Parent->Common.Next);
393ddbd7b91SNathan Whitehorn            return (Parent->Common.Next);
394ddbd7b91SNathan Whitehorn        }
395ddbd7b91SNathan Whitehorn
396ddbd7b91SNathan Whitehorn        Op = Parent;
397ddbd7b91SNathan Whitehorn        Parent = Parent->Common.Parent;
398ddbd7b91SNathan Whitehorn    }
399ddbd7b91SNathan Whitehorn
400ff2e2f81SFredrik Holmqvist    ASL_CV_LABEL_FILENODE (Next);
401ddbd7b91SNathan Whitehorn    return (Next);
402ddbd7b91SNathan Whitehorn}
403ddbd7b91SNathan Whitehorn
404ddbd7b91SNathan Whitehorn
40543547dbeSJérôme Duval#ifdef ACPI_OBSOLETE_FUNCTIONS
40643547dbeSJérôme Duval/*******************************************************************************
40743547dbeSJérôme Duval *
40843547dbeSJérôme Duval * FUNCTION:    AcpiPsGetChild
40943547dbeSJérôme Duval *
41043547dbeSJérôme Duval * PARAMETERS:  Op              - Get the child of this Op
41143547dbeSJérôme Duval *
41243547dbeSJérôme Duval * RETURN:      Child Op, Null if none is found.
41343547dbeSJérôme Duval *
41443547dbeSJérôme Duval * DESCRIPTION: Get op's children or NULL if none
41543547dbeSJérôme Duval *
41643547dbeSJérôme Duval ******************************************************************************/
41743547dbeSJérôme Duval
41843547dbeSJérôme DuvalACPI_PARSE_OBJECT *
41943547dbeSJérôme DuvalAcpiPsGetChild (
42043547dbeSJérôme Duval    ACPI_PARSE_OBJECT       *Op)
42143547dbeSJérôme Duval{
42243547dbeSJérôme Duval    ACPI_PARSE_OBJECT       *Child = NULL;
42343547dbeSJérôme Duval
42443547dbeSJérôme Duval
42543547dbeSJérôme Duval    ACPI_FUNCTION_ENTRY ();
42643547dbeSJérôme Duval
42743547dbeSJérôme Duval
42843547dbeSJérôme Duval    switch (Op->Common.AmlOpcode)
42943547dbeSJérôme Duval    {
43043547dbeSJérôme Duval    case AML_SCOPE_OP:
43143547dbeSJérôme Duval    case AML_ELSE_OP:
43243547dbeSJérôme Duval    case AML_DEVICE_OP:
43343547dbeSJérôme Duval    case AML_THERMAL_ZONE_OP:
43443547dbeSJérôme Duval    case AML_INT_METHODCALL_OP:
43543547dbeSJérôme Duval
43643547dbeSJérôme Duval        Child = AcpiPsGetArg (Op, 0);
43743547dbeSJérôme Duval        break;
43843547dbeSJérôme Duval
43943547dbeSJérôme Duval    case AML_BUFFER_OP:
44043547dbeSJérôme Duval    case AML_PACKAGE_OP:
44108c9948cSFredrik Holmqvist    case AML_VARIABLE_PACKAGE_OP:
44243547dbeSJérôme Duval    case AML_METHOD_OP:
44343547dbeSJérôme Duval    case AML_IF_OP:
44443547dbeSJérôme Duval    case AML_WHILE_OP:
44543547dbeSJérôme Duval    case AML_FIELD_OP:
44643547dbeSJérôme Duval
44743547dbeSJérôme Duval        Child = AcpiPsGetArg (Op, 1);
44843547dbeSJérôme Duval        break;
44943547dbeSJérôme Duval
450ff2e2f81SFredrik Holmqvist    case AML_POWER_RESOURCE_OP:
45143547dbeSJérôme Duval    case AML_INDEX_FIELD_OP:
45243547dbeSJérôme Duval
45343547dbeSJérôme Duval        Child = AcpiPsGetArg (Op, 2);
45443547dbeSJérôme Duval        break;
45543547dbeSJérôme Duval
45643547dbeSJérôme Duval    case AML_PROCESSOR_OP:
45743547dbeSJérôme Duval    case AML_BANK_FIELD_OP:
45843547dbeSJérôme Duval
45943547dbeSJérôme Duval        Child = AcpiPsGetArg (Op, 3);
46043547dbeSJérôme Duval        break;
46143547dbeSJérôme Duval
46243547dbeSJérôme Duval    default:
463c70258b7SJérôme Duval
46443547dbeSJérôme Duval        /* All others have no children */
465c70258b7SJérôme Duval
46643547dbeSJérôme Duval        break;
46743547dbeSJérôme Duval    }
46843547dbeSJérôme Duval
46943547dbeSJérôme Duval    return (Child);
47043547dbeSJérôme Duval}
47143547dbeSJérôme Duval#endif
472