1 /******************************************************************************
3 * Module Name: pstree - Parser op tree manipulation/traversal/search
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/amlcode.h>
49 #define _COMPONENT ACPI_PARSER
50 ACPI_MODULE_NAME ("pstree")
52 /* Local prototypes */
54 #ifdef ACPI_OBSOLETE_FUNCTIONS
55 union acpi_parse_object *
57 union acpi_parse_object *op);
61 /*******************************************************************************
63 * FUNCTION: acpi_ps_get_arg
65 * PARAMETERS: Op - Get an argument for this op
66 * Argn - Nth argument to get
68 * RETURN: The argument (as an Op object). NULL if argument does not exist
70 * DESCRIPTION: Get the specified op's argument.
72 ******************************************************************************/
74 union acpi_parse_object *
76 union acpi_parse_object *op,
79 union acpi_parse_object *arg = NULL;
80 const struct acpi_opcode_info *op_info;
83 ACPI_FUNCTION_ENTRY ();
86 /* Get the info structure for this opcode */
88 op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
89 if (op_info->class == AML_CLASS_UNKNOWN) {
90 /* Invalid opcode or ASCII character */
95 /* Check if this opcode requires argument sub-objects */
97 if (!(op_info->flags & AML_HAS_ARGS)) {
98 /* Has no linked argument objects */
103 /* Get the requested argument object */
105 arg = op->common.value.arg;
106 while (arg && argn) {
108 arg = arg->common.next;
115 /*******************************************************************************
117 * FUNCTION: acpi_ps_append_arg
119 * PARAMETERS: Op - Append an argument to this Op.
120 * Arg - Argument Op to append
124 * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
126 ******************************************************************************/
130 union acpi_parse_object *op,
131 union acpi_parse_object *arg)
133 union acpi_parse_object *prev_arg;
134 const struct acpi_opcode_info *op_info;
137 ACPI_FUNCTION_ENTRY ();
144 /* Get the info structure for this opcode */
146 op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
147 if (op_info->class == AML_CLASS_UNKNOWN) {
150 ACPI_REPORT_ERROR (("ps_append_arg: Invalid AML Opcode: 0x%2.2X\n",
151 op->common.aml_opcode));
155 /* Check if this opcode requires argument sub-objects */
157 if (!(op_info->flags & AML_HAS_ARGS)) {
158 /* Has no linked argument objects */
163 /* Append the argument to the linked argument list */
165 if (op->common.value.arg) {
166 /* Append to existing argument list */
168 prev_arg = op->common.value.arg;
169 while (prev_arg->common.next) {
170 prev_arg = prev_arg->common.next;
172 prev_arg->common.next = arg;
175 /* No argument list, this will be the first argument */
177 op->common.value.arg = arg;
180 /* Set the parent in this arg and any args linked after it */
183 arg->common.parent = op;
184 arg = arg->common.next;
189 #ifdef ACPI_FUTURE_USAGE
190 /*******************************************************************************
192 * FUNCTION: acpi_ps_get_depth_next
194 * PARAMETERS: Origin - Root of subtree to search
195 * Op - Last (previous) Op that was found
197 * RETURN: Next Op found in the search.
199 * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
200 * Return NULL when reaching "origin" or when walking up from root
202 ******************************************************************************/
204 union acpi_parse_object *
205 acpi_ps_get_depth_next (
206 union acpi_parse_object *origin,
207 union acpi_parse_object *op)
209 union acpi_parse_object *next = NULL;
210 union acpi_parse_object *parent;
211 union acpi_parse_object *arg;
214 ACPI_FUNCTION_ENTRY ();
221 /* Look for an argument or child */
223 next = acpi_ps_get_arg (op, 0);
228 /* Look for a sibling */
230 next = op->common.next;
235 /* Look for a sibling of parent */
237 parent = op->common.parent;
240 arg = acpi_ps_get_arg (parent, 0);
241 while (arg && (arg != origin) && (arg != op)) {
242 arg = arg->common.next;
246 /* Reached parent of origin, end search */
251 if (parent->common.next) {
252 /* Found sibling of parent */
254 return (parent->common.next);
258 parent = parent->common.parent;
265 #ifdef ACPI_OBSOLETE_FUNCTIONS
266 /*******************************************************************************
268 * FUNCTION: acpi_ps_get_child
270 * PARAMETERS: Op - Get the child of this Op
272 * RETURN: Child Op, Null if none is found.
274 * DESCRIPTION: Get op's children or NULL if none
276 ******************************************************************************/
278 union acpi_parse_object *
280 union acpi_parse_object *op)
282 union acpi_parse_object *child = NULL;
285 ACPI_FUNCTION_ENTRY ();
288 switch (op->common.aml_opcode) {
292 case AML_THERMAL_ZONE_OP:
293 case AML_INT_METHODCALL_OP:
295 child = acpi_ps_get_arg (op, 0);
306 child = acpi_ps_get_arg (op, 1);
310 case AML_POWER_RES_OP:
311 case AML_INDEX_FIELD_OP:
313 child = acpi_ps_get_arg (op, 2);
317 case AML_PROCESSOR_OP:
318 case AML_BANK_FIELD_OP:
320 child = acpi_ps_get_arg (op, 3);
325 /* All others have no children */
333 #endif /* ACPI_FUTURE_USAGE */