13446Smrj /******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: nsparse - namespace interface to AML parser
4*7851SDana.Myers@Sun.COM  *              $Revision: 1.19 $
53446Smrj  *
63446Smrj  *****************************************************************************/
73446Smrj 
83446Smrj /******************************************************************************
93446Smrj  *
103446Smrj  * 1. Copyright Notice
113446Smrj  *
12*7851SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
133446Smrj  * All rights reserved.
143446Smrj  *
153446Smrj  * 2. License
163446Smrj  *
173446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
183446Smrj  * rights.  You may have additional license terms from the party that provided
193446Smrj  * you this software, covering your right to use that party's intellectual
203446Smrj  * property rights.
213446Smrj  *
223446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
233446Smrj  * copy of the source code appearing in this file ("Covered Code") an
243446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
253446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
263446Smrj  * make derivatives, distribute, use and display any portion of the Covered
273446Smrj  * Code in any form, with the right to sublicense such rights; and
283446Smrj  *
293446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
303446Smrj  * license (with the right to sublicense), under only those claims of Intel
313446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
323446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
333446Smrj  * solely to the minimum extent necessary to exercise the above copyright
343446Smrj  * license, and in no event shall the patent license extend to any additions
353446Smrj  * to or modifications of the Original Intel Code.  No other license or right
363446Smrj  * is granted directly or by implication, estoppel or otherwise;
373446Smrj  *
383446Smrj  * The above copyright and patent license is granted only if the following
393446Smrj  * conditions are met:
403446Smrj  *
413446Smrj  * 3. Conditions
423446Smrj  *
433446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
443446Smrj  * Redistribution of source code of any substantial portion of the Covered
453446Smrj  * Code or modification with rights to further distribute source must include
463446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
473446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
483446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
493446Smrj  * contain a file documenting the changes Licensee made to create that Covered
503446Smrj  * Code and the date of any change.  Licensee must include in that file the
513446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
523446Smrj  * must include a prominent statement that the modification is derived,
533446Smrj  * directly or indirectly, from Original Intel Code.
543446Smrj  *
553446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
563446Smrj  * Redistribution of source code of any substantial portion of the Covered
573446Smrj  * Code or modification without rights to further distribute source must
583446Smrj  * include the following Disclaimer and Export Compliance provision in the
593446Smrj  * documentation and/or other materials provided with distribution.  In
603446Smrj  * addition, Licensee may not authorize further sublicense of source of any
613446Smrj  * portion of the Covered Code, and must include terms to the effect that the
623446Smrj  * license from Licensee to its licensee is limited to the intellectual
633446Smrj  * property embodied in the software Licensee provides to its licensee, and
643446Smrj  * not to intellectual property embodied in modifications its licensee may
653446Smrj  * make.
663446Smrj  *
673446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
683446Smrj  * substantial portion of the Covered Code or modification must reproduce the
693446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
703446Smrj  * provision in the documentation and/or other materials provided with the
713446Smrj  * distribution.
723446Smrj  *
733446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
743446Smrj  * Intel Code.
753446Smrj  *
763446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
773446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
783446Smrj  * other dealings in products derived from or relating to the Covered Code
793446Smrj  * without prior written authorization from Intel.
803446Smrj  *
813446Smrj  * 4. Disclaimer and Export Compliance
823446Smrj  *
833446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
843446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
853446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
863446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
873446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
883446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
893446Smrj  * PARTICULAR PURPOSE.
903446Smrj  *
913446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
923446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
933446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
943446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
953446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
963446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
973446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
983446Smrj  * LIMITED REMEDY.
993446Smrj  *
1003446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1013446Smrj  * software or system incorporating such software without first obtaining any
1023446Smrj  * required license or other approval from the U. S. Department of Commerce or
1033446Smrj  * any other agency or department of the United States Government.  In the
1043446Smrj  * event Licensee exports any such software from the United States or
1053446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1063446Smrj  * ensure that the distribution and export/re-export of the software is in
1073446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1083446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1093446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1103446Smrj  * software, or service, directly or indirectly, to any country for which the
1113446Smrj  * United States government or any agency thereof requires an export license,
1123446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1133446Smrj  * such license, approval or letter.
1143446Smrj  *
1153446Smrj  *****************************************************************************/
1163446Smrj 
1173446Smrj #define __NSPARSE_C__
1183446Smrj 
1193446Smrj #include "acpi.h"
1203446Smrj #include "acnamesp.h"
1213446Smrj #include "acparser.h"
1223446Smrj #include "acdispat.h"
123*7851SDana.Myers@Sun.COM #include "actables.h"
1243446Smrj 
1253446Smrj 
1263446Smrj #define _COMPONENT          ACPI_NAMESPACE
1273446Smrj         ACPI_MODULE_NAME    ("nsparse")
1283446Smrj 
1293446Smrj 
1303446Smrj /*******************************************************************************
1313446Smrj  *
1323446Smrj  * FUNCTION:    NsOneCompleteParse
1333446Smrj  *
1343446Smrj  * PARAMETERS:  PassNumber              - 1 or 2
1353446Smrj  *              TableDesc               - The table to be parsed.
1363446Smrj  *
1373446Smrj  * RETURN:      Status
1383446Smrj  *
1393446Smrj  * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
1403446Smrj  *
1413446Smrj  ******************************************************************************/
1423446Smrj 
1433446Smrj ACPI_STATUS
1443446Smrj AcpiNsOneCompleteParse (
145*7851SDana.Myers@Sun.COM     UINT32                  PassNumber,
146*7851SDana.Myers@Sun.COM     UINT32                  TableIndex,
147*7851SDana.Myers@Sun.COM     ACPI_NAMESPACE_NODE     *StartNode)
1483446Smrj {
1493446Smrj     ACPI_PARSE_OBJECT       *ParseRoot;
1503446Smrj     ACPI_STATUS             Status;
151*7851SDana.Myers@Sun.COM     UINT32                  AmlLength;
152*7851SDana.Myers@Sun.COM     UINT8                   *AmlStart;
1533446Smrj     ACPI_WALK_STATE         *WalkState;
154*7851SDana.Myers@Sun.COM     ACPI_TABLE_HEADER       *Table;
155*7851SDana.Myers@Sun.COM     ACPI_OWNER_ID           OwnerId;
1563446Smrj 
1573446Smrj 
1583446Smrj     ACPI_FUNCTION_TRACE (NsOneCompleteParse);
1593446Smrj 
1603446Smrj 
161*7851SDana.Myers@Sun.COM     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
162*7851SDana.Myers@Sun.COM     if (ACPI_FAILURE (Status))
163*7851SDana.Myers@Sun.COM     {
164*7851SDana.Myers@Sun.COM         return_ACPI_STATUS (Status);
165*7851SDana.Myers@Sun.COM     }
166*7851SDana.Myers@Sun.COM 
1673446Smrj     /* Create and init a Root Node */
1683446Smrj 
1693446Smrj     ParseRoot = AcpiPsCreateScopeOp ();
1703446Smrj     if (!ParseRoot)
1713446Smrj     {
1723446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
1733446Smrj     }
1743446Smrj 
1753446Smrj     /* Create and initialize a new walk state */
1763446Smrj 
177*7851SDana.Myers@Sun.COM     WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
1783446Smrj     if (!WalkState)
1793446Smrj     {
1803446Smrj         AcpiPsFreeOp (ParseRoot);
1813446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
1823446Smrj     }
1833446Smrj 
184*7851SDana.Myers@Sun.COM     Status = AcpiGetTableByIndex (TableIndex, &Table);
1853446Smrj     if (ACPI_FAILURE (Status))
1863446Smrj     {
1873446Smrj         AcpiDsDeleteWalkState (WalkState);
188*7851SDana.Myers@Sun.COM         AcpiPsFreeOp (ParseRoot);
1893446Smrj         return_ACPI_STATUS (Status);
1903446Smrj     }
1913446Smrj 
192*7851SDana.Myers@Sun.COM     /* Table must consist of at least a complete header */
193*7851SDana.Myers@Sun.COM 
194*7851SDana.Myers@Sun.COM     if (Table->Length < sizeof (ACPI_TABLE_HEADER))
195*7851SDana.Myers@Sun.COM     {
196*7851SDana.Myers@Sun.COM         Status = AE_BAD_HEADER;
197*7851SDana.Myers@Sun.COM     }
198*7851SDana.Myers@Sun.COM     else
199*7851SDana.Myers@Sun.COM     {
200*7851SDana.Myers@Sun.COM         AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
201*7851SDana.Myers@Sun.COM         AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
202*7851SDana.Myers@Sun.COM         Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
203*7851SDana.Myers@Sun.COM                     AmlStart, AmlLength, NULL, (UINT8) PassNumber);
204*7851SDana.Myers@Sun.COM     }
205*7851SDana.Myers@Sun.COM 
206*7851SDana.Myers@Sun.COM     if (ACPI_FAILURE (Status))
207*7851SDana.Myers@Sun.COM     {
208*7851SDana.Myers@Sun.COM         AcpiDsDeleteWalkState (WalkState);
209*7851SDana.Myers@Sun.COM         goto Cleanup;
210*7851SDana.Myers@Sun.COM     }
211*7851SDana.Myers@Sun.COM 
212*7851SDana.Myers@Sun.COM     /* StartNode is the default location to load the table  */
213*7851SDana.Myers@Sun.COM 
214*7851SDana.Myers@Sun.COM     if (StartNode && StartNode != AcpiGbl_RootNode)
215*7851SDana.Myers@Sun.COM     {
216*7851SDana.Myers@Sun.COM         Status = AcpiDsScopeStackPush (StartNode, ACPI_TYPE_METHOD, WalkState);
217*7851SDana.Myers@Sun.COM         if (ACPI_FAILURE (Status))
218*7851SDana.Myers@Sun.COM         {
219*7851SDana.Myers@Sun.COM             AcpiDsDeleteWalkState (WalkState);
220*7851SDana.Myers@Sun.COM             goto Cleanup;
221*7851SDana.Myers@Sun.COM         }
222*7851SDana.Myers@Sun.COM     }
223*7851SDana.Myers@Sun.COM 
2243446Smrj     /* Parse the AML */
2253446Smrj 
2263446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %d parse\n", PassNumber));
2273446Smrj     Status = AcpiPsParseAml (WalkState);
2283446Smrj 
229*7851SDana.Myers@Sun.COM Cleanup:
2303446Smrj     AcpiPsDeleteParseTree (ParseRoot);
2313446Smrj     return_ACPI_STATUS (Status);
2323446Smrj }
2333446Smrj 
2343446Smrj 
2353446Smrj /*******************************************************************************
2363446Smrj  *
2373446Smrj  * FUNCTION:    AcpiNsParseTable
2383446Smrj  *
2393446Smrj  * PARAMETERS:  TableDesc       - An ACPI table descriptor for table to parse
2403446Smrj  *              StartNode       - Where to enter the table into the namespace
2413446Smrj  *
2423446Smrj  * RETURN:      Status
2433446Smrj  *
2443446Smrj  * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
2453446Smrj  *
2463446Smrj  ******************************************************************************/
2473446Smrj 
2483446Smrj ACPI_STATUS
2493446Smrj AcpiNsParseTable (
250*7851SDana.Myers@Sun.COM     UINT32                  TableIndex,
2513446Smrj     ACPI_NAMESPACE_NODE     *StartNode)
2523446Smrj {
2533446Smrj     ACPI_STATUS             Status;
2543446Smrj 
2553446Smrj 
2563446Smrj     ACPI_FUNCTION_TRACE (NsParseTable);
2573446Smrj 
2583446Smrj 
2593446Smrj     /*
2603446Smrj      * AML Parse, pass 1
2613446Smrj      *
2623446Smrj      * In this pass, we load most of the namespace.  Control methods
2633446Smrj      * are not parsed until later.  A parse tree is not created.  Instead,
2643446Smrj      * each Parser Op subtree is deleted when it is finished.  This saves
2653446Smrj      * a great deal of memory, and allows a small cache of parse objects
2663446Smrj      * to service the entire parse.  The second pass of the parse then
267*7851SDana.Myers@Sun.COM      * performs another complete parse of the AML.
2683446Smrj      */
2693446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
270*7851SDana.Myers@Sun.COM     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1, TableIndex, StartNode);
2713446Smrj     if (ACPI_FAILURE (Status))
2723446Smrj     {
2733446Smrj         return_ACPI_STATUS (Status);
2743446Smrj     }
2753446Smrj 
2763446Smrj     /*
2773446Smrj      * AML Parse, pass 2
2783446Smrj      *
2793446Smrj      * In this pass, we resolve forward references and other things
2803446Smrj      * that could not be completed during the first pass.
2813446Smrj      * Another complete parse of the AML is performed, but the
2823446Smrj      * overhead of this is compensated for by the fact that the
2833446Smrj      * parse objects are all cached.
2843446Smrj      */
2853446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
286*7851SDana.Myers@Sun.COM     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, StartNode);
2873446Smrj     if (ACPI_FAILURE (Status))
2883446Smrj     {
2893446Smrj         return_ACPI_STATUS (Status);
2903446Smrj     }
2913446Smrj 
2923446Smrj     return_ACPI_STATUS (Status);
2933446Smrj }
2943446Smrj 
2953446Smrj 
296