1 /******************************************************************************* 2 * 3 * Module Name: dbcmds - Miscellaneous debug commands and output routines 4 * 5 ******************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2012, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 45 #include <contrib/dev/acpica/include/acpi.h> 46 #include <contrib/dev/acpica/include/accommon.h> 47 #include <contrib/dev/acpica/include/acevents.h> 48 #include <contrib/dev/acpica/include/acdebug.h> 49 #include <contrib/dev/acpica/include/acnamesp.h> 50 #include <contrib/dev/acpica/include/acresrc.h> 51 #include <contrib/dev/acpica/include/actables.h> 52 53 #ifdef ACPI_DEBUGGER 54 55 #define _COMPONENT ACPI_CA_DEBUGGER 56 ACPI_MODULE_NAME ("dbcmds") 57 58 59 /* Local prototypes */ 60 61 static void 62 AcpiDmCompareAmlResources ( 63 UINT8 *Aml1Buffer, 64 ACPI_RSDESC_SIZE Aml1BufferLength, 65 UINT8 *Aml2Buffer, 66 ACPI_RSDESC_SIZE Aml2BufferLength); 67 68 static ACPI_STATUS 69 AcpiDmTestResourceConversion ( 70 ACPI_NAMESPACE_NODE *Node, 71 char *Name); 72 73 static ACPI_STATUS 74 AcpiDbResourceCallback ( 75 ACPI_RESOURCE *Resource, 76 void *Context); 77 78 static ACPI_STATUS 79 AcpiDbDeviceResources ( 80 ACPI_HANDLE ObjHandle, 81 UINT32 NestingLevel, 82 void *Context, 83 void **ReturnValue); 84 85 86 /******************************************************************************* 87 * 88 * FUNCTION: AcpiDbConvertToNode 89 * 90 * PARAMETERS: InString - String to convert 91 * 92 * RETURN: Pointer to a NS node 93 * 94 * DESCRIPTION: Convert a string to a valid NS pointer. Handles numeric or 95 * alpha strings. 96 * 97 ******************************************************************************/ 98 99 ACPI_NAMESPACE_NODE * 100 AcpiDbConvertToNode ( 101 char *InString) 102 { 103 ACPI_NAMESPACE_NODE *Node; 104 105 106 if ((*InString >= 0x30) && (*InString <= 0x39)) 107 { 108 /* Numeric argument, convert */ 109 110 Node = ACPI_TO_POINTER (ACPI_STRTOUL (InString, NULL, 16)); 111 if (!AcpiOsReadable (Node, sizeof (ACPI_NAMESPACE_NODE))) 112 { 113 AcpiOsPrintf ("Address %p is invalid in this address space\n", 114 Node); 115 return (NULL); 116 } 117 118 /* Make sure pointer is valid NS node */ 119 120 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED) 121 { 122 AcpiOsPrintf ("Address %p is not a valid NS node [%s]\n", 123 Node, AcpiUtGetDescriptorName (Node)); 124 return (NULL); 125 } 126 } 127 else 128 { 129 /* Alpha argument */ 130 /* The parameter is a name string that must be resolved to a 131 * Named obj 132 */ 133 Node = AcpiDbLocalNsLookup (InString); 134 if (!Node) 135 { 136 Node = AcpiGbl_RootNode; 137 } 138 } 139 140 return (Node); 141 } 142 143 144 /******************************************************************************* 145 * 146 * FUNCTION: AcpiDbSleep 147 * 148 * PARAMETERS: ObjectArg - Desired sleep state (0-5) 149 * 150 * RETURN: Status 151 * 152 * DESCRIPTION: Simulate a sleep/wake sequence 153 * 154 ******************************************************************************/ 155 156 ACPI_STATUS 157 AcpiDbSleep ( 158 char *ObjectArg) 159 { 160 ACPI_STATUS Status; 161 UINT8 SleepState; 162 163 164 ACPI_FUNCTION_TRACE (AcpiDbSleep); 165 166 167 SleepState = (UINT8) ACPI_STRTOUL (ObjectArg, NULL, 0); 168 169 AcpiOsPrintf ("**** Prepare to sleep ****\n"); 170 Status = AcpiEnterSleepStatePrep (SleepState); 171 if (ACPI_FAILURE (Status)) 172 { 173 goto ErrorExit; 174 } 175 176 AcpiOsPrintf ("**** Going to sleep ****\n"); 177 Status = AcpiEnterSleepState (SleepState); 178 if (ACPI_FAILURE (Status)) 179 { 180 goto ErrorExit; 181 } 182 183 AcpiOsPrintf ("**** Prepare to return from sleep ****\n"); 184 Status = AcpiLeaveSleepStatePrep (SleepState); 185 if (ACPI_FAILURE (Status)) 186 { 187 goto ErrorExit; 188 } 189 190 AcpiOsPrintf ("**** Returning from sleep ****\n"); 191 Status = AcpiLeaveSleepState (SleepState); 192 if (ACPI_FAILURE (Status)) 193 { 194 goto ErrorExit; 195 } 196 197 return (Status); 198 199 200 ErrorExit: 201 202 ACPI_EXCEPTION ((AE_INFO, Status, "During sleep test")); 203 return (Status); 204 } 205 206 207 /******************************************************************************* 208 * 209 * FUNCTION: AcpiDbDisplayLocks 210 * 211 * PARAMETERS: None 212 * 213 * RETURN: None 214 * 215 * DESCRIPTION: Display information about internal mutexes. 216 * 217 ******************************************************************************/ 218 219 void 220 AcpiDbDisplayLocks ( 221 void) 222 { 223 UINT32 i; 224 225 226 for (i = 0; i < ACPI_MAX_MUTEX; i++) 227 { 228 AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i), 229 AcpiGbl_MutexInfo[i].ThreadId == ACPI_MUTEX_NOT_ACQUIRED 230 ? "Locked" : "Unlocked"); 231 } 232 } 233 234 235 /******************************************************************************* 236 * 237 * FUNCTION: AcpiDbDisplayTableInfo 238 * 239 * PARAMETERS: TableArg - String with name of table to be displayed 240 * 241 * RETURN: None 242 * 243 * DESCRIPTION: Display information about loaded tables. Current 244 * implementation displays all loaded tables. 245 * 246 ******************************************************************************/ 247 248 void 249 AcpiDbDisplayTableInfo ( 250 char *TableArg) 251 { 252 UINT32 i; 253 ACPI_TABLE_DESC *TableDesc; 254 ACPI_STATUS Status; 255 256 257 /* Walk the entire root table list */ 258 259 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 260 { 261 TableDesc = &AcpiGbl_RootTableList.Tables[i]; 262 AcpiOsPrintf ("%u ", i); 263 264 /* Make sure that the table is mapped */ 265 266 Status = AcpiTbVerifyTable (TableDesc); 267 if (ACPI_FAILURE (Status)) 268 { 269 return; 270 } 271 272 /* Dump the table header */ 273 274 if (TableDesc->Pointer) 275 { 276 AcpiTbPrintTableHeader (TableDesc->Address, TableDesc->Pointer); 277 } 278 else 279 { 280 /* If the pointer is null, the table has been unloaded */ 281 282 ACPI_INFO ((AE_INFO, "%4.4s - Table has been unloaded", 283 TableDesc->Signature.Ascii)); 284 } 285 } 286 } 287 288 289 /******************************************************************************* 290 * 291 * FUNCTION: AcpiDbUnloadAcpiTable 292 * 293 * PARAMETERS: TableArg - Name of the table to be unloaded 294 * InstanceArg - Which instance of the table to unload (if 295 * there are multiple tables of the same type) 296 * 297 * RETURN: Nonde 298 * 299 * DESCRIPTION: Unload an ACPI table. 300 * Instance is not implemented 301 * 302 ******************************************************************************/ 303 304 void 305 AcpiDbUnloadAcpiTable ( 306 char *TableArg, 307 char *InstanceArg) 308 { 309 /* TBD: Need to reimplement for new data structures */ 310 311 #if 0 312 UINT32 i; 313 ACPI_STATUS Status; 314 315 316 /* Search all tables for the target type */ 317 318 for (i = 0; i < (ACPI_TABLE_ID_MAX+1); i++) 319 { 320 if (!ACPI_STRNCMP (TableArg, AcpiGbl_TableData[i].Signature, 321 AcpiGbl_TableData[i].SigLength)) 322 { 323 /* Found the table, unload it */ 324 325 Status = AcpiUnloadTable (i); 326 if (ACPI_SUCCESS (Status)) 327 { 328 AcpiOsPrintf ("[%s] unloaded and uninstalled\n", TableArg); 329 } 330 else 331 { 332 AcpiOsPrintf ("%s, while unloading [%s]\n", 333 AcpiFormatException (Status), TableArg); 334 } 335 336 return; 337 } 338 } 339 340 AcpiOsPrintf ("Unknown table type [%s]\n", TableArg); 341 #endif 342 } 343 344 345 /******************************************************************************* 346 * 347 * FUNCTION: AcpiDbSendNotify 348 * 349 * PARAMETERS: Name - Name of ACPI object to send the notify to 350 * Value - Value of the notify to send. 351 * 352 * RETURN: None 353 * 354 * DESCRIPTION: Send an ACPI notification. The value specified is sent to the 355 * named object as an ACPI notify. 356 * 357 ******************************************************************************/ 358 359 void 360 AcpiDbSendNotify ( 361 char *Name, 362 UINT32 Value) 363 { 364 ACPI_NAMESPACE_NODE *Node; 365 ACPI_STATUS Status; 366 367 368 /* Translate name to an Named object */ 369 370 Node = AcpiDbConvertToNode (Name); 371 if (!Node) 372 { 373 return; 374 } 375 376 /* Decode Named object type */ 377 378 switch (Node->Type) 379 { 380 case ACPI_TYPE_DEVICE: 381 case ACPI_TYPE_THERMAL: 382 383 /* Send the notify */ 384 385 Status = AcpiEvQueueNotifyRequest (Node, Value); 386 if (ACPI_FAILURE (Status)) 387 { 388 AcpiOsPrintf ("Could not queue notify\n"); 389 } 390 break; 391 392 default: 393 AcpiOsPrintf ("Named object is not a device or a thermal object\n"); 394 break; 395 } 396 } 397 398 399 /******************************************************************************* 400 * 401 * FUNCTION: AcpiDbDisplayInterfaces 402 * 403 * PARAMETERS: ActionArg - Null, "install", or "remove" 404 * InterfaceNameArg - Name for install/remove options 405 * 406 * RETURN: None 407 * 408 * DESCRIPTION: Display or modify the global _OSI interface list 409 * 410 ******************************************************************************/ 411 412 void 413 AcpiDbDisplayInterfaces ( 414 char *ActionArg, 415 char *InterfaceNameArg) 416 { 417 ACPI_INTERFACE_INFO *NextInterface; 418 char *SubString; 419 ACPI_STATUS Status; 420 421 422 /* If no arguments, just display current interface list */ 423 424 if (!ActionArg) 425 { 426 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, 427 ACPI_WAIT_FOREVER); 428 429 NextInterface = AcpiGbl_SupportedInterfaces; 430 431 while (NextInterface) 432 { 433 if (!(NextInterface->Flags & ACPI_OSI_INVALID)) 434 { 435 AcpiOsPrintf ("%s\n", NextInterface->Name); 436 } 437 NextInterface = NextInterface->Next; 438 } 439 440 AcpiOsReleaseMutex (AcpiGbl_OsiMutex); 441 return; 442 } 443 444 /* If ActionArg exists, so must InterfaceNameArg */ 445 446 if (!InterfaceNameArg) 447 { 448 AcpiOsPrintf ("Missing Interface Name argument\n"); 449 return; 450 } 451 452 /* Uppercase the action for match below */ 453 454 AcpiUtStrupr (ActionArg); 455 456 /* Install - install an interface */ 457 458 SubString = ACPI_STRSTR ("INSTALL", ActionArg); 459 if (SubString) 460 { 461 Status = AcpiInstallInterface (InterfaceNameArg); 462 if (ACPI_FAILURE (Status)) 463 { 464 AcpiOsPrintf ("%s, while installing \"%s\"\n", 465 AcpiFormatException (Status), InterfaceNameArg); 466 } 467 return; 468 } 469 470 /* Remove - remove an interface */ 471 472 SubString = ACPI_STRSTR ("REMOVE", ActionArg); 473 if (SubString) 474 { 475 Status = AcpiRemoveInterface (InterfaceNameArg); 476 if (ACPI_FAILURE (Status)) 477 { 478 AcpiOsPrintf ("%s, while removing \"%s\"\n", 479 AcpiFormatException (Status), InterfaceNameArg); 480 } 481 return; 482 } 483 484 /* Invalid ActionArg */ 485 486 AcpiOsPrintf ("Invalid action argument: %s\n", ActionArg); 487 return; 488 } 489 490 491 /******************************************************************************* 492 * 493 * FUNCTION: AcpiDbDisplayTemplate 494 * 495 * PARAMETERS: BufferArg - Buffer name or addrss 496 * 497 * RETURN: None 498 * 499 * DESCRIPTION: Dump a buffer that contains a resource template 500 * 501 ******************************************************************************/ 502 503 void 504 AcpiDbDisplayTemplate ( 505 char *BufferArg) 506 { 507 ACPI_NAMESPACE_NODE *Node; 508 ACPI_STATUS Status; 509 ACPI_BUFFER ReturnObj; 510 511 512 /* Translate BufferArg to an Named object */ 513 514 Node = AcpiDbConvertToNode (BufferArg); 515 if (!Node || (Node == AcpiGbl_RootNode)) 516 { 517 AcpiOsPrintf ("Invalid argument: %s\n", BufferArg); 518 return; 519 } 520 521 /* We must have a buffer object */ 522 523 if (Node->Type != ACPI_TYPE_BUFFER) 524 { 525 AcpiOsPrintf ("Not a Buffer object, cannot be a template: %s\n", 526 BufferArg); 527 return; 528 } 529 530 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 531 ReturnObj.Pointer = AcpiGbl_DbBuffer; 532 533 /* Attempt to convert the raw buffer to a resource list */ 534 535 Status = AcpiRsCreateResourceList (Node->Object, &ReturnObj); 536 537 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); 538 AcpiDbgLevel |= ACPI_LV_RESOURCES; 539 540 if (ACPI_FAILURE (Status)) 541 { 542 AcpiOsPrintf ("Could not convert Buffer to a resource list: %s, %s\n", 543 BufferArg, AcpiFormatException (Status)); 544 goto DumpBuffer; 545 } 546 547 /* Now we can dump the resource list */ 548 549 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, 550 ReturnObj.Pointer)); 551 552 DumpBuffer: 553 AcpiOsPrintf ("\nRaw data buffer:\n"); 554 AcpiUtDumpBuffer ((UINT8 *) Node->Object->Buffer.Pointer, 555 Node->Object->Buffer.Length, 556 DB_BYTE_DISPLAY, ACPI_UINT32_MAX); 557 558 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 559 return; 560 } 561 562 563 /******************************************************************************* 564 * 565 * FUNCTION: AcpiDmCompareAmlResources 566 * 567 * PARAMETERS: Aml1Buffer - Contains first resource list 568 * Aml1BufferLength - Length of first resource list 569 * Aml2Buffer - Contains second resource list 570 * Aml2BufferLength - Length of second resource list 571 * 572 * RETURN: None 573 * 574 * DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in 575 * order to isolate a miscompare to an individual resource) 576 * 577 ******************************************************************************/ 578 579 static void 580 AcpiDmCompareAmlResources ( 581 UINT8 *Aml1Buffer, 582 ACPI_RSDESC_SIZE Aml1BufferLength, 583 UINT8 *Aml2Buffer, 584 ACPI_RSDESC_SIZE Aml2BufferLength) 585 { 586 UINT8 *Aml1; 587 UINT8 *Aml2; 588 UINT8 *Aml1End; 589 UINT8 *Aml2End; 590 ACPI_RSDESC_SIZE Aml1Length; 591 ACPI_RSDESC_SIZE Aml2Length; 592 ACPI_RSDESC_SIZE Offset = 0; 593 UINT8 ResourceType; 594 UINT32 Count = 0; 595 UINT32 i; 596 597 598 /* Compare overall buffer sizes (may be different due to size rounding) */ 599 600 if (Aml1BufferLength != Aml2BufferLength) 601 { 602 AcpiOsPrintf ( 603 "**** Buffer length mismatch in converted AML: Original %X, New %X ****\n", 604 Aml1BufferLength, Aml2BufferLength); 605 } 606 607 Aml1 = Aml1Buffer; 608 Aml2 = Aml2Buffer; 609 Aml1End = Aml1Buffer + Aml1BufferLength; 610 Aml2End = Aml2Buffer + Aml2BufferLength; 611 612 /* Walk the descriptor lists, comparing each descriptor */ 613 614 while ((Aml1 < Aml1End) && (Aml2 < Aml2End)) 615 { 616 /* Get the lengths of each descriptor */ 617 618 Aml1Length = AcpiUtGetDescriptorLength (Aml1); 619 Aml2Length = AcpiUtGetDescriptorLength (Aml2); 620 ResourceType = AcpiUtGetResourceType (Aml1); 621 622 /* Check for descriptor length match */ 623 624 if (Aml1Length != Aml2Length) 625 { 626 AcpiOsPrintf ( 627 "**** Length mismatch in descriptor [%.2X] type %2.2X, Offset %8.8X Len1 %X, Len2 %X ****\n", 628 Count, ResourceType, Offset, Aml1Length, Aml2Length); 629 } 630 631 /* Check for descriptor byte match */ 632 633 else if (ACPI_MEMCMP (Aml1, Aml2, Aml1Length)) 634 { 635 AcpiOsPrintf ( 636 "**** Data mismatch in descriptor [%.2X] type %2.2X, Offset %8.8X ****\n", 637 Count, ResourceType, Offset); 638 639 for (i = 0; i < Aml1Length; i++) 640 { 641 if (Aml1[i] != Aml2[i]) 642 { 643 AcpiOsPrintf ("Mismatch at byte offset %.2X: is %2.2X, should be %2.2X\n", 644 i, Aml2[i], Aml1[i]); 645 } 646 } 647 } 648 649 /* Exit on EndTag descriptor */ 650 651 if (ResourceType == ACPI_RESOURCE_NAME_END_TAG) 652 { 653 return; 654 } 655 656 /* Point to next descriptor in each buffer */ 657 658 Count++; 659 Offset += Aml1Length; 660 Aml1 += Aml1Length; 661 Aml2 += Aml2Length; 662 } 663 } 664 665 666 /******************************************************************************* 667 * 668 * FUNCTION: AcpiDmTestResourceConversion 669 * 670 * PARAMETERS: Node - Parent device node 671 * Name - resource method name (_CRS) 672 * 673 * RETURN: Status 674 * 675 * DESCRIPTION: Compare the original AML with a conversion of the AML to 676 * internal resource list, then back to AML. 677 * 678 ******************************************************************************/ 679 680 static ACPI_STATUS 681 AcpiDmTestResourceConversion ( 682 ACPI_NAMESPACE_NODE *Node, 683 char *Name) 684 { 685 ACPI_STATUS Status; 686 ACPI_BUFFER ReturnObj; 687 ACPI_BUFFER ResourceObj; 688 ACPI_BUFFER NewAml; 689 ACPI_OBJECT *OriginalAml; 690 691 692 AcpiOsPrintf ("Resource Conversion Comparison:\n"); 693 694 NewAml.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 695 ReturnObj.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 696 ResourceObj.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 697 698 /* Get the original _CRS AML resource template */ 699 700 Status = AcpiEvaluateObject (Node, Name, NULL, &ReturnObj); 701 if (ACPI_FAILURE (Status)) 702 { 703 AcpiOsPrintf ("Could not obtain %s: %s\n", 704 Name, AcpiFormatException (Status)); 705 return (Status); 706 } 707 708 /* Get the AML resource template, converted to internal resource structs */ 709 710 Status = AcpiGetCurrentResources (Node, &ResourceObj); 711 if (ACPI_FAILURE (Status)) 712 { 713 AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n", 714 AcpiFormatException (Status)); 715 goto Exit1; 716 } 717 718 /* Convert internal resource list to external AML resource template */ 719 720 Status = AcpiRsCreateAmlResources (ResourceObj.Pointer, &NewAml); 721 if (ACPI_FAILURE (Status)) 722 { 723 AcpiOsPrintf ("AcpiRsCreateAmlResources failed: %s\n", 724 AcpiFormatException (Status)); 725 goto Exit2; 726 } 727 728 /* Compare original AML to the newly created AML resource list */ 729 730 OriginalAml = ReturnObj.Pointer; 731 732 AcpiDmCompareAmlResources ( 733 OriginalAml->Buffer.Pointer, (ACPI_RSDESC_SIZE) OriginalAml->Buffer.Length, 734 NewAml.Pointer, (ACPI_RSDESC_SIZE) NewAml.Length); 735 736 /* Cleanup and exit */ 737 738 ACPI_FREE (NewAml.Pointer); 739 Exit2: 740 ACPI_FREE (ResourceObj.Pointer); 741 Exit1: 742 ACPI_FREE (ReturnObj.Pointer); 743 return (Status); 744 } 745 746 747 /******************************************************************************* 748 * 749 * FUNCTION: AcpiDbResourceCallback 750 * 751 * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK 752 * 753 * RETURN: Status 754 * 755 * DESCRIPTION: Simple callback to exercise AcpiWalkResources 756 * 757 ******************************************************************************/ 758 759 static ACPI_STATUS 760 AcpiDbResourceCallback ( 761 ACPI_RESOURCE *Resource, 762 void *Context) 763 { 764 765 return (AE_OK); 766 } 767 768 769 /******************************************************************************* 770 * 771 * FUNCTION: AcpiDbDeviceResources 772 * 773 * PARAMETERS: ACPI_WALK_CALLBACK 774 * 775 * RETURN: Status 776 * 777 * DESCRIPTION: Display the _PRT/_CRS/_PRS resources for a device object. 778 * 779 ******************************************************************************/ 780 781 static ACPI_STATUS 782 AcpiDbDeviceResources ( 783 ACPI_HANDLE ObjHandle, 784 UINT32 NestingLevel, 785 void *Context, 786 void **ReturnValue) 787 { 788 ACPI_NAMESPACE_NODE *Node; 789 ACPI_NAMESPACE_NODE *PrtNode = NULL; 790 ACPI_NAMESPACE_NODE *CrsNode = NULL; 791 ACPI_NAMESPACE_NODE *PrsNode = NULL; 792 ACPI_NAMESPACE_NODE *AeiNode = NULL; 793 char *ParentPath; 794 ACPI_BUFFER ReturnObj; 795 ACPI_STATUS Status; 796 797 798 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle); 799 ParentPath = AcpiNsGetExternalPathname (Node); 800 if (!ParentPath) 801 { 802 return (AE_NO_MEMORY); 803 } 804 805 /* Get handles to the resource methods for this device */ 806 807 (void) AcpiGetHandle (Node, METHOD_NAME__PRT, ACPI_CAST_PTR (ACPI_HANDLE, &PrtNode)); 808 (void) AcpiGetHandle (Node, METHOD_NAME__CRS, ACPI_CAST_PTR (ACPI_HANDLE, &CrsNode)); 809 (void) AcpiGetHandle (Node, METHOD_NAME__PRS, ACPI_CAST_PTR (ACPI_HANDLE, &PrsNode)); 810 (void) AcpiGetHandle (Node, METHOD_NAME__AEI, ACPI_CAST_PTR (ACPI_HANDLE, &AeiNode)); 811 if (!PrtNode && !CrsNode && !PrsNode && !AeiNode) 812 { 813 goto Cleanup; /* Nothing to do */ 814 } 815 816 AcpiOsPrintf ("\nDevice: %s\n", ParentPath); 817 818 /* Prepare for a return object of arbitrary size */ 819 820 ReturnObj.Pointer = AcpiGbl_DbBuffer; 821 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 822 823 824 /* _PRT */ 825 826 if (PrtNode) 827 { 828 AcpiOsPrintf ("Evaluating _PRT\n"); 829 830 Status = AcpiEvaluateObject (PrtNode, NULL, NULL, &ReturnObj); 831 if (ACPI_FAILURE (Status)) 832 { 833 AcpiOsPrintf ("Could not evaluate _PRT: %s\n", 834 AcpiFormatException (Status)); 835 goto GetCrs; 836 } 837 838 ReturnObj.Pointer = AcpiGbl_DbBuffer; 839 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 840 841 Status = AcpiGetIrqRoutingTable (Node, &ReturnObj); 842 if (ACPI_FAILURE (Status)) 843 { 844 AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n", 845 AcpiFormatException (Status)); 846 goto GetCrs; 847 } 848 849 AcpiRsDumpIrqList (ACPI_CAST_PTR (UINT8, AcpiGbl_DbBuffer)); 850 } 851 852 853 /* _CRS */ 854 855 GetCrs: 856 if (CrsNode) 857 { 858 AcpiOsPrintf ("Evaluating _CRS\n"); 859 860 ReturnObj.Pointer = AcpiGbl_DbBuffer; 861 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 862 863 Status = AcpiEvaluateObject (CrsNode, NULL, NULL, &ReturnObj); 864 if (ACPI_FAILURE (Status)) 865 { 866 AcpiOsPrintf ("Could not evaluate _CRS: %s\n", 867 AcpiFormatException (Status)); 868 goto GetPrs; 869 } 870 871 /* This code is here to exercise the AcpiWalkResources interface */ 872 873 Status = AcpiWalkResources (Node, METHOD_NAME__CRS, 874 AcpiDbResourceCallback, NULL); 875 if (ACPI_FAILURE (Status)) 876 { 877 AcpiOsPrintf ("AcpiWalkResources failed: %s\n", 878 AcpiFormatException (Status)); 879 goto GetPrs; 880 } 881 882 /* Get the _CRS resource list */ 883 884 ReturnObj.Pointer = AcpiGbl_DbBuffer; 885 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 886 887 Status = AcpiGetCurrentResources (Node, &ReturnObj); 888 if (ACPI_FAILURE (Status)) 889 { 890 AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n", 891 AcpiFormatException (Status)); 892 goto GetPrs; 893 } 894 895 /* Dump the _CRS resource list */ 896 897 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, 898 ReturnObj.Pointer)); 899 900 /* 901 * Perform comparison of original AML to newly created AML. This tests both 902 * the AML->Resource conversion and the Resource->Aml conversion. 903 */ 904 Status = AcpiDmTestResourceConversion (Node, METHOD_NAME__CRS); 905 906 /* Execute _SRS with the resource list */ 907 908 Status = AcpiSetCurrentResources (Node, &ReturnObj); 909 if (ACPI_FAILURE (Status)) 910 { 911 AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n", 912 AcpiFormatException (Status)); 913 goto GetPrs; 914 } 915 } 916 917 918 /* _PRS */ 919 920 GetPrs: 921 if (PrsNode) 922 { 923 AcpiOsPrintf ("Evaluating _PRS\n"); 924 925 ReturnObj.Pointer = AcpiGbl_DbBuffer; 926 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 927 928 Status = AcpiEvaluateObject (PrsNode, NULL, NULL, &ReturnObj); 929 if (ACPI_FAILURE (Status)) 930 { 931 AcpiOsPrintf ("Could not evaluate _PRS: %s\n", 932 AcpiFormatException (Status)); 933 goto GetAei; 934 } 935 936 ReturnObj.Pointer = AcpiGbl_DbBuffer; 937 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 938 939 Status = AcpiGetPossibleResources (Node, &ReturnObj); 940 if (ACPI_FAILURE (Status)) 941 { 942 AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n", 943 AcpiFormatException (Status)); 944 goto GetAei; 945 } 946 947 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer)); 948 } 949 950 951 /* _AEI */ 952 953 GetAei: 954 if (AeiNode) 955 { 956 AcpiOsPrintf ("Evaluating _AEI\n"); 957 958 ReturnObj.Pointer = AcpiGbl_DbBuffer; 959 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 960 961 Status = AcpiEvaluateObject (AeiNode, NULL, NULL, &ReturnObj); 962 if (ACPI_FAILURE (Status)) 963 { 964 AcpiOsPrintf ("Could not evaluate _AEI: %s\n", 965 AcpiFormatException (Status)); 966 goto Cleanup; 967 } 968 969 ReturnObj.Pointer = AcpiGbl_DbBuffer; 970 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE; 971 972 Status = AcpiGetEventResources (Node, &ReturnObj); 973 if (ACPI_FAILURE (Status)) 974 { 975 AcpiOsPrintf ("AcpiGetEventResources failed: %s\n", 976 AcpiFormatException (Status)); 977 goto Cleanup; 978 } 979 980 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer)); 981 } 982 983 984 Cleanup: 985 ACPI_FREE (ParentPath); 986 return (AE_OK); 987 } 988 989 990 /******************************************************************************* 991 * 992 * FUNCTION: AcpiDbDisplayResources 993 * 994 * PARAMETERS: ObjectArg - String object name or object pointer. 995 * "*" means "display resources for all devices" 996 * 997 * RETURN: None 998 * 999 * DESCRIPTION: Display the resource objects associated with a device. 1000 * 1001 ******************************************************************************/ 1002 1003 void 1004 AcpiDbDisplayResources ( 1005 char *ObjectArg) 1006 { 1007 ACPI_NAMESPACE_NODE *Node; 1008 1009 1010 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); 1011 AcpiDbgLevel |= ACPI_LV_RESOURCES; 1012 1013 /* Asterisk means "display resources for all devices" */ 1014 1015 if (!ACPI_STRCMP (ObjectArg, "*")) 1016 { 1017 (void) AcpiWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 1018 ACPI_UINT32_MAX, AcpiDbDeviceResources, NULL, NULL, NULL); 1019 } 1020 else 1021 { 1022 /* Convert string to object pointer */ 1023 1024 Node = AcpiDbConvertToNode (ObjectArg); 1025 if (Node) 1026 { 1027 if (Node->Type != ACPI_TYPE_DEVICE) 1028 { 1029 AcpiOsPrintf ("%4.4s: Name is not a device object (%s)\n", 1030 Node->Name.Ascii, AcpiUtGetTypeName (Node->Type)); 1031 } 1032 else 1033 { 1034 (void) AcpiDbDeviceResources (Node, 0, NULL, NULL); 1035 } 1036 } 1037 } 1038 1039 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 1040 } 1041 1042 1043 #if (!ACPI_REDUCED_HARDWARE) 1044 /******************************************************************************* 1045 * 1046 * FUNCTION: AcpiDbGenerateGpe 1047 * 1048 * PARAMETERS: GpeArg - Raw GPE number, ascii string 1049 * BlockArg - GPE block number, ascii string 1050 * 0 or 1 for FADT GPE blocks 1051 * 1052 * RETURN: None 1053 * 1054 * DESCRIPTION: Generate a GPE 1055 * 1056 ******************************************************************************/ 1057 1058 void 1059 AcpiDbGenerateGpe ( 1060 char *GpeArg, 1061 char *BlockArg) 1062 { 1063 UINT32 BlockNumber; 1064 UINT32 GpeNumber; 1065 ACPI_GPE_EVENT_INFO *GpeEventInfo; 1066 1067 1068 GpeNumber = ACPI_STRTOUL (GpeArg, NULL, 0); 1069 BlockNumber = ACPI_STRTOUL (BlockArg, NULL, 0); 1070 1071 1072 GpeEventInfo = AcpiEvGetGpeEventInfo (ACPI_TO_POINTER (BlockNumber), 1073 GpeNumber); 1074 if (!GpeEventInfo) 1075 { 1076 AcpiOsPrintf ("Invalid GPE\n"); 1077 return; 1078 } 1079 1080 (void) AcpiEvGpeDispatch (NULL, GpeEventInfo, GpeNumber); 1081 } 1082 #endif /* !ACPI_REDUCED_HARDWARE */ 1083 1084 #endif /* ACPI_DEBUGGER */ 1085