Path: blob/main/sys/contrib/dev/acpica/components/debugger/dbtest.c
48406 views
/*******************************************************************************1*2* Module Name: dbtest - Various debug-related tests3*4******************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acdebug.h>154#include <contrib/dev/acpica/include/acnamesp.h>155#include <contrib/dev/acpica/include/acpredef.h>156#include <contrib/dev/acpica/include/acinterp.h>157158159#define _COMPONENT ACPI_CA_DEBUGGER160ACPI_MODULE_NAME ("dbtest")161162163/* Local prototypes */164165static void166AcpiDbTestAllObjects (167void);168169static ACPI_STATUS170AcpiDbTestOneObject (171ACPI_HANDLE ObjHandle,172UINT32 NestingLevel,173void *Context,174void **ReturnValue);175176static ACPI_STATUS177AcpiDbTestIntegerType (178ACPI_NAMESPACE_NODE *Node,179UINT32 BitLength);180181static ACPI_STATUS182AcpiDbTestBufferType (183ACPI_NAMESPACE_NODE *Node,184UINT32 BitLength);185186static ACPI_STATUS187AcpiDbTestStringType (188ACPI_NAMESPACE_NODE *Node,189UINT32 ByteLength);190191static ACPI_STATUS192AcpiDbTestPackageType (193ACPI_NAMESPACE_NODE *Node);194195static ACPI_STATUS196AcpiDbTestFieldUnitType (197ACPI_OPERAND_OBJECT *ObjDesc);198199static ACPI_STATUS200AcpiDbReadFromObject (201ACPI_NAMESPACE_NODE *Node,202ACPI_OBJECT_TYPE ExpectedType,203ACPI_OBJECT **Value);204205static ACPI_STATUS206AcpiDbWriteToObject (207ACPI_NAMESPACE_NODE *Node,208ACPI_OBJECT *Value);209210static void211AcpiDbEvaluateAllPredefinedNames (212char *CountArg);213214static ACPI_STATUS215AcpiDbEvaluateOnePredefinedName (216ACPI_HANDLE ObjHandle,217UINT32 NestingLevel,218void *Context,219void **ReturnValue);220221/*222* Test subcommands223*/224static ACPI_DB_ARGUMENT_INFO AcpiDbTestTypes [] =225{226{"OBJECTS"},227{"PREDEFINED"},228{NULL} /* Must be null terminated */229};230231#define CMD_TEST_OBJECTS 0232#define CMD_TEST_PREDEFINED 1233234#define BUFFER_FILL_VALUE 0xFF235236/*237* Support for the special debugger read/write control methods.238* These methods are installed into the current namespace and are239* used to read and write the various namespace objects. The point240* is to force the AML interpreter do all of the work.241*/242#define ACPI_DB_READ_METHOD "\\_T98"243#define ACPI_DB_WRITE_METHOD "\\_T99"244245static ACPI_HANDLE ReadHandle = NULL;246static ACPI_HANDLE WriteHandle = NULL;247248/* ASL Definitions of the debugger read/write control methods. AML below. */249250#if 0251DefinitionBlock ("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)252{253Method (_T98, 1, NotSerialized) /* Read */254{255Return (DeRefOf (Arg0))256}257}258DefinitionBlock ("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)259{260Method (_T99, 2, NotSerialized) /* Write */261{262Store (Arg1, Arg0)263}264}265#endif266267static unsigned char ReadMethodCode[] =268{2690x53,0x53,0x44,0x54,0x2E,0x00,0x00,0x00, /* 00000000 "SSDT...." */2700x02,0xC9,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */2710x44,0x45,0x42,0x55,0x47,0x00,0x00,0x00, /* 00000010 "DEBUG..." */2720x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */2730x18,0x12,0x13,0x20,0x14,0x09,0x5F,0x54, /* 00000020 "... .._T" */2740x39,0x38,0x01,0xA4,0x83,0x68 /* 00000028 "98...h" */275};276277static unsigned char WriteMethodCode[] =278{2790x53,0x53,0x44,0x54,0x2E,0x00,0x00,0x00, /* 00000000 "SSDT...." */2800x02,0x15,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */2810x44,0x45,0x42,0x55,0x47,0x00,0x00,0x00, /* 00000010 "DEBUG..." */2820x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */2830x18,0x12,0x13,0x20,0x14,0x09,0x5F,0x54, /* 00000020 "... .._T" */2840x39,0x39,0x02,0x70,0x69,0x68 /* 00000028 "99.pih" */285};286287288/*******************************************************************************289*290* FUNCTION: AcpiDbExecuteTest291*292* PARAMETERS: TypeArg - Subcommand293*294* RETURN: None295*296* DESCRIPTION: Execute various debug tests.297*298* Note: Code is prepared for future expansion of the TEST command.299*300******************************************************************************/301302void303AcpiDbExecuteTest (304char *TypeArg)305{306UINT32 Temp;307308309AcpiUtStrupr (TypeArg);310Temp = AcpiDbMatchArgument (TypeArg, AcpiDbTestTypes);311if (Temp == ACPI_TYPE_NOT_FOUND)312{313AcpiOsPrintf ("Invalid or unsupported argument\n");314return;315}316317switch (Temp)318{319case CMD_TEST_OBJECTS:320321AcpiDbTestAllObjects ();322break;323324case CMD_TEST_PREDEFINED:325326AcpiDbEvaluateAllPredefinedNames (NULL);327break;328329default:330break;331}332}333334335/*******************************************************************************336*337* FUNCTION: AcpiDbTestAllObjects338*339* PARAMETERS: None340*341* RETURN: None342*343* DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the344* namespace by reading/writing/comparing all data objects such345* as integers, strings, buffers, fields, buffer fields, etc.346*347******************************************************************************/348349static void350AcpiDbTestAllObjects (351void)352{353ACPI_STATUS Status;354355356/* Install the debugger read-object control method if necessary */357358if (!ReadHandle)359{360Status = AcpiInstallMethod (ReadMethodCode);361if (ACPI_FAILURE (Status))362{363AcpiOsPrintf ("%s, Could not install debugger read method\n",364AcpiFormatException (Status));365return;366}367368Status = AcpiGetHandle (NULL, ACPI_DB_READ_METHOD, &ReadHandle);369if (ACPI_FAILURE (Status))370{371AcpiOsPrintf ("Could not obtain handle for debug method %s\n",372ACPI_DB_READ_METHOD);373return;374}375}376377/* Install the debugger write-object control method if necessary */378379if (!WriteHandle)380{381Status = AcpiInstallMethod (WriteMethodCode);382if (ACPI_FAILURE (Status))383{384AcpiOsPrintf ("%s, Could not install debugger write method\n",385AcpiFormatException (Status));386return;387}388389Status = AcpiGetHandle (NULL, ACPI_DB_WRITE_METHOD, &WriteHandle);390if (ACPI_FAILURE (Status))391{392AcpiOsPrintf ("Could not obtain handle for debug method %s\n",393ACPI_DB_WRITE_METHOD);394return;395}396}397398/* Walk the entire namespace, testing each supported named data object */399400(void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,401ACPI_UINT32_MAX, AcpiDbTestOneObject, NULL, NULL, NULL);402}403404405/*******************************************************************************406*407* FUNCTION: AcpiDbTestOneObject408*409* PARAMETERS: ACPI_WALK_CALLBACK410*411* RETURN: Status412*413* DESCRIPTION: Test one namespace object. Supported types are Integer,414* String, Buffer, Package, BufferField, and FieldUnit.415* All other object types are simply ignored.416*417******************************************************************************/418419static ACPI_STATUS420AcpiDbTestOneObject (421ACPI_HANDLE ObjHandle,422UINT32 NestingLevel,423void *Context,424void **ReturnValue)425{426ACPI_NAMESPACE_NODE *Node;427ACPI_OPERAND_OBJECT *ObjDesc;428ACPI_OBJECT_TYPE LocalType;429UINT32 BitLength = 0;430UINT32 ByteLength = 0;431ACPI_STATUS Status = AE_OK;432433434Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);435ObjDesc = Node->Object;436437/*438* For the supported types, get the actual bit length or439* byte length. Map the type to one of Integer/String/Buffer.440*/441switch (Node->Type)442{443case ACPI_TYPE_INTEGER:444445/* Integer width is either 32 or 64 */446447LocalType = ACPI_TYPE_INTEGER;448BitLength = AcpiGbl_IntegerBitWidth;449break;450451case ACPI_TYPE_STRING:452453LocalType = ACPI_TYPE_STRING;454ByteLength = ObjDesc->String.Length;455break;456457case ACPI_TYPE_BUFFER:458459LocalType = ACPI_TYPE_BUFFER;460ByteLength = ObjDesc->Buffer.Length;461BitLength = ByteLength * 8;462break;463464case ACPI_TYPE_PACKAGE:465466LocalType = ACPI_TYPE_PACKAGE;467break;468469case ACPI_TYPE_FIELD_UNIT:470case ACPI_TYPE_LOCAL_REGION_FIELD:471case ACPI_TYPE_LOCAL_INDEX_FIELD:472case ACPI_TYPE_LOCAL_BANK_FIELD:473474LocalType = ACPI_TYPE_FIELD_UNIT;475break;476477case ACPI_TYPE_BUFFER_FIELD:478/*479* The returned object will be a Buffer if the field length480* is larger than the size of an Integer (32 or 64 bits481* depending on the DSDT version).482*/483LocalType = ACPI_TYPE_INTEGER;484if (ObjDesc)485{486BitLength = ObjDesc->CommonField.BitLength;487ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);488if (BitLength > AcpiGbl_IntegerBitWidth)489{490LocalType = ACPI_TYPE_BUFFER;491}492}493break;494495default:496497/* Ignore all non-data types - Methods, Devices, Scopes, etc. */498499return (AE_OK);500}501502/* Emit the common prefix: Type:Name */503504AcpiOsPrintf ("%14s: %4.4s",505AcpiUtGetTypeName (Node->Type), Node->Name.Ascii);506507if (!ObjDesc)508{509AcpiOsPrintf (" No attached sub-object, ignoring\n");510return (AE_OK);511}512513/* At this point, we have resolved the object to one of the major types */514515switch (LocalType)516{517case ACPI_TYPE_INTEGER:518519Status = AcpiDbTestIntegerType (Node, BitLength);520break;521522case ACPI_TYPE_STRING:523524Status = AcpiDbTestStringType (Node, ByteLength);525break;526527case ACPI_TYPE_BUFFER:528529Status = AcpiDbTestBufferType (Node, BitLength);530break;531532case ACPI_TYPE_PACKAGE:533534Status = AcpiDbTestPackageType (Node);535break;536537case ACPI_TYPE_FIELD_UNIT:538539Status = AcpiDbTestFieldUnitType (ObjDesc);540break;541542default:543544AcpiOsPrintf (" Ignoring, type not implemented (%2.2X)",545LocalType);546break;547}548549/* Exit on error, but don't abort the namespace walk */550551if (ACPI_FAILURE (Status))552{553Status = AE_OK;554}555556AcpiOsPrintf ("\n");557return (Status);558}559560561/*******************************************************************************562*563* FUNCTION: AcpiDbTestIntegerType564*565* PARAMETERS: Node - Parent NS node for the object566* BitLength - Actual length of the object. Used for567* support of arbitrary length FieldUnit568* and BufferField objects.569*570* RETURN: Status571*572* DESCRIPTION: Test read/write for an Integer-valued object. Performs a573* write/read/compare of an arbitrary new value, then performs574* a write/read/compare of the original value.575*576******************************************************************************/577578static ACPI_STATUS579AcpiDbTestIntegerType (580ACPI_NAMESPACE_NODE *Node,581UINT32 BitLength)582{583ACPI_OBJECT *Temp1 = NULL;584ACPI_OBJECT *Temp2 = NULL;585ACPI_OBJECT *Temp3 = NULL;586ACPI_OBJECT WriteValue;587UINT64 ValueToWrite;588ACPI_STATUS Status;589590591if (BitLength > 64)592{593AcpiOsPrintf (" Invalid length for an Integer: %u", BitLength);594return (AE_OK);595}596597/* Read the original value */598599Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp1);600if (ACPI_FAILURE (Status))601{602return (Status);603}604605AcpiOsPrintf (ACPI_DEBUG_LENGTH_FORMAT " %8.8X%8.8X",606BitLength, ACPI_ROUND_BITS_UP_TO_BYTES (BitLength),607ACPI_FORMAT_UINT64 (Temp1->Integer.Value));608609ValueToWrite = ACPI_UINT64_MAX >> (64 - BitLength);610if (Temp1->Integer.Value == ValueToWrite)611{612ValueToWrite = 0;613}614/* Write a new value */615616WriteValue.Type = ACPI_TYPE_INTEGER;617WriteValue.Integer.Value = ValueToWrite;618Status = AcpiDbWriteToObject (Node, &WriteValue);619if (ACPI_FAILURE (Status))620{621goto Exit;622}623624/* Ensure that we can read back the new value */625626Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp2);627if (ACPI_FAILURE (Status))628{629goto Exit;630}631632if (Temp2->Integer.Value != ValueToWrite)633{634AcpiOsPrintf (" MISMATCH 2: %8.8X%8.8X, expecting %8.8X%8.8X",635ACPI_FORMAT_UINT64 (Temp2->Integer.Value),636ACPI_FORMAT_UINT64 (ValueToWrite));637}638639/* Write back the original value */640641WriteValue.Integer.Value = Temp1->Integer.Value;642Status = AcpiDbWriteToObject (Node, &WriteValue);643if (ACPI_FAILURE (Status))644{645goto Exit;646}647648/* Ensure that we can read back the original value */649650Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp3);651if (ACPI_FAILURE (Status))652{653goto Exit;654}655656if (Temp3->Integer.Value != Temp1->Integer.Value)657{658AcpiOsPrintf (" MISMATCH 3: %8.8X%8.8X, expecting %8.8X%8.8X",659ACPI_FORMAT_UINT64 (Temp3->Integer.Value),660ACPI_FORMAT_UINT64 (Temp1->Integer.Value));661}662663Exit:664if (Temp1) {AcpiOsFree (Temp1);}665if (Temp2) {AcpiOsFree (Temp2);}666if (Temp3) {AcpiOsFree (Temp3);}667return (AE_OK);668}669670671/*******************************************************************************672*673* FUNCTION: AcpiDbTestBufferType674*675* PARAMETERS: Node - Parent NS node for the object676* BitLength - Actual length of the object.677*678* RETURN: Status679*680* DESCRIPTION: Test read/write for an Buffer-valued object. Performs a681* write/read/compare of an arbitrary new value, then performs682* a write/read/compare of the original value.683*684******************************************************************************/685686static ACPI_STATUS687AcpiDbTestBufferType (688ACPI_NAMESPACE_NODE *Node,689UINT32 BitLength)690{691ACPI_OBJECT *Temp1 = NULL;692ACPI_OBJECT *Temp2 = NULL;693ACPI_OBJECT *Temp3 = NULL;694UINT8 *Buffer;695ACPI_OBJECT WriteValue;696ACPI_STATUS Status;697UINT32 ByteLength;698UINT32 i;699UINT8 ExtraBits;700701702ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);703if (ByteLength == 0)704{705AcpiOsPrintf (" Ignoring zero length buffer");706return (AE_OK);707}708709/* Allocate a local buffer */710711Buffer = ACPI_ALLOCATE_ZEROED (ByteLength);712if (!Buffer)713{714return (AE_NO_MEMORY);715}716717/* Read the original value */718719Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp1);720if (ACPI_FAILURE (Status))721{722goto Exit;723}724725/* Emit a few bytes of the buffer */726727AcpiOsPrintf (ACPI_DEBUG_LENGTH_FORMAT, BitLength, Temp1->Buffer.Length);728for (i = 0; ((i < 8) && (i < ByteLength)); i++)729{730AcpiOsPrintf (" %2.2X", Temp1->Buffer.Pointer[i]);731}732AcpiOsPrintf ("... ");733734/*735* Write a new value.736*737* Handle possible extra bits at the end of the buffer. Can738* happen for FieldUnits larger than an integer, but the bit739* count is not an integral number of bytes. Zero out the740* unused bits.741*/742memset (Buffer, BUFFER_FILL_VALUE, ByteLength);743ExtraBits = BitLength % 8;744if (ExtraBits)745{746Buffer [ByteLength - 1] = ACPI_MASK_BITS_ABOVE (ExtraBits);747}748749WriteValue.Type = ACPI_TYPE_BUFFER;750WriteValue.Buffer.Length = ByteLength;751WriteValue.Buffer.Pointer = Buffer;752753Status = AcpiDbWriteToObject (Node, &WriteValue);754if (ACPI_FAILURE (Status))755{756goto Exit;757}758759/* Ensure that we can read back the new value */760761Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp2);762if (ACPI_FAILURE (Status))763{764goto Exit;765}766767if (memcmp (Temp2->Buffer.Pointer, Buffer, ByteLength))768{769AcpiOsPrintf (" MISMATCH 2: New buffer value");770}771772/* Write back the original value */773774WriteValue.Buffer.Length = ByteLength;775WriteValue.Buffer.Pointer = Temp1->Buffer.Pointer;776777Status = AcpiDbWriteToObject (Node, &WriteValue);778if (ACPI_FAILURE (Status))779{780goto Exit;781}782783/* Ensure that we can read back the original value */784785Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp3);786if (ACPI_FAILURE (Status))787{788goto Exit;789}790791if (memcmp (Temp1->Buffer.Pointer,792Temp3->Buffer.Pointer, ByteLength))793{794AcpiOsPrintf (" MISMATCH 3: While restoring original buffer");795}796797Exit:798ACPI_FREE (Buffer);799if (Temp1) {AcpiOsFree (Temp1);}800if (Temp2) {AcpiOsFree (Temp2);}801if (Temp3) {AcpiOsFree (Temp3);}802return (Status);803}804805806/*******************************************************************************807*808* FUNCTION: AcpiDbTestStringType809*810* PARAMETERS: Node - Parent NS node for the object811* ByteLength - Actual length of the object.812*813* RETURN: Status814*815* DESCRIPTION: Test read/write for an String-valued object. Performs a816* write/read/compare of an arbitrary new value, then performs817* a write/read/compare of the original value.818*819******************************************************************************/820821static ACPI_STATUS822AcpiDbTestStringType (823ACPI_NAMESPACE_NODE *Node,824UINT32 ByteLength)825{826ACPI_OBJECT *Temp1 = NULL;827ACPI_OBJECT *Temp2 = NULL;828ACPI_OBJECT *Temp3 = NULL;829char *ValueToWrite = "Test String from AML Debugger";830ACPI_OBJECT WriteValue;831ACPI_STATUS Status;832833834/* Read the original value */835836Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp1);837if (ACPI_FAILURE (Status))838{839return (Status);840}841842AcpiOsPrintf (ACPI_DEBUG_LENGTH_FORMAT " \"%s\"", (Temp1->String.Length * 8),843Temp1->String.Length, Temp1->String.Pointer);844845/* Write a new value */846847WriteValue.Type = ACPI_TYPE_STRING;848WriteValue.String.Length = strlen (ValueToWrite);849WriteValue.String.Pointer = ValueToWrite;850851Status = AcpiDbWriteToObject (Node, &WriteValue);852if (ACPI_FAILURE (Status))853{854goto Exit;855}856857/* Ensure that we can read back the new value */858859Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp2);860if (ACPI_FAILURE (Status))861{862goto Exit;863}864865if (strcmp (Temp2->String.Pointer, ValueToWrite))866{867AcpiOsPrintf (" MISMATCH 2: %s, expecting %s",868Temp2->String.Pointer, ValueToWrite);869}870871/* Write back the original value */872873WriteValue.String.Length = strlen (Temp1->String.Pointer);874WriteValue.String.Pointer = Temp1->String.Pointer;875876Status = AcpiDbWriteToObject (Node, &WriteValue);877if (ACPI_FAILURE (Status))878{879goto Exit;880}881882/* Ensure that we can read back the original value */883884Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp3);885if (ACPI_FAILURE (Status))886{887goto Exit;888}889890if (strcmp (Temp1->String.Pointer, Temp3->String.Pointer))891{892AcpiOsPrintf (" MISMATCH 3: %s, expecting %s",893Temp3->String.Pointer, Temp1->String.Pointer);894}895896Exit:897if (Temp1) {AcpiOsFree (Temp1);}898if (Temp2) {AcpiOsFree (Temp2);}899if (Temp3) {AcpiOsFree (Temp3);}900return (Status);901}902903904/*******************************************************************************905*906* FUNCTION: AcpiDbTestPackageType907*908* PARAMETERS: Node - Parent NS node for the object909*910* RETURN: Status911*912* DESCRIPTION: Test read for a Package object.913*914******************************************************************************/915916static ACPI_STATUS917AcpiDbTestPackageType (918ACPI_NAMESPACE_NODE *Node)919{920ACPI_OBJECT *Temp1 = NULL;921ACPI_STATUS Status;922923924/* Read the original value */925926Status = AcpiDbReadFromObject (Node, ACPI_TYPE_PACKAGE, &Temp1);927if (ACPI_FAILURE (Status))928{929return (Status);930}931932AcpiOsPrintf (" %.2X Elements", Temp1->Package.Count);933AcpiOsFree (Temp1);934return (Status);935}936937938/*******************************************************************************939*940* FUNCTION: AcpiDbTestFieldUnitType941*942* PARAMETERS: ObjDesc - A field unit object943*944* RETURN: Status945*946* DESCRIPTION: Test read/write on a named field unit.947*948******************************************************************************/949950static ACPI_STATUS951AcpiDbTestFieldUnitType (952ACPI_OPERAND_OBJECT *ObjDesc)953{954ACPI_OPERAND_OBJECT *RegionObj;955UINT32 BitLength = 0;956UINT32 ByteLength = 0;957ACPI_STATUS Status = AE_OK;958ACPI_OPERAND_OBJECT *RetBufferDesc;959960961/* Supported spaces are memory/io/pci_config */962963RegionObj = ObjDesc->Field.RegionObj;964switch (RegionObj->Region.SpaceId)965{966case ACPI_ADR_SPACE_SYSTEM_MEMORY:967case ACPI_ADR_SPACE_SYSTEM_IO:968case ACPI_ADR_SPACE_PCI_CONFIG:969970/* Need the interpreter to execute */971972AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);973AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);974975/* Exercise read-then-write */976977Status = AcpiExReadDataFromField (NULL, ObjDesc, &RetBufferDesc);978if (Status == AE_OK)979{980AcpiExWriteDataToField (RetBufferDesc, ObjDesc, NULL);981AcpiUtRemoveReference (RetBufferDesc);982}983984AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);985AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);986987BitLength = ObjDesc->CommonField.BitLength;988ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);989990AcpiOsPrintf (ACPI_DEBUG_LENGTH_FORMAT " [%s]", BitLength,991ByteLength, AcpiUtGetRegionName (RegionObj->Region.SpaceId));992return (Status);993994default:995996AcpiOsPrintf (997" %s address space is not supported in this command [%4.4s]",998AcpiUtGetRegionName (RegionObj->Region.SpaceId),999RegionObj->Region.Node->Name.Ascii);1000return (AE_OK);1001}1002}100310041005/*******************************************************************************1006*1007* FUNCTION: AcpiDbReadFromObject1008*1009* PARAMETERS: Node - Parent NS node for the object1010* ExpectedType - Object type expected from the read1011* Value - Where the value read is returned1012*1013* RETURN: Status1014*1015* DESCRIPTION: Performs a read from the specified object by invoking the1016* special debugger control method that reads the object. Thus,1017* the AML interpreter is doing all of the work, increasing the1018* validity of the test.1019*1020******************************************************************************/10211022static ACPI_STATUS1023AcpiDbReadFromObject (1024ACPI_NAMESPACE_NODE *Node,1025ACPI_OBJECT_TYPE ExpectedType,1026ACPI_OBJECT **Value)1027{1028ACPI_OBJECT *RetValue;1029ACPI_OBJECT_LIST ParamObjects;1030ACPI_OBJECT Params[2];1031ACPI_BUFFER ReturnObj;1032ACPI_STATUS Status;103310341035Params[0].Type = ACPI_TYPE_LOCAL_REFERENCE;1036Params[0].Reference.ActualType = Node->Type;1037Params[0].Reference.Handle = ACPI_CAST_PTR (ACPI_HANDLE, Node);10381039ParamObjects.Count = 1;1040ParamObjects.Pointer = Params;10411042ReturnObj.Length = ACPI_ALLOCATE_BUFFER;10431044AcpiGbl_MethodExecuting = TRUE;1045Status = AcpiEvaluateObject (ReadHandle, NULL,1046&ParamObjects, &ReturnObj);10471048AcpiGbl_MethodExecuting = FALSE;1049if (ACPI_FAILURE (Status))1050{1051AcpiOsPrintf ("Could not read from object, %s",1052AcpiFormatException (Status));1053return (Status);1054}10551056RetValue = (ACPI_OBJECT *) ReturnObj.Pointer;10571058switch (RetValue->Type)1059{1060case ACPI_TYPE_INTEGER:1061case ACPI_TYPE_BUFFER:1062case ACPI_TYPE_STRING:1063case ACPI_TYPE_PACKAGE:1064/*1065* Did we receive the type we wanted? Most important for the1066* Integer/Buffer case (when a field is larger than an Integer,1067* it should return a Buffer).1068*/1069if (RetValue->Type != ExpectedType)1070{1071AcpiOsPrintf (" Type mismatch: Expected %s, Received %s",1072AcpiUtGetTypeName (ExpectedType),1073AcpiUtGetTypeName (RetValue->Type));10741075AcpiOsFree (ReturnObj.Pointer);1076return (AE_TYPE);1077}10781079*Value = RetValue;1080break;10811082default:10831084AcpiOsPrintf (" Unsupported return object type, %s",1085AcpiUtGetTypeName (RetValue->Type));10861087AcpiOsFree (ReturnObj.Pointer);1088return (AE_TYPE);1089}10901091return (Status);1092}109310941095/*******************************************************************************1096*1097* FUNCTION: AcpiDbWriteToObject1098*1099* PARAMETERS: Node - Parent NS node for the object1100* Value - Value to be written1101*1102* RETURN: Status1103*1104* DESCRIPTION: Performs a write to the specified object by invoking the1105* special debugger control method that writes the object. Thus,1106* the AML interpreter is doing all of the work, increasing the1107* validity of the test.1108*1109******************************************************************************/11101111static ACPI_STATUS1112AcpiDbWriteToObject (1113ACPI_NAMESPACE_NODE *Node,1114ACPI_OBJECT *Value)1115{1116ACPI_OBJECT_LIST ParamObjects;1117ACPI_OBJECT Params[2];1118ACPI_STATUS Status;111911201121Params[0].Type = ACPI_TYPE_LOCAL_REFERENCE;1122Params[0].Reference.ActualType = Node->Type;1123Params[0].Reference.Handle = ACPI_CAST_PTR (ACPI_HANDLE, Node);11241125/* Copy the incoming user parameter */11261127memcpy (&Params[1], Value, sizeof (ACPI_OBJECT));11281129ParamObjects.Count = 2;1130ParamObjects.Pointer = Params;11311132AcpiGbl_MethodExecuting = TRUE;1133Status = AcpiEvaluateObject (WriteHandle, NULL, &ParamObjects, NULL);1134AcpiGbl_MethodExecuting = FALSE;11351136if (ACPI_FAILURE (Status))1137{1138AcpiOsPrintf ("Could not write to object, %s",1139AcpiFormatException (Status));1140}11411142return (Status);1143}114411451146/*******************************************************************************1147*1148* FUNCTION: AcpiDbEvaluateAllPredefinedNames1149*1150* PARAMETERS: CountArg - Max number of methods to execute1151*1152* RETURN: None1153*1154* DESCRIPTION: Namespace batch execution. Execute predefined names in the1155* namespace, up to the max count, if specified.1156*1157******************************************************************************/11581159static void1160AcpiDbEvaluateAllPredefinedNames (1161char *CountArg)1162{1163ACPI_DB_EXECUTE_WALK Info;116411651166Info.Count = 0;1167Info.MaxCount = ACPI_UINT32_MAX;11681169if (CountArg)1170{1171Info.MaxCount = strtoul (CountArg, NULL, 0);1172}11731174/* Search all nodes in namespace */11751176(void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,1177ACPI_UINT32_MAX, AcpiDbEvaluateOnePredefinedName, NULL,1178(void *) &Info, NULL);11791180AcpiOsPrintf (1181"Evaluated %u predefined names in the namespace\n", Info.Count);1182}118311841185/*******************************************************************************1186*1187* FUNCTION: AcpiDbEvaluateOnePredefinedName1188*1189* PARAMETERS: Callback from WalkNamespace1190*1191* RETURN: Status1192*1193* DESCRIPTION: Batch execution module. Currently only executes predefined1194* ACPI names.1195*1196******************************************************************************/11971198static ACPI_STATUS1199AcpiDbEvaluateOnePredefinedName (1200ACPI_HANDLE ObjHandle,1201UINT32 NestingLevel,1202void *Context,1203void **ReturnValue)1204{1205ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;1206ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context;1207char *Pathname;1208const ACPI_PREDEFINED_INFO *Predefined;1209ACPI_DEVICE_INFO *ObjInfo;1210ACPI_OBJECT_LIST ParamObjects;1211ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];1212ACPI_OBJECT *ThisParam;1213ACPI_BUFFER ReturnObj;1214ACPI_STATUS Status;1215UINT16 ArgTypeList;1216UINT8 ArgCount;1217UINT8 ArgType;1218UINT32 i;121912201221/* The name must be a predefined ACPI name */12221223Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);1224if (!Predefined)1225{1226return (AE_OK);1227}12281229if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)1230{1231return (AE_OK);1232}12331234Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);1235if (!Pathname)1236{1237return (AE_OK);1238}12391240/* Get the object info for number of method parameters */12411242Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);1243if (ACPI_FAILURE (Status))1244{1245ACPI_FREE (Pathname);1246return (Status);1247}12481249ParamObjects.Count = 0;1250ParamObjects.Pointer = NULL;12511252if (ObjInfo->Type == ACPI_TYPE_METHOD)1253{1254/* Setup default parameters (with proper types) */12551256ArgTypeList = Predefined->Info.ArgumentList;1257ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);12581259/*1260* Setup the ACPI-required number of arguments, regardless of what1261* the actual method defines. If there is a difference, then the1262* method is wrong and a warning will be issued during execution.1263*/1264ThisParam = Params;1265for (i = 0; i < ArgCount; i++)1266{1267ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);1268ThisParam->Type = ArgType;12691270switch (ArgType)1271{1272case ACPI_TYPE_INTEGER:12731274ThisParam->Integer.Value = 1;1275break;12761277case ACPI_TYPE_STRING:12781279ThisParam->String.Pointer =1280"This is the default argument string";1281ThisParam->String.Length =1282strlen (ThisParam->String.Pointer);1283break;12841285case ACPI_TYPE_BUFFER:12861287ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */1288ThisParam->Buffer.Length = 48;1289break;12901291case ACPI_TYPE_PACKAGE:12921293ThisParam->Package.Elements = NULL;1294ThisParam->Package.Count = 0;1295break;12961297default:12981299AcpiOsPrintf ("%s: Unsupported argument type: %u\n",1300Pathname, ArgType);1301break;1302}13031304ThisParam++;1305}13061307ParamObjects.Count = ArgCount;1308ParamObjects.Pointer = Params;1309}13101311ACPI_FREE (ObjInfo);1312ReturnObj.Pointer = NULL;1313ReturnObj.Length = ACPI_ALLOCATE_BUFFER;13141315/* Do the actual method execution */13161317AcpiGbl_MethodExecuting = TRUE;13181319Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);13201321AcpiOsPrintf ("%-32s returned %s\n",1322Pathname, AcpiFormatException (Status));1323AcpiGbl_MethodExecuting = FALSE;1324ACPI_FREE (Pathname);13251326/* Ignore status from method execution */13271328Status = AE_OK;13291330/* Update count, check if we have executed enough methods */13311332Info->Count++;1333if (Info->Count >= Info->MaxCount)1334{1335Status = AE_CTRL_TERMINATE;1336}13371338return (Status);1339}134013411342