]> err.no Git - linux-2.6/blob - drivers/acpi/dispatcher/dswscope.c
21f4548ff323f9c19af28d8973a845c558cbf5bf
[linux-2.6] / drivers / acpi / dispatcher / dswscope.c
1 /******************************************************************************
2  *
3  * Module Name: dswscope - Scope stack manipulation
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2005, R. Byron Moore
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
25  *
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.
29  *
30  * NO WARRANTY
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.
42  */
43
44
45 #include <acpi/acpi.h>
46 #include <acpi/acdispat.h>
47
48
49 #define _COMPONENT          ACPI_DISPATCHER
50          ACPI_MODULE_NAME    ("dswscope")
51
52
53 /****************************************************************************
54  *
55  * FUNCTION:    acpi_ds_scope_stack_clear
56  *
57  * PARAMETERS:  walk_state      - Current state
58  *
59  * RETURN:      None
60  *
61  * DESCRIPTION: Pop (and free) everything on the scope stack except the
62  *              root scope object (which remains at the stack top.)
63  *
64  ***************************************************************************/
65
66 void
67 acpi_ds_scope_stack_clear (
68         struct acpi_walk_state          *walk_state)
69 {
70         union acpi_generic_state        *scope_info;
71
72         ACPI_FUNCTION_NAME ("ds_scope_stack_clear");
73
74
75         while (walk_state->scope_info) {
76                 /* Pop a scope off the stack */
77
78                 scope_info = walk_state->scope_info;
79                 walk_state->scope_info = scope_info->scope.next;
80
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);
85         }
86 }
87
88
89 /****************************************************************************
90  *
91  * FUNCTION:    acpi_ds_scope_stack_push
92  *
93  * PARAMETERS:  Node            - Name to be made current
94  *              Type            - Type of frame being pushed
95  *              walk_state      - Current state
96  *
97  * RETURN:      Status
98  *
99  * DESCRIPTION: Push the current scope on the scope stack, and make the
100  *              passed Node current.
101  *
102  ***************************************************************************/
103
104 acpi_status
105 acpi_ds_scope_stack_push (
106         struct acpi_namespace_node      *node,
107         acpi_object_type                type,
108         struct acpi_walk_state          *walk_state)
109 {
110         union acpi_generic_state        *scope_info;
111         union acpi_generic_state        *old_scope_info;
112
113
114         ACPI_FUNCTION_TRACE ("ds_scope_stack_push");
115
116
117         if (!node) {
118                 /* Invalid scope   */
119
120                 ACPI_REPORT_ERROR (("ds_scope_stack_push: null scope passed\n"));
121                 return_ACPI_STATUS (AE_BAD_PARAMETER);
122         }
123
124         /* Make sure object type is valid */
125
126         if (!acpi_ut_valid_object_type (type)) {
127                 ACPI_REPORT_WARNING ((
128                         "ds_scope_stack_push: Invalid object type: 0x%X\n", type));
129         }
130
131         /* Allocate a new scope object */
132
133         scope_info = acpi_ut_create_generic_state ();
134         if (!scope_info) {
135                 return_ACPI_STATUS (AE_NO_MEMORY);
136         }
137
138         /* Init new scope object */
139
140         scope_info->common.data_type = ACPI_DESC_TYPE_STATE_WSCOPE;
141         scope_info->scope.node      = node;
142         scope_info->common.value    = (u16) type;
143
144         walk_state->scope_depth++;
145
146         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
147                 "[%.2d] Pushed scope ", (u32) walk_state->scope_depth));
148
149         old_scope_info = walk_state->scope_info;
150         if (old_scope_info) {
151                 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
152                         "[%4.4s] (%s)",
153                         acpi_ut_get_node_name (old_scope_info->scope.node),
154                         acpi_ut_get_type_name (old_scope_info->common.value)));
155         }
156         else {
157                 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
158                         "[\\___] (%s)", "ROOT"));
159         }
160
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)));
165
166         /* Push new scope object onto stack */
167
168         acpi_ut_push_generic_state (&walk_state->scope_info, scope_info);
169         return_ACPI_STATUS (AE_OK);
170 }
171
172
173 /****************************************************************************
174  *
175  * FUNCTION:    acpi_ds_scope_stack_pop
176  *
177  * PARAMETERS:  walk_state      - Current state
178  *
179  * RETURN:      Status
180  *
181  * DESCRIPTION: Pop the scope stack once.
182  *
183  ***************************************************************************/
184
185 acpi_status
186 acpi_ds_scope_stack_pop (
187         struct acpi_walk_state          *walk_state)
188 {
189         union acpi_generic_state        *scope_info;
190         union acpi_generic_state        *new_scope_info;
191
192
193         ACPI_FUNCTION_TRACE ("ds_scope_stack_pop");
194
195
196         /*
197          * Pop scope info object off the stack.
198          */
199         scope_info = acpi_ut_pop_generic_state (&walk_state->scope_info);
200         if (!scope_info) {
201                 return_ACPI_STATUS (AE_STACK_UNDERFLOW);
202         }
203
204         walk_state->scope_depth--;
205
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)));
211
212         new_scope_info = walk_state->scope_info;
213         if (new_scope_info) {
214                 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
215                         "[%4.4s] (%s)\n",
216                         acpi_ut_get_node_name (new_scope_info->scope.node),
217                         acpi_ut_get_type_name (new_scope_info->common.value)));
218         }
219         else {
220                 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
221                         "[\\___] (ROOT)\n"));
222         }
223
224         acpi_ut_delete_generic_state (scope_info);
225         return_ACPI_STATUS (AE_OK);
226 }
227
228