^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: dbexec - debugger control method execution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "acdebug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "acnamesp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define _COMPONENT ACPI_CA_DEBUGGER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) ACPI_MODULE_NAME("dbexec")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static struct acpi_db_method_info acpi_gbl_db_method_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) acpi_db_execute_method(struct acpi_db_method_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct acpi_buffer *return_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static acpi_status acpi_db_execute_setup(struct acpi_db_method_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static u32 acpi_db_get_outstanding_allocations(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void ACPI_SYSTEM_XFACE acpi_db_method_thread(void *context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) acpi_db_execution_walk(acpi_handle obj_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u32 nesting_level, void *context, void **return_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static void ACPI_SYSTEM_XFACE acpi_db_single_execution_thread(void *context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * FUNCTION: acpi_db_delete_objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * PARAMETERS: count - Count of objects in the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * objects - Array of ACPI_OBJECTs to be deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * packages via recursion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) *
^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) void acpi_db_delete_objects(u32 count, union acpi_object *objects)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) switch (objects[i].type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) case ACPI_TYPE_BUFFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ACPI_FREE(objects[i].buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) case ACPI_TYPE_PACKAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Recursive call to delete package elements */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) acpi_db_delete_objects(objects[i].package.count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) objects[i].package.elements);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* Free the elements array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ACPI_FREE(objects[i].package.elements);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * FUNCTION: acpi_db_execute_method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * PARAMETERS: info - Valid info segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * return_obj - Where to put return object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * DESCRIPTION: Execute a control method. Used to evaluate objects via the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * "EXECUTE" or "EVALUATE" commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) acpi_db_execute_method(struct acpi_db_method_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct acpi_buffer *return_obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct acpi_object_list param_objects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) union acpi_object params[ACPI_DEBUGGER_MAX_ARGS + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ACPI_FUNCTION_TRACE(db_execute_method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (acpi_gbl_db_output_to_file && !acpi_dbg_level) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) acpi_os_printf("Warning: debug output is not enabled!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) param_objects.count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) param_objects.pointer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* Pass through any command-line arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (info->args && info->args[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* Get arguments passed on the command line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) for (i = 0; (info->args[i] && *(info->args[i])); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* Convert input string (token) to an actual union acpi_object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) status = acpi_db_convert_to_object(info->types[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) info->args[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ¶ms[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) "While parsing method arguments"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^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) param_objects.count = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) param_objects.pointer = params;
^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) /* Prepare for a return object of arbitrary size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return_obj->pointer = acpi_gbl_db_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return_obj->length = ACPI_DEBUG_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* Do the actual method execution */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) acpi_gbl_method_executing = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) status = acpi_evaluate_object(NULL, info->pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ¶m_objects, return_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) acpi_gbl_cm_single_step = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) acpi_gbl_method_executing = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if ((status == AE_ABORT_METHOD) || acpi_gbl_abort_method) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* Clear the abort and fall back to the debugger prompt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) "Aborting top-level method"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) acpi_gbl_abort_method = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) goto cleanup;
^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) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) "while executing %s from AML Debugger",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) info->pathname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (status == AE_BUFFER_OVERFLOW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) "Possible buffer overflow within AML Debugger "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) "buffer (size 0x%X needed 0x%X)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ACPI_DEBUG_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) (u32)return_obj->length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^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) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) acpi_db_delete_objects(param_objects.count, params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * FUNCTION: acpi_db_execute_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * PARAMETERS: info - Valid method info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * DESCRIPTION: Setup info segment prior to method execution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static acpi_status acpi_db_execute_setup(struct acpi_db_method_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ACPI_FUNCTION_NAME(db_execute_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* Concatenate the current scope to the supplied name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) info->pathname[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if ((info->name[0] != '\\') && (info->name[0] != '/')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (acpi_ut_safe_strcat(info->pathname, sizeof(info->pathname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) acpi_gbl_db_scope_buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) status = AE_BUFFER_OVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) goto error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (acpi_ut_safe_strcat(info->pathname, sizeof(info->pathname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) info->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) status = AE_BUFFER_OVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) goto error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) acpi_db_prep_namestring(info->pathname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) acpi_os_printf("Evaluating %s\n", info->pathname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (info->flags & EX_SINGLE_STEP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) acpi_gbl_cm_single_step = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* No single step, allow redirection to a file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) error_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ACPI_EXCEPTION((AE_INFO, status, "During setup for method execution"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #ifdef ACPI_DBG_TRACK_ALLOCATIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) u32 acpi_db_get_cache_info(struct acpi_memory_list *cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return (cache->total_allocated - cache->total_freed -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) cache->current_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * FUNCTION: acpi_db_get_outstanding_allocations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * PARAMETERS: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * RETURN: Current global allocation count minus cache entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * DESCRIPTION: Determine the current number of "outstanding" allocations --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * those allocations that have not been freed and also are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * in one of the various object caches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static u32 acpi_db_get_outstanding_allocations(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) u32 outstanding = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #ifdef ACPI_DBG_TRACK_ALLOCATIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) outstanding += acpi_db_get_cache_info(acpi_gbl_state_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) outstanding += acpi_db_get_cache_info(acpi_gbl_ps_node_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) outstanding += acpi_db_get_cache_info(acpi_gbl_ps_node_ext_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) outstanding += acpi_db_get_cache_info(acpi_gbl_operand_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return (outstanding);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * FUNCTION: acpi_db_execution_walk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * PARAMETERS: WALK_CALLBACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * DESCRIPTION: Execute a control method. Name is relative to the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * scope.
^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) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) acpi_db_execution_walk(acpi_handle obj_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) u32 nesting_level, void *context, void **return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) union acpi_operand_object *obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct acpi_namespace_node *node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) (struct acpi_namespace_node *)obj_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct acpi_buffer return_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) obj_desc = acpi_ns_get_attached_object(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (obj_desc->method.param_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return_obj.pointer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return_obj.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) acpi_ns_print_node_pathname(node, "Evaluating");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* Do the actual method execution */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) acpi_os_printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) acpi_gbl_method_executing = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) status = acpi_evaluate_object(node, NULL, NULL, &return_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) acpi_gbl_method_executing = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) acpi_os_printf("Evaluation of [%4.4s] returned %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) acpi_ut_get_node_name(node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^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) * FUNCTION: acpi_db_execute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * PARAMETERS: name - Name of method to execute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * args - Parameters to the method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * Types -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * flags - single step/no single step
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * DESCRIPTION: Execute a control method. Name is relative to the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * scope. Function used for the "EXECUTE", "EVALUATE", and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * "ALL" commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) acpi_db_execute(char *name, char **args, acpi_object_type *types, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct acpi_buffer return_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) char *name_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) #ifdef ACPI_DEBUG_OUTPUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) u32 previous_allocations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) u32 allocations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * Allow one execution to be performed by debugger or single step
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * execution will be dead locked by the interpreter mutexes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (acpi_gbl_method_executing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) acpi_os_printf("Only one debugger execution is allowed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #ifdef ACPI_DEBUG_OUTPUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* Memory allocation tracking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) previous_allocations = acpi_db_get_outstanding_allocations();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (*name == '*') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) (void)acpi_walk_namespace(ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ACPI_UINT32_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) acpi_db_execution_walk, NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if ((flags & EX_ALL) && (strlen(name) > 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) acpi_os_printf("Input name (%s) must be a 4-char NameSeg\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) name_string = ACPI_ALLOCATE(strlen(name) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (!name_string) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) strcpy(name_string, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) acpi_ut_strupr(name_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /* Subcommand to Execute all predefined names in the namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (!strncmp(name_string, "PREDEF", 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) acpi_db_evaluate_predefined_names();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ACPI_FREE(name_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /* Command (ALL <nameseg>) to execute all methods of a particular name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) else if (flags & EX_ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) acpi_gbl_db_method_info.name = name_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return_obj.pointer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return_obj.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) acpi_db_evaluate_all(name_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) ACPI_FREE(name_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) acpi_gbl_db_method_info.name = name_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) acpi_gbl_db_method_info.args = args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) acpi_gbl_db_method_info.types = types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) acpi_gbl_db_method_info.flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return_obj.pointer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return_obj.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ACPI_FREE(name_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /* Get the NS node, determines existence also */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) &acpi_gbl_db_method_info.method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) status = acpi_db_execute_method(&acpi_gbl_db_method_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) &return_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) ACPI_FREE(name_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * Allow any handlers in separate threads to complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * (Such as Notify handlers invoked from AML executed above).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) acpi_os_sleep((u64)10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) #ifdef ACPI_DEBUG_OUTPUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* Memory allocation tracking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) allocations =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) acpi_db_get_outstanding_allocations() - previous_allocations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (allocations > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) acpi_os_printf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ("0x%X Outstanding allocations after evaluation of %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) allocations, acpi_gbl_db_method_info.pathname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) acpi_os_printf("Evaluation of %s failed with status %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) acpi_gbl_db_method_info.pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* Display a return object, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (return_obj.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) acpi_os_printf("Evaluation of %s returned object %p, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) "external buffer length %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) acpi_gbl_db_method_info.pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return_obj.pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) (u32)return_obj.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) acpi_db_dump_external_object(return_obj.pointer, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) acpi_os_printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) /* Dump a _PLD buffer if present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (ACPI_COMPARE_NAMESEG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) ((ACPI_CAST_PTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) (struct acpi_namespace_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) acpi_gbl_db_method_info.method)->name.ascii),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) METHOD_NAME__PLD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) acpi_db_dump_pld_buffer(return_obj.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) acpi_os_printf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) ("No object was returned from evaluation of %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) acpi_gbl_db_method_info.pathname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^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) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * FUNCTION: acpi_db_method_thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * PARAMETERS: context - Execution info segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * DESCRIPTION: Debugger execute thread. Waits for a command line, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * simply dispatches it.
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static void ACPI_SYSTEM_XFACE acpi_db_method_thread(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct acpi_db_method_info *info = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct acpi_db_method_info local_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) u8 allow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct acpi_buffer return_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * acpi_gbl_db_method_info.Arguments will be passed as method arguments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * Prevent acpi_gbl_db_method_info from being modified by multiple threads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * concurrently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * Note: The arguments we are passing are used by the ASL test suite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * (aslts). Do not change them without updating the tests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) (void)acpi_os_wait_semaphore(info->info_gate, 1, ACPI_WAIT_FOREVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (info->init_args) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) acpi_db_uint32_to_hex_string(info->num_created,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) info->index_of_thread_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) acpi_db_uint32_to_hex_string((u32)acpi_os_get_thread_id(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) info->id_of_thread_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (info->threads && (info->num_created < info->num_threads)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) info->threads[info->num_created++] = acpi_os_get_thread_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) local_info = *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) local_info.args = local_info.arguments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) local_info.arguments[0] = local_info.num_threads_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) local_info.arguments[1] = local_info.id_of_thread_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) local_info.arguments[2] = local_info.index_of_thread_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) local_info.arguments[3] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) local_info.types = local_info.arg_types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) (void)acpi_os_signal_semaphore(info->info_gate, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) for (i = 0; i < info->num_loops; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) status = acpi_db_execute_method(&local_info, &return_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) acpi_os_printf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) ("%s During evaluation of %s at iteration %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) acpi_format_exception(status), info->pathname, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) if (status == AE_ABORT_METHOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if ((i % 100) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) acpi_os_printf("%u loops, Thread 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) i, acpi_os_get_thread_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (return_obj.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) acpi_os_printf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) ("Evaluation of %s returned object %p Buflen %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) info->pathname, return_obj.pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) (u32)return_obj.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) acpi_db_dump_external_object(return_obj.pointer, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* Signal our completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) allow = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) (void)acpi_os_wait_semaphore(info->thread_complete_gate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 1, ACPI_WAIT_FOREVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) info->num_completed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (info->num_completed == info->num_threads) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* Do signal for main thread once only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) allow = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) (void)acpi_os_signal_semaphore(info->thread_complete_gate, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (allow) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) status = acpi_os_signal_semaphore(info->main_thread_gate, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) acpi_os_printf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ("Could not signal debugger thread sync semaphore, %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^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) * FUNCTION: acpi_db_single_execution_thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * PARAMETERS: context - Method info struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) * DESCRIPTION: Create one thread and execute a method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) static void ACPI_SYSTEM_XFACE acpi_db_single_execution_thread(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct acpi_db_method_info *info = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct acpi_buffer return_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) acpi_os_printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) status = acpi_db_execute_method(info, &return_obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) acpi_os_printf("%s During evaluation of %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) acpi_format_exception(status), info->pathname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /* Display a return object, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (return_obj.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) acpi_os_printf("Evaluation of %s returned object %p, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) "external buffer length %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) acpi_gbl_db_method_info.pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) return_obj.pointer, (u32)return_obj.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) acpi_db_dump_external_object(return_obj.pointer, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) acpi_os_printf("\nBackground thread completed\n%c ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) ACPI_DEBUGGER_COMMAND_PROMPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^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) * FUNCTION: acpi_db_create_execution_thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * PARAMETERS: method_name_arg - Control method to execute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * arguments - Array of arguments to the method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * types - Corresponding array of object types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * DESCRIPTION: Create a single thread to evaluate a namespace object. Handles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * arguments passed on command line for control methods.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) acpi_db_create_execution_thread(char *method_name_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) char **arguments, acpi_object_type *types)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) acpi_gbl_db_method_info.name = method_name_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) acpi_gbl_db_method_info.init_args = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) acpi_gbl_db_method_info.args = acpi_gbl_db_method_info.arguments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) acpi_gbl_db_method_info.types = acpi_gbl_db_method_info.arg_types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /* Setup method arguments, up to 7 (0-6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && *arguments; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) acpi_gbl_db_method_info.arguments[i] = *arguments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) arguments++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) acpi_gbl_db_method_info.arg_types[i] = *types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) types++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* Get the NS node, determines existence also */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) &acpi_gbl_db_method_info.method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) acpi_os_printf("%s Could not get handle for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) acpi_format_exception(status),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) acpi_gbl_db_method_info.pathname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) status = acpi_os_execute(OSL_DEBUGGER_EXEC_THREAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) acpi_db_single_execution_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) &acpi_gbl_db_method_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) acpi_os_printf("\nBackground thread started\n");
^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) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * FUNCTION: acpi_db_create_execution_threads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * PARAMETERS: num_threads_arg - Number of threads to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * num_loops_arg - Loop count for the thread(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) * method_name_arg - Control method to execute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) * DESCRIPTION: Create threads to execute method(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) acpi_db_create_execution_threads(char *num_threads_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) char *num_loops_arg, char *method_name_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) u32 num_threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) u32 num_loops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) acpi_mutex main_thread_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) acpi_mutex thread_complete_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) acpi_mutex info_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) /* Get the arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) num_threads = strtoul(num_threads_arg, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) num_loops = strtoul(num_loops_arg, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) if (!num_threads || !num_loops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) acpi_os_printf("Bad argument: Threads %X, Loops %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) num_threads, num_loops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * Create the semaphore for synchronization of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * the created threads with the main thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) status = acpi_os_create_semaphore(1, 0, &main_thread_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) acpi_os_printf("Could not create semaphore for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) "synchronization with the main thread, %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) * Create the semaphore for synchronization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) * between the created threads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) status = acpi_os_create_semaphore(1, 1, &thread_complete_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) acpi_os_printf("Could not create semaphore for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) "synchronization between the created threads, %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) (void)acpi_os_delete_semaphore(main_thread_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) return;
^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) status = acpi_os_create_semaphore(1, 1, &info_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) acpi_os_printf("Could not create semaphore for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) "synchronization of AcpiGbl_DbMethodInfo, %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) (void)acpi_os_delete_semaphore(thread_complete_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) (void)acpi_os_delete_semaphore(main_thread_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) /* Array to store IDs of threads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) acpi_gbl_db_method_info.num_threads = num_threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) size = sizeof(acpi_thread_id) * acpi_gbl_db_method_info.num_threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) acpi_gbl_db_method_info.threads = acpi_os_allocate(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (acpi_gbl_db_method_info.threads == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) acpi_os_printf("No memory for thread IDs array\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) (void)acpi_os_delete_semaphore(main_thread_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) (void)acpi_os_delete_semaphore(thread_complete_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) (void)acpi_os_delete_semaphore(info_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) memset(acpi_gbl_db_method_info.threads, 0, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) /* Setup the context to be passed to each thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) acpi_gbl_db_method_info.name = method_name_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) acpi_gbl_db_method_info.flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) acpi_gbl_db_method_info.num_loops = num_loops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) acpi_gbl_db_method_info.main_thread_gate = main_thread_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) acpi_gbl_db_method_info.thread_complete_gate = thread_complete_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) acpi_gbl_db_method_info.info_gate = info_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /* Init arguments to be passed to method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) acpi_gbl_db_method_info.init_args = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) acpi_gbl_db_method_info.args = acpi_gbl_db_method_info.arguments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) acpi_gbl_db_method_info.arguments[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) acpi_gbl_db_method_info.num_threads_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) acpi_gbl_db_method_info.arguments[1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) acpi_gbl_db_method_info.id_of_thread_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) acpi_gbl_db_method_info.arguments[2] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) acpi_gbl_db_method_info.index_of_thread_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) acpi_gbl_db_method_info.arguments[3] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) acpi_gbl_db_method_info.types = acpi_gbl_db_method_info.arg_types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) acpi_gbl_db_method_info.arg_types[0] = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) acpi_gbl_db_method_info.arg_types[1] = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) acpi_gbl_db_method_info.arg_types[2] = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) acpi_db_uint32_to_hex_string(num_threads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) acpi_gbl_db_method_info.num_threads_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) goto cleanup_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /* Get the NS node, determines existence also */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) &acpi_gbl_db_method_info.method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) acpi_os_printf("%s Could not get handle for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) acpi_format_exception(status),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) acpi_gbl_db_method_info.pathname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) goto cleanup_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) /* Create the threads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) acpi_os_printf("Creating %X threads to execute %X times each\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) num_threads, num_loops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) for (i = 0; i < (num_threads); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) acpi_os_execute(OSL_DEBUGGER_EXEC_THREAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) acpi_db_method_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) &acpi_gbl_db_method_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) /* Wait for all threads to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) (void)acpi_os_wait_semaphore(main_thread_gate, 1, ACPI_WAIT_FOREVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) acpi_os_printf("All threads (%X) have completed\n", num_threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) cleanup_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) /* Cleanup and exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) (void)acpi_os_delete_semaphore(main_thread_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) (void)acpi_os_delete_semaphore(thread_complete_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) (void)acpi_os_delete_semaphore(info_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) acpi_os_free(acpi_gbl_db_method_info.threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) acpi_gbl_db_method_info.threads = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }