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