1 /******************************************************************************
3 * Module Name: pstree - Parser op tree manipulation/traversal/search
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define _COMPONENT ACPI_PARSER
30 MODULE_NAME ("pstree")
33 /*******************************************************************************
35 * FUNCTION: Acpi_ps_get_arg
37 * PARAMETERS: Op - Get an argument for this op
38 * Argn - Nth argument to get
40 * RETURN: The argument (as an Op object). NULL if argument does not exist
42 * DESCRIPTION: Get the specified op's argument.
44 ******************************************************************************/
48 ACPI_PARSE_OBJECT
*op
,
51 ACPI_PARSE_OBJECT
*arg
= NULL
;
52 ACPI_OPCODE_INFO
*op_info
;
55 /* Get the info structure for this opcode */
57 op_info
= acpi_ps_get_opcode_info (op
->opcode
);
58 if (ACPI_GET_OP_TYPE (op_info
) != ACPI_OP_TYPE_OPCODE
) {
59 /* Invalid opcode or ASCII character */
64 /* Check if this opcode requires argument sub-objects */
66 if (!(ACPI_GET_OP_ARGS (op_info
))) {
67 /* Has no linked argument objects */
72 /* Get the requested argument object */
84 /*******************************************************************************
86 * FUNCTION: Acpi_ps_append_arg
88 * PARAMETERS: Op - Append an argument to this Op.
89 * Arg - Argument Op to append
93 * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
95 ******************************************************************************/
99 ACPI_PARSE_OBJECT
*op
,
100 ACPI_PARSE_OBJECT
*arg
)
102 ACPI_PARSE_OBJECT
*prev_arg
;
103 ACPI_OPCODE_INFO
*op_info
;
110 /* Get the info structure for this opcode */
112 op_info
= acpi_ps_get_opcode_info (op
->opcode
);
113 if (ACPI_GET_OP_TYPE (op_info
) != ACPI_OP_TYPE_OPCODE
) {
119 /* Check if this opcode requires argument sub-objects */
121 if (!(ACPI_GET_OP_ARGS (op_info
))) {
122 /* Has no linked argument objects */
128 /* Append the argument to the linked argument list */
131 /* Append to existing argument list */
133 prev_arg
= op
->value
.arg
;
134 while (prev_arg
->next
) {
135 prev_arg
= prev_arg
->next
;
137 prev_arg
->next
= arg
;
141 /* No argument list, this will be the first argument */
147 /* Set the parent in this arg and any args linked after it */
156 /*******************************************************************************
158 * FUNCTION: Acpi_ps_get_child
160 * PARAMETERS: Op - Get the child of this Op
162 * RETURN: Child Op, Null if none is found.
164 * DESCRIPTION: Get op's children or NULL if none
166 ******************************************************************************/
170 ACPI_PARSE_OBJECT
*op
)
172 ACPI_PARSE_OBJECT
*child
= NULL
;
175 switch (op
->opcode
) {
179 case AML_THERMAL_ZONE_OP
:
180 case AML_METHODCALL_OP
:
182 child
= acpi_ps_get_arg (op
, 0);
191 case AML_DEF_FIELD_OP
:
193 child
= acpi_ps_get_arg (op
, 1);
197 case AML_POWER_RES_OP
:
198 case AML_INDEX_FIELD_OP
:
200 child
= acpi_ps_get_arg (op
, 2);
204 case AML_PROCESSOR_OP
:
205 case AML_BANK_FIELD_OP
:
207 child
= acpi_ps_get_arg (op
, 3);
216 /*******************************************************************************
218 * FUNCTION: Acpi_ps_get_depth_next
220 * PARAMETERS: Origin - Root of subtree to search
221 * Op - Last (previous) Op that was found
223 * RETURN: Next Op found in the search.
225 * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
226 * Return NULL when reaching "origin" or when walking up from root
228 ******************************************************************************/
231 acpi_ps_get_depth_next (
232 ACPI_PARSE_OBJECT
*origin
,
233 ACPI_PARSE_OBJECT
*op
)
235 ACPI_PARSE_OBJECT
*next
= NULL
;
236 ACPI_PARSE_OBJECT
*parent
;
237 ACPI_PARSE_OBJECT
*arg
;
244 /* look for an argument or child */
246 next
= acpi_ps_get_arg (op
, 0);
251 /* look for a sibling */
258 /* look for a sibling of parent */
263 arg
= acpi_ps_get_arg (parent
, 0);
264 while (arg
&& (arg
!= origin
) && (arg
!= op
)) {
269 /* reached parent of origin, end search */
275 /* found sibling of parent */
276 return (parent
->next
);
280 parent
= parent
->parent
;