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