13446Smrj /******************************************************************************* 23446Smrj * 33446Smrj * Module Name: nsxfeval - Public interfaces to the ACPI subsystem 43446Smrj * ACPI Object evaluation interfaces 5*7851SDana.Myers@Sun.COM * $Revision: 1.33 $ 63446Smrj * 73446Smrj ******************************************************************************/ 83446Smrj 93446Smrj /****************************************************************************** 103446Smrj * 113446Smrj * 1. Copyright Notice 123446Smrj * 13*7851SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp. 143446Smrj * All rights reserved. 153446Smrj * 163446Smrj * 2. License 173446Smrj * 183446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property 193446Smrj * rights. You may have additional license terms from the party that provided 203446Smrj * you this software, covering your right to use that party's intellectual 213446Smrj * property rights. 223446Smrj * 233446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 243446Smrj * copy of the source code appearing in this file ("Covered Code") an 253446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 263446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy, 273446Smrj * make derivatives, distribute, use and display any portion of the Covered 283446Smrj * Code in any form, with the right to sublicense such rights; and 293446Smrj * 303446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 313446Smrj * license (with the right to sublicense), under only those claims of Intel 323446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell, 333446Smrj * offer to sell, and import the Covered Code and derivative works thereof 343446Smrj * solely to the minimum extent necessary to exercise the above copyright 353446Smrj * license, and in no event shall the patent license extend to any additions 363446Smrj * to or modifications of the Original Intel Code. No other license or right 373446Smrj * is granted directly or by implication, estoppel or otherwise; 383446Smrj * 393446Smrj * The above copyright and patent license is granted only if the following 403446Smrj * conditions are met: 413446Smrj * 423446Smrj * 3. Conditions 433446Smrj * 443446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 453446Smrj * Redistribution of source code of any substantial portion of the Covered 463446Smrj * Code or modification with rights to further distribute source must include 473446Smrj * the above Copyright Notice, the above License, this list of Conditions, 483446Smrj * and the following Disclaimer and Export Compliance provision. In addition, 493446Smrj * Licensee must cause all Covered Code to which Licensee contributes to 503446Smrj * contain a file documenting the changes Licensee made to create that Covered 513446Smrj * Code and the date of any change. Licensee must include in that file the 523446Smrj * documentation of any changes made by any predecessor Licensee. Licensee 533446Smrj * must include a prominent statement that the modification is derived, 543446Smrj * directly or indirectly, from Original Intel Code. 553446Smrj * 563446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 573446Smrj * Redistribution of source code of any substantial portion of the Covered 583446Smrj * Code or modification without rights to further distribute source must 593446Smrj * include the following Disclaimer and Export Compliance provision in the 603446Smrj * documentation and/or other materials provided with distribution. In 613446Smrj * addition, Licensee may not authorize further sublicense of source of any 623446Smrj * portion of the Covered Code, and must include terms to the effect that the 633446Smrj * license from Licensee to its licensee is limited to the intellectual 643446Smrj * property embodied in the software Licensee provides to its licensee, and 653446Smrj * not to intellectual property embodied in modifications its licensee may 663446Smrj * make. 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 1193446Smrj #define __NSXFEVAL_C__ 1203446Smrj 1213446Smrj #include "acpi.h" 1223446Smrj #include "acnamesp.h" 1233446Smrj #include "acinterp.h" 1243446Smrj 1253446Smrj 1263446Smrj #define _COMPONENT ACPI_NAMESPACE 1273446Smrj ACPI_MODULE_NAME ("nsxfeval") 1283446Smrj 129*7851SDana.Myers@Sun.COM /* Local prototypes */ 130*7851SDana.Myers@Sun.COM 131*7851SDana.Myers@Sun.COM static void 132*7851SDana.Myers@Sun.COM AcpiNsResolveReferences ( 133*7851SDana.Myers@Sun.COM ACPI_EVALUATE_INFO *Info); 134*7851SDana.Myers@Sun.COM 1353446Smrj 1363446Smrj /******************************************************************************* 1373446Smrj * 1383446Smrj * FUNCTION: AcpiEvaluateObjectTyped 1393446Smrj * 1403446Smrj * PARAMETERS: Handle - Object handle (optional) 1413446Smrj * Pathname - Object pathname (optional) 1423446Smrj * ExternalParams - List of parameters to pass to method, 1433446Smrj * terminated by NULL. May be NULL 1443446Smrj * if no parameters are being passed. 1453446Smrj * ReturnBuffer - Where to put method's return value (if 1463446Smrj * any). If NULL, no value is returned. 1473446Smrj * ReturnType - Expected type of return object 1483446Smrj * 1493446Smrj * RETURN: Status 1503446Smrj * 1513446Smrj * DESCRIPTION: Find and evaluate the given object, passing the given 1523446Smrj * parameters if necessary. One of "Handle" or "Pathname" must 1533446Smrj * be valid (non-null) 1543446Smrj * 1553446Smrj ******************************************************************************/ 1563446Smrj 1573446Smrj ACPI_STATUS 1583446Smrj AcpiEvaluateObjectTyped ( 1593446Smrj ACPI_HANDLE Handle, 1603446Smrj ACPI_STRING Pathname, 1613446Smrj ACPI_OBJECT_LIST *ExternalParams, 1623446Smrj ACPI_BUFFER *ReturnBuffer, 1633446Smrj ACPI_OBJECT_TYPE ReturnType) 1643446Smrj { 1653446Smrj ACPI_STATUS Status; 1663446Smrj BOOLEAN MustFree = FALSE; 1673446Smrj 1683446Smrj 1693446Smrj ACPI_FUNCTION_TRACE (AcpiEvaluateObjectTyped); 1703446Smrj 1713446Smrj 1723446Smrj /* Return buffer must be valid */ 1733446Smrj 1743446Smrj if (!ReturnBuffer) 1753446Smrj { 1763446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 1773446Smrj } 1783446Smrj 1793446Smrj if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER) 1803446Smrj { 1813446Smrj MustFree = TRUE; 1823446Smrj } 1833446Smrj 1843446Smrj /* Evaluate the object */ 1853446Smrj 1863446Smrj Status = AcpiEvaluateObject (Handle, Pathname, ExternalParams, ReturnBuffer); 1873446Smrj if (ACPI_FAILURE (Status)) 1883446Smrj { 1893446Smrj return_ACPI_STATUS (Status); 1903446Smrj } 1913446Smrj 1923446Smrj /* Type ANY means "don't care" */ 1933446Smrj 1943446Smrj if (ReturnType == ACPI_TYPE_ANY) 1953446Smrj { 1963446Smrj return_ACPI_STATUS (AE_OK); 1973446Smrj } 1983446Smrj 1993446Smrj if (ReturnBuffer->Length == 0) 2003446Smrj { 2013446Smrj /* Error because caller specifically asked for a return value */ 2023446Smrj 2033446Smrj ACPI_ERROR ((AE_INFO, "No return value")); 2043446Smrj return_ACPI_STATUS (AE_NULL_OBJECT); 2053446Smrj } 2063446Smrj 2073446Smrj /* Examine the object type returned from EvaluateObject */ 2083446Smrj 2093446Smrj if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType) 2103446Smrj { 2113446Smrj return_ACPI_STATUS (AE_OK); 2123446Smrj } 2133446Smrj 2143446Smrj /* Return object type does not match requested type */ 2153446Smrj 2163446Smrj ACPI_ERROR ((AE_INFO, 2173446Smrj "Incorrect return type [%s] requested [%s]", 2183446Smrj AcpiUtGetTypeName (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type), 2193446Smrj AcpiUtGetTypeName (ReturnType))); 2203446Smrj 2213446Smrj if (MustFree) 2223446Smrj { 2233446Smrj /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ 2243446Smrj 2253446Smrj AcpiOsFree (ReturnBuffer->Pointer); 2263446Smrj ReturnBuffer->Pointer = NULL; 2273446Smrj } 2283446Smrj 2293446Smrj ReturnBuffer->Length = 0; 2303446Smrj return_ACPI_STATUS (AE_TYPE); 2313446Smrj } 2323446Smrj 2333446Smrj ACPI_EXPORT_SYMBOL (AcpiEvaluateObjectTyped) 2343446Smrj 2353446Smrj 2363446Smrj /******************************************************************************* 2373446Smrj * 2383446Smrj * FUNCTION: AcpiEvaluateObject 2393446Smrj * 2403446Smrj * PARAMETERS: Handle - Object handle (optional) 2413446Smrj * Pathname - Object pathname (optional) 2423446Smrj * ExternalParams - List of parameters to pass to method, 2433446Smrj * terminated by NULL. May be NULL 2443446Smrj * if no parameters are being passed. 2453446Smrj * ReturnBuffer - Where to put method's return value (if 2463446Smrj * any). If NULL, no value is returned. 2473446Smrj * 2483446Smrj * RETURN: Status 2493446Smrj * 2503446Smrj * DESCRIPTION: Find and evaluate the given object, passing the given 2513446Smrj * parameters if necessary. One of "Handle" or "Pathname" must 2523446Smrj * be valid (non-null) 2533446Smrj * 2543446Smrj ******************************************************************************/ 2553446Smrj 2563446Smrj ACPI_STATUS 2573446Smrj AcpiEvaluateObject ( 2583446Smrj ACPI_HANDLE Handle, 2593446Smrj ACPI_STRING Pathname, 2603446Smrj ACPI_OBJECT_LIST *ExternalParams, 2613446Smrj ACPI_BUFFER *ReturnBuffer) 2623446Smrj { 2633446Smrj ACPI_STATUS Status; 2643446Smrj ACPI_EVALUATE_INFO *Info; 2653446Smrj ACPI_SIZE BufferSpaceNeeded; 2663446Smrj UINT32 i; 2673446Smrj 2683446Smrj 2693446Smrj ACPI_FUNCTION_TRACE (AcpiEvaluateObject); 2703446Smrj 2713446Smrj 2723446Smrj /* Allocate and initialize the evaluation information block */ 2733446Smrj 2743446Smrj Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 2753446Smrj if (!Info) 2763446Smrj { 2773446Smrj return_ACPI_STATUS (AE_NO_MEMORY); 2783446Smrj } 2793446Smrj 2803446Smrj Info->Pathname = Pathname; 2813446Smrj 2823446Smrj /* Convert and validate the device handle */ 2833446Smrj 2843446Smrj Info->PrefixNode = AcpiNsMapHandleToNode (Handle); 2853446Smrj if (!Info->PrefixNode) 2863446Smrj { 2873446Smrj Status = AE_BAD_PARAMETER; 2883446Smrj goto Cleanup; 2893446Smrj } 2903446Smrj 2913446Smrj /* 2923446Smrj * If there are parameters to be passed to a control method, the external 2933446Smrj * objects must all be converted to internal objects 2943446Smrj */ 2953446Smrj if (ExternalParams && ExternalParams->Count) 2963446Smrj { 2973446Smrj /* 2983446Smrj * Allocate a new parameter block for the internal objects 2993446Smrj * Add 1 to count to allow for null terminated internal list 3003446Smrj */ 3013446Smrj Info->Parameters = ACPI_ALLOCATE_ZEROED ( 3023446Smrj ((ACPI_SIZE) ExternalParams->Count + 1) * sizeof (void *)); 3033446Smrj if (!Info->Parameters) 3043446Smrj { 3053446Smrj Status = AE_NO_MEMORY; 3063446Smrj goto Cleanup; 3073446Smrj } 3083446Smrj 3093446Smrj /* Convert each external object in the list to an internal object */ 3103446Smrj 3113446Smrj for (i = 0; i < ExternalParams->Count; i++) 3123446Smrj { 3133446Smrj Status = AcpiUtCopyEobjectToIobject ( 3143446Smrj &ExternalParams->Pointer[i], &Info->Parameters[i]); 3153446Smrj if (ACPI_FAILURE (Status)) 3163446Smrj { 3173446Smrj goto Cleanup; 3183446Smrj } 3193446Smrj } 3203446Smrj Info->Parameters[ExternalParams->Count] = NULL; 3213446Smrj } 3223446Smrj 3233446Smrj /* 3243446Smrj * Three major cases: 3253446Smrj * 1) Fully qualified pathname 3263446Smrj * 2) No handle, not fully qualified pathname (error) 3273446Smrj * 3) Valid handle 3283446Smrj */ 3293446Smrj if ((Pathname) && 3303446Smrj (AcpiNsValidRootPrefix (Pathname[0]))) 3313446Smrj { 3323446Smrj /* The path is fully qualified, just evaluate by name */ 3333446Smrj 3343446Smrj Info->PrefixNode = NULL; 3353446Smrj Status = AcpiNsEvaluate (Info); 3363446Smrj } 3373446Smrj else if (!Handle) 3383446Smrj { 3393446Smrj /* 3403446Smrj * A handle is optional iff a fully qualified pathname is specified. 3413446Smrj * Since we've already handled fully qualified names above, this is 3423446Smrj * an error 3433446Smrj */ 3443446Smrj if (!Pathname) 3453446Smrj { 3463446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 3473446Smrj "Both Handle and Pathname are NULL")); 3483446Smrj } 3493446Smrj else 3503446Smrj { 3513446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 3523446Smrj "Null Handle with relative pathname [%s]", Pathname)); 3533446Smrj } 3543446Smrj 3553446Smrj Status = AE_BAD_PARAMETER; 3563446Smrj } 3573446Smrj else 3583446Smrj { 3593446Smrj /* We have a namespace a node and a possible relative path */ 3603446Smrj 3613446Smrj Status = AcpiNsEvaluate (Info); 3623446Smrj } 3633446Smrj 3643446Smrj /* 3653446Smrj * If we are expecting a return value, and all went well above, 3663446Smrj * copy the return value to an external object. 3673446Smrj */ 3683446Smrj if (ReturnBuffer) 3693446Smrj { 3703446Smrj if (!Info->ReturnObject) 3713446Smrj { 3723446Smrj ReturnBuffer->Length = 0; 3733446Smrj } 3743446Smrj else 3753446Smrj { 3763446Smrj if (ACPI_GET_DESCRIPTOR_TYPE (Info->ReturnObject) == 3773446Smrj ACPI_DESC_TYPE_NAMED) 3783446Smrj { 3793446Smrj /* 3803446Smrj * If we received a NS Node as a return object, this means that 3813446Smrj * the object we are evaluating has nothing interesting to 3823446Smrj * return (such as a mutex, etc.) We return an error because 3833446Smrj * these types are essentially unsupported by this interface. 3843446Smrj * We don't check up front because this makes it easier to add 3853446Smrj * support for various types at a later date if necessary. 3863446Smrj */ 3873446Smrj Status = AE_TYPE; 3883446Smrj Info->ReturnObject = NULL; /* No need to delete a NS Node */ 3893446Smrj ReturnBuffer->Length = 0; 3903446Smrj } 3913446Smrj 3923446Smrj if (ACPI_SUCCESS (Status)) 3933446Smrj { 394*7851SDana.Myers@Sun.COM /* Dereference Index and RefOf references */ 395*7851SDana.Myers@Sun.COM 396*7851SDana.Myers@Sun.COM AcpiNsResolveReferences (Info); 397*7851SDana.Myers@Sun.COM 3983446Smrj /* Get the size of the returned object */ 3993446Smrj 4003446Smrj Status = AcpiUtGetObjectSize (Info->ReturnObject, 4013446Smrj &BufferSpaceNeeded); 4023446Smrj if (ACPI_SUCCESS (Status)) 4033446Smrj { 4043446Smrj /* Validate/Allocate/Clear caller buffer */ 4053446Smrj 4063446Smrj Status = AcpiUtInitializeBuffer (ReturnBuffer, 4073446Smrj BufferSpaceNeeded); 4083446Smrj if (ACPI_FAILURE (Status)) 4093446Smrj { 4103446Smrj /* 4113446Smrj * Caller's buffer is too small or a new one can't 4123446Smrj * be allocated 4133446Smrj */ 4143446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 4153446Smrj "Needed buffer size %X, %s\n", 4163446Smrj (UINT32) BufferSpaceNeeded, 4173446Smrj AcpiFormatException (Status))); 4183446Smrj } 4193446Smrj else 4203446Smrj { 4213446Smrj /* We have enough space for the object, build it */ 4223446Smrj 4233446Smrj Status = AcpiUtCopyIobjectToEobject (Info->ReturnObject, 4243446Smrj ReturnBuffer); 4253446Smrj } 4263446Smrj } 4273446Smrj } 4283446Smrj } 4293446Smrj } 4303446Smrj 4313446Smrj if (Info->ReturnObject) 4323446Smrj { 4333446Smrj /* 4343446Smrj * Delete the internal return object. NOTE: Interpreter must be 4353446Smrj * locked to avoid race condition. 4363446Smrj */ 437*7851SDana.Myers@Sun.COM AcpiExEnterInterpreter (); 4383446Smrj 439*7851SDana.Myers@Sun.COM /* Remove one reference on the return object (should delete it) */ 440*7851SDana.Myers@Sun.COM 441*7851SDana.Myers@Sun.COM AcpiUtRemoveReference (Info->ReturnObject); 442*7851SDana.Myers@Sun.COM AcpiExExitInterpreter (); 4433446Smrj } 4443446Smrj 4453446Smrj 4463446Smrj Cleanup: 4473446Smrj 4483446Smrj /* Free the input parameter list (if we created one) */ 4493446Smrj 4503446Smrj if (Info->Parameters) 4513446Smrj { 4523446Smrj /* Free the allocated parameter block */ 4533446Smrj 4543446Smrj AcpiUtDeleteInternalObjectList (Info->Parameters); 4553446Smrj } 4563446Smrj 4573446Smrj ACPI_FREE (Info); 4583446Smrj return_ACPI_STATUS (Status); 4593446Smrj } 4603446Smrj 4613446Smrj ACPI_EXPORT_SYMBOL (AcpiEvaluateObject) 4623446Smrj 4633446Smrj 4643446Smrj /******************************************************************************* 4653446Smrj * 466*7851SDana.Myers@Sun.COM * FUNCTION: AcpiNsResolveReferences 467*7851SDana.Myers@Sun.COM * 468*7851SDana.Myers@Sun.COM * PARAMETERS: Info - Evaluation info block 469*7851SDana.Myers@Sun.COM * 470*7851SDana.Myers@Sun.COM * RETURN: Info->ReturnObject is replaced with the dereferenced object 471*7851SDana.Myers@Sun.COM * 472*7851SDana.Myers@Sun.COM * DESCRIPTION: Dereference certain reference objects. Called before an 473*7851SDana.Myers@Sun.COM * internal return object is converted to an external ACPI_OBJECT. 474*7851SDana.Myers@Sun.COM * 475*7851SDana.Myers@Sun.COM * Performs an automatic dereference of Index and RefOf reference objects. 476*7851SDana.Myers@Sun.COM * These reference objects are not supported by the ACPI_OBJECT, so this is a 477*7851SDana.Myers@Sun.COM * last resort effort to return something useful. Also, provides compatibility 478*7851SDana.Myers@Sun.COM * with other ACPI implementations. 479*7851SDana.Myers@Sun.COM * 480*7851SDana.Myers@Sun.COM * NOTE: does not handle references within returned package objects or nested 481*7851SDana.Myers@Sun.COM * references, but this support could be added later if found to be necessary. 482*7851SDana.Myers@Sun.COM * 483*7851SDana.Myers@Sun.COM ******************************************************************************/ 484*7851SDana.Myers@Sun.COM 485*7851SDana.Myers@Sun.COM static void 486*7851SDana.Myers@Sun.COM AcpiNsResolveReferences ( 487*7851SDana.Myers@Sun.COM ACPI_EVALUATE_INFO *Info) 488*7851SDana.Myers@Sun.COM { 489*7851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *ObjDesc = NULL; 490*7851SDana.Myers@Sun.COM ACPI_NAMESPACE_NODE *Node; 491*7851SDana.Myers@Sun.COM 492*7851SDana.Myers@Sun.COM 493*7851SDana.Myers@Sun.COM /* We are interested in reference objects only */ 494*7851SDana.Myers@Sun.COM 495*7851SDana.Myers@Sun.COM if (ACPI_GET_OBJECT_TYPE (Info->ReturnObject) != ACPI_TYPE_LOCAL_REFERENCE) 496*7851SDana.Myers@Sun.COM { 497*7851SDana.Myers@Sun.COM return; 498*7851SDana.Myers@Sun.COM } 499*7851SDana.Myers@Sun.COM 500*7851SDana.Myers@Sun.COM /* 501*7851SDana.Myers@Sun.COM * Two types of references are supported - those created by Index and 502*7851SDana.Myers@Sun.COM * RefOf operators. A name reference (AML_NAMEPATH_OP) can be converted 503*7851SDana.Myers@Sun.COM * to an ACPI_OBJECT, so it is not dereferenced here. A DdbHandle 504*7851SDana.Myers@Sun.COM * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to 505*7851SDana.Myers@Sun.COM * an ACPI_OBJECT. 506*7851SDana.Myers@Sun.COM */ 507*7851SDana.Myers@Sun.COM switch (Info->ReturnObject->Reference.Class) 508*7851SDana.Myers@Sun.COM { 509*7851SDana.Myers@Sun.COM case ACPI_REFCLASS_INDEX: 510*7851SDana.Myers@Sun.COM 511*7851SDana.Myers@Sun.COM ObjDesc = *(Info->ReturnObject->Reference.Where); 512*7851SDana.Myers@Sun.COM break; 513*7851SDana.Myers@Sun.COM 514*7851SDana.Myers@Sun.COM case ACPI_REFCLASS_REFOF: 515*7851SDana.Myers@Sun.COM 516*7851SDana.Myers@Sun.COM Node = Info->ReturnObject->Reference.Object; 517*7851SDana.Myers@Sun.COM if (Node) 518*7851SDana.Myers@Sun.COM { 519*7851SDana.Myers@Sun.COM ObjDesc = Node->Object; 520*7851SDana.Myers@Sun.COM } 521*7851SDana.Myers@Sun.COM break; 522*7851SDana.Myers@Sun.COM 523*7851SDana.Myers@Sun.COM default: 524*7851SDana.Myers@Sun.COM return; 525*7851SDana.Myers@Sun.COM } 526*7851SDana.Myers@Sun.COM 527*7851SDana.Myers@Sun.COM /* Replace the existing reference object */ 528*7851SDana.Myers@Sun.COM 529*7851SDana.Myers@Sun.COM if (ObjDesc) 530*7851SDana.Myers@Sun.COM { 531*7851SDana.Myers@Sun.COM AcpiUtAddReference (ObjDesc); 532*7851SDana.Myers@Sun.COM AcpiUtRemoveReference (Info->ReturnObject); 533*7851SDana.Myers@Sun.COM Info->ReturnObject = ObjDesc; 534*7851SDana.Myers@Sun.COM } 535*7851SDana.Myers@Sun.COM 536*7851SDana.Myers@Sun.COM return; 537*7851SDana.Myers@Sun.COM } 538*7851SDana.Myers@Sun.COM 539*7851SDana.Myers@Sun.COM 540*7851SDana.Myers@Sun.COM /******************************************************************************* 541*7851SDana.Myers@Sun.COM * 5423446Smrj * FUNCTION: AcpiWalkNamespace 5433446Smrj * 5443446Smrj * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for 5453446Smrj * StartObject - Handle in namespace where search begins 5463446Smrj * MaxDepth - Depth to which search is to reach 5473446Smrj * UserFunction - Called when an object of "Type" is found 5483446Smrj * Context - Passed to user function 5493446Smrj * ReturnValue - Location where return value of 5503446Smrj * UserFunction is put if terminated early 5513446Smrj * 5523446Smrj * RETURNS Return value from the UserFunction if terminated early. 5533446Smrj * Otherwise, returns NULL. 5543446Smrj * 5553446Smrj * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 5563446Smrj * starting (and ending) at the object specified by StartHandle. 5573446Smrj * The UserFunction is called whenever an object that matches 5583446Smrj * the type parameter is found. If the user function returns 5593446Smrj * a non-zero value, the search is terminated immediately and this 5603446Smrj * value is returned to the caller. 5613446Smrj * 5623446Smrj * The point of this procedure is to provide a generic namespace 5633446Smrj * walk routine that can be called from multiple places to 5643446Smrj * provide multiple services; the User Function can be tailored 5653446Smrj * to each task, whether it is a print function, a compare 5663446Smrj * function, etc. 5673446Smrj * 5683446Smrj ******************************************************************************/ 5693446Smrj 5703446Smrj ACPI_STATUS 5713446Smrj AcpiWalkNamespace ( 5723446Smrj ACPI_OBJECT_TYPE Type, 5733446Smrj ACPI_HANDLE StartObject, 5743446Smrj UINT32 MaxDepth, 5753446Smrj ACPI_WALK_CALLBACK UserFunction, 5763446Smrj void *Context, 5773446Smrj void **ReturnValue) 5783446Smrj { 5793446Smrj ACPI_STATUS Status; 5803446Smrj 5813446Smrj 5823446Smrj ACPI_FUNCTION_TRACE (AcpiWalkNamespace); 5833446Smrj 5843446Smrj 5853446Smrj /* Parameter validation */ 5863446Smrj 5873446Smrj if ((Type > ACPI_TYPE_LOCAL_MAX) || 5883446Smrj (!MaxDepth) || 5893446Smrj (!UserFunction)) 5903446Smrj { 5913446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 5923446Smrj } 5933446Smrj 5943446Smrj /* 5953446Smrj * Lock the namespace around the walk. 5963446Smrj * The namespace will be unlocked/locked around each call 5973446Smrj * to the user function - since this function 5983446Smrj * must be allowed to make Acpi calls itself. 5993446Smrj */ 6003446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 6013446Smrj if (ACPI_FAILURE (Status)) 6023446Smrj { 6033446Smrj return_ACPI_STATUS (Status); 6043446Smrj } 6053446Smrj 6063446Smrj Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth, 6073446Smrj ACPI_NS_WALK_UNLOCK, 6083446Smrj UserFunction, Context, ReturnValue); 6093446Smrj 6103446Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 6113446Smrj return_ACPI_STATUS (Status); 6123446Smrj } 6133446Smrj 6143446Smrj ACPI_EXPORT_SYMBOL (AcpiWalkNamespace) 6153446Smrj 6163446Smrj 6173446Smrj /******************************************************************************* 6183446Smrj * 6193446Smrj * FUNCTION: AcpiNsGetDeviceCallback 6203446Smrj * 6213446Smrj * PARAMETERS: Callback from AcpiGetDevice 6223446Smrj * 6233446Smrj * RETURN: Status 6243446Smrj * 6253446Smrj * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non- 6263446Smrj * present devices, or if they specified a HID, it filters based 6273446Smrj * on that. 6283446Smrj * 6293446Smrj ******************************************************************************/ 6303446Smrj 6313446Smrj static ACPI_STATUS 6323446Smrj AcpiNsGetDeviceCallback ( 6333446Smrj ACPI_HANDLE ObjHandle, 6343446Smrj UINT32 NestingLevel, 6353446Smrj void *Context, 6363446Smrj void **ReturnValue) 6373446Smrj { 6383446Smrj ACPI_GET_DEVICES_INFO *Info = Context; 6393446Smrj ACPI_STATUS Status; 6403446Smrj ACPI_NAMESPACE_NODE *Node; 6413446Smrj UINT32 Flags; 6423446Smrj ACPI_DEVICE_ID Hid; 6433446Smrj ACPI_COMPATIBLE_ID_LIST *Cid; 644*7851SDana.Myers@Sun.COM UINT32 i; 645*7851SDana.Myers@Sun.COM BOOLEAN Found; 6463446Smrj 6473446Smrj 6483446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 6493446Smrj if (ACPI_FAILURE (Status)) 6503446Smrj { 6513446Smrj return (Status); 6523446Smrj } 6533446Smrj 6543446Smrj Node = AcpiNsMapHandleToNode (ObjHandle); 6553446Smrj Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 6563446Smrj if (ACPI_FAILURE (Status)) 6573446Smrj { 6583446Smrj return (Status); 6593446Smrj } 6603446Smrj 6613446Smrj if (!Node) 6623446Smrj { 6633446Smrj return (AE_BAD_PARAMETER); 6643446Smrj } 6653446Smrj 6663446Smrj /* Run _STA to determine if device is present */ 6673446Smrj 6683446Smrj Status = AcpiUtExecute_STA (Node, &Flags); 6693446Smrj if (ACPI_FAILURE (Status)) 6703446Smrj { 6713446Smrj return (AE_CTRL_DEPTH); 6723446Smrj } 6733446Smrj 674*7851SDana.Myers@Sun.COM if (!(Flags & ACPI_STA_DEVICE_PRESENT) && 675*7851SDana.Myers@Sun.COM !(Flags & ACPI_STA_DEVICE_FUNCTIONING)) 6763446Smrj { 677*7851SDana.Myers@Sun.COM /* 678*7851SDana.Myers@Sun.COM * Don't examine the children of the device only when the 679*7851SDana.Myers@Sun.COM * device is neither present nor functional. See ACPI spec, 680*7851SDana.Myers@Sun.COM * description of _STA for more information. 681*7851SDana.Myers@Sun.COM */ 6823446Smrj return (AE_CTRL_DEPTH); 6833446Smrj } 6843446Smrj 6853446Smrj /* Filter based on device HID & CID */ 6863446Smrj 6873446Smrj if (Info->Hid != NULL) 6883446Smrj { 6893446Smrj Status = AcpiUtExecute_HID (Node, &Hid); 6903446Smrj if (Status == AE_NOT_FOUND) 6913446Smrj { 6923446Smrj return (AE_OK); 6933446Smrj } 6943446Smrj else if (ACPI_FAILURE (Status)) 6953446Smrj { 6963446Smrj return (AE_CTRL_DEPTH); 6973446Smrj } 6983446Smrj 6993446Smrj if (ACPI_STRNCMP (Hid.Value, Info->Hid, sizeof (Hid.Value)) != 0) 7003446Smrj { 701*7851SDana.Myers@Sun.COM /* 702*7851SDana.Myers@Sun.COM * HID does not match, attempt match within the 703*7851SDana.Myers@Sun.COM * list of Compatible IDs (CIDs) 704*7851SDana.Myers@Sun.COM */ 7053446Smrj Status = AcpiUtExecute_CID (Node, &Cid); 7063446Smrj if (Status == AE_NOT_FOUND) 7073446Smrj { 7083446Smrj return (AE_OK); 7093446Smrj } 7103446Smrj else if (ACPI_FAILURE (Status)) 7113446Smrj { 7123446Smrj return (AE_CTRL_DEPTH); 7133446Smrj } 7143446Smrj 7153446Smrj /* Walk the CID list */ 7163446Smrj 717*7851SDana.Myers@Sun.COM Found = FALSE; 7183446Smrj for (i = 0; i < Cid->Count; i++) 7193446Smrj { 7203446Smrj if (ACPI_STRNCMP (Cid->Id[i].Value, Info->Hid, 721*7851SDana.Myers@Sun.COM sizeof (ACPI_COMPATIBLE_ID)) == 0) 7223446Smrj { 723*7851SDana.Myers@Sun.COM /* Found a matching CID */ 724*7851SDana.Myers@Sun.COM 725*7851SDana.Myers@Sun.COM Found = TRUE; 726*7851SDana.Myers@Sun.COM break; 7273446Smrj } 7283446Smrj } 729*7851SDana.Myers@Sun.COM 7303446Smrj ACPI_FREE (Cid); 731*7851SDana.Myers@Sun.COM if (!Found) 732*7851SDana.Myers@Sun.COM { 733*7851SDana.Myers@Sun.COM return (AE_OK); 734*7851SDana.Myers@Sun.COM } 7353446Smrj } 7363446Smrj } 7373446Smrj 738*7851SDana.Myers@Sun.COM /* We have a valid device, invoke the user function */ 739*7851SDana.Myers@Sun.COM 7403446Smrj Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context, 7413446Smrj ReturnValue); 7423446Smrj return (Status); 7433446Smrj } 7443446Smrj 7453446Smrj 7463446Smrj /******************************************************************************* 7473446Smrj * 7483446Smrj * FUNCTION: AcpiGetDevices 7493446Smrj * 7503446Smrj * PARAMETERS: HID - HID to search for. Can be NULL. 7513446Smrj * UserFunction - Called when a matching object is found 7523446Smrj * Context - Passed to user function 7533446Smrj * ReturnValue - Location where return value of 7543446Smrj * UserFunction is put if terminated early 7553446Smrj * 7563446Smrj * RETURNS Return value from the UserFunction if terminated early. 7573446Smrj * Otherwise, returns NULL. 7583446Smrj * 7593446Smrj * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 7603446Smrj * starting (and ending) at the object specified by StartHandle. 7613446Smrj * The UserFunction is called whenever an object of type 7623446Smrj * Device is found. If the user function returns 7633446Smrj * a non-zero value, the search is terminated immediately and this 7643446Smrj * value is returned to the caller. 7653446Smrj * 7663446Smrj * This is a wrapper for WalkNamespace, but the callback performs 767*7851SDana.Myers@Sun.COM * additional filtering. Please see AcpiNsGetDeviceCallback. 7683446Smrj * 7693446Smrj ******************************************************************************/ 7703446Smrj 7713446Smrj ACPI_STATUS 7723446Smrj AcpiGetDevices ( 7733446Smrj char *HID, 7743446Smrj ACPI_WALK_CALLBACK UserFunction, 7753446Smrj void *Context, 7763446Smrj void **ReturnValue) 7773446Smrj { 7783446Smrj ACPI_STATUS Status; 7793446Smrj ACPI_GET_DEVICES_INFO Info; 7803446Smrj 7813446Smrj 7823446Smrj ACPI_FUNCTION_TRACE (AcpiGetDevices); 7833446Smrj 7843446Smrj 7853446Smrj /* Parameter validation */ 7863446Smrj 7873446Smrj if (!UserFunction) 7883446Smrj { 7893446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 7903446Smrj } 7913446Smrj 7923446Smrj /* 7933446Smrj * We're going to call their callback from OUR callback, so we need 7943446Smrj * to know what it is, and their context parameter. 7953446Smrj */ 7963446Smrj Info.Hid = HID; 7973446Smrj Info.Context = Context; 7983446Smrj Info.UserFunction = UserFunction; 7993446Smrj 8003446Smrj /* 8013446Smrj * Lock the namespace around the walk. 8023446Smrj * The namespace will be unlocked/locked around each call 8033446Smrj * to the user function - since this function 8043446Smrj * must be allowed to make Acpi calls itself. 8053446Smrj */ 8063446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 8073446Smrj if (ACPI_FAILURE (Status)) 8083446Smrj { 8093446Smrj return_ACPI_STATUS (Status); 8103446Smrj } 8113446Smrj 8123446Smrj Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 8133446Smrj ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, 8143446Smrj AcpiNsGetDeviceCallback, &Info, ReturnValue); 8153446Smrj 8163446Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 8173446Smrj return_ACPI_STATUS (Status); 8183446Smrj } 8193446Smrj 8203446Smrj ACPI_EXPORT_SYMBOL (AcpiGetDevices) 8213446Smrj 8223446Smrj 8233446Smrj /******************************************************************************* 8243446Smrj * 8253446Smrj * FUNCTION: AcpiAttachData 8263446Smrj * 8273446Smrj * PARAMETERS: ObjHandle - Namespace node 8283446Smrj * Handler - Handler for this attachment 8293446Smrj * Data - Pointer to data to be attached 8303446Smrj * 8313446Smrj * RETURN: Status 8323446Smrj * 8333446Smrj * DESCRIPTION: Attach arbitrary data and handler to a namespace node. 8343446Smrj * 8353446Smrj ******************************************************************************/ 8363446Smrj 8373446Smrj ACPI_STATUS 8383446Smrj AcpiAttachData ( 8393446Smrj ACPI_HANDLE ObjHandle, 8403446Smrj ACPI_OBJECT_HANDLER Handler, 8413446Smrj void *Data) 8423446Smrj { 8433446Smrj ACPI_NAMESPACE_NODE *Node; 8443446Smrj ACPI_STATUS Status; 8453446Smrj 8463446Smrj 8473446Smrj /* Parameter validation */ 8483446Smrj 8493446Smrj if (!ObjHandle || 8503446Smrj !Handler || 8513446Smrj !Data) 8523446Smrj { 8533446Smrj return (AE_BAD_PARAMETER); 8543446Smrj } 8553446Smrj 8563446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 8573446Smrj if (ACPI_FAILURE (Status)) 8583446Smrj { 8593446Smrj return (Status); 8603446Smrj } 8613446Smrj 8623446Smrj /* Convert and validate the handle */ 8633446Smrj 8643446Smrj Node = AcpiNsMapHandleToNode (ObjHandle); 8653446Smrj if (!Node) 8663446Smrj { 8673446Smrj Status = AE_BAD_PARAMETER; 8683446Smrj goto UnlockAndExit; 8693446Smrj } 8703446Smrj 8713446Smrj Status = AcpiNsAttachData (Node, Handler, Data); 8723446Smrj 8733446Smrj UnlockAndExit: 8743446Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 8753446Smrj return (Status); 8763446Smrj } 8773446Smrj 8783446Smrj ACPI_EXPORT_SYMBOL (AcpiAttachData) 8793446Smrj 8803446Smrj 8813446Smrj /******************************************************************************* 8823446Smrj * 8833446Smrj * FUNCTION: AcpiDetachData 8843446Smrj * 8853446Smrj * PARAMETERS: ObjHandle - Namespace node handle 8863446Smrj * Handler - Handler used in call to AcpiAttachData 8873446Smrj * 8883446Smrj * RETURN: Status 8893446Smrj * 8903446Smrj * DESCRIPTION: Remove data that was previously attached to a node. 8913446Smrj * 8923446Smrj ******************************************************************************/ 8933446Smrj 8943446Smrj ACPI_STATUS 8953446Smrj AcpiDetachData ( 8963446Smrj ACPI_HANDLE ObjHandle, 8973446Smrj ACPI_OBJECT_HANDLER Handler) 8983446Smrj { 8993446Smrj ACPI_NAMESPACE_NODE *Node; 9003446Smrj ACPI_STATUS Status; 9013446Smrj 9023446Smrj 9033446Smrj /* Parameter validation */ 9043446Smrj 9053446Smrj if (!ObjHandle || 9063446Smrj !Handler) 9073446Smrj { 9083446Smrj return (AE_BAD_PARAMETER); 9093446Smrj } 9103446Smrj 9113446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 9123446Smrj if (ACPI_FAILURE (Status)) 9133446Smrj { 9143446Smrj return (Status); 9153446Smrj } 9163446Smrj 9173446Smrj /* Convert and validate the handle */ 9183446Smrj 9193446Smrj Node = AcpiNsMapHandleToNode (ObjHandle); 9203446Smrj if (!Node) 9213446Smrj { 9223446Smrj Status = AE_BAD_PARAMETER; 9233446Smrj goto UnlockAndExit; 9243446Smrj } 9253446Smrj 9263446Smrj Status = AcpiNsDetachData (Node, Handler); 9273446Smrj 9283446Smrj UnlockAndExit: 9293446Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 9303446Smrj return (Status); 9313446Smrj } 9323446Smrj 9333446Smrj ACPI_EXPORT_SYMBOL (AcpiDetachData) 9343446Smrj 9353446Smrj 9363446Smrj /******************************************************************************* 9373446Smrj * 9383446Smrj * FUNCTION: AcpiGetData 9393446Smrj * 9403446Smrj * PARAMETERS: ObjHandle - Namespace node 9413446Smrj * Handler - Handler used in call to AttachData 9423446Smrj * Data - Where the data is returned 9433446Smrj * 9443446Smrj * RETURN: Status 9453446Smrj * 9463446Smrj * DESCRIPTION: Retrieve data that was previously attached to a namespace node. 9473446Smrj * 9483446Smrj ******************************************************************************/ 9493446Smrj 9503446Smrj ACPI_STATUS 9513446Smrj AcpiGetData ( 9523446Smrj ACPI_HANDLE ObjHandle, 9533446Smrj ACPI_OBJECT_HANDLER Handler, 9543446Smrj void **Data) 9553446Smrj { 9563446Smrj ACPI_NAMESPACE_NODE *Node; 9573446Smrj ACPI_STATUS Status; 9583446Smrj 9593446Smrj 9603446Smrj /* Parameter validation */ 9613446Smrj 9623446Smrj if (!ObjHandle || 9633446Smrj !Handler || 9643446Smrj !Data) 9653446Smrj { 9663446Smrj return (AE_BAD_PARAMETER); 9673446Smrj } 9683446Smrj 9693446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 9703446Smrj if (ACPI_FAILURE (Status)) 9713446Smrj { 9723446Smrj return (Status); 9733446Smrj } 9743446Smrj 9753446Smrj /* Convert and validate the handle */ 9763446Smrj 9773446Smrj Node = AcpiNsMapHandleToNode (ObjHandle); 9783446Smrj if (!Node) 9793446Smrj { 9803446Smrj Status = AE_BAD_PARAMETER; 9813446Smrj goto UnlockAndExit; 9823446Smrj } 9833446Smrj 9843446Smrj Status = AcpiNsGetAttachedData (Node, Handler, Data); 9853446Smrj 9863446Smrj UnlockAndExit: 9873446Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 9883446Smrj return (Status); 9893446Smrj } 9903446Smrj 9913446Smrj ACPI_EXPORT_SYMBOL (AcpiGetData) 9923446Smrj 9933446Smrj 994