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 /****************************************************************************
55 * FUNCTION: acpi_ds_scope_stack_clear
57 * PARAMETERS: walk_state - Current state
61 * DESCRIPTION: Pop (and free) everything on the scope stack except the
62 * root scope object (which remains at the stack top.)
64 ***************************************************************************/
67 acpi_ds_scope_stack_clear (
68 struct acpi_walk_state *walk_state)
70 union acpi_generic_state *scope_info;
72 ACPI_FUNCTION_NAME ("ds_scope_stack_clear");
75 while (walk_state->scope_info) {
76 /* Pop a scope off the stack */
78 scope_info = walk_state->scope_info;
79 walk_state->scope_info = scope_info->scope.next;
81 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
82 "Popped object type (%s)\n",
83 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
95 * walk_state - Current state
99 * DESCRIPTION: Push the current scope on the scope stack, and make the
100 * passed Node current.
102 ***************************************************************************/
105 acpi_ds_scope_stack_push (
106 struct acpi_namespace_node *node,
107 acpi_object_type type,
108 struct acpi_walk_state *walk_state)
110 union acpi_generic_state *scope_info;
111 union acpi_generic_state *old_scope_info;
114 ACPI_FUNCTION_TRACE ("ds_scope_stack_push");
120 ACPI_REPORT_ERROR (("ds_scope_stack_push: null scope passed\n"));
121 return_ACPI_STATUS (AE_BAD_PARAMETER);
124 /* Make sure object type is valid */
126 if (!acpi_ut_valid_object_type (type)) {
127 ACPI_REPORT_WARNING ((
128 "ds_scope_stack_push: Invalid object type: 0x%X\n", type));
131 /* Allocate a new scope object */
133 scope_info = acpi_ut_create_generic_state ();
135 return_ACPI_STATUS (AE_NO_MEMORY);
138 /* Init new scope object */
140 scope_info->common.data_type = ACPI_DESC_TYPE_STATE_WSCOPE;
141 scope_info->scope.node = node;
142 scope_info->common.value = (u16) type;
144 walk_state->scope_depth++;
146 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
147 "[%.2d] Pushed scope ", (u32) walk_state->scope_depth));
149 old_scope_info = walk_state->scope_info;
150 if (old_scope_info) {
151 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
153 acpi_ut_get_node_name (old_scope_info->scope.node),
154 acpi_ut_get_type_name (old_scope_info->common.value)));
157 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
158 "[\\___] (%s)", "ROOT"));
161 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
162 ", New scope -> [%4.4s] (%s)\n",
163 acpi_ut_get_node_name (scope_info->scope.node),
164 acpi_ut_get_type_name (scope_info->common.value)));
166 /* Push new scope object onto stack */
168 acpi_ut_push_generic_state (&walk_state->scope_info, scope_info);
169 return_ACPI_STATUS (AE_OK);
173 /****************************************************************************
175 * FUNCTION: acpi_ds_scope_stack_pop
177 * PARAMETERS: walk_state - Current state
181 * DESCRIPTION: Pop the scope stack once.
183 ***************************************************************************/
186 acpi_ds_scope_stack_pop (
187 struct acpi_walk_state *walk_state)
189 union acpi_generic_state *scope_info;
190 union acpi_generic_state *new_scope_info;
193 ACPI_FUNCTION_TRACE ("ds_scope_stack_pop");
197 * Pop scope info object off the stack.
199 scope_info = acpi_ut_pop_generic_state (&walk_state->scope_info);
201 return_ACPI_STATUS (AE_STACK_UNDERFLOW);
204 walk_state->scope_depth--;
206 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
207 "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
208 (u32) walk_state->scope_depth,
209 acpi_ut_get_node_name (scope_info->scope.node),
210 acpi_ut_get_type_name (scope_info->common.value)));
212 new_scope_info = walk_state->scope_info;
213 if (new_scope_info) {
214 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
216 acpi_ut_get_node_name (new_scope_info->scope.node),
217 acpi_ut_get_type_name (new_scope_info->common.value)));
220 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
221 "[\\___] (ROOT)\n"));
224 acpi_ut_delete_generic_state (scope_info);
225 return_ACPI_STATUS (AE_OK);