Home | History | Annotate | Line # | Download | only in events
evxface.c revision 1.1
      1  1.1  jruoho /******************************************************************************
      2  1.1  jruoho  *
      3  1.1  jruoho  * Module Name: evxface - External interfaces for ACPI events
      4  1.1  jruoho  *
      5  1.1  jruoho  *****************************************************************************/
      6  1.1  jruoho 
      7  1.1  jruoho /******************************************************************************
      8  1.1  jruoho  *
      9  1.1  jruoho  * 1. Copyright Notice
     10  1.1  jruoho  *
     11  1.1  jruoho  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     12  1.1  jruoho  * All rights reserved.
     13  1.1  jruoho  *
     14  1.1  jruoho  * 2. License
     15  1.1  jruoho  *
     16  1.1  jruoho  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1  jruoho  * rights.  You may have additional license terms from the party that provided
     18  1.1  jruoho  * you this software, covering your right to use that party's intellectual
     19  1.1  jruoho  * property rights.
     20  1.1  jruoho  *
     21  1.1  jruoho  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1  jruoho  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1  jruoho  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1  jruoho  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1  jruoho  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1  jruoho  * Code in any form, with the right to sublicense such rights; and
     27  1.1  jruoho  *
     28  1.1  jruoho  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1  jruoho  * license (with the right to sublicense), under only those claims of Intel
     30  1.1  jruoho  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1  jruoho  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1  jruoho  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1  jruoho  * license, and in no event shall the patent license extend to any additions
     34  1.1  jruoho  * to or modifications of the Original Intel Code.  No other license or right
     35  1.1  jruoho  * is granted directly or by implication, estoppel or otherwise;
     36  1.1  jruoho  *
     37  1.1  jruoho  * The above copyright and patent license is granted only if the following
     38  1.1  jruoho  * conditions are met:
     39  1.1  jruoho  *
     40  1.1  jruoho  * 3. Conditions
     41  1.1  jruoho  *
     42  1.1  jruoho  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     44  1.1  jruoho  * Code or modification with rights to further distribute source must include
     45  1.1  jruoho  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1  jruoho  * and the following Disclaimer and Export Compliance provision.  In addition,
     47  1.1  jruoho  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1  jruoho  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1  jruoho  * Code and the date of any change.  Licensee must include in that file the
     50  1.1  jruoho  * documentation of any changes made by any predecessor Licensee.  Licensee
     51  1.1  jruoho  * must include a prominent statement that the modification is derived,
     52  1.1  jruoho  * directly or indirectly, from Original Intel Code.
     53  1.1  jruoho  *
     54  1.1  jruoho  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     56  1.1  jruoho  * Code or modification without rights to further distribute source must
     57  1.1  jruoho  * include the following Disclaimer and Export Compliance provision in the
     58  1.1  jruoho  * documentation and/or other materials provided with distribution.  In
     59  1.1  jruoho  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1  jruoho  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1  jruoho  * license from Licensee to its licensee is limited to the intellectual
     62  1.1  jruoho  * property embodied in the software Licensee provides to its licensee, and
     63  1.1  jruoho  * not to intellectual property embodied in modifications its licensee may
     64  1.1  jruoho  * make.
     65  1.1  jruoho  *
     66  1.1  jruoho  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1  jruoho  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1  jruoho  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1  jruoho  * provision in the documentation and/or other materials provided with the
     70  1.1  jruoho  * distribution.
     71  1.1  jruoho  *
     72  1.1  jruoho  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1  jruoho  * Intel Code.
     74  1.1  jruoho  *
     75  1.1  jruoho  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1  jruoho  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1  jruoho  * other dealings in products derived from or relating to the Covered Code
     78  1.1  jruoho  * without prior written authorization from Intel.
     79  1.1  jruoho  *
     80  1.1  jruoho  * 4. Disclaimer and Export Compliance
     81  1.1  jruoho  *
     82  1.1  jruoho  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1  jruoho  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1  jruoho  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     85  1.1  jruoho  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     86  1.1  jruoho  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1  jruoho  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1  jruoho  * PARTICULAR PURPOSE.
     89  1.1  jruoho  *
     90  1.1  jruoho  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1  jruoho  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1  jruoho  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1  jruoho  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1  jruoho  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1  jruoho  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     96  1.1  jruoho  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1  jruoho  * LIMITED REMEDY.
     98  1.1  jruoho  *
     99  1.1  jruoho  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1  jruoho  * software or system incorporating such software without first obtaining any
    101  1.1  jruoho  * required license or other approval from the U. S. Department of Commerce or
    102  1.1  jruoho  * any other agency or department of the United States Government.  In the
    103  1.1  jruoho  * event Licensee exports any such software from the United States or
    104  1.1  jruoho  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1  jruoho  * ensure that the distribution and export/re-export of the software is in
    106  1.1  jruoho  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1  jruoho  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1  jruoho  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1  jruoho  * software, or service, directly or indirectly, to any country for which the
    110  1.1  jruoho  * United States government or any agency thereof requires an export license,
    111  1.1  jruoho  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1  jruoho  * such license, approval or letter.
    113  1.1  jruoho  *
    114  1.1  jruoho  *****************************************************************************/
    115  1.1  jruoho 
    116  1.1  jruoho 
    117  1.1  jruoho #define __EVXFACE_C__
    118  1.1  jruoho 
    119  1.1  jruoho #include "acpi.h"
    120  1.1  jruoho #include "accommon.h"
    121  1.1  jruoho #include "acnamesp.h"
    122  1.1  jruoho #include "acevents.h"
    123  1.1  jruoho #include "acinterp.h"
    124  1.1  jruoho 
    125  1.1  jruoho #define _COMPONENT          ACPI_EVENTS
    126  1.1  jruoho         ACPI_MODULE_NAME    ("evxface")
    127  1.1  jruoho 
    128  1.1  jruoho 
    129  1.1  jruoho /*******************************************************************************
    130  1.1  jruoho  *
    131  1.1  jruoho  * FUNCTION:    AcpiInstallExceptionHandler
    132  1.1  jruoho  *
    133  1.1  jruoho  * PARAMETERS:  Handler         - Pointer to the handler function for the
    134  1.1  jruoho  *                                event
    135  1.1  jruoho  *
    136  1.1  jruoho  * RETURN:      Status
    137  1.1  jruoho  *
    138  1.1  jruoho  * DESCRIPTION: Saves the pointer to the handler function
    139  1.1  jruoho  *
    140  1.1  jruoho  ******************************************************************************/
    141  1.1  jruoho 
    142  1.1  jruoho ACPI_STATUS
    143  1.1  jruoho AcpiInstallExceptionHandler (
    144  1.1  jruoho     ACPI_EXCEPTION_HANDLER  Handler)
    145  1.1  jruoho {
    146  1.1  jruoho     ACPI_STATUS             Status;
    147  1.1  jruoho 
    148  1.1  jruoho 
    149  1.1  jruoho     ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler);
    150  1.1  jruoho 
    151  1.1  jruoho 
    152  1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    153  1.1  jruoho     if (ACPI_FAILURE (Status))
    154  1.1  jruoho     {
    155  1.1  jruoho         return_ACPI_STATUS (Status);
    156  1.1  jruoho     }
    157  1.1  jruoho 
    158  1.1  jruoho     /* Don't allow two handlers. */
    159  1.1  jruoho 
    160  1.1  jruoho     if (AcpiGbl_ExceptionHandler)
    161  1.1  jruoho     {
    162  1.1  jruoho         Status = AE_ALREADY_EXISTS;
    163  1.1  jruoho         goto Cleanup;
    164  1.1  jruoho     }
    165  1.1  jruoho 
    166  1.1  jruoho     /* Install the handler */
    167  1.1  jruoho 
    168  1.1  jruoho     AcpiGbl_ExceptionHandler = Handler;
    169  1.1  jruoho 
    170  1.1  jruoho Cleanup:
    171  1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    172  1.1  jruoho     return_ACPI_STATUS (Status);
    173  1.1  jruoho }
    174  1.1  jruoho 
    175  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler)
    176  1.1  jruoho 
    177  1.1  jruoho 
    178  1.1  jruoho /*******************************************************************************
    179  1.1  jruoho  *
    180  1.1  jruoho  * FUNCTION:    AcpiInstallFixedEventHandler
    181  1.1  jruoho  *
    182  1.1  jruoho  * PARAMETERS:  Event           - Event type to enable.
    183  1.1  jruoho  *              Handler         - Pointer to the handler function for the
    184  1.1  jruoho  *                                event
    185  1.1  jruoho  *              Context         - Value passed to the handler on each GPE
    186  1.1  jruoho  *
    187  1.1  jruoho  * RETURN:      Status
    188  1.1  jruoho  *
    189  1.1  jruoho  * DESCRIPTION: Saves the pointer to the handler function and then enables the
    190  1.1  jruoho  *              event.
    191  1.1  jruoho  *
    192  1.1  jruoho  ******************************************************************************/
    193  1.1  jruoho 
    194  1.1  jruoho ACPI_STATUS
    195  1.1  jruoho AcpiInstallFixedEventHandler (
    196  1.1  jruoho     UINT32                  Event,
    197  1.1  jruoho     ACPI_EVENT_HANDLER      Handler,
    198  1.1  jruoho     void                    *Context)
    199  1.1  jruoho {
    200  1.1  jruoho     ACPI_STATUS             Status;
    201  1.1  jruoho 
    202  1.1  jruoho 
    203  1.1  jruoho     ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler);
    204  1.1  jruoho 
    205  1.1  jruoho 
    206  1.1  jruoho     /* Parameter validation */
    207  1.1  jruoho 
    208  1.1  jruoho     if (Event > ACPI_EVENT_MAX)
    209  1.1  jruoho     {
    210  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    211  1.1  jruoho     }
    212  1.1  jruoho 
    213  1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    214  1.1  jruoho     if (ACPI_FAILURE (Status))
    215  1.1  jruoho     {
    216  1.1  jruoho         return_ACPI_STATUS (Status);
    217  1.1  jruoho     }
    218  1.1  jruoho 
    219  1.1  jruoho     /* Don't allow two handlers. */
    220  1.1  jruoho 
    221  1.1  jruoho     if (NULL != AcpiGbl_FixedEventHandlers[Event].Handler)
    222  1.1  jruoho     {
    223  1.1  jruoho         Status = AE_ALREADY_EXISTS;
    224  1.1  jruoho         goto Cleanup;
    225  1.1  jruoho     }
    226  1.1  jruoho 
    227  1.1  jruoho     /* Install the handler before enabling the event */
    228  1.1  jruoho 
    229  1.1  jruoho     AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
    230  1.1  jruoho     AcpiGbl_FixedEventHandlers[Event].Context = Context;
    231  1.1  jruoho 
    232  1.1  jruoho     Status = AcpiEnableEvent (Event, 0);
    233  1.1  jruoho     if (ACPI_FAILURE (Status))
    234  1.1  jruoho     {
    235  1.1  jruoho         ACPI_WARNING ((AE_INFO, "Could not enable fixed event 0x%X", Event));
    236  1.1  jruoho 
    237  1.1  jruoho         /* Remove the handler */
    238  1.1  jruoho 
    239  1.1  jruoho         AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
    240  1.1  jruoho         AcpiGbl_FixedEventHandlers[Event].Context = NULL;
    241  1.1  jruoho     }
    242  1.1  jruoho     else
    243  1.1  jruoho     {
    244  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    245  1.1  jruoho             "Enabled fixed event %X, Handler=%p\n", Event, Handler));
    246  1.1  jruoho     }
    247  1.1  jruoho 
    248  1.1  jruoho 
    249  1.1  jruoho Cleanup:
    250  1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    251  1.1  jruoho     return_ACPI_STATUS (Status);
    252  1.1  jruoho }
    253  1.1  jruoho 
    254  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler)
    255  1.1  jruoho 
    256  1.1  jruoho 
    257  1.1  jruoho /*******************************************************************************
    258  1.1  jruoho  *
    259  1.1  jruoho  * FUNCTION:    AcpiRemoveFixedEventHandler
    260  1.1  jruoho  *
    261  1.1  jruoho  * PARAMETERS:  Event           - Event type to disable.
    262  1.1  jruoho  *              Handler         - Address of the handler
    263  1.1  jruoho  *
    264  1.1  jruoho  * RETURN:      Status
    265  1.1  jruoho  *
    266  1.1  jruoho  * DESCRIPTION: Disables the event and unregisters the event handler.
    267  1.1  jruoho  *
    268  1.1  jruoho  ******************************************************************************/
    269  1.1  jruoho 
    270  1.1  jruoho ACPI_STATUS
    271  1.1  jruoho AcpiRemoveFixedEventHandler (
    272  1.1  jruoho     UINT32                  Event,
    273  1.1  jruoho     ACPI_EVENT_HANDLER      Handler)
    274  1.1  jruoho {
    275  1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    276  1.1  jruoho 
    277  1.1  jruoho 
    278  1.1  jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler);
    279  1.1  jruoho 
    280  1.1  jruoho 
    281  1.1  jruoho     /* Parameter validation */
    282  1.1  jruoho 
    283  1.1  jruoho     if (Event > ACPI_EVENT_MAX)
    284  1.1  jruoho     {
    285  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    286  1.1  jruoho     }
    287  1.1  jruoho 
    288  1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    289  1.1  jruoho     if (ACPI_FAILURE (Status))
    290  1.1  jruoho     {
    291  1.1  jruoho         return_ACPI_STATUS (Status);
    292  1.1  jruoho     }
    293  1.1  jruoho 
    294  1.1  jruoho     /* Disable the event before removing the handler */
    295  1.1  jruoho 
    296  1.1  jruoho     Status = AcpiDisableEvent (Event, 0);
    297  1.1  jruoho 
    298  1.1  jruoho     /* Always Remove the handler */
    299  1.1  jruoho 
    300  1.1  jruoho     AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
    301  1.1  jruoho     AcpiGbl_FixedEventHandlers[Event].Context = NULL;
    302  1.1  jruoho 
    303  1.1  jruoho     if (ACPI_FAILURE (Status))
    304  1.1  jruoho     {
    305  1.1  jruoho         ACPI_WARNING ((AE_INFO,
    306  1.1  jruoho             "Could not write to fixed event enable register 0x%X", Event));
    307  1.1  jruoho     }
    308  1.1  jruoho     else
    309  1.1  jruoho     {
    310  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Disabled fixed event %X\n", Event));
    311  1.1  jruoho     }
    312  1.1  jruoho 
    313  1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    314  1.1  jruoho     return_ACPI_STATUS (Status);
    315  1.1  jruoho }
    316  1.1  jruoho 
    317  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler)
    318  1.1  jruoho 
    319  1.1  jruoho 
    320  1.1  jruoho /*******************************************************************************
    321  1.1  jruoho  *
    322  1.1  jruoho  * FUNCTION:    AcpiInstallNotifyHandler
    323  1.1  jruoho  *
    324  1.1  jruoho  * PARAMETERS:  Device          - The device for which notifies will be handled
    325  1.1  jruoho  *              HandlerType     - The type of handler:
    326  1.1  jruoho  *                                  ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
    327  1.1  jruoho  *                                  ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
    328  1.1  jruoho  *                                  ACPI_ALL_NOTIFY:  both system and device
    329  1.1  jruoho  *              Handler         - Address of the handler
    330  1.1  jruoho  *              Context         - Value passed to the handler on each GPE
    331  1.1  jruoho  *
    332  1.1  jruoho  * RETURN:      Status
    333  1.1  jruoho  *
    334  1.1  jruoho  * DESCRIPTION: Install a handler for notifies on an ACPI device
    335  1.1  jruoho  *
    336  1.1  jruoho  ******************************************************************************/
    337  1.1  jruoho 
    338  1.1  jruoho ACPI_STATUS
    339  1.1  jruoho AcpiInstallNotifyHandler (
    340  1.1  jruoho     ACPI_HANDLE             Device,
    341  1.1  jruoho     UINT32                  HandlerType,
    342  1.1  jruoho     ACPI_NOTIFY_HANDLER     Handler,
    343  1.1  jruoho     void                    *Context)
    344  1.1  jruoho {
    345  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    346  1.1  jruoho     ACPI_OPERAND_OBJECT     *NotifyObj;
    347  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node;
    348  1.1  jruoho     ACPI_STATUS             Status;
    349  1.1  jruoho 
    350  1.1  jruoho 
    351  1.1  jruoho     ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler);
    352  1.1  jruoho 
    353  1.1  jruoho 
    354  1.1  jruoho     /* Parameter validation */
    355  1.1  jruoho 
    356  1.1  jruoho     if ((!Device)  ||
    357  1.1  jruoho         (!Handler) ||
    358  1.1  jruoho         (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
    359  1.1  jruoho     {
    360  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    361  1.1  jruoho     }
    362  1.1  jruoho 
    363  1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    364  1.1  jruoho     if (ACPI_FAILURE (Status))
    365  1.1  jruoho     {
    366  1.1  jruoho         return_ACPI_STATUS (Status);
    367  1.1  jruoho     }
    368  1.1  jruoho 
    369  1.1  jruoho     /* Convert and validate the device handle */
    370  1.1  jruoho 
    371  1.1  jruoho     Node = AcpiNsValidateHandle (Device);
    372  1.1  jruoho     if (!Node)
    373  1.1  jruoho     {
    374  1.1  jruoho         Status = AE_BAD_PARAMETER;
    375  1.1  jruoho         goto UnlockAndExit;
    376  1.1  jruoho     }
    377  1.1  jruoho 
    378  1.1  jruoho     /*
    379  1.1  jruoho      * Root Object:
    380  1.1  jruoho      * Registering a notify handler on the root object indicates that the
    381  1.1  jruoho      * caller wishes to receive notifications for all objects. Note that
    382  1.1  jruoho      * only one <external> global handler can be regsitered (per notify type).
    383  1.1  jruoho      */
    384  1.1  jruoho     if (Device == ACPI_ROOT_OBJECT)
    385  1.1  jruoho     {
    386  1.1  jruoho         /* Make sure the handler is not already installed */
    387  1.1  jruoho 
    388  1.1  jruoho         if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
    389  1.1  jruoho                 AcpiGbl_SystemNotify.Handler)       ||
    390  1.1  jruoho             ((HandlerType & ACPI_DEVICE_NOTIFY) &&
    391  1.1  jruoho                 AcpiGbl_DeviceNotify.Handler))
    392  1.1  jruoho         {
    393  1.1  jruoho             Status = AE_ALREADY_EXISTS;
    394  1.1  jruoho             goto UnlockAndExit;
    395  1.1  jruoho         }
    396  1.1  jruoho 
    397  1.1  jruoho         if (HandlerType & ACPI_SYSTEM_NOTIFY)
    398  1.1  jruoho         {
    399  1.1  jruoho             AcpiGbl_SystemNotify.Node    = Node;
    400  1.1  jruoho             AcpiGbl_SystemNotify.Handler = Handler;
    401  1.1  jruoho             AcpiGbl_SystemNotify.Context = Context;
    402  1.1  jruoho         }
    403  1.1  jruoho 
    404  1.1  jruoho         if (HandlerType & ACPI_DEVICE_NOTIFY)
    405  1.1  jruoho         {
    406  1.1  jruoho             AcpiGbl_DeviceNotify.Node    = Node;
    407  1.1  jruoho             AcpiGbl_DeviceNotify.Handler = Handler;
    408  1.1  jruoho             AcpiGbl_DeviceNotify.Context = Context;
    409  1.1  jruoho         }
    410  1.1  jruoho 
    411  1.1  jruoho         /* Global notify handler installed */
    412  1.1  jruoho     }
    413  1.1  jruoho 
    414  1.1  jruoho     /*
    415  1.1  jruoho      * All Other Objects:
    416  1.1  jruoho      * Caller will only receive notifications specific to the target object.
    417  1.1  jruoho      * Note that only certain object types can receive notifications.
    418  1.1  jruoho      */
    419  1.1  jruoho     else
    420  1.1  jruoho     {
    421  1.1  jruoho         /* Notifies allowed on this object? */
    422  1.1  jruoho 
    423  1.1  jruoho         if (!AcpiEvIsNotifyObject (Node))
    424  1.1  jruoho         {
    425  1.1  jruoho             Status = AE_TYPE;
    426  1.1  jruoho             goto UnlockAndExit;
    427  1.1  jruoho         }
    428  1.1  jruoho 
    429  1.1  jruoho         /* Check for an existing internal object */
    430  1.1  jruoho 
    431  1.1  jruoho         ObjDesc = AcpiNsGetAttachedObject (Node);
    432  1.1  jruoho         if (ObjDesc)
    433  1.1  jruoho         {
    434  1.1  jruoho             /* Object exists - make sure there's no handler */
    435  1.1  jruoho 
    436  1.1  jruoho             if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
    437  1.1  jruoho                     ObjDesc->CommonNotify.SystemNotify)   ||
    438  1.1  jruoho                 ((HandlerType & ACPI_DEVICE_NOTIFY) &&
    439  1.1  jruoho                     ObjDesc->CommonNotify.DeviceNotify))
    440  1.1  jruoho             {
    441  1.1  jruoho                 Status = AE_ALREADY_EXISTS;
    442  1.1  jruoho                 goto UnlockAndExit;
    443  1.1  jruoho             }
    444  1.1  jruoho         }
    445  1.1  jruoho         else
    446  1.1  jruoho         {
    447  1.1  jruoho             /* Create a new object */
    448  1.1  jruoho 
    449  1.1  jruoho             ObjDesc = AcpiUtCreateInternalObject (Node->Type);
    450  1.1  jruoho             if (!ObjDesc)
    451  1.1  jruoho             {
    452  1.1  jruoho                 Status = AE_NO_MEMORY;
    453  1.1  jruoho                 goto UnlockAndExit;
    454  1.1  jruoho             }
    455  1.1  jruoho 
    456  1.1  jruoho             /* Attach new object to the Node */
    457  1.1  jruoho 
    458  1.1  jruoho             Status = AcpiNsAttachObject (Device, ObjDesc, Node->Type);
    459  1.1  jruoho 
    460  1.1  jruoho             /* Remove local reference to the object */
    461  1.1  jruoho 
    462  1.1  jruoho             AcpiUtRemoveReference (ObjDesc);
    463  1.1  jruoho             if (ACPI_FAILURE (Status))
    464  1.1  jruoho             {
    465  1.1  jruoho                 goto UnlockAndExit;
    466  1.1  jruoho             }
    467  1.1  jruoho         }
    468  1.1  jruoho 
    469  1.1  jruoho         /* Install the handler */
    470  1.1  jruoho 
    471  1.1  jruoho         NotifyObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY);
    472  1.1  jruoho         if (!NotifyObj)
    473  1.1  jruoho         {
    474  1.1  jruoho             Status = AE_NO_MEMORY;
    475  1.1  jruoho             goto UnlockAndExit;
    476  1.1  jruoho         }
    477  1.1  jruoho 
    478  1.1  jruoho         NotifyObj->Notify.Node    = Node;
    479  1.1  jruoho         NotifyObj->Notify.Handler = Handler;
    480  1.1  jruoho         NotifyObj->Notify.Context = Context;
    481  1.1  jruoho 
    482  1.1  jruoho         if (HandlerType & ACPI_SYSTEM_NOTIFY)
    483  1.1  jruoho         {
    484  1.1  jruoho             ObjDesc->CommonNotify.SystemNotify = NotifyObj;
    485  1.1  jruoho         }
    486  1.1  jruoho 
    487  1.1  jruoho         if (HandlerType & ACPI_DEVICE_NOTIFY)
    488  1.1  jruoho         {
    489  1.1  jruoho             ObjDesc->CommonNotify.DeviceNotify = NotifyObj;
    490  1.1  jruoho         }
    491  1.1  jruoho 
    492  1.1  jruoho         if (HandlerType == ACPI_ALL_NOTIFY)
    493  1.1  jruoho         {
    494  1.1  jruoho             /* Extra ref if installed in both */
    495  1.1  jruoho 
    496  1.1  jruoho             AcpiUtAddReference (NotifyObj);
    497  1.1  jruoho         }
    498  1.1  jruoho     }
    499  1.1  jruoho 
    500  1.1  jruoho 
    501  1.1  jruoho UnlockAndExit:
    502  1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    503  1.1  jruoho     return_ACPI_STATUS (Status);
    504  1.1  jruoho }
    505  1.1  jruoho 
    506  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler)
    507  1.1  jruoho 
    508  1.1  jruoho 
    509  1.1  jruoho /*******************************************************************************
    510  1.1  jruoho  *
    511  1.1  jruoho  * FUNCTION:    AcpiRemoveNotifyHandler
    512  1.1  jruoho  *
    513  1.1  jruoho  * PARAMETERS:  Device          - The device for which notifies will be handled
    514  1.1  jruoho  *              HandlerType     - The type of handler:
    515  1.1  jruoho  *                                  ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
    516  1.1  jruoho  *                                  ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
    517  1.1  jruoho  *                                  ACPI_ALL_NOTIFY:  both system and device
    518  1.1  jruoho  *              Handler         - Address of the handler
    519  1.1  jruoho  *
    520  1.1  jruoho  * RETURN:      Status
    521  1.1  jruoho  *
    522  1.1  jruoho  * DESCRIPTION: Remove a handler for notifies on an ACPI device
    523  1.1  jruoho  *
    524  1.1  jruoho  ******************************************************************************/
    525  1.1  jruoho 
    526  1.1  jruoho ACPI_STATUS
    527  1.1  jruoho AcpiRemoveNotifyHandler (
    528  1.1  jruoho     ACPI_HANDLE             Device,
    529  1.1  jruoho     UINT32                  HandlerType,
    530  1.1  jruoho     ACPI_NOTIFY_HANDLER     Handler)
    531  1.1  jruoho {
    532  1.1  jruoho     ACPI_OPERAND_OBJECT     *NotifyObj;
    533  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    534  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node;
    535  1.1  jruoho     ACPI_STATUS             Status;
    536  1.1  jruoho 
    537  1.1  jruoho 
    538  1.1  jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler);
    539  1.1  jruoho 
    540  1.1  jruoho 
    541  1.1  jruoho     /* Parameter validation */
    542  1.1  jruoho 
    543  1.1  jruoho     if ((!Device)  ||
    544  1.1  jruoho         (!Handler) ||
    545  1.1  jruoho         (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
    546  1.1  jruoho     {
    547  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    548  1.1  jruoho     }
    549  1.1  jruoho 
    550  1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    551  1.1  jruoho     if (ACPI_FAILURE (Status))
    552  1.1  jruoho     {
    553  1.1  jruoho         return_ACPI_STATUS (Status);
    554  1.1  jruoho     }
    555  1.1  jruoho 
    556  1.1  jruoho     /* Convert and validate the device handle */
    557  1.1  jruoho 
    558  1.1  jruoho     Node = AcpiNsValidateHandle (Device);
    559  1.1  jruoho     if (!Node)
    560  1.1  jruoho     {
    561  1.1  jruoho         Status = AE_BAD_PARAMETER;
    562  1.1  jruoho         goto UnlockAndExit;
    563  1.1  jruoho     }
    564  1.1  jruoho 
    565  1.1  jruoho     /* Root Object */
    566  1.1  jruoho 
    567  1.1  jruoho     if (Device == ACPI_ROOT_OBJECT)
    568  1.1  jruoho     {
    569  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    570  1.1  jruoho             "Removing notify handler for namespace root object\n"));
    571  1.1  jruoho 
    572  1.1  jruoho         if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
    573  1.1  jruoho               !AcpiGbl_SystemNotify.Handler)        ||
    574  1.1  jruoho             ((HandlerType & ACPI_DEVICE_NOTIFY) &&
    575  1.1  jruoho               !AcpiGbl_DeviceNotify.Handler))
    576  1.1  jruoho         {
    577  1.1  jruoho             Status = AE_NOT_EXIST;
    578  1.1  jruoho             goto UnlockAndExit;
    579  1.1  jruoho         }
    580  1.1  jruoho 
    581  1.1  jruoho         if (HandlerType & ACPI_SYSTEM_NOTIFY)
    582  1.1  jruoho         {
    583  1.1  jruoho             AcpiGbl_SystemNotify.Node    = NULL;
    584  1.1  jruoho             AcpiGbl_SystemNotify.Handler = NULL;
    585  1.1  jruoho             AcpiGbl_SystemNotify.Context = NULL;
    586  1.1  jruoho         }
    587  1.1  jruoho 
    588  1.1  jruoho         if (HandlerType & ACPI_DEVICE_NOTIFY)
    589  1.1  jruoho         {
    590  1.1  jruoho             AcpiGbl_DeviceNotify.Node    = NULL;
    591  1.1  jruoho             AcpiGbl_DeviceNotify.Handler = NULL;
    592  1.1  jruoho             AcpiGbl_DeviceNotify.Context = NULL;
    593  1.1  jruoho         }
    594  1.1  jruoho     }
    595  1.1  jruoho 
    596  1.1  jruoho     /* All Other Objects */
    597  1.1  jruoho 
    598  1.1  jruoho     else
    599  1.1  jruoho     {
    600  1.1  jruoho         /* Notifies allowed on this object? */
    601  1.1  jruoho 
    602  1.1  jruoho         if (!AcpiEvIsNotifyObject (Node))
    603  1.1  jruoho         {
    604  1.1  jruoho             Status = AE_TYPE;
    605  1.1  jruoho             goto UnlockAndExit;
    606  1.1  jruoho         }
    607  1.1  jruoho 
    608  1.1  jruoho         /* Check for an existing internal object */
    609  1.1  jruoho 
    610  1.1  jruoho         ObjDesc = AcpiNsGetAttachedObject (Node);
    611  1.1  jruoho         if (!ObjDesc)
    612  1.1  jruoho         {
    613  1.1  jruoho             Status = AE_NOT_EXIST;
    614  1.1  jruoho             goto UnlockAndExit;
    615  1.1  jruoho         }
    616  1.1  jruoho 
    617  1.1  jruoho         /* Object exists - make sure there's an existing handler */
    618  1.1  jruoho 
    619  1.1  jruoho         if (HandlerType & ACPI_SYSTEM_NOTIFY)
    620  1.1  jruoho         {
    621  1.1  jruoho             NotifyObj = ObjDesc->CommonNotify.SystemNotify;
    622  1.1  jruoho             if (!NotifyObj)
    623  1.1  jruoho             {
    624  1.1  jruoho                 Status = AE_NOT_EXIST;
    625  1.1  jruoho                 goto UnlockAndExit;
    626  1.1  jruoho             }
    627  1.1  jruoho 
    628  1.1  jruoho             if (NotifyObj->Notify.Handler != Handler)
    629  1.1  jruoho             {
    630  1.1  jruoho                 Status = AE_BAD_PARAMETER;
    631  1.1  jruoho                 goto UnlockAndExit;
    632  1.1  jruoho             }
    633  1.1  jruoho 
    634  1.1  jruoho             /* Remove the handler */
    635  1.1  jruoho 
    636  1.1  jruoho             ObjDesc->CommonNotify.SystemNotify = NULL;
    637  1.1  jruoho             AcpiUtRemoveReference (NotifyObj);
    638  1.1  jruoho         }
    639  1.1  jruoho 
    640  1.1  jruoho         if (HandlerType & ACPI_DEVICE_NOTIFY)
    641  1.1  jruoho         {
    642  1.1  jruoho             NotifyObj = ObjDesc->CommonNotify.DeviceNotify;
    643  1.1  jruoho             if (!NotifyObj)
    644  1.1  jruoho             {
    645  1.1  jruoho                 Status = AE_NOT_EXIST;
    646  1.1  jruoho                 goto UnlockAndExit;
    647  1.1  jruoho             }
    648  1.1  jruoho 
    649  1.1  jruoho             if (NotifyObj->Notify.Handler != Handler)
    650  1.1  jruoho             {
    651  1.1  jruoho                 Status = AE_BAD_PARAMETER;
    652  1.1  jruoho                 goto UnlockAndExit;
    653  1.1  jruoho             }
    654  1.1  jruoho 
    655  1.1  jruoho             /* Remove the handler */
    656  1.1  jruoho 
    657  1.1  jruoho             ObjDesc->CommonNotify.DeviceNotify = NULL;
    658  1.1  jruoho             AcpiUtRemoveReference (NotifyObj);
    659  1.1  jruoho         }
    660  1.1  jruoho     }
    661  1.1  jruoho 
    662  1.1  jruoho 
    663  1.1  jruoho UnlockAndExit:
    664  1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    665  1.1  jruoho     return_ACPI_STATUS (Status);
    666  1.1  jruoho }
    667  1.1  jruoho 
    668  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler)
    669  1.1  jruoho 
    670  1.1  jruoho 
    671  1.1  jruoho /*******************************************************************************
    672  1.1  jruoho  *
    673  1.1  jruoho  * FUNCTION:    AcpiInstallGpeHandler
    674  1.1  jruoho  *
    675  1.1  jruoho  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
    676  1.1  jruoho  *                                defined GPEs)
    677  1.1  jruoho  *              GpeNumber       - The GPE number within the GPE block
    678  1.1  jruoho  *              Type            - Whether this GPE should be treated as an
    679  1.1  jruoho  *                                edge- or level-triggered interrupt.
    680  1.1  jruoho  *              Address         - Address of the handler
    681  1.1  jruoho  *              Context         - Value passed to the handler on each GPE
    682  1.1  jruoho  *
    683  1.1  jruoho  * RETURN:      Status
    684  1.1  jruoho  *
    685  1.1  jruoho  * DESCRIPTION: Install a handler for a General Purpose Event.
    686  1.1  jruoho  *
    687  1.1  jruoho  ******************************************************************************/
    688  1.1  jruoho 
    689  1.1  jruoho ACPI_STATUS
    690  1.1  jruoho AcpiInstallGpeHandler (
    691  1.1  jruoho     ACPI_HANDLE             GpeDevice,
    692  1.1  jruoho     UINT32                  GpeNumber,
    693  1.1  jruoho     UINT32                  Type,
    694  1.1  jruoho     ACPI_EVENT_HANDLER      Address,
    695  1.1  jruoho     void                    *Context)
    696  1.1  jruoho {
    697  1.1  jruoho     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
    698  1.1  jruoho     ACPI_HANDLER_INFO       *Handler;
    699  1.1  jruoho     ACPI_STATUS             Status;
    700  1.1  jruoho     ACPI_CPU_FLAGS          Flags;
    701  1.1  jruoho 
    702  1.1  jruoho 
    703  1.1  jruoho     ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);
    704  1.1  jruoho 
    705  1.1  jruoho 
    706  1.1  jruoho     /* Parameter validation */
    707  1.1  jruoho 
    708  1.1  jruoho     if ((!Address) || (Type & ~ACPI_GPE_XRUPT_TYPE_MASK))
    709  1.1  jruoho     {
    710  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    711  1.1  jruoho     }
    712  1.1  jruoho 
    713  1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    714  1.1  jruoho     if (ACPI_FAILURE (Status))
    715  1.1  jruoho     {
    716  1.1  jruoho         return_ACPI_STATUS (Status);
    717  1.1  jruoho     }
    718  1.1  jruoho 
    719  1.1  jruoho     /* Ensure that we have a valid GPE number */
    720  1.1  jruoho 
    721  1.1  jruoho     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
    722  1.1  jruoho     if (!GpeEventInfo)
    723  1.1  jruoho     {
    724  1.1  jruoho         Status = AE_BAD_PARAMETER;
    725  1.1  jruoho         goto UnlockAndExit;
    726  1.1  jruoho     }
    727  1.1  jruoho 
    728  1.1  jruoho     /* Make sure that there isn't a handler there already */
    729  1.1  jruoho 
    730  1.1  jruoho     if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
    731  1.1  jruoho             ACPI_GPE_DISPATCH_HANDLER)
    732  1.1  jruoho     {
    733  1.1  jruoho         Status = AE_ALREADY_EXISTS;
    734  1.1  jruoho         goto UnlockAndExit;
    735  1.1  jruoho     }
    736  1.1  jruoho 
    737  1.1  jruoho     /* Allocate and init handler object */
    738  1.1  jruoho 
    739  1.1  jruoho     Handler = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_HANDLER_INFO));
    740  1.1  jruoho     if (!Handler)
    741  1.1  jruoho     {
    742  1.1  jruoho         Status = AE_NO_MEMORY;
    743  1.1  jruoho         goto UnlockAndExit;
    744  1.1  jruoho     }
    745  1.1  jruoho 
    746  1.1  jruoho     Handler->Address    = Address;
    747  1.1  jruoho     Handler->Context    = Context;
    748  1.1  jruoho     Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;
    749  1.1  jruoho 
    750  1.1  jruoho     /* Disable the GPE before installing the handler */
    751  1.1  jruoho 
    752  1.1  jruoho     Status = AcpiEvDisableGpe (GpeEventInfo);
    753  1.1  jruoho     if (ACPI_FAILURE (Status))
    754  1.1  jruoho     {
    755  1.1  jruoho         goto UnlockAndExit;
    756  1.1  jruoho     }
    757  1.1  jruoho 
    758  1.1  jruoho     /* Install the handler */
    759  1.1  jruoho 
    760  1.1  jruoho     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
    761  1.1  jruoho     GpeEventInfo->Dispatch.Handler = Handler;
    762  1.1  jruoho 
    763  1.1  jruoho     /* Setup up dispatch flags to indicate handler (vs. method) */
    764  1.1  jruoho 
    765  1.1  jruoho     GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
    766  1.1  jruoho     GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_HANDLER);
    767  1.1  jruoho 
    768  1.1  jruoho     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    769  1.1  jruoho 
    770  1.1  jruoho 
    771  1.1  jruoho UnlockAndExit:
    772  1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    773  1.1  jruoho     return_ACPI_STATUS (Status);
    774  1.1  jruoho }
    775  1.1  jruoho 
    776  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)
    777  1.1  jruoho 
    778  1.1  jruoho 
    779  1.1  jruoho /*******************************************************************************
    780  1.1  jruoho  *
    781  1.1  jruoho  * FUNCTION:    AcpiRemoveGpeHandler
    782  1.1  jruoho  *
    783  1.1  jruoho  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
    784  1.1  jruoho  *                                defined GPEs)
    785  1.1  jruoho  *              GpeNumber       - The event to remove a handler
    786  1.1  jruoho  *              Address         - Address of the handler
    787  1.1  jruoho  *
    788  1.1  jruoho  * RETURN:      Status
    789  1.1  jruoho  *
    790  1.1  jruoho  * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
    791  1.1  jruoho  *
    792  1.1  jruoho  ******************************************************************************/
    793  1.1  jruoho 
    794  1.1  jruoho ACPI_STATUS
    795  1.1  jruoho AcpiRemoveGpeHandler (
    796  1.1  jruoho     ACPI_HANDLE             GpeDevice,
    797  1.1  jruoho     UINT32                  GpeNumber,
    798  1.1  jruoho     ACPI_EVENT_HANDLER      Address)
    799  1.1  jruoho {
    800  1.1  jruoho     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
    801  1.1  jruoho     ACPI_HANDLER_INFO       *Handler;
    802  1.1  jruoho     ACPI_STATUS             Status;
    803  1.1  jruoho     ACPI_CPU_FLAGS          Flags;
    804  1.1  jruoho 
    805  1.1  jruoho 
    806  1.1  jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler);
    807  1.1  jruoho 
    808  1.1  jruoho 
    809  1.1  jruoho     /* Parameter validation */
    810  1.1  jruoho 
    811  1.1  jruoho     if (!Address)
    812  1.1  jruoho     {
    813  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    814  1.1  jruoho     }
    815  1.1  jruoho 
    816  1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    817  1.1  jruoho     if (ACPI_FAILURE (Status))
    818  1.1  jruoho     {
    819  1.1  jruoho         return_ACPI_STATUS (Status);
    820  1.1  jruoho     }
    821  1.1  jruoho 
    822  1.1  jruoho     /* Ensure that we have a valid GPE number */
    823  1.1  jruoho 
    824  1.1  jruoho     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
    825  1.1  jruoho     if (!GpeEventInfo)
    826  1.1  jruoho     {
    827  1.1  jruoho         Status = AE_BAD_PARAMETER;
    828  1.1  jruoho         goto UnlockAndExit;
    829  1.1  jruoho     }
    830  1.1  jruoho 
    831  1.1  jruoho     /* Make sure that a handler is indeed installed */
    832  1.1  jruoho 
    833  1.1  jruoho     if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) !=
    834  1.1  jruoho             ACPI_GPE_DISPATCH_HANDLER)
    835  1.1  jruoho     {
    836  1.1  jruoho         Status = AE_NOT_EXIST;
    837  1.1  jruoho         goto UnlockAndExit;
    838  1.1  jruoho     }
    839  1.1  jruoho 
    840  1.1  jruoho     /* Make sure that the installed handler is the same */
    841  1.1  jruoho 
    842  1.1  jruoho     if (GpeEventInfo->Dispatch.Handler->Address != Address)
    843  1.1  jruoho     {
    844  1.1  jruoho         Status = AE_BAD_PARAMETER;
    845  1.1  jruoho         goto UnlockAndExit;
    846  1.1  jruoho     }
    847  1.1  jruoho 
    848  1.1  jruoho     /* Disable the GPE before removing the handler */
    849  1.1  jruoho 
    850  1.1  jruoho     Status = AcpiEvDisableGpe (GpeEventInfo);
    851  1.1  jruoho     if (ACPI_FAILURE (Status))
    852  1.1  jruoho     {
    853  1.1  jruoho         goto UnlockAndExit;
    854  1.1  jruoho     }
    855  1.1  jruoho 
    856  1.1  jruoho     /* Remove the handler */
    857  1.1  jruoho 
    858  1.1  jruoho     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
    859  1.1  jruoho     Handler = GpeEventInfo->Dispatch.Handler;
    860  1.1  jruoho 
    861  1.1  jruoho     /* Restore Method node (if any), set dispatch flags */
    862  1.1  jruoho 
    863  1.1  jruoho     GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;
    864  1.1  jruoho     GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;  /* Clear bits */
    865  1.1  jruoho     if (Handler->MethodNode)
    866  1.1  jruoho     {
    867  1.1  jruoho         GpeEventInfo->Flags |= ACPI_GPE_DISPATCH_METHOD;
    868  1.1  jruoho     }
    869  1.1  jruoho     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    870  1.1  jruoho 
    871  1.1  jruoho     /* Now we can free the handler object */
    872  1.1  jruoho 
    873  1.1  jruoho     ACPI_FREE (Handler);
    874  1.1  jruoho 
    875  1.1  jruoho 
    876  1.1  jruoho UnlockAndExit:
    877  1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    878  1.1  jruoho     return_ACPI_STATUS (Status);
    879  1.1  jruoho }
    880  1.1  jruoho 
    881  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler)
    882  1.1  jruoho 
    883  1.1  jruoho 
    884  1.1  jruoho /*******************************************************************************
    885  1.1  jruoho  *
    886  1.1  jruoho  * FUNCTION:    AcpiAcquireGlobalLock
    887  1.1  jruoho  *
    888  1.1  jruoho  * PARAMETERS:  Timeout         - How long the caller is willing to wait
    889  1.1  jruoho  *              Handle          - Where the handle to the lock is returned
    890  1.1  jruoho  *                                (if acquired)
    891  1.1  jruoho  *
    892  1.1  jruoho  * RETURN:      Status
    893  1.1  jruoho  *
    894  1.1  jruoho  * DESCRIPTION: Acquire the ACPI Global Lock
    895  1.1  jruoho  *
    896  1.1  jruoho  * Note: Allows callers with the same thread ID to acquire the global lock
    897  1.1  jruoho  * multiple times. In other words, externally, the behavior of the global lock
    898  1.1  jruoho  * is identical to an AML mutex. On the first acquire, a new handle is
    899  1.1  jruoho  * returned. On any subsequent calls to acquire by the same thread, the same
    900  1.1  jruoho  * handle is returned.
    901  1.1  jruoho  *
    902  1.1  jruoho  ******************************************************************************/
    903  1.1  jruoho 
    904  1.1  jruoho ACPI_STATUS
    905  1.1  jruoho AcpiAcquireGlobalLock (
    906  1.1  jruoho     UINT16                  Timeout,
    907  1.1  jruoho     UINT32                  *Handle)
    908  1.1  jruoho {
    909  1.1  jruoho     ACPI_STATUS             Status;
    910  1.1  jruoho 
    911  1.1  jruoho 
    912  1.1  jruoho     if (!Handle)
    913  1.1  jruoho     {
    914  1.1  jruoho         return (AE_BAD_PARAMETER);
    915  1.1  jruoho     }
    916  1.1  jruoho 
    917  1.1  jruoho     /* Must lock interpreter to prevent race conditions */
    918  1.1  jruoho 
    919  1.1  jruoho     AcpiExEnterInterpreter ();
    920  1.1  jruoho 
    921  1.1  jruoho     Status = AcpiExAcquireMutexObject (Timeout,
    922  1.1  jruoho                 AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
    923  1.1  jruoho 
    924  1.1  jruoho     if (ACPI_SUCCESS (Status))
    925  1.1  jruoho     {
    926  1.1  jruoho         /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
    927  1.1  jruoho 
    928  1.1  jruoho         *Handle = AcpiGbl_GlobalLockHandle;
    929  1.1  jruoho     }
    930  1.1  jruoho 
    931  1.1  jruoho     AcpiExExitInterpreter ();
    932  1.1  jruoho     return (Status);
    933  1.1  jruoho }
    934  1.1  jruoho 
    935  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock)
    936  1.1  jruoho 
    937  1.1  jruoho 
    938  1.1  jruoho /*******************************************************************************
    939  1.1  jruoho  *
    940  1.1  jruoho  * FUNCTION:    AcpiReleaseGlobalLock
    941  1.1  jruoho  *
    942  1.1  jruoho  * PARAMETERS:  Handle      - Returned from AcpiAcquireGlobalLock
    943  1.1  jruoho  *
    944  1.1  jruoho  * RETURN:      Status
    945  1.1  jruoho  *
    946  1.1  jruoho  * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
    947  1.1  jruoho  *
    948  1.1  jruoho  ******************************************************************************/
    949  1.1  jruoho 
    950  1.1  jruoho ACPI_STATUS
    951  1.1  jruoho AcpiReleaseGlobalLock (
    952  1.1  jruoho     UINT32                  Handle)
    953  1.1  jruoho {
    954  1.1  jruoho     ACPI_STATUS             Status;
    955  1.1  jruoho 
    956  1.1  jruoho 
    957  1.1  jruoho     if (!Handle || (Handle != AcpiGbl_GlobalLockHandle))
    958  1.1  jruoho     {
    959  1.1  jruoho         return (AE_NOT_ACQUIRED);
    960  1.1  jruoho     }
    961  1.1  jruoho 
    962  1.1  jruoho     Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
    963  1.1  jruoho     return (Status);
    964  1.1  jruoho }
    965  1.1  jruoho 
    966  1.1  jruoho ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock)
    967  1.1  jruoho 
    968