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