dswscope.c 6.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: dswscope - Scope stack manipulation
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2011, Intel Corp.
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
L
Len Brown 已提交
45 46
#include "accommon.h"
#include "acdispat.h"
L
Linus Torvalds 已提交
47 48

#define _COMPONENT          ACPI_DISPATCHER
L
Len Brown 已提交
49
ACPI_MODULE_NAME("dswscope")
L
Linus Torvalds 已提交
50 51 52 53 54

/****************************************************************************
 *
 * FUNCTION:    acpi_ds_scope_stack_clear
 *
R
Robert Moore 已提交
55 56 57
 * PARAMETERS:  walk_state      - Current state
 *
 * RETURN:      None
L
Linus Torvalds 已提交
58 59 60 61 62
 *
 * DESCRIPTION: Pop (and free) everything on the scope stack except the
 *              root scope object (which remains at the stack top.)
 *
 ***************************************************************************/
L
Len Brown 已提交
63
void acpi_ds_scope_stack_clear(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
64
{
L
Len Brown 已提交
65
	union acpi_generic_state *scope_info;
L
Linus Torvalds 已提交
66

B
Bob Moore 已提交
67
	ACPI_FUNCTION_NAME(ds_scope_stack_clear);
L
Linus Torvalds 已提交
68 69

	while (walk_state->scope_info) {
B
Bob Moore 已提交
70

L
Linus Torvalds 已提交
71 72 73 74 75
		/* Pop a scope off the stack */

		scope_info = walk_state->scope_info;
		walk_state->scope_info = scope_info->scope.next;

L
Len Brown 已提交
76 77 78 79 80
		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
				  "Popped object type (%s)\n",
				  acpi_ut_get_type_name(scope_info->common.
							value)));
		acpi_ut_delete_generic_state(scope_info);
L
Linus Torvalds 已提交
81 82 83 84 85 86 87
	}
}

/****************************************************************************
 *
 * FUNCTION:    acpi_ds_scope_stack_push
 *
R
Robert Moore 已提交
88 89 90 91 92
 * PARAMETERS:  Node            - Name to be made current
 *              Type            - Type of frame being pushed
 *              walk_state      - Current state
 *
 * RETURN:      Status
L
Linus Torvalds 已提交
93 94 95 96 97 98 99
 *
 * DESCRIPTION: Push the current scope on the scope stack, and make the
 *              passed Node current.
 *
 ***************************************************************************/

acpi_status
L
Len Brown 已提交
100 101 102
acpi_ds_scope_stack_push(struct acpi_namespace_node *node,
			 acpi_object_type type,
			 struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
103
{
L
Len Brown 已提交
104 105
	union acpi_generic_state *scope_info;
	union acpi_generic_state *old_scope_info;
L
Linus Torvalds 已提交
106

B
Bob Moore 已提交
107
	ACPI_FUNCTION_TRACE(ds_scope_stack_push);
L
Linus Torvalds 已提交
108 109

	if (!node) {
B
Bob Moore 已提交
110

L
Linus Torvalds 已提交
111 112
		/* Invalid scope   */

B
Bob Moore 已提交
113
		ACPI_ERROR((AE_INFO, "Null scope parameter"));
L
Len Brown 已提交
114
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
115 116 117 118
	}

	/* Make sure object type is valid */

L
Len Brown 已提交
119
	if (!acpi_ut_valid_object_type(type)) {
B
Bob Moore 已提交
120
		ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type));
L
Linus Torvalds 已提交
121 122 123 124
	}

	/* Allocate a new scope object */

L
Len Brown 已提交
125
	scope_info = acpi_ut_create_generic_state();
L
Linus Torvalds 已提交
126
	if (!scope_info) {
L
Len Brown 已提交
127
		return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
128 129 130 131
	}

	/* Init new scope object */

B
Bob Moore 已提交
132
	scope_info->common.descriptor_type = ACPI_DESC_TYPE_STATE_WSCOPE;
L
Len Brown 已提交
133 134
	scope_info->scope.node = node;
	scope_info->common.value = (u16) type;
L
Linus Torvalds 已提交
135 136 137

	walk_state->scope_depth++;

L
Len Brown 已提交
138 139 140
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
			  "[%.2d] Pushed scope ",
			  (u32) walk_state->scope_depth));
L
Linus Torvalds 已提交
141 142 143

	old_scope_info = walk_state->scope_info;
	if (old_scope_info) {
L
Len Brown 已提交
144 145 146 147 148 149 150 151
		ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
				      "[%4.4s] (%s)",
				      acpi_ut_get_node_name(old_scope_info->
							    scope.node),
				      acpi_ut_get_type_name(old_scope_info->
							    common.value)));
	} else {
		ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (%s)", "ROOT"));
L
Linus Torvalds 已提交
152 153
	}

L
Len Brown 已提交
154 155 156 157
	ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
			      ", New scope -> [%4.4s] (%s)\n",
			      acpi_ut_get_node_name(scope_info->scope.node),
			      acpi_ut_get_type_name(scope_info->common.value)));
L
Linus Torvalds 已提交
158 159 160

	/* Push new scope object onto stack */

L
Len Brown 已提交
161 162
	acpi_ut_push_generic_state(&walk_state->scope_info, scope_info);
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
163 164 165 166 167 168
}

/****************************************************************************
 *
 * FUNCTION:    acpi_ds_scope_stack_pop
 *
R
Robert Moore 已提交
169
 * PARAMETERS:  walk_state      - Current state
L
Linus Torvalds 已提交
170
 *
R
Robert Moore 已提交
171
 * RETURN:      Status
L
Linus Torvalds 已提交
172
 *
R
Robert Moore 已提交
173
 * DESCRIPTION: Pop the scope stack once.
L
Linus Torvalds 已提交
174 175 176
 *
 ***************************************************************************/

L
Len Brown 已提交
177
acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
178
{
L
Len Brown 已提交
179 180
	union acpi_generic_state *scope_info;
	union acpi_generic_state *new_scope_info;
L
Linus Torvalds 已提交
181

B
Bob Moore 已提交
182
	ACPI_FUNCTION_TRACE(ds_scope_stack_pop);
L
Linus Torvalds 已提交
183 184 185 186

	/*
	 * Pop scope info object off the stack.
	 */
L
Len Brown 已提交
187
	scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info);
L
Linus Torvalds 已提交
188
	if (!scope_info) {
L
Len Brown 已提交
189
		return_ACPI_STATUS(AE_STACK_UNDERFLOW);
L
Linus Torvalds 已提交
190 191 192 193
	}

	walk_state->scope_depth--;

L
Len Brown 已提交
194 195 196 197 198
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
			  "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
			  (u32) walk_state->scope_depth,
			  acpi_ut_get_node_name(scope_info->scope.node),
			  acpi_ut_get_type_name(scope_info->common.value)));
L
Linus Torvalds 已提交
199 200 201

	new_scope_info = walk_state->scope_info;
	if (new_scope_info) {
L
Len Brown 已提交
202 203 204 205 206 207 208 209
		ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
				      "[%4.4s] (%s)\n",
				      acpi_ut_get_node_name(new_scope_info->
							    scope.node),
				      acpi_ut_get_type_name(new_scope_info->
							    common.value)));
	} else {
		ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (ROOT)\n"));
L
Linus Torvalds 已提交
210 211
	}

L
Len Brown 已提交
212 213
	acpi_ut_delete_generic_state(scope_info);
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
214
}