The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/dev/acpica/compiler/asltransform.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /******************************************************************************
    2  *
    3  * Module Name: asltransform - Parse tree transforms
    4  *
    5  *****************************************************************************/
    6 
    7 /******************************************************************************
    8  *
    9  * 1. Copyright Notice
   10  *
   11  * Some or all of this work - Copyright (c) 1999 - 2022, Intel Corp.
   12  * All rights reserved.
   13  *
   14  * 2. License
   15  *
   16  * 2.1. This is your license from Intel Corp. under its intellectual property
   17  * rights. You may have additional license terms from the party that provided
   18  * you this software, covering your right to use that party's intellectual
   19  * property rights.
   20  *
   21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
   22  * copy of the source code appearing in this file ("Covered Code") an
   23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
   24  * base code distributed originally by Intel ("Original Intel Code") to copy,
   25  * make derivatives, distribute, use and display any portion of the Covered
   26  * Code in any form, with the right to sublicense such rights; and
   27  *
   28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
   29  * license (with the right to sublicense), under only those claims of Intel
   30  * patents that are infringed by the Original Intel Code, to make, use, sell,
   31  * offer to sell, and import the Covered Code and derivative works thereof
   32  * solely to the minimum extent necessary to exercise the above copyright
   33  * license, and in no event shall the patent license extend to any additions
   34  * to or modifications of the Original Intel Code. No other license or right
   35  * is granted directly or by implication, estoppel or otherwise;
   36  *
   37  * The above copyright and patent license is granted only if the following
   38  * conditions are met:
   39  *
   40  * 3. Conditions
   41  *
   42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
   43  * Redistribution of source code of any substantial portion of the Covered
   44  * Code or modification with rights to further distribute source must include
   45  * the above Copyright Notice, the above License, this list of Conditions,
   46  * and the following Disclaimer and Export Compliance provision. In addition,
   47  * Licensee must cause all Covered Code to which Licensee contributes to
   48  * contain a file documenting the changes Licensee made to create that Covered
   49  * Code and the date of any change. Licensee must include in that file the
   50  * documentation of any changes made by any predecessor Licensee. Licensee
   51  * must include a prominent statement that the modification is derived,
   52  * directly or indirectly, from Original Intel Code.
   53  *
   54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
   55  * Redistribution of source code of any substantial portion of the Covered
   56  * Code or modification without rights to further distribute source must
   57  * include the following Disclaimer and Export Compliance provision in the
   58  * documentation and/or other materials provided with distribution. In
   59  * addition, Licensee may not authorize further sublicense of source of any
   60  * portion of the Covered Code, and must include terms to the effect that the
   61  * license from Licensee to its licensee is limited to the intellectual
   62  * property embodied in the software Licensee provides to its licensee, and
   63  * not to intellectual property embodied in modifications its licensee may
   64  * make.
   65  *
   66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
   67  * substantial portion of the Covered Code or modification must reproduce the
   68  * above Copyright Notice, and the following Disclaimer and Export Compliance
   69  * provision in the documentation and/or other materials provided with the
   70  * distribution.
   71  *
   72  * 3.4. Intel retains all right, title, and interest in and to the Original
   73  * Intel Code.
   74  *
   75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
   76  * Intel shall be used in advertising or otherwise to promote the sale, use or
   77  * other dealings in products derived from or relating to the Covered Code
   78  * without prior written authorization from Intel.
   79  *
   80  * 4. Disclaimer and Export Compliance
   81  *
   82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
   83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
   84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
   85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
   86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
   87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
   88  * PARTICULAR PURPOSE.
   89  *
   90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
   91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
   92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
   93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
   94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
   95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
   96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
   97  * LIMITED REMEDY.
   98  *
   99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
  100  * software or system incorporating such software without first obtaining any
  101  * required license or other approval from the U. S. Department of Commerce or
  102  * any other agency or department of the United States Government. In the
  103  * event Licensee exports any such software from the United States or
  104  * re-exports any such software from a foreign destination, Licensee shall
  105  * ensure that the distribution and export/re-export of the software is in
  106  * compliance with all laws, regulations, orders, or other restrictions of the
  107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  108  * any of its subsidiaries will export/re-export any technical data, process,
  109  * software, or service, directly or indirectly, to any country for which the
  110  * United States government or any agency thereof requires an export license,
  111  * other governmental approval, or letter of assurance, without first obtaining
  112  * such license, approval or letter.
  113  *
  114  *****************************************************************************
  115  *
  116  * Alternatively, you may choose to be licensed under the terms of the
  117  * following license:
  118  *
  119  * Redistribution and use in source and binary forms, with or without
  120  * modification, are permitted provided that the following conditions
  121  * are met:
  122  * 1. Redistributions of source code must retain the above copyright
  123  *    notice, this list of conditions, and the following disclaimer,
  124  *    without modification.
  125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  126  *    substantially similar to the "NO WARRANTY" disclaimer below
  127  *    ("Disclaimer") and any redistribution must be conditioned upon
  128  *    including a substantially similar Disclaimer requirement for further
  129  *    binary redistribution.
  130  * 3. Neither the names of the above-listed copyright holders nor the names
  131  *    of any contributors may be used to endorse or promote products derived
  132  *    from this software without specific prior written permission.
  133  *
  134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  145  *
  146  * Alternatively, you may choose to be licensed under the terms of the
  147  * GNU General Public License ("GPL") version 2 as published by the Free
  148  * Software Foundation.
  149  *
  150  *****************************************************************************/
  151 
  152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
  153 #include "aslcompiler.y.h"
  154 #include <contrib/dev/acpica/include/acnamesp.h>
  155 
  156 #define _COMPONENT          ACPI_COMPILER
  157         ACPI_MODULE_NAME    ("asltransform")
  158 
  159 /* Local prototypes */
  160 
  161 static void
  162 TrTransformSubtree (
  163     ACPI_PARSE_OBJECT       *Op);
  164 
  165 static char *
  166 TrAmlGetNextTempName (
  167     ACPI_PARSE_OBJECT       *Op,
  168     UINT8                   *TempCount);
  169 
  170 static void
  171 TrAmlInitLineNumbers (
  172     ACPI_PARSE_OBJECT       *Op,
  173     ACPI_PARSE_OBJECT       *Neighbor);
  174 
  175 static void
  176 TrAmlInitNode (
  177     ACPI_PARSE_OBJECT       *Op,
  178     UINT16                  ParseOpcode);
  179 
  180 static void
  181 TrAmlSetSubtreeParent (
  182     ACPI_PARSE_OBJECT       *Op,
  183     ACPI_PARSE_OBJECT       *Parent);
  184 
  185 static void
  186 TrAmlInsertPeer (
  187     ACPI_PARSE_OBJECT       *Op,
  188     ACPI_PARSE_OBJECT       *NewPeer);
  189 
  190 static void
  191 TrDoDefinitionBlock (
  192     ACPI_PARSE_OBJECT       *Op);
  193 
  194 static void
  195 TrDoSwitch (
  196     ACPI_PARSE_OBJECT       *StartNode);
  197 
  198 static void
  199 TrCheckForDuplicateCase (
  200     ACPI_PARSE_OBJECT       *CaseOp,
  201     ACPI_PARSE_OBJECT       *Predicate1);
  202 
  203 static BOOLEAN
  204 TrCheckForBufferMatch (
  205     ACPI_PARSE_OBJECT       *Next1,
  206     ACPI_PARSE_OBJECT       *Next2);
  207 
  208 static void
  209 TrDoMethod (
  210     ACPI_PARSE_OBJECT       *Op);
  211 
  212 
  213 /*******************************************************************************
  214  *
  215  * FUNCTION:    TrAmlGetNextTempName
  216  *
  217  * PARAMETERS:  Op              - Current parse op
  218  *              TempCount       - Current temporary counter. Was originally
  219  *                                per-module; Currently per method, could be
  220  *                                expanded to per-scope.
  221  *
  222  * RETURN:      A pointer to name (allocated here).
  223  *
  224  * DESCRIPTION: Generate an ACPI name of the form _T_x. These names are
  225  *              reserved for use by the ASL compiler. (_T_0 through _T_Z)
  226  *
  227  ******************************************************************************/
  228 
  229 static char *
  230 TrAmlGetNextTempName (
  231     ACPI_PARSE_OBJECT       *Op,
  232     UINT8                   *TempCount)
  233 {
  234     char                    *TempName;
  235 
  236 
  237     if (*TempCount >= (10 + 26))  /* 0-35 valid: 0-9 and A-Z for TempName[3] */
  238     {
  239         /* Too many temps */
  240 
  241         AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL);
  242         return (NULL);
  243     }
  244 
  245     TempName = UtLocalCalloc (5);
  246 
  247     if (*TempCount < 10)    /* 0-9 */
  248     {
  249         TempName[3] = (char) (*TempCount + '');
  250     }
  251     else                    /* 10-35: A-Z */
  252     {
  253         TempName[3] = (char) (*TempCount + ('A' - 10));
  254     }
  255 
  256     (*TempCount)++;
  257 
  258     /* First three characters are always "_T_" */
  259 
  260     TempName[0] = '_';
  261     TempName[1] = 'T';
  262     TempName[2] = '_';
  263 
  264     return (TempName);
  265 }
  266 
  267 
  268 /*******************************************************************************
  269  *
  270  * FUNCTION:    TrAmlInitLineNumbers
  271  *
  272  * PARAMETERS:  Op              - Op to be initialized
  273  *              Neighbor        - Op used for initialization values
  274  *
  275  * RETURN:      None
  276  *
  277  * DESCRIPTION: Initialized the various line numbers for a parse node.
  278  *
  279  ******************************************************************************/
  280 
  281 static void
  282 TrAmlInitLineNumbers (
  283     ACPI_PARSE_OBJECT       *Op,
  284     ACPI_PARSE_OBJECT       *Neighbor)
  285 {
  286 
  287     Op->Asl.EndLine           = Neighbor->Asl.EndLine;
  288     Op->Asl.EndLogicalLine    = Neighbor->Asl.EndLogicalLine;
  289     Op->Asl.LineNumber        = Neighbor->Asl.LineNumber;
  290     Op->Asl.LogicalByteOffset = Neighbor->Asl.LogicalByteOffset;
  291     Op->Asl.LogicalLineNumber = Neighbor->Asl.LogicalLineNumber;
  292 }
  293 
  294 
  295 /*******************************************************************************
  296  *
  297  * FUNCTION:    TrAmlInitNode
  298  *
  299  * PARAMETERS:  Op              - Op to be initialized
  300  *              ParseOpcode     - Opcode for this node
  301  *
  302  * RETURN:      None
  303  *
  304  * DESCRIPTION: Initialize a node with the parse opcode and opcode name.
  305  *
  306  ******************************************************************************/
  307 
  308 static void
  309 TrAmlInitNode (
  310     ACPI_PARSE_OBJECT       *Op,
  311     UINT16                  ParseOpcode)
  312 {
  313 
  314     Op->Asl.ParseOpcode = ParseOpcode;
  315     UtSetParseOpName (Op);
  316 }
  317 
  318 
  319 /*******************************************************************************
  320  *
  321  * FUNCTION:    TrAmlSetSubtreeParent
  322  *
  323  * PARAMETERS:  Op              - First node in a list of peer nodes
  324  *              Parent          - Parent of the subtree
  325  *
  326  * RETURN:      None
  327  *
  328  * DESCRIPTION: Set the parent for all peer nodes in a subtree
  329  *
  330  ******************************************************************************/
  331 
  332 static void
  333 TrAmlSetSubtreeParent (
  334     ACPI_PARSE_OBJECT       *Op,
  335     ACPI_PARSE_OBJECT       *Parent)
  336 {
  337     ACPI_PARSE_OBJECT       *Next;
  338 
  339 
  340     Next = Op;
  341     while (Next)
  342     {
  343         Next->Asl.Parent = Parent;
  344         Next = Next->Asl.Next;
  345     }
  346 }
  347 
  348 
  349 /*******************************************************************************
  350  *
  351  * FUNCTION:    TrAmlInsertPeer
  352  *
  353  * PARAMETERS:  Op              - First node in a list of peer nodes
  354  *              NewPeer         - Peer node to insert
  355  *
  356  * RETURN:      None
  357  *
  358  * DESCRIPTION: Insert a new peer node into a list of peers.
  359  *
  360  ******************************************************************************/
  361 
  362 static void
  363 TrAmlInsertPeer (
  364     ACPI_PARSE_OBJECT       *Op,
  365     ACPI_PARSE_OBJECT       *NewPeer)
  366 {
  367 
  368     NewPeer->Asl.Next = Op->Asl.Next;
  369     Op->Asl.Next = NewPeer;
  370 }
  371 
  372 
  373 /*******************************************************************************
  374  *
  375  * FUNCTION:    TrAmlTransformWalkBegin
  376  *
  377  * PARAMETERS:  ASL_WALK_CALLBACK
  378  *
  379  * RETURN:      None
  380  *
  381  * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
  382  *              operands.
  383  *
  384  ******************************************************************************/
  385 
  386 ACPI_STATUS
  387 TrAmlTransformWalkBegin (
  388     ACPI_PARSE_OBJECT       *Op,
  389     UINT32                  Level,
  390     void                    *Context)
  391 {
  392 
  393     TrTransformSubtree (Op);
  394     return (AE_OK);
  395 }
  396 
  397 
  398 /*******************************************************************************
  399  *
  400  * FUNCTION:    TrAmlTransformWalkEnd
  401  *
  402  * PARAMETERS:  ASL_WALK_CALLBACK
  403  *
  404  * RETURN:      None
  405  *
  406  * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
  407  *              operands.
  408  *
  409  ******************************************************************************/
  410 
  411 ACPI_STATUS
  412 TrAmlTransformWalkEnd (
  413     ACPI_PARSE_OBJECT       *Op,
  414     UINT32                  Level,
  415     void                    *Context)
  416 {
  417 
  418     /* Save possible Externals list in the DefintionBlock Op */
  419 
  420     if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK)
  421     {
  422         Op->Asl.Value.Arg = AslGbl_ExternalsListHead;
  423         AslGbl_ExternalsListHead = NULL;
  424     }
  425 
  426     return (AE_OK);
  427 }
  428 
  429 
  430 /*******************************************************************************
  431  *
  432  * FUNCTION:    TrTransformSubtree
  433  *
  434  * PARAMETERS:  Op        - The parent parse node
  435  *
  436  * RETURN:      None
  437  *
  438  * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more
  439  *              complex AML opcodes require processing of the child nodes
  440  *              (arguments/operands).
  441  *
  442  ******************************************************************************/
  443 
  444 static void
  445 TrTransformSubtree (
  446     ACPI_PARSE_OBJECT           *Op)
  447 {
  448     ACPI_PARSE_OBJECT           *MethodOp;
  449     ACPI_NAMESTRING_INFO        Info;
  450 
  451 
  452     if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
  453     {
  454         return;
  455     }
  456 
  457     switch (Op->Asl.ParseOpcode)
  458     {
  459     case PARSEOP_DEFINITION_BLOCK:
  460 
  461         TrDoDefinitionBlock (Op);
  462         break;
  463 
  464     case PARSEOP_SWITCH:
  465 
  466         TrDoSwitch (Op);
  467         break;
  468 
  469     case PARSEOP_METHOD:
  470 
  471         TrDoMethod (Op);
  472         break;
  473 
  474     case PARSEOP_EXTERNAL:
  475 
  476         ExDoExternal (Op);
  477         break;
  478 
  479     case PARSEOP___METHOD__:
  480 
  481         /* Transform to a string op containing the parent method name */
  482 
  483         Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
  484         UtSetParseOpName (Op);
  485 
  486         /* Find the parent control method op */
  487 
  488         MethodOp = Op;
  489         while (MethodOp)
  490         {
  491             if (MethodOp->Asl.ParseOpcode == PARSEOP_METHOD)
  492             {
  493                 /* First child contains the method name */
  494 
  495                 MethodOp = MethodOp->Asl.Child;
  496                 Op->Asl.Value.String = MethodOp->Asl.Value.String;
  497                 return;
  498             }
  499 
  500             MethodOp = MethodOp->Asl.Parent;
  501         }
  502 
  503         /* At the root, invocation not within a control method */
  504 
  505         Op->Asl.Value.String = "\\";
  506         break;
  507 
  508     case PARSEOP_NAMESTRING:
  509         /*
  510          * A NameString can be up to 255 (0xFF) individual NameSegs maximum
  511          * (with 254 dot separators) - as per the ACPI specification. Note:
  512          * Cannot check for NumSegments == 0 because things like
  513          * Scope(\) are legal and OK.
  514          */
  515         Info.ExternalName = Op->Asl.Value.String;
  516         AcpiNsGetInternalNameLength (&Info);
  517 
  518         if (Info.NumSegments > 255)
  519         {
  520             AslError (ASL_ERROR, ASL_MSG_NAMESTRING_LENGTH, Op, NULL);
  521         }
  522         break;
  523 
  524     case PARSEOP_UNLOAD:
  525 
  526         AslError (ASL_WARNING, ASL_MSG_UNLOAD, Op, NULL);
  527         break;
  528 
  529     case PARSEOP_SLEEP:
  530 
  531         /* Remark for very long sleep values */
  532 
  533         if (Op->Asl.Child->Asl.Value.Integer > 1000)
  534         {
  535             AslError (ASL_REMARK, ASL_MSG_LONG_SLEEP, Op, NULL);
  536         }
  537         break;
  538 
  539     case PARSEOP_PROCESSOR:
  540 
  541         AslError (ASL_WARNING, ASL_MSG_LEGACY_PROCESSOR_OP, Op, Op->Asl.ExternalName);
  542         break;
  543 
  544     case PARSEOP_OBJECTTYPE_DDB:
  545 
  546         AslError (ASL_WARNING, ASL_MSG_LEGACY_DDB_TYPE, Op, Op->Asl.ExternalName);
  547         break;
  548 
  549     default:
  550 
  551         /* Nothing to do here for other opcodes */
  552 
  553         break;
  554     }
  555 }
  556 
  557 
  558 /*******************************************************************************
  559  *
  560  * FUNCTION:    TrDoDefinitionBlock
  561  *
  562  * PARAMETERS:  Op        - Parse node
  563  *
  564  * RETURN:      None
  565  *
  566  * DESCRIPTION: Find the end of the definition block and set a global to this
  567  *              node. It is used by the compiler to insert compiler-generated
  568  *              names at the root level of the namespace.
  569  *
  570  ******************************************************************************/
  571 
  572 static void
  573 TrDoDefinitionBlock (
  574     ACPI_PARSE_OBJECT       *Op)
  575 {
  576     ACPI_PARSE_OBJECT       *Next;
  577     UINT32                  i;
  578 
  579 
  580     /* Reset external list when starting a definition block */
  581 
  582     AslGbl_ExternalsListHead = NULL;
  583 
  584     Next = Op->Asl.Child;
  585     for (i = 0; i < 5; i++)
  586     {
  587         Next = Next->Asl.Next;
  588         if (i == 0)
  589         {
  590             /*
  591              * This is the table signature. Only the DSDT can be assumed
  592              * to be at the root of the namespace;  Therefore, namepath
  593              * optimization can only be performed on the DSDT.
  594              */
  595             if (!ACPI_COMPARE_NAMESEG (Next->Asl.Value.String, ACPI_SIG_DSDT))
  596             {
  597                 AslGbl_ReferenceOptimizationFlag = FALSE;
  598             }
  599         }
  600     }
  601 
  602     AslGbl_FirstLevelInsertionNode = Next;
  603 }
  604 
  605 
  606 /*******************************************************************************
  607  *
  608  * FUNCTION:    TrDoSwitch
  609  *
  610  * PARAMETERS:  StartNode        - Parse node for SWITCH
  611  *
  612  * RETURN:      None
  613  *
  614  * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs. There is
  615  *              no actual AML opcode for SWITCH -- it must be simulated.
  616  *
  617  ******************************************************************************/
  618 
  619 static void
  620 TrDoSwitch (
  621     ACPI_PARSE_OBJECT       *StartNode)
  622 {
  623     ACPI_PARSE_OBJECT       *Next;
  624     ACPI_PARSE_OBJECT       *CaseOp = NULL;
  625     ACPI_PARSE_OBJECT       *CaseBlock = NULL;
  626     ACPI_PARSE_OBJECT       *DefaultOp = NULL;
  627     ACPI_PARSE_OBJECT       *CurrentParentNode;
  628     ACPI_PARSE_OBJECT       *Conditional = NULL;
  629     ACPI_PARSE_OBJECT       *Predicate;
  630     ACPI_PARSE_OBJECT       *Peer;
  631     ACPI_PARSE_OBJECT       *NewOp;
  632     ACPI_PARSE_OBJECT       *NewOp2;
  633     ACPI_PARSE_OBJECT       *MethodOp;
  634     ACPI_PARSE_OBJECT       *StoreOp;
  635     ACPI_PARSE_OBJECT       *BreakOp;
  636     ACPI_PARSE_OBJECT       *BufferOp;
  637     char                    *PredicateValueName;
  638     UINT16                  Index;
  639     UINT32                  Btype;
  640 
  641 
  642     /* Start node is the Switch() node */
  643 
  644     CurrentParentNode  = StartNode;
  645 
  646     /* Create a new temp name of the form _T_x */
  647 
  648     PredicateValueName = TrAmlGetNextTempName (StartNode, &AslGbl_TempCount);
  649     if (!PredicateValueName)
  650     {
  651         return;
  652     }
  653 
  654     /* First child is the Switch() predicate */
  655 
  656     Next = StartNode->Asl.Child;
  657 
  658     /*
  659      * Examine the return type of the Switch Value -
  660      * must be Integer/Buffer/String
  661      */
  662     Index = (UINT16) (Next->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
  663     Btype = AslKeywordMapping[Index].AcpiBtype;
  664     if ((Btype != ACPI_BTYPE_INTEGER) &&
  665         (Btype != ACPI_BTYPE_STRING)  &&
  666         (Btype != ACPI_BTYPE_BUFFER))
  667     {
  668         AslError (ASL_WARNING, ASL_MSG_SWITCH_TYPE, Next, NULL);
  669         Btype = ACPI_BTYPE_INTEGER;
  670     }
  671 
  672     /* CASE statements start at next child */
  673 
  674     Peer = Next->Asl.Next;
  675     while (Peer)
  676     {
  677         Next = Peer;
  678         Peer = Next->Asl.Next;
  679 
  680         if (Next->Asl.ParseOpcode == PARSEOP_CASE)
  681         {
  682             TrCheckForDuplicateCase (Next, Next->Asl.Child);
  683 
  684             if (CaseOp)
  685             {
  686                 /* Add an ELSE to complete the previous CASE */
  687 
  688                 NewOp = TrCreateLeafOp (PARSEOP_ELSE);
  689                 NewOp->Asl.Parent = Conditional->Asl.Parent;
  690                 TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent);
  691 
  692                 /* Link ELSE node as a peer to the previous IF */
  693 
  694                 TrAmlInsertPeer (Conditional, NewOp);
  695                 CurrentParentNode = NewOp;
  696             }
  697 
  698             CaseOp = Next;
  699             Conditional = CaseOp;
  700             CaseBlock = CaseOp->Asl.Child->Asl.Next;
  701             Conditional->Asl.Child->Asl.Next = NULL;
  702             Predicate = CaseOp->Asl.Child;
  703 
  704             if ((Predicate->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
  705                 (Predicate->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
  706             {
  707                 /*
  708                  * Convert the package declaration to this form:
  709                  *
  710                  * If (LNotEqual (Match (Package(<size>){<data>},
  711                  *                       MEQ, _T_x, MTR, Zero, Zero), Ones))
  712                  */
  713                 NewOp2              = TrCreateLeafOp (PARSEOP_MATCHTYPE_MEQ);
  714                 Predicate->Asl.Next = NewOp2;
  715                 TrAmlInitLineNumbers (NewOp2, Conditional);
  716 
  717                 NewOp               = NewOp2;
  718                 NewOp2              = TrCreateValuedLeafOp (PARSEOP_NAMESTRING,
  719                                         (UINT64) ACPI_TO_INTEGER (PredicateValueName));
  720                 NewOp->Asl.Next     = NewOp2;
  721                 TrAmlInitLineNumbers (NewOp2, Predicate);
  722 
  723                 NewOp               = NewOp2;
  724                 NewOp2              = TrCreateLeafOp (PARSEOP_MATCHTYPE_MTR);
  725                 NewOp->Asl.Next     = NewOp2;
  726                 TrAmlInitLineNumbers (NewOp2, Predicate);
  727 
  728                 NewOp               = NewOp2;
  729                 NewOp2              = TrCreateLeafOp (PARSEOP_ZERO);
  730                 NewOp->Asl.Next     = NewOp2;
  731                 TrAmlInitLineNumbers (NewOp2, Predicate);
  732 
  733                 NewOp               = NewOp2;
  734                 NewOp2              = TrCreateLeafOp (PARSEOP_ZERO);
  735                 NewOp->Asl.Next     = NewOp2;
  736                 TrAmlInitLineNumbers (NewOp2, Predicate);
  737 
  738                 NewOp2              = TrCreateLeafOp (PARSEOP_MATCH);
  739                 NewOp2->Asl.Child   = Predicate;  /* PARSEOP_PACKAGE */
  740                 TrAmlInitLineNumbers (NewOp2, Conditional);
  741                 TrAmlSetSubtreeParent (Predicate, NewOp2);
  742 
  743                 NewOp               = NewOp2;
  744                 NewOp2              = TrCreateLeafOp (PARSEOP_ONES);
  745                 NewOp->Asl.Next     = NewOp2;
  746                 TrAmlInitLineNumbers (NewOp2, Conditional);
  747 
  748                 NewOp2              = TrCreateLeafOp (PARSEOP_LEQUAL);
  749                 NewOp2->Asl.Child   = NewOp;
  750                 NewOp->Asl.Parent   = NewOp2;
  751                 TrAmlInitLineNumbers (NewOp2, Conditional);
  752                 TrAmlSetSubtreeParent (NewOp, NewOp2);
  753 
  754                 NewOp               = NewOp2;
  755                 NewOp2              = TrCreateLeafOp (PARSEOP_LNOT);
  756                 NewOp2->Asl.Child   = NewOp;
  757                 NewOp2->Asl.Parent  = Conditional;
  758                 NewOp->Asl.Parent   = NewOp2;
  759                 TrAmlInitLineNumbers (NewOp2, Conditional);
  760 
  761                 Conditional->Asl.Child = NewOp2;
  762                 NewOp2->Asl.Next = CaseBlock;
  763             }
  764             else
  765             {
  766                 /*
  767                  * Integer and Buffer case.
  768                  *
  769                  * Change CaseOp() to:  If (LEqual (SwitchValue, CaseValue)) {...}
  770                  * Note: SwitchValue is first to allow the CaseValue to be implicitly
  771                  * converted to the type of SwitchValue if necessary.
  772                  *
  773                  * CaseOp->Child is the case value
  774                  * CaseOp->Child->Peer is the beginning of the case block
  775                  */
  776                 NewOp = TrCreateValuedLeafOp (PARSEOP_NAMESTRING,
  777                     (UINT64) ACPI_TO_INTEGER (PredicateValueName));
  778                 NewOp->Asl.Next = Predicate;
  779                 TrAmlInitLineNumbers (NewOp, Predicate);
  780 
  781                 NewOp2              = TrCreateLeafOp (PARSEOP_LEQUAL);
  782                 NewOp2->Asl.Parent  = Conditional;
  783                 NewOp2->Asl.Child   = NewOp;
  784                 TrAmlInitLineNumbers (NewOp2, Conditional);
  785 
  786                 TrAmlSetSubtreeParent (NewOp, NewOp2);
  787 
  788                 Predicate           = NewOp2;
  789                 Predicate->Asl.Next = CaseBlock;
  790 
  791                 TrAmlSetSubtreeParent (Predicate, Conditional);
  792                 Conditional->Asl.Child = Predicate;
  793             }
  794 
  795             /* Reinitialize the CASE node to an IF node */
  796 
  797             TrAmlInitNode (Conditional, PARSEOP_IF);
  798 
  799             /*
  800              * The first CASE(IF) is not nested under an ELSE.
  801              * All other CASEs are children of a parent ELSE.
  802              */
  803             if (CurrentParentNode == StartNode)
  804             {
  805                 Conditional->Asl.Next = NULL;
  806             }
  807             else
  808             {
  809                 /*
  810                  * The IF is a child of previous IF/ELSE. It
  811                  * is therefore without peer.
  812                  */
  813                 CurrentParentNode->Asl.Child = Conditional;
  814                 Conditional->Asl.Parent      = CurrentParentNode;
  815                 Conditional->Asl.Next        = NULL;
  816             }
  817         }
  818         else if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT)
  819         {
  820             if (DefaultOp)
  821             {
  822                 /*
  823                  * More than one Default
  824                  * (Parser does not catch this, must check here)
  825                  */
  826                 AslError (ASL_ERROR, ASL_MSG_MULTIPLE_DEFAULT, Next, NULL);
  827             }
  828             else
  829             {
  830                 /* Save the DEFAULT node for later, after CASEs */
  831 
  832                 DefaultOp = Next;
  833             }
  834         }
  835         else
  836         {
  837             /* Unknown peer opcode */
  838 
  839             AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n",
  840                 Next->Asl.ParseOpName, Next->Asl.ParseOpcode);
  841         }
  842     }
  843 
  844     /* Add the default case at the end of the if/else construct */
  845 
  846     if (DefaultOp)
  847     {
  848         /* If no CASE statements, this is an error - see below */
  849 
  850         if (CaseOp)
  851         {
  852             /* Convert the DEFAULT node to an ELSE */
  853 
  854             TrAmlInitNode (DefaultOp, PARSEOP_ELSE);
  855             DefaultOp->Asl.Parent = Conditional->Asl.Parent;
  856 
  857             /* Link ELSE node as a peer to the previous IF */
  858 
  859             TrAmlInsertPeer (Conditional, DefaultOp);
  860         }
  861     }
  862 
  863     if (!CaseOp)
  864     {
  865         AslError (ASL_ERROR, ASL_MSG_NO_CASES, StartNode, NULL);
  866     }
  867 
  868 
  869     /*
  870      * Create a Name(_T_x, ...) statement. This statement must appear at the
  871      * method level, in case a loop surrounds the switch statement and could
  872      * cause the name to be created twice (error).
  873      */
  874 
  875     /* Create the Name node */
  876 
  877     Predicate = StartNode->Asl.Child;
  878     NewOp = TrCreateLeafOp (PARSEOP_NAME);
  879     TrAmlInitLineNumbers (NewOp, StartNode);
  880 
  881     /* Find the parent method */
  882 
  883     Next = StartNode;
  884     while ((Next->Asl.ParseOpcode != PARSEOP_METHOD) &&
  885            (Next->Asl.ParseOpcode != PARSEOP_DEFINITION_BLOCK))
  886     {
  887         Next = Next->Asl.Parent;
  888     }
  889     MethodOp = Next;
  890 
  891     NewOp->Asl.CompileFlags |= OP_COMPILER_EMITTED;
  892     NewOp->Asl.Parent = Next;
  893 
  894     /* Insert name after the method name and arguments */
  895 
  896     Next = Next->Asl.Child; /* Name */
  897     Next = Next->Asl.Next;  /* NumArgs */
  898     Next = Next->Asl.Next;  /* SerializeRule */
  899 
  900     /*
  901      * If method is not Serialized, we must make is so, because of the way
  902      * that Switch() must be implemented -- we cannot allow multiple threads
  903      * to execute this method concurrently since we need to create local
  904      * temporary name(s).
  905      */
  906     if (Next->Asl.ParseOpcode != PARSEOP_SERIALIZERULE_SERIAL)
  907     {
  908         AslError (ASL_REMARK, ASL_MSG_SERIALIZED, MethodOp,
  909             "Due to use of Switch operator");
  910         Next->Asl.ParseOpcode = PARSEOP_SERIALIZERULE_SERIAL;
  911     }
  912 
  913     Next = Next->Asl.Next;  /* SyncLevel */
  914     Next = Next->Asl.Next;  /* ReturnType */
  915     Next = Next->Asl.Next;  /* ParameterTypes */
  916 
  917     TrAmlInsertPeer (Next, NewOp);
  918     TrAmlInitLineNumbers (NewOp, Next);
  919 
  920     /* Create the NameSeg child for the Name node */
  921 
  922     NewOp2 = TrCreateValuedLeafOp (PARSEOP_NAMESEG,
  923         (UINT64) ACPI_TO_INTEGER (PredicateValueName));
  924     TrAmlInitLineNumbers (NewOp2, NewOp);
  925     NewOp2->Asl.CompileFlags |= OP_IS_NAME_DECLARATION;
  926     NewOp->Asl.Child  = NewOp2;
  927 
  928     /* Create the initial value for the Name. Btype was already validated above */
  929 
  930     switch (Btype)
  931     {
  932     case ACPI_BTYPE_INTEGER:
  933 
  934         NewOp2->Asl.Next = TrCreateValuedLeafOp (PARSEOP_ZERO,
  935             (UINT64) 0);
  936         TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
  937         break;
  938 
  939     case ACPI_BTYPE_STRING:
  940 
  941         NewOp2->Asl.Next = TrCreateValuedLeafOp (PARSEOP_STRING_LITERAL,
  942             (UINT64) ACPI_TO_INTEGER (""));
  943         TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
  944         break;
  945 
  946     case ACPI_BTYPE_BUFFER:
  947 
  948         (void) TrLinkPeerOp (NewOp2, TrCreateValuedLeafOp (PARSEOP_BUFFER,
  949             (UINT64) 0));
  950         Next = NewOp2->Asl.Next;
  951         TrAmlInitLineNumbers (Next, NewOp2);
  952 
  953         (void) TrLinkOpChildren (Next, 1, TrCreateValuedLeafOp (PARSEOP_ZERO,
  954             (UINT64) 1));
  955         TrAmlInitLineNumbers (Next->Asl.Child, Next);
  956 
  957         BufferOp = TrCreateValuedLeafOp (PARSEOP_DEFAULT_ARG, (UINT64) 0);
  958         TrAmlInitLineNumbers (BufferOp, Next->Asl.Child);
  959         (void) TrLinkPeerOp (Next->Asl.Child, BufferOp);
  960 
  961         TrAmlSetSubtreeParent (Next->Asl.Child, Next);
  962         break;
  963 
  964     default:
  965 
  966         break;
  967     }
  968 
  969     TrAmlSetSubtreeParent (NewOp2, NewOp);
  970 
  971     /*
  972      * Transform the Switch() into a While(One)-Break node.
  973      * And create a Store() node which will be used to save the
  974      * Switch() value. The store is of the form: Store (Value, _T_x)
  975      * where _T_x is the temp variable.
  976      */
  977     TrAmlInitNode (StartNode, PARSEOP_WHILE);
  978     NewOp = TrCreateLeafOp (PARSEOP_ONE);
  979     TrAmlInitLineNumbers (NewOp, StartNode);
  980     NewOp->Asl.Next = Predicate->Asl.Next;
  981     NewOp->Asl.Parent = StartNode;
  982     StartNode->Asl.Child = NewOp;
  983 
  984     /* Create a Store() node */
  985 
  986     StoreOp = TrCreateLeafOp (PARSEOP_STORE);
  987     TrAmlInitLineNumbers (StoreOp, NewOp);
  988     StoreOp->Asl.Parent = StartNode;
  989     TrAmlInsertPeer (NewOp, StoreOp);
  990 
  991     /* Complete the Store subtree */
  992 
  993     StoreOp->Asl.Child = Predicate;
  994     Predicate->Asl.Parent = StoreOp;
  995 
  996     NewOp = TrCreateValuedLeafOp (PARSEOP_NAMESEG,
  997         (UINT64) ACPI_TO_INTEGER (PredicateValueName));
  998     TrAmlInitLineNumbers (NewOp, StoreOp);
  999     NewOp->Asl.Parent    = StoreOp;
 1000     Predicate->Asl.Next  = NewOp;
 1001 
 1002     /* Create a Break() node and insert it into the end of While() */
 1003 
 1004     Conditional = StartNode->Asl.Child;
 1005     while (Conditional->Asl.Next)
 1006     {
 1007         Conditional = Conditional->Asl.Next;
 1008     }
 1009 
 1010     BreakOp = TrCreateLeafOp (PARSEOP_BREAK);
 1011     TrAmlInitLineNumbers (BreakOp, NewOp);
 1012     BreakOp->Asl.Parent = StartNode;
 1013     TrAmlInsertPeer (Conditional, BreakOp);
 1014 }
 1015 
 1016 
 1017 /*******************************************************************************
 1018  *
 1019  * FUNCTION:    TrCheckForDuplicateCase
 1020  *
 1021  * PARAMETERS:  CaseOp          - Parse node for first Case statement in list
 1022  *              Predicate1      - Case value for the input CaseOp
 1023  *
 1024  * RETURN:      None
 1025  *
 1026  * DESCRIPTION: Check for duplicate case values. Currently, only handles
 1027  *              Integers, Strings and Buffers. No support for Package objects.
 1028  *
 1029  ******************************************************************************/
 1030 
 1031 static void
 1032 TrCheckForDuplicateCase (
 1033     ACPI_PARSE_OBJECT       *CaseOp,
 1034     ACPI_PARSE_OBJECT       *Predicate1)
 1035 {
 1036     ACPI_PARSE_OBJECT       *Next;
 1037     ACPI_PARSE_OBJECT       *Predicate2;
 1038 
 1039 
 1040     /* Walk the list of CASE opcodes */
 1041 
 1042     Next = CaseOp->Asl.Next;
 1043     while (Next)
 1044     {
 1045         if (Next->Asl.ParseOpcode == PARSEOP_CASE)
 1046         {
 1047             /* Emit error only once */
 1048 
 1049             if (Next->Asl.CompileFlags & OP_IS_DUPLICATE)
 1050             {
 1051                 goto NextCase;
 1052             }
 1053 
 1054             /* Check for a duplicate plain integer */
 1055 
 1056             Predicate2 = Next->Asl.Child;
 1057             if ((Predicate1->Asl.ParseOpcode == PARSEOP_INTEGER) &&
 1058                 (Predicate2->Asl.ParseOpcode == PARSEOP_INTEGER))
 1059             {
 1060                 if (Predicate1->Asl.Value.Integer == Predicate2->Asl.Value.Integer)
 1061                 {
 1062                     goto FoundDuplicate;
 1063                 }
 1064             }
 1065 
 1066             /* Check for pairs of the constants ZERO, ONE, ONES */
 1067 
 1068             else if (((Predicate1->Asl.ParseOpcode == PARSEOP_ZERO) &&
 1069                 (Predicate2->Asl.ParseOpcode == PARSEOP_ZERO)) ||
 1070                 ((Predicate1->Asl.ParseOpcode == PARSEOP_ONE) &&
 1071                 (Predicate2->Asl.ParseOpcode == PARSEOP_ONE)) ||
 1072                 ((Predicate1->Asl.ParseOpcode == PARSEOP_ONES) &&
 1073                 (Predicate2->Asl.ParseOpcode == PARSEOP_ONES)))
 1074             {
 1075                 goto FoundDuplicate;
 1076             }
 1077 
 1078             /* Check for a duplicate string constant (literal) */
 1079 
 1080             else if ((Predicate1->Asl.ParseOpcode == PARSEOP_STRING_LITERAL) &&
 1081                 (Predicate2->Asl.ParseOpcode == PARSEOP_STRING_LITERAL))
 1082             {
 1083                 if (!strcmp (Predicate1->Asl.Value.String,
 1084                         Predicate2->Asl.Value.String))
 1085                 {
 1086                     goto FoundDuplicate;
 1087                 }
 1088             }
 1089 
 1090             /* Check for a duplicate buffer constant */
 1091 
 1092             else if ((Predicate1->Asl.ParseOpcode == PARSEOP_BUFFER) &&
 1093                 (Predicate2->Asl.ParseOpcode == PARSEOP_BUFFER))
 1094             {
 1095                 if (TrCheckForBufferMatch (Predicate1->Asl.Child,
 1096                         Predicate2->Asl.Child))
 1097                 {
 1098                     goto FoundDuplicate;
 1099                 }
 1100             }
 1101         }
 1102         goto NextCase;
 1103 
 1104 FoundDuplicate:
 1105         /* Emit error message only once */
 1106 
 1107         Next->Asl.CompileFlags |= OP_IS_DUPLICATE;
 1108 
 1109         AslDualParseOpError (ASL_ERROR, ASL_MSG_DUPLICATE_CASE, Next,
 1110             Next->Asl.Value.String, ASL_MSG_CASE_FOUND_HERE, CaseOp,
 1111             CaseOp->Asl.ExternalName);
 1112 
 1113 NextCase:
 1114         Next = Next->Asl.Next;
 1115     }
 1116 }
 1117 
 1118 /*******************************************************************************
 1119  *
 1120  * FUNCTION:    TrBufferIsAllZero
 1121  *
 1122  * PARAMETERS:  Op          - Parse node for first opcode in buffer initializer
 1123  *                            list
 1124  *
 1125  * RETURN:      TRUE if buffer contains all zeros or a DEFAULT_ARG
 1126  *
 1127  * DESCRIPTION: Check for duplicate Buffer case values.
 1128  *
 1129  ******************************************************************************/
 1130 
 1131 static BOOLEAN
 1132 TrBufferIsAllZero (
 1133     ACPI_PARSE_OBJECT       *Op)
 1134 {
 1135     while (Op)
 1136     {
 1137         if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
 1138         {
 1139             return (TRUE);
 1140         }
 1141         else if (Op->Asl.Value.Integer != 0)
 1142         {
 1143             return (FALSE);
 1144         }
 1145 
 1146         Op = Op->Asl.Next;
 1147     }
 1148 
 1149     return (TRUE);
 1150 }
 1151 
 1152 
 1153 /*******************************************************************************
 1154  *
 1155  * FUNCTION:    TrCheckForBufferMatch
 1156  *
 1157  * PARAMETERS:  Next1       - Parse node for first opcode in first buffer list
 1158  *                              (The DEFAULT_ARG or INTEGER node)
 1159  *              Next2       - Parse node for first opcode in second buffer list
 1160  *                              (The DEFAULT_ARG or INTEGER node)
 1161  *
 1162  * RETURN:      TRUE if buffers match, FALSE otherwise
 1163  *
 1164  * DESCRIPTION: Check for duplicate Buffer case values.
 1165  *
 1166  ******************************************************************************/
 1167 
 1168 static BOOLEAN
 1169 TrCheckForBufferMatch (
 1170     ACPI_PARSE_OBJECT       *NextOp1,
 1171     ACPI_PARSE_OBJECT       *NextOp2)
 1172 {
 1173     /*
 1174      * The buffer length can be a DEFAULT_ARG or INTEGER. If any of the nodes
 1175      * are DEFAULT_ARG, it means that the length has yet to be computed.
 1176      * However, the initializer list can be compared to determine if these two
 1177      * buffers match.
 1178      */
 1179     if ((NextOp1->Asl.ParseOpcode == PARSEOP_INTEGER &&
 1180         NextOp2->Asl.ParseOpcode == PARSEOP_INTEGER) &&
 1181         NextOp1->Asl.Value.Integer != NextOp2->Asl.Value.Integer)
 1182     {
 1183         return (FALSE);
 1184     }
 1185 
 1186     /*
 1187      * Buffers that have explicit lengths but no initializer lists are
 1188      * filled with zeros at runtime. This is equivalent to buffers that have the
 1189      * same length that are filled with zeros.
 1190      *
 1191      * In other words, the following buffers are equivalent:
 1192      *
 1193      * Buffer(0x4) {}
 1194      * Buffer() {0x0, 0x0, 0x0, 0x0}
 1195      *
 1196      * This statement checks for matches where one buffer does not have an
 1197      * initializer list and another buffer contains all zeros.
 1198      */
 1199     if (NextOp1->Asl.ParseOpcode != NextOp2->Asl.ParseOpcode &&
 1200         TrBufferIsAllZero (NextOp1->Asl.Next) &&
 1201         TrBufferIsAllZero (NextOp2->Asl.Next))
 1202     {
 1203         return (TRUE);
 1204     }
 1205 
 1206     /* Start at the BYTECONST initializer node list */
 1207 
 1208     NextOp1 = NextOp1->Asl.Next;
 1209     NextOp2 = NextOp2->Asl.Next;
 1210 
 1211     /*
 1212      * Walk both lists until either a mismatch is found, or one or more
 1213      * end-of-lists are found
 1214      */
 1215     while (NextOp1 && NextOp2)
 1216     {
 1217         if ((NextOp1->Asl.ParseOpcode == PARSEOP_STRING_LITERAL) &&
 1218             (NextOp2->Asl.ParseOpcode == PARSEOP_STRING_LITERAL))
 1219         {
 1220             if (!strcmp (NextOp1->Asl.Value.String, NextOp2->Asl.Value.String))
 1221             {
 1222                 return (TRUE);
 1223             }
 1224             else
 1225             {
 1226                 return (FALSE);
 1227             }
 1228         }
 1229         if ((UINT8) NextOp1->Asl.Value.Integer != (UINT8) NextOp2->Asl.Value.Integer)
 1230         {
 1231             return (FALSE);
 1232         }
 1233 
 1234         NextOp1 = NextOp1->Asl.Next;
 1235         NextOp2 = NextOp2->Asl.Next;
 1236     }
 1237 
 1238     /* Not a match if one of the lists is not at end-of-list */
 1239 
 1240     if (NextOp1 || NextOp2)
 1241     {
 1242         return (FALSE);
 1243     }
 1244 
 1245     /* Otherwise, the buffers match */
 1246 
 1247     return (TRUE);
 1248 }
 1249 
 1250 
 1251 /*******************************************************************************
 1252  *
 1253  * FUNCTION:    TrDoMethod
 1254  *
 1255  * PARAMETERS:  Op               - Parse node for SWITCH
 1256  *
 1257  * RETURN:      None
 1258  *
 1259  * DESCRIPTION: Determine that parameter count of an ASL method node by
 1260  *              translating the parameter count parse node from
 1261  *              PARSEOP_DEFAULT_ARG to PARSEOP_BYTECONST.
 1262  *
 1263  ******************************************************************************/
 1264 
 1265 static void
 1266 TrDoMethod (
 1267     ACPI_PARSE_OBJECT       *Op)
 1268 {
 1269     ACPI_PARSE_OBJECT           *ArgCountOp;
 1270     UINT8                       ArgCount;
 1271     ACPI_PARSE_OBJECT           *ParameterOp;
 1272 
 1273 
 1274     /*
 1275      * TBD: Zero the tempname (_T_x) count. Probably shouldn't be a global,
 1276      * however
 1277      */
 1278     AslGbl_TempCount = 0;
 1279 
 1280     ArgCountOp = Op->Asl.Child->Asl.Next;
 1281     if (ArgCountOp->Asl.ParseOpcode == PARSEOP_BYTECONST)
 1282     {
 1283         /*
 1284          * Parameter count for this method has already been recorded in the
 1285          * method declaration.
 1286          */
 1287         return;
 1288     }
 1289 
 1290     /*
 1291      * Parameter count has been omitted in the method declaration.
 1292      * Count the amount of arguments here.
 1293      */
 1294     ParameterOp = ArgCountOp->Asl.Next->Asl.Next->Asl.Next->Asl.Next;
 1295     if (ParameterOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
 1296     {
 1297         ArgCount = 0;
 1298         ParameterOp = ParameterOp->Asl.Child;
 1299 
 1300         while (ParameterOp)
 1301         {
 1302             ParameterOp = ParameterOp->Asl.Next;
 1303             ArgCount++;
 1304         }
 1305 
 1306         ArgCountOp->Asl.Value.Integer = ArgCount;
 1307         ArgCountOp->Asl.ParseOpcode = PARSEOP_BYTECONST;
 1308     }
 1309     else
 1310     {
 1311         /*
 1312          * Method parameters can be counted by analyzing the Parameter type
 1313          * list. If the Parameter list contains more than 1 parameter, it
 1314          * is nested under PARSEOP_DEFAULT_ARG. When there is only 1
 1315          * parameter, the parse tree contains a single node representing
 1316          * that type.
 1317          */
 1318         ArgCountOp->Asl.Value.Integer = 1;
 1319         ArgCountOp->Asl.ParseOpcode = PARSEOP_BYTECONST;
 1320     }
 1321 }

Cache object: 4efdcb48d0c6c25ea85869d91167c24f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.