blob: ada21ef4a1744d0c9e39aa0c16bdb7333b9e2e32 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: dswscope - Scope stack manipulation
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acdispat.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("dswscope")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/****************************************************************************
51 *
52 * FUNCTION: acpi_ds_scope_stack_clear
53 *
Robert Moore44f6c012005-04-18 22:49:35 -040054 * PARAMETERS: walk_state - Current state
55 *
56 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 *
58 * DESCRIPTION: Pop (and free) everything on the scope stack except the
59 * root scope object (which remains at the stack top.)
60 *
61 ***************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040062void acpi_ds_scope_stack_clear(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Len Brown4be44fc2005-08-05 00:44:28 -040064 union acpi_generic_state *scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Len Brown4be44fc2005-08-05 00:44:28 -040066 ACPI_FUNCTION_NAME("ds_scope_stack_clear");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 while (walk_state->scope_info) {
69 /* Pop a scope off the stack */
70
71 scope_info = walk_state->scope_info;
72 walk_state->scope_info = scope_info->scope.next;
73
Len Brown4be44fc2005-08-05 00:44:28 -040074 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
75 "Popped object type (%s)\n",
76 acpi_ut_get_type_name(scope_info->common.
77 value)));
78 acpi_ut_delete_generic_state(scope_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
80}
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/****************************************************************************
83 *
84 * FUNCTION: acpi_ds_scope_stack_push
85 *
Robert Moore44f6c012005-04-18 22:49:35 -040086 * PARAMETERS: Node - Name to be made current
87 * Type - Type of frame being pushed
88 * walk_state - Current state
89 *
90 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 *
92 * DESCRIPTION: Push the current scope on the scope stack, and make the
93 * passed Node current.
94 *
95 ***************************************************************************/
96
97acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040098acpi_ds_scope_stack_push(struct acpi_namespace_node *node,
99 acpi_object_type type,
100 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Len Brown4be44fc2005-08-05 00:44:28 -0400102 union acpi_generic_state *scope_info;
103 union acpi_generic_state *old_scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Len Brown4be44fc2005-08-05 00:44:28 -0400105 ACPI_FUNCTION_TRACE("ds_scope_stack_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 if (!node) {
108 /* Invalid scope */
109
Bob Mooreb8e4d892006-01-27 16:43:00 -0500110 ACPI_ERROR((AE_INFO, "Null scope parameter"));
Len Brown4be44fc2005-08-05 00:44:28 -0400111 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113
114 /* Make sure object type is valid */
115
Len Brown4be44fc2005-08-05 00:44:28 -0400116 if (!acpi_ut_valid_object_type(type)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500117 ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119
120 /* Allocate a new scope object */
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 scope_info = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (!scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400124 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
126
127 /* Init new scope object */
128
129 scope_info->common.data_type = ACPI_DESC_TYPE_STATE_WSCOPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400130 scope_info->scope.node = node;
131 scope_info->common.value = (u16) type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 walk_state->scope_depth++;
134
Len Brown4be44fc2005-08-05 00:44:28 -0400135 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
136 "[%.2d] Pushed scope ",
137 (u32) walk_state->scope_depth));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 old_scope_info = walk_state->scope_info;
140 if (old_scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400141 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
142 "[%4.4s] (%s)",
143 acpi_ut_get_node_name(old_scope_info->
144 scope.node),
145 acpi_ut_get_type_name(old_scope_info->
146 common.value)));
147 } else {
148 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (%s)", "ROOT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
150
Len Brown4be44fc2005-08-05 00:44:28 -0400151 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
152 ", New scope -> [%4.4s] (%s)\n",
153 acpi_ut_get_node_name(scope_info->scope.node),
154 acpi_ut_get_type_name(scope_info->common.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 /* Push new scope object onto stack */
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 acpi_ut_push_generic_state(&walk_state->scope_info, scope_info);
159 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162/****************************************************************************
163 *
164 * FUNCTION: acpi_ds_scope_stack_pop
165 *
Robert Moore44f6c012005-04-18 22:49:35 -0400166 * PARAMETERS: walk_state - Current state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 *
Robert Moore44f6c012005-04-18 22:49:35 -0400168 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 *
Robert Moore44f6c012005-04-18 22:49:35 -0400170 * DESCRIPTION: Pop the scope stack once.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 *
172 ***************************************************************************/
173
Len Brown4be44fc2005-08-05 00:44:28 -0400174acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Len Brown4be44fc2005-08-05 00:44:28 -0400176 union acpi_generic_state *scope_info;
177 union acpi_generic_state *new_scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Len Brown4be44fc2005-08-05 00:44:28 -0400179 ACPI_FUNCTION_TRACE("ds_scope_stack_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 /*
182 * Pop scope info object off the stack.
183 */
Len Brown4be44fc2005-08-05 00:44:28 -0400184 scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (!scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400186 return_ACPI_STATUS(AE_STACK_UNDERFLOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 walk_state->scope_depth--;
190
Len Brown4be44fc2005-08-05 00:44:28 -0400191 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
192 "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
193 (u32) walk_state->scope_depth,
194 acpi_ut_get_node_name(scope_info->scope.node),
195 acpi_ut_get_type_name(scope_info->common.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 new_scope_info = walk_state->scope_info;
198 if (new_scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400199 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
200 "[%4.4s] (%s)\n",
201 acpi_ut_get_node_name(new_scope_info->
202 scope.node),
203 acpi_ut_get_type_name(new_scope_info->
204 common.value)));
205 } else {
206 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (ROOT)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 }
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209 acpi_ut_delete_generic_state(scope_info);
210 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}