dsmethod.c

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

C
633
字号
/****************************************************************************** * * Module Name: dsmethod - Parser/Interpreter interface - control method parsing * *****************************************************************************//* * Copyright (C) 2000 - 2007, R. Byron Moore * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions, and the following disclaimer, *    without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer *    substantially similar to the "NO WARRANTY" disclaimer below *    ("Disclaimer") and any redistribution must be conditioned upon *    including a substantially similar Disclaimer requirement for further *    binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names *    of any contributors may be used to endorse or promote products derived *    from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */#include <acpi/acpi.h>#include <acpi/acparser.h>#include <acpi/amlcode.h>#include <acpi/acdispat.h>#include <acpi/acinterp.h>#include <acpi/acnamesp.h>#include <acpi/acdisasm.h>#define _COMPONENT          ACPI_DISPATCHERACPI_MODULE_NAME("dsmethod")/* Local prototypes */static acpi_statusacpi_ds_create_method_mutex(union acpi_operand_object *method_desc);/******************************************************************************* * * FUNCTION:    acpi_ds_method_error * * PARAMETERS:  Status          - Execution status *              walk_state      - Current state * * RETURN:      Status * * DESCRIPTION: Called on method error. Invoke the global exception handler if *              present, dump the method data if the disassembler is configured * *              Note: Allows the exception handler to change the status code * ******************************************************************************/acpi_statusacpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state){	ACPI_FUNCTION_ENTRY();	/* Ignore AE_OK and control exception codes */	if (ACPI_SUCCESS(status) || (status & AE_CODE_CONTROL)) {		return (status);	}	/* Invoke the global exception handler */	if (acpi_gbl_exception_handler) {		/* Exit the interpreter, allow handler to execute methods */		acpi_ex_exit_interpreter();		/*		 * Handler can map the exception code to anything it wants, including		 * AE_OK, in which case the executing method will not be aborted.		 */		status = acpi_gbl_exception_handler(status,						    walk_state->method_node ?						    walk_state->method_node->						    name.integer : 0,						    walk_state->opcode,						    walk_state->aml_offset,						    NULL);		(void)acpi_ex_enter_interpreter();	}#ifdef ACPI_DISASSEMBLER	if (ACPI_FAILURE(status)) {		/* Display method locals/args if disassembler is present */		acpi_dm_dump_method_info(status, walk_state, walk_state->op);	}#endif	return (status);}/******************************************************************************* * * FUNCTION:    acpi_ds_create_method_mutex * * PARAMETERS:  obj_desc            - The method object * * RETURN:      Status * * DESCRIPTION: Create a mutex object for a serialized control method * ******************************************************************************/static acpi_statusacpi_ds_create_method_mutex(union acpi_operand_object *method_desc){	union acpi_operand_object *mutex_desc;	acpi_status status;	ACPI_FUNCTION_TRACE(ds_create_method_mutex);	/* Create the new mutex object */	mutex_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);	if (!mutex_desc) {		return_ACPI_STATUS(AE_NO_MEMORY);	}	/* Create the actual OS Mutex */	status = acpi_os_create_mutex(&mutex_desc->mutex.os_mutex);	if (ACPI_FAILURE(status)) {		return_ACPI_STATUS(status);	}	mutex_desc->mutex.sync_level = method_desc->method.sync_level;	method_desc->method.mutex = mutex_desc;	return_ACPI_STATUS(AE_OK);}/******************************************************************************* * * FUNCTION:    acpi_ds_begin_method_execution * * PARAMETERS:  method_node         - Node of the method *              obj_desc            - The method object *              walk_state          - current state, NULL if not yet executing *                                    a method. * * RETURN:      Status * * DESCRIPTION: Prepare a method for execution.  Parses the method if necessary, *              increments the thread count, and waits at the method semaphore *              for clearance to execute. * ******************************************************************************/acpi_statusacpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,			       union acpi_operand_object *obj_desc,			       struct acpi_walk_state *walk_state){	acpi_status status = AE_OK;	ACPI_FUNCTION_TRACE_PTR(ds_begin_method_execution, method_node);	if (!method_node) {		return_ACPI_STATUS(AE_NULL_ENTRY);	}	/* Prevent wraparound of thread count */	if (obj_desc->method.thread_count == ACPI_UINT8_MAX) {		ACPI_ERROR((AE_INFO,			    "Method reached maximum reentrancy limit (255)"));		return_ACPI_STATUS(AE_AML_METHOD_LIMIT);	}	/*	 * If this method is serialized, we need to acquire the method mutex.	 */	if (obj_desc->method.method_flags & AML_METHOD_SERIALIZED) {		/*		 * Create a mutex for the method if it is defined to be Serialized		 * and a mutex has not already been created. We defer the mutex creation		 * until a method is actually executed, to minimize the object count		 */		if (!obj_desc->method.mutex) {			status = acpi_ds_create_method_mutex(obj_desc);			if (ACPI_FAILURE(status)) {				return_ACPI_STATUS(status);			}		}		/*		 * The current_sync_level (per-thread) must be less than or equal to		 * the sync level of the method. This mechanism provides some		 * deadlock prevention		 *		 * Top-level method invocation has no walk state at this point		 */		if (walk_state &&		    (walk_state->thread->current_sync_level >		     obj_desc->method.mutex->mutex.sync_level)) {			ACPI_ERROR((AE_INFO,				    "Cannot acquire Mutex for method [%4.4s], current SyncLevel is too large (%d)",				    acpi_ut_get_node_name(method_node),				    walk_state->thread->current_sync_level));			return_ACPI_STATUS(AE_AML_MUTEX_ORDER);		}		/*		 * Obtain the method mutex if necessary. Do not acquire mutex for a		 * recursive call.		 */		if (!walk_state ||		    !obj_desc->method.mutex->mutex.owner_thread ||		    (walk_state->thread !=		     obj_desc->method.mutex->mutex.owner_thread)) {			/*			 * Acquire the method mutex. This releases the interpreter if we			 * block (and reacquires it before it returns)			 */			status =			    acpi_ex_system_wait_mutex(obj_desc->method.mutex->						      mutex.os_mutex,						      ACPI_WAIT_FOREVER);			if (ACPI_FAILURE(status)) {				return_ACPI_STATUS(status);			}			/* Update the mutex and walk info and save the original sync_level */			if (walk_state) {				obj_desc->method.mutex->mutex.				    original_sync_level =				    walk_state->thread->current_sync_level;				obj_desc->method.mutex->mutex.owner_thread =				    walk_state->thread;				walk_state->thread->current_sync_level =				    obj_desc->method.sync_level;			} else {				obj_desc->method.mutex->mutex.				    original_sync_level =				    obj_desc->method.mutex->mutex.sync_level;			}		}		/* Always increase acquisition depth */		obj_desc->method.mutex->mutex.acquisition_depth++;	}	/*	 * Allocate an Owner ID for this method, only if this is the first thread	 * to begin concurrent execution. We only need one owner_id, even if the	 * method is invoked recursively.	 */	if (!obj_desc->method.owner_id) {		status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);		if (ACPI_FAILURE(status)) {			goto cleanup;		}	}	/*	 * Increment the method parse tree thread count since it has been	 * reentered one more time (even if it is the same thread)	 */	obj_desc->method.thread_count++;	return_ACPI_STATUS(status);      cleanup:	/* On error, must release the method mutex (if present) */	if (obj_desc->method.mutex) {		acpi_os_release_mutex(obj_desc->method.mutex->mutex.os_mutex);	}	return_ACPI_STATUS(status);}/******************************************************************************* * * FUNCTION:    acpi_ds_call_control_method * * PARAMETERS:  Thread              - Info for this thread *              this_walk_state     - Current walk state *              Op                  - Current Op to be walked * * RETURN:      Status * * DESCRIPTION: Transfer execution to a called control method * ******************************************************************************/acpi_statusacpi_ds_call_control_method(struct acpi_thread_state *thread,			    struct acpi_walk_state *this_walk_state,

⌨️ 快捷键说明

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