Home | History | Annotate | Line # | Download | only in events
evregion.c revision 1.1.1.20
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3   1.1.1.4  christos  * Module Name: evregion - Operation Region support
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.19  christos  * Copyright (C) 2000 - 2022, 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.17  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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 #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "acevents.h"
     47       1.1    jruoho #include "acnamesp.h"
     48       1.1    jruoho #include "acinterp.h"
     49       1.1    jruoho 
     50       1.1    jruoho #define _COMPONENT          ACPI_EVENTS
     51       1.1    jruoho         ACPI_MODULE_NAME    ("evregion")
     52       1.1    jruoho 
     53       1.1    jruoho 
     54   1.1.1.4  christos extern UINT8        AcpiGbl_DefaultAddressSpaces[];
     55       1.1    jruoho 
     56   1.1.1.4  christos /* Local prototypes */
     57       1.1    jruoho 
     58   1.1.1.3    jruoho static void
     59  1.1.1.16  christos AcpiEvExecuteOrphanRegMethod (
     60  1.1.1.16  christos     ACPI_NAMESPACE_NODE     *DeviceNode,
     61  1.1.1.16  christos     ACPI_ADR_SPACE_TYPE     SpaceId);
     62  1.1.1.16  christos 
     63   1.1.1.3    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 
     72       1.1    jruoho /*******************************************************************************
     73       1.1    jruoho  *
     74       1.1    jruoho  * FUNCTION:    AcpiEvInitializeOpRegions
     75       1.1    jruoho  *
     76       1.1    jruoho  * PARAMETERS:  None
     77       1.1    jruoho  *
     78       1.1    jruoho  * RETURN:      Status
     79       1.1    jruoho  *
     80       1.1    jruoho  * DESCRIPTION: Execute _REG methods for all Operation Regions that have
     81       1.1    jruoho  *              an installed default region handler.
     82       1.1    jruoho  *
     83       1.1    jruoho  ******************************************************************************/
     84       1.1    jruoho 
     85       1.1    jruoho ACPI_STATUS
     86       1.1    jruoho AcpiEvInitializeOpRegions (
     87       1.1    jruoho     void)
     88       1.1    jruoho {
     89       1.1    jruoho     ACPI_STATUS             Status;
     90       1.1    jruoho     UINT32                  i;
     91       1.1    jruoho 
     92       1.1    jruoho 
     93       1.1    jruoho     ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
     94       1.1    jruoho 
     95       1.1    jruoho 
     96       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
     97       1.1    jruoho     if (ACPI_FAILURE (Status))
     98       1.1    jruoho     {
     99       1.1    jruoho         return_ACPI_STATUS (Status);
    100       1.1    jruoho     }
    101       1.1    jruoho 
    102       1.1    jruoho     /* Run the _REG methods for OpRegions in each default address space */
    103       1.1    jruoho 
    104       1.1    jruoho     for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
    105       1.1    jruoho     {
    106       1.1    jruoho         /*
    107       1.1    jruoho          * Make sure the installed handler is the DEFAULT handler. If not the
    108       1.1    jruoho          * default, the _REG methods will have already been run (when the
    109       1.1    jruoho          * handler was installed)
    110       1.1    jruoho          */
    111       1.1    jruoho         if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
    112       1.1    jruoho                AcpiGbl_DefaultAddressSpaces[i]))
    113       1.1    jruoho         {
    114   1.1.1.7  christos             AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
    115   1.1.1.7  christos                 AcpiGbl_DefaultAddressSpaces[i], ACPI_REG_CONNECT);
    116       1.1    jruoho         }
    117       1.1    jruoho     }
    118       1.1    jruoho 
    119       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    120       1.1    jruoho     return_ACPI_STATUS (Status);
    121       1.1    jruoho }
    122       1.1    jruoho 
    123       1.1    jruoho 
    124       1.1    jruoho /*******************************************************************************
    125       1.1    jruoho  *
    126       1.1    jruoho  * FUNCTION:    AcpiEvAddressSpaceDispatch
    127       1.1    jruoho  *
    128       1.1    jruoho  * PARAMETERS:  RegionObj           - Internal region object
    129   1.1.1.4  christos  *              FieldObj            - Corresponding field. Can be NULL.
    130       1.1    jruoho  *              Function            - Read or Write operation
    131       1.1    jruoho  *              RegionOffset        - Where in the region to read or write
    132       1.1    jruoho  *              BitWidth            - Field width in bits (8, 16, 32, or 64)
    133       1.1    jruoho  *              Value               - Pointer to in or out value, must be
    134       1.1    jruoho  *                                    a full 64-bit integer
    135       1.1    jruoho  *
    136       1.1    jruoho  * RETURN:      Status
    137       1.1    jruoho  *
    138       1.1    jruoho  * DESCRIPTION: Dispatch an address space or operation region access to
    139       1.1    jruoho  *              a previously installed handler.
    140       1.1    jruoho  *
    141   1.1.1.7  christos  * NOTE: During early initialization, we always install the default region
    142   1.1.1.7  christos  * handlers for Memory, I/O and PCI_Config. This ensures that these operation
    143   1.1.1.7  christos  * region address spaces are always available as per the ACPI specification.
    144   1.1.1.7  christos  * This is especially needed in order to support the execution of
    145   1.1.1.7  christos  * module-level AML code during loading of the ACPI tables.
    146   1.1.1.7  christos  *
    147       1.1    jruoho  ******************************************************************************/
    148       1.1    jruoho 
    149       1.1    jruoho ACPI_STATUS
    150       1.1    jruoho AcpiEvAddressSpaceDispatch (
    151       1.1    jruoho     ACPI_OPERAND_OBJECT     *RegionObj,
    152   1.1.1.4  christos     ACPI_OPERAND_OBJECT     *FieldObj,
    153       1.1    jruoho     UINT32                  Function,
    154       1.1    jruoho     UINT32                  RegionOffset,
    155       1.1    jruoho     UINT32                  BitWidth,
    156       1.1    jruoho     UINT64                  *Value)
    157       1.1    jruoho {
    158       1.1    jruoho     ACPI_STATUS             Status;
    159       1.1    jruoho     ACPI_ADR_SPACE_HANDLER  Handler;
    160       1.1    jruoho     ACPI_ADR_SPACE_SETUP    RegionSetup;
    161       1.1    jruoho     ACPI_OPERAND_OBJECT     *HandlerDesc;
    162       1.1    jruoho     ACPI_OPERAND_OBJECT     *RegionObj2;
    163       1.1    jruoho     void                    *RegionContext = NULL;
    164   1.1.1.4  christos     ACPI_CONNECTION_INFO    *Context;
    165  1.1.1.17  christos     ACPI_MUTEX              ContextMutex;
    166  1.1.1.17  christos     BOOLEAN                 ContextLocked;
    167   1.1.1.5  christos     ACPI_PHYSICAL_ADDRESS   Address;
    168       1.1    jruoho 
    169       1.1    jruoho 
    170       1.1    jruoho     ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
    171       1.1    jruoho 
    172       1.1    jruoho 
    173       1.1    jruoho     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
    174       1.1    jruoho     if (!RegionObj2)
    175       1.1    jruoho     {
    176       1.1    jruoho         return_ACPI_STATUS (AE_NOT_EXIST);
    177       1.1    jruoho     }
    178       1.1    jruoho 
    179       1.1    jruoho     /* Ensure that there is a handler associated with this region */
    180       1.1    jruoho 
    181       1.1    jruoho     HandlerDesc = RegionObj->Region.Handler;
    182       1.1    jruoho     if (!HandlerDesc)
    183       1.1    jruoho     {
    184       1.1    jruoho         ACPI_ERROR ((AE_INFO,
    185       1.1    jruoho             "No handler for Region [%4.4s] (%p) [%s]",
    186       1.1    jruoho             AcpiUtGetNodeName (RegionObj->Region.Node),
    187       1.1    jruoho             RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    188       1.1    jruoho 
    189       1.1    jruoho         return_ACPI_STATUS (AE_NOT_EXIST);
    190       1.1    jruoho     }
    191       1.1    jruoho 
    192   1.1.1.4  christos     Context = HandlerDesc->AddressSpace.Context;
    193  1.1.1.17  christos     ContextMutex = HandlerDesc->AddressSpace.ContextMutex;
    194  1.1.1.17  christos     ContextLocked = FALSE;
    195   1.1.1.4  christos 
    196       1.1    jruoho     /*
    197       1.1    jruoho      * It may be the case that the region has never been initialized.
    198       1.1    jruoho      * Some types of regions require special init code
    199       1.1    jruoho      */
    200       1.1    jruoho     if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
    201       1.1    jruoho     {
    202       1.1    jruoho         /* This region has not been initialized yet, do it */
    203       1.1    jruoho 
    204       1.1    jruoho         RegionSetup = HandlerDesc->AddressSpace.Setup;
    205       1.1    jruoho         if (!RegionSetup)
    206       1.1    jruoho         {
    207       1.1    jruoho             /* No initialization routine, exit with error */
    208       1.1    jruoho 
    209       1.1    jruoho             ACPI_ERROR ((AE_INFO,
    210       1.1    jruoho                 "No init routine for region(%p) [%s]",
    211       1.1    jruoho                 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    212       1.1    jruoho             return_ACPI_STATUS (AE_NOT_EXIST);
    213       1.1    jruoho         }
    214       1.1    jruoho 
    215  1.1.1.19  christos         if (RegionObj->Region.SpaceId == ACPI_ADR_SPACE_PLATFORM_COMM)
    216  1.1.1.19  christos         {
    217  1.1.1.19  christos             ACPI_PCC_INFO *Ctx = HandlerDesc->AddressSpace.Context;
    218  1.1.1.19  christos 
    219  1.1.1.19  christos             Ctx->InternalBuffer = FieldObj->Field.InternalPccBuffer;
    220  1.1.1.19  christos             Ctx->Length = (UINT16) RegionObj->Region.Length;
    221  1.1.1.19  christos             Ctx->SubspaceId = (UINT8) RegionObj->Region.Address;
    222  1.1.1.19  christos         }
    223  1.1.1.18  christos 
    224  1.1.1.20  christos         if (RegionObj->Region.SpaceId == ACPI_ADR_SPACE_FIXED_HARDWARE)
    225  1.1.1.20  christos         {
    226  1.1.1.20  christos             ACPI_FFH_INFO *Ctx = HandlerDesc->AddressSpace.Context;
    227  1.1.1.20  christos 
    228  1.1.1.20  christos             Ctx->Length = RegionObj->Region.Length;
    229  1.1.1.20  christos             Ctx->Offset = RegionObj->Region.Address;
    230  1.1.1.20  christos         }
    231  1.1.1.20  christos 
    232       1.1    jruoho         /*
    233       1.1    jruoho          * We must exit the interpreter because the region setup will
    234       1.1    jruoho          * potentially execute control methods (for example, the _REG method
    235       1.1    jruoho          * for this region)
    236       1.1    jruoho          */
    237       1.1    jruoho         AcpiExExitInterpreter ();
    238       1.1    jruoho 
    239       1.1    jruoho         Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
    240   1.1.1.7  christos             Context, &RegionContext);
    241       1.1    jruoho 
    242       1.1    jruoho         /* Re-enter the interpreter */
    243       1.1    jruoho 
    244       1.1    jruoho         AcpiExEnterInterpreter ();
    245       1.1    jruoho 
    246       1.1    jruoho         /* Check for failure of the Region Setup */
    247       1.1    jruoho 
    248       1.1    jruoho         if (ACPI_FAILURE (Status))
    249       1.1    jruoho         {
    250       1.1    jruoho             ACPI_EXCEPTION ((AE_INFO, Status,
    251       1.1    jruoho                 "During region initialization: [%s]",
    252       1.1    jruoho                 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    253       1.1    jruoho             return_ACPI_STATUS (Status);
    254       1.1    jruoho         }
    255       1.1    jruoho 
    256       1.1    jruoho         /* Region initialization may have been completed by RegionSetup */
    257       1.1    jruoho 
    258       1.1    jruoho         if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
    259       1.1    jruoho         {
    260       1.1    jruoho             RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
    261       1.1    jruoho 
    262   1.1.1.4  christos             /*
    263   1.1.1.4  christos              * Save the returned context for use in all accesses to
    264   1.1.1.4  christos              * the handler for this particular region
    265   1.1.1.4  christos              */
    266   1.1.1.4  christos             if (!(RegionObj2->Extra.RegionContext))
    267       1.1    jruoho             {
    268       1.1    jruoho                 RegionObj2->Extra.RegionContext = RegionContext;
    269       1.1    jruoho             }
    270       1.1    jruoho         }
    271       1.1    jruoho     }
    272       1.1    jruoho 
    273       1.1    jruoho     /* We have everything we need, we can invoke the address space handler */
    274       1.1    jruoho 
    275       1.1    jruoho     Handler = HandlerDesc->AddressSpace.Handler;
    276   1.1.1.5  christos     Address = (RegionObj->Region.Address + RegionOffset);
    277       1.1    jruoho 
    278  1.1.1.17  christos     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    279  1.1.1.17  christos         "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
    280  1.1.1.17  christos         &RegionObj->Region.Handler->AddressSpace, Handler,
    281  1.1.1.17  christos         ACPI_FORMAT_UINT64 (Address),
    282  1.1.1.17  christos         AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    283  1.1.1.17  christos 
    284  1.1.1.17  christos     if (!(HandlerDesc->AddressSpace.HandlerFlags &
    285  1.1.1.17  christos         ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
    286  1.1.1.17  christos     {
    287  1.1.1.17  christos         /*
    288  1.1.1.17  christos          * For handlers other than the default (supplied) handlers, we must
    289  1.1.1.17  christos          * exit the interpreter because the handler *might* block -- we don't
    290  1.1.1.17  christos          * know what it will do, so we can't hold the lock on the interpreter.
    291  1.1.1.17  christos          */
    292  1.1.1.17  christos         AcpiExExitInterpreter();
    293  1.1.1.17  christos     }
    294  1.1.1.17  christos 
    295   1.1.1.4  christos     /*
    296   1.1.1.4  christos      * Special handling for GenericSerialBus and GeneralPurposeIo:
    297   1.1.1.4  christos      * There are three extra parameters that must be passed to the
    298   1.1.1.4  christos      * handler via the context:
    299   1.1.1.5  christos      *   1) Connection buffer, a resource template from Connection() op
    300   1.1.1.5  christos      *   2) Length of the above buffer
    301   1.1.1.5  christos      *   3) Actual access length from the AccessAs() op
    302   1.1.1.5  christos      *
    303  1.1.1.17  christos      * Since we pass these extra parameters via the context, which is
    304  1.1.1.17  christos      * shared between threads, we must lock the context to avoid these
    305  1.1.1.17  christos      * parameters being changed from another thread before the handler
    306  1.1.1.17  christos      * has completed running.
    307  1.1.1.17  christos      *
    308   1.1.1.5  christos      * In addition, for GeneralPurposeIo, the Address and BitWidth fields
    309   1.1.1.5  christos      * are defined as follows:
    310   1.1.1.5  christos      *   1) Address is the pin number index of the field (bit offset from
    311   1.1.1.5  christos      *      the previous Connection)
    312   1.1.1.5  christos      *   2) BitWidth is the actual bit length of the field (number of pins)
    313   1.1.1.4  christos      */
    314  1.1.1.17  christos     if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
    315  1.1.1.17  christos          RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO) &&
    316   1.1.1.4  christos         Context &&
    317   1.1.1.4  christos         FieldObj)
    318   1.1.1.4  christos     {
    319   1.1.1.4  christos 
    320  1.1.1.17  christos         Status = AcpiOsAcquireMutex (ContextMutex, ACPI_WAIT_FOREVER);
    321  1.1.1.17  christos         if (ACPI_FAILURE (Status))
    322  1.1.1.17  christos         {
    323  1.1.1.17  christos             goto ReEnterInterpreter;
    324  1.1.1.17  christos         }
    325  1.1.1.17  christos 
    326  1.1.1.17  christos         ContextLocked = TRUE;
    327  1.1.1.17  christos 
    328   1.1.1.5  christos         /* Get the Connection (ResourceTemplate) buffer */
    329   1.1.1.5  christos 
    330   1.1.1.5  christos         Context->Connection = FieldObj->Field.ResourceBuffer;
    331   1.1.1.5  christos         Context->Length = FieldObj->Field.ResourceLength;
    332   1.1.1.5  christos         Context->AccessLength = FieldObj->Field.AccessLength;
    333   1.1.1.5  christos 
    334  1.1.1.17  christos         if (RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO)
    335  1.1.1.17  christos         {
    336  1.1.1.17  christos             Address = FieldObj->Field.PinNumberIndex;
    337  1.1.1.17  christos             BitWidth = FieldObj->Field.BitLength;
    338  1.1.1.17  christos         }
    339       1.1    jruoho     }
    340       1.1    jruoho 
    341       1.1    jruoho     /* Call the handler */
    342       1.1    jruoho 
    343   1.1.1.5  christos     Status = Handler (Function, Address, BitWidth, Value, Context,
    344   1.1.1.5  christos         RegionObj2->Extra.RegionContext);
    345       1.1    jruoho 
    346  1.1.1.17  christos     if (ContextLocked)
    347  1.1.1.17  christos     {
    348  1.1.1.17  christos         AcpiOsReleaseMutex (ContextMutex);
    349  1.1.1.17  christos     }
    350  1.1.1.17  christos 
    351       1.1    jruoho     if (ACPI_FAILURE (Status))
    352       1.1    jruoho     {
    353       1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
    354       1.1    jruoho             AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    355  1.1.1.10  christos 
    356  1.1.1.10  christos         /*
    357  1.1.1.10  christos          * Special case for an EC timeout. These are seen so frequently
    358  1.1.1.10  christos          * that an additional error message is helpful
    359  1.1.1.10  christos          */
    360  1.1.1.10  christos         if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
    361  1.1.1.10  christos             (Status == AE_TIME))
    362  1.1.1.10  christos         {
    363  1.1.1.10  christos             ACPI_ERROR ((AE_INFO,
    364  1.1.1.10  christos                 "Timeout from EC hardware or EC device driver"));
    365  1.1.1.10  christos         }
    366       1.1    jruoho     }
    367       1.1    jruoho 
    368  1.1.1.17  christos ReEnterInterpreter:
    369       1.1    jruoho     if (!(HandlerDesc->AddressSpace.HandlerFlags &
    370   1.1.1.7  christos         ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
    371       1.1    jruoho     {
    372       1.1    jruoho         /*
    373       1.1    jruoho          * We just returned from a non-default handler, we must re-enter the
    374       1.1    jruoho          * interpreter
    375       1.1    jruoho          */
    376   1.1.1.7  christos         AcpiExEnterInterpreter ();
    377       1.1    jruoho     }
    378       1.1    jruoho 
    379       1.1    jruoho     return_ACPI_STATUS (Status);
    380       1.1    jruoho }
    381       1.1    jruoho 
    382       1.1    jruoho 
    383       1.1    jruoho /*******************************************************************************
    384       1.1    jruoho  *
    385       1.1    jruoho  * FUNCTION:    AcpiEvDetachRegion
    386       1.1    jruoho  *
    387       1.1    jruoho  * PARAMETERS:  RegionObj           - Region Object
    388       1.1    jruoho  *              AcpiNsIsLocked      - Namespace Region Already Locked?
    389       1.1    jruoho  *
    390       1.1    jruoho  * RETURN:      None
    391       1.1    jruoho  *
    392       1.1    jruoho  * DESCRIPTION: Break the association between the handler and the region
    393       1.1    jruoho  *              this is a two way association.
    394       1.1    jruoho  *
    395       1.1    jruoho  ******************************************************************************/
    396       1.1    jruoho 
    397       1.1    jruoho void
    398   1.1.1.7  christos AcpiEvDetachRegion (
    399       1.1    jruoho     ACPI_OPERAND_OBJECT     *RegionObj,
    400       1.1    jruoho     BOOLEAN                 AcpiNsIsLocked)
    401       1.1    jruoho {
    402       1.1    jruoho     ACPI_OPERAND_OBJECT     *HandlerObj;
    403       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    404   1.1.1.5  christos     ACPI_OPERAND_OBJECT     *StartDesc;
    405       1.1    jruoho     ACPI_OPERAND_OBJECT     **LastObjPtr;
    406       1.1    jruoho     ACPI_ADR_SPACE_SETUP    RegionSetup;
    407       1.1    jruoho     void                    **RegionContext;
    408       1.1    jruoho     ACPI_OPERAND_OBJECT     *RegionObj2;
    409       1.1    jruoho     ACPI_STATUS             Status;
    410       1.1    jruoho 
    411       1.1    jruoho 
    412       1.1    jruoho     ACPI_FUNCTION_TRACE (EvDetachRegion);
    413       1.1    jruoho 
    414       1.1    jruoho 
    415       1.1    jruoho     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
    416       1.1    jruoho     if (!RegionObj2)
    417       1.1    jruoho     {
    418       1.1    jruoho         return_VOID;
    419       1.1    jruoho     }
    420       1.1    jruoho     RegionContext = &RegionObj2->Extra.RegionContext;
    421       1.1    jruoho 
    422       1.1    jruoho     /* Get the address handler from the region object */
    423       1.1    jruoho 
    424       1.1    jruoho     HandlerObj = RegionObj->Region.Handler;
    425       1.1    jruoho     if (!HandlerObj)
    426       1.1    jruoho     {
    427       1.1    jruoho         /* This region has no handler, all done */
    428       1.1    jruoho 
    429       1.1    jruoho         return_VOID;
    430       1.1    jruoho     }
    431       1.1    jruoho 
    432       1.1    jruoho     /* Find this region in the handler's list */
    433       1.1    jruoho 
    434       1.1    jruoho     ObjDesc = HandlerObj->AddressSpace.RegionList;
    435   1.1.1.5  christos     StartDesc = ObjDesc;
    436       1.1    jruoho     LastObjPtr = &HandlerObj->AddressSpace.RegionList;
    437       1.1    jruoho 
    438       1.1    jruoho     while (ObjDesc)
    439       1.1    jruoho     {
    440       1.1    jruoho         /* Is this the correct Region? */
    441       1.1    jruoho 
    442       1.1    jruoho         if (ObjDesc == RegionObj)
    443       1.1    jruoho         {
    444       1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    445       1.1    jruoho                 "Removing Region %p from address handler %p\n",
    446       1.1    jruoho                 RegionObj, HandlerObj));
    447       1.1    jruoho 
    448       1.1    jruoho             /* This is it, remove it from the handler's list */
    449       1.1    jruoho 
    450       1.1    jruoho             *LastObjPtr = ObjDesc->Region.Next;
    451       1.1    jruoho             ObjDesc->Region.Next = NULL;        /* Must clear field */
    452       1.1    jruoho 
    453       1.1    jruoho             if (AcpiNsIsLocked)
    454       1.1    jruoho             {
    455       1.1    jruoho                 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    456       1.1    jruoho                 if (ACPI_FAILURE (Status))
    457       1.1    jruoho                 {
    458       1.1    jruoho                     return_VOID;
    459       1.1    jruoho                 }
    460       1.1    jruoho             }
    461       1.1    jruoho 
    462       1.1    jruoho             /* Now stop region accesses by executing the _REG method */
    463       1.1    jruoho 
    464   1.1.1.3    jruoho             Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_DISCONNECT);
    465       1.1    jruoho             if (ACPI_FAILURE (Status))
    466       1.1    jruoho             {
    467       1.1    jruoho                 ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
    468       1.1    jruoho                     AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    469       1.1    jruoho             }
    470       1.1    jruoho 
    471       1.1    jruoho             if (AcpiNsIsLocked)
    472       1.1    jruoho             {
    473       1.1    jruoho                 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    474       1.1    jruoho                 if (ACPI_FAILURE (Status))
    475       1.1    jruoho                 {
    476       1.1    jruoho                     return_VOID;
    477       1.1    jruoho                 }
    478       1.1    jruoho             }
    479       1.1    jruoho 
    480       1.1    jruoho             /*
    481       1.1    jruoho              * If the region has been activated, call the setup handler with
    482       1.1    jruoho              * the deactivate notification
    483       1.1    jruoho              */
    484       1.1    jruoho             if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
    485       1.1    jruoho             {
    486       1.1    jruoho                 RegionSetup = HandlerObj->AddressSpace.Setup;
    487       1.1    jruoho                 Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
    488       1.1    jruoho                     HandlerObj->AddressSpace.Context, RegionContext);
    489       1.1    jruoho 
    490   1.1.1.4  christos                 /*
    491   1.1.1.4  christos                  * RegionContext should have been released by the deactivate
    492   1.1.1.4  christos                  * operation. We don't need access to it anymore here.
    493   1.1.1.4  christos                  */
    494   1.1.1.4  christos                 if (RegionContext)
    495   1.1.1.4  christos                 {
    496   1.1.1.4  christos                     *RegionContext = NULL;
    497   1.1.1.4  christos                 }
    498   1.1.1.4  christos 
    499       1.1    jruoho                 /* Init routine may fail, Just ignore errors */
    500       1.1    jruoho 
    501       1.1    jruoho                 if (ACPI_FAILURE (Status))
    502       1.1    jruoho                 {
    503       1.1    jruoho                     ACPI_EXCEPTION ((AE_INFO, Status,
    504       1.1    jruoho                         "from region handler - deactivate, [%s]",
    505       1.1    jruoho                         AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    506       1.1    jruoho                 }
    507       1.1    jruoho 
    508       1.1    jruoho                 RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
    509       1.1    jruoho             }
    510       1.1    jruoho 
    511       1.1    jruoho             /*
    512       1.1    jruoho              * Remove handler reference in the region
    513       1.1    jruoho              *
    514       1.1    jruoho              * NOTE: this doesn't mean that the region goes away, the region
    515       1.1    jruoho              * is just inaccessible as indicated to the _REG method
    516       1.1    jruoho              *
    517       1.1    jruoho              * If the region is on the handler's list, this must be the
    518       1.1    jruoho              * region's handler
    519       1.1    jruoho              */
    520       1.1    jruoho             RegionObj->Region.Handler = NULL;
    521       1.1    jruoho             AcpiUtRemoveReference (HandlerObj);
    522       1.1    jruoho 
    523       1.1    jruoho             return_VOID;
    524       1.1    jruoho         }
    525       1.1    jruoho 
    526       1.1    jruoho         /* Walk the linked list of handlers */
    527       1.1    jruoho 
    528       1.1    jruoho         LastObjPtr = &ObjDesc->Region.Next;
    529       1.1    jruoho         ObjDesc = ObjDesc->Region.Next;
    530   1.1.1.5  christos 
    531   1.1.1.5  christos         /* Prevent infinite loop if list is corrupted */
    532   1.1.1.5  christos 
    533   1.1.1.5  christos         if (ObjDesc == StartDesc)
    534   1.1.1.5  christos         {
    535   1.1.1.5  christos             ACPI_ERROR ((AE_INFO,
    536   1.1.1.5  christos                 "Circular handler list in region object %p",
    537   1.1.1.5  christos                 RegionObj));
    538   1.1.1.5  christos             return_VOID;
    539   1.1.1.5  christos         }
    540       1.1    jruoho     }
    541       1.1    jruoho 
    542       1.1    jruoho     /* If we get here, the region was not in the handler's region list */
    543       1.1    jruoho 
    544       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    545       1.1    jruoho         "Cannot remove region %p from address handler %p\n",
    546       1.1    jruoho         RegionObj, HandlerObj));
    547       1.1    jruoho 
    548       1.1    jruoho     return_VOID;
    549       1.1    jruoho }
    550       1.1    jruoho 
    551       1.1    jruoho 
    552       1.1    jruoho /*******************************************************************************
    553       1.1    jruoho  *
    554       1.1    jruoho  * FUNCTION:    AcpiEvAttachRegion
    555       1.1    jruoho  *
    556       1.1    jruoho  * PARAMETERS:  HandlerObj          - Handler Object
    557       1.1    jruoho  *              RegionObj           - Region Object
    558       1.1    jruoho  *              AcpiNsIsLocked      - Namespace Region Already Locked?
    559       1.1    jruoho  *
    560       1.1    jruoho  * RETURN:      None
    561       1.1    jruoho  *
    562       1.1    jruoho  * DESCRIPTION: Create the association between the handler and the region
    563       1.1    jruoho  *              this is a two way association.
    564       1.1    jruoho  *
    565       1.1    jruoho  ******************************************************************************/
    566       1.1    jruoho 
    567       1.1    jruoho ACPI_STATUS
    568       1.1    jruoho AcpiEvAttachRegion (
    569       1.1    jruoho     ACPI_OPERAND_OBJECT     *HandlerObj,
    570       1.1    jruoho     ACPI_OPERAND_OBJECT     *RegionObj,
    571       1.1    jruoho     BOOLEAN                 AcpiNsIsLocked)
    572       1.1    jruoho {
    573       1.1    jruoho 
    574       1.1    jruoho     ACPI_FUNCTION_TRACE (EvAttachRegion);
    575       1.1    jruoho 
    576       1.1    jruoho 
    577   1.1.1.7  christos     /* Install the region's handler */
    578   1.1.1.7  christos 
    579   1.1.1.7  christos     if (RegionObj->Region.Handler)
    580   1.1.1.7  christos     {
    581   1.1.1.7  christos         return_ACPI_STATUS (AE_ALREADY_EXISTS);
    582   1.1.1.7  christos     }
    583   1.1.1.7  christos 
    584       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    585       1.1    jruoho         "Adding Region [%4.4s] %p to address handler %p [%s]\n",
    586       1.1    jruoho         AcpiUtGetNodeName (RegionObj->Region.Node),
    587       1.1    jruoho         RegionObj, HandlerObj,
    588       1.1    jruoho         AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
    589       1.1    jruoho 
    590       1.1    jruoho     /* Link this region to the front of the handler's list */
    591       1.1    jruoho 
    592       1.1    jruoho     RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
    593       1.1    jruoho     HandlerObj->AddressSpace.RegionList = RegionObj;
    594   1.1.1.7  christos     RegionObj->Region.Handler = HandlerObj;
    595   1.1.1.7  christos     AcpiUtAddReference (HandlerObj);
    596       1.1    jruoho 
    597   1.1.1.7  christos     return_ACPI_STATUS (AE_OK);
    598   1.1.1.7  christos }
    599       1.1    jruoho 
    600   1.1.1.7  christos 
    601   1.1.1.7  christos /*******************************************************************************
    602   1.1.1.7  christos  *
    603   1.1.1.4  christos  * FUNCTION:    AcpiEvExecuteRegMethod
    604       1.1    jruoho  *
    605   1.1.1.4  christos  * PARAMETERS:  RegionObj           - Region object
    606   1.1.1.4  christos  *              Function            - Passed to _REG: On (1) or Off (0)
    607       1.1    jruoho  *
    608       1.1    jruoho  * RETURN:      Status
    609       1.1    jruoho  *
    610   1.1.1.4  christos  * DESCRIPTION: Execute _REG method for a region
    611       1.1    jruoho  *
    612       1.1    jruoho  ******************************************************************************/
    613       1.1    jruoho 
    614       1.1    jruoho ACPI_STATUS
    615   1.1.1.4  christos AcpiEvExecuteRegMethod (
    616   1.1.1.4  christos     ACPI_OPERAND_OBJECT     *RegionObj,
    617   1.1.1.4  christos     UINT32                  Function)
    618       1.1    jruoho {
    619   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info;
    620   1.1.1.4  christos     ACPI_OPERAND_OBJECT     *Args[3];
    621   1.1.1.4  christos     ACPI_OPERAND_OBJECT     *RegionObj2;
    622   1.1.1.8  christos     const ACPI_NAME         *RegNamePtr = ACPI_CAST_PTR (ACPI_NAME, METHOD_NAME__REG);
    623   1.1.1.8  christos     ACPI_NAMESPACE_NODE     *MethodNode;
    624   1.1.1.8  christos     ACPI_NAMESPACE_NODE     *Node;
    625       1.1    jruoho     ACPI_STATUS             Status;
    626       1.1    jruoho 
    627       1.1    jruoho 
    628   1.1.1.4  christos     ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
    629       1.1    jruoho 
    630       1.1    jruoho 
    631   1.1.1.8  christos     if (!AcpiGbl_NamespaceInitialized ||
    632   1.1.1.8  christos         RegionObj->Region.Handler == NULL)
    633   1.1.1.8  christos     {
    634   1.1.1.8  christos         return_ACPI_STATUS (AE_OK);
    635   1.1.1.8  christos     }
    636   1.1.1.8  christos 
    637   1.1.1.4  christos     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
    638   1.1.1.4  christos     if (!RegionObj2)
    639       1.1    jruoho     {
    640   1.1.1.4  christos         return_ACPI_STATUS (AE_NOT_EXIST);
    641       1.1    jruoho     }
    642       1.1    jruoho 
    643   1.1.1.8  christos     /*
    644   1.1.1.8  christos      * Find any "_REG" method associated with this region definition.
    645   1.1.1.8  christos      * The method should always be updated as this function may be
    646   1.1.1.8  christos      * invoked after a namespace change.
    647   1.1.1.8  christos      */
    648   1.1.1.8  christos     Node = RegionObj->Region.Node->Parent;
    649   1.1.1.8  christos     Status = AcpiNsSearchOneScope (
    650   1.1.1.8  christos         *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
    651   1.1.1.8  christos     if (ACPI_SUCCESS (Status))
    652   1.1.1.8  christos     {
    653   1.1.1.8  christos         /*
    654   1.1.1.8  christos          * The _REG method is optional and there can be only one per
    655   1.1.1.8  christos          * region definition. This will be executed when the handler is
    656   1.1.1.8  christos          * attached or removed.
    657   1.1.1.8  christos          */
    658   1.1.1.8  christos         RegionObj2->Extra.Method_REG = MethodNode;
    659   1.1.1.8  christos     }
    660   1.1.1.8  christos     if (RegionObj2->Extra.Method_REG == NULL)
    661   1.1.1.7  christos     {
    662   1.1.1.7  christos         return_ACPI_STATUS (AE_OK);
    663   1.1.1.7  christos     }
    664   1.1.1.7  christos 
    665   1.1.1.7  christos     /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
    666   1.1.1.7  christos 
    667   1.1.1.7  christos     if ((Function == ACPI_REG_CONNECT &&
    668   1.1.1.7  christos         RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED) ||
    669   1.1.1.7  christos         (Function == ACPI_REG_DISCONNECT &&
    670   1.1.1.7  christos          !(RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED)))
    671       1.1    jruoho     {
    672   1.1.1.4  christos         return_ACPI_STATUS (AE_OK);
    673       1.1    jruoho     }
    674       1.1    jruoho 
    675   1.1.1.4  christos     /* Allocate and initialize the evaluation information block */
    676       1.1    jruoho 
    677   1.1.1.4  christos     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    678   1.1.1.4  christos     if (!Info)
    679       1.1    jruoho     {
    680   1.1.1.4  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    681       1.1    jruoho     }
    682       1.1    jruoho 
    683   1.1.1.4  christos     Info->PrefixNode = RegionObj2->Extra.Method_REG;
    684   1.1.1.4  christos     Info->RelativePathname = NULL;
    685   1.1.1.4  christos     Info->Parameters = Args;
    686   1.1.1.4  christos     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
    687       1.1    jruoho 
    688       1.1    jruoho     /*
    689   1.1.1.4  christos      * The _REG method has two arguments:
    690   1.1.1.4  christos      *
    691   1.1.1.4  christos      * Arg0 - Integer:
    692   1.1.1.4  christos      *  Operation region space ID Same value as RegionObj->Region.SpaceId
    693       1.1    jruoho      *
    694   1.1.1.4  christos      * Arg1 - Integer:
    695   1.1.1.4  christos      *  connection status 1 for connecting the handler, 0 for disconnecting
    696   1.1.1.4  christos      *  the handler (Passed as a parameter)
    697       1.1    jruoho      */
    698   1.1.1.4  christos     Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
    699   1.1.1.4  christos     if (!Args[0])
    700       1.1    jruoho     {
    701       1.1    jruoho         Status = AE_NO_MEMORY;
    702   1.1.1.4  christos         goto Cleanup1;
    703       1.1    jruoho     }
    704       1.1    jruoho 
    705   1.1.1.4  christos     Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
    706   1.1.1.4  christos     if (!Args[1])
    707   1.1.1.4  christos     {
    708   1.1.1.4  christos         Status = AE_NO_MEMORY;
    709   1.1.1.4  christos         goto Cleanup2;
    710   1.1.1.4  christos     }
    711       1.1    jruoho 
    712   1.1.1.4  christos     Args[2] = NULL; /* Terminate list */
    713       1.1    jruoho 
    714   1.1.1.4  christos     /* Execute the method, no return value */
    715       1.1    jruoho 
    716   1.1.1.4  christos     ACPI_DEBUG_EXEC (
    717   1.1.1.4  christos         AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
    718       1.1    jruoho 
    719   1.1.1.4  christos     Status = AcpiNsEvaluate (Info);
    720   1.1.1.4  christos     AcpiUtRemoveReference (Args[1]);
    721       1.1    jruoho 
    722   1.1.1.7  christos     if (ACPI_FAILURE (Status))
    723   1.1.1.7  christos     {
    724   1.1.1.7  christos         goto Cleanup2;
    725   1.1.1.7  christos     }
    726   1.1.1.7  christos 
    727   1.1.1.7  christos     if (Function == ACPI_REG_CONNECT)
    728   1.1.1.7  christos     {
    729   1.1.1.7  christos         RegionObj->Common.Flags |= AOPOBJ_REG_CONNECTED;
    730   1.1.1.7  christos     }
    731   1.1.1.7  christos     else
    732   1.1.1.7  christos     {
    733   1.1.1.7  christos         RegionObj->Common.Flags &= ~AOPOBJ_REG_CONNECTED;
    734   1.1.1.7  christos     }
    735   1.1.1.7  christos 
    736   1.1.1.4  christos Cleanup2:
    737   1.1.1.4  christos     AcpiUtRemoveReference (Args[0]);
    738       1.1    jruoho 
    739   1.1.1.4  christos Cleanup1:
    740   1.1.1.4  christos     ACPI_FREE (Info);
    741       1.1    jruoho     return_ACPI_STATUS (Status);
    742       1.1    jruoho }
    743       1.1    jruoho 
    744       1.1    jruoho 
    745       1.1    jruoho /*******************************************************************************
    746       1.1    jruoho  *
    747       1.1    jruoho  * FUNCTION:    AcpiEvExecuteRegMethods
    748       1.1    jruoho  *
    749       1.1    jruoho  * PARAMETERS:  Node            - Namespace node for the device
    750       1.1    jruoho  *              SpaceId         - The address space ID
    751   1.1.1.7  christos  *              Function        - Passed to _REG: On (1) or Off (0)
    752       1.1    jruoho  *
    753   1.1.1.7  christos  * RETURN:      None
    754       1.1    jruoho  *
    755       1.1    jruoho  * DESCRIPTION: Run all _REG methods for the input Space ID;
    756       1.1    jruoho  *              Note: assumes namespace is locked, or system init time.
    757       1.1    jruoho  *
    758       1.1    jruoho  ******************************************************************************/
    759       1.1    jruoho 
    760   1.1.1.7  christos void
    761       1.1    jruoho AcpiEvExecuteRegMethods (
    762       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    763   1.1.1.7  christos     ACPI_ADR_SPACE_TYPE     SpaceId,
    764   1.1.1.7  christos     UINT32                  Function)
    765       1.1    jruoho {
    766   1.1.1.7  christos     ACPI_REG_WALK_INFO      Info;
    767       1.1    jruoho 
    768       1.1    jruoho 
    769       1.1    jruoho     ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
    770       1.1    jruoho 
    771  1.1.1.12  christos     /*
    772  1.1.1.12  christos      * These address spaces do not need a call to _REG, since the ACPI
    773  1.1.1.12  christos      * specification defines them as: "must always be accessible". Since
    774  1.1.1.12  christos      * they never change state (never become unavailable), no need to ever
    775  1.1.1.12  christos      * call _REG on them. Also, a DataTable is not a "real" address space,
    776  1.1.1.12  christos      * so do not call _REG. September 2018.
    777  1.1.1.12  christos      */
    778  1.1.1.12  christos     if ((SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) ||
    779  1.1.1.12  christos         (SpaceId == ACPI_ADR_SPACE_SYSTEM_IO) ||
    780  1.1.1.12  christos         (SpaceId == ACPI_ADR_SPACE_DATA_TABLE))
    781  1.1.1.12  christos     {
    782  1.1.1.12  christos         return_VOID;
    783  1.1.1.12  christos     }
    784  1.1.1.12  christos 
    785   1.1.1.7  christos     Info.SpaceId = SpaceId;
    786   1.1.1.7  christos     Info.Function = Function;
    787   1.1.1.7  christos     Info.RegRunCount = 0;
    788   1.1.1.7  christos 
    789   1.1.1.7  christos     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES,
    790   1.1.1.7  christos         "    Running _REG methods for SpaceId %s\n",
    791   1.1.1.7  christos         AcpiUtGetRegionName (Info.SpaceId)));
    792       1.1    jruoho 
    793       1.1    jruoho     /*
    794       1.1    jruoho      * Run all _REG methods for all Operation Regions for this space ID. This
    795       1.1    jruoho      * is a separate walk in order to handle any interdependencies between
    796       1.1    jruoho      * regions and _REG methods. (i.e. handlers must be installed for all
    797       1.1    jruoho      * regions of this Space ID before we can run any _REG methods)
    798       1.1    jruoho      */
    799   1.1.1.7  christos     (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
    800   1.1.1.7  christos         ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL, &Info, NULL);
    801       1.1    jruoho 
    802  1.1.1.16  christos     /*
    803  1.1.1.16  christos      * Special case for EC and GPIO: handle "orphan" _REG methods with
    804  1.1.1.16  christos      * no region.
    805  1.1.1.16  christos      */
    806  1.1.1.16  christos     if (SpaceId == ACPI_ADR_SPACE_EC || SpaceId == ACPI_ADR_SPACE_GPIO)
    807   1.1.1.3    jruoho     {
    808  1.1.1.16  christos         AcpiEvExecuteOrphanRegMethod (Node, SpaceId);
    809   1.1.1.3    jruoho     }
    810   1.1.1.3    jruoho 
    811   1.1.1.7  christos     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES,
    812   1.1.1.7  christos         "    Executed %u _REG methods for SpaceId %s\n",
    813   1.1.1.7  christos         Info.RegRunCount, AcpiUtGetRegionName (Info.SpaceId)));
    814   1.1.1.7  christos 
    815   1.1.1.7  christos     return_VOID;
    816       1.1    jruoho }
    817       1.1    jruoho 
    818       1.1    jruoho 
    819       1.1    jruoho /*******************************************************************************
    820       1.1    jruoho  *
    821       1.1    jruoho  * FUNCTION:    AcpiEvRegRun
    822       1.1    jruoho  *
    823       1.1    jruoho  * PARAMETERS:  WalkNamespace callback
    824       1.1    jruoho  *
    825       1.1    jruoho  * DESCRIPTION: Run _REG method for region objects of the requested spaceID
    826       1.1    jruoho  *
    827       1.1    jruoho  ******************************************************************************/
    828       1.1    jruoho 
    829       1.1    jruoho static ACPI_STATUS
    830       1.1    jruoho AcpiEvRegRun (
    831       1.1    jruoho     ACPI_HANDLE             ObjHandle,
    832       1.1    jruoho     UINT32                  Level,
    833       1.1    jruoho     void                    *Context,
    834       1.1    jruoho     void                    **ReturnValue)
    835       1.1    jruoho {
    836       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    837       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    838       1.1    jruoho     ACPI_STATUS             Status;
    839   1.1.1.7  christos     ACPI_REG_WALK_INFO      *Info;
    840       1.1    jruoho 
    841       1.1    jruoho 
    842   1.1.1.7  christos     Info = ACPI_CAST_PTR (ACPI_REG_WALK_INFO, Context);
    843       1.1    jruoho 
    844       1.1    jruoho     /* Convert and validate the device handle */
    845       1.1    jruoho 
    846       1.1    jruoho     Node = AcpiNsValidateHandle (ObjHandle);
    847       1.1    jruoho     if (!Node)
    848       1.1    jruoho     {
    849       1.1    jruoho         return (AE_BAD_PARAMETER);
    850       1.1    jruoho     }
    851       1.1    jruoho 
    852       1.1    jruoho     /*
    853  1.1.1.12  christos      * We only care about regions and objects that are allowed to have
    854  1.1.1.12  christos      * address space handlers
    855       1.1    jruoho      */
    856       1.1    jruoho     if ((Node->Type != ACPI_TYPE_REGION) &&
    857       1.1    jruoho         (Node != AcpiGbl_RootNode))
    858       1.1    jruoho     {
    859       1.1    jruoho         return (AE_OK);
    860       1.1    jruoho     }
    861       1.1    jruoho 
    862       1.1    jruoho     /* Check for an existing internal object */
    863       1.1    jruoho 
    864       1.1    jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
    865       1.1    jruoho     if (!ObjDesc)
    866       1.1    jruoho     {
    867       1.1    jruoho         /* No object, just exit */
    868       1.1    jruoho 
    869       1.1    jruoho         return (AE_OK);
    870       1.1    jruoho     }
    871       1.1    jruoho 
    872       1.1    jruoho     /* Object is a Region */
    873       1.1    jruoho 
    874   1.1.1.7  christos     if (ObjDesc->Region.SpaceId != Info->SpaceId)
    875       1.1    jruoho     {
    876       1.1    jruoho         /* This region is for a different address space, just ignore it */
    877       1.1    jruoho 
    878       1.1    jruoho         return (AE_OK);
    879       1.1    jruoho     }
    880       1.1    jruoho 
    881   1.1.1.7  christos     Info->RegRunCount++;
    882   1.1.1.7  christos     Status = AcpiEvExecuteRegMethod (ObjDesc, Info->Function);
    883       1.1    jruoho     return (Status);
    884       1.1    jruoho }
    885       1.1    jruoho 
    886   1.1.1.3    jruoho 
    887   1.1.1.3    jruoho /*******************************************************************************
    888   1.1.1.3    jruoho  *
    889  1.1.1.16  christos  * FUNCTION:    AcpiEvExecuteOrphanRegMethod
    890   1.1.1.3    jruoho  *
    891  1.1.1.16  christos  * PARAMETERS:  DeviceNode          - Namespace node for an ACPI device
    892  1.1.1.16  christos  *              SpaceId             - The address space ID
    893   1.1.1.3    jruoho  *
    894   1.1.1.3    jruoho  * RETURN:      None
    895   1.1.1.3    jruoho  *
    896  1.1.1.16  christos  * DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI
    897   1.1.1.3    jruoho  *              device. This is a _REG method that has no corresponding region
    898  1.1.1.16  christos  *              within the device's scope. ACPI tables depending on these
    899  1.1.1.16  christos  *              "orphan" _REG methods have been seen for both EC and GPIO
    900  1.1.1.16  christos  *              Operation Regions. Presumably the Windows ACPI implementation
    901  1.1.1.16  christos  *              always calls the _REG method independent of the presence of
    902  1.1.1.16  christos  *              an actual Operation Region with the correct address space ID.
    903   1.1.1.4  christos  *
    904   1.1.1.4  christos  *  MUTEX:      Assumes the namespace is locked
    905   1.1.1.3    jruoho  *
    906   1.1.1.3    jruoho  ******************************************************************************/
    907   1.1.1.3    jruoho 
    908   1.1.1.3    jruoho static void
    909  1.1.1.16  christos AcpiEvExecuteOrphanRegMethod (
    910  1.1.1.16  christos     ACPI_NAMESPACE_NODE     *DeviceNode,
    911  1.1.1.16  christos     ACPI_ADR_SPACE_TYPE     SpaceId)
    912   1.1.1.3    jruoho {
    913   1.1.1.4  christos     ACPI_HANDLE             RegMethod;
    914   1.1.1.4  christos     ACPI_NAMESPACE_NODE     *NextNode;
    915   1.1.1.3    jruoho     ACPI_STATUS             Status;
    916   1.1.1.3    jruoho     ACPI_OBJECT_LIST        Args;
    917   1.1.1.3    jruoho     ACPI_OBJECT             Objects[2];
    918   1.1.1.3    jruoho 
    919   1.1.1.3    jruoho 
    920  1.1.1.16  christos     ACPI_FUNCTION_TRACE (EvExecuteOrphanRegMethod);
    921   1.1.1.3    jruoho 
    922   1.1.1.3    jruoho 
    923  1.1.1.16  christos     if (!DeviceNode)
    924   1.1.1.3    jruoho     {
    925   1.1.1.3    jruoho         return_VOID;
    926   1.1.1.3    jruoho     }
    927   1.1.1.3    jruoho 
    928   1.1.1.3    jruoho     /* Namespace is currently locked, must release */
    929   1.1.1.3    jruoho 
    930   1.1.1.3    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    931   1.1.1.3    jruoho 
    932   1.1.1.3    jruoho     /* Get a handle to a _REG method immediately under the EC device */
    933   1.1.1.3    jruoho 
    934  1.1.1.16  christos     Status = AcpiGetHandle (DeviceNode, METHOD_NAME__REG, &RegMethod);
    935   1.1.1.3    jruoho     if (ACPI_FAILURE (Status))
    936   1.1.1.3    jruoho     {
    937   1.1.1.4  christos         goto Exit; /* There is no _REG method present */
    938   1.1.1.3    jruoho     }
    939   1.1.1.3    jruoho 
    940   1.1.1.3    jruoho     /*
    941   1.1.1.3    jruoho      * Execute the _REG method only if there is no Operation Region in
    942   1.1.1.3    jruoho      * this scope with the Embedded Controller space ID. Otherwise, it
    943   1.1.1.3    jruoho      * will already have been executed. Note, this allows for Regions
    944   1.1.1.3    jruoho      * with other space IDs to be present; but the code below will then
    945   1.1.1.4  christos      * execute the _REG method with the EmbeddedControl SpaceID argument.
    946   1.1.1.3    jruoho      */
    947  1.1.1.16  christos     NextNode = AcpiNsGetNextNode (DeviceNode, NULL);
    948   1.1.1.3    jruoho     while (NextNode)
    949   1.1.1.3    jruoho     {
    950   1.1.1.3    jruoho         if ((NextNode->Type == ACPI_TYPE_REGION) &&
    951   1.1.1.3    jruoho             (NextNode->Object) &&
    952  1.1.1.16  christos             (NextNode->Object->Region.SpaceId == SpaceId))
    953   1.1.1.3    jruoho         {
    954   1.1.1.4  christos             goto Exit; /* Do not execute the _REG */
    955   1.1.1.3    jruoho         }
    956   1.1.1.4  christos 
    957  1.1.1.16  christos         NextNode = AcpiNsGetNextNode (DeviceNode, NextNode);
    958   1.1.1.3    jruoho     }
    959   1.1.1.3    jruoho 
    960  1.1.1.16  christos     /* Evaluate the _REG(SpaceId,Connect) method */
    961   1.1.1.3    jruoho 
    962   1.1.1.3    jruoho     Args.Count = 2;
    963   1.1.1.3    jruoho     Args.Pointer = Objects;
    964   1.1.1.3    jruoho     Objects[0].Type = ACPI_TYPE_INTEGER;
    965  1.1.1.16  christos     Objects[0].Integer.Value = SpaceId;
    966   1.1.1.3    jruoho     Objects[1].Type = ACPI_TYPE_INTEGER;
    967   1.1.1.3    jruoho     Objects[1].Integer.Value = ACPI_REG_CONNECT;
    968   1.1.1.3    jruoho 
    969  1.1.1.14  christos     (void) AcpiEvaluateObject (RegMethod, NULL, &Args, NULL);
    970   1.1.1.3    jruoho 
    971   1.1.1.3    jruoho Exit:
    972   1.1.1.3    jruoho     /* We ignore all errors from above, don't care */
    973   1.1.1.3    jruoho 
    974  1.1.1.14  christos     (void) AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    975   1.1.1.3    jruoho     return_VOID;
    976   1.1.1.3    jruoho }
    977