Home | History | Annotate | Line # | Download | only in dispatcher
dsmethod.c revision 1.1.1.2.2.2
      1  1.1.1.2.2.2  bouyer /******************************************************************************
      2  1.1.1.2.2.2  bouyer  *
      3  1.1.1.2.2.2  bouyer  * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
      4  1.1.1.2.2.2  bouyer  *
      5  1.1.1.2.2.2  bouyer  *****************************************************************************/
      6  1.1.1.2.2.2  bouyer 
      7  1.1.1.2.2.2  bouyer /*
      8  1.1.1.2.2.2  bouyer  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1.1.2.2.2  bouyer  * All rights reserved.
     10  1.1.1.2.2.2  bouyer  *
     11  1.1.1.2.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2.2.2  bouyer  * modification, are permitted provided that the following conditions
     13  1.1.1.2.2.2  bouyer  * are met:
     14  1.1.1.2.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2.2.2  bouyer  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2.2.2  bouyer  *    without modification.
     17  1.1.1.2.2.2  bouyer  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2.2.2  bouyer  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2.2.2  bouyer  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2.2.2  bouyer  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2.2.2  bouyer  *    binary redistribution.
     22  1.1.1.2.2.2  bouyer  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2.2.2  bouyer  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2.2.2  bouyer  *    from this software without specific prior written permission.
     25  1.1.1.2.2.2  bouyer  *
     26  1.1.1.2.2.2  bouyer  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2.2.2  bouyer  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2.2.2  bouyer  * Software Foundation.
     29  1.1.1.2.2.2  bouyer  *
     30  1.1.1.2.2.2  bouyer  * NO WARRANTY
     31  1.1.1.2.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2.2.2  bouyer  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2.2.2  bouyer  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2.2.2  bouyer  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2.2.2  bouyer  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2.2.2  bouyer  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2.2.2  bouyer  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2.2.2  bouyer  */
     43  1.1.1.2.2.2  bouyer 
     44  1.1.1.2.2.2  bouyer #define __DSMETHOD_C__
     45  1.1.1.2.2.2  bouyer 
     46  1.1.1.2.2.2  bouyer #include "acpi.h"
     47  1.1.1.2.2.2  bouyer #include "accommon.h"
     48  1.1.1.2.2.2  bouyer #include "acdispat.h"
     49  1.1.1.2.2.2  bouyer #include "acinterp.h"
     50  1.1.1.2.2.2  bouyer #include "acnamesp.h"
     51  1.1.1.2.2.2  bouyer #include "acdisasm.h"
     52  1.1.1.2.2.2  bouyer 
     53  1.1.1.2.2.2  bouyer 
     54  1.1.1.2.2.2  bouyer #define _COMPONENT          ACPI_DISPATCHER
     55  1.1.1.2.2.2  bouyer         ACPI_MODULE_NAME    ("dsmethod")
     56  1.1.1.2.2.2  bouyer 
     57  1.1.1.2.2.2  bouyer /* Local prototypes */
     58  1.1.1.2.2.2  bouyer 
     59  1.1.1.2.2.2  bouyer static ACPI_STATUS
     60  1.1.1.2.2.2  bouyer AcpiDsCreateMethodMutex (
     61  1.1.1.2.2.2  bouyer     ACPI_OPERAND_OBJECT     *MethodDesc);
     62  1.1.1.2.2.2  bouyer 
     63  1.1.1.2.2.2  bouyer 
     64  1.1.1.2.2.2  bouyer /*******************************************************************************
     65  1.1.1.2.2.2  bouyer  *
     66  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiDsMethodError
     67  1.1.1.2.2.2  bouyer  *
     68  1.1.1.2.2.2  bouyer  * PARAMETERS:  Status          - Execution status
     69  1.1.1.2.2.2  bouyer  *              WalkState       - Current state
     70  1.1.1.2.2.2  bouyer  *
     71  1.1.1.2.2.2  bouyer  * RETURN:      Status
     72  1.1.1.2.2.2  bouyer  *
     73  1.1.1.2.2.2  bouyer  * DESCRIPTION: Called on method error. Invoke the global exception handler if
     74  1.1.1.2.2.2  bouyer  *              present, dump the method data if the disassembler is configured
     75  1.1.1.2.2.2  bouyer  *
     76  1.1.1.2.2.2  bouyer  *              Note: Allows the exception handler to change the status code
     77  1.1.1.2.2.2  bouyer  *
     78  1.1.1.2.2.2  bouyer  ******************************************************************************/
     79  1.1.1.2.2.2  bouyer 
     80  1.1.1.2.2.2  bouyer ACPI_STATUS
     81  1.1.1.2.2.2  bouyer AcpiDsMethodError (
     82  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status,
     83  1.1.1.2.2.2  bouyer     ACPI_WALK_STATE         *WalkState)
     84  1.1.1.2.2.2  bouyer {
     85  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_ENTRY ();
     86  1.1.1.2.2.2  bouyer 
     87  1.1.1.2.2.2  bouyer 
     88  1.1.1.2.2.2  bouyer     /* Ignore AE_OK and control exception codes */
     89  1.1.1.2.2.2  bouyer 
     90  1.1.1.2.2.2  bouyer     if (ACPI_SUCCESS (Status) ||
     91  1.1.1.2.2.2  bouyer         (Status & AE_CODE_CONTROL))
     92  1.1.1.2.2.2  bouyer     {
     93  1.1.1.2.2.2  bouyer         return (Status);
     94  1.1.1.2.2.2  bouyer     }
     95  1.1.1.2.2.2  bouyer 
     96  1.1.1.2.2.2  bouyer     /* Invoke the global exception handler */
     97  1.1.1.2.2.2  bouyer 
     98  1.1.1.2.2.2  bouyer     if (AcpiGbl_ExceptionHandler)
     99  1.1.1.2.2.2  bouyer     {
    100  1.1.1.2.2.2  bouyer         /* Exit the interpreter, allow handler to execute methods */
    101  1.1.1.2.2.2  bouyer 
    102  1.1.1.2.2.2  bouyer         AcpiExExitInterpreter ();
    103  1.1.1.2.2.2  bouyer 
    104  1.1.1.2.2.2  bouyer         /*
    105  1.1.1.2.2.2  bouyer          * Handler can map the exception code to anything it wants, including
    106  1.1.1.2.2.2  bouyer          * AE_OK, in which case the executing method will not be aborted.
    107  1.1.1.2.2.2  bouyer          */
    108  1.1.1.2.2.2  bouyer         Status = AcpiGbl_ExceptionHandler (Status,
    109  1.1.1.2.2.2  bouyer                     WalkState->MethodNode ?
    110  1.1.1.2.2.2  bouyer                         WalkState->MethodNode->Name.Integer : 0,
    111  1.1.1.2.2.2  bouyer                     WalkState->Opcode, WalkState->AmlOffset, NULL);
    112  1.1.1.2.2.2  bouyer         AcpiExEnterInterpreter ();
    113  1.1.1.2.2.2  bouyer     }
    114  1.1.1.2.2.2  bouyer 
    115  1.1.1.2.2.2  bouyer     AcpiDsClearImplicitReturn (WalkState);
    116  1.1.1.2.2.2  bouyer 
    117  1.1.1.2.2.2  bouyer #ifdef ACPI_DISASSEMBLER
    118  1.1.1.2.2.2  bouyer     if (ACPI_FAILURE (Status))
    119  1.1.1.2.2.2  bouyer     {
    120  1.1.1.2.2.2  bouyer         /* Display method locals/args if disassembler is present */
    121  1.1.1.2.2.2  bouyer 
    122  1.1.1.2.2.2  bouyer         AcpiDmDumpMethodInfo (Status, WalkState, WalkState->Op);
    123  1.1.1.2.2.2  bouyer     }
    124  1.1.1.2.2.2  bouyer #endif
    125  1.1.1.2.2.2  bouyer 
    126  1.1.1.2.2.2  bouyer     return (Status);
    127  1.1.1.2.2.2  bouyer }
    128  1.1.1.2.2.2  bouyer 
    129  1.1.1.2.2.2  bouyer 
    130  1.1.1.2.2.2  bouyer /*******************************************************************************
    131  1.1.1.2.2.2  bouyer  *
    132  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiDsCreateMethodMutex
    133  1.1.1.2.2.2  bouyer  *
    134  1.1.1.2.2.2  bouyer  * PARAMETERS:  ObjDesc             - The method object
    135  1.1.1.2.2.2  bouyer  *
    136  1.1.1.2.2.2  bouyer  * RETURN:      Status
    137  1.1.1.2.2.2  bouyer  *
    138  1.1.1.2.2.2  bouyer  * DESCRIPTION: Create a mutex object for a serialized control method
    139  1.1.1.2.2.2  bouyer  *
    140  1.1.1.2.2.2  bouyer  ******************************************************************************/
    141  1.1.1.2.2.2  bouyer 
    142  1.1.1.2.2.2  bouyer static ACPI_STATUS
    143  1.1.1.2.2.2  bouyer AcpiDsCreateMethodMutex (
    144  1.1.1.2.2.2  bouyer     ACPI_OPERAND_OBJECT     *MethodDesc)
    145  1.1.1.2.2.2  bouyer {
    146  1.1.1.2.2.2  bouyer     ACPI_OPERAND_OBJECT     *MutexDesc;
    147  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    148  1.1.1.2.2.2  bouyer 
    149  1.1.1.2.2.2  bouyer 
    150  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE (DsCreateMethodMutex);
    151  1.1.1.2.2.2  bouyer 
    152  1.1.1.2.2.2  bouyer 
    153  1.1.1.2.2.2  bouyer     /* Create the new mutex object */
    154  1.1.1.2.2.2  bouyer 
    155  1.1.1.2.2.2  bouyer     MutexDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
    156  1.1.1.2.2.2  bouyer     if (!MutexDesc)
    157  1.1.1.2.2.2  bouyer     {
    158  1.1.1.2.2.2  bouyer         return_ACPI_STATUS (AE_NO_MEMORY);
    159  1.1.1.2.2.2  bouyer     }
    160  1.1.1.2.2.2  bouyer 
    161  1.1.1.2.2.2  bouyer     /* Create the actual OS Mutex */
    162  1.1.1.2.2.2  bouyer 
    163  1.1.1.2.2.2  bouyer     Status = AcpiOsCreateMutex (&MutexDesc->Mutex.OsMutex);
    164  1.1.1.2.2.2  bouyer     if (ACPI_FAILURE (Status))
    165  1.1.1.2.2.2  bouyer     {
    166  1.1.1.2.2.2  bouyer         return_ACPI_STATUS (Status);
    167  1.1.1.2.2.2  bouyer     }
    168  1.1.1.2.2.2  bouyer 
    169  1.1.1.2.2.2  bouyer     MutexDesc->Mutex.SyncLevel = MethodDesc->Method.SyncLevel;
    170  1.1.1.2.2.2  bouyer     MethodDesc->Method.Mutex = MutexDesc;
    171  1.1.1.2.2.2  bouyer     return_ACPI_STATUS (AE_OK);
    172  1.1.1.2.2.2  bouyer }
    173  1.1.1.2.2.2  bouyer 
    174  1.1.1.2.2.2  bouyer 
    175  1.1.1.2.2.2  bouyer /*******************************************************************************
    176  1.1.1.2.2.2  bouyer  *
    177  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiDsBeginMethodExecution
    178  1.1.1.2.2.2  bouyer  *
    179  1.1.1.2.2.2  bouyer  * PARAMETERS:  MethodNode          - Node of the method
    180  1.1.1.2.2.2  bouyer  *              ObjDesc             - The method object
    181  1.1.1.2.2.2  bouyer  *              WalkState           - current state, NULL if not yet executing
    182  1.1.1.2.2.2  bouyer  *                                    a method.
    183  1.1.1.2.2.2  bouyer  *
    184  1.1.1.2.2.2  bouyer  * RETURN:      Status
    185  1.1.1.2.2.2  bouyer  *
    186  1.1.1.2.2.2  bouyer  * DESCRIPTION: Prepare a method for execution.  Parses the method if necessary,
    187  1.1.1.2.2.2  bouyer  *              increments the thread count, and waits at the method semaphore
    188  1.1.1.2.2.2  bouyer  *              for clearance to execute.
    189  1.1.1.2.2.2  bouyer  *
    190  1.1.1.2.2.2  bouyer  ******************************************************************************/
    191  1.1.1.2.2.2  bouyer 
    192  1.1.1.2.2.2  bouyer ACPI_STATUS
    193  1.1.1.2.2.2  bouyer AcpiDsBeginMethodExecution (
    194  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *MethodNode,
    195  1.1.1.2.2.2  bouyer     ACPI_OPERAND_OBJECT     *ObjDesc,
    196  1.1.1.2.2.2  bouyer     ACPI_WALK_STATE         *WalkState)
    197  1.1.1.2.2.2  bouyer {
    198  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status = AE_OK;
    199  1.1.1.2.2.2  bouyer 
    200  1.1.1.2.2.2  bouyer 
    201  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE_PTR (DsBeginMethodExecution, MethodNode);
    202  1.1.1.2.2.2  bouyer 
    203  1.1.1.2.2.2  bouyer 
    204  1.1.1.2.2.2  bouyer     if (!MethodNode)
    205  1.1.1.2.2.2  bouyer     {
    206  1.1.1.2.2.2  bouyer         return_ACPI_STATUS (AE_NULL_ENTRY);
    207  1.1.1.2.2.2  bouyer     }
    208  1.1.1.2.2.2  bouyer 
    209  1.1.1.2.2.2  bouyer     /* Prevent wraparound of thread count */
    210  1.1.1.2.2.2  bouyer 
    211  1.1.1.2.2.2  bouyer     if (ObjDesc->Method.ThreadCount == ACPI_UINT8_MAX)
    212  1.1.1.2.2.2  bouyer     {
    213  1.1.1.2.2.2  bouyer         ACPI_ERROR ((AE_INFO,
    214  1.1.1.2.2.2  bouyer             "Method reached maximum reentrancy limit (255)"));
    215  1.1.1.2.2.2  bouyer         return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
    216  1.1.1.2.2.2  bouyer     }
    217  1.1.1.2.2.2  bouyer 
    218  1.1.1.2.2.2  bouyer     /*
    219  1.1.1.2.2.2  bouyer      * If this method is serialized, we need to acquire the method mutex.
    220  1.1.1.2.2.2  bouyer      */
    221  1.1.1.2.2.2  bouyer     if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
    222  1.1.1.2.2.2  bouyer     {
    223  1.1.1.2.2.2  bouyer         /*
    224  1.1.1.2.2.2  bouyer          * Create a mutex for the method if it is defined to be Serialized
    225  1.1.1.2.2.2  bouyer          * and a mutex has not already been created. We defer the mutex creation
    226  1.1.1.2.2.2  bouyer          * until a method is actually executed, to minimize the object count
    227  1.1.1.2.2.2  bouyer          */
    228  1.1.1.2.2.2  bouyer         if (!ObjDesc->Method.Mutex)
    229  1.1.1.2.2.2  bouyer         {
    230  1.1.1.2.2.2  bouyer             Status = AcpiDsCreateMethodMutex (ObjDesc);
    231  1.1.1.2.2.2  bouyer             if (ACPI_FAILURE (Status))
    232  1.1.1.2.2.2  bouyer             {
    233  1.1.1.2.2.2  bouyer                 return_ACPI_STATUS (Status);
    234  1.1.1.2.2.2  bouyer             }
    235  1.1.1.2.2.2  bouyer         }
    236  1.1.1.2.2.2  bouyer 
    237  1.1.1.2.2.2  bouyer         /*
    238  1.1.1.2.2.2  bouyer          * The CurrentSyncLevel (per-thread) must be less than or equal to
    239  1.1.1.2.2.2  bouyer          * the sync level of the method. This mechanism provides some
    240  1.1.1.2.2.2  bouyer          * deadlock prevention
    241  1.1.1.2.2.2  bouyer          *
    242  1.1.1.2.2.2  bouyer          * Top-level method invocation has no walk state at this point
    243  1.1.1.2.2.2  bouyer          */
    244  1.1.1.2.2.2  bouyer         if (WalkState &&
    245  1.1.1.2.2.2  bouyer             (WalkState->Thread->CurrentSyncLevel > ObjDesc->Method.Mutex->Mutex.SyncLevel))
    246  1.1.1.2.2.2  bouyer         {
    247  1.1.1.2.2.2  bouyer             ACPI_ERROR ((AE_INFO,
    248  1.1.1.2.2.2  bouyer                 "Cannot acquire Mutex for method [%4.4s], current SyncLevel is too large (%u)",
    249  1.1.1.2.2.2  bouyer                 AcpiUtGetNodeName (MethodNode),
    250  1.1.1.2.2.2  bouyer                 WalkState->Thread->CurrentSyncLevel));
    251  1.1.1.2.2.2  bouyer 
    252  1.1.1.2.2.2  bouyer             return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
    253  1.1.1.2.2.2  bouyer         }
    254  1.1.1.2.2.2  bouyer 
    255  1.1.1.2.2.2  bouyer         /*
    256  1.1.1.2.2.2  bouyer          * Obtain the method mutex if necessary. Do not acquire mutex for a
    257  1.1.1.2.2.2  bouyer          * recursive call.
    258  1.1.1.2.2.2  bouyer          */
    259  1.1.1.2.2.2  bouyer         if (!WalkState ||
    260  1.1.1.2.2.2  bouyer             !ObjDesc->Method.Mutex->Mutex.ThreadId ||
    261  1.1.1.2.2.2  bouyer             (WalkState->Thread->ThreadId != ObjDesc->Method.Mutex->Mutex.ThreadId))
    262  1.1.1.2.2.2  bouyer         {
    263  1.1.1.2.2.2  bouyer             /*
    264  1.1.1.2.2.2  bouyer              * Acquire the method mutex. This releases the interpreter if we
    265  1.1.1.2.2.2  bouyer              * block (and reacquires it before it returns)
    266  1.1.1.2.2.2  bouyer              */
    267  1.1.1.2.2.2  bouyer             Status = AcpiExSystemWaitMutex (ObjDesc->Method.Mutex->Mutex.OsMutex,
    268  1.1.1.2.2.2  bouyer                         ACPI_WAIT_FOREVER);
    269  1.1.1.2.2.2  bouyer             if (ACPI_FAILURE (Status))
    270  1.1.1.2.2.2  bouyer             {
    271  1.1.1.2.2.2  bouyer                 return_ACPI_STATUS (Status);
    272  1.1.1.2.2.2  bouyer             }
    273  1.1.1.2.2.2  bouyer 
    274  1.1.1.2.2.2  bouyer             /* Update the mutex and walk info and save the original SyncLevel */
    275  1.1.1.2.2.2  bouyer 
    276  1.1.1.2.2.2  bouyer             if (WalkState)
    277  1.1.1.2.2.2  bouyer             {
    278  1.1.1.2.2.2  bouyer                 ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
    279  1.1.1.2.2.2  bouyer                     WalkState->Thread->CurrentSyncLevel;
    280  1.1.1.2.2.2  bouyer 
    281  1.1.1.2.2.2  bouyer                 ObjDesc->Method.Mutex->Mutex.ThreadId = WalkState->Thread->ThreadId;
    282  1.1.1.2.2.2  bouyer                 WalkState->Thread->CurrentSyncLevel = ObjDesc->Method.SyncLevel;
    283  1.1.1.2.2.2  bouyer             }
    284  1.1.1.2.2.2  bouyer             else
    285  1.1.1.2.2.2  bouyer             {
    286  1.1.1.2.2.2  bouyer                 ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
    287  1.1.1.2.2.2  bouyer                     ObjDesc->Method.Mutex->Mutex.SyncLevel;
    288  1.1.1.2.2.2  bouyer             }
    289  1.1.1.2.2.2  bouyer         }
    290  1.1.1.2.2.2  bouyer 
    291  1.1.1.2.2.2  bouyer         /* Always increase acquisition depth */
    292  1.1.1.2.2.2  bouyer 
    293  1.1.1.2.2.2  bouyer         ObjDesc->Method.Mutex->Mutex.AcquisitionDepth++;
    294  1.1.1.2.2.2  bouyer     }
    295  1.1.1.2.2.2  bouyer 
    296  1.1.1.2.2.2  bouyer     /*
    297  1.1.1.2.2.2  bouyer      * Allocate an Owner ID for this method, only if this is the first thread
    298  1.1.1.2.2.2  bouyer      * to begin concurrent execution. We only need one OwnerId, even if the
    299  1.1.1.2.2.2  bouyer      * method is invoked recursively.
    300  1.1.1.2.2.2  bouyer      */
    301  1.1.1.2.2.2  bouyer     if (!ObjDesc->Method.OwnerId)
    302  1.1.1.2.2.2  bouyer     {
    303  1.1.1.2.2.2  bouyer         Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
    304  1.1.1.2.2.2  bouyer         if (ACPI_FAILURE (Status))
    305  1.1.1.2.2.2  bouyer         {
    306  1.1.1.2.2.2  bouyer             goto Cleanup;
    307  1.1.1.2.2.2  bouyer         }
    308  1.1.1.2.2.2  bouyer     }
    309  1.1.1.2.2.2  bouyer 
    310  1.1.1.2.2.2  bouyer     /*
    311  1.1.1.2.2.2  bouyer      * Increment the method parse tree thread count since it has been
    312  1.1.1.2.2.2  bouyer      * reentered one more time (even if it is the same thread)
    313  1.1.1.2.2.2  bouyer      */
    314  1.1.1.2.2.2  bouyer     ObjDesc->Method.ThreadCount++;
    315  1.1.1.2.2.2  bouyer     AcpiMethodCount++;
    316  1.1.1.2.2.2  bouyer     return_ACPI_STATUS (Status);
    317  1.1.1.2.2.2  bouyer 
    318  1.1.1.2.2.2  bouyer 
    319  1.1.1.2.2.2  bouyer Cleanup:
    320  1.1.1.2.2.2  bouyer     /* On error, must release the method mutex (if present) */
    321  1.1.1.2.2.2  bouyer 
    322  1.1.1.2.2.2  bouyer     if (ObjDesc->Method.Mutex)
    323  1.1.1.2.2.2  bouyer     {
    324  1.1.1.2.2.2  bouyer         AcpiOsReleaseMutex (ObjDesc->Method.Mutex->Mutex.OsMutex);
    325  1.1.1.2.2.2  bouyer     }
    326  1.1.1.2.2.2  bouyer     return_ACPI_STATUS (Status);
    327  1.1.1.2.2.2  bouyer }
    328  1.1.1.2.2.2  bouyer 
    329  1.1.1.2.2.2  bouyer 
    330  1.1.1.2.2.2  bouyer /*******************************************************************************
    331  1.1.1.2.2.2  bouyer  *
    332  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiDsCallControlMethod
    333  1.1.1.2.2.2  bouyer  *
    334  1.1.1.2.2.2  bouyer  * PARAMETERS:  Thread              - Info for this thread
    335  1.1.1.2.2.2  bouyer  *              ThisWalkState       - Current walk state
    336  1.1.1.2.2.2  bouyer  *              Op                  - Current Op to be walked
    337  1.1.1.2.2.2  bouyer  *
    338  1.1.1.2.2.2  bouyer  * RETURN:      Status
    339  1.1.1.2.2.2  bouyer  *
    340  1.1.1.2.2.2  bouyer  * DESCRIPTION: Transfer execution to a called control method
    341  1.1.1.2.2.2  bouyer  *
    342  1.1.1.2.2.2  bouyer  ******************************************************************************/
    343  1.1.1.2.2.2  bouyer 
    344  1.1.1.2.2.2  bouyer ACPI_STATUS
    345  1.1.1.2.2.2  bouyer AcpiDsCallControlMethod (
    346  1.1.1.2.2.2  bouyer     ACPI_THREAD_STATE       *Thread,
    347  1.1.1.2.2.2  bouyer     ACPI_WALK_STATE         *ThisWalkState,
    348  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op)
    349  1.1.1.2.2.2  bouyer {
    350  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    351  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *MethodNode;
    352  1.1.1.2.2.2  bouyer     ACPI_WALK_STATE         *NextWalkState = NULL;
    353  1.1.1.2.2.2  bouyer     ACPI_OPERAND_OBJECT     *ObjDesc;
    354  1.1.1.2.2.2  bouyer     ACPI_EVALUATE_INFO      *Info;
    355  1.1.1.2.2.2  bouyer     UINT32                  i;
    356  1.1.1.2.2.2  bouyer 
    357  1.1.1.2.2.2  bouyer 
    358  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE_PTR (DsCallControlMethod, ThisWalkState);
    359  1.1.1.2.2.2  bouyer 
    360  1.1.1.2.2.2  bouyer     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Calling method %p, currentstate=%p\n",
    361  1.1.1.2.2.2  bouyer         ThisWalkState->PrevOp, ThisWalkState));
    362  1.1.1.2.2.2  bouyer 
    363  1.1.1.2.2.2  bouyer     /*
    364  1.1.1.2.2.2  bouyer      * Get the namespace entry for the control method we are about to call
    365  1.1.1.2.2.2  bouyer      */
    366  1.1.1.2.2.2  bouyer     MethodNode = ThisWalkState->MethodCallNode;
    367  1.1.1.2.2.2  bouyer     if (!MethodNode)
    368  1.1.1.2.2.2  bouyer     {
    369  1.1.1.2.2.2  bouyer         return_ACPI_STATUS (AE_NULL_ENTRY);
    370  1.1.1.2.2.2  bouyer     }
    371  1.1.1.2.2.2  bouyer 
    372  1.1.1.2.2.2  bouyer     ObjDesc = AcpiNsGetAttachedObject (MethodNode);
    373  1.1.1.2.2.2  bouyer     if (!ObjDesc)
    374  1.1.1.2.2.2  bouyer     {
    375  1.1.1.2.2.2  bouyer         return_ACPI_STATUS (AE_NULL_OBJECT);
    376  1.1.1.2.2.2  bouyer     }
    377  1.1.1.2.2.2  bouyer 
    378  1.1.1.2.2.2  bouyer     /* Init for new method, possibly wait on method mutex */
    379  1.1.1.2.2.2  bouyer 
    380  1.1.1.2.2.2  bouyer     Status = AcpiDsBeginMethodExecution (MethodNode, ObjDesc,
    381  1.1.1.2.2.2  bouyer                 ThisWalkState);
    382  1.1.1.2.2.2  bouyer     if (ACPI_FAILURE (Status))
    383  1.1.1.2.2.2  bouyer     {
    384  1.1.1.2.2.2  bouyer         return_ACPI_STATUS (Status);
    385  1.1.1.2.2.2  bouyer     }
    386  1.1.1.2.2.2  bouyer 
    387  1.1.1.2.2.2  bouyer     /* Begin method parse/execution. Create a new walk state */
    388  1.1.1.2.2.2  bouyer 
    389  1.1.1.2.2.2  bouyer     NextWalkState = AcpiDsCreateWalkState (ObjDesc->Method.OwnerId,
    390  1.1.1.2.2.2  bouyer                         NULL, ObjDesc, Thread);
    391  1.1.1.2.2.2  bouyer     if (!NextWalkState)
    392  1.1.1.2.2.2  bouyer     {
    393  1.1.1.2.2.2  bouyer         Status = AE_NO_MEMORY;
    394  1.1.1.2.2.2  bouyer         goto Cleanup;
    395  1.1.1.2.2.2  bouyer     }
    396  1.1.1.2.2.2  bouyer 
    397  1.1.1.2.2.2  bouyer     /*
    398  1.1.1.2.2.2  bouyer      * The resolved arguments were put on the previous walk state's operand
    399  1.1.1.2.2.2  bouyer      * stack. Operands on the previous walk state stack always
    400  1.1.1.2.2.2  bouyer      * start at index 0. Also, null terminate the list of arguments
    401  1.1.1.2.2.2  bouyer      */
    402  1.1.1.2.2.2  bouyer     ThisWalkState->Operands [ThisWalkState->NumOperands] = NULL;
    403  1.1.1.2.2.2  bouyer 
    404  1.1.1.2.2.2  bouyer     /*
    405  1.1.1.2.2.2  bouyer      * Allocate and initialize the evaluation information block
    406  1.1.1.2.2.2  bouyer      * TBD: this is somewhat inefficient, should change interface to
    407  1.1.1.2.2.2  bouyer      * DsInitAmlWalk. For now, keeps this struct off the CPU stack
    408  1.1.1.2.2.2  bouyer      */
    409  1.1.1.2.2.2  bouyer     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    410  1.1.1.2.2.2  bouyer     if (!Info)
    411  1.1.1.2.2.2  bouyer     {
    412  1.1.1.2.2.2  bouyer         return_ACPI_STATUS (AE_NO_MEMORY);
    413  1.1.1.2.2.2  bouyer     }
    414  1.1.1.2.2.2  bouyer 
    415  1.1.1.2.2.2  bouyer     Info->Parameters = &ThisWalkState->Operands[0];
    416  1.1.1.2.2.2  bouyer 
    417  1.1.1.2.2.2  bouyer     Status = AcpiDsInitAmlWalk (NextWalkState, NULL, MethodNode,
    418  1.1.1.2.2.2  bouyer                 ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength,
    419  1.1.1.2.2.2  bouyer                 Info, ACPI_IMODE_EXECUTE);
    420  1.1.1.2.2.2  bouyer 
    421  1.1.1.2.2.2  bouyer     ACPI_FREE (Info);
    422  1.1.1.2.2.2  bouyer     if (ACPI_FAILURE (Status))
    423  1.1.1.2.2.2  bouyer     {
    424  1.1.1.2.2.2  bouyer         goto Cleanup;
    425  1.1.1.2.2.2  bouyer     }
    426  1.1.1.2.2.2  bouyer 
    427  1.1.1.2.2.2  bouyer     /*
    428  1.1.1.2.2.2  bouyer      * Delete the operands on the previous walkstate operand stack
    429  1.1.1.2.2.2  bouyer      * (they were copied to new objects)
    430  1.1.1.2.2.2  bouyer      */
    431  1.1.1.2.2.2  bouyer     for (i = 0; i < ObjDesc->Method.ParamCount; i++)
    432  1.1.1.2.2.2  bouyer     {
    433  1.1.1.2.2.2  bouyer         AcpiUtRemoveReference (ThisWalkState->Operands [i]);
    434  1.1.1.2.2.2  bouyer         ThisWalkState->Operands [i] = NULL;
    435  1.1.1.2.2.2  bouyer     }
    436  1.1.1.2.2.2  bouyer 
    437  1.1.1.2.2.2  bouyer     /* Clear the operand stack */
    438  1.1.1.2.2.2  bouyer 
    439  1.1.1.2.2.2  bouyer     ThisWalkState->NumOperands = 0;
    440  1.1.1.2.2.2  bouyer 
    441  1.1.1.2.2.2  bouyer     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    442  1.1.1.2.2.2  bouyer         "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
    443  1.1.1.2.2.2  bouyer         MethodNode->Name.Ascii, NextWalkState));
    444  1.1.1.2.2.2  bouyer 
    445  1.1.1.2.2.2  bouyer     /* Invoke an internal method if necessary */
    446  1.1.1.2.2.2  bouyer 
    447  1.1.1.2.2.2  bouyer     if (ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
    448  1.1.1.2.2.2  bouyer     {
    449  1.1.1.2.2.2  bouyer         Status = ObjDesc->Method.Dispatch.Implementation (NextWalkState);
    450  1.1.1.2.2.2  bouyer         if (Status == AE_OK)
    451  1.1.1.2.2.2  bouyer         {
    452  1.1.1.2.2.2  bouyer             Status = AE_CTRL_TERMINATE;
    453  1.1.1.2.2.2  bouyer         }
    454  1.1.1.2.2.2  bouyer     }
    455  1.1.1.2.2.2  bouyer 
    456  1.1.1.2.2.2  bouyer     return_ACPI_STATUS (Status);
    457  1.1.1.2.2.2  bouyer 
    458  1.1.1.2.2.2  bouyer 
    459  1.1.1.2.2.2  bouyer Cleanup:
    460  1.1.1.2.2.2  bouyer 
    461  1.1.1.2.2.2  bouyer     /* On error, we must terminate the method properly */
    462  1.1.1.2.2.2  bouyer 
    463  1.1.1.2.2.2  bouyer     AcpiDsTerminateControlMethod (ObjDesc, NextWalkState);
    464  1.1.1.2.2.2  bouyer     if (NextWalkState)
    465  1.1.1.2.2.2  bouyer     {
    466  1.1.1.2.2.2  bouyer         AcpiDsDeleteWalkState (NextWalkState);
    467  1.1.1.2.2.2  bouyer     }
    468  1.1.1.2.2.2  bouyer 
    469  1.1.1.2.2.2  bouyer     return_ACPI_STATUS (Status);
    470  1.1.1.2.2.2  bouyer }
    471  1.1.1.2.2.2  bouyer 
    472  1.1.1.2.2.2  bouyer 
    473  1.1.1.2.2.2  bouyer /*******************************************************************************
    474  1.1.1.2.2.2  bouyer  *
    475  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiDsRestartControlMethod
    476  1.1.1.2.2.2  bouyer  *
    477  1.1.1.2.2.2  bouyer  * PARAMETERS:  WalkState           - State for preempted method (caller)
    478  1.1.1.2.2.2  bouyer  *              ReturnDesc          - Return value from the called method
    479  1.1.1.2.2.2  bouyer  *
    480  1.1.1.2.2.2  bouyer  * RETURN:      Status
    481  1.1.1.2.2.2  bouyer  *
    482  1.1.1.2.2.2  bouyer  * DESCRIPTION: Restart a method that was preempted by another (nested) method
    483  1.1.1.2.2.2  bouyer  *              invocation.  Handle the return value (if any) from the callee.
    484  1.1.1.2.2.2  bouyer  *
    485  1.1.1.2.2.2  bouyer  ******************************************************************************/
    486  1.1.1.2.2.2  bouyer 
    487  1.1.1.2.2.2  bouyer ACPI_STATUS
    488  1.1.1.2.2.2  bouyer AcpiDsRestartControlMethod (
    489  1.1.1.2.2.2  bouyer     ACPI_WALK_STATE         *WalkState,
    490  1.1.1.2.2.2  bouyer     ACPI_OPERAND_OBJECT     *ReturnDesc)
    491  1.1.1.2.2.2  bouyer {
    492  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    493  1.1.1.2.2.2  bouyer     int                     SameAsImplicitReturn;
    494  1.1.1.2.2.2  bouyer 
    495  1.1.1.2.2.2  bouyer 
    496  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE_PTR (DsRestartControlMethod, WalkState);
    497  1.1.1.2.2.2  bouyer 
    498  1.1.1.2.2.2  bouyer 
    499  1.1.1.2.2.2  bouyer     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    500  1.1.1.2.2.2  bouyer         "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
    501  1.1.1.2.2.2  bouyer         AcpiUtGetNodeName (WalkState->MethodNode),
    502  1.1.1.2.2.2  bouyer         WalkState->MethodCallOp, ReturnDesc));
    503  1.1.1.2.2.2  bouyer 
    504  1.1.1.2.2.2  bouyer     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    505  1.1.1.2.2.2  bouyer         "    ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
    506  1.1.1.2.2.2  bouyer         WalkState->ReturnUsed,
    507  1.1.1.2.2.2  bouyer         WalkState->Results, WalkState));
    508  1.1.1.2.2.2  bouyer 
    509  1.1.1.2.2.2  bouyer     /* Did the called method return a value? */
    510  1.1.1.2.2.2  bouyer 
    511  1.1.1.2.2.2  bouyer     if (ReturnDesc)
    512  1.1.1.2.2.2  bouyer     {
    513  1.1.1.2.2.2  bouyer         /* Is the implicit return object the same as the return desc? */
    514  1.1.1.2.2.2  bouyer 
    515  1.1.1.2.2.2  bouyer         SameAsImplicitReturn = (WalkState->ImplicitReturnObj == ReturnDesc);
    516  1.1.1.2.2.2  bouyer 
    517  1.1.1.2.2.2  bouyer         /* Are we actually going to use the return value? */
    518  1.1.1.2.2.2  bouyer 
    519  1.1.1.2.2.2  bouyer         if (WalkState->ReturnUsed)
    520  1.1.1.2.2.2  bouyer         {
    521  1.1.1.2.2.2  bouyer             /* Save the return value from the previous method */
    522  1.1.1.2.2.2  bouyer 
    523  1.1.1.2.2.2  bouyer             Status = AcpiDsResultPush (ReturnDesc, WalkState);
    524  1.1.1.2.2.2  bouyer             if (ACPI_FAILURE (Status))
    525  1.1.1.2.2.2  bouyer             {
    526  1.1.1.2.2.2  bouyer                 AcpiUtRemoveReference (ReturnDesc);
    527  1.1.1.2.2.2  bouyer                 return_ACPI_STATUS (Status);
    528  1.1.1.2.2.2  bouyer             }
    529  1.1.1.2.2.2  bouyer 
    530  1.1.1.2.2.2  bouyer             /*
    531  1.1.1.2.2.2  bouyer              * Save as THIS method's return value in case it is returned
    532  1.1.1.2.2.2  bouyer              * immediately to yet another method
    533  1.1.1.2.2.2  bouyer              */
    534  1.1.1.2.2.2  bouyer             WalkState->ReturnDesc = ReturnDesc;
    535  1.1.1.2.2.2  bouyer         }
    536  1.1.1.2.2.2  bouyer 
    537  1.1.1.2.2.2  bouyer         /*
    538  1.1.1.2.2.2  bouyer          * The following code is the optional support for the so-called
    539  1.1.1.2.2.2  bouyer          * "implicit return". Some AML code assumes that the last value of the
    540  1.1.1.2.2.2  bouyer          * method is "implicitly" returned to the caller, in the absence of an
    541  1.1.1.2.2.2  bouyer          * explicit return value.
    542  1.1.1.2.2.2  bouyer          *
    543  1.1.1.2.2.2  bouyer          * Just save the last result of the method as the return value.
    544  1.1.1.2.2.2  bouyer          *
    545  1.1.1.2.2.2  bouyer          * NOTE: this is optional because the ASL language does not actually
    546  1.1.1.2.2.2  bouyer          * support this behavior.
    547  1.1.1.2.2.2  bouyer          */
    548  1.1.1.2.2.2  bouyer         else if (!AcpiDsDoImplicitReturn (ReturnDesc, WalkState, FALSE) ||
    549  1.1.1.2.2.2  bouyer                  SameAsImplicitReturn)
    550  1.1.1.2.2.2  bouyer         {
    551  1.1.1.2.2.2  bouyer             /*
    552  1.1.1.2.2.2  bouyer              * Delete the return value if it will not be used by the
    553  1.1.1.2.2.2  bouyer              * calling method or remove one reference if the explicit return
    554  1.1.1.2.2.2  bouyer              * is the same as the implicit return value.
    555  1.1.1.2.2.2  bouyer              */
    556  1.1.1.2.2.2  bouyer             AcpiUtRemoveReference (ReturnDesc);
    557  1.1.1.2.2.2  bouyer         }
    558  1.1.1.2.2.2  bouyer     }
    559  1.1.1.2.2.2  bouyer 
    560  1.1.1.2.2.2  bouyer     return_ACPI_STATUS (AE_OK);
    561  1.1.1.2.2.2  bouyer }
    562  1.1.1.2.2.2  bouyer 
    563  1.1.1.2.2.2  bouyer 
    564  1.1.1.2.2.2  bouyer /*******************************************************************************
    565  1.1.1.2.2.2  bouyer  *
    566  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiDsTerminateControlMethod
    567  1.1.1.2.2.2  bouyer  *
    568  1.1.1.2.2.2  bouyer  * PARAMETERS:  MethodDesc          - Method object
    569  1.1.1.2.2.2  bouyer  *              WalkState           - State associated with the method
    570  1.1.1.2.2.2  bouyer  *
    571  1.1.1.2.2.2  bouyer  * RETURN:      None
    572  1.1.1.2.2.2  bouyer  *
    573  1.1.1.2.2.2  bouyer  * DESCRIPTION: Terminate a control method.  Delete everything that the method
    574  1.1.1.2.2.2  bouyer  *              created, delete all locals and arguments, and delete the parse
    575  1.1.1.2.2.2  bouyer  *              tree if requested.
    576  1.1.1.2.2.2  bouyer  *
    577  1.1.1.2.2.2  bouyer  * MUTEX:       Interpreter is locked
    578  1.1.1.2.2.2  bouyer  *
    579  1.1.1.2.2.2  bouyer  ******************************************************************************/
    580  1.1.1.2.2.2  bouyer 
    581  1.1.1.2.2.2  bouyer void
    582  1.1.1.2.2.2  bouyer AcpiDsTerminateControlMethod (
    583  1.1.1.2.2.2  bouyer     ACPI_OPERAND_OBJECT     *MethodDesc,
    584  1.1.1.2.2.2  bouyer     ACPI_WALK_STATE         *WalkState)
    585  1.1.1.2.2.2  bouyer {
    586  1.1.1.2.2.2  bouyer 
    587  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE_PTR (DsTerminateControlMethod, WalkState);
    588  1.1.1.2.2.2  bouyer 
    589  1.1.1.2.2.2  bouyer 
    590  1.1.1.2.2.2  bouyer     /* MethodDesc is required, WalkState is optional */
    591  1.1.1.2.2.2  bouyer 
    592  1.1.1.2.2.2  bouyer     if (!MethodDesc)
    593  1.1.1.2.2.2  bouyer     {
    594  1.1.1.2.2.2  bouyer         return_VOID;
    595  1.1.1.2.2.2  bouyer     }
    596  1.1.1.2.2.2  bouyer 
    597  1.1.1.2.2.2  bouyer     if (WalkState)
    598  1.1.1.2.2.2  bouyer     {
    599  1.1.1.2.2.2  bouyer         /* Delete all arguments and locals */
    600  1.1.1.2.2.2  bouyer 
    601  1.1.1.2.2.2  bouyer         AcpiDsMethodDataDeleteAll (WalkState);
    602  1.1.1.2.2.2  bouyer 
    603  1.1.1.2.2.2  bouyer         /*
    604  1.1.1.2.2.2  bouyer          * If method is serialized, release the mutex and restore the
    605  1.1.1.2.2.2  bouyer          * current sync level for this thread
    606  1.1.1.2.2.2  bouyer          */
    607  1.1.1.2.2.2  bouyer         if (MethodDesc->Method.Mutex)
    608  1.1.1.2.2.2  bouyer         {
    609  1.1.1.2.2.2  bouyer             /* Acquisition Depth handles recursive calls */
    610  1.1.1.2.2.2  bouyer 
    611  1.1.1.2.2.2  bouyer             MethodDesc->Method.Mutex->Mutex.AcquisitionDepth--;
    612  1.1.1.2.2.2  bouyer             if (!MethodDesc->Method.Mutex->Mutex.AcquisitionDepth)
    613  1.1.1.2.2.2  bouyer             {
    614  1.1.1.2.2.2  bouyer                 WalkState->Thread->CurrentSyncLevel =
    615  1.1.1.2.2.2  bouyer                     MethodDesc->Method.Mutex->Mutex.OriginalSyncLevel;
    616  1.1.1.2.2.2  bouyer 
    617  1.1.1.2.2.2  bouyer                 AcpiOsReleaseMutex (MethodDesc->Method.Mutex->Mutex.OsMutex);
    618  1.1.1.2.2.2  bouyer                 MethodDesc->Method.Mutex->Mutex.ThreadId = 0;
    619  1.1.1.2.2.2  bouyer             }
    620  1.1.1.2.2.2  bouyer         }
    621  1.1.1.2.2.2  bouyer 
    622  1.1.1.2.2.2  bouyer         /*
    623  1.1.1.2.2.2  bouyer          * Delete any namespace objects created anywhere within the
    624  1.1.1.2.2.2  bouyer          * namespace by the execution of this method. Unless:
    625  1.1.1.2.2.2  bouyer          * 1) This method is a module-level executable code method, in which
    626  1.1.1.2.2.2  bouyer          *    case we want make the objects permanent.
    627  1.1.1.2.2.2  bouyer          * 2) There are other threads executing the method, in which case we
    628  1.1.1.2.2.2  bouyer          *    will wait until the last thread has completed.
    629  1.1.1.2.2.2  bouyer          */
    630  1.1.1.2.2.2  bouyer         if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) &&
    631  1.1.1.2.2.2  bouyer              (MethodDesc->Method.ThreadCount == 1))
    632  1.1.1.2.2.2  bouyer         {
    633  1.1.1.2.2.2  bouyer             /* Delete any direct children of (created by) this method */
    634  1.1.1.2.2.2  bouyer 
    635  1.1.1.2.2.2  bouyer             AcpiNsDeleteNamespaceSubtree (WalkState->MethodNode);
    636  1.1.1.2.2.2  bouyer 
    637  1.1.1.2.2.2  bouyer             /*
    638  1.1.1.2.2.2  bouyer              * Delete any objects that were created by this method
    639  1.1.1.2.2.2  bouyer              * elsewhere in the namespace (if any were created).
    640  1.1.1.2.2.2  bouyer              * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the
    641  1.1.1.2.2.2  bouyer              * deletion such that we don't have to perform an entire
    642  1.1.1.2.2.2  bouyer              * namespace walk for every control method execution.
    643  1.1.1.2.2.2  bouyer              */
    644  1.1.1.2.2.2  bouyer             if (MethodDesc->Method.InfoFlags & ACPI_METHOD_MODIFIED_NAMESPACE)
    645  1.1.1.2.2.2  bouyer             {
    646  1.1.1.2.2.2  bouyer                 AcpiNsDeleteNamespaceByOwner (MethodDesc->Method.OwnerId);
    647  1.1.1.2.2.2  bouyer                 MethodDesc->Method.InfoFlags &= ~ACPI_METHOD_MODIFIED_NAMESPACE;
    648  1.1.1.2.2.2  bouyer             }
    649  1.1.1.2.2.2  bouyer         }
    650  1.1.1.2.2.2  bouyer     }
    651  1.1.1.2.2.2  bouyer 
    652  1.1.1.2.2.2  bouyer     /* Decrement the thread count on the method */
    653  1.1.1.2.2.2  bouyer 
    654  1.1.1.2.2.2  bouyer     if (MethodDesc->Method.ThreadCount)
    655  1.1.1.2.2.2  bouyer     {
    656  1.1.1.2.2.2  bouyer         MethodDesc->Method.ThreadCount--;
    657  1.1.1.2.2.2  bouyer     }
    658  1.1.1.2.2.2  bouyer     else
    659  1.1.1.2.2.2  bouyer     {
    660  1.1.1.2.2.2  bouyer         ACPI_ERROR ((AE_INFO,
    661  1.1.1.2.2.2  bouyer             "Invalid zero thread count in method"));
    662  1.1.1.2.2.2  bouyer     }
    663  1.1.1.2.2.2  bouyer 
    664  1.1.1.2.2.2  bouyer     /* Are there any other threads currently executing this method? */
    665  1.1.1.2.2.2  bouyer 
    666  1.1.1.2.2.2  bouyer     if (MethodDesc->Method.ThreadCount)
    667  1.1.1.2.2.2  bouyer     {
    668  1.1.1.2.2.2  bouyer         /*
    669  1.1.1.2.2.2  bouyer          * Additional threads. Do not release the OwnerId in this case,
    670  1.1.1.2.2.2  bouyer          * we immediately reuse it for the next thread executing this method
    671  1.1.1.2.2.2  bouyer          */
    672  1.1.1.2.2.2  bouyer         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    673  1.1.1.2.2.2  bouyer             "*** Completed execution of one thread, %u threads remaining\n",
    674  1.1.1.2.2.2  bouyer             MethodDesc->Method.ThreadCount));
    675  1.1.1.2.2.2  bouyer     }
    676  1.1.1.2.2.2  bouyer     else
    677  1.1.1.2.2.2  bouyer     {
    678  1.1.1.2.2.2  bouyer         /* This is the only executing thread for this method */
    679  1.1.1.2.2.2  bouyer 
    680  1.1.1.2.2.2  bouyer         /*
    681  1.1.1.2.2.2  bouyer          * Support to dynamically change a method from NotSerialized to
    682  1.1.1.2.2.2  bouyer          * Serialized if it appears that the method is incorrectly written and
    683  1.1.1.2.2.2  bouyer          * does not support multiple thread execution. The best example of this
    684  1.1.1.2.2.2  bouyer          * is if such a method creates namespace objects and blocks. A second
    685  1.1.1.2.2.2  bouyer          * thread will fail with an AE_ALREADY_EXISTS exception.
    686  1.1.1.2.2.2  bouyer          *
    687  1.1.1.2.2.2  bouyer          * This code is here because we must wait until the last thread exits
    688  1.1.1.2.2.2  bouyer          * before marking the method as serialized.
    689  1.1.1.2.2.2  bouyer          */
    690  1.1.1.2.2.2  bouyer         if (MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED_PENDING)
    691  1.1.1.2.2.2  bouyer         {
    692  1.1.1.2.2.2  bouyer             if (WalkState)
    693  1.1.1.2.2.2  bouyer             {
    694  1.1.1.2.2.2  bouyer                 ACPI_INFO ((AE_INFO,
    695  1.1.1.2.2.2  bouyer                     "Marking method %4.4s as Serialized because of AE_ALREADY_EXISTS error",
    696  1.1.1.2.2.2  bouyer                     WalkState->MethodNode->Name.Ascii));
    697  1.1.1.2.2.2  bouyer             }
    698  1.1.1.2.2.2  bouyer 
    699  1.1.1.2.2.2  bouyer             /*
    700  1.1.1.2.2.2  bouyer              * Method tried to create an object twice and was marked as
    701  1.1.1.2.2.2  bouyer              * "pending serialized". The probable cause is that the method
    702  1.1.1.2.2.2  bouyer              * cannot handle reentrancy.
    703  1.1.1.2.2.2  bouyer              *
    704  1.1.1.2.2.2  bouyer              * The method was created as NotSerialized, but it tried to create
    705  1.1.1.2.2.2  bouyer              * a named object and then blocked, causing the second thread
    706  1.1.1.2.2.2  bouyer              * entrance to begin and then fail. Workaround this problem by
    707  1.1.1.2.2.2  bouyer              * marking the method permanently as Serialized when the last
    708  1.1.1.2.2.2  bouyer              * thread exits here.
    709  1.1.1.2.2.2  bouyer              */
    710  1.1.1.2.2.2  bouyer             MethodDesc->Method.InfoFlags &= ~ACPI_METHOD_SERIALIZED_PENDING;
    711  1.1.1.2.2.2  bouyer             MethodDesc->Method.InfoFlags |= ACPI_METHOD_SERIALIZED;
    712  1.1.1.2.2.2  bouyer             MethodDesc->Method.SyncLevel = 0;
    713  1.1.1.2.2.2  bouyer         }
    714  1.1.1.2.2.2  bouyer 
    715  1.1.1.2.2.2  bouyer         /* No more threads, we can free the OwnerId */
    716  1.1.1.2.2.2  bouyer 
    717  1.1.1.2.2.2  bouyer         if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL))
    718  1.1.1.2.2.2  bouyer         {
    719  1.1.1.2.2.2  bouyer             AcpiUtReleaseOwnerId (&MethodDesc->Method.OwnerId);
    720  1.1.1.2.2.2  bouyer         }
    721  1.1.1.2.2.2  bouyer     }
    722  1.1.1.2.2.2  bouyer 
    723  1.1.1.2.2.2  bouyer     return_VOID;
    724  1.1.1.2.2.2  bouyer }
    725  1.1.1.2.2.2  bouyer 
    726  1.1.1.2.2.2  bouyer 
    727