Home | History | Annotate | Line # | Download | only in disassembler
dmbuffer.c revision 1.12
      1 /*******************************************************************************
      2  *
      3  * Module Name: dmbuffer - AML disassembler, buffer and string support
      4  *
      5  ******************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2020, 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 "acutils.h"
     47 #include "acdisasm.h"
     48 #include "acparser.h"
     49 #include "amlcode.h"
     50 #include "acinterp.h"
     51 
     52 
     53 #define _COMPONENT          ACPI_CA_DEBUGGER
     54         ACPI_MODULE_NAME    ("dmbuffer")
     55 
     56 /* Local prototypes */
     57 
     58 static void
     59 AcpiDmUuid (
     60     ACPI_PARSE_OBJECT       *Op);
     61 
     62 static void
     63 AcpiDmUnicode (
     64     ACPI_PARSE_OBJECT       *Op);
     65 
     66 static void
     67 AcpiDmGetHardwareIdType (
     68     ACPI_PARSE_OBJECT       *Op);
     69 
     70 static void
     71 AcpiDmPldBuffer (
     72     UINT32                  Level,
     73     UINT8                   *ByteData,
     74     UINT32                  ByteCount);
     75 
     76 static const char *
     77 AcpiDmFindNameByIndex (
     78     UINT64                  Index,
     79     const char              **List);
     80 
     81 
     82 #define ACPI_BUFFER_BYTES_PER_LINE      8
     83 
     84 
     85 /*******************************************************************************
     86  *
     87  * FUNCTION:    AcpiDmDisasmByteList
     88  *
     89  * PARAMETERS:  Level               - Current source code indentation level
     90  *              ByteData            - Pointer to the byte list
     91  *              ByteCount           - Length of the byte list
     92  *
     93  * RETURN:      None
     94  *
     95  * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
     96  *              with the hex buffer offset.
     97  *
     98  ******************************************************************************/
     99 
    100 void
    101 AcpiDmDisasmByteList (
    102     UINT32                  Level,
    103     UINT8                   *ByteData,
    104     UINT32                  ByteCount)
    105 {
    106     UINT32                  i;
    107     UINT32                  j;
    108     UINT32                  CurrentIndex;
    109     UINT8                   BufChar;
    110 
    111 
    112     if (!ByteCount)
    113     {
    114         return;
    115     }
    116 
    117     for (i = 0; i < ByteCount; i += ACPI_BUFFER_BYTES_PER_LINE)
    118     {
    119         /* Line indent and offset prefix for each new line */
    120 
    121         AcpiDmIndent (Level);
    122         if (ByteCount > ACPI_BUFFER_BYTES_PER_LINE)
    123         {
    124             AcpiOsPrintf ("/* %04X */ ", i);
    125         }
    126 
    127         /* Dump the actual hex values */
    128 
    129         for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
    130         {
    131             CurrentIndex = i + j;
    132             if (CurrentIndex >= ByteCount)
    133             {
    134                 /* Dump fill spaces */
    135 
    136                 AcpiOsPrintf ("      ");
    137                 continue;
    138             }
    139 
    140             AcpiOsPrintf (" 0x%2.2X", ByteData[CurrentIndex]);
    141 
    142             /* Add comma if there are more bytes to display */
    143 
    144             if (CurrentIndex < (ByteCount - 1))
    145             {
    146                 AcpiOsPrintf (",");
    147             }
    148             else
    149             {
    150                 AcpiOsPrintf (" ");
    151             }
    152         }
    153 
    154         /* Dump the ASCII equivalents within a comment */
    155 
    156         AcpiOsPrintf ("  // ");
    157         for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
    158         {
    159             CurrentIndex = i + j;
    160             if (CurrentIndex >= ByteCount)
    161             {
    162                 break;
    163             }
    164 
    165             BufChar = ByteData[CurrentIndex];
    166             if (isprint (BufChar))
    167             {
    168                 AcpiOsPrintf ("%c", BufChar);
    169             }
    170             else
    171             {
    172                 AcpiOsPrintf (".");
    173             }
    174         }
    175 
    176         /* Finished with this line */
    177 
    178         AcpiOsPrintf ("\n");
    179     }
    180 }
    181 
    182 
    183 /*******************************************************************************
    184  *
    185  * FUNCTION:    AcpiDmByteList
    186  *
    187  * PARAMETERS:  Info            - Parse tree walk info
    188  *              Op              - Byte list op
    189  *
    190  * RETURN:      None
    191  *
    192  * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
    193  *              Buffer type must be already set in the Op DisasmOpcode.
    194  *
    195  ******************************************************************************/
    196 
    197 void
    198 AcpiDmByteList (
    199     ACPI_OP_WALK_INFO       *Info,
    200     ACPI_PARSE_OBJECT       *Op)
    201 {
    202     UINT8                   *ByteData;
    203     UINT32                  ByteCount;
    204 
    205 
    206     ByteData = Op->Named.Data;
    207     ByteCount = (UINT32) Op->Common.Value.Integer;
    208 
    209     /*
    210      * The byte list belongs to a buffer, and can be produced by either
    211      * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
    212      */
    213     switch (Op->Common.Parent->Common.DisasmOpcode)
    214     {
    215     case ACPI_DASM_RESOURCE:
    216 
    217         AcpiDmResourceTemplate (
    218             Info, Op->Common.Parent, ByteData, ByteCount);
    219         break;
    220 
    221     case ACPI_DASM_STRING:
    222 
    223         AcpiDmIndent (Info->Level);
    224         AcpiUtPrintString ((char *) ByteData, ACPI_UINT16_MAX);
    225         AcpiOsPrintf ("\n");
    226         break;
    227 
    228     case ACPI_DASM_UUID:
    229 
    230         AcpiDmUuid (Op);
    231         break;
    232 
    233     case ACPI_DASM_UNICODE:
    234 
    235         AcpiDmUnicode (Op);
    236         break;
    237 
    238     case ACPI_DASM_PLD_METHOD:
    239 #if 0
    240         AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
    241 #endif
    242         AcpiDmPldBuffer (Info->Level, ByteData, ByteCount);
    243         break;
    244 
    245     case ACPI_DASM_BUFFER:
    246     default:
    247         /*
    248          * Not a resource, string, or unicode string.
    249          * Just dump the buffer
    250          */
    251         AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
    252         break;
    253     }
    254 }
    255 
    256 
    257 /*******************************************************************************
    258  *
    259  * FUNCTION:    AcpiDmIsUuidBuffer
    260  *
    261  * PARAMETERS:  Op              - Buffer Object to be examined
    262  *
    263  * RETURN:      TRUE if buffer contains a UUID
    264  *
    265  * DESCRIPTION: Determine if a buffer Op contains a UUID
    266  *
    267  * To help determine whether the buffer is a UUID versus a raw data buffer,
    268  * there a are a couple bytes we can look at:
    269  *
    270  *    xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
    271  *
    272  * The variant covered by the UUID specification is indicated by the two most
    273  * significant bits of N being 1 0 (i.e., the hexadecimal N will always be
    274  * 8, 9, A, or B).
    275  *
    276  * The variant covered by the UUID specification has five versions. For this
    277  * variant, the four bits of M indicates the UUID version (i.e., the
    278  * hexadecimal M will be either 1, 2, 3, 4, or 5).
    279  *
    280  ******************************************************************************/
    281 
    282 BOOLEAN
    283 AcpiDmIsUuidBuffer (
    284     ACPI_PARSE_OBJECT       *Op)
    285 {
    286     UINT8                   *ByteData;
    287     UINT32                  ByteCount;
    288     ACPI_PARSE_OBJECT       *SizeOp;
    289     ACPI_PARSE_OBJECT       *NextOp;
    290 
    291 
    292     /* Buffer size is the buffer argument */
    293 
    294     SizeOp = Op->Common.Value.Arg;
    295     if (!SizeOp)
    296     {
    297         return (FALSE);
    298     }
    299 
    300     /* Next, the initializer byte list to examine */
    301 
    302     NextOp = SizeOp->Common.Next;
    303     if (!NextOp)
    304     {
    305         return (FALSE);
    306     }
    307 
    308     /* Extract the byte list info */
    309 
    310     ByteData = NextOp->Named.Data;
    311     ByteCount = (UINT32) NextOp->Common.Value.Integer;
    312 
    313     /* Byte count must be exactly 16 */
    314 
    315     if (ByteCount != UUID_BUFFER_LENGTH)
    316     {
    317         return (FALSE);
    318     }
    319 
    320     /* Check for valid "M" and "N" values (see function header above) */
    321 
    322     if (((ByteData[7] & 0xF0) == 0x00) || /* M={1,2,3,4,5} */
    323         ((ByteData[7] & 0xF0) > 0x50)  ||
    324         ((ByteData[8] & 0xF0) < 0x80)  || /* N={8,9,A,B} */
    325         ((ByteData[8] & 0xF0) > 0xB0))
    326     {
    327         return (FALSE);
    328     }
    329 
    330     /* Ignore the Size argument in the disassembly of this buffer op */
    331 
    332     SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
    333     return (TRUE);
    334 }
    335 
    336 
    337 /*******************************************************************************
    338  *
    339  * FUNCTION:    AcpiDmUuid
    340  *
    341  * PARAMETERS:  Op              - Byte List op containing a UUID
    342  *
    343  * RETURN:      None
    344  *
    345  * DESCRIPTION: Dump a buffer containing a UUID as a standard ASCII string.
    346  *
    347  * Output Format:
    348  * In its canonical form, the UUID is represented by a string containing 32
    349  * lowercase hexadecimal digits, displayed in 5 groups separated by hyphens.
    350  * The complete form is 8-4-4-4-12 for a total of 36 characters (32
    351  * alphanumeric characters representing hex digits and 4 hyphens). In bytes,
    352  * 4-2-2-2-6. Example:
    353  *
    354  *    ToUUID ("107ededd-d381-4fd7-8da9-08e9a6c79644")
    355  *
    356  ******************************************************************************/
    357 
    358 static void
    359 AcpiDmUuid (
    360     ACPI_PARSE_OBJECT       *Op)
    361 {
    362     UINT8                   *Data;
    363     const char              *Description;
    364 
    365 
    366     Data = ACPI_CAST_PTR (UINT8, Op->Named.Data);
    367 
    368     /* Emit the 36-byte UUID string in the proper format/order */
    369 
    370     AcpiOsPrintf (
    371         "\"%2.2x%2.2x%2.2x%2.2x-"
    372         "%2.2x%2.2x-"
    373         "%2.2x%2.2x-"
    374         "%2.2x%2.2x-"
    375         "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\")",
    376         Data[3], Data[2], Data[1], Data[0],
    377         Data[5], Data[4],
    378         Data[7], Data[6],
    379         Data[8], Data[9],
    380         Data[10], Data[11], Data[12], Data[13], Data[14], Data[15]);
    381 
    382     /* Dump the UUID description string if available */
    383 
    384     Description = AcpiAhMatchUuid (Data);
    385     if (Description)
    386     {
    387         AcpiOsPrintf (" /* %s */", Description);
    388     }
    389 }
    390 
    391 
    392 /*******************************************************************************
    393  *
    394  * FUNCTION:    AcpiDmIsUnicodeBuffer
    395  *
    396  * PARAMETERS:  Op              - Buffer Object to be examined
    397  *
    398  * RETURN:      TRUE if buffer contains a UNICODE string
    399  *
    400  * DESCRIPTION: Determine if a buffer Op contains a Unicode string
    401  *
    402  ******************************************************************************/
    403 
    404 BOOLEAN
    405 AcpiDmIsUnicodeBuffer (
    406     ACPI_PARSE_OBJECT       *Op)
    407 {
    408     UINT8                   *ByteData;
    409     UINT32                  ByteCount;
    410     UINT32                  WordCount;
    411     ACPI_PARSE_OBJECT       *SizeOp;
    412     ACPI_PARSE_OBJECT       *NextOp;
    413     UINT32                  i;
    414 
    415 
    416     /* Buffer size is the buffer argument */
    417 
    418     SizeOp = Op->Common.Value.Arg;
    419     if (!SizeOp)
    420     {
    421         return (FALSE);
    422     }
    423 
    424     /* Next, the initializer byte list to examine */
    425 
    426     NextOp = SizeOp->Common.Next;
    427     if (!NextOp)
    428     {
    429         return (FALSE);
    430     }
    431 
    432     /* Extract the byte list info */
    433 
    434     ByteData = NextOp->Named.Data;
    435     ByteCount = (UINT32) NextOp->Common.Value.Integer;
    436     WordCount = ACPI_DIV_2 (ByteCount);
    437 
    438     /*
    439      * Unicode string must have an even number of bytes and last
    440      * word must be zero
    441      */
    442     if ((!ByteCount)     ||
    443          (ByteCount < 4) ||
    444          (ByteCount & 1) ||
    445         ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
    446     {
    447         return (FALSE);
    448     }
    449 
    450     /*
    451      * For each word, 1st byte must be printable ascii, and the
    452      * 2nd byte must be zero. This does not allow for escape
    453      * sequences, but it is the most secure way to detect a
    454      * unicode string.
    455      */
    456     for (i = 0; i < (ByteCount - 2); i += 2)
    457     {
    458         if ((ByteData[i] == 0) ||
    459             !(isprint (ByteData[i])) ||
    460             (ByteData[(ACPI_SIZE) i + 1] != 0))
    461         {
    462             return (FALSE);
    463         }
    464     }
    465 
    466     /* Ignore the Size argument in the disassembly of this buffer op */
    467 
    468     SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
    469     return (TRUE);
    470 }
    471 
    472 
    473 /*******************************************************************************
    474  *
    475  * FUNCTION:    AcpiDmIsStringBuffer
    476  *
    477  * PARAMETERS:  Op              - Buffer Object to be examined
    478  *
    479  * RETURN:      TRUE if buffer contains a ASCII string, FALSE otherwise
    480  *
    481  * DESCRIPTION: Determine if a buffer Op contains a ASCII string
    482  *
    483  ******************************************************************************/
    484 
    485 BOOLEAN
    486 AcpiDmIsStringBuffer (
    487     ACPI_PARSE_OBJECT       *Op)
    488 {
    489     UINT8                   *ByteData;
    490     UINT32                  ByteCount;
    491     ACPI_PARSE_OBJECT       *SizeOp;
    492     ACPI_PARSE_OBJECT       *NextOp;
    493     UINT32                  i;
    494 
    495 
    496     /* Buffer size is the buffer argument */
    497 
    498     SizeOp = Op->Common.Value.Arg;
    499     if (!SizeOp)
    500     {
    501         return (FALSE);
    502     }
    503 
    504     /* Next, the initializer byte list to examine */
    505 
    506     NextOp = SizeOp->Common.Next;
    507     if (!NextOp)
    508     {
    509         return (FALSE);
    510     }
    511 
    512     /* Extract the byte list info */
    513 
    514     ByteData = NextOp->Named.Data;
    515     ByteCount = (UINT32) NextOp->Common.Value.Integer;
    516 
    517     /* Last byte must be the null terminator */
    518 
    519     if ((!ByteCount)     ||
    520          (ByteCount < 2) ||
    521          (ByteData[ByteCount-1] != 0))
    522     {
    523         return (FALSE);
    524     }
    525 
    526     /*
    527      * Check for a possible standalone resource EndTag, ignore it
    528      * here. However, this sequence is also the string "Y", but
    529      * this seems rare enough to be acceptable.
    530      */
    531     if ((ByteCount == 2) && (ByteData[0] == 0x79))
    532     {
    533         return (FALSE);
    534     }
    535 
    536     /* Check all bytes for ASCII */
    537 
    538     for (i = 0; i < (ByteCount - 1); i++)
    539     {
    540         /*
    541          * TBD: allow some escapes (non-ascii chars).
    542          * they will be handled in the string output routine
    543          */
    544 
    545         /* Not a string if not printable ascii */
    546 
    547         if (!isprint (ByteData[i]))
    548         {
    549             return (FALSE);
    550         }
    551     }
    552 
    553     return (TRUE);
    554 }
    555 
    556 
    557 /*******************************************************************************
    558  *
    559  * FUNCTION:    AcpiDmIsPldBuffer
    560  *
    561  * PARAMETERS:  Op                  - Buffer Object to be examined
    562  *
    563  * RETURN:      TRUE if buffer appears to contain data produced via the
    564  *              ToPLD macro, FALSE otherwise
    565  *
    566  * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
    567  *
    568  ******************************************************************************/
    569 
    570 BOOLEAN
    571 AcpiDmIsPldBuffer (
    572     ACPI_PARSE_OBJECT       *Op)
    573 {
    574     ACPI_NAMESPACE_NODE     *Node;
    575     ACPI_PARSE_OBJECT       *SizeOp;
    576     ACPI_PARSE_OBJECT       *ByteListOp;
    577     ACPI_PARSE_OBJECT       *ParentOp;
    578     UINT64                  BufferSize;
    579     UINT64                  InitializerSize;
    580 
    581 
    582     if (!Op)
    583     {
    584         return (FALSE);
    585     }
    586 
    587     /*
    588      * Get the BufferSize argument - Buffer(BufferSize)
    589      * If the buffer was generated by the ToPld macro, it must
    590      * be a BYTE constant.
    591      */
    592     SizeOp = Op->Common.Value.Arg;
    593     if (!SizeOp || SizeOp->Common.AmlOpcode != AML_BYTE_OP)
    594     {
    595         return (FALSE);
    596     }
    597 
    598     /* Check the declared BufferSize, two possibilities */
    599 
    600     BufferSize = SizeOp->Common.Value.Integer;
    601     if ((BufferSize != ACPI_PLD_REV1_BUFFER_SIZE) &&
    602         (BufferSize != ACPI_PLD_REV2_BUFFER_SIZE))
    603     {
    604         return (FALSE);
    605     }
    606 
    607     /*
    608      * Check the initializer list length. This is the actual
    609      * number of bytes in the buffer as counted by the AML parser.
    610      * The declared BufferSize can be larger than the actual length.
    611      * However, for the ToPLD macro, the BufferSize will be the same
    612      * as the initializer list length.
    613      */
    614     ByteListOp = SizeOp->Common.Next;
    615     if (!ByteListOp)
    616     {
    617         return (FALSE); /* Zero-length buffer case */
    618     }
    619 
    620     InitializerSize = ByteListOp->Common.Value.Integer;
    621     if ((InitializerSize != ACPI_PLD_REV1_BUFFER_SIZE) &&
    622         (InitializerSize != ACPI_PLD_REV2_BUFFER_SIZE))
    623     {
    624         return (FALSE);
    625     }
    626 
    627     /* Final size check */
    628 
    629     if (BufferSize != InitializerSize)
    630     {
    631         return (FALSE);
    632     }
    633 
    634     /* Now examine the buffer parent */
    635 
    636     ParentOp = Op->Common.Parent;
    637     if (!ParentOp)
    638     {
    639         return (FALSE);
    640     }
    641 
    642     /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
    643 
    644     if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
    645     {
    646         Node = ParentOp->Common.Node;
    647 
    648         if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, METHOD_NAME__PLD))
    649         {
    650             /* Ignore the Size argument in the disassembly of this buffer op */
    651 
    652             SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
    653             return (TRUE);
    654         }
    655 
    656         return (FALSE);
    657     }
    658 
    659     /*
    660      * Check for proper form: Name(_PLD, Package() {ToPLD()})
    661      *
    662      * Note: All other forms such as
    663      *      Return (Package() {ToPLD()})
    664      *      Local0 = ToPLD()
    665      * etc. are not converted back to the ToPLD macro, because
    666      * there is really no deterministic way to disassemble the buffer
    667      * back to the ToPLD macro, other than trying to find the "_PLD"
    668      * name
    669      */
    670     if (ParentOp->Common.AmlOpcode == AML_PACKAGE_OP)
    671     {
    672         ParentOp = ParentOp->Common.Parent;
    673         if (!ParentOp)
    674         {
    675             return (FALSE);
    676         }
    677 
    678         if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
    679         {
    680             Node = ParentOp->Common.Node;
    681 
    682             if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, METHOD_NAME__PLD))
    683             {
    684                 /* Ignore the Size argument in the disassembly of this buffer op */
    685 
    686                 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
    687                 return (TRUE);
    688             }
    689         }
    690     }
    691 
    692     return (FALSE);
    693 }
    694 
    695 
    696 /*******************************************************************************
    697  *
    698  * FUNCTION:    AcpiDmFindNameByIndex
    699  *
    700  * PARAMETERS:  Index               - Index of array to check
    701  *              List                - Array to reference
    702  *
    703  * RETURN:      String from List or empty string
    704  *
    705  * DESCRIPTION: Finds and returns the char string located at the given index
    706  *              position in List.
    707  *
    708  ******************************************************************************/
    709 
    710 static const char *
    711 AcpiDmFindNameByIndex (
    712     UINT64                  Index,
    713     const char              **List)
    714 {
    715     const char              *NameString;
    716     UINT32                  i;
    717 
    718 
    719     /* Bounds check */
    720 
    721     NameString = List[0];
    722     i = 0;
    723 
    724     while (NameString)
    725     {
    726         i++;
    727         NameString = List[i];
    728     }
    729 
    730     if (Index >= i)
    731     {
    732         /* TBD: Add error msg */
    733 
    734         return ("");
    735     }
    736 
    737     return (List[Index]);
    738 }
    739 
    740 
    741 /*******************************************************************************
    742  *
    743  * FUNCTION:    AcpiDmPldBuffer
    744  *
    745  * PARAMETERS:  Level               - Current source code indentation level
    746  *              ByteData            - Pointer to the byte list
    747  *              ByteCount           - Length of the byte list
    748  *
    749  * RETURN:      None
    750  *
    751  * DESCRIPTION: Dump and format the contents of a _PLD buffer object
    752  *
    753  ******************************************************************************/
    754 
    755 #define ACPI_PLD_OUTPUT08   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
    756 #define ACPI_PLD_OUTPUT08P  "%*.s%-22s = 0x%X)\n", ACPI_MUL_4 (Level), " "
    757 #define ACPI_PLD_OUTPUT16   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
    758 #define ACPI_PLD_OUTPUT16P  "%*.s%-22s = 0x%X)\n", ACPI_MUL_4 (Level), " "
    759 #define ACPI_PLD_OUTPUT24   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
    760 #define ACPI_PLD_OUTPUTSTR  "%*.s%-22s = \"%s\",\n", ACPI_MUL_4 (Level), " "
    761 
    762 static void
    763 AcpiDmPldBuffer (
    764     UINT32                  Level,
    765     UINT8                   *ByteData,
    766     UINT32                  ByteCount)
    767 {
    768     ACPI_PLD_INFO           *PldInfo;
    769     ACPI_STATUS             Status;
    770 
    771 
    772     /* Check for valid byte count */
    773 
    774     if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
    775     {
    776         return;
    777     }
    778 
    779     /* Convert _PLD buffer to local _PLD struct */
    780 
    781     Status = AcpiDecodePldBuffer (ByteData, ByteCount, &PldInfo);
    782     if (ACPI_FAILURE (Status))
    783     {
    784         return;
    785     }
    786 
    787     AcpiOsPrintf ("\n");
    788 
    789     /* First 32-bit dword */
    790 
    791     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Revision", PldInfo->Revision);
    792     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_IgnoreColor", PldInfo->IgnoreColor);
    793     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Red", PldInfo->Red);
    794     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Green", PldInfo->Green);
    795     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Blue", PldInfo->Blue);
    796 
    797     /* Second 32-bit dword */
    798 
    799     AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_Width", PldInfo->Width);
    800     AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_Height", PldInfo->Height);
    801 
    802     /* Third 32-bit dword */
    803 
    804     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_UserVisible", PldInfo->UserVisible);
    805     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Dock", PldInfo->Dock);
    806     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Lid", PldInfo->Lid);
    807     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Panel",
    808         AcpiDmFindNameByIndex(PldInfo->Panel, AcpiGbl_PldPanelList));
    809 
    810     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_VerticalPosition",
    811         AcpiDmFindNameByIndex(PldInfo->VerticalPosition, AcpiGbl_PldVerticalPositionList));
    812 
    813     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_HorizontalPosition",
    814         AcpiDmFindNameByIndex(PldInfo->HorizontalPosition, AcpiGbl_PldHorizontalPositionList));
    815 
    816     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Shape",
    817         AcpiDmFindNameByIndex(PldInfo->Shape, AcpiGbl_PldShapeList));
    818     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupOrientation", PldInfo->GroupOrientation);
    819 
    820     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupToken", PldInfo->GroupToken);
    821     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupPosition", PldInfo->GroupPosition);
    822     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Bay", PldInfo->Bay);
    823 
    824     /* Fourth 32-bit dword */
    825 
    826     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Ejectable", PldInfo->Ejectable);
    827     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_EjectRequired", PldInfo->OspmEjectRequired);
    828     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_CabinetNumber", PldInfo->CabinetNumber);
    829     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_CardCageNumber", PldInfo->CardCageNumber);
    830     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Reference", PldInfo->Reference);
    831     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Rotation", PldInfo->Rotation);
    832 
    833     if (ByteCount >= ACPI_PLD_REV2_BUFFER_SIZE)
    834     {
    835         AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Order", PldInfo->Order);
    836 
    837         /* Fifth 32-bit dword */
    838 
    839         AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_VerticalOffset", PldInfo->VerticalOffset);
    840         AcpiOsPrintf (ACPI_PLD_OUTPUT16P, "PLD_HorizontalOffset", PldInfo->HorizontalOffset);
    841     }
    842     else /* Rev 1 buffer */
    843     {
    844         AcpiOsPrintf (ACPI_PLD_OUTPUT08P, "PLD_Order", PldInfo->Order);
    845     }
    846 
    847     ACPI_FREE (PldInfo);
    848 }
    849 
    850 
    851 /*******************************************************************************
    852  *
    853  * FUNCTION:    AcpiDmUnicode
    854  *
    855  * PARAMETERS:  Op              - Byte List op containing Unicode string
    856  *
    857  * RETURN:      None
    858  *
    859  * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
    860  *              the extra zero bytes).
    861  *
    862  ******************************************************************************/
    863 
    864 static void
    865 AcpiDmUnicode (
    866     ACPI_PARSE_OBJECT       *Op)
    867 {
    868     UINT16                  *WordData;
    869     UINT32                  WordCount;
    870     UINT32                  i;
    871     int                     OutputValue;
    872 
    873 
    874     /* Extract the buffer info as a WORD buffer */
    875 
    876     WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
    877     WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
    878 
    879     /* Write every other byte as an ASCII character */
    880 
    881     AcpiOsPrintf ("\"");
    882     for (i = 0; i < (WordCount - 1); i++)
    883     {
    884         OutputValue = (int) WordData[i];
    885 
    886         /* Handle values that must be escaped */
    887 
    888         if ((OutputValue == '\"') ||
    889             (OutputValue == '\\'))
    890         {
    891             AcpiOsPrintf ("\\%c", OutputValue);
    892         }
    893         else if (!isprint (OutputValue))
    894         {
    895             AcpiOsPrintf ("\\x%2.2X", OutputValue);
    896         }
    897         else
    898         {
    899             AcpiOsPrintf ("%c", OutputValue);
    900         }
    901     }
    902 
    903     AcpiOsPrintf ("\")");
    904 }
    905 
    906 
    907 /*******************************************************************************
    908  *
    909  * FUNCTION:    AcpiDmGetHardwareIdType
    910  *
    911  * PARAMETERS:  Op              - Op to be examined
    912  *
    913  * RETURN:      None
    914  *
    915  * DESCRIPTION: Determine the type of the argument to a _HID or _CID
    916  *              1) Strings are allowed
    917  *              2) If Integer, determine if it is a valid EISAID
    918  *
    919  ******************************************************************************/
    920 
    921 static void
    922 AcpiDmGetHardwareIdType (
    923     ACPI_PARSE_OBJECT       *Op)
    924 {
    925     UINT32                  BigEndianId;
    926     UINT32                  Prefix[3];
    927     UINT32                  i;
    928 
    929 
    930     switch (Op->Common.AmlOpcode)
    931     {
    932     case AML_STRING_OP:
    933 
    934         /* Mark this string as an _HID/_CID string */
    935 
    936         Op->Common.DisasmOpcode = ACPI_DASM_HID_STRING;
    937         break;
    938 
    939     case AML_WORD_OP:
    940     case AML_DWORD_OP:
    941 
    942         /* Determine if a Word/Dword is a valid encoded EISAID */
    943 
    944         /* Swap from little-endian to big-endian to simplify conversion */
    945 
    946         BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
    947 
    948         /* Create the 3 leading ASCII letters */
    949 
    950         Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
    951         Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
    952         Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
    953 
    954         /* Verify that all 3 are ascii and alpha */
    955 
    956         for (i = 0; i < 3; i++)
    957         {
    958             if (!ACPI_IS_ASCII (Prefix[i]) ||
    959                 !isalpha (Prefix[i]))
    960             {
    961                 return;
    962             }
    963         }
    964 
    965         /* Mark this node as convertible to an EISA ID string */
    966 
    967         Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
    968         break;
    969 
    970     default:
    971         break;
    972     }
    973 }
    974 
    975 
    976 /*******************************************************************************
    977  *
    978  * FUNCTION:    AcpiDmCheckForHardwareId
    979  *
    980  * PARAMETERS:  Op              - Op to be examined
    981  *
    982  * RETURN:      None
    983  *
    984  * DESCRIPTION: Determine if a Name() Op is a _HID/_CID.
    985  *
    986  ******************************************************************************/
    987 
    988 void
    989 AcpiDmCheckForHardwareId (
    990     ACPI_PARSE_OBJECT       *Op)
    991 {
    992     UINT32                  Name;
    993     ACPI_PARSE_OBJECT       *NextOp;
    994 
    995 
    996     /* Get the NameSegment */
    997 
    998     Name = AcpiPsGetName (Op);
    999     if (!Name)
   1000     {
   1001         return;
   1002     }
   1003 
   1004     NextOp = AcpiPsGetDepthNext (NULL, Op);
   1005     if (!NextOp)
   1006     {
   1007         return;
   1008     }
   1009 
   1010     /* Check for _HID - has one argument */
   1011 
   1012     if (ACPI_COMPARE_NAMESEG (&Name, METHOD_NAME__HID))
   1013     {
   1014         AcpiDmGetHardwareIdType (NextOp);
   1015         return;
   1016     }
   1017 
   1018     /* Exit if not _CID */
   1019 
   1020     if (!ACPI_COMPARE_NAMESEG (&Name, METHOD_NAME__CID))
   1021     {
   1022         return;
   1023     }
   1024 
   1025     /* _CID can contain a single argument or a package */
   1026 
   1027     if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
   1028     {
   1029         AcpiDmGetHardwareIdType (NextOp);
   1030         return;
   1031     }
   1032 
   1033     /* _CID with Package: get the package length, check all elements */
   1034 
   1035     NextOp = AcpiPsGetDepthNext (NULL, NextOp);
   1036     if (!NextOp)
   1037     {
   1038         return;
   1039     }
   1040 
   1041     /* Don't need to use the length, just walk the peer list */
   1042 
   1043     NextOp = NextOp->Common.Next;
   1044     while (NextOp)
   1045     {
   1046         AcpiDmGetHardwareIdType (NextOp);
   1047         NextOp = NextOp->Common.Next;
   1048     }
   1049 }
   1050 
   1051 
   1052 /*******************************************************************************
   1053  *
   1054  * FUNCTION:    AcpiDmDecompressEisaId
   1055  *
   1056  * PARAMETERS:  EncodedId       - Raw encoded EISA ID.
   1057  *
   1058  * RETURN:      None
   1059  *
   1060  * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String
   1061  *              and emit the correct ASL statement. If the ID is known, emit
   1062  *              a description of the ID as a comment.
   1063  *
   1064  ******************************************************************************/
   1065 
   1066 void
   1067 AcpiDmDecompressEisaId (
   1068     UINT32                  EncodedId)
   1069 {
   1070     char                    IdBuffer[ACPI_EISAID_STRING_SIZE];
   1071     const AH_DEVICE_ID      *Info;
   1072 
   1073 
   1074     /* Convert EISAID to a string an emit the statement */
   1075 
   1076     AcpiExEisaIdToString (IdBuffer, EncodedId);
   1077     AcpiOsPrintf ("EisaId (\"%s\")", IdBuffer);
   1078 
   1079     /* If we know about the ID, emit the description */
   1080 
   1081     Info = AcpiAhMatchHardwareId (IdBuffer);
   1082     if (Info)
   1083     {
   1084         AcpiOsPrintf (" /* %s */", Info->Description);
   1085     }
   1086 }
   1087