1 /*******************************************************************************
3 * Module Name: dbexec - debugger control method execution
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
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>
52 #define _COMPONENT ACPI_CA_DEBUGGER
53 ACPI_MODULE_NAME ("dbexec")
56 static ACPI_DB_METHOD_INFO AcpiGbl_DbMethodInfo;
57 #define DB_DEFAULT_PKG_ELEMENTS 33
59 /* Local prototypes */
63 ACPI_DB_METHOD_INFO *Info,
64 ACPI_BUFFER *ReturnObj);
68 ACPI_DB_METHOD_INFO *Info);
71 AcpiDbGetOutstandingAllocations (
74 static void ACPI_SYSTEM_XFACE
80 ACPI_HANDLE ObjHandle,
86 AcpiDbHexCharToValue (
91 AcpiDbConvertToPackage (
96 AcpiDbConvertToObject (
97 ACPI_OBJECT_TYPE Type,
102 AcpiDbDeleteObjects (
104 ACPI_OBJECT *Objects);
107 /*******************************************************************************
109 * FUNCTION: AcpiDbHexCharToValue
111 * PARAMETERS: HexChar - Ascii Hex digit, 0-9|a-f|A-F
112 * ReturnValue - Where the converted value is returned
116 * DESCRIPTION: Convert a single hex character to a 4-bit number (0-16).
118 ******************************************************************************/
121 AcpiDbHexCharToValue (
128 /* Digit must be ascii [0-9a-fA-F] */
130 if (!ACPI_IS_XDIGIT (HexChar))
132 return (AE_BAD_HEX_CONSTANT);
137 Value = (UINT8) (HexChar - 0x30);
141 Value = (UINT8) (ACPI_TOUPPER (HexChar) - 0x37);
144 *ReturnValue = Value;
149 /*******************************************************************************
151 * FUNCTION: AcpiDbHexByteToBinary
153 * PARAMETERS: HexByte - Double hex digit (0x00 - 0xFF) in format:
154 * HiByte then LoByte.
155 * ReturnValue - Where the converted value is returned
159 * DESCRIPTION: Convert two hex characters to an 8 bit number (0 - 255).
161 ******************************************************************************/
164 AcpiDbHexByteToBinary (
175 Status = AcpiDbHexCharToValue (HexByte[0], &Local0);
176 if (ACPI_FAILURE (Status))
183 Status = AcpiDbHexCharToValue (HexByte[1], &Local1);
184 if (ACPI_FAILURE (Status))
189 *ReturnValue = (UINT8) ((Local0 << 4) | Local1);
194 /*******************************************************************************
196 * FUNCTION: AcpiDbConvertToBuffer
198 * PARAMETERS: String - Input string to be converted
199 * Object - Where the buffer object is returned
203 * DESCRIPTION: Convert a string to a buffer object. String is treated a list
204 * of buffer elements, each separated by a space or comma.
206 ******************************************************************************/
209 AcpiDbConvertToBuffer (
220 /* Generate the final buffer length */
222 for (i = 0, Length = 0; String[i];)
228 ((String[i] == ',') || (String[i] == ' ')))
234 Buffer = ACPI_ALLOCATE (Length);
237 return (AE_NO_MEMORY);
240 /* Convert the command line bytes to the buffer */
242 for (i = 0, j = 0; String[i];)
244 Status = AcpiDbHexByteToBinary (&String[i], &Buffer[j]);
245 if (ACPI_FAILURE (Status))
254 ((String[i] == ',') || (String[i] == ' ')))
260 Object->Type = ACPI_TYPE_BUFFER;
261 Object->Buffer.Pointer = Buffer;
262 Object->Buffer.Length = Length;
267 /*******************************************************************************
269 * FUNCTION: AcpiDbConvertToPackage
271 * PARAMETERS: String - Input string to be converted
272 * Object - Where the package object is returned
276 * DESCRIPTION: Convert a string to a package object. Handles nested packages
277 * via recursion with AcpiDbConvertToObject.
279 ******************************************************************************/
282 AcpiDbConvertToPackage (
289 ACPI_OBJECT_TYPE Type;
290 ACPI_OBJECT *Elements;
294 Elements = ACPI_ALLOCATE_ZEROED (
295 DB_DEFAULT_PKG_ELEMENTS * sizeof (ACPI_OBJECT));
298 for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++)
300 This = AcpiDbGetNextToken (This, &Next, &Type);
306 /* Recursive call to convert each package element */
308 Status = AcpiDbConvertToObject (Type, This, &Elements[i]);
309 if (ACPI_FAILURE (Status))
311 AcpiDbDeleteObjects (i + 1, Elements);
312 ACPI_FREE (Elements);
319 Object->Type = ACPI_TYPE_PACKAGE;
320 Object->Package.Count = i;
321 Object->Package.Elements = Elements;
326 /*******************************************************************************
328 * FUNCTION: AcpiDbConvertToObject
330 * PARAMETERS: Type - Object type as determined by parser
331 * String - Input string to be converted
332 * Object - Where the new object is returned
336 * DESCRIPTION: Convert a typed and tokenized string to an ACPI_OBJECT. Typing:
337 * 1) String objects were surrounded by quotes.
338 * 2) Buffer objects were surrounded by parentheses.
339 * 3) Package objects were surrounded by brackets "[]".
340 * 4) All standalone tokens are treated as integers.
342 ******************************************************************************/
345 AcpiDbConvertToObject (
346 ACPI_OBJECT_TYPE Type,
350 ACPI_STATUS Status = AE_OK;
355 case ACPI_TYPE_STRING:
356 Object->Type = ACPI_TYPE_STRING;
357 Object->String.Pointer = String;
358 Object->String.Length = (UINT32) ACPI_STRLEN (String);
361 case ACPI_TYPE_BUFFER:
362 Status = AcpiDbConvertToBuffer (String, Object);
365 case ACPI_TYPE_PACKAGE:
366 Status = AcpiDbConvertToPackage (String, Object);
370 Object->Type = ACPI_TYPE_INTEGER;
371 Status = AcpiUtStrtoul64 (String, 16, &Object->Integer.Value);
379 /*******************************************************************************
381 * FUNCTION: AcpiDbDeleteObjects
383 * PARAMETERS: Count - Count of objects in the list
384 * Objects - Array of ACPI_OBJECTs to be deleted
388 * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
389 * packages via recursion.
391 ******************************************************************************/
394 AcpiDbDeleteObjects (
396 ACPI_OBJECT *Objects)
401 for (i = 0; i < Count; i++)
403 switch (Objects[i].Type)
405 case ACPI_TYPE_BUFFER:
406 ACPI_FREE (Objects[i].Buffer.Pointer);
409 case ACPI_TYPE_PACKAGE:
411 /* Recursive call to delete package elements */
413 AcpiDbDeleteObjects (Objects[i].Package.Count,
414 Objects[i].Package.Elements);
416 /* Free the elements array */
418 ACPI_FREE (Objects[i].Package.Elements);
428 /*******************************************************************************
430 * FUNCTION: AcpiDbExecuteMethod
432 * PARAMETERS: Info - Valid info segment
433 * ReturnObj - Where to put return object
437 * DESCRIPTION: Execute a control method.
439 ******************************************************************************/
442 AcpiDbExecuteMethod (
443 ACPI_DB_METHOD_INFO *Info,
444 ACPI_BUFFER *ReturnObj)
447 ACPI_OBJECT_LIST ParamObjects;
448 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
450 ACPI_DEVICE_INFO *ObjInfo;
454 ACPI_FUNCTION_TRACE (DbExecuteMethod);
457 if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
459 AcpiOsPrintf ("Warning: debug output is not enabled!\n");
462 /* Get the NS node, determines existence also */
464 Status = AcpiGetHandle (NULL, Info->Pathname, &Handle);
465 if (ACPI_FAILURE (Status))
467 return_ACPI_STATUS (Status);
470 /* Get the object info for number of method parameters */
472 Status = AcpiGetObjectInfo (Handle, &ObjInfo);
473 if (ACPI_FAILURE (Status))
475 return_ACPI_STATUS (Status);
478 ParamObjects.Pointer = NULL;
479 ParamObjects.Count = 0;
481 if (ObjInfo->Type == ACPI_TYPE_METHOD)
483 /* Are there arguments to the method? */
486 if (Info->Args && Info->Args[0])
488 /* Get arguments passed on the command line */
490 for (; Info->Args[i] &&
491 (i < ACPI_METHOD_NUM_ARGS) &&
492 (i < ObjInfo->ParamCount);
495 /* Convert input string (token) to an actual ACPI_OBJECT */
497 Status = AcpiDbConvertToObject (Info->Types[i],
498 Info->Args[i], &Params[i]);
499 if (ACPI_FAILURE (Status))
501 ACPI_EXCEPTION ((AE_INFO, Status,
502 "While parsing method arguments"));
508 /* Create additional "default" parameters as needed */
510 if (i < ObjInfo->ParamCount)
512 AcpiOsPrintf ("Adding %u arguments containing default values\n",
513 ObjInfo->ParamCount - i);
515 for (; i < ObjInfo->ParamCount; i++)
521 Params[0].Type = ACPI_TYPE_INTEGER;
522 Params[0].Integer.Value = 0x01020304;
527 Params[1].Type = ACPI_TYPE_STRING;
528 Params[1].String.Length = 12;
529 Params[1].String.Pointer = "AML Debugger";
534 Params[i].Type = ACPI_TYPE_INTEGER;
535 Params[i].Integer.Value = i * (UINT64) 0x1000;
541 ParamObjects.Count = ObjInfo->ParamCount;
542 ParamObjects.Pointer = Params;
545 /* Prepare for a return object of arbitrary size */
547 ReturnObj->Pointer = AcpiGbl_DbBuffer;
548 ReturnObj->Length = ACPI_DEBUG_BUFFER_SIZE;
550 /* Do the actual method execution */
552 AcpiGbl_MethodExecuting = TRUE;
553 Status = AcpiEvaluateObject (NULL,
554 Info->Pathname, &ParamObjects, ReturnObj);
556 AcpiGbl_CmSingleStep = FALSE;
557 AcpiGbl_MethodExecuting = FALSE;
559 if (ACPI_FAILURE (Status))
561 ACPI_EXCEPTION ((AE_INFO, Status,
562 "while executing %s from debugger", Info->Pathname));
564 if (Status == AE_BUFFER_OVERFLOW)
566 ACPI_ERROR ((AE_INFO,
567 "Possible overflow of internal debugger buffer (size 0x%X needed 0x%X)",
568 ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length));
573 AcpiDbDeleteObjects (ObjInfo->ParamCount, Params);
576 return_ACPI_STATUS (Status);
580 /*******************************************************************************
582 * FUNCTION: AcpiDbExecuteSetup
584 * PARAMETERS: Info - Valid method info
588 * DESCRIPTION: Setup info segment prior to method execution
590 ******************************************************************************/
594 ACPI_DB_METHOD_INFO *Info)
597 /* Catenate the current scope to the supplied name */
599 Info->Pathname[0] = 0;
600 if ((Info->Name[0] != '\\') &&
601 (Info->Name[0] != '/'))
603 ACPI_STRCAT (Info->Pathname, AcpiGbl_DbScopeBuf);
606 ACPI_STRCAT (Info->Pathname, Info->Name);
607 AcpiDbPrepNamestring (Info->Pathname);
609 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
610 AcpiOsPrintf ("Executing %s\n", Info->Pathname);
612 if (Info->Flags & EX_SINGLE_STEP)
614 AcpiGbl_CmSingleStep = TRUE;
615 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
620 /* No single step, allow redirection to a file */
622 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
627 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
630 ACPI_MEMORY_LIST *Cache)
633 return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
637 /*******************************************************************************
639 * FUNCTION: AcpiDbGetOutstandingAllocations
643 * RETURN: Current global allocation count minus cache entries
645 * DESCRIPTION: Determine the current number of "outstanding" allocations --
646 * those allocations that have not been freed and also are not
647 * in one of the various object caches.
649 ******************************************************************************/
652 AcpiDbGetOutstandingAllocations (
655 UINT32 Outstanding = 0;
657 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
659 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
660 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
661 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
662 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
665 return (Outstanding);
669 /*******************************************************************************
671 * FUNCTION: AcpiDbExecutionWalk
673 * PARAMETERS: WALK_CALLBACK
677 * DESCRIPTION: Execute a control method. Name is relative to the current
680 ******************************************************************************/
683 AcpiDbExecutionWalk (
684 ACPI_HANDLE ObjHandle,
689 ACPI_OPERAND_OBJECT *ObjDesc;
690 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
691 ACPI_BUFFER ReturnObj;
695 ObjDesc = AcpiNsGetAttachedObject (Node);
696 if (ObjDesc->Method.ParamCount)
701 ReturnObj.Pointer = NULL;
702 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
704 AcpiNsPrintNodePathname (Node, "Execute");
706 /* Do the actual method execution */
709 AcpiGbl_MethodExecuting = TRUE;
711 Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
713 AcpiOsPrintf ("[%4.4s] returned %s\n", AcpiUtGetNodeName (Node),
714 AcpiFormatException (Status));
715 AcpiGbl_MethodExecuting = FALSE;
721 /*******************************************************************************
723 * FUNCTION: AcpiDbExecute
725 * PARAMETERS: Name - Name of method to execute
726 * Args - Parameters to the method
727 * Flags - single step/no single step
731 * DESCRIPTION: Execute a control method. Name is relative to the current
734 ******************************************************************************/
740 ACPI_OBJECT_TYPE *Types,
744 ACPI_BUFFER ReturnObj;
748 #ifdef ACPI_DEBUG_OUTPUT
749 UINT32 PreviousAllocations;
753 /* Memory allocation tracking */
755 PreviousAllocations = AcpiDbGetOutstandingAllocations ();
760 (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
761 ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
766 NameString = ACPI_ALLOCATE (ACPI_STRLEN (Name) + 1);
772 ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
774 ACPI_STRCPY (NameString, Name);
775 AcpiUtStrupr (NameString);
776 AcpiGbl_DbMethodInfo.Name = NameString;
777 AcpiGbl_DbMethodInfo.Args = Args;
778 AcpiGbl_DbMethodInfo.Types = Types;
779 AcpiGbl_DbMethodInfo.Flags = Flags;
781 ReturnObj.Pointer = NULL;
782 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
784 AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
785 Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj);
786 ACPI_FREE (NameString);
790 * Allow any handlers in separate threads to complete.
791 * (Such as Notify handlers invoked from AML executed above).
793 AcpiOsSleep ((UINT64) 10);
796 #ifdef ACPI_DEBUG_OUTPUT
798 /* Memory allocation tracking */
800 Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
802 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
806 AcpiOsPrintf ("Outstanding: 0x%X allocations after execution\n",
811 if (ACPI_FAILURE (Status))
813 AcpiOsPrintf ("Execution of %s failed with status %s\n",
814 AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status));
818 /* Display a return object, if any */
820 if (ReturnObj.Length)
822 AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
823 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
824 (UINT32) ReturnObj.Length);
825 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
829 AcpiOsPrintf ("No return object from execution of %s\n",
830 AcpiGbl_DbMethodInfo.Pathname);
834 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
838 /*******************************************************************************
840 * FUNCTION: AcpiDbMethodThread
842 * PARAMETERS: Context - Execution info segment
846 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
847 * simply dispatches it.
849 ******************************************************************************/
851 static void ACPI_SYSTEM_XFACE
856 ACPI_DB_METHOD_INFO *Info = Context;
857 ACPI_DB_METHOD_INFO LocalInfo;
860 ACPI_BUFFER ReturnObj;
864 * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
865 * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
868 * Note: The arguments we are passing are used by the ASL test suite
869 * (aslts). Do not change them without updating the tests.
871 (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
875 AcpiDbUInt32ToHexString (Info->NumCreated, Info->IndexOfThreadStr);
876 AcpiDbUInt32ToHexString ((UINT32) AcpiOsGetThreadId (), Info->IdOfThreadStr);
879 if (Info->Threads && (Info->NumCreated < Info->NumThreads))
881 Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
885 LocalInfo.Args = LocalInfo.Arguments;
886 LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
887 LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
888 LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
889 LocalInfo.Arguments[3] = NULL;
891 LocalInfo.Types = LocalInfo.ArgTypes;
893 (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
895 for (i = 0; i < Info->NumLoops; i++)
897 Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
898 if (ACPI_FAILURE (Status))
900 AcpiOsPrintf ("%s During execution of %s at iteration %X\n",
901 AcpiFormatException (Status), Info->Pathname, i);
902 if (Status == AE_ABORT_METHOD)
911 AcpiOsPrintf ("%u executions, Thread 0x%x\n", i, AcpiOsGetThreadId ());
914 if (ReturnObj.Length)
916 AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
917 Info->Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length);
918 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
923 /* Signal our completion */
926 (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate, 1, ACPI_WAIT_FOREVER);
927 Info->NumCompleted++;
929 if (Info->NumCompleted == Info->NumThreads)
931 /* Do signal for main thread once only */
935 (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
939 Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
940 if (ACPI_FAILURE (Status))
942 AcpiOsPrintf ("Could not signal debugger thread sync semaphore, %s\n",
943 AcpiFormatException (Status));
949 /*******************************************************************************
951 * FUNCTION: AcpiDbCreateExecutionThreads
953 * PARAMETERS: NumThreadsArg - Number of threads to create
954 * NumLoopsArg - Loop count for the thread(s)
955 * MethodNameArg - Control method to execute
959 * DESCRIPTION: Create threads to execute method(s)
961 ******************************************************************************/
964 AcpiDbCreateExecutionThreads (
974 ACPI_MUTEX MainThreadGate;
975 ACPI_MUTEX ThreadCompleteGate;
979 /* Get the arguments */
981 NumThreads = ACPI_STRTOUL (NumThreadsArg, NULL, 0);
982 NumLoops = ACPI_STRTOUL (NumLoopsArg, NULL, 0);
984 if (!NumThreads || !NumLoops)
986 AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
987 NumThreads, NumLoops);
992 * Create the semaphore for synchronization of
993 * the created threads with the main thread.
995 Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
996 if (ACPI_FAILURE (Status))
998 AcpiOsPrintf ("Could not create semaphore for synchronization with the main thread, %s\n",
999 AcpiFormatException (Status));
1004 * Create the semaphore for synchronization
1005 * between the created threads.
1007 Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
1008 if (ACPI_FAILURE (Status))
1010 AcpiOsPrintf ("Could not create semaphore for synchronization between the created threads, %s\n",
1011 AcpiFormatException (Status));
1012 (void) AcpiOsDeleteSemaphore (MainThreadGate);
1016 Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
1017 if (ACPI_FAILURE (Status))
1019 AcpiOsPrintf ("Could not create semaphore for synchronization of AcpiGbl_DbMethodInfo, %s\n",
1020 AcpiFormatException (Status));
1021 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
1022 (void) AcpiOsDeleteSemaphore (MainThreadGate);
1026 ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
1028 /* Array to store IDs of threads */
1030 AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
1031 Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
1032 AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
1033 if (AcpiGbl_DbMethodInfo.Threads == NULL)
1035 AcpiOsPrintf ("No memory for thread IDs array\n");
1036 (void) AcpiOsDeleteSemaphore (MainThreadGate);
1037 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
1038 (void) AcpiOsDeleteSemaphore (InfoGate);
1041 ACPI_MEMSET (AcpiGbl_DbMethodInfo.Threads, 0, Size);
1043 /* Setup the context to be passed to each thread */
1045 AcpiGbl_DbMethodInfo.Name = MethodNameArg;
1046 AcpiGbl_DbMethodInfo.Flags = 0;
1047 AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
1048 AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
1049 AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
1050 AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
1052 /* Init arguments to be passed to method */
1054 AcpiGbl_DbMethodInfo.InitArgs = 1;
1055 AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
1056 AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
1057 AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
1058 AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
1059 AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
1061 AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
1062 AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
1063 AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
1064 AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
1066 AcpiDbUInt32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
1068 AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
1070 /* Create the threads */
1072 AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
1073 NumThreads, NumLoops);
1075 for (i = 0; i < (NumThreads); i++)
1077 Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbMethodThread,
1078 &AcpiGbl_DbMethodInfo);
1079 if (ACPI_FAILURE (Status))
1085 /* Wait for all threads to complete */
1087 (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
1089 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
1090 AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
1091 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1093 /* Cleanup and exit */
1095 (void) AcpiOsDeleteSemaphore (MainThreadGate);
1096 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
1097 (void) AcpiOsDeleteSemaphore (InfoGate);
1099 AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
1100 AcpiGbl_DbMethodInfo.Threads = NULL;
1103 #endif /* ACPI_DEBUGGER */