python_code
stringlengths
0
1.8M
repo_name
stringclasses
7 values
file_path
stringlengths
5
99
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: nsxfobj - Public interfaces to the ACPI subsystem * ACPI Object oriented interfaces * ******************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsxfobj") /******************************************************************************* * * FUNCTION: acpi_get_type * * PARAMETERS: handle - Handle of object whose type is desired * ret_type - Where the type will be placed * * RETURN: Status * * DESCRIPTION: This routine returns the type associated with a particular * handle * ******************************************************************************/ acpi_status acpi_get_type(acpi_handle handle, acpi_object_type *ret_type) { struct acpi_namespace_node *node; acpi_status status; /* Parameter Validation */ if (!ret_type) { return (AE_BAD_PARAMETER); } /* Special case for the predefined Root Node (return type ANY) */ if (handle == ACPI_ROOT_OBJECT) { *ret_type = ACPI_TYPE_ANY; return (AE_OK); } status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } /* Convert and validate the handle */ node = acpi_ns_validate_handle(handle); if (!node) { (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (AE_BAD_PARAMETER); } *ret_type = node->type; status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status); } ACPI_EXPORT_SYMBOL(acpi_get_type) /******************************************************************************* * * FUNCTION: acpi_get_parent * * PARAMETERS: handle - Handle of object whose parent is desired * ret_handle - Where the parent handle will be placed * * RETURN: Status * * DESCRIPTION: Returns a handle to the parent of the object represented by * Handle. * ******************************************************************************/ acpi_status acpi_get_parent(acpi_handle handle, acpi_handle *ret_handle) { struct acpi_namespace_node *node; struct acpi_namespace_node *parent_node; acpi_status status; if (!ret_handle) { return (AE_BAD_PARAMETER); } /* Special case for the predefined Root Node (no parent) */ if (handle == ACPI_ROOT_OBJECT) { return (AE_NULL_ENTRY); } status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } /* Convert and validate the handle */ node = acpi_ns_validate_handle(handle); if (!node) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } /* Get the parent entry */ parent_node = node->parent; *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node); /* Return exception if parent is null */ if (!parent_node) { status = AE_NULL_ENTRY; } unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status); } ACPI_EXPORT_SYMBOL(acpi_get_parent) /******************************************************************************* * * FUNCTION: acpi_get_next_object * * PARAMETERS: type - Type of object to be searched for * parent - Parent object whose children we are getting * last_child - Previous child that was found. * The NEXT child will be returned * ret_handle - Where handle to the next object is placed * * RETURN: Status * * DESCRIPTION: Return the next peer object within the namespace. If Handle is * valid, Scope is ignored. Otherwise, the first object within * Scope is returned. * ******************************************************************************/ acpi_status acpi_get_next_object(acpi_object_type type, acpi_handle parent, acpi_handle child, acpi_handle *ret_handle) { acpi_status status; struct acpi_namespace_node *node; struct acpi_namespace_node *parent_node = NULL; struct acpi_namespace_node *child_node = NULL; /* Parameter validation */ if (type > ACPI_TYPE_EXTERNAL_MAX) { return (AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } /* If null handle, use the parent */ if (!child) { /* Start search at the beginning of the specified scope */ parent_node = acpi_ns_validate_handle(parent); if (!parent_node) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } } else { /* Non-null handle, ignore the parent */ /* Convert and validate the handle */ child_node = acpi_ns_validate_handle(child); if (!child_node) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } } /* Internal function does the real work */ node = acpi_ns_get_next_node_typed(type, parent_node, child_node); if (!node) { status = AE_NOT_FOUND; goto unlock_and_exit; } if (ret_handle) { *ret_handle = ACPI_CAST_PTR(acpi_handle, node); } unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status); } ACPI_EXPORT_SYMBOL(acpi_get_next_object)
linux-master
drivers/acpi/acpica/nsxfobj.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dsargs - Support for execution of dynamic arguments for static * objects (regions, fields, buffer fields, etc.) * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "amlcode.h" #include "acdispat.h" #include "acnamesp.h" #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dsargs") /* Local prototypes */ static acpi_status acpi_ds_execute_arguments(struct acpi_namespace_node *node, struct acpi_namespace_node *scope_node, u32 aml_length, u8 *aml_start); /******************************************************************************* * * FUNCTION: acpi_ds_execute_arguments * * PARAMETERS: node - Object NS node * scope_node - Parent NS node * aml_length - Length of executable AML * aml_start - Pointer to the AML * * RETURN: Status. * * DESCRIPTION: Late (deferred) execution of region or field arguments * ******************************************************************************/ static acpi_status acpi_ds_execute_arguments(struct acpi_namespace_node *node, struct acpi_namespace_node *scope_node, u32 aml_length, u8 *aml_start) { acpi_status status; union acpi_parse_object *op; struct acpi_walk_state *walk_state; ACPI_FUNCTION_TRACE_PTR(ds_execute_arguments, aml_start); /* Allocate a new parser op to be the root of the parsed tree */ op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP, aml_start); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Save the Node for use in acpi_ps_parse_aml */ op->common.node = scope_node; /* Create and initialize a new parser state */ walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL); if (!walk_state) { status = AE_NO_MEMORY; goto cleanup; } status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, aml_length, NULL, ACPI_IMODE_LOAD_PASS1); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup; } /* Mark this parse as a deferred opcode */ walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP; walk_state->deferred_node = node; /* Pass1: Parse the entire declaration */ status = acpi_ps_parse_aml(walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } /* Get and init the Op created above */ op->common.node = node; acpi_ps_delete_parse_tree(op); /* Evaluate the deferred arguments */ op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP, aml_start); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } op->common.node = scope_node; /* Create and initialize a new parser state */ walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL); if (!walk_state) { status = AE_NO_MEMORY; goto cleanup; } /* Execute the opcode and arguments */ status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start, aml_length, NULL, ACPI_IMODE_EXECUTE); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup; } /* Mark this execution as a deferred opcode */ walk_state->deferred_node = node; status = acpi_ps_parse_aml(walk_state); cleanup: acpi_ps_delete_parse_tree(op); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_get_buffer_field_arguments * * PARAMETERS: obj_desc - A valid buffer_field object * * RETURN: Status. * * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late * evaluation of these field attributes. * ******************************************************************************/ acpi_status acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc) { union acpi_operand_object *extra_desc; struct acpi_namespace_node *node; acpi_status status; ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments, obj_desc); if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { return_ACPI_STATUS(AE_OK); } /* Get the AML pointer (method object) and buffer_field node */ extra_desc = acpi_ns_get_secondary_object(obj_desc); node = obj_desc->buffer_field.node; ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_BUFFER_FIELD, node, NULL)); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n", acpi_ut_get_node_name(node))); /* Execute the AML code for the term_arg arguments */ status = acpi_ds_execute_arguments(node, node->parent, extra_desc->extra.aml_length, extra_desc->extra.aml_start); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_get_bank_field_arguments * * PARAMETERS: obj_desc - A valid bank_field object * * RETURN: Status. * * DESCRIPTION: Get bank_field bank_value. This implements the late * evaluation of these field attributes. * ******************************************************************************/ acpi_status acpi_ds_get_bank_field_arguments(union acpi_operand_object *obj_desc) { union acpi_operand_object *extra_desc; struct acpi_namespace_node *node; acpi_status status; ACPI_FUNCTION_TRACE_PTR(ds_get_bank_field_arguments, obj_desc); if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { return_ACPI_STATUS(AE_OK); } /* Get the AML pointer (method object) and bank_field node */ extra_desc = acpi_ns_get_secondary_object(obj_desc); node = obj_desc->bank_field.node; ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_LOCAL_BANK_FIELD, node, NULL)); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n", acpi_ut_get_node_name(node))); /* Execute the AML code for the term_arg arguments */ status = acpi_ds_execute_arguments(node, node->parent, extra_desc->extra.aml_length, extra_desc->extra.aml_start); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ut_add_address_range(obj_desc->region.space_id, obj_desc->region.address, obj_desc->region.length, node); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_get_buffer_arguments * * PARAMETERS: obj_desc - A valid Buffer object * * RETURN: Status. * * DESCRIPTION: Get Buffer length and initializer byte list. This implements * the late evaluation of these attributes. * ******************************************************************************/ acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc) { struct acpi_namespace_node *node; acpi_status status; ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc); if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { return_ACPI_STATUS(AE_OK); } /* Get the Buffer node */ node = obj_desc->buffer.node; if (!node) { ACPI_ERROR((AE_INFO, "No pointer back to namespace node in buffer object %p", obj_desc)); return_ACPI_STATUS(AE_AML_INTERNAL); } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n")); /* Execute the AML code for the term_arg arguments */ status = acpi_ds_execute_arguments(node, node, obj_desc->buffer.aml_length, obj_desc->buffer.aml_start); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_get_package_arguments * * PARAMETERS: obj_desc - A valid Package object * * RETURN: Status. * * DESCRIPTION: Get Package length and initializer byte list. This implements * the late evaluation of these attributes. * ******************************************************************************/ acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc) { struct acpi_namespace_node *node; acpi_status status; ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc); if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { return_ACPI_STATUS(AE_OK); } /* Get the Package node */ node = obj_desc->package.node; if (!node) { ACPI_ERROR((AE_INFO, "No pointer back to namespace node in package %p", obj_desc)); return_ACPI_STATUS(AE_AML_INTERNAL); } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Argument Init, AML Ptr: %p\n", obj_desc->package.aml_start)); /* Execute the AML code for the term_arg arguments */ status = acpi_ds_execute_arguments(node, node, obj_desc->package.aml_length, obj_desc->package.aml_start); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_get_region_arguments * * PARAMETERS: obj_desc - A valid region object * * RETURN: Status. * * DESCRIPTION: Get region address and length. This implements the late * evaluation of these region attributes. * ******************************************************************************/ acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc) { struct acpi_namespace_node *node; acpi_status status; union acpi_operand_object *extra_desc; ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments, obj_desc); if (obj_desc->region.flags & AOPOBJ_DATA_VALID) { return_ACPI_STATUS(AE_OK); } extra_desc = acpi_ns_get_secondary_object(obj_desc); if (!extra_desc) { return_ACPI_STATUS(AE_NOT_EXIST); } /* Get the Region node */ node = obj_desc->region.node; ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_REGION, node, NULL)); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n", acpi_ut_get_node_name(node), extra_desc->extra.aml_start)); /* Execute the argument AML */ status = acpi_ds_execute_arguments(node, extra_desc->extra.scope_node, extra_desc->extra.aml_length, extra_desc->extra.aml_start); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ut_add_address_range(obj_desc->region.space_id, obj_desc->region.address, obj_desc->region.length, node); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/dsargs.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dsdebug - Parser/Interpreter interface - debugging * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdispat.h" #include "acnamesp.h" #ifdef ACPI_DISASSEMBLER #include "acdisasm.h" #endif #include "acinterp.h" #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dsdebug") #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) /* Local prototypes */ static void acpi_ds_print_node_pathname(struct acpi_namespace_node *node, const char *message); /******************************************************************************* * * FUNCTION: acpi_ds_print_node_pathname * * PARAMETERS: node - Object * message - Prefix message * * DESCRIPTION: Print an object's full namespace pathname * Manages allocation/freeing of a pathname buffer * ******************************************************************************/ static void acpi_ds_print_node_pathname(struct acpi_namespace_node *node, const char *message) { struct acpi_buffer buffer; acpi_status status; ACPI_FUNCTION_TRACE(ds_print_node_pathname); if (!node) { ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "[NULL NAME]")); return_VOID; } /* Convert handle to full pathname and print it (with supplied message) */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_ns_handle_to_pathname(node, &buffer, TRUE); if (ACPI_SUCCESS(status)) { if (message) { ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "%s ", message)); } ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "[%s] (Node %p)", (char *)buffer.pointer, node)); ACPI_FREE(buffer.pointer); } return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ds_dump_method_stack * * PARAMETERS: status - Method execution status * walk_state - Current state of the parse tree walk * op - Executing parse op * * RETURN: None * * DESCRIPTION: Called when a method has been aborted because of an error. * Dumps the method execution stack. * ******************************************************************************/ void acpi_ds_dump_method_stack(acpi_status status, struct acpi_walk_state *walk_state, union acpi_parse_object *op) { union acpi_parse_object *next; struct acpi_thread_state *thread; struct acpi_walk_state *next_walk_state; struct acpi_namespace_node *previous_method = NULL; union acpi_operand_object *method_desc; ACPI_FUNCTION_TRACE(ds_dump_method_stack); /* Ignore control codes, they are not errors */ if (ACPI_CNTL_EXCEPTION(status)) { return_VOID; } /* We may be executing a deferred opcode */ if (walk_state->deferred_node) { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Executing subtree for Buffer/Package/Region\n")); return_VOID; } /* * If there is no Thread, we are not actually executing a method. * This can happen when the iASL compiler calls the interpreter * to perform constant folding. */ thread = walk_state->thread; if (!thread) { return_VOID; } /* Display exception and method name */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "\n**** Exception %s during execution of method ", acpi_format_exception(status))); acpi_ds_print_node_pathname(walk_state->method_node, NULL); /* Display stack of executing methods */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "\n\nMethod Execution Stack:\n")); next_walk_state = thread->walk_state_list; /* Walk list of linked walk states */ while (next_walk_state) { method_desc = next_walk_state->method_desc; if (method_desc) { acpi_ex_stop_trace_method((struct acpi_namespace_node *) method_desc->method.node, method_desc, walk_state); } ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, " Method [%4.4s] executing: ", acpi_ut_get_node_name(next_walk_state-> method_node))); /* First method is the currently executing method */ if (next_walk_state == walk_state) { if (op) { /* Display currently executing ASL statement */ next = op->common.next; op->common.next = NULL; #ifdef ACPI_DISASSEMBLER if (walk_state->method_node != acpi_gbl_root_node) { /* More verbose if not module-level code */ acpi_os_printf("Failed at "); acpi_dm_disassemble(next_walk_state, op, ACPI_UINT32_MAX); } #endif op->common.next = next; } } else { /* * This method has called another method * NOTE: the method call parse subtree is already deleted at * this point, so we cannot disassemble the method invocation. */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "Call to method ")); acpi_ds_print_node_pathname(previous_method, NULL); } previous_method = next_walk_state->method_node; next_walk_state = next_walk_state->next; ACPI_DEBUG_PRINT_RAW((ACPI_DB_DISPATCH, "\n")); } return_VOID; } #else void acpi_ds_dump_method_stack(acpi_status status, struct acpi_walk_state *walk_state, union acpi_parse_object *op) { return; } #endif
linux-master
drivers/acpi/acpica/dsdebug.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exsystem - Interface to OS services * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exsystem") /******************************************************************************* * * FUNCTION: acpi_ex_system_wait_semaphore * * PARAMETERS: semaphore - Semaphore to wait on * timeout - Max time to wait * * RETURN: Status * * DESCRIPTION: Implements a semaphore wait with a check to see if the * semaphore is available immediately. If it is not, the * interpreter is released before waiting. * ******************************************************************************/ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout) { acpi_status status; ACPI_FUNCTION_TRACE(ex_system_wait_semaphore); status = acpi_os_wait_semaphore(semaphore, 1, ACPI_DO_NOT_WAIT); if (ACPI_SUCCESS(status)) { return_ACPI_STATUS(status); } if (status == AE_TIME) { /* We must wait, so unlock the interpreter */ acpi_ex_exit_interpreter(); status = acpi_os_wait_semaphore(semaphore, 1, timeout); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "*** Thread awake after blocking, %s\n", acpi_format_exception(status))); /* Reacquire the interpreter */ acpi_ex_enter_interpreter(); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_system_wait_mutex * * PARAMETERS: mutex - Mutex to wait on * timeout - Max time to wait * * RETURN: Status * * DESCRIPTION: Implements a mutex wait with a check to see if the * mutex is available immediately. If it is not, the * interpreter is released before waiting. * ******************************************************************************/ acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout) { acpi_status status; ACPI_FUNCTION_TRACE(ex_system_wait_mutex); status = acpi_os_acquire_mutex(mutex, ACPI_DO_NOT_WAIT); if (ACPI_SUCCESS(status)) { return_ACPI_STATUS(status); } if (status == AE_TIME) { /* We must wait, so unlock the interpreter */ acpi_ex_exit_interpreter(); status = acpi_os_acquire_mutex(mutex, timeout); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "*** Thread awake after blocking, %s\n", acpi_format_exception(status))); /* Reacquire the interpreter */ acpi_ex_enter_interpreter(); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_system_do_stall * * PARAMETERS: how_long_us - The amount of time to stall, * in microseconds * * RETURN: Status * * DESCRIPTION: Suspend running thread for specified amount of time. * Note: ACPI specification requires that Stall() does not * relinquish the processor, and delays longer than 100 usec * should use Sleep() instead. We allow stalls up to 255 usec * for compatibility with other interpreters and existing BIOSs. * ******************************************************************************/ acpi_status acpi_ex_system_do_stall(u32 how_long_us) { acpi_status status = AE_OK; ACPI_FUNCTION_ENTRY(); if (how_long_us > 255) { /* * Longer than 255 microseconds, this is an error * * (ACPI specifies 100 usec as max, but this gives some slack in * order to support existing BIOSs) */ ACPI_ERROR((AE_INFO, "Time parameter is too large (%u)", how_long_us)); status = AE_AML_OPERAND_VALUE; } else { if (how_long_us > 100) { ACPI_WARNING((AE_INFO, "Time parameter %u us > 100 us violating ACPI spec, please fix the firmware.", how_long_us)); } acpi_os_stall(how_long_us); } return (status); } /******************************************************************************* * * FUNCTION: acpi_ex_system_do_sleep * * PARAMETERS: how_long_ms - The amount of time to sleep, * in milliseconds * * RETURN: None * * DESCRIPTION: Sleep the running thread for specified amount of time. * ******************************************************************************/ acpi_status acpi_ex_system_do_sleep(u64 how_long_ms) { ACPI_FUNCTION_ENTRY(); /* Since this thread will sleep, we must release the interpreter */ acpi_ex_exit_interpreter(); /* * For compatibility with other ACPI implementations and to prevent * accidental deep sleeps, limit the sleep time to something reasonable. */ if (how_long_ms > ACPI_MAX_SLEEP) { how_long_ms = ACPI_MAX_SLEEP; } acpi_os_sleep(how_long_ms); /* And now we must get the interpreter again */ acpi_ex_enter_interpreter(); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ex_system_signal_event * * PARAMETERS: obj_desc - The object descriptor for this op * * RETURN: Status * * DESCRIPTION: Provides an access point to perform synchronization operations * within the AML. * ******************************************************************************/ acpi_status acpi_ex_system_signal_event(union acpi_operand_object * obj_desc) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ex_system_signal_event); if (obj_desc) { status = acpi_os_signal_semaphore(obj_desc->event.os_semaphore, 1); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_system_wait_event * * PARAMETERS: time_desc - The 'time to delay' object descriptor * obj_desc - The object descriptor for this op * * RETURN: Status * * DESCRIPTION: Provides an access point to perform synchronization operations * within the AML. This operation is a request to wait for an * event. * ******************************************************************************/ acpi_status acpi_ex_system_wait_event(union acpi_operand_object *time_desc, union acpi_operand_object *obj_desc) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ex_system_wait_event); if (obj_desc) { status = acpi_ex_system_wait_semaphore(obj_desc->event.os_semaphore, (u16) time_desc->integer. value); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_system_reset_event * * PARAMETERS: obj_desc - The object descriptor for this op * * RETURN: Status * * DESCRIPTION: Reset an event to a known state. * ******************************************************************************/ acpi_status acpi_ex_system_reset_event(union acpi_operand_object *obj_desc) { acpi_status status = AE_OK; acpi_semaphore temp_semaphore; ACPI_FUNCTION_ENTRY(); /* * We are going to simply delete the existing semaphore and * create a new one! */ status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore); if (ACPI_SUCCESS(status)) { (void)acpi_os_delete_semaphore(obj_desc->event.os_semaphore); obj_desc->event.os_semaphore = temp_semaphore; } return (status); }
linux-master
drivers/acpi/acpica/exsystem.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: evglock - Global Lock support * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #include "acinterp.h" #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evglock") #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ /* Local prototypes */ static u32 acpi_ev_global_lock_handler(void *context); /******************************************************************************* * * FUNCTION: acpi_ev_init_global_lock_handler * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Install a handler for the global lock release event * ******************************************************************************/ acpi_status acpi_ev_init_global_lock_handler(void) { acpi_status status; ACPI_FUNCTION_TRACE(ev_init_global_lock_handler); /* If Hardware Reduced flag is set, there is no global lock */ if (acpi_gbl_reduced_hardware) { return_ACPI_STATUS(AE_OK); } /* Attempt installation of the global lock handler */ status = acpi_install_fixed_event_handler(ACPI_EVENT_GLOBAL, acpi_ev_global_lock_handler, NULL); /* * If the global lock does not exist on this platform, the attempt to * enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick). * Map to AE_OK, but mark global lock as not present. Any attempt to * actually use the global lock will be flagged with an error. */ acpi_gbl_global_lock_present = FALSE; if (status == AE_NO_HARDWARE_RESPONSE) { ACPI_ERROR((AE_INFO, "No response from Global Lock hardware, disabling lock")); return_ACPI_STATUS(AE_OK); } status = acpi_os_create_lock(&acpi_gbl_global_lock_pending_lock); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_gbl_global_lock_pending = FALSE; acpi_gbl_global_lock_present = TRUE; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_remove_global_lock_handler * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Remove the handler for the Global Lock * ******************************************************************************/ acpi_status acpi_ev_remove_global_lock_handler(void) { acpi_status status; ACPI_FUNCTION_TRACE(ev_remove_global_lock_handler); acpi_gbl_global_lock_present = FALSE; status = acpi_remove_fixed_event_handler(ACPI_EVENT_GLOBAL, acpi_ev_global_lock_handler); acpi_os_delete_lock(acpi_gbl_global_lock_pending_lock); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_global_lock_handler * * PARAMETERS: context - From thread interface, not used * * RETURN: ACPI_INTERRUPT_HANDLED * * DESCRIPTION: Invoked directly from the SCI handler when a global lock * release interrupt occurs. If there is actually a pending * request for the lock, signal the waiting thread. * ******************************************************************************/ static u32 acpi_ev_global_lock_handler(void *context) { acpi_status status; acpi_cpu_flags flags; flags = acpi_os_acquire_lock(acpi_gbl_global_lock_pending_lock); /* * If a request for the global lock is not actually pending, * we are done. This handles "spurious" global lock interrupts * which are possible (and have been seen) with bad BIOSs. */ if (!acpi_gbl_global_lock_pending) { goto cleanup_and_exit; } /* * Send a unit to the global lock semaphore. The actual acquisition * of the global lock will be performed by the waiting thread. */ status = acpi_os_signal_semaphore(acpi_gbl_global_lock_semaphore, 1); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Could not signal Global Lock semaphore")); } acpi_gbl_global_lock_pending = FALSE; cleanup_and_exit: acpi_os_release_lock(acpi_gbl_global_lock_pending_lock, flags); return (ACPI_INTERRUPT_HANDLED); } /****************************************************************************** * * FUNCTION: acpi_ev_acquire_global_lock * * PARAMETERS: timeout - Max time to wait for the lock, in millisec. * * RETURN: Status * * DESCRIPTION: Attempt to gain ownership of the Global Lock. * * MUTEX: Interpreter must be locked * * Note: The original implementation allowed multiple threads to "acquire" the * Global Lock, and the OS would hold the lock until the last thread had * released it. However, this could potentially starve the BIOS out of the * lock, especially in the case where there is a tight handshake between the * Embedded Controller driver and the BIOS. Therefore, this implementation * allows only one thread to acquire the HW Global Lock at a time, and makes * the global lock appear as a standard mutex on the OS side. * *****************************************************************************/ acpi_status acpi_ev_acquire_global_lock(u16 timeout) { acpi_cpu_flags flags; acpi_status status; u8 acquired = FALSE; ACPI_FUNCTION_TRACE(ev_acquire_global_lock); /* * Only one thread can acquire the GL at a time, the global_lock_mutex * enforces this. This interface releases the interpreter if we must wait. */ status = acpi_ex_system_wait_mutex(acpi_gbl_global_lock_mutex->mutex. os_mutex, timeout); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Update the global lock handle and check for wraparound. The handle is * only used for the external global lock interfaces, but it is updated * here to properly handle the case where a single thread may acquire the * lock via both the AML and the acpi_acquire_global_lock interfaces. The * handle is therefore updated on the first acquire from a given thread * regardless of where the acquisition request originated. */ acpi_gbl_global_lock_handle++; if (acpi_gbl_global_lock_handle == 0) { acpi_gbl_global_lock_handle = 1; } /* * Make sure that a global lock actually exists. If not, just * treat the lock as a standard mutex. */ if (!acpi_gbl_global_lock_present) { acpi_gbl_global_lock_acquired = TRUE; return_ACPI_STATUS(AE_OK); } flags = acpi_os_acquire_lock(acpi_gbl_global_lock_pending_lock); do { /* Attempt to acquire the actual hardware lock */ ACPI_ACQUIRE_GLOBAL_LOCK(acpi_gbl_FACS, acquired); if (acquired) { acpi_gbl_global_lock_acquired = TRUE; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Acquired hardware Global Lock\n")); break; } /* * Did not get the lock. The pending bit was set above, and * we must now wait until we receive the global lock * released interrupt. */ acpi_gbl_global_lock_pending = TRUE; acpi_os_release_lock(acpi_gbl_global_lock_pending_lock, flags); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Waiting for hardware Global Lock\n")); /* * Wait for handshake with the global lock interrupt handler. * This interface releases the interpreter if we must wait. */ status = acpi_ex_system_wait_semaphore (acpi_gbl_global_lock_semaphore, ACPI_WAIT_FOREVER); flags = acpi_os_acquire_lock(acpi_gbl_global_lock_pending_lock); } while (ACPI_SUCCESS(status)); acpi_gbl_global_lock_pending = FALSE; acpi_os_release_lock(acpi_gbl_global_lock_pending_lock, flags); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_release_global_lock * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Releases ownership of the Global Lock. * ******************************************************************************/ acpi_status acpi_ev_release_global_lock(void) { u8 pending = FALSE; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ev_release_global_lock); /* Lock must be already acquired */ if (!acpi_gbl_global_lock_acquired) { ACPI_WARNING((AE_INFO, "Cannot release the ACPI Global Lock, it has not been acquired")); return_ACPI_STATUS(AE_NOT_ACQUIRED); } if (acpi_gbl_global_lock_present) { /* Allow any thread to release the lock */ ACPI_RELEASE_GLOBAL_LOCK(acpi_gbl_FACS, pending); /* * If the pending bit was set, we must write GBL_RLS to the control * register */ if (pending) { status = acpi_write_bit_register (ACPI_BITREG_GLOBAL_LOCK_RELEASE, ACPI_ENABLE_EVENT); } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Released hardware Global Lock\n")); } acpi_gbl_global_lock_acquired = FALSE; /* Release the local GL mutex */ acpi_os_release_mutex(acpi_gbl_global_lock_mutex->mutex.os_mutex); return_ACPI_STATUS(status); } #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/evglock.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: dbtest - Various debug-related tests * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdebug.h" #include "acnamesp.h" #include "acpredef.h" #include "acinterp.h" #define _COMPONENT ACPI_CA_DEBUGGER ACPI_MODULE_NAME("dbtest") /* Local prototypes */ static void acpi_db_test_all_objects(void); static acpi_status acpi_db_test_one_object(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length); static acpi_status acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length); static acpi_status acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length); static acpi_status acpi_db_test_package_type(struct acpi_namespace_node *node); static acpi_status acpi_db_test_field_unit_type(union acpi_operand_object *obj_desc); static acpi_status acpi_db_read_from_object(struct acpi_namespace_node *node, acpi_object_type expected_type, union acpi_object **value); static acpi_status acpi_db_write_to_object(struct acpi_namespace_node *node, union acpi_object *value); static void acpi_db_evaluate_all_predefined_names(char *count_arg); static acpi_status acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); /* * Test subcommands */ static struct acpi_db_argument_info acpi_db_test_types[] = { {"OBJECTS"}, {"PREDEFINED"}, {NULL} /* Must be null terminated */ }; #define CMD_TEST_OBJECTS 0 #define CMD_TEST_PREDEFINED 1 #define BUFFER_FILL_VALUE 0xFF /* * Support for the special debugger read/write control methods. * These methods are installed into the current namespace and are * used to read and write the various namespace objects. The point * is to force the AML interpreter do all of the work. */ #define ACPI_DB_READ_METHOD "\\_T98" #define ACPI_DB_WRITE_METHOD "\\_T99" static acpi_handle read_handle = NULL; static acpi_handle write_handle = NULL; /* ASL Definitions of the debugger read/write control methods. AML below. */ #if 0 definition_block("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001) { method(_T98, 1, not_serialized) { /* Read */ return (de_ref_of(arg0)) } } definition_block("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001) { method(_T99, 2, not_serialized) { /* Write */ store(arg1, arg0) } } #endif static unsigned char read_method_code[] = { 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */ 0x02, 0xC9, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */ 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */ 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */ 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */ 0x39, 0x38, 0x01, 0xA4, 0x83, 0x68 /* 00000028 "98...h" */ }; static unsigned char write_method_code[] = { 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */ 0x02, 0x15, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */ 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */ 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */ 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */ 0x39, 0x39, 0x02, 0x70, 0x69, 0x68 /* 00000028 "99.pih" */ }; /******************************************************************************* * * FUNCTION: acpi_db_execute_test * * PARAMETERS: type_arg - Subcommand * * RETURN: None * * DESCRIPTION: Execute various debug tests. * * Note: Code is prepared for future expansion of the TEST command. * ******************************************************************************/ void acpi_db_execute_test(char *type_arg) { u32 temp; acpi_ut_strupr(type_arg); temp = acpi_db_match_argument(type_arg, acpi_db_test_types); if (temp == ACPI_TYPE_NOT_FOUND) { acpi_os_printf("Invalid or unsupported argument\n"); return; } switch (temp) { case CMD_TEST_OBJECTS: acpi_db_test_all_objects(); break; case CMD_TEST_PREDEFINED: acpi_db_evaluate_all_predefined_names(NULL); break; default: break; } } /******************************************************************************* * * FUNCTION: acpi_db_test_all_objects * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the * namespace by reading/writing/comparing all data objects such * as integers, strings, buffers, fields, buffer fields, etc. * ******************************************************************************/ static void acpi_db_test_all_objects(void) { acpi_status status; /* Install the debugger read-object control method if necessary */ if (!read_handle) { status = acpi_install_method(read_method_code); if (ACPI_FAILURE(status)) { acpi_os_printf ("%s, Could not install debugger read method\n", acpi_format_exception(status)); return; } status = acpi_get_handle(NULL, ACPI_DB_READ_METHOD, &read_handle); if (ACPI_FAILURE(status)) { acpi_os_printf ("Could not obtain handle for debug method %s\n", ACPI_DB_READ_METHOD); return; } } /* Install the debugger write-object control method if necessary */ if (!write_handle) { status = acpi_install_method(write_method_code); if (ACPI_FAILURE(status)) { acpi_os_printf ("%s, Could not install debugger write method\n", acpi_format_exception(status)); return; } status = acpi_get_handle(NULL, ACPI_DB_WRITE_METHOD, &write_handle); if (ACPI_FAILURE(status)) { acpi_os_printf ("Could not obtain handle for debug method %s\n", ACPI_DB_WRITE_METHOD); return; } } /* Walk the entire namespace, testing each supported named data object */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_test_one_object, NULL, NULL, NULL); } /******************************************************************************* * * FUNCTION: acpi_db_test_one_object * * PARAMETERS: acpi_walk_callback * * RETURN: Status * * DESCRIPTION: Test one namespace object. Supported types are Integer, * String, Buffer, Package, buffer_field, and field_unit. * All other object types are simply ignored. * ******************************************************************************/ static acpi_status acpi_db_test_one_object(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_namespace_node *node; union acpi_operand_object *obj_desc; acpi_object_type local_type; u32 bit_length = 0; u32 byte_length = 0; acpi_status status = AE_OK; node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); obj_desc = node->object; /* * For the supported types, get the actual bit length or * byte length. Map the type to one of Integer/String/Buffer. */ switch (node->type) { case ACPI_TYPE_INTEGER: /* Integer width is either 32 or 64 */ local_type = ACPI_TYPE_INTEGER; bit_length = acpi_gbl_integer_bit_width; break; case ACPI_TYPE_STRING: local_type = ACPI_TYPE_STRING; byte_length = obj_desc->string.length; break; case ACPI_TYPE_BUFFER: local_type = ACPI_TYPE_BUFFER; byte_length = obj_desc->buffer.length; bit_length = byte_length * 8; break; case ACPI_TYPE_PACKAGE: local_type = ACPI_TYPE_PACKAGE; break; case ACPI_TYPE_FIELD_UNIT: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: local_type = ACPI_TYPE_FIELD_UNIT; break; case ACPI_TYPE_BUFFER_FIELD: /* * The returned object will be a Buffer if the field length * is larger than the size of an Integer (32 or 64 bits * depending on the DSDT version). */ local_type = ACPI_TYPE_INTEGER; if (obj_desc) { bit_length = obj_desc->common_field.bit_length; byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length); if (bit_length > acpi_gbl_integer_bit_width) { local_type = ACPI_TYPE_BUFFER; } } break; default: /* Ignore all non-data types - Methods, Devices, Scopes, etc. */ return (AE_OK); } /* Emit the common prefix: Type:Name */ acpi_os_printf("%14s: %4.4s", acpi_ut_get_type_name(node->type), node->name.ascii); if (!obj_desc) { acpi_os_printf(" No attached sub-object, ignoring\n"); return (AE_OK); } /* At this point, we have resolved the object to one of the major types */ switch (local_type) { case ACPI_TYPE_INTEGER: status = acpi_db_test_integer_type(node, bit_length); break; case ACPI_TYPE_STRING: status = acpi_db_test_string_type(node, byte_length); break; case ACPI_TYPE_BUFFER: status = acpi_db_test_buffer_type(node, bit_length); break; case ACPI_TYPE_PACKAGE: status = acpi_db_test_package_type(node); break; case ACPI_TYPE_FIELD_UNIT: status = acpi_db_test_field_unit_type(obj_desc); break; default: acpi_os_printf(" Ignoring, type not implemented (%2.2X)", local_type); break; } /* Exit on error, but don't abort the namespace walk */ if (ACPI_FAILURE(status)) { status = AE_OK; } acpi_os_printf("\n"); return (status); } /******************************************************************************* * * FUNCTION: acpi_db_test_integer_type * * PARAMETERS: node - Parent NS node for the object * bit_length - Actual length of the object. Used for * support of arbitrary length field_unit * and buffer_field objects. * * RETURN: Status * * DESCRIPTION: Test read/write for an Integer-valued object. Performs a * write/read/compare of an arbitrary new value, then performs * a write/read/compare of the original value. * ******************************************************************************/ static acpi_status acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length) { union acpi_object *temp1 = NULL; union acpi_object *temp2 = NULL; union acpi_object *temp3 = NULL; union acpi_object write_value; u64 value_to_write; acpi_status status; if (bit_length > 64) { acpi_os_printf(" Invalid length for an Integer: %u", bit_length); return (AE_OK); } /* Read the original value */ status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp1); if (ACPI_FAILURE(status)) { return (status); } acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " %8.8X%8.8X", bit_length, ACPI_ROUND_BITS_UP_TO_BYTES(bit_length), ACPI_FORMAT_UINT64(temp1->integer.value)); value_to_write = ACPI_UINT64_MAX >> (64 - bit_length); if (temp1->integer.value == value_to_write) { value_to_write = 0; } /* Write a new value */ write_value.type = ACPI_TYPE_INTEGER; write_value.integer.value = value_to_write; status = acpi_db_write_to_object(node, &write_value); if (ACPI_FAILURE(status)) { goto exit; } /* Ensure that we can read back the new value */ status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp2); if (ACPI_FAILURE(status)) { goto exit; } if (temp2->integer.value != value_to_write) { acpi_os_printf(" MISMATCH 2: %8.8X%8.8X, expecting %8.8X%8.8X", ACPI_FORMAT_UINT64(temp2->integer.value), ACPI_FORMAT_UINT64(value_to_write)); } /* Write back the original value */ write_value.integer.value = temp1->integer.value; status = acpi_db_write_to_object(node, &write_value); if (ACPI_FAILURE(status)) { goto exit; } /* Ensure that we can read back the original value */ status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp3); if (ACPI_FAILURE(status)) { goto exit; } if (temp3->integer.value != temp1->integer.value) { acpi_os_printf(" MISMATCH 3: %8.8X%8.8X, expecting %8.8X%8.8X", ACPI_FORMAT_UINT64(temp3->integer.value), ACPI_FORMAT_UINT64(temp1->integer.value)); } exit: if (temp1) { acpi_os_free(temp1); } if (temp2) { acpi_os_free(temp2); } if (temp3) { acpi_os_free(temp3); } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_test_buffer_type * * PARAMETERS: node - Parent NS node for the object * bit_length - Actual length of the object. * * RETURN: Status * * DESCRIPTION: Test read/write for an Buffer-valued object. Performs a * write/read/compare of an arbitrary new value, then performs * a write/read/compare of the original value. * ******************************************************************************/ static acpi_status acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length) { union acpi_object *temp1 = NULL; union acpi_object *temp2 = NULL; union acpi_object *temp3 = NULL; u8 *buffer; union acpi_object write_value; acpi_status status; u32 byte_length; u32 i; u8 extra_bits; byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length); if (byte_length == 0) { acpi_os_printf(" Ignoring zero length buffer"); return (AE_OK); } /* Allocate a local buffer */ buffer = ACPI_ALLOCATE_ZEROED(byte_length); if (!buffer) { return (AE_NO_MEMORY); } /* Read the original value */ status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp1); if (ACPI_FAILURE(status)) { goto exit; } /* Emit a few bytes of the buffer */ acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT, bit_length, temp1->buffer.length); for (i = 0; ((i < 8) && (i < byte_length)); i++) { acpi_os_printf(" %2.2X", temp1->buffer.pointer[i]); } acpi_os_printf("... "); /* * Write a new value. * * Handle possible extra bits at the end of the buffer. Can * happen for field_units larger than an integer, but the bit * count is not an integral number of bytes. Zero out the * unused bits. */ memset(buffer, BUFFER_FILL_VALUE, byte_length); extra_bits = bit_length % 8; if (extra_bits) { buffer[byte_length - 1] = ACPI_MASK_BITS_ABOVE(extra_bits); } write_value.type = ACPI_TYPE_BUFFER; write_value.buffer.length = byte_length; write_value.buffer.pointer = buffer; status = acpi_db_write_to_object(node, &write_value); if (ACPI_FAILURE(status)) { goto exit; } /* Ensure that we can read back the new value */ status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp2); if (ACPI_FAILURE(status)) { goto exit; } if (memcmp(temp2->buffer.pointer, buffer, byte_length)) { acpi_os_printf(" MISMATCH 2: New buffer value"); } /* Write back the original value */ write_value.buffer.length = byte_length; write_value.buffer.pointer = temp1->buffer.pointer; status = acpi_db_write_to_object(node, &write_value); if (ACPI_FAILURE(status)) { goto exit; } /* Ensure that we can read back the original value */ status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp3); if (ACPI_FAILURE(status)) { goto exit; } if (memcmp(temp1->buffer.pointer, temp3->buffer.pointer, byte_length)) { acpi_os_printf(" MISMATCH 3: While restoring original buffer"); } exit: ACPI_FREE(buffer); if (temp1) { acpi_os_free(temp1); } if (temp2) { acpi_os_free(temp2); } if (temp3) { acpi_os_free(temp3); } return (status); } /******************************************************************************* * * FUNCTION: acpi_db_test_string_type * * PARAMETERS: node - Parent NS node for the object * byte_length - Actual length of the object. * * RETURN: Status * * DESCRIPTION: Test read/write for an String-valued object. Performs a * write/read/compare of an arbitrary new value, then performs * a write/read/compare of the original value. * ******************************************************************************/ static acpi_status acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length) { union acpi_object *temp1 = NULL; union acpi_object *temp2 = NULL; union acpi_object *temp3 = NULL; char *value_to_write = "Test String from AML Debugger"; union acpi_object write_value; acpi_status status; /* Read the original value */ status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp1); if (ACPI_FAILURE(status)) { return (status); } acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " \"%s\"", (temp1->string.length * 8), temp1->string.length, temp1->string.pointer); /* Write a new value */ write_value.type = ACPI_TYPE_STRING; write_value.string.length = strlen(value_to_write); write_value.string.pointer = value_to_write; status = acpi_db_write_to_object(node, &write_value); if (ACPI_FAILURE(status)) { goto exit; } /* Ensure that we can read back the new value */ status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp2); if (ACPI_FAILURE(status)) { goto exit; } if (strcmp(temp2->string.pointer, value_to_write)) { acpi_os_printf(" MISMATCH 2: %s, expecting %s", temp2->string.pointer, value_to_write); } /* Write back the original value */ write_value.string.length = strlen(temp1->string.pointer); write_value.string.pointer = temp1->string.pointer; status = acpi_db_write_to_object(node, &write_value); if (ACPI_FAILURE(status)) { goto exit; } /* Ensure that we can read back the original value */ status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp3); if (ACPI_FAILURE(status)) { goto exit; } if (strcmp(temp1->string.pointer, temp3->string.pointer)) { acpi_os_printf(" MISMATCH 3: %s, expecting %s", temp3->string.pointer, temp1->string.pointer); } exit: if (temp1) { acpi_os_free(temp1); } if (temp2) { acpi_os_free(temp2); } if (temp3) { acpi_os_free(temp3); } return (status); } /******************************************************************************* * * FUNCTION: acpi_db_test_package_type * * PARAMETERS: node - Parent NS node for the object * * RETURN: Status * * DESCRIPTION: Test read for a Package object. * ******************************************************************************/ static acpi_status acpi_db_test_package_type(struct acpi_namespace_node *node) { union acpi_object *temp1 = NULL; acpi_status status; /* Read the original value */ status = acpi_db_read_from_object(node, ACPI_TYPE_PACKAGE, &temp1); if (ACPI_FAILURE(status)) { return (status); } acpi_os_printf(" %.2X Elements", temp1->package.count); acpi_os_free(temp1); return (status); } /******************************************************************************* * * FUNCTION: acpi_db_test_field_unit_type * * PARAMETERS: obj_desc - A field unit object * * RETURN: Status * * DESCRIPTION: Test read/write on a named field unit. * ******************************************************************************/ static acpi_status acpi_db_test_field_unit_type(union acpi_operand_object *obj_desc) { union acpi_operand_object *region_obj; u32 bit_length = 0; u32 byte_length = 0; acpi_status status = AE_OK; union acpi_operand_object *ret_buffer_desc; /* Supported spaces are memory/io/pci_config */ region_obj = obj_desc->field.region_obj; switch (region_obj->region.space_id) { case ACPI_ADR_SPACE_SYSTEM_MEMORY: case ACPI_ADR_SPACE_SYSTEM_IO: case ACPI_ADR_SPACE_PCI_CONFIG: /* Need the interpreter to execute */ acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); /* Exercise read-then-write */ status = acpi_ex_read_data_from_field(NULL, obj_desc, &ret_buffer_desc); if (status == AE_OK) { acpi_ex_write_data_to_field(ret_buffer_desc, obj_desc, NULL); acpi_ut_remove_reference(ret_buffer_desc); } acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); bit_length = obj_desc->common_field.bit_length; byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length); acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " [%s]", bit_length, byte_length, acpi_ut_get_region_name(region_obj->region. space_id)); return (status); default: acpi_os_printf (" %s address space is not supported in this command [%4.4s]", acpi_ut_get_region_name(region_obj->region.space_id), region_obj->region.node->name.ascii); return (AE_OK); } } /******************************************************************************* * * FUNCTION: acpi_db_read_from_object * * PARAMETERS: node - Parent NS node for the object * expected_type - Object type expected from the read * value - Where the value read is returned * * RETURN: Status * * DESCRIPTION: Performs a read from the specified object by invoking the * special debugger control method that reads the object. Thus, * the AML interpreter is doing all of the work, increasing the * validity of the test. * ******************************************************************************/ static acpi_status acpi_db_read_from_object(struct acpi_namespace_node *node, acpi_object_type expected_type, union acpi_object **value) { union acpi_object *ret_value; struct acpi_object_list param_objects; union acpi_object params[2]; struct acpi_buffer return_obj; acpi_status status; params[0].type = ACPI_TYPE_LOCAL_REFERENCE; params[0].reference.actual_type = node->type; params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node); param_objects.count = 1; param_objects.pointer = params; return_obj.length = ACPI_ALLOCATE_BUFFER; acpi_gbl_method_executing = TRUE; status = acpi_evaluate_object(read_handle, NULL, &param_objects, &return_obj); acpi_gbl_method_executing = FALSE; if (ACPI_FAILURE(status)) { acpi_os_printf("Could not read from object, %s", acpi_format_exception(status)); return (status); } ret_value = (union acpi_object *)return_obj.pointer; switch (ret_value->type) { case ACPI_TYPE_INTEGER: case ACPI_TYPE_BUFFER: case ACPI_TYPE_STRING: case ACPI_TYPE_PACKAGE: /* * Did we receive the type we wanted? Most important for the * Integer/Buffer case (when a field is larger than an Integer, * it should return a Buffer). */ if (ret_value->type != expected_type) { acpi_os_printf (" Type mismatch: Expected %s, Received %s", acpi_ut_get_type_name(expected_type), acpi_ut_get_type_name(ret_value->type)); acpi_os_free(return_obj.pointer); return (AE_TYPE); } *value = ret_value; break; default: acpi_os_printf(" Unsupported return object type, %s", acpi_ut_get_type_name(ret_value->type)); acpi_os_free(return_obj.pointer); return (AE_TYPE); } return (status); } /******************************************************************************* * * FUNCTION: acpi_db_write_to_object * * PARAMETERS: node - Parent NS node for the object * value - Value to be written * * RETURN: Status * * DESCRIPTION: Performs a write to the specified object by invoking the * special debugger control method that writes the object. Thus, * the AML interpreter is doing all of the work, increasing the * validity of the test. * ******************************************************************************/ static acpi_status acpi_db_write_to_object(struct acpi_namespace_node *node, union acpi_object *value) { struct acpi_object_list param_objects; union acpi_object params[2]; acpi_status status; params[0].type = ACPI_TYPE_LOCAL_REFERENCE; params[0].reference.actual_type = node->type; params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node); /* Copy the incoming user parameter */ memcpy(&params[1], value, sizeof(union acpi_object)); param_objects.count = 2; param_objects.pointer = params; acpi_gbl_method_executing = TRUE; status = acpi_evaluate_object(write_handle, NULL, &param_objects, NULL); acpi_gbl_method_executing = FALSE; if (ACPI_FAILURE(status)) { acpi_os_printf("Could not write to object, %s", acpi_format_exception(status)); } return (status); } /******************************************************************************* * * FUNCTION: acpi_db_evaluate_all_predefined_names * * PARAMETERS: count_arg - Max number of methods to execute * * RETURN: None * * DESCRIPTION: Namespace batch execution. Execute predefined names in the * namespace, up to the max count, if specified. * ******************************************************************************/ static void acpi_db_evaluate_all_predefined_names(char *count_arg) { struct acpi_db_execute_walk info; info.count = 0; info.max_count = ACPI_UINT32_MAX; if (count_arg) { info.max_count = strtoul(count_arg, NULL, 0); } /* Search all nodes in namespace */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_evaluate_one_predefined_name, NULL, (void *)&info, NULL); acpi_os_printf("Evaluated %u predefined names in the namespace\n", info.count); } /******************************************************************************* * * FUNCTION: acpi_db_evaluate_one_predefined_name * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Batch execution module. Currently only executes predefined * ACPI names. * ******************************************************************************/ static acpi_status acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; struct acpi_db_execute_walk *info = (struct acpi_db_execute_walk *)context; char *pathname; const union acpi_predefined_info *predefined; struct acpi_device_info *obj_info; struct acpi_object_list param_objects; union acpi_object params[ACPI_METHOD_NUM_ARGS]; union acpi_object *this_param; struct acpi_buffer return_obj; acpi_status status; u16 arg_type_list; u8 arg_count; u8 arg_type; u32 i; /* The name must be a predefined ACPI name */ predefined = acpi_ut_match_predefined_method(node->name.ascii); if (!predefined) { return (AE_OK); } if (node->type == ACPI_TYPE_LOCAL_SCOPE) { return (AE_OK); } pathname = acpi_ns_get_normalized_pathname(node, TRUE); if (!pathname) { return (AE_OK); } /* Get the object info for number of method parameters */ status = acpi_get_object_info(obj_handle, &obj_info); if (ACPI_FAILURE(status)) { ACPI_FREE(pathname); return (status); } param_objects.count = 0; param_objects.pointer = NULL; if (obj_info->type == ACPI_TYPE_METHOD) { /* Setup default parameters (with proper types) */ arg_type_list = predefined->info.argument_list; arg_count = METHOD_GET_ARG_COUNT(arg_type_list); /* * Setup the ACPI-required number of arguments, regardless of what * the actual method defines. If there is a difference, then the * method is wrong and a warning will be issued during execution. */ this_param = params; for (i = 0; i < arg_count; i++) { arg_type = METHOD_GET_NEXT_TYPE(arg_type_list); this_param->type = arg_type; switch (arg_type) { case ACPI_TYPE_INTEGER: this_param->integer.value = 1; break; case ACPI_TYPE_STRING: this_param->string.pointer = "This is the default argument string"; this_param->string.length = strlen(this_param->string.pointer); break; case ACPI_TYPE_BUFFER: this_param->buffer.pointer = (u8 *)params; /* just a garbage buffer */ this_param->buffer.length = 48; break; case ACPI_TYPE_PACKAGE: this_param->package.elements = NULL; this_param->package.count = 0; break; default: acpi_os_printf ("%s: Unsupported argument type: %u\n", pathname, arg_type); break; } this_param++; } param_objects.count = arg_count; param_objects.pointer = params; } ACPI_FREE(obj_info); return_obj.pointer = NULL; return_obj.length = ACPI_ALLOCATE_BUFFER; /* Do the actual method execution */ acpi_gbl_method_executing = TRUE; status = acpi_evaluate_object(node, NULL, &param_objects, &return_obj); acpi_os_printf("%-32s returned %s\n", pathname, acpi_format_exception(status)); acpi_gbl_method_executing = FALSE; ACPI_FREE(pathname); /* Ignore status from method execution */ status = AE_OK; /* Update count, check if we have executed enough methods */ info->count++; if (info->count >= info->max_count) { status = AE_CTRL_TERMINATE; } return (status); }
linux-master
drivers/acpi/acpica/dbtest.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: psargs - Parse AML opcode arguments * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "amlcode.h" #include "acnamesp.h" #include "acdispat.h" #include "acconvert.h" #define _COMPONENT ACPI_PARSER ACPI_MODULE_NAME("psargs") /* Local prototypes */ static u32 acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state); static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state *parser_state); /******************************************************************************* * * FUNCTION: acpi_ps_get_next_package_length * * PARAMETERS: parser_state - Current parser state object * * RETURN: Decoded package length. On completion, the AML pointer points * past the length byte or bytes. * * DESCRIPTION: Decode and return a package length field. * Note: Largest package length is 28 bits, from ACPI specification * ******************************************************************************/ static u32 acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state) { u8 *aml = parser_state->aml; u32 package_length = 0; u32 byte_count; u8 byte_zero_mask = 0x3F; /* Default [0:5] */ ACPI_FUNCTION_TRACE(ps_get_next_package_length); /* * Byte 0 bits [6:7] contain the number of additional bytes * used to encode the package length, either 0,1,2, or 3 */ byte_count = (aml[0] >> 6); parser_state->aml += ((acpi_size)byte_count + 1); /* Get bytes 3, 2, 1 as needed */ while (byte_count) { /* * Final bit positions for the package length bytes: * Byte3->[20:27] * Byte2->[12:19] * Byte1->[04:11] * Byte0->[00:03] */ package_length |= (aml[byte_count] << ((byte_count << 3) - 4)); byte_zero_mask = 0x0F; /* Use bits [0:3] of byte 0 */ byte_count--; } /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */ package_length |= (aml[0] & byte_zero_mask); return_UINT32(package_length); } /******************************************************************************* * * FUNCTION: acpi_ps_get_next_package_end * * PARAMETERS: parser_state - Current parser state object * * RETURN: Pointer to end-of-package +1 * * DESCRIPTION: Get next package length and return a pointer past the end of * the package. Consumes the package length field * ******************************************************************************/ u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state) { u8 *start = parser_state->aml; u32 package_length; ACPI_FUNCTION_TRACE(ps_get_next_package_end); /* Function below updates parser_state->Aml */ package_length = acpi_ps_get_next_package_length(parser_state); return_PTR(start + package_length); /* end of package */ } /******************************************************************************* * * FUNCTION: acpi_ps_get_next_namestring * * PARAMETERS: parser_state - Current parser state object * * RETURN: Pointer to the start of the name string (pointer points into * the AML. * * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name * prefix characters. Set parser state to point past the string. * (Name is consumed from the AML.) * ******************************************************************************/ char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state) { u8 *start = parser_state->aml; u8 *end = parser_state->aml; ACPI_FUNCTION_TRACE(ps_get_next_namestring); /* Point past any namestring prefix characters (backslash or carat) */ while (ACPI_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*end)) { end++; } /* Decode the path prefix character */ switch (*end) { case 0: /* null_name */ if (end == start) { start = NULL; } end++; break; case AML_DUAL_NAME_PREFIX: /* Two name segments */ end += 1 + (2 * ACPI_NAMESEG_SIZE); break; case AML_MULTI_NAME_PREFIX: /* Multiple name segments, 4 chars each, count in next byte */ end += 2 + (*(end + 1) * ACPI_NAMESEG_SIZE); break; default: /* Single name segment */ end += ACPI_NAMESEG_SIZE; break; } parser_state->aml = end; return_PTR((char *)start); } /******************************************************************************* * * FUNCTION: acpi_ps_get_next_namepath * * PARAMETERS: parser_state - Current parser state object * arg - Where the namepath will be stored * arg_count - If the namepath points to a control method * the method's argument is returned here. * possible_method_call - Whether the namepath can possibly be the * start of a method call * * RETURN: Status * * DESCRIPTION: Get next name (if method call, return # of required args). * Names are looked up in the internal namespace to determine * if the name represents a control method. If a method * is found, the number of arguments to the method is returned. * This information is critical for parsing to continue correctly. * ******************************************************************************/ acpi_status acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state, struct acpi_parse_state *parser_state, union acpi_parse_object *arg, u8 possible_method_call) { acpi_status status; char *path; union acpi_parse_object *name_op; union acpi_operand_object *method_desc; struct acpi_namespace_node *node; u8 *start = parser_state->aml; ACPI_FUNCTION_TRACE(ps_get_next_namepath); path = acpi_ps_get_next_namestring(parser_state); acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP); /* Null path case is allowed, just exit */ if (!path) { arg->common.value.name = path; return_ACPI_STATUS(AE_OK); } /* * Lookup the name in the internal namespace, starting with the current * scope. We don't want to add anything new to the namespace here, * however, so we use MODE_EXECUTE. * Allow searching of the parent tree, but don't open a new scope - * we just want to lookup the object (must be mode EXECUTE to perform * the upsearch) */ status = acpi_ns_lookup(walk_state->scope_info, path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &node); /* * If this name is a control method invocation, we must * setup the method call */ if (ACPI_SUCCESS(status) && possible_method_call && (node->type == ACPI_TYPE_METHOD)) { if ((GET_CURRENT_ARG_TYPE(walk_state->arg_types) == ARGP_SUPERNAME) || (GET_CURRENT_ARG_TYPE(walk_state->arg_types) == ARGP_TARGET)) { /* * acpi_ps_get_next_namestring has increased the AML pointer past * the method invocation namestring, so we need to restore the * saved AML pointer back to the original method invocation * namestring. */ walk_state->parser_state.aml = start; walk_state->arg_count = 1; acpi_ps_init_op(arg, AML_INT_METHODCALL_OP); } /* This name is actually a control method invocation */ method_desc = acpi_ns_get_attached_object(node); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Control Method invocation %4.4s - %p Desc %p Path=%p\n", node->name.ascii, node, method_desc, path)); name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, start); if (!name_op) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Change Arg into a METHOD CALL and attach name to it */ acpi_ps_init_op(arg, AML_INT_METHODCALL_OP); name_op->common.value.name = path; /* Point METHODCALL/NAME to the METHOD Node */ name_op->common.node = node; acpi_ps_append_arg(arg, name_op); if (!method_desc) { ACPI_ERROR((AE_INFO, "Control Method %p has no attached object", node)); return_ACPI_STATUS(AE_AML_INTERNAL); } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Control Method - %p Args %X\n", node, method_desc->method.param_count)); /* Get the number of arguments to expect */ walk_state->arg_count = method_desc->method.param_count; return_ACPI_STATUS(AE_OK); } /* * Special handling if the name was not found during the lookup - * some not_found cases are allowed */ if (status == AE_NOT_FOUND) { /* 1) not_found is ok during load pass 1/2 (allow forward references) */ if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) != ACPI_PARSE_EXECUTE) { status = AE_OK; } /* 2) not_found during a cond_ref_of(x) is ok by definition */ else if (walk_state->op->common.aml_opcode == AML_CONDITIONAL_REF_OF_OP) { status = AE_OK; } /* * 3) not_found while building a Package is ok at this point, we * may flag as an error later if slack mode is not enabled. * (Some ASL code depends on allowing this behavior) */ else if ((arg->common.parent) && ((arg->common.parent->common.aml_opcode == AML_PACKAGE_OP) || (arg->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP))) { status = AE_OK; } } /* Final exception check (may have been changed from code above) */ if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, path, status); if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) { /* Report a control method execution error */ status = acpi_ds_method_error(status, walk_state); } } /* Save the namepath */ arg->common.value.name = path; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ps_get_next_simple_arg * * PARAMETERS: parser_state - Current parser state object * arg_type - The argument type (AML_*_ARG) * arg - Where the argument is returned * * RETURN: None * * DESCRIPTION: Get the next simple argument (constant, string, or namestring) * ******************************************************************************/ void acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state, u32 arg_type, union acpi_parse_object *arg) { u32 length; u16 opcode; u8 *aml = parser_state->aml; ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type); switch (arg_type) { case ARGP_BYTEDATA: /* Get 1 byte from the AML stream */ opcode = AML_BYTE_OP; arg->common.value.integer = (u64) *aml; length = 1; break; case ARGP_WORDDATA: /* Get 2 bytes from the AML stream */ opcode = AML_WORD_OP; ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml); length = 2; break; case ARGP_DWORDDATA: /* Get 4 bytes from the AML stream */ opcode = AML_DWORD_OP; ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml); length = 4; break; case ARGP_QWORDDATA: /* Get 8 bytes from the AML stream */ opcode = AML_QWORD_OP; ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml); length = 8; break; case ARGP_CHARLIST: /* Get a pointer to the string, point past the string */ opcode = AML_STRING_OP; arg->common.value.string = ACPI_CAST_PTR(char, aml); /* Find the null terminator */ length = 0; while (aml[length]) { length++; } length++; break; case ARGP_NAME: case ARGP_NAMESTRING: acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP); arg->common.value.name = acpi_ps_get_next_namestring(parser_state); return_VOID; default: ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type)); return_VOID; } acpi_ps_init_op(arg, opcode); parser_state->aml += length; return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ps_get_next_field * * PARAMETERS: parser_state - Current parser state object * * RETURN: A newly allocated FIELD op * * DESCRIPTION: Get next field (named_field, reserved_field, or access_field) * ******************************************************************************/ static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state *parser_state) { u8 *aml; union acpi_parse_object *field; union acpi_parse_object *arg = NULL; u16 opcode; u32 name; u8 access_type; u8 access_attribute; u8 access_length; u32 pkg_length; u8 *pkg_end; u32 buffer_length; ACPI_FUNCTION_TRACE(ps_get_next_field); ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state); aml = parser_state->aml; /* Determine field type */ switch (ACPI_GET8(parser_state->aml)) { case AML_FIELD_OFFSET_OP: opcode = AML_INT_RESERVEDFIELD_OP; parser_state->aml++; break; case AML_FIELD_ACCESS_OP: opcode = AML_INT_ACCESSFIELD_OP; parser_state->aml++; break; case AML_FIELD_CONNECTION_OP: opcode = AML_INT_CONNECTION_OP; parser_state->aml++; break; case AML_FIELD_EXT_ACCESS_OP: opcode = AML_INT_EXTACCESSFIELD_OP; parser_state->aml++; break; default: opcode = AML_INT_NAMEDFIELD_OP; break; } /* Allocate a new field op */ field = acpi_ps_alloc_op(opcode, aml); if (!field) { return_PTR(NULL); } /* Decode the field type */ ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state); switch (opcode) { case AML_INT_NAMEDFIELD_OP: /* Get the 4-character name */ ACPI_MOVE_32_TO_32(&name, parser_state->aml); acpi_ps_set_name(field, name); parser_state->aml += ACPI_NAMESEG_SIZE; ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state); #ifdef ACPI_ASL_COMPILER /* * Because the package length isn't represented as a parse tree object, * take comments surrounding this and add to the previously created * parse node. */ if (field->common.inline_comment) { field->common.name_comment = field->common.inline_comment; } field->common.inline_comment = acpi_gbl_current_inline_comment; acpi_gbl_current_inline_comment = NULL; #endif /* Get the length which is encoded as a package length */ field->common.value.size = acpi_ps_get_next_package_length(parser_state); break; case AML_INT_RESERVEDFIELD_OP: /* Get the length which is encoded as a package length */ field->common.value.size = acpi_ps_get_next_package_length(parser_state); break; case AML_INT_ACCESSFIELD_OP: case AML_INT_EXTACCESSFIELD_OP: /* * Get access_type and access_attrib and merge into the field Op * access_type is first operand, access_attribute is second. stuff * these bytes into the node integer value for convenience. */ /* Get the two bytes (Type/Attribute) */ access_type = ACPI_GET8(parser_state->aml); parser_state->aml++; access_attribute = ACPI_GET8(parser_state->aml); parser_state->aml++; field->common.value.integer = (u8)access_type; field->common.value.integer |= (u16)(access_attribute << 8); /* This opcode has a third byte, access_length */ if (opcode == AML_INT_EXTACCESSFIELD_OP) { access_length = ACPI_GET8(parser_state->aml); parser_state->aml++; field->common.value.integer |= (u32)(access_length << 16); } break; case AML_INT_CONNECTION_OP: /* * Argument for Connection operator can be either a Buffer * (resource descriptor), or a name_string. */ aml = parser_state->aml; if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) { parser_state->aml++; ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state); pkg_end = parser_state->aml; pkg_length = acpi_ps_get_next_package_length(parser_state); pkg_end += pkg_length; ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state); if (parser_state->aml < pkg_end) { /* Non-empty list */ arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml); if (!arg) { acpi_ps_free_op(field); return_PTR(NULL); } /* Get the actual buffer length argument */ opcode = ACPI_GET8(parser_state->aml); parser_state->aml++; ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state); switch (opcode) { case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ buffer_length = ACPI_GET8(parser_state->aml); parser_state->aml += 1; break; case AML_WORD_OP: /* AML_WORDDATA_ARG */ buffer_length = ACPI_GET16(parser_state->aml); parser_state->aml += 2; break; case AML_DWORD_OP: /* AML_DWORDATA_ARG */ buffer_length = ACPI_GET32(parser_state->aml); parser_state->aml += 4; break; default: buffer_length = 0; break; } /* Fill in bytelist data */ ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state); arg->named.value.size = buffer_length; arg->named.data = parser_state->aml; } /* Skip to End of byte data */ parser_state->aml = pkg_end; } else { arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml); if (!arg) { acpi_ps_free_op(field); return_PTR(NULL); } /* Get the Namestring argument */ arg->common.value.name = acpi_ps_get_next_namestring(parser_state); } /* Link the buffer/namestring to parent (CONNECTION_OP) */ acpi_ps_append_arg(field, arg); break; default: /* Opcode was set in previous switch */ break; } return_PTR(field); } /******************************************************************************* * * FUNCTION: acpi_ps_get_next_arg * * PARAMETERS: walk_state - Current state * parser_state - Current parser state object * arg_type - The argument type (AML_*_ARG) * return_arg - Where the next arg is returned * * RETURN: Status, and an op object containing the next argument. * * DESCRIPTION: Get next argument (including complex list arguments that require * pushing the parser stack) * ******************************************************************************/ acpi_status acpi_ps_get_next_arg(struct acpi_walk_state *walk_state, struct acpi_parse_state *parser_state, u32 arg_type, union acpi_parse_object **return_arg) { union acpi_parse_object *arg = NULL; union acpi_parse_object *prev = NULL; union acpi_parse_object *field; u32 subop; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Expected argument type ARGP: %s (%2.2X)\n", acpi_ut_get_argument_type_name(arg_type), arg_type)); switch (arg_type) { case ARGP_BYTEDATA: case ARGP_WORDDATA: case ARGP_DWORDDATA: case ARGP_CHARLIST: case ARGP_NAME: case ARGP_NAMESTRING: /* Constants, strings, and namestrings are all the same size */ arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml); if (!arg) { return_ACPI_STATUS(AE_NO_MEMORY); } acpi_ps_get_next_simple_arg(parser_state, arg_type, arg); break; case ARGP_PKGLENGTH: /* Package length, nothing returned */ parser_state->pkg_end = acpi_ps_get_next_package_end(parser_state); break; case ARGP_FIELDLIST: if (parser_state->aml < parser_state->pkg_end) { /* Non-empty list */ while (parser_state->aml < parser_state->pkg_end) { field = acpi_ps_get_next_field(parser_state); if (!field) { return_ACPI_STATUS(AE_NO_MEMORY); } if (prev) { prev->common.next = field; } else { arg = field; } prev = field; } /* Skip to End of byte data */ parser_state->aml = parser_state->pkg_end; } break; case ARGP_BYTELIST: if (parser_state->aml < parser_state->pkg_end) { /* Non-empty list */ arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP, parser_state->aml); if (!arg) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Fill in bytelist data */ arg->common.value.size = (u32) ACPI_PTR_DIFF(parser_state->pkg_end, parser_state->aml); arg->named.data = parser_state->aml; /* Skip to End of byte data */ parser_state->aml = parser_state->pkg_end; } break; case ARGP_SIMPLENAME: case ARGP_NAME_OR_REF: ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** SimpleName/NameOrRef: %s (%2.2X)\n", acpi_ut_get_argument_type_name(arg_type), arg_type)); subop = acpi_ps_peek_opcode(parser_state); if (subop == 0 || acpi_ps_is_leading_char(subop) || ACPI_IS_ROOT_PREFIX(subop) || ACPI_IS_PARENT_PREFIX(subop)) { /* null_name or name_string */ arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, parser_state->aml); if (!arg) { return_ACPI_STATUS(AE_NO_MEMORY); } status = acpi_ps_get_next_namepath(walk_state, parser_state, arg, ACPI_NOT_METHOD_CALL); } else { /* Single complex argument, nothing returned */ walk_state->arg_count = 1; } break; case ARGP_TARGET: case ARGP_SUPERNAME: ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Target/Supername: %s (%2.2X)\n", acpi_ut_get_argument_type_name(arg_type), arg_type)); subop = acpi_ps_peek_opcode(parser_state); if (subop == 0 || acpi_ps_is_leading_char(subop) || ACPI_IS_ROOT_PREFIX(subop) || ACPI_IS_PARENT_PREFIX(subop)) { /* NULL target (zero). Convert to a NULL namepath */ arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, parser_state->aml); if (!arg) { return_ACPI_STATUS(AE_NO_MEMORY); } status = acpi_ps_get_next_namepath(walk_state, parser_state, arg, ACPI_POSSIBLE_METHOD_CALL); if (arg->common.aml_opcode == AML_INT_METHODCALL_OP) { /* Free method call op and corresponding namestring sub-ob */ acpi_ps_free_op(arg->common.value.arg); acpi_ps_free_op(arg); arg = NULL; walk_state->arg_count = 1; } } else { /* Single complex argument, nothing returned */ walk_state->arg_count = 1; } break; case ARGP_DATAOBJ: case ARGP_TERMARG: ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** TermArg/DataObj: %s (%2.2X)\n", acpi_ut_get_argument_type_name(arg_type), arg_type)); /* Single complex argument, nothing returned */ walk_state->arg_count = 1; break; case ARGP_DATAOBJLIST: case ARGP_TERMLIST: case ARGP_OBJLIST: if (parser_state->aml < parser_state->pkg_end) { /* Non-empty list of variable arguments, nothing returned */ walk_state->arg_count = ACPI_VAR_ARGS; } break; default: ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type)); status = AE_AML_OPERAND_TYPE; break; } *return_arg = arg; return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/psargs.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utdebug - Debug print/trace routines * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utdebug") #ifdef ACPI_DEBUG_OUTPUT static acpi_thread_id acpi_gbl_previous_thread_id = (acpi_thread_id) 0xFFFFFFFF; static const char *acpi_gbl_function_entry_prefix = "----Entry"; static const char *acpi_gbl_function_exit_prefix = "----Exit-"; /******************************************************************************* * * FUNCTION: acpi_ut_init_stack_ptr_trace * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Save the current CPU stack pointer at subsystem startup * ******************************************************************************/ void acpi_ut_init_stack_ptr_trace(void) { acpi_size current_sp; #pragma GCC diagnostic push #if defined(__GNUC__) && __GNUC__ >= 12 #pragma GCC diagnostic ignored "-Wdangling-pointer=" #endif acpi_gbl_entry_stack_pointer = &current_sp; #pragma GCC diagnostic pop } /******************************************************************************* * * FUNCTION: acpi_ut_track_stack_ptr * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Save the current CPU stack pointer * ******************************************************************************/ void acpi_ut_track_stack_ptr(void) { acpi_size current_sp; if (&current_sp < acpi_gbl_lowest_stack_pointer) { acpi_gbl_lowest_stack_pointer = &current_sp; } if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) { acpi_gbl_deepest_nesting = acpi_gbl_nesting_level; } } /******************************************************************************* * * FUNCTION: acpi_ut_trim_function_name * * PARAMETERS: function_name - Ascii string containing a procedure name * * RETURN: Updated pointer to the function name * * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present. * This allows compiler macros such as __func__ to be used * with no change to the debug output. * ******************************************************************************/ static const char *acpi_ut_trim_function_name(const char *function_name) { /* All Function names are longer than 4 chars, check is safe */ if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) { /* This is the case where the original source has not been modified */ return (function_name + 4); } if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) { /* This is the case where the source has been 'linuxized' */ return (function_name + 5); } return (function_name); } /******************************************************************************* * * FUNCTION: acpi_debug_print * * PARAMETERS: requested_debug_level - Requested debug print level * line_number - Caller's line number (for error output) * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * format - Printf format field * ... - Optional printf arguments * * RETURN: None * * DESCRIPTION: Print error message with prefix consisting of the module name, * line number, and component ID. * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_debug_print(u32 requested_debug_level, u32 line_number, const char *function_name, const char *module_name, u32 component_id, const char *format, ...) { acpi_thread_id thread_id; va_list args; #ifdef ACPI_APPLICATION int fill_count; #endif /* Check if debug output enabled */ if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) { return; } /* * Thread tracking and context switch notification */ thread_id = acpi_os_get_thread_id(); if (thread_id != acpi_gbl_previous_thread_id) { if (ACPI_LV_THREADS & acpi_dbg_level) { acpi_os_printf ("\n**** Context Switch from TID %u to TID %u ****\n\n", (u32)acpi_gbl_previous_thread_id, (u32)thread_id); } acpi_gbl_previous_thread_id = thread_id; acpi_gbl_nesting_level = 0; } /* * Display the module name, current line number, thread ID (if requested), * current procedure nesting level, and the current procedure name */ acpi_os_printf("%9s-%04d ", module_name, line_number); #ifdef ACPI_APPLICATION /* * For acpi_exec/iASL only, emit the thread ID and nesting level. * Note: nesting level is really only useful during a single-thread * execution. Otherwise, multiple threads will keep resetting the * level. */ if (ACPI_LV_THREADS & acpi_dbg_level) { acpi_os_printf("[%u] ", (u32)thread_id); } fill_count = 48 - acpi_gbl_nesting_level - strlen(acpi_ut_trim_function_name(function_name)); if (fill_count < 0) { fill_count = 0; } acpi_os_printf("[%02d] %*s", acpi_gbl_nesting_level, acpi_gbl_nesting_level + 1, " "); acpi_os_printf("%s%*s: ", acpi_ut_trim_function_name(function_name), fill_count, " "); #else acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name)); #endif va_start(args, format); acpi_os_vprintf(format, args); va_end(args); } ACPI_EXPORT_SYMBOL(acpi_debug_print) /******************************************************************************* * * FUNCTION: acpi_debug_print_raw * * PARAMETERS: requested_debug_level - Requested debug print level * line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * format - Printf format field * ... - Optional printf arguments * * RETURN: None * * DESCRIPTION: Print message with no headers. Has same interface as * debug_print so that the same macros can be used. * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_debug_print_raw(u32 requested_debug_level, u32 line_number, const char *function_name, const char *module_name, u32 component_id, const char *format, ...) { va_list args; /* Check if debug output enabled */ if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) { return; } va_start(args, format); acpi_os_vprintf(format, args); va_end(args); } ACPI_EXPORT_SYMBOL(acpi_debug_print_raw) /******************************************************************************* * * FUNCTION: acpi_ut_trace * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * * RETURN: None * * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level * ******************************************************************************/ void acpi_ut_trace(u32 line_number, const char *function_name, const char *module_name, u32 component_id) { acpi_gbl_nesting_level++; acpi_ut_track_stack_ptr(); /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s\n", acpi_gbl_function_entry_prefix); } } ACPI_EXPORT_SYMBOL(acpi_ut_trace) /******************************************************************************* * * FUNCTION: acpi_ut_trace_ptr * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * pointer - Pointer to display * * RETURN: None * * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level * ******************************************************************************/ void acpi_ut_trace_ptr(u32 line_number, const char *function_name, const char *module_name, u32 component_id, const void *pointer) { acpi_gbl_nesting_level++; acpi_ut_track_stack_ptr(); /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s %p\n", acpi_gbl_function_entry_prefix, pointer); } } /******************************************************************************* * * FUNCTION: acpi_ut_trace_str * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * string - Additional string to display * * RETURN: None * * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level * ******************************************************************************/ void acpi_ut_trace_str(u32 line_number, const char *function_name, const char *module_name, u32 component_id, const char *string) { acpi_gbl_nesting_level++; acpi_ut_track_stack_ptr(); /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s %s\n", acpi_gbl_function_entry_prefix, string); } } /******************************************************************************* * * FUNCTION: acpi_ut_trace_u32 * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * integer - Integer to display * * RETURN: None * * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level * ******************************************************************************/ void acpi_ut_trace_u32(u32 line_number, const char *function_name, const char *module_name, u32 component_id, u32 integer) { acpi_gbl_nesting_level++; acpi_ut_track_stack_ptr(); /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s %08X\n", acpi_gbl_function_entry_prefix, integer); } } /******************************************************************************* * * FUNCTION: acpi_ut_exit * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * * RETURN: None * * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level * ******************************************************************************/ void acpi_ut_exit(u32 line_number, const char *function_name, const char *module_name, u32 component_id) { /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s\n", acpi_gbl_function_exit_prefix); } if (acpi_gbl_nesting_level) { acpi_gbl_nesting_level--; } } ACPI_EXPORT_SYMBOL(acpi_ut_exit) /******************************************************************************* * * FUNCTION: acpi_ut_status_exit * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * status - Exit status code * * RETURN: None * * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level. Prints exit status also. * ******************************************************************************/ void acpi_ut_status_exit(u32 line_number, const char *function_name, const char *module_name, u32 component_id, acpi_status status) { /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { if (ACPI_SUCCESS(status)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s %s\n", acpi_gbl_function_exit_prefix, acpi_format_exception(status)); } else { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s ****Exception****: %s\n", acpi_gbl_function_exit_prefix, acpi_format_exception(status)); } } if (acpi_gbl_nesting_level) { acpi_gbl_nesting_level--; } } ACPI_EXPORT_SYMBOL(acpi_ut_status_exit) /******************************************************************************* * * FUNCTION: acpi_ut_value_exit * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * value - Value to be printed with exit msg * * RETURN: None * * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level. Prints exit value also. * ******************************************************************************/ void acpi_ut_value_exit(u32 line_number, const char *function_name, const char *module_name, u32 component_id, u64 value) { /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s %8.8X%8.8X\n", acpi_gbl_function_exit_prefix, ACPI_FORMAT_UINT64(value)); } if (acpi_gbl_nesting_level) { acpi_gbl_nesting_level--; } } ACPI_EXPORT_SYMBOL(acpi_ut_value_exit) /******************************************************************************* * * FUNCTION: acpi_ut_ptr_exit * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * ptr - Pointer to display * * RETURN: None * * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level. Prints exit value also. * ******************************************************************************/ void acpi_ut_ptr_exit(u32 line_number, const char *function_name, const char *module_name, u32 component_id, u8 *ptr) { /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s %p\n", acpi_gbl_function_exit_prefix, ptr); } if (acpi_gbl_nesting_level) { acpi_gbl_nesting_level--; } } /******************************************************************************* * * FUNCTION: acpi_ut_str_exit * * PARAMETERS: line_number - Caller's line number * function_name - Caller's procedure name * module_name - Caller's module name * component_id - Caller's component ID * string - String to display * * RETURN: None * * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is * set in debug_level. Prints exit value also. * ******************************************************************************/ void acpi_ut_str_exit(u32 line_number, const char *function_name, const char *module_name, u32 component_id, const char *string) { /* Check if enabled up-front for performance */ if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) { acpi_debug_print(ACPI_LV_FUNCTIONS, line_number, function_name, module_name, component_id, "%s %s\n", acpi_gbl_function_exit_prefix, string); } if (acpi_gbl_nesting_level) { acpi_gbl_nesting_level--; } } /******************************************************************************* * * FUNCTION: acpi_trace_point * * PARAMETERS: type - Trace event type * begin - TRUE if before execution * aml - Executed AML address * pathname - Object path * pointer - Pointer to the related object * * RETURN: None * * DESCRIPTION: Interpreter execution trace. * ******************************************************************************/ void acpi_trace_point(acpi_trace_event_type type, u8 begin, u8 *aml, char *pathname) { ACPI_FUNCTION_ENTRY(); acpi_ex_trace_point(type, begin, aml, pathname); #ifdef ACPI_USE_SYSTEM_TRACER acpi_os_trace_point(type, begin, aml, pathname); #endif } ACPI_EXPORT_SYMBOL(acpi_trace_point) #endif
linux-master
drivers/acpi/acpica/utdebug.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "actables.h" #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evxfevnt") #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ /******************************************************************************* * * FUNCTION: acpi_enable * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Transfers the system into ACPI mode. * ******************************************************************************/ acpi_status acpi_enable(void) { acpi_status status; int retry; ACPI_FUNCTION_TRACE(acpi_enable); /* ACPI tables must be present */ if (acpi_gbl_fadt_index == ACPI_INVALID_TABLE_INDEX) { return_ACPI_STATUS(AE_NO_ACPI_TABLES); } /* If the Hardware Reduced flag is set, machine is always in acpi mode */ if (acpi_gbl_reduced_hardware) { return_ACPI_STATUS(AE_OK); } /* Check current mode */ if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) { ACPI_DEBUG_PRINT((ACPI_DB_INIT, "System is already in ACPI mode\n")); return_ACPI_STATUS(AE_OK); } /* Transition to ACPI mode */ status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Could not transition to ACPI mode")); return_ACPI_STATUS(status); } /* Sanity check that transition succeeded */ for (retry = 0; retry < 30000; ++retry) { if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) { if (retry != 0) ACPI_WARNING((AE_INFO, "Platform took > %d00 usec to enter ACPI mode", retry)); return_ACPI_STATUS(AE_OK); } acpi_os_stall(100); /* 100 usec */ } ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode")); return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); } ACPI_EXPORT_SYMBOL(acpi_enable) /******************************************************************************* * * FUNCTION: acpi_disable * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode. * ******************************************************************************/ acpi_status acpi_disable(void) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(acpi_disable); /* If the Hardware Reduced flag is set, machine is always in acpi mode */ if (acpi_gbl_reduced_hardware) { return_ACPI_STATUS(AE_OK); } if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) { ACPI_DEBUG_PRINT((ACPI_DB_INIT, "System is already in legacy (non-ACPI) mode\n")); } else { /* Transition to LEGACY mode */ status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Could not exit ACPI mode to legacy mode")); return_ACPI_STATUS(status); } ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n")); } return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_disable) /******************************************************************************* * * FUNCTION: acpi_enable_event * * PARAMETERS: event - The fixed eventto be enabled * flags - Reserved * * RETURN: Status * * DESCRIPTION: Enable an ACPI event (fixed) * ******************************************************************************/ acpi_status acpi_enable_event(u32 event, u32 flags) { acpi_status status = AE_OK; u32 value; ACPI_FUNCTION_TRACE(acpi_enable_event); /* If Hardware Reduced flag is set, there are no fixed events */ if (acpi_gbl_reduced_hardware) { return_ACPI_STATUS(AE_OK); } /* Decode the Fixed Event */ if (event > ACPI_EVENT_MAX) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Enable the requested fixed event (by writing a one to the enable * register bit) */ status = acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. enable_register_id, ACPI_ENABLE_EVENT); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Make sure that the hardware responded */ status = acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. enable_register_id, &value); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (value != 1) { ACPI_ERROR((AE_INFO, "Could not enable %s event", acpi_ut_get_event_name(event))); return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); } return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_enable_event) /******************************************************************************* * * FUNCTION: acpi_disable_event * * PARAMETERS: event - The fixed event to be disabled * flags - Reserved * * RETURN: Status * * DESCRIPTION: Disable an ACPI event (fixed) * ******************************************************************************/ acpi_status acpi_disable_event(u32 event, u32 flags) { acpi_status status = AE_OK; u32 value; ACPI_FUNCTION_TRACE(acpi_disable_event); /* If Hardware Reduced flag is set, there are no fixed events */ if (acpi_gbl_reduced_hardware) { return_ACPI_STATUS(AE_OK); } /* Decode the Fixed Event */ if (event > ACPI_EVENT_MAX) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Disable the requested fixed event (by writing a zero to the enable * register bit) */ status = acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. enable_register_id, ACPI_DISABLE_EVENT); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. enable_register_id, &value); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (value != 0) { ACPI_ERROR((AE_INFO, "Could not disable %s events", acpi_ut_get_event_name(event))); return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); } return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_disable_event) /******************************************************************************* * * FUNCTION: acpi_clear_event * * PARAMETERS: event - The fixed event to be cleared * * RETURN: Status * * DESCRIPTION: Clear an ACPI event (fixed) * ******************************************************************************/ acpi_status acpi_clear_event(u32 event) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(acpi_clear_event); /* If Hardware Reduced flag is set, there are no fixed events */ if (acpi_gbl_reduced_hardware) { return_ACPI_STATUS(AE_OK); } /* Decode the Fixed Event */ if (event > ACPI_EVENT_MAX) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Clear the requested fixed event (By writing a one to the status * register bit) */ status = acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. status_register_id, ACPI_CLEAR_STATUS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_clear_event) /******************************************************************************* * * FUNCTION: acpi_get_event_status * * PARAMETERS: event - The fixed event * event_status - Where the current status of the event will * be returned * * RETURN: Status * * DESCRIPTION: Obtains and returns the current status of the event * ******************************************************************************/ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status) { acpi_status status; acpi_event_status local_event_status = 0; u32 in_byte; ACPI_FUNCTION_TRACE(acpi_get_event_status); if (!event_status) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Decode the Fixed Event */ if (event > ACPI_EVENT_MAX) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Fixed event currently can be dispatched? */ if (acpi_gbl_fixed_event_handlers[event].handler) { local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER; } /* Fixed event currently enabled? */ status = acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. enable_register_id, &in_byte); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (in_byte) { local_event_status |= (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET); } /* Fixed event currently active? */ status = acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. status_register_id, &in_byte); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (in_byte) { local_event_status |= ACPI_EVENT_FLAG_STATUS_SET; } (*event_status) = local_event_status; return_ACPI_STATUS(AE_OK); } ACPI_EXPORT_SYMBOL(acpi_get_event_status) #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/evxfevnt.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nsinit - namespace initialization * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acdispat.h" #include "acinterp.h" #include "acevents.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsinit") /* Local prototypes */ static acpi_status acpi_ns_init_one_object(acpi_handle obj_handle, u32 level, void *context, void **return_value); static acpi_status acpi_ns_init_one_device(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_ns_find_ini_methods(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); /******************************************************************************* * * FUNCTION: acpi_ns_initialize_objects * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Walk the entire namespace and perform any necessary * initialization on the objects found therein * ******************************************************************************/ acpi_status acpi_ns_initialize_objects(void) { acpi_status status; struct acpi_init_walk_info info; ACPI_FUNCTION_TRACE(ns_initialize_objects); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[Init] Completing Initialization of ACPI Objects\n")); ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "**** Starting initialization of namespace objects ****\n")); ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Final data object initialization: ")); /* Clear the info block */ memset(&info, 0, sizeof(struct acpi_init_walk_info)); /* Walk entire namespace from the supplied root */ /* * TBD: will become ACPI_TYPE_PACKAGE as this type object * is now the only one that supports deferred initialization * (forward references). */ status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_ns_init_one_object, NULL, &info, NULL); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); } ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Namespace contains %u (0x%X) objects\n", info.object_count, info.object_count)); ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Control Methods found\n%u Op Regions found\n", info.method_count, info.op_region_count)); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_initialize_devices * * PARAMETERS: None * * RETURN: acpi_status * * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices. * This means running _INI on all present devices. * * Note: We install PCI config space handler on region access, * not here. * ******************************************************************************/ acpi_status acpi_ns_initialize_devices(u32 flags) { acpi_status status = AE_OK; struct acpi_device_walk_info info; acpi_handle handle; ACPI_FUNCTION_TRACE(ns_initialize_devices); if (!(flags & ACPI_NO_DEVICE_INIT)) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[Init] Initializing ACPI Devices\n")); /* Init counters */ info.device_count = 0; info.num_STA = 0; info.num_INI = 0; ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Initializing Device/Processor/Thermal objects " "and executing _INI/_STA methods:\n")); /* Tree analysis: find all subtrees that contain _INI methods */ status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, FALSE, acpi_ns_find_ini_methods, NULL, &info, NULL); if (ACPI_FAILURE(status)) { goto error_exit; } /* Allocate the evaluation information block */ info.evaluate_info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); if (!info.evaluate_info) { status = AE_NO_MEMORY; goto error_exit; } /* * Execute the "global" _INI method that may appear at the root. * This support is provided for Windows compatibility (Vista+) and * is not part of the ACPI specification. */ info.evaluate_info->prefix_node = acpi_gbl_root_node; info.evaluate_info->relative_pathname = METHOD_NAME__INI; info.evaluate_info->parameters = NULL; info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE; status = acpi_ns_evaluate(info.evaluate_info); if (ACPI_SUCCESS(status)) { info.num_INI++; } /* * Execute \_SB._INI. * There appears to be a strict order requirement for \_SB._INI, * which should be evaluated before any _REG evaluations. */ status = acpi_get_handle(NULL, "\\_SB", &handle); if (ACPI_SUCCESS(status)) { memset(info.evaluate_info, 0, sizeof(struct acpi_evaluate_info)); info.evaluate_info->prefix_node = handle; info.evaluate_info->relative_pathname = METHOD_NAME__INI; info.evaluate_info->parameters = NULL; info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE; status = acpi_ns_evaluate(info.evaluate_info); if (ACPI_SUCCESS(status)) { info.num_INI++; } } } /* * Run all _REG methods * * Note: Any objects accessed by the _REG methods will be automatically * initialized, even if they contain executable AML (see the call to * acpi_ns_initialize_objects below). * * Note: According to the ACPI specification, we actually needn't execute * _REG for system_memory/system_io operation regions, but for PCI_Config * operation regions, it is required to evaluate _REG for those on a PCI * root bus that doesn't contain _BBN object. So this code is kept here * in order not to break things. */ if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[Init] Executing _REG OpRegion methods\n")); status = acpi_ev_initialize_op_regions(); if (ACPI_FAILURE(status)) { goto error_exit; } } if (!(flags & ACPI_NO_DEVICE_INIT)) { /* Walk namespace to execute all _INIs on present devices */ status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, FALSE, acpi_ns_init_one_device, NULL, &info, NULL); /* * Any _OSI requests should be completed by now. If the BIOS has * requested any Windows OSI strings, we will always truncate * I/O addresses to 16 bits -- for Windows compatibility. */ if (acpi_gbl_osi_data >= ACPI_OSI_WIN_2000) { acpi_gbl_truncate_io_addresses = TRUE; } ACPI_FREE(info.evaluate_info); if (ACPI_FAILURE(status)) { goto error_exit; } ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, " Executed %u _INI methods requiring %u _STA executions " "(examined %u objects)\n", info.num_INI, info.num_STA, info.device_count)); } return_ACPI_STATUS(status); error_exit: ACPI_EXCEPTION((AE_INFO, status, "During device initialization")); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ns_init_one_package * * PARAMETERS: obj_handle - Node * level - Current nesting level * context - Not used * return_value - Not used * * RETURN: Status * * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every package * within the namespace. Used during dynamic load of an SSDT. * ******************************************************************************/ acpi_status acpi_ns_init_one_package(acpi_handle obj_handle, u32 level, void *context, void **return_value) { acpi_status status; union acpi_operand_object *obj_desc; struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { return (AE_OK); } /* Exit if package is already initialized */ if (obj_desc->package.flags & AOPOBJ_DATA_VALID) { return (AE_OK); } status = acpi_ds_get_package_arguments(obj_desc); if (ACPI_FAILURE(status)) { return (AE_OK); } status = acpi_ut_walk_package_tree(obj_desc, NULL, acpi_ds_init_package_element, NULL); if (ACPI_FAILURE(status)) { return (AE_OK); } obj_desc->package.flags |= AOPOBJ_DATA_VALID; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_init_one_object * * PARAMETERS: obj_handle - Node * level - Current nesting level * context - Points to a init info struct * return_value - Not used * * RETURN: Status * * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object * within the namespace. * * Currently, the only objects that require initialization are: * 1) Methods * 2) Op Regions * ******************************************************************************/ static acpi_status acpi_ns_init_one_object(acpi_handle obj_handle, u32 level, void *context, void **return_value) { acpi_object_type type; acpi_status status = AE_OK; struct acpi_init_walk_info *info = (struct acpi_init_walk_info *)context; struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; union acpi_operand_object *obj_desc; ACPI_FUNCTION_NAME(ns_init_one_object); info->object_count++; /* And even then, we are only interested in a few object types */ type = acpi_ns_get_type(obj_handle); obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { return (AE_OK); } /* Increment counters for object types we are looking for */ switch (type) { case ACPI_TYPE_REGION: info->op_region_count++; break; case ACPI_TYPE_BUFFER_FIELD: info->field_count++; break; case ACPI_TYPE_LOCAL_BANK_FIELD: info->field_count++; break; case ACPI_TYPE_BUFFER: info->buffer_count++; break; case ACPI_TYPE_PACKAGE: info->package_count++; break; default: /* No init required, just exit now */ return (AE_OK); } /* If the object is already initialized, nothing else to do */ if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { return (AE_OK); } /* Must lock the interpreter before executing AML code */ acpi_ex_enter_interpreter(); /* * Only initialization of Package objects can be deferred, in order * to support forward references. */ switch (type) { case ACPI_TYPE_LOCAL_BANK_FIELD: /* TBD: bank_fields do not require deferred init, remove this code */ info->field_init++; status = acpi_ds_get_bank_field_arguments(obj_desc); break; case ACPI_TYPE_PACKAGE: /* Complete the initialization/resolution of the package object */ info->package_init++; status = acpi_ns_init_one_package(obj_handle, level, NULL, NULL); break; default: /* No other types should get here */ status = AE_TYPE; ACPI_EXCEPTION((AE_INFO, status, "Opcode is not deferred [%4.4s] (%s)", acpi_ut_get_node_name(node), acpi_ut_get_type_name(type))); break; } if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Could not execute arguments for [%4.4s] (%s)", acpi_ut_get_node_name(node), acpi_ut_get_type_name(type))); } /* * We ignore errors from above, and always return OK, since we don't want * to abort the walk on any single error. */ acpi_ex_exit_interpreter(); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_find_ini_methods * * PARAMETERS: acpi_walk_callback * * RETURN: acpi_status * * DESCRIPTION: Called during namespace walk. Finds objects named _INI under * device/processor/thermal objects, and marks the entire subtree * with a SUBTREE_HAS_INI flag. This flag is used during the * subsequent device initialization walk to avoid entire subtrees * that do not contain an _INI. * ******************************************************************************/ static acpi_status acpi_ns_find_ini_methods(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_device_walk_info *info = ACPI_CAST_PTR(struct acpi_device_walk_info, context); struct acpi_namespace_node *node; struct acpi_namespace_node *parent_node; /* Keep count of device/processor/thermal objects */ node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); if ((node->type == ACPI_TYPE_DEVICE) || (node->type == ACPI_TYPE_PROCESSOR) || (node->type == ACPI_TYPE_THERMAL)) { info->device_count++; return (AE_OK); } /* We are only looking for methods named _INI */ if (!ACPI_COMPARE_NAMESEG(node->name.ascii, METHOD_NAME__INI)) { return (AE_OK); } /* * The only _INI methods that we care about are those that are * present under Device, Processor, and Thermal objects. */ parent_node = node->parent; switch (parent_node->type) { case ACPI_TYPE_DEVICE: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: /* Mark parent and bubble up the INI present flag to the root */ while (parent_node) { parent_node->flags |= ANOBJ_SUBTREE_HAS_INI; parent_node = parent_node->parent; } break; default: break; } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_init_one_device * * PARAMETERS: acpi_walk_callback * * RETURN: acpi_status * * DESCRIPTION: This is called once per device soon after ACPI is enabled * to initialize each device. It determines if the device is * present, and if so, calls _INI. * ******************************************************************************/ static acpi_status acpi_ns_init_one_device(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_device_walk_info *walk_info = ACPI_CAST_PTR(struct acpi_device_walk_info, context); struct acpi_evaluate_info *info = walk_info->evaluate_info; u32 flags; acpi_status status; struct acpi_namespace_node *device_node; ACPI_FUNCTION_TRACE(ns_init_one_device); /* We are interested in Devices, Processors and thermal_zones only */ device_node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); if ((device_node->type != ACPI_TYPE_DEVICE) && (device_node->type != ACPI_TYPE_PROCESSOR) && (device_node->type != ACPI_TYPE_THERMAL)) { return_ACPI_STATUS(AE_OK); } /* * Because of an earlier namespace analysis, all subtrees that contain an * _INI method are tagged. * * If this device subtree does not contain any _INI methods, we * can exit now and stop traversing this entire subtree. */ if (!(device_node->flags & ANOBJ_SUBTREE_HAS_INI)) { return_ACPI_STATUS(AE_CTRL_DEPTH); } /* * Run _STA to determine if this device is present and functioning. We * must know this information for two important reasons (from ACPI spec): * * 1) We can only run _INI if the device is present. * 2) We must abort the device tree walk on this subtree if the device is * not present and is not functional (we will not examine the children) * * The _STA method is not required to be present under the device, we * assume the device is present if _STA does not exist. */ ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, device_node, METHOD_NAME__STA)); status = acpi_ut_execute_STA(device_node, &flags); if (ACPI_FAILURE(status)) { /* Ignore error and move on to next device */ return_ACPI_STATUS(AE_OK); } /* * Flags == -1 means that _STA was not found. In this case, we assume that * the device is both present and functional. * * From the ACPI spec, description of _STA: * * "If a device object (including the processor object) does not have an * _STA object, then OSPM assumes that all of the above bits are set (in * other words, the device is present, ..., and functioning)" */ if (flags != ACPI_UINT32_MAX) { walk_info->num_STA++; } /* * Examine the PRESENT and FUNCTIONING status bits * * Note: ACPI spec does not seem to specify behavior for the present but * not functioning case, so we assume functioning if present. */ if (!(flags & ACPI_STA_DEVICE_PRESENT)) { /* Device is not present, we must examine the Functioning bit */ if (flags & ACPI_STA_DEVICE_FUNCTIONING) { /* * Device is not present but is "functioning". In this case, * we will not run _INI, but we continue to examine the children * of this device. * * From the ACPI spec, description of _STA: (note - no mention * of whether to run _INI or not on the device in question) * * "_STA may return bit 0 clear (not present) with bit 3 set * (device is functional). This case is used to indicate a valid * device for which no device driver should be loaded (for example, * a bridge device.) Children of this device may be present and * valid. OSPM should continue enumeration below a device whose * _STA returns this bit combination" */ return_ACPI_STATUS(AE_OK); } else { /* * Device is not present and is not functioning. We must abort the * walk of this subtree immediately -- don't look at the children * of such a device. * * From the ACPI spec, description of _INI: * * "If the _STA method indicates that the device is not present, * OSPM will not run the _INI and will not examine the children * of the device for _INI methods" */ return_ACPI_STATUS(AE_CTRL_DEPTH); } } /* * The device is present or is assumed present if no _STA exists. * Run the _INI if it exists (not required to exist) * * Note: We know there is an _INI within this subtree, but it may not be * under this particular device, it may be lower in the branch. */ if (!ACPI_COMPARE_NAMESEG(device_node->name.ascii, "_SB_") || device_node->parent != acpi_gbl_root_node) { ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, device_node, METHOD_NAME__INI)); memset(info, 0, sizeof(struct acpi_evaluate_info)); info->prefix_node = device_node; info->relative_pathname = METHOD_NAME__INI; info->parameters = NULL; info->flags = ACPI_IGNORE_RETURN_VALUE; status = acpi_ns_evaluate(info); if (ACPI_SUCCESS(status)) { walk_info->num_INI++; } #ifdef ACPI_DEBUG_OUTPUT else if (status != AE_NOT_FOUND) { /* Ignore error and move on to next device */ char *scope_name = acpi_ns_get_normalized_pathname(device_node, TRUE); ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution", scope_name)); ACPI_FREE(scope_name); } #endif } /* Ignore errors from above */ status = AE_OK; /* * The _INI method has been run if present; call the Global Initialization * Handler for this device. */ if (acpi_gbl_init_handler) { status = acpi_gbl_init_handler(device_node, ACPI_INIT_DEVICE_INI); } return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/nsinit.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: nsaccess - Top-level functions for accessing ACPI namespace * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "amlcode.h" #include "acnamesp.h" #include "acdispat.h" #ifdef ACPI_ASL_COMPILER #include "acdisasm.h" #endif #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsaccess") /******************************************************************************* * * FUNCTION: acpi_ns_root_initialize * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Allocate and initialize the default root named objects * * MUTEX: Locks namespace for entire execution * ******************************************************************************/ acpi_status acpi_ns_root_initialize(void) { acpi_status status; const struct acpi_predefined_names *init_val = NULL; struct acpi_namespace_node *new_node; struct acpi_namespace_node *prev_node = NULL; union acpi_operand_object *obj_desc; acpi_string val = NULL; ACPI_FUNCTION_TRACE(ns_root_initialize); status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * The global root ptr is initially NULL, so a non-NULL value indicates * that acpi_ns_root_initialize() has already been called; just return. */ if (acpi_gbl_root_node) { status = AE_OK; goto unlock_and_exit; } /* * Tell the rest of the subsystem that the root is initialized * (This is OK because the namespace is locked) */ acpi_gbl_root_node = &acpi_gbl_root_node_struct; /* Enter the predefined names in the name table */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Entering predefined entries into namespace\n")); /* * Create the initial (default) namespace. * This namespace looks like something similar to this: * * ACPI Namespace (from Namespace Root): * 0 _GPE Scope 00203160 00 * 0 _PR_ Scope 002031D0 00 * 0 _SB_ Device 00203240 00 Notify Object: 0020ADD8 * 0 _SI_ Scope 002032B0 00 * 0 _TZ_ Device 00203320 00 * 0 _REV Integer 00203390 00 = 0000000000000002 * 0 _OS_ String 00203488 00 Len 14 "Microsoft Windows NT" * 0 _GL_ Mutex 00203580 00 Object 002035F0 * 0 _OSI Method 00203678 00 Args 1 Len 0000 Aml 00000000 */ for (init_val = acpi_gbl_pre_defined_names; init_val->name; init_val++) { status = AE_OK; /* _OSI is optional for now, will be permanent later */ if (!strcmp(init_val->name, "_OSI") && !acpi_gbl_create_osi_method) { continue; } /* * Create, init, and link the new predefined name * Note: No need to use acpi_ns_lookup here because all the * predefined names are at the root level. It is much easier to * just create and link the new node(s) here. */ new_node = acpi_ns_create_node(*ACPI_CAST_PTR(u32, init_val->name)); if (!new_node) { status = AE_NO_MEMORY; goto unlock_and_exit; } new_node->descriptor_type = ACPI_DESC_TYPE_NAMED; new_node->type = init_val->type; if (!prev_node) { acpi_gbl_root_node_struct.child = new_node; } else { prev_node->peer = new_node; } new_node->parent = &acpi_gbl_root_node_struct; prev_node = new_node; /* * Name entered successfully. If entry in pre_defined_names[] specifies * an initial value, create the initial value. */ if (init_val->val) { status = acpi_os_predefined_override(init_val, &val); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Could not override predefined %s", init_val->name)); } if (!val) { val = init_val->val; } /* * Entry requests an initial value, allocate a * descriptor for it. */ obj_desc = acpi_ut_create_internal_object(init_val->type); if (!obj_desc) { status = AE_NO_MEMORY; goto unlock_and_exit; } /* * Convert value string from table entry to * internal representation. Only types actually * used for initial values are implemented here. */ switch (init_val->type) { case ACPI_TYPE_METHOD: obj_desc->method.param_count = (u8) ACPI_TO_INTEGER(val); obj_desc->common.flags |= AOPOBJ_DATA_VALID; #if defined (ACPI_ASL_COMPILER) /* Save the parameter count for the iASL compiler */ new_node->value = obj_desc->method.param_count; #else /* Mark this as a very SPECIAL method (_OSI) */ obj_desc->method.info_flags = ACPI_METHOD_INTERNAL_ONLY; obj_desc->method.dispatch.implementation = acpi_ut_osi_implementation; #endif break; case ACPI_TYPE_INTEGER: obj_desc->integer.value = ACPI_TO_INTEGER(val); break; case ACPI_TYPE_STRING: /* Build an object around the static string */ obj_desc->string.length = (u32)strlen(val); obj_desc->string.pointer = val; obj_desc->common.flags |= AOPOBJ_STATIC_POINTER; break; case ACPI_TYPE_MUTEX: obj_desc->mutex.node = new_node; obj_desc->mutex.sync_level = (u8) (ACPI_TO_INTEGER(val) - 1); /* Create a mutex */ status = acpi_os_create_mutex(&obj_desc->mutex. os_mutex); if (ACPI_FAILURE(status)) { acpi_ut_remove_reference(obj_desc); goto unlock_and_exit; } /* Special case for ACPI Global Lock */ if (strcmp(init_val->name, "_GL_") == 0) { acpi_gbl_global_lock_mutex = obj_desc; /* Create additional counting semaphore for global lock */ status = acpi_os_create_semaphore(1, 0, &acpi_gbl_global_lock_semaphore); if (ACPI_FAILURE(status)) { acpi_ut_remove_reference (obj_desc); goto unlock_and_exit; } } break; default: ACPI_ERROR((AE_INFO, "Unsupported initial type value 0x%X", init_val->type)); acpi_ut_remove_reference(obj_desc); obj_desc = NULL; continue; } /* Store pointer to value descriptor in the Node */ status = acpi_ns_attach_object(new_node, obj_desc, obj_desc->common.type); /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); } } unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); /* Save a handle to "_GPE", it is always present */ if (ACPI_SUCCESS(status)) { status = acpi_ns_get_node(NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH, &acpi_gbl_fadt_gpe_device); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ns_lookup * * PARAMETERS: scope_info - Current scope info block * pathname - Search pathname, in internal format * (as represented in the AML stream) * type - Type associated with name * interpreter_mode - IMODE_LOAD_PASS2 => add name if not found * flags - Flags describing the search restrictions * walk_state - Current state of the walk * return_node - Where the Node is placed (if found * or created successfully) * * RETURN: Status * * DESCRIPTION: Find or enter the passed name in the name space. * Log an error if name not found in Exec mode. * * MUTEX: Assumes namespace is locked. * ******************************************************************************/ acpi_status acpi_ns_lookup(union acpi_generic_state *scope_info, char *pathname, acpi_object_type type, acpi_interpreter_mode interpreter_mode, u32 flags, struct acpi_walk_state *walk_state, struct acpi_namespace_node **return_node) { acpi_status status; char *path = pathname; char *external_path; struct acpi_namespace_node *prefix_node; struct acpi_namespace_node *current_node = NULL; struct acpi_namespace_node *this_node = NULL; u32 num_segments; u32 num_carats; acpi_name simple_name; acpi_object_type type_to_check_for; acpi_object_type this_search_type; u32 search_parent_flag = ACPI_NS_SEARCH_PARENT; u32 local_flags; acpi_interpreter_mode local_interpreter_mode; ACPI_FUNCTION_TRACE(ns_lookup); if (!return_node) { return_ACPI_STATUS(AE_BAD_PARAMETER); } local_flags = flags & ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_OVERRIDE_IF_FOUND | ACPI_NS_SEARCH_PARENT); *return_node = ACPI_ENTRY_NOT_FOUND; acpi_gbl_ns_lookup_count++; if (!acpi_gbl_root_node) { return_ACPI_STATUS(AE_NO_NAMESPACE); } /* Get the prefix scope. A null scope means use the root scope */ if ((!scope_info) || (!scope_info->scope.node)) { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Null scope prefix, using root node (%p)\n", acpi_gbl_root_node)); prefix_node = acpi_gbl_root_node; } else { prefix_node = scope_info->scope.node; if (ACPI_GET_DESCRIPTOR_TYPE(prefix_node) != ACPI_DESC_TYPE_NAMED) { ACPI_ERROR((AE_INFO, "%p is not a namespace node [%s]", prefix_node, acpi_ut_get_descriptor_name(prefix_node))); return_ACPI_STATUS(AE_AML_INTERNAL); } if (!(flags & ACPI_NS_PREFIX_IS_SCOPE)) { /* * This node might not be a actual "scope" node (such as a * Device/Method, etc.) It could be a Package or other object * node. Backup up the tree to find the containing scope node. */ while (!acpi_ns_opens_scope(prefix_node->type) && prefix_node->type != ACPI_TYPE_ANY) { prefix_node = prefix_node->parent; } } } /* Save type. TBD: may be no longer necessary */ type_to_check_for = type; /* * Begin examination of the actual pathname */ if (!pathname) { /* A Null name_path is allowed and refers to the root */ num_segments = 0; this_node = acpi_gbl_root_node; path = ""; ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Null Pathname (Zero segments), Flags=%X\n", flags)); } else { /* * Name pointer is valid (and must be in internal name format) * * Check for scope prefixes: * * As represented in the AML stream, a namepath consists of an * optional scope prefix followed by a name segment part. * * If present, the scope prefix is either a Root Prefix (in * which case the name is fully qualified), or one or more * Parent Prefixes (in which case the name's scope is relative * to the current scope). */ if (*path == (u8) AML_ROOT_PREFIX) { /* Pathname is fully qualified, start from the root */ this_node = acpi_gbl_root_node; search_parent_flag = ACPI_NS_NO_UPSEARCH; /* Point to name segment part */ path++; ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Path is absolute from root [%p]\n", this_node)); } else { /* Pathname is relative to current scope, start there */ ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Searching relative to prefix scope [%4.4s] (%p)\n", acpi_ut_get_node_name(prefix_node), prefix_node)); /* * Handle multiple Parent Prefixes (carat) by just getting * the parent node for each prefix instance. */ this_node = prefix_node; num_carats = 0; while (*path == (u8) AML_PARENT_PREFIX) { /* Name is fully qualified, no search rules apply */ search_parent_flag = ACPI_NS_NO_UPSEARCH; /* * Point past this prefix to the name segment * part or the next Parent Prefix */ path++; /* Backup to the parent node */ num_carats++; this_node = this_node->parent; if (!this_node) { /* * Current scope has no parent scope. Externalize * the internal path for error message. */ status = acpi_ns_externalize_name (ACPI_UINT32_MAX, pathname, NULL, &external_path); if (ACPI_SUCCESS(status)) { ACPI_ERROR((AE_INFO, "%s: Path has too many parent prefixes (^)", external_path)); ACPI_FREE(external_path); } return_ACPI_STATUS(AE_NOT_FOUND); } } if (search_parent_flag == ACPI_NS_NO_UPSEARCH) { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Search scope is [%4.4s], path has %u carat(s)\n", acpi_ut_get_node_name (this_node), num_carats)); } } /* * Determine the number of ACPI name segments in this pathname. * * The segment part consists of either: * - A Null name segment (0) * - A dual_name_prefix followed by two 4-byte name segments * - A multi_name_prefix followed by a byte indicating the * number of segments and the segments themselves. * - A single 4-byte name segment * * Examine the name prefix opcode, if any, to determine the number of * segments. */ switch (*path) { case 0: /* * Null name after a root or parent prefixes. We already * have the correct target node and there are no name segments. */ num_segments = 0; type = this_node->type; ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Prefix-only Pathname (Zero name segments), Flags=%X\n", flags)); break; case AML_DUAL_NAME_PREFIX: /* More than one name_seg, search rules do not apply */ search_parent_flag = ACPI_NS_NO_UPSEARCH; /* Two segments, point to first name segment */ num_segments = 2; path++; ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Dual Pathname (2 segments, Flags=%X)\n", flags)); break; case AML_MULTI_NAME_PREFIX: /* More than one name_seg, search rules do not apply */ search_parent_flag = ACPI_NS_NO_UPSEARCH; /* Extract segment count, point to first name segment */ path++; num_segments = (u32) (u8) * path; path++; ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Multi Pathname (%u Segments, Flags=%X)\n", num_segments, flags)); break; default: /* * Not a Null name, no Dual or Multi prefix, hence there is * only one name segment and Pathname is already pointing to it. */ num_segments = 1; ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Simple Pathname (1 segment, Flags=%X)\n", flags)); break; } ACPI_DEBUG_EXEC(acpi_ns_print_pathname(num_segments, path)); } /* * Search namespace for each segment of the name. Loop through and * verify (or add to the namespace) each name segment. * * The object type is significant only at the last name * segment. (We don't care about the types along the path, only * the type of the final target object.) */ this_search_type = ACPI_TYPE_ANY; current_node = this_node; while (num_segments && current_node) { num_segments--; if (!num_segments) { /* This is the last segment, enable typechecking */ this_search_type = type; /* * Only allow automatic parent search (search rules) if the caller * requested it AND we have a single, non-fully-qualified name_seg */ if ((search_parent_flag != ACPI_NS_NO_UPSEARCH) && (flags & ACPI_NS_SEARCH_PARENT)) { local_flags |= ACPI_NS_SEARCH_PARENT; } /* Set error flag according to caller */ if (flags & ACPI_NS_ERROR_IF_FOUND) { local_flags |= ACPI_NS_ERROR_IF_FOUND; } /* Set override flag according to caller */ if (flags & ACPI_NS_OVERRIDE_IF_FOUND) { local_flags |= ACPI_NS_OVERRIDE_IF_FOUND; } } /* Handle opcodes that create a new name_seg via a full name_path */ local_interpreter_mode = interpreter_mode; if ((flags & ACPI_NS_PREFIX_MUST_EXIST) && (num_segments > 0)) { /* Every element of the path must exist (except for the final name_seg) */ local_interpreter_mode = ACPI_IMODE_EXECUTE; } /* Extract one ACPI name from the front of the pathname */ ACPI_MOVE_32_TO_32(&simple_name, path); /* Try to find the single (4 character) ACPI name */ status = acpi_ns_search_and_enter(simple_name, walk_state, current_node, local_interpreter_mode, this_search_type, local_flags, &this_node); if (ACPI_FAILURE(status)) { if (status == AE_NOT_FOUND) { #if !defined ACPI_ASL_COMPILER /* Note: iASL reports this error by itself, not needed here */ if (flags & ACPI_NS_PREFIX_MUST_EXIST) { acpi_os_printf(ACPI_MSG_BIOS_ERROR "Object does not exist: %4.4s\n", (char *)&simple_name); } #endif /* Name not found in ACPI namespace */ ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Name [%4.4s] not found in scope [%4.4s] %p\n", (char *)&simple_name, (char *)&current_node->name, current_node)); } #ifdef ACPI_EXEC_APP if ((status == AE_ALREADY_EXISTS) && (this_node->flags & ANOBJ_NODE_EARLY_INIT)) { this_node->flags &= ~ANOBJ_NODE_EARLY_INIT; status = AE_OK; } #endif #ifdef ACPI_ASL_COMPILER /* * If this ACPI name already exists within the namespace as an * external declaration, then mark the external as a conflicting * declaration and proceed to process the current node as if it did * not exist in the namespace. If this node is not processed as * normal, then it could cause improper namespace resolution * by failing to open a new scope. */ if (acpi_gbl_disasm_flag && (status == AE_ALREADY_EXISTS) && ((this_node->flags & ANOBJ_IS_EXTERNAL) || (walk_state && walk_state->opcode == AML_EXTERNAL_OP))) { this_node->flags &= ~ANOBJ_IS_EXTERNAL; this_node->type = (u8)this_search_type; if (walk_state->opcode != AML_EXTERNAL_OP) { acpi_dm_mark_external_conflict (this_node); } break; } #endif *return_node = this_node; return_ACPI_STATUS(status); } /* More segments to follow? */ if (num_segments > 0) { /* * If we have an alias to an object that opens a scope (such as a * device or processor), we need to dereference the alias here so * that we can access any children of the original node (via the * remaining segments). */ if (this_node->type == ACPI_TYPE_LOCAL_ALIAS) { if (!this_node->object) { return_ACPI_STATUS(AE_NOT_EXIST); } if (acpi_ns_opens_scope (((struct acpi_namespace_node *) this_node->object)->type)) { this_node = (struct acpi_namespace_node *) this_node->object; } } } /* Special handling for the last segment (num_segments == 0) */ else { /* * Sanity typecheck of the target object: * * If 1) This is the last segment (num_segments == 0) * 2) And we are looking for a specific type * (Not checking for TYPE_ANY) * 3) Which is not an alias * 4) Which is not a local type (TYPE_SCOPE) * 5) And the type of target object is known (not TYPE_ANY) * 6) And target object does not match what we are looking for * * Then we have a type mismatch. Just warn and ignore it. */ if ((type_to_check_for != ACPI_TYPE_ANY) && (type_to_check_for != ACPI_TYPE_LOCAL_ALIAS) && (type_to_check_for != ACPI_TYPE_LOCAL_METHOD_ALIAS) && (type_to_check_for != ACPI_TYPE_LOCAL_SCOPE) && (this_node->type != ACPI_TYPE_ANY) && (this_node->type != type_to_check_for)) { /* Complain about a type mismatch */ ACPI_WARNING((AE_INFO, "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)", ACPI_CAST_PTR(char, &simple_name), acpi_ut_get_type_name(this_node-> type), acpi_ut_get_type_name (type_to_check_for))); } /* * If this is the last name segment and we are not looking for a * specific type, but the type of found object is known, use that * type to (later) see if it opens a scope. */ if (type == ACPI_TYPE_ANY) { type = this_node->type; } } /* Point to next name segment and make this node current */ path += ACPI_NAMESEG_SIZE; current_node = this_node; } /* Always check if we need to open a new scope */ if (!(flags & ACPI_NS_DONT_OPEN_SCOPE) && (walk_state)) { /* * If entry is a type which opens a scope, push the new scope on the * scope stack. */ if (acpi_ns_opens_scope(type)) { status = acpi_ds_scope_stack_push(this_node, type, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } } #ifdef ACPI_EXEC_APP if (flags & ACPI_NS_EARLY_INIT) { this_node->flags |= ANOBJ_NODE_EARLY_INIT; } #endif *return_node = this_node; return_ACPI_STATUS(AE_OK); }
linux-master
drivers/acpi/acpica/nsaccess.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nsparse - namespace interface to AML parser * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acparser.h" #include "acdispat.h" #include "actables.h" #include "acinterp.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsparse") /******************************************************************************* * * FUNCTION: ns_execute_table * * PARAMETERS: table_desc - An ACPI table descriptor for table to parse * start_node - Where to enter the table into the namespace * * RETURN: Status * * DESCRIPTION: Load ACPI/AML table by executing the entire table as a single * large control method. * * NOTE: The point of this is to execute any module-level code in-place * as the table is parsed. Some AML code depends on this behavior. * * It is a run-time option at this time, but will eventually become * the default. * * Note: This causes the table to only have a single-pass parse. * However, this is compatible with other ACPI implementations. * ******************************************************************************/ acpi_status acpi_ns_execute_table(u32 table_index, struct acpi_namespace_node *start_node) { acpi_status status; struct acpi_table_header *table; acpi_owner_id owner_id; struct acpi_evaluate_info *info = NULL; u32 aml_length; u8 *aml_start; union acpi_operand_object *method_obj = NULL; ACPI_FUNCTION_TRACE(ns_execute_table); status = acpi_get_table_by_index(table_index, &table); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Table must consist of at least a complete header */ if (table->length < sizeof(struct acpi_table_header)) { return_ACPI_STATUS(AE_BAD_HEADER); } aml_start = (u8 *)table + sizeof(struct acpi_table_header); aml_length = table->length - sizeof(struct acpi_table_header); status = acpi_tb_get_owner_id(table_index, &owner_id); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Create, initialize, and link a new temporary method object */ method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD); if (!method_obj) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Allocate the evaluation information block */ info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); if (!info) { status = AE_NO_MEMORY; goto cleanup; } ACPI_DEBUG_PRINT_RAW((ACPI_DB_PARSE, "%s: Create table pseudo-method for [%4.4s] @%p, method %p\n", ACPI_GET_FUNCTION_NAME, table->signature, table, method_obj)); method_obj->method.aml_start = aml_start; method_obj->method.aml_length = aml_length; method_obj->method.owner_id = owner_id; method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL; info->pass_number = ACPI_IMODE_EXECUTE; info->node = start_node; info->obj_desc = method_obj; info->node_flags = info->node->flags; info->full_pathname = acpi_ns_get_normalized_pathname(info->node, TRUE); if (!info->full_pathname) { status = AE_NO_MEMORY; goto cleanup; } /* Optional object evaluation log */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_EVALUATION, "%-26s: (Definition Block level)\n", "Module-level evaluation")); status = acpi_ps_execute_table(info); /* Optional object evaluation log */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_EVALUATION, "%-26s: (Definition Block level)\n", "Module-level complete")); cleanup: if (info) { ACPI_FREE(info->full_pathname); info->full_pathname = NULL; } ACPI_FREE(info); acpi_ut_remove_reference(method_obj); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: ns_one_complete_parse * * PARAMETERS: pass_number - 1 or 2 * table_desc - The table to be parsed. * * RETURN: Status * * DESCRIPTION: Perform one complete parse of an ACPI/AML table. * ******************************************************************************/ acpi_status acpi_ns_one_complete_parse(u32 pass_number, u32 table_index, struct acpi_namespace_node *start_node) { union acpi_parse_object *parse_root; acpi_status status; u32 aml_length; u8 *aml_start; struct acpi_walk_state *walk_state; struct acpi_table_header *table; acpi_owner_id owner_id; ACPI_FUNCTION_TRACE(ns_one_complete_parse); status = acpi_get_table_by_index(table_index, &table); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Table must consist of at least a complete header */ if (table->length < sizeof(struct acpi_table_header)) { return_ACPI_STATUS(AE_BAD_HEADER); } aml_start = (u8 *)table + sizeof(struct acpi_table_header); aml_length = table->length - sizeof(struct acpi_table_header); status = acpi_tb_get_owner_id(table_index, &owner_id); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Create and init a Root Node */ parse_root = acpi_ps_create_scope_op(aml_start); if (!parse_root) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state(owner_id, NULL, NULL, NULL); if (!walk_state) { acpi_ps_free_op(parse_root); return_ACPI_STATUS(AE_NO_MEMORY); } status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL, aml_start, aml_length, NULL, (u8)pass_number); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup; } /* Found OSDT table, enable the namespace override feature */ if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_OSDT) && pass_number == ACPI_IMODE_LOAD_PASS1) { walk_state->namespace_override = TRUE; } /* start_node is the default location to load the table */ if (start_node && start_node != acpi_gbl_root_node) { status = acpi_ds_scope_stack_push(start_node, ACPI_TYPE_METHOD, walk_state); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup; } } /* Parse the AML */ ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "*PARSE* pass %u parse\n", pass_number)); acpi_ex_enter_interpreter(); status = acpi_ps_parse_aml(walk_state); acpi_ex_exit_interpreter(); cleanup: acpi_ps_delete_parse_tree(parse_root); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ns_parse_table * * PARAMETERS: table_desc - An ACPI table descriptor for table to parse * start_node - Where to enter the table into the namespace * * RETURN: Status * * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops * ******************************************************************************/ acpi_status acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node) { acpi_status status; ACPI_FUNCTION_TRACE(ns_parse_table); /* * Executes the AML table as one large control method. * The point of this is to execute any module-level code in-place * as the table is parsed. Some AML code depends on this behavior. * * Note: This causes the table to only have a single-pass parse. * However, this is compatible with other ACPI implementations. */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_PARSE, "%s: **** Start table execution pass\n", ACPI_GET_FUNCTION_NAME)); status = acpi_ns_execute_table(table_index, start_node); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/nsparse.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: dbstats - Generation and display of ACPI table statistics * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdebug.h" #include "acnamesp.h" #define _COMPONENT ACPI_CA_DEBUGGER ACPI_MODULE_NAME("dbstats") /* Local prototypes */ static void acpi_db_count_namespace_objects(void); static void acpi_db_enumerate_object(union acpi_operand_object *obj_desc); static acpi_status acpi_db_classify_one_object(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); #if defined ACPI_DBG_TRACK_ALLOCATIONS || defined ACPI_USE_LOCAL_CACHE static void acpi_db_list_info(struct acpi_memory_list *list); #endif /* * Statistics subcommands */ static struct acpi_db_argument_info acpi_db_stat_types[] = { {"ALLOCATIONS"}, {"OBJECTS"}, {"MEMORY"}, {"MISC"}, {"TABLES"}, {"SIZES"}, {"STACK"}, {NULL} /* Must be null terminated */ }; #define CMD_STAT_ALLOCATIONS 0 #define CMD_STAT_OBJECTS 1 #define CMD_STAT_MEMORY 2 #define CMD_STAT_MISC 3 #define CMD_STAT_TABLES 4 #define CMD_STAT_SIZES 5 #define CMD_STAT_STACK 6 #if defined ACPI_DBG_TRACK_ALLOCATIONS || defined ACPI_USE_LOCAL_CACHE /******************************************************************************* * * FUNCTION: acpi_db_list_info * * PARAMETERS: list - Memory list/cache to be displayed * * RETURN: None * * DESCRIPTION: Display information about the input memory list or cache. * ******************************************************************************/ static void acpi_db_list_info(struct acpi_memory_list *list) { #ifdef ACPI_DBG_TRACK_ALLOCATIONS u32 outstanding; #endif acpi_os_printf("\n%s\n", list->list_name); /* max_depth > 0 indicates a cache object */ if (list->max_depth > 0) { acpi_os_printf (" Cache: [Depth MaxD Avail Size] " "%8.2X %8.2X %8.2X %8.2X\n", list->current_depth, list->max_depth, list->max_depth - list->current_depth, (list->current_depth * list->object_size)); } #ifdef ACPI_DBG_TRACK_ALLOCATIONS if (list->max_depth > 0) { acpi_os_printf (" Cache: [Requests Hits Misses ObjSize] " "%8.2X %8.2X %8.2X %8.2X\n", list->requests, list->hits, list->requests - list->hits, list->object_size); } outstanding = acpi_db_get_cache_info(list); if (list->object_size) { acpi_os_printf (" Mem: [Alloc Free Max CurSize Outstanding] " "%8.2X %8.2X %8.2X %8.2X %8.2X\n", list->total_allocated, list->total_freed, list->max_occupied, outstanding * list->object_size, outstanding); } else { acpi_os_printf (" Mem: [Alloc Free Max CurSize Outstanding Total] " "%8.2X %8.2X %8.2X %8.2X %8.2X %8.2X\n", list->total_allocated, list->total_freed, list->max_occupied, list->current_total_size, outstanding, list->total_size); } #endif } #endif /******************************************************************************* * * FUNCTION: acpi_db_enumerate_object * * PARAMETERS: obj_desc - Object to be counted * * RETURN: None * * DESCRIPTION: Add this object to the global counts, by object type. * Limited recursion handles subobjects and packages, and this * is probably acceptable within the AML debugger only. * ******************************************************************************/ static void acpi_db_enumerate_object(union acpi_operand_object *obj_desc) { u32 i; if (!obj_desc) { return; } /* Enumerate this object first */ acpi_gbl_num_objects++; if (obj_desc->common.type > ACPI_TYPE_NS_NODE_MAX) { acpi_gbl_obj_type_count_misc++; } else { acpi_gbl_obj_type_count[obj_desc->common.type]++; } /* Count the sub-objects */ switch (obj_desc->common.type) { case ACPI_TYPE_PACKAGE: for (i = 0; i < obj_desc->package.count; i++) { acpi_db_enumerate_object(obj_desc->package.elements[i]); } break; case ACPI_TYPE_DEVICE: acpi_db_enumerate_object(obj_desc->device.notify_list[0]); acpi_db_enumerate_object(obj_desc->device.notify_list[1]); acpi_db_enumerate_object(obj_desc->device.handler); break; case ACPI_TYPE_BUFFER_FIELD: if (acpi_ns_get_secondary_object(obj_desc)) { acpi_gbl_obj_type_count[ACPI_TYPE_BUFFER_FIELD]++; } break; case ACPI_TYPE_REGION: acpi_gbl_obj_type_count[ACPI_TYPE_LOCAL_REGION_FIELD]++; acpi_db_enumerate_object(obj_desc->region.handler); break; case ACPI_TYPE_POWER: acpi_db_enumerate_object(obj_desc->power_resource. notify_list[0]); acpi_db_enumerate_object(obj_desc->power_resource. notify_list[1]); break; case ACPI_TYPE_PROCESSOR: acpi_db_enumerate_object(obj_desc->processor.notify_list[0]); acpi_db_enumerate_object(obj_desc->processor.notify_list[1]); acpi_db_enumerate_object(obj_desc->processor.handler); break; case ACPI_TYPE_THERMAL: acpi_db_enumerate_object(obj_desc->thermal_zone.notify_list[0]); acpi_db_enumerate_object(obj_desc->thermal_zone.notify_list[1]); acpi_db_enumerate_object(obj_desc->thermal_zone.handler); break; default: break; } } /******************************************************************************* * * FUNCTION: acpi_db_classify_one_object * * PARAMETERS: Callback for walk_namespace * * RETURN: Status * * DESCRIPTION: Enumerate both the object descriptor (including subobjects) and * the parent namespace node. * ******************************************************************************/ static acpi_status acpi_db_classify_one_object(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_namespace_node *node; union acpi_operand_object *obj_desc; u32 type; acpi_gbl_num_nodes++; node = (struct acpi_namespace_node *)obj_handle; obj_desc = acpi_ns_get_attached_object(node); acpi_db_enumerate_object(obj_desc); type = node->type; if (type > ACPI_TYPE_NS_NODE_MAX) { acpi_gbl_node_type_count_misc++; } else { acpi_gbl_node_type_count[type]++; } return (AE_OK); #ifdef ACPI_FUTURE_IMPLEMENTATION /* TBD: These need to be counted during the initial parsing phase */ if (acpi_ps_is_named_op(op->opcode)) { num_nodes++; } if (is_method) { num_method_elements++; } num_grammar_elements++; op = acpi_ps_get_depth_next(root, op); size_of_parse_tree = (num_grammar_elements - num_method_elements) * (u32)sizeof(union acpi_parse_object); size_of_method_trees = num_method_elements * (u32)sizeof(union acpi_parse_object); size_of_node_entries = num_nodes * (u32)sizeof(struct acpi_namespace_node); size_of_acpi_objects = num_nodes * (u32)sizeof(union acpi_operand_object); #endif } /******************************************************************************* * * FUNCTION: acpi_db_count_namespace_objects * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Count and classify the entire namespace, including all * namespace nodes and attached objects. * ******************************************************************************/ static void acpi_db_count_namespace_objects(void) { u32 i; acpi_gbl_num_nodes = 0; acpi_gbl_num_objects = 0; acpi_gbl_obj_type_count_misc = 0; for (i = 0; i < (ACPI_TYPE_NS_NODE_MAX - 1); i++) { acpi_gbl_obj_type_count[i] = 0; acpi_gbl_node_type_count[i] = 0; } (void)acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, FALSE, acpi_db_classify_one_object, NULL, NULL, NULL); } /******************************************************************************* * * FUNCTION: acpi_db_display_statistics * * PARAMETERS: type_arg - Subcommand * * RETURN: Status * * DESCRIPTION: Display various statistics * ******************************************************************************/ acpi_status acpi_db_display_statistics(char *type_arg) { u32 i; u32 temp; acpi_ut_strupr(type_arg); temp = acpi_db_match_argument(type_arg, acpi_db_stat_types); if (temp == ACPI_TYPE_NOT_FOUND) { acpi_os_printf("Invalid or unsupported argument\n"); return (AE_OK); } switch (temp) { case CMD_STAT_ALLOCATIONS: #ifdef ACPI_DBG_TRACK_ALLOCATIONS acpi_ut_dump_allocation_info(); #endif break; case CMD_STAT_TABLES: acpi_os_printf("ACPI Table Information (not implemented):\n\n"); break; case CMD_STAT_OBJECTS: acpi_db_count_namespace_objects(); acpi_os_printf ("\nObjects defined in the current namespace:\n\n"); acpi_os_printf("%16.16s %10.10s %10.10s\n", "ACPI_TYPE", "NODES", "OBJECTS"); for (i = 0; i < ACPI_TYPE_NS_NODE_MAX; i++) { acpi_os_printf("%16.16s %10u %10u\n", acpi_ut_get_type_name(i), acpi_gbl_node_type_count[i], acpi_gbl_obj_type_count[i]); } acpi_os_printf("%16.16s %10u %10u\n", "Misc/Unknown", acpi_gbl_node_type_count_misc, acpi_gbl_obj_type_count_misc); acpi_os_printf("%16.16s %10u %10u\n", "TOTALS:", acpi_gbl_num_nodes, acpi_gbl_num_objects); break; case CMD_STAT_MEMORY: #ifdef ACPI_DBG_TRACK_ALLOCATIONS acpi_os_printf ("\n----Object Statistics (all in hex)---------\n"); acpi_db_list_info(acpi_gbl_global_list); acpi_db_list_info(acpi_gbl_ns_node_list); #endif #ifdef ACPI_USE_LOCAL_CACHE acpi_os_printf ("\n----Cache Statistics (all in hex)---------\n"); acpi_db_list_info(acpi_gbl_operand_cache); acpi_db_list_info(acpi_gbl_ps_node_cache); acpi_db_list_info(acpi_gbl_ps_node_ext_cache); acpi_db_list_info(acpi_gbl_state_cache); #endif break; case CMD_STAT_MISC: acpi_os_printf("\nMiscellaneous Statistics:\n\n"); acpi_os_printf("%-28s: %7u\n", "Calls to AcpiPsFind", acpi_gbl_ps_find_count); acpi_os_printf("%-28s: %7u\n", "Calls to AcpiNsLookup", acpi_gbl_ns_lookup_count); acpi_os_printf("\nMutex usage:\n\n"); for (i = 0; i < ACPI_NUM_MUTEX; i++) { acpi_os_printf("%-28s: %7u\n", acpi_ut_get_mutex_name(i), acpi_gbl_mutex_info[i].use_count); } break; case CMD_STAT_SIZES: acpi_os_printf("\nInternal object sizes:\n\n"); acpi_os_printf("Common %3d\n", (u32)sizeof(struct acpi_object_common)); acpi_os_printf("Number %3d\n", (u32)sizeof(struct acpi_object_integer)); acpi_os_printf("String %3d\n", (u32)sizeof(struct acpi_object_string)); acpi_os_printf("Buffer %3d\n", (u32)sizeof(struct acpi_object_buffer)); acpi_os_printf("Package %3d\n", (u32)sizeof(struct acpi_object_package)); acpi_os_printf("BufferField %3d\n", (u32)sizeof(struct acpi_object_buffer_field)); acpi_os_printf("Device %3d\n", (u32)sizeof(struct acpi_object_device)); acpi_os_printf("Event %3d\n", (u32)sizeof(struct acpi_object_event)); acpi_os_printf("Method %3d\n", (u32)sizeof(struct acpi_object_method)); acpi_os_printf("Mutex %3d\n", (u32)sizeof(struct acpi_object_mutex)); acpi_os_printf("Region %3d\n", (u32)sizeof(struct acpi_object_region)); acpi_os_printf("PowerResource %3d\n", (u32)sizeof(struct acpi_object_power_resource)); acpi_os_printf("Processor %3d\n", (u32)sizeof(struct acpi_object_processor)); acpi_os_printf("ThermalZone %3d\n", (u32)sizeof(struct acpi_object_thermal_zone)); acpi_os_printf("RegionField %3d\n", (u32)sizeof(struct acpi_object_region_field)); acpi_os_printf("BankField %3d\n", (u32)sizeof(struct acpi_object_bank_field)); acpi_os_printf("IndexField %3d\n", (u32)sizeof(struct acpi_object_index_field)); acpi_os_printf("Reference %3d\n", (u32)sizeof(struct acpi_object_reference)); acpi_os_printf("Notify %3d\n", (u32)sizeof(struct acpi_object_notify_handler)); acpi_os_printf("AddressSpace %3d\n", (u32)sizeof(struct acpi_object_addr_handler)); acpi_os_printf("Extra %3d\n", (u32)sizeof(struct acpi_object_extra)); acpi_os_printf("Data %3d\n", (u32)sizeof(struct acpi_object_data)); acpi_os_printf("\n"); acpi_os_printf("ParseObject %3d\n", (u32)sizeof(struct acpi_parse_obj_common)); acpi_os_printf("ParseObjectNamed %3d\n", (u32)sizeof(struct acpi_parse_obj_named)); acpi_os_printf("ParseObjectAsl %3d\n", (u32)sizeof(struct acpi_parse_obj_asl)); acpi_os_printf("OperandObject %3d\n", (u32)sizeof(union acpi_operand_object)); acpi_os_printf("NamespaceNode %3d\n", (u32)sizeof(struct acpi_namespace_node)); acpi_os_printf("AcpiObject %3d\n", (u32)sizeof(union acpi_object)); acpi_os_printf("\n"); acpi_os_printf("Generic State %3d\n", (u32)sizeof(union acpi_generic_state)); acpi_os_printf("Common State %3d\n", (u32)sizeof(struct acpi_common_state)); acpi_os_printf("Control State %3d\n", (u32)sizeof(struct acpi_control_state)); acpi_os_printf("Update State %3d\n", (u32)sizeof(struct acpi_update_state)); acpi_os_printf("Scope State %3d\n", (u32)sizeof(struct acpi_scope_state)); acpi_os_printf("Parse Scope %3d\n", (u32)sizeof(struct acpi_pscope_state)); acpi_os_printf("Package State %3d\n", (u32)sizeof(struct acpi_pkg_state)); acpi_os_printf("Thread State %3d\n", (u32)sizeof(struct acpi_thread_state)); acpi_os_printf("Result Values %3d\n", (u32)sizeof(struct acpi_result_values)); acpi_os_printf("Notify Info %3d\n", (u32)sizeof(struct acpi_notify_info)); break; case CMD_STAT_STACK: #if defined(ACPI_DEBUG_OUTPUT) temp = (u32)ACPI_PTR_DIFF(acpi_gbl_entry_stack_pointer, acpi_gbl_lowest_stack_pointer); acpi_os_printf("\nSubsystem Stack Usage:\n\n"); acpi_os_printf("Entry Stack Pointer %p\n", acpi_gbl_entry_stack_pointer); acpi_os_printf("Lowest Stack Pointer %p\n", acpi_gbl_lowest_stack_pointer); acpi_os_printf("Stack Use %X (%u)\n", temp, temp); acpi_os_printf("Deepest Procedure Nesting %u\n", acpi_gbl_deepest_nesting); #endif break; default: break; } acpi_os_printf("\n"); return (AE_OK); }
linux-master
drivers/acpi/acpica/dbstats.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: rsxface - Public interfaces to the resource manager * ******************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #include "acnamesp.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rsxface") /* Local macros for 16,32-bit to 64-bit conversion */ #define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field) #define ACPI_COPY_ADDRESS(out, in) \ ACPI_COPY_FIELD(out, in, resource_type); \ ACPI_COPY_FIELD(out, in, producer_consumer); \ ACPI_COPY_FIELD(out, in, decode); \ ACPI_COPY_FIELD(out, in, min_address_fixed); \ ACPI_COPY_FIELD(out, in, max_address_fixed); \ ACPI_COPY_FIELD(out, in, info); \ ACPI_COPY_FIELD(out, in, address.granularity); \ ACPI_COPY_FIELD(out, in, address.minimum); \ ACPI_COPY_FIELD(out, in, address.maximum); \ ACPI_COPY_FIELD(out, in, address.translation_offset); \ ACPI_COPY_FIELD(out, in, address.address_length); \ ACPI_COPY_FIELD(out, in, resource_source); /* Local prototypes */ static acpi_status acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context); static acpi_status acpi_rs_validate_parameters(acpi_handle device_handle, struct acpi_buffer *buffer, struct acpi_namespace_node **return_node); /******************************************************************************* * * FUNCTION: acpi_rs_validate_parameters * * PARAMETERS: device_handle - Handle to a device * buffer - Pointer to a data buffer * return_node - Pointer to where the device node is returned * * RETURN: Status * * DESCRIPTION: Common parameter validation for resource interfaces * ******************************************************************************/ static acpi_status acpi_rs_validate_parameters(acpi_handle device_handle, struct acpi_buffer *buffer, struct acpi_namespace_node **return_node) { acpi_status status; struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(rs_validate_parameters); /* * Must have a valid handle to an ACPI device */ if (!device_handle) { return_ACPI_STATUS(AE_BAD_PARAMETER); } node = acpi_ns_validate_handle(device_handle); if (!node) { return_ACPI_STATUS(AE_BAD_PARAMETER); } if (node->type != ACPI_TYPE_DEVICE) { return_ACPI_STATUS(AE_TYPE); } /* * Validate the user buffer object * * if there is a non-zero buffer length we also need a valid pointer in * the buffer. If it's a zero buffer length, we'll be returning the * needed buffer size (later), so keep going. */ status = acpi_ut_validate_buffer(buffer); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } *return_node = node; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_get_irq_routing_table * * PARAMETERS: device_handle - Handle to the Bus device we are querying * ret_buffer - Pointer to a buffer to receive the * current resources for the device * * RETURN: Status * * DESCRIPTION: This function is called to get the IRQ routing table for a * specific bus. The caller must first acquire a handle for the * desired bus. The routine table is placed in the buffer pointed * to by the ret_buffer variable parameter. * * If the function fails an appropriate status will be returned * and the value of ret_buffer is undefined. * * This function attempts to execute the _PRT method contained in * the object indicated by the passed device_handle. * ******************************************************************************/ acpi_status acpi_get_irq_routing_table(acpi_handle device_handle, struct acpi_buffer *ret_buffer) { acpi_status status; struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(acpi_get_irq_routing_table); /* Validate parameters then dispatch to internal routine */ status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_rs_get_prt_method_data(node, ret_buffer); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_get_irq_routing_table) /******************************************************************************* * * FUNCTION: acpi_get_current_resources * * PARAMETERS: device_handle - Handle to the device object for the * device we are querying * ret_buffer - Pointer to a buffer to receive the * current resources for the device * * RETURN: Status * * DESCRIPTION: This function is called to get the current resources for a * specific device. The caller must first acquire a handle for * the desired device. The resource data is placed in the buffer * pointed to by the ret_buffer variable parameter. * * If the function fails an appropriate status will be returned * and the value of ret_buffer is undefined. * * This function attempts to execute the _CRS method contained in * the object indicated by the passed device_handle. * ******************************************************************************/ acpi_status acpi_get_current_resources(acpi_handle device_handle, struct acpi_buffer *ret_buffer) { acpi_status status; struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(acpi_get_current_resources); /* Validate parameters then dispatch to internal routine */ status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_rs_get_crs_method_data(node, ret_buffer); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_get_current_resources) /******************************************************************************* * * FUNCTION: acpi_get_possible_resources * * PARAMETERS: device_handle - Handle to the device object for the * device we are querying * ret_buffer - Pointer to a buffer to receive the * resources for the device * * RETURN: Status * * DESCRIPTION: This function is called to get a list of the possible resources * for a specific device. The caller must first acquire a handle * for the desired device. The resource data is placed in the * buffer pointed to by the ret_buffer variable. * * If the function fails an appropriate status will be returned * and the value of ret_buffer is undefined. * ******************************************************************************/ acpi_status acpi_get_possible_resources(acpi_handle device_handle, struct acpi_buffer *ret_buffer) { acpi_status status; struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(acpi_get_possible_resources); /* Validate parameters then dispatch to internal routine */ status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_rs_get_prs_method_data(node, ret_buffer); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_get_possible_resources) /******************************************************************************* * * FUNCTION: acpi_set_current_resources * * PARAMETERS: device_handle - Handle to the device object for the * device we are setting resources * in_buffer - Pointer to a buffer containing the * resources to be set for the device * * RETURN: Status * * DESCRIPTION: This function is called to set the current resources for a * specific device. The caller must first acquire a handle for * the desired device. The resource data is passed to the routine * the buffer pointed to by the in_buffer variable. * ******************************************************************************/ acpi_status acpi_set_current_resources(acpi_handle device_handle, struct acpi_buffer *in_buffer) { acpi_status status; struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(acpi_set_current_resources); /* Validate the buffer, don't allow zero length */ if ((!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Validate parameters then dispatch to internal routine */ status = acpi_rs_validate_parameters(device_handle, in_buffer, &node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_rs_set_srs_method_data(node, in_buffer); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_set_current_resources) /******************************************************************************* * * FUNCTION: acpi_get_event_resources * * PARAMETERS: device_handle - Handle to the device object for the * device we are getting resources * in_buffer - Pointer to a buffer containing the * resources to be set for the device * * RETURN: Status * * DESCRIPTION: This function is called to get the event resources for a * specific device. The caller must first acquire a handle for * the desired device. The resource data is passed to the routine * the buffer pointed to by the in_buffer variable. Uses the * _AEI method. * ******************************************************************************/ acpi_status acpi_get_event_resources(acpi_handle device_handle, struct acpi_buffer *ret_buffer) { acpi_status status; struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(acpi_get_event_resources); /* Validate parameters then dispatch to internal routine */ status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_rs_get_aei_method_data(node, ret_buffer); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_get_event_resources) /****************************************************************************** * * FUNCTION: acpi_resource_to_address64 * * PARAMETERS: resource - Pointer to a resource * out - Pointer to the users's return buffer * (a struct acpi_resource_address64) * * RETURN: Status * * DESCRIPTION: If the resource is an address16, address32, or address64, * copy it to the address64 return buffer. This saves the * caller from having to duplicate code for different-sized * addresses. * ******************************************************************************/ acpi_status acpi_resource_to_address64(struct acpi_resource *resource, struct acpi_resource_address64 *out) { struct acpi_resource_address16 *address16; struct acpi_resource_address32 *address32; if (!resource || !out) { return (AE_BAD_PARAMETER); } /* Convert 16 or 32 address descriptor to 64 */ switch (resource->type) { case ACPI_RESOURCE_TYPE_ADDRESS16: address16 = ACPI_CAST_PTR(struct acpi_resource_address16, &resource->data); ACPI_COPY_ADDRESS(out, address16); break; case ACPI_RESOURCE_TYPE_ADDRESS32: address32 = ACPI_CAST_PTR(struct acpi_resource_address32, &resource->data); ACPI_COPY_ADDRESS(out, address32); break; case ACPI_RESOURCE_TYPE_ADDRESS64: /* Simple copy for 64 bit source */ memcpy(out, &resource->data, sizeof(struct acpi_resource_address64)); break; default: return (AE_BAD_PARAMETER); } return (AE_OK); } ACPI_EXPORT_SYMBOL(acpi_resource_to_address64) /******************************************************************************* * * FUNCTION: acpi_get_vendor_resource * * PARAMETERS: device_handle - Handle for the parent device object * name - Method name for the parent resource * (METHOD_NAME__CRS or METHOD_NAME__PRS) * uuid - Pointer to the UUID to be matched. * includes both subtype and 16-byte UUID * ret_buffer - Where the vendor resource is returned * * RETURN: Status * * DESCRIPTION: Walk a resource template for the specified device to find a * vendor-defined resource that matches the supplied UUID and * UUID subtype. Returns a struct acpi_resource of type Vendor. * ******************************************************************************/ acpi_status acpi_get_vendor_resource(acpi_handle device_handle, char *name, struct acpi_vendor_uuid *uuid, struct acpi_buffer *ret_buffer) { struct acpi_vendor_walk_info info; acpi_status status; /* Other parameters are validated by acpi_walk_resources */ if (!uuid || !ret_buffer) { return (AE_BAD_PARAMETER); } info.uuid = uuid; info.buffer = ret_buffer; info.status = AE_NOT_EXIST; /* Walk the _CRS or _PRS resource list for this device */ status = acpi_walk_resources(device_handle, name, acpi_rs_match_vendor_resource, &info); if (ACPI_FAILURE(status)) { return (status); } return (info.status); } ACPI_EXPORT_SYMBOL(acpi_get_vendor_resource) /******************************************************************************* * * FUNCTION: acpi_rs_match_vendor_resource * * PARAMETERS: acpi_walk_resource_callback * * RETURN: Status * * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID * ******************************************************************************/ static acpi_status acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context) { struct acpi_vendor_walk_info *info = context; struct acpi_resource_vendor_typed *vendor; struct acpi_buffer *buffer; acpi_status status; /* Ignore all descriptors except Vendor */ if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) { return (AE_OK); } vendor = &resource->data.vendor_typed; /* * For a valid match, these conditions must hold: * * 1) Length of descriptor data must be at least as long as a UUID struct * 2) The UUID subtypes must match * 3) The UUID data must match */ if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) || (vendor->uuid_subtype != info->uuid->subtype) || (memcmp(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) { return (AE_OK); } /* Validate/Allocate/Clear caller buffer */ buffer = info->buffer; status = acpi_ut_initialize_buffer(buffer, resource->length); if (ACPI_FAILURE(status)) { return (status); } /* Found the correct resource, copy and return it */ memcpy(buffer->pointer, resource, resource->length); buffer->length = resource->length; /* Found the desired descriptor, terminate resource walk */ info->status = AE_OK; return (AE_CTRL_TERMINATE); } /******************************************************************************* * * FUNCTION: acpi_walk_resource_buffer * * PARAMETERS: buffer - Formatted buffer returned by one of the * various Get*Resource functions * user_function - Called for each resource * context - Passed to user_function * * RETURN: Status * * DESCRIPTION: Walks the input resource template. The user_function is called * once for each resource in the list. * ******************************************************************************/ acpi_status acpi_walk_resource_buffer(struct acpi_buffer *buffer, acpi_walk_resource_callback user_function, void *context) { acpi_status status = AE_OK; struct acpi_resource *resource; struct acpi_resource *resource_end; ACPI_FUNCTION_TRACE(acpi_walk_resource_buffer); /* Parameter validation */ if (!buffer || !buffer->pointer || !user_function) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Buffer contains the resource list and length */ resource = ACPI_CAST_PTR(struct acpi_resource, buffer->pointer); resource_end = ACPI_ADD_PTR(struct acpi_resource, buffer->pointer, buffer->length); /* Walk the resource list until the end_tag is found (or buffer end) */ while (resource < resource_end) { /* Sanity check the resource type */ if (resource->type > ACPI_RESOURCE_TYPE_MAX) { status = AE_AML_INVALID_RESOURCE_TYPE; break; } /* Sanity check the length. It must not be zero, or we loop forever */ if (!resource->length) { return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); } /* Invoke the user function, abort on any error returned */ status = user_function(resource, context); if (ACPI_FAILURE(status)) { if (status == AE_CTRL_TERMINATE) { /* This is an OK termination by the user function */ status = AE_OK; } break; } /* end_tag indicates end-of-list */ if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) { break; } /* Get the next resource descriptor */ resource = ACPI_NEXT_RESOURCE(resource); } return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_walk_resource_buffer) /******************************************************************************* * * FUNCTION: acpi_walk_resources * * PARAMETERS: device_handle - Handle to the device object for the * device we are querying * name - Method name of the resources we want. * (METHOD_NAME__CRS, METHOD_NAME__PRS, or * METHOD_NAME__AEI or METHOD_NAME__DMA) * user_function - Called for each resource * context - Passed to user_function * * RETURN: Status * * DESCRIPTION: Retrieves the current or possible resource list for the * specified device. The user_function is called once for * each resource in the list. * ******************************************************************************/ acpi_status acpi_walk_resources(acpi_handle device_handle, char *name, acpi_walk_resource_callback user_function, void *context) { acpi_status status; struct acpi_buffer buffer; ACPI_FUNCTION_TRACE(acpi_walk_resources); /* Parameter validation */ if (!device_handle || !user_function || !name || (!ACPI_COMPARE_NAMESEG(name, METHOD_NAME__CRS) && !ACPI_COMPARE_NAMESEG(name, METHOD_NAME__PRS) && !ACPI_COMPARE_NAMESEG(name, METHOD_NAME__AEI) && !ACPI_COMPARE_NAMESEG(name, METHOD_NAME__DMA))) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Get the _CRS/_PRS/_AEI/_DMA resource list */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_rs_get_method_data(device_handle, name, &buffer); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Walk the resource list and cleanup */ status = acpi_walk_resource_buffer(&buffer, user_function, context); ACPI_FREE(buffer.pointer); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_walk_resources)
linux-master
drivers/acpi/acpica/rsxface.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: evgpe - General Purpose Event handling and dispatch * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #include "acnamesp.h" #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evgpe") #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ /* Local prototypes */ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context); static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context); /******************************************************************************* * * FUNCTION: acpi_ev_update_gpe_enable_mask * * PARAMETERS: gpe_event_info - GPE to update * * RETURN: Status * * DESCRIPTION: Updates GPE register enable mask based upon whether there are * runtime references to this GPE * ******************************************************************************/ acpi_status acpi_ev_update_gpe_enable_mask(struct acpi_gpe_event_info *gpe_event_info) { struct acpi_gpe_register_info *gpe_register_info; u32 register_bit; ACPI_FUNCTION_TRACE(ev_update_gpe_enable_mask); gpe_register_info = gpe_event_info->register_info; if (!gpe_register_info) { return_ACPI_STATUS(AE_NOT_EXIST); } register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); /* Clear the run bit up front */ ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit); /* Set the mask bit only if there are references to this GPE */ if (gpe_event_info->runtime_count) { ACPI_SET_BIT(gpe_register_info->enable_for_run, (u8)register_bit); } gpe_register_info->enable_mask = gpe_register_info->enable_for_run; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_enable_gpe * * PARAMETERS: gpe_event_info - GPE to enable * * RETURN: Status * * DESCRIPTION: Enable a GPE. * ******************************************************************************/ acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info) { acpi_status status; ACPI_FUNCTION_TRACE(ev_enable_gpe); /* Enable the requested GPE */ status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_mask_gpe * * PARAMETERS: gpe_event_info - GPE to be blocked/unblocked * is_masked - Whether the GPE is masked or not * * RETURN: Status * * DESCRIPTION: Unconditionally mask/unmask a GPE during runtime. * ******************************************************************************/ acpi_status acpi_ev_mask_gpe(struct acpi_gpe_event_info *gpe_event_info, u8 is_masked) { struct acpi_gpe_register_info *gpe_register_info; u32 register_bit; ACPI_FUNCTION_TRACE(ev_mask_gpe); gpe_register_info = gpe_event_info->register_info; if (!gpe_register_info) { return_ACPI_STATUS(AE_NOT_EXIST); } register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); /* Perform the action */ if (is_masked) { if (register_bit & gpe_register_info->mask_for_run) { return_ACPI_STATUS(AE_BAD_PARAMETER); } (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE); ACPI_SET_BIT(gpe_register_info->mask_for_run, (u8)register_bit); } else { if (!(register_bit & gpe_register_info->mask_for_run)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } ACPI_CLEAR_BIT(gpe_register_info->mask_for_run, (u8)register_bit); if (gpe_event_info->runtime_count && !gpe_event_info->disable_for_dispatch) { (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE); } } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_add_gpe_reference * * PARAMETERS: gpe_event_info - Add a reference to this GPE * clear_on_enable - Clear GPE status before enabling it * * RETURN: Status * * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is * hardware-enabled. * ******************************************************************************/ acpi_status acpi_ev_add_gpe_reference(struct acpi_gpe_event_info *gpe_event_info, u8 clear_on_enable) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ev_add_gpe_reference); if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) { return_ACPI_STATUS(AE_LIMIT); } gpe_event_info->runtime_count++; if (gpe_event_info->runtime_count == 1) { /* Enable on first reference */ if (clear_on_enable) { (void)acpi_hw_clear_gpe(gpe_event_info); } status = acpi_ev_update_gpe_enable_mask(gpe_event_info); if (ACPI_SUCCESS(status)) { status = acpi_ev_enable_gpe(gpe_event_info); } if (ACPI_FAILURE(status)) { gpe_event_info->runtime_count--; } } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_remove_gpe_reference * * PARAMETERS: gpe_event_info - Remove a reference to this GPE * * RETURN: Status * * DESCRIPTION: Remove a reference to a GPE. When the last reference is * removed, the GPE is hardware-disabled. * ******************************************************************************/ acpi_status acpi_ev_remove_gpe_reference(struct acpi_gpe_event_info *gpe_event_info) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ev_remove_gpe_reference); if (!gpe_event_info->runtime_count) { return_ACPI_STATUS(AE_LIMIT); } gpe_event_info->runtime_count--; if (!gpe_event_info->runtime_count) { /* Disable on last reference */ status = acpi_ev_update_gpe_enable_mask(gpe_event_info); if (ACPI_SUCCESS(status)) { status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE); } if (ACPI_FAILURE(status)) { gpe_event_info->runtime_count++; } } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_low_get_gpe_info * * PARAMETERS: gpe_number - Raw GPE number * gpe_block - A GPE info block * * RETURN: A GPE event_info struct. NULL if not a valid GPE (The gpe_number * is not within the specified GPE block) * * DESCRIPTION: Returns the event_info struct associated with this GPE. This is * the low-level implementation of ev_get_gpe_event_info. * ******************************************************************************/ struct acpi_gpe_event_info *acpi_ev_low_get_gpe_info(u32 gpe_number, struct acpi_gpe_block_info *gpe_block) { u32 gpe_index; /* * Validate that the gpe_number is within the specified gpe_block. * (Two steps) */ if (!gpe_block || (gpe_number < gpe_block->block_base_number)) { return (NULL); } gpe_index = gpe_number - gpe_block->block_base_number; if (gpe_index >= gpe_block->gpe_count) { return (NULL); } return (&gpe_block->event_info[gpe_index]); } /******************************************************************************* * * FUNCTION: acpi_ev_get_gpe_event_info * * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1 * gpe_number - Raw GPE number * * RETURN: A GPE event_info struct. NULL if not a valid GPE * * DESCRIPTION: Returns the event_info struct associated with this GPE. * Validates the gpe_block and the gpe_number * * Should be called only when the GPE lists are semaphore locked * and not subject to change. * ******************************************************************************/ struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device, u32 gpe_number) { union acpi_operand_object *obj_desc; struct acpi_gpe_event_info *gpe_info; u32 i; ACPI_FUNCTION_ENTRY(); /* A NULL gpe_device means use the FADT-defined GPE block(s) */ if (!gpe_device) { /* Examine GPE Block 0 and 1 (These blocks are permanent) */ for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) { gpe_info = acpi_ev_low_get_gpe_info(gpe_number, acpi_gbl_gpe_fadt_blocks [i]); if (gpe_info) { return (gpe_info); } } /* The gpe_number was not in the range of either FADT GPE block */ return (NULL); } /* A Non-NULL gpe_device means this is a GPE Block Device */ obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *) gpe_device); if (!obj_desc || !obj_desc->device.gpe_block) { return (NULL); } return (acpi_ev_low_get_gpe_info (gpe_number, obj_desc->device.gpe_block)); } /******************************************************************************* * * FUNCTION: acpi_ev_gpe_detect * * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt. * Can have multiple GPE blocks attached. * * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED * * DESCRIPTION: Detect if any GP events have occurred. This function is * executed at interrupt level. * ******************************************************************************/ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list) { struct acpi_gpe_block_info *gpe_block; struct acpi_namespace_node *gpe_device; struct acpi_gpe_register_info *gpe_register_info; struct acpi_gpe_event_info *gpe_event_info; u32 gpe_number; u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; acpi_cpu_flags flags; u32 i; u32 j; ACPI_FUNCTION_NAME(ev_gpe_detect); /* Check for the case where there are no GPEs */ if (!gpe_xrupt_list) { return (int_status); } /* * We need to obtain the GPE lock for both the data structs and registers * Note: Not necessary to obtain the hardware lock, since the GPE * registers are owned by the gpe_lock. */ flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); /* Examine all GPE blocks attached to this interrupt level */ gpe_block = gpe_xrupt_list->gpe_block_list_head; while (gpe_block) { gpe_device = gpe_block->node; /* * Read all of the 8-bit GPE status and enable registers in this GPE * block, saving all of them. Find all currently active GP events. */ for (i = 0; i < gpe_block->register_count; i++) { /* Get the next status/enable pair */ gpe_register_info = &gpe_block->register_info[i]; /* * Optimization: If there are no GPEs enabled within this * register, we can safely ignore the entire register. */ if (!(gpe_register_info->enable_for_run | gpe_register_info->enable_for_wake)) { ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS, "Ignore disabled registers for GPE %02X-%02X: " "RunEnable=%02X, WakeEnable=%02X\n", gpe_register_info-> base_gpe_number, gpe_register_info-> base_gpe_number + (ACPI_GPE_REGISTER_WIDTH - 1), gpe_register_info-> enable_for_run, gpe_register_info-> enable_for_wake)); continue; } /* Now look at the individual GPEs in this byte register */ for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { /* Detect and dispatch one GPE bit */ gpe_event_info = &gpe_block-> event_info[((acpi_size)i * ACPI_GPE_REGISTER_WIDTH) + j]; gpe_number = j + gpe_register_info->base_gpe_number; acpi_os_release_lock(acpi_gbl_gpe_lock, flags); int_status |= acpi_ev_detect_gpe(gpe_device, gpe_event_info, gpe_number); flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); } } gpe_block = gpe_block->next; } acpi_os_release_lock(acpi_gbl_gpe_lock, flags); return (int_status); } /******************************************************************************* * * FUNCTION: acpi_ev_asynch_execute_gpe_method * * PARAMETERS: Context (gpe_event_info) - Info for this GPE * * RETURN: None * * DESCRIPTION: Perform the actual execution of a GPE control method. This * function is called from an invocation of acpi_os_execute and * therefore does NOT execute at interrupt level - so that * the control method itself is not executed in the context of * an interrupt handler. * ******************************************************************************/ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context) { struct acpi_gpe_event_info *gpe_event_info = context; acpi_status status = AE_OK; struct acpi_evaluate_info *info; struct acpi_gpe_notify_info *notify; ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method); /* Do the correct dispatch - normal method or implicit notify */ switch (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags)) { case ACPI_GPE_DISPATCH_NOTIFY: /* * Implicit notify. * Dispatch a DEVICE_WAKE notify to the appropriate handler. * NOTE: the request is queued for execution after this method * completes. The notify handlers are NOT invoked synchronously * from this thread -- because handlers may in turn run other * control methods. * * June 2012: Expand implicit notify mechanism to support * notifies on multiple device objects. */ notify = gpe_event_info->dispatch.notify_list; while (ACPI_SUCCESS(status) && notify) { status = acpi_ev_queue_notify_request(notify->device_node, ACPI_NOTIFY_DEVICE_WAKE); notify = notify->next; } break; case ACPI_GPE_DISPATCH_METHOD: /* Allocate the evaluation information block */ info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); if (!info) { status = AE_NO_MEMORY; } else { /* * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the * _Lxx/_Exx control method that corresponds to this GPE */ info->prefix_node = gpe_event_info->dispatch.method_node; info->flags = ACPI_IGNORE_RETURN_VALUE; status = acpi_ns_evaluate(info); ACPI_FREE(info); } if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "while evaluating GPE method [%4.4s]", acpi_ut_get_node_name(gpe_event_info-> dispatch. method_node))); } break; default: goto error_exit; /* Should never happen */ } /* Defer enabling of GPE until all notify handlers are done */ status = acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe, gpe_event_info); if (ACPI_SUCCESS(status)) { return_VOID; } error_exit: acpi_ev_asynch_enable_gpe(gpe_event_info); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ev_asynch_enable_gpe * * PARAMETERS: Context (gpe_event_info) - Info for this GPE * Callback from acpi_os_execute * * RETURN: None * * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to * complete (i.e., finish execution of Notify) * ******************************************************************************/ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context) { struct acpi_gpe_event_info *gpe_event_info = context; acpi_cpu_flags flags; flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); (void)acpi_ev_finish_gpe(gpe_event_info); acpi_os_release_lock(acpi_gbl_gpe_lock, flags); return; } /******************************************************************************* * * FUNCTION: acpi_ev_finish_gpe * * PARAMETERS: gpe_event_info - Info for this GPE * * RETURN: Status * * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution * of a GPE method or a synchronous or asynchronous GPE handler. * ******************************************************************************/ acpi_status acpi_ev_finish_gpe(struct acpi_gpe_event_info *gpe_event_info) { acpi_status status; if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED) { /* * GPE is level-triggered, we clear the GPE status bit after * handling the event. */ status = acpi_hw_clear_gpe(gpe_event_info); if (ACPI_FAILURE(status)) { return (status); } } /* * Enable this GPE, conditionally. This means that the GPE will * only be physically enabled if the enable_mask bit is set * in the event_info. */ (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_CONDITIONAL_ENABLE); gpe_event_info->disable_for_dispatch = FALSE; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_detect_gpe * * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1 * gpe_event_info - Info for this GPE * gpe_number - Number relative to the parent GPE block * * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED * * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function * (e.g. EC) or method (e.g. _Lxx/_Exx) handler. * NOTE: GPE is W1C, so it is possible to handle a single GPE from both * task and irq context in parallel as long as the process to * detect and mask the GPE is atomic. * However the atomicity of ACPI_GPE_DISPATCH_RAW_HANDLER is * dependent on the raw handler itself. * ******************************************************************************/ u32 acpi_ev_detect_gpe(struct acpi_namespace_node *gpe_device, struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number) { u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; u8 enabled_status_byte; u64 status_reg; u64 enable_reg; u32 register_bit; struct acpi_gpe_register_info *gpe_register_info; struct acpi_gpe_handler_info *gpe_handler_info; acpi_cpu_flags flags; acpi_status status; ACPI_FUNCTION_TRACE(ev_gpe_detect); flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); if (!gpe_event_info) { gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); if (!gpe_event_info) goto error_exit; } /* Get the info block for the entire GPE register */ gpe_register_info = gpe_event_info->register_info; /* Get the register bitmask for this GPE */ register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); /* GPE currently enabled (enable bit == 1)? */ status = acpi_hw_gpe_read(&enable_reg, &gpe_register_info->enable_address); if (ACPI_FAILURE(status)) { goto error_exit; } /* GPE currently active (status bit == 1)? */ status = acpi_hw_gpe_read(&status_reg, &gpe_register_info->status_address); if (ACPI_FAILURE(status)) { goto error_exit; } /* Check if there is anything active at all in this GPE */ ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS, "Read registers for GPE %02X: Status=%02X, Enable=%02X, " "RunEnable=%02X, WakeEnable=%02X\n", gpe_number, (u32)(status_reg & register_bit), (u32)(enable_reg & register_bit), gpe_register_info->enable_for_run, gpe_register_info->enable_for_wake)); enabled_status_byte = (u8)(status_reg & enable_reg); if (!(enabled_status_byte & register_bit)) { goto error_exit; } /* Invoke global event handler if present */ acpi_gpe_count++; if (acpi_gbl_global_event_handler) { acpi_gbl_global_event_handler(ACPI_EVENT_TYPE_GPE, gpe_device, gpe_number, acpi_gbl_global_event_handler_context); } /* Found an active GPE */ if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) == ACPI_GPE_DISPATCH_RAW_HANDLER) { /* Dispatch the event to a raw handler */ gpe_handler_info = gpe_event_info->dispatch.handler; /* * There is no protection around the namespace node * and the GPE handler to ensure a safe destruction * because: * 1. The namespace node is expected to always * exist after loading a table. * 2. The GPE handler is expected to be flushed by * acpi_os_wait_events_complete() before the * destruction. */ acpi_os_release_lock(acpi_gbl_gpe_lock, flags); int_status |= gpe_handler_info->address(gpe_device, gpe_number, gpe_handler_info->context); flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); } else { /* Dispatch the event to a standard handler or method. */ int_status |= acpi_ev_gpe_dispatch(gpe_device, gpe_event_info, gpe_number); } error_exit: acpi_os_release_lock(acpi_gbl_gpe_lock, flags); return (int_status); } /******************************************************************************* * * FUNCTION: acpi_ev_gpe_dispatch * * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1 * gpe_event_info - Info for this GPE * gpe_number - Number relative to the parent GPE block * * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED * * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC) * or method (e.g. _Lxx/_Exx) handler. * ******************************************************************************/ u32 acpi_ev_gpe_dispatch(struct acpi_namespace_node *gpe_device, struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number) { acpi_status status; u32 return_value; ACPI_FUNCTION_TRACE(ev_gpe_dispatch); /* * Always disable the GPE so that it does not keep firing before * any asynchronous activity completes (either from the execution * of a GPE method or an asynchronous GPE handler.) * * If there is no handler or method to run, just disable the * GPE and leave it disabled permanently to prevent further such * pointless events from firing. */ status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Unable to disable GPE %02X", gpe_number)); return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); } /* * If edge-triggered, clear the GPE status bit now. Note that * level-triggered events are cleared after the GPE is serviced. */ if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_EDGE_TRIGGERED) { status = acpi_hw_clear_gpe(gpe_event_info); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Unable to clear GPE %02X", gpe_number)); (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_CONDITIONAL_ENABLE); return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); } } gpe_event_info->disable_for_dispatch = TRUE; /* * Dispatch the GPE to either an installed handler or the control * method associated with this GPE (_Lxx or _Exx). If a handler * exists, we invoke it and do not attempt to run the method. * If there is neither a handler nor a method, leave the GPE * disabled. */ switch (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags)) { case ACPI_GPE_DISPATCH_HANDLER: /* Invoke the installed handler (at interrupt level) */ return_value = gpe_event_info->dispatch.handler->address(gpe_device, gpe_number, gpe_event_info-> dispatch.handler-> context); /* If requested, clear (if level-triggered) and re-enable the GPE */ if (return_value & ACPI_REENABLE_GPE) { (void)acpi_ev_finish_gpe(gpe_event_info); } break; case ACPI_GPE_DISPATCH_METHOD: case ACPI_GPE_DISPATCH_NOTIFY: /* * Execute the method associated with the GPE * NOTE: Level-triggered GPEs are cleared after the method completes. */ status = acpi_os_execute(OSL_GPE_HANDLER, acpi_ev_asynch_execute_gpe_method, gpe_event_info); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Unable to queue handler for GPE %02X - event disabled", gpe_number)); } break; default: /* * No handler or method to run! * 03/2010: This case should no longer be possible. We will not allow * a GPE to be enabled if it has no handler or method. */ ACPI_ERROR((AE_INFO, "No handler or method for GPE %02X, disabling event", gpe_number)); break; } return_UINT32(ACPI_INTERRUPT_HANDLED); } #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/evgpe.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: uterror - Various internal error/warning output functions * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("uterror") /* * This module contains internal error functions that may * be configured out. */ #if !defined (ACPI_NO_ERROR_MESSAGES) /******************************************************************************* * * FUNCTION: acpi_ut_predefined_warning * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * pathname - Full pathname to the node * node_flags - From Namespace node for the method/object * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Warnings for the predefined validation module. Messages are * only emitted the first time a problem with a particular * method/object is detected. This prevents a flood of error * messages for methods that are repeatedly evaluated. * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_ut_predefined_warning(const char *module_name, u32 line_number, char *pathname, u16 node_flags, const char *format, ...) { va_list arg_list; /* * Warning messages for this method/object will be disabled after the * first time a validation fails or an object is successfully repaired. */ if (node_flags & ANOBJ_EVALUATED) { return; } acpi_os_printf(ACPI_MSG_WARNING "%s: ", pathname); va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); } /******************************************************************************* * * FUNCTION: acpi_ut_predefined_info * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * pathname - Full pathname to the node * node_flags - From Namespace node for the method/object * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Info messages for the predefined validation module. Messages * are only emitted the first time a problem with a particular * method/object is detected. This prevents a flood of * messages for methods that are repeatedly evaluated. * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_ut_predefined_info(const char *module_name, u32 line_number, char *pathname, u16 node_flags, const char *format, ...) { va_list arg_list; /* * Warning messages for this method/object will be disabled after the * first time a validation fails or an object is successfully repaired. */ if (node_flags & ANOBJ_EVALUATED) { return; } acpi_os_printf(ACPI_MSG_INFO "%s: ", pathname); va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); } /******************************************************************************* * * FUNCTION: acpi_ut_predefined_bios_error * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * pathname - Full pathname to the node * node_flags - From Namespace node for the method/object * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: BIOS error message for predefined names. Messages * are only emitted the first time a problem with a particular * method/object is detected. This prevents a flood of * messages for methods that are repeatedly evaluated. * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_ut_predefined_bios_error(const char *module_name, u32 line_number, char *pathname, u16 node_flags, const char *format, ...) { va_list arg_list; /* * Warning messages for this method/object will be disabled after the * first time a validation fails or an object is successfully repaired. */ if (node_flags & ANOBJ_EVALUATED) { return; } acpi_os_printf(ACPI_MSG_BIOS_ERROR "%s: ", pathname); va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); } /******************************************************************************* * * FUNCTION: acpi_ut_prefixed_namespace_error * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * prefix_scope - Scope/Path that prefixes the internal path * internal_path - Name or path of the namespace node * lookup_status - Exception code from NS lookup * * RETURN: None * * DESCRIPTION: Print error message with the full pathname constructed this way: * * prefix_scope_node_full_path.externalized_internal_path * * NOTE: 10/2017: Treat the major ns_lookup errors as firmware errors * ******************************************************************************/ void acpi_ut_prefixed_namespace_error(const char *module_name, u32 line_number, union acpi_generic_state *prefix_scope, const char *internal_path, acpi_status lookup_status) { char *full_path; const char *message; /* * Main cases: * 1) Object creation, object must not already exist * 2) Object lookup, object must exist */ switch (lookup_status) { case AE_ALREADY_EXISTS: acpi_os_printf(ACPI_MSG_BIOS_ERROR); message = "Failure creating named object"; break; case AE_NOT_FOUND: acpi_os_printf(ACPI_MSG_BIOS_ERROR); message = "Could not resolve symbol"; break; default: acpi_os_printf(ACPI_MSG_ERROR); message = "Failure resolving symbol"; break; } /* Concatenate the prefix path and the internal path */ full_path = acpi_ns_build_prefixed_pathname(prefix_scope, internal_path); acpi_os_printf("%s [%s], %s", message, full_path ? full_path : "Could not get pathname", acpi_format_exception(lookup_status)); if (full_path) { ACPI_FREE(full_path); } ACPI_MSG_SUFFIX; } #ifdef __OBSOLETE_FUNCTION /******************************************************************************* * * FUNCTION: acpi_ut_namespace_error * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * internal_name - Name or path of the namespace node * lookup_status - Exception code from NS lookup * * RETURN: None * * DESCRIPTION: Print error message with the full pathname for the NS node. * ******************************************************************************/ void acpi_ut_namespace_error(const char *module_name, u32 line_number, const char *internal_name, acpi_status lookup_status) { acpi_status status; u32 bad_name; char *name = NULL; ACPI_MSG_REDIRECT_BEGIN; acpi_os_printf(ACPI_MSG_ERROR); if (lookup_status == AE_BAD_CHARACTER) { /* There is a non-ascii character in the name */ ACPI_MOVE_32_TO_32(&bad_name, ACPI_CAST_PTR(u32, internal_name)); acpi_os_printf("[0x%.8X] (NON-ASCII)", bad_name); } else { /* Convert path to external format */ status = acpi_ns_externalize_name(ACPI_UINT32_MAX, internal_name, NULL, &name); /* Print target name */ if (ACPI_SUCCESS(status)) { acpi_os_printf("[%s]", name); } else { acpi_os_printf("[COULD NOT EXTERNALIZE NAME]"); } if (name) { ACPI_FREE(name); } } acpi_os_printf(" Namespace lookup failure, %s", acpi_format_exception(lookup_status)); ACPI_MSG_SUFFIX; ACPI_MSG_REDIRECT_END; } #endif /******************************************************************************* * * FUNCTION: acpi_ut_method_error * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * message - Error message to use on failure * prefix_node - Prefix relative to the path * path - Path to the node (optional) * method_status - Execution status * * RETURN: None * * DESCRIPTION: Print error message with the full pathname for the method. * ******************************************************************************/ void acpi_ut_method_error(const char *module_name, u32 line_number, const char *message, struct acpi_namespace_node *prefix_node, const char *path, acpi_status method_status) { acpi_status status; struct acpi_namespace_node *node = prefix_node; ACPI_MSG_REDIRECT_BEGIN; acpi_os_printf(ACPI_MSG_ERROR); if (path) { status = acpi_ns_get_node(prefix_node, path, ACPI_NS_NO_UPSEARCH, &node); if (ACPI_FAILURE(status)) { acpi_os_printf("[Could not get node by pathname]"); } } acpi_ns_print_node_pathname(node, message); acpi_os_printf(" due to previous error (%s)", acpi_format_exception(method_status)); ACPI_MSG_SUFFIX; ACPI_MSG_REDIRECT_END; } #endif /* ACPI_NO_ERROR_MESSAGES */
linux-master
drivers/acpi/acpica/uterror.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nsarguments - Validation of args for ACPI predefined methods * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acpredef.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsarguments") /******************************************************************************* * * FUNCTION: acpi_ns_check_argument_types * * PARAMETERS: info - Method execution information block * * RETURN: None * * DESCRIPTION: Check the incoming argument count and all argument types * against the argument type list for a predefined name. * ******************************************************************************/ void acpi_ns_check_argument_types(struct acpi_evaluate_info *info) { u16 arg_type_list; u8 arg_count; u8 arg_type; u8 user_arg_type; u32 i; /* * If not a predefined name, cannot typecheck args, because * we have no idea what argument types are expected. * Also, ignore typecheck if warnings/errors if this method * has already been evaluated at least once -- in order * to suppress repetitive messages. */ if (!info->predefined || (info->node->flags & ANOBJ_EVALUATED)) { return; } arg_type_list = info->predefined->info.argument_list; arg_count = METHOD_GET_ARG_COUNT(arg_type_list); /* Typecheck all arguments */ for (i = 0; ((i < arg_count) && (i < info->param_count)); i++) { arg_type = METHOD_GET_NEXT_TYPE(arg_type_list); user_arg_type = info->parameters[i]->common.type; /* No typechecking for ACPI_TYPE_ANY */ if ((user_arg_type != arg_type) && (arg_type != ACPI_TYPE_ANY)) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, ACPI_WARN_ALWAYS, "Argument #%u type mismatch - " "Found [%s], ACPI requires [%s]", (i + 1), acpi_ut_get_type_name (user_arg_type), acpi_ut_get_type_name(arg_type))); /* Prevent any additional typechecking for this method */ info->node->flags |= ANOBJ_EVALUATED; } } } /******************************************************************************* * * FUNCTION: acpi_ns_check_acpi_compliance * * PARAMETERS: pathname - Full pathname to the node (for error msgs) * node - Namespace node for the method/object * predefined - Pointer to entry in predefined name table * * RETURN: None * * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a * predefined name is what is expected (matches what is defined in * the ACPI specification for this predefined name.) * ******************************************************************************/ void acpi_ns_check_acpi_compliance(char *pathname, struct acpi_namespace_node *node, const union acpi_predefined_info *predefined) { u32 aml_param_count; u32 required_param_count; if (!predefined || (node->flags & ANOBJ_EVALUATED)) { return; } /* Get the ACPI-required arg count from the predefined info table */ required_param_count = METHOD_GET_ARG_COUNT(predefined->info.argument_list); /* * If this object is not a control method, we can check if the ACPI * spec requires that it be a method. */ if (node->type != ACPI_TYPE_METHOD) { if (required_param_count > 0) { /* Object requires args, must be implemented as a method */ ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "Object (%s) must be a control method with %u arguments", acpi_ut_get_type_name(node-> type), required_param_count)); } else if (!required_param_count && !predefined->info.expected_btypes) { /* Object requires no args and no return value, must be a method */ ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "Object (%s) must be a control method " "with no arguments and no return value", acpi_ut_get_type_name(node-> type))); } return; } /* * This is a control method. * Check that the ASL/AML-defined parameter count for this method * matches the ACPI-required parameter count * * Some methods are allowed to have a "minimum" number of args (_SCP) * because their definition in ACPI has changed over time. * * Note: These are BIOS errors in the declaration of the object */ aml_param_count = node->object->method.param_count; if (aml_param_count < required_param_count) { ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "Insufficient arguments - " "ASL declared %u, ACPI requires %u", aml_param_count, required_param_count)); } else if ((aml_param_count > required_param_count) && !(predefined->info. argument_list & ARG_COUNT_IS_MINIMUM)) { ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "Excess arguments - " "ASL declared %u, ACPI requires %u", aml_param_count, required_param_count)); } } /******************************************************************************* * * FUNCTION: acpi_ns_check_argument_count * * PARAMETERS: pathname - Full pathname to the node (for error msgs) * node - Namespace node for the method/object * user_param_count - Number of args passed in by the caller * predefined - Pointer to entry in predefined name table * * RETURN: None * * DESCRIPTION: Check that incoming argument count matches the declared * parameter count (in the ASL/AML) for an object. * ******************************************************************************/ void acpi_ns_check_argument_count(char *pathname, struct acpi_namespace_node *node, u32 user_param_count, const union acpi_predefined_info *predefined) { u32 aml_param_count; u32 required_param_count; if (node->flags & ANOBJ_EVALUATED) { return; } if (!predefined) { /* * Not a predefined name. Check the incoming user argument count * against the count that is specified in the method/object. */ if (node->type != ACPI_TYPE_METHOD) { if (user_param_count) { ACPI_INFO_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "%u arguments were passed to a non-method ACPI object (%s)", user_param_count, acpi_ut_get_type_name (node->type))); } return; } /* * This is a control method. Check the parameter count. * We can only check the incoming argument count against the * argument count declared for the method in the ASL/AML. * * Emit a message if too few or too many arguments have been passed * by the caller. * * Note: Too many arguments will not cause the method to * fail. However, the method will fail if there are too few * arguments and the method attempts to use one of the missing ones. */ aml_param_count = node->object->method.param_count; if (user_param_count < aml_param_count) { ACPI_WARN_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "Insufficient arguments - " "Caller passed %u, method requires %u", user_param_count, aml_param_count)); } else if (user_param_count > aml_param_count) { ACPI_INFO_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "Excess arguments - " "Caller passed %u, method requires %u", user_param_count, aml_param_count)); } return; } /* * This is a predefined name. Validate the user-supplied parameter * count against the ACPI specification. We don't validate against * the method itself because what is important here is that the * caller is in conformance with the spec. (The arg count for the * method was checked against the ACPI spec earlier.) * * Some methods are allowed to have a "minimum" number of args (_SCP) * because their definition in ACPI has changed over time. */ required_param_count = METHOD_GET_ARG_COUNT(predefined->info.argument_list); if (user_param_count < required_param_count) { ACPI_WARN_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "Insufficient arguments - " "Caller passed %u, ACPI requires %u", user_param_count, required_param_count)); } else if ((user_param_count > required_param_count) && !(predefined->info.argument_list & ARG_COUNT_IS_MINIMUM)) { ACPI_INFO_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS, "Excess arguments - " "Caller passed %u, ACPI requires %u", user_param_count, required_param_count)); } }
linux-master
drivers/acpi/acpica/nsarguments.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: tbutils - ACPI Table utilities * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "actables.h" #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbutils") /* Local prototypes */ static acpi_physical_address acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size); #if (!ACPI_REDUCED_HARDWARE) /******************************************************************************* * * FUNCTION: acpi_tb_initialize_facs * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global * for accessing the Global Lock and Firmware Waking Vector * ******************************************************************************/ acpi_status acpi_tb_initialize_facs(void) { struct acpi_table_facs *facs; /* If Hardware Reduced flag is set, there is no FACS */ if (acpi_gbl_reduced_hardware) { acpi_gbl_FACS = NULL; return (AE_OK); } else if (acpi_gbl_FADT.Xfacs && (!acpi_gbl_FADT.facs || !acpi_gbl_use32_bit_facs_addresses)) { (void)acpi_get_table_by_index(acpi_gbl_xfacs_index, ACPI_CAST_INDIRECT_PTR(struct acpi_table_header, &facs)); acpi_gbl_FACS = facs; } else if (acpi_gbl_FADT.facs) { (void)acpi_get_table_by_index(acpi_gbl_facs_index, ACPI_CAST_INDIRECT_PTR(struct acpi_table_header, &facs)); acpi_gbl_FACS = facs; } /* If there is no FACS, just continue. There was already an error msg */ return (AE_OK); } #endif /* !ACPI_REDUCED_HARDWARE */ /******************************************************************************* * * FUNCTION: acpi_tb_check_dsdt_header * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect * if the DSDT has been replaced from outside the OS and/or if * the DSDT header has been corrupted. * ******************************************************************************/ void acpi_tb_check_dsdt_header(void) { /* Compare original length and checksum to current values */ if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length || acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) { ACPI_BIOS_ERROR((AE_INFO, "The DSDT has been corrupted or replaced - " "old, new headers below")); acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header); acpi_tb_print_table_header(0, acpi_gbl_DSDT); ACPI_ERROR((AE_INFO, "Please send DMI info to [email protected]\n" "If system does not work as expected, please boot with acpi=copy_dsdt")); /* Disable further error messages */ acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length; acpi_gbl_original_dsdt_header.checksum = acpi_gbl_DSDT->checksum; } } /******************************************************************************* * * FUNCTION: acpi_tb_copy_dsdt * * PARAMETERS: table_index - Index of installed table to copy * * RETURN: The copied DSDT * * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory. * Some very bad BIOSs are known to either corrupt the DSDT or * install a new, bad DSDT. This copy works around the problem. * ******************************************************************************/ struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index) { struct acpi_table_header *new_table; struct acpi_table_desc *table_desc; table_desc = &acpi_gbl_root_table_list.tables[table_index]; new_table = ACPI_ALLOCATE(table_desc->length); if (!new_table) { ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X", table_desc->length)); return (NULL); } memcpy(new_table, table_desc->pointer, table_desc->length); acpi_tb_uninstall_table(table_desc); acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list. tables[acpi_gbl_dsdt_index], ACPI_PTR_TO_PHYSADDR(new_table), ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, new_table); ACPI_INFO(("Forced DSDT copy: length 0x%05X copied locally, original unmapped", new_table->length)); return (new_table); } /******************************************************************************* * * FUNCTION: acpi_tb_get_root_table_entry * * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry * table_entry_size - sizeof 32 or 64 (RSDT or XSDT) * * RETURN: Physical address extracted from the root table * * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on * both 32-bit and 64-bit platforms * * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on * 64-bit platforms. * ******************************************************************************/ static acpi_physical_address acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size) { u32 address32; u64 address64; /* * Get the table physical address (32-bit for RSDT, 64-bit for XSDT): * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT */ if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) { /* * 32-bit platform, RSDT: Return 32-bit table entry * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return */ ACPI_MOVE_32_TO_32(&address32, table_entry); return address32; } else { /* * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, * return 64-bit */ ACPI_MOVE_64_TO_64(&address64, table_entry); #if ACPI_MACHINE_WIDTH == 32 if (address64 > ACPI_UINT32_MAX) { /* Will truncate 64-bit address to 32 bits, issue warning */ ACPI_BIOS_WARNING((AE_INFO, "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X)," " truncating", ACPI_FORMAT_UINT64(address64))); } #endif return ((acpi_physical_address)(address64)); } } /******************************************************************************* * * FUNCTION: acpi_tb_parse_root_table * * PARAMETERS: rsdp_address - Pointer to the RSDP * * RETURN: Status * * DESCRIPTION: This function is called to parse the Root System Description * Table (RSDT or XSDT) * * NOTE: Tables are mapped (not copied) for efficiency. The FACS must * be mapped and cannot be copied because it contains the actual * memory location of the ACPI Global Lock. * ******************************************************************************/ acpi_status ACPI_INIT_FUNCTION acpi_tb_parse_root_table(acpi_physical_address rsdp_address) { struct acpi_table_rsdp *rsdp; u32 table_entry_size; u32 i; u32 table_count; struct acpi_table_header *table; acpi_physical_address address; u32 length; u8 *table_entry; acpi_status status; u32 table_index; ACPI_FUNCTION_TRACE(tb_parse_root_table); /* Map the entire RSDP and extract the address of the RSDT or XSDT */ rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp)); if (!rsdp) { return_ACPI_STATUS(AE_NO_MEMORY); } acpi_tb_print_table_header(rsdp_address, ACPI_CAST_PTR(struct acpi_table_header, rsdp)); /* Use XSDT if present and not overridden. Otherwise, use RSDT */ if ((rsdp->revision > 1) && rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) { /* * RSDP contains an XSDT (64-bit physical addresses). We must use * the XSDT if the revision is > 1 and the XSDT pointer is present, * as per the ACPI specification. */ address = (acpi_physical_address)rsdp->xsdt_physical_address; table_entry_size = ACPI_XSDT_ENTRY_SIZE; } else { /* Root table is an RSDT (32-bit physical addresses) */ address = (acpi_physical_address)rsdp->rsdt_physical_address; table_entry_size = ACPI_RSDT_ENTRY_SIZE; } /* * It is not possible to map more than one entry in some environments, * so unmap the RSDP here before mapping other tables */ acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp)); /* Map the RSDT/XSDT table header to get the full table length */ table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); if (!table) { return_ACPI_STATUS(AE_NO_MEMORY); } acpi_tb_print_table_header(address, table); /* * Validate length of the table, and map entire table. * Minimum length table must contain at least one entry. */ length = table->length; acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); if (length < (sizeof(struct acpi_table_header) + table_entry_size)) { ACPI_BIOS_ERROR((AE_INFO, "Invalid table length 0x%X in RSDT/XSDT", length)); return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); } table = acpi_os_map_memory(address, length); if (!table) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Validate the root table checksum */ status = acpi_ut_verify_checksum(table, length); if (ACPI_FAILURE(status)) { acpi_os_unmap_memory(table, length); return_ACPI_STATUS(status); } /* Get the number of entries and pointer to first entry */ table_count = (u32)((table->length - sizeof(struct acpi_table_header)) / table_entry_size); table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header)); /* Initialize the root table array from the RSDT/XSDT */ for (i = 0; i < table_count; i++) { /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */ address = acpi_tb_get_root_table_entry(table_entry, table_entry_size); /* Skip NULL entries in RSDT/XSDT */ if (!address) { goto next_table; } status = acpi_tb_install_standard_table(address, ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, TRUE, &table_index); if (ACPI_SUCCESS(status) && ACPI_COMPARE_NAMESEG(&acpi_gbl_root_table_list. tables[table_index].signature, ACPI_SIG_FADT)) { acpi_gbl_fadt_index = table_index; acpi_tb_parse_fadt(); } next_table: table_entry += table_entry_size; } acpi_os_unmap_memory(table, length); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_tb_get_table * * PARAMETERS: table_desc - Table descriptor * out_table - Where the pointer to the table is returned * * RETURN: Status and pointer to the requested table * * DESCRIPTION: Increase a reference to a table descriptor and return the * validated table pointer. * If the table descriptor is an entry of the root table list, * this API must be invoked with ACPI_MTX_TABLES acquired. * ******************************************************************************/ acpi_status acpi_tb_get_table(struct acpi_table_desc *table_desc, struct acpi_table_header **out_table) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_tb_get_table); if (table_desc->validation_count == 0) { /* Table need to be "VALIDATED" */ status = acpi_tb_validate_table(table_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) { table_desc->validation_count++; /* * Detect validation_count overflows to ensure that the warning * message will only be printed once. */ if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) { ACPI_WARNING((AE_INFO, "Table %p, Validation count overflows\n", table_desc)); } } *out_table = table_desc->pointer; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_tb_put_table * * PARAMETERS: table_desc - Table descriptor * * RETURN: None * * DESCRIPTION: Decrease a reference to a table descriptor and release the * validated table pointer if no references. * If the table descriptor is an entry of the root table list, * this API must be invoked with ACPI_MTX_TABLES acquired. * ******************************************************************************/ void acpi_tb_put_table(struct acpi_table_desc *table_desc) { ACPI_FUNCTION_TRACE(acpi_tb_put_table); if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) { table_desc->validation_count--; /* * Detect validation_count underflows to ensure that the warning * message will only be printed once. */ if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) { ACPI_WARNING((AE_INFO, "Table %p, Validation count underflows\n", table_desc)); return_VOID; } } if (table_desc->validation_count == 0) { /* Table need to be "INVALIDATED" */ acpi_tb_invalidate_table(table_desc); } return_VOID; }
linux-master
drivers/acpi/acpica/tbutils.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: rsaddr - Address resource descriptors (16/32/64) * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rsaddr") /******************************************************************************* * * acpi_rs_convert_address16 - All WORD (16-bit) address resources * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_address16[5] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS16, ACPI_RS_SIZE(struct acpi_resource_address16), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address16)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS16, sizeof(struct aml_resource_address16), 0}, /* Resource Type, General Flags, and Type-Specific Flags */ {ACPI_RSC_ADDRESS, 0, 0, 0}, /* * These fields are contiguous in both the source and destination: * Address Granularity * Address Range Minimum * Address Range Maximum * Address Translation Offset * Address Length */ {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.address16.address.granularity), AML_OFFSET(address16.granularity), 5}, /* Optional resource_source (Index and String) */ {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address16.resource_source), 0, sizeof(struct aml_resource_address16)} }; /******************************************************************************* * * acpi_rs_convert_address32 - All DWORD (32-bit) address resources * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_address32[5] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS32, ACPI_RS_SIZE(struct acpi_resource_address32), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address32)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS32, sizeof(struct aml_resource_address32), 0}, /* Resource Type, General Flags, and Type-Specific Flags */ {ACPI_RSC_ADDRESS, 0, 0, 0}, /* * These fields are contiguous in both the source and destination: * Address Granularity * Address Range Minimum * Address Range Maximum * Address Translation Offset * Address Length */ {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.address32.address.granularity), AML_OFFSET(address32.granularity), 5}, /* Optional resource_source (Index and String) */ {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address32.resource_source), 0, sizeof(struct aml_resource_address32)} }; /******************************************************************************* * * acpi_rs_convert_address64 - All QWORD (64-bit) address resources * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_address64[5] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS64, ACPI_RS_SIZE(struct acpi_resource_address64), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address64)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS64, sizeof(struct aml_resource_address64), 0}, /* Resource Type, General Flags, and Type-Specific Flags */ {ACPI_RSC_ADDRESS, 0, 0, 0}, /* * These fields are contiguous in both the source and destination: * Address Granularity * Address Range Minimum * Address Range Maximum * Address Translation Offset * Address Length */ {ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.address64.address.granularity), AML_OFFSET(address64.granularity), 5}, /* Optional resource_source (Index and String) */ {ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address64.resource_source), 0, sizeof(struct aml_resource_address64)} }; /******************************************************************************* * * acpi_rs_convert_ext_address64 - All Extended (64-bit) address resources * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_ext_address64[5] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64, ACPI_RS_SIZE(struct acpi_resource_extended_address64), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_ext_address64)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64, sizeof(struct aml_resource_extended_address64), 0}, /* Resource Type, General Flags, and Type-Specific Flags */ {ACPI_RSC_ADDRESS, 0, 0, 0}, /* Revision ID */ {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.ext_address64.revision_ID), AML_OFFSET(ext_address64.revision_ID), 1}, /* * These fields are contiguous in both the source and destination: * Address Granularity * Address Range Minimum * Address Range Maximum * Address Translation Offset * Address Length * Type-Specific Attribute */ {ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.ext_address64.address.granularity), AML_OFFSET(ext_address64.granularity), 6} }; /******************************************************************************* * * acpi_rs_convert_general_flags - Flags common to all address descriptors * ******************************************************************************/ static struct acpi_rsconvert_info acpi_rs_convert_general_flags[6] = { {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.flags), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_general_flags)}, /* Resource Type (Memory, Io, bus_number, etc.) */ {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.address.resource_type), AML_OFFSET(address.resource_type), 1}, /* General flags - Consume, Decode, min_fixed, max_fixed */ {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.producer_consumer), AML_OFFSET(address.flags), 0}, {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.decode), AML_OFFSET(address.flags), 1}, {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.min_address_fixed), AML_OFFSET(address.flags), 2}, {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.max_address_fixed), AML_OFFSET(address.flags), 3} }; /******************************************************************************* * * acpi_rs_convert_mem_flags - Flags common to Memory address descriptors * ******************************************************************************/ static struct acpi_rsconvert_info acpi_rs_convert_mem_flags[5] = { {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_mem_flags)}, /* Memory-specific flags */ {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.write_protect), AML_OFFSET(address.specific_flags), 0}, {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.caching), AML_OFFSET(address.specific_flags), 1}, {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.range_type), AML_OFFSET(address.specific_flags), 3}, {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.translation), AML_OFFSET(address.specific_flags), 5} }; /******************************************************************************* * * acpi_rs_convert_io_flags - Flags common to I/O address descriptors * ******************************************************************************/ static struct acpi_rsconvert_info acpi_rs_convert_io_flags[4] = { {ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_io_flags)}, /* I/O-specific flags */ {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.io.range_type), AML_OFFSET(address.specific_flags), 0}, {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.io.translation), AML_OFFSET(address.specific_flags), 4}, {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.io.translation_type), AML_OFFSET(address.specific_flags), 5} }; /******************************************************************************* * * FUNCTION: acpi_rs_get_address_common * * PARAMETERS: resource - Pointer to the internal resource struct * aml - Pointer to the AML resource descriptor * * RETURN: TRUE if the resource_type field is OK, FALSE otherwise * * DESCRIPTION: Convert common flag fields from a raw AML resource descriptor * to an internal resource descriptor * ******************************************************************************/ u8 acpi_rs_get_address_common(struct acpi_resource *resource, union aml_resource *aml) { struct aml_resource_address address; ACPI_FUNCTION_ENTRY(); /* Avoid undefined behavior: member access within misaligned address */ memcpy(&address, aml, sizeof(address)); /* Validate the Resource Type */ if ((address.resource_type > 2) && (address.resource_type < 0xC0)) { return (FALSE); } /* Get the Resource Type and General Flags */ (void)acpi_rs_convert_aml_to_resource(resource, aml, acpi_rs_convert_general_flags); /* Get the Type-Specific Flags (Memory and I/O descriptors only) */ if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) { (void)acpi_rs_convert_aml_to_resource(resource, aml, acpi_rs_convert_mem_flags); } else if (resource->data.address.resource_type == ACPI_IO_RANGE) { (void)acpi_rs_convert_aml_to_resource(resource, aml, acpi_rs_convert_io_flags); } else { /* Generic resource type, just grab the type_specific byte */ resource->data.address.info.type_specific = address.specific_flags; } return (TRUE); } /******************************************************************************* * * FUNCTION: acpi_rs_set_address_common * * PARAMETERS: aml - Pointer to the AML resource descriptor * resource - Pointer to the internal resource struct * * RETURN: None * * DESCRIPTION: Convert common flag fields from a resource descriptor to an * AML descriptor * ******************************************************************************/ void acpi_rs_set_address_common(union aml_resource *aml, struct acpi_resource *resource) { ACPI_FUNCTION_ENTRY(); /* Set the Resource Type and General Flags */ (void)acpi_rs_convert_resource_to_aml(resource, aml, acpi_rs_convert_general_flags); /* Set the Type-Specific Flags (Memory and I/O descriptors only) */ if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) { (void)acpi_rs_convert_resource_to_aml(resource, aml, acpi_rs_convert_mem_flags); } else if (resource->data.address.resource_type == ACPI_IO_RANGE) { (void)acpi_rs_convert_resource_to_aml(resource, aml, acpi_rs_convert_io_flags); } else { /* Generic resource type, just copy the type_specific byte */ aml->address.specific_flags = resource->data.address.info.type_specific; } }
linux-master
drivers/acpi/acpica/rsaddr.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: nsobject - Utilities for objects attached to namespace * table entries * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsobject") /******************************************************************************* * * FUNCTION: acpi_ns_attach_object * * PARAMETERS: node - Parent Node * object - Object to be attached * type - Type of object, or ACPI_TYPE_ANY if not * known * * RETURN: Status * * DESCRIPTION: Record the given object as the value associated with the * name whose acpi_handle is passed. If Object is NULL * and Type is ACPI_TYPE_ANY, set the name as having no value. * Note: Future may require that the Node->Flags field be passed * as a parameter. * * MUTEX: Assumes namespace is locked * ******************************************************************************/ acpi_status acpi_ns_attach_object(struct acpi_namespace_node *node, union acpi_operand_object *object, acpi_object_type type) { union acpi_operand_object *obj_desc; union acpi_operand_object *last_obj_desc; acpi_object_type object_type = ACPI_TYPE_ANY; ACPI_FUNCTION_TRACE(ns_attach_object); /* * Parameter validation */ if (!node) { /* Invalid handle */ ACPI_ERROR((AE_INFO, "Null NamedObj handle")); return_ACPI_STATUS(AE_BAD_PARAMETER); } if (!object && (ACPI_TYPE_ANY != type)) { /* Null object */ ACPI_ERROR((AE_INFO, "Null object, but type not ACPI_TYPE_ANY")); return_ACPI_STATUS(AE_BAD_PARAMETER); } if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) { /* Not a name handle */ ACPI_ERROR((AE_INFO, "Invalid handle %p [%s]", node, acpi_ut_get_descriptor_name(node))); return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Check if this object is already attached */ if (node->object == object) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj %p already installed in NameObj %p\n", object, node)); return_ACPI_STATUS(AE_OK); } /* If null object, we will just install it */ if (!object) { obj_desc = NULL; object_type = ACPI_TYPE_ANY; } /* * If the source object is a namespace Node with an attached object, * we will use that (attached) object */ else if ((ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) && ((struct acpi_namespace_node *)object)->object) { /* * Value passed is a name handle and that name has a * non-null value. Use that name's value and type. */ obj_desc = ((struct acpi_namespace_node *)object)->object; object_type = ((struct acpi_namespace_node *)object)->type; } /* * Otherwise, we will use the parameter object, but we must type * it first */ else { obj_desc = (union acpi_operand_object *)object; /* Use the given type */ object_type = type; } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n", obj_desc, node, acpi_ut_get_node_name(node))); /* Detach an existing attached object if present */ if (node->object) { acpi_ns_detach_object(node); } if (obj_desc) { /* * Must increment the new value's reference count * (if it is an internal object) */ acpi_ut_add_reference(obj_desc); /* * Handle objects with multiple descriptors - walk * to the end of the descriptor list */ last_obj_desc = obj_desc; while (last_obj_desc->common.next_object) { last_obj_desc = last_obj_desc->common.next_object; } /* Install the object at the front of the object list */ last_obj_desc->common.next_object = node->object; } node->type = (u8) object_type; node->object = obj_desc; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_detach_object * * PARAMETERS: node - A Namespace node whose object will be detached * * RETURN: None. * * DESCRIPTION: Detach/delete an object associated with a namespace node. * if the object is an allocated object, it is freed. * Otherwise, the field is simply cleared. * ******************************************************************************/ void acpi_ns_detach_object(struct acpi_namespace_node *node) { union acpi_operand_object *obj_desc; ACPI_FUNCTION_TRACE(ns_detach_object); obj_desc = node->object; if (!obj_desc || (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) { return_VOID; } if (node->flags & ANOBJ_ALLOCATED_BUFFER) { /* Free the dynamic aml buffer */ if (obj_desc->common.type == ACPI_TYPE_METHOD) { ACPI_FREE(obj_desc->method.aml_start); } } if (obj_desc->common.type == ACPI_TYPE_REGION) { acpi_ut_remove_address_range(obj_desc->region.space_id, node); } /* Clear the Node entry in all cases */ node->object = NULL; if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) { /* Unlink object from front of possible object list */ node->object = obj_desc->common.next_object; /* Handle possible 2-descriptor object */ if (node->object && (node->object->common.type != ACPI_TYPE_LOCAL_DATA)) { node->object = node->object->common.next_object; } /* * Detach the object from any data objects (which are still held by * the namespace node) */ if (obj_desc->common.next_object && ((obj_desc->common.next_object)->common.type == ACPI_TYPE_LOCAL_DATA)) { obj_desc->common.next_object = NULL; } } /* Reset the node type to untyped */ node->type = ACPI_TYPE_ANY; ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n", node, acpi_ut_get_node_name(node), obj_desc)); /* Remove one reference on the object (and all subobjects) */ acpi_ut_remove_reference(obj_desc); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ns_get_attached_object * * PARAMETERS: node - Namespace node * * RETURN: Current value of the object field from the Node whose * handle is passed * * DESCRIPTION: Obtain the object attached to a namespace node. * ******************************************************************************/ union acpi_operand_object *acpi_ns_get_attached_object(struct acpi_namespace_node *node) { ACPI_FUNCTION_TRACE_PTR(ns_get_attached_object, node); if (!node) { ACPI_WARNING((AE_INFO, "Null Node ptr")); return_PTR(NULL); } if (!node->object || ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND) && (ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_NAMED)) || ((node->object)->common.type == ACPI_TYPE_LOCAL_DATA)) { return_PTR(NULL); } return_PTR(node->object); } /******************************************************************************* * * FUNCTION: acpi_ns_get_secondary_object * * PARAMETERS: node - Namespace node * * RETURN: Current value of the object field from the Node whose * handle is passed. * * DESCRIPTION: Obtain a secondary object associated with a namespace node. * ******************************************************************************/ union acpi_operand_object *acpi_ns_get_secondary_object(union acpi_operand_object *obj_desc) { ACPI_FUNCTION_TRACE_PTR(ns_get_secondary_object, obj_desc); if ((!obj_desc) || (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) || (!obj_desc->common.next_object) || ((obj_desc->common.next_object)->common.type == ACPI_TYPE_LOCAL_DATA)) { return_PTR(NULL); } return_PTR(obj_desc->common.next_object); } /******************************************************************************* * * FUNCTION: acpi_ns_attach_data * * PARAMETERS: node - Namespace node * handler - Handler to be associated with the data * data - Data to be attached * * RETURN: Status * * DESCRIPTION: Low-level attach data. Create and attach a Data object. * ******************************************************************************/ acpi_status acpi_ns_attach_data(struct acpi_namespace_node *node, acpi_object_handler handler, void *data) { union acpi_operand_object *prev_obj_desc; union acpi_operand_object *obj_desc; union acpi_operand_object *data_desc; /* We only allow one attachment per handler */ prev_obj_desc = NULL; obj_desc = node->object; while (obj_desc) { if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && (obj_desc->data.handler == handler)) { return (AE_ALREADY_EXISTS); } prev_obj_desc = obj_desc; obj_desc = obj_desc->common.next_object; } /* Create an internal object for the data */ data_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_DATA); if (!data_desc) { return (AE_NO_MEMORY); } data_desc->data.handler = handler; data_desc->data.pointer = data; /* Install the data object */ if (prev_obj_desc) { prev_obj_desc->common.next_object = data_desc; } else { node->object = data_desc; } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_detach_data * * PARAMETERS: node - Namespace node * handler - Handler associated with the data * * RETURN: Status * * DESCRIPTION: Low-level detach data. Delete the data node, but the caller * is responsible for the actual data. * ******************************************************************************/ acpi_status acpi_ns_detach_data(struct acpi_namespace_node *node, acpi_object_handler handler) { union acpi_operand_object *obj_desc; union acpi_operand_object *prev_obj_desc; prev_obj_desc = NULL; obj_desc = node->object; while (obj_desc) { if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && (obj_desc->data.handler == handler)) { if (prev_obj_desc) { prev_obj_desc->common.next_object = obj_desc->common.next_object; } else { node->object = obj_desc->common.next_object; } acpi_ut_remove_reference(obj_desc); return (AE_OK); } prev_obj_desc = obj_desc; obj_desc = obj_desc->common.next_object; } return (AE_NOT_FOUND); } /******************************************************************************* * * FUNCTION: acpi_ns_get_attached_data * * PARAMETERS: node - Namespace node * handler - Handler associated with the data * data - Where the data is returned * * RETURN: Status * * DESCRIPTION: Low level interface to obtain data previously associated with * a namespace node. * ******************************************************************************/ acpi_status acpi_ns_get_attached_data(struct acpi_namespace_node *node, acpi_object_handler handler, void **data) { union acpi_operand_object *obj_desc; obj_desc = node->object; while (obj_desc) { if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) && (obj_desc->data.handler == handler)) { *data = obj_desc->data.pointer; return (AE_OK); } obj_desc = obj_desc->common.next_object; } return (AE_NOT_FOUND); }
linux-master
drivers/acpi/acpica/nsobject.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: dsutils - Dispatcher utilities * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "amlcode.h" #include "acdispat.h" #include "acinterp.h" #include "acnamesp.h" #include "acdebug.h" #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dsutils") /******************************************************************************* * * FUNCTION: acpi_ds_clear_implicit_return * * PARAMETERS: walk_state - Current State * * RETURN: None. * * DESCRIPTION: Clear and remove a reference on an implicit return value. Used * to delete "stale" return values (if enabled, the return value * from every operator is saved at least momentarily, in case the * parent method exits.) * ******************************************************************************/ void acpi_ds_clear_implicit_return(struct acpi_walk_state *walk_state) { ACPI_FUNCTION_NAME(ds_clear_implicit_return); /* * Slack must be enabled for this feature */ if (!acpi_gbl_enable_interpreter_slack) { return; } if (walk_state->implicit_return_obj) { /* * Delete any "stale" implicit return. However, in * complex statements, the implicit return value can be * bubbled up several levels. */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Removing reference on stale implicit return obj %p\n", walk_state->implicit_return_obj)); acpi_ut_remove_reference(walk_state->implicit_return_obj); walk_state->implicit_return_obj = NULL; } } /******************************************************************************* * * FUNCTION: acpi_ds_do_implicit_return * * PARAMETERS: return_desc - The return value * walk_state - Current State * add_reference - True if a reference should be added to the * return object * * RETURN: TRUE if implicit return enabled, FALSE otherwise * * DESCRIPTION: Implements the optional "implicit return". We save the result * of every ASL operator and control method invocation in case the * parent method exit. Before storing a new return value, we * delete the previous return value. * ******************************************************************************/ u8 acpi_ds_do_implicit_return(union acpi_operand_object *return_desc, struct acpi_walk_state *walk_state, u8 add_reference) { ACPI_FUNCTION_NAME(ds_do_implicit_return); /* * Slack must be enabled for this feature, and we must * have a valid return object */ if ((!acpi_gbl_enable_interpreter_slack) || (!return_desc)) { return (FALSE); } ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Result %p will be implicitly returned; Prev=%p\n", return_desc, walk_state->implicit_return_obj)); /* * Delete any "stale" implicit return value first. However, in * complex statements, the implicit return value can be * bubbled up several levels, so we don't clear the value if it * is the same as the return_desc. */ if (walk_state->implicit_return_obj) { if (walk_state->implicit_return_obj == return_desc) { return (TRUE); } acpi_ds_clear_implicit_return(walk_state); } /* Save the implicit return value, add a reference if requested */ walk_state->implicit_return_obj = return_desc; if (add_reference) { acpi_ut_add_reference(return_desc); } return (TRUE); } /******************************************************************************* * * FUNCTION: acpi_ds_is_result_used * * PARAMETERS: op - Current Op * walk_state - Current State * * RETURN: TRUE if result is used, FALSE otherwise * * DESCRIPTION: Check if a result object will be used by the parent * ******************************************************************************/ u8 acpi_ds_is_result_used(union acpi_parse_object * op, struct acpi_walk_state * walk_state) { const struct acpi_opcode_info *parent_info; ACPI_FUNCTION_TRACE_PTR(ds_is_result_used, op); /* Must have both an Op and a Result Object */ if (!op) { ACPI_ERROR((AE_INFO, "Null Op")); return_UINT8(TRUE); } /* * We know that this operator is not a * Return() operator (would not come here.) The following code is the * optional support for a so-called "implicit return". Some AML code * assumes that the last value of the method is "implicitly" returned * to the caller. Just save the last result as the return value. * NOTE: this is optional because the ASL language does not actually * support this behavior. */ (void)acpi_ds_do_implicit_return(walk_state->result_obj, walk_state, TRUE); /* * Now determine if the parent will use the result * * If there is no parent, or the parent is a scope_op, we are executing * at the method level. An executing method typically has no parent, * since each method is parsed separately. A method invoked externally * via execute_control_method has a scope_op as the parent. */ if ((!op->common.parent) || (op->common.parent->common.aml_opcode == AML_SCOPE_OP)) { /* No parent, the return value cannot possibly be used */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "At Method level, result of [%s] not used\n", acpi_ps_get_opcode_name(op->common. aml_opcode))); return_UINT8(FALSE); } /* Get info on the parent. The root_op is AML_SCOPE */ parent_info = acpi_ps_get_opcode_info(op->common.parent->common.aml_opcode); if (parent_info->class == AML_CLASS_UNKNOWN) { ACPI_ERROR((AE_INFO, "Unknown parent opcode Op=%p", op)); return_UINT8(FALSE); } /* * Decide what to do with the result based on the parent. If * the parent opcode will not use the result, delete the object. * Otherwise leave it as is, it will be deleted when it is used * as an operand later. */ switch (parent_info->class) { case AML_CLASS_CONTROL: switch (op->common.parent->common.aml_opcode) { case AML_RETURN_OP: /* Never delete the return value associated with a return opcode */ goto result_used; case AML_IF_OP: case AML_WHILE_OP: /* * If we are executing the predicate AND this is the predicate op, * we will use the return value */ if ((walk_state->control_state->common.state == ACPI_CONTROL_PREDICATE_EXECUTING) && (walk_state->control_state->control.predicate_op == op)) { goto result_used; } break; default: /* Ignore other control opcodes */ break; } /* The general control opcode returns no result */ goto result_not_used; case AML_CLASS_CREATE: /* * These opcodes allow term_arg(s) as operands and therefore * the operands can be method calls. The result is used. */ goto result_used; case AML_CLASS_NAMED_OBJECT: if ((op->common.parent->common.aml_opcode == AML_REGION_OP) || (op->common.parent->common.aml_opcode == AML_DATA_REGION_OP) || (op->common.parent->common.aml_opcode == AML_PACKAGE_OP) || (op->common.parent->common.aml_opcode == AML_BUFFER_OP) || (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP) || (op->common.parent->common.aml_opcode == AML_INT_EVAL_SUBTREE_OP) || (op->common.parent->common.aml_opcode == AML_BANK_FIELD_OP)) { /* * These opcodes allow term_arg(s) as operands and therefore * the operands can be method calls. The result is used. */ goto result_used; } goto result_not_used; default: /* * In all other cases. the parent will actually use the return * object, so keep it. */ goto result_used; } result_used: ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Result of [%s] used by Parent [%s] Op=%p\n", acpi_ps_get_opcode_name(op->common.aml_opcode), acpi_ps_get_opcode_name(op->common.parent->common. aml_opcode), op)); return_UINT8(TRUE); result_not_used: ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Result of [%s] not used by Parent [%s] Op=%p\n", acpi_ps_get_opcode_name(op->common.aml_opcode), acpi_ps_get_opcode_name(op->common.parent->common. aml_opcode), op)); return_UINT8(FALSE); } /******************************************************************************* * * FUNCTION: acpi_ds_delete_result_if_not_used * * PARAMETERS: op - Current parse Op * result_obj - Result of the operation * walk_state - Current state * * RETURN: Status * * DESCRIPTION: Used after interpretation of an opcode. If there is an internal * result descriptor, check if the parent opcode will actually use * this result. If not, delete the result now so that it will * not become orphaned. * ******************************************************************************/ void acpi_ds_delete_result_if_not_used(union acpi_parse_object *op, union acpi_operand_object *result_obj, struct acpi_walk_state *walk_state) { union acpi_operand_object *obj_desc; acpi_status status; ACPI_FUNCTION_TRACE_PTR(ds_delete_result_if_not_used, result_obj); if (!op) { ACPI_ERROR((AE_INFO, "Null Op")); return_VOID; } if (!result_obj) { return_VOID; } if (!acpi_ds_is_result_used(op, walk_state)) { /* Must pop the result stack (obj_desc should be equal to result_obj) */ status = acpi_ds_result_pop(&obj_desc, walk_state); if (ACPI_SUCCESS(status)) { acpi_ut_remove_reference(result_obj); } } return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ds_resolve_operands * * PARAMETERS: walk_state - Current walk state with operands on stack * * RETURN: Status * * DESCRIPTION: Resolve all operands to their values. Used to prepare * arguments to a control method invocation (a call from one * method to another.) * ******************************************************************************/ acpi_status acpi_ds_resolve_operands(struct acpi_walk_state *walk_state) { u32 i; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE_PTR(ds_resolve_operands, walk_state); /* * Attempt to resolve each of the valid operands * Method arguments are passed by reference, not by value. This means * that the actual objects are passed, not copies of the objects. */ for (i = 0; i < walk_state->num_operands; i++) { status = acpi_ex_resolve_to_value(&walk_state->operands[i], walk_state); if (ACPI_FAILURE(status)) { break; } } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_clear_operands * * PARAMETERS: walk_state - Current walk state with operands on stack * * RETURN: None * * DESCRIPTION: Clear all operands on the current walk state operand stack. * ******************************************************************************/ void acpi_ds_clear_operands(struct acpi_walk_state *walk_state) { u32 i; ACPI_FUNCTION_TRACE_PTR(ds_clear_operands, walk_state); /* Remove a reference on each operand on the stack */ for (i = 0; i < walk_state->num_operands; i++) { /* * Remove a reference to all operands, including both * "Arguments" and "Targets". */ acpi_ut_remove_reference(walk_state->operands[i]); walk_state->operands[i] = NULL; } walk_state->num_operands = 0; return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ds_create_operand * * PARAMETERS: walk_state - Current walk state * arg - Parse object for the argument * arg_index - Which argument (zero based) * * RETURN: Status * * DESCRIPTION: Translate a parse tree object that is an argument to an AML * opcode to the equivalent interpreter object. This may include * looking up a name or entering a new name into the internal * namespace. * ******************************************************************************/ acpi_status acpi_ds_create_operand(struct acpi_walk_state *walk_state, union acpi_parse_object *arg, u32 arg_index) { acpi_status status = AE_OK; char *name_string; u32 name_length; union acpi_operand_object *obj_desc; union acpi_parse_object *parent_op; u16 opcode; acpi_interpreter_mode interpreter_mode; const struct acpi_opcode_info *op_info; ACPI_FUNCTION_TRACE_PTR(ds_create_operand, arg); /* A valid name must be looked up in the namespace */ if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) && (arg->common.value.string) && !(arg->common.flags & ACPI_PARSEOP_IN_STACK)) { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", arg)); /* Get the entire name string from the AML stream */ status = acpi_ex_get_name_string(ACPI_TYPE_ANY, arg->common.value.buffer, &name_string, &name_length); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* All prefixes have been handled, and the name is in name_string */ /* * Special handling for buffer_field declarations. This is a deferred * opcode that unfortunately defines the field name as the last * parameter instead of the first. We get here when we are performing * the deferred execution, so the actual name of the field is already * in the namespace. We don't want to attempt to look it up again * because we may be executing in a different scope than where the * actual opcode exists. */ if ((walk_state->deferred_node) && (walk_state->deferred_node->type == ACPI_TYPE_BUFFER_FIELD) && (arg_index == (u32) ((walk_state->opcode == AML_CREATE_FIELD_OP) ? 3 : 2))) { obj_desc = ACPI_CAST_PTR(union acpi_operand_object, walk_state->deferred_node); status = AE_OK; } else { /* All other opcodes */ /* * Differentiate between a namespace "create" operation * versus a "lookup" operation (IMODE_LOAD_PASS2 vs. * IMODE_EXECUTE) in order to support the creation of * namespace objects during the execution of control methods. */ parent_op = arg->common.parent; op_info = acpi_ps_get_opcode_info(parent_op->common. aml_opcode); if ((op_info->flags & AML_NSNODE) && (parent_op->common.aml_opcode != AML_INT_METHODCALL_OP) && (parent_op->common.aml_opcode != AML_REGION_OP) && (parent_op->common.aml_opcode != AML_INT_NAMEPATH_OP)) { /* Enter name into namespace if not found */ interpreter_mode = ACPI_IMODE_LOAD_PASS2; } else { /* Return a failure if name not found */ interpreter_mode = ACPI_IMODE_EXECUTE; } status = acpi_ns_lookup(walk_state->scope_info, name_string, ACPI_TYPE_ANY, interpreter_mode, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, walk_state, ACPI_CAST_INDIRECT_PTR(struct acpi_namespace_node, &obj_desc)); /* * The only case where we pass through (ignore) a NOT_FOUND * error is for the cond_ref_of opcode. */ if (status == AE_NOT_FOUND) { if (parent_op->common.aml_opcode == AML_CONDITIONAL_REF_OF_OP) { /* * For the Conditional Reference op, it's OK if * the name is not found; We just need a way to * indicate this to the interpreter, set the * object to the root */ obj_desc = ACPI_CAST_PTR(union acpi_operand_object, acpi_gbl_root_node); status = AE_OK; } else if (parent_op->common.aml_opcode == AML_EXTERNAL_OP) { /* * This opcode should never appear here. It is used only * by AML disassemblers and is surrounded by an If(0) * by the ASL compiler. * * Therefore, if we see it here, it is a serious error. */ status = AE_AML_BAD_OPCODE; } else { /* * We just plain didn't find it -- which is a * very serious error at this point */ status = AE_AML_NAME_NOT_FOUND; } } if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, name_string, status); } } /* Free the namestring created above */ ACPI_FREE(name_string); /* Check status from the lookup */ if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Put the resulting object onto the current object stack */ status = acpi_ds_obj_stack_push(obj_desc, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_db_display_argument_object(obj_desc, walk_state); } else { /* Check for null name case */ if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) && !(arg->common.flags & ACPI_PARSEOP_IN_STACK)) { /* * If the name is null, this means that this is an * optional result parameter that was not specified * in the original ASL. Create a Zero Constant for a * placeholder. (Store to a constant is a Noop.) */ opcode = AML_ZERO_OP; /* Has no arguments! */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Null namepath: Arg=%p\n", arg)); } else { opcode = arg->common.aml_opcode; } /* Get the object type of the argument */ op_info = acpi_ps_get_opcode_info(opcode); if (op_info->object_type == ACPI_TYPE_INVALID) { return_ACPI_STATUS(AE_NOT_IMPLEMENTED); } if ((op_info->flags & AML_HAS_RETVAL) || (arg->common.flags & ACPI_PARSEOP_IN_STACK)) { /* * Use value that was already previously returned * by the evaluation of this argument */ status = acpi_ds_result_pop(&obj_desc, walk_state); if (ACPI_FAILURE(status)) { /* * Only error is underflow, and this indicates * a missing or null operand! */ ACPI_EXCEPTION((AE_INFO, status, "Missing or null operand")); return_ACPI_STATUS(status); } } else { /* Create an ACPI_INTERNAL_OBJECT for the argument */ obj_desc = acpi_ut_create_internal_object(op_info-> object_type); if (!obj_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Initialize the new object */ status = acpi_ds_init_object_from_op(walk_state, arg, opcode, &obj_desc); if (ACPI_FAILURE(status)) { acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(status); } } /* Put the operand object on the object stack */ status = acpi_ds_obj_stack_push(obj_desc, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_db_display_argument_object(obj_desc, walk_state); } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_create_operands * * PARAMETERS: walk_state - Current state * first_arg - First argument of a parser argument tree * * RETURN: Status * * DESCRIPTION: Convert an operator's arguments from a parse tree format to * namespace objects and place those argument object on the object * stack in preparation for evaluation by the interpreter. * ******************************************************************************/ acpi_status acpi_ds_create_operands(struct acpi_walk_state *walk_state, union acpi_parse_object *first_arg) { acpi_status status = AE_OK; union acpi_parse_object *arg; union acpi_parse_object *arguments[ACPI_OBJ_NUM_OPERANDS]; u32 arg_count = 0; u32 index = walk_state->num_operands; u32 i; ACPI_FUNCTION_TRACE_PTR(ds_create_operands, first_arg); /* Get all arguments in the list */ arg = first_arg; while (arg) { if (index >= ACPI_OBJ_NUM_OPERANDS) { return_ACPI_STATUS(AE_BAD_DATA); } arguments[index] = arg; walk_state->operands[index] = NULL; /* Move on to next argument, if any */ arg = arg->common.next; arg_count++; index++; } ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "NumOperands %d, ArgCount %d, Index %d\n", walk_state->num_operands, arg_count, index)); /* Create the interpreter arguments, in reverse order */ index--; for (i = 0; i < arg_count; i++) { arg = arguments[index]; walk_state->operand_index = (u8)index; status = acpi_ds_create_operand(walk_state, arg, index); if (ACPI_FAILURE(status)) { goto cleanup; } ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Created Arg #%u (%p) %u args total\n", index, arg, arg_count)); index--; } return_ACPI_STATUS(status); cleanup: /* * We must undo everything done above; meaning that we must * pop everything off of the operand stack and delete those * objects */ acpi_ds_obj_stack_pop_and_delete(arg_count, walk_state); ACPI_EXCEPTION((AE_INFO, status, "While creating Arg %u", index)); return_ACPI_STATUS(status); } /***************************************************************************** * * FUNCTION: acpi_ds_evaluate_name_path * * PARAMETERS: walk_state - Current state of the parse tree walk, * the opcode of current operation should be * AML_INT_NAMEPATH_OP * * RETURN: Status * * DESCRIPTION: Translate the -name_path- parse tree object to the equivalent * interpreter object, convert it to value, if needed, duplicate * it, if needed, and push it onto the current result stack. * ****************************************************************************/ acpi_status acpi_ds_evaluate_name_path(struct acpi_walk_state *walk_state) { acpi_status status = AE_OK; union acpi_parse_object *op = walk_state->op; union acpi_operand_object **operand = &walk_state->operands[0]; union acpi_operand_object *new_obj_desc; u8 type; ACPI_FUNCTION_TRACE_PTR(ds_evaluate_name_path, walk_state); if (!op->common.parent) { /* This happens after certain exception processing */ goto exit; } if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) || (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP) || (op->common.parent->common.aml_opcode == AML_REF_OF_OP)) { /* TBD: Should we specify this feature as a bit of op_info->Flags of these opcodes? */ goto exit; } status = acpi_ds_create_operand(walk_state, op, 0); if (ACPI_FAILURE(status)) { goto exit; } if (op->common.flags & ACPI_PARSEOP_TARGET) { new_obj_desc = *operand; goto push_result; } type = (*operand)->common.type; status = acpi_ex_resolve_to_value(operand, walk_state); if (ACPI_FAILURE(status)) { goto exit; } if (type == ACPI_TYPE_INTEGER) { /* It was incremented by acpi_ex_resolve_to_value */ acpi_ut_remove_reference(*operand); status = acpi_ut_copy_iobject_to_iobject(*operand, &new_obj_desc, walk_state); if (ACPI_FAILURE(status)) { goto exit; } } else { /* * The object either was anew created or is * a Namespace node - don't decrement it. */ new_obj_desc = *operand; } /* Cleanup for name-path operand */ status = acpi_ds_obj_stack_pop(1, walk_state); if (ACPI_FAILURE(status)) { walk_state->result_obj = new_obj_desc; goto exit; } push_result: walk_state->result_obj = new_obj_desc; status = acpi_ds_result_push(walk_state->result_obj, walk_state); if (ACPI_SUCCESS(status)) { /* Force to take it from stack */ op->common.flags |= ACPI_PARSEOP_IN_STACK; } exit: return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/dsutils.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: evhandler - Support for Address Space handlers * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #include "acnamesp.h" #include "acinterp.h" #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evhandler") /* Local prototypes */ static acpi_status acpi_ev_install_handler(acpi_handle obj_handle, u32 level, void *context, void **return_value); /* These are the address spaces that will get default handlers */ u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = { ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_ADR_SPACE_SYSTEM_IO, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_ADR_SPACE_DATA_TABLE }; /******************************************************************************* * * FUNCTION: acpi_ev_install_region_handlers * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Installs the core subsystem default address space handlers. * ******************************************************************************/ acpi_status acpi_ev_install_region_handlers(void) { acpi_status status; u32 i; ACPI_FUNCTION_TRACE(ev_install_region_handlers); status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * All address spaces (PCI Config, EC, SMBus) are scope dependent and * registration must occur for a specific device. * * In the case of the system memory and IO address spaces there is * currently no device associated with the address space. For these we * use the root. * * We install the default PCI config space handler at the root so that * this space is immediately available even though the we have not * enumerated all the PCI Root Buses yet. This is to conform to the ACPI * specification which states that the PCI config space must be always * available -- even though we are nowhere near ready to find the PCI root * buses at this point. * * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler * has already been installed (via acpi_install_address_space_handler). * Similar for AE_SAME_HANDLER. */ for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { status = acpi_ev_install_space_handler(acpi_gbl_root_node, acpi_gbl_default_address_spaces [i], ACPI_DEFAULT_HANDLER, NULL, NULL); switch (status) { case AE_OK: case AE_SAME_HANDLER: case AE_ALREADY_EXISTS: /* These exceptions are all OK */ status = AE_OK; break; default: goto unlock_and_exit; } } unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_has_default_handler * * PARAMETERS: node - Namespace node for the device * space_id - The address space ID * * RETURN: TRUE if default handler is installed, FALSE otherwise * * DESCRIPTION: Check if the default handler is installed for the requested * space ID. * ******************************************************************************/ u8 acpi_ev_has_default_handler(struct acpi_namespace_node *node, acpi_adr_space_type space_id) { union acpi_operand_object *obj_desc; union acpi_operand_object *handler_obj; /* Must have an existing internal object */ obj_desc = acpi_ns_get_attached_object(node); if (obj_desc) { handler_obj = obj_desc->common_notify.handler; /* Walk the linked list of handlers for this object */ while (handler_obj) { if (handler_obj->address_space.space_id == space_id) { if (handler_obj->address_space.handler_flags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) { return (TRUE); } } handler_obj = handler_obj->address_space.next; } } return (FALSE); } /******************************************************************************* * * FUNCTION: acpi_ev_install_handler * * PARAMETERS: walk_namespace callback * * DESCRIPTION: This routine installs an address handler into objects that are * of type Region or Device. * * If the Object is a Device, and the device has a handler of * the same type then the search is terminated in that branch. * * This is because the existing handler is closer in proximity * to any more regions than the one we are trying to install. * ******************************************************************************/ static acpi_status acpi_ev_install_handler(acpi_handle obj_handle, u32 level, void *context, void **return_value) { union acpi_operand_object *handler_obj; union acpi_operand_object *next_handler_obj; union acpi_operand_object *obj_desc; struct acpi_namespace_node *node; acpi_status status; ACPI_FUNCTION_NAME(ev_install_handler); handler_obj = (union acpi_operand_object *)context; /* Parameter validation */ if (!handler_obj) { return (AE_OK); } /* Convert and validate the device handle */ node = acpi_ns_validate_handle(obj_handle); if (!node) { return (AE_BAD_PARAMETER); } /* * We only care about regions and objects that are allowed to have * address space handlers */ if ((node->type != ACPI_TYPE_DEVICE) && (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { return (AE_OK); } /* Check for an existing internal object */ obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { /* No object, just exit */ return (AE_OK); } /* Devices are handled different than regions */ if (obj_desc->common.type == ACPI_TYPE_DEVICE) { /* Check if this Device already has a handler for this address space */ next_handler_obj = acpi_ev_find_region_handler(handler_obj->address_space. space_id, obj_desc->common_notify. handler); if (next_handler_obj) { /* Found a handler, is it for the same address space? */ ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Found handler for region [%s] in device %p(%p) handler %p\n", acpi_ut_get_region_name(handler_obj-> address_space. space_id), obj_desc, next_handler_obj, handler_obj)); /* * Since the object we found it on was a device, then it means * that someone has already installed a handler for the branch * of the namespace from this device on. Just bail out telling * the walk routine to not traverse this branch. This preserves * the scoping rule for handlers. */ return (AE_CTRL_DEPTH); } /* * As long as the device didn't have a handler for this space we * don't care about it. We just ignore it and proceed. */ return (AE_OK); } /* Object is a Region */ if (obj_desc->region.space_id != handler_obj->address_space.space_id) { /* This region is for a different address space, just ignore it */ return (AE_OK); } /* * Now we have a region and it is for the handler's address space type. * * First disconnect region for any previous handler (if any) */ acpi_ev_detach_region(obj_desc, FALSE); /* Connect the region to the new handler */ status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE); return (status); } /******************************************************************************* * * FUNCTION: acpi_ev_find_region_handler * * PARAMETERS: space_id - The address space ID * handler_obj - Head of the handler object list * * RETURN: Matching handler object. NULL if space ID not matched * * DESCRIPTION: Search a handler object list for a match on the address * space ID. * ******************************************************************************/ union acpi_operand_object *acpi_ev_find_region_handler(acpi_adr_space_type space_id, union acpi_operand_object *handler_obj) { /* Walk the handler list for this device */ while (handler_obj) { /* Same space_id indicates a handler is installed */ if (handler_obj->address_space.space_id == space_id) { return (handler_obj); } /* Next handler object */ handler_obj = handler_obj->address_space.next; } return (NULL); } /******************************************************************************* * * FUNCTION: acpi_ev_install_space_handler * * PARAMETERS: node - Namespace node for the device * space_id - The address space ID * handler - Address of the handler * setup - Address of the setup function * context - Value passed to the handler on each access * * RETURN: Status * * DESCRIPTION: Install a handler for all op_regions of a given space_id. * Assumes namespace is locked * ******************************************************************************/ acpi_status acpi_ev_install_space_handler(struct acpi_namespace_node *node, acpi_adr_space_type space_id, acpi_adr_space_handler handler, acpi_adr_space_setup setup, void *context) { union acpi_operand_object *obj_desc; union acpi_operand_object *handler_obj; acpi_status status = AE_OK; acpi_object_type type; u8 flags = 0; ACPI_FUNCTION_TRACE(ev_install_space_handler); /* * This registration is valid for only the types below and the root. * The root node is where the default handlers get installed. */ if ((node->type != ACPI_TYPE_DEVICE) && (node->type != ACPI_TYPE_PROCESSOR) && (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } if (handler == ACPI_DEFAULT_HANDLER) { flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED; switch (space_id) { case ACPI_ADR_SPACE_SYSTEM_MEMORY: handler = acpi_ex_system_memory_space_handler; setup = acpi_ev_system_memory_region_setup; break; case ACPI_ADR_SPACE_SYSTEM_IO: handler = acpi_ex_system_io_space_handler; setup = acpi_ev_io_space_region_setup; break; #ifdef ACPI_PCI_CONFIGURED case ACPI_ADR_SPACE_PCI_CONFIG: handler = acpi_ex_pci_config_space_handler; setup = acpi_ev_pci_config_region_setup; break; #endif case ACPI_ADR_SPACE_CMOS: handler = acpi_ex_cmos_space_handler; setup = acpi_ev_cmos_region_setup; break; #ifdef ACPI_PCI_CONFIGURED case ACPI_ADR_SPACE_PCI_BAR_TARGET: handler = acpi_ex_pci_bar_space_handler; setup = acpi_ev_pci_bar_region_setup; break; #endif case ACPI_ADR_SPACE_DATA_TABLE: handler = acpi_ex_data_table_space_handler; setup = acpi_ev_data_table_region_setup; break; default: status = AE_BAD_PARAMETER; goto unlock_and_exit; } } /* If the caller hasn't specified a setup routine, use the default */ if (!setup) { setup = acpi_ev_default_region_setup; } /* Check for an existing internal object */ obj_desc = acpi_ns_get_attached_object(node); if (obj_desc) { /* * The attached device object already exists. Now make sure * the handler is not already installed. */ handler_obj = acpi_ev_find_region_handler(space_id, obj_desc-> common_notify. handler); if (handler_obj) { if (handler_obj->address_space.handler == handler) { /* * It is (relatively) OK to attempt to install the SAME * handler twice. This can easily happen with the * PCI_Config space. */ status = AE_SAME_HANDLER; goto unlock_and_exit; } else { /* A handler is already installed */ status = AE_ALREADY_EXISTS; } goto unlock_and_exit; } } else { ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Creating object on Device %p while installing handler\n", node)); /* obj_desc does not exist, create one */ if (node->type == ACPI_TYPE_ANY) { type = ACPI_TYPE_DEVICE; } else { type = node->type; } obj_desc = acpi_ut_create_internal_object(type); if (!obj_desc) { status = AE_NO_MEMORY; goto unlock_and_exit; } /* Init new descriptor */ obj_desc->common.type = (u8)type; /* Attach the new object to the Node */ status = acpi_ns_attach_object(node, obj_desc, type); /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); if (ACPI_FAILURE(status)) { goto unlock_and_exit; } } ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Installing address handler for region %s(%X) " "on Device %4.4s %p(%p)\n", acpi_ut_get_region_name(space_id), space_id, acpi_ut_get_node_name(node), node, obj_desc)); /* * Install the handler * * At this point there is no existing handler. Just allocate the object * for the handler and link it into the list. */ handler_obj = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER); if (!handler_obj) { status = AE_NO_MEMORY; goto unlock_and_exit; } /* Init handler obj */ status = acpi_os_create_mutex(&handler_obj->address_space.context_mutex); if (ACPI_FAILURE(status)) { acpi_ut_remove_reference(handler_obj); goto unlock_and_exit; } handler_obj->address_space.space_id = (u8)space_id; handler_obj->address_space.handler_flags = flags; handler_obj->address_space.region_list = NULL; handler_obj->address_space.node = node; handler_obj->address_space.handler = handler; handler_obj->address_space.context = context; handler_obj->address_space.setup = setup; /* Install at head of Device.address_space list */ handler_obj->address_space.next = obj_desc->common_notify.handler; /* * The Device object is the first reference on the handler_obj. * Each region that uses the handler adds a reference. */ obj_desc->common_notify.handler = handler_obj; /* * Walk the namespace finding all of the regions this handler will * manage. * * Start at the device and search the branch toward the leaf nodes * until either the leaf is encountered or a device is detected that * has an address handler of the same type. * * In either case, back up and search down the remainder of the branch */ status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, acpi_ev_install_handler, NULL, handler_obj, NULL); unlock_and_exit: return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/evhandler.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nsxfname - Public interfaces to the ACPI subsystem * ACPI Namespace oriented interfaces * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acparser.h" #include "amlcode.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsxfname") /* Local prototypes */ static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest, struct acpi_pnp_device_id *source, char *string_area); /****************************************************************************** * * FUNCTION: acpi_get_handle * * PARAMETERS: parent - Object to search under (search scope). * pathname - Pointer to an asciiz string containing the * name * ret_handle - Where the return handle is returned * * RETURN: Status * * DESCRIPTION: This routine will search for a caller specified name in the * name space. The caller can restrict the search region by * specifying a non NULL parent. The parent value is itself a * namespace handle. * ******************************************************************************/ acpi_status acpi_get_handle(acpi_handle parent, const char *pathname, acpi_handle *ret_handle) { acpi_status status; struct acpi_namespace_node *node = NULL; struct acpi_namespace_node *prefix_node = NULL; ACPI_FUNCTION_ENTRY(); /* Parameter Validation */ if (!ret_handle || !pathname) { return (AE_BAD_PARAMETER); } /* Convert a parent handle to a prefix node */ if (parent) { prefix_node = acpi_ns_validate_handle(parent); if (!prefix_node) { return (AE_BAD_PARAMETER); } } /* * Valid cases are: * 1) Fully qualified pathname * 2) Parent + Relative pathname * * Error for <null Parent + relative path> */ if (ACPI_IS_ROOT_PREFIX(pathname[0])) { /* Pathname is fully qualified (starts with '\') */ /* Special case for root-only, since we can't search for it */ if (!strcmp(pathname, ACPI_NS_ROOT_PATH)) { *ret_handle = ACPI_CAST_PTR(acpi_handle, acpi_gbl_root_node); return (AE_OK); } } else if (!prefix_node) { /* Relative path with null prefix is disallowed */ return (AE_BAD_PARAMETER); } /* Find the Node and convert to a handle */ status = acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node); if (ACPI_SUCCESS(status)) { *ret_handle = ACPI_CAST_PTR(acpi_handle, node); } return (status); } ACPI_EXPORT_SYMBOL(acpi_get_handle) /****************************************************************************** * * FUNCTION: acpi_get_name * * PARAMETERS: handle - Handle to be converted to a pathname * name_type - Full pathname or single segment * buffer - Buffer for returned path * * RETURN: Pointer to a string containing the fully qualified Name. * * DESCRIPTION: This routine returns the fully qualified name associated with * the Handle parameter. This and the acpi_pathname_to_handle are * complementary functions. * ******************************************************************************/ acpi_status acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer *buffer) { acpi_status status; /* Parameter validation */ if (name_type > ACPI_NAME_TYPE_MAX) { return (AE_BAD_PARAMETER); } status = acpi_ut_validate_buffer(buffer); if (ACPI_FAILURE(status)) { return (status); } /* * Wants the single segment ACPI name. * Validate handle and convert to a namespace Node */ status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } if (name_type == ACPI_FULL_PATHNAME || name_type == ACPI_FULL_PATHNAME_NO_TRAILING) { /* Get the full pathname (From the namespace root) */ status = acpi_ns_handle_to_pathname(handle, buffer, name_type == ACPI_FULL_PATHNAME ? FALSE : TRUE); } else { /* Get the single name */ status = acpi_ns_handle_to_name(handle, buffer); } (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status); } ACPI_EXPORT_SYMBOL(acpi_get_name) /****************************************************************************** * * FUNCTION: acpi_ns_copy_device_id * * PARAMETERS: dest - Pointer to the destination PNP_DEVICE_ID * source - Pointer to the source PNP_DEVICE_ID * string_area - Pointer to where to copy the dest string * * RETURN: Pointer to the next string area * * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data. * ******************************************************************************/ static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest, struct acpi_pnp_device_id *source, char *string_area) { /* Create the destination PNP_DEVICE_ID */ dest->string = string_area; dest->length = source->length; /* Copy actual string and return a pointer to the next string area */ memcpy(string_area, source->string, source->length); return (string_area + source->length); } /****************************************************************************** * * FUNCTION: acpi_get_object_info * * PARAMETERS: handle - Object Handle * return_buffer - Where the info is returned * * RETURN: Status * * DESCRIPTION: Returns information about an object as gleaned from the * namespace node and possibly by running several standard * control methods (Such as in the case of a device.) * * For Device and Processor objects, run the Device _HID, _UID, _CID, * _CLS, _ADR, _sx_w, and _sx_d methods. * * Note: Allocates the return buffer, must be freed by the caller. * * Note: This interface is intended to be used during the initial device * discovery namespace traversal. Therefore, no complex methods can be * executed, especially those that access operation regions. Therefore, do * not add any additional methods that could cause problems in this area. * Because of this reason support for the following methods has been removed: * 1) _SUB method was removed (11/2015) * 2) _STA method was removed (02/2018) * ******************************************************************************/ acpi_status acpi_get_object_info(acpi_handle handle, struct acpi_device_info **return_buffer) { struct acpi_namespace_node *node; struct acpi_device_info *info; struct acpi_pnp_device_id_list *cid_list = NULL; struct acpi_pnp_device_id *hid = NULL; struct acpi_pnp_device_id *uid = NULL; struct acpi_pnp_device_id *cls = NULL; char *next_id_string; acpi_object_type type; acpi_name name; u8 param_count = 0; u16 valid = 0; u32 info_size; u32 i; acpi_status status; /* Parameter validation */ if (!handle || !return_buffer) { return (AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } node = acpi_ns_validate_handle(handle); if (!node) { (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (AE_BAD_PARAMETER); } /* Get the namespace node data while the namespace is locked */ info_size = sizeof(struct acpi_device_info); type = node->type; name = node->name.integer; if (node->type == ACPI_TYPE_METHOD) { param_count = node->object->method.param_count; } status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) { /* * Get extra info for ACPI Device/Processor objects only: * Run the Device _HID, _UID, _CLS, and _CID methods. * * Note: none of these methods are required, so they may or may * not be present for this device. The Info->Valid bitfield is used * to indicate which methods were found and run successfully. */ /* Execute the Device._HID method */ status = acpi_ut_execute_HID(node, &hid); if (ACPI_SUCCESS(status)) { info_size += hid->length; valid |= ACPI_VALID_HID; } /* Execute the Device._UID method */ status = acpi_ut_execute_UID(node, &uid); if (ACPI_SUCCESS(status)) { info_size += uid->length; valid |= ACPI_VALID_UID; } /* Execute the Device._CID method */ status = acpi_ut_execute_CID(node, &cid_list); if (ACPI_SUCCESS(status)) { /* Add size of CID strings and CID pointer array */ info_size += (cid_list->list_size - sizeof(struct acpi_pnp_device_id_list)); valid |= ACPI_VALID_CID; } /* Execute the Device._CLS method */ status = acpi_ut_execute_CLS(node, &cls); if (ACPI_SUCCESS(status)) { info_size += cls->length; valid |= ACPI_VALID_CLS; } } /* * Now that we have the variable-length data, we can allocate the * return buffer */ info = ACPI_ALLOCATE_ZEROED(info_size); if (!info) { status = AE_NO_MEMORY; goto cleanup; } /* Get the fixed-length data */ if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) { /* * Get extra info for ACPI Device/Processor objects only: * Run the _ADR and, sx_w, and _sx_d methods. * * Notes: none of these methods are required, so they may or may * not be present for this device. The Info->Valid bitfield is used * to indicate which methods were found and run successfully. */ /* Execute the Device._ADR method */ status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node, &info->address); if (ACPI_SUCCESS(status)) { valid |= ACPI_VALID_ADR; } /* Execute the Device._sx_w methods */ status = acpi_ut_execute_power_methods(node, acpi_gbl_lowest_dstate_names, ACPI_NUM_sx_w_METHODS, info->lowest_dstates); if (ACPI_SUCCESS(status)) { valid |= ACPI_VALID_SXWS; } /* Execute the Device._sx_d methods */ status = acpi_ut_execute_power_methods(node, acpi_gbl_highest_dstate_names, ACPI_NUM_sx_d_METHODS, info->highest_dstates); if (ACPI_SUCCESS(status)) { valid |= ACPI_VALID_SXDS; } } /* * Create a pointer to the string area of the return buffer. * Point to the end of the base struct acpi_device_info structure. */ next_id_string = ACPI_CAST_PTR(char, info->compatible_id_list.ids); if (cid_list) { /* Point past the CID PNP_DEVICE_ID array */ next_id_string += ((acpi_size)cid_list->count * sizeof(struct acpi_pnp_device_id)); } /* * Copy the HID, UID, and CIDs to the return buffer. The variable-length * strings are copied to the reserved area at the end of the buffer. * * For HID and CID, check if the ID is a PCI Root Bridge. */ if (hid) { next_id_string = acpi_ns_copy_device_id(&info->hardware_id, hid, next_id_string); if (acpi_ut_is_pci_root_bridge(hid->string)) { info->flags |= ACPI_PCI_ROOT_BRIDGE; } } if (uid) { next_id_string = acpi_ns_copy_device_id(&info->unique_id, uid, next_id_string); } if (cid_list) { info->compatible_id_list.count = cid_list->count; info->compatible_id_list.list_size = cid_list->list_size; /* Copy each CID */ for (i = 0; i < cid_list->count; i++) { next_id_string = acpi_ns_copy_device_id(&info->compatible_id_list. ids[i], &cid_list->ids[i], next_id_string); if (acpi_ut_is_pci_root_bridge(cid_list->ids[i].string)) { info->flags |= ACPI_PCI_ROOT_BRIDGE; } } } if (cls) { (void)acpi_ns_copy_device_id(&info->class_code, cls, next_id_string); } /* Copy the fixed-length data */ info->info_size = info_size; info->type = type; info->name = name; info->param_count = param_count; info->valid = valid; *return_buffer = info; status = AE_OK; cleanup: if (hid) { ACPI_FREE(hid); } if (uid) { ACPI_FREE(uid); } if (cid_list) { ACPI_FREE(cid_list); } if (cls) { ACPI_FREE(cls); } return (status); } ACPI_EXPORT_SYMBOL(acpi_get_object_info) /****************************************************************************** * * FUNCTION: acpi_install_method * * PARAMETERS: buffer - An ACPI table containing one control method * * RETURN: Status * * DESCRIPTION: Install a control method into the namespace. If the method * name already exists in the namespace, it is overwritten. The * input buffer must contain a valid DSDT or SSDT containing a * single control method. * ******************************************************************************/ acpi_status acpi_install_method(u8 *buffer) { struct acpi_table_header *table = ACPI_CAST_PTR(struct acpi_table_header, buffer); u8 *aml_buffer; u8 *aml_start; char *path; struct acpi_namespace_node *node; union acpi_operand_object *method_obj; struct acpi_parse_state parser_state; u32 aml_length; u16 opcode; u8 method_flags; acpi_status status; /* Parameter validation */ if (!buffer) { return (AE_BAD_PARAMETER); } /* Table must be a DSDT or SSDT */ if (!ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_DSDT) && !ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_SSDT)) { return (AE_BAD_HEADER); } /* First AML opcode in the table must be a control method */ parser_state.aml = buffer + sizeof(struct acpi_table_header); opcode = acpi_ps_peek_opcode(&parser_state); if (opcode != AML_METHOD_OP) { return (AE_BAD_PARAMETER); } /* Extract method information from the raw AML */ parser_state.aml += acpi_ps_get_opcode_size(opcode); parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state); path = acpi_ps_get_next_namestring(&parser_state); method_flags = *parser_state.aml++; aml_start = parser_state.aml; aml_length = (u32)ACPI_PTR_DIFF(parser_state.pkg_end, aml_start); /* * Allocate resources up-front. We don't want to have to delete a new * node from the namespace if we cannot allocate memory. */ aml_buffer = ACPI_ALLOCATE(aml_length); if (!aml_buffer) { return (AE_NO_MEMORY); } method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD); if (!method_obj) { ACPI_FREE(aml_buffer); return (AE_NO_MEMORY); } /* Lock namespace for acpi_ns_lookup, we may be creating a new node */ status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { goto error_exit; } /* The lookup either returns an existing node or creates a new one */ status = acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1, ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &node); (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { /* ns_lookup */ if (status != AE_ALREADY_EXISTS) { goto error_exit; } /* Node existed previously, make sure it is a method node */ if (node->type != ACPI_TYPE_METHOD) { status = AE_TYPE; goto error_exit; } } /* Copy the method AML to the local buffer */ memcpy(aml_buffer, aml_start, aml_length); /* Initialize the method object with the new method's information */ method_obj->method.aml_start = aml_buffer; method_obj->method.aml_length = aml_length; method_obj->method.param_count = (u8) (method_flags & AML_METHOD_ARG_COUNT); if (method_flags & AML_METHOD_SERIALIZED) { method_obj->method.info_flags = ACPI_METHOD_SERIALIZED; method_obj->method.sync_level = (u8) ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4); } /* * Now that it is complete, we can attach the new method object to * the method Node (detaches/deletes any existing object) */ status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD); /* * Flag indicates AML buffer is dynamic, must be deleted later. * Must be set only after attach above. */ node->flags |= ANOBJ_ALLOCATED_BUFFER; /* Remove local reference to the method object */ acpi_ut_remove_reference(method_obj); return (status); error_exit: ACPI_FREE(aml_buffer); ACPI_FREE(method_obj); return (status); } ACPI_EXPORT_SYMBOL(acpi_install_method)
linux-master
drivers/acpi/acpica/nsxfname.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: rscalc - Calculate stream and list lengths * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #include "acnamesp.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rscalc") /* Local prototypes */ static u8 acpi_rs_count_set_bits(u16 bit_field); static acpi_rs_length acpi_rs_struct_option_length(struct acpi_resource_source *resource_source); static u32 acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length); /******************************************************************************* * * FUNCTION: acpi_rs_count_set_bits * * PARAMETERS: bit_field - Field in which to count bits * * RETURN: Number of bits set within the field * * DESCRIPTION: Count the number of bits set in a resource field. Used for * (Short descriptor) interrupt and DMA lists. * ******************************************************************************/ static u8 acpi_rs_count_set_bits(u16 bit_field) { u8 bits_set; ACPI_FUNCTION_ENTRY(); for (bits_set = 0; bit_field; bits_set++) { /* Zero the least significant bit that is set */ bit_field &= (u16) (bit_field - 1); } return (bits_set); } /******************************************************************************* * * FUNCTION: acpi_rs_struct_option_length * * PARAMETERS: resource_source - Pointer to optional descriptor field * * RETURN: Status * * DESCRIPTION: Common code to handle optional resource_source_index and * resource_source fields in some Large descriptors. Used during * list-to-stream conversion * ******************************************************************************/ static acpi_rs_length acpi_rs_struct_option_length(struct acpi_resource_source *resource_source) { ACPI_FUNCTION_ENTRY(); /* * If the resource_source string is valid, return the size of the string * (string_length includes the NULL terminator) plus the size of the * resource_source_index (1). */ if (resource_source->string_ptr) { return ((acpi_rs_length)(resource_source->string_length + 1)); } return (0); } /******************************************************************************* * * FUNCTION: acpi_rs_stream_option_length * * PARAMETERS: resource_length - Length from the resource header * minimum_total_length - Minimum length of this resource, before * any optional fields. Includes header size * * RETURN: Length of optional string (0 if no string present) * * DESCRIPTION: Common code to handle optional resource_source_index and * resource_source fields in some Large descriptors. Used during * stream-to-list conversion * ******************************************************************************/ static u32 acpi_rs_stream_option_length(u32 resource_length, u32 minimum_aml_resource_length) { u32 string_length = 0; ACPI_FUNCTION_ENTRY(); /* * The resource_source_index and resource_source are optional elements of * some Large-type resource descriptors. */ /* * If the length of the actual resource descriptor is greater than the * ACPI spec-defined minimum length, it means that a resource_source_index * exists and is followed by a (required) null terminated string. The * string length (including the null terminator) is the resource length * minus the minimum length, minus one byte for the resource_source_index * itself. */ if (resource_length > minimum_aml_resource_length) { /* Compute the length of the optional string */ string_length = resource_length - minimum_aml_resource_length - 1; } /* * Round the length up to a multiple of the native word in order to * guarantee that the entire resource descriptor is native word aligned */ return ((u32) ACPI_ROUND_UP_TO_NATIVE_WORD(string_length)); } /******************************************************************************* * * FUNCTION: acpi_rs_get_aml_length * * PARAMETERS: resource - Pointer to the resource linked list * resource_list_size - Size of the resource linked list * size_needed - Where the required size is returned * * RETURN: Status * * DESCRIPTION: Takes a linked list of internal resource descriptors and * calculates the size buffer needed to hold the corresponding * external resource byte stream. * ******************************************************************************/ acpi_status acpi_rs_get_aml_length(struct acpi_resource *resource, acpi_size resource_list_size, acpi_size *size_needed) { acpi_size aml_size_needed = 0; struct acpi_resource *resource_end; acpi_rs_length total_size; ACPI_FUNCTION_TRACE(rs_get_aml_length); /* Traverse entire list of internal resource descriptors */ resource_end = ACPI_ADD_PTR(struct acpi_resource, resource, resource_list_size); while (resource < resource_end) { /* Validate the descriptor type */ if (resource->type > ACPI_RESOURCE_TYPE_MAX) { return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); } /* Sanity check the length. It must not be zero, or we loop forever */ if (!resource->length) { return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); } /* Get the base size of the (external stream) resource descriptor */ total_size = acpi_gbl_aml_resource_sizes[resource->type]; /* * Augment the base size for descriptors with optional and/or * variable-length fields */ switch (resource->type) { case ACPI_RESOURCE_TYPE_IRQ: /* Length can be 3 or 2 */ if (resource->data.irq.descriptor_length == 2) { total_size--; } break; case ACPI_RESOURCE_TYPE_START_DEPENDENT: /* Length can be 1 or 0 */ if (resource->data.irq.descriptor_length == 0) { total_size--; } break; case ACPI_RESOURCE_TYPE_VENDOR: /* * Vendor Defined Resource: * For a Vendor Specific resource, if the Length is between 1 and 7 * it will be created as a Small Resource data type, otherwise it * is a Large Resource data type. */ if (resource->data.vendor.byte_length > 7) { /* Base size of a Large resource descriptor */ total_size = sizeof(struct aml_resource_large_header); } /* Add the size of the vendor-specific data */ total_size = (acpi_rs_length) (total_size + resource->data.vendor.byte_length); break; case ACPI_RESOURCE_TYPE_END_TAG: /* * End Tag: * We are done -- return the accumulated total size. */ *size_needed = aml_size_needed + total_size; /* Normal exit */ return_ACPI_STATUS(AE_OK); case ACPI_RESOURCE_TYPE_ADDRESS16: /* * 16-Bit Address Resource: * Add the size of the optional resource_source info */ total_size = (acpi_rs_length)(total_size + acpi_rs_struct_option_length (&resource->data. address16. resource_source)); break; case ACPI_RESOURCE_TYPE_ADDRESS32: /* * 32-Bit Address Resource: * Add the size of the optional resource_source info */ total_size = (acpi_rs_length)(total_size + acpi_rs_struct_option_length (&resource->data. address32. resource_source)); break; case ACPI_RESOURCE_TYPE_ADDRESS64: /* * 64-Bit Address Resource: * Add the size of the optional resource_source info */ total_size = (acpi_rs_length)(total_size + acpi_rs_struct_option_length (&resource->data. address64. resource_source)); break; case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: /* * Extended IRQ Resource: * Add the size of each additional optional interrupt beyond the * required 1 (4 bytes for each u32 interrupt number) */ total_size = (acpi_rs_length)(total_size + ((resource->data. extended_irq. interrupt_count - 1) * 4) + /* Add the size of the optional resource_source info */ acpi_rs_struct_option_length (&resource->data. extended_irq. resource_source)); break; case ACPI_RESOURCE_TYPE_GPIO: total_size = (acpi_rs_length)(total_size + (resource->data.gpio. pin_table_length * 2) + resource->data.gpio. resource_source. string_length + resource->data.gpio. vendor_length); break; case ACPI_RESOURCE_TYPE_PIN_FUNCTION: total_size = (acpi_rs_length)(total_size + (resource->data. pin_function. pin_table_length * 2) + resource->data. pin_function. resource_source. string_length + resource->data. pin_function. vendor_length); break; case ACPI_RESOURCE_TYPE_CLOCK_INPUT: total_size = (acpi_rs_length)(total_size + resource->data. clock_input. resource_source. string_length); break; case ACPI_RESOURCE_TYPE_SERIAL_BUS: total_size = acpi_gbl_aml_resource_serial_bus_sizes[resource-> data. common_serial_bus. type]; total_size = (acpi_rs_length)(total_size + resource->data. i2c_serial_bus. resource_source. string_length + resource->data. i2c_serial_bus. vendor_length); break; case ACPI_RESOURCE_TYPE_PIN_CONFIG: total_size = (acpi_rs_length)(total_size + (resource->data. pin_config. pin_table_length * 2) + resource->data.pin_config. resource_source. string_length + resource->data.pin_config. vendor_length); break; case ACPI_RESOURCE_TYPE_PIN_GROUP: total_size = (acpi_rs_length)(total_size + (resource->data.pin_group. pin_table_length * 2) + resource->data.pin_group. resource_label. string_length + resource->data.pin_group. vendor_length); break; case ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION: total_size = (acpi_rs_length)(total_size + resource->data. pin_group_function. resource_source. string_length + resource->data. pin_group_function. resource_source_label. string_length + resource->data. pin_group_function. vendor_length); break; case ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG: total_size = (acpi_rs_length)(total_size + resource->data. pin_group_config. resource_source. string_length + resource->data. pin_group_config. resource_source_label. string_length + resource->data. pin_group_config. vendor_length); break; default: break; } /* Update the total */ aml_size_needed += total_size; /* Point to the next object */ resource = ACPI_ADD_PTR(struct acpi_resource, resource, resource->length); } /* Did not find an end_tag resource descriptor */ return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } /******************************************************************************* * * FUNCTION: acpi_rs_get_list_length * * PARAMETERS: aml_buffer - Pointer to the resource byte stream * aml_buffer_length - Size of aml_buffer * size_needed - Where the size needed is returned * * RETURN: Status * * DESCRIPTION: Takes an external resource byte stream and calculates the size * buffer needed to hold the corresponding internal resource * descriptor linked list. * ******************************************************************************/ acpi_status acpi_rs_get_list_length(u8 *aml_buffer, u32 aml_buffer_length, acpi_size *size_needed) { acpi_status status; u8 *end_aml; u8 *buffer; u32 buffer_size; u16 temp16; u16 resource_length; u32 extra_struct_bytes; u8 resource_index; u8 minimum_aml_resource_length; union aml_resource *aml_resource; ACPI_FUNCTION_TRACE(rs_get_list_length); *size_needed = ACPI_RS_SIZE_MIN; /* Minimum size is one end_tag */ end_aml = aml_buffer + aml_buffer_length; /* Walk the list of AML resource descriptors */ while (aml_buffer < end_aml) { /* Validate the Resource Type and Resource Length */ status = acpi_ut_validate_resource(NULL, aml_buffer, &resource_index); if (ACPI_FAILURE(status)) { /* * Exit on failure. Cannot continue because the descriptor length * may be bogus also. */ return_ACPI_STATUS(status); } aml_resource = (void *)aml_buffer; /* Get the resource length and base (minimum) AML size */ resource_length = acpi_ut_get_resource_length(aml_buffer); minimum_aml_resource_length = acpi_gbl_resource_aml_sizes[resource_index]; /* * Augment the size for descriptors with optional * and/or variable length fields */ extra_struct_bytes = 0; buffer = aml_buffer + acpi_ut_get_resource_header_length(aml_buffer); switch (acpi_ut_get_resource_type(aml_buffer)) { case ACPI_RESOURCE_NAME_IRQ: /* * IRQ Resource: * Get the number of bits set in the 16-bit IRQ mask */ ACPI_MOVE_16_TO_16(&temp16, buffer); extra_struct_bytes = acpi_rs_count_set_bits(temp16); break; case ACPI_RESOURCE_NAME_DMA: /* * DMA Resource: * Get the number of bits set in the 8-bit DMA mask */ extra_struct_bytes = acpi_rs_count_set_bits(*buffer); break; case ACPI_RESOURCE_NAME_VENDOR_SMALL: case ACPI_RESOURCE_NAME_VENDOR_LARGE: /* * Vendor Resource: * Get the number of vendor data bytes */ extra_struct_bytes = resource_length; /* * There is already one byte included in the minimum * descriptor size. If there are extra struct bytes, * subtract one from the count. */ if (extra_struct_bytes) { extra_struct_bytes--; } break; case ACPI_RESOURCE_NAME_END_TAG: /* * End Tag: This is the normal exit */ return_ACPI_STATUS(AE_OK); case ACPI_RESOURCE_NAME_ADDRESS32: case ACPI_RESOURCE_NAME_ADDRESS16: case ACPI_RESOURCE_NAME_ADDRESS64: /* * Address Resource: * Add the size of the optional resource_source */ extra_struct_bytes = acpi_rs_stream_option_length(resource_length, minimum_aml_resource_length); break; case ACPI_RESOURCE_NAME_EXTENDED_IRQ: /* * Extended IRQ Resource: * Using the interrupt_table_length, add 4 bytes for each additional * interrupt. Note: at least one interrupt is required and is * included in the minimum descriptor size (reason for the -1) */ extra_struct_bytes = (buffer[1] - 1) * sizeof(u32); /* Add the size of the optional resource_source */ extra_struct_bytes += acpi_rs_stream_option_length(resource_length - extra_struct_bytes, minimum_aml_resource_length); break; case ACPI_RESOURCE_NAME_GPIO: /* Vendor data is optional */ if (aml_resource->gpio.vendor_length) { extra_struct_bytes += aml_resource->gpio.vendor_offset - aml_resource->gpio.pin_table_offset + aml_resource->gpio.vendor_length; } else { extra_struct_bytes += aml_resource->large_header.resource_length + sizeof(struct aml_resource_large_header) - aml_resource->gpio.pin_table_offset; } break; case ACPI_RESOURCE_NAME_PIN_FUNCTION: /* Vendor data is optional */ if (aml_resource->pin_function.vendor_length) { extra_struct_bytes += aml_resource->pin_function.vendor_offset - aml_resource->pin_function. pin_table_offset + aml_resource->pin_function.vendor_length; } else { extra_struct_bytes += aml_resource->large_header.resource_length + sizeof(struct aml_resource_large_header) - aml_resource->pin_function.pin_table_offset; } break; case ACPI_RESOURCE_NAME_SERIAL_BUS:{ /* Avoid undefined behavior: member access within misaligned address */ struct aml_resource_common_serialbus common_serial_bus; memcpy(&common_serial_bus, aml_resource, sizeof(common_serial_bus)); minimum_aml_resource_length = acpi_gbl_resource_aml_serial_bus_sizes [common_serial_bus.type]; extra_struct_bytes += common_serial_bus.resource_length - minimum_aml_resource_length; break; } case ACPI_RESOURCE_NAME_PIN_CONFIG: /* Vendor data is optional */ if (aml_resource->pin_config.vendor_length) { extra_struct_bytes += aml_resource->pin_config.vendor_offset - aml_resource->pin_config.pin_table_offset + aml_resource->pin_config.vendor_length; } else { extra_struct_bytes += aml_resource->large_header.resource_length + sizeof(struct aml_resource_large_header) - aml_resource->pin_config.pin_table_offset; } break; case ACPI_RESOURCE_NAME_PIN_GROUP: extra_struct_bytes += aml_resource->pin_group.vendor_offset - aml_resource->pin_group.pin_table_offset + aml_resource->pin_group.vendor_length; break; case ACPI_RESOURCE_NAME_PIN_GROUP_FUNCTION: extra_struct_bytes += aml_resource->pin_group_function.vendor_offset - aml_resource->pin_group_function.res_source_offset + aml_resource->pin_group_function.vendor_length; break; case ACPI_RESOURCE_NAME_PIN_GROUP_CONFIG: extra_struct_bytes += aml_resource->pin_group_config.vendor_offset - aml_resource->pin_group_config.res_source_offset + aml_resource->pin_group_config.vendor_length; break; case ACPI_RESOURCE_NAME_CLOCK_INPUT: extra_struct_bytes = acpi_rs_stream_option_length(resource_length, minimum_aml_resource_length); break; default: break; } /* * Update the required buffer size for the internal descriptor structs * * Important: Round the size up for the appropriate alignment. This * is a requirement on IA64. */ if (acpi_ut_get_resource_type(aml_buffer) == ACPI_RESOURCE_NAME_SERIAL_BUS) { /* Avoid undefined behavior: member access within misaligned address */ struct aml_resource_common_serialbus common_serial_bus; memcpy(&common_serial_bus, aml_resource, sizeof(common_serial_bus)); buffer_size = acpi_gbl_resource_struct_serial_bus_sizes [common_serial_bus.type] + extra_struct_bytes; } else { buffer_size = acpi_gbl_resource_struct_sizes[resource_index] + extra_struct_bytes; } buffer_size = (u32)ACPI_ROUND_UP_TO_NATIVE_WORD(buffer_size); *size_needed += buffer_size; ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Type %.2X, AmlLength %.2X InternalLength %.2X%8X\n", acpi_ut_get_resource_type(aml_buffer), acpi_ut_get_descriptor_length(aml_buffer), ACPI_FORMAT_UINT64(*size_needed))); /* * Point to the next resource within the AML stream using the length * contained in the resource descriptor header */ aml_buffer += acpi_ut_get_descriptor_length(aml_buffer); } /* Did not find an end_tag resource descriptor */ return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } /******************************************************************************* * * FUNCTION: acpi_rs_get_pci_routing_table_length * * PARAMETERS: package_object - Pointer to the package object * buffer_size_needed - u32 pointer of the size buffer * needed to properly return the * parsed data * * RETURN: Status * * DESCRIPTION: Given a package representing a PCI routing table, this * calculates the size of the corresponding linked list of * descriptions. * ******************************************************************************/ acpi_status acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object, acpi_size *buffer_size_needed) { u32 number_of_elements; acpi_size temp_size_needed = 0; union acpi_operand_object **top_object_list; u32 index; union acpi_operand_object *package_element; union acpi_operand_object **sub_object_list; u8 name_found; u32 table_index; ACPI_FUNCTION_TRACE(rs_get_pci_routing_table_length); number_of_elements = package_object->package.count; /* * Calculate the size of the return buffer. * The base size is the number of elements * the sizes of the * structures. Additional space for the strings is added below. * The minus one is to subtract the size of the u8 Source[1] * member because it is added below. * * But each PRT_ENTRY structure has a pointer to a string and * the size of that string must be found. */ top_object_list = package_object->package.elements; for (index = 0; index < number_of_elements; index++) { /* Dereference the subpackage */ package_element = *top_object_list; /* We must have a valid Package object */ if (!package_element || (package_element->common.type != ACPI_TYPE_PACKAGE)) { return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* * The sub_object_list will now point to an array of the * four IRQ elements: Address, Pin, Source and source_index */ sub_object_list = package_element->package.elements; /* Scan the irq_table_elements for the Source Name String */ name_found = FALSE; for (table_index = 0; table_index < package_element->package.count && !name_found; table_index++) { if (*sub_object_list && /* Null object allowed */ ((ACPI_TYPE_STRING == (*sub_object_list)->common.type) || ((ACPI_TYPE_LOCAL_REFERENCE == (*sub_object_list)->common.type) && ((*sub_object_list)->reference.class == ACPI_REFCLASS_NAME)))) { name_found = TRUE; } else { /* Look at the next element */ sub_object_list++; } } temp_size_needed += (sizeof(struct acpi_pci_routing_table) - 4); /* Was a String type found? */ if (name_found) { if ((*sub_object_list)->common.type == ACPI_TYPE_STRING) { /* * The length String.Length field does not include the * terminating NULL, add 1 */ temp_size_needed += ((acpi_size) (*sub_object_list)->string. length + 1); } else { temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node); } } else { /* * If no name was found, then this is a NULL, which is * translated as a u32 zero. */ temp_size_needed += sizeof(u32); } /* Round up the size since each element must be aligned */ temp_size_needed = ACPI_ROUND_UP_TO_64BIT(temp_size_needed); /* Point to the next union acpi_operand_object */ top_object_list++; } /* * Add an extra element to the end of the list, essentially a * NULL terminator */ *buffer_size_needed = temp_size_needed + sizeof(struct acpi_pci_routing_table); return_ACPI_STATUS(AE_OK); }
linux-master
drivers/acpi/acpica/rscalc.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exprep - ACPI AML field prep utilities * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #include "amlcode.h" #include "acnamesp.h" #include "acdispat.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exprep") /* Local prototypes */ static u32 acpi_ex_decode_field_access(union acpi_operand_object *obj_desc, u8 field_flags, u32 * return_byte_alignment); #ifdef ACPI_UNDER_DEVELOPMENT static u32 acpi_ex_generate_access(u32 field_bit_offset, u32 field_bit_length, u32 region_length); /******************************************************************************* * * FUNCTION: acpi_ex_generate_access * * PARAMETERS: field_bit_offset - Start of field within parent region/buffer * field_bit_length - Length of field in bits * region_length - Length of parent in bytes * * RETURN: Field granularity (8, 16, 32 or 64) and * byte_alignment (1, 2, 3, or 4) * * DESCRIPTION: Generate an optimal access width for fields defined with the * any_acc keyword. * * NOTE: Need to have the region_length in order to check for boundary * conditions (end-of-region). However, the region_length is a deferred * operation. Therefore, to complete this implementation, the generation * of this access width must be deferred until the region length has * been evaluated. * ******************************************************************************/ static u32 acpi_ex_generate_access(u32 field_bit_offset, u32 field_bit_length, u32 region_length) { u32 field_byte_length; u32 field_byte_offset; u32 field_byte_end_offset; u32 access_byte_width; u32 field_start_offset; u32 field_end_offset; u32 minimum_access_width = 0xFFFFFFFF; u32 minimum_accesses = 0xFFFFFFFF; u32 accesses; ACPI_FUNCTION_TRACE(ex_generate_access); /* Round Field start offset and length to "minimal" byte boundaries */ field_byte_offset = ACPI_DIV_8(ACPI_ROUND_DOWN(field_bit_offset, 8)); field_byte_end_offset = ACPI_DIV_8(ACPI_ROUND_UP(field_bit_length + field_bit_offset, 8)); field_byte_length = field_byte_end_offset - field_byte_offset; ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Bit length %u, Bit offset %u\n", field_bit_length, field_bit_offset)); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Byte Length %u, Byte Offset %u, End Offset %u\n", field_byte_length, field_byte_offset, field_byte_end_offset)); /* * Iterative search for the maximum access width that is both aligned * and does not go beyond the end of the region * * Start at byte_acc and work upwards to qword_acc max. (1,2,4,8 bytes) */ for (access_byte_width = 1; access_byte_width <= 8; access_byte_width <<= 1) { /* * 1) Round end offset up to next access boundary and make sure that * this does not go beyond the end of the parent region. * 2) When the Access width is greater than the field_byte_length, we * are done. (This does not optimize for the perfectly aligned * case yet). */ if (ACPI_ROUND_UP(field_byte_end_offset, access_byte_width) <= region_length) { field_start_offset = ACPI_ROUND_DOWN(field_byte_offset, access_byte_width) / access_byte_width; field_end_offset = ACPI_ROUND_UP((field_byte_length + field_byte_offset), access_byte_width) / access_byte_width; accesses = field_end_offset - field_start_offset; ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "AccessWidth %u end is within region\n", access_byte_width)); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Field Start %u, Field End %u -- requires %u accesses\n", field_start_offset, field_end_offset, accesses)); /* Single access is optimal */ if (accesses <= 1) { ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Entire field can be accessed " "with one operation of size %u\n", access_byte_width)); return_VALUE(access_byte_width); } /* * Fits in the region, but requires more than one read/write. * try the next wider access on next iteration */ if (accesses < minimum_accesses) { minimum_accesses = accesses; minimum_access_width = access_byte_width; } } else { ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "AccessWidth %u end is NOT within region\n", access_byte_width)); if (access_byte_width == 1) { ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Field goes beyond end-of-region!\n")); /* Field does not fit in the region at all */ return_VALUE(0); } /* * This width goes beyond the end-of-region, back off to * previous access */ ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Backing off to previous optimal access width of %u\n", minimum_access_width)); return_VALUE(minimum_access_width); } } /* * Could not read/write field with one operation, * just use max access width */ ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Cannot access field in one operation, using width 8\n")); return_VALUE(8); } #endif /* ACPI_UNDER_DEVELOPMENT */ /******************************************************************************* * * FUNCTION: acpi_ex_decode_field_access * * PARAMETERS: obj_desc - Field object * field_flags - Encoded fieldflags (contains access bits) * return_byte_alignment - Where the byte alignment is returned * * RETURN: Field granularity (8, 16, 32 or 64) and * byte_alignment (1, 2, 3, or 4) * * DESCRIPTION: Decode the access_type bits of a field definition. * ******************************************************************************/ static u32 acpi_ex_decode_field_access(union acpi_operand_object *obj_desc, u8 field_flags, u32 * return_byte_alignment) { u32 access; u32 byte_alignment; u32 bit_length; ACPI_FUNCTION_TRACE(ex_decode_field_access); access = (field_flags & AML_FIELD_ACCESS_TYPE_MASK); switch (access) { case AML_FIELD_ACCESS_ANY: #ifdef ACPI_UNDER_DEVELOPMENT byte_alignment = acpi_ex_generate_access(obj_desc->common_field. start_field_bit_offset, obj_desc->common_field.bit_length, 0xFFFFFFFF /* Temp until we pass region_length as parameter */ ); bit_length = byte_alignment * 8; #endif byte_alignment = 1; bit_length = 8; break; case AML_FIELD_ACCESS_BYTE: case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */ byte_alignment = 1; bit_length = 8; break; case AML_FIELD_ACCESS_WORD: byte_alignment = 2; bit_length = 16; break; case AML_FIELD_ACCESS_DWORD: byte_alignment = 4; bit_length = 32; break; case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */ byte_alignment = 8; bit_length = 64; break; default: /* Invalid field access type */ ACPI_ERROR((AE_INFO, "Unknown field access type 0x%X", access)); return_UINT32(0); } if (obj_desc->common.type == ACPI_TYPE_BUFFER_FIELD) { /* * buffer_field access can be on any byte boundary, so the * byte_alignment is always 1 byte -- regardless of any byte_alignment * implied by the field access type. */ byte_alignment = 1; } *return_byte_alignment = byte_alignment; return_UINT32(bit_length); } /******************************************************************************* * * FUNCTION: acpi_ex_prep_common_field_object * * PARAMETERS: obj_desc - The field object * field_flags - Access, lock_rule, and update_rule. * The format of a field_flag is described * in the ACPI specification * field_attribute - Special attributes (not used) * field_bit_position - Field start position * field_bit_length - Field length in number of bits * * RETURN: Status * * DESCRIPTION: Initialize the areas of the field object that are common * to the various types of fields. Note: This is very "sensitive" * code because we are solving the general case for field * alignment. * ******************************************************************************/ acpi_status acpi_ex_prep_common_field_object(union acpi_operand_object *obj_desc, u8 field_flags, u8 field_attribute, u32 field_bit_position, u32 field_bit_length) { u32 access_bit_width; u32 byte_alignment; u32 nearest_byte_address; ACPI_FUNCTION_TRACE(ex_prep_common_field_object); /* * Note: the structure being initialized is the * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common * area are initialized by this procedure. */ obj_desc->common_field.field_flags = field_flags; obj_desc->common_field.attribute = field_attribute; obj_desc->common_field.bit_length = field_bit_length; /* * Decode the access type so we can compute offsets. The access type gives * two pieces of information - the width of each field access and the * necessary byte_alignment (address granularity) of the access. * * For any_acc, the access_bit_width is the largest width that is both * necessary and possible in an attempt to access the whole field in one * I/O operation. However, for any_acc, the byte_alignment is always one * byte. * * For all Buffer Fields, the byte_alignment is always one byte. * * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is * the same (equivalent) as the byte_alignment. */ access_bit_width = acpi_ex_decode_field_access(obj_desc, field_flags, &byte_alignment); if (!access_bit_width) { return_ACPI_STATUS(AE_AML_OPERAND_VALUE); } /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */ obj_desc->common_field.access_byte_width = (u8) ACPI_DIV_8(access_bit_width); /* * base_byte_offset is the address of the start of the field within the * region. It is the byte address of the first *datum* (field-width data * unit) of the field. (i.e., the first datum that contains at least the * first *bit* of the field.) * * Note: byte_alignment is always either equal to the access_bit_width or 8 * (Byte access), and it defines the addressing granularity of the parent * region or buffer. */ nearest_byte_address = ACPI_ROUND_BITS_DOWN_TO_BYTES(field_bit_position); obj_desc->common_field.base_byte_offset = (u32) ACPI_ROUND_DOWN(nearest_byte_address, byte_alignment); /* * start_field_bit_offset is the offset of the first bit of the field within * a field datum. */ obj_desc->common_field.start_field_bit_offset = (u8) (field_bit_position - ACPI_MUL_8(obj_desc->common_field.base_byte_offset)); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ex_prep_field_value * * PARAMETERS: info - Contains all field creation info * * RETURN: Status * * DESCRIPTION: Construct an object of type union acpi_operand_object with a * subtype of def_field and connect it to the parent Node. * ******************************************************************************/ acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info) { union acpi_operand_object *obj_desc; union acpi_operand_object *second_desc = NULL; acpi_status status; u32 access_byte_width; u32 type; ACPI_FUNCTION_TRACE(ex_prep_field_value); /* Parameter validation */ if (info->field_type != ACPI_TYPE_LOCAL_INDEX_FIELD) { if (!info->region_node) { ACPI_ERROR((AE_INFO, "Null RegionNode")); return_ACPI_STATUS(AE_AML_NO_OPERAND); } type = acpi_ns_get_type(info->region_node); if (type != ACPI_TYPE_REGION) { ACPI_ERROR((AE_INFO, "Needed Region, found type 0x%X (%s)", type, acpi_ut_get_type_name(type))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } } /* Allocate a new field object */ obj_desc = acpi_ut_create_internal_object(info->field_type); if (!obj_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Initialize areas of the object that are common to all fields */ obj_desc->common_field.node = info->field_node; status = acpi_ex_prep_common_field_object(obj_desc, info->field_flags, info->attribute, info->field_bit_position, info->field_bit_length); if (ACPI_FAILURE(status)) { acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(status); } /* Initialize areas of the object that are specific to the field type */ switch (info->field_type) { case ACPI_TYPE_LOCAL_REGION_FIELD: obj_desc->field.region_obj = acpi_ns_get_attached_object(info->region_node); /* Fields specific to generic_serial_bus fields */ obj_desc->field.access_length = info->access_length; if (info->connection_node) { second_desc = info->connection_node->object; if (!(second_desc->common.flags & AOPOBJ_DATA_VALID)) { status = acpi_ds_get_buffer_arguments(second_desc); if (ACPI_FAILURE(status)) { acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(status); } } obj_desc->field.resource_buffer = second_desc->buffer.pointer; obj_desc->field.resource_length = (u16)second_desc->buffer.length; } else if (info->resource_buffer) { obj_desc->field.resource_buffer = info->resource_buffer; obj_desc->field.resource_length = info->resource_length; } obj_desc->field.pin_number_index = info->pin_number_index; /* Allow full data read from EC address space */ if ((obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_EC) && (obj_desc->common_field.bit_length > 8)) { access_byte_width = ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field. bit_length); /* Maximum byte width supported is 255 */ if (access_byte_width < 256) { obj_desc->common_field.access_byte_width = (u8)access_byte_width; } } ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n", obj_desc->field.start_field_bit_offset, obj_desc->field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->field.region_obj)); break; case ACPI_TYPE_LOCAL_BANK_FIELD: obj_desc->bank_field.value = info->bank_value; obj_desc->bank_field.region_obj = acpi_ns_get_attached_object(info->region_node); obj_desc->bank_field.bank_obj = acpi_ns_get_attached_object(info->register_node); /* An additional reference for the attached objects */ acpi_ut_add_reference(obj_desc->bank_field.region_obj); acpi_ut_add_reference(obj_desc->bank_field.bank_obj); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n", obj_desc->bank_field.start_field_bit_offset, obj_desc->bank_field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->bank_field.region_obj, obj_desc->bank_field.bank_obj)); /* * Remember location in AML stream of the field unit * opcode and operands -- since the bank_value * operands must be evaluated. */ second_desc = obj_desc->common.next_object; second_desc->extra.aml_start = ACPI_CAST_PTR(union acpi_parse_object, info->data_register_node)->named.data; second_desc->extra.aml_length = ACPI_CAST_PTR(union acpi_parse_object, info->data_register_node)->named.length; break; case ACPI_TYPE_LOCAL_INDEX_FIELD: /* Get the Index and Data registers */ obj_desc->index_field.index_obj = acpi_ns_get_attached_object(info->register_node); obj_desc->index_field.data_obj = acpi_ns_get_attached_object(info->data_register_node); if (!obj_desc->index_field.data_obj || !obj_desc->index_field.index_obj) { ACPI_ERROR((AE_INFO, "Null Index Object during field prep")); acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(AE_AML_INTERNAL); } /* An additional reference for the attached objects */ acpi_ut_add_reference(obj_desc->index_field.data_obj); acpi_ut_add_reference(obj_desc->index_field.index_obj); /* * April 2006: Changed to match MS behavior * * The value written to the Index register is the byte offset of the * target field in units of the granularity of the index_field * * Previously, the value was calculated as an index in terms of the * width of the Data register, as below: * * obj_desc->index_field.Value = (u32) * (Info->field_bit_position / ACPI_MUL_8 ( * obj_desc->Field.access_byte_width)); * * February 2006: Tried value as a byte offset: * obj_desc->index_field.Value = (u32) * ACPI_DIV_8 (Info->field_bit_position); */ obj_desc->index_field.value = (u32) ACPI_ROUND_DOWN(ACPI_DIV_8(info->field_bit_position), obj_desc->index_field. access_byte_width); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "IndexField: BitOff %X, Off %X, Value %X, " "Gran %X, Index %p, Data %p\n", obj_desc->index_field.start_field_bit_offset, obj_desc->index_field.base_byte_offset, obj_desc->index_field.value, obj_desc->field.access_byte_width, obj_desc->index_field.index_obj, obj_desc->index_field.data_obj)); break; default: /* No other types should get here */ break; } /* * Store the constructed descriptor (obj_desc) into the parent Node, * preserving the current type of that named_obj. */ status = acpi_ns_attach_object(info->field_node, obj_desc, acpi_ns_get_type(info->field_node)); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Set NamedObj %p [%4.4s], ObjDesc %p\n", info->field_node, acpi_ut_get_node_name(info->field_node), obj_desc)); /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exprep.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exstore - AML Interpreter object store support * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdispat.h" #include "acinterp.h" #include "amlcode.h" #include "acnamesp.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exstore") /* Local prototypes */ static acpi_status acpi_ex_store_object_to_index(union acpi_operand_object *val_desc, union acpi_operand_object *dest_desc, struct acpi_walk_state *walk_state); static acpi_status acpi_ex_store_direct_to_node(union acpi_operand_object *source_desc, struct acpi_namespace_node *node, struct acpi_walk_state *walk_state); /******************************************************************************* * * FUNCTION: acpi_ex_store * * PARAMETERS: *source_desc - Value to be stored * *dest_desc - Where to store it. Must be an NS node * or union acpi_operand_object of type * Reference; * walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Store the value described by source_desc into the location * described by dest_desc. Called by various interpreter * functions to store the result of an operation into * the destination operand -- not just simply the actual "Store" * ASL operator. * ******************************************************************************/ acpi_status acpi_ex_store(union acpi_operand_object *source_desc, union acpi_operand_object *dest_desc, struct acpi_walk_state *walk_state) { acpi_status status = AE_OK; union acpi_operand_object *ref_desc = dest_desc; ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc); /* Validate parameters */ if (!source_desc || !dest_desc) { ACPI_ERROR((AE_INFO, "Null parameter")); return_ACPI_STATUS(AE_AML_NO_OPERAND); } /* dest_desc can be either a namespace node or an ACPI object */ if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) { /* * Dest is a namespace node, * Storing an object into a Named node. */ status = acpi_ex_store_object_to_node(source_desc, (struct acpi_namespace_node *) dest_desc, walk_state, ACPI_IMPLICIT_CONVERSION); return_ACPI_STATUS(status); } /* Destination object must be a Reference or a Constant object */ switch (dest_desc->common.type) { case ACPI_TYPE_LOCAL_REFERENCE: break; case ACPI_TYPE_INTEGER: /* Allow stores to Constants -- a Noop as per ACPI spec */ if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) { return_ACPI_STATUS(AE_OK); } ACPI_FALLTHROUGH; default: /* Destination is not a Reference object */ ACPI_ERROR((AE_INFO, "Target is not a Reference or Constant object - [%s] %p", acpi_ut_get_object_type_name(dest_desc), dest_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* * Examine the Reference class. These cases are handled: * * 1) Store to Name (Change the object associated with a name) * 2) Store to an indexed area of a Buffer or Package * 3) Store to a Method Local or Arg * 4) Store to the debug object */ switch (ref_desc->reference.class) { case ACPI_REFCLASS_REFOF: /* Storing an object into a Name "container" */ status = acpi_ex_store_object_to_node(source_desc, ref_desc->reference. object, walk_state, ACPI_IMPLICIT_CONVERSION); break; case ACPI_REFCLASS_INDEX: /* Storing to an Index (pointer into a packager or buffer) */ status = acpi_ex_store_object_to_index(source_desc, ref_desc, walk_state); break; case ACPI_REFCLASS_LOCAL: case ACPI_REFCLASS_ARG: /* Store to a method local/arg */ status = acpi_ds_store_object_to_local(ref_desc->reference.class, ref_desc->reference.value, source_desc, walk_state); break; case ACPI_REFCLASS_DEBUG: /* * Storing to the Debug object causes the value stored to be * displayed and otherwise has no effect -- see ACPI Specification */ ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "**** Write to Debug Object: Object %p [%s] ****:\n\n", source_desc, acpi_ut_get_object_type_name(source_desc))); ACPI_DEBUG_OBJECT(source_desc, 0, 0); break; default: ACPI_ERROR((AE_INFO, "Unknown Reference Class 0x%2.2X", ref_desc->reference.class)); ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_INFO); status = AE_AML_INTERNAL; break; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_store_object_to_index * * PARAMETERS: *source_desc - Value to be stored * *dest_desc - Named object to receive the value * walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Store the object to indexed Buffer or Package element * ******************************************************************************/ static acpi_status acpi_ex_store_object_to_index(union acpi_operand_object *source_desc, union acpi_operand_object *index_desc, struct acpi_walk_state *walk_state) { acpi_status status = AE_OK; union acpi_operand_object *obj_desc; union acpi_operand_object *new_desc; u8 value = 0; u32 i; ACPI_FUNCTION_TRACE(ex_store_object_to_index); /* * Destination must be a reference pointer, and * must point to either a buffer or a package */ switch (index_desc->reference.target_type) { case ACPI_TYPE_PACKAGE: /* * Storing to a package element. Copy the object and replace * any existing object with the new object. No implicit * conversion is performed. * * The object at *(index_desc->Reference.Where) is the * element within the package that is to be modified. * The parent package object is at index_desc->Reference.Object */ obj_desc = *(index_desc->reference.where); if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE && source_desc->reference.class == ACPI_REFCLASS_TABLE) { /* This is a DDBHandle, just add a reference to it */ acpi_ut_add_reference(source_desc); new_desc = source_desc; } else { /* Normal object, copy it */ status = acpi_ut_copy_iobject_to_iobject(source_desc, &new_desc, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } if (obj_desc) { /* Decrement reference count by the ref count of the parent package */ for (i = 0; i < ((union acpi_operand_object *) index_desc->reference.object)->common. reference_count; i++) { acpi_ut_remove_reference(obj_desc); } } *(index_desc->reference.where) = new_desc; /* Increment ref count by the ref count of the parent package-1 */ for (i = 1; i < ((union acpi_operand_object *) index_desc->reference.object)->common. reference_count; i++) { acpi_ut_add_reference(new_desc); } break; case ACPI_TYPE_BUFFER_FIELD: /* * Store into a Buffer or String (not actually a real buffer_field) * at a location defined by an Index. * * The first 8-bit element of the source object is written to the * 8-bit Buffer location defined by the Index destination object, * according to the ACPI 2.0 specification. */ /* * Make sure the target is a Buffer or String. An error should * not happen here, since the reference_object was constructed * by the INDEX_OP code. */ obj_desc = index_desc->reference.object; if ((obj_desc->common.type != ACPI_TYPE_BUFFER) && (obj_desc->common.type != ACPI_TYPE_STRING)) { return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* * The assignment of the individual elements will be slightly * different for each source type. */ switch (source_desc->common.type) { case ACPI_TYPE_INTEGER: /* Use the least-significant byte of the integer */ value = (u8) (source_desc->integer.value); break; case ACPI_TYPE_BUFFER: case ACPI_TYPE_STRING: /* Note: Takes advantage of common string/buffer fields */ value = source_desc->buffer.pointer[0]; break; default: /* All other types are invalid */ ACPI_ERROR((AE_INFO, "Source must be type [Integer/Buffer/String], found [%s]", acpi_ut_get_object_type_name(source_desc))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* Store the source value into the target buffer byte */ obj_desc->buffer.pointer[index_desc->reference.value] = value; break; default: ACPI_ERROR((AE_INFO, "Target is not of type [Package/BufferField]")); status = AE_AML_TARGET_TYPE; break; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_store_object_to_node * * PARAMETERS: source_desc - Value to be stored * node - Named object to receive the value * walk_state - Current walk state * implicit_conversion - Perform implicit conversion (yes/no) * * RETURN: Status * * DESCRIPTION: Store the object to the named object. * * The assignment of an object to a named object is handled here. * The value passed in will replace the current value (if any) * with the input value. * * When storing into an object the data is converted to the * target object type then stored in the object. This means * that the target object type (for an initialized target) will * not be changed by a store operation. A copy_object can change * the target type, however. * * The implicit_conversion flag is set to NO/FALSE only when * storing to an arg_x -- as per the rules of the ACPI spec. * * Assumes parameters are already validated. * ******************************************************************************/ acpi_status acpi_ex_store_object_to_node(union acpi_operand_object *source_desc, struct acpi_namespace_node *node, struct acpi_walk_state *walk_state, u8 implicit_conversion) { acpi_status status = AE_OK; union acpi_operand_object *target_desc; union acpi_operand_object *new_desc; acpi_object_type target_type; ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc); /* Get current type of the node, and object attached to Node */ target_type = acpi_ns_get_type(node); target_desc = acpi_ns_get_attached_object(node); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p [%s] to node %p [%s]\n", source_desc, acpi_ut_get_object_type_name(source_desc), node, acpi_ut_get_type_name(target_type))); /* Only limited target types possible for everything except copy_object */ if (walk_state->opcode != AML_COPY_OBJECT_OP) { /* * Only copy_object allows all object types to be overwritten. For * target_ref(s), there are restrictions on the object types that * are allowed. * * Allowable operations/typing for Store: * * 1) Simple Store * Integer --> Integer (Named/Local/Arg) * String --> String (Named/Local/Arg) * Buffer --> Buffer (Named/Local/Arg) * Package --> Package (Named/Local/Arg) * * 2) Store with implicit conversion * Integer --> String or Buffer (Named) * String --> Integer or Buffer (Named) * Buffer --> Integer or String (Named) */ switch (target_type) { case ACPI_TYPE_PACKAGE: /* * Here, can only store a package to an existing package. * Storing a package to a Local/Arg is OK, and handled * elsewhere. */ if (walk_state->opcode == AML_STORE_OP) { if (source_desc->common.type != ACPI_TYPE_PACKAGE) { ACPI_ERROR((AE_INFO, "Cannot assign type [%s] to [Package] " "(source must be type Pkg)", acpi_ut_get_object_type_name (source_desc))); return_ACPI_STATUS(AE_AML_TARGET_TYPE); } break; } ACPI_FALLTHROUGH; case ACPI_TYPE_DEVICE: case ACPI_TYPE_EVENT: case ACPI_TYPE_MUTEX: case ACPI_TYPE_REGION: case ACPI_TYPE_POWER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: ACPI_ERROR((AE_INFO, "Target must be [Buffer/Integer/String/Reference]" ", found [%s] (%4.4s)", acpi_ut_get_type_name(node->type), node->name.ascii)); return_ACPI_STATUS(AE_AML_TARGET_TYPE); default: break; } } /* * Resolve the source object to an actual value * (If it is a reference object) */ status = acpi_ex_resolve_object(&source_desc, target_type, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Do the actual store operation */ switch (target_type) { /* * The simple data types all support implicit source operand * conversion before the store. */ case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: if ((walk_state->opcode == AML_COPY_OBJECT_OP) || !implicit_conversion) { /* * However, copy_object and Stores to arg_x do not perform * an implicit conversion, as per the ACPI specification. * A direct store is performed instead. */ status = acpi_ex_store_direct_to_node(source_desc, node, walk_state); break; } /* Store with implicit source operand conversion support */ status = acpi_ex_store_object_to_object(source_desc, target_desc, &new_desc, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (new_desc != target_desc) { /* * Store the new new_desc as the new value of the Name, and set * the Name's type to that of the value being stored in it. * source_desc reference count is incremented by attach_object. * * Note: This may change the type of the node if an explicit * store has been performed such that the node/object type * has been changed. */ status = acpi_ns_attach_object(node, new_desc, new_desc->common.type); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Store type [%s] into [%s] via Convert/Attach\n", acpi_ut_get_object_type_name (source_desc), acpi_ut_get_object_type_name (new_desc))); } break; case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: /* * For all fields, always write the source data to the target * field. Any required implicit source operand conversion is * performed in the function below as necessary. Note, field * objects must retain their original type permanently. */ status = acpi_ex_write_data_to_field(source_desc, target_desc, &walk_state->result_obj); break; default: /* * copy_object operator: No conversions for all other types. * Instead, directly store a copy of the source object. * * This is the ACPI spec-defined behavior for the copy_object * operator. (Note, for this default case, all normal * Store/Target operations exited above with an error). */ status = acpi_ex_store_direct_to_node(source_desc, node, walk_state); break; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_store_direct_to_node * * PARAMETERS: source_desc - Value to be stored * node - Named object to receive the value * walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: "Store" an object directly to a node. This involves a copy * and an attach. * ******************************************************************************/ static acpi_status acpi_ex_store_direct_to_node(union acpi_operand_object *source_desc, struct acpi_namespace_node *node, struct acpi_walk_state *walk_state) { acpi_status status; union acpi_operand_object *new_desc; ACPI_FUNCTION_TRACE(ex_store_direct_to_node); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing [%s] (%p) directly into node [%s] (%p)" " with no implicit conversion\n", acpi_ut_get_object_type_name(source_desc), source_desc, acpi_ut_get_type_name(node->type), node)); /* Copy the source object to a new object */ status = acpi_ut_copy_iobject_to_iobject(source_desc, &new_desc, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Attach the new object to the node */ status = acpi_ns_attach_object(node, new_desc, new_desc->common.type); acpi_ut_remove_reference(new_desc); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exstore.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Name: hwtimer.c - ACPI Power Management Timer Interface * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_HARDWARE ACPI_MODULE_NAME("hwtimer") #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ /****************************************************************************** * * FUNCTION: acpi_get_timer_resolution * * PARAMETERS: resolution - Where the resolution is returned * * RETURN: Status and timer resolution * * DESCRIPTION: Obtains resolution of the ACPI PM Timer (24 or 32 bits). * ******************************************************************************/ acpi_status acpi_get_timer_resolution(u32 * resolution) { ACPI_FUNCTION_TRACE(acpi_get_timer_resolution); if (!resolution) { return_ACPI_STATUS(AE_BAD_PARAMETER); } if ((acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) == 0) { *resolution = 24; } else { *resolution = 32; } return_ACPI_STATUS(AE_OK); } ACPI_EXPORT_SYMBOL(acpi_get_timer_resolution) /****************************************************************************** * * FUNCTION: acpi_get_timer * * PARAMETERS: ticks - Where the timer value is returned * * RETURN: Status and current timer value (ticks) * * DESCRIPTION: Obtains current value of ACPI PM Timer (in ticks). * ******************************************************************************/ acpi_status acpi_get_timer(u32 * ticks) { acpi_status status; u64 timer_value; ACPI_FUNCTION_TRACE(acpi_get_timer); if (!ticks) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* ACPI 5.0A: PM Timer is optional */ if (!acpi_gbl_FADT.xpm_timer_block.address) { return_ACPI_STATUS(AE_SUPPORT); } status = acpi_hw_read(&timer_value, &acpi_gbl_FADT.xpm_timer_block); if (ACPI_SUCCESS(status)) { /* ACPI PM Timer is defined to be 32 bits (PM_TMR_LEN) */ *ticks = (u32)timer_value; } return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_get_timer) /****************************************************************************** * * FUNCTION: acpi_get_timer_duration * * PARAMETERS: start_ticks - Starting timestamp * end_ticks - End timestamp * time_elapsed - Where the elapsed time is returned * * RETURN: Status and time_elapsed * * DESCRIPTION: Computes the time elapsed (in microseconds) between two * PM Timer time stamps, taking into account the possibility of * rollovers, the timer resolution, and timer frequency. * * The PM Timer's clock ticks at roughly 3.6 times per * _microsecond_, and its clock continues through Cx state * transitions (unlike many CPU timestamp counters) -- making it * a versatile and accurate timer. * * Note that this function accommodates only a single timer * rollover. Thus for 24-bit timers, this function should only * be used for calculating durations less than ~4.6 seconds * (~20 minutes for 32-bit timers) -- calculations below: * * 2**24 Ticks / 3,600,000 Ticks/Sec = 4.66 sec * 2**32 Ticks / 3,600,000 Ticks/Sec = 1193 sec or 19.88 minutes * ******************************************************************************/ acpi_status acpi_get_timer_duration(u32 start_ticks, u32 end_ticks, u32 *time_elapsed) { acpi_status status; u64 delta_ticks; u64 quotient; ACPI_FUNCTION_TRACE(acpi_get_timer_duration); if (!time_elapsed) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* ACPI 5.0A: PM Timer is optional */ if (!acpi_gbl_FADT.xpm_timer_block.address) { return_ACPI_STATUS(AE_SUPPORT); } if (start_ticks == end_ticks) { *time_elapsed = 0; return_ACPI_STATUS(AE_OK); } /* * Compute Tick Delta: * Handle (max one) timer rollovers on 24-bit versus 32-bit timers. */ delta_ticks = end_ticks; if (start_ticks > end_ticks) { if ((acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) == 0) { /* 24-bit Timer */ delta_ticks |= (u64)1 << 24; } else { /* 32-bit Timer */ delta_ticks |= (u64)1 << 32; } } delta_ticks -= start_ticks; /* * Compute Duration (Requires a 64-bit multiply and divide): * * time_elapsed (microseconds) = * (delta_ticks * ACPI_USEC_PER_SEC) / ACPI_PM_TIMER_FREQUENCY; */ status = acpi_ut_short_divide(delta_ticks * ACPI_USEC_PER_SEC, ACPI_PM_TIMER_FREQUENCY, &quotient, NULL); *time_elapsed = (u32)quotient; return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_get_timer_duration) #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/hwtimer.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: psutils - Parser miscellaneous utilities (Parser only) * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "amlcode.h" #include "acconvert.h" #define _COMPONENT ACPI_PARSER ACPI_MODULE_NAME("psutils") /******************************************************************************* * * FUNCTION: acpi_ps_create_scope_op * * PARAMETERS: None * * RETURN: A new Scope object, null on failure * * DESCRIPTION: Create a Scope and associated namepath op with the root name * ******************************************************************************/ union acpi_parse_object *acpi_ps_create_scope_op(u8 *aml) { union acpi_parse_object *scope_op; scope_op = acpi_ps_alloc_op(AML_SCOPE_OP, aml); if (!scope_op) { return (NULL); } scope_op->named.name = ACPI_ROOT_NAME; return (scope_op); } /******************************************************************************* * * FUNCTION: acpi_ps_init_op * * PARAMETERS: op - A newly allocated Op object * opcode - Opcode to store in the Op * * RETURN: None * * DESCRIPTION: Initialize a parse (Op) object * ******************************************************************************/ void acpi_ps_init_op(union acpi_parse_object *op, u16 opcode) { ACPI_FUNCTION_ENTRY(); op->common.descriptor_type = ACPI_DESC_TYPE_PARSER; op->common.aml_opcode = opcode; ACPI_DISASM_ONLY_MEMBERS(acpi_ut_safe_strncpy(op->common.aml_op_name, (acpi_ps_get_opcode_info (opcode))->name, sizeof(op->common. aml_op_name))); } /******************************************************************************* * * FUNCTION: acpi_ps_alloc_op * * PARAMETERS: opcode - Opcode that will be stored in the new Op * aml - Address of the opcode * * RETURN: Pointer to the new Op, null on failure * * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on * opcode. A cache of opcodes is available for the pure * GENERIC_OP, since this is by far the most commonly used. * ******************************************************************************/ union acpi_parse_object *acpi_ps_alloc_op(u16 opcode, u8 *aml) { union acpi_parse_object *op; const struct acpi_opcode_info *op_info; u8 flags = ACPI_PARSEOP_GENERIC; ACPI_FUNCTION_ENTRY(); op_info = acpi_ps_get_opcode_info(opcode); /* Determine type of parse_op required */ if (op_info->flags & AML_DEFER) { flags = ACPI_PARSEOP_DEFERRED; } else if (op_info->flags & AML_NAMED) { flags = ACPI_PARSEOP_NAMED_OBJECT; } else if (opcode == AML_INT_BYTELIST_OP) { flags = ACPI_PARSEOP_BYTELIST; } /* Allocate the minimum required size object */ if (flags == ACPI_PARSEOP_GENERIC) { /* The generic op (default) is by far the most common (16 to 1) */ op = acpi_os_acquire_object(acpi_gbl_ps_node_cache); } else { /* Extended parseop */ op = acpi_os_acquire_object(acpi_gbl_ps_node_ext_cache); } /* Initialize the Op */ if (op) { acpi_ps_init_op(op, opcode); op->common.aml = aml; op->common.flags = flags; ASL_CV_CLEAR_OP_COMMENTS(op); if (opcode == AML_SCOPE_OP) { acpi_gbl_current_scope = op; } if (acpi_gbl_capture_comments) { ASL_CV_TRANSFER_COMMENTS(op); } } return (op); } /******************************************************************************* * * FUNCTION: acpi_ps_free_op * * PARAMETERS: op - Op to be freed * * RETURN: None. * * DESCRIPTION: Free an Op object. Either put it on the GENERIC_OP cache list * or actually free it. * ******************************************************************************/ void acpi_ps_free_op(union acpi_parse_object *op) { ACPI_FUNCTION_NAME(ps_free_op); ASL_CV_CLEAR_OP_COMMENTS(op); if (op->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Free retval op: %p\n", op)); } if (op->common.flags & ACPI_PARSEOP_GENERIC) { (void)acpi_os_release_object(acpi_gbl_ps_node_cache, op); } else { (void)acpi_os_release_object(acpi_gbl_ps_node_ext_cache, op); } } /******************************************************************************* * * FUNCTION: Utility functions * * DESCRIPTION: Low level character and object functions * ******************************************************************************/ /* * Is "c" a namestring lead character? */ u8 acpi_ps_is_leading_char(u32 c) { return ((u8) (c == '_' || (c >= 'A' && c <= 'Z'))); } /* * Get op's name (4-byte name segment) or 0 if unnamed */ u32 acpi_ps_get_name(union acpi_parse_object * op) { /* The "generic" object has no name associated with it */ if (op->common.flags & ACPI_PARSEOP_GENERIC) { return (0); } /* Only the "Extended" parse objects have a name */ return (op->named.name); } /* * Set op's name */ void acpi_ps_set_name(union acpi_parse_object *op, u32 name) { /* The "generic" object has no name associated with it */ if (op->common.flags & ACPI_PARSEOP_GENERIC) { return; } op->named.name = name; }
linux-master
drivers/acpi/acpica/psutils.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exmutex - ASL Mutex Acquire/Release functions * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #include "acevents.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exmutex") /* Local prototypes */ static void acpi_ex_link_mutex(union acpi_operand_object *obj_desc, struct acpi_thread_state *thread); /******************************************************************************* * * FUNCTION: acpi_ex_unlink_mutex * * PARAMETERS: obj_desc - The mutex to be unlinked * * RETURN: None * * DESCRIPTION: Remove a mutex from the "AcquiredMutex" list * ******************************************************************************/ void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc) { struct acpi_thread_state *thread = obj_desc->mutex.owner_thread; if (!thread) { return; } /* Doubly linked list */ if (obj_desc->mutex.next) { (obj_desc->mutex.next)->mutex.prev = obj_desc->mutex.prev; } if (obj_desc->mutex.prev) { (obj_desc->mutex.prev)->mutex.next = obj_desc->mutex.next; /* * Migrate the previous sync level associated with this mutex to * the previous mutex on the list so that it may be preserved. * This handles the case where several mutexes have been acquired * at the same level, but are not released in opposite order. */ (obj_desc->mutex.prev)->mutex.original_sync_level = obj_desc->mutex.original_sync_level; } else { thread->acquired_mutex_list = obj_desc->mutex.next; } } /******************************************************************************* * * FUNCTION: acpi_ex_link_mutex * * PARAMETERS: obj_desc - The mutex to be linked * thread - Current executing thread object * * RETURN: None * * DESCRIPTION: Add a mutex to the "AcquiredMutex" list for this walk * ******************************************************************************/ static void acpi_ex_link_mutex(union acpi_operand_object *obj_desc, struct acpi_thread_state *thread) { union acpi_operand_object *list_head; list_head = thread->acquired_mutex_list; /* This object will be the first object in the list */ obj_desc->mutex.prev = NULL; obj_desc->mutex.next = list_head; /* Update old first object to point back to this object */ if (list_head) { list_head->mutex.prev = obj_desc; } /* Update list head */ thread->acquired_mutex_list = obj_desc; } /******************************************************************************* * * FUNCTION: acpi_ex_acquire_mutex_object * * PARAMETERS: timeout - Timeout in milliseconds * obj_desc - Mutex object * thread_id - Current thread state * * RETURN: Status * * DESCRIPTION: Acquire an AML mutex, low-level interface. Provides a common * path that supports multiple acquires by the same thread. * * MUTEX: Interpreter must be locked * * NOTE: This interface is called from three places: * 1) From acpi_ex_acquire_mutex, via an AML Acquire() operator * 2) From acpi_ex_acquire_global_lock when an AML Field access requires the * global lock * 3) From the external interface, acpi_acquire_global_lock * ******************************************************************************/ acpi_status acpi_ex_acquire_mutex_object(u16 timeout, union acpi_operand_object *obj_desc, acpi_thread_id thread_id) { acpi_status status; ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex_object, obj_desc); if (!obj_desc) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Support for multiple acquires by the owning thread */ if (obj_desc->mutex.thread_id == thread_id) { /* * The mutex is already owned by this thread, just increment the * acquisition depth */ obj_desc->mutex.acquisition_depth++; return_ACPI_STATUS(AE_OK); } /* Acquire the mutex, wait if necessary. Special case for Global Lock */ if (obj_desc == acpi_gbl_global_lock_mutex) { status = acpi_ev_acquire_global_lock(timeout); } else { status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex, timeout); } if (ACPI_FAILURE(status)) { /* Includes failure from a timeout on time_desc */ return_ACPI_STATUS(status); } /* Acquired the mutex: update mutex object */ obj_desc->mutex.thread_id = thread_id; obj_desc->mutex.acquisition_depth = 1; obj_desc->mutex.original_sync_level = 0; obj_desc->mutex.owner_thread = NULL; /* Used only for AML Acquire() */ return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ex_acquire_mutex * * PARAMETERS: time_desc - Timeout integer * obj_desc - Mutex object * walk_state - Current method execution state * * RETURN: Status * * DESCRIPTION: Acquire an AML mutex * ******************************************************************************/ acpi_status acpi_ex_acquire_mutex(union acpi_operand_object *time_desc, union acpi_operand_object *obj_desc, struct acpi_walk_state *walk_state) { acpi_status status; ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex, obj_desc); if (!obj_desc) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Must have a valid thread state struct */ if (!walk_state->thread) { ACPI_ERROR((AE_INFO, "Cannot acquire Mutex [%4.4s], null thread info", acpi_ut_get_node_name(obj_desc->mutex.node))); return_ACPI_STATUS(AE_AML_INTERNAL); } /* * Current sync level must be less than or equal to the sync level * of the mutex. This mechanism provides some deadlock prevention. */ if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) { ACPI_ERROR((AE_INFO, "Cannot acquire Mutex [%4.4s], " "current SyncLevel is too large (%u)", acpi_ut_get_node_name(obj_desc->mutex.node), walk_state->thread->current_sync_level)); return_ACPI_STATUS(AE_AML_MUTEX_ORDER); } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Acquiring: Mutex SyncLevel %u, Thread SyncLevel %u, " "Depth %u TID %p\n", obj_desc->mutex.sync_level, walk_state->thread->current_sync_level, obj_desc->mutex.acquisition_depth, walk_state->thread)); status = acpi_ex_acquire_mutex_object((u16)time_desc->integer.value, obj_desc, walk_state->thread->thread_id); if (ACPI_SUCCESS(status) && obj_desc->mutex.acquisition_depth == 1) { /* Save Thread object, original/current sync levels */ obj_desc->mutex.owner_thread = walk_state->thread; obj_desc->mutex.original_sync_level = walk_state->thread->current_sync_level; walk_state->thread->current_sync_level = obj_desc->mutex.sync_level; /* Link the mutex to the current thread for force-unlock at method exit */ acpi_ex_link_mutex(obj_desc, walk_state->thread); } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Acquired: Mutex SyncLevel %u, Thread SyncLevel %u, Depth %u\n", obj_desc->mutex.sync_level, walk_state->thread->current_sync_level, obj_desc->mutex.acquisition_depth)); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_release_mutex_object * * PARAMETERS: obj_desc - The object descriptor for this op * * RETURN: Status * * DESCRIPTION: Release a previously acquired Mutex, low level interface. * Provides a common path that supports multiple releases (after * previous multiple acquires) by the same thread. * * MUTEX: Interpreter must be locked * * NOTE: This interface is called from three places: * 1) From acpi_ex_release_mutex, via an AML Acquire() operator * 2) From acpi_ex_release_global_lock when an AML Field access requires the * global lock * 3) From the external interface, acpi_release_global_lock * ******************************************************************************/ acpi_status acpi_ex_release_mutex_object(union acpi_operand_object *obj_desc) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ex_release_mutex_object); if (obj_desc->mutex.acquisition_depth == 0) { return_ACPI_STATUS(AE_NOT_ACQUIRED); } /* Match multiple Acquires with multiple Releases */ obj_desc->mutex.acquisition_depth--; if (obj_desc->mutex.acquisition_depth != 0) { /* Just decrement the depth and return */ return_ACPI_STATUS(AE_OK); } if (obj_desc->mutex.owner_thread) { /* Unlink the mutex from the owner's list */ acpi_ex_unlink_mutex(obj_desc); obj_desc->mutex.owner_thread = NULL; } /* Release the mutex, special case for Global Lock */ if (obj_desc == acpi_gbl_global_lock_mutex) { status = acpi_ev_release_global_lock(); } else { acpi_os_release_mutex(obj_desc->mutex.os_mutex); } /* Clear mutex info */ obj_desc->mutex.thread_id = 0; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_release_mutex * * PARAMETERS: obj_desc - The object descriptor for this op * walk_state - Current method execution state * * RETURN: Status * * DESCRIPTION: Release a previously acquired Mutex. * ******************************************************************************/ acpi_status acpi_ex_release_mutex(union acpi_operand_object *obj_desc, struct acpi_walk_state *walk_state) { u8 previous_sync_level; struct acpi_thread_state *owner_thread; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ex_release_mutex); if (!obj_desc) { return_ACPI_STATUS(AE_BAD_PARAMETER); } owner_thread = obj_desc->mutex.owner_thread; /* The mutex must have been previously acquired in order to release it */ if (!owner_thread) { ACPI_ERROR((AE_INFO, "Cannot release Mutex [%4.4s], not acquired", acpi_ut_get_node_name(obj_desc->mutex.node))); return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED); } /* Must have a valid thread ID */ if (!walk_state->thread) { ACPI_ERROR((AE_INFO, "Cannot release Mutex [%4.4s], null thread info", acpi_ut_get_node_name(obj_desc->mutex.node))); return_ACPI_STATUS(AE_AML_INTERNAL); } /* * The Mutex is owned, but this thread must be the owner. * Special case for Global Lock, any thread can release */ if ((owner_thread->thread_id != walk_state->thread->thread_id) && (obj_desc != acpi_gbl_global_lock_mutex)) { ACPI_ERROR((AE_INFO, "Thread %u cannot release Mutex [%4.4s] acquired by thread %u", (u32)walk_state->thread->thread_id, acpi_ut_get_node_name(obj_desc->mutex.node), (u32)owner_thread->thread_id)); return_ACPI_STATUS(AE_AML_NOT_OWNER); } /* * The sync level of the mutex must be equal to the current sync level. In * other words, the current level means that at least one mutex at that * level is currently being held. Attempting to release a mutex of a * different level can only mean that the mutex ordering rule is being * violated. This behavior is clarified in ACPI 4.0 specification. */ if (obj_desc->mutex.sync_level != owner_thread->current_sync_level) { ACPI_ERROR((AE_INFO, "Cannot release Mutex [%4.4s], SyncLevel mismatch: " "mutex %u current %u", acpi_ut_get_node_name(obj_desc->mutex.node), obj_desc->mutex.sync_level, walk_state->thread->current_sync_level)); return_ACPI_STATUS(AE_AML_MUTEX_ORDER); } /* * Get the previous sync_level from the head of the acquired mutex list. * This handles the case where several mutexes at the same level have been * acquired, but are not released in reverse order. */ previous_sync_level = owner_thread->acquired_mutex_list->mutex.original_sync_level; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Releasing: Object SyncLevel %u, Thread SyncLevel %u, " "Prev SyncLevel %u, Depth %u TID %p\n", obj_desc->mutex.sync_level, walk_state->thread->current_sync_level, previous_sync_level, obj_desc->mutex.acquisition_depth, walk_state->thread)); status = acpi_ex_release_mutex_object(obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (obj_desc->mutex.acquisition_depth == 0) { /* Restore the previous sync_level */ owner_thread->current_sync_level = previous_sync_level; } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Released: Object SyncLevel %u, Thread SyncLevel, %u, " "Prev SyncLevel %u, Depth %u\n", obj_desc->mutex.sync_level, walk_state->thread->current_sync_level, previous_sync_level, obj_desc->mutex.acquisition_depth)); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_release_all_mutexes * * PARAMETERS: thread - Current executing thread object * * RETURN: Status * * DESCRIPTION: Release all mutexes held by this thread * * NOTE: This function is called as the thread is exiting the interpreter. * Mutexes are not released when an individual control method is exited, but * only when the parent thread actually exits the interpreter. This allows one * method to acquire a mutex, and a different method to release it, as long as * this is performed underneath a single parent control method. * ******************************************************************************/ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread) { union acpi_operand_object *next = thread->acquired_mutex_list; union acpi_operand_object *obj_desc; ACPI_FUNCTION_TRACE(ex_release_all_mutexes); /* Traverse the list of owned mutexes, releasing each one */ while (next) { obj_desc = next; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Mutex [%4.4s] force-release, SyncLevel %u Depth %u\n", obj_desc->mutex.node->name.ascii, obj_desc->mutex.sync_level, obj_desc->mutex.acquisition_depth)); /* Release the mutex, special case for Global Lock */ if (obj_desc == acpi_gbl_global_lock_mutex) { /* Ignore errors */ (void)acpi_ev_release_global_lock(); } else { acpi_os_release_mutex(obj_desc->mutex.os_mutex); } /* Update Thread sync_level (Last mutex is the important one) */ thread->current_sync_level = obj_desc->mutex.original_sync_level; /* Mark mutex unowned */ next = obj_desc->mutex.next; obj_desc->mutex.prev = NULL; obj_desc->mutex.next = NULL; obj_desc->mutex.acquisition_depth = 0; obj_desc->mutex.owner_thread = NULL; obj_desc->mutex.thread_id = 0; } return_VOID; }
linux-master
drivers/acpi/acpica/exmutex.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nsdump - table dumping routines for debug * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> /* TBD: This entire module is apparently obsolete and should be removed */ #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsdumpdv") #ifdef ACPI_OBSOLETE_FUNCTIONS #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) #include "acnamesp.h" /******************************************************************************* * * FUNCTION: acpi_ns_dump_one_device * * PARAMETERS: handle - Node to be dumped * level - Nesting level of the handle * context - Passed into walk_namespace * return_value - Not used * * RETURN: Status * * DESCRIPTION: Dump a single Node that represents a device * This procedure is a user_function called by acpi_ns_walk_namespace. * ******************************************************************************/ static acpi_status acpi_ns_dump_one_device(acpi_handle obj_handle, u32 level, void *context, void **return_value) { struct acpi_buffer buffer; struct acpi_device_info *info; acpi_status status; u32 i; ACPI_FUNCTION_NAME(ns_dump_one_device); status = acpi_ns_dump_one_object(obj_handle, level, context, return_value); buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_get_object_info(obj_handle, &buffer); if (ACPI_SUCCESS(status)) { info = buffer.pointer; for (i = 0; i < level; i++) { ACPI_DEBUG_PRINT_RAW((ACPI_DB_TABLES, " ")); } ACPI_DEBUG_PRINT_RAW((ACPI_DB_TABLES, " HID: %s, ADR: %8.8X%8.8X\n", info->hardware_id.value, ACPI_FORMAT_UINT64(info->address))); ACPI_FREE(info); } return (status); } /******************************************************************************* * * FUNCTION: acpi_ns_dump_root_devices * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Dump all objects of type "device" * ******************************************************************************/ void acpi_ns_dump_root_devices(void) { acpi_handle sys_bus_handle; acpi_status status; ACPI_FUNCTION_NAME(ns_dump_root_devices); /* Only dump the table if tracing is enabled */ if (!(ACPI_LV_TABLES & acpi_dbg_level)) { return; } status = acpi_get_handle(NULL, METHOD_NAME__SB_, &sys_bus_handle); if (ACPI_FAILURE(status)) { return; } ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Display of all devices in the namespace:\n")); status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, sys_bus_handle, ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, acpi_ns_dump_one_device, NULL, NULL, NULL); } #endif #endif
linux-master
drivers/acpi/acpica/nsdumpdv.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: rsio - IO and DMA resource descriptors * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rsio") /******************************************************************************* * * acpi_rs_convert_io * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_io[5] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_IO, ACPI_RS_SIZE(struct acpi_resource_io), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_io)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_IO, sizeof(struct aml_resource_io), 0}, /* Decode flag */ {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.io.io_decode), AML_OFFSET(io.flags), 0}, /* * These fields are contiguous in both the source and destination: * Address Alignment * Length * Minimum Base Address * Maximum Base Address */ {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.io.alignment), AML_OFFSET(io.alignment), 2}, {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.io.minimum), AML_OFFSET(io.minimum), 2} }; /******************************************************************************* * * acpi_rs_convert_fixed_io * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_fixed_io[4] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_FIXED_IO, ACPI_RS_SIZE(struct acpi_resource_fixed_io), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_fixed_io)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_FIXED_IO, sizeof(struct aml_resource_fixed_io), 0}, /* * These fields are contiguous in both the source and destination: * Base Address * Length */ {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.fixed_io.address_length), AML_OFFSET(fixed_io.address_length), 1}, {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.fixed_io.address), AML_OFFSET(fixed_io.address), 1} }; /******************************************************************************* * * acpi_rs_convert_generic_reg * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_generic_reg[4] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_GENERIC_REGISTER, ACPI_RS_SIZE(struct acpi_resource_generic_register), ACPI_RSC_TABLE_SIZE(acpi_rs_convert_generic_reg)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_GENERIC_REGISTER, sizeof(struct aml_resource_generic_register), 0}, /* * These fields are contiguous in both the source and destination: * Address Space ID * Register Bit Width * Register Bit Offset * Access Size */ {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.generic_reg.space_id), AML_OFFSET(generic_reg.address_space_id), 4}, /* Get the Register Address */ {ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.generic_reg.address), AML_OFFSET(generic_reg.address), 1} }; /******************************************************************************* * * acpi_rs_convert_end_dpf * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_end_dpf[2] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_END_DEPENDENT, ACPI_RS_SIZE_MIN, ACPI_RSC_TABLE_SIZE(acpi_rs_convert_end_dpf)}, {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_END_DEPENDENT, sizeof(struct aml_resource_end_dependent), 0} }; /******************************************************************************* * * acpi_rs_convert_end_tag * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_convert_end_tag[2] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_END_TAG, ACPI_RS_SIZE_MIN, ACPI_RSC_TABLE_SIZE(acpi_rs_convert_end_tag)}, /* * Note: The checksum field is set to zero, meaning that the resource * data is treated as if the checksum operation succeeded. * (ACPI Spec 1.0b Section 6.4.2.8) */ {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_END_TAG, sizeof(struct aml_resource_end_tag), 0} }; /******************************************************************************* * * acpi_rs_get_start_dpf * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_get_start_dpf[6] = { {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_START_DEPENDENT, ACPI_RS_SIZE(struct acpi_resource_start_dependent), ACPI_RSC_TABLE_SIZE(acpi_rs_get_start_dpf)}, /* Defaults for Compatibility and Performance priorities */ {ACPI_RSC_SET8, ACPI_RS_OFFSET(data.start_dpf.compatibility_priority), ACPI_ACCEPTABLE_CONFIGURATION, 2}, /* Get the descriptor length (0 or 1 for Start Dpf descriptor) */ {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.start_dpf.descriptor_length), AML_OFFSET(start_dpf.descriptor_type), 0}, /* All done if there is no flag byte present in the descriptor */ {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_AML_LENGTH, 0, 1}, /* Flag byte is present, get the flags */ {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.start_dpf.compatibility_priority), AML_OFFSET(start_dpf.flags), 0}, {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.start_dpf.performance_robustness), AML_OFFSET(start_dpf.flags), 2} }; /******************************************************************************* * * acpi_rs_set_start_dpf * ******************************************************************************/ struct acpi_rsconvert_info acpi_rs_set_start_dpf[10] = { /* Start with a default descriptor of length 1 */ {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_START_DEPENDENT, sizeof(struct aml_resource_start_dependent), ACPI_RSC_TABLE_SIZE(acpi_rs_set_start_dpf)}, /* Set the default flag values */ {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.start_dpf.compatibility_priority), AML_OFFSET(start_dpf.flags), 0}, {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.start_dpf.performance_robustness), AML_OFFSET(start_dpf.flags), 2}, /* * All done if the output descriptor length is required to be 1 * (i.e., optimization to 0 bytes cannot be attempted) */ {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE, ACPI_RS_OFFSET(data.start_dpf.descriptor_length), 1}, /* Set length to 0 bytes (no flags byte) */ {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_start_dependent_noprio)}, /* * All done if the output descriptor length is required to be 0. * * TBD: Perhaps we should check for error if input flags are not * compatible with a 0-byte descriptor. */ {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE, ACPI_RS_OFFSET(data.start_dpf.descriptor_length), 0}, /* Reset length to 1 byte (descriptor with flags byte) */ {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_start_dependent)}, /* * All done if flags byte is necessary -- if either priority value * is not ACPI_ACCEPTABLE_CONFIGURATION */ {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE, ACPI_RS_OFFSET(data.start_dpf.compatibility_priority), ACPI_ACCEPTABLE_CONFIGURATION}, {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_VALUE, ACPI_RS_OFFSET(data.start_dpf.performance_robustness), ACPI_ACCEPTABLE_CONFIGURATION}, /* Flag byte is not necessary */ {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_start_dependent_noprio)} };
linux-master
drivers/acpi/acpica/rsio.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: utstring - Common functions for strings and characters * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utstring") /******************************************************************************* * * FUNCTION: acpi_ut_print_string * * PARAMETERS: string - Null terminated ASCII string * max_length - Maximum output length. Used to constrain the * length of strings during debug output only. * * RETURN: None * * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape * sequences. * ******************************************************************************/ void acpi_ut_print_string(char *string, u16 max_length) { u32 i; if (!string) { acpi_os_printf("<\"NULL STRING PTR\">"); return; } acpi_os_printf("\""); for (i = 0; (i < max_length) && string[i]; i++) { /* Escape sequences */ switch (string[i]) { case 0x07: acpi_os_printf("\\a"); /* BELL */ break; case 0x08: acpi_os_printf("\\b"); /* BACKSPACE */ break; case 0x0C: acpi_os_printf("\\f"); /* FORMFEED */ break; case 0x0A: acpi_os_printf("\\n"); /* LINEFEED */ break; case 0x0D: acpi_os_printf("\\r"); /* CARRIAGE RETURN */ break; case 0x09: acpi_os_printf("\\t"); /* HORIZONTAL TAB */ break; case 0x0B: acpi_os_printf("\\v"); /* VERTICAL TAB */ break; case '\'': /* Single Quote */ case '\"': /* Double Quote */ case '\\': /* Backslash */ acpi_os_printf("\\%c", (int)string[i]); break; default: /* Check for printable character or hex escape */ if (isprint((int)string[i])) { /* This is a normal character */ acpi_os_printf("%c", (int)string[i]); } else { /* All others will be Hex escapes */ acpi_os_printf("\\x%2.2X", (s32)string[i]); } break; } } acpi_os_printf("\""); if (i == max_length && string[i]) { acpi_os_printf("..."); } } /******************************************************************************* * * FUNCTION: acpi_ut_repair_name * * PARAMETERS: name - The ACPI name to be repaired * * RETURN: Repaired version of the name * * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and * return the new name. NOTE: the Name parameter must reside in * read/write memory, cannot be a const. * * An ACPI Name must consist of valid ACPI characters. We will repair the name * if necessary because we don't want to abort because of this, but we want * all namespace names to be printable. A warning message is appropriate. * * This issue came up because there are in fact machines that exhibit * this problem, and we want to be able to enable ACPI support for them, * even though there are a few bad names. * ******************************************************************************/ void acpi_ut_repair_name(char *name) { u32 i; u8 found_bad_char = FALSE; u32 original_name; ACPI_FUNCTION_NAME(ut_repair_name); /* * Special case for the root node. This can happen if we get an * error during the execution of module-level code. */ if (ACPI_COMPARE_NAMESEG(name, ACPI_ROOT_PATHNAME)) { return; } ACPI_COPY_NAMESEG(&original_name, &name[0]); /* Check each character in the name */ for (i = 0; i < ACPI_NAMESEG_SIZE; i++) { if (acpi_ut_valid_name_char(name[i], i)) { continue; } /* * Replace a bad character with something printable, yet technically * "odd". This prevents any collisions with existing "good" * names in the namespace. */ name[i] = '_'; found_bad_char = TRUE; } if (found_bad_char) { /* Report warning only if in strict mode or debug mode */ if (!acpi_gbl_enable_interpreter_slack) { ACPI_WARNING((AE_INFO, "Invalid character(s) in name (0x%.8X) %p, repaired: [%4.4s]", original_name, name, &name[0])); } else { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]", original_name, name)); } } } #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP /******************************************************************************* * * FUNCTION: ut_convert_backslashes * * PARAMETERS: pathname - File pathname string to be converted * * RETURN: Modifies the input Pathname * * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within * the entire input file pathname string. * ******************************************************************************/ void ut_convert_backslashes(char *pathname) { if (!pathname) { return; } while (*pathname) { if (*pathname == '\\') { *pathname = '/'; } pathname++; } } #endif
linux-master
drivers/acpi/acpica/utstring.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utdecode - Utility decoding routines (value-to-string) * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "amlcode.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utdecode") /* * Properties of the ACPI Object Types, both internal and external. * The table is indexed by values of acpi_object_type */ const u8 acpi_gbl_ns_properties[ACPI_NUM_NS_TYPES] = { ACPI_NS_NORMAL, /* 00 Any */ ACPI_NS_NORMAL, /* 01 Number */ ACPI_NS_NORMAL, /* 02 String */ ACPI_NS_NORMAL, /* 03 Buffer */ ACPI_NS_NORMAL, /* 04 Package */ ACPI_NS_NORMAL, /* 05 field_unit */ ACPI_NS_NEWSCOPE, /* 06 Device */ ACPI_NS_NORMAL, /* 07 Event */ ACPI_NS_NEWSCOPE, /* 08 Method */ ACPI_NS_NORMAL, /* 09 Mutex */ ACPI_NS_NORMAL, /* 10 Region */ ACPI_NS_NEWSCOPE, /* 11 Power */ ACPI_NS_NEWSCOPE, /* 12 Processor */ ACPI_NS_NEWSCOPE, /* 13 Thermal */ ACPI_NS_NORMAL, /* 14 buffer_field */ ACPI_NS_NORMAL, /* 15 ddb_handle */ ACPI_NS_NORMAL, /* 16 Debug Object */ ACPI_NS_NORMAL, /* 17 def_field */ ACPI_NS_NORMAL, /* 18 bank_field */ ACPI_NS_NORMAL, /* 19 index_field */ ACPI_NS_NORMAL, /* 20 Reference */ ACPI_NS_NORMAL, /* 21 Alias */ ACPI_NS_NORMAL, /* 22 method_alias */ ACPI_NS_NORMAL, /* 23 Notify */ ACPI_NS_NORMAL, /* 24 Address Handler */ ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL, /* 25 Resource Desc */ ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL, /* 26 Resource Field */ ACPI_NS_NEWSCOPE, /* 27 Scope */ ACPI_NS_NORMAL, /* 28 Extra */ ACPI_NS_NORMAL, /* 29 Data */ ACPI_NS_NORMAL /* 30 Invalid */ }; /******************************************************************************* * * FUNCTION: acpi_ut_get_region_name * * PARAMETERS: Space ID - ID for the region * * RETURN: Decoded region space_id name * * DESCRIPTION: Translate a Space ID into a name string (Debug only) * ******************************************************************************/ /* Region type decoding */ const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] = { "SystemMemory", /* 0x00 */ "SystemIO", /* 0x01 */ "PCI_Config", /* 0x02 */ "EmbeddedControl", /* 0x03 */ "SMBus", /* 0x04 */ "SystemCMOS", /* 0x05 */ "PCIBARTarget", /* 0x06 */ "IPMI", /* 0x07 */ "GeneralPurposeIo", /* 0x08 */ "GenericSerialBus", /* 0x09 */ "PCC", /* 0x0A */ "PlatformRtMechanism" /* 0x0B */ }; const char *acpi_ut_get_region_name(u8 space_id) { if (space_id >= ACPI_USER_REGION_BEGIN) { return ("UserDefinedRegion"); } else if (space_id == ACPI_ADR_SPACE_DATA_TABLE) { return ("DataTable"); } else if (space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { return ("FunctionalFixedHW"); } else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS) { return ("InvalidSpaceId"); } return (acpi_gbl_region_types[space_id]); } /******************************************************************************* * * FUNCTION: acpi_ut_get_event_name * * PARAMETERS: event_id - Fixed event ID * * RETURN: Decoded event ID name * * DESCRIPTION: Translate a Event ID into a name string (Debug only) * ******************************************************************************/ /* Event type decoding */ static const char *acpi_gbl_event_types[ACPI_NUM_FIXED_EVENTS] = { "PM_Timer", "GlobalLock", "PowerButton", "SleepButton", "RealTimeClock", }; const char *acpi_ut_get_event_name(u32 event_id) { if (event_id > ACPI_EVENT_MAX) { return ("InvalidEventID"); } return (acpi_gbl_event_types[event_id]); } /******************************************************************************* * * FUNCTION: acpi_ut_get_type_name * * PARAMETERS: type - An ACPI object type * * RETURN: Decoded ACPI object type name * * DESCRIPTION: Translate a Type ID into a name string (Debug only) * ******************************************************************************/ /* * Elements of acpi_gbl_ns_type_names below must match * one-to-one with values of acpi_object_type * * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching; * when stored in a table it really means that we have thus far seen no * evidence to indicate what type is actually going to be stored for this & entry. */ static const char acpi_gbl_bad_type[] = "UNDEFINED"; /* Printable names of the ACPI object types */ static const char *acpi_gbl_ns_type_names[] = { /* 00 */ "Untyped", /* 01 */ "Integer", /* 02 */ "String", /* 03 */ "Buffer", /* 04 */ "Package", /* 05 */ "FieldUnit", /* 06 */ "Device", /* 07 */ "Event", /* 08 */ "Method", /* 09 */ "Mutex", /* 10 */ "Region", /* 11 */ "Power", /* 12 */ "Processor", /* 13 */ "Thermal", /* 14 */ "BufferField", /* 15 */ "DdbHandle", /* 16 */ "DebugObject", /* 17 */ "RegionField", /* 18 */ "BankField", /* 19 */ "IndexField", /* 20 */ "Reference", /* 21 */ "Alias", /* 22 */ "MethodAlias", /* 23 */ "Notify", /* 24 */ "AddrHandler", /* 25 */ "ResourceDesc", /* 26 */ "ResourceFld", /* 27 */ "Scope", /* 28 */ "Extra", /* 29 */ "Data", /* 30 */ "Invalid" }; const char *acpi_ut_get_type_name(acpi_object_type type) { if (type > ACPI_TYPE_INVALID) { return (acpi_gbl_bad_type); } return (acpi_gbl_ns_type_names[type]); } const char *acpi_ut_get_object_type_name(union acpi_operand_object *obj_desc) { ACPI_FUNCTION_TRACE(ut_get_object_type_name); if (!obj_desc) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Null Object Descriptor\n")); return_STR("[NULL Object Descriptor]"); } /* These descriptor types share a common area */ if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) && (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_NAMED)) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Invalid object descriptor type: 0x%2.2X [%s] (%p)\n", ACPI_GET_DESCRIPTOR_TYPE(obj_desc), acpi_ut_get_descriptor_name(obj_desc), obj_desc)); return_STR("Invalid object"); } return_STR(acpi_ut_get_type_name(obj_desc->common.type)); } /******************************************************************************* * * FUNCTION: acpi_ut_get_node_name * * PARAMETERS: object - A namespace node * * RETURN: ASCII name of the node * * DESCRIPTION: Validate the node and return the node's ACPI name. * ******************************************************************************/ const char *acpi_ut_get_node_name(void *object) { struct acpi_namespace_node *node = (struct acpi_namespace_node *)object; /* Must return a string of exactly 4 characters == ACPI_NAMESEG_SIZE */ if (!object) { return ("NULL"); } /* Check for Root node */ if ((object == ACPI_ROOT_OBJECT) || (object == acpi_gbl_root_node)) { return ("\"\\\" "); } /* Descriptor must be a namespace node */ if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) { return ("####"); } /* * Ensure name is valid. The name was validated/repaired when the node * was created, but make sure it has not been corrupted. */ acpi_ut_repair_name(node->name.ascii); /* Return the name */ return (node->name.ascii); } /******************************************************************************* * * FUNCTION: acpi_ut_get_descriptor_name * * PARAMETERS: object - An ACPI object * * RETURN: Decoded name of the descriptor type * * DESCRIPTION: Validate object and return the descriptor type * ******************************************************************************/ /* Printable names of object descriptor types */ static const char *acpi_gbl_desc_type_names[] = { /* 00 */ "Not a Descriptor", /* 01 */ "Cached Object", /* 02 */ "State-Generic", /* 03 */ "State-Update", /* 04 */ "State-Package", /* 05 */ "State-Control", /* 06 */ "State-RootParseScope", /* 07 */ "State-ParseScope", /* 08 */ "State-WalkScope", /* 09 */ "State-Result", /* 10 */ "State-Notify", /* 11 */ "State-Thread", /* 12 */ "Tree Walk State", /* 13 */ "Parse Tree Op", /* 14 */ "Operand Object", /* 15 */ "Namespace Node" }; const char *acpi_ut_get_descriptor_name(void *object) { if (!object) { return ("NULL OBJECT"); } if (ACPI_GET_DESCRIPTOR_TYPE(object) > ACPI_DESC_TYPE_MAX) { return ("Not a Descriptor"); } return (acpi_gbl_desc_type_names[ACPI_GET_DESCRIPTOR_TYPE(object)]); } /******************************************************************************* * * FUNCTION: acpi_ut_get_reference_name * * PARAMETERS: object - An ACPI reference object * * RETURN: Decoded name of the type of reference * * DESCRIPTION: Decode a reference object sub-type to a string. * ******************************************************************************/ /* Printable names of reference object sub-types */ static const char *acpi_gbl_ref_class_names[] = { /* 00 */ "Local", /* 01 */ "Argument", /* 02 */ "RefOf", /* 03 */ "Index", /* 04 */ "DdbHandle", /* 05 */ "Named Object", /* 06 */ "Debug" }; const char *acpi_ut_get_reference_name(union acpi_operand_object *object) { if (!object) { return ("NULL Object"); } if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) { return ("Not an Operand object"); } if (object->common.type != ACPI_TYPE_LOCAL_REFERENCE) { return ("Not a Reference object"); } if (object->reference.class > ACPI_REFCLASS_MAX) { return ("Unknown Reference class"); } return (acpi_gbl_ref_class_names[object->reference.class]); } /******************************************************************************* * * FUNCTION: acpi_ut_get_mutex_name * * PARAMETERS: mutex_id - The predefined ID for this mutex. * * RETURN: Decoded name of the internal mutex * * DESCRIPTION: Translate a mutex ID into a name string (Debug only) * ******************************************************************************/ /* Names for internal mutex objects, used for debug output */ static const char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = { "ACPI_MTX_Interpreter", "ACPI_MTX_Namespace", "ACPI_MTX_Tables", "ACPI_MTX_Events", "ACPI_MTX_Caches", "ACPI_MTX_Memory", }; const char *acpi_ut_get_mutex_name(u32 mutex_id) { if (mutex_id > ACPI_MAX_MUTEX) { return ("Invalid Mutex ID"); } return (acpi_gbl_mutex_names[mutex_id]); } #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) /* * Strings and procedures used for debug only */ /******************************************************************************* * * FUNCTION: acpi_ut_get_notify_name * * PARAMETERS: notify_value - Value from the Notify() request * * RETURN: Decoded name for the notify value * * DESCRIPTION: Translate a Notify Value to a notify namestring. * ******************************************************************************/ /* Names for Notify() values, used for debug output */ static const char *acpi_gbl_generic_notify[ACPI_GENERIC_NOTIFY_MAX + 1] = { /* 00 */ "Bus Check", /* 01 */ "Device Check", /* 02 */ "Device Wake", /* 03 */ "Eject Request", /* 04 */ "Device Check Light", /* 05 */ "Frequency Mismatch", /* 06 */ "Bus Mode Mismatch", /* 07 */ "Power Fault", /* 08 */ "Capabilities Check", /* 09 */ "Device PLD Check", /* 0A */ "Reserved", /* 0B */ "System Locality Update", /* 0C */ "Reserved (was previously Shutdown Request)", /* Reserved in ACPI 6.0 */ /* 0D */ "System Resource Affinity Update", /* 0E */ "Heterogeneous Memory Attributes Update", /* ACPI 6.2 */ /* 0F */ "Error Disconnect Recover" /* ACPI 6.3 */ }; static const char *acpi_gbl_device_notify[5] = { /* 80 */ "Status Change", /* 81 */ "Information Change", /* 82 */ "Device-Specific Change", /* 83 */ "Device-Specific Change", /* 84 */ "Reserved" }; static const char *acpi_gbl_processor_notify[5] = { /* 80 */ "Performance Capability Change", /* 81 */ "C-State Change", /* 82 */ "Throttling Capability Change", /* 83 */ "Guaranteed Change", /* 84 */ "Minimum Excursion" }; static const char *acpi_gbl_thermal_notify[5] = { /* 80 */ "Thermal Status Change", /* 81 */ "Thermal Trip Point Change", /* 82 */ "Thermal Device List Change", /* 83 */ "Thermal Relationship Change", /* 84 */ "Reserved" }; const char *acpi_ut_get_notify_name(u32 notify_value, acpi_object_type type) { /* 00 - 0F are "common to all object types" (from ACPI Spec) */ if (notify_value <= ACPI_GENERIC_NOTIFY_MAX) { return (acpi_gbl_generic_notify[notify_value]); } /* 10 - 7F are reserved */ if (notify_value <= ACPI_MAX_SYS_NOTIFY) { return ("Reserved"); } /* 80 - 84 are per-object-type */ if (notify_value <= ACPI_SPECIFIC_NOTIFY_MAX) { switch (type) { case ACPI_TYPE_ANY: case ACPI_TYPE_DEVICE: return (acpi_gbl_device_notify[notify_value - 0x80]); case ACPI_TYPE_PROCESSOR: return (acpi_gbl_processor_notify[notify_value - 0x80]); case ACPI_TYPE_THERMAL: return (acpi_gbl_thermal_notify[notify_value - 0x80]); default: return ("Target object type does not support notifies"); } } /* 84 - BF are device-specific */ if (notify_value <= ACPI_MAX_DEVICE_SPECIFIC_NOTIFY) { return ("Device-Specific"); } /* C0 and above are hardware-specific */ return ("Hardware-Specific"); } /******************************************************************************* * * FUNCTION: acpi_ut_get_argument_type_name * * PARAMETERS: arg_type - an ARGP_* parser argument type * * RETURN: Decoded ARGP_* type * * DESCRIPTION: Decode an ARGP_* parser type, as defined in the amlcode.h file, * and used in the acopcode.h file. For example, ARGP_TERMARG. * Used for debug only. * ******************************************************************************/ static const char *acpi_gbl_argument_type[20] = { /* 00 */ "Unknown ARGP", /* 01 */ "ByteData", /* 02 */ "ByteList", /* 03 */ "CharList", /* 04 */ "DataObject", /* 05 */ "DataObjectList", /* 06 */ "DWordData", /* 07 */ "FieldList", /* 08 */ "Name", /* 09 */ "NameString", /* 0A */ "ObjectList", /* 0B */ "PackageLength", /* 0C */ "SuperName", /* 0D */ "Target", /* 0E */ "TermArg", /* 0F */ "TermList", /* 10 */ "WordData", /* 11 */ "QWordData", /* 12 */ "SimpleName", /* 13 */ "NameOrRef" }; const char *acpi_ut_get_argument_type_name(u32 arg_type) { if (arg_type > ARGP_MAX) { return ("Unknown ARGP"); } return (acpi_gbl_argument_type[arg_type]); } #endif /******************************************************************************* * * FUNCTION: acpi_ut_valid_object_type * * PARAMETERS: type - Object type to be validated * * RETURN: TRUE if valid object type, FALSE otherwise * * DESCRIPTION: Validate an object type * ******************************************************************************/ u8 acpi_ut_valid_object_type(acpi_object_type type) { if (type > ACPI_TYPE_LOCAL_MAX) { /* Note: Assumes all TYPEs are contiguous (external/local) */ return (FALSE); } return (TRUE); }
linux-master
drivers/acpi/acpica/utdecode.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: dbmethod - Debug commands for control methods * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdispat.h" #include "acnamesp.h" #include "acdebug.h" #include "acparser.h" #include "acpredef.h" #define _COMPONENT ACPI_CA_DEBUGGER ACPI_MODULE_NAME("dbmethod") /* Local prototypes */ static acpi_status acpi_db_walk_for_execute(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_db_evaluate_object(struct acpi_namespace_node *node); /******************************************************************************* * * FUNCTION: acpi_db_set_method_breakpoint * * PARAMETERS: location - AML offset of breakpoint * walk_state - Current walk info * op - Current Op (from parse walk) * * RETURN: None * * DESCRIPTION: Set a breakpoint in a control method at the specified * AML offset * ******************************************************************************/ void acpi_db_set_method_breakpoint(char *location, struct acpi_walk_state *walk_state, union acpi_parse_object *op) { u32 address; u32 aml_offset; if (!op) { acpi_os_printf("There is no method currently executing\n"); return; } /* Get and verify the breakpoint address */ address = strtoul(location, NULL, 16); aml_offset = (u32)ACPI_PTR_DIFF(op->common.aml, walk_state->parser_state.aml_start); if (address <= aml_offset) { acpi_os_printf("Breakpoint %X is beyond current address %X\n", address, aml_offset); } /* Save breakpoint in current walk */ walk_state->user_breakpoint = address; acpi_os_printf("Breakpoint set at AML offset %X\n", address); } /******************************************************************************* * * FUNCTION: acpi_db_set_method_call_breakpoint * * PARAMETERS: op - Current Op (from parse walk) * * RETURN: None * * DESCRIPTION: Set a breakpoint in a control method at the specified * AML offset * ******************************************************************************/ void acpi_db_set_method_call_breakpoint(union acpi_parse_object *op) { if (!op) { acpi_os_printf("There is no method currently executing\n"); return; } acpi_gbl_step_to_next_call = TRUE; } /******************************************************************************* * * FUNCTION: acpi_db_set_method_data * * PARAMETERS: type_arg - L for local, A for argument * index_arg - which one * value_arg - Value to set. * * RETURN: None * * DESCRIPTION: Set a local or argument for the running control method. * NOTE: only object supported is Number. * ******************************************************************************/ void acpi_db_set_method_data(char *type_arg, char *index_arg, char *value_arg) { char type; u32 index; u32 value; struct acpi_walk_state *walk_state; union acpi_operand_object *obj_desc; acpi_status status; struct acpi_namespace_node *node; /* Validate type_arg */ acpi_ut_strupr(type_arg); type = type_arg[0]; if ((type != 'L') && (type != 'A') && (type != 'N')) { acpi_os_printf("Invalid SET operand: %s\n", type_arg); return; } value = strtoul(value_arg, NULL, 16); if (type == 'N') { node = acpi_db_convert_to_node(index_arg); if (!node) { return; } if (node->type != ACPI_TYPE_INTEGER) { acpi_os_printf("Can only set Integer nodes\n"); return; } obj_desc = node->object; obj_desc->integer.value = value; return; } /* Get the index and value */ index = strtoul(index_arg, NULL, 16); walk_state = acpi_ds_get_current_walk_state(acpi_gbl_current_walk_list); if (!walk_state) { acpi_os_printf("There is no method currently executing\n"); return; } /* Create and initialize the new object */ obj_desc = acpi_ut_create_integer_object((u64)value); if (!obj_desc) { acpi_os_printf("Could not create an internal object\n"); return; } /* Store the new object into the target */ switch (type) { case 'A': /* Set a method argument */ if (index > ACPI_METHOD_MAX_ARG) { acpi_os_printf("Arg%u - Invalid argument name\n", index); goto cleanup; } status = acpi_ds_store_object_to_local(ACPI_REFCLASS_ARG, index, obj_desc, walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } obj_desc = walk_state->arguments[index].object; acpi_os_printf("Arg%u: ", index); acpi_db_display_internal_object(obj_desc, walk_state); break; case 'L': /* Set a method local */ if (index > ACPI_METHOD_MAX_LOCAL) { acpi_os_printf ("Local%u - Invalid local variable name\n", index); goto cleanup; } status = acpi_ds_store_object_to_local(ACPI_REFCLASS_LOCAL, index, obj_desc, walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } obj_desc = walk_state->local_variables[index].object; acpi_os_printf("Local%u: ", index); acpi_db_display_internal_object(obj_desc, walk_state); break; default: break; } cleanup: acpi_ut_remove_reference(obj_desc); } #ifdef ACPI_DISASSEMBLER /******************************************************************************* * * FUNCTION: acpi_db_disassemble_aml * * PARAMETERS: statements - Number of statements to disassemble * op - Current Op (from parse walk) * * RETURN: None * * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number * of statements specified. * ******************************************************************************/ void acpi_db_disassemble_aml(char *statements, union acpi_parse_object *op) { u32 num_statements = 8; if (!op) { acpi_os_printf("There is no method currently executing\n"); return; } if (statements) { num_statements = strtoul(statements, NULL, 0); } acpi_dm_disassemble(NULL, op, num_statements); } /******************************************************************************* * * FUNCTION: acpi_db_disassemble_method * * PARAMETERS: name - Name of control method * * RETURN: None * * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number * of statements specified. * ******************************************************************************/ acpi_status acpi_db_disassemble_method(char *name) { acpi_status status; union acpi_parse_object *op; struct acpi_walk_state *walk_state; union acpi_operand_object *obj_desc; struct acpi_namespace_node *method; method = acpi_db_convert_to_node(name); if (!method) { return (AE_BAD_PARAMETER); } if (method->type != ACPI_TYPE_METHOD) { ACPI_ERROR((AE_INFO, "%s (%s): Object must be a control method", name, acpi_ut_get_type_name(method->type))); return (AE_BAD_PARAMETER); } obj_desc = method->object; op = acpi_ps_create_scope_op(obj_desc->method.aml_start); if (!op) { return (AE_NO_MEMORY); } /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state(0, op, NULL, NULL); if (!walk_state) { return (AE_NO_MEMORY); } status = acpi_ds_init_aml_walk(walk_state, op, NULL, obj_desc->method.aml_start, obj_desc->method.aml_length, NULL, ACPI_IMODE_LOAD_PASS1); if (ACPI_FAILURE(status)) { return (status); } status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); if (ACPI_FAILURE(status)) { return (status); } walk_state->owner_id = obj_desc->method.owner_id; /* Push start scope on scope stack and make it current */ status = acpi_ds_scope_stack_push(method, method->type, walk_state); if (ACPI_FAILURE(status)) { return (status); } /* Parse the entire method AML including deferred operators */ walk_state->parse_flags &= ~ACPI_PARSE_DELETE_TREE; walk_state->parse_flags |= ACPI_PARSE_DISASSEMBLE; status = acpi_ps_parse_aml(walk_state); if (ACPI_FAILURE(status)) { return (status); } (void)acpi_dm_parse_deferred_ops(op); /* Now we can disassemble the method */ acpi_gbl_dm_opt_verbose = FALSE; acpi_dm_disassemble(NULL, op, 0); acpi_gbl_dm_opt_verbose = TRUE; acpi_ps_delete_parse_tree(op); /* Method cleanup */ acpi_ns_delete_namespace_subtree(method); acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id); acpi_ut_release_owner_id(&obj_desc->method.owner_id); return (AE_OK); } #endif /******************************************************************************* * * FUNCTION: acpi_db_evaluate_object * * PARAMETERS: node - Namespace node for the object * * RETURN: Status * * DESCRIPTION: Main execution function for the Evaluate/Execute/All debugger * commands. * ******************************************************************************/ static acpi_status acpi_db_evaluate_object(struct acpi_namespace_node *node) { char *pathname; u32 i; struct acpi_device_info *obj_info; struct acpi_object_list param_objects; union acpi_object params[ACPI_METHOD_NUM_ARGS]; struct acpi_buffer return_obj; acpi_status status; pathname = acpi_ns_get_external_pathname(node); if (!pathname) { return (AE_OK); } /* Get the object info for number of method parameters */ status = acpi_get_object_info(node, &obj_info); if (ACPI_FAILURE(status)) { ACPI_FREE(pathname); return (status); } param_objects.pointer = NULL; param_objects.count = 0; if (obj_info->type == ACPI_TYPE_METHOD) { /* Setup default parameters */ for (i = 0; i < obj_info->param_count; i++) { params[i].type = ACPI_TYPE_INTEGER; params[i].integer.value = 1; } param_objects.pointer = params; param_objects.count = obj_info->param_count; } ACPI_FREE(obj_info); return_obj.pointer = NULL; return_obj.length = ACPI_ALLOCATE_BUFFER; /* Do the actual method execution */ acpi_gbl_method_executing = TRUE; status = acpi_evaluate_object(node, NULL, &param_objects, &return_obj); acpi_gbl_method_executing = FALSE; acpi_os_printf("%-32s returned %s\n", pathname, acpi_format_exception(status)); if (return_obj.length) { acpi_os_printf("Evaluation of %s returned object %p, " "external buffer length %X\n", pathname, return_obj.pointer, (u32)return_obj.length); acpi_db_dump_external_object(return_obj.pointer, 1); acpi_os_printf("\n"); } ACPI_FREE(pathname); /* Ignore status from method execution */ return (AE_OK); /* Update count, check if we have executed enough methods */ } /******************************************************************************* * * FUNCTION: acpi_db_walk_for_execute * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Batch execution function. Evaluates all "predefined" objects -- * the nameseg begins with an underscore. * ******************************************************************************/ static acpi_status acpi_db_walk_for_execute(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; struct acpi_db_execute_walk *info = (struct acpi_db_execute_walk *)context; acpi_status status; const union acpi_predefined_info *predefined; predefined = acpi_ut_match_predefined_method(node->name.ascii); if (!predefined) { return (AE_OK); } if (node->type == ACPI_TYPE_LOCAL_SCOPE) { return (AE_OK); } acpi_db_evaluate_object(node); /* Ignore status from object evaluation */ status = AE_OK; /* Update count, check if we have executed enough methods */ info->count++; if (info->count >= info->max_count) { status = AE_CTRL_TERMINATE; } return (status); } /******************************************************************************* * * FUNCTION: acpi_db_walk_for_execute_all * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Batch execution function. Evaluates all objects whose path ends * with the nameseg "Info->NameSeg". Used for the "ALL" command. * ******************************************************************************/ static acpi_status acpi_db_walk_for_execute_all(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; struct acpi_db_execute_walk *info = (struct acpi_db_execute_walk *)context; acpi_status status; if (!ACPI_COMPARE_NAMESEG(node->name.ascii, info->name_seg)) { return (AE_OK); } if (node->type == ACPI_TYPE_LOCAL_SCOPE) { return (AE_OK); } /* Now evaluate the input object (node) */ acpi_db_evaluate_object(node); /* Ignore status from method execution */ status = AE_OK; /* Update count of executed methods/objects */ info->count++; return (status); } /******************************************************************************* * * FUNCTION: acpi_db_evaluate_predefined_names * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Namespace batch execution. Execute predefined names in the * namespace, up to the max count, if specified. * ******************************************************************************/ void acpi_db_evaluate_predefined_names(void) { struct acpi_db_execute_walk info; info.count = 0; info.max_count = ACPI_UINT32_MAX; /* Search all nodes in namespace */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_walk_for_execute, NULL, (void *)&info, NULL); acpi_os_printf("Evaluated %u predefined names in the namespace\n", info.count); } /******************************************************************************* * * FUNCTION: acpi_db_evaluate_all * * PARAMETERS: none_acpi_gbl_db_method_info * * RETURN: None * * DESCRIPTION: Namespace batch execution. Implements the "ALL" command. * Execute all namepaths whose final nameseg matches the * input nameseg. * ******************************************************************************/ void acpi_db_evaluate_all(char *name_seg) { struct acpi_db_execute_walk info; info.count = 0; info.max_count = ACPI_UINT32_MAX; ACPI_COPY_NAMESEG(info.name_seg, name_seg); info.name_seg[ACPI_NAMESEG_SIZE] = 0; /* Search all nodes in namespace */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_walk_for_execute_all, NULL, (void *)&info, NULL); acpi_os_printf("Evaluated %u names in the namespace\n", info.count); }
linux-master
drivers/acpi/acpica/dbmethod.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utpredef - support functions for predefined names * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acpredef.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utpredef") /* * Names for the types that can be returned by the predefined objects. * Used for warning messages. Must be in the same order as the ACPI_RTYPEs */ static const char *ut_rtype_names[] = { "/Integer", "/String", "/Buffer", "/Package", "/Reference", }; /******************************************************************************* * * FUNCTION: acpi_ut_get_next_predefined_method * * PARAMETERS: this_name - Entry in the predefined method/name table * * RETURN: Pointer to next entry in predefined table. * * DESCRIPTION: Get the next entry in the predefine method table. Handles the * cases where a package info entry follows a method name that * returns a package. * ******************************************************************************/ const union acpi_predefined_info *acpi_ut_get_next_predefined_method(const union acpi_predefined_info *this_name) { /* * Skip next entry in the table if this name returns a Package * (next entry contains the package info) */ if ((this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) && (this_name->info.expected_btypes != ACPI_RTYPE_ALL)) { this_name++; } this_name++; return (this_name); } /******************************************************************************* * * FUNCTION: acpi_ut_match_predefined_method * * PARAMETERS: name - Name to find * * RETURN: Pointer to entry in predefined table. NULL indicates not found. * * DESCRIPTION: Check an object name against the predefined object list. * ******************************************************************************/ const union acpi_predefined_info *acpi_ut_match_predefined_method(char *name) { const union acpi_predefined_info *this_name; /* Quick check for a predefined name, first character must be underscore */ if (name[0] != '_') { return (NULL); } /* Search info table for a predefined method/object name */ this_name = acpi_gbl_predefined_methods; while (this_name->info.name[0]) { if (ACPI_COMPARE_NAMESEG(name, this_name->info.name)) { return (this_name); } this_name = acpi_ut_get_next_predefined_method(this_name); } return (NULL); /* Not found */ } /******************************************************************************* * * FUNCTION: acpi_ut_get_expected_return_types * * PARAMETERS: buffer - Where the formatted string is returned * expected_Btypes - Bitfield of expected data types * * RETURN: Formatted string in Buffer. * * DESCRIPTION: Format the expected object types into a printable string. * ******************************************************************************/ void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes) { u32 this_rtype; u32 i; u32 j; if (!expected_btypes) { strcpy(buffer, "NONE"); return; } j = 1; buffer[0] = 0; this_rtype = ACPI_RTYPE_INTEGER; for (i = 0; i < ACPI_NUM_RTYPES; i++) { /* If one of the expected types, concatenate the name of this type */ if (expected_btypes & this_rtype) { strcat(buffer, &ut_rtype_names[i][j]); j = 0; /* Use name separator from now on */ } this_rtype <<= 1; /* Next Rtype */ } } /******************************************************************************* * * The remaining functions are used by iASL and acpi_help only * ******************************************************************************/ #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP) /* Local prototypes */ static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types); /* Types that can be returned externally by a predefined name */ static const char *ut_external_type_names[] = /* Indexed by ACPI_TYPE_* */ { ", Type_ANY", ", Integer", ", String", ", Buffer", ", Package" }; /* Bit widths for resource descriptor predefined names */ static const char *ut_resource_type_names[] = { "/1", "/2", "/3", "/8", "/16", "/32", "/64", "/variable", }; /******************************************************************************* * * FUNCTION: acpi_ut_match_resource_name * * PARAMETERS: name - Name to find * * RETURN: Pointer to entry in the resource table. NULL indicates not * found. * * DESCRIPTION: Check an object name against the predefined resource * descriptor object list. * ******************************************************************************/ const union acpi_predefined_info *acpi_ut_match_resource_name(char *name) { const union acpi_predefined_info *this_name; /* * Quick check for a predefined name, first character must * be underscore */ if (name[0] != '_') { return (NULL); } /* Search info table for a predefined method/object name */ this_name = acpi_gbl_resource_names; while (this_name->info.name[0]) { if (ACPI_COMPARE_NAMESEG(name, this_name->info.name)) { return (this_name); } this_name++; } return (NULL); /* Not found */ } /******************************************************************************* * * FUNCTION: acpi_ut_display_predefined_method * * PARAMETERS: buffer - Scratch buffer for this function * this_name - Entry in the predefined method/name table * multi_line - TRUE if output should be on >1 line * * RETURN: None * * DESCRIPTION: Display information about a predefined method. Number and * type of the input arguments, and expected type(s) for the * return value, if any. * ******************************************************************************/ void acpi_ut_display_predefined_method(char *buffer, const union acpi_predefined_info *this_name, u8 multi_line) { u32 arg_count; /* * Get the argument count and the string buffer * containing all argument types */ arg_count = acpi_ut_get_argument_types(buffer, this_name->info.argument_list); if (multi_line) { printf(" "); } printf("%4.4s Requires %s%u argument%s", this_name->info.name, (this_name->info.argument_list & ARG_COUNT_IS_MINIMUM) ? "(at least) " : "", arg_count, arg_count != 1 ? "s" : ""); /* Display the types for any arguments */ if (arg_count > 0) { printf(" (%s)", buffer); } if (multi_line) { printf("\n "); } /* Get the return value type(s) allowed */ if (this_name->info.expected_btypes) { acpi_ut_get_expected_return_types(buffer, this_name->info. expected_btypes); printf(" Return value types: %s\n", buffer); } else { printf(" No return value\n"); } } /******************************************************************************* * * FUNCTION: acpi_ut_get_argument_types * * PARAMETERS: buffer - Where to return the formatted types * argument_types - Types field for this method * * RETURN: count - the number of arguments required for this method * * DESCRIPTION: Format the required data types for this method (Integer, * String, Buffer, or Package) and return the required argument * count. * ******************************************************************************/ static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types) { u16 this_argument_type; u16 sub_index; u16 arg_count; u32 i; *buffer = 0; sub_index = 2; /* First field in the types list is the count of args to follow */ arg_count = METHOD_GET_ARG_COUNT(argument_types); if (arg_count > METHOD_PREDEF_ARGS_MAX) { printf("**** Invalid argument count (%u) " "in predefined info structure\n", arg_count); return (arg_count); } /* Get each argument from the list, convert to ascii, store to buffer */ for (i = 0; i < arg_count; i++) { this_argument_type = METHOD_GET_NEXT_TYPE(argument_types); if (this_argument_type > METHOD_MAX_ARG_TYPE) { printf("**** Invalid argument type (%u) " "in predefined info structure\n", this_argument_type); return (arg_count); } strcat(buffer, ut_external_type_names[this_argument_type] + sub_index); sub_index = 0; } return (arg_count); } /******************************************************************************* * * FUNCTION: acpi_ut_get_resource_bit_width * * PARAMETERS: buffer - Where the formatted string is returned * types - Bitfield of expected data types * * RETURN: Count of return types. Formatted string in Buffer. * * DESCRIPTION: Format the resource bit widths into a printable string. * ******************************************************************************/ u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types) { u32 i; u16 sub_index; u32 found; *buffer = 0; sub_index = 1; found = 0; for (i = 0; i < NUM_RESOURCE_WIDTHS; i++) { if (types & 1) { strcat(buffer, &(ut_resource_type_names[i][sub_index])); sub_index = 0; found++; } types >>= 1; } return (found); } #endif
linux-master
drivers/acpi/acpica/utpredef.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nsrepair2 - Repair for objects returned by specific * predefined methods * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsrepair2") /* * Information structure and handler for ACPI predefined names that can * be repaired on a per-name basis. */ typedef acpi_status (*acpi_repair_function) (struct acpi_evaluate_info * info, union acpi_operand_object ** return_object_ptr); typedef struct acpi_repair_info { char name[ACPI_NAMESEG_SIZE]; acpi_repair_function repair_function; } acpi_repair_info; /* Local prototypes */ static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct acpi_namespace_node *node); static acpi_status acpi_ns_repair_ALR(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr); static acpi_status acpi_ns_repair_CID(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr); static acpi_status acpi_ns_repair_CST(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr); static acpi_status acpi_ns_repair_FDE(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr); static acpi_status acpi_ns_repair_HID(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr); static acpi_status acpi_ns_repair_PRT(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr); static acpi_status acpi_ns_repair_PSS(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr); static acpi_status acpi_ns_repair_TSS(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr); static acpi_status acpi_ns_check_sorted_list(struct acpi_evaluate_info *info, union acpi_operand_object *return_object, u32 start_index, u32 expected_count, u32 sort_index, u8 sort_direction, char *sort_key_name); /* Values for sort_direction above */ #define ACPI_SORT_ASCENDING 0 #define ACPI_SORT_DESCENDING 1 static void acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index); static void acpi_ns_sort_list(union acpi_operand_object **elements, u32 count, u32 index, u8 sort_direction); /* * This table contains the names of the predefined methods for which we can * perform more complex repairs. * * As necessary: * * _ALR: Sort the list ascending by ambient_illuminance * _CID: Strings: uppercase all, remove any leading asterisk * _CST: Sort the list ascending by C state type * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs * _HID: Strings: uppercase all, remove any leading asterisk * _PRT: Fix reversed source_name and source_index * _PSS: Sort the list descending by Power * _TSS: Sort the list descending by Power * * Names that must be packages, but cannot be sorted: * * _BCL: Values are tied to the Package index where they appear, and cannot * be moved or sorted. These index values are used for _BQC and _BCM. * However, we can fix the case where a buffer is returned, by converting * it to a Package of integers. */ static const struct acpi_repair_info acpi_ns_repairable_names[] = { {"_ALR", acpi_ns_repair_ALR}, {"_CID", acpi_ns_repair_CID}, {"_CST", acpi_ns_repair_CST}, {"_FDE", acpi_ns_repair_FDE}, {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */ {"_HID", acpi_ns_repair_HID}, {"_PRT", acpi_ns_repair_PRT}, {"_PSS", acpi_ns_repair_PSS}, {"_TSS", acpi_ns_repair_TSS}, {{0, 0, 0, 0}, NULL} /* Table terminator */ }; #define ACPI_FDE_FIELD_COUNT 5 #define ACPI_FDE_BYTE_BUFFER_SIZE 5 #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * (u32) sizeof (u32)) /****************************************************************************** * * FUNCTION: acpi_ns_complex_repairs * * PARAMETERS: info - Method execution information block * node - Namespace node for the method/object * validate_status - Original status of earlier validation * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if repair was successful. If name is not * matched, validate_status is returned. * * DESCRIPTION: Attempt to repair/convert a return object of a type that was * not expected. * *****************************************************************************/ acpi_status acpi_ns_complex_repairs(struct acpi_evaluate_info *info, struct acpi_namespace_node *node, acpi_status validate_status, union acpi_operand_object **return_object_ptr) { const struct acpi_repair_info *predefined; acpi_status status; ACPI_FUNCTION_TRACE(ns_complex_repairs); /* Check if this name is in the list of repairable names */ predefined = acpi_ns_match_complex_repair(node); if (!predefined) { return_ACPI_STATUS(validate_status); } status = predefined->repair_function(info, return_object_ptr); return_ACPI_STATUS(status); } /****************************************************************************** * * FUNCTION: acpi_ns_match_complex_repair * * PARAMETERS: node - Namespace node for the method/object * * RETURN: Pointer to entry in repair table. NULL indicates not found. * * DESCRIPTION: Check an object name against the repairable object list. * *****************************************************************************/ static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct acpi_namespace_node *node) { const struct acpi_repair_info *this_name; /* Search info table for a repairable predefined method/object name */ this_name = acpi_ns_repairable_names; while (this_name->repair_function) { if (ACPI_COMPARE_NAMESEG(node->name.ascii, this_name->name)) { return (this_name); } this_name++; } return (NULL); /* Not found */ } /****************************************************************************** * * FUNCTION: acpi_ns_repair_ALR * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if object is OK or was repaired successfully * * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list * ascending by the ambient illuminance values. * *****************************************************************************/ static acpi_status acpi_ns_repair_ALR(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *return_object = *return_object_ptr; acpi_status status; status = acpi_ns_check_sorted_list(info, return_object, 0, 2, 1, ACPI_SORT_ASCENDING, "AmbientIlluminance"); return (status); } /****************************************************************************** * * FUNCTION: acpi_ns_repair_FDE * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if object is OK or was repaired successfully * * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return * value is a Buffer of 5 DWORDs. This function repairs a common * problem where the return value is a Buffer of BYTEs, not * DWORDs. * *****************************************************************************/ static acpi_status acpi_ns_repair_FDE(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *return_object = *return_object_ptr; union acpi_operand_object *buffer_object; u8 *byte_buffer; u32 *dword_buffer; u32 i; ACPI_FUNCTION_NAME(ns_repair_FDE); switch (return_object->common.type) { case ACPI_TYPE_BUFFER: /* This is the expected type. Length should be (at least) 5 DWORDs */ if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) { return (AE_OK); } /* We can only repair if we have exactly 5 BYTEs */ if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "Incorrect return buffer length %u, expected %u", return_object->buffer.length, ACPI_FDE_DWORD_BUFFER_SIZE)); return (AE_AML_OPERAND_TYPE); } /* Create the new (larger) buffer object */ buffer_object = acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE); if (!buffer_object) { return (AE_NO_MEMORY); } /* Expand each byte to a DWORD */ byte_buffer = return_object->buffer.pointer; dword_buffer = ACPI_CAST_PTR(u32, buffer_object->buffer.pointer); for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) { *dword_buffer = (u32) *byte_buffer; dword_buffer++; byte_buffer++; } ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, "%s Expanded Byte Buffer to expected DWord Buffer\n", info->full_pathname)); break; default: return (AE_AML_OPERAND_TYPE); } /* Delete the original return object, return the new buffer object */ acpi_ut_remove_reference(return_object); *return_object_ptr = buffer_object; info->return_flags |= ACPI_OBJECT_REPAIRED; return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_ns_repair_CID * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if object is OK or was repaired successfully * * DESCRIPTION: Repair for the _CID object. If a string, ensure that all * letters are uppercase and that there is no leading asterisk. * If a Package, ensure same for all string elements. * *****************************************************************************/ static acpi_status acpi_ns_repair_CID(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr) { acpi_status status; union acpi_operand_object *return_object = *return_object_ptr; union acpi_operand_object **element_ptr; union acpi_operand_object *original_element; u16 original_ref_count; u32 i; ACPI_FUNCTION_TRACE(ns_repair_CID); /* Check for _CID as a simple string */ if (return_object->common.type == ACPI_TYPE_STRING) { status = acpi_ns_repair_HID(info, return_object_ptr); return_ACPI_STATUS(status); } /* Exit if not a Package */ if (return_object->common.type != ACPI_TYPE_PACKAGE) { return_ACPI_STATUS(AE_OK); } /* Examine each element of the _CID package */ element_ptr = return_object->package.elements; for (i = 0; i < return_object->package.count; i++) { original_element = *element_ptr; original_ref_count = original_element->common.reference_count; status = acpi_ns_repair_HID(info, element_ptr); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (original_element != *element_ptr) { /* Update reference count of new object */ (*element_ptr)->common.reference_count = original_ref_count; } element_ptr++; } return_ACPI_STATUS(AE_OK); } /****************************************************************************** * * FUNCTION: acpi_ns_repair_CST * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if object is OK or was repaired successfully * * DESCRIPTION: Repair for the _CST object: * 1. Sort the list ascending by C state type * 2. Ensure type cannot be zero * 3. A subpackage count of zero means _CST is meaningless * 4. Count must match the number of C state subpackages * *****************************************************************************/ static acpi_status acpi_ns_repair_CST(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *return_object = *return_object_ptr; union acpi_operand_object **outer_elements; u32 outer_element_count; union acpi_operand_object *obj_desc; acpi_status status; u8 removing; u32 i; ACPI_FUNCTION_NAME(ns_repair_CST); /* * Check if the C-state type values are proportional. */ outer_element_count = return_object->package.count - 1; i = 0; while (i < outer_element_count) { outer_elements = &return_object->package.elements[i + 1]; removing = FALSE; if ((*outer_elements)->package.count == 0) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "SubPackage[%u] - removing entry due to zero count", i)); removing = TRUE; goto remove_element; } obj_desc = (*outer_elements)->package.elements[1]; /* Index1 = Type */ if ((u32)obj_desc->integer.value == 0) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "SubPackage[%u] - removing entry due to invalid Type(0)", i)); removing = TRUE; } remove_element: if (removing) { acpi_ns_remove_element(return_object, i + 1); outer_element_count--; } else { i++; } } /* Update top-level package count, Type "Integer" checked elsewhere */ obj_desc = return_object->package.elements[0]; obj_desc->integer.value = outer_element_count; /* * Entries (subpackages) in the _CST Package must be sorted by the * C-state type, in ascending order. */ status = acpi_ns_check_sorted_list(info, return_object, 1, 4, 1, ACPI_SORT_ASCENDING, "C-State Type"); if (ACPI_FAILURE(status)) { return (status); } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_ns_repair_HID * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if object is OK or was repaired successfully * * DESCRIPTION: Repair for the _HID object. If a string, ensure that all * letters are uppercase and that there is no leading asterisk. * *****************************************************************************/ static acpi_status acpi_ns_repair_HID(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *return_object = *return_object_ptr; union acpi_operand_object *new_string; char *source; char *dest; ACPI_FUNCTION_TRACE(ns_repair_HID); /* We only care about string _HID objects (not integers) */ if (return_object->common.type != ACPI_TYPE_STRING) { return_ACPI_STATUS(AE_OK); } if (return_object->string.length == 0) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "Invalid zero-length _HID or _CID string")); /* Return AE_OK anyway, let driver handle it */ info->return_flags |= ACPI_OBJECT_REPAIRED; return_ACPI_STATUS(AE_OK); } /* It is simplest to always create a new string object */ new_string = acpi_ut_create_string_object(return_object->string.length); if (!new_string) { return_ACPI_STATUS(AE_NO_MEMORY); } /* * Remove a leading asterisk if present. For some unknown reason, there * are many machines in the field that contains IDs like this. * * Examples: "*PNP0C03", "*ACPI0003" */ source = return_object->string.pointer; if (*source == '*') { source++; new_string->string.length--; ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, "%s: Removed invalid leading asterisk\n", info->full_pathname)); } /* * Copy and uppercase the string. From the ACPI 5.0 specification: * * A valid PNP ID must be of the form "AAA####" where A is an uppercase * letter and # is a hex digit. A valid ACPI ID must be of the form * "NNNN####" where N is an uppercase letter or decimal digit, and * # is a hex digit. */ for (dest = new_string->string.pointer; *source; dest++, source++) { *dest = (char)toupper((int)*source); } acpi_ut_remove_reference(return_object); *return_object_ptr = new_string; return_ACPI_STATUS(AE_OK); } /****************************************************************************** * * FUNCTION: acpi_ns_repair_PRT * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if object is OK or was repaired successfully * * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed * source_name and source_index field, a common BIOS bug. * *****************************************************************************/ static acpi_status acpi_ns_repair_PRT(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *package_object = *return_object_ptr; union acpi_operand_object **top_object_list; union acpi_operand_object **sub_object_list; union acpi_operand_object *obj_desc; union acpi_operand_object *sub_package; u32 element_count; u32 index; /* Each element in the _PRT package is a subpackage */ top_object_list = package_object->package.elements; element_count = package_object->package.count; /* Examine each subpackage */ for (index = 0; index < element_count; index++, top_object_list++) { sub_package = *top_object_list; sub_object_list = sub_package->package.elements; /* Check for minimum required element count */ if (sub_package->package.count < 4) { continue; } /* * If the BIOS has erroneously reversed the _PRT source_name (index 2) * and the source_index (index 3), fix it. _PRT is important enough to * workaround this BIOS error. This also provides compatibility with * other ACPI implementations. */ obj_desc = sub_object_list[3]; if (!obj_desc || (obj_desc->common.type != ACPI_TYPE_INTEGER)) { sub_object_list[3] = sub_object_list[2]; sub_object_list[2] = obj_desc; info->return_flags |= ACPI_OBJECT_REPAIRED; ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "PRT[%X]: Fixed reversed SourceName and SourceIndex", index)); } } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_ns_repair_PSS * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if object is OK or was repaired successfully * * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list * by the CPU frequencies. Check that the power dissipation values * are all proportional to CPU frequency (i.e., sorting by * frequency should be the same as sorting by power.) * *****************************************************************************/ static acpi_status acpi_ns_repair_PSS(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *return_object = *return_object_ptr; union acpi_operand_object **outer_elements; u32 outer_element_count; union acpi_operand_object **elements; union acpi_operand_object *obj_desc; u32 previous_value; acpi_status status; u32 i; /* * Entries (subpackages) in the _PSS Package must be sorted by power * dissipation, in descending order. If it appears that the list is * incorrectly sorted, sort it. We sort by cpu_frequency, since this * should be proportional to the power. */ status = acpi_ns_check_sorted_list(info, return_object, 0, 6, 0, ACPI_SORT_DESCENDING, "CpuFrequency"); if (ACPI_FAILURE(status)) { return (status); } /* * We now know the list is correctly sorted by CPU frequency. Check if * the power dissipation values are proportional. */ previous_value = ACPI_UINT32_MAX; outer_elements = return_object->package.elements; outer_element_count = return_object->package.count; for (i = 0; i < outer_element_count; i++) { elements = (*outer_elements)->package.elements; obj_desc = elements[1]; /* Index1 = power_dissipation */ if ((u32)obj_desc->integer.value > previous_value) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "SubPackage[%u,%u] - suspicious power dissipation values", i - 1, i)); } previous_value = (u32) obj_desc->integer.value; outer_elements++; } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_ns_repair_TSS * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status. AE_OK if object is OK or was repaired successfully * * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list * descending by the power dissipation values. * *****************************************************************************/ static acpi_status acpi_ns_repair_TSS(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *return_object = *return_object_ptr; acpi_status status; struct acpi_namespace_node *node; /* * We can only sort the _TSS return package if there is no _PSS in the * same scope. This is because if _PSS is present, the ACPI specification * dictates that the _TSS Power Dissipation field is to be ignored, and * therefore some BIOSs leave garbage values in the _TSS Power field(s). * In this case, it is best to just return the _TSS package as-is. * (May, 2011) */ status = acpi_ns_get_node(info->node, "^_PSS", ACPI_NS_NO_UPSEARCH, &node); if (ACPI_SUCCESS(status)) { return (AE_OK); } status = acpi_ns_check_sorted_list(info, return_object, 0, 5, 1, ACPI_SORT_DESCENDING, "PowerDissipation"); return (status); } /****************************************************************************** * * FUNCTION: acpi_ns_check_sorted_list * * PARAMETERS: info - Method execution information block * return_object - Pointer to the top-level returned object * start_index - Index of the first subpackage * expected_count - Minimum length of each subpackage * sort_index - Subpackage entry to sort on * sort_direction - Ascending or descending * sort_key_name - Name of the sort_index field * * RETURN: Status. AE_OK if the list is valid and is sorted correctly or * has been repaired by sorting the list. * * DESCRIPTION: Check if the package list is valid and sorted correctly by the * sort_index. If not, then sort the list. * *****************************************************************************/ static acpi_status acpi_ns_check_sorted_list(struct acpi_evaluate_info *info, union acpi_operand_object *return_object, u32 start_index, u32 expected_count, u32 sort_index, u8 sort_direction, char *sort_key_name) { u32 outer_element_count; union acpi_operand_object **outer_elements; union acpi_operand_object **elements; union acpi_operand_object *obj_desc; u32 i; u32 previous_value; ACPI_FUNCTION_NAME(ns_check_sorted_list); /* The top-level object must be a package */ if (return_object->common.type != ACPI_TYPE_PACKAGE) { return (AE_AML_OPERAND_TYPE); } /* * NOTE: assumes list of subpackages contains no NULL elements. * Any NULL elements should have been removed by earlier call * to acpi_ns_remove_null_elements. */ outer_element_count = return_object->package.count; if (!outer_element_count || start_index >= outer_element_count) { return (AE_AML_PACKAGE_LIMIT); } outer_elements = &return_object->package.elements[start_index]; outer_element_count -= start_index; previous_value = 0; if (sort_direction == ACPI_SORT_DESCENDING) { previous_value = ACPI_UINT32_MAX; } /* Examine each subpackage */ for (i = 0; i < outer_element_count; i++) { /* Each element of the top-level package must also be a package */ if ((*outer_elements)->common.type != ACPI_TYPE_PACKAGE) { return (AE_AML_OPERAND_TYPE); } /* Each subpackage must have the minimum length */ if ((*outer_elements)->package.count < expected_count) { return (AE_AML_PACKAGE_LIMIT); } elements = (*outer_elements)->package.elements; obj_desc = elements[sort_index]; if (obj_desc->common.type != ACPI_TYPE_INTEGER) { return (AE_AML_OPERAND_TYPE); } /* * The list must be sorted in the specified order. If we detect a * discrepancy, sort the entire list. */ if (((sort_direction == ACPI_SORT_ASCENDING) && (obj_desc->integer.value < previous_value)) || ((sort_direction == ACPI_SORT_DESCENDING) && (obj_desc->integer.value > previous_value))) { acpi_ns_sort_list(&return_object->package. elements[start_index], outer_element_count, sort_index, sort_direction); info->return_flags |= ACPI_OBJECT_REPAIRED; ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, "%s: Repaired unsorted list - now sorted by %s\n", info->full_pathname, sort_key_name)); return (AE_OK); } previous_value = (u32) obj_desc->integer.value; outer_elements++; } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_ns_sort_list * * PARAMETERS: elements - Package object element list * count - Element count for above * index - Sort by which package element * sort_direction - Ascending or Descending sort * * RETURN: None * * DESCRIPTION: Sort the objects that are in a package element list. * * NOTE: Assumes that all NULL elements have been removed from the package, * and that all elements have been verified to be of type Integer. * *****************************************************************************/ static void acpi_ns_sort_list(union acpi_operand_object **elements, u32 count, u32 index, u8 sort_direction) { union acpi_operand_object *obj_desc1; union acpi_operand_object *obj_desc2; union acpi_operand_object *temp_obj; u32 i; u32 j; /* Simple bubble sort */ for (i = 1; i < count; i++) { for (j = (count - 1); j >= i; j--) { obj_desc1 = elements[j - 1]->package.elements[index]; obj_desc2 = elements[j]->package.elements[index]; if (((sort_direction == ACPI_SORT_ASCENDING) && (obj_desc1->integer.value > obj_desc2->integer.value)) || ((sort_direction == ACPI_SORT_DESCENDING) && (obj_desc1->integer.value < obj_desc2->integer.value))) { temp_obj = elements[j - 1]; elements[j - 1] = elements[j]; elements[j] = temp_obj; } } } } /****************************************************************************** * * FUNCTION: acpi_ns_remove_element * * PARAMETERS: obj_desc - Package object element list * index - Index of element to remove * * RETURN: None * * DESCRIPTION: Remove the requested element of a package and delete it. * *****************************************************************************/ static void acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index) { union acpi_operand_object **source; union acpi_operand_object **dest; u32 count; u32 new_count; u32 i; ACPI_FUNCTION_NAME(ns_remove_element); count = obj_desc->package.count; new_count = count - 1; source = obj_desc->package.elements; dest = source; /* Examine all elements of the package object, remove matched index */ for (i = 0; i < count; i++) { if (i == index) { acpi_ut_remove_reference(*source); /* Remove one ref for being in pkg */ acpi_ut_remove_reference(*source); } else { *dest = *source; dest++; } source++; } /* NULL terminate list and update the package count */ *dest = NULL; obj_desc->package.count = new_count; }
linux-master
drivers/acpi/acpica/nsrepair2.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: psloop - Main AML parse loop * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ /* * Parse the AML and build an operation tree as most interpreters, (such as * Perl) do. Parsing is done by hand rather than with a YACC generated parser * to tightly constrain stack and dynamic memory usage. Parsing is kept * flexible and the code fairly compact by parsing based on a list of AML * opcode templates in aml_op_info[]. */ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #include "acparser.h" #include "acdispat.h" #include "amlcode.h" #include "acconvert.h" #include "acnamesp.h" #define _COMPONENT ACPI_PARSER ACPI_MODULE_NAME("psloop") /* Local prototypes */ static acpi_status acpi_ps_get_arguments(struct acpi_walk_state *walk_state, u8 * aml_op_start, union acpi_parse_object *op); /******************************************************************************* * * FUNCTION: acpi_ps_get_arguments * * PARAMETERS: walk_state - Current state * aml_op_start - Op start in AML * op - Current Op * * RETURN: Status * * DESCRIPTION: Get arguments for passed Op. * ******************************************************************************/ static acpi_status acpi_ps_get_arguments(struct acpi_walk_state *walk_state, u8 * aml_op_start, union acpi_parse_object *op) { acpi_status status = AE_OK; union acpi_parse_object *arg = NULL; ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Get arguments for opcode [%s]\n", op->common.aml_op_name)); switch (op->common.aml_opcode) { case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ case AML_WORD_OP: /* AML_WORDDATA_ARG */ case AML_DWORD_OP: /* AML_DWORDATA_ARG */ case AML_QWORD_OP: /* AML_QWORDATA_ARG */ case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */ /* Fill in constant or string argument directly */ acpi_ps_get_next_simple_arg(&(walk_state->parser_state), GET_CURRENT_ARG_TYPE(walk_state-> arg_types), op); break; case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */ status = acpi_ps_get_next_namepath(walk_state, &(walk_state->parser_state), op, ACPI_POSSIBLE_METHOD_CALL); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } walk_state->arg_types = 0; break; default: /* * Op is not a constant or string, append each argument to the Op */ while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) && !walk_state->arg_count) { walk_state->aml = walk_state->parser_state.aml; switch (op->common.aml_opcode) { case AML_METHOD_OP: case AML_BUFFER_OP: case AML_PACKAGE_OP: case AML_VARIABLE_PACKAGE_OP: case AML_WHILE_OP: break; default: ASL_CV_CAPTURE_COMMENTS(walk_state); break; } status = acpi_ps_get_next_arg(walk_state, &(walk_state->parser_state), GET_CURRENT_ARG_TYPE (walk_state->arg_types), &arg); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (arg) { acpi_ps_append_arg(op, arg); } INCREMENT_ARG_LIST(walk_state->arg_types); } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Final argument count: %8.8X pass %u\n", walk_state->arg_count, walk_state->pass_number)); /* Special processing for certain opcodes */ switch (op->common.aml_opcode) { case AML_METHOD_OP: /* * Skip parsing of control method because we don't have enough * info in the first pass to parse it correctly. * * Save the length and address of the body */ op->named.data = walk_state->parser_state.aml; op->named.length = (u32) (walk_state->parser_state.pkg_end - walk_state->parser_state.aml); /* Skip body of method */ walk_state->parser_state.aml = walk_state->parser_state.pkg_end; walk_state->arg_count = 0; break; case AML_BUFFER_OP: case AML_PACKAGE_OP: case AML_VARIABLE_PACKAGE_OP: if ((op->common.parent) && (op->common.parent->common.aml_opcode == AML_NAME_OP) && (walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2)) { ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Setup Package/Buffer: Pass %u, AML Ptr: %p\n", walk_state->pass_number, aml_op_start)); /* * Skip parsing of Buffers and Packages because we don't have * enough info in the first pass to parse them correctly. */ op->named.data = aml_op_start; op->named.length = (u32) (walk_state->parser_state.pkg_end - aml_op_start); /* Skip body */ walk_state->parser_state.aml = walk_state->parser_state.pkg_end; walk_state->arg_count = 0; } break; case AML_WHILE_OP: if (walk_state->control_state) { walk_state->control_state->control.package_end = walk_state->parser_state.pkg_end; } break; default: /* No action for all other opcodes */ break; } break; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ps_parse_loop * * PARAMETERS: walk_state - Current state * * RETURN: Status * * DESCRIPTION: Parse AML (pointed to by the current parser state) and return * a tree of ops. * ******************************************************************************/ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state) { acpi_status status = AE_OK; union acpi_parse_object *op = NULL; /* current op */ struct acpi_parse_state *parser_state; u8 *aml_op_start = NULL; u8 opcode_length; ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state); if (walk_state->descending_callback == NULL) { return_ACPI_STATUS(AE_BAD_PARAMETER); } parser_state = &walk_state->parser_state; walk_state->arg_types = 0; #ifndef ACPI_CONSTANT_EVAL_ONLY if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { /* We are restarting a preempted control method */ if (acpi_ps_has_completed_scope(parser_state)) { /* * We must check if a predicate to an IF or WHILE statement * was just completed */ if ((parser_state->scope->parse_scope.op) && ((parser_state->scope->parse_scope.op->common. aml_opcode == AML_IF_OP) || (parser_state->scope->parse_scope.op->common. aml_opcode == AML_WHILE_OP)) && (walk_state->control_state) && (walk_state->control_state->common.state == ACPI_CONTROL_PREDICATE_EXECUTING)) { /* * A predicate was just completed, get the value of the * predicate and branch based on that value */ walk_state->op = NULL; status = acpi_ds_get_predicate_value(walk_state, ACPI_TO_POINTER (TRUE)); if (ACPI_FAILURE(status) && !ACPI_CNTL_EXCEPTION(status)) { if (status == AE_AML_NO_RETURN_VALUE) { ACPI_EXCEPTION((AE_INFO, status, "Invoked method did not return a value")); } ACPI_EXCEPTION((AE_INFO, status, "GetPredicate Failed")); return_ACPI_STATUS(status); } status = acpi_ps_next_parse_state(walk_state, op, status); } acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, &walk_state->arg_count); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", op)); } else if (walk_state->prev_op) { /* We were in the middle of an op */ op = walk_state->prev_op; walk_state->arg_types = walk_state->prev_arg_types; } } #endif /* Iterative parsing loop, while there is more AML to process: */ while ((parser_state->aml < parser_state->aml_end) || (op)) { ASL_CV_CAPTURE_COMMENTS(walk_state); aml_op_start = parser_state->aml; if (!op) { status = acpi_ps_create_op(walk_state, aml_op_start, &op); if (ACPI_FAILURE(status)) { /* * ACPI_PARSE_MODULE_LEVEL means that we are loading a table by * executing it as a control method. However, if we encounter * an error while loading the table, we need to keep trying to * load the table rather than aborting the table load. Set the * status to AE_OK to proceed with the table load. */ if ((walk_state-> parse_flags & ACPI_PARSE_MODULE_LEVEL) && ((status == AE_ALREADY_EXISTS) || (status == AE_NOT_FOUND))) { status = AE_OK; } if (status == AE_CTRL_PARSE_CONTINUE) { continue; } if (status == AE_CTRL_PARSE_PENDING) { status = AE_OK; } if (status == AE_CTRL_TERMINATE) { return_ACPI_STATUS(status); } status = acpi_ps_complete_op(walk_state, &op, status); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (acpi_ns_opens_scope (acpi_ps_get_opcode_info (walk_state->opcode)->object_type)) { /* * If the scope/device op fails to parse, skip the body of * the scope op because the parse failure indicates that * the device may not exist. */ ACPI_INFO(("Skipping parse of AML opcode: %s (0x%4.4X)", acpi_ps_get_opcode_name(walk_state->opcode), walk_state->opcode)); /* * Determine the opcode length before skipping the opcode. * An opcode can be 1 byte or 2 bytes in length. */ opcode_length = 1; if ((walk_state->opcode & 0xFF00) == AML_EXTENDED_OPCODE) { opcode_length = 2; } walk_state->parser_state.aml = walk_state->aml + opcode_length; walk_state->parser_state.aml = acpi_ps_get_next_package_end (&walk_state->parser_state); walk_state->aml = walk_state->parser_state.aml; } continue; } acpi_ex_start_trace_opcode(op, walk_state); } /* * Start arg_count at zero because we don't know if there are * any args yet */ walk_state->arg_count = 0; switch (op->common.aml_opcode) { case AML_BYTE_OP: case AML_WORD_OP: case AML_DWORD_OP: case AML_QWORD_OP: break; default: ASL_CV_CAPTURE_COMMENTS(walk_state); break; } /* Are there any arguments that must be processed? */ if (walk_state->arg_types) { /* Get arguments */ status = acpi_ps_get_arguments(walk_state, aml_op_start, op); if (ACPI_FAILURE(status)) { status = acpi_ps_complete_op(walk_state, &op, status); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if ((walk_state->control_state) && ((walk_state->control_state->control. opcode == AML_IF_OP) || (walk_state->control_state->control. opcode == AML_WHILE_OP))) { /* * If the if/while op fails to parse, we will skip parsing * the body of the op. */ parser_state->aml = walk_state->control_state->control. aml_predicate_start + 1; parser_state->aml = acpi_ps_get_next_package_end (parser_state); walk_state->aml = parser_state->aml; ACPI_ERROR((AE_INFO, "Skipping While/If block")); if (*walk_state->aml == AML_ELSE_OP) { ACPI_ERROR((AE_INFO, "Skipping Else block")); walk_state->parser_state.aml = walk_state->aml + 1; walk_state->parser_state.aml = acpi_ps_get_next_package_end (parser_state); walk_state->aml = parser_state->aml; } ACPI_FREE(acpi_ut_pop_generic_state (&walk_state->control_state)); } op = NULL; continue; } } /* Check for arguments that need to be processed */ ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Parseloop: argument count: %8.8X\n", walk_state->arg_count)); if (walk_state->arg_count) { /* * There are arguments (complex ones), push Op and * prepare for argument */ status = acpi_ps_push_scope(parser_state, op, walk_state->arg_types, walk_state->arg_count); if (ACPI_FAILURE(status)) { status = acpi_ps_complete_op(walk_state, &op, status); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } continue; } op = NULL; continue; } /* * All arguments have been processed -- Op is complete, * prepare for next */ walk_state->op_info = acpi_ps_get_opcode_info(op->common.aml_opcode); if (walk_state->op_info->flags & AML_NAMED) { if (op->common.aml_opcode == AML_REGION_OP || op->common.aml_opcode == AML_DATA_REGION_OP) { /* * Skip parsing of control method or opregion body, * because we don't have enough info in the first pass * to parse them correctly. * * Completed parsing an op_region declaration, we now * know the length. */ op->named.length = (u32) (parser_state->aml - op->named.data); } } if (walk_state->op_info->flags & AML_CREATE) { /* * Backup to beginning of create_XXXfield declaration (1 for * Opcode) * * body_length is unknown until we parse the body */ op->named.length = (u32) (parser_state->aml - op->named.data); } if (op->common.aml_opcode == AML_BANK_FIELD_OP) { /* * Backup to beginning of bank_field declaration * * body_length is unknown until we parse the body */ op->named.length = (u32) (parser_state->aml - op->named.data); } /* This op complete, notify the dispatcher */ if (walk_state->ascending_callback != NULL) { walk_state->op = op; walk_state->opcode = op->common.aml_opcode; status = walk_state->ascending_callback(walk_state); status = acpi_ps_next_parse_state(walk_state, op, status); if (status == AE_CTRL_PENDING) { status = AE_OK; } else if ((walk_state-> parse_flags & ACPI_PARSE_MODULE_LEVEL) && (ACPI_AML_EXCEPTION(status) || status == AE_ALREADY_EXISTS || status == AE_NOT_FOUND)) { /* * ACPI_PARSE_MODULE_LEVEL flag means that we * are currently loading a table by executing * it as a control method. However, if we * encounter an error while loading the table, * we need to keep trying to load the table * rather than aborting the table load (setting * the status to AE_OK continues the table * load). If we get a failure at this point, it * means that the dispatcher got an error while * trying to execute the Op. */ status = AE_OK; } } status = acpi_ps_complete_op(walk_state, &op, status); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } /* while parser_state->Aml */ status = acpi_ps_complete_final_op(walk_state, op, status); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/psloop.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: excreate - Named object creation * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #include "amlcode.h" #include "acnamesp.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("excreate") /******************************************************************************* * * FUNCTION: acpi_ex_create_alias * * PARAMETERS: walk_state - Current state, contains operands * * RETURN: Status * * DESCRIPTION: Create a new named alias * ******************************************************************************/ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state) { struct acpi_namespace_node *target_node; struct acpi_namespace_node *alias_node; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ex_create_alias); /* Get the source/alias operands (both namespace nodes) */ alias_node = (struct acpi_namespace_node *)walk_state->operands[0]; target_node = (struct acpi_namespace_node *)walk_state->operands[1]; if ((target_node->type == ACPI_TYPE_LOCAL_ALIAS) || (target_node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) { /* * Dereference an existing alias so that we don't create a chain * of aliases. With this code, we guarantee that an alias is * always exactly one level of indirection away from the * actual aliased name. */ target_node = ACPI_CAST_PTR(struct acpi_namespace_node, target_node->object); } /* Ensure that the target node is valid */ if (!target_node) { return_ACPI_STATUS(AE_NULL_OBJECT); } /* Construct the alias object (a namespace node) */ switch (target_node->type) { case ACPI_TYPE_METHOD: /* * Control method aliases need to be differentiated with * a special type */ alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS; break; default: /* * All other object types. * * The new alias has the type ALIAS and points to the original * NS node, not the object itself. */ alias_node->type = ACPI_TYPE_LOCAL_ALIAS; alias_node->object = ACPI_CAST_PTR(union acpi_operand_object, target_node); break; } /* Since both operands are Nodes, we don't need to delete them */ alias_node->object = ACPI_CAST_PTR(union acpi_operand_object, target_node); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_create_event * * PARAMETERS: walk_state - Current state * * RETURN: Status * * DESCRIPTION: Create a new event object * ******************************************************************************/ acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state) { acpi_status status; union acpi_operand_object *obj_desc; ACPI_FUNCTION_TRACE(ex_create_event); obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_EVENT); if (!obj_desc) { status = AE_NO_MEMORY; goto cleanup; } /* * Create the actual OS semaphore, with zero initial units -- meaning * that the event is created in an unsignalled state */ status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0, &obj_desc->event.os_semaphore); if (ACPI_FAILURE(status)) { goto cleanup; } /* Attach object to the Node */ status = acpi_ns_attach_object((struct acpi_namespace_node *) walk_state->operands[0], obj_desc, ACPI_TYPE_EVENT); cleanup: /* * Remove local reference to the object (on error, will cause deletion * of both object and semaphore if present.) */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_create_mutex * * PARAMETERS: walk_state - Current state * * RETURN: Status * * DESCRIPTION: Create a new mutex object * * Mutex (Name[0], sync_level[1]) * ******************************************************************************/ acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state) { acpi_status status = AE_OK; union acpi_operand_object *obj_desc; ACPI_FUNCTION_TRACE_PTR(ex_create_mutex, ACPI_WALK_OPERANDS); /* Create the new mutex object */ obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX); if (!obj_desc) { status = AE_NO_MEMORY; goto cleanup; } /* Create the actual OS Mutex */ status = acpi_os_create_mutex(&obj_desc->mutex.os_mutex); if (ACPI_FAILURE(status)) { goto cleanup; } /* Init object and attach to NS node */ obj_desc->mutex.sync_level = (u8)walk_state->operands[1]->integer.value; obj_desc->mutex.node = (struct acpi_namespace_node *)walk_state->operands[0]; status = acpi_ns_attach_object(obj_desc->mutex.node, obj_desc, ACPI_TYPE_MUTEX); cleanup: /* * Remove local reference to the object (on error, will cause deletion * of both object and semaphore if present.) */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_create_region * * PARAMETERS: aml_start - Pointer to the region declaration AML * aml_length - Max length of the declaration AML * space_id - Address space ID for the region * walk_state - Current state * * RETURN: Status * * DESCRIPTION: Create a new operation region object * ******************************************************************************/ acpi_status acpi_ex_create_region(u8 * aml_start, u32 aml_length, u8 space_id, struct acpi_walk_state *walk_state) { acpi_status status; union acpi_operand_object *obj_desc; struct acpi_namespace_node *node; union acpi_operand_object *region_obj2; ACPI_FUNCTION_TRACE(ex_create_region); /* Get the Namespace Node */ node = walk_state->op->common.node; /* * If the region object is already attached to this node, * just return */ if (acpi_ns_get_attached_object(node)) { return_ACPI_STATUS(AE_OK); } /* * Space ID must be one of the predefined IDs, or in the user-defined * range */ if (!acpi_is_valid_space_id(space_id)) { /* * Print an error message, but continue. We don't want to abort * a table load for this exception. Instead, if the region is * actually used at runtime, abort the executing method. */ ACPI_ERROR((AE_INFO, "Invalid/unknown Address Space ID: 0x%2.2X", space_id)); } ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n", acpi_ut_get_region_name(space_id), space_id)); /* Create the region descriptor */ obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION); if (!obj_desc) { status = AE_NO_MEMORY; goto cleanup; } /* * Remember location in AML stream of address & length * operands since they need to be evaluated at run time. */ region_obj2 = acpi_ns_get_secondary_object(obj_desc); region_obj2->extra.aml_start = aml_start; region_obj2->extra.aml_length = aml_length; region_obj2->extra.method_REG = NULL; if (walk_state->scope_info) { region_obj2->extra.scope_node = walk_state->scope_info->scope.node; } else { region_obj2->extra.scope_node = node; } /* Init the region from the operands */ obj_desc->region.space_id = space_id; obj_desc->region.address = 0; obj_desc->region.length = 0; obj_desc->region.pointer = NULL; obj_desc->region.node = node; obj_desc->region.handler = NULL; obj_desc->common.flags &= ~(AOPOBJ_SETUP_COMPLETE | AOPOBJ_REG_CONNECTED | AOPOBJ_OBJECT_INITIALIZED); /* Install the new region object in the parent Node */ status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION); cleanup: /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_create_processor * * PARAMETERS: walk_state - Current state * * RETURN: Status * * DESCRIPTION: Create a new processor object and populate the fields * * Processor (Name[0], cpu_ID[1], pblock_addr[2], pblock_length[3]) * ******************************************************************************/ acpi_status acpi_ex_create_processor(struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; union acpi_operand_object *obj_desc; acpi_status status; ACPI_FUNCTION_TRACE_PTR(ex_create_processor, walk_state); /* Create the processor object */ obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PROCESSOR); if (!obj_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Initialize the processor object from the operands */ obj_desc->processor.proc_id = (u8) operand[1]->integer.value; obj_desc->processor.length = (u8) operand[3]->integer.value; obj_desc->processor.address = (acpi_io_address)operand[2]->integer.value; /* Install the processor object in the parent Node */ status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0], obj_desc, ACPI_TYPE_PROCESSOR); /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_create_power_resource * * PARAMETERS: walk_state - Current state * * RETURN: Status * * DESCRIPTION: Create a new power_resource object and populate the fields * * power_resource (Name[0], system_level[1], resource_order[2]) * ******************************************************************************/ acpi_status acpi_ex_create_power_resource(struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; acpi_status status; union acpi_operand_object *obj_desc; ACPI_FUNCTION_TRACE_PTR(ex_create_power_resource, walk_state); /* Create the power resource object */ obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_POWER); if (!obj_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Initialize the power object from the operands */ obj_desc->power_resource.system_level = (u8) operand[1]->integer.value; obj_desc->power_resource.resource_order = (u16) operand[2]->integer.value; /* Install the power resource object in the parent Node */ status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0], obj_desc, ACPI_TYPE_POWER); /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_create_method * * PARAMETERS: aml_start - First byte of the method's AML * aml_length - AML byte count for this method * walk_state - Current state * * RETURN: Status * * DESCRIPTION: Create a new method object * ******************************************************************************/ acpi_status acpi_ex_create_method(u8 * aml_start, u32 aml_length, struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; union acpi_operand_object *obj_desc; acpi_status status; u8 method_flags; ACPI_FUNCTION_TRACE_PTR(ex_create_method, walk_state); /* Create a new method object */ obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD); if (!obj_desc) { status = AE_NO_MEMORY; goto exit; } /* Save the method's AML pointer and length */ obj_desc->method.aml_start = aml_start; obj_desc->method.aml_length = aml_length; obj_desc->method.node = operand[0]; /* * Disassemble the method flags. Split off the arg_count, Serialized * flag, and sync_level for efficiency. */ method_flags = (u8)operand[1]->integer.value; obj_desc->method.param_count = (u8) (method_flags & AML_METHOD_ARG_COUNT); /* * Get the sync_level. If method is serialized, a mutex will be * created for this method when it is parsed. */ if (method_flags & AML_METHOD_SERIALIZED) { obj_desc->method.info_flags = ACPI_METHOD_SERIALIZED; /* * ACPI 1.0: sync_level = 0 * ACPI 2.0: sync_level = sync_level in method declaration */ obj_desc->method.sync_level = (u8) ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4); } /* Attach the new object to the method Node */ status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0], obj_desc, ACPI_TYPE_METHOD); /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); exit: /* Remove a reference to the operand */ acpi_ut_remove_reference(operand[1]); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/excreate.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: psobject - Support for parse objects * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "amlcode.h" #include "acconvert.h" #include "acnamesp.h" #define _COMPONENT ACPI_PARSER ACPI_MODULE_NAME("psobject") /* Local prototypes */ static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state); /******************************************************************************* * * FUNCTION: acpi_ps_get_aml_opcode * * PARAMETERS: walk_state - Current state * * RETURN: Status * * DESCRIPTION: Extract the next AML opcode from the input stream. * ******************************************************************************/ static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state) { ACPI_ERROR_ONLY(u32 aml_offset); ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state); walk_state->aml = walk_state->parser_state.aml; walk_state->opcode = acpi_ps_peek_opcode(&(walk_state->parser_state)); /* * First cut to determine what we have found: * 1) A valid AML opcode * 2) A name string * 3) An unknown/invalid opcode */ walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode); switch (walk_state->op_info->class) { case AML_CLASS_ASCII: case AML_CLASS_PREFIX: /* * Starts with a valid prefix or ASCII char, this is a name * string. Convert the bare name string to a namepath. */ walk_state->opcode = AML_INT_NAMEPATH_OP; walk_state->arg_types = ARGP_NAMESTRING; break; case AML_CLASS_UNKNOWN: /* The opcode is unrecognized. Complain and skip unknown opcodes */ if (walk_state->pass_number == 2) { ACPI_ERROR_ONLY(aml_offset = (u32)ACPI_PTR_DIFF(walk_state->aml, walk_state-> parser_state. aml_start)); ACPI_ERROR((AE_INFO, "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring", walk_state->opcode, (u32)(aml_offset + sizeof(struct acpi_table_header)))); ACPI_DUMP_BUFFER((walk_state->parser_state.aml - 16), 48); #ifdef ACPI_ASL_COMPILER /* * This is executed for the disassembler only. Output goes * to the disassembled ASL output file. */ acpi_os_printf ("/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n", walk_state->opcode, (u32)(aml_offset + sizeof(struct acpi_table_header))); ACPI_ERROR((AE_INFO, "Aborting disassembly, AML byte code is corrupt")); /* Dump the context surrounding the invalid opcode */ acpi_ut_dump_buffer(((u8 *)walk_state->parser_state. aml - 16), 48, DB_BYTE_DISPLAY, (aml_offset + sizeof(struct acpi_table_header) - 16)); acpi_os_printf(" */\n"); /* * Just abort the disassembly, cannot continue because the * parser is essentially lost. The disassembler can then * randomly fail because an ill-constructed parse tree * can result. */ return_ACPI_STATUS(AE_AML_BAD_OPCODE); #endif } /* Increment past one-byte or two-byte opcode */ walk_state->parser_state.aml++; if (walk_state->opcode > 0xFF) { /* Can only happen if first byte is 0x5B */ walk_state->parser_state.aml++; } return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); default: /* Found opcode info, this is a normal opcode */ walk_state->parser_state.aml += acpi_ps_get_opcode_size(walk_state->opcode); walk_state->arg_types = walk_state->op_info->parse_args; break; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ps_build_named_op * * PARAMETERS: walk_state - Current state * aml_op_start - Begin of named Op in AML * unnamed_op - Early Op (not a named Op) * op - Returned Op * * RETURN: Status * * DESCRIPTION: Parse a named Op * ******************************************************************************/ acpi_status acpi_ps_build_named_op(struct acpi_walk_state *walk_state, u8 *aml_op_start, union acpi_parse_object *unnamed_op, union acpi_parse_object **op) { acpi_status status = AE_OK; union acpi_parse_object *arg = NULL; ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state); unnamed_op->common.value.arg = NULL; unnamed_op->common.arg_list_length = 0; unnamed_op->common.aml_opcode = walk_state->opcode; /* * Get and append arguments until we find the node that contains * the name (the type ARGP_NAME). */ while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) && (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) { ASL_CV_CAPTURE_COMMENTS(walk_state); status = acpi_ps_get_next_arg(walk_state, &(walk_state->parser_state), GET_CURRENT_ARG_TYPE(walk_state-> arg_types), &arg); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_ps_append_arg(unnamed_op, arg); INCREMENT_ARG_LIST(walk_state->arg_types); } /* are there any inline comments associated with the name_seg?? If so, save this. */ ASL_CV_CAPTURE_COMMENTS(walk_state); #ifdef ACPI_ASL_COMPILER if (acpi_gbl_current_inline_comment != NULL) { unnamed_op->common.name_comment = acpi_gbl_current_inline_comment; acpi_gbl_current_inline_comment = NULL; } #endif /* * Make sure that we found a NAME and didn't run out of arguments */ if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) { return_ACPI_STATUS(AE_AML_NO_OPERAND); } /* We know that this arg is a name, move to next arg */ INCREMENT_ARG_LIST(walk_state->arg_types); /* * Find the object. This will either insert the object into * the namespace or simply look it up */ walk_state->op = NULL; status = walk_state->descending_callback(walk_state, op); if (ACPI_FAILURE(status)) { if (status != AE_CTRL_TERMINATE) { ACPI_EXCEPTION((AE_INFO, status, "During name lookup/catalog")); } return_ACPI_STATUS(status); } if (!*op) { return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); } status = acpi_ps_next_parse_state(walk_state, *op, status); if (ACPI_FAILURE(status)) { if (status == AE_CTRL_PENDING) { status = AE_CTRL_PARSE_PENDING; } return_ACPI_STATUS(status); } acpi_ps_append_arg(*op, unnamed_op->common.value.arg); #ifdef ACPI_ASL_COMPILER /* save any comments that might be associated with unnamed_op. */ (*op)->common.inline_comment = unnamed_op->common.inline_comment; (*op)->common.end_node_comment = unnamed_op->common.end_node_comment; (*op)->common.close_brace_comment = unnamed_op->common.close_brace_comment; (*op)->common.name_comment = unnamed_op->common.name_comment; (*op)->common.comment_list = unnamed_op->common.comment_list; (*op)->common.end_blk_comment = unnamed_op->common.end_blk_comment; (*op)->common.cv_filename = unnamed_op->common.cv_filename; (*op)->common.cv_parent_filename = unnamed_op->common.cv_parent_filename; (*op)->named.aml = unnamed_op->common.aml; unnamed_op->common.inline_comment = NULL; unnamed_op->common.end_node_comment = NULL; unnamed_op->common.close_brace_comment = NULL; unnamed_op->common.name_comment = NULL; unnamed_op->common.comment_list = NULL; unnamed_op->common.end_blk_comment = NULL; #endif if ((*op)->common.aml_opcode == AML_REGION_OP || (*op)->common.aml_opcode == AML_DATA_REGION_OP) { /* * Defer final parsing of an operation_region body, because we don't * have enough info in the first pass to parse it correctly (i.e., * there may be method calls within the term_arg elements of the body.) * * However, we must continue parsing because the opregion is not a * standalone package -- we don't know where the end is at this point. * * (Length is unknown until parse of the body complete) */ (*op)->named.data = aml_op_start; (*op)->named.length = 0; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ps_create_op * * PARAMETERS: walk_state - Current state * aml_op_start - Op start in AML * new_op - Returned Op * * RETURN: Status * * DESCRIPTION: Get Op from AML * ******************************************************************************/ acpi_status acpi_ps_create_op(struct acpi_walk_state *walk_state, u8 *aml_op_start, union acpi_parse_object **new_op) { acpi_status status = AE_OK; union acpi_parse_object *op; union acpi_parse_object *named_op = NULL; union acpi_parse_object *parent_scope; u8 argument_count; const struct acpi_opcode_info *op_info; ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state); status = acpi_ps_get_aml_opcode(walk_state); if (status == AE_CTRL_PARSE_CONTINUE) { return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); } if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Create Op structure and append to parent's argument list */ walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode); op = acpi_ps_alloc_op(walk_state->opcode, aml_op_start); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } if (walk_state->op_info->flags & AML_NAMED) { status = acpi_ps_build_named_op(walk_state, aml_op_start, op, &named_op); acpi_ps_free_op(op); #ifdef ACPI_ASL_COMPILER if (acpi_gbl_disasm_flag && walk_state->opcode == AML_EXTERNAL_OP && status == AE_NOT_FOUND) { /* * If parsing of AML_EXTERNAL_OP's name path fails, then skip * past this opcode and keep parsing. This is a much better * alternative than to abort the entire disassembler. At this * point, the parser_state is at the end of the namepath of the * external declaration opcode. Setting walk_state->Aml to * walk_state->parser_state.Aml + 2 moves increments the * walk_state->Aml past the object type and the paramcount of the * external opcode. */ walk_state->aml = walk_state->parser_state.aml + 2; walk_state->parser_state.aml = walk_state->aml; return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); } #endif if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } *new_op = named_op; return_ACPI_STATUS(AE_OK); } /* Not a named opcode, just allocate Op and append to parent */ if (walk_state->op_info->flags & AML_CREATE) { /* * Backup to beginning of create_XXXfield declaration * body_length is unknown until we parse the body */ op->named.data = aml_op_start; op->named.length = 0; } if (walk_state->opcode == AML_BANK_FIELD_OP) { /* * Backup to beginning of bank_field declaration * body_length is unknown until we parse the body */ op->named.data = aml_op_start; op->named.length = 0; } parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state)); acpi_ps_append_arg(parent_scope, op); if (parent_scope) { op_info = acpi_ps_get_opcode_info(parent_scope->common.aml_opcode); if (op_info->flags & AML_HAS_TARGET) { argument_count = acpi_ps_get_argument_count(op_info->type); if (parent_scope->common.arg_list_length > argument_count) { op->common.flags |= ACPI_PARSEOP_TARGET; } } /* * Special case for both Increment() and Decrement(), where * the lone argument is both a source and a target. */ else if ((parent_scope->common.aml_opcode == AML_INCREMENT_OP) || (parent_scope->common.aml_opcode == AML_DECREMENT_OP)) { op->common.flags |= ACPI_PARSEOP_TARGET; } } if (walk_state->descending_callback != NULL) { /* * Find the object. This will either insert the object into * the namespace or simply look it up */ walk_state->op = *new_op = op; status = walk_state->descending_callback(walk_state, &op); status = acpi_ps_next_parse_state(walk_state, op, status); if (status == AE_CTRL_PENDING) { status = AE_CTRL_PARSE_PENDING; } } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ps_complete_op * * PARAMETERS: walk_state - Current state * op - Returned Op * status - Parse status before complete Op * * RETURN: Status * * DESCRIPTION: Complete Op * ******************************************************************************/ acpi_status acpi_ps_complete_op(struct acpi_walk_state *walk_state, union acpi_parse_object **op, acpi_status status) { acpi_status status2; ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state); /* * Finished one argument of the containing scope */ walk_state->parser_state.scope->parse_scope.arg_count--; /* Close this Op (will result in parse subtree deletion) */ status2 = acpi_ps_complete_this_op(walk_state, *op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } *op = NULL; switch (status) { case AE_OK: break; case AE_CTRL_TRANSFER: /* We are about to transfer to a called method */ walk_state->prev_op = NULL; walk_state->prev_arg_types = walk_state->arg_types; return_ACPI_STATUS(status); case AE_CTRL_END: acpi_ps_pop_scope(&(walk_state->parser_state), op, &walk_state->arg_types, &walk_state->arg_count); if (*op) { walk_state->op = *op; walk_state->op_info = acpi_ps_get_opcode_info((*op)->common.aml_opcode); walk_state->opcode = (*op)->common.aml_opcode; status = walk_state->ascending_callback(walk_state); (void)acpi_ps_next_parse_state(walk_state, *op, status); status2 = acpi_ps_complete_this_op(walk_state, *op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } } break; case AE_CTRL_BREAK: case AE_CTRL_CONTINUE: /* Pop off scopes until we find the While */ while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) { acpi_ps_pop_scope(&(walk_state->parser_state), op, &walk_state->arg_types, &walk_state->arg_count); } /* Close this iteration of the While loop */ walk_state->op = *op; walk_state->op_info = acpi_ps_get_opcode_info((*op)->common.aml_opcode); walk_state->opcode = (*op)->common.aml_opcode; status = walk_state->ascending_callback(walk_state); (void)acpi_ps_next_parse_state(walk_state, *op, status); status2 = acpi_ps_complete_this_op(walk_state, *op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } break; case AE_CTRL_TERMINATE: /* Clean up */ do { if (*op) { status2 = acpi_ps_complete_this_op(walk_state, *op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } acpi_ut_delete_generic_state (acpi_ut_pop_generic_state (&walk_state->control_state)); } acpi_ps_pop_scope(&(walk_state->parser_state), op, &walk_state->arg_types, &walk_state->arg_count); } while (*op); return_ACPI_STATUS(AE_OK); default: /* All other non-AE_OK status */ do { if (*op) { /* * These Opcodes need to be removed from the namespace because they * get created even if these opcodes cannot be created due to * errors. */ if (((*op)->common.aml_opcode == AML_REGION_OP) || ((*op)->common.aml_opcode == AML_DATA_REGION_OP)) { acpi_ns_delete_children((*op)->common. node); acpi_ns_remove_node((*op)->common.node); (*op)->common.node = NULL; acpi_ps_delete_parse_tree(*op); } status2 = acpi_ps_complete_this_op(walk_state, *op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } } acpi_ps_pop_scope(&(walk_state->parser_state), op, &walk_state->arg_types, &walk_state->arg_count); } while (*op); #if 0 /* * TBD: Cleanup parse ops on error */ if (*op == NULL) { acpi_ps_pop_scope(parser_state, op, &walk_state->arg_types, &walk_state->arg_count); } #endif walk_state->prev_op = NULL; walk_state->prev_arg_types = walk_state->arg_types; if (walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL) { /* * There was something that went wrong while executing code at the * module-level. We need to skip parsing whatever caused the * error and keep going. One runtime error during the table load * should not cause the entire table to not be loaded. This is * because there could be correct AML beyond the parts that caused * the runtime error. */ ACPI_INFO(("Ignoring error and continuing table load")); return_ACPI_STATUS(AE_OK); } return_ACPI_STATUS(status); } /* This scope complete? */ if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) { acpi_ps_pop_scope(&(walk_state->parser_state), op, &walk_state->arg_types, &walk_state->arg_count); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op)); } else { *op = NULL; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ps_complete_final_op * * PARAMETERS: walk_state - Current state * op - Current Op * status - Current parse status before complete last * Op * * RETURN: Status * * DESCRIPTION: Complete last Op. * ******************************************************************************/ acpi_status acpi_ps_complete_final_op(struct acpi_walk_state *walk_state, union acpi_parse_object *op, acpi_status status) { acpi_status status2; ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state); /* * Complete the last Op (if not completed), and clear the scope stack. * It is easily possible to end an AML "package" with an unbounded number * of open scopes (such as when several ASL blocks are closed with * sequential closing braces). We want to terminate each one cleanly. */ ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n", op)); do { if (op) { if (walk_state->ascending_callback != NULL) { walk_state->op = op; walk_state->op_info = acpi_ps_get_opcode_info(op->common. aml_opcode); walk_state->opcode = op->common.aml_opcode; status = walk_state->ascending_callback(walk_state); status = acpi_ps_next_parse_state(walk_state, op, status); if (status == AE_CTRL_PENDING) { status = acpi_ps_complete_op(walk_state, &op, AE_OK); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } if (status == AE_CTRL_TERMINATE) { status = AE_OK; /* Clean up */ do { if (op) { status2 = acpi_ps_complete_this_op (walk_state, op); if (ACPI_FAILURE (status2)) { return_ACPI_STATUS (status2); } } acpi_ps_pop_scope(& (walk_state-> parser_state), &op, &walk_state-> arg_types, &walk_state-> arg_count); } while (op); return_ACPI_STATUS(status); } else if (ACPI_FAILURE(status)) { /* First error is most important */ (void) acpi_ps_complete_this_op(walk_state, op); return_ACPI_STATUS(status); } } status2 = acpi_ps_complete_this_op(walk_state, op); if (ACPI_FAILURE(status2)) { return_ACPI_STATUS(status2); } } acpi_ps_pop_scope(&(walk_state->parser_state), &op, &walk_state->arg_types, &walk_state->arg_count); } while (op); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/psobject.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: hwvalid - I/O request validation * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_HARDWARE ACPI_MODULE_NAME("hwvalid") /* Local prototypes */ static acpi_status acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width); /* * Protected I/O ports. Some ports are always illegal, and some are * conditionally illegal. This table must remain ordered by port address. * * The table is used to implement the Microsoft port access rules that * first appeared in Windows XP. Some ports are always illegal, and some * ports are only illegal if the BIOS calls _OSI with nothing newer than * the specific _OSI strings. * * This provides ACPICA with the desired port protections and * Microsoft compatibility. * * Description of port entries: * DMA: DMA controller * PIC0: Programmable Interrupt Controller (8259A) * PIT1: System Timer 1 * PIT2: System Timer 2 failsafe * RTC: Real-time clock * CMOS: Extended CMOS * DMA1: DMA 1 page registers * DMA1L: DMA 1 Ch 0 low page * DMA2: DMA 2 page registers * DMA2L: DMA 2 low page refresh * ARBC: Arbitration control * SETUP: Reserved system board setup * POS: POS channel select * PIC1: Cascaded PIC * IDMA: ISA DMA * ELCR: PIC edge/level registers * PCI: PCI configuration space */ static const struct acpi_port_info acpi_protected_ports[] = { {"DMA", 0x0000, 0x000F, ACPI_OSI_WIN_XP}, {"PIC0", 0x0020, 0x0021, ACPI_ALWAYS_ILLEGAL}, {"PIT1", 0x0040, 0x0043, ACPI_OSI_WIN_XP}, {"PIT2", 0x0048, 0x004B, ACPI_OSI_WIN_XP}, {"RTC", 0x0070, 0x0071, ACPI_OSI_WIN_XP}, {"CMOS", 0x0074, 0x0076, ACPI_OSI_WIN_XP}, {"DMA1", 0x0081, 0x0083, ACPI_OSI_WIN_XP}, {"DMA1L", 0x0087, 0x0087, ACPI_OSI_WIN_XP}, {"DMA2", 0x0089, 0x008B, ACPI_OSI_WIN_XP}, {"DMA2L", 0x008F, 0x008F, ACPI_OSI_WIN_XP}, {"ARBC", 0x0090, 0x0091, ACPI_OSI_WIN_XP}, {"SETUP", 0x0093, 0x0094, ACPI_OSI_WIN_XP}, {"POS", 0x0096, 0x0097, ACPI_OSI_WIN_XP}, {"PIC1", 0x00A0, 0x00A1, ACPI_ALWAYS_ILLEGAL}, {"IDMA", 0x00C0, 0x00DF, ACPI_OSI_WIN_XP}, {"ELCR", 0x04D0, 0x04D1, ACPI_ALWAYS_ILLEGAL}, {"PCI", 0x0CF8, 0x0CFF, ACPI_OSI_WIN_XP} }; #define ACPI_PORT_INFO_ENTRIES ACPI_ARRAY_LENGTH (acpi_protected_ports) /****************************************************************************** * * FUNCTION: acpi_hw_validate_io_request * * PARAMETERS: Address Address of I/O port/register * bit_width Number of bits (8,16,32) * * RETURN: Status * * DESCRIPTION: Validates an I/O request (address/length). Certain ports are * always illegal and some ports are only illegal depending on * the requests the BIOS AML code makes to the predefined * _OSI method. * ******************************************************************************/ static acpi_status acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width) { u32 i; u32 byte_width; acpi_io_address last_address; const struct acpi_port_info *port_info; ACPI_FUNCTION_TRACE(hw_validate_io_request); /* Supported widths are 8/16/32 */ if ((bit_width != 8) && (bit_width != 16) && (bit_width != 32)) { ACPI_ERROR((AE_INFO, "Bad BitWidth parameter: %8.8X", bit_width)); return_ACPI_STATUS(AE_BAD_PARAMETER); } port_info = acpi_protected_ports; byte_width = ACPI_DIV_8(bit_width); last_address = address + byte_width - 1; ACPI_DEBUG_PRINT((ACPI_DB_IO, "Address %8.8X%8.8X LastAddress %8.8X%8.8X Length %X", ACPI_FORMAT_UINT64(address), ACPI_FORMAT_UINT64(last_address), byte_width)); /* Maximum 16-bit address in I/O space */ if (last_address > ACPI_UINT16_MAX) { ACPI_ERROR((AE_INFO, "Illegal I/O port address/length above 64K: %8.8X%8.8X/0x%X", ACPI_FORMAT_UINT64(address), byte_width)); return_ACPI_STATUS(AE_LIMIT); } /* Exit if requested address is not within the protected port table */ if (address > acpi_protected_ports[ACPI_PORT_INFO_ENTRIES - 1].end) { return_ACPI_STATUS(AE_OK); } /* Check request against the list of protected I/O ports */ for (i = 0; i < ACPI_PORT_INFO_ENTRIES; i++, port_info++) { /* * Check if the requested address range will write to a reserved * port. There are four cases to consider: * * 1) Address range is contained completely in the port address range * 2) Address range overlaps port range at the port range start * 3) Address range overlaps port range at the port range end * 4) Address range completely encompasses the port range */ if ((address <= port_info->end) && (last_address >= port_info->start)) { /* Port illegality may depend on the _OSI calls made by the BIOS */ if (port_info->osi_dependency == ACPI_ALWAYS_ILLEGAL || acpi_gbl_osi_data == port_info->osi_dependency) { ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "Denied AML access to port 0x%8.8X%8.8X/%X (%s 0x%.4X-0x%.4X)\n", ACPI_FORMAT_UINT64(address), byte_width, port_info->name, port_info->start, port_info->end)); return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS); } } /* Finished if address range ends before the end of this port */ if (last_address <= port_info->end) { break; } } return_ACPI_STATUS(AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_read_port * * PARAMETERS: Address Address of I/O port/register to read * Value Where value (data) is returned * Width Number of bits * * RETURN: Status and value read from port * * DESCRIPTION: Read data from an I/O port or register. This is a front-end * to acpi_os_read_port that performs validation on both the port * address and the length. * *****************************************************************************/ acpi_status acpi_hw_read_port(acpi_io_address address, u32 *value, u32 width) { acpi_status status; u32 one_byte; u32 i; /* Truncate address to 16 bits if requested */ if (acpi_gbl_truncate_io_addresses) { address &= ACPI_UINT16_MAX; } /* Validate the entire request and perform the I/O */ status = acpi_hw_validate_io_request(address, width); if (ACPI_SUCCESS(status)) { status = acpi_os_read_port(address, value, width); return (status); } if (status != AE_AML_ILLEGAL_ADDRESS) { return (status); } /* * There has been a protection violation within the request. Fall * back to byte granularity port I/O and ignore the failing bytes. * This provides compatibility with other ACPI implementations. */ for (i = 0, *value = 0; i < width; i += 8) { /* Validate and read one byte */ if (acpi_hw_validate_io_request(address, 8) == AE_OK) { status = acpi_os_read_port(address, &one_byte, 8); if (ACPI_FAILURE(status)) { return (status); } *value |= (one_byte << i); } address++; } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_write_port * * PARAMETERS: Address Address of I/O port/register to write * Value Value to write * Width Number of bits * * RETURN: Status * * DESCRIPTION: Write data to an I/O port or register. This is a front-end * to acpi_os_write_port that performs validation on both the port * address and the length. * *****************************************************************************/ acpi_status acpi_hw_write_port(acpi_io_address address, u32 value, u32 width) { acpi_status status; u32 i; /* Truncate address to 16 bits if requested */ if (acpi_gbl_truncate_io_addresses) { address &= ACPI_UINT16_MAX; } /* Validate the entire request and perform the I/O */ status = acpi_hw_validate_io_request(address, width); if (ACPI_SUCCESS(status)) { status = acpi_os_write_port(address, value, width); return (status); } if (status != AE_AML_ILLEGAL_ADDRESS) { return (status); } /* * There has been a protection violation within the request. Fall * back to byte granularity port I/O and ignore the failing bytes. * This provides compatibility with other ACPI implementations. */ for (i = 0; i < width; i += 8) { /* Validate and write one byte */ if (acpi_hw_validate_io_request(address, 8) == AE_OK) { status = acpi_os_write_port(address, (value >> i) & 0xFF, 8); if (ACPI_FAILURE(status)) { return (status); } } address++; } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_validate_io_block * * PARAMETERS: Address Address of I/O port/register blobk * bit_width Number of bits (8,16,32) in each register * count Number of registers in the block * * RETURN: Status * * DESCRIPTION: Validates a block of I/O ports/registers. * ******************************************************************************/ acpi_status acpi_hw_validate_io_block(u64 address, u32 bit_width, u32 count) { acpi_status status; while (count--) { status = acpi_hw_validate_io_request((acpi_io_address)address, bit_width); if (ACPI_FAILURE(status)) return_ACPI_STATUS(status); address += ACPI_DIV_8(bit_width); } return_ACPI_STATUS(AE_OK); }
linux-master
drivers/acpi/acpica/hwvalid.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exresnte - AML Interpreter object resolution * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdispat.h" #include "acinterp.h" #include "acnamesp.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exresnte") /******************************************************************************* * * FUNCTION: acpi_ex_resolve_node_to_value * * PARAMETERS: object_ptr - Pointer to a location that contains * a pointer to a NS node, and will receive a * pointer to the resolved object. * walk_state - Current state. Valid only if executing AML * code. NULL if simply resolving an object * * RETURN: Status * * DESCRIPTION: Resolve a Namespace node to a valued object * * Note: for some of the data types, the pointer attached to the Node * can be either a pointer to an actual internal object or a pointer into the * AML stream itself. These types are currently: * * ACPI_TYPE_INTEGER * ACPI_TYPE_STRING * ACPI_TYPE_BUFFER * ACPI_TYPE_MUTEX * ACPI_TYPE_PACKAGE * ******************************************************************************/ acpi_status acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr, struct acpi_walk_state *walk_state) { acpi_status status = AE_OK; union acpi_operand_object *source_desc; union acpi_operand_object *obj_desc = NULL; struct acpi_namespace_node *node; acpi_object_type entry_type; ACPI_FUNCTION_TRACE(ex_resolve_node_to_value); /* * The stack pointer points to a struct acpi_namespace_node (Node). Get the * object that is attached to the Node. */ node = *object_ptr; source_desc = acpi_ns_get_attached_object(node); entry_type = acpi_ns_get_type((acpi_handle)node); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n", node, source_desc, acpi_ut_get_type_name(entry_type))); if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) || (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) { /* There is always exactly one level of indirection */ node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object); source_desc = acpi_ns_get_attached_object(node); entry_type = acpi_ns_get_type((acpi_handle)node); *object_ptr = node; } /* * Several object types require no further processing: * 1) Device/Thermal objects don't have a "real" subobject, return Node * 2) Method locals and arguments have a pseudo-Node * 3) 10/2007: Added method type to assist with Package construction. */ if ((entry_type == ACPI_TYPE_DEVICE) || (entry_type == ACPI_TYPE_THERMAL) || (entry_type == ACPI_TYPE_METHOD) || (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) { return_ACPI_STATUS(AE_OK); } if (!source_desc) { ACPI_ERROR((AE_INFO, "No object attached to node [%4.4s] %p", node->name.ascii, node)); return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE); } /* * Action is based on the type of the Node, which indicates the type * of the attached object or pointer */ switch (entry_type) { case ACPI_TYPE_PACKAGE: if (source_desc->common.type != ACPI_TYPE_PACKAGE) { ACPI_ERROR((AE_INFO, "Object not a Package, type %s", acpi_ut_get_object_type_name(source_desc))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } status = acpi_ds_get_package_arguments(source_desc); if (ACPI_SUCCESS(status)) { /* Return an additional reference to the object */ obj_desc = source_desc; acpi_ut_add_reference(obj_desc); } break; case ACPI_TYPE_BUFFER: if (source_desc->common.type != ACPI_TYPE_BUFFER) { ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s", acpi_ut_get_object_type_name(source_desc))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } status = acpi_ds_get_buffer_arguments(source_desc); if (ACPI_SUCCESS(status)) { /* Return an additional reference to the object */ obj_desc = source_desc; acpi_ut_add_reference(obj_desc); } break; case ACPI_TYPE_STRING: if (source_desc->common.type != ACPI_TYPE_STRING) { ACPI_ERROR((AE_INFO, "Object not a String, type %s", acpi_ut_get_object_type_name(source_desc))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* Return an additional reference to the object */ obj_desc = source_desc; acpi_ut_add_reference(obj_desc); break; case ACPI_TYPE_INTEGER: if (source_desc->common.type != ACPI_TYPE_INTEGER) { ACPI_ERROR((AE_INFO, "Object not a Integer, type %s", acpi_ut_get_object_type_name(source_desc))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* Return an additional reference to the object */ obj_desc = source_desc; acpi_ut_add_reference(obj_desc); break; case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "FieldRead Node=%p SourceDesc=%p Type=%X\n", node, source_desc, entry_type)); status = acpi_ex_read_data_from_field(walk_state, source_desc, &obj_desc); break; /* For these objects, just return the object attached to the Node */ case ACPI_TYPE_MUTEX: case ACPI_TYPE_POWER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_EVENT: case ACPI_TYPE_REGION: /* Return an additional reference to the object */ obj_desc = source_desc; acpi_ut_add_reference(obj_desc); break; /* TYPE_ANY is untyped, and thus there is no object associated with it */ case ACPI_TYPE_ANY: ACPI_ERROR((AE_INFO, "Untyped entry %p, no attached object!", node)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ case ACPI_TYPE_LOCAL_REFERENCE: switch (source_desc->reference.class) { case ACPI_REFCLASS_TABLE: /* This is a ddb_handle */ case ACPI_REFCLASS_REFOF: case ACPI_REFCLASS_INDEX: /* Return an additional reference to the object */ obj_desc = source_desc; acpi_ut_add_reference(obj_desc); break; default: /* No named references are allowed here */ ACPI_ERROR((AE_INFO, "Unsupported Reference type 0x%X", source_desc->reference.class)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } break; default: /* Default case is for unknown types */ ACPI_ERROR((AE_INFO, "Node %p - Unknown object type 0x%X", node, entry_type)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* switch (entry_type) */ /* Return the object descriptor */ *object_ptr = (void *)obj_desc; return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exresnte.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utuuid -- UUID support functions * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_COMPILER ACPI_MODULE_NAME("utuuid") #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_HELP_APP) /* * UUID support functions. * * This table is used to convert an input UUID ascii string to a 16 byte * buffer and the reverse. The table maps a UUID buffer index 0-15 to * the index within the 36-byte UUID string where the associated 2-byte * hex value can be found. * * 36-byte UUID strings are of the form: * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp * Where aa-pp are one byte hex numbers, made up of two hex digits * * Note: This table is basically the inverse of the string-to-offset table * found in the ACPI spec in the description of the to_UUID macro. */ const u8 acpi_gbl_map_to_uuid_offset[UUID_BUFFER_LENGTH] = { 6, 4, 2, 0, 11, 9, 16, 14, 19, 21, 24, 26, 28, 30, 32, 34 }; /******************************************************************************* * * FUNCTION: acpi_ut_convert_string_to_uuid * * PARAMETERS: in_string - 36-byte formatted UUID string * uuid_buffer - Where the 16-byte UUID buffer is returned * * RETURN: None. Output data is returned in the uuid_buffer * * DESCRIPTION: Convert a 36-byte formatted UUID string to 16-byte UUID buffer * ******************************************************************************/ void acpi_ut_convert_string_to_uuid(char *in_string, u8 *uuid_buffer) { u32 i; for (i = 0; i < UUID_BUFFER_LENGTH; i++) { uuid_buffer[i] = (acpi_ut_ascii_char_to_hex (in_string[acpi_gbl_map_to_uuid_offset[i]]) << 4); uuid_buffer[i] |= acpi_ut_ascii_char_to_hex(in_string [acpi_gbl_map_to_uuid_offset[i] + 1]); } } /******************************************************************************* * * FUNCTION: acpi_ut_convert_uuid_to_string * * PARAMETERS: uuid_buffer - 16-byte UUID buffer * out_string - 36-byte formatted UUID string * * RETURN: Status * * DESCRIPTION: Convert 16-byte UUID buffer to 36-byte formatted UUID string * out_string must be 37 bytes to include null terminator. * ******************************************************************************/ acpi_status acpi_ut_convert_uuid_to_string(char *uuid_buffer, char *out_string) { u32 i; if (!uuid_buffer || !out_string) { return (AE_BAD_PARAMETER); } for (i = 0; i < UUID_BUFFER_LENGTH; i++) { out_string[acpi_gbl_map_to_uuid_offset[i]] = acpi_ut_hex_to_ascii_char(uuid_buffer[i], 4); out_string[acpi_gbl_map_to_uuid_offset[i] + 1] = acpi_ut_hex_to_ascii_char(uuid_buffer[i], 0); } /* Insert required hyphens (dashes) */ out_string[UUID_HYPHEN1_OFFSET] = out_string[UUID_HYPHEN2_OFFSET] = out_string[UUID_HYPHEN3_OFFSET] = out_string[UUID_HYPHEN4_OFFSET] = '-'; out_string[UUID_STRING_LENGTH] = 0; /* Null terminate */ return (AE_OK); } #endif
linux-master
drivers/acpi/acpica/utuuid.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: evmisc - Miscellaneous event manager support functions * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #include "acnamesp.h" #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evmisc") /* Local prototypes */ static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context); /******************************************************************************* * * FUNCTION: acpi_ev_is_notify_object * * PARAMETERS: node - Node to check * * RETURN: TRUE if notifies allowed on this object * * DESCRIPTION: Check type of node for a object that supports notifies. * * TBD: This could be replaced by a flag bit in the node. * ******************************************************************************/ u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node) { switch (node->type) { case ACPI_TYPE_DEVICE: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: /* * These are the ONLY objects that can receive ACPI notifications */ return (TRUE); default: return (FALSE); } } /******************************************************************************* * * FUNCTION: acpi_ev_queue_notify_request * * PARAMETERS: node - NS node for the notified object * notify_value - Value from the Notify() request * * RETURN: Status * * DESCRIPTION: Dispatch a device notification event to a previously * installed handler. * ******************************************************************************/ acpi_status acpi_ev_queue_notify_request(struct acpi_namespace_node *node, u32 notify_value) { union acpi_operand_object *obj_desc; union acpi_operand_object *handler_list_head = NULL; union acpi_generic_state *info; u8 handler_list_id = 0; acpi_status status = AE_OK; ACPI_FUNCTION_NAME(ev_queue_notify_request); /* Are Notifies allowed on this object? */ if (!acpi_ev_is_notify_object(node)) { return (AE_TYPE); } /* Get the correct notify list type (System or Device) */ if (notify_value <= ACPI_MAX_SYS_NOTIFY) { handler_list_id = ACPI_SYSTEM_HANDLER_LIST; } else { handler_list_id = ACPI_DEVICE_HANDLER_LIST; } /* Get the notify object attached to the namespace Node */ obj_desc = acpi_ns_get_attached_object(node); if (obj_desc) { /* We have an attached object, Get the correct handler list */ handler_list_head = obj_desc->common_notify.notify_list[handler_list_id]; } /* * If there is no notify handler (Global or Local) * for this object, just ignore the notify */ if (!acpi_gbl_global_notify[handler_list_id].handler && !handler_list_head) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n", acpi_ut_get_node_name(node), notify_value, node)); return (AE_OK); } /* Setup notify info and schedule the notify dispatcher */ info = acpi_ut_create_generic_state(); if (!info) { return (AE_NO_MEMORY); } info->common.descriptor_type = ACPI_DESC_TYPE_STATE_NOTIFY; info->notify.node = node; info->notify.value = (u16)notify_value; info->notify.handler_list_id = handler_list_id; info->notify.handler_list_head = handler_list_head; info->notify.global = &acpi_gbl_global_notify[handler_list_id]; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n", acpi_ut_get_node_name(node), acpi_ut_get_type_name(node->type), notify_value, acpi_ut_get_notify_name(notify_value, ACPI_TYPE_ANY), node)); status = acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch, info); if (ACPI_FAILURE(status)) { acpi_ut_delete_generic_state(info); } return (status); } /******************************************************************************* * * FUNCTION: acpi_ev_notify_dispatch * * PARAMETERS: context - To be passed to the notify handler * * RETURN: None. * * DESCRIPTION: Dispatch a device notification event to a previously * installed handler. * ******************************************************************************/ static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context) { union acpi_generic_state *info = (union acpi_generic_state *)context; union acpi_operand_object *handler_obj; ACPI_FUNCTION_ENTRY(); /* Invoke a global notify handler if installed */ if (info->notify.global->handler) { info->notify.global->handler(info->notify.node, info->notify.value, info->notify.global->context); } /* Now invoke the local notify handler(s) if any are installed */ handler_obj = info->notify.handler_list_head; while (handler_obj) { handler_obj->notify.handler(info->notify.node, info->notify.value, handler_obj->notify.context); handler_obj = handler_obj->notify.next[info->notify.handler_list_id]; } /* All done with the info object */ acpi_ut_delete_generic_state(info); } #if (!ACPI_REDUCED_HARDWARE) /****************************************************************************** * * FUNCTION: acpi_ev_terminate * * PARAMETERS: none * * RETURN: none * * DESCRIPTION: Disable events and free memory allocated for table storage. * ******************************************************************************/ void acpi_ev_terminate(void) { u32 i; acpi_status status; ACPI_FUNCTION_TRACE(ev_terminate); if (acpi_gbl_events_initialized) { /* * Disable all event-related functionality. In all cases, on error, * print a message but obviously we don't abort. */ /* Disable all fixed events */ for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { status = acpi_disable_event(i, 0); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Could not disable fixed event %u", (u32) i)); } } /* Disable all GPEs in all GPE blocks */ status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Could not disable GPEs in GPE block")); } status = acpi_ev_remove_global_lock_handler(); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Could not remove Global Lock handler")); } acpi_gbl_events_initialized = FALSE; } /* Remove SCI handlers */ status = acpi_ev_remove_all_sci_handlers(); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Could not remove SCI handler")); } /* Deallocate all handler objects installed within GPE info structs */ status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Could not delete GPE handlers")); } /* Return to original mode if necessary */ if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) { status = acpi_disable(); if (ACPI_FAILURE(status)) { ACPI_WARNING((AE_INFO, "AcpiDisable failed")); } } return_VOID; } #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/evmisc.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: dbcmds - Miscellaneous debug commands and output routines * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #include "acdebug.h" #include "acnamesp.h" #include "acresrc.h" #include "actables.h" #define _COMPONENT ACPI_CA_DEBUGGER ACPI_MODULE_NAME("dbcmds") /* Local prototypes */ static void acpi_dm_compare_aml_resources(u8 *aml1_buffer, acpi_rsdesc_size aml1_buffer_length, u8 *aml2_buffer, acpi_rsdesc_size aml2_buffer_length); static acpi_status acpi_dm_test_resource_conversion(struct acpi_namespace_node *node, char *name); static acpi_status acpi_db_resource_callback(struct acpi_resource *resource, void *context); static acpi_status acpi_db_device_resources(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static void acpi_db_do_one_sleep_state(u8 sleep_state); static char *acpi_db_trace_method_name = NULL; /******************************************************************************* * * FUNCTION: acpi_db_convert_to_node * * PARAMETERS: in_string - String to convert * * RETURN: Pointer to a NS node * * DESCRIPTION: Convert a string to a valid NS pointer. Handles numeric or * alphanumeric strings. * ******************************************************************************/ struct acpi_namespace_node *acpi_db_convert_to_node(char *in_string) { struct acpi_namespace_node *node; acpi_size address; if ((*in_string >= 0x30) && (*in_string <= 0x39)) { /* Numeric argument, convert */ address = strtoul(in_string, NULL, 16); node = ACPI_TO_POINTER(address); if (!acpi_os_readable(node, sizeof(struct acpi_namespace_node))) { acpi_os_printf("Address %p is invalid", node); return (NULL); } /* Make sure pointer is valid NS node */ if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) { acpi_os_printf ("Address %p is not a valid namespace node [%s]\n", node, acpi_ut_get_descriptor_name(node)); return (NULL); } } else { /* * Alpha argument: The parameter is a name string that must be * resolved to a Namespace object. */ node = acpi_db_local_ns_lookup(in_string); if (!node) { acpi_os_printf ("Could not find [%s] in namespace, defaulting to root node\n", in_string); node = acpi_gbl_root_node; } } return (node); } /******************************************************************************* * * FUNCTION: acpi_db_sleep * * PARAMETERS: object_arg - Desired sleep state (0-5). NULL means * invoke all possible sleep states. * * RETURN: Status * * DESCRIPTION: Simulate sleep/wake sequences * ******************************************************************************/ acpi_status acpi_db_sleep(char *object_arg) { u8 sleep_state; u32 i; ACPI_FUNCTION_TRACE(acpi_db_sleep); /* Null input (no arguments) means to invoke all sleep states */ if (!object_arg) { acpi_os_printf("Invoking all possible sleep states, 0-%d\n", ACPI_S_STATES_MAX); for (i = 0; i <= ACPI_S_STATES_MAX; i++) { acpi_db_do_one_sleep_state((u8)i); } return_ACPI_STATUS(AE_OK); } /* Convert argument to binary and invoke the sleep state */ sleep_state = (u8)strtoul(object_arg, NULL, 0); acpi_db_do_one_sleep_state(sleep_state); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_do_one_sleep_state * * PARAMETERS: sleep_state - Desired sleep state (0-5) * * RETURN: None * * DESCRIPTION: Simulate a sleep/wake sequence * ******************************************************************************/ static void acpi_db_do_one_sleep_state(u8 sleep_state) { acpi_status status; u8 sleep_type_a; u8 sleep_type_b; /* Validate parameter */ if (sleep_state > ACPI_S_STATES_MAX) { acpi_os_printf("Sleep state %d out of range (%d max)\n", sleep_state, ACPI_S_STATES_MAX); return; } acpi_os_printf("\n---- Invoking sleep state S%d (%s):\n", sleep_state, acpi_gbl_sleep_state_names[sleep_state]); /* Get the values for the sleep type registers (for display only) */ status = acpi_get_sleep_type_data(sleep_state, &sleep_type_a, &sleep_type_b); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not evaluate [%s] method, %s\n", acpi_gbl_sleep_state_names[sleep_state], acpi_format_exception(status)); return; } acpi_os_printf ("Register values for sleep state S%d: Sleep-A: %.2X, Sleep-B: %.2X\n", sleep_state, sleep_type_a, sleep_type_b); /* Invoke the various sleep/wake interfaces */ acpi_os_printf("**** Sleep: Prepare to sleep (S%d) ****\n", sleep_state); status = acpi_enter_sleep_state_prep(sleep_state); if (ACPI_FAILURE(status)) { goto error_exit; } acpi_os_printf("**** Sleep: Going to sleep (S%d) ****\n", sleep_state); status = acpi_enter_sleep_state(sleep_state); if (ACPI_FAILURE(status)) { goto error_exit; } acpi_os_printf("**** Wake: Prepare to return from sleep (S%d) ****\n", sleep_state); status = acpi_leave_sleep_state_prep(sleep_state); if (ACPI_FAILURE(status)) { goto error_exit; } acpi_os_printf("**** Wake: Return from sleep (S%d) ****\n", sleep_state); status = acpi_leave_sleep_state(sleep_state); if (ACPI_FAILURE(status)) { goto error_exit; } return; error_exit: ACPI_EXCEPTION((AE_INFO, status, "During invocation of sleep state S%d", sleep_state)); } /******************************************************************************* * * FUNCTION: acpi_db_display_locks * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Display information about internal mutexes. * ******************************************************************************/ void acpi_db_display_locks(void) { u32 i; for (i = 0; i < ACPI_MAX_MUTEX; i++) { acpi_os_printf("%26s : %s\n", acpi_ut_get_mutex_name(i), acpi_gbl_mutex_info[i].thread_id == ACPI_MUTEX_NOT_ACQUIRED ? "Locked" : "Unlocked"); } } /******************************************************************************* * * FUNCTION: acpi_db_display_table_info * * PARAMETERS: table_arg - Name of table to be displayed * * RETURN: None * * DESCRIPTION: Display information about loaded tables. Current * implementation displays all loaded tables. * ******************************************************************************/ void acpi_db_display_table_info(char *table_arg) { u32 i; struct acpi_table_desc *table_desc; acpi_status status; /* Header */ acpi_os_printf("Idx ID Status Type " "TableHeader (Sig, Address, Length, Misc)\n"); /* Walk the entire root table list */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { table_desc = &acpi_gbl_root_table_list.tables[i]; /* Index and Table ID */ acpi_os_printf("%3u %.2u ", i, table_desc->owner_id); /* Decode the table flags */ if (!(table_desc->flags & ACPI_TABLE_IS_LOADED)) { acpi_os_printf("NotLoaded "); } else { acpi_os_printf(" Loaded "); } switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) { case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: acpi_os_printf("External/virtual "); break; case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: acpi_os_printf("Internal/physical "); break; case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: acpi_os_printf("Internal/virtual "); break; default: acpi_os_printf("INVALID TYPE "); break; } /* Make sure that the table is mapped */ status = acpi_tb_validate_table(table_desc); if (ACPI_FAILURE(status)) { return; } /* Dump the table header */ if (table_desc->pointer) { acpi_tb_print_table_header(table_desc->address, table_desc->pointer); } else { /* If the pointer is null, the table has been unloaded */ ACPI_INFO(("%4.4s - Table has been unloaded", table_desc->signature.ascii)); } } } /******************************************************************************* * * FUNCTION: acpi_db_unload_acpi_table * * PARAMETERS: object_name - Namespace pathname for an object that * is owned by the table to be unloaded * * RETURN: None * * DESCRIPTION: Unload an ACPI table, via any namespace node that is owned * by the table. * ******************************************************************************/ void acpi_db_unload_acpi_table(char *object_name) { struct acpi_namespace_node *node; acpi_status status; /* Translate name to an Named object */ node = acpi_db_convert_to_node(object_name); if (!node) { return; } status = acpi_unload_parent_table(ACPI_CAST_PTR(acpi_handle, node)); if (ACPI_SUCCESS(status)) { acpi_os_printf("Parent of [%s] (%p) unloaded and uninstalled\n", object_name, node); } else { acpi_os_printf("%s, while unloading parent table of [%s]\n", acpi_format_exception(status), object_name); } } /******************************************************************************* * * FUNCTION: acpi_db_send_notify * * PARAMETERS: name - Name of ACPI object where to send notify * value - Value of the notify to send. * * RETURN: None * * DESCRIPTION: Send an ACPI notification. The value specified is sent to the * named object as an ACPI notify. * ******************************************************************************/ void acpi_db_send_notify(char *name, u32 value) { struct acpi_namespace_node *node; acpi_status status; /* Translate name to an Named object */ node = acpi_db_convert_to_node(name); if (!node) { return; } /* Dispatch the notify if legal */ if (acpi_ev_is_notify_object(node)) { status = acpi_ev_queue_notify_request(node, value); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not queue notify\n"); } } else { acpi_os_printf("Named object [%4.4s] Type %s, " "must be Device/Thermal/Processor type\n", acpi_ut_get_node_name(node), acpi_ut_get_type_name(node->type)); } } /******************************************************************************* * * FUNCTION: acpi_db_display_interfaces * * PARAMETERS: action_arg - Null, "install", or "remove" * interface_name_arg - Name for install/remove options * * RETURN: None * * DESCRIPTION: Display or modify the global _OSI interface list * ******************************************************************************/ void acpi_db_display_interfaces(char *action_arg, char *interface_name_arg) { struct acpi_interface_info *next_interface; char *sub_string; acpi_status status; /* If no arguments, just display current interface list */ if (!action_arg) { (void)acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER); next_interface = acpi_gbl_supported_interfaces; while (next_interface) { if (!(next_interface->flags & ACPI_OSI_INVALID)) { acpi_os_printf("%s\n", next_interface->name); } next_interface = next_interface->next; } acpi_os_release_mutex(acpi_gbl_osi_mutex); return; } /* If action_arg exists, so must interface_name_arg */ if (!interface_name_arg) { acpi_os_printf("Missing Interface Name argument\n"); return; } /* Uppercase the action for match below */ acpi_ut_strupr(action_arg); /* install - install an interface */ sub_string = strstr("INSTALL", action_arg); if (sub_string) { status = acpi_install_interface(interface_name_arg); if (ACPI_FAILURE(status)) { acpi_os_printf("%s, while installing \"%s\"\n", acpi_format_exception(status), interface_name_arg); } return; } /* remove - remove an interface */ sub_string = strstr("REMOVE", action_arg); if (sub_string) { status = acpi_remove_interface(interface_name_arg); if (ACPI_FAILURE(status)) { acpi_os_printf("%s, while removing \"%s\"\n", acpi_format_exception(status), interface_name_arg); } return; } /* Invalid action_arg */ acpi_os_printf("Invalid action argument: %s\n", action_arg); return; } /******************************************************************************* * * FUNCTION: acpi_db_display_template * * PARAMETERS: buffer_arg - Buffer name or address * * RETURN: None * * DESCRIPTION: Dump a buffer that contains a resource template * ******************************************************************************/ void acpi_db_display_template(char *buffer_arg) { struct acpi_namespace_node *node; acpi_status status; struct acpi_buffer return_buffer; /* Translate buffer_arg to an Named object */ node = acpi_db_convert_to_node(buffer_arg); if (!node || (node == acpi_gbl_root_node)) { acpi_os_printf("Invalid argument: %s\n", buffer_arg); return; } /* We must have a buffer object */ if (node->type != ACPI_TYPE_BUFFER) { acpi_os_printf ("Not a Buffer object, cannot be a template: %s\n", buffer_arg); return; } return_buffer.length = ACPI_DEBUG_BUFFER_SIZE; return_buffer.pointer = acpi_gbl_db_buffer; /* Attempt to convert the raw buffer to a resource list */ status = acpi_rs_create_resource_list(node->object, &return_buffer); acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT); acpi_dbg_level |= ACPI_LV_RESOURCES; if (ACPI_FAILURE(status)) { acpi_os_printf ("Could not convert Buffer to a resource list: %s, %s\n", buffer_arg, acpi_format_exception(status)); goto dump_buffer; } /* Now we can dump the resource list */ acpi_rs_dump_resource_list(ACPI_CAST_PTR(struct acpi_resource, return_buffer.pointer)); dump_buffer: acpi_os_printf("\nRaw data buffer:\n"); acpi_ut_debug_dump_buffer((u8 *)node->object->buffer.pointer, node->object->buffer.length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX); acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT); return; } /******************************************************************************* * * FUNCTION: acpi_dm_compare_aml_resources * * PARAMETERS: aml1_buffer - Contains first resource list * aml1_buffer_length - Length of first resource list * aml2_buffer - Contains second resource list * aml2_buffer_length - Length of second resource list * * RETURN: None * * DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in * order to isolate a miscompare to an individual resource) * ******************************************************************************/ static void acpi_dm_compare_aml_resources(u8 *aml1_buffer, acpi_rsdesc_size aml1_buffer_length, u8 *aml2_buffer, acpi_rsdesc_size aml2_buffer_length) { u8 *aml1; u8 *aml2; u8 *aml1_end; u8 *aml2_end; acpi_rsdesc_size aml1_length; acpi_rsdesc_size aml2_length; acpi_rsdesc_size offset = 0; u8 resource_type; u32 count = 0; u32 i; /* Compare overall buffer sizes (may be different due to size rounding) */ if (aml1_buffer_length != aml2_buffer_length) { acpi_os_printf("**** Buffer length mismatch in converted " "AML: Original %X, New %X ****\n", aml1_buffer_length, aml2_buffer_length); } aml1 = aml1_buffer; aml2 = aml2_buffer; aml1_end = aml1_buffer + aml1_buffer_length; aml2_end = aml2_buffer + aml2_buffer_length; /* Walk the descriptor lists, comparing each descriptor */ while ((aml1 < aml1_end) && (aml2 < aml2_end)) { /* Get the lengths of each descriptor */ aml1_length = acpi_ut_get_descriptor_length(aml1); aml2_length = acpi_ut_get_descriptor_length(aml2); resource_type = acpi_ut_get_resource_type(aml1); /* Check for descriptor length match */ if (aml1_length != aml2_length) { acpi_os_printf ("**** Length mismatch in descriptor [%.2X] type %2.2X, " "Offset %8.8X Len1 %X, Len2 %X ****\n", count, resource_type, offset, aml1_length, aml2_length); } /* Check for descriptor byte match */ else if (memcmp(aml1, aml2, aml1_length)) { acpi_os_printf ("**** Data mismatch in descriptor [%.2X] type %2.2X, " "Offset %8.8X ****\n", count, resource_type, offset); for (i = 0; i < aml1_length; i++) { if (aml1[i] != aml2[i]) { acpi_os_printf ("Mismatch at byte offset %.2X: is %2.2X, " "should be %2.2X\n", i, aml2[i], aml1[i]); } } } /* Exit on end_tag descriptor */ if (resource_type == ACPI_RESOURCE_NAME_END_TAG) { return; } /* Point to next descriptor in each buffer */ count++; offset += aml1_length; aml1 += aml1_length; aml2 += aml2_length; } } /******************************************************************************* * * FUNCTION: acpi_dm_test_resource_conversion * * PARAMETERS: node - Parent device node * name - resource method name (_CRS) * * RETURN: Status * * DESCRIPTION: Compare the original AML with a conversion of the AML to * internal resource list, then back to AML. * ******************************************************************************/ static acpi_status acpi_dm_test_resource_conversion(struct acpi_namespace_node *node, char *name) { acpi_status status; struct acpi_buffer return_buffer; struct acpi_buffer resource_buffer; struct acpi_buffer new_aml; union acpi_object *original_aml; acpi_os_printf("Resource Conversion Comparison:\n"); new_aml.length = ACPI_ALLOCATE_LOCAL_BUFFER; return_buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; resource_buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; /* Get the original _CRS AML resource template */ status = acpi_evaluate_object(node, name, NULL, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not obtain %s: %s\n", name, acpi_format_exception(status)); return (status); } /* Get the AML resource template, converted to internal resource structs */ status = acpi_get_current_resources(node, &resource_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("AcpiGetCurrentResources failed: %s\n", acpi_format_exception(status)); goto exit1; } /* Convert internal resource list to external AML resource template */ status = acpi_rs_create_aml_resources(&resource_buffer, &new_aml); if (ACPI_FAILURE(status)) { acpi_os_printf("AcpiRsCreateAmlResources failed: %s\n", acpi_format_exception(status)); goto exit2; } /* Compare original AML to the newly created AML resource list */ original_aml = return_buffer.pointer; acpi_dm_compare_aml_resources(original_aml->buffer.pointer, (acpi_rsdesc_size)original_aml->buffer. length, new_aml.pointer, (acpi_rsdesc_size)new_aml.length); /* Cleanup and exit */ ACPI_FREE(new_aml.pointer); exit2: ACPI_FREE(resource_buffer.pointer); exit1: ACPI_FREE(return_buffer.pointer); return (status); } /******************************************************************************* * * FUNCTION: acpi_db_resource_callback * * PARAMETERS: acpi_walk_resource_callback * * RETURN: Status * * DESCRIPTION: Simple callback to exercise acpi_walk_resources and * acpi_walk_resource_buffer. * ******************************************************************************/ static acpi_status acpi_db_resource_callback(struct acpi_resource *resource, void *context) { return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_device_resources * * PARAMETERS: acpi_walk_callback * * RETURN: Status * * DESCRIPTION: Display the _PRT/_CRS/_PRS resources for a device object. * ******************************************************************************/ static acpi_status acpi_db_device_resources(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_namespace_node *node; struct acpi_namespace_node *prt_node = NULL; struct acpi_namespace_node *crs_node = NULL; struct acpi_namespace_node *prs_node = NULL; struct acpi_namespace_node *aei_node = NULL; char *parent_path; struct acpi_buffer return_buffer; acpi_status status; node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); parent_path = acpi_ns_get_normalized_pathname(node, TRUE); if (!parent_path) { return (AE_NO_MEMORY); } /* Get handles to the resource methods for this device */ (void)acpi_get_handle(node, METHOD_NAME__PRT, ACPI_CAST_PTR(acpi_handle, &prt_node)); (void)acpi_get_handle(node, METHOD_NAME__CRS, ACPI_CAST_PTR(acpi_handle, &crs_node)); (void)acpi_get_handle(node, METHOD_NAME__PRS, ACPI_CAST_PTR(acpi_handle, &prs_node)); (void)acpi_get_handle(node, METHOD_NAME__AEI, ACPI_CAST_PTR(acpi_handle, &aei_node)); if (!prt_node && !crs_node && !prs_node && !aei_node) { goto cleanup; /* Nothing to do */ } acpi_os_printf("\nDevice: %s\n", parent_path); /* Prepare for a return object of arbitrary size */ return_buffer.pointer = acpi_gbl_db_buffer; return_buffer.length = ACPI_DEBUG_BUFFER_SIZE; /* _PRT */ if (prt_node) { acpi_os_printf("Evaluating _PRT\n"); status = acpi_evaluate_object(prt_node, NULL, NULL, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not evaluate _PRT: %s\n", acpi_format_exception(status)); goto get_crs; } return_buffer.pointer = acpi_gbl_db_buffer; return_buffer.length = ACPI_DEBUG_BUFFER_SIZE; status = acpi_get_irq_routing_table(node, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("GetIrqRoutingTable failed: %s\n", acpi_format_exception(status)); goto get_crs; } acpi_rs_dump_irq_list(ACPI_CAST_PTR(u8, acpi_gbl_db_buffer)); } /* _CRS */ get_crs: if (crs_node) { acpi_os_printf("Evaluating _CRS\n"); return_buffer.pointer = acpi_gbl_db_buffer; return_buffer.length = ACPI_DEBUG_BUFFER_SIZE; status = acpi_evaluate_object(crs_node, NULL, NULL, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not evaluate _CRS: %s\n", acpi_format_exception(status)); goto get_prs; } /* This code exercises the acpi_walk_resources interface */ status = acpi_walk_resources(node, METHOD_NAME__CRS, acpi_db_resource_callback, NULL); if (ACPI_FAILURE(status)) { acpi_os_printf("AcpiWalkResources failed: %s\n", acpi_format_exception(status)); goto get_prs; } /* Get the _CRS resource list (test ALLOCATE buffer) */ return_buffer.pointer = NULL; return_buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_get_current_resources(node, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("AcpiGetCurrentResources failed: %s\n", acpi_format_exception(status)); goto get_prs; } /* This code exercises the acpi_walk_resource_buffer interface */ status = acpi_walk_resource_buffer(&return_buffer, acpi_db_resource_callback, NULL); if (ACPI_FAILURE(status)) { acpi_os_printf("AcpiWalkResourceBuffer failed: %s\n", acpi_format_exception(status)); goto end_crs; } /* Dump the _CRS resource list */ acpi_rs_dump_resource_list(ACPI_CAST_PTR(struct acpi_resource, return_buffer. pointer)); /* * Perform comparison of original AML to newly created AML. This * tests both the AML->Resource conversion and the Resource->AML * conversion. */ (void)acpi_dm_test_resource_conversion(node, METHOD_NAME__CRS); /* Execute _SRS with the resource list */ acpi_os_printf("Evaluating _SRS\n"); status = acpi_set_current_resources(node, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("AcpiSetCurrentResources failed: %s\n", acpi_format_exception(status)); goto end_crs; } end_crs: ACPI_FREE(return_buffer.pointer); } /* _PRS */ get_prs: if (prs_node) { acpi_os_printf("Evaluating _PRS\n"); return_buffer.pointer = acpi_gbl_db_buffer; return_buffer.length = ACPI_DEBUG_BUFFER_SIZE; status = acpi_evaluate_object(prs_node, NULL, NULL, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not evaluate _PRS: %s\n", acpi_format_exception(status)); goto get_aei; } return_buffer.pointer = acpi_gbl_db_buffer; return_buffer.length = ACPI_DEBUG_BUFFER_SIZE; status = acpi_get_possible_resources(node, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("AcpiGetPossibleResources failed: %s\n", acpi_format_exception(status)); goto get_aei; } acpi_rs_dump_resource_list(ACPI_CAST_PTR (struct acpi_resource, acpi_gbl_db_buffer)); } /* _AEI */ get_aei: if (aei_node) { acpi_os_printf("Evaluating _AEI\n"); return_buffer.pointer = acpi_gbl_db_buffer; return_buffer.length = ACPI_DEBUG_BUFFER_SIZE; status = acpi_evaluate_object(aei_node, NULL, NULL, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not evaluate _AEI: %s\n", acpi_format_exception(status)); goto cleanup; } return_buffer.pointer = acpi_gbl_db_buffer; return_buffer.length = ACPI_DEBUG_BUFFER_SIZE; status = acpi_get_event_resources(node, &return_buffer); if (ACPI_FAILURE(status)) { acpi_os_printf("AcpiGetEventResources failed: %s\n", acpi_format_exception(status)); goto cleanup; } acpi_rs_dump_resource_list(ACPI_CAST_PTR (struct acpi_resource, acpi_gbl_db_buffer)); } cleanup: ACPI_FREE(parent_path); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_display_resources * * PARAMETERS: object_arg - String object name or object pointer. * NULL or "*" means "display resources for * all devices" * * RETURN: None * * DESCRIPTION: Display the resource objects associated with a device. * ******************************************************************************/ void acpi_db_display_resources(char *object_arg) { struct acpi_namespace_node *node; acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT); acpi_dbg_level |= ACPI_LV_RESOURCES; /* Asterisk means "display resources for all devices" */ if (!object_arg || (!strcmp(object_arg, "*"))) { (void)acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_device_resources, NULL, NULL, NULL); } else { /* Convert string to object pointer */ node = acpi_db_convert_to_node(object_arg); if (node) { if (node->type != ACPI_TYPE_DEVICE) { acpi_os_printf ("%4.4s: Name is not a device object (%s)\n", node->name.ascii, acpi_ut_get_type_name(node->type)); } else { (void)acpi_db_device_resources(node, 0, NULL, NULL); } } } acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT); } /******************************************************************************* * * FUNCTION: acpi_db_generate_ged * * PARAMETERS: ged_arg - Raw GED number, ascii string * * RETURN: None * * DESCRIPTION: Simulate firing of a GED * ******************************************************************************/ void acpi_db_generate_interrupt(char *gsiv_arg) { u32 gsiv_number; struct acpi_ged_handler_info *ged_info = acpi_gbl_ged_handler_list; if (!ged_info) { acpi_os_printf("No GED handling present\n"); } gsiv_number = strtoul(gsiv_arg, NULL, 0); while (ged_info) { if (ged_info->int_id == gsiv_number) { struct acpi_object_list arg_list; union acpi_object arg0; acpi_handle evt_handle = ged_info->evt_method; acpi_status status; acpi_os_printf("Evaluate GED _EVT (GSIV=%d)\n", gsiv_number); if (!evt_handle) { acpi_os_printf("Undefined _EVT method\n"); return; } arg0.integer.type = ACPI_TYPE_INTEGER; arg0.integer.value = gsiv_number; arg_list.count = 1; arg_list.pointer = &arg0; status = acpi_evaluate_object(evt_handle, NULL, &arg_list, NULL); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not evaluate _EVT\n"); return; } } ged_info = ged_info->next; } } #if (!ACPI_REDUCED_HARDWARE) /******************************************************************************* * * FUNCTION: acpi_db_generate_gpe * * PARAMETERS: gpe_arg - Raw GPE number, ascii string * block_arg - GPE block number, ascii string * 0 or 1 for FADT GPE blocks * * RETURN: None * * DESCRIPTION: Simulate firing of a GPE * ******************************************************************************/ void acpi_db_generate_gpe(char *gpe_arg, char *block_arg) { u32 block_number = 0; u32 gpe_number; struct acpi_gpe_event_info *gpe_event_info; gpe_number = strtoul(gpe_arg, NULL, 0); /* * If no block arg, or block arg == 0 or 1, use the FADT-defined * GPE blocks. */ if (block_arg) { block_number = strtoul(block_arg, NULL, 0); if (block_number == 1) { block_number = 0; } } gpe_event_info = acpi_ev_get_gpe_event_info(ACPI_TO_POINTER(block_number), gpe_number); if (!gpe_event_info) { acpi_os_printf("Invalid GPE\n"); return; } (void)acpi_ev_gpe_dispatch(NULL, gpe_event_info, gpe_number); } /******************************************************************************* * * FUNCTION: acpi_db_generate_sci * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Simulate an SCI -- just call the SCI dispatch. * ******************************************************************************/ void acpi_db_generate_sci(void) { acpi_ev_sci_dispatch(); } #endif /* !ACPI_REDUCED_HARDWARE */ /******************************************************************************* * * FUNCTION: acpi_db_trace * * PARAMETERS: enable_arg - ENABLE/AML to enable tracer * DISABLE to disable tracer * method_arg - Method to trace * once_arg - Whether trace once * * RETURN: None * * DESCRIPTION: Control method tracing facility * ******************************************************************************/ void acpi_db_trace(char *enable_arg, char *method_arg, char *once_arg) { u32 debug_level = 0; u32 debug_layer = 0; u32 flags = 0; acpi_ut_strupr(enable_arg); acpi_ut_strupr(once_arg); if (method_arg) { if (acpi_db_trace_method_name) { ACPI_FREE(acpi_db_trace_method_name); acpi_db_trace_method_name = NULL; } acpi_db_trace_method_name = ACPI_ALLOCATE(strlen(method_arg) + 1); if (!acpi_db_trace_method_name) { acpi_os_printf("Failed to allocate method name (%s)\n", method_arg); return; } strcpy(acpi_db_trace_method_name, method_arg); } if (!strcmp(enable_arg, "ENABLE") || !strcmp(enable_arg, "METHOD") || !strcmp(enable_arg, "OPCODE")) { if (!strcmp(enable_arg, "ENABLE")) { /* Inherit current console settings */ debug_level = acpi_gbl_db_console_debug_level; debug_layer = acpi_dbg_layer; } else { /* Restrict console output to trace points only */ debug_level = ACPI_LV_TRACE_POINT; debug_layer = ACPI_EXECUTER; } flags = ACPI_TRACE_ENABLED; if (!strcmp(enable_arg, "OPCODE")) { flags |= ACPI_TRACE_OPCODE; } if (once_arg && !strcmp(once_arg, "ONCE")) { flags |= ACPI_TRACE_ONESHOT; } } (void)acpi_debug_trace(acpi_db_trace_method_name, debug_level, debug_layer, flags); }
linux-master
drivers/acpi/acpica/dbcmds.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: rslist - Linked list utilities * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rslist") /******************************************************************************* * * FUNCTION: acpi_rs_convert_aml_to_resources * * PARAMETERS: acpi_walk_aml_callback * resource_ptr - Pointer to the buffer that will * contain the output structures * * RETURN: Status * * DESCRIPTION: Convert an AML resource to an internal representation of the * resource that is aligned and easier to access. * ******************************************************************************/ acpi_status acpi_rs_convert_aml_to_resources(u8 * aml, u32 length, u32 offset, u8 resource_index, void **context) { struct acpi_resource **resource_ptr = ACPI_CAST_INDIRECT_PTR(struct acpi_resource, context); struct acpi_resource *resource; union aml_resource *aml_resource; struct acpi_rsconvert_info *conversion_table; acpi_status status; ACPI_FUNCTION_TRACE(rs_convert_aml_to_resources); /* * Check that the input buffer and all subsequent pointers into it * are aligned on a native word boundary. Most important on IA64 */ resource = *resource_ptr; if (ACPI_IS_MISALIGNED(resource)) { ACPI_WARNING((AE_INFO, "Misaligned resource pointer %p", resource)); } /* Get the appropriate conversion info table */ aml_resource = ACPI_CAST_PTR(union aml_resource, aml); if (acpi_ut_get_resource_type(aml) == ACPI_RESOURCE_NAME_SERIAL_BUS) { /* Avoid undefined behavior: member access within misaligned address */ struct aml_resource_common_serialbus common_serial_bus; memcpy(&common_serial_bus, aml_resource, sizeof(common_serial_bus)); if (common_serial_bus.type > AML_RESOURCE_MAX_SERIALBUSTYPE) { conversion_table = NULL; } else { /* This is an I2C, SPI, UART, or CSI2 serial_bus descriptor */ conversion_table = acpi_gbl_convert_resource_serial_bus_dispatch [common_serial_bus.type]; } } else { conversion_table = acpi_gbl_get_resource_dispatch[resource_index]; } if (!conversion_table) { ACPI_ERROR((AE_INFO, "Invalid/unsupported resource descriptor: Type 0x%2.2X", resource_index)); return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); } /* Convert the AML byte stream resource to a local resource struct */ status = acpi_rs_convert_aml_to_resource(resource, aml_resource, conversion_table); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Could not convert AML resource (Type 0x%X)", *aml)); return_ACPI_STATUS(status); } if (!resource->length) { ACPI_EXCEPTION((AE_INFO, status, "Zero-length resource returned from RsConvertAmlToResource")); } ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Type %.2X, AmlLength %.2X InternalLength %.2X\n", acpi_ut_get_resource_type(aml), length, resource->length)); /* Point to the next structure in the output buffer */ *resource_ptr = ACPI_NEXT_RESOURCE(resource); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_rs_convert_resources_to_aml * * PARAMETERS: resource - Pointer to the resource linked list * aml_size_needed - Calculated size of the byte stream * needed from calling acpi_rs_get_aml_length() * The size of the output_buffer is * guaranteed to be >= aml_size_needed * output_buffer - Pointer to the buffer that will * contain the byte stream * * RETURN: Status * * DESCRIPTION: Takes the resource linked list and parses it, creating a * byte stream of resources in the caller's output buffer * ******************************************************************************/ acpi_status acpi_rs_convert_resources_to_aml(struct acpi_resource *resource, acpi_size aml_size_needed, u8 * output_buffer) { u8 *aml = output_buffer; u8 *end_aml = output_buffer + aml_size_needed; struct acpi_rsconvert_info *conversion_table; acpi_status status; ACPI_FUNCTION_TRACE(rs_convert_resources_to_aml); /* Walk the resource descriptor list, convert each descriptor */ while (aml < end_aml) { /* Validate the (internal) Resource Type */ if (resource->type > ACPI_RESOURCE_TYPE_MAX) { ACPI_ERROR((AE_INFO, "Invalid descriptor type (0x%X) in resource list", resource->type)); return_ACPI_STATUS(AE_BAD_DATA); } /* Sanity check the length. It must not be zero, or we loop forever */ if (!resource->length) { ACPI_ERROR((AE_INFO, "Invalid zero length descriptor in resource list\n")); return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); } /* Perform the conversion */ if (resource->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) { if (resource->data.common_serial_bus.type > AML_RESOURCE_MAX_SERIALBUSTYPE) { conversion_table = NULL; } else { /* This is an I2C, SPI, UART or CSI2 serial_bus descriptor */ conversion_table = acpi_gbl_convert_resource_serial_bus_dispatch [resource->data.common_serial_bus.type]; } } else { conversion_table = acpi_gbl_set_resource_dispatch[resource->type]; } if (!conversion_table) { ACPI_ERROR((AE_INFO, "Invalid/unsupported resource descriptor: Type 0x%2.2X", resource->type)); return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE); } status = acpi_rs_convert_resource_to_aml(resource, ACPI_CAST_PTR(union aml_resource, aml), conversion_table); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Could not convert resource (type 0x%X) to AML", resource->type)); return_ACPI_STATUS(status); } /* Perform final sanity check on the new AML resource descriptor */ status = acpi_ut_validate_resource(NULL, ACPI_CAST_PTR(union aml_resource, aml), NULL); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Check for end-of-list, normal exit */ if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) { /* An End Tag indicates the end of the input Resource Template */ return_ACPI_STATUS(AE_OK); } /* * Extract the total length of the new descriptor and set the * Aml to point to the next (output) resource descriptor */ aml += acpi_ut_get_descriptor_length(aml); /* Point to the next input resource descriptor */ resource = ACPI_NEXT_RESOURCE(resource); } /* Completed buffer, but did not find an end_tag resource descriptor */ return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); }
linux-master
drivers/acpi/acpica/rslist.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: evrgnini- ACPI address_space (op_region) init * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #include "acnamesp.h" #include "acinterp.h" #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evrgnini") /******************************************************************************* * * FUNCTION: acpi_ev_system_memory_region_setup * * PARAMETERS: handle - Region we are interested in * function - Start or stop * handler_context - Address space handler context * region_context - Region specific context * * RETURN: Status * * DESCRIPTION: Setup a system_memory operation region * ******************************************************************************/ acpi_status acpi_ev_system_memory_region_setup(acpi_handle handle, u32 function, void *handler_context, void **region_context) { union acpi_operand_object *region_desc = (union acpi_operand_object *)handle; struct acpi_mem_space_context *local_region_context; struct acpi_mem_mapping *mm; ACPI_FUNCTION_TRACE(ev_system_memory_region_setup); if (function == ACPI_REGION_DEACTIVATE) { if (*region_context) { local_region_context = (struct acpi_mem_space_context *)*region_context; /* Delete memory mappings if present */ while (local_region_context->first_mm) { mm = local_region_context->first_mm; local_region_context->first_mm = mm->next_mm; acpi_os_unmap_memory(mm->logical_address, mm->length); ACPI_FREE(mm); } ACPI_FREE(local_region_context); *region_context = NULL; } return_ACPI_STATUS(AE_OK); } /* Create a new context */ local_region_context = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_mem_space_context)); if (!(local_region_context)) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Save the region length and address for use in the handler */ local_region_context->length = region_desc->region.length; local_region_context->address = region_desc->region.address; *region_context = local_region_context; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_io_space_region_setup * * PARAMETERS: handle - Region we are interested in * function - Start or stop * handler_context - Address space handler context * region_context - Region specific context * * RETURN: Status * * DESCRIPTION: Setup a IO operation region * ******************************************************************************/ acpi_status acpi_ev_io_space_region_setup(acpi_handle handle, u32 function, void *handler_context, void **region_context) { ACPI_FUNCTION_TRACE(ev_io_space_region_setup); if (function == ACPI_REGION_DEACTIVATE) { *region_context = NULL; } else { *region_context = handler_context; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_pci_config_region_setup * * PARAMETERS: handle - Region we are interested in * function - Start or stop * handler_context - Address space handler context * region_context - Region specific context * * RETURN: Status * * DESCRIPTION: Setup a PCI_Config operation region * * MUTEX: Assumes namespace is not locked * ******************************************************************************/ acpi_status acpi_ev_pci_config_region_setup(acpi_handle handle, u32 function, void *handler_context, void **region_context) { acpi_status status = AE_OK; u64 pci_value; struct acpi_pci_id *pci_id = *region_context; union acpi_operand_object *handler_obj; struct acpi_namespace_node *parent_node; struct acpi_namespace_node *pci_root_node; struct acpi_namespace_node *pci_device_node; union acpi_operand_object *region_obj = (union acpi_operand_object *)handle; ACPI_FUNCTION_TRACE(ev_pci_config_region_setup); handler_obj = region_obj->region.handler; if (!handler_obj) { /* * No installed handler. This shouldn't happen because the dispatch * routine checks before we get here, but we check again just in case. */ ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Attempting to init a region %p, with no handler\n", region_obj)); return_ACPI_STATUS(AE_NOT_EXIST); } *region_context = NULL; if (function == ACPI_REGION_DEACTIVATE) { if (pci_id) { ACPI_FREE(pci_id); } return_ACPI_STATUS(status); } parent_node = region_obj->region.node->parent; /* * Get the _SEG and _BBN values from the device upon which the handler * is installed. * * We need to get the _SEG and _BBN objects relative to the PCI BUS device. * This is the device the handler has been registered to handle. */ /* * If the address_space.Node is still pointing to the root, we need * to scan upward for a PCI Root bridge and re-associate the op_region * handlers with that device. */ if (handler_obj->address_space.node == acpi_gbl_root_node) { /* Start search from the parent object */ pci_root_node = parent_node; while (pci_root_node != acpi_gbl_root_node) { /* Get the _HID/_CID in order to detect a root_bridge */ if (acpi_ev_is_pci_root_bridge(pci_root_node)) { /* Install a handler for this PCI root bridge */ status = acpi_install_address_space_handler((acpi_handle)pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL); if (ACPI_FAILURE(status)) { if (status == AE_SAME_HANDLER) { /* * It is OK if the handler is already installed on the * root bridge. Still need to return a context object * for the new PCI_Config operation region, however. */ } else { ACPI_EXCEPTION((AE_INFO, status, "Could not install PciConfig handler " "for Root Bridge %4.4s", acpi_ut_get_node_name (pci_root_node))); } } break; } pci_root_node = pci_root_node->parent; } /* PCI root bridge not found, use namespace root node */ } else { pci_root_node = handler_obj->address_space.node; } /* * If this region is now initialized, we are done. * (install_address_space_handler could have initialized it) */ if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { return_ACPI_STATUS(AE_OK); } /* Region is still not initialized. Create a new context */ pci_id = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pci_id)); if (!pci_id) { return_ACPI_STATUS(AE_NO_MEMORY); } /* * For PCI_Config space access, we need the segment, bus, device and * function numbers. Acquire them here. * * Find the parent device object. (This allows the operation region to be * within a subscope under the device, such as a control method.) */ pci_device_node = region_obj->region.node; while (pci_device_node && (pci_device_node->type != ACPI_TYPE_DEVICE)) { pci_device_node = pci_device_node->parent; } if (!pci_device_node) { ACPI_FREE(pci_id); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* * Get the PCI device and function numbers from the _ADR object * contained in the parent's scope. */ status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, pci_device_node, &pci_value); /* * The default is zero, and since the allocation above zeroed the data, * just do nothing on failure. */ if (ACPI_SUCCESS(status)) { pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value)); pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value)); } /* The PCI segment number comes from the _SEG method */ status = acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, pci_root_node, &pci_value); if (ACPI_SUCCESS(status)) { pci_id->segment = ACPI_LOWORD(pci_value); } /* The PCI bus number comes from the _BBN method */ status = acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, pci_root_node, &pci_value); if (ACPI_SUCCESS(status)) { pci_id->bus = ACPI_LOWORD(pci_value); } /* Complete/update the PCI ID for this device */ status = acpi_hw_derive_pci_id(pci_id, pci_root_node, region_obj->region.node); if (ACPI_FAILURE(status)) { ACPI_FREE(pci_id); return_ACPI_STATUS(status); } *region_context = pci_id; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_is_pci_root_bridge * * PARAMETERS: node - Device node being examined * * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge * * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by * examining the _HID and _CID for the device. * ******************************************************************************/ u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node) { acpi_status status; struct acpi_pnp_device_id *hid; struct acpi_pnp_device_id_list *cid; u32 i; u8 match; /* Get the _HID and check for a PCI Root Bridge */ status = acpi_ut_execute_HID(node, &hid); if (ACPI_FAILURE(status)) { return (FALSE); } match = acpi_ut_is_pci_root_bridge(hid->string); ACPI_FREE(hid); if (match) { return (TRUE); } /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */ status = acpi_ut_execute_CID(node, &cid); if (ACPI_FAILURE(status)) { return (FALSE); } /* Check all _CIDs in the returned list */ for (i = 0; i < cid->count; i++) { if (acpi_ut_is_pci_root_bridge(cid->ids[i].string)) { ACPI_FREE(cid); return (TRUE); } } ACPI_FREE(cid); return (FALSE); } /******************************************************************************* * * FUNCTION: acpi_ev_pci_bar_region_setup * * PARAMETERS: handle - Region we are interested in * function - Start or stop * handler_context - Address space handler context * region_context - Region specific context * * RETURN: Status * * DESCRIPTION: Setup a pci_BAR operation region * * MUTEX: Assumes namespace is not locked * ******************************************************************************/ acpi_status acpi_ev_pci_bar_region_setup(acpi_handle handle, u32 function, void *handler_context, void **region_context) { ACPI_FUNCTION_TRACE(ev_pci_bar_region_setup); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_cmos_region_setup * * PARAMETERS: handle - Region we are interested in * function - Start or stop * handler_context - Address space handler context * region_context - Region specific context * * RETURN: Status * * DESCRIPTION: Setup a CMOS operation region * * MUTEX: Assumes namespace is not locked * ******************************************************************************/ acpi_status acpi_ev_cmos_region_setup(acpi_handle handle, u32 function, void *handler_context, void **region_context) { ACPI_FUNCTION_TRACE(ev_cmos_region_setup); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_data_table_region_setup * * PARAMETERS: handle - Region we are interested in * function - Start or stop * handler_context - Address space handler context * region_context - Region specific context * * RETURN: Status * * DESCRIPTION: Setup a data_table_region * * MUTEX: Assumes namespace is not locked * ******************************************************************************/ acpi_status acpi_ev_data_table_region_setup(acpi_handle handle, u32 function, void *handler_context, void **region_context) { union acpi_operand_object *region_desc = (union acpi_operand_object *)handle; struct acpi_data_table_mapping *local_region_context; ACPI_FUNCTION_TRACE(ev_data_table_region_setup); if (function == ACPI_REGION_DEACTIVATE) { if (*region_context) { ACPI_FREE(*region_context); *region_context = NULL; } return_ACPI_STATUS(AE_OK); } /* Create a new context */ local_region_context = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_data_table_mapping)); if (!(local_region_context)) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Save the data table pointer for use in the handler */ local_region_context->pointer = region_desc->region.pointer; *region_context = local_region_context; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_default_region_setup * * PARAMETERS: handle - Region we are interested in * function - Start or stop * handler_context - Address space handler context * region_context - Region specific context * * RETURN: Status * * DESCRIPTION: Default region initialization * ******************************************************************************/ acpi_status acpi_ev_default_region_setup(acpi_handle handle, u32 function, void *handler_context, void **region_context) { ACPI_FUNCTION_TRACE(ev_default_region_setup); if (function == ACPI_REGION_DEACTIVATE) { *region_context = NULL; } else { *region_context = handler_context; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_initialize_region * * PARAMETERS: region_obj - Region we are initializing * * RETURN: Status * * DESCRIPTION: Initializes the region, finds any _REG methods and saves them * for execution at a later time * * Get the appropriate address space handler for a newly * created region. * * This also performs address space specific initialization. For * example, PCI regions must have an _ADR object that contains * a PCI address in the scope of the definition. This address is * required to perform an access to PCI config space. * * MUTEX: Interpreter should be unlocked, because we may run the _REG * method for this region. * * NOTE: Possible incompliance: * There is a behavior conflict in automatic _REG execution: * 1. When the interpreter is evaluating a method, we can only * automatically run _REG for the following case: * operation_region (OPR1, 0x80, 0x1000010, 0x4) * 2. When the interpreter is loading a table, we can also * automatically run _REG for the following case: * operation_region (OPR1, 0x80, 0x1000010, 0x4) * Though this may not be compliant to the de-facto standard, the * logic is kept in order not to trigger regressions. And keeping * this logic should be taken care by the caller of this function. * ******************************************************************************/ acpi_status acpi_ev_initialize_region(union acpi_operand_object *region_obj) { union acpi_operand_object *handler_obj; union acpi_operand_object *obj_desc; acpi_adr_space_type space_id; struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(ev_initialize_region); if (!region_obj) { return_ACPI_STATUS(AE_BAD_PARAMETER); } if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) { return_ACPI_STATUS(AE_OK); } region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED; node = region_obj->region.node->parent; space_id = region_obj->region.space_id; /* * The following loop depends upon the root Node having no parent * ie: acpi_gbl_root_node->Parent being set to NULL */ while (node) { /* Check to see if a handler exists */ handler_obj = NULL; obj_desc = acpi_ns_get_attached_object(node); if (obj_desc) { /* Can only be a handler if the object exists */ switch (node->type) { case ACPI_TYPE_DEVICE: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: handler_obj = obj_desc->common_notify.handler; break; default: /* Ignore other objects */ break; } handler_obj = acpi_ev_find_region_handler(space_id, handler_obj); if (handler_obj) { /* Found correct handler */ ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Found handler %p for region %p in obj %p\n", handler_obj, region_obj, obj_desc)); (void)acpi_ev_attach_region(handler_obj, region_obj, FALSE); /* * Tell all users that this region is usable by * running the _REG method */ acpi_ex_exit_interpreter(); (void)acpi_ev_execute_reg_method(region_obj, ACPI_REG_CONNECT); acpi_ex_enter_interpreter(); return_ACPI_STATUS(AE_OK); } } /* This node does not have the handler we need; Pop up one level */ node = node->parent; } /* * If we get here, there is no handler for this region. This is not * fatal because many regions get created before a handler is installed * for said region. */ ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "No handler for RegionType %s(%X) (RegionObj %p)\n", acpi_ut_get_region_name(space_id), space_id, region_obj)); return_ACPI_STATUS(AE_OK); }
linux-master
drivers/acpi/acpica/evrgnini.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: tbxface - ACPI table-oriented external interfaces * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "actables.h" #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbxface") /******************************************************************************* * * FUNCTION: acpi_allocate_root_table * * PARAMETERS: initial_table_count - Size of initial_table_array, in number of * struct acpi_table_desc structures * * RETURN: Status * * DESCRIPTION: Allocate a root table array. Used by iASL compiler and * acpi_initialize_tables. * ******************************************************************************/ acpi_status acpi_allocate_root_table(u32 initial_table_count) { acpi_gbl_root_table_list.max_table_count = initial_table_count; acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE; return (acpi_tb_resize_root_table_list()); } /******************************************************************************* * * FUNCTION: acpi_initialize_tables * * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated * struct acpi_table_desc structures. If NULL, the * array is dynamically allocated. * initial_table_count - Size of initial_table_array, in number of * struct acpi_table_desc structures * allow_resize - Flag to tell Table Manager if resize of * pre-allocated array is allowed. Ignored * if initial_table_array is NULL. * * RETURN: Status * * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT. * * NOTE: Allows static allocation of the initial table array in order * to avoid the use of dynamic memory in confined environments * such as the kernel boot sequence where it may not be available. * * If the host OS memory managers are initialized, use NULL for * initial_table_array, and the table will be dynamically allocated. * ******************************************************************************/ acpi_status ACPI_INIT_FUNCTION acpi_initialize_tables(struct acpi_table_desc *initial_table_array, u32 initial_table_count, u8 allow_resize) { acpi_physical_address rsdp_address; acpi_status status; ACPI_FUNCTION_TRACE(acpi_initialize_tables); /* * Setup the Root Table Array and allocate the table array * if requested */ if (!initial_table_array) { status = acpi_allocate_root_table(initial_table_count); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } else { /* Root Table Array has been statically allocated by the host */ memset(initial_table_array, 0, (acpi_size)initial_table_count * sizeof(struct acpi_table_desc)); acpi_gbl_root_table_list.tables = initial_table_array; acpi_gbl_root_table_list.max_table_count = initial_table_count; acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN; if (allow_resize) { acpi_gbl_root_table_list.flags |= ACPI_ROOT_ALLOW_RESIZE; } } /* Get the address of the RSDP */ rsdp_address = acpi_os_get_root_pointer(); if (!rsdp_address) { return_ACPI_STATUS(AE_NOT_FOUND); } /* * Get the root table (RSDT or XSDT) and extract all entries to the local * Root Table Array. This array contains the information of the RSDT/XSDT * in a common, more usable format. */ status = acpi_tb_parse_root_table(rsdp_address); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_tables) /******************************************************************************* * * FUNCTION: acpi_reallocate_root_table * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the * root list from the previously provided scratch area. Should * be called once dynamic memory allocation is available in the * kernel. * ******************************************************************************/ acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void) { acpi_status status; struct acpi_table_desc *table_desc; u32 i, j; ACPI_FUNCTION_TRACE(acpi_reallocate_root_table); /* * If there are tables unverified, it is required to reallocate the * root table list to clean up invalid table entries. Otherwise only * reallocate the root table list if the host provided a static buffer * for the table array in the call to acpi_initialize_tables(). */ if ((acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) && acpi_gbl_enable_table_validation) { return_ACPI_STATUS(AE_SUPPORT); } (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); /* * Ensure OS early boot logic, which is required by some hosts. If the * table state is reported to be wrong, developers should fix the * issue by invoking acpi_put_table() for the reported table during the * early stage. */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { table_desc = &acpi_gbl_root_table_list.tables[i]; if (table_desc->pointer) { ACPI_ERROR((AE_INFO, "Table [%4.4s] is not invalidated during early boot stage", table_desc->signature.ascii)); } } if (!acpi_gbl_enable_table_validation) { /* * Now it's safe to do full table validation. We can do deferred * table initialization here once the flag is set. */ acpi_gbl_enable_table_validation = TRUE; for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { table_desc = &acpi_gbl_root_table_list.tables[i]; if (!(table_desc->flags & ACPI_TABLE_IS_VERIFIED)) { status = acpi_tb_verify_temp_table(table_desc, NULL, &j); if (ACPI_FAILURE(status)) { acpi_tb_uninstall_table(table_desc); } } } } acpi_gbl_root_table_list.flags |= ACPI_ROOT_ALLOW_RESIZE; status = acpi_tb_resize_root_table_list(); acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED; (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL_INIT(acpi_reallocate_root_table) /******************************************************************************* * * FUNCTION: acpi_get_table_header * * PARAMETERS: signature - ACPI signature of needed table * instance - Which instance (for SSDTs) * out_table_header - The pointer to the where the table header * is returned * * RETURN: Status and a copy of the table header * * DESCRIPTION: Finds and returns an ACPI table header. Caller provides the * memory where a copy of the header is to be returned * (fixed length). * ******************************************************************************/ acpi_status acpi_get_table_header(char *signature, u32 instance, struct acpi_table_header *out_table_header) { u32 i; u32 j; struct acpi_table_header *header; /* Parameter validation */ if (!signature || !out_table_header) { return (AE_BAD_PARAMETER); } /* Walk the root table list */ for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { if (!ACPI_COMPARE_NAMESEG (&(acpi_gbl_root_table_list.tables[i].signature), signature)) { continue; } if (++j < instance) { continue; } if (!acpi_gbl_root_table_list.tables[i].pointer) { if ((acpi_gbl_root_table_list.tables[i].flags & ACPI_TABLE_ORIGIN_MASK) == ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL) { header = acpi_os_map_memory(acpi_gbl_root_table_list. tables[i].address, sizeof(struct acpi_table_header)); if (!header) { return (AE_NO_MEMORY); } memcpy(out_table_header, header, sizeof(struct acpi_table_header)); acpi_os_unmap_memory(header, sizeof(struct acpi_table_header)); } else { return (AE_NOT_FOUND); } } else { memcpy(out_table_header, acpi_gbl_root_table_list.tables[i].pointer, sizeof(struct acpi_table_header)); } return (AE_OK); } return (AE_NOT_FOUND); } ACPI_EXPORT_SYMBOL(acpi_get_table_header) /******************************************************************************* * * FUNCTION: acpi_get_table * * PARAMETERS: signature - ACPI signature of needed table * instance - Which instance (for SSDTs) * out_table - Where the pointer to the table is returned * * RETURN: Status and pointer to the requested table * * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the * RSDT/XSDT. * Note that an early stage acpi_get_table() call must be paired * with an early stage acpi_put_table() call. otherwise the table * pointer mapped by the early stage mapping implementation may be * erroneously unmapped by the late stage unmapping implementation * in an acpi_put_table() invoked during the late stage. * ******************************************************************************/ acpi_status acpi_get_table(char *signature, u32 instance, struct acpi_table_header ** out_table) { u32 i; u32 j; acpi_status status = AE_NOT_FOUND; struct acpi_table_desc *table_desc; /* Parameter validation */ if (!signature || !out_table) { return (AE_BAD_PARAMETER); } /* * Note that the following line is required by some OSPMs, they only * check if the returned table is NULL instead of the returned status * to determined if this function is succeeded. */ *out_table = NULL; (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); /* Walk the root table list */ for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { table_desc = &acpi_gbl_root_table_list.tables[i]; if (!ACPI_COMPARE_NAMESEG(&table_desc->signature, signature)) { continue; } if (++j < instance) { continue; } status = acpi_tb_get_table(table_desc, out_table); break; } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return (status); } ACPI_EXPORT_SYMBOL(acpi_get_table) /******************************************************************************* * * FUNCTION: acpi_put_table * * PARAMETERS: table - The pointer to the table * * RETURN: None * * DESCRIPTION: Release a table returned by acpi_get_table() and its clones. * Note that it is not safe if this function was invoked after an * uninstallation happened to the original table descriptor. * Currently there is no OSPMs' requirement to handle such * situations. * ******************************************************************************/ void acpi_put_table(struct acpi_table_header *table) { u32 i; struct acpi_table_desc *table_desc; ACPI_FUNCTION_TRACE(acpi_put_table); if (!table) { return_VOID; } (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); /* Walk the root table list */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { table_desc = &acpi_gbl_root_table_list.tables[i]; if (table_desc->pointer != table) { continue; } acpi_tb_put_table(table_desc); break; } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_VOID; } ACPI_EXPORT_SYMBOL(acpi_put_table) /******************************************************************************* * * FUNCTION: acpi_get_table_by_index * * PARAMETERS: table_index - Table index * out_table - Where the pointer to the table is returned * * RETURN: Status and pointer to the requested table * * DESCRIPTION: Obtain a table by an index into the global table list. Used * internally also. * ******************************************************************************/ acpi_status acpi_get_table_by_index(u32 table_index, struct acpi_table_header **out_table) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_get_table_by_index); /* Parameter validation */ if (!out_table) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Note that the following line is required by some OSPMs, they only * check if the returned table is NULL instead of the returned status * to determined if this function is succeeded. */ *out_table = NULL; (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); /* Validate index */ if (table_index >= acpi_gbl_root_table_list.current_table_count) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } status = acpi_tb_get_table(&acpi_gbl_root_table_list.tables[table_index], out_table); unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_get_table_by_index) /******************************************************************************* * * FUNCTION: acpi_install_table_handler * * PARAMETERS: handler - Table event handler * context - Value passed to the handler on each event * * RETURN: Status * * DESCRIPTION: Install a global table event handler. * ******************************************************************************/ acpi_status acpi_install_table_handler(acpi_table_handler handler, void *context) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_install_table_handler); if (!handler) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Don't allow more than one handler */ if (acpi_gbl_table_handler) { status = AE_ALREADY_EXISTS; goto cleanup; } /* Install the handler */ acpi_gbl_table_handler = handler; acpi_gbl_table_handler_context = context; cleanup: (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_install_table_handler) /******************************************************************************* * * FUNCTION: acpi_remove_table_handler * * PARAMETERS: handler - Table event handler that was installed * previously. * * RETURN: Status * * DESCRIPTION: Remove a table event handler * ******************************************************************************/ acpi_status acpi_remove_table_handler(acpi_table_handler handler) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_remove_table_handler); status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Make sure that the installed handler is the same */ if (!handler || handler != acpi_gbl_table_handler) { status = AE_BAD_PARAMETER; goto cleanup; } /* Remove the handler */ acpi_gbl_table_handler = NULL; cleanup: (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_remove_table_handler)
linux-master
drivers/acpi/acpica/tbxface.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: utmisc - common utility procedures * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utmisc") /******************************************************************************* * * FUNCTION: acpi_ut_is_pci_root_bridge * * PARAMETERS: id - The HID/CID in string format * * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge * * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID. * ******************************************************************************/ u8 acpi_ut_is_pci_root_bridge(char *id) { /* * Check if this is a PCI root bridge. * ACPI 3.0+: check for a PCI Express root also. */ if (!(strcmp(id, PCI_ROOT_HID_STRING)) || !(strcmp(id, PCI_EXPRESS_ROOT_HID_STRING))) { return (TRUE); } return (FALSE); } #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_NAMES_APP) /******************************************************************************* * * FUNCTION: acpi_ut_is_aml_table * * PARAMETERS: table - An ACPI table * * RETURN: TRUE if table contains executable AML; FALSE otherwise * * DESCRIPTION: Check ACPI Signature for a table that contains AML code. * Currently, these are DSDT,SSDT,PSDT. All other table types are * data tables that do not contain AML code. * ******************************************************************************/ u8 acpi_ut_is_aml_table(struct acpi_table_header *table) { /* These are the only tables that contain executable AML */ if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_DSDT) || ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_PSDT) || ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_SSDT) || ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_OSDT) || ACPI_IS_OEM_SIG(table->signature)) { return (TRUE); } return (FALSE); } #endif /******************************************************************************* * * FUNCTION: acpi_ut_dword_byte_swap * * PARAMETERS: value - Value to be converted * * RETURN: u32 integer with bytes swapped * * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes) * ******************************************************************************/ u32 acpi_ut_dword_byte_swap(u32 value) { union { u32 value; u8 bytes[4]; } out; union { u32 value; u8 bytes[4]; } in; ACPI_FUNCTION_ENTRY(); in.value = value; out.bytes[0] = in.bytes[3]; out.bytes[1] = in.bytes[2]; out.bytes[2] = in.bytes[1]; out.bytes[3] = in.bytes[0]; return (out.value); } /******************************************************************************* * * FUNCTION: acpi_ut_set_integer_width * * PARAMETERS: Revision From DSDT header * * RETURN: None * * DESCRIPTION: Set the global integer bit width based upon the revision * of the DSDT. For Revision 1 and 0, Integers are 32 bits. * For Revision 2 and above, Integers are 64 bits. Yes, this * makes a difference. * ******************************************************************************/ void acpi_ut_set_integer_width(u8 revision) { if (revision < 2) { /* 32-bit case */ acpi_gbl_integer_bit_width = 32; acpi_gbl_integer_nybble_width = 8; acpi_gbl_integer_byte_width = 4; } else { /* 64-bit case (ACPI 2.0+) */ acpi_gbl_integer_bit_width = 64; acpi_gbl_integer_nybble_width = 16; acpi_gbl_integer_byte_width = 8; } } /******************************************************************************* * * FUNCTION: acpi_ut_create_update_state_and_push * * PARAMETERS: object - Object to be added to the new state * action - Increment/Decrement * state_list - List the state will be added to * * RETURN: Status * * DESCRIPTION: Create a new state and push it * ******************************************************************************/ acpi_status acpi_ut_create_update_state_and_push(union acpi_operand_object *object, u16 action, union acpi_generic_state **state_list) { union acpi_generic_state *state; ACPI_FUNCTION_ENTRY(); /* Ignore null objects; these are expected */ if (!object) { return (AE_OK); } state = acpi_ut_create_update_state(object, action); if (!state) { return (AE_NO_MEMORY); } acpi_ut_push_generic_state(state_list, state); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ut_walk_package_tree * * PARAMETERS: source_object - The package to walk * target_object - Target object (if package is being copied) * walk_callback - Called once for each package element * context - Passed to the callback function * * RETURN: Status * * DESCRIPTION: Walk through a package, including subpackages * ******************************************************************************/ acpi_status acpi_ut_walk_package_tree(union acpi_operand_object *source_object, void *target_object, acpi_pkg_callback walk_callback, void *context) { acpi_status status = AE_OK; union acpi_generic_state *state_list = NULL; union acpi_generic_state *state; union acpi_operand_object *this_source_obj; u32 this_index; ACPI_FUNCTION_TRACE(ut_walk_package_tree); state = acpi_ut_create_pkg_state(source_object, target_object, 0); if (!state) { return_ACPI_STATUS(AE_NO_MEMORY); } while (state) { /* Get one element of the package */ this_index = state->pkg.index; this_source_obj = state->pkg.source_object->package.elements[this_index]; state->pkg.this_target_obj = &state->pkg.source_object->package.elements[this_index]; /* * Check for: * 1) An uninitialized package element. It is completely * legal to declare a package and leave it uninitialized * 2) Not an internal object - can be a namespace node instead * 3) Any type other than a package. Packages are handled in else * case below. */ if ((!this_source_obj) || (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) != ACPI_DESC_TYPE_OPERAND) || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) { status = walk_callback(ACPI_COPY_TYPE_SIMPLE, this_source_obj, state, context); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } state->pkg.index++; while (state->pkg.index >= state->pkg.source_object->package.count) { /* * We've handled all of the objects at this level, This means * that we have just completed a package. That package may * have contained one or more packages itself. * * Delete this state and pop the previous state (package). */ acpi_ut_delete_generic_state(state); state = acpi_ut_pop_generic_state(&state_list); /* Finished when there are no more states */ if (!state) { /* * We have handled all of the objects in the top level * package just add the length of the package objects * and exit */ return_ACPI_STATUS(AE_OK); } /* * Go back up a level and move the index past the just * completed package object. */ state->pkg.index++; } } else { /* This is a subobject of type package */ status = walk_callback(ACPI_COPY_TYPE_PACKAGE, this_source_obj, state, context); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Push the current state and create a new one * The callback above returned a new target package object. */ acpi_ut_push_generic_state(&state_list, state); state = acpi_ut_create_pkg_state(this_source_obj, state->pkg.this_target_obj, 0); if (!state) { /* Free any stacked Update State objects */ while (state_list) { state = acpi_ut_pop_generic_state (&state_list); acpi_ut_delete_generic_state(state); } return_ACPI_STATUS(AE_NO_MEMORY); } } } /* We should never get here */ ACPI_ERROR((AE_INFO, "State list did not terminate correctly")); return_ACPI_STATUS(AE_AML_INTERNAL); } #ifdef ACPI_DEBUG_OUTPUT /******************************************************************************* * * FUNCTION: acpi_ut_display_init_pathname * * PARAMETERS: type - Object type of the node * obj_handle - Handle whose pathname will be displayed * path - Additional path string to be appended. * (NULL if no extra path) * * RETURN: acpi_status * * DESCRIPTION: Display full pathname of an object, DEBUG ONLY * ******************************************************************************/ void acpi_ut_display_init_pathname(u8 type, struct acpi_namespace_node *obj_handle, const char *path) { acpi_status status; struct acpi_buffer buffer; ACPI_FUNCTION_ENTRY(); /* Only print the path if the appropriate debug level is enabled */ if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { return; } /* Get the full pathname to the node */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE); if (ACPI_FAILURE(status)) { return; } /* Print what we're doing */ switch (type) { case ACPI_TYPE_METHOD: acpi_os_printf("Executing "); break; default: acpi_os_printf("Initializing "); break; } /* Print the object type and pathname */ acpi_os_printf("%-12s %s", acpi_ut_get_type_name(type), (char *)buffer.pointer); /* Extra path is used to append names like _STA, _INI, etc. */ if (path) { acpi_os_printf(".%s", path); } acpi_os_printf("\n"); ACPI_FREE(buffer.pointer); } #endif
linux-master
drivers/acpi/acpica/utmisc.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: nseval - Object evaluation, includes control method execution * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "acinterp.h" #include "acnamesp.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nseval") /******************************************************************************* * * FUNCTION: acpi_ns_evaluate * * PARAMETERS: info - Evaluation info block, contains these fields * and more: * prefix_node - Prefix or Method/Object Node to execute * relative_path - Name of method to execute, If NULL, the * Node is the object to execute * parameters - List of parameters to pass to the method, * terminated by NULL. Params itself may be * NULL if no parameters are being passed. * parameter_type - Type of Parameter list * return_object - Where to put method's return value (if * any). If NULL, no value is returned. * flags - ACPI_IGNORE_RETURN_VALUE to delete return * * RETURN: Status * * DESCRIPTION: Execute a control method or return the current value of an * ACPI namespace object. * * MUTEX: Locks interpreter * ******************************************************************************/ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info) { acpi_status status; ACPI_FUNCTION_TRACE(ns_evaluate); if (!info) { return_ACPI_STATUS(AE_BAD_PARAMETER); } if (!info->node) { /* * Get the actual namespace node for the target object if we * need to. Handles these cases: * * 1) Null node, valid pathname from root (absolute path) * 2) Node and valid pathname (path relative to Node) * 3) Node, Null pathname */ status = acpi_ns_get_node(info->prefix_node, info->relative_pathname, ACPI_NS_NO_UPSEARCH, &info->node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } /* * For a method alias, we must grab the actual method node so that * proper scoping context will be established before execution. */ if (acpi_ns_get_type(info->node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) { info->node = ACPI_CAST_PTR(struct acpi_namespace_node, info->node->object); } /* Complete the info block initialization */ info->return_object = NULL; info->node_flags = info->node->flags; info->obj_desc = acpi_ns_get_attached_object(info->node); ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n", info->relative_pathname, info->node, acpi_ns_get_attached_object(info->node))); /* Get info if we have a predefined name (_HID, etc.) */ info->predefined = acpi_ut_match_predefined_method(info->node->name.ascii); /* Get the full pathname to the object, for use in warning messages */ info->full_pathname = acpi_ns_get_normalized_pathname(info->node, TRUE); if (!info->full_pathname) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Optional object evaluation log */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_EVALUATION, "%-26s: %s (%s)\n", " Enter evaluation", &info->full_pathname[1], acpi_ut_get_type_name(info->node->type))); /* Count the number of arguments being passed in */ info->param_count = 0; if (info->parameters) { while (info->parameters[info->param_count]) { info->param_count++; } /* Warn on impossible argument count */ if (info->param_count > ACPI_METHOD_NUM_ARGS) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, ACPI_WARN_ALWAYS, "Excess arguments (%u) - using only %u", info->param_count, ACPI_METHOD_NUM_ARGS)); info->param_count = ACPI_METHOD_NUM_ARGS; } } /* * For predefined names: Check that the declared argument count * matches the ACPI spec -- otherwise this is a BIOS error. */ acpi_ns_check_acpi_compliance(info->full_pathname, info->node, info->predefined); /* * For all names: Check that the incoming argument count for * this method/object matches the actual ASL/AML definition. */ acpi_ns_check_argument_count(info->full_pathname, info->node, info->param_count, info->predefined); /* For predefined names: Typecheck all incoming arguments */ acpi_ns_check_argument_types(info); /* * Three major evaluation cases: * * 1) Object types that cannot be evaluated by definition * 2) The object is a control method -- execute it * 3) The object is not a method -- just return it's current value */ switch (acpi_ns_get_type(info->node)) { case ACPI_TYPE_ANY: case ACPI_TYPE_DEVICE: case ACPI_TYPE_EVENT: case ACPI_TYPE_MUTEX: case ACPI_TYPE_REGION: case ACPI_TYPE_THERMAL: case ACPI_TYPE_LOCAL_SCOPE: /* * 1) Disallow evaluation of these object types. For these, * object evaluation is undefined. */ ACPI_ERROR((AE_INFO, "%s: This object type [%s] " "never contains data and cannot be evaluated", info->full_pathname, acpi_ut_get_type_name(info->node->type))); status = AE_TYPE; goto cleanup; case ACPI_TYPE_METHOD: /* * 2) Object is a control method - execute it */ /* Verify that there is a method object associated with this node */ if (!info->obj_desc) { ACPI_ERROR((AE_INFO, "%s: Method has no attached sub-object", info->full_pathname)); status = AE_NULL_OBJECT; goto cleanup; } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "**** Execute method [%s] at AML address %p length %X\n", info->full_pathname, info->obj_desc->method.aml_start + 1, info->obj_desc->method.aml_length - 1)); /* * Any namespace deletion must acquire both the namespace and * interpreter locks to ensure that no thread is using the portion of * the namespace that is being deleted. * * Execute the method via the interpreter. The interpreter is locked * here before calling into the AML parser */ acpi_ex_enter_interpreter(); status = acpi_ps_execute_method(info); acpi_ex_exit_interpreter(); break; default: /* * 3) All other non-method objects -- get the current object value */ /* * Some objects require additional resolution steps (e.g., the Node * may be a field that must be read, etc.) -- we can't just grab * the object out of the node. * * Use resolve_node_to_value() to get the associated value. * * NOTE: we can get away with passing in NULL for a walk state because * the Node is guaranteed to not be a reference to either a method * local or a method argument (because this interface is never called * from a running method.) * * Even though we do not directly invoke the interpreter for object * resolution, we must lock it because we could access an op_region. * The op_region access code assumes that the interpreter is locked. */ acpi_ex_enter_interpreter(); /* TBD: resolve_node_to_value has a strange interface, fix */ info->return_object = ACPI_CAST_PTR(union acpi_operand_object, info->node); status = acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR (struct acpi_namespace_node, &info->return_object), NULL); acpi_ex_exit_interpreter(); if (ACPI_FAILURE(status)) { info->return_object = NULL; goto cleanup; } ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Returned object %p [%s]\n", info->return_object, acpi_ut_get_object_type_name(info-> return_object))); status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */ break; } /* * For predefined names, check the return value against the ACPI * specification. Some incorrect return value types are repaired. */ (void)acpi_ns_check_return_value(info->node, info, info->param_count, status, &info->return_object); /* Check if there is a return value that must be dealt with */ if (status == AE_CTRL_RETURN_VALUE) { /* If caller does not want the return value, delete it */ if (info->flags & ACPI_IGNORE_RETURN_VALUE) { acpi_ut_remove_reference(info->return_object); info->return_object = NULL; } /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */ status = AE_OK; } else if (ACPI_FAILURE(status)) { /* If return_object exists, delete it */ if (info->return_object) { acpi_ut_remove_reference(info->return_object); info->return_object = NULL; } } ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "*** Completed evaluation of object %s ***\n", info->relative_pathname)); cleanup: /* Optional object evaluation log */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_EVALUATION, "%-26s: %s\n", " Exit evaluation", &info->full_pathname[1])); /* * Namespace was unlocked by the handling acpi_ns* function, so we * just free the pathname and return */ ACPI_FREE(info->full_pathname); info->full_pathname = NULL; return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/nseval.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: rsutils - Utilities for the resource manager * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acresrc.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rsutils") /******************************************************************************* * * FUNCTION: acpi_rs_decode_bitmask * * PARAMETERS: mask - Bitmask to decode * list - Where the converted list is returned * * RETURN: Count of bits set (length of list) * * DESCRIPTION: Convert a bit mask into a list of values * ******************************************************************************/ u8 acpi_rs_decode_bitmask(u16 mask, u8 * list) { u8 i; u8 bit_count; ACPI_FUNCTION_ENTRY(); /* Decode the mask bits */ for (i = 0, bit_count = 0; mask; i++) { if (mask & 0x0001) { list[bit_count] = i; bit_count++; } mask >>= 1; } return (bit_count); } /******************************************************************************* * * FUNCTION: acpi_rs_encode_bitmask * * PARAMETERS: list - List of values to encode * count - Length of list * * RETURN: Encoded bitmask * * DESCRIPTION: Convert a list of values to an encoded bitmask * ******************************************************************************/ u16 acpi_rs_encode_bitmask(u8 * list, u8 count) { u32 i; u16 mask; ACPI_FUNCTION_ENTRY(); /* Encode the list into a single bitmask */ for (i = 0, mask = 0; i < count; i++) { mask |= (0x1 << list[i]); } return (mask); } /******************************************************************************* * * FUNCTION: acpi_rs_move_data * * PARAMETERS: destination - Pointer to the destination descriptor * source - Pointer to the source descriptor * item_count - How many items to move * move_type - Byte width * * RETURN: None * * DESCRIPTION: Move multiple data items from one descriptor to another. Handles * alignment issues and endian issues if necessary, as configured * via the ACPI_MOVE_* macros. (This is why a memcpy is not used) * ******************************************************************************/ void acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type) { u32 i; ACPI_FUNCTION_ENTRY(); /* One move per item */ for (i = 0; i < item_count; i++) { switch (move_type) { /* * For the 8-bit case, we can perform the move all at once * since there are no alignment or endian issues */ case ACPI_RSC_MOVE8: case ACPI_RSC_MOVE_GPIO_RES: case ACPI_RSC_MOVE_SERIAL_VEN: case ACPI_RSC_MOVE_SERIAL_RES: memcpy(destination, source, item_count); return; /* * 16-, 32-, and 64-bit cases must use the move macros that perform * endian conversion and/or accommodate hardware that cannot perform * misaligned memory transfers */ case ACPI_RSC_MOVE16: case ACPI_RSC_MOVE_GPIO_PIN: ACPI_MOVE_16_TO_16(&ACPI_CAST_PTR(u16, destination)[i], &ACPI_CAST_PTR(u16, source)[i]); break; case ACPI_RSC_MOVE32: ACPI_MOVE_32_TO_32(&ACPI_CAST_PTR(u32, destination)[i], &ACPI_CAST_PTR(u32, source)[i]); break; case ACPI_RSC_MOVE64: ACPI_MOVE_64_TO_64(&ACPI_CAST_PTR(u64, destination)[i], &ACPI_CAST_PTR(u64, source)[i]); break; default: return; } } } /******************************************************************************* * * FUNCTION: acpi_rs_set_resource_length * * PARAMETERS: total_length - Length of the AML descriptor, including * the header and length fields. * aml - Pointer to the raw AML descriptor * * RETURN: None * * DESCRIPTION: Set the resource_length field of an AML * resource descriptor, both Large and Small descriptors are * supported automatically. Note: Descriptor Type field must * be valid. * ******************************************************************************/ void acpi_rs_set_resource_length(acpi_rsdesc_size total_length, union aml_resource *aml) { acpi_rs_length resource_length; ACPI_FUNCTION_ENTRY(); /* Length is the total descriptor length minus the header length */ resource_length = (acpi_rs_length) (total_length - acpi_ut_get_resource_header_length(aml)); /* Length is stored differently for large and small descriptors */ if (aml->small_header.descriptor_type & ACPI_RESOURCE_NAME_LARGE) { /* Large descriptor -- bytes 1-2 contain the 16-bit length */ ACPI_MOVE_16_TO_16(&aml->large_header.resource_length, &resource_length); } else { /* * Small descriptor -- bits 2:0 of byte 0 contain the length * Clear any existing length, preserving descriptor type bits */ aml->small_header.descriptor_type = (u8) ((aml->small_header.descriptor_type & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK) | resource_length); } } /******************************************************************************* * * FUNCTION: acpi_rs_set_resource_header * * PARAMETERS: descriptor_type - Byte to be inserted as the type * total_length - Length of the AML descriptor, including * the header and length fields. * aml - Pointer to the raw AML descriptor * * RETURN: None * * DESCRIPTION: Set the descriptor_type and resource_length fields of an AML * resource descriptor, both Large and Small descriptors are * supported automatically * ******************************************************************************/ void acpi_rs_set_resource_header(u8 descriptor_type, acpi_rsdesc_size total_length, union aml_resource *aml) { ACPI_FUNCTION_ENTRY(); /* Set the Resource Type */ aml->small_header.descriptor_type = descriptor_type; /* Set the Resource Length */ acpi_rs_set_resource_length(total_length, aml); } /******************************************************************************* * * FUNCTION: acpi_rs_strcpy * * PARAMETERS: destination - Pointer to the destination string * source - Pointer to the source string * * RETURN: String length, including NULL terminator * * DESCRIPTION: Local string copy that returns the string length, saving a * strcpy followed by a strlen. * ******************************************************************************/ static u16 acpi_rs_strcpy(char *destination, char *source) { u16 i; ACPI_FUNCTION_ENTRY(); for (i = 0; source[i]; i++) { destination[i] = source[i]; } destination[i] = 0; /* Return string length including the NULL terminator */ return ((u16) (i + 1)); } /******************************************************************************* * * FUNCTION: acpi_rs_get_resource_source * * PARAMETERS: resource_length - Length field of the descriptor * minimum_length - Minimum length of the descriptor (minus * any optional fields) * resource_source - Where the resource_source is returned * aml - Pointer to the raw AML descriptor * string_ptr - (optional) where to store the actual * resource_source string * * RETURN: Length of the string plus NULL terminator, rounded up to native * word boundary * * DESCRIPTION: Copy the optional resource_source data from a raw AML descriptor * to an internal resource descriptor * ******************************************************************************/ acpi_rs_length acpi_rs_get_resource_source(acpi_rs_length resource_length, acpi_rs_length minimum_length, struct acpi_resource_source * resource_source, union aml_resource * aml, char *string_ptr) { acpi_rsdesc_size total_length; u8 *aml_resource_source; ACPI_FUNCTION_ENTRY(); total_length = resource_length + sizeof(struct aml_resource_large_header); aml_resource_source = ACPI_ADD_PTR(u8, aml, minimum_length); /* * resource_source is present if the length of the descriptor is longer * than the minimum length. * * Note: Some resource descriptors will have an additional null, so * we add 1 to the minimum length. */ if (total_length > (acpi_rsdesc_size)(minimum_length + 1)) { /* Get the resource_source_index */ resource_source->index = aml_resource_source[0]; resource_source->string_ptr = string_ptr; if (!string_ptr) { /* * String destination pointer is not specified; Set the String * pointer to the end of the current resource_source structure. */ resource_source->string_ptr = ACPI_ADD_PTR(char, resource_source, sizeof(struct acpi_resource_source)); } /* * In order for the Resource length to be a multiple of the native * word, calculate the length of the string (+1 for NULL terminator) * and expand to the next word multiple. * * Zero the entire area of the buffer. */ total_length = (u32)strlen(ACPI_CAST_PTR(char, &aml_resource_source[1])) + 1; total_length = (u32)ACPI_ROUND_UP_TO_NATIVE_WORD(total_length); memset(resource_source->string_ptr, 0, total_length); /* Copy the resource_source string to the destination */ resource_source->string_length = acpi_rs_strcpy(resource_source->string_ptr, ACPI_CAST_PTR(char, &aml_resource_source[1])); return ((acpi_rs_length)total_length); } /* resource_source is not present */ resource_source->index = 0; resource_source->string_length = 0; resource_source->string_ptr = NULL; return (0); } /******************************************************************************* * * FUNCTION: acpi_rs_set_resource_source * * PARAMETERS: aml - Pointer to the raw AML descriptor * minimum_length - Minimum length of the descriptor (minus * any optional fields) * resource_source - Internal resource_source * * RETURN: Total length of the AML descriptor * * DESCRIPTION: Convert an optional resource_source from internal format to a * raw AML resource descriptor * ******************************************************************************/ acpi_rsdesc_size acpi_rs_set_resource_source(union aml_resource *aml, acpi_rs_length minimum_length, struct acpi_resource_source *resource_source) { u8 *aml_resource_source; acpi_rsdesc_size descriptor_length; ACPI_FUNCTION_ENTRY(); descriptor_length = minimum_length; /* Non-zero string length indicates presence of a resource_source */ if (resource_source->string_length) { /* Point to the end of the AML descriptor */ aml_resource_source = ACPI_ADD_PTR(u8, aml, minimum_length); /* Copy the resource_source_index */ aml_resource_source[0] = (u8) resource_source->index; /* Copy the resource_source string */ strcpy(ACPI_CAST_PTR(char, &aml_resource_source[1]), resource_source->string_ptr); /* * Add the length of the string (+ 1 for null terminator) to the * final descriptor length */ descriptor_length += ((acpi_rsdesc_size) resource_source->string_length + 1); } /* Return the new total length of the AML descriptor */ return (descriptor_length); } /******************************************************************************* * * FUNCTION: acpi_rs_get_prt_method_data * * PARAMETERS: node - Device node * ret_buffer - Pointer to a buffer structure for the * results * * RETURN: Status * * DESCRIPTION: This function is called to get the _PRT value of an object * contained in an object specified by the handle passed in * * If the function fails an appropriate status will be returned * and the contents of the callers buffer is undefined. * ******************************************************************************/ acpi_status acpi_rs_get_prt_method_data(struct acpi_namespace_node *node, struct acpi_buffer *ret_buffer) { union acpi_operand_object *obj_desc; acpi_status status; ACPI_FUNCTION_TRACE(rs_get_prt_method_data); /* Parameters guaranteed valid by caller */ /* Execute the method, no parameters */ status = acpi_ut_evaluate_object(node, METHOD_NAME__PRT, ACPI_BTYPE_PACKAGE, &obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Create a resource linked list from the byte stream buffer that comes * back from the _CRS method execution. */ status = acpi_rs_create_pci_routing_table(obj_desc, ret_buffer); /* On exit, we must delete the object returned by evaluate_object */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_rs_get_crs_method_data * * PARAMETERS: node - Device node * ret_buffer - Pointer to a buffer structure for the * results * * RETURN: Status * * DESCRIPTION: This function is called to get the _CRS value of an object * contained in an object specified by the handle passed in * * If the function fails an appropriate status will be returned * and the contents of the callers buffer is undefined. * ******************************************************************************/ acpi_status acpi_rs_get_crs_method_data(struct acpi_namespace_node *node, struct acpi_buffer *ret_buffer) { union acpi_operand_object *obj_desc; acpi_status status; ACPI_FUNCTION_TRACE(rs_get_crs_method_data); /* Parameters guaranteed valid by caller */ /* Execute the method, no parameters */ status = acpi_ut_evaluate_object(node, METHOD_NAME__CRS, ACPI_BTYPE_BUFFER, &obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Make the call to create a resource linked list from the * byte stream buffer that comes back from the _CRS method * execution. */ status = acpi_rs_create_resource_list(obj_desc, ret_buffer); /* On exit, we must delete the object returned by evaluateObject */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_rs_get_prs_method_data * * PARAMETERS: node - Device node * ret_buffer - Pointer to a buffer structure for the * results * * RETURN: Status * * DESCRIPTION: This function is called to get the _PRS value of an object * contained in an object specified by the handle passed in * * If the function fails an appropriate status will be returned * and the contents of the callers buffer is undefined. * ******************************************************************************/ acpi_status acpi_rs_get_prs_method_data(struct acpi_namespace_node *node, struct acpi_buffer *ret_buffer) { union acpi_operand_object *obj_desc; acpi_status status; ACPI_FUNCTION_TRACE(rs_get_prs_method_data); /* Parameters guaranteed valid by caller */ /* Execute the method, no parameters */ status = acpi_ut_evaluate_object(node, METHOD_NAME__PRS, ACPI_BTYPE_BUFFER, &obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Make the call to create a resource linked list from the * byte stream buffer that comes back from the _CRS method * execution. */ status = acpi_rs_create_resource_list(obj_desc, ret_buffer); /* On exit, we must delete the object returned by evaluateObject */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_rs_get_aei_method_data * * PARAMETERS: node - Device node * ret_buffer - Pointer to a buffer structure for the * results * * RETURN: Status * * DESCRIPTION: This function is called to get the _AEI value of an object * contained in an object specified by the handle passed in * * If the function fails an appropriate status will be returned * and the contents of the callers buffer is undefined. * ******************************************************************************/ acpi_status acpi_rs_get_aei_method_data(struct acpi_namespace_node *node, struct acpi_buffer *ret_buffer) { union acpi_operand_object *obj_desc; acpi_status status; ACPI_FUNCTION_TRACE(rs_get_aei_method_data); /* Parameters guaranteed valid by caller */ /* Execute the method, no parameters */ status = acpi_ut_evaluate_object(node, METHOD_NAME__AEI, ACPI_BTYPE_BUFFER, &obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Make the call to create a resource linked list from the * byte stream buffer that comes back from the _CRS method * execution. */ status = acpi_rs_create_resource_list(obj_desc, ret_buffer); /* On exit, we must delete the object returned by evaluateObject */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_rs_get_method_data * * PARAMETERS: handle - Handle to the containing object * path - Path to method, relative to Handle * ret_buffer - Pointer to a buffer structure for the * results * * RETURN: Status * * DESCRIPTION: This function is called to get the _CRS or _PRS value of an * object contained in an object specified by the handle passed in * * If the function fails an appropriate status will be returned * and the contents of the callers buffer is undefined. * ******************************************************************************/ acpi_status acpi_rs_get_method_data(acpi_handle handle, const char *path, struct acpi_buffer *ret_buffer) { union acpi_operand_object *obj_desc; acpi_status status; ACPI_FUNCTION_TRACE(rs_get_method_data); /* Parameters guaranteed valid by caller */ /* Execute the method, no parameters */ status = acpi_ut_evaluate_object(ACPI_CAST_PTR (struct acpi_namespace_node, handle), path, ACPI_BTYPE_BUFFER, &obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Make the call to create a resource linked list from the * byte stream buffer that comes back from the method * execution. */ status = acpi_rs_create_resource_list(obj_desc, ret_buffer); /* On exit, we must delete the object returned by evaluate_object */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_rs_set_srs_method_data * * PARAMETERS: node - Device node * in_buffer - Pointer to a buffer structure of the * parameter * * RETURN: Status * * DESCRIPTION: This function is called to set the _SRS of an object contained * in an object specified by the handle passed in * * If the function fails an appropriate status will be returned * and the contents of the callers buffer is undefined. * * Note: Parameters guaranteed valid by caller * ******************************************************************************/ acpi_status acpi_rs_set_srs_method_data(struct acpi_namespace_node *node, struct acpi_buffer *in_buffer) { struct acpi_evaluate_info *info; union acpi_operand_object *args[2]; acpi_status status; struct acpi_buffer buffer; ACPI_FUNCTION_TRACE(rs_set_srs_method_data); /* Allocate and initialize the evaluation information block */ info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); if (!info) { return_ACPI_STATUS(AE_NO_MEMORY); } info->prefix_node = node; info->relative_pathname = METHOD_NAME__SRS; info->parameters = args; info->flags = ACPI_IGNORE_RETURN_VALUE; /* * The in_buffer parameter will point to a linked list of * resource parameters. It needs to be formatted into a * byte stream to be sent in as an input parameter to _SRS * * Convert the linked list into a byte stream */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_rs_create_aml_resources(in_buffer, &buffer); if (ACPI_FAILURE(status)) { goto cleanup; } /* Create and initialize the method parameter object */ args[0] = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER); if (!args[0]) { /* * Must free the buffer allocated above (otherwise it is freed * later) */ ACPI_FREE(buffer.pointer); status = AE_NO_MEMORY; goto cleanup; } args[0]->buffer.length = (u32) buffer.length; args[0]->buffer.pointer = buffer.pointer; args[0]->common.flags = AOPOBJ_DATA_VALID; args[1] = NULL; /* Execute the method, no return value is expected */ status = acpi_ns_evaluate(info); /* Clean up and return the status from acpi_ns_evaluate */ acpi_ut_remove_reference(args[0]); cleanup: ACPI_FREE(info); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/rsutils.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: utxfmutex - external AML mutex access functions * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utxfmutex") /* Local prototypes */ static acpi_status acpi_ut_get_mutex_object(acpi_handle handle, acpi_string pathname, union acpi_operand_object **ret_obj); /******************************************************************************* * * FUNCTION: acpi_ut_get_mutex_object * * PARAMETERS: handle - Mutex or prefix handle (optional) * pathname - Mutex pathname (optional) * ret_obj - Where the mutex object is returned * * RETURN: Status * * DESCRIPTION: Get an AML mutex object. The mutex node is pointed to by * Handle:Pathname. Either Handle or Pathname can be NULL, but * not both. * ******************************************************************************/ static acpi_status acpi_ut_get_mutex_object(acpi_handle handle, acpi_string pathname, union acpi_operand_object **ret_obj) { struct acpi_namespace_node *mutex_node; union acpi_operand_object *mutex_obj; acpi_status status; /* Parameter validation */ if (!ret_obj || (!handle && !pathname)) { return (AE_BAD_PARAMETER); } /* Get a the namespace node for the mutex */ mutex_node = handle; if (pathname != NULL) { status = acpi_get_handle(handle, pathname, ACPI_CAST_PTR(acpi_handle, &mutex_node)); if (ACPI_FAILURE(status)) { return (status); } } /* Ensure that we actually have a Mutex object */ if (!mutex_node || (mutex_node->type != ACPI_TYPE_MUTEX)) { return (AE_TYPE); } /* Get the low-level mutex object */ mutex_obj = acpi_ns_get_attached_object(mutex_node); if (!mutex_obj) { return (AE_NULL_OBJECT); } *ret_obj = mutex_obj; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_acquire_mutex * * PARAMETERS: handle - Mutex or prefix handle (optional) * pathname - Mutex pathname (optional) * timeout - Max time to wait for the lock (millisec) * * RETURN: Status * * DESCRIPTION: Acquire an AML mutex. This is a device driver interface to * AML mutex objects, and allows for transaction locking between * drivers and AML code. The mutex node is pointed to by * Handle:Pathname. Either Handle or Pathname can be NULL, but * not both. * ******************************************************************************/ acpi_status acpi_acquire_mutex(acpi_handle handle, acpi_string pathname, u16 timeout) { acpi_status status; union acpi_operand_object *mutex_obj; /* Get the low-level mutex associated with Handle:Pathname */ status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj); if (ACPI_FAILURE(status)) { return (status); } /* Acquire the OS mutex */ status = acpi_os_acquire_mutex(mutex_obj->mutex.os_mutex, timeout); return (status); } ACPI_EXPORT_SYMBOL(acpi_acquire_mutex) /******************************************************************************* * * FUNCTION: acpi_release_mutex * * PARAMETERS: handle - Mutex or prefix handle (optional) * pathname - Mutex pathname (optional) * * RETURN: Status * * DESCRIPTION: Release an AML mutex. This is a device driver interface to * AML mutex objects, and allows for transaction locking between * drivers and AML code. The mutex node is pointed to by * Handle:Pathname. Either Handle or Pathname can be NULL, but * not both. * ******************************************************************************/ acpi_status acpi_release_mutex(acpi_handle handle, acpi_string pathname) { acpi_status status; union acpi_operand_object *mutex_obj; /* Get the low-level mutex associated with Handle:Pathname */ status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj); if (ACPI_FAILURE(status)) { return (status); } /* Release the OS mutex */ acpi_os_release_mutex(mutex_obj->mutex.os_mutex); return (AE_OK); } ACPI_EXPORT_SYMBOL(acpi_release_mutex)
linux-master
drivers/acpi/acpica/utxfmutex.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exoparg3 - AML execution - opcodes with 3 arguments * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #include "acparser.h" #include "amlcode.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exoparg3") /*! * Naming convention for AML interpreter execution routines. * * The routines that begin execution of AML opcodes are named with a common * convention based upon the number of arguments, the number of target operands, * and whether or not a value is returned: * * AcpiExOpcode_xA_yT_zR * * Where: * * xA - ARGUMENTS: The number of arguments (input operands) that are * required for this opcode type (1 through 6 args). * yT - TARGETS: The number of targets (output operands) that are required * for this opcode type (0, 1, or 2 targets). * zR - RETURN VALUE: Indicates whether this opcode type returns a value * as the function return (0 or 1). * * The AcpiExOpcode* functions are called via the Dispatcher component with * fully resolved operands. !*/ /******************************************************************************* * * FUNCTION: acpi_ex_opcode_3A_0T_0R * * PARAMETERS: walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Execute Triadic operator (3 operands) * ******************************************************************************/ acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; struct acpi_signal_fatal_info *fatal; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R, acpi_ps_get_opcode_name(walk_state->opcode)); switch (walk_state->opcode) { case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, "FatalOp: Type %X Code %X Arg %X " "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", (u32)operand[0]->integer.value, (u32)operand[1]->integer.value, (u32)operand[2]->integer.value)); fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info)); if (fatal) { fatal->type = (u32) operand[0]->integer.value; fatal->code = (u32) operand[1]->integer.value; fatal->argument = (u32) operand[2]->integer.value; } /* Always signal the OS! */ status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal); /* Might return while OS is shutting down, just continue */ ACPI_FREE(fatal); goto cleanup; case AML_EXTERNAL_OP: /* * If the interpreter sees this opcode, just ignore it. The External * op is intended for use by disassemblers in order to properly * disassemble control method invocations. The opcode or group of * opcodes should be surrounded by an "if (0)" clause to ensure that * AML interpreters never see the opcode. Thus, something is * wrong if an external opcode ever gets here. */ ACPI_ERROR((AE_INFO, "Executed External Op")); status = AE_OK; goto cleanup; default: ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", walk_state->opcode)); status = AE_AML_BAD_OPCODE; goto cleanup; } cleanup: return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_opcode_3A_1T_1R * * PARAMETERS: walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Execute Triadic operator (3 operands) * ******************************************************************************/ acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; union acpi_operand_object *return_desc = NULL; char *buffer = NULL; acpi_status status = AE_OK; u64 index; acpi_size length; ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R, acpi_ps_get_opcode_name(walk_state->opcode)); switch (walk_state->opcode) { case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */ /* * Create the return object. The Source operand is guaranteed to be * either a String or a Buffer, so just use its type. */ return_desc = acpi_ut_create_internal_object((operand[0])-> common.type); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } /* Get the Integer values from the objects */ index = operand[1]->integer.value; length = (acpi_size)operand[2]->integer.value; /* * If the index is beyond the length of the String/Buffer, or if the * requested length is zero, return a zero-length String/Buffer */ if (index >= operand[0]->string.length) { length = 0; } /* Truncate request if larger than the actual String/Buffer */ else if ((index + length) > operand[0]->string.length) { length = (acpi_size)operand[0]->string.length - (acpi_size)index; } /* Strings always have a sub-pointer, not so for buffers */ switch ((operand[0])->common.type) { case ACPI_TYPE_STRING: /* Always allocate a new buffer for the String */ buffer = ACPI_ALLOCATE_ZEROED((acpi_size)length + 1); if (!buffer) { status = AE_NO_MEMORY; goto cleanup; } break; case ACPI_TYPE_BUFFER: /* If the requested length is zero, don't allocate a buffer */ if (length > 0) { /* Allocate a new buffer for the Buffer */ buffer = ACPI_ALLOCATE_ZEROED(length); if (!buffer) { status = AE_NO_MEMORY; goto cleanup; } } break; default: /* Should not happen */ status = AE_AML_OPERAND_TYPE; goto cleanup; } if (buffer) { /* We have a buffer, copy the portion requested */ memcpy(buffer, operand[0]->string.pointer + index, length); } /* Set the length of the new String/Buffer */ return_desc->string.pointer = buffer; return_desc->string.length = (u32) length; /* Mark buffer initialized */ return_desc->buffer.flags |= AOPOBJ_DATA_VALID; break; default: ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", walk_state->opcode)); status = AE_AML_BAD_OPCODE; goto cleanup; } /* Store the result in the target */ status = acpi_ex_store(return_desc, operand[3], walk_state); cleanup: /* Delete return object on error */ if (ACPI_FAILURE(status) || walk_state->result_obj) { acpi_ut_remove_reference(return_desc); walk_state->result_obj = NULL; } else { /* Set the return object and exit */ walk_state->result_obj = return_desc; } return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exoparg3.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dbhistry - debugger HISTORY command * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdebug.h" #define _COMPONENT ACPI_CA_DEBUGGER ACPI_MODULE_NAME("dbhistry") #define HI_NO_HISTORY 0 #define HI_RECORD_HISTORY 1 #define HISTORY_SIZE 40 typedef struct history_info { char *command; u32 cmd_num; } HISTORY_INFO; static HISTORY_INFO acpi_gbl_history_buffer[HISTORY_SIZE]; static u16 acpi_gbl_lo_history = 0; static u16 acpi_gbl_num_history = 0; static u16 acpi_gbl_next_history_index = 0; /******************************************************************************* * * FUNCTION: acpi_db_add_to_history * * PARAMETERS: command_line - Command to add * * RETURN: None * * DESCRIPTION: Add a command line to the history buffer. * ******************************************************************************/ void acpi_db_add_to_history(char *command_line) { u16 cmd_len; u16 buffer_len; /* Put command into the next available slot */ cmd_len = (u16)strlen(command_line); if (!cmd_len) { return; } if (acpi_gbl_history_buffer[acpi_gbl_next_history_index].command != NULL) { buffer_len = (u16) strlen(acpi_gbl_history_buffer[acpi_gbl_next_history_index]. command); if (cmd_len > buffer_len) { acpi_os_free(acpi_gbl_history_buffer [acpi_gbl_next_history_index].command); acpi_gbl_history_buffer[acpi_gbl_next_history_index]. command = acpi_os_allocate(cmd_len + 1); } } else { acpi_gbl_history_buffer[acpi_gbl_next_history_index].command = acpi_os_allocate(cmd_len + 1); } strcpy(acpi_gbl_history_buffer[acpi_gbl_next_history_index].command, command_line); acpi_gbl_history_buffer[acpi_gbl_next_history_index].cmd_num = acpi_gbl_next_cmd_num; /* Adjust indexes */ if ((acpi_gbl_num_history == HISTORY_SIZE) && (acpi_gbl_next_history_index == acpi_gbl_lo_history)) { acpi_gbl_lo_history++; if (acpi_gbl_lo_history >= HISTORY_SIZE) { acpi_gbl_lo_history = 0; } } acpi_gbl_next_history_index++; if (acpi_gbl_next_history_index >= HISTORY_SIZE) { acpi_gbl_next_history_index = 0; } acpi_gbl_next_cmd_num++; if (acpi_gbl_num_history < HISTORY_SIZE) { acpi_gbl_num_history++; } } /******************************************************************************* * * FUNCTION: acpi_db_display_history * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Display the contents of the history buffer * ******************************************************************************/ void acpi_db_display_history(void) { u32 i; u16 history_index; history_index = acpi_gbl_lo_history; /* Dump entire history buffer */ for (i = 0; i < acpi_gbl_num_history; i++) { if (acpi_gbl_history_buffer[history_index].command) { acpi_os_printf("%3u %s\n", acpi_gbl_history_buffer[history_index]. cmd_num, acpi_gbl_history_buffer[history_index]. command); } history_index++; if (history_index >= HISTORY_SIZE) { history_index = 0; } } } /******************************************************************************* * * FUNCTION: acpi_db_get_from_history * * PARAMETERS: command_num_arg - String containing the number of the * command to be retrieved * * RETURN: Pointer to the retrieved command. Null on error. * * DESCRIPTION: Get a command from the history buffer * ******************************************************************************/ char *acpi_db_get_from_history(char *command_num_arg) { u32 cmd_num; if (command_num_arg == NULL) { cmd_num = acpi_gbl_next_cmd_num - 1; } else { cmd_num = strtoul(command_num_arg, NULL, 0); } return (acpi_db_get_history_by_index(cmd_num)); } /******************************************************************************* * * FUNCTION: acpi_db_get_history_by_index * * PARAMETERS: cmd_num - Index of the desired history entry. * Values are 0...(acpi_gbl_next_cmd_num - 1) * * RETURN: Pointer to the retrieved command. Null on error. * * DESCRIPTION: Get a command from the history buffer * ******************************************************************************/ char *acpi_db_get_history_by_index(u32 cmd_num) { u32 i; u16 history_index; /* Search history buffer */ history_index = acpi_gbl_lo_history; for (i = 0; i < acpi_gbl_num_history; i++) { if (acpi_gbl_history_buffer[history_index].cmd_num == cmd_num) { /* Found the command, return it */ return (acpi_gbl_history_buffer[history_index].command); } /* History buffer is circular */ history_index++; if (history_index >= HISTORY_SIZE) { history_index = 0; } } acpi_os_printf("Invalid history number: %u\n", history_index); return (NULL); }
linux-master
drivers/acpi/acpica/dbhistry.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: nssearch - Namespace search * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #ifdef ACPI_ASL_COMPILER #include "amlcode.h" #endif #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nssearch") /* Local prototypes */ static acpi_status acpi_ns_search_parent_tree(u32 target_name, struct acpi_namespace_node *node, acpi_object_type type, struct acpi_namespace_node **return_node); /******************************************************************************* * * FUNCTION: acpi_ns_search_one_scope * * PARAMETERS: target_name - Ascii ACPI name to search for * parent_node - Starting node where search will begin * type - Object type to match * return_node - Where the matched Named obj is returned * * RETURN: Status * * DESCRIPTION: Search a single level of the namespace. Performs a * simple search of the specified level, and does not add * entries or search parents. * * * Named object lists are built (and subsequently dumped) in the * order in which the names are encountered during the namespace load; * * All namespace searching is linear in this implementation, but * could be easily modified to support any improved search * algorithm. However, the linear search was chosen for simplicity * and because the trees are small and the other interpreter * execution overhead is relatively high. * * Note: CPU execution analysis has shown that the AML interpreter spends * a very small percentage of its time searching the namespace. Therefore, * the linear search seems to be sufficient, as there would seem to be * little value in improving the search. * ******************************************************************************/ acpi_status acpi_ns_search_one_scope(u32 target_name, struct acpi_namespace_node *parent_node, acpi_object_type type, struct acpi_namespace_node **return_node) { struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(ns_search_one_scope); #ifdef ACPI_DEBUG_OUTPUT if (ACPI_LV_NAMES & acpi_dbg_level) { char *scope_name; scope_name = acpi_ns_get_normalized_pathname(parent_node, TRUE); if (scope_name) { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Searching %s (%p) For [%4.4s] (%s)\n", scope_name, parent_node, ACPI_CAST_PTR(char, &target_name), acpi_ut_get_type_name(type))); ACPI_FREE(scope_name); } } #endif /* * Search for name at this namespace level, which is to say that we * must search for the name among the children of this object */ node = parent_node->child; while (node) { /* Check for match against the name */ if (node->name.integer == target_name) { /* Resolve a control method alias if any */ if (acpi_ns_get_type(node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) { node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object); } /* Found matching entry */ ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n", ACPI_CAST_PTR(char, &target_name), acpi_ut_get_type_name(node->type), node, acpi_ut_get_node_name(parent_node), parent_node)); *return_node = node; return_ACPI_STATUS(AE_OK); } /* Didn't match name, move on to the next peer object */ node = node->peer; } /* Searched entire namespace level, not found */ ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Name [%4.4s] (%s) not found in search in scope [%4.4s] " "%p first child %p\n", ACPI_CAST_PTR(char, &target_name), acpi_ut_get_type_name(type), acpi_ut_get_node_name(parent_node), parent_node, parent_node->child)); return_ACPI_STATUS(AE_NOT_FOUND); } /******************************************************************************* * * FUNCTION: acpi_ns_search_parent_tree * * PARAMETERS: target_name - Ascii ACPI name to search for * node - Starting node where search will begin * type - Object type to match * return_node - Where the matched Node is returned * * RETURN: Status * * DESCRIPTION: Called when a name has not been found in the current namespace * level. Before adding it or giving up, ACPI scope rules require * searching enclosing scopes in cases identified by acpi_ns_local(). * * "A name is located by finding the matching name in the current * name space, and then in the parent name space. If the parent * name space does not contain the name, the search continues * recursively until either the name is found or the name space * does not have a parent (the root of the name space). This * indicates that the name is not found" (From ACPI Specification, * section 5.3) * ******************************************************************************/ static acpi_status acpi_ns_search_parent_tree(u32 target_name, struct acpi_namespace_node *node, acpi_object_type type, struct acpi_namespace_node **return_node) { acpi_status status; struct acpi_namespace_node *parent_node; ACPI_FUNCTION_TRACE(ns_search_parent_tree); parent_node = node->parent; /* * If there is no parent (i.e., we are at the root) or type is "local", * we won't be searching the parent tree. */ if (!parent_node) { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "[%4.4s] has no parent\n", ACPI_CAST_PTR(char, &target_name))); return_ACPI_STATUS(AE_NOT_FOUND); } if (acpi_ns_local(type)) { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "[%4.4s] type [%s] must be local to this scope (no parent search)\n", ACPI_CAST_PTR(char, &target_name), acpi_ut_get_type_name(type))); return_ACPI_STATUS(AE_NOT_FOUND); } /* Search the parent tree */ ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Searching parent [%4.4s] for [%4.4s]\n", acpi_ut_get_node_name(parent_node), ACPI_CAST_PTR(char, &target_name))); /* Search parents until target is found or we have backed up to the root */ while (parent_node) { /* * Search parent scope. Use TYPE_ANY because we don't care about the * object type at this point, we only care about the existence of * the actual name we are searching for. Typechecking comes later. */ status = acpi_ns_search_one_scope(target_name, parent_node, ACPI_TYPE_ANY, return_node); if (ACPI_SUCCESS(status)) { return_ACPI_STATUS(status); } /* Not found here, go up another level (until we reach the root) */ parent_node = parent_node->parent; } /* Not found in parent tree */ return_ACPI_STATUS(AE_NOT_FOUND); } /******************************************************************************* * * FUNCTION: acpi_ns_search_and_enter * * PARAMETERS: target_name - Ascii ACPI name to search for (4 chars) * walk_state - Current state of the walk * node - Starting node where search will begin * interpreter_mode - Add names only in ACPI_MODE_LOAD_PASS_x. * Otherwise,search only. * type - Object type to match * flags - Flags describing the search restrictions * return_node - Where the Node is returned * * RETURN: Status * * DESCRIPTION: Search for a name segment in a single namespace level, * optionally adding it if it is not found. If the passed * Type is not Any and the type previously stored in the * entry was Any (i.e. unknown), update the stored type. * * In ACPI_IMODE_EXECUTE, search only. * In other modes, search and add if not found. * ******************************************************************************/ acpi_status acpi_ns_search_and_enter(u32 target_name, struct acpi_walk_state *walk_state, struct acpi_namespace_node *node, acpi_interpreter_mode interpreter_mode, acpi_object_type type, u32 flags, struct acpi_namespace_node **return_node) { acpi_status status; struct acpi_namespace_node *new_node; ACPI_FUNCTION_TRACE(ns_search_and_enter); /* Parameter validation */ if (!node || !target_name || !return_node) { ACPI_ERROR((AE_INFO, "Null parameter: Node %p Name 0x%X ReturnNode %p", node, target_name, return_node)); return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Name must consist of valid ACPI characters. We will repair the name if * necessary because we don't want to abort because of this, but we want * all namespace names to be printable. A warning message is appropriate. * * This issue came up because there are in fact machines that exhibit * this problem, and we want to be able to enable ACPI support for them, * even though there are a few bad names. */ acpi_ut_repair_name(ACPI_CAST_PTR(char, &target_name)); /* Try to find the name in the namespace level specified by the caller */ *return_node = ACPI_ENTRY_NOT_FOUND; status = acpi_ns_search_one_scope(target_name, node, type, return_node); if (status != AE_NOT_FOUND) { /* * If we found it AND the request specifies that a find is an error, * return the error */ if (status == AE_OK) { /* The node was found in the namespace */ /* * If the namespace override feature is enabled for this node, * delete any existing attached sub-object and make the node * look like a new node that is owned by the override table. */ if (flags & ACPI_NS_OVERRIDE_IF_FOUND) { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Namespace override: %4.4s pass %u type %X Owner %X\n", ACPI_CAST_PTR(char, &target_name), interpreter_mode, (*return_node)->type, walk_state->owner_id)); acpi_ns_delete_children(*return_node); if (acpi_gbl_runtime_namespace_override) { acpi_ut_remove_reference((*return_node)->object); (*return_node)->object = NULL; (*return_node)->owner_id = walk_state->owner_id; } else { acpi_ns_remove_node(*return_node); *return_node = ACPI_ENTRY_NOT_FOUND; } } /* Return an error if we don't expect to find the object */ else if (flags & ACPI_NS_ERROR_IF_FOUND) { status = AE_ALREADY_EXISTS; } } #ifdef ACPI_ASL_COMPILER if (*return_node && (*return_node)->type == ACPI_TYPE_ANY) { (*return_node)->flags |= ANOBJ_IS_EXTERNAL; } #endif /* Either found it or there was an error: finished either way */ return_ACPI_STATUS(status); } /* * The name was not found. If we are NOT performing the first pass * (name entry) of loading the namespace, search the parent tree (all the * way to the root if necessary.) We don't want to perform the parent * search when the namespace is actually being loaded. We want to perform * the search when namespace references are being resolved (load pass 2) * and during the execution phase. */ if ((interpreter_mode != ACPI_IMODE_LOAD_PASS1) && (flags & ACPI_NS_SEARCH_PARENT)) { /* * Not found at this level - search parent tree according to the * ACPI specification */ status = acpi_ns_search_parent_tree(target_name, node, type, return_node); if (ACPI_SUCCESS(status)) { return_ACPI_STATUS(status); } } /* In execute mode, just search, never add names. Exit now */ if (interpreter_mode == ACPI_IMODE_EXECUTE) { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%4.4s Not found in %p [Not adding]\n", ACPI_CAST_PTR(char, &target_name), node)); return_ACPI_STATUS(AE_NOT_FOUND); } /* Create the new named object */ new_node = acpi_ns_create_node(target_name); if (!new_node) { return_ACPI_STATUS(AE_NO_MEMORY); } #ifdef ACPI_ASL_COMPILER /* Node is an object defined by an External() statement */ if (flags & ACPI_NS_EXTERNAL || (walk_state && walk_state->opcode == AML_SCOPE_OP)) { new_node->flags |= ANOBJ_IS_EXTERNAL; } #endif if (flags & ACPI_NS_TEMPORARY) { new_node->flags |= ANOBJ_TEMPORARY; } /* Install the new object into the parent's list of children */ acpi_ns_install_node(walk_state, node, new_node, type); *return_node = new_node; return_ACPI_STATUS(AE_OK); }
linux-master
drivers/acpi/acpica/nssearch.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utcache - local cache allocation routines * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utcache") #ifdef ACPI_USE_LOCAL_CACHE /******************************************************************************* * * FUNCTION: acpi_os_create_cache * * PARAMETERS: cache_name - Ascii name for the cache * object_size - Size of each cached object * max_depth - Maximum depth of the cache (in objects) * return_cache - Where the new cache object is returned * * RETURN: Status * * DESCRIPTION: Create a cache object * ******************************************************************************/ acpi_status acpi_os_create_cache(char *cache_name, u16 object_size, u16 max_depth, struct acpi_memory_list **return_cache) { struct acpi_memory_list *cache; ACPI_FUNCTION_ENTRY(); if (!cache_name || !return_cache || !object_size) { return (AE_BAD_PARAMETER); } /* Create the cache object */ cache = acpi_os_allocate(sizeof(struct acpi_memory_list)); if (!cache) { return (AE_NO_MEMORY); } /* Populate the cache object and return it */ memset(cache, 0, sizeof(struct acpi_memory_list)); cache->list_name = cache_name; cache->object_size = object_size; cache->max_depth = max_depth; *return_cache = cache; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_os_purge_cache * * PARAMETERS: cache - Handle to cache object * * RETURN: Status * * DESCRIPTION: Free all objects within the requested cache. * ******************************************************************************/ acpi_status acpi_os_purge_cache(struct acpi_memory_list *cache) { void *next; acpi_status status; ACPI_FUNCTION_ENTRY(); if (!cache) { return (AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); if (ACPI_FAILURE(status)) { return (status); } /* Walk the list of objects in this cache */ while (cache->list_head) { /* Delete and unlink one cached state object */ next = ACPI_GET_DESCRIPTOR_PTR(cache->list_head); ACPI_FREE(cache->list_head); cache->list_head = next; cache->current_depth--; } (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_os_delete_cache * * PARAMETERS: cache - Handle to cache object * * RETURN: Status * * DESCRIPTION: Free all objects within the requested cache and delete the * cache object. * ******************************************************************************/ acpi_status acpi_os_delete_cache(struct acpi_memory_list *cache) { acpi_status status; ACPI_FUNCTION_ENTRY(); /* Purge all objects in the cache */ status = acpi_os_purge_cache(cache); if (ACPI_FAILURE(status)) { return (status); } /* Now we can delete the cache object */ acpi_os_free(cache); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_os_release_object * * PARAMETERS: cache - Handle to cache object * object - The object to be released * * RETURN: None * * DESCRIPTION: Release an object to the specified cache. If cache is full, * the object is deleted. * ******************************************************************************/ acpi_status acpi_os_release_object(struct acpi_memory_list *cache, void *object) { acpi_status status; ACPI_FUNCTION_ENTRY(); if (!cache || !object) { return (AE_BAD_PARAMETER); } /* If cache is full, just free this object */ if (cache->current_depth >= cache->max_depth) { ACPI_FREE(object); ACPI_MEM_TRACKING(cache->total_freed++); } /* Otherwise put this object back into the cache */ else { status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); if (ACPI_FAILURE(status)) { return (status); } /* Mark the object as cached */ memset(object, 0xCA, cache->object_size); ACPI_SET_DESCRIPTOR_TYPE(object, ACPI_DESC_TYPE_CACHED); /* Put the object at the head of the cache list */ ACPI_SET_DESCRIPTOR_PTR(object, cache->list_head); cache->list_head = object; cache->current_depth++; (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_os_acquire_object * * PARAMETERS: cache - Handle to cache object * * RETURN: the acquired object. NULL on error * * DESCRIPTION: Get an object from the specified cache. If cache is empty, * the object is allocated. * ******************************************************************************/ void *acpi_os_acquire_object(struct acpi_memory_list *cache) { acpi_status status; void *object; ACPI_FUNCTION_TRACE(os_acquire_object); if (!cache) { return_PTR(NULL); } status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); if (ACPI_FAILURE(status)) { return_PTR(NULL); } ACPI_MEM_TRACKING(cache->requests++); /* Check the cache first */ if (cache->list_head) { /* There is an object available, use it */ object = cache->list_head; cache->list_head = ACPI_GET_DESCRIPTOR_PTR(object); cache->current_depth--; ACPI_MEM_TRACKING(cache->hits++); ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "%s: Object %p from %s cache\n", ACPI_GET_FUNCTION_NAME, object, cache->list_name)); status = acpi_ut_release_mutex(ACPI_MTX_CACHES); if (ACPI_FAILURE(status)) { return_PTR(NULL); } /* Clear (zero) the previously used Object */ memset(object, 0, cache->object_size); } else { /* The cache is empty, create a new object */ ACPI_MEM_TRACKING(cache->total_allocated++); #ifdef ACPI_DBG_TRACK_ALLOCATIONS if ((cache->total_allocated - cache->total_freed) > cache->max_occupied) { cache->max_occupied = cache->total_allocated - cache->total_freed; } #endif /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */ status = acpi_ut_release_mutex(ACPI_MTX_CACHES); if (ACPI_FAILURE(status)) { return_PTR(NULL); } object = ACPI_ALLOCATE_ZEROED(cache->object_size); if (!object) { return_PTR(NULL); } } return_PTR(object); } #endif /* ACPI_USE_LOCAL_CACHE */
linux-master
drivers/acpi/acpica/utcache.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utxface - External interfaces, miscellaneous utility functions * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "acdebug.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utxface") /******************************************************************************* * * FUNCTION: acpi_terminate * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources. * ******************************************************************************/ acpi_status ACPI_INIT_FUNCTION acpi_terminate(void) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_terminate); /* Shutdown and free all resources */ acpi_ut_subsystem_shutdown(); /* Free the mutex objects */ acpi_ut_mutex_terminate(); /* Now we can shutdown the OS-dependent layer */ status = acpi_os_terminate(); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL_INIT(acpi_terminate) #ifndef ACPI_ASL_COMPILER #ifdef ACPI_FUTURE_USAGE /******************************************************************************* * * FUNCTION: acpi_subsystem_status * * PARAMETERS: None * * RETURN: Status of the ACPI subsystem * * DESCRIPTION: Other drivers that use the ACPI subsystem should call this * before making any other calls, to ensure the subsystem * initialized successfully. * ******************************************************************************/ acpi_status acpi_subsystem_status(void) { if (acpi_gbl_startup_flags & ACPI_INITIALIZED_OK) { return (AE_OK); } else { return (AE_ERROR); } } ACPI_EXPORT_SYMBOL(acpi_subsystem_status) /******************************************************************************* * * FUNCTION: acpi_get_system_info * * PARAMETERS: out_buffer - A buffer to receive the resources for the * device * * RETURN: status - the status of the call * * DESCRIPTION: This function is called to get information about the current * state of the ACPI subsystem. It will return system information * in the out_buffer. * * If the function fails an appropriate status will be returned * and the value of out_buffer is undefined. * ******************************************************************************/ acpi_status acpi_get_system_info(struct acpi_buffer *out_buffer) { struct acpi_system_info *info_ptr; acpi_status status; ACPI_FUNCTION_TRACE(acpi_get_system_info); /* Parameter validation */ status = acpi_ut_validate_buffer(out_buffer); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Validate/Allocate/Clear caller buffer */ status = acpi_ut_initialize_buffer(out_buffer, sizeof(struct acpi_system_info)); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Populate the return buffer */ info_ptr = (struct acpi_system_info *)out_buffer->pointer; info_ptr->acpi_ca_version = ACPI_CA_VERSION; /* System flags (ACPI capabilities) */ info_ptr->flags = ACPI_SYS_MODE_ACPI; /* Timer resolution - 24 or 32 bits */ if (acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) { info_ptr->timer_resolution = 24; } else { info_ptr->timer_resolution = 32; } /* Clear the reserved fields */ info_ptr->reserved1 = 0; info_ptr->reserved2 = 0; /* Current debug levels */ info_ptr->debug_layer = acpi_dbg_layer; info_ptr->debug_level = acpi_dbg_level; return_ACPI_STATUS(AE_OK); } ACPI_EXPORT_SYMBOL(acpi_get_system_info) /******************************************************************************* * * FUNCTION: acpi_get_statistics * * PARAMETERS: stats - Where the statistics are returned * * RETURN: status - the status of the call * * DESCRIPTION: Get the contents of the various system counters * ******************************************************************************/ acpi_status acpi_get_statistics(struct acpi_statistics *stats) { ACPI_FUNCTION_TRACE(acpi_get_statistics); /* Parameter validation */ if (!stats) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Various interrupt-based event counters */ stats->sci_count = acpi_sci_count; stats->gpe_count = acpi_gpe_count; memcpy(stats->fixed_event_count, acpi_fixed_event_count, sizeof(acpi_fixed_event_count)); /* Other counters */ stats->method_count = acpi_method_count; return_ACPI_STATUS(AE_OK); } ACPI_EXPORT_SYMBOL(acpi_get_statistics) /***************************************************************************** * * FUNCTION: acpi_install_initialization_handler * * PARAMETERS: handler - Callback procedure * function - Not (currently) used, see below * * RETURN: Status * * DESCRIPTION: Install an initialization handler * * TBD: When a second function is added, must save the Function also. * ****************************************************************************/ acpi_status acpi_install_initialization_handler(acpi_init_handler handler, u32 function) { if (!handler) { return (AE_BAD_PARAMETER); } if (acpi_gbl_init_handler) { return (AE_ALREADY_EXISTS); } acpi_gbl_init_handler = handler; return (AE_OK); } ACPI_EXPORT_SYMBOL(acpi_install_initialization_handler) #endif /***************************************************************************** * * FUNCTION: acpi_purge_cached_objects * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Empty all caches (delete the cached objects) * ****************************************************************************/ acpi_status acpi_purge_cached_objects(void) { ACPI_FUNCTION_TRACE(acpi_purge_cached_objects); (void)acpi_os_purge_cache(acpi_gbl_state_cache); (void)acpi_os_purge_cache(acpi_gbl_operand_cache); (void)acpi_os_purge_cache(acpi_gbl_ps_node_cache); (void)acpi_os_purge_cache(acpi_gbl_ps_node_ext_cache); return_ACPI_STATUS(AE_OK); } ACPI_EXPORT_SYMBOL(acpi_purge_cached_objects) /***************************************************************************** * * FUNCTION: acpi_install_interface * * PARAMETERS: interface_name - The interface to install * * RETURN: Status * * DESCRIPTION: Install an _OSI interface to the global list * ****************************************************************************/ acpi_status acpi_install_interface(acpi_string interface_name) { acpi_status status; struct acpi_interface_info *interface_info; /* Parameter validation */ if (!interface_name || (strlen(interface_name) == 0)) { return (AE_BAD_PARAMETER); } status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER); if (ACPI_FAILURE(status)) { return (status); } /* Check if the interface name is already in the global list */ interface_info = acpi_ut_get_interface(interface_name); if (interface_info) { /* * The interface already exists in the list. This is OK if the * interface has been marked invalid -- just clear the bit. */ if (interface_info->flags & ACPI_OSI_INVALID) { interface_info->flags &= ~ACPI_OSI_INVALID; status = AE_OK; } else { status = AE_ALREADY_EXISTS; } } else { /* New interface name, install into the global list */ status = acpi_ut_install_interface(interface_name); } acpi_os_release_mutex(acpi_gbl_osi_mutex); return (status); } ACPI_EXPORT_SYMBOL(acpi_install_interface) /***************************************************************************** * * FUNCTION: acpi_remove_interface * * PARAMETERS: interface_name - The interface to remove * * RETURN: Status * * DESCRIPTION: Remove an _OSI interface from the global list * ****************************************************************************/ acpi_status acpi_remove_interface(acpi_string interface_name) { acpi_status status; /* Parameter validation */ if (!interface_name || (strlen(interface_name) == 0)) { return (AE_BAD_PARAMETER); } status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER); if (ACPI_FAILURE(status)) { return (status); } status = acpi_ut_remove_interface(interface_name); acpi_os_release_mutex(acpi_gbl_osi_mutex); return (status); } ACPI_EXPORT_SYMBOL(acpi_remove_interface) /***************************************************************************** * * FUNCTION: acpi_install_interface_handler * * PARAMETERS: handler - The _OSI interface handler to install * NULL means "remove existing handler" * * RETURN: Status * * DESCRIPTION: Install a handler for the predefined _OSI ACPI method. * invoked during execution of the internal implementation of * _OSI. A NULL handler simply removes any existing handler. * ****************************************************************************/ acpi_status acpi_install_interface_handler(acpi_interface_handler handler) { acpi_status status; status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER); if (ACPI_FAILURE(status)) { return (status); } if (handler && acpi_gbl_interface_handler) { status = AE_ALREADY_EXISTS; } else { acpi_gbl_interface_handler = handler; } acpi_os_release_mutex(acpi_gbl_osi_mutex); return (status); } ACPI_EXPORT_SYMBOL(acpi_install_interface_handler) /***************************************************************************** * * FUNCTION: acpi_update_interfaces * * PARAMETERS: action - Actions to be performed during the * update * * RETURN: Status * * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor * string or/and feature group strings. * ****************************************************************************/ acpi_status acpi_update_interfaces(u8 action) { acpi_status status; status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER); if (ACPI_FAILURE(status)) { return (status); } status = acpi_ut_update_interfaces(action); acpi_os_release_mutex(acpi_gbl_osi_mutex); return (status); } /***************************************************************************** * * FUNCTION: acpi_check_address_range * * PARAMETERS: space_id - Address space ID * address - Start address * length - Length * warn - TRUE if warning on overlap desired * * RETURN: Count of the number of conflicts detected. * * DESCRIPTION: Check if the input address range overlaps any of the * ASL operation region address ranges. * ****************************************************************************/ u32 acpi_check_address_range(acpi_adr_space_type space_id, acpi_physical_address address, acpi_size length, u8 warn) { u32 overlaps; acpi_status status; status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (0); } overlaps = acpi_ut_check_address_range(space_id, address, (u32)length, warn); (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (overlaps); } ACPI_EXPORT_SYMBOL(acpi_check_address_range) #endif /* !ACPI_ASL_COMPILER */ /******************************************************************************* * * FUNCTION: acpi_decode_pld_buffer * * PARAMETERS: in_buffer - Buffer returned by _PLD method * length - Length of the in_buffer * return_buffer - Where the decode buffer is returned * * RETURN: Status and the decoded _PLD buffer. User must deallocate * the buffer via ACPI_FREE. * * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into * a local struct that is much more useful to an ACPI driver. * ******************************************************************************/ acpi_status acpi_decode_pld_buffer(u8 *in_buffer, acpi_size length, struct acpi_pld_info **return_buffer) { struct acpi_pld_info *pld_info; u32 *buffer = ACPI_CAST_PTR(u32, in_buffer); u32 dword; /* Parameter validation */ if (!in_buffer || !return_buffer || (length < ACPI_PLD_REV1_BUFFER_SIZE)) { return (AE_BAD_PARAMETER); } pld_info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pld_info)); if (!pld_info) { return (AE_NO_MEMORY); } /* First 32-bit DWord */ ACPI_MOVE_32_TO_32(&dword, &buffer[0]); pld_info->revision = ACPI_PLD_GET_REVISION(&dword); pld_info->ignore_color = ACPI_PLD_GET_IGNORE_COLOR(&dword); pld_info->red = ACPI_PLD_GET_RED(&dword); pld_info->green = ACPI_PLD_GET_GREEN(&dword); pld_info->blue = ACPI_PLD_GET_BLUE(&dword); /* Second 32-bit DWord */ ACPI_MOVE_32_TO_32(&dword, &buffer[1]); pld_info->width = ACPI_PLD_GET_WIDTH(&dword); pld_info->height = ACPI_PLD_GET_HEIGHT(&dword); /* Third 32-bit DWord */ ACPI_MOVE_32_TO_32(&dword, &buffer[2]); pld_info->user_visible = ACPI_PLD_GET_USER_VISIBLE(&dword); pld_info->dock = ACPI_PLD_GET_DOCK(&dword); pld_info->lid = ACPI_PLD_GET_LID(&dword); pld_info->panel = ACPI_PLD_GET_PANEL(&dword); pld_info->vertical_position = ACPI_PLD_GET_VERTICAL(&dword); pld_info->horizontal_position = ACPI_PLD_GET_HORIZONTAL(&dword); pld_info->shape = ACPI_PLD_GET_SHAPE(&dword); pld_info->group_orientation = ACPI_PLD_GET_ORIENTATION(&dword); pld_info->group_token = ACPI_PLD_GET_TOKEN(&dword); pld_info->group_position = ACPI_PLD_GET_POSITION(&dword); pld_info->bay = ACPI_PLD_GET_BAY(&dword); /* Fourth 32-bit DWord */ ACPI_MOVE_32_TO_32(&dword, &buffer[3]); pld_info->ejectable = ACPI_PLD_GET_EJECTABLE(&dword); pld_info->ospm_eject_required = ACPI_PLD_GET_OSPM_EJECT(&dword); pld_info->cabinet_number = ACPI_PLD_GET_CABINET(&dword); pld_info->card_cage_number = ACPI_PLD_GET_CARD_CAGE(&dword); pld_info->reference = ACPI_PLD_GET_REFERENCE(&dword); pld_info->rotation = ACPI_PLD_GET_ROTATION(&dword); pld_info->order = ACPI_PLD_GET_ORDER(&dword); if (length >= ACPI_PLD_REV2_BUFFER_SIZE) { /* Fifth 32-bit DWord (Revision 2 of _PLD) */ ACPI_MOVE_32_TO_32(&dword, &buffer[4]); pld_info->vertical_offset = ACPI_PLD_GET_VERT_OFFSET(&dword); pld_info->horizontal_offset = ACPI_PLD_GET_HORIZ_OFFSET(&dword); } *return_buffer = pld_info; return (AE_OK); } ACPI_EXPORT_SYMBOL(acpi_decode_pld_buffer)
linux-master
drivers/acpi/acpica/utxface.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dswload - Dispatcher first pass namespace load callbacks * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "amlcode.h" #include "acdispat.h" #include "acinterp.h" #include "acnamesp.h" #ifdef ACPI_ASL_COMPILER #include "acdisasm.h" #endif #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dswload") /******************************************************************************* * * FUNCTION: acpi_ds_init_callbacks * * PARAMETERS: walk_state - Current state of the parse tree walk * pass_number - 1, 2, or 3 * * RETURN: Status * * DESCRIPTION: Init walk state callbacks * ******************************************************************************/ acpi_status acpi_ds_init_callbacks(struct acpi_walk_state *walk_state, u32 pass_number) { switch (pass_number) { case 0: /* Parse only - caller will setup callbacks */ walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE | ACPI_PARSE_DISASSEMBLE; walk_state->descending_callback = NULL; walk_state->ascending_callback = NULL; break; case 1: /* Load pass 1 */ walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE; walk_state->descending_callback = acpi_ds_load1_begin_op; walk_state->ascending_callback = acpi_ds_load1_end_op; break; case 2: /* Load pass 2 */ walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE; walk_state->descending_callback = acpi_ds_load2_begin_op; walk_state->ascending_callback = acpi_ds_load2_end_op; break; case 3: /* Execution pass */ walk_state->parse_flags |= ACPI_PARSE_EXECUTE | ACPI_PARSE_DELETE_TREE; walk_state->descending_callback = acpi_ds_exec_begin_op; walk_state->ascending_callback = acpi_ds_exec_end_op; break; default: return (AE_BAD_PARAMETER); } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_load1_begin_op * * PARAMETERS: walk_state - Current state of the parse tree walk * out_op - Where to return op if a new one is created * * RETURN: Status * * DESCRIPTION: Descending callback used during the loading of ACPI tables. * ******************************************************************************/ acpi_status acpi_ds_load1_begin_op(struct acpi_walk_state *walk_state, union acpi_parse_object **out_op) { union acpi_parse_object *op; struct acpi_namespace_node *node; acpi_status status; acpi_object_type object_type; char *path; u32 flags; ACPI_FUNCTION_TRACE_PTR(ds_load1_begin_op, walk_state->op); op = walk_state->op; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state)); /* We are only interested in opcodes that have an associated name */ if (op) { if (!(walk_state->op_info->flags & AML_NAMED)) { *out_op = op; return_ACPI_STATUS(AE_OK); } /* Check if this object has already been installed in the namespace */ if (op->common.node) { *out_op = op; return_ACPI_STATUS(AE_OK); } } path = acpi_ps_get_next_namestring(&walk_state->parser_state); /* Map the raw opcode into an internal object type */ object_type = walk_state->op_info->object_type; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "State=%p Op=%p [%s]\n", walk_state, op, acpi_ut_get_type_name(object_type))); switch (walk_state->opcode) { case AML_SCOPE_OP: /* * The target name of the Scope() operator must exist at this point so * that we can actually open the scope to enter new names underneath it. * Allow search-to-root for single namesegs. */ status = acpi_ns_lookup(walk_state->scope_info, path, object_type, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); #ifdef ACPI_ASL_COMPILER if (status == AE_NOT_FOUND) { /* * Table disassembly: * Target of Scope() not found. Generate an External for it, and * insert the name into the namespace. */ acpi_dm_add_op_to_external_list(op, path, ACPI_TYPE_DEVICE, 0, 0); status = acpi_ns_lookup(walk_state->scope_info, path, object_type, ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, walk_state, &node); } #endif if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, path, status); return_ACPI_STATUS(status); } /* * Check to make sure that the target is * one of the opcodes that actually opens a scope */ switch (node->type) { case ACPI_TYPE_ANY: case ACPI_TYPE_LOCAL_SCOPE: /* Scope */ case ACPI_TYPE_DEVICE: case ACPI_TYPE_POWER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: /* These are acceptable types */ break; case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* * These types we will allow, but we will change the type. * This enables some existing code of the form: * * Name (DEB, 0) * Scope (DEB) { ... } * * Note: silently change the type here. On the second pass, * we will report a warning */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Type override - [%4.4s] had invalid type (%s) " "for Scope operator, changed to type ANY\n", acpi_ut_get_node_name(node), acpi_ut_get_type_name(node->type))); node->type = ACPI_TYPE_ANY; walk_state->scope_info->common.value = ACPI_TYPE_ANY; break; case ACPI_TYPE_METHOD: /* * Allow scope change to root during execution of module-level * code. Root is typed METHOD during this time. */ if ((node == acpi_gbl_root_node) && (walk_state-> parse_flags & ACPI_PARSE_MODULE_LEVEL)) { break; } ACPI_FALLTHROUGH; default: /* All other types are an error */ ACPI_ERROR((AE_INFO, "Invalid type (%s) for target of " "Scope operator [%4.4s] (Cannot override)", acpi_ut_get_type_name(node->type), acpi_ut_get_node_name(node))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } break; default: /* * For all other named opcodes, we will enter the name into * the namespace. * * Setup the search flags. * Since we are entering a name into the namespace, we do not want to * enable the search-to-root upsearch. * * There are only two conditions where it is acceptable that the name * already exists: * 1) the Scope() operator can reopen a scoping object that was * previously defined (Scope, Method, Device, etc.) * 2) Whenever we are parsing a deferred opcode (op_region, Buffer, * buffer_field, or Package), the name of the object is already * in the namespace. */ if (walk_state->deferred_node) { /* This name is already in the namespace, get the node */ node = walk_state->deferred_node; status = AE_OK; break; } /* * If we are executing a method, do not create any namespace objects * during the load phase, only during execution. */ if (walk_state->method_node) { node = NULL; status = AE_OK; break; } flags = ACPI_NS_NO_UPSEARCH; if ((walk_state->opcode != AML_SCOPE_OP) && (!(walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP))) { if (walk_state->namespace_override) { flags |= ACPI_NS_OVERRIDE_IF_FOUND; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[%s] Override allowed\n", acpi_ut_get_type_name (object_type))); } else { flags |= ACPI_NS_ERROR_IF_FOUND; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n", acpi_ut_get_type_name (object_type))); } } else { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[%s] Both Find or Create allowed\n", acpi_ut_get_type_name(object_type))); } /* * Enter the named type into the internal namespace. We enter the name * as we go downward in the parse tree. Any necessary subobjects that * involve arguments to the opcode must be created as we go back up the * parse tree later. */ status = acpi_ns_lookup(walk_state->scope_info, path, object_type, ACPI_IMODE_LOAD_PASS1, flags, walk_state, &node); if (ACPI_FAILURE(status)) { if (status == AE_ALREADY_EXISTS) { /* The name already exists in this scope */ if (node->flags & ANOBJ_IS_EXTERNAL) { /* * Allow one create on an object or segment that was * previously declared External */ node->flags &= ~ANOBJ_IS_EXTERNAL; node->type = (u8) object_type; /* Just retyped a node, probably will need to open a scope */ if (acpi_ns_opens_scope(object_type)) { status = acpi_ds_scope_stack_push (node, object_type, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS (status); } } status = AE_OK; } } if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, path, status); return_ACPI_STATUS(status); } } break; } /* Common exit */ if (!op) { /* Create a new op */ op = acpi_ps_alloc_op(walk_state->opcode, walk_state->aml); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } } /* Initialize the op */ #ifdef ACPI_CONSTANT_EVAL_ONLY op->named.path = path; #endif if (node) { /* * Put the Node in the "op" object that the parser uses, so we * can get it again quickly when this scope is closed */ op->common.node = node; op->named.name = node->name.integer; } acpi_ps_append_arg(acpi_ps_get_parent_scope(&walk_state->parser_state), op); *out_op = op; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_load1_end_op * * PARAMETERS: walk_state - Current state of the parse tree walk * * RETURN: Status * * DESCRIPTION: Ascending callback used during the loading of the namespace, * both control methods and everything else. * ******************************************************************************/ acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state) { union acpi_parse_object *op; acpi_object_type object_type; acpi_status status = AE_OK; #ifdef ACPI_ASL_COMPILER u8 param_count; #endif ACPI_FUNCTION_TRACE(ds_load1_end_op); op = walk_state->op; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state)); /* * Disassembler: handle create field operators here. * * create_buffer_field is a deferred op that is typically processed in load * pass 2. However, disassembly of control method contents walk the parse * tree with ACPI_PARSE_LOAD_PASS1 and AML_CREATE operators are processed * in a later walk. This is a problem when there is a control method that * has the same name as the AML_CREATE object. In this case, any use of the * name segment will be detected as a method call rather than a reference * to a buffer field. * * This earlier creation during disassembly solves this issue by inserting * the named object in the ACPI namespace so that references to this name * would be a name string rather than a method call. */ if ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) && (walk_state->op_info->flags & AML_CREATE)) { status = acpi_ds_create_buffer_field(op, walk_state); return_ACPI_STATUS(status); } /* We are only interested in opcodes that have an associated name */ if (!(walk_state->op_info->flags & (AML_NAMED | AML_FIELD))) { return_ACPI_STATUS(AE_OK); } /* Get the object type to determine if we should pop the scope */ object_type = walk_state->op_info->object_type; if (walk_state->op_info->flags & AML_FIELD) { /* * If we are executing a method, do not create any namespace objects * during the load phase, only during execution. */ if (!walk_state->method_node) { if (walk_state->opcode == AML_FIELD_OP || walk_state->opcode == AML_BANK_FIELD_OP || walk_state->opcode == AML_INDEX_FIELD_OP) { status = acpi_ds_init_field_objects(op, walk_state); } } return_ACPI_STATUS(status); } /* * If we are executing a method, do not create any namespace objects * during the load phase, only during execution. */ if (!walk_state->method_node) { if (op->common.aml_opcode == AML_REGION_OP) { status = acpi_ex_create_region(op->named.data, op->named.length, (acpi_adr_space_type) ((op->common.value.arg)-> common.value.integer), walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } else if (op->common.aml_opcode == AML_DATA_REGION_OP) { status = acpi_ex_create_region(op->named.data, op->named.length, ACPI_ADR_SPACE_DATA_TABLE, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } } if (op->common.aml_opcode == AML_NAME_OP) { /* For Name opcode, get the object type from the argument */ if (op->common.value.arg) { object_type = (acpi_ps_get_opcode_info((op->common. value.arg)-> common. aml_opcode))-> object_type; /* Set node type if we have a namespace node */ if (op->common.node) { op->common.node->type = (u8) object_type; } } } #ifdef ACPI_ASL_COMPILER /* * For external opcode, get the object type from the argument and * get the parameter count from the argument's next. */ if (acpi_gbl_disasm_flag && op->common.node && op->common.aml_opcode == AML_EXTERNAL_OP) { /* * Note, if this external is not a method * Op->Common.Value.Arg->Common.Next->Common.Value.Integer == 0 * Therefore, param_count will be 0. */ param_count = (u8)op->common.value.arg->common.next->common.value.integer; object_type = (u8)op->common.value.arg->common.value.integer; op->common.node->flags |= ANOBJ_IS_EXTERNAL; op->common.node->type = (u8)object_type; acpi_dm_create_subobject_for_external((u8)object_type, &op->common.node, param_count); /* * Add the external to the external list because we may be * emitting code based off of the items within the external list. */ acpi_dm_add_op_to_external_list(op, op->named.path, (u8)object_type, param_count, ACPI_EXT_ORIGIN_FROM_OPCODE | ACPI_EXT_RESOLVED_REFERENCE); } #endif /* * If we are executing a method, do not create any namespace objects * during the load phase, only during execution. */ if (!walk_state->method_node) { if (op->common.aml_opcode == AML_METHOD_OP) { /* * method_op pkg_length name_string method_flags term_list * * Note: We must create the method node/object pair as soon as we * see the method declaration. This allows later pass1 parsing * of invocations of the method (need to know the number of * arguments.) */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "LOADING-Method: State=%p Op=%p NamedObj=%p\n", walk_state, op, op->named.node)); if (!acpi_ns_get_attached_object(op->named.node)) { walk_state->operands[0] = ACPI_CAST_PTR(void, op->named.node); walk_state->num_operands = 1; status = acpi_ds_create_operands(walk_state, op->common.value. arg); if (ACPI_SUCCESS(status)) { status = acpi_ex_create_method(op->named. data, op->named. length, walk_state); } walk_state->operands[0] = NULL; walk_state->num_operands = 0; if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } } } /* Pop the scope stack (only if loading a table) */ if (!walk_state->method_node && op->common.aml_opcode != AML_EXTERNAL_OP && acpi_ns_opens_scope(object_type)) { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n", acpi_ut_get_type_name(object_type), op)); status = acpi_ds_scope_stack_pop(walk_state); } return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/dswload.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exserial - field_unit support for serial address spaces * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdispat.h" #include "acinterp.h" #include "amlcode.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exserial") /******************************************************************************* * * FUNCTION: acpi_ex_read_gpio * * PARAMETERS: obj_desc - The named field to read * buffer - Where the return data is returned * * RETURN: Status * * DESCRIPTION: Read from a named field that references a Generic Serial Bus * field * ******************************************************************************/ acpi_status acpi_ex_read_gpio(union acpi_operand_object *obj_desc, void *buffer) { acpi_status status; ACPI_FUNCTION_TRACE_PTR(ex_read_gpio, obj_desc); /* * For GPIO (general_purpose_io), the Address will be the bit offset * from the previous Connection() operator, making it effectively a * pin number index. The bit_length is the length of the field, which * is thus the number of pins. */ ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "GPIO FieldRead [FROM]: Pin %u Bits %u\n", obj_desc->field.pin_number_index, obj_desc->field.bit_length)); /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* Perform the read */ status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, ACPI_READ); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_write_gpio * * PARAMETERS: source_desc - Contains data to write. Expect to be * an Integer object. * obj_desc - The named field * result_desc - Where the return value is returned, if any * * RETURN: Status * * DESCRIPTION: Write to a named field that references a General Purpose I/O * field. * ******************************************************************************/ acpi_status acpi_ex_write_gpio(union acpi_operand_object *source_desc, union acpi_operand_object *obj_desc, union acpi_operand_object **return_buffer) { acpi_status status; void *buffer; ACPI_FUNCTION_TRACE_PTR(ex_write_gpio, obj_desc); /* * For GPIO (general_purpose_io), we will bypass the entire field * mechanism and handoff the bit address and bit width directly to * the handler. The Address will be the bit offset * from the previous Connection() operator, making it effectively a * pin number index. The bit_length is the length of the field, which * is thus the number of pins. */ if (source_desc->common.type != ACPI_TYPE_INTEGER) { return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "GPIO FieldWrite [FROM]: (%s:%X), Value %.8X [TO]: Pin %u Bits %u\n", acpi_ut_get_type_name(source_desc->common.type), source_desc->common.type, (u32)source_desc->integer.value, obj_desc->field.pin_number_index, obj_desc->field.bit_length)); buffer = &source_desc->integer.value; /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* Perform the write */ status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, ACPI_WRITE); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_read_serial_bus * * PARAMETERS: obj_desc - The named field to read * return_buffer - Where the return value is returned, if any * * RETURN: Status * * DESCRIPTION: Read from a named field that references a serial bus * (SMBus, IPMI, or GSBus). * ******************************************************************************/ acpi_status acpi_ex_read_serial_bus(union acpi_operand_object *obj_desc, union acpi_operand_object **return_buffer) { acpi_status status; u32 buffer_length; union acpi_operand_object *buffer_desc; u32 function; u16 accessor_type; ACPI_FUNCTION_TRACE_PTR(ex_read_serial_bus, obj_desc); /* * This is an SMBus, GSBus or IPMI read. We must create a buffer to * hold the data and then directly access the region handler. * * Note: SMBus and GSBus protocol value is passed in upper 16-bits * of Function * * Common buffer format: * Status; (Byte 0 of the data buffer) * Length; (Byte 1 of the data buffer) * Data[x-1]: (Bytes 2-x of the arbitrary length data buffer) */ switch (obj_desc->field.region_obj->region.space_id) { case ACPI_ADR_SPACE_SMBUS: buffer_length = ACPI_SMBUS_BUFFER_SIZE; function = ACPI_READ | (obj_desc->field.attribute << 16); break; case ACPI_ADR_SPACE_IPMI: buffer_length = ACPI_IPMI_BUFFER_SIZE; function = ACPI_READ; break; case ACPI_ADR_SPACE_GSBUS: accessor_type = obj_desc->field.attribute; if (accessor_type == AML_FIELD_ATTRIB_RAW_PROCESS_BYTES) { ACPI_ERROR((AE_INFO, "Invalid direct read using bidirectional write-then-read protocol")); return_ACPI_STATUS(AE_AML_PROTOCOL); } status = acpi_ex_get_protocol_buffer_length(accessor_type, &buffer_length); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Invalid protocol ID for GSBus: 0x%4.4X", accessor_type)); return_ACPI_STATUS(status); } /* Add header length to get the full size of the buffer */ buffer_length += ACPI_SERIAL_HEADER_SIZE; function = ACPI_READ | (accessor_type << 16); break; case ACPI_ADR_SPACE_PLATFORM_RT: buffer_length = ACPI_PRM_INPUT_BUFFER_SIZE; function = ACPI_READ; break; default: return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID); } /* Create the local transfer buffer that is returned to the caller */ buffer_desc = acpi_ut_create_buffer_object(buffer_length); if (!buffer_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* Call the region handler for the write-then-read */ status = acpi_ex_access_region(obj_desc, 0, ACPI_CAST_PTR(u64, buffer_desc->buffer. pointer), function); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); *return_buffer = buffer_desc; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_write_serial_bus * * PARAMETERS: source_desc - Contains data to write * obj_desc - The named field * return_buffer - Where the return value is returned, if any * * RETURN: Status * * DESCRIPTION: Write to a named field that references a serial bus * (SMBus, IPMI, GSBus). * ******************************************************************************/ acpi_status acpi_ex_write_serial_bus(union acpi_operand_object *source_desc, union acpi_operand_object *obj_desc, union acpi_operand_object **return_buffer) { acpi_status status; u32 buffer_length; u32 data_length; void *buffer; union acpi_operand_object *buffer_desc; u32 function; u16 accessor_type; ACPI_FUNCTION_TRACE_PTR(ex_write_serial_bus, obj_desc); /* * This is an SMBus, GSBus or IPMI write. We will bypass the entire * field mechanism and handoff the buffer directly to the handler. * For these address spaces, the buffer is bidirectional; on a * write, return data is returned in the same buffer. * * Source must be a buffer of sufficient size, these are fixed size: * ACPI_SMBUS_BUFFER_SIZE, or ACPI_IPMI_BUFFER_SIZE. * * Note: SMBus and GSBus protocol type is passed in upper 16-bits * of Function * * Common buffer format: * Status; (Byte 0 of the data buffer) * Length; (Byte 1 of the data buffer) * Data[x-1]: (Bytes 2-x of the arbitrary length data buffer) */ if (source_desc->common.type != ACPI_TYPE_BUFFER) { ACPI_ERROR((AE_INFO, "SMBus/IPMI/GenericSerialBus write requires " "Buffer, found type %s", acpi_ut_get_object_type_name(source_desc))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } switch (obj_desc->field.region_obj->region.space_id) { case ACPI_ADR_SPACE_SMBUS: buffer_length = ACPI_SMBUS_BUFFER_SIZE; function = ACPI_WRITE | (obj_desc->field.attribute << 16); break; case ACPI_ADR_SPACE_IPMI: buffer_length = ACPI_IPMI_BUFFER_SIZE; function = ACPI_WRITE; break; case ACPI_ADR_SPACE_GSBUS: accessor_type = obj_desc->field.attribute; status = acpi_ex_get_protocol_buffer_length(accessor_type, &buffer_length); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Invalid protocol ID for GSBus: 0x%4.4X", accessor_type)); return_ACPI_STATUS(status); } /* Add header length to get the full size of the buffer */ buffer_length += ACPI_SERIAL_HEADER_SIZE; function = ACPI_WRITE | (accessor_type << 16); break; case ACPI_ADR_SPACE_PLATFORM_RT: buffer_length = ACPI_PRM_INPUT_BUFFER_SIZE; function = ACPI_WRITE; break; case ACPI_ADR_SPACE_FIXED_HARDWARE: buffer_length = ACPI_FFH_INPUT_BUFFER_SIZE; function = ACPI_WRITE; break; default: return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID); } /* Create the transfer/bidirectional/return buffer */ buffer_desc = acpi_ut_create_buffer_object(buffer_length); if (!buffer_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Copy the input buffer data to the transfer buffer */ buffer = buffer_desc->buffer.pointer; data_length = ACPI_MIN(buffer_length, source_desc->buffer.length); memcpy(buffer, source_desc->buffer.pointer, data_length); /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* * Perform the write (returns status and perhaps data in the * same buffer) */ status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, function); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); *return_buffer = buffer_desc; return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exserial.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utlock - Reader/Writer lock interfaces * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utlock") /******************************************************************************* * * FUNCTION: acpi_ut_create_rw_lock * acpi_ut_delete_rw_lock * * PARAMETERS: lock - Pointer to a valid RW lock * * RETURN: Status * * DESCRIPTION: Reader/writer lock creation and deletion interfaces. * ******************************************************************************/ acpi_status acpi_ut_create_rw_lock(struct acpi_rw_lock *lock) { acpi_status status; lock->num_readers = 0; status = acpi_os_create_mutex(&lock->reader_mutex); if (ACPI_FAILURE(status)) { return (status); } status = acpi_os_create_mutex(&lock->writer_mutex); return (status); } void acpi_ut_delete_rw_lock(struct acpi_rw_lock *lock) { acpi_os_delete_mutex(lock->reader_mutex); acpi_os_delete_mutex(lock->writer_mutex); lock->num_readers = 0; lock->reader_mutex = NULL; lock->writer_mutex = NULL; } /******************************************************************************* * * FUNCTION: acpi_ut_acquire_read_lock * acpi_ut_release_read_lock * * PARAMETERS: lock - Pointer to a valid RW lock * * RETURN: Status * * DESCRIPTION: Reader interfaces for reader/writer locks. On acquisition, * only the first reader acquires the write mutex. On release, * only the last reader releases the write mutex. Although this * algorithm can in theory starve writers, this should not be a * problem with ACPICA since the subsystem is infrequently used * in comparison to (for example) an I/O system. * ******************************************************************************/ acpi_status acpi_ut_acquire_read_lock(struct acpi_rw_lock *lock) { acpi_status status; status = acpi_os_acquire_mutex(lock->reader_mutex, ACPI_WAIT_FOREVER); if (ACPI_FAILURE(status)) { return (status); } /* Acquire the write lock only for the first reader */ lock->num_readers++; if (lock->num_readers == 1) { status = acpi_os_acquire_mutex(lock->writer_mutex, ACPI_WAIT_FOREVER); } acpi_os_release_mutex(lock->reader_mutex); return (status); } acpi_status acpi_ut_release_read_lock(struct acpi_rw_lock *lock) { acpi_status status; status = acpi_os_acquire_mutex(lock->reader_mutex, ACPI_WAIT_FOREVER); if (ACPI_FAILURE(status)) { return (status); } /* Release the write lock only for the very last reader */ lock->num_readers--; if (lock->num_readers == 0) { acpi_os_release_mutex(lock->writer_mutex); } acpi_os_release_mutex(lock->reader_mutex); return (status); } /******************************************************************************* * * FUNCTION: acpi_ut_acquire_write_lock * acpi_ut_release_write_lock * * PARAMETERS: lock - Pointer to a valid RW lock * * RETURN: Status * * DESCRIPTION: Writer interfaces for reader/writer locks. Simply acquire or * release the writer mutex associated with the lock. Acquisition * of the lock is fully exclusive and will block all readers and * writers until it is released. * ******************************************************************************/ acpi_status acpi_ut_acquire_write_lock(struct acpi_rw_lock *lock) { acpi_status status; status = acpi_os_acquire_mutex(lock->writer_mutex, ACPI_WAIT_FOREVER); return (status); } void acpi_ut_release_write_lock(struct acpi_rw_lock *lock) { acpi_os_release_mutex(lock->writer_mutex); }
linux-master
drivers/acpi/acpica/utlock.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: psopcode - Parser/Interpreter opcode information table * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acopcode.h" #include "amlcode.h" #define _COMPONENT ACPI_PARSER ACPI_MODULE_NAME("psopcode") /******************************************************************************* * * NAME: acpi_gbl_aml_op_info * * DESCRIPTION: Opcode table. Each entry contains <opcode, type, name, operands> * The name is a simple ascii string, the operand specifier is an * ascii string with one letter per operand. The letter specifies * the operand type. * ******************************************************************************/ /* * Summary of opcode types/flags * Opcodes that have associated namespace objects (AML_NSOBJECT flag) AML_SCOPE_OP AML_DEVICE_OP AML_THERMAL_ZONE_OP AML_METHOD_OP AML_POWER_RESOURCE_OP AML_PROCESSOR_OP AML_FIELD_OP AML_INDEX_FIELD_OP AML_BANK_FIELD_OP AML_NAME_OP AML_ALIAS_OP AML_MUTEX_OP AML_EVENT_OP AML_REGION_OP AML_CREATE_FIELD_OP AML_CREATE_BIT_FIELD_OP AML_CREATE_BYTE_FIELD_OP AML_CREATE_WORD_FIELD_OP AML_CREATE_DWORD_FIELD_OP AML_CREATE_QWORD_FIELD_OP AML_INT_NAMEDFIELD_OP AML_INT_METHODCALL_OP AML_INT_NAMEPATH_OP Opcodes that are "namespace" opcodes (AML_NSOPCODE flag) AML_SCOPE_OP AML_DEVICE_OP AML_THERMAL_ZONE_OP AML_METHOD_OP AML_POWER_RESOURCE_OP AML_PROCESSOR_OP AML_FIELD_OP AML_INDEX_FIELD_OP AML_BANK_FIELD_OP AML_NAME_OP AML_ALIAS_OP AML_MUTEX_OP AML_EVENT_OP AML_REGION_OP AML_INT_NAMEDFIELD_OP Opcodes that have an associated namespace node (AML_NSNODE flag) AML_SCOPE_OP AML_DEVICE_OP AML_THERMAL_ZONE_OP AML_METHOD_OP AML_POWER_RESOURCE_OP AML_PROCESSOR_OP AML_NAME_OP AML_ALIAS_OP AML_MUTEX_OP AML_EVENT_OP AML_REGION_OP AML_CREATE_FIELD_OP AML_CREATE_BIT_FIELD_OP AML_CREATE_BYTE_FIELD_OP AML_CREATE_WORD_FIELD_OP AML_CREATE_DWORD_FIELD_OP AML_CREATE_QWORD_FIELD_OP AML_INT_NAMEDFIELD_OP AML_INT_METHODCALL_OP AML_INT_NAMEPATH_OP Opcodes that define named ACPI objects (AML_NAMED flag) AML_SCOPE_OP AML_DEVICE_OP AML_THERMAL_ZONE_OP AML_METHOD_OP AML_POWER_RESOURCE_OP AML_PROCESSOR_OP AML_NAME_OP AML_ALIAS_OP AML_MUTEX_OP AML_EVENT_OP AML_REGION_OP AML_INT_NAMEDFIELD_OP Opcodes that contain executable AML as part of the definition that must be deferred until needed AML_METHOD_OP AML_VARIABLE_PACKAGE_OP AML_CREATE_FIELD_OP AML_CREATE_BIT_FIELD_OP AML_CREATE_BYTE_FIELD_OP AML_CREATE_WORD_FIELD_OP AML_CREATE_DWORD_FIELD_OP AML_CREATE_QWORD_FIELD_OP AML_REGION_OP AML_BUFFER_OP Field opcodes AML_CREATE_FIELD_OP AML_FIELD_OP AML_INDEX_FIELD_OP AML_BANK_FIELD_OP Field "Create" opcodes AML_CREATE_FIELD_OP AML_CREATE_BIT_FIELD_OP AML_CREATE_BYTE_FIELD_OP AML_CREATE_WORD_FIELD_OP AML_CREATE_DWORD_FIELD_OP AML_CREATE_QWORD_FIELD_OP ******************************************************************************/ /* * Master Opcode information table. A summary of everything we know about each * opcode, all in one place. */ const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES] = { /*! [Begin] no source code translation */ /* Index Name Parser Args Interpreter Args ObjectType Class Type Flags */ /* 00 */ ACPI_OP("Zero", ARGP_ZERO_OP, ARGI_ZERO_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT), /* 01 */ ACPI_OP("One", ARGP_ONE_OP, ARGI_ONE_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT), /* 02 */ ACPI_OP("Alias", ARGP_ALIAS_OP, ARGI_ALIAS_OP, ACPI_TYPE_LOCAL_ALIAS, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 03 */ ACPI_OP("Name", ARGP_NAME_OP, ARGI_NAME_OP, ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_COMPLEX, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 04 */ ACPI_OP("ByteConst", ARGP_BYTE_OP, ARGI_BYTE_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT), /* 05 */ ACPI_OP("WordConst", ARGP_WORD_OP, ARGI_WORD_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT), /* 06 */ ACPI_OP("DwordConst", ARGP_DWORD_OP, ARGI_DWORD_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT), /* 07 */ ACPI_OP("String", ARGP_STRING_OP, ARGI_STRING_OP, ACPI_TYPE_STRING, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT), /* 08 */ ACPI_OP("Scope", ARGP_SCOPE_OP, ARGI_SCOPE_OP, ACPI_TYPE_LOCAL_SCOPE, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_NO_OBJ, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 09 */ ACPI_OP("Buffer", ARGP_BUFFER_OP, ARGI_BUFFER_OP, ACPI_TYPE_BUFFER, AML_CLASS_CREATE, AML_TYPE_CREATE_OBJECT, AML_HAS_ARGS | AML_DEFER | AML_CONSTANT), /* 0A */ ACPI_OP("Package", ARGP_PACKAGE_OP, ARGI_PACKAGE_OP, ACPI_TYPE_PACKAGE, AML_CLASS_CREATE, AML_TYPE_CREATE_OBJECT, AML_HAS_ARGS | AML_DEFER | AML_CONSTANT), /* 0B */ ACPI_OP("Method", ARGP_METHOD_OP, ARGI_METHOD_OP, ACPI_TYPE_METHOD, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_COMPLEX, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED | AML_DEFER), /* 0C */ ACPI_OP("Local0", ARGP_LOCAL0, ARGI_LOCAL0, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LOCAL_VARIABLE, 0), /* 0D */ ACPI_OP("Local1", ARGP_LOCAL1, ARGI_LOCAL1, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LOCAL_VARIABLE, 0), /* 0E */ ACPI_OP("Local2", ARGP_LOCAL2, ARGI_LOCAL2, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LOCAL_VARIABLE, 0), /* 0F */ ACPI_OP("Local3", ARGP_LOCAL3, ARGI_LOCAL3, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LOCAL_VARIABLE, 0), /* 10 */ ACPI_OP("Local4", ARGP_LOCAL4, ARGI_LOCAL4, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LOCAL_VARIABLE, 0), /* 11 */ ACPI_OP("Local5", ARGP_LOCAL5, ARGI_LOCAL5, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LOCAL_VARIABLE, 0), /* 12 */ ACPI_OP("Local6", ARGP_LOCAL6, ARGI_LOCAL6, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LOCAL_VARIABLE, 0), /* 13 */ ACPI_OP("Local7", ARGP_LOCAL7, ARGI_LOCAL7, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LOCAL_VARIABLE, 0), /* 14 */ ACPI_OP("Arg0", ARGP_ARG0, ARGI_ARG0, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_METHOD_ARGUMENT, 0), /* 15 */ ACPI_OP("Arg1", ARGP_ARG1, ARGI_ARG1, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_METHOD_ARGUMENT, 0), /* 16 */ ACPI_OP("Arg2", ARGP_ARG2, ARGI_ARG2, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_METHOD_ARGUMENT, 0), /* 17 */ ACPI_OP("Arg3", ARGP_ARG3, ARGI_ARG3, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_METHOD_ARGUMENT, 0), /* 18 */ ACPI_OP("Arg4", ARGP_ARG4, ARGI_ARG4, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_METHOD_ARGUMENT, 0), /* 19 */ ACPI_OP("Arg5", ARGP_ARG5, ARGI_ARG5, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_METHOD_ARGUMENT, 0), /* 1A */ ACPI_OP("Arg6", ARGP_ARG6, ARGI_ARG6, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_METHOD_ARGUMENT, 0), /* 1B */ ACPI_OP("Store", ARGP_STORE_OP, ARGI_STORE_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R), /* 1C */ ACPI_OP("RefOf", ARGP_REF_OF_OP, ARGI_REF_OF_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R), /* 1D */ ACPI_OP("Add", ARGP_ADD_OP, ARGI_ADD_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 1E */ ACPI_OP("Concatenate", ARGP_CONCAT_OP, ARGI_CONCAT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT), /* 1F */ ACPI_OP("Subtract", ARGP_SUBTRACT_OP, ARGI_SUBTRACT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 20 */ ACPI_OP("Increment", ARGP_INCREMENT_OP, ARGI_INCREMENT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT), /* 21 */ ACPI_OP("Decrement", ARGP_DECREMENT_OP, ARGI_DECREMENT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT), /* 22 */ ACPI_OP("Multiply", ARGP_MULTIPLY_OP, ARGI_MULTIPLY_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 23 */ ACPI_OP("Divide", ARGP_DIVIDE_OP, ARGI_DIVIDE_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_2T_1R, AML_FLAGS_EXEC_2A_2T_1R | AML_CONSTANT), /* 24 */ ACPI_OP("ShiftLeft", ARGP_SHIFT_LEFT_OP, ARGI_SHIFT_LEFT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 25 */ ACPI_OP("ShiftRight", ARGP_SHIFT_RIGHT_OP, ARGI_SHIFT_RIGHT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 26 */ ACPI_OP("And", ARGP_BIT_AND_OP, ARGI_BIT_AND_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 27 */ ACPI_OP("NAnd", ARGP_BIT_NAND_OP, ARGI_BIT_NAND_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 28 */ ACPI_OP("Or", ARGP_BIT_OR_OP, ARGI_BIT_OR_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 29 */ ACPI_OP("NOr", ARGP_BIT_NOR_OP, ARGI_BIT_NOR_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 2A */ ACPI_OP("XOr", ARGP_BIT_XOR_OP, ARGI_BIT_XOR_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), /* 2B */ ACPI_OP("Not", ARGP_BIT_NOT_OP, ARGI_BIT_NOT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 2C */ ACPI_OP("FindSetLeftBit", ARGP_FIND_SET_LEFT_BIT_OP, ARGI_FIND_SET_LEFT_BIT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 2D */ ACPI_OP("FindSetRightBit", ARGP_FIND_SET_RIGHT_BIT_OP, ARGI_FIND_SET_RIGHT_BIT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 2E */ ACPI_OP("DerefOf", ARGP_DEREF_OF_OP, ARGI_DEREF_OF_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R), /* 2F */ ACPI_OP("Notify", ARGP_NOTIFY_OP, ARGI_NOTIFY_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_0R, AML_FLAGS_EXEC_2A_0T_0R), /* 30 */ ACPI_OP("SizeOf", ARGP_SIZE_OF_OP, ARGI_SIZE_OF_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R | AML_NO_OPERAND_RESOLVE), /* 31 */ ACPI_OP("Index", ARGP_INDEX_OP, ARGI_INDEX_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R), /* 32 */ ACPI_OP("Match", ARGP_MATCH_OP, ARGI_MATCH_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_6A_0T_1R, AML_FLAGS_EXEC_6A_0T_1R | AML_CONSTANT), /* 33 */ ACPI_OP("CreateDWordField", ARGP_CREATE_DWORD_FIELD_OP, ARGI_CREATE_DWORD_FIELD_OP, ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, AML_TYPE_CREATE_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | AML_DEFER | AML_CREATE), /* 34 */ ACPI_OP("CreateWordField", ARGP_CREATE_WORD_FIELD_OP, ARGI_CREATE_WORD_FIELD_OP, ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, AML_TYPE_CREATE_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | AML_DEFER | AML_CREATE), /* 35 */ ACPI_OP("CreateByteField", ARGP_CREATE_BYTE_FIELD_OP, ARGI_CREATE_BYTE_FIELD_OP, ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, AML_TYPE_CREATE_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | AML_DEFER | AML_CREATE), /* 36 */ ACPI_OP("CreateBitField", ARGP_CREATE_BIT_FIELD_OP, ARGI_CREATE_BIT_FIELD_OP, ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, AML_TYPE_CREATE_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | AML_DEFER | AML_CREATE), /* 37 */ ACPI_OP("ObjectType", ARGP_OBJECT_TYPE_OP, ARGI_OBJECT_TYPE_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R | AML_NO_OPERAND_RESOLVE), /* 38 */ ACPI_OP("LAnd", ARGP_LAND_OP, ARGI_LAND_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL_NUMERIC | AML_CONSTANT), /* 39 */ ACPI_OP("LOr", ARGP_LOR_OP, ARGI_LOR_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL_NUMERIC | AML_CONSTANT), /* 3A */ ACPI_OP("LNot", ARGP_LNOT_OP, ARGI_LNOT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT), /* 3B */ ACPI_OP("LEqual", ARGP_LEQUAL_OP, ARGI_LEQUAL_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT), /* 3C */ ACPI_OP("LGreater", ARGP_LGREATER_OP, ARGI_LGREATER_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT), /* 3D */ ACPI_OP("LLess", ARGP_LLESS_OP, ARGI_LLESS_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT), /* 3E */ ACPI_OP("If", ARGP_IF_OP, ARGI_IF_OP, ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS), /* 3F */ ACPI_OP("Else", ARGP_ELSE_OP, ARGI_ELSE_OP, ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS), /* 40 */ ACPI_OP("While", ARGP_WHILE_OP, ARGI_WHILE_OP, ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS), /* 41 */ ACPI_OP("Noop", ARGP_NOOP_OP, ARGI_NOOP_OP, ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0), /* 42 */ ACPI_OP("Return", ARGP_RETURN_OP, ARGI_RETURN_OP, ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS), /* 43 */ ACPI_OP("Break", ARGP_BREAK_OP, ARGI_BREAK_OP, ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0), /* 44 */ ACPI_OP("BreakPoint", ARGP_BREAK_POINT_OP, ARGI_BREAK_POINT_OP, ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0), /* 45 */ ACPI_OP("Ones", ARGP_ONES_OP, ARGI_ONES_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT), /* Prefixed opcodes (Two-byte opcodes with a prefix op) */ /* 46 */ ACPI_OP("Mutex", ARGP_MUTEX_OP, ARGI_MUTEX_OP, ACPI_TYPE_MUTEX, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 47 */ ACPI_OP("Event", ARGP_EVENT_OP, ARGI_EVENT_OP, ACPI_TYPE_EVENT, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 48 */ ACPI_OP("CondRefOf", ARGP_COND_REF_OF_OP, ARGI_COND_REF_OF_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R), /* 49 */ ACPI_OP("CreateField", ARGP_CREATE_FIELD_OP, ARGI_CREATE_FIELD_OP, ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, AML_TYPE_CREATE_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | AML_DEFER | AML_FIELD | AML_CREATE), /* 4A */ ACPI_OP("Load", ARGP_LOAD_OP, ARGI_LOAD_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R), /* 4B */ ACPI_OP("Stall", ARGP_STALL_OP, ARGI_STALL_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), /* 4C */ ACPI_OP("Sleep", ARGP_SLEEP_OP, ARGI_SLEEP_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), /* 4D */ ACPI_OP("Acquire", ARGP_ACQUIRE_OP, ARGI_ACQUIRE_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R), /* 4E */ ACPI_OP("Signal", ARGP_SIGNAL_OP, ARGI_SIGNAL_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), /* 4F */ ACPI_OP("Wait", ARGP_WAIT_OP, ARGI_WAIT_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R), /* 50 */ ACPI_OP("Reset", ARGP_RESET_OP, ARGI_RESET_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), /* 51 */ ACPI_OP("Release", ARGP_RELEASE_OP, ARGI_RELEASE_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), /* 52 */ ACPI_OP("FromBCD", ARGP_FROM_BCD_OP, ARGI_FROM_BCD_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 53 */ ACPI_OP("ToBCD", ARGP_TO_BCD_OP, ARGI_TO_BCD_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 54 */ ACPI_OP("Unload", ARGP_UNLOAD_OP, ARGI_UNLOAD_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), /* 55 */ ACPI_OP("Revision", ARGP_REVISION_OP, ARGI_REVISION_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, 0), /* 56 */ ACPI_OP("Debug", ARGP_DEBUG_OP, ARGI_DEBUG_OP, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, 0), /* 57 */ ACPI_OP("Fatal", ARGP_FATAL_OP, ARGI_FATAL_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_3A_0T_0R, AML_FLAGS_EXEC_3A_0T_0R), /* 58 */ ACPI_OP("OperationRegion", ARGP_REGION_OP, ARGI_REGION_OP, ACPI_TYPE_REGION, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_COMPLEX, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED | AML_DEFER), /* 59 */ ACPI_OP("Field", ARGP_FIELD_OP, ARGI_FIELD_OP, ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD), /* 5A */ ACPI_OP("Device", ARGP_DEVICE_OP, ARGI_DEVICE_OP, ACPI_TYPE_DEVICE, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_NO_OBJ, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 5B */ ACPI_OP("Processor", ARGP_PROCESSOR_OP, ARGI_PROCESSOR_OP, ACPI_TYPE_PROCESSOR, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 5C */ ACPI_OP("PowerResource", ARGP_POWER_RES_OP, ARGI_POWER_RES_OP, ACPI_TYPE_POWER, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 5D */ ACPI_OP("ThermalZone", ARGP_THERMAL_ZONE_OP, ARGI_THERMAL_ZONE_OP, ACPI_TYPE_THERMAL, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_NO_OBJ, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 5E */ ACPI_OP("IndexField", ARGP_INDEX_FIELD_OP, ARGI_INDEX_FIELD_OP, ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD), /* 5F */ ACPI_OP("BankField", ARGP_BANK_FIELD_OP, ARGI_BANK_FIELD_OP, ACPI_TYPE_LOCAL_BANK_FIELD, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD | AML_DEFER), /* Internal opcodes that map to invalid AML opcodes */ /* 60 */ ACPI_OP("LNotEqual", ARGP_LNOTEQUAL_OP, ARGI_LNOTEQUAL_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, AML_HAS_ARGS | AML_CONSTANT), /* 61 */ ACPI_OP("LLessEqual", ARGP_LLESSEQUAL_OP, ARGI_LLESSEQUAL_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, AML_HAS_ARGS | AML_CONSTANT), /* 62 */ ACPI_OP("LGreaterEqual", ARGP_LGREATEREQUAL_OP, ARGI_LGREATEREQUAL_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, AML_HAS_ARGS | AML_CONSTANT), /* 63 */ ACPI_OP("-NamePath-", ARGP_NAMEPATH_OP, ARGI_NAMEPATH_OP, ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_NSOBJECT | AML_NSNODE), /* 64 */ ACPI_OP("-MethodCall-", ARGP_METHODCALL_OP, ARGI_METHODCALL_OP, ACPI_TYPE_METHOD, AML_CLASS_METHOD_CALL, AML_TYPE_METHOD_CALL, AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE), /* 65 */ ACPI_OP("-ByteList-", ARGP_BYTELIST_OP, ARGI_BYTELIST_OP, ACPI_TYPE_ANY, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, 0), /* 66 */ ACPI_OP("-ReservedField-", ARGP_RESERVEDFIELD_OP, ARGI_RESERVEDFIELD_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0), /* 67 */ ACPI_OP("-NamedField-", ARGP_NAMEDFIELD_OP, ARGI_NAMEDFIELD_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 68 */ ACPI_OP("-AccessField-", ARGP_ACCESSFIELD_OP, ARGI_ACCESSFIELD_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0), /* 69 */ ACPI_OP("-StaticString", ARGP_STATICSTRING_OP, ARGI_STATICSTRING_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0), /* 6A */ ACPI_OP("-Return Value-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY, AML_CLASS_RETURN_VALUE, AML_TYPE_RETURN, AML_HAS_ARGS | AML_HAS_RETVAL), /* 6B */ ACPI_OP("-UNKNOWN_OP-", ARG_NONE, ARG_NONE, ACPI_TYPE_INVALID, AML_CLASS_UNKNOWN, AML_TYPE_BOGUS, AML_HAS_ARGS), /* 6C */ ACPI_OP("-ASCII_ONLY-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY, AML_CLASS_ASCII, AML_TYPE_BOGUS, AML_HAS_ARGS), /* 6D */ ACPI_OP("-PREFIX_ONLY-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY, AML_CLASS_PREFIX, AML_TYPE_BOGUS, AML_HAS_ARGS), /* ACPI 2.0 opcodes */ /* 6E */ ACPI_OP("QwordConst", ARGP_QWORD_OP, ARGI_QWORD_OP, ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT), /* 6F */ ACPI_OP("Package", /* Var */ ARGP_VAR_PACKAGE_OP, ARGI_VAR_PACKAGE_OP, ACPI_TYPE_PACKAGE, AML_CLASS_CREATE, AML_TYPE_CREATE_OBJECT, AML_HAS_ARGS | AML_DEFER), /* 70 */ ACPI_OP("ConcatenateResTemplate", ARGP_CONCAT_RES_OP, ARGI_CONCAT_RES_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT), /* 71 */ ACPI_OP("Mod", ARGP_MOD_OP, ARGI_MOD_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT), /* 72 */ ACPI_OP("CreateQWordField", ARGP_CREATE_QWORD_FIELD_OP, ARGI_CREATE_QWORD_FIELD_OP, ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, AML_TYPE_CREATE_FIELD, AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | AML_DEFER | AML_CREATE), /* 73 */ ACPI_OP("ToBuffer", ARGP_TO_BUFFER_OP, ARGI_TO_BUFFER_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 74 */ ACPI_OP("ToDecimalString", ARGP_TO_DEC_STR_OP, ARGI_TO_DEC_STR_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 75 */ ACPI_OP("ToHexString", ARGP_TO_HEX_STR_OP, ARGI_TO_HEX_STR_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 76 */ ACPI_OP("ToInteger", ARGP_TO_INTEGER_OP, ARGI_TO_INTEGER_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), /* 77 */ ACPI_OP("ToString", ARGP_TO_STRING_OP, ARGI_TO_STRING_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT), /* 78 */ ACPI_OP("CopyObject", ARGP_COPY_OP, ARGI_COPY_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R), /* 79 */ ACPI_OP("Mid", ARGP_MID_OP, ARGI_MID_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_3A_1T_1R, AML_FLAGS_EXEC_3A_1T_1R | AML_CONSTANT), /* 7A */ ACPI_OP("Continue", ARGP_CONTINUE_OP, ARGI_CONTINUE_OP, ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0), /* 7B */ ACPI_OP("LoadTable", ARGP_LOAD_TABLE_OP, ARGI_LOAD_TABLE_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_6A_0T_1R, AML_FLAGS_EXEC_6A_0T_1R), /* 7C */ ACPI_OP("DataTableRegion", ARGP_DATA_REGION_OP, ARGI_DATA_REGION_OP, ACPI_TYPE_REGION, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_COMPLEX, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED | AML_DEFER), /* 7D */ ACPI_OP("[EvalSubTree]", ARGP_SCOPE_OP, ARGI_SCOPE_OP, ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_NO_OBJ, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE), /* ACPI 3.0 opcodes */ /* 7E */ ACPI_OP("Timer", ARGP_TIMER_OP, ARGI_TIMER_OP, ACPI_TYPE_ANY, AML_CLASS_EXECUTE, AML_TYPE_EXEC_0A_0T_1R, AML_FLAGS_EXEC_0A_0T_1R | AML_NO_OPERAND_RESOLVE), /* ACPI 5.0 opcodes */ /* 7F */ ACPI_OP("-ConnectField-", ARGP_CONNECTFIELD_OP, ARGI_CONNECTFIELD_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, AML_HAS_ARGS), /* 80 */ ACPI_OP("-ExtAccessField-", ARGP_CONNECTFIELD_OP, ARGI_CONNECTFIELD_OP, ACPI_TYPE_ANY, AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0), /* ACPI 6.0 opcodes */ /* 81 */ ACPI_OP("External", ARGP_EXTERNAL_OP, ARGI_EXTERNAL_OP, ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), /* 82 */ ACPI_OP("Comment", ARGP_COMMENT_OP, ARGI_COMMENT_OP, ACPI_TYPE_STRING, AML_CLASS_ARGUMENT, AML_TYPE_LITERAL, AML_CONSTANT) /*! [End] no source code translation !*/ };
linux-master
drivers/acpi/acpica/psopcode.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dsinit - Object initialization namespace walk * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdispat.h" #include "acnamesp.h" #include "actables.h" #include "acinterp.h" #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dsinit") /* Local prototypes */ static acpi_status acpi_ds_init_one_object(acpi_handle obj_handle, u32 level, void *context, void **return_value); /******************************************************************************* * * FUNCTION: acpi_ds_init_one_object * * PARAMETERS: obj_handle - Node for the object * level - Current nesting level * context - Points to a init info struct * return_value - Not used * * RETURN: Status * * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object * within the namespace. * * Currently, the only objects that require initialization are: * 1) Methods * 2) Operation Regions * ******************************************************************************/ static acpi_status acpi_ds_init_one_object(acpi_handle obj_handle, u32 level, void *context, void **return_value) { struct acpi_init_walk_info *info = (struct acpi_init_walk_info *)context; struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; acpi_status status; union acpi_operand_object *obj_desc; ACPI_FUNCTION_ENTRY(); /* * We are only interested in NS nodes owned by the table that * was just loaded */ if (node->owner_id != info->owner_id) { return (AE_OK); } info->object_count++; /* And even then, we are only interested in a few object types */ switch (acpi_ns_get_type(obj_handle)) { case ACPI_TYPE_REGION: status = acpi_ds_initialize_region(obj_handle); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "During Region initialization %p [%4.4s]", obj_handle, acpi_ut_get_node_name(obj_handle))); } info->op_region_count++; break; case ACPI_TYPE_METHOD: /* * Auto-serialization support. We will examine each method that is * not_serialized to determine if it creates any Named objects. If * it does, it will be marked serialized to prevent problems if * the method is entered by two or more threads and an attempt is * made to create the same named object twice -- which results in * an AE_ALREADY_EXISTS exception and method abort. */ info->method_count++; obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { break; } /* Ignore if already serialized */ if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) { info->serial_method_count++; break; } if (acpi_gbl_auto_serialize_methods) { /* Parse/scan method and serialize it if necessary */ acpi_ds_auto_serialize_method(node, obj_desc); if (obj_desc->method. info_flags & ACPI_METHOD_SERIALIZED) { /* Method was just converted to Serialized */ info->serial_method_count++; info->serialized_method_count++; break; } } info->non_serial_method_count++; break; case ACPI_TYPE_DEVICE: info->device_count++; break; default: break; } /* * We ignore errors from above, and always return OK, since * we don't want to abort the walk on a single error. */ return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_initialize_objects * * PARAMETERS: table_desc - Descriptor for parent ACPI table * start_node - Root of subtree to be initialized. * * RETURN: Status * * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any * necessary initialization on the objects found therein * ******************************************************************************/ acpi_status acpi_ds_initialize_objects(u32 table_index, struct acpi_namespace_node *start_node) { acpi_status status; struct acpi_init_walk_info info; struct acpi_table_header *table; acpi_owner_id owner_id; ACPI_FUNCTION_TRACE(ds_initialize_objects); status = acpi_tb_get_owner_id(table_index, &owner_id); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "**** Starting initialization of namespace objects ****\n")); /* Set all init info to zero */ memset(&info, 0, sizeof(struct acpi_init_walk_info)); info.owner_id = owner_id; info.table_index = table_index; /* Walk entire namespace from the supplied root */ /* * We don't use acpi_walk_namespace since we do not want to acquire * the namespace reader lock. */ status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, acpi_ds_init_one_object, NULL, &info, NULL); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); } status = acpi_get_table_by_index(table_index, &table); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* DSDT is always the first AML table */ if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_DSDT)) { ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "\nACPI table initialization:\n")); } /* Summary of objects initialized */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, " "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n", table->signature, table->oem_table_id, owner_id, info.object_count, info.device_count, info.op_region_count, info.method_count, info.serial_method_count, info.non_serial_method_count, info.serialized_method_count)); ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n", info.method_count, info.op_region_count)); return_ACPI_STATUS(AE_OK); }
linux-master
drivers/acpi/acpica/dsinit.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nspredef - Validation of ACPI predefined methods and objects * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define ACPI_CREATE_PREDEFINED_TABLE #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acpredef.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nspredef") /******************************************************************************* * * This module validates predefined ACPI objects that appear in the namespace, * at the time they are evaluated (via acpi_evaluate_object). The purpose of this * validation is to detect problems with BIOS-exposed predefined ACPI objects * before the results are returned to the ACPI-related drivers. * * There are several areas that are validated: * * 1) The number of input arguments as defined by the method/object in the * ASL is validated against the ACPI specification. * 2) The type of the return object (if any) is validated against the ACPI * specification. * 3) For returned package objects, the count of package elements is * validated, as well as the type of each package element. Nested * packages are supported. * * For any problems found, a warning message is issued. * ******************************************************************************/ /* Local prototypes */ static acpi_status acpi_ns_check_reference(struct acpi_evaluate_info *info, union acpi_operand_object *return_object); static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object); /******************************************************************************* * * FUNCTION: acpi_ns_check_return_value * * PARAMETERS: node - Namespace node for the method/object * info - Method execution information block * user_param_count - Number of parameters actually passed * return_status - Status from the object evaluation * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * * RETURN: Status * * DESCRIPTION: Check the value returned from a predefined name. * ******************************************************************************/ acpi_status acpi_ns_check_return_value(struct acpi_namespace_node *node, struct acpi_evaluate_info *info, u32 user_param_count, acpi_status return_status, union acpi_operand_object **return_object_ptr) { acpi_status status; const union acpi_predefined_info *predefined; ACPI_FUNCTION_TRACE(ns_check_return_value); /* If not a predefined name, we cannot validate the return object */ predefined = info->predefined; if (!predefined) { return_ACPI_STATUS(AE_OK); } /* * If the method failed or did not actually return an object, we cannot * validate the return object */ if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) { return_ACPI_STATUS(AE_OK); } /* * Return value validation and possible repair. * * 1) Don't perform return value validation/repair if this feature * has been disabled via a global option. * * 2) We have a return value, but if one wasn't expected, just exit, * this is not a problem. For example, if the "Implicit Return" * feature is enabled, methods will always return a value. * * 3) If the return value can be of any type, then we cannot perform * any validation, just exit. */ if (acpi_gbl_disable_auto_repair || (!predefined->info.expected_btypes) || (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) { return_ACPI_STATUS(AE_OK); } /* * Check that the type of the main return object is what is expected * for this predefined name */ status = acpi_ns_check_object_type(info, return_object_ptr, predefined->info.expected_btypes, ACPI_NOT_PACKAGE_ELEMENT); if (ACPI_FAILURE(status)) { goto exit; } /* * * 4) If there is no return value and it is optional, just return * AE_OK (_WAK). */ if (!(*return_object_ptr)) { goto exit; } /* * For returned Package objects, check the type of all sub-objects. * Note: Package may have been newly created by call above. */ if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) { info->parent_package = *return_object_ptr; status = acpi_ns_check_package(info, return_object_ptr); if (ACPI_FAILURE(status)) { /* We might be able to fix some errors */ if ((status != AE_AML_OPERAND_TYPE) && (status != AE_AML_OPERAND_VALUE)) { goto exit; } } } /* * The return object was OK, or it was successfully repaired above. * Now make some additional checks such as verifying that package * objects are sorted correctly (if required) or buffer objects have * the correct data width (bytes vs. dwords). These repairs are * performed on a per-name basis, i.e., the code is specific to * particular predefined names. */ status = acpi_ns_complex_repairs(info, node, status, return_object_ptr); exit: /* * If the object validation failed or if we successfully repaired one * or more objects, mark the parent node to suppress further warning * messages during the next evaluation of the same method/object. */ if (ACPI_FAILURE(status) || (info->return_flags & ACPI_OBJECT_REPAIRED)) { node->flags |= ANOBJ_EVALUATED; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ns_check_object_type * * PARAMETERS: info - Method execution information block * return_object_ptr - Pointer to the object returned from the * evaluation of a method or object * expected_btypes - Bitmap of expected return type(s) * package_index - Index of object within parent package (if * applicable - ACPI_NOT_PACKAGE_ELEMENT * otherwise) * * RETURN: Status * * DESCRIPTION: Check the type of the return object against the expected object * type(s). Use of Btype allows multiple expected object types. * ******************************************************************************/ acpi_status acpi_ns_check_object_type(struct acpi_evaluate_info *info, union acpi_operand_object **return_object_ptr, u32 expected_btypes, u32 package_index) { union acpi_operand_object *return_object = *return_object_ptr; acpi_status status = AE_OK; char type_buffer[96]; /* Room for 10 types */ /* A Namespace node should not get here, but make sure */ if (return_object && ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "Invalid return type - Found a Namespace node [%4.4s] type %s", return_object->node.name.ascii, acpi_ut_get_type_name(return_object->node. type))); return (AE_AML_OPERAND_TYPE); } /* * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. * The bitmapped type allows multiple possible return types. * * Note, the cases below must handle all of the possible types returned * from all of the predefined names (including elements of returned * packages) */ info->return_btype = acpi_ns_get_bitmapped_type(return_object); if (info->return_btype == ACPI_RTYPE_ANY) { /* Not one of the supported objects, must be incorrect */ goto type_error_exit; } /* For reference objects, check that the reference type is correct */ if ((info->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) { status = acpi_ns_check_reference(info, return_object); return (status); } /* Attempt simple repair of the returned object if necessary */ status = acpi_ns_simple_repair(info, expected_btypes, package_index, return_object_ptr); if (ACPI_SUCCESS(status)) { return (AE_OK); /* Successful repair */ } type_error_exit: /* Create a string with all expected types for this predefined object */ acpi_ut_get_expected_return_types(type_buffer, expected_btypes); if (!return_object) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "Expected return object of type %s", type_buffer)); } else if (package_index == ACPI_NOT_PACKAGE_ELEMENT) { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "Return type mismatch - found %s, expected %s", acpi_ut_get_object_type_name (return_object), type_buffer)); } else { ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "Return Package type mismatch at index %u - " "found %s, expected %s", package_index, acpi_ut_get_object_type_name (return_object), type_buffer)); } return (AE_AML_OPERAND_TYPE); } /******************************************************************************* * * FUNCTION: acpi_ns_check_reference * * PARAMETERS: info - Method execution information block * return_object - Object returned from the evaluation of a * method or object * * RETURN: Status * * DESCRIPTION: Check a returned reference object for the correct reference * type. The only reference type that can be returned from a * predefined method is a named reference. All others are invalid. * ******************************************************************************/ static acpi_status acpi_ns_check_reference(struct acpi_evaluate_info *info, union acpi_operand_object *return_object) { /* * Check the reference object for the correct reference type (opcode). * The only type of reference that can be converted to a union acpi_object is * a reference to a named object (reference class: NAME) */ if (return_object->reference.class == ACPI_REFCLASS_NAME) { return (AE_OK); } ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags, "Return type mismatch - unexpected reference object type [%s] %2.2X", acpi_ut_get_reference_name(return_object), return_object->reference.class)); return (AE_AML_OPERAND_TYPE); } /******************************************************************************* * * FUNCTION: acpi_ns_get_bitmapped_type * * PARAMETERS: return_object - Object returned from method/obj evaluation * * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object * type is not supported. ACPI_RTYPE_NONE indicates that no * object was returned (return_object is NULL). * * DESCRIPTION: Convert object type into a bitmapped object return type. * ******************************************************************************/ static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object) { u32 return_btype; if (!return_object) { return (ACPI_RTYPE_NONE); } /* Map acpi_object_type to internal bitmapped type */ switch (return_object->common.type) { case ACPI_TYPE_INTEGER: return_btype = ACPI_RTYPE_INTEGER; break; case ACPI_TYPE_BUFFER: return_btype = ACPI_RTYPE_BUFFER; break; case ACPI_TYPE_STRING: return_btype = ACPI_RTYPE_STRING; break; case ACPI_TYPE_PACKAGE: return_btype = ACPI_RTYPE_PACKAGE; break; case ACPI_TYPE_LOCAL_REFERENCE: return_btype = ACPI_RTYPE_REFERENCE; break; default: /* Not one of the supported objects, must be incorrect */ return_btype = ACPI_RTYPE_ANY; break; } return (return_btype); }
linux-master
drivers/acpi/acpica/nspredef.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dsfield - Dispatcher field routines * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "amlcode.h" #include "acdispat.h" #include "acinterp.h" #include "acnamesp.h" #include "acparser.h" #ifdef ACPI_EXEC_APP #include "aecommon.h" #endif #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dsfield") /* Local prototypes */ #ifdef ACPI_ASL_COMPILER #include "acdisasm.h" static acpi_status acpi_ds_create_external_region(acpi_status lookup_status, union acpi_parse_object *op, char *path, struct acpi_walk_state *walk_state, struct acpi_namespace_node **node); #endif static acpi_status acpi_ds_get_field_names(struct acpi_create_field_info *info, struct acpi_walk_state *walk_state, union acpi_parse_object *arg); #ifdef ACPI_ASL_COMPILER /******************************************************************************* * * FUNCTION: acpi_ds_create_external_region (iASL Disassembler only) * * PARAMETERS: lookup_status - Status from ns_lookup operation * op - Op containing the Field definition and args * path - Pathname of the region * ` walk_state - Current method state * node - Where the new region node is returned * * RETURN: Status * * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new * region node/object. * ******************************************************************************/ static acpi_status acpi_ds_create_external_region(acpi_status lookup_status, union acpi_parse_object *op, char *path, struct acpi_walk_state *walk_state, struct acpi_namespace_node **node) { acpi_status status; union acpi_operand_object *obj_desc; if (lookup_status != AE_NOT_FOUND) { return (lookup_status); } /* * Table disassembly: * operation_region not found. Generate an External for it, and * insert the name into the namespace. */ acpi_dm_add_op_to_external_list(op, path, ACPI_TYPE_REGION, 0, 0); status = acpi_ns_lookup(walk_state->scope_info, path, ACPI_TYPE_REGION, ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, walk_state, node); if (ACPI_FAILURE(status)) { return (status); } /* Must create and install a region object for the new node */ obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION); if (!obj_desc) { return (AE_NO_MEMORY); } obj_desc->region.node = *node; status = acpi_ns_attach_object(*node, obj_desc, ACPI_TYPE_REGION); return (status); } #endif /******************************************************************************* * * FUNCTION: acpi_ds_create_buffer_field * * PARAMETERS: op - Current parse op (create_XXField) * walk_state - Current state * * RETURN: Status * * DESCRIPTION: Execute the create_field operators: * create_bit_field_op, * create_byte_field_op, * create_word_field_op, * create_dword_field_op, * create_qword_field_op, * create_field_op (all of which define a field in a buffer) * ******************************************************************************/ acpi_status acpi_ds_create_buffer_field(union acpi_parse_object *op, struct acpi_walk_state *walk_state) { union acpi_parse_object *arg; struct acpi_namespace_node *node; acpi_status status; union acpi_operand_object *obj_desc; union acpi_operand_object *second_desc = NULL; u32 flags; ACPI_FUNCTION_TRACE(ds_create_buffer_field); /* * Get the name_string argument (name of the new buffer_field) */ if (op->common.aml_opcode == AML_CREATE_FIELD_OP) { /* For create_field, name is the 4th argument */ arg = acpi_ps_get_arg(op, 3); } else { /* For all other create_XXXField operators, name is the 3rd argument */ arg = acpi_ps_get_arg(op, 2); } if (!arg) { return_ACPI_STATUS(AE_AML_NO_OPERAND); } if (walk_state->deferred_node) { node = walk_state->deferred_node; } else { /* Execute flag should always be set when this function is entered */ if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) { ACPI_ERROR((AE_INFO, "Parse execute mode is not set")); return_ACPI_STATUS(AE_AML_INTERNAL); } /* Creating new namespace node, should not already exist */ flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND; /* * Mark node temporary if we are executing a normal control * method. (Don't mark if this is a module-level code method) */ if (walk_state->method_node && !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) { flags |= ACPI_NS_TEMPORARY; } /* Enter the name_string into the namespace */ status = acpi_ns_lookup(walk_state->scope_info, arg->common.value.string, ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1, flags, walk_state, &node); if ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) && status == AE_ALREADY_EXISTS) { status = AE_OK; } else if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, arg->common.value.string, status); return_ACPI_STATUS(status); } } /* * We could put the returned object (Node) on the object stack for later, * but for now, we will put it in the "op" object that the parser uses, * so we can get it again at the end of this scope. */ op->common.node = node; /* * If there is no object attached to the node, this node was just created * and we need to create the field object. Otherwise, this was a lookup * of an existing node and we don't want to create the field object again. */ obj_desc = acpi_ns_get_attached_object(node); if (obj_desc) { return_ACPI_STATUS(AE_OK); } /* * The Field definition is not fully parsed at this time. * (We must save the address of the AML for the buffer and index operands) */ /* Create the buffer field object */ obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD); if (!obj_desc) { status = AE_NO_MEMORY; goto cleanup; } /* * Remember location in AML stream of the field unit opcode and operands * -- since the buffer and index operands must be evaluated. */ second_desc = obj_desc->common.next_object; second_desc->extra.aml_start = op->named.data; second_desc->extra.aml_length = op->named.length; obj_desc->buffer_field.node = node; /* Attach constructed field descriptors to parent node */ status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD); if (ACPI_FAILURE(status)) { goto cleanup; } cleanup: /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_get_field_names * * PARAMETERS: info - create_field info structure * walk_state - Current method state * arg - First parser arg for the field name list * * RETURN: Status * * DESCRIPTION: Process all named fields in a field declaration. Names are * entered into the namespace. * ******************************************************************************/ static acpi_status acpi_ds_get_field_names(struct acpi_create_field_info *info, struct acpi_walk_state *walk_state, union acpi_parse_object *arg) { acpi_status status; u64 position; union acpi_parse_object *child; #ifdef ACPI_EXEC_APP union acpi_operand_object *result_desc; union acpi_operand_object *obj_desc; char *name_path; #endif ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info); /* First field starts at bit zero */ info->field_bit_position = 0; /* Process all elements in the field list (of parse nodes) */ while (arg) { /* * Four types of field elements are handled: * 1) name - Enters a new named field into the namespace * 2) offset - specifies a bit offset * 3) access_as - changes the access mode/attributes * 4) connection - Associate a resource template with the field */ switch (arg->common.aml_opcode) { case AML_INT_RESERVEDFIELD_OP: position = (u64)info->field_bit_position + (u64)arg->common.value.size; if (position > ACPI_UINT32_MAX) { ACPI_ERROR((AE_INFO, "Bit offset within field too large (> 0xFFFFFFFF)")); return_ACPI_STATUS(AE_SUPPORT); } info->field_bit_position = (u32) position; break; case AML_INT_ACCESSFIELD_OP: case AML_INT_EXTACCESSFIELD_OP: /* * Get new access_type, access_attribute, and access_length fields * -- to be used for all field units that follow, until the * end-of-field or another access_as keyword is encountered. * NOTE. These three bytes are encoded in the integer value * of the parseop for convenience. * * In field_flags, preserve the flag bits other than the * ACCESS_TYPE bits. */ /* access_type (byte_acc, word_acc, etc.) */ info->field_flags = (u8) ((info-> field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) | ((u8)((u32)(arg->common.value.integer & 0x07)))); /* access_attribute (attrib_quick, attrib_byte, etc.) */ info->attribute = (u8) ((arg->common.value.integer >> 8) & 0xFF); /* access_length (for serial/buffer protocols) */ info->access_length = (u8) ((arg->common.value.integer >> 16) & 0xFF); break; case AML_INT_CONNECTION_OP: /* * Clear any previous connection. New connection is used for all * fields that follow, similar to access_as */ info->resource_buffer = NULL; info->connection_node = NULL; info->pin_number_index = 0; /* * A Connection() is either an actual resource descriptor (buffer) * or a named reference to a resource template */ child = arg->common.value.arg; if (child->common.aml_opcode == AML_INT_BYTELIST_OP) { info->resource_buffer = child->named.data; info->resource_length = (u16)child->named.value.integer; } else { /* Lookup the Connection() namepath, it should already exist */ status = acpi_ns_lookup(walk_state->scope_info, child->common.value. name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE, walk_state, &info->connection_node); if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state-> scope_info, child->common. value.name, status); return_ACPI_STATUS(status); } } break; case AML_INT_NAMEDFIELD_OP: /* Lookup the name, it should already exist */ status = acpi_ns_lookup(walk_state->scope_info, (char *)&arg->named.name, info->field_type, ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE, walk_state, &info->field_node); if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, (char *)&arg->named.name, status); return_ACPI_STATUS(status); } else { arg->common.node = info->field_node; info->field_bit_length = arg->common.value.size; /* * If there is no object attached to the node, this node was * just created and we need to create the field object. * Otherwise, this was a lookup of an existing node and we * don't want to create the field object again. */ if (!acpi_ns_get_attached_object (info->field_node)) { status = acpi_ex_prep_field_value(info); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } #ifdef ACPI_EXEC_APP name_path = acpi_ns_get_external_pathname(info-> field_node); if (ACPI_SUCCESS (ae_lookup_init_file_entry (name_path, &obj_desc))) { acpi_ex_write_data_to_field (obj_desc, acpi_ns_get_attached_object (info->field_node), &result_desc); acpi_ut_remove_reference (obj_desc); } ACPI_FREE(name_path); #endif } } /* Keep track of bit position for the next field */ position = (u64)info->field_bit_position + (u64)arg->common.value.size; if (position > ACPI_UINT32_MAX) { ACPI_ERROR((AE_INFO, "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)", ACPI_CAST_PTR(char, &info->field_node-> name))); return_ACPI_STATUS(AE_SUPPORT); } info->field_bit_position += info->field_bit_length; info->pin_number_index++; /* Index relative to previous Connection() */ break; default: ACPI_ERROR((AE_INFO, "Invalid opcode in field list: 0x%X", arg->common.aml_opcode)); return_ACPI_STATUS(AE_AML_BAD_OPCODE); } arg = arg->common.next; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_create_field * * PARAMETERS: op - Op containing the Field definition and args * region_node - Object for the containing Operation Region * ` walk_state - Current method state * * RETURN: Status * * DESCRIPTION: Create a new field in the specified operation region * ******************************************************************************/ acpi_status acpi_ds_create_field(union acpi_parse_object *op, struct acpi_namespace_node *region_node, struct acpi_walk_state *walk_state) { acpi_status status; union acpi_parse_object *arg; struct acpi_create_field_info info; ACPI_FUNCTION_TRACE_PTR(ds_create_field, op); /* First arg is the name of the parent op_region (must already exist) */ arg = op->common.value.arg; if (!region_node) { status = acpi_ns_lookup(walk_state->scope_info, arg->common.value.name, ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &region_node); #ifdef ACPI_ASL_COMPILER status = acpi_ds_create_external_region(status, arg, arg->common.value.name, walk_state, &region_node); #endif if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, arg->common.value.name, status); return_ACPI_STATUS(status); } } memset(&info, 0, sizeof(struct acpi_create_field_info)); /* Second arg is the field flags */ arg = arg->common.next; info.field_flags = (u8) arg->common.value.integer; info.attribute = 0; /* Each remaining arg is a Named Field */ info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD; info.region_node = region_node; status = acpi_ds_get_field_names(&info, walk_state, arg->common.next); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (info.region_node->object->region.space_id == ACPI_ADR_SPACE_PLATFORM_COMM) { region_node->object->field.internal_pcc_buffer = ACPI_ALLOCATE_ZEROED(info.region_node->object->region. length); if (!region_node->object->field.internal_pcc_buffer) { return_ACPI_STATUS(AE_NO_MEMORY); } } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_init_field_objects * * PARAMETERS: op - Op containing the Field definition and args * ` walk_state - Current method state * * RETURN: Status * * DESCRIPTION: For each "Field Unit" name in the argument list that is * part of the field declaration, enter the name into the * namespace. * ******************************************************************************/ acpi_status acpi_ds_init_field_objects(union acpi_parse_object *op, struct acpi_walk_state *walk_state) { acpi_status status; union acpi_parse_object *arg = NULL; struct acpi_namespace_node *node; u8 type = 0; u32 flags; ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op); /* Execute flag should always be set when this function is entered */ if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) { if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) { /* bank_field Op is deferred, just return OK */ return_ACPI_STATUS(AE_OK); } ACPI_ERROR((AE_INFO, "Parse deferred mode is not set")); return_ACPI_STATUS(AE_AML_INTERNAL); } /* * Get the field_list argument for this opcode. This is the start of the * list of field elements. */ switch (walk_state->opcode) { case AML_FIELD_OP: arg = acpi_ps_get_arg(op, 2); type = ACPI_TYPE_LOCAL_REGION_FIELD; break; case AML_BANK_FIELD_OP: arg = acpi_ps_get_arg(op, 4); type = ACPI_TYPE_LOCAL_BANK_FIELD; break; case AML_INDEX_FIELD_OP: arg = acpi_ps_get_arg(op, 3); type = ACPI_TYPE_LOCAL_INDEX_FIELD; break; default: return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Creating new namespace node(s), should not already exist */ flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND; /* * Mark node(s) temporary if we are executing a normal control * method. (Don't mark if this is a module-level code method) */ if (walk_state->method_node && !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) { flags |= ACPI_NS_TEMPORARY; } #ifdef ACPI_EXEC_APP flags |= ACPI_NS_OVERRIDE_IF_FOUND; #endif /* * Walk the list of entries in the field_list * Note: field_list can be of zero length. In this case, Arg will be NULL. */ while (arg) { /* * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested * in the field names in order to enter them into the namespace. */ if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) { status = acpi_ns_lookup(walk_state->scope_info, (char *)&arg->named.name, type, ACPI_IMODE_LOAD_PASS1, flags, walk_state, &node); if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, (char *)&arg->named.name, status); if (status != AE_ALREADY_EXISTS) { return_ACPI_STATUS(status); } /* Name already exists, just ignore this error */ } arg->common.node = node; } /* Get the next field element in the list */ arg = arg->common.next; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_create_bank_field * * PARAMETERS: op - Op containing the Field definition and args * region_node - Object for the containing Operation Region * walk_state - Current method state * * RETURN: Status * * DESCRIPTION: Create a new bank field in the specified operation region * ******************************************************************************/ acpi_status acpi_ds_create_bank_field(union acpi_parse_object *op, struct acpi_namespace_node *region_node, struct acpi_walk_state *walk_state) { acpi_status status; union acpi_parse_object *arg; struct acpi_create_field_info info; ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op); /* First arg is the name of the parent op_region (must already exist) */ arg = op->common.value.arg; if (!region_node) { status = acpi_ns_lookup(walk_state->scope_info, arg->common.value.name, ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &region_node); #ifdef ACPI_ASL_COMPILER status = acpi_ds_create_external_region(status, arg, arg->common.value.name, walk_state, &region_node); #endif if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, arg->common.value.name, status); return_ACPI_STATUS(status); } } /* Second arg is the Bank Register (Field) (must already exist) */ arg = arg->common.next; status = acpi_ns_lookup(walk_state->scope_info, arg->common.value.string, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &info.register_node); if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, arg->common.value.string, status); return_ACPI_STATUS(status); } /* * Third arg is the bank_value * This arg is a term_arg, not a constant * It will be evaluated later, by acpi_ds_eval_bank_field_operands */ arg = arg->common.next; /* Fourth arg is the field flags */ arg = arg->common.next; info.field_flags = (u8) arg->common.value.integer; /* Each remaining arg is a Named Field */ info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD; info.region_node = region_node; /* * Use Info.data_register_node to store bank_field Op * It's safe because data_register_node will never be used when create * bank field \we store aml_start and aml_length in the bank_field Op for * late evaluation. Used in acpi_ex_prep_field_value(Info) * * TBD: Or, should we add a field in struct acpi_create_field_info, like * "void *ParentOp"? */ info.data_register_node = (struct acpi_namespace_node *)op; status = acpi_ds_get_field_names(&info, walk_state, arg->common.next); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_create_index_field * * PARAMETERS: op - Op containing the Field definition and args * region_node - Object for the containing Operation Region * ` walk_state - Current method state * * RETURN: Status * * DESCRIPTION: Create a new index field in the specified operation region * ******************************************************************************/ acpi_status acpi_ds_create_index_field(union acpi_parse_object *op, struct acpi_namespace_node *region_node, struct acpi_walk_state *walk_state) { acpi_status status; union acpi_parse_object *arg; struct acpi_create_field_info info; ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op); /* First arg is the name of the Index register (must already exist) */ arg = op->common.value.arg; status = acpi_ns_lookup(walk_state->scope_info, arg->common.value.string, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &info.register_node); if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, arg->common.value.string, status); return_ACPI_STATUS(status); } /* Second arg is the data register (must already exist) */ arg = arg->common.next; status = acpi_ns_lookup(walk_state->scope_info, arg->common.value.string, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &info.data_register_node); if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, arg->common.value.string, status); return_ACPI_STATUS(status); } /* Next arg is the field flags */ arg = arg->common.next; info.field_flags = (u8) arg->common.value.integer; /* Each remaining arg is a Named Field */ info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD; info.region_node = region_node; status = acpi_ds_get_field_names(&info, walk_state, arg->common.next); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/dsfield.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utbuffer - Buffer dump routines * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utbuffer") /******************************************************************************* * * FUNCTION: acpi_ut_dump_buffer * * PARAMETERS: buffer - Buffer to dump * count - Amount to dump, in bytes * display - BYTE, WORD, DWORD, or QWORD display: * DB_BYTE_DISPLAY * DB_WORD_DISPLAY * DB_DWORD_DISPLAY * DB_QWORD_DISPLAY * base_offset - Beginning buffer offset (display only) * * RETURN: None * * DESCRIPTION: Generic dump buffer in both hex and ascii. * ******************************************************************************/ void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 base_offset) { u32 i = 0; u32 j; u32 temp32; u8 buf_char; u32 display_data_only = display & DB_DISPLAY_DATA_ONLY; display &= ~DB_DISPLAY_DATA_ONLY; if (!buffer) { acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n"); return; } if ((count < 4) || (count & 0x01)) { display = DB_BYTE_DISPLAY; } /* Nasty little dump buffer routine! */ while (i < count) { /* Print current offset */ if (!display_data_only) { acpi_os_printf("%8.4X: ", (base_offset + i)); } /* Print 16 hex chars */ for (j = 0; j < 16;) { if (i + j >= count) { /* Dump fill spaces */ acpi_os_printf("%*s", ((display * 2) + 1), " "); j += display; continue; } switch (display) { case DB_BYTE_DISPLAY: default: /* Default is BYTE display */ acpi_os_printf("%02X ", buffer[(acpi_size)i + j]); break; case DB_WORD_DISPLAY: ACPI_MOVE_16_TO_32(&temp32, &buffer[(acpi_size)i + j]); acpi_os_printf("%04X ", temp32); break; case DB_DWORD_DISPLAY: ACPI_MOVE_32_TO_32(&temp32, &buffer[(acpi_size)i + j]); acpi_os_printf("%08X ", temp32); break; case DB_QWORD_DISPLAY: ACPI_MOVE_32_TO_32(&temp32, &buffer[(acpi_size)i + j]); acpi_os_printf("%08X", temp32); ACPI_MOVE_32_TO_32(&temp32, &buffer[(acpi_size)i + j + 4]); acpi_os_printf("%08X ", temp32); break; } j += display; } /* * Print the ASCII equivalent characters but watch out for the bad * unprintable ones (printable chars are 0x20 through 0x7E) */ if (!display_data_only) { acpi_os_printf(" "); for (j = 0; j < 16; j++) { if (i + j >= count) { acpi_os_printf("\n"); return; } /* * Add comment characters so rest of line is ignored when * compiled */ if (j == 0) { acpi_os_printf("// "); } buf_char = buffer[(acpi_size)i + j]; if (isprint(buf_char)) { acpi_os_printf("%c", buf_char); } else { acpi_os_printf("."); } } /* Done with that line. */ acpi_os_printf("\n"); } i += 16; } return; } /******************************************************************************* * * FUNCTION: acpi_ut_debug_dump_buffer * * PARAMETERS: buffer - Buffer to dump * count - Amount to dump, in bytes * display - BYTE, WORD, DWORD, or QWORD display: * DB_BYTE_DISPLAY * DB_WORD_DISPLAY * DB_DWORD_DISPLAY * DB_QWORD_DISPLAY * component_ID - Caller's component ID * * RETURN: None * * DESCRIPTION: Generic dump buffer in both hex and ascii. * ******************************************************************************/ void acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id) { /* Only dump the buffer if tracing is enabled */ if (!((ACPI_LV_TABLES & acpi_dbg_level) && (component_id & acpi_dbg_layer))) { return; } acpi_ut_dump_buffer(buffer, count, display, 0); } #ifdef ACPI_APPLICATION /******************************************************************************* * * FUNCTION: acpi_ut_dump_buffer_to_file * * PARAMETERS: file - File descriptor * buffer - Buffer to dump * count - Amount to dump, in bytes * display - BYTE, WORD, DWORD, or QWORD display: * DB_BYTE_DISPLAY * DB_WORD_DISPLAY * DB_DWORD_DISPLAY * DB_QWORD_DISPLAY * base_offset - Beginning buffer offset (display only) * * RETURN: None * * DESCRIPTION: Generic dump buffer in both hex and ascii to a file. * ******************************************************************************/ void acpi_ut_dump_buffer_to_file(ACPI_FILE file, u8 *buffer, u32 count, u32 display, u32 base_offset) { u32 i = 0; u32 j; u32 temp32; u8 buf_char; if (!buffer) { fprintf(file, "Null Buffer Pointer in DumpBuffer!\n"); return; } if ((count < 4) || (count & 0x01)) { display = DB_BYTE_DISPLAY; } /* Nasty little dump buffer routine! */ while (i < count) { /* Print current offset */ fprintf(file, "%8.4X: ", (base_offset + i)); /* Print 16 hex chars */ for (j = 0; j < 16;) { if (i + j >= count) { /* Dump fill spaces */ fprintf(file, "%*s", ((display * 2) + 1), " "); j += display; continue; } switch (display) { case DB_BYTE_DISPLAY: default: /* Default is BYTE display */ fprintf(file, "%02X ", buffer[(acpi_size)i + j]); break; case DB_WORD_DISPLAY: ACPI_MOVE_16_TO_32(&temp32, &buffer[(acpi_size)i + j]); fprintf(file, "%04X ", temp32); break; case DB_DWORD_DISPLAY: ACPI_MOVE_32_TO_32(&temp32, &buffer[(acpi_size)i + j]); fprintf(file, "%08X ", temp32); break; case DB_QWORD_DISPLAY: ACPI_MOVE_32_TO_32(&temp32, &buffer[(acpi_size)i + j]); fprintf(file, "%08X", temp32); ACPI_MOVE_32_TO_32(&temp32, &buffer[(acpi_size)i + j + 4]); fprintf(file, "%08X ", temp32); break; } j += display; } /* * Print the ASCII equivalent characters but watch out for the bad * unprintable ones (printable chars are 0x20 through 0x7E) */ fprintf(file, " "); for (j = 0; j < 16; j++) { if (i + j >= count) { fprintf(file, "\n"); return; } buf_char = buffer[(acpi_size)i + j]; if (isprint(buf_char)) { fprintf(file, "%c", buf_char); } else { fprintf(file, "."); } } /* Done with that line. */ fprintf(file, "\n"); i += 16; } return; } #endif
linux-master
drivers/acpi/acpica/utbuffer.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing * parents and siblings and Scope manipulation * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "amlcode.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsutils") /* Local prototypes */ #ifdef ACPI_OBSOLETE_FUNCTIONS acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node *node_to_search); #endif /******************************************************************************* * * FUNCTION: acpi_ns_print_node_pathname * * PARAMETERS: node - Object * message - Prefix message * * DESCRIPTION: Print an object's full namespace pathname * Manages allocation/freeing of a pathname buffer * ******************************************************************************/ void acpi_ns_print_node_pathname(struct acpi_namespace_node *node, const char *message) { struct acpi_buffer buffer; acpi_status status; if (!node) { acpi_os_printf("[NULL NAME]"); return; } /* Convert handle to full pathname and print it (with supplied message) */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_ns_handle_to_pathname(node, &buffer, TRUE); if (ACPI_SUCCESS(status)) { if (message) { acpi_os_printf("%s ", message); } acpi_os_printf("%s", (char *)buffer.pointer); ACPI_FREE(buffer.pointer); } } /******************************************************************************* * * FUNCTION: acpi_ns_get_type * * PARAMETERS: node - Parent Node to be examined * * RETURN: Type field from Node whose handle is passed * * DESCRIPTION: Return the type of a Namespace node * ******************************************************************************/ acpi_object_type acpi_ns_get_type(struct acpi_namespace_node * node) { ACPI_FUNCTION_TRACE(ns_get_type); if (!node) { ACPI_WARNING((AE_INFO, "Null Node parameter")); return_UINT8(ACPI_TYPE_ANY); } return_UINT8(node->type); } /******************************************************************************* * * FUNCTION: acpi_ns_local * * PARAMETERS: type - A namespace object type * * RETURN: LOCAL if names must be found locally in objects of the * passed type, 0 if enclosing scopes should be searched * * DESCRIPTION: Returns scope rule for the given object type. * ******************************************************************************/ u32 acpi_ns_local(acpi_object_type type) { ACPI_FUNCTION_TRACE(ns_local); if (!acpi_ut_valid_object_type(type)) { /* Type code out of range */ ACPI_WARNING((AE_INFO, "Invalid Object Type 0x%X", type)); return_UINT32(ACPI_NS_NORMAL); } return_UINT32(acpi_gbl_ns_properties[type] & ACPI_NS_LOCAL); } /******************************************************************************* * * FUNCTION: acpi_ns_get_internal_name_length * * PARAMETERS: info - Info struct initialized with the * external name pointer. * * RETURN: None * * DESCRIPTION: Calculate the length of the internal (AML) namestring * corresponding to the external (ASL) namestring. * ******************************************************************************/ void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info) { const char *next_external_char; u32 i; ACPI_FUNCTION_ENTRY(); next_external_char = info->external_name; info->num_carats = 0; info->num_segments = 0; info->fully_qualified = FALSE; /* * For the internal name, the required length is 4 bytes per segment, * plus 1 each for root_prefix, multi_name_prefix_op, segment count, * trailing null (which is not really needed, but no there's harm in * putting it there) * * strlen() + 1 covers the first name_seg, which has no path separator */ if (ACPI_IS_ROOT_PREFIX(*next_external_char)) { info->fully_qualified = TRUE; next_external_char++; /* Skip redundant root_prefix, like \\_SB.PCI0.SBRG.EC0 */ while (ACPI_IS_ROOT_PREFIX(*next_external_char)) { next_external_char++; } } else { /* Handle Carat prefixes */ while (ACPI_IS_PARENT_PREFIX(*next_external_char)) { info->num_carats++; next_external_char++; } } /* * Determine the number of ACPI name "segments" by counting the number of * path separators within the string. Start with one segment since the * segment count is [(# separators) + 1], and zero separators is ok. */ if (*next_external_char) { info->num_segments = 1; for (i = 0; next_external_char[i]; i++) { if (ACPI_IS_PATH_SEPARATOR(next_external_char[i])) { info->num_segments++; } } } info->length = (ACPI_NAMESEG_SIZE * info->num_segments) + 4 + info->num_carats; info->next_external_char = next_external_char; } /******************************************************************************* * * FUNCTION: acpi_ns_build_internal_name * * PARAMETERS: info - Info struct fully initialized * * RETURN: Status * * DESCRIPTION: Construct the internal (AML) namestring * corresponding to the external (ASL) namestring. * ******************************************************************************/ acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info) { u32 num_segments = info->num_segments; char *internal_name = info->internal_name; const char *external_name = info->next_external_char; char *result = NULL; u32 i; ACPI_FUNCTION_TRACE(ns_build_internal_name); /* Setup the correct prefixes, counts, and pointers */ if (info->fully_qualified) { internal_name[0] = AML_ROOT_PREFIX; if (num_segments <= 1) { result = &internal_name[1]; } else if (num_segments == 2) { internal_name[1] = AML_DUAL_NAME_PREFIX; result = &internal_name[2]; } else { internal_name[1] = AML_MULTI_NAME_PREFIX; internal_name[2] = (char)num_segments; result = &internal_name[3]; } } else { /* * Not fully qualified. * Handle Carats first, then append the name segments */ i = 0; if (info->num_carats) { for (i = 0; i < info->num_carats; i++) { internal_name[i] = AML_PARENT_PREFIX; } } if (num_segments <= 1) { result = &internal_name[i]; } else if (num_segments == 2) { internal_name[i] = AML_DUAL_NAME_PREFIX; result = &internal_name[(acpi_size)i + 1]; } else { internal_name[i] = AML_MULTI_NAME_PREFIX; internal_name[(acpi_size)i + 1] = (char)num_segments; result = &internal_name[(acpi_size)i + 2]; } } /* Build the name (minus path separators) */ for (; num_segments; num_segments--) { for (i = 0; i < ACPI_NAMESEG_SIZE; i++) { if (ACPI_IS_PATH_SEPARATOR(*external_name) || (*external_name == 0)) { /* Pad the segment with underscore(s) if segment is short */ result[i] = '_'; } else { /* Convert the character to uppercase and save it */ result[i] = (char)toupper((int)*external_name); external_name++; } } /* Now we must have a path separator, or the pathname is bad */ if (!ACPI_IS_PATH_SEPARATOR(*external_name) && (*external_name != 0)) { return_ACPI_STATUS(AE_BAD_PATHNAME); } /* Move on the next segment */ external_name++; result += ACPI_NAMESEG_SIZE; } /* Terminate the string */ *result = 0; if (info->fully_qualified) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n", internal_name, internal_name)); } else { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n", internal_name, internal_name)); } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_internalize_name * * PARAMETERS: *external_name - External representation of name * **Converted name - Where to return the resulting * internal represention of the name * * RETURN: Status * * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0") * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) * *******************************************************************************/ acpi_status acpi_ns_internalize_name(const char *external_name, char **converted_name) { char *internal_name; struct acpi_namestring_info info; acpi_status status; ACPI_FUNCTION_TRACE(ns_internalize_name); if ((!external_name) || (*external_name == 0) || (!converted_name)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Get the length of the new internal name */ info.external_name = external_name; acpi_ns_get_internal_name_length(&info); /* We need a segment to store the internal name */ internal_name = ACPI_ALLOCATE_ZEROED(info.length); if (!internal_name) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Build the name */ info.internal_name = internal_name; status = acpi_ns_build_internal_name(&info); if (ACPI_FAILURE(status)) { ACPI_FREE(internal_name); return_ACPI_STATUS(status); } *converted_name = internal_name; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_externalize_name * * PARAMETERS: internal_name_length - Length of the internal name below * internal_name - Internal representation of name * converted_name_length - Where the length is returned * converted_name - Where the resulting external name * is returned * * RETURN: Status * * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) * to its external (printable) form (e.g. "\_PR_.CPU0") * ******************************************************************************/ acpi_status acpi_ns_externalize_name(u32 internal_name_length, const char *internal_name, u32 * converted_name_length, char **converted_name) { u32 names_index = 0; u32 num_segments = 0; u32 required_length; u32 prefix_length = 0; u32 i = 0; u32 j = 0; ACPI_FUNCTION_TRACE(ns_externalize_name); if (!internal_name_length || !internal_name || !converted_name) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Check for a prefix (one '\' | one or more '^') */ switch (internal_name[0]) { case AML_ROOT_PREFIX: prefix_length = 1; break; case AML_PARENT_PREFIX: for (i = 0; i < internal_name_length; i++) { if (ACPI_IS_PARENT_PREFIX(internal_name[i])) { prefix_length = i + 1; } else { break; } } if (i == internal_name_length) { prefix_length = i; } break; default: break; } /* * Check for object names. Note that there could be 0-255 of these * 4-byte elements. */ if (prefix_length < internal_name_length) { switch (internal_name[prefix_length]) { case AML_MULTI_NAME_PREFIX: /* <count> 4-byte names */ names_index = prefix_length + 2; num_segments = (u8) internal_name[(acpi_size)prefix_length + 1]; break; case AML_DUAL_NAME_PREFIX: /* Two 4-byte names */ names_index = prefix_length + 1; num_segments = 2; break; case 0: /* null_name */ names_index = 0; num_segments = 0; break; default: /* one 4-byte name */ names_index = prefix_length; num_segments = 1; break; } } /* * Calculate the length of converted_name, which equals the length * of the prefix, length of all object names, length of any required * punctuation ('.') between object names, plus the NULL terminator. */ required_length = prefix_length + (4 * num_segments) + ((num_segments > 0) ? (num_segments - 1) : 0) + 1; /* * Check to see if we're still in bounds. If not, there's a problem * with internal_name (invalid format). */ if (required_length > internal_name_length) { ACPI_ERROR((AE_INFO, "Invalid internal name")); return_ACPI_STATUS(AE_BAD_PATHNAME); } /* Build the converted_name */ *converted_name = ACPI_ALLOCATE_ZEROED(required_length); if (!(*converted_name)) { return_ACPI_STATUS(AE_NO_MEMORY); } j = 0; for (i = 0; i < prefix_length; i++) { (*converted_name)[j++] = internal_name[i]; } if (num_segments > 0) { for (i = 0; i < num_segments; i++) { if (i > 0) { (*converted_name)[j++] = '.'; } /* Copy and validate the 4-char name segment */ ACPI_COPY_NAMESEG(&(*converted_name)[j], &internal_name[names_index]); acpi_ut_repair_name(&(*converted_name)[j]); j += ACPI_NAMESEG_SIZE; names_index += ACPI_NAMESEG_SIZE; } } if (converted_name_length) { *converted_name_length = (u32) required_length; } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_validate_handle * * PARAMETERS: handle - Handle to be validated and typecast to a * namespace node. * * RETURN: A pointer to a namespace node * * DESCRIPTION: Convert a namespace handle to a namespace node. Handles special * cases for the root node. * * NOTE: Real integer handles would allow for more verification * and keep all pointers within this subsystem - however this introduces * more overhead and has not been necessary to this point. Drivers * holding handles are typically notified before a node becomes invalid * due to a table unload. * ******************************************************************************/ struct acpi_namespace_node *acpi_ns_validate_handle(acpi_handle handle) { ACPI_FUNCTION_ENTRY(); /* Parameter validation */ if ((!handle) || (handle == ACPI_ROOT_OBJECT)) { return (acpi_gbl_root_node); } /* We can at least attempt to verify the handle */ if (ACPI_GET_DESCRIPTOR_TYPE(handle) != ACPI_DESC_TYPE_NAMED) { return (NULL); } return (ACPI_CAST_PTR(struct acpi_namespace_node, handle)); } /******************************************************************************* * * FUNCTION: acpi_ns_terminate * * PARAMETERS: none * * RETURN: none * * DESCRIPTION: free memory allocated for namespace and ACPI table storage. * ******************************************************************************/ void acpi_ns_terminate(void) { acpi_status status; ACPI_FUNCTION_TRACE(ns_terminate); /* * Free the entire namespace -- all nodes and all objects * attached to the nodes */ acpi_ns_delete_namespace_subtree(acpi_gbl_root_node); /* Delete any objects attached to the root node */ status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_VOID; } acpi_ns_delete_node(acpi_gbl_root_node); (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace freed\n")); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ns_opens_scope * * PARAMETERS: type - A valid namespace type * * RETURN: NEWSCOPE if the passed type "opens a name scope" according * to the ACPI specification, else 0 * ******************************************************************************/ u32 acpi_ns_opens_scope(acpi_object_type type) { ACPI_FUNCTION_ENTRY(); if (type > ACPI_TYPE_LOCAL_MAX) { /* type code out of range */ ACPI_WARNING((AE_INFO, "Invalid Object Type 0x%X", type)); return (ACPI_NS_NORMAL); } return (((u32)acpi_gbl_ns_properties[type]) & ACPI_NS_NEWSCOPE); } /******************************************************************************* * * FUNCTION: acpi_ns_get_node_unlocked * * PARAMETERS: *pathname - Name to be found, in external (ASL) format. The * \ (backslash) and ^ (carat) prefixes, and the * . (period) to separate segments are supported. * prefix_node - Root of subtree to be searched, or NS_ALL for the * root of the name space. If Name is fully * qualified (first s8 is '\'), the passed value * of Scope will not be accessed. * flags - Used to indicate whether to perform upsearch or * not. * return_node - Where the Node is returned * * DESCRIPTION: Look up a name relative to a given scope and return the * corresponding Node. NOTE: Scope can be null. * * MUTEX: Doesn't locks namespace * ******************************************************************************/ acpi_status acpi_ns_get_node_unlocked(struct acpi_namespace_node *prefix_node, const char *pathname, u32 flags, struct acpi_namespace_node **return_node) { union acpi_generic_state scope_info; acpi_status status; char *internal_path; ACPI_FUNCTION_TRACE_PTR(ns_get_node_unlocked, ACPI_CAST_PTR(char, pathname)); /* Simplest case is a null pathname */ if (!pathname) { *return_node = prefix_node; if (!prefix_node) { *return_node = acpi_gbl_root_node; } return_ACPI_STATUS(AE_OK); } /* Quick check for a reference to the root */ if (ACPI_IS_ROOT_PREFIX(pathname[0]) && (!pathname[1])) { *return_node = acpi_gbl_root_node; return_ACPI_STATUS(AE_OK); } /* Convert path to internal representation */ status = acpi_ns_internalize_name(pathname, &internal_path); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Setup lookup scope (search starting point) */ scope_info.scope.node = prefix_node; /* Lookup the name in the namespace */ status = acpi_ns_lookup(&scope_info, internal_path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, (flags | ACPI_NS_DONT_OPEN_SCOPE), NULL, return_node); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%s, %s\n", pathname, acpi_format_exception(status))); } ACPI_FREE(internal_path); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ns_get_node * * PARAMETERS: *pathname - Name to be found, in external (ASL) format. The * \ (backslash) and ^ (carat) prefixes, and the * . (period) to separate segments are supported. * prefix_node - Root of subtree to be searched, or NS_ALL for the * root of the name space. If Name is fully * qualified (first s8 is '\'), the passed value * of Scope will not be accessed. * flags - Used to indicate whether to perform upsearch or * not. * return_node - Where the Node is returned * * DESCRIPTION: Look up a name relative to a given scope and return the * corresponding Node. NOTE: Scope can be null. * * MUTEX: Locks namespace * ******************************************************************************/ acpi_status acpi_ns_get_node(struct acpi_namespace_node *prefix_node, const char *pathname, u32 flags, struct acpi_namespace_node **return_node) { acpi_status status; ACPI_FUNCTION_TRACE_PTR(ns_get_node, ACPI_CAST_PTR(char, pathname)); status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ns_get_node_unlocked(prefix_node, pathname, flags, return_node); (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/nsutils.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: tbinstal - ACPI table installation and removal * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "actables.h" #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbinstal") /******************************************************************************* * * FUNCTION: acpi_tb_install_table_with_override * * PARAMETERS: new_table_desc - New table descriptor to install * override - Whether override should be performed * table_index - Where the table index is returned * * RETURN: None * * DESCRIPTION: Install an ACPI table into the global data structure. The * table override mechanism is called to allow the host * OS to replace any table before it is installed in the root * table array. * ******************************************************************************/ void acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc, u8 override, u32 *table_index) { u32 i; acpi_status status; status = acpi_tb_get_next_table_descriptor(&i, NULL); if (ACPI_FAILURE(status)) { return; } /* * ACPI Table Override: * * Before we install the table, let the host OS override it with a new * one if desired. Any table within the RSDT/XSDT can be replaced, * including the DSDT which is pointed to by the FADT. */ if (override) { acpi_tb_override_table(new_table_desc); } acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i], new_table_desc->address, new_table_desc->flags, new_table_desc->pointer); acpi_tb_print_table_header(new_table_desc->address, new_table_desc->pointer); /* This synchronizes acpi_gbl_dsdt_index */ *table_index = i; /* Set the global integer width (based upon revision of the DSDT) */ if (i == acpi_gbl_dsdt_index) { acpi_ut_set_integer_width(new_table_desc->pointer->revision); } } /******************************************************************************* * * FUNCTION: acpi_tb_install_standard_table * * PARAMETERS: address - Address of the table (might be a virtual * address depending on the table_flags) * flags - Flags for the table * table - Pointer to the table (required for virtual * origins, optional for physical) * reload - Whether reload should be performed * override - Whether override should be performed * table_index - Where the table index is returned * * RETURN: Status * * DESCRIPTION: This function is called to verify and install an ACPI table. * When this function is called by "Load" or "LoadTable" opcodes, * or by acpi_load_table() API, the "Reload" parameter is set. * After successfully returning from this function, table is * "INSTALLED" but not "VALIDATED". * ******************************************************************************/ acpi_status acpi_tb_install_standard_table(acpi_physical_address address, u8 flags, struct acpi_table_header *table, u8 reload, u8 override, u32 *table_index) { u32 i; acpi_status status = AE_OK; struct acpi_table_desc new_table_desc; ACPI_FUNCTION_TRACE(tb_install_standard_table); /* Acquire a temporary table descriptor for validation */ status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags, table); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Could not acquire table length at %8.8X%8.8X", ACPI_FORMAT_UINT64(address))); return_ACPI_STATUS(status); } /* * Optionally do not load any SSDTs from the RSDT/XSDT. This can * be useful for debugging ACPI problems on some machines. */ if (!reload && acpi_gbl_disable_ssdt_table_install && ACPI_COMPARE_NAMESEG(&new_table_desc.signature, ACPI_SIG_SSDT)) { ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X", new_table_desc.signature.ascii, ACPI_FORMAT_UINT64(address))); goto release_and_exit; } /* Acquire the table lock */ (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); /* Validate and verify a table before installation */ status = acpi_tb_verify_temp_table(&new_table_desc, NULL, &i); if (ACPI_FAILURE(status)) { if (status == AE_CTRL_TERMINATE) { /* * Table was unloaded, allow it to be reloaded. * As we are going to return AE_OK to the caller, we should * take the responsibility of freeing the input descriptor. * Refill the input descriptor to ensure * acpi_tb_install_table_with_override() can be called again to * indicate the re-installation. */ acpi_tb_uninstall_table(&new_table_desc); (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); *table_index = i; return_ACPI_STATUS(AE_OK); } goto unlock_and_exit; } /* Add the table to the global root table list */ acpi_tb_install_table_with_override(&new_table_desc, override, table_index); /* Invoke table handler */ (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); unlock_and_exit: /* Release the table lock */ (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); release_and_exit: /* Release the temporary table descriptor */ acpi_tb_release_temp_table(&new_table_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_tb_override_table * * PARAMETERS: old_table_desc - Validated table descriptor to be * overridden * * RETURN: None * * DESCRIPTION: Attempt table override by calling the OSL override functions. * Note: If the table is overridden, then the entire new table * is acquired and returned by this function. * Before/after invocation, the table descriptor is in a state * that is "VALIDATED". * ******************************************************************************/ void acpi_tb_override_table(struct acpi_table_desc *old_table_desc) { acpi_status status; struct acpi_table_desc new_table_desc; struct acpi_table_header *table; acpi_physical_address address; u32 length; ACPI_ERROR_ONLY(char *override_type); /* (1) Attempt logical override (returns a logical address) */ status = acpi_os_table_override(old_table_desc->pointer, &table); if (ACPI_SUCCESS(status) && table) { acpi_tb_acquire_temp_table(&new_table_desc, ACPI_PTR_TO_PHYSADDR(table), ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, table); ACPI_ERROR_ONLY(override_type = "Logical"); goto finish_override; } /* (2) Attempt physical override (returns a physical address) */ status = acpi_os_physical_table_override(old_table_desc->pointer, &address, &length); if (ACPI_SUCCESS(status) && address && length) { acpi_tb_acquire_temp_table(&new_table_desc, address, ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL); ACPI_ERROR_ONLY(override_type = "Physical"); goto finish_override; } return; /* There was no override */ finish_override: /* * Validate and verify a table before overriding, no nested table * duplication check as it's too complicated and unnecessary. */ status = acpi_tb_verify_temp_table(&new_table_desc, NULL, NULL); if (ACPI_FAILURE(status)) { return; } ACPI_INFO(("%4.4s 0x%8.8X%8.8X" " %s table override, new table: 0x%8.8X%8.8X", old_table_desc->signature.ascii, ACPI_FORMAT_UINT64(old_table_desc->address), override_type, ACPI_FORMAT_UINT64(new_table_desc.address))); /* We can now uninstall the original table */ acpi_tb_uninstall_table(old_table_desc); /* * Replace the original table descriptor and keep its state as * "VALIDATED". */ acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address, new_table_desc.flags, new_table_desc.pointer); acpi_tb_validate_temp_table(old_table_desc); /* Release the temporary table descriptor */ acpi_tb_release_temp_table(&new_table_desc); } /******************************************************************************* * * FUNCTION: acpi_tb_uninstall_table * * PARAMETERS: table_desc - Table descriptor * * RETURN: None * * DESCRIPTION: Delete one internal ACPI table * ******************************************************************************/ void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc) { ACPI_FUNCTION_TRACE(tb_uninstall_table); /* Table must be installed */ if (!table_desc->address) { return_VOID; } acpi_tb_invalidate_table(table_desc); if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) == ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) { ACPI_FREE(table_desc->pointer); table_desc->pointer = NULL; } table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL); return_VOID; }
linux-master
drivers/acpi/acpica/tbinstal.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exresop - AML Interpreter operand/object resolution * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "amlcode.h" #include "acparser.h" #include "acinterp.h" #include "acnamesp.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exresop") /* Local prototypes */ static acpi_status acpi_ex_check_object_type(acpi_object_type type_needed, acpi_object_type this_type, void *object); /******************************************************************************* * * FUNCTION: acpi_ex_check_object_type * * PARAMETERS: type_needed Object type needed * this_type Actual object type * Object Object pointer * * RETURN: Status * * DESCRIPTION: Check required type against actual type * ******************************************************************************/ static acpi_status acpi_ex_check_object_type(acpi_object_type type_needed, acpi_object_type this_type, void *object) { ACPI_FUNCTION_ENTRY(); if (type_needed == ACPI_TYPE_ANY) { /* All types OK, so we don't perform any typechecks */ return (AE_OK); } if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) { /* * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference * objects and thus allow them to be targets. (As per the ACPI * specification, a store to a constant is a noop.) */ if ((this_type == ACPI_TYPE_INTEGER) && (((union acpi_operand_object *)object)->common.flags & AOPOBJ_AML_CONSTANT)) { return (AE_OK); } } if (type_needed != this_type) { ACPI_ERROR((AE_INFO, "Needed type [%s], found [%s] %p", acpi_ut_get_type_name(type_needed), acpi_ut_get_type_name(this_type), object)); return (AE_AML_OPERAND_TYPE); } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ex_resolve_operands * * PARAMETERS: opcode - Opcode being interpreted * stack_ptr - Pointer to the operand stack to be * resolved * walk_state - Current state * * RETURN: Status * * DESCRIPTION: Convert multiple input operands to the types required by the * target operator. * * Each 5-bit group in arg_types represents one required * operand and indicates the required Type. The corresponding operand * will be converted to the required type if possible, otherwise we * abort with an exception. * ******************************************************************************/ acpi_status acpi_ex_resolve_operands(u16 opcode, union acpi_operand_object **stack_ptr, struct acpi_walk_state *walk_state) { union acpi_operand_object *obj_desc; acpi_status status = AE_OK; u8 object_type; u32 arg_types; const struct acpi_opcode_info *op_info; u32 this_arg_type; acpi_object_type type_needed; u16 target_op = 0; ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode); op_info = acpi_ps_get_opcode_info(opcode); if (op_info->class == AML_CLASS_UNKNOWN) { return_ACPI_STATUS(AE_AML_BAD_OPCODE); } arg_types = op_info->runtime_args; if (arg_types == ARGI_INVALID_OPCODE) { ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", opcode)); return_ACPI_STATUS(AE_AML_INTERNAL); } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Opcode %X [%s] RequiredOperandTypes=%8.8X\n", opcode, op_info->name, arg_types)); /* * Normal exit is with (arg_types == 0) at end of argument list. * Function will return an exception from within the loop upon * finding an entry which is not (or cannot be converted * to) the required type; if stack underflows; or upon * finding a NULL stack entry (which should not happen). */ while (GET_CURRENT_ARG_TYPE(arg_types)) { if (!stack_ptr || !*stack_ptr) { ACPI_ERROR((AE_INFO, "Null stack entry at %p", stack_ptr)); return_ACPI_STATUS(AE_AML_INTERNAL); } /* Extract useful items */ obj_desc = *stack_ptr; /* Decode the descriptor type */ switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) { case ACPI_DESC_TYPE_NAMED: /* Namespace Node */ object_type = ((struct acpi_namespace_node *)obj_desc)->type; /* * Resolve an alias object. The construction of these objects * guarantees that there is only one level of alias indirection; * thus, the attached object is always the aliased namespace node */ if (object_type == ACPI_TYPE_LOCAL_ALIAS) { obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *) obj_desc); *stack_ptr = obj_desc; object_type = ((struct acpi_namespace_node *)obj_desc)-> type; } break; case ACPI_DESC_TYPE_OPERAND: /* ACPI internal object */ object_type = obj_desc->common.type; /* Check for bad acpi_object_type */ if (!acpi_ut_valid_object_type(object_type)) { ACPI_ERROR((AE_INFO, "Bad operand object type [0x%X]", object_type)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) { /* Validate the Reference */ switch (obj_desc->reference.class) { case ACPI_REFCLASS_DEBUG: target_op = AML_DEBUG_OP; ACPI_FALLTHROUGH; case ACPI_REFCLASS_ARG: case ACPI_REFCLASS_LOCAL: case ACPI_REFCLASS_INDEX: case ACPI_REFCLASS_REFOF: case ACPI_REFCLASS_TABLE: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */ case ACPI_REFCLASS_NAME: /* Reference to a named object */ ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Operand is a Reference, Class [%s] %2.2X\n", acpi_ut_get_reference_name (obj_desc), obj_desc->reference. class)); break; default: ACPI_ERROR((AE_INFO, "Unknown Reference Class 0x%2.2X in %p", obj_desc->reference.class, obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } } break; default: /* Invalid descriptor */ ACPI_ERROR((AE_INFO, "Invalid descriptor %p [%s]", obj_desc, acpi_ut_get_descriptor_name(obj_desc))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } /* Get one argument type, point to the next */ this_arg_type = GET_CURRENT_ARG_TYPE(arg_types); INCREMENT_ARG_LIST(arg_types); /* * Handle cases where the object does not need to be * resolved to a value */ switch (this_arg_type) { case ARGI_REF_OR_STRING: /* Can be a String or Reference */ if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) && (obj_desc->common.type == ACPI_TYPE_STRING)) { /* * String found - the string references a named object and * must be resolved to a node */ goto next_operand; } /* * Else not a string - fall through to the normal Reference * case below */ ACPI_FALLTHROUGH; case ARGI_REFERENCE: /* References: */ case ARGI_INTEGER_REF: case ARGI_OBJECT_REF: case ARGI_DEVICE_REF: case ARGI_TARGETREF: /* Allows implicit conversion rules before store */ case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */ case ARGI_SIMPLE_TARGET: /* Name, Local, or arg - no implicit conversion */ case ARGI_STORE_TARGET: /* * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE * A Namespace Node is OK as-is */ if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_NAMED) { goto next_operand; } status = acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE, object_type, obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } goto next_operand; case ARGI_DATAREFOBJ: /* Store operator only */ /* * We don't want to resolve index_op reference objects during * a store because this would be an implicit de_ref_of operation. * Instead, we just want to store the reference object. * -- All others must be resolved below. */ if ((opcode == AML_STORE_OP) && ((*stack_ptr)->common.type == ACPI_TYPE_LOCAL_REFERENCE) && ((*stack_ptr)->reference.class == ACPI_REFCLASS_INDEX)) { goto next_operand; } break; default: /* All cases covered above */ break; } /* * Resolve this object to a value */ status = acpi_ex_resolve_to_value(stack_ptr, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Get the resolved object */ obj_desc = *stack_ptr; /* * Check the resulting object (value) type */ switch (this_arg_type) { /* * For the simple cases, only one type of resolved object * is allowed */ case ARGI_MUTEX: /* Need an operand of type ACPI_TYPE_MUTEX */ type_needed = ACPI_TYPE_MUTEX; break; case ARGI_EVENT: /* Need an operand of type ACPI_TYPE_EVENT */ type_needed = ACPI_TYPE_EVENT; break; case ARGI_PACKAGE: /* Package */ /* Need an operand of type ACPI_TYPE_PACKAGE */ type_needed = ACPI_TYPE_PACKAGE; break; case ARGI_ANYTYPE: /* Any operand type will do */ type_needed = ACPI_TYPE_ANY; break; case ARGI_DDBHANDLE: /* Need an operand of type ACPI_TYPE_DDB_HANDLE */ type_needed = ACPI_TYPE_LOCAL_REFERENCE; break; /* * The more complex cases allow multiple resolved object types */ case ARGI_INTEGER: /* * Need an operand of type ACPI_TYPE_INTEGER, but we can * implicitly convert from a STRING or BUFFER. * * Known as "Implicit Source Operand Conversion" */ status = acpi_ex_convert_to_integer(obj_desc, stack_ptr, ACPI_IMPLICIT_CONVERSION); if (ACPI_FAILURE(status)) { if (status == AE_TYPE) { ACPI_ERROR((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } return_ACPI_STATUS(status); } if (obj_desc != *stack_ptr) { acpi_ut_remove_reference(obj_desc); } goto next_operand; case ARGI_BUFFER: /* * Need an operand of type ACPI_TYPE_BUFFER, * But we can implicitly convert from a STRING or INTEGER * aka - "Implicit Source Operand Conversion" */ status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr); if (ACPI_FAILURE(status)) { if (status == AE_TYPE) { ACPI_ERROR((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } return_ACPI_STATUS(status); } if (obj_desc != *stack_ptr) { acpi_ut_remove_reference(obj_desc); } goto next_operand; case ARGI_STRING: /* * Need an operand of type ACPI_TYPE_STRING, * But we can implicitly convert from a BUFFER or INTEGER * aka - "Implicit Source Operand Conversion" */ status = acpi_ex_convert_to_string(obj_desc, stack_ptr, ACPI_IMPLICIT_CONVERT_HEX); if (ACPI_FAILURE(status)) { if (status == AE_TYPE) { ACPI_ERROR((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } return_ACPI_STATUS(status); } if (obj_desc != *stack_ptr) { acpi_ut_remove_reference(obj_desc); } goto next_operand; case ARGI_COMPUTEDATA: /* Need an operand of type INTEGER, STRING or BUFFER */ switch (obj_desc->common.type) { case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* Valid operand */ break; default: ACPI_ERROR((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } goto next_operand; case ARGI_BUFFER_OR_STRING: /* Need an operand of type STRING or BUFFER */ switch (obj_desc->common.type) { case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* Valid operand */ break; case ACPI_TYPE_INTEGER: /* Highest priority conversion is to type Buffer */ status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (obj_desc != *stack_ptr) { acpi_ut_remove_reference(obj_desc); } break; default: ACPI_ERROR((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } goto next_operand; case ARGI_DATAOBJECT: /* * ARGI_DATAOBJECT is only used by the size_of operator. * Need a buffer, string, package, or ref_of reference. * * The only reference allowed here is a direct reference to * a namespace node. */ switch (obj_desc->common.type) { case ACPI_TYPE_PACKAGE: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: case ACPI_TYPE_LOCAL_REFERENCE: /* Valid operand */ break; default: ACPI_ERROR((AE_INFO, "Needed [Buffer/String/Package/Reference], found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } goto next_operand; case ARGI_COMPLEXOBJ: /* Need a buffer or package or (ACPI 2.0) String */ switch (obj_desc->common.type) { case ACPI_TYPE_PACKAGE: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* Valid operand */ break; default: ACPI_ERROR((AE_INFO, "Needed [Buffer/String/Package], found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } goto next_operand; case ARGI_REGION_OR_BUFFER: /* Used by Load() only */ /* * Need an operand of type REGION or a BUFFER * (which could be a resolved region field) */ switch (obj_desc->common.type) { case ACPI_TYPE_BUFFER: case ACPI_TYPE_REGION: /* Valid operand */ break; default: ACPI_ERROR((AE_INFO, "Needed [Region/Buffer], found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } goto next_operand; case ARGI_DATAREFOBJ: /* Used by the Store() operator only */ switch (obj_desc->common.type) { case ACPI_TYPE_INTEGER: case ACPI_TYPE_PACKAGE: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REFERENCE: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: case ACPI_TYPE_DDB_HANDLE: /* Valid operand */ break; default: if (acpi_gbl_enable_interpreter_slack) { /* * Enable original behavior of Store(), allowing any * and all objects as the source operand. The ACPI * spec does not allow this, however. */ break; } if (target_op == AML_DEBUG_OP) { /* Allow store of any object to the Debug object */ break; } ACPI_ERROR((AE_INFO, "Needed Integer/Buffer/String/Package/Ref/Ddb]" ", found [%s] %p", acpi_ut_get_object_type_name (obj_desc), obj_desc)); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } goto next_operand; default: /* Unknown type */ ACPI_ERROR((AE_INFO, "Internal - Unknown ARGI (required operand) type 0x%X", this_arg_type)); return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Make sure that the original object was resolved to the * required object type (Simple cases only). */ status = acpi_ex_check_object_type(type_needed, (*stack_ptr)->common.type, *stack_ptr); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } next_operand: /* * If more operands needed, decrement stack_ptr to point * to next operand on stack */ if (GET_CURRENT_ARG_TYPE(arg_types)) { stack_ptr--; } } ACPI_DUMP_OPERANDS(walk_state->operands, acpi_ps_get_opcode_name(opcode), walk_state->num_operands); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exresop.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: tbfadt - FADT table utilities * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "actables.h" #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbfadt") /* Local prototypes */ static void acpi_tb_init_generic_address(struct acpi_generic_address *generic_address, u8 space_id, u8 byte_width, u64 address, const char *register_name, u8 flags); static void acpi_tb_convert_fadt(void); static void acpi_tb_setup_fadt_registers(void); static u64 acpi_tb_select_address(char *register_name, u32 address32, u64 address64); /* Table for conversion of FADT to common internal format and FADT validation */ typedef struct acpi_fadt_info { const char *name; u16 address64; u16 address32; u16 length; u8 default_length; u8 flags; } acpi_fadt_info; #define ACPI_FADT_OPTIONAL 0 #define ACPI_FADT_REQUIRED 1 #define ACPI_FADT_SEPARATE_LENGTH 2 #define ACPI_FADT_GPE_REGISTER 4 static struct acpi_fadt_info fadt_info_table[] = { {"Pm1aEventBlock", ACPI_FADT_OFFSET(xpm1a_event_block), ACPI_FADT_OFFSET(pm1a_event_block), ACPI_FADT_OFFSET(pm1_event_length), ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */ ACPI_FADT_REQUIRED}, {"Pm1bEventBlock", ACPI_FADT_OFFSET(xpm1b_event_block), ACPI_FADT_OFFSET(pm1b_event_block), ACPI_FADT_OFFSET(pm1_event_length), ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */ ACPI_FADT_OPTIONAL}, {"Pm1aControlBlock", ACPI_FADT_OFFSET(xpm1a_control_block), ACPI_FADT_OFFSET(pm1a_control_block), ACPI_FADT_OFFSET(pm1_control_length), ACPI_PM1_REGISTER_WIDTH, ACPI_FADT_REQUIRED}, {"Pm1bControlBlock", ACPI_FADT_OFFSET(xpm1b_control_block), ACPI_FADT_OFFSET(pm1b_control_block), ACPI_FADT_OFFSET(pm1_control_length), ACPI_PM1_REGISTER_WIDTH, ACPI_FADT_OPTIONAL}, {"Pm2ControlBlock", ACPI_FADT_OFFSET(xpm2_control_block), ACPI_FADT_OFFSET(pm2_control_block), ACPI_FADT_OFFSET(pm2_control_length), ACPI_PM2_REGISTER_WIDTH, ACPI_FADT_SEPARATE_LENGTH}, {"PmTimerBlock", ACPI_FADT_OFFSET(xpm_timer_block), ACPI_FADT_OFFSET(pm_timer_block), ACPI_FADT_OFFSET(pm_timer_length), ACPI_PM_TIMER_WIDTH, ACPI_FADT_SEPARATE_LENGTH}, /* ACPI 5.0A: Timer is optional */ {"Gpe0Block", ACPI_FADT_OFFSET(xgpe0_block), ACPI_FADT_OFFSET(gpe0_block), ACPI_FADT_OFFSET(gpe0_block_length), 0, ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER}, {"Gpe1Block", ACPI_FADT_OFFSET(xgpe1_block), ACPI_FADT_OFFSET(gpe1_block), ACPI_FADT_OFFSET(gpe1_block_length), 0, ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER} }; #define ACPI_FADT_INFO_ENTRIES \ (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info)) /* Table used to split Event Blocks into separate status/enable registers */ typedef struct acpi_fadt_pm_info { struct acpi_generic_address *target; u16 source; u8 register_num; } acpi_fadt_pm_info; static struct acpi_fadt_pm_info fadt_pm_info_table[] = { {&acpi_gbl_xpm1a_status, ACPI_FADT_OFFSET(xpm1a_event_block), 0}, {&acpi_gbl_xpm1a_enable, ACPI_FADT_OFFSET(xpm1a_event_block), 1}, {&acpi_gbl_xpm1b_status, ACPI_FADT_OFFSET(xpm1b_event_block), 0}, {&acpi_gbl_xpm1b_enable, ACPI_FADT_OFFSET(xpm1b_event_block), 1} }; #define ACPI_FADT_PM_INFO_ENTRIES \ (sizeof (fadt_pm_info_table) / sizeof (struct acpi_fadt_pm_info)) /******************************************************************************* * * FUNCTION: acpi_tb_init_generic_address * * PARAMETERS: generic_address - GAS struct to be initialized * space_id - ACPI Space ID for this register * byte_width - Width of this register * address - Address of the register * register_name - ASCII name of the ACPI register * * RETURN: None * * DESCRIPTION: Initialize a Generic Address Structure (GAS) * See the ACPI specification for a full description and * definition of this structure. * ******************************************************************************/ static void acpi_tb_init_generic_address(struct acpi_generic_address *generic_address, u8 space_id, u8 byte_width, u64 address, const char *register_name, u8 flags) { u8 bit_width; /* * Bit width field in the GAS is only one byte long, 255 max. * Check for bit_width overflow in GAS. */ bit_width = (u8)(byte_width * 8); if (byte_width > 31) { /* (31*8)=248, (32*8)=256 */ /* * No error for GPE blocks, because we do not use the bit_width * for GPEs, the legacy length (byte_width) is used instead to * allow for a large number of GPEs. */ if (!(flags & ACPI_FADT_GPE_REGISTER)) { ACPI_ERROR((AE_INFO, "%s - 32-bit FADT register is too long (%u bytes, %u bits) " "to convert to GAS struct - 255 bits max, truncating", register_name, byte_width, (byte_width * 8))); } bit_width = 255; } /* * The 64-bit Address field is non-aligned in the byte packed * GAS struct. */ ACPI_MOVE_64_TO_64(&generic_address->address, &address); /* All other fields are byte-wide */ generic_address->space_id = space_id; generic_address->bit_width = bit_width; generic_address->bit_offset = 0; generic_address->access_width = 0; /* Access width ANY */ } /******************************************************************************* * * FUNCTION: acpi_tb_select_address * * PARAMETERS: register_name - ASCII name of the ACPI register * address32 - 32-bit address of the register * address64 - 64-bit address of the register * * RETURN: The resolved 64-bit address * * DESCRIPTION: Select between 32-bit and 64-bit versions of addresses within * the FADT. Used for the FACS and DSDT addresses. * * NOTES: * * Check for FACS and DSDT address mismatches. An address mismatch between * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and * DSDT/X_DSDT) could be a corrupted address field or it might indicate * the presence of two FACS or two DSDT tables. * * November 2013: * By default, as per the ACPICA specification, a valid 64-bit address is * used regardless of the value of the 32-bit address. However, this * behavior can be overridden via the acpi_gbl_use32_bit_fadt_addresses flag. * ******************************************************************************/ static u64 acpi_tb_select_address(char *register_name, u32 address32, u64 address64) { if (!address64) { /* 64-bit address is zero, use 32-bit address */ return ((u64)address32); } if (address32 && (address64 != (u64)address32)) { /* Address mismatch between 32-bit and 64-bit versions */ ACPI_BIOS_WARNING((AE_INFO, "32/64X %s address mismatch in FADT: " "0x%8.8X/0x%8.8X%8.8X, using %u-bit address", register_name, address32, ACPI_FORMAT_UINT64(address64), acpi_gbl_use32_bit_fadt_addresses ? 32 : 64)); /* 32-bit address override */ if (acpi_gbl_use32_bit_fadt_addresses) { return ((u64)address32); } } /* Default is to use the 64-bit address */ return (address64); } /******************************************************************************* * * FUNCTION: acpi_tb_parse_fadt * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Initialize the FADT, DSDT and FACS tables * (FADT contains the addresses of the DSDT and FACS) * ******************************************************************************/ void acpi_tb_parse_fadt(void) { u32 length; struct acpi_table_header *table; struct acpi_table_desc *fadt_desc; acpi_status status; /* * The FADT has multiple versions with different lengths, * and it contains pointers to both the DSDT and FACS tables. * * Get a local copy of the FADT and convert it to a common format * Map entire FADT, assumed to be smaller than one page. */ fadt_desc = &acpi_gbl_root_table_list.tables[acpi_gbl_fadt_index]; status = acpi_tb_get_table(fadt_desc, &table); if (ACPI_FAILURE(status)) { return; } length = fadt_desc->length; /* * Validate the FADT checksum before we copy the table. Ignore * checksum error as we want to try to get the DSDT and FACS. */ (void)acpi_ut_verify_checksum(table, length); /* Create a local copy of the FADT in common ACPI 2.0+ format */ acpi_tb_create_local_fadt(table, length); /* All done with the real FADT, unmap it */ acpi_tb_put_table(fadt_desc); /* Obtain the DSDT and FACS tables via their addresses within the FADT */ acpi_tb_install_standard_table((acpi_physical_address)acpi_gbl_FADT. Xdsdt, ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, TRUE, &acpi_gbl_dsdt_index); /* If Hardware Reduced flag is set, there is no FACS */ if (!acpi_gbl_reduced_hardware) { if (acpi_gbl_FADT.facs) { acpi_tb_install_standard_table((acpi_physical_address) acpi_gbl_FADT.facs, ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, TRUE, &acpi_gbl_facs_index); } if (acpi_gbl_FADT.Xfacs) { acpi_tb_install_standard_table((acpi_physical_address) acpi_gbl_FADT.Xfacs, ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, TRUE, &acpi_gbl_xfacs_index); } } } /******************************************************************************* * * FUNCTION: acpi_tb_create_local_fadt * * PARAMETERS: table - Pointer to BIOS FADT * length - Length of the table * * RETURN: None * * DESCRIPTION: Get a local copy of the FADT and convert it to a common format. * Performs validation on some important FADT fields. * * NOTE: We create a local copy of the FADT regardless of the version. * ******************************************************************************/ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length) { /* * Check if the FADT is larger than the largest table that we expect * (typically the current ACPI specification version). If so, truncate * the table, and issue a warning. */ if (length > sizeof(struct acpi_table_fadt)) { ACPI_BIOS_WARNING((AE_INFO, "FADT (revision %u) is longer than %s length, " "truncating length %u to %u", table->revision, ACPI_FADT_CONFORMANCE, length, (u32)sizeof(struct acpi_table_fadt))); } /* Clear the entire local FADT */ memset(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt)); /* Copy the original FADT, up to sizeof (struct acpi_table_fadt) */ memcpy(&acpi_gbl_FADT, table, ACPI_MIN(length, sizeof(struct acpi_table_fadt))); /* Take a copy of the Hardware Reduced flag */ acpi_gbl_reduced_hardware = FALSE; if (acpi_gbl_FADT.flags & ACPI_FADT_HW_REDUCED) { acpi_gbl_reduced_hardware = TRUE; } /* Convert the local copy of the FADT to the common internal format */ acpi_tb_convert_fadt(); /* Initialize the global ACPI register structures */ acpi_tb_setup_fadt_registers(); } /******************************************************************************* * * FUNCTION: acpi_tb_convert_fadt * * PARAMETERS: none - acpi_gbl_FADT is used. * * RETURN: None * * DESCRIPTION: Converts all versions of the FADT to a common internal format. * Expand 32-bit addresses to 64-bit as necessary. Also validate * important fields within the FADT. * * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt), and must * contain a copy of the actual BIOS-provided FADT. * * Notes on 64-bit register addresses: * * After this FADT conversion, later ACPICA code will only use the 64-bit "X" * fields of the FADT for all ACPI register addresses. * * The 64-bit X fields are optional extensions to the original 32-bit FADT * V1.0 fields. Even if they are present in the FADT, they are optional and * are unused if the BIOS sets them to zero. Therefore, we must copy/expand * 32-bit V1.0 fields to the 64-bit X fields if the 64-bit X field is originally * zero. * * For ACPI 1.0 FADTs (that contain no 64-bit addresses), all 32-bit address * fields are expanded to the corresponding 64-bit X fields in the internal * common FADT. * * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded * to the corresponding 64-bit X fields, if the 64-bit field is originally * zero. Adhering to the ACPI specification, we completely ignore the 32-bit * field if the 64-bit field is valid, regardless of whether the host OS is * 32-bit or 64-bit. * * Possible additional checks: * (acpi_gbl_FADT.pm1_event_length >= 4) * (acpi_gbl_FADT.pm1_control_length >= 2) * (acpi_gbl_FADT.pm_timer_length >= 4) * Gpe block lengths must be multiple of 2 * ******************************************************************************/ static void acpi_tb_convert_fadt(void) { const char *name; struct acpi_generic_address *address64; u32 address32; u8 length; u8 flags; u32 i; /* * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which * should be zero are indeed zero. This will workaround BIOSs that * inadvertently place values in these fields. * * The ACPI 1.0 reserved fields that will be zeroed are the bytes located * at offset 45, 55, 95, and the word located at offset 109, 110. * * Note: The FADT revision value is unreliable. Only the length can be * trusted. */ if (acpi_gbl_FADT.header.length <= ACPI_FADT_V2_SIZE) { acpi_gbl_FADT.preferred_profile = 0; acpi_gbl_FADT.pstate_control = 0; acpi_gbl_FADT.cst_control = 0; acpi_gbl_FADT.boot_flags = 0; } /* * Now we can update the local FADT length to the length of the * current FADT version as defined by the ACPI specification. * Thus, we will have a common FADT internally. */ acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt); /* * Expand the 32-bit DSDT addresses to 64-bit as necessary. * Later ACPICA code will always use the X 64-bit field. */ acpi_gbl_FADT.Xdsdt = acpi_tb_select_address("DSDT", acpi_gbl_FADT.dsdt, acpi_gbl_FADT.Xdsdt); /* If Hardware Reduced flag is set, we are all done */ if (acpi_gbl_reduced_hardware) { return; } /* Examine all of the 64-bit extended address fields (X fields) */ for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) { /* * Get the 32-bit and 64-bit addresses, as well as the register * length and register name. */ address32 = *ACPI_ADD_PTR(u32, &acpi_gbl_FADT, fadt_info_table[i].address32); address64 = ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT, fadt_info_table[i].address64); length = *ACPI_ADD_PTR(u8, &acpi_gbl_FADT, fadt_info_table[i].length); name = fadt_info_table[i].name; flags = fadt_info_table[i].flags; /* * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X" * generic address structures as necessary. Later code will always use * the 64-bit address structures. * * November 2013: * Now always use the 64-bit address if it is valid (non-zero), in * accordance with the ACPI specification which states that a 64-bit * address supersedes the 32-bit version. This behavior can be * overridden by the acpi_gbl_use32_bit_fadt_addresses flag. * * During 64-bit address construction and verification, * these cases are handled: * * Address32 zero, Address64 [don't care] - Use Address64 * * No override: if acpi_gbl_use32_bit_fadt_addresses is FALSE, and: * Address32 non-zero, Address64 zero - Copy/use Address32 * Address32 non-zero == Address64 non-zero - Use Address64 * Address32 non-zero != Address64 non-zero - Warning, use Address64 * * Override: if acpi_gbl_use32_bit_fadt_addresses is TRUE, and: * Address32 non-zero, Address64 zero - Copy/use Address32 * Address32 non-zero == Address64 non-zero - Copy/use Address32 * Address32 non-zero != Address64 non-zero - Warning, copy/use Address32 * * Note: space_id is always I/O for 32-bit legacy address fields */ if (address32) { if (address64->address) { if (address64->address != (u64)address32) { /* Address mismatch */ ACPI_BIOS_WARNING((AE_INFO, "32/64X address mismatch in FADT/%s: " "0x%8.8X/0x%8.8X%8.8X, using %u-bit address", name, address32, ACPI_FORMAT_UINT64 (address64->address), acpi_gbl_use32_bit_fadt_addresses ? 32 : 64)); } /* * For each extended field, check for length mismatch * between the legacy length field and the corresponding * 64-bit X length field. * Note: If the legacy length field is > 0xFF bits, ignore * this check. (GPE registers can be larger than the * 64-bit GAS structure can accommodate, 0xFF bits). */ if ((ACPI_MUL_8(length) <= ACPI_UINT8_MAX) && (address64->bit_width != ACPI_MUL_8(length))) { ACPI_BIOS_WARNING((AE_INFO, "32/64X length mismatch in FADT/%s: %u/%u", name, ACPI_MUL_8(length), address64-> bit_width)); } } /* * Hardware register access code always uses the 64-bit fields. * So if the 64-bit field is zero or is to be overridden, * initialize it with the 32-bit fields. * Note that when the 32-bit address favor is specified, the * 64-bit fields are always re-initialized so that * access_size/bit_width/bit_offset fields can be correctly * configured to the values to trigger a 32-bit compatible * access mode in the hardware register access code. */ if (!address64->address || acpi_gbl_use32_bit_fadt_addresses) { acpi_tb_init_generic_address(address64, ACPI_ADR_SPACE_SYSTEM_IO, length, (u64)address32, name, flags); } } if (fadt_info_table[i].flags & ACPI_FADT_REQUIRED) { /* * Field is required (Pm1a_event, Pm1a_control). * Both the address and length must be non-zero. */ if (!address64->address || !length) { ACPI_BIOS_ERROR((AE_INFO, "Required FADT field %s has zero address and/or length: " "0x%8.8X%8.8X/0x%X", name, ACPI_FORMAT_UINT64(address64-> address), length)); } } else if (fadt_info_table[i].flags & ACPI_FADT_SEPARATE_LENGTH) { /* * Field is optional (Pm2_control, GPE0, GPE1) AND has its own * length field. If present, both the address and length must * be valid. */ if ((address64->address && !length) || (!address64->address && length)) { ACPI_BIOS_WARNING((AE_INFO, "Optional FADT field %s has valid %s but zero %s: " "0x%8.8X%8.8X/0x%X", name, (length ? "Length" : "Address"), (length ? "Address" : "Length"), ACPI_FORMAT_UINT64 (address64->address), length)); } } } } /******************************************************************************* * * FUNCTION: acpi_tb_setup_fadt_registers * * PARAMETERS: None, uses acpi_gbl_FADT. * * RETURN: None * * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally, * force FADT register definitions to their default lengths. * ******************************************************************************/ static void acpi_tb_setup_fadt_registers(void) { struct acpi_generic_address *target64; struct acpi_generic_address *source64; u8 pm1_register_byte_width; u32 i; /* * Optionally check all register lengths against the default values and * update them if they are incorrect. */ if (acpi_gbl_use_default_register_widths) { for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) { target64 = ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT, fadt_info_table[i].address64); /* * If a valid register (Address != 0) and the (default_length > 0) * (Not a GPE register), then check the width against the default. */ if ((target64->address) && (fadt_info_table[i].default_length > 0) && (fadt_info_table[i].default_length != target64->bit_width)) { ACPI_BIOS_WARNING((AE_INFO, "Invalid length for FADT/%s: %u, using default %u", fadt_info_table[i].name, target64->bit_width, fadt_info_table[i]. default_length)); /* Incorrect size, set width to the default */ target64->bit_width = fadt_info_table[i].default_length; } } } /* * Get the length of the individual PM1 registers (enable and status). * Each register is defined to be (event block length / 2). Extra divide * by 8 converts bits to bytes. */ pm1_register_byte_width = (u8) ACPI_DIV_16(acpi_gbl_FADT.xpm1a_event_block.bit_width); /* * Calculate separate GAS structs for the PM1x (A/B) Status and Enable * registers. These addresses do not appear (directly) in the FADT, so it * is useful to pre-calculate them from the PM1 Event Block definitions. * * The PM event blocks are split into two register blocks, first is the * PM Status Register block, followed immediately by the PM Enable * Register block. Each is of length (pm1_event_length/2) * * Note: The PM1A event block is required by the ACPI specification. * However, the PM1B event block is optional and is rarely, if ever, * used. */ for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++) { source64 = ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT, fadt_pm_info_table[i].source); if (source64->address) { acpi_tb_init_generic_address(fadt_pm_info_table[i]. target, source64->space_id, pm1_register_byte_width, source64->address + (fadt_pm_info_table[i]. register_num * pm1_register_byte_width), "PmRegisters", 0); } } }
linux-master
drivers/acpi/acpica/tbfadt.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: utnonansi - Non-ansi C library functions * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utnonansi") /* * Non-ANSI C library functions - strlwr, strupr, stricmp, and "safe" * string functions. */ /******************************************************************************* * * FUNCTION: acpi_ut_strlwr (strlwr) * * PARAMETERS: src_string - The source string to convert * * RETURN: None * * DESCRIPTION: Convert a string to lowercase * ******************************************************************************/ void acpi_ut_strlwr(char *src_string) { char *string; ACPI_FUNCTION_ENTRY(); if (!src_string) { return; } /* Walk entire string, lowercasing the letters */ for (string = src_string; *string; string++) { *string = (char)tolower((int)*string); } } /******************************************************************************* * * FUNCTION: acpi_ut_strupr (strupr) * * PARAMETERS: src_string - The source string to convert * * RETURN: None * * DESCRIPTION: Convert a string to uppercase * ******************************************************************************/ void acpi_ut_strupr(char *src_string) { char *string; ACPI_FUNCTION_ENTRY(); if (!src_string) { return; } /* Walk entire string, uppercasing the letters */ for (string = src_string; *string; string++) { *string = (char)toupper((int)*string); } } /****************************************************************************** * * FUNCTION: acpi_ut_stricmp (stricmp) * * PARAMETERS: string1 - first string to compare * string2 - second string to compare * * RETURN: int that signifies string relationship. Zero means strings * are equal. * * DESCRIPTION: Case-insensitive string compare. Implementation of the * non-ANSI stricmp function. * ******************************************************************************/ int acpi_ut_stricmp(char *string1, char *string2) { int c1; int c2; do { c1 = tolower((int)*string1); c2 = tolower((int)*string2); string1++; string2++; } while ((c1 == c2) && (c1)); return (c1 - c2); } #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) || defined (ACPI_DEBUG_OUTPUT) /******************************************************************************* * * FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat * * PARAMETERS: Adds a "DestSize" parameter to each of the standard string * functions. This is the size of the Destination buffer. * * RETURN: TRUE if the operation would overflow the destination buffer. * * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that * the result of the operation will not overflow the output string * buffer. * * NOTE: These functions are typically only helpful for processing * user input and command lines. For most ACPICA code, the * required buffer length is precisely calculated before buffer * allocation, so the use of these functions is unnecessary. * ******************************************************************************/ u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source) { if (strlen(source) >= dest_size) { return (TRUE); } strcpy(dest, source); return (FALSE); } u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source) { if ((strlen(dest) + strlen(source)) >= dest_size) { return (TRUE); } strcat(dest, source); return (FALSE); } u8 acpi_ut_safe_strncat(char *dest, acpi_size dest_size, char *source, acpi_size max_transfer_length) { acpi_size actual_transfer_length; actual_transfer_length = ACPI_MIN(max_transfer_length, strlen(source)); if ((strlen(dest) + actual_transfer_length) >= dest_size) { return (TRUE); } strncat(dest, source, max_transfer_length); return (FALSE); } void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size) { /* Always terminate destination string */ strncpy(dest, source, dest_size); dest[dest_size - 1] = 0; } #endif
linux-master
drivers/acpi/acpica/utnonansi.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: tbxfload - Table load/unload external interfaces * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "actables.h" #include "acevents.h" #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbxfload") /******************************************************************************* * * FUNCTION: acpi_load_tables * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT * ******************************************************************************/ acpi_status ACPI_INIT_FUNCTION acpi_load_tables(void) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_load_tables); /* * Install the default operation region handlers. These are the * handlers that are defined by the ACPI specification to be * "always accessible" -- namely, system_memory, system_IO, and * PCI_Config. This also means that no _REG methods need to be * run for these address spaces. We need to have these handlers * installed before any AML code can be executed, especially any * module-level code (11/2015). * Note that we allow OSPMs to install their own region handlers * between acpi_initialize_subsystem() and acpi_load_tables() to use * their customized default region handlers. */ status = acpi_ev_install_region_handlers(); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "During Region initialization")); return_ACPI_STATUS(status); } /* Load the namespace from the tables */ status = acpi_tb_load_namespace(); /* Don't let single failures abort the load */ if (status == AE_CTRL_TERMINATE) { status = AE_OK; } if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "While loading namespace from ACPI tables")); } /* * Initialize the objects in the namespace that remain uninitialized. * This runs the executable AML that may be part of the declaration of * these name objects: * operation_regions, buffer_fields, Buffers, and Packages. * */ status = acpi_ns_initialize_objects(); if (ACPI_SUCCESS(status)) { acpi_gbl_namespace_initialized = TRUE; } return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables) /******************************************************************************* * * FUNCTION: acpi_tb_load_namespace * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in * the RSDT/XSDT. * ******************************************************************************/ acpi_status acpi_tb_load_namespace(void) { acpi_status status; u32 i; struct acpi_table_header *new_dsdt; struct acpi_table_desc *table; u32 tables_loaded = 0; u32 tables_failed = 0; ACPI_FUNCTION_TRACE(tb_load_namespace); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); /* * Load the namespace. The DSDT is required, but any SSDT and * PSDT tables are optional. Verify the DSDT. */ table = &acpi_gbl_root_table_list.tables[acpi_gbl_dsdt_index]; if (!acpi_gbl_root_table_list.current_table_count || !ACPI_COMPARE_NAMESEG(table->signature.ascii, ACPI_SIG_DSDT) || ACPI_FAILURE(acpi_tb_validate_table(table))) { status = AE_NO_ACPI_TABLES; goto unlock_and_exit; } /* * Save the DSDT pointer for simple access. This is the mapped memory * address. We must take care here because the address of the .Tables * array can change dynamically as tables are loaded at run-time. Note: * .Pointer field is not validated until after call to acpi_tb_validate_table. */ acpi_gbl_DSDT = table->pointer; /* * Optionally copy the entire DSDT to local memory (instead of simply * mapping it.) There are some BIOSs that corrupt or replace the original * DSDT, creating the need for this option. Default is FALSE, do not copy * the DSDT. */ if (acpi_gbl_copy_dsdt_locally) { new_dsdt = acpi_tb_copy_dsdt(acpi_gbl_dsdt_index); if (new_dsdt) { acpi_gbl_DSDT = new_dsdt; } } /* * Save the original DSDT header for detection of table corruption * and/or replacement of the DSDT from outside the OS. */ memcpy(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT, sizeof(struct acpi_table_header)); /* Load and parse tables */ (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); status = acpi_ns_load_table(acpi_gbl_dsdt_index, acpi_gbl_root_node); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "[DSDT] table load failed")); tables_failed++; } else { tables_loaded++; } /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { table = &acpi_gbl_root_table_list.tables[i]; if (!table->address || (!ACPI_COMPARE_NAMESEG (table->signature.ascii, ACPI_SIG_SSDT) && !ACPI_COMPARE_NAMESEG(table->signature.ascii, ACPI_SIG_PSDT) && !ACPI_COMPARE_NAMESEG(table->signature.ascii, ACPI_SIG_OSDT)) || ACPI_FAILURE(acpi_tb_validate_table(table))) { continue; } /* Ignore errors while loading tables, get as many as possible */ (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); status = acpi_ns_load_table(i, acpi_gbl_root_node); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "(%4.4s:%8.8s) while loading table", table->signature.ascii, table->pointer->oem_table_id)); tables_failed++; ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n", table->signature.ascii, table->pointer->oem_table_id)); } else { tables_loaded++; } } if (!tables_failed) { ACPI_INFO(("%u ACPI AML tables successfully acquired and loaded", tables_loaded)); } else { ACPI_ERROR((AE_INFO, "%u table load failures, %u successful", tables_failed, tables_loaded)); /* Indicate at least one failure */ status = AE_CTRL_TERMINATE; } #ifdef ACPI_APPLICATION ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "\n")); #endif unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_install_table * * PARAMETERS: table - Pointer to the ACPI table to be installed. * * RETURN: Status * * DESCRIPTION: Dynamically install an ACPI table. * Note: This function should only be invoked after * acpi_initialize_tables() and before acpi_load_tables(). * ******************************************************************************/ acpi_status ACPI_INIT_FUNCTION acpi_install_table(struct acpi_table_header *table) { acpi_status status; u32 table_index; ACPI_FUNCTION_TRACE(acpi_install_table); status = acpi_tb_install_standard_table(ACPI_PTR_TO_PHYSADDR(table), ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, table, FALSE, FALSE, &table_index); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL_INIT(acpi_install_table) /******************************************************************************* * * FUNCTION: acpi_install_physical_table * * PARAMETERS: address - Address of the ACPI table to be installed. * * RETURN: Status * * DESCRIPTION: Dynamically install an ACPI table. * Note: This function should only be invoked after * acpi_initialize_tables() and before acpi_load_tables(). * ******************************************************************************/ acpi_status ACPI_INIT_FUNCTION acpi_install_physical_table(acpi_physical_address address) { acpi_status status; u32 table_index; ACPI_FUNCTION_TRACE(acpi_install_physical_table); status = acpi_tb_install_standard_table(address, ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, FALSE, &table_index); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL_INIT(acpi_install_physical_table) /******************************************************************************* * * FUNCTION: acpi_load_table * * PARAMETERS: table - Pointer to a buffer containing the ACPI * table to be loaded. * table_idx - Pointer to a u32 for storing the table * index, might be NULL * * RETURN: Status * * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must * be a valid ACPI table with a valid ACPI table header. * Note1: Mainly intended to support hotplug addition of SSDTs. * Note2: Does not copy the incoming table. User is responsible * to ensure that the table is not deleted or unmapped. * ******************************************************************************/ acpi_status acpi_load_table(struct acpi_table_header *table, u32 *table_idx) { acpi_status status; u32 table_index; ACPI_FUNCTION_TRACE(acpi_load_table); /* Parameter validation */ if (!table) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Install the table and load it into the namespace */ ACPI_INFO(("Host-directed Dynamic ACPI Table Load:")); status = acpi_tb_install_and_load_table(ACPI_PTR_TO_PHYSADDR(table), ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, table, FALSE, &table_index); if (table_idx) { *table_idx = table_index; } if (ACPI_SUCCESS(status)) { /* Complete the initialization/resolution of new objects */ acpi_ns_initialize_objects(); } return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_load_table) /******************************************************************************* * * FUNCTION: acpi_unload_parent_table * * PARAMETERS: object - Handle to any namespace object owned by * the table to be unloaded * * RETURN: Status * * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads * the table and deletes all namespace objects associated with * that table. Unloading of the DSDT is not allowed. * Note: Mainly intended to support hotplug removal of SSDTs. * ******************************************************************************/ acpi_status acpi_unload_parent_table(acpi_handle object) { struct acpi_namespace_node *node = ACPI_CAST_PTR(struct acpi_namespace_node, object); acpi_status status = AE_NOT_EXIST; acpi_owner_id owner_id; u32 i; ACPI_FUNCTION_TRACE(acpi_unload_parent_table); /* Parameter validation */ if (!object) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * The node owner_id is currently the same as the parent table ID. * However, this could change in the future. */ owner_id = node->owner_id; if (!owner_id) { /* owner_id==0 means DSDT is the owner. DSDT cannot be unloaded */ return_ACPI_STATUS(AE_TYPE); } /* Must acquire the table lock during this operation */ status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Find the table in the global table list */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { if (owner_id != acpi_gbl_root_table_list.tables[i].owner_id) { continue; } /* * Allow unload of SSDT and OEMx tables only. Do not allow unload * of the DSDT. No other types of tables should get here, since * only these types can contain AML and thus are the only types * that can create namespace objects. */ if (ACPI_COMPARE_NAMESEG (acpi_gbl_root_table_list.tables[i].signature.ascii, ACPI_SIG_DSDT)) { status = AE_TYPE; break; } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); status = acpi_tb_unload_table(i); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); break; } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_unload_parent_table) /******************************************************************************* * * FUNCTION: acpi_unload_table * * PARAMETERS: table_index - Index as returned by acpi_load_table * * RETURN: Status * * DESCRIPTION: Via the table_index representing an SSDT or OEMx table, unloads * the table and deletes all namespace objects associated with * that table. Unloading of the DSDT is not allowed. * Note: Mainly intended to support hotplug removal of SSDTs. * ******************************************************************************/ acpi_status acpi_unload_table(u32 table_index) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_unload_table); if (table_index == 1) { /* table_index==1 means DSDT is the owner. DSDT cannot be unloaded */ return_ACPI_STATUS(AE_TYPE); } status = acpi_tb_unload_table(table_index); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_unload_table)
linux-master
drivers/acpi/acpica/tbxfload.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dscontrol - Support for execution control opcodes - * if/else/while/return * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "amlcode.h" #include "acdispat.h" #include "acinterp.h" #include "acdebug.h" #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dscontrol") /******************************************************************************* * * FUNCTION: acpi_ds_exec_begin_control_op * * PARAMETERS: walk_list - The list that owns the walk stack * op - The control Op * * RETURN: Status * * DESCRIPTION: Handles all control ops encountered during control method * execution. * ******************************************************************************/ acpi_status acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state, union acpi_parse_object *op) { acpi_status status = AE_OK; union acpi_generic_state *control_state; ACPI_FUNCTION_NAME(ds_exec_begin_control_op); ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op, op->common.aml_opcode, walk_state)); switch (op->common.aml_opcode) { case AML_WHILE_OP: /* * If this is an additional iteration of a while loop, continue. * There is no need to allocate a new control state. */ if (walk_state->control_state) { if (walk_state->control_state->control. aml_predicate_start == (walk_state->parser_state.aml - 1)) { /* Reset the state to start-of-loop */ walk_state->control_state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING; break; } } ACPI_FALLTHROUGH; case AML_IF_OP: /* * IF/WHILE: Create a new control state to manage these * constructs. We need to manage these as a stack, in order * to handle nesting. */ control_state = acpi_ut_create_control_state(); if (!control_state) { status = AE_NO_MEMORY; break; } /* * Save a pointer to the predicate for multiple executions * of a loop */ control_state->control.aml_predicate_start = walk_state->parser_state.aml - 1; control_state->control.package_end = walk_state->parser_state.pkg_end; control_state->control.opcode = op->common.aml_opcode; control_state->control.loop_timeout = acpi_os_get_timer() + ((u64)acpi_gbl_max_loop_iterations * ACPI_100NSEC_PER_SEC); /* Push the control state on this walk's control stack */ acpi_ut_push_generic_state(&walk_state->control_state, control_state); break; case AML_ELSE_OP: /* Predicate is in the state object */ /* If predicate is true, the IF was executed, ignore ELSE part */ if (walk_state->last_predicate) { status = AE_CTRL_TRUE; } break; case AML_RETURN_OP: break; default: break; } return (status); } /******************************************************************************* * * FUNCTION: acpi_ds_exec_end_control_op * * PARAMETERS: walk_list - The list that owns the walk stack * op - The control Op * * RETURN: Status * * DESCRIPTION: Handles all control ops encountered during control method * execution. * ******************************************************************************/ acpi_status acpi_ds_exec_end_control_op(struct acpi_walk_state *walk_state, union acpi_parse_object *op) { acpi_status status = AE_OK; union acpi_generic_state *control_state; ACPI_FUNCTION_NAME(ds_exec_end_control_op); switch (op->common.aml_opcode) { case AML_IF_OP: ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op)); /* * Save the result of the predicate in case there is an * ELSE to come */ walk_state->last_predicate = (u8)walk_state->control_state->common.value; /* * Pop the control state that was created at the start * of the IF and free it */ control_state = acpi_ut_pop_generic_state(&walk_state->control_state); acpi_ut_delete_generic_state(control_state); break; case AML_ELSE_OP: break; case AML_WHILE_OP: ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op)); control_state = walk_state->control_state; if (control_state->common.value) { /* Predicate was true, the body of the loop was just executed */ /* * This infinite loop detection mechanism allows the interpreter * to escape possibly infinite loops. This can occur in poorly * written AML when the hardware does not respond within a while * loop and the loop does not implement a timeout. */ if (ACPI_TIME_AFTER(acpi_os_get_timer(), control_state->control. loop_timeout)) { status = AE_AML_LOOP_TIMEOUT; break; } /* * Go back and evaluate the predicate and maybe execute the loop * another time */ status = AE_CTRL_PENDING; walk_state->aml_last_while = control_state->control.aml_predicate_start; break; } /* Predicate was false, terminate this while loop */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] termination! Op=%p\n", op)); /* Pop this control state and free it */ control_state = acpi_ut_pop_generic_state(&walk_state->control_state); acpi_ut_delete_generic_state(control_state); break; case AML_RETURN_OP: ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[RETURN_OP] Op=%p Arg=%p\n", op, op->common.value.arg)); /* * One optional operand -- the return value * It can be either an immediate operand or a result that * has been bubbled up the tree */ if (op->common.value.arg) { /* Since we have a real Return(), delete any implicit return */ acpi_ds_clear_implicit_return(walk_state); /* Return statement has an immediate operand */ status = acpi_ds_create_operands(walk_state, op->common.value.arg); if (ACPI_FAILURE(status)) { return (status); } /* * If value being returned is a Reference (such as * an arg or local), resolve it now because it may * cease to exist at the end of the method. */ status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state); if (ACPI_FAILURE(status)) { return (status); } /* * Get the return value and save as the last result * value. This is the only place where walk_state->return_desc * is set to anything other than zero! */ walk_state->return_desc = walk_state->operands[0]; } else if (walk_state->result_count) { /* Since we have a real Return(), delete any implicit return */ acpi_ds_clear_implicit_return(walk_state); /* * The return value has come from a previous calculation. * * If value being returned is a Reference (such as * an arg or local), resolve it now because it may * cease to exist at the end of the method. * * Allow references created by the Index operator to return * unchanged. */ if ((ACPI_GET_DESCRIPTOR_TYPE (walk_state->results->results.obj_desc[0]) == ACPI_DESC_TYPE_OPERAND) && ((walk_state->results->results.obj_desc[0])-> common.type == ACPI_TYPE_LOCAL_REFERENCE) && ((walk_state->results->results.obj_desc[0])-> reference.class != ACPI_REFCLASS_INDEX)) { status = acpi_ex_resolve_to_value(&walk_state-> results->results. obj_desc[0], walk_state); if (ACPI_FAILURE(status)) { return (status); } } walk_state->return_desc = walk_state->results->results.obj_desc[0]; } else { /* No return operand */ if (walk_state->num_operands) { acpi_ut_remove_reference(walk_state-> operands[0]); } walk_state->operands[0] = NULL; walk_state->num_operands = 0; walk_state->return_desc = NULL; } ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Completed RETURN_OP State=%p, RetVal=%p\n", walk_state, walk_state->return_desc)); /* End the control method execution right now */ status = AE_CTRL_TERMINATE; break; case AML_NOOP_OP: /* Just do nothing! */ break; case AML_BREAKPOINT_OP: acpi_db_signal_break_point(walk_state); /* Call to the OSL in case OS wants a piece of the action */ status = acpi_os_signal(ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode"); break; case AML_BREAK_OP: case AML_CONTINUE_OP: /* ACPI 2.0 */ /* Pop and delete control states until we find a while */ while (walk_state->control_state && (walk_state->control_state->control.opcode != AML_WHILE_OP)) { control_state = acpi_ut_pop_generic_state(&walk_state-> control_state); acpi_ut_delete_generic_state(control_state); } /* No while found? */ if (!walk_state->control_state) { return (AE_AML_NO_WHILE); } /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */ walk_state->aml_last_while = walk_state->control_state->control.package_end; /* Return status depending on opcode */ if (op->common.aml_opcode == AML_BREAK_OP) { status = AE_CTRL_BREAK; } else { status = AE_CTRL_CONTINUE; } break; default: ACPI_ERROR((AE_INFO, "Unknown control opcode=0x%X Op=%p", op->common.aml_opcode, op)); status = AE_AML_BAD_OPCODE; break; } return (status); }
linux-master
drivers/acpi/acpica/dscontrol.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utobject - ACPI object create/delete/size/cache routines * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include <linux/kmemleak.h> #include "accommon.h" #include "acnamesp.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utobject") /* Local prototypes */ static acpi_status acpi_ut_get_simple_object_size(union acpi_operand_object *obj, acpi_size *obj_length); static acpi_status acpi_ut_get_package_object_size(union acpi_operand_object *obj, acpi_size *obj_length); static acpi_status acpi_ut_get_element_length(u8 object_type, union acpi_operand_object *source_object, union acpi_generic_state *state, void *context); /******************************************************************************* * * FUNCTION: acpi_ut_create_internal_object_dbg * * PARAMETERS: module_name - Source file name of caller * line_number - Line number of caller * component_id - Component type of caller * type - ACPI Type of the new object * * RETURN: A new internal object, null on failure * * DESCRIPTION: Create and initialize a new internal object. * * NOTE: We always allocate the worst-case object descriptor because * these objects are cached, and we want them to be * one-size-satisfies-any-request. This in itself may not be * the most memory efficient, but the efficiency of the object * cache should more than make up for this! * ******************************************************************************/ union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char *module_name, u32 line_number, u32 component_id, acpi_object_type type) { union acpi_operand_object *object; union acpi_operand_object *second_object; ACPI_FUNCTION_TRACE_STR(ut_create_internal_object_dbg, acpi_ut_get_type_name(type)); /* Allocate the raw object descriptor */ object = acpi_ut_allocate_object_desc_dbg(module_name, line_number, component_id); if (!object) { return_PTR(NULL); } kmemleak_not_leak(object); switch (type) { case ACPI_TYPE_REGION: case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: /* These types require a secondary object */ second_object = acpi_ut_allocate_object_desc_dbg(module_name, line_number, component_id); if (!second_object) { acpi_ut_delete_object_desc(object); return_PTR(NULL); } second_object->common.type = ACPI_TYPE_LOCAL_EXTRA; second_object->common.reference_count = 1; /* Link the second object to the first */ object->common.next_object = second_object; break; default: /* All others have no secondary object */ break; } /* Save the object type in the object descriptor */ object->common.type = (u8) type; /* Init the reference count */ object->common.reference_count = 1; /* Any per-type initialization should go here */ return_PTR(object); } /******************************************************************************* * * FUNCTION: acpi_ut_create_package_object * * PARAMETERS: count - Number of package elements * * RETURN: Pointer to a new Package object, null on failure * * DESCRIPTION: Create a fully initialized package object * ******************************************************************************/ union acpi_operand_object *acpi_ut_create_package_object(u32 count) { union acpi_operand_object *package_desc; union acpi_operand_object **package_elements; ACPI_FUNCTION_TRACE_U32(ut_create_package_object, count); /* Create a new Package object */ package_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE); if (!package_desc) { return_PTR(NULL); } /* * Create the element array. Count+1 allows the array to be null * terminated. */ package_elements = ACPI_ALLOCATE_ZEROED(((acpi_size)count + 1) * sizeof(void *)); if (!package_elements) { ACPI_FREE(package_desc); return_PTR(NULL); } package_desc->package.count = count; package_desc->package.elements = package_elements; return_PTR(package_desc); } /******************************************************************************* * * FUNCTION: acpi_ut_create_integer_object * * PARAMETERS: initial_value - Initial value for the integer * * RETURN: Pointer to a new Integer object, null on failure * * DESCRIPTION: Create an initialized integer object * ******************************************************************************/ union acpi_operand_object *acpi_ut_create_integer_object(u64 initial_value) { union acpi_operand_object *integer_desc; ACPI_FUNCTION_TRACE(ut_create_integer_object); /* Create and initialize a new integer object */ integer_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); if (!integer_desc) { return_PTR(NULL); } integer_desc->integer.value = initial_value; return_PTR(integer_desc); } /******************************************************************************* * * FUNCTION: acpi_ut_create_buffer_object * * PARAMETERS: buffer_size - Size of buffer to be created * * RETURN: Pointer to a new Buffer object, null on failure * * DESCRIPTION: Create a fully initialized buffer object * ******************************************************************************/ union acpi_operand_object *acpi_ut_create_buffer_object(acpi_size buffer_size) { union acpi_operand_object *buffer_desc; u8 *buffer = NULL; ACPI_FUNCTION_TRACE_U32(ut_create_buffer_object, buffer_size); /* Create a new Buffer object */ buffer_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER); if (!buffer_desc) { return_PTR(NULL); } /* Create an actual buffer only if size > 0 */ if (buffer_size > 0) { /* Allocate the actual buffer */ buffer = ACPI_ALLOCATE_ZEROED(buffer_size); if (!buffer) { ACPI_ERROR((AE_INFO, "Could not allocate size %u", (u32)buffer_size)); acpi_ut_remove_reference(buffer_desc); return_PTR(NULL); } } /* Complete buffer object initialization */ buffer_desc->buffer.flags |= AOPOBJ_DATA_VALID; buffer_desc->buffer.pointer = buffer; buffer_desc->buffer.length = (u32) buffer_size; /* Return the new buffer descriptor */ return_PTR(buffer_desc); } /******************************************************************************* * * FUNCTION: acpi_ut_create_string_object * * PARAMETERS: string_size - Size of string to be created. Does not * include NULL terminator, this is added * automatically. * * RETURN: Pointer to a new String object * * DESCRIPTION: Create a fully initialized string object * ******************************************************************************/ union acpi_operand_object *acpi_ut_create_string_object(acpi_size string_size) { union acpi_operand_object *string_desc; char *string; ACPI_FUNCTION_TRACE_U32(ut_create_string_object, string_size); /* Create a new String object */ string_desc = acpi_ut_create_internal_object(ACPI_TYPE_STRING); if (!string_desc) { return_PTR(NULL); } /* * Allocate the actual string buffer -- (Size + 1) for NULL terminator. * NOTE: Zero-length strings are NULL terminated */ string = ACPI_ALLOCATE_ZEROED(string_size + 1); if (!string) { ACPI_ERROR((AE_INFO, "Could not allocate size %u", (u32)string_size)); acpi_ut_remove_reference(string_desc); return_PTR(NULL); } /* Complete string object initialization */ string_desc->string.pointer = string; string_desc->string.length = (u32) string_size; /* Return the new string descriptor */ return_PTR(string_desc); } /******************************************************************************* * * FUNCTION: acpi_ut_valid_internal_object * * PARAMETERS: object - Object to be validated * * RETURN: TRUE if object is valid, FALSE otherwise * * DESCRIPTION: Validate a pointer to be of type union acpi_operand_object * ******************************************************************************/ u8 acpi_ut_valid_internal_object(void *object) { ACPI_FUNCTION_NAME(ut_valid_internal_object); /* Check for a null pointer */ if (!object) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "**** Null Object Ptr\n")); return (FALSE); } /* Check the descriptor type field */ switch (ACPI_GET_DESCRIPTOR_TYPE(object)) { case ACPI_DESC_TYPE_OPERAND: /* The object appears to be a valid union acpi_operand_object */ return (TRUE); default: ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%p is not an ACPI operand obj [%s]\n", object, acpi_ut_get_descriptor_name(object))); break; } return (FALSE); } /******************************************************************************* * * FUNCTION: acpi_ut_allocate_object_desc_dbg * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * component_id - Caller's component ID (for error output) * * RETURN: Pointer to newly allocated object descriptor. Null on error * * DESCRIPTION: Allocate a new object descriptor. Gracefully handle * error conditions. * ******************************************************************************/ void *acpi_ut_allocate_object_desc_dbg(const char *module_name, u32 line_number, u32 component_id) { union acpi_operand_object *object; ACPI_FUNCTION_TRACE(ut_allocate_object_desc_dbg); object = acpi_os_acquire_object(acpi_gbl_operand_cache); if (!object) { ACPI_ERROR((module_name, line_number, "Could not allocate an object descriptor")); return_PTR(NULL); } /* Mark the descriptor type */ ACPI_SET_DESCRIPTOR_TYPE(object, ACPI_DESC_TYPE_OPERAND); ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "%p Size %X\n", object, (u32) sizeof(union acpi_operand_object))); return_PTR(object); } /******************************************************************************* * * FUNCTION: acpi_ut_delete_object_desc * * PARAMETERS: object - An Acpi internal object to be deleted * * RETURN: None. * * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache * ******************************************************************************/ void acpi_ut_delete_object_desc(union acpi_operand_object *object) { ACPI_FUNCTION_TRACE_PTR(ut_delete_object_desc, object); /* Object must be of type union acpi_operand_object */ if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) { ACPI_ERROR((AE_INFO, "%p is not an ACPI Operand object [%s]", object, acpi_ut_get_descriptor_name(object))); return_VOID; } (void)acpi_os_release_object(acpi_gbl_operand_cache, object); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ut_get_simple_object_size * * PARAMETERS: internal_object - An ACPI operand object * obj_length - Where the length is returned * * RETURN: Status * * DESCRIPTION: This function is called to determine the space required to * contain a simple object for return to an external user. * * The length includes the object structure plus any additional * needed space. * ******************************************************************************/ static acpi_status acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object, acpi_size *obj_length) { acpi_size length; acpi_size size; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE_PTR(ut_get_simple_object_size, internal_object); /* Start with the length of the (external) Acpi object */ length = sizeof(union acpi_object); /* A NULL object is allowed, can be a legal uninitialized package element */ if (!internal_object) { /* * Object is NULL, just return the length of union acpi_object * (A NULL union acpi_object is an object of all zeroes.) */ *obj_length = ACPI_ROUND_UP_TO_NATIVE_WORD(length); return_ACPI_STATUS(AE_OK); } /* A Namespace Node should never appear here */ if (ACPI_GET_DESCRIPTOR_TYPE(internal_object) == ACPI_DESC_TYPE_NAMED) { /* A namespace node should never get here */ ACPI_ERROR((AE_INFO, "Received a namespace node [%4.4s] " "where an operand object is required", ACPI_CAST_PTR(struct acpi_namespace_node, internal_object)->name.ascii)); return_ACPI_STATUS(AE_AML_INTERNAL); } /* * The final length depends on the object type * Strings and Buffers are packed right up against the parent object and * must be accessed bytewise or there may be alignment problems on * certain processors */ switch (internal_object->common.type) { case ACPI_TYPE_STRING: length += (acpi_size)internal_object->string.length + 1; break; case ACPI_TYPE_BUFFER: length += (acpi_size)internal_object->buffer.length; break; case ACPI_TYPE_INTEGER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_POWER: /* No extra data for these types */ break; case ACPI_TYPE_LOCAL_REFERENCE: switch (internal_object->reference.class) { case ACPI_REFCLASS_NAME: /* * Get the actual length of the full pathname to this object. * The reference will be converted to the pathname to the object */ size = acpi_ns_get_pathname_length(internal_object-> reference.node); if (!size) { return_ACPI_STATUS(AE_BAD_PARAMETER); } length += ACPI_ROUND_UP_TO_NATIVE_WORD(size); break; default: /* * No other reference opcodes are supported. * Notably, Locals and Args are not supported, but this may be * required eventually. */ ACPI_ERROR((AE_INFO, "Cannot convert to external object - " "unsupported Reference Class [%s] 0x%X in object %p", acpi_ut_get_reference_name(internal_object), internal_object->reference.class, internal_object)); status = AE_TYPE; break; } break; default: ACPI_ERROR((AE_INFO, "Cannot convert to external object - " "unsupported type [%s] 0x%X in object %p", acpi_ut_get_object_type_name(internal_object), internal_object->common.type, internal_object)); status = AE_TYPE; break; } /* * Account for the space required by the object rounded up to the next * multiple of the machine word size. This keeps each object aligned * on a machine word boundary. (preventing alignment faults on some * machines.) */ *obj_length = ACPI_ROUND_UP_TO_NATIVE_WORD(length); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ut_get_element_length * * PARAMETERS: acpi_pkg_callback * * RETURN: Status * * DESCRIPTION: Get the length of one package element. * ******************************************************************************/ static acpi_status acpi_ut_get_element_length(u8 object_type, union acpi_operand_object *source_object, union acpi_generic_state *state, void *context) { acpi_status status = AE_OK; struct acpi_pkg_info *info = (struct acpi_pkg_info *)context; acpi_size object_space; switch (object_type) { case ACPI_COPY_TYPE_SIMPLE: /* * Simple object - just get the size (Null object/entry is handled * here also) and sum it into the running package length */ status = acpi_ut_get_simple_object_size(source_object, &object_space); if (ACPI_FAILURE(status)) { return (status); } info->length += object_space; break; case ACPI_COPY_TYPE_PACKAGE: /* Package object - nothing much to do here, let the walk handle it */ info->num_packages++; state->pkg.this_target_obj = NULL; break; default: /* No other types allowed */ return (AE_BAD_PARAMETER); } return (status); } /******************************************************************************* * * FUNCTION: acpi_ut_get_package_object_size * * PARAMETERS: internal_object - An ACPI internal object * obj_length - Where the length is returned * * RETURN: Status * * DESCRIPTION: This function is called to determine the space required to * contain a package object for return to an external user. * * This is moderately complex since a package contains other * objects including packages. * ******************************************************************************/ static acpi_status acpi_ut_get_package_object_size(union acpi_operand_object *internal_object, acpi_size *obj_length) { acpi_status status; struct acpi_pkg_info info; ACPI_FUNCTION_TRACE_PTR(ut_get_package_object_size, internal_object); info.length = 0; info.object_space = 0; info.num_packages = 1; status = acpi_ut_walk_package_tree(internal_object, NULL, acpi_ut_get_element_length, &info); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * We have handled all of the objects in all levels of the package. * just add the length of the package objects themselves. * Round up to the next machine word. */ info.length += ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)) * (acpi_size)info.num_packages; /* Return the total package length */ *obj_length = info.length; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ut_get_object_size * * PARAMETERS: internal_object - An ACPI internal object * obj_length - Where the length will be returned * * RETURN: Status * * DESCRIPTION: This function is called to determine the space required to * contain an object for return to an API user. * ******************************************************************************/ acpi_status acpi_ut_get_object_size(union acpi_operand_object *internal_object, acpi_size *obj_length) { acpi_status status; ACPI_FUNCTION_ENTRY(); if ((ACPI_GET_DESCRIPTOR_TYPE(internal_object) == ACPI_DESC_TYPE_OPERAND) && (internal_object->common.type == ACPI_TYPE_PACKAGE)) { status = acpi_ut_get_package_object_size(internal_object, obj_length); } else { status = acpi_ut_get_simple_object_size(internal_object, obj_length); } return (status); }
linux-master
drivers/acpi/acpica/utobject.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dsopcode - Dispatcher support for regions and fields * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "amlcode.h" #include "acdispat.h" #include "acinterp.h" #include "acnamesp.h" #include "acevents.h" #include "actables.h" #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dsopcode") /* Local prototypes */ static acpi_status acpi_ds_init_buffer_field(u16 aml_opcode, union acpi_operand_object *obj_desc, union acpi_operand_object *buffer_desc, union acpi_operand_object *offset_desc, union acpi_operand_object *length_desc, union acpi_operand_object *result_desc); /******************************************************************************* * * FUNCTION: acpi_ds_initialize_region * * PARAMETERS: obj_handle - Region namespace node * * RETURN: Status * * DESCRIPTION: Front end to ev_initialize_region * ******************************************************************************/ acpi_status acpi_ds_initialize_region(acpi_handle obj_handle) { union acpi_operand_object *obj_desc; acpi_status status; obj_desc = acpi_ns_get_attached_object(obj_handle); /* Namespace is NOT locked */ status = acpi_ev_initialize_region(obj_desc); return (status); } /******************************************************************************* * * FUNCTION: acpi_ds_init_buffer_field * * PARAMETERS: aml_opcode - create_xxx_field * obj_desc - buffer_field object * buffer_desc - Host Buffer * offset_desc - Offset into buffer * length_desc - Length of field (CREATE_FIELD_OP only) * result_desc - Where to store the result * * RETURN: Status * * DESCRIPTION: Perform actual initialization of a buffer field * ******************************************************************************/ static acpi_status acpi_ds_init_buffer_field(u16 aml_opcode, union acpi_operand_object *obj_desc, union acpi_operand_object *buffer_desc, union acpi_operand_object *offset_desc, union acpi_operand_object *length_desc, union acpi_operand_object *result_desc) { u32 offset; u32 bit_offset; u32 bit_count; u8 field_flags; acpi_status status; ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc); /* Host object must be a Buffer */ if (buffer_desc->common.type != ACPI_TYPE_BUFFER) { ACPI_ERROR((AE_INFO, "Target of Create Field is not a Buffer object - %s", acpi_ut_get_object_type_name(buffer_desc))); status = AE_AML_OPERAND_TYPE; goto cleanup; } /* * The last parameter to all of these opcodes (result_desc) started * out as a name_string, and should therefore now be a NS node * after resolution in acpi_ex_resolve_operands(). */ if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) { ACPI_ERROR((AE_INFO, "(%s) destination not a NS Node [%s]", acpi_ps_get_opcode_name(aml_opcode), acpi_ut_get_descriptor_name(result_desc))); status = AE_AML_OPERAND_TYPE; goto cleanup; } offset = (u32) offset_desc->integer.value; /* * Setup the Bit offsets and counts, according to the opcode */ switch (aml_opcode) { case AML_CREATE_FIELD_OP: /* Offset is in bits, count is in bits */ field_flags = AML_FIELD_ACCESS_BYTE; bit_offset = offset; bit_count = (u32) length_desc->integer.value; /* Must have a valid (>0) bit count */ if (bit_count == 0) { ACPI_BIOS_ERROR((AE_INFO, "Attempt to CreateField of length zero")); status = AE_AML_OPERAND_VALUE; goto cleanup; } break; case AML_CREATE_BIT_FIELD_OP: /* Offset is in bits, Field is one bit */ bit_offset = offset; bit_count = 1; field_flags = AML_FIELD_ACCESS_BYTE; break; case AML_CREATE_BYTE_FIELD_OP: /* Offset is in bytes, field is one byte */ bit_offset = 8 * offset; bit_count = 8; field_flags = AML_FIELD_ACCESS_BYTE; break; case AML_CREATE_WORD_FIELD_OP: /* Offset is in bytes, field is one word */ bit_offset = 8 * offset; bit_count = 16; field_flags = AML_FIELD_ACCESS_WORD; break; case AML_CREATE_DWORD_FIELD_OP: /* Offset is in bytes, field is one dword */ bit_offset = 8 * offset; bit_count = 32; field_flags = AML_FIELD_ACCESS_DWORD; break; case AML_CREATE_QWORD_FIELD_OP: /* Offset is in bytes, field is one qword */ bit_offset = 8 * offset; bit_count = 64; field_flags = AML_FIELD_ACCESS_QWORD; break; default: ACPI_ERROR((AE_INFO, "Unknown field creation opcode 0x%02X", aml_opcode)); status = AE_AML_BAD_OPCODE; goto cleanup; } /* Entire field must fit within the current length of the buffer */ if ((bit_offset + bit_count) > (8 * (u32)buffer_desc->buffer.length)) { status = AE_AML_BUFFER_LIMIT; ACPI_BIOS_EXCEPTION((AE_INFO, status, "Field [%4.4s] at bit offset/length %u/%u " "exceeds size of target Buffer (%u bits)", acpi_ut_get_node_name(result_desc), bit_offset, bit_count, 8 * (u32)buffer_desc->buffer.length)); goto cleanup; } /* * Initialize areas of the field object that are common to all fields * For field_flags, use LOCK_RULE = 0 (NO_LOCK), * UPDATE_RULE = 0 (UPDATE_PRESERVE) */ status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0, bit_offset, bit_count); if (ACPI_FAILURE(status)) { goto cleanup; } obj_desc->buffer_field.buffer_obj = buffer_desc; obj_desc->buffer_field.is_create_field = aml_opcode == AML_CREATE_FIELD_OP; /* Reference count for buffer_desc inherits obj_desc count */ buffer_desc->common.reference_count = (u16) (buffer_desc->common.reference_count + obj_desc->common.reference_count); cleanup: /* Always delete the operands */ acpi_ut_remove_reference(offset_desc); acpi_ut_remove_reference(buffer_desc); if (aml_opcode == AML_CREATE_FIELD_OP) { acpi_ut_remove_reference(length_desc); } /* On failure, delete the result descriptor */ if (ACPI_FAILURE(status)) { acpi_ut_remove_reference(result_desc); /* Result descriptor */ } else { /* Now the address and length are valid for this buffer_field */ obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_eval_buffer_field_operands * * PARAMETERS: walk_state - Current walk * op - A valid buffer_field Op object * * RETURN: Status * * DESCRIPTION: Get buffer_field Buffer and Index * Called from acpi_ds_exec_end_op during buffer_field parse tree walk * ******************************************************************************/ acpi_status acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state, union acpi_parse_object *op) { acpi_status status; union acpi_operand_object *obj_desc; struct acpi_namespace_node *node; union acpi_parse_object *next_op; ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op); /* * This is where we evaluate the address and length fields of the * create_xxx_field declaration */ node = op->common.node; /* next_op points to the op that holds the Buffer */ next_op = op->common.value.arg; /* Evaluate/create the address and length operands */ status = acpi_ds_create_operands(walk_state, next_op); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { return_ACPI_STATUS(AE_NOT_EXIST); } /* Resolve the operands */ status = acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS, walk_state); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "(%s) bad operand(s), status 0x%X", acpi_ps_get_opcode_name(op->common.aml_opcode), status)); return_ACPI_STATUS(status); } /* Initialize the Buffer Field */ if (op->common.aml_opcode == AML_CREATE_FIELD_OP) { /* NOTE: Slightly different operands for this opcode */ status = acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc, walk_state->operands[0], walk_state->operands[1], walk_state->operands[2], walk_state->operands[3]); } else { /* All other, create_xxx_field opcodes */ status = acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc, walk_state->operands[0], walk_state->operands[1], NULL, walk_state->operands[2]); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_eval_region_operands * * PARAMETERS: walk_state - Current walk * op - A valid region Op object * * RETURN: Status * * DESCRIPTION: Get region address and length * Called from acpi_ds_exec_end_op during op_region parse tree walk * ******************************************************************************/ acpi_status acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state, union acpi_parse_object *op) { acpi_status status; union acpi_operand_object *obj_desc; union acpi_operand_object *operand_desc; struct acpi_namespace_node *node; union acpi_parse_object *next_op; acpi_adr_space_type space_id; ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op); /* * This is where we evaluate the address and length fields of the * op_region declaration */ node = op->common.node; /* next_op points to the op that holds the space_ID */ next_op = op->common.value.arg; space_id = (acpi_adr_space_type)next_op->common.value.integer; /* next_op points to address op */ next_op = next_op->common.next; /* Evaluate/create the address and length operands */ status = acpi_ds_create_operands(walk_state, next_op); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Resolve the length and address operands to numbers */ status = acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { return_ACPI_STATUS(AE_NOT_EXIST); } /* * Get the length operand and save it * (at Top of stack) */ operand_desc = walk_state->operands[walk_state->num_operands - 1]; obj_desc->region.length = (u32) operand_desc->integer.value; acpi_ut_remove_reference(operand_desc); /* A zero-length operation region is unusable. Just warn */ if (!obj_desc->region.length && (space_id < ACPI_NUM_PREDEFINED_REGIONS)) { ACPI_WARNING((AE_INFO, "Operation Region [%4.4s] has zero length (SpaceId %X)", node->name.ascii, space_id)); } /* * Get the address and save it * (at top of stack - 1) */ operand_desc = walk_state->operands[walk_state->num_operands - 2]; obj_desc->region.address = (acpi_physical_address) operand_desc->integer.value; acpi_ut_remove_reference(operand_desc); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n", obj_desc, ACPI_FORMAT_UINT64(obj_desc->region.address), obj_desc->region.length)); status = acpi_ut_add_address_range(obj_desc->region.space_id, obj_desc->region.address, obj_desc->region.length, node); /* Now the address and length are valid for this opregion */ obj_desc->region.flags |= AOPOBJ_DATA_VALID; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_eval_table_region_operands * * PARAMETERS: walk_state - Current walk * op - A valid region Op object * * RETURN: Status * * DESCRIPTION: Get region address and length. * Called from acpi_ds_exec_end_op during data_table_region parse * tree walk. * ******************************************************************************/ acpi_status acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state, union acpi_parse_object *op) { acpi_status status; union acpi_operand_object *obj_desc; union acpi_operand_object **operand; struct acpi_namespace_node *node; union acpi_parse_object *next_op; struct acpi_table_header *table; u32 table_index; ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op); /* * This is where we evaluate the Signature string, oem_id string, * and oem_table_id string of the Data Table Region declaration */ node = op->common.node; /* next_op points to Signature string op */ next_op = op->common.value.arg; /* * Evaluate/create the Signature string, oem_id string, * and oem_table_id string operands */ status = acpi_ds_create_operands(walk_state, next_op); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } operand = &walk_state->operands[0]; /* * Resolve the Signature string, oem_id string, * and oem_table_id string operands */ status = acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS, walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } /* Find the ACPI table */ status = acpi_tb_find_table(operand[0]->string.pointer, operand[1]->string.pointer, operand[2]->string.pointer, &table_index); if (ACPI_FAILURE(status)) { if (status == AE_NOT_FOUND) { ACPI_ERROR((AE_INFO, "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT", operand[0]->string.pointer, operand[1]->string.pointer, operand[2]->string.pointer)); } goto cleanup; } status = acpi_get_table_by_index(table_index, &table); if (ACPI_FAILURE(status)) { goto cleanup; } obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { status = AE_NOT_EXIST; goto cleanup; } obj_desc->region.address = ACPI_PTR_TO_PHYSADDR(table); obj_desc->region.length = table->length; obj_desc->region.pointer = table; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n", obj_desc, ACPI_FORMAT_UINT64(obj_desc->region.address), obj_desc->region.length)); /* Now the address and length are valid for this opregion */ obj_desc->region.flags |= AOPOBJ_DATA_VALID; cleanup: acpi_ut_remove_reference(operand[0]); acpi_ut_remove_reference(operand[1]); acpi_ut_remove_reference(operand[2]); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_eval_data_object_operands * * PARAMETERS: walk_state - Current walk * op - A valid data_object Op object * obj_desc - data_object * * RETURN: Status * * DESCRIPTION: Get the operands and complete the following data object types: * Buffer, Package. * ******************************************************************************/ acpi_status acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state, union acpi_parse_object *op, union acpi_operand_object *obj_desc) { acpi_status status; union acpi_operand_object *arg_desc; u32 length; ACPI_FUNCTION_TRACE(ds_eval_data_object_operands); /* The first operand (for all of these data objects) is the length */ /* * Set proper index into operand stack for acpi_ds_obj_stack_push * invoked inside acpi_ds_create_operand. */ walk_state->operand_index = walk_state->num_operands; /* Ignore if child is not valid */ if (!op->common.value.arg) { ACPI_ERROR((AE_INFO, "Missing child while evaluating opcode %4.4X, Op %p", op->common.aml_opcode, op)); return_ACPI_STATUS(AE_OK); } status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ex_resolve_operands(walk_state->opcode, &(walk_state-> operands[walk_state->num_operands - 1]), walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Extract length operand */ arg_desc = walk_state->operands[walk_state->num_operands - 1]; length = (u32) arg_desc->integer.value; /* Cleanup for length operand */ status = acpi_ds_obj_stack_pop(1, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_ut_remove_reference(arg_desc); /* * Create the actual data object */ switch (op->common.aml_opcode) { case AML_BUFFER_OP: status = acpi_ds_build_internal_buffer_obj(walk_state, op, length, &obj_desc); break; case AML_PACKAGE_OP: case AML_VARIABLE_PACKAGE_OP: status = acpi_ds_build_internal_package_obj(walk_state, op, length, &obj_desc); break; default: return_ACPI_STATUS(AE_AML_BAD_OPCODE); } if (ACPI_SUCCESS(status)) { /* * Return the object in the walk_state, unless the parent is a package - * in this case, the return object will be stored in the parse tree * for the package. */ if ((!op->common.parent) || ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) && (op->common.parent->common.aml_opcode != AML_VARIABLE_PACKAGE_OP) && (op->common.parent->common.aml_opcode != AML_NAME_OP))) { walk_state->result_obj = obj_desc; } } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_eval_bank_field_operands * * PARAMETERS: walk_state - Current walk * op - A valid bank_field Op object * * RETURN: Status * * DESCRIPTION: Get bank_field bank_value * Called from acpi_ds_exec_end_op during bank_field parse tree walk * ******************************************************************************/ acpi_status acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state, union acpi_parse_object *op) { acpi_status status; union acpi_operand_object *obj_desc; union acpi_operand_object *operand_desc; struct acpi_namespace_node *node; union acpi_parse_object *next_op; union acpi_parse_object *arg; ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op); /* * This is where we evaluate the bank_value field of the * bank_field declaration */ /* next_op points to the op that holds the Region */ next_op = op->common.value.arg; /* next_op points to the op that holds the Bank Register */ next_op = next_op->common.next; /* next_op points to the op that holds the Bank Value */ next_op = next_op->common.next; /* * Set proper index into operand stack for acpi_ds_obj_stack_push * invoked inside acpi_ds_create_operand. * * We use walk_state->Operands[0] to store the evaluated bank_value */ walk_state->operand_index = 0; status = acpi_ds_create_operand(walk_state, next_op, 0); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, acpi_ps_get_opcode_name(op->common.aml_opcode), 1); /* * Get the bank_value operand and save it * (at Top of stack) */ operand_desc = walk_state->operands[0]; /* Arg points to the start Bank Field */ arg = acpi_ps_get_arg(op, 4); while (arg) { /* Ignore OFFSET and ACCESSAS terms here */ if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) { node = arg->common.node; obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { return_ACPI_STATUS(AE_NOT_EXIST); } obj_desc->bank_field.value = (u32) operand_desc->integer.value; } /* Move to next field in the list */ arg = arg->common.next; } acpi_ut_remove_reference(operand_desc); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/dsopcode.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: hwregs - Read/write access functions for the various ACPI * control and status registers. * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #define _COMPONENT ACPI_HARDWARE ACPI_MODULE_NAME("hwregs") #if (!ACPI_REDUCED_HARDWARE) /* Local Prototypes */ static u8 acpi_hw_get_access_bit_width(u64 address, struct acpi_generic_address *reg, u8 max_bit_width); static acpi_status acpi_hw_read_multiple(u32 *value, struct acpi_generic_address *register_a, struct acpi_generic_address *register_b); static acpi_status acpi_hw_write_multiple(u32 value, struct acpi_generic_address *register_a, struct acpi_generic_address *register_b); #endif /* !ACPI_REDUCED_HARDWARE */ /****************************************************************************** * * FUNCTION: acpi_hw_get_access_bit_width * * PARAMETERS: address - GAS register address * reg - GAS register structure * max_bit_width - Max bit_width supported (32 or 64) * * RETURN: Status * * DESCRIPTION: Obtain optimal access bit width * ******************************************************************************/ static u8 acpi_hw_get_access_bit_width(u64 address, struct acpi_generic_address *reg, u8 max_bit_width) { u8 access_bit_width; /* * GAS format "register", used by FADT: * 1. Detected if bit_offset is 0 and bit_width is 8/16/32/64; * 2. access_size field is ignored and bit_width field is used for * determining the boundary of the IO accesses. * GAS format "region", used by APEI registers: * 1. Detected if bit_offset is not 0 or bit_width is not 8/16/32/64; * 2. access_size field is used for determining the boundary of the * IO accesses; * 3. bit_offset/bit_width fields are used to describe the "region". * * Note: This algorithm assumes that the "Address" fields should always * contain aligned values. */ if (!reg->bit_offset && reg->bit_width && ACPI_IS_POWER_OF_TWO(reg->bit_width) && ACPI_IS_ALIGNED(reg->bit_width, 8)) { access_bit_width = reg->bit_width; } else if (reg->access_width) { access_bit_width = ACPI_ACCESS_BIT_WIDTH(reg->access_width); } else { access_bit_width = ACPI_ROUND_UP_POWER_OF_TWO_8(reg->bit_offset + reg->bit_width); if (access_bit_width <= 8) { access_bit_width = 8; } else { while (!ACPI_IS_ALIGNED(address, access_bit_width >> 3)) { access_bit_width >>= 1; } } } /* Maximum IO port access bit width is 32 */ if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { max_bit_width = 32; } /* * Return access width according to the requested maximum access bit width, * as the caller should know the format of the register and may enforce * a 32-bit accesses. */ if (access_bit_width < max_bit_width) { return (access_bit_width); } return (max_bit_width); } /****************************************************************************** * * FUNCTION: acpi_hw_validate_register * * PARAMETERS: reg - GAS register structure * max_bit_width - Max bit_width supported (32 or 64) * address - Pointer to where the gas->address * is returned * * RETURN: Status * * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS * pointer, Address, space_id, bit_width, and bit_offset. * ******************************************************************************/ acpi_status acpi_hw_validate_register(struct acpi_generic_address *reg, u8 max_bit_width, u64 *address) { u8 bit_width; u8 access_width; /* Must have a valid pointer to a GAS structure */ if (!reg) { return (AE_BAD_PARAMETER); } /* * Copy the target address. This handles possible alignment issues. * Address must not be null. A null address also indicates an optional * ACPI register that is not supported, so no error message. */ ACPI_MOVE_64_TO_64(address, &reg->address); if (!(*address)) { return (AE_BAD_ADDRESS); } /* Validate the space_ID */ if ((reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) && (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) { ACPI_ERROR((AE_INFO, "Unsupported address space: 0x%X", reg->space_id)); return (AE_SUPPORT); } /* Validate the access_width */ if (reg->access_width > 4) { ACPI_ERROR((AE_INFO, "Unsupported register access width: 0x%X", reg->access_width)); return (AE_SUPPORT); } /* Validate the bit_width, convert access_width into number of bits */ access_width = acpi_hw_get_access_bit_width(*address, reg, max_bit_width); bit_width = ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width); if (max_bit_width < bit_width) { ACPI_WARNING((AE_INFO, "Requested bit width 0x%X is smaller than register bit width 0x%X", max_bit_width, bit_width)); return (AE_SUPPORT); } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_read * * PARAMETERS: value - Where the value is returned * reg - GAS register structure * * RETURN: Status * * DESCRIPTION: Read from either memory or IO space. This is a 64-bit max * version of acpi_read. * * LIMITATIONS: <These limitations also apply to acpi_hw_write> * space_ID must be system_memory or system_IO. * ******************************************************************************/ acpi_status acpi_hw_read(u64 *value, struct acpi_generic_address *reg) { u64 address; u8 access_width; u32 bit_width; u8 bit_offset; u64 value64; u32 value32; u8 index; acpi_status status; ACPI_FUNCTION_NAME(hw_read); /* Validate contents of the GAS register */ status = acpi_hw_validate_register(reg, 64, &address); if (ACPI_FAILURE(status)) { return (status); } /* * Initialize entire 64-bit return value to zero, convert access_width * into number of bits based */ *value = 0; access_width = acpi_hw_get_access_bit_width(address, reg, 64); bit_width = reg->bit_offset + reg->bit_width; bit_offset = reg->bit_offset; /* * Two address spaces supported: Memory or IO. PCI_Config is * not supported here because the GAS structure is insufficient */ index = 0; while (bit_width) { if (bit_offset >= access_width) { value64 = 0; bit_offset -= access_width; } else { if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { status = acpi_os_read_memory((acpi_physical_address) address + index * ACPI_DIV_8 (access_width), &value64, access_width); } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ status = acpi_hw_read_port((acpi_io_address) address + index * ACPI_DIV_8 (access_width), &value32, access_width); value64 = (u64)value32; } } /* * Use offset style bit writes because "Index * AccessWidth" is * ensured to be less than 64-bits by acpi_hw_validate_register(). */ ACPI_SET_BITS(value, index * access_width, ACPI_MASK_BITS_ABOVE_64(access_width), value64); bit_width -= bit_width > access_width ? access_width : bit_width; index++; } ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n", ACPI_FORMAT_UINT64(*value), access_width, ACPI_FORMAT_UINT64(address), acpi_ut_get_region_name(reg->space_id))); return (status); } /****************************************************************************** * * FUNCTION: acpi_hw_write * * PARAMETERS: value - Value to be written * reg - GAS register structure * * RETURN: Status * * DESCRIPTION: Write to either memory or IO space. This is a 64-bit max * version of acpi_write. * ******************************************************************************/ acpi_status acpi_hw_write(u64 value, struct acpi_generic_address *reg) { u64 address; u8 access_width; u32 bit_width; u8 bit_offset; u64 value64; u8 index; acpi_status status; ACPI_FUNCTION_NAME(hw_write); /* Validate contents of the GAS register */ status = acpi_hw_validate_register(reg, 64, &address); if (ACPI_FAILURE(status)) { return (status); } /* Convert access_width into number of bits based */ access_width = acpi_hw_get_access_bit_width(address, reg, 64); bit_width = reg->bit_offset + reg->bit_width; bit_offset = reg->bit_offset; /* * Two address spaces supported: Memory or IO. PCI_Config is * not supported here because the GAS structure is insufficient */ index = 0; while (bit_width) { /* * Use offset style bit reads because "Index * AccessWidth" is * ensured to be less than 64-bits by acpi_hw_validate_register(). */ value64 = ACPI_GET_BITS(&value, index * access_width, ACPI_MASK_BITS_ABOVE_64(access_width)); if (bit_offset >= access_width) { bit_offset -= access_width; } else { if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { status = acpi_os_write_memory((acpi_physical_address) address + index * ACPI_DIV_8 (access_width), value64, access_width); } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ status = acpi_hw_write_port((acpi_io_address) address + index * ACPI_DIV_8 (access_width), (u32)value64, access_width); } } /* * Index * access_width is ensured to be less than 32-bits by * acpi_hw_validate_register(). */ bit_width -= bit_width > access_width ? access_width : bit_width; index++; } ACPI_DEBUG_PRINT((ACPI_DB_IO, "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n", ACPI_FORMAT_UINT64(value), access_width, ACPI_FORMAT_UINT64(address), acpi_ut_get_region_name(reg->space_id))); return (status); } #if (!ACPI_REDUCED_HARDWARE) /******************************************************************************* * * FUNCTION: acpi_hw_clear_acpi_status * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Clears all fixed and general purpose status bits * ******************************************************************************/ acpi_status acpi_hw_clear_acpi_status(void) { acpi_status status; acpi_cpu_flags lock_flags = 0; ACPI_FUNCTION_TRACE(hw_clear_acpi_status); ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n", ACPI_BITMASK_ALL_FIXED_STATUS, ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address))); lock_flags = acpi_os_acquire_raw_lock(acpi_gbl_hardware_lock); /* Clear the fixed events in PM1 A/B */ status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, ACPI_BITMASK_ALL_FIXED_STATUS); acpi_os_release_raw_lock(acpi_gbl_hardware_lock, lock_flags); if (ACPI_FAILURE(status)) { goto exit; } /* Clear the GPE Bits in all GPE registers in all GPE blocks */ status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); exit: return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_hw_get_bit_register_info * * PARAMETERS: register_id - Index of ACPI Register to access * * RETURN: The bitmask to be used when accessing the register * * DESCRIPTION: Map register_id into a register bitmask. * ******************************************************************************/ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id) { ACPI_FUNCTION_ENTRY(); if (register_id > ACPI_BITREG_MAX) { ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X", register_id)); return (NULL); } return (&acpi_gbl_bit_register_info[register_id]); } /****************************************************************************** * * FUNCTION: acpi_hw_write_pm1_control * * PARAMETERS: pm1a_control - Value to be written to PM1A control * pm1b_control - Value to be written to PM1B control * * RETURN: Status * * DESCRIPTION: Write the PM1 A/B control registers. These registers are * different than the PM1 A/B status and enable registers * in that different values can be written to the A/B registers. * Most notably, the SLP_TYP bits can be different, as per the * values returned from the _Sx predefined methods. * ******************************************************************************/ acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control) { acpi_status status; ACPI_FUNCTION_TRACE(hw_write_pm1_control); status = acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (acpi_gbl_FADT.xpm1b_control_block.address) { status = acpi_hw_write(pm1b_control, &acpi_gbl_FADT.xpm1b_control_block); } return_ACPI_STATUS(status); } /****************************************************************************** * * FUNCTION: acpi_hw_register_read * * PARAMETERS: register_id - ACPI Register ID * return_value - Where the register value is returned * * RETURN: Status and the value read. * * DESCRIPTION: Read from the specified ACPI register * ******************************************************************************/ acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value) { u32 value = 0; u64 value64; acpi_status status; ACPI_FUNCTION_TRACE(hw_register_read); switch (register_id) { case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ status = acpi_hw_read_multiple(&value, &acpi_gbl_xpm1a_status, &acpi_gbl_xpm1b_status); break; case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ status = acpi_hw_read_multiple(&value, &acpi_gbl_xpm1a_enable, &acpi_gbl_xpm1b_enable); break; case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ status = acpi_hw_read_multiple(&value, &acpi_gbl_FADT. xpm1a_control_block, &acpi_gbl_FADT. xpm1b_control_block); /* * Zero the write-only bits. From the ACPI specification, "Hardware * Write-Only Bits": "Upon reads to registers with write-only bits, * software masks out all write-only bits." */ value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS; break; case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ status = acpi_hw_read(&value64, &acpi_gbl_FADT.xpm2_control_block); if (ACPI_SUCCESS(status)) { value = (u32)value64; } break; case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ status = acpi_hw_read(&value64, &acpi_gbl_FADT.xpm_timer_block); if (ACPI_SUCCESS(status)) { value = (u32)value64; } break; case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ status = acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8); break; default: ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id)); status = AE_BAD_PARAMETER; break; } if (ACPI_SUCCESS(status)) { *return_value = (u32)value; } return_ACPI_STATUS(status); } /****************************************************************************** * * FUNCTION: acpi_hw_register_write * * PARAMETERS: register_id - ACPI Register ID * value - The value to write * * RETURN: Status * * DESCRIPTION: Write to the specified ACPI register * * NOTE: In accordance with the ACPI specification, this function automatically * preserves the value of the following bits, meaning that these bits cannot be * changed via this interface: * * PM1_CONTROL[0] = SCI_EN * PM1_CONTROL[9] * PM1_STATUS[11] * * ACPI References: * 1) Hardware Ignored Bits: When software writes to a register with ignored * bit fields, it preserves the ignored bit fields * 2) SCI_EN: OSPM always preserves this bit position * ******************************************************************************/ acpi_status acpi_hw_register_write(u32 register_id, u32 value) { acpi_status status; u32 read_value; u64 read_value64; ACPI_FUNCTION_TRACE(hw_register_write); switch (register_id) { case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ /* * Handle the "ignored" bit in PM1 Status. According to the ACPI * specification, ignored bits are to be preserved when writing. * Normally, this would mean a read/modify/write sequence. However, * preserving a bit in the status register is different. Writing a * one clears the status, and writing a zero preserves the status. * Therefore, we must always write zero to the ignored bit. * * This behavior is clarified in the ACPI 4.0 specification. */ value &= ~ACPI_PM1_STATUS_PRESERVED_BITS; status = acpi_hw_write_multiple(value, &acpi_gbl_xpm1a_status, &acpi_gbl_xpm1b_status); break; case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ status = acpi_hw_write_multiple(value, &acpi_gbl_xpm1a_enable, &acpi_gbl_xpm1b_enable); break; case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ /* * Perform a read first to preserve certain bits (per ACPI spec) * Note: This includes SCI_EN, we never want to change this bit */ status = acpi_hw_read_multiple(&read_value, &acpi_gbl_FADT. xpm1a_control_block, &acpi_gbl_FADT. xpm1b_control_block); if (ACPI_FAILURE(status)) { goto exit; } /* Insert the bits to be preserved */ ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS, read_value); /* Now we can write the data */ status = acpi_hw_write_multiple(value, &acpi_gbl_FADT. xpm1a_control_block, &acpi_gbl_FADT. xpm1b_control_block); break; case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ /* * For control registers, all reserved bits must be preserved, * as per the ACPI spec. */ status = acpi_hw_read(&read_value64, &acpi_gbl_FADT.xpm2_control_block); if (ACPI_FAILURE(status)) { goto exit; } read_value = (u32)read_value64; /* Insert the bits to be preserved */ ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS, read_value); status = acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block); break; case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block); break; case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ /* SMI_CMD is currently always in IO space */ status = acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8); break; default: ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id)); status = AE_BAD_PARAMETER; break; } exit: return_ACPI_STATUS(status); } /****************************************************************************** * * FUNCTION: acpi_hw_read_multiple * * PARAMETERS: value - Where the register value is returned * register_a - First ACPI register (required) * register_b - Second ACPI register (optional) * * RETURN: Status * * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B) * ******************************************************************************/ static acpi_status acpi_hw_read_multiple(u32 *value, struct acpi_generic_address *register_a, struct acpi_generic_address *register_b) { u32 value_a = 0; u32 value_b = 0; u64 value64; acpi_status status; /* The first register is always required */ status = acpi_hw_read(&value64, register_a); if (ACPI_FAILURE(status)) { return (status); } value_a = (u32)value64; /* Second register is optional */ if (register_b->address) { status = acpi_hw_read(&value64, register_b); if (ACPI_FAILURE(status)) { return (status); } value_b = (u32)value64; } /* * OR the two return values together. No shifting or masking is necessary, * because of how the PM1 registers are defined in the ACPI specification: * * "Although the bits can be split between the two register blocks (each * register block has a unique pointer within the FADT), the bit positions * are maintained. The register block with unimplemented bits (that is, * those implemented in the other register block) always returns zeros, * and writes have no side effects" */ *value = (value_a | value_b); return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_write_multiple * * PARAMETERS: value - The value to write * register_a - First ACPI register (required) * register_b - Second ACPI register (optional) * * RETURN: Status * * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B) * ******************************************************************************/ static acpi_status acpi_hw_write_multiple(u32 value, struct acpi_generic_address *register_a, struct acpi_generic_address *register_b) { acpi_status status; /* The first register is always required */ status = acpi_hw_write(value, register_a); if (ACPI_FAILURE(status)) { return (status); } /* * Second register is optional * * No bit shifting or clearing is necessary, because of how the PM1 * registers are defined in the ACPI specification: * * "Although the bits can be split between the two register blocks (each * register block has a unique pointer within the FADT), the bit positions * are maintained. The register block with unimplemented bits (that is, * those implemented in the other register block) always returns zeros, * and writes have no side effects" */ if (register_b->address) { status = acpi_hw_write(value, register_b); } return (status); } #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/hwregs.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: hwpci - Obtain PCI bus, device, and function numbers * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("hwpci") /* PCI configuration space values */ #define PCI_CFG_HEADER_TYPE_REG 0x0E #define PCI_CFG_PRIMARY_BUS_NUMBER_REG 0x18 #define PCI_CFG_SECONDARY_BUS_NUMBER_REG 0x19 /* PCI header values */ #define PCI_HEADER_TYPE_MASK 0x7F #define PCI_TYPE_BRIDGE 0x01 #define PCI_TYPE_CARDBUS_BRIDGE 0x02 typedef struct acpi_pci_device { acpi_handle device; struct acpi_pci_device *next; } acpi_pci_device; /* Local prototypes */ static acpi_status acpi_hw_build_pci_list(acpi_handle root_pci_device, acpi_handle pci_region, struct acpi_pci_device **return_list_head); static acpi_status acpi_hw_process_pci_list(struct acpi_pci_id *pci_id, struct acpi_pci_device *list_head); static void acpi_hw_delete_pci_list(struct acpi_pci_device *list_head); static acpi_status acpi_hw_get_pci_device_info(struct acpi_pci_id *pci_id, acpi_handle pci_device, u16 *bus_number, u8 *is_bridge); /******************************************************************************* * * FUNCTION: acpi_hw_derive_pci_id * * PARAMETERS: pci_id - Initial values for the PCI ID. May be * modified by this function. * root_pci_device - A handle to a PCI device object. This * object must be a PCI Root Bridge having a * _HID value of either PNP0A03 or PNP0A08 * pci_region - A handle to a PCI configuration space * Operation Region being initialized * * RETURN: Status * * DESCRIPTION: This function derives a full PCI ID for a PCI device, * consisting of a Segment number, Bus number, Device number, * and function code. * * The PCI hardware dynamically configures PCI bus numbers * depending on the bus topology discovered during system * initialization. This function is invoked during configuration * of a PCI_Config Operation Region in order to (possibly) update * the Bus/Device/Function numbers in the pci_id with the actual * values as determined by the hardware and operating system * configuration. * * The pci_id parameter is initially populated during the Operation * Region initialization. This function is then called, and is * will make any necessary modifications to the Bus, Device, or * Function number PCI ID subfields as appropriate for the * current hardware and OS configuration. * * NOTE: Created 08/2010. Replaces the previous OSL acpi_os_derive_pci_id * interface since this feature is OS-independent. This module * specifically avoids any use of recursion by building a local * temporary device list. * ******************************************************************************/ acpi_status acpi_hw_derive_pci_id(struct acpi_pci_id *pci_id, acpi_handle root_pci_device, acpi_handle pci_region) { acpi_status status; struct acpi_pci_device *list_head; ACPI_FUNCTION_TRACE(hw_derive_pci_id); if (!pci_id) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Build a list of PCI devices, from pci_region up to root_pci_device */ status = acpi_hw_build_pci_list(root_pci_device, pci_region, &list_head); if (ACPI_SUCCESS(status)) { /* Walk the list, updating the PCI device/function/bus numbers */ status = acpi_hw_process_pci_list(pci_id, list_head); /* Delete the list */ acpi_hw_delete_pci_list(list_head); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_hw_build_pci_list * * PARAMETERS: root_pci_device - A handle to a PCI device object. This * object is guaranteed to be a PCI Root * Bridge having a _HID value of either * PNP0A03 or PNP0A08 * pci_region - A handle to the PCI configuration space * Operation Region * return_list_head - Where the PCI device list is returned * * RETURN: Status * * DESCRIPTION: Builds a list of devices from the input PCI region up to the * Root PCI device for this namespace subtree. * ******************************************************************************/ static acpi_status acpi_hw_build_pci_list(acpi_handle root_pci_device, acpi_handle pci_region, struct acpi_pci_device **return_list_head) { acpi_handle current_device; acpi_handle parent_device; acpi_status status; struct acpi_pci_device *list_element; /* * Ascend namespace branch until the root_pci_device is reached, building * a list of device nodes. Loop will exit when either the PCI device is * found, or the root of the namespace is reached. */ *return_list_head = NULL; current_device = pci_region; while (1) { status = acpi_get_parent(current_device, &parent_device); if (ACPI_FAILURE(status)) { /* Must delete the list before exit */ acpi_hw_delete_pci_list(*return_list_head); return (status); } /* Finished when we reach the PCI root device (PNP0A03 or PNP0A08) */ if (parent_device == root_pci_device) { return (AE_OK); } list_element = ACPI_ALLOCATE(sizeof(struct acpi_pci_device)); if (!list_element) { /* Must delete the list before exit */ acpi_hw_delete_pci_list(*return_list_head); return (AE_NO_MEMORY); } /* Put new element at the head of the list */ list_element->next = *return_list_head; list_element->device = parent_device; *return_list_head = list_element; current_device = parent_device; } } /******************************************************************************* * * FUNCTION: acpi_hw_process_pci_list * * PARAMETERS: pci_id - Initial values for the PCI ID. May be * modified by this function. * list_head - Device list created by * acpi_hw_build_pci_list * * RETURN: Status * * DESCRIPTION: Walk downward through the PCI device list, getting the device * info for each, via the PCI configuration space and updating * the PCI ID as necessary. Deletes the list during traversal. * ******************************************************************************/ static acpi_status acpi_hw_process_pci_list(struct acpi_pci_id *pci_id, struct acpi_pci_device *list_head) { acpi_status status = AE_OK; struct acpi_pci_device *info; u16 bus_number; u8 is_bridge = TRUE; ACPI_FUNCTION_NAME(hw_process_pci_list); ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Input PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X\n", pci_id->segment, pci_id->bus, pci_id->device, pci_id->function)); bus_number = pci_id->bus; /* * Descend down the namespace tree, collecting PCI device, function, * and bus numbers. bus_number is only important for PCI bridges. * Algorithm: As we descend the tree, use the last valid PCI device, * function, and bus numbers that are discovered, and assign them * to the PCI ID for the target device. */ info = list_head; while (info) { status = acpi_hw_get_pci_device_info(pci_id, info->device, &bus_number, &is_bridge); if (ACPI_FAILURE(status)) { return (status); } info = info->next; } ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Output PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X " "Status %X BusNumber %X IsBridge %X\n", pci_id->segment, pci_id->bus, pci_id->device, pci_id->function, status, bus_number, is_bridge)); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_hw_delete_pci_list * * PARAMETERS: list_head - Device list created by * acpi_hw_build_pci_list * * RETURN: None * * DESCRIPTION: Free the entire PCI list. * ******************************************************************************/ static void acpi_hw_delete_pci_list(struct acpi_pci_device *list_head) { struct acpi_pci_device *next; struct acpi_pci_device *previous; next = list_head; while (next) { previous = next; next = previous->next; ACPI_FREE(previous); } } /******************************************************************************* * * FUNCTION: acpi_hw_get_pci_device_info * * PARAMETERS: pci_id - Initial values for the PCI ID. May be * modified by this function. * pci_device - Handle for the PCI device object * bus_number - Where a PCI bridge bus number is returned * is_bridge - Return value, indicates if this PCI * device is a PCI bridge * * RETURN: Status * * DESCRIPTION: Get the device info for a single PCI device object. Get the * _ADR (contains PCI device and function numbers), and for PCI * bridge devices, get the bus number from PCI configuration * space. * ******************************************************************************/ static acpi_status acpi_hw_get_pci_device_info(struct acpi_pci_id *pci_id, acpi_handle pci_device, u16 *bus_number, u8 *is_bridge) { acpi_status status; acpi_object_type object_type; u64 return_value; u64 pci_value; /* We only care about objects of type Device */ status = acpi_get_type(pci_device, &object_type); if (ACPI_FAILURE(status)) { return (status); } if (object_type != ACPI_TYPE_DEVICE) { return (AE_OK); } /* We need an _ADR. Ignore device if not present */ status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, pci_device, &return_value); if (ACPI_FAILURE(status)) { return (AE_OK); } /* * From _ADR, get the PCI Device and Function and * update the PCI ID. */ pci_id->device = ACPI_HIWORD(ACPI_LODWORD(return_value)); pci_id->function = ACPI_LOWORD(ACPI_LODWORD(return_value)); /* * If the previous device was a bridge, use the previous * device bus number */ if (*is_bridge) { pci_id->bus = *bus_number; } /* * Get the bus numbers from PCI Config space: * * First, get the PCI header_type */ *is_bridge = FALSE; status = acpi_os_read_pci_configuration(pci_id, PCI_CFG_HEADER_TYPE_REG, &pci_value, 8); if (ACPI_FAILURE(status)) { return (status); } /* We only care about bridges (1=pci_bridge, 2=card_bus_bridge) */ pci_value &= PCI_HEADER_TYPE_MASK; if ((pci_value != PCI_TYPE_BRIDGE) && (pci_value != PCI_TYPE_CARDBUS_BRIDGE)) { return (AE_OK); } /* Bridge: Get the Primary bus_number */ status = acpi_os_read_pci_configuration(pci_id, PCI_CFG_PRIMARY_BUS_NUMBER_REG, &pci_value, 8); if (ACPI_FAILURE(status)) { return (status); } *is_bridge = TRUE; pci_id->bus = (u16)pci_value; /* Bridge: Get the Secondary bus_number */ status = acpi_os_read_pci_configuration(pci_id, PCI_CFG_SECONDARY_BUS_NUMBER_REG, &pci_value, 8); if (ACPI_FAILURE(status)) { return (status); } *bus_number = (u16)pci_value; return (AE_OK); }
linux-master
drivers/acpi/acpica/hwpci.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: dbconvert - debugger miscellaneous conversion routines * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdebug.h" #define _COMPONENT ACPI_CA_DEBUGGER ACPI_MODULE_NAME("dbconvert") #define DB_DEFAULT_PKG_ELEMENTS 33 /******************************************************************************* * * FUNCTION: acpi_db_hex_char_to_value * * PARAMETERS: hex_char - Ascii Hex digit, 0-9|a-f|A-F * return_value - Where the converted value is returned * * RETURN: Status * * DESCRIPTION: Convert a single hex character to a 4-bit number (0-16). * ******************************************************************************/ acpi_status acpi_db_hex_char_to_value(int hex_char, u8 *return_value) { u8 value; /* Digit must be ascii [0-9a-fA-F] */ if (!isxdigit(hex_char)) { return (AE_BAD_HEX_CONSTANT); } if (hex_char <= 0x39) { value = (u8)(hex_char - 0x30); } else { value = (u8)(toupper(hex_char) - 0x37); } *return_value = value; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_hex_byte_to_binary * * PARAMETERS: hex_byte - Double hex digit (0x00 - 0xFF) in format: * hi_byte then lo_byte. * return_value - Where the converted value is returned * * RETURN: Status * * DESCRIPTION: Convert two hex characters to an 8 bit number (0 - 255). * ******************************************************************************/ static acpi_status acpi_db_hex_byte_to_binary(char *hex_byte, u8 *return_value) { u8 local0; u8 local1; acpi_status status; /* High byte */ status = acpi_db_hex_char_to_value(hex_byte[0], &local0); if (ACPI_FAILURE(status)) { return (status); } /* Low byte */ status = acpi_db_hex_char_to_value(hex_byte[1], &local1); if (ACPI_FAILURE(status)) { return (status); } *return_value = (u8)((local0 << 4) | local1); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_convert_to_buffer * * PARAMETERS: string - Input string to be converted * object - Where the buffer object is returned * * RETURN: Status * * DESCRIPTION: Convert a string to a buffer object. String is treated a list * of buffer elements, each separated by a space or comma. * ******************************************************************************/ static acpi_status acpi_db_convert_to_buffer(char *string, union acpi_object *object) { u32 i; u32 j; u32 length; u8 *buffer; acpi_status status; /* Skip all preceding white space */ acpi_ut_remove_whitespace(&string); /* Generate the final buffer length */ for (i = 0, length = 0; string[i];) { i += 2; length++; while (string[i] && ((string[i] == ',') || (string[i] == ' '))) { i++; } } buffer = ACPI_ALLOCATE(length); if (!buffer) { return (AE_NO_MEMORY); } /* Convert the command line bytes to the buffer */ for (i = 0, j = 0; string[i];) { status = acpi_db_hex_byte_to_binary(&string[i], &buffer[j]); if (ACPI_FAILURE(status)) { ACPI_FREE(buffer); return (status); } j++; i += 2; while (string[i] && ((string[i] == ',') || (string[i] == ' '))) { i++; } } object->type = ACPI_TYPE_BUFFER; object->buffer.pointer = buffer; object->buffer.length = length; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_convert_to_package * * PARAMETERS: string - Input string to be converted * object - Where the package object is returned * * RETURN: Status * * DESCRIPTION: Convert a string to a package object. Handles nested packages * via recursion with acpi_db_convert_to_object. * ******************************************************************************/ acpi_status acpi_db_convert_to_package(char *string, union acpi_object *object) { char *this; char *next; u32 i; acpi_object_type type; union acpi_object *elements; acpi_status status; elements = ACPI_ALLOCATE_ZEROED(DB_DEFAULT_PKG_ELEMENTS * sizeof(union acpi_object)); this = string; for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++) { this = acpi_db_get_next_token(this, &next, &type); if (!this) { break; } /* Recursive call to convert each package element */ status = acpi_db_convert_to_object(type, this, &elements[i]); if (ACPI_FAILURE(status)) { acpi_db_delete_objects(i + 1, elements); ACPI_FREE(elements); return (status); } this = next; } object->type = ACPI_TYPE_PACKAGE; object->package.count = i; object->package.elements = elements; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_convert_to_object * * PARAMETERS: type - Object type as determined by parser * string - Input string to be converted * object - Where the new object is returned * * RETURN: Status * * DESCRIPTION: Convert a typed and tokenized string to a union acpi_object. Typing: * 1) String objects were surrounded by quotes. * 2) Buffer objects were surrounded by parentheses. * 3) Package objects were surrounded by brackets "[]". * 4) All standalone tokens are treated as integers. * ******************************************************************************/ acpi_status acpi_db_convert_to_object(acpi_object_type type, char *string, union acpi_object *object) { acpi_status status = AE_OK; switch (type) { case ACPI_TYPE_STRING: object->type = ACPI_TYPE_STRING; object->string.pointer = string; object->string.length = (u32)strlen(string); break; case ACPI_TYPE_BUFFER: status = acpi_db_convert_to_buffer(string, object); break; case ACPI_TYPE_PACKAGE: status = acpi_db_convert_to_package(string, object); break; default: object->type = ACPI_TYPE_INTEGER; status = acpi_ut_strtoul64(string, &object->integer.value); break; } return (status); } /******************************************************************************* * * FUNCTION: acpi_db_encode_pld_buffer * * PARAMETERS: pld_info - _PLD buffer struct (Using local struct) * * RETURN: Encode _PLD buffer suitable for return value from _PLD * * DESCRIPTION: Bit-packs a _PLD buffer struct. Used to test the _PLD macros * ******************************************************************************/ u8 *acpi_db_encode_pld_buffer(struct acpi_pld_info *pld_info) { u32 *buffer; u32 dword; buffer = ACPI_ALLOCATE_ZEROED(ACPI_PLD_BUFFER_SIZE); if (!buffer) { return (NULL); } /* First 32 bits */ dword = 0; ACPI_PLD_SET_REVISION(&dword, pld_info->revision); ACPI_PLD_SET_IGNORE_COLOR(&dword, pld_info->ignore_color); ACPI_PLD_SET_RED(&dword, pld_info->red); ACPI_PLD_SET_GREEN(&dword, pld_info->green); ACPI_PLD_SET_BLUE(&dword, pld_info->blue); ACPI_MOVE_32_TO_32(&buffer[0], &dword); /* Second 32 bits */ dword = 0; ACPI_PLD_SET_WIDTH(&dword, pld_info->width); ACPI_PLD_SET_HEIGHT(&dword, pld_info->height); ACPI_MOVE_32_TO_32(&buffer[1], &dword); /* Third 32 bits */ dword = 0; ACPI_PLD_SET_USER_VISIBLE(&dword, pld_info->user_visible); ACPI_PLD_SET_DOCK(&dword, pld_info->dock); ACPI_PLD_SET_LID(&dword, pld_info->lid); ACPI_PLD_SET_PANEL(&dword, pld_info->panel); ACPI_PLD_SET_VERTICAL(&dword, pld_info->vertical_position); ACPI_PLD_SET_HORIZONTAL(&dword, pld_info->horizontal_position); ACPI_PLD_SET_SHAPE(&dword, pld_info->shape); ACPI_PLD_SET_ORIENTATION(&dword, pld_info->group_orientation); ACPI_PLD_SET_TOKEN(&dword, pld_info->group_token); ACPI_PLD_SET_POSITION(&dword, pld_info->group_position); ACPI_PLD_SET_BAY(&dword, pld_info->bay); ACPI_MOVE_32_TO_32(&buffer[2], &dword); /* Fourth 32 bits */ dword = 0; ACPI_PLD_SET_EJECTABLE(&dword, pld_info->ejectable); ACPI_PLD_SET_OSPM_EJECT(&dword, pld_info->ospm_eject_required); ACPI_PLD_SET_CABINET(&dword, pld_info->cabinet_number); ACPI_PLD_SET_CARD_CAGE(&dword, pld_info->card_cage_number); ACPI_PLD_SET_REFERENCE(&dword, pld_info->reference); ACPI_PLD_SET_ROTATION(&dword, pld_info->rotation); ACPI_PLD_SET_ORDER(&dword, pld_info->order); ACPI_MOVE_32_TO_32(&buffer[3], &dword); if (pld_info->revision >= 2) { /* Fifth 32 bits */ dword = 0; ACPI_PLD_SET_VERT_OFFSET(&dword, pld_info->vertical_offset); ACPI_PLD_SET_HORIZ_OFFSET(&dword, pld_info->horizontal_offset); ACPI_MOVE_32_TO_32(&buffer[4], &dword); } return (ACPI_CAST_PTR(u8, buffer)); } /******************************************************************************* * * FUNCTION: acpi_db_dump_pld_buffer * * PARAMETERS: obj_desc - Object returned from _PLD method * * RETURN: None. * * DESCRIPTION: Dumps formatted contents of a _PLD return buffer. * ******************************************************************************/ #define ACPI_PLD_OUTPUT "%20s : %-6X\n" void acpi_db_dump_pld_buffer(union acpi_object *obj_desc) { union acpi_object *buffer_desc; struct acpi_pld_info *pld_info; u8 *new_buffer; acpi_status status; /* Object must be of type Package with at least one Buffer element */ if (obj_desc->type != ACPI_TYPE_PACKAGE) { return; } buffer_desc = &obj_desc->package.elements[0]; if (buffer_desc->type != ACPI_TYPE_BUFFER) { return; } /* Convert _PLD buffer to local _PLD struct */ status = acpi_decode_pld_buffer(buffer_desc->buffer.pointer, buffer_desc->buffer.length, &pld_info); if (ACPI_FAILURE(status)) { return; } /* Encode local _PLD struct back to a _PLD buffer */ new_buffer = acpi_db_encode_pld_buffer(pld_info); if (!new_buffer) { goto exit; } /* The two bit-packed buffers should match */ if (memcmp(new_buffer, buffer_desc->buffer.pointer, buffer_desc->buffer.length)) { acpi_os_printf ("Converted _PLD buffer does not compare. New:\n"); acpi_ut_dump_buffer(new_buffer, buffer_desc->buffer.length, DB_BYTE_DISPLAY, 0); } /* First 32-bit dword */ acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Revision", pld_info->revision); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_IgnoreColor", pld_info->ignore_color); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Red", pld_info->red); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Green", pld_info->green); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Blue", pld_info->blue); /* Second 32-bit dword */ acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Width", pld_info->width); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Height", pld_info->height); /* Third 32-bit dword */ acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_UserVisible", pld_info->user_visible); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Dock", pld_info->dock); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Lid", pld_info->lid); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Panel", pld_info->panel); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_VerticalPosition", pld_info->vertical_position); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_HorizontalPosition", pld_info->horizontal_position); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Shape", pld_info->shape); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupOrientation", pld_info->group_orientation); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupToken", pld_info->group_token); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupPosition", pld_info->group_position); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Bay", pld_info->bay); /* Fourth 32-bit dword */ acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Ejectable", pld_info->ejectable); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_EjectRequired", pld_info->ospm_eject_required); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_CabinetNumber", pld_info->cabinet_number); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_CardCageNumber", pld_info->card_cage_number); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Reference", pld_info->reference); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Rotation", pld_info->rotation); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Order", pld_info->order); /* Fifth 32-bit dword */ if (buffer_desc->buffer.length > 16) { acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_VerticalOffset", pld_info->vertical_offset); acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_HorizontalOffset", pld_info->horizontal_offset); } ACPI_FREE(new_buffer); exit: ACPI_FREE(pld_info); }
linux-master
drivers/acpi/acpica/dbconvert.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: utresrc - Resource management utilities * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utresrc") /* * Base sizes of the raw AML resource descriptors, indexed by resource type. * Zero indicates a reserved (and therefore invalid) resource type. */ const u8 acpi_gbl_resource_aml_sizes[] = { /* Small descriptors */ 0, 0, 0, 0, ACPI_AML_SIZE_SMALL(struct aml_resource_irq), ACPI_AML_SIZE_SMALL(struct aml_resource_dma), ACPI_AML_SIZE_SMALL(struct aml_resource_start_dependent), ACPI_AML_SIZE_SMALL(struct aml_resource_end_dependent), ACPI_AML_SIZE_SMALL(struct aml_resource_io), ACPI_AML_SIZE_SMALL(struct aml_resource_fixed_io), ACPI_AML_SIZE_SMALL(struct aml_resource_fixed_dma), 0, 0, 0, ACPI_AML_SIZE_SMALL(struct aml_resource_vendor_small), ACPI_AML_SIZE_SMALL(struct aml_resource_end_tag), /* Large descriptors */ 0, ACPI_AML_SIZE_LARGE(struct aml_resource_memory24), ACPI_AML_SIZE_LARGE(struct aml_resource_generic_register), 0, ACPI_AML_SIZE_LARGE(struct aml_resource_vendor_large), ACPI_AML_SIZE_LARGE(struct aml_resource_memory32), ACPI_AML_SIZE_LARGE(struct aml_resource_fixed_memory32), ACPI_AML_SIZE_LARGE(struct aml_resource_address32), ACPI_AML_SIZE_LARGE(struct aml_resource_address16), ACPI_AML_SIZE_LARGE(struct aml_resource_extended_irq), ACPI_AML_SIZE_LARGE(struct aml_resource_address64), ACPI_AML_SIZE_LARGE(struct aml_resource_extended_address64), ACPI_AML_SIZE_LARGE(struct aml_resource_gpio), ACPI_AML_SIZE_LARGE(struct aml_resource_pin_function), ACPI_AML_SIZE_LARGE(struct aml_resource_common_serialbus), ACPI_AML_SIZE_LARGE(struct aml_resource_pin_config), ACPI_AML_SIZE_LARGE(struct aml_resource_pin_group), ACPI_AML_SIZE_LARGE(struct aml_resource_pin_group_function), ACPI_AML_SIZE_LARGE(struct aml_resource_pin_group_config), ACPI_AML_SIZE_LARGE(struct aml_resource_clock_input), }; const u8 acpi_gbl_resource_aml_serial_bus_sizes[] = { 0, ACPI_AML_SIZE_LARGE(struct aml_resource_i2c_serialbus), ACPI_AML_SIZE_LARGE(struct aml_resource_spi_serialbus), ACPI_AML_SIZE_LARGE(struct aml_resource_uart_serialbus), ACPI_AML_SIZE_LARGE(struct aml_resource_csi2_serialbus), }; /* * Resource types, used to validate the resource length field. * The length of fixed-length types must match exactly, variable * lengths must meet the minimum required length, etc. * Zero indicates a reserved (and therefore invalid) resource type. */ static const u8 acpi_gbl_resource_types[] = { /* Small descriptors */ 0, 0, 0, 0, ACPI_SMALL_VARIABLE_LENGTH, /* 04 IRQ */ ACPI_FIXED_LENGTH, /* 05 DMA */ ACPI_SMALL_VARIABLE_LENGTH, /* 06 start_dependent_functions */ ACPI_FIXED_LENGTH, /* 07 end_dependent_functions */ ACPI_FIXED_LENGTH, /* 08 IO */ ACPI_FIXED_LENGTH, /* 09 fixed_IO */ ACPI_FIXED_LENGTH, /* 0A fixed_DMA */ 0, 0, 0, ACPI_VARIABLE_LENGTH, /* 0E vendor_short */ ACPI_FIXED_LENGTH, /* 0F end_tag */ /* Large descriptors */ 0, ACPI_FIXED_LENGTH, /* 01 Memory24 */ ACPI_FIXED_LENGTH, /* 02 generic_register */ 0, ACPI_VARIABLE_LENGTH, /* 04 vendor_long */ ACPI_FIXED_LENGTH, /* 05 Memory32 */ ACPI_FIXED_LENGTH, /* 06 memory32_fixed */ ACPI_VARIABLE_LENGTH, /* 07 Dword* address */ ACPI_VARIABLE_LENGTH, /* 08 Word* address */ ACPI_VARIABLE_LENGTH, /* 09 extended_IRQ */ ACPI_VARIABLE_LENGTH, /* 0A Qword* address */ ACPI_FIXED_LENGTH, /* 0B Extended* address */ ACPI_VARIABLE_LENGTH, /* 0C Gpio* */ ACPI_VARIABLE_LENGTH, /* 0D pin_function */ ACPI_VARIABLE_LENGTH, /* 0E *serial_bus */ ACPI_VARIABLE_LENGTH, /* 0F pin_config */ ACPI_VARIABLE_LENGTH, /* 10 pin_group */ ACPI_VARIABLE_LENGTH, /* 11 pin_group_function */ ACPI_VARIABLE_LENGTH, /* 12 pin_group_config */ ACPI_VARIABLE_LENGTH, /* 13 clock_input */ }; /******************************************************************************* * * FUNCTION: acpi_ut_walk_aml_resources * * PARAMETERS: walk_state - Current walk info * PARAMETERS: aml - Pointer to the raw AML resource template * aml_length - Length of the entire template * user_function - Called once for each descriptor found. If * NULL, a pointer to the end_tag is returned * context - Passed to user_function * * RETURN: Status * * DESCRIPTION: Walk a raw AML resource list(buffer). User function called * once for each resource found. * ******************************************************************************/ acpi_status acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state, u8 *aml, acpi_size aml_length, acpi_walk_aml_callback user_function, void **context) { acpi_status status; u8 *end_aml; u8 resource_index; u32 length; u32 offset = 0; u8 end_tag[2] = { 0x79, 0x00 }; ACPI_FUNCTION_TRACE(ut_walk_aml_resources); /* The absolute minimum resource template is one end_tag descriptor */ if (aml_length < sizeof(struct aml_resource_end_tag)) { return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } /* Point to the end of the resource template buffer */ end_aml = aml + aml_length; /* Walk the byte list, abort on any invalid descriptor type or length */ while (aml < end_aml) { /* Validate the Resource Type and Resource Length */ status = acpi_ut_validate_resource(walk_state, aml, &resource_index); if (ACPI_FAILURE(status)) { /* * Exit on failure. Cannot continue because the descriptor * length may be bogus also. */ return_ACPI_STATUS(status); } /* Get the length of this descriptor */ length = acpi_ut_get_descriptor_length(aml); /* Invoke the user function */ if (user_function) { status = user_function(aml, length, offset, resource_index, context); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } /* An end_tag descriptor terminates this resource template */ if (acpi_ut_get_resource_type(aml) == ACPI_RESOURCE_NAME_END_TAG) { /* * There must be at least one more byte in the buffer for * the 2nd byte of the end_tag */ if ((aml + 1) >= end_aml) { return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } /* * Don't attempt to perform any validation on the 2nd byte. * Although all known ASL compilers insert a zero for the 2nd * byte, it can also be a checksum (as per the ACPI spec), * and this is occasionally seen in the field. July 2017. */ /* Return the pointer to the end_tag if requested */ if (!user_function) { *context = aml; } /* Normal exit */ return_ACPI_STATUS(AE_OK); } aml += length; offset += length; } /* Did not find an end_tag descriptor */ if (user_function) { /* Insert an end_tag anyway. acpi_rs_get_list_length always leaves room */ (void)acpi_ut_validate_resource(walk_state, end_tag, &resource_index); status = user_function(end_tag, 2, offset, resource_index, context); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } /******************************************************************************* * * FUNCTION: acpi_ut_validate_resource * * PARAMETERS: walk_state - Current walk info * aml - Pointer to the raw AML resource descriptor * return_index - Where the resource index is returned. NULL * if the index is not required. * * RETURN: Status, and optionally the Index into the global resource tables * * DESCRIPTION: Validate an AML resource descriptor by checking the Resource * Type and Resource Length. Returns an index into the global * resource information/dispatch tables for later use. * ******************************************************************************/ acpi_status acpi_ut_validate_resource(struct acpi_walk_state *walk_state, void *aml, u8 *return_index) { union aml_resource *aml_resource; u8 resource_type; u8 resource_index; acpi_rs_length resource_length; acpi_rs_length minimum_resource_length; ACPI_FUNCTION_ENTRY(); /* * 1) Validate the resource_type field (Byte 0) */ resource_type = ACPI_GET8(aml); /* * Byte 0 contains the descriptor name (Resource Type) * Examine the large/small bit in the resource header */ if (resource_type & ACPI_RESOURCE_NAME_LARGE) { /* Verify the large resource type (name) against the max */ if (resource_type > ACPI_RESOURCE_NAME_LARGE_MAX) { goto invalid_resource; } /* * Large Resource Type -- bits 6:0 contain the name * Translate range 0x80-0x8B to index range 0x10-0x1B */ resource_index = (u8) (resource_type - 0x70); } else { /* * Small Resource Type -- bits 6:3 contain the name * Shift range to index range 0x00-0x0F */ resource_index = (u8) ((resource_type & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3); } /* * Check validity of the resource type, via acpi_gbl_resource_types. * Zero indicates an invalid resource. */ if (!acpi_gbl_resource_types[resource_index]) { goto invalid_resource; } /* * Validate the resource_length field. This ensures that the length * is at least reasonable, and guarantees that it is non-zero. */ resource_length = acpi_ut_get_resource_length(aml); minimum_resource_length = acpi_gbl_resource_aml_sizes[resource_index]; /* Validate based upon the type of resource - fixed length or variable */ switch (acpi_gbl_resource_types[resource_index]) { case ACPI_FIXED_LENGTH: /* Fixed length resource, length must match exactly */ if (resource_length != minimum_resource_length) { goto bad_resource_length; } break; case ACPI_VARIABLE_LENGTH: /* Variable length resource, length must be at least the minimum */ if (resource_length < minimum_resource_length) { goto bad_resource_length; } break; case ACPI_SMALL_VARIABLE_LENGTH: /* Small variable length resource, length can be (Min) or (Min-1) */ if ((resource_length > minimum_resource_length) || (resource_length < (minimum_resource_length - 1))) { goto bad_resource_length; } break; default: /* Shouldn't happen (because of validation earlier), but be sure */ goto invalid_resource; } aml_resource = ACPI_CAST_PTR(union aml_resource, aml); if (resource_type == ACPI_RESOURCE_NAME_SERIAL_BUS) { /* Avoid undefined behavior: member access within misaligned address */ struct aml_resource_common_serialbus common_serial_bus; memcpy(&common_serial_bus, aml_resource, sizeof(common_serial_bus)); /* Validate the bus_type field */ if ((common_serial_bus.type == 0) || (common_serial_bus.type > AML_RESOURCE_MAX_SERIALBUSTYPE)) { if (walk_state) { ACPI_ERROR((AE_INFO, "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X", common_serial_bus.type)); } return (AE_AML_INVALID_RESOURCE_TYPE); } } /* Optionally return the resource table index */ if (return_index) { *return_index = resource_index; } return (AE_OK); invalid_resource: if (walk_state) { ACPI_ERROR((AE_INFO, "Invalid/unsupported resource descriptor: Type 0x%2.2X", resource_type)); } return (AE_AML_INVALID_RESOURCE_TYPE); bad_resource_length: if (walk_state) { ACPI_ERROR((AE_INFO, "Invalid resource descriptor length: Type " "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X", resource_type, resource_length, minimum_resource_length)); } return (AE_AML_BAD_RESOURCE_LENGTH); } /******************************************************************************* * * FUNCTION: acpi_ut_get_resource_type * * PARAMETERS: aml - Pointer to the raw AML resource descriptor * * RETURN: The Resource Type with no extraneous bits (except the * Large/Small descriptor bit -- this is left alone) * * DESCRIPTION: Extract the Resource Type/Name from the first byte of * a resource descriptor. * ******************************************************************************/ u8 acpi_ut_get_resource_type(void *aml) { ACPI_FUNCTION_ENTRY(); /* * Byte 0 contains the descriptor name (Resource Type) * Examine the large/small bit in the resource header */ if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) { /* Large Resource Type -- bits 6:0 contain the name */ return (ACPI_GET8(aml)); } else { /* Small Resource Type -- bits 6:3 contain the name */ return ((u8) (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_SMALL_MASK)); } } /******************************************************************************* * * FUNCTION: acpi_ut_get_resource_length * * PARAMETERS: aml - Pointer to the raw AML resource descriptor * * RETURN: Byte Length * * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By * definition, this does not include the size of the descriptor * header or the length field itself. * ******************************************************************************/ u16 acpi_ut_get_resource_length(void *aml) { acpi_rs_length resource_length; ACPI_FUNCTION_ENTRY(); /* * Byte 0 contains the descriptor name (Resource Type) * Examine the large/small bit in the resource header */ if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) { /* Large Resource type -- bytes 1-2 contain the 16-bit length */ ACPI_MOVE_16_TO_16(&resource_length, ACPI_ADD_PTR(u8, aml, 1)); } else { /* Small Resource type -- bits 2:0 of byte 0 contain the length */ resource_length = (u16) (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK); } return (resource_length); } /******************************************************************************* * * FUNCTION: acpi_ut_get_resource_header_length * * PARAMETERS: aml - Pointer to the raw AML resource descriptor * * RETURN: Length of the AML header (depends on large/small descriptor) * * DESCRIPTION: Get the length of the header for this resource. * ******************************************************************************/ u8 acpi_ut_get_resource_header_length(void *aml) { ACPI_FUNCTION_ENTRY(); /* Examine the large/small bit in the resource header */ if (ACPI_GET8(aml) & ACPI_RESOURCE_NAME_LARGE) { return (sizeof(struct aml_resource_large_header)); } else { return (sizeof(struct aml_resource_small_header)); } } /******************************************************************************* * * FUNCTION: acpi_ut_get_descriptor_length * * PARAMETERS: aml - Pointer to the raw AML resource descriptor * * RETURN: Byte length * * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the * length of the descriptor header and the length field itself. * Used to walk descriptor lists. * ******************************************************************************/ u32 acpi_ut_get_descriptor_length(void *aml) { ACPI_FUNCTION_ENTRY(); /* * Get the Resource Length (does not include header length) and add * the header length (depends on if this is a small or large resource) */ return (acpi_ut_get_resource_length(aml) + acpi_ut_get_resource_header_length(aml)); } /******************************************************************************* * * FUNCTION: acpi_ut_get_resource_end_tag * * PARAMETERS: obj_desc - The resource template buffer object * end_tag - Where the pointer to the end_tag is returned * * RETURN: Status, pointer to the end tag * * DESCRIPTION: Find the end_tag resource descriptor in an AML resource template * Note: allows a buffer length of zero. * ******************************************************************************/ acpi_status acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc, u8 **end_tag) { acpi_status status; ACPI_FUNCTION_TRACE(ut_get_resource_end_tag); /* Allow a buffer length of zero */ if (!obj_desc->buffer.length) { *end_tag = obj_desc->buffer.pointer; return_ACPI_STATUS(AE_OK); } /* Validate the template and get a pointer to the end_tag */ status = acpi_ut_walk_aml_resources(NULL, obj_desc->buffer.pointer, obj_desc->buffer.length, NULL, (void **)end_tag); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/utresrc.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: rsinfo - Dispatch and Info tables * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rsinfo") /* * Resource dispatch and information tables. Any new resource types (either * Large or Small) must be reflected in each of these tables, so they are here * in one place. * * The tables for Large descriptors are indexed by bits 6:0 of the AML * descriptor type byte. The tables for Small descriptors are indexed by * bits 6:3 of the descriptor byte. The tables for internal resource * descriptors are indexed by the acpi_resource_type field. */ /* Dispatch table for resource-to-AML (Set Resource) conversion functions */ struct acpi_rsconvert_info *acpi_gbl_set_resource_dispatch[] = { acpi_rs_set_irq, /* 0x00, ACPI_RESOURCE_TYPE_IRQ */ acpi_rs_convert_dma, /* 0x01, ACPI_RESOURCE_TYPE_DMA */ acpi_rs_set_start_dpf, /* 0x02, ACPI_RESOURCE_TYPE_START_DEPENDENT */ acpi_rs_convert_end_dpf, /* 0x03, ACPI_RESOURCE_TYPE_END_DEPENDENT */ acpi_rs_convert_io, /* 0x04, ACPI_RESOURCE_TYPE_IO */ acpi_rs_convert_fixed_io, /* 0x05, ACPI_RESOURCE_TYPE_FIXED_IO */ acpi_rs_set_vendor, /* 0x06, ACPI_RESOURCE_TYPE_VENDOR */ acpi_rs_convert_end_tag, /* 0x07, ACPI_RESOURCE_TYPE_END_TAG */ acpi_rs_convert_memory24, /* 0x08, ACPI_RESOURCE_TYPE_MEMORY24 */ acpi_rs_convert_memory32, /* 0x09, ACPI_RESOURCE_TYPE_MEMORY32 */ acpi_rs_convert_fixed_memory32, /* 0x0A, ACPI_RESOURCE_TYPE_FIXED_MEMORY32 */ acpi_rs_convert_address16, /* 0x0B, ACPI_RESOURCE_TYPE_ADDRESS16 */ acpi_rs_convert_address32, /* 0x0C, ACPI_RESOURCE_TYPE_ADDRESS32 */ acpi_rs_convert_address64, /* 0x0D, ACPI_RESOURCE_TYPE_ADDRESS64 */ acpi_rs_convert_ext_address64, /* 0x0E, ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64 */ acpi_rs_convert_ext_irq, /* 0x0F, ACPI_RESOURCE_TYPE_EXTENDED_IRQ */ acpi_rs_convert_generic_reg, /* 0x10, ACPI_RESOURCE_TYPE_GENERIC_REGISTER */ acpi_rs_convert_gpio, /* 0x11, ACPI_RESOURCE_TYPE_GPIO */ acpi_rs_convert_fixed_dma, /* 0x12, ACPI_RESOURCE_TYPE_FIXED_DMA */ NULL, /* 0x13, ACPI_RESOURCE_TYPE_SERIAL_BUS - Use subtype table below */ acpi_rs_convert_pin_function, /* 0x14, ACPI_RESOURCE_TYPE_PIN_FUNCTION */ acpi_rs_convert_pin_config, /* 0x15, ACPI_RESOURCE_TYPE_PIN_CONFIG */ acpi_rs_convert_pin_group, /* 0x16, ACPI_RESOURCE_TYPE_PIN_GROUP */ acpi_rs_convert_pin_group_function, /* 0x17, ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION */ acpi_rs_convert_pin_group_config, /* 0x18, ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG */ acpi_rs_convert_clock_input, /* 0x19, ACPI_RESOURCE_TYPE_CLOCK_INPUT */ }; /* Dispatch tables for AML-to-resource (Get Resource) conversion functions */ struct acpi_rsconvert_info *acpi_gbl_get_resource_dispatch[] = { /* Small descriptors */ NULL, /* 0x00, Reserved */ NULL, /* 0x01, Reserved */ NULL, /* 0x02, Reserved */ NULL, /* 0x03, Reserved */ acpi_rs_get_irq, /* 0x04, ACPI_RESOURCE_NAME_IRQ */ acpi_rs_convert_dma, /* 0x05, ACPI_RESOURCE_NAME_DMA */ acpi_rs_get_start_dpf, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */ acpi_rs_convert_end_dpf, /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */ acpi_rs_convert_io, /* 0x08, ACPI_RESOURCE_NAME_IO */ acpi_rs_convert_fixed_io, /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO */ acpi_rs_convert_fixed_dma, /* 0x0A, ACPI_RESOURCE_NAME_FIXED_DMA */ NULL, /* 0x0B, Reserved */ NULL, /* 0x0C, Reserved */ NULL, /* 0x0D, Reserved */ acpi_rs_get_vendor_small, /* 0x0E, ACPI_RESOURCE_NAME_VENDOR_SMALL */ acpi_rs_convert_end_tag, /* 0x0F, ACPI_RESOURCE_NAME_END_TAG */ /* Large descriptors */ NULL, /* 0x00, Reserved */ acpi_rs_convert_memory24, /* 0x01, ACPI_RESOURCE_NAME_MEMORY24 */ acpi_rs_convert_generic_reg, /* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */ NULL, /* 0x03, Reserved */ acpi_rs_get_vendor_large, /* 0x04, ACPI_RESOURCE_NAME_VENDOR_LARGE */ acpi_rs_convert_memory32, /* 0x05, ACPI_RESOURCE_NAME_MEMORY32 */ acpi_rs_convert_fixed_memory32, /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY32 */ acpi_rs_convert_address32, /* 0x07, ACPI_RESOURCE_NAME_ADDRESS32 */ acpi_rs_convert_address16, /* 0x08, ACPI_RESOURCE_NAME_ADDRESS16 */ acpi_rs_convert_ext_irq, /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_IRQ */ acpi_rs_convert_address64, /* 0x0A, ACPI_RESOURCE_NAME_ADDRESS64 */ acpi_rs_convert_ext_address64, /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64 */ acpi_rs_convert_gpio, /* 0x0C, ACPI_RESOURCE_NAME_GPIO */ acpi_rs_convert_pin_function, /* 0x0D, ACPI_RESOURCE_NAME_PIN_FUNCTION */ NULL, /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS - Use subtype table below */ acpi_rs_convert_pin_config, /* 0x0F, ACPI_RESOURCE_NAME_PIN_CONFIG */ acpi_rs_convert_pin_group, /* 0x10, ACPI_RESOURCE_NAME_PIN_GROUP */ acpi_rs_convert_pin_group_function, /* 0x11, ACPI_RESOURCE_NAME_PIN_GROUP_FUNCTION */ acpi_rs_convert_pin_group_config, /* 0x12, ACPI_RESOURCE_NAME_PIN_GROUP_CONFIG */ acpi_rs_convert_clock_input, /* 0x13, ACPI_RESOURCE_NAME_CLOCK_INPUT */ }; /* Subtype table for serial_bus -- I2C, SPI, UART, and CSI2 */ struct acpi_rsconvert_info *acpi_gbl_convert_resource_serial_bus_dispatch[] = { NULL, acpi_rs_convert_i2c_serial_bus, acpi_rs_convert_spi_serial_bus, acpi_rs_convert_uart_serial_bus, acpi_rs_convert_csi2_serial_bus }; #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DISASSEMBLER) || defined(ACPI_DEBUGGER) /* Dispatch table for resource dump functions */ struct acpi_rsdump_info *acpi_gbl_dump_resource_dispatch[] = { acpi_rs_dump_irq, /* ACPI_RESOURCE_TYPE_IRQ */ acpi_rs_dump_dma, /* ACPI_RESOURCE_TYPE_DMA */ acpi_rs_dump_start_dpf, /* ACPI_RESOURCE_TYPE_START_DEPENDENT */ acpi_rs_dump_end_dpf, /* ACPI_RESOURCE_TYPE_END_DEPENDENT */ acpi_rs_dump_io, /* ACPI_RESOURCE_TYPE_IO */ acpi_rs_dump_fixed_io, /* ACPI_RESOURCE_TYPE_FIXED_IO */ acpi_rs_dump_vendor, /* ACPI_RESOURCE_TYPE_VENDOR */ acpi_rs_dump_end_tag, /* ACPI_RESOURCE_TYPE_END_TAG */ acpi_rs_dump_memory24, /* ACPI_RESOURCE_TYPE_MEMORY24 */ acpi_rs_dump_memory32, /* ACPI_RESOURCE_TYPE_MEMORY32 */ acpi_rs_dump_fixed_memory32, /* ACPI_RESOURCE_TYPE_FIXED_MEMORY32 */ acpi_rs_dump_address16, /* ACPI_RESOURCE_TYPE_ADDRESS16 */ acpi_rs_dump_address32, /* ACPI_RESOURCE_TYPE_ADDRESS32 */ acpi_rs_dump_address64, /* ACPI_RESOURCE_TYPE_ADDRESS64 */ acpi_rs_dump_ext_address64, /* ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64 */ acpi_rs_dump_ext_irq, /* ACPI_RESOURCE_TYPE_EXTENDED_IRQ */ acpi_rs_dump_generic_reg, /* ACPI_RESOURCE_TYPE_GENERIC_REGISTER */ acpi_rs_dump_gpio, /* ACPI_RESOURCE_TYPE_GPIO */ acpi_rs_dump_fixed_dma, /* ACPI_RESOURCE_TYPE_FIXED_DMA */ NULL, /* ACPI_RESOURCE_TYPE_SERIAL_BUS */ acpi_rs_dump_pin_function, /* ACPI_RESOURCE_TYPE_PIN_FUNCTION */ acpi_rs_dump_pin_config, /* ACPI_RESOURCE_TYPE_PIN_CONFIG */ acpi_rs_dump_pin_group, /* ACPI_RESOURCE_TYPE_PIN_GROUP */ acpi_rs_dump_pin_group_function, /* ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION */ acpi_rs_dump_pin_group_config, /* ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG */ acpi_rs_dump_clock_input, /* ACPI_RESOURCE_TYPE_CLOCK_INPUT */ }; struct acpi_rsdump_info *acpi_gbl_dump_serial_bus_dispatch[] = { NULL, acpi_rs_dump_i2c_serial_bus, /* AML_RESOURCE_I2C_BUS_TYPE */ acpi_rs_dump_spi_serial_bus, /* AML_RESOURCE_SPI_BUS_TYPE */ acpi_rs_dump_uart_serial_bus, /* AML_RESOURCE_UART_BUS_TYPE */ acpi_rs_dump_csi2_serial_bus, /* AML_RESOURCE_CSI2_BUS_TYPE */ }; #endif /* * Base sizes for external AML resource descriptors, indexed by internal type. * Includes size of the descriptor header (1 byte for small descriptors, * 3 bytes for large descriptors) */ const u8 acpi_gbl_aml_resource_sizes[] = { sizeof(struct aml_resource_irq), /* ACPI_RESOURCE_TYPE_IRQ (optional Byte 3 always created) */ sizeof(struct aml_resource_dma), /* ACPI_RESOURCE_TYPE_DMA */ sizeof(struct aml_resource_start_dependent), /* ACPI_RESOURCE_TYPE_START_DEPENDENT (optional Byte 1 always created) */ sizeof(struct aml_resource_end_dependent), /* ACPI_RESOURCE_TYPE_END_DEPENDENT */ sizeof(struct aml_resource_io), /* ACPI_RESOURCE_TYPE_IO */ sizeof(struct aml_resource_fixed_io), /* ACPI_RESOURCE_TYPE_FIXED_IO */ sizeof(struct aml_resource_vendor_small), /* ACPI_RESOURCE_TYPE_VENDOR */ sizeof(struct aml_resource_end_tag), /* ACPI_RESOURCE_TYPE_END_TAG */ sizeof(struct aml_resource_memory24), /* ACPI_RESOURCE_TYPE_MEMORY24 */ sizeof(struct aml_resource_memory32), /* ACPI_RESOURCE_TYPE_MEMORY32 */ sizeof(struct aml_resource_fixed_memory32), /* ACPI_RESOURCE_TYPE_FIXED_MEMORY32 */ sizeof(struct aml_resource_address16), /* ACPI_RESOURCE_TYPE_ADDRESS16 */ sizeof(struct aml_resource_address32), /* ACPI_RESOURCE_TYPE_ADDRESS32 */ sizeof(struct aml_resource_address64), /* ACPI_RESOURCE_TYPE_ADDRESS64 */ sizeof(struct aml_resource_extended_address64), /*ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64 */ sizeof(struct aml_resource_extended_irq), /* ACPI_RESOURCE_TYPE_EXTENDED_IRQ */ sizeof(struct aml_resource_generic_register), /* ACPI_RESOURCE_TYPE_GENERIC_REGISTER */ sizeof(struct aml_resource_gpio), /* ACPI_RESOURCE_TYPE_GPIO */ sizeof(struct aml_resource_fixed_dma), /* ACPI_RESOURCE_TYPE_FIXED_DMA */ sizeof(struct aml_resource_common_serialbus), /* ACPI_RESOURCE_TYPE_SERIAL_BUS */ sizeof(struct aml_resource_pin_function), /* ACPI_RESOURCE_TYPE_PIN_FUNCTION */ sizeof(struct aml_resource_pin_config), /* ACPI_RESOURCE_TYPE_PIN_CONFIG */ sizeof(struct aml_resource_pin_group), /* ACPI_RESOURCE_TYPE_PIN_GROUP */ sizeof(struct aml_resource_pin_group_function), /* ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION */ sizeof(struct aml_resource_pin_group_config), /* ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG */ sizeof(struct aml_resource_clock_input), /* ACPI_RESOURCE_TYPE_CLOCK_INPUT */ }; const u8 acpi_gbl_resource_struct_sizes[] = { /* Small descriptors */ 0, 0, 0, 0, ACPI_RS_SIZE(struct acpi_resource_irq), ACPI_RS_SIZE(struct acpi_resource_dma), ACPI_RS_SIZE(struct acpi_resource_start_dependent), ACPI_RS_SIZE_MIN, ACPI_RS_SIZE(struct acpi_resource_io), ACPI_RS_SIZE(struct acpi_resource_fixed_io), ACPI_RS_SIZE(struct acpi_resource_fixed_dma), 0, 0, 0, ACPI_RS_SIZE(struct acpi_resource_vendor), ACPI_RS_SIZE_MIN, /* Large descriptors */ 0, ACPI_RS_SIZE(struct acpi_resource_memory24), ACPI_RS_SIZE(struct acpi_resource_generic_register), 0, ACPI_RS_SIZE(struct acpi_resource_vendor), ACPI_RS_SIZE(struct acpi_resource_memory32), ACPI_RS_SIZE(struct acpi_resource_fixed_memory32), ACPI_RS_SIZE(struct acpi_resource_address32), ACPI_RS_SIZE(struct acpi_resource_address16), ACPI_RS_SIZE(struct acpi_resource_extended_irq), ACPI_RS_SIZE(struct acpi_resource_address64), ACPI_RS_SIZE(struct acpi_resource_extended_address64), ACPI_RS_SIZE(struct acpi_resource_gpio), ACPI_RS_SIZE(struct acpi_resource_pin_function), ACPI_RS_SIZE(struct acpi_resource_common_serialbus), ACPI_RS_SIZE(struct acpi_resource_pin_config), ACPI_RS_SIZE(struct acpi_resource_pin_group), ACPI_RS_SIZE(struct acpi_resource_pin_group_function), ACPI_RS_SIZE(struct acpi_resource_pin_group_config), ACPI_RS_SIZE(struct acpi_resource_clock_input), }; const u8 acpi_gbl_aml_resource_serial_bus_sizes[] = { 0, sizeof(struct aml_resource_i2c_serialbus), sizeof(struct aml_resource_spi_serialbus), sizeof(struct aml_resource_uart_serialbus), sizeof(struct aml_resource_csi2_serialbus), }; const u8 acpi_gbl_resource_struct_serial_bus_sizes[] = { 0, ACPI_RS_SIZE(struct acpi_resource_i2c_serialbus), ACPI_RS_SIZE(struct acpi_resource_spi_serialbus), ACPI_RS_SIZE(struct acpi_resource_uart_serialbus), ACPI_RS_SIZE(struct acpi_resource_csi2_serialbus), };
linux-master
drivers/acpi/acpica/rsinfo.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: tbdata - Table manager data structure functions * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "actables.h" #include "acevents.h" #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbdata") /* Local prototypes */ static acpi_status acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index); static u8 acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index); /******************************************************************************* * * FUNCTION: acpi_tb_compare_tables * * PARAMETERS: table_desc - Table 1 descriptor to be compared * table_index - Index of table 2 to be compared * * RETURN: TRUE if both tables are identical. * * DESCRIPTION: This function compares a table with another table that has * already been installed in the root table list. * ******************************************************************************/ static u8 acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index) { acpi_status status = AE_OK; u8 is_identical; struct acpi_table_header *table; u32 table_length; u8 table_flags; status = acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index], &table, &table_length, &table_flags); if (ACPI_FAILURE(status)) { return (FALSE); } /* * Check for a table match on the entire table length, * not just the header. */ is_identical = (u8)((table_desc->length != table_length || memcmp(table_desc->pointer, table, table_length)) ? FALSE : TRUE); /* Release the acquired table */ acpi_tb_release_table(table, table_length, table_flags); return (is_identical); } /******************************************************************************* * * FUNCTION: acpi_tb_init_table_descriptor * * PARAMETERS: table_desc - Table descriptor * address - Physical address of the table * flags - Allocation flags of the table * table - Pointer to the table * * RETURN: None * * DESCRIPTION: Initialize a new table descriptor * ******************************************************************************/ void acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc, acpi_physical_address address, u8 flags, struct acpi_table_header *table) { /* * Initialize the table descriptor. Set the pointer to NULL for external * tables, since the table is not fully mapped at this time. */ memset(table_desc, 0, sizeof(struct acpi_table_desc)); table_desc->address = address; table_desc->length = table->length; table_desc->flags = flags; ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature); switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) { case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: table_desc->pointer = table; break; case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: default: break; } } /******************************************************************************* * * FUNCTION: acpi_tb_acquire_table * * PARAMETERS: table_desc - Table descriptor * table_ptr - Where table is returned * table_length - Where table length is returned * table_flags - Where table allocation flags are returned * * RETURN: Status * * DESCRIPTION: Acquire an ACPI table. It can be used for tables not * maintained in the acpi_gbl_root_table_list. * ******************************************************************************/ acpi_status acpi_tb_acquire_table(struct acpi_table_desc *table_desc, struct acpi_table_header **table_ptr, u32 *table_length, u8 *table_flags) { struct acpi_table_header *table = NULL; switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) { case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: table = acpi_os_map_memory(table_desc->address, table_desc->length); break; case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: table = table_desc->pointer; break; default: break; } /* Table is not valid yet */ if (!table) { return (AE_NO_MEMORY); } /* Fill the return values */ *table_ptr = table; *table_length = table_desc->length; *table_flags = table_desc->flags; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_tb_release_table * * PARAMETERS: table - Pointer for the table * table_length - Length for the table * table_flags - Allocation flags for the table * * RETURN: None * * DESCRIPTION: Release a table. The inverse of acpi_tb_acquire_table(). * ******************************************************************************/ void acpi_tb_release_table(struct acpi_table_header *table, u32 table_length, u8 table_flags) { switch (table_flags & ACPI_TABLE_ORIGIN_MASK) { case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: acpi_os_unmap_memory(table, table_length); break; case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: default: break; } } /******************************************************************************* * * FUNCTION: acpi_tb_acquire_temp_table * * PARAMETERS: table_desc - Table descriptor to be acquired * address - Address of the table * flags - Allocation flags of the table * table - Pointer to the table (required for virtual * origins, optional for physical) * * RETURN: Status * * DESCRIPTION: This function validates the table header to obtain the length * of a table and fills the table descriptor to make its state as * "INSTALLED". Such a table descriptor is only used for verified * installation. * ******************************************************************************/ acpi_status acpi_tb_acquire_temp_table(struct acpi_table_desc *table_desc, acpi_physical_address address, u8 flags, struct acpi_table_header *table) { u8 mapped_table = FALSE; switch (flags & ACPI_TABLE_ORIGIN_MASK) { case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: /* Get the length of the full table from the header */ if (!table) { table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); if (!table) { return (AE_NO_MEMORY); } mapped_table = TRUE; } break; case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: if (!table) { return (AE_BAD_PARAMETER); } break; default: /* Table is not valid yet */ return (AE_NO_MEMORY); } acpi_tb_init_table_descriptor(table_desc, address, flags, table); if (mapped_table) { acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_tb_release_temp_table * * PARAMETERS: table_desc - Table descriptor to be released * * RETURN: Status * * DESCRIPTION: The inverse of acpi_tb_acquire_temp_table(). * *****************************************************************************/ void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc) { /* * Note that the .Address is maintained by the callers of * acpi_tb_acquire_temp_table(), thus do not invoke acpi_tb_uninstall_table() * where .Address will be freed. */ acpi_tb_invalidate_table(table_desc); } /****************************************************************************** * * FUNCTION: acpi_tb_validate_table * * PARAMETERS: table_desc - Table descriptor * * RETURN: Status * * DESCRIPTION: This function is called to validate the table, the returned * table descriptor is in "VALIDATED" state. * *****************************************************************************/ acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(tb_validate_table); /* Validate the table if necessary */ if (!table_desc->pointer) { status = acpi_tb_acquire_table(table_desc, &table_desc->pointer, &table_desc->length, &table_desc->flags); if (!table_desc->pointer) { status = AE_NO_MEMORY; } } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_tb_invalidate_table * * PARAMETERS: table_desc - Table descriptor * * RETURN: None * * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of * acpi_tb_validate_table(). * ******************************************************************************/ void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc) { ACPI_FUNCTION_TRACE(tb_invalidate_table); /* Table must be validated */ if (!table_desc->pointer) { return_VOID; } acpi_tb_release_table(table_desc->pointer, table_desc->length, table_desc->flags); switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) { case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: table_desc->pointer = NULL; break; case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: default: break; } return_VOID; } /****************************************************************************** * * FUNCTION: acpi_tb_validate_temp_table * * PARAMETERS: table_desc - Table descriptor * * RETURN: Status * * DESCRIPTION: This function is called to validate the table, the returned * table descriptor is in "VALIDATED" state. * *****************************************************************************/ acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc) { if (!table_desc->pointer && !acpi_gbl_enable_table_validation) { /* * Only validates the header of the table. * Note that Length contains the size of the mapping after invoking * this work around, this value is required by * acpi_tb_release_temp_table(). * We can do this because in acpi_init_table_descriptor(), the Length * field of the installed descriptor is filled with the actual * table length obtaining from the table header. */ table_desc->length = sizeof(struct acpi_table_header); } return (acpi_tb_validate_table(table_desc)); } /******************************************************************************* * * FUNCTION: acpi_tb_check_duplication * * PARAMETERS: table_desc - Table descriptor * table_index - Where the table index is returned * * RETURN: Status * * DESCRIPTION: Avoid installing duplicated tables. However table override and * user aided dynamic table load is allowed, thus comparing the * address of the table is not sufficient, and checking the entire * table content is required. * ******************************************************************************/ static acpi_status acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index) { u32 i; ACPI_FUNCTION_TRACE(tb_check_duplication); /* Check if table is already registered */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { /* Do not compare with unverified tables */ if (! (acpi_gbl_root_table_list.tables[i]. flags & ACPI_TABLE_IS_VERIFIED)) { continue; } /* * Check for a table match on the entire table length, * not just the header. */ if (!acpi_tb_compare_tables(table_desc, i)) { continue; } /* * Note: the current mechanism does not unregister a table if it is * dynamically unloaded. The related namespace entries are deleted, * but the table remains in the root table list. * * The assumption here is that the number of different tables that * will be loaded is actually small, and there is minimal overhead * in just keeping the table in case it is needed again. * * If this assumption changes in the future (perhaps on large * machines with many table load/unload operations), tables will * need to be unregistered when they are unloaded, and slots in the * root table list should be reused when empty. */ if (acpi_gbl_root_table_list.tables[i].flags & ACPI_TABLE_IS_LOADED) { /* Table is still loaded, this is an error */ return_ACPI_STATUS(AE_ALREADY_EXISTS); } else { *table_index = i; return_ACPI_STATUS(AE_CTRL_TERMINATE); } } /* Indicate no duplication to the caller */ return_ACPI_STATUS(AE_OK); } /****************************************************************************** * * FUNCTION: acpi_tb_verify_temp_table * * PARAMETERS: table_desc - Table descriptor * signature - Table signature to verify * table_index - Where the table index is returned * * RETURN: Status * * DESCRIPTION: This function is called to validate and verify the table, the * returned table descriptor is in "VALIDATED" state. * Note that 'TableIndex' is required to be set to !NULL to * enable duplication check. * *****************************************************************************/ acpi_status acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature, u32 *table_index) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(tb_verify_temp_table); /* Validate the table */ status = acpi_tb_validate_temp_table(table_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(AE_NO_MEMORY); } /* If a particular signature is expected (DSDT/FACS), it must match */ if (signature && !ACPI_COMPARE_NAMESEG(&table_desc->signature, signature)) { ACPI_BIOS_ERROR((AE_INFO, "Invalid signature 0x%X for ACPI table, expected [%s]", table_desc->signature.integer, signature)); status = AE_BAD_SIGNATURE; goto invalidate_and_exit; } if (acpi_gbl_enable_table_validation) { /* Verify the checksum */ status = acpi_ut_verify_checksum(table_desc->pointer, table_desc->length); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "%4.4s 0x%8.8X%8.8X" " Attempted table install failed", acpi_ut_valid_nameseg(table_desc-> signature. ascii) ? table_desc->signature.ascii : "????", ACPI_FORMAT_UINT64(table_desc-> address))); goto invalidate_and_exit; } /* Avoid duplications */ if (table_index) { status = acpi_tb_check_duplication(table_desc, table_index); if (ACPI_FAILURE(status)) { if (status != AE_CTRL_TERMINATE) { ACPI_EXCEPTION((AE_INFO, status, "%4.4s 0x%8.8X%8.8X" " Table is already loaded", acpi_ut_valid_nameseg (table_desc->signature. ascii) ? table_desc-> signature. ascii : "????", ACPI_FORMAT_UINT64 (table_desc->address))); } goto invalidate_and_exit; } } table_desc->flags |= ACPI_TABLE_IS_VERIFIED; } return_ACPI_STATUS(status); invalidate_and_exit: acpi_tb_invalidate_table(table_desc); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_tb_resize_root_table_list * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Expand the size of global table array * ******************************************************************************/ acpi_status acpi_tb_resize_root_table_list(void) { struct acpi_table_desc *tables; u32 table_count; u32 current_table_count, max_table_count; u32 i; ACPI_FUNCTION_TRACE(tb_resize_root_table_list); /* allow_resize flag is a parameter to acpi_initialize_tables */ if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) { ACPI_ERROR((AE_INFO, "Resize of Root Table Array is not allowed")); return_ACPI_STATUS(AE_SUPPORT); } /* Increase the Table Array size */ if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { table_count = acpi_gbl_root_table_list.max_table_count; } else { table_count = acpi_gbl_root_table_list.current_table_count; } max_table_count = table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT; tables = ACPI_ALLOCATE_ZEROED(((acpi_size)max_table_count) * sizeof(struct acpi_table_desc)); if (!tables) { ACPI_ERROR((AE_INFO, "Could not allocate new root table array")); return_ACPI_STATUS(AE_NO_MEMORY); } /* Copy and free the previous table array */ current_table_count = 0; if (acpi_gbl_root_table_list.tables) { for (i = 0; i < table_count; i++) { if (acpi_gbl_root_table_list.tables[i].address) { memcpy(tables + current_table_count, acpi_gbl_root_table_list.tables + i, sizeof(struct acpi_table_desc)); current_table_count++; } } if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { ACPI_FREE(acpi_gbl_root_table_list.tables); } } acpi_gbl_root_table_list.tables = tables; acpi_gbl_root_table_list.max_table_count = max_table_count; acpi_gbl_root_table_list.current_table_count = current_table_count; acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED; return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_tb_get_next_table_descriptor * * PARAMETERS: table_index - Where table index is returned * table_desc - Where table descriptor is returned * * RETURN: Status and table index/descriptor. * * DESCRIPTION: Allocate a new ACPI table entry to the global table list * ******************************************************************************/ acpi_status acpi_tb_get_next_table_descriptor(u32 *table_index, struct acpi_table_desc **table_desc) { acpi_status status; u32 i; /* Ensure that there is room for the table in the Root Table List */ if (acpi_gbl_root_table_list.current_table_count >= acpi_gbl_root_table_list.max_table_count) { status = acpi_tb_resize_root_table_list(); if (ACPI_FAILURE(status)) { return (status); } } i = acpi_gbl_root_table_list.current_table_count; acpi_gbl_root_table_list.current_table_count++; if (table_index) { *table_index = i; } if (table_desc) { *table_desc = &acpi_gbl_root_table_list.tables[i]; } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_tb_terminate * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Delete all internal ACPI tables * ******************************************************************************/ void acpi_tb_terminate(void) { u32 i; ACPI_FUNCTION_TRACE(tb_terminate); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); /* Delete the individual tables */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]); } /* * Delete the root table array if allocated locally. Array cannot be * mapped, so we don't need to check for that flag. */ if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { ACPI_FREE(acpi_gbl_root_table_list.tables); } acpi_gbl_root_table_list.tables = NULL; acpi_gbl_root_table_list.flags = 0; acpi_gbl_root_table_list.current_table_count = 0; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n")); (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_tb_delete_namespace_by_owner * * PARAMETERS: table_index - Table index * * RETURN: Status * * DESCRIPTION: Delete all namespace objects created when this table was loaded. * ******************************************************************************/ acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index) { acpi_owner_id owner_id; acpi_status status; ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner); status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (table_index >= acpi_gbl_root_table_list.current_table_count) { /* The table index does not exist */ (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(AE_NOT_EXIST); } /* Get the owner ID for this table, used to delete namespace nodes */ owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id; (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); /* * Need to acquire the namespace writer lock to prevent interference * with any concurrent namespace walks. The interpreter must be * released during the deletion since the acquisition of the deletion * lock may block, and also since the execution of a namespace walk * must be allowed to use the interpreter. */ status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_ns_delete_namespace_by_owner(owner_id); acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_tb_allocate_owner_id * * PARAMETERS: table_index - Table index * * RETURN: Status * * DESCRIPTION: Allocates owner_id in table_desc * ******************************************************************************/ acpi_status acpi_tb_allocate_owner_id(u32 table_index) { acpi_status status = AE_BAD_PARAMETER; ACPI_FUNCTION_TRACE(tb_allocate_owner_id); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (table_index < acpi_gbl_root_table_list.current_table_count) { status = acpi_ut_allocate_owner_id(& (acpi_gbl_root_table_list. tables[table_index].owner_id)); } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_tb_release_owner_id * * PARAMETERS: table_index - Table index * * RETURN: Status * * DESCRIPTION: Releases owner_id in table_desc * ******************************************************************************/ acpi_status acpi_tb_release_owner_id(u32 table_index) { acpi_status status = AE_BAD_PARAMETER; ACPI_FUNCTION_TRACE(tb_release_owner_id); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (table_index < acpi_gbl_root_table_list.current_table_count) { acpi_ut_release_owner_id(& (acpi_gbl_root_table_list. tables[table_index].owner_id)); status = AE_OK; } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_tb_get_owner_id * * PARAMETERS: table_index - Table index * owner_id - Where the table owner_id is returned * * RETURN: Status * * DESCRIPTION: returns owner_id for the ACPI table * ******************************************************************************/ acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id) { acpi_status status = AE_BAD_PARAMETER; ACPI_FUNCTION_TRACE(tb_get_owner_id); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (table_index < acpi_gbl_root_table_list.current_table_count) { *owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id; status = AE_OK; } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_tb_is_table_loaded * * PARAMETERS: table_index - Index into the root table * * RETURN: Table Loaded Flag * ******************************************************************************/ u8 acpi_tb_is_table_loaded(u32 table_index) { u8 is_loaded = FALSE; (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (table_index < acpi_gbl_root_table_list.current_table_count) { is_loaded = (u8) (acpi_gbl_root_table_list.tables[table_index].flags & ACPI_TABLE_IS_LOADED); } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return (is_loaded); } /******************************************************************************* * * FUNCTION: acpi_tb_set_table_loaded_flag * * PARAMETERS: table_index - Table index * is_loaded - TRUE if table is loaded, FALSE otherwise * * RETURN: None * * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE. * ******************************************************************************/ void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded) { (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (table_index < acpi_gbl_root_table_list.current_table_count) { if (is_loaded) { acpi_gbl_root_table_list.tables[table_index].flags |= ACPI_TABLE_IS_LOADED; } else { acpi_gbl_root_table_list.tables[table_index].flags &= ~ACPI_TABLE_IS_LOADED; } } (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); } /******************************************************************************* * * FUNCTION: acpi_tb_load_table * * PARAMETERS: table_index - Table index * parent_node - Where table index is returned * * RETURN: Status * * DESCRIPTION: Load an ACPI table * ******************************************************************************/ acpi_status acpi_tb_load_table(u32 table_index, struct acpi_namespace_node *parent_node) { struct acpi_table_header *table; acpi_status status; acpi_owner_id owner_id; ACPI_FUNCTION_TRACE(tb_load_table); /* * Note: Now table is "INSTALLED", it must be validated before * using. */ status = acpi_get_table_by_index(table_index, &table); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ns_load_table(table_index, parent_node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is * responsible for discovering any new wake GPEs by running _PRW methods * that may have been loaded by this table. */ status = acpi_tb_get_owner_id(table_index, &owner_id); if (ACPI_SUCCESS(status)) { acpi_ev_update_gpes(owner_id); } /* Invoke table handler */ acpi_tb_notify_table(ACPI_TABLE_EVENT_LOAD, table); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_tb_install_and_load_table * * PARAMETERS: address - Physical address of the table * flags - Allocation flags of the table * table - Pointer to the table (required for * virtual origins, optional for * physical) * override - Whether override should be performed * table_index - Where table index is returned * * RETURN: Status * * DESCRIPTION: Install and load an ACPI table * ******************************************************************************/ acpi_status acpi_tb_install_and_load_table(acpi_physical_address address, u8 flags, struct acpi_table_header *table, u8 override, u32 *table_index) { acpi_status status; u32 i; ACPI_FUNCTION_TRACE(tb_install_and_load_table); /* Install the table and load it into the namespace */ status = acpi_tb_install_standard_table(address, flags, table, TRUE, override, &i); if (ACPI_FAILURE(status)) { goto exit; } status = acpi_tb_load_table(i, acpi_gbl_root_node); exit: *table_index = i; return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_tb_install_and_load_table) /******************************************************************************* * * FUNCTION: acpi_tb_unload_table * * PARAMETERS: table_index - Table index * * RETURN: Status * * DESCRIPTION: Unload an ACPI table * ******************************************************************************/ acpi_status acpi_tb_unload_table(u32 table_index) { acpi_status status = AE_OK; struct acpi_table_header *table; ACPI_FUNCTION_TRACE(tb_unload_table); /* Ensure the table is still loaded */ if (!acpi_tb_is_table_loaded(table_index)) { return_ACPI_STATUS(AE_NOT_EXIST); } /* Invoke table handler */ status = acpi_get_table_by_index(table_index, &table); if (ACPI_SUCCESS(status)) { acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD, table); } /* Delete the portion of the namespace owned by this table */ status = acpi_tb_delete_namespace_by_owner(table_index); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } (void)acpi_tb_release_owner_id(table_index); acpi_tb_set_table_loaded_flag(table_index, FALSE); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_tb_unload_table) /******************************************************************************* * * FUNCTION: acpi_tb_notify_table * * PARAMETERS: event - Table event * table - Validated table pointer * * RETURN: None * * DESCRIPTION: Notify a table event to the users. * ******************************************************************************/ void acpi_tb_notify_table(u32 event, void *table) { /* Invoke table handler if present */ if (acpi_gbl_table_handler) { (void)acpi_gbl_table_handler(event, table, acpi_gbl_table_handler_context); } }
linux-master
drivers/acpi/acpica/tbdata.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: tbfind - find table * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "actables.h" #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbfind") /******************************************************************************* * * FUNCTION: acpi_tb_find_table * * PARAMETERS: signature - String with ACPI table signature * oem_id - String with the table OEM ID * oem_table_id - String with the OEM Table ID * table_index - Where the table index is returned * * RETURN: Status and table index * * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the * Signature, OEM ID and OEM Table ID. Returns an index that can * be used to get the table header or entire table. * ******************************************************************************/ acpi_status acpi_tb_find_table(char *signature, char *oem_id, char *oem_table_id, u32 *table_index) { acpi_status status = AE_OK; struct acpi_table_header header; u32 i; ACPI_FUNCTION_TRACE(tb_find_table); /* Validate the input table signature */ if (!acpi_ut_valid_nameseg(signature)) { return_ACPI_STATUS(AE_BAD_SIGNATURE); } /* Don't allow the OEM strings to be too long */ if ((strlen(oem_id) > ACPI_OEM_ID_SIZE) || (strlen(oem_table_id) > ACPI_OEM_TABLE_ID_SIZE)) { return_ACPI_STATUS(AE_AML_STRING_LIMIT); } /* Normalize the input strings */ memset(&header, 0, sizeof(struct acpi_table_header)); ACPI_COPY_NAMESEG(header.signature, signature); strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE); strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE); /* Search for the table */ (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { if (memcmp(&(acpi_gbl_root_table_list.tables[i].signature), header.signature, ACPI_NAMESEG_SIZE)) { /* Not the requested table */ continue; } /* Table with matching signature has been found */ if (!acpi_gbl_root_table_list.tables[i].pointer) { /* Table is not currently mapped, map it */ status = acpi_tb_validate_table(&acpi_gbl_root_table_list. tables[i]); if (ACPI_FAILURE(status)) { goto unlock_and_exit; } if (!acpi_gbl_root_table_list.tables[i].pointer) { continue; } } /* Check for table match on all IDs */ if (!memcmp (acpi_gbl_root_table_list.tables[i].pointer->signature, header.signature, ACPI_NAMESEG_SIZE) && (!oem_id[0] || !memcmp (acpi_gbl_root_table_list. tables[i]. pointer->oem_id, header.oem_id, ACPI_OEM_ID_SIZE)) && (!oem_table_id[0] || !memcmp(acpi_gbl_root_table_list.tables[i].pointer-> oem_table_id, header.oem_table_id, ACPI_OEM_TABLE_ID_SIZE))) { *table_index = i; ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Found table [%4.4s]\n", header.signature)); goto unlock_and_exit; } } status = AE_NOT_FOUND; unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/tbfind.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: psxface - Parser external interfaces * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "acdispat.h" #include "acinterp.h" #include "actables.h" #include "acnamesp.h" #define _COMPONENT ACPI_PARSER ACPI_MODULE_NAME("psxface") /* Local Prototypes */ static void acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action); /******************************************************************************* * * FUNCTION: acpi_debug_trace * * PARAMETERS: method_name - Valid ACPI name string * debug_level - Optional level mask. 0 to use default * debug_layer - Optional layer mask. 0 to use default * flags - bit 1: one shot(1) or persistent(0) * * RETURN: Status * * DESCRIPTION: External interface to enable debug tracing during control * method execution * ******************************************************************************/ acpi_status acpi_debug_trace(const char *name, u32 debug_level, u32 debug_layer, u32 flags) { acpi_status status; status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } acpi_gbl_trace_method_name = name; acpi_gbl_trace_flags = flags; acpi_gbl_trace_dbg_level = debug_level; acpi_gbl_trace_dbg_layer = debug_layer; status = AE_OK; (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status); } /******************************************************************************* * * FUNCTION: acpi_ps_execute_method * * PARAMETERS: info - Method info block, contains: * node - Method Node to execute * obj_desc - Method object * parameters - List of parameters to pass to the method, * terminated by NULL. Params itself may be * NULL if no parameters are being passed. * return_object - Where to put method's return value (if * any). If NULL, no value is returned. * parameter_type - Type of Parameter list * return_object - Where to put method's return value (if * any). If NULL, no value is returned. * pass_number - Parse or execute pass * * RETURN: Status * * DESCRIPTION: Execute a control method * ******************************************************************************/ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info) { acpi_status status; union acpi_parse_object *op; struct acpi_walk_state *walk_state; ACPI_FUNCTION_TRACE(ps_execute_method); /* Quick validation of DSDT header */ acpi_tb_check_dsdt_header(); /* Validate the Info and method Node */ if (!info || !info->node) { return_ACPI_STATUS(AE_NULL_ENTRY); } /* Init for new method, wait on concurrency semaphore */ status = acpi_ds_begin_method_execution(info->node, info->obj_desc, NULL); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * The caller "owns" the parameters, so give each one an extra reference */ acpi_ps_update_parameter_list(info, REF_INCREMENT); /* * Execute the method. Performs parse simultaneously */ ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n", info->node->name.ascii, info->node, info->obj_desc)); /* Create and init a Root Node */ op = acpi_ps_create_scope_op(info->obj_desc->method.aml_start); if (!op) { status = AE_NO_MEMORY; goto cleanup; } /* Create and initialize a new walk state */ info->pass_number = ACPI_IMODE_EXECUTE; walk_state = acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL, NULL, NULL); if (!walk_state) { status = AE_NO_MEMORY; goto cleanup; } status = acpi_ds_init_aml_walk(walk_state, op, info->node, info->obj_desc->method.aml_start, info->obj_desc->method.aml_length, info, info->pass_number); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup; } walk_state->method_pathname = info->full_pathname; walk_state->method_is_nested = FALSE; if (info->obj_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL) { walk_state->parse_flags |= ACPI_PARSE_MODULE_LEVEL; } /* Invoke an internal method if necessary */ if (info->obj_desc->method.info_flags & ACPI_METHOD_INTERNAL_ONLY) { status = info->obj_desc->method.dispatch.implementation(walk_state); info->return_object = walk_state->return_desc; /* Cleanup states */ acpi_ds_scope_stack_clear(walk_state); acpi_ps_cleanup_scope(&walk_state->parser_state); acpi_ds_terminate_control_method(walk_state->method_desc, walk_state); acpi_ds_delete_walk_state(walk_state); goto cleanup; } /* * Start method evaluation with an implicit return of zero. * This is done for Windows compatibility. */ if (acpi_gbl_enable_interpreter_slack) { walk_state->implicit_return_obj = acpi_ut_create_integer_object((u64) 0); if (!walk_state->implicit_return_obj) { status = AE_NO_MEMORY; acpi_ds_delete_walk_state(walk_state); goto cleanup; } } /* Parse the AML */ status = acpi_ps_parse_aml(walk_state); /* walk_state was deleted by parse_aml */ cleanup: acpi_ps_delete_parse_tree(op); /* Take away the extra reference that we gave the parameters above */ acpi_ps_update_parameter_list(info, REF_DECREMENT); /* Exit now if error above */ if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * If the method has returned an object, signal this to the caller with * a control exception code */ if (info->return_object) { ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n", info->return_object)); ACPI_DUMP_STACK_ENTRY(info->return_object); status = AE_CTRL_RETURN_VALUE; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ps_execute_table * * PARAMETERS: info - Method info block, contains: * node - Node to where the is entered into the * namespace * obj_desc - Pseudo method object describing the AML * code of the entire table * pass_number - Parse or execute pass * * RETURN: Status * * DESCRIPTION: Execute a table * ******************************************************************************/ acpi_status acpi_ps_execute_table(struct acpi_evaluate_info *info) { acpi_status status; union acpi_parse_object *op = NULL; struct acpi_walk_state *walk_state = NULL; ACPI_FUNCTION_TRACE(ps_execute_table); /* Create and init a Root Node */ op = acpi_ps_create_scope_op(info->obj_desc->method.aml_start); if (!op) { status = AE_NO_MEMORY; goto cleanup; } /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL, NULL, NULL); if (!walk_state) { status = AE_NO_MEMORY; goto cleanup; } status = acpi_ds_init_aml_walk(walk_state, op, info->node, info->obj_desc->method.aml_start, info->obj_desc->method.aml_length, info, info->pass_number); if (ACPI_FAILURE(status)) { goto cleanup; } walk_state->method_pathname = info->full_pathname; walk_state->method_is_nested = FALSE; if (info->obj_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL) { walk_state->parse_flags |= ACPI_PARSE_MODULE_LEVEL; } /* Info->Node is the default location to load the table */ if (info->node && info->node != acpi_gbl_root_node) { status = acpi_ds_scope_stack_push(info->node, ACPI_TYPE_METHOD, walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } } /* * Parse the AML, walk_state will be deleted by parse_aml */ acpi_ex_enter_interpreter(); status = acpi_ps_parse_aml(walk_state); acpi_ex_exit_interpreter(); walk_state = NULL; cleanup: if (walk_state) { acpi_ds_delete_walk_state(walk_state); } if (op) { acpi_ps_delete_parse_tree(op); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ps_update_parameter_list * * PARAMETERS: info - See struct acpi_evaluate_info * (Used: parameter_type and Parameters) * action - Add or Remove reference * * RETURN: Status * * DESCRIPTION: Update reference count on all method parameter objects * ******************************************************************************/ static void acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action) { u32 i; if (info->parameters) { /* Update reference count for each parameter */ for (i = 0; info->parameters[i]; i++) { /* Ignore errors, just do them all */ (void)acpi_ut_update_object_reference(info-> parameters[i], action); } } }
linux-master
drivers/acpi/acpica/psxface.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exnames - interpreter/scanner name load/execute * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #include "amlcode.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exnames") /* Local prototypes */ static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs); static acpi_status acpi_ex_name_segment(u8 **in_aml_address, char *name_string); /******************************************************************************* * * FUNCTION: acpi_ex_allocate_name_string * * PARAMETERS: prefix_count - Count of parent levels. Special cases: * (-1)==root, 0==none * num_name_segs - count of 4-character name segments * * RETURN: A pointer to the allocated string segment. This segment must * be deleted by the caller. * * DESCRIPTION: Allocate a buffer for a name string. Ensure allocated name * string is long enough, and set up prefix if any. * ******************************************************************************/ static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs) { char *temp_ptr; char *name_string; u32 size_needed; ACPI_FUNCTION_TRACE(ex_allocate_name_string); /* * Allow room for all \ and ^ prefixes, all segments and a multi_name_prefix. * Also, one byte for the null terminator. * This may actually be somewhat longer than needed. */ if (prefix_count == ACPI_UINT32_MAX) { /* Special case for root */ size_needed = 1 + (ACPI_NAMESEG_SIZE * num_name_segs) + 2 + 1; } else { size_needed = prefix_count + (ACPI_NAMESEG_SIZE * num_name_segs) + 2 + 1; } /* * Allocate a buffer for the name. * This buffer must be deleted by the caller! */ name_string = ACPI_ALLOCATE(size_needed); if (!name_string) { ACPI_ERROR((AE_INFO, "Could not allocate size %u", size_needed)); return_PTR(NULL); } temp_ptr = name_string; /* Set up Root or Parent prefixes if needed */ if (prefix_count == ACPI_UINT32_MAX) { *temp_ptr++ = AML_ROOT_PREFIX; } else { while (prefix_count--) { *temp_ptr++ = AML_PARENT_PREFIX; } } /* Set up Dual or Multi prefixes if needed */ if (num_name_segs > 2) { /* Set up multi prefixes */ *temp_ptr++ = AML_MULTI_NAME_PREFIX; *temp_ptr++ = (char)num_name_segs; } else if (2 == num_name_segs) { /* Set up dual prefixes */ *temp_ptr++ = AML_DUAL_NAME_PREFIX; } /* * Terminate string following prefixes. acpi_ex_name_segment() will * append the segment(s) */ *temp_ptr = 0; return_PTR(name_string); } /******************************************************************************* * * FUNCTION: acpi_ex_name_segment * * PARAMETERS: in_aml_address - Pointer to the name in the AML code * name_string - Where to return the name. The name is appended * to any existing string to form a namepath * * RETURN: Status * * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream * ******************************************************************************/ static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string) { char *aml_address = (void *)*in_aml_address; acpi_status status = AE_OK; u32 index; char char_buf[5]; ACPI_FUNCTION_TRACE(ex_name_segment); /* * If first character is a digit, then we know that we aren't looking * at a valid name segment */ char_buf[0] = *aml_address; if ('0' <= char_buf[0] && char_buf[0] <= '9') { ACPI_ERROR((AE_INFO, "Invalid leading digit: %c", char_buf[0])); return_ACPI_STATUS(AE_CTRL_PENDING); } for (index = 0; (index < ACPI_NAMESEG_SIZE) && (acpi_ut_valid_name_char(*aml_address, 0)); index++) { char_buf[index] = *aml_address++; } /* Valid name segment */ if (index == 4) { /* Found 4 valid characters */ char_buf[4] = '\0'; if (name_string) { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Appending NameSeg %s\n", char_buf)); strcat(name_string, char_buf); } else { ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "No Name string - %s\n", char_buf)); } } else if (index == 0) { /* * First character was not a valid name character, * so we are looking at something other than a name. */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Leading character is not alpha: %02Xh (not a name)\n", char_buf[0])); status = AE_CTRL_PENDING; } else { /* * Segment started with one or more valid characters, but fewer than * the required 4 */ status = AE_AML_BAD_NAME; ACPI_ERROR((AE_INFO, "Bad character 0x%02x in name, at %p", *aml_address, aml_address)); } *in_aml_address = ACPI_CAST_PTR(u8, aml_address); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_get_name_string * * PARAMETERS: data_type - Object type to be associated with this * name * in_aml_address - Pointer to the namestring in the AML code * out_name_string - Where the namestring is returned * out_name_length - Length of the returned string * * RETURN: Status, namestring and length * * DESCRIPTION: Extract a full namepath from the AML byte stream, * including any prefixes. * ******************************************************************************/ acpi_status acpi_ex_get_name_string(acpi_object_type data_type, u8 * in_aml_address, char **out_name_string, u32 * out_name_length) { acpi_status status = AE_OK; u8 *aml_address = in_aml_address; char *name_string = NULL; u32 num_segments; u32 prefix_count = 0; u8 has_prefix = FALSE; ACPI_FUNCTION_TRACE_PTR(ex_get_name_string, aml_address); if (ACPI_TYPE_LOCAL_REGION_FIELD == data_type || ACPI_TYPE_LOCAL_BANK_FIELD == data_type || ACPI_TYPE_LOCAL_INDEX_FIELD == data_type) { /* Disallow prefixes for types associated with field_unit names */ name_string = acpi_ex_allocate_name_string(0, 1); if (!name_string) { status = AE_NO_MEMORY; } else { status = acpi_ex_name_segment(&aml_address, name_string); } } else { /* * data_type is not a field name. * Examine first character of name for root or parent prefix operators */ switch (*aml_address) { case AML_ROOT_PREFIX: ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "RootPrefix(\\) at %p\n", aml_address)); /* * Remember that we have a root_prefix -- * see comment in acpi_ex_allocate_name_string() */ aml_address++; prefix_count = ACPI_UINT32_MAX; has_prefix = TRUE; break; case AML_PARENT_PREFIX: /* Increment past possibly multiple parent prefixes */ do { ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "ParentPrefix (^) at %p\n", aml_address)); aml_address++; prefix_count++; } while (*aml_address == AML_PARENT_PREFIX); has_prefix = TRUE; break; default: /* Not a prefix character */ break; } /* Examine first character of name for name segment prefix operator */ switch (*aml_address) { case AML_DUAL_NAME_PREFIX: ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "DualNamePrefix at %p\n", aml_address)); aml_address++; name_string = acpi_ex_allocate_name_string(prefix_count, 2); if (!name_string) { status = AE_NO_MEMORY; break; } /* Indicate that we processed a prefix */ has_prefix = TRUE; status = acpi_ex_name_segment(&aml_address, name_string); if (ACPI_SUCCESS(status)) { status = acpi_ex_name_segment(&aml_address, name_string); } break; case AML_MULTI_NAME_PREFIX: ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "MultiNamePrefix at %p\n", aml_address)); /* Fetch count of segments remaining in name path */ aml_address++; num_segments = *aml_address; name_string = acpi_ex_allocate_name_string(prefix_count, num_segments); if (!name_string) { status = AE_NO_MEMORY; break; } /* Indicate that we processed a prefix */ aml_address++; has_prefix = TRUE; while (num_segments && (status = acpi_ex_name_segment(&aml_address, name_string)) == AE_OK) { num_segments--; } break; case 0: /* null_name valid as of 8-12-98 ASL/AML Grammar Update */ if (prefix_count == ACPI_UINT32_MAX) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "NameSeg is \"\\\" followed by NULL\n")); } /* Consume the NULL byte */ aml_address++; name_string = acpi_ex_allocate_name_string(prefix_count, 0); if (!name_string) { status = AE_NO_MEMORY; break; } break; default: /* Name segment string */ name_string = acpi_ex_allocate_name_string(prefix_count, 1); if (!name_string) { status = AE_NO_MEMORY; break; } status = acpi_ex_name_segment(&aml_address, name_string); break; } } if (AE_CTRL_PENDING == status && has_prefix) { /* Ran out of segments after processing a prefix */ ACPI_ERROR((AE_INFO, "Malformed Name at %p", name_string)); status = AE_AML_BAD_NAME; } if (ACPI_FAILURE(status)) { if (name_string) { ACPI_FREE(name_string); } return_ACPI_STATUS(status); } *out_name_string = name_string; *out_name_length = (u32) (aml_address - in_aml_address); return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exnames.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exstoren - AML Interpreter object store support, * Store to Node (namespace object) * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #include "amlcode.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exstoren") /******************************************************************************* * * FUNCTION: acpi_ex_resolve_object * * PARAMETERS: source_desc_ptr - Pointer to the source object * target_type - Current type of the target * walk_state - Current walk state * * RETURN: Status, resolved object in source_desc_ptr. * * DESCRIPTION: Resolve an object. If the object is a reference, dereference * it and return the actual object in the source_desc_ptr. * ******************************************************************************/ acpi_status acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr, acpi_object_type target_type, struct acpi_walk_state *walk_state) { union acpi_operand_object *source_desc = *source_desc_ptr; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(ex_resolve_object); /* Ensure we have a Target that can be stored to */ switch (target_type) { case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: /* * These cases all require only Integers or values that * can be converted to Integers (Strings or Buffers) */ case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* * Stores into a Field/Region or into a Integer/Buffer/String * are all essentially the same. This case handles the * "interchangeable" types Integer, String, and Buffer. */ if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) { /* Resolve a reference object first */ status = acpi_ex_resolve_to_value(source_desc_ptr, walk_state); if (ACPI_FAILURE(status)) { break; } } /* For copy_object, no further validation necessary */ if (walk_state->opcode == AML_COPY_OBJECT_OP) { break; } /* Must have a Integer, Buffer, or String */ if ((source_desc->common.type != ACPI_TYPE_INTEGER) && (source_desc->common.type != ACPI_TYPE_BUFFER) && (source_desc->common.type != ACPI_TYPE_STRING) && !((source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) && (source_desc->reference.class == ACPI_REFCLASS_TABLE))) { /* Conversion successful but still not a valid type */ ACPI_ERROR((AE_INFO, "Cannot assign type [%s] to [%s] (must be type Int/Str/Buf)", acpi_ut_get_object_type_name(source_desc), acpi_ut_get_type_name(target_type))); status = AE_AML_OPERAND_TYPE; } break; case ACPI_TYPE_LOCAL_ALIAS: case ACPI_TYPE_LOCAL_METHOD_ALIAS: /* * All aliases should have been resolved earlier, during the * operand resolution phase. */ ACPI_ERROR((AE_INFO, "Store into an unresolved Alias object")); status = AE_AML_INTERNAL; break; case ACPI_TYPE_PACKAGE: default: /* * All other types than Alias and the various Fields come here, * including the untyped case - ACPI_TYPE_ANY. */ break; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_store_object_to_object * * PARAMETERS: source_desc - Object to store * dest_desc - Object to receive a copy of the source * new_desc - New object if dest_desc is obsoleted * walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: "Store" an object to another object. This may include * converting the source type to the target type (implicit * conversion), and a copy of the value of the source to * the target. * * The Assignment of an object to another (not named) object * is handled here. * The Source passed in will replace the current value (if any) * with the input value. * * When storing into an object the data is converted to the * target object type then stored in the object. This means * that the target object type (for an initialized target) will * not be changed by a store operation. * * This module allows destination types of Number, String, * Buffer, and Package. * * Assumes parameters are already validated. NOTE: source_desc * resolution (from a reference object) must be performed by * the caller if necessary. * ******************************************************************************/ acpi_status acpi_ex_store_object_to_object(union acpi_operand_object *source_desc, union acpi_operand_object *dest_desc, union acpi_operand_object **new_desc, struct acpi_walk_state *walk_state) { union acpi_operand_object *actual_src_desc; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc); actual_src_desc = source_desc; if (!dest_desc) { /* * There is no destination object (An uninitialized node or * package element), so we can simply copy the source object * creating a new destination object */ status = acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc, walk_state); return_ACPI_STATUS(status); } if (source_desc->common.type != dest_desc->common.type) { /* * The source type does not match the type of the destination. * Perform the "implicit conversion" of the source to the current type * of the target as per the ACPI specification. * * If no conversion performed, actual_src_desc = source_desc. * Otherwise, actual_src_desc is a temporary object to hold the * converted object. */ status = acpi_ex_convert_to_target_type(dest_desc->common.type, source_desc, &actual_src_desc, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (source_desc == actual_src_desc) { /* * No conversion was performed. Return the source_desc as the * new object. */ *new_desc = source_desc; return_ACPI_STATUS(AE_OK); } } /* * We now have two objects of identical types, and we can perform a * copy of the *value* of the source object. */ switch (dest_desc->common.type) { case ACPI_TYPE_INTEGER: dest_desc->integer.value = actual_src_desc->integer.value; /* Truncate value if we are executing from a 32-bit ACPI table */ (void)acpi_ex_truncate_for32bit_table(dest_desc); break; case ACPI_TYPE_STRING: status = acpi_ex_store_string_to_string(actual_src_desc, dest_desc); break; case ACPI_TYPE_BUFFER: status = acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc); break; case ACPI_TYPE_PACKAGE: status = acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc, walk_state); break; default: /* * All other types come here. */ ACPI_WARNING((AE_INFO, "Store into type [%s] not implemented", acpi_ut_get_object_type_name(dest_desc))); status = AE_NOT_IMPLEMENTED; break; } if (actual_src_desc != source_desc) { /* Delete the intermediate (temporary) source object */ acpi_ut_remove_reference(actual_src_desc); } *new_desc = dest_desc; return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exstoren.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: extrace - Support for interpreter execution tracing * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acinterp.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("extrace") static union acpi_operand_object *acpi_gbl_trace_method_object = NULL; /* Local prototypes */ #ifdef ACPI_DEBUG_OUTPUT static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type); #endif /******************************************************************************* * * FUNCTION: acpi_ex_interpreter_trace_enabled * * PARAMETERS: name - Whether method name should be matched, * this should be checked before starting * the tracer * * RETURN: TRUE if interpreter trace is enabled. * * DESCRIPTION: Check whether interpreter trace is enabled * ******************************************************************************/ static u8 acpi_ex_interpreter_trace_enabled(char *name) { /* Check if tracing is enabled */ if (!(acpi_gbl_trace_flags & ACPI_TRACE_ENABLED)) { return (FALSE); } /* * Check if tracing is filtered: * * 1. If the tracer is started, acpi_gbl_trace_method_object should have * been filled by the trace starter * 2. If the tracer is not started, acpi_gbl_trace_method_name should be * matched if it is specified * 3. If the tracer is oneshot style, acpi_gbl_trace_method_name should * not be cleared by the trace stopper during the first match */ if (acpi_gbl_trace_method_object) { return (TRUE); } if (name && (acpi_gbl_trace_method_name && strcmp(acpi_gbl_trace_method_name, name))) { return (FALSE); } if ((acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) && !acpi_gbl_trace_method_name) { return (FALSE); } return (TRUE); } /******************************************************************************* * * FUNCTION: acpi_ex_get_trace_event_name * * PARAMETERS: type - Trace event type * * RETURN: Trace event name. * * DESCRIPTION: Used to obtain the full trace event name. * ******************************************************************************/ #ifdef ACPI_DEBUG_OUTPUT static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type) { switch (type) { case ACPI_TRACE_AML_METHOD: return "Method"; case ACPI_TRACE_AML_OPCODE: return "Opcode"; case ACPI_TRACE_AML_REGION: return "Region"; default: return ""; } } #endif /******************************************************************************* * * FUNCTION: acpi_ex_trace_point * * PARAMETERS: type - Trace event type * begin - TRUE if before execution * aml - Executed AML address * pathname - Object path * * RETURN: None * * DESCRIPTION: Internal interpreter execution trace. * ******************************************************************************/ void acpi_ex_trace_point(acpi_trace_event_type type, u8 begin, u8 *aml, char *pathname) { ACPI_FUNCTION_NAME(ex_trace_point); if (pathname) { ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT, "%s %s [0x%p:%s] execution.\n", acpi_ex_get_trace_event_name(type), begin ? "Begin" : "End", aml, pathname)); } else { ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT, "%s %s [0x%p] execution.\n", acpi_ex_get_trace_event_name(type), begin ? "Begin" : "End", aml)); } } /******************************************************************************* * * FUNCTION: acpi_ex_start_trace_method * * PARAMETERS: method_node - Node of the method * obj_desc - The method object * walk_state - current state, NULL if not yet executing * a method. * * RETURN: None * * DESCRIPTION: Start control method execution trace * ******************************************************************************/ void acpi_ex_start_trace_method(struct acpi_namespace_node *method_node, union acpi_operand_object *obj_desc, struct acpi_walk_state *walk_state) { char *pathname = NULL; u8 enabled = FALSE; ACPI_FUNCTION_NAME(ex_start_trace_method); if (method_node) { pathname = acpi_ns_get_normalized_pathname(method_node, TRUE); } enabled = acpi_ex_interpreter_trace_enabled(pathname); if (enabled && !acpi_gbl_trace_method_object) { acpi_gbl_trace_method_object = obj_desc; acpi_gbl_original_dbg_level = acpi_dbg_level; acpi_gbl_original_dbg_layer = acpi_dbg_layer; acpi_dbg_level = ACPI_TRACE_LEVEL_ALL; acpi_dbg_layer = ACPI_TRACE_LAYER_ALL; if (acpi_gbl_trace_dbg_level) { acpi_dbg_level = acpi_gbl_trace_dbg_level; } if (acpi_gbl_trace_dbg_layer) { acpi_dbg_layer = acpi_gbl_trace_dbg_layer; } } if (enabled) { ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, TRUE, obj_desc ? obj_desc->method.aml_start : NULL, pathname); } if (pathname) { ACPI_FREE(pathname); } } /******************************************************************************* * * FUNCTION: acpi_ex_stop_trace_method * * PARAMETERS: method_node - Node of the method * obj_desc - The method object * walk_state - current state, NULL if not yet executing * a method. * * RETURN: None * * DESCRIPTION: Stop control method execution trace * ******************************************************************************/ void acpi_ex_stop_trace_method(struct acpi_namespace_node *method_node, union acpi_operand_object *obj_desc, struct acpi_walk_state *walk_state) { char *pathname = NULL; u8 enabled; ACPI_FUNCTION_NAME(ex_stop_trace_method); if (method_node) { pathname = acpi_ns_get_normalized_pathname(method_node, TRUE); } enabled = acpi_ex_interpreter_trace_enabled(NULL); if (enabled) { ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, FALSE, obj_desc ? obj_desc->method.aml_start : NULL, pathname); } /* Check whether the tracer should be stopped */ if (acpi_gbl_trace_method_object == obj_desc) { /* Disable further tracing if type is one-shot */ if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) { acpi_gbl_trace_method_name = NULL; } acpi_dbg_level = acpi_gbl_original_dbg_level; acpi_dbg_layer = acpi_gbl_original_dbg_layer; acpi_gbl_trace_method_object = NULL; } if (pathname) { ACPI_FREE(pathname); } } /******************************************************************************* * * FUNCTION: acpi_ex_start_trace_opcode * * PARAMETERS: op - The parser opcode object * walk_state - current state, NULL if not yet executing * a method. * * RETURN: None * * DESCRIPTION: Start opcode execution trace * ******************************************************************************/ void acpi_ex_start_trace_opcode(union acpi_parse_object *op, struct acpi_walk_state *walk_state) { ACPI_FUNCTION_NAME(ex_start_trace_opcode); if (acpi_ex_interpreter_trace_enabled(NULL) && (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) { ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, TRUE, op->common.aml, op->common.aml_op_name); } } /******************************************************************************* * * FUNCTION: acpi_ex_stop_trace_opcode * * PARAMETERS: op - The parser opcode object * walk_state - current state, NULL if not yet executing * a method. * * RETURN: None * * DESCRIPTION: Stop opcode execution trace * ******************************************************************************/ void acpi_ex_stop_trace_opcode(union acpi_parse_object *op, struct acpi_walk_state *walk_state) { ACPI_FUNCTION_NAME(ex_stop_trace_opcode); if (acpi_ex_interpreter_trace_enabled(NULL) && (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) { ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, FALSE, op->common.aml, op->common.aml_op_name); } }
linux-master
drivers/acpi/acpica/extrace.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: psparse - Parser top level AML parse routines * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ /* * Parse the AML and build an operation tree as most interpreters, * like Perl, do. Parsing is done by hand rather than with a YACC * generated parser to tightly constrain stack and dynamic memory * usage. At the same time, parsing is kept flexible and the code * fairly compact by parsing based on a list of AML opcode * templates in aml_op_info[] */ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "acdispat.h" #include "amlcode.h" #include "acinterp.h" #include "acnamesp.h" #define _COMPONENT ACPI_PARSER ACPI_MODULE_NAME("psparse") /******************************************************************************* * * FUNCTION: acpi_ps_get_opcode_size * * PARAMETERS: opcode - An AML opcode * * RETURN: Size of the opcode, in bytes (1 or 2) * * DESCRIPTION: Get the size of the current opcode. * ******************************************************************************/ u32 acpi_ps_get_opcode_size(u32 opcode) { /* Extended (2-byte) opcode if > 255 */ if (opcode > 0x00FF) { return (2); } /* Otherwise, just a single byte opcode */ return (1); } /******************************************************************************* * * FUNCTION: acpi_ps_peek_opcode * * PARAMETERS: parser_state - A parser state object * * RETURN: Next AML opcode * * DESCRIPTION: Get next AML opcode (without incrementing AML pointer) * ******************************************************************************/ u16 acpi_ps_peek_opcode(struct acpi_parse_state * parser_state) { u8 *aml; u16 opcode; aml = parser_state->aml; opcode = (u16) ACPI_GET8(aml); if (opcode == AML_EXTENDED_PREFIX) { /* Extended opcode, get the second opcode byte */ aml++; opcode = (u16) ((opcode << 8) | ACPI_GET8(aml)); } return (opcode); } /******************************************************************************* * * FUNCTION: acpi_ps_complete_this_op * * PARAMETERS: walk_state - Current State * op - Op to complete * * RETURN: Status * * DESCRIPTION: Perform any cleanup at the completion of an Op. * ******************************************************************************/ acpi_status acpi_ps_complete_this_op(struct acpi_walk_state *walk_state, union acpi_parse_object *op) { union acpi_parse_object *prev; union acpi_parse_object *next; const struct acpi_opcode_info *parent_info; union acpi_parse_object *replacement_op = NULL; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE_PTR(ps_complete_this_op, op); /* Check for null Op, can happen if AML code is corrupt */ if (!op) { return_ACPI_STATUS(AE_OK); /* OK for now */ } acpi_ex_stop_trace_opcode(op, walk_state); /* Delete this op and the subtree below it if asked to */ if (((walk_state->parse_flags & ACPI_PARSE_TREE_MASK) != ACPI_PARSE_DELETE_TREE) || (walk_state->op_info->class == AML_CLASS_ARGUMENT)) { return_ACPI_STATUS(AE_OK); } /* Make sure that we only delete this subtree */ if (op->common.parent) { prev = op->common.parent->common.value.arg; if (!prev) { /* Nothing more to do */ goto cleanup; } /* * Check if we need to replace the operator and its subtree * with a return value op (placeholder op) */ parent_info = acpi_ps_get_opcode_info(op->common.parent->common. aml_opcode); switch (parent_info->class) { case AML_CLASS_CONTROL: break; case AML_CLASS_CREATE: /* * These opcodes contain term_arg operands. The current * op must be replaced by a placeholder return op */ replacement_op = acpi_ps_alloc_op(AML_INT_RETURN_VALUE_OP, op->common.aml); if (!replacement_op) { status = AE_NO_MEMORY; } break; case AML_CLASS_NAMED_OBJECT: /* * These opcodes contain term_arg operands. The current * op must be replaced by a placeholder return op */ if ((op->common.parent->common.aml_opcode == AML_REGION_OP) || (op->common.parent->common.aml_opcode == AML_DATA_REGION_OP) || (op->common.parent->common.aml_opcode == AML_BUFFER_OP) || (op->common.parent->common.aml_opcode == AML_PACKAGE_OP) || (op->common.parent->common.aml_opcode == AML_BANK_FIELD_OP) || (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) { replacement_op = acpi_ps_alloc_op(AML_INT_RETURN_VALUE_OP, op->common.aml); if (!replacement_op) { status = AE_NO_MEMORY; } } else if ((op->common.parent->common.aml_opcode == AML_NAME_OP) && (walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2)) { if ((op->common.aml_opcode == AML_BUFFER_OP) || (op->common.aml_opcode == AML_PACKAGE_OP) || (op->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) { replacement_op = acpi_ps_alloc_op(op->common. aml_opcode, op->common.aml); if (!replacement_op) { status = AE_NO_MEMORY; } else { replacement_op->named.data = op->named.data; replacement_op->named.length = op->named.length; } } } break; default: replacement_op = acpi_ps_alloc_op(AML_INT_RETURN_VALUE_OP, op->common.aml); if (!replacement_op) { status = AE_NO_MEMORY; } } /* We must unlink this op from the parent tree */ if (prev == op) { /* This op is the first in the list */ if (replacement_op) { replacement_op->common.parent = op->common.parent; replacement_op->common.value.arg = NULL; replacement_op->common.node = op->common.node; op->common.parent->common.value.arg = replacement_op; replacement_op->common.next = op->common.next; } else { op->common.parent->common.value.arg = op->common.next; } } /* Search the parent list */ else while (prev) { /* Traverse all siblings in the parent's argument list */ next = prev->common.next; if (next == op) { if (replacement_op) { replacement_op->common.parent = op->common.parent; replacement_op->common.value. arg = NULL; replacement_op->common.node = op->common.node; prev->common.next = replacement_op; replacement_op->common.next = op->common.next; next = NULL; } else { prev->common.next = op->common.next; next = NULL; } } prev = next; } } cleanup: /* Now we can actually delete the subtree rooted at Op */ acpi_ps_delete_parse_tree(op); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ps_next_parse_state * * PARAMETERS: walk_state - Current state * op - Current parse op * callback_status - Status from previous operation * * RETURN: Status * * DESCRIPTION: Update the parser state based upon the return exception from * the parser callback. * ******************************************************************************/ acpi_status acpi_ps_next_parse_state(struct acpi_walk_state *walk_state, union acpi_parse_object *op, acpi_status callback_status) { struct acpi_parse_state *parser_state = &walk_state->parser_state; acpi_status status = AE_CTRL_PENDING; ACPI_FUNCTION_TRACE_PTR(ps_next_parse_state, op); switch (callback_status) { case AE_CTRL_TERMINATE: /* * A control method was terminated via a RETURN statement. * The walk of this method is complete. */ parser_state->aml = parser_state->aml_end; status = AE_CTRL_TERMINATE; break; case AE_CTRL_BREAK: parser_state->aml = walk_state->aml_last_while; walk_state->control_state->common.value = FALSE; status = AE_CTRL_BREAK; break; case AE_CTRL_CONTINUE: parser_state->aml = walk_state->aml_last_while; status = AE_CTRL_CONTINUE; break; case AE_CTRL_PENDING: parser_state->aml = walk_state->aml_last_while; break; #if 0 case AE_CTRL_SKIP: parser_state->aml = parser_state->scope->parse_scope.pkg_end; status = AE_OK; break; #endif case AE_CTRL_TRUE: /* * Predicate of an IF was true, and we are at the matching ELSE. * Just close out this package */ parser_state->aml = acpi_ps_get_next_package_end(parser_state); status = AE_CTRL_PENDING; break; case AE_CTRL_FALSE: /* * Either an IF/WHILE Predicate was false or we encountered a BREAK * opcode. In both cases, we do not execute the rest of the * package; We simply close out the parent (finishing the walk of * this branch of the tree) and continue execution at the parent * level. */ parser_state->aml = parser_state->scope->parse_scope.pkg_end; /* In the case of a BREAK, just force a predicate (if any) to FALSE */ walk_state->control_state->common.value = FALSE; status = AE_CTRL_END; break; case AE_CTRL_TRANSFER: /* A method call (invocation) -- transfer control */ status = AE_CTRL_TRANSFER; walk_state->prev_op = op; walk_state->method_call_op = op; walk_state->method_call_node = (op->common.value.arg)->common.node; /* Will return value (if any) be used by the caller? */ walk_state->return_used = acpi_ds_is_result_used(op, walk_state); break; default: status = callback_status; if (ACPI_CNTL_EXCEPTION(callback_status)) { status = AE_OK; } break; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ps_parse_aml * * PARAMETERS: walk_state - Current state * * * RETURN: Status * * DESCRIPTION: Parse raw AML and return a tree of ops * ******************************************************************************/ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state) { acpi_status status; struct acpi_thread_state *thread; struct acpi_thread_state *prev_walk_list = acpi_gbl_current_walk_list; struct acpi_walk_state *previous_walk_state; ACPI_FUNCTION_TRACE(ps_parse_aml); ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Entered with WalkState=%p Aml=%p size=%X\n", walk_state, walk_state->parser_state.aml, walk_state->parser_state.aml_size)); if (!walk_state->parser_state.aml) { return_ACPI_STATUS(AE_BAD_ADDRESS); } /* Create and initialize a new thread state */ thread = acpi_ut_create_thread_state(); if (!thread) { if (walk_state->method_desc) { /* Executing a control method - additional cleanup */ acpi_ds_terminate_control_method(walk_state-> method_desc, walk_state); } acpi_ds_delete_walk_state(walk_state); return_ACPI_STATUS(AE_NO_MEMORY); } walk_state->thread = thread; /* * If executing a method, the starting sync_level is this method's * sync_level */ if (walk_state->method_desc) { walk_state->thread->current_sync_level = walk_state->method_desc->method.sync_level; } acpi_ds_push_walk_state(walk_state, thread); /* * This global allows the AML debugger to get a handle to the currently * executing control method. */ acpi_gbl_current_walk_list = thread; /* * Execute the walk loop as long as there is a valid Walk State. This * handles nested control method invocations without recursion. */ ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "State=%p\n", walk_state)); status = AE_OK; while (walk_state) { if (ACPI_SUCCESS(status)) { /* * The parse_loop executes AML until the method terminates * or calls another method. */ status = acpi_ps_parse_loop(walk_state); } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Completed one call to walk loop, %s State=%p\n", acpi_format_exception(status), walk_state)); if (walk_state->method_pathname && walk_state->method_is_nested) { /* Optional object evaluation log */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_EVALUATION, "%-26s: %*s%s\n", " Exit nested method", (walk_state-> method_nesting_depth + 1) * 3, " ", &walk_state->method_pathname[1])); ACPI_FREE(walk_state->method_pathname); walk_state->method_is_nested = FALSE; } if (status == AE_CTRL_TRANSFER) { /* * A method call was detected. * Transfer control to the called control method */ status = acpi_ds_call_control_method(thread, walk_state, NULL); if (ACPI_FAILURE(status)) { status = acpi_ds_method_error(status, walk_state); } /* * If the transfer to the new method method call worked, * a new walk state was created -- get it */ walk_state = acpi_ds_get_current_walk_state(thread); continue; } else if (status == AE_CTRL_TERMINATE) { status = AE_OK; } else if ((status != AE_OK) && (walk_state->method_desc)) { /* Either the method parse or actual execution failed */ acpi_ex_exit_interpreter(); if (status == AE_ABORT_METHOD) { acpi_ns_print_node_pathname(walk_state-> method_node, "Aborting method"); acpi_os_printf("\n"); } else { ACPI_ERROR_METHOD("Aborting method", walk_state->method_node, NULL, status); } acpi_ex_enter_interpreter(); /* Check for possible multi-thread reentrancy problem */ if ((status == AE_ALREADY_EXISTS) && (!(walk_state->method_desc->method.info_flags & ACPI_METHOD_SERIALIZED))) { /* * Method is not serialized and tried to create an object * twice. The probable cause is that the method cannot * handle reentrancy. Mark as "pending serialized" now, and * then mark "serialized" when the last thread exits. */ walk_state->method_desc->method.info_flags |= ACPI_METHOD_SERIALIZED_PENDING; } } /* We are done with this walk, move on to the parent if any */ walk_state = acpi_ds_pop_walk_state(thread); /* Reset the current scope to the beginning of scope stack */ acpi_ds_scope_stack_clear(walk_state); /* * If we just returned from the execution of a control method or if we * encountered an error during the method parse phase, there's lots of * cleanup to do */ if (((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE && !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) || (ACPI_FAILURE(status))) { acpi_ds_terminate_control_method(walk_state-> method_desc, walk_state); } /* Delete this walk state and all linked control states */ acpi_ps_cleanup_scope(&walk_state->parser_state); previous_walk_state = walk_state; ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "ReturnValue=%p, ImplicitValue=%p State=%p\n", walk_state->return_desc, walk_state->implicit_return_obj, walk_state)); /* Check if we have restarted a preempted walk */ walk_state = acpi_ds_get_current_walk_state(thread); if (walk_state) { if (ACPI_SUCCESS(status)) { /* * There is another walk state, restart it. * If the method return value is not used by the parent, * The object is deleted */ if (!previous_walk_state->return_desc) { /* * In slack mode execution, if there is no return value * we should implicitly return zero (0) as a default value. */ if (acpi_gbl_enable_interpreter_slack && !previous_walk_state-> implicit_return_obj) { previous_walk_state-> implicit_return_obj = acpi_ut_create_integer_object ((u64) 0); if (!previous_walk_state-> implicit_return_obj) { return_ACPI_STATUS (AE_NO_MEMORY); } } /* Restart the calling control method */ status = acpi_ds_restart_control_method (walk_state, previous_walk_state-> implicit_return_obj); } else { /* * We have a valid return value, delete any implicit * return value. */ acpi_ds_clear_implicit_return (previous_walk_state); status = acpi_ds_restart_control_method (walk_state, previous_walk_state->return_desc); } if (ACPI_SUCCESS(status)) { walk_state->walk_type |= ACPI_WALK_METHOD_RESTART; } } else { /* On error, delete any return object or implicit return */ acpi_ut_remove_reference(previous_walk_state-> return_desc); acpi_ds_clear_implicit_return (previous_walk_state); } } /* * Just completed a 1st-level method, save the final internal return * value (if any) */ else if (previous_walk_state->caller_return_desc) { if (previous_walk_state->implicit_return_obj) { *(previous_walk_state->caller_return_desc) = previous_walk_state->implicit_return_obj; } else { /* NULL if no return value */ *(previous_walk_state->caller_return_desc) = previous_walk_state->return_desc; } } else { if (previous_walk_state->return_desc) { /* Caller doesn't want it, must delete it */ acpi_ut_remove_reference(previous_walk_state-> return_desc); } if (previous_walk_state->implicit_return_obj) { /* Caller doesn't want it, must delete it */ acpi_ut_remove_reference(previous_walk_state-> implicit_return_obj); } } acpi_ds_delete_walk_state(previous_walk_state); } /* Normal exit */ acpi_ex_release_all_mutexes(thread); acpi_ut_delete_generic_state(ACPI_CAST_PTR (union acpi_generic_state, thread)); acpi_gbl_current_walk_list = prev_walk_list; return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/psparse.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: dbnames - Debugger commands for the acpi namespace * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acdebug.h" #include "acpredef.h" #include "acinterp.h" #define _COMPONENT ACPI_CA_DEBUGGER ACPI_MODULE_NAME("dbnames") /* Local prototypes */ static acpi_status acpi_db_walk_and_match_name(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_db_walk_for_predefined_names(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_db_walk_for_specific_objects(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_db_walk_for_object_counts(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_db_integrity_walk(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_db_walk_for_references(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); static acpi_status acpi_db_bus_walk(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value); /* * Arguments for the Objects command * These object types map directly to the ACPI_TYPES */ static struct acpi_db_argument_info acpi_db_object_types[] = { {"ANY"}, {"INTEGERS"}, {"STRINGS"}, {"BUFFERS"}, {"PACKAGES"}, {"FIELDS"}, {"DEVICES"}, {"EVENTS"}, {"METHODS"}, {"MUTEXES"}, {"REGIONS"}, {"POWERRESOURCES"}, {"PROCESSORS"}, {"THERMALZONES"}, {"BUFFERFIELDS"}, {"DDBHANDLES"}, {"DEBUG"}, {"REGIONFIELDS"}, {"BANKFIELDS"}, {"INDEXFIELDS"}, {"REFERENCES"}, {"ALIASES"}, {"METHODALIASES"}, {"NOTIFY"}, {"ADDRESSHANDLER"}, {"RESOURCE"}, {"RESOURCEFIELD"}, {"SCOPES"}, {NULL} /* Must be null terminated */ }; /******************************************************************************* * * FUNCTION: acpi_db_set_scope * * PARAMETERS: name - New scope path * * RETURN: Status * * DESCRIPTION: Set the "current scope" as maintained by this utility. * The scope is used as a prefix to ACPI paths. * ******************************************************************************/ void acpi_db_set_scope(char *name) { acpi_status status; struct acpi_namespace_node *node; if (!name || name[0] == 0) { acpi_os_printf("Current scope: %s\n", acpi_gbl_db_scope_buf); return; } acpi_db_prep_namestring(name); if (ACPI_IS_ROOT_PREFIX(name[0])) { /* Validate new scope from the root */ status = acpi_ns_get_node(acpi_gbl_root_node, name, ACPI_NS_NO_UPSEARCH, &node); if (ACPI_FAILURE(status)) { goto error_exit; } acpi_gbl_db_scope_buf[0] = 0; } else { /* Validate new scope relative to old scope */ status = acpi_ns_get_node(acpi_gbl_db_scope_node, name, ACPI_NS_NO_UPSEARCH, &node); if (ACPI_FAILURE(status)) { goto error_exit; } } /* Build the final pathname */ if (acpi_ut_safe_strcat (acpi_gbl_db_scope_buf, sizeof(acpi_gbl_db_scope_buf), name)) { status = AE_BUFFER_OVERFLOW; goto error_exit; } if (acpi_ut_safe_strcat (acpi_gbl_db_scope_buf, sizeof(acpi_gbl_db_scope_buf), "\\")) { status = AE_BUFFER_OVERFLOW; goto error_exit; } acpi_gbl_db_scope_node = node; acpi_os_printf("New scope: %s\n", acpi_gbl_db_scope_buf); return; error_exit: acpi_os_printf("Could not attach scope: %s, %s\n", name, acpi_format_exception(status)); } /******************************************************************************* * * FUNCTION: acpi_db_dump_namespace * * PARAMETERS: start_arg - Node to begin namespace dump * depth_arg - Maximum tree depth to be dumped * * RETURN: None * * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed * with type and other information. * ******************************************************************************/ void acpi_db_dump_namespace(char *start_arg, char *depth_arg) { acpi_handle subtree_entry = acpi_gbl_root_node; u32 max_depth = ACPI_UINT32_MAX; /* No argument given, just start at the root and dump entire namespace */ if (start_arg) { subtree_entry = acpi_db_convert_to_node(start_arg); if (!subtree_entry) { return; } /* Now we can check for the depth argument */ if (depth_arg) { max_depth = strtoul(depth_arg, NULL, 0); } } acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT); if (((struct acpi_namespace_node *)subtree_entry)->parent) { acpi_os_printf("ACPI Namespace (from %4.4s (%p) subtree):\n", ((struct acpi_namespace_node *)subtree_entry)-> name.ascii, subtree_entry); } else { acpi_os_printf("ACPI Namespace (from %s):\n", ACPI_NAMESPACE_ROOT); } /* Display the subtree */ acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT); acpi_ns_dump_objects(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, max_depth, ACPI_OWNER_ID_MAX, subtree_entry); acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT); } /******************************************************************************* * * FUNCTION: acpi_db_dump_namespace_paths * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Dump entire namespace with full object pathnames and object * type information. Alternative to "namespace" command. * ******************************************************************************/ void acpi_db_dump_namespace_paths(void) { acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT); acpi_os_printf("ACPI Namespace (from root):\n"); /* Display the entire namespace */ acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT); acpi_ns_dump_object_paths(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, ACPI_UINT32_MAX, ACPI_OWNER_ID_MAX, acpi_gbl_root_node); acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT); } /******************************************************************************* * * FUNCTION: acpi_db_dump_namespace_by_owner * * PARAMETERS: owner_arg - Owner ID whose nodes will be displayed * depth_arg - Maximum tree depth to be dumped * * RETURN: None * * DESCRIPTION: Dump elements of the namespace that are owned by the owner_id. * ******************************************************************************/ void acpi_db_dump_namespace_by_owner(char *owner_arg, char *depth_arg) { acpi_handle subtree_entry = acpi_gbl_root_node; u32 max_depth = ACPI_UINT32_MAX; acpi_owner_id owner_id; owner_id = (acpi_owner_id)strtoul(owner_arg, NULL, 0); /* Now we can check for the depth argument */ if (depth_arg) { max_depth = strtoul(depth_arg, NULL, 0); } acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT); acpi_os_printf("ACPI Namespace by owner %X:\n", owner_id); /* Display the subtree */ acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT); acpi_ns_dump_objects(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, max_depth, owner_id, subtree_entry); acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT); } /******************************************************************************* * * FUNCTION: acpi_db_walk_and_match_name * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Find a particular name/names within the namespace. Wildcards * are supported -- '?' matches any character. * ******************************************************************************/ static acpi_status acpi_db_walk_and_match_name(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { acpi_status status; char *requested_name = (char *)context; u32 i; struct acpi_buffer buffer; struct acpi_walk_info info; /* Check for a name match */ for (i = 0; i < 4; i++) { /* Wildcard support */ if ((requested_name[i] != '?') && (requested_name[i] != ((struct acpi_namespace_node *) obj_handle)->name.ascii[i])) { /* No match, just exit */ return (AE_OK); } } /* Get the full pathname to this object */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE); if (ACPI_FAILURE(status)) { acpi_os_printf("Could Not get pathname for object %p\n", obj_handle); } else { info.count = 0; info.owner_id = ACPI_OWNER_ID_MAX; info.debug_level = ACPI_UINT32_MAX; info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT; acpi_os_printf("%32s", (char *)buffer.pointer); (void)acpi_ns_dump_one_object(obj_handle, nesting_level, &info, NULL); ACPI_FREE(buffer.pointer); } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_find_name_in_namespace * * PARAMETERS: name_arg - The 4-character ACPI name to find. * wildcards are supported. * * RETURN: None * * DESCRIPTION: Search the namespace for a given name (with wildcards) * ******************************************************************************/ acpi_status acpi_db_find_name_in_namespace(char *name_arg) { char acpi_name[5] = "____"; char *acpi_name_ptr = acpi_name; if (strlen(name_arg) > ACPI_NAMESEG_SIZE) { acpi_os_printf("Name must be no longer than 4 characters\n"); return (AE_OK); } /* Pad out name with underscores as necessary to create a 4-char name */ acpi_ut_strupr(name_arg); while (*name_arg) { *acpi_name_ptr = *name_arg; acpi_name_ptr++; name_arg++; } /* Walk the namespace from the root */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_walk_and_match_name, NULL, acpi_name, NULL); acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_walk_for_predefined_names * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Detect and display predefined ACPI names (names that start with * an underscore) * ******************************************************************************/ static acpi_status acpi_db_walk_for_predefined_names(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; u32 *count = (u32 *)context; const union acpi_predefined_info *predefined; const union acpi_predefined_info *package = NULL; char *pathname; char string_buffer[48]; predefined = acpi_ut_match_predefined_method(node->name.ascii); if (!predefined) { return (AE_OK); } pathname = acpi_ns_get_normalized_pathname(node, TRUE); if (!pathname) { return (AE_OK); } /* If method returns a package, the info is in the next table entry */ if (predefined->info.expected_btypes & ACPI_RTYPE_PACKAGE) { package = predefined + 1; } acpi_ut_get_expected_return_types(string_buffer, predefined->info.expected_btypes); acpi_os_printf("%-32s Arguments %X, Return Types: %s", pathname, METHOD_GET_ARG_COUNT(predefined->info.argument_list), string_buffer); if (package) { acpi_os_printf(" (PkgType %2.2X, ObjType %2.2X, Count %2.2X)", package->ret_info.type, package->ret_info.object_type1, package->ret_info.count1); } acpi_os_printf("\n"); /* Check that the declared argument count matches the ACPI spec */ acpi_ns_check_acpi_compliance(pathname, node, predefined); ACPI_FREE(pathname); (*count)++; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_check_predefined_names * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Validate all predefined names in the namespace * ******************************************************************************/ void acpi_db_check_predefined_names(void) { u32 count = 0; /* Search all nodes in namespace */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_walk_for_predefined_names, NULL, (void *)&count, NULL); acpi_os_printf("Found %u predefined names in the namespace\n", count); } /******************************************************************************* * * FUNCTION: acpi_db_walk_for_object_counts * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Display short info about objects in the namespace * ******************************************************************************/ static acpi_status acpi_db_walk_for_object_counts(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_object_info *info = (struct acpi_object_info *)context; struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; if (node->type > ACPI_TYPE_NS_NODE_MAX) { acpi_os_printf("[%4.4s]: Unknown object type %X\n", node->name.ascii, node->type); } else { info->types[node->type]++; } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_walk_for_fields * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Display short info about objects in the namespace * ******************************************************************************/ static acpi_status acpi_db_walk_for_fields(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { union acpi_object *ret_value; struct acpi_region_walk_info *info = (struct acpi_region_walk_info *)context; struct acpi_buffer buffer; acpi_status status; struct acpi_namespace_node *node = acpi_ns_validate_handle(obj_handle); if (!node) { return (AE_OK); } if (node->object->field.region_obj->region.space_id != info->address_space_id) { return (AE_OK); } info->count++; /* Get and display the full pathname to this object */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE); if (ACPI_FAILURE(status)) { acpi_os_printf("Could Not get pathname for object %p\n", obj_handle); return (AE_OK); } acpi_os_printf("%s ", (char *)buffer.pointer); ACPI_FREE(buffer.pointer); buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; acpi_evaluate_object(obj_handle, NULL, NULL, &buffer); /* * Since this is a field unit, surround the output in braces */ acpi_os_printf("{"); ret_value = (union acpi_object *)buffer.pointer; switch (ret_value->type) { case ACPI_TYPE_INTEGER: acpi_os_printf("%8.8X%8.8X", ACPI_FORMAT_UINT64(ret_value->integer.value)); break; case ACPI_TYPE_BUFFER: acpi_ut_dump_buffer(ret_value->buffer.pointer, ret_value->buffer.length, DB_DISPLAY_DATA_ONLY | DB_BYTE_DISPLAY, 0); break; default: break; } acpi_os_printf("}\n"); ACPI_FREE(buffer.pointer); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_walk_for_specific_objects * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Display short info about objects in the namespace * ******************************************************************************/ static acpi_status acpi_db_walk_for_specific_objects(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_walk_info *info = (struct acpi_walk_info *)context; struct acpi_buffer buffer; acpi_status status; info->count++; /* Get and display the full pathname to this object */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE); if (ACPI_FAILURE(status)) { acpi_os_printf("Could Not get pathname for object %p\n", obj_handle); return (AE_OK); } acpi_os_printf("%32s", (char *)buffer.pointer); ACPI_FREE(buffer.pointer); /* Dump short info about the object */ (void)acpi_ns_dump_one_object(obj_handle, nesting_level, info, NULL); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_display_objects * * PARAMETERS: obj_type_arg - Type of object to display * display_count_arg - Max depth to display * * RETURN: None * * DESCRIPTION: Display objects in the namespace of the requested type * ******************************************************************************/ acpi_status acpi_db_display_objects(char *obj_type_arg, char *display_count_arg) { struct acpi_walk_info info; acpi_object_type type; struct acpi_object_info *object_info; u32 i; u32 total_objects = 0; /* No argument means display summary/count of all object types */ if (!obj_type_arg) { object_info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_object_info)); if (!object_info) return (AE_NO_MEMORY); /* Walk the namespace from the root */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_walk_for_object_counts, NULL, (void *)object_info, NULL); acpi_os_printf("\nSummary of namespace objects:\n\n"); for (i = 0; i < ACPI_TOTAL_TYPES; i++) { acpi_os_printf("%8u %s\n", object_info->types[i], acpi_ut_get_type_name(i)); total_objects += object_info->types[i]; } acpi_os_printf("\n%8u Total namespace objects\n\n", total_objects); ACPI_FREE(object_info); return (AE_OK); } /* Get the object type */ type = acpi_db_match_argument(obj_type_arg, acpi_db_object_types); if (type == ACPI_TYPE_NOT_FOUND) { acpi_os_printf("Invalid or unsupported argument\n"); return (AE_OK); } acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT); acpi_os_printf ("Objects of type [%s] defined in the current ACPI Namespace:\n", acpi_ut_get_type_name(type)); acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT); info.count = 0; info.owner_id = ACPI_OWNER_ID_MAX; info.debug_level = ACPI_UINT32_MAX; info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT; /* Walk the namespace from the root */ (void)acpi_walk_namespace(type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_walk_for_specific_objects, NULL, (void *)&info, NULL); acpi_os_printf ("\nFound %u objects of type [%s] in the current ACPI Namespace\n", info.count, acpi_ut_get_type_name(type)); acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_display_fields * * PARAMETERS: obj_type_arg - Type of object to display * display_count_arg - Max depth to display * * RETURN: None * * DESCRIPTION: Display objects in the namespace of the requested type * ******************************************************************************/ acpi_status acpi_db_display_fields(u32 address_space_id) { struct acpi_region_walk_info info; info.count = 0; info.owner_id = ACPI_OWNER_ID_MAX; info.debug_level = ACPI_UINT32_MAX; info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT; info.address_space_id = address_space_id; /* Walk the namespace from the root */ (void)acpi_walk_namespace(ACPI_TYPE_LOCAL_REGION_FIELD, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_walk_for_fields, NULL, (void *)&info, NULL); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_integrity_walk * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Examine one NS node for valid values. * ******************************************************************************/ static acpi_status acpi_db_integrity_walk(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_integrity_info *info = (struct acpi_integrity_info *)context; struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; union acpi_operand_object *object; u8 alias = TRUE; info->nodes++; /* Verify the NS node, and dereference aliases */ while (alias) { if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) { acpi_os_printf ("Invalid Descriptor Type for Node %p [%s] - " "is %2.2X should be %2.2X\n", node, acpi_ut_get_descriptor_name(node), ACPI_GET_DESCRIPTOR_TYPE(node), ACPI_DESC_TYPE_NAMED); return (AE_OK); } if ((node->type == ACPI_TYPE_LOCAL_ALIAS) || (node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) { node = (struct acpi_namespace_node *)node->object; } else { alias = FALSE; } } if (node->type > ACPI_TYPE_LOCAL_MAX) { acpi_os_printf("Invalid Object Type for Node %p, Type = %X\n", node, node->type); return (AE_OK); } if (!acpi_ut_valid_nameseg(node->name.ascii)) { acpi_os_printf("Invalid AcpiName for Node %p\n", node); return (AE_OK); } object = acpi_ns_get_attached_object(node); if (object) { info->objects++; if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) { acpi_os_printf ("Invalid Descriptor Type for Object %p [%s]\n", object, acpi_ut_get_descriptor_name(object)); } } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_check_integrity * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Check entire namespace for data structure integrity * ******************************************************************************/ void acpi_db_check_integrity(void) { struct acpi_integrity_info info = { 0, 0 }; /* Search all nodes in namespace */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_integrity_walk, NULL, (void *)&info, NULL); acpi_os_printf("Verified %u namespace nodes with %u Objects\n", info.nodes, info.objects); } /******************************************************************************* * * FUNCTION: acpi_db_walk_for_references * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Check if this namespace object refers to the target object * that is passed in as the context value. * * Note: Currently doesn't check subobjects within the Node's object * ******************************************************************************/ static acpi_status acpi_db_walk_for_references(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { union acpi_operand_object *obj_desc = (union acpi_operand_object *)context; struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; /* Check for match against the namespace node itself */ if (node == (void *)obj_desc) { acpi_os_printf("Object is a Node [%4.4s]\n", acpi_ut_get_node_name(node)); } /* Check for match against the object attached to the node */ if (acpi_ns_get_attached_object(node) == obj_desc) { acpi_os_printf("Reference at Node->Object %p [%4.4s]\n", node, acpi_ut_get_node_name(node)); } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_find_references * * PARAMETERS: object_arg - String with hex value of the object * * RETURN: None * * DESCRIPTION: Search namespace for all references to the input object * ******************************************************************************/ void acpi_db_find_references(char *object_arg) { union acpi_operand_object *obj_desc; acpi_size address; /* Convert string to object pointer */ address = strtoul(object_arg, NULL, 16); obj_desc = ACPI_TO_POINTER(address); /* Search all nodes in namespace */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_walk_for_references, NULL, (void *)obj_desc, NULL); } /******************************************************************************* * * FUNCTION: acpi_db_bus_walk * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Display info about device objects that have a corresponding * _PRT method. * ******************************************************************************/ static acpi_status acpi_db_bus_walk(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value) { struct acpi_namespace_node *node = (struct acpi_namespace_node *)obj_handle; acpi_status status; struct acpi_buffer buffer; struct acpi_namespace_node *temp_node; struct acpi_device_info *info; u32 i; if ((node->type != ACPI_TYPE_DEVICE) && (node->type != ACPI_TYPE_PROCESSOR)) { return (AE_OK); } /* Exit if there is no _PRT under this device */ status = acpi_get_handle(node, METHOD_NAME__PRT, ACPI_CAST_PTR(acpi_handle, &temp_node)); if (ACPI_FAILURE(status)) { return (AE_OK); } /* Get the full path to this device object */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE); if (ACPI_FAILURE(status)) { acpi_os_printf("Could Not get pathname for object %p\n", obj_handle); return (AE_OK); } status = acpi_get_object_info(obj_handle, &info); if (ACPI_FAILURE(status)) { return (AE_OK); } /* Display the full path */ acpi_os_printf("%-32s Type %X", (char *)buffer.pointer, node->type); ACPI_FREE(buffer.pointer); if (info->flags & ACPI_PCI_ROOT_BRIDGE) { acpi_os_printf(" - Is PCI Root Bridge"); } acpi_os_printf("\n"); /* _PRT info */ acpi_os_printf("_PRT: %p\n", temp_node); /* Dump _ADR, _HID, _UID, _CID */ if (info->valid & ACPI_VALID_ADR) { acpi_os_printf("_ADR: %8.8X%8.8X\n", ACPI_FORMAT_UINT64(info->address)); } else { acpi_os_printf("_ADR: <Not Present>\n"); } if (info->valid & ACPI_VALID_HID) { acpi_os_printf("_HID: %s\n", info->hardware_id.string); } else { acpi_os_printf("_HID: <Not Present>\n"); } if (info->valid & ACPI_VALID_UID) { acpi_os_printf("_UID: %s\n", info->unique_id.string); } else { acpi_os_printf("_UID: <Not Present>\n"); } if (info->valid & ACPI_VALID_CID) { for (i = 0; i < info->compatible_id_list.count; i++) { acpi_os_printf("_CID: %s\n", info->compatible_id_list.ids[i].string); } } else { acpi_os_printf("_CID: <Not Present>\n"); } ACPI_FREE(info); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_db_get_bus_info * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Display info about system buses. * ******************************************************************************/ void acpi_db_get_bus_info(void) { /* Search all nodes in namespace */ (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_db_bus_walk, NULL, NULL, NULL); }
linux-master
drivers/acpi/acpica/dbnames.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: exoparg2 - AML execution - opcodes with 2 arguments * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "acinterp.h" #include "acevents.h" #include "amlcode.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME("exoparg2") /*! * Naming convention for AML interpreter execution routines. * * The routines that begin execution of AML opcodes are named with a common * convention based upon the number of arguments, the number of target operands, * and whether or not a value is returned: * * AcpiExOpcode_xA_yT_zR * * Where: * * xA - ARGUMENTS: The number of arguments (input operands) that are * required for this opcode type (1 through 6 args). * yT - TARGETS: The number of targets (output operands) that are required * for this opcode type (0, 1, or 2 targets). * zR - RETURN VALUE: Indicates whether this opcode type returns a value * as the function return (0 or 1). * * The AcpiExOpcode* functions are called via the Dispatcher component with * fully resolved operands. !*/ /******************************************************************************* * * FUNCTION: acpi_ex_opcode_2A_0T_0R * * PARAMETERS: walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Execute opcode with two arguments, no target, and no return * value. * * ALLOCATION: Deletes both operands * ******************************************************************************/ acpi_status acpi_ex_opcode_2A_0T_0R(struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; struct acpi_namespace_node *node; u32 value; acpi_status status = AE_OK; ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_0T_0R, acpi_ps_get_opcode_name(walk_state->opcode)); /* Examine the opcode */ switch (walk_state->opcode) { case AML_NOTIFY_OP: /* Notify (notify_object, notify_value) */ /* The first operand is a namespace node */ node = (struct acpi_namespace_node *)operand[0]; /* Second value is the notify value */ value = (u32) operand[1]->integer.value; /* Are notifies allowed on this object? */ if (!acpi_ev_is_notify_object(node)) { ACPI_ERROR((AE_INFO, "Unexpected notify object type [%s]", acpi_ut_get_type_name(node->type))); status = AE_AML_OPERAND_TYPE; break; } /* * Dispatch the notify to the appropriate handler * NOTE: the request is queued for execution after this method * completes. The notify handlers are NOT invoked synchronously * from this thread -- because handlers may in turn run other * control methods. */ status = acpi_ev_queue_notify_request(node, value); break; default: ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", walk_state->opcode)); status = AE_AML_BAD_OPCODE; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_opcode_2A_2T_1R * * PARAMETERS: walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets * and one implicit return value. * ******************************************************************************/ acpi_status acpi_ex_opcode_2A_2T_1R(struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; union acpi_operand_object *return_desc1 = NULL; union acpi_operand_object *return_desc2 = NULL; acpi_status status; ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_2T_1R, acpi_ps_get_opcode_name(walk_state->opcode)); /* Execute the opcode */ switch (walk_state->opcode) { case AML_DIVIDE_OP: /* Divide (Dividend, Divisor, remainder_result quotient_result) */ return_desc1 = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); if (!return_desc1) { status = AE_NO_MEMORY; goto cleanup; } return_desc2 = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); if (!return_desc2) { status = AE_NO_MEMORY; goto cleanup; } /* Quotient to return_desc1, remainder to return_desc2 */ status = acpi_ut_divide(operand[0]->integer.value, operand[1]->integer.value, &return_desc1->integer.value, &return_desc2->integer.value); if (ACPI_FAILURE(status)) { goto cleanup; } break; default: ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", walk_state->opcode)); status = AE_AML_BAD_OPCODE; goto cleanup; } /* Store the results to the target reference operands */ status = acpi_ex_store(return_desc2, operand[2], walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } status = acpi_ex_store(return_desc1, operand[3], walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } cleanup: /* * Since the remainder is not returned indirectly, remove a reference to * it. Only the quotient is returned indirectly. */ acpi_ut_remove_reference(return_desc2); if (ACPI_FAILURE(status)) { /* Delete the return object */ acpi_ut_remove_reference(return_desc1); } /* Save return object (the remainder) on success */ else { walk_state->result_obj = return_desc1; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_opcode_2A_1T_1R * * PARAMETERS: walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Execute opcode with two arguments, one target, and a return * value. * ******************************************************************************/ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; union acpi_operand_object *return_desc = NULL; u64 index; acpi_status status = AE_OK; acpi_size length = 0; ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_1T_1R, acpi_ps_get_opcode_name(walk_state->opcode)); /* Execute the opcode */ if (walk_state->op_info->flags & AML_MATH) { /* All simple math opcodes (add, etc.) */ return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } return_desc->integer.value = acpi_ex_do_math_op(walk_state->opcode, operand[0]->integer.value, operand[1]->integer.value); goto store_result_to_target; } switch (walk_state->opcode) { case AML_MOD_OP: /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */ return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } /* return_desc will contain the remainder */ status = acpi_ut_divide(operand[0]->integer.value, operand[1]->integer.value, NULL, &return_desc->integer.value); break; case AML_CONCATENATE_OP: /* Concatenate (Data1, Data2, Result) */ status = acpi_ex_do_concatenate(operand[0], operand[1], &return_desc, walk_state); break; case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */ /* * Input object is guaranteed to be a buffer at this point (it may have * been converted.) Copy the raw buffer data to a new object of * type String. */ /* * Get the length of the new string. It is the smallest of: * 1) Length of the input buffer * 2) Max length as specified in the to_string operator * 3) Length of input buffer up to a zero byte (null terminator) * * NOTE: A length of zero is ok, and will create a zero-length, null * terminated string. */ while ((length < operand[0]->buffer.length) && /* Length of input buffer */ (length < operand[1]->integer.value) && /* Length operand */ (operand[0]->buffer.pointer[length])) { /* Null terminator */ length++; } /* Allocate a new string object */ return_desc = acpi_ut_create_string_object(length); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } /* * Copy the raw buffer data with no transform. * (NULL terminated already) */ memcpy(return_desc->string.pointer, operand[0]->buffer.pointer, length); break; case AML_CONCATENATE_TEMPLATE_OP: /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */ status = acpi_ex_concat_template(operand[0], operand[1], &return_desc, walk_state); break; case AML_INDEX_OP: /* Index (Source Index Result) */ /* Create the internal return object */ return_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } /* Initialize the Index reference object */ index = operand[1]->integer.value; return_desc->reference.value = (u32) index; return_desc->reference.class = ACPI_REFCLASS_INDEX; /* * At this point, the Source operand is a String, Buffer, or Package. * Verify that the index is within range. */ switch ((operand[0])->common.type) { case ACPI_TYPE_STRING: if (index >= operand[0]->string.length) { length = operand[0]->string.length; status = AE_AML_STRING_LIMIT; } return_desc->reference.target_type = ACPI_TYPE_BUFFER_FIELD; return_desc->reference.index_pointer = &(operand[0]->buffer.pointer[index]); break; case ACPI_TYPE_BUFFER: if (index >= operand[0]->buffer.length) { length = operand[0]->buffer.length; status = AE_AML_BUFFER_LIMIT; } return_desc->reference.target_type = ACPI_TYPE_BUFFER_FIELD; return_desc->reference.index_pointer = &(operand[0]->buffer.pointer[index]); break; case ACPI_TYPE_PACKAGE: if (index >= operand[0]->package.count) { length = operand[0]->package.count; status = AE_AML_PACKAGE_LIMIT; } return_desc->reference.target_type = ACPI_TYPE_PACKAGE; return_desc->reference.where = &operand[0]->package.elements[index]; break; default: ACPI_ERROR((AE_INFO, "Invalid object type: %X", (operand[0])->common.type)); status = AE_AML_INTERNAL; goto cleanup; } /* Failure means that the Index was beyond the end of the object */ if (ACPI_FAILURE(status)) { ACPI_BIOS_EXCEPTION((AE_INFO, status, "Index (0x%X%8.8X) is beyond end of object (length 0x%X)", ACPI_FORMAT_UINT64(index), (u32)length)); goto cleanup; } /* * Save the target object and add a reference to it for the life * of the index */ return_desc->reference.object = operand[0]; acpi_ut_add_reference(operand[0]); /* Store the reference to the Target */ status = acpi_ex_store(return_desc, operand[2], walk_state); /* Return the reference */ walk_state->result_obj = return_desc; goto cleanup; default: ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", walk_state->opcode)); status = AE_AML_BAD_OPCODE; break; } store_result_to_target: if (ACPI_SUCCESS(status)) { /* * Store the result of the operation (which is now in return_desc) into * the Target descriptor. */ status = acpi_ex_store(return_desc, operand[2], walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } if (!walk_state->result_obj) { walk_state->result_obj = return_desc; } } cleanup: /* Delete return object on error */ if (ACPI_FAILURE(status)) { acpi_ut_remove_reference(return_desc); walk_state->result_obj = NULL; } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ex_opcode_2A_0T_1R * * PARAMETERS: walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value * ******************************************************************************/ acpi_status acpi_ex_opcode_2A_0T_1R(struct acpi_walk_state *walk_state) { union acpi_operand_object **operand = &walk_state->operands[0]; union acpi_operand_object *return_desc = NULL; acpi_status status = AE_OK; u8 logical_result = FALSE; ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_0T_1R, acpi_ps_get_opcode_name(walk_state->opcode)); /* Create the internal return object */ return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } /* Execute the Opcode */ if (walk_state->op_info->flags & AML_LOGICAL_NUMERIC) { /* logical_op (Operand0, Operand1) */ status = acpi_ex_do_logical_numeric_op(walk_state->opcode, operand[0]->integer. value, operand[1]->integer. value, &logical_result); goto store_logical_result; } else if (walk_state->op_info->flags & AML_LOGICAL) { /* logical_op (Operand0, Operand1) */ status = acpi_ex_do_logical_op(walk_state->opcode, operand[0], operand[1], &logical_result); goto store_logical_result; } switch (walk_state->opcode) { case AML_ACQUIRE_OP: /* Acquire (mutex_object, Timeout) */ status = acpi_ex_acquire_mutex(operand[1], operand[0], walk_state); if (status == AE_TIME) { logical_result = TRUE; /* TRUE = Acquire timed out */ status = AE_OK; } break; case AML_WAIT_OP: /* Wait (event_object, Timeout) */ status = acpi_ex_system_wait_event(operand[1], operand[0]); if (status == AE_TIME) { logical_result = TRUE; /* TRUE, Wait timed out */ status = AE_OK; } break; default: ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", walk_state->opcode)); status = AE_AML_BAD_OPCODE; goto cleanup; } store_logical_result: /* * Set return value to according to logical_result. logical TRUE (all ones) * Default is FALSE (zero) */ if (logical_result) { return_desc->integer.value = ACPI_UINT64_MAX; } cleanup: /* Delete return object on error */ if (ACPI_FAILURE(status)) { acpi_ut_remove_reference(return_desc); } /* Save return object on success */ else { walk_state->result_obj = return_desc; } return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/exoparg2.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utcksum - Support generating table checksums * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acutils.h" /* This module used for application-level code only */ #define _COMPONENT ACPI_CA_DISASSEMBLER ACPI_MODULE_NAME("utcksum") /******************************************************************************* * * FUNCTION: acpi_ut_verify_checksum * * PARAMETERS: table - ACPI table to verify * length - Length of entire table * * RETURN: Status * * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns * exception on bad checksum. * Note: We don't have to check for a CDAT here, since CDAT is * not in the RSDT/XSDT, and the CDAT table is never installed * via ACPICA. * ******************************************************************************/ acpi_status acpi_ut_verify_checksum(struct acpi_table_header *table, u32 length) { u8 checksum; /* * FACS/S3PT: * They are the odd tables, have no standard ACPI header and no checksum */ if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_S3PT) || ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_FACS)) { return (AE_OK); } /* Compute the checksum on the table */ length = table->length; checksum = acpi_ut_generate_checksum(ACPI_CAST_PTR(u8, table), length, table->checksum); /* Computed checksum matches table? */ if (checksum != table->checksum) { ACPI_BIOS_WARNING((AE_INFO, "Incorrect checksum in table [%4.4s] - 0x%2.2X, " "should be 0x%2.2X", table->signature, table->checksum, table->checksum - checksum)); #if (ACPI_CHECKSUM_ABORT) return (AE_BAD_CHECKSUM); #endif } return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ut_verify_cdat_checksum * * PARAMETERS: table - CDAT ACPI table to verify * length - Length of entire table * * RETURN: Status * * DESCRIPTION: Verifies that the CDAT table checksums to zero. Optionally * returns an exception on bad checksum. * ******************************************************************************/ acpi_status acpi_ut_verify_cdat_checksum(struct acpi_table_cdat *cdat_table, u32 length) { u8 checksum; /* Compute the checksum on the table */ checksum = acpi_ut_generate_checksum(ACPI_CAST_PTR(u8, cdat_table), cdat_table->length, cdat_table->checksum); /* Computed checksum matches table? */ if (checksum != cdat_table->checksum) { ACPI_BIOS_WARNING((AE_INFO, "Incorrect checksum in table [%4.4s] - 0x%2.2X, " "should be 0x%2.2X", acpi_gbl_CDAT, cdat_table->checksum, checksum)); #if (ACPI_CHECKSUM_ABORT) return (AE_BAD_CHECKSUM); #endif } cdat_table->checksum = checksum; return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ut_generate_checksum * * PARAMETERS: table - Pointer to table to be checksummed * length - Length of the table * original_checksum - Value of the checksum field * * RETURN: 8 bit checksum of buffer * * DESCRIPTION: Computes an 8 bit checksum of the table. * ******************************************************************************/ u8 acpi_ut_generate_checksum(void *table, u32 length, u8 original_checksum) { u8 checksum; /* Sum the entire table as-is */ checksum = acpi_ut_checksum((u8 *)table, length); /* Subtract off the existing checksum value in the table */ checksum = (u8)(checksum - original_checksum); /* Compute and return the final checksum */ checksum = (u8)(0 - checksum); return (checksum); } /******************************************************************************* * * FUNCTION: acpi_ut_checksum * * PARAMETERS: buffer - Pointer to memory region to be checked * length - Length of this memory region * * RETURN: Checksum (u8) * * DESCRIPTION: Calculates circular checksum of memory region. * ******************************************************************************/ u8 acpi_ut_checksum(u8 *buffer, u32 length) { u8 sum = 0; u8 *end = buffer + length; while (buffer < end) { sum = (u8)(sum + *(buffer++)); } return (sum); }
linux-master
drivers/acpi/acpica/utcksum.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: hwgpe - Low level GPE enable/disable/clear functions * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #define _COMPONENT ACPI_HARDWARE ACPI_MODULE_NAME("hwgpe") #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ /* Local prototypes */ static acpi_status acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, struct acpi_gpe_block_info *gpe_block, void *context); static acpi_status acpi_hw_gpe_enable_write(u8 enable_mask, struct acpi_gpe_register_info *gpe_register_info); /****************************************************************************** * * FUNCTION: acpi_hw_gpe_read * * PARAMETERS: value - Where the value is returned * reg - GPE register structure * * RETURN: Status * * DESCRIPTION: Read from a GPE register in either memory or IO space. * * LIMITATIONS: <These limitations also apply to acpi_hw_gpe_write> * space_ID must be system_memory or system_IO. * ******************************************************************************/ acpi_status acpi_hw_gpe_read(u64 *value, struct acpi_gpe_address *reg) { acpi_status status; u32 value32; if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { #ifdef ACPI_GPE_USE_LOGICAL_ADDRESSES *value = (u64)ACPI_GET8((unsigned long)reg->address); return_ACPI_STATUS(AE_OK); #else return acpi_os_read_memory((acpi_physical_address)reg->address, value, ACPI_GPE_REGISTER_WIDTH); #endif } status = acpi_os_read_port((acpi_io_address)reg->address, &value32, ACPI_GPE_REGISTER_WIDTH); if (ACPI_FAILURE(status)) return_ACPI_STATUS(status); *value = (u64)value32; return_ACPI_STATUS(AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_gpe_write * * PARAMETERS: value - Value to be written * reg - GPE register structure * * RETURN: Status * * DESCRIPTION: Write to a GPE register in either memory or IO space. * ******************************************************************************/ acpi_status acpi_hw_gpe_write(u64 value, struct acpi_gpe_address *reg) { if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { #ifdef ACPI_GPE_USE_LOGICAL_ADDRESSES ACPI_SET8((unsigned long)reg->address, value); return_ACPI_STATUS(AE_OK); #else return acpi_os_write_memory((acpi_physical_address)reg->address, value, ACPI_GPE_REGISTER_WIDTH); #endif } return acpi_os_write_port((acpi_io_address)reg->address, (u32)value, ACPI_GPE_REGISTER_WIDTH); } /****************************************************************************** * * FUNCTION: acpi_hw_get_gpe_register_bit * * PARAMETERS: gpe_event_info - Info block for the GPE * * RETURN: Register mask with a one in the GPE bit position * * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the * correct position for the input GPE. * ******************************************************************************/ u32 acpi_hw_get_gpe_register_bit(struct acpi_gpe_event_info *gpe_event_info) { return ((u32)1 << (gpe_event_info->gpe_number - gpe_event_info->register_info->base_gpe_number)); } /****************************************************************************** * * FUNCTION: acpi_hw_low_set_gpe * * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled * action - Enable or disable * * RETURN: Status * * DESCRIPTION: Enable or disable a single GPE in the parent enable register. * The enable_mask field of the involved GPE register must be * updated by the caller if necessary. * ******************************************************************************/ acpi_status acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action) { struct acpi_gpe_register_info *gpe_register_info; acpi_status status = AE_OK; u64 enable_mask; u32 register_bit; ACPI_FUNCTION_ENTRY(); /* Get the info block for the entire GPE register */ gpe_register_info = gpe_event_info->register_info; if (!gpe_register_info) { return (AE_NOT_EXIST); } /* Get current value of the enable register that contains this GPE */ status = acpi_hw_gpe_read(&enable_mask, &gpe_register_info->enable_address); if (ACPI_FAILURE(status)) { return (status); } /* Set or clear just the bit that corresponds to this GPE */ register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); switch (action) { case ACPI_GPE_CONDITIONAL_ENABLE: /* Only enable if the corresponding enable_mask bit is set */ if (!(register_bit & gpe_register_info->enable_mask)) { return (AE_BAD_PARAMETER); } ACPI_FALLTHROUGH; case ACPI_GPE_ENABLE: ACPI_SET_BIT(enable_mask, register_bit); break; case ACPI_GPE_DISABLE: ACPI_CLEAR_BIT(enable_mask, register_bit); break; default: ACPI_ERROR((AE_INFO, "Invalid GPE Action, %u", action)); return (AE_BAD_PARAMETER); } if (!(register_bit & gpe_register_info->mask_for_run)) { /* Write the updated enable mask */ status = acpi_hw_gpe_write(enable_mask, &gpe_register_info->enable_address); } return (status); } /****************************************************************************** * * FUNCTION: acpi_hw_clear_gpe * * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared * * RETURN: Status * * DESCRIPTION: Clear the status bit for a single GPE. * ******************************************************************************/ acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info *gpe_event_info) { struct acpi_gpe_register_info *gpe_register_info; acpi_status status; u32 register_bit; ACPI_FUNCTION_ENTRY(); /* Get the info block for the entire GPE register */ gpe_register_info = gpe_event_info->register_info; if (!gpe_register_info) { return (AE_NOT_EXIST); } /* * Write a one to the appropriate bit in the status register to * clear this GPE. */ register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); status = acpi_hw_gpe_write(register_bit, &gpe_register_info->status_address); return (status); } /****************************************************************************** * * FUNCTION: acpi_hw_get_gpe_status * * PARAMETERS: gpe_event_info - Info block for the GPE to queried * event_status - Where the GPE status is returned * * RETURN: Status * * DESCRIPTION: Return the status of a single GPE. * ******************************************************************************/ acpi_status acpi_hw_get_gpe_status(struct acpi_gpe_event_info *gpe_event_info, acpi_event_status *event_status) { u64 in_byte; u32 register_bit; struct acpi_gpe_register_info *gpe_register_info; acpi_event_status local_event_status = 0; acpi_status status; ACPI_FUNCTION_ENTRY(); if (!event_status) { return (AE_BAD_PARAMETER); } /* GPE currently handled? */ if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) != ACPI_GPE_DISPATCH_NONE) { local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER; } /* Get the info block for the entire GPE register */ gpe_register_info = gpe_event_info->register_info; /* Get the register bitmask for this GPE */ register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); /* GPE currently enabled? (enabled for runtime?) */ if (register_bit & gpe_register_info->enable_for_run) { local_event_status |= ACPI_EVENT_FLAG_ENABLED; } /* GPE currently masked? (masked for runtime?) */ if (register_bit & gpe_register_info->mask_for_run) { local_event_status |= ACPI_EVENT_FLAG_MASKED; } /* GPE enabled for wake? */ if (register_bit & gpe_register_info->enable_for_wake) { local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED; } /* GPE currently enabled (enable bit == 1)? */ status = acpi_hw_gpe_read(&in_byte, &gpe_register_info->enable_address); if (ACPI_FAILURE(status)) { return (status); } if (register_bit & in_byte) { local_event_status |= ACPI_EVENT_FLAG_ENABLE_SET; } /* GPE currently active (status bit == 1)? */ status = acpi_hw_gpe_read(&in_byte, &gpe_register_info->status_address); if (ACPI_FAILURE(status)) { return (status); } if (register_bit & in_byte) { local_event_status |= ACPI_EVENT_FLAG_STATUS_SET; } /* Set return value */ (*event_status) = local_event_status; return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_gpe_enable_write * * PARAMETERS: enable_mask - Bit mask to write to the GPE register * gpe_register_info - Gpe Register info * * RETURN: Status * * DESCRIPTION: Write the enable mask byte to the given GPE register. * ******************************************************************************/ static acpi_status acpi_hw_gpe_enable_write(u8 enable_mask, struct acpi_gpe_register_info *gpe_register_info) { acpi_status status; gpe_register_info->enable_mask = enable_mask; status = acpi_hw_gpe_write(enable_mask, &gpe_register_info->enable_address); return (status); } /****************************************************************************** * * FUNCTION: acpi_hw_disable_gpe_block * * PARAMETERS: gpe_xrupt_info - GPE Interrupt info * gpe_block - Gpe Block info * * RETURN: Status * * DESCRIPTION: Disable all GPEs within a single GPE block * ******************************************************************************/ acpi_status acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, struct acpi_gpe_block_info *gpe_block, void *context) { u32 i; acpi_status status; /* Examine each GPE Register within the block */ for (i = 0; i < gpe_block->register_count; i++) { /* Disable all GPEs in this register */ status = acpi_hw_gpe_enable_write(0x00, &gpe_block->register_info[i]); if (ACPI_FAILURE(status)) { return (status); } } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_clear_gpe_block * * PARAMETERS: gpe_xrupt_info - GPE Interrupt info * gpe_block - Gpe Block info * * RETURN: Status * * DESCRIPTION: Clear status bits for all GPEs within a single GPE block * ******************************************************************************/ acpi_status acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, struct acpi_gpe_block_info *gpe_block, void *context) { u32 i; acpi_status status; /* Examine each GPE Register within the block */ for (i = 0; i < gpe_block->register_count; i++) { /* Clear status on all GPEs in this register */ status = acpi_hw_gpe_write(0xFF, &gpe_block->register_info[i].status_address); if (ACPI_FAILURE(status)) { return (status); } } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_enable_runtime_gpe_block * * PARAMETERS: gpe_xrupt_info - GPE Interrupt info * gpe_block - Gpe Block info * * RETURN: Status * * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes * combination wake/run GPEs. * ******************************************************************************/ acpi_status acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, struct acpi_gpe_block_info *gpe_block, void *context) { u32 i; acpi_status status; struct acpi_gpe_register_info *gpe_register_info; u8 enable_mask; /* NOTE: assumes that all GPEs are currently disabled */ /* Examine each GPE Register within the block */ for (i = 0; i < gpe_block->register_count; i++) { gpe_register_info = &gpe_block->register_info[i]; if (!gpe_register_info->enable_for_run) { continue; } /* Enable all "runtime" GPEs in this register */ enable_mask = gpe_register_info->enable_for_run & ~gpe_register_info->mask_for_run; status = acpi_hw_gpe_enable_write(enable_mask, gpe_register_info); if (ACPI_FAILURE(status)) { return (status); } } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_enable_wakeup_gpe_block * * PARAMETERS: gpe_xrupt_info - GPE Interrupt info * gpe_block - Gpe Block info * * RETURN: Status * * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes * combination wake/run GPEs. * ******************************************************************************/ static acpi_status acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, struct acpi_gpe_block_info *gpe_block, void *context) { u32 i; acpi_status status; struct acpi_gpe_register_info *gpe_register_info; /* Examine each GPE Register within the block */ for (i = 0; i < gpe_block->register_count; i++) { gpe_register_info = &gpe_block->register_info[i]; /* * Enable all "wake" GPEs in this register and disable the * remaining ones. */ status = acpi_hw_gpe_enable_write(gpe_register_info->enable_for_wake, gpe_register_info); if (ACPI_FAILURE(status)) { return (status); } } return (AE_OK); } struct acpi_gpe_block_status_context { struct acpi_gpe_register_info *gpe_skip_register_info; u8 gpe_skip_mask; u8 retval; }; /****************************************************************************** * * FUNCTION: acpi_hw_get_gpe_block_status * * PARAMETERS: gpe_xrupt_info - GPE Interrupt info * gpe_block - Gpe Block info * context - GPE list walk context data * * RETURN: Success * * DESCRIPTION: Produce a combined GPE status bits mask for the given block. * ******************************************************************************/ static acpi_status acpi_hw_get_gpe_block_status(struct acpi_gpe_xrupt_info *gpe_xrupt_info, struct acpi_gpe_block_info *gpe_block, void *context) { struct acpi_gpe_block_status_context *c = context; struct acpi_gpe_register_info *gpe_register_info; u64 in_enable, in_status; acpi_status status; u8 ret_mask; u32 i; /* Examine each GPE Register within the block */ for (i = 0; i < gpe_block->register_count; i++) { gpe_register_info = &gpe_block->register_info[i]; status = acpi_hw_gpe_read(&in_enable, &gpe_register_info->enable_address); if (ACPI_FAILURE(status)) { continue; } status = acpi_hw_gpe_read(&in_status, &gpe_register_info->status_address); if (ACPI_FAILURE(status)) { continue; } ret_mask = in_enable & in_status; if (ret_mask && c->gpe_skip_register_info == gpe_register_info) { ret_mask &= ~c->gpe_skip_mask; } c->retval |= ret_mask; } return (AE_OK); } /****************************************************************************** * * FUNCTION: acpi_hw_disable_all_gpes * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Disable and clear all GPEs in all GPE blocks * ******************************************************************************/ acpi_status acpi_hw_disable_all_gpes(void) { acpi_status status; ACPI_FUNCTION_TRACE(hw_disable_all_gpes); status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL); return_ACPI_STATUS(status); } /****************************************************************************** * * FUNCTION: acpi_hw_enable_all_runtime_gpes * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks * ******************************************************************************/ acpi_status acpi_hw_enable_all_runtime_gpes(void) { acpi_status status; ACPI_FUNCTION_TRACE(hw_enable_all_runtime_gpes); status = acpi_ev_walk_gpe_list(acpi_hw_enable_runtime_gpe_block, NULL); return_ACPI_STATUS(status); } /****************************************************************************** * * FUNCTION: acpi_hw_enable_all_wakeup_gpes * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks * ******************************************************************************/ acpi_status acpi_hw_enable_all_wakeup_gpes(void) { acpi_status status; ACPI_FUNCTION_TRACE(hw_enable_all_wakeup_gpes); status = acpi_ev_walk_gpe_list(acpi_hw_enable_wakeup_gpe_block, NULL); return_ACPI_STATUS(status); } /****************************************************************************** * * FUNCTION: acpi_hw_check_all_gpes * * PARAMETERS: gpe_skip_device - GPE devoce of the GPE to skip * gpe_skip_number - Number of the GPE to skip * * RETURN: Combined status of all GPEs * * DESCRIPTION: Check all enabled GPEs in all GPE blocks, except for the one * represented by the "skip" arguments, and return TRUE if the * status bit is set for at least one of them of FALSE otherwise. * ******************************************************************************/ u8 acpi_hw_check_all_gpes(acpi_handle gpe_skip_device, u32 gpe_skip_number) { struct acpi_gpe_block_status_context context = { .gpe_skip_register_info = NULL, .retval = 0, }; struct acpi_gpe_event_info *gpe_event_info; acpi_cpu_flags flags; ACPI_FUNCTION_TRACE(acpi_hw_check_all_gpes); flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); gpe_event_info = acpi_ev_get_gpe_event_info(gpe_skip_device, gpe_skip_number); if (gpe_event_info) { context.gpe_skip_register_info = gpe_event_info->register_info; context.gpe_skip_mask = acpi_hw_get_gpe_register_bit(gpe_event_info); } acpi_os_release_lock(acpi_gbl_gpe_lock, flags); (void)acpi_ev_walk_gpe_list(acpi_hw_get_gpe_block_status, &context); return (context.retval != 0); } #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/hwgpe.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: evxface - External interfaces for ACPI events * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acevents.h" #include "acinterp.h" #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evxface") #if (!ACPI_REDUCED_HARDWARE) /* Local prototypes */ static acpi_status acpi_ev_install_gpe_handler(acpi_handle gpe_device, u32 gpe_number, u32 type, u8 is_raw_handler, acpi_gpe_handler address, void *context); #endif /******************************************************************************* * * FUNCTION: acpi_install_notify_handler * * PARAMETERS: device - The device for which notifies will be handled * handler_type - The type of handler: * ACPI_SYSTEM_NOTIFY: System Handler (00-7F) * ACPI_DEVICE_NOTIFY: Device Handler (80-FF) * ACPI_ALL_NOTIFY: Both System and Device * handler - Address of the handler * context - Value passed to the handler on each GPE * * RETURN: Status * * DESCRIPTION: Install a handler for notifications on an ACPI Device, * thermal_zone, or Processor object. * * NOTES: The Root namespace object may have only one handler for each * type of notify (System/Device). Device/Thermal/Processor objects * may have one device notify handler, and multiple system notify * handlers. * ******************************************************************************/ acpi_status acpi_install_notify_handler(acpi_handle device, u32 handler_type, acpi_notify_handler handler, void *context) { struct acpi_namespace_node *node = ACPI_CAST_PTR(struct acpi_namespace_node, device); union acpi_operand_object *obj_desc; union acpi_operand_object *handler_obj; acpi_status status; u32 i; ACPI_FUNCTION_TRACE(acpi_install_notify_handler); /* Parameter validation */ if ((!device) || (!handler) || (!handler_type) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Root Object: * Registering a notify handler on the root object indicates that the * caller wishes to receive notifications for all objects. Note that * only one global handler can be registered per notify type. * Ensure that a handler is not already installed. */ if (device == ACPI_ROOT_OBJECT) { for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { if (handler_type & (i + 1)) { if (acpi_gbl_global_notify[i].handler) { status = AE_ALREADY_EXISTS; goto unlock_and_exit; } acpi_gbl_global_notify[i].handler = handler; acpi_gbl_global_notify[i].context = context; } } goto unlock_and_exit; /* Global notify handler installed, all done */ } /* * All Other Objects: * Caller will only receive notifications specific to the target * object. Note that only certain object types are allowed to * receive notifications. */ /* Are Notifies allowed on this object? */ if (!acpi_ev_is_notify_object(node)) { status = AE_TYPE; goto unlock_and_exit; } /* Check for an existing internal object, might not exist */ obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { /* Create a new object */ obj_desc = acpi_ut_create_internal_object(node->type); if (!obj_desc) { status = AE_NO_MEMORY; goto unlock_and_exit; } /* Attach new object to the Node, remove local reference */ status = acpi_ns_attach_object(device, obj_desc, node->type); acpi_ut_remove_reference(obj_desc); if (ACPI_FAILURE(status)) { goto unlock_and_exit; } } /* Ensure that the handler is not already installed in the lists */ for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { if (handler_type & (i + 1)) { handler_obj = obj_desc->common_notify.notify_list[i]; while (handler_obj) { if (handler_obj->notify.handler == handler) { status = AE_ALREADY_EXISTS; goto unlock_and_exit; } handler_obj = handler_obj->notify.next[i]; } } } /* Create and populate a new notify handler object */ handler_obj = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY); if (!handler_obj) { status = AE_NO_MEMORY; goto unlock_and_exit; } handler_obj->notify.node = node; handler_obj->notify.handler_type = handler_type; handler_obj->notify.handler = handler; handler_obj->notify.context = context; /* Install the handler at the list head(s) */ for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { if (handler_type & (i + 1)) { handler_obj->notify.next[i] = obj_desc->common_notify.notify_list[i]; obj_desc->common_notify.notify_list[i] = handler_obj; } } /* Add an extra reference if handler was installed in both lists */ if (handler_type == ACPI_ALL_NOTIFY) { acpi_ut_add_reference(handler_obj); } unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_install_notify_handler) /******************************************************************************* * * FUNCTION: acpi_remove_notify_handler * * PARAMETERS: device - The device for which the handler is installed * handler_type - The type of handler: * ACPI_SYSTEM_NOTIFY: System Handler (00-7F) * ACPI_DEVICE_NOTIFY: Device Handler (80-FF) * ACPI_ALL_NOTIFY: Both System and Device * handler - Address of the handler * * RETURN: Status * * DESCRIPTION: Remove a handler for notifies on an ACPI device * ******************************************************************************/ acpi_status acpi_remove_notify_handler(acpi_handle device, u32 handler_type, acpi_notify_handler handler) { struct acpi_namespace_node *node = ACPI_CAST_PTR(struct acpi_namespace_node, device); union acpi_operand_object *obj_desc; union acpi_operand_object *handler_obj; union acpi_operand_object *previous_handler_obj; acpi_status status = AE_OK; u32 i; ACPI_FUNCTION_TRACE(acpi_remove_notify_handler); /* Parameter validation */ if ((!device) || (!handler) || (!handler_type) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Root Object. Global handlers are removed here */ if (device == ACPI_ROOT_OBJECT) { for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { if (handler_type & (i + 1)) { status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (!acpi_gbl_global_notify[i].handler || (acpi_gbl_global_notify[i].handler != handler)) { status = AE_NOT_EXIST; goto unlock_and_exit; } ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Removing global notify handler\n")); acpi_gbl_global_notify[i].handler = NULL; acpi_gbl_global_notify[i].context = NULL; (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); /* Make sure all deferred notify tasks are completed */ acpi_os_wait_events_complete(); } } return_ACPI_STATUS(AE_OK); } /* All other objects: Are Notifies allowed on this object? */ if (!acpi_ev_is_notify_object(node)) { return_ACPI_STATUS(AE_TYPE); } /* Must have an existing internal object */ obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { return_ACPI_STATUS(AE_NOT_EXIST); } /* Internal object exists. Find the handler and remove it */ for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { if (handler_type & (i + 1)) { status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } handler_obj = obj_desc->common_notify.notify_list[i]; previous_handler_obj = NULL; /* Attempt to find the handler in the handler list */ while (handler_obj && (handler_obj->notify.handler != handler)) { previous_handler_obj = handler_obj; handler_obj = handler_obj->notify.next[i]; } if (!handler_obj) { status = AE_NOT_EXIST; goto unlock_and_exit; } /* Remove the handler object from the list */ if (previous_handler_obj) { /* Handler is not at the list head */ previous_handler_obj->notify.next[i] = handler_obj->notify.next[i]; } else { /* Handler is at the list head */ obj_desc->common_notify.notify_list[i] = handler_obj->notify.next[i]; } (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); /* Make sure all deferred notify tasks are completed */ acpi_os_wait_events_complete(); acpi_ut_remove_reference(handler_obj); } } return_ACPI_STATUS(status); unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler) /******************************************************************************* * * FUNCTION: acpi_install_exception_handler * * PARAMETERS: handler - Pointer to the handler function for the * event * * RETURN: Status * * DESCRIPTION: Saves the pointer to the handler function * ******************************************************************************/ #ifdef ACPI_FUTURE_USAGE acpi_status acpi_install_exception_handler(acpi_exception_handler handler) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_install_exception_handler); status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Don't allow two handlers. */ if (acpi_gbl_exception_handler) { status = AE_ALREADY_EXISTS; goto cleanup; } /* Install the handler */ acpi_gbl_exception_handler = handler; cleanup: (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_install_exception_handler) #endif #if (!ACPI_REDUCED_HARDWARE) /******************************************************************************* * * FUNCTION: acpi_install_sci_handler * * PARAMETERS: address - Address of the handler * context - Value passed to the handler on each SCI * * RETURN: Status * * DESCRIPTION: Install a handler for a System Control Interrupt. * ******************************************************************************/ acpi_status acpi_install_sci_handler(acpi_sci_handler address, void *context) { struct acpi_sci_handler_info *new_sci_handler; struct acpi_sci_handler_info *sci_handler; acpi_cpu_flags flags; acpi_status status; ACPI_FUNCTION_TRACE(acpi_install_sci_handler); if (!address) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Allocate and init a handler object */ new_sci_handler = ACPI_ALLOCATE(sizeof(struct acpi_sci_handler_info)); if (!new_sci_handler) { return_ACPI_STATUS(AE_NO_MEMORY); } new_sci_handler->address = address; new_sci_handler->context = context; status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { goto exit; } /* Lock list during installation */ flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); sci_handler = acpi_gbl_sci_handler_list; /* Ensure handler does not already exist */ while (sci_handler) { if (address == sci_handler->address) { status = AE_ALREADY_EXISTS; goto unlock_and_exit; } sci_handler = sci_handler->next; } /* Install the new handler into the global list (at head) */ new_sci_handler->next = acpi_gbl_sci_handler_list; acpi_gbl_sci_handler_list = new_sci_handler; unlock_and_exit: acpi_os_release_lock(acpi_gbl_gpe_lock, flags); (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); exit: if (ACPI_FAILURE(status)) { ACPI_FREE(new_sci_handler); } return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_install_sci_handler) /******************************************************************************* * * FUNCTION: acpi_remove_sci_handler * * PARAMETERS: address - Address of the handler * * RETURN: Status * * DESCRIPTION: Remove a handler for a System Control Interrupt. * ******************************************************************************/ acpi_status acpi_remove_sci_handler(acpi_sci_handler address) { struct acpi_sci_handler_info *prev_sci_handler; struct acpi_sci_handler_info *next_sci_handler; acpi_cpu_flags flags; acpi_status status; ACPI_FUNCTION_TRACE(acpi_remove_sci_handler); if (!address) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Remove the SCI handler with lock */ flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); prev_sci_handler = NULL; next_sci_handler = acpi_gbl_sci_handler_list; while (next_sci_handler) { if (next_sci_handler->address == address) { /* Unlink and free the SCI handler info block */ if (prev_sci_handler) { prev_sci_handler->next = next_sci_handler->next; } else { acpi_gbl_sci_handler_list = next_sci_handler->next; } acpi_os_release_lock(acpi_gbl_gpe_lock, flags); ACPI_FREE(next_sci_handler); goto unlock_and_exit; } prev_sci_handler = next_sci_handler; next_sci_handler = next_sci_handler->next; } acpi_os_release_lock(acpi_gbl_gpe_lock, flags); status = AE_NOT_EXIST; unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_remove_sci_handler) /******************************************************************************* * * FUNCTION: acpi_install_global_event_handler * * PARAMETERS: handler - Pointer to the global event handler function * context - Value passed to the handler on each event * * RETURN: Status * * DESCRIPTION: Saves the pointer to the handler function. The global handler * is invoked upon each incoming GPE and Fixed Event. It is * invoked at interrupt level at the time of the event dispatch. * Can be used to update event counters, etc. * ******************************************************************************/ acpi_status acpi_install_global_event_handler(acpi_gbl_event_handler handler, void *context) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_install_global_event_handler); /* Parameter validation */ if (!handler) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Don't allow two handlers. */ if (acpi_gbl_global_event_handler) { status = AE_ALREADY_EXISTS; goto cleanup; } acpi_gbl_global_event_handler = handler; acpi_gbl_global_event_handler_context = context; cleanup: (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler) /******************************************************************************* * * FUNCTION: acpi_install_fixed_event_handler * * PARAMETERS: event - Event type to enable. * handler - Pointer to the handler function for the * event * context - Value passed to the handler on each GPE * * RETURN: Status * * DESCRIPTION: Saves the pointer to the handler function and then enables the * event. * ******************************************************************************/ acpi_status acpi_install_fixed_event_handler(u32 event, acpi_event_handler handler, void *context) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler); /* Parameter validation */ if (event > ACPI_EVENT_MAX) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Do not allow multiple handlers */ if (acpi_gbl_fixed_event_handlers[event].handler) { status = AE_ALREADY_EXISTS; goto cleanup; } /* Install the handler before enabling the event */ acpi_gbl_fixed_event_handlers[event].handler = handler; acpi_gbl_fixed_event_handlers[event].context = context; status = acpi_clear_event(event); if (ACPI_SUCCESS(status)) status = acpi_enable_event(event, 0); if (ACPI_FAILURE(status)) { ACPI_WARNING((AE_INFO, "Could not enable fixed event - %s (%u)", acpi_ut_get_event_name(event), event)); /* Remove the handler */ acpi_gbl_fixed_event_handlers[event].handler = NULL; acpi_gbl_fixed_event_handlers[event].context = NULL; } else { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Enabled fixed event %s (%X), Handler=%p\n", acpi_ut_get_event_name(event), event, handler)); } cleanup: (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler) /******************************************************************************* * * FUNCTION: acpi_remove_fixed_event_handler * * PARAMETERS: event - Event type to disable. * handler - Address of the handler * * RETURN: Status * * DESCRIPTION: Disables the event and unregisters the event handler. * ******************************************************************************/ acpi_status acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler) { acpi_status status = AE_OK; ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler); /* Parameter validation */ if (event > ACPI_EVENT_MAX) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Disable the event before removing the handler */ status = acpi_disable_event(event, 0); /* Always Remove the handler */ acpi_gbl_fixed_event_handlers[event].handler = NULL; acpi_gbl_fixed_event_handlers[event].context = NULL; if (ACPI_FAILURE(status)) { ACPI_WARNING((AE_INFO, "Could not disable fixed event - %s (%u)", acpi_ut_get_event_name(event), event)); } else { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event - %s (%X)\n", acpi_ut_get_event_name(event), event)); } (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler) /******************************************************************************* * * FUNCTION: acpi_ev_install_gpe_handler * * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT * defined GPEs) * gpe_number - The GPE number within the GPE block * type - Whether this GPE should be treated as an * edge- or level-triggered interrupt. * is_raw_handler - Whether this GPE should be handled using * the special GPE handler mode. * address - Address of the handler * context - Value passed to the handler on each GPE * * RETURN: Status * * DESCRIPTION: Internal function to install a handler for a General Purpose * Event. * ******************************************************************************/ static acpi_status acpi_ev_install_gpe_handler(acpi_handle gpe_device, u32 gpe_number, u32 type, u8 is_raw_handler, acpi_gpe_handler address, void *context) { struct acpi_gpe_event_info *gpe_event_info; struct acpi_gpe_handler_info *handler; acpi_status status; acpi_cpu_flags flags; ACPI_FUNCTION_TRACE(ev_install_gpe_handler); /* Parameter validation */ if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Allocate and init handler object (before lock) */ handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info)); if (!handler) { status = AE_NO_MEMORY; goto unlock_and_exit; } flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); /* Ensure that we have a valid GPE number */ gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); if (!gpe_event_info) { status = AE_BAD_PARAMETER; goto free_and_exit; } /* Make sure that there isn't a handler there already */ if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) == ACPI_GPE_DISPATCH_HANDLER) || (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) == ACPI_GPE_DISPATCH_RAW_HANDLER)) { status = AE_ALREADY_EXISTS; goto free_and_exit; } handler->address = address; handler->context = context; handler->method_node = gpe_event_info->dispatch.method_node; handler->original_flags = (u8)(gpe_event_info->flags & (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK)); /* * If the GPE is associated with a method, it may have been enabled * automatically during initialization, in which case it has to be * disabled now to avoid spurious execution of the handler. */ if (((ACPI_GPE_DISPATCH_TYPE(handler->original_flags) == ACPI_GPE_DISPATCH_METHOD) || (ACPI_GPE_DISPATCH_TYPE(handler->original_flags) == ACPI_GPE_DISPATCH_NOTIFY)) && gpe_event_info->runtime_count) { handler->originally_enabled = TRUE; (void)acpi_ev_remove_gpe_reference(gpe_event_info); /* Sanity check of original type against new type */ if (type != (u32)(gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) { ACPI_WARNING((AE_INFO, "GPE type mismatch (level/edge)")); } } /* Install the handler */ gpe_event_info->dispatch.handler = handler; /* Setup up dispatch flags to indicate handler (vs. method/notify) */ gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); gpe_event_info->flags |= (u8)(type | (is_raw_handler ? ACPI_GPE_DISPATCH_RAW_HANDLER : ACPI_GPE_DISPATCH_HANDLER)); acpi_os_release_lock(acpi_gbl_gpe_lock, flags); unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); free_and_exit: acpi_os_release_lock(acpi_gbl_gpe_lock, flags); ACPI_FREE(handler); goto unlock_and_exit; } /******************************************************************************* * * FUNCTION: acpi_install_gpe_handler * * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT * defined GPEs) * gpe_number - The GPE number within the GPE block * type - Whether this GPE should be treated as an * edge- or level-triggered interrupt. * address - Address of the handler * context - Value passed to the handler on each GPE * * RETURN: Status * * DESCRIPTION: Install a handler for a General Purpose Event. * ******************************************************************************/ acpi_status acpi_install_gpe_handler(acpi_handle gpe_device, u32 gpe_number, u32 type, acpi_gpe_handler address, void *context) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_install_gpe_handler); status = acpi_ev_install_gpe_handler(gpe_device, gpe_number, type, FALSE, address, context); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler) /******************************************************************************* * * FUNCTION: acpi_install_gpe_raw_handler * * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT * defined GPEs) * gpe_number - The GPE number within the GPE block * type - Whether this GPE should be treated as an * edge- or level-triggered interrupt. * address - Address of the handler * context - Value passed to the handler on each GPE * * RETURN: Status * * DESCRIPTION: Install a handler for a General Purpose Event. * ******************************************************************************/ acpi_status acpi_install_gpe_raw_handler(acpi_handle gpe_device, u32 gpe_number, u32 type, acpi_gpe_handler address, void *context) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_install_gpe_raw_handler); status = acpi_ev_install_gpe_handler(gpe_device, gpe_number, type, TRUE, address, context); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_install_gpe_raw_handler) /******************************************************************************* * * FUNCTION: acpi_remove_gpe_handler * * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT * defined GPEs) * gpe_number - The event to remove a handler * address - Address of the handler * * RETURN: Status * * DESCRIPTION: Remove a handler for a General Purpose acpi_event. * ******************************************************************************/ acpi_status acpi_remove_gpe_handler(acpi_handle gpe_device, u32 gpe_number, acpi_gpe_handler address) { struct acpi_gpe_event_info *gpe_event_info; struct acpi_gpe_handler_info *handler; acpi_status status; acpi_cpu_flags flags; ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler); /* Parameter validation */ if (!address) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); /* Ensure that we have a valid GPE number */ gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); if (!gpe_event_info) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } /* Make sure that a handler is indeed installed */ if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) != ACPI_GPE_DISPATCH_HANDLER) && (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) != ACPI_GPE_DISPATCH_RAW_HANDLER)) { status = AE_NOT_EXIST; goto unlock_and_exit; } /* Make sure that the installed handler is the same */ if (gpe_event_info->dispatch.handler->address != address) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } /* Remove the handler */ handler = gpe_event_info->dispatch.handler; gpe_event_info->dispatch.handler = NULL; /* Restore Method node (if any), set dispatch flags */ gpe_event_info->dispatch.method_node = handler->method_node; gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); gpe_event_info->flags |= handler->original_flags; /* * If the GPE was previously associated with a method and it was * enabled, it should be enabled at this point to restore the * post-initialization configuration. */ if (((ACPI_GPE_DISPATCH_TYPE(handler->original_flags) == ACPI_GPE_DISPATCH_METHOD) || (ACPI_GPE_DISPATCH_TYPE(handler->original_flags) == ACPI_GPE_DISPATCH_NOTIFY)) && handler->originally_enabled) { (void)acpi_ev_add_gpe_reference(gpe_event_info, FALSE); if (ACPI_GPE_IS_POLLING_NEEDED(gpe_event_info)) { /* Poll edge triggered GPEs to handle existing events */ acpi_os_release_lock(acpi_gbl_gpe_lock, flags); (void)acpi_ev_detect_gpe(gpe_device, gpe_event_info, gpe_number); flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); } } acpi_os_release_lock(acpi_gbl_gpe_lock, flags); (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); /* Make sure all deferred GPE tasks are completed */ acpi_os_wait_events_complete(); /* Now we can free the handler object */ ACPI_FREE(handler); return_ACPI_STATUS(status); unlock_and_exit: acpi_os_release_lock(acpi_gbl_gpe_lock, flags); (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); return_ACPI_STATUS(status); } ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler) /******************************************************************************* * * FUNCTION: acpi_acquire_global_lock * * PARAMETERS: timeout - How long the caller is willing to wait * handle - Where the handle to the lock is returned * (if acquired) * * RETURN: Status * * DESCRIPTION: Acquire the ACPI Global Lock * * Note: Allows callers with the same thread ID to acquire the global lock * multiple times. In other words, externally, the behavior of the global lock * is identical to an AML mutex. On the first acquire, a new handle is * returned. On any subsequent calls to acquire by the same thread, the same * handle is returned. * ******************************************************************************/ acpi_status acpi_acquire_global_lock(u16 timeout, u32 *handle) { acpi_status status; if (!handle) { return (AE_BAD_PARAMETER); } /* Must lock interpreter to prevent race conditions */ acpi_ex_enter_interpreter(); status = acpi_ex_acquire_mutex_object(timeout, acpi_gbl_global_lock_mutex, acpi_os_get_thread_id()); if (ACPI_SUCCESS(status)) { /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */ *handle = acpi_gbl_global_lock_handle; } acpi_ex_exit_interpreter(); return (status); } ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock) /******************************************************************************* * * FUNCTION: acpi_release_global_lock * * PARAMETERS: handle - Returned from acpi_acquire_global_lock * * RETURN: Status * * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid. * ******************************************************************************/ acpi_status acpi_release_global_lock(u32 handle) { acpi_status status; if (!handle || (handle != acpi_gbl_global_lock_handle)) { return (AE_NOT_ACQUIRED); } status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex); return (status); } ACPI_EXPORT_SYMBOL(acpi_release_global_lock) #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/evxface.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: evregion - Operation Region support * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acevents.h" #include "acnamesp.h" #include "acinterp.h" #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evregion") extern u8 acpi_gbl_default_address_spaces[]; /* Local prototypes */ static void acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node, acpi_adr_space_type space_id); static acpi_status acpi_ev_reg_run(acpi_handle obj_handle, u32 level, void *context, void **return_value); /******************************************************************************* * * FUNCTION: acpi_ev_initialize_op_regions * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Execute _REG methods for all Operation Regions that have * an installed default region handler. * ******************************************************************************/ acpi_status acpi_ev_initialize_op_regions(void) { acpi_status status; u32 i; ACPI_FUNCTION_TRACE(ev_initialize_op_regions); status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Run the _REG methods for op_regions in each default address space */ for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { /* * Make sure the installed handler is the DEFAULT handler. If not the * default, the _REG methods will have already been run (when the * handler was installed) */ if (acpi_ev_has_default_handler(acpi_gbl_root_node, acpi_gbl_default_address_spaces [i])) { acpi_ev_execute_reg_methods(acpi_gbl_root_node, acpi_gbl_default_address_spaces [i], ACPI_REG_CONNECT); } } (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_address_space_dispatch * * PARAMETERS: region_obj - Internal region object * field_obj - Corresponding field. Can be NULL. * function - Read or Write operation * region_offset - Where in the region to read or write * bit_width - Field width in bits (8, 16, 32, or 64) * value - Pointer to in or out value, must be * a full 64-bit integer * * RETURN: Status * * DESCRIPTION: Dispatch an address space or operation region access to * a previously installed handler. * * NOTE: During early initialization, we always install the default region * handlers for Memory, I/O and PCI_Config. This ensures that these operation * region address spaces are always available as per the ACPI specification. * This is especially needed in order to support the execution of * module-level AML code during loading of the ACPI tables. * ******************************************************************************/ acpi_status acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj, union acpi_operand_object *field_obj, u32 function, u32 region_offset, u32 bit_width, u64 *value) { acpi_status status; acpi_adr_space_handler handler; acpi_adr_space_setup region_setup; union acpi_operand_object *handler_desc; union acpi_operand_object *region_obj2; void *region_context = NULL; struct acpi_connection_info *context; acpi_mutex context_mutex; u8 context_locked; acpi_physical_address address; ACPI_FUNCTION_TRACE(ev_address_space_dispatch); region_obj2 = acpi_ns_get_secondary_object(region_obj); if (!region_obj2) { return_ACPI_STATUS(AE_NOT_EXIST); } /* Ensure that there is a handler associated with this region */ handler_desc = region_obj->region.handler; if (!handler_desc) { ACPI_ERROR((AE_INFO, "No handler for Region [%4.4s] (%p) [%s]", acpi_ut_get_node_name(region_obj->region.node), region_obj, acpi_ut_get_region_name(region_obj->region. space_id))); return_ACPI_STATUS(AE_NOT_EXIST); } context = handler_desc->address_space.context; context_mutex = handler_desc->address_space.context_mutex; context_locked = FALSE; /* * It may be the case that the region has never been initialized. * Some types of regions require special init code */ if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { /* This region has not been initialized yet, do it */ region_setup = handler_desc->address_space.setup; if (!region_setup) { /* No initialization routine, exit with error */ ACPI_ERROR((AE_INFO, "No init routine for region(%p) [%s]", region_obj, acpi_ut_get_region_name(region_obj->region. space_id))); return_ACPI_STATUS(AE_NOT_EXIST); } if (region_obj->region.space_id == ACPI_ADR_SPACE_PLATFORM_COMM) { struct acpi_pcc_info *ctx = handler_desc->address_space.context; ctx->internal_buffer = field_obj->field.internal_pcc_buffer; ctx->length = (u16)region_obj->region.length; ctx->subspace_id = (u8)region_obj->region.address; } if (region_obj->region.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { struct acpi_ffh_info *ctx = handler_desc->address_space.context; ctx->length = region_obj->region.length; ctx->offset = region_obj->region.address; } /* * We must exit the interpreter because the region setup will * potentially execute control methods (for example, the _REG method * for this region) */ acpi_ex_exit_interpreter(); status = region_setup(region_obj, ACPI_REGION_ACTIVATE, context, &region_context); /* Re-enter the interpreter */ acpi_ex_enter_interpreter(); /* Check for failure of the Region Setup */ if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "During region initialization: [%s]", acpi_ut_get_region_name(region_obj-> region. space_id))); return_ACPI_STATUS(status); } /* Region initialization may have been completed by region_setup */ if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; /* * Save the returned context for use in all accesses to * the handler for this particular region */ if (!(region_obj2->extra.region_context)) { region_obj2->extra.region_context = region_context; } } } /* We have everything we need, we can invoke the address space handler */ handler = handler_desc->address_space.handler; address = (region_obj->region.address + region_offset); ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", &region_obj->region.handler->address_space, handler, ACPI_FORMAT_UINT64(address), acpi_ut_get_region_name(region_obj->region. space_id))); if (!(handler_desc->address_space.handler_flags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { /* * For handlers other than the default (supplied) handlers, we must * exit the interpreter because the handler *might* block -- we don't * know what it will do, so we can't hold the lock on the interpreter. */ acpi_ex_exit_interpreter(); } /* * Special handling for generic_serial_bus and general_purpose_io: * There are three extra parameters that must be passed to the * handler via the context: * 1) Connection buffer, a resource template from Connection() op * 2) Length of the above buffer * 3) Actual access length from the access_as() op * * Since we pass these extra parameters via the context, which is * shared between threads, we must lock the context to avoid these * parameters being changed from another thread before the handler * has completed running. * * In addition, for general_purpose_io, the Address and bit_width fields * are defined as follows: * 1) Address is the pin number index of the field (bit offset from * the previous Connection) * 2) bit_width is the actual bit length of the field (number of pins) */ if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS || region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) && context && field_obj) { status = acpi_os_acquire_mutex(context_mutex, ACPI_WAIT_FOREVER); if (ACPI_FAILURE(status)) { goto re_enter_interpreter; } context_locked = TRUE; /* Get the Connection (resource_template) buffer */ context->connection = field_obj->field.resource_buffer; context->length = field_obj->field.resource_length; context->access_length = field_obj->field.access_length; if (region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) { address = field_obj->field.pin_number_index; bit_width = field_obj->field.bit_length; } } /* Call the handler */ status = handler(function, address, bit_width, value, context, region_obj2->extra.region_context); if (context_locked) { acpi_os_release_mutex(context_mutex); } if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]", acpi_ut_get_region_name(region_obj->region. space_id))); /* * Special case for an EC timeout. These are seen so frequently * that an additional error message is helpful */ if ((region_obj->region.space_id == ACPI_ADR_SPACE_EC) && (status == AE_TIME)) { ACPI_ERROR((AE_INFO, "Timeout from EC hardware or EC device driver")); } } re_enter_interpreter: if (!(handler_desc->address_space.handler_flags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { /* * We just returned from a non-default handler, we must re-enter the * interpreter */ acpi_ex_enter_interpreter(); } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_detach_region * * PARAMETERS: region_obj - Region Object * acpi_ns_is_locked - Namespace Region Already Locked? * * RETURN: None * * DESCRIPTION: Break the association between the handler and the region * this is a two way association. * ******************************************************************************/ void acpi_ev_detach_region(union acpi_operand_object *region_obj, u8 acpi_ns_is_locked) { union acpi_operand_object *handler_obj; union acpi_operand_object *obj_desc; union acpi_operand_object *start_desc; union acpi_operand_object **last_obj_ptr; acpi_adr_space_setup region_setup; void **region_context; union acpi_operand_object *region_obj2; acpi_status status; ACPI_FUNCTION_TRACE(ev_detach_region); region_obj2 = acpi_ns_get_secondary_object(region_obj); if (!region_obj2) { return_VOID; } region_context = &region_obj2->extra.region_context; /* Get the address handler from the region object */ handler_obj = region_obj->region.handler; if (!handler_obj) { /* This region has no handler, all done */ return_VOID; } /* Find this region in the handler's list */ obj_desc = handler_obj->address_space.region_list; start_desc = obj_desc; last_obj_ptr = &handler_obj->address_space.region_list; while (obj_desc) { /* Is this the correct Region? */ if (obj_desc == region_obj) { ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Removing Region %p from address handler %p\n", region_obj, handler_obj)); /* This is it, remove it from the handler's list */ *last_obj_ptr = obj_desc->region.next; obj_desc->region.next = NULL; /* Must clear field */ if (acpi_ns_is_locked) { status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_VOID; } } /* Now stop region accesses by executing the _REG method */ status = acpi_ev_execute_reg_method(region_obj, ACPI_REG_DISCONNECT); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "from region _REG, [%s]", acpi_ut_get_region_name (region_obj->region.space_id))); } if (acpi_ns_is_locked) { status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_VOID; } } /* * If the region has been activated, call the setup handler with * the deactivate notification */ if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { region_setup = handler_obj->address_space.setup; status = region_setup(region_obj, ACPI_REGION_DEACTIVATE, handler_obj->address_space. context, region_context); /* * region_context should have been released by the deactivate * operation. We don't need access to it anymore here. */ if (region_context) { *region_context = NULL; } /* Init routine may fail, Just ignore errors */ if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "from region handler - deactivate, [%s]", acpi_ut_get_region_name (region_obj->region. space_id))); } region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE); } /* * Remove handler reference in the region * * NOTE: this doesn't mean that the region goes away, the region * is just inaccessible as indicated to the _REG method * * If the region is on the handler's list, this must be the * region's handler */ region_obj->region.handler = NULL; acpi_ut_remove_reference(handler_obj); return_VOID; } /* Walk the linked list of handlers */ last_obj_ptr = &obj_desc->region.next; obj_desc = obj_desc->region.next; /* Prevent infinite loop if list is corrupted */ if (obj_desc == start_desc) { ACPI_ERROR((AE_INFO, "Circular handler list in region object %p", region_obj)); return_VOID; } } /* If we get here, the region was not in the handler's region list */ ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Cannot remove region %p from address handler %p\n", region_obj, handler_obj)); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ev_attach_region * * PARAMETERS: handler_obj - Handler Object * region_obj - Region Object * acpi_ns_is_locked - Namespace Region Already Locked? * * RETURN: None * * DESCRIPTION: Create the association between the handler and the region * this is a two way association. * ******************************************************************************/ acpi_status acpi_ev_attach_region(union acpi_operand_object *handler_obj, union acpi_operand_object *region_obj, u8 acpi_ns_is_locked) { ACPI_FUNCTION_TRACE(ev_attach_region); /* Install the region's handler */ if (region_obj->region.handler) { return_ACPI_STATUS(AE_ALREADY_EXISTS); } ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, "Adding Region [%4.4s] %p to address handler %p [%s]\n", acpi_ut_get_node_name(region_obj->region.node), region_obj, handler_obj, acpi_ut_get_region_name(region_obj->region. space_id))); /* Link this region to the front of the handler's list */ region_obj->region.next = handler_obj->address_space.region_list; handler_obj->address_space.region_list = region_obj; region_obj->region.handler = handler_obj; acpi_ut_add_reference(handler_obj); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ev_execute_reg_method * * PARAMETERS: region_obj - Region object * function - Passed to _REG: On (1) or Off (0) * * RETURN: Status * * DESCRIPTION: Execute _REG method for a region * ******************************************************************************/ acpi_status acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function) { struct acpi_evaluate_info *info; union acpi_operand_object *args[3]; union acpi_operand_object *region_obj2; const acpi_name *reg_name_ptr = ACPI_CAST_PTR(acpi_name, METHOD_NAME__REG); struct acpi_namespace_node *method_node; struct acpi_namespace_node *node; acpi_status status; ACPI_FUNCTION_TRACE(ev_execute_reg_method); if (!acpi_gbl_namespace_initialized || region_obj->region.handler == NULL) { return_ACPI_STATUS(AE_OK); } region_obj2 = acpi_ns_get_secondary_object(region_obj); if (!region_obj2) { return_ACPI_STATUS(AE_NOT_EXIST); } /* * Find any "_REG" method associated with this region definition. * The method should always be updated as this function may be * invoked after a namespace change. */ node = region_obj->region.node->parent; status = acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD, &method_node); if (ACPI_SUCCESS(status)) { /* * The _REG method is optional and there can be only one per * region definition. This will be executed when the handler is * attached or removed. */ region_obj2->extra.method_REG = method_node; } if (region_obj2->extra.method_REG == NULL) { return_ACPI_STATUS(AE_OK); } /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */ if ((function == ACPI_REG_CONNECT && region_obj->common.flags & AOPOBJ_REG_CONNECTED) || (function == ACPI_REG_DISCONNECT && !(region_obj->common.flags & AOPOBJ_REG_CONNECTED))) { return_ACPI_STATUS(AE_OK); } /* Allocate and initialize the evaluation information block */ info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); if (!info) { return_ACPI_STATUS(AE_NO_MEMORY); } info->prefix_node = region_obj2->extra.method_REG; info->relative_pathname = NULL; info->parameters = args; info->flags = ACPI_IGNORE_RETURN_VALUE; /* * The _REG method has two arguments: * * arg0 - Integer: * Operation region space ID Same value as region_obj->Region.space_id * * arg1 - Integer: * connection status 1 for connecting the handler, 0 for disconnecting * the handler (Passed as a parameter) */ args[0] = acpi_ut_create_integer_object((u64)region_obj->region.space_id); if (!args[0]) { status = AE_NO_MEMORY; goto cleanup1; } args[1] = acpi_ut_create_integer_object((u64)function); if (!args[1]) { status = AE_NO_MEMORY; goto cleanup2; } args[2] = NULL; /* Terminate list */ /* Execute the method, no return value */ ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, info->prefix_node, NULL)); status = acpi_ns_evaluate(info); acpi_ut_remove_reference(args[1]); if (ACPI_FAILURE(status)) { goto cleanup2; } if (function == ACPI_REG_CONNECT) { region_obj->common.flags |= AOPOBJ_REG_CONNECTED; } else { region_obj->common.flags &= ~AOPOBJ_REG_CONNECTED; } cleanup2: acpi_ut_remove_reference(args[0]); cleanup1: ACPI_FREE(info); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ev_execute_reg_methods * * PARAMETERS: node - Namespace node for the device * space_id - The address space ID * function - Passed to _REG: On (1) or Off (0) * * RETURN: None * * DESCRIPTION: Run all _REG methods for the input Space ID; * Note: assumes namespace is locked, or system init time. * ******************************************************************************/ void acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, acpi_adr_space_type space_id, u32 function) { struct acpi_reg_walk_info info; ACPI_FUNCTION_TRACE(ev_execute_reg_methods); /* * These address spaces do not need a call to _REG, since the ACPI * specification defines them as: "must always be accessible". Since * they never change state (never become unavailable), no need to ever * call _REG on them. Also, a data_table is not a "real" address space, * so do not call _REG. September 2018. */ if ((space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) || (space_id == ACPI_ADR_SPACE_SYSTEM_IO) || (space_id == ACPI_ADR_SPACE_DATA_TABLE)) { return_VOID; } info.space_id = space_id; info.function = function; info.reg_run_count = 0; ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES, " Running _REG methods for SpaceId %s\n", acpi_ut_get_region_name(info.space_id))); /* * Run all _REG methods for all Operation Regions for this space ID. This * is a separate walk in order to handle any interdependencies between * regions and _REG methods. (i.e. handlers must be installed for all * regions of this Space ID before we can run any _REG methods) */ (void)acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, NULL, &info, NULL); /* * Special case for EC and GPIO: handle "orphan" _REG methods with * no region. */ if (space_id == ACPI_ADR_SPACE_EC || space_id == ACPI_ADR_SPACE_GPIO) { acpi_ev_execute_orphan_reg_method(node, space_id); } ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES, " Executed %u _REG methods for SpaceId %s\n", info.reg_run_count, acpi_ut_get_region_name(info.space_id))); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ev_reg_run * * PARAMETERS: walk_namespace callback * * DESCRIPTION: Run _REG method for region objects of the requested spaceID * ******************************************************************************/ static acpi_status acpi_ev_reg_run(acpi_handle obj_handle, u32 level, void *context, void **return_value) { union acpi_operand_object *obj_desc; struct acpi_namespace_node *node; acpi_status status; struct acpi_reg_walk_info *info; info = ACPI_CAST_PTR(struct acpi_reg_walk_info, context); /* Convert and validate the device handle */ node = acpi_ns_validate_handle(obj_handle); if (!node) { return (AE_BAD_PARAMETER); } /* * We only care about regions and objects that are allowed to have * address space handlers */ if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { return (AE_OK); } /* Check for an existing internal object */ obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { /* No object, just exit */ return (AE_OK); } /* Object is a Region */ if (obj_desc->region.space_id != info->space_id) { /* This region is for a different address space, just ignore it */ return (AE_OK); } info->reg_run_count++; status = acpi_ev_execute_reg_method(obj_desc, info->function); return (status); } /******************************************************************************* * * FUNCTION: acpi_ev_execute_orphan_reg_method * * PARAMETERS: device_node - Namespace node for an ACPI device * space_id - The address space ID * * RETURN: None * * DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI * device. This is a _REG method that has no corresponding region * within the device's scope. ACPI tables depending on these * "orphan" _REG methods have been seen for both EC and GPIO * Operation Regions. Presumably the Windows ACPI implementation * always calls the _REG method independent of the presence of * an actual Operation Region with the correct address space ID. * * MUTEX: Assumes the namespace is locked * ******************************************************************************/ static void acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node, acpi_adr_space_type space_id) { acpi_handle reg_method; struct acpi_namespace_node *next_node; acpi_status status; struct acpi_object_list args; union acpi_object objects[2]; ACPI_FUNCTION_TRACE(ev_execute_orphan_reg_method); if (!device_node) { return_VOID; } /* Namespace is currently locked, must release */ (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); /* Get a handle to a _REG method immediately under the EC device */ status = acpi_get_handle(device_node, METHOD_NAME__REG, &reg_method); if (ACPI_FAILURE(status)) { goto exit; /* There is no _REG method present */ } /* * Execute the _REG method only if there is no Operation Region in * this scope with the Embedded Controller space ID. Otherwise, it * will already have been executed. Note, this allows for Regions * with other space IDs to be present; but the code below will then * execute the _REG method with the embedded_control space_ID argument. */ next_node = acpi_ns_get_next_node(device_node, NULL); while (next_node) { if ((next_node->type == ACPI_TYPE_REGION) && (next_node->object) && (next_node->object->region.space_id == space_id)) { goto exit; /* Do not execute the _REG */ } next_node = acpi_ns_get_next_node(device_node, next_node); } /* Evaluate the _REG(space_id,Connect) method */ args.count = 2; args.pointer = objects; objects[0].type = ACPI_TYPE_INTEGER; objects[0].integer.value = space_id; objects[1].type = ACPI_TYPE_INTEGER; objects[1].integer.value = ACPI_REG_CONNECT; (void)acpi_evaluate_object(reg_method, NULL, &args, NULL); exit: /* We ignore all errors from above, don't care */ (void)acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); return_VOID; }
linux-master
drivers/acpi/acpica/evregion.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: rsdumpinfo - Tables used to display resource descriptors. * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acresrc.h" #define _COMPONENT ACPI_RESOURCES ACPI_MODULE_NAME("rsdumpinfo") #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DISASSEMBLER) || defined(ACPI_DEBUGGER) #define ACPI_RSD_OFFSET(f) (u8) ACPI_OFFSET (union acpi_resource_data,f) #define ACPI_PRT_OFFSET(f) (u8) ACPI_OFFSET (struct acpi_pci_routing_table,f) #define ACPI_RSD_TABLE_SIZE(name) (sizeof(name) / sizeof (struct acpi_rsdump_info)) /******************************************************************************* * * Resource Descriptor info tables * * Note: The first table entry must be a Title or Literal and must contain * the table length (number of table entries) * ******************************************************************************/ struct acpi_rsdump_info acpi_rs_dump_irq[7] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_irq), "IRQ", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(irq.descriptor_length), "Descriptor Length", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(irq.triggering), "Triggering", acpi_gbl_he_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(irq.polarity), "Polarity", acpi_gbl_ll_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(irq.shareable), "Sharing", acpi_gbl_shr_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(irq.interrupt_count), "Interrupt Count", NULL}, {ACPI_RSD_SHORTLIST, ACPI_RSD_OFFSET(irq.interrupts[0]), "Interrupt List", NULL} }; struct acpi_rsdump_info acpi_rs_dump_dma[6] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_dma), "DMA", NULL}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(dma.type), "Speed", acpi_gbl_typ_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(dma.bus_master), "Mastering", acpi_gbl_bm_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(dma.transfer), "Transfer Type", acpi_gbl_siz_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(dma.channel_count), "Channel Count", NULL}, {ACPI_RSD_SHORTLIST, ACPI_RSD_OFFSET(dma.channels[0]), "Channel List", NULL} }; struct acpi_rsdump_info acpi_rs_dump_start_dpf[4] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_start_dpf), "Start-Dependent-Functions", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(start_dpf.descriptor_length), "Descriptor Length", NULL}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(start_dpf.compatibility_priority), "Compatibility Priority", acpi_gbl_config_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(start_dpf.performance_robustness), "Performance/Robustness", acpi_gbl_config_decode} }; struct acpi_rsdump_info acpi_rs_dump_end_dpf[1] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_end_dpf), "End-Dependent-Functions", NULL} }; struct acpi_rsdump_info acpi_rs_dump_io[6] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_io), "I/O", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(io.io_decode), "Address Decoding", acpi_gbl_io_decode}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(io.minimum), "Address Minimum", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(io.maximum), "Address Maximum", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(io.alignment), "Alignment", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(io.address_length), "Address Length", NULL} }; struct acpi_rsdump_info acpi_rs_dump_fixed_io[3] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_fixed_io), "Fixed I/O", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(fixed_io.address), "Address", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(fixed_io.address_length), "Address Length", NULL} }; struct acpi_rsdump_info acpi_rs_dump_vendor[3] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_vendor), "Vendor Specific", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(vendor.byte_length), "Length", NULL}, {ACPI_RSD_LONGLIST, ACPI_RSD_OFFSET(vendor.byte_data[0]), "Vendor Data", NULL} }; struct acpi_rsdump_info acpi_rs_dump_end_tag[1] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_end_tag), "EndTag", NULL} }; struct acpi_rsdump_info acpi_rs_dump_memory24[6] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_memory24), "24-Bit Memory Range", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(memory24.write_protect), "Write Protect", acpi_gbl_rw_decode}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(memory24.minimum), "Address Minimum", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(memory24.maximum), "Address Maximum", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(memory24.alignment), "Alignment", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(memory24.address_length), "Address Length", NULL} }; struct acpi_rsdump_info acpi_rs_dump_memory32[6] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_memory32), "32-Bit Memory Range", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(memory32.write_protect), "Write Protect", acpi_gbl_rw_decode}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(memory32.minimum), "Address Minimum", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(memory32.maximum), "Address Maximum", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(memory32.alignment), "Alignment", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(memory32.address_length), "Address Length", NULL} }; struct acpi_rsdump_info acpi_rs_dump_fixed_memory32[4] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_fixed_memory32), "32-Bit Fixed Memory Range", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(fixed_memory32.write_protect), "Write Protect", acpi_gbl_rw_decode}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(fixed_memory32.address), "Address", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(fixed_memory32.address_length), "Address Length", NULL} }; struct acpi_rsdump_info acpi_rs_dump_address16[8] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_address16), "16-Bit WORD Address Space", NULL}, {ACPI_RSD_ADDRESS, 0, NULL, NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(address16.address.granularity), "Granularity", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(address16.address.minimum), "Address Minimum", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(address16.address.maximum), "Address Maximum", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(address16.address.translation_offset), "Translation Offset", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(address16.address.address_length), "Address Length", NULL}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(address16.resource_source), NULL, NULL} }; struct acpi_rsdump_info acpi_rs_dump_address32[8] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_address32), "32-Bit DWORD Address Space", NULL}, {ACPI_RSD_ADDRESS, 0, NULL, NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(address32.address.granularity), "Granularity", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(address32.address.minimum), "Address Minimum", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(address32.address.maximum), "Address Maximum", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(address32.address.translation_offset), "Translation Offset", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(address32.address.address_length), "Address Length", NULL}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(address32.resource_source), NULL, NULL} }; struct acpi_rsdump_info acpi_rs_dump_address64[8] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_address64), "64-Bit QWORD Address Space", NULL}, {ACPI_RSD_ADDRESS, 0, NULL, NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(address64.address.granularity), "Granularity", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(address64.address.minimum), "Address Minimum", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(address64.address.maximum), "Address Maximum", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(address64.address.translation_offset), "Translation Offset", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(address64.address.address_length), "Address Length", NULL}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(address64.resource_source), NULL, NULL} }; struct acpi_rsdump_info acpi_rs_dump_ext_address64[8] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_ext_address64), "64-Bit Extended Address Space", NULL}, {ACPI_RSD_ADDRESS, 0, NULL, NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(ext_address64.address.granularity), "Granularity", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(ext_address64.address.minimum), "Address Minimum", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(ext_address64.address.maximum), "Address Maximum", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(ext_address64.address.translation_offset), "Translation Offset", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(ext_address64.address.address_length), "Address Length", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(ext_address64.type_specific), "Type-Specific Attribute", NULL} }; struct acpi_rsdump_info acpi_rs_dump_ext_irq[8] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_ext_irq), "Extended IRQ", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(extended_irq.producer_consumer), "Type", acpi_gbl_consume_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(extended_irq.triggering), "Triggering", acpi_gbl_he_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(extended_irq.polarity), "Polarity", acpi_gbl_ll_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(extended_irq.shareable), "Sharing", acpi_gbl_shr_decode}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(extended_irq.resource_source), NULL, NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(extended_irq.interrupt_count), "Interrupt Count", NULL}, {ACPI_RSD_DWORDLIST, ACPI_RSD_OFFSET(extended_irq.interrupts[0]), "Interrupt List", NULL} }; struct acpi_rsdump_info acpi_rs_dump_generic_reg[6] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_generic_reg), "Generic Register", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(generic_reg.space_id), "Space ID", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(generic_reg.bit_width), "Bit Width", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(generic_reg.bit_offset), "Bit Offset", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(generic_reg.access_size), "Access Size", NULL}, {ACPI_RSD_UINT64, ACPI_RSD_OFFSET(generic_reg.address), "Address", NULL} }; struct acpi_rsdump_info acpi_rs_dump_gpio[16] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_gpio), "GPIO", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(gpio.revision_id), "RevisionId", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(gpio.connection_type), "ConnectionType", acpi_gbl_ct_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(gpio.producer_consumer), "ProducerConsumer", acpi_gbl_consume_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(gpio.pin_config), "PinConfig", acpi_gbl_ppc_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(gpio.shareable), "Sharing", acpi_gbl_shr_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(gpio.io_restriction), "IoRestriction", acpi_gbl_ior_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(gpio.triggering), "Triggering", acpi_gbl_he_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(gpio.polarity), "Polarity", acpi_gbl_ll_decode}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(gpio.drive_strength), "DriveStrength", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(gpio.debounce_timeout), "DebounceTimeout", NULL}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(gpio.resource_source), "ResourceSource", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(gpio.pin_table_length), "PinTableLength", NULL}, {ACPI_RSD_WORDLIST, ACPI_RSD_OFFSET(gpio.pin_table), "PinTable", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(gpio.vendor_length), "VendorLength", NULL}, {ACPI_RSD_SHORTLISTX, ACPI_RSD_OFFSET(gpio.vendor_data), "VendorData", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_pin_function[10] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_function), "PinFunction", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_function.revision_id), "RevisionId", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_function.pin_config), "PinConfig", acpi_gbl_ppc_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_function.shareable), "Sharing", acpi_gbl_shr_decode}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_function.function_number), "FunctionNumber", NULL}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(pin_function.resource_source), "ResourceSource", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_function.pin_table_length), "PinTableLength", NULL}, {ACPI_RSD_WORDLIST, ACPI_RSD_OFFSET(pin_function.pin_table), "PinTable", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_function.vendor_length), "VendorLength", NULL}, {ACPI_RSD_SHORTLISTX, ACPI_RSD_OFFSET(pin_function.vendor_data), "VendorData", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_clock_input[7] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_clock_input), "ClockInput", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(clock_input.revision_id), "RevisionId", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(clock_input.frequency_numerator), "FrequencyNumerator", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(clock_input.frequency_divisor), "FrequencyDivisor", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(clock_input.scale), "Scale", acpi_gbl_clock_input_scale}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(clock_input.mode), "Mode", acpi_gbl_clock_input_mode}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(clock_input.resource_source), "ResourceSource", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_pin_config[11] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_config), "PinConfig", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_config.revision_id), "RevisionId", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_config.producer_consumer), "ProducerConsumer", acpi_gbl_consume_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_config.shareable), "Sharing", acpi_gbl_shr_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_config.pin_config_type), "PinConfigType", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(pin_config.pin_config_value), "PinConfigValue", NULL}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(pin_config.resource_source), "ResourceSource", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_config.pin_table_length), "PinTableLength", NULL}, {ACPI_RSD_WORDLIST, ACPI_RSD_OFFSET(pin_config.pin_table), "PinTable", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_config.vendor_length), "VendorLength", NULL}, {ACPI_RSD_SHORTLISTX, ACPI_RSD_OFFSET(pin_config.vendor_data), "VendorData", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_pin_group[8] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_group), "PinGroup", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_group.revision_id), "RevisionId", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_group.producer_consumer), "ProducerConsumer", acpi_gbl_consume_decode}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_group.pin_table_length), "PinTableLength", NULL}, {ACPI_RSD_WORDLIST, ACPI_RSD_OFFSET(pin_group.pin_table), "PinTable", NULL}, {ACPI_RSD_LABEL, ACPI_RSD_OFFSET(pin_group.resource_label), "ResourceLabel", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_group.vendor_length), "VendorLength", NULL}, {ACPI_RSD_SHORTLISTX, ACPI_RSD_OFFSET(pin_group.vendor_data), "VendorData", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_pin_group_function[9] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_group_function), "PinGroupFunction", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_group_function.revision_id), "RevisionId", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_group_function.producer_consumer), "ProducerConsumer", acpi_gbl_consume_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_group_function.shareable), "Sharing", acpi_gbl_shr_decode}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_group_function.function_number), "FunctionNumber", NULL}, {ACPI_RSD_SOURCE_LABEL, ACPI_RSD_OFFSET(pin_group_function.resource_source_label), "ResourceSourceLabel", NULL}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(pin_group_function.resource_source), "ResourceSource", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_group_function.vendor_length), "VendorLength", NULL}, {ACPI_RSD_SHORTLISTX, ACPI_RSD_OFFSET(pin_group_function.vendor_data), "VendorData", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_pin_group_config[10] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_group_config), "PinGroupConfig", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_group_config.revision_id), "RevisionId", NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_group_config.producer_consumer), "ProducerConsumer", acpi_gbl_consume_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_group_config.shareable), "Sharing", acpi_gbl_shr_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_group_config.pin_config_type), "PinConfigType", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(pin_group_config.pin_config_value), "PinConfigValue", NULL}, {ACPI_RSD_SOURCE_LABEL, ACPI_RSD_OFFSET(pin_group_config.resource_source_label), "ResourceSourceLabel", NULL}, {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(pin_group_config.resource_source), "ResourceSource", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_group_config.vendor_length), "VendorLength", NULL}, {ACPI_RSD_SHORTLISTX, ACPI_RSD_OFFSET(pin_group_config.vendor_data), "VendorData", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_fixed_dma[4] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_fixed_dma), "FixedDma", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(fixed_dma.request_lines), "RequestLines", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(fixed_dma.channels), "Channels", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(fixed_dma.width), "TransferWidth", acpi_gbl_dts_decode}, }; #define ACPI_RS_DUMP_COMMON_SERIAL_BUS \ {ACPI_RSD_UINT8, ACPI_RSD_OFFSET (common_serial_bus.revision_id), "RevisionId", NULL}, \ {ACPI_RSD_UINT8, ACPI_RSD_OFFSET (common_serial_bus.type), "Type", acpi_gbl_sbt_decode}, \ {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET (common_serial_bus.producer_consumer), "ProducerConsumer", acpi_gbl_consume_decode}, \ {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET (common_serial_bus.slave_mode), "SlaveMode", acpi_gbl_sm_decode}, \ {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET (common_serial_bus.connection_sharing),"ConnectionSharing", acpi_gbl_shr_decode}, \ {ACPI_RSD_UINT8, ACPI_RSD_OFFSET (common_serial_bus.type_revision_id), "TypeRevisionId", NULL}, \ {ACPI_RSD_UINT16, ACPI_RSD_OFFSET (common_serial_bus.type_data_length), "TypeDataLength", NULL}, \ {ACPI_RSD_SOURCE, ACPI_RSD_OFFSET (common_serial_bus.resource_source), "ResourceSource", NULL}, \ {ACPI_RSD_UINT16, ACPI_RSD_OFFSET (common_serial_bus.vendor_length), "VendorLength", NULL}, \ {ACPI_RSD_SHORTLISTX,ACPI_RSD_OFFSET (common_serial_bus.vendor_data), "VendorData", NULL}, struct acpi_rsdump_info acpi_rs_dump_common_serial_bus[11] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_common_serial_bus), "Common Serial Bus", NULL}, ACPI_RS_DUMP_COMMON_SERIAL_BUS }; struct acpi_rsdump_info acpi_rs_dump_csi2_serial_bus[11] = { { ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_csi2_serial_bus), "Camera Serial Bus", NULL }, { ACPI_RSD_UINT8, ACPI_RSD_OFFSET(csi2_serial_bus.revision_id), "RevisionId", NULL }, { ACPI_RSD_UINT8, ACPI_RSD_OFFSET(csi2_serial_bus.type), "Type", acpi_gbl_sbt_decode }, { ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(csi2_serial_bus.producer_consumer), "ProducerConsumer", acpi_gbl_consume_decode }, { ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(csi2_serial_bus.slave_mode), "SlaveMode", acpi_gbl_sm_decode }, { ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(csi2_serial_bus.phy_type), "PhyType", acpi_gbl_phy_decode }, { ACPI_RSD_6BITFLAG, ACPI_RSD_OFFSET(csi2_serial_bus.local_port_instance), "LocalPortInstance", NULL }, { ACPI_RSD_UINT8, ACPI_RSD_OFFSET(csi2_serial_bus.type_revision_id), "TypeRevisionId", NULL }, { ACPI_RSD_UINT16, ACPI_RSD_OFFSET(csi2_serial_bus.vendor_length), "VendorLength", NULL }, { ACPI_RSD_SHORTLISTX, ACPI_RSD_OFFSET(csi2_serial_bus.vendor_data), "VendorData", NULL }, { ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(csi2_serial_bus.resource_source), "ResourceSource", NULL }, }; struct acpi_rsdump_info acpi_rs_dump_i2c_serial_bus[14] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_i2c_serial_bus), "I2C Serial Bus", NULL}, ACPI_RS_DUMP_COMMON_SERIAL_BUS {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(i2c_serial_bus. access_mode), "AccessMode", acpi_gbl_am_decode}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(i2c_serial_bus.connection_speed), "ConnectionSpeed", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(i2c_serial_bus.slave_address), "SlaveAddress", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_spi_serial_bus[18] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_spi_serial_bus), "Spi Serial Bus", NULL}, ACPI_RS_DUMP_COMMON_SERIAL_BUS {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(spi_serial_bus. wire_mode), "WireMode", acpi_gbl_wm_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(spi_serial_bus.device_polarity), "DevicePolarity", acpi_gbl_dp_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(spi_serial_bus.data_bit_length), "DataBitLength", NULL}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(spi_serial_bus.clock_phase), "ClockPhase", acpi_gbl_cph_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(spi_serial_bus.clock_polarity), "ClockPolarity", acpi_gbl_cpo_decode}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(spi_serial_bus.device_selection), "DeviceSelection", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(spi_serial_bus.connection_speed), "ConnectionSpeed", NULL}, }; struct acpi_rsdump_info acpi_rs_dump_uart_serial_bus[20] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_uart_serial_bus), "Uart Serial Bus", NULL}, ACPI_RS_DUMP_COMMON_SERIAL_BUS {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(uart_serial_bus. flow_control), "FlowControl", acpi_gbl_fc_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(uart_serial_bus.stop_bits), "StopBits", acpi_gbl_sb_decode}, {ACPI_RSD_3BITFLAG, ACPI_RSD_OFFSET(uart_serial_bus.data_bits), "DataBits", acpi_gbl_bpb_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(uart_serial_bus.endian), "Endian", acpi_gbl_ed_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(uart_serial_bus.parity), "Parity", acpi_gbl_pt_decode}, {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(uart_serial_bus.lines_enabled), "LinesEnabled", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(uart_serial_bus.rx_fifo_size), "RxFifoSize", NULL}, {ACPI_RSD_UINT16, ACPI_RSD_OFFSET(uart_serial_bus.tx_fifo_size), "TxFifoSize", NULL}, {ACPI_RSD_UINT32, ACPI_RSD_OFFSET(uart_serial_bus.default_baud_rate), "ConnectionSpeed", NULL}, }; /* * Tables used for common address descriptor flag fields */ struct acpi_rsdump_info acpi_rs_dump_general_flags[5] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_general_flags), NULL, NULL}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.producer_consumer), "Consumer/Producer", acpi_gbl_consume_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.decode), "Address Decode", acpi_gbl_dec_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.min_address_fixed), "Min Relocatability", acpi_gbl_min_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.max_address_fixed), "Max Relocatability", acpi_gbl_max_decode} }; struct acpi_rsdump_info acpi_rs_dump_memory_flags[5] = { {ACPI_RSD_LITERAL, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_memory_flags), "Resource Type", (void *)"Memory Range"}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.info.mem.write_protect), "Write Protect", acpi_gbl_rw_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(address.info.mem.caching), "Caching", acpi_gbl_mem_decode}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(address.info.mem.range_type), "Range Type", acpi_gbl_mtp_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.info.mem.translation), "Translation", acpi_gbl_ttp_decode} }; struct acpi_rsdump_info acpi_rs_dump_io_flags[4] = { {ACPI_RSD_LITERAL, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_io_flags), "Resource Type", (void *)"I/O Range"}, {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(address.info.io.range_type), "Range Type", acpi_gbl_rng_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.info.io.translation), "Translation", acpi_gbl_ttp_decode}, {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.info.io.translation_type), "Translation Type", acpi_gbl_trs_decode} }; /* * Table used to dump _PRT contents */ struct acpi_rsdump_info acpi_rs_dump_prt[5] = { {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_prt), NULL, NULL}, {ACPI_RSD_UINT64, ACPI_PRT_OFFSET(address), "Address", NULL}, {ACPI_RSD_UINT32, ACPI_PRT_OFFSET(pin), "Pin", NULL}, {ACPI_RSD_STRING, ACPI_PRT_OFFSET(source[0]), "Source", NULL}, {ACPI_RSD_UINT32, ACPI_PRT_OFFSET(source_index), "Source Index", NULL} }; #endif
linux-master
drivers/acpi/acpica/rsdumpinfo.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: utdelete - object deletion and reference count utilities * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acinterp.h" #include "acnamesp.h" #include "acevents.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utdelete") /* Local prototypes */ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object); static void acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action); /******************************************************************************* * * FUNCTION: acpi_ut_delete_internal_obj * * PARAMETERS: object - Object to be deleted * * RETURN: None * * DESCRIPTION: Low level object deletion, after reference counts have been * updated (All reference counts, including sub-objects!) * ******************************************************************************/ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object) { void *obj_pointer = NULL; union acpi_operand_object *handler_desc; union acpi_operand_object *second_desc; union acpi_operand_object *next_desc; union acpi_operand_object *start_desc; union acpi_operand_object **last_obj_ptr; ACPI_FUNCTION_TRACE_PTR(ut_delete_internal_obj, object); if (!object) { return_VOID; } /* * Must delete or free any pointers within the object that are not * actual ACPI objects (for example, a raw buffer pointer). */ switch (object->common.type) { case ACPI_TYPE_STRING: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n", object, object->string.pointer)); /* Free the actual string buffer */ if (!(object->common.flags & AOPOBJ_STATIC_POINTER)) { /* But only if it is NOT a pointer into an ACPI table */ obj_pointer = object->string.pointer; } break; case ACPI_TYPE_BUFFER: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n", object, object->buffer.pointer)); /* Free the actual buffer */ if (!(object->common.flags & AOPOBJ_STATIC_POINTER)) { /* But only if it is NOT a pointer into an ACPI table */ obj_pointer = object->buffer.pointer; } break; case ACPI_TYPE_PACKAGE: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n", object->package.count)); /* * Elements of the package are not handled here, they are deleted * separately */ /* Free the (variable length) element pointer array */ obj_pointer = object->package.elements; break; /* * These objects have a possible list of notify handlers. * Device object also may have a GPE block. */ case ACPI_TYPE_DEVICE: if (object->device.gpe_block) { (void)acpi_ev_delete_gpe_block(object->device. gpe_block); } ACPI_FALLTHROUGH; case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: /* Walk the address handler list for this object */ handler_desc = object->common_notify.handler; while (handler_desc) { next_desc = handler_desc->address_space.next; acpi_ut_remove_reference(handler_desc); handler_desc = next_desc; } break; case ACPI_TYPE_MUTEX: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Mutex %p, OS Mutex %p\n", object, object->mutex.os_mutex)); if (object == acpi_gbl_global_lock_mutex) { /* Global Lock has extra semaphore */ (void) acpi_os_delete_semaphore (acpi_gbl_global_lock_semaphore); acpi_gbl_global_lock_semaphore = NULL; acpi_os_delete_mutex(object->mutex.os_mutex); acpi_gbl_global_lock_mutex = NULL; } else { acpi_ex_unlink_mutex(object); acpi_os_delete_mutex(object->mutex.os_mutex); } break; case ACPI_TYPE_EVENT: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Event %p, OS Semaphore %p\n", object, object->event.os_semaphore)); (void)acpi_os_delete_semaphore(object->event.os_semaphore); object->event.os_semaphore = NULL; break; case ACPI_TYPE_METHOD: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Method %p\n", object)); /* Delete the method mutex if it exists */ if (object->method.mutex) { acpi_os_delete_mutex(object->method.mutex->mutex. os_mutex); acpi_ut_delete_object_desc(object->method.mutex); object->method.mutex = NULL; } if (object->method.node) { object->method.node = NULL; } break; case ACPI_TYPE_REGION: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Region %p\n", object)); /* * Update address_range list. However, only permanent regions * are installed in this list. (Not created within a method) */ if (!(object->region.node->flags & ANOBJ_TEMPORARY)) { acpi_ut_remove_address_range(object->region.space_id, object->region.node); } second_desc = acpi_ns_get_secondary_object(object); if (second_desc) { /* * Free the region_context if and only if the handler is one of the * default handlers -- and therefore, we created the context object * locally, it was not created by an external caller. */ handler_desc = object->region.handler; if (handler_desc) { next_desc = handler_desc->address_space.region_list; start_desc = next_desc; last_obj_ptr = &handler_desc->address_space.region_list; /* Remove the region object from the handler list */ while (next_desc) { if (next_desc == object) { *last_obj_ptr = next_desc->region.next; break; } /* Walk the linked list of handlers */ last_obj_ptr = &next_desc->region.next; next_desc = next_desc->region.next; /* Prevent infinite loop if list is corrupted */ if (next_desc == start_desc) { ACPI_ERROR((AE_INFO, "Circular region list in address handler object %p", handler_desc)); return_VOID; } } if (handler_desc->address_space.handler_flags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) { /* Deactivate region and free region context */ if (handler_desc->address_space.setup) { (void)handler_desc-> address_space.setup(object, ACPI_REGION_DEACTIVATE, handler_desc-> address_space. context, &second_desc-> extra. region_context); } } acpi_ut_remove_reference(handler_desc); } /* Now we can free the Extra object */ acpi_ut_delete_object_desc(second_desc); } if (object->field.internal_pcc_buffer) { ACPI_FREE(object->field.internal_pcc_buffer); } break; case ACPI_TYPE_BUFFER_FIELD: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Buffer Field %p\n", object)); second_desc = acpi_ns_get_secondary_object(object); if (second_desc) { acpi_ut_delete_object_desc(second_desc); } break; case ACPI_TYPE_LOCAL_BANK_FIELD: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Bank Field %p\n", object)); second_desc = acpi_ns_get_secondary_object(object); if (second_desc) { acpi_ut_delete_object_desc(second_desc); } break; case ACPI_TYPE_LOCAL_ADDRESS_HANDLER: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Address handler %p\n", object)); acpi_os_delete_mutex(object->address_space.context_mutex); break; default: break; } /* Free any allocated memory (pointer within the object) found above */ if (obj_pointer) { ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n", obj_pointer)); ACPI_FREE(obj_pointer); } /* Now the object can be safely deleted */ ACPI_DEBUG_PRINT_RAW((ACPI_DB_ALLOCATIONS, "%s: Deleting Object %p [%s]\n", ACPI_GET_FUNCTION_NAME, object, acpi_ut_get_object_type_name(object))); acpi_ut_delete_object_desc(object); return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ut_delete_internal_object_list * * PARAMETERS: obj_list - Pointer to the list to be deleted * * RETURN: None * * DESCRIPTION: This function deletes an internal object list, including both * simple objects and package objects * ******************************************************************************/ void acpi_ut_delete_internal_object_list(union acpi_operand_object **obj_list) { union acpi_operand_object **internal_obj; ACPI_FUNCTION_ENTRY(); /* Walk the null-terminated internal list */ for (internal_obj = obj_list; *internal_obj; internal_obj++) { acpi_ut_remove_reference(*internal_obj); } /* Free the combined parameter pointer list and object array */ ACPI_FREE(obj_list); return; } /******************************************************************************* * * FUNCTION: acpi_ut_update_ref_count * * PARAMETERS: object - Object whose ref count is to be updated * action - What to do (REF_INCREMENT or REF_DECREMENT) * * RETURN: None. Sets new reference count within the object * * DESCRIPTION: Modify the reference count for an internal acpi object * ******************************************************************************/ static void acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action) { u16 original_count; u16 new_count = 0; acpi_cpu_flags lock_flags; char *message; ACPI_FUNCTION_NAME(ut_update_ref_count); if (!object) { return; } /* * Always get the reference count lock. Note: Interpreter and/or * Namespace is not always locked when this function is called. */ lock_flags = acpi_os_acquire_lock(acpi_gbl_reference_count_lock); original_count = object->common.reference_count; /* Perform the reference count action (increment, decrement) */ switch (action) { case REF_INCREMENT: new_count = original_count + 1; object->common.reference_count = new_count; acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags); /* The current reference count should never be zero here */ if (!original_count) { ACPI_WARNING((AE_INFO, "Obj %p, Reference Count was zero before increment\n", object)); } ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Obj %p Type %.2X [%s] Refs %.2X [Incremented]\n", object, object->common.type, acpi_ut_get_object_type_name(object), new_count)); message = "Incremement"; break; case REF_DECREMENT: /* The current reference count must be non-zero */ if (original_count) { new_count = original_count - 1; object->common.reference_count = new_count; } acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags); if (!original_count) { ACPI_WARNING((AE_INFO, "Obj %p, Reference Count is already zero, cannot decrement\n", object)); return; } ACPI_DEBUG_PRINT_RAW((ACPI_DB_ALLOCATIONS, "%s: Obj %p Type %.2X Refs %.2X [Decremented]\n", ACPI_GET_FUNCTION_NAME, object, object->common.type, new_count)); /* Actually delete the object on a reference count of zero */ if (new_count == 0) { acpi_ut_delete_internal_obj(object); } message = "Decrement"; break; default: acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags); ACPI_ERROR((AE_INFO, "Unknown Reference Count action (0x%X)", action)); return; } /* * Sanity check the reference count, for debug purposes only. * (A deleted object will have a huge reference count) */ if (new_count > ACPI_MAX_REFERENCE_COUNT) { ACPI_WARNING((AE_INFO, "Large Reference Count (0x%X) in object %p, Type=0x%.2X Operation=%s", new_count, object, object->common.type, message)); } } /******************************************************************************* * * FUNCTION: acpi_ut_update_object_reference * * PARAMETERS: object - Increment or decrement the ref count for * this object and all sub-objects * action - Either REF_INCREMENT or REF_DECREMENT * * RETURN: Status * * DESCRIPTION: Increment or decrement the object reference count * * Object references are incremented when: * 1) An object is attached to a Node (namespace object) * 2) An object is copied (all subobjects must be incremented) * * Object references are decremented when: * 1) An object is detached from an Node * ******************************************************************************/ acpi_status acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action) { acpi_status status = AE_OK; union acpi_generic_state *state_list = NULL; union acpi_operand_object *next_object = NULL; union acpi_operand_object *prev_object; union acpi_generic_state *state; u32 i; ACPI_FUNCTION_NAME(ut_update_object_reference); while (object) { /* Make sure that this isn't a namespace handle */ if (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) { ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Object %p is NS handle\n", object)); return (AE_OK); } /* * All sub-objects must have their reference count updated * also. Different object types have different subobjects. */ switch (object->common.type) { case ACPI_TYPE_DEVICE: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_POWER: case ACPI_TYPE_THERMAL: /* * Update the notify objects for these types (if present) * Two lists, system and device notify handlers. */ for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { prev_object = object->common_notify.notify_list[i]; while (prev_object) { next_object = prev_object->notify.next[i]; acpi_ut_update_ref_count(prev_object, action); prev_object = next_object; } } break; case ACPI_TYPE_PACKAGE: /* * We must update all the sub-objects of the package, * each of whom may have their own sub-objects. */ for (i = 0; i < object->package.count; i++) { /* * Null package elements are legal and can be simply * ignored. */ next_object = object->package.elements[i]; if (!next_object) { continue; } switch (next_object->common.type) { case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* * For these very simple sub-objects, we can just * update the reference count here and continue. * Greatly increases performance of this operation. */ acpi_ut_update_ref_count(next_object, action); break; default: /* * For complex sub-objects, push them onto the stack * for later processing (this eliminates recursion.) */ status = acpi_ut_create_update_state_and_push (next_object, action, &state_list); if (ACPI_FAILURE(status)) { goto error_exit; } break; } } next_object = NULL; break; case ACPI_TYPE_BUFFER_FIELD: next_object = object->buffer_field.buffer_obj; break; case ACPI_TYPE_LOCAL_BANK_FIELD: next_object = object->bank_field.bank_obj; status = acpi_ut_create_update_state_and_push(object-> bank_field. region_obj, action, &state_list); if (ACPI_FAILURE(status)) { goto error_exit; } break; case ACPI_TYPE_LOCAL_INDEX_FIELD: next_object = object->index_field.index_obj; status = acpi_ut_create_update_state_and_push(object-> index_field. data_obj, action, &state_list); if (ACPI_FAILURE(status)) { goto error_exit; } break; case ACPI_TYPE_LOCAL_REFERENCE: /* * The target of an Index (a package, string, or buffer) or a named * reference must track changes to the ref count of the index or * target object. */ if ((object->reference.class == ACPI_REFCLASS_INDEX) || (object->reference.class == ACPI_REFCLASS_NAME)) { next_object = object->reference.object; } break; case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_REGION: default: break; /* No subobjects for all other types */ } /* * Now we can update the count in the main object. This can only * happen after we update the sub-objects in case this causes the * main object to be deleted. */ acpi_ut_update_ref_count(object, action); object = NULL; /* Move on to the next object to be updated */ if (next_object) { object = next_object; next_object = NULL; } else if (state_list) { state = acpi_ut_pop_generic_state(&state_list); object = state->update.object; acpi_ut_delete_generic_state(state); } } return (AE_OK); error_exit: ACPI_EXCEPTION((AE_INFO, status, "Could not update object reference count")); /* Free any stacked Update State objects */ while (state_list) { state = acpi_ut_pop_generic_state(&state_list); acpi_ut_delete_generic_state(state); } return (status); } /******************************************************************************* * * FUNCTION: acpi_ut_add_reference * * PARAMETERS: object - Object whose reference count is to be * incremented * * RETURN: None * * DESCRIPTION: Add one reference to an ACPI object * ******************************************************************************/ void acpi_ut_add_reference(union acpi_operand_object *object) { ACPI_FUNCTION_NAME(ut_add_reference); /* Ensure that we have a valid object */ if (!acpi_ut_valid_internal_object(object)) { return; } ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Obj %p Current Refs=%X [To Be Incremented]\n", object, object->common.reference_count)); /* Increment the reference count */ (void)acpi_ut_update_object_reference(object, REF_INCREMENT); return; } /******************************************************************************* * * FUNCTION: acpi_ut_remove_reference * * PARAMETERS: object - Object whose ref count will be decremented * * RETURN: None * * DESCRIPTION: Decrement the reference count of an ACPI internal object * ******************************************************************************/ void acpi_ut_remove_reference(union acpi_operand_object *object) { ACPI_FUNCTION_NAME(ut_remove_reference); /* * Allow a NULL pointer to be passed in, just ignore it. This saves * each caller from having to check. Also, ignore NS nodes. */ if (!object || (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED)) { return; } /* Ensure that we have a valid object */ if (!acpi_ut_valid_internal_object(object)) { return; } ACPI_DEBUG_PRINT_RAW((ACPI_DB_ALLOCATIONS, "%s: Obj %p Current Refs=%X [To Be Decremented]\n", ACPI_GET_FUNCTION_NAME, object, object->common.reference_count)); /* * Decrement the reference count, and only actually delete the object * if the reference count becomes 0. (Must also decrement the ref count * of all subobjects!) */ (void)acpi_ut_update_object_reference(object, REF_DECREMENT); return; }
linux-master
drivers/acpi/acpica/utdelete.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Name: hwsleep.c - ACPI Hardware Sleep/Wake Support functions for the * original/legacy sleep/PM registers. * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_HARDWARE ACPI_MODULE_NAME("hwsleep") #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ /******************************************************************************* * * FUNCTION: acpi_hw_legacy_sleep * * PARAMETERS: sleep_state - Which sleep state to enter * * RETURN: Status * * DESCRIPTION: Enter a system sleep state via the legacy FADT PM registers * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED * ******************************************************************************/ acpi_status acpi_hw_legacy_sleep(u8 sleep_state) { struct acpi_bit_register_info *sleep_type_reg_info; struct acpi_bit_register_info *sleep_enable_reg_info; u32 pm1a_control; u32 pm1b_control; u32 in_value; acpi_status status; ACPI_FUNCTION_TRACE(hw_legacy_sleep); sleep_type_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); sleep_enable_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); /* Clear wake status */ status = acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Disable all GPEs */ status = acpi_hw_disable_all_gpes(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_hw_clear_acpi_status(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_gbl_system_awake_and_running = FALSE; /* Enable all wakeup GPEs */ status = acpi_hw_enable_all_wakeup_gpes(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Get current value of PM1A control */ status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &pm1a_control); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } ACPI_DEBUG_PRINT((ACPI_DB_INIT, "Entering sleep state [S%u]\n", sleep_state)); /* Clear the SLP_EN and SLP_TYP fields */ pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info->access_bit_mask); pm1b_control = pm1a_control; /* Insert the SLP_TYP bits */ pm1a_control |= (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); pm1b_control |= (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); /* * We split the writes of SLP_TYP and SLP_EN to workaround * poorly implemented hardware. */ /* Write #1: write the SLP_TYP data to the PM1 Control registers */ status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Insert the sleep enable (SLP_EN) bit */ pm1a_control |= sleep_enable_reg_info->access_bit_mask; pm1b_control |= sleep_enable_reg_info->access_bit_mask; /* Flush caches, as per ACPI specification */ if (sleep_state < ACPI_STATE_S4) { ACPI_FLUSH_CPU_CACHE(); } status = acpi_os_enter_sleep(sleep_state, pm1a_control, pm1b_control); if (status == AE_CTRL_TERMINATE) { return_ACPI_STATUS(AE_OK); } if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Write #2: Write both SLP_TYP + SLP_EN */ status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (sleep_state > ACPI_STATE_S3) { /* * We wanted to sleep > S3, but it didn't happen (by virtue of the * fact that we are still executing!) * * Wait ten seconds, then try again. This is to get S4/S5 to work on * all machines. * * We wait so long to allow chipsets that poll this reg very slowly * to still read the right value. Ideally, this block would go * away entirely. */ acpi_os_stall(10 * ACPI_USEC_PER_SEC); status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, sleep_enable_reg_info-> access_bit_mask); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } /* Wait for transition back to Working State */ do { status = acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } while (!in_value); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_hw_legacy_wake_prep * * PARAMETERS: sleep_state - Which sleep state we just exited * * RETURN: Status * * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a * sleep. * Called with interrupts ENABLED. * ******************************************************************************/ acpi_status acpi_hw_legacy_wake_prep(u8 sleep_state) { acpi_status status = AE_OK; struct acpi_bit_register_info *sleep_type_reg_info; struct acpi_bit_register_info *sleep_enable_reg_info; u32 pm1a_control; u32 pm1b_control; ACPI_FUNCTION_TRACE(hw_legacy_wake_prep); /* * Set SLP_TYPE and SLP_EN to state S0. * This is unclear from the ACPI Spec, but it is required * by some machines. */ if (acpi_gbl_sleep_type_a_s0 != ACPI_SLEEP_TYPE_INVALID) { sleep_type_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); sleep_enable_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); /* Get current value of PM1A control */ status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &pm1a_control); if (ACPI_SUCCESS(status)) { /* Clear the SLP_EN and SLP_TYP fields */ pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info-> access_bit_mask); pm1b_control = pm1a_control; /* Insert the SLP_TYP bits */ pm1a_control |= (acpi_gbl_sleep_type_a_s0 << sleep_type_reg_info->bit_position); pm1b_control |= (acpi_gbl_sleep_type_b_s0 << sleep_type_reg_info->bit_position); /* Write the control registers and ignore any errors */ (void)acpi_hw_write_pm1_control(pm1a_control, pm1b_control); } } return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_hw_legacy_wake * * PARAMETERS: sleep_state - Which sleep state we just exited * * RETURN: Status * * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep * Called with interrupts ENABLED. * ******************************************************************************/ acpi_status acpi_hw_legacy_wake(u8 sleep_state) { acpi_status status; ACPI_FUNCTION_TRACE(hw_legacy_wake); /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING); /* * GPEs must be enabled before _WAK is called as GPEs * might get fired there * * Restore the GPEs: * 1) Disable all GPEs * 2) Enable all runtime GPEs */ status = acpi_hw_disable_all_gpes(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_hw_enable_all_runtime_gpes(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Now we can execute _WAK, etc. Some machines require that the GPEs * are enabled before the wake methods are executed. */ acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state); /* * Some BIOS code assumes that WAK_STS will be cleared on resume * and use it to determine whether the system is rebooting or * resuming. Clear WAK_STS for compatibility. */ (void)acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); acpi_gbl_system_awake_and_running = TRUE; /* Enable power button */ (void) acpi_write_bit_register(acpi_gbl_fixed_event_info [ACPI_EVENT_POWER_BUTTON]. enable_register_id, ACPI_ENABLE_EVENT); (void) acpi_write_bit_register(acpi_gbl_fixed_event_info [ACPI_EVENT_POWER_BUTTON]. status_register_id, ACPI_CLEAR_STATUS); /* Enable sleep button */ (void) acpi_write_bit_register(acpi_gbl_fixed_event_info [ACPI_EVENT_SLEEP_BUTTON]. enable_register_id, ACPI_ENABLE_EVENT); (void) acpi_write_bit_register(acpi_gbl_fixed_event_info [ACPI_EVENT_SLEEP_BUTTON]. status_register_id, ACPI_CLEAR_STATUS); acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING); return_ACPI_STATUS(status); } #endif /* !ACPI_REDUCED_HARDWARE */
linux-master
drivers/acpi/acpica/hwsleep.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: utxferror - Various error/warning output functions * ******************************************************************************/ #define EXPORT_ACPI_INTERFACES #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utxferror") /* * This module is used for the in-kernel ACPICA as well as the ACPICA * tools/applications. */ #ifndef ACPI_NO_ERROR_MESSAGES /* Entire module */ /******************************************************************************* * * FUNCTION: acpi_error * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Print "ACPI Error" message with module/line/version info * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_error(const char *module_name, u32 line_number, const char *format, ...) { va_list arg_list; ACPI_MSG_REDIRECT_BEGIN; acpi_os_printf(ACPI_MSG_ERROR); va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); ACPI_MSG_REDIRECT_END; } ACPI_EXPORT_SYMBOL(acpi_error) /******************************************************************************* * * FUNCTION: acpi_exception * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * status - Status value to be decoded/formatted * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Print an "ACPI Error" message with module/line/version * info as well as decoded acpi_status. * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_exception(const char *module_name, u32 line_number, acpi_status status, const char *format, ...) { va_list arg_list; ACPI_MSG_REDIRECT_BEGIN; /* For AE_OK, just print the message */ if (ACPI_SUCCESS(status)) { acpi_os_printf(ACPI_MSG_ERROR); } else { acpi_os_printf(ACPI_MSG_ERROR "%s, ", acpi_format_exception(status)); } va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); ACPI_MSG_REDIRECT_END; } ACPI_EXPORT_SYMBOL(acpi_exception) /******************************************************************************* * * FUNCTION: acpi_warning * * PARAMETERS: module_name - Caller's module name (for warning output) * line_number - Caller's line number (for warning output) * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Print "ACPI Warning" message with module/line/version info * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_warning(const char *module_name, u32 line_number, const char *format, ...) { va_list arg_list; ACPI_MSG_REDIRECT_BEGIN; acpi_os_printf(ACPI_MSG_WARNING); va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); ACPI_MSG_REDIRECT_END; } ACPI_EXPORT_SYMBOL(acpi_warning) /******************************************************************************* * * FUNCTION: acpi_info * * PARAMETERS: format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Print generic "ACPI:" information message. There is no * module/line/version info in order to keep the message simple. * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_info(const char *format, ...) { va_list arg_list; ACPI_MSG_REDIRECT_BEGIN; acpi_os_printf(ACPI_MSG_INFO); va_start(arg_list, format); acpi_os_vprintf(format, arg_list); acpi_os_printf("\n"); va_end(arg_list); ACPI_MSG_REDIRECT_END; } ACPI_EXPORT_SYMBOL(acpi_info) /******************************************************************************* * * FUNCTION: acpi_bios_error * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Print "ACPI Firmware Error" message with module/line/version * info * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_bios_error(const char *module_name, u32 line_number, const char *format, ...) { va_list arg_list; ACPI_MSG_REDIRECT_BEGIN; acpi_os_printf(ACPI_MSG_BIOS_ERROR); va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); ACPI_MSG_REDIRECT_END; } ACPI_EXPORT_SYMBOL(acpi_bios_error) /******************************************************************************* * * FUNCTION: acpi_bios_exception * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * status - Status value to be decoded/formatted * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Print an "ACPI Firmware Error" message with module/line/version * info as well as decoded acpi_status. * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_bios_exception(const char *module_name, u32 line_number, acpi_status status, const char *format, ...) { va_list arg_list; ACPI_MSG_REDIRECT_BEGIN; /* For AE_OK, just print the message */ if (ACPI_SUCCESS(status)) { acpi_os_printf(ACPI_MSG_BIOS_ERROR); } else { acpi_os_printf(ACPI_MSG_BIOS_ERROR "%s, ", acpi_format_exception(status)); } va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); ACPI_MSG_REDIRECT_END; } ACPI_EXPORT_SYMBOL(acpi_bios_exception) /******************************************************************************* * * FUNCTION: acpi_bios_warning * * PARAMETERS: module_name - Caller's module name (for warning output) * line_number - Caller's line number (for warning output) * format - Printf format string + additional args * * RETURN: None * * DESCRIPTION: Print "ACPI Firmware Warning" message with module/line/version * info * ******************************************************************************/ void ACPI_INTERNAL_VAR_XFACE acpi_bios_warning(const char *module_name, u32 line_number, const char *format, ...) { va_list arg_list; ACPI_MSG_REDIRECT_BEGIN; acpi_os_printf(ACPI_MSG_BIOS_WARNING); va_start(arg_list, format); acpi_os_vprintf(format, arg_list); ACPI_MSG_SUFFIX; va_end(arg_list); ACPI_MSG_REDIRECT_END; } ACPI_EXPORT_SYMBOL(acpi_bios_warning) #endif /* ACPI_NO_ERROR_MESSAGES */
linux-master
drivers/acpi/acpica/utxferror.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dswload2 - Dispatcher second pass namespace load callbacks * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "amlcode.h" #include "acdispat.h" #include "acinterp.h" #include "acnamesp.h" #include "acevents.h" #ifdef ACPI_EXEC_APP #include "aecommon.h" #endif #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dswload2") /******************************************************************************* * * FUNCTION: acpi_ds_load2_begin_op * * PARAMETERS: walk_state - Current state of the parse tree walk * out_op - Where to return op if a new one is created * * RETURN: Status * * DESCRIPTION: Descending callback used during the loading of ACPI tables. * ******************************************************************************/ acpi_status acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state, union acpi_parse_object **out_op) { union acpi_parse_object *op; struct acpi_namespace_node *node; acpi_status status; acpi_object_type object_type; char *buffer_ptr; u32 flags; ACPI_FUNCTION_TRACE(ds_load2_begin_op); op = walk_state->op; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state)); if (op) { if ((walk_state->control_state) && (walk_state->control_state->common.state == ACPI_CONTROL_CONDITIONAL_EXECUTING)) { /* We are executing a while loop outside of a method */ status = acpi_ds_exec_begin_op(walk_state, out_op); return_ACPI_STATUS(status); } /* We only care about Namespace opcodes here */ if ((!(walk_state->op_info->flags & AML_NSOPCODE) && (walk_state->opcode != AML_INT_NAMEPATH_OP)) || (!(walk_state->op_info->flags & AML_NAMED))) { return_ACPI_STATUS(AE_OK); } /* Get the name we are going to enter or lookup in the namespace */ if (walk_state->opcode == AML_INT_NAMEPATH_OP) { /* For Namepath op, get the path string */ buffer_ptr = op->common.value.string; if (!buffer_ptr) { /* No name, just exit */ return_ACPI_STATUS(AE_OK); } } else { /* Get name from the op */ buffer_ptr = ACPI_CAST_PTR(char, &op->named.name); } } else { /* Get the namestring from the raw AML */ buffer_ptr = acpi_ps_get_next_namestring(&walk_state->parser_state); } /* Map the opcode into an internal object type */ object_type = walk_state->op_info->object_type; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "State=%p Op=%p Type=%X\n", walk_state, op, object_type)); switch (walk_state->opcode) { case AML_FIELD_OP: case AML_BANK_FIELD_OP: case AML_INDEX_FIELD_OP: node = NULL; status = AE_OK; break; case AML_INT_NAMEPATH_OP: /* * The name_path is an object reference to an existing object. * Don't enter the name into the namespace, but look it up * for use later. */ status = acpi_ns_lookup(walk_state->scope_info, buffer_ptr, object_type, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); break; case AML_SCOPE_OP: /* Special case for Scope(\) -> refers to the Root node */ if (op && (op->named.node == acpi_gbl_root_node)) { node = op->named.node; status = acpi_ds_scope_stack_push(node, object_type, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } else { /* * The Path is an object reference to an existing object. * Don't enter the name into the namespace, but look it up * for use later. */ status = acpi_ns_lookup(walk_state->scope_info, buffer_ptr, object_type, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); if (ACPI_FAILURE(status)) { #ifdef ACPI_ASL_COMPILER if (status == AE_NOT_FOUND) { status = AE_OK; } else { ACPI_ERROR_NAMESPACE(walk_state-> scope_info, buffer_ptr, status); } #else ACPI_ERROR_NAMESPACE(walk_state->scope_info, buffer_ptr, status); #endif return_ACPI_STATUS(status); } } /* * We must check to make sure that the target is * one of the opcodes that actually opens a scope */ switch (node->type) { case ACPI_TYPE_ANY: case ACPI_TYPE_LOCAL_SCOPE: /* Scope */ case ACPI_TYPE_DEVICE: case ACPI_TYPE_POWER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: /* These are acceptable types */ break; case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* * These types we will allow, but we will change the type. * This enables some existing code of the form: * * Name (DEB, 0) * Scope (DEB) { ... } */ ACPI_WARNING((AE_INFO, "Type override - [%4.4s] had invalid type (%s) " "for Scope operator, changed to type ANY", acpi_ut_get_node_name(node), acpi_ut_get_type_name(node->type))); node->type = ACPI_TYPE_ANY; walk_state->scope_info->common.value = ACPI_TYPE_ANY; break; case ACPI_TYPE_METHOD: /* * Allow scope change to root during execution of module-level * code. Root is typed METHOD during this time. */ if ((node == acpi_gbl_root_node) && (walk_state-> parse_flags & ACPI_PARSE_MODULE_LEVEL)) { break; } ACPI_FALLTHROUGH; default: /* All other types are an error */ ACPI_ERROR((AE_INFO, "Invalid type (%s) for target of " "Scope operator [%4.4s] (Cannot override)", acpi_ut_get_type_name(node->type), acpi_ut_get_node_name(node))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } break; default: /* All other opcodes */ if (op && op->common.node) { /* This op/node was previously entered into the namespace */ node = op->common.node; if (acpi_ns_opens_scope(object_type)) { status = acpi_ds_scope_stack_push(node, object_type, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } return_ACPI_STATUS(AE_OK); } /* * Enter the named type into the internal namespace. We enter the name * as we go downward in the parse tree. Any necessary subobjects that * involve arguments to the opcode must be created as we go back up the * parse tree later. * * Note: Name may already exist if we are executing a deferred opcode. */ if (walk_state->deferred_node) { /* This name is already in the namespace, get the node */ node = walk_state->deferred_node; status = AE_OK; break; } flags = ACPI_NS_NO_UPSEARCH; if (walk_state->pass_number == ACPI_IMODE_EXECUTE) { /* Execution mode, node cannot already exist, node is temporary */ flags |= ACPI_NS_ERROR_IF_FOUND; if (! (walk_state-> parse_flags & ACPI_PARSE_MODULE_LEVEL)) { flags |= ACPI_NS_TEMPORARY; } } #ifdef ACPI_ASL_COMPILER /* * Do not open a scope for AML_EXTERNAL_OP * acpi_ns_lookup can open a new scope based on the object type * of this op. AML_EXTERNAL_OP is a declaration rather than a * definition. In the case that this external is a method object, * acpi_ns_lookup will open a new scope. However, an AML_EXTERNAL_OP * associated with the ACPI_TYPE_METHOD is a declaration, rather than * a definition. Flags is set to avoid opening a scope for any * AML_EXTERNAL_OP. */ if (walk_state->opcode == AML_EXTERNAL_OP) { flags |= ACPI_NS_DONT_OPEN_SCOPE; } #endif /* * For name creation opcodes, the full namepath prefix must * exist, except for the final (new) nameseg. */ if (walk_state->op_info->flags & AML_NAMED) { flags |= ACPI_NS_PREFIX_MUST_EXIST; } /* Add new entry or lookup existing entry */ status = acpi_ns_lookup(walk_state->scope_info, buffer_ptr, object_type, ACPI_IMODE_LOAD_PASS2, flags, walk_state, &node); if (ACPI_SUCCESS(status) && (flags & ACPI_NS_TEMPORARY)) { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "***New Node [%4.4s] %p is temporary\n", acpi_ut_get_node_name(node), node)); } break; } if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(walk_state->scope_info, buffer_ptr, status); return_ACPI_STATUS(status); } if (!op) { /* Create a new op */ op = acpi_ps_alloc_op(walk_state->opcode, walk_state->aml); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Initialize the new op */ if (node) { op->named.name = node->name.integer; } *out_op = op; } /* * Put the Node in the "op" object that the parser uses, so we * can get it again quickly when this scope is closed */ op->common.node = node; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_load2_end_op * * PARAMETERS: walk_state - Current state of the parse tree walk * * RETURN: Status * * DESCRIPTION: Ascending callback used during the loading of the namespace, * both control methods and everything else. * ******************************************************************************/ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state) { union acpi_parse_object *op; acpi_status status = AE_OK; acpi_object_type object_type; struct acpi_namespace_node *node; union acpi_parse_object *arg; struct acpi_namespace_node *new_node; u32 i; u8 region_space; #ifdef ACPI_EXEC_APP union acpi_operand_object *obj_desc; char *namepath; #endif ACPI_FUNCTION_TRACE(ds_load2_end_op); op = walk_state->op; ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n", walk_state->op_info->name, op, walk_state)); /* Check if opcode had an associated namespace object */ if (!(walk_state->op_info->flags & AML_NSOBJECT)) { return_ACPI_STATUS(AE_OK); } if (op->common.aml_opcode == AML_SCOPE_OP) { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Ending scope Op=%p State=%p\n", op, walk_state)); } object_type = walk_state->op_info->object_type; /* * Get the Node/name from the earlier lookup * (It was saved in the *op structure) */ node = op->common.node; /* * Put the Node on the object stack (Contains the ACPI Name of * this object) */ walk_state->operands[0] = (void *)node; walk_state->num_operands = 1; /* Pop the scope stack */ if (acpi_ns_opens_scope(object_type) && (op->common.aml_opcode != AML_INT_METHODCALL_OP)) { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n", acpi_ut_get_type_name(object_type), op)); status = acpi_ds_scope_stack_pop(walk_state); if (ACPI_FAILURE(status)) { goto cleanup; } } /* * Named operations are as follows: * * AML_ALIAS * AML_BANKFIELD * AML_CREATEBITFIELD * AML_CREATEBYTEFIELD * AML_CREATEDWORDFIELD * AML_CREATEFIELD * AML_CREATEQWORDFIELD * AML_CREATEWORDFIELD * AML_DATA_REGION * AML_DEVICE * AML_EVENT * AML_FIELD * AML_INDEXFIELD * AML_METHOD * AML_METHODCALL * AML_MUTEX * AML_NAME * AML_NAMEDFIELD * AML_OPREGION * AML_POWERRES * AML_PROCESSOR * AML_SCOPE * AML_THERMALZONE */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Create-Load [%s] State=%p Op=%p NamedObj=%p\n", acpi_ps_get_opcode_name(op->common.aml_opcode), walk_state, op, node)); /* Decode the opcode */ arg = op->common.value.arg; switch (walk_state->op_info->type) { case AML_TYPE_CREATE_FIELD: /* * Create the field object, but the field buffer and index must * be evaluated later during the execution phase */ status = acpi_ds_create_buffer_field(op, walk_state); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "CreateBufferField failure")); goto cleanup; } break; case AML_TYPE_NAMED_FIELD: /* * If we are executing a method, initialize the field */ if (walk_state->method_node) { status = acpi_ds_init_field_objects(op, walk_state); } switch (op->common.aml_opcode) { case AML_INDEX_FIELD_OP: status = acpi_ds_create_index_field(op, (acpi_handle)arg->common. node, walk_state); break; case AML_BANK_FIELD_OP: status = acpi_ds_create_bank_field(op, arg->common.node, walk_state); break; case AML_FIELD_OP: status = acpi_ds_create_field(op, arg->common.node, walk_state); break; default: /* All NAMED_FIELD opcodes must be handled above */ break; } break; case AML_TYPE_NAMED_SIMPLE: status = acpi_ds_create_operands(walk_state, arg); if (ACPI_FAILURE(status)) { goto cleanup; } switch (op->common.aml_opcode) { case AML_PROCESSOR_OP: status = acpi_ex_create_processor(walk_state); break; case AML_POWER_RESOURCE_OP: status = acpi_ex_create_power_resource(walk_state); break; case AML_MUTEX_OP: status = acpi_ex_create_mutex(walk_state); break; case AML_EVENT_OP: status = acpi_ex_create_event(walk_state); break; case AML_ALIAS_OP: status = acpi_ex_create_alias(walk_state); break; default: /* Unknown opcode */ status = AE_OK; goto cleanup; } /* Delete operands */ for (i = 1; i < walk_state->num_operands; i++) { acpi_ut_remove_reference(walk_state->operands[i]); walk_state->operands[i] = NULL; } break; case AML_TYPE_NAMED_COMPLEX: switch (op->common.aml_opcode) { case AML_REGION_OP: case AML_DATA_REGION_OP: if (op->common.aml_opcode == AML_REGION_OP) { region_space = (acpi_adr_space_type) ((op->common.value.arg)->common.value. integer); } else { region_space = ACPI_ADR_SPACE_DATA_TABLE; } /* * The op_region is not fully parsed at this time. The only valid * argument is the space_id. (We must save the address of the * AML of the address and length operands) * * If we have a valid region, initialize it. The namespace is * unlocked at this point. * * Need to unlock interpreter if it is locked (if we are running * a control method), in order to allow _REG methods to be run * during acpi_ev_initialize_region. */ if (walk_state->method_node) { /* * Executing a method: initialize the region and unlock * the interpreter */ status = acpi_ex_create_region(op->named.data, op->named.length, region_space, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } status = acpi_ev_initialize_region (acpi_ns_get_attached_object(node)); break; case AML_NAME_OP: status = acpi_ds_create_node(walk_state, node, op); if (ACPI_FAILURE(status)) { goto cleanup; } #ifdef ACPI_EXEC_APP /* * acpi_exec support for namespace initialization file (initialize * Name opcodes in this code.) */ namepath = acpi_ns_get_external_pathname(node); status = ae_lookup_init_file_entry(namepath, &obj_desc); if (ACPI_SUCCESS(status)) { /* Detach any existing object, attach new object */ if (node->object) { acpi_ns_detach_object(node); } acpi_ns_attach_object(node, obj_desc, obj_desc->common.type); } ACPI_FREE(namepath); status = AE_OK; #endif break; case AML_METHOD_OP: /* * method_op pkg_length name_string method_flags term_list * * Note: We must create the method node/object pair as soon as we * see the method declaration. This allows later pass1 parsing * of invocations of the method (need to know the number of * arguments.) */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "LOADING-Method: State=%p Op=%p NamedObj=%p\n", walk_state, op, op->named.node)); if (!acpi_ns_get_attached_object(op->named.node)) { walk_state->operands[0] = ACPI_CAST_PTR(void, op->named.node); walk_state->num_operands = 1; status = acpi_ds_create_operands(walk_state, op->common.value. arg); if (ACPI_SUCCESS(status)) { status = acpi_ex_create_method(op->named. data, op->named. length, walk_state); } walk_state->operands[0] = NULL; walk_state->num_operands = 0; if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } break; default: /* All NAMED_COMPLEX opcodes must be handled above */ break; } break; case AML_CLASS_INTERNAL: /* case AML_INT_NAMEPATH_OP: */ break; case AML_CLASS_METHOD_CALL: ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n", walk_state, op, node)); /* * Lookup the method name and save the Node */ status = acpi_ns_lookup(walk_state->scope_info, arg->common.value.string, ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, walk_state, &(new_node)); if (ACPI_SUCCESS(status)) { /* * Make sure that what we found is indeed a method * We didn't search for a method on purpose, to see if the name * would resolve */ if (new_node->type != ACPI_TYPE_METHOD) { status = AE_AML_OPERAND_TYPE; } /* We could put the returned object (Node) on the object stack for * later, but for now, we will put it in the "op" object that the * parser uses, so we can get it again at the end of this scope */ op->common.node = new_node; } else { ACPI_ERROR_NAMESPACE(walk_state->scope_info, arg->common.value.string, status); } break; default: break; } cleanup: /* Remove the Node pushed at the very beginning */ walk_state->operands[0] = NULL; walk_state->num_operands = 0; return_ACPI_STATUS(status); }
linux-master
drivers/acpi/acpica/dswload2.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: dsmthdat - control method arguments and local variables * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acdispat.h" #include "acnamesp.h" #include "acinterp.h" #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dsmthdat") /* Local prototypes */ static void acpi_ds_method_data_delete_value(u8 type, u32 index, struct acpi_walk_state *walk_state); static acpi_status acpi_ds_method_data_set_value(u8 type, u32 index, union acpi_operand_object *object, struct acpi_walk_state *walk_state); #ifdef ACPI_OBSOLETE_FUNCTIONS acpi_object_type acpi_ds_method_data_get_type(u16 opcode, u32 index, struct acpi_walk_state *walk_state); #endif /******************************************************************************* * * FUNCTION: acpi_ds_method_data_init * * PARAMETERS: walk_state - Current walk state object * * RETURN: Status * * DESCRIPTION: Initialize the data structures that hold the method's arguments * and locals. The data struct is an array of namespace nodes for * each - this allows ref_of and de_ref_of to work properly for these * special data types. * * NOTES: walk_state fields are initialized to zero by the * ACPI_ALLOCATE_ZEROED(). * * A pseudo-Namespace Node is assigned to each argument and local * so that ref_of() can return a pointer to the Node. * ******************************************************************************/ void acpi_ds_method_data_init(struct acpi_walk_state *walk_state) { u32 i; ACPI_FUNCTION_TRACE(ds_method_data_init); /* Init the method arguments */ for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) { ACPI_MOVE_32_TO_32(&walk_state->arguments[i].name, NAMEOF_ARG_NTE); walk_state->arguments[i].name.integer |= (i << 24); walk_state->arguments[i].descriptor_type = ACPI_DESC_TYPE_NAMED; walk_state->arguments[i].type = ACPI_TYPE_ANY; walk_state->arguments[i].flags = ANOBJ_METHOD_ARG; } /* Init the method locals */ for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) { ACPI_MOVE_32_TO_32(&walk_state->local_variables[i].name, NAMEOF_LOCAL_NTE); walk_state->local_variables[i].name.integer |= (i << 24); walk_state->local_variables[i].descriptor_type = ACPI_DESC_TYPE_NAMED; walk_state->local_variables[i].type = ACPI_TYPE_ANY; walk_state->local_variables[i].flags = ANOBJ_METHOD_LOCAL; } return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ds_method_data_delete_all * * PARAMETERS: walk_state - Current walk state object * * RETURN: None * * DESCRIPTION: Delete method locals and arguments. Arguments are only * deleted if this method was called from another method. * ******************************************************************************/ void acpi_ds_method_data_delete_all(struct acpi_walk_state *walk_state) { u32 index; ACPI_FUNCTION_TRACE(ds_method_data_delete_all); /* Detach the locals */ for (index = 0; index < ACPI_METHOD_NUM_LOCALS; index++) { if (walk_state->local_variables[index].object) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Local%u=%p\n", index, walk_state->local_variables[index]. object)); /* Detach object (if present) and remove a reference */ acpi_ns_detach_object(&walk_state-> local_variables[index]); } } /* Detach the arguments */ for (index = 0; index < ACPI_METHOD_NUM_ARGS; index++) { if (walk_state->arguments[index].object) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Arg%u=%p\n", index, walk_state->arguments[index].object)); /* Detach object (if present) and remove a reference */ acpi_ns_detach_object(&walk_state->arguments[index]); } } return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ds_method_data_init_args * * PARAMETERS: *params - Pointer to a parameter list for the method * max_param_count - The arg count for this method * walk_state - Current walk state object * * RETURN: Status * * DESCRIPTION: Initialize arguments for a method. The parameter list is a list * of ACPI operand objects, either null terminated or whose length * is defined by max_param_count. * ******************************************************************************/ acpi_status acpi_ds_method_data_init_args(union acpi_operand_object **params, u32 max_param_count, struct acpi_walk_state *walk_state) { acpi_status status; u32 index = 0; ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args, params); if (!params) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "No parameter list passed to method\n")); return_ACPI_STATUS(AE_OK); } /* Copy passed parameters into the new method stack frame */ while ((index < ACPI_METHOD_NUM_ARGS) && (index < max_param_count) && params[index]) { /* * A valid parameter. * Store the argument in the method/walk descriptor. * Do not copy the arg in order to implement call by reference */ status = acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG, index, params[index], walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } index++; } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%u args passed to method\n", index)); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_method_data_get_node * * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or * ACPI_REFCLASS_ARG * index - Which Local or Arg whose type to get * walk_state - Current walk state object * node - Where the node is returned. * * RETURN: Status and node * * DESCRIPTION: Get the Node associated with a local or arg. * ******************************************************************************/ acpi_status acpi_ds_method_data_get_node(u8 type, u32 index, struct acpi_walk_state *walk_state, struct acpi_namespace_node **node) { ACPI_FUNCTION_TRACE(ds_method_data_get_node); /* * Method Locals and Arguments are supported */ switch (type) { case ACPI_REFCLASS_LOCAL: if (index > ACPI_METHOD_MAX_LOCAL) { ACPI_ERROR((AE_INFO, "Local index %u is invalid (max %u)", index, ACPI_METHOD_MAX_LOCAL)); return_ACPI_STATUS(AE_AML_INVALID_INDEX); } /* Return a pointer to the pseudo-node */ *node = &walk_state->local_variables[index]; break; case ACPI_REFCLASS_ARG: if (index > ACPI_METHOD_MAX_ARG) { ACPI_ERROR((AE_INFO, "Arg index %u is invalid (max %u)", index, ACPI_METHOD_MAX_ARG)); return_ACPI_STATUS(AE_AML_INVALID_INDEX); } /* Return a pointer to the pseudo-node */ *node = &walk_state->arguments[index]; break; default: ACPI_ERROR((AE_INFO, "Type %u is invalid", type)); return_ACPI_STATUS(AE_TYPE); } return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_method_data_set_value * * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or * ACPI_REFCLASS_ARG * index - Which Local or Arg to get * object - Object to be inserted into the stack entry * walk_state - Current walk state object * * RETURN: Status * * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index. * Note: There is no "implicit conversion" for locals. * ******************************************************************************/ static acpi_status acpi_ds_method_data_set_value(u8 type, u32 index, union acpi_operand_object *object, struct acpi_walk_state *walk_state) { acpi_status status; struct acpi_namespace_node *node; ACPI_FUNCTION_TRACE(ds_method_data_set_value); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "NewObj %p Type %2.2X, Refs=%u [%s]\n", object, type, object->common.reference_count, acpi_ut_get_type_name(object->common.type))); /* Get the namespace node for the arg/local */ status = acpi_ds_method_data_get_node(type, index, walk_state, &node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Increment ref count so object can't be deleted while installed. * NOTE: We do not copy the object in order to preserve the call by * reference semantics of ACPI Control Method invocation. * (See ACPI Specification 2.0C) */ acpi_ut_add_reference(object); /* Install the object */ node->object = object; return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_method_data_get_value * * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or * ACPI_REFCLASS_ARG * index - Which localVar or argument to get * walk_state - Current walk state object * dest_desc - Where Arg or Local value is returned * * RETURN: Status * * DESCRIPTION: Retrieve value of selected Arg or Local for this method * Used only in acpi_ex_resolve_to_value(). * ******************************************************************************/ acpi_status acpi_ds_method_data_get_value(u8 type, u32 index, struct acpi_walk_state *walk_state, union acpi_operand_object **dest_desc) { acpi_status status; struct acpi_namespace_node *node; union acpi_operand_object *object; ACPI_FUNCTION_TRACE(ds_method_data_get_value); /* Validate the object descriptor */ if (!dest_desc) { ACPI_ERROR((AE_INFO, "Null object descriptor pointer")); return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Get the namespace node for the arg/local */ status = acpi_ds_method_data_get_node(type, index, walk_state, &node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Get the object from the node */ object = node->object; /* Examine the returned object, it must be valid. */ if (!object) { /* * Index points to uninitialized object. * This means that either 1) The expected argument was * not passed to the method, or 2) A local variable * was referenced by the method (via the ASL) * before it was initialized. Either case is an error. */ /* If slack enabled, init the local_x/arg_x to an Integer of value zero */ if (acpi_gbl_enable_interpreter_slack) { object = acpi_ut_create_integer_object((u64) 0); if (!object) { return_ACPI_STATUS(AE_NO_MEMORY); } node->object = object; } /* Otherwise, return the error */ else switch (type) { case ACPI_REFCLASS_ARG: ACPI_ERROR((AE_INFO, "Uninitialized Arg[%u] at node %p", index, node)); return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG); case ACPI_REFCLASS_LOCAL: /* * No error message for this case, will be trapped again later to * detect and ignore cases of Store(local_x,local_x) */ return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL); default: ACPI_ERROR((AE_INFO, "Not a Arg/Local opcode: 0x%X", type)); return_ACPI_STATUS(AE_AML_INTERNAL); } } /* * The Index points to an initialized and valid object. * Return an additional reference to the object */ *dest_desc = object; acpi_ut_add_reference(object); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_method_data_delete_value * * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or * ACPI_REFCLASS_ARG * index - Which localVar or argument to delete * walk_state - Current walk state object * * RETURN: None * * DESCRIPTION: Delete the entry at Opcode:Index. Inserts * a null into the stack slot after the object is deleted. * ******************************************************************************/ static void acpi_ds_method_data_delete_value(u8 type, u32 index, struct acpi_walk_state *walk_state) { acpi_status status; struct acpi_namespace_node *node; union acpi_operand_object *object; ACPI_FUNCTION_TRACE(ds_method_data_delete_value); /* Get the namespace node for the arg/local */ status = acpi_ds_method_data_get_node(type, index, walk_state, &node); if (ACPI_FAILURE(status)) { return_VOID; } /* Get the associated object */ object = acpi_ns_get_attached_object(node); /* * Undefine the Arg or Local by setting its descriptor * pointer to NULL. Locals/Args can contain both * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs */ node->object = NULL; if ((object) && (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_OPERAND)) { /* * There is a valid object. * Decrement the reference count by one to balance the * increment when the object was stored. */ acpi_ut_remove_reference(object); } return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ds_store_object_to_local * * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or * ACPI_REFCLASS_ARG * index - Which Local or Arg to set * obj_desc - Value to be stored * walk_state - Current walk state * * RETURN: Status * * DESCRIPTION: Store a value in an Arg or Local. The obj_desc is installed * as the new value for the Arg or Local and the reference count * for obj_desc is incremented. * ******************************************************************************/ acpi_status acpi_ds_store_object_to_local(u8 type, u32 index, union acpi_operand_object *obj_desc, struct acpi_walk_state *walk_state) { acpi_status status; struct acpi_namespace_node *node; union acpi_operand_object *current_obj_desc; union acpi_operand_object *new_obj_desc; ACPI_FUNCTION_TRACE(ds_store_object_to_local); ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n", type, index, obj_desc)); /* Parameter validation */ if (!obj_desc) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Get the namespace node for the arg/local */ status = acpi_ds_method_data_get_node(type, index, walk_state, &node); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } current_obj_desc = acpi_ns_get_attached_object(node); if (current_obj_desc == obj_desc) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p already installed!\n", obj_desc)); return_ACPI_STATUS(status); } /* * If the reference count on the object is more than one, we must * take a copy of the object before we store. A reference count * of exactly 1 means that the object was just created during the * evaluation of an expression, and we can safely use it since it * is not used anywhere else. */ new_obj_desc = obj_desc; if (obj_desc->common.reference_count > 1) { status = acpi_ut_copy_iobject_to_iobject(obj_desc, &new_obj_desc, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } /* * If there is an object already in this slot, we either * have to delete it, or if this is an argument and there * is an object reference stored there, we have to do * an indirect store! */ if (current_obj_desc) { /* * Check for an indirect store if an argument * contains an object reference (stored as an Node). * We don't allow this automatic dereferencing for * locals, since a store to a local should overwrite * anything there, including an object reference. * * If both Arg0 and Local0 contain ref_of (Local4): * * Store (1, Arg0) - Causes indirect store to local4 * Store (1, Local0) - Stores 1 in local0, overwriting * the reference to local4 * Store (1, de_refof (Local0)) - Causes indirect store to local4 * * Weird, but true. */ if (type == ACPI_REFCLASS_ARG) { /* * If we have a valid reference object that came from ref_of(), * do the indirect store */ if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc) == ACPI_DESC_TYPE_OPERAND) && (current_obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) && (current_obj_desc->reference.class == ACPI_REFCLASS_REFOF)) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Arg (%p) is an ObjRef(Node), storing in node %p\n", new_obj_desc, current_obj_desc)); /* * Store this object to the Node (perform the indirect store) * NOTE: No implicit conversion is performed, as per the ACPI * specification rules on storing to Locals/Args. */ status = acpi_ex_store_object_to_node(new_obj_desc, current_obj_desc-> reference. object, walk_state, ACPI_NO_IMPLICIT_CONVERSION); /* Remove local reference if we copied the object above */ if (new_obj_desc != obj_desc) { acpi_ut_remove_reference(new_obj_desc); } return_ACPI_STATUS(status); } } /* Delete the existing object before storing the new one */ acpi_ds_method_data_delete_value(type, index, walk_state); } /* * Install the Obj descriptor (*new_obj_desc) into * the descriptor for the Arg or Local. * (increments the object reference count by one) */ status = acpi_ds_method_data_set_value(type, index, new_obj_desc, walk_state); /* Remove local reference if we copied the object above */ if (new_obj_desc != obj_desc) { acpi_ut_remove_reference(new_obj_desc); } return_ACPI_STATUS(status); } #ifdef ACPI_OBSOLETE_FUNCTIONS /******************************************************************************* * * FUNCTION: acpi_ds_method_data_get_type * * PARAMETERS: opcode - Either AML_FIRST LOCAL_OP or * AML_FIRST_ARG_OP * index - Which Local or Arg whose type to get * walk_state - Current walk state object * * RETURN: Data type of current value of the selected Arg or Local * * DESCRIPTION: Get the type of the object stored in the Local or Arg * ******************************************************************************/ acpi_object_type acpi_ds_method_data_get_type(u16 opcode, u32 index, struct acpi_walk_state *walk_state) { acpi_status status; struct acpi_namespace_node *node; union acpi_operand_object *object; ACPI_FUNCTION_TRACE(ds_method_data_get_type); /* Get the namespace node for the arg/local */ status = acpi_ds_method_data_get_node(opcode, index, walk_state, &node); if (ACPI_FAILURE(status)) { return_VALUE((ACPI_TYPE_NOT_FOUND)); } /* Get the object */ object = acpi_ns_get_attached_object(node); if (!object) { /* Uninitialized local/arg, return TYPE_ANY */ return_VALUE(ACPI_TYPE_ANY); } /* Get the object type */ return_VALUE(object->type); } #endif
linux-master
drivers/acpi/acpica/dsmthdat.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: nsload - namespace loading/expanding/contracting procedures * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acnamesp.h" #include "acdispat.h" #include "actables.h" #include "acinterp.h" #define _COMPONENT ACPI_NAMESPACE ACPI_MODULE_NAME("nsload") /* Local prototypes */ #ifdef ACPI_FUTURE_IMPLEMENTATION acpi_status acpi_ns_unload_namespace(acpi_handle handle); static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle); #endif /******************************************************************************* * * FUNCTION: acpi_ns_load_table * * PARAMETERS: table_index - Index for table to be loaded * node - Owning NS node * * RETURN: Status * * DESCRIPTION: Load one ACPI table into the namespace * ******************************************************************************/ acpi_status acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node) { acpi_status status; ACPI_FUNCTION_TRACE(ns_load_table); /* If table already loaded into namespace, just return */ if (acpi_tb_is_table_loaded(table_index)) { status = AE_ALREADY_EXISTS; goto unlock; } ACPI_DEBUG_PRINT((ACPI_DB_INFO, "**** Loading table into namespace ****\n")); status = acpi_tb_allocate_owner_id(table_index); if (ACPI_FAILURE(status)) { goto unlock; } /* * Parse the table and load the namespace with all named * objects found within. Control methods are NOT parsed * at this time. In fact, the control methods cannot be * parsed until the entire namespace is loaded, because * if a control method makes a forward reference (call) * to another control method, we can't continue parsing * because we don't know how many arguments to parse next! */ status = acpi_ns_parse_table(table_index, node); if (ACPI_SUCCESS(status)) { acpi_tb_set_table_loaded_flag(table_index, TRUE); } else { /* * On error, delete any namespace objects created by this table. * We cannot initialize these objects, so delete them. There are * a couple of especially bad cases: * AE_ALREADY_EXISTS - namespace collision. * AE_NOT_FOUND - the target of a Scope operator does not * exist. This target of Scope must already exist in the * namespace, as per the ACPI specification. */ acpi_ns_delete_namespace_by_owner(acpi_gbl_root_table_list. tables[table_index].owner_id); acpi_tb_release_owner_id(table_index); return_ACPI_STATUS(status); } unlock: if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Now we can parse the control methods. We always parse * them here for a sanity check, and if configured for * just-in-time parsing, we delete the control method * parse trees. */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, "**** Begin Table Object Initialization\n")); acpi_ex_enter_interpreter(); status = acpi_ds_initialize_objects(table_index, node); acpi_ex_exit_interpreter(); ACPI_DEBUG_PRINT((ACPI_DB_INFO, "**** Completed Table Object Initialization\n")); return_ACPI_STATUS(status); } #ifdef ACPI_OBSOLETE_FUNCTIONS /******************************************************************************* * * FUNCTION: acpi_load_namespace * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Load the name space from what ever is pointed to by DSDT. * (DSDT points to either the BIOS or a buffer.) * ******************************************************************************/ acpi_status acpi_ns_load_namespace(void) { acpi_status status; ACPI_FUNCTION_TRACE(acpi_load_name_space); /* There must be at least a DSDT installed */ if (acpi_gbl_DSDT == NULL) { ACPI_ERROR((AE_INFO, "DSDT is not in memory")); return_ACPI_STATUS(AE_NO_ACPI_TABLES); } /* * Load the namespace. The DSDT is required, * but the SSDT and PSDT tables are optional. */ status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Ignore exceptions from these */ (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT); (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT); ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "ACPI Namespace successfully loaded at root %p\n", acpi_gbl_root_node)); return_ACPI_STATUS(status); } #endif #ifdef ACPI_FUTURE_IMPLEMENTATION /******************************************************************************* * * FUNCTION: acpi_ns_delete_subtree * * PARAMETERS: start_handle - Handle in namespace where search begins * * RETURNS Status * * DESCRIPTION: Walks the namespace starting at the given handle and deletes * all objects, entries, and scopes in the entire subtree. * * Namespace/Interpreter should be locked or the subsystem should * be in shutdown before this routine is called. * ******************************************************************************/ static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle) { acpi_status status; acpi_handle child_handle; acpi_handle parent_handle; acpi_handle next_child_handle; acpi_handle dummy; u32 level; ACPI_FUNCTION_TRACE(ns_delete_subtree); parent_handle = start_handle; child_handle = NULL; level = 1; /* * Traverse the tree of objects until we bubble back up * to where we started. */ while (level > 0) { /* Attempt to get the next object in this scope */ status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle, child_handle, &next_child_handle); child_handle = next_child_handle; /* Did we get a new object? */ if (ACPI_SUCCESS(status)) { /* Check if this object has any children */ if (ACPI_SUCCESS (acpi_get_next_object (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) { /* * There is at least one child of this object, * visit the object */ level++; parent_handle = child_handle; child_handle = NULL; } } else { /* * No more children in this object, go back up to * the object's parent */ level--; /* Delete all children now */ acpi_ns_delete_children(child_handle); child_handle = parent_handle; status = acpi_get_parent(parent_handle, &parent_handle); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } } /* Now delete the starting object, and we are done */ acpi_ns_remove_node(child_handle); return_ACPI_STATUS(AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ns_unload_name_space * * PARAMETERS: handle - Root of namespace subtree to be deleted * * RETURN: Status * * DESCRIPTION: Shrinks the namespace, typically in response to an undocking * event. Deletes an entire subtree starting from (and * including) the given handle. * ******************************************************************************/ acpi_status acpi_ns_unload_namespace(acpi_handle handle) { acpi_status status; ACPI_FUNCTION_TRACE(ns_unload_name_space); /* Parameter validation */ if (!acpi_gbl_root_node) { return_ACPI_STATUS(AE_NO_NAMESPACE); } if (!handle) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* This function does the real work */ status = acpi_ns_delete_subtree(handle); return_ACPI_STATUS(status); } #endif
linux-master
drivers/acpi/acpica/nsload.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: utascii - Utility ascii functions * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" /******************************************************************************* * * FUNCTION: acpi_ut_valid_nameseg * * PARAMETERS: name - The name or table signature to be examined. * Four characters, does not have to be a * NULL terminated string. * * RETURN: TRUE if signature is has 4 valid ACPI characters * * DESCRIPTION: Validate an ACPI table signature. * ******************************************************************************/ u8 acpi_ut_valid_nameseg(char *name) { u32 i; /* Validate each character in the signature */ for (i = 0; i < ACPI_NAMESEG_SIZE; i++) { if (!acpi_ut_valid_name_char(name[i], i)) { return (FALSE); } } return (TRUE); } /******************************************************************************* * * FUNCTION: acpi_ut_valid_name_char * * PARAMETERS: char - The character to be examined * position - Byte position (0-3) * * RETURN: TRUE if the character is valid, FALSE otherwise * * DESCRIPTION: Check for a valid ACPI character. Must be one of: * 1) Upper case alpha * 2) numeric * 3) underscore * * We allow a '!' as the last character because of the ASF! table * ******************************************************************************/ u8 acpi_ut_valid_name_char(char character, u32 position) { if (!((character >= 'A' && character <= 'Z') || (character >= '0' && character <= '9') || (character == '_'))) { /* Allow a '!' in the last position */ if (character == '!' && position == 3) { return (TRUE); } return (FALSE); } return (TRUE); } /******************************************************************************* * * FUNCTION: acpi_ut_check_and_repair_ascii * * PARAMETERS: name - Ascii string * count - Number of characters to check * * RETURN: None * * DESCRIPTION: Ensure that the requested number of characters are printable * Ascii characters. Sets non-printable and null chars to <space>. * ******************************************************************************/ void acpi_ut_check_and_repair_ascii(u8 *name, char *repaired_name, u32 count) { u32 i; for (i = 0; i < count; i++) { repaired_name[i] = (char)name[i]; if (!name[i]) { return; } if (!isprint(name[i])) { repaired_name[i] = ' '; } } }
linux-master
drivers/acpi/acpica/utascii.c
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /****************************************************************************** * * Module Name: dswstate - Dispatcher parse tree walk management routines * * Copyright (C) 2000 - 2023, Intel Corp. * *****************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #include "acparser.h" #include "acdispat.h" #include "acnamesp.h" #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dswstate") /* Local prototypes */ static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state); static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state); /******************************************************************************* * * FUNCTION: acpi_ds_result_pop * * PARAMETERS: object - Where to return the popped object * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop an object off the top of this walk's result stack * ******************************************************************************/ acpi_status acpi_ds_result_pop(union acpi_operand_object **object, struct acpi_walk_state *walk_state) { u32 index; union acpi_generic_state *state; acpi_status status; ACPI_FUNCTION_NAME(ds_result_pop); state = walk_state->results; /* Incorrect state of result stack */ if (state && !walk_state->result_count) { ACPI_ERROR((AE_INFO, "No results on result stack")); return (AE_AML_INTERNAL); } if (!state && walk_state->result_count) { ACPI_ERROR((AE_INFO, "No result state for result stack")); return (AE_AML_INTERNAL); } /* Empty result stack */ if (!state) { ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p", walk_state)); return (AE_AML_NO_RETURN_VALUE); } /* Return object of the top element and clean that top element result stack */ walk_state->result_count--; index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM; *object = state->results.obj_desc[index]; if (!*object) { ACPI_ERROR((AE_INFO, "No result objects on result stack, State=%p", walk_state)); return (AE_AML_NO_RETURN_VALUE); } state->results.obj_desc[index] = NULL; if (index == 0) { status = acpi_ds_result_stack_pop(walk_state); if (ACPI_FAILURE(status)) { return (status); } } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object, acpi_ut_get_object_type_name(*object), index, walk_state, walk_state->result_count)); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_result_push * * PARAMETERS: object - Where to return the popped object * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Push an object onto the current result stack * ******************************************************************************/ acpi_status acpi_ds_result_push(union acpi_operand_object *object, struct acpi_walk_state *walk_state) { union acpi_generic_state *state; acpi_status status; u32 index; ACPI_FUNCTION_NAME(ds_result_push); if (walk_state->result_count > walk_state->result_size) { ACPI_ERROR((AE_INFO, "Result stack is full")); return (AE_AML_INTERNAL); } else if (walk_state->result_count == walk_state->result_size) { /* Extend the result stack */ status = acpi_ds_result_stack_push(walk_state); if (ACPI_FAILURE(status)) { ACPI_ERROR((AE_INFO, "Failed to extend the result stack")); return (status); } } if (!(walk_state->result_count < walk_state->result_size)) { ACPI_ERROR((AE_INFO, "No free elements in result stack")); return (AE_AML_INTERNAL); } state = walk_state->results; if (!state) { ACPI_ERROR((AE_INFO, "No result stack frame during push")); return (AE_AML_INTERNAL); } if (!object) { ACPI_ERROR((AE_INFO, "Null Object! State=%p Num=%u", walk_state, walk_state->result_count)); return (AE_BAD_PARAMETER); } /* Assign the address of object to the top free element of result stack */ index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM; state->results.obj_desc[index] = object; walk_state->result_count++; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n", object, acpi_ut_get_object_type_name((union acpi_operand_object *) object), walk_state, walk_state->result_count, walk_state->current_result)); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_result_stack_push * * PARAMETERS: walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Push an object onto the walk_state result stack * ******************************************************************************/ static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state) { union acpi_generic_state *state; ACPI_FUNCTION_NAME(ds_result_stack_push); /* Check for stack overflow */ if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) > ACPI_RESULTS_OBJ_NUM_MAX) { ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%u", walk_state, walk_state->result_size)); return (AE_STACK_OVERFLOW); } state = acpi_ut_create_generic_state(); if (!state) { return (AE_NO_MEMORY); } state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT; acpi_ut_push_generic_state(&walk_state->results, state); /* Increase the length of the result stack by the length of frame */ walk_state->result_size += ACPI_RESULTS_FRAME_OBJ_NUM; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n", state, walk_state)); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_result_stack_pop * * PARAMETERS: walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop an object off of the walk_state result stack * ******************************************************************************/ static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state) { union acpi_generic_state *state; ACPI_FUNCTION_NAME(ds_result_stack_pop); /* Check for stack underflow */ if (walk_state->results == NULL) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Result stack underflow - State=%p\n", walk_state)); return (AE_AML_NO_OPERAND); } if (walk_state->result_size < ACPI_RESULTS_FRAME_OBJ_NUM) { ACPI_ERROR((AE_INFO, "Insufficient result stack size")); return (AE_AML_INTERNAL); } state = acpi_ut_pop_generic_state(&walk_state->results); acpi_ut_delete_generic_state(state); /* Decrease the length of result stack by the length of frame */ walk_state->result_size -= ACPI_RESULTS_FRAME_OBJ_NUM; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Result=%p RemainingResults=%X State=%p\n", state, walk_state->result_count, walk_state)); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_obj_stack_push * * PARAMETERS: object - Object to push * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Push an object onto this walk's object/operand stack * ******************************************************************************/ acpi_status acpi_ds_obj_stack_push(void *object, struct acpi_walk_state *walk_state) { ACPI_FUNCTION_NAME(ds_obj_stack_push); /* Check for stack overflow */ if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) { ACPI_ERROR((AE_INFO, "Object stack overflow! Obj=%p State=%p #Ops=%u", object, walk_state, walk_state->num_operands)); return (AE_STACK_OVERFLOW); } /* Put the object onto the stack */ walk_state->operands[walk_state->operand_index] = object; walk_state->num_operands++; /* For the usual order of filling the operand stack */ walk_state->operand_index++; ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n", object, acpi_ut_get_object_type_name((union acpi_operand_object *) object), walk_state, walk_state->num_operands)); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_obj_stack_pop * * PARAMETERS: pop_count - Number of objects/entries to pop * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT * deleted by this routine. * ******************************************************************************/ acpi_status acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state *walk_state) { u32 i; ACPI_FUNCTION_NAME(ds_obj_stack_pop); for (i = 0; i < pop_count; i++) { /* Check for stack underflow */ if (walk_state->num_operands == 0) { ACPI_ERROR((AE_INFO, "Object stack underflow! Count=%X State=%p #Ops=%u", pop_count, walk_state, walk_state->num_operands)); return (AE_STACK_UNDERFLOW); } /* Just set the stack entry to null */ walk_state->num_operands--; walk_state->operands[walk_state->num_operands] = NULL; } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n", pop_count, walk_state, walk_state->num_operands)); return (AE_OK); } /******************************************************************************* * * FUNCTION: acpi_ds_obj_stack_pop_and_delete * * PARAMETERS: pop_count - Number of objects/entries to pop * walk_state - Current Walk state * * RETURN: Status * * DESCRIPTION: Pop this walk's object stack and delete each object that is * popped off. * ******************************************************************************/ void acpi_ds_obj_stack_pop_and_delete(u32 pop_count, struct acpi_walk_state *walk_state) { s32 i; union acpi_operand_object *obj_desc; ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete); if (pop_count == 0) { return; } for (i = (s32)pop_count - 1; i >= 0; i--) { if (walk_state->num_operands == 0) { return; } /* Pop the stack and delete an object if present in this stack entry */ walk_state->num_operands--; obj_desc = walk_state->operands[i]; if (obj_desc) { acpi_ut_remove_reference(walk_state->operands[i]); walk_state->operands[i] = NULL; } } ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n", pop_count, walk_state, walk_state->num_operands)); } /******************************************************************************* * * FUNCTION: acpi_ds_get_current_walk_state * * PARAMETERS: thread - Get current active state for this Thread * * RETURN: Pointer to the current walk state * * DESCRIPTION: Get the walk state that is at the head of the list (the "current" * walk state.) * ******************************************************************************/ struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state *thread) { ACPI_FUNCTION_NAME(ds_get_current_walk_state); if (!thread) { return (NULL); } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n", thread->walk_state_list)); return (thread->walk_state_list); } /******************************************************************************* * * FUNCTION: acpi_ds_push_walk_state * * PARAMETERS: walk_state - State to push * thread - Thread state object * * RETURN: None * * DESCRIPTION: Place the Thread state at the head of the state list * ******************************************************************************/ void acpi_ds_push_walk_state(struct acpi_walk_state *walk_state, struct acpi_thread_state *thread) { ACPI_FUNCTION_TRACE(ds_push_walk_state); walk_state->next = thread->walk_state_list; thread->walk_state_list = walk_state; return_VOID; } /******************************************************************************* * * FUNCTION: acpi_ds_pop_walk_state * * PARAMETERS: thread - Current thread state * * RETURN: A walk_state object popped from the thread's stack * * DESCRIPTION: Remove and return the walkstate object that is at the head of * the walk stack for the given walk list. NULL indicates that * the list is empty. * ******************************************************************************/ struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread) { struct acpi_walk_state *walk_state; ACPI_FUNCTION_TRACE(ds_pop_walk_state); walk_state = thread->walk_state_list; if (walk_state) { /* Next walk state becomes the current walk state */ thread->walk_state_list = walk_state->next; /* * Don't clear the NEXT field, this serves as an indicator * that there is a parent WALK STATE * Do Not: walk_state->Next = NULL; */ } return_PTR(walk_state); } /******************************************************************************* * * FUNCTION: acpi_ds_create_walk_state * * PARAMETERS: owner_id - ID for object creation * origin - Starting point for this walk * method_desc - Method object * thread - Current thread state * * RETURN: Pointer to the new walk state. * * DESCRIPTION: Allocate and initialize a new walk state. The current walk * state is set to this new state. * ******************************************************************************/ struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, union acpi_parse_object *origin, union acpi_operand_object *method_desc, struct acpi_thread_state *thread) { struct acpi_walk_state *walk_state; ACPI_FUNCTION_TRACE(ds_create_walk_state); walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state)); if (!walk_state) { return_PTR(NULL); } walk_state->descriptor_type = ACPI_DESC_TYPE_WALK; walk_state->method_desc = method_desc; walk_state->owner_id = owner_id; walk_state->origin = origin; walk_state->thread = thread; walk_state->parser_state.start_op = origin; /* Init the method args/local */ #ifndef ACPI_CONSTANT_EVAL_ONLY acpi_ds_method_data_init(walk_state); #endif /* Put the new state at the head of the walk list */ if (thread) { acpi_ds_push_walk_state(walk_state, thread); } return_PTR(walk_state); } /******************************************************************************* * * FUNCTION: acpi_ds_init_aml_walk * * PARAMETERS: walk_state - New state to be initialized * op - Current parse op * method_node - Control method NS node, if any * aml_start - Start of AML * aml_length - Length of AML * info - Method info block (params, etc.) * pass_number - 1, 2, or 3 * * RETURN: Status * * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk * ******************************************************************************/ acpi_status acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state, union acpi_parse_object *op, struct acpi_namespace_node *method_node, u8 * aml_start, u32 aml_length, struct acpi_evaluate_info *info, u8 pass_number) { acpi_status status; struct acpi_parse_state *parser_state = &walk_state->parser_state; union acpi_parse_object *extra_op; ACPI_FUNCTION_TRACE(ds_init_aml_walk); walk_state->parser_state.aml = walk_state->parser_state.aml_start = walk_state->parser_state.aml_end = walk_state->parser_state.pkg_end = aml_start; /* Avoid undefined behavior: applying zero offset to null pointer */ if (aml_length != 0) { walk_state->parser_state.aml_end += aml_length; walk_state->parser_state.pkg_end += aml_length; } /* The next_op of the next_walk will be the beginning of the method */ walk_state->next_op = NULL; walk_state->pass_number = pass_number; if (info) { walk_state->params = info->parameters; walk_state->caller_return_desc = &info->return_object; } status = acpi_ps_init_scope(&walk_state->parser_state, op); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (method_node) { walk_state->parser_state.start_node = method_node; walk_state->walk_type = ACPI_WALK_METHOD; walk_state->method_node = method_node; walk_state->method_desc = acpi_ns_get_attached_object(method_node); /* Push start scope on scope stack and make it current */ status = acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Init the method arguments */ status = acpi_ds_method_data_init_args(walk_state->params, ACPI_METHOD_NUM_ARGS, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } else { /* * Setup the current scope. * Find a Named Op that has a namespace node associated with it. * search upwards from this Op. Current scope is the first * Op with a namespace node. */ extra_op = parser_state->start_op; while (extra_op && !extra_op->common.node) { extra_op = extra_op->common.parent; } if (!extra_op) { parser_state->start_node = NULL; } else { parser_state->start_node = extra_op->common.node; } if (parser_state->start_node) { /* Push start scope on scope stack and make it current */ status = acpi_ds_scope_stack_push(parser_state->start_node, parser_state->start_node-> type, walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } } status = acpi_ds_init_callbacks(walk_state, pass_number); return_ACPI_STATUS(status); } /******************************************************************************* * * FUNCTION: acpi_ds_delete_walk_state * * PARAMETERS: walk_state - State to delete * * RETURN: Status * * DESCRIPTION: Delete a walk state including all internal data structures * ******************************************************************************/ void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state) { union acpi_generic_state *state; ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state); if (!walk_state) { return_VOID; } if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) { ACPI_ERROR((AE_INFO, "%p is not a valid walk state", walk_state)); return_VOID; } /* There should not be any open scopes */ if (walk_state->parser_state.scope) { ACPI_ERROR((AE_INFO, "%p walk still has a scope list", walk_state)); acpi_ps_cleanup_scope(&walk_state->parser_state); } /* Always must free any linked control states */ while (walk_state->control_state) { state = walk_state->control_state; walk_state->control_state = state->common.next; acpi_ut_delete_generic_state(state); } /* Always must free any linked parse states */ while (walk_state->scope_info) { state = walk_state->scope_info; walk_state->scope_info = state->common.next; acpi_ut_delete_generic_state(state); } /* Always must free any stacked result states */ while (walk_state->results) { state = walk_state->results; walk_state->results = state->common.next; acpi_ut_delete_generic_state(state); } ACPI_FREE(walk_state); return_VOID; }
linux-master
drivers/acpi/acpica/dswstate.c