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