Home | History | Annotate | Line # | Download | only in namespace
nsparse.c revision 1.1.1.8.2.1
      1          1.1    jruoho /******************************************************************************
      2          1.1    jruoho  *
      3          1.1    jruoho  * Module Name: nsparse - namespace interface to AML parser
      4          1.1    jruoho  *
      5          1.1    jruoho  *****************************************************************************/
      6          1.1    jruoho 
      7      1.1.1.2    jruoho /*
      8  1.1.1.8.2.1    bouyer  * Copyright (C) 2000 - 2017, Intel Corp.
      9          1.1    jruoho  * All rights reserved.
     10          1.1    jruoho  *
     11      1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13      1.1.1.2    jruoho  * are met:
     14      1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1.1.2    jruoho  *    without modification.
     17      1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1.1.2    jruoho  *    binary redistribution.
     22      1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25      1.1.1.2    jruoho  *
     26      1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1.1.2    jruoho  * Software Foundation.
     29      1.1.1.2    jruoho  *
     30      1.1.1.2    jruoho  * NO WARRANTY
     31      1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1.1.2    jruoho  */
     43          1.1    jruoho 
     44          1.1    jruoho #include "acpi.h"
     45          1.1    jruoho #include "accommon.h"
     46          1.1    jruoho #include "acnamesp.h"
     47          1.1    jruoho #include "acparser.h"
     48          1.1    jruoho #include "acdispat.h"
     49          1.1    jruoho #include "actables.h"
     50      1.1.1.8  christos #include "acinterp.h"
     51          1.1    jruoho 
     52          1.1    jruoho 
     53          1.1    jruoho #define _COMPONENT          ACPI_NAMESPACE
     54          1.1    jruoho         ACPI_MODULE_NAME    ("nsparse")
     55          1.1    jruoho 
     56          1.1    jruoho 
     57          1.1    jruoho /*******************************************************************************
     58          1.1    jruoho  *
     59      1.1.1.8  christos  * FUNCTION:    NsExecuteTable
     60      1.1.1.8  christos  *
     61      1.1.1.8  christos  * PARAMETERS:  TableDesc       - An ACPI table descriptor for table to parse
     62      1.1.1.8  christos  *              StartNode       - Where to enter the table into the namespace
     63      1.1.1.8  christos  *
     64      1.1.1.8  christos  * RETURN:      Status
     65      1.1.1.8  christos  *
     66      1.1.1.8  christos  * DESCRIPTION: Load ACPI/AML table by executing the entire table as a
     67      1.1.1.8  christos  *              TermList.
     68      1.1.1.8  christos  *
     69      1.1.1.8  christos  ******************************************************************************/
     70      1.1.1.8  christos 
     71      1.1.1.8  christos ACPI_STATUS
     72      1.1.1.8  christos AcpiNsExecuteTable (
     73      1.1.1.8  christos     UINT32                  TableIndex,
     74      1.1.1.8  christos     ACPI_NAMESPACE_NODE     *StartNode)
     75      1.1.1.8  christos {
     76      1.1.1.8  christos     ACPI_STATUS             Status;
     77      1.1.1.8  christos     ACPI_TABLE_HEADER       *Table;
     78      1.1.1.8  christos     ACPI_OWNER_ID           OwnerId;
     79      1.1.1.8  christos     ACPI_EVALUATE_INFO      *Info = NULL;
     80      1.1.1.8  christos     UINT32                  AmlLength;
     81      1.1.1.8  christos     UINT8                   *AmlStart;
     82      1.1.1.8  christos     ACPI_OPERAND_OBJECT     *MethodObj = NULL;
     83      1.1.1.8  christos 
     84      1.1.1.8  christos 
     85      1.1.1.8  christos     ACPI_FUNCTION_TRACE (NsExecuteTable);
     86      1.1.1.8  christos 
     87      1.1.1.8  christos 
     88      1.1.1.8  christos     Status = AcpiGetTableByIndex (TableIndex, &Table);
     89      1.1.1.8  christos     if (ACPI_FAILURE (Status))
     90      1.1.1.8  christos     {
     91      1.1.1.8  christos         return_ACPI_STATUS (Status);
     92      1.1.1.8  christos     }
     93      1.1.1.8  christos 
     94      1.1.1.8  christos     /* Table must consist of at least a complete header */
     95      1.1.1.8  christos 
     96      1.1.1.8  christos     if (Table->Length < sizeof (ACPI_TABLE_HEADER))
     97      1.1.1.8  christos     {
     98      1.1.1.8  christos         return_ACPI_STATUS (AE_BAD_HEADER);
     99      1.1.1.8  christos     }
    100      1.1.1.8  christos 
    101      1.1.1.8  christos     AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
    102      1.1.1.8  christos     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
    103      1.1.1.8  christos 
    104      1.1.1.8  christos     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
    105      1.1.1.8  christos     if (ACPI_FAILURE (Status))
    106      1.1.1.8  christos     {
    107      1.1.1.8  christos         return_ACPI_STATUS (Status);
    108      1.1.1.8  christos     }
    109      1.1.1.8  christos 
    110      1.1.1.8  christos     /* Create, initialize, and link a new temporary method object */
    111      1.1.1.8  christos 
    112      1.1.1.8  christos     MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
    113      1.1.1.8  christos     if (!MethodObj)
    114      1.1.1.8  christos     {
    115      1.1.1.8  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    116      1.1.1.8  christos     }
    117      1.1.1.8  christos 
    118      1.1.1.8  christos     /* Allocate the evaluation information block */
    119      1.1.1.8  christos 
    120      1.1.1.8  christos     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    121      1.1.1.8  christos     if (!Info)
    122      1.1.1.8  christos     {
    123      1.1.1.8  christos         Status = AE_NO_MEMORY;
    124      1.1.1.8  christos         goto Cleanup;
    125      1.1.1.8  christos     }
    126      1.1.1.8  christos 
    127      1.1.1.8  christos     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
    128      1.1.1.8  christos         "Create table code block: %p\n", MethodObj));
    129      1.1.1.8  christos 
    130      1.1.1.8  christos     MethodObj->Method.AmlStart = AmlStart;
    131      1.1.1.8  christos     MethodObj->Method.AmlLength = AmlLength;
    132      1.1.1.8  christos     MethodObj->Method.OwnerId = OwnerId;
    133      1.1.1.8  christos     MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
    134      1.1.1.8  christos 
    135      1.1.1.8  christos     Info->PassNumber = ACPI_IMODE_EXECUTE;
    136      1.1.1.8  christos     Info->Node = StartNode;
    137      1.1.1.8  christos     Info->ObjDesc = MethodObj;
    138      1.1.1.8  christos     Info->NodeFlags = Info->Node->Flags;
    139      1.1.1.8  christos     Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);
    140      1.1.1.8  christos     if (!Info->FullPathname)
    141      1.1.1.8  christos     {
    142      1.1.1.8  christos         Status = AE_NO_MEMORY;
    143      1.1.1.8  christos         goto Cleanup;
    144      1.1.1.8  christos     }
    145      1.1.1.8  christos 
    146      1.1.1.8  christos     Status = AcpiPsExecuteTable (Info);
    147      1.1.1.8  christos 
    148      1.1.1.8  christos Cleanup:
    149      1.1.1.8  christos     if (Info)
    150      1.1.1.8  christos     {
    151      1.1.1.8  christos         ACPI_FREE (Info->FullPathname);
    152      1.1.1.8  christos         Info->FullPathname = NULL;
    153      1.1.1.8  christos     }
    154      1.1.1.8  christos     ACPI_FREE (Info);
    155      1.1.1.8  christos     AcpiUtRemoveReference (MethodObj);
    156      1.1.1.8  christos     return_ACPI_STATUS (Status);
    157      1.1.1.8  christos }
    158      1.1.1.8  christos 
    159      1.1.1.8  christos 
    160      1.1.1.8  christos /*******************************************************************************
    161      1.1.1.8  christos  *
    162          1.1    jruoho  * FUNCTION:    NsOneCompleteParse
    163          1.1    jruoho  *
    164          1.1    jruoho  * PARAMETERS:  PassNumber              - 1 or 2
    165          1.1    jruoho  *              TableDesc               - The table to be parsed.
    166          1.1    jruoho  *
    167          1.1    jruoho  * RETURN:      Status
    168          1.1    jruoho  *
    169          1.1    jruoho  * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
    170          1.1    jruoho  *
    171          1.1    jruoho  ******************************************************************************/
    172          1.1    jruoho 
    173          1.1    jruoho ACPI_STATUS
    174          1.1    jruoho AcpiNsOneCompleteParse (
    175          1.1    jruoho     UINT32                  PassNumber,
    176          1.1    jruoho     UINT32                  TableIndex,
    177          1.1    jruoho     ACPI_NAMESPACE_NODE     *StartNode)
    178          1.1    jruoho {
    179          1.1    jruoho     ACPI_PARSE_OBJECT       *ParseRoot;
    180          1.1    jruoho     ACPI_STATUS             Status;
    181          1.1    jruoho     UINT32                  AmlLength;
    182          1.1    jruoho     UINT8                   *AmlStart;
    183          1.1    jruoho     ACPI_WALK_STATE         *WalkState;
    184          1.1    jruoho     ACPI_TABLE_HEADER       *Table;
    185          1.1    jruoho     ACPI_OWNER_ID           OwnerId;
    186          1.1    jruoho 
    187          1.1    jruoho 
    188          1.1    jruoho     ACPI_FUNCTION_TRACE (NsOneCompleteParse);
    189          1.1    jruoho 
    190          1.1    jruoho 
    191      1.1.1.6  christos     Status = AcpiGetTableByIndex (TableIndex, &Table);
    192      1.1.1.6  christos     if (ACPI_FAILURE (Status))
    193      1.1.1.6  christos     {
    194      1.1.1.6  christos         return_ACPI_STATUS (Status);
    195      1.1.1.6  christos     }
    196      1.1.1.6  christos 
    197      1.1.1.6  christos     /* Table must consist of at least a complete header */
    198      1.1.1.6  christos 
    199      1.1.1.6  christos     if (Table->Length < sizeof (ACPI_TABLE_HEADER))
    200      1.1.1.6  christos     {
    201      1.1.1.6  christos         return_ACPI_STATUS (AE_BAD_HEADER);
    202      1.1.1.6  christos     }
    203      1.1.1.6  christos 
    204      1.1.1.6  christos     AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
    205      1.1.1.6  christos     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
    206      1.1.1.6  christos 
    207          1.1    jruoho     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
    208          1.1    jruoho     if (ACPI_FAILURE (Status))
    209          1.1    jruoho     {
    210          1.1    jruoho         return_ACPI_STATUS (Status);
    211          1.1    jruoho     }
    212          1.1    jruoho 
    213          1.1    jruoho     /* Create and init a Root Node */
    214          1.1    jruoho 
    215      1.1.1.6  christos     ParseRoot = AcpiPsCreateScopeOp (AmlStart);
    216          1.1    jruoho     if (!ParseRoot)
    217          1.1    jruoho     {
    218          1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    219          1.1    jruoho     }
    220          1.1    jruoho 
    221          1.1    jruoho     /* Create and initialize a new walk state */
    222          1.1    jruoho 
    223          1.1    jruoho     WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
    224          1.1    jruoho     if (!WalkState)
    225          1.1    jruoho     {
    226          1.1    jruoho         AcpiPsFreeOp (ParseRoot);
    227          1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    228          1.1    jruoho     }
    229          1.1    jruoho 
    230      1.1.1.6  christos     Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
    231      1.1.1.7  christos         AmlStart, AmlLength, NULL, (UINT8) PassNumber);
    232          1.1    jruoho     if (ACPI_FAILURE (Status))
    233          1.1    jruoho     {
    234          1.1    jruoho         AcpiDsDeleteWalkState (WalkState);
    235      1.1.1.6  christos         goto Cleanup;
    236          1.1    jruoho     }
    237          1.1    jruoho 
    238      1.1.1.6  christos     /* Found OSDT table, enable the namespace override feature */
    239          1.1    jruoho 
    240      1.1.1.6  christos     if (ACPI_COMPARE_NAME(Table->Signature, ACPI_SIG_OSDT) &&
    241      1.1.1.6  christos         PassNumber == ACPI_IMODE_LOAD_PASS1)
    242          1.1    jruoho     {
    243      1.1.1.6  christos         WalkState->NamespaceOverride = TRUE;
    244          1.1    jruoho     }
    245          1.1    jruoho 
    246          1.1    jruoho     /* StartNode is the default location to load the table  */
    247          1.1    jruoho 
    248          1.1    jruoho     if (StartNode && StartNode != AcpiGbl_RootNode)
    249          1.1    jruoho     {
    250      1.1.1.7  christos         Status = AcpiDsScopeStackPush (
    251      1.1.1.7  christos             StartNode, ACPI_TYPE_METHOD, WalkState);
    252          1.1    jruoho         if (ACPI_FAILURE (Status))
    253          1.1    jruoho         {
    254          1.1    jruoho             AcpiDsDeleteWalkState (WalkState);
    255          1.1    jruoho             goto Cleanup;
    256          1.1    jruoho         }
    257          1.1    jruoho     }
    258          1.1    jruoho 
    259          1.1    jruoho     /* Parse the AML */
    260          1.1    jruoho 
    261      1.1.1.7  christos     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
    262      1.1.1.7  christos         "*PARSE* pass %u parse\n", PassNumber));
    263      1.1.1.8  christos     AcpiExEnterInterpreter ();
    264          1.1    jruoho     Status = AcpiPsParseAml (WalkState);
    265      1.1.1.8  christos     AcpiExExitInterpreter ();
    266          1.1    jruoho 
    267          1.1    jruoho Cleanup:
    268          1.1    jruoho     AcpiPsDeleteParseTree (ParseRoot);
    269          1.1    jruoho     return_ACPI_STATUS (Status);
    270          1.1    jruoho }
    271          1.1    jruoho 
    272          1.1    jruoho 
    273          1.1    jruoho /*******************************************************************************
    274          1.1    jruoho  *
    275          1.1    jruoho  * FUNCTION:    AcpiNsParseTable
    276          1.1    jruoho  *
    277          1.1    jruoho  * PARAMETERS:  TableDesc       - An ACPI table descriptor for table to parse
    278          1.1    jruoho  *              StartNode       - Where to enter the table into the namespace
    279          1.1    jruoho  *
    280          1.1    jruoho  * RETURN:      Status
    281          1.1    jruoho  *
    282          1.1    jruoho  * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
    283          1.1    jruoho  *
    284          1.1    jruoho  ******************************************************************************/
    285          1.1    jruoho 
    286          1.1    jruoho ACPI_STATUS
    287          1.1    jruoho AcpiNsParseTable (
    288          1.1    jruoho     UINT32                  TableIndex,
    289          1.1    jruoho     ACPI_NAMESPACE_NODE     *StartNode)
    290          1.1    jruoho {
    291          1.1    jruoho     ACPI_STATUS             Status;
    292          1.1    jruoho 
    293          1.1    jruoho 
    294          1.1    jruoho     ACPI_FUNCTION_TRACE (NsParseTable);
    295          1.1    jruoho 
    296          1.1    jruoho 
    297      1.1.1.8  christos     if (AcpiGbl_ParseTableAsTermList)
    298          1.1    jruoho     {
    299      1.1.1.8  christos         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start load pass\n"));
    300          1.1    jruoho 
    301      1.1.1.8  christos         Status = AcpiNsExecuteTable (TableIndex, StartNode);
    302      1.1.1.8  christos         if (ACPI_FAILURE (Status))
    303      1.1.1.8  christos         {
    304      1.1.1.8  christos             return_ACPI_STATUS (Status);
    305      1.1.1.8  christos         }
    306      1.1.1.8  christos     }
    307      1.1.1.8  christos     else
    308          1.1    jruoho     {
    309      1.1.1.8  christos         /*
    310      1.1.1.8  christos          * AML Parse, pass 1
    311      1.1.1.8  christos          *
    312      1.1.1.8  christos          * In this pass, we load most of the namespace. Control methods
    313      1.1.1.8  christos          * are not parsed until later. A parse tree is not created.
    314      1.1.1.8  christos          * Instead, each Parser Op subtree is deleted when it is finished.
    315      1.1.1.8  christos          * This saves a great deal of memory, and allows a small cache of
    316      1.1.1.8  christos          * parse objects to service the entire parse. The second pass of
    317      1.1.1.8  christos          * the parse then performs another complete parse of the AML.
    318      1.1.1.8  christos          */
    319      1.1.1.8  christos         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
    320      1.1.1.8  christos 
    321      1.1.1.8  christos         Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
    322      1.1.1.8  christos             TableIndex, StartNode);
    323      1.1.1.8  christos         if (ACPI_FAILURE (Status))
    324      1.1.1.8  christos         {
    325      1.1.1.8  christos             return_ACPI_STATUS (Status);
    326      1.1.1.8  christos         }
    327      1.1.1.8  christos 
    328      1.1.1.8  christos         /*
    329      1.1.1.8  christos          * AML Parse, pass 2
    330      1.1.1.8  christos          *
    331      1.1.1.8  christos          * In this pass, we resolve forward references and other things
    332      1.1.1.8  christos          * that could not be completed during the first pass.
    333      1.1.1.8  christos          * Another complete parse of the AML is performed, but the
    334      1.1.1.8  christos          * overhead of this is compensated for by the fact that the
    335      1.1.1.8  christos          * parse objects are all cached.
    336      1.1.1.8  christos          */
    337      1.1.1.8  christos         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
    338      1.1.1.8  christos         Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
    339      1.1.1.8  christos             TableIndex, StartNode);
    340      1.1.1.8  christos         if (ACPI_FAILURE (Status))
    341      1.1.1.8  christos         {
    342      1.1.1.8  christos             return_ACPI_STATUS (Status);
    343      1.1.1.8  christos         }
    344          1.1    jruoho     }
    345          1.1    jruoho 
    346          1.1    jruoho     return_ACPI_STATUS (Status);
    347          1.1    jruoho }
    348