Path: blob/main/sys/contrib/dev/acpica/components/namespace/nsparse.c
48524 views
/******************************************************************************1*2* Module Name: nsparse - namespace interface to AML parser3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acnamesp.h>154#include <contrib/dev/acpica/include/acparser.h>155#include <contrib/dev/acpica/include/acdispat.h>156#include <contrib/dev/acpica/include/actables.h>157#include <contrib/dev/acpica/include/acinterp.h>158159160#define _COMPONENT ACPI_NAMESPACE161ACPI_MODULE_NAME ("nsparse")162163164/*******************************************************************************165*166* FUNCTION: NsExecuteTable167*168* PARAMETERS: TableDesc - An ACPI table descriptor for table to parse169* StartNode - Where to enter the table into the namespace170*171* RETURN: Status172*173* DESCRIPTION: Load ACPI/AML table by executing the entire table as a single174* large control method.175*176* NOTE: The point of this is to execute any module-level code in-place177* as the table is parsed. Some AML code depends on this behavior.178*179* It is a run-time option at this time, but will eventually become180* the default.181*182* Note: This causes the table to only have a single-pass parse.183* However, this is compatible with other ACPI implementations.184*185******************************************************************************/186187ACPI_STATUS188AcpiNsExecuteTable (189UINT32 TableIndex,190ACPI_NAMESPACE_NODE *StartNode)191{192ACPI_STATUS Status;193ACPI_TABLE_HEADER *Table;194ACPI_OWNER_ID OwnerId;195ACPI_EVALUATE_INFO *Info = NULL;196UINT32 AmlLength;197UINT8 *AmlStart;198ACPI_OPERAND_OBJECT *MethodObj = NULL;199200201ACPI_FUNCTION_TRACE (NsExecuteTable);202203204Status = AcpiGetTableByIndex (TableIndex, &Table);205if (ACPI_FAILURE (Status))206{207return_ACPI_STATUS (Status);208}209210/* Table must consist of at least a complete header */211212if (Table->Length < sizeof (ACPI_TABLE_HEADER))213{214return_ACPI_STATUS (AE_BAD_HEADER);215}216217AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);218AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);219220Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);221if (ACPI_FAILURE (Status))222{223return_ACPI_STATUS (Status);224}225226/* Create, initialize, and link a new temporary method object */227228MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);229if (!MethodObj)230{231return_ACPI_STATUS (AE_NO_MEMORY);232}233234/* Allocate the evaluation information block */235236Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));237if (!Info)238{239Status = AE_NO_MEMORY;240goto Cleanup;241}242243ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,244"%s: Create table pseudo-method for [%4.4s] @%p, method %p\n",245ACPI_GET_FUNCTION_NAME, Table->Signature, Table, MethodObj));246247MethodObj->Method.AmlStart = AmlStart;248MethodObj->Method.AmlLength = AmlLength;249MethodObj->Method.OwnerId = OwnerId;250MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;251252Info->PassNumber = ACPI_IMODE_EXECUTE;253Info->Node = StartNode;254Info->ObjDesc = MethodObj;255Info->NodeFlags = Info->Node->Flags;256Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);257if (!Info->FullPathname)258{259Status = AE_NO_MEMORY;260goto Cleanup;261}262263/* Optional object evaluation log */264265ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,266"%-26s: (Definition Block level)\n", "Module-level evaluation"));267268Status = AcpiPsExecuteTable (Info);269270/* Optional object evaluation log */271272ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,273"%-26s: (Definition Block level)\n", "Module-level complete"));274275Cleanup:276if (Info)277{278ACPI_FREE (Info->FullPathname);279Info->FullPathname = NULL;280}281ACPI_FREE (Info);282AcpiUtRemoveReference (MethodObj);283return_ACPI_STATUS (Status);284}285286287/*******************************************************************************288*289* FUNCTION: NsOneCompleteParse290*291* PARAMETERS: PassNumber - 1 or 2292* TableDesc - The table to be parsed.293*294* RETURN: Status295*296* DESCRIPTION: Perform one complete parse of an ACPI/AML table.297*298******************************************************************************/299300ACPI_STATUS301AcpiNsOneCompleteParse (302UINT32 PassNumber,303UINT32 TableIndex,304ACPI_NAMESPACE_NODE *StartNode)305{306ACPI_PARSE_OBJECT *ParseRoot;307ACPI_STATUS Status;308UINT32 AmlLength;309UINT8 *AmlStart;310ACPI_WALK_STATE *WalkState;311ACPI_TABLE_HEADER *Table;312ACPI_OWNER_ID OwnerId;313314315ACPI_FUNCTION_TRACE (NsOneCompleteParse);316317318Status = AcpiGetTableByIndex (TableIndex, &Table);319if (ACPI_FAILURE (Status))320{321return_ACPI_STATUS (Status);322}323324/* Table must consist of at least a complete header */325326if (Table->Length < sizeof (ACPI_TABLE_HEADER))327{328return_ACPI_STATUS (AE_BAD_HEADER);329}330331AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);332AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);333334Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);335if (ACPI_FAILURE (Status))336{337return_ACPI_STATUS (Status);338}339340/* Create and init a Root Node */341342ParseRoot = AcpiPsCreateScopeOp (AmlStart);343if (!ParseRoot)344{345return_ACPI_STATUS (AE_NO_MEMORY);346}347348/* Create and initialize a new walk state */349350WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);351if (!WalkState)352{353AcpiPsFreeOp (ParseRoot);354return_ACPI_STATUS (AE_NO_MEMORY);355}356357Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,358AmlStart, AmlLength, NULL, (UINT8) PassNumber);359if (ACPI_FAILURE (Status))360{361AcpiDsDeleteWalkState (WalkState);362goto Cleanup;363}364365/* Found OSDT table, enable the namespace override feature */366367if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_OSDT) &&368PassNumber == ACPI_IMODE_LOAD_PASS1)369{370WalkState->NamespaceOverride = TRUE;371}372373/* StartNode is the default location to load the table */374375if (StartNode && StartNode != AcpiGbl_RootNode)376{377Status = AcpiDsScopeStackPush (378StartNode, ACPI_TYPE_METHOD, WalkState);379if (ACPI_FAILURE (Status))380{381AcpiDsDeleteWalkState (WalkState);382goto Cleanup;383}384}385386/* Parse the AML */387388ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,389"*PARSE* pass %u parse\n", PassNumber));390AcpiExEnterInterpreter ();391Status = AcpiPsParseAml (WalkState);392AcpiExExitInterpreter ();393394Cleanup:395AcpiPsDeleteParseTree (ParseRoot);396return_ACPI_STATUS (Status);397}398399400/*******************************************************************************401*402* FUNCTION: AcpiNsParseTable403*404* PARAMETERS: TableDesc - An ACPI table descriptor for table to parse405* StartNode - Where to enter the table into the namespace406*407* RETURN: Status408*409* DESCRIPTION: Parse AML within an ACPI table and return a tree of ops410*411******************************************************************************/412413ACPI_STATUS414AcpiNsParseTable (415UINT32 TableIndex,416ACPI_NAMESPACE_NODE *StartNode)417{418ACPI_STATUS Status;419420421ACPI_FUNCTION_TRACE (NsParseTable);422423424/*425* Executes the AML table as one large control method.426* The point of this is to execute any module-level code in-place427* as the table is parsed. Some AML code depends on this behavior.428*429* Note: This causes the table to only have a single-pass parse.430* However, this is compatible with other ACPI implementations.431*/432ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,433"%s: **** Start table execution pass\n", ACPI_GET_FUNCTION_NAME));434435Status = AcpiNsExecuteTable (TableIndex, StartNode);436437return_ACPI_STATUS (Status);438}439440441