Path: blob/main/sys/contrib/dev/acpica/components/namespace/nseval.c
48524 views
/*******************************************************************************1*2* Module Name: nseval - Object evaluation, includes control method execution3*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.6465*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/acinterp.h>156#include <contrib/dev/acpica/include/acnamesp.h>157158159#define _COMPONENT ACPI_NAMESPACE160ACPI_MODULE_NAME ("nseval")161162163/*******************************************************************************164*165* FUNCTION: AcpiNsEvaluate166*167* PARAMETERS: Info - Evaluation info block, contains these fields168* and more:169* PrefixNode - Prefix or Method/Object Node to execute170* RelativePath - Name of method to execute, If NULL, the171* Node is the object to execute172* Parameters - List of parameters to pass to the method,173* terminated by NULL. Params itself may be174* NULL if no parameters are being passed.175* ParameterType - Type of Parameter list176* ReturnObject - Where to put method's return value (if177* any). If NULL, no value is returned.178* Flags - ACPI_IGNORE_RETURN_VALUE to delete return179*180* RETURN: Status181*182* DESCRIPTION: Execute a control method or return the current value of an183* ACPI namespace object.184*185* MUTEX: Locks interpreter186*187******************************************************************************/188189ACPI_STATUS190AcpiNsEvaluate (191ACPI_EVALUATE_INFO *Info)192{193ACPI_STATUS Status;194195196ACPI_FUNCTION_TRACE (NsEvaluate);197198199if (!Info)200{201return_ACPI_STATUS (AE_BAD_PARAMETER);202}203204if (!Info->Node)205{206/*207* Get the actual namespace node for the target object if we208* need to. Handles these cases:209*210* 1) Null node, valid pathname from root (absolute path)211* 2) Node and valid pathname (path relative to Node)212* 3) Node, Null pathname213*/214Status = AcpiNsGetNode (Info->PrefixNode, Info->RelativePathname,215ACPI_NS_NO_UPSEARCH, &Info->Node);216if (ACPI_FAILURE (Status))217{218return_ACPI_STATUS (Status);219}220}221222/*223* For a method alias, we must grab the actual method node so that224* proper scoping context will be established before execution.225*/226if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)227{228Info->Node = ACPI_CAST_PTR (229ACPI_NAMESPACE_NODE, Info->Node->Object);230}231232/* Complete the info block initialization */233234Info->ReturnObject = NULL;235Info->NodeFlags = Info->Node->Flags;236Info->ObjDesc = AcpiNsGetAttachedObject (Info->Node);237238ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",239Info->RelativePathname, Info->Node,240AcpiNsGetAttachedObject (Info->Node)));241242/* Get info if we have a predefined name (_HID, etc.) */243244Info->Predefined = AcpiUtMatchPredefinedMethod (Info->Node->Name.Ascii);245246/* Get the full pathname to the object, for use in warning messages */247248Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);249if (!Info->FullPathname)250{251return_ACPI_STATUS (AE_NO_MEMORY);252}253254/* Optional object evaluation log */255256ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,257"%-26s: %s (%s)\n", " Enter evaluation",258&Info->FullPathname[1], AcpiUtGetTypeName (Info->Node->Type)));259260/* Count the number of arguments being passed in */261262Info->ParamCount = 0;263if (Info->Parameters)264{265while (Info->Parameters[Info->ParamCount])266{267Info->ParamCount++;268}269270/* Warn on impossible argument count */271272if (Info->ParamCount > ACPI_METHOD_NUM_ARGS)273{274ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,275"Excess arguments (%u) - using only %u",276Info->ParamCount, ACPI_METHOD_NUM_ARGS));277278Info->ParamCount = ACPI_METHOD_NUM_ARGS;279}280}281282/*283* For predefined names: Check that the declared argument count284* matches the ACPI spec -- otherwise this is a BIOS error.285*/286AcpiNsCheckAcpiCompliance (Info->FullPathname, Info->Node,287Info->Predefined);288289/*290* For all names: Check that the incoming argument count for291* this method/object matches the actual ASL/AML definition.292*/293AcpiNsCheckArgumentCount (Info->FullPathname, Info->Node,294Info->ParamCount, Info->Predefined);295296/* For predefined names: Typecheck all incoming arguments */297298AcpiNsCheckArgumentTypes (Info);299300/*301* Three major evaluation cases:302*303* 1) Object types that cannot be evaluated by definition304* 2) The object is a control method -- execute it305* 3) The object is not a method -- just return it's current value306*/307switch (AcpiNsGetType (Info->Node))308{309case ACPI_TYPE_ANY:310case ACPI_TYPE_DEVICE:311case ACPI_TYPE_EVENT:312case ACPI_TYPE_MUTEX:313case ACPI_TYPE_REGION:314case ACPI_TYPE_THERMAL:315case ACPI_TYPE_LOCAL_SCOPE:316/*317* 1) Disallow evaluation of these object types. For these,318* object evaluation is undefined.319*/320ACPI_ERROR ((AE_INFO,321"%s: This object type [%s] "322"never contains data and cannot be evaluated",323Info->FullPathname, AcpiUtGetTypeName (Info->Node->Type)));324325Status = AE_TYPE;326goto Cleanup;327328case ACPI_TYPE_METHOD:329/*330* 2) Object is a control method - execute it331*/332333/* Verify that there is a method object associated with this node */334335if (!Info->ObjDesc)336{337ACPI_ERROR ((AE_INFO, "%s: Method has no attached sub-object",338Info->FullPathname));339Status = AE_NULL_OBJECT;340goto Cleanup;341}342343ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,344"**** Execute method [%s] at AML address %p length %X\n",345Info->FullPathname,346Info->ObjDesc->Method.AmlStart + 1,347Info->ObjDesc->Method.AmlLength - 1));348349/*350* Any namespace deletion must acquire both the namespace and351* interpreter locks to ensure that no thread is using the portion of352* the namespace that is being deleted.353*354* Execute the method via the interpreter. The interpreter is locked355* here before calling into the AML parser356*/357AcpiExEnterInterpreter ();358Status = AcpiPsExecuteMethod (Info);359AcpiExExitInterpreter ();360break;361362default:363/*364* 3) All other non-method objects -- get the current object value365*/366367/*368* Some objects require additional resolution steps (e.g., the Node369* may be a field that must be read, etc.) -- we can't just grab370* the object out of the node.371*372* Use ResolveNodeToValue() to get the associated value.373*374* NOTE: we can get away with passing in NULL for a walk state because375* the Node is guaranteed to not be a reference to either a method376* local or a method argument (because this interface is never called377* from a running method.)378*379* Even though we do not directly invoke the interpreter for object380* resolution, we must lock it because we could access an OpRegion.381* The OpRegion access code assumes that the interpreter is locked.382*/383AcpiExEnterInterpreter ();384385/* TBD: ResolveNodeToValue has a strange interface, fix */386387Info->ReturnObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->Node);388389Status = AcpiExResolveNodeToValue (ACPI_CAST_INDIRECT_PTR (390ACPI_NAMESPACE_NODE, &Info->ReturnObject), NULL);391AcpiExExitInterpreter ();392393if (ACPI_FAILURE (Status))394{395Info->ReturnObject = NULL;396goto Cleanup;397}398399ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returned object %p [%s]\n",400Info->ReturnObject,401AcpiUtGetObjectTypeName (Info->ReturnObject)));402403Status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */404break;405}406407/*408* For predefined names, check the return value against the ACPI409* specification. Some incorrect return value types are repaired.410*/411(void) AcpiNsCheckReturnValue (Info->Node, Info, Info->ParamCount,412Status, &Info->ReturnObject);413414/* Check if there is a return value that must be dealt with */415416if (Status == AE_CTRL_RETURN_VALUE)417{418/* If caller does not want the return value, delete it */419420if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)421{422AcpiUtRemoveReference (Info->ReturnObject);423Info->ReturnObject = NULL;424}425426/* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */427428Status = AE_OK;429}430else if (ACPI_FAILURE(Status))431{432/* If ReturnObject exists, delete it */433434if (Info->ReturnObject)435{436AcpiUtRemoveReference (Info->ReturnObject);437Info->ReturnObject = NULL;438}439}440441ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,442"*** Completed evaluation of object %s ***\n",443Info->RelativePathname));444445Cleanup:446/* Optional object evaluation log */447448ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION,449"%-26s: %s\n", " Exit evaluation",450&Info->FullPathname[1]));451452/*453* Namespace was unlocked by the handling AcpiNs* function, so we454* just free the pathname and return455*/456ACPI_FREE (Info->FullPathname);457Info->FullPathname = NULL;458return_ACPI_STATUS (Status);459}460461462