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