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
31 #define _COMPONENT ACPI_PARSER
32 MODULE_NAME ("pstree")
35 /*******************************************************************************
37 * FUNCTION: Acpi_ps_get_arg
39 * PARAMETERS: Op - Get an argument for this op
40 * Argn - Nth argument to get
42 * RETURN: The argument (as an Op object). NULL if argument does not exist
44 * DESCRIPTION: Get the specified op's argument.
46 ******************************************************************************/
50 ACPI_PARSE_OBJECT
*op
,
53 ACPI_PARSE_OBJECT
*arg
= NULL
;
54 ACPI_OPCODE_INFO
*op_info
;
57 /* Get the info structure for this opcode */
59 op_info
= acpi_ps_get_opcode_info (op
->opcode
);
60 if (ACPI_GET_OP_TYPE (op_info
) != ACPI_OP_TYPE_OPCODE
) {
61 /* Invalid opcode or ASCII character */
66 /* Check if this opcode requires argument sub-objects */
68 if (!(ACPI_GET_OP_ARGS (op_info
))) {
69 /* Has no linked argument objects */
74 /* Get the requested argument object */
86 /*******************************************************************************
88 * FUNCTION: Acpi_ps_append_arg
90 * PARAMETERS: Op - Append an argument to this Op.
91 * Arg - Argument Op to append
95 * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
97 ******************************************************************************/
101 ACPI_PARSE_OBJECT
*op
,
102 ACPI_PARSE_OBJECT
*arg
)
104 ACPI_PARSE_OBJECT
*prev_arg
;
105 ACPI_OPCODE_INFO
*op_info
;
112 /* Get the info structure for this opcode */
114 op_info
= acpi_ps_get_opcode_info (op
->opcode
);
115 if (ACPI_GET_OP_TYPE (op_info
) != ACPI_OP_TYPE_OPCODE
) {
121 /* Check if this opcode requires argument sub-objects */
123 if (!(ACPI_GET_OP_ARGS (op_info
))) {
124 /* Has no linked argument objects */
130 /* Append the argument to the linked argument list */
133 /* Append to existing argument list */
135 prev_arg
= op
->value
.arg
;
136 while (prev_arg
->next
) {
137 prev_arg
= prev_arg
->next
;
139 prev_arg
->next
= arg
;
143 /* No argument list, this will be the first argument */
149 /* Set the parent in this arg and any args linked after it */
158 /*******************************************************************************
160 * FUNCTION: Acpi_ps_get_child
162 * PARAMETERS: Op - Get the child of this Op
164 * RETURN: Child Op, Null if none is found.
166 * DESCRIPTION: Get op's children or NULL if none
168 ******************************************************************************/
172 ACPI_PARSE_OBJECT
*op
)
174 ACPI_PARSE_OBJECT
*child
= NULL
;
177 switch (op
->opcode
) {
181 case AML_THERMAL_ZONE_OP
:
182 case AML_METHODCALL_OP
:
184 child
= acpi_ps_get_arg (op
, 0);
193 case AML_DEF_FIELD_OP
:
195 child
= acpi_ps_get_arg (op
, 1);
199 case AML_POWER_RES_OP
:
200 case AML_INDEX_FIELD_OP
:
202 child
= acpi_ps_get_arg (op
, 2);
206 case AML_PROCESSOR_OP
:
207 case AML_BANK_FIELD_OP
:
209 child
= acpi_ps_get_arg (op
, 3);
218 /*******************************************************************************
220 * FUNCTION: Acpi_ps_get_depth_next
222 * PARAMETERS: Origin - Root of subtree to search
223 * Op - Last (previous) Op that was found
225 * RETURN: Next Op found in the search.
227 * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
228 * Return NULL when reaching "origin" or when walking up from root
230 ******************************************************************************/
233 acpi_ps_get_depth_next (
234 ACPI_PARSE_OBJECT
*origin
,
235 ACPI_PARSE_OBJECT
*op
)
237 ACPI_PARSE_OBJECT
*next
= NULL
;
238 ACPI_PARSE_OBJECT
*parent
;
239 ACPI_PARSE_OBJECT
*arg
;
246 /* look for an argument or child */
248 next
= acpi_ps_get_arg (op
, 0);
253 /* look for a sibling */
260 /* look for a sibling of parent */
265 arg
= acpi_ps_get_arg (parent
, 0);
266 while (arg
&& (arg
!= origin
) && (arg
!= op
)) {
271 /* reached parent of origin, end search */
277 /* found sibling of parent */
278 return (parent
->next
);
282 parent
= parent
->parent
;