Home | History | Annotate | Line # | Download | only in debugger
dbexec.c revision 1.13
      1 /*******************************************************************************
      2  *
      3  * Module Name: dbexec - debugger control method execution
      4  *
      5  ******************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2017, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "acpi.h"
     45 #include "accommon.h"
     46 #include "acdebug.h"
     47 #include "acnamesp.h"
     48 
     49 
     50 #define _COMPONENT          ACPI_CA_DEBUGGER
     51         ACPI_MODULE_NAME    ("dbexec")
     52 
     53 
     54 static ACPI_DB_METHOD_INFO          AcpiGbl_DbMethodInfo;
     55 
     56 /* Local prototypes */
     57 
     58 static ACPI_STATUS
     59 AcpiDbExecuteMethod (
     60     ACPI_DB_METHOD_INFO     *Info,
     61     ACPI_BUFFER             *ReturnObj);
     62 
     63 static ACPI_STATUS
     64 AcpiDbExecuteSetup (
     65     ACPI_DB_METHOD_INFO     *Info);
     66 
     67 static UINT32
     68 AcpiDbGetOutstandingAllocations (
     69     void);
     70 
     71 static void ACPI_SYSTEM_XFACE
     72 AcpiDbMethodThread (
     73     void                    *Context);
     74 
     75 static ACPI_STATUS
     76 AcpiDbExecutionWalk (
     77     ACPI_HANDLE             ObjHandle,
     78     UINT32                  NestingLevel,
     79     void                    *Context,
     80     void                    **ReturnValue);
     81 
     82 
     83 /*******************************************************************************
     84  *
     85  * FUNCTION:    AcpiDbDeleteObjects
     86  *
     87  * PARAMETERS:  Count               - Count of objects in the list
     88  *              Objects             - Array of ACPI_OBJECTs to be deleted
     89  *
     90  * RETURN:      None
     91  *
     92  * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
     93  *              packages via recursion.
     94  *
     95  ******************************************************************************/
     96 
     97 void
     98 AcpiDbDeleteObjects (
     99     UINT32                  Count,
    100     ACPI_OBJECT             *Objects)
    101 {
    102     UINT32                  i;
    103 
    104 
    105     for (i = 0; i < Count; i++)
    106     {
    107         switch (Objects[i].Type)
    108         {
    109         case ACPI_TYPE_BUFFER:
    110 
    111             ACPI_FREE (Objects[i].Buffer.Pointer);
    112             break;
    113 
    114         case ACPI_TYPE_PACKAGE:
    115 
    116             /* Recursive call to delete package elements */
    117 
    118             AcpiDbDeleteObjects (Objects[i].Package.Count,
    119                 Objects[i].Package.Elements);
    120 
    121             /* Free the elements array */
    122 
    123             ACPI_FREE (Objects[i].Package.Elements);
    124             break;
    125 
    126         default:
    127 
    128             break;
    129         }
    130     }
    131 }
    132 
    133 
    134 /*******************************************************************************
    135  *
    136  * FUNCTION:    AcpiDbExecuteMethod
    137  *
    138  * PARAMETERS:  Info            - Valid info segment
    139  *              ReturnObj       - Where to put return object
    140  *
    141  * RETURN:      Status
    142  *
    143  * DESCRIPTION: Execute a control method.
    144  *
    145  ******************************************************************************/
    146 
    147 static ACPI_STATUS
    148 AcpiDbExecuteMethod (
    149     ACPI_DB_METHOD_INFO     *Info,
    150     ACPI_BUFFER             *ReturnObj)
    151 {
    152     ACPI_STATUS             Status;
    153     ACPI_OBJECT_LIST        ParamObjects;
    154     ACPI_OBJECT             Params[ACPI_DEBUGGER_MAX_ARGS + 1];
    155     UINT32                  i;
    156 
    157 
    158     ACPI_FUNCTION_TRACE (DbExecuteMethod);
    159 
    160 
    161     if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
    162     {
    163         AcpiOsPrintf ("Warning: debug output is not enabled!\n");
    164     }
    165 
    166     ParamObjects.Count = 0;
    167     ParamObjects.Pointer = NULL;
    168 
    169     /* Pass through any command-line arguments */
    170 
    171     if (Info->Args && Info->Args[0])
    172     {
    173         /* Get arguments passed on the command line */
    174 
    175         for (i = 0; (Info->Args[i] && *(Info->Args[i])); i++)
    176         {
    177             /* Convert input string (token) to an actual ACPI_OBJECT */
    178 
    179             Status = AcpiDbConvertToObject (Info->Types[i],
    180                 Info->Args[i], &Params[i]);
    181             if (ACPI_FAILURE (Status))
    182             {
    183                 ACPI_EXCEPTION ((AE_INFO, Status,
    184                     "While parsing method arguments"));
    185                 goto Cleanup;
    186             }
    187         }
    188 
    189         ParamObjects.Count = i;
    190         ParamObjects.Pointer = Params;
    191     }
    192 
    193     /* Prepare for a return object of arbitrary size */
    194 
    195     ReturnObj->Pointer = AcpiGbl_DbBuffer;
    196     ReturnObj->Length  = ACPI_DEBUG_BUFFER_SIZE;
    197 
    198     /* Do the actual method execution */
    199 
    200     AcpiGbl_MethodExecuting = TRUE;
    201     Status = AcpiEvaluateObject (NULL, Info->Pathname,
    202         &ParamObjects, ReturnObj);
    203 
    204     AcpiGbl_CmSingleStep = FALSE;
    205     AcpiGbl_MethodExecuting = FALSE;
    206 
    207     if (ACPI_FAILURE (Status))
    208     {
    209         if ((Status == AE_ABORT_METHOD) || AcpiGbl_AbortMethod)
    210         {
    211             /* Clear the abort and fall back to the debugger prompt */
    212 
    213             ACPI_EXCEPTION ((AE_INFO, Status,
    214                 "Aborting top-level method"));
    215 
    216             AcpiGbl_AbortMethod = FALSE;
    217             Status = AE_OK;
    218             goto Cleanup;
    219         }
    220 
    221         ACPI_EXCEPTION ((AE_INFO, Status,
    222             "while executing %s from debugger", Info->Pathname));
    223 
    224         if (Status == AE_BUFFER_OVERFLOW)
    225         {
    226             ACPI_ERROR ((AE_INFO,
    227                 "Possible overflow of internal debugger "
    228                 "buffer (size 0x%X needed 0x%X)",
    229                 ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length));
    230         }
    231     }
    232 
    233 Cleanup:
    234     AcpiDbDeleteObjects (ParamObjects.Count, Params);
    235     return_ACPI_STATUS (Status);
    236 }
    237 
    238 
    239 /*******************************************************************************
    240  *
    241  * FUNCTION:    AcpiDbExecuteSetup
    242  *
    243  * PARAMETERS:  Info            - Valid method info
    244  *
    245  * RETURN:      None
    246  *
    247  * DESCRIPTION: Setup info segment prior to method execution
    248  *
    249  ******************************************************************************/
    250 
    251 static ACPI_STATUS
    252 AcpiDbExecuteSetup (
    253     ACPI_DB_METHOD_INFO     *Info)
    254 {
    255     ACPI_STATUS             Status;
    256 
    257 
    258     ACPI_FUNCTION_NAME (DbExecuteSetup);
    259 
    260 
    261     /* Catenate the current scope to the supplied name */
    262 
    263     Info->Pathname[0] = 0;
    264     if ((Info->Name[0] != '\\') &&
    265         (Info->Name[0] != '/'))
    266     {
    267         if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
    268             AcpiGbl_DbScopeBuf))
    269         {
    270             Status = AE_BUFFER_OVERFLOW;
    271             goto ErrorExit;
    272         }
    273     }
    274 
    275     if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
    276         Info->Name))
    277     {
    278         Status = AE_BUFFER_OVERFLOW;
    279         goto ErrorExit;
    280     }
    281 
    282     AcpiDbPrepNamestring (Info->Pathname);
    283 
    284     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
    285     AcpiOsPrintf ("Evaluating %s\n", Info->Pathname);
    286 
    287     if (Info->Flags & EX_SINGLE_STEP)
    288     {
    289         AcpiGbl_CmSingleStep = TRUE;
    290         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
    291     }
    292 
    293     else
    294     {
    295         /* No single step, allow redirection to a file */
    296 
    297         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
    298     }
    299 
    300     return (AE_OK);
    301 
    302 ErrorExit:
    303 
    304     ACPI_EXCEPTION ((AE_INFO, Status, "During setup for method execution"));
    305     return (Status);
    306 }
    307 
    308 
    309 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    310 UINT32
    311 AcpiDbGetCacheInfo (
    312     ACPI_MEMORY_LIST        *Cache)
    313 {
    314 
    315     return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
    316 }
    317 #endif
    318 
    319 /*******************************************************************************
    320  *
    321  * FUNCTION:    AcpiDbGetOutstandingAllocations
    322  *
    323  * PARAMETERS:  None
    324  *
    325  * RETURN:      Current global allocation count minus cache entries
    326  *
    327  * DESCRIPTION: Determine the current number of "outstanding" allocations --
    328  *              those allocations that have not been freed and also are not
    329  *              in one of the various object caches.
    330  *
    331  ******************************************************************************/
    332 
    333 #ifdef ACPI_DEBUG_OUTPUT
    334 static UINT32
    335 AcpiDbGetOutstandingAllocations (
    336     void)
    337 {
    338     UINT32                  Outstanding = 0;
    339 
    340 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    341 
    342     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
    343     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
    344     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
    345     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
    346 #endif
    347 
    348     return (Outstanding);
    349 }
    350 #endif
    351 
    352 
    353 /*******************************************************************************
    354  *
    355  * FUNCTION:    AcpiDbExecutionWalk
    356  *
    357  * PARAMETERS:  WALK_CALLBACK
    358  *
    359  * RETURN:      Status
    360  *
    361  * DESCRIPTION: Execute a control method. Name is relative to the current
    362  *              scope.
    363  *
    364  ******************************************************************************/
    365 
    366 static ACPI_STATUS
    367 AcpiDbExecutionWalk (
    368     ACPI_HANDLE             ObjHandle,
    369     UINT32                  NestingLevel,
    370     void                    *Context,
    371     void                    **ReturnValue)
    372 {
    373     ACPI_OPERAND_OBJECT     *ObjDesc;
    374     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    375     ACPI_BUFFER             ReturnObj;
    376     ACPI_STATUS             Status;
    377 
    378 
    379     ObjDesc = AcpiNsGetAttachedObject (Node);
    380     if (ObjDesc->Method.ParamCount)
    381     {
    382         return (AE_OK);
    383     }
    384 
    385     ReturnObj.Pointer = NULL;
    386     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    387 
    388     AcpiNsPrintNodePathname (Node, "Evaluating");
    389 
    390     /* Do the actual method execution */
    391 
    392     AcpiOsPrintf ("\n");
    393     AcpiGbl_MethodExecuting = TRUE;
    394 
    395     Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
    396 
    397     AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n",
    398         AcpiUtGetNodeName (Node),
    399         AcpiFormatException (Status));
    400 
    401     AcpiGbl_MethodExecuting = FALSE;
    402     return (AE_OK);
    403 }
    404 
    405 
    406 /*******************************************************************************
    407  *
    408  * FUNCTION:    AcpiDbExecute
    409  *
    410  * PARAMETERS:  Name                - Name of method to execute
    411  *              Args                - Parameters to the method
    412  *              Types               -
    413  *              Flags               - single step/no single step
    414  *
    415  * RETURN:      None
    416  *
    417  * DESCRIPTION: Execute a control method. Name is relative to the current
    418  *              scope.
    419  *
    420  ******************************************************************************/
    421 
    422 void
    423 AcpiDbExecute (
    424     char                    *Name,
    425     char                    **Args,
    426     ACPI_OBJECT_TYPE        *Types,
    427     UINT32                  Flags)
    428 {
    429     ACPI_STATUS             Status;
    430     ACPI_BUFFER             ReturnObj;
    431     char                    *NameString;
    432 
    433 #ifdef ACPI_DEBUG_OUTPUT
    434     UINT32                  PreviousAllocations;
    435     UINT32                  Allocations;
    436 #endif
    437 
    438 
    439     /*
    440      * Allow one execution to be performed by debugger or single step
    441      * execution will be dead locked by the interpreter mutexes.
    442      */
    443     if (AcpiGbl_MethodExecuting)
    444     {
    445         AcpiOsPrintf ("Only one debugger execution is allowed.\n");
    446         return;
    447     }
    448 
    449 #ifdef ACPI_DEBUG_OUTPUT
    450     /* Memory allocation tracking */
    451 
    452     PreviousAllocations = AcpiDbGetOutstandingAllocations ();
    453 #endif
    454 
    455     if (*Name == '*')
    456     {
    457         (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
    458             ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
    459         return;
    460     }
    461 
    462     NameString = ACPI_ALLOCATE (strlen (Name) + 1);
    463     if (!NameString)
    464     {
    465         return;
    466     }
    467 
    468     memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
    469     strcpy (NameString, Name);
    470     AcpiUtStrupr (NameString);
    471 
    472     /* Subcommand to Execute all predefined names in the namespace */
    473 
    474     if (!strncmp (NameString, "PREDEF", 6))
    475     {
    476         AcpiDbEvaluatePredefinedNames ();
    477         ACPI_FREE (NameString);
    478         return;
    479     }
    480 
    481     AcpiGbl_DbMethodInfo.Name = NameString;
    482     AcpiGbl_DbMethodInfo.Args = Args;
    483     AcpiGbl_DbMethodInfo.Types = Types;
    484     AcpiGbl_DbMethodInfo.Flags = Flags;
    485 
    486     ReturnObj.Pointer = NULL;
    487     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    488 
    489     Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
    490     if (ACPI_FAILURE (Status))
    491     {
    492         ACPI_FREE (NameString);
    493         return;
    494     }
    495 
    496     /* Get the NS node, determines existence also */
    497 
    498     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
    499         &AcpiGbl_DbMethodInfo.Method);
    500     if (ACPI_SUCCESS (Status))
    501     {
    502         Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo,
    503             &ReturnObj);
    504     }
    505     ACPI_FREE (NameString);
    506 
    507     /*
    508      * Allow any handlers in separate threads to complete.
    509      * (Such as Notify handlers invoked from AML executed above).
    510      */
    511     AcpiOsSleep ((UINT64) 10);
    512 
    513 #ifdef ACPI_DEBUG_OUTPUT
    514 
    515     /* Memory allocation tracking */
    516 
    517     Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
    518 
    519     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
    520 
    521     if (Allocations > 0)
    522     {
    523         AcpiOsPrintf (
    524             "0x%X Outstanding allocations after evaluation of %s\n",
    525             Allocations, AcpiGbl_DbMethodInfo.Pathname);
    526     }
    527 #endif
    528 
    529     if (ACPI_FAILURE (Status))
    530     {
    531         AcpiOsPrintf ("Evaluation of %s failed with status %s\n",
    532             AcpiGbl_DbMethodInfo.Pathname,
    533             AcpiFormatException (Status));
    534     }
    535     else
    536     {
    537         /* Display a return object, if any */
    538 
    539         if (ReturnObj.Length)
    540         {
    541             AcpiOsPrintf (
    542                 "Evaluation of %s returned object %p, "
    543                 "external buffer length %X\n",
    544                 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
    545                 (UINT32) ReturnObj.Length);
    546 
    547             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
    548 
    549             /* Dump a _PLD buffer if present */
    550 
    551             if (ACPI_COMPARE_NAME ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
    552                 AcpiGbl_DbMethodInfo.Method)->Name.Ascii),
    553                 METHOD_NAME__PLD))
    554             {
    555                 AcpiDbDumpPldBuffer (ReturnObj.Pointer);
    556             }
    557         }
    558         else
    559         {
    560             AcpiOsPrintf ("No object was returned from evaluation of %s\n",
    561                 AcpiGbl_DbMethodInfo.Pathname);
    562         }
    563     }
    564 
    565     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
    566 }
    567 
    568 
    569 /*******************************************************************************
    570  *
    571  * FUNCTION:    AcpiDbMethodThread
    572  *
    573  * PARAMETERS:  Context             - Execution info segment
    574  *
    575  * RETURN:      None
    576  *
    577  * DESCRIPTION: Debugger execute thread. Waits for a command line, then
    578  *              simply dispatches it.
    579  *
    580  ******************************************************************************/
    581 
    582 static void ACPI_SYSTEM_XFACE
    583 AcpiDbMethodThread (
    584     void                    *Context)
    585 {
    586     ACPI_STATUS             Status;
    587     ACPI_DB_METHOD_INFO     *Info = Context;
    588     ACPI_DB_METHOD_INFO     LocalInfo;
    589     UINT32                  i;
    590     UINT8                   Allow;
    591     ACPI_BUFFER             ReturnObj;
    592 
    593 
    594     /*
    595      * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
    596      * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
    597      * concurrently.
    598      *
    599      * Note: The arguments we are passing are used by the ASL test suite
    600      * (aslts). Do not change them without updating the tests.
    601      */
    602     (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
    603 
    604     if (Info->InitArgs)
    605     {
    606         AcpiDbUint32ToHexString (Info->NumCreated,
    607             Info->IndexOfThreadStr);
    608         AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (),
    609             Info->IdOfThreadStr);
    610     }
    611 
    612     if (Info->Threads && (Info->NumCreated < Info->NumThreads))
    613     {
    614         Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
    615     }
    616 
    617     LocalInfo = *Info;
    618     LocalInfo.Args = LocalInfo.Arguments;
    619     LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
    620     LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
    621     LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
    622     LocalInfo.Arguments[3] = NULL;
    623 
    624     LocalInfo.Types = LocalInfo.ArgTypes;
    625 
    626     (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
    627 
    628     for (i = 0; i < Info->NumLoops; i++)
    629     {
    630         Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
    631         if (ACPI_FAILURE (Status))
    632         {
    633             AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n",
    634                 AcpiFormatException (Status), Info->Pathname, i);
    635             if (Status == AE_ABORT_METHOD)
    636             {
    637                 break;
    638             }
    639         }
    640 
    641 #if 0
    642         if ((i % 100) == 0)
    643         {
    644             AcpiOsPrintf ("%u loops, Thread 0x%x\n",
    645                 i, AcpiOsGetThreadId ());
    646         }
    647 
    648         if (ReturnObj.Length)
    649         {
    650             AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n",
    651                 Info->Pathname, ReturnObj.Pointer,
    652                 (UINT32) ReturnObj.Length);
    653             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
    654         }
    655 #endif
    656     }
    657 
    658     /* Signal our completion */
    659 
    660     Allow = 0;
    661     (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate,
    662         1, ACPI_WAIT_FOREVER);
    663     Info->NumCompleted++;
    664 
    665     if (Info->NumCompleted == Info->NumThreads)
    666     {
    667         /* Do signal for main thread once only */
    668         Allow = 1;
    669     }
    670 
    671     (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
    672 
    673     if (Allow)
    674     {
    675         Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
    676         if (ACPI_FAILURE (Status))
    677         {
    678             AcpiOsPrintf (
    679                 "Could not signal debugger thread sync semaphore, %s\n",
    680                 AcpiFormatException (Status));
    681         }
    682     }
    683 }
    684 
    685 
    686 /*******************************************************************************
    687  *
    688  * FUNCTION:    AcpiDbCreateExecutionThreads
    689  *
    690  * PARAMETERS:  NumThreadsArg           - Number of threads to create
    691  *              NumLoopsArg             - Loop count for the thread(s)
    692  *              MethodNameArg           - Control method to execute
    693  *
    694  * RETURN:      None
    695  *
    696  * DESCRIPTION: Create threads to execute method(s)
    697  *
    698  ******************************************************************************/
    699 
    700 void
    701 AcpiDbCreateExecutionThreads (
    702     char                    *NumThreadsArg,
    703     char                    *NumLoopsArg,
    704     char                    *MethodNameArg)
    705 {
    706     ACPI_STATUS             Status;
    707     UINT32                  NumThreads;
    708     UINT32                  NumLoops;
    709     UINT32                  i;
    710     UINT32                  Size;
    711     ACPI_MUTEX              MainThreadGate;
    712     ACPI_MUTEX              ThreadCompleteGate;
    713     ACPI_MUTEX              InfoGate;
    714 
    715 
    716     /* Get the arguments */
    717 
    718     NumThreads = strtoul (NumThreadsArg, NULL, 0);
    719     NumLoops = strtoul (NumLoopsArg, NULL, 0);
    720 
    721     if (!NumThreads || !NumLoops)
    722     {
    723         AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
    724             NumThreads, NumLoops);
    725         return;
    726     }
    727 
    728     /*
    729      * Create the semaphore for synchronization of
    730      * the created threads with the main thread.
    731      */
    732     Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
    733     if (ACPI_FAILURE (Status))
    734     {
    735         AcpiOsPrintf ("Could not create semaphore for "
    736             "synchronization with the main thread, %s\n",
    737             AcpiFormatException (Status));
    738         return;
    739     }
    740 
    741     /*
    742      * Create the semaphore for synchronization
    743      * between the created threads.
    744      */
    745     Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
    746     if (ACPI_FAILURE (Status))
    747     {
    748         AcpiOsPrintf ("Could not create semaphore for "
    749             "synchronization between the created threads, %s\n",
    750             AcpiFormatException (Status));
    751 
    752         (void) AcpiOsDeleteSemaphore (MainThreadGate);
    753         return;
    754     }
    755 
    756     Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
    757     if (ACPI_FAILURE (Status))
    758     {
    759         AcpiOsPrintf ("Could not create semaphore for "
    760             "synchronization of AcpiGbl_DbMethodInfo, %s\n",
    761             AcpiFormatException (Status));
    762 
    763         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
    764         (void) AcpiOsDeleteSemaphore (MainThreadGate);
    765         return;
    766     }
    767 
    768     memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
    769 
    770     /* Array to store IDs of threads */
    771 
    772     AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
    773     Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
    774 
    775     AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
    776     if (AcpiGbl_DbMethodInfo.Threads == NULL)
    777     {
    778         AcpiOsPrintf ("No memory for thread IDs array\n");
    779         (void) AcpiOsDeleteSemaphore (MainThreadGate);
    780         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
    781         (void) AcpiOsDeleteSemaphore (InfoGate);
    782         return;
    783     }
    784     memset (AcpiGbl_DbMethodInfo.Threads, 0, Size);
    785 
    786     /* Setup the context to be passed to each thread */
    787 
    788     AcpiGbl_DbMethodInfo.Name = MethodNameArg;
    789     AcpiGbl_DbMethodInfo.Flags = 0;
    790     AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
    791     AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
    792     AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
    793     AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
    794 
    795     /* Init arguments to be passed to method */
    796 
    797     AcpiGbl_DbMethodInfo.InitArgs = 1;
    798     AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
    799     AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
    800     AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
    801     AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
    802     AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
    803 
    804     AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
    805     AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
    806     AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
    807     AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
    808 
    809     AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
    810 
    811     Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
    812     if (ACPI_FAILURE (Status))
    813     {
    814         goto CleanupAndExit;
    815     }
    816 
    817     /* Get the NS node, determines existence also */
    818 
    819     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
    820         &AcpiGbl_DbMethodInfo.Method);
    821     if (ACPI_FAILURE (Status))
    822     {
    823         AcpiOsPrintf ("%s Could not get handle for %s\n",
    824             AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
    825         goto CleanupAndExit;
    826     }
    827 
    828     /* Create the threads */
    829 
    830     AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
    831         NumThreads, NumLoops);
    832 
    833     for (i = 0; i < (NumThreads); i++)
    834     {
    835         Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD, AcpiDbMethodThread,
    836             &AcpiGbl_DbMethodInfo);
    837         if (ACPI_FAILURE (Status))
    838         {
    839             break;
    840         }
    841     }
    842 
    843     /* Wait for all threads to complete */
    844 
    845     (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
    846 
    847     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
    848     AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
    849     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
    850 
    851 CleanupAndExit:
    852 
    853     /* Cleanup and exit */
    854 
    855     (void) AcpiOsDeleteSemaphore (MainThreadGate);
    856     (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
    857     (void) AcpiOsDeleteSemaphore (InfoGate);
    858 
    859     AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
    860     AcpiGbl_DbMethodInfo.Threads = NULL;
    861 }
    862