evxface.c revision 69450
167754Smsmith/****************************************************************************** 267754Smsmith * 367754Smsmith * Module Name: evxface - External interfaces for ACPI events 469450Smsmith * $Revision: 96 $ 567754Smsmith * 667754Smsmith *****************************************************************************/ 767754Smsmith 867754Smsmith/****************************************************************************** 967754Smsmith * 1067754Smsmith * 1. Copyright Notice 1167754Smsmith * 1267754Smsmith * Some or all of this work - Copyright (c) 1999, Intel Corp. All rights 1367754Smsmith * reserved. 1467754Smsmith * 1567754Smsmith * 2. License 1667754Smsmith * 1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property 1867754Smsmith * rights. You may have additional license terms from the party that provided 1967754Smsmith * you this software, covering your right to use that party's intellectual 2067754Smsmith * property rights. 2167754Smsmith * 2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an 2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy, 2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered 2767754Smsmith * Code in any form, with the right to sublicense such rights; and 2867754Smsmith * 2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3067754Smsmith * license (with the right to sublicense), under only those claims of Intel 3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell, 3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof 3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright 3467754Smsmith * license, and in no event shall the patent license extend to any additions 3567754Smsmith * to or modifications of the Original Intel Code. No other license or right 3667754Smsmith * is granted directly or by implication, estoppel or otherwise; 3767754Smsmith * 3867754Smsmith * The above copyright and patent license is granted only if the following 3967754Smsmith * conditions are met: 4067754Smsmith * 4167754Smsmith * 3. Conditions 4267754Smsmith * 4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4467754Smsmith * Redistribution of source code of any substantial prton of the Covered 4567754Smsmith * Code or modification with rights to further distribute source must include 4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions, 4767754Smsmith * and the following Disclaimer and Export Compliance provision. In addition, 4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to 4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered 5067754Smsmith * Code and the date of any change. Licensee must include in that file the 5167754Smsmith * documentation of any changes made by any predecessor Licensee. Licensee 5267754Smsmith * must include a prominent statement that the modification is derived, 5367754Smsmith * directly or indirectly, from Original Intel Code. 5467754Smsmith * 5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5667754Smsmith * Redistribution of source code of any substantial portion of the Covered 5767754Smsmith * Code or modification without rights to further distribute source must 5867754Smsmith * include the following Disclaimer and Export Compliance provision in the 5967754Smsmith * documentation and/or other materials provided with distribution. In 6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any 6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the 6267754Smsmith * license from Licensee to its licensee is limited to the intellectual 6367754Smsmith * property embodied in the software Licensee provides to its licensee, and 6467754Smsmith * not to intellectual property embodied in modifications its licensee may 6567754Smsmith * make. 6667754Smsmith * 6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any 6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the 6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance 7067754Smsmith * provision in the documentation and/or other materials provided with the 7167754Smsmith * distribution. 7267754Smsmith * 7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original 7467754Smsmith * Intel Code. 7567754Smsmith * 7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or 7867754Smsmith * other dealings in products derived from or relating to the Covered Code 7967754Smsmith * without prior written authorization from Intel. 8067754Smsmith * 8167754Smsmith * 4. Disclaimer and Export Compliance 8267754Smsmith * 8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8467754Smsmith * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8767754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8867754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8967754Smsmith * PARTICULAR PURPOSE. 9067754Smsmith * 9167754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9267754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9367754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9467754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9567754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9667754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9767754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9867754Smsmith * LIMITED REMEDY. 9967754Smsmith * 10067754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this 10167754Smsmith * software or system incorporating such software without first obtaining any 10267754Smsmith * required license or other approval from the U. S. Department of Commerce or 10367754Smsmith * any other agency or department of the United States Government. In the 10467754Smsmith * event Licensee exports any such software from the United States or 10567754Smsmith * re-exports any such software from a foreign destination, Licensee shall 10667754Smsmith * ensure that the distribution and export/re-export of the software is in 10767754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the 10867754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10967754Smsmith * any of its subsidiaries will export/re-export any technical data, process, 11067754Smsmith * software, or service, directly or indirectly, to any country for which the 11167754Smsmith * United States government or any agency thereof requires an export license, 11267754Smsmith * other governmental approval, or letter of assurance, without first obtaining 11367754Smsmith * such license, approval or letter. 11467754Smsmith * 11567754Smsmith *****************************************************************************/ 11667754Smsmith 11767754Smsmith 11867754Smsmith#define __EVXFACE_C__ 11967754Smsmith 12067754Smsmith#include "acpi.h" 12167754Smsmith#include "achware.h" 12267754Smsmith#include "acnamesp.h" 12367754Smsmith#include "acevents.h" 12467754Smsmith#include "amlcode.h" 12567754Smsmith#include "acinterp.h" 12667754Smsmith 12767754Smsmith#define _COMPONENT EVENT_HANDLING 12867754Smsmith MODULE_NAME ("evxface") 12967754Smsmith 13067754Smsmith 13167754Smsmith/****************************************************************************** 13267754Smsmith * 13367754Smsmith * FUNCTION: AcpiInstallFixedEventHandler 13467754Smsmith * 13567754Smsmith * PARAMETERS: Event - Event type to enable. 13667754Smsmith * Handler - Pointer to the handler function for the 13767754Smsmith * event 13867754Smsmith * Context - Value passed to the handler on each GPE 13967754Smsmith * 14067754Smsmith * RETURN: Status 14167754Smsmith * 14267754Smsmith * DESCRIPTION: Saves the pointer to the handler function and then enables the 14367754Smsmith * event. 14467754Smsmith * 14567754Smsmith ******************************************************************************/ 14667754Smsmith 14767754SmsmithACPI_STATUS 14867754SmsmithAcpiInstallFixedEventHandler ( 14967754Smsmith UINT32 Event, 15067754Smsmith FIXED_EVENT_HANDLER Handler, 15167754Smsmith void *Context) 15267754Smsmith{ 15367754Smsmith ACPI_STATUS Status = AE_OK; 15467754Smsmith 15567754Smsmith 15667754Smsmith FUNCTION_TRACE ("AcpiInstallFixedEventHandler"); 15767754Smsmith 15867754Smsmith 15967754Smsmith /* Sanity check the parameters. */ 16067754Smsmith 16167754Smsmith if (Event >= NUM_FIXED_EVENTS) 16267754Smsmith { 16367754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 16467754Smsmith } 16567754Smsmith 16667754Smsmith AcpiCmAcquireMutex (ACPI_MTX_EVENTS); 16767754Smsmith 16867754Smsmith /* Don't allow two handlers. */ 16967754Smsmith 17067754Smsmith if (NULL != AcpiGbl_FixedEventHandlers[Event].Handler) 17167754Smsmith { 17267754Smsmith Status = AE_EXIST; 17367754Smsmith goto Cleanup; 17467754Smsmith } 17567754Smsmith 17667754Smsmith 17767754Smsmith /* Install the handler before enabling the event - just in case... */ 17867754Smsmith 17967754Smsmith AcpiGbl_FixedEventHandlers[Event].Handler = Handler; 18067754Smsmith AcpiGbl_FixedEventHandlers[Event].Context = Context; 18167754Smsmith 18269450Smsmith Status = AcpiEnableEvent(Event, ACPI_EVENT_FIXED); 18369450Smsmith 18469450Smsmith if (!ACPI_SUCCESS(Status)) 18567754Smsmith { 18669450Smsmith DEBUG_PRINT (ACPI_WARN, ("Could not enable fixed event.\n")); 18767754Smsmith 18867754Smsmith /* Remove the handler */ 18967754Smsmith 19067754Smsmith AcpiGbl_FixedEventHandlers[Event].Handler = NULL; 19167754Smsmith AcpiGbl_FixedEventHandlers[Event].Context = NULL; 19267754Smsmith 19367754Smsmith Status = AE_ERROR; 19467754Smsmith goto Cleanup; 19567754Smsmith } 19667754Smsmith 19767754Smsmith DEBUG_PRINT (ACPI_INFO, 19867754Smsmith ("Enabled fixed event %d. Handler: %x\n", Event, Handler)); 19967754Smsmith 20067754Smsmith 20167754SmsmithCleanup: 20267754Smsmith AcpiCmReleaseMutex (ACPI_MTX_EVENTS); 20367754Smsmith return_ACPI_STATUS (Status); 20467754Smsmith} 20567754Smsmith 20667754Smsmith 20767754Smsmith/****************************************************************************** 20867754Smsmith * 20967754Smsmith * FUNCTION: AcpiRemoveFixedEventHandler 21067754Smsmith * 21167754Smsmith * PARAMETERS: Event - Event type to disable. 21267754Smsmith * Handler - Address of the handler 21367754Smsmith * 21467754Smsmith * RETURN: Status 21567754Smsmith * 21667754Smsmith * DESCRIPTION: Disables the event and unregisters the event handler. 21767754Smsmith * 21867754Smsmith ******************************************************************************/ 21967754Smsmith 22067754SmsmithACPI_STATUS 22167754SmsmithAcpiRemoveFixedEventHandler ( 22267754Smsmith UINT32 Event, 22367754Smsmith FIXED_EVENT_HANDLER Handler) 22467754Smsmith{ 22567754Smsmith ACPI_STATUS Status = AE_OK; 22667754Smsmith 22767754Smsmith 22867754Smsmith FUNCTION_TRACE ("AcpiRemoveFixedEventHandler"); 22967754Smsmith 23067754Smsmith 23167754Smsmith /* Sanity check the parameters. */ 23267754Smsmith 23367754Smsmith if (Event >= NUM_FIXED_EVENTS) 23467754Smsmith { 23567754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 23667754Smsmith } 23767754Smsmith 23867754Smsmith AcpiCmAcquireMutex (ACPI_MTX_EVENTS); 23967754Smsmith 24067754Smsmith /* Disable the event before removing the handler - just in case... */ 24167754Smsmith 24269450Smsmith Status = AcpiDisableEvent(Event, ACPI_EVENT_FIXED); 24369450Smsmith 24469450Smsmith if (!ACPI_SUCCESS(Status)) 24567754Smsmith { 24667754Smsmith DEBUG_PRINT (ACPI_WARN, 24767754Smsmith ("Could not write to fixed event enable register.\n")); 24869450Smsmith 24967754Smsmith Status = AE_ERROR; 25069450Smsmith AcpiCmReleaseMutex (ACPI_MTX_EVENTS); 25169450Smsmith return_ACPI_STATUS (Status); 25267754Smsmith } 25367754Smsmith 25467754Smsmith /* Remove the handler */ 25567754Smsmith 25667754Smsmith AcpiGbl_FixedEventHandlers[Event].Handler = NULL; 25767754Smsmith AcpiGbl_FixedEventHandlers[Event].Context = NULL; 25867754Smsmith 25967754Smsmith DEBUG_PRINT (ACPI_INFO, ("Disabled fixed event %d.\n", Event)); 26067754Smsmith 26167754Smsmith AcpiCmReleaseMutex (ACPI_MTX_EVENTS); 26267754Smsmith return_ACPI_STATUS (Status); 26367754Smsmith} 26467754Smsmith 26567754Smsmith 26667754Smsmith/****************************************************************************** 26767754Smsmith * 26867754Smsmith * FUNCTION: AcpiInstallNotifyHandler 26967754Smsmith * 27067754Smsmith * PARAMETERS: Device - The device for which notifies will be handled 27167754Smsmith * HandlerType - The type of handler: 27267754Smsmith * ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f) 27367754Smsmith * ACPI_DEVICE_NOTIFY: DriverHandler (80-ff) 27467754Smsmith * Handler - Address of the handler 27567754Smsmith * Context - Value passed to the handler on each GPE 27667754Smsmith * 27767754Smsmith * RETURN: Status 27867754Smsmith * 27967754Smsmith * DESCRIPTION: Install a handler for notifies on an ACPI device 28067754Smsmith * 28167754Smsmith ******************************************************************************/ 28267754Smsmith 28367754SmsmithACPI_STATUS 28467754SmsmithAcpiInstallNotifyHandler ( 28567754Smsmith ACPI_HANDLE Device, 28667754Smsmith UINT32 HandlerType, 28767754Smsmith NOTIFY_HANDLER Handler, 28867754Smsmith void *Context) 28967754Smsmith{ 29067754Smsmith ACPI_OPERAND_OBJECT *ObjDesc; 29167754Smsmith ACPI_OPERAND_OBJECT *NotifyObj; 29267754Smsmith ACPI_NAMESPACE_NODE *DeviceNode; 29367754Smsmith ACPI_STATUS Status = AE_OK; 29467754Smsmith 29567754Smsmith 29667754Smsmith FUNCTION_TRACE ("AcpiInstallNotifyHandler"); 29767754Smsmith 29867754Smsmith 29967754Smsmith /* Parameter validation */ 30067754Smsmith 30167754Smsmith if ((!Handler) || 30267754Smsmith (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE)) 30367754Smsmith { 30467754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 30567754Smsmith } 30667754Smsmith 30767754Smsmith /* Convert and validate the device handle */ 30867754Smsmith 30967754Smsmith AcpiCmAcquireMutex (ACPI_MTX_NAMESPACE); 31067754Smsmith 31167754Smsmith DeviceNode = AcpiNsConvertHandleToEntry (Device); 31267754Smsmith if (!DeviceNode) 31367754Smsmith { 31467754Smsmith Status = AE_BAD_PARAMETER; 31567754Smsmith goto UnlockAndExit; 31667754Smsmith } 31767754Smsmith 31867754Smsmith 31967754Smsmith /* 32067754Smsmith * Support for global notify handlers. These handlers are invoked for 32167754Smsmith * every notifiy of the type specifiec 32267754Smsmith */ 32367754Smsmith 32467754Smsmith if (Device == ACPI_ROOT_OBJECT) 32567754Smsmith { 32667754Smsmith /* 32767754Smsmith * Make sure the handler is not already installed. 32867754Smsmith */ 32967754Smsmith 33067754Smsmith if (((HandlerType == ACPI_SYSTEM_NOTIFY) && 33167754Smsmith AcpiGbl_SysNotify.Handler) || 33267754Smsmith ((HandlerType == ACPI_DEVICE_NOTIFY) && 33367754Smsmith AcpiGbl_DrvNotify.Handler)) 33467754Smsmith { 33567754Smsmith Status = AE_EXIST; 33667754Smsmith goto UnlockAndExit; 33767754Smsmith } 33867754Smsmith 33967754Smsmith if (HandlerType == ACPI_SYSTEM_NOTIFY) 34067754Smsmith { 34167754Smsmith AcpiGbl_SysNotify.Node = DeviceNode; 34267754Smsmith AcpiGbl_SysNotify.Handler = Handler; 34367754Smsmith AcpiGbl_SysNotify.Context = Context; 34467754Smsmith } 34567754Smsmith 34667754Smsmith else 34767754Smsmith { 34867754Smsmith AcpiGbl_DrvNotify.Node = DeviceNode; 34967754Smsmith AcpiGbl_DrvNotify.Handler = Handler; 35067754Smsmith AcpiGbl_DrvNotify.Context = Context; 35167754Smsmith } 35267754Smsmith 35367754Smsmith 35467754Smsmith /* Global notify handler installed */ 35567754Smsmith 35667754Smsmith goto UnlockAndExit; 35767754Smsmith } 35867754Smsmith 35967754Smsmith 36067754Smsmith /* 36167754Smsmith * These are the ONLY objects that can receive ACPI notifications 36267754Smsmith */ 36367754Smsmith 36467754Smsmith if ((DeviceNode->Type != ACPI_TYPE_DEVICE) && 36567754Smsmith (DeviceNode->Type != ACPI_TYPE_PROCESSOR) && 36667754Smsmith (DeviceNode->Type != ACPI_TYPE_POWER) && 36767754Smsmith (DeviceNode->Type != ACPI_TYPE_THERMAL)) 36867754Smsmith { 36967754Smsmith Status = AE_BAD_PARAMETER; 37067754Smsmith goto UnlockAndExit; 37167754Smsmith } 37267754Smsmith 37367754Smsmith /* Check for an existing internal object */ 37467754Smsmith 37567754Smsmith ObjDesc = AcpiNsGetAttachedObject ((ACPI_HANDLE) DeviceNode); 37667754Smsmith if (ObjDesc) 37767754Smsmith { 37867754Smsmith /* 37967754Smsmith * The object exists. 38067754Smsmith * Make sure the handler is not already installed. 38167754Smsmith */ 38267754Smsmith 38367754Smsmith if (((HandlerType == ACPI_SYSTEM_NOTIFY) && 38467754Smsmith ObjDesc->Device.SysHandler) || 38567754Smsmith ((HandlerType == ACPI_DEVICE_NOTIFY) && 38667754Smsmith ObjDesc->Device.DrvHandler)) 38767754Smsmith { 38867754Smsmith Status = AE_EXIST; 38967754Smsmith goto UnlockAndExit; 39067754Smsmith } 39167754Smsmith } 39267754Smsmith 39367754Smsmith else 39467754Smsmith { 39567754Smsmith /* Create a new object */ 39667754Smsmith 39767754Smsmith ObjDesc = AcpiCmCreateInternalObject (DeviceNode->Type); 39867754Smsmith if (!ObjDesc) 39967754Smsmith { 40067754Smsmith Status = AE_NO_MEMORY; 40167754Smsmith goto UnlockAndExit; 40267754Smsmith } 40367754Smsmith 40467754Smsmith /* Attach new object to the Node */ 40567754Smsmith 40667754Smsmith Status = AcpiNsAttachObject (Device, ObjDesc, (UINT8) DeviceNode->Type); 40767754Smsmith 40867754Smsmith if (ACPI_FAILURE (Status)) 40967754Smsmith { 41067754Smsmith goto UnlockAndExit; 41167754Smsmith } 41267754Smsmith } 41367754Smsmith 41467754Smsmith 41567754Smsmith /* 41667754Smsmith * If we get here, we know that there is no handler installed 41767754Smsmith * so let's party 41867754Smsmith */ 41967754Smsmith NotifyObj = AcpiCmCreateInternalObject (INTERNAL_TYPE_NOTIFY); 42067754Smsmith if (!NotifyObj) 42167754Smsmith { 42267754Smsmith Status = AE_NO_MEMORY; 42367754Smsmith goto UnlockAndExit; 42467754Smsmith } 42567754Smsmith 42667754Smsmith NotifyObj->NotifyHandler.Node = DeviceNode; 42767754Smsmith NotifyObj->NotifyHandler.Handler = Handler; 42867754Smsmith NotifyObj->NotifyHandler.Context = Context; 42967754Smsmith 43067754Smsmith 43167754Smsmith if (HandlerType == ACPI_SYSTEM_NOTIFY) 43267754Smsmith { 43367754Smsmith ObjDesc->Device.SysHandler = NotifyObj; 43467754Smsmith } 43567754Smsmith 43667754Smsmith else 43767754Smsmith { 43867754Smsmith ObjDesc->Device.DrvHandler = NotifyObj; 43967754Smsmith } 44067754Smsmith 44167754Smsmith 44267754SmsmithUnlockAndExit: 44367754Smsmith AcpiCmReleaseMutex (ACPI_MTX_NAMESPACE); 44467754Smsmith return_ACPI_STATUS (Status); 44567754Smsmith} 44667754Smsmith 44767754Smsmith 44867754Smsmith/***************************************************************************** 44967754Smsmith * 45067754Smsmith * FUNCTION: AcpiRemoveNotifyHandler 45167754Smsmith * 45267754Smsmith * PARAMETERS: Device - The device for which notifies will be handled 45367754Smsmith * HandlerType - The type of handler: 45467754Smsmith * ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f) 45567754Smsmith * ACPI_DEVICE_NOTIFY: DriverHandler (80-ff) 45667754Smsmith * Handler - Address of the handler 45767754Smsmith * RETURN: Status 45867754Smsmith * 45967754Smsmith * DESCRIPTION: Remove a handler for notifies on an ACPI device 46067754Smsmith * 46167754Smsmith ******************************************************************************/ 46267754Smsmith 46367754SmsmithACPI_STATUS 46467754SmsmithAcpiRemoveNotifyHandler ( 46567754Smsmith ACPI_HANDLE Device, 46667754Smsmith UINT32 HandlerType, 46767754Smsmith NOTIFY_HANDLER Handler) 46867754Smsmith{ 46967754Smsmith ACPI_OPERAND_OBJECT *NotifyObj; 47067754Smsmith ACPI_OPERAND_OBJECT *ObjDesc; 47167754Smsmith ACPI_NAMESPACE_NODE *DeviceNode; 47267754Smsmith ACPI_STATUS Status = AE_OK; 47367754Smsmith 47467754Smsmith 47567754Smsmith FUNCTION_TRACE ("AcpiRemoveNotifyHandler"); 47667754Smsmith 47767754Smsmith 47867754Smsmith /* Parameter validation */ 47967754Smsmith 48067754Smsmith if ((!Handler) || 48167754Smsmith (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE)) 48267754Smsmith { 48367754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 48467754Smsmith } 48567754Smsmith 48667754Smsmith AcpiCmAcquireMutex (ACPI_MTX_NAMESPACE); 48767754Smsmith 48867754Smsmith /* Convert and validate the device handle */ 48967754Smsmith 49067754Smsmith DeviceNode = AcpiNsConvertHandleToEntry (Device); 49167754Smsmith if (!DeviceNode) 49267754Smsmith { 49367754Smsmith Status = AE_BAD_PARAMETER; 49467754Smsmith goto UnlockAndExit; 49567754Smsmith } 49667754Smsmith 49767754Smsmith /* 49867754Smsmith * These are the ONLY objects that can receive ACPI notifications 49967754Smsmith */ 50067754Smsmith 50167754Smsmith if ((DeviceNode->Type != ACPI_TYPE_DEVICE) && 50267754Smsmith (DeviceNode->Type != ACPI_TYPE_PROCESSOR) && 50367754Smsmith (DeviceNode->Type != ACPI_TYPE_POWER) && 50467754Smsmith (DeviceNode->Type != ACPI_TYPE_THERMAL)) 50567754Smsmith { 50667754Smsmith Status = AE_BAD_PARAMETER; 50767754Smsmith goto UnlockAndExit; 50867754Smsmith } 50967754Smsmith 51067754Smsmith /* Check for an existing internal object */ 51167754Smsmith 51267754Smsmith ObjDesc = AcpiNsGetAttachedObject ((ACPI_HANDLE) DeviceNode); 51367754Smsmith if (!ObjDesc) 51467754Smsmith { 51567754Smsmith Status = AE_NOT_EXIST; 51667754Smsmith goto UnlockAndExit; 51767754Smsmith } 51867754Smsmith 51967754Smsmith /* 52067754Smsmith * The object exists. 52167754Smsmith * 52267754Smsmith * Make sure the handler is installed. 52367754Smsmith */ 52467754Smsmith 52567754Smsmith if (HandlerType == ACPI_SYSTEM_NOTIFY) 52667754Smsmith { 52767754Smsmith NotifyObj = ObjDesc->Device.SysHandler; 52867754Smsmith } 52967754Smsmith else 53067754Smsmith { 53167754Smsmith NotifyObj = ObjDesc->Device.DrvHandler; 53267754Smsmith } 53367754Smsmith 53467754Smsmith if ((!NotifyObj) || 53567754Smsmith (NotifyObj->NotifyHandler.Handler != Handler)) 53667754Smsmith { 53767754Smsmith Status = AE_BAD_PARAMETER; 53867754Smsmith goto UnlockAndExit; 53967754Smsmith } 54067754Smsmith 54167754Smsmith /* 54267754Smsmith * Now we can remove the handler 54367754Smsmith */ 54467754Smsmith if (HandlerType == ACPI_SYSTEM_NOTIFY) 54567754Smsmith { 54667754Smsmith ObjDesc->Device.SysHandler = NULL; 54767754Smsmith } 54867754Smsmith else 54967754Smsmith { 55067754Smsmith ObjDesc->Device.DrvHandler = NULL; 55167754Smsmith } 55267754Smsmith 55367754Smsmith AcpiCmRemoveReference (NotifyObj); 55467754Smsmith 55567754SmsmithUnlockAndExit: 55667754Smsmith AcpiCmReleaseMutex (ACPI_MTX_NAMESPACE); 55767754Smsmith return_ACPI_STATUS (Status); 55867754Smsmith} 55967754Smsmith 56067754Smsmith/****************************************************************************** 56167754Smsmith * 56267754Smsmith * FUNCTION: AcpiInstallGpeHandler 56367754Smsmith * 56467754Smsmith * PARAMETERS: GpeNumber - The GPE number. The numbering scheme is 56567754Smsmith * bank 0 first, then bank 1. 56667754Smsmith * Type - Whether this GPE should be treated as an 56767754Smsmith * edge- or level-triggered interrupt. 56867754Smsmith * Handler - Address of the handler 56967754Smsmith * Context - Value passed to the handler on each GPE 57067754Smsmith * 57167754Smsmith * RETURN: Status 57267754Smsmith * 57367754Smsmith * DESCRIPTION: Install a handler for a General Purpose Event. 57467754Smsmith * 57567754Smsmith ******************************************************************************/ 57667754Smsmith 57767754SmsmithACPI_STATUS 57867754SmsmithAcpiInstallGpeHandler ( 57967754Smsmith UINT32 GpeNumber, 58067754Smsmith UINT32 Type, 58167754Smsmith GPE_HANDLER Handler, 58267754Smsmith void *Context) 58367754Smsmith{ 58467754Smsmith ACPI_STATUS Status = AE_OK; 58567754Smsmith 58667754Smsmith FUNCTION_TRACE ("AcpiInstallGpeHandler"); 58767754Smsmith 58867754Smsmith /* Parameter validation */ 58967754Smsmith 59067754Smsmith if (!Handler || (GpeNumber > NUM_GPE)) 59167754Smsmith { 59267754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 59367754Smsmith } 59467754Smsmith 59567754Smsmith /* Ensure that we have a valid GPE number */ 59667754Smsmith 59767754Smsmith if (AcpiGbl_GpeValid[GpeNumber] == ACPI_GPE_INVALID) 59867754Smsmith { 59967754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 60067754Smsmith } 60167754Smsmith 60267754Smsmith AcpiCmAcquireMutex (ACPI_MTX_EVENTS); 60367754Smsmith 60467754Smsmith /* Make sure that there isn't a handler there already */ 60567754Smsmith 60667754Smsmith if (AcpiGbl_GpeInfo[GpeNumber].Handler) 60767754Smsmith { 60867754Smsmith Status = AE_EXIST; 60967754Smsmith goto Cleanup; 61067754Smsmith } 61167754Smsmith 61267754Smsmith /* Install the handler */ 61367754Smsmith 61467754Smsmith AcpiGbl_GpeInfo[GpeNumber].Handler = Handler; 61567754Smsmith AcpiGbl_GpeInfo[GpeNumber].Context = Context; 61667754Smsmith AcpiGbl_GpeInfo[GpeNumber].Type = (UINT8) Type; 61767754Smsmith 61867754Smsmith /* Clear the GPE (of stale events), the enable it */ 61967754Smsmith 62067754Smsmith AcpiHwClearGpe (GpeNumber); 62167754Smsmith AcpiHwEnableGpe (GpeNumber); 62267754Smsmith 62367754SmsmithCleanup: 62467754Smsmith AcpiCmReleaseMutex (ACPI_MTX_EVENTS); 62567754Smsmith return_ACPI_STATUS (Status); 62667754Smsmith} 62767754Smsmith 62867754Smsmith 62967754Smsmith/****************************************************************************** 63067754Smsmith * 63167754Smsmith * FUNCTION: AcpiRemoveGpeHandler 63267754Smsmith * 63367754Smsmith * PARAMETERS: GpeNumber - The event to remove a handler 63467754Smsmith * Handler - Address of the handler 63567754Smsmith * 63667754Smsmith * RETURN: Status 63767754Smsmith * 63867754Smsmith * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent. 63967754Smsmith * 64067754Smsmith ******************************************************************************/ 64167754Smsmith 64267754SmsmithACPI_STATUS 64367754SmsmithAcpiRemoveGpeHandler ( 64467754Smsmith UINT32 GpeNumber, 64567754Smsmith GPE_HANDLER Handler) 64667754Smsmith{ 64767754Smsmith ACPI_STATUS Status = AE_OK; 64867754Smsmith 64967754Smsmith 65067754Smsmith FUNCTION_TRACE ("AcpiRemoveGpeHandler"); 65167754Smsmith 65267754Smsmith 65367754Smsmith /* Parameter validation */ 65467754Smsmith 65567754Smsmith if (!Handler || (GpeNumber > NUM_GPE)) 65667754Smsmith { 65767754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 65867754Smsmith } 65967754Smsmith 66067754Smsmith /* Ensure that we have a valid GPE number */ 66167754Smsmith 66267754Smsmith if (AcpiGbl_GpeValid[GpeNumber] == ACPI_GPE_INVALID) 66367754Smsmith { 66467754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 66567754Smsmith } 66667754Smsmith 66767754Smsmith /* Disable the GPE before removing the handler */ 66867754Smsmith 66967754Smsmith AcpiHwDisableGpe (GpeNumber); 67067754Smsmith 67167754Smsmith AcpiCmAcquireMutex (ACPI_MTX_EVENTS); 67267754Smsmith 67367754Smsmith /* Make sure that the installed handler is the same */ 67467754Smsmith 67567754Smsmith if (AcpiGbl_GpeInfo[GpeNumber].Handler != Handler) 67667754Smsmith { 67767754Smsmith AcpiHwEnableGpe (GpeNumber); 67867754Smsmith Status = AE_BAD_PARAMETER; 67967754Smsmith goto Cleanup; 68067754Smsmith } 68167754Smsmith 68267754Smsmith /* Remove the handler */ 68367754Smsmith 68467754Smsmith AcpiGbl_GpeInfo[GpeNumber].Handler = NULL; 68567754Smsmith AcpiGbl_GpeInfo[GpeNumber].Context = NULL; 68667754Smsmith 68767754SmsmithCleanup: 68867754Smsmith AcpiCmReleaseMutex (ACPI_MTX_EVENTS); 68967754Smsmith return_ACPI_STATUS (Status); 69067754Smsmith} 69167754Smsmith 69267754Smsmith 69367754Smsmith/****************************************************************************** 69467754Smsmith * 69567754Smsmith * FUNCTION: AcpiAcquireGlobalLock 69667754Smsmith * 69767754Smsmith * PARAMETERS: Timeout - How long the caller is willing to wait 69867754Smsmith * OutHandle - A handle to the lock if acquired 69967754Smsmith * 70067754Smsmith * RETURN: Status 70167754Smsmith * 70267754Smsmith * DESCRIPTION: Acquire the ACPI Global Lock 70367754Smsmith * 70467754Smsmith ******************************************************************************/ 70567754SmsmithACPI_STATUS 70667754SmsmithAcpiAcquireGlobalLock ( 70767754Smsmith void) 70867754Smsmith{ 70967754Smsmith ACPI_STATUS Status; 71067754Smsmith 71167754Smsmith 71267754Smsmith AcpiAmlEnterInterpreter (); 71367754Smsmith 71467754Smsmith /* 71567754Smsmith * TBD: [Restructure] add timeout param to internal interface, and 71667754Smsmith * perhaps INTERPRETER_LOCKED 71767754Smsmith */ 71867754Smsmith 71967754Smsmith Status = AcpiEvAcquireGlobalLock (); 72067754Smsmith AcpiAmlExitInterpreter (); 72167754Smsmith 72267754Smsmith return (Status); 72367754Smsmith} 72467754Smsmith 72567754Smsmith 72667754Smsmith/****************************************************************************** 72767754Smsmith * 72867754Smsmith * FUNCTION: AcpiReleaseGlobalLock 72967754Smsmith * 73067754Smsmith * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock 73167754Smsmith * 73267754Smsmith * RETURN: Status 73367754Smsmith * 73467754Smsmith * DESCRIPTION: Release the ACPI Global Lock 73567754Smsmith * 73667754Smsmith ******************************************************************************/ 73767754Smsmith 73867754SmsmithACPI_STATUS 73967754SmsmithAcpiReleaseGlobalLock ( 74067754Smsmith void) 74167754Smsmith{ 74267754Smsmith AcpiEvReleaseGlobalLock (); 74367754Smsmith return (AE_OK); 74467754Smsmith} 74567754Smsmith 74667754Smsmith 747