13446Smrj /******************************************************************************* 23446Smrj * 33446Smrj * Module Name: nseval - Object evaluation, includes control method execution 4*7851SDana.Myers@Sun.COM * $Revision: 1.145 $ 53446Smrj * 63446Smrj ******************************************************************************/ 73446Smrj 83446Smrj /****************************************************************************** 93446Smrj * 103446Smrj * 1. Copyright Notice 113446Smrj * 12*7851SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp. 133446Smrj * All rights reserved. 143446Smrj * 153446Smrj * 2. License 163446Smrj * 173446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property 183446Smrj * rights. You may have additional license terms from the party that provided 193446Smrj * you this software, covering your right to use that party's intellectual 203446Smrj * property rights. 213446Smrj * 223446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 233446Smrj * copy of the source code appearing in this file ("Covered Code") an 243446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 253446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy, 263446Smrj * make derivatives, distribute, use and display any portion of the Covered 273446Smrj * Code in any form, with the right to sublicense such rights; and 283446Smrj * 293446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 303446Smrj * license (with the right to sublicense), under only those claims of Intel 313446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell, 323446Smrj * offer to sell, and import the Covered Code and derivative works thereof 333446Smrj * solely to the minimum extent necessary to exercise the above copyright 343446Smrj * license, and in no event shall the patent license extend to any additions 353446Smrj * to or modifications of the Original Intel Code. No other license or right 363446Smrj * is granted directly or by implication, estoppel or otherwise; 373446Smrj * 383446Smrj * The above copyright and patent license is granted only if the following 393446Smrj * conditions are met: 403446Smrj * 413446Smrj * 3. Conditions 423446Smrj * 433446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 443446Smrj * Redistribution of source code of any substantial portion of the Covered 453446Smrj * Code or modification with rights to further distribute source must include 463446Smrj * the above Copyright Notice, the above License, this list of Conditions, 473446Smrj * and the following Disclaimer and Export Compliance provision. In addition, 483446Smrj * Licensee must cause all Covered Code to which Licensee contributes to 493446Smrj * contain a file documenting the changes Licensee made to create that Covered 503446Smrj * Code and the date of any change. Licensee must include in that file the 513446Smrj * documentation of any changes made by any predecessor Licensee. Licensee 523446Smrj * must include a prominent statement that the modification is derived, 533446Smrj * directly or indirectly, from Original Intel Code. 543446Smrj * 553446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 563446Smrj * Redistribution of source code of any substantial portion of the Covered 573446Smrj * Code or modification without rights to further distribute source must 583446Smrj * include the following Disclaimer and Export Compliance provision in the 593446Smrj * documentation and/or other materials provided with distribution. In 603446Smrj * addition, Licensee may not authorize further sublicense of source of any 613446Smrj * portion of the Covered Code, and must include terms to the effect that the 623446Smrj * license from Licensee to its licensee is limited to the intellectual 633446Smrj * property embodied in the software Licensee provides to its licensee, and 643446Smrj * not to intellectual property embodied in modifications its licensee may 653446Smrj * make. 663446Smrj 673446Smrj * 683446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any 693446Smrj * substantial portion of the Covered Code or modification must reproduce the 703446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance 713446Smrj * provision in the documentation and/or other materials provided with the 723446Smrj * distribution. 733446Smrj * 743446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original 753446Smrj * Intel Code. 763446Smrj * 773446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by 783446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or 793446Smrj * other dealings in products derived from or relating to the Covered Code 803446Smrj * without prior written authorization from Intel. 813446Smrj * 823446Smrj * 4. Disclaimer and Export Compliance 833446Smrj * 843446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 853446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 863446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 873446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 883446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 893446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 903446Smrj * PARTICULAR PURPOSE. 913446Smrj * 923446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 933446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 943446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 953446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 963446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 973446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 983446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 993446Smrj * LIMITED REMEDY. 1003446Smrj * 1013446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this 1023446Smrj * software or system incorporating such software without first obtaining any 1033446Smrj * required license or other approval from the U. S. Department of Commerce or 1043446Smrj * any other agency or department of the United States Government. In the 1053446Smrj * event Licensee exports any such software from the United States or 1063446Smrj * re-exports any such software from a foreign destination, Licensee shall 1073446Smrj * ensure that the distribution and export/re-export of the software is in 1083446Smrj * compliance with all laws, regulations, orders, or other restrictions of the 1093446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1103446Smrj * any of its subsidiaries will export/re-export any technical data, process, 1113446Smrj * software, or service, directly or indirectly, to any country for which the 1123446Smrj * United States government or any agency thereof requires an export license, 1133446Smrj * other governmental approval, or letter of assurance, without first obtaining 1143446Smrj * such license, approval or letter. 1153446Smrj * 1163446Smrj *****************************************************************************/ 1173446Smrj 1183446Smrj #define __NSEVAL_C__ 1193446Smrj 1203446Smrj #include "acpi.h" 1213446Smrj #include "acparser.h" 1223446Smrj #include "acinterp.h" 1233446Smrj #include "acnamesp.h" 1243446Smrj 1253446Smrj 1263446Smrj #define _COMPONENT ACPI_NAMESPACE 1273446Smrj ACPI_MODULE_NAME ("nseval") 1283446Smrj 1293446Smrj 1303446Smrj /******************************************************************************* 1313446Smrj * 1323446Smrj * FUNCTION: AcpiNsEvaluate 1333446Smrj * 1343446Smrj * PARAMETERS: Info - Evaluation info block, contains: 1353446Smrj * PrefixNode - Prefix or Method/Object Node to execute 1363446Smrj * Pathname - Name of method to execute, If NULL, the 1373446Smrj * Node is the object to execute 1383446Smrj * Parameters - List of parameters to pass to the method, 1393446Smrj * terminated by NULL. Params itself may be 1403446Smrj * NULL if no parameters are being passed. 1413446Smrj * ReturnObject - Where to put method's return value (if 1423446Smrj * any). If NULL, no value is returned. 1433446Smrj * ParameterType - Type of Parameter list 1443446Smrj * ReturnObject - Where to put method's return value (if 1453446Smrj * any). If NULL, no value is returned. 1463446Smrj * Flags - ACPI_IGNORE_RETURN_VALUE to delete return 1473446Smrj * 1483446Smrj * RETURN: Status 1493446Smrj * 1503446Smrj * DESCRIPTION: Execute a control method or return the current value of an 1513446Smrj * ACPI namespace object. 1523446Smrj * 1533446Smrj * MUTEX: Locks interpreter 1543446Smrj * 1553446Smrj ******************************************************************************/ 1563446Smrj 1573446Smrj ACPI_STATUS 1583446Smrj AcpiNsEvaluate ( 1593446Smrj ACPI_EVALUATE_INFO *Info) 1603446Smrj { 1613446Smrj ACPI_STATUS Status; 1623446Smrj 1633446Smrj 1643446Smrj ACPI_FUNCTION_TRACE (NsEvaluate); 1653446Smrj 1663446Smrj 1673446Smrj if (!Info) 1683446Smrj { 1693446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 1703446Smrj } 1713446Smrj 1723446Smrj /* Initialize the return value to an invalid object */ 1733446Smrj 1743446Smrj Info->ReturnObject = NULL; 1753446Smrj 1763446Smrj /* 1773446Smrj * Get the actual namespace node for the target object. Handles these cases: 1783446Smrj * 1793446Smrj * 1) Null node, Pathname (absolute path) 1803446Smrj * 2) Node, Pathname (path relative to Node) 1813446Smrj * 3) Node, Null Pathname 1823446Smrj */ 1833446Smrj Status = AcpiNsGetNode (Info->PrefixNode, Info->Pathname, 1843446Smrj ACPI_NS_NO_UPSEARCH, &Info->ResolvedNode); 1853446Smrj if (ACPI_FAILURE (Status)) 1863446Smrj { 1873446Smrj return_ACPI_STATUS (Status); 1883446Smrj } 1893446Smrj 1903446Smrj /* 1913446Smrj * For a method alias, we must grab the actual method node so that proper 1923446Smrj * scoping context will be established before execution. 1933446Smrj */ 1943446Smrj if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_LOCAL_METHOD_ALIAS) 1953446Smrj { 1963446Smrj Info->ResolvedNode = 1973446Smrj ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->ResolvedNode->Object); 1983446Smrj } 1993446Smrj 2003446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->Pathname, 2013446Smrj Info->ResolvedNode, AcpiNsGetAttachedObject (Info->ResolvedNode))); 2023446Smrj 2033446Smrj /* 2043446Smrj * Two major cases here: 2053446Smrj * 2063446Smrj * 1) The object is a control method -- execute it 2073446Smrj * 2) The object is not a method -- just return it's current value 2083446Smrj */ 2093446Smrj if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_METHOD) 2103446Smrj { 2113446Smrj /* 2123446Smrj * 1) Object is a control method - execute it 2133446Smrj */ 2143446Smrj 2153446Smrj /* Verify that there is a method object associated with this node */ 2163446Smrj 2173446Smrj Info->ObjDesc = AcpiNsGetAttachedObject (Info->ResolvedNode); 2183446Smrj if (!Info->ObjDesc) 2193446Smrj { 2203446Smrj ACPI_ERROR ((AE_INFO, "Control method has no attached sub-object")); 2213446Smrj return_ACPI_STATUS (AE_NULL_OBJECT); 2223446Smrj } 2233446Smrj 224*7851SDana.Myers@Sun.COM /* Calculate the number of arguments being passed to the method */ 225*7851SDana.Myers@Sun.COM 226*7851SDana.Myers@Sun.COM Info->ParamCount = 0; 227*7851SDana.Myers@Sun.COM if (Info->Parameters) 228*7851SDana.Myers@Sun.COM { 229*7851SDana.Myers@Sun.COM while (Info->Parameters[Info->ParamCount]) 230*7851SDana.Myers@Sun.COM { 231*7851SDana.Myers@Sun.COM Info->ParamCount++; 232*7851SDana.Myers@Sun.COM } 233*7851SDana.Myers@Sun.COM } 234*7851SDana.Myers@Sun.COM 235*7851SDana.Myers@Sun.COM /* 236*7851SDana.Myers@Sun.COM * Warning if too few or too many arguments have been passed by the 237*7851SDana.Myers@Sun.COM * caller. We don't want to abort here with an error because an 238*7851SDana.Myers@Sun.COM * incorrect number of arguments may not cause the method to fail. 239*7851SDana.Myers@Sun.COM * However, the method will fail if there are too few arguments passed 240*7851SDana.Myers@Sun.COM * and the method attempts to use one of the missing ones. 241*7851SDana.Myers@Sun.COM */ 242*7851SDana.Myers@Sun.COM if (Info->ParamCount < Info->ObjDesc->Method.ParamCount) 243*7851SDana.Myers@Sun.COM { 244*7851SDana.Myers@Sun.COM ACPI_WARNING ((AE_INFO, 245*7851SDana.Myers@Sun.COM "Insufficient arguments - method [%4.4s] needs %d, found %d", 246*7851SDana.Myers@Sun.COM AcpiUtGetNodeName (Info->ResolvedNode), 247*7851SDana.Myers@Sun.COM Info->ObjDesc->Method.ParamCount, Info->ParamCount)); 248*7851SDana.Myers@Sun.COM } 249*7851SDana.Myers@Sun.COM else if (Info->ParamCount > Info->ObjDesc->Method.ParamCount) 250*7851SDana.Myers@Sun.COM { 251*7851SDana.Myers@Sun.COM ACPI_WARNING ((AE_INFO, 252*7851SDana.Myers@Sun.COM "Excess arguments - method [%4.4s] needs %d, found %d", 253*7851SDana.Myers@Sun.COM AcpiUtGetNodeName (Info->ResolvedNode), 254*7851SDana.Myers@Sun.COM Info->ObjDesc->Method.ParamCount, Info->ParamCount)); 255*7851SDana.Myers@Sun.COM } 256*7851SDana.Myers@Sun.COM 2573446Smrj ACPI_DUMP_PATHNAME (Info->ResolvedNode, "Execute Method:", 2583446Smrj ACPI_LV_INFO, _COMPONENT); 2593446Smrj 2603446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 2613446Smrj "Method at AML address %p Length %X\n", 2623446Smrj Info->ObjDesc->Method.AmlStart + 1, 2633446Smrj Info->ObjDesc->Method.AmlLength - 1)); 2643446Smrj 2653446Smrj /* 2663446Smrj * Any namespace deletion must acquire both the namespace and 2673446Smrj * interpreter locks to ensure that no thread is using the portion of 2683446Smrj * the namespace that is being deleted. 2693446Smrj * 2703446Smrj * Execute the method via the interpreter. The interpreter is locked 2713446Smrj * here before calling into the AML parser 2723446Smrj */ 273*7851SDana.Myers@Sun.COM AcpiExEnterInterpreter (); 2743446Smrj Status = AcpiPsExecuteMethod (Info); 2753446Smrj AcpiExExitInterpreter (); 2763446Smrj } 2773446Smrj else 2783446Smrj { 2793446Smrj /* 2803446Smrj * 2) Object is not a method, return its current value 281*7851SDana.Myers@Sun.COM * 282*7851SDana.Myers@Sun.COM * Disallow certain object types. For these, "evaluation" is undefined. 2833446Smrj */ 284*7851SDana.Myers@Sun.COM switch (Info->ResolvedNode->Type) 285*7851SDana.Myers@Sun.COM { 286*7851SDana.Myers@Sun.COM case ACPI_TYPE_DEVICE: 287*7851SDana.Myers@Sun.COM case ACPI_TYPE_EVENT: 288*7851SDana.Myers@Sun.COM case ACPI_TYPE_MUTEX: 289*7851SDana.Myers@Sun.COM case ACPI_TYPE_REGION: 290*7851SDana.Myers@Sun.COM case ACPI_TYPE_THERMAL: 291*7851SDana.Myers@Sun.COM case ACPI_TYPE_LOCAL_SCOPE: 292*7851SDana.Myers@Sun.COM 293*7851SDana.Myers@Sun.COM ACPI_ERROR ((AE_INFO, 294*7851SDana.Myers@Sun.COM "[%4.4s] Evaluation of object type [%s] is not supported", 295*7851SDana.Myers@Sun.COM Info->ResolvedNode->Name.Ascii, 296*7851SDana.Myers@Sun.COM AcpiUtGetTypeName (Info->ResolvedNode->Type))); 297*7851SDana.Myers@Sun.COM 298*7851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_TYPE); 299*7851SDana.Myers@Sun.COM 300*7851SDana.Myers@Sun.COM default: 301*7851SDana.Myers@Sun.COM break; 302*7851SDana.Myers@Sun.COM } 3033446Smrj 3043446Smrj /* 3053446Smrj * Objects require additional resolution steps (e.g., the Node may be 3063446Smrj * a field that must be read, etc.) -- we can't just grab the object 3073446Smrj * out of the node. 3083446Smrj * 3093446Smrj * Use ResolveNodeToValue() to get the associated value. 3103446Smrj * 3113446Smrj * NOTE: we can get away with passing in NULL for a walk state because 3123446Smrj * ResolvedNode is guaranteed to not be a reference to either a method 3133446Smrj * local or a method argument (because this interface is never called 3143446Smrj * from a running method.) 3153446Smrj * 3163446Smrj * Even though we do not directly invoke the interpreter for object 3173446Smrj * resolution, we must lock it because we could access an opregion. 3183446Smrj * The opregion access code assumes that the interpreter is locked. 3193446Smrj */ 320*7851SDana.Myers@Sun.COM AcpiExEnterInterpreter (); 3213446Smrj 3223446Smrj /* Function has a strange interface */ 3233446Smrj 3243446Smrj Status = AcpiExResolveNodeToValue (&Info->ResolvedNode, NULL); 3253446Smrj AcpiExExitInterpreter (); 3263446Smrj 3273446Smrj /* 3283446Smrj * If AcpiExResolveNodeToValue() succeeded, the return value was placed 3293446Smrj * in ResolvedNode. 3303446Smrj */ 3313446Smrj if (ACPI_SUCCESS (Status)) 3323446Smrj { 3333446Smrj Status = AE_CTRL_RETURN_VALUE; 3343446Smrj Info->ReturnObject = 3353446Smrj ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->ResolvedNode); 3363446Smrj 3373446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n", 3383446Smrj Info->ReturnObject, 3393446Smrj AcpiUtGetObjectTypeName (Info->ReturnObject))); 3403446Smrj } 3413446Smrj } 3423446Smrj 3433446Smrj /* 3443446Smrj * Check if there is a return value that must be dealt with 3453446Smrj */ 3463446Smrj if (Status == AE_CTRL_RETURN_VALUE) 3473446Smrj { 3483446Smrj /* If caller does not want the return value, delete it */ 3493446Smrj 3503446Smrj if (Info->Flags & ACPI_IGNORE_RETURN_VALUE) 3513446Smrj { 3523446Smrj AcpiUtRemoveReference (Info->ReturnObject); 3533446Smrj Info->ReturnObject = NULL; 3543446Smrj } 3553446Smrj 3563446Smrj /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */ 3573446Smrj 3583446Smrj Status = AE_OK; 3593446Smrj } 3603446Smrj 3613446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 3623446Smrj "*** Completed evaluation of object %s ***\n", Info->Pathname)); 3633446Smrj 3643446Smrj /* 3653446Smrj * Namespace was unlocked by the handling AcpiNs* function, so we 3663446Smrj * just return 3673446Smrj */ 3683446Smrj return_ACPI_STATUS (Status); 3693446Smrj } 3703446Smrj 371