xref: /onnv-gate/usr/src/uts/intel/io/acpica/debugger/dbexec.c (revision 7851:e828bbb1689c)
1 /*******************************************************************************
2  *
3  * Module Name: dbexec - debugger control method execution
4  *              $Revision: 1.83 $
5  *
6  ******************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 
118 #include "acpi.h"
119 #include "acdebug.h"
120 #include "acnamesp.h"
121 
122 #ifdef ACPI_DEBUGGER
123 
124 #define _COMPONENT          ACPI_CA_DEBUGGER
125         ACPI_MODULE_NAME    ("dbexec")
126 
127 
128 static ACPI_DB_METHOD_INFO  AcpiGbl_DbMethodInfo;
129 
130 /* Local prototypes */
131 
132 static ACPI_STATUS
133 AcpiDbExecuteMethod (
134     ACPI_DB_METHOD_INFO     *Info,
135     ACPI_BUFFER             *ReturnObj);
136 
137 static void
138 AcpiDbExecuteSetup (
139     ACPI_DB_METHOD_INFO     *Info);
140 
141 static UINT32
142 AcpiDbGetOutstandingAllocations (
143     void);
144 
145 static void ACPI_SYSTEM_XFACE
146 AcpiDbMethodThread (
147     void                    *Context);
148 
149 static ACPI_STATUS
150 AcpiDbExecutionWalk (
151     ACPI_HANDLE             ObjHandle,
152     UINT32                  NestingLevel,
153     void                    *Context,
154     void                    **ReturnValue);
155 
156 
157 /*******************************************************************************
158  *
159  * FUNCTION:    AcpiDbExecuteMethod
160  *
161  * PARAMETERS:  Info            - Valid info segment
162  *              ReturnObj       - Where to put return object
163  *
164  * RETURN:      Status
165  *
166  * DESCRIPTION: Execute a control method.
167  *
168  ******************************************************************************/
169 
170 static ACPI_STATUS
171 AcpiDbExecuteMethod (
172     ACPI_DB_METHOD_INFO     *Info,
173     ACPI_BUFFER             *ReturnObj)
174 {
175     ACPI_STATUS             Status;
176     ACPI_OBJECT_LIST        ParamObjects;
177     ACPI_OBJECT             Params[ACPI_METHOD_NUM_ARGS];
178     ACPI_HANDLE             Handle;
179     ACPI_BUFFER             Buffer;
180     UINT32                  i;
181     ACPI_DEVICE_INFO        *ObjInfo;
182 
183 
184     if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
185     {
186         AcpiOsPrintf ("Warning: debug output is not enabled!\n");
187     }
188 
189     /* Get the NS node, determines existence also */
190 
191     Status = AcpiGetHandle (NULL, Info->Pathname, &Handle);
192     if (ACPI_FAILURE (Status))
193     {
194         return (Status);
195     }
196 
197     /* Get the object info for number of method parameters */
198 
199     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
200     Status = AcpiGetObjectInfo (Handle, &Buffer);
201     if (ACPI_FAILURE (Status))
202     {
203         return (Status);
204     }
205 
206     ParamObjects.Pointer = NULL;
207     ParamObjects.Count   = 0;
208 
209     ObjInfo = Buffer.Pointer;
210     if (ObjInfo->Type == ACPI_TYPE_METHOD)
211     {
212         /* Are there arguments to the method? */
213 
214         if (Info->Args && Info->Args[0])
215         {
216             for (i = 0; Info->Args[i] && i < ACPI_METHOD_NUM_ARGS; i++)
217             {
218                 Params[i].Type          = ACPI_TYPE_INTEGER;
219                 Params[i].Integer.Value = ACPI_STRTOUL (Info->Args[i], NULL, 16);
220             }
221 
222             ParamObjects.Pointer = Params;
223             ParamObjects.Count   = i;
224         }
225         else
226         {
227             /* Setup default parameters */
228 
229             for (i = 0; i < ObjInfo->ParamCount; i++)
230             {
231                 switch (i)
232                 {
233                 case 0:
234 
235                     Params[0].Type           = ACPI_TYPE_INTEGER;
236                     Params[0].Integer.Value  = 0x01020304;
237                     break;
238 
239                 case 1:
240 
241                     Params[1].Type           = ACPI_TYPE_STRING;
242                     Params[1].String.Length  = 12;
243                     Params[1].String.Pointer = "AML Debugger";
244                     break;
245 
246                 default:
247 
248                     Params[i].Type           = ACPI_TYPE_INTEGER;
249                     Params[i].Integer.Value  = i * (ACPI_INTEGER) 0x1000;
250                     break;
251                 }
252             }
253 
254             ParamObjects.Pointer     = Params;
255             ParamObjects.Count       = ObjInfo->ParamCount;
256         }
257     }
258 
259     ACPI_FREE (Buffer.Pointer);
260 
261     /* Prepare for a return object of arbitrary size */
262 
263     ReturnObj->Pointer = AcpiGbl_DbBuffer;
264     ReturnObj->Length  = ACPI_DEBUG_BUFFER_SIZE;
265 
266     /* Do the actual method execution */
267 
268     AcpiGbl_MethodExecuting = TRUE;
269     Status = AcpiEvaluateObject (NULL,
270                 Info->Pathname, &ParamObjects, ReturnObj);
271 
272     AcpiGbl_CmSingleStep = FALSE;
273     AcpiGbl_MethodExecuting = FALSE;
274 
275     return (Status);
276 }
277 
278 
279 /*******************************************************************************
280  *
281  * FUNCTION:    AcpiDbExecuteSetup
282  *
283  * PARAMETERS:  Info            - Valid method info
284  *
285  * RETURN:      None
286  *
287  * DESCRIPTION: Setup info segment prior to method execution
288  *
289  ******************************************************************************/
290 
291 static void
292 AcpiDbExecuteSetup (
293     ACPI_DB_METHOD_INFO     *Info)
294 {
295 
296     /* Catenate the current scope to the supplied name */
297 
298     Info->Pathname[0] = 0;
299     if ((Info->Name[0] != '\\') &&
300         (Info->Name[0] != '/'))
301     {
302         ACPI_STRCAT (Info->Pathname, AcpiGbl_DbScopeBuf);
303     }
304 
305     ACPI_STRCAT (Info->Pathname, Info->Name);
306     AcpiDbPrepNamestring (Info->Pathname);
307 
308     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
309     AcpiOsPrintf ("Executing %s\n", Info->Pathname);
310 
311     if (Info->Flags & EX_SINGLE_STEP)
312     {
313         AcpiGbl_CmSingleStep = TRUE;
314         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
315     }
316 
317     else
318     {
319         /* No single step, allow redirection to a file */
320 
321         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
322     }
323 }
324 
325 
326 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
327 UINT32
328 AcpiDbGetCacheInfo (
329     ACPI_MEMORY_LIST        *Cache)
330 {
331 
332     return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
333 }
334 #endif
335 
336 /*******************************************************************************
337  *
338  * FUNCTION:    AcpiDbGetOutstandingAllocations
339  *
340  * PARAMETERS:  None
341  *
342  * RETURN:      Current global allocation count minus cache entries
343  *
344  * DESCRIPTION: Determine the current number of "outstanding" allocations --
345  *              those allocations that have not been freed and also are not
346  *              in one of the various object caches.
347  *
348  ******************************************************************************/
349 
350 static UINT32
351 AcpiDbGetOutstandingAllocations (
352     void)
353 {
354     UINT32                  Outstanding = 0;
355 
356 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
357 
358     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
359     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
360     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
361     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
362 #endif
363 
364     return (Outstanding);
365 }
366 
367 
368 /*******************************************************************************
369  *
370  * FUNCTION:    AcpiDbExecutionWalk
371  *
372  * PARAMETERS:  WALK_CALLBACK
373  *
374  * RETURN:      Status
375  *
376  * DESCRIPTION: Execute a control method.  Name is relative to the current
377  *              scope.
378  *
379  ******************************************************************************/
380 
381 static ACPI_STATUS
382 AcpiDbExecutionWalk (
383     ACPI_HANDLE             ObjHandle,
384     UINT32                  NestingLevel,
385     void                    *Context,
386     void                    **ReturnValue)
387 {
388     ACPI_OPERAND_OBJECT     *ObjDesc;
389     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
390     ACPI_BUFFER             ReturnObj;
391     ACPI_STATUS             Status;
392 
393 
394     ObjDesc = AcpiNsGetAttachedObject (Node);
395     if (ObjDesc->Method.ParamCount)
396     {
397         return (AE_OK);
398     }
399 
400     ReturnObj.Pointer = NULL;
401     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
402 
403     AcpiNsPrintNodePathname (Node, "Execute");
404 
405     /* Do the actual method execution */
406 
407     AcpiOsPrintf ("\n");
408     AcpiGbl_MethodExecuting = TRUE;
409 
410     Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
411 
412     AcpiOsPrintf ("[%4.4s] returned %s\n", AcpiUtGetNodeName (Node),
413             AcpiFormatException (Status));
414     AcpiGbl_MethodExecuting = FALSE;
415 
416     return (AE_OK);
417 }
418 
419 
420 /*******************************************************************************
421  *
422  * FUNCTION:    AcpiDbExecute
423  *
424  * PARAMETERS:  Name                - Name of method to execute
425  *              Args                - Parameters to the method
426  *              Flags               - single step/no single step
427  *
428  * RETURN:      None
429  *
430  * DESCRIPTION: Execute a control method.  Name is relative to the current
431  *              scope.
432  *
433  ******************************************************************************/
434 
435 void
436 AcpiDbExecute (
437     char                    *Name,
438     char                    **Args,
439     UINT32                  Flags)
440 {
441     ACPI_STATUS             Status;
442     ACPI_BUFFER             ReturnObj;
443     char                    *NameString;
444 
445 
446 #ifdef ACPI_DEBUG_OUTPUT
447     UINT32                  PreviousAllocations;
448     UINT32                  Allocations;
449 
450 
451     /* Memory allocation tracking */
452 
453     PreviousAllocations = AcpiDbGetOutstandingAllocations ();
454 #endif
455 
456     if (*Name == '*')
457     {
458         (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
459                     ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL);
460         return;
461     }
462     else
463     {
464         NameString = ACPI_ALLOCATE (ACPI_STRLEN (Name) + 1);
465         if (!NameString)
466         {
467             return;
468         }
469 
470         ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
471 
472         ACPI_STRCPY (NameString, Name);
473         AcpiUtStrupr (NameString);
474         AcpiGbl_DbMethodInfo.Name = NameString;
475         AcpiGbl_DbMethodInfo.Args = Args;
476         AcpiGbl_DbMethodInfo.Flags = Flags;
477 
478         ReturnObj.Pointer = NULL;
479         ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
480 
481         AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
482         Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj);
483         ACPI_FREE (NameString);
484     }
485 
486     /*
487      * Allow any handlers in separate threads to complete.
488      * (Such as Notify handlers invoked from AML executed above).
489      */
490     AcpiOsSleep ((ACPI_INTEGER) 10);
491 
492 
493 #ifdef ACPI_DEBUG_OUTPUT
494 
495     /* Memory allocation tracking */
496 
497     Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
498 
499     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
500 
501     if (Allocations > 0)
502     {
503         AcpiOsPrintf ("Outstanding: 0x%X allocations after execution\n",
504                         Allocations);
505     }
506 #endif
507 
508     if (ACPI_FAILURE (Status))
509     {
510         AcpiOsPrintf ("Execution of %s failed with status %s\n",
511             AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status));
512     }
513     else
514     {
515         /* Display a return object, if any */
516 
517         if (ReturnObj.Length)
518         {
519             AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
520                 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
521                 (UINT32) ReturnObj.Length);
522             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
523         }
524         else
525         {
526             AcpiOsPrintf ("No return object from execution of %s\n",
527                 AcpiGbl_DbMethodInfo.Pathname);
528         }
529     }
530 
531     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
532 }
533 
534 
535 /*******************************************************************************
536  *
537  * FUNCTION:    AcpiDbMethodThread
538  *
539  * PARAMETERS:  Context             - Execution info segment
540  *
541  * RETURN:      None
542  *
543  * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
544  *              simply dispatches it.
545  *
546  ******************************************************************************/
547 
548 static void ACPI_SYSTEM_XFACE
549 AcpiDbMethodThread (
550     void                    *Context)
551 {
552     ACPI_STATUS             Status;
553     ACPI_DB_METHOD_INFO     *Info = Context;
554     UINT32                  i;
555     UINT8                   Allow;
556     ACPI_BUFFER             ReturnObj;
557 
558 
559     if (Info->InitArgs)
560     {
561         AcpiDbUInt32ToHexString (Info->NumCreated, Info->IndexOfThreadStr);
562         AcpiDbUInt32ToHexString ((UINT32) AcpiOsGetThreadId (), Info->IdOfThreadStr);
563     }
564 
565     if (Info->Threads && (Info->NumCreated < Info->NumThreads))
566     {
567         Info->Threads[Info->NumCreated++] = (UINT32) AcpiOsGetThreadId();
568     }
569 
570     for (i = 0; i < Info->NumLoops; i++)
571     {
572         Status = AcpiDbExecuteMethod (Info, &ReturnObj);
573         if (ACPI_FAILURE (Status))
574         {
575             AcpiOsPrintf ("%s During execution of %s at iteration %X\n",
576                 AcpiFormatException (Status), Info->Pathname, i);
577             if (Status == AE_ABORT_METHOD)
578             {
579                 break;
580             }
581         }
582 
583 #if 0
584         if ((i % 100) == 0)
585         {
586             AcpiOsPrintf ("%d executions, Thread 0x%x\n", i, AcpiOsGetThreadId ());
587         }
588 
589         if (ReturnObj.Length)
590         {
591             AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
592                 Info->Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length);
593             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
594         }
595 #endif
596     }
597 
598     /* Signal our completion */
599 
600     Allow = 0;
601     (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate, 1, ACPI_WAIT_FOREVER);
602     Info->NumCompleted++;
603 
604     if (Info->NumCompleted == Info->NumThreads)
605     {
606         /* Do signal for main thread once only */
607         Allow = 1;
608     }
609 
610     (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
611 
612     if (Allow)
613     {
614         Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
615         if (ACPI_FAILURE (Status))
616         {
617             AcpiOsPrintf ("Could not signal debugger thread sync semaphore, %s\n",
618                 AcpiFormatException (Status));
619         }
620     }
621 }
622 
623 
624 /*******************************************************************************
625  *
626  * FUNCTION:    AcpiDbCreateExecutionThreads
627  *
628  * PARAMETERS:  NumThreadsArg           - Number of threads to create
629  *              NumLoopsArg             - Loop count for the thread(s)
630  *              MethodNameArg           - Control method to execute
631  *
632  * RETURN:      None
633  *
634  * DESCRIPTION: Create threads to execute method(s)
635  *
636  ******************************************************************************/
637 
638 void
639 AcpiDbCreateExecutionThreads (
640     char                    *NumThreadsArg,
641     char                    *NumLoopsArg,
642     char                    *MethodNameArg)
643 {
644     ACPI_STATUS             Status;
645     UINT32                  NumThreads;
646     UINT32                  NumLoops;
647     UINT32                  i;
648     UINT32                  Size;
649     ACPI_MUTEX              MainThreadGate;
650     ACPI_MUTEX              ThreadCompleteGate;
651 
652     /* Get the arguments */
653 
654     NumThreads = ACPI_STRTOUL (NumThreadsArg, NULL, 0);
655     NumLoops   = ACPI_STRTOUL (NumLoopsArg, NULL, 0);
656 
657     if (!NumThreads || !NumLoops)
658     {
659         AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
660             NumThreads, NumLoops);
661         return;
662     }
663 
664     /*
665      * Create the semaphore for synchronization of
666      * the created threads with the main thread.
667      */
668     Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
669     if (ACPI_FAILURE (Status))
670     {
671         AcpiOsPrintf ("Could not create semaphore for synchronization with the main thread, %s\n",
672             AcpiFormatException (Status));
673         return;
674     }
675 
676     /*
677      * Create the semaphore for synchronization
678      * between the created threads.
679      */
680     Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
681     if (ACPI_FAILURE (Status))
682     {
683         AcpiOsPrintf ("Could not create semaphore for synchronization between the created threads, %s\n",
684             AcpiFormatException (Status));
685         (void) AcpiOsDeleteSemaphore (MainThreadGate);
686         return;
687     }
688 
689     ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
690 
691     /* Array to store IDs of threads */
692 
693     AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
694     Size = 4 * AcpiGbl_DbMethodInfo.NumThreads;
695     AcpiGbl_DbMethodInfo.Threads = (UINT32 *) AcpiOsAllocate (Size);
696     if (AcpiGbl_DbMethodInfo.Threads == NULL)
697     {
698         AcpiOsPrintf ("No memory for thread IDs array\n");
699         (void) AcpiOsDeleteSemaphore (MainThreadGate);
700         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
701         return;
702     }
703     ACPI_MEMSET (AcpiGbl_DbMethodInfo.Threads, 0, Size);
704 
705     /* Setup the context to be passed to each thread */
706 
707     AcpiGbl_DbMethodInfo.Name = MethodNameArg;
708     AcpiGbl_DbMethodInfo.Flags = 0;
709     AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
710     AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
711     AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
712 
713     /* Init arguments to be passed to method */
714 
715     AcpiGbl_DbMethodInfo.InitArgs = 1;
716     AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
717     AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
718     AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
719     AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
720     AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
721     AcpiDbUInt32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
722 
723     AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
724 
725     /* Create the threads */
726 
727     AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
728         NumThreads, NumLoops);
729 
730     for (i = 0; i < (NumThreads); i++)
731     {
732         Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbMethodThread,
733             &AcpiGbl_DbMethodInfo);
734         if (ACPI_FAILURE (Status))
735         {
736             break;
737         }
738     }
739 
740     /* Wait for all threads to complete */
741 
742     (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
743 
744     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
745     AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
746     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
747 
748     /* Cleanup and exit */
749 
750     (void) AcpiOsDeleteSemaphore (MainThreadGate);
751     (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
752 
753     AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
754     AcpiGbl_DbMethodInfo.Threads = NULL;
755 }
756 
757 #endif /* ACPI_DEBUGGER */
758 
759 
760