dsmethod.c

来自「linux 内核源代码」· C语言 代码 · 共 633 行 · 第 1/2 页

C
633
字号
			    union acpi_parse_object *op){	acpi_status status;	struct acpi_namespace_node *method_node;	struct acpi_walk_state *next_walk_state = NULL;	union acpi_operand_object *obj_desc;	struct acpi_evaluate_info *info;	u32 i;	ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state);	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,			  "Calling method %p, currentstate=%p\n",			  this_walk_state->prev_op, this_walk_state));	/*	 * Get the namespace entry for the control method we are about to call	 */	method_node = this_walk_state->method_call_node;	if (!method_node) {		return_ACPI_STATUS(AE_NULL_ENTRY);	}	obj_desc = acpi_ns_get_attached_object(method_node);	if (!obj_desc) {		return_ACPI_STATUS(AE_NULL_OBJECT);	}	/* Init for new method, possibly wait on method mutex */	status = acpi_ds_begin_method_execution(method_node, obj_desc,						this_walk_state);	if (ACPI_FAILURE(status)) {		return_ACPI_STATUS(status);	}	/* Begin method parse/execution. Create a new walk state */	next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id,						    NULL, obj_desc, thread);	if (!next_walk_state) {		status = AE_NO_MEMORY;		goto cleanup;	}	/*	 * The resolved arguments were put on the previous walk state's operand	 * stack. Operands on the previous walk state stack always	 * start at index 0. Also, null terminate the list of arguments	 */	this_walk_state->operands[this_walk_state->num_operands] = NULL;	/*	 * Allocate and initialize the evaluation information block	 * TBD: this is somewhat inefficient, should change interface to	 * ds_init_aml_walk. For now, keeps this struct off the CPU stack	 */	info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));	if (!info) {		return_ACPI_STATUS(AE_NO_MEMORY);	}	info->parameters = &this_walk_state->operands[0];	info->parameter_type = ACPI_PARAM_ARGS;	status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,				       obj_desc->method.aml_start,				       obj_desc->method.aml_length, info,				       ACPI_IMODE_EXECUTE);	ACPI_FREE(info);	if (ACPI_FAILURE(status)) {		goto cleanup;	}	/*	 * Delete the operands on the previous walkstate operand stack	 * (they were copied to new objects)	 */	for (i = 0; i < obj_desc->method.param_count; i++) {		acpi_ut_remove_reference(this_walk_state->operands[i]);		this_walk_state->operands[i] = NULL;	}	/* Clear the operand stack */	this_walk_state->num_operands = 0;	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,			  "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",			  method_node->name.ascii, next_walk_state));	/* Invoke an internal method if necessary */	if (obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY) {		status = obj_desc->method.implementation(next_walk_state);	}	return_ACPI_STATUS(status);      cleanup:	/* On error, we must terminate the method properly */	acpi_ds_terminate_control_method(obj_desc, next_walk_state);	if (next_walk_state) {		acpi_ds_delete_walk_state(next_walk_state);	}	return_ACPI_STATUS(status);}/******************************************************************************* * * FUNCTION:    acpi_ds_restart_control_method * * PARAMETERS:  walk_state          - State for preempted method (caller) *              return_desc         - Return value from the called method * * RETURN:      Status * * DESCRIPTION: Restart a method that was preempted by another (nested) method *              invocation.  Handle the return value (if any) from the callee. * ******************************************************************************/acpi_statusacpi_ds_restart_control_method(struct acpi_walk_state *walk_state,			       union acpi_operand_object *return_desc){	acpi_status status;	int same_as_implicit_return;	ACPI_FUNCTION_TRACE_PTR(ds_restart_control_method, walk_state);	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,			  "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",			  acpi_ut_get_node_name(walk_state->method_node),			  walk_state->method_call_op, return_desc));	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,			  "    ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",			  walk_state->return_used,			  walk_state->results, walk_state));	/* Did the called method return a value? */	if (return_desc) {		/* Is the implicit return object the same as the return desc? */		same_as_implicit_return =		    (walk_state->implicit_return_obj == return_desc);		/* Are we actually going to use the return value? */		if (walk_state->return_used) {			/* Save the return value from the previous method */			status = acpi_ds_result_push(return_desc, walk_state);			if (ACPI_FAILURE(status)) {				acpi_ut_remove_reference(return_desc);				return_ACPI_STATUS(status);			}			/*			 * Save as THIS method's return value in case it is returned			 * immediately to yet another method			 */			walk_state->return_desc = return_desc;		}		/*		 * The following code is the optional support for the so-called		 * "implicit return". Some AML code assumes that the last value of the		 * method is "implicitly" returned to the caller, in the absence of an		 * explicit return value.		 *		 * Just save the last result of the method as the return value.		 *		 * NOTE: this is optional because the ASL language does not actually		 * support this behavior.		 */		else if (!acpi_ds_do_implicit_return			 (return_desc, walk_state, FALSE)			 || same_as_implicit_return) {			/*			 * Delete the return value if it will not be used by the			 * calling method or remove one reference if the explicit return			 * is the same as the implicit return value.			 */			acpi_ut_remove_reference(return_desc);		}	}	return_ACPI_STATUS(AE_OK);}/******************************************************************************* * * FUNCTION:    acpi_ds_terminate_control_method * * PARAMETERS:  method_desc         - Method object *              walk_state          - State associated with the method * * RETURN:      None * * DESCRIPTION: Terminate a control method.  Delete everything that the method *              created, delete all locals and arguments, and delete the parse *              tree if requested. * * MUTEX:       Interpreter is locked * ******************************************************************************/voidacpi_ds_terminate_control_method(union acpi_operand_object *method_desc,				 struct acpi_walk_state *walk_state){	struct acpi_namespace_node *method_node;	acpi_status status;	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.owner_thread = NULL;		}	}	if (walk_state) {		/*		 * Delete any objects created by this method during execution.		 * The method Node is stored in the walk state		 */		method_node = walk_state->method_node;		/*		 * Delete any namespace objects created anywhere within		 * the namespace by the execution of this method		 */		acpi_ns_delete_namespace_by_owner(method_desc->method.owner_id);	}	/* 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, %d 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 creating the synchronization semaphore.		 */		if ((method_desc->method.method_flags & AML_METHOD_SERIALIZED)		    && (!method_desc->method.mutex)) {			status = acpi_ds_create_method_mutex(method_desc);		}		/* No more threads, we can free the owner_id */		acpi_ut_release_owner_id(&method_desc->method.owner_id);	}	return_VOID;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?