evgpe.c

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

C
723
字号
 * * 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){	acpi_status status;	struct acpi_gpe_block_info *gpe_block;	struct acpi_gpe_register_info *gpe_register_info;	u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;	u8 enabled_status_byte;	u32 status_reg;	u32 enable_reg;	acpi_cpu_flags flags;	acpi_native_uint i;	acpi_native_uint 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) {		/*		 * 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];			/* Read the Status Register */			status =			    acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH,						   &status_reg,						   &gpe_register_info->						   status_address);			if (ACPI_FAILURE(status)) {				goto unlock_and_exit;			}			/* Read the Enable Register */			status =			    acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH,						   &enable_reg,						   &gpe_register_info->						   enable_address);			if (ACPI_FAILURE(status)) {				goto unlock_and_exit;			}			ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,					  "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",					  gpe_register_info->base_gpe_number,					  status_reg, enable_reg));			/* Check if there is anything active at all in this register */			enabled_status_byte = (u8) (status_reg & enable_reg);			if (!enabled_status_byte) {				/* No active GPEs in this register, move on */				continue;			}			/* Now look at the individual GPEs in this byte register */			for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {				/* Examine one GPE bit */				if (enabled_status_byte & (1 << j)) {					/*					 * Found an active GPE. Dispatch the event to a handler					 * or method.					 */					int_status |=					    acpi_ev_gpe_dispatch(&gpe_block->								 event_info[(i *									     ACPI_GPE_REGISTER_WIDTH)									    +									    j],								 (u32) j +								 gpe_register_info->								 base_gpe_number);				}			}		}		gpe_block = gpe_block->next;	}      unlock_and_exit:	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 = (void *)context;	acpi_status status;	struct acpi_gpe_event_info local_gpe_event_info;	struct acpi_evaluate_info *info;	ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);	if (ACPI_FAILURE(status)) {		return_VOID;	}	/* Must revalidate the gpe_number/gpe_block */	if (!acpi_ev_valid_gpe_event(gpe_event_info)) {		status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);		return_VOID;	}	/* Set the GPE flags for return to enabled state */	(void)acpi_ev_enable_gpe(gpe_event_info, FALSE);	/*	 * Take a snapshot of the GPE info for this level - we copy the	 * info to prevent a race condition with remove_handler/remove_block.	 */	ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,		    sizeof(struct acpi_gpe_event_info));	status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);	if (ACPI_FAILURE(status)) {		return_VOID;	}	/*	 * Must check for control method type dispatch one more	 * time to avoid race with ev_gpe_install_handler	 */	if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==	    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 =			    local_gpe_event_info.dispatch.method_node;			info->parameters =			    ACPI_CAST_PTR(union acpi_operand_object *,					  gpe_event_info);			info->parameter_type = ACPI_PARAM_GPE;			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					(local_gpe_event_info.dispatch.					 method_node)));		}	}	if ((local_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(&local_gpe_event_info);		if (ACPI_FAILURE(status)) {			return_VOID;		}	}	/* Enable this GPE */	(void)acpi_hw_write_gpe_enable_reg(&local_gpe_event_info);	return_VOID;}/******************************************************************************* * * FUNCTION:    acpi_ev_gpe_dispatch * * PARAMETERS:  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. * *              This function executes at interrupt level. * ******************************************************************************/u32acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number){	acpi_status status;	ACPI_FUNCTION_TRACE(ev_gpe_dispatch);	acpi_gpe_count++;	/*	 * 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[%2X]",					gpe_number));			return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);		}	}	/*	 * 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, we disable this GPE to prevent further such pointless	 * events from firing.	 */	switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {	case ACPI_GPE_DISPATCH_HANDLER:		/*		 * Invoke the installed handler (at interrupt level)		 * Ignore return status for now.  TBD: leave GPE disabled on error?		 */		(void)gpe_event_info->dispatch.handler->address(gpe_event_info->								dispatch.								handler->								context);		/* It is now safe to clear level-triggered events. */		if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==		    ACPI_GPE_LEVEL_TRIGGERED) {			status = acpi_hw_clear_gpe(gpe_event_info);			if (ACPI_FAILURE(status)) {				ACPI_EXCEPTION((AE_INFO, status,						"Unable to clear GPE[%2X]",						gpe_number));				return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);			}		}		break;	case ACPI_GPE_DISPATCH_METHOD:		/*		 * Disable the GPE, so it doesn't keep firing before the method has a		 * chance to run (it runs asynchronously with interrupts enabled).		 */		status = acpi_ev_disable_gpe(gpe_event_info);		if (ACPI_FAILURE(status)) {			ACPI_EXCEPTION((AE_INFO, status,					"Unable to disable GPE[%2X]",					gpe_number));			return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);		}		/*		 * 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[%2X] - event disabled",					gpe_number));		}		break;	default:		/* No handler or method to run! */		ACPI_ERROR((AE_INFO,			    "No handler or method for GPE[%2X], disabling event",			    gpe_number));		/*		 * Disable the GPE. The GPE will remain disabled until the ACPI		 * Core Subsystem is restarted, or a handler is installed.		 */		status = acpi_ev_disable_gpe(gpe_event_info);		if (ACPI_FAILURE(status)) {			ACPI_EXCEPTION((AE_INFO, status,					"Unable to disable GPE[%2X]",					gpe_number));			return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);		}		break;	}	return_UINT32(ACPI_INTERRUPT_HANDLED);}

⌨️ 快捷键说明

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