dswscope.c 6.59 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: dswscope - Scope stack manipulation
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds's avatar
Linus Torvalds committed
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>
Len Brown's avatar
Len Brown committed
45 46
#include "accommon.h"
#include "acdispat.h"
Linus Torvalds's avatar
Linus Torvalds committed
47 48

#define _COMPONENT          ACPI_DISPATCHER
Len Brown's avatar
Len Brown committed
49
ACPI_MODULE_NAME("dswscope")
Linus Torvalds's avatar
Linus Torvalds committed
50 51 52 53 54

/****************************************************************************
 *
 * FUNCTION:    acpi_ds_scope_stack_clear
 *
Robert Moore's avatar
Robert Moore committed
55 56 57
 * PARAMETERS:  walk_state      - Current state
 *
 * RETURN:      None
Linus Torvalds's avatar
Linus Torvalds committed
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.)
 *
 ***************************************************************************/
Len Brown's avatar
Len Brown committed
63
void acpi_ds_scope_stack_clear(struct acpi_walk_state *walk_state)
Linus Torvalds's avatar
Linus Torvalds committed
64
{
Len Brown's avatar
Len Brown committed
65
	union acpi_generic_state *scope_info;
Linus Torvalds's avatar
Linus Torvalds committed
66

Bob Moore's avatar
Bob Moore committed
67
	ACPI_FUNCTION_NAME(ds_scope_stack_clear);
Linus Torvalds's avatar
Linus Torvalds committed
68 69

	while (walk_state->scope_info) {
Bob Moore's avatar
Bob Moore committed
70

Linus Torvalds's avatar
Linus Torvalds committed
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;

Len Brown's avatar
Len Brown committed
76 77 78 79
		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
				  "Popped object type (%s)\n",
				  acpi_ut_get_type_name(scope_info->common.
							value)));
80

Len Brown's avatar
Len Brown committed
81
		acpi_ut_delete_generic_state(scope_info);
Linus Torvalds's avatar
Linus Torvalds committed
82 83 84 85 86 87 88
	}
}

/****************************************************************************
 *
 * FUNCTION:    acpi_ds_scope_stack_push
 *
89 90
 * PARAMETERS:  node            - Name to be made current
 *              type            - Type of frame being pushed
Robert Moore's avatar
Robert Moore committed
91 92 93
 *              walk_state      - Current state
 *
 * RETURN:      Status
Linus Torvalds's avatar
Linus Torvalds committed
94 95 96 97 98 99 100
 *
 * DESCRIPTION: Push the current scope on the scope stack, and make the
 *              passed Node current.
 *
 ***************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
101 102 103
acpi_ds_scope_stack_push(struct acpi_namespace_node *node,
			 acpi_object_type type,
			 struct acpi_walk_state *walk_state)
Linus Torvalds's avatar
Linus Torvalds committed
104
{
Len Brown's avatar
Len Brown committed
105 106
	union acpi_generic_state *scope_info;
	union acpi_generic_state *old_scope_info;
Linus Torvalds's avatar
Linus Torvalds committed
107

Bob Moore's avatar
Bob Moore committed
108
	ACPI_FUNCTION_TRACE(ds_scope_stack_push);
Linus Torvalds's avatar
Linus Torvalds committed
109 110

	if (!node) {
Bob Moore's avatar
Bob Moore committed
111

Linus Torvalds's avatar
Linus Torvalds committed
112 113
		/* Invalid scope   */

Bob Moore's avatar
Bob Moore committed
114
		ACPI_ERROR((AE_INFO, "Null scope parameter"));
Len Brown's avatar
Len Brown committed
115
		return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds's avatar
Linus Torvalds committed
116 117 118 119
	}

	/* Make sure object type is valid */

Len Brown's avatar
Len Brown committed
120
	if (!acpi_ut_valid_object_type(type)) {
Bob Moore's avatar
Bob Moore committed
121
		ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type));
