1f8146b88SJung-uk Kim /****************************************************************************** 2f8146b88SJung-uk Kim * 3f8146b88SJung-uk Kim * Module Name: aslexternal - ASL External opcode compiler support 4f8146b88SJung-uk Kim * 5f8146b88SJung-uk Kim *****************************************************************************/ 6f8146b88SJung-uk Kim 70d84335fSJung-uk Kim /****************************************************************************** 80d84335fSJung-uk Kim * 90d84335fSJung-uk Kim * 1. Copyright Notice 100d84335fSJung-uk Kim * 11f425b8beSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp. 12f8146b88SJung-uk Kim * All rights reserved. 13f8146b88SJung-uk Kim * 140d84335fSJung-uk Kim * 2. License 150d84335fSJung-uk Kim * 160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 190d84335fSJung-uk Kim * property rights. 200d84335fSJung-uk Kim * 210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 270d84335fSJung-uk Kim * 280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 360d84335fSJung-uk Kim * 370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 380d84335fSJung-uk Kim * conditions are met: 390d84335fSJung-uk Kim * 400d84335fSJung-uk Kim * 3. Conditions 410d84335fSJung-uk Kim * 420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 530d84335fSJung-uk Kim * 540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 640d84335fSJung-uk Kim * make. 650d84335fSJung-uk Kim * 660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 700d84335fSJung-uk Kim * distribution. 710d84335fSJung-uk Kim * 720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 730d84335fSJung-uk Kim * Intel Code. 740d84335fSJung-uk Kim * 750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 780d84335fSJung-uk Kim * without prior written authorization from Intel. 790d84335fSJung-uk Kim * 800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 810d84335fSJung-uk Kim * 820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 880d84335fSJung-uk Kim * PARTICULAR PURPOSE. 890d84335fSJung-uk Kim * 900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 970d84335fSJung-uk Kim * LIMITED REMEDY. 980d84335fSJung-uk Kim * 990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 1120d84335fSJung-uk Kim * such license, approval or letter. 1130d84335fSJung-uk Kim * 1140d84335fSJung-uk Kim ***************************************************************************** 1150d84335fSJung-uk Kim * 1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 1170d84335fSJung-uk Kim * following license: 1180d84335fSJung-uk Kim * 119f8146b88SJung-uk Kim * Redistribution and use in source and binary forms, with or without 120f8146b88SJung-uk Kim * modification, are permitted provided that the following conditions 121f8146b88SJung-uk Kim * are met: 122f8146b88SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 123f8146b88SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 124f8146b88SJung-uk Kim * without modification. 125f8146b88SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126f8146b88SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 127f8146b88SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 128f8146b88SJung-uk Kim * including a substantially similar Disclaimer requirement for further 129f8146b88SJung-uk Kim * binary redistribution. 130f8146b88SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 131f8146b88SJung-uk Kim * of any contributors may be used to endorse or promote products derived 132f8146b88SJung-uk Kim * from this software without specific prior written permission. 133f8146b88SJung-uk Kim * 1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1450d84335fSJung-uk Kim * 1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 147f8146b88SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 148f8146b88SJung-uk Kim * Software Foundation. 149f8146b88SJung-uk Kim * 1500d84335fSJung-uk Kim *****************************************************************************/ 151f8146b88SJung-uk Kim 152f8146b88SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 153f8146b88SJung-uk Kim #include "aslcompiler.y.h" 154f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h> 155f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h> 156f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h> 157f8146b88SJung-uk Kim 158f8146b88SJung-uk Kim 159f8146b88SJung-uk Kim #define _COMPONENT ACPI_COMPILER 160f8146b88SJung-uk Kim ACPI_MODULE_NAME ("aslexternal") 161f8146b88SJung-uk Kim 162f8146b88SJung-uk Kim 163f8146b88SJung-uk Kim /* Local prototypes */ 164f8146b88SJung-uk Kim 165f8146b88SJung-uk Kim static void 166f8146b88SJung-uk Kim ExInsertArgCount ( 167f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op); 168f8146b88SJung-uk Kim 169f8146b88SJung-uk Kim static void 170f8146b88SJung-uk Kim ExMoveExternals ( 171f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *DefinitionBlockOp); 172f8146b88SJung-uk Kim 173f8146b88SJung-uk Kim 174f8146b88SJung-uk Kim /******************************************************************************* 175f8146b88SJung-uk Kim * 176f8146b88SJung-uk Kim * FUNCTION: ExDoExternal 177f8146b88SJung-uk Kim * 178f8146b88SJung-uk Kim * PARAMETERS: Op - Current Parse node 179f8146b88SJung-uk Kim * 180f8146b88SJung-uk Kim * RETURN: None 181f8146b88SJung-uk Kim * 182f8146b88SJung-uk Kim * DESCRIPTION: Add an External() definition to the global list. This list 183f8146b88SJung-uk Kim * is used to generate External opcodes. 184f8146b88SJung-uk Kim * 185f8146b88SJung-uk Kim ******************************************************************************/ 186f8146b88SJung-uk Kim 187f8146b88SJung-uk Kim void 188f8146b88SJung-uk Kim ExDoExternal ( 189f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op) 190f8146b88SJung-uk Kim { 191f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *ListOp; 192f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Prev; 193f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Next; 194f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *ArgCountOp; 195*ec0234b4SJung-uk Kim ACPI_PARSE_OBJECT *TypeOp; 196*ec0234b4SJung-uk Kim ACPI_PARSE_OBJECT *ExternTypeOp = Op->Asl.Child->Asl.Next; 197*ec0234b4SJung-uk Kim UINT32 ExternType; 198*ec0234b4SJung-uk Kim UINT8 ParamCount = ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS; 199*ec0234b4SJung-uk Kim UINT32 ParamTypes[ACPI_METHOD_NUM_ARGS]; 200f8146b88SJung-uk Kim 201f8146b88SJung-uk Kim 202*ec0234b4SJung-uk Kim ExternType = AnMapObjTypeToBtype (ExternTypeOp); 203*ec0234b4SJung-uk Kim 204*ec0234b4SJung-uk Kim /* 205*ec0234b4SJung-uk Kim * The parser allows optional parameter return types regardless of the 206*ec0234b4SJung-uk Kim * type. Check object type keyword emit error if optional parameter/return 207*ec0234b4SJung-uk Kim * types exist. 208*ec0234b4SJung-uk Kim * 209*ec0234b4SJung-uk Kim * Check the parameter return type 210*ec0234b4SJung-uk Kim */ 211*ec0234b4SJung-uk Kim TypeOp = ExternTypeOp->Asl.Next; 212*ec0234b4SJung-uk Kim if (TypeOp->Asl.Child) 213*ec0234b4SJung-uk Kim { 214*ec0234b4SJung-uk Kim /* Ignore the return type for now. */ 215*ec0234b4SJung-uk Kim 216*ec0234b4SJung-uk Kim (void) MtProcessTypeOp (TypeOp->Asl.Child); 217*ec0234b4SJung-uk Kim if (ExternType != ACPI_BTYPE_METHOD) 218*ec0234b4SJung-uk Kim { 219*ec0234b4SJung-uk Kim sprintf (AslGbl_MsgBuffer, "Found type [%s]", AcpiUtGetTypeName(ExternType)); 220*ec0234b4SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_EXTERN_INVALID_RET_TYPE, TypeOp, 221*ec0234b4SJung-uk Kim AslGbl_MsgBuffer); 222*ec0234b4SJung-uk Kim } 223*ec0234b4SJung-uk Kim } 224*ec0234b4SJung-uk Kim 225*ec0234b4SJung-uk Kim /* Check the parameter types */ 226*ec0234b4SJung-uk Kim 227*ec0234b4SJung-uk Kim TypeOp = TypeOp->Asl.Next; 228*ec0234b4SJung-uk Kim if (TypeOp->Asl.Child) 229*ec0234b4SJung-uk Kim { 230*ec0234b4SJung-uk Kim ParamCount = MtProcessParameterTypeList (TypeOp->Asl.Child, ParamTypes); 231*ec0234b4SJung-uk Kim if (ExternType != ACPI_BTYPE_METHOD) 232*ec0234b4SJung-uk Kim { 233*ec0234b4SJung-uk Kim sprintf (AslGbl_MsgBuffer, "Found type [%s]", AcpiUtGetTypeName(ExternType)); 234*ec0234b4SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_EXTERN_INVALID_PARAM_TYPE, TypeOp, 235*ec0234b4SJung-uk Kim AslGbl_MsgBuffer); 236*ec0234b4SJung-uk Kim } 237*ec0234b4SJung-uk Kim } 238*ec0234b4SJung-uk Kim 239f8146b88SJung-uk Kim ArgCountOp = Op->Asl.Child->Asl.Next->Asl.Next; 240f8146b88SJung-uk Kim ArgCountOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE; 241f8146b88SJung-uk Kim ArgCountOp->Asl.ParseOpcode = PARSEOP_BYTECONST; 242*ec0234b4SJung-uk Kim ArgCountOp->Asl.Value.Integer = ParamCount; 243f8146b88SJung-uk Kim UtSetParseOpName (ArgCountOp); 244f8146b88SJung-uk Kim 245f8146b88SJung-uk Kim /* Create new list node of arbitrary type */ 246f8146b88SJung-uk Kim 2475f9b24faSJung-uk Kim ListOp = TrAllocateOp (PARSEOP_DEFAULT_ARG); 248f8146b88SJung-uk Kim 249f8146b88SJung-uk Kim /* Store External node as child */ 250f8146b88SJung-uk Kim 251f8146b88SJung-uk Kim ListOp->Asl.Child = Op; 252f8146b88SJung-uk Kim ListOp->Asl.Next = NULL; 253f8146b88SJung-uk Kim 2546f1f1a63SJung-uk Kim if (AslGbl_ExternalsListHead) 255f8146b88SJung-uk Kim { 256f8146b88SJung-uk Kim /* Link new External to end of list */ 257f8146b88SJung-uk Kim 2586f1f1a63SJung-uk Kim Prev = AslGbl_ExternalsListHead; 259f8146b88SJung-uk Kim Next = Prev; 260f8146b88SJung-uk Kim while (Next) 261f8146b88SJung-uk Kim { 262f8146b88SJung-uk Kim Prev = Next; 263f8146b88SJung-uk Kim Next = Next->Asl.Next; 264f8146b88SJung-uk Kim } 265f8146b88SJung-uk Kim 266f8146b88SJung-uk Kim Prev->Asl.Next = ListOp; 267f8146b88SJung-uk Kim } 268f8146b88SJung-uk Kim else 269f8146b88SJung-uk Kim { 2706f1f1a63SJung-uk Kim AslGbl_ExternalsListHead = ListOp; 271f8146b88SJung-uk Kim } 272f8146b88SJung-uk Kim } 273f8146b88SJung-uk Kim 274f8146b88SJung-uk Kim 275f8146b88SJung-uk Kim /******************************************************************************* 276f8146b88SJung-uk Kim * 277f8146b88SJung-uk Kim * FUNCTION: ExInsertArgCount 278f8146b88SJung-uk Kim * 279f8146b88SJung-uk Kim * PARAMETERS: Op - Op for a method invocation 280f8146b88SJung-uk Kim * 281f8146b88SJung-uk Kim * RETURN: None 282f8146b88SJung-uk Kim * 283f8146b88SJung-uk Kim * DESCRIPTION: Obtain the number of arguments for a control method -- from 284f8146b88SJung-uk Kim * the actual invocation. 285f8146b88SJung-uk Kim * 286f8146b88SJung-uk Kim ******************************************************************************/ 287f8146b88SJung-uk Kim 288f8146b88SJung-uk Kim static void 289f8146b88SJung-uk Kim ExInsertArgCount ( 290f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op) 291f8146b88SJung-uk Kim { 292f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Next; 293f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *NameOp; 294f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Child; 295f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *ArgCountOp; 296f8146b88SJung-uk Kim char * ExternalName; 297f8146b88SJung-uk Kim char * CallName; 298f8146b88SJung-uk Kim UINT16 ArgCount = 0; 299f8146b88SJung-uk Kim ACPI_STATUS Status; 300f8146b88SJung-uk Kim 301f8146b88SJung-uk Kim 302f8146b88SJung-uk Kim CallName = AcpiNsGetNormalizedPathname (Op->Asl.Node, TRUE); 303f8146b88SJung-uk Kim 3046f1f1a63SJung-uk Kim Next = AslGbl_ExternalsListHead; 305f8146b88SJung-uk Kim while (Next) 306f8146b88SJung-uk Kim { 307f8146b88SJung-uk Kim ArgCount = 0; 308f8146b88SJung-uk Kim 309f8146b88SJung-uk Kim /* Skip if External node already handled */ 310f8146b88SJung-uk Kim 3115f9b24faSJung-uk Kim if (Next->Asl.Child->Asl.CompileFlags & OP_VISITED) 312f8146b88SJung-uk Kim { 313f8146b88SJung-uk Kim Next = Next->Asl.Next; 314f8146b88SJung-uk Kim continue; 315f8146b88SJung-uk Kim } 316f8146b88SJung-uk Kim 317f8146b88SJung-uk Kim NameOp = Next->Asl.Child->Asl.Child; 318f8146b88SJung-uk Kim ExternalName = AcpiNsGetNormalizedPathname (NameOp->Asl.Node, TRUE); 319f8146b88SJung-uk Kim 320f8146b88SJung-uk Kim if (strcmp (CallName, ExternalName)) 321f8146b88SJung-uk Kim { 322f8146b88SJung-uk Kim ACPI_FREE (ExternalName); 323f8146b88SJung-uk Kim Next = Next->Asl.Next; 324f8146b88SJung-uk Kim continue; 325f8146b88SJung-uk Kim } 326f8146b88SJung-uk Kim 3275f9b24faSJung-uk Kim Next->Asl.Child->Asl.CompileFlags |= OP_VISITED; 328f8146b88SJung-uk Kim 329f8146b88SJung-uk Kim /* 330f8146b88SJung-uk Kim * Since we will reposition Externals to the Root, set Namepath 331f8146b88SJung-uk Kim * to the fully qualified name and recalculate the aml length 332f8146b88SJung-uk Kim */ 333f8146b88SJung-uk Kim Status = UtInternalizeName (ExternalName, 334f8146b88SJung-uk Kim &NameOp->Asl.Value.String); 335f8146b88SJung-uk Kim 336f8146b88SJung-uk Kim ACPI_FREE (ExternalName); 337f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 338f8146b88SJung-uk Kim { 339f8146b88SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, 340f8146b88SJung-uk Kim NULL, "- Could not Internalize External"); 341f8146b88SJung-uk Kim break; 342f8146b88SJung-uk Kim } 343f8146b88SJung-uk Kim 344f8146b88SJung-uk Kim NameOp->Asl.AmlLength = strlen (NameOp->Asl.Value.String); 345f8146b88SJung-uk Kim 346f8146b88SJung-uk Kim /* Get argument count */ 347f8146b88SJung-uk Kim 348f8146b88SJung-uk Kim Child = Op->Asl.Child; 349f8146b88SJung-uk Kim while (Child) 350f8146b88SJung-uk Kim { 351f8146b88SJung-uk Kim ArgCount++; 352f8146b88SJung-uk Kim Child = Child->Asl.Next; 353f8146b88SJung-uk Kim } 354f8146b88SJung-uk Kim 355f8146b88SJung-uk Kim /* Setup ArgCount operand */ 356f8146b88SJung-uk Kim 357f8146b88SJung-uk Kim ArgCountOp = Next->Asl.Child->Asl.Child->Asl.Next->Asl.Next; 358f8146b88SJung-uk Kim ArgCountOp->Asl.Value.Integer = ArgCount; 359f8146b88SJung-uk Kim break; 360f8146b88SJung-uk Kim } 361f8146b88SJung-uk Kim 362f8146b88SJung-uk Kim ACPI_FREE (CallName); 363f8146b88SJung-uk Kim } 364f8146b88SJung-uk Kim 365f8146b88SJung-uk Kim 366f8146b88SJung-uk Kim /******************************************************************************* 367f8146b88SJung-uk Kim * 368f8146b88SJung-uk Kim * FUNCTION: ExAmlExternalWalkBegin 369f8146b88SJung-uk Kim * 370f8146b88SJung-uk Kim * PARAMETERS: ASL_WALK_CALLBACK 371f8146b88SJung-uk Kim * 372f8146b88SJung-uk Kim * RETURN: None 373f8146b88SJung-uk Kim * 374f8146b88SJung-uk Kim * DESCRIPTION: Parse tree walk to create external opcode list for methods. 375f8146b88SJung-uk Kim * 376f8146b88SJung-uk Kim ******************************************************************************/ 377f8146b88SJung-uk Kim 378f8146b88SJung-uk Kim ACPI_STATUS 379f8146b88SJung-uk Kim ExAmlExternalWalkBegin ( 380f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op, 381f8146b88SJung-uk Kim UINT32 Level, 382f8146b88SJung-uk Kim void *Context) 383f8146b88SJung-uk Kim { 384f8146b88SJung-uk Kim 385f8146b88SJung-uk Kim /* External list head saved in the definition block op */ 386f8146b88SJung-uk Kim 387f8146b88SJung-uk Kim if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) 388f8146b88SJung-uk Kim { 3896f1f1a63SJung-uk Kim AslGbl_ExternalsListHead = Op->Asl.Value.Arg; 390f8146b88SJung-uk Kim } 391f8146b88SJung-uk Kim 3926f1f1a63SJung-uk Kim if (!AslGbl_ExternalsListHead) 393f8146b88SJung-uk Kim { 394f8146b88SJung-uk Kim return (AE_OK); 395f8146b88SJung-uk Kim } 396f8146b88SJung-uk Kim 397f8146b88SJung-uk Kim if (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) 398f8146b88SJung-uk Kim { 399f8146b88SJung-uk Kim return (AE_OK); 400f8146b88SJung-uk Kim } 401f8146b88SJung-uk Kim 402f8146b88SJung-uk Kim /* 403f8146b88SJung-uk Kim * The NameOp child under an ExternalOp gets turned into PARSE_METHODCALL 404f8146b88SJung-uk Kim * by XfNamespaceLocateBegin(). Ignore these. 405f8146b88SJung-uk Kim */ 406f8146b88SJung-uk Kim if (Op->Asl.Parent && 407f8146b88SJung-uk Kim Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_EXTERNAL) 408f8146b88SJung-uk Kim { 409f8146b88SJung-uk Kim return (AE_OK); 410f8146b88SJung-uk Kim } 411f8146b88SJung-uk Kim 412f8146b88SJung-uk Kim ExInsertArgCount (Op); 413f8146b88SJung-uk Kim return (AE_OK); 414f8146b88SJung-uk Kim } 415f8146b88SJung-uk Kim 416f8146b88SJung-uk Kim 417f8146b88SJung-uk Kim /******************************************************************************* 418f8146b88SJung-uk Kim * 419f8146b88SJung-uk Kim * FUNCTION: ExAmlExternalWalkEnd 420f8146b88SJung-uk Kim * 421f8146b88SJung-uk Kim * PARAMETERS: ASL_WALK_CALLBACK 422f8146b88SJung-uk Kim * 423f8146b88SJung-uk Kim * RETURN: None 424f8146b88SJung-uk Kim * 425f8146b88SJung-uk Kim * DESCRIPTION: Parse tree walk to create external opcode list for methods. 426f8146b88SJung-uk Kim * Here, we just want to catch the case where a definition block 427f8146b88SJung-uk Kim * has been completed. Then we move all of the externals into 428f8146b88SJung-uk Kim * a single block in the parse tree and thus the AML code. 429f8146b88SJung-uk Kim * 430f8146b88SJung-uk Kim ******************************************************************************/ 431f8146b88SJung-uk Kim 432f8146b88SJung-uk Kim ACPI_STATUS 433f8146b88SJung-uk Kim ExAmlExternalWalkEnd ( 434f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op, 435f8146b88SJung-uk Kim UINT32 Level, 436f8146b88SJung-uk Kim void *Context) 437f8146b88SJung-uk Kim { 438f8146b88SJung-uk Kim 439f8146b88SJung-uk Kim if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) 440f8146b88SJung-uk Kim { 441f8146b88SJung-uk Kim /* 442f8146b88SJung-uk Kim * Process any existing external list. (Support for 443f8146b88SJung-uk Kim * multiple definition blocks in a single file/compile) 444f8146b88SJung-uk Kim */ 445f8146b88SJung-uk Kim ExMoveExternals (Op); 4466f1f1a63SJung-uk Kim AslGbl_ExternalsListHead = NULL; 447f8146b88SJung-uk Kim } 448f8146b88SJung-uk Kim 449f8146b88SJung-uk Kim return (AE_OK); 450f8146b88SJung-uk Kim } 451f8146b88SJung-uk Kim 452f8146b88SJung-uk Kim 453f8146b88SJung-uk Kim /******************************************************************************* 454f8146b88SJung-uk Kim * 455f8146b88SJung-uk Kim * FUNCTION: ExMoveExternals 456f8146b88SJung-uk Kim * 457f8146b88SJung-uk Kim * PARAMETERS: DefinitionBlockOp - Op for current definition block 458f8146b88SJung-uk Kim * 459f8146b88SJung-uk Kim * RETURN: None 460f8146b88SJung-uk Kim * 461f8146b88SJung-uk Kim * DESCRIPTION: Move all externals present in the source file into a single 462f8146b88SJung-uk Kim * block of AML code, surrounded by an "If (0)" to prevent 463f8146b88SJung-uk Kim * AML interpreters from attempting to execute the External 464f8146b88SJung-uk Kim * opcodes. 465f8146b88SJung-uk Kim * 466f8146b88SJung-uk Kim ******************************************************************************/ 467f8146b88SJung-uk Kim 468f8146b88SJung-uk Kim static void 469f8146b88SJung-uk Kim ExMoveExternals ( 470f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *DefinitionBlockOp) 471f8146b88SJung-uk Kim { 472f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *ParentOp; 473f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *ExternalOp; 474f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *PredicateOp; 475f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *NextOp; 476f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Prev; 477f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Next; 4781cc50d6bSJung-uk Kim char *ExternalName; 479f8146b88SJung-uk Kim ACPI_OBJECT_TYPE ObjType; 480af051161SJung-uk Kim ACPI_STATUS Status; 481f8146b88SJung-uk Kim UINT32 i; 482f8146b88SJung-uk Kim 483f8146b88SJung-uk Kim 4846f1f1a63SJung-uk Kim if (!AslGbl_ExternalsListHead) 485f8146b88SJung-uk Kim { 486f8146b88SJung-uk Kim return; 487f8146b88SJung-uk Kim } 488f8146b88SJung-uk Kim 489f8146b88SJung-uk Kim /* Remove the External nodes from the tree */ 490f8146b88SJung-uk Kim 4916f1f1a63SJung-uk Kim NextOp = AslGbl_ExternalsListHead; 492f8146b88SJung-uk Kim while (NextOp) 493f8146b88SJung-uk Kim { 494f8146b88SJung-uk Kim /* 495f8146b88SJung-uk Kim * The External is stored in child pointer of each node in the 496f8146b88SJung-uk Kim * list 497f8146b88SJung-uk Kim */ 498f8146b88SJung-uk Kim ExternalOp = NextOp->Asl.Child; 499f8146b88SJung-uk Kim 5001cc50d6bSJung-uk Kim /* Get/set the fully qualified name */ 5011cc50d6bSJung-uk Kim 5021cc50d6bSJung-uk Kim ExternalName = AcpiNsGetNormalizedPathname (ExternalOp->Asl.Node, TRUE); 5031cc50d6bSJung-uk Kim ExternalOp->Asl.ExternalName = ExternalName; 5041cc50d6bSJung-uk Kim ExternalOp->Asl.Namepath = ExternalName; 5051cc50d6bSJung-uk Kim 506f8146b88SJung-uk Kim /* Set line numbers (for listings, etc.) */ 507f8146b88SJung-uk Kim 508f8146b88SJung-uk Kim ExternalOp->Asl.LineNumber = 0; 509f8146b88SJung-uk Kim ExternalOp->Asl.LogicalLineNumber = 0; 510f8146b88SJung-uk Kim 511f8146b88SJung-uk Kim Next = ExternalOp->Asl.Child; 512f8146b88SJung-uk Kim Next->Asl.LineNumber = 0; 513f8146b88SJung-uk Kim Next->Asl.LogicalLineNumber = 0; 514f8146b88SJung-uk Kim 5151cc50d6bSJung-uk Kim if (Next->Asl.ParseOpcode == PARSEOP_NAMESEG) 5161cc50d6bSJung-uk Kim { 5171cc50d6bSJung-uk Kim Next->Asl.ParseOpcode = PARSEOP_NAMESTRING; 5181cc50d6bSJung-uk Kim } 519af051161SJung-uk Kim 5201cc50d6bSJung-uk Kim Next->Asl.ExternalName = ExternalName; 521af051161SJung-uk Kim Status = UtInternalizeName (ExternalName, &Next->Asl.Value.String); 522af051161SJung-uk Kim if (ACPI_FAILURE (Status)) 523af051161SJung-uk Kim { 524af051161SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, 525af051161SJung-uk Kim Next, "Could not internalize namestring"); 526af051161SJung-uk Kim return; 527af051161SJung-uk Kim } 528af051161SJung-uk Kim 5291cc50d6bSJung-uk Kim Next->Asl.AmlLength = strlen (Next->Asl.Value.String); 5301cc50d6bSJung-uk Kim 531f8146b88SJung-uk Kim Next = Next->Asl.Next; 532f8146b88SJung-uk Kim Next->Asl.LineNumber = 0; 533f8146b88SJung-uk Kim Next->Asl.LogicalLineNumber = 0; 534f8146b88SJung-uk Kim 535f8146b88SJung-uk Kim Next = Next->Asl.Next; 536f8146b88SJung-uk Kim Next->Asl.LineNumber = 0; 537f8146b88SJung-uk Kim Next->Asl.LogicalLineNumber = 0; 538f8146b88SJung-uk Kim 539f8146b88SJung-uk Kim Next = Next->Asl.Next; 540f8146b88SJung-uk Kim Next->Asl.LineNumber = 0; 541f8146b88SJung-uk Kim Next->Asl.LogicalLineNumber = 0; 542f8146b88SJung-uk Kim 543f8146b88SJung-uk Kim ParentOp = ExternalOp->Asl.Parent; 544f8146b88SJung-uk Kim Prev = Next = ParentOp->Asl.Child; 545f8146b88SJung-uk Kim 546f8146b88SJung-uk Kim /* Now find the External node's position in parse tree */ 547f8146b88SJung-uk Kim 548f8146b88SJung-uk Kim while (Next != ExternalOp) 549f8146b88SJung-uk Kim { 550f8146b88SJung-uk Kim Prev = Next; 551f8146b88SJung-uk Kim Next = Next->Asl.Next; 552f8146b88SJung-uk Kim } 553f8146b88SJung-uk Kim 554f8146b88SJung-uk Kim /* Remove the External from the parse tree */ 555f8146b88SJung-uk Kim 556f8146b88SJung-uk Kim if (Prev == ExternalOp) 557f8146b88SJung-uk Kim { 558f8146b88SJung-uk Kim /* External was the first child node */ 559f8146b88SJung-uk Kim 560f8146b88SJung-uk Kim ParentOp->Asl.Child = ExternalOp->Asl.Next; 561f8146b88SJung-uk Kim } 562f8146b88SJung-uk Kim 563f8146b88SJung-uk Kim Prev->Asl.Next = ExternalOp->Asl.Next; 564f8146b88SJung-uk Kim ExternalOp->Asl.Next = NULL; 5656f1f1a63SJung-uk Kim ExternalOp->Asl.Parent = AslGbl_ExternalsListHead; 566f8146b88SJung-uk Kim 567f8146b88SJung-uk Kim /* Point the External to the next in the list */ 568f8146b88SJung-uk Kim 569f8146b88SJung-uk Kim if (NextOp->Asl.Next) 570f8146b88SJung-uk Kim { 571f8146b88SJung-uk Kim ExternalOp->Asl.Next = NextOp->Asl.Next->Asl.Child; 572f8146b88SJung-uk Kim } 573f8146b88SJung-uk Kim 574f8146b88SJung-uk Kim NextOp = NextOp->Asl.Next; 575f8146b88SJung-uk Kim } 576f8146b88SJung-uk Kim 577f8146b88SJung-uk Kim /* 578f8146b88SJung-uk Kim * Loop again to remove MethodObj Externals for which 579f8146b88SJung-uk Kim * a MethodCall was not found (dead external reference) 580f8146b88SJung-uk Kim */ 5816f1f1a63SJung-uk Kim Prev = AslGbl_ExternalsListHead->Asl.Child; 582f8146b88SJung-uk Kim Next = Prev; 583f8146b88SJung-uk Kim while (Next) 584f8146b88SJung-uk Kim { 585f8146b88SJung-uk Kim ObjType = (ACPI_OBJECT_TYPE) 586f8146b88SJung-uk Kim Next->Asl.Child->Asl.Next->Asl.Value.Integer; 587f8146b88SJung-uk Kim 588f8146b88SJung-uk Kim if (ObjType == ACPI_TYPE_METHOD && 5895f9b24faSJung-uk Kim !(Next->Asl.CompileFlags & OP_VISITED)) 590f8146b88SJung-uk Kim { 591f8146b88SJung-uk Kim if (Next == Prev) 592f8146b88SJung-uk Kim { 5936f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.Child = Next->Asl.Next; 594f8146b88SJung-uk Kim Next->Asl.Next = NULL; 5956f1f1a63SJung-uk Kim Prev = AslGbl_ExternalsListHead->Asl.Child; 596f8146b88SJung-uk Kim Next = Prev; 597f8146b88SJung-uk Kim continue; 598f8146b88SJung-uk Kim } 599f8146b88SJung-uk Kim else 600f8146b88SJung-uk Kim { 601f8146b88SJung-uk Kim Prev->Asl.Next = Next->Asl.Next; 602f8146b88SJung-uk Kim Next->Asl.Next = NULL; 603f8146b88SJung-uk Kim Next = Prev->Asl.Next; 604f8146b88SJung-uk Kim continue; 605f8146b88SJung-uk Kim } 606f8146b88SJung-uk Kim } 607f8146b88SJung-uk Kim 608f8146b88SJung-uk Kim Prev = Next; 609f8146b88SJung-uk Kim Next = Next->Asl.Next; 610f8146b88SJung-uk Kim } 611f8146b88SJung-uk Kim 612f8146b88SJung-uk Kim /* If list is now empty, don't bother to make If (0) block */ 613f8146b88SJung-uk Kim 6146f1f1a63SJung-uk Kim if (!AslGbl_ExternalsListHead->Asl.Child) 615f8146b88SJung-uk Kim { 616f8146b88SJung-uk Kim return; 617f8146b88SJung-uk Kim } 618f8146b88SJung-uk Kim 619f8146b88SJung-uk Kim /* Convert Gbl_ExternalsListHead parent to If(). */ 620f8146b88SJung-uk Kim 6216f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.ParseOpcode = PARSEOP_IF; 6226f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.AmlOpcode = AML_IF_OP; 6236f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.CompileFlags = OP_AML_PACKAGE; 6246f1f1a63SJung-uk Kim UtSetParseOpName (AslGbl_ExternalsListHead); 625f8146b88SJung-uk Kim 626f8146b88SJung-uk Kim /* Create a Zero op for the If predicate */ 627f8146b88SJung-uk Kim 6285f9b24faSJung-uk Kim PredicateOp = TrAllocateOp (PARSEOP_ZERO); 629f8146b88SJung-uk Kim PredicateOp->Asl.AmlOpcode = AML_ZERO_OP; 630f8146b88SJung-uk Kim 6316f1f1a63SJung-uk Kim PredicateOp->Asl.Parent = AslGbl_ExternalsListHead; 632f8146b88SJung-uk Kim PredicateOp->Asl.Child = NULL; 6336f1f1a63SJung-uk Kim PredicateOp->Asl.Next = AslGbl_ExternalsListHead->Asl.Child; 6346f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.Child = PredicateOp; 635f8146b88SJung-uk Kim 636f8146b88SJung-uk Kim /* Set line numbers (for listings, etc.) */ 637f8146b88SJung-uk Kim 6386f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.LineNumber = 0; 6396f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.LogicalLineNumber = 0; 640f8146b88SJung-uk Kim 641f8146b88SJung-uk Kim PredicateOp->Asl.LineNumber = 0; 642f8146b88SJung-uk Kim PredicateOp->Asl.LogicalLineNumber = 0; 643f8146b88SJung-uk Kim 644f8146b88SJung-uk Kim /* Insert block back in the list */ 645f8146b88SJung-uk Kim 646f8146b88SJung-uk Kim Prev = DefinitionBlockOp->Asl.Child; 647f8146b88SJung-uk Kim Next = Prev; 648f8146b88SJung-uk Kim 649f8146b88SJung-uk Kim /* Find last default arg */ 650f8146b88SJung-uk Kim 651f8146b88SJung-uk Kim for (i = 0; i < 6; i++) 652f8146b88SJung-uk Kim { 653f8146b88SJung-uk Kim Prev = Next; 654f8146b88SJung-uk Kim Next = Prev->Asl.Next; 655f8146b88SJung-uk Kim } 656f8146b88SJung-uk Kim 657f8146b88SJung-uk Kim if (Next) 658f8146b88SJung-uk Kim { 659f8146b88SJung-uk Kim /* Definition Block is not empty */ 660f8146b88SJung-uk Kim 6616f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.Next = Next; 662f8146b88SJung-uk Kim } 663f8146b88SJung-uk Kim else 664f8146b88SJung-uk Kim { 665f8146b88SJung-uk Kim /* Definition Block is empty. */ 666f8146b88SJung-uk Kim 6676f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.Next = NULL; 668f8146b88SJung-uk Kim } 669f8146b88SJung-uk Kim 6706f1f1a63SJung-uk Kim Prev->Asl.Next = AslGbl_ExternalsListHead; 6716f1f1a63SJung-uk Kim AslGbl_ExternalsListHead->Asl.Parent = Prev->Asl.Parent; 672f8146b88SJung-uk Kim } 673