Home | History | Annotate | Line # | Download | only in namespace
nseval.c revision 1.1.1.12
      1       1.1    jruoho /*******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: nseval - Object evaluation, includes control method execution
      4       1.1    jruoho  *
      5       1.1    jruoho  ******************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.10  christos  * Copyright (C) 2000 - 2018, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33   1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "acparser.h"
     47       1.1    jruoho #include "acinterp.h"
     48       1.1    jruoho #include "acnamesp.h"
     49       1.1    jruoho 
     50       1.1    jruoho 
     51       1.1    jruoho #define _COMPONENT          ACPI_NAMESPACE
     52       1.1    jruoho         ACPI_MODULE_NAME    ("nseval")
     53       1.1    jruoho 
     54       1.1    jruoho /* Local prototypes */
     55       1.1    jruoho 
     56       1.1    jruoho static void
     57       1.1    jruoho AcpiNsExecModuleCode (
     58       1.1    jruoho     ACPI_OPERAND_OBJECT     *MethodObj,
     59       1.1    jruoho     ACPI_EVALUATE_INFO      *Info);
     60       1.1    jruoho 
     61       1.1    jruoho 
     62       1.1    jruoho /*******************************************************************************
     63       1.1    jruoho  *
     64       1.1    jruoho  * FUNCTION:    AcpiNsEvaluate
     65       1.1    jruoho  *
     66   1.1.1.6  christos  * PARAMETERS:  Info            - Evaluation info block, contains these fields
     67   1.1.1.6  christos  *                                and more:
     68       1.1    jruoho  *                  PrefixNode      - Prefix or Method/Object Node to execute
     69   1.1.1.3  christos  *                  RelativePath    - Name of method to execute, If NULL, the
     70       1.1    jruoho  *                                    Node is the object to execute
     71       1.1    jruoho  *                  Parameters      - List of parameters to pass to the method,
     72       1.1    jruoho  *                                    terminated by NULL. Params itself may be
     73       1.1    jruoho  *                                    NULL if no parameters are being passed.
     74       1.1    jruoho  *                  ParameterType   - Type of Parameter list
     75       1.1    jruoho  *                  ReturnObject    - Where to put method's return value (if
     76       1.1    jruoho  *                                    any). If NULL, no value is returned.
     77       1.1    jruoho  *                  Flags           - ACPI_IGNORE_RETURN_VALUE to delete return
     78       1.1    jruoho  *
     79       1.1    jruoho  * RETURN:      Status
     80       1.1    jruoho  *
     81       1.1    jruoho  * DESCRIPTION: Execute a control method or return the current value of an
     82       1.1    jruoho  *              ACPI namespace object.
     83       1.1    jruoho  *
     84       1.1    jruoho  * MUTEX:       Locks interpreter
     85       1.1    jruoho  *
     86       1.1    jruoho  ******************************************************************************/
     87       1.1    jruoho 
     88       1.1    jruoho ACPI_STATUS
     89       1.1    jruoho AcpiNsEvaluate (
     90       1.1    jruoho     ACPI_EVALUATE_INFO      *Info)
     91       1.1    jruoho {
     92       1.1    jruoho     ACPI_STATUS             Status;
     93       1.1    jruoho 
     94       1.1    jruoho 
     95       1.1    jruoho     ACPI_FUNCTION_TRACE (NsEvaluate);
     96       1.1    jruoho 
     97       1.1    jruoho 
     98       1.1    jruoho     if (!Info)
     99       1.1    jruoho     {
    100       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    101       1.1    jruoho     }
    102       1.1    jruoho 
    103   1.1.1.3  christos     if (!Info->Node)
    104   1.1.1.3  christos     {
    105   1.1.1.3  christos         /*
    106   1.1.1.3  christos          * Get the actual namespace node for the target object if we
    107   1.1.1.3  christos          * need to. Handles these cases:
    108   1.1.1.3  christos          *
    109   1.1.1.3  christos          * 1) Null node, valid pathname from root (absolute path)
    110   1.1.1.3  christos          * 2) Node and valid pathname (path relative to Node)
    111   1.1.1.3  christos          * 3) Node, Null pathname
    112   1.1.1.3  christos          */
    113   1.1.1.3  christos         Status = AcpiNsGetNode (Info->PrefixNode, Info->RelativePathname,
    114   1.1.1.3  christos             ACPI_NS_NO_UPSEARCH, &Info->Node);
    115   1.1.1.3  christos         if (ACPI_FAILURE (Status))
    116   1.1.1.3  christos         {
    117   1.1.1.3  christos             return_ACPI_STATUS (Status);
    118   1.1.1.3  christos         }
    119   1.1.1.3  christos     }
    120   1.1.1.3  christos 
    121   1.1.1.3  christos     /*
    122   1.1.1.3  christos      * For a method alias, we must grab the actual method node so that
    123   1.1.1.3  christos      * proper scoping context will be established before execution.
    124   1.1.1.3  christos      */
    125   1.1.1.3  christos     if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
    126   1.1.1.3  christos     {
    127   1.1.1.3  christos         Info->Node = ACPI_CAST_PTR (
    128   1.1.1.3  christos             ACPI_NAMESPACE_NODE, Info->Node->Object);
    129   1.1.1.3  christos     }
    130   1.1.1.3  christos 
    131   1.1.1.3  christos     /* Complete the info block initialization */
    132       1.1    jruoho 
    133       1.1    jruoho     Info->ReturnObject = NULL;
    134   1.1.1.3  christos     Info->NodeFlags = Info->Node->Flags;
    135   1.1.1.3  christos     Info->ObjDesc = AcpiNsGetAttachedObject (Info->Node);
    136   1.1.1.3  christos 
    137   1.1.1.3  christos     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
    138   1.1.1.3  christos         Info->RelativePathname, Info->Node,
    139   1.1.1.3  christos         AcpiNsGetAttachedObject (Info->Node)));
    140   1.1.1.3  christos 
    141   1.1.1.3  christos     /* Get info if we have a predefined name (_HID, etc.) */
    142   1.1.1.3  christos 
    143   1.1.1.3  christos     Info->Predefined = AcpiUtMatchPredefinedMethod (Info->Node->Name.Ascii);
    144   1.1.1.3  christos 
    145   1.1.1.3  christos     /* Get the full pathname to the object, for use in warning messages */
    146   1.1.1.3  christos 
    147   1.1.1.7  christos     Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);
    148   1.1.1.3  christos     if (!Info->FullPathname)
    149   1.1.1.3  christos     {
    150   1.1.1.3  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    151   1.1.1.3  christos     }
    152   1.1.1.3  christos 
    153  1.1.1.12  christos     /* Optional object evaluation log */
    154  1.1.1.12  christos 
    155  1.1.1.12  christos     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,
    156  1.1.1.12  christos         "%-26s:  %s (%s)\n", "   Enter evaluation",
    157  1.1.1.12  christos         &Info->FullPathname[1], AcpiUtGetTypeName (Info->Node->Type)));
    158  1.1.1.12  christos 
    159   1.1.1.3  christos     /* Count the number of arguments being passed in */
    160   1.1.1.3  christos 
    161       1.1    jruoho     Info->ParamCount = 0;
    162   1.1.1.3  christos     if (Info->Parameters)
    163   1.1.1.3  christos     {
    164   1.1.1.3  christos         while (Info->Parameters[Info->ParamCount])
    165   1.1.1.3  christos         {
    166   1.1.1.3  christos             Info->ParamCount++;
    167   1.1.1.3  christos         }
    168   1.1.1.3  christos 
    169   1.1.1.3  christos         /* Warn on impossible argument count */
    170   1.1.1.3  christos 
    171   1.1.1.3  christos         if (Info->ParamCount > ACPI_METHOD_NUM_ARGS)
    172   1.1.1.3  christos         {
    173   1.1.1.3  christos             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,
    174   1.1.1.3  christos                 "Excess arguments (%u) - using only %u",
    175   1.1.1.3  christos                 Info->ParamCount, ACPI_METHOD_NUM_ARGS));
    176   1.1.1.3  christos 
    177   1.1.1.3  christos             Info->ParamCount = ACPI_METHOD_NUM_ARGS;
    178   1.1.1.3  christos         }
    179   1.1.1.3  christos     }
    180       1.1    jruoho 
    181       1.1    jruoho     /*
    182   1.1.1.3  christos      * For predefined names: Check that the declared argument count
    183   1.1.1.3  christos      * matches the ACPI spec -- otherwise this is a BIOS error.
    184       1.1    jruoho      */
    185   1.1.1.3  christos     AcpiNsCheckAcpiCompliance (Info->FullPathname, Info->Node,
    186   1.1.1.3  christos         Info->Predefined);
    187       1.1    jruoho 
    188       1.1    jruoho     /*
    189   1.1.1.3  christos      * For all names: Check that the incoming argument count for
    190   1.1.1.3  christos      * this method/object matches the actual ASL/AML definition.
    191       1.1    jruoho      */
    192   1.1.1.3  christos     AcpiNsCheckArgumentCount (Info->FullPathname, Info->Node,
    193   1.1.1.3  christos         Info->ParamCount, Info->Predefined);
    194       1.1    jruoho 
    195   1.1.1.3  christos     /* For predefined names: Typecheck all incoming arguments */
    196       1.1    jruoho 
    197   1.1.1.3  christos     AcpiNsCheckArgumentTypes (Info);
    198       1.1    jruoho 
    199       1.1    jruoho     /*
    200   1.1.1.3  christos      * Three major evaluation cases:
    201       1.1    jruoho      *
    202   1.1.1.3  christos      * 1) Object types that cannot be evaluated by definition
    203   1.1.1.3  christos      * 2) The object is a control method -- execute it
    204   1.1.1.3  christos      * 3) The object is not a method -- just return it's current value
    205       1.1    jruoho      */
    206   1.1.1.3  christos     switch (AcpiNsGetType (Info->Node))
    207       1.1    jruoho     {
    208  1.1.1.10  christos     case ACPI_TYPE_ANY:
    209   1.1.1.3  christos     case ACPI_TYPE_DEVICE:
    210   1.1.1.3  christos     case ACPI_TYPE_EVENT:
    211   1.1.1.3  christos     case ACPI_TYPE_MUTEX:
    212   1.1.1.3  christos     case ACPI_TYPE_REGION:
    213   1.1.1.3  christos     case ACPI_TYPE_THERMAL:
    214   1.1.1.3  christos     case ACPI_TYPE_LOCAL_SCOPE:
    215       1.1    jruoho         /*
    216  1.1.1.10  christos          * 1) Disallow evaluation of these object types. For these,
    217  1.1.1.10  christos          *    object evaluation is undefined.
    218       1.1    jruoho          */
    219   1.1.1.3  christos         ACPI_ERROR ((AE_INFO,
    220  1.1.1.10  christos             "%s: This object type [%s] "
    221  1.1.1.10  christos             "never contains data and cannot be evaluated",
    222  1.1.1.10  christos             Info->FullPathname, AcpiUtGetTypeName (Info->Node->Type)));
    223       1.1    jruoho 
    224   1.1.1.3  christos         Status = AE_TYPE;
    225   1.1.1.3  christos         goto Cleanup;
    226       1.1    jruoho 
    227   1.1.1.3  christos     case ACPI_TYPE_METHOD:
    228   1.1.1.3  christos         /*
    229   1.1.1.3  christos          * 2) Object is a control method - execute it
    230   1.1.1.3  christos          */
    231       1.1    jruoho 
    232   1.1.1.3  christos         /* Verify that there is a method object associated with this node */
    233       1.1    jruoho 
    234   1.1.1.3  christos         if (!Info->ObjDesc)
    235       1.1    jruoho         {
    236   1.1.1.3  christos             ACPI_ERROR ((AE_INFO, "%s: Method has no attached sub-object",
    237   1.1.1.3  christos                 Info->FullPathname));
    238   1.1.1.3  christos             Status = AE_NULL_OBJECT;
    239   1.1.1.3  christos             goto Cleanup;
    240       1.1    jruoho         }
    241       1.1    jruoho 
    242       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    243   1.1.1.3  christos             "**** Execute method [%s] at AML address %p length %X\n",
    244   1.1.1.3  christos             Info->FullPathname,
    245       1.1    jruoho             Info->ObjDesc->Method.AmlStart + 1,
    246       1.1    jruoho             Info->ObjDesc->Method.AmlLength - 1));
    247       1.1    jruoho 
    248       1.1    jruoho         /*
    249       1.1    jruoho          * Any namespace deletion must acquire both the namespace and
    250       1.1    jruoho          * interpreter locks to ensure that no thread is using the portion of
    251       1.1    jruoho          * the namespace that is being deleted.
    252       1.1    jruoho          *
    253       1.1    jruoho          * Execute the method via the interpreter. The interpreter is locked
    254       1.1    jruoho          * here before calling into the AML parser
    255       1.1    jruoho          */
    256       1.1    jruoho         AcpiExEnterInterpreter ();
    257       1.1    jruoho         Status = AcpiPsExecuteMethod (Info);
    258       1.1    jruoho         AcpiExExitInterpreter ();
    259   1.1.1.3  christos         break;
    260   1.1.1.3  christos 
    261   1.1.1.3  christos     default:
    262       1.1    jruoho         /*
    263   1.1.1.3  christos          * 3) All other non-method objects -- get the current object value
    264       1.1    jruoho          */
    265       1.1    jruoho 
    266       1.1    jruoho         /*
    267   1.1.1.3  christos          * Some objects require additional resolution steps (e.g., the Node
    268   1.1.1.3  christos          * may be a field that must be read, etc.) -- we can't just grab
    269   1.1.1.3  christos          * the object out of the node.
    270       1.1    jruoho          *
    271       1.1    jruoho          * Use ResolveNodeToValue() to get the associated value.
    272       1.1    jruoho          *
    273       1.1    jruoho          * NOTE: we can get away with passing in NULL for a walk state because
    274   1.1.1.3  christos          * the Node is guaranteed to not be a reference to either a method
    275       1.1    jruoho          * local or a method argument (because this interface is never called
    276       1.1    jruoho          * from a running method.)
    277       1.1    jruoho          *
    278       1.1    jruoho          * Even though we do not directly invoke the interpreter for object
    279   1.1.1.3  christos          * resolution, we must lock it because we could access an OpRegion.
    280   1.1.1.3  christos          * The OpRegion access code assumes that the interpreter is locked.
    281       1.1    jruoho          */
    282       1.1    jruoho         AcpiExEnterInterpreter ();
    283       1.1    jruoho 
    284   1.1.1.3  christos         /* TBD: ResolveNodeToValue has a strange interface, fix */
    285   1.1.1.3  christos 
    286   1.1.1.3  christos         Info->ReturnObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->Node);
    287       1.1    jruoho 
    288   1.1.1.3  christos         Status = AcpiExResolveNodeToValue (ACPI_CAST_INDIRECT_PTR (
    289   1.1.1.3  christos             ACPI_NAMESPACE_NODE, &Info->ReturnObject), NULL);
    290       1.1    jruoho         AcpiExExitInterpreter ();
    291       1.1    jruoho 
    292   1.1.1.3  christos         if (ACPI_FAILURE (Status))
    293       1.1    jruoho         {
    294   1.1.1.7  christos             Info->ReturnObject = NULL;
    295   1.1.1.3  christos             goto Cleanup;
    296       1.1    jruoho         }
    297   1.1.1.3  christos 
    298   1.1.1.3  christos         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returned object %p [%s]\n",
    299   1.1.1.3  christos             Info->ReturnObject,
    300   1.1.1.3  christos             AcpiUtGetObjectTypeName (Info->ReturnObject)));
    301   1.1.1.3  christos 
    302   1.1.1.3  christos         Status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */
    303   1.1.1.3  christos         break;
    304       1.1    jruoho     }
    305       1.1    jruoho 
    306       1.1    jruoho     /*
    307   1.1.1.3  christos      * For predefined names, check the return value against the ACPI
    308   1.1.1.3  christos      * specification. Some incorrect return value types are repaired.
    309       1.1    jruoho      */
    310   1.1.1.3  christos     (void) AcpiNsCheckReturnValue (Info->Node, Info, Info->ParamCount,
    311   1.1.1.3  christos         Status, &Info->ReturnObject);
    312       1.1    jruoho 
    313       1.1    jruoho     /* Check if there is a return value that must be dealt with */
    314       1.1    jruoho 
    315       1.1    jruoho     if (Status == AE_CTRL_RETURN_VALUE)
    316       1.1    jruoho     {
    317       1.1    jruoho         /* If caller does not want the return value, delete it */
    318       1.1    jruoho 
    319       1.1    jruoho         if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
    320       1.1    jruoho         {
    321       1.1    jruoho             AcpiUtRemoveReference (Info->ReturnObject);
    322       1.1    jruoho             Info->ReturnObject = NULL;
    323       1.1    jruoho         }
    324       1.1    jruoho 
    325       1.1    jruoho         /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
    326       1.1    jruoho 
    327       1.1    jruoho         Status = AE_OK;
    328       1.1    jruoho     }
    329  1.1.1.11  christos     else if (ACPI_FAILURE(Status))
    330  1.1.1.10  christos     {
    331  1.1.1.10  christos         /* If ReturnObject exists, delete it */
    332  1.1.1.10  christos 
    333  1.1.1.11  christos         if (Info->ReturnObject)
    334  1.1.1.10  christos         {
    335  1.1.1.10  christos             AcpiUtRemoveReference (Info->ReturnObject);
    336  1.1.1.10  christos             Info->ReturnObject = NULL;
    337  1.1.1.10  christos         }
    338  1.1.1.10  christos     }
    339       1.1    jruoho 
    340       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    341   1.1.1.3  christos         "*** Completed evaluation of object %s ***\n",
    342   1.1.1.3  christos         Info->RelativePathname));
    343       1.1    jruoho 
    344   1.1.1.3  christos Cleanup:
    345  1.1.1.12  christos     /* Optional object evaluation log */
    346  1.1.1.12  christos 
    347  1.1.1.12  christos     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,
    348  1.1.1.12  christos         "%-26s:  %s\n", "   Exit evaluation",
    349  1.1.1.12  christos         &Info->FullPathname[1]));
    350  1.1.1.12  christos 
    351       1.1    jruoho     /*
    352       1.1    jruoho      * Namespace was unlocked by the handling AcpiNs* function, so we
    353   1.1.1.3  christos      * just free the pathname and return
    354       1.1    jruoho      */
    355   1.1.1.3  christos     ACPI_FREE (Info->FullPathname);
    356   1.1.1.3  christos     Info->FullPathname = NULL;
    357       1.1    jruoho     return_ACPI_STATUS (Status);
    358       1.1    jruoho }
    359       1.1    jruoho 
    360       1.1    jruoho 
    361       1.1    jruoho /*******************************************************************************
    362       1.1    jruoho  *
    363       1.1    jruoho  * FUNCTION:    AcpiNsExecModuleCodeList
    364       1.1    jruoho  *
    365       1.1    jruoho  * PARAMETERS:  None
    366       1.1    jruoho  *
    367       1.1    jruoho  * RETURN:      None. Exceptions during method execution are ignored, since
    368       1.1    jruoho  *              we cannot abort a table load.
    369       1.1    jruoho  *
    370       1.1    jruoho  * DESCRIPTION: Execute all elements of the global module-level code list.
    371       1.1    jruoho  *              Each element is executed as a single control method.
    372       1.1    jruoho  *
    373  1.1.1.10  christos  * NOTE: With this option enabled, each block of detected executable AML
    374  1.1.1.10  christos  * code that is outside of any control method is wrapped with a temporary
    375  1.1.1.10  christos  * control method object and placed on a global list. The methods on this
    376  1.1.1.10  christos  * list are executed below.
    377  1.1.1.10  christos  *
    378  1.1.1.10  christos  * This function executes the module-level code for all tables only after
    379  1.1.1.10  christos  * all of the tables have been loaded. It is a legacy option and is
    380  1.1.1.10  christos  * not compatible with other ACPI implementations. See AcpiNsLoadTable.
    381  1.1.1.10  christos  *
    382  1.1.1.10  christos  * This function will be removed when the legacy option is removed.
    383  1.1.1.10  christos  *
    384       1.1    jruoho  ******************************************************************************/
    385       1.1    jruoho 
    386       1.1    jruoho void
    387       1.1    jruoho AcpiNsExecModuleCodeList (
    388       1.1    jruoho     void)
    389       1.1    jruoho {
    390       1.1    jruoho     ACPI_OPERAND_OBJECT     *Prev;
    391       1.1    jruoho     ACPI_OPERAND_OBJECT     *Next;
    392       1.1    jruoho     ACPI_EVALUATE_INFO      *Info;
    393       1.1    jruoho     UINT32                  MethodCount = 0;
    394       1.1    jruoho 
    395       1.1    jruoho 
    396       1.1    jruoho     ACPI_FUNCTION_TRACE (NsExecModuleCodeList);
    397       1.1    jruoho 
    398       1.1    jruoho 
    399       1.1    jruoho     /* Exit now if the list is empty */
    400       1.1    jruoho 
    401       1.1    jruoho     Next = AcpiGbl_ModuleCodeList;
    402       1.1    jruoho     if (!Next)
    403       1.1    jruoho     {
    404  1.1.1.10  christos         ACPI_DEBUG_PRINT ((ACPI_DB_INIT_NAMES,
    405  1.1.1.10  christos             "Legacy MLC block list is empty\n"));
    406  1.1.1.10  christos 
    407       1.1    jruoho         return_VOID;
    408       1.1    jruoho     }
    409       1.1    jruoho 
    410       1.1    jruoho     /* Allocate the evaluation information block */
    411       1.1    jruoho 
    412       1.1    jruoho     Info = ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO));
    413       1.1    jruoho     if (!Info)
    414       1.1    jruoho     {
    415       1.1    jruoho         return_VOID;
    416       1.1    jruoho     }
    417       1.1    jruoho 
    418       1.1    jruoho     /* Walk the list, executing each "method" */
    419       1.1    jruoho 
    420       1.1    jruoho     while (Next)
    421       1.1    jruoho     {
    422       1.1    jruoho         Prev = Next;
    423       1.1    jruoho         Next = Next->Method.Mutex;
    424       1.1    jruoho 
    425       1.1    jruoho         /* Clear the link field and execute the method */
    426       1.1    jruoho 
    427       1.1    jruoho         Prev->Method.Mutex = NULL;
    428       1.1    jruoho         AcpiNsExecModuleCode (Prev, Info);
    429       1.1    jruoho         MethodCount++;
    430       1.1    jruoho 
    431       1.1    jruoho         /* Delete the (temporary) method object */
    432       1.1    jruoho 
    433       1.1    jruoho         AcpiUtRemoveReference (Prev);
    434       1.1    jruoho     }
    435       1.1    jruoho 
    436   1.1.1.8  christos     ACPI_INFO ((
    437       1.1    jruoho         "Executed %u blocks of module-level executable AML code",
    438       1.1    jruoho         MethodCount));
    439       1.1    jruoho 
    440       1.1    jruoho     ACPI_FREE (Info);
    441       1.1    jruoho     AcpiGbl_ModuleCodeList = NULL;
    442       1.1    jruoho     return_VOID;
    443       1.1    jruoho }
    444       1.1    jruoho 
    445       1.1    jruoho 
    446       1.1    jruoho /*******************************************************************************
    447       1.1    jruoho  *
    448       1.1    jruoho  * FUNCTION:    AcpiNsExecModuleCode
    449       1.1    jruoho  *
    450       1.1    jruoho  * PARAMETERS:  MethodObj           - Object container for the module-level code
    451       1.1    jruoho  *              Info                - Info block for method evaluation
    452       1.1    jruoho  *
    453       1.1    jruoho  * RETURN:      None. Exceptions during method execution are ignored, since
    454       1.1    jruoho  *              we cannot abort a table load.
    455       1.1    jruoho  *
    456       1.1    jruoho  * DESCRIPTION: Execute a control method containing a block of module-level
    457       1.1    jruoho  *              executable AML code. The control method is temporarily
    458       1.1    jruoho  *              installed to the root node, then evaluated.
    459       1.1    jruoho  *
    460       1.1    jruoho  ******************************************************************************/
    461       1.1    jruoho 
    462       1.1    jruoho static void
    463       1.1    jruoho AcpiNsExecModuleCode (
    464       1.1    jruoho     ACPI_OPERAND_OBJECT     *MethodObj,
    465       1.1    jruoho     ACPI_EVALUATE_INFO      *Info)
    466       1.1    jruoho {
    467       1.1    jruoho     ACPI_OPERAND_OBJECT     *ParentObj;
    468       1.1    jruoho     ACPI_NAMESPACE_NODE     *ParentNode;
    469       1.1    jruoho     ACPI_OBJECT_TYPE        Type;
    470       1.1    jruoho     ACPI_STATUS             Status;
    471       1.1    jruoho 
    472       1.1    jruoho 
    473       1.1    jruoho     ACPI_FUNCTION_TRACE (NsExecModuleCode);
    474       1.1    jruoho 
    475       1.1    jruoho 
    476       1.1    jruoho     /*
    477       1.1    jruoho      * Get the parent node. We cheat by using the NextObject field
    478       1.1    jruoho      * of the method object descriptor.
    479       1.1    jruoho      */
    480   1.1.1.7  christos     ParentNode = ACPI_CAST_PTR (
    481   1.1.1.7  christos         ACPI_NAMESPACE_NODE, MethodObj->Method.NextObject);
    482       1.1    jruoho     Type = AcpiNsGetType (ParentNode);
    483       1.1    jruoho 
    484       1.1    jruoho     /*
    485       1.1    jruoho      * Get the region handler and save it in the method object. We may need
    486       1.1    jruoho      * this if an operation region declaration causes a _REG method to be run.
    487       1.1    jruoho      *
    488       1.1    jruoho      * We can't do this in AcpiPsLinkModuleCode because
    489       1.1    jruoho      * AcpiGbl_RootNode->Object is NULL at PASS1.
    490       1.1    jruoho      */
    491       1.1    jruoho     if ((Type == ACPI_TYPE_DEVICE) && ParentNode->Object)
    492       1.1    jruoho     {
    493   1.1.1.2    jruoho         MethodObj->Method.Dispatch.Handler =
    494       1.1    jruoho             ParentNode->Object->Device.Handler;
    495       1.1    jruoho     }
    496       1.1    jruoho 
    497       1.1    jruoho     /* Must clear NextObject (AcpiNsAttachObject needs the field) */
    498       1.1    jruoho 
    499       1.1    jruoho     MethodObj->Method.NextObject = NULL;
    500       1.1    jruoho 
    501       1.1    jruoho     /* Initialize the evaluation information block */
    502       1.1    jruoho 
    503   1.1.1.6  christos     memset (Info, 0, sizeof (ACPI_EVALUATE_INFO));
    504       1.1    jruoho     Info->PrefixNode = ParentNode;
    505       1.1    jruoho 
    506       1.1    jruoho     /*
    507   1.1.1.7  christos      * Get the currently attached parent object. Add a reference,
    508   1.1.1.7  christos      * because the ref count will be decreased when the method object
    509   1.1.1.7  christos      * is installed to the parent node.
    510       1.1    jruoho      */
    511       1.1    jruoho     ParentObj = AcpiNsGetAttachedObject (ParentNode);
    512       1.1    jruoho     if (ParentObj)
    513       1.1    jruoho     {
    514       1.1    jruoho         AcpiUtAddReference (ParentObj);
    515       1.1    jruoho     }
    516       1.1    jruoho 
    517       1.1    jruoho     /* Install the method (module-level code) in the parent node */
    518       1.1    jruoho 
    519   1.1.1.7  christos     Status = AcpiNsAttachObject (ParentNode, MethodObj, ACPI_TYPE_METHOD);
    520       1.1    jruoho     if (ACPI_FAILURE (Status))
    521       1.1    jruoho     {
    522       1.1    jruoho         goto Exit;
    523       1.1    jruoho     }
    524       1.1    jruoho 
    525       1.1    jruoho     /* Execute the parent node as a control method */
    526       1.1    jruoho 
    527       1.1    jruoho     Status = AcpiNsEvaluate (Info);
    528       1.1    jruoho 
    529   1.1.1.7  christos     ACPI_DEBUG_PRINT ((ACPI_DB_INIT_NAMES,
    530   1.1.1.7  christos         "Executed module-level code at %p\n",
    531       1.1    jruoho         MethodObj->Method.AmlStart));
    532       1.1    jruoho 
    533       1.1    jruoho     /* Delete a possible implicit return value (in slack mode) */
    534       1.1    jruoho 
    535       1.1    jruoho     if (Info->ReturnObject)
    536       1.1    jruoho     {
    537       1.1    jruoho         AcpiUtRemoveReference (Info->ReturnObject);
    538       1.1    jruoho     }
    539       1.1    jruoho 
    540       1.1    jruoho     /* Detach the temporary method object */
    541       1.1    jruoho 
    542       1.1    jruoho     AcpiNsDetachObject (ParentNode);
    543       1.1    jruoho 
    544       1.1    jruoho     /* Restore the original parent object */
    545       1.1    jruoho 
    546       1.1    jruoho     if (ParentObj)
    547       1.1    jruoho     {
    548       1.1    jruoho         Status = AcpiNsAttachObject (ParentNode, ParentObj, Type);
    549       1.1    jruoho     }
    550       1.1    jruoho     else
    551       1.1    jruoho     {
    552       1.1    jruoho         ParentNode->Type = (UINT8) Type;
    553       1.1    jruoho     }
    554       1.1    jruoho 
    555       1.1    jruoho Exit:
    556       1.1    jruoho     if (ParentObj)
    557       1.1    jruoho     {
    558       1.1    jruoho         AcpiUtRemoveReference (ParentObj);
    559       1.1    jruoho     }
    560       1.1    jruoho     return_VOID;
    561       1.1    jruoho }
    562