1 /******************************************************************************
3 * Module Name: dswscope - Scope stack manipulation
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/acdispat.h>
49 #define _COMPONENT ACPI_DISPATCHER
50 ACPI_MODULE_NAME ("dswscope")
53 #define STACK_POP(head) head
56 /****************************************************************************
58 * FUNCTION: acpi_ds_scope_stack_clear
62 * DESCRIPTION: Pop (and free) everything on the scope stack except the
63 * root scope object (which remains at the stack top.)
65 ***************************************************************************/
68 acpi_ds_scope_stack_clear (
69 struct acpi_walk_state *walk_state)
71 union acpi_generic_state *scope_info;
73 ACPI_FUNCTION_NAME ("ds_scope_stack_clear");
76 while (walk_state->scope_info) {
77 /* Pop a scope off the stack */
79 scope_info = walk_state->scope_info;
80 walk_state->scope_info = scope_info->scope.next;
82 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
83 "Popped object type (%s)\n", acpi_ut_get_type_name (scope_info->common.value)));
84 acpi_ut_delete_generic_state (scope_info);
89 /****************************************************************************
91 * FUNCTION: acpi_ds_scope_stack_push
93 * PARAMETERS: *Node, - Name to be made current
94 * Type, - Type of frame being pushed
96 * DESCRIPTION: Push the current scope on the scope stack, and make the
97 * passed Node current.
99 ***************************************************************************/
102 acpi_ds_scope_stack_push (
103 struct acpi_namespace_node *node,
104 acpi_object_type type,
105 struct acpi_walk_state *walk_state)
107 union acpi_generic_state *scope_info;
108 union acpi_generic_state *old_scope_info;
111 ACPI_FUNCTION_TRACE ("ds_scope_stack_push");
117 ACPI_REPORT_ERROR (("ds_scope_stack_push: null scope passed\n"));
118 return_ACPI_STATUS (AE_BAD_PARAMETER);
121 /* Make sure object type is valid */
123 if (!acpi_ut_valid_object_type (type)) {
124 ACPI_REPORT_WARNING (("ds_scope_stack_push: Invalid object type: 0x%X\n", type));
127 /* Allocate a new scope object */
129 scope_info = acpi_ut_create_generic_state ();
131 return_ACPI_STATUS (AE_NO_MEMORY);
134 /* Init new scope object */
136 scope_info->common.data_type = ACPI_DESC_TYPE_STATE_WSCOPE;
137 scope_info->scope.node = node;
138 scope_info->common.value = (u16) type;
140 walk_state->scope_depth++;
142 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
143 "[%.2d] Pushed scope ", (u32) walk_state->scope_depth));
145 old_scope_info = walk_state->scope_info;
146 if (old_scope_info) {
147 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
149 acpi_ut_get_node_name (old_scope_info->scope.node),
150 acpi_ut_get_type_name (old_scope_info->common.value)));
153 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
154 "[\\___] (%s)", "ROOT"));
157 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
158 ", New scope -> [%4.4s] (%s)\n",
159 acpi_ut_get_node_name (scope_info->scope.node),
160 acpi_ut_get_type_name (scope_info->common.value)));
162 /* Push new scope object onto stack */
164 acpi_ut_push_generic_state (&walk_state->scope_info, scope_info);
165 return_ACPI_STATUS (AE_OK);
169 /****************************************************************************
171 * FUNCTION: acpi_ds_scope_stack_pop
173 * PARAMETERS: Type - The type of frame to be found
175 * DESCRIPTION: Pop the scope stack until a frame of the requested type
178 * RETURN: Count of frames popped. If no frame of the requested type
179 * was found, the count is returned as a negative number and
180 * the scope stack is emptied (which sets the current scope
181 * to the root). If the scope stack was empty at entry, the
182 * function is a no-op and returns 0.
184 ***************************************************************************/
187 acpi_ds_scope_stack_pop (
188 struct acpi_walk_state *walk_state)
190 union acpi_generic_state *scope_info;
191 union acpi_generic_state *new_scope_info;
194 ACPI_FUNCTION_TRACE ("ds_scope_stack_pop");
198 * Pop scope info object off the stack.
200 scope_info = acpi_ut_pop_generic_state (&walk_state->scope_info);
202 return_ACPI_STATUS (AE_STACK_UNDERFLOW);
205 walk_state->scope_depth--;
207 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
208 "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
209 (u32) walk_state->scope_depth,
210 acpi_ut_get_node_name (scope_info->scope.node),
211 acpi_ut_get_type_name (scope_info->common.value)));
213 new_scope_info = walk_state->scope_info;
214 if (new_scope_info) {
215 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
217 acpi_ut_get_node_name (new_scope_info->scope.node),
218 acpi_ut_get_type_name (new_scope_info->common.value)));
221 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
222 "[\\___] (ROOT)\n"));
225 acpi_ut_delete_generic_state (scope_info);
226 return_ACPI_STATUS (AE_OK);