1 /******************************************************************************
3 * Module Name: pswalk - Parser routines to walk parsed op tree(s)
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
34 #define _COMPONENT ACPI_PARSER
35 MODULE_NAME ("pswalk")
38 /*******************************************************************************
40 * FUNCTION: Acpi_ps_get_next_walk_op
42 * PARAMETERS: Walk_state - Current state of the walk
43 * Op - Current Op to be walked
44 * Ascending_callback - Procedure called when Op is complete
48 * DESCRIPTION: Get the next Op in a walk of the parse tree.
50 ******************************************************************************/
53 acpi_ps_get_next_walk_op (
54 ACPI_WALK_STATE *walk_state,
55 ACPI_PARSE_OBJECT *op,
56 ACPI_PARSE_UPWARDS ascending_callback)
58 ACPI_PARSE_OBJECT *next;
59 ACPI_PARSE_OBJECT *parent;
60 ACPI_PARSE_OBJECT *grand_parent;
64 /* Check for a argument only if we are descending in the tree */
66 if (walk_state->next_op_info != NEXT_OP_UPWARD) {
67 /* Look for an argument or child of the current op */
69 next = acpi_ps_get_arg (op, 0);
71 /* Still going downward in tree (Op is not completed yet) */
73 walk_state->prev_op = op;
74 walk_state->next_op = next;
75 walk_state->next_op_info = NEXT_OP_DOWNWARD;
82 * No more children, this Op is complete. Save Next and Parent
83 * in case the Op object gets deleted by the callback routine
89 status = ascending_callback (walk_state, op);
92 * If we are back to the starting point, the walk is complete.
94 if (op == walk_state->origin) {
95 /* Reached the point of origin, the walk is complete */
97 walk_state->prev_op = op;
98 walk_state->next_op = NULL;
104 * Check for a sibling to the current op. A sibling means
105 * we are still going "downward" in the tree.
109 /* There is a sibling, it will be next */
111 walk_state->prev_op = op;
112 walk_state->next_op = next;
113 walk_state->next_op_info = NEXT_OP_DOWNWARD;
115 /* Continue downward */
122 * Drop into the loop below because we are moving upwards in
129 * We are resuming a walk, and we were (are) going upward in the tree.
130 * So, we want to drop into the parent loop below.
138 * Look for a sibling of the current Op's parent
139 * Continue moving up the tree until we find a node that has not been
140 * visited, or we get back to where we started.
143 /* We are moving up the tree, therefore this parent Op is complete */
145 grand_parent = parent->parent;
148 status = ascending_callback (walk_state, parent);
151 * If we are back to the starting point, the walk is complete.
153 if (parent == walk_state->origin) {
154 /* Reached the point of origin, the walk is complete */
156 walk_state->prev_op = parent;
157 walk_state->next_op = NULL;
163 * If there is a sibling to this parent (it is not the starting point
164 * Op), then we will visit it.
167 /* found sibling of parent */
169 walk_state->prev_op = parent;
170 walk_state->next_op = next;
171 walk_state->next_op_info = NEXT_OP_DOWNWARD;
176 /* No siblings, no errors, just move up one more level in the tree */
179 parent = grand_parent;
180 walk_state->prev_op = op;
184 /* Got all the way to the top of the tree, we must be done! */
185 /* However, the code should have terminated in the loop above */
187 walk_state->next_op = NULL;
193 /*******************************************************************************
195 * FUNCTION: Acpi_ps_delete_completed_op
197 * PARAMETERS: State - Walk state
202 * DESCRIPTION: Callback function for Acpi_ps_get_next_walk_op(). Used during
203 * Acpi_ps_delete_parse tree to delete Op objects when all sub-objects
204 * have been visited (and deleted.)
206 ******************************************************************************/
209 acpi_ps_delete_completed_op (
210 ACPI_WALK_STATE *state,
211 ACPI_PARSE_OBJECT *op)
214 acpi_ps_free_op (op);
219 /*******************************************************************************
221 * FUNCTION: Acpi_ps_delete_parse_tree
223 * PARAMETERS: Subtree_root - Root of tree (or subtree) to delete
227 * DESCRIPTION: Delete a portion of or an entire parse tree.
229 ******************************************************************************/
232 acpi_ps_delete_parse_tree (
233 ACPI_PARSE_OBJECT *subtree_root)
235 ACPI_WALK_STATE *walk_state;
236 ACPI_WALK_LIST walk_list;
243 /* Create and initialize a new walk list */
245 walk_list.walk_state = NULL;
246 walk_list.acquired_mutex_list.prev = NULL;
247 walk_list.acquired_mutex_list.next = NULL;
249 walk_state = acpi_ds_create_walk_state (TABLE_ID_DSDT, NULL, NULL, &walk_list);
254 walk_state->parser_state = NULL;
255 walk_state->parse_flags = 0;
256 walk_state->descending_callback = NULL;
257 walk_state->ascending_callback = NULL;
260 walk_state->origin = subtree_root;
261 walk_state->next_op = subtree_root;
264 /* Head downward in the tree */
266 walk_state->next_op_info = NEXT_OP_DOWNWARD;
268 /* Visit all nodes in the subtree */
270 while (walk_state->next_op) {
271 acpi_ps_get_next_walk_op (walk_state, walk_state->next_op,
272 acpi_ps_delete_completed_op);
275 /* We are done with this walk */
277 acpi_aml_release_all_mutexes ((ACPI_OPERAND_OBJECT *) &walk_list.acquired_mutex_list);
278 acpi_ds_delete_walk_state (walk_state);