📄 evgpeblk.c
字号:
/****************************************************************************** * * Module Name: evgpeblk - GPE block creation and initialization. * *****************************************************************************//* * Copyright (C) 2000 - 2005, 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/acevents.h>#include <acpi/acnamesp.h>#define _COMPONENT ACPI_EVENTSACPI_MODULE_NAME("evgpeblk")/* Local prototypes */static acpi_statusacpi_ev_save_method_info(acpi_handle obj_handle, u32 level, void *obj_desc, void **return_value);static acpi_statusacpi_ev_match_prw_and_gpe(acpi_handle obj_handle, u32 level, void *info, void **return_value);static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32 interrupt_number);static acpi_statusacpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);static acpi_statusacpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block, u32 interrupt_number);static acpi_statusacpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);/******************************************************************************* * * FUNCTION: acpi_ev_valid_gpe_event * * PARAMETERS: gpe_event_info - Info for this GPE * * RETURN: TRUE if the gpe_event is valid * * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL. * Should be called only when the GPE lists are semaphore locked * and not subject to change. * ******************************************************************************/u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info){ struct acpi_gpe_xrupt_info *gpe_xrupt_block; struct acpi_gpe_block_info *gpe_block; ACPI_FUNCTION_ENTRY(); /* No need for spin lock since we are not changing any list elements */ /* Walk the GPE interrupt levels */ gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head; while (gpe_xrupt_block) { gpe_block = gpe_xrupt_block->gpe_block_list_head; /* Walk the GPE blocks on this interrupt level */ while (gpe_block) { if ((&gpe_block->event_info[0] <= gpe_event_info) && (&gpe_block-> event_info[((acpi_size) gpe_block-> register_count) * 8] > gpe_event_info)) { return (TRUE); } gpe_block = gpe_block->next; } gpe_xrupt_block = gpe_xrupt_block->next; } return (FALSE);}/******************************************************************************* * * FUNCTION: acpi_ev_walk_gpe_list * * PARAMETERS: gpe_walk_callback - Routine called for each GPE block * * RETURN: Status * * DESCRIPTION: Walk the GPE lists. * ******************************************************************************/acpi_status acpi_ev_walk_gpe_list(ACPI_GPE_CALLBACK gpe_walk_callback){ struct acpi_gpe_block_info *gpe_block; struct acpi_gpe_xrupt_info *gpe_xrupt_info; acpi_status status = AE_OK; u32 flags; ACPI_FUNCTION_TRACE("ev_walk_gpe_list"); flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); /* Walk the interrupt level descriptor list */ gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; while (gpe_xrupt_info) { /* Walk all Gpe Blocks attached to this interrupt level */ gpe_block = gpe_xrupt_info->gpe_block_list_head; while (gpe_block) { /* One callback per GPE block */ status = gpe_walk_callback(gpe_xrupt_info, gpe_block); if (ACPI_FAILURE(status)) { goto unlock_and_exit; } gpe_block = gpe_block->next; } gpe_xrupt_info = gpe_xrupt_info->next; } unlock_and_exit: acpi_os_release_lock(acpi_gbl_gpe_lock, flags); return_ACPI_STATUS(status);}/******************************************************************************* * * FUNCTION: acpi_ev_delete_gpe_handlers * * PARAMETERS: gpe_xrupt_info - GPE Interrupt info * gpe_block - Gpe Block info * * RETURN: Status * * DESCRIPTION: Delete all Handler objects found in the GPE data structs. * Used only prior to termination. * ******************************************************************************/acpi_statusacpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info, struct acpi_gpe_block_info *gpe_block){ struct acpi_gpe_event_info *gpe_event_info; acpi_native_uint i; acpi_native_uint j; ACPI_FUNCTION_TRACE("ev_delete_gpe_handlers"); /* Examine each GPE Register within the block */ for (i = 0; i < gpe_block->register_count; i++) { /* Now look at the individual GPEs in this byte register */ for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { gpe_event_info = &gpe_block-> event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER) { ACPI_MEM_FREE(gpe_event_info->dispatch.handler); gpe_event_info->dispatch.handler = NULL; gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; } } } return_ACPI_STATUS(AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ev_save_method_info * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a * control method under the _GPE portion of the namespace. * Extract the name and GPE type from the object, saving this * information for quick lookup during GPE dispatch * * The name of each GPE control method is of the form: * "_Lxx" or "_Exx" * Where: * L - means that the GPE is level triggered * E - means that the GPE is edge triggered * xx - is the GPE number [in HEX] * ******************************************************************************/static acpi_statusacpi_ev_save_method_info(acpi_handle obj_handle, u32 level, void *obj_desc, void **return_value){ struct acpi_gpe_block_info *gpe_block = (void *)obj_desc; struct acpi_gpe_event_info *gpe_event_info; u32 gpe_number; char name[ACPI_NAME_SIZE + 1]; u8 type; acpi_status status; ACPI_FUNCTION_TRACE("ev_save_method_info"); /* * _Lxx and _Exx GPE method support * * 1) Extract the name from the object and convert to a string */ ACPI_MOVE_32_TO_32(name, &((struct acpi_namespace_node *)obj_handle)->name. integer); name[ACPI_NAME_SIZE] = 0; /* * 2) Edge/Level determination is based on the 2nd character * of the method name * * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE * if a _PRW object is found that points to this GPE. */ switch (name[1]) { case 'L': type = ACPI_GPE_LEVEL_TRIGGERED; break; case 'E': type = ACPI_GPE_EDGE_TRIGGERED; break; default: /* Unknown method type, just ignore it! */ ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n", name)); return_ACPI_STATUS(AE_OK); } /* Convert the last two characters of the name to the GPE Number */ gpe_number = ACPI_STRTOUL(&name[2], NULL, 16); if (gpe_number == ACPI_UINT32_MAX) { /* Conversion failed; invalid method, just ignore it */ ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n", name)); return_ACPI_STATUS(AE_OK); } /* Ensure that we have a valid GPE number for this GPE block */ if ((gpe_number < gpe_block->block_base_number) || (gpe_number >= (gpe_block->block_base_number + (gpe_block->register_count * 8)))) { /* * Not valid for this GPE block, just ignore it * However, it may be valid for a different GPE block, since GPE0 and GPE1 * methods both appear under \_GPE. */ return_ACPI_STATUS(AE_OK); } /* * Now we can add this information to the gpe_event_info block * for use during dispatch of this GPE. Default type is RUNTIME, although * this may change when the _PRW methods are executed later. */ gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number]; gpe_event_info->flags = (u8) (type | ACPI_GPE_DISPATCH_METHOD | ACPI_GPE_TYPE_RUNTIME); gpe_event_info->dispatch.method_node = (struct acpi_namespace_node *)obj_handle; /* Update enable mask, but don't enable the HW GPE as of yet */ status = acpi_ev_enable_gpe(gpe_event_info, FALSE); ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Registered GPE method %s as GPE number 0x%.2X\n", name, gpe_number)); return_ACPI_STATUS(status);}/******************************************************************************* * * FUNCTION: acpi_ev_match_prw_and_gpe * * PARAMETERS: Callback from walk_namespace * * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is * not aborted on a single _PRW failure. * * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a * Device. Run the _PRW method. If present, extract the GPE * number and mark the GPE as a WAKE GPE. * ******************************************************************************/static acpi_statusacpi_ev_match_prw_and_gpe(acpi_handle obj_handle, u32 level, void *info, void **return_value){ struct acpi_gpe_walk_info *gpe_info = (void *)info; struct acpi_namespace_node *gpe_device; struct acpi_gpe_block_info *gpe_block; struct acpi_namespace_node *target_gpe_device; struct acpi_gpe_event_info *gpe_event_info; union acpi_operand_object *pkg_desc; union acpi_operand_object *obj_desc; u32 gpe_number; acpi_status status; ACPI_FUNCTION_TRACE("ev_match_prw_and_gpe"); /* Check for a _PRW method under this device */ status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW, ACPI_BTYPE_PACKAGE, &pkg_desc); if (ACPI_FAILURE(status)) { /* Ignore all errors from _PRW, we don't want to abort the subsystem */ return_ACPI_STATUS(AE_OK); } /* The returned _PRW package must have at least two elements */ if (pkg_desc->package.count < 2) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -