Print this page
update to acpica-unix2-20140114
update to acpica-unix2-20130927
acpica-unix2-20130823
PANKOVs restructure
   1 /******************************************************************************
   2  *
   3  * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
   4  *
   5  *****************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2011, Intel Corp.
   9  * All rights reserved.
  10  *
  11  * Redistribution and use in source and binary forms, with or without
  12  * modification, are permitted provided that the following conditions
  13  * are met:
  14  * 1. Redistributions of source code must retain the above copyright
  15  *    notice, this list of conditions, and the following disclaimer,
  16  *    without modification.
  17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18  *    substantially similar to the "NO WARRANTY" disclaimer below
  19  *    ("Disclaimer") and any redistribution must be conditioned upon
  20  *    including a substantially similar Disclaimer requirement for further
  21  *    binary redistribution.
  22  * 3. Neither the names of the above-listed copyright holders nor the names
  23  *    of any contributors may be used to endorse or promote products derived
  24  *    from this software without specific prior written permission.
  25  *
  26  * Alternatively, this software may be distributed under the terms of the
  27  * GNU General Public License ("GPL") version 2 as published by the Free
  28  * Software Foundation.
  29  *
  30  * NO WARRANTY
  31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41  * POSSIBILITY OF SUCH DAMAGES.
  42  */
  43 
  44 
  45 #define __EVXFGPE_C__

  46 
  47 #include "acpi.h"
  48 #include "accommon.h"
  49 #include "acevents.h"
  50 #include "acnamesp.h"
  51 
  52 #define _COMPONENT          ACPI_EVENTS
  53         ACPI_MODULE_NAME    ("evxfgpe")
  54 
  55 

  56 /*******************************************************************************
  57  *
  58  * FUNCTION:    AcpiUpdateAllGpes
  59  *
  60  * PARAMETERS:  None
  61  *
  62  * RETURN:      Status
  63  *
  64  * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
  65  *              associated _Lxx or _Exx methods and are not pointed to by any
  66  *              device _PRW methods (this indicates that these GPEs are
  67  *              generally intended for system or device wakeup. Such GPEs
  68  *              have to be enabled directly when the devices whose _PRW
  69  *              methods point to them are set up for wakeup signaling.)
  70  *
  71  * NOTE: Should be called after any GPEs are added to the system. Primarily,
  72  * after the system _PRW methods have been run, but also after a GPE Block
  73  * Device has been added or if any new GPE methods have been added via a
  74  * dynamic table load.
  75  *
  76  ******************************************************************************/
  77 
  78 ACPI_STATUS
  79 AcpiUpdateAllGpes (
  80     void)
  81 {
  82     ACPI_STATUS             Status;
  83 
  84 
  85     ACPI_FUNCTION_TRACE (AcpiUpdateGpes);
  86 
  87 
  88     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
  89     if (ACPI_FAILURE (Status))
  90     {
  91         return_ACPI_STATUS (Status);
  92     }
  93 
  94     if (AcpiGbl_AllGpesInitialized)
  95     {
  96         goto UnlockAndExit;
  97     }
  98 
  99     Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock, NULL);
 100     if (ACPI_SUCCESS (Status))
 101     {
 102         AcpiGbl_AllGpesInitialized = TRUE;
 103     }
 104 
 105 UnlockAndExit:


 232 
 233     ACPI_FUNCTION_TRACE (AcpiSetGpe);
 234 
 235 
 236     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
 237 
 238     /* Ensure that we have a valid GPE number */
 239 
 240     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
 241     if (!GpeEventInfo)
 242     {
 243         Status = AE_BAD_PARAMETER;
 244         goto UnlockAndExit;
 245     }
 246 
 247     /* Perform the action */
 248 
 249     switch (Action)
 250     {
 251     case ACPI_GPE_ENABLE:

 252         Status = AcpiEvEnableGpe (GpeEventInfo);
 253         break;
 254 
 255     case ACPI_GPE_DISABLE:

 256         Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
 257         break;
 258 
 259     default:

 260         Status = AE_BAD_PARAMETER;
 261         break;
 262     }
 263 
 264 UnlockAndExit:
 265     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
 266     return_ACPI_STATUS (Status);
 267 }
 268 
 269 ACPI_EXPORT_SYMBOL (AcpiSetGpe)
 270 
 271 
 272 /*******************************************************************************
 273  *
 274  * FUNCTION:    AcpiSetupGpeForWake
 275  *
 276  * PARAMETERS:  WakeDevice          - Device associated with the GPE (via _PRW)
 277  *              GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
 278  *              GpeNumber           - GPE level within the GPE block
 279  *
 280  * RETURN:      Status
 281  *
 282  * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
 283  *              interface is intended to be used as the host executes the
 284  *              _PRW methods (Power Resources for Wake) in the system tables.
 285  *              Each _PRW appears under a Device Object (The WakeDevice), and
 286  *              contains the info for the wake GPE associated with the
 287  *              WakeDevice.
 288  *
 289  ******************************************************************************/
 290 
 291 ACPI_STATUS
 292 AcpiSetupGpeForWake (
 293     ACPI_HANDLE             WakeDevice,
 294     ACPI_HANDLE             GpeDevice,
 295     UINT32                  GpeNumber)
 296 {
 297     ACPI_STATUS             Status = AE_BAD_PARAMETER;
 298     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
 299     ACPI_NAMESPACE_NODE     *DeviceNode;


 300     ACPI_CPU_FLAGS          Flags;
 301 
 302 
 303     ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
 304 
 305 
 306     /* Parameter Validation */
 307 
 308     if (!WakeDevice)
 309     {
 310         /*
 311          * By forcing WakeDevice to be valid, we automatically enable the
 312          * implicit notify feature on all hosts.
 313          */
 314         return_ACPI_STATUS (AE_BAD_PARAMETER);
 315     }
 316 
 317     /* Handle root object case */
 318 
 319     if (WakeDevice == ACPI_ROOT_OBJECT)
 320     {
 321         DeviceNode = AcpiGbl_RootNode;
 322     }
 323     else
 324     {
 325         DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
 326     }
 327 
 328     /* Validate WakeDevice is of type Device */
 329 
 330     if (DeviceNode->Type != ACPI_TYPE_DEVICE)
 331     {
 332         return_ACPI_STATUS (AE_BAD_PARAMETER);
 333     }
 334 











 335     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
 336 
 337     /* Ensure that we have a valid GPE number */
 338 
 339     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
 340     if (GpeEventInfo)
 341     {




 342         /*
 343          * If there is no method or handler for this GPE, then the
 344          * WakeDevice will be notified whenever this GPE fires (aka
 345          * "implicit notify") Note: The GPE is assumed to be
 346          * level-triggered (for windows compatibility).
 347          */
 348         if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
 349                 ACPI_GPE_DISPATCH_NONE)
 350         {




 351             GpeEventInfo->Flags =
 352                 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
 353             GpeEventInfo->Dispatch.DeviceNode = DeviceNode;
 354         }
 355 






























 356         GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
 357         Status = AE_OK;
 358     }
 359 


 360     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);







 361     return_ACPI_STATUS (Status);
 362 }
 363 
 364 ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
 365 
 366 
 367 /*******************************************************************************
 368  *
 369  * FUNCTION:    AcpiSetGpeWakeMask
 370  *
 371  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
 372  *              GpeNumber           - GPE level within the GPE block
 373  *              Action              - Enable or Disable
 374  *
 375  * RETURN:      Status
 376  *
 377  * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
 378  *              already be marked as a WAKE GPE.
 379  *
 380  ******************************************************************************/


 404     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
 405     if (!GpeEventInfo)
 406     {
 407         Status = AE_BAD_PARAMETER;
 408         goto UnlockAndExit;
 409     }
 410 
 411     if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
 412     {
 413         Status = AE_TYPE;
 414         goto UnlockAndExit;
 415     }
 416 
 417     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
 418     if (!GpeRegisterInfo)
 419     {
 420         Status = AE_NOT_EXIST;
 421         goto UnlockAndExit;
 422     }
 423 
 424     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
 425 
 426     /* Perform the action */
 427 
 428     switch (Action)
 429     {
 430     case ACPI_GPE_ENABLE:

 431         ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
 432         break;
 433 
 434     case ACPI_GPE_DISABLE:

 435         ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
 436         break;
 437 
 438     default:

 439         ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
 440         Status = AE_BAD_PARAMETER;
 441         break;
 442     }
 443 
 444 UnlockAndExit:
 445     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
 446     return_ACPI_STATUS (Status);
 447 }
 448 
 449 ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
 450 
 451 
 452 /*******************************************************************************
 453  *
 454  * FUNCTION:    AcpiClearGpe
 455  *
 456  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
 457  *              GpeNumber           - GPE level within the GPE block
 458  *


 698 {
 699     ACPI_STATUS             Status;
 700     ACPI_OPERAND_OBJECT     *ObjDesc;
 701     ACPI_NAMESPACE_NODE     *Node;
 702     ACPI_GPE_BLOCK_INFO     *GpeBlock;
 703 
 704 
 705     ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
 706 
 707 
 708     if ((!GpeDevice)       ||
 709         (!GpeBlockAddress) ||
 710         (!RegisterCount))
 711     {
 712         return_ACPI_STATUS (AE_BAD_PARAMETER);
 713     }
 714 
 715     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
 716     if (ACPI_FAILURE (Status))
 717     {
 718         return (Status);
 719     }
 720 
 721     Node = AcpiNsValidateHandle (GpeDevice);
 722     if (!Node)
 723     {
 724         Status = AE_BAD_PARAMETER;
 725         goto UnlockAndExit;
 726     }
 727 














 728     /*
 729      * For user-installed GPE Block Devices, the GpeBlockBaseNumber
 730      * is always zero
 731      */
 732     Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
 733                 0, InterruptNumber, &GpeBlock);
 734     if (ACPI_FAILURE (Status))
 735     {
 736         goto UnlockAndExit;
 737     }
 738 
 739     /* Install block in the DeviceObject attached to the node */
 740 
 741     ObjDesc = AcpiNsGetAttachedObject (Node);
 742     if (!ObjDesc)
 743     {
 744         /*
 745          * No object, create a new one (Device nodes do not always have
 746          * an attached object)
 747          */


 791 ACPI_STATUS
 792 AcpiRemoveGpeBlock (
 793     ACPI_HANDLE             GpeDevice)
 794 {
 795     ACPI_OPERAND_OBJECT     *ObjDesc;
 796     ACPI_STATUS             Status;
 797     ACPI_NAMESPACE_NODE     *Node;
 798 
 799 
 800     ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
 801 
 802 
 803     if (!GpeDevice)
 804     {
 805         return_ACPI_STATUS (AE_BAD_PARAMETER);
 806     }
 807 
 808     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
 809     if (ACPI_FAILURE (Status))
 810     {
 811         return (Status);
 812     }
 813 
 814     Node = AcpiNsValidateHandle (GpeDevice);
 815     if (!Node)
 816     {
 817         Status = AE_BAD_PARAMETER;
 818         goto UnlockAndExit;
 819     }
 820 








 821     /* Get the DeviceObject attached to the node */
 822 
 823     ObjDesc = AcpiNsGetAttachedObject (Node);
 824     if (!ObjDesc ||
 825         !ObjDesc->Device.GpeBlock)
 826     {
 827         return_ACPI_STATUS (AE_NULL_OBJECT);
 828     }
 829 
 830     /* Delete the GPE block (but not the DeviceObject) */
 831 
 832     Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
 833     if (ACPI_SUCCESS (Status))
 834     {
 835         ObjDesc->Device.GpeBlock = NULL;
 836     }
 837 
 838 UnlockAndExit:
 839     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
 840     return_ACPI_STATUS (Status);


 881     }
 882 
 883     /* Setup and walk the GPE list */
 884 
 885     Info.Index = Index;
 886     Info.Status = AE_NOT_EXIST;
 887     Info.GpeDevice = NULL;
 888     Info.NextBlockBaseIndex = 0;
 889 
 890     Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
 891     if (ACPI_FAILURE (Status))
 892     {
 893         return_ACPI_STATUS (Status);
 894     }
 895 
 896     *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
 897     return_ACPI_STATUS (Info.Status);
 898 }
 899 
 900 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)


   1 /******************************************************************************
   2  *
   3  * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
   4  *
   5  *****************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2014, Intel Corp.
   9  * All rights reserved.
  10  *
  11  * Redistribution and use in source and binary forms, with or without
  12  * modification, are permitted provided that the following conditions
  13  * are met:
  14  * 1. Redistributions of source code must retain the above copyright
  15  *    notice, this list of conditions, and the following disclaimer,
  16  *    without modification.
  17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18  *    substantially similar to the "NO WARRANTY" disclaimer below
  19  *    ("Disclaimer") and any redistribution must be conditioned upon
  20  *    including a substantially similar Disclaimer requirement for further
  21  *    binary redistribution.
  22  * 3. Neither the names of the above-listed copyright holders nor the names
  23  *    of any contributors may be used to endorse or promote products derived
  24  *    from this software without specific prior written permission.
  25  *
  26  * Alternatively, this software may be distributed under the terms of the
  27  * GNU General Public License ("GPL") version 2 as published by the Free
  28  * Software Foundation.
  29  *
  30  * NO WARRANTY
  31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41  * POSSIBILITY OF SUCH DAMAGES.
  42  */
  43 
  44 
  45 #define __EVXFGPE_C__
  46 #define EXPORT_ACPI_INTERFACES
  47 
  48 #include "acpi.h"
  49 #include "accommon.h"
  50 #include "acevents.h"
  51 #include "acnamesp.h"
  52 
  53 #define _COMPONENT          ACPI_EVENTS
  54         ACPI_MODULE_NAME    ("evxfgpe")
  55 
  56 
  57 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  58 /*******************************************************************************
  59  *
  60  * FUNCTION:    AcpiUpdateAllGpes
  61  *
  62  * PARAMETERS:  None
  63  *
  64  * RETURN:      Status
  65  *
  66  * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
  67  *              associated _Lxx or _Exx methods and are not pointed to by any
  68  *              device _PRW methods (this indicates that these GPEs are
  69  *              generally intended for system or device wakeup. Such GPEs
  70  *              have to be enabled directly when the devices whose _PRW
  71  *              methods point to them are set up for wakeup signaling.)
  72  *
  73  * NOTE: Should be called after any GPEs are added to the system. Primarily,
  74  * after the system _PRW methods have been run, but also after a GPE Block
  75  * Device has been added or if any new GPE methods have been added via a
  76  * dynamic table load.
  77  *
  78  ******************************************************************************/
  79 
  80 ACPI_STATUS
  81 AcpiUpdateAllGpes (
  82     void)
  83 {
  84     ACPI_STATUS             Status;
  85 
  86 
  87     ACPI_FUNCTION_TRACE (AcpiUpdateAllGpes);
  88 
  89 
  90     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
  91     if (ACPI_FAILURE (Status))
  92     {
  93         return_ACPI_STATUS (Status);
  94     }
  95 
  96     if (AcpiGbl_AllGpesInitialized)
  97     {
  98         goto UnlockAndExit;
  99     }
 100 
 101     Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock, NULL);
 102     if (ACPI_SUCCESS (Status))
 103     {
 104         AcpiGbl_AllGpesInitialized = TRUE;
 105     }
 106 
 107 UnlockAndExit:


 234 
 235     ACPI_FUNCTION_TRACE (AcpiSetGpe);
 236 
 237 
 238     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
 239 
 240     /* Ensure that we have a valid GPE number */
 241 
 242     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
 243     if (!GpeEventInfo)
 244     {
 245         Status = AE_BAD_PARAMETER;
 246         goto UnlockAndExit;
 247     }
 248 
 249     /* Perform the action */
 250 
 251     switch (Action)
 252     {
 253     case ACPI_GPE_ENABLE:
 254 
 255         Status = AcpiEvEnableGpe (GpeEventInfo);
 256         break;
 257 
 258     case ACPI_GPE_DISABLE:
 259 
 260         Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
 261         break;
 262 
 263     default:
 264 
 265         Status = AE_BAD_PARAMETER;
 266         break;
 267     }
 268 
 269 UnlockAndExit:
 270     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
 271     return_ACPI_STATUS (Status);
 272 }
 273 
 274 ACPI_EXPORT_SYMBOL (AcpiSetGpe)
 275 
 276 
 277 /*******************************************************************************
 278  *
 279  * FUNCTION:    AcpiSetupGpeForWake
 280  *
 281  * PARAMETERS:  WakeDevice          - Device associated with the GPE (via _PRW)
 282  *              GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
 283  *              GpeNumber           - GPE level within the GPE block
 284  *
 285  * RETURN:      Status
 286  *
 287  * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
 288  *              interface is intended to be used as the host executes the
 289  *              _PRW methods (Power Resources for Wake) in the system tables.
 290  *              Each _PRW appears under a Device Object (The WakeDevice), and
 291  *              contains the info for the wake GPE associated with the
 292  *              WakeDevice.
 293  *
 294  ******************************************************************************/
 295 
 296 ACPI_STATUS
 297 AcpiSetupGpeForWake (
 298     ACPI_HANDLE             WakeDevice,
 299     ACPI_HANDLE             GpeDevice,
 300     UINT32                  GpeNumber)
 301 {
 302     ACPI_STATUS             Status;
 303     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
 304     ACPI_NAMESPACE_NODE     *DeviceNode;
 305     ACPI_GPE_NOTIFY_INFO    *Notify;
 306     ACPI_GPE_NOTIFY_INFO    *NewNotify;
 307     ACPI_CPU_FLAGS          Flags;
 308 
 309 
 310     ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
 311 
 312 
 313     /* Parameter Validation */
 314 
 315     if (!WakeDevice)
 316     {
 317         /*
 318          * By forcing WakeDevice to be valid, we automatically enable the
 319          * implicit notify feature on all hosts.
 320          */
 321         return_ACPI_STATUS (AE_BAD_PARAMETER);
 322     }
 323 
 324     /* Handle root object case */
 325 
 326     if (WakeDevice == ACPI_ROOT_OBJECT)
 327     {
 328         DeviceNode = AcpiGbl_RootNode;
 329     }
 330     else
 331     {
 332         DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
 333     }
 334 
 335     /* Validate WakeDevice is of type Device */
 336 
 337     if (DeviceNode->Type != ACPI_TYPE_DEVICE)
 338     {
 339         return_ACPI_STATUS (AE_BAD_PARAMETER);
 340     }
 341 
 342     /*
 343      * Allocate a new notify object up front, in case it is needed.
 344      * Memory allocation while holding a spinlock is a big no-no
 345      * on some hosts.
 346      */
 347     NewNotify = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_NOTIFY_INFO));
 348     if (!NewNotify)
 349     {
 350         return_ACPI_STATUS (AE_NO_MEMORY);
 351     }
 352 
 353     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
 354 
 355     /* Ensure that we have a valid GPE number */
 356 
 357     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
 358     if (!GpeEventInfo)
 359     {
 360         Status = AE_BAD_PARAMETER;
 361         goto UnlockAndExit;
 362     }
 363 
 364     /*
 365      * If there is no method or handler for this GPE, then the
 366      * WakeDevice will be notified whenever this GPE fires. This is
 367      * known as an "implicit notify". Note: The GPE is assumed to be
 368      * level-triggered (for windows compatibility).
 369      */
 370     if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
 371             ACPI_GPE_DISPATCH_NONE)
 372     {
 373         /*
 374          * This is the first device for implicit notify on this GPE.
 375          * Just set the flags here, and enter the NOTIFY block below.
 376          */
 377         GpeEventInfo->Flags =
 378             (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);

 379     }
 380 
 381     /*
 382      * If we already have an implicit notify on this GPE, add
 383      * this device to the notify list.
 384      */
 385     if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
 386             ACPI_GPE_DISPATCH_NOTIFY)
 387     {
 388         /* Ensure that the device is not already in the list */
 389 
 390         Notify = GpeEventInfo->Dispatch.NotifyList;
 391         while (Notify)
 392         {
 393             if (Notify->DeviceNode == DeviceNode)
 394             {
 395                 Status = AE_ALREADY_EXISTS;
 396                 goto UnlockAndExit;
 397             }
 398             Notify = Notify->Next;
 399         }
 400 
 401         /* Add this device to the notify list for this GPE */
 402 
 403         NewNotify->DeviceNode = DeviceNode;
 404         NewNotify->Next = GpeEventInfo->Dispatch.NotifyList;
 405         GpeEventInfo->Dispatch.NotifyList = NewNotify;
 406         NewNotify = NULL;
 407     }
 408 
 409     /* Mark the GPE as a possible wake event */
 410 
 411     GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
 412     Status = AE_OK;

 413 
 414 
 415 UnlockAndExit:
 416     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
 417 
 418     /* Delete the notify object if it was not used above */
 419 
 420     if (NewNotify)
 421     {
 422         ACPI_FREE (NewNotify);
 423     }
 424     return_ACPI_STATUS (Status);
 425 }
 426 
 427 ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
 428 
 429 
 430 /*******************************************************************************
 431  *
 432  * FUNCTION:    AcpiSetGpeWakeMask
 433  *
 434  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
 435  *              GpeNumber           - GPE level within the GPE block
 436  *              Action              - Enable or Disable
 437  *
 438  * RETURN:      Status
 439  *
 440  * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
 441  *              already be marked as a WAKE GPE.
 442  *
 443  ******************************************************************************/


 467     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
 468     if (!GpeEventInfo)
 469     {
 470         Status = AE_BAD_PARAMETER;
 471         goto UnlockAndExit;
 472     }
 473 
 474     if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
 475     {
 476         Status = AE_TYPE;
 477         goto UnlockAndExit;
 478     }
 479 
 480     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
 481     if (!GpeRegisterInfo)
 482     {
 483         Status = AE_NOT_EXIST;
 484         goto UnlockAndExit;
 485     }
 486 
 487     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
 488 
 489     /* Perform the action */
 490 
 491     switch (Action)
 492     {
 493     case ACPI_GPE_ENABLE:
 494 
 495         ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
 496         break;
 497 
 498     case ACPI_GPE_DISABLE:
 499 
 500         ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
 501         break;
 502 
 503     default:
 504 
 505         ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
 506         Status = AE_BAD_PARAMETER;
 507         break;
 508     }
 509 
 510 UnlockAndExit:
 511     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
 512     return_ACPI_STATUS (Status);
 513 }
 514 
 515 ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
 516 
 517 
 518 /*******************************************************************************
 519  *
 520  * FUNCTION:    AcpiClearGpe
 521  *
 522  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
 523  *              GpeNumber           - GPE level within the GPE block
 524  *


 764 {
 765     ACPI_STATUS             Status;
 766     ACPI_OPERAND_OBJECT     *ObjDesc;
 767     ACPI_NAMESPACE_NODE     *Node;
 768     ACPI_GPE_BLOCK_INFO     *GpeBlock;
 769 
 770 
 771     ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
 772 
 773 
 774     if ((!GpeDevice)       ||
 775         (!GpeBlockAddress) ||
 776         (!RegisterCount))
 777     {
 778         return_ACPI_STATUS (AE_BAD_PARAMETER);
 779     }
 780 
 781     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
 782     if (ACPI_FAILURE (Status))
 783     {
 784         return_ACPI_STATUS (Status);
 785     }
 786 
 787     Node = AcpiNsValidateHandle (GpeDevice);
 788     if (!Node)
 789     {
 790         Status = AE_BAD_PARAMETER;
 791         goto UnlockAndExit;
 792     }
 793 
 794     /* Validate the parent device */
 795 
 796     if (Node->Type != ACPI_TYPE_DEVICE)
 797     {
 798         Status = AE_TYPE;
 799         goto UnlockAndExit;
 800     }
 801 
 802     if (Node->Object)
 803     {
 804         Status = AE_ALREADY_EXISTS;
 805         goto UnlockAndExit;
 806     }
 807 
 808     /*
 809      * For user-installed GPE Block Devices, the GpeBlockBaseNumber
 810      * is always zero
 811      */
 812     Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
 813                 0, InterruptNumber, &GpeBlock);
 814     if (ACPI_FAILURE (Status))
 815     {
 816         goto UnlockAndExit;
 817     }
 818 
 819     /* Install block in the DeviceObject attached to the node */
 820 
 821     ObjDesc = AcpiNsGetAttachedObject (Node);
 822     if (!ObjDesc)
 823     {
 824         /*
 825          * No object, create a new one (Device nodes do not always have
 826          * an attached object)
 827          */


 871 ACPI_STATUS
 872 AcpiRemoveGpeBlock (
 873     ACPI_HANDLE             GpeDevice)
 874 {
 875     ACPI_OPERAND_OBJECT     *ObjDesc;
 876     ACPI_STATUS             Status;
 877     ACPI_NAMESPACE_NODE     *Node;
 878 
 879 
 880     ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
 881 
 882 
 883     if (!GpeDevice)
 884     {
 885         return_ACPI_STATUS (AE_BAD_PARAMETER);
 886     }
 887 
 888     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
 889     if (ACPI_FAILURE (Status))
 890     {
 891         return_ACPI_STATUS (Status);
 892     }
 893 
 894     Node = AcpiNsValidateHandle (GpeDevice);
 895     if (!Node)
 896     {
 897         Status = AE_BAD_PARAMETER;
 898         goto UnlockAndExit;
 899     }
 900 
 901     /* Validate the parent device */
 902 
 903     if (Node->Type != ACPI_TYPE_DEVICE)
 904     {
 905         Status = AE_TYPE;
 906         goto UnlockAndExit;
 907     }
 908 
 909     /* Get the DeviceObject attached to the node */
 910 
 911     ObjDesc = AcpiNsGetAttachedObject (Node);
 912     if (!ObjDesc ||
 913         !ObjDesc->Device.GpeBlock)
 914     {
 915         return_ACPI_STATUS (AE_NULL_OBJECT);
 916     }
 917 
 918     /* Delete the GPE block (but not the DeviceObject) */
 919 
 920     Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
 921     if (ACPI_SUCCESS (Status))
 922     {
 923         ObjDesc->Device.GpeBlock = NULL;
 924     }
 925 
 926 UnlockAndExit:
 927     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
 928     return_ACPI_STATUS (Status);


 969     }
 970 
 971     /* Setup and walk the GPE list */
 972 
 973     Info.Index = Index;
 974     Info.Status = AE_NOT_EXIST;
 975     Info.GpeDevice = NULL;
 976     Info.NextBlockBaseIndex = 0;
 977 
 978     Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
 979     if (ACPI_FAILURE (Status))
 980     {
 981         return_ACPI_STATUS (Status);
 982     }
 983 
 984     *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
 985     return_ACPI_STATUS (Info.Status);
 986 }
 987 
 988 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
 989 
 990 #endif /* !ACPI_REDUCED_HARDWARE */