xref: /freebsd/sys/contrib/dev/acpica/components/debugger/dbexec.c (revision 7661de35d15f582ab33e3bd6b8d909601557e436)
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 <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acdebug.h>
48 #include <contrib/dev/acpica/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 void
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 void
241 AcpiDbExecuteSetup (
242     ACPI_DB_METHOD_INFO     *Info)
243 {
244 
245     /* Catenate the current scope to the supplied name */
246 
247     Info->Pathname[0] = 0;
248     if ((Info->Name[0] != '\\') &&
249         (Info->Name[0] != '/'))
250     {
251         ACPI_STRCAT (Info->Pathname, AcpiGbl_DbScopeBuf);
252     }
253 
254     ACPI_STRCAT (Info->Pathname, Info->Name);
255     AcpiDbPrepNamestring (Info->Pathname);
256 
257     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
258     AcpiOsPrintf ("Evaluating %s\n", Info->Pathname);
259 
260     if (Info->Flags & EX_SINGLE_STEP)
261     {
262         AcpiGbl_CmSingleStep = TRUE;
263         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
264     }
265 
266     else
267     {
268         /* No single step, allow redirection to a file */
269 
270         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
271     }
272 }
273 
274 
275 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
276 UINT32
277 AcpiDbGetCacheInfo (
278     ACPI_MEMORY_LIST        *Cache)
279 {
280 
281     return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
282 }
283 #endif
284 
285 /*******************************************************************************
286  *
287  * FUNCTION:    AcpiDbGetOutstandingAllocations
288  *
289  * PARAMETERS:  None
290  *
291  * RETURN:      Current global allocation count minus cache entries
292  *
293  * DESCRIPTION: Determine the current number of "outstanding" allocations --
294  *              those allocations that have not been freed and also are not
295  *              in one of the various object caches.
296  *
297  ******************************************************************************/
298 
299 static UINT32
300 AcpiDbGetOutstandingAllocations (
301     void)
302 {
303     UINT32                  Outstanding = 0;
304 
305 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
306 
307     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
308     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
309     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
310     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
311 #endif
312 
313     return (Outstanding);
314 }
315 
316 
317 /*******************************************************************************
318  *
319  * FUNCTION:    AcpiDbExecutionWalk
320  *
321  * PARAMETERS:  WALK_CALLBACK
322  *
323  * RETURN:      Status
324  *
325  * DESCRIPTION: Execute a control method. Name is relative to the current
326  *              scope.
327  *
328  ******************************************************************************/
329 
330 static ACPI_STATUS
331 AcpiDbExecutionWalk (
332     ACPI_HANDLE             ObjHandle,
333     UINT32                  NestingLevel,
334     void                    *Context,
335     void                    **ReturnValue)
336 {
337     ACPI_OPERAND_OBJECT     *ObjDesc;
338     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
339     ACPI_BUFFER             ReturnObj;
340     ACPI_STATUS             Status;
341 
342 
343     ObjDesc = AcpiNsGetAttachedObject (Node);
344     if (ObjDesc->Method.ParamCount)
345     {
346         return (AE_OK);
347     }
348 
349     ReturnObj.Pointer = NULL;
350     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
351 
352     AcpiNsPrintNodePathname (Node, "Evaluating");
353 
354     /* Do the actual method execution */
355 
356     AcpiOsPrintf ("\n");
357     AcpiGbl_MethodExecuting = TRUE;
358 
359     Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
360 
361     AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n", AcpiUtGetNodeName (Node),
362             AcpiFormatException (Status));
363     AcpiGbl_MethodExecuting = FALSE;
364 
365     return (AE_OK);
366 }
367 
368 
369 /*******************************************************************************
370  *
371  * FUNCTION:    AcpiDbExecute
372  *
373  * PARAMETERS:  Name                - Name of method to execute
374  *              Args                - Parameters to the method
375  *              Flags               - single step/no single step
376  *
377  * RETURN:      None
378  *
379  * DESCRIPTION: Execute a control method. Name is relative to the current
380  *              scope.
381  *
382  ******************************************************************************/
383 
384 void
385 AcpiDbExecute (
386     char                    *Name,
387     char                    **Args,
388     ACPI_OBJECT_TYPE        *Types,
389     UINT32                  Flags)
390 {
391     ACPI_STATUS             Status;
392     ACPI_BUFFER             ReturnObj;
393     char                    *NameString;
394 
395 
396 #ifdef ACPI_DEBUG_OUTPUT
397     UINT32                  PreviousAllocations;
398     UINT32                  Allocations;
399 
400 
401     /* Memory allocation tracking */
402 
403     PreviousAllocations = AcpiDbGetOutstandingAllocations ();
404 #endif
405 
406     if (*Name == '*')
407     {
408         (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
409                     ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
410         return;
411     }
412     else
413     {
414         NameString = ACPI_ALLOCATE (ACPI_STRLEN (Name) + 1);
415         if (!NameString)
416         {
417             return;
418         }
419 
420         ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
421 
422         ACPI_STRCPY (NameString, Name);
423         AcpiUtStrupr (NameString);
424         AcpiGbl_DbMethodInfo.Name = NameString;
425         AcpiGbl_DbMethodInfo.Args = Args;
426         AcpiGbl_DbMethodInfo.Types = Types;
427         AcpiGbl_DbMethodInfo.Flags = Flags;
428 
429         ReturnObj.Pointer = NULL;
430         ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
431 
432         AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
433 
434         /* Get the NS node, determines existence also */
435 
436         Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
437             &AcpiGbl_DbMethodInfo.Method);
438         if (ACPI_SUCCESS (Status))
439         {
440             Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj);
441         }
442         ACPI_FREE (NameString);
443     }
444 
445     /*
446      * Allow any handlers in separate threads to complete.
447      * (Such as Notify handlers invoked from AML executed above).
448      */
449     AcpiOsSleep ((UINT64) 10);
450 
451 #ifdef ACPI_DEBUG_OUTPUT
452 
453     /* Memory allocation tracking */
454 
455     Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
456 
457     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
458 
459     if (Allocations > 0)
460     {
461         AcpiOsPrintf ("0x%X Outstanding allocations after evaluation of %s\n",
462                         Allocations, AcpiGbl_DbMethodInfo.Pathname);
463     }
464 #endif
465 
466     if (ACPI_FAILURE (Status))
467     {
468         AcpiOsPrintf ("Evaluation of %s failed with status %s\n",
469             AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status));
470     }
471     else
472     {
473         /* Display a return object, if any */
474 
475         if (ReturnObj.Length)
476         {
477             AcpiOsPrintf (
478                 "Evaluation of %s returned object %p, external buffer length %X\n",
479                 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
480                 (UINT32) ReturnObj.Length);
481             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
482 
483             /* Dump a _PLD buffer if present */
484 
485             if (ACPI_COMPARE_NAME ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
486                     AcpiGbl_DbMethodInfo.Method)->Name.Ascii), METHOD_NAME__PLD))
487             {
488                 AcpiDbDumpPldBuffer (ReturnObj.Pointer);
489             }
490         }
491         else
492         {
493             AcpiOsPrintf ("No object was returned from evaluation of %s\n",
494                 AcpiGbl_DbMethodInfo.Pathname);
495         }
496     }
497 
498     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
499 }
500 
501 
502 /*******************************************************************************
503  *
504  * FUNCTION:    AcpiDbMethodThread
505  *
506  * PARAMETERS:  Context             - Execution info segment
507  *
508  * RETURN:      None
509  *
510  * DESCRIPTION: Debugger execute thread. Waits for a command line, then
511  *              simply dispatches it.
512  *
513  ******************************************************************************/
514 
515 static void ACPI_SYSTEM_XFACE
516 AcpiDbMethodThread (
517     void                    *Context)
518 {
519     ACPI_STATUS             Status;
520     ACPI_DB_METHOD_INFO     *Info = Context;
521     ACPI_DB_METHOD_INFO     LocalInfo;
522     UINT32                  i;
523     UINT8                   Allow;
524     ACPI_BUFFER             ReturnObj;
525 
526 
527     /*
528      * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
529      * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
530      * concurrently.
531      *
532      * Note: The arguments we are passing are used by the ASL test suite
533      * (aslts). Do not change them without updating the tests.
534      */
535     (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
536 
537     if (Info->InitArgs)
538     {
539         AcpiDbUint32ToHexString (Info->NumCreated, Info->IndexOfThreadStr);
540         AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (), Info->IdOfThreadStr);
541     }
542 
543     if (Info->Threads && (Info->NumCreated < Info->NumThreads))
544     {
545         Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
546     }
547 
548     LocalInfo = *Info;
549     LocalInfo.Args = LocalInfo.Arguments;
550     LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
551     LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
552     LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
553     LocalInfo.Arguments[3] = NULL;
554 
555     LocalInfo.Types = LocalInfo.ArgTypes;
556 
557     (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
558 
559     for (i = 0; i < Info->NumLoops; i++)
560     {
561         Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
562         if (ACPI_FAILURE (Status))
563         {
564             AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n",
565                 AcpiFormatException (Status), Info->Pathname, i);
566             if (Status == AE_ABORT_METHOD)
567             {
568                 break;
569             }
570         }
571 
572 #if 0
573         if ((i % 100) == 0)
574         {
575             AcpiOsPrintf ("%u loops, Thread 0x%x\n", i, AcpiOsGetThreadId ());
576         }
577 
578         if (ReturnObj.Length)
579         {
580             AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n",
581                 Info->Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length);
582             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
583         }
584 #endif
585     }
586 
587     /* Signal our completion */
588 
589     Allow = 0;
590     (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate, 1, ACPI_WAIT_FOREVER);
591     Info->NumCompleted++;
592 
593     if (Info->NumCompleted == Info->NumThreads)
594     {
595         /* Do signal for main thread once only */
596         Allow = 1;
597     }
598 
599     (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
600 
601     if (Allow)
602     {
603         Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
604         if (ACPI_FAILURE (Status))
605         {
606             AcpiOsPrintf ("Could not signal debugger thread sync semaphore, %s\n",
607                 AcpiFormatException (Status));
608         }
609     }
610 }
611 
612 
613 /*******************************************************************************
614  *
615  * FUNCTION:    AcpiDbCreateExecutionThreads
616  *
617  * PARAMETERS:  NumThreadsArg           - Number of threads to create
618  *              NumLoopsArg             - Loop count for the thread(s)
619  *              MethodNameArg           - Control method to execute
620  *
621  * RETURN:      None
622  *
623  * DESCRIPTION: Create threads to execute method(s)
624  *
625  ******************************************************************************/
626 
627 void
628 AcpiDbCreateExecutionThreads (
629     char                    *NumThreadsArg,
630     char                    *NumLoopsArg,
631     char                    *MethodNameArg)
632 {
633     ACPI_STATUS             Status;
634     UINT32                  NumThreads;
635     UINT32                  NumLoops;
636     UINT32                  i;
637     UINT32                  Size;
638     ACPI_MUTEX              MainThreadGate;
639     ACPI_MUTEX              ThreadCompleteGate;
640     ACPI_MUTEX              InfoGate;
641 
642 
643     /* Get the arguments */
644 
645     NumThreads = ACPI_STRTOUL (NumThreadsArg, NULL, 0);
646     NumLoops   = ACPI_STRTOUL (NumLoopsArg, NULL, 0);
647 
648     if (!NumThreads || !NumLoops)
649     {
650         AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
651             NumThreads, NumLoops);
652         return;
653     }
654 
655     /*
656      * Create the semaphore for synchronization of
657      * the created threads with the main thread.
658      */
659     Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
660     if (ACPI_FAILURE (Status))
661     {
662         AcpiOsPrintf ("Could not create semaphore for synchronization with the main thread, %s\n",
663             AcpiFormatException (Status));
664         return;
665     }
666 
667     /*
668      * Create the semaphore for synchronization
669      * between the created threads.
670      */
671     Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
672     if (ACPI_FAILURE (Status))
673     {
674         AcpiOsPrintf ("Could not create semaphore for synchronization between the created threads, %s\n",
675             AcpiFormatException (Status));
676         (void) AcpiOsDeleteSemaphore (MainThreadGate);
677         return;
678     }
679 
680     Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
681     if (ACPI_FAILURE (Status))
682     {
683         AcpiOsPrintf ("Could not create semaphore for synchronization of AcpiGbl_DbMethodInfo, %s\n",
684             AcpiFormatException (Status));
685         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
686         (void) AcpiOsDeleteSemaphore (MainThreadGate);
687         return;
688     }
689 
690     ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
691 
692     /* Array to store IDs of threads */
693 
694     AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
695     Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
696     AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
697     if (AcpiGbl_DbMethodInfo.Threads == NULL)
698     {
699         AcpiOsPrintf ("No memory for thread IDs array\n");
700         (void) AcpiOsDeleteSemaphore (MainThreadGate);
701         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
702         (void) AcpiOsDeleteSemaphore (InfoGate);
703         return;
704     }
705     ACPI_MEMSET (AcpiGbl_DbMethodInfo.Threads, 0, Size);
706 
707     /* Setup the context to be passed to each thread */
708 
709     AcpiGbl_DbMethodInfo.Name = MethodNameArg;
710     AcpiGbl_DbMethodInfo.Flags = 0;
711     AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
712     AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
713     AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
714     AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
715 
716     /* Init arguments to be passed to method */
717 
718     AcpiGbl_DbMethodInfo.InitArgs = 1;
719     AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
720     AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
721     AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
722     AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
723     AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
724 
725     AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
726     AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
727     AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
728     AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
729 
730     AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
731 
732     AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
733 
734     /* Get the NS node, determines existence also */
735 
736     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
737         &AcpiGbl_DbMethodInfo.Method);
738     if (ACPI_FAILURE (Status))
739     {
740         AcpiOsPrintf ("%s Could not get handle for %s\n",
741             AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
742         goto CleanupAndExit;
743     }
744 
745     /* Create the threads */
746 
747     AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
748         NumThreads, NumLoops);
749 
750     for (i = 0; i < (NumThreads); i++)
751     {
752         Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbMethodThread,
753             &AcpiGbl_DbMethodInfo);
754         if (ACPI_FAILURE (Status))
755         {
756             break;
757         }
758     }
759 
760     /* Wait for all threads to complete */
761 
762     (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
763 
764     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
765     AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
766     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
767 
768 CleanupAndExit:
769 
770     /* Cleanup and exit */
771 
772     (void) AcpiOsDeleteSemaphore (MainThreadGate);
773     (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
774     (void) AcpiOsDeleteSemaphore (InfoGate);
775 
776     AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
777     AcpiGbl_DbMethodInfo.Threads = NULL;
778 }
779 
780 #endif /* ACPI_DEBUGGER */
781