^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: dsmethod - Parser/Interpreter interface - control method parsing
^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) #include "acinterp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "acnamesp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "acparser.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "amlcode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "acdebug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define _COMPONENT ACPI_DISPATCHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) ACPI_MODULE_NAME("dsmethod")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) acpi_ds_detect_named_opcodes(struct acpi_walk_state *walk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) union acpi_parse_object **out_op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) acpi_ds_create_method_mutex(union acpi_operand_object *method_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * FUNCTION: acpi_ds_auto_serialize_method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * PARAMETERS: node - Namespace Node of the method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * obj_desc - Method object attached to node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * DESCRIPTION: Parse a control method AML to scan for control methods that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * need serialization due to the creation of named objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * NOTE: It is a bit of overkill to mark all such methods serialized, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * there is only a problem if the method actually blocks during execution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * A blocking operation is, for example, a Sleep() operation, or any access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * to an operation region. However, it is probably not possible to easily
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * detect whether a method will block or not, so we simply mark all suspicious
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * methods as serialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * NOTE2: This code is essentially a generic routine for parsing a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * control method.
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) acpi_ds_auto_serialize_method(struct acpi_namespace_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) union acpi_operand_object *obj_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) union acpi_parse_object *op = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct acpi_walk_state *walk_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ACPI_FUNCTION_TRACE_PTR(ds_auto_serialize_method, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) "Method auto-serialization parse [%4.4s] %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) acpi_ut_get_node_name(node), node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* Create/Init a root op for the method parse tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) op = acpi_ps_alloc_op(AML_METHOD_OP, obj_desc->method.aml_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (!op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) acpi_ps_set_name(op, node->name.integer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) op->common.node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Create and initialize a new walk state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) walk_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) acpi_ds_create_walk_state(node->owner_id, NULL, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (!walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) acpi_ps_free_op(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) status = acpi_ds_init_aml_walk(walk_state, op, node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) obj_desc->method.aml_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) obj_desc->method.aml_length, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) acpi_ds_delete_walk_state(walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) acpi_ps_free_op(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) walk_state->descending_callback = acpi_ds_detect_named_opcodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* Parse the method, scan for creation of named objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) status = acpi_ps_parse_aml(walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) acpi_ps_delete_parse_tree(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * FUNCTION: acpi_ds_detect_named_opcodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * PARAMETERS: walk_state - Current state of the parse tree walk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * out_op - Unused, required for parser interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * DESCRIPTION: Descending callback used during the loading of ACPI tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Currently used to detect methods that must be marked serialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * in order to avoid problems with the creation of named objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) *
^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) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) acpi_ds_detect_named_opcodes(struct acpi_walk_state *walk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) union acpi_parse_object **out_op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ACPI_FUNCTION_NAME(acpi_ds_detect_named_opcodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* We are only interested in opcodes that create a new name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) (walk_state->op_info->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) flags & (AML_NAMED | AML_CREATE | AML_FIELD))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * At this point, we know we have a Named object opcode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * Mark the method as serialized. Later code will create a mutex for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * this method to enforce serialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * Note, ACPI_METHOD_IGNORE_SYNC_LEVEL flag means that we will ignore the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * Sync Level mechanism for this method, even though it is now serialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * Otherwise, there can be conflicts with existing ASL code that actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * uses sync levels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) walk_state->method_desc->method.sync_level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) walk_state->method_desc->method.info_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) "Method serialized [%4.4s] %p - [%s] (%4.4X)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) walk_state->method_node->name.ascii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) walk_state->method_node, walk_state->op_info->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) walk_state->opcode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Abort the parse, no need to examine this method any further */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return (AE_CTRL_TERMINATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * FUNCTION: acpi_ds_method_error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * PARAMETERS: status - Execution status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * walk_state - Current state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * DESCRIPTION: Called on method error. Invoke the global exception handler if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * present, dump the method data if the debugger is configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Note: Allows the exception handler to change the status code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) u32 aml_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) acpi_name name = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Ignore AE_OK and control exception codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (ACPI_SUCCESS(status) || (status & AE_CODE_CONTROL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* Invoke the global exception handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (acpi_gbl_exception_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* Exit the interpreter, allow handler to execute methods */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) acpi_ex_exit_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * Handler can map the exception code to anything it wants, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * AE_OK, in which case the executing method will not be aborted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) aml_offset = (u32)ACPI_PTR_DIFF(walk_state->aml,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) walk_state->parser_state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) aml_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (walk_state->method_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) name = walk_state->method_node->name.integer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) } else if (walk_state->deferred_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) name = walk_state->deferred_node->name.integer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) status = acpi_gbl_exception_handler(status, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) walk_state->opcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) aml_offset, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) acpi_ex_enter_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) acpi_ds_clear_implicit_return(walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) acpi_ds_dump_method_stack(status, walk_state, walk_state->op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* Display method locals/args if debugger is present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #ifdef ACPI_DEBUGGER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) acpi_db_dump_method_info(status, walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * FUNCTION: acpi_ds_create_method_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * PARAMETERS: obj_desc - The method object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * DESCRIPTION: Create a mutex object for a serialized control method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) acpi_ds_create_method_mutex(union acpi_operand_object *method_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) union acpi_operand_object *mutex_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ACPI_FUNCTION_TRACE(ds_create_method_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* Create the new mutex object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) mutex_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!mutex_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* Create the actual OS Mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) status = acpi_os_create_mutex(&mutex_desc->mutex.os_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) acpi_ut_delete_object_desc(mutex_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) mutex_desc->mutex.sync_level = method_desc->method.sync_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) method_desc->method.mutex = mutex_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * FUNCTION: acpi_ds_begin_method_execution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * PARAMETERS: method_node - Node of the method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * obj_desc - The method object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * walk_state - current state, NULL if not yet executing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * a method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * increments the thread count, and waits at the method semaphore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * for clearance to execute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct acpi_walk_state *walk_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ACPI_FUNCTION_TRACE_PTR(ds_begin_method_execution, method_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (!method_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return_ACPI_STATUS(AE_NULL_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) acpi_ex_start_trace_method(method_node, obj_desc, walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* Prevent wraparound of thread count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (obj_desc->method.thread_count == ACPI_UINT8_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) "Method reached maximum reentrancy limit (255)"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return_ACPI_STATUS(AE_AML_METHOD_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * If this method is serialized, we need to acquire the method mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * Create a mutex for the method if it is defined to be Serialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * and a mutex has not already been created. We defer the mutex creation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * until a method is actually executed, to minimize the object count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (!obj_desc->method.mutex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) status = acpi_ds_create_method_mutex(obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * The current_sync_level (per-thread) must be less than or equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * the sync level of the method. This mechanism provides some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * deadlock prevention.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * If the method was auto-serialized, we just ignore the sync level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * mechanism, because auto-serialization of methods can interfere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * with ASL code that actually uses sync levels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * Top-level method invocation has no walk state at this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (walk_state &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) (!(obj_desc->method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) info_flags & ACPI_METHOD_IGNORE_SYNC_LEVEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) && (walk_state->thread->current_sync_level >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) obj_desc->method.mutex->mutex.sync_level)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) "Cannot acquire Mutex for method [%4.4s]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ", current SyncLevel is too large (%u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) acpi_ut_get_node_name(method_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) walk_state->thread->current_sync_level));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * Obtain the method mutex if necessary. Do not acquire mutex for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * recursive call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (!walk_state ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) !obj_desc->method.mutex->mutex.thread_id ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) (walk_state->thread->thread_id !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) obj_desc->method.mutex->mutex.thread_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * Acquire the method mutex. This releases the interpreter if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * block (and reacquires it before it returns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) acpi_ex_system_wait_mutex(obj_desc->method.mutex->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) mutex.os_mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ACPI_WAIT_FOREVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* Update the mutex and walk info and save the original sync_level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) obj_desc->method.mutex->mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) original_sync_level =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) walk_state->thread->current_sync_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) obj_desc->method.mutex->mutex.thread_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) walk_state->thread->thread_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * Update the current sync_level only if this is not an auto-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * serialized method. In the auto case, we have to ignore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * the sync level for the method mutex (created for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * auto-serialization) because we have no idea of what the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * sync level should be. Therefore, just ignore it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (!(obj_desc->method.info_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) ACPI_METHOD_IGNORE_SYNC_LEVEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) walk_state->thread->current_sync_level =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) obj_desc->method.sync_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) obj_desc->method.mutex->mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) original_sync_level =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) obj_desc->method.mutex->mutex.sync_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) obj_desc->method.mutex->mutex.thread_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) acpi_os_get_thread_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* Always increase acquisition depth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) obj_desc->method.mutex->mutex.acquisition_depth++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * Allocate an Owner ID for this method, only if this is the first thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * to begin concurrent execution. We only need one owner_id, even if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * method is invoked recursively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (!obj_desc->method.owner_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * Increment the method parse tree thread count since it has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * reentered one more time (even if it is the same thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) obj_desc->method.thread_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) acpi_method_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* On error, must release the method mutex (if present) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (obj_desc->method.mutex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) acpi_os_release_mutex(obj_desc->method.mutex->mutex.os_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * FUNCTION: acpi_ds_call_control_method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * PARAMETERS: thread - Info for this thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * this_walk_state - Current walk state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * op - Current Op to be walked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * DESCRIPTION: Transfer execution to a called control method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) acpi_ds_call_control_method(struct acpi_thread_state *thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct acpi_walk_state *this_walk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) union acpi_parse_object *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct acpi_namespace_node *method_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct acpi_walk_state *next_walk_state = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) union acpi_operand_object *obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct acpi_evaluate_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) "Calling method %p, currentstate=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) this_walk_state->prev_op, this_walk_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * Get the namespace entry for the control method we are about to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) method_node = this_walk_state->method_call_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!method_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return_ACPI_STATUS(AE_NULL_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) obj_desc = acpi_ns_get_attached_object(method_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (!obj_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return_ACPI_STATUS(AE_NULL_OBJECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /* Init for new method, possibly wait on method mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) acpi_ds_begin_method_execution(method_node, obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) this_walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /* Begin method parse/execution. Create a new walk state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) next_walk_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (!next_walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) status = AE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * The resolved arguments were put on the previous walk state's operand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * stack. Operands on the previous walk state stack always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * start at index 0. Also, null terminate the list of arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) this_walk_state->operands[this_walk_state->num_operands] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * Allocate and initialize the evaluation information block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * TBD: this is somewhat inefficient, should change interface to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * ds_init_aml_walk. For now, keeps this struct off the CPU stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (!info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) status = AE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) info->parameters = &this_walk_state->operands[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) obj_desc->method.aml_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) obj_desc->method.aml_length, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) ACPI_IMODE_EXECUTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) ACPI_FREE(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) next_walk_state->method_nesting_depth =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) this_walk_state->method_nesting_depth + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * Delete the operands on the previous walkstate operand stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * (they were copied to new objects)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) for (i = 0; i < obj_desc->method.param_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) acpi_ut_remove_reference(this_walk_state->operands[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) this_walk_state->operands[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /* Clear the operand stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) this_walk_state->num_operands = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) method_node->name.ascii, next_walk_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) this_walk_state->method_pathname =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) acpi_ns_get_normalized_pathname(method_node, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) this_walk_state->method_is_nested = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) /* Optional object evaluation log */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) ACPI_DEBUG_PRINT_RAW((ACPI_DB_EVALUATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) "%-26s: %*s%s\n", " Nested method call",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) next_walk_state->method_nesting_depth * 3, " ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) &this_walk_state->method_pathname[1]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /* Invoke an internal method if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (obj_desc->method.info_flags & ACPI_METHOD_INTERNAL_ONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) obj_desc->method.dispatch.implementation(next_walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (status == AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) status = AE_CTRL_TERMINATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* On error, we must terminate the method properly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) acpi_ds_terminate_control_method(obj_desc, next_walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) acpi_ds_delete_walk_state(next_walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * FUNCTION: acpi_ds_restart_control_method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * PARAMETERS: walk_state - State for preempted method (caller)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * return_desc - Return value from the called method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * DESCRIPTION: Restart a method that was preempted by another (nested) method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) * invocation. Handle the return value (if any) from the callee.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) union acpi_operand_object *return_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int same_as_implicit_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) ACPI_FUNCTION_TRACE_PTR(ds_restart_control_method, walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) acpi_ut_get_node_name(walk_state->method_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) walk_state->method_call_op, return_desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) walk_state->return_used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) walk_state->results, walk_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) /* Did the called method return a value? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (return_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) /* Is the implicit return object the same as the return desc? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) same_as_implicit_return =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) (walk_state->implicit_return_obj == return_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /* Are we actually going to use the return value? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (walk_state->return_used) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /* Save the return value from the previous method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) status = acpi_ds_result_push(return_desc, walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) acpi_ut_remove_reference(return_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) * Save as THIS method's return value in case it is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * immediately to yet another method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) walk_state->return_desc = return_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * The following code is the optional support for the so-called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * "implicit return". Some AML code assumes that the last value of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * method is "implicitly" returned to the caller, in the absence of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * explicit return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * Just save the last result of the method as the return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * NOTE: this is optional because the ASL language does not actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * support this behavior.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) else if (!acpi_ds_do_implicit_return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) (return_desc, walk_state, FALSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) || same_as_implicit_return) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * Delete the return value if it will not be used by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * calling method or remove one reference if the explicit return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * is the same as the implicit return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) acpi_ut_remove_reference(return_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) * FUNCTION: acpi_ds_terminate_control_method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * PARAMETERS: method_desc - Method object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) * walk_state - State associated with the method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) * DESCRIPTION: Terminate a control method. Delete everything that the method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) * created, delete all locals and arguments, and delete the parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) * tree if requested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) * MUTEX: Interpreter is locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) struct acpi_walk_state *walk_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) /* method_desc is required, walk_state is optional */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (!method_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) /* Delete all arguments and locals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) acpi_ds_method_data_delete_all(walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * Delete any namespace objects created anywhere within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) * namespace by the execution of this method. Unless:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) * 1) This method is a module-level executable code method, in which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) * case we want make the objects permanent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * 2) There are other threads executing the method, in which case we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * will wait until the last thread has completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (!(method_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) && (method_desc->method.thread_count == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /* Delete any direct children of (created by) this method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) (void)acpi_ex_exit_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) acpi_ns_delete_namespace_subtree(walk_state->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) method_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) (void)acpi_ex_enter_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * Delete any objects that were created by this method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * elsewhere in the namespace (if any were created).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * deletion such that we don't have to perform an entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * namespace walk for every control method execution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (method_desc->method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) info_flags & ACPI_METHOD_MODIFIED_NAMESPACE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) (void)acpi_ex_exit_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) acpi_ns_delete_namespace_by_owner(method_desc->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) owner_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) (void)acpi_ex_enter_interpreter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) method_desc->method.info_flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) ~ACPI_METHOD_MODIFIED_NAMESPACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * If method is serialized, release the mutex and restore the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) * current sync level for this thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (method_desc->method.mutex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* Acquisition Depth handles recursive calls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) method_desc->method.mutex->mutex.acquisition_depth--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (!method_desc->method.mutex->mutex.acquisition_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) walk_state->thread->current_sync_level =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) method_desc->method.mutex->mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) original_sync_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) acpi_os_release_mutex(method_desc->method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) mutex->mutex.os_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) method_desc->method.mutex->mutex.thread_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) /* Decrement the thread count on the method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if (method_desc->method.thread_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) method_desc->method.thread_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) ACPI_ERROR((AE_INFO, "Invalid zero thread count in method"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /* Are there any other threads currently executing this method? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (method_desc->method.thread_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * Additional threads. Do not release the owner_id in this case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * we immediately reuse it for the next thread executing this method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) "*** Completed execution of one thread, %u threads remaining\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) method_desc->method.thread_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) /* This is the only executing thread for this method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) * Support to dynamically change a method from not_serialized to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * Serialized if it appears that the method is incorrectly written and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * does not support multiple thread execution. The best example of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) * is if such a method creates namespace objects and blocks. A second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * thread will fail with an AE_ALREADY_EXISTS exception.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * This code is here because we must wait until the last thread exits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) * before marking the method as serialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (method_desc->method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) info_flags & ACPI_METHOD_SERIALIZED_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (walk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) ACPI_INFO(("Marking method %4.4s as Serialized "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) "because of AE_ALREADY_EXISTS error",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) walk_state->method_node->name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) ascii));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * Method tried to create an object twice and was marked as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * "pending serialized". The probable cause is that the method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * cannot handle reentrancy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) * The method was created as not_serialized, but it tried to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * a named object and then blocked, causing the second thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) * entrance to begin and then fail. Workaround this problem by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) * marking the method permanently as Serialized when the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * thread exits here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) method_desc->method.info_flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) ~ACPI_METHOD_SERIALIZED_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) method_desc->method.info_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) (ACPI_METHOD_SERIALIZED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) ACPI_METHOD_IGNORE_SYNC_LEVEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) method_desc->method.sync_level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) /* No more threads, we can free the owner_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) (method_desc->method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) info_flags & ACPI_METHOD_MODULE_LEVEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) acpi_ut_release_owner_id(&method_desc->method.owner_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) acpi_ex_stop_trace_method((struct acpi_namespace_node *)method_desc->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) method.node, method_desc, walk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }