13446Smrj /******************************************************************************* 23446Smrj * 33446Smrj * Module Name: nseval - Object evaluation, includes control method execution 43446Smrj * 53446Smrj ******************************************************************************/ 63446Smrj 73446Smrj /****************************************************************************** 83446Smrj * 93446Smrj * 1. Copyright Notice 103446Smrj * 11*9980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 123446Smrj * All rights reserved. 133446Smrj * 143446Smrj * 2. License 153446Smrj * 163446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property 173446Smrj * rights. You may have additional license terms from the party that provided 183446Smrj * you this software, covering your right to use that party's intellectual 193446Smrj * property rights. 203446Smrj * 213446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 223446Smrj * copy of the source code appearing in this file ("Covered Code") an 233446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 243446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy, 253446Smrj * make derivatives, distribute, use and display any portion of the Covered 263446Smrj * Code in any form, with the right to sublicense such rights; and 273446Smrj * 283446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 293446Smrj * license (with the right to sublicense), under only those claims of Intel 303446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell, 313446Smrj * offer to sell, and import the Covered Code and derivative works thereof 323446Smrj * solely to the minimum extent necessary to exercise the above copyright 333446Smrj * license, and in no event shall the patent license extend to any additions 343446Smrj * to or modifications of the Original Intel Code. No other license or right 353446Smrj * is granted directly or by implication, estoppel or otherwise; 363446Smrj * 373446Smrj * The above copyright and patent license is granted only if the following 383446Smrj * conditions are met: 393446Smrj * 403446Smrj * 3. Conditions 413446Smrj * 423446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 433446Smrj * Redistribution of source code of any substantial portion of the Covered 443446Smrj * Code or modification with rights to further distribute source must include 453446Smrj * the above Copyright Notice, the above License, this list of Conditions, 463446Smrj * and the following Disclaimer and Export Compliance provision. In addition, 473446Smrj * Licensee must cause all Covered Code to which Licensee contributes to 483446Smrj * contain a file documenting the changes Licensee made to create that Covered 493446Smrj * Code and the date of any change. Licensee must include in that file the 503446Smrj * documentation of any changes made by any predecessor Licensee. Licensee 513446Smrj * must include a prominent statement that the modification is derived, 523446Smrj * directly or indirectly, from Original Intel Code. 533446Smrj * 543446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 553446Smrj * Redistribution of source code of any substantial portion of the Covered 563446Smrj * Code or modification without rights to further distribute source must 573446Smrj * include the following Disclaimer and Export Compliance provision in the 583446Smrj * documentation and/or other materials provided with distribution. In 593446Smrj * addition, Licensee may not authorize further sublicense of source of any 603446Smrj * portion of the Covered Code, and must include terms to the effect that the 613446Smrj * license from Licensee to its licensee is limited to the intellectual 623446Smrj * property embodied in the software Licensee provides to its licensee, and 633446Smrj * not to intellectual property embodied in modifications its licensee may 643446Smrj * make. 653446Smrj 663446Smrj * 673446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any 683446Smrj * substantial portion of the Covered Code or modification must reproduce the 693446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance 703446Smrj * provision in the documentation and/or other materials provided with the 713446Smrj * distribution. 723446Smrj * 733446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original 743446Smrj * Intel Code. 753446Smrj * 763446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by 773446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or 783446Smrj * other dealings in products derived from or relating to the Covered Code 793446Smrj * without prior written authorization from Intel. 803446Smrj * 813446Smrj * 4. Disclaimer and Export Compliance 823446Smrj * 833446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 843446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 853446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 863446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 873446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 883446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 893446Smrj * PARTICULAR PURPOSE. 903446Smrj * 913446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 923446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 933446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 943446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 953446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 963446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 973446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 983446Smrj * LIMITED REMEDY. 993446Smrj * 1003446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this 1013446Smrj * software or system incorporating such software without first obtaining any 1023446Smrj * required license or other approval from the U. S. Department of Commerce or 1033446Smrj * any other agency or department of the United States Government. In the 1043446Smrj * event Licensee exports any such software from the United States or 1053446Smrj * re-exports any such software from a foreign destination, Licensee shall 1063446Smrj * ensure that the distribution and export/re-export of the software is in 1073446Smrj * compliance with all laws, regulations, orders, or other restrictions of the 1083446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1093446Smrj * any of its subsidiaries will export/re-export any technical data, process, 1103446Smrj * software, or service, directly or indirectly, to any country for which the 1113446Smrj * United States government or any agency thereof requires an export license, 1123446Smrj * other governmental approval, or letter of assurance, without first obtaining 1133446Smrj * such license, approval or letter. 1143446Smrj * 1153446Smrj *****************************************************************************/ 1163446Smrj 1173446Smrj #define __NSEVAL_C__ 1183446Smrj 1193446Smrj #include "acpi.h" 120*9980SDana.Myers@Sun.COM #include "accommon.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; 162*9980SDana.Myers@Sun.COM ACPI_NAMESPACE_NODE *Node; 1633446Smrj 1643446Smrj 1653446Smrj ACPI_FUNCTION_TRACE (NsEvaluate); 1663446Smrj 1673446Smrj 1683446Smrj if (!Info) 1693446Smrj { 1703446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 1713446Smrj } 1723446Smrj 1733446Smrj /* Initialize the return value to an invalid object */ 1743446Smrj 1753446Smrj Info->ReturnObject = NULL; 176*9980SDana.Myers@Sun.COM Info->ParamCount = 0; 1773446Smrj 1783446Smrj /* 1793446Smrj * Get the actual namespace node for the target object. Handles these cases: 1803446Smrj * 1813446Smrj * 1) Null node, Pathname (absolute path) 1823446Smrj * 2) Node, Pathname (path relative to Node) 1833446Smrj * 3) Node, Null Pathname 1843446Smrj */ 1853446Smrj Status = AcpiNsGetNode (Info->PrefixNode, Info->Pathname, 1863446Smrj ACPI_NS_NO_UPSEARCH, &Info->ResolvedNode); 1873446Smrj if (ACPI_FAILURE (Status)) 1883446Smrj { 1893446Smrj return_ACPI_STATUS (Status); 1903446Smrj } 1913446Smrj 1923446Smrj /* 1933446Smrj * For a method alias, we must grab the actual method node so that proper 1943446Smrj * scoping context will be established before execution. 1953446Smrj */ 1963446Smrj if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_LOCAL_METHOD_ALIAS) 1973446Smrj { 1983446Smrj Info->ResolvedNode = 1993446Smrj ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->ResolvedNode->Object); 2003446Smrj } 2013446Smrj 2023446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->Pathname, 2033446Smrj Info->ResolvedNode, AcpiNsGetAttachedObject (Info->ResolvedNode))); 2043446Smrj 205*9980SDana.Myers@Sun.COM Node = Info->ResolvedNode; 206*9980SDana.Myers@Sun.COM 2073446Smrj /* 2083446Smrj * Two major cases here: 2093446Smrj * 2103446Smrj * 1) The object is a control method -- execute it 2113446Smrj * 2) The object is not a method -- just return it's current value 2123446Smrj */ 2133446Smrj if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_METHOD) 2143446Smrj { 2153446Smrj /* 2163446Smrj * 1) Object is a control method - execute it 2173446Smrj */ 2183446Smrj 2193446Smrj /* Verify that there is a method object associated with this node */ 2203446Smrj 2213446Smrj Info->ObjDesc = AcpiNsGetAttachedObject (Info->ResolvedNode); 2223446Smrj if (!Info->ObjDesc) 2233446Smrj { 2243446Smrj ACPI_ERROR ((AE_INFO, "Control method has no attached sub-object")); 2253446Smrj return_ACPI_STATUS (AE_NULL_OBJECT); 2263446Smrj } 2273446Smrj 228*9980SDana.Myers@Sun.COM /* Count the number of arguments being passed to the method */ 2297851SDana.Myers@Sun.COM 2307851SDana.Myers@Sun.COM if (Info->Parameters) 2317851SDana.Myers@Sun.COM { 2327851SDana.Myers@Sun.COM while (Info->Parameters[Info->ParamCount]) 2337851SDana.Myers@Sun.COM { 234*9980SDana.Myers@Sun.COM if (Info->ParamCount > ACPI_METHOD_MAX_ARG) 235*9980SDana.Myers@Sun.COM { 236*9980SDana.Myers@Sun.COM return_ACPI_STATUS (AE_LIMIT); 237*9980SDana.Myers@Sun.COM } 2387851SDana.Myers@Sun.COM Info->ParamCount++; 2397851SDana.Myers@Sun.COM } 2407851SDana.Myers@Sun.COM } 2417851SDana.Myers@Sun.COM 242*9980SDana.Myers@Sun.COM ACPI_DUMP_PATHNAME (Info->ResolvedNode, "ACPI: Execute Method", 2433446Smrj ACPI_LV_INFO, _COMPONENT); 2443446Smrj 2453446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 2463446Smrj "Method at AML address %p Length %X\n", 2473446Smrj Info->ObjDesc->Method.AmlStart + 1, 2483446Smrj Info->ObjDesc->Method.AmlLength - 1)); 2493446Smrj 2503446Smrj /* 2513446Smrj * Any namespace deletion must acquire both the namespace and 2523446Smrj * interpreter locks to ensure that no thread is using the portion of 2533446Smrj * the namespace that is being deleted. 2543446Smrj * 2553446Smrj * Execute the method via the interpreter. The interpreter is locked 2563446Smrj * here before calling into the AML parser 2573446Smrj */ 2587851SDana.Myers@Sun.COM AcpiExEnterInterpreter (); 2593446Smrj Status = AcpiPsExecuteMethod (Info); 2603446Smrj AcpiExExitInterpreter (); 2613446Smrj } 2623446Smrj else 2633446Smrj { 2643446Smrj /* 2653446Smrj * 2) Object is not a method, return its current value 2667851SDana.Myers@Sun.COM * 2677851SDana.Myers@Sun.COM * Disallow certain object types. For these, "evaluation" is undefined. 2683446Smrj */ 2697851SDana.Myers@Sun.COM switch (Info->ResolvedNode->Type) 2707851SDana.Myers@Sun.COM { 2717851SDana.Myers@Sun.COM case ACPI_TYPE_DEVICE: 2727851SDana.Myers@Sun.COM case ACPI_TYPE_EVENT: 2737851SDana.Myers@Sun.COM case ACPI_TYPE_MUTEX: 2747851SDana.Myers@Sun.COM case ACPI_TYPE_REGION: 2757851SDana.Myers@Sun.COM case ACPI_TYPE_THERMAL: 2767851SDana.Myers@Sun.COM case ACPI_TYPE_LOCAL_SCOPE: 2777851SDana.Myers@Sun.COM 2787851SDana.Myers@Sun.COM ACPI_ERROR ((AE_INFO, 2797851SDana.Myers@Sun.COM "[%4.4s] Evaluation of object type [%s] is not supported", 2807851SDana.Myers@Sun.COM Info->ResolvedNode->Name.Ascii, 2817851SDana.Myers@Sun.COM AcpiUtGetTypeName (Info->ResolvedNode->Type))); 2827851SDana.Myers@Sun.COM 2837851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_TYPE); 2847851SDana.Myers@Sun.COM 2857851SDana.Myers@Sun.COM default: 2867851SDana.Myers@Sun.COM break; 2877851SDana.Myers@Sun.COM } 2883446Smrj 2893446Smrj /* 2903446Smrj * Objects require additional resolution steps (e.g., the Node may be 2913446Smrj * a field that must be read, etc.) -- we can't just grab the object 2923446Smrj * out of the node. 2933446Smrj * 2943446Smrj * Use ResolveNodeToValue() to get the associated value. 2953446Smrj * 2963446Smrj * NOTE: we can get away with passing in NULL for a walk state because 2973446Smrj * ResolvedNode is guaranteed to not be a reference to either a method 2983446Smrj * local or a method argument (because this interface is never called 2993446Smrj * from a running method.) 3003446Smrj * 3013446Smrj * Even though we do not directly invoke the interpreter for object 3023446Smrj * resolution, we must lock it because we could access an opregion. 3033446Smrj * The opregion access code assumes that the interpreter is locked. 3043446Smrj */ 3057851SDana.Myers@Sun.COM AcpiExEnterInterpreter (); 3063446Smrj 3073446Smrj /* Function has a strange interface */ 3083446Smrj 3093446Smrj Status = AcpiExResolveNodeToValue (&Info->ResolvedNode, NULL); 3103446Smrj AcpiExExitInterpreter (); 3113446Smrj 3123446Smrj /* 3133446Smrj * If AcpiExResolveNodeToValue() succeeded, the return value was placed 3143446Smrj * in ResolvedNode. 3153446Smrj */ 3163446Smrj if (ACPI_SUCCESS (Status)) 3173446Smrj { 3183446Smrj Status = AE_CTRL_RETURN_VALUE; 3193446Smrj Info->ReturnObject = 3203446Smrj ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->ResolvedNode); 3213446Smrj 3223446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n", 3233446Smrj Info->ReturnObject, 3243446Smrj AcpiUtGetObjectTypeName (Info->ReturnObject))); 3253446Smrj } 3263446Smrj } 3273446Smrj 3283446Smrj /* 329*9980SDana.Myers@Sun.COM * Check input argument count against the ASL-defined count for a method. 330*9980SDana.Myers@Sun.COM * Also check predefined names: argument count and return value against 331*9980SDana.Myers@Sun.COM * the ACPI specification. Some incorrect return value types are repaired. 3323446Smrj */ 333*9980SDana.Myers@Sun.COM (void) AcpiNsCheckPredefinedNames (Node, Info->ParamCount, 334*9980SDana.Myers@Sun.COM Status, &Info->ReturnObject); 335*9980SDana.Myers@Sun.COM 336*9980SDana.Myers@Sun.COM /* Check if there is a return value that must be dealt with */ 337*9980SDana.Myers@Sun.COM 3383446Smrj if (Status == AE_CTRL_RETURN_VALUE) 3393446Smrj { 3403446Smrj /* If caller does not want the return value, delete it */ 3413446Smrj 3423446Smrj if (Info->Flags & ACPI_IGNORE_RETURN_VALUE) 3433446Smrj { 3443446Smrj AcpiUtRemoveReference (Info->ReturnObject); 3453446Smrj Info->ReturnObject = NULL; 3463446Smrj } 3473446Smrj 3483446Smrj /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */ 3493446Smrj 3503446Smrj Status = AE_OK; 3513446Smrj } 3523446Smrj 3533446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 3543446Smrj "*** Completed evaluation of object %s ***\n", Info->Pathname)); 3553446Smrj 3563446Smrj /* 3573446Smrj * Namespace was unlocked by the handling AcpiNs* function, so we 3583446Smrj * just return 3593446Smrj */ 3603446Smrj return_ACPI_STATUS (Status); 3613446Smrj } 3623446Smrj 363