blob: 9f32e08a07d98d8b3c2294769de9475ea9a5bddb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: dswscope - Scope stack manipulation
4 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
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>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acdispat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("dswscope")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/****************************************************************************
52 *
53 * FUNCTION: acpi_ds_scope_stack_clear
54 *
Robert Moore44f6c012005-04-18 22:49:35 -040055 * PARAMETERS: walk_state - Current state
56 *
57 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 *
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 Brown4be44fc2005-08-05 00:44:28 -040063void acpi_ds_scope_stack_clear(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Len Brown4be44fc2005-08-05 00:44:28 -040065 union acpi_generic_state *scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Bob Mooreb229cf92006-04-21 17:15:00 -040067 ACPI_FUNCTION_NAME(ds_scope_stack_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 while (walk_state->scope_info) {
Bob Moore52fc0b02006-10-02 00:00:00 -040070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 /* 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 Brown4be44fc2005-08-05 00:44:28 -040076 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
77 "Popped object type (%s)\n",
78 acpi_ut_get_type_name(scope_info->common.
79 value)));
Bob Moore1fad8732015-12-29 13:54:36 +080080
Len Brown4be44fc2005-08-05 00:44:28 -040081 acpi_ut_delete_generic_state(scope_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 }
83}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/****************************************************************************
86 *
87 * FUNCTION: acpi_ds_scope_stack_push
88 *
Bob Mooreba494be2012-07-12 09:40:10 +080089 * PARAMETERS: node - Name to be made current
90 * type - Type of frame being pushed
Robert Moore44f6c012005-04-18 22:49:35 -040091 * walk_state - Current state
92 *
93 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 *
95 * DESCRIPTION: Push the current scope on the scope stack, and make the
96 * passed Node current.
97 *
98 ***************************************************************************/
99
100acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400101acpi_ds_scope_stack_push(struct acpi_namespace_node *node,
102 acpi_object_type type,
103 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Len Brown4be44fc2005-08-05 00:44:28 -0400105 union acpi_generic_state *scope_info;
106 union acpi_generic_state *old_scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Bob Mooreb229cf92006-04-21 17:15:00 -0400108 ACPI_FUNCTION_TRACE(ds_scope_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 if (!node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 /* Invalid scope */
113
Bob Mooreb8e4d892006-01-27 16:43:00 -0500114 ACPI_ERROR((AE_INFO, "Null scope parameter"));
Len Brown4be44fc2005-08-05 00:44:28 -0400115 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117
118 /* Make sure object type is valid */
119
Len Brown4be44fc2005-08-05 00:44:28 -0400120 if (!acpi_ut_valid_object_type(type)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500121 ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
124 /* Allocate a new scope object */
125
Len Brown4be44fc2005-08-05 00:44:28 -0400126 scope_info = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if (!scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400128 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130
131 /* Init new scope object */
132
Bob Moore616861242006-03-17 16:44:00 -0500133 scope_info->common.descriptor_type = ACPI_DESC_TYPE_STATE_WSCOPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400134 scope_info->scope.node = node;
135 scope_info->common.value = (u16) type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 walk_state->scope_depth++;
138
Len Brown4be44fc2005-08-05 00:44:28 -0400139 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
140 "[%.2d] Pushed scope ",
141 (u32) walk_state->scope_depth));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 old_scope_info = walk_state->scope_info;
144 if (old_scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400145 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
146 "[%4.4s] (%s)",
147 acpi_ut_get_node_name(old_scope_info->
148 scope.node),
149 acpi_ut_get_type_name(old_scope_info->
150 common.value)));
151 } else {
152 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (%s)", "ROOT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
156 ", New scope -> [%4.4s] (%s)\n",
157 acpi_ut_get_node_name(scope_info->scope.node),
158 acpi_ut_get_type_name(scope_info->common.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 /* Push new scope object onto stack */
161
Len Brown4be44fc2005-08-05 00:44:28 -0400162 acpi_ut_push_generic_state(&walk_state->scope_info, scope_info);
163 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/****************************************************************************
167 *
168 * FUNCTION: acpi_ds_scope_stack_pop
169 *
Robert Moore44f6c012005-04-18 22:49:35 -0400170 * PARAMETERS: walk_state - Current state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 *
Robert Moore44f6c012005-04-18 22:49:35 -0400172 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 *
Robert Moore44f6c012005-04-18 22:49:35 -0400174 * DESCRIPTION: Pop the scope stack once.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 *
176 ***************************************************************************/
177
Len Brown4be44fc2005-08-05 00:44:28 -0400178acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Len Brown4be44fc2005-08-05 00:44:28 -0400180 union acpi_generic_state *scope_info;
181 union acpi_generic_state *new_scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Bob Mooreb229cf92006-04-21 17:15:00 -0400183 ACPI_FUNCTION_TRACE(ds_scope_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /*
186 * Pop scope info object off the stack.
187 */
Len Brown4be44fc2005-08-05 00:44:28 -0400188 scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if (!scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400190 return_ACPI_STATUS(AE_STACK_UNDERFLOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 }
192
193 walk_state->scope_depth--;
194
Len Brown4be44fc2005-08-05 00:44:28 -0400195 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
196 "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
197 (u32) walk_state->scope_depth,
198 acpi_ut_get_node_name(scope_info->scope.node),
199 acpi_ut_get_type_name(scope_info->common.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 new_scope_info = walk_state->scope_info;
202 if (new_scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
204 "[%4.4s] (%s)\n",
205 acpi_ut_get_node_name(new_scope_info->
206 scope.node),
207 acpi_ut_get_type_name(new_scope_info->
208 common.value)));
209 } else {
210 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[\\___] (ROOT)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213 acpi_ut_delete_generic_state(scope_info);
214 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}