Linus Torvalds's avatar
Linus Torvalds committed
122 123 124 125
	}

	/* Allocate a new scope object */

Len Brown's avatar
Len Brown committed
126
	scope_info = acpi_ut_create_generic_state();
Linus Torvalds's avatar
Linus Torvalds committed
127
	if (!scope_info) {
Len Brown's avatar
Len Brown committed
128
		return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds's avatar
Linus Torvalds committed
129 130 131 132
	}

	/* Init new scope object */

Bob Moore's avatar
Bob Moore committed
133
	scope_info->common.descriptor_type = ACPI_DESC_TYPE_STATE_WSCOPE;
Len Brown's avatar
Len Brown committed
134 135
	scope_info->scope.node = node;
	scope_info->common.value = (u16) type;
Linus Torvalds's avatar
Linus Torvalds committed
136 137 138

	walk_state->scope_depth++;

Len Brown's avatar
Len Brown committed
139 140 141
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
			  "[%.2d] Pushed scope ",
			  (u32) walk_state->scope_depth));
Linus Torvalds's avatar
Linus Torvalds committed
142 143 144

	old_scope_info = walk_state->scope_info;
	if (old_scope_info) {
Len Brown's avatar
Len Brown committed
145 146 147 148 149 150 151 152
		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"));
Linus Torvalds's avatar
Linus Torvalds committed
153 154
	}

Len Brown's avatar
Len Brown committed
155 156 157 158
	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)));
Linus Torvalds's avatar
Linus Torvalds committed
159 160 161

	/* Push new scope object onto stack */

Len Brown's avatar
Len Brown committed
162 163
	acpi_ut_push_generic_state(&walk_state->scope_info, scope_info);
	return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
164 165 166 167 168 169
}

/****************************************************************************
 *
 * FUNCTION:    acpi_ds_scope_stack_pop
 *
Robert Moore's avatar
Robert Moore committed
170
 * PARAMETERS:  walk_state      - Current state
Linus Torvalds's avatar
Linus Torvalds committed
171
 *
Robert Moore's avatar
Robert Moore committed
172
 * RETURN:      Status
Linus Torvalds's avatar
Linus Torvalds committed
173
 *
Robert Moore's avatar
Robert Moore committed
174
 * DESCRIPTION: Pop the scope stack once.
Linus Torvalds's avatar
Linus Torvalds committed
175 176 177
 *
 ***************************************************************************/

Len Brown's avatar
Len Brown committed
178
acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)
Linus Torvalds's avatar
Linus Torvalds committed
179
{
Len Brown's avatar
Len Brown committed
180 181
	union acpi_generic_state *scope_info;
	union acpi_generic_state *new_scope_info;
Linus Torvalds's avatar
Linus Torvalds committed
182

Bob Moore's avatar
Bob Moore committed
183
	ACPI_FUNCTION_TRACE(ds_scope_stack_pop);
Linus Torvalds's avatar
Linus Torvalds committed
184 185 186 187

	/*
	 * Pop scope info object off the stack.
	 */
Len Brown's avatar
Len Brown committed
188
	scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info);
Linus Torvalds's avatar
Linus Torvalds committed
189
	if (!scope_info) {
Len Brown's avatar
Len Brown committed
190
		return_ACPI_STATUS(AE_STACK_UNDERFLOW);
Linus Torvalds's avatar
Linus Torvalds committed
191 192 193 194
	}

	walk_state->scope_depth--;

Len Brown's avatar
Len Brown committed
195 196 197 198 199
	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)));
Linus Torvalds's avatar
Linus Torvalds committed
200 201 202

	new_scope_info = walk_state->scope_info;
	if (new_scope_info) {
Len Brown's avatar
Len Brown committed
203 204 205 206 207 208 209 210
		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"));
Linus Torvalds's avatar
Linus Torvalds committed
211 212
	}

Len Brown's avatar
Len Brown committed
213 214
	acpi_ut_delete_generic_state(scope_info);
	return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
215
}