Path: blob/main/sys/contrib/dev/acpica/components/dispatcher/dsargs.c
48521 views
/******************************************************************************1*2* Module Name: dsargs - Support for execution of dynamic arguments for static3* objects (regions, fields, buffer fields, etc.)4*5*****************************************************************************/67/******************************************************************************8*9* 1. Copyright Notice10*11* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.12* All rights reserved.13*14* 2. License15*16* 2.1. This is your license from Intel Corp. under its intellectual property17* rights. You may have additional license terms from the party that provided18* you this software, covering your right to use that party's intellectual19* property rights.20*21* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a22* copy of the source code appearing in this file ("Covered Code") an23* irrevocable, perpetual, worldwide license under Intel's copyrights in the24* base code distributed originally by Intel ("Original Intel Code") to copy,25* make derivatives, distribute, use and display any portion of the Covered26* Code in any form, with the right to sublicense such rights; and27*28* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent29* license (with the right to sublicense), under only those claims of Intel30* patents that are infringed by the Original Intel Code, to make, use, sell,31* offer to sell, and import the Covered Code and derivative works thereof32* solely to the minimum extent necessary to exercise the above copyright33* license, and in no event shall the patent license extend to any additions34* to or modifications of the Original Intel Code. No other license or right35* is granted directly or by implication, estoppel or otherwise;36*37* The above copyright and patent license is granted only if the following38* conditions are met:39*40* 3. Conditions41*42* 3.1. Redistribution of Source with Rights to Further Distribute Source.43* Redistribution of source code of any substantial portion of the Covered44* Code or modification with rights to further distribute source must include45* the above Copyright Notice, the above License, this list of Conditions,46* and the following Disclaimer and Export Compliance provision. In addition,47* Licensee must cause all Covered Code to which Licensee contributes to48* contain a file documenting the changes Licensee made to create that Covered49* Code and the date of any change. Licensee must include in that file the50* documentation of any changes made by any predecessor Licensee. Licensee51* must include a prominent statement that the modification is derived,52* directly or indirectly, from Original Intel Code.53*54* 3.2. Redistribution of Source with no Rights to Further Distribute Source.55* Redistribution of source code of any substantial portion of the Covered56* Code or modification without rights to further distribute source must57* include the following Disclaimer and Export Compliance provision in the58* documentation and/or other materials provided with distribution. In59* addition, Licensee may not authorize further sublicense of source of any60* portion of the Covered Code, and must include terms to the effect that the61* license from Licensee to its licensee is limited to the intellectual62* property embodied in the software Licensee provides to its licensee, and63* not to intellectual property embodied in modifications its licensee may64* make.65*66* 3.3. Redistribution of Executable. Redistribution in executable form of any67* substantial portion of the Covered Code or modification must reproduce the68* above Copyright Notice, and the following Disclaimer and Export Compliance69* provision in the documentation and/or other materials provided with the70* distribution.71*72* 3.4. Intel retains all right, title, and interest in and to the Original73* Intel Code.74*75* 3.5. Neither the name Intel nor any other trademark owned or controlled by76* Intel shall be used in advertising or otherwise to promote the sale, use or77* other dealings in products derived from or relating to the Covered Code78* without prior written authorization from Intel.79*80* 4. Disclaimer and Export Compliance81*82* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED83* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE84* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,85* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY86* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY87* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A88* PARTICULAR PURPOSE.89*90* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES91* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR92* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,93* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY94* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL95* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS96* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY97* LIMITED REMEDY.98*99* 4.3. Licensee shall not export, either directly or indirectly, any of this100* software or system incorporating such software without first obtaining any101* required license or other approval from the U. S. Department of Commerce or102* any other agency or department of the United States Government. In the103* event Licensee exports any such software from the United States or104* re-exports any such software from a foreign destination, Licensee shall105* ensure that the distribution and export/re-export of the software is in106* compliance with all laws, regulations, orders, or other restrictions of the107* U.S. Export Administration Regulations. Licensee agrees that neither it nor108* any of its subsidiaries will export/re-export any technical data, process,109* software, or service, directly or indirectly, to any country for which the110* United States government or any agency thereof requires an export license,111* other governmental approval, or letter of assurance, without first obtaining112* such license, approval or letter.113*114*****************************************************************************115*116* Alternatively, you may choose to be licensed under the terms of the117* following license:118*119* Redistribution and use in source and binary forms, with or without120* modification, are permitted provided that the following conditions121* are met:122* 1. Redistributions of source code must retain the above copyright123* notice, this list of conditions, and the following disclaimer,124* without modification.125* 2. Redistributions in binary form must reproduce at minimum a disclaimer126* substantially similar to the "NO WARRANTY" disclaimer below127* ("Disclaimer") and any redistribution must be conditioned upon128* including a substantially similar Disclaimer requirement for further129* binary redistribution.130* 3. Neither the names of the above-listed copyright holders nor the names131* of any contributors may be used to endorse or promote products derived132* from this software without specific prior written permission.133*134* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS135* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT136* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR137* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT138* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,139* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT140* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,141* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY142* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT143* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE144* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.145*146* Alternatively, you may choose to be licensed under the terms of the147* GNU General Public License ("GPL") version 2 as published by the Free148* Software Foundation.149*150*****************************************************************************/151152#include <contrib/dev/acpica/include/acpi.h>153#include <contrib/dev/acpica/include/accommon.h>154#include <contrib/dev/acpica/include/acparser.h>155#include <contrib/dev/acpica/include/amlcode.h>156#include <contrib/dev/acpica/include/acdispat.h>157#include <contrib/dev/acpica/include/acnamesp.h>158159#define _COMPONENT ACPI_DISPATCHER160ACPI_MODULE_NAME ("dsargs")161162/* Local prototypes */163164static ACPI_STATUS165AcpiDsExecuteArguments (166ACPI_NAMESPACE_NODE *Node,167ACPI_NAMESPACE_NODE *ScopeNode,168UINT32 AmlLength,169UINT8 *AmlStart);170171172/*******************************************************************************173*174* FUNCTION: AcpiDsExecuteArguments175*176* PARAMETERS: Node - Object NS node177* ScopeNode - Parent NS node178* AmlLength - Length of executable AML179* AmlStart - Pointer to the AML180*181* RETURN: Status.182*183* DESCRIPTION: Late (deferred) execution of region or field arguments184*185******************************************************************************/186187static ACPI_STATUS188AcpiDsExecuteArguments (189ACPI_NAMESPACE_NODE *Node,190ACPI_NAMESPACE_NODE *ScopeNode,191UINT32 AmlLength,192UINT8 *AmlStart)193{194ACPI_STATUS Status;195ACPI_PARSE_OBJECT *Op;196ACPI_WALK_STATE *WalkState;197198199ACPI_FUNCTION_TRACE_PTR (DsExecuteArguments, AmlStart);200201202/* Allocate a new parser op to be the root of the parsed tree */203204Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart);205if (!Op)206{207return_ACPI_STATUS (AE_NO_MEMORY);208}209210/* Save the Node for use in AcpiPsParseAml */211212Op->Common.Node = ScopeNode;213214/* Create and initialize a new parser state */215216WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);217if (!WalkState)218{219Status = AE_NO_MEMORY;220goto Cleanup;221}222223Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,224AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);225if (ACPI_FAILURE (Status))226{227AcpiDsDeleteWalkState (WalkState);228goto Cleanup;229}230231/* Mark this parse as a deferred opcode */232233WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;234WalkState->DeferredNode = Node;235236/* Pass1: Parse the entire declaration */237238Status = AcpiPsParseAml (WalkState);239if (ACPI_FAILURE (Status))240{241goto Cleanup;242}243244/* Get and init the Op created above */245246Op->Common.Node = Node;247AcpiPsDeleteParseTree (Op);248249/* Evaluate the deferred arguments */250251Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart);252if (!Op)253{254return_ACPI_STATUS (AE_NO_MEMORY);255}256257Op->Common.Node = ScopeNode;258259/* Create and initialize a new parser state */260261WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);262if (!WalkState)263{264Status = AE_NO_MEMORY;265goto Cleanup;266}267268/* Execute the opcode and arguments */269270Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,271AmlLength, NULL, ACPI_IMODE_EXECUTE);272if (ACPI_FAILURE (Status))273{274AcpiDsDeleteWalkState (WalkState);275goto Cleanup;276}277278/* Mark this execution as a deferred opcode */279280WalkState->DeferredNode = Node;281Status = AcpiPsParseAml (WalkState);282283Cleanup:284AcpiPsDeleteParseTree (Op);285return_ACPI_STATUS (Status);286}287288289/*******************************************************************************290*291* FUNCTION: AcpiDsGetBufferFieldArguments292*293* PARAMETERS: ObjDesc - A valid BufferField object294*295* RETURN: Status.296*297* DESCRIPTION: Get BufferField Buffer and Index. This implements the late298* evaluation of these field attributes.299*300******************************************************************************/301302ACPI_STATUS303AcpiDsGetBufferFieldArguments (304ACPI_OPERAND_OBJECT *ObjDesc)305{306ACPI_OPERAND_OBJECT *ExtraDesc;307ACPI_NAMESPACE_NODE *Node;308ACPI_STATUS Status;309310311ACPI_FUNCTION_TRACE_PTR (DsGetBufferFieldArguments, ObjDesc);312313314if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)315{316return_ACPI_STATUS (AE_OK);317}318319/* Get the AML pointer (method object) and BufferField node */320321ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);322Node = ObjDesc->BufferField.Node;323324ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (325ACPI_TYPE_BUFFER_FIELD, Node, NULL));326327ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",328AcpiUtGetNodeName (Node)));329330/* Execute the AML code for the TermArg arguments */331332Status = AcpiDsExecuteArguments (Node, Node->Parent,333ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);334return_ACPI_STATUS (Status);335}336337338/*******************************************************************************339*340* FUNCTION: AcpiDsGetBankFieldArguments341*342* PARAMETERS: ObjDesc - A valid BankField object343*344* RETURN: Status.345*346* DESCRIPTION: Get BankField BankValue. This implements the late347* evaluation of these field attributes.348*349******************************************************************************/350351ACPI_STATUS352AcpiDsGetBankFieldArguments (353ACPI_OPERAND_OBJECT *ObjDesc)354{355ACPI_OPERAND_OBJECT *ExtraDesc;356ACPI_NAMESPACE_NODE *Node;357ACPI_STATUS Status;358359360ACPI_FUNCTION_TRACE_PTR (DsGetBankFieldArguments, ObjDesc);361362363if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)364{365return_ACPI_STATUS (AE_OK);366}367368/* Get the AML pointer (method object) and BankField node */369370ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);371Node = ObjDesc->BankField.Node;372373ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (374ACPI_TYPE_LOCAL_BANK_FIELD, Node, NULL));375376ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",377AcpiUtGetNodeName (Node)));378379/* Execute the AML code for the TermArg arguments */380381Status = AcpiDsExecuteArguments (Node, Node->Parent,382ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);383return_ACPI_STATUS (Status);384}385386387/*******************************************************************************388*389* FUNCTION: AcpiDsGetBufferArguments390*391* PARAMETERS: ObjDesc - A valid Buffer object392*393* RETURN: Status.394*395* DESCRIPTION: Get Buffer length and initializer byte list. This implements396* the late evaluation of these attributes.397*398******************************************************************************/399400ACPI_STATUS401AcpiDsGetBufferArguments (402ACPI_OPERAND_OBJECT *ObjDesc)403{404ACPI_NAMESPACE_NODE *Node;405ACPI_STATUS Status;406407408ACPI_FUNCTION_TRACE_PTR (DsGetBufferArguments, ObjDesc);409410411if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)412{413return_ACPI_STATUS (AE_OK);414}415416/* Get the Buffer node */417418Node = ObjDesc->Buffer.Node;419if (!Node)420{421ACPI_ERROR ((AE_INFO,422"No pointer back to namespace node in buffer object %p",423ObjDesc));424return_ACPI_STATUS (AE_AML_INTERNAL);425}426427ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));428429/* Execute the AML code for the TermArg arguments */430431Status = AcpiDsExecuteArguments (Node, Node,432ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);433return_ACPI_STATUS (Status);434}435436437/*******************************************************************************438*439* FUNCTION: AcpiDsGetPackageArguments440*441* PARAMETERS: ObjDesc - A valid Package object442*443* RETURN: Status.444*445* DESCRIPTION: Get Package length and initializer byte list. This implements446* the late evaluation of these attributes.447*448******************************************************************************/449450ACPI_STATUS451AcpiDsGetPackageArguments (452ACPI_OPERAND_OBJECT *ObjDesc)453{454ACPI_NAMESPACE_NODE *Node;455ACPI_STATUS Status;456457458ACPI_FUNCTION_TRACE_PTR (DsGetPackageArguments, ObjDesc);459460461if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)462{463return_ACPI_STATUS (AE_OK);464}465466/* Get the Package node */467468Node = ObjDesc->Package.Node;469if (!Node)470{471ACPI_ERROR ((AE_INFO,472"No pointer back to namespace node in package %p", ObjDesc));473return_ACPI_STATUS (AE_AML_INTERNAL);474}475476ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Argument Init, AML Ptr: %p\n",477ObjDesc->Package.AmlStart));478479/* Execute the AML code for the TermArg arguments */480481Status = AcpiDsExecuteArguments (Node, Node,482ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);483484return_ACPI_STATUS (Status);485}486487488/*******************************************************************************489*490* FUNCTION: AcpiDsGetRegionArguments491*492* PARAMETERS: ObjDesc - A valid region object493*494* RETURN: Status.495*496* DESCRIPTION: Get region address and length. This implements the late497* evaluation of these region attributes.498*499******************************************************************************/500501ACPI_STATUS502AcpiDsGetRegionArguments (503ACPI_OPERAND_OBJECT *ObjDesc)504{505ACPI_NAMESPACE_NODE *Node;506ACPI_STATUS Status;507ACPI_OPERAND_OBJECT *ExtraDesc;508509510ACPI_FUNCTION_TRACE_PTR (DsGetRegionArguments, ObjDesc);511512513if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)514{515return_ACPI_STATUS (AE_OK);516}517518ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);519if (!ExtraDesc)520{521return_ACPI_STATUS (AE_NOT_EXIST);522}523524/* Get the Region node */525526Node = ObjDesc->Region.Node;527528ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (529ACPI_TYPE_REGION, Node, NULL));530531ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,532"[%4.4s] OpRegion Arg Init at AML %p\n",533AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));534535/* Execute the argument AML */536537Status = AcpiDsExecuteArguments (Node, ExtraDesc->Extra.ScopeNode,538ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);539if (ACPI_FAILURE (Status))540{541return_ACPI_STATUS (Status);542}543544Status = AcpiUtAddAddressRange (ObjDesc->Region.SpaceId,545ObjDesc->Region.Address, ObjDesc->Region.Length, Node);546return_ACPI_STATUS (Status);547}548549550