Home | History | Annotate | Line # | Download | only in debugger
dbexec.c revision 1.1.1.19
      1       1.1    jruoho /*******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: dbexec - debugger control method execution
      4       1.1    jruoho  *
      5       1.1    jruoho  ******************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.19  christos  * Copyright (C) 2000 - 2023, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.17  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "acdebug.h"
     47       1.1    jruoho #include "acnamesp.h"
     48       1.1    jruoho 
     49       1.1    jruoho 
     50       1.1    jruoho #define _COMPONENT          ACPI_CA_DEBUGGER
     51       1.1    jruoho         ACPI_MODULE_NAME    ("dbexec")
     52       1.1    jruoho 
     53       1.1    jruoho 
     54   1.1.1.3    jruoho static ACPI_DB_METHOD_INFO          AcpiGbl_DbMethodInfo;
     55       1.1    jruoho 
     56       1.1    jruoho /* Local prototypes */
     57       1.1    jruoho 
     58       1.1    jruoho static ACPI_STATUS
     59       1.1    jruoho AcpiDbExecuteMethod (
     60       1.1    jruoho     ACPI_DB_METHOD_INFO     *Info,
     61       1.1    jruoho     ACPI_BUFFER             *ReturnObj);
     62       1.1    jruoho 
     63   1.1.1.4  christos static ACPI_STATUS
     64       1.1    jruoho AcpiDbExecuteSetup (
     65       1.1    jruoho     ACPI_DB_METHOD_INFO     *Info);
     66       1.1    jruoho 
     67       1.1    jruoho static UINT32
     68       1.1    jruoho AcpiDbGetOutstandingAllocations (
     69       1.1    jruoho     void);
     70       1.1    jruoho 
     71       1.1    jruoho static void ACPI_SYSTEM_XFACE
     72       1.1    jruoho AcpiDbMethodThread (
     73       1.1    jruoho     void                    *Context);
     74       1.1    jruoho 
     75       1.1    jruoho static ACPI_STATUS
     76       1.1    jruoho AcpiDbExecutionWalk (
     77       1.1    jruoho     ACPI_HANDLE             ObjHandle,
     78       1.1    jruoho     UINT32                  NestingLevel,
     79       1.1    jruoho     void                    *Context,
     80       1.1    jruoho     void                    **ReturnValue);
     81       1.1    jruoho 
     82  1.1.1.12  christos static void ACPI_SYSTEM_XFACE
     83  1.1.1.12  christos AcpiDbSingleExecutionThread (
     84  1.1.1.12  christos     void                    *Context);
     85  1.1.1.12  christos 
     86   1.1.1.3    jruoho 
     87   1.1.1.3    jruoho /*******************************************************************************
     88   1.1.1.3    jruoho  *
     89   1.1.1.3    jruoho  * FUNCTION:    AcpiDbDeleteObjects
     90   1.1.1.3    jruoho  *
     91   1.1.1.3    jruoho  * PARAMETERS:  Count               - Count of objects in the list
     92   1.1.1.3    jruoho  *              Objects             - Array of ACPI_OBJECTs to be deleted
     93   1.1.1.3    jruoho  *
     94   1.1.1.3    jruoho  * RETURN:      None
     95   1.1.1.3    jruoho  *
     96   1.1.1.3    jruoho  * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
     97   1.1.1.3    jruoho  *              packages via recursion.
     98   1.1.1.3    jruoho  *
     99   1.1.1.3    jruoho  ******************************************************************************/
    100   1.1.1.3    jruoho 
    101   1.1.1.4  christos void
    102   1.1.1.3    jruoho AcpiDbDeleteObjects (
    103   1.1.1.3    jruoho     UINT32                  Count,
    104   1.1.1.3    jruoho     ACPI_OBJECT             *Objects)
    105   1.1.1.3    jruoho {
    106   1.1.1.3    jruoho     UINT32                  i;
    107   1.1.1.3    jruoho 
    108   1.1.1.3    jruoho 
    109   1.1.1.3    jruoho     for (i = 0; i < Count; i++)
    110   1.1.1.3    jruoho     {
    111   1.1.1.3    jruoho         switch (Objects[i].Type)
    112   1.1.1.3    jruoho         {
    113   1.1.1.3    jruoho         case ACPI_TYPE_BUFFER:
    114   1.1.1.4  christos 
    115   1.1.1.3    jruoho             ACPI_FREE (Objects[i].Buffer.Pointer);
    116   1.1.1.3    jruoho             break;
    117   1.1.1.3    jruoho 
    118   1.1.1.3    jruoho         case ACPI_TYPE_PACKAGE:
    119   1.1.1.3    jruoho 
    120   1.1.1.3    jruoho             /* Recursive call to delete package elements */
    121   1.1.1.3    jruoho 
    122   1.1.1.3    jruoho             AcpiDbDeleteObjects (Objects[i].Package.Count,
    123   1.1.1.3    jruoho                 Objects[i].Package.Elements);
    124   1.1.1.3    jruoho 
    125   1.1.1.3    jruoho             /* Free the elements array */
    126   1.1.1.3    jruoho 
    127   1.1.1.3    jruoho             ACPI_FREE (Objects[i].Package.Elements);
    128   1.1.1.3    jruoho             break;
    129   1.1.1.3    jruoho 
    130   1.1.1.3    jruoho         default:
    131   1.1.1.4  christos 
    132   1.1.1.3    jruoho             break;
    133   1.1.1.3    jruoho         }
    134   1.1.1.3    jruoho     }
    135   1.1.1.3    jruoho }
    136   1.1.1.3    jruoho 
    137       1.1    jruoho 
    138       1.1    jruoho /*******************************************************************************
    139       1.1    jruoho  *
    140       1.1    jruoho  * FUNCTION:    AcpiDbExecuteMethod
    141       1.1    jruoho  *
    142       1.1    jruoho  * PARAMETERS:  Info            - Valid info segment
    143       1.1    jruoho  *              ReturnObj       - Where to put return object
    144       1.1    jruoho  *
    145       1.1    jruoho  * RETURN:      Status
    146       1.1    jruoho  *
    147  1.1.1.16  christos  * DESCRIPTION: Execute a control method. Used to evaluate objects via the
    148  1.1.1.16  christos  *              "EXECUTE" or "EVALUATE" commands.
    149       1.1    jruoho  *
    150       1.1    jruoho  ******************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho static ACPI_STATUS
    153       1.1    jruoho AcpiDbExecuteMethod (
    154       1.1    jruoho     ACPI_DB_METHOD_INFO     *Info,
    155       1.1    jruoho     ACPI_BUFFER             *ReturnObj)
    156       1.1    jruoho {
    157       1.1    jruoho     ACPI_STATUS             Status;
    158       1.1    jruoho     ACPI_OBJECT_LIST        ParamObjects;
    159   1.1.1.4  christos     ACPI_OBJECT             Params[ACPI_DEBUGGER_MAX_ARGS + 1];
    160   1.1.1.3    jruoho     UINT32                  i;
    161       1.1    jruoho 
    162       1.1    jruoho 
    163   1.1.1.2    jruoho     ACPI_FUNCTION_TRACE (DbExecuteMethod);
    164   1.1.1.2    jruoho 
    165   1.1.1.2    jruoho 
    166       1.1    jruoho     if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
    167       1.1    jruoho     {
    168       1.1    jruoho         AcpiOsPrintf ("Warning: debug output is not enabled!\n");
    169       1.1    jruoho     }
    170       1.1    jruoho 
    171   1.1.1.4  christos     ParamObjects.Count = 0;
    172       1.1    jruoho     ParamObjects.Pointer = NULL;
    173       1.1    jruoho 
    174   1.1.1.4  christos     /* Pass through any command-line arguments */
    175       1.1    jruoho 
    176   1.1.1.4  christos     if (Info->Args && Info->Args[0])
    177   1.1.1.4  christos     {
    178   1.1.1.4  christos         /* Get arguments passed on the command line */
    179   1.1.1.3    jruoho 
    180   1.1.1.4  christos         for (i = 0; (Info->Args[i] && *(Info->Args[i])); i++)
    181       1.1    jruoho         {
    182   1.1.1.4  christos             /* Convert input string (token) to an actual ACPI_OBJECT */
    183       1.1    jruoho 
    184   1.1.1.4  christos             Status = AcpiDbConvertToObject (Info->Types[i],
    185   1.1.1.4  christos                 Info->Args[i], &Params[i]);
    186   1.1.1.4  christos             if (ACPI_FAILURE (Status))
    187       1.1    jruoho             {
    188   1.1.1.4  christos                 ACPI_EXCEPTION ((AE_INFO, Status,
    189   1.1.1.4  christos                     "While parsing method arguments"));
    190   1.1.1.4  christos                 goto Cleanup;
    191       1.1    jruoho             }
    192       1.1    jruoho         }
    193       1.1    jruoho 
    194   1.1.1.4  christos         ParamObjects.Count = i;
    195   1.1.1.3    jruoho         ParamObjects.Pointer = Params;
    196   1.1.1.3    jruoho     }
    197       1.1    jruoho 
    198       1.1    jruoho     /* Prepare for a return object of arbitrary size */
    199       1.1    jruoho 
    200       1.1    jruoho     ReturnObj->Pointer = AcpiGbl_DbBuffer;
    201       1.1    jruoho     ReturnObj->Length  = ACPI_DEBUG_BUFFER_SIZE;
    202       1.1    jruoho 
    203       1.1    jruoho     /* Do the actual method execution */
    204       1.1    jruoho 
    205       1.1    jruoho     AcpiGbl_MethodExecuting = TRUE;
    206   1.1.1.4  christos     Status = AcpiEvaluateObject (NULL, Info->Pathname,
    207   1.1.1.4  christos         &ParamObjects, ReturnObj);
    208       1.1    jruoho 
    209       1.1    jruoho     AcpiGbl_CmSingleStep = FALSE;
    210       1.1    jruoho     AcpiGbl_MethodExecuting = FALSE;
    211       1.1    jruoho 
    212   1.1.1.2    jruoho     if (ACPI_FAILURE (Status))
    213   1.1.1.2    jruoho     {
    214  1.1.1.11  christos         if ((Status == AE_ABORT_METHOD) || AcpiGbl_AbortMethod)
    215  1.1.1.11  christos         {
    216  1.1.1.11  christos             /* Clear the abort and fall back to the debugger prompt */
    217  1.1.1.11  christos 
    218  1.1.1.11  christos             ACPI_EXCEPTION ((AE_INFO, Status,
    219  1.1.1.11  christos                 "Aborting top-level method"));
    220  1.1.1.11  christos 
    221  1.1.1.11  christos             AcpiGbl_AbortMethod = FALSE;
    222  1.1.1.11  christos             Status = AE_OK;
    223  1.1.1.11  christos             goto Cleanup;
    224  1.1.1.11  christos         }
    225  1.1.1.11  christos 
    226   1.1.1.2    jruoho         ACPI_EXCEPTION ((AE_INFO, Status,
    227  1.1.1.14  christos             "while executing %s from AML Debugger", Info->Pathname));
    228   1.1.1.2    jruoho 
    229   1.1.1.2    jruoho         if (Status == AE_BUFFER_OVERFLOW)
    230   1.1.1.2    jruoho         {
    231   1.1.1.2    jruoho             ACPI_ERROR ((AE_INFO,
    232  1.1.1.14  christos                 "Possible buffer overflow within AML Debugger "
    233   1.1.1.8  christos                 "buffer (size 0x%X needed 0x%X)",
    234   1.1.1.2    jruoho                 ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length));
    235   1.1.1.2    jruoho         }
    236   1.1.1.2    jruoho     }
    237   1.1.1.2    jruoho 
    238   1.1.1.3    jruoho Cleanup:
    239   1.1.1.4  christos     AcpiDbDeleteObjects (ParamObjects.Count, Params);
    240   1.1.1.2    jruoho     return_ACPI_STATUS (Status);
    241       1.1    jruoho }
    242       1.1    jruoho 
    243       1.1    jruoho 
    244       1.1    jruoho /*******************************************************************************
    245       1.1    jruoho  *
    246       1.1    jruoho  * FUNCTION:    AcpiDbExecuteSetup
    247       1.1    jruoho  *
    248       1.1    jruoho  * PARAMETERS:  Info            - Valid method info
    249       1.1    jruoho  *
    250       1.1    jruoho  * RETURN:      None
    251       1.1    jruoho  *
    252       1.1    jruoho  * DESCRIPTION: Setup info segment prior to method execution
    253       1.1    jruoho  *
    254       1.1    jruoho  ******************************************************************************/
    255       1.1    jruoho 
    256   1.1.1.4  christos static ACPI_STATUS
    257       1.1    jruoho AcpiDbExecuteSetup (
    258       1.1    jruoho     ACPI_DB_METHOD_INFO     *Info)
    259       1.1    jruoho {
    260   1.1.1.4  christos     ACPI_STATUS             Status;
    261   1.1.1.4  christos 
    262   1.1.1.4  christos 
    263   1.1.1.4  christos     ACPI_FUNCTION_NAME (DbExecuteSetup);
    264   1.1.1.4  christos 
    265       1.1    jruoho 
    266  1.1.1.12  christos     /* Concatenate the current scope to the supplied name */
    267       1.1    jruoho 
    268       1.1    jruoho     Info->Pathname[0] = 0;
    269       1.1    jruoho     if ((Info->Name[0] != '\\') &&
    270       1.1    jruoho         (Info->Name[0] != '/'))
    271       1.1    jruoho     {
    272   1.1.1.4  christos         if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
    273   1.1.1.4  christos             AcpiGbl_DbScopeBuf))
    274   1.1.1.4  christos         {
    275   1.1.1.4  christos             Status = AE_BUFFER_OVERFLOW;
    276   1.1.1.4  christos             goto ErrorExit;
    277   1.1.1.4  christos         }
    278   1.1.1.4  christos     }
    279   1.1.1.4  christos 
    280   1.1.1.4  christos     if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
    281   1.1.1.4  christos         Info->Name))
    282   1.1.1.4  christos     {
    283   1.1.1.4  christos         Status = AE_BUFFER_OVERFLOW;
    284   1.1.1.4  christos         goto ErrorExit;
    285       1.1    jruoho     }
    286       1.1    jruoho 
    287       1.1    jruoho     AcpiDbPrepNamestring (Info->Pathname);
    288       1.1    jruoho 
    289       1.1    jruoho     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
    290   1.1.1.4  christos     AcpiOsPrintf ("Evaluating %s\n", Info->Pathname);
    291       1.1    jruoho 
    292       1.1    jruoho     if (Info->Flags & EX_SINGLE_STEP)
    293       1.1    jruoho     {
    294       1.1    jruoho         AcpiGbl_CmSingleStep = TRUE;
    295       1.1    jruoho         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
    296       1.1    jruoho     }
    297       1.1    jruoho 
    298       1.1    jruoho     else
    299       1.1    jruoho     {
    300       1.1    jruoho         /* No single step, allow redirection to a file */
    301       1.1    jruoho 
    302       1.1    jruoho         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
    303       1.1    jruoho     }
    304   1.1.1.4  christos 
    305   1.1.1.4  christos     return (AE_OK);
    306   1.1.1.4  christos 
    307   1.1.1.4  christos ErrorExit:
    308   1.1.1.4  christos 
    309   1.1.1.4  christos     ACPI_EXCEPTION ((AE_INFO, Status, "During setup for method execution"));
    310   1.1.1.4  christos     return (Status);
    311       1.1    jruoho }
    312       1.1    jruoho 
    313       1.1    jruoho 
    314       1.1    jruoho #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    315       1.1    jruoho UINT32
    316       1.1    jruoho AcpiDbGetCacheInfo (
    317       1.1    jruoho     ACPI_MEMORY_LIST        *Cache)
    318       1.1    jruoho {
    319       1.1    jruoho 
    320       1.1    jruoho     return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
    321       1.1    jruoho }
    322       1.1    jruoho #endif
    323       1.1    jruoho 
    324       1.1    jruoho /*******************************************************************************
    325       1.1    jruoho  *
    326       1.1    jruoho  * FUNCTION:    AcpiDbGetOutstandingAllocations
    327       1.1    jruoho  *
    328       1.1    jruoho  * PARAMETERS:  None
    329       1.1    jruoho  *
    330       1.1    jruoho  * RETURN:      Current global allocation count minus cache entries
    331       1.1    jruoho  *
    332       1.1    jruoho  * DESCRIPTION: Determine the current number of "outstanding" allocations --
    333       1.1    jruoho  *              those allocations that have not been freed and also are not
    334       1.1    jruoho  *              in one of the various object caches.
    335       1.1    jruoho  *
    336       1.1    jruoho  ******************************************************************************/
    337       1.1    jruoho 
    338       1.1    jruoho static UINT32
    339       1.1    jruoho AcpiDbGetOutstandingAllocations (
    340       1.1    jruoho     void)
    341       1.1    jruoho {
    342       1.1    jruoho     UINT32                  Outstanding = 0;
    343       1.1    jruoho 
    344       1.1    jruoho #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    345       1.1    jruoho 
    346       1.1    jruoho     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
    347       1.1    jruoho     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
    348       1.1    jruoho     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
    349       1.1    jruoho     Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
    350       1.1    jruoho #endif
    351       1.1    jruoho 
    352       1.1    jruoho     return (Outstanding);
    353       1.1    jruoho }
    354       1.1    jruoho 
    355       1.1    jruoho 
    356       1.1    jruoho /*******************************************************************************
    357       1.1    jruoho  *
    358       1.1    jruoho  * FUNCTION:    AcpiDbExecutionWalk
    359       1.1    jruoho  *
    360       1.1    jruoho  * PARAMETERS:  WALK_CALLBACK
    361       1.1    jruoho  *
    362       1.1    jruoho  * RETURN:      Status
    363       1.1    jruoho  *
    364   1.1.1.4  christos  * DESCRIPTION: Execute a control method. Name is relative to the current
    365       1.1    jruoho  *              scope.
    366       1.1    jruoho  *
    367       1.1    jruoho  ******************************************************************************/
    368       1.1    jruoho 
    369       1.1    jruoho static ACPI_STATUS
    370       1.1    jruoho AcpiDbExecutionWalk (
    371       1.1    jruoho     ACPI_HANDLE             ObjHandle,
    372       1.1    jruoho     UINT32                  NestingLevel,
    373       1.1    jruoho     void                    *Context,
    374       1.1    jruoho     void                    **ReturnValue)
    375       1.1    jruoho {
    376       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    377       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    378       1.1    jruoho     ACPI_BUFFER             ReturnObj;
    379       1.1    jruoho     ACPI_STATUS             Status;
    380       1.1    jruoho 
    381       1.1    jruoho 
    382       1.1    jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
    383       1.1    jruoho     if (ObjDesc->Method.ParamCount)
    384       1.1    jruoho     {
    385       1.1    jruoho         return (AE_OK);
    386       1.1    jruoho     }
    387       1.1    jruoho 
    388       1.1    jruoho     ReturnObj.Pointer = NULL;
    389       1.1    jruoho     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    390       1.1    jruoho 
    391   1.1.1.4  christos     AcpiNsPrintNodePathname (Node, "Evaluating");
    392       1.1    jruoho 
    393       1.1    jruoho     /* Do the actual method execution */
    394       1.1    jruoho 
    395       1.1    jruoho     AcpiOsPrintf ("\n");
    396       1.1    jruoho     AcpiGbl_MethodExecuting = TRUE;
    397       1.1    jruoho 
    398       1.1    jruoho     Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
    399       1.1    jruoho 
    400  1.1.1.16  christos     AcpiGbl_MethodExecuting = FALSE;
    401  1.1.1.16  christos 
    402   1.1.1.8  christos     AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n",
    403   1.1.1.8  christos         AcpiUtGetNodeName (Node),
    404   1.1.1.8  christos         AcpiFormatException (Status));
    405       1.1    jruoho 
    406       1.1    jruoho     return (AE_OK);
    407       1.1    jruoho }
    408       1.1    jruoho 
    409       1.1    jruoho 
    410       1.1    jruoho /*******************************************************************************
    411       1.1    jruoho  *
    412       1.1    jruoho  * FUNCTION:    AcpiDbExecute
    413       1.1    jruoho  *
    414       1.1    jruoho  * PARAMETERS:  Name                - Name of method to execute
    415       1.1    jruoho  *              Args                - Parameters to the method
    416   1.1.1.8  christos  *              Types               -
    417       1.1    jruoho  *              Flags               - single step/no single step
    418       1.1    jruoho  *
    419       1.1    jruoho  * RETURN:      None
    420       1.1    jruoho  *
    421   1.1.1.4  christos  * DESCRIPTION: Execute a control method. Name is relative to the current
    422  1.1.1.16  christos  *              scope. Function used for the "EXECUTE", "EVALUATE", and
    423  1.1.1.16  christos  *              "ALL" commands
    424       1.1    jruoho  *
    425       1.1    jruoho  ******************************************************************************/
    426       1.1    jruoho 
    427       1.1    jruoho void
    428       1.1    jruoho AcpiDbExecute (
    429       1.1    jruoho     char                    *Name,
    430       1.1    jruoho     char                    **Args,
    431   1.1.1.3    jruoho     ACPI_OBJECT_TYPE        *Types,
    432       1.1    jruoho     UINT32                  Flags)
    433       1.1    jruoho {
    434       1.1    jruoho     ACPI_STATUS             Status;
    435       1.1    jruoho     ACPI_BUFFER             ReturnObj;
    436       1.1    jruoho     char                    *NameString;
    437       1.1    jruoho 
    438       1.1    jruoho #ifdef ACPI_DEBUG_OUTPUT
    439       1.1    jruoho     UINT32                  PreviousAllocations;
    440       1.1    jruoho     UINT32                  Allocations;
    441   1.1.1.8  christos #endif
    442       1.1    jruoho 
    443       1.1    jruoho 
    444   1.1.1.8  christos     /*
    445   1.1.1.8  christos      * Allow one execution to be performed by debugger or single step
    446   1.1.1.8  christos      * execution will be dead locked by the interpreter mutexes.
    447   1.1.1.8  christos      */
    448   1.1.1.8  christos     if (AcpiGbl_MethodExecuting)
    449   1.1.1.8  christos     {
    450   1.1.1.8  christos         AcpiOsPrintf ("Only one debugger execution is allowed.\n");
    451   1.1.1.8  christos         return;
    452   1.1.1.8  christos     }
    453   1.1.1.8  christos 
    454   1.1.1.8  christos #ifdef ACPI_DEBUG_OUTPUT
    455       1.1    jruoho     /* Memory allocation tracking */
    456       1.1    jruoho 
    457       1.1    jruoho     PreviousAllocations = AcpiDbGetOutstandingAllocations ();
    458       1.1    jruoho #endif
    459       1.1    jruoho 
    460       1.1    jruoho     if (*Name == '*')
    461       1.1    jruoho     {
    462       1.1    jruoho         (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
    463   1.1.1.8  christos             ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
    464       1.1    jruoho         return;
    465       1.1    jruoho     }
    466   1.1.1.9  christos 
    467  1.1.1.16  christos     if ((Flags & EX_ALL) && (strlen (Name) > 4))
    468  1.1.1.16  christos     {
    469  1.1.1.16  christos         AcpiOsPrintf ("Input name (%s) must be a 4-char NameSeg\n", Name);
    470  1.1.1.16  christos         return;
    471  1.1.1.16  christos     }
    472  1.1.1.16  christos 
    473   1.1.1.9  christos     NameString = ACPI_ALLOCATE (strlen (Name) + 1);
    474   1.1.1.9  christos     if (!NameString)
    475       1.1    jruoho     {
    476   1.1.1.9  christos         return;
    477   1.1.1.9  christos     }
    478       1.1    jruoho 
    479   1.1.1.9  christos     memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
    480   1.1.1.9  christos     strcpy (NameString, Name);
    481   1.1.1.9  christos     AcpiUtStrupr (NameString);
    482       1.1    jruoho 
    483   1.1.1.9  christos     /* Subcommand to Execute all predefined names in the namespace */
    484       1.1    jruoho 
    485   1.1.1.9  christos     if (!strncmp (NameString, "PREDEF", 6))
    486   1.1.1.9  christos     {
    487   1.1.1.9  christos         AcpiDbEvaluatePredefinedNames ();
    488   1.1.1.9  christos         ACPI_FREE (NameString);
    489   1.1.1.9  christos         return;
    490   1.1.1.9  christos     }
    491       1.1    jruoho 
    492  1.1.1.16  christos     /* Command (ALL <nameseg>) to execute all methods of a particular name */
    493   1.1.1.4  christos 
    494  1.1.1.16  christos     else if (Flags & EX_ALL)
    495  1.1.1.16  christos     {
    496  1.1.1.16  christos         AcpiGbl_DbMethodInfo.Name = NameString;
    497  1.1.1.16  christos         ReturnObj.Pointer = NULL;
    498  1.1.1.16  christos         ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    499  1.1.1.16  christos         AcpiDbEvaluateAll (NameString);
    500  1.1.1.16  christos         ACPI_FREE (NameString);
    501  1.1.1.16  christos         return;
    502  1.1.1.16  christos     }
    503  1.1.1.16  christos     else
    504  1.1.1.16  christos     {
    505  1.1.1.16  christos         AcpiGbl_DbMethodInfo.Name = NameString;
    506  1.1.1.16  christos         AcpiGbl_DbMethodInfo.Args = Args;
    507  1.1.1.16  christos         AcpiGbl_DbMethodInfo.Types = Types;
    508  1.1.1.16  christos         AcpiGbl_DbMethodInfo.Flags = Flags;
    509  1.1.1.16  christos 
    510  1.1.1.16  christos         ReturnObj.Pointer = NULL;
    511  1.1.1.16  christos         ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    512  1.1.1.16  christos     }
    513   1.1.1.4  christos 
    514   1.1.1.9  christos     Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
    515   1.1.1.9  christos     if (ACPI_FAILURE (Status))
    516   1.1.1.9  christos     {
    517       1.1    jruoho         ACPI_FREE (NameString);
    518   1.1.1.9  christos         return;
    519   1.1.1.9  christos     }
    520   1.1.1.9  christos 
    521   1.1.1.9  christos     /* Get the NS node, determines existence also */
    522   1.1.1.9  christos 
    523   1.1.1.9  christos     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
    524   1.1.1.9  christos         &AcpiGbl_DbMethodInfo.Method);
    525   1.1.1.9  christos     if (ACPI_SUCCESS (Status))
    526   1.1.1.9  christos     {
    527   1.1.1.9  christos         Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo,
    528   1.1.1.9  christos             &ReturnObj);
    529       1.1    jruoho     }
    530   1.1.1.9  christos     ACPI_FREE (NameString);
    531       1.1    jruoho 
    532       1.1    jruoho     /*
    533       1.1    jruoho      * Allow any handlers in separate threads to complete.
    534       1.1    jruoho      * (Such as Notify handlers invoked from AML executed above).
    535       1.1    jruoho      */
    536       1.1    jruoho     AcpiOsSleep ((UINT64) 10);
    537       1.1    jruoho 
    538       1.1    jruoho #ifdef ACPI_DEBUG_OUTPUT
    539       1.1    jruoho 
    540       1.1    jruoho     /* Memory allocation tracking */
    541       1.1    jruoho 
    542       1.1    jruoho     Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
    543       1.1    jruoho 
    544       1.1    jruoho     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
    545       1.1    jruoho 
    546       1.1    jruoho     if (Allocations > 0)
    547       1.1    jruoho     {
    548   1.1.1.8  christos         AcpiOsPrintf (
    549   1.1.1.8  christos             "0x%X Outstanding allocations after evaluation of %s\n",
    550   1.1.1.8  christos             Allocations, AcpiGbl_DbMethodInfo.Pathname);
    551       1.1    jruoho     }
    552       1.1    jruoho #endif
    553       1.1    jruoho 
    554       1.1    jruoho     if (ACPI_FAILURE (Status))
    555       1.1    jruoho     {
    556   1.1.1.4  christos         AcpiOsPrintf ("Evaluation of %s failed with status %s\n",
    557   1.1.1.8  christos             AcpiGbl_DbMethodInfo.Pathname,
    558   1.1.1.8  christos             AcpiFormatException (Status));
    559       1.1    jruoho     }
    560       1.1    jruoho     else
    561       1.1    jruoho     {
    562       1.1    jruoho         /* Display a return object, if any */
    563       1.1    jruoho 
    564       1.1    jruoho         if (ReturnObj.Length)
    565       1.1    jruoho         {
    566   1.1.1.4  christos             AcpiOsPrintf (
    567   1.1.1.8  christos                 "Evaluation of %s returned object %p, "
    568   1.1.1.8  christos                 "external buffer length %X\n",
    569       1.1    jruoho                 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
    570       1.1    jruoho                 (UINT32) ReturnObj.Length);
    571   1.1.1.8  christos 
    572       1.1    jruoho             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
    573  1.1.1.16  christos             AcpiOsPrintf ("\n");
    574   1.1.1.4  christos 
    575   1.1.1.4  christos             /* Dump a _PLD buffer if present */
    576   1.1.1.4  christos 
    577  1.1.1.14  christos             if (ACPI_COMPARE_NAMESEG ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
    578   1.1.1.8  christos                 AcpiGbl_DbMethodInfo.Method)->Name.Ascii),
    579   1.1.1.8  christos                 METHOD_NAME__PLD))
    580   1.1.1.4  christos             {
    581   1.1.1.4  christos                 AcpiDbDumpPldBuffer (ReturnObj.Pointer);
    582   1.1.1.4  christos             }
    583       1.1    jruoho         }
    584       1.1    jruoho         else
    585       1.1    jruoho         {
    586   1.1.1.4  christos             AcpiOsPrintf ("No object was returned from evaluation of %s\n",
    587       1.1    jruoho                 AcpiGbl_DbMethodInfo.Pathname);
    588       1.1    jruoho         }
    589       1.1    jruoho     }
    590       1.1    jruoho 
    591       1.1    jruoho     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
    592       1.1    jruoho }
    593       1.1    jruoho 
    594       1.1    jruoho 
    595       1.1    jruoho /*******************************************************************************
    596       1.1    jruoho  *
    597       1.1    jruoho  * FUNCTION:    AcpiDbMethodThread
    598       1.1    jruoho  *
    599       1.1    jruoho  * PARAMETERS:  Context             - Execution info segment
    600       1.1    jruoho  *
    601       1.1    jruoho  * RETURN:      None
    602       1.1    jruoho  *
    603   1.1.1.4  christos  * DESCRIPTION: Debugger execute thread. Waits for a command line, then
    604       1.1    jruoho  *              simply dispatches it.
    605       1.1    jruoho  *
    606       1.1    jruoho  ******************************************************************************/
    607       1.1    jruoho 
    608       1.1    jruoho static void ACPI_SYSTEM_XFACE
    609       1.1    jruoho AcpiDbMethodThread (
    610       1.1    jruoho     void                    *Context)
    611       1.1    jruoho {
    612       1.1    jruoho     ACPI_STATUS             Status;
    613       1.1    jruoho     ACPI_DB_METHOD_INFO     *Info = Context;
    614       1.1    jruoho     ACPI_DB_METHOD_INFO     LocalInfo;
    615       1.1    jruoho     UINT32                  i;
    616       1.1    jruoho     UINT8                   Allow;
    617       1.1    jruoho     ACPI_BUFFER             ReturnObj;
    618       1.1    jruoho 
    619       1.1    jruoho 
    620       1.1    jruoho     /*
    621       1.1    jruoho      * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
    622       1.1    jruoho      * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
    623       1.1    jruoho      * concurrently.
    624       1.1    jruoho      *
    625       1.1    jruoho      * Note: The arguments we are passing are used by the ASL test suite
    626       1.1    jruoho      * (aslts). Do not change them without updating the tests.
    627       1.1    jruoho      */
    628       1.1    jruoho     (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
    629       1.1    jruoho 
    630       1.1    jruoho     if (Info->InitArgs)
    631       1.1    jruoho     {
    632   1.1.1.8  christos         AcpiDbUint32ToHexString (Info->NumCreated,
    633   1.1.1.8  christos             Info->IndexOfThreadStr);
    634   1.1.1.8  christos         AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (),
    635   1.1.1.8  christos             Info->IdOfThreadStr);
    636       1.1    jruoho     }
    637       1.1    jruoho 
    638       1.1    jruoho     if (Info->Threads && (Info->NumCreated < Info->NumThreads))
    639       1.1    jruoho     {
    640   1.1.1.2    jruoho         Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
    641       1.1    jruoho     }
    642       1.1    jruoho 
    643       1.1    jruoho     LocalInfo = *Info;
    644       1.1    jruoho     LocalInfo.Args = LocalInfo.Arguments;
    645       1.1    jruoho     LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
    646       1.1    jruoho     LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
    647       1.1    jruoho     LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
    648       1.1    jruoho     LocalInfo.Arguments[3] = NULL;
    649       1.1    jruoho 
    650   1.1.1.3    jruoho     LocalInfo.Types = LocalInfo.ArgTypes;
    651   1.1.1.3    jruoho 
    652       1.1    jruoho     (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
    653       1.1    jruoho 
    654       1.1    jruoho     for (i = 0; i < Info->NumLoops; i++)
    655       1.1    jruoho     {
    656       1.1    jruoho         Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
    657       1.1    jruoho         if (ACPI_FAILURE (Status))
    658       1.1    jruoho         {
    659   1.1.1.4  christos             AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n",
    660       1.1    jruoho                 AcpiFormatException (Status), Info->Pathname, i);
    661       1.1    jruoho             if (Status == AE_ABORT_METHOD)
    662       1.1    jruoho             {
    663       1.1    jruoho                 break;
    664       1.1    jruoho             }
    665       1.1    jruoho         }
    666       1.1    jruoho 
    667       1.1    jruoho #if 0
    668       1.1    jruoho         if ((i % 100) == 0)
    669       1.1    jruoho         {
    670   1.1.1.8  christos             AcpiOsPrintf ("%u loops, Thread 0x%x\n",
    671   1.1.1.8  christos                 i, AcpiOsGetThreadId ());
    672       1.1    jruoho         }
    673       1.1    jruoho 
    674       1.1    jruoho         if (ReturnObj.Length)
    675       1.1    jruoho         {
    676   1.1.1.4  christos             AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n",
    677   1.1.1.8  christos                 Info->Pathname, ReturnObj.Pointer,
    678   1.1.1.8  christos                 (UINT32) ReturnObj.Length);
    679       1.1    jruoho             AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
    680       1.1    jruoho         }
    681       1.1    jruoho #endif
    682       1.1    jruoho     }
    683       1.1    jruoho 
    684       1.1    jruoho     /* Signal our completion */
    685       1.1    jruoho 
    686       1.1    jruoho     Allow = 0;
    687   1.1.1.8  christos     (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate,
    688   1.1.1.8  christos         1, ACPI_WAIT_FOREVER);
    689       1.1    jruoho     Info->NumCompleted++;
    690       1.1    jruoho 
    691       1.1    jruoho     if (Info->NumCompleted == Info->NumThreads)
    692       1.1    jruoho     {
    693       1.1    jruoho         /* Do signal for main thread once only */
    694       1.1    jruoho         Allow = 1;
    695       1.1    jruoho     }
    696       1.1    jruoho 
    697       1.1    jruoho     (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
    698       1.1    jruoho 
    699       1.1    jruoho     if (Allow)
    700       1.1    jruoho     {
    701       1.1    jruoho         Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
    702       1.1    jruoho         if (ACPI_FAILURE (Status))
    703       1.1    jruoho         {
    704   1.1.1.8  christos             AcpiOsPrintf (
    705   1.1.1.8  christos                 "Could not signal debugger thread sync semaphore, %s\n",
    706       1.1    jruoho                 AcpiFormatException (Status));
    707       1.1    jruoho         }
    708       1.1    jruoho     }
    709       1.1    jruoho }
    710       1.1    jruoho 
    711       1.1    jruoho 
    712       1.1    jruoho /*******************************************************************************
    713       1.1    jruoho  *
    714  1.1.1.12  christos  * FUNCTION:    AcpiDbSingleExecutionThread
    715  1.1.1.12  christos  *
    716  1.1.1.12  christos  * PARAMETERS:  Context                 - Method info struct
    717  1.1.1.12  christos  *
    718  1.1.1.12  christos  * RETURN:      None
    719  1.1.1.12  christos  *
    720  1.1.1.12  christos  * DESCRIPTION: Create one thread and execute a method
    721  1.1.1.12  christos  *
    722  1.1.1.12  christos  ******************************************************************************/
    723  1.1.1.12  christos 
    724  1.1.1.12  christos static void ACPI_SYSTEM_XFACE
    725  1.1.1.12  christos AcpiDbSingleExecutionThread (
    726  1.1.1.12  christos     void                    *Context)
    727  1.1.1.12  christos {
    728  1.1.1.12  christos     ACPI_DB_METHOD_INFO     *Info = Context;
    729  1.1.1.12  christos     ACPI_STATUS             Status;
    730  1.1.1.12  christos     ACPI_BUFFER             ReturnObj;
    731  1.1.1.12  christos 
    732  1.1.1.12  christos 
    733  1.1.1.12  christos     AcpiOsPrintf ("\n");
    734  1.1.1.12  christos 
    735  1.1.1.12  christos     Status = AcpiDbExecuteMethod (Info, &ReturnObj);
    736  1.1.1.12  christos     if (ACPI_FAILURE (Status))
    737  1.1.1.12  christos     {
    738  1.1.1.12  christos         AcpiOsPrintf ("%s During evaluation of %s\n",
    739  1.1.1.12  christos             AcpiFormatException (Status), Info->Pathname);
    740  1.1.1.12  christos         return;
    741  1.1.1.12  christos     }
    742  1.1.1.12  christos 
    743  1.1.1.12  christos     /* Display a return object, if any */
    744  1.1.1.12  christos 
    745  1.1.1.12  christos     if (ReturnObj.Length)
    746  1.1.1.12  christos     {
    747  1.1.1.12  christos         AcpiOsPrintf ("Evaluation of %s returned object %p, "
    748  1.1.1.12  christos             "external buffer length %X\n",
    749  1.1.1.12  christos             AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
    750  1.1.1.12  christos             (UINT32) ReturnObj.Length);
    751  1.1.1.12  christos 
    752  1.1.1.12  christos         AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
    753  1.1.1.12  christos     }
    754  1.1.1.12  christos 
    755  1.1.1.12  christos     AcpiOsPrintf ("\nBackground thread completed\n%c ",
    756  1.1.1.12  christos         ACPI_DEBUGGER_COMMAND_PROMPT);
    757  1.1.1.12  christos }
    758  1.1.1.12  christos 
    759  1.1.1.12  christos 
    760  1.1.1.12  christos /*******************************************************************************
    761  1.1.1.12  christos  *
    762  1.1.1.12  christos  * FUNCTION:    AcpiDbCreateExecutionThread
    763  1.1.1.12  christos  *
    764  1.1.1.12  christos  * PARAMETERS:  MethodNameArg           - Control method to execute
    765  1.1.1.12  christos  *              Arguments               - Array of arguments to the method
    766  1.1.1.12  christos  *              Types                   - Corresponding array of object types
    767  1.1.1.12  christos  *
    768  1.1.1.12  christos  * RETURN:      None
    769  1.1.1.12  christos  *
    770  1.1.1.12  christos  * DESCRIPTION: Create a single thread to evaluate a namespace object. Handles
    771  1.1.1.12  christos  *              arguments passed on command line for control methods.
    772  1.1.1.12  christos  *
    773  1.1.1.12  christos  ******************************************************************************/
    774  1.1.1.12  christos 
    775  1.1.1.12  christos void
    776  1.1.1.12  christos AcpiDbCreateExecutionThread (
    777  1.1.1.12  christos     char                    *MethodNameArg,
    778  1.1.1.12  christos     char                    **Arguments,
    779  1.1.1.12  christos     ACPI_OBJECT_TYPE        *Types)
    780  1.1.1.12  christos {
    781  1.1.1.12  christos     ACPI_STATUS             Status;
    782  1.1.1.12  christos     UINT32                  i;
    783  1.1.1.12  christos 
    784  1.1.1.12  christos 
    785  1.1.1.12  christos     memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
    786  1.1.1.12  christos     AcpiGbl_DbMethodInfo.Name = MethodNameArg;
    787  1.1.1.12  christos     AcpiGbl_DbMethodInfo.InitArgs = 1;
    788  1.1.1.12  christos     AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
    789  1.1.1.12  christos     AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
    790  1.1.1.12  christos 
    791  1.1.1.12  christos     /* Setup method arguments, up to 7 (0-6) */
    792  1.1.1.12  christos 
    793  1.1.1.12  christos     for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && *Arguments; i++)
    794  1.1.1.12  christos     {
    795  1.1.1.12  christos         AcpiGbl_DbMethodInfo.Arguments[i] = *Arguments;
    796  1.1.1.12  christos         Arguments++;
    797  1.1.1.12  christos 
    798  1.1.1.12  christos         AcpiGbl_DbMethodInfo.ArgTypes[i] = *Types;
    799  1.1.1.12  christos         Types++;
    800  1.1.1.12  christos     }
    801  1.1.1.12  christos 
    802  1.1.1.12  christos     Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
    803  1.1.1.12  christos     if (ACPI_FAILURE (Status))
    804  1.1.1.12  christos     {
    805  1.1.1.12  christos         return;
    806  1.1.1.12  christos     }
    807  1.1.1.12  christos 
    808  1.1.1.12  christos     /* Get the NS node, determines existence also */
    809  1.1.1.12  christos 
    810  1.1.1.12  christos     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
    811  1.1.1.12  christos         &AcpiGbl_DbMethodInfo.Method);
    812  1.1.1.12  christos     if (ACPI_FAILURE (Status))
    813  1.1.1.12  christos     {
    814  1.1.1.12  christos         AcpiOsPrintf ("%s Could not get handle for %s\n",
    815  1.1.1.12  christos             AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
    816  1.1.1.12  christos         return;
    817  1.1.1.12  christos     }
    818  1.1.1.12  christos 
    819  1.1.1.12  christos     Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD,
    820  1.1.1.12  christos         AcpiDbSingleExecutionThread, &AcpiGbl_DbMethodInfo);
    821  1.1.1.12  christos     if (ACPI_FAILURE (Status))
    822  1.1.1.12  christos     {
    823  1.1.1.12  christos         return;
    824  1.1.1.12  christos     }
    825  1.1.1.12  christos 
    826  1.1.1.12  christos     AcpiOsPrintf ("\nBackground thread started\n");
    827  1.1.1.12  christos }
    828  1.1.1.12  christos 
    829  1.1.1.12  christos 
    830  1.1.1.12  christos /*******************************************************************************
    831  1.1.1.12  christos  *
    832       1.1    jruoho  * FUNCTION:    AcpiDbCreateExecutionThreads
    833       1.1    jruoho  *
    834       1.1    jruoho  * PARAMETERS:  NumThreadsArg           - Number of threads to create
    835       1.1    jruoho  *              NumLoopsArg             - Loop count for the thread(s)
    836       1.1    jruoho  *              MethodNameArg           - Control method to execute
    837       1.1    jruoho  *
    838       1.1    jruoho  * RETURN:      None
    839       1.1    jruoho  *
    840       1.1    jruoho  * DESCRIPTION: Create threads to execute method(s)
    841       1.1    jruoho  *
    842       1.1    jruoho  ******************************************************************************/
    843       1.1    jruoho 
    844       1.1    jruoho void
    845       1.1    jruoho AcpiDbCreateExecutionThreads (
    846       1.1    jruoho     char                    *NumThreadsArg,
    847       1.1    jruoho     char                    *NumLoopsArg,
    848       1.1    jruoho     char                    *MethodNameArg)
    849       1.1    jruoho {
    850       1.1    jruoho     ACPI_STATUS             Status;
    851       1.1    jruoho     UINT32                  NumThreads;
    852       1.1    jruoho     UINT32                  NumLoops;
    853       1.1    jruoho     UINT32                  i;
    854       1.1    jruoho     UINT32                  Size;
    855       1.1    jruoho     ACPI_MUTEX              MainThreadGate;
    856       1.1    jruoho     ACPI_MUTEX              ThreadCompleteGate;
    857       1.1    jruoho     ACPI_MUTEX              InfoGate;
    858       1.1    jruoho 
    859       1.1    jruoho 
    860       1.1    jruoho     /* Get the arguments */
    861       1.1    jruoho 
    862   1.1.1.7  christos     NumThreads = strtoul (NumThreadsArg, NULL, 0);
    863   1.1.1.8  christos     NumLoops = strtoul (NumLoopsArg, NULL, 0);
    864       1.1    jruoho 
    865       1.1    jruoho     if (!NumThreads || !NumLoops)
    866       1.1    jruoho     {
    867       1.1    jruoho         AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
    868       1.1    jruoho             NumThreads, NumLoops);
    869       1.1    jruoho         return;
    870       1.1    jruoho     }
    871       1.1    jruoho 
    872       1.1    jruoho     /*
    873       1.1    jruoho      * Create the semaphore for synchronization of
    874       1.1    jruoho      * the created threads with the main thread.
    875       1.1    jruoho      */
    876       1.1    jruoho     Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
    877       1.1    jruoho     if (ACPI_FAILURE (Status))
    878       1.1    jruoho     {
    879   1.1.1.8  christos         AcpiOsPrintf ("Could not create semaphore for "
    880   1.1.1.8  christos             "synchronization with the main thread, %s\n",
    881       1.1    jruoho             AcpiFormatException (Status));
    882       1.1    jruoho         return;
    883       1.1    jruoho     }
    884       1.1    jruoho 
    885       1.1    jruoho     /*
    886       1.1    jruoho      * Create the semaphore for synchronization
    887       1.1    jruoho      * between the created threads.
    888       1.1    jruoho      */
    889       1.1    jruoho     Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
    890       1.1    jruoho     if (ACPI_FAILURE (Status))
    891       1.1    jruoho     {
    892   1.1.1.8  christos         AcpiOsPrintf ("Could not create semaphore for "
    893   1.1.1.8  christos             "synchronization between the created threads, %s\n",
    894       1.1    jruoho             AcpiFormatException (Status));
    895   1.1.1.8  christos 
    896       1.1    jruoho         (void) AcpiOsDeleteSemaphore (MainThreadGate);
    897       1.1    jruoho         return;
    898       1.1    jruoho     }
    899       1.1    jruoho 
    900       1.1    jruoho     Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
    901       1.1    jruoho     if (ACPI_FAILURE (Status))
    902       1.1    jruoho     {
    903   1.1.1.8  christos         AcpiOsPrintf ("Could not create semaphore for "
    904   1.1.1.8  christos             "synchronization of AcpiGbl_DbMethodInfo, %s\n",
    905       1.1    jruoho             AcpiFormatException (Status));
    906   1.1.1.8  christos 
    907       1.1    jruoho         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
    908       1.1    jruoho         (void) AcpiOsDeleteSemaphore (MainThreadGate);
    909       1.1    jruoho         return;
    910       1.1    jruoho     }
    911       1.1    jruoho 
    912   1.1.1.7  christos     memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
    913       1.1    jruoho 
    914       1.1    jruoho     /* Array to store IDs of threads */
    915       1.1    jruoho 
    916       1.1    jruoho     AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
    917   1.1.1.2    jruoho     Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
    918   1.1.1.8  christos 
    919   1.1.1.2    jruoho     AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
    920       1.1    jruoho     if (AcpiGbl_DbMethodInfo.Threads == NULL)
    921       1.1    jruoho     {
    922       1.1    jruoho         AcpiOsPrintf ("No memory for thread IDs array\n");
    923       1.1    jruoho         (void) AcpiOsDeleteSemaphore (MainThreadGate);
    924       1.1    jruoho         (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
    925       1.1    jruoho         (void) AcpiOsDeleteSemaphore (InfoGate);
    926       1.1    jruoho         return;
    927       1.1    jruoho     }
    928   1.1.1.7  christos     memset (AcpiGbl_DbMethodInfo.Threads, 0, Size);
    929       1.1    jruoho 
    930       1.1    jruoho     /* Setup the context to be passed to each thread */
    931       1.1    jruoho 
    932       1.1    jruoho     AcpiGbl_DbMethodInfo.Name = MethodNameArg;
    933       1.1    jruoho     AcpiGbl_DbMethodInfo.Flags = 0;
    934       1.1    jruoho     AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
    935       1.1    jruoho     AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
    936       1.1    jruoho     AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
    937       1.1    jruoho     AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
    938       1.1    jruoho 
    939       1.1    jruoho     /* Init arguments to be passed to method */
    940       1.1    jruoho 
    941       1.1    jruoho     AcpiGbl_DbMethodInfo.InitArgs = 1;
    942       1.1    jruoho     AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
    943       1.1    jruoho     AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
    944       1.1    jruoho     AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
    945       1.1    jruoho     AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
    946       1.1    jruoho     AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
    947   1.1.1.3    jruoho 
    948   1.1.1.3    jruoho     AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
    949   1.1.1.3    jruoho     AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
    950   1.1.1.3    jruoho     AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
    951   1.1.1.3    jruoho     AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
    952   1.1.1.3    jruoho 
    953   1.1.1.4  christos     AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
    954       1.1    jruoho 
    955   1.1.1.4  christos     Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
    956   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    957   1.1.1.4  christos     {
    958   1.1.1.4  christos         goto CleanupAndExit;
    959   1.1.1.4  christos     }
    960   1.1.1.4  christos 
    961   1.1.1.4  christos     /* Get the NS node, determines existence also */
    962   1.1.1.4  christos 
    963   1.1.1.4  christos     Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
    964   1.1.1.4  christos         &AcpiGbl_DbMethodInfo.Method);
    965   1.1.1.4  christos     if (ACPI_FAILURE (Status))
    966   1.1.1.4  christos     {
    967   1.1.1.4  christos         AcpiOsPrintf ("%s Could not get handle for %s\n",
    968   1.1.1.4  christos             AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
    969   1.1.1.4  christos         goto CleanupAndExit;
    970   1.1.1.4  christos     }
    971       1.1    jruoho 
    972       1.1    jruoho     /* Create the threads */
    973       1.1    jruoho 
    974       1.1    jruoho     AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
    975       1.1    jruoho         NumThreads, NumLoops);
    976       1.1    jruoho 
    977       1.1    jruoho     for (i = 0; i < (NumThreads); i++)
    978       1.1    jruoho     {
    979   1.1.1.8  christos         Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD, AcpiDbMethodThread,
    980       1.1    jruoho             &AcpiGbl_DbMethodInfo);
    981       1.1    jruoho         if (ACPI_FAILURE (Status))
    982       1.1    jruoho         {
    983       1.1    jruoho             break;
    984       1.1    jruoho         }
    985       1.1    jruoho     }
    986       1.1    jruoho 
    987       1.1    jruoho     /* Wait for all threads to complete */
    988       1.1    jruoho 
    989       1.1    jruoho     (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
    990       1.1    jruoho 
    991       1.1    jruoho     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
    992       1.1    jruoho     AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
    993       1.1    jruoho     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
    994       1.1    jruoho 
    995   1.1.1.4  christos CleanupAndExit:
    996   1.1.1.4  christos 
    997       1.1    jruoho     /* Cleanup and exit */
    998       1.1    jruoho 
    999       1.1    jruoho     (void) AcpiOsDeleteSemaphore (MainThreadGate);
   1000       1.1    jruoho     (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
   1001       1.1    jruoho     (void) AcpiOsDeleteSemaphore (InfoGate);
   1002       1.1    jruoho 
   1003       1.1    jruoho     AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
   1004       1.1    jruoho     AcpiGbl_DbMethodInfo.Threads = NULL;
   1005       1.1    jruoho }
   1006