Home | History | Annotate | Line # | Download | only in events
evxface.c revision 1.1.1.10
      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.1.2    jruoho /*
      8   1.1.1.9  christos  * Copyright (C) 2000 - 2019, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33   1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44   1.1.1.3  christos #define EXPORT_ACPI_INTERFACES
     45       1.1    jruoho 
     46       1.1    jruoho #include "acpi.h"
     47       1.1    jruoho #include "accommon.h"
     48       1.1    jruoho #include "acnamesp.h"
     49       1.1    jruoho #include "acevents.h"
     50       1.1    jruoho #include "acinterp.h"
     51       1.1    jruoho 
     52       1.1    jruoho #define _COMPONENT          ACPI_EVENTS
     53       1.1    jruoho         ACPI_MODULE_NAME    ("evxface")
     54       1.1    jruoho 
     55   1.1.1.5  christos #if (!ACPI_REDUCED_HARDWARE)
     56   1.1.1.5  christos 
     57   1.1.1.5  christos /* Local prototypes */
     58   1.1.1.5  christos 
     59   1.1.1.5  christos static ACPI_STATUS
     60   1.1.1.5  christos AcpiEvInstallGpeHandler (
     61   1.1.1.5  christos     ACPI_HANDLE             GpeDevice,
     62   1.1.1.5  christos     UINT32                  GpeNumber,
     63   1.1.1.5  christos     UINT32                  Type,
     64   1.1.1.5  christos     BOOLEAN                 IsRawHandler,
     65   1.1.1.5  christos     ACPI_GPE_HANDLER        Address,
     66   1.1.1.5  christos     void                    *Context);
     67   1.1.1.5  christos 
     68   1.1.1.5  christos #endif
     69   1.1.1.5  christos 
     70       1.1    jruoho 
     71       1.1    jruoho /*******************************************************************************
     72       1.1    jruoho  *
     73   1.1.1.3  christos  * FUNCTION:    AcpiInstallNotifyHandler
     74   1.1.1.3  christos  *
     75   1.1.1.3  christos  * PARAMETERS:  Device          - The device for which notifies will be handled
     76   1.1.1.3  christos  *              HandlerType     - The type of handler:
     77   1.1.1.3  christos  *                                  ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
     78   1.1.1.3  christos  *                                  ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
     79   1.1.1.3  christos  *                                  ACPI_ALL_NOTIFY:    Both System and Device
     80   1.1.1.3  christos  *              Handler         - Address of the handler
     81   1.1.1.3  christos  *              Context         - Value passed to the handler on each GPE
     82   1.1.1.3  christos  *
     83   1.1.1.3  christos  * RETURN:      Status
     84   1.1.1.3  christos  *
     85   1.1.1.3  christos  * DESCRIPTION: Install a handler for notifications on an ACPI Device,
     86   1.1.1.3  christos  *              ThermalZone, or Processor object.
     87   1.1.1.3  christos  *
     88   1.1.1.3  christos  * NOTES:       The Root namespace object may have only one handler for each
     89   1.1.1.3  christos  *              type of notify (System/Device). Device/Thermal/Processor objects
     90   1.1.1.3  christos  *              may have one device notify handler, and multiple system notify
     91   1.1.1.3  christos  *              handlers.
     92   1.1.1.3  christos  *
     93   1.1.1.3  christos  ******************************************************************************/
     94   1.1.1.3  christos 
     95   1.1.1.3  christos ACPI_STATUS
     96   1.1.1.3  christos AcpiInstallNotifyHandler (
     97   1.1.1.3  christos     ACPI_HANDLE             Device,
     98   1.1.1.3  christos     UINT32                  HandlerType,
     99   1.1.1.3  christos     ACPI_NOTIFY_HANDLER     Handler,
    100   1.1.1.3  christos     void                    *Context)
    101   1.1.1.3  christos {
    102   1.1.1.3  christos     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
    103   1.1.1.3  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    104   1.1.1.3  christos     ACPI_OPERAND_OBJECT     *HandlerObj;
    105   1.1.1.3  christos     ACPI_STATUS             Status;
    106   1.1.1.3  christos     UINT32                  i;
    107   1.1.1.3  christos 
    108   1.1.1.3  christos 
    109   1.1.1.3  christos     ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler);
    110   1.1.1.3  christos 
    111   1.1.1.3  christos 
    112   1.1.1.3  christos     /* Parameter validation */
    113   1.1.1.3  christos 
    114   1.1.1.3  christos     if ((!Device) || (!Handler) || (!HandlerType) ||
    115   1.1.1.3  christos         (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
    116   1.1.1.3  christos     {
    117   1.1.1.3  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    118   1.1.1.3  christos     }
    119   1.1.1.3  christos 
    120   1.1.1.3  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    121   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    122   1.1.1.3  christos     {
    123   1.1.1.3  christos         return_ACPI_STATUS (Status);
    124   1.1.1.3  christos     }
    125   1.1.1.3  christos 
    126   1.1.1.3  christos     /*
    127   1.1.1.3  christos      * Root Object:
    128   1.1.1.3  christos      * Registering a notify handler on the root object indicates that the
    129   1.1.1.3  christos      * caller wishes to receive notifications for all objects. Note that
    130   1.1.1.3  christos      * only one global handler can be registered per notify type.
    131   1.1.1.3  christos      * Ensure that a handler is not already installed.
    132   1.1.1.3  christos      */
    133   1.1.1.3  christos     if (Device == ACPI_ROOT_OBJECT)
    134   1.1.1.3  christos     {
    135   1.1.1.3  christos         for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
    136   1.1.1.3  christos         {
    137   1.1.1.3  christos             if (HandlerType & (i+1))
    138   1.1.1.3  christos             {
    139   1.1.1.3  christos                 if (AcpiGbl_GlobalNotify[i].Handler)
    140   1.1.1.3  christos                 {
    141   1.1.1.3  christos                     Status = AE_ALREADY_EXISTS;
    142   1.1.1.3  christos                     goto UnlockAndExit;
    143   1.1.1.3  christos                 }
    144   1.1.1.3  christos 
    145   1.1.1.3  christos                 AcpiGbl_GlobalNotify[i].Handler = Handler;
    146   1.1.1.3  christos                 AcpiGbl_GlobalNotify[i].Context = Context;
    147   1.1.1.3  christos             }
    148   1.1.1.3  christos         }
    149   1.1.1.3  christos 
    150   1.1.1.3  christos         goto UnlockAndExit; /* Global notify handler installed, all done */
    151   1.1.1.3  christos     }
    152   1.1.1.3  christos 
    153   1.1.1.3  christos     /*
    154   1.1.1.3  christos      * All Other Objects:
    155   1.1.1.3  christos      * Caller will only receive notifications specific to the target
    156   1.1.1.3  christos      * object. Note that only certain object types are allowed to
    157   1.1.1.3  christos      * receive notifications.
    158   1.1.1.3  christos      */
    159   1.1.1.3  christos 
    160   1.1.1.3  christos     /* Are Notifies allowed on this object? */
    161   1.1.1.3  christos 
    162   1.1.1.3  christos     if (!AcpiEvIsNotifyObject (Node))
    163   1.1.1.3  christos     {
    164   1.1.1.3  christos         Status = AE_TYPE;
    165   1.1.1.3  christos         goto UnlockAndExit;
    166   1.1.1.3  christos     }
    167   1.1.1.3  christos 
    168   1.1.1.3  christos     /* Check for an existing internal object, might not exist */
    169   1.1.1.3  christos 
    170   1.1.1.3  christos     ObjDesc = AcpiNsGetAttachedObject (Node);
    171   1.1.1.3  christos     if (!ObjDesc)
    172   1.1.1.3  christos     {
    173   1.1.1.3  christos         /* Create a new object */
    174   1.1.1.3  christos 
    175   1.1.1.3  christos         ObjDesc = AcpiUtCreateInternalObject (Node->Type);
    176   1.1.1.3  christos         if (!ObjDesc)
    177   1.1.1.3  christos         {
    178   1.1.1.3  christos             Status = AE_NO_MEMORY;
    179   1.1.1.3  christos             goto UnlockAndExit;
    180   1.1.1.3  christos         }
    181   1.1.1.3  christos 
    182   1.1.1.3  christos         /* Attach new object to the Node, remove local reference */
    183   1.1.1.3  christos 
    184   1.1.1.3  christos         Status = AcpiNsAttachObject (Device, ObjDesc, Node->Type);
    185   1.1.1.3  christos         AcpiUtRemoveReference (ObjDesc);
    186   1.1.1.3  christos         if (ACPI_FAILURE (Status))
    187   1.1.1.3  christos         {
    188   1.1.1.3  christos             goto UnlockAndExit;
    189   1.1.1.3  christos         }
    190   1.1.1.3  christos     }
    191   1.1.1.3  christos 
    192   1.1.1.3  christos     /* Ensure that the handler is not already installed in the lists */
    193   1.1.1.3  christos 
    194   1.1.1.3  christos     for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
    195   1.1.1.3  christos     {
    196   1.1.1.3  christos         if (HandlerType & (i+1))
    197   1.1.1.3  christos         {
    198   1.1.1.3  christos             HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
    199   1.1.1.3  christos             while (HandlerObj)
    200   1.1.1.3  christos             {
    201   1.1.1.3  christos                 if (HandlerObj->Notify.Handler == Handler)
    202   1.1.1.3  christos                 {
    203   1.1.1.3  christos                     Status = AE_ALREADY_EXISTS;
    204   1.1.1.3  christos                     goto UnlockAndExit;
    205   1.1.1.3  christos                 }
    206   1.1.1.3  christos 
    207   1.1.1.3  christos                 HandlerObj = HandlerObj->Notify.Next[i];
    208   1.1.1.3  christos             }
    209   1.1.1.3  christos         }
    210   1.1.1.3  christos     }
    211   1.1.1.3  christos 
    212   1.1.1.3  christos     /* Create and populate a new notify handler object */
    213   1.1.1.3  christos 
    214   1.1.1.3  christos     HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY);
    215   1.1.1.3  christos     if (!HandlerObj)
    216   1.1.1.3  christos     {
    217   1.1.1.3  christos         Status = AE_NO_MEMORY;
    218   1.1.1.3  christos         goto UnlockAndExit;
    219   1.1.1.3  christos     }
    220   1.1.1.3  christos 
    221   1.1.1.3  christos     HandlerObj->Notify.Node = Node;
    222   1.1.1.3  christos     HandlerObj->Notify.HandlerType = HandlerType;
    223   1.1.1.3  christos     HandlerObj->Notify.Handler = Handler;
    224   1.1.1.3  christos     HandlerObj->Notify.Context = Context;
    225   1.1.1.3  christos 
    226   1.1.1.3  christos     /* Install the handler at the list head(s) */
    227   1.1.1.3  christos 
    228   1.1.1.3  christos     for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
    229   1.1.1.3  christos     {
    230   1.1.1.3  christos         if (HandlerType & (i+1))
    231   1.1.1.3  christos         {
    232   1.1.1.3  christos             HandlerObj->Notify.Next[i] =
    233   1.1.1.3  christos                 ObjDesc->CommonNotify.NotifyList[i];
    234   1.1.1.3  christos 
    235   1.1.1.3  christos             ObjDesc->CommonNotify.NotifyList[i] = HandlerObj;
    236   1.1.1.3  christos         }
    237   1.1.1.3  christos     }
    238   1.1.1.3  christos 
    239   1.1.1.3  christos     /* Add an extra reference if handler was installed in both lists */
    240   1.1.1.3  christos 
    241   1.1.1.3  christos     if (HandlerType == ACPI_ALL_NOTIFY)
    242   1.1.1.3  christos     {
    243   1.1.1.3  christos         AcpiUtAddReference (HandlerObj);
    244   1.1.1.3  christos     }
    245   1.1.1.3  christos 
    246   1.1.1.3  christos 
    247   1.1.1.3  christos UnlockAndExit:
    248   1.1.1.3  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    249   1.1.1.3  christos     return_ACPI_STATUS (Status);
    250   1.1.1.3  christos }
    251   1.1.1.3  christos 
    252   1.1.1.3  christos ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler)
    253   1.1.1.3  christos 
    254   1.1.1.3  christos 
    255   1.1.1.3  christos /*******************************************************************************
    256   1.1.1.3  christos  *
    257   1.1.1.3  christos  * FUNCTION:    AcpiRemoveNotifyHandler
    258   1.1.1.3  christos  *
    259   1.1.1.3  christos  * PARAMETERS:  Device          - The device for which the handler is installed
    260   1.1.1.3  christos  *              HandlerType     - The type of handler:
    261   1.1.1.3  christos  *                                  ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
    262   1.1.1.3  christos  *                                  ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
    263   1.1.1.3  christos  *                                  ACPI_ALL_NOTIFY:    Both System and Device
    264   1.1.1.3  christos  *              Handler         - Address of the handler
    265   1.1.1.3  christos  *
    266   1.1.1.3  christos  * RETURN:      Status
    267   1.1.1.3  christos  *
    268   1.1.1.3  christos  * DESCRIPTION: Remove a handler for notifies on an ACPI device
    269   1.1.1.3  christos  *
    270   1.1.1.3  christos  ******************************************************************************/
    271   1.1.1.3  christos 
    272   1.1.1.3  christos ACPI_STATUS
    273   1.1.1.3  christos AcpiRemoveNotifyHandler (
    274   1.1.1.3  christos     ACPI_HANDLE             Device,
    275   1.1.1.3  christos     UINT32                  HandlerType,
    276   1.1.1.3  christos     ACPI_NOTIFY_HANDLER     Handler)
    277   1.1.1.3  christos {
    278   1.1.1.3  christos     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
    279   1.1.1.3  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    280   1.1.1.3  christos     ACPI_OPERAND_OBJECT     *HandlerObj;
    281   1.1.1.3  christos     ACPI_OPERAND_OBJECT     *PreviousHandlerObj;
    282   1.1.1.4  christos     ACPI_STATUS             Status = AE_OK;
    283   1.1.1.3  christos     UINT32                  i;
    284   1.1.1.3  christos 
    285   1.1.1.3  christos 
    286   1.1.1.3  christos     ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler);
    287   1.1.1.3  christos 
    288   1.1.1.3  christos 
    289   1.1.1.3  christos     /* Parameter validation */
    290   1.1.1.3  christos 
    291   1.1.1.3  christos     if ((!Device) || (!Handler) || (!HandlerType) ||
    292   1.1.1.3  christos         (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
    293   1.1.1.3  christos     {
    294   1.1.1.3  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    295   1.1.1.3  christos     }
    296   1.1.1.3  christos 
    297   1.1.1.3  christos     /* Root Object. Global handlers are removed here */
    298   1.1.1.3  christos 
    299   1.1.1.3  christos     if (Device == ACPI_ROOT_OBJECT)
    300   1.1.1.3  christos     {
    301   1.1.1.3  christos         for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
    302   1.1.1.3  christos         {
    303   1.1.1.3  christos             if (HandlerType & (i+1))
    304   1.1.1.3  christos             {
    305   1.1.1.4  christos                 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    306   1.1.1.4  christos                 if (ACPI_FAILURE (Status))
    307   1.1.1.4  christos                 {
    308   1.1.1.4  christos                     return_ACPI_STATUS (Status);
    309   1.1.1.4  christos                 }
    310   1.1.1.4  christos 
    311   1.1.1.3  christos                 if (!AcpiGbl_GlobalNotify[i].Handler ||
    312   1.1.1.3  christos                     (AcpiGbl_GlobalNotify[i].Handler != Handler))
    313   1.1.1.3  christos                 {
    314   1.1.1.3  christos                     Status = AE_NOT_EXIST;
    315   1.1.1.3  christos                     goto UnlockAndExit;
    316   1.1.1.3  christos                 }
    317   1.1.1.3  christos 
    318   1.1.1.3  christos                 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    319   1.1.1.3  christos                     "Removing global notify handler\n"));
    320   1.1.1.3  christos 
    321   1.1.1.3  christos                 AcpiGbl_GlobalNotify[i].Handler = NULL;
    322   1.1.1.3  christos                 AcpiGbl_GlobalNotify[i].Context = NULL;
    323   1.1.1.4  christos 
    324   1.1.1.4  christos                 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    325   1.1.1.4  christos 
    326   1.1.1.4  christos                 /* Make sure all deferred notify tasks are completed */
    327   1.1.1.4  christos 
    328   1.1.1.4  christos                 AcpiOsWaitEventsComplete ();
    329   1.1.1.3  christos             }
    330   1.1.1.3  christos         }
    331   1.1.1.3  christos 
    332   1.1.1.4  christos         return_ACPI_STATUS (AE_OK);
    333   1.1.1.3  christos     }
    334   1.1.1.3  christos 
    335   1.1.1.3  christos     /* All other objects: Are Notifies allowed on this object? */
    336   1.1.1.3  christos 
    337   1.1.1.3  christos     if (!AcpiEvIsNotifyObject (Node))
    338   1.1.1.3  christos     {
    339   1.1.1.4  christos         return_ACPI_STATUS (AE_TYPE);
    340   1.1.1.3  christos     }
    341   1.1.1.3  christos 
    342   1.1.1.3  christos     /* Must have an existing internal object */
    343   1.1.1.3  christos 
    344   1.1.1.3  christos     ObjDesc = AcpiNsGetAttachedObject (Node);
    345   1.1.1.3  christos     if (!ObjDesc)
    346   1.1.1.3  christos     {
    347   1.1.1.4  christos         return_ACPI_STATUS (AE_NOT_EXIST);
    348   1.1.1.3  christos     }
    349   1.1.1.3  christos 
    350   1.1.1.3  christos     /* Internal object exists. Find the handler and remove it */
    351   1.1.1.3  christos 
    352   1.1.1.3  christos     for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
    353   1.1.1.3  christos     {
    354   1.1.1.3  christos         if (HandlerType & (i+1))
    355   1.1.1.3  christos         {
    356   1.1.1.4  christos             Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    357   1.1.1.4  christos             if (ACPI_FAILURE (Status))
    358   1.1.1.4  christos             {
    359   1.1.1.4  christos                 return_ACPI_STATUS (Status);
    360   1.1.1.4  christos             }
    361   1.1.1.4  christos 
    362   1.1.1.3  christos             HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
    363   1.1.1.3  christos             PreviousHandlerObj = NULL;
    364   1.1.1.3  christos 
    365   1.1.1.3  christos             /* Attempt to find the handler in the handler list */
    366   1.1.1.3  christos 
    367   1.1.1.3  christos             while (HandlerObj &&
    368   1.1.1.3  christos                   (HandlerObj->Notify.Handler != Handler))
    369   1.1.1.3  christos             {
    370   1.1.1.3  christos                 PreviousHandlerObj = HandlerObj;
    371   1.1.1.3  christos                 HandlerObj = HandlerObj->Notify.Next[i];
    372   1.1.1.3  christos             }
    373   1.1.1.3  christos 
    374   1.1.1.3  christos             if (!HandlerObj)
    375   1.1.1.3  christos             {
    376   1.1.1.3  christos                 Status = AE_NOT_EXIST;
    377   1.1.1.3  christos                 goto UnlockAndExit;
    378   1.1.1.3  christos             }
    379   1.1.1.3  christos 
    380   1.1.1.3  christos             /* Remove the handler object from the list */
    381   1.1.1.3  christos 
    382   1.1.1.3  christos             if (PreviousHandlerObj) /* Handler is not at the list head */
    383   1.1.1.3  christos             {
    384   1.1.1.3  christos                 PreviousHandlerObj->Notify.Next[i] =
    385   1.1.1.3  christos                     HandlerObj->Notify.Next[i];
    386   1.1.1.3  christos             }
    387   1.1.1.3  christos             else /* Handler is at the list head */
    388   1.1.1.3  christos             {
    389   1.1.1.3  christos                 ObjDesc->CommonNotify.NotifyList[i] =
    390   1.1.1.3  christos                     HandlerObj->Notify.Next[i];
    391   1.1.1.3  christos             }
    392   1.1.1.3  christos 
    393   1.1.1.4  christos             (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    394   1.1.1.4  christos 
    395   1.1.1.4  christos             /* Make sure all deferred notify tasks are completed */
    396   1.1.1.4  christos 
    397   1.1.1.4  christos             AcpiOsWaitEventsComplete ();
    398   1.1.1.3  christos             AcpiUtRemoveReference (HandlerObj);
    399   1.1.1.3  christos         }
    400   1.1.1.3  christos     }
    401   1.1.1.3  christos 
    402   1.1.1.4  christos     return_ACPI_STATUS (Status);
    403   1.1.1.4  christos 
    404   1.1.1.3  christos 
    405   1.1.1.3  christos UnlockAndExit:
    406   1.1.1.3  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    407   1.1.1.3  christos     return_ACPI_STATUS (Status);
    408   1.1.1.3  christos }
    409   1.1.1.3  christos 
    410   1.1.1.3  christos ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler)
    411   1.1.1.3  christos 
    412   1.1.1.3  christos 
    413   1.1.1.3  christos /*******************************************************************************
    414   1.1.1.3  christos  *
    415       1.1    jruoho  * FUNCTION:    AcpiInstallExceptionHandler
    416       1.1    jruoho  *
    417       1.1    jruoho  * PARAMETERS:  Handler         - Pointer to the handler function for the
    418       1.1    jruoho  *                                event
    419       1.1    jruoho  *
    420       1.1    jruoho  * RETURN:      Status
    421       1.1    jruoho  *
    422       1.1    jruoho  * DESCRIPTION: Saves the pointer to the handler function
    423       1.1    jruoho  *
    424       1.1    jruoho  ******************************************************************************/
    425       1.1    jruoho 
    426       1.1    jruoho ACPI_STATUS
    427       1.1    jruoho AcpiInstallExceptionHandler (
    428       1.1    jruoho     ACPI_EXCEPTION_HANDLER  Handler)
    429       1.1    jruoho {
    430       1.1    jruoho     ACPI_STATUS             Status;
    431       1.1    jruoho 
    432       1.1    jruoho 
    433       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler);
    434       1.1    jruoho 
    435       1.1    jruoho 
    436       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    437       1.1    jruoho     if (ACPI_FAILURE (Status))
    438       1.1    jruoho     {
    439       1.1    jruoho         return_ACPI_STATUS (Status);
    440       1.1    jruoho     }
    441       1.1    jruoho 
    442       1.1    jruoho     /* Don't allow two handlers. */
    443       1.1    jruoho 
    444   1.1.1.3  christos     if (AcpiGbl_ExceptionHandler)
    445   1.1.1.3  christos     {
    446   1.1.1.3  christos         Status = AE_ALREADY_EXISTS;
    447   1.1.1.3  christos         goto Cleanup;
    448   1.1.1.3  christos     }
    449   1.1.1.3  christos 
    450   1.1.1.3  christos     /* Install the handler */
    451   1.1.1.3  christos 
    452   1.1.1.3  christos     AcpiGbl_ExceptionHandler = Handler;
    453   1.1.1.3  christos 
    454   1.1.1.3  christos Cleanup:
    455   1.1.1.3  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    456   1.1.1.3  christos     return_ACPI_STATUS (Status);
    457   1.1.1.3  christos }
    458   1.1.1.3  christos 
    459   1.1.1.3  christos ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler)
    460   1.1.1.3  christos 
    461   1.1.1.3  christos 
    462   1.1.1.3  christos #if (!ACPI_REDUCED_HARDWARE)
    463   1.1.1.3  christos /*******************************************************************************
    464   1.1.1.3  christos  *
    465   1.1.1.3  christos  * FUNCTION:    AcpiInstallSciHandler
    466   1.1.1.3  christos  *
    467   1.1.1.3  christos  * PARAMETERS:  Address             - Address of the handler
    468   1.1.1.3  christos  *              Context             - Value passed to the handler on each SCI
    469   1.1.1.3  christos  *
    470   1.1.1.3  christos  * RETURN:      Status
    471   1.1.1.3  christos  *
    472   1.1.1.3  christos  * DESCRIPTION: Install a handler for a System Control Interrupt.
    473   1.1.1.3  christos  *
    474   1.1.1.3  christos  ******************************************************************************/
    475   1.1.1.3  christos 
    476   1.1.1.3  christos ACPI_STATUS
    477   1.1.1.3  christos AcpiInstallSciHandler (
    478   1.1.1.3  christos     ACPI_SCI_HANDLER        Address,
    479   1.1.1.3  christos     void                    *Context)
    480   1.1.1.3  christos {
    481   1.1.1.3  christos     ACPI_SCI_HANDLER_INFO   *NewSciHandler;
    482   1.1.1.3  christos     ACPI_SCI_HANDLER_INFO   *SciHandler;
    483   1.1.1.3  christos     ACPI_CPU_FLAGS          Flags;
    484   1.1.1.3  christos     ACPI_STATUS             Status;
    485   1.1.1.3  christos 
    486   1.1.1.3  christos 
    487   1.1.1.3  christos     ACPI_FUNCTION_TRACE (AcpiInstallSciHandler);
    488   1.1.1.3  christos 
    489   1.1.1.3  christos 
    490   1.1.1.3  christos     if (!Address)
    491   1.1.1.3  christos     {
    492   1.1.1.3  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    493   1.1.1.3  christos     }
    494   1.1.1.3  christos 
    495   1.1.1.3  christos     /* Allocate and init a handler object */
    496   1.1.1.3  christos 
    497   1.1.1.3  christos     NewSciHandler = ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO));
    498   1.1.1.3  christos     if (!NewSciHandler)
    499   1.1.1.3  christos     {
    500   1.1.1.3  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    501   1.1.1.3  christos     }
    502   1.1.1.3  christos 
    503   1.1.1.3  christos     NewSciHandler->Address = Address;
    504   1.1.1.3  christos     NewSciHandler->Context = Context;
    505   1.1.1.3  christos 
    506   1.1.1.3  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    507   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    508   1.1.1.3  christos     {
    509   1.1.1.3  christos         goto Exit;
    510   1.1.1.3  christos     }
    511   1.1.1.3  christos 
    512   1.1.1.3  christos     /* Lock list during installation */
    513   1.1.1.3  christos 
    514   1.1.1.3  christos     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
    515   1.1.1.3  christos     SciHandler = AcpiGbl_SciHandlerList;
    516   1.1.1.3  christos 
    517   1.1.1.3  christos     /* Ensure handler does not already exist */
    518   1.1.1.3  christos 
    519   1.1.1.3  christos     while (SciHandler)
    520   1.1.1.3  christos     {
    521   1.1.1.3  christos         if (Address == SciHandler->Address)
    522   1.1.1.3  christos         {
    523   1.1.1.3  christos             Status = AE_ALREADY_EXISTS;
    524   1.1.1.3  christos             goto UnlockAndExit;
    525   1.1.1.3  christos         }
    526   1.1.1.3  christos 
    527   1.1.1.3  christos         SciHandler = SciHandler->Next;
    528   1.1.1.3  christos     }
    529   1.1.1.3  christos 
    530   1.1.1.3  christos     /* Install the new handler into the global list (at head) */
    531   1.1.1.3  christos 
    532   1.1.1.3  christos     NewSciHandler->Next = AcpiGbl_SciHandlerList;
    533   1.1.1.3  christos     AcpiGbl_SciHandlerList = NewSciHandler;
    534   1.1.1.3  christos 
    535   1.1.1.3  christos 
    536   1.1.1.3  christos UnlockAndExit:
    537   1.1.1.3  christos 
    538   1.1.1.3  christos     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    539   1.1.1.3  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    540   1.1.1.3  christos 
    541   1.1.1.3  christos Exit:
    542   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    543   1.1.1.3  christos     {
    544   1.1.1.3  christos         ACPI_FREE (NewSciHandler);
    545   1.1.1.3  christos     }
    546   1.1.1.3  christos     return_ACPI_STATUS (Status);
    547   1.1.1.3  christos }
    548   1.1.1.3  christos 
    549   1.1.1.4  christos ACPI_EXPORT_SYMBOL (AcpiInstallSciHandler)
    550   1.1.1.4  christos 
    551   1.1.1.3  christos 
    552   1.1.1.3  christos /*******************************************************************************
    553   1.1.1.3  christos  *
    554   1.1.1.3  christos  * FUNCTION:    AcpiRemoveSciHandler
    555   1.1.1.3  christos  *
    556   1.1.1.3  christos  * PARAMETERS:  Address             - Address of the handler
    557   1.1.1.3  christos  *
    558   1.1.1.3  christos  * RETURN:      Status
    559   1.1.1.3  christos  *
    560   1.1.1.3  christos  * DESCRIPTION: Remove a handler for a System Control Interrupt.
    561   1.1.1.3  christos  *
    562   1.1.1.3  christos  ******************************************************************************/
    563   1.1.1.3  christos 
    564   1.1.1.3  christos ACPI_STATUS
    565   1.1.1.3  christos AcpiRemoveSciHandler (
    566   1.1.1.3  christos     ACPI_SCI_HANDLER        Address)
    567   1.1.1.3  christos {
    568   1.1.1.3  christos     ACPI_SCI_HANDLER_INFO   *PrevSciHandler;
    569   1.1.1.3  christos     ACPI_SCI_HANDLER_INFO   *NextSciHandler;
    570   1.1.1.3  christos     ACPI_CPU_FLAGS          Flags;
    571   1.1.1.3  christos     ACPI_STATUS             Status;
    572   1.1.1.3  christos 
    573   1.1.1.3  christos 
    574   1.1.1.3  christos     ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler);
    575   1.1.1.3  christos 
    576   1.1.1.3  christos 
    577   1.1.1.3  christos     if (!Address)
    578   1.1.1.3  christos     {
    579   1.1.1.3  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    580   1.1.1.3  christos     }
    581   1.1.1.3  christos 
    582   1.1.1.3  christos     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    583   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    584   1.1.1.3  christos     {
    585   1.1.1.3  christos         return_ACPI_STATUS (Status);
    586   1.1.1.3  christos     }
    587   1.1.1.3  christos 
    588   1.1.1.3  christos     /* Remove the SCI handler with lock */
    589   1.1.1.3  christos 
    590   1.1.1.3  christos     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
    591   1.1.1.3  christos 
    592   1.1.1.3  christos     PrevSciHandler = NULL;
    593   1.1.1.3  christos     NextSciHandler = AcpiGbl_SciHandlerList;
    594   1.1.1.3  christos     while (NextSciHandler)
    595   1.1.1.3  christos     {
    596   1.1.1.3  christos         if (NextSciHandler->Address == Address)
    597   1.1.1.3  christos         {
    598   1.1.1.3  christos             /* Unlink and free the SCI handler info block */
    599   1.1.1.3  christos 
    600   1.1.1.3  christos             if (PrevSciHandler)
    601   1.1.1.3  christos             {
    602   1.1.1.3  christos                 PrevSciHandler->Next = NextSciHandler->Next;
    603   1.1.1.3  christos             }
    604   1.1.1.3  christos             else
    605   1.1.1.3  christos             {
    606   1.1.1.3  christos                 AcpiGbl_SciHandlerList = NextSciHandler->Next;
    607   1.1.1.3  christos             }
    608   1.1.1.3  christos 
    609   1.1.1.3  christos             AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    610   1.1.1.3  christos             ACPI_FREE (NextSciHandler);
    611   1.1.1.3  christos             goto UnlockAndExit;
    612   1.1.1.3  christos         }
    613   1.1.1.3  christos 
    614   1.1.1.3  christos         PrevSciHandler = NextSciHandler;
    615   1.1.1.3  christos         NextSciHandler = NextSciHandler->Next;
    616       1.1    jruoho     }
    617       1.1    jruoho 
    618   1.1.1.3  christos     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    619   1.1.1.3  christos     Status = AE_NOT_EXIST;
    620       1.1    jruoho 
    621       1.1    jruoho 
    622   1.1.1.3  christos UnlockAndExit:
    623       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    624       1.1    jruoho     return_ACPI_STATUS (Status);
    625       1.1    jruoho }
    626       1.1    jruoho 
    627   1.1.1.4  christos ACPI_EXPORT_SYMBOL (AcpiRemoveSciHandler)
    628   1.1.1.4  christos 
    629       1.1    jruoho 
    630       1.1    jruoho /*******************************************************************************
    631       1.1    jruoho  *
    632   1.1.1.2    jruoho  * FUNCTION:    AcpiInstallGlobalEventHandler
    633   1.1.1.2    jruoho  *
    634   1.1.1.2    jruoho  * PARAMETERS:  Handler         - Pointer to the global event handler function
    635   1.1.1.2    jruoho  *              Context         - Value passed to the handler on each event
    636   1.1.1.2    jruoho  *
    637   1.1.1.2    jruoho  * RETURN:      Status
    638   1.1.1.2    jruoho  *
    639   1.1.1.2    jruoho  * DESCRIPTION: Saves the pointer to the handler function. The global handler
    640   1.1.1.2    jruoho  *              is invoked upon each incoming GPE and Fixed Event. It is
    641   1.1.1.2    jruoho  *              invoked at interrupt level at the time of the event dispatch.
    642   1.1.1.2    jruoho  *              Can be used to update event counters, etc.
    643   1.1.1.2    jruoho  *
    644   1.1.1.2    jruoho  ******************************************************************************/
    645   1.1.1.2    jruoho 
    646   1.1.1.2    jruoho ACPI_STATUS
    647   1.1.1.2    jruoho AcpiInstallGlobalEventHandler (
    648   1.1.1.2    jruoho     ACPI_GBL_EVENT_HANDLER  Handler,
    649   1.1.1.2    jruoho     void                    *Context)
    650   1.1.1.2    jruoho {
    651   1.1.1.2    jruoho     ACPI_STATUS             Status;
    652   1.1.1.2    jruoho 
    653   1.1.1.2    jruoho 
    654   1.1.1.2    jruoho     ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler);
    655   1.1.1.2    jruoho 
    656   1.1.1.2    jruoho 
    657   1.1.1.2    jruoho     /* Parameter validation */
    658   1.1.1.2    jruoho 
    659   1.1.1.2    jruoho     if (!Handler)
    660   1.1.1.2    jruoho     {
    661   1.1.1.2    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    662   1.1.1.2    jruoho     }
    663   1.1.1.2    jruoho 
    664   1.1.1.2    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    665   1.1.1.2    jruoho     if (ACPI_FAILURE (Status))
    666   1.1.1.2    jruoho     {
    667   1.1.1.2    jruoho         return_ACPI_STATUS (Status);
    668   1.1.1.2    jruoho     }
    669   1.1.1.2    jruoho 
    670   1.1.1.2    jruoho     /* Don't allow two handlers. */
    671   1.1.1.2    jruoho 
    672   1.1.1.2    jruoho     if (AcpiGbl_GlobalEventHandler)
    673   1.1.1.2    jruoho     {
    674   1.1.1.2    jruoho         Status = AE_ALREADY_EXISTS;
    675   1.1.1.2    jruoho         goto Cleanup;
    676   1.1.1.2    jruoho     }
    677   1.1.1.2    jruoho 
    678   1.1.1.2    jruoho     AcpiGbl_GlobalEventHandler = Handler;
    679   1.1.1.2    jruoho     AcpiGbl_GlobalEventHandlerContext = Context;
    680   1.1.1.2    jruoho 
    681   1.1.1.2    jruoho 
    682   1.1.1.2    jruoho Cleanup:
    683   1.1.1.2    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    684   1.1.1.2    jruoho     return_ACPI_STATUS (Status);
    685   1.1.1.2    jruoho }
    686   1.1.1.2    jruoho 
    687   1.1.1.2    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler)
    688   1.1.1.2    jruoho 
    689   1.1.1.2    jruoho 
    690   1.1.1.2    jruoho /*******************************************************************************
    691   1.1.1.2    jruoho  *
    692       1.1    jruoho  * FUNCTION:    AcpiInstallFixedEventHandler
    693       1.1    jruoho  *
    694       1.1    jruoho  * PARAMETERS:  Event           - Event type to enable.
    695       1.1    jruoho  *              Handler         - Pointer to the handler function for the
    696       1.1    jruoho  *                                event
    697       1.1    jruoho  *              Context         - Value passed to the handler on each GPE
    698       1.1    jruoho  *
    699       1.1    jruoho  * RETURN:      Status
    700       1.1    jruoho  *
    701       1.1    jruoho  * DESCRIPTION: Saves the pointer to the handler function and then enables the
    702       1.1    jruoho  *              event.
    703       1.1    jruoho  *
    704       1.1    jruoho  ******************************************************************************/
    705       1.1    jruoho 
    706       1.1    jruoho ACPI_STATUS
    707       1.1    jruoho AcpiInstallFixedEventHandler (
    708       1.1    jruoho     UINT32                  Event,
    709       1.1    jruoho     ACPI_EVENT_HANDLER      Handler,
    710       1.1    jruoho     void                    *Context)
    711       1.1    jruoho {
    712       1.1    jruoho     ACPI_STATUS             Status;
    713       1.1    jruoho 
    714       1.1    jruoho 
    715       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler);
    716       1.1    jruoho 
    717       1.1    jruoho 
    718       1.1    jruoho     /* Parameter validation */
    719       1.1    jruoho 
    720       1.1    jruoho     if (Event > ACPI_EVENT_MAX)
    721       1.1    jruoho     {
    722       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    723       1.1    jruoho     }
    724       1.1    jruoho 
    725       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    726       1.1    jruoho     if (ACPI_FAILURE (Status))
    727       1.1    jruoho     {
    728       1.1    jruoho         return_ACPI_STATUS (Status);
    729       1.1    jruoho     }
    730       1.1    jruoho 
    731   1.1.1.3  christos     /* Do not allow multiple handlers */
    732       1.1    jruoho 
    733   1.1.1.3  christos     if (AcpiGbl_FixedEventHandlers[Event].Handler)
    734       1.1    jruoho     {
    735       1.1    jruoho         Status = AE_ALREADY_EXISTS;
    736       1.1    jruoho         goto Cleanup;
    737       1.1    jruoho     }
    738       1.1    jruoho 
    739       1.1    jruoho     /* Install the handler before enabling the event */
    740       1.1    jruoho 
    741       1.1    jruoho     AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
    742       1.1    jruoho     AcpiGbl_FixedEventHandlers[Event].Context = Context;
    743       1.1    jruoho 
    744       1.1    jruoho     Status = AcpiEnableEvent (Event, 0);
    745       1.1    jruoho     if (ACPI_FAILURE (Status))
    746       1.1    jruoho     {
    747   1.1.1.3  christos         ACPI_WARNING ((AE_INFO,
    748   1.1.1.3  christos             "Could not enable fixed event - %s (%u)",
    749   1.1.1.3  christos             AcpiUtGetEventName (Event), Event));
    750       1.1    jruoho 
    751       1.1    jruoho         /* Remove the handler */
    752       1.1    jruoho 
    753       1.1    jruoho         AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
    754       1.1    jruoho         AcpiGbl_FixedEventHandlers[Event].Context = NULL;
    755       1.1    jruoho     }
    756       1.1    jruoho     else
    757       1.1    jruoho     {
    758       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    759   1.1.1.3  christos             "Enabled fixed event %s (%X), Handler=%p\n",
    760   1.1.1.3  christos             AcpiUtGetEventName (Event), Event, Handler));
    761       1.1    jruoho     }
    762       1.1    jruoho 
    763       1.1    jruoho 
    764       1.1    jruoho Cleanup:
    765       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    766       1.1    jruoho     return_ACPI_STATUS (Status);
    767       1.1    jruoho }
    768       1.1    jruoho 
    769       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler)
    770       1.1    jruoho 
    771       1.1    jruoho 
    772       1.1    jruoho /*******************************************************************************
    773       1.1    jruoho  *
    774       1.1    jruoho  * FUNCTION:    AcpiRemoveFixedEventHandler
    775       1.1    jruoho  *
    776       1.1    jruoho  * PARAMETERS:  Event           - Event type to disable.
    777       1.1    jruoho  *              Handler         - Address of the handler
    778       1.1    jruoho  *
    779       1.1    jruoho  * RETURN:      Status
    780       1.1    jruoho  *
    781       1.1    jruoho  * DESCRIPTION: Disables the event and unregisters the event handler.
    782       1.1    jruoho  *
    783       1.1    jruoho  ******************************************************************************/
    784       1.1    jruoho 
    785       1.1    jruoho ACPI_STATUS
    786       1.1    jruoho AcpiRemoveFixedEventHandler (
    787       1.1    jruoho     UINT32                  Event,
    788       1.1    jruoho     ACPI_EVENT_HANDLER      Handler)
    789       1.1    jruoho {
    790       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    791       1.1    jruoho 
    792       1.1    jruoho 
    793       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler);
    794       1.1    jruoho 
    795       1.1    jruoho 
    796       1.1    jruoho     /* Parameter validation */
    797       1.1    jruoho 
    798       1.1    jruoho     if (Event > ACPI_EVENT_MAX)
    799       1.1    jruoho     {
    800       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    801       1.1    jruoho     }
    802       1.1    jruoho 
    803       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    804       1.1    jruoho     if (ACPI_FAILURE (Status))
    805       1.1    jruoho     {
    806       1.1    jruoho         return_ACPI_STATUS (Status);
    807       1.1    jruoho     }
    808       1.1    jruoho 
    809       1.1    jruoho     /* Disable the event before removing the handler */
    810       1.1    jruoho 
    811       1.1    jruoho     Status = AcpiDisableEvent (Event, 0);
    812       1.1    jruoho 
    813       1.1    jruoho     /* Always Remove the handler */
    814       1.1    jruoho 
    815       1.1    jruoho     AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
    816       1.1    jruoho     AcpiGbl_FixedEventHandlers[Event].Context = NULL;
    817       1.1    jruoho 
    818       1.1    jruoho     if (ACPI_FAILURE (Status))
    819       1.1    jruoho     {
    820       1.1    jruoho         ACPI_WARNING ((AE_INFO,
    821   1.1.1.3  christos             "Could not disable fixed event - %s (%u)",
    822   1.1.1.3  christos             AcpiUtGetEventName (Event), Event));
    823       1.1    jruoho     }
    824       1.1    jruoho     else
    825       1.1    jruoho     {
    826   1.1.1.3  christos         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    827   1.1.1.3  christos             "Disabled fixed event - %s (%X)\n",
    828   1.1.1.3  christos             AcpiUtGetEventName (Event), Event));
    829       1.1    jruoho     }
    830       1.1    jruoho 
    831       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    832       1.1    jruoho     return_ACPI_STATUS (Status);
    833       1.1    jruoho }
    834       1.1    jruoho 
    835       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler)
    836       1.1    jruoho 
    837       1.1    jruoho 
    838       1.1    jruoho /*******************************************************************************
    839       1.1    jruoho  *
    840   1.1.1.5  christos  * FUNCTION:    AcpiEvInstallGpeHandler
    841       1.1    jruoho  *
    842       1.1    jruoho  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
    843       1.1    jruoho  *                                defined GPEs)
    844       1.1    jruoho  *              GpeNumber       - The GPE number within the GPE block
    845       1.1    jruoho  *              Type            - Whether this GPE should be treated as an
    846       1.1    jruoho  *                                edge- or level-triggered interrupt.
    847   1.1.1.5  christos  *              IsRawHandler    - Whether this GPE should be handled using
    848   1.1.1.5  christos  *                                the special GPE handler mode.
    849       1.1    jruoho  *              Address         - Address of the handler
    850       1.1    jruoho  *              Context         - Value passed to the handler on each GPE
    851       1.1    jruoho  *
    852       1.1    jruoho  * RETURN:      Status
    853       1.1    jruoho  *
    854   1.1.1.5  christos  * DESCRIPTION: Internal function to install a handler for a General Purpose
    855   1.1.1.5  christos  *              Event.
    856       1.1    jruoho  *
    857       1.1    jruoho  ******************************************************************************/
    858       1.1    jruoho 
    859   1.1.1.5  christos static ACPI_STATUS
    860   1.1.1.5  christos AcpiEvInstallGpeHandler (
    861       1.1    jruoho     ACPI_HANDLE             GpeDevice,
    862       1.1    jruoho     UINT32                  GpeNumber,
    863       1.1    jruoho     UINT32                  Type,
    864   1.1.1.5  christos     BOOLEAN                 IsRawHandler,
    865   1.1.1.2    jruoho     ACPI_GPE_HANDLER        Address,
    866       1.1    jruoho     void                    *Context)
    867       1.1    jruoho {
    868       1.1    jruoho     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
    869   1.1.1.2    jruoho     ACPI_GPE_HANDLER_INFO   *Handler;
    870       1.1    jruoho     ACPI_STATUS             Status;
    871       1.1    jruoho     ACPI_CPU_FLAGS          Flags;
    872       1.1    jruoho 
    873       1.1    jruoho 
    874   1.1.1.5  christos     ACPI_FUNCTION_TRACE (EvInstallGpeHandler);
    875       1.1    jruoho 
    876       1.1    jruoho 
    877       1.1    jruoho     /* Parameter validation */
    878       1.1    jruoho 
    879       1.1    jruoho     if ((!Address) || (Type & ~ACPI_GPE_XRUPT_TYPE_MASK))
    880       1.1    jruoho     {
    881       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    882       1.1    jruoho     }
    883       1.1    jruoho 
    884       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    885       1.1    jruoho     if (ACPI_FAILURE (Status))
    886       1.1    jruoho     {
    887       1.1    jruoho         return_ACPI_STATUS (Status);
    888       1.1    jruoho     }
    889       1.1    jruoho 
    890   1.1.1.2    jruoho     /* Allocate and init handler object (before lock) */
    891   1.1.1.2    jruoho 
    892   1.1.1.2    jruoho     Handler = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO));
    893   1.1.1.2    jruoho     if (!Handler)
    894   1.1.1.2    jruoho     {
    895   1.1.1.2    jruoho         Status = AE_NO_MEMORY;
    896   1.1.1.2    jruoho         goto UnlockAndExit;
    897   1.1.1.2    jruoho     }
    898   1.1.1.2    jruoho 
    899   1.1.1.2    jruoho     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
    900   1.1.1.2    jruoho 
    901       1.1    jruoho     /* Ensure that we have a valid GPE number */
    902       1.1    jruoho 
    903       1.1    jruoho     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
    904       1.1    jruoho     if (!GpeEventInfo)
    905       1.1    jruoho     {
    906       1.1    jruoho         Status = AE_BAD_PARAMETER;
    907   1.1.1.2    jruoho         goto FreeAndExit;
    908       1.1    jruoho     }
    909       1.1    jruoho 
    910       1.1    jruoho     /* Make sure that there isn't a handler there already */
    911       1.1    jruoho 
    912   1.1.1.5  christos     if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
    913   1.1.1.5  christos             ACPI_GPE_DISPATCH_HANDLER) ||
    914   1.1.1.5  christos         (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
    915   1.1.1.5  christos             ACPI_GPE_DISPATCH_RAW_HANDLER))
    916       1.1    jruoho     {
    917       1.1    jruoho         Status = AE_ALREADY_EXISTS;
    918   1.1.1.2    jruoho         goto FreeAndExit;
    919       1.1    jruoho     }
    920       1.1    jruoho 
    921   1.1.1.2    jruoho     Handler->Address = Address;
    922   1.1.1.2    jruoho     Handler->Context = Context;
    923   1.1.1.2    jruoho     Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;
    924   1.1.1.2    jruoho     Handler->OriginalFlags = (UINT8) (GpeEventInfo->Flags &
    925   1.1.1.2    jruoho         (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK));
    926       1.1    jruoho 
    927   1.1.1.2    jruoho     /*
    928   1.1.1.2    jruoho      * If the GPE is associated with a method, it may have been enabled
    929   1.1.1.2    jruoho      * automatically during initialization, in which case it has to be
    930   1.1.1.2    jruoho      * disabled now to avoid spurious execution of the handler.
    931   1.1.1.2    jruoho      */
    932   1.1.1.5  christos     if (((ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
    933   1.1.1.5  christos             ACPI_GPE_DISPATCH_METHOD) ||
    934   1.1.1.5  christos          (ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
    935   1.1.1.5  christos             ACPI_GPE_DISPATCH_NOTIFY)) &&
    936   1.1.1.2    jruoho         GpeEventInfo->RuntimeCount)
    937       1.1    jruoho     {
    938   1.1.1.2    jruoho         Handler->OriginallyEnabled = TRUE;
    939   1.1.1.2    jruoho         (void) AcpiEvRemoveGpeReference (GpeEventInfo);
    940       1.1    jruoho 
    941   1.1.1.2    jruoho         /* Sanity check of original type against new type */
    942       1.1    jruoho 
    943   1.1.1.2    jruoho         if (Type != (UINT32) (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
    944   1.1.1.2    jruoho         {
    945   1.1.1.2    jruoho             ACPI_WARNING ((AE_INFO, "GPE type mismatch (level/edge)"));
    946   1.1.1.2    jruoho         }
    947       1.1    jruoho     }
    948       1.1    jruoho 
    949       1.1    jruoho     /* Install the handler */
    950       1.1    jruoho 
    951       1.1    jruoho     GpeEventInfo->Dispatch.Handler = Handler;
    952       1.1    jruoho 
    953   1.1.1.2    jruoho     /* Setup up dispatch flags to indicate handler (vs. method/notify) */
    954       1.1    jruoho 
    955       1.1    jruoho     GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
    956   1.1.1.5  christos     GpeEventInfo->Flags |= (UINT8) (Type | (IsRawHandler ?
    957   1.1.1.5  christos         ACPI_GPE_DISPATCH_RAW_HANDLER : ACPI_GPE_DISPATCH_HANDLER));
    958       1.1    jruoho 
    959       1.1    jruoho     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    960       1.1    jruoho 
    961       1.1    jruoho 
    962       1.1    jruoho UnlockAndExit:
    963       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    964       1.1    jruoho     return_ACPI_STATUS (Status);
    965   1.1.1.2    jruoho 
    966   1.1.1.2    jruoho FreeAndExit:
    967   1.1.1.2    jruoho     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    968   1.1.1.2    jruoho     ACPI_FREE (Handler);
    969   1.1.1.2    jruoho     goto UnlockAndExit;
    970       1.1    jruoho }
    971       1.1    jruoho 
    972   1.1.1.5  christos 
    973   1.1.1.5  christos /*******************************************************************************
    974   1.1.1.5  christos  *
    975   1.1.1.5  christos  * FUNCTION:    AcpiInstallGpeHandler
    976   1.1.1.5  christos  *
    977   1.1.1.5  christos  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
    978   1.1.1.5  christos  *                                defined GPEs)
    979   1.1.1.5  christos  *              GpeNumber       - The GPE number within the GPE block
    980   1.1.1.5  christos  *              Type            - Whether this GPE should be treated as an
    981   1.1.1.5  christos  *                                edge- or level-triggered interrupt.
    982   1.1.1.5  christos  *              Address         - Address of the handler
    983   1.1.1.5  christos  *              Context         - Value passed to the handler on each GPE
    984   1.1.1.5  christos  *
    985   1.1.1.5  christos  * RETURN:      Status
    986   1.1.1.5  christos  *
    987   1.1.1.5  christos  * DESCRIPTION: Install a handler for a General Purpose Event.
    988   1.1.1.5  christos  *
    989   1.1.1.5  christos  ******************************************************************************/
    990   1.1.1.5  christos 
    991   1.1.1.5  christos ACPI_STATUS
    992   1.1.1.5  christos AcpiInstallGpeHandler (
    993   1.1.1.5  christos     ACPI_HANDLE             GpeDevice,
    994   1.1.1.5  christos     UINT32                  GpeNumber,
    995   1.1.1.5  christos     UINT32                  Type,
    996   1.1.1.5  christos     ACPI_GPE_HANDLER        Address,
    997   1.1.1.5  christos     void                    *Context)
    998   1.1.1.5  christos {
    999   1.1.1.5  christos     ACPI_STATUS             Status;
   1000   1.1.1.5  christos 
   1001   1.1.1.5  christos 
   1002   1.1.1.5  christos     ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);
   1003   1.1.1.5  christos 
   1004   1.1.1.5  christos 
   1005   1.1.1.6  christos     Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type,
   1006   1.1.1.6  christos         FALSE, Address, Context);
   1007   1.1.1.5  christos 
   1008   1.1.1.5  christos     return_ACPI_STATUS (Status);
   1009   1.1.1.5  christos }
   1010   1.1.1.5  christos 
   1011       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)
   1012       1.1    jruoho 
   1013       1.1    jruoho 
   1014       1.1    jruoho /*******************************************************************************
   1015       1.1    jruoho  *
   1016   1.1.1.5  christos  * FUNCTION:    AcpiInstallGpeRawHandler
   1017   1.1.1.5  christos  *
   1018   1.1.1.5  christos  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
   1019   1.1.1.5  christos  *                                defined GPEs)
   1020   1.1.1.5  christos  *              GpeNumber       - The GPE number within the GPE block
   1021   1.1.1.5  christos  *              Type            - Whether this GPE should be treated as an
   1022   1.1.1.5  christos  *                                edge- or level-triggered interrupt.
   1023   1.1.1.5  christos  *              Address         - Address of the handler
   1024   1.1.1.5  christos  *              Context         - Value passed to the handler on each GPE
   1025   1.1.1.5  christos  *
   1026   1.1.1.5  christos  * RETURN:      Status
   1027   1.1.1.5  christos  *
   1028   1.1.1.5  christos  * DESCRIPTION: Install a handler for a General Purpose Event.
   1029   1.1.1.5  christos  *
   1030   1.1.1.5  christos  ******************************************************************************/
   1031   1.1.1.5  christos 
   1032   1.1.1.5  christos ACPI_STATUS
   1033   1.1.1.5  christos AcpiInstallGpeRawHandler (
   1034   1.1.1.5  christos     ACPI_HANDLE             GpeDevice,
   1035   1.1.1.5  christos     UINT32                  GpeNumber,
   1036   1.1.1.5  christos     UINT32                  Type,
   1037   1.1.1.5  christos     ACPI_GPE_HANDLER        Address,
   1038   1.1.1.5  christos     void                    *Context)
   1039   1.1.1.5  christos {
   1040   1.1.1.5  christos     ACPI_STATUS             Status;
   1041   1.1.1.5  christos 
   1042   1.1.1.5  christos 
   1043   1.1.1.5  christos     ACPI_FUNCTION_TRACE (AcpiInstallGpeRawHandler);
   1044   1.1.1.5  christos 
   1045   1.1.1.5  christos 
   1046   1.1.1.6  christos     Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type,
   1047   1.1.1.6  christos         TRUE, Address, Context);
   1048   1.1.1.5  christos 
   1049   1.1.1.5  christos     return_ACPI_STATUS (Status);
   1050   1.1.1.5  christos }
   1051   1.1.1.5  christos 
   1052   1.1.1.5  christos ACPI_EXPORT_SYMBOL (AcpiInstallGpeRawHandler)
   1053   1.1.1.5  christos 
   1054   1.1.1.5  christos 
   1055   1.1.1.5  christos /*******************************************************************************
   1056   1.1.1.5  christos  *
   1057       1.1    jruoho  * FUNCTION:    AcpiRemoveGpeHandler
   1058       1.1    jruoho  *
   1059       1.1    jruoho  * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT
   1060       1.1    jruoho  *                                defined GPEs)
   1061       1.1    jruoho  *              GpeNumber       - The event to remove a handler
   1062       1.1    jruoho  *              Address         - Address of the handler
   1063       1.1    jruoho  *
   1064       1.1    jruoho  * RETURN:      Status
   1065       1.1    jruoho  *
   1066       1.1    jruoho  * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
   1067       1.1    jruoho  *
   1068       1.1    jruoho  ******************************************************************************/
   1069       1.1    jruoho 
   1070       1.1    jruoho ACPI_STATUS
   1071       1.1    jruoho AcpiRemoveGpeHandler (
   1072       1.1    jruoho     ACPI_HANDLE             GpeDevice,
   1073       1.1    jruoho     UINT32                  GpeNumber,
   1074   1.1.1.2    jruoho     ACPI_GPE_HANDLER        Address)
   1075       1.1    jruoho {
   1076       1.1    jruoho     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
   1077   1.1.1.2    jruoho     ACPI_GPE_HANDLER_INFO   *Handler;
   1078       1.1    jruoho     ACPI_STATUS             Status;
   1079       1.1    jruoho     ACPI_CPU_FLAGS          Flags;
   1080       1.1    jruoho 
   1081       1.1    jruoho 
   1082       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler);
   1083       1.1    jruoho 
   1084       1.1    jruoho 
   1085       1.1    jruoho     /* Parameter validation */
   1086       1.1    jruoho 
   1087       1.1    jruoho     if (!Address)
   1088       1.1    jruoho     {
   1089       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
   1090       1.1    jruoho     }
   1091       1.1    jruoho 
   1092       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
   1093       1.1    jruoho     if (ACPI_FAILURE (Status))
   1094       1.1    jruoho     {
   1095       1.1    jruoho         return_ACPI_STATUS (Status);
   1096       1.1    jruoho     }
   1097       1.1    jruoho 
   1098   1.1.1.2    jruoho     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
   1099   1.1.1.2    jruoho 
   1100       1.1    jruoho     /* Ensure that we have a valid GPE number */
   1101       1.1    jruoho 
   1102       1.1    jruoho     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
   1103       1.1    jruoho     if (!GpeEventInfo)
   1104       1.1    jruoho     {
   1105       1.1    jruoho         Status = AE_BAD_PARAMETER;
   1106       1.1    jruoho         goto UnlockAndExit;
   1107       1.1    jruoho     }
   1108       1.1    jruoho 
   1109       1.1    jruoho     /* Make sure that a handler is indeed installed */
   1110       1.1    jruoho 
   1111   1.1.1.5  christos     if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
   1112   1.1.1.5  christos             ACPI_GPE_DISPATCH_HANDLER) &&
   1113   1.1.1.5  christos         (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
   1114   1.1.1.5  christos             ACPI_GPE_DISPATCH_RAW_HANDLER))
   1115       1.1    jruoho     {
   1116       1.1    jruoho         Status = AE_NOT_EXIST;
   1117       1.1    jruoho         goto UnlockAndExit;
   1118       1.1    jruoho     }
   1119       1.1    jruoho 
   1120       1.1    jruoho     /* Make sure that the installed handler is the same */
   1121       1.1    jruoho 
   1122       1.1    jruoho     if (GpeEventInfo->Dispatch.Handler->Address != Address)
   1123       1.1    jruoho     {
   1124       1.1    jruoho         Status = AE_BAD_PARAMETER;
   1125       1.1    jruoho         goto UnlockAndExit;
   1126       1.1    jruoho     }
   1127       1.1    jruoho 
   1128       1.1    jruoho     /* Remove the handler */
   1129       1.1    jruoho 
   1130       1.1    jruoho     Handler = GpeEventInfo->Dispatch.Handler;
   1131   1.1.1.5  christos     GpeEventInfo->Dispatch.Handler = NULL;
   1132       1.1    jruoho 
   1133       1.1    jruoho     /* Restore Method node (if any), set dispatch flags */
   1134       1.1    jruoho 
   1135       1.1    jruoho     GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;
   1136   1.1.1.2    jruoho     GpeEventInfo->Flags &=
   1137   1.1.1.2    jruoho         ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
   1138   1.1.1.2    jruoho     GpeEventInfo->Flags |= Handler->OriginalFlags;
   1139   1.1.1.2    jruoho 
   1140   1.1.1.2    jruoho     /*
   1141   1.1.1.2    jruoho      * If the GPE was previously associated with a method and it was
   1142   1.1.1.2    jruoho      * enabled, it should be enabled at this point to restore the
   1143   1.1.1.2    jruoho      * post-initialization configuration.
   1144   1.1.1.2    jruoho      */
   1145   1.1.1.5  christos     if (((ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
   1146   1.1.1.5  christos             ACPI_GPE_DISPATCH_METHOD) ||
   1147   1.1.1.5  christos          (ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
   1148   1.1.1.5  christos             ACPI_GPE_DISPATCH_NOTIFY)) &&
   1149   1.1.1.2    jruoho         Handler->OriginallyEnabled)
   1150       1.1    jruoho     {
   1151  1.1.1.10  christos         (void) AcpiEvAddGpeReference (GpeEventInfo, FALSE);
   1152   1.1.1.8  christos         if (ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
   1153   1.1.1.8  christos         {
   1154   1.1.1.8  christos             /* Poll edge triggered GPEs to handle existing events */
   1155   1.1.1.8  christos 
   1156   1.1.1.8  christos             AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
   1157   1.1.1.8  christos             (void) AcpiEvDetectGpe (
   1158   1.1.1.8  christos                 GpeDevice, GpeEventInfo, GpeNumber);
   1159   1.1.1.8  christos             Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
   1160   1.1.1.8  christos         }
   1161       1.1    jruoho     }
   1162       1.1    jruoho 
   1163   1.1.1.4  christos     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
   1164   1.1.1.4  christos     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
   1165   1.1.1.4  christos 
   1166   1.1.1.4  christos     /* Make sure all deferred GPE tasks are completed */
   1167   1.1.1.4  christos 
   1168   1.1.1.4  christos     AcpiOsWaitEventsComplete ();
   1169   1.1.1.4  christos 
   1170       1.1    jruoho     /* Now we can free the handler object */
   1171       1.1    jruoho 
   1172       1.1    jruoho     ACPI_FREE (Handler);
   1173   1.1.1.4  christos     return_ACPI_STATUS (Status);
   1174       1.1    jruoho 
   1175       1.1    jruoho UnlockAndExit:
   1176   1.1.1.2    jruoho     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
   1177       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
   1178       1.1    jruoho     return_ACPI_STATUS (Status);
   1179       1.1    jruoho }
   1180       1.1    jruoho 
   1181       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler)
   1182       1.1    jruoho 
   1183       1.1    jruoho 
   1184       1.1    jruoho /*******************************************************************************
   1185       1.1    jruoho  *
   1186       1.1    jruoho  * FUNCTION:    AcpiAcquireGlobalLock
   1187       1.1    jruoho  *
   1188       1.1    jruoho  * PARAMETERS:  Timeout         - How long the caller is willing to wait
   1189       1.1    jruoho  *              Handle          - Where the handle to the lock is returned
   1190       1.1    jruoho  *                                (if acquired)
   1191       1.1    jruoho  *
   1192       1.1    jruoho  * RETURN:      Status
   1193       1.1    jruoho  *
   1194       1.1    jruoho  * DESCRIPTION: Acquire the ACPI Global Lock
   1195       1.1    jruoho  *
   1196       1.1    jruoho  * Note: Allows callers with the same thread ID to acquire the global lock
   1197       1.1    jruoho  * multiple times. In other words, externally, the behavior of the global lock
   1198       1.1    jruoho  * is identical to an AML mutex. On the first acquire, a new handle is
   1199       1.1    jruoho  * returned. On any subsequent calls to acquire by the same thread, the same
   1200       1.1    jruoho  * handle is returned.
   1201       1.1    jruoho  *
   1202       1.1    jruoho  ******************************************************************************/
   1203       1.1    jruoho 
   1204       1.1    jruoho ACPI_STATUS
   1205       1.1    jruoho AcpiAcquireGlobalLock (
   1206       1.1    jruoho     UINT16                  Timeout,
   1207       1.1    jruoho     UINT32                  *Handle)
   1208       1.1    jruoho {
   1209       1.1    jruoho     ACPI_STATUS             Status;
   1210       1.1    jruoho 
   1211       1.1    jruoho 
   1212       1.1    jruoho     if (!Handle)
   1213       1.1    jruoho     {
   1214       1.1    jruoho         return (AE_BAD_PARAMETER);
   1215       1.1    jruoho     }
   1216       1.1    jruoho 
   1217       1.1    jruoho     /* Must lock interpreter to prevent race conditions */
   1218       1.1    jruoho 
   1219       1.1    jruoho     AcpiExEnterInterpreter ();
   1220       1.1    jruoho 
   1221       1.1    jruoho     Status = AcpiExAcquireMutexObject (Timeout,
   1222   1.1.1.6  christos         AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
   1223       1.1    jruoho 
   1224       1.1    jruoho     if (ACPI_SUCCESS (Status))
   1225       1.1    jruoho     {
   1226       1.1    jruoho         /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
   1227       1.1    jruoho 
   1228       1.1    jruoho         *Handle = AcpiGbl_GlobalLockHandle;
   1229       1.1    jruoho     }
   1230       1.1    jruoho 
   1231       1.1    jruoho     AcpiExExitInterpreter ();
   1232       1.1    jruoho     return (Status);
   1233       1.1    jruoho }
   1234       1.1    jruoho 
   1235       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock)
   1236       1.1    jruoho 
   1237       1.1    jruoho 
   1238       1.1    jruoho /*******************************************************************************
   1239       1.1    jruoho  *
   1240       1.1    jruoho  * FUNCTION:    AcpiReleaseGlobalLock
   1241       1.1    jruoho  *
   1242       1.1    jruoho  * PARAMETERS:  Handle      - Returned from AcpiAcquireGlobalLock
   1243       1.1    jruoho  *
   1244       1.1    jruoho  * RETURN:      Status
   1245       1.1    jruoho  *
   1246       1.1    jruoho  * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
   1247       1.1    jruoho  *
   1248       1.1    jruoho  ******************************************************************************/
   1249       1.1    jruoho 
   1250       1.1    jruoho ACPI_STATUS
   1251       1.1    jruoho AcpiReleaseGlobalLock (
   1252       1.1    jruoho     UINT32                  Handle)
   1253       1.1    jruoho {
   1254       1.1    jruoho     ACPI_STATUS             Status;
   1255       1.1    jruoho 
   1256       1.1    jruoho 
   1257       1.1    jruoho     if (!Handle || (Handle != AcpiGbl_GlobalLockHandle))
   1258       1.1    jruoho     {
   1259       1.1    jruoho         return (AE_NOT_ACQUIRED);
   1260       1.1    jruoho     }
   1261       1.1    jruoho 
   1262       1.1    jruoho     Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
   1263       1.1    jruoho     return (Status);
   1264       1.1    jruoho }
   1265       1.1    jruoho 
   1266       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock)
   1267       1.1    jruoho 
   1268   1.1.1.3  christos #endif /* !ACPI_REDUCED_HARDWARE */
   1269