xref: /onnv-gate/usr/src/uts/intel/io/acpica/debugger/dbexec.c (revision 11225:eb6056029d84)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: dbexec - debugger control method execution
43446Smrj  *
53446Smrj  ******************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
119980SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj  * All rights reserved.
133446Smrj  *
143446Smrj  * 2. License
153446Smrj  *
163446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj  * rights.  You may have additional license terms from the party that provided
183446Smrj  * you this software, covering your right to use that party's intellectual
193446Smrj  * property rights.
203446Smrj  *
213446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj  * copy of the source code appearing in this file ("Covered Code") an
233446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj  * make derivatives, distribute, use and display any portion of the Covered
263446Smrj  * Code in any form, with the right to sublicense such rights; and
273446Smrj  *
283446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj  * license (with the right to sublicense), under only those claims of Intel
303446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj  * solely to the minimum extent necessary to exercise the above copyright
333446Smrj  * license, and in no event shall the patent license extend to any additions
343446Smrj  * to or modifications of the Original Intel Code.  No other license or right
353446Smrj  * is granted directly or by implication, estoppel or otherwise;
363446Smrj  *
373446Smrj  * The above copyright and patent license is granted only if the following
383446Smrj  * conditions are met:
393446Smrj  *
403446Smrj  * 3. Conditions
413446Smrj  *
423446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj  * Redistribution of source code of any substantial portion of the Covered
443446Smrj  * Code or modification with rights to further distribute source must include
453446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
473446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj  * contain a file documenting the changes Licensee made to create that Covered
493446Smrj  * Code and the date of any change.  Licensee must include in that file the
503446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
513446Smrj  * must include a prominent statement that the modification is derived,
523446Smrj  * directly or indirectly, from Original Intel Code.
533446Smrj  *
543446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj  * Redistribution of source code of any substantial portion of the Covered
563446Smrj  * Code or modification without rights to further distribute source must
573446Smrj  * include the following Disclaimer and Export Compliance provision in the
583446Smrj  * documentation and/or other materials provided with distribution.  In
593446Smrj  * addition, Licensee may not authorize further sublicense of source of any
603446Smrj  * portion of the Covered Code, and must include terms to the effect that the
613446Smrj  * license from Licensee to its licensee is limited to the intellectual
623446Smrj  * property embodied in the software Licensee provides to its licensee, and
633446Smrj  * not to intellectual property embodied in modifications its licensee may
643446Smrj  * make.
653446Smrj  *
663446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj  * substantial portion of the Covered Code or modification must reproduce the
683446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj  * provision in the documentation and/or other materials provided with the
703446Smrj  * distribution.
713446Smrj  *
723446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj  * Intel Code.
743446Smrj  *
753446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj  * other dealings in products derived from or relating to the Covered Code
783446Smrj  * without prior written authorization from Intel.
793446Smrj  *
803446Smrj  * 4. Disclaimer and Export Compliance
813446Smrj  *
823446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
853446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
863446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj  * PARTICULAR PURPOSE.
893446Smrj  *
903446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
963446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj  * LIMITED REMEDY.
983446Smrj  *
993446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj  * software or system incorporating such software without first obtaining any
1013446Smrj  * required license or other approval from the U. S. Department of Commerce or
1023446Smrj  * any other agency or department of the United States Government.  In the
1033446Smrj  * event Licensee exports any such software from the United States or
1043446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj  * ensure that the distribution and export/re-export of the software is in
1063446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj  * software, or service, directly or indirectly, to any country for which the
1103446Smrj  * United States government or any agency thereof requires an export license,
1113446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj  * such license, approval or letter.
1133446Smrj  *
1143446Smrj  *****************************************************************************/
1153446Smrj 
1163446Smrj 
1173446Smrj #include "acpi.h"
1189980SDana.Myers@Sun.COM #include "accommon.h"
1193446Smrj #include "acdebug.h"
1203446Smrj #include "acnamesp.h"
1213446Smrj 
1223446Smrj #ifdef ACPI_DEBUGGER
1233446Smrj 
1243446Smrj #define _COMPONENT          ACPI_CA_DEBUGGER
1253446Smrj         ACPI_MODULE_NAME    ("dbexec")
1263446Smrj 
1273446Smrj 
1283446Smrj static ACPI_DB_METHOD_INFO  AcpiGbl_DbMethodInfo;
1293446Smrj 
1303446Smrj /* Local prototypes */
1313446Smrj 
1323446Smrj static ACPI_STATUS
1333446Smrj AcpiDbExecuteMethod (
1343446Smrj     ACPI_DB_METHOD_INFO     *Info,
1353446Smrj     ACPI_BUFFER             *ReturnObj);
1363446Smrj 
1373446Smrj static void
1383446Smrj AcpiDbExecuteSetup (
1393446Smrj     ACPI_DB_METHOD_INFO     *Info);
1403446Smrj 
1413446Smrj static UINT32
1423446Smrj AcpiDbGetOutstandingAllocations (
1433446Smrj     void);
1443446Smrj 
1453446Smrj static void ACPI_SYSTEM_XFACE
1463446Smrj AcpiDbMethodThread (
1473446Smrj     void                    *Context);
1483446Smrj 
1493446Smrj static ACPI_STATUS
1503446Smrj AcpiDbExecutionWalk (
1513446Smrj     ACPI_HANDLE             ObjHandle,
1523446Smrj     UINT32                  NestingLevel,
1533446Smrj     void                    *Context,
1543446Smrj     void                    **ReturnValue);
1553446Smrj 
1563446Smrj 
1573446Smrj /*******************************************************************************
1583446Smrj  *
1593446Smrj  * FUNCTION:    AcpiDbExecuteMethod
1603446Smrj  *
1613446Smrj  * PARAMETERS:  Info            - Valid info segment
1623446Smrj  *              ReturnObj       - Where to put return object
1633446Smrj  *
1643446Smrj  * RETURN:      Status
1653446Smrj  *
1663446Smrj  * DESCRIPTION: Execute a control method.
1673446Smrj  *
1683446Smrj  ******************************************************************************/
1693446Smrj 
1703446Smrj static ACPI_STATUS
AcpiDbExecuteMethod(ACPI_DB_METHOD_INFO * Info,ACPI_BUFFER * ReturnObj)1713446Smrj AcpiDbExecuteMethod (
1723446Smrj     ACPI_DB_METHOD_INFO     *Info,
1733446Smrj     ACPI_BUFFER             *ReturnObj)
1743446Smrj {
1753446Smrj     ACPI_STATUS             Status;
1763446Smrj     ACPI_OBJECT_LIST        ParamObjects;
1773446Smrj     ACPI_OBJECT             Params[ACPI_METHOD_NUM_ARGS];
1787851SDana.Myers@Sun.COM     ACPI_HANDLE             Handle;
1793446Smrj     UINT32                  i;
1807851SDana.Myers@Sun.COM     ACPI_DEVICE_INFO        *ObjInfo;
1813446Smrj 
1823446Smrj 
1833446Smrj     if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
1843446Smrj     {
1853446Smrj         AcpiOsPrintf ("Warning: debug output is not enabled!\n");
1863446Smrj     }
1873446Smrj 
1887851SDana.Myers@Sun.COM     /* Get the NS node, determines existence also */
1893446Smrj 
1907851SDana.Myers@Sun.COM     Status = AcpiGetHandle (NULL, Info->Pathname, &Handle);
1917851SDana.Myers@Sun.COM     if (ACPI_FAILURE (Status))
1923446Smrj     {
1937851SDana.Myers@Sun.COM         return (Status);
1947851SDana.Myers@Sun.COM     }
1957851SDana.Myers@Sun.COM 
1967851SDana.Myers@Sun.COM     /* Get the object info for number of method parameters */
1973446Smrj 
198*11225SDana.Myers@Sun.COM     Status = AcpiGetObjectInfo (Handle, &ObjInfo);
1997851SDana.Myers@Sun.COM     if (ACPI_FAILURE (Status))
2007851SDana.Myers@Sun.COM     {
2017851SDana.Myers@Sun.COM         return (Status);
2023446Smrj     }
2037851SDana.Myers@Sun.COM 
2047851SDana.Myers@Sun.COM     ParamObjects.Pointer = NULL;
2057851SDana.Myers@Sun.COM     ParamObjects.Count   = 0;
2067851SDana.Myers@Sun.COM 
2077851SDana.Myers@Sun.COM     if (ObjInfo->Type == ACPI_TYPE_METHOD)
2083446Smrj     {
2097851SDana.Myers@Sun.COM         /* Are there arguments to the method? */
2103446Smrj 
2117851SDana.Myers@Sun.COM         if (Info->Args && Info->Args[0])
2127851SDana.Myers@Sun.COM         {
2137851SDana.Myers@Sun.COM             for (i = 0; Info->Args[i] && i < ACPI_METHOD_NUM_ARGS; i++)
2147851SDana.Myers@Sun.COM             {
2157851SDana.Myers@Sun.COM                 Params[i].Type          = ACPI_TYPE_INTEGER;
2167851SDana.Myers@Sun.COM                 Params[i].Integer.Value = ACPI_STRTOUL (Info->Args[i], NULL, 16);
2177851SDana.Myers@Sun.COM             }
2187851SDana.Myers@Sun.COM 
2197851SDana.Myers@Sun.COM             ParamObjects.Pointer = Params;
2207851SDana.Myers@Sun.COM             ParamObjects.Count   = i;
2217851SDana.Myers@Sun.COM         }
2227851SDana.Myers@Sun.COM         else
2237851SDana.Myers@Sun.COM         {
2247851SDana.Myers@Sun.COM             /* Setup default parameters */
2253446Smrj 
2267851SDana.Myers@Sun.COM             for (i = 0; i < ObjInfo->ParamCount; i++)
2277851SDana.Myers@Sun.COM             {
2287851SDana.Myers@Sun.COM                 switch (i)
2297851SDana.Myers@Sun.COM                 {
2307851SDana.Myers@Sun.COM                 case 0:
2317851SDana.Myers@Sun.COM 
2327851SDana.Myers@Sun.COM                     Params[0].Type           = ACPI_TYPE_INTEGER;
2337851SDana.Myers@Sun.COM                     Params[0].Integer.Value  = 0x01020304;
2347851SDana.Myers@Sun.COM                     break;
2357851SDana.Myers@Sun.COM 
2367851SDana.Myers@Sun.COM                 case 1:
2373446Smrj 
2387851SDana.Myers@Sun.COM                     Params[1].Type           = ACPI_TYPE_STRING;
2397851SDana.Myers@Sun.COM                     Params[1].String.Length  = 12;
2407851SDana.Myers@Sun.COM                     Params[1].String.Pointer = "AML Debugger";
2417851SDana.Myers@Sun.COM                     break;
2427851SDana.Myers@Sun.COM 
2437851SDana.Myers@Sun.COM                 default:
2447851SDana.Myers@Sun.COM 
2457851SDana.Myers@Sun.COM                     Params[i].Type           = ACPI_TYPE_INTEGER;
2467851SDana.Myers@Sun.COM                     Params[i].Integer.Value  = i * (ACPI_INTEGER) 0x1000;
2477851SDana.Myers@Sun.COM                     break;
2487851SDana.Myers@Sun.COM                 }
2497851SDana.Myers@Sun.COM             }
2507851SDana.Myers@Sun.COM 
2517851SDana.Myers@Sun.COM             ParamObjects.Pointer     = Params;
2527851SDana.Myers@Sun.COM             ParamObjects.Count       = ObjInfo->ParamCount;
2537851SDana.Myers@Sun.COM         }
2543446Smrj     }
2553446Smrj 
256*11225SDana.Myers@Sun.COM     ACPI_FREE (ObjInfo);
2577851SDana.Myers@Sun.COM 
2583446Smrj     /* Prepare for a return object of arbitrary size */
2593446Smrj 
2603446Smrj     ReturnObj->Pointer = AcpiGbl_DbBuffer;
2613446Smrj     ReturnObj->Length  = ACPI_DEBUG_BUFFER_SIZE;
2623446Smrj 
2633446Smrj     /* Do the actual method execution */
2643446Smrj 
2653446Smrj     AcpiGbl_MethodExecuting = TRUE;
2663446Smrj     Status = AcpiEvaluateObject (NULL,
2673446Smrj                 Info->Pathname, &ParamObjects, ReturnObj);
2683446Smrj 
2693446Smrj     AcpiGbl_CmSingleStep = FALSE;
2703446Smrj     AcpiGbl_MethodExecuting = FALSE;
2713446Smrj 
2723446Smrj     return (Status);
2733446Smrj }
2743446Smrj 
2753446Smrj 
2763446Smrj /*******************************************************************************
2773446Smrj  *
2783446Smrj  * FUNCTION:    AcpiDbExecuteSetup
2793446Smrj  *
2803446Smrj  * PARAMETERS:  Info            - Valid method info
2813446Smrj  *
2823446Smrj  * RETURN:      None
2833446Smrj  *
2843446Smrj  * DESCRIPTION: Setup info segment prior to method execution
2853446Smrj  *
2863446Smrj  ******************************************************************************/
2873446Smrj 
2883446Smrj static void
AcpiDbExecuteSetup(ACPI_DB_METHOD_INFO * Info)2893446Smrj AcpiDbExecuteSetup (
2903446Smrj     ACPI_DB_METHOD_INFO     *Info)
2913446Smrj {
2923446Smrj 
2933446Smrj     /* Catenate the current scope to the supplied name */
2943446Smrj 
2953446Smrj     Info->Pathname[0] = 0;
2963446Smrj     if ((Info->Name[0] != '\\') &&
2973446Smrj         (Info->Name[0] != '/'))
2983446Smrj     {
2993446Smrj         ACPI_STRCAT (Info->Pathname, AcpiGbl_DbScopeBuf);
3003446Smrj     }
3013446Smrj 
3023446Smrj     ACPI_STRCAT (Info->Pathname, Info->Name);
3033446Smrj     AcpiDbPrepNamestring (Info->Pathname);
3043446Smrj 
3053446Smrj     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
3063446Smrj     AcpiOsPrintf ("Executing %s\n", Info->Pathname);
3073446Smrj 
3083446Smrj     if (Info->Flags & EX_SINGLE_STEP)
3093446Smrj     {
3103446Smrj         AcpiGbl_CmSingleStep = TRUE;
3113446Smrj         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
3123446Smrj     }
3133446Smrj 
3143446Smrj     else
3153446Smrj     {
3163446Smrj         /* No single step, allow redirection to a file */
3173446Smrj 
3183446Smrj         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
3193446Smrj     }
3203446Smrj }
3213446Smrj 
3223446Smrj 
3233446Smrj #ifdef ACPI_DBG_TRACK_ALLOCATIONS
3247851SDana.Myers@Sun.COM UINT32
AcpiDbGetCacheInfo(ACPI_MEMORY_LIST * Cache)3253446Smrj AcpiDbGetCacheInfo (
3263446Smrj     ACPI_MEMORY_LIST        *Cache)
3273446Smrj {
3283446Smrj 
3293446Smrj     return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
3303446Smrj }
3313446Smrj #endif
3323446Smrj 
3333446Smrj /*******************************************************************************
3343446Smrj  *
3353446Smrj  * FUNCTION:    AcpiDbGetOutstandingAllocations
3363446Smrj  *
3373446Smrj  * PARAMETERS:  None
3383446Smrj  *
3393446Smrj  * RETURN:      Current global allocation count minus cache entries
3403446Smrj  *
3413446Smrj  * DESCRIPTION: Determine the current number of "outstanding" allocations --
3423446Smrj  *              those allocations that have not been freed and also are not
3433446Smrj  *              in one of the various object caches.
3443446Smrj  *
3453446Smrj  ******************************************************************************/
3463446Smrj 
3473446Smrj static UINT32
AcpiDbGetOutstandingAllocations(void)3483446Smrj AcpiDbGetOutstandingAllocations (
3493446Smrj     void)
3503446Smrj {
3513446Smrj     UINT32                  Outstanding = 0;
3523446Smrj 
3533446Smrj #ifdef ACPI_DBG_TRACK_ALLOCATIONS
3543446Smrj 
3553446Smrj     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
3563446Smrj     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
3573446Smrj     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
3583446Smrj     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
3593446Smrj #endif
3603446Smrj 
3613446Smrj     return (Outstanding);
3623446Smrj }
3633446Smrj 
3643446Smrj 
3653446Smrj /*******************************************************************************
3663446Smrj  *
3673446Smrj  * FUNCTION:    AcpiDbExecutionWalk
3683446Smrj  *
3693446Smrj  * PARAMETERS:  WALK_CALLBACK
3703446Smrj  *
3713446Smrj  * RETURN:      Status
3723446Smrj  *
3733446Smrj  * DESCRIPTION: Execute a control method.  Name is relative to the current
3743446Smrj  *              scope.
3753446Smrj  *
3763446Smrj  ******************************************************************************/
3773446Smrj 
3783446Smrj static ACPI_STATUS
AcpiDbExecutionWalk(ACPI_HANDLE ObjHandle,UINT32 NestingLevel,void * Context,void ** ReturnValue)3793446Smrj AcpiDbExecutionWalk (
3803446Smrj     ACPI_HANDLE             ObjHandle,
3813446Smrj     UINT32                  NestingLevel,
3823446Smrj     void                    *Context,
3833446Smrj     void                    **ReturnValue)
3843446Smrj {
3853446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
3863446Smrj     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
3873446Smrj     ACPI_BUFFER             ReturnObj;
3883446Smrj     ACPI_STATUS             Status;
3893446Smrj 
3903446Smrj 
3913446Smrj     ObjDesc = AcpiNsGetAttachedObject (Node);
3923446Smrj     if (ObjDesc->Method.ParamCount)
3933446Smrj     {
3943446Smrj         return (AE_OK);
3953446Smrj     }
3963446Smrj 
3973446Smrj     ReturnObj.Pointer = NULL;
3983446Smrj     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
3993446Smrj 
4003446Smrj     AcpiNsPrintNodePathname (Node, "Execute");
4013446Smrj 
4023446Smrj     /* Do the actual method execution */
4033446Smrj 
4043446Smrj     AcpiOsPrintf ("\n");
4053446Smrj     AcpiGbl_MethodExecuting = TRUE;
4063446Smrj 
4073446Smrj     Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
4083446Smrj 
4093446Smrj     AcpiOsPrintf ("[%4.4s] returned %s\n", AcpiUtGetNodeName (Node),
4103446Smrj             AcpiFormatException (Status));
4113446Smrj     AcpiGbl_MethodExecuting = FALSE;
4123446Smrj 
4133446Smrj     return (AE_OK);
4143446Smrj }
4153446Smrj 
4163446Smrj 
4173446Smrj /*******************************************************************************
4183446Smrj  *
4193446Smrj  * FUNCTION:    AcpiDbExecute
4203446Smrj  *
4213446Smrj  * PARAMETERS:  Name                - Name of method to execute
4223446Smrj  *              Args                - Parameters to the method
4233446Smrj  *              Flags               - single step/no single step
4243446Smrj  *
4253446Smrj  * RETURN:      None
4263446Smrj  *
4273446Smrj  * DESCRIPTION: Execute a control method.  Name is relative to the current
4283446Smrj  *              scope.
4293446Smrj  *
4303446Smrj  ******************************************************************************/
4313446Smrj 
4323446Smrj void
AcpiDbExecute(char * Name,char ** Args,UINT32 Flags)4333446Smrj AcpiDbExecute (
4343446Smrj     char                    *Name,
4353446Smrj     char                    **Args,
4363446Smrj     UINT32                  Flags)
4373446Smrj {
4383446Smrj     ACPI_STATUS             Status;
4393446Smrj     ACPI_BUFFER             ReturnObj;
4403446Smrj     char                    *NameString;
4413446Smrj 
4423446Smrj 
4433446Smrj #ifdef ACPI_DEBUG_OUTPUT
4443446Smrj     UINT32                  PreviousAllocations;
4453446Smrj     UINT32                  Allocations;
4463446Smrj 
4473446Smrj 
4483446Smrj     /* Memory allocation tracking */
4493446Smrj 
4503446Smrj     PreviousAllocations = AcpiDbGetOutstandingAllocations ();
4513446Smrj #endif
4523446Smrj 
4533446Smrj     if (*Name == '*')
4543446Smrj     {
4553446Smrj         (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
456*11225SDana.Myers@Sun.COM                     ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
4573446Smrj         return;
4583446Smrj     }
4593446Smrj     else
4603446Smrj     {
4613446Smrj         NameString = ACPI_ALLOCATE (ACPI_STRLEN (Name) + 1);
4623446Smrj         if (!NameString)
4633446Smrj         {
4643446Smrj             return;
4653446Smrj         }
4663446Smrj 
4677851SDana.Myers@Sun.COM         ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
4687851SDana.Myers@Sun.COM 
4693446Smrj         ACPI_STRCPY (NameString, Name);
4703446Smrj         AcpiUtStrupr (NameString);
4713446Smrj         AcpiGbl_DbMethodInfo.Name = NameString;
4723446Smrj         AcpiGbl_DbMethodInfo.Args = Args;
4733446Smrj         AcpiGbl_DbMethodInfo.Flags = Flags;
4743446Smrj 
4753446Smrj         ReturnObj.Pointer = NULL;
4763446Smrj         ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
4773446Smrj 
4783446Smrj         AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
4793446Smrj         Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj);
4803446Smrj         ACPI_FREE (NameString);
4813446Smrj     }
4823446Smrj 
4833446Smrj     /*
4843446Smrj      * Allow any handlers in separate threads to complete.
4853446Smrj      * (Such as Notify handlers invoked from AML executed above).
4863446Smrj      */
4873446Smrj     AcpiOsSleep ((ACPI_INTEGER) 10);
4883446Smrj 
4893446Smrj 
4903446Smrj #ifdef ACPI_DEBUG_OUTPUT
4913446Smrj 
4923446Smrj     /* Memory allocation tracking */
4933446Smrj 
4943446Smrj     Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
4953446Smrj 
4963446Smrj     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
4973446Smrj 
4983446Smrj     if (Allocations > 0)
4993446Smrj     {
5003446Smrj         AcpiOsPrintf ("Outstanding: 0x%X allocations after execution\n",
5013446Smrj                         Allocations);
5023446Smrj     }
5033446Smrj #endif
5043446Smrj 
5053446Smrj     if (ACPI_FAILURE (Status))
5063446Smrj     {
5073446Smrj         AcpiOsPrintf ("Execution of %s failed with status %s\n",
5083446Smrj             AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status));
5093446Smrj     }
5103446Smrj     else
5113446Smrj     {
5123446Smrj         /* Display a return object, if any */
5133446Smrj 
5143446Smrj         if (ReturnObj.Length)
5153446Smrj         {
5163446Smrj             AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
5173446Smrj                 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
5183446Smrj                 (UINT32) ReturnObj.Length);
5193446Smrj             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
5203446Smrj         }
5213446Smrj         else
5223446Smrj         {
5233446Smrj             AcpiOsPrintf ("No return object from execution of %s\n",
5243446Smrj                 AcpiGbl_DbMethodInfo.Pathname);
5253446Smrj         }
5263446Smrj     }
5273446Smrj 
5283446Smrj     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
5293446Smrj }
5303446Smrj 
5313446Smrj 
5323446Smrj /*******************************************************************************
5333446Smrj  *
5343446Smrj  * FUNCTION:    AcpiDbMethodThread
5353446Smrj  *
5363446Smrj  * PARAMETERS:  Context             - Execution info segment
5373446Smrj  *
5383446Smrj  * RETURN:      None
5393446Smrj  *
5403446Smrj  * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
5413446Smrj  *              simply dispatches it.
5423446Smrj  *
5433446Smrj  ******************************************************************************/
5443446Smrj 
5453446Smrj static void ACPI_SYSTEM_XFACE
AcpiDbMethodThread(void * Context)5463446Smrj AcpiDbMethodThread (
5473446Smrj     void                    *Context)
5483446Smrj {
5493446Smrj     ACPI_STATUS             Status;
5503446Smrj     ACPI_DB_METHOD_INFO     *Info = Context;
5519980SDana.Myers@Sun.COM     ACPI_DB_METHOD_INFO     LocalInfo;
5523446Smrj     UINT32                  i;
5537851SDana.Myers@Sun.COM     UINT8                   Allow;
5543446Smrj     ACPI_BUFFER             ReturnObj;
5553446Smrj 
5563446Smrj 
5579980SDana.Myers@Sun.COM     /*
5589980SDana.Myers@Sun.COM      * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
5599980SDana.Myers@Sun.COM      * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
5609980SDana.Myers@Sun.COM      * concurrently.
5619980SDana.Myers@Sun.COM      *
5629980SDana.Myers@Sun.COM      * Note: The arguments we are passing are used by the ASL test suite
5639980SDana.Myers@Sun.COM      * (aslts). Do not change them without updating the tests.
5649980SDana.Myers@Sun.COM      */
5659980SDana.Myers@Sun.COM     (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
5669980SDana.Myers@Sun.COM 
5677851SDana.Myers@Sun.COM     if (Info->InitArgs)
5687851SDana.Myers@Sun.COM     {
5697851SDana.Myers@Sun.COM         AcpiDbUInt32ToHexString (Info->NumCreated, Info->IndexOfThreadStr);
5709980SDana.Myers@Sun.COM         AcpiDbUInt32ToHexString (ACPI_TO_INTEGER (AcpiOsGetThreadId ()),
5719980SDana.Myers@Sun.COM             Info->IdOfThreadStr);
5727851SDana.Myers@Sun.COM     }
5737851SDana.Myers@Sun.COM 
5747851SDana.Myers@Sun.COM     if (Info->Threads && (Info->NumCreated < Info->NumThreads))
5757851SDana.Myers@Sun.COM     {
5769980SDana.Myers@Sun.COM         Info->Threads[Info->NumCreated++] =
5779980SDana.Myers@Sun.COM             ACPI_TO_INTEGER (AcpiOsGetThreadId());
5787851SDana.Myers@Sun.COM     }
5797851SDana.Myers@Sun.COM 
5809980SDana.Myers@Sun.COM     LocalInfo = *Info;
5819980SDana.Myers@Sun.COM     LocalInfo.Args = LocalInfo.Arguments;
5829980SDana.Myers@Sun.COM     LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
5839980SDana.Myers@Sun.COM     LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
5849980SDana.Myers@Sun.COM     LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
5859980SDana.Myers@Sun.COM     LocalInfo.Arguments[3] = NULL;
5869980SDana.Myers@Sun.COM 
5879980SDana.Myers@Sun.COM     (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
5889980SDana.Myers@Sun.COM 
5893446Smrj     for (i = 0; i < Info->NumLoops; i++)
5903446Smrj     {
5919980SDana.Myers@Sun.COM         Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
5923446Smrj         if (ACPI_FAILURE (Status))
5933446Smrj         {
5943446Smrj             AcpiOsPrintf ("%s During execution of %s at iteration %X\n",
5953446Smrj                 AcpiFormatException (Status), Info->Pathname, i);
5963446Smrj             if (Status == AE_ABORT_METHOD)
5973446Smrj             {
5983446Smrj                 break;
5993446Smrj             }
6003446Smrj         }
6013446Smrj 
6027851SDana.Myers@Sun.COM #if 0
6033446Smrj         if ((i % 100) == 0)
6043446Smrj         {
6057851SDana.Myers@Sun.COM             AcpiOsPrintf ("%d executions, Thread 0x%x\n", i, AcpiOsGetThreadId ());
6063446Smrj         }
6073446Smrj 
6083446Smrj         if (ReturnObj.Length)
6093446Smrj         {
6103446Smrj             AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
6113446Smrj                 Info->Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length);
6123446Smrj             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
6133446Smrj         }
6143446Smrj #endif
6153446Smrj     }
6163446Smrj 
6173446Smrj     /* Signal our completion */
6183446Smrj 
6197851SDana.Myers@Sun.COM     Allow = 0;
6207851SDana.Myers@Sun.COM     (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate, 1, ACPI_WAIT_FOREVER);
6217851SDana.Myers@Sun.COM     Info->NumCompleted++;
6227851SDana.Myers@Sun.COM 
6237851SDana.Myers@Sun.COM     if (Info->NumCompleted == Info->NumThreads)
6243446Smrj     {
6257851SDana.Myers@Sun.COM         /* Do signal for main thread once only */
6267851SDana.Myers@Sun.COM         Allow = 1;
6277851SDana.Myers@Sun.COM     }
6287851SDana.Myers@Sun.COM 
6297851SDana.Myers@Sun.COM     (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
6307851SDana.Myers@Sun.COM 
6317851SDana.Myers@Sun.COM     if (Allow)
6327851SDana.Myers@Sun.COM     {
6337851SDana.Myers@Sun.COM         Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
6347851SDana.Myers@Sun.COM         if (ACPI_FAILURE (Status))
6357851SDana.Myers@Sun.COM         {
6367851SDana.Myers@Sun.COM             AcpiOsPrintf ("Could not signal debugger thread sync semaphore, %s\n",
6377851SDana.Myers@Sun.COM                 AcpiFormatException (Status));
6387851SDana.Myers@Sun.COM         }
6393446Smrj     }
6403446Smrj }
6413446Smrj 
6423446Smrj 
6433446Smrj /*******************************************************************************
6443446Smrj  *
6453446Smrj  * FUNCTION:    AcpiDbCreateExecutionThreads
6463446Smrj  *
6473446Smrj  * PARAMETERS:  NumThreadsArg           - Number of threads to create
6483446Smrj  *              NumLoopsArg             - Loop count for the thread(s)
6493446Smrj  *              MethodNameArg           - Control method to execute
6503446Smrj  *
6513446Smrj  * RETURN:      None
6523446Smrj  *
6533446Smrj  * DESCRIPTION: Create threads to execute method(s)
6543446Smrj  *
6553446Smrj  ******************************************************************************/
6563446Smrj 
6573446Smrj void
AcpiDbCreateExecutionThreads(char * NumThreadsArg,char * NumLoopsArg,char * MethodNameArg)6583446Smrj AcpiDbCreateExecutionThreads (
6593446Smrj     char                    *NumThreadsArg,
6603446Smrj     char                    *NumLoopsArg,
6613446Smrj     char                    *MethodNameArg)
6623446Smrj {
6633446Smrj     ACPI_STATUS             Status;
6643446Smrj     UINT32                  NumThreads;
6653446Smrj     UINT32                  NumLoops;
6663446Smrj     UINT32                  i;
6677851SDana.Myers@Sun.COM     UINT32                  Size;
6687851SDana.Myers@Sun.COM     ACPI_MUTEX              MainThreadGate;
6697851SDana.Myers@Sun.COM     ACPI_MUTEX              ThreadCompleteGate;
6709980SDana.Myers@Sun.COM     ACPI_MUTEX              InfoGate;
6719980SDana.Myers@Sun.COM 
6723446Smrj 
6733446Smrj     /* Get the arguments */
6743446Smrj 
6753446Smrj     NumThreads = ACPI_STRTOUL (NumThreadsArg, NULL, 0);
6763446Smrj     NumLoops   = ACPI_STRTOUL (NumLoopsArg, NULL, 0);
6773446Smrj 
6783446Smrj     if (!NumThreads || !NumLoops)
6793446Smrj     {
6803446Smrj         AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
6813446Smrj             NumThreads, NumLoops);
6823446Smrj         return;
6833446Smrj     }
6843446Smrj 
6857851SDana.Myers@Sun.COM     /*
6867851SDana.Myers@Sun.COM      * Create the semaphore for synchronization of
6877851SDana.Myers@Sun.COM      * the created threads with the main thread.
6887851SDana.Myers@Sun.COM      */
6897851SDana.Myers@Sun.COM     Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
6903446Smrj     if (ACPI_FAILURE (Status))
6913446Smrj     {
6927851SDana.Myers@Sun.COM         AcpiOsPrintf ("Could not create semaphore for synchronization with the main thread, %s\n",
6933446Smrj             AcpiFormatException (Status));
6943446Smrj         return;
6953446Smrj     }
6963446Smrj 
6977851SDana.Myers@Sun.COM     /*
6987851SDana.Myers@Sun.COM      * Create the semaphore for synchronization
6997851SDana.Myers@Sun.COM      * between the created threads.
7007851SDana.Myers@Sun.COM      */
7017851SDana.Myers@Sun.COM     Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
7027851SDana.Myers@Sun.COM     if (ACPI_FAILURE (Status))
7037851SDana.Myers@Sun.COM     {
7047851SDana.Myers@Sun.COM         AcpiOsPrintf ("Could not create semaphore for synchronization between the created threads, %s\n",
7057851SDana.Myers@Sun.COM             AcpiFormatException (Status));
7067851SDana.Myers@Sun.COM         (void) AcpiOsDeleteSemaphore (MainThreadGate);
7077851SDana.Myers@Sun.COM         return;
7087851SDana.Myers@Sun.COM     }
7097851SDana.Myers@Sun.COM 
7109980SDana.Myers@Sun.COM     Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
7119980SDana.Myers@Sun.COM     if (ACPI_FAILURE (Status))
7129980SDana.Myers@Sun.COM     {
7139980SDana.Myers@Sun.COM         AcpiOsPrintf ("Could not create semaphore for synchronization of AcpiGbl_DbMethodInfo, %s\n",
7149980SDana.Myers@Sun.COM             AcpiFormatException (Status));
7159980SDana.Myers@Sun.COM         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
7169980SDana.Myers@Sun.COM         (void) AcpiOsDeleteSemaphore (MainThreadGate);
7179980SDana.Myers@Sun.COM         return;
7189980SDana.Myers@Sun.COM     }
7199980SDana.Myers@Sun.COM 
7207851SDana.Myers@Sun.COM     ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
7217851SDana.Myers@Sun.COM 
7227851SDana.Myers@Sun.COM     /* Array to store IDs of threads */
7237851SDana.Myers@Sun.COM 
7247851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
7257851SDana.Myers@Sun.COM     Size = 4 * AcpiGbl_DbMethodInfo.NumThreads;
7267851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.Threads = (UINT32 *) AcpiOsAllocate (Size);
7277851SDana.Myers@Sun.COM     if (AcpiGbl_DbMethodInfo.Threads == NULL)
7287851SDana.Myers@Sun.COM     {
7297851SDana.Myers@Sun.COM         AcpiOsPrintf ("No memory for thread IDs array\n");
7307851SDana.Myers@Sun.COM         (void) AcpiOsDeleteSemaphore (MainThreadGate);
7317851SDana.Myers@Sun.COM         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
7329980SDana.Myers@Sun.COM         (void) AcpiOsDeleteSemaphore (InfoGate);
7337851SDana.Myers@Sun.COM         return;
7347851SDana.Myers@Sun.COM     }
7357851SDana.Myers@Sun.COM     ACPI_MEMSET (AcpiGbl_DbMethodInfo.Threads, 0, Size);
7367851SDana.Myers@Sun.COM 
7373446Smrj     /* Setup the context to be passed to each thread */
7383446Smrj 
7393446Smrj     AcpiGbl_DbMethodInfo.Name = MethodNameArg;
7403446Smrj     AcpiGbl_DbMethodInfo.Flags = 0;
7413446Smrj     AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
7427851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
7437851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
7449980SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
7457851SDana.Myers@Sun.COM 
7467851SDana.Myers@Sun.COM     /* Init arguments to be passed to method */
7477851SDana.Myers@Sun.COM 
7487851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.InitArgs = 1;
7497851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
7507851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
7517851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
7527851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
7537851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
7547851SDana.Myers@Sun.COM     AcpiDbUInt32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
7553446Smrj 
7563446Smrj     AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
7573446Smrj 
7583446Smrj     /* Create the threads */
7593446Smrj 
7603446Smrj     AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
7613446Smrj         NumThreads, NumLoops);
7623446Smrj 
7633446Smrj     for (i = 0; i < (NumThreads); i++)
7643446Smrj     {
7653446Smrj         Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbMethodThread,
7663446Smrj             &AcpiGbl_DbMethodInfo);
7673446Smrj         if (ACPI_FAILURE (Status))
7683446Smrj         {
7693446Smrj             break;
7703446Smrj         }
7713446Smrj     }
7723446Smrj 
7733446Smrj     /* Wait for all threads to complete */
7743446Smrj 
7757851SDana.Myers@Sun.COM     (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
7763446Smrj 
7773446Smrj     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
7783446Smrj     AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
7793446Smrj     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
7807851SDana.Myers@Sun.COM 
7817851SDana.Myers@Sun.COM     /* Cleanup and exit */
7827851SDana.Myers@Sun.COM 
7837851SDana.Myers@Sun.COM     (void) AcpiOsDeleteSemaphore (MainThreadGate);
7847851SDana.Myers@Sun.COM     (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
7859980SDana.Myers@Sun.COM     (void) AcpiOsDeleteSemaphore (InfoGate);
7867851SDana.Myers@Sun.COM 
7877851SDana.Myers@Sun.COM     AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
7887851SDana.Myers@Sun.COM     AcpiGbl_DbMethodInfo.Threads = NULL;
7893446Smrj }
7903446Smrj 
7913446Smrj #endif /* ACPI_DEBUGGER */
7923446Smrj 
7933446Smrj 
794