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