Home | History | Annotate | Line # | Download | only in events
evregion.c revision 1.1.1.2
      1      1.1  jruoho /******************************************************************************
      2      1.1  jruoho  *
      3      1.1  jruoho  * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
      4      1.1  jruoho  *
      5      1.1  jruoho  *****************************************************************************/
      6      1.1  jruoho 
      7  1.1.1.2  jruoho /*
      8  1.1.1.2  jruoho  * Copyright (C) 2000 - 2011, Intel Corp.
      9      1.1  jruoho  * All rights reserved.
     10      1.1  jruoho  *
     11  1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2  jruoho  * are met:
     14  1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2  jruoho  *    without modification.
     17  1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2  jruoho  *    binary redistribution.
     22  1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2  jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2  jruoho  *
     26  1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2  jruoho  * Software Foundation.
     29  1.1.1.2  jruoho  *
     30  1.1.1.2  jruoho  * NO WARRANTY
     31  1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2  jruoho  */
     43      1.1  jruoho 
     44      1.1  jruoho 
     45      1.1  jruoho #define __EVREGION_C__
     46      1.1  jruoho 
     47      1.1  jruoho #include "acpi.h"
     48      1.1  jruoho #include "accommon.h"
     49      1.1  jruoho #include "acevents.h"
     50      1.1  jruoho #include "acnamesp.h"
     51      1.1  jruoho #include "acinterp.h"
     52      1.1  jruoho 
     53      1.1  jruoho #define _COMPONENT          ACPI_EVENTS
     54      1.1  jruoho         ACPI_MODULE_NAME    ("evregion")
     55      1.1  jruoho 
     56      1.1  jruoho 
     57      1.1  jruoho /* Local prototypes */
     58      1.1  jruoho 
     59      1.1  jruoho static BOOLEAN
     60      1.1  jruoho AcpiEvHasDefaultHandler (
     61      1.1  jruoho     ACPI_NAMESPACE_NODE     *Node,
     62      1.1  jruoho     ACPI_ADR_SPACE_TYPE     SpaceId);
     63      1.1  jruoho 
     64      1.1  jruoho static ACPI_STATUS
     65      1.1  jruoho AcpiEvRegRun (
     66      1.1  jruoho     ACPI_HANDLE             ObjHandle,
     67      1.1  jruoho     UINT32                  Level,
     68      1.1  jruoho     void                    *Context,
     69      1.1  jruoho     void                    **ReturnValue);
     70      1.1  jruoho 
     71      1.1  jruoho static ACPI_STATUS
     72      1.1  jruoho AcpiEvInstallHandler (
     73      1.1  jruoho     ACPI_HANDLE             ObjHandle,
     74      1.1  jruoho     UINT32                  Level,
     75      1.1  jruoho     void                    *Context,
     76      1.1  jruoho     void                    **ReturnValue);
     77      1.1  jruoho 
     78      1.1  jruoho /* These are the address spaces that will get default handlers */
     79      1.1  jruoho 
     80      1.1  jruoho #define ACPI_NUM_DEFAULT_SPACES     4
     81      1.1  jruoho 
     82      1.1  jruoho static UINT8        AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
     83      1.1  jruoho {
     84      1.1  jruoho     ACPI_ADR_SPACE_SYSTEM_MEMORY,
     85      1.1  jruoho     ACPI_ADR_SPACE_SYSTEM_IO,
     86      1.1  jruoho     ACPI_ADR_SPACE_PCI_CONFIG,
     87      1.1  jruoho     ACPI_ADR_SPACE_DATA_TABLE
     88      1.1  jruoho };
     89      1.1  jruoho 
     90      1.1  jruoho 
     91      1.1  jruoho /*******************************************************************************
     92      1.1  jruoho  *
     93      1.1  jruoho  * FUNCTION:    AcpiEvInstallRegionHandlers
     94      1.1  jruoho  *
     95      1.1  jruoho  * PARAMETERS:  None
     96      1.1  jruoho  *
     97      1.1  jruoho  * RETURN:      Status
     98      1.1  jruoho  *
     99      1.1  jruoho  * DESCRIPTION: Installs the core subsystem default address space handlers.
    100      1.1  jruoho  *
    101      1.1  jruoho  ******************************************************************************/
    102      1.1  jruoho 
    103      1.1  jruoho ACPI_STATUS
    104      1.1  jruoho AcpiEvInstallRegionHandlers (
    105      1.1  jruoho     void)
    106      1.1  jruoho {
    107      1.1  jruoho     ACPI_STATUS             Status;
    108      1.1  jruoho     UINT32                  i;
    109      1.1  jruoho 
    110      1.1  jruoho 
    111      1.1  jruoho     ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
    112      1.1  jruoho 
    113      1.1  jruoho 
    114      1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    115      1.1  jruoho     if (ACPI_FAILURE (Status))
    116      1.1  jruoho     {
    117      1.1  jruoho         return_ACPI_STATUS (Status);
    118      1.1  jruoho     }
    119      1.1  jruoho 
    120      1.1  jruoho     /*
    121      1.1  jruoho      * All address spaces (PCI Config, EC, SMBus) are scope dependent and
    122      1.1  jruoho      * registration must occur for a specific device.
    123      1.1  jruoho      *
    124      1.1  jruoho      * In the case of the system memory and IO address spaces there is
    125      1.1  jruoho      * currently no device associated with the address space. For these we
    126      1.1  jruoho      * use the root.
    127      1.1  jruoho      *
    128      1.1  jruoho      * We install the default PCI config space handler at the root so that
    129      1.1  jruoho      * this space is immediately available even though the we have not
    130      1.1  jruoho      * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
    131      1.1  jruoho      * specification which states that the PCI config space must be always
    132      1.1  jruoho      * available -- even though we are nowhere near ready to find the PCI root
    133      1.1  jruoho      * buses at this point.
    134      1.1  jruoho      *
    135      1.1  jruoho      * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
    136      1.1  jruoho      * has already been installed (via AcpiInstallAddressSpaceHandler).
    137      1.1  jruoho      * Similar for AE_SAME_HANDLER.
    138      1.1  jruoho      */
    139      1.1  jruoho     for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
    140      1.1  jruoho     {
    141      1.1  jruoho         Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
    142      1.1  jruoho                     AcpiGbl_DefaultAddressSpaces[i],
    143      1.1  jruoho                     ACPI_DEFAULT_HANDLER, NULL, NULL);
    144      1.1  jruoho         switch (Status)
    145      1.1  jruoho         {
    146      1.1  jruoho         case AE_OK:
    147      1.1  jruoho         case AE_SAME_HANDLER:
    148      1.1  jruoho         case AE_ALREADY_EXISTS:
    149      1.1  jruoho 
    150      1.1  jruoho             /* These exceptions are all OK */
    151      1.1  jruoho 
    152      1.1  jruoho             Status = AE_OK;
    153      1.1  jruoho             break;
    154      1.1  jruoho 
    155      1.1  jruoho         default:
    156      1.1  jruoho 
    157      1.1  jruoho             goto UnlockAndExit;
    158      1.1  jruoho         }
    159      1.1  jruoho     }
    160      1.1  jruoho 
    161      1.1  jruoho UnlockAndExit:
    162      1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    163      1.1  jruoho     return_ACPI_STATUS (Status);
    164      1.1  jruoho }
    165      1.1  jruoho 
    166      1.1  jruoho 
    167      1.1  jruoho /*******************************************************************************
    168      1.1  jruoho  *
    169      1.1  jruoho  * FUNCTION:    AcpiEvHasDefaultHandler
    170      1.1  jruoho  *
    171      1.1  jruoho  * PARAMETERS:  Node                - Namespace node for the device
    172      1.1  jruoho  *              SpaceId             - The address space ID
    173      1.1  jruoho  *
    174      1.1  jruoho  * RETURN:      TRUE if default handler is installed, FALSE otherwise
    175      1.1  jruoho  *
    176      1.1  jruoho  * DESCRIPTION: Check if the default handler is installed for the requested
    177      1.1  jruoho  *              space ID.
    178      1.1  jruoho  *
    179      1.1  jruoho  ******************************************************************************/
    180      1.1  jruoho 
    181      1.1  jruoho static BOOLEAN
    182      1.1  jruoho AcpiEvHasDefaultHandler (
    183      1.1  jruoho     ACPI_NAMESPACE_NODE     *Node,
    184      1.1  jruoho     ACPI_ADR_SPACE_TYPE     SpaceId)
    185      1.1  jruoho {
    186      1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    187      1.1  jruoho     ACPI_OPERAND_OBJECT     *HandlerObj;
    188      1.1  jruoho 
    189      1.1  jruoho 
    190      1.1  jruoho     /* Must have an existing internal object */
    191      1.1  jruoho 
    192      1.1  jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
    193      1.1  jruoho     if (ObjDesc)
    194      1.1  jruoho     {
    195      1.1  jruoho         HandlerObj = ObjDesc->Device.Handler;
    196      1.1  jruoho 
    197      1.1  jruoho         /* Walk the linked list of handlers for this object */
    198      1.1  jruoho 
    199      1.1  jruoho         while (HandlerObj)
    200      1.1  jruoho         {
    201      1.1  jruoho             if (HandlerObj->AddressSpace.SpaceId == SpaceId)
    202      1.1  jruoho             {
    203      1.1  jruoho                 if (HandlerObj->AddressSpace.HandlerFlags &
    204      1.1  jruoho                         ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
    205      1.1  jruoho                 {
    206      1.1  jruoho                     return (TRUE);
    207      1.1  jruoho                 }
    208      1.1  jruoho             }
    209      1.1  jruoho 
    210      1.1  jruoho             HandlerObj = HandlerObj->AddressSpace.Next;
    211      1.1  jruoho         }
    212      1.1  jruoho     }
    213      1.1  jruoho 
    214      1.1  jruoho     return (FALSE);
    215      1.1  jruoho }
    216      1.1  jruoho 
    217      1.1  jruoho 
    218      1.1  jruoho /*******************************************************************************
    219      1.1  jruoho  *
    220      1.1  jruoho  * FUNCTION:    AcpiEvInitializeOpRegions
    221      1.1  jruoho  *
    222      1.1  jruoho  * PARAMETERS:  None
    223      1.1  jruoho  *
    224      1.1  jruoho  * RETURN:      Status
    225      1.1  jruoho  *
    226      1.1  jruoho  * DESCRIPTION: Execute _REG methods for all Operation Regions that have
    227      1.1  jruoho  *              an installed default region handler.
    228      1.1  jruoho  *
    229      1.1  jruoho  ******************************************************************************/
    230      1.1  jruoho 
    231      1.1  jruoho ACPI_STATUS
    232      1.1  jruoho AcpiEvInitializeOpRegions (
    233      1.1  jruoho     void)
    234      1.1  jruoho {
    235      1.1  jruoho     ACPI_STATUS             Status;
    236      1.1  jruoho     UINT32                  i;
    237      1.1  jruoho 
    238      1.1  jruoho 
    239      1.1  jruoho     ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
    240      1.1  jruoho 
    241      1.1  jruoho 
    242      1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    243      1.1  jruoho     if (ACPI_FAILURE (Status))
    244      1.1  jruoho     {
    245      1.1  jruoho         return_ACPI_STATUS (Status);
    246      1.1  jruoho     }
    247      1.1  jruoho 
    248      1.1  jruoho     /* Run the _REG methods for OpRegions in each default address space */
    249      1.1  jruoho 
    250      1.1  jruoho     for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
    251      1.1  jruoho     {
    252      1.1  jruoho         /*
    253      1.1  jruoho          * Make sure the installed handler is the DEFAULT handler. If not the
    254      1.1  jruoho          * default, the _REG methods will have already been run (when the
    255      1.1  jruoho          * handler was installed)
    256      1.1  jruoho          */
    257      1.1  jruoho         if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
    258      1.1  jruoho                AcpiGbl_DefaultAddressSpaces[i]))
    259      1.1  jruoho         {
    260      1.1  jruoho             Status = AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
    261      1.1  jruoho                         AcpiGbl_DefaultAddressSpaces[i]);
    262      1.1  jruoho         }
    263      1.1  jruoho     }
    264      1.1  jruoho 
    265  1.1.1.2  jruoho     AcpiGbl_RegMethodsExecuted = TRUE;
    266  1.1.1.2  jruoho 
    267      1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    268      1.1  jruoho     return_ACPI_STATUS (Status);
    269      1.1  jruoho }
    270      1.1  jruoho 
    271      1.1  jruoho 
    272      1.1  jruoho /*******************************************************************************
    273      1.1  jruoho  *
    274      1.1  jruoho  * FUNCTION:    AcpiEvExecuteRegMethod
    275      1.1  jruoho  *
    276      1.1  jruoho  * PARAMETERS:  RegionObj           - Region object
    277      1.1  jruoho  *              Function            - Passed to _REG: On (1) or Off (0)
    278      1.1  jruoho  *
    279      1.1  jruoho  * RETURN:      Status
    280      1.1  jruoho  *
    281      1.1  jruoho  * DESCRIPTION: Execute _REG method for a region
    282      1.1  jruoho  *
    283      1.1  jruoho  ******************************************************************************/
    284      1.1  jruoho 
    285      1.1  jruoho ACPI_STATUS
    286      1.1  jruoho AcpiEvExecuteRegMethod (
    287      1.1  jruoho     ACPI_OPERAND_OBJECT     *RegionObj,
    288      1.1  jruoho     UINT32                  Function)
    289      1.1  jruoho {
    290      1.1  jruoho     ACPI_EVALUATE_INFO      *Info;
    291      1.1  jruoho     ACPI_OPERAND_OBJECT     *Args[3];
    292      1.1  jruoho     ACPI_OPERAND_OBJECT     *RegionObj2;
    293      1.1  jruoho     ACPI_STATUS             Status;
    294      1.1  jruoho 
    295      1.1  jruoho 
    296      1.1  jruoho     ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
    297      1.1  jruoho 
    298      1.1  jruoho 
    299      1.1  jruoho     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
    300      1.1  jruoho     if (!RegionObj2)
    301      1.1  jruoho     {
    302      1.1  jruoho         return_ACPI_STATUS (AE_NOT_EXIST);
    303      1.1  jruoho     }
    304      1.1  jruoho 
    305      1.1  jruoho     if (RegionObj2->Extra.Method_REG == NULL)
    306      1.1  jruoho     {
    307      1.1  jruoho         return_ACPI_STATUS (AE_OK);
    308      1.1  jruoho     }
    309      1.1  jruoho 
    310      1.1  jruoho     /* Allocate and initialize the evaluation information block */
    311      1.1  jruoho 
    312      1.1  jruoho     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    313      1.1  jruoho     if (!Info)
    314      1.1  jruoho     {
    315      1.1  jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    316      1.1  jruoho     }
    317      1.1  jruoho 
    318      1.1  jruoho     Info->PrefixNode = RegionObj2->Extra.Method_REG;
    319      1.1  jruoho     Info->Pathname = NULL;
    320      1.1  jruoho     Info->Parameters = Args;
    321      1.1  jruoho     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
    322      1.1  jruoho 
    323      1.1  jruoho     /*
    324      1.1  jruoho      * The _REG method has two arguments:
    325      1.1  jruoho      *
    326      1.1  jruoho      * Arg0 - Integer:
    327      1.1  jruoho      *  Operation region space ID Same value as RegionObj->Region.SpaceId
    328      1.1  jruoho      *
    329      1.1  jruoho      * Arg1 - Integer:
    330      1.1  jruoho      *  connection status 1 for connecting the handler, 0 for disconnecting
    331      1.1  jruoho      *  the handler (Passed as a parameter)
    332      1.1  jruoho      */
    333      1.1  jruoho     Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
    334      1.1  jruoho     if (!Args[0])
    335      1.1  jruoho     {
    336      1.1  jruoho         Status = AE_NO_MEMORY;
    337      1.1  jruoho         goto Cleanup1;
    338      1.1  jruoho     }
    339      1.1  jruoho 
    340      1.1  jruoho     Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
    341      1.1  jruoho     if (!Args[1])
    342      1.1  jruoho     {
    343      1.1  jruoho         Status = AE_NO_MEMORY;
    344      1.1  jruoho         goto Cleanup2;
    345      1.1  jruoho     }
    346      1.1  jruoho 
    347      1.1  jruoho     Args[2] = NULL; /* Terminate list */
    348      1.1  jruoho 
    349      1.1  jruoho     /* Execute the method, no return value */
    350      1.1  jruoho 
    351      1.1  jruoho     ACPI_DEBUG_EXEC (
    352      1.1  jruoho         AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
    353      1.1  jruoho 
    354      1.1  jruoho     Status = AcpiNsEvaluate (Info);
    355      1.1  jruoho     AcpiUtRemoveReference (Args[1]);
    356      1.1  jruoho 
    357      1.1  jruoho Cleanup2:
    358      1.1  jruoho     AcpiUtRemoveReference (Args[0]);
    359      1.1  jruoho 
    360      1.1  jruoho Cleanup1:
    361      1.1  jruoho     ACPI_FREE (Info);
    362      1.1  jruoho     return_ACPI_STATUS (Status);
    363      1.1  jruoho }
    364      1.1  jruoho 
    365      1.1  jruoho 
    366      1.1  jruoho /*******************************************************************************
    367      1.1  jruoho  *
    368      1.1  jruoho  * FUNCTION:    AcpiEvAddressSpaceDispatch
    369      1.1  jruoho  *
    370      1.1  jruoho  * PARAMETERS:  RegionObj           - Internal region object
    371      1.1  jruoho  *              Function            - Read or Write operation
    372      1.1  jruoho  *              RegionOffset        - Where in the region to read or write
    373      1.1  jruoho  *              BitWidth            - Field width in bits (8, 16, 32, or 64)
    374      1.1  jruoho  *              Value               - Pointer to in or out value, must be
    375      1.1  jruoho  *                                    a full 64-bit integer
    376      1.1  jruoho  *
    377      1.1  jruoho  * RETURN:      Status
    378      1.1  jruoho  *
    379      1.1  jruoho  * DESCRIPTION: Dispatch an address space or operation region access to
    380      1.1  jruoho  *              a previously installed handler.
    381      1.1  jruoho  *
    382      1.1  jruoho  ******************************************************************************/
    383      1.1  jruoho 
    384      1.1  jruoho ACPI_STATUS
    385      1.1  jruoho AcpiEvAddressSpaceDispatch (
    386      1.1  jruoho     ACPI_OPERAND_OBJECT     *RegionObj,
    387      1.1  jruoho     UINT32                  Function,
    388      1.1  jruoho     UINT32                  RegionOffset,
    389      1.1  jruoho     UINT32                  BitWidth,
    390      1.1  jruoho     UINT64                  *Value)
    391      1.1  jruoho {
    392      1.1  jruoho     ACPI_STATUS             Status;
    393      1.1  jruoho     ACPI_ADR_SPACE_HANDLER  Handler;
    394      1.1  jruoho     ACPI_ADR_SPACE_SETUP    RegionSetup;
    395      1.1  jruoho     ACPI_OPERAND_OBJECT     *HandlerDesc;
    396      1.1  jruoho     ACPI_OPERAND_OBJECT     *RegionObj2;
    397      1.1  jruoho     void                    *RegionContext = NULL;
    398      1.1  jruoho 
    399      1.1  jruoho 
    400      1.1  jruoho     ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
    401      1.1  jruoho 
    402      1.1  jruoho 
    403      1.1  jruoho     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
    404      1.1  jruoho     if (!RegionObj2)
    405      1.1  jruoho     {
    406      1.1  jruoho         return_ACPI_STATUS (AE_NOT_EXIST);
    407      1.1  jruoho     }
    408      1.1  jruoho 
    409      1.1  jruoho     /* Ensure that there is a handler associated with this region */
    410      1.1  jruoho 
    411      1.1  jruoho     HandlerDesc = RegionObj->Region.Handler;
    412      1.1  jruoho     if (!HandlerDesc)
    413      1.1  jruoho     {
    414      1.1  jruoho         ACPI_ERROR ((AE_INFO,
    415      1.1  jruoho             "No handler for Region [%4.4s] (%p) [%s]",
    416      1.1  jruoho             AcpiUtGetNodeName (RegionObj->Region.Node),
    417      1.1  jruoho             RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    418      1.1  jruoho 
    419      1.1  jruoho         return_ACPI_STATUS (AE_NOT_EXIST);
    420      1.1  jruoho     }
    421      1.1  jruoho 
    422      1.1  jruoho     /*
    423      1.1  jruoho      * It may be the case that the region has never been initialized.
    424      1.1  jruoho      * Some types of regions require special init code
    425      1.1  jruoho      */
    426      1.1  jruoho     if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
    427      1.1  jruoho     {
    428      1.1  jruoho         /* This region has not been initialized yet, do it */
    429      1.1  jruoho 
    430      1.1  jruoho         RegionSetup = HandlerDesc->AddressSpace.Setup;
    431      1.1  jruoho         if (!RegionSetup)
    432      1.1  jruoho         {
    433      1.1  jruoho             /* No initialization routine, exit with error */
    434      1.1  jruoho 
    435      1.1  jruoho             ACPI_ERROR ((AE_INFO,
    436      1.1  jruoho                 "No init routine for region(%p) [%s]",
    437      1.1  jruoho                 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    438      1.1  jruoho             return_ACPI_STATUS (AE_NOT_EXIST);
    439      1.1  jruoho         }
    440      1.1  jruoho 
    441      1.1  jruoho         /*
    442      1.1  jruoho          * We must exit the interpreter because the region setup will
    443      1.1  jruoho          * potentially execute control methods (for example, the _REG method
    444      1.1  jruoho          * for this region)
    445      1.1  jruoho          */
    446      1.1  jruoho         AcpiExExitInterpreter ();
    447      1.1  jruoho 
    448      1.1  jruoho         Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
    449      1.1  jruoho                     HandlerDesc->AddressSpace.Context, &RegionContext);
    450      1.1  jruoho 
    451      1.1  jruoho         /* Re-enter the interpreter */
    452      1.1  jruoho 
    453      1.1  jruoho         AcpiExEnterInterpreter ();
    454      1.1  jruoho 
    455      1.1  jruoho         /* Check for failure of the Region Setup */
    456      1.1  jruoho 
    457      1.1  jruoho         if (ACPI_FAILURE (Status))
    458      1.1  jruoho         {
    459      1.1  jruoho             ACPI_EXCEPTION ((AE_INFO, Status,
    460      1.1  jruoho                 "During region initialization: [%s]",
    461      1.1  jruoho                 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    462      1.1  jruoho             return_ACPI_STATUS (Status);
    463      1.1  jruoho         }
    464      1.1  jruoho 
    465      1.1  jruoho         /* Region initialization may have been completed by RegionSetup */
    466      1.1  jruoho 
    467      1.1  jruoho         if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
    468      1.1  jruoho         {
    469      1.1  jruoho             RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
    470      1.1  jruoho 
    471      1.1  jruoho             if (RegionObj2->Extra.RegionContext)
    472      1.1  jruoho             {
    473      1.1  jruoho                 /* The handler for this region was already installed */
    474      1.1  jruoho 
    475      1.1  jruoho                 ACPI_FREE (RegionContext);
    476      1.1  jruoho             }
    477      1.1  jruoho             else
    478      1.1  jruoho             {
    479      1.1  jruoho                 /*
    480      1.1  jruoho                  * Save the returned context for use in all accesses to
    481      1.1  jruoho                  * this particular region
    482      1.1  jruoho                  */
    483      1.1  jruoho                 RegionObj2->Extra.RegionContext = RegionContext;
    484      1.1  jruoho             }
    485      1.1  jruoho         }
    486      1.1  jruoho     }
    487      1.1  jruoho 
    488      1.1  jruoho     /* We have everything we need, we can invoke the address space handler */
    489      1.1  jruoho 
    490      1.1  jruoho     Handler = HandlerDesc->AddressSpace.Handler;
    491      1.1  jruoho 
    492      1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    493      1.1  jruoho         "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
    494      1.1  jruoho         &RegionObj->Region.Handler->AddressSpace, Handler,
    495      1.1  jruoho         ACPI_FORMAT_NATIVE_UINT (RegionObj->Region.Address + RegionOffset),
    496      1.1  jruoho         AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    497      1.1  jruoho 
    498      1.1  jruoho     if (!(HandlerDesc->AddressSpace.HandlerFlags &
    499      1.1  jruoho             ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
    500      1.1  jruoho     {
    501      1.1  jruoho         /*
    502      1.1  jruoho          * For handlers other than the default (supplied) handlers, we must
    503      1.1  jruoho          * exit the interpreter because the handler *might* block -- we don't
    504      1.1  jruoho          * know what it will do, so we can't hold the lock on the intepreter.
    505      1.1  jruoho          */
    506      1.1  jruoho         AcpiExExitInterpreter();
    507      1.1  jruoho     }
    508      1.1  jruoho 
    509      1.1  jruoho     /* Call the handler */
    510      1.1  jruoho 
    511      1.1  jruoho     Status = Handler (Function,
    512      1.1  jruoho         (RegionObj->Region.Address + RegionOffset), BitWidth, Value,
    513      1.1  jruoho         HandlerDesc->AddressSpace.Context, RegionObj2->Extra.RegionContext);
    514      1.1  jruoho 
    515      1.1  jruoho     if (ACPI_FAILURE (Status))
    516      1.1  jruoho     {
    517      1.1  jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
    518      1.1  jruoho             AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    519      1.1  jruoho     }
    520      1.1  jruoho 
    521      1.1  jruoho     if (!(HandlerDesc->AddressSpace.HandlerFlags &
    522      1.1  jruoho             ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
    523      1.1  jruoho     {
    524      1.1  jruoho         /*
    525      1.1  jruoho          * We just returned from a non-default handler, we must re-enter the
    526      1.1  jruoho          * interpreter
    527      1.1  jruoho          */
    528      1.1  jruoho        AcpiExEnterInterpreter ();
    529      1.1  jruoho     }
    530      1.1  jruoho 
    531      1.1  jruoho     return_ACPI_STATUS (Status);
    532      1.1  jruoho }
    533      1.1  jruoho 
    534      1.1  jruoho 
    535      1.1  jruoho /*******************************************************************************
    536      1.1  jruoho  *
    537      1.1  jruoho  * FUNCTION:    AcpiEvDetachRegion
    538      1.1  jruoho  *
    539      1.1  jruoho  * PARAMETERS:  RegionObj           - Region Object
    540      1.1  jruoho  *              AcpiNsIsLocked      - Namespace Region Already Locked?
    541      1.1  jruoho  *
    542      1.1  jruoho  * RETURN:      None
    543      1.1  jruoho  *
    544      1.1  jruoho  * DESCRIPTION: Break the association between the handler and the region
    545      1.1  jruoho  *              this is a two way association.
    546      1.1  jruoho  *
    547      1.1  jruoho  ******************************************************************************/
    548      1.1  jruoho 
    549      1.1  jruoho void
    550      1.1  jruoho AcpiEvDetachRegion(
    551      1.1  jruoho     ACPI_OPERAND_OBJECT     *RegionObj,
    552      1.1  jruoho     BOOLEAN                 AcpiNsIsLocked)
    553      1.1  jruoho {
    554      1.1  jruoho     ACPI_OPERAND_OBJECT     *HandlerObj;
    555      1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    556      1.1  jruoho     ACPI_OPERAND_OBJECT     **LastObjPtr;
    557      1.1  jruoho     ACPI_ADR_SPACE_SETUP    RegionSetup;
    558      1.1  jruoho     void                    **RegionContext;
    559      1.1  jruoho     ACPI_OPERAND_OBJECT     *RegionObj2;
    560      1.1  jruoho     ACPI_STATUS             Status;
    561      1.1  jruoho 
    562      1.1  jruoho 
    563      1.1  jruoho     ACPI_FUNCTION_TRACE (EvDetachRegion);
    564      1.1  jruoho 
    565      1.1  jruoho 
    566      1.1  jruoho     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
    567      1.1  jruoho     if (!RegionObj2)
    568      1.1  jruoho     {
    569      1.1  jruoho         return_VOID;
    570      1.1  jruoho     }
    571      1.1  jruoho     RegionContext = &RegionObj2->Extra.RegionContext;
    572      1.1  jruoho 
    573      1.1  jruoho     /* Get the address handler from the region object */
    574      1.1  jruoho 
    575      1.1  jruoho     HandlerObj = RegionObj->Region.Handler;
    576      1.1  jruoho     if (!HandlerObj)
    577      1.1  jruoho     {
    578      1.1  jruoho         /* This region has no handler, all done */
    579      1.1  jruoho 
    580      1.1  jruoho         return_VOID;
    581      1.1  jruoho     }
    582      1.1  jruoho 
    583      1.1  jruoho     /* Find this region in the handler's list */
    584      1.1  jruoho 
    585      1.1  jruoho     ObjDesc = HandlerObj->AddressSpace.RegionList;
    586      1.1  jruoho     LastObjPtr = &HandlerObj->AddressSpace.RegionList;
    587      1.1  jruoho 
    588      1.1  jruoho     while (ObjDesc)
    589      1.1  jruoho     {
    590      1.1  jruoho         /* Is this the correct Region? */
    591      1.1  jruoho 
    592      1.1  jruoho         if (ObjDesc == RegionObj)
    593      1.1  jruoho         {
    594      1.1  jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    595      1.1  jruoho                 "Removing Region %p from address handler %p\n",
    596      1.1  jruoho                 RegionObj, HandlerObj));
    597      1.1  jruoho 
    598      1.1  jruoho             /* This is it, remove it from the handler's list */
    599      1.1  jruoho 
    600      1.1  jruoho             *LastObjPtr = ObjDesc->Region.Next;
    601      1.1  jruoho             ObjDesc->Region.Next = NULL;        /* Must clear field */
    602      1.1  jruoho 
    603      1.1  jruoho             if (AcpiNsIsLocked)
    604      1.1  jruoho             {
    605      1.1  jruoho                 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    606      1.1  jruoho                 if (ACPI_FAILURE (Status))
    607      1.1  jruoho                 {
    608      1.1  jruoho                     return_VOID;
    609      1.1  jruoho                 }
    610      1.1  jruoho             }
    611      1.1  jruoho 
    612      1.1  jruoho             /* Now stop region accesses by executing the _REG method */
    613      1.1  jruoho 
    614      1.1  jruoho             Status = AcpiEvExecuteRegMethod (RegionObj, 0);
    615      1.1  jruoho             if (ACPI_FAILURE (Status))
    616      1.1  jruoho             {
    617      1.1  jruoho                 ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
    618      1.1  jruoho                     AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    619      1.1  jruoho             }
    620      1.1  jruoho 
    621      1.1  jruoho             if (AcpiNsIsLocked)
    622      1.1  jruoho             {
    623      1.1  jruoho                 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    624      1.1  jruoho                 if (ACPI_FAILURE (Status))
    625      1.1  jruoho                 {
    626      1.1  jruoho                     return_VOID;
    627      1.1  jruoho                 }
    628      1.1  jruoho             }
    629      1.1  jruoho 
    630      1.1  jruoho             /*
    631      1.1  jruoho              * If the region has been activated, call the setup handler with
    632      1.1  jruoho              * the deactivate notification
    633      1.1  jruoho              */
    634      1.1  jruoho             if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
    635      1.1  jruoho             {
    636      1.1  jruoho                 RegionSetup = HandlerObj->AddressSpace.Setup;
    637      1.1  jruoho                 Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
    638      1.1  jruoho                     HandlerObj->AddressSpace.Context, RegionContext);
    639      1.1  jruoho 
    640      1.1  jruoho                 /* Init routine may fail, Just ignore errors */
    641      1.1  jruoho 
    642      1.1  jruoho                 if (ACPI_FAILURE (Status))
    643      1.1  jruoho                 {
    644      1.1  jruoho                     ACPI_EXCEPTION ((AE_INFO, Status,
    645      1.1  jruoho                         "from region handler - deactivate, [%s]",
    646      1.1  jruoho                         AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    647      1.1  jruoho                 }
    648      1.1  jruoho 
    649      1.1  jruoho                 RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
    650      1.1  jruoho             }
    651      1.1  jruoho 
    652      1.1  jruoho             /*
    653      1.1  jruoho              * Remove handler reference in the region
    654      1.1  jruoho              *
    655      1.1  jruoho              * NOTE: this doesn't mean that the region goes away, the region
    656      1.1  jruoho              * is just inaccessible as indicated to the _REG method
    657      1.1  jruoho              *
    658      1.1  jruoho              * If the region is on the handler's list, this must be the
    659      1.1  jruoho              * region's handler
    660      1.1  jruoho              */
    661      1.1  jruoho             RegionObj->Region.Handler = NULL;
    662      1.1  jruoho             AcpiUtRemoveReference (HandlerObj);
    663      1.1  jruoho 
    664      1.1  jruoho             return_VOID;
    665      1.1  jruoho         }
    666      1.1  jruoho 
    667      1.1  jruoho         /* Walk the linked list of handlers */
    668      1.1  jruoho 
    669      1.1  jruoho         LastObjPtr = &ObjDesc->Region.Next;
    670      1.1  jruoho         ObjDesc = ObjDesc->Region.Next;
    671      1.1  jruoho     }
    672      1.1  jruoho 
    673      1.1  jruoho     /* If we get here, the region was not in the handler's region list */
    674      1.1  jruoho 
    675      1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    676      1.1  jruoho         "Cannot remove region %p from address handler %p\n",
    677      1.1  jruoho         RegionObj, HandlerObj));
    678      1.1  jruoho 
    679      1.1  jruoho     return_VOID;
    680      1.1  jruoho }
    681      1.1  jruoho 
    682      1.1  jruoho 
    683      1.1  jruoho /*******************************************************************************
    684      1.1  jruoho  *
    685      1.1  jruoho  * FUNCTION:    AcpiEvAttachRegion
    686      1.1  jruoho  *
    687      1.1  jruoho  * PARAMETERS:  HandlerObj          - Handler Object
    688      1.1  jruoho  *              RegionObj           - Region Object
    689      1.1  jruoho  *              AcpiNsIsLocked      - Namespace Region Already Locked?
    690      1.1  jruoho  *
    691      1.1  jruoho  * RETURN:      None
    692      1.1  jruoho  *
    693      1.1  jruoho  * DESCRIPTION: Create the association between the handler and the region
    694      1.1  jruoho  *              this is a two way association.
    695      1.1  jruoho  *
    696      1.1  jruoho  ******************************************************************************/
    697      1.1  jruoho 
    698      1.1  jruoho ACPI_STATUS
    699      1.1  jruoho AcpiEvAttachRegion (
    700      1.1  jruoho     ACPI_OPERAND_OBJECT     *HandlerObj,
    701      1.1  jruoho     ACPI_OPERAND_OBJECT     *RegionObj,
    702      1.1  jruoho     BOOLEAN                 AcpiNsIsLocked)
    703      1.1  jruoho {
    704      1.1  jruoho 
    705      1.1  jruoho     ACPI_FUNCTION_TRACE (EvAttachRegion);
    706      1.1  jruoho 
    707      1.1  jruoho 
    708      1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    709      1.1  jruoho         "Adding Region [%4.4s] %p to address handler %p [%s]\n",
    710      1.1  jruoho         AcpiUtGetNodeName (RegionObj->Region.Node),
    711      1.1  jruoho         RegionObj, HandlerObj,
    712      1.1  jruoho         AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    713      1.1  jruoho 
    714      1.1  jruoho     /* Link this region to the front of the handler's list */
    715      1.1  jruoho 
    716      1.1  jruoho     RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
    717      1.1  jruoho     HandlerObj->AddressSpace.RegionList = RegionObj;
    718      1.1  jruoho 
    719      1.1  jruoho     /* Install the region's handler */
    720      1.1  jruoho 
    721      1.1  jruoho     if (RegionObj->Region.Handler)
    722      1.1  jruoho     {
    723      1.1  jruoho         return_ACPI_STATUS (AE_ALREADY_EXISTS);
    724      1.1  jruoho     }
    725      1.1  jruoho 
    726      1.1  jruoho     RegionObj->Region.Handler = HandlerObj;
    727      1.1  jruoho     AcpiUtAddReference (HandlerObj);
    728      1.1  jruoho 
    729      1.1  jruoho     return_ACPI_STATUS (AE_OK);
    730      1.1  jruoho }
    731      1.1  jruoho 
    732      1.1  jruoho 
    733      1.1  jruoho /*******************************************************************************
    734      1.1  jruoho  *
    735      1.1  jruoho  * FUNCTION:    AcpiEvInstallHandler
    736      1.1  jruoho  *
    737      1.1  jruoho  * PARAMETERS:  WalkNamespace callback
    738      1.1  jruoho  *
    739      1.1  jruoho  * DESCRIPTION: This routine installs an address handler into objects that are
    740      1.1  jruoho  *              of type Region or Device.
    741      1.1  jruoho  *
    742      1.1  jruoho  *              If the Object is a Device, and the device has a handler of
    743      1.1  jruoho  *              the same type then the search is terminated in that branch.
    744      1.1  jruoho  *
    745      1.1  jruoho  *              This is because the existing handler is closer in proximity
    746      1.1  jruoho  *              to any more regions than the one we are trying to install.
    747      1.1  jruoho  *
    748      1.1  jruoho  ******************************************************************************/
    749      1.1  jruoho 
    750      1.1  jruoho static ACPI_STATUS
    751      1.1  jruoho AcpiEvInstallHandler (
    752      1.1  jruoho     ACPI_HANDLE             ObjHandle,
    753      1.1  jruoho     UINT32                  Level,
    754      1.1  jruoho     void                    *Context,
    755      1.1  jruoho     void                    **ReturnValue)
    756      1.1  jruoho {
    757      1.1  jruoho     ACPI_OPERAND_OBJECT     *HandlerObj;
    758      1.1  jruoho     ACPI_OPERAND_OBJECT     *NextHandlerObj;
    759      1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    760      1.1  jruoho     ACPI_NAMESPACE_NODE     *Node;
    761      1.1  jruoho     ACPI_STATUS             Status;
    762      1.1  jruoho 
    763      1.1  jruoho 
    764      1.1  jruoho     ACPI_FUNCTION_NAME (EvInstallHandler);
    765      1.1  jruoho 
    766      1.1  jruoho 
    767      1.1  jruoho     HandlerObj = (ACPI_OPERAND_OBJECT  *) Context;
    768      1.1  jruoho 
    769      1.1  jruoho     /* Parameter validation */
    770      1.1  jruoho 
    771      1.1  jruoho     if (!HandlerObj)
    772      1.1  jruoho     {
    773      1.1  jruoho         return (AE_OK);
    774      1.1  jruoho     }
    775      1.1  jruoho 
    776      1.1  jruoho     /* Convert and validate the device handle */
    777      1.1  jruoho 
    778      1.1  jruoho     Node = AcpiNsValidateHandle (ObjHandle);
    779      1.1  jruoho     if (!Node)
    780      1.1  jruoho     {
    781      1.1  jruoho         return (AE_BAD_PARAMETER);
    782      1.1  jruoho     }
    783      1.1  jruoho 
    784      1.1  jruoho     /*
    785      1.1  jruoho      * We only care about regions and objects that are allowed to have
    786      1.1  jruoho      * address space handlers
    787      1.1  jruoho      */
    788      1.1  jruoho     if ((Node->Type != ACPI_TYPE_DEVICE) &&
    789      1.1  jruoho         (Node->Type != ACPI_TYPE_REGION) &&
    790      1.1  jruoho         (Node != AcpiGbl_RootNode))
    791      1.1  jruoho     {
    792      1.1  jruoho         return (AE_OK);
    793      1.1  jruoho     }
    794      1.1  jruoho 
    795      1.1  jruoho     /* Check for an existing internal object */
    796      1.1  jruoho 
    797      1.1  jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
    798      1.1  jruoho     if (!ObjDesc)
    799      1.1  jruoho     {
    800      1.1  jruoho         /* No object, just exit */
    801      1.1  jruoho 
    802      1.1  jruoho         return (AE_OK);
    803      1.1  jruoho     }
    804      1.1  jruoho 
    805      1.1  jruoho     /* Devices are handled different than regions */
    806      1.1  jruoho 
    807      1.1  jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
    808      1.1  jruoho     {
    809      1.1  jruoho         /* Check if this Device already has a handler for this address space */
    810      1.1  jruoho 
    811      1.1  jruoho         NextHandlerObj = ObjDesc->Device.Handler;
    812      1.1  jruoho         while (NextHandlerObj)
    813      1.1  jruoho         {
    814      1.1  jruoho             /* Found a handler, is it for the same address space? */
    815      1.1  jruoho 
    816      1.1  jruoho             if (NextHandlerObj->AddressSpace.SpaceId ==
    817      1.1  jruoho                     HandlerObj->AddressSpace.SpaceId)
    818      1.1  jruoho             {
    819      1.1  jruoho                 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    820      1.1  jruoho                     "Found handler for region [%s] in device %p(%p) "
    821      1.1  jruoho                     "handler %p\n",
    822      1.1  jruoho                     AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
    823      1.1  jruoho                     ObjDesc, NextHandlerObj, HandlerObj));
    824      1.1  jruoho 
    825      1.1  jruoho                 /*
    826      1.1  jruoho                  * Since the object we found it on was a device, then it
    827      1.1  jruoho                  * means that someone has already installed a handler for
    828      1.1  jruoho                  * the branch of the namespace from this device on. Just
    829      1.1  jruoho                  * bail out telling the walk routine to not traverse this
    830      1.1  jruoho                  * branch. This preserves the scoping rule for handlers.
    831      1.1  jruoho                  */
    832      1.1  jruoho                 return (AE_CTRL_DEPTH);
    833      1.1  jruoho             }
    834      1.1  jruoho 
    835      1.1  jruoho             /* Walk the linked list of handlers attached to this device */
    836      1.1  jruoho 
    837      1.1  jruoho             NextHandlerObj = NextHandlerObj->AddressSpace.Next;
    838      1.1  jruoho         }
    839      1.1  jruoho 
    840      1.1  jruoho         /*
    841      1.1  jruoho          * As long as the device didn't have a handler for this space we
    842      1.1  jruoho          * don't care about it. We just ignore it and proceed.
    843      1.1  jruoho          */
    844      1.1  jruoho         return (AE_OK);
    845      1.1  jruoho     }
    846      1.1  jruoho 
    847      1.1  jruoho     /* Object is a Region */
    848      1.1  jruoho 
    849      1.1  jruoho     if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
    850      1.1  jruoho     {
    851      1.1  jruoho         /* This region is for a different address space, just ignore it */
    852      1.1  jruoho 
    853      1.1  jruoho         return (AE_OK);
    854      1.1  jruoho     }
    855      1.1  jruoho 
    856      1.1  jruoho     /*
    857      1.1  jruoho      * Now we have a region and it is for the handler's address space type.
    858      1.1  jruoho      *
    859      1.1  jruoho      * First disconnect region for any previous handler (if any)
    860      1.1  jruoho      */
    861      1.1  jruoho     AcpiEvDetachRegion (ObjDesc, FALSE);
    862      1.1  jruoho 
    863      1.1  jruoho     /* Connect the region to the new handler */
    864      1.1  jruoho 
    865      1.1  jruoho     Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
    866      1.1  jruoho     return (Status);
    867      1.1  jruoho }
    868      1.1  jruoho 
    869      1.1  jruoho 
    870      1.1  jruoho /*******************************************************************************
    871      1.1  jruoho  *
    872      1.1  jruoho  * FUNCTION:    AcpiEvInstallSpaceHandler
    873      1.1  jruoho  *
    874      1.1  jruoho  * PARAMETERS:  Node            - Namespace node for the device
    875      1.1  jruoho  *              SpaceId         - The address space ID
    876      1.1  jruoho  *              Handler         - Address of the handler
    877      1.1  jruoho  *              Setup           - Address of the setup function
    878      1.1  jruoho  *              Context         - Value passed to the handler on each access
    879      1.1  jruoho  *
    880      1.1  jruoho  * RETURN:      Status
    881      1.1  jruoho  *
    882      1.1  jruoho  * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
    883      1.1  jruoho  *              Assumes namespace is locked
    884      1.1  jruoho  *
    885      1.1  jruoho  ******************************************************************************/
    886      1.1  jruoho 
    887      1.1  jruoho ACPI_STATUS
    888      1.1  jruoho AcpiEvInstallSpaceHandler (
    889      1.1  jruoho     ACPI_NAMESPACE_NODE     *Node,
    890      1.1  jruoho     ACPI_ADR_SPACE_TYPE     SpaceId,
    891      1.1  jruoho     ACPI_ADR_SPACE_HANDLER  Handler,
    892      1.1  jruoho     ACPI_ADR_SPACE_SETUP    Setup,
    893      1.1  jruoho     void                    *Context)
    894      1.1  jruoho {
    895      1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    896      1.1  jruoho     ACPI_OPERAND_OBJECT     *HandlerObj;
    897      1.1  jruoho     ACPI_STATUS             Status;
    898      1.1  jruoho     ACPI_OBJECT_TYPE        Type;
    899      1.1  jruoho     UINT8                  Flags = 0;
    900      1.1  jruoho 
    901      1.1  jruoho 
    902      1.1  jruoho     ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
    903      1.1  jruoho 
    904      1.1  jruoho 
    905      1.1  jruoho     /*
    906      1.1  jruoho      * This registration is valid for only the types below and the root. This
    907      1.1  jruoho      * is where the default handlers get placed.
    908      1.1  jruoho      */
    909      1.1  jruoho     if ((Node->Type != ACPI_TYPE_DEVICE)     &&
    910      1.1  jruoho         (Node->Type != ACPI_TYPE_PROCESSOR)  &&
    911      1.1  jruoho         (Node->Type != ACPI_TYPE_THERMAL)    &&
    912      1.1  jruoho         (Node != AcpiGbl_RootNode))
    913      1.1  jruoho     {
    914      1.1  jruoho         Status = AE_BAD_PARAMETER;
    915      1.1  jruoho         goto UnlockAndExit;
    916      1.1  jruoho     }
    917      1.1  jruoho 
    918      1.1  jruoho     if (Handler == ACPI_DEFAULT_HANDLER)
    919      1.1  jruoho     {
    920      1.1  jruoho         Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
    921      1.1  jruoho 
    922      1.1  jruoho         switch (SpaceId)
    923      1.1  jruoho         {
    924      1.1  jruoho         case ACPI_ADR_SPACE_SYSTEM_MEMORY:
    925      1.1  jruoho             Handler = AcpiExSystemMemorySpaceHandler;
    926      1.1  jruoho             Setup   = AcpiEvSystemMemoryRegionSetup;
    927      1.1  jruoho             break;
    928      1.1  jruoho 
    929      1.1  jruoho         case ACPI_ADR_SPACE_SYSTEM_IO:
    930      1.1  jruoho             Handler = AcpiExSystemIoSpaceHandler;
    931      1.1  jruoho             Setup   = AcpiEvIoSpaceRegionSetup;
    932      1.1  jruoho             break;
    933      1.1  jruoho 
    934      1.1  jruoho         case ACPI_ADR_SPACE_PCI_CONFIG:
    935      1.1  jruoho             Handler = AcpiExPciConfigSpaceHandler;
    936      1.1  jruoho             Setup   = AcpiEvPciConfigRegionSetup;
    937      1.1  jruoho             break;
    938      1.1  jruoho 
    939      1.1  jruoho         case ACPI_ADR_SPACE_CMOS:
    940      1.1  jruoho             Handler = AcpiExCmosSpaceHandler;
    941      1.1  jruoho             Setup   = AcpiEvCmosRegionSetup;
    942      1.1  jruoho             break;
    943      1.1  jruoho 
    944      1.1  jruoho         case ACPI_ADR_SPACE_PCI_BAR_TARGET:
    945      1.1  jruoho             Handler = AcpiExPciBarSpaceHandler;
    946      1.1  jruoho             Setup   = AcpiEvPciBarRegionSetup;
    947      1.1  jruoho             break;
    948      1.1  jruoho 
    949      1.1  jruoho         case ACPI_ADR_SPACE_DATA_TABLE:
    950      1.1  jruoho             Handler = AcpiExDataTableSpaceHandler;
    951      1.1  jruoho             Setup   = NULL;
    952      1.1  jruoho             break;
    953      1.1  jruoho 
    954      1.1  jruoho         default:
    955      1.1  jruoho             Status = AE_BAD_PARAMETER;
    956      1.1  jruoho             goto UnlockAndExit;
    957      1.1  jruoho         }
    958      1.1  jruoho     }
    959      1.1  jruoho 
    960      1.1  jruoho     /* If the caller hasn't specified a setup routine, use the default */
    961      1.1  jruoho 
    962      1.1  jruoho     if (!Setup)
    963      1.1  jruoho     {
    964      1.1  jruoho         Setup = AcpiEvDefaultRegionSetup;
    965      1.1  jruoho     }
    966      1.1  jruoho 
    967      1.1  jruoho     /* Check for an existing internal object */
    968      1.1  jruoho 
    969      1.1  jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
    970      1.1  jruoho     if (ObjDesc)
    971      1.1  jruoho     {
    972      1.1  jruoho         /*
    973      1.1  jruoho          * The attached device object already exists. Make sure the handler
    974      1.1  jruoho          * is not already installed.
    975      1.1  jruoho          */
    976      1.1  jruoho         HandlerObj = ObjDesc->Device.Handler;
    977      1.1  jruoho 
    978      1.1  jruoho         /* Walk the handler list for this device */
    979      1.1  jruoho 
    980      1.1  jruoho         while (HandlerObj)
    981      1.1  jruoho         {
    982      1.1  jruoho             /* Same SpaceId indicates a handler already installed */
    983      1.1  jruoho 
    984      1.1  jruoho             if (HandlerObj->AddressSpace.SpaceId == SpaceId)
    985      1.1  jruoho             {
    986      1.1  jruoho                 if (HandlerObj->AddressSpace.Handler == Handler)
    987      1.1  jruoho                 {
    988      1.1  jruoho                     /*
    989      1.1  jruoho                      * It is (relatively) OK to attempt to install the SAME
    990      1.1  jruoho                      * handler twice. This can easily happen with the
    991      1.1  jruoho                      * PCI_Config space.
    992      1.1  jruoho                      */
    993      1.1  jruoho                     Status = AE_SAME_HANDLER;
    994      1.1  jruoho                     goto UnlockAndExit;
    995      1.1  jruoho                 }
    996      1.1  jruoho                 else
    997      1.1  jruoho                 {
    998      1.1  jruoho                     /* A handler is already installed */
    999      1.1  jruoho 
   1000      1.1  jruoho                     Status = AE_ALREADY_EXISTS;
   1001      1.1  jruoho                 }
   1002      1.1  jruoho                 goto UnlockAndExit;
   1003      1.1  jruoho             }
   1004      1.1  jruoho 
   1005      1.1  jruoho             /* Walk the linked list of handlers */
   1006      1.1  jruoho 
   1007      1.1  jruoho             HandlerObj = HandlerObj->AddressSpace.Next;
   1008      1.1  jruoho         }
   1009      1.1  jruoho     }
   1010      1.1  jruoho     else
   1011      1.1  jruoho     {
   1012      1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
   1013      1.1  jruoho             "Creating object on Device %p while installing handler\n", Node));
   1014      1.1  jruoho 
   1015      1.1  jruoho         /* ObjDesc does not exist, create one */
   1016      1.1  jruoho 
   1017      1.1  jruoho         if (Node->Type == ACPI_TYPE_ANY)
   1018      1.1  jruoho         {
   1019      1.1  jruoho             Type = ACPI_TYPE_DEVICE;
   1020      1.1  jruoho         }
   1021      1.1  jruoho         else
   1022      1.1  jruoho         {
   1023      1.1  jruoho             Type = Node->Type;
   1024      1.1  jruoho         }
   1025      1.1  jruoho 
   1026      1.1  jruoho         ObjDesc = AcpiUtCreateInternalObject (Type);
   1027      1.1  jruoho         if (!ObjDesc)
   1028      1.1  jruoho         {
   1029      1.1  jruoho             Status = AE_NO_MEMORY;
   1030      1.1  jruoho             goto UnlockAndExit;
   1031      1.1  jruoho         }
   1032      1.1  jruoho 
   1033      1.1  jruoho         /* Init new descriptor */
   1034      1.1  jruoho 
   1035      1.1  jruoho         ObjDesc->Common.Type = (UINT8) Type;
   1036      1.1  jruoho 
   1037      1.1  jruoho         /* Attach the new object to the Node */
   1038      1.1  jruoho 
   1039      1.1  jruoho         Status = AcpiNsAttachObject (Node, ObjDesc, Type);
   1040      1.1  jruoho 
   1041      1.1  jruoho         /* Remove local reference to the object */
   1042      1.1  jruoho 
   1043      1.1  jruoho         AcpiUtRemoveReference (ObjDesc);
   1044      1.1  jruoho 
   1045      1.1  jruoho         if (ACPI_FAILURE (Status))
   1046      1.1  jruoho         {
   1047      1.1  jruoho             goto UnlockAndExit;
   1048      1.1  jruoho         }
   1049      1.1  jruoho     }
   1050      1.1  jruoho 
   1051      1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
   1052      1.1  jruoho         "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
   1053      1.1  jruoho         AcpiUtGetRegionName (SpaceId), SpaceId,
   1054      1.1  jruoho         AcpiUtGetNodeName (Node), Node, ObjDesc));
   1055      1.1  jruoho 
   1056      1.1  jruoho     /*
   1057      1.1  jruoho      * Install the handler
   1058      1.1  jruoho      *
   1059      1.1  jruoho      * At this point there is no existing handler. Just allocate the object
   1060      1.1  jruoho      * for the handler and link it into the list.
   1061      1.1  jruoho      */
   1062      1.1  jruoho     HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
   1063      1.1  jruoho     if (!HandlerObj)
   1064      1.1  jruoho     {
   1065      1.1  jruoho         Status = AE_NO_MEMORY;
   1066      1.1  jruoho         goto UnlockAndExit;
   1067      1.1  jruoho     }
   1068      1.1  jruoho 
   1069      1.1  jruoho     /* Init handler obj */
   1070      1.1  jruoho 
   1071      1.1  jruoho     HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
   1072      1.1  jruoho     HandlerObj->AddressSpace.HandlerFlags = Flags;
   1073      1.1  jruoho     HandlerObj->AddressSpace.RegionList = NULL;
   1074      1.1  jruoho     HandlerObj->AddressSpace.Node = Node;
   1075      1.1  jruoho     HandlerObj->AddressSpace.Handler = Handler;
   1076      1.1  jruoho     HandlerObj->AddressSpace.Context = Context;
   1077      1.1  jruoho     HandlerObj->AddressSpace.Setup  = Setup;
   1078      1.1  jruoho 
   1079      1.1  jruoho     /* Install at head of Device.AddressSpace list */
   1080      1.1  jruoho 
   1081      1.1  jruoho     HandlerObj->AddressSpace.Next = ObjDesc->Device.Handler;
   1082      1.1  jruoho 
   1083      1.1  jruoho     /*
   1084      1.1  jruoho      * The Device object is the first reference on the HandlerObj.
   1085      1.1  jruoho      * Each region that uses the handler adds a reference.
   1086      1.1  jruoho      */
   1087      1.1  jruoho     ObjDesc->Device.Handler = HandlerObj;
   1088      1.1  jruoho 
   1089      1.1  jruoho     /*
   1090      1.1  jruoho      * Walk the namespace finding all of the regions this
   1091      1.1  jruoho      * handler will manage.
   1092      1.1  jruoho      *
   1093      1.1  jruoho      * Start at the device and search the branch toward
   1094      1.1  jruoho      * the leaf nodes until either the leaf is encountered or
   1095      1.1  jruoho      * a device is detected that has an address handler of the
   1096      1.1  jruoho      * same type.
   1097      1.1  jruoho      *
   1098      1.1  jruoho      * In either case, back up and search down the remainder
   1099      1.1  jruoho      * of the branch
   1100      1.1  jruoho      */
   1101      1.1  jruoho     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
   1102      1.1  jruoho                 ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler, NULL,
   1103      1.1  jruoho                 HandlerObj, NULL);
   1104      1.1  jruoho 
   1105      1.1  jruoho UnlockAndExit:
   1106      1.1  jruoho     return_ACPI_STATUS (Status);
   1107      1.1  jruoho }
   1108      1.1  jruoho 
   1109      1.1  jruoho 
   1110      1.1  jruoho /*******************************************************************************
   1111      1.1  jruoho  *
   1112      1.1  jruoho  * FUNCTION:    AcpiEvExecuteRegMethods
   1113      1.1  jruoho  *
   1114      1.1  jruoho  * PARAMETERS:  Node            - Namespace node for the device
   1115      1.1  jruoho  *              SpaceId         - The address space ID
   1116      1.1  jruoho  *
   1117      1.1  jruoho  * RETURN:      Status
   1118      1.1  jruoho  *
   1119      1.1  jruoho  * DESCRIPTION: Run all _REG methods for the input Space ID;
   1120      1.1  jruoho  *              Note: assumes namespace is locked, or system init time.
   1121      1.1  jruoho  *
   1122      1.1  jruoho  ******************************************************************************/
   1123      1.1  jruoho 
   1124      1.1  jruoho ACPI_STATUS
   1125      1.1  jruoho AcpiEvExecuteRegMethods (
   1126      1.1  jruoho     ACPI_NAMESPACE_NODE     *Node,
   1127      1.1  jruoho     ACPI_ADR_SPACE_TYPE     SpaceId)
   1128      1.1  jruoho {
   1129      1.1  jruoho     ACPI_STATUS             Status;
   1130      1.1  jruoho 
   1131      1.1  jruoho 
   1132      1.1  jruoho     ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
   1133      1.1  jruoho 
   1134      1.1  jruoho 
   1135      1.1  jruoho     /*
   1136      1.1  jruoho      * Run all _REG methods for all Operation Regions for this space ID. This
   1137      1.1  jruoho      * is a separate walk in order to handle any interdependencies between
   1138      1.1  jruoho      * regions and _REG methods. (i.e. handlers must be installed for all
   1139      1.1  jruoho      * regions of this Space ID before we can run any _REG methods)
   1140      1.1  jruoho      */
   1141      1.1  jruoho     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
   1142      1.1  jruoho                 ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL,
   1143      1.1  jruoho                 &SpaceId, NULL);
   1144      1.1  jruoho 
   1145      1.1  jruoho     return_ACPI_STATUS (Status);
   1146      1.1  jruoho }
   1147      1.1  jruoho 
   1148      1.1  jruoho 
   1149      1.1  jruoho /*******************************************************************************
   1150      1.1  jruoho  *
   1151      1.1  jruoho  * FUNCTION:    AcpiEvRegRun
   1152      1.1  jruoho  *
   1153      1.1  jruoho  * PARAMETERS:  WalkNamespace callback
   1154      1.1  jruoho  *
   1155      1.1  jruoho  * DESCRIPTION: Run _REG method for region objects of the requested spaceID
   1156      1.1  jruoho  *
   1157      1.1  jruoho  ******************************************************************************/
   1158      1.1  jruoho 
   1159      1.1  jruoho static ACPI_STATUS
   1160      1.1  jruoho AcpiEvRegRun (
   1161      1.1  jruoho     ACPI_HANDLE             ObjHandle,
   1162      1.1  jruoho     UINT32                  Level,
   1163      1.1  jruoho     void                    *Context,
   1164      1.1  jruoho     void                    **ReturnValue)
   1165      1.1  jruoho {
   1166      1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
   1167      1.1  jruoho     ACPI_NAMESPACE_NODE     *Node;
   1168      1.1  jruoho     ACPI_ADR_SPACE_TYPE     SpaceId;
   1169      1.1  jruoho     ACPI_STATUS             Status;
   1170      1.1  jruoho 
   1171      1.1  jruoho 
   1172      1.1  jruoho     SpaceId = *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE, Context);
   1173      1.1  jruoho 
   1174      1.1  jruoho     /* Convert and validate the device handle */
   1175      1.1  jruoho 
   1176      1.1  jruoho     Node = AcpiNsValidateHandle (ObjHandle);
   1177      1.1  jruoho     if (!Node)
   1178      1.1  jruoho     {
   1179      1.1  jruoho         return (AE_BAD_PARAMETER);
   1180      1.1  jruoho     }
   1181      1.1  jruoho 
   1182      1.1  jruoho     /*
   1183      1.1  jruoho      * We only care about regions.and objects that are allowed to have address
   1184      1.1  jruoho      * space handlers
   1185      1.1  jruoho      */
   1186      1.1  jruoho     if ((Node->Type != ACPI_TYPE_REGION) &&
   1187      1.1  jruoho         (Node != AcpiGbl_RootNode))
   1188      1.1  jruoho     {
   1189      1.1  jruoho         return (AE_OK);
   1190      1.1  jruoho     }
   1191      1.1  jruoho 
   1192      1.1  jruoho     /* Check for an existing internal object */
   1193      1.1  jruoho 
   1194      1.1  jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
   1195      1.1  jruoho     if (!ObjDesc)
   1196      1.1  jruoho     {
   1197      1.1  jruoho         /* No object, just exit */
   1198      1.1  jruoho 
   1199      1.1  jruoho         return (AE_OK);
   1200      1.1  jruoho     }
   1201      1.1  jruoho 
   1202      1.1  jruoho     /* Object is a Region */
   1203      1.1  jruoho 
   1204      1.1  jruoho     if (ObjDesc->Region.SpaceId != SpaceId)
   1205      1.1  jruoho     {
   1206      1.1  jruoho         /* This region is for a different address space, just ignore it */
   1207      1.1  jruoho 
   1208      1.1  jruoho         return (AE_OK);
   1209      1.1  jruoho     }
   1210      1.1  jruoho 
   1211      1.1  jruoho     Status = AcpiEvExecuteRegMethod (ObjDesc, 1);
   1212      1.1  jruoho     return (Status);
   1213      1.1  jruoho }
   1214      1.1  jruoho 
   1215