Home | History | Annotate | Line # | Download | only in compiler
aslopcodes.c revision 1.1.1.19
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: aslopcode - AML opcode generation
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7  1.1.1.19  christos /******************************************************************************
      8  1.1.1.19  christos  *
      9  1.1.1.19  christos  * 1. Copyright Notice
     10  1.1.1.19  christos  *
     11  1.1.1.19  christos  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
     12       1.1    jruoho  * All rights reserved.
     13       1.1    jruoho  *
     14  1.1.1.19  christos  * 2. License
     15  1.1.1.19  christos  *
     16  1.1.1.19  christos  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1.1.19  christos  * rights. You may have additional license terms from the party that provided
     18  1.1.1.19  christos  * you this software, covering your right to use that party's intellectual
     19  1.1.1.19  christos  * property rights.
     20  1.1.1.19  christos  *
     21  1.1.1.19  christos  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1.1.19  christos  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1.1.19  christos  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1.1.19  christos  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1.1.19  christos  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1.1.19  christos  * Code in any form, with the right to sublicense such rights; and
     27  1.1.1.19  christos  *
     28  1.1.1.19  christos  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1.1.19  christos  * license (with the right to sublicense), under only those claims of Intel
     30  1.1.1.19  christos  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1.1.19  christos  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1.1.19  christos  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1.1.19  christos  * license, and in no event shall the patent license extend to any additions
     34  1.1.1.19  christos  * to or modifications of the Original Intel Code. No other license or right
     35  1.1.1.19  christos  * is granted directly or by implication, estoppel or otherwise;
     36  1.1.1.19  christos  *
     37  1.1.1.19  christos  * The above copyright and patent license is granted only if the following
     38  1.1.1.19  christos  * conditions are met:
     39  1.1.1.19  christos  *
     40  1.1.1.19  christos  * 3. Conditions
     41  1.1.1.19  christos  *
     42  1.1.1.19  christos  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1.1.19  christos  * Redistribution of source code of any substantial portion of the Covered
     44  1.1.1.19  christos  * Code or modification with rights to further distribute source must include
     45  1.1.1.19  christos  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1.1.19  christos  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.1.1.19  christos  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1.1.19  christos  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1.1.19  christos  * Code and the date of any change. Licensee must include in that file the
     50  1.1.1.19  christos  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.1.1.19  christos  * must include a prominent statement that the modification is derived,
     52  1.1.1.19  christos  * directly or indirectly, from Original Intel Code.
     53  1.1.1.19  christos  *
     54  1.1.1.19  christos  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1.1.19  christos  * Redistribution of source code of any substantial portion of the Covered
     56  1.1.1.19  christos  * Code or modification without rights to further distribute source must
     57  1.1.1.19  christos  * include the following Disclaimer and Export Compliance provision in the
     58  1.1.1.19  christos  * documentation and/or other materials provided with distribution. In
     59  1.1.1.19  christos  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1.1.19  christos  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1.1.19  christos  * license from Licensee to its licensee is limited to the intellectual
     62  1.1.1.19  christos  * property embodied in the software Licensee provides to its licensee, and
     63  1.1.1.19  christos  * not to intellectual property embodied in modifications its licensee may
     64  1.1.1.19  christos  * make.
     65  1.1.1.19  christos  *
     66  1.1.1.19  christos  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1.1.19  christos  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1.1.19  christos  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1.1.19  christos  * provision in the documentation and/or other materials provided with the
     70  1.1.1.19  christos  * distribution.
     71  1.1.1.19  christos  *
     72  1.1.1.19  christos  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1.1.19  christos  * Intel Code.
     74  1.1.1.19  christos  *
     75  1.1.1.19  christos  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1.1.19  christos  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1.1.19  christos  * other dealings in products derived from or relating to the Covered Code
     78  1.1.1.19  christos  * without prior written authorization from Intel.
     79  1.1.1.19  christos  *
     80  1.1.1.19  christos  * 4. Disclaimer and Export Compliance
     81  1.1.1.19  christos  *
     82  1.1.1.19  christos  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1.1.19  christos  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1.1.19  christos  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.1.1.19  christos  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.1.1.19  christos  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1.1.19  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1.1.19  christos  * PARTICULAR PURPOSE.
     89  1.1.1.19  christos  *
     90  1.1.1.19  christos  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1.1.19  christos  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1.1.19  christos  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1.1.19  christos  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1.1.19  christos  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1.1.19  christos  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.1.1.19  christos  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1.1.19  christos  * LIMITED REMEDY.
     98  1.1.1.19  christos  *
     99  1.1.1.19  christos  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1.1.19  christos  * software or system incorporating such software without first obtaining any
    101  1.1.1.19  christos  * required license or other approval from the U. S. Department of Commerce or
    102  1.1.1.19  christos  * any other agency or department of the United States Government. In the
    103  1.1.1.19  christos  * event Licensee exports any such software from the United States or
    104  1.1.1.19  christos  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1.1.19  christos  * ensure that the distribution and export/re-export of the software is in
    106  1.1.1.19  christos  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1.1.19  christos  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1.1.19  christos  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1.1.19  christos  * software, or service, directly or indirectly, to any country for which the
    110  1.1.1.19  christos  * United States government or any agency thereof requires an export license,
    111  1.1.1.19  christos  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1.1.19  christos  * such license, approval or letter.
    113  1.1.1.19  christos  *
    114  1.1.1.19  christos  *****************************************************************************
    115  1.1.1.19  christos  *
    116  1.1.1.19  christos  * Alternatively, you may choose to be licensed under the terms of the
    117  1.1.1.19  christos  * following license:
    118  1.1.1.19  christos  *
    119   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
    120   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
    121   1.1.1.2    jruoho  * are met:
    122   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
    123   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
    124   1.1.1.2    jruoho  *    without modification.
    125   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
    127   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
    128   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
    129   1.1.1.2    jruoho  *    binary redistribution.
    130   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
    131   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
    132   1.1.1.2    jruoho  *    from this software without specific prior written permission.
    133   1.1.1.2    jruoho  *
    134   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136  1.1.1.16  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.1.1.19  christos  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.1.1.19  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.1.1.19  christos  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.1.1.19  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.1.1.19  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.1.1.19  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.1.1.19  christos  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.1.1.19  christos  *
    146  1.1.1.19  christos  * Alternatively, you may choose to be licensed under the terms of the
    147  1.1.1.19  christos  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.1.1.19  christos  * Software Foundation.
    149  1.1.1.19  christos  *
    150  1.1.1.19  christos  *****************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho #include "aslcompiler.h"
    153       1.1    jruoho #include "aslcompiler.y.h"
    154       1.1    jruoho #include "amlcode.h"
    155       1.1    jruoho 
    156       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
    157       1.1    jruoho         ACPI_MODULE_NAME    ("aslopcodes")
    158       1.1    jruoho 
    159       1.1    jruoho 
    160       1.1    jruoho /* Local prototypes */
    161       1.1    jruoho 
    162       1.1    jruoho static void
    163       1.1    jruoho OpcDoAccessAs (
    164       1.1    jruoho     ACPI_PARSE_OBJECT       *Op);
    165       1.1    jruoho 
    166       1.1    jruoho static void
    167   1.1.1.3  christos OpcDoConnection (
    168   1.1.1.3  christos     ACPI_PARSE_OBJECT       *Op);
    169   1.1.1.3  christos 
    170   1.1.1.3  christos static void
    171       1.1    jruoho OpcDoUnicode (
    172       1.1    jruoho     ACPI_PARSE_OBJECT       *Op);
    173       1.1    jruoho 
    174       1.1    jruoho static void
    175       1.1    jruoho OpcDoEisaId (
    176       1.1    jruoho     ACPI_PARSE_OBJECT       *Op);
    177       1.1    jruoho 
    178       1.1    jruoho static void
    179       1.1    jruoho OpcDoUuId (
    180       1.1    jruoho     ACPI_PARSE_OBJECT       *Op);
    181       1.1    jruoho 
    182       1.1    jruoho 
    183       1.1    jruoho /*******************************************************************************
    184       1.1    jruoho  *
    185       1.1    jruoho  * FUNCTION:    OpcAmlOpcodeUpdateWalk
    186       1.1    jruoho  *
    187       1.1    jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
    188       1.1    jruoho  *
    189       1.1    jruoho  * RETURN:      Status
    190       1.1    jruoho  *
    191       1.1    jruoho  * DESCRIPTION: Opcode update walk, ascending callback
    192       1.1    jruoho  *
    193       1.1    jruoho  ******************************************************************************/
    194       1.1    jruoho 
    195       1.1    jruoho ACPI_STATUS
    196       1.1    jruoho OpcAmlOpcodeUpdateWalk (
    197       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    198       1.1    jruoho     UINT32                  Level,
    199       1.1    jruoho     void                    *Context)
    200       1.1    jruoho {
    201       1.1    jruoho 
    202       1.1    jruoho     /*
    203       1.1    jruoho      * Handle the Package() case where the actual opcode cannot be determined
    204       1.1    jruoho      * until the PackageLength operand has been folded and minimized.
    205       1.1    jruoho      * (PackageOp versus VarPackageOp)
    206       1.1    jruoho      *
    207       1.1    jruoho      * This is (as of ACPI 3.0) the only case where the AML opcode can change
    208       1.1    jruoho      * based upon the value of a parameter.
    209       1.1    jruoho      *
    210       1.1    jruoho      * The parser always inserts a VarPackage opcode, which can possibly be
    211       1.1    jruoho      * optimized to a Package opcode.
    212       1.1    jruoho      */
    213       1.1    jruoho     if (Op->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)
    214       1.1    jruoho     {
    215       1.1    jruoho         OpnDoPackage (Op);
    216       1.1    jruoho     }
    217       1.1    jruoho 
    218       1.1    jruoho     return (AE_OK);
    219       1.1    jruoho }
    220       1.1    jruoho 
    221       1.1    jruoho 
    222       1.1    jruoho /*******************************************************************************
    223       1.1    jruoho  *
    224       1.1    jruoho  * FUNCTION:    OpcAmlOpcodeWalk
    225       1.1    jruoho  *
    226       1.1    jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
    227       1.1    jruoho  *
    228       1.1    jruoho  * RETURN:      Status
    229       1.1    jruoho  *
    230       1.1    jruoho  * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
    231       1.1    jruoho  *              operands.
    232       1.1    jruoho  *
    233       1.1    jruoho  ******************************************************************************/
    234       1.1    jruoho 
    235       1.1    jruoho ACPI_STATUS
    236       1.1    jruoho OpcAmlOpcodeWalk (
    237       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    238       1.1    jruoho     UINT32                  Level,
    239       1.1    jruoho     void                    *Context)
    240       1.1    jruoho {
    241       1.1    jruoho 
    242  1.1.1.12  christos     AslGbl_TotalParseNodes++;
    243       1.1    jruoho 
    244       1.1    jruoho     OpcGenerateAmlOpcode (Op);
    245       1.1    jruoho     OpnGenerateAmlOperands (Op);
    246       1.1    jruoho     return (AE_OK);
    247       1.1    jruoho }
    248       1.1    jruoho 
    249       1.1    jruoho 
    250       1.1    jruoho /*******************************************************************************
    251       1.1    jruoho  *
    252       1.1    jruoho  * FUNCTION:    OpcGetIntegerWidth
    253       1.1    jruoho  *
    254       1.1    jruoho  * PARAMETERS:  Op          - DEFINITION BLOCK op
    255       1.1    jruoho  *
    256       1.1    jruoho  * RETURN:      none
    257       1.1    jruoho  *
    258       1.1    jruoho  * DESCRIPTION: Extract integer width from the table revision
    259       1.1    jruoho  *
    260       1.1    jruoho  ******************************************************************************/
    261       1.1    jruoho 
    262       1.1    jruoho void
    263       1.1    jruoho OpcGetIntegerWidth (
    264       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    265       1.1    jruoho {
    266       1.1    jruoho     ACPI_PARSE_OBJECT       *Child;
    267       1.1    jruoho 
    268       1.1    jruoho 
    269       1.1    jruoho     if (!Op)
    270       1.1    jruoho     {
    271       1.1    jruoho         return;
    272       1.1    jruoho     }
    273       1.1    jruoho 
    274  1.1.1.12  christos     if (AslGbl_RevisionOverride)
    275       1.1    jruoho     {
    276  1.1.1.12  christos         AcpiUtSetIntegerWidth (AslGbl_RevisionOverride);
    277       1.1    jruoho     }
    278       1.1    jruoho     else
    279       1.1    jruoho     {
    280       1.1    jruoho         Child = Op->Asl.Child;
    281       1.1    jruoho         Child = Child->Asl.Next;
    282       1.1    jruoho         Child = Child->Asl.Next;
    283       1.1    jruoho 
    284       1.1    jruoho         /* Use the revision to set the integer width */
    285       1.1    jruoho 
    286       1.1    jruoho         AcpiUtSetIntegerWidth ((UINT8) Child->Asl.Value.Integer);
    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:    OpcSetOptimalIntegerSize
    294       1.1    jruoho  *
    295       1.1    jruoho  * PARAMETERS:  Op        - A parse tree node
    296       1.1    jruoho  *
    297   1.1.1.3  christos  * RETURN:      Integer width, in bytes. Also sets the node AML opcode to the
    298       1.1    jruoho  *              optimal integer AML prefix opcode.
    299       1.1    jruoho  *
    300   1.1.1.3  christos  * DESCRIPTION: Determine the optimal AML encoding of an integer. All leading
    301       1.1    jruoho  *              zeros can be truncated to squeeze the integer into the
    302       1.1    jruoho  *              minimal number of AML bytes.
    303       1.1    jruoho  *
    304       1.1    jruoho  ******************************************************************************/
    305       1.1    jruoho 
    306       1.1    jruoho UINT32
    307       1.1    jruoho OpcSetOptimalIntegerSize (
    308       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    309       1.1    jruoho {
    310       1.1    jruoho 
    311       1.1    jruoho #if 0
    312       1.1    jruoho     /*
    313       1.1    jruoho      * TBD: - we don't want to optimize integers in the block header, but the
    314       1.1    jruoho      * code below does not work correctly.
    315       1.1    jruoho      */
    316       1.1    jruoho     if (Op->Asl.Parent &&
    317       1.1    jruoho         Op->Asl.Parent->Asl.Parent &&
    318   1.1.1.7  christos        (Op->Asl.Parent->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK))
    319       1.1    jruoho     {
    320   1.1.1.3  christos         return (0);
    321       1.1    jruoho     }
    322       1.1    jruoho #endif
    323       1.1    jruoho 
    324       1.1    jruoho     /*
    325       1.1    jruoho      * Check for the special AML integers first - Zero, One, Ones.
    326       1.1    jruoho      * These are single-byte opcodes that are the smallest possible
    327       1.1    jruoho      * representation of an integer.
    328       1.1    jruoho      *
    329       1.1    jruoho      * This optimization is optional.
    330       1.1    jruoho      */
    331  1.1.1.12  christos     if (AslGbl_IntegerOptimizationFlag)
    332       1.1    jruoho     {
    333       1.1    jruoho         switch (Op->Asl.Value.Integer)
    334       1.1    jruoho         {
    335       1.1    jruoho         case 0:
    336       1.1    jruoho 
    337       1.1    jruoho             Op->Asl.AmlOpcode = AML_ZERO_OP;
    338       1.1    jruoho             AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
    339       1.1    jruoho                 Op, "Zero");
    340   1.1.1.3  christos             return (1);
    341       1.1    jruoho 
    342       1.1    jruoho         case 1:
    343       1.1    jruoho 
    344       1.1    jruoho             Op->Asl.AmlOpcode = AML_ONE_OP;
    345       1.1    jruoho             AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
    346       1.1    jruoho                 Op, "One");
    347   1.1.1.3  christos             return (1);
    348       1.1    jruoho 
    349       1.1    jruoho         case ACPI_UINT32_MAX:
    350       1.1    jruoho 
    351       1.1    jruoho             /* Check for table integer width (32 or 64) */
    352       1.1    jruoho 
    353       1.1    jruoho             if (AcpiGbl_IntegerByteWidth == 4)
    354       1.1    jruoho             {
    355       1.1    jruoho                 Op->Asl.AmlOpcode = AML_ONES_OP;
    356       1.1    jruoho                 AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
    357       1.1    jruoho                     Op, "Ones");
    358   1.1.1.3  christos                 return (1);
    359       1.1    jruoho             }
    360       1.1    jruoho             break;
    361       1.1    jruoho 
    362       1.1    jruoho         case ACPI_UINT64_MAX:
    363       1.1    jruoho 
    364       1.1    jruoho             /* Check for table integer width (32 or 64) */
    365       1.1    jruoho 
    366       1.1    jruoho             if (AcpiGbl_IntegerByteWidth == 8)
    367       1.1    jruoho             {
    368       1.1    jruoho                 Op->Asl.AmlOpcode = AML_ONES_OP;
    369       1.1    jruoho                 AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
    370       1.1    jruoho                     Op, "Ones");
    371   1.1.1.3  christos                 return (1);
    372       1.1    jruoho             }
    373       1.1    jruoho             break;
    374       1.1    jruoho 
    375       1.1    jruoho         default:
    376   1.1.1.3  christos 
    377       1.1    jruoho             break;
    378       1.1    jruoho         }
    379       1.1    jruoho     }
    380       1.1    jruoho 
    381       1.1    jruoho     /* Find the best fit using the various AML integer prefixes */
    382       1.1    jruoho 
    383       1.1    jruoho     if (Op->Asl.Value.Integer <= ACPI_UINT8_MAX)
    384       1.1    jruoho     {
    385       1.1    jruoho         Op->Asl.AmlOpcode = AML_BYTE_OP;
    386   1.1.1.3  christos         return (1);
    387       1.1    jruoho     }
    388   1.1.1.7  christos 
    389       1.1    jruoho     if (Op->Asl.Value.Integer <= ACPI_UINT16_MAX)
    390       1.1    jruoho     {
    391       1.1    jruoho         Op->Asl.AmlOpcode = AML_WORD_OP;
    392   1.1.1.3  christos         return (2);
    393       1.1    jruoho     }
    394   1.1.1.7  christos 
    395       1.1    jruoho     if (Op->Asl.Value.Integer <= ACPI_UINT32_MAX)
    396       1.1    jruoho     {
    397       1.1    jruoho         Op->Asl.AmlOpcode = AML_DWORD_OP;
    398   1.1.1.3  christos         return (4);
    399       1.1    jruoho     }
    400   1.1.1.9  christos     else /* 64-bit integer */
    401       1.1    jruoho     {
    402       1.1    jruoho         if (AcpiGbl_IntegerByteWidth == 4)
    403       1.1    jruoho         {
    404       1.1    jruoho             AslError (ASL_WARNING, ASL_MSG_INTEGER_LENGTH,
    405       1.1    jruoho                 Op, NULL);
    406       1.1    jruoho 
    407  1.1.1.12  christos             if (!AslGbl_IgnoreErrors)
    408       1.1    jruoho             {
    409       1.1    jruoho                 /* Truncate the integer to 32-bit */
    410   1.1.1.9  christos 
    411   1.1.1.9  christos                 Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
    412   1.1.1.9  christos 
    413   1.1.1.9  christos                 /* Now set the optimal integer size */
    414   1.1.1.9  christos 
    415   1.1.1.9  christos                 return (OpcSetOptimalIntegerSize (Op));
    416       1.1    jruoho             }
    417       1.1    jruoho         }
    418       1.1    jruoho 
    419       1.1    jruoho         Op->Asl.AmlOpcode = AML_QWORD_OP;
    420   1.1.1.3  christos         return (8);
    421       1.1    jruoho     }
    422       1.1    jruoho }
    423       1.1    jruoho 
    424       1.1    jruoho 
    425       1.1    jruoho /*******************************************************************************
    426       1.1    jruoho  *
    427       1.1    jruoho  * FUNCTION:    OpcDoAccessAs
    428       1.1    jruoho  *
    429       1.1    jruoho  * PARAMETERS:  Op        - Parse node
    430       1.1    jruoho  *
    431       1.1    jruoho  * RETURN:      None
    432       1.1    jruoho  *
    433       1.1    jruoho  * DESCRIPTION: Implement the ACCESS_AS ASL keyword.
    434       1.1    jruoho  *
    435       1.1    jruoho  ******************************************************************************/
    436       1.1    jruoho 
    437       1.1    jruoho static void
    438       1.1    jruoho OpcDoAccessAs (
    439       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    440       1.1    jruoho {
    441   1.1.1.3  christos     ACPI_PARSE_OBJECT       *TypeOp;
    442   1.1.1.3  christos     ACPI_PARSE_OBJECT       *AttribOp;
    443   1.1.1.3  christos     ACPI_PARSE_OBJECT       *LengthOp;
    444   1.1.1.3  christos     UINT8                   Attribute;
    445       1.1    jruoho 
    446       1.1    jruoho 
    447       1.1    jruoho     Op->Asl.AmlOpcodeLength = 1;
    448   1.1.1.3  christos     TypeOp = Op->Asl.Child;
    449       1.1    jruoho 
    450       1.1    jruoho     /* First child is the access type */
    451       1.1    jruoho 
    452   1.1.1.3  christos     TypeOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
    453   1.1.1.3  christos     TypeOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
    454       1.1    jruoho 
    455       1.1    jruoho     /* Second child is the optional access attribute */
    456       1.1    jruoho 
    457   1.1.1.3  christos     AttribOp = TypeOp->Asl.Next;
    458   1.1.1.3  christos     if (AttribOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
    459   1.1.1.3  christos     {
    460   1.1.1.3  christos         AttribOp->Asl.Value.Integer = 0;
    461   1.1.1.3  christos     }
    462   1.1.1.7  christos 
    463   1.1.1.3  christos     AttribOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
    464   1.1.1.3  christos     AttribOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
    465   1.1.1.3  christos 
    466   1.1.1.3  christos     /* Only a few AccessAttributes support AccessLength */
    467   1.1.1.3  christos 
    468   1.1.1.3  christos     Attribute = (UINT8) AttribOp->Asl.Value.Integer;
    469  1.1.1.12  christos     if ((Attribute != AML_FIELD_ATTRIB_BYTES) &&
    470   1.1.1.3  christos         (Attribute != AML_FIELD_ATTRIB_RAW_BYTES) &&
    471  1.1.1.12  christos         (Attribute != AML_FIELD_ATTRIB_RAW_PROCESS_BYTES))
    472   1.1.1.3  christos     {
    473   1.1.1.3  christos         return;
    474   1.1.1.3  christos     }
    475   1.1.1.3  christos 
    476   1.1.1.3  christos     Op->Asl.AmlOpcode = AML_FIELD_EXT_ACCESS_OP;
    477   1.1.1.3  christos 
    478   1.1.1.3  christos     /*
    479   1.1.1.3  christos      * Child of Attributes is the AccessLength (required for Multibyte,
    480   1.1.1.3  christos      * RawBytes, RawProcess.)
    481   1.1.1.3  christos      */
    482   1.1.1.3  christos     LengthOp = AttribOp->Asl.Child;
    483   1.1.1.3  christos     if (!LengthOp)
    484   1.1.1.3  christos     {
    485   1.1.1.3  christos         return;
    486   1.1.1.3  christos     }
    487   1.1.1.3  christos 
    488   1.1.1.3  christos     /* TBD: probably can remove */
    489   1.1.1.3  christos 
    490   1.1.1.3  christos     if (LengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
    491   1.1.1.3  christos     {
    492   1.1.1.3  christos         LengthOp->Asl.Value.Integer = 16;
    493   1.1.1.3  christos     }
    494   1.1.1.3  christos 
    495   1.1.1.3  christos     LengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
    496   1.1.1.3  christos     LengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
    497   1.1.1.3  christos }
    498   1.1.1.3  christos 
    499   1.1.1.3  christos 
    500   1.1.1.3  christos /*******************************************************************************
    501   1.1.1.3  christos  *
    502   1.1.1.3  christos  * FUNCTION:    OpcDoConnection
    503   1.1.1.3  christos  *
    504   1.1.1.3  christos  * PARAMETERS:  Op        - Parse node
    505   1.1.1.3  christos  *
    506   1.1.1.3  christos  * RETURN:      None
    507   1.1.1.3  christos  *
    508   1.1.1.3  christos  * DESCRIPTION: Implement the Connection ASL keyword.
    509   1.1.1.3  christos  *
    510   1.1.1.3  christos  ******************************************************************************/
    511   1.1.1.3  christos 
    512   1.1.1.3  christos static void
    513   1.1.1.3  christos OpcDoConnection (
    514   1.1.1.3  christos     ACPI_PARSE_OBJECT       *Op)
    515   1.1.1.3  christos {
    516   1.1.1.3  christos     ASL_RESOURCE_NODE       *Rnode;
    517   1.1.1.3  christos     ACPI_PARSE_OBJECT       *BufferOp;
    518   1.1.1.3  christos     ACPI_PARSE_OBJECT       *BufferLengthOp;
    519   1.1.1.3  christos     ACPI_PARSE_OBJECT       *BufferDataOp;
    520   1.1.1.4  christos     ASL_RESOURCE_INFO       Info;
    521   1.1.1.3  christos     UINT8                   State;
    522   1.1.1.3  christos 
    523   1.1.1.3  christos 
    524   1.1.1.3  christos     Op->Asl.AmlOpcodeLength = 1;
    525   1.1.1.3  christos 
    526   1.1.1.3  christos     if (Op->Asl.Child->Asl.AmlOpcode == AML_INT_NAMEPATH_OP)
    527   1.1.1.3  christos     {
    528   1.1.1.3  christos         return;
    529   1.1.1.3  christos     }
    530   1.1.1.3  christos 
    531   1.1.1.3  christos     BufferOp = Op->Asl.Child;
    532   1.1.1.3  christos     BufferLengthOp = BufferOp->Asl.Child;
    533   1.1.1.3  christos     BufferDataOp = BufferLengthOp->Asl.Next;
    534   1.1.1.3  christos 
    535   1.1.1.4  christos     Info.DescriptorTypeOp = BufferDataOp->Asl.Next;
    536   1.1.1.4  christos     Info.CurrentByteOffset = 0;
    537   1.1.1.3  christos     State = ACPI_RSTATE_NORMAL;
    538   1.1.1.4  christos     Rnode = RsDoOneResourceDescriptor (&Info, &State);
    539   1.1.1.3  christos     if (!Rnode)
    540       1.1    jruoho     {
    541   1.1.1.3  christos         return; /* error */
    542       1.1    jruoho     }
    543   1.1.1.3  christos 
    544   1.1.1.3  christos     /*
    545   1.1.1.3  christos      * Transform the nodes into the following
    546   1.1.1.3  christos      *
    547   1.1.1.3  christos      * Op           -> AML_BUFFER_OP
    548   1.1.1.3  christos      * First Child  -> BufferLength
    549   1.1.1.3  christos      * Second Child -> Descriptor Buffer (raw byte data)
    550   1.1.1.3  christos      */
    551   1.1.1.7  christos     BufferOp->Asl.ParseOpcode = PARSEOP_BUFFER;
    552   1.1.1.7  christos     BufferOp->Asl.AmlOpcode = AML_BUFFER_OP;
    553  1.1.1.10  christos     BufferOp->Asl.CompileFlags = OP_AML_PACKAGE | OP_IS_RESOURCE_DESC;
    554   1.1.1.3  christos     UtSetParseOpName (BufferOp);
    555   1.1.1.3  christos 
    556   1.1.1.7  christos     BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
    557   1.1.1.3  christos     BufferLengthOp->Asl.Value.Integer = Rnode->BufferLength;
    558   1.1.1.3  christos     (void) OpcSetOptimalIntegerSize (BufferLengthOp);
    559   1.1.1.3  christos     UtSetParseOpName (BufferLengthOp);
    560   1.1.1.3  christos 
    561   1.1.1.7  christos     BufferDataOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
    562   1.1.1.7  christos     BufferDataOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;
    563   1.1.1.7  christos     BufferDataOp->Asl.AmlOpcodeLength = 0;
    564   1.1.1.7  christos     BufferDataOp->Asl.AmlLength = Rnode->BufferLength;
    565   1.1.1.7  christos     BufferDataOp->Asl.Value.Buffer = (UINT8 *) Rnode;
    566   1.1.1.3  christos     UtSetParseOpName (BufferDataOp);
    567       1.1    jruoho }
    568       1.1    jruoho 
    569       1.1    jruoho 
    570       1.1    jruoho /*******************************************************************************
    571       1.1    jruoho  *
    572       1.1    jruoho  * FUNCTION:    OpcDoUnicode
    573       1.1    jruoho  *
    574       1.1    jruoho  * PARAMETERS:  Op        - Parse node
    575       1.1    jruoho  *
    576       1.1    jruoho  * RETURN:      None
    577       1.1    jruoho  *
    578       1.1    jruoho  * DESCRIPTION: Implement the UNICODE ASL "macro".  Convert the input string
    579   1.1.1.3  christos  *              to a unicode buffer. There is no Unicode AML opcode.
    580       1.1    jruoho  *
    581       1.1    jruoho  * Note:  The Unicode string is 16 bits per character, no leading signature,
    582       1.1    jruoho  *        with a 16-bit terminating NULL.
    583       1.1    jruoho  *
    584       1.1    jruoho  ******************************************************************************/
    585       1.1    jruoho 
    586       1.1    jruoho static void
    587       1.1    jruoho OpcDoUnicode (
    588       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    589       1.1    jruoho {
    590       1.1    jruoho     ACPI_PARSE_OBJECT       *InitializerOp;
    591       1.1    jruoho     UINT32                  Length;
    592       1.1    jruoho     UINT32                  Count;
    593       1.1    jruoho     UINT32                  i;
    594       1.1    jruoho     UINT8                   *AsciiString;
    595       1.1    jruoho     UINT16                  *UnicodeString;
    596       1.1    jruoho     ACPI_PARSE_OBJECT       *BufferLengthOp;
    597       1.1    jruoho 
    598       1.1    jruoho 
    599       1.1    jruoho     /* Change op into a buffer object */
    600       1.1    jruoho 
    601  1.1.1.10  christos     Op->Asl.CompileFlags &= ~OP_COMPILE_TIME_CONST;
    602       1.1    jruoho     Op->Asl.ParseOpcode = PARSEOP_BUFFER;
    603       1.1    jruoho     UtSetParseOpName (Op);
    604       1.1    jruoho 
    605       1.1    jruoho     /* Buffer Length is first, followed by the string */
    606       1.1    jruoho 
    607       1.1    jruoho     BufferLengthOp = Op->Asl.Child;
    608       1.1    jruoho     InitializerOp = BufferLengthOp->Asl.Next;
    609       1.1    jruoho 
    610       1.1    jruoho     AsciiString = (UINT8 *) InitializerOp->Asl.Value.String;
    611       1.1    jruoho 
    612       1.1    jruoho     /* Create a new buffer for the Unicode string */
    613       1.1    jruoho 
    614       1.1    jruoho     Count = strlen (InitializerOp->Asl.Value.String) + 1;
    615       1.1    jruoho     Length = Count * sizeof (UINT16);
    616       1.1    jruoho     UnicodeString = UtLocalCalloc (Length);
    617       1.1    jruoho 
    618       1.1    jruoho     /* Convert to Unicode string (including null terminator) */
    619       1.1    jruoho 
    620       1.1    jruoho     for (i = 0; i < Count; i++)
    621       1.1    jruoho     {
    622       1.1    jruoho         UnicodeString[i] = (UINT16) AsciiString[i];
    623       1.1    jruoho     }
    624       1.1    jruoho 
    625       1.1    jruoho     /*
    626       1.1    jruoho      * Just set the buffer size node to be the buffer length, regardless
    627       1.1    jruoho      * of whether it was previously an integer or a default_arg placeholder
    628       1.1    jruoho      */
    629   1.1.1.7  christos     BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
    630   1.1.1.7  christos     BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP;
    631       1.1    jruoho     BufferLengthOp->Asl.Value.Integer = Length;
    632       1.1    jruoho     UtSetParseOpName (BufferLengthOp);
    633       1.1    jruoho 
    634       1.1    jruoho     (void) OpcSetOptimalIntegerSize (BufferLengthOp);
    635       1.1    jruoho 
    636       1.1    jruoho     /* The Unicode string is a raw data buffer */
    637       1.1    jruoho 
    638   1.1.1.7  christos     InitializerOp->Asl.Value.Buffer = (UINT8 *) UnicodeString;
    639   1.1.1.7  christos     InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
    640   1.1.1.7  christos     InitializerOp->Asl.AmlLength = Length;
    641   1.1.1.7  christos     InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
    642   1.1.1.7  christos     InitializerOp->Asl.Child = NULL;
    643       1.1    jruoho     UtSetParseOpName (InitializerOp);
    644       1.1    jruoho }
    645       1.1    jruoho 
    646       1.1    jruoho 
    647       1.1    jruoho /*******************************************************************************
    648       1.1    jruoho  *
    649       1.1    jruoho  * FUNCTION:    OpcDoEisaId
    650       1.1    jruoho  *
    651       1.1    jruoho  * PARAMETERS:  Op        - Parse node
    652       1.1    jruoho  *
    653       1.1    jruoho  * RETURN:      None
    654       1.1    jruoho  *
    655   1.1.1.3  christos  * DESCRIPTION: Convert a string EISA ID to numeric representation. See the
    656   1.1.1.3  christos  *              Pnp BIOS Specification for details. Here is an excerpt:
    657       1.1    jruoho  *
    658       1.1    jruoho  *              A seven character ASCII representation of the product
    659   1.1.1.3  christos  *              identifier compressed into a 32-bit identifier. The seven
    660       1.1    jruoho  *              character ID consists of a three character manufacturer code,
    661       1.1    jruoho  *              a three character hexadecimal product identifier, and a one
    662   1.1.1.3  christos  *              character hexadecimal revision number. The manufacturer code
    663       1.1    jruoho  *              is a 3 uppercase character code that is compressed into 3 5-bit
    664       1.1    jruoho  *              values as follows:
    665       1.1    jruoho  *                  1) Find hex ASCII value for each letter
    666       1.1    jruoho  *                  2) Subtract 40h from each ASCII value
    667   1.1.1.3  christos  *                  3) Retain 5 least significant bits for each letter by
    668       1.1    jruoho  *                     discarding upper 3 bits because they are always 0.
    669       1.1    jruoho  *                  4) Compressed code = concatenate 0 and the 3 5-bit values
    670       1.1    jruoho  *
    671       1.1    jruoho  *              The format of the compressed product identifier is as follows:
    672       1.1    jruoho  *              Byte 0: Bit 7       - Reserved (0)
    673       1.1    jruoho  *                      Bits 6-2:   - 1st character of compressed mfg code
    674       1.1    jruoho  *                      Bits 1-0    - Upper 2 bits of 2nd character of mfg code
    675       1.1    jruoho  *              Byte 1: Bits 7-5    - Lower 3 bits of 2nd character of mfg code
    676       1.1    jruoho  *                      Bits 4-0    - 3rd character of mfg code
    677       1.1    jruoho  *              Byte 2: Bits 7-4    - 1st hex digit of product number
    678       1.1    jruoho  *                      Bits 3-0    - 2nd hex digit of product number
    679  1.1.1.16  christos  *              Byte 3: Bits 7-4    - 3rd hex digit of product number
    680       1.1    jruoho  *                      Bits 3-0    - Hex digit of the revision number
    681       1.1    jruoho  *
    682       1.1    jruoho  ******************************************************************************/
    683       1.1    jruoho 
    684       1.1    jruoho static void
    685       1.1    jruoho OpcDoEisaId (
    686       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    687       1.1    jruoho {
    688       1.1    jruoho     UINT32                  EisaId = 0;
    689       1.1    jruoho     UINT32                  BigEndianId;
    690       1.1    jruoho     char                    *InString;
    691       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    692       1.1    jruoho     UINT32                  i;
    693       1.1    jruoho 
    694       1.1    jruoho 
    695       1.1    jruoho     InString = (char *) Op->Asl.Value.String;
    696       1.1    jruoho 
    697       1.1    jruoho     /*
    698       1.1    jruoho      * The EISAID string must be exactly 7 characters and of the form
    699       1.1    jruoho      * "UUUXXXX" -- 3 uppercase letters and 4 hex digits (e.g., "PNP0001")
    700       1.1    jruoho      */
    701   1.1.1.6  christos     if (strlen (InString) != 7)
    702       1.1    jruoho     {
    703       1.1    jruoho         Status = AE_BAD_PARAMETER;
    704       1.1    jruoho     }
    705       1.1    jruoho     else
    706       1.1    jruoho     {
    707       1.1    jruoho         /* Check all 7 characters for correct format */
    708       1.1    jruoho 
    709       1.1    jruoho         for (i = 0; i < 7; i++)
    710       1.1    jruoho         {
    711       1.1    jruoho             /* First 3 characters must be uppercase letters */
    712       1.1    jruoho 
    713       1.1    jruoho             if (i < 3)
    714       1.1    jruoho             {
    715       1.1    jruoho                 if (!isupper ((int) InString[i]))
    716       1.1    jruoho                 {
    717       1.1    jruoho                     Status = AE_BAD_PARAMETER;
    718       1.1    jruoho                 }
    719       1.1    jruoho             }
    720       1.1    jruoho 
    721       1.1    jruoho             /* Last 4 characters must be hex digits */
    722       1.1    jruoho 
    723       1.1    jruoho             else if (!isxdigit ((int) InString[i]))
    724       1.1    jruoho             {
    725       1.1    jruoho                 Status = AE_BAD_PARAMETER;
    726       1.1    jruoho             }
    727       1.1    jruoho         }
    728       1.1    jruoho     }
    729       1.1    jruoho 
    730       1.1    jruoho     if (ACPI_FAILURE (Status))
    731       1.1    jruoho     {
    732       1.1    jruoho         AslError (ASL_ERROR, ASL_MSG_INVALID_EISAID, Op, Op->Asl.Value.String);
    733       1.1    jruoho     }
    734       1.1    jruoho     else
    735       1.1    jruoho     {
    736       1.1    jruoho         /* Create ID big-endian first (bits are contiguous) */
    737       1.1    jruoho 
    738       1.1    jruoho         BigEndianId =
    739   1.1.1.2    jruoho             (UINT32) ((UINT8) (InString[0] - 0x40)) << 26 |
    740   1.1.1.2    jruoho             (UINT32) ((UINT8) (InString[1] - 0x40)) << 21 |
    741   1.1.1.2    jruoho             (UINT32) ((UINT8) (InString[2] - 0x40)) << 16 |
    742       1.1    jruoho 
    743   1.1.1.4  christos             (AcpiUtAsciiCharToHex (InString[3])) << 12 |
    744   1.1.1.4  christos             (AcpiUtAsciiCharToHex (InString[4])) << 8  |
    745   1.1.1.4  christos             (AcpiUtAsciiCharToHex (InString[5])) << 4  |
    746   1.1.1.4  christos              AcpiUtAsciiCharToHex (InString[6]);
    747       1.1    jruoho 
    748       1.1    jruoho         /* Swap to little-endian to get final ID (see function header) */
    749       1.1    jruoho 
    750       1.1    jruoho         EisaId = AcpiUtDwordByteSwap (BigEndianId);
    751       1.1    jruoho     }
    752       1.1    jruoho 
    753       1.1    jruoho     /*
    754       1.1    jruoho      * Morph the Op into an integer, regardless of whether there
    755       1.1    jruoho      * was an error in the EISAID string
    756       1.1    jruoho      */
    757       1.1    jruoho     Op->Asl.Value.Integer = EisaId;
    758       1.1    jruoho 
    759  1.1.1.10  christos     Op->Asl.CompileFlags &= ~OP_COMPILE_TIME_CONST;
    760       1.1    jruoho     Op->Asl.ParseOpcode = PARSEOP_INTEGER;
    761       1.1    jruoho     (void) OpcSetOptimalIntegerSize (Op);
    762       1.1    jruoho 
    763       1.1    jruoho     /* Op is now an integer */
    764       1.1    jruoho 
    765       1.1    jruoho     UtSetParseOpName (Op);
    766       1.1    jruoho }
    767       1.1    jruoho 
    768       1.1    jruoho 
    769       1.1    jruoho /*******************************************************************************
    770       1.1    jruoho  *
    771   1.1.1.3  christos  * FUNCTION:    OpcDoUuId
    772       1.1    jruoho  *
    773   1.1.1.5  christos  * PARAMETERS:  Op                  - Parse node
    774       1.1    jruoho  *
    775       1.1    jruoho  * RETURN:      None
    776       1.1    jruoho  *
    777       1.1    jruoho  * DESCRIPTION: Convert UUID string to 16-byte buffer
    778       1.1    jruoho  *
    779       1.1    jruoho  ******************************************************************************/
    780       1.1    jruoho 
    781       1.1    jruoho static void
    782       1.1    jruoho OpcDoUuId (
    783       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    784       1.1    jruoho {
    785       1.1    jruoho     char                    *InString;
    786   1.1.1.4  christos     UINT8                   *Buffer;
    787       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    788       1.1    jruoho     ACPI_PARSE_OBJECT       *NewOp;
    789       1.1    jruoho 
    790       1.1    jruoho 
    791   1.1.1.5  christos     InString = ACPI_CAST_PTR (char, Op->Asl.Value.String);
    792       1.1    jruoho     Buffer = UtLocalCalloc (16);
    793       1.1    jruoho 
    794   1.1.1.2    jruoho     Status = AuValidateUuid (InString);
    795       1.1    jruoho     if (ACPI_FAILURE (Status))
    796       1.1    jruoho     {
    797       1.1    jruoho         AslError (ASL_ERROR, ASL_MSG_INVALID_UUID, Op, Op->Asl.Value.String);
    798       1.1    jruoho     }
    799   1.1.1.2    jruoho     else
    800       1.1    jruoho     {
    801  1.1.1.15  christos         /* Convert UUID string to a buffer, check for a known UUID */
    802  1.1.1.15  christos 
    803   1.1.1.4  christos         AcpiUtConvertStringToUuid (InString, Buffer);
    804  1.1.1.15  christos         if (!AcpiAhMatchUuid (Buffer))
    805  1.1.1.15  christos         {
    806  1.1.1.15  christos             AslError (ASL_REMARK, ASL_MSG_UUID_NOT_FOUND, Op, NULL);
    807  1.1.1.15  christos         }
    808       1.1    jruoho     }
    809       1.1    jruoho 
    810       1.1    jruoho     /* Change Op to a Buffer */
    811       1.1    jruoho 
    812       1.1    jruoho     Op->Asl.ParseOpcode = PARSEOP_BUFFER;
    813       1.1    jruoho     Op->Common.AmlOpcode = AML_BUFFER_OP;
    814       1.1    jruoho 
    815       1.1    jruoho     /* Disable further optimization */
    816       1.1    jruoho 
    817  1.1.1.10  christos     Op->Asl.CompileFlags &= ~OP_COMPILE_TIME_CONST;
    818       1.1    jruoho     UtSetParseOpName (Op);
    819       1.1    jruoho 
    820       1.1    jruoho     /* Child node is the buffer length */
    821       1.1    jruoho 
    822  1.1.1.10  christos     NewOp = TrAllocateOp (PARSEOP_INTEGER);
    823       1.1    jruoho 
    824   1.1.1.7  christos     NewOp->Asl.AmlOpcode = AML_BYTE_OP;
    825       1.1    jruoho     NewOp->Asl.Value.Integer = 16;
    826   1.1.1.7  christos     NewOp->Asl.Parent = Op;
    827       1.1    jruoho 
    828       1.1    jruoho     Op->Asl.Child = NewOp;
    829       1.1    jruoho     Op = NewOp;
    830       1.1    jruoho 
    831       1.1    jruoho     /* Peer to the child is the raw buffer data */
    832       1.1    jruoho 
    833  1.1.1.10  christos     NewOp = TrAllocateOp (PARSEOP_RAW_DATA);
    834   1.1.1.7  christos     NewOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
    835   1.1.1.7  christos     NewOp->Asl.AmlLength = 16;
    836   1.1.1.7  christos     NewOp->Asl.Value.String = ACPI_CAST_PTR (char, Buffer);
    837   1.1.1.7  christos     NewOp->Asl.Parent = Op->Asl.Parent;
    838       1.1    jruoho 
    839       1.1    jruoho     Op->Asl.Next = NewOp;
    840       1.1    jruoho }
    841       1.1    jruoho 
    842       1.1    jruoho 
    843       1.1    jruoho /*******************************************************************************
    844       1.1    jruoho  *
    845       1.1    jruoho  * FUNCTION:    OpcGenerateAmlOpcode
    846       1.1    jruoho  *
    847   1.1.1.5  christos  * PARAMETERS:  Op                  - Parse node
    848       1.1    jruoho  *
    849       1.1    jruoho  * RETURN:      None
    850       1.1    jruoho  *
    851       1.1    jruoho  * DESCRIPTION: Generate the AML opcode associated with the node and its
    852   1.1.1.3  christos  *              parse (lex/flex) keyword opcode. Essentially implements
    853       1.1    jruoho  *              a mapping between the parse opcodes and the actual AML opcodes.
    854       1.1    jruoho  *
    855       1.1    jruoho  ******************************************************************************/
    856       1.1    jruoho 
    857       1.1    jruoho void
    858       1.1    jruoho OpcGenerateAmlOpcode (
    859       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    860       1.1    jruoho {
    861       1.1    jruoho     UINT16                  Index;
    862       1.1    jruoho 
    863       1.1    jruoho 
    864       1.1    jruoho     Index = (UINT16) (Op->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
    865       1.1    jruoho 
    866       1.1    jruoho     Op->Asl.AmlOpcode     = AslKeywordMapping[Index].AmlOpcode;
    867       1.1    jruoho     Op->Asl.AcpiBtype     = AslKeywordMapping[Index].AcpiBtype;
    868       1.1    jruoho     Op->Asl.CompileFlags |= AslKeywordMapping[Index].Flags;
    869       1.1    jruoho 
    870       1.1    jruoho     if (!Op->Asl.Value.Integer)
    871       1.1    jruoho     {
    872       1.1    jruoho         Op->Asl.Value.Integer = AslKeywordMapping[Index].Value;
    873       1.1    jruoho     }
    874       1.1    jruoho 
    875       1.1    jruoho     /* Special handling for some opcodes */
    876       1.1    jruoho 
    877       1.1    jruoho     switch (Op->Asl.ParseOpcode)
    878       1.1    jruoho     {
    879       1.1    jruoho     case PARSEOP_INTEGER:
    880       1.1    jruoho         /*
    881       1.1    jruoho          * Set the opcode based on the size of the integer
    882       1.1    jruoho          */
    883       1.1    jruoho         (void) OpcSetOptimalIntegerSize (Op);
    884       1.1    jruoho         break;
    885       1.1    jruoho 
    886       1.1    jruoho     case PARSEOP_OFFSET:
    887       1.1    jruoho 
    888       1.1    jruoho         Op->Asl.AmlOpcodeLength = 1;
    889       1.1    jruoho         break;
    890       1.1    jruoho 
    891       1.1    jruoho     case PARSEOP_ACCESSAS:
    892       1.1    jruoho 
    893       1.1    jruoho         OpcDoAccessAs (Op);
    894       1.1    jruoho         break;
    895       1.1    jruoho 
    896   1.1.1.3  christos     case PARSEOP_CONNECTION:
    897   1.1.1.3  christos 
    898   1.1.1.3  christos         OpcDoConnection (Op);
    899   1.1.1.3  christos         break;
    900   1.1.1.3  christos 
    901       1.1    jruoho     case PARSEOP_EISAID:
    902       1.1    jruoho 
    903       1.1    jruoho         OpcDoEisaId (Op);
    904       1.1    jruoho         break;
    905       1.1    jruoho 
    906   1.1.1.5  christos     case PARSEOP_PRINTF:
    907   1.1.1.5  christos 
    908   1.1.1.5  christos         OpcDoPrintf (Op);
    909   1.1.1.5  christos         break;
    910   1.1.1.5  christos 
    911   1.1.1.5  christos     case PARSEOP_FPRINTF:
    912   1.1.1.5  christos 
    913   1.1.1.5  christos         OpcDoFprintf (Op);
    914   1.1.1.5  christos         break;
    915   1.1.1.5  christos 
    916   1.1.1.5  christos     case PARSEOP_TOPLD:
    917   1.1.1.5  christos 
    918   1.1.1.5  christos         OpcDoPld (Op);
    919   1.1.1.5  christos         break;
    920   1.1.1.5  christos 
    921       1.1    jruoho     case PARSEOP_TOUUID:
    922       1.1    jruoho 
    923       1.1    jruoho         OpcDoUuId (Op);
    924       1.1    jruoho         break;
    925       1.1    jruoho 
    926       1.1    jruoho     case PARSEOP_UNICODE:
    927       1.1    jruoho 
    928       1.1    jruoho         OpcDoUnicode (Op);
    929       1.1    jruoho         break;
    930       1.1    jruoho 
    931       1.1    jruoho     case PARSEOP_INCLUDE:
    932       1.1    jruoho 
    933  1.1.1.12  christos         AslGbl_HasIncludeFiles = TRUE;
    934       1.1    jruoho         break;
    935       1.1    jruoho 
    936   1.1.1.3  christos     case PARSEOP_TIMER:
    937   1.1.1.3  christos 
    938   1.1.1.3  christos         if (AcpiGbl_IntegerBitWidth == 32)
    939   1.1.1.3  christos         {
    940   1.1.1.3  christos             AslError (ASL_REMARK, ASL_MSG_TRUNCATION, Op, NULL);
    941   1.1.1.3  christos         }
    942   1.1.1.3  christos         break;
    943   1.1.1.3  christos 
    944       1.1    jruoho     default:
    945   1.1.1.3  christos 
    946       1.1    jruoho         /* Nothing to do for other opcodes */
    947   1.1.1.3  christos 
    948       1.1    jruoho         break;
    949       1.1    jruoho     }
    950       1.1    jruoho 
    951       1.1    jruoho     return;
    952       1.1    jruoho }
    953