Home | History | Annotate | Line # | Download | only in events
evgpeblk.c revision 1.1.1.2.4.2
      1  1.1.1.2.4.2  rmind /******************************************************************************
      2  1.1.1.2.4.2  rmind  *
      3  1.1.1.2.4.2  rmind  * Module Name: evgpeblk - GPE block creation and initialization.
      4  1.1.1.2.4.2  rmind  *
      5  1.1.1.2.4.2  rmind  *****************************************************************************/
      6  1.1.1.2.4.2  rmind 
      7  1.1.1.2.4.2  rmind /*
      8  1.1.1.2.4.2  rmind  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1.1.2.4.2  rmind  * All rights reserved.
     10  1.1.1.2.4.2  rmind  *
     11  1.1.1.2.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2.4.2  rmind  * modification, are permitted provided that the following conditions
     13  1.1.1.2.4.2  rmind  * are met:
     14  1.1.1.2.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2.4.2  rmind  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2.4.2  rmind  *    without modification.
     17  1.1.1.2.4.2  rmind  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2.4.2  rmind  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2.4.2  rmind  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2.4.2  rmind  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2.4.2  rmind  *    binary redistribution.
     22  1.1.1.2.4.2  rmind  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2.4.2  rmind  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2.4.2  rmind  *    from this software without specific prior written permission.
     25  1.1.1.2.4.2  rmind  *
     26  1.1.1.2.4.2  rmind  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2.4.2  rmind  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2.4.2  rmind  * Software Foundation.
     29  1.1.1.2.4.2  rmind  *
     30  1.1.1.2.4.2  rmind  * NO WARRANTY
     31  1.1.1.2.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2.4.2  rmind  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2.4.2  rmind  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2.4.2  rmind  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2.4.2  rmind  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2.4.2  rmind  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2.4.2  rmind  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2.4.2  rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2.4.2  rmind  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2.4.2  rmind  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2.4.2  rmind  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2.4.2  rmind  */
     43  1.1.1.2.4.2  rmind 
     44  1.1.1.2.4.2  rmind #include "acpi.h"
     45  1.1.1.2.4.2  rmind #include "accommon.h"
     46  1.1.1.2.4.2  rmind #include "acevents.h"
     47  1.1.1.2.4.2  rmind #include "acnamesp.h"
     48  1.1.1.2.4.2  rmind 
     49  1.1.1.2.4.2  rmind #define _COMPONENT          ACPI_EVENTS
     50  1.1.1.2.4.2  rmind         ACPI_MODULE_NAME    ("evgpeblk")
     51  1.1.1.2.4.2  rmind 
     52  1.1.1.2.4.2  rmind /* Local prototypes */
     53  1.1.1.2.4.2  rmind 
     54  1.1.1.2.4.2  rmind static ACPI_STATUS
     55  1.1.1.2.4.2  rmind AcpiEvInstallGpeBlock (
     56  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     *GpeBlock,
     57  1.1.1.2.4.2  rmind     UINT32                  InterruptNumber);
     58  1.1.1.2.4.2  rmind 
     59  1.1.1.2.4.2  rmind static ACPI_STATUS
     60  1.1.1.2.4.2  rmind AcpiEvCreateGpeInfoBlocks (
     61  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     *GpeBlock);
     62  1.1.1.2.4.2  rmind 
     63  1.1.1.2.4.2  rmind 
     64  1.1.1.2.4.2  rmind /*******************************************************************************
     65  1.1.1.2.4.2  rmind  *
     66  1.1.1.2.4.2  rmind  * FUNCTION:    AcpiEvInstallGpeBlock
     67  1.1.1.2.4.2  rmind  *
     68  1.1.1.2.4.2  rmind  * PARAMETERS:  GpeBlock                - New GPE block
     69  1.1.1.2.4.2  rmind  *              InterruptNumber         - Xrupt to be associated with this
     70  1.1.1.2.4.2  rmind  *                                        GPE block
     71  1.1.1.2.4.2  rmind  *
     72  1.1.1.2.4.2  rmind  * RETURN:      Status
     73  1.1.1.2.4.2  rmind  *
     74  1.1.1.2.4.2  rmind  * DESCRIPTION: Install new GPE block with mutex support
     75  1.1.1.2.4.2  rmind  *
     76  1.1.1.2.4.2  rmind  ******************************************************************************/
     77  1.1.1.2.4.2  rmind 
     78  1.1.1.2.4.2  rmind static ACPI_STATUS
     79  1.1.1.2.4.2  rmind AcpiEvInstallGpeBlock (
     80  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     *GpeBlock,
     81  1.1.1.2.4.2  rmind     UINT32                  InterruptNumber)
     82  1.1.1.2.4.2  rmind {
     83  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     *NextGpeBlock;
     84  1.1.1.2.4.2  rmind     ACPI_GPE_XRUPT_INFO     *GpeXruptBlock;
     85  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
     86  1.1.1.2.4.2  rmind     ACPI_CPU_FLAGS          Flags;
     87  1.1.1.2.4.2  rmind 
     88  1.1.1.2.4.2  rmind 
     89  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
     90  1.1.1.2.4.2  rmind 
     91  1.1.1.2.4.2  rmind 
     92  1.1.1.2.4.2  rmind     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
     93  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
     94  1.1.1.2.4.2  rmind     {
     95  1.1.1.2.4.2  rmind         return_ACPI_STATUS (Status);
     96  1.1.1.2.4.2  rmind     }
     97  1.1.1.2.4.2  rmind 
     98  1.1.1.2.4.2  rmind     GpeXruptBlock = AcpiEvGetGpeXruptBlock (InterruptNumber);
     99  1.1.1.2.4.2  rmind     if (!GpeXruptBlock)
    100  1.1.1.2.4.2  rmind     {
    101  1.1.1.2.4.2  rmind         Status = AE_NO_MEMORY;
    102  1.1.1.2.4.2  rmind         goto UnlockAndExit;
    103  1.1.1.2.4.2  rmind     }
    104  1.1.1.2.4.2  rmind 
    105  1.1.1.2.4.2  rmind     /* Install the new block at the end of the list with lock */
    106  1.1.1.2.4.2  rmind 
    107  1.1.1.2.4.2  rmind     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
    108  1.1.1.2.4.2  rmind     if (GpeXruptBlock->GpeBlockListHead)
    109  1.1.1.2.4.2  rmind     {
    110  1.1.1.2.4.2  rmind         NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
    111  1.1.1.2.4.2  rmind         while (NextGpeBlock->Next)
    112  1.1.1.2.4.2  rmind         {
    113  1.1.1.2.4.2  rmind             NextGpeBlock = NextGpeBlock->Next;
    114  1.1.1.2.4.2  rmind         }
    115  1.1.1.2.4.2  rmind 
    116  1.1.1.2.4.2  rmind         NextGpeBlock->Next = GpeBlock;
    117  1.1.1.2.4.2  rmind         GpeBlock->Previous = NextGpeBlock;
    118  1.1.1.2.4.2  rmind     }
    119  1.1.1.2.4.2  rmind     else
    120  1.1.1.2.4.2  rmind     {
    121  1.1.1.2.4.2  rmind         GpeXruptBlock->GpeBlockListHead = GpeBlock;
    122  1.1.1.2.4.2  rmind     }
    123  1.1.1.2.4.2  rmind 
    124  1.1.1.2.4.2  rmind     GpeBlock->XruptBlock = GpeXruptBlock;
    125  1.1.1.2.4.2  rmind     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    126  1.1.1.2.4.2  rmind 
    127  1.1.1.2.4.2  rmind 
    128  1.1.1.2.4.2  rmind UnlockAndExit:
    129  1.1.1.2.4.2  rmind     Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    130  1.1.1.2.4.2  rmind     return_ACPI_STATUS (Status);
    131  1.1.1.2.4.2  rmind }
    132  1.1.1.2.4.2  rmind 
    133  1.1.1.2.4.2  rmind 
    134  1.1.1.2.4.2  rmind /*******************************************************************************
    135  1.1.1.2.4.2  rmind  *
    136  1.1.1.2.4.2  rmind  * FUNCTION:    AcpiEvDeleteGpeBlock
    137  1.1.1.2.4.2  rmind  *
    138  1.1.1.2.4.2  rmind  * PARAMETERS:  GpeBlock            - Existing GPE block
    139  1.1.1.2.4.2  rmind  *
    140  1.1.1.2.4.2  rmind  * RETURN:      Status
    141  1.1.1.2.4.2  rmind  *
    142  1.1.1.2.4.2  rmind  * DESCRIPTION: Remove a GPE block
    143  1.1.1.2.4.2  rmind  *
    144  1.1.1.2.4.2  rmind  ******************************************************************************/
    145  1.1.1.2.4.2  rmind 
    146  1.1.1.2.4.2  rmind ACPI_STATUS
    147  1.1.1.2.4.2  rmind AcpiEvDeleteGpeBlock (
    148  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     *GpeBlock)
    149  1.1.1.2.4.2  rmind {
    150  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    151  1.1.1.2.4.2  rmind     ACPI_CPU_FLAGS          Flags;
    152  1.1.1.2.4.2  rmind 
    153  1.1.1.2.4.2  rmind 
    154  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
    155  1.1.1.2.4.2  rmind 
    156  1.1.1.2.4.2  rmind 
    157  1.1.1.2.4.2  rmind     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
    158  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    159  1.1.1.2.4.2  rmind     {
    160  1.1.1.2.4.2  rmind         return_ACPI_STATUS (Status);
    161  1.1.1.2.4.2  rmind     }
    162  1.1.1.2.4.2  rmind 
    163  1.1.1.2.4.2  rmind     /* Disable all GPEs in this block */
    164  1.1.1.2.4.2  rmind 
    165  1.1.1.2.4.2  rmind     Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock, NULL);
    166  1.1.1.2.4.2  rmind 
    167  1.1.1.2.4.2  rmind     if (!GpeBlock->Previous && !GpeBlock->Next)
    168  1.1.1.2.4.2  rmind     {
    169  1.1.1.2.4.2  rmind         /* This is the last GpeBlock on this interrupt */
    170  1.1.1.2.4.2  rmind 
    171  1.1.1.2.4.2  rmind         Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
    172  1.1.1.2.4.2  rmind         if (ACPI_FAILURE (Status))
    173  1.1.1.2.4.2  rmind         {
    174  1.1.1.2.4.2  rmind             goto UnlockAndExit;
    175  1.1.1.2.4.2  rmind         }
    176  1.1.1.2.4.2  rmind     }
    177  1.1.1.2.4.2  rmind     else
    178  1.1.1.2.4.2  rmind     {
    179  1.1.1.2.4.2  rmind         /* Remove the block on this interrupt with lock */
    180  1.1.1.2.4.2  rmind 
    181  1.1.1.2.4.2  rmind         Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
    182  1.1.1.2.4.2  rmind         if (GpeBlock->Previous)
    183  1.1.1.2.4.2  rmind         {
    184  1.1.1.2.4.2  rmind             GpeBlock->Previous->Next = GpeBlock->Next;
    185  1.1.1.2.4.2  rmind         }
    186  1.1.1.2.4.2  rmind         else
    187  1.1.1.2.4.2  rmind         {
    188  1.1.1.2.4.2  rmind             GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
    189  1.1.1.2.4.2  rmind         }
    190  1.1.1.2.4.2  rmind 
    191  1.1.1.2.4.2  rmind         if (GpeBlock->Next)
    192  1.1.1.2.4.2  rmind         {
    193  1.1.1.2.4.2  rmind             GpeBlock->Next->Previous = GpeBlock->Previous;
    194  1.1.1.2.4.2  rmind         }
    195  1.1.1.2.4.2  rmind         AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
    196  1.1.1.2.4.2  rmind     }
    197  1.1.1.2.4.2  rmind 
    198  1.1.1.2.4.2  rmind     AcpiCurrentGpeCount -= GpeBlock->GpeCount;
    199  1.1.1.2.4.2  rmind 
    200  1.1.1.2.4.2  rmind     /* Free the GpeBlock */
    201  1.1.1.2.4.2  rmind 
    202  1.1.1.2.4.2  rmind     ACPI_FREE (GpeBlock->RegisterInfo);
    203  1.1.1.2.4.2  rmind     ACPI_FREE (GpeBlock->EventInfo);
    204  1.1.1.2.4.2  rmind     ACPI_FREE (GpeBlock);
    205  1.1.1.2.4.2  rmind 
    206  1.1.1.2.4.2  rmind UnlockAndExit:
    207  1.1.1.2.4.2  rmind     Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
    208  1.1.1.2.4.2  rmind     return_ACPI_STATUS (Status);
    209  1.1.1.2.4.2  rmind }
    210  1.1.1.2.4.2  rmind 
    211  1.1.1.2.4.2  rmind 
    212  1.1.1.2.4.2  rmind /*******************************************************************************
    213  1.1.1.2.4.2  rmind  *
    214  1.1.1.2.4.2  rmind  * FUNCTION:    AcpiEvCreateGpeInfoBlocks
    215  1.1.1.2.4.2  rmind  *
    216  1.1.1.2.4.2  rmind  * PARAMETERS:  GpeBlock    - New GPE block
    217  1.1.1.2.4.2  rmind  *
    218  1.1.1.2.4.2  rmind  * RETURN:      Status
    219  1.1.1.2.4.2  rmind  *
    220  1.1.1.2.4.2  rmind  * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
    221  1.1.1.2.4.2  rmind  *
    222  1.1.1.2.4.2  rmind  ******************************************************************************/
    223  1.1.1.2.4.2  rmind 
    224  1.1.1.2.4.2  rmind static ACPI_STATUS
    225  1.1.1.2.4.2  rmind AcpiEvCreateGpeInfoBlocks (
    226  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     *GpeBlock)
    227  1.1.1.2.4.2  rmind {
    228  1.1.1.2.4.2  rmind     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo = NULL;
    229  1.1.1.2.4.2  rmind     ACPI_GPE_EVENT_INFO     *GpeEventInfo = NULL;
    230  1.1.1.2.4.2  rmind     ACPI_GPE_EVENT_INFO     *ThisEvent;
    231  1.1.1.2.4.2  rmind     ACPI_GPE_REGISTER_INFO  *ThisRegister;
    232  1.1.1.2.4.2  rmind     UINT32                  i;
    233  1.1.1.2.4.2  rmind     UINT32                  j;
    234  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    235  1.1.1.2.4.2  rmind 
    236  1.1.1.2.4.2  rmind 
    237  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks);
    238  1.1.1.2.4.2  rmind 
    239  1.1.1.2.4.2  rmind 
    240  1.1.1.2.4.2  rmind     /* Allocate the GPE register information block */
    241  1.1.1.2.4.2  rmind 
    242  1.1.1.2.4.2  rmind     GpeRegisterInfo = ACPI_ALLOCATE_ZEROED (
    243  1.1.1.2.4.2  rmind                         (ACPI_SIZE) GpeBlock->RegisterCount *
    244  1.1.1.2.4.2  rmind                         sizeof (ACPI_GPE_REGISTER_INFO));
    245  1.1.1.2.4.2  rmind     if (!GpeRegisterInfo)
    246  1.1.1.2.4.2  rmind     {
    247  1.1.1.2.4.2  rmind         ACPI_ERROR ((AE_INFO,
    248  1.1.1.2.4.2  rmind             "Could not allocate the GpeRegisterInfo table"));
    249  1.1.1.2.4.2  rmind         return_ACPI_STATUS (AE_NO_MEMORY);
    250  1.1.1.2.4.2  rmind     }
    251  1.1.1.2.4.2  rmind 
    252  1.1.1.2.4.2  rmind     /*
    253  1.1.1.2.4.2  rmind      * Allocate the GPE EventInfo block. There are eight distinct GPEs
    254  1.1.1.2.4.2  rmind      * per register. Initialization to zeros is sufficient.
    255  1.1.1.2.4.2  rmind      */
    256  1.1.1.2.4.2  rmind     GpeEventInfo = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) GpeBlock->GpeCount *
    257  1.1.1.2.4.2  rmind                     sizeof (ACPI_GPE_EVENT_INFO));
    258  1.1.1.2.4.2  rmind     if (!GpeEventInfo)
    259  1.1.1.2.4.2  rmind     {
    260  1.1.1.2.4.2  rmind         ACPI_ERROR ((AE_INFO,
    261  1.1.1.2.4.2  rmind             "Could not allocate the GpeEventInfo table"));
    262  1.1.1.2.4.2  rmind         Status = AE_NO_MEMORY;
    263  1.1.1.2.4.2  rmind         goto ErrorExit;
    264  1.1.1.2.4.2  rmind     }
    265  1.1.1.2.4.2  rmind 
    266  1.1.1.2.4.2  rmind     /* Save the new Info arrays in the GPE block */
    267  1.1.1.2.4.2  rmind 
    268  1.1.1.2.4.2  rmind     GpeBlock->RegisterInfo = GpeRegisterInfo;
    269  1.1.1.2.4.2  rmind     GpeBlock->EventInfo    = GpeEventInfo;
    270  1.1.1.2.4.2  rmind 
    271  1.1.1.2.4.2  rmind     /*
    272  1.1.1.2.4.2  rmind      * Initialize the GPE Register and Event structures. A goal of these
    273  1.1.1.2.4.2  rmind      * tables is to hide the fact that there are two separate GPE register
    274  1.1.1.2.4.2  rmind      * sets in a given GPE hardware block, the status registers occupy the
    275  1.1.1.2.4.2  rmind      * first half, and the enable registers occupy the second half.
    276  1.1.1.2.4.2  rmind      */
    277  1.1.1.2.4.2  rmind     ThisRegister = GpeRegisterInfo;
    278  1.1.1.2.4.2  rmind     ThisEvent    = GpeEventInfo;
    279  1.1.1.2.4.2  rmind 
    280  1.1.1.2.4.2  rmind     for (i = 0; i < GpeBlock->RegisterCount; i++)
    281  1.1.1.2.4.2  rmind     {
    282  1.1.1.2.4.2  rmind         /* Init the RegisterInfo for this GPE register (8 GPEs) */
    283  1.1.1.2.4.2  rmind 
    284  1.1.1.2.4.2  rmind         ThisRegister->BaseGpeNumber = (UINT8) (GpeBlock->BlockBaseNumber +
    285  1.1.1.2.4.2  rmind                                              (i * ACPI_GPE_REGISTER_WIDTH));
    286  1.1.1.2.4.2  rmind 
    287  1.1.1.2.4.2  rmind         ThisRegister->StatusAddress.Address =
    288  1.1.1.2.4.2  rmind             GpeBlock->BlockAddress.Address + i;
    289  1.1.1.2.4.2  rmind 
    290  1.1.1.2.4.2  rmind         ThisRegister->EnableAddress.Address =
    291  1.1.1.2.4.2  rmind             GpeBlock->BlockAddress.Address + i + GpeBlock->RegisterCount;
    292  1.1.1.2.4.2  rmind 
    293  1.1.1.2.4.2  rmind         ThisRegister->StatusAddress.SpaceId   = GpeBlock->BlockAddress.SpaceId;
    294  1.1.1.2.4.2  rmind         ThisRegister->EnableAddress.SpaceId   = GpeBlock->BlockAddress.SpaceId;
    295  1.1.1.2.4.2  rmind         ThisRegister->StatusAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
    296  1.1.1.2.4.2  rmind         ThisRegister->EnableAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
    297  1.1.1.2.4.2  rmind         ThisRegister->StatusAddress.BitOffset = 0;
    298  1.1.1.2.4.2  rmind         ThisRegister->EnableAddress.BitOffset = 0;
    299  1.1.1.2.4.2  rmind 
    300  1.1.1.2.4.2  rmind         /* Init the EventInfo for each GPE within this register */
    301  1.1.1.2.4.2  rmind 
    302  1.1.1.2.4.2  rmind         for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
    303  1.1.1.2.4.2  rmind         {
    304  1.1.1.2.4.2  rmind             ThisEvent->GpeNumber = (UINT8) (ThisRegister->BaseGpeNumber + j);
    305  1.1.1.2.4.2  rmind             ThisEvent->RegisterInfo = ThisRegister;
    306  1.1.1.2.4.2  rmind             ThisEvent++;
    307  1.1.1.2.4.2  rmind         }
    308  1.1.1.2.4.2  rmind 
    309  1.1.1.2.4.2  rmind         /* Disable all GPEs within this register */
    310  1.1.1.2.4.2  rmind 
    311  1.1.1.2.4.2  rmind         Status = AcpiHwWrite (0x00, &ThisRegister->EnableAddress);
    312  1.1.1.2.4.2  rmind         if (ACPI_FAILURE (Status))
    313  1.1.1.2.4.2  rmind         {
    314  1.1.1.2.4.2  rmind             goto ErrorExit;
    315  1.1.1.2.4.2  rmind         }
    316  1.1.1.2.4.2  rmind 
    317  1.1.1.2.4.2  rmind         /* Clear any pending GPE events within this register */
    318  1.1.1.2.4.2  rmind 
    319  1.1.1.2.4.2  rmind         Status = AcpiHwWrite (0xFF, &ThisRegister->StatusAddress);
    320  1.1.1.2.4.2  rmind         if (ACPI_FAILURE (Status))
    321  1.1.1.2.4.2  rmind         {
    322  1.1.1.2.4.2  rmind             goto ErrorExit;
    323  1.1.1.2.4.2  rmind         }
    324  1.1.1.2.4.2  rmind 
    325  1.1.1.2.4.2  rmind         ThisRegister++;
    326  1.1.1.2.4.2  rmind     }
    327  1.1.1.2.4.2  rmind 
    328  1.1.1.2.4.2  rmind     return_ACPI_STATUS (AE_OK);
    329  1.1.1.2.4.2  rmind 
    330  1.1.1.2.4.2  rmind 
    331  1.1.1.2.4.2  rmind ErrorExit:
    332  1.1.1.2.4.2  rmind     if (GpeRegisterInfo)
    333  1.1.1.2.4.2  rmind     {
    334  1.1.1.2.4.2  rmind         ACPI_FREE (GpeRegisterInfo);
    335  1.1.1.2.4.2  rmind     }
    336  1.1.1.2.4.2  rmind     if (GpeEventInfo)
    337  1.1.1.2.4.2  rmind     {
    338  1.1.1.2.4.2  rmind         ACPI_FREE (GpeEventInfo);
    339  1.1.1.2.4.2  rmind     }
    340  1.1.1.2.4.2  rmind 
    341  1.1.1.2.4.2  rmind     return_ACPI_STATUS (Status);
    342  1.1.1.2.4.2  rmind }
    343  1.1.1.2.4.2  rmind 
    344  1.1.1.2.4.2  rmind 
    345  1.1.1.2.4.2  rmind /*******************************************************************************
    346  1.1.1.2.4.2  rmind  *
    347  1.1.1.2.4.2  rmind  * FUNCTION:    AcpiEvCreateGpeBlock
    348  1.1.1.2.4.2  rmind  *
    349  1.1.1.2.4.2  rmind  * PARAMETERS:  GpeDevice           - Handle to the parent GPE block
    350  1.1.1.2.4.2  rmind  *              GpeBlockAddress     - Address and SpaceID
    351  1.1.1.2.4.2  rmind  *              RegisterCount       - Number of GPE register pairs in the block
    352  1.1.1.2.4.2  rmind  *              GpeBlockBaseNumber  - Starting GPE number for the block
    353  1.1.1.2.4.2  rmind  *              InterruptNumber     - H/W interrupt for the block
    354  1.1.1.2.4.2  rmind  *              ReturnGpeBlock      - Where the new block descriptor is returned
    355  1.1.1.2.4.2  rmind  *
    356  1.1.1.2.4.2  rmind  * RETURN:      Status
    357  1.1.1.2.4.2  rmind  *
    358  1.1.1.2.4.2  rmind  * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
    359  1.1.1.2.4.2  rmind  *              the block are disabled at exit.
    360  1.1.1.2.4.2  rmind  *              Note: Assumes namespace is locked.
    361  1.1.1.2.4.2  rmind  *
    362  1.1.1.2.4.2  rmind  ******************************************************************************/
    363  1.1.1.2.4.2  rmind 
    364  1.1.1.2.4.2  rmind ACPI_STATUS
    365  1.1.1.2.4.2  rmind AcpiEvCreateGpeBlock (
    366  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *GpeDevice,
    367  1.1.1.2.4.2  rmind     ACPI_GENERIC_ADDRESS    *GpeBlockAddress,
    368  1.1.1.2.4.2  rmind     UINT32                  RegisterCount,
    369  1.1.1.2.4.2  rmind     UINT8                   GpeBlockBaseNumber,
    370  1.1.1.2.4.2  rmind     UINT32                  InterruptNumber,
    371  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     **ReturnGpeBlock)
    372  1.1.1.2.4.2  rmind {
    373  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    374  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     *GpeBlock;
    375  1.1.1.2.4.2  rmind     ACPI_GPE_WALK_INFO      WalkInfo;
    376  1.1.1.2.4.2  rmind 
    377  1.1.1.2.4.2  rmind 
    378  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (EvCreateGpeBlock);
    379  1.1.1.2.4.2  rmind 
    380  1.1.1.2.4.2  rmind 
    381  1.1.1.2.4.2  rmind     if (!RegisterCount)
    382  1.1.1.2.4.2  rmind     {
    383  1.1.1.2.4.2  rmind         return_ACPI_STATUS (AE_OK);
    384  1.1.1.2.4.2  rmind     }
    385  1.1.1.2.4.2  rmind 
    386  1.1.1.2.4.2  rmind     /* Allocate a new GPE block */
    387  1.1.1.2.4.2  rmind 
    388  1.1.1.2.4.2  rmind     GpeBlock = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO));
    389  1.1.1.2.4.2  rmind     if (!GpeBlock)
    390  1.1.1.2.4.2  rmind     {
    391  1.1.1.2.4.2  rmind         return_ACPI_STATUS (AE_NO_MEMORY);
    392  1.1.1.2.4.2  rmind     }
    393  1.1.1.2.4.2  rmind 
    394  1.1.1.2.4.2  rmind     /* Initialize the new GPE block */
    395  1.1.1.2.4.2  rmind 
    396  1.1.1.2.4.2  rmind     GpeBlock->Node = GpeDevice;
    397  1.1.1.2.4.2  rmind     GpeBlock->GpeCount = (UINT16) (RegisterCount * ACPI_GPE_REGISTER_WIDTH);
    398  1.1.1.2.4.2  rmind     GpeBlock->Initialized = FALSE;
    399  1.1.1.2.4.2  rmind     GpeBlock->RegisterCount = RegisterCount;
    400  1.1.1.2.4.2  rmind     GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
    401  1.1.1.2.4.2  rmind 
    402  1.1.1.2.4.2  rmind     ACPI_MEMCPY (&GpeBlock->BlockAddress, GpeBlockAddress,
    403  1.1.1.2.4.2  rmind         sizeof (ACPI_GENERIC_ADDRESS));
    404  1.1.1.2.4.2  rmind 
    405  1.1.1.2.4.2  rmind     /*
    406  1.1.1.2.4.2  rmind      * Create the RegisterInfo and EventInfo sub-structures
    407  1.1.1.2.4.2  rmind      * Note: disables and clears all GPEs in the block
    408  1.1.1.2.4.2  rmind      */
    409  1.1.1.2.4.2  rmind     Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
    410  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    411  1.1.1.2.4.2  rmind     {
    412  1.1.1.2.4.2  rmind         ACPI_FREE (GpeBlock);
    413  1.1.1.2.4.2  rmind         return_ACPI_STATUS (Status);
    414  1.1.1.2.4.2  rmind     }
    415  1.1.1.2.4.2  rmind 
    416  1.1.1.2.4.2  rmind     /* Install the new block in the global lists */
    417  1.1.1.2.4.2  rmind 
    418  1.1.1.2.4.2  rmind     Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
    419  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    420  1.1.1.2.4.2  rmind     {
    421  1.1.1.2.4.2  rmind         ACPI_FREE (GpeBlock);
    422  1.1.1.2.4.2  rmind         return_ACPI_STATUS (Status);
    423  1.1.1.2.4.2  rmind     }
    424  1.1.1.2.4.2  rmind 
    425  1.1.1.2.4.2  rmind     AcpiGbl_AllGpesInitialized = FALSE;
    426  1.1.1.2.4.2  rmind 
    427  1.1.1.2.4.2  rmind     /* Find all GPE methods (_Lxx or_Exx) for this block */
    428  1.1.1.2.4.2  rmind 
    429  1.1.1.2.4.2  rmind     WalkInfo.GpeBlock = GpeBlock;
    430  1.1.1.2.4.2  rmind     WalkInfo.GpeDevice = GpeDevice;
    431  1.1.1.2.4.2  rmind     WalkInfo.ExecuteByOwnerId = FALSE;
    432  1.1.1.2.4.2  rmind 
    433  1.1.1.2.4.2  rmind     Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
    434  1.1.1.2.4.2  rmind                 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
    435  1.1.1.2.4.2  rmind                 AcpiEvMatchGpeMethod, NULL, &WalkInfo, NULL);
    436  1.1.1.2.4.2  rmind 
    437  1.1.1.2.4.2  rmind     /* Return the new block */
    438  1.1.1.2.4.2  rmind 
    439  1.1.1.2.4.2  rmind     if (ReturnGpeBlock)
    440  1.1.1.2.4.2  rmind     {
    441  1.1.1.2.4.2  rmind         (*ReturnGpeBlock) = GpeBlock;
    442  1.1.1.2.4.2  rmind     }
    443  1.1.1.2.4.2  rmind 
    444  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
    445  1.1.1.2.4.2  rmind         "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
    446  1.1.1.2.4.2  rmind         (UINT32) GpeBlock->BlockBaseNumber,
    447  1.1.1.2.4.2  rmind         (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1)),
    448  1.1.1.2.4.2  rmind         GpeDevice->Name.Ascii, GpeBlock->RegisterCount,
    449  1.1.1.2.4.2  rmind         InterruptNumber));
    450  1.1.1.2.4.2  rmind 
    451  1.1.1.2.4.2  rmind     /* Update global count of currently available GPEs */
    452  1.1.1.2.4.2  rmind 
    453  1.1.1.2.4.2  rmind     AcpiCurrentGpeCount += GpeBlock->GpeCount;
    454  1.1.1.2.4.2  rmind     return_ACPI_STATUS (AE_OK);
    455  1.1.1.2.4.2  rmind }
    456  1.1.1.2.4.2  rmind 
    457  1.1.1.2.4.2  rmind 
    458  1.1.1.2.4.2  rmind /*******************************************************************************
    459  1.1.1.2.4.2  rmind  *
    460  1.1.1.2.4.2  rmind  * FUNCTION:    AcpiEvInitializeGpeBlock
    461  1.1.1.2.4.2  rmind  *
    462  1.1.1.2.4.2  rmind  * PARAMETERS:  ACPI_GPE_CALLBACK
    463  1.1.1.2.4.2  rmind  *
    464  1.1.1.2.4.2  rmind  * RETURN:      Status
    465  1.1.1.2.4.2  rmind  *
    466  1.1.1.2.4.2  rmind  * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
    467  1.1.1.2.4.2  rmind  *              associated methods.
    468  1.1.1.2.4.2  rmind  *              Note: Assumes namespace is locked.
    469  1.1.1.2.4.2  rmind  *
    470  1.1.1.2.4.2  rmind  ******************************************************************************/
    471  1.1.1.2.4.2  rmind 
    472  1.1.1.2.4.2  rmind ACPI_STATUS
    473  1.1.1.2.4.2  rmind AcpiEvInitializeGpeBlock (
    474  1.1.1.2.4.2  rmind     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
    475  1.1.1.2.4.2  rmind     ACPI_GPE_BLOCK_INFO     *GpeBlock,
    476  1.1.1.2.4.2  rmind     void                    *Ignored)
    477  1.1.1.2.4.2  rmind {
    478  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    479  1.1.1.2.4.2  rmind     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
    480  1.1.1.2.4.2  rmind     UINT32                  GpeEnabledCount;
    481  1.1.1.2.4.2  rmind     UINT32                  GpeIndex;
    482  1.1.1.2.4.2  rmind     UINT32                  i;
    483  1.1.1.2.4.2  rmind     UINT32                  j;
    484  1.1.1.2.4.2  rmind 
    485  1.1.1.2.4.2  rmind 
    486  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (EvInitializeGpeBlock);
    487  1.1.1.2.4.2  rmind 
    488  1.1.1.2.4.2  rmind 
    489  1.1.1.2.4.2  rmind     /*
    490  1.1.1.2.4.2  rmind      * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
    491  1.1.1.2.4.2  rmind      * any GPE blocks that have been initialized already.
    492  1.1.1.2.4.2  rmind      */
    493  1.1.1.2.4.2  rmind     if (!GpeBlock || GpeBlock->Initialized)
    494  1.1.1.2.4.2  rmind     {
    495  1.1.1.2.4.2  rmind         return_ACPI_STATUS (AE_OK);
    496  1.1.1.2.4.2  rmind     }
    497  1.1.1.2.4.2  rmind 
    498  1.1.1.2.4.2  rmind     /*
    499  1.1.1.2.4.2  rmind      * Enable all GPEs that have a corresponding method and have the
    500  1.1.1.2.4.2  rmind      * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
    501  1.1.1.2.4.2  rmind      * must be enabled via the acpi_enable_gpe() interface.
    502  1.1.1.2.4.2  rmind      */
    503  1.1.1.2.4.2  rmind     GpeEnabledCount = 0;
    504  1.1.1.2.4.2  rmind 
    505  1.1.1.2.4.2  rmind     for (i = 0; i < GpeBlock->RegisterCount; i++)
    506  1.1.1.2.4.2  rmind     {
    507  1.1.1.2.4.2  rmind         for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
    508  1.1.1.2.4.2  rmind         {
    509  1.1.1.2.4.2  rmind             /* Get the info block for this particular GPE */
    510  1.1.1.2.4.2  rmind 
    511  1.1.1.2.4.2  rmind             GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
    512  1.1.1.2.4.2  rmind             GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
    513  1.1.1.2.4.2  rmind 
    514  1.1.1.2.4.2  rmind             /*
    515  1.1.1.2.4.2  rmind              * Ignore GPEs that have no corresponding _Lxx/_Exx method
    516  1.1.1.2.4.2  rmind              * and GPEs that are used to wake the system
    517  1.1.1.2.4.2  rmind              */
    518  1.1.1.2.4.2  rmind             if (((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_NONE) ||
    519  1.1.1.2.4.2  rmind                 ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER) ||
    520  1.1.1.2.4.2  rmind                 (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
    521  1.1.1.2.4.2  rmind             {
    522  1.1.1.2.4.2  rmind                 continue;
    523  1.1.1.2.4.2  rmind             }
    524  1.1.1.2.4.2  rmind 
    525  1.1.1.2.4.2  rmind             Status = AcpiEvAddGpeReference (GpeEventInfo);
    526  1.1.1.2.4.2  rmind             if (ACPI_FAILURE (Status))
    527  1.1.1.2.4.2  rmind             {
    528  1.1.1.2.4.2  rmind                 ACPI_EXCEPTION ((AE_INFO, Status,
    529  1.1.1.2.4.2  rmind                     "Could not enable GPE 0x%02X",
    530  1.1.1.2.4.2  rmind                     GpeIndex + GpeBlock->BlockBaseNumber));
    531  1.1.1.2.4.2  rmind                 continue;
    532  1.1.1.2.4.2  rmind             }
    533  1.1.1.2.4.2  rmind 
    534  1.1.1.2.4.2  rmind             GpeEnabledCount++;
    535  1.1.1.2.4.2  rmind         }
    536  1.1.1.2.4.2  rmind     }
    537  1.1.1.2.4.2  rmind 
    538  1.1.1.2.4.2  rmind     if (GpeEnabledCount)
    539  1.1.1.2.4.2  rmind     {
    540  1.1.1.2.4.2  rmind         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
    541  1.1.1.2.4.2  rmind             "Enabled %u GPEs in this block\n", GpeEnabledCount));
    542  1.1.1.2.4.2  rmind     }
    543  1.1.1.2.4.2  rmind 
    544  1.1.1.2.4.2  rmind     GpeBlock->Initialized = TRUE;
    545  1.1.1.2.4.2  rmind     return_ACPI_STATUS (AE_OK);
    546  1.1.1.2.4.2  rmind }
    547  1.1.1.2.4.2  rmind 
    548