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