Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / components / parser / pstree.c
blob6b67013a0da6c51a0c519f777e8021ba0067936c
1 /******************************************************************************
3 * Module Name: pstree - Parser op tree manipulation/traversal/search
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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.
45 #define __PSTREE_C__
47 #include "acpi.h"
48 #include "accommon.h"
49 #include "acparser.h"
50 #include "amlcode.h"
52 #define _COMPONENT ACPI_PARSER
53 ACPI_MODULE_NAME ("pstree")
55 /* Local prototypes */
57 #ifdef ACPI_OBSOLETE_FUNCTIONS
58 ACPI_PARSE_OBJECT *
59 AcpiPsGetChild (
60 ACPI_PARSE_OBJECT *op);
61 #endif
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 ******************************************************************************/
77 ACPI_PARSE_OBJECT *
78 AcpiPsGetArg (
79 ACPI_PARSE_OBJECT *Op,
80 UINT32 Argn)
82 ACPI_PARSE_OBJECT *Arg = NULL;
83 const ACPI_OPCODE_INFO *OpInfo;
86 ACPI_FUNCTION_ENTRY ();
89 if (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP)
91 return (Op->Common.Value.Arg);
94 /* Get the info structure for this opcode */
96 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
97 if (OpInfo->Class == AML_CLASS_UNKNOWN)
99 /* Invalid opcode or ASCII character */
101 return (NULL);
104 /* Check if this opcode requires argument sub-objects */
106 if (!(OpInfo->Flags & AML_HAS_ARGS))
108 /* Has no linked argument objects */
110 return (NULL);
113 /* Get the requested argument object */
115 Arg = Op->Common.Value.Arg;
116 while (Arg && Argn)
118 Argn--;
119 Arg = Arg->Common.Next;
122 return (Arg);
126 /*******************************************************************************
128 * FUNCTION: AcpiPsAppendArg
130 * PARAMETERS: Op - Append an argument to this Op.
131 * Arg - Argument Op to append
133 * RETURN: None.
135 * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
137 ******************************************************************************/
139 void
140 AcpiPsAppendArg (
141 ACPI_PARSE_OBJECT *Op,
142 ACPI_PARSE_OBJECT *Arg)
144 ACPI_PARSE_OBJECT *PrevArg;
145 const ACPI_OPCODE_INFO *OpInfo;
148 ACPI_FUNCTION_ENTRY ();
151 if (!Op)
153 return;
156 /* Get the info structure for this opcode */
158 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
159 if (OpInfo->Class == AML_CLASS_UNKNOWN)
161 /* Invalid opcode */
163 ACPI_ERROR ((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
164 Op->Common.AmlOpcode));
165 return;
168 /* Check if this opcode requires argument sub-objects */
170 if (!(OpInfo->Flags & AML_HAS_ARGS))
172 /* Has no linked argument objects */
174 return;
177 /* Append the argument to the linked argument list */
179 if (Op->Common.Value.Arg)
181 /* Append to existing argument list */
183 PrevArg = Op->Common.Value.Arg;
184 while (PrevArg->Common.Next)
186 PrevArg = PrevArg->Common.Next;
188 PrevArg->Common.Next = Arg;
190 else
192 /* No argument list, this will be the first argument */
194 Op->Common.Value.Arg = Arg;
197 /* Set the parent in this arg and any args linked after it */
199 while (Arg)
201 Arg->Common.Parent = Op;
202 Arg = Arg->Common.Next;
204 Op->Common.ArgListLength++;
209 /*******************************************************************************
211 * FUNCTION: AcpiPsGetDepthNext
213 * PARAMETERS: Origin - Root of subtree to search
214 * Op - Last (previous) Op that was found
216 * RETURN: Next Op found in the search.
218 * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
219 * Return NULL when reaching "origin" or when walking up from root
221 ******************************************************************************/
223 ACPI_PARSE_OBJECT *
224 AcpiPsGetDepthNext (
225 ACPI_PARSE_OBJECT *Origin,
226 ACPI_PARSE_OBJECT *Op)
228 ACPI_PARSE_OBJECT *Next = NULL;
229 ACPI_PARSE_OBJECT *Parent;
230 ACPI_PARSE_OBJECT *Arg;
233 ACPI_FUNCTION_ENTRY ();
236 if (!Op)
238 return (NULL);
241 /* Look for an argument or child */
243 Next = AcpiPsGetArg (Op, 0);
244 if (Next)
246 return (Next);
249 /* Look for a sibling */
251 Next = Op->Common.Next;
252 if (Next)
254 return (Next);
257 /* Look for a sibling of parent */
259 Parent = Op->Common.Parent;
261 while (Parent)
263 Arg = AcpiPsGetArg (Parent, 0);
264 while (Arg && (Arg != Origin) && (Arg != Op))
266 Arg = Arg->Common.Next;
269 if (Arg == Origin)
271 /* Reached parent of origin, end search */
273 return (NULL);
276 if (Parent->Common.Next)
278 /* Found sibling of parent */
280 return (Parent->Common.Next);
283 Op = Parent;
284 Parent = Parent->Common.Parent;
287 return (Next);
291 #ifdef ACPI_OBSOLETE_FUNCTIONS
292 /*******************************************************************************
294 * FUNCTION: AcpiPsGetChild
296 * PARAMETERS: Op - Get the child of this Op
298 * RETURN: Child Op, Null if none is found.
300 * DESCRIPTION: Get op's children or NULL if none
302 ******************************************************************************/
304 ACPI_PARSE_OBJECT *
305 AcpiPsGetChild (
306 ACPI_PARSE_OBJECT *Op)
308 ACPI_PARSE_OBJECT *Child = NULL;
311 ACPI_FUNCTION_ENTRY ();
314 switch (Op->Common.AmlOpcode)
316 case AML_SCOPE_OP:
317 case AML_ELSE_OP:
318 case AML_DEVICE_OP:
319 case AML_THERMAL_ZONE_OP:
320 case AML_INT_METHODCALL_OP:
322 Child = AcpiPsGetArg (Op, 0);
323 break;
325 case AML_BUFFER_OP:
326 case AML_PACKAGE_OP:
327 case AML_METHOD_OP:
328 case AML_IF_OP:
329 case AML_WHILE_OP:
330 case AML_FIELD_OP:
332 Child = AcpiPsGetArg (Op, 1);
333 break;
335 case AML_POWER_RES_OP:
336 case AML_INDEX_FIELD_OP:
338 Child = AcpiPsGetArg (Op, 2);
339 break;
341 case AML_PROCESSOR_OP:
342 case AML_BANK_FIELD_OP:
344 Child = AcpiPsGetArg (Op, 3);
345 break;
347 default:
349 /* All others have no children */
351 break;
354 return (Child);
356 #endif