blob: 7592176a8fa2eba4f3a288575a379c63cae088ef [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: dswscope - Scope stack manipulation
5 *
Bob Mooreda6f8322018-01-04 10:06:38 -08006 * Copyright (C) 2000 - 2018, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050011#include "accommon.h"
12#include "acdispat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040015ACPI_MODULE_NAME("dswscope")
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/****************************************************************************
18 *
19 * FUNCTION: acpi_ds_scope_stack_clear
20 *
Robert Moore44f6c012005-04-18 22:49:35 -040021 * PARAMETERS: walk_state - Current state
22 *
23 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 * DESCRIPTION: Pop (and free) everything on the scope stack except the
26 * root scope object (which remains at the stack top.)
27 *
28 ***************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040029void acpi_ds_scope_stack_clear(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Len Brown4be44fc2005-08-05 00:44:28 -040031 union acpi_generic_state *scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Bob Mooreb229cf92006-04-21 17:15:00 -040033 ACPI_FUNCTION_NAME(ds_scope_stack_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 while (walk_state->scope_info) {
Bob Moore52fc0b02006-10-02 00:00:00 -040036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 /* Pop a scope off the stack */
38
39 scope_info = walk_state->scope_info;
40 walk_state->scope_info = scope_info->scope.next;
41
Len Brown4be44fc2005-08-05 00:44:28 -040042 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
43 "Popped object type (%s)\n",
44 acpi_ut_get_type_name(scope_info->common.
45 value)));
Bob Moore1fad8732015-12-29 13:54:36 +080046
Len Brown4be44fc2005-08-05 00:44:28 -040047 acpi_ut_delete_generic_state(scope_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 }
49}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/****************************************************************************
52 *
53 * FUNCTION: acpi_ds_scope_stack_push
54 *
Bob Mooreba494be2012-07-12 09:40:10 +080055 * PARAMETERS: node - Name to be made current
56 * type - Type of frame being pushed
Robert Moore44f6c012005-04-18 22:49:35 -040057 * walk_state - Current state
58 *
59 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * DESCRIPTION: Push the current scope on the scope stack, and make the
62 * passed Node current.
63 *
64 ***************************************************************************/
65
66acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040067acpi_ds_scope_stack_push(struct acpi_namespace_node *node,
68 acpi_object_type type,
69 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Len Brown4be44fc2005-08-05 00:44:28 -040071 union acpi_generic_state *scope_info;
72 union acpi_generic_state *old_scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bob Mooreb229cf92006-04-21 17:15:00 -040074 ACPI_FUNCTION_TRACE(ds_scope_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 if (!node) {
Bob Moore52fc0b02006-10-02 00:00:00 -040077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 /* Invalid scope */
79
Bob Mooreb8e4d892006-01-27 16:43:00 -050080 ACPI_ERROR((AE_INFO, "Null scope parameter"));
Len Brown4be44fc2005-08-05 00:44:28 -040081 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 }
83
84 /* Make sure object type is valid */
85
Len Brown4be44fc2005-08-05 00:44:28 -040086 if (!acpi_ut_valid_object_type(type)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050087 ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type));
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
90 /* Allocate a new scope object */
91
Len Brown4be44fc2005-08-05 00:44:28 -040092 scope_info = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (!scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -040094 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
97 /* Init new scope object */
98
Bob Moore616861242006-03-17 16:44:00 -050099 scope_info->common.descriptor_type = ACPI_DESC_TYPE_STATE_WSCOPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400100 scope_info->scope.node = node;
101 scope_info->common.value = (u16) type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 walk_state->scope_depth++;
104
Len Brown4be44fc2005-08-05 00:44:28 -0400105 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
106 "[%.2d] Pushed scope ",
107 (u32) walk_state->scope_depth));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 old_scope_info = walk_state->scope_info;
110 if (old_scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400111 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
112 "[%4.4s] (%s)",
113 acpi_ut_get_node_name(old_scope_info->
114 scope.node),
115 acpi_ut_get_type_name(old_scope_info->
116 common.value)));
117 } else {
Bob Moore4032cc32018-05-08 14:06:11 -0700118 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, ACPI_NAMESPACE_ROOT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
120
Len Brown4be44fc2005-08-05 00:44:28 -0400121 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
122 ", New scope -> [%4.4s] (%s)\n",
123 acpi_ut_get_node_name(scope_info->scope.node),
124 acpi_ut_get_type_name(scope_info->common.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 /* Push new scope object onto stack */
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 acpi_ut_push_generic_state(&walk_state->scope_info, scope_info);
129 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/****************************************************************************
133 *
134 * FUNCTION: acpi_ds_scope_stack_pop
135 *
Robert Moore44f6c012005-04-18 22:49:35 -0400136 * PARAMETERS: walk_state - Current state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 *
Robert Moore44f6c012005-04-18 22:49:35 -0400138 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 *
Robert Moore44f6c012005-04-18 22:49:35 -0400140 * DESCRIPTION: Pop the scope stack once.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 *
142 ***************************************************************************/
143
Len Brown4be44fc2005-08-05 00:44:28 -0400144acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Len Brown4be44fc2005-08-05 00:44:28 -0400146 union acpi_generic_state *scope_info;
147 union acpi_generic_state *new_scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Bob Mooreb229cf92006-04-21 17:15:00 -0400149 ACPI_FUNCTION_TRACE(ds_scope_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 /*
152 * Pop scope info object off the stack.
153 */
Len Brown4be44fc2005-08-05 00:44:28 -0400154 scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (!scope_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400156 return_ACPI_STATUS(AE_STACK_UNDERFLOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 }
158
159 walk_state->scope_depth--;
160
Len Brown4be44fc2005-08-05 00:44:28 -0400161 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
162 "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
163 (u32) walk_state->scope_depth,
164 acpi_ut_get_node_name(scope_info->scope.node),
165 acpi_ut_get_type_name(scope_info->common.value)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 new_scope_info = walk_state->scope_info;
168 if (new_scope_info) {
Bob Moore4032cc32018-05-08 14:06:11 -0700169 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[%4.4s] (%s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400170 acpi_ut_get_node_name(new_scope_info->
171 scope.node),
172 acpi_ut_get_type_name(new_scope_info->
173 common.value)));
174 } else {
Bob Moore4032cc32018-05-08 14:06:11 -0700175 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "%s\n",
176 ACPI_NAMESPACE_ROOT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178
Len Brown4be44fc2005-08-05 00:44:28 -0400179 acpi_ut_delete_generic_state(scope_info);
180 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}