| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
 | 2 |  * | 
 | 3 |  * Module Name: dswscope - Scope stack manipulation | 
 | 4 |  * | 
 | 5 |  *****************************************************************************/ | 
 | 6 |  | 
 | 7 | /* | 
| Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 8 |  * Copyright (C) 2000 - 2008, Intel Corp. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> | 
| Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" | 
 | 46 | #include "acdispat.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define _COMPONENT          ACPI_DISPATCHER | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 49 | ACPI_MODULE_NAME("dswscope") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /**************************************************************************** | 
 | 52 |  * | 
 | 53 |  * FUNCTION:    acpi_ds_scope_stack_clear | 
 | 54 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 |  * PARAMETERS:  walk_state      - Current state | 
 | 56 |  * | 
 | 57 |  * RETURN:      None | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  * | 
 | 59 |  * DESCRIPTION: Pop (and free) everything on the scope stack except the | 
 | 60 |  *              root scope object (which remains at the stack top.) | 
 | 61 |  * | 
 | 62 |  ***************************************************************************/ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | void acpi_ds_scope_stack_clear(struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | 	union acpi_generic_state *scope_info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 67 | 	ACPI_FUNCTION_NAME(ds_scope_stack_clear); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
 | 69 | 	while (walk_state->scope_info) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 70 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | 		/* Pop a scope off the stack */ | 
 | 72 |  | 
 | 73 | 		scope_info = walk_state->scope_info; | 
 | 74 | 		walk_state->scope_info = scope_info->scope.next; | 
 | 75 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | 		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
 | 77 | 				  "Popped object type (%s)\n", | 
 | 78 | 				  acpi_ut_get_type_name(scope_info->common. | 
 | 79 | 							value))); | 
 | 80 | 		acpi_ut_delete_generic_state(scope_info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | 	} | 
 | 82 | } | 
 | 83 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /**************************************************************************** | 
 | 85 |  * | 
 | 86 |  * FUNCTION:    acpi_ds_scope_stack_push | 
 | 87 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 88 |  * PARAMETERS:  Node            - Name to be made current | 
 | 89 |  *              Type            - Type of frame being pushed | 
 | 90 |  *              walk_state      - Current state | 
 | 91 |  * | 
 | 92 |  * RETURN:      Status | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 |  * | 
 | 94 |  * DESCRIPTION: Push the current scope on the scope stack, and make the | 
 | 95 |  *              passed Node current. | 
 | 96 |  * | 
 | 97 |  ***************************************************************************/ | 
 | 98 |  | 
 | 99 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 100 | acpi_ds_scope_stack_push(struct acpi_namespace_node *node, | 
 | 101 | 			 acpi_object_type type, | 
 | 102 | 			 struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | 	union acpi_generic_state *scope_info; | 
 | 105 | 	union acpi_generic_state *old_scope_info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 107 | 	ACPI_FUNCTION_TRACE(ds_scope_stack_push); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
 | 109 | 	if (!node) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 110 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | 		/* Invalid scope   */ | 
 | 112 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 113 | 		ACPI_ERROR((AE_INFO, "Null scope parameter")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | 	} | 
 | 116 |  | 
 | 117 | 	/* Make sure object type is valid */ | 
 | 118 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | 	if (!acpi_ut_valid_object_type(type)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 120 | 		ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | 	} | 
 | 122 |  | 
 | 123 | 	/* Allocate a new scope object */ | 
 | 124 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | 	scope_info = acpi_ut_create_generic_state(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | 	if (!scope_info) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | 		return_ACPI_STATUS(AE_NO_MEMORY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | 	} | 
 | 129 |  | 
 | 130 | 	/* Init new scope object */ | 
 | 131 |  | 
| Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 132 | 	scope_info->common.descriptor_type = ACPI_DESC_TYPE_STATE_WSCOPE; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | 	scope_info->scope.node = node; | 
 | 134 | 	scope_info->common.value = (u16) type; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 |  | 
 | 136 | 	walk_state->scope_depth++; | 
 | 137 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | 	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
 | 139 | 			  "[%.2d] Pushed scope ", | 
 | 140 | 			  (u32) walk_state->scope_depth)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 |  | 
 | 142 | 	old_scope_info = walk_state->scope_info; | 
 | 143 | 	if (old_scope_info) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | 		ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, | 
 | 145 | 				      "[%4.4s] (%s)", | 
 | 146 | 				      acpi_ut_get_node_name(old_scope_info-> | 
 | 147 | 							    scope.node), | 
 | 148 | 				      acpi_ut_get_type_name(old_scope_info-> | 
 | 149 | 							    common.value))); | 
 | 150 | 	} else { | 
 | 151 | 		ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (%s)", "ROOT")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | 	} | 
 | 153 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | 	ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, | 
 | 155 | 			      ", New scope -> [%4.4s] (%s)\n", | 
 | 156 | 			      acpi_ut_get_node_name(scope_info->scope.node), | 
 | 157 | 			      acpi_ut_get_type_name(scope_info->common.value))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 |  | 
 | 159 | 	/* Push new scope object onto stack */ | 
 | 160 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | 	acpi_ut_push_generic_state(&walk_state->scope_info, scope_info); | 
 | 162 | 	return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } | 
 | 164 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /**************************************************************************** | 
 | 166 |  * | 
 | 167 |  * FUNCTION:    acpi_ds_scope_stack_pop | 
 | 168 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 169 |  * PARAMETERS:  walk_state      - Current state | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 171 |  * RETURN:      Status | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 173 |  * DESCRIPTION: Pop the scope stack once. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 |  * | 
 | 175 |  ***************************************************************************/ | 
 | 176 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | 	union acpi_generic_state *scope_info; | 
 | 180 | 	union acpi_generic_state *new_scope_info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 182 | 	ACPI_FUNCTION_TRACE(ds_scope_stack_pop); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
 | 184 | 	/* | 
 | 185 | 	 * Pop scope info object off the stack. | 
 | 186 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | 	scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | 	if (!scope_info) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | 		return_ACPI_STATUS(AE_STACK_UNDERFLOW); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | 	} | 
 | 191 |  | 
 | 192 | 	walk_state->scope_depth--; | 
 | 193 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | 	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
 | 195 | 			  "[%.2d] Popped scope [%4.4s] (%s), New scope -> ", | 
 | 196 | 			  (u32) walk_state->scope_depth, | 
 | 197 | 			  acpi_ut_get_node_name(scope_info->scope.node), | 
 | 198 | 			  acpi_ut_get_type_name(scope_info->common.value))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 |  | 
 | 200 | 	new_scope_info = walk_state->scope_info; | 
 | 201 | 	if (new_scope_info) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | 		ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, | 
 | 203 | 				      "[%4.4s] (%s)\n", | 
 | 204 | 				      acpi_ut_get_node_name(new_scope_info-> | 
 | 205 | 							    scope.node), | 
 | 206 | 				      acpi_ut_get_type_name(new_scope_info-> | 
 | 207 | 							    common.value))); | 
 | 208 | 	} else { | 
 | 209 | 		ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (ROOT)\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | 	} | 
 | 211 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | 	acpi_ut_delete_generic_state(scope_info); | 
 | 213 | 	return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |