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