1 /******************************************************************************
3 * Module Name: pstree - Parser op tree manipulation/traversal/search
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acparser.h>
50 #include <contrib/dev/acpica/include/amlcode.h>
52 #define _COMPONENT ACPI_PARSER
53 ACPI_MODULE_NAME ("pstree")
55 /* Local prototypes */
57 #ifdef ACPI_OBSOLETE_FUNCTIONS
60 ACPI_PARSE_OBJECT *op);
64 /*******************************************************************************
66 * FUNCTION: AcpiPsGetArg
68 * PARAMETERS: Op - Get an argument for this op
69 * Argn - Nth argument to get
71 * RETURN: The argument (as an Op object). NULL if argument does not exist
73 * DESCRIPTION: Get the specified op's argument.
75 ******************************************************************************/
79 ACPI_PARSE_OBJECT *Op,
82 ACPI_PARSE_OBJECT *Arg = NULL;
83 const ACPI_OPCODE_INFO *OpInfo;
86 ACPI_FUNCTION_ENTRY ();
89 /* Get the info structure for this opcode */
91 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
92 if (OpInfo->Class == AML_CLASS_UNKNOWN)
94 /* Invalid opcode or ASCII character */
99 /* Check if this opcode requires argument sub-objects */
101 if (!(OpInfo->Flags & AML_HAS_ARGS))
103 /* Has no linked argument objects */
108 /* Get the requested argument object */
110 Arg = Op->Common.Value.Arg;
114 Arg = Arg->Common.Next;
121 /*******************************************************************************
123 * FUNCTION: AcpiPsAppendArg
125 * PARAMETERS: Op - Append an argument to this Op.
126 * Arg - Argument Op to append
130 * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
132 ******************************************************************************/
136 ACPI_PARSE_OBJECT *Op,
137 ACPI_PARSE_OBJECT *Arg)
139 ACPI_PARSE_OBJECT *PrevArg;
140 const ACPI_OPCODE_INFO *OpInfo;
143 ACPI_FUNCTION_ENTRY ();
151 /* Get the info structure for this opcode */
153 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
154 if (OpInfo->Class == AML_CLASS_UNKNOWN)
158 ACPI_ERROR ((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
159 Op->Common.AmlOpcode));
163 /* Check if this opcode requires argument sub-objects */
165 if (!(OpInfo->Flags & AML_HAS_ARGS))
167 /* Has no linked argument objects */
172 /* Append the argument to the linked argument list */
174 if (Op->Common.Value.Arg)
176 /* Append to existing argument list */
178 PrevArg = Op->Common.Value.Arg;
179 while (PrevArg->Common.Next)
181 PrevArg = PrevArg->Common.Next;
183 PrevArg->Common.Next = Arg;
187 /* No argument list, this will be the first argument */
189 Op->Common.Value.Arg = Arg;
192 /* Set the parent in this arg and any args linked after it */
196 Arg->Common.Parent = Op;
197 Arg = Arg->Common.Next;
199 Op->Common.ArgListLength++;
204 /*******************************************************************************
206 * FUNCTION: AcpiPsGetDepthNext
208 * PARAMETERS: Origin - Root of subtree to search
209 * Op - Last (previous) Op that was found
211 * RETURN: Next Op found in the search.
213 * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
214 * Return NULL when reaching "origin" or when walking up from root
216 ******************************************************************************/
220 ACPI_PARSE_OBJECT *Origin,
221 ACPI_PARSE_OBJECT *Op)
223 ACPI_PARSE_OBJECT *Next = NULL;
224 ACPI_PARSE_OBJECT *Parent;
225 ACPI_PARSE_OBJECT *Arg;
228 ACPI_FUNCTION_ENTRY ();
236 /* Look for an argument or child */
238 Next = AcpiPsGetArg (Op, 0);
244 /* Look for a sibling */
246 Next = Op->Common.Next;
252 /* Look for a sibling of parent */
254 Parent = Op->Common.Parent;
258 Arg = AcpiPsGetArg (Parent, 0);
259 while (Arg && (Arg != Origin) && (Arg != Op))
261 Arg = Arg->Common.Next;
266 /* Reached parent of origin, end search */
271 if (Parent->Common.Next)
273 /* Found sibling of parent */
275 return (Parent->Common.Next);
279 Parent = Parent->Common.Parent;
286 #ifdef ACPI_OBSOLETE_FUNCTIONS
287 /*******************************************************************************
289 * FUNCTION: AcpiPsGetChild
291 * PARAMETERS: Op - Get the child of this Op
293 * RETURN: Child Op, Null if none is found.
295 * DESCRIPTION: Get op's children or NULL if none
297 ******************************************************************************/
301 ACPI_PARSE_OBJECT *Op)
303 ACPI_PARSE_OBJECT *Child = NULL;
306 ACPI_FUNCTION_ENTRY ();
309 switch (Op->Common.AmlOpcode)
314 case AML_THERMAL_ZONE_OP:
315 case AML_INT_METHODCALL_OP:
317 Child = AcpiPsGetArg (Op, 0);
328 Child = AcpiPsGetArg (Op, 1);
332 case AML_POWER_RES_OP:
333 case AML_INDEX_FIELD_OP:
335 Child = AcpiPsGetArg (Op, 2);
339 case AML_PROCESSOR_OP:
340 case AML_BANK_FIELD_OP:
342 Child = AcpiPsGetArg (Op, 3);
347 /* All others have no children */