1 /******************************************************************************* 2 * 3 * Module Name: rsdump - AML debugger support for resource structures. 4 * 5 ******************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2023, 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 MERCHANTABILITY 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 #include "acpi.h" 45 #include "accommon.h" 46 #include "acresrc.h" 47 48 #define _COMPONENT ACPI_RESOURCES 49 ACPI_MODULE_NAME ("rsdump") 50 51 /* 52 * All functions in this module are used by the AML Debugger only 53 */ 54 55 /* Local prototypes */ 56 57 static void 58 AcpiRsOutString ( 59 const char *Title, 60 const char *Value); 61 62 static void 63 AcpiRsOutInteger8 ( 64 const char *Title, 65 UINT8 Value); 66 67 static void 68 AcpiRsOutInteger16 ( 69 const char *Title, 70 UINT16 Value); 71 72 static void 73 AcpiRsOutInteger32 ( 74 const char *Title, 75 UINT32 Value); 76 77 static void 78 AcpiRsOutInteger64 ( 79 const char *Title, 80 UINT64 Value); 81 82 static void 83 AcpiRsOutTitle ( 84 const char *Title); 85 86 static void 87 AcpiRsDumpByteList ( 88 UINT16 Length, 89 UINT8 *Data); 90 91 static void 92 AcpiRsDumpWordList ( 93 UINT16 Length, 94 UINT16 *Data); 95 96 static void 97 AcpiRsDumpDwordList ( 98 UINT8 Length, 99 UINT32 *Data); 100 101 static void 102 AcpiRsDumpShortByteList ( 103 UINT8 Length, 104 UINT8 *Data); 105 106 static void 107 AcpiRsDumpResourceSource ( 108 ACPI_RESOURCE_SOURCE *ResourceSource); 109 110 static void 111 AcpiRsDumpResourceLabel ( 112 const char *Title, 113 ACPI_RESOURCE_LABEL *ResourceLabel); 114 115 static void 116 AcpiRsDumpAddressCommon ( 117 ACPI_RESOURCE_DATA *Resource); 118 119 static void 120 AcpiRsDumpDescriptor ( 121 void *Resource, 122 ACPI_RSDUMP_INFO *Table); 123 124 125 #ifdef ACPI_DEBUGGER 126 /******************************************************************************* 127 * 128 * FUNCTION: AcpiRsDumpResourceList 129 * 130 * PARAMETERS: ResourceList - Pointer to a resource descriptor list 131 * 132 * RETURN: None 133 * 134 * DESCRIPTION: Dispatches the structure to the correct dump routine. 135 * 136 ******************************************************************************/ 137 138 void 139 AcpiRsDumpResourceList ( 140 ACPI_RESOURCE *ResourceList) 141 { 142 UINT32 Count = 0; 143 UINT32 Type; 144 145 146 ACPI_FUNCTION_ENTRY (); 147 148 149 /* Check if debug output enabled */ 150 151 if (!ACPI_IS_DEBUG_ENABLED (ACPI_LV_RESOURCES, _COMPONENT)) 152 { 153 return; 154 } 155 156 /* Walk list and dump all resource descriptors (END_TAG terminates) */ 157 158 do 159 { 160 AcpiOsPrintf ("\n[%02X] ", Count); 161 Count++; 162 163 /* Validate Type before dispatch */ 164 165 Type = ResourceList->Type; 166 if (Type > ACPI_RESOURCE_TYPE_MAX) 167 { 168 AcpiOsPrintf ( 169 "Invalid descriptor type (%X) in resource list\n", 170 ResourceList->Type); 171 return; 172 } 173 else if (!ResourceList->Type) 174 { 175 ACPI_ERROR ((AE_INFO, "Invalid Zero Resource Type")); 176 return; 177 } 178 179 /* Sanity check the length. It must not be zero, or we loop forever */ 180 181 if (!ResourceList->Length) 182 { 183 AcpiOsPrintf ( 184 "Invalid zero length descriptor in resource list\n"); 185 return; 186 } 187 188 /* Dump the resource descriptor */ 189 190 if (Type == ACPI_RESOURCE_TYPE_SERIAL_BUS) 191 { 192 AcpiRsDumpDescriptor (&ResourceList->Data, 193 AcpiGbl_DumpSerialBusDispatch[ 194 ResourceList->Data.CommonSerialBus.Type]); 195 } 196 else 197 { 198 AcpiRsDumpDescriptor (&ResourceList->Data, 199 AcpiGbl_DumpResourceDispatch[Type]); 200 } 201 202 /* Point to the next resource structure */ 203 204 ResourceList = ACPI_NEXT_RESOURCE (ResourceList); 205 206 /* Exit when END_TAG descriptor is reached */ 207 208 } while (Type != ACPI_RESOURCE_TYPE_END_TAG); 209 } 210 211 212 /******************************************************************************* 213 * 214 * FUNCTION: AcpiRsDumpIrqList 215 * 216 * PARAMETERS: RouteTable - Pointer to the routing table to dump. 217 * 218 * RETURN: None 219 * 220 * DESCRIPTION: Print IRQ routing table 221 * 222 ******************************************************************************/ 223 224 void 225 AcpiRsDumpIrqList ( 226 UINT8 *RouteTable) 227 { 228 ACPI_PCI_ROUTING_TABLE *PrtElement; 229 UINT8 Count; 230 231 232 ACPI_FUNCTION_ENTRY (); 233 234 235 /* Check if debug output enabled */ 236 237 if (!ACPI_IS_DEBUG_ENABLED (ACPI_LV_RESOURCES, _COMPONENT)) 238 { 239 return; 240 } 241 242 PrtElement = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, RouteTable); 243 244 /* Dump all table elements, Exit on zero length element */ 245 246 for (Count = 0; PrtElement->Length; Count++) 247 { 248 AcpiOsPrintf ("\n[%02X] PCI IRQ Routing Table Package\n", Count); 249 AcpiRsDumpDescriptor (PrtElement, AcpiRsDumpPrt); 250 251 PrtElement = ACPI_ADD_PTR (ACPI_PCI_ROUTING_TABLE, 252 PrtElement, PrtElement->Length); 253 } 254 } 255 #endif 256 257 /******************************************************************************* 258 * 259 * FUNCTION: AcpiRsDumpDescriptor 260 * 261 * PARAMETERS: Resource - Buffer containing the resource 262 * Table - Table entry to decode the resource 263 * 264 * RETURN: None 265 * 266 * DESCRIPTION: Dump a resource descriptor based on a dump table entry. 267 * 268 ******************************************************************************/ 269 270 static void 271 AcpiRsDumpDescriptor ( 272 void *Resource, 273 ACPI_RSDUMP_INFO *Table) 274 { 275 UINT8 *Target = NULL; 276 UINT8 *PreviousTarget; 277 const char *Name; 278 UINT8 Count; 279 280 281 /* First table entry must contain the table length (# of table entries) */ 282 283 Count = Table->Offset; 284 285 while (Count) 286 { 287 PreviousTarget = Target; 288 Target = ACPI_ADD_PTR (UINT8, Resource, Table->Offset); 289 Name = Table->Name; 290 291 switch (Table->Opcode) 292 { 293 case ACPI_RSD_TITLE: 294 /* 295 * Optional resource title 296 */ 297 if (Table->Name) 298 { 299 AcpiOsPrintf ("%s Resource\n", Name); 300 } 301 break; 302 303 /* Strings */ 304 305 case ACPI_RSD_LITERAL: 306 307 AcpiRsOutString (Name, ACPI_CAST_PTR (char, Table->Pointer)); 308 break; 309 310 case ACPI_RSD_STRING: 311 312 AcpiRsOutString (Name, ACPI_CAST_PTR (char, Target)); 313 break; 314 315 /* Data items, 8/16/32/64 bit */ 316 317 case ACPI_RSD_UINT8: 318 319 if (Table->Pointer) 320 { 321 AcpiRsOutString (Name, Table->Pointer [*Target]); 322 } 323 else 324 { 325 AcpiRsOutInteger8 (Name, ACPI_GET8 (Target)); 326 } 327 break; 328 329 case ACPI_RSD_UINT16: 330 331 AcpiRsOutInteger16 (Name, ACPI_GET16 (Target)); 332 break; 333 334 case ACPI_RSD_UINT32: 335 336 AcpiRsOutInteger32 (Name, ACPI_GET32 (Target)); 337 break; 338 339 case ACPI_RSD_UINT64: 340 341 AcpiRsOutInteger64 (Name, ACPI_GET64 (Target)); 342 break; 343 344 /* Flags: 1-bit and 2-bit flags supported */ 345 346 case ACPI_RSD_1BITFLAG: 347 348 AcpiRsOutString (Name, Table->Pointer [*Target & 0x01]); 349 break; 350 351 case ACPI_RSD_2BITFLAG: 352 353 AcpiRsOutString (Name, Table->Pointer [*Target & 0x03]); 354 break; 355 356 case ACPI_RSD_3BITFLAG: 357 358 AcpiRsOutString (Name, Table->Pointer [*Target & 0x07]); 359 break; 360 361 case ACPI_RSD_6BITFLAG: 362 363 AcpiRsOutInteger8 (Name, (ACPI_GET8 (Target) & 0x3F)); 364 break; 365 366 case ACPI_RSD_SHORTLIST: 367 /* 368 * Short byte list (single line output) for DMA and IRQ resources 369 * Note: The list length is obtained from the previous table entry 370 */ 371 if (PreviousTarget) 372 { 373 AcpiRsOutTitle (Name); 374 AcpiRsDumpShortByteList (*PreviousTarget, Target); 375 } 376 break; 377 378 case ACPI_RSD_SHORTLISTX: 379 /* 380 * Short byte list (single line output) for GPIO vendor data 381 * Note: The list length is obtained from the previous table entry 382 */ 383 if (PreviousTarget) 384 { 385 AcpiRsOutTitle (Name); 386 AcpiRsDumpShortByteList (*PreviousTarget, 387 *(ACPI_CAST_INDIRECT_PTR (UINT8, Target))); 388 } 389 break; 390 391 case ACPI_RSD_LONGLIST: 392 /* 393 * Long byte list for Vendor resource data 394 * Note: The list length is obtained from the previous table entry 395 */ 396 if (PreviousTarget) 397 { 398 AcpiRsDumpByteList (ACPI_GET16 (PreviousTarget), Target); 399 } 400 break; 401 402 case ACPI_RSD_DWORDLIST: 403 /* 404 * Dword list for Extended Interrupt resources 405 * Note: The list length is obtained from the previous table entry 406 */ 407 if (PreviousTarget) 408 { 409 AcpiRsDumpDwordList (*PreviousTarget, 410 ACPI_CAST_PTR (UINT32, Target)); 411 } 412 break; 413 414 case ACPI_RSD_WORDLIST: 415 /* 416 * Word list for GPIO Pin Table 417 * Note: The list length is obtained from the previous table entry 418 */ 419 if (PreviousTarget) 420 { 421 AcpiRsDumpWordList (*PreviousTarget, 422 *(ACPI_CAST_INDIRECT_PTR (UINT16, Target))); 423 } 424 break; 425 426 case ACPI_RSD_ADDRESS: 427 /* 428 * Common flags for all Address resources 429 */ 430 AcpiRsDumpAddressCommon (ACPI_CAST_PTR ( 431 ACPI_RESOURCE_DATA, Target)); 432 break; 433 434 case ACPI_RSD_SOURCE: 435 /* 436 * Optional ResourceSource for Address resources 437 */ 438 AcpiRsDumpResourceSource (ACPI_CAST_PTR ( 439 ACPI_RESOURCE_SOURCE, Target)); 440 break; 441 442 case ACPI_RSD_LABEL: 443 /* 444 * ResourceLabel 445 */ 446 AcpiRsDumpResourceLabel ("Resource Label", ACPI_CAST_PTR ( 447 ACPI_RESOURCE_LABEL, Target)); 448 break; 449 450 case ACPI_RSD_SOURCE_LABEL: 451 /* 452 * ResourceSourceLabel 453 */ 454 AcpiRsDumpResourceLabel ("Resource Source Label", ACPI_CAST_PTR ( 455 ACPI_RESOURCE_LABEL, Target)); 456 break; 457 458 default: 459 460 AcpiOsPrintf ("**** Invalid table opcode [%X] ****\n", 461 Table->Opcode); 462 return; 463 } 464 465 Table++; 466 Count--; 467 } 468 } 469 470 471 /******************************************************************************* 472 * 473 * FUNCTION: AcpiRsDumpResourceSource 474 * 475 * PARAMETERS: ResourceSource - Pointer to a Resource Source struct 476 * 477 * RETURN: None 478 * 479 * DESCRIPTION: Common routine for dumping the optional ResourceSource and the 480 * corresponding ResourceSourceIndex. 481 * 482 ******************************************************************************/ 483 484 static void 485 AcpiRsDumpResourceSource ( 486 ACPI_RESOURCE_SOURCE *ResourceSource) 487 { 488 ACPI_FUNCTION_ENTRY (); 489 490 491 if (ResourceSource->Index == 0xFF) 492 { 493 return; 494 } 495 496 AcpiRsOutInteger8 ("Resource Source Index", 497 ResourceSource->Index); 498 499 AcpiRsOutString ("Resource Source", 500 ResourceSource->StringPtr ? 501 ResourceSource->StringPtr : "[Not Specified]"); 502 } 503 504 505 /******************************************************************************* 506 * 507 * FUNCTION: AcpiRsDumpResourceLabel 508 * 509 * PARAMETERS: Title - Title of the dumped resource field 510 * ResourceLabel - Pointer to a Resource Label struct 511 * 512 * RETURN: None 513 * 514 * DESCRIPTION: Common routine for dumping the ResourceLabel 515 * 516 ******************************************************************************/ 517 518 static void 519 AcpiRsDumpResourceLabel ( 520 const char *Title, 521 ACPI_RESOURCE_LABEL *ResourceLabel) 522 { 523 ACPI_FUNCTION_ENTRY (); 524 525 AcpiRsOutString (Title, 526 ResourceLabel->StringPtr ? 527 ResourceLabel->StringPtr : "[Not Specified]"); 528 } 529 530 531 /******************************************************************************* 532 * 533 * FUNCTION: AcpiRsDumpAddressCommon 534 * 535 * PARAMETERS: Resource - Pointer to an internal resource descriptor 536 * 537 * RETURN: None 538 * 539 * DESCRIPTION: Dump the fields that are common to all Address resource 540 * descriptors 541 * 542 ******************************************************************************/ 543 544 static void 545 AcpiRsDumpAddressCommon ( 546 ACPI_RESOURCE_DATA *Resource) 547 { 548 ACPI_FUNCTION_ENTRY (); 549 550 551 /* Decode the type-specific flags */ 552 553 switch (Resource->Address.ResourceType) 554 { 555 case ACPI_MEMORY_RANGE: 556 557 AcpiRsDumpDescriptor (Resource, AcpiRsDumpMemoryFlags); 558 break; 559 560 case ACPI_IO_RANGE: 561 562 AcpiRsDumpDescriptor (Resource, AcpiRsDumpIoFlags); 563 break; 564 565 case ACPI_BUS_NUMBER_RANGE: 566 567 AcpiRsOutString ("Resource Type", "Bus Number Range"); 568 break; 569 570 default: 571 572 AcpiRsOutInteger8 ("Resource Type", 573 (UINT8) Resource->Address.ResourceType); 574 break; 575 } 576 577 /* Decode the general flags */ 578 579 AcpiRsDumpDescriptor (Resource, AcpiRsDumpGeneralFlags); 580 } 581 582 583 /******************************************************************************* 584 * 585 * FUNCTION: AcpiRsOut* 586 * 587 * PARAMETERS: Title - Name of the resource field 588 * Value - Value of the resource field 589 * 590 * RETURN: None 591 * 592 * DESCRIPTION: Miscellaneous helper functions to consistently format the 593 * output of the resource dump routines 594 * 595 ******************************************************************************/ 596 597 static void 598 AcpiRsOutString ( 599 const char *Title, 600 const char *Value) 601 { 602 603 AcpiOsPrintf ("%27s : %s", Title, Value); 604 if (!*Value) 605 { 606 AcpiOsPrintf ("[NULL NAMESTRING]"); 607 } 608 AcpiOsPrintf ("\n"); 609 } 610 611 static void 612 AcpiRsOutInteger8 ( 613 const char *Title, 614 UINT8 Value) 615 { 616 AcpiOsPrintf ("%27s : %2.2X\n", Title, Value); 617 } 618 619 static void 620 AcpiRsOutInteger16 ( 621 const char *Title, 622 UINT16 Value) 623 { 624 625 AcpiOsPrintf ("%27s : %4.4X\n", Title, Value); 626 } 627 628 static void 629 AcpiRsOutInteger32 ( 630 const char *Title, 631 UINT32 Value) 632 { 633 634 AcpiOsPrintf ("%27s : %8.8X\n", Title, Value); 635 } 636 637 static void 638 AcpiRsOutInteger64 ( 639 const char *Title, 640 UINT64 Value) 641 { 642 643 AcpiOsPrintf ("%27s : %8.8X%8.8X\n", Title, 644 ACPI_FORMAT_UINT64 (Value)); 645 } 646 647 static void 648 AcpiRsOutTitle ( 649 const char *Title) 650 { 651 652 AcpiOsPrintf ("%27s : ", Title); 653 } 654 655 656 /******************************************************************************* 657 * 658 * FUNCTION: AcpiRsDump*List 659 * 660 * PARAMETERS: Length - Number of elements in the list 661 * Data - Start of the list 662 * 663 * RETURN: None 664 * 665 * DESCRIPTION: Miscellaneous functions to dump lists of raw data 666 * 667 ******************************************************************************/ 668 669 static void 670 AcpiRsDumpByteList ( 671 UINT16 Length, 672 UINT8 *Data) 673 { 674 UINT16 i; 675 676 677 for (i = 0; i < Length; i++) 678 { 679 AcpiOsPrintf ("%25s%2.2X : %2.2X\n", "Byte", i, Data[i]); 680 } 681 } 682 683 static void 684 AcpiRsDumpShortByteList ( 685 UINT8 Length, 686 UINT8 *Data) 687 { 688 UINT8 i; 689 690 691 for (i = 0; i < Length; i++) 692 { 693 AcpiOsPrintf ("%X ", Data[i]); 694 } 695 696 AcpiOsPrintf ("\n"); 697 } 698 699 static void 700 AcpiRsDumpDwordList ( 701 UINT8 Length, 702 UINT32 *Data) 703 { 704 UINT8 i; 705 706 707 for (i = 0; i < Length; i++) 708 { 709 AcpiOsPrintf ("%25s%2.2X : %8.8X\n", "Dword", i, Data[i]); 710 } 711 } 712 713 static void 714 AcpiRsDumpWordList ( 715 UINT16 Length, 716 UINT16 *Data) 717 { 718 UINT16 i; 719 720 721 for (i = 0; i < Length; i++) 722 { 723 AcpiOsPrintf ("%25s%2.2X : %4.4X\n", "Word", i, Data[i]); 724 } 725 } 726