xref: /dflybsd-src/sys/contrib/dev/acpica/source/components/debugger/dbexec.c (revision b4315fc7edb71a3b20b837c3aa96f46bf41080bf)
1 /*******************************************************************************
2  *
3  * Module Name: dbexec - debugger control method execution
4  *
5  ******************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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
19  * property rights.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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
64  * make.
65  *
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
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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
88  * PARTICULAR PURPOSE.
89  *
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
97  * LIMITED REMEDY.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
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.
133  *
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.
145  *
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.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acdebug.h"
155 #include "acnamesp.h"
156 
157 #ifdef ACPI_DEBUGGER
158 
159 #define _COMPONENT          ACPI_CA_DEBUGGER
160         ACPI_MODULE_NAME    ("dbexec")
161 
162 
163 static ACPI_DB_METHOD_INFO          AcpiGbl_DbMethodInfo;
164 
165 /* Local prototypes */
166 
167 static ACPI_STATUS
168 AcpiDbExecuteMethod (
169     ACPI_DB_METHOD_INFO     *Info,
170     ACPI_BUFFER             *ReturnObj);
171 
172 static ACPI_STATUS
173 AcpiDbExecuteSetup (
174     ACPI_DB_METHOD_INFO     *Info);
175 
176 static UINT32
177 AcpiDbGetOutstandingAllocations (
178     void);
179 
180 static void ACPI_SYSTEM_XFACE
181 AcpiDbMethodThread (
182     void                    *Context);
183 
184 static ACPI_STATUS
185 AcpiDbExecutionWalk (
186     ACPI_HANDLE             ObjHandle,
187     UINT32                  NestingLevel,
188     void                    *Context,
189     void                    **ReturnValue);
190 
191 
192 /*******************************************************************************
193  *
194  * FUNCTION:    AcpiDbDeleteObjects
195  *
196  * PARAMETERS:  Count               - Count of objects in the list
197  *              Objects             - Array of ACPI_OBJECTs to be deleted
198  *
199  * RETURN:      None
200  *
201  * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
202  *              packages via recursion.
203  *
204  ******************************************************************************/
205 
206 void
207 AcpiDbDeleteObjects (
208     UINT32                  Count,
209     ACPI_OBJECT             *Objects)
210 {
211     UINT32                  i;
212 
213 
214     for (i = 0; i < Count; i++)
215     {
216         switch (Objects[i].Type)
217         {
218         case ACPI_TYPE_BUFFER:
219 
220             ACPI_FREE (Objects[i].Buffer.Pointer);
221             break;
222 
223         case ACPI_TYPE_PACKAGE:
224 
225             /* Recursive call to delete package elements */
226 
227             AcpiDbDeleteObjects (Objects[i].Package.Count,
228                 Objects[i].Package.Elements);
229 
230             /* Free the elements array */
231 
232             ACPI_FREE (Objects[i].Package.Elements);
233             break;
234 
235         default:
236 
237             break;
238         }
239     }
240 }
241 
242 
243 /*******************************************************************************
244  *
245  * FUNCTION:    AcpiDbExecuteMethod
246  *
247  * PARAMETERS:  Info            - Valid info segment
248  *              ReturnObj       - Where to put return object
249  *
250  * RETURN:      Status
251  *
252  * DESCRIPTION: Execute a control method.
253  *
254  ******************************************************************************/
255 
256 static ACPI_STATUS
257 AcpiDbExecuteMethod (
258     ACPI_DB_METHOD_INFO     *Info,
259     ACPI_BUFFER             *ReturnObj)
260 {
261     ACPI_STATUS             Status;
262     ACPI_OBJECT_LIST        ParamObjects;
263     ACPI_OBJECT             Params[ACPI_DEBUGGER_MAX_ARGS + 1];
264     UINT32                  i;
265 
266 
267     ACPI_FUNCTION_TRACE (DbExecuteMethod);
268 
269 
270     if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
271     {
272         AcpiOsPrintf ("Warning: debug output is not enabled!\n");
273     }
274 
275     ParamObjects.Count = 0;
276     ParamObjects.Pointer = NULL;
277 
278     /* Pass through any command-line arguments */
279 
280     if (Info->Args && Info->Args[0])
281     {
282         /* Get arguments passed on the command line */
283 
284         for (i = 0; (Info->Args[i] && *(Info->Args[i])); i++)
285         {
286             /* Convert input string (token) to an actual ACPI_OBJECT */
287 
288             Status = AcpiDbConvertToObject (Info->Types[i],
289                 Info->Args[i], &Params[i]);
290             if (ACPI_FAILURE (Status))
291             {
292                 ACPI_EXCEPTION ((AE_INFO, Status,
293                     "While parsing method arguments"));
294                 goto Cleanup;
295             }
296         }
297 
298         ParamObjects.Count = i;
299         ParamObjects.Pointer = Params;
300     }
301 
302     /* Prepare for a return object of arbitrary size */
303 
304     ReturnObj->Pointer = AcpiGbl_DbBuffer;
305     ReturnObj->Length  = ACPI_DEBUG_BUFFER_SIZE;
306 
307     /* Do the actual method execution */
308 
309     AcpiGbl_MethodExecuting = TRUE;
310     Status = AcpiEvaluateObject (NULL, Info->Pathname,
311         &ParamObjects, ReturnObj);
312 
313     AcpiGbl_CmSingleStep = FALSE;
314     AcpiGbl_MethodExecuting = FALSE;
315 
316     if (ACPI_FAILURE (Status))
317     {
318         ACPI_EXCEPTION ((AE_INFO, Status,
319             "while executing %s from debugger", Info->Pathname));
320 
321         if (Status == AE_BUFFER_OVERFLOW)
322         {
323             ACPI_ERROR ((AE_INFO,
324                 "Possible overflow of internal debugger "
325                 "buffer (size 0x%X needed 0x%X)",
326                 ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length));
327         }
328     }
329 
330 Cleanup:
331     AcpiDbDeleteObjects (ParamObjects.Count, Params);
332     return_ACPI_STATUS (Status);
333 }
334 
335 
336 /*******************************************************************************
337  *
338  * FUNCTION:    AcpiDbExecuteSetup
339  *
340  * PARAMETERS:  Info            - Valid method info
341  *
342  * RETURN:      None
343  *
344  * DESCRIPTION: Setup info segment prior to method execution
345  *
346  ******************************************************************************/
347 
348 static ACPI_STATUS
349 AcpiDbExecuteSetup (
350     ACPI_DB_METHOD_INFO     *Info)
351 {
352     ACPI_STATUS             Status;
353 
354 
355     ACPI_FUNCTION_NAME (DbExecuteSetup);
356 
357 
358     /* Catenate the current scope to the supplied name */
359 
360     Info->Pathname[0] = 0;
361     if ((Info->Name[0] != '\\') &&
362         (Info->Name[0] != '/'))
363     {
364         if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
365             AcpiGbl_DbScopeBuf))
366         {
367             Status = AE_BUFFER_OVERFLOW;
368             goto ErrorExit;
369         }
370     }
371 
372     if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
373         Info->Name))
374     {
375         Status = AE_BUFFER_OVERFLOW;
376         goto ErrorExit;
377     }
378 
379     AcpiDbPrepNamestring (Info->Pathname);
380 
381     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
382     AcpiOsPrintf ("Evaluating %s\n", Info->Pathname);
383 
384     if (Info->Flags & EX_SINGLE_STEP)
385     {
386         AcpiGbl_CmSingleStep = TRUE;
387         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
388     }
389 
390     else
391     {
392         /* No single step, allow redirection to a file */
393 
394         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
395     }
396 
397     return (AE_OK);
398 
399 ErrorExit:
400 
401     ACPI_EXCEPTION ((AE_INFO, Status, "During setup for method execution"));
402     return (Status);
403 }
404 
405 
406 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
407 UINT32
408 AcpiDbGetCacheInfo (
409     ACPI_MEMORY_LIST        *Cache)
410 {
411 
412     return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
413 }
414 #endif
415 
416 /*******************************************************************************
417  *
418  * FUNCTION:    AcpiDbGetOutstandingAllocations
419  *
420  * PARAMETERS:  None
421  *
422  * RETURN:      Current global allocation count minus cache entries
423  *
424  * DESCRIPTION: Determine the current number of "outstanding" allocations --
425  *              those allocations that have not been freed and also are not
426  *              in one of the various object caches.
427  *
428  ******************************************************************************/
429 
430 static UINT32
431 AcpiDbGetOutstandingAllocations (
432     void)
433 {
434     UINT32                  Outstanding = 0;
435 
436 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
437 
438     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
439     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
440     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
441     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
442 #endif
443 
444     return (Outstanding);
445 }
446 
447 
448 /*******************************************************************************
449  *
450  * FUNCTION:    AcpiDbExecutionWalk
451  *
452  * PARAMETERS:  WALK_CALLBACK
453  *
454  * RETURN:      Status
455  *
456  * DESCRIPTION: Execute a control method. Name is relative to the current
457  *              scope.
458  *
459  ******************************************************************************/
460 
461 static ACPI_STATUS
462 AcpiDbExecutionWalk (
463     ACPI_HANDLE             ObjHandle,
464     UINT32                  NestingLevel,
465     void                    *Context,
466     void                    **ReturnValue)
467 {
468     ACPI_OPERAND_OBJECT     *ObjDesc;
469     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
470     ACPI_BUFFER             ReturnObj;
471     ACPI_STATUS             Status;
472 
473 
474     ObjDesc = AcpiNsGetAttachedObject (Node);
475     if (ObjDesc->Method.ParamCount)
476     {
477         return (AE_OK);
478     }
479 
480     ReturnObj.Pointer = NULL;
481     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
482 
483     AcpiNsPrintNodePathname (Node, "Evaluating");
484 
485     /* Do the actual method execution */
486 
487     AcpiOsPrintf ("\n");
488     AcpiGbl_MethodExecuting = TRUE;
489 
490     Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
491 
492     AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n",
493         AcpiUtGetNodeName (Node),
494         AcpiFormatException (Status));
495 
496     AcpiGbl_MethodExecuting = FALSE;
497     return (AE_OK);
498 }
499 
500 
501 /*******************************************************************************
502  *
503  * FUNCTION:    AcpiDbExecute
504  *
505  * PARAMETERS:  Name                - Name of method to execute
506  *              Args                - Parameters to the method
507  *              Types               -
508  *              Flags               - single step/no single step
509  *
510  * RETURN:      None
511  *
512  * DESCRIPTION: Execute a control method. Name is relative to the current
513  *              scope.
514  *
515  ******************************************************************************/
516 
517 void
518 AcpiDbExecute (
519     char                    *Name,
520     char                    **Args,
521     ACPI_OBJECT_TYPE        *Types,
522     UINT32                  Flags)
523 {
524     ACPI_STATUS             Status;
525     ACPI_BUFFER             ReturnObj;
526     char                    *NameString;
527 
528 #ifdef ACPI_DEBUG_OUTPUT
529     UINT32                  PreviousAllocations;
530     UINT32                  Allocations;
531 #endif
532 
533 
534     /*
535      * Allow one execution to be performed by debugger or single step
536      * execution will be dead locked by the interpreter mutexes.
537      */
538     if (AcpiGbl_MethodExecuting)
539     {
540         AcpiOsPrintf ("Only one debugger execution is allowed.\n");
541         return;
542     }
543 
544 #ifdef ACPI_DEBUG_OUTPUT
545     /* Memory allocation tracking */
546 
547     PreviousAllocations = AcpiDbGetOutstandingAllocations ();
548 #endif
549 
550     if (*Name == '*')
551     {
552         (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
553             ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
554         return;
555     }
556 
557     NameString = ACPI_ALLOCATE (strlen (Name) + 1);
558     if (!NameString)
559     {
560         return;
561     }
562 
563     memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
564     strcpy (NameString, Name);
565     AcpiUtStrupr (NameString);
566 
567     /* Subcommand to Execute all predefined names in the namespace */
568 
569     if (!strncmp (NameString, "PREDEF", 6))
570     {
571         AcpiDbEvaluatePredefinedNames ();
572         ACPI_FREE (NameString);
573         return;
574     }
575 
576     AcpiGbl_DbMethodInfo.Name = NameString;
577     AcpiGbl_DbMethodInfo.Args = Args;
578     AcpiGbl_DbMethodInfo.Types = Types;
579     AcpiGbl_DbMethodInfo.Flags = Flags;
580 
581     ReturnObj.Pointer = NULL;
582     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
583 
584     Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
585     if (ACPI_FAILURE (Status))
586     {
587         ACPI_FREE (NameString);
588         return;
589     }
590 
591     /* Get the NS node, determines existence also */
592 
593     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
594         &AcpiGbl_DbMethodInfo.Method);
595     if (ACPI_SUCCESS (Status))
596     {
597         Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo,
598             &ReturnObj);
599     }
600     ACPI_FREE (NameString);
601 
602     /*
603      * Allow any handlers in separate threads to complete.
604      * (Such as Notify handlers invoked from AML executed above).
605      */
606     AcpiOsSleep ((UINT64) 10);
607 
608 #ifdef ACPI_DEBUG_OUTPUT
609 
610     /* Memory allocation tracking */
611 
612     Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
613 
614     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
615 
616     if (Allocations > 0)
617     {
618         AcpiOsPrintf (
619             "0x%X Outstanding allocations after evaluation of %s\n",
620             Allocations, AcpiGbl_DbMethodInfo.Pathname);
621     }
622 #endif
623 
624     if (ACPI_FAILURE (Status))
625     {
626         AcpiOsPrintf ("Evaluation of %s failed with status %s\n",
627             AcpiGbl_DbMethodInfo.Pathname,
628             AcpiFormatException (Status));
629     }
630     else
631     {
632         /* Display a return object, if any */
633 
634         if (ReturnObj.Length)
635         {
636             AcpiOsPrintf (
637                 "Evaluation of %s returned object %p, "
638                 "external buffer length %X\n",
639                 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
640                 (UINT32) ReturnObj.Length);
641 
642             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
643 
644             /* Dump a _PLD buffer if present */
645 
646             if (ACPI_COMPARE_NAME ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
647                 AcpiGbl_DbMethodInfo.Method)->Name.Ascii),
648                 METHOD_NAME__PLD))
649             {
650                 AcpiDbDumpPldBuffer (ReturnObj.Pointer);
651             }
652         }
653         else
654         {
655             AcpiOsPrintf ("No object was returned from evaluation of %s\n",
656                 AcpiGbl_DbMethodInfo.Pathname);
657         }
658     }
659 
660     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
661 }
662 
663 
664 /*******************************************************************************
665  *
666  * FUNCTION:    AcpiDbMethodThread
667  *
668  * PARAMETERS:  Context             - Execution info segment
669  *
670  * RETURN:      None
671  *
672  * DESCRIPTION: Debugger execute thread. Waits for a command line, then
673  *              simply dispatches it.
674  *
675  ******************************************************************************/
676 
677 static void ACPI_SYSTEM_XFACE
678 AcpiDbMethodThread (
679     void                    *Context)
680 {
681     ACPI_STATUS             Status;
682     ACPI_DB_METHOD_INFO     *Info = Context;
683     ACPI_DB_METHOD_INFO     LocalInfo;
684     UINT32                  i;
685     UINT8                   Allow;
686     ACPI_BUFFER             ReturnObj;
687 
688 
689     /*
690      * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
691      * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
692      * concurrently.
693      *
694      * Note: The arguments we are passing are used by the ASL test suite
695      * (aslts). Do not change them without updating the tests.
696      */
697     (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
698 
699     if (Info->InitArgs)
700     {
701         AcpiDbUint32ToHexString (Info->NumCreated,
702             Info->IndexOfThreadStr);
703         AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (),
704             Info->IdOfThreadStr);
705     }
706 
707     if (Info->Threads && (Info->NumCreated < Info->NumThreads))
708     {
709         Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
710     }
711 
712     LocalInfo = *Info;
713     LocalInfo.Args = LocalInfo.Arguments;
714     LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
715     LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
716     LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
717     LocalInfo.Arguments[3] = NULL;
718 
719     LocalInfo.Types = LocalInfo.ArgTypes;
720 
721     (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
722 
723     for (i = 0; i < Info->NumLoops; i++)
724     {
725         Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
726         if (ACPI_FAILURE (Status))
727         {
728             AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n",
729                 AcpiFormatException (Status), Info->Pathname, i);
730             if (Status == AE_ABORT_METHOD)
731             {
732                 break;
733             }
734         }
735 
736 #if 0
737         if ((i % 100) == 0)
738         {
739             AcpiOsPrintf ("%u loops, Thread 0x%x\n",
740                 i, AcpiOsGetThreadId ());
741         }
742 
743         if (ReturnObj.Length)
744         {
745             AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n",
746                 Info->Pathname, ReturnObj.Pointer,
747                 (UINT32) ReturnObj.Length);
748             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
749         }
750 #endif
751     }
752 
753     /* Signal our completion */
754 
755     Allow = 0;
756     (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate,
757         1, ACPI_WAIT_FOREVER);
758     Info->NumCompleted++;
759 
760     if (Info->NumCompleted == Info->NumThreads)
761     {
762         /* Do signal for main thread once only */
763         Allow = 1;
764     }
765 
766     (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
767 
768     if (Allow)
769     {
770         Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
771         if (ACPI_FAILURE (Status))
772         {
773             AcpiOsPrintf (
774                 "Could not signal debugger thread sync semaphore, %s\n",
775                 AcpiFormatException (Status));
776         }
777     }
778 }
779 
780 
781 /*******************************************************************************
782  *
783  * FUNCTION:    AcpiDbCreateExecutionThreads
784  *
785  * PARAMETERS:  NumThreadsArg           - Number of threads to create
786  *              NumLoopsArg             - Loop count for the thread(s)
787  *              MethodNameArg           - Control method to execute
788  *
789  * RETURN:      None
790  *
791  * DESCRIPTION: Create threads to execute method(s)
792  *
793  ******************************************************************************/
794 
795 void
796 AcpiDbCreateExecutionThreads (
797     char                    *NumThreadsArg,
798     char                    *NumLoopsArg,
799     char                    *MethodNameArg)
800 {
801     ACPI_STATUS             Status;
802     UINT32                  NumThreads;
803     UINT32                  NumLoops;
804     UINT32                  i;
805     UINT32                  Size;
806     ACPI_MUTEX              MainThreadGate;
807     ACPI_MUTEX              ThreadCompleteGate;
808     ACPI_MUTEX              InfoGate;
809 
810 
811     /* Get the arguments */
812 
813     NumThreads = strtoul (NumThreadsArg, NULL, 0);
814     NumLoops = strtoul (NumLoopsArg, NULL, 0);
815 
816     if (!NumThreads || !NumLoops)
817     {
818         AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
819             NumThreads, NumLoops);
820         return;
821     }
822 
823     /*
824      * Create the semaphore for synchronization of
825      * the created threads with the main thread.
826      */
827     Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
828     if (ACPI_FAILURE (Status))
829     {
830         AcpiOsPrintf ("Could not create semaphore for "
831             "synchronization with the main thread, %s\n",
832             AcpiFormatException (Status));
833         return;
834     }
835 
836     /*
837      * Create the semaphore for synchronization
838      * between the created threads.
839      */
840     Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
841     if (ACPI_FAILURE (Status))
842     {
843         AcpiOsPrintf ("Could not create semaphore for "
844             "synchronization between the created threads, %s\n",
845             AcpiFormatException (Status));
846 
847         (void) AcpiOsDeleteSemaphore (MainThreadGate);
848         return;
849     }
850 
851     Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
852     if (ACPI_FAILURE (Status))
853     {
854         AcpiOsPrintf ("Could not create semaphore for "
855             "synchronization of AcpiGbl_DbMethodInfo, %s\n",
856             AcpiFormatException (Status));
857 
858         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
859         (void) AcpiOsDeleteSemaphore (MainThreadGate);
860         return;
861     }
862 
863     memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
864 
865     /* Array to store IDs of threads */
866 
867     AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
868     Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
869 
870     AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
871     if (AcpiGbl_DbMethodInfo.Threads == NULL)
872     {
873         AcpiOsPrintf ("No memory for thread IDs array\n");
874         (void) AcpiOsDeleteSemaphore (MainThreadGate);
875         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
876         (void) AcpiOsDeleteSemaphore (InfoGate);
877         return;
878     }
879     memset (AcpiGbl_DbMethodInfo.Threads, 0, Size);
880 
881     /* Setup the context to be passed to each thread */
882 
883     AcpiGbl_DbMethodInfo.Name = MethodNameArg;
884     AcpiGbl_DbMethodInfo.Flags = 0;
885     AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
886     AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
887     AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
888     AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
889 
890     /* Init arguments to be passed to method */
891 
892     AcpiGbl_DbMethodInfo.InitArgs = 1;
893     AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
894     AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
895     AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
896     AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
897     AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
898 
899     AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
900     AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
901     AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
902     AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
903 
904     AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
905 
906     Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
907     if (ACPI_FAILURE (Status))
908     {
909         goto CleanupAndExit;
910     }
911 
912     /* Get the NS node, determines existence also */
913 
914     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
915         &AcpiGbl_DbMethodInfo.Method);
916     if (ACPI_FAILURE (Status))
917     {
918         AcpiOsPrintf ("%s Could not get handle for %s\n",
919             AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
920         goto CleanupAndExit;
921     }
922 
923     /* Create the threads */
924 
925     AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
926         NumThreads, NumLoops);
927 
928     for (i = 0; i < (NumThreads); i++)
929     {
930         Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD, AcpiDbMethodThread,
931             &AcpiGbl_DbMethodInfo);
932         if (ACPI_FAILURE (Status))
933         {
934             break;
935         }
936     }
937 
938     /* Wait for all threads to complete */
939 
940     (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
941 
942     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
943     AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
944     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
945 
946 CleanupAndExit:
947 
948     /* Cleanup and exit */
949 
950     (void) AcpiOsDeleteSemaphore (MainThreadGate);
951     (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
952     (void) AcpiOsDeleteSemaphore (InfoGate);
953 
954     AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
955     AcpiGbl_DbMethodInfo.Threads = NULL;
956 }
957 
958 #endif /* ACPI_DEBUGGER */
959