Home | History | Annotate | Line # | Download | only in events
evhandler.c revision 1.1.1.1.10.3
      1  1.1.1.1.10.2       tls /******************************************************************************
      2  1.1.1.1.10.2       tls  *
      3  1.1.1.1.10.2       tls  * Module Name: evhandler - Support for Address Space handlers
      4  1.1.1.1.10.2       tls  *
      5  1.1.1.1.10.2       tls  *****************************************************************************/
      6  1.1.1.1.10.2       tls 
      7  1.1.1.1.10.2       tls /*
      8  1.1.1.1.10.3  jdolecek  * Copyright (C) 2000 - 2017, Intel Corp.
      9  1.1.1.1.10.2       tls  * All rights reserved.
     10  1.1.1.1.10.2       tls  *
     11  1.1.1.1.10.2       tls  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.1.10.2       tls  * modification, are permitted provided that the following conditions
     13  1.1.1.1.10.2       tls  * are met:
     14  1.1.1.1.10.2       tls  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.1.10.2       tls  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.1.10.2       tls  *    without modification.
     17  1.1.1.1.10.2       tls  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.1.10.2       tls  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.1.10.2       tls  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.1.10.2       tls  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.1.10.2       tls  *    binary redistribution.
     22  1.1.1.1.10.2       tls  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.1.10.2       tls  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.1.10.2       tls  *    from this software without specific prior written permission.
     25  1.1.1.1.10.2       tls  *
     26  1.1.1.1.10.2       tls  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.1.10.2       tls  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.1.10.2       tls  * Software Foundation.
     29  1.1.1.1.10.2       tls  *
     30  1.1.1.1.10.2       tls  * NO WARRANTY
     31  1.1.1.1.10.2       tls  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.1.10.2       tls  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.1.10.2       tls  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.1.10.2       tls  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.1.10.2       tls  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.1.10.2       tls  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.1.10.2       tls  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.1.10.2       tls  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.1.10.2       tls  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.1.10.2       tls  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.1.10.2       tls  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.1.10.2       tls  */
     43  1.1.1.1.10.2       tls 
     44  1.1.1.1.10.2       tls #include "acpi.h"
     45  1.1.1.1.10.2       tls #include "accommon.h"
     46  1.1.1.1.10.2       tls #include "acevents.h"
     47  1.1.1.1.10.2       tls #include "acnamesp.h"
     48  1.1.1.1.10.2       tls #include "acinterp.h"
     49  1.1.1.1.10.2       tls 
     50  1.1.1.1.10.2       tls #define _COMPONENT          ACPI_EVENTS
     51  1.1.1.1.10.2       tls         ACPI_MODULE_NAME    ("evhandler")
     52  1.1.1.1.10.2       tls 
     53  1.1.1.1.10.2       tls 
     54  1.1.1.1.10.2       tls /* Local prototypes */
     55  1.1.1.1.10.2       tls 
     56  1.1.1.1.10.2       tls static ACPI_STATUS
     57  1.1.1.1.10.2       tls AcpiEvInstallHandler (
     58  1.1.1.1.10.2       tls     ACPI_HANDLE             ObjHandle,
     59  1.1.1.1.10.2       tls     UINT32                  Level,
     60  1.1.1.1.10.2       tls     void                    *Context,
     61  1.1.1.1.10.2       tls     void                    **ReturnValue);
     62  1.1.1.1.10.2       tls 
     63  1.1.1.1.10.3  jdolecek 
     64  1.1.1.1.10.2       tls /* These are the address spaces that will get default handlers */
     65  1.1.1.1.10.2       tls 
     66  1.1.1.1.10.2       tls UINT8        AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
     67  1.1.1.1.10.2       tls {
     68  1.1.1.1.10.2       tls     ACPI_ADR_SPACE_SYSTEM_MEMORY,
     69  1.1.1.1.10.2       tls     ACPI_ADR_SPACE_SYSTEM_IO,
     70  1.1.1.1.10.2       tls     ACPI_ADR_SPACE_PCI_CONFIG,
     71  1.1.1.1.10.2       tls     ACPI_ADR_SPACE_DATA_TABLE
     72  1.1.1.1.10.2       tls };
     73  1.1.1.1.10.2       tls 
     74  1.1.1.1.10.2       tls 
     75  1.1.1.1.10.2       tls /*******************************************************************************
     76  1.1.1.1.10.2       tls  *
     77  1.1.1.1.10.2       tls  * FUNCTION:    AcpiEvInstallRegionHandlers
     78  1.1.1.1.10.2       tls  *
     79  1.1.1.1.10.2       tls  * PARAMETERS:  None
     80  1.1.1.1.10.2       tls  *
     81  1.1.1.1.10.2       tls  * RETURN:      Status
     82  1.1.1.1.10.2       tls  *
     83  1.1.1.1.10.2       tls  * DESCRIPTION: Installs the core subsystem default address space handlers.
     84  1.1.1.1.10.2       tls  *
     85  1.1.1.1.10.2       tls  ******************************************************************************/
     86  1.1.1.1.10.2       tls 
     87  1.1.1.1.10.2       tls ACPI_STATUS
     88  1.1.1.1.10.2       tls AcpiEvInstallRegionHandlers (
     89  1.1.1.1.10.2       tls     void)
     90  1.1.1.1.10.2       tls {
     91  1.1.1.1.10.2       tls     ACPI_STATUS             Status;
     92  1.1.1.1.10.2       tls     UINT32                  i;
     93  1.1.1.1.10.2       tls 
     94  1.1.1.1.10.2       tls 
     95  1.1.1.1.10.2       tls     ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
     96  1.1.1.1.10.2       tls 
     97  1.1.1.1.10.2       tls 
     98  1.1.1.1.10.2       tls     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
     99  1.1.1.1.10.2       tls     if (ACPI_FAILURE (Status))
    100  1.1.1.1.10.2       tls     {
    101  1.1.1.1.10.2       tls         return_ACPI_STATUS (Status);
    102  1.1.1.1.10.2       tls     }
    103  1.1.1.1.10.2       tls 
    104  1.1.1.1.10.2       tls     /*
    105  1.1.1.1.10.2       tls      * All address spaces (PCI Config, EC, SMBus) are scope dependent and
    106  1.1.1.1.10.2       tls      * registration must occur for a specific device.
    107  1.1.1.1.10.2       tls      *
    108  1.1.1.1.10.2       tls      * In the case of the system memory and IO address spaces there is
    109  1.1.1.1.10.2       tls      * currently no device associated with the address space. For these we
    110  1.1.1.1.10.2       tls      * use the root.
    111  1.1.1.1.10.2       tls      *
    112  1.1.1.1.10.2       tls      * We install the default PCI config space handler at the root so that
    113  1.1.1.1.10.2       tls      * this space is immediately available even though the we have not
    114  1.1.1.1.10.2       tls      * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
    115  1.1.1.1.10.2       tls      * specification which states that the PCI config space must be always
    116  1.1.1.1.10.2       tls      * available -- even though we are nowhere near ready to find the PCI root
    117  1.1.1.1.10.2       tls      * buses at this point.
    118  1.1.1.1.10.2       tls      *
    119  1.1.1.1.10.2       tls      * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
    120  1.1.1.1.10.2       tls      * has already been installed (via AcpiInstallAddressSpaceHandler).
    121  1.1.1.1.10.2       tls      * Similar for AE_SAME_HANDLER.
    122  1.1.1.1.10.2       tls      */
    123  1.1.1.1.10.2       tls     for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
    124  1.1.1.1.10.2       tls     {
    125  1.1.1.1.10.2       tls         Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
    126  1.1.1.1.10.3  jdolecek             AcpiGbl_DefaultAddressSpaces[i],
    127  1.1.1.1.10.3  jdolecek             ACPI_DEFAULT_HANDLER, NULL, NULL);
    128  1.1.1.1.10.2       tls         switch (Status)
    129  1.1.1.1.10.2       tls         {
    130  1.1.1.1.10.2       tls         case AE_OK:
    131  1.1.1.1.10.2       tls         case AE_SAME_HANDLER:
    132  1.1.1.1.10.2       tls         case AE_ALREADY_EXISTS:
    133  1.1.1.1.10.2       tls 
    134  1.1.1.1.10.2       tls             /* These exceptions are all OK */
    135  1.1.1.1.10.2       tls 
    136  1.1.1.1.10.2       tls             Status = AE_OK;
    137  1.1.1.1.10.2       tls             break;
    138  1.1.1.1.10.2       tls 
    139  1.1.1.1.10.2       tls         default:
    140  1.1.1.1.10.2       tls 
    141  1.1.1.1.10.2       tls             goto UnlockAndExit;
    142  1.1.1.1.10.2       tls         }
    143  1.1.1.1.10.2       tls     }
    144  1.1.1.1.10.2       tls 
    145  1.1.1.1.10.2       tls UnlockAndExit:
    146  1.1.1.1.10.2       tls     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    147  1.1.1.1.10.2       tls     return_ACPI_STATUS (Status);
    148  1.1.1.1.10.2       tls }
    149  1.1.1.1.10.2       tls 
    150  1.1.1.1.10.2       tls 
    151  1.1.1.1.10.2       tls /*******************************************************************************
    152  1.1.1.1.10.2       tls  *
    153  1.1.1.1.10.2       tls  * FUNCTION:    AcpiEvHasDefaultHandler
    154  1.1.1.1.10.2       tls  *
    155  1.1.1.1.10.2       tls  * PARAMETERS:  Node                - Namespace node for the device
    156  1.1.1.1.10.2       tls  *              SpaceId             - The address space ID
    157  1.1.1.1.10.2       tls  *
    158  1.1.1.1.10.2       tls  * RETURN:      TRUE if default handler is installed, FALSE otherwise
    159  1.1.1.1.10.2       tls  *
    160  1.1.1.1.10.2       tls  * DESCRIPTION: Check if the default handler is installed for the requested
    161  1.1.1.1.10.2       tls  *              space ID.
    162  1.1.1.1.10.2       tls  *
    163  1.1.1.1.10.2       tls  ******************************************************************************/
    164  1.1.1.1.10.2       tls 
    165  1.1.1.1.10.2       tls BOOLEAN
    166  1.1.1.1.10.2       tls AcpiEvHasDefaultHandler (
    167  1.1.1.1.10.2       tls     ACPI_NAMESPACE_NODE     *Node,
    168  1.1.1.1.10.2       tls     ACPI_ADR_SPACE_TYPE     SpaceId)
    169  1.1.1.1.10.2       tls {
    170  1.1.1.1.10.2       tls     ACPI_OPERAND_OBJECT     *ObjDesc;
    171  1.1.1.1.10.2       tls     ACPI_OPERAND_OBJECT     *HandlerObj;
    172  1.1.1.1.10.2       tls 
    173  1.1.1.1.10.2       tls 
    174  1.1.1.1.10.2       tls     /* Must have an existing internal object */
    175  1.1.1.1.10.2       tls 
    176  1.1.1.1.10.2       tls     ObjDesc = AcpiNsGetAttachedObject (Node);
    177  1.1.1.1.10.2       tls     if (ObjDesc)
    178  1.1.1.1.10.2       tls     {
    179  1.1.1.1.10.3  jdolecek         HandlerObj = ObjDesc->CommonNotify.Handler;
    180  1.1.1.1.10.2       tls 
    181  1.1.1.1.10.2       tls         /* Walk the linked list of handlers for this object */
    182  1.1.1.1.10.2       tls 
    183  1.1.1.1.10.2       tls         while (HandlerObj)
    184  1.1.1.1.10.2       tls         {
    185  1.1.1.1.10.2       tls             if (HandlerObj->AddressSpace.SpaceId == SpaceId)
    186  1.1.1.1.10.2       tls             {
    187  1.1.1.1.10.2       tls                 if (HandlerObj->AddressSpace.HandlerFlags &
    188  1.1.1.1.10.3  jdolecek                     ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
    189  1.1.1.1.10.2       tls                 {
    190  1.1.1.1.10.2       tls                     return (TRUE);
    191  1.1.1.1.10.2       tls                 }
    192  1.1.1.1.10.2       tls             }
    193  1.1.1.1.10.2       tls 
    194  1.1.1.1.10.2       tls             HandlerObj = HandlerObj->AddressSpace.Next;
    195  1.1.1.1.10.2       tls         }
    196  1.1.1.1.10.2       tls     }
    197  1.1.1.1.10.2       tls 
    198  1.1.1.1.10.2       tls     return (FALSE);
    199  1.1.1.1.10.2       tls }
    200  1.1.1.1.10.2       tls 
    201  1.1.1.1.10.2       tls 
    202  1.1.1.1.10.2       tls /*******************************************************************************
    203  1.1.1.1.10.2       tls  *
    204  1.1.1.1.10.2       tls  * FUNCTION:    AcpiEvInstallHandler
    205  1.1.1.1.10.2       tls  *
    206  1.1.1.1.10.2       tls  * PARAMETERS:  WalkNamespace callback
    207  1.1.1.1.10.2       tls  *
    208  1.1.1.1.10.2       tls  * DESCRIPTION: This routine installs an address handler into objects that are
    209  1.1.1.1.10.2       tls  *              of type Region or Device.
    210  1.1.1.1.10.2       tls  *
    211  1.1.1.1.10.2       tls  *              If the Object is a Device, and the device has a handler of
    212  1.1.1.1.10.2       tls  *              the same type then the search is terminated in that branch.
    213  1.1.1.1.10.2       tls  *
    214  1.1.1.1.10.2       tls  *              This is because the existing handler is closer in proximity
    215  1.1.1.1.10.2       tls  *              to any more regions than the one we are trying to install.
    216  1.1.1.1.10.2       tls  *
    217  1.1.1.1.10.2       tls  ******************************************************************************/
    218  1.1.1.1.10.2       tls 
    219  1.1.1.1.10.2       tls static ACPI_STATUS
    220  1.1.1.1.10.2       tls AcpiEvInstallHandler (
    221  1.1.1.1.10.2       tls     ACPI_HANDLE             ObjHandle,
    222  1.1.1.1.10.2       tls     UINT32                  Level,
    223  1.1.1.1.10.2       tls     void                    *Context,
    224  1.1.1.1.10.2       tls     void                    **ReturnValue)
    225  1.1.1.1.10.2       tls {
    226  1.1.1.1.10.2       tls     ACPI_OPERAND_OBJECT     *HandlerObj;
    227  1.1.1.1.10.2       tls     ACPI_OPERAND_OBJECT     *NextHandlerObj;
    228  1.1.1.1.10.2       tls     ACPI_OPERAND_OBJECT     *ObjDesc;
    229  1.1.1.1.10.2       tls     ACPI_NAMESPACE_NODE     *Node;
    230  1.1.1.1.10.2       tls     ACPI_STATUS             Status;
    231  1.1.1.1.10.2       tls 
    232  1.1.1.1.10.2       tls 
    233  1.1.1.1.10.2       tls     ACPI_FUNCTION_NAME (EvInstallHandler);
    234  1.1.1.1.10.2       tls 
    235  1.1.1.1.10.2       tls 
    236  1.1.1.1.10.2       tls     HandlerObj = (ACPI_OPERAND_OBJECT  *) Context;
    237  1.1.1.1.10.2       tls 
    238  1.1.1.1.10.2       tls     /* Parameter validation */
    239  1.1.1.1.10.2       tls 
    240  1.1.1.1.10.2       tls     if (!HandlerObj)
    241  1.1.1.1.10.2       tls     {
    242  1.1.1.1.10.2       tls         return (AE_OK);
    243  1.1.1.1.10.2       tls     }
    244  1.1.1.1.10.2       tls 
    245  1.1.1.1.10.2       tls     /* Convert and validate the device handle */
    246  1.1.1.1.10.2       tls 
    247  1.1.1.1.10.2       tls     Node = AcpiNsValidateHandle (ObjHandle);
    248  1.1.1.1.10.2       tls     if (!Node)
    249  1.1.1.1.10.2       tls     {
    250  1.1.1.1.10.2       tls         return (AE_BAD_PARAMETER);
    251  1.1.1.1.10.2       tls     }
    252  1.1.1.1.10.2       tls 
    253  1.1.1.1.10.2       tls     /*
    254  1.1.1.1.10.2       tls      * We only care about regions and objects that are allowed to have
    255  1.1.1.1.10.2       tls      * address space handlers
    256  1.1.1.1.10.2       tls      */
    257  1.1.1.1.10.2       tls     if ((Node->Type != ACPI_TYPE_DEVICE) &&
    258  1.1.1.1.10.2       tls         (Node->Type != ACPI_TYPE_REGION) &&
    259  1.1.1.1.10.2       tls         (Node != AcpiGbl_RootNode))
    260  1.1.1.1.10.2       tls     {
    261  1.1.1.1.10.2       tls         return (AE_OK);
    262  1.1.1.1.10.2       tls     }
    263  1.1.1.1.10.2       tls 
    264  1.1.1.1.10.2       tls     /* Check for an existing internal object */
    265  1.1.1.1.10.2       tls 
    266  1.1.1.1.10.2       tls     ObjDesc = AcpiNsGetAttachedObject (Node);
    267  1.1.1.1.10.2       tls     if (!ObjDesc)
    268  1.1.1.1.10.2       tls     {
    269  1.1.1.1.10.2       tls         /* No object, just exit */
    270  1.1.1.1.10.2       tls 
    271  1.1.1.1.10.2       tls         return (AE_OK);
    272  1.1.1.1.10.2       tls     }
    273  1.1.1.1.10.2       tls 
    274  1.1.1.1.10.2       tls     /* Devices are handled different than regions */
    275  1.1.1.1.10.2       tls 
    276  1.1.1.1.10.2       tls     if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
    277  1.1.1.1.10.2       tls     {
    278  1.1.1.1.10.2       tls         /* Check if this Device already has a handler for this address space */
    279  1.1.1.1.10.2       tls 
    280  1.1.1.1.10.3  jdolecek         NextHandlerObj = AcpiEvFindRegionHandler (
    281  1.1.1.1.10.3  jdolecek             HandlerObj->AddressSpace.SpaceId, ObjDesc->CommonNotify.Handler);
    282  1.1.1.1.10.3  jdolecek         if (NextHandlerObj)
    283  1.1.1.1.10.2       tls         {
    284  1.1.1.1.10.2       tls             /* Found a handler, is it for the same address space? */
    285  1.1.1.1.10.2       tls 
    286  1.1.1.1.10.3  jdolecek             ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    287  1.1.1.1.10.3  jdolecek                 "Found handler for region [%s] in device %p(%p) handler %p\n",
    288  1.1.1.1.10.3  jdolecek                 AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
    289  1.1.1.1.10.3  jdolecek                 ObjDesc, NextHandlerObj, HandlerObj));
    290  1.1.1.1.10.3  jdolecek 
    291  1.1.1.1.10.3  jdolecek             /*
    292  1.1.1.1.10.3  jdolecek              * Since the object we found it on was a device, then it means
    293  1.1.1.1.10.3  jdolecek              * that someone has already installed a handler for the branch
    294  1.1.1.1.10.3  jdolecek              * of the namespace from this device on. Just bail out telling
    295  1.1.1.1.10.3  jdolecek              * the walk routine to not traverse this branch. This preserves
    296  1.1.1.1.10.3  jdolecek              * the scoping rule for handlers.
    297  1.1.1.1.10.3  jdolecek              */
    298  1.1.1.1.10.3  jdolecek             return (AE_CTRL_DEPTH);
    299  1.1.1.1.10.2       tls         }
    300  1.1.1.1.10.2       tls 
    301  1.1.1.1.10.2       tls         /*
    302  1.1.1.1.10.2       tls          * As long as the device didn't have a handler for this space we
    303  1.1.1.1.10.2       tls          * don't care about it. We just ignore it and proceed.
    304  1.1.1.1.10.2       tls          */
    305  1.1.1.1.10.2       tls         return (AE_OK);
    306  1.1.1.1.10.2       tls     }
    307  1.1.1.1.10.2       tls 
    308  1.1.1.1.10.2       tls     /* Object is a Region */
    309  1.1.1.1.10.2       tls 
    310  1.1.1.1.10.2       tls     if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
    311  1.1.1.1.10.2       tls     {
    312  1.1.1.1.10.2       tls         /* This region is for a different address space, just ignore it */
    313  1.1.1.1.10.2       tls 
    314  1.1.1.1.10.2       tls         return (AE_OK);
    315  1.1.1.1.10.2       tls     }
    316  1.1.1.1.10.2       tls 
    317  1.1.1.1.10.2       tls     /*
    318  1.1.1.1.10.2       tls      * Now we have a region and it is for the handler's address space type.
    319  1.1.1.1.10.2       tls      *
    320  1.1.1.1.10.2       tls      * First disconnect region for any previous handler (if any)
    321  1.1.1.1.10.2       tls      */
    322  1.1.1.1.10.2       tls     AcpiEvDetachRegion (ObjDesc, FALSE);
    323  1.1.1.1.10.2       tls 
    324  1.1.1.1.10.2       tls     /* Connect the region to the new handler */
    325  1.1.1.1.10.2       tls 
    326  1.1.1.1.10.2       tls     Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
    327  1.1.1.1.10.2       tls     return (Status);
    328  1.1.1.1.10.2       tls }
    329  1.1.1.1.10.2       tls 
    330  1.1.1.1.10.2       tls 
    331  1.1.1.1.10.2       tls /*******************************************************************************
    332  1.1.1.1.10.2       tls  *
    333  1.1.1.1.10.3  jdolecek  * FUNCTION:    AcpiEvFindRegionHandler
    334  1.1.1.1.10.3  jdolecek  *
    335  1.1.1.1.10.3  jdolecek  * PARAMETERS:  SpaceId         - The address space ID
    336  1.1.1.1.10.3  jdolecek  *              HandlerObj      - Head of the handler object list
    337  1.1.1.1.10.3  jdolecek  *
    338  1.1.1.1.10.3  jdolecek  * RETURN:      Matching handler object. NULL if space ID not matched
    339  1.1.1.1.10.3  jdolecek  *
    340  1.1.1.1.10.3  jdolecek  * DESCRIPTION: Search a handler object list for a match on the address
    341  1.1.1.1.10.3  jdolecek  *              space ID.
    342  1.1.1.1.10.3  jdolecek  *
    343  1.1.1.1.10.3  jdolecek  ******************************************************************************/
    344  1.1.1.1.10.3  jdolecek 
    345  1.1.1.1.10.3  jdolecek ACPI_OPERAND_OBJECT *
    346  1.1.1.1.10.3  jdolecek AcpiEvFindRegionHandler (
    347  1.1.1.1.10.3  jdolecek     ACPI_ADR_SPACE_TYPE     SpaceId,
    348  1.1.1.1.10.3  jdolecek     ACPI_OPERAND_OBJECT     *HandlerObj)
    349  1.1.1.1.10.3  jdolecek {
    350  1.1.1.1.10.3  jdolecek 
    351  1.1.1.1.10.3  jdolecek     /* Walk the handler list for this device */
    352  1.1.1.1.10.3  jdolecek 
    353  1.1.1.1.10.3  jdolecek     while (HandlerObj)
    354  1.1.1.1.10.3  jdolecek     {
    355  1.1.1.1.10.3  jdolecek         /* Same SpaceId indicates a handler is installed */
    356  1.1.1.1.10.3  jdolecek 
    357  1.1.1.1.10.3  jdolecek         if (HandlerObj->AddressSpace.SpaceId == SpaceId)
    358  1.1.1.1.10.3  jdolecek         {
    359  1.1.1.1.10.3  jdolecek             return (HandlerObj);
    360  1.1.1.1.10.3  jdolecek         }
    361  1.1.1.1.10.3  jdolecek 
    362  1.1.1.1.10.3  jdolecek         /* Next handler object */
    363  1.1.1.1.10.3  jdolecek 
    364  1.1.1.1.10.3  jdolecek         HandlerObj = HandlerObj->AddressSpace.Next;
    365  1.1.1.1.10.3  jdolecek     }
    366  1.1.1.1.10.3  jdolecek 
    367  1.1.1.1.10.3  jdolecek     return (NULL);
    368  1.1.1.1.10.3  jdolecek }
    369  1.1.1.1.10.3  jdolecek 
    370  1.1.1.1.10.3  jdolecek 
    371  1.1.1.1.10.3  jdolecek /*******************************************************************************
    372  1.1.1.1.10.3  jdolecek  *
    373  1.1.1.1.10.2       tls  * FUNCTION:    AcpiEvInstallSpaceHandler
    374  1.1.1.1.10.2       tls  *
    375  1.1.1.1.10.2       tls  * PARAMETERS:  Node            - Namespace node for the device
    376  1.1.1.1.10.2       tls  *              SpaceId         - The address space ID
    377  1.1.1.1.10.2       tls  *              Handler         - Address of the handler
    378  1.1.1.1.10.2       tls  *              Setup           - Address of the setup function
    379  1.1.1.1.10.2       tls  *              Context         - Value passed to the handler on each access
    380  1.1.1.1.10.2       tls  *
    381  1.1.1.1.10.2       tls  * RETURN:      Status
    382  1.1.1.1.10.2       tls  *
    383  1.1.1.1.10.2       tls  * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
    384  1.1.1.1.10.2       tls  *              Assumes namespace is locked
    385  1.1.1.1.10.2       tls  *
    386  1.1.1.1.10.2       tls  ******************************************************************************/
    387  1.1.1.1.10.2       tls 
    388  1.1.1.1.10.2       tls ACPI_STATUS
    389  1.1.1.1.10.2       tls AcpiEvInstallSpaceHandler (
    390  1.1.1.1.10.2       tls     ACPI_NAMESPACE_NODE     *Node,
    391  1.1.1.1.10.2       tls     ACPI_ADR_SPACE_TYPE     SpaceId,
    392  1.1.1.1.10.2       tls     ACPI_ADR_SPACE_HANDLER  Handler,
    393  1.1.1.1.10.2       tls     ACPI_ADR_SPACE_SETUP    Setup,
    394  1.1.1.1.10.2       tls     void                    *Context)
    395  1.1.1.1.10.2       tls {
    396  1.1.1.1.10.2       tls     ACPI_OPERAND_OBJECT     *ObjDesc;
    397  1.1.1.1.10.2       tls     ACPI_OPERAND_OBJECT     *HandlerObj;
    398  1.1.1.1.10.3  jdolecek     ACPI_STATUS             Status = AE_OK;
    399  1.1.1.1.10.2       tls     ACPI_OBJECT_TYPE        Type;
    400  1.1.1.1.10.3  jdolecek     UINT8                   Flags = 0;
    401  1.1.1.1.10.2       tls 
    402  1.1.1.1.10.2       tls 
    403  1.1.1.1.10.2       tls     ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
    404  1.1.1.1.10.2       tls 
    405  1.1.1.1.10.2       tls 
    406  1.1.1.1.10.2       tls     /*
    407  1.1.1.1.10.3  jdolecek      * This registration is valid for only the types below and the root.
    408  1.1.1.1.10.3  jdolecek      * The root node is where the default handlers get installed.
    409  1.1.1.1.10.2       tls      */
    410  1.1.1.1.10.2       tls     if ((Node->Type != ACPI_TYPE_DEVICE)     &&
    411  1.1.1.1.10.2       tls         (Node->Type != ACPI_TYPE_PROCESSOR)  &&
    412  1.1.1.1.10.2       tls         (Node->Type != ACPI_TYPE_THERMAL)    &&
    413  1.1.1.1.10.2       tls         (Node != AcpiGbl_RootNode))
    414  1.1.1.1.10.2       tls     {
    415  1.1.1.1.10.2       tls         Status = AE_BAD_PARAMETER;
    416  1.1.1.1.10.2       tls         goto UnlockAndExit;
    417  1.1.1.1.10.2       tls     }
    418  1.1.1.1.10.2       tls 
    419  1.1.1.1.10.2       tls     if (Handler == ACPI_DEFAULT_HANDLER)
    420  1.1.1.1.10.2       tls     {
    421  1.1.1.1.10.2       tls         Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
    422  1.1.1.1.10.2       tls 
    423  1.1.1.1.10.2       tls         switch (SpaceId)
    424  1.1.1.1.10.2       tls         {
    425  1.1.1.1.10.2       tls         case ACPI_ADR_SPACE_SYSTEM_MEMORY:
    426  1.1.1.1.10.2       tls 
    427  1.1.1.1.10.2       tls             Handler = AcpiExSystemMemorySpaceHandler;
    428  1.1.1.1.10.2       tls             Setup   = AcpiEvSystemMemoryRegionSetup;
    429  1.1.1.1.10.2       tls             break;
    430  1.1.1.1.10.2       tls 
    431  1.1.1.1.10.2       tls         case ACPI_ADR_SPACE_SYSTEM_IO:
    432  1.1.1.1.10.2       tls 
    433  1.1.1.1.10.2       tls             Handler = AcpiExSystemIoSpaceHandler;
    434  1.1.1.1.10.2       tls             Setup   = AcpiEvIoSpaceRegionSetup;
    435  1.1.1.1.10.2       tls             break;
    436  1.1.1.1.10.2       tls 
    437  1.1.1.1.10.2       tls         case ACPI_ADR_SPACE_PCI_CONFIG:
    438  1.1.1.1.10.2       tls 
    439  1.1.1.1.10.2       tls             Handler = AcpiExPciConfigSpaceHandler;
    440  1.1.1.1.10.2       tls             Setup   = AcpiEvPciConfigRegionSetup;
    441  1.1.1.1.10.2       tls             break;
    442  1.1.1.1.10.2       tls 
    443  1.1.1.1.10.2       tls         case ACPI_ADR_SPACE_CMOS:
    444  1.1.1.1.10.2       tls 
    445  1.1.1.1.10.2       tls             Handler = AcpiExCmosSpaceHandler;
    446  1.1.1.1.10.2       tls             Setup   = AcpiEvCmosRegionSetup;
    447  1.1.1.1.10.2       tls             break;
    448  1.1.1.1.10.2       tls 
    449  1.1.1.1.10.2       tls         case ACPI_ADR_SPACE_PCI_BAR_TARGET:
    450  1.1.1.1.10.2       tls 
    451  1.1.1.1.10.2       tls             Handler = AcpiExPciBarSpaceHandler;
    452  1.1.1.1.10.2       tls             Setup   = AcpiEvPciBarRegionSetup;
    453  1.1.1.1.10.2       tls             break;
    454  1.1.1.1.10.2       tls 
    455  1.1.1.1.10.2       tls         case ACPI_ADR_SPACE_DATA_TABLE:
    456  1.1.1.1.10.2       tls 
    457  1.1.1.1.10.2       tls             Handler = AcpiExDataTableSpaceHandler;
    458  1.1.1.1.10.2       tls             Setup   = NULL;
    459  1.1.1.1.10.2       tls             break;
    460  1.1.1.1.10.2       tls 
    461  1.1.1.1.10.2       tls         default:
    462  1.1.1.1.10.2       tls 
    463  1.1.1.1.10.2       tls             Status = AE_BAD_PARAMETER;
    464  1.1.1.1.10.2       tls             goto UnlockAndExit;
    465  1.1.1.1.10.2       tls         }
    466  1.1.1.1.10.2       tls     }
    467  1.1.1.1.10.2       tls 
    468  1.1.1.1.10.2       tls     /* If the caller hasn't specified a setup routine, use the default */
    469  1.1.1.1.10.2       tls 
    470  1.1.1.1.10.2       tls     if (!Setup)
    471  1.1.1.1.10.2       tls     {
    472  1.1.1.1.10.2       tls         Setup = AcpiEvDefaultRegionSetup;
    473  1.1.1.1.10.2       tls     }
    474  1.1.1.1.10.2       tls 
    475  1.1.1.1.10.2       tls     /* Check for an existing internal object */
    476  1.1.1.1.10.2       tls 
    477  1.1.1.1.10.2       tls     ObjDesc = AcpiNsGetAttachedObject (Node);
    478  1.1.1.1.10.2       tls     if (ObjDesc)
    479  1.1.1.1.10.2       tls     {
    480  1.1.1.1.10.2       tls         /*
    481  1.1.1.1.10.3  jdolecek          * The attached device object already exists. Now make sure
    482  1.1.1.1.10.3  jdolecek          * the handler is not already installed.
    483  1.1.1.1.10.2       tls          */
    484  1.1.1.1.10.3  jdolecek         HandlerObj = AcpiEvFindRegionHandler (SpaceId,
    485  1.1.1.1.10.3  jdolecek             ObjDesc->CommonNotify.Handler);
    486  1.1.1.1.10.2       tls 
    487  1.1.1.1.10.3  jdolecek         if (HandlerObj)
    488  1.1.1.1.10.2       tls         {
    489  1.1.1.1.10.3  jdolecek             if (HandlerObj->AddressSpace.Handler == Handler)
    490  1.1.1.1.10.2       tls             {
    491  1.1.1.1.10.3  jdolecek                 /*
    492  1.1.1.1.10.3  jdolecek                  * It is (relatively) OK to attempt to install the SAME
    493  1.1.1.1.10.3  jdolecek                  * handler twice. This can easily happen with the
    494  1.1.1.1.10.3  jdolecek                  * PCI_Config space.
    495  1.1.1.1.10.3  jdolecek                  */
    496  1.1.1.1.10.3  jdolecek                 Status = AE_SAME_HANDLER;
    497  1.1.1.1.10.2       tls                 goto UnlockAndExit;
    498  1.1.1.1.10.2       tls             }
    499  1.1.1.1.10.3  jdolecek             else
    500  1.1.1.1.10.3  jdolecek             {
    501  1.1.1.1.10.3  jdolecek                 /* A handler is already installed */
    502  1.1.1.1.10.2       tls 
    503  1.1.1.1.10.3  jdolecek                 Status = AE_ALREADY_EXISTS;
    504  1.1.1.1.10.3  jdolecek             }
    505  1.1.1.1.10.2       tls 
    506  1.1.1.1.10.3  jdolecek             goto UnlockAndExit;
    507  1.1.1.1.10.2       tls         }
    508  1.1.1.1.10.2       tls     }
    509  1.1.1.1.10.2       tls     else
    510  1.1.1.1.10.2       tls     {
    511  1.1.1.1.10.2       tls         ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    512  1.1.1.1.10.3  jdolecek             "Creating object on Device %p while installing handler\n",
    513  1.1.1.1.10.3  jdolecek             Node));
    514  1.1.1.1.10.2       tls 
    515  1.1.1.1.10.2       tls         /* ObjDesc does not exist, create one */
    516  1.1.1.1.10.2       tls 
    517  1.1.1.1.10.2       tls         if (Node->Type == ACPI_TYPE_ANY)
    518  1.1.1.1.10.2       tls         {
    519  1.1.1.1.10.2       tls             Type = ACPI_TYPE_DEVICE;
    520  1.1.1.1.10.2       tls         }
    521  1.1.1.1.10.2       tls         else
    522  1.1.1.1.10.2       tls         {
    523  1.1.1.1.10.2       tls             Type = Node->Type;
    524  1.1.1.1.10.2       tls         }
    525  1.1.1.1.10.2       tls 
    526  1.1.1.1.10.2       tls         ObjDesc = AcpiUtCreateInternalObject (Type);
    527  1.1.1.1.10.2       tls         if (!ObjDesc)
    528  1.1.1.1.10.2       tls         {
    529  1.1.1.1.10.2       tls             Status = AE_NO_MEMORY;
    530  1.1.1.1.10.2       tls             goto UnlockAndExit;
    531  1.1.1.1.10.2       tls         }
    532  1.1.1.1.10.2       tls 
    533  1.1.1.1.10.2       tls         /* Init new descriptor */
    534  1.1.1.1.10.2       tls 
    535  1.1.1.1.10.2       tls         ObjDesc->Common.Type = (UINT8) Type;
    536  1.1.1.1.10.2       tls 
    537  1.1.1.1.10.2       tls         /* Attach the new object to the Node */
    538  1.1.1.1.10.2       tls 
    539  1.1.1.1.10.2       tls         Status = AcpiNsAttachObject (Node, ObjDesc, Type);
    540  1.1.1.1.10.2       tls 
    541  1.1.1.1.10.2       tls         /* Remove local reference to the object */
    542  1.1.1.1.10.2       tls 
    543  1.1.1.1.10.2       tls         AcpiUtRemoveReference (ObjDesc);
    544  1.1.1.1.10.2       tls 
    545  1.1.1.1.10.2       tls         if (ACPI_FAILURE (Status))
    546  1.1.1.1.10.2       tls         {
    547  1.1.1.1.10.2       tls             goto UnlockAndExit;
    548  1.1.1.1.10.2       tls         }
    549  1.1.1.1.10.2       tls     }
    550  1.1.1.1.10.2       tls 
    551  1.1.1.1.10.2       tls     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    552  1.1.1.1.10.3  jdolecek         "Installing address handler for region %s(%X) "
    553  1.1.1.1.10.3  jdolecek         "on Device %4.4s %p(%p)\n",
    554  1.1.1.1.10.2       tls         AcpiUtGetRegionName (SpaceId), SpaceId,
    555  1.1.1.1.10.2       tls         AcpiUtGetNodeName (Node), Node, ObjDesc));
    556  1.1.1.1.10.2       tls 
    557  1.1.1.1.10.2       tls     /*
    558  1.1.1.1.10.2       tls      * Install the handler
    559  1.1.1.1.10.2       tls      *
    560  1.1.1.1.10.2       tls      * At this point there is no existing handler. Just allocate the object
    561  1.1.1.1.10.2       tls      * for the handler and link it into the list.
    562  1.1.1.1.10.2       tls      */
    563  1.1.1.1.10.2       tls     HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
    564  1.1.1.1.10.2       tls     if (!HandlerObj)
    565  1.1.1.1.10.2       tls     {
    566  1.1.1.1.10.2       tls         Status = AE_NO_MEMORY;
    567  1.1.1.1.10.2       tls         goto UnlockAndExit;
    568  1.1.1.1.10.2       tls     }
    569  1.1.1.1.10.2       tls 
    570  1.1.1.1.10.2       tls     /* Init handler obj */
    571  1.1.1.1.10.2       tls 
    572  1.1.1.1.10.2       tls     HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
    573  1.1.1.1.10.2       tls     HandlerObj->AddressSpace.HandlerFlags = Flags;
    574  1.1.1.1.10.2       tls     HandlerObj->AddressSpace.RegionList = NULL;
    575  1.1.1.1.10.2       tls     HandlerObj->AddressSpace.Node = Node;
    576  1.1.1.1.10.2       tls     HandlerObj->AddressSpace.Handler = Handler;
    577  1.1.1.1.10.2       tls     HandlerObj->AddressSpace.Context = Context;
    578  1.1.1.1.10.3  jdolecek     HandlerObj->AddressSpace.Setup = Setup;
    579  1.1.1.1.10.2       tls 
    580  1.1.1.1.10.2       tls     /* Install at head of Device.AddressSpace list */
    581  1.1.1.1.10.2       tls 
    582  1.1.1.1.10.3  jdolecek     HandlerObj->AddressSpace.Next = ObjDesc->CommonNotify.Handler;
    583  1.1.1.1.10.2       tls 
    584  1.1.1.1.10.2       tls     /*
    585  1.1.1.1.10.2       tls      * The Device object is the first reference on the HandlerObj.
    586  1.1.1.1.10.2       tls      * Each region that uses the handler adds a reference.
    587  1.1.1.1.10.2       tls      */
    588  1.1.1.1.10.3  jdolecek     ObjDesc->CommonNotify.Handler = HandlerObj;
    589  1.1.1.1.10.2       tls 
    590  1.1.1.1.10.2       tls     /*
    591  1.1.1.1.10.3  jdolecek      * Walk the namespace finding all of the regions this handler will
    592  1.1.1.1.10.3  jdolecek      * manage.
    593  1.1.1.1.10.2       tls      *
    594  1.1.1.1.10.3  jdolecek      * Start at the device and search the branch toward the leaf nodes
    595  1.1.1.1.10.3  jdolecek      * until either the leaf is encountered or a device is detected that
    596  1.1.1.1.10.3  jdolecek      * has an address handler of the same type.
    597  1.1.1.1.10.2       tls      *
    598  1.1.1.1.10.3  jdolecek      * In either case, back up and search down the remainder of the branch
    599  1.1.1.1.10.2       tls      */
    600  1.1.1.1.10.3  jdolecek     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node,
    601  1.1.1.1.10.3  jdolecek         ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
    602  1.1.1.1.10.3  jdolecek         AcpiEvInstallHandler, NULL, HandlerObj, NULL);
    603  1.1.1.1.10.2       tls 
    604  1.1.1.1.10.2       tls UnlockAndExit:
    605  1.1.1.1.10.2       tls     return_ACPI_STATUS (Status);
    606  1.1.1.1.10.2       tls }
    607