Home | History | Annotate | Line # | Download | only in namespace
nsparse.c revision 1.1.1.2.4.2
      1  1.1.1.2.4.2  rmind /******************************************************************************
      2  1.1.1.2.4.2  rmind  *
      3  1.1.1.2.4.2  rmind  * Module Name: nsparse - namespace interface to AML parser
      4  1.1.1.2.4.2  rmind  *
      5  1.1.1.2.4.2  rmind  *****************************************************************************/
      6  1.1.1.2.4.2  rmind 
      7  1.1.1.2.4.2  rmind /*
      8  1.1.1.2.4.2  rmind  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1.1.2.4.2  rmind  * All rights reserved.
     10  1.1.1.2.4.2  rmind  *
     11  1.1.1.2.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2.4.2  rmind  * modification, are permitted provided that the following conditions
     13  1.1.1.2.4.2  rmind  * are met:
     14  1.1.1.2.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2.4.2  rmind  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2.4.2  rmind  *    without modification.
     17  1.1.1.2.4.2  rmind  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2.4.2  rmind  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2.4.2  rmind  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2.4.2  rmind  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2.4.2  rmind  *    binary redistribution.
     22  1.1.1.2.4.2  rmind  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2.4.2  rmind  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2.4.2  rmind  *    from this software without specific prior written permission.
     25  1.1.1.2.4.2  rmind  *
     26  1.1.1.2.4.2  rmind  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2.4.2  rmind  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2.4.2  rmind  * Software Foundation.
     29  1.1.1.2.4.2  rmind  *
     30  1.1.1.2.4.2  rmind  * NO WARRANTY
     31  1.1.1.2.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2.4.2  rmind  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2.4.2  rmind  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2.4.2  rmind  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2.4.2  rmind  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2.4.2  rmind  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2.4.2  rmind  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2.4.2  rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2.4.2  rmind  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2.4.2  rmind  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2.4.2  rmind  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2.4.2  rmind  */
     43  1.1.1.2.4.2  rmind 
     44  1.1.1.2.4.2  rmind #define __NSPARSE_C__
     45  1.1.1.2.4.2  rmind 
     46  1.1.1.2.4.2  rmind #include "acpi.h"
     47  1.1.1.2.4.2  rmind #include "accommon.h"
     48  1.1.1.2.4.2  rmind #include "acnamesp.h"
     49  1.1.1.2.4.2  rmind #include "acparser.h"
     50  1.1.1.2.4.2  rmind #include "acdispat.h"
     51  1.1.1.2.4.2  rmind #include "actables.h"
     52  1.1.1.2.4.2  rmind 
     53  1.1.1.2.4.2  rmind 
     54  1.1.1.2.4.2  rmind #define _COMPONENT          ACPI_NAMESPACE
     55  1.1.1.2.4.2  rmind         ACPI_MODULE_NAME    ("nsparse")
     56  1.1.1.2.4.2  rmind 
     57  1.1.1.2.4.2  rmind 
     58  1.1.1.2.4.2  rmind /*******************************************************************************
     59  1.1.1.2.4.2  rmind  *
     60  1.1.1.2.4.2  rmind  * FUNCTION:    NsOneCompleteParse
     61  1.1.1.2.4.2  rmind  *
     62  1.1.1.2.4.2  rmind  * PARAMETERS:  PassNumber              - 1 or 2
     63  1.1.1.2.4.2  rmind  *              TableDesc               - The table to be parsed.
     64  1.1.1.2.4.2  rmind  *
     65  1.1.1.2.4.2  rmind  * RETURN:      Status
     66  1.1.1.2.4.2  rmind  *
     67  1.1.1.2.4.2  rmind  * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
     68  1.1.1.2.4.2  rmind  *
     69  1.1.1.2.4.2  rmind  ******************************************************************************/
     70  1.1.1.2.4.2  rmind 
     71  1.1.1.2.4.2  rmind ACPI_STATUS
     72  1.1.1.2.4.2  rmind AcpiNsOneCompleteParse (
     73  1.1.1.2.4.2  rmind     UINT32                  PassNumber,
     74  1.1.1.2.4.2  rmind     UINT32                  TableIndex,
     75  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *StartNode)
     76  1.1.1.2.4.2  rmind {
     77  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *ParseRoot;
     78  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
     79  1.1.1.2.4.2  rmind     UINT32                  AmlLength;
     80  1.1.1.2.4.2  rmind     UINT8                   *AmlStart;
     81  1.1.1.2.4.2  rmind     ACPI_WALK_STATE         *WalkState;
     82  1.1.1.2.4.2  rmind     ACPI_TABLE_HEADER       *Table;
     83  1.1.1.2.4.2  rmind     ACPI_OWNER_ID           OwnerId;
     84  1.1.1.2.4.2  rmind 
     85  1.1.1.2.4.2  rmind 
     86  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (NsOneCompleteParse);
     87  1.1.1.2.4.2  rmind 
     88  1.1.1.2.4.2  rmind 
     89  1.1.1.2.4.2  rmind     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
     90  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
     91  1.1.1.2.4.2  rmind     {
     92  1.1.1.2.4.2  rmind         return_ACPI_STATUS (Status);
     93  1.1.1.2.4.2  rmind     }
     94  1.1.1.2.4.2  rmind 
     95  1.1.1.2.4.2  rmind     /* Create and init a Root Node */
     96  1.1.1.2.4.2  rmind 
     97  1.1.1.2.4.2  rmind     ParseRoot = AcpiPsCreateScopeOp ();
     98  1.1.1.2.4.2  rmind     if (!ParseRoot)
     99  1.1.1.2.4.2  rmind     {
    100  1.1.1.2.4.2  rmind         return_ACPI_STATUS (AE_NO_MEMORY);
    101  1.1.1.2.4.2  rmind     }
    102  1.1.1.2.4.2  rmind 
    103  1.1.1.2.4.2  rmind     /* Create and initialize a new walk state */
    104  1.1.1.2.4.2  rmind 
    105  1.1.1.2.4.2  rmind     WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
    106  1.1.1.2.4.2  rmind     if (!WalkState)
    107  1.1.1.2.4.2  rmind     {
    108  1.1.1.2.4.2  rmind         AcpiPsFreeOp (ParseRoot);
    109  1.1.1.2.4.2  rmind         return_ACPI_STATUS (AE_NO_MEMORY);
    110  1.1.1.2.4.2  rmind     }
    111  1.1.1.2.4.2  rmind 
    112  1.1.1.2.4.2  rmind     Status = AcpiGetTableByIndex (TableIndex, &Table);
    113  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    114  1.1.1.2.4.2  rmind     {
    115  1.1.1.2.4.2  rmind         AcpiDsDeleteWalkState (WalkState);
    116  1.1.1.2.4.2  rmind         AcpiPsFreeOp (ParseRoot);
    117  1.1.1.2.4.2  rmind         return_ACPI_STATUS (Status);
    118  1.1.1.2.4.2  rmind     }
    119  1.1.1.2.4.2  rmind 
    120  1.1.1.2.4.2  rmind     /* Table must consist of at least a complete header */
    121  1.1.1.2.4.2  rmind 
    122  1.1.1.2.4.2  rmind     if (Table->Length < sizeof (ACPI_TABLE_HEADER))
    123  1.1.1.2.4.2  rmind     {
    124  1.1.1.2.4.2  rmind         Status = AE_BAD_HEADER;
    125  1.1.1.2.4.2  rmind     }
    126  1.1.1.2.4.2  rmind     else
    127  1.1.1.2.4.2  rmind     {
    128  1.1.1.2.4.2  rmind         AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
    129  1.1.1.2.4.2  rmind         AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
    130  1.1.1.2.4.2  rmind         Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
    131  1.1.1.2.4.2  rmind                     AmlStart, AmlLength, NULL, (UINT8) PassNumber);
    132  1.1.1.2.4.2  rmind     }
    133  1.1.1.2.4.2  rmind 
    134  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    135  1.1.1.2.4.2  rmind     {
    136  1.1.1.2.4.2  rmind         AcpiDsDeleteWalkState (WalkState);
    137  1.1.1.2.4.2  rmind         goto Cleanup;
    138  1.1.1.2.4.2  rmind     }
    139  1.1.1.2.4.2  rmind 
    140  1.1.1.2.4.2  rmind     /* StartNode is the default location to load the table  */
    141  1.1.1.2.4.2  rmind 
    142  1.1.1.2.4.2  rmind     if (StartNode && StartNode != AcpiGbl_RootNode)
    143  1.1.1.2.4.2  rmind     {
    144  1.1.1.2.4.2  rmind         Status = AcpiDsScopeStackPush (StartNode, ACPI_TYPE_METHOD, WalkState);
    145  1.1.1.2.4.2  rmind         if (ACPI_FAILURE (Status))
    146  1.1.1.2.4.2  rmind         {
    147  1.1.1.2.4.2  rmind             AcpiDsDeleteWalkState (WalkState);
    148  1.1.1.2.4.2  rmind             goto Cleanup;
    149  1.1.1.2.4.2  rmind         }
    150  1.1.1.2.4.2  rmind     }
    151  1.1.1.2.4.2  rmind 
    152  1.1.1.2.4.2  rmind     /* Parse the AML */
    153  1.1.1.2.4.2  rmind 
    154  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %u parse\n", PassNumber));
    155  1.1.1.2.4.2  rmind     Status = AcpiPsParseAml (WalkState);
    156  1.1.1.2.4.2  rmind 
    157  1.1.1.2.4.2  rmind Cleanup:
    158  1.1.1.2.4.2  rmind     AcpiPsDeleteParseTree (ParseRoot);
    159  1.1.1.2.4.2  rmind     return_ACPI_STATUS (Status);
    160  1.1.1.2.4.2  rmind }
    161  1.1.1.2.4.2  rmind 
    162  1.1.1.2.4.2  rmind 
    163  1.1.1.2.4.2  rmind /*******************************************************************************
    164  1.1.1.2.4.2  rmind  *
    165  1.1.1.2.4.2  rmind  * FUNCTION:    AcpiNsParseTable
    166  1.1.1.2.4.2  rmind  *
    167  1.1.1.2.4.2  rmind  * PARAMETERS:  TableDesc       - An ACPI table descriptor for table to parse
    168  1.1.1.2.4.2  rmind  *              StartNode       - Where to enter the table into the namespace
    169  1.1.1.2.4.2  rmind  *
    170  1.1.1.2.4.2  rmind  * RETURN:      Status
    171  1.1.1.2.4.2  rmind  *
    172  1.1.1.2.4.2  rmind  * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
    173  1.1.1.2.4.2  rmind  *
    174  1.1.1.2.4.2  rmind  ******************************************************************************/
    175  1.1.1.2.4.2  rmind 
    176  1.1.1.2.4.2  rmind ACPI_STATUS
    177  1.1.1.2.4.2  rmind AcpiNsParseTable (
    178  1.1.1.2.4.2  rmind     UINT32                  TableIndex,
    179  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *StartNode)
    180  1.1.1.2.4.2  rmind {
    181  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    182  1.1.1.2.4.2  rmind 
    183  1.1.1.2.4.2  rmind 
    184  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (NsParseTable);
    185  1.1.1.2.4.2  rmind 
    186  1.1.1.2.4.2  rmind 
    187  1.1.1.2.4.2  rmind     /*
    188  1.1.1.2.4.2  rmind      * AML Parse, pass 1
    189  1.1.1.2.4.2  rmind      *
    190  1.1.1.2.4.2  rmind      * In this pass, we load most of the namespace.  Control methods
    191  1.1.1.2.4.2  rmind      * are not parsed until later.  A parse tree is not created.  Instead,
    192  1.1.1.2.4.2  rmind      * each Parser Op subtree is deleted when it is finished.  This saves
    193  1.1.1.2.4.2  rmind      * a great deal of memory, and allows a small cache of parse objects
    194  1.1.1.2.4.2  rmind      * to service the entire parse.  The second pass of the parse then
    195  1.1.1.2.4.2  rmind      * performs another complete parse of the AML.
    196  1.1.1.2.4.2  rmind      */
    197  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
    198  1.1.1.2.4.2  rmind     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
    199  1.1.1.2.4.2  rmind                 TableIndex, StartNode);
    200  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    201  1.1.1.2.4.2  rmind     {
    202  1.1.1.2.4.2  rmind         return_ACPI_STATUS (Status);
    203  1.1.1.2.4.2  rmind     }
    204  1.1.1.2.4.2  rmind 
    205  1.1.1.2.4.2  rmind     /*
    206  1.1.1.2.4.2  rmind      * AML Parse, pass 2
    207  1.1.1.2.4.2  rmind      *
    208  1.1.1.2.4.2  rmind      * In this pass, we resolve forward references and other things
    209  1.1.1.2.4.2  rmind      * that could not be completed during the first pass.
    210  1.1.1.2.4.2  rmind      * Another complete parse of the AML is performed, but the
    211  1.1.1.2.4.2  rmind      * overhead of this is compensated for by the fact that the
    212  1.1.1.2.4.2  rmind      * parse objects are all cached.
    213  1.1.1.2.4.2  rmind      */
    214  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
    215  1.1.1.2.4.2  rmind     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
    216  1.1.1.2.4.2  rmind                 TableIndex, StartNode);
    217  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    218  1.1.1.2.4.2  rmind     {
    219  1.1.1.2.4.2  rmind         return_ACPI_STATUS (Status);
    220  1.1.1.2.4.2  rmind     }
    221  1.1.1.2.4.2  rmind 
    222  1.1.1.2.4.2  rmind     return_ACPI_STATUS (Status);
    223  1.1.1.2.4.2  rmind }
    224  1.1.1.2.4.2  rmind 
    225  1.1.1.2.4.2  rmind 
    226