blob: c9228972f5f65a08a1ed6bb464dc255d9413c362 [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
Bob Mooreb229cf92006-04-21 17:15:00 -040066 ACPI_FUNCTION_NAME(ds_scope_stack_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 while (walk_state->scope_info) {
Bob Moore52fc0b02006-10-02 00:00:00 -040069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 /* Pop a scope off the stack */
71
72 scope_info = walk_state->scope_info;
73 walk_state->scope_info = scope_info->scope.next;
74
Len Brown4be44fc2005-08-05 00:44:28 -040075 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
76 "Popped object type (%s)\n",
77 acpi_ut_get_type_name(scope_info->common.
78 value)));
79 acpi_ut_delete_generic_state(scope_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
81}
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/****************************************************************************
84 *
85 * FUNCTION: acpi_ds_scope_stack_push
86 *
Robert Moore44f6c012005-04-18 22:49:35 -040087 * PARAMETERS: Node - Name to be made current
88 * Type - Type of frame being pushed
89 * walk_state - Current state
90 *
91 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 *
93 * DESCRIPTION: Push the current scope on the scope stack, and make the
94 * passed Node current.
95 *
96 ***************************************************************************/
97
98acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040099acpi_ds_scope_stack_push(struct acpi_namespace_node *node,
100 acpi_object_type type,
101 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Len Brown4be44fc2005-08-05 00:44:28 -0400103 union acpi_generic_state *scope_info;
104 union acpi_generic_state *old_scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Bob Mooreb229cf92006-04-21 17:15:00 -0400106 ACPI_FUNCTION_TRACE(ds_scope_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 if (!node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /* Invalid scope */
111
Bob Mooreb8e4d892006-01-27 16:43:00 -0500112 ACPI_ERROR((AE_INFO, "Null scope parameter"));
Len Brown4be44fc2005-08-05 00:44:28 -0400113 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115
116 /* Make sure object type is valid */
117
Len Brown4be44fc2005-08-05 00:44:28 -0400118 if (!acpi_ut_valid_object_type(type)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500119 ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
122 /* Allocate a new scope object */
123
Len Brown4be44fc2005-08-05 00:44:28 -0400124 scope_info = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (!scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400126 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
129 /* Init new scope object */
130
Bob Moore616861242006-03-17 16:44:00 -0500131 scope_info->common.descriptor_type = ACPI_DESC_TYPE_STATE_WSCOPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400132 scope_info->scope.node = node;
133 scope_info->common.value = (u16) type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 walk_state->scope_depth++;
136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
138 "[%.2d] Pushed scope ",
139 (u32) walk_state->scope_depth));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 old_scope_info = walk_state->scope_info;
142 if (old_scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400143 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
144 "[%4.4s] (%s)",
145 acpi_ut_get_node_name(old_scope_info->
146 scope.node),
147 acpi_ut_get_type_name(old_scope_info->
148 common.value)));
149 } else {
150 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (%s)", "ROOT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152
Len Brown4be44fc2005-08-05 00:44:28 -0400153 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
154 ", New scope -> [%4.4s] (%s)\n",
155 acpi_ut_get_node_name(scope_info->scope.node),
156 acpi_ut_get_type_name(scope_info->common.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 /* Push new scope object onto stack */
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 acpi_ut_push_generic_state(&walk_state->scope_info, scope_info);
161 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/****************************************************************************
165 *
166 * FUNCTION: acpi_ds_scope_stack_pop
167 *
Robert Moore44f6c012005-04-18 22:49:35 -0400168 * PARAMETERS: walk_state - Current state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 *
Robert Moore44f6c012005-04-18 22:49:35 -0400170 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 *
Robert Moore44f6c012005-04-18 22:49:35 -0400172 * DESCRIPTION: Pop the scope stack once.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 *
174 ***************************************************************************/
175
Len Brown4be44fc2005-08-05 00:44:28 -0400176acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Len Brown4be44fc2005-08-05 00:44:28 -0400178 union acpi_generic_state *scope_info;
179 union acpi_generic_state *new_scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Bob Mooreb229cf92006-04-21 17:15:00 -0400181 ACPI_FUNCTION_TRACE(ds_scope_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 /*
184 * Pop scope info object off the stack.
185 */
Len Brown4be44fc2005-08-05 00:44:28 -0400186 scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 if (!scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400188 return_ACPI_STATUS(AE_STACK_UNDERFLOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190
191 walk_state->scope_depth--;
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
194 "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
195 (u32) walk_state->scope_depth,
196 acpi_ut_get_node_name(scope_info->scope.node),
197 acpi_ut_get_type_name(scope_info->common.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 new_scope_info = walk_state->scope_info;
200 if (new_scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400201 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
202 "[%4.4s] (%s)\n",
203 acpi_ut_get_node_name(new_scope_info->
204 scope.node),
205 acpi_ut_get_type_name(new_scope_info->
206 common.value)));
207 } else {
208 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (ROOT)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210
Len Brown4be44fc2005-08-05 00:44:28 -0400211 acpi_ut_delete_generic_state(scope_info);
212 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}