Home | History | Annotate | Line # | Download | only in resources
rsdump.c revision 1.1.1.5
      1 /*******************************************************************************
      2  *
      3  * Module Name: rsdump - AML debugger support for resource structures.
      4  *
      5  ******************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2015, 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     char                    *Title,
     61     char                    *Value);
     62 
     63 static void
     64 AcpiRsOutInteger8 (
     65     char                    *Title,
     66     UINT8                   Value);
     67 
     68 static void
     69 AcpiRsOutInteger16 (
     70     char                    *Title,
     71     UINT16                  Value);
     72 
     73 static void
     74 AcpiRsOutInteger32 (
     75     char                    *Title,
     76     UINT32                  Value);
     77 
     78 static void
     79 AcpiRsOutInteger64 (
     80     char                    *Title,
     81     UINT64                  Value);
     82 
     83 static void
     84 AcpiRsOutTitle (
     85     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     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, ACPI_CAST_PTR (char,
    312                     Table->Pointer [*Target]));
    313             }
    314             else
    315             {
    316                 AcpiRsOutInteger8 (Name, ACPI_GET8 (Target));
    317             }
    318             break;
    319 
    320         case ACPI_RSD_UINT16:
    321 
    322             AcpiRsOutInteger16 (Name, ACPI_GET16 (Target));
    323             break;
    324 
    325         case ACPI_RSD_UINT32:
    326 
    327             AcpiRsOutInteger32 (Name, ACPI_GET32 (Target));
    328             break;
    329 
    330         case ACPI_RSD_UINT64:
    331 
    332             AcpiRsOutInteger64 (Name, ACPI_GET64 (Target));
    333             break;
    334 
    335         /* Flags: 1-bit and 2-bit flags supported */
    336 
    337         case ACPI_RSD_1BITFLAG:
    338 
    339             AcpiRsOutString (Name, ACPI_CAST_PTR (char,
    340                 Table->Pointer [*Target & 0x01]));
    341             break;
    342 
    343         case ACPI_RSD_2BITFLAG:
    344 
    345             AcpiRsOutString (Name, ACPI_CAST_PTR (char,
    346                 Table->Pointer [*Target & 0x03]));
    347             break;
    348 
    349         case ACPI_RSD_3BITFLAG:
    350 
    351             AcpiRsOutString (Name, ACPI_CAST_PTR (char,
    352                 Table->Pointer [*Target & 0x07]));
    353             break;
    354 
    355         case ACPI_RSD_SHORTLIST:
    356             /*
    357              * Short byte list (single line output) for DMA and IRQ resources
    358              * Note: The list length is obtained from the previous table entry
    359              */
    360             if (PreviousTarget)
    361             {
    362                 AcpiRsOutTitle (Name);
    363                 AcpiRsDumpShortByteList (*PreviousTarget, Target);
    364             }
    365             break;
    366 
    367         case ACPI_RSD_SHORTLISTX:
    368             /*
    369              * Short byte list (single line output) for GPIO vendor data
    370              * Note: The list length is obtained from the previous table entry
    371              */
    372             if (PreviousTarget)
    373             {
    374                 AcpiRsOutTitle (Name);
    375                 AcpiRsDumpShortByteList (*PreviousTarget,
    376                     *(ACPI_CAST_INDIRECT_PTR (UINT8, Target)));
    377             }
    378             break;
    379 
    380         case ACPI_RSD_LONGLIST:
    381             /*
    382              * Long byte list for Vendor resource data
    383              * Note: The list length is obtained from the previous table entry
    384              */
    385             if (PreviousTarget)
    386             {
    387                 AcpiRsDumpByteList (ACPI_GET16 (PreviousTarget), Target);
    388             }
    389             break;
    390 
    391         case ACPI_RSD_DWORDLIST:
    392             /*
    393              * Dword list for Extended Interrupt resources
    394              * Note: The list length is obtained from the previous table entry
    395              */
    396             if (PreviousTarget)
    397             {
    398                 AcpiRsDumpDwordList (*PreviousTarget,
    399                     ACPI_CAST_PTR (UINT32, Target));
    400             }
    401             break;
    402 
    403         case ACPI_RSD_WORDLIST:
    404             /*
    405              * Word list for GPIO Pin Table
    406              * Note: The list length is obtained from the previous table entry
    407              */
    408             if (PreviousTarget)
    409             {
    410                 AcpiRsDumpWordList (*PreviousTarget,
    411                     *(ACPI_CAST_INDIRECT_PTR (UINT16, Target)));
    412             }
    413             break;
    414 
    415         case ACPI_RSD_ADDRESS:
    416             /*
    417              * Common flags for all Address resources
    418              */
    419             AcpiRsDumpAddressCommon (ACPI_CAST_PTR (
    420                 ACPI_RESOURCE_DATA, Target));
    421             break;
    422 
    423         case ACPI_RSD_SOURCE:
    424             /*
    425              * Optional ResourceSource for Address resources
    426              */
    427             AcpiRsDumpResourceSource (ACPI_CAST_PTR (
    428                 ACPI_RESOURCE_SOURCE, Target));
    429             break;
    430 
    431         default:
    432 
    433             AcpiOsPrintf ("**** Invalid table opcode [%X] ****\n",
    434                 Table->Opcode);
    435             return;
    436         }
    437 
    438         Table++;
    439         Count--;
    440     }
    441 }
    442 
    443 
    444 /*******************************************************************************
    445  *
    446  * FUNCTION:    AcpiRsDumpResourceSource
    447  *
    448  * PARAMETERS:  ResourceSource      - Pointer to a Resource Source struct
    449  *
    450  * RETURN:      None
    451  *
    452  * DESCRIPTION: Common routine for dumping the optional ResourceSource and the
    453  *              corresponding ResourceSourceIndex.
    454  *
    455  ******************************************************************************/
    456 
    457 static void
    458 AcpiRsDumpResourceSource (
    459     ACPI_RESOURCE_SOURCE    *ResourceSource)
    460 {
    461     ACPI_FUNCTION_ENTRY ();
    462 
    463 
    464     if (ResourceSource->Index == 0xFF)
    465     {
    466         return;
    467     }
    468 
    469     AcpiRsOutInteger8 ("Resource Source Index",
    470         ResourceSource->Index);
    471 
    472     AcpiRsOutString ("Resource Source",
    473         ResourceSource->StringPtr ?
    474             ResourceSource->StringPtr : "[Not Specified]");
    475 }
    476 
    477 
    478 /*******************************************************************************
    479  *
    480  * FUNCTION:    AcpiRsDumpAddressCommon
    481  *
    482  * PARAMETERS:  Resource        - Pointer to an internal resource descriptor
    483  *
    484  * RETURN:      None
    485  *
    486  * DESCRIPTION: Dump the fields that are common to all Address resource
    487  *              descriptors
    488  *
    489  ******************************************************************************/
    490 
    491 static void
    492 AcpiRsDumpAddressCommon (
    493     ACPI_RESOURCE_DATA      *Resource)
    494 {
    495     ACPI_FUNCTION_ENTRY ();
    496 
    497 
    498    /* Decode the type-specific flags */
    499 
    500     switch (Resource->Address.ResourceType)
    501     {
    502     case ACPI_MEMORY_RANGE:
    503 
    504         AcpiRsDumpDescriptor (Resource, AcpiRsDumpMemoryFlags);
    505         break;
    506 
    507     case ACPI_IO_RANGE:
    508 
    509         AcpiRsDumpDescriptor (Resource, AcpiRsDumpIoFlags);
    510         break;
    511 
    512     case ACPI_BUS_NUMBER_RANGE:
    513 
    514         AcpiRsOutString ("Resource Type", "Bus Number Range");
    515         break;
    516 
    517     default:
    518 
    519         AcpiRsOutInteger8 ("Resource Type",
    520             (UINT8) Resource->Address.ResourceType);
    521         break;
    522     }
    523 
    524     /* Decode the general flags */
    525 
    526     AcpiRsDumpDescriptor (Resource, AcpiRsDumpGeneralFlags);
    527 }
    528 
    529 
    530 /*******************************************************************************
    531  *
    532  * FUNCTION:    AcpiRsOut*
    533  *
    534  * PARAMETERS:  Title       - Name of the resource field
    535  *              Value       - Value of the resource field
    536  *
    537  * RETURN:      None
    538  *
    539  * DESCRIPTION: Miscellaneous helper functions to consistently format the
    540  *              output of the resource dump routines
    541  *
    542  ******************************************************************************/
    543 
    544 static void
    545 AcpiRsOutString (
    546     char                    *Title,
    547     char                    *Value)
    548 {
    549     AcpiOsPrintf ("%27s : %s", Title, Value);
    550     if (!*Value)
    551     {
    552         AcpiOsPrintf ("[NULL NAMESTRING]");
    553     }
    554     AcpiOsPrintf ("\n");
    555 }
    556 
    557 static void
    558 AcpiRsOutInteger8 (
    559     char                    *Title,
    560     UINT8                   Value)
    561 {
    562     AcpiOsPrintf ("%27s : %2.2X\n", Title, Value);
    563 }
    564 
    565 static void
    566 AcpiRsOutInteger16 (
    567     char                    *Title,
    568     UINT16                  Value)
    569 {
    570     AcpiOsPrintf ("%27s : %4.4X\n", Title, Value);
    571 }
    572 
    573 static void
    574 AcpiRsOutInteger32 (
    575     char                    *Title,
    576     UINT32                  Value)
    577 {
    578     AcpiOsPrintf ("%27s : %8.8X\n", Title, Value);
    579 }
    580 
    581 static void
    582 AcpiRsOutInteger64 (
    583     char                    *Title,
    584     UINT64                  Value)
    585 {
    586     AcpiOsPrintf ("%27s : %8.8X%8.8X\n", Title,
    587         ACPI_FORMAT_UINT64 (Value));
    588 }
    589 
    590 static void
    591 AcpiRsOutTitle (
    592     char                    *Title)
    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",
    622             "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     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",
    652             "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",
    667             "Word", i, Data[i]);
    668     }
    669 }
    670 
    671 #endif
    672