Home | History | Annotate | Line # | Download | only in namespace
nsparse.c revision 1.1.1.13.4.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.13.4.1   thorpej  * Copyright (C) 2000 - 2021, 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.13.4.1   thorpej  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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.10  christos  * DESCRIPTION: Load ACPI/AML table by executing the entire table as a single
     67      1.1.1.10  christos  *              large control method.
     68      1.1.1.10  christos  *
     69      1.1.1.10  christos  * NOTE: The point of this is to execute any module-level code in-place
     70      1.1.1.10  christos  * as the table is parsed. Some AML code depends on this behavior.
     71      1.1.1.10  christos  *
     72      1.1.1.10  christos  * It is a run-time option at this time, but will eventually become
     73      1.1.1.10  christos  * the default.
     74      1.1.1.10  christos  *
     75      1.1.1.10  christos  * Note: This causes the table to only have a single-pass parse.
     76      1.1.1.10  christos  * However, this is compatible with other ACPI implementations.
     77       1.1.1.8  christos  *
     78       1.1.1.8  christos  ******************************************************************************/
     79       1.1.1.8  christos 
     80       1.1.1.8  christos ACPI_STATUS
     81       1.1.1.8  christos AcpiNsExecuteTable (
     82       1.1.1.8  christos     UINT32                  TableIndex,
     83       1.1.1.8  christos     ACPI_NAMESPACE_NODE     *StartNode)
     84       1.1.1.8  christos {
     85       1.1.1.8  christos     ACPI_STATUS             Status;
     86       1.1.1.8  christos     ACPI_TABLE_HEADER       *Table;
     87       1.1.1.8  christos     ACPI_OWNER_ID           OwnerId;
     88       1.1.1.8  christos     ACPI_EVALUATE_INFO      *Info = NULL;
     89       1.1.1.8  christos     UINT32                  AmlLength;
     90       1.1.1.8  christos     UINT8                   *AmlStart;
     91       1.1.1.8  christos     ACPI_OPERAND_OBJECT     *MethodObj = NULL;
     92       1.1.1.8  christos 
     93       1.1.1.8  christos 
     94       1.1.1.8  christos     ACPI_FUNCTION_TRACE (NsExecuteTable);
     95       1.1.1.8  christos 
     96       1.1.1.8  christos 
     97       1.1.1.8  christos     Status = AcpiGetTableByIndex (TableIndex, &Table);
     98       1.1.1.8  christos     if (ACPI_FAILURE (Status))
     99       1.1.1.8  christos     {
    100       1.1.1.8  christos         return_ACPI_STATUS (Status);
    101       1.1.1.8  christos     }
    102       1.1.1.8  christos 
    103       1.1.1.8  christos     /* Table must consist of at least a complete header */
    104       1.1.1.8  christos 
    105       1.1.1.8  christos     if (Table->Length < sizeof (ACPI_TABLE_HEADER))
    106       1.1.1.8  christos     {
    107       1.1.1.8  christos         return_ACPI_STATUS (AE_BAD_HEADER);
    108       1.1.1.8  christos     }
    109       1.1.1.8  christos 
    110       1.1.1.8  christos     AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
    111       1.1.1.8  christos     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
    112       1.1.1.8  christos 
    113       1.1.1.8  christos     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
    114       1.1.1.8  christos     if (ACPI_FAILURE (Status))
    115       1.1.1.8  christos     {
    116       1.1.1.8  christos         return_ACPI_STATUS (Status);
    117       1.1.1.8  christos     }
    118       1.1.1.8  christos 
    119       1.1.1.8  christos     /* Create, initialize, and link a new temporary method object */
    120       1.1.1.8  christos 
    121       1.1.1.8  christos     MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
    122       1.1.1.8  christos     if (!MethodObj)
    123       1.1.1.8  christos     {
    124       1.1.1.8  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    125       1.1.1.8  christos     }
    126       1.1.1.8  christos 
    127       1.1.1.8  christos     /* Allocate the evaluation information block */
    128       1.1.1.8  christos 
    129       1.1.1.8  christos     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    130       1.1.1.8  christos     if (!Info)
    131       1.1.1.8  christos     {
    132       1.1.1.8  christos         Status = AE_NO_MEMORY;
    133       1.1.1.8  christos         goto Cleanup;
    134       1.1.1.8  christos     }
    135       1.1.1.8  christos 
    136      1.1.1.10  christos     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
    137      1.1.1.10  christos         "%s: Create table pseudo-method for [%4.4s] @%p, method %p\n",
    138      1.1.1.10  christos         ACPI_GET_FUNCTION_NAME, Table->Signature, Table, MethodObj));
    139       1.1.1.8  christos 
    140       1.1.1.8  christos     MethodObj->Method.AmlStart = AmlStart;
    141       1.1.1.8  christos     MethodObj->Method.AmlLength = AmlLength;
    142       1.1.1.8  christos     MethodObj->Method.OwnerId = OwnerId;
    143       1.1.1.8  christos     MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
    144       1.1.1.8  christos 
    145       1.1.1.8  christos     Info->PassNumber = ACPI_IMODE_EXECUTE;
    146       1.1.1.8  christos     Info->Node = StartNode;
    147       1.1.1.8  christos     Info->ObjDesc = MethodObj;
    148       1.1.1.8  christos     Info->NodeFlags = Info->Node->Flags;
    149       1.1.1.8  christos     Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);
    150       1.1.1.8  christos     if (!Info->FullPathname)
    151       1.1.1.8  christos     {
    152       1.1.1.8  christos         Status = AE_NO_MEMORY;
    153       1.1.1.8  christos         goto Cleanup;
    154       1.1.1.8  christos     }
    155       1.1.1.8  christos 
    156      1.1.1.11  christos     /* Optional object evaluation log */
    157      1.1.1.11  christos 
    158      1.1.1.11  christos     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,
    159      1.1.1.11  christos         "%-26s:  (Definition Block level)\n", "Module-level evaluation"));
    160      1.1.1.11  christos 
    161       1.1.1.8  christos     Status = AcpiPsExecuteTable (Info);
    162       1.1.1.8  christos 
    163      1.1.1.11  christos     /* Optional object evaluation log */
    164      1.1.1.11  christos 
    165      1.1.1.11  christos     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,
    166      1.1.1.11  christos         "%-26s:  (Definition Block level)\n", "Module-level complete"));
    167      1.1.1.11  christos 
    168       1.1.1.8  christos Cleanup:
    169       1.1.1.8  christos     if (Info)
    170       1.1.1.8  christos     {
    171       1.1.1.8  christos         ACPI_FREE (Info->FullPathname);
    172       1.1.1.8  christos         Info->FullPathname = NULL;
    173       1.1.1.8  christos     }
    174       1.1.1.8  christos     ACPI_FREE (Info);
    175       1.1.1.8  christos     AcpiUtRemoveReference (MethodObj);
    176       1.1.1.8  christos     return_ACPI_STATUS (Status);
    177       1.1.1.8  christos }
    178       1.1.1.8  christos 
    179       1.1.1.8  christos 
    180       1.1.1.8  christos /*******************************************************************************
    181       1.1.1.8  christos  *
    182           1.1    jruoho  * FUNCTION:    NsOneCompleteParse
    183           1.1    jruoho  *
    184           1.1    jruoho  * PARAMETERS:  PassNumber              - 1 or 2
    185           1.1    jruoho  *              TableDesc               - The table to be parsed.
    186           1.1    jruoho  *
    187           1.1    jruoho  * RETURN:      Status
    188           1.1    jruoho  *
    189           1.1    jruoho  * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
    190           1.1    jruoho  *
    191           1.1    jruoho  ******************************************************************************/
    192           1.1    jruoho 
    193           1.1    jruoho ACPI_STATUS
    194           1.1    jruoho AcpiNsOneCompleteParse (
    195           1.1    jruoho     UINT32                  PassNumber,
    196           1.1    jruoho     UINT32                  TableIndex,
    197           1.1    jruoho     ACPI_NAMESPACE_NODE     *StartNode)
    198           1.1    jruoho {
    199           1.1    jruoho     ACPI_PARSE_OBJECT       *ParseRoot;
    200           1.1    jruoho     ACPI_STATUS             Status;
    201           1.1    jruoho     UINT32                  AmlLength;
    202           1.1    jruoho     UINT8                   *AmlStart;
    203           1.1    jruoho     ACPI_WALK_STATE         *WalkState;
    204           1.1    jruoho     ACPI_TABLE_HEADER       *Table;
    205           1.1    jruoho     ACPI_OWNER_ID           OwnerId;
    206           1.1    jruoho 
    207           1.1    jruoho 
    208           1.1    jruoho     ACPI_FUNCTION_TRACE (NsOneCompleteParse);
    209           1.1    jruoho 
    210           1.1    jruoho 
    211       1.1.1.6  christos     Status = AcpiGetTableByIndex (TableIndex, &Table);
    212       1.1.1.6  christos     if (ACPI_FAILURE (Status))
    213       1.1.1.6  christos     {
    214       1.1.1.6  christos         return_ACPI_STATUS (Status);
    215       1.1.1.6  christos     }
    216       1.1.1.6  christos 
    217       1.1.1.6  christos     /* Table must consist of at least a complete header */
    218       1.1.1.6  christos 
    219       1.1.1.6  christos     if (Table->Length < sizeof (ACPI_TABLE_HEADER))
    220       1.1.1.6  christos     {
    221       1.1.1.6  christos         return_ACPI_STATUS (AE_BAD_HEADER);
    222       1.1.1.6  christos     }
    223       1.1.1.6  christos 
    224       1.1.1.6  christos     AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
    225       1.1.1.6  christos     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
    226       1.1.1.6  christos 
    227           1.1    jruoho     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
    228           1.1    jruoho     if (ACPI_FAILURE (Status))
    229           1.1    jruoho     {
    230           1.1    jruoho         return_ACPI_STATUS (Status);
    231           1.1    jruoho     }
    232           1.1    jruoho 
    233           1.1    jruoho     /* Create and init a Root Node */
    234           1.1    jruoho 
    235       1.1.1.6  christos     ParseRoot = AcpiPsCreateScopeOp (AmlStart);
    236           1.1    jruoho     if (!ParseRoot)
    237           1.1    jruoho     {
    238           1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    239           1.1    jruoho     }
    240           1.1    jruoho 
    241           1.1    jruoho     /* Create and initialize a new walk state */
    242           1.1    jruoho 
    243           1.1    jruoho     WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
    244           1.1    jruoho     if (!WalkState)
    245           1.1    jruoho     {
    246           1.1    jruoho         AcpiPsFreeOp (ParseRoot);
    247           1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    248           1.1    jruoho     }
    249           1.1    jruoho 
    250       1.1.1.6  christos     Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
    251       1.1.1.7  christos         AmlStart, AmlLength, NULL, (UINT8) PassNumber);
    252           1.1    jruoho     if (ACPI_FAILURE (Status))
    253           1.1    jruoho     {
    254           1.1    jruoho         AcpiDsDeleteWalkState (WalkState);
    255       1.1.1.6  christos         goto Cleanup;
    256           1.1    jruoho     }
    257           1.1    jruoho 
    258       1.1.1.6  christos     /* Found OSDT table, enable the namespace override feature */
    259           1.1    jruoho 
    260      1.1.1.12  christos     if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_OSDT) &&
    261       1.1.1.6  christos         PassNumber == ACPI_IMODE_LOAD_PASS1)
    262           1.1    jruoho     {
    263       1.1.1.6  christos         WalkState->NamespaceOverride = TRUE;
    264           1.1    jruoho     }
    265           1.1    jruoho 
    266           1.1    jruoho     /* StartNode is the default location to load the table  */
    267           1.1    jruoho 
    268           1.1    jruoho     if (StartNode && StartNode != AcpiGbl_RootNode)
    269           1.1    jruoho     {
    270       1.1.1.7  christos         Status = AcpiDsScopeStackPush (
    271       1.1.1.7  christos             StartNode, ACPI_TYPE_METHOD, WalkState);
    272           1.1    jruoho         if (ACPI_FAILURE (Status))
    273           1.1    jruoho         {
    274           1.1    jruoho             AcpiDsDeleteWalkState (WalkState);
    275           1.1    jruoho             goto Cleanup;
    276           1.1    jruoho         }
    277           1.1    jruoho     }
    278           1.1    jruoho 
    279           1.1    jruoho     /* Parse the AML */
    280           1.1    jruoho 
    281       1.1.1.7  christos     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
    282       1.1.1.7  christos         "*PARSE* pass %u parse\n", PassNumber));
    283       1.1.1.8  christos     AcpiExEnterInterpreter ();
    284           1.1    jruoho     Status = AcpiPsParseAml (WalkState);
    285       1.1.1.8  christos     AcpiExExitInterpreter ();
    286           1.1    jruoho 
    287           1.1    jruoho Cleanup:
    288           1.1    jruoho     AcpiPsDeleteParseTree (ParseRoot);
    289           1.1    jruoho     return_ACPI_STATUS (Status);
    290           1.1    jruoho }
    291           1.1    jruoho 
    292           1.1    jruoho 
    293           1.1    jruoho /*******************************************************************************
    294           1.1    jruoho  *
    295           1.1    jruoho  * FUNCTION:    AcpiNsParseTable
    296           1.1    jruoho  *
    297           1.1    jruoho  * PARAMETERS:  TableDesc       - An ACPI table descriptor for table to parse
    298           1.1    jruoho  *              StartNode       - Where to enter the table into the namespace
    299           1.1    jruoho  *
    300           1.1    jruoho  * RETURN:      Status
    301           1.1    jruoho  *
    302           1.1    jruoho  * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
    303           1.1    jruoho  *
    304           1.1    jruoho  ******************************************************************************/
    305           1.1    jruoho 
    306           1.1    jruoho ACPI_STATUS
    307           1.1    jruoho AcpiNsParseTable (
    308           1.1    jruoho     UINT32                  TableIndex,
    309           1.1    jruoho     ACPI_NAMESPACE_NODE     *StartNode)
    310           1.1    jruoho {
    311           1.1    jruoho     ACPI_STATUS             Status;
    312           1.1    jruoho 
    313           1.1    jruoho 
    314           1.1    jruoho     ACPI_FUNCTION_TRACE (NsParseTable);
    315           1.1    jruoho 
    316           1.1    jruoho 
    317      1.1.1.12  christos     /*
    318      1.1.1.12  christos      * Executes the AML table as one large control method.
    319      1.1.1.12  christos      * The point of this is to execute any module-level code in-place
    320      1.1.1.12  christos      * as the table is parsed. Some AML code depends on this behavior.
    321      1.1.1.12  christos      *
    322      1.1.1.12  christos      * Note: This causes the table to only have a single-pass parse.
    323      1.1.1.12  christos      * However, this is compatible with other ACPI implementations.
    324      1.1.1.12  christos      */
    325      1.1.1.12  christos     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
    326      1.1.1.12  christos         "%s: **** Start table execution pass\n", ACPI_GET_FUNCTION_NAME));
    327       1.1.1.8  christos 
    328      1.1.1.12  christos     Status = AcpiNsExecuteTable (TableIndex, StartNode);
    329           1.1    jruoho 
    330           1.1    jruoho     return_ACPI_STATUS (Status);
    331           1.1    jruoho }
    332