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