📄 evgpeblk.c
字号:
/****************************************************************************** * * Module Name: evgpeblk - GPE block creation and initialization. * *****************************************************************************//* * Copyright (C) 2000 - 2004, 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_EVENTS ACPI_MODULE_NAME ("evgpeblk")/******************************************************************************* * * 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. * ******************************************************************************/u8acpi_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. * FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED * ******************************************************************************/acpi_statusacpi_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; ACPI_FUNCTION_TRACE ("ev_walk_gpe_list"); acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_ISR); /* 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, ACPI_ISR); return_ACPI_STATUS (status);}/******************************************************************************* * * 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_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 | ACPI_GPE_TYPE_RUNTIME; break; case 'E': type = ACPI_GPE_EDGE_TRIGGERED | ACPI_GPE_TYPE_RUNTIME; 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. */ gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number]; gpe_event_info->flags = type; gpe_event_info->method_node = (struct acpi_namespace_node *) obj_handle; ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Registered GPE method %s as GPE number 0x%.2X\n", name, gpe_number)); return_ACPI_STATUS (AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ev_get_gpe_type * * PARAMETERS: Callback from walk_namespace * * RETURN: Status * * 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_get_gpe_type ( 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_get_gpe_type"); /* Check for a _PRW method under this device */ status = acpi_ut_evaluate_object (obj_handle, METHOD_NAME__PRW, ACPI_BTYPE_PACKAGE, &pkg_desc); if (status == AE_NOT_FOUND) { return_ACPI_STATUS (AE_OK); } else if (ACPI_FAILURE (status)) { return_ACPI_STATUS (status); } /* The returned _PRW package must have at least two elements */ if (pkg_desc->package.count < 2) { goto cleanup; } /* Extract pointers from the input context */ gpe_device = gpe_info->gpe_device; gpe_block = gpe_info->gpe_block; /* * The _PRW object must return a package, we are only interested * in the first element */ obj_desc = pkg_desc->package.elements[0]; if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) { /* Use FADT-defined GPE device (from definition of _PRW) */ target_gpe_device = acpi_gbl_fadt_gpe_device; /* Integer is the GPE number in the FADT described GPE blocks */ gpe_number = (u32) obj_desc->integer.value; } else if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) { /* Package contains a GPE reference and GPE number within a GPE block */ if ((obj_desc->package.count < 2) || (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[0]) != ACPI_TYPE_LOCAL_REFERENCE) || (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[1]) != ACPI_TYPE_INTEGER)) { goto cleanup; } /* Get GPE block reference and decode */ target_gpe_device = obj_desc->package.elements[0]->reference.node; gpe_number = (u32) obj_desc->package.elements[1]->integer.value; } else { /* Unknown type, just ignore it */ goto cleanup; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -