Home | History | Annotate | Line # | Download | only in debugger
dbtest.c revision 1.1
      1  1.1  christos /*******************************************************************************
      2  1.1  christos  *
      3  1.1  christos  * Module Name: dbtest - Various debug-related tests
      4  1.1  christos  *
      5  1.1  christos  ******************************************************************************/
      6  1.1  christos 
      7  1.1  christos /*
      8  1.1  christos  * Copyright (C) 2000 - 2014, Intel Corp.
      9  1.1  christos  * All rights reserved.
     10  1.1  christos  *
     11  1.1  christos  * Redistribution and use in source and binary forms, with or without
     12  1.1  christos  * modification, are permitted provided that the following conditions
     13  1.1  christos  * are met:
     14  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15  1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16  1.1  christos  *    without modification.
     17  1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21  1.1  christos  *    binary redistribution.
     22  1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24  1.1  christos  *    from this software without specific prior written permission.
     25  1.1  christos  *
     26  1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27  1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1  christos  * Software Foundation.
     29  1.1  christos  *
     30  1.1  christos  * NO WARRANTY
     31  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1  christos  */
     43  1.1  christos 
     44  1.1  christos #include "acpi.h"
     45  1.1  christos #include "accommon.h"
     46  1.1  christos #include "acdebug.h"
     47  1.1  christos #include "acnamesp.h"
     48  1.1  christos #include "acpredef.h"
     49  1.1  christos 
     50  1.1  christos #ifdef ACPI_DEBUGGER
     51  1.1  christos 
     52  1.1  christos #define _COMPONENT          ACPI_CA_DEBUGGER
     53  1.1  christos         ACPI_MODULE_NAME    ("dbtest")
     54  1.1  christos 
     55  1.1  christos 
     56  1.1  christos /* Local prototypes */
     57  1.1  christos 
     58  1.1  christos static void
     59  1.1  christos AcpiDbTestAllObjects (
     60  1.1  christos     void);
     61  1.1  christos 
     62  1.1  christos static ACPI_STATUS
     63  1.1  christos AcpiDbTestOneObject (
     64  1.1  christos     ACPI_HANDLE             ObjHandle,
     65  1.1  christos     UINT32                  NestingLevel,
     66  1.1  christos     void                    *Context,
     67  1.1  christos     void                    **ReturnValue);
     68  1.1  christos 
     69  1.1  christos static ACPI_STATUS
     70  1.1  christos AcpiDbTestIntegerType (
     71  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
     72  1.1  christos     UINT32                  BitLength);
     73  1.1  christos 
     74  1.1  christos static ACPI_STATUS
     75  1.1  christos AcpiDbTestBufferType (
     76  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
     77  1.1  christos     UINT32                  BitLength);
     78  1.1  christos 
     79  1.1  christos static ACPI_STATUS
     80  1.1  christos AcpiDbTestStringType (
     81  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
     82  1.1  christos     UINT32                  ByteLength);
     83  1.1  christos 
     84  1.1  christos static ACPI_STATUS
     85  1.1  christos AcpiDbReadFromObject (
     86  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
     87  1.1  christos     ACPI_OBJECT_TYPE        ExpectedType,
     88  1.1  christos     ACPI_OBJECT             **Value);
     89  1.1  christos 
     90  1.1  christos static ACPI_STATUS
     91  1.1  christos AcpiDbWriteToObject (
     92  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
     93  1.1  christos     ACPI_OBJECT             *Value);
     94  1.1  christos 
     95  1.1  christos static void
     96  1.1  christos AcpiDbEvaluateAllPredefinedNames (
     97  1.1  christos     char                    *CountArg);
     98  1.1  christos 
     99  1.1  christos static ACPI_STATUS
    100  1.1  christos AcpiDbEvaluateOnePredefinedName (
    101  1.1  christos     ACPI_HANDLE             ObjHandle,
    102  1.1  christos     UINT32                  NestingLevel,
    103  1.1  christos     void                    *Context,
    104  1.1  christos     void                    **ReturnValue);
    105  1.1  christos 
    106  1.1  christos /*
    107  1.1  christos  * Test subcommands
    108  1.1  christos  */
    109  1.1  christos static ACPI_DB_ARGUMENT_INFO    AcpiDbTestTypes [] =
    110  1.1  christos {
    111  1.1  christos     {"OBJECTS"},
    112  1.1  christos     {"PREDEFINED"},
    113  1.1  christos     {NULL}           /* Must be null terminated */
    114  1.1  christos };
    115  1.1  christos 
    116  1.1  christos #define CMD_TEST_OBJECTS        0
    117  1.1  christos #define CMD_TEST_PREDEFINED     1
    118  1.1  christos 
    119  1.1  christos #define BUFFER_FILL_VALUE       0xFF
    120  1.1  christos 
    121  1.1  christos /*
    122  1.1  christos  * Support for the special debugger read/write control methods.
    123  1.1  christos  * These methods are installed into the current namespace and are
    124  1.1  christos  * used to read and write the various namespace objects. The point
    125  1.1  christos  * is to force the AML interpreter do all of the work.
    126  1.1  christos  */
    127  1.1  christos #define                     ACPI_DB_READ_METHOD     "\\_T98"
    128  1.1  christos #define                     ACPI_DB_WRITE_METHOD    "\\_T99"
    129  1.1  christos 
    130  1.1  christos static ACPI_HANDLE          ReadHandle = NULL;
    131  1.1  christos static ACPI_HANDLE          WriteHandle = NULL;
    132  1.1  christos 
    133  1.1  christos /* ASL Definitions of the debugger read/write control methods */
    134  1.1  christos 
    135  1.1  christos #if 0
    136  1.1  christos DefinitionBlock ("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
    137  1.1  christos {
    138  1.1  christos     Method (_T98, 1, NotSerialized)     /* Read */
    139  1.1  christos     {
    140  1.1  christos         Return (DeRefOf (Arg0))
    141  1.1  christos     }
    142  1.1  christos }
    143  1.1  christos DefinitionBlock ("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
    144  1.1  christos {
    145  1.1  christos     Method (_T99, 2, NotSerialized)     /* Write */
    146  1.1  christos     {
    147  1.1  christos         Store (Arg1, Arg0)
    148  1.1  christos     }
    149  1.1  christos }
    150  1.1  christos #endif
    151  1.1  christos 
    152  1.1  christos static unsigned char ReadMethodCode[] =
    153  1.1  christos {
    154  1.1  christos     0x53,0x53,0x44,0x54,0x2E,0x00,0x00,0x00,  /* 00000000    "SSDT...." */
    155  1.1  christos     0x02,0xC9,0x49,0x6E,0x74,0x65,0x6C,0x00,  /* 00000008    "..Intel." */
    156  1.1  christos     0x44,0x45,0x42,0x55,0x47,0x00,0x00,0x00,  /* 00000010    "DEBUG..." */
    157  1.1  christos     0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C,  /* 00000018    "....INTL" */
    158  1.1  christos     0x18,0x12,0x13,0x20,0x14,0x09,0x5F,0x54,  /* 00000020    "... .._T" */
    159  1.1  christos     0x39,0x38,0x01,0xA4,0x83,0x68             /* 00000028    "98...h"   */
    160  1.1  christos };
    161  1.1  christos 
    162  1.1  christos static unsigned char WriteMethodCode[] =
    163  1.1  christos {
    164  1.1  christos     0x53,0x53,0x44,0x54,0x2E,0x00,0x00,0x00,  /* 00000000    "SSDT...." */
    165  1.1  christos     0x02,0x15,0x49,0x6E,0x74,0x65,0x6C,0x00,  /* 00000008    "..Intel." */
    166  1.1  christos     0x44,0x45,0x42,0x55,0x47,0x00,0x00,0x00,  /* 00000010    "DEBUG..." */
    167  1.1  christos     0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C,  /* 00000018    "....INTL" */
    168  1.1  christos     0x18,0x12,0x13,0x20,0x14,0x09,0x5F,0x54,  /* 00000020    "... .._T" */
    169  1.1  christos     0x39,0x39,0x02,0x70,0x69,0x68             /* 00000028    "99.pih"   */
    170  1.1  christos };
    171  1.1  christos 
    172  1.1  christos 
    173  1.1  christos /*******************************************************************************
    174  1.1  christos  *
    175  1.1  christos  * FUNCTION:    AcpiDbExecuteTest
    176  1.1  christos  *
    177  1.1  christos  * PARAMETERS:  TypeArg         - Subcommand
    178  1.1  christos  *
    179  1.1  christos  * RETURN:      None
    180  1.1  christos  *
    181  1.1  christos  * DESCRIPTION: Execute various debug tests.
    182  1.1  christos  *
    183  1.1  christos  * Note: Code is prepared for future expansion of the TEST command.
    184  1.1  christos  *
    185  1.1  christos  ******************************************************************************/
    186  1.1  christos 
    187  1.1  christos void
    188  1.1  christos AcpiDbExecuteTest (
    189  1.1  christos     char                    *TypeArg)
    190  1.1  christos {
    191  1.1  christos     UINT32                  Temp;
    192  1.1  christos 
    193  1.1  christos 
    194  1.1  christos     AcpiUtStrupr (TypeArg);
    195  1.1  christos     Temp = AcpiDbMatchArgument (TypeArg, AcpiDbTestTypes);
    196  1.1  christos     if (Temp == ACPI_TYPE_NOT_FOUND)
    197  1.1  christos     {
    198  1.1  christos         AcpiOsPrintf ("Invalid or unsupported argument\n");
    199  1.1  christos         return;
    200  1.1  christos     }
    201  1.1  christos 
    202  1.1  christos     switch (Temp)
    203  1.1  christos     {
    204  1.1  christos     case CMD_TEST_OBJECTS:
    205  1.1  christos 
    206  1.1  christos         AcpiDbTestAllObjects ();
    207  1.1  christos         break;
    208  1.1  christos 
    209  1.1  christos     case CMD_TEST_PREDEFINED:
    210  1.1  christos 
    211  1.1  christos         AcpiDbEvaluateAllPredefinedNames (NULL);
    212  1.1  christos         break;
    213  1.1  christos 
    214  1.1  christos     default:
    215  1.1  christos         break;
    216  1.1  christos     }
    217  1.1  christos }
    218  1.1  christos 
    219  1.1  christos 
    220  1.1  christos /*******************************************************************************
    221  1.1  christos  *
    222  1.1  christos  * FUNCTION:    AcpiDbTestAllObjects
    223  1.1  christos  *
    224  1.1  christos  * PARAMETERS:  None
    225  1.1  christos  *
    226  1.1  christos  * RETURN:      None
    227  1.1  christos  *
    228  1.1  christos  * DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the
    229  1.1  christos  *              namespace by reading/writing/comparing all data objects such
    230  1.1  christos  *              as integers, strings, buffers, fields, buffer fields, etc.
    231  1.1  christos  *
    232  1.1  christos  ******************************************************************************/
    233  1.1  christos 
    234  1.1  christos static void
    235  1.1  christos AcpiDbTestAllObjects (
    236  1.1  christos     void)
    237  1.1  christos {
    238  1.1  christos     ACPI_STATUS             Status;
    239  1.1  christos 
    240  1.1  christos 
    241  1.1  christos     /* Install the debugger read-object control method if necessary */
    242  1.1  christos 
    243  1.1  christos     if (!ReadHandle)
    244  1.1  christos     {
    245  1.1  christos         Status = AcpiInstallMethod (ReadMethodCode);
    246  1.1  christos         if (ACPI_FAILURE (Status))
    247  1.1  christos         {
    248  1.1  christos             AcpiOsPrintf ("%s, Could not install debugger read method\n",
    249  1.1  christos                 AcpiFormatException (Status));
    250  1.1  christos             return;
    251  1.1  christos         }
    252  1.1  christos 
    253  1.1  christos         Status = AcpiGetHandle (NULL, ACPI_DB_READ_METHOD, &ReadHandle);
    254  1.1  christos         if (ACPI_FAILURE (Status))
    255  1.1  christos         {
    256  1.1  christos             AcpiOsPrintf ("Could not obtain handle for debug method %s\n",
    257  1.1  christos                 ACPI_DB_READ_METHOD);
    258  1.1  christos             return;
    259  1.1  christos         }
    260  1.1  christos     }
    261  1.1  christos 
    262  1.1  christos     /* Install the debugger write-object control method if necessary */
    263  1.1  christos 
    264  1.1  christos     if (!WriteHandle)
    265  1.1  christos     {
    266  1.1  christos         Status = AcpiInstallMethod (WriteMethodCode);
    267  1.1  christos         if (ACPI_FAILURE (Status))
    268  1.1  christos         {
    269  1.1  christos             AcpiOsPrintf ("%s, Could not install debugger write method\n",
    270  1.1  christos                 AcpiFormatException (Status));
    271  1.1  christos             return;
    272  1.1  christos         }
    273  1.1  christos 
    274  1.1  christos         Status = AcpiGetHandle (NULL, ACPI_DB_WRITE_METHOD, &WriteHandle);
    275  1.1  christos         if (ACPI_FAILURE (Status))
    276  1.1  christos         {
    277  1.1  christos             AcpiOsPrintf ("Could not obtain handle for debug method %s\n",
    278  1.1  christos                 ACPI_DB_WRITE_METHOD);
    279  1.1  christos             return;
    280  1.1  christos         }
    281  1.1  christos     }
    282  1.1  christos 
    283  1.1  christos     /* Walk the entire namespace, testing each supported named data object */
    284  1.1  christos 
    285  1.1  christos     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    286  1.1  christos                 ACPI_UINT32_MAX, AcpiDbTestOneObject, NULL, NULL, NULL);
    287  1.1  christos }
    288  1.1  christos 
    289  1.1  christos 
    290  1.1  christos /*******************************************************************************
    291  1.1  christos  *
    292  1.1  christos  * FUNCTION:    AcpiDbTestOneObject
    293  1.1  christos  *
    294  1.1  christos  * PARAMETERS:  ACPI_WALK_CALLBACK
    295  1.1  christos  *
    296  1.1  christos  * RETURN:      Status
    297  1.1  christos  *
    298  1.1  christos  * DESCRIPTION: Test one namespace object. Supported types are Integer,
    299  1.1  christos  *              String, Buffer, BufferField, and FieldUnit. All other object
    300  1.1  christos  *              types are simply ignored.
    301  1.1  christos  *
    302  1.1  christos  *              Note: Support for Packages is not implemented.
    303  1.1  christos  *
    304  1.1  christos  ******************************************************************************/
    305  1.1  christos 
    306  1.1  christos static ACPI_STATUS
    307  1.1  christos AcpiDbTestOneObject (
    308  1.1  christos     ACPI_HANDLE             ObjHandle,
    309  1.1  christos     UINT32                  NestingLevel,
    310  1.1  christos     void                    *Context,
    311  1.1  christos     void                    **ReturnValue)
    312  1.1  christos {
    313  1.1  christos     ACPI_NAMESPACE_NODE     *Node;
    314  1.1  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    315  1.1  christos     ACPI_OPERAND_OBJECT     *RegionObj;
    316  1.1  christos     ACPI_OBJECT_TYPE        LocalType;
    317  1.1  christos     UINT32                  BitLength = 0;
    318  1.1  christos     UINT32                  ByteLength = 0;
    319  1.1  christos     ACPI_STATUS             Status = AE_OK;
    320  1.1  christos 
    321  1.1  christos 
    322  1.1  christos     Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
    323  1.1  christos     ObjDesc = Node->Object;
    324  1.1  christos 
    325  1.1  christos     /*
    326  1.1  christos      * For the supported types, get the actual bit length or
    327  1.1  christos      * byte length. Map the type to one of Integer/String/Buffer.
    328  1.1  christos      */
    329  1.1  christos     switch (Node->Type)
    330  1.1  christos     {
    331  1.1  christos     case ACPI_TYPE_INTEGER:
    332  1.1  christos 
    333  1.1  christos         /* Integer width is either 32 or 64 */
    334  1.1  christos 
    335  1.1  christos         LocalType = ACPI_TYPE_INTEGER;
    336  1.1  christos         BitLength = AcpiGbl_IntegerBitWidth;
    337  1.1  christos         break;
    338  1.1  christos 
    339  1.1  christos     case ACPI_TYPE_STRING:
    340  1.1  christos 
    341  1.1  christos         LocalType = ACPI_TYPE_STRING;
    342  1.1  christos         ByteLength = ObjDesc->String.Length;
    343  1.1  christos         break;
    344  1.1  christos 
    345  1.1  christos     case ACPI_TYPE_BUFFER:
    346  1.1  christos 
    347  1.1  christos         LocalType = ACPI_TYPE_BUFFER;
    348  1.1  christos         ByteLength = ObjDesc->Buffer.Length;
    349  1.1  christos         BitLength = ByteLength * 8;
    350  1.1  christos         break;
    351  1.1  christos 
    352  1.1  christos     case ACPI_TYPE_FIELD_UNIT:
    353  1.1  christos     case ACPI_TYPE_BUFFER_FIELD:
    354  1.1  christos     case ACPI_TYPE_LOCAL_REGION_FIELD:
    355  1.1  christos     case ACPI_TYPE_LOCAL_INDEX_FIELD:
    356  1.1  christos     case ACPI_TYPE_LOCAL_BANK_FIELD:
    357  1.1  christos 
    358  1.1  christos         LocalType = ACPI_TYPE_INTEGER;
    359  1.1  christos         if (ObjDesc)
    360  1.1  christos         {
    361  1.1  christos             /*
    362  1.1  christos              * Returned object will be a Buffer if the field length
    363  1.1  christos              * is larger than the size of an Integer (32 or 64 bits
    364  1.1  christos              * depending on the DSDT version).
    365  1.1  christos              */
    366  1.1  christos             BitLength = ObjDesc->CommonField.BitLength;
    367  1.1  christos             ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);
    368  1.1  christos             if (BitLength > AcpiGbl_IntegerBitWidth)
    369  1.1  christos             {
    370  1.1  christos                 LocalType = ACPI_TYPE_BUFFER;
    371  1.1  christos             }
    372  1.1  christos         }
    373  1.1  christos         break;
    374  1.1  christos 
    375  1.1  christos     default:
    376  1.1  christos 
    377  1.1  christos         /* Ignore all other types */
    378  1.1  christos 
    379  1.1  christos         return (AE_OK);
    380  1.1  christos     }
    381  1.1  christos 
    382  1.1  christos     /* Emit the common prefix: Type:Name */
    383  1.1  christos 
    384  1.1  christos     AcpiOsPrintf ("%14s: %4.4s",
    385  1.1  christos         AcpiUtGetTypeName (Node->Type), Node->Name.Ascii);
    386  1.1  christos     if (!ObjDesc)
    387  1.1  christos     {
    388  1.1  christos         AcpiOsPrintf (" Ignoring, no attached object\n");
    389  1.1  christos         return (AE_OK);
    390  1.1  christos     }
    391  1.1  christos 
    392  1.1  christos     /*
    393  1.1  christos      * Check for unsupported region types. Note: AcpiExec simulates
    394  1.1  christos      * access to SystemMemory, SystemIO, PCI_Config, and EC.
    395  1.1  christos      */
    396  1.1  christos     switch (Node->Type)
    397  1.1  christos     {
    398  1.1  christos     case ACPI_TYPE_LOCAL_REGION_FIELD:
    399  1.1  christos 
    400  1.1  christos         RegionObj = ObjDesc->Field.RegionObj;
    401  1.1  christos         switch (RegionObj->Region.SpaceId)
    402  1.1  christos         {
    403  1.1  christos         case ACPI_ADR_SPACE_SYSTEM_MEMORY:
    404  1.1  christos         case ACPI_ADR_SPACE_SYSTEM_IO:
    405  1.1  christos         case ACPI_ADR_SPACE_PCI_CONFIG:
    406  1.1  christos         case ACPI_ADR_SPACE_EC:
    407  1.1  christos 
    408  1.1  christos             break;
    409  1.1  christos 
    410  1.1  christos         default:
    411  1.1  christos 
    412  1.1  christos             AcpiOsPrintf ("      %s space is not supported [%4.4s]\n",
    413  1.1  christos                 AcpiUtGetRegionName (RegionObj->Region.SpaceId),
    414  1.1  christos                 RegionObj->Region.Node->Name.Ascii);
    415  1.1  christos             return (AE_OK);
    416  1.1  christos         }
    417  1.1  christos         break;
    418  1.1  christos 
    419  1.1  christos     default:
    420  1.1  christos         break;
    421  1.1  christos     }
    422  1.1  christos 
    423  1.1  christos     /* At this point, we have resolved the object to one of the major types */
    424  1.1  christos 
    425  1.1  christos     switch (LocalType)
    426  1.1  christos     {
    427  1.1  christos     case ACPI_TYPE_INTEGER:
    428  1.1  christos 
    429  1.1  christos         Status = AcpiDbTestIntegerType (Node, BitLength);
    430  1.1  christos         break;
    431  1.1  christos 
    432  1.1  christos     case ACPI_TYPE_STRING:
    433  1.1  christos 
    434  1.1  christos         Status = AcpiDbTestStringType (Node, ByteLength);
    435  1.1  christos         break;
    436  1.1  christos 
    437  1.1  christos     case ACPI_TYPE_BUFFER:
    438  1.1  christos 
    439  1.1  christos         Status = AcpiDbTestBufferType (Node, BitLength);
    440  1.1  christos         break;
    441  1.1  christos 
    442  1.1  christos     default:
    443  1.1  christos 
    444  1.1  christos         AcpiOsPrintf (" Ignoring, type not implemented (%2.2X)",
    445  1.1  christos             LocalType);
    446  1.1  christos         break;
    447  1.1  christos     }
    448  1.1  christos 
    449  1.1  christos     switch (Node->Type)
    450  1.1  christos     {
    451  1.1  christos     case ACPI_TYPE_LOCAL_REGION_FIELD:
    452  1.1  christos 
    453  1.1  christos         RegionObj = ObjDesc->Field.RegionObj;
    454  1.1  christos         AcpiOsPrintf (" (%s)",
    455  1.1  christos             AcpiUtGetRegionName (RegionObj->Region.SpaceId));
    456  1.1  christos         break;
    457  1.1  christos 
    458  1.1  christos     default:
    459  1.1  christos         break;
    460  1.1  christos     }
    461  1.1  christos 
    462  1.1  christos     AcpiOsPrintf ("\n");
    463  1.1  christos     return (Status);
    464  1.1  christos }
    465  1.1  christos 
    466  1.1  christos 
    467  1.1  christos /*******************************************************************************
    468  1.1  christos  *
    469  1.1  christos  * FUNCTION:    AcpiDbTestIntegerType
    470  1.1  christos  *
    471  1.1  christos  * PARAMETERS:  Node                - Parent NS node for the object
    472  1.1  christos  *              BitLength           - Actual length of the object. Used for
    473  1.1  christos  *                                    support of arbitrary length FieldUnit
    474  1.1  christos  *                                    and BufferField objects.
    475  1.1  christos  *
    476  1.1  christos  * RETURN:      Status
    477  1.1  christos  *
    478  1.1  christos  * DESCRIPTION: Test read/write for an Integer-valued object. Performs a
    479  1.1  christos  *              write/read/compare of an arbitrary new value, then performs
    480  1.1  christos  *              a write/read/compare of the original value.
    481  1.1  christos  *
    482  1.1  christos  ******************************************************************************/
    483  1.1  christos 
    484  1.1  christos static ACPI_STATUS
    485  1.1  christos AcpiDbTestIntegerType (
    486  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
    487  1.1  christos     UINT32                  BitLength)
    488  1.1  christos {
    489  1.1  christos     ACPI_OBJECT             *Temp1 = NULL;
    490  1.1  christos     ACPI_OBJECT             *Temp2 = NULL;
    491  1.1  christos     ACPI_OBJECT             *Temp3 = NULL;
    492  1.1  christos     ACPI_OBJECT             WriteValue;
    493  1.1  christos     UINT64                  ValueToWrite;
    494  1.1  christos     ACPI_STATUS             Status;
    495  1.1  christos 
    496  1.1  christos 
    497  1.1  christos     if (BitLength > 64)
    498  1.1  christos     {
    499  1.1  christos         AcpiOsPrintf (" Invalid length for an Integer: %u", BitLength);
    500  1.1  christos         return (AE_OK);
    501  1.1  christos     }
    502  1.1  christos 
    503  1.1  christos     /* Read the original value */
    504  1.1  christos 
    505  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp1);
    506  1.1  christos     if (ACPI_FAILURE (Status))
    507  1.1  christos     {
    508  1.1  christos         return (Status);
    509  1.1  christos     }
    510  1.1  christos 
    511  1.1  christos     AcpiOsPrintf (" (%4.4X/%3.3X) %8.8X%8.8X",
    512  1.1  christos         BitLength, ACPI_ROUND_BITS_UP_TO_BYTES (BitLength),
    513  1.1  christos         ACPI_FORMAT_UINT64 (Temp1->Integer.Value));
    514  1.1  christos 
    515  1.1  christos     ValueToWrite = ACPI_UINT64_MAX >> (64 - BitLength);
    516  1.1  christos     if (Temp1->Integer.Value == ValueToWrite)
    517  1.1  christos     {
    518  1.1  christos         ValueToWrite = 0;
    519  1.1  christos     }
    520  1.1  christos 
    521  1.1  christos     /* Write a new value */
    522  1.1  christos 
    523  1.1  christos     WriteValue.Type = ACPI_TYPE_INTEGER;
    524  1.1  christos     WriteValue.Integer.Value = ValueToWrite;
    525  1.1  christos     Status = AcpiDbWriteToObject (Node, &WriteValue);
    526  1.1  christos     if (ACPI_FAILURE (Status))
    527  1.1  christos     {
    528  1.1  christos         goto Exit;
    529  1.1  christos     }
    530  1.1  christos 
    531  1.1  christos     /* Ensure that we can read back the new value */
    532  1.1  christos 
    533  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp2);
    534  1.1  christos     if (ACPI_FAILURE (Status))
    535  1.1  christos     {
    536  1.1  christos         goto Exit;
    537  1.1  christos     }
    538  1.1  christos 
    539  1.1  christos     if (Temp2->Integer.Value != ValueToWrite)
    540  1.1  christos     {
    541  1.1  christos         AcpiOsPrintf (" MISMATCH 2: %8.8X%8.8X, expecting %8.8X%8.8X",
    542  1.1  christos             ACPI_FORMAT_UINT64 (Temp2->Integer.Value),
    543  1.1  christos             ACPI_FORMAT_UINT64 (ValueToWrite));
    544  1.1  christos     }
    545  1.1  christos 
    546  1.1  christos     /* Write back the original value */
    547  1.1  christos 
    548  1.1  christos     WriteValue.Integer.Value = Temp1->Integer.Value;
    549  1.1  christos     Status = AcpiDbWriteToObject (Node, &WriteValue);
    550  1.1  christos     if (ACPI_FAILURE (Status))
    551  1.1  christos     {
    552  1.1  christos         goto Exit;
    553  1.1  christos     }
    554  1.1  christos 
    555  1.1  christos     /* Ensure that we can read back the original value */
    556  1.1  christos 
    557  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp3);
    558  1.1  christos     if (ACPI_FAILURE (Status))
    559  1.1  christos     {
    560  1.1  christos         goto Exit;
    561  1.1  christos     }
    562  1.1  christos 
    563  1.1  christos     if (Temp3->Integer.Value != Temp1->Integer.Value)
    564  1.1  christos     {
    565  1.1  christos         AcpiOsPrintf (" MISMATCH 3: %8.8X%8.8X, expecting %8.8X%8.8X",
    566  1.1  christos             ACPI_FORMAT_UINT64 (Temp3->Integer.Value),
    567  1.1  christos             ACPI_FORMAT_UINT64 (Temp1->Integer.Value));
    568  1.1  christos     }
    569  1.1  christos 
    570  1.1  christos Exit:
    571  1.1  christos     if (Temp1) {AcpiOsFree (Temp1);}
    572  1.1  christos     if (Temp2) {AcpiOsFree (Temp2);}
    573  1.1  christos     if (Temp3) {AcpiOsFree (Temp3);}
    574  1.1  christos     return (AE_OK);
    575  1.1  christos }
    576  1.1  christos 
    577  1.1  christos 
    578  1.1  christos /*******************************************************************************
    579  1.1  christos  *
    580  1.1  christos  * FUNCTION:    AcpiDbTestBufferType
    581  1.1  christos  *
    582  1.1  christos  * PARAMETERS:  Node                - Parent NS node for the object
    583  1.1  christos  *              BitLength           - Actual length of the object.
    584  1.1  christos  *
    585  1.1  christos  * RETURN:      Status
    586  1.1  christos  *
    587  1.1  christos  * DESCRIPTION: Test read/write for an Buffer-valued object. Performs a
    588  1.1  christos  *              write/read/compare of an arbitrary new value, then performs
    589  1.1  christos  *              a write/read/compare of the original value.
    590  1.1  christos  *
    591  1.1  christos  ******************************************************************************/
    592  1.1  christos 
    593  1.1  christos static ACPI_STATUS
    594  1.1  christos AcpiDbTestBufferType (
    595  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
    596  1.1  christos     UINT32                  BitLength)
    597  1.1  christos {
    598  1.1  christos     ACPI_OBJECT             *Temp1 = NULL;
    599  1.1  christos     ACPI_OBJECT             *Temp2 = NULL;
    600  1.1  christos     ACPI_OBJECT             *Temp3 = NULL;
    601  1.1  christos     UINT8                   *Buffer;
    602  1.1  christos     ACPI_OBJECT             WriteValue;
    603  1.1  christos     ACPI_STATUS             Status;
    604  1.1  christos     UINT32                  ByteLength;
    605  1.1  christos     UINT32                  i;
    606  1.1  christos     UINT8                   ExtraBits;
    607  1.1  christos 
    608  1.1  christos 
    609  1.1  christos     ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);
    610  1.1  christos     if (ByteLength == 0)
    611  1.1  christos     {
    612  1.1  christos         AcpiOsPrintf (" Ignoring zero length buffer");
    613  1.1  christos         return (AE_OK);
    614  1.1  christos     }
    615  1.1  christos 
    616  1.1  christos     /* Allocate a local buffer */
    617  1.1  christos 
    618  1.1  christos     Buffer = ACPI_ALLOCATE_ZEROED (ByteLength);
    619  1.1  christos     if (!Buffer)
    620  1.1  christos     {
    621  1.1  christos         return (AE_NO_MEMORY);
    622  1.1  christos     }
    623  1.1  christos 
    624  1.1  christos     /* Read the original value */
    625  1.1  christos 
    626  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp1);
    627  1.1  christos     if (ACPI_FAILURE (Status))
    628  1.1  christos     {
    629  1.1  christos         goto Exit;
    630  1.1  christos     }
    631  1.1  christos 
    632  1.1  christos     /* Emit a few bytes of the buffer */
    633  1.1  christos 
    634  1.1  christos     AcpiOsPrintf (" (%4.4X/%3.3X)", BitLength, Temp1->Buffer.Length);
    635  1.1  christos     for (i = 0; ((i < 4) && (i < ByteLength)); i++)
    636  1.1  christos     {
    637  1.1  christos         AcpiOsPrintf (" %2.2X", Temp1->Buffer.Pointer[i]);
    638  1.1  christos     }
    639  1.1  christos     AcpiOsPrintf ("...  ");
    640  1.1  christos 
    641  1.1  christos     /*
    642  1.1  christos      * Write a new value.
    643  1.1  christos      *
    644  1.1  christos      * Handle possible extra bits at the end of the buffer. Can
    645  1.1  christos      * happen for FieldUnits larger than an integer, but the bit
    646  1.1  christos      * count is not an integral number of bytes. Zero out the
    647  1.1  christos      * unused bits.
    648  1.1  christos      */
    649  1.1  christos     ACPI_MEMSET (Buffer, BUFFER_FILL_VALUE, ByteLength);
    650  1.1  christos     ExtraBits = BitLength % 8;
    651  1.1  christos     if (ExtraBits)
    652  1.1  christos     {
    653  1.1  christos         Buffer [ByteLength - 1] = ACPI_MASK_BITS_ABOVE (ExtraBits);
    654  1.1  christos     }
    655  1.1  christos 
    656  1.1  christos     WriteValue.Type = ACPI_TYPE_BUFFER;
    657  1.1  christos     WriteValue.Buffer.Length = ByteLength;
    658  1.1  christos     WriteValue.Buffer.Pointer = Buffer;
    659  1.1  christos 
    660  1.1  christos     Status = AcpiDbWriteToObject (Node, &WriteValue);
    661  1.1  christos     if (ACPI_FAILURE (Status))
    662  1.1  christos     {
    663  1.1  christos         goto Exit;
    664  1.1  christos     }
    665  1.1  christos 
    666  1.1  christos     /* Ensure that we can read back the new value */
    667  1.1  christos 
    668  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp2);
    669  1.1  christos     if (ACPI_FAILURE (Status))
    670  1.1  christos     {
    671  1.1  christos         goto Exit;
    672  1.1  christos     }
    673  1.1  christos 
    674  1.1  christos     if (ACPI_MEMCMP (Temp2->Buffer.Pointer, Buffer, ByteLength))
    675  1.1  christos     {
    676  1.1  christos         AcpiOsPrintf (" MISMATCH 2: New buffer value");
    677  1.1  christos     }
    678  1.1  christos 
    679  1.1  christos     /* Write back the original value */
    680  1.1  christos 
    681  1.1  christos     WriteValue.Buffer.Length = ByteLength;
    682  1.1  christos     WriteValue.Buffer.Pointer = Temp1->Buffer.Pointer;
    683  1.1  christos 
    684  1.1  christos     Status = AcpiDbWriteToObject (Node, &WriteValue);
    685  1.1  christos     if (ACPI_FAILURE (Status))
    686  1.1  christos     {
    687  1.1  christos         goto Exit;
    688  1.1  christos     }
    689  1.1  christos 
    690  1.1  christos     /* Ensure that we can read back the original value */
    691  1.1  christos 
    692  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp3);
    693  1.1  christos     if (ACPI_FAILURE (Status))
    694  1.1  christos     {
    695  1.1  christos         goto Exit;
    696  1.1  christos     }
    697  1.1  christos 
    698  1.1  christos     if (ACPI_MEMCMP (Temp1->Buffer.Pointer, Temp3->Buffer.Pointer, ByteLength))
    699  1.1  christos     {
    700  1.1  christos         AcpiOsPrintf (" MISMATCH 3: While restoring original buffer");
    701  1.1  christos     }
    702  1.1  christos 
    703  1.1  christos Exit:
    704  1.1  christos     ACPI_FREE (Buffer);
    705  1.1  christos     if (Temp1) {AcpiOsFree (Temp1);}
    706  1.1  christos     if (Temp2) {AcpiOsFree (Temp2);}
    707  1.1  christos     if (Temp3) {AcpiOsFree (Temp3);}
    708  1.1  christos     return (Status);
    709  1.1  christos }
    710  1.1  christos 
    711  1.1  christos 
    712  1.1  christos /*******************************************************************************
    713  1.1  christos  *
    714  1.1  christos  * FUNCTION:    AcpiDbTestStringType
    715  1.1  christos  *
    716  1.1  christos  * PARAMETERS:  Node                - Parent NS node for the object
    717  1.1  christos  *              ByteLength          - Actual length of the object.
    718  1.1  christos  *
    719  1.1  christos  * RETURN:      Status
    720  1.1  christos  *
    721  1.1  christos  * DESCRIPTION: Test read/write for an String-valued object. Performs a
    722  1.1  christos  *              write/read/compare of an arbitrary new value, then performs
    723  1.1  christos  *              a write/read/compare of the original value.
    724  1.1  christos  *
    725  1.1  christos  ******************************************************************************/
    726  1.1  christos 
    727  1.1  christos static ACPI_STATUS
    728  1.1  christos AcpiDbTestStringType (
    729  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
    730  1.1  christos     UINT32                  ByteLength)
    731  1.1  christos {
    732  1.1  christos     ACPI_OBJECT             *Temp1 = NULL;
    733  1.1  christos     ACPI_OBJECT             *Temp2 = NULL;
    734  1.1  christos     ACPI_OBJECT             *Temp3 = NULL;
    735  1.1  christos     char                    *ValueToWrite = "Test String from AML Debugger";
    736  1.1  christos     ACPI_OBJECT             WriteValue;
    737  1.1  christos     ACPI_STATUS             Status;
    738  1.1  christos 
    739  1.1  christos 
    740  1.1  christos     /* Read the original value */
    741  1.1  christos 
    742  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp1);
    743  1.1  christos     if (ACPI_FAILURE (Status))
    744  1.1  christos     {
    745  1.1  christos         return (Status);
    746  1.1  christos     }
    747  1.1  christos 
    748  1.1  christos     AcpiOsPrintf (" (%4.4X/%3.3X) \"%s\"", (Temp1->String.Length * 8),
    749  1.1  christos         Temp1->String.Length, Temp1->String.Pointer);
    750  1.1  christos 
    751  1.1  christos     /* Write a new value */
    752  1.1  christos 
    753  1.1  christos     WriteValue.Type = ACPI_TYPE_STRING;
    754  1.1  christos     WriteValue.String.Length = ACPI_STRLEN (ValueToWrite);
    755  1.1  christos     WriteValue.String.Pointer = ValueToWrite;
    756  1.1  christos 
    757  1.1  christos     Status = AcpiDbWriteToObject (Node, &WriteValue);
    758  1.1  christos     if (ACPI_FAILURE (Status))
    759  1.1  christos     {
    760  1.1  christos         goto Exit;
    761  1.1  christos     }
    762  1.1  christos 
    763  1.1  christos     /* Ensure that we can read back the new value */
    764  1.1  christos 
    765  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp2);
    766  1.1  christos     if (ACPI_FAILURE (Status))
    767  1.1  christos     {
    768  1.1  christos         goto Exit;
    769  1.1  christos     }
    770  1.1  christos 
    771  1.1  christos     if (ACPI_STRCMP (Temp2->String.Pointer, ValueToWrite))
    772  1.1  christos     {
    773  1.1  christos         AcpiOsPrintf (" MISMATCH 2: %s, expecting %s",
    774  1.1  christos             Temp2->String.Pointer, ValueToWrite);
    775  1.1  christos     }
    776  1.1  christos 
    777  1.1  christos     /* Write back the original value */
    778  1.1  christos 
    779  1.1  christos     WriteValue.String.Length = ACPI_STRLEN (Temp1->String.Pointer);
    780  1.1  christos     WriteValue.String.Pointer = Temp1->String.Pointer;
    781  1.1  christos 
    782  1.1  christos     Status = AcpiDbWriteToObject (Node, &WriteValue);
    783  1.1  christos     if (ACPI_FAILURE (Status))
    784  1.1  christos     {
    785  1.1  christos         goto Exit;
    786  1.1  christos     }
    787  1.1  christos 
    788  1.1  christos     /* Ensure that we can read back the original value */
    789  1.1  christos 
    790  1.1  christos     Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp3);
    791  1.1  christos     if (ACPI_FAILURE (Status))
    792  1.1  christos     {
    793  1.1  christos         goto Exit;
    794  1.1  christos     }
    795  1.1  christos 
    796  1.1  christos     if (ACPI_STRCMP (Temp1->String.Pointer, Temp3->String.Pointer))
    797  1.1  christos     {
    798  1.1  christos         AcpiOsPrintf (" MISMATCH 3: %s, expecting %s",
    799  1.1  christos             Temp3->String.Pointer, Temp1->String.Pointer);
    800  1.1  christos     }
    801  1.1  christos 
    802  1.1  christos Exit:
    803  1.1  christos     if (Temp1) {AcpiOsFree (Temp1);}
    804  1.1  christos     if (Temp2) {AcpiOsFree (Temp2);}
    805  1.1  christos     if (Temp3) {AcpiOsFree (Temp3);}
    806  1.1  christos     return (Status);
    807  1.1  christos }
    808  1.1  christos 
    809  1.1  christos 
    810  1.1  christos /*******************************************************************************
    811  1.1  christos  *
    812  1.1  christos  * FUNCTION:    AcpiDbReadFromObject
    813  1.1  christos  *
    814  1.1  christos  * PARAMETERS:  Node                - Parent NS node for the object
    815  1.1  christos  *              ExpectedType        - Object type expected from the read
    816  1.1  christos  *              Value               - Where the value read is returned
    817  1.1  christos  *
    818  1.1  christos  * RETURN:      Status
    819  1.1  christos  *
    820  1.1  christos  * DESCRIPTION: Performs a read from the specified object by invoking the
    821  1.1  christos  *              special debugger control method that reads the object. Thus,
    822  1.1  christos  *              the AML interpreter is doing all of the work, increasing the
    823  1.1  christos  *              validity of the test.
    824  1.1  christos  *
    825  1.1  christos  ******************************************************************************/
    826  1.1  christos 
    827  1.1  christos static ACPI_STATUS
    828  1.1  christos AcpiDbReadFromObject (
    829  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
    830  1.1  christos     ACPI_OBJECT_TYPE        ExpectedType,
    831  1.1  christos     ACPI_OBJECT             **Value)
    832  1.1  christos {
    833  1.1  christos     ACPI_OBJECT             *RetValue;
    834  1.1  christos     ACPI_OBJECT_LIST        ParamObjects;
    835  1.1  christos     ACPI_OBJECT             Params[2];
    836  1.1  christos     ACPI_BUFFER             ReturnObj;
    837  1.1  christos     ACPI_STATUS             Status;
    838  1.1  christos 
    839  1.1  christos 
    840  1.1  christos     Params[0].Type = ACPI_TYPE_LOCAL_REFERENCE;
    841  1.1  christos     Params[0].Reference.ActualType = Node->Type;
    842  1.1  christos     Params[0].Reference.Handle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
    843  1.1  christos 
    844  1.1  christos     ParamObjects.Count = 1;
    845  1.1  christos     ParamObjects.Pointer = Params;
    846  1.1  christos 
    847  1.1  christos     ReturnObj.Length  = ACPI_ALLOCATE_BUFFER;
    848  1.1  christos 
    849  1.1  christos     AcpiGbl_MethodExecuting = TRUE;
    850  1.1  christos     Status = AcpiEvaluateObject (ReadHandle, NULL, &ParamObjects, &ReturnObj);
    851  1.1  christos     AcpiGbl_MethodExecuting = FALSE;
    852  1.1  christos 
    853  1.1  christos     if (ACPI_FAILURE (Status))
    854  1.1  christos     {
    855  1.1  christos         AcpiOsPrintf ("Could not read from object, %s",
    856  1.1  christos             AcpiFormatException (Status));
    857  1.1  christos         return (Status);
    858  1.1  christos     }
    859  1.1  christos 
    860  1.1  christos     RetValue = (ACPI_OBJECT *) ReturnObj.Pointer;
    861  1.1  christos 
    862  1.1  christos     switch (RetValue->Type)
    863  1.1  christos     {
    864  1.1  christos     case ACPI_TYPE_INTEGER:
    865  1.1  christos     case ACPI_TYPE_BUFFER:
    866  1.1  christos     case ACPI_TYPE_STRING:
    867  1.1  christos         /*
    868  1.1  christos          * Did we receive the type we wanted? Most important for the
    869  1.1  christos          * Integer/Buffer case (when a field is larger than an Integer,
    870  1.1  christos          * it should return a Buffer).
    871  1.1  christos          */
    872  1.1  christos         if (RetValue->Type != ExpectedType)
    873  1.1  christos         {
    874  1.1  christos             AcpiOsPrintf (" Type mismatch:  Expected %s, Received %s",
    875  1.1  christos                 AcpiUtGetTypeName (ExpectedType),
    876  1.1  christos                 AcpiUtGetTypeName (RetValue->Type));
    877  1.1  christos 
    878  1.1  christos             return (AE_TYPE);
    879  1.1  christos         }
    880  1.1  christos 
    881  1.1  christos         *Value = RetValue;
    882  1.1  christos         break;
    883  1.1  christos 
    884  1.1  christos     default:
    885  1.1  christos 
    886  1.1  christos         AcpiOsPrintf (" Unsupported return object type, %s",
    887  1.1  christos             AcpiUtGetTypeName (RetValue->Type));
    888  1.1  christos         AcpiOsFree (ReturnObj.Pointer);
    889  1.1  christos 
    890  1.1  christos         return (AE_TYPE);
    891  1.1  christos     }
    892  1.1  christos 
    893  1.1  christos     return (Status);
    894  1.1  christos }
    895  1.1  christos 
    896  1.1  christos 
    897  1.1  christos /*******************************************************************************
    898  1.1  christos  *
    899  1.1  christos  * FUNCTION:    AcpiDbWriteToObject
    900  1.1  christos  *
    901  1.1  christos  * PARAMETERS:  Node                - Parent NS node for the object
    902  1.1  christos  *              Value               - Value to be written
    903  1.1  christos  *
    904  1.1  christos  * RETURN:      Status
    905  1.1  christos  *
    906  1.1  christos  * DESCRIPTION: Performs a write to the specified object by invoking the
    907  1.1  christos  *              special debugger control method that writes the object. Thus,
    908  1.1  christos  *              the AML interpreter is doing all of the work, increasing the
    909  1.1  christos  *              validity of the test.
    910  1.1  christos  *
    911  1.1  christos  ******************************************************************************/
    912  1.1  christos 
    913  1.1  christos static ACPI_STATUS
    914  1.1  christos AcpiDbWriteToObject (
    915  1.1  christos     ACPI_NAMESPACE_NODE     *Node,
    916  1.1  christos     ACPI_OBJECT             *Value)
    917  1.1  christos {
    918  1.1  christos     ACPI_OBJECT_LIST        ParamObjects;
    919  1.1  christos     ACPI_OBJECT             Params[2];
    920  1.1  christos     ACPI_STATUS             Status;
    921  1.1  christos 
    922  1.1  christos 
    923  1.1  christos     Params[0].Type = ACPI_TYPE_LOCAL_REFERENCE;
    924  1.1  christos     Params[0].Reference.ActualType = Node->Type;
    925  1.1  christos     Params[0].Reference.Handle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
    926  1.1  christos 
    927  1.1  christos     /* Copy the incoming user parameter */
    928  1.1  christos 
    929  1.1  christos     ACPI_MEMCPY (&Params[1], Value, sizeof (ACPI_OBJECT));
    930  1.1  christos 
    931  1.1  christos     ParamObjects.Count = 2;
    932  1.1  christos     ParamObjects.Pointer = Params;
    933  1.1  christos 
    934  1.1  christos     AcpiGbl_MethodExecuting = TRUE;
    935  1.1  christos     Status = AcpiEvaluateObject (WriteHandle, NULL, &ParamObjects, NULL);
    936  1.1  christos     AcpiGbl_MethodExecuting = FALSE;
    937  1.1  christos 
    938  1.1  christos     if (ACPI_FAILURE (Status))
    939  1.1  christos     {
    940  1.1  christos         AcpiOsPrintf ("Could not write to object, %s",
    941  1.1  christos             AcpiFormatException (Status));
    942  1.1  christos     }
    943  1.1  christos 
    944  1.1  christos     return (Status);
    945  1.1  christos }
    946  1.1  christos 
    947  1.1  christos 
    948  1.1  christos /*******************************************************************************
    949  1.1  christos  *
    950  1.1  christos  * FUNCTION:    AcpiDbEvaluateAllPredefinedNames
    951  1.1  christos  *
    952  1.1  christos  * PARAMETERS:  CountArg            - Max number of methods to execute
    953  1.1  christos  *
    954  1.1  christos  * RETURN:      None
    955  1.1  christos  *
    956  1.1  christos  * DESCRIPTION: Namespace batch execution. Execute predefined names in the
    957  1.1  christos  *              namespace, up to the max count, if specified.
    958  1.1  christos  *
    959  1.1  christos  ******************************************************************************/
    960  1.1  christos 
    961  1.1  christos static void
    962  1.1  christos AcpiDbEvaluateAllPredefinedNames (
    963  1.1  christos     char                    *CountArg)
    964  1.1  christos {
    965  1.1  christos     ACPI_DB_EXECUTE_WALK    Info;
    966  1.1  christos 
    967  1.1  christos 
    968  1.1  christos     Info.Count = 0;
    969  1.1  christos     Info.MaxCount = ACPI_UINT32_MAX;
    970  1.1  christos 
    971  1.1  christos     if (CountArg)
    972  1.1  christos     {
    973  1.1  christos         Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
    974  1.1  christos     }
    975  1.1  christos 
    976  1.1  christos     /* Search all nodes in namespace */
    977  1.1  christos 
    978  1.1  christos     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
    979  1.1  christos                 AcpiDbEvaluateOnePredefinedName, NULL, (void *) &Info, NULL);
    980  1.1  christos 
    981  1.1  christos     AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
    982  1.1  christos }
    983  1.1  christos 
    984  1.1  christos 
    985  1.1  christos /*******************************************************************************
    986  1.1  christos  *
    987  1.1  christos  * FUNCTION:    AcpiDbEvaluateOnePredefinedName
    988  1.1  christos  *
    989  1.1  christos  * PARAMETERS:  Callback from WalkNamespace
    990  1.1  christos  *
    991  1.1  christos  * RETURN:      Status
    992  1.1  christos  *
    993  1.1  christos  * DESCRIPTION: Batch execution module. Currently only executes predefined
    994  1.1  christos  *              ACPI names.
    995  1.1  christos  *
    996  1.1  christos  ******************************************************************************/
    997  1.1  christos 
    998  1.1  christos static ACPI_STATUS
    999  1.1  christos AcpiDbEvaluateOnePredefinedName (
   1000  1.1  christos     ACPI_HANDLE             ObjHandle,
   1001  1.1  christos     UINT32                  NestingLevel,
   1002  1.1  christos     void                    *Context,
   1003  1.1  christos     void                    **ReturnValue)
   1004  1.1  christos {
   1005  1.1  christos     ACPI_NAMESPACE_NODE         *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
   1006  1.1  christos     ACPI_DB_EXECUTE_WALK        *Info = (ACPI_DB_EXECUTE_WALK *) Context;
   1007  1.1  christos     char                        *Pathname;
   1008  1.1  christos     const ACPI_PREDEFINED_INFO  *Predefined;
   1009  1.1  christos     ACPI_DEVICE_INFO            *ObjInfo;
   1010  1.1  christos     ACPI_OBJECT_LIST            ParamObjects;
   1011  1.1  christos     ACPI_OBJECT                 Params[ACPI_METHOD_NUM_ARGS];
   1012  1.1  christos     ACPI_OBJECT                 *ThisParam;
   1013  1.1  christos     ACPI_BUFFER                 ReturnObj;
   1014  1.1  christos     ACPI_STATUS                 Status;
   1015  1.1  christos     UINT16                      ArgTypeList;
   1016  1.1  christos     UINT8                       ArgCount;
   1017  1.1  christos     UINT8                       ArgType;
   1018  1.1  christos     UINT32                      i;
   1019  1.1  christos 
   1020  1.1  christos 
   1021  1.1  christos     /* The name must be a predefined ACPI name */
   1022  1.1  christos 
   1023  1.1  christos     Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
   1024  1.1  christos     if (!Predefined)
   1025  1.1  christos     {
   1026  1.1  christos         return (AE_OK);
   1027  1.1  christos     }
   1028  1.1  christos 
   1029  1.1  christos     if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
   1030  1.1  christos     {
   1031  1.1  christos         return (AE_OK);
   1032  1.1  christos     }
   1033  1.1  christos 
   1034  1.1  christos     Pathname = AcpiNsGetExternalPathname (Node);
   1035  1.1  christos     if (!Pathname)
   1036  1.1  christos     {
   1037  1.1  christos         return (AE_OK);
   1038  1.1  christos     }
   1039  1.1  christos 
   1040  1.1  christos     /* Get the object info for number of method parameters */
   1041  1.1  christos 
   1042  1.1  christos     Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
   1043  1.1  christos     if (ACPI_FAILURE (Status))
   1044  1.1  christos     {
   1045  1.1  christos         ACPI_FREE (Pathname);
   1046  1.1  christos         return (Status);
   1047  1.1  christos     }
   1048  1.1  christos 
   1049  1.1  christos     ParamObjects.Count = 0;
   1050  1.1  christos     ParamObjects.Pointer = NULL;
   1051  1.1  christos 
   1052  1.1  christos     if (ObjInfo->Type == ACPI_TYPE_METHOD)
   1053  1.1  christos     {
   1054  1.1  christos         /* Setup default parameters (with proper types) */
   1055  1.1  christos 
   1056  1.1  christos         ArgTypeList = Predefined->Info.ArgumentList;
   1057  1.1  christos         ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
   1058  1.1  christos 
   1059  1.1  christos         /*
   1060  1.1  christos          * Setup the ACPI-required number of arguments, regardless of what
   1061  1.1  christos          * the actual method defines. If there is a difference, then the
   1062  1.1  christos          * method is wrong and a warning will be issued during execution.
   1063  1.1  christos          */
   1064  1.1  christos         ThisParam = Params;
   1065  1.1  christos         for (i = 0; i < ArgCount; i++)
   1066  1.1  christos         {
   1067  1.1  christos             ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
   1068  1.1  christos             ThisParam->Type = ArgType;
   1069  1.1  christos 
   1070  1.1  christos             switch (ArgType)
   1071  1.1  christos             {
   1072  1.1  christos             case ACPI_TYPE_INTEGER:
   1073  1.1  christos 
   1074  1.1  christos                 ThisParam->Integer.Value = 1;
   1075  1.1  christos                 break;
   1076  1.1  christos 
   1077  1.1  christos             case ACPI_TYPE_STRING:
   1078  1.1  christos 
   1079  1.1  christos                 ThisParam->String.Pointer = "This is the default argument string";
   1080  1.1  christos                 ThisParam->String.Length = ACPI_STRLEN (ThisParam->String.Pointer);
   1081  1.1  christos                 break;
   1082  1.1  christos 
   1083  1.1  christos             case ACPI_TYPE_BUFFER:
   1084  1.1  christos 
   1085  1.1  christos                 ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */
   1086  1.1  christos                 ThisParam->Buffer.Length = 48;
   1087  1.1  christos                 break;
   1088  1.1  christos 
   1089  1.1  christos              case ACPI_TYPE_PACKAGE:
   1090  1.1  christos 
   1091  1.1  christos                 ThisParam->Package.Elements = NULL;
   1092  1.1  christos                 ThisParam->Package.Count = 0;
   1093  1.1  christos                 break;
   1094  1.1  christos 
   1095  1.1  christos            default:
   1096  1.1  christos 
   1097  1.1  christos                 AcpiOsPrintf ("%s: Unsupported argument type: %u\n",
   1098  1.1  christos                     Pathname, ArgType);
   1099  1.1  christos                 break;
   1100  1.1  christos             }
   1101  1.1  christos 
   1102  1.1  christos             ThisParam++;
   1103  1.1  christos         }
   1104  1.1  christos 
   1105  1.1  christos         ParamObjects.Count = ArgCount;
   1106  1.1  christos         ParamObjects.Pointer = Params;
   1107  1.1  christos     }
   1108  1.1  christos 
   1109  1.1  christos     ACPI_FREE (ObjInfo);
   1110  1.1  christos     ReturnObj.Pointer = NULL;
   1111  1.1  christos     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
   1112  1.1  christos 
   1113  1.1  christos     /* Do the actual method execution */
   1114  1.1  christos 
   1115  1.1  christos     AcpiGbl_MethodExecuting = TRUE;
   1116  1.1  christos 
   1117  1.1  christos     Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
   1118  1.1  christos 
   1119  1.1  christos     AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
   1120  1.1  christos     AcpiGbl_MethodExecuting = FALSE;
   1121  1.1  christos     ACPI_FREE (Pathname);
   1122  1.1  christos 
   1123  1.1  christos     /* Ignore status from method execution */
   1124  1.1  christos 
   1125  1.1  christos     Status = AE_OK;
   1126  1.1  christos 
   1127  1.1  christos     /* Update count, check if we have executed enough methods */
   1128  1.1  christos 
   1129  1.1  christos     Info->Count++;
   1130  1.1  christos     if (Info->Count >= Info->MaxCount)
   1131  1.1  christos     {
   1132  1.1  christos         Status = AE_CTRL_TERMINATE;
   1133  1.1  christos     }
   1134  1.1  christos 
   1135  1.1  christos     return (Status);
   1136  1.1  christos }
   1137  1.1  christos 
   1138  1.1  christos #endif /* ACPI_DEBUGGER */
   1139