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