1 /*******************************************************************************
3 * Module Name: dbexec - debugger control method execution
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acdebug.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
158 #define _COMPONENT ACPI_CA_DEBUGGER
159 ACPI_MODULE_NAME ("dbexec")
162 static ACPI_DB_METHOD_INFO AcpiGbl_DbMethodInfo;
164 /* Local prototypes */
167 AcpiDbExecuteMethod (
168 ACPI_DB_METHOD_INFO *Info,
169 ACPI_BUFFER *ReturnObj);
173 ACPI_DB_METHOD_INFO *Info);
176 AcpiDbGetOutstandingAllocations (
179 static void ACPI_SYSTEM_XFACE
184 AcpiDbExecutionWalk (
185 ACPI_HANDLE ObjHandle,
190 static void ACPI_SYSTEM_XFACE
191 AcpiDbSingleExecutionThread (
195 /*******************************************************************************
197 * FUNCTION: AcpiDbDeleteObjects
199 * PARAMETERS: Count - Count of objects in the list
200 * Objects - Array of ACPI_OBJECTs to be deleted
204 * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
205 * packages via recursion.
207 ******************************************************************************/
210 AcpiDbDeleteObjects (
212 ACPI_OBJECT *Objects)
217 for (i = 0; i < Count; i++)
219 switch (Objects[i].Type)
221 case ACPI_TYPE_BUFFER:
223 ACPI_FREE (Objects[i].Buffer.Pointer);
226 case ACPI_TYPE_PACKAGE:
228 /* Recursive call to delete package elements */
230 AcpiDbDeleteObjects (Objects[i].Package.Count,
231 Objects[i].Package.Elements);
233 /* Free the elements array */
235 ACPI_FREE (Objects[i].Package.Elements);
246 /*******************************************************************************
248 * FUNCTION: AcpiDbExecuteMethod
250 * PARAMETERS: Info - Valid info segment
251 * ReturnObj - Where to put return object
255 * DESCRIPTION: Execute a control method.
257 ******************************************************************************/
260 AcpiDbExecuteMethod (
261 ACPI_DB_METHOD_INFO *Info,
262 ACPI_BUFFER *ReturnObj)
265 ACPI_OBJECT_LIST ParamObjects;
266 ACPI_OBJECT Params[ACPI_DEBUGGER_MAX_ARGS + 1];
270 ACPI_FUNCTION_TRACE (DbExecuteMethod);
273 if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
275 AcpiOsPrintf ("Warning: debug output is not enabled!\n");
278 ParamObjects.Count = 0;
279 ParamObjects.Pointer = NULL;
281 /* Pass through any command-line arguments */
283 if (Info->Args && Info->Args[0])
285 /* Get arguments passed on the command line */
287 for (i = 0; (Info->Args[i] && *(Info->Args[i])); i++)
289 /* Convert input string (token) to an actual ACPI_OBJECT */
291 Status = AcpiDbConvertToObject (Info->Types[i],
292 Info->Args[i], &Params[i]);
293 if (ACPI_FAILURE (Status))
295 ACPI_EXCEPTION ((AE_INFO, Status,
296 "While parsing method arguments"));
301 ParamObjects.Count = i;
302 ParamObjects.Pointer = Params;
305 /* Prepare for a return object of arbitrary size */
307 ReturnObj->Pointer = AcpiGbl_DbBuffer;
308 ReturnObj->Length = ACPI_DEBUG_BUFFER_SIZE;
310 /* Do the actual method execution */
312 AcpiGbl_MethodExecuting = TRUE;
313 Status = AcpiEvaluateObject (NULL, Info->Pathname,
314 &ParamObjects, ReturnObj);
316 AcpiGbl_CmSingleStep = FALSE;
317 AcpiGbl_MethodExecuting = FALSE;
319 if (ACPI_FAILURE (Status))
321 if ((Status == AE_ABORT_METHOD) || AcpiGbl_AbortMethod)
323 /* Clear the abort and fall back to the debugger prompt */
325 ACPI_EXCEPTION ((AE_INFO, Status,
326 "Aborting top-level method"));
328 AcpiGbl_AbortMethod = FALSE;
333 ACPI_EXCEPTION ((AE_INFO, Status,
334 "while executing %s from AML Debugger", Info->Pathname));
336 if (Status == AE_BUFFER_OVERFLOW)
338 ACPI_ERROR ((AE_INFO,
339 "Possible buffer overflow within AML Debugger "
340 "buffer (size 0x%X needed 0x%X)",
341 ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length));
346 AcpiDbDeleteObjects (ParamObjects.Count, Params);
347 return_ACPI_STATUS (Status);
351 /*******************************************************************************
353 * FUNCTION: AcpiDbExecuteSetup
355 * PARAMETERS: Info - Valid method info
359 * DESCRIPTION: Setup info segment prior to method execution
361 ******************************************************************************/
365 ACPI_DB_METHOD_INFO *Info)
370 ACPI_FUNCTION_NAME (DbExecuteSetup);
373 /* Concatenate the current scope to the supplied name */
375 Info->Pathname[0] = 0;
376 if ((Info->Name[0] != '\\') &&
377 (Info->Name[0] != '/'))
379 if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
382 Status = AE_BUFFER_OVERFLOW;
387 if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
390 Status = AE_BUFFER_OVERFLOW;
394 AcpiDbPrepNamestring (Info->Pathname);
396 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
397 AcpiOsPrintf ("Evaluating %s\n", Info->Pathname);
399 if (Info->Flags & EX_SINGLE_STEP)
401 AcpiGbl_CmSingleStep = TRUE;
402 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
407 /* No single step, allow redirection to a file */
409 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
416 ACPI_EXCEPTION ((AE_INFO, Status, "During setup for method execution"));
421 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
424 ACPI_MEMORY_LIST *Cache)
427 return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
431 /*******************************************************************************
433 * FUNCTION: AcpiDbGetOutstandingAllocations
437 * RETURN: Current global allocation count minus cache entries
439 * DESCRIPTION: Determine the current number of "outstanding" allocations --
440 * those allocations that have not been freed and also are not
441 * in one of the various object caches.
443 ******************************************************************************/
446 AcpiDbGetOutstandingAllocations (
449 UINT32 Outstanding = 0;
451 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
453 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
454 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
455 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
456 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
459 return (Outstanding);
463 /*******************************************************************************
465 * FUNCTION: AcpiDbExecutionWalk
467 * PARAMETERS: WALK_CALLBACK
471 * DESCRIPTION: Execute a control method. Name is relative to the current
474 ******************************************************************************/
477 AcpiDbExecutionWalk (
478 ACPI_HANDLE ObjHandle,
483 ACPI_OPERAND_OBJECT *ObjDesc;
484 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
485 ACPI_BUFFER ReturnObj;
489 ObjDesc = AcpiNsGetAttachedObject (Node);
490 if (ObjDesc->Method.ParamCount)
495 ReturnObj.Pointer = NULL;
496 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
498 AcpiNsPrintNodePathname (Node, "Evaluating");
500 /* Do the actual method execution */
503 AcpiGbl_MethodExecuting = TRUE;
505 Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
507 AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n",
508 AcpiUtGetNodeName (Node),
509 AcpiFormatException (Status));
511 AcpiGbl_MethodExecuting = FALSE;
516 /*******************************************************************************
518 * FUNCTION: AcpiDbExecute
520 * PARAMETERS: Name - Name of method to execute
521 * Args - Parameters to the method
523 * Flags - single step/no single step
527 * DESCRIPTION: Execute a control method. Name is relative to the current
530 ******************************************************************************/
536 ACPI_OBJECT_TYPE *Types,
540 ACPI_BUFFER ReturnObj;
543 #ifdef ACPI_DEBUG_OUTPUT
544 UINT32 PreviousAllocations;
550 * Allow one execution to be performed by debugger or single step
551 * execution will be dead locked by the interpreter mutexes.
553 if (AcpiGbl_MethodExecuting)
555 AcpiOsPrintf ("Only one debugger execution is allowed.\n");
559 #ifdef ACPI_DEBUG_OUTPUT
560 /* Memory allocation tracking */
562 PreviousAllocations = AcpiDbGetOutstandingAllocations ();
567 (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
568 ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
572 NameString = ACPI_ALLOCATE (strlen (Name) + 1);
578 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
579 strcpy (NameString, Name);
580 AcpiUtStrupr (NameString);
582 /* Subcommand to Execute all predefined names in the namespace */
584 if (!strncmp (NameString, "PREDEF", 6))
586 AcpiDbEvaluatePredefinedNames ();
587 ACPI_FREE (NameString);
591 AcpiGbl_DbMethodInfo.Name = NameString;
592 AcpiGbl_DbMethodInfo.Args = Args;
593 AcpiGbl_DbMethodInfo.Types = Types;
594 AcpiGbl_DbMethodInfo.Flags = Flags;
596 ReturnObj.Pointer = NULL;
597 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
599 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
600 if (ACPI_FAILURE (Status))
602 ACPI_FREE (NameString);
606 /* Get the NS node, determines existence also */
608 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
609 &AcpiGbl_DbMethodInfo.Method);
610 if (ACPI_SUCCESS (Status))
612 Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo,
615 ACPI_FREE (NameString);
618 * Allow any handlers in separate threads to complete.
619 * (Such as Notify handlers invoked from AML executed above).
621 AcpiOsSleep ((UINT64) 10);
623 #ifdef ACPI_DEBUG_OUTPUT
625 /* Memory allocation tracking */
627 Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
629 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
634 "0x%X Outstanding allocations after evaluation of %s\n",
635 Allocations, AcpiGbl_DbMethodInfo.Pathname);
639 if (ACPI_FAILURE (Status))
641 AcpiOsPrintf ("Evaluation of %s failed with status %s\n",
642 AcpiGbl_DbMethodInfo.Pathname,
643 AcpiFormatException (Status));
647 /* Display a return object, if any */
649 if (ReturnObj.Length)
652 "Evaluation of %s returned object %p, "
653 "external buffer length %X\n",
654 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
655 (UINT32) ReturnObj.Length);
657 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
659 /* Dump a _PLD buffer if present */
661 if (ACPI_COMPARE_NAMESEG ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
662 AcpiGbl_DbMethodInfo.Method)->Name.Ascii),
665 AcpiDbDumpPldBuffer (ReturnObj.Pointer);
670 AcpiOsPrintf ("No object was returned from evaluation of %s\n",
671 AcpiGbl_DbMethodInfo.Pathname);
675 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
679 /*******************************************************************************
681 * FUNCTION: AcpiDbMethodThread
683 * PARAMETERS: Context - Execution info segment
687 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
688 * simply dispatches it.
690 ******************************************************************************/
692 static void ACPI_SYSTEM_XFACE
697 ACPI_DB_METHOD_INFO *Info = Context;
698 ACPI_DB_METHOD_INFO LocalInfo;
701 ACPI_BUFFER ReturnObj;
705 * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
706 * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
709 * Note: The arguments we are passing are used by the ASL test suite
710 * (aslts). Do not change them without updating the tests.
712 (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
716 AcpiDbUint32ToHexString (Info->NumCreated,
717 Info->IndexOfThreadStr);
718 AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (),
719 Info->IdOfThreadStr);
722 if (Info->Threads && (Info->NumCreated < Info->NumThreads))
724 Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
728 LocalInfo.Args = LocalInfo.Arguments;
729 LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
730 LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
731 LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
732 LocalInfo.Arguments[3] = NULL;
734 LocalInfo.Types = LocalInfo.ArgTypes;
736 (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
738 for (i = 0; i < Info->NumLoops; i++)
740 Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
741 if (ACPI_FAILURE (Status))
743 AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n",
744 AcpiFormatException (Status), Info->Pathname, i);
745 if (Status == AE_ABORT_METHOD)
754 AcpiOsPrintf ("%u loops, Thread 0x%x\n",
755 i, AcpiOsGetThreadId ());
758 if (ReturnObj.Length)
760 AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n",
761 Info->Pathname, ReturnObj.Pointer,
762 (UINT32) ReturnObj.Length);
763 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
768 /* Signal our completion */
771 (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate,
772 1, ACPI_WAIT_FOREVER);
773 Info->NumCompleted++;
775 if (Info->NumCompleted == Info->NumThreads)
777 /* Do signal for main thread once only */
781 (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
785 Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
786 if (ACPI_FAILURE (Status))
789 "Could not signal debugger thread sync semaphore, %s\n",
790 AcpiFormatException (Status));
796 /*******************************************************************************
798 * FUNCTION: AcpiDbSingleExecutionThread
800 * PARAMETERS: Context - Method info struct
804 * DESCRIPTION: Create one thread and execute a method
806 ******************************************************************************/
808 static void ACPI_SYSTEM_XFACE
809 AcpiDbSingleExecutionThread (
812 ACPI_DB_METHOD_INFO *Info = Context;
814 ACPI_BUFFER ReturnObj;
819 Status = AcpiDbExecuteMethod (Info, &ReturnObj);
820 if (ACPI_FAILURE (Status))
822 AcpiOsPrintf ("%s During evaluation of %s\n",
823 AcpiFormatException (Status), Info->Pathname);
827 /* Display a return object, if any */
829 if (ReturnObj.Length)
831 AcpiOsPrintf ("Evaluation of %s returned object %p, "
832 "external buffer length %X\n",
833 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
834 (UINT32) ReturnObj.Length);
836 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
839 AcpiOsPrintf ("\nBackground thread completed\n%c ",
840 ACPI_DEBUGGER_COMMAND_PROMPT);
844 /*******************************************************************************
846 * FUNCTION: AcpiDbCreateExecutionThread
848 * PARAMETERS: MethodNameArg - Control method to execute
849 * Arguments - Array of arguments to the method
850 * Types - Corresponding array of object types
854 * DESCRIPTION: Create a single thread to evaluate a namespace object. Handles
855 * arguments passed on command line for control methods.
857 ******************************************************************************/
860 AcpiDbCreateExecutionThread (
863 ACPI_OBJECT_TYPE *Types)
869 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
870 AcpiGbl_DbMethodInfo.Name = MethodNameArg;
871 AcpiGbl_DbMethodInfo.InitArgs = 1;
872 AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
873 AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
875 /* Setup method arguments, up to 7 (0-6) */
877 for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && *Arguments; i++)
879 AcpiGbl_DbMethodInfo.Arguments[i] = *Arguments;
882 AcpiGbl_DbMethodInfo.ArgTypes[i] = *Types;
886 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
887 if (ACPI_FAILURE (Status))
892 /* Get the NS node, determines existence also */
894 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
895 &AcpiGbl_DbMethodInfo.Method);
896 if (ACPI_FAILURE (Status))
898 AcpiOsPrintf ("%s Could not get handle for %s\n",
899 AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
903 Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD,
904 AcpiDbSingleExecutionThread, &AcpiGbl_DbMethodInfo);
905 if (ACPI_FAILURE (Status))
910 AcpiOsPrintf ("\nBackground thread started\n");
914 /*******************************************************************************
916 * FUNCTION: AcpiDbCreateExecutionThreads
918 * PARAMETERS: NumThreadsArg - Number of threads to create
919 * NumLoopsArg - Loop count for the thread(s)
920 * MethodNameArg - Control method to execute
924 * DESCRIPTION: Create threads to execute method(s)
926 ******************************************************************************/
929 AcpiDbCreateExecutionThreads (
939 ACPI_MUTEX MainThreadGate;
940 ACPI_MUTEX ThreadCompleteGate;
944 /* Get the arguments */
946 NumThreads = strtoul (NumThreadsArg, NULL, 0);
947 NumLoops = strtoul (NumLoopsArg, NULL, 0);
949 if (!NumThreads || !NumLoops)
951 AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
952 NumThreads, NumLoops);
957 * Create the semaphore for synchronization of
958 * the created threads with the main thread.
960 Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
961 if (ACPI_FAILURE (Status))
963 AcpiOsPrintf ("Could not create semaphore for "
964 "synchronization with the main thread, %s\n",
965 AcpiFormatException (Status));
970 * Create the semaphore for synchronization
971 * between the created threads.
973 Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
974 if (ACPI_FAILURE (Status))
976 AcpiOsPrintf ("Could not create semaphore for "
977 "synchronization between the created threads, %s\n",
978 AcpiFormatException (Status));
980 (void) AcpiOsDeleteSemaphore (MainThreadGate);
984 Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
985 if (ACPI_FAILURE (Status))
987 AcpiOsPrintf ("Could not create semaphore for "
988 "synchronization of AcpiGbl_DbMethodInfo, %s\n",
989 AcpiFormatException (Status));
991 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
992 (void) AcpiOsDeleteSemaphore (MainThreadGate);
996 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
998 /* Array to store IDs of threads */
1000 AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
1001 Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
1003 AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
1004 if (AcpiGbl_DbMethodInfo.Threads == NULL)
1006 AcpiOsPrintf ("No memory for thread IDs array\n");
1007 (void) AcpiOsDeleteSemaphore (MainThreadGate);
1008 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
1009 (void) AcpiOsDeleteSemaphore (InfoGate);
1012 memset (AcpiGbl_DbMethodInfo.Threads, 0, Size);
1014 /* Setup the context to be passed to each thread */
1016 AcpiGbl_DbMethodInfo.Name = MethodNameArg;
1017 AcpiGbl_DbMethodInfo.Flags = 0;
1018 AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
1019 AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
1020 AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
1021 AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
1023 /* Init arguments to be passed to method */
1025 AcpiGbl_DbMethodInfo.InitArgs = 1;
1026 AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
1027 AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
1028 AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
1029 AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
1030 AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
1032 AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
1033 AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
1034 AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
1035 AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
1037 AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
1039 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
1040 if (ACPI_FAILURE (Status))
1042 goto CleanupAndExit;
1045 /* Get the NS node, determines existence also */
1047 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
1048 &AcpiGbl_DbMethodInfo.Method);
1049 if (ACPI_FAILURE (Status))
1051 AcpiOsPrintf ("%s Could not get handle for %s\n",
1052 AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
1053 goto CleanupAndExit;
1056 /* Create the threads */
1058 AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
1059 NumThreads, NumLoops);
1061 for (i = 0; i < (NumThreads); i++)
1063 Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD, AcpiDbMethodThread,
1064 &AcpiGbl_DbMethodInfo);
1065 if (ACPI_FAILURE (Status))
1071 /* Wait for all threads to complete */
1073 (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
1075 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
1076 AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
1077 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1081 /* Cleanup and exit */
1083 (void) AcpiOsDeleteSemaphore (MainThreadGate);
1084 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
1085 (void) AcpiOsDeleteSemaphore (InfoGate);
1087 AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
1088 AcpiGbl_DbMethodInfo.Threads = NULL;