Home | History | Annotate | Line # | Download | only in debugger
dbmethod.c revision 1.15.4.2
      1       1.1    jruoho /*******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: dbmethod - Debug commands for control methods
      4       1.1    jruoho  *
      5       1.1    jruoho  ******************************************************************************/
      6       1.1    jruoho 
      7       1.1    jruoho /*
      8  1.15.4.2   thorpej  * Copyright (C) 2000 - 2021, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11       1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.1    jruoho  * modification, are permitted provided that the following conditions
     13       1.1    jruoho  * are met:
     14       1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.1    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.1    jruoho  *    without modification.
     17       1.1    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1    jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.1    jruoho  *    binary redistribution.
     22       1.1    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1    jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.1    jruoho  *    from this software without specific prior written permission.
     25       1.1    jruoho  *
     26       1.1    jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.1    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1    jruoho  * Software Foundation.
     29       1.1    jruoho  *
     30       1.1    jruoho  * NO WARRANTY
     31       1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.15.4.2   thorpej  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34       1.1    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "acdispat.h"
     47       1.1    jruoho #include "acnamesp.h"
     48       1.1    jruoho #include "acdebug.h"
     49       1.1    jruoho #include "acparser.h"
     50       1.2  christos #include "acpredef.h"
     51       1.1    jruoho 
     52       1.1    jruoho 
     53       1.1    jruoho #define _COMPONENT          ACPI_CA_DEBUGGER
     54       1.1    jruoho         ACPI_MODULE_NAME    ("dbmethod")
     55       1.1    jruoho 
     56       1.7  christos /* Local prototypes */
     57       1.7  christos 
     58       1.7  christos static ACPI_STATUS
     59       1.7  christos AcpiDbWalkForExecute (
     60       1.7  christos     ACPI_HANDLE             ObjHandle,
     61       1.7  christos     UINT32                  NestingLevel,
     62       1.7  christos     void                    *Context,
     63       1.7  christos     void                    **ReturnValue);
     64       1.7  christos 
     65  1.15.4.1   thorpej static ACPI_STATUS
     66  1.15.4.1   thorpej AcpiDbEvaluateObject (
     67  1.15.4.1   thorpej     ACPI_NAMESPACE_NODE     *Node);
     68  1.15.4.1   thorpej 
     69       1.1    jruoho 
     70       1.1    jruoho /*******************************************************************************
     71       1.1    jruoho  *
     72       1.1    jruoho  * FUNCTION:    AcpiDbSetMethodBreakpoint
     73       1.1    jruoho  *
     74       1.1    jruoho  * PARAMETERS:  Location            - AML offset of breakpoint
     75       1.1    jruoho  *              WalkState           - Current walk info
     76       1.1    jruoho  *              Op                  - Current Op (from parse walk)
     77       1.1    jruoho  *
     78       1.1    jruoho  * RETURN:      None
     79       1.1    jruoho  *
     80       1.1    jruoho  * DESCRIPTION: Set a breakpoint in a control method at the specified
     81       1.1    jruoho  *              AML offset
     82       1.1    jruoho  *
     83       1.1    jruoho  ******************************************************************************/
     84       1.1    jruoho 
     85       1.1    jruoho void
     86       1.1    jruoho AcpiDbSetMethodBreakpoint (
     87       1.1    jruoho     char                    *Location,
     88       1.1    jruoho     ACPI_WALK_STATE         *WalkState,
     89       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
     90       1.1    jruoho {
     91       1.1    jruoho     UINT32                  Address;
     92       1.5  christos     UINT32                  AmlOffset;
     93       1.1    jruoho 
     94       1.1    jruoho 
     95       1.1    jruoho     if (!Op)
     96       1.1    jruoho     {
     97       1.1    jruoho         AcpiOsPrintf ("There is no method currently executing\n");
     98       1.1    jruoho         return;
     99       1.1    jruoho     }
    100       1.1    jruoho 
    101       1.1    jruoho     /* Get and verify the breakpoint address */
    102       1.1    jruoho 
    103       1.5  christos     Address = strtoul (Location, NULL, 16);
    104       1.5  christos     AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
    105       1.6  christos         WalkState->ParserState.AmlStart);
    106       1.5  christos     if (Address <= AmlOffset)
    107       1.1    jruoho     {
    108       1.1    jruoho         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
    109       1.5  christos             Address, AmlOffset);
    110       1.1    jruoho     }
    111       1.1    jruoho 
    112       1.1    jruoho     /* Save breakpoint in current walk */
    113       1.1    jruoho 
    114       1.1    jruoho     WalkState->UserBreakpoint = Address;
    115       1.1    jruoho     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
    116       1.1    jruoho }
    117       1.1    jruoho 
    118       1.1    jruoho 
    119       1.1    jruoho /*******************************************************************************
    120       1.1    jruoho  *
    121       1.1    jruoho  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
    122       1.1    jruoho  *
    123       1.1    jruoho  * PARAMETERS:  Op                  - Current Op (from parse walk)
    124       1.1    jruoho  *
    125       1.1    jruoho  * RETURN:      None
    126       1.1    jruoho  *
    127       1.1    jruoho  * DESCRIPTION: Set a breakpoint in a control method at the specified
    128       1.1    jruoho  *              AML offset
    129       1.1    jruoho  *
    130       1.1    jruoho  ******************************************************************************/
    131       1.1    jruoho 
    132       1.1    jruoho void
    133       1.1    jruoho AcpiDbSetMethodCallBreakpoint (
    134       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    135       1.1    jruoho {
    136       1.1    jruoho 
    137       1.1    jruoho 
    138       1.1    jruoho     if (!Op)
    139       1.1    jruoho     {
    140       1.1    jruoho         AcpiOsPrintf ("There is no method currently executing\n");
    141       1.1    jruoho         return;
    142       1.1    jruoho     }
    143       1.1    jruoho 
    144       1.1    jruoho     AcpiGbl_StepToNextCall = TRUE;
    145       1.1    jruoho }
    146       1.1    jruoho 
    147       1.1    jruoho 
    148       1.1    jruoho /*******************************************************************************
    149       1.1    jruoho  *
    150       1.1    jruoho  * FUNCTION:    AcpiDbSetMethodData
    151       1.1    jruoho  *
    152       1.1    jruoho  * PARAMETERS:  TypeArg         - L for local, A for argument
    153       1.1    jruoho  *              IndexArg        - which one
    154       1.1    jruoho  *              ValueArg        - Value to set.
    155       1.1    jruoho  *
    156       1.1    jruoho  * RETURN:      None
    157       1.1    jruoho  *
    158       1.1    jruoho  * DESCRIPTION: Set a local or argument for the running control method.
    159       1.1    jruoho  *              NOTE: only object supported is Number.
    160       1.1    jruoho  *
    161       1.1    jruoho  ******************************************************************************/
    162       1.1    jruoho 
    163       1.1    jruoho void
    164       1.1    jruoho AcpiDbSetMethodData (
    165       1.1    jruoho     char                    *TypeArg,
    166       1.1    jruoho     char                    *IndexArg,
    167       1.1    jruoho     char                    *ValueArg)
    168       1.1    jruoho {
    169       1.1    jruoho     char                    Type;
    170       1.1    jruoho     UINT32                  Index;
    171       1.1    jruoho     UINT32                  Value;
    172       1.1    jruoho     ACPI_WALK_STATE         *WalkState;
    173       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    174       1.1    jruoho     ACPI_STATUS             Status;
    175       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    176       1.1    jruoho 
    177       1.1    jruoho 
    178       1.1    jruoho     /* Validate TypeArg */
    179       1.1    jruoho 
    180       1.1    jruoho     AcpiUtStrupr (TypeArg);
    181       1.1    jruoho     Type = TypeArg[0];
    182       1.1    jruoho     if ((Type != 'L') &&
    183       1.1    jruoho         (Type != 'A') &&
    184       1.1    jruoho         (Type != 'N'))
    185       1.1    jruoho     {
    186       1.1    jruoho         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
    187       1.1    jruoho         return;
    188       1.1    jruoho     }
    189       1.1    jruoho 
    190       1.5  christos     Value = strtoul (ValueArg, NULL, 16);
    191       1.1    jruoho 
    192       1.1    jruoho     if (Type == 'N')
    193       1.1    jruoho     {
    194       1.1    jruoho         Node = AcpiDbConvertToNode (IndexArg);
    195       1.3  christos         if (!Node)
    196       1.3  christos         {
    197       1.3  christos             return;
    198       1.3  christos         }
    199       1.3  christos 
    200       1.1    jruoho         if (Node->Type != ACPI_TYPE_INTEGER)
    201       1.1    jruoho         {
    202       1.1    jruoho             AcpiOsPrintf ("Can only set Integer nodes\n");
    203       1.1    jruoho             return;
    204       1.1    jruoho         }
    205       1.1    jruoho         ObjDesc = Node->Object;
    206       1.1    jruoho         ObjDesc->Integer.Value = Value;
    207       1.1    jruoho         return;
    208       1.1    jruoho     }
    209       1.1    jruoho 
    210       1.1    jruoho     /* Get the index and value */
    211       1.1    jruoho 
    212       1.5  christos     Index = strtoul (IndexArg, NULL, 16);
    213       1.1    jruoho 
    214       1.1    jruoho     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
    215       1.1    jruoho     if (!WalkState)
    216       1.1    jruoho     {
    217       1.1    jruoho         AcpiOsPrintf ("There is no method currently executing\n");
    218       1.1    jruoho         return;
    219       1.1    jruoho     }
    220       1.1    jruoho 
    221       1.1    jruoho     /* Create and initialize the new object */
    222       1.1    jruoho 
    223       1.1    jruoho     ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
    224       1.1    jruoho     if (!ObjDesc)
    225       1.1    jruoho     {
    226       1.1    jruoho         AcpiOsPrintf ("Could not create an internal object\n");
    227       1.1    jruoho         return;
    228       1.1    jruoho     }
    229       1.1    jruoho 
    230       1.1    jruoho     /* Store the new object into the target */
    231       1.1    jruoho 
    232       1.1    jruoho     switch (Type)
    233       1.1    jruoho     {
    234       1.1    jruoho     case 'A':
    235       1.1    jruoho 
    236       1.1    jruoho         /* Set a method argument */
    237       1.1    jruoho 
    238       1.1    jruoho         if (Index > ACPI_METHOD_MAX_ARG)
    239       1.1    jruoho         {
    240       1.6  christos             AcpiOsPrintf ("Arg%u - Invalid argument name\n",
    241       1.6  christos                 Index);
    242       1.1    jruoho             goto Cleanup;
    243       1.1    jruoho         }
    244       1.1    jruoho 
    245       1.6  christos         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG,
    246       1.6  christos             Index, ObjDesc, WalkState);
    247       1.1    jruoho         if (ACPI_FAILURE (Status))
    248       1.1    jruoho         {
    249       1.1    jruoho             goto Cleanup;
    250       1.1    jruoho         }
    251       1.1    jruoho 
    252       1.1    jruoho         ObjDesc = WalkState->Arguments[Index].Object;
    253       1.1    jruoho 
    254       1.1    jruoho         AcpiOsPrintf ("Arg%u: ", Index);
    255       1.5  christos         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
    256       1.1    jruoho         break;
    257       1.1    jruoho 
    258       1.1    jruoho     case 'L':
    259       1.1    jruoho 
    260       1.1    jruoho         /* Set a method local */
    261       1.1    jruoho 
    262       1.1    jruoho         if (Index > ACPI_METHOD_MAX_LOCAL)
    263       1.1    jruoho         {
    264       1.6  christos             AcpiOsPrintf ("Local%u - Invalid local variable name\n",
    265       1.6  christos                 Index);
    266       1.1    jruoho             goto Cleanup;
    267       1.1    jruoho         }
    268       1.1    jruoho 
    269       1.6  christos         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL,
    270       1.6  christos             Index, ObjDesc, WalkState);
    271       1.1    jruoho         if (ACPI_FAILURE (Status))
    272       1.1    jruoho         {
    273       1.1    jruoho             goto Cleanup;
    274       1.1    jruoho         }
    275       1.1    jruoho 
    276       1.1    jruoho         ObjDesc = WalkState->LocalVariables[Index].Object;
    277       1.1    jruoho 
    278       1.1    jruoho         AcpiOsPrintf ("Local%u: ", Index);
    279       1.5  christos         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
    280       1.1    jruoho         break;
    281       1.1    jruoho 
    282       1.1    jruoho     default:
    283       1.2  christos 
    284       1.1    jruoho         break;
    285       1.1    jruoho     }
    286       1.1    jruoho 
    287       1.1    jruoho Cleanup:
    288       1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    289       1.1    jruoho }
    290       1.1    jruoho 
    291       1.1    jruoho 
    292      1.11  christos #ifdef ACPI_DISASSEMBLER
    293       1.1    jruoho /*******************************************************************************
    294       1.1    jruoho  *
    295       1.1    jruoho  * FUNCTION:    AcpiDbDisassembleAml
    296       1.1    jruoho  *
    297       1.1    jruoho  * PARAMETERS:  Statements          - Number of statements to disassemble
    298       1.1    jruoho  *              Op                  - Current Op (from parse walk)
    299       1.1    jruoho  *
    300       1.1    jruoho  * RETURN:      None
    301       1.1    jruoho  *
    302       1.1    jruoho  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
    303       1.1    jruoho  *              of statements specified.
    304       1.1    jruoho  *
    305       1.1    jruoho  ******************************************************************************/
    306       1.1    jruoho 
    307       1.1    jruoho void
    308       1.1    jruoho AcpiDbDisassembleAml (
    309       1.1    jruoho     char                    *Statements,
    310       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    311       1.1    jruoho {
    312       1.1    jruoho     UINT32                  NumStatements = 8;
    313       1.1    jruoho 
    314       1.1    jruoho 
    315       1.1    jruoho     if (!Op)
    316       1.1    jruoho     {
    317       1.1    jruoho         AcpiOsPrintf ("There is no method currently executing\n");
    318       1.1    jruoho         return;
    319       1.1    jruoho     }
    320       1.1    jruoho 
    321       1.1    jruoho     if (Statements)
    322       1.1    jruoho     {
    323       1.5  christos         NumStatements = strtoul (Statements, NULL, 0);
    324       1.1    jruoho     }
    325       1.1    jruoho 
    326       1.1    jruoho     AcpiDmDisassemble (NULL, Op, NumStatements);
    327       1.1    jruoho }
    328       1.1    jruoho 
    329       1.1    jruoho 
    330       1.1    jruoho /*******************************************************************************
    331       1.1    jruoho  *
    332       1.1    jruoho  * FUNCTION:    AcpiDbDisassembleMethod
    333       1.1    jruoho  *
    334       1.1    jruoho  * PARAMETERS:  Name            - Name of control method
    335       1.1    jruoho  *
    336       1.1    jruoho  * RETURN:      None
    337       1.1    jruoho  *
    338       1.1    jruoho  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
    339       1.1    jruoho  *              of statements specified.
    340       1.1    jruoho  *
    341       1.1    jruoho  ******************************************************************************/
    342       1.1    jruoho 
    343       1.1    jruoho ACPI_STATUS
    344       1.1    jruoho AcpiDbDisassembleMethod (
    345       1.1    jruoho     char                    *Name)
    346       1.1    jruoho {
    347       1.1    jruoho     ACPI_STATUS             Status;
    348       1.1    jruoho     ACPI_PARSE_OBJECT       *Op;
    349       1.1    jruoho     ACPI_WALK_STATE         *WalkState;
    350       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    351       1.1    jruoho     ACPI_NAMESPACE_NODE     *Method;
    352       1.1    jruoho 
    353       1.1    jruoho 
    354       1.1    jruoho     Method = AcpiDbConvertToNode (Name);
    355       1.1    jruoho     if (!Method)
    356       1.1    jruoho     {
    357       1.1    jruoho         return (AE_BAD_PARAMETER);
    358       1.1    jruoho     }
    359       1.1    jruoho 
    360       1.2  christos     if (Method->Type != ACPI_TYPE_METHOD)
    361       1.2  christos     {
    362       1.2  christos         ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
    363       1.2  christos             Name, AcpiUtGetTypeName (Method->Type)));
    364       1.2  christos         return (AE_BAD_PARAMETER);
    365       1.2  christos     }
    366       1.2  christos 
    367       1.1    jruoho     ObjDesc = Method->Object;
    368       1.1    jruoho 
    369       1.5  christos     Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
    370       1.1    jruoho     if (!Op)
    371       1.1    jruoho     {
    372       1.1    jruoho         return (AE_NO_MEMORY);
    373       1.1    jruoho     }
    374       1.1    jruoho 
    375       1.1    jruoho     /* Create and initialize a new walk state */
    376       1.1    jruoho 
    377       1.1    jruoho     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
    378       1.1    jruoho     if (!WalkState)
    379       1.1    jruoho     {
    380       1.1    jruoho         return (AE_NO_MEMORY);
    381       1.1    jruoho     }
    382       1.1    jruoho 
    383       1.1    jruoho     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
    384       1.2  christos         ObjDesc->Method.AmlStart,
    385       1.2  christos         ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
    386       1.2  christos     if (ACPI_FAILURE (Status))
    387       1.2  christos     {
    388       1.2  christos         return (Status);
    389       1.2  christos     }
    390       1.2  christos 
    391       1.2  christos     Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
    392      1.13  christos     if (ACPI_FAILURE(Status))
    393      1.13  christos     {
    394      1.13  christos         return (Status);
    395      1.13  christos     }
    396      1.13  christos 
    397       1.2  christos     WalkState->OwnerId = ObjDesc->Method.OwnerId;
    398       1.2  christos 
    399       1.2  christos     /* Push start scope on scope stack and make it current */
    400       1.2  christos 
    401       1.2  christos     Status = AcpiDsScopeStackPush (Method,
    402       1.2  christos         Method->Type, WalkState);
    403       1.1    jruoho     if (ACPI_FAILURE (Status))
    404       1.1    jruoho     {
    405       1.1    jruoho         return (Status);
    406       1.1    jruoho     }
    407       1.1    jruoho 
    408       1.2  christos     /* Parse the entire method AML including deferred operators */
    409       1.1    jruoho 
    410       1.1    jruoho     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
    411       1.1    jruoho     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
    412       1.2  christos 
    413       1.1    jruoho     Status = AcpiPsParseAml (WalkState);
    414      1.14  christos     if (ACPI_FAILURE(Status))
    415      1.14  christos     {
    416      1.14  christos         return (Status);
    417      1.14  christos     }
    418      1.14  christos 
    419       1.2  christos     (void) AcpiDmParseDeferredOps (Op);
    420       1.2  christos 
    421       1.2  christos     /* Now we can disassemble the method */
    422       1.1    jruoho 
    423       1.6  christos     AcpiGbl_DmOpt_Verbose = FALSE;
    424       1.1    jruoho     AcpiDmDisassemble (NULL, Op, 0);
    425       1.6  christos     AcpiGbl_DmOpt_Verbose = TRUE;
    426       1.2  christos 
    427       1.1    jruoho     AcpiPsDeleteParseTree (Op);
    428       1.2  christos 
    429       1.2  christos     /* Method cleanup */
    430       1.2  christos 
    431       1.2  christos     AcpiNsDeleteNamespaceSubtree (Method);
    432       1.2  christos     AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
    433       1.2  christos     AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
    434       1.1    jruoho     return (AE_OK);
    435       1.1    jruoho }
    436      1.11  christos #endif
    437       1.7  christos 
    438       1.7  christos 
    439       1.7  christos /*******************************************************************************
    440       1.7  christos  *
    441  1.15.4.1   thorpej  * FUNCTION:    AcpiDbEvaluateObject
    442       1.7  christos  *
    443  1.15.4.1   thorpej  * PARAMETERS:  Node                - Namespace node for the object
    444       1.7  christos  *
    445       1.7  christos  * RETURN:      Status
    446       1.7  christos  *
    447  1.15.4.1   thorpej  * DESCRIPTION: Main execution function for the Evaluate/Execute/All debugger
    448  1.15.4.1   thorpej  *              commands.
    449       1.7  christos  *
    450       1.7  christos  ******************************************************************************/
    451       1.7  christos 
    452       1.7  christos static ACPI_STATUS
    453  1.15.4.1   thorpej AcpiDbEvaluateObject (
    454  1.15.4.1   thorpej     ACPI_NAMESPACE_NODE     *Node)
    455       1.7  christos {
    456       1.7  christos     char                    *Pathname;
    457       1.7  christos     UINT32                  i;
    458       1.7  christos     ACPI_DEVICE_INFO        *ObjInfo;
    459       1.7  christos     ACPI_OBJECT_LIST        ParamObjects;
    460       1.7  christos     ACPI_OBJECT             Params[ACPI_METHOD_NUM_ARGS];
    461  1.15.4.1   thorpej     ACPI_BUFFER             ReturnObj;
    462  1.15.4.1   thorpej     ACPI_STATUS             Status;
    463       1.7  christos 
    464       1.7  christos 
    465       1.7  christos     Pathname = AcpiNsGetExternalPathname (Node);
    466       1.7  christos     if (!Pathname)
    467       1.7  christos     {
    468       1.7  christos         return (AE_OK);
    469       1.7  christos     }
    470       1.7  christos 
    471       1.7  christos     /* Get the object info for number of method parameters */
    472       1.7  christos 
    473  1.15.4.1   thorpej     Status = AcpiGetObjectInfo (Node, &ObjInfo);
    474       1.7  christos     if (ACPI_FAILURE (Status))
    475       1.7  christos     {
    476       1.9  christos         ACPI_FREE (Pathname);
    477       1.7  christos         return (Status);
    478       1.7  christos     }
    479       1.7  christos 
    480       1.7  christos     ParamObjects.Pointer = NULL;
    481       1.7  christos     ParamObjects.Count   = 0;
    482       1.7  christos 
    483       1.7  christos     if (ObjInfo->Type == ACPI_TYPE_METHOD)
    484       1.7  christos     {
    485       1.7  christos         /* Setup default parameters */
    486       1.7  christos 
    487       1.7  christos         for (i = 0; i < ObjInfo->ParamCount; i++)
    488       1.7  christos         {
    489       1.7  christos             Params[i].Type           = ACPI_TYPE_INTEGER;
    490       1.7  christos             Params[i].Integer.Value  = 1;
    491       1.7  christos         }
    492       1.7  christos 
    493       1.7  christos         ParamObjects.Pointer     = Params;
    494       1.7  christos         ParamObjects.Count       = ObjInfo->ParamCount;
    495       1.7  christos     }
    496       1.7  christos 
    497       1.7  christos     ACPI_FREE (ObjInfo);
    498       1.7  christos     ReturnObj.Pointer = NULL;
    499       1.7  christos     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    500       1.7  christos 
    501       1.7  christos     /* Do the actual method execution */
    502       1.7  christos 
    503       1.7  christos     AcpiGbl_MethodExecuting = TRUE;
    504       1.7  christos 
    505       1.7  christos     Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
    506  1.15.4.1   thorpej     AcpiGbl_MethodExecuting = FALSE;
    507       1.7  christos 
    508       1.7  christos     AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
    509  1.15.4.1   thorpej     if (ReturnObj.Length)
    510  1.15.4.1   thorpej     {
    511  1.15.4.1   thorpej         AcpiOsPrintf ("Evaluation of %s returned object %p, "
    512  1.15.4.1   thorpej             "external buffer length %X\n",
    513  1.15.4.1   thorpej             Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length);
    514  1.15.4.1   thorpej 
    515  1.15.4.1   thorpej         AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
    516  1.15.4.1   thorpej         AcpiOsPrintf ("\n");
    517  1.15.4.1   thorpej     }
    518  1.15.4.1   thorpej 
    519       1.7  christos     ACPI_FREE (Pathname);
    520       1.7  christos 
    521       1.7  christos     /* Ignore status from method execution */
    522       1.7  christos 
    523  1.15.4.1   thorpej     return (AE_OK);
    524  1.15.4.1   thorpej 
    525  1.15.4.1   thorpej     /* Update count, check if we have executed enough methods */
    526  1.15.4.1   thorpej 
    527  1.15.4.1   thorpej }
    528  1.15.4.1   thorpej 
    529  1.15.4.1   thorpej /*******************************************************************************
    530  1.15.4.1   thorpej  *
    531  1.15.4.1   thorpej  * FUNCTION:    AcpiDbWalkForExecute
    532  1.15.4.1   thorpej  *
    533  1.15.4.1   thorpej  * PARAMETERS:  Callback from WalkNamespace
    534  1.15.4.1   thorpej  *
    535  1.15.4.1   thorpej  * RETURN:      Status
    536  1.15.4.1   thorpej  *
    537  1.15.4.1   thorpej  * DESCRIPTION: Batch execution function. Evaluates all "predefined" objects --
    538  1.15.4.1   thorpej  *              the nameseg begins with an underscore.
    539  1.15.4.1   thorpej  *
    540  1.15.4.1   thorpej  ******************************************************************************/
    541  1.15.4.1   thorpej 
    542  1.15.4.1   thorpej static ACPI_STATUS
    543  1.15.4.1   thorpej AcpiDbWalkForExecute (
    544  1.15.4.1   thorpej     ACPI_HANDLE             ObjHandle,
    545  1.15.4.1   thorpej     UINT32                  NestingLevel,
    546  1.15.4.1   thorpej     void                    *Context,
    547  1.15.4.1   thorpej     void                    **ReturnValue)
    548  1.15.4.1   thorpej {
    549  1.15.4.1   thorpej     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    550  1.15.4.1   thorpej     ACPI_DB_EXECUTE_WALK    *Info = (ACPI_DB_EXECUTE_WALK *) Context;
    551  1.15.4.1   thorpej     ACPI_STATUS             Status;
    552  1.15.4.1   thorpej     const ACPI_PREDEFINED_INFO *Predefined;
    553  1.15.4.1   thorpej 
    554  1.15.4.1   thorpej 
    555  1.15.4.1   thorpej     Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
    556  1.15.4.1   thorpej     if (!Predefined)
    557  1.15.4.1   thorpej     {
    558  1.15.4.1   thorpej         return (AE_OK);
    559  1.15.4.1   thorpej     }
    560  1.15.4.1   thorpej 
    561  1.15.4.1   thorpej     if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
    562  1.15.4.1   thorpej     {
    563  1.15.4.1   thorpej         return (AE_OK);
    564  1.15.4.1   thorpej     }
    565  1.15.4.1   thorpej 
    566  1.15.4.1   thorpej     AcpiDbEvaluateObject (Node);
    567  1.15.4.1   thorpej 
    568  1.15.4.1   thorpej     /* Ignore status from object evaluation */
    569  1.15.4.1   thorpej 
    570       1.7  christos     Status = AE_OK;
    571       1.7  christos 
    572       1.7  christos     /* Update count, check if we have executed enough methods */
    573       1.7  christos 
    574       1.7  christos     Info->Count++;
    575       1.7  christos     if (Info->Count >= Info->MaxCount)
    576       1.7  christos     {
    577       1.7  christos         Status = AE_CTRL_TERMINATE;
    578       1.7  christos     }
    579       1.7  christos 
    580       1.7  christos     return (Status);
    581       1.7  christos }
    582       1.7  christos 
    583       1.7  christos 
    584       1.7  christos /*******************************************************************************
    585       1.7  christos  *
    586  1.15.4.1   thorpej  * FUNCTION:    AcpiDbWalkForExecuteAll
    587  1.15.4.1   thorpej  *
    588  1.15.4.1   thorpej  * PARAMETERS:  Callback from WalkNamespace
    589  1.15.4.1   thorpej  *
    590  1.15.4.1   thorpej  * RETURN:      Status
    591  1.15.4.1   thorpej  *
    592  1.15.4.1   thorpej  * DESCRIPTION: Batch execution function. Evaluates all objects whose path ends
    593  1.15.4.1   thorpej  *              with the nameseg "Info->NameSeg". Used for the "ALL" command.
    594  1.15.4.1   thorpej  *
    595  1.15.4.1   thorpej  ******************************************************************************/
    596  1.15.4.1   thorpej 
    597  1.15.4.1   thorpej static ACPI_STATUS
    598  1.15.4.1   thorpej AcpiDbWalkForExecuteAll (
    599  1.15.4.1   thorpej     ACPI_HANDLE             ObjHandle,
    600  1.15.4.1   thorpej     UINT32                  NestingLevel,
    601  1.15.4.1   thorpej     void                    *Context,
    602  1.15.4.1   thorpej     void                    **ReturnValue)
    603  1.15.4.1   thorpej {
    604  1.15.4.1   thorpej     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    605  1.15.4.1   thorpej     ACPI_DB_EXECUTE_WALK    *Info = (ACPI_DB_EXECUTE_WALK *) Context;
    606  1.15.4.1   thorpej     ACPI_STATUS             Status;
    607  1.15.4.1   thorpej 
    608  1.15.4.1   thorpej 
    609  1.15.4.1   thorpej     if (!ACPI_COMPARE_NAMESEG (Node->Name.Ascii, Info->NameSeg))
    610  1.15.4.1   thorpej     {
    611  1.15.4.1   thorpej         return (AE_OK);
    612  1.15.4.1   thorpej     }
    613  1.15.4.1   thorpej 
    614  1.15.4.1   thorpej     if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
    615  1.15.4.1   thorpej     {
    616  1.15.4.1   thorpej         return (AE_OK);
    617  1.15.4.1   thorpej     }
    618  1.15.4.1   thorpej 
    619  1.15.4.1   thorpej     /* Now evaluate the input object (node) */
    620  1.15.4.1   thorpej 
    621  1.15.4.1   thorpej     AcpiDbEvaluateObject (Node);
    622  1.15.4.1   thorpej 
    623  1.15.4.1   thorpej     /* Ignore status from method execution */
    624  1.15.4.1   thorpej 
    625  1.15.4.1   thorpej     Status = AE_OK;
    626  1.15.4.1   thorpej 
    627  1.15.4.1   thorpej     /* Update count of executed methods/objects */
    628  1.15.4.1   thorpej 
    629  1.15.4.1   thorpej     Info->Count++;
    630  1.15.4.1   thorpej     return (Status);
    631  1.15.4.1   thorpej }
    632  1.15.4.1   thorpej 
    633  1.15.4.1   thorpej 
    634  1.15.4.1   thorpej /*******************************************************************************
    635  1.15.4.1   thorpej  *
    636       1.7  christos  * FUNCTION:    AcpiDbEvaluatePredefinedNames
    637       1.7  christos  *
    638       1.7  christos  * PARAMETERS:  None
    639       1.7  christos  *
    640       1.7  christos  * RETURN:      None
    641       1.7  christos  *
    642       1.7  christos  * DESCRIPTION: Namespace batch execution. Execute predefined names in the
    643       1.7  christos  *              namespace, up to the max count, if specified.
    644       1.7  christos  *
    645       1.7  christos  ******************************************************************************/
    646       1.7  christos 
    647       1.7  christos void
    648       1.7  christos AcpiDbEvaluatePredefinedNames (
    649       1.7  christos     void)
    650       1.7  christos {
    651       1.7  christos     ACPI_DB_EXECUTE_WALK    Info;
    652       1.7  christos 
    653       1.7  christos 
    654       1.7  christos     Info.Count = 0;
    655       1.7  christos     Info.MaxCount = ACPI_UINT32_MAX;
    656       1.7  christos 
    657       1.7  christos     /* Search all nodes in namespace */
    658       1.7  christos 
    659       1.7  christos     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
    660       1.7  christos                 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
    661       1.7  christos 
    662       1.7  christos     AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
    663       1.7  christos }
    664  1.15.4.1   thorpej 
    665  1.15.4.1   thorpej 
    666  1.15.4.1   thorpej /*******************************************************************************
    667  1.15.4.1   thorpej  *
    668  1.15.4.1   thorpej  * FUNCTION:    AcpiDbEvaluateAll
    669  1.15.4.1   thorpej  *
    670  1.15.4.1   thorpej  * PARAMETERS:  NoneAcpiGbl_DbMethodInfo
    671  1.15.4.1   thorpej  *
    672  1.15.4.1   thorpej  * RETURN:      None
    673  1.15.4.1   thorpej  *
    674  1.15.4.1   thorpej  * DESCRIPTION: Namespace batch execution. Implements the "ALL" command.
    675  1.15.4.1   thorpej  *              Execute all namepaths whose final nameseg matches the
    676  1.15.4.1   thorpej  *              input nameseg.
    677  1.15.4.1   thorpej  *
    678  1.15.4.1   thorpej  ******************************************************************************/
    679  1.15.4.1   thorpej 
    680  1.15.4.1   thorpej void
    681  1.15.4.1   thorpej AcpiDbEvaluateAll (
    682  1.15.4.1   thorpej     char                    *NameSeg)
    683  1.15.4.1   thorpej {
    684  1.15.4.1   thorpej     ACPI_DB_EXECUTE_WALK    Info;
    685  1.15.4.1   thorpej 
    686  1.15.4.1   thorpej 
    687  1.15.4.1   thorpej     Info.Count = 0;
    688  1.15.4.1   thorpej     Info.MaxCount = ACPI_UINT32_MAX;
    689  1.15.4.1   thorpej     ACPI_COPY_NAMESEG (Info.NameSeg, NameSeg);
    690  1.15.4.1   thorpej     Info.NameSeg[ACPI_NAMESEG_SIZE] = 0;
    691  1.15.4.1   thorpej 
    692  1.15.4.1   thorpej     /* Search all nodes in namespace */
    693  1.15.4.1   thorpej 
    694  1.15.4.1   thorpej     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
    695  1.15.4.1   thorpej                 AcpiDbWalkForExecuteAll, NULL, (void *) &Info, NULL);
    696  1.15.4.1   thorpej 
    697  1.15.4.1   thorpej     AcpiOsPrintf ("Evaluated %u names in the namespace\n", Info.Count);
    698  1.15.4.1   thorpej }
    699