xref: /freebsd/sys/contrib/dev/acpica/components/debugger/dbexec.c (revision 49b49cda41feabe3439f7318e8bf40e3896c7bf4)
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 <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acdebug.h>
47 #include <contrib/dev/acpica/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         ACPI_EXCEPTION ((AE_INFO, Status,
210             "while executing %s from debugger", Info->Pathname));
211 
212         if (Status == AE_BUFFER_OVERFLOW)
213         {
214             ACPI_ERROR ((AE_INFO,
215                 "Possible overflow of internal debugger "
216                 "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",
384         AcpiUtGetNodeName (Node),
385         AcpiFormatException (Status));
386 
387     AcpiGbl_MethodExecuting = FALSE;
388     return (AE_OK);
389 }
390 
391 
392 /*******************************************************************************
393  *
394  * FUNCTION:    AcpiDbExecute
395  *
396  * PARAMETERS:  Name                - Name of method to execute
397  *              Args                - Parameters to the method
398  *              Types               -
399  *              Flags               - single step/no single step
400  *
401  * RETURN:      None
402  *
403  * DESCRIPTION: Execute a control method. Name is relative to the current
404  *              scope.
405  *
406  ******************************************************************************/
407 
408 void
409 AcpiDbExecute (
410     char                    *Name,
411     char                    **Args,
412     ACPI_OBJECT_TYPE        *Types,
413     UINT32                  Flags)
414 {
415     ACPI_STATUS             Status;
416     ACPI_BUFFER             ReturnObj;
417     char                    *NameString;
418 
419 #ifdef ACPI_DEBUG_OUTPUT
420     UINT32                  PreviousAllocations;
421     UINT32                  Allocations;
422 
423 
424     /* Memory allocation tracking */
425 
426     PreviousAllocations = AcpiDbGetOutstandingAllocations ();
427 #endif
428 
429     if (*Name == '*')
430     {
431         (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
432             ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
433         return;
434     }
435     else
436     {
437         NameString = ACPI_ALLOCATE (strlen (Name) + 1);
438         if (!NameString)
439         {
440             return;
441         }
442 
443         memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
444 
445         strcpy (NameString, Name);
446         AcpiUtStrupr (NameString);
447         AcpiGbl_DbMethodInfo.Name = NameString;
448         AcpiGbl_DbMethodInfo.Args = Args;
449         AcpiGbl_DbMethodInfo.Types = Types;
450         AcpiGbl_DbMethodInfo.Flags = Flags;
451 
452         ReturnObj.Pointer = NULL;
453         ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
454 
455         Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
456         if (ACPI_FAILURE (Status))
457         {
458             ACPI_FREE (NameString);
459             return;
460         }
461 
462         /* Get the NS node, determines existence also */
463 
464         Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
465             &AcpiGbl_DbMethodInfo.Method);
466         if (ACPI_SUCCESS (Status))
467         {
468             Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo,
469                 &ReturnObj);
470         }
471         ACPI_FREE (NameString);
472     }
473 
474     /*
475      * Allow any handlers in separate threads to complete.
476      * (Such as Notify handlers invoked from AML executed above).
477      */
478     AcpiOsSleep ((UINT64) 10);
479 
480 #ifdef ACPI_DEBUG_OUTPUT
481 
482     /* Memory allocation tracking */
483 
484     Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
485 
486     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
487 
488     if (Allocations > 0)
489     {
490         AcpiOsPrintf (
491             "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,
500             AcpiFormatException (Status));
501     }
502     else
503     {
504         /* Display a return object, if any */
505 
506         if (ReturnObj.Length)
507         {
508             AcpiOsPrintf (
509                 "Evaluation of %s returned object %p, "
510                 "external buffer length %X\n",
511                 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
512                 (UINT32) ReturnObj.Length);
513 
514             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
515 
516             /* Dump a _PLD buffer if present */
517 
518             if (ACPI_COMPARE_NAME ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
519                     AcpiGbl_DbMethodInfo.Method)->Name.Ascii),
520                     METHOD_NAME__PLD))
521             {
522                 AcpiDbDumpPldBuffer (ReturnObj.Pointer);
523             }
524         }
525         else
526         {
527             AcpiOsPrintf ("No object was returned from evaluation of %s\n",
528                 AcpiGbl_DbMethodInfo.Pathname);
529         }
530     }
531 
532     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
533 }
534 
535 
536 /*******************************************************************************
537  *
538  * FUNCTION:    AcpiDbMethodThread
539  *
540  * PARAMETERS:  Context             - Execution info segment
541  *
542  * RETURN:      None
543  *
544  * DESCRIPTION: Debugger execute thread. Waits for a command line, then
545  *              simply dispatches it.
546  *
547  ******************************************************************************/
548 
549 static void ACPI_SYSTEM_XFACE
550 AcpiDbMethodThread (
551     void                    *Context)
552 {
553     ACPI_STATUS             Status;
554     ACPI_DB_METHOD_INFO     *Info = Context;
555     ACPI_DB_METHOD_INFO     LocalInfo;
556     UINT32                  i;
557     UINT8                   Allow;
558     ACPI_BUFFER             ReturnObj;
559 
560 
561     /*
562      * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
563      * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
564      * concurrently.
565      *
566      * Note: The arguments we are passing are used by the ASL test suite
567      * (aslts). Do not change them without updating the tests.
568      */
569     (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
570 
571     if (Info->InitArgs)
572     {
573         AcpiDbUint32ToHexString (Info->NumCreated,
574             Info->IndexOfThreadStr);
575         AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (),
576             Info->IdOfThreadStr);
577     }
578 
579     if (Info->Threads && (Info->NumCreated < Info->NumThreads))
580     {
581         Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
582     }
583 
584     LocalInfo = *Info;
585     LocalInfo.Args = LocalInfo.Arguments;
586     LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
587     LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
588     LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
589     LocalInfo.Arguments[3] = NULL;
590 
591     LocalInfo.Types = LocalInfo.ArgTypes;
592 
593     (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
594 
595     for (i = 0; i < Info->NumLoops; i++)
596     {
597         Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
598         if (ACPI_FAILURE (Status))
599         {
600             AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n",
601                 AcpiFormatException (Status), Info->Pathname, i);
602             if (Status == AE_ABORT_METHOD)
603             {
604                 break;
605             }
606         }
607 
608 #if 0
609         if ((i % 100) == 0)
610         {
611             AcpiOsPrintf ("%u loops, Thread 0x%x\n",
612                 i, AcpiOsGetThreadId ());
613         }
614 
615         if (ReturnObj.Length)
616         {
617             AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n",
618                 Info->Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length);
619             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
620         }
621 #endif
622     }
623 
624     /* Signal our completion */
625 
626     Allow = 0;
627     (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate,
628         1, ACPI_WAIT_FOREVER);
629     Info->NumCompleted++;
630 
631     if (Info->NumCompleted == Info->NumThreads)
632     {
633         /* Do signal for main thread once only */
634         Allow = 1;
635     }
636 
637     (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
638 
639     if (Allow)
640     {
641         Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
642         if (ACPI_FAILURE (Status))
643         {
644             AcpiOsPrintf (
645                 "Could not signal debugger thread sync semaphore, %s\n",
646                 AcpiFormatException (Status));
647         }
648     }
649 }
650 
651 
652 /*******************************************************************************
653  *
654  * FUNCTION:    AcpiDbCreateExecutionThreads
655  *
656  * PARAMETERS:  NumThreadsArg           - Number of threads to create
657  *              NumLoopsArg             - Loop count for the thread(s)
658  *              MethodNameArg           - Control method to execute
659  *
660  * RETURN:      None
661  *
662  * DESCRIPTION: Create threads to execute method(s)
663  *
664  ******************************************************************************/
665 
666 void
667 AcpiDbCreateExecutionThreads (
668     char                    *NumThreadsArg,
669     char                    *NumLoopsArg,
670     char                    *MethodNameArg)
671 {
672     ACPI_STATUS             Status;
673     UINT32                  NumThreads;
674     UINT32                  NumLoops;
675     UINT32                  i;
676     UINT32                  Size;
677     ACPI_MUTEX              MainThreadGate;
678     ACPI_MUTEX              ThreadCompleteGate;
679     ACPI_MUTEX              InfoGate;
680 
681 
682     /* Get the arguments */
683 
684     NumThreads = strtoul (NumThreadsArg, NULL, 0);
685     NumLoops   = strtoul (NumLoopsArg, NULL, 0);
686 
687     if (!NumThreads || !NumLoops)
688     {
689         AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
690             NumThreads, NumLoops);
691         return;
692     }
693 
694     /*
695      * Create the semaphore for synchronization of
696      * the created threads with the main thread.
697      */
698     Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
699     if (ACPI_FAILURE (Status))
700     {
701         AcpiOsPrintf ("Could not create semaphore for "
702             "synchronization with the main thread, %s\n",
703             AcpiFormatException (Status));
704         return;
705     }
706 
707     /*
708      * Create the semaphore for synchronization
709      * between the created threads.
710      */
711     Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
712     if (ACPI_FAILURE (Status))
713     {
714         AcpiOsPrintf ("Could not create semaphore for "
715             "synchronization between the created threads, %s\n",
716             AcpiFormatException (Status));
717 
718         (void) AcpiOsDeleteSemaphore (MainThreadGate);
719         return;
720     }
721 
722     Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
723     if (ACPI_FAILURE (Status))
724     {
725         AcpiOsPrintf ("Could not create semaphore for "
726             "synchronization of AcpiGbl_DbMethodInfo, %s\n",
727             AcpiFormatException (Status));
728 
729         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
730         (void) AcpiOsDeleteSemaphore (MainThreadGate);
731         return;
732     }
733 
734     memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
735 
736     /* Array to store IDs of threads */
737 
738     AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
739     Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
740 
741     AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
742     if (AcpiGbl_DbMethodInfo.Threads == NULL)
743     {
744         AcpiOsPrintf ("No memory for thread IDs array\n");
745         (void) AcpiOsDeleteSemaphore (MainThreadGate);
746         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
747         (void) AcpiOsDeleteSemaphore (InfoGate);
748         return;
749     }
750     memset (AcpiGbl_DbMethodInfo.Threads, 0, Size);
751 
752     /* Setup the context to be passed to each thread */
753 
754     AcpiGbl_DbMethodInfo.Name = MethodNameArg;
755     AcpiGbl_DbMethodInfo.Flags = 0;
756     AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
757     AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
758     AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
759     AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
760 
761     /* Init arguments to be passed to method */
762 
763     AcpiGbl_DbMethodInfo.InitArgs = 1;
764     AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
765     AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
766     AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
767     AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
768     AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
769 
770     AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
771     AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
772     AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
773     AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
774 
775     AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
776 
777     Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
778     if (ACPI_FAILURE (Status))
779     {
780         goto CleanupAndExit;
781     }
782 
783     /* Get the NS node, determines existence also */
784 
785     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
786         &AcpiGbl_DbMethodInfo.Method);
787     if (ACPI_FAILURE (Status))
788     {
789         AcpiOsPrintf ("%s Could not get handle for %s\n",
790             AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
791         goto CleanupAndExit;
792     }
793 
794     /* Create the threads */
795 
796     AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
797         NumThreads, NumLoops);
798 
799     for (i = 0; i < (NumThreads); i++)
800     {
801         Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbMethodThread,
802             &AcpiGbl_DbMethodInfo);
803         if (ACPI_FAILURE (Status))
804         {
805             break;
806         }
807     }
808 
809     /* Wait for all threads to complete */
810 
811     (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
812 
813     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
814     AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
815     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
816 
817 CleanupAndExit:
818 
819     /* Cleanup and exit */
820 
821     (void) AcpiOsDeleteSemaphore (MainThreadGate);
822     (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
823     (void) AcpiOsDeleteSemaphore (InfoGate);
824 
825     AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
826     AcpiGbl_DbMethodInfo.Threads = NULL;
827 }
828