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