/******************************************************************************1*2* Module Name: dswscope - Scope stack manipulation3*4*****************************************************************************/56/*7* Copyright (C) 2000 - 2011, Intel Corp.8* All rights reserved.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions, and the following disclaimer,15* without modification.16* 2. Redistributions in binary form must reproduce at minimum a disclaimer17* substantially similar to the "NO WARRANTY" disclaimer below18* ("Disclaimer") and any redistribution must be conditioned upon19* including a substantially similar Disclaimer requirement for further20* binary redistribution.21* 3. Neither the names of the above-listed copyright holders nor the names22* of any contributors may be used to endorse or promote products derived23* from this software without specific prior written permission.24*25* Alternatively, this software may be distributed under the terms of the26* GNU General Public License ("GPL") version 2 as published by the Free27* Software Foundation.28*29* NO WARRANTY30* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS31* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT32* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR33* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT34* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL35* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS36* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)37* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,38* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING39* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE40* POSSIBILITY OF SUCH DAMAGES.41*/4243#include <acpi/acpi.h>44#include "accommon.h"45#include "acdispat.h"4647#define _COMPONENT ACPI_DISPATCHER48ACPI_MODULE_NAME("dswscope")4950/****************************************************************************51*52* FUNCTION: acpi_ds_scope_stack_clear53*54* PARAMETERS: walk_state - Current state55*56* RETURN: None57*58* DESCRIPTION: Pop (and free) everything on the scope stack except the59* root scope object (which remains at the stack top.)60*61***************************************************************************/62void acpi_ds_scope_stack_clear(struct acpi_walk_state *walk_state)63{64union acpi_generic_state *scope_info;6566ACPI_FUNCTION_NAME(ds_scope_stack_clear);6768while (walk_state->scope_info) {6970/* Pop a scope off the stack */7172scope_info = walk_state->scope_info;73walk_state->scope_info = scope_info->scope.next;7475ACPI_DEBUG_PRINT((ACPI_DB_EXEC,76"Popped object type (%s)\n",77acpi_ut_get_type_name(scope_info->common.78value)));79acpi_ut_delete_generic_state(scope_info);80}81}8283/****************************************************************************84*85* FUNCTION: acpi_ds_scope_stack_push86*87* PARAMETERS: Node - Name to be made current88* Type - Type of frame being pushed89* walk_state - Current state90*91* RETURN: Status92*93* DESCRIPTION: Push the current scope on the scope stack, and make the94* passed Node current.95*96***************************************************************************/9798acpi_status99acpi_ds_scope_stack_push(struct acpi_namespace_node *node,100acpi_object_type type,101struct acpi_walk_state *walk_state)102{103union acpi_generic_state *scope_info;104union acpi_generic_state *old_scope_info;105106ACPI_FUNCTION_TRACE(ds_scope_stack_push);107108if (!node) {109110/* Invalid scope */111112ACPI_ERROR((AE_INFO, "Null scope parameter"));113return_ACPI_STATUS(AE_BAD_PARAMETER);114}115116/* Make sure object type is valid */117118if (!acpi_ut_valid_object_type(type)) {119ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type));120}121122/* Allocate a new scope object */123124scope_info = acpi_ut_create_generic_state();125if (!scope_info) {126return_ACPI_STATUS(AE_NO_MEMORY);127}128129/* Init new scope object */130131scope_info->common.descriptor_type = ACPI_DESC_TYPE_STATE_WSCOPE;132scope_info->scope.node = node;133scope_info->common.value = (u16) type;134135walk_state->scope_depth++;136137ACPI_DEBUG_PRINT((ACPI_DB_EXEC,138"[%.2d] Pushed scope ",139(u32) walk_state->scope_depth));140141old_scope_info = walk_state->scope_info;142if (old_scope_info) {143ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,144"[%4.4s] (%s)",145acpi_ut_get_node_name(old_scope_info->146scope.node),147acpi_ut_get_type_name(old_scope_info->148common.value)));149} else {150ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (%s)", "ROOT"));151}152153ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,154", New scope -> [%4.4s] (%s)\n",155acpi_ut_get_node_name(scope_info->scope.node),156acpi_ut_get_type_name(scope_info->common.value)));157158/* Push new scope object onto stack */159160acpi_ut_push_generic_state(&walk_state->scope_info, scope_info);161return_ACPI_STATUS(AE_OK);162}163164/****************************************************************************165*166* FUNCTION: acpi_ds_scope_stack_pop167*168* PARAMETERS: walk_state - Current state169*170* RETURN: Status171*172* DESCRIPTION: Pop the scope stack once.173*174***************************************************************************/175176acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)177{178union acpi_generic_state *scope_info;179union acpi_generic_state *new_scope_info;180181ACPI_FUNCTION_TRACE(ds_scope_stack_pop);182183/*184* Pop scope info object off the stack.185*/186scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info);187if (!scope_info) {188return_ACPI_STATUS(AE_STACK_UNDERFLOW);189}190191walk_state->scope_depth--;192193ACPI_DEBUG_PRINT((ACPI_DB_EXEC,194"[%.2d] Popped scope [%4.4s] (%s), New scope -> ",195(u32) walk_state->scope_depth,196acpi_ut_get_node_name(scope_info->scope.node),197acpi_ut_get_type_name(scope_info->common.value)));198199new_scope_info = walk_state->scope_info;200if (new_scope_info) {201ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,202"[%4.4s] (%s)\n",203acpi_ut_get_node_name(new_scope_info->204scope.node),205acpi_ut_get_type_name(new_scope_info->206common.value)));207} else {208ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (ROOT)\n"));209}210211acpi_ut_delete_generic_state(scope_info);212return_ACPI_STATUS(AE_OK);213}214215216