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