Path: blob/main/sys/contrib/dev/acpica/components/utilities/uteval.c
48406 views
/******************************************************************************1*2* Module Name: uteval - Object evaluation3*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>154155156#define _COMPONENT ACPI_UTILITIES157ACPI_MODULE_NAME ("uteval")158159160/*******************************************************************************161*162* FUNCTION: AcpiUtEvaluateObject163*164* PARAMETERS: PrefixNode - Starting node165* Path - Path to object from starting node166* ExpectedReturnTypes - Bitmap of allowed return types167* ReturnDesc - Where a return value is stored168*169* RETURN: Status170*171* DESCRIPTION: Evaluates a namespace object and verifies the type of the172* return object. Common code that simplifies accessing objects173* that have required return objects of fixed types.174*175* NOTE: Internal function, no parameter validation176*177******************************************************************************/178179ACPI_STATUS180AcpiUtEvaluateObject (181ACPI_NAMESPACE_NODE *PrefixNode,182const char *Path,183UINT32 ExpectedReturnBtypes,184ACPI_OPERAND_OBJECT **ReturnDesc)185{186ACPI_EVALUATE_INFO *Info;187ACPI_STATUS Status;188UINT32 ReturnBtype;189190191ACPI_FUNCTION_TRACE (UtEvaluateObject);192193194/* Allocate the evaluation information block */195196Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));197if (!Info)198{199return_ACPI_STATUS (AE_NO_MEMORY);200}201202Info->PrefixNode = PrefixNode;203Info->RelativePathname = Path;204205/* Evaluate the object/method */206207Status = AcpiNsEvaluate (Info);208if (ACPI_FAILURE (Status))209{210if (Status == AE_NOT_FOUND)211{212ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",213AcpiUtGetNodeName (PrefixNode), Path));214}215else216{217ACPI_ERROR_METHOD ("Method execution failed",218PrefixNode, Path, Status);219}220221goto Cleanup;222}223224/* Did we get a return object? */225226if (!Info->ReturnObject)227{228if (ExpectedReturnBtypes)229{230ACPI_ERROR_METHOD ("No object was returned from",231PrefixNode, Path, AE_NOT_EXIST);232233Status = AE_NOT_EXIST;234}235236goto Cleanup;237}238239/* Map the return object type to the bitmapped type */240241switch ((Info->ReturnObject)->Common.Type)242{243case ACPI_TYPE_INTEGER:244245ReturnBtype = ACPI_BTYPE_INTEGER;246break;247248case ACPI_TYPE_BUFFER:249250ReturnBtype = ACPI_BTYPE_BUFFER;251break;252253case ACPI_TYPE_STRING:254255ReturnBtype = ACPI_BTYPE_STRING;256break;257258case ACPI_TYPE_PACKAGE:259260ReturnBtype = ACPI_BTYPE_PACKAGE;261break;262263default:264265ReturnBtype = 0;266break;267}268269if ((AcpiGbl_EnableInterpreterSlack) &&270(!ExpectedReturnBtypes))271{272/*273* We received a return object, but one was not expected. This can274* happen frequently if the "implicit return" feature is enabled.275* Just delete the return object and return AE_OK.276*/277AcpiUtRemoveReference (Info->ReturnObject);278goto Cleanup;279}280281/* Is the return object one of the expected types? */282283if (!(ExpectedReturnBtypes & ReturnBtype))284{285ACPI_ERROR_METHOD ("Return object type is incorrect",286PrefixNode, Path, AE_TYPE);287288ACPI_ERROR ((AE_INFO,289"Type returned from %s was incorrect: %s, expected Btypes: 0x%X",290Path, AcpiUtGetObjectTypeName (Info->ReturnObject),291ExpectedReturnBtypes));292293/* On error exit, we must delete the return object */294295AcpiUtRemoveReference (Info->ReturnObject);296Status = AE_TYPE;297goto Cleanup;298}299300/* Object type is OK, return it */301302*ReturnDesc = Info->ReturnObject;303304Cleanup:305ACPI_FREE (Info);306return_ACPI_STATUS (Status);307}308309310/*******************************************************************************311*312* FUNCTION: AcpiUtEvaluateNumericObject313*314* PARAMETERS: ObjectName - Object name to be evaluated315* DeviceNode - Node for the device316* Value - Where the value is returned317*318* RETURN: Status319*320* DESCRIPTION: Evaluates a numeric namespace object for a selected device321* and stores result in *Value.322*323* NOTE: Internal function, no parameter validation324*325******************************************************************************/326327ACPI_STATUS328AcpiUtEvaluateNumericObject (329const char *ObjectName,330ACPI_NAMESPACE_NODE *DeviceNode,331UINT64 *Value)332{333ACPI_OPERAND_OBJECT *ObjDesc;334ACPI_STATUS Status;335336337ACPI_FUNCTION_TRACE (UtEvaluateNumericObject);338339340Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,341ACPI_BTYPE_INTEGER, &ObjDesc);342if (ACPI_FAILURE (Status))343{344return_ACPI_STATUS (Status);345}346347/* Get the returned Integer */348349*Value = ObjDesc->Integer.Value;350351/* On exit, we must delete the return object */352353AcpiUtRemoveReference (ObjDesc);354return_ACPI_STATUS (Status);355}356357358/*******************************************************************************359*360* FUNCTION: AcpiUtExecute_STA361*362* PARAMETERS: DeviceNode - Node for the device363* Flags - Where the status flags are returned364*365* RETURN: Status366*367* DESCRIPTION: Executes _STA for selected device and stores results in368* *Flags. If _STA does not exist, then the device is assumed369* to be present/functional/enabled (as per the ACPI spec).370*371* NOTE: Internal function, no parameter validation372*373******************************************************************************/374375ACPI_STATUS376AcpiUtExecute_STA (377ACPI_NAMESPACE_NODE *DeviceNode,378UINT32 *Flags)379{380ACPI_OPERAND_OBJECT *ObjDesc;381ACPI_STATUS Status;382383384ACPI_FUNCTION_TRACE (UtExecute_STA);385386387Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,388ACPI_BTYPE_INTEGER, &ObjDesc);389if (ACPI_FAILURE (Status))390{391if (AE_NOT_FOUND == Status)392{393/*394* if _STA does not exist, then (as per the ACPI specification),395* the returned flags will indicate that the device is present,396* functional, and enabled.397*/398ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,399"_STA on %4.4s was not found, assuming device is present\n",400AcpiUtGetNodeName (DeviceNode)));401402*Flags = ACPI_UINT32_MAX;403Status = AE_OK;404}405406return_ACPI_STATUS (Status);407}408409/* Extract the status flags */410411*Flags = (UINT32) ObjDesc->Integer.Value;412413/* On exit, we must delete the return object */414415AcpiUtRemoveReference (ObjDesc);416return_ACPI_STATUS (Status);417}418419420/*******************************************************************************421*422* FUNCTION: AcpiUtExecutePowerMethods423*424* PARAMETERS: DeviceNode - Node for the device425* MethodNames - Array of power method names426* MethodCount - Number of methods to execute427* OutValues - Where the power method values are returned428*429* RETURN: Status, OutValues430*431* DESCRIPTION: Executes the specified power methods for the device and returns432* the result(s).433*434* NOTE: Internal function, no parameter validation435*436******************************************************************************/437438ACPI_STATUS439AcpiUtExecutePowerMethods (440ACPI_NAMESPACE_NODE *DeviceNode,441const char **MethodNames,442UINT8 MethodCount,443UINT8 *OutValues)444{445ACPI_OPERAND_OBJECT *ObjDesc;446ACPI_STATUS Status;447ACPI_STATUS FinalStatus = AE_NOT_FOUND;448UINT32 i;449450451ACPI_FUNCTION_TRACE (UtExecutePowerMethods);452453454for (i = 0; i < MethodCount; i++)455{456/*457* Execute the power method (_SxD or _SxW). The only allowable458* return type is an Integer.459*/460Status = AcpiUtEvaluateObject (DeviceNode,461ACPI_CAST_PTR (char, MethodNames[i]),462ACPI_BTYPE_INTEGER, &ObjDesc);463if (ACPI_SUCCESS (Status))464{465OutValues[i] = (UINT8) ObjDesc->Integer.Value;466467/* Delete the return object */468469AcpiUtRemoveReference (ObjDesc);470FinalStatus = AE_OK; /* At least one value is valid */471continue;472}473474OutValues[i] = ACPI_UINT8_MAX;475if (Status == AE_NOT_FOUND)476{477continue; /* Ignore if not found */478}479480ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Failed %s on Device %4.4s, %s\n",481ACPI_CAST_PTR (char, MethodNames[i]),482AcpiUtGetNodeName (DeviceNode), AcpiFormatException (Status)));483}484485return_ACPI_STATUS (FinalStatus);486}487488489