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 7*0d84335fSJung-uk Kim /****************************************************************************** 8*0d84335fSJung-uk Kim * 9*0d84335fSJung-uk Kim * 1. Copyright Notice 10*0d84335fSJung-uk Kim * 11*0d84335fSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12f8146b88SJung-uk Kim * All rights reserved. 13f8146b88SJung-uk Kim * 14*0d84335fSJung-uk Kim * 2. License 15*0d84335fSJung-uk Kim * 16*0d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 17*0d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 18*0d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 19*0d84335fSJung-uk Kim * property rights. 20*0d84335fSJung-uk Kim * 21*0d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22*0d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 23*0d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24*0d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 25*0d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 26*0d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 27*0d84335fSJung-uk Kim * 28*0d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29*0d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 30*0d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 31*0d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 32*0d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 33*0d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 34*0d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 35*0d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 36*0d84335fSJung-uk Kim * 37*0d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 38*0d84335fSJung-uk Kim * conditions are met: 39*0d84335fSJung-uk Kim * 40*0d84335fSJung-uk Kim * 3. Conditions 41*0d84335fSJung-uk Kim * 42*0d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43*0d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 44*0d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 45*0d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 46*0d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 47*0d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 48*0d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 49*0d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 50*0d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 51*0d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 52*0d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 53*0d84335fSJung-uk Kim * 54*0d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55*0d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 56*0d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 57*0d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 58*0d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 59*0d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 60*0d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 61*0d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 62*0d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 63*0d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 64*0d84335fSJung-uk Kim * make. 65*0d84335fSJung-uk Kim * 66*0d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67*0d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 68*0d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 69*0d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 70*0d84335fSJung-uk Kim * distribution. 71*0d84335fSJung-uk Kim * 72*0d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 73*0d84335fSJung-uk Kim * Intel Code. 74*0d84335fSJung-uk Kim * 75*0d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76*0d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 77*0d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 78*0d84335fSJung-uk Kim * without prior written authorization from Intel. 79*0d84335fSJung-uk Kim * 80*0d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 81*0d84335fSJung-uk Kim * 82*0d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83*0d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84*0d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85*0d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86*0d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87*0d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88*0d84335fSJung-uk Kim * PARTICULAR PURPOSE. 89*0d84335fSJung-uk Kim * 90*0d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91*0d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92*0d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93*0d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94*0d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95*0d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96*0d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97*0d84335fSJung-uk Kim * LIMITED REMEDY. 98*0d84335fSJung-uk Kim * 99*0d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100*0d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 101*0d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 102*0d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 103*0d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 104*0d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 105*0d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 106*0d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 107*0d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108*0d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 109*0d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 110*0d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 111*0d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 112*0d84335fSJung-uk Kim * such license, approval or letter. 113*0d84335fSJung-uk Kim * 114*0d84335fSJung-uk Kim ***************************************************************************** 115*0d84335fSJung-uk Kim * 116*0d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 117*0d84335fSJung-uk Kim * following license: 118*0d84335fSJung-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 * 134*0d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135*0d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136*0d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137*0d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138*0d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139*0d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140*0d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141*0d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142*0d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143*0d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144*0d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145*0d84335fSJung-uk Kim * 146*0d84335fSJung-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 * 150*0d84335fSJung-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; 195f8146b88SJung-uk Kim 196f8146b88SJung-uk Kim 197f8146b88SJung-uk Kim ArgCountOp = Op->Asl.Child->Asl.Next->Asl.Next; 198f8146b88SJung-uk Kim ArgCountOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE; 199f8146b88SJung-uk Kim ArgCountOp->Asl.ParseOpcode = PARSEOP_BYTECONST; 200f8146b88SJung-uk Kim ArgCountOp->Asl.Value.Integer = 0; 201f8146b88SJung-uk Kim UtSetParseOpName (ArgCountOp); 202f8146b88SJung-uk Kim 203f8146b88SJung-uk Kim /* Create new list node of arbitrary type */ 204f8146b88SJung-uk Kim 205f8146b88SJung-uk Kim ListOp = TrAllocateNode (PARSEOP_DEFAULT_ARG); 206f8146b88SJung-uk Kim 207f8146b88SJung-uk Kim /* Store External node as child */ 208f8146b88SJung-uk Kim 209f8146b88SJung-uk Kim ListOp->Asl.Child = Op; 210f8146b88SJung-uk Kim ListOp->Asl.Next = NULL; 211f8146b88SJung-uk Kim 212f8146b88SJung-uk Kim if (Gbl_ExternalsListHead) 213f8146b88SJung-uk Kim { 214f8146b88SJung-uk Kim /* Link new External to end of list */ 215f8146b88SJung-uk Kim 216f8146b88SJung-uk Kim Prev = Gbl_ExternalsListHead; 217f8146b88SJung-uk Kim Next = Prev; 218f8146b88SJung-uk Kim while (Next) 219f8146b88SJung-uk Kim { 220f8146b88SJung-uk Kim Prev = Next; 221f8146b88SJung-uk Kim Next = Next->Asl.Next; 222f8146b88SJung-uk Kim } 223f8146b88SJung-uk Kim 224f8146b88SJung-uk Kim Prev->Asl.Next = ListOp; 225f8146b88SJung-uk Kim } 226f8146b88SJung-uk Kim else 227f8146b88SJung-uk Kim { 228f8146b88SJung-uk Kim Gbl_ExternalsListHead = ListOp; 229f8146b88SJung-uk Kim } 230f8146b88SJung-uk Kim } 231f8146b88SJung-uk Kim 232f8146b88SJung-uk Kim 233f8146b88SJung-uk Kim /******************************************************************************* 234f8146b88SJung-uk Kim * 235f8146b88SJung-uk Kim * FUNCTION: ExInsertArgCount 236f8146b88SJung-uk Kim * 237f8146b88SJung-uk Kim * PARAMETERS: Op - Op for a method invocation 238f8146b88SJung-uk Kim * 239f8146b88SJung-uk Kim * RETURN: None 240f8146b88SJung-uk Kim * 241f8146b88SJung-uk Kim * DESCRIPTION: Obtain the number of arguments for a control method -- from 242f8146b88SJung-uk Kim * the actual invocation. 243f8146b88SJung-uk Kim * 244f8146b88SJung-uk Kim ******************************************************************************/ 245f8146b88SJung-uk Kim 246f8146b88SJung-uk Kim static void 247f8146b88SJung-uk Kim ExInsertArgCount ( 248f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op) 249f8146b88SJung-uk Kim { 250f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Next; 251f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *NameOp; 252f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Child; 253f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *ArgCountOp; 254f8146b88SJung-uk Kim char * ExternalName; 255f8146b88SJung-uk Kim char * CallName; 256f8146b88SJung-uk Kim UINT16 ArgCount = 0; 257f8146b88SJung-uk Kim ACPI_STATUS Status; 258f8146b88SJung-uk Kim 259f8146b88SJung-uk Kim 260f8146b88SJung-uk Kim CallName = AcpiNsGetNormalizedPathname (Op->Asl.Node, TRUE); 261f8146b88SJung-uk Kim 262f8146b88SJung-uk Kim Next = Gbl_ExternalsListHead; 263f8146b88SJung-uk Kim while (Next) 264f8146b88SJung-uk Kim { 265f8146b88SJung-uk Kim ArgCount = 0; 266f8146b88SJung-uk Kim 267f8146b88SJung-uk Kim /* Skip if External node already handled */ 268f8146b88SJung-uk Kim 269f8146b88SJung-uk Kim if (Next->Asl.Child->Asl.CompileFlags & NODE_VISITED) 270f8146b88SJung-uk Kim { 271f8146b88SJung-uk Kim Next = Next->Asl.Next; 272f8146b88SJung-uk Kim continue; 273f8146b88SJung-uk Kim } 274f8146b88SJung-uk Kim 275f8146b88SJung-uk Kim NameOp = Next->Asl.Child->Asl.Child; 276f8146b88SJung-uk Kim ExternalName = AcpiNsGetNormalizedPathname (NameOp->Asl.Node, TRUE); 277f8146b88SJung-uk Kim 278f8146b88SJung-uk Kim if (strcmp (CallName, ExternalName)) 279f8146b88SJung-uk Kim { 280f8146b88SJung-uk Kim ACPI_FREE (ExternalName); 281f8146b88SJung-uk Kim Next = Next->Asl.Next; 282f8146b88SJung-uk Kim continue; 283f8146b88SJung-uk Kim } 284f8146b88SJung-uk Kim 285f8146b88SJung-uk Kim Next->Asl.Child->Asl.CompileFlags |= NODE_VISITED; 286f8146b88SJung-uk Kim 287f8146b88SJung-uk Kim /* 288f8146b88SJung-uk Kim * Since we will reposition Externals to the Root, set Namepath 289f8146b88SJung-uk Kim * to the fully qualified name and recalculate the aml length 290f8146b88SJung-uk Kim */ 291f8146b88SJung-uk Kim Status = UtInternalizeName (ExternalName, 292f8146b88SJung-uk Kim &NameOp->Asl.Value.String); 293f8146b88SJung-uk Kim 294f8146b88SJung-uk Kim ACPI_FREE (ExternalName); 295f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 296f8146b88SJung-uk Kim { 297f8146b88SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, 298f8146b88SJung-uk Kim NULL, "- Could not Internalize External"); 299f8146b88SJung-uk Kim break; 300f8146b88SJung-uk Kim } 301f8146b88SJung-uk Kim 302f8146b88SJung-uk Kim NameOp->Asl.AmlLength = strlen (NameOp->Asl.Value.String); 303f8146b88SJung-uk Kim 304f8146b88SJung-uk Kim /* Get argument count */ 305f8146b88SJung-uk Kim 306f8146b88SJung-uk Kim Child = Op->Asl.Child; 307f8146b88SJung-uk Kim while (Child) 308f8146b88SJung-uk Kim { 309f8146b88SJung-uk Kim ArgCount++; 310f8146b88SJung-uk Kim Child = Child->Asl.Next; 311f8146b88SJung-uk Kim } 312f8146b88SJung-uk Kim 313f8146b88SJung-uk Kim /* Setup ArgCount operand */ 314f8146b88SJung-uk Kim 315f8146b88SJung-uk Kim ArgCountOp = Next->Asl.Child->Asl.Child->Asl.Next->Asl.Next; 316f8146b88SJung-uk Kim ArgCountOp->Asl.Value.Integer = ArgCount; 317f8146b88SJung-uk Kim break; 318f8146b88SJung-uk Kim } 319f8146b88SJung-uk Kim 320f8146b88SJung-uk Kim ACPI_FREE (CallName); 321f8146b88SJung-uk Kim } 322f8146b88SJung-uk Kim 323f8146b88SJung-uk Kim 324f8146b88SJung-uk Kim /******************************************************************************* 325f8146b88SJung-uk Kim * 326f8146b88SJung-uk Kim * FUNCTION: ExAmlExternalWalkBegin 327f8146b88SJung-uk Kim * 328f8146b88SJung-uk Kim * PARAMETERS: ASL_WALK_CALLBACK 329f8146b88SJung-uk Kim * 330f8146b88SJung-uk Kim * RETURN: None 331f8146b88SJung-uk Kim * 332f8146b88SJung-uk Kim * DESCRIPTION: Parse tree walk to create external opcode list for methods. 333f8146b88SJung-uk Kim * 334f8146b88SJung-uk Kim ******************************************************************************/ 335f8146b88SJung-uk Kim 336f8146b88SJung-uk Kim ACPI_STATUS 337f8146b88SJung-uk Kim ExAmlExternalWalkBegin ( 338f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op, 339f8146b88SJung-uk Kim UINT32 Level, 340f8146b88SJung-uk Kim void *Context) 341f8146b88SJung-uk Kim { 342f8146b88SJung-uk Kim 343f8146b88SJung-uk Kim /* External list head saved in the definition block op */ 344f8146b88SJung-uk Kim 345f8146b88SJung-uk Kim if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) 346f8146b88SJung-uk Kim { 347f8146b88SJung-uk Kim Gbl_ExternalsListHead = Op->Asl.Value.Arg; 348f8146b88SJung-uk Kim } 349f8146b88SJung-uk Kim 350f8146b88SJung-uk Kim if (!Gbl_ExternalsListHead) 351f8146b88SJung-uk Kim { 352f8146b88SJung-uk Kim return (AE_OK); 353f8146b88SJung-uk Kim } 354f8146b88SJung-uk Kim 355f8146b88SJung-uk Kim if (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) 356f8146b88SJung-uk Kim { 357f8146b88SJung-uk Kim return (AE_OK); 358f8146b88SJung-uk Kim } 359f8146b88SJung-uk Kim 360f8146b88SJung-uk Kim /* 361f8146b88SJung-uk Kim * The NameOp child under an ExternalOp gets turned into PARSE_METHODCALL 362f8146b88SJung-uk Kim * by XfNamespaceLocateBegin(). Ignore these. 363f8146b88SJung-uk Kim */ 364f8146b88SJung-uk Kim if (Op->Asl.Parent && 365f8146b88SJung-uk Kim Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_EXTERNAL) 366f8146b88SJung-uk Kim { 367f8146b88SJung-uk Kim return (AE_OK); 368f8146b88SJung-uk Kim } 369f8146b88SJung-uk Kim 370f8146b88SJung-uk Kim ExInsertArgCount (Op); 371f8146b88SJung-uk Kim return (AE_OK); 372f8146b88SJung-uk Kim } 373f8146b88SJung-uk Kim 374f8146b88SJung-uk Kim 375f8146b88SJung-uk Kim /******************************************************************************* 376f8146b88SJung-uk Kim * 377f8146b88SJung-uk Kim * FUNCTION: ExAmlExternalWalkEnd 378f8146b88SJung-uk Kim * 379f8146b88SJung-uk Kim * PARAMETERS: ASL_WALK_CALLBACK 380f8146b88SJung-uk Kim * 381f8146b88SJung-uk Kim * RETURN: None 382f8146b88SJung-uk Kim * 383f8146b88SJung-uk Kim * DESCRIPTION: Parse tree walk to create external opcode list for methods. 384f8146b88SJung-uk Kim * Here, we just want to catch the case where a definition block 385f8146b88SJung-uk Kim * has been completed. Then we move all of the externals into 386f8146b88SJung-uk Kim * a single block in the parse tree and thus the AML code. 387f8146b88SJung-uk Kim * 388f8146b88SJung-uk Kim ******************************************************************************/ 389f8146b88SJung-uk Kim 390f8146b88SJung-uk Kim ACPI_STATUS 391f8146b88SJung-uk Kim ExAmlExternalWalkEnd ( 392f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Op, 393f8146b88SJung-uk Kim UINT32 Level, 394f8146b88SJung-uk Kim void *Context) 395f8146b88SJung-uk Kim { 396f8146b88SJung-uk Kim 397f8146b88SJung-uk Kim if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) 398f8146b88SJung-uk Kim { 399f8146b88SJung-uk Kim /* 400f8146b88SJung-uk Kim * Process any existing external list. (Support for 401f8146b88SJung-uk Kim * multiple definition blocks in a single file/compile) 402f8146b88SJung-uk Kim */ 403f8146b88SJung-uk Kim ExMoveExternals (Op); 404f8146b88SJung-uk Kim Gbl_ExternalsListHead = NULL; 405f8146b88SJung-uk Kim } 406f8146b88SJung-uk Kim 407f8146b88SJung-uk Kim return (AE_OK); 408f8146b88SJung-uk Kim } 409f8146b88SJung-uk Kim 410f8146b88SJung-uk Kim 411f8146b88SJung-uk Kim /******************************************************************************* 412f8146b88SJung-uk Kim * 413f8146b88SJung-uk Kim * FUNCTION: ExMoveExternals 414f8146b88SJung-uk Kim * 415f8146b88SJung-uk Kim * PARAMETERS: DefinitionBlockOp - Op for current definition block 416f8146b88SJung-uk Kim * 417f8146b88SJung-uk Kim * RETURN: None 418f8146b88SJung-uk Kim * 419f8146b88SJung-uk Kim * DESCRIPTION: Move all externals present in the source file into a single 420f8146b88SJung-uk Kim * block of AML code, surrounded by an "If (0)" to prevent 421f8146b88SJung-uk Kim * AML interpreters from attempting to execute the External 422f8146b88SJung-uk Kim * opcodes. 423f8146b88SJung-uk Kim * 424f8146b88SJung-uk Kim ******************************************************************************/ 425f8146b88SJung-uk Kim 426f8146b88SJung-uk Kim static void 427f8146b88SJung-uk Kim ExMoveExternals ( 428f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *DefinitionBlockOp) 429f8146b88SJung-uk Kim { 430f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *ParentOp; 431f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *ExternalOp; 432f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *PredicateOp; 433f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *NextOp; 434f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Prev; 435f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *Next; 4361cc50d6bSJung-uk Kim char *ExternalName; 437f8146b88SJung-uk Kim ACPI_OBJECT_TYPE ObjType; 438f8146b88SJung-uk Kim UINT32 i; 439f8146b88SJung-uk Kim 440f8146b88SJung-uk Kim 441f8146b88SJung-uk Kim if (!Gbl_ExternalsListHead) 442f8146b88SJung-uk Kim { 443f8146b88SJung-uk Kim return; 444f8146b88SJung-uk Kim } 445f8146b88SJung-uk Kim 446f8146b88SJung-uk Kim /* Remove the External nodes from the tree */ 447f8146b88SJung-uk Kim 448f8146b88SJung-uk Kim NextOp = Gbl_ExternalsListHead; 449f8146b88SJung-uk Kim while (NextOp) 450f8146b88SJung-uk Kim { 451f8146b88SJung-uk Kim /* 452f8146b88SJung-uk Kim * The External is stored in child pointer of each node in the 453f8146b88SJung-uk Kim * list 454f8146b88SJung-uk Kim */ 455f8146b88SJung-uk Kim ExternalOp = NextOp->Asl.Child; 456f8146b88SJung-uk Kim 4571cc50d6bSJung-uk Kim /* Get/set the fully qualified name */ 4581cc50d6bSJung-uk Kim 4591cc50d6bSJung-uk Kim ExternalName = AcpiNsGetNormalizedPathname (ExternalOp->Asl.Node, TRUE); 4601cc50d6bSJung-uk Kim ExternalOp->Asl.ExternalName = ExternalName; 4611cc50d6bSJung-uk Kim ExternalOp->Asl.Namepath = ExternalName; 4621cc50d6bSJung-uk Kim 463f8146b88SJung-uk Kim /* Set line numbers (for listings, etc.) */ 464f8146b88SJung-uk Kim 465f8146b88SJung-uk Kim ExternalOp->Asl.LineNumber = 0; 466f8146b88SJung-uk Kim ExternalOp->Asl.LogicalLineNumber = 0; 467f8146b88SJung-uk Kim 468f8146b88SJung-uk Kim Next = ExternalOp->Asl.Child; 469f8146b88SJung-uk Kim Next->Asl.LineNumber = 0; 470f8146b88SJung-uk Kim Next->Asl.LogicalLineNumber = 0; 471f8146b88SJung-uk Kim 4721cc50d6bSJung-uk Kim if (Next->Asl.ParseOpcode == PARSEOP_NAMESEG) 4731cc50d6bSJung-uk Kim { 4741cc50d6bSJung-uk Kim Next->Asl.ParseOpcode = PARSEOP_NAMESTRING; 4751cc50d6bSJung-uk Kim } 4761cc50d6bSJung-uk Kim Next->Asl.ExternalName = ExternalName; 4771cc50d6bSJung-uk Kim UtInternalizeName (ExternalName, &Next->Asl.Value.String); 4781cc50d6bSJung-uk Kim Next->Asl.AmlLength = strlen (Next->Asl.Value.String); 4791cc50d6bSJung-uk Kim 480f8146b88SJung-uk Kim Next = Next->Asl.Next; 481f8146b88SJung-uk Kim Next->Asl.LineNumber = 0; 482f8146b88SJung-uk Kim Next->Asl.LogicalLineNumber = 0; 483f8146b88SJung-uk Kim 484f8146b88SJung-uk Kim Next = Next->Asl.Next; 485f8146b88SJung-uk Kim Next->Asl.LineNumber = 0; 486f8146b88SJung-uk Kim Next->Asl.LogicalLineNumber = 0; 487f8146b88SJung-uk Kim 488f8146b88SJung-uk Kim Next = Next->Asl.Next; 489f8146b88SJung-uk Kim Next->Asl.LineNumber = 0; 490f8146b88SJung-uk Kim Next->Asl.LogicalLineNumber = 0; 491f8146b88SJung-uk Kim 492f8146b88SJung-uk Kim ParentOp = ExternalOp->Asl.Parent; 493f8146b88SJung-uk Kim Prev = Next = ParentOp->Asl.Child; 494f8146b88SJung-uk Kim 495f8146b88SJung-uk Kim /* Now find the External node's position in parse tree */ 496f8146b88SJung-uk Kim 497f8146b88SJung-uk Kim while (Next != ExternalOp) 498f8146b88SJung-uk Kim { 499f8146b88SJung-uk Kim Prev = Next; 500f8146b88SJung-uk Kim Next = Next->Asl.Next; 501f8146b88SJung-uk Kim } 502f8146b88SJung-uk Kim 503f8146b88SJung-uk Kim /* Remove the External from the parse tree */ 504f8146b88SJung-uk Kim 505f8146b88SJung-uk Kim if (Prev == ExternalOp) 506f8146b88SJung-uk Kim { 507f8146b88SJung-uk Kim /* External was the first child node */ 508f8146b88SJung-uk Kim 509f8146b88SJung-uk Kim ParentOp->Asl.Child = ExternalOp->Asl.Next; 510f8146b88SJung-uk Kim } 511f8146b88SJung-uk Kim 512f8146b88SJung-uk Kim Prev->Asl.Next = ExternalOp->Asl.Next; 513f8146b88SJung-uk Kim ExternalOp->Asl.Next = NULL; 514f8146b88SJung-uk Kim ExternalOp->Asl.Parent = Gbl_ExternalsListHead; 515f8146b88SJung-uk Kim 516f8146b88SJung-uk Kim /* Point the External to the next in the list */ 517f8146b88SJung-uk Kim 518f8146b88SJung-uk Kim if (NextOp->Asl.Next) 519f8146b88SJung-uk Kim { 520f8146b88SJung-uk Kim ExternalOp->Asl.Next = NextOp->Asl.Next->Asl.Child; 521f8146b88SJung-uk Kim } 522f8146b88SJung-uk Kim 523f8146b88SJung-uk Kim NextOp = NextOp->Asl.Next; 524f8146b88SJung-uk Kim } 525f8146b88SJung-uk Kim 526f8146b88SJung-uk Kim /* 527f8146b88SJung-uk Kim * Loop again to remove MethodObj Externals for which 528f8146b88SJung-uk Kim * a MethodCall was not found (dead external reference) 529f8146b88SJung-uk Kim */ 530f8146b88SJung-uk Kim Prev = Gbl_ExternalsListHead->Asl.Child; 531f8146b88SJung-uk Kim Next = Prev; 532f8146b88SJung-uk Kim while (Next) 533f8146b88SJung-uk Kim { 534f8146b88SJung-uk Kim ObjType = (ACPI_OBJECT_TYPE) 535f8146b88SJung-uk Kim Next->Asl.Child->Asl.Next->Asl.Value.Integer; 536f8146b88SJung-uk Kim 537f8146b88SJung-uk Kim if (ObjType == ACPI_TYPE_METHOD && 538f8146b88SJung-uk Kim !(Next->Asl.CompileFlags & NODE_VISITED)) 539f8146b88SJung-uk Kim { 540f8146b88SJung-uk Kim if (Next == Prev) 541f8146b88SJung-uk Kim { 542f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.Child = Next->Asl.Next; 543f8146b88SJung-uk Kim Next->Asl.Next = NULL; 544f8146b88SJung-uk Kim Prev = Gbl_ExternalsListHead->Asl.Child; 545f8146b88SJung-uk Kim Next = Prev; 546f8146b88SJung-uk Kim continue; 547f8146b88SJung-uk Kim } 548f8146b88SJung-uk Kim else 549f8146b88SJung-uk Kim { 550f8146b88SJung-uk Kim Prev->Asl.Next = Next->Asl.Next; 551f8146b88SJung-uk Kim Next->Asl.Next = NULL; 552f8146b88SJung-uk Kim Next = Prev->Asl.Next; 553f8146b88SJung-uk Kim continue; 554f8146b88SJung-uk Kim } 555f8146b88SJung-uk Kim } 556f8146b88SJung-uk Kim 557f8146b88SJung-uk Kim Prev = Next; 558f8146b88SJung-uk Kim Next = Next->Asl.Next; 559f8146b88SJung-uk Kim } 560f8146b88SJung-uk Kim 561f8146b88SJung-uk Kim /* If list is now empty, don't bother to make If (0) block */ 562f8146b88SJung-uk Kim 563f8146b88SJung-uk Kim if (!Gbl_ExternalsListHead->Asl.Child) 564f8146b88SJung-uk Kim { 565f8146b88SJung-uk Kim return; 566f8146b88SJung-uk Kim } 567f8146b88SJung-uk Kim 568f8146b88SJung-uk Kim /* Convert Gbl_ExternalsListHead parent to If(). */ 569f8146b88SJung-uk Kim 570f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.ParseOpcode = PARSEOP_IF; 571f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.AmlOpcode = AML_IF_OP; 572f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.CompileFlags = NODE_AML_PACKAGE; 573f8146b88SJung-uk Kim UtSetParseOpName (Gbl_ExternalsListHead); 574f8146b88SJung-uk Kim 575f8146b88SJung-uk Kim /* Create a Zero op for the If predicate */ 576f8146b88SJung-uk Kim 577f8146b88SJung-uk Kim PredicateOp = TrAllocateNode (PARSEOP_ZERO); 578f8146b88SJung-uk Kim PredicateOp->Asl.AmlOpcode = AML_ZERO_OP; 579f8146b88SJung-uk Kim 580f8146b88SJung-uk Kim PredicateOp->Asl.Parent = Gbl_ExternalsListHead; 581f8146b88SJung-uk Kim PredicateOp->Asl.Child = NULL; 582f8146b88SJung-uk Kim PredicateOp->Asl.Next = Gbl_ExternalsListHead->Asl.Child; 583f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.Child = PredicateOp; 584f8146b88SJung-uk Kim 585f8146b88SJung-uk Kim /* Set line numbers (for listings, etc.) */ 586f8146b88SJung-uk Kim 587f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.LineNumber = 0; 588f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.LogicalLineNumber = 0; 589f8146b88SJung-uk Kim 590f8146b88SJung-uk Kim PredicateOp->Asl.LineNumber = 0; 591f8146b88SJung-uk Kim PredicateOp->Asl.LogicalLineNumber = 0; 592f8146b88SJung-uk Kim 593f8146b88SJung-uk Kim /* Insert block back in the list */ 594f8146b88SJung-uk Kim 595f8146b88SJung-uk Kim Prev = DefinitionBlockOp->Asl.Child; 596f8146b88SJung-uk Kim Next = Prev; 597f8146b88SJung-uk Kim 598f8146b88SJung-uk Kim /* Find last default arg */ 599f8146b88SJung-uk Kim 600f8146b88SJung-uk Kim for (i = 0; i < 6; i++) 601f8146b88SJung-uk Kim { 602f8146b88SJung-uk Kim Prev = Next; 603f8146b88SJung-uk Kim Next = Prev->Asl.Next; 604f8146b88SJung-uk Kim } 605f8146b88SJung-uk Kim 606f8146b88SJung-uk Kim if (Next) 607f8146b88SJung-uk Kim { 608f8146b88SJung-uk Kim /* Definition Block is not empty */ 609f8146b88SJung-uk Kim 610f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.Next = Next; 611f8146b88SJung-uk Kim } 612f8146b88SJung-uk Kim else 613f8146b88SJung-uk Kim { 614f8146b88SJung-uk Kim /* Definition Block is empty. */ 615f8146b88SJung-uk Kim 616f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.Next = NULL; 617f8146b88SJung-uk Kim } 618f8146b88SJung-uk Kim 619f8146b88SJung-uk Kim Prev->Asl.Next = Gbl_ExternalsListHead; 620f8146b88SJung-uk Kim Gbl_ExternalsListHead->Asl.Parent = Prev->Asl.Parent; 621f8146b88SJung-uk Kim } 622