1 /******************************************************************************
3 * Module Name: dswscope - Scope stack manipulation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
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.
44 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_DISPATCHER
49 ACPI_MODULE_NAME("dswscope")
51 /****************************************************************************
53 * FUNCTION: acpi_ds_scope_stack_clear
55 * PARAMETERS: walk_state - Current state
59 * DESCRIPTION: Pop (and free) everything on the scope stack except the
60 * root scope object (which remains at the stack top.)
62 ***************************************************************************/
63 void acpi_ds_scope_stack_clear(struct acpi_walk_state
*walk_state
)
65 union acpi_generic_state
*scope_info
;
67 ACPI_FUNCTION_NAME(ds_scope_stack_clear
);
69 while (walk_state
->scope_info
) {
71 /* Pop a scope off the stack */
73 scope_info
= walk_state
->scope_info
;
74 walk_state
->scope_info
= scope_info
->scope
.next
;
76 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
77 "Popped object type (%s)\n",
78 acpi_ut_get_type_name(scope_info
->common
.
81 acpi_ut_delete_generic_state(scope_info
);
85 /****************************************************************************
87 * FUNCTION: acpi_ds_scope_stack_push
89 * PARAMETERS: node - Name to be made current
90 * type - Type of frame being pushed
91 * walk_state - Current state
95 * DESCRIPTION: Push the current scope on the scope stack, and make the
96 * passed Node current.
98 ***************************************************************************/
101 acpi_ds_scope_stack_push(struct acpi_namespace_node
*node
,
102 acpi_object_type type
,
103 struct acpi_walk_state
*walk_state
)
105 union acpi_generic_state
*scope_info
;
106 union acpi_generic_state
*old_scope_info
;
108 ACPI_FUNCTION_TRACE(ds_scope_stack_push
);
114 ACPI_ERROR((AE_INFO
, "Null scope parameter"));
115 return_ACPI_STATUS(AE_BAD_PARAMETER
);
118 /* Make sure object type is valid */
120 if (!acpi_ut_valid_object_type(type
)) {
121 ACPI_WARNING((AE_INFO
, "Invalid object type: 0x%X", type
));
124 /* Allocate a new scope object */
126 scope_info
= acpi_ut_create_generic_state();
128 return_ACPI_STATUS(AE_NO_MEMORY
);
131 /* Init new scope object */
133 scope_info
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_WSCOPE
;
134 scope_info
->scope
.node
= node
;
135 scope_info
->common
.value
= (u16
) type
;
137 walk_state
->scope_depth
++;
139 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
140 "[%.2d] Pushed scope ",
141 (u32
) walk_state
->scope_depth
));
143 old_scope_info
= walk_state
->scope_info
;
144 if (old_scope_info
) {
145 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC
,
147 acpi_ut_get_node_name(old_scope_info
->
149 acpi_ut_get_type_name(old_scope_info
->
152 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC
, "[\\___] (%s)", "ROOT"));
155 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC
,
156 ", New scope -> [%4.4s] (%s)\n",
157 acpi_ut_get_node_name(scope_info
->scope
.node
),
158 acpi_ut_get_type_name(scope_info
->common
.value
)));
160 /* Push new scope object onto stack */
162 acpi_ut_push_generic_state(&walk_state
->scope_info
, scope_info
);
163 return_ACPI_STATUS(AE_OK
);
166 /****************************************************************************
168 * FUNCTION: acpi_ds_scope_stack_pop
170 * PARAMETERS: walk_state - Current state
174 * DESCRIPTION: Pop the scope stack once.
176 ***************************************************************************/
178 acpi_status
acpi_ds_scope_stack_pop(struct acpi_walk_state
*walk_state
)
180 union acpi_generic_state
*scope_info
;
181 union acpi_generic_state
*new_scope_info
;
183 ACPI_FUNCTION_TRACE(ds_scope_stack_pop
);
186 * Pop scope info object off the stack.
188 scope_info
= acpi_ut_pop_generic_state(&walk_state
->scope_info
);
190 return_ACPI_STATUS(AE_STACK_UNDERFLOW
);
193 walk_state
->scope_depth
--;
195 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
196 "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
197 (u32
) walk_state
->scope_depth
,
198 acpi_ut_get_node_name(scope_info
->scope
.node
),
199 acpi_ut_get_type_name(scope_info
->common
.value
)));
201 new_scope_info
= walk_state
->scope_info
;
202 if (new_scope_info
) {
203 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC
,
205 acpi_ut_get_node_name(new_scope_info
->
207 acpi_ut_get_type_name(new_scope_info
->
210 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC
, "[\\___] (ROOT)\n"));
213 acpi_ut_delete_generic_state(scope_info
);
214 return_ACPI_STATUS(AE_OK
);