1 /******************************************************************************
3 * Module Name: pstree - Parser op tree manipulation/traversal/search
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
51 #define _COMPONENT ACPI_PARSER
52 ACPI_MODULE_NAME ("pstree")
54 /* Local prototypes */
56 #ifdef ACPI_OBSOLETE_FUNCTIONS
59 ACPI_PARSE_OBJECT *op);
63 /*******************************************************************************
65 * FUNCTION: AcpiPsGetArg
67 * PARAMETERS: Op - Get an argument for this op
68 * Argn - Nth argument to get
70 * RETURN: The argument (as an Op object). NULL if argument does not exist
72 * DESCRIPTION: Get the specified op's argument.
74 ******************************************************************************/
78 ACPI_PARSE_OBJECT *Op,
81 ACPI_PARSE_OBJECT *Arg = NULL;
82 const ACPI_OPCODE_INFO *OpInfo;
85 ACPI_FUNCTION_ENTRY ();
88 if (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP)
90 return (Op->Common.Value.Arg);
93 /* Get the info structure for this opcode */
95 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
96 if (OpInfo->Class == AML_CLASS_UNKNOWN)
98 /* Invalid opcode or ASCII character */
103 /* Check if this opcode requires argument sub-objects */
105 if (!(OpInfo->Flags & AML_HAS_ARGS))
107 /* Has no linked argument objects */
112 /* Get the requested argument object */
114 Arg = Op->Common.Value.Arg;
118 Arg = Arg->Common.Next;
125 /*******************************************************************************
127 * FUNCTION: AcpiPsAppendArg
129 * PARAMETERS: Op - Append an argument to this Op.
130 * Arg - Argument Op to append
134 * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
136 ******************************************************************************/
140 ACPI_PARSE_OBJECT *Op,
141 ACPI_PARSE_OBJECT *Arg)
143 ACPI_PARSE_OBJECT *PrevArg;
144 const ACPI_OPCODE_INFO *OpInfo;
147 ACPI_FUNCTION_ENTRY ();
155 /* Get the info structure for this opcode */
157 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
158 if (OpInfo->Class == AML_CLASS_UNKNOWN)
162 ACPI_ERROR ((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
163 Op->Common.AmlOpcode));
167 /* Check if this opcode requires argument sub-objects */
169 if (!(OpInfo->Flags & AML_HAS_ARGS))
171 /* Has no linked argument objects */
176 /* Append the argument to the linked argument list */
178 if (Op->Common.Value.Arg)
180 /* Append to existing argument list */
182 PrevArg = Op->Common.Value.Arg;
183 while (PrevArg->Common.Next)
185 PrevArg = PrevArg->Common.Next;
187 PrevArg->Common.Next = Arg;
191 /* No argument list, this will be the first argument */
193 Op->Common.Value.Arg = Arg;
196 /* Set the parent in this arg and any args linked after it */
200 Arg->Common.Parent = Op;
201 Arg = Arg->Common.Next;
203 Op->Common.ArgListLength++;
208 /*******************************************************************************
210 * FUNCTION: AcpiPsGetDepthNext
212 * PARAMETERS: Origin - Root of subtree to search
213 * Op - Last (previous) Op that was found
215 * RETURN: Next Op found in the search.
217 * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
218 * Return NULL when reaching "origin" or when walking up from root
220 ******************************************************************************/
224 ACPI_PARSE_OBJECT *Origin,
225 ACPI_PARSE_OBJECT *Op)
227 ACPI_PARSE_OBJECT *Next = NULL;
228 ACPI_PARSE_OBJECT *Parent;
229 ACPI_PARSE_OBJECT *Arg;
232 ACPI_FUNCTION_ENTRY ();
240 /* Look for an argument or child */
242 Next = AcpiPsGetArg (Op, 0);
248 /* Look for a sibling */
250 Next = Op->Common.Next;
256 /* Look for a sibling of parent */
258 Parent = Op->Common.Parent;
262 Arg = AcpiPsGetArg (Parent, 0);
263 while (Arg && (Arg != Origin) && (Arg != Op))
265 Arg = Arg->Common.Next;
270 /* Reached parent of origin, end search */
275 if (Parent->Common.Next)
277 /* Found sibling of parent */
279 return (Parent->Common.Next);
283 Parent = Parent->Common.Parent;
290 #ifdef ACPI_OBSOLETE_FUNCTIONS
291 /*******************************************************************************
293 * FUNCTION: AcpiPsGetChild
295 * PARAMETERS: Op - Get the child of this Op
297 * RETURN: Child Op, Null if none is found.
299 * DESCRIPTION: Get op's children or NULL if none
301 ******************************************************************************/
305 ACPI_PARSE_OBJECT *Op)
307 ACPI_PARSE_OBJECT *Child = NULL;
310 ACPI_FUNCTION_ENTRY ();
313 switch (Op->Common.AmlOpcode)
318 case AML_THERMAL_ZONE_OP:
319 case AML_INT_METHODCALL_OP:
321 Child = AcpiPsGetArg (Op, 0);
331 Child = AcpiPsGetArg (Op, 1);
334 case AML_POWER_RES_OP:
335 case AML_INDEX_FIELD_OP:
337 Child = AcpiPsGetArg (Op, 2);
340 case AML_PROCESSOR_OP:
341 case AML_BANK_FIELD_OP:
343 Child = AcpiPsGetArg (Op, 3);
348 /* All others have no children */