void acpi_ns_terminate (void) { union acpi_operand_object *obj_desc; ACPI_FUNCTION_TRACE ("ns_terminate"); /* * 1) Free the entire namespace -- all nodes and objects * * Delete all object descriptors attached to namepsace nodes */ acpi_ns_delete_namespace_subtree (acpi_gbl_root_node); /* Detach any objects attached to the root */ obj_desc = acpi_ns_get_attached_object (acpi_gbl_root_node); if (obj_desc) { acpi_ns_detach_object (acpi_gbl_root_node); } ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n")); /* * 2) Now we can delete the ACPI tables */ acpi_tb_delete_all_tables (); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n")); return_VOID; }
void acpi_ns_terminate(void) { acpi_status status; ACPI_FUNCTION_TRACE(ns_terminate); #ifdef ACPI_EXEC_APP { union acpi_operand_object *prev; union acpi_operand_object *next; /* Delete any module-level code blocks */ next = acpi_gbl_module_code_list; while (next) { prev = next; next = next->method.mutex; prev->method.mutex = NULL; /* Clear the Mutex (cheated) field */ acpi_ut_remove_reference(prev); } } #endif /* * 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; }
void acpi_ns_terminate (void) { acpi_operand_object *obj_desc; acpi_namespace_node *this_node; FUNCTION_TRACE ("Ns_terminate"); this_node = acpi_gbl_root_node; /* * 1) Free the entire namespace -- all objects, tables, and stacks * * Delete all objects linked to the root * (additional table descriptors) */ acpi_ns_delete_namespace_subtree (this_node); /* Detach any object(s) attached to the root */ obj_desc = acpi_ns_get_attached_object (this_node); if (obj_desc) { acpi_ns_detach_object (this_node); acpi_ut_remove_reference (obj_desc); } acpi_ns_delete_children (this_node); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n")); /* * 2) Now we can delete the ACPI tables */ acpi_tb_delete_acpi_tables (); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n")); return_VOID; }
/******************************************************************************* * * FUNCTION: acpi_ds_parse_method * * PARAMETERS: Node - Method node * * RETURN: Status * * DESCRIPTION: Parse the AML that is associated with the method. * * MUTEX: Assumes parser is locked * ******************************************************************************/ acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node) { acpi_status status; union acpi_operand_object *obj_desc; union acpi_parse_object *op; struct acpi_walk_state *walk_state; ACPI_FUNCTION_TRACE_PTR("ds_parse_method", node); /* Parameter Validation */ if (!node) { return_ACPI_STATUS(AE_NULL_ENTRY); } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Parsing [%4.4s] **** named_obj=%p\n", acpi_ut_get_node_name(node), node)); /* Extract the method object from the method Node */ obj_desc = acpi_ns_get_attached_object(node); if (!obj_desc) { return_ACPI_STATUS(AE_NULL_OBJECT); } /* Create a mutex for the method if there is a concurrency limit */ if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) && (!obj_desc->method.semaphore)) { status = acpi_os_create_semaphore(obj_desc->method.concurrency, obj_desc->method.concurrency, &obj_desc->method.semaphore); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } /* * Allocate a new parser op to be the root of the parsed * method tree */ op = acpi_ps_alloc_op(AML_METHOD_OP); if (!op) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Init new op with the method name and pointer back to the Node */ acpi_ps_set_name(op, node->name.integer); op->common.node = node; /* * Get a new owner_id for objects created by this method. Namespace * objects (such as Operation Regions) can be created during the * first pass parse. */ status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); if (ACPI_FAILURE(status)) { goto cleanup; } /* Create and initialize a new walk state */ walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL, NULL); if (!walk_state) { status = AE_NO_MEMORY; goto cleanup2; } status = acpi_ds_init_aml_walk(walk_state, op, node, obj_desc->method.aml_start, obj_desc->method.aml_length, NULL, 1); if (ACPI_FAILURE(status)) { acpi_ds_delete_walk_state(walk_state); goto cleanup2; } /* * Parse the method, first pass * * The first pass load is where newly declared named objects are added into * the namespace. Actual evaluation of the named objects (what would be * called a "second pass") happens during the actual execution of the * method so that operands to the named objects can take on dynamic * run-time values. */ status = acpi_ps_parse_aml(walk_state); if (ACPI_FAILURE(status)) { goto cleanup2; } ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** [%4.4s] Parsed **** named_obj=%p Op=%p\n", acpi_ut_get_node_name(node), node, op)); /* * Delete the parse tree. We simply re-parse the method for every * execution since there isn't much overhead (compared to keeping lots * of parse trees around) */ acpi_ns_delete_namespace_subtree(node); acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id); cleanup2: acpi_ut_release_owner_id(&obj_desc->method.owner_id); cleanup: acpi_ps_delete_parse_tree(op); return_ACPI_STATUS(status); }
void acpi_ds_terminate_control_method(struct acpi_walk_state *walk_state) { union acpi_operand_object *obj_desc; struct acpi_namespace_node *method_node; acpi_status status; ACPI_FUNCTION_TRACE_PTR("ds_terminate_control_method", walk_state); if (!walk_state) { return_VOID; } /* The current method object was saved in the walk state */ obj_desc = walk_state->method_desc; if (!obj_desc) { return_VOID; } /* Delete all arguments and locals */ acpi_ds_method_data_delete_all(walk_state); /* * Lock the parser while we terminate this method. * If this is the last thread executing the method, * we have additional cleanup to perform */ status = acpi_ut_acquire_mutex(ACPI_MTX_PARSER); if (ACPI_FAILURE(status)) { return_VOID; } /* Signal completion of the execution of this method if necessary */ if (walk_state->method_desc->method.semaphore) { status = acpi_os_signal_semaphore(walk_state->method_desc->method. semaphore, 1); if (ACPI_FAILURE(status)) { ACPI_REPORT_ERROR(("Could not signal method semaphore\n")); /* Ignore error and continue cleanup */ } } if (walk_state->method_desc->method.thread_count) { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "*** Not deleting method namespace, there are still %d threads\n", walk_state->method_desc->method. thread_count)); } else { /* This is the last executing thread */ /* * Support to dynamically change a method from not_serialized to * Serialized if it appears that the method is written foolishly and * does not support multiple thread execution. The best example of this * is if such a method creates namespace objects and blocks. A second * thread will fail with an AE_ALREADY_EXISTS exception * * This code is here because we must wait until the last thread exits * before creating the synchronization semaphore. */ if ((walk_state->method_desc->method.concurrency == 1) && (!walk_state->method_desc->method.semaphore)) { status = acpi_os_create_semaphore(1, 1, &walk_state-> method_desc->method. semaphore); } /* * There are no more threads executing this method. Perform * additional cleanup. * * The method Node is stored in the walk state */ method_node = walk_state->method_node; /* * Delete any namespace entries created immediately underneath * the method */ status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { goto exit; } if (method_node->child) { acpi_ns_delete_namespace_subtree(method_node); } /* * Delete any namespace entries created anywhere else within * the namespace */ acpi_ns_delete_namespace_by_owner(walk_state->method_desc-> method.owner_id); status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); acpi_ut_release_owner_id(&walk_state->method_desc->method. owner_id); } exit: (void)acpi_ut_release_mutex(ACPI_MTX_PARSER); return_VOID; }
acpi_status acpi_ds_init_one_object ( acpi_handle obj_handle, u32 level, void *context, void **return_value) { acpi_object_type type; acpi_status status; struct acpi_init_walk_info *info = (struct acpi_init_walk_info *) context; ACPI_FUNCTION_NAME ("ds_init_one_object"); /* * We are only interested in objects owned by the table that * was just loaded */ if (((struct acpi_namespace_node *) obj_handle)->owner_id != info->table_desc->table_id) { return (AE_OK); } info->object_count++; /* And even then, we are only interested in a few object types */ type = acpi_ns_get_type (obj_handle); switch (type) { case ACPI_TYPE_REGION: status = acpi_ds_initialize_region (obj_handle); if (ACPI_FAILURE (status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Region %p [%4.4s] - Init failure, %s\n", obj_handle, acpi_ut_get_node_name (obj_handle), acpi_format_exception (status))); } info->op_region_count++; break; case ACPI_TYPE_METHOD: info->method_count++; /* Print a dot for each method unless we are going to print the entire pathname */ if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, ".")); } /* * Set the execution data width (32 or 64) based upon the * revision number of the parent ACPI table. * TBD: This is really for possible future support of integer width * on a per-table basis. Currently, we just use a global for the width. */ if (info->table_desc->pointer->revision == 1) { ((struct acpi_namespace_node *) obj_handle)->flags |= ANOBJ_DATA_WIDTH_32; } /* * Always parse methods to detect errors, we will delete * the parse tree below */ status = acpi_ds_parse_method (obj_handle); if (ACPI_FAILURE (status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Method %p [%4.4s] - parse failure, %s\n", obj_handle, acpi_ut_get_node_name (obj_handle), acpi_format_exception (status))); /* This parse failed, but we will continue parsing more methods */ break; } /* * Delete the parse tree. We simply re-parse the method * for every execution since there isn't much overhead */ acpi_ns_delete_namespace_subtree (obj_handle); acpi_ns_delete_namespace_by_owner (((struct acpi_namespace_node *) obj_handle)->object->method.owning_id); 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); }
void acpi_ds_terminate_control_method(union acpi_operand_object *method_desc, struct acpi_walk_state *walk_state) { ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state); /* method_desc is required, walk_state is optional */ if (!method_desc) { return_VOID; } if (walk_state) { /* Delete all arguments and locals */ acpi_ds_method_data_delete_all(walk_state); /* * If method is serialized, release the mutex and restore the * current sync level for this thread */ if (method_desc->method.mutex) { /* Acquisition Depth handles recursive calls */ method_desc->method.mutex->mutex.acquisition_depth--; if (!method_desc->method.mutex->mutex.acquisition_depth) { walk_state->thread->current_sync_level = method_desc->method.mutex->mutex. original_sync_level; acpi_os_release_mutex(method_desc->method. mutex->mutex.os_mutex); method_desc->method.mutex->mutex.thread_id = 0; } } /* * Delete any namespace objects created anywhere within the * namespace by the execution of this method. Unless: * 1) This method is a module-level executable code method, in which * case we want make the objects permanent. * 2) There are other threads executing the method, in which case we * will wait until the last thread has completed. */ if (!(method_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL) && (method_desc->method.thread_count == 1)) { /* Delete any direct children of (created by) this method */ acpi_ns_delete_namespace_subtree(walk_state-> method_node); /* * Delete any objects that were created by this method * elsewhere in the namespace (if any were created). * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the * deletion such that we don't have to perform an entire * namespace walk for every control method execution. */ if (method_desc->method. info_flags & ACPI_METHOD_MODIFIED_NAMESPACE) { acpi_ns_delete_namespace_by_owner(method_desc-> method. owner_id); method_desc->method.info_flags &= ~ACPI_METHOD_MODIFIED_NAMESPACE; } } } /* Decrement the thread count on the method */ if (method_desc->method.thread_count) { method_desc->method.thread_count--; } else { ACPI_ERROR((AE_INFO, "Invalid zero thread count in method")); } /* Are there any other threads currently executing this method? */ if (method_desc->method.thread_count) { /* * Additional threads. Do not release the owner_id in this case, * we immediately reuse it for the next thread executing this method */ ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "*** Completed execution of one thread, %u threads remaining\n", method_desc->method.thread_count)); } else { /* This is the only executing thread for this method */ /* * Support to dynamically change a method from not_serialized to * Serialized if it appears that the method is incorrectly written and * does not support multiple thread execution. The best example of this * is if such a method creates namespace objects and blocks. A second * thread will fail with an AE_ALREADY_EXISTS exception. * * This code is here because we must wait until the last thread exits * before marking the method as serialized. */ if (method_desc->method. info_flags & ACPI_METHOD_SERIALIZED_PENDING) { if (walk_state) { ACPI_INFO((AE_INFO, "Marking method %4.4s as Serialized because of AE_ALREADY_EXISTS error", walk_state->method_node->name. ascii)); } /* * Method tried to create an object twice and was marked as * "pending serialized". The probable cause is that the method * cannot handle reentrancy. * * The method was created as not_serialized, but it tried to create * a named object and then blocked, causing the second thread * entrance to begin and then fail. Workaround this problem by * marking the method permanently as Serialized when the last * thread exits here. */ method_desc->method.info_flags &= ~ACPI_METHOD_SERIALIZED_PENDING; method_desc->method.info_flags |= (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL); method_desc->method.sync_level = 0; } /* No more threads, we can free the owner_id */ if (! (method_desc->method. info_flags & ACPI_METHOD_MODULE_LEVEL)) { acpi_ut_release_owner_id(&method_desc->method.owner_id); } } return_VOID; }
ACPI_STATUS acpi_ds_terminate_control_method ( ACPI_WALK_STATE *walk_state) { ACPI_STATUS status; ACPI_OPERAND_OBJECT *obj_desc; ACPI_NAMESPACE_NODE *method_node; /* The method object should be stored in the walk state */ obj_desc = walk_state->method_desc; if (!obj_desc) { return (AE_OK); } /* Delete all arguments and locals */ acpi_ds_method_data_delete_all (walk_state); /* * Lock the parser while we terminate this method. * If this is the last thread executing the method, * we have additional cleanup to perform */ acpi_cm_acquire_mutex (ACPI_MTX_PARSER); /* Signal completion of the execution of this method if necessary */ if (walk_state->method_desc->method.semaphore) { status = acpi_os_signal_semaphore ( walk_state->method_desc->method.semaphore, 1); } /* Decrement the thread count on the method parse tree */ walk_state->method_desc->method.thread_count--; if (!walk_state->method_desc->method.thread_count) { /* * There are no more threads executing this method. Perform * additional cleanup. * * The method Node is stored in the walk state */ method_node = walk_state->method_node; /* * Delete any namespace entries created immediately underneath * the method */ acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE); if (method_node->child) { acpi_ns_delete_namespace_subtree (method_node); } /* * Delete any namespace entries created anywhere else within * the namespace */ acpi_ns_delete_namespace_by_owner (walk_state->method_desc->method.owning_id); acpi_cm_release_mutex (ACPI_MTX_NAMESPACE); } acpi_cm_release_mutex (ACPI_MTX_PARSER); return (AE_OK); }