^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: dswscope - Scope stack manipulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "acdispat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _COMPONENT ACPI_DISPATCHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) ACPI_MODULE_NAME("dswscope")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * FUNCTION: acpi_ds_scope_stack_clear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * PARAMETERS: walk_state - Current state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * DESCRIPTION: Pop (and free) everything on the scope stack except the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * root scope object (which remains at the stack top.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) void acpi_ds_scope_stack_clear(struct acpi_walk_state *walk_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) union acpi_generic_state *scope_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ACPI_FUNCTION_NAME(ds_scope_stack_clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) while (walk_state->scope_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Pop a scope off the stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) scope_info = walk_state->scope_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) walk_state->scope_info = scope_info->scope.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) "Popped object type (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) acpi_ut_get_type_name(scope_info->common.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) value)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) acpi_ut_delete_generic_state(scope_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * FUNCTION: acpi_ds_scope_stack_push
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * PARAMETERS: node - Name to be made current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * type - Type of frame being pushed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * walk_state - Current state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * DESCRIPTION: Push the current scope on the scope stack, and make the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * passed Node current.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) acpi_ds_scope_stack_push(struct acpi_namespace_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) acpi_object_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct acpi_walk_state *walk_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) union acpi_generic_state *scope_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) union acpi_generic_state *old_scope_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ACPI_FUNCTION_TRACE(ds_scope_stack_push);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (!node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Invalid scope */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ACPI_ERROR((AE_INFO, "Null scope parameter"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* Make sure object type is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (!acpi_ut_valid_object_type(type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ACPI_WARNING((AE_INFO, "Invalid object type: 0x%X", type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* Allocate a new scope object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) scope_info = acpi_ut_create_generic_state();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!scope_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* Init new scope object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) scope_info->common.descriptor_type = ACPI_DESC_TYPE_STATE_WSCOPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) scope_info->scope.node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) scope_info->common.value = (u16) type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) walk_state->scope_depth++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) "[%.2d] Pushed scope ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) (u32) walk_state->scope_depth));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) old_scope_info = walk_state->scope_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (old_scope_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) "[%4.4s] (%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) acpi_ut_get_node_name(old_scope_info->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) scope.node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) acpi_ut_get_type_name(old_scope_info->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) common.value)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, ACPI_NAMESPACE_ROOT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ", New scope -> [%4.4s] (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) acpi_ut_get_node_name(scope_info->scope.node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) acpi_ut_get_type_name(scope_info->common.value)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* Push new scope object onto stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) acpi_ut_push_generic_state(&walk_state->scope_info, scope_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * FUNCTION: acpi_ds_scope_stack_pop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * PARAMETERS: walk_state - Current state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * DESCRIPTION: Pop the scope stack once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) acpi_status acpi_ds_scope_stack_pop(struct acpi_walk_state *walk_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) union acpi_generic_state *scope_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) union acpi_generic_state *new_scope_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ACPI_FUNCTION_TRACE(ds_scope_stack_pop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * Pop scope info object off the stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) scope_info = acpi_ut_pop_generic_state(&walk_state->scope_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (!scope_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return_ACPI_STATUS(AE_STACK_UNDERFLOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) walk_state->scope_depth--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) (u32) walk_state->scope_depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) acpi_ut_get_node_name(scope_info->scope.node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) acpi_ut_get_type_name(scope_info->common.value)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) new_scope_info = walk_state->scope_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (new_scope_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "[%4.4s] (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) acpi_ut_get_node_name(new_scope_info->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) scope.node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) acpi_ut_get_type_name(new_scope_info->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) common.value)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ACPI_NAMESPACE_ROOT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) acpi_ut_delete_generic_state(scope_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }