Home | History | Annotate | Line # | Download | only in dispatcher
dsmethod.c revision 1.1.1.7
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.7  christos  * Copyright (C) 2000 - 2016, 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 "acdispat.h"
     47      1.1    jruoho #include "acinterp.h"
     48      1.1    jruoho #include "acnamesp.h"
     49  1.1.1.4  christos #include "acparser.h"
     50  1.1.1.4  christos #include "amlcode.h"
     51  1.1.1.6  christos #include "acdebug.h"
     52      1.1    jruoho 
     53      1.1    jruoho 
     54      1.1    jruoho #define _COMPONENT          ACPI_DISPATCHER
     55      1.1    jruoho         ACPI_MODULE_NAME    ("dsmethod")
     56      1.1    jruoho 
     57      1.1    jruoho /* Local prototypes */
     58      1.1    jruoho 
     59      1.1    jruoho static ACPI_STATUS
     60  1.1.1.4  christos AcpiDsDetectNamedOpcodes (
     61  1.1.1.4  christos     ACPI_WALK_STATE         *WalkState,
     62  1.1.1.4  christos     ACPI_PARSE_OBJECT       **OutOp);
     63  1.1.1.4  christos 
     64  1.1.1.4  christos static ACPI_STATUS
     65      1.1    jruoho AcpiDsCreateMethodMutex (
     66      1.1    jruoho     ACPI_OPERAND_OBJECT     *MethodDesc);
     67      1.1    jruoho 
     68      1.1    jruoho 
     69      1.1    jruoho /*******************************************************************************
     70      1.1    jruoho  *
     71  1.1.1.4  christos  * FUNCTION:    AcpiDsAutoSerializeMethod
     72  1.1.1.4  christos  *
     73  1.1.1.4  christos  * PARAMETERS:  Node                        - Namespace Node of the method
     74  1.1.1.4  christos  *              ObjDesc                     - Method object attached to node
     75  1.1.1.4  christos  *
     76  1.1.1.4  christos  * RETURN:      Status
     77  1.1.1.4  christos  *
     78  1.1.1.4  christos  * DESCRIPTION: Parse a control method AML to scan for control methods that
     79  1.1.1.4  christos  *              need serialization due to the creation of named objects.
     80  1.1.1.4  christos  *
     81  1.1.1.4  christos  * NOTE: It is a bit of overkill to mark all such methods serialized, since
     82  1.1.1.4  christos  * there is only a problem if the method actually blocks during execution.
     83  1.1.1.4  christos  * A blocking operation is, for example, a Sleep() operation, or any access
     84  1.1.1.4  christos  * to an operation region. However, it is probably not possible to easily
     85  1.1.1.4  christos  * detect whether a method will block or not, so we simply mark all suspicious
     86  1.1.1.4  christos  * methods as serialized.
     87  1.1.1.4  christos  *
     88  1.1.1.4  christos  * NOTE2: This code is essentially a generic routine for parsing a single
     89  1.1.1.4  christos  * control method.
     90  1.1.1.4  christos  *
     91  1.1.1.4  christos  ******************************************************************************/
     92  1.1.1.4  christos 
     93  1.1.1.4  christos ACPI_STATUS
     94  1.1.1.4  christos AcpiDsAutoSerializeMethod (
     95  1.1.1.4  christos     ACPI_NAMESPACE_NODE     *Node,
     96  1.1.1.4  christos     ACPI_OPERAND_OBJECT     *ObjDesc)
     97  1.1.1.4  christos {
     98  1.1.1.4  christos     ACPI_STATUS             Status;
     99  1.1.1.4  christos     ACPI_PARSE_OBJECT       *Op = NULL;
    100  1.1.1.4  christos     ACPI_WALK_STATE         *WalkState;
    101  1.1.1.4  christos 
    102  1.1.1.4  christos 
    103  1.1.1.4  christos     ACPI_FUNCTION_TRACE_PTR (DsAutoSerializeMethod, Node);
    104  1.1.1.4  christos 
    105  1.1.1.4  christos 
    106  1.1.1.4  christos     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
    107  1.1.1.4  christos         "Method auto-serialization parse [%4.4s] %p\n",
    108  1.1.1.4  christos         AcpiUtGetNodeName (Node), Node));
    109  1.1.1.4  christos 
    110  1.1.1.4  christos     /* Create/Init a root op for the method parse tree */
    111  1.1.1.4  christos 
    112  1.1.1.6  christos     Op = AcpiPsAllocOp (AML_METHOD_OP, ObjDesc->Method.AmlStart);
    113  1.1.1.4  christos     if (!Op)
    114  1.1.1.4  christos     {
    115  1.1.1.4  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    116  1.1.1.4  christos     }
    117  1.1.1.4  christos 
    118  1.1.1.4  christos     AcpiPsSetName (Op, Node->Name.Integer);
    119  1.1.1.4  christos     Op->Common.Node = Node;
    120  1.1.1.4  christos 
    121  1.1.1.4  christos     /* Create and initialize a new walk state */
    122  1.1.1.4  christos 
    123  1.1.1.4  christos     WalkState = AcpiDsCreateWalkState (Node->OwnerId, NULL, NULL, NULL);
    124  1.1.1.4  christos     if (!WalkState)
    125  1.1.1.4  christos     {
    126  1.1.1.6  christos         AcpiPsFreeOp (Op);
    127  1.1.1.4  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    128  1.1.1.4  christos     }
    129  1.1.1.4  christos 
    130  1.1.1.7  christos     Status = AcpiDsInitAmlWalk (WalkState, Op, Node,
    131  1.1.1.7  christos         ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength, NULL, 0);
    132  1.1.1.4  christos     if (ACPI_FAILURE (Status))
    133  1.1.1.4  christos     {
    134  1.1.1.4  christos         AcpiDsDeleteWalkState (WalkState);
    135  1.1.1.6  christos         AcpiPsFreeOp (Op);
    136  1.1.1.4  christos         return_ACPI_STATUS (Status);
    137  1.1.1.4  christos     }
    138  1.1.1.4  christos 
    139  1.1.1.4  christos     WalkState->DescendingCallback = AcpiDsDetectNamedOpcodes;
    140  1.1.1.4  christos 
    141  1.1.1.4  christos     /* Parse the method, scan for creation of named objects */
    142  1.1.1.4  christos 
    143  1.1.1.4  christos     Status = AcpiPsParseAml (WalkState);
    144  1.1.1.4  christos 
    145  1.1.1.4  christos     AcpiPsDeleteParseTree (Op);
    146  1.1.1.4  christos     return_ACPI_STATUS (Status);
    147  1.1.1.4  christos }
    148  1.1.1.4  christos 
    149  1.1.1.4  christos 
    150  1.1.1.4  christos /*******************************************************************************
    151  1.1.1.4  christos  *
    152  1.1.1.4  christos  * FUNCTION:    AcpiDsDetectNamedOpcodes
    153  1.1.1.4  christos  *
    154  1.1.1.4  christos  * PARAMETERS:  WalkState       - Current state of the parse tree walk
    155  1.1.1.4  christos  *              OutOp           - Unused, required for parser interface
    156  1.1.1.4  christos  *
    157  1.1.1.4  christos  * RETURN:      Status
    158  1.1.1.4  christos  *
    159  1.1.1.4  christos  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
    160  1.1.1.4  christos  *              Currently used to detect methods that must be marked serialized
    161  1.1.1.4  christos  *              in order to avoid problems with the creation of named objects.
    162  1.1.1.4  christos  *
    163  1.1.1.4  christos  ******************************************************************************/
    164  1.1.1.4  christos 
    165  1.1.1.4  christos static ACPI_STATUS
    166  1.1.1.4  christos AcpiDsDetectNamedOpcodes (
    167  1.1.1.4  christos     ACPI_WALK_STATE         *WalkState,
    168  1.1.1.4  christos     ACPI_PARSE_OBJECT       **OutOp)
    169  1.1.1.4  christos {
    170  1.1.1.4  christos 
    171  1.1.1.4  christos     ACPI_FUNCTION_NAME (AcpiDsDetectNamedOpcodes);
    172  1.1.1.4  christos 
    173  1.1.1.4  christos 
    174  1.1.1.4  christos     /* We are only interested in opcodes that create a new name */
    175  1.1.1.4  christos 
    176  1.1.1.4  christos     if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_FIELD)))
    177  1.1.1.4  christos     {
    178  1.1.1.4  christos         return (AE_OK);
    179  1.1.1.4  christos     }
    180  1.1.1.4  christos 
    181  1.1.1.4  christos     /*
    182  1.1.1.4  christos      * At this point, we know we have a Named object opcode.
    183  1.1.1.4  christos      * Mark the method as serialized. Later code will create a mutex for
    184  1.1.1.4  christos      * this method to enforce serialization.
    185  1.1.1.4  christos      *
    186  1.1.1.4  christos      * Note, ACPI_METHOD_IGNORE_SYNC_LEVEL flag means that we will ignore the
    187  1.1.1.4  christos      * Sync Level mechanism for this method, even though it is now serialized.
    188  1.1.1.4  christos      * Otherwise, there can be conflicts with existing ASL code that actually
    189  1.1.1.4  christos      * uses sync levels.
    190  1.1.1.4  christos      */
    191  1.1.1.4  christos     WalkState->MethodDesc->Method.SyncLevel = 0;
    192  1.1.1.4  christos     WalkState->MethodDesc->Method.InfoFlags |=
    193  1.1.1.4  christos         (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
    194  1.1.1.4  christos 
    195  1.1.1.4  christos     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    196  1.1.1.4  christos         "Method serialized [%4.4s] %p - [%s] (%4.4X)\n",
    197  1.1.1.4  christos         WalkState->MethodNode->Name.Ascii, WalkState->MethodNode,
    198  1.1.1.4  christos         WalkState->OpInfo->Name, WalkState->Opcode));
    199  1.1.1.4  christos 
    200  1.1.1.4  christos     /* Abort the parse, no need to examine this method any further */
    201  1.1.1.4  christos 
    202  1.1.1.4  christos     return (AE_CTRL_TERMINATE);
    203  1.1.1.4  christos }
    204  1.1.1.4  christos 
    205  1.1.1.4  christos 
    206  1.1.1.4  christos /*******************************************************************************
    207  1.1.1.4  christos  *
    208      1.1    jruoho  * FUNCTION:    AcpiDsMethodError
    209      1.1    jruoho  *
    210      1.1    jruoho  * PARAMETERS:  Status          - Execution status
    211      1.1    jruoho  *              WalkState       - Current state
    212      1.1    jruoho  *
    213      1.1    jruoho  * RETURN:      Status
    214      1.1    jruoho  *
    215      1.1    jruoho  * DESCRIPTION: Called on method error. Invoke the global exception handler if
    216  1.1.1.6  christos  *              present, dump the method data if the debugger is configured
    217      1.1    jruoho  *
    218      1.1    jruoho  *              Note: Allows the exception handler to change the status code
    219      1.1    jruoho  *
    220      1.1    jruoho  ******************************************************************************/
    221      1.1    jruoho 
    222      1.1    jruoho ACPI_STATUS
    223      1.1    jruoho AcpiDsMethodError (
    224      1.1    jruoho     ACPI_STATUS             Status,
    225      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    226      1.1    jruoho {
    227  1.1.1.6  christos     UINT32                  AmlOffset;
    228  1.1.1.6  christos 
    229  1.1.1.6  christos 
    230      1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    231      1.1    jruoho 
    232      1.1    jruoho 
    233      1.1    jruoho     /* Ignore AE_OK and control exception codes */
    234      1.1    jruoho 
    235      1.1    jruoho     if (ACPI_SUCCESS (Status) ||
    236      1.1    jruoho         (Status & AE_CODE_CONTROL))
    237      1.1    jruoho     {
    238      1.1    jruoho         return (Status);
    239      1.1    jruoho     }
    240      1.1    jruoho 
    241      1.1    jruoho     /* Invoke the global exception handler */
    242      1.1    jruoho 
    243      1.1    jruoho     if (AcpiGbl_ExceptionHandler)
    244      1.1    jruoho     {
    245      1.1    jruoho         /* Exit the interpreter, allow handler to execute methods */
    246      1.1    jruoho 
    247      1.1    jruoho         AcpiExExitInterpreter ();
    248      1.1    jruoho 
    249      1.1    jruoho         /*
    250      1.1    jruoho          * Handler can map the exception code to anything it wants, including
    251      1.1    jruoho          * AE_OK, in which case the executing method will not be aborted.
    252      1.1    jruoho          */
    253  1.1.1.6  christos         AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,
    254  1.1.1.7  christos             WalkState->ParserState.AmlStart);
    255  1.1.1.6  christos 
    256      1.1    jruoho         Status = AcpiGbl_ExceptionHandler (Status,
    257  1.1.1.7  christos             WalkState->MethodNode ?
    258  1.1.1.7  christos                 WalkState->MethodNode->Name.Integer : 0,
    259  1.1.1.7  christos             WalkState->Opcode, AmlOffset, NULL);
    260      1.1    jruoho         AcpiExEnterInterpreter ();
    261      1.1    jruoho     }
    262      1.1    jruoho 
    263      1.1    jruoho     AcpiDsClearImplicitReturn (WalkState);
    264      1.1    jruoho 
    265      1.1    jruoho     if (ACPI_FAILURE (Status))
    266      1.1    jruoho     {
    267  1.1.1.6  christos         AcpiDsDumpMethodStack (Status, WalkState, WalkState->Op);
    268      1.1    jruoho 
    269  1.1.1.6  christos         /* Display method locals/args if debugger is present */
    270  1.1.1.6  christos 
    271  1.1.1.6  christos #ifdef ACPI_DEBUGGER
    272  1.1.1.6  christos         AcpiDbDumpMethodInfo (Status, WalkState);
    273      1.1    jruoho #endif
    274  1.1.1.6  christos     }
    275      1.1    jruoho 
    276      1.1    jruoho     return (Status);
    277      1.1    jruoho }
    278      1.1    jruoho 
    279      1.1    jruoho 
    280      1.1    jruoho /*******************************************************************************
    281      1.1    jruoho  *
    282      1.1    jruoho  * FUNCTION:    AcpiDsCreateMethodMutex
    283      1.1    jruoho  *
    284      1.1    jruoho  * PARAMETERS:  ObjDesc             - The method object
    285      1.1    jruoho  *
    286      1.1    jruoho  * RETURN:      Status
    287      1.1    jruoho  *
    288      1.1    jruoho  * DESCRIPTION: Create a mutex object for a serialized control method
    289      1.1    jruoho  *
    290      1.1    jruoho  ******************************************************************************/
    291      1.1    jruoho 
    292      1.1    jruoho static ACPI_STATUS
    293      1.1    jruoho AcpiDsCreateMethodMutex (
    294      1.1    jruoho     ACPI_OPERAND_OBJECT     *MethodDesc)
    295      1.1    jruoho {
    296      1.1    jruoho     ACPI_OPERAND_OBJECT     *MutexDesc;
    297      1.1    jruoho     ACPI_STATUS             Status;
    298      1.1    jruoho 
    299      1.1    jruoho 
    300      1.1    jruoho     ACPI_FUNCTION_TRACE (DsCreateMethodMutex);
    301      1.1    jruoho 
    302      1.1    jruoho 
    303      1.1    jruoho     /* Create the new mutex object */
    304      1.1    jruoho 
    305      1.1    jruoho     MutexDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
    306      1.1    jruoho     if (!MutexDesc)
    307      1.1    jruoho     {
    308      1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    309      1.1    jruoho     }
    310      1.1    jruoho 
    311      1.1    jruoho     /* Create the actual OS Mutex */
    312      1.1    jruoho 
    313      1.1    jruoho     Status = AcpiOsCreateMutex (&MutexDesc->Mutex.OsMutex);
    314      1.1    jruoho     if (ACPI_FAILURE (Status))
    315      1.1    jruoho     {
    316  1.1.1.3  christos         AcpiUtDeleteObjectDesc (MutexDesc);
    317      1.1    jruoho         return_ACPI_STATUS (Status);
    318      1.1    jruoho     }
    319      1.1    jruoho 
    320      1.1    jruoho     MutexDesc->Mutex.SyncLevel = MethodDesc->Method.SyncLevel;
    321      1.1    jruoho     MethodDesc->Method.Mutex = MutexDesc;
    322      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    323      1.1    jruoho }
    324      1.1    jruoho 
    325      1.1    jruoho 
    326      1.1    jruoho /*******************************************************************************
    327      1.1    jruoho  *
    328      1.1    jruoho  * FUNCTION:    AcpiDsBeginMethodExecution
    329      1.1    jruoho  *
    330      1.1    jruoho  * PARAMETERS:  MethodNode          - Node of the method
    331      1.1    jruoho  *              ObjDesc             - The method object
    332      1.1    jruoho  *              WalkState           - current state, NULL if not yet executing
    333      1.1    jruoho  *                                    a method.
    334      1.1    jruoho  *
    335      1.1    jruoho  * RETURN:      Status
    336      1.1    jruoho  *
    337  1.1.1.3  christos  * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
    338      1.1    jruoho  *              increments the thread count, and waits at the method semaphore
    339      1.1    jruoho  *              for clearance to execute.
    340      1.1    jruoho  *
    341      1.1    jruoho  ******************************************************************************/
    342      1.1    jruoho 
    343      1.1    jruoho ACPI_STATUS
    344      1.1    jruoho AcpiDsBeginMethodExecution (
    345      1.1    jruoho     ACPI_NAMESPACE_NODE     *MethodNode,
    346      1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc,
    347      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    348      1.1    jruoho {
    349      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    350      1.1    jruoho 
    351      1.1    jruoho 
    352      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsBeginMethodExecution, MethodNode);
    353      1.1    jruoho 
    354      1.1    jruoho 
    355      1.1    jruoho     if (!MethodNode)
    356      1.1    jruoho     {
    357      1.1    jruoho         return_ACPI_STATUS (AE_NULL_ENTRY);
    358      1.1    jruoho     }
    359      1.1    jruoho 
    360  1.1.1.6  christos     AcpiExStartTraceMethod (MethodNode, ObjDesc, WalkState);
    361  1.1.1.6  christos 
    362      1.1    jruoho     /* Prevent wraparound of thread count */
    363      1.1    jruoho 
    364      1.1    jruoho     if (ObjDesc->Method.ThreadCount == ACPI_UINT8_MAX)
    365      1.1    jruoho     {
    366      1.1    jruoho         ACPI_ERROR ((AE_INFO,
    367      1.1    jruoho             "Method reached maximum reentrancy limit (255)"));
    368      1.1    jruoho         return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
    369      1.1    jruoho     }
    370      1.1    jruoho 
    371      1.1    jruoho     /*
    372      1.1    jruoho      * If this method is serialized, we need to acquire the method mutex.
    373      1.1    jruoho      */
    374  1.1.1.2    jruoho     if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
    375      1.1    jruoho     {
    376      1.1    jruoho         /*
    377      1.1    jruoho          * Create a mutex for the method if it is defined to be Serialized
    378      1.1    jruoho          * and a mutex has not already been created. We defer the mutex creation
    379      1.1    jruoho          * until a method is actually executed, to minimize the object count
    380      1.1    jruoho          */
    381      1.1    jruoho         if (!ObjDesc->Method.Mutex)
    382      1.1    jruoho         {
    383      1.1    jruoho             Status = AcpiDsCreateMethodMutex (ObjDesc);
    384      1.1    jruoho             if (ACPI_FAILURE (Status))
    385      1.1    jruoho             {
    386      1.1    jruoho                 return_ACPI_STATUS (Status);
    387      1.1    jruoho             }
    388      1.1    jruoho         }
    389      1.1    jruoho 
    390      1.1    jruoho         /*
    391      1.1    jruoho          * The CurrentSyncLevel (per-thread) must be less than or equal to
    392      1.1    jruoho          * the sync level of the method. This mechanism provides some
    393  1.1.1.4  christos          * deadlock prevention.
    394  1.1.1.4  christos          *
    395  1.1.1.4  christos          * If the method was auto-serialized, we just ignore the sync level
    396  1.1.1.4  christos          * mechanism, because auto-serialization of methods can interfere
    397  1.1.1.4  christos          * with ASL code that actually uses sync levels.
    398      1.1    jruoho          *
    399      1.1    jruoho          * Top-level method invocation has no walk state at this point
    400      1.1    jruoho          */
    401      1.1    jruoho         if (WalkState &&
    402  1.1.1.4  christos             (!(ObjDesc->Method.InfoFlags & ACPI_METHOD_IGNORE_SYNC_LEVEL)) &&
    403  1.1.1.7  christos             (WalkState->Thread->CurrentSyncLevel >
    404  1.1.1.7  christos                 ObjDesc->Method.Mutex->Mutex.SyncLevel))
    405      1.1    jruoho         {
    406      1.1    jruoho             ACPI_ERROR ((AE_INFO,
    407  1.1.1.7  christos                 "Cannot acquire Mutex for method [%4.4s]"
    408  1.1.1.7  christos                 ", current SyncLevel is too large (%u)",
    409      1.1    jruoho                 AcpiUtGetNodeName (MethodNode),
    410      1.1    jruoho                 WalkState->Thread->CurrentSyncLevel));
    411      1.1    jruoho 
    412      1.1    jruoho             return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
    413      1.1    jruoho         }
    414      1.1    jruoho 
    415      1.1    jruoho         /*
    416      1.1    jruoho          * Obtain the method mutex if necessary. Do not acquire mutex for a
    417      1.1    jruoho          * recursive call.
    418      1.1    jruoho          */
    419      1.1    jruoho         if (!WalkState ||
    420      1.1    jruoho             !ObjDesc->Method.Mutex->Mutex.ThreadId ||
    421  1.1.1.7  christos             (WalkState->Thread->ThreadId !=
    422  1.1.1.7  christos                 ObjDesc->Method.Mutex->Mutex.ThreadId))
    423      1.1    jruoho         {
    424      1.1    jruoho             /*
    425      1.1    jruoho              * Acquire the method mutex. This releases the interpreter if we
    426      1.1    jruoho              * block (and reacquires it before it returns)
    427      1.1    jruoho              */
    428  1.1.1.7  christos             Status = AcpiExSystemWaitMutex (
    429  1.1.1.7  christos                 ObjDesc->Method.Mutex->Mutex.OsMutex, ACPI_WAIT_FOREVER);
    430      1.1    jruoho             if (ACPI_FAILURE (Status))
    431      1.1    jruoho             {
    432      1.1    jruoho                 return_ACPI_STATUS (Status);
    433      1.1    jruoho             }
    434      1.1    jruoho 
    435      1.1    jruoho             /* Update the mutex and walk info and save the original SyncLevel */
    436      1.1    jruoho 
    437      1.1    jruoho             if (WalkState)
    438      1.1    jruoho             {
    439      1.1    jruoho                 ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
    440      1.1    jruoho                     WalkState->Thread->CurrentSyncLevel;
    441      1.1    jruoho 
    442  1.1.1.7  christos                 ObjDesc->Method.Mutex->Mutex.ThreadId =
    443  1.1.1.7  christos                     WalkState->Thread->ThreadId;
    444  1.1.1.7  christos 
    445  1.1.1.7  christos                 /*
    446  1.1.1.7  christos                  * Update the current SyncLevel only if this is not an auto-
    447  1.1.1.7  christos                  * serialized method. In the auto case, we have to ignore
    448  1.1.1.7  christos                  * the sync level for the method mutex (created for the
    449  1.1.1.7  christos                  * auto-serialization) because we have no idea of what the
    450  1.1.1.7  christos                  * sync level should be. Therefore, just ignore it.
    451  1.1.1.7  christos                  */
    452  1.1.1.7  christos                 if (!(ObjDesc->Method.InfoFlags &
    453  1.1.1.7  christos                     ACPI_METHOD_IGNORE_SYNC_LEVEL))
    454  1.1.1.7  christos                 {
    455  1.1.1.7  christos                     WalkState->Thread->CurrentSyncLevel =
    456  1.1.1.7  christos                         ObjDesc->Method.SyncLevel;
    457  1.1.1.7  christos                 }
    458      1.1    jruoho             }
    459      1.1    jruoho             else
    460      1.1    jruoho             {
    461      1.1    jruoho                 ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
    462      1.1    jruoho                     ObjDesc->Method.Mutex->Mutex.SyncLevel;
    463      1.1    jruoho             }
    464      1.1    jruoho         }
    465      1.1    jruoho 
    466      1.1    jruoho         /* Always increase acquisition depth */
    467      1.1    jruoho 
    468      1.1    jruoho         ObjDesc->Method.Mutex->Mutex.AcquisitionDepth++;
    469      1.1    jruoho     }
    470      1.1    jruoho 
    471      1.1    jruoho     /*
    472      1.1    jruoho      * Allocate an Owner ID for this method, only if this is the first thread
    473      1.1    jruoho      * to begin concurrent execution. We only need one OwnerId, even if the
    474      1.1    jruoho      * method is invoked recursively.
    475      1.1    jruoho      */
    476      1.1    jruoho     if (!ObjDesc->Method.OwnerId)
    477      1.1    jruoho     {
    478      1.1    jruoho         Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
    479      1.1    jruoho         if (ACPI_FAILURE (Status))
    480      1.1    jruoho         {
    481      1.1    jruoho             goto Cleanup;
    482      1.1    jruoho         }
    483      1.1    jruoho     }
    484      1.1    jruoho 
    485      1.1    jruoho     /*
    486      1.1    jruoho      * Increment the method parse tree thread count since it has been
    487      1.1    jruoho      * reentered one more time (even if it is the same thread)
    488      1.1    jruoho      */
    489      1.1    jruoho     ObjDesc->Method.ThreadCount++;
    490      1.1    jruoho     AcpiMethodCount++;
    491      1.1    jruoho     return_ACPI_STATUS (Status);
    492      1.1    jruoho 
    493      1.1    jruoho 
    494      1.1    jruoho Cleanup:
    495      1.1    jruoho     /* On error, must release the method mutex (if present) */
    496      1.1    jruoho 
    497      1.1    jruoho     if (ObjDesc->Method.Mutex)
    498      1.1    jruoho     {
    499      1.1    jruoho         AcpiOsReleaseMutex (ObjDesc->Method.Mutex->Mutex.OsMutex);
    500      1.1    jruoho     }
    501      1.1    jruoho     return_ACPI_STATUS (Status);
    502      1.1    jruoho }
    503      1.1    jruoho 
    504      1.1    jruoho 
    505      1.1    jruoho /*******************************************************************************
    506      1.1    jruoho  *
    507      1.1    jruoho  * FUNCTION:    AcpiDsCallControlMethod
    508      1.1    jruoho  *
    509      1.1    jruoho  * PARAMETERS:  Thread              - Info for this thread
    510      1.1    jruoho  *              ThisWalkState       - Current walk state
    511      1.1    jruoho  *              Op                  - Current Op to be walked
    512      1.1    jruoho  *
    513      1.1    jruoho  * RETURN:      Status
    514      1.1    jruoho  *
    515      1.1    jruoho  * DESCRIPTION: Transfer execution to a called control method
    516      1.1    jruoho  *
    517      1.1    jruoho  ******************************************************************************/
    518      1.1    jruoho 
    519      1.1    jruoho ACPI_STATUS
    520      1.1    jruoho AcpiDsCallControlMethod (
    521      1.1    jruoho     ACPI_THREAD_STATE       *Thread,
    522      1.1    jruoho     ACPI_WALK_STATE         *ThisWalkState,
    523      1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    524      1.1    jruoho {
    525      1.1    jruoho     ACPI_STATUS             Status;
    526      1.1    jruoho     ACPI_NAMESPACE_NODE     *MethodNode;
    527      1.1    jruoho     ACPI_WALK_STATE         *NextWalkState = NULL;
    528      1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    529      1.1    jruoho     ACPI_EVALUATE_INFO      *Info;
    530      1.1    jruoho     UINT32                  i;
    531      1.1    jruoho 
    532      1.1    jruoho 
    533      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsCallControlMethod, ThisWalkState);
    534      1.1    jruoho 
    535  1.1.1.7  christos     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    536  1.1.1.7  christos         "Calling method %p, currentstate=%p\n",
    537      1.1    jruoho         ThisWalkState->PrevOp, ThisWalkState));
    538      1.1    jruoho 
    539      1.1    jruoho     /*
    540      1.1    jruoho      * Get the namespace entry for the control method we are about to call
    541      1.1    jruoho      */
    542      1.1    jruoho     MethodNode = ThisWalkState->MethodCallNode;
    543      1.1    jruoho     if (!MethodNode)
    544      1.1    jruoho     {
    545      1.1    jruoho         return_ACPI_STATUS (AE_NULL_ENTRY);
    546      1.1    jruoho     }
    547      1.1    jruoho 
    548      1.1    jruoho     ObjDesc = AcpiNsGetAttachedObject (MethodNode);
    549      1.1    jruoho     if (!ObjDesc)
    550      1.1    jruoho     {
    551      1.1    jruoho         return_ACPI_STATUS (AE_NULL_OBJECT);
    552      1.1    jruoho     }
    553      1.1    jruoho 
    554      1.1    jruoho     /* Init for new method, possibly wait on method mutex */
    555      1.1    jruoho 
    556  1.1.1.7  christos     Status = AcpiDsBeginMethodExecution (
    557  1.1.1.7  christos         MethodNode, ObjDesc, ThisWalkState);
    558      1.1    jruoho     if (ACPI_FAILURE (Status))
    559      1.1    jruoho     {
    560      1.1    jruoho         return_ACPI_STATUS (Status);
    561      1.1    jruoho     }
    562      1.1    jruoho 
    563      1.1    jruoho     /* Begin method parse/execution. Create a new walk state */
    564      1.1    jruoho 
    565  1.1.1.7  christos     NextWalkState = AcpiDsCreateWalkState (
    566  1.1.1.7  christos         ObjDesc->Method.OwnerId, NULL, ObjDesc, Thread);
    567      1.1    jruoho     if (!NextWalkState)
    568      1.1    jruoho     {
    569      1.1    jruoho         Status = AE_NO_MEMORY;
    570      1.1    jruoho         goto Cleanup;
    571      1.1    jruoho     }
    572      1.1    jruoho 
    573      1.1    jruoho     /*
    574      1.1    jruoho      * The resolved arguments were put on the previous walk state's operand
    575      1.1    jruoho      * stack. Operands on the previous walk state stack always
    576      1.1    jruoho      * start at index 0. Also, null terminate the list of arguments
    577      1.1    jruoho      */
    578      1.1    jruoho     ThisWalkState->Operands [ThisWalkState->NumOperands] = NULL;
    579      1.1    jruoho 
    580      1.1    jruoho     /*
    581      1.1    jruoho      * Allocate and initialize the evaluation information block
    582      1.1    jruoho      * TBD: this is somewhat inefficient, should change interface to
    583      1.1    jruoho      * DsInitAmlWalk. For now, keeps this struct off the CPU stack
    584      1.1    jruoho      */
    585      1.1    jruoho     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    586      1.1    jruoho     if (!Info)
    587      1.1    jruoho     {
    588  1.1.1.3  christos         Status = AE_NO_MEMORY;
    589  1.1.1.3  christos         goto Cleanup;
    590      1.1    jruoho     }
    591      1.1    jruoho 
    592      1.1    jruoho     Info->Parameters = &ThisWalkState->Operands[0];
    593      1.1    jruoho 
    594      1.1    jruoho     Status = AcpiDsInitAmlWalk (NextWalkState, NULL, MethodNode,
    595  1.1.1.7  christos         ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength,
    596  1.1.1.7  christos         Info, ACPI_IMODE_EXECUTE);
    597      1.1    jruoho 
    598      1.1    jruoho     ACPI_FREE (Info);
    599      1.1    jruoho     if (ACPI_FAILURE (Status))
    600      1.1    jruoho     {
    601      1.1    jruoho         goto Cleanup;
    602      1.1    jruoho     }
    603      1.1    jruoho 
    604      1.1    jruoho     /*
    605      1.1    jruoho      * Delete the operands on the previous walkstate operand stack
    606      1.1    jruoho      * (they were copied to new objects)
    607      1.1    jruoho      */
    608      1.1    jruoho     for (i = 0; i < ObjDesc->Method.ParamCount; i++)
    609      1.1    jruoho     {
    610      1.1    jruoho         AcpiUtRemoveReference (ThisWalkState->Operands [i]);
    611      1.1    jruoho         ThisWalkState->Operands [i] = NULL;
    612      1.1    jruoho     }
    613      1.1    jruoho 
    614      1.1    jruoho     /* Clear the operand stack */
    615      1.1    jruoho 
    616      1.1    jruoho     ThisWalkState->NumOperands = 0;
    617      1.1    jruoho 
    618      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    619      1.1    jruoho         "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
    620      1.1    jruoho         MethodNode->Name.Ascii, NextWalkState));
    621      1.1    jruoho 
    622      1.1    jruoho     /* Invoke an internal method if necessary */
    623      1.1    jruoho 
    624  1.1.1.2    jruoho     if (ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
    625      1.1    jruoho     {
    626  1.1.1.2    jruoho         Status = ObjDesc->Method.Dispatch.Implementation (NextWalkState);
    627      1.1    jruoho         if (Status == AE_OK)
    628      1.1    jruoho         {
    629      1.1    jruoho             Status = AE_CTRL_TERMINATE;
    630      1.1    jruoho         }
    631      1.1    jruoho     }
    632      1.1    jruoho 
    633      1.1    jruoho     return_ACPI_STATUS (Status);
    634      1.1    jruoho 
    635      1.1    jruoho 
    636      1.1    jruoho Cleanup:
    637      1.1    jruoho 
    638      1.1    jruoho     /* On error, we must terminate the method properly */
    639      1.1    jruoho 
    640      1.1    jruoho     AcpiDsTerminateControlMethod (ObjDesc, NextWalkState);
    641  1.1.1.6  christos     AcpiDsDeleteWalkState (NextWalkState);
    642      1.1    jruoho 
    643      1.1    jruoho     return_ACPI_STATUS (Status);
    644      1.1    jruoho }
    645      1.1    jruoho 
    646      1.1    jruoho 
    647      1.1    jruoho /*******************************************************************************
    648      1.1    jruoho  *
    649      1.1    jruoho  * FUNCTION:    AcpiDsRestartControlMethod
    650      1.1    jruoho  *
    651      1.1    jruoho  * PARAMETERS:  WalkState           - State for preempted method (caller)
    652      1.1    jruoho  *              ReturnDesc          - Return value from the called method
    653      1.1    jruoho  *
    654      1.1    jruoho  * RETURN:      Status
    655      1.1    jruoho  *
    656      1.1    jruoho  * DESCRIPTION: Restart a method that was preempted by another (nested) method
    657  1.1.1.3  christos  *              invocation. Handle the return value (if any) from the callee.
    658      1.1    jruoho  *
    659      1.1    jruoho  ******************************************************************************/
    660      1.1    jruoho 
    661      1.1    jruoho ACPI_STATUS
    662      1.1    jruoho AcpiDsRestartControlMethod (
    663      1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    664      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc)
    665      1.1    jruoho {
    666      1.1    jruoho     ACPI_STATUS             Status;
    667      1.1    jruoho     int                     SameAsImplicitReturn;
    668      1.1    jruoho 
    669      1.1    jruoho 
    670      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsRestartControlMethod, WalkState);
    671      1.1    jruoho 
    672      1.1    jruoho 
    673      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    674      1.1    jruoho         "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
    675      1.1    jruoho         AcpiUtGetNodeName (WalkState->MethodNode),
    676      1.1    jruoho         WalkState->MethodCallOp, ReturnDesc));
    677      1.1    jruoho 
    678      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    679      1.1    jruoho         "    ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
    680      1.1    jruoho         WalkState->ReturnUsed,
    681      1.1    jruoho         WalkState->Results, WalkState));
    682      1.1    jruoho 
    683      1.1    jruoho     /* Did the called method return a value? */
    684      1.1    jruoho 
    685      1.1    jruoho     if (ReturnDesc)
    686      1.1    jruoho     {
    687      1.1    jruoho         /* Is the implicit return object the same as the return desc? */
    688      1.1    jruoho 
    689      1.1    jruoho         SameAsImplicitReturn = (WalkState->ImplicitReturnObj == ReturnDesc);
    690      1.1    jruoho 
    691      1.1    jruoho         /* Are we actually going to use the return value? */
    692      1.1    jruoho 
    693      1.1    jruoho         if (WalkState->ReturnUsed)
    694      1.1    jruoho         {
    695      1.1    jruoho             /* Save the return value from the previous method */
    696      1.1    jruoho 
    697      1.1    jruoho             Status = AcpiDsResultPush (ReturnDesc, WalkState);
    698      1.1    jruoho             if (ACPI_FAILURE (Status))
    699      1.1    jruoho             {
    700      1.1    jruoho                 AcpiUtRemoveReference (ReturnDesc);
    701      1.1    jruoho                 return_ACPI_STATUS (Status);
    702      1.1    jruoho             }
    703      1.1    jruoho 
    704      1.1    jruoho             /*
    705      1.1    jruoho              * Save as THIS method's return value in case it is returned
    706      1.1    jruoho              * immediately to yet another method
    707      1.1    jruoho              */
    708      1.1    jruoho             WalkState->ReturnDesc = ReturnDesc;
    709      1.1    jruoho         }
    710      1.1    jruoho 
    711      1.1    jruoho         /*
    712      1.1    jruoho          * The following code is the optional support for the so-called
    713      1.1    jruoho          * "implicit return". Some AML code assumes that the last value of the
    714      1.1    jruoho          * method is "implicitly" returned to the caller, in the absence of an
    715      1.1    jruoho          * explicit return value.
    716      1.1    jruoho          *
    717      1.1    jruoho          * Just save the last result of the method as the return value.
    718      1.1    jruoho          *
    719      1.1    jruoho          * NOTE: this is optional because the ASL language does not actually
    720      1.1    jruoho          * support this behavior.
    721      1.1    jruoho          */
    722      1.1    jruoho         else if (!AcpiDsDoImplicitReturn (ReturnDesc, WalkState, FALSE) ||
    723      1.1    jruoho                  SameAsImplicitReturn)
    724      1.1    jruoho         {
    725      1.1    jruoho             /*
    726      1.1    jruoho              * Delete the return value if it will not be used by the
    727      1.1    jruoho              * calling method or remove one reference if the explicit return
    728      1.1    jruoho              * is the same as the implicit return value.
    729      1.1    jruoho              */
    730      1.1    jruoho             AcpiUtRemoveReference (ReturnDesc);
    731      1.1    jruoho         }
    732      1.1    jruoho     }
    733      1.1    jruoho 
    734      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    735      1.1    jruoho }
    736      1.1    jruoho 
    737      1.1    jruoho 
    738      1.1    jruoho /*******************************************************************************
    739      1.1    jruoho  *
    740      1.1    jruoho  * FUNCTION:    AcpiDsTerminateControlMethod
    741      1.1    jruoho  *
    742      1.1    jruoho  * PARAMETERS:  MethodDesc          - Method object
    743      1.1    jruoho  *              WalkState           - State associated with the method
    744      1.1    jruoho  *
    745      1.1    jruoho  * RETURN:      None
    746      1.1    jruoho  *
    747  1.1.1.3  christos  * DESCRIPTION: Terminate a control method. Delete everything that the method
    748      1.1    jruoho  *              created, delete all locals and arguments, and delete the parse
    749      1.1    jruoho  *              tree if requested.
    750      1.1    jruoho  *
    751      1.1    jruoho  * MUTEX:       Interpreter is locked
    752      1.1    jruoho  *
    753      1.1    jruoho  ******************************************************************************/
    754      1.1    jruoho 
    755      1.1    jruoho void
    756      1.1    jruoho AcpiDsTerminateControlMethod (
    757      1.1    jruoho     ACPI_OPERAND_OBJECT     *MethodDesc,
    758      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    759      1.1    jruoho {
    760      1.1    jruoho 
    761      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsTerminateControlMethod, WalkState);
    762      1.1    jruoho 
    763      1.1    jruoho 
    764      1.1    jruoho     /* MethodDesc is required, WalkState is optional */
    765      1.1    jruoho 
    766      1.1    jruoho     if (!MethodDesc)
    767      1.1    jruoho     {
    768      1.1    jruoho         return_VOID;
    769      1.1    jruoho     }
    770      1.1    jruoho 
    771      1.1    jruoho     if (WalkState)
    772      1.1    jruoho     {
    773      1.1    jruoho         /* Delete all arguments and locals */
    774      1.1    jruoho 
    775      1.1    jruoho         AcpiDsMethodDataDeleteAll (WalkState);
    776      1.1    jruoho 
    777      1.1    jruoho         /*
    778      1.1    jruoho          * If method is serialized, release the mutex and restore the
    779      1.1    jruoho          * current sync level for this thread
    780      1.1    jruoho          */
    781      1.1    jruoho         if (MethodDesc->Method.Mutex)
    782      1.1    jruoho         {
    783      1.1    jruoho             /* Acquisition Depth handles recursive calls */
    784      1.1    jruoho 
    785      1.1    jruoho             MethodDesc->Method.Mutex->Mutex.AcquisitionDepth--;
    786      1.1    jruoho             if (!MethodDesc->Method.Mutex->Mutex.AcquisitionDepth)
    787      1.1    jruoho             {
    788      1.1    jruoho                 WalkState->Thread->CurrentSyncLevel =
    789      1.1    jruoho                     MethodDesc->Method.Mutex->Mutex.OriginalSyncLevel;
    790      1.1    jruoho 
    791  1.1.1.7  christos                 AcpiOsReleaseMutex (
    792  1.1.1.7  christos                     MethodDesc->Method.Mutex->Mutex.OsMutex);
    793      1.1    jruoho                 MethodDesc->Method.Mutex->Mutex.ThreadId = 0;
    794      1.1    jruoho             }
    795      1.1    jruoho         }
    796      1.1    jruoho 
    797      1.1    jruoho         /*
    798      1.1    jruoho          * Delete any namespace objects created anywhere within the
    799  1.1.1.2    jruoho          * namespace by the execution of this method. Unless:
    800  1.1.1.2    jruoho          * 1) This method is a module-level executable code method, in which
    801  1.1.1.2    jruoho          *    case we want make the objects permanent.
    802  1.1.1.2    jruoho          * 2) There are other threads executing the method, in which case we
    803  1.1.1.2    jruoho          *    will wait until the last thread has completed.
    804      1.1    jruoho          */
    805  1.1.1.2    jruoho         if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) &&
    806  1.1.1.2    jruoho              (MethodDesc->Method.ThreadCount == 1))
    807      1.1    jruoho         {
    808      1.1    jruoho             /* Delete any direct children of (created by) this method */
    809      1.1    jruoho 
    810      1.1    jruoho             AcpiNsDeleteNamespaceSubtree (WalkState->MethodNode);
    811      1.1    jruoho 
    812      1.1    jruoho             /*
    813      1.1    jruoho              * Delete any objects that were created by this method
    814      1.1    jruoho              * elsewhere in the namespace (if any were created).
    815  1.1.1.2    jruoho              * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the
    816  1.1.1.2    jruoho              * deletion such that we don't have to perform an entire
    817  1.1.1.2    jruoho              * namespace walk for every control method execution.
    818      1.1    jruoho              */
    819  1.1.1.2    jruoho             if (MethodDesc->Method.InfoFlags & ACPI_METHOD_MODIFIED_NAMESPACE)
    820      1.1    jruoho             {
    821      1.1    jruoho                 AcpiNsDeleteNamespaceByOwner (MethodDesc->Method.OwnerId);
    822  1.1.1.7  christos                 MethodDesc->Method.InfoFlags &=
    823  1.1.1.7  christos                     ~ACPI_METHOD_MODIFIED_NAMESPACE;
    824      1.1    jruoho             }
    825      1.1    jruoho         }
    826      1.1    jruoho     }
    827      1.1    jruoho 
    828      1.1    jruoho     /* Decrement the thread count on the method */
    829      1.1    jruoho 
    830      1.1    jruoho     if (MethodDesc->Method.ThreadCount)
    831      1.1    jruoho     {
    832      1.1    jruoho         MethodDesc->Method.ThreadCount--;
    833      1.1    jruoho     }
    834      1.1    jruoho     else
    835      1.1    jruoho     {
    836      1.1    jruoho         ACPI_ERROR ((AE_INFO,
    837      1.1    jruoho             "Invalid zero thread count in method"));
    838      1.1    jruoho     }
    839      1.1    jruoho 
    840      1.1    jruoho     /* Are there any other threads currently executing this method? */
    841      1.1    jruoho 
    842      1.1    jruoho     if (MethodDesc->Method.ThreadCount)
    843      1.1    jruoho     {
    844      1.1    jruoho         /*
    845      1.1    jruoho          * Additional threads. Do not release the OwnerId in this case,
    846      1.1    jruoho          * we immediately reuse it for the next thread executing this method
    847      1.1    jruoho          */
    848      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    849      1.1    jruoho             "*** Completed execution of one thread, %u threads remaining\n",
    850      1.1    jruoho             MethodDesc->Method.ThreadCount));
    851      1.1    jruoho     }
    852      1.1    jruoho     else
    853      1.1    jruoho     {
    854      1.1    jruoho         /* This is the only executing thread for this method */
    855      1.1    jruoho 
    856      1.1    jruoho         /*
    857      1.1    jruoho          * Support to dynamically change a method from NotSerialized to
    858      1.1    jruoho          * Serialized if it appears that the method is incorrectly written and
    859      1.1    jruoho          * does not support multiple thread execution. The best example of this
    860      1.1    jruoho          * is if such a method creates namespace objects and blocks. A second
    861  1.1.1.2    jruoho          * thread will fail with an AE_ALREADY_EXISTS exception.
    862      1.1    jruoho          *
    863      1.1    jruoho          * This code is here because we must wait until the last thread exits
    864  1.1.1.2    jruoho          * before marking the method as serialized.
    865      1.1    jruoho          */
    866  1.1.1.2    jruoho         if (MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED_PENDING)
    867      1.1    jruoho         {
    868  1.1.1.2    jruoho             if (WalkState)
    869  1.1.1.2    jruoho             {
    870  1.1.1.2    jruoho                 ACPI_INFO ((AE_INFO,
    871  1.1.1.7  christos                     "Marking method %4.4s as Serialized "
    872  1.1.1.7  christos                     "because of AE_ALREADY_EXISTS error",
    873  1.1.1.2    jruoho                     WalkState->MethodNode->Name.Ascii));
    874  1.1.1.2    jruoho             }
    875  1.1.1.2    jruoho 
    876  1.1.1.2    jruoho             /*
    877  1.1.1.2    jruoho              * Method tried to create an object twice and was marked as
    878  1.1.1.2    jruoho              * "pending serialized". The probable cause is that the method
    879  1.1.1.2    jruoho              * cannot handle reentrancy.
    880  1.1.1.2    jruoho              *
    881  1.1.1.2    jruoho              * The method was created as NotSerialized, but it tried to create
    882  1.1.1.2    jruoho              * a named object and then blocked, causing the second thread
    883  1.1.1.2    jruoho              * entrance to begin and then fail. Workaround this problem by
    884  1.1.1.2    jruoho              * marking the method permanently as Serialized when the last
    885  1.1.1.2    jruoho              * thread exits here.
    886  1.1.1.2    jruoho              */
    887  1.1.1.7  christos             MethodDesc->Method.InfoFlags &=
    888  1.1.1.7  christos                 ~ACPI_METHOD_SERIALIZED_PENDING;
    889  1.1.1.7  christos 
    890  1.1.1.4  christos             MethodDesc->Method.InfoFlags |=
    891  1.1.1.4  christos                 (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
    892  1.1.1.2    jruoho             MethodDesc->Method.SyncLevel = 0;
    893      1.1    jruoho         }
    894      1.1    jruoho 
    895      1.1    jruoho         /* No more threads, we can free the OwnerId */
    896      1.1    jruoho 
    897  1.1.1.2    jruoho         if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL))
    898      1.1    jruoho         {
    899      1.1    jruoho             AcpiUtReleaseOwnerId (&MethodDesc->Method.OwnerId);
    900      1.1    jruoho         }
    901      1.1    jruoho     }
    902      1.1    jruoho 
    903  1.1.1.6  christos     AcpiExStopTraceMethod ((ACPI_NAMESPACE_NODE *) MethodDesc->Method.Node,
    904  1.1.1.7  christos         MethodDesc, WalkState);
    905  1.1.1.6  christos 
    906      1.1    jruoho     return_VOID;
    907      1.1    jruoho }
    908