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