xref: /onnv-gate/usr/src/uts/intel/io/acpica/namespace/nseval.c (revision 11225:eb6056029d84)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: nseval - Object evaluation, includes control method execution
43446Smrj  *
53446Smrj  ******************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
119980SDana.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"
1209980SDana.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 
129*11225SDana.Myers@Sun.COM /* Local prototypes */
130*11225SDana.Myers@Sun.COM 
131*11225SDana.Myers@Sun.COM static void
132*11225SDana.Myers@Sun.COM AcpiNsExecModuleCode (
133*11225SDana.Myers@Sun.COM     ACPI_OPERAND_OBJECT     *MethodObj,
134*11225SDana.Myers@Sun.COM     ACPI_EVALUATE_INFO      *Info);
135*11225SDana.Myers@Sun.COM 
1363446Smrj 
1373446Smrj /*******************************************************************************
1383446Smrj  *
1393446Smrj  * FUNCTION:    AcpiNsEvaluate
1403446Smrj  *
1413446Smrj  * PARAMETERS:  Info            - Evaluation info block, contains:
1423446Smrj  *                  PrefixNode      - Prefix or Method/Object Node to execute
1433446Smrj  *                  Pathname        - Name of method to execute, If NULL, the
1443446Smrj  *                                    Node is the object to execute
1453446Smrj  *                  Parameters      - List of parameters to pass to the method,
1463446Smrj  *                                    terminated by NULL. Params itself may be
1473446Smrj  *                                    NULL if no parameters are being passed.
1483446Smrj  *                  ReturnObject    - Where to put method's return value (if
1493446Smrj  *                                    any). If NULL, no value is returned.
1503446Smrj  *                  ParameterType   - Type of Parameter list
1513446Smrj  *                  ReturnObject    - Where to put method's return value (if
1523446Smrj  *                                    any). If NULL, no value is returned.
1533446Smrj  *                  Flags           - ACPI_IGNORE_RETURN_VALUE to delete return
1543446Smrj  *
1553446Smrj  * RETURN:      Status
1563446Smrj  *
1573446Smrj  * DESCRIPTION: Execute a control method or return the current value of an
1583446Smrj  *              ACPI namespace object.
1593446Smrj  *
1603446Smrj  * MUTEX:       Locks interpreter
1613446Smrj  *
1623446Smrj  ******************************************************************************/
1633446Smrj 
1643446Smrj ACPI_STATUS
AcpiNsEvaluate(ACPI_EVALUATE_INFO * Info)1653446Smrj AcpiNsEvaluate (
1663446Smrj     ACPI_EVALUATE_INFO      *Info)
1673446Smrj {
1683446Smrj     ACPI_STATUS             Status;
1699980SDana.Myers@Sun.COM     ACPI_NAMESPACE_NODE     *Node;
1703446Smrj 
1713446Smrj 
1723446Smrj     ACPI_FUNCTION_TRACE (NsEvaluate);
1733446Smrj 
1743446Smrj 
1753446Smrj     if (!Info)
1763446Smrj     {
1773446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
1783446Smrj     }
1793446Smrj 
1803446Smrj     /* Initialize the return value to an invalid object */
1813446Smrj 
1823446Smrj     Info->ReturnObject = NULL;
1839980SDana.Myers@Sun.COM     Info->ParamCount = 0;
1843446Smrj 
1853446Smrj     /*
1863446Smrj      * Get the actual namespace node for the target object. Handles these cases:
1873446Smrj      *
1883446Smrj      * 1) Null node, Pathname (absolute path)
1893446Smrj      * 2) Node, Pathname (path relative to Node)
1903446Smrj      * 3) Node, Null Pathname
1913446Smrj      */
1923446Smrj     Status = AcpiNsGetNode (Info->PrefixNode, Info->Pathname,
1933446Smrj                 ACPI_NS_NO_UPSEARCH, &Info->ResolvedNode);
1943446Smrj     if (ACPI_FAILURE (Status))
1953446Smrj     {
1963446Smrj         return_ACPI_STATUS (Status);
1973446Smrj     }
1983446Smrj 
1993446Smrj     /*
2003446Smrj      * For a method alias, we must grab the actual method node so that proper
2013446Smrj      * scoping context will be established before execution.
2023446Smrj      */
2033446Smrj     if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
2043446Smrj     {
2053446Smrj         Info->ResolvedNode =
2063446Smrj             ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->ResolvedNode->Object);
2073446Smrj     }
2083446Smrj 
2093446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->Pathname,
2103446Smrj         Info->ResolvedNode, AcpiNsGetAttachedObject (Info->ResolvedNode)));
2113446Smrj 
2129980SDana.Myers@Sun.COM     Node = Info->ResolvedNode;
2139980SDana.Myers@Sun.COM 
2143446Smrj     /*
2153446Smrj      * Two major cases here:
2163446Smrj      *
2173446Smrj      * 1) The object is a control method -- execute it
2183446Smrj      * 2) The object is not a method -- just return it's current value
2193446Smrj      */
2203446Smrj     if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_METHOD)
2213446Smrj     {
2223446Smrj         /*
2233446Smrj          * 1) Object is a control method - execute it
2243446Smrj          */
2253446Smrj 
2263446Smrj         /* Verify that there is a method object associated with this node */
2273446Smrj 
2283446Smrj         Info->ObjDesc = AcpiNsGetAttachedObject (Info->ResolvedNode);
2293446Smrj         if (!Info->ObjDesc)
2303446Smrj         {
2313446Smrj             ACPI_ERROR ((AE_INFO, "Control method has no attached sub-object"));
2323446Smrj             return_ACPI_STATUS (AE_NULL_OBJECT);
2333446Smrj         }
2343446Smrj 
2359980SDana.Myers@Sun.COM         /* Count the number of arguments being passed to the method */
2367851SDana.Myers@Sun.COM 
2377851SDana.Myers@Sun.COM         if (Info->Parameters)
2387851SDana.Myers@Sun.COM         {
2397851SDana.Myers@Sun.COM             while (Info->Parameters[Info->ParamCount])
2407851SDana.Myers@Sun.COM             {
2419980SDana.Myers@Sun.COM                 if (Info->ParamCount > ACPI_METHOD_MAX_ARG)
2429980SDana.Myers@Sun.COM                 {
2439980SDana.Myers@Sun.COM                     return_ACPI_STATUS (AE_LIMIT);
2449980SDana.Myers@Sun.COM                 }
2457851SDana.Myers@Sun.COM                 Info->ParamCount++;
2467851SDana.Myers@Sun.COM             }
2477851SDana.Myers@Sun.COM         }
2487851SDana.Myers@Sun.COM 
2499980SDana.Myers@Sun.COM         ACPI_DUMP_PATHNAME (Info->ResolvedNode, "ACPI: Execute Method",
2503446Smrj             ACPI_LV_INFO, _COMPONENT);
2513446Smrj 
2523446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
2533446Smrj             "Method at AML address %p Length %X\n",
2543446Smrj             Info->ObjDesc->Method.AmlStart + 1,
2553446Smrj             Info->ObjDesc->Method.AmlLength - 1));
2563446Smrj 
2573446Smrj         /*
2583446Smrj          * Any namespace deletion must acquire both the namespace and
2593446Smrj          * interpreter locks to ensure that no thread is using the portion of
2603446Smrj          * the namespace that is being deleted.
2613446Smrj          *
2623446Smrj          * Execute the method via the interpreter. The interpreter is locked
2633446Smrj          * here before calling into the AML parser
2643446Smrj          */
2657851SDana.Myers@Sun.COM         AcpiExEnterInterpreter ();
2663446Smrj         Status = AcpiPsExecuteMethod (Info);
2673446Smrj         AcpiExExitInterpreter ();
2683446Smrj     }
2693446Smrj     else
2703446Smrj     {
2713446Smrj         /*
2723446Smrj          * 2) Object is not a method, return its current value
2737851SDana.Myers@Sun.COM          *
2747851SDana.Myers@Sun.COM          * Disallow certain object types. For these, "evaluation" is undefined.
2753446Smrj          */
2767851SDana.Myers@Sun.COM         switch (Info->ResolvedNode->Type)
2777851SDana.Myers@Sun.COM         {
2787851SDana.Myers@Sun.COM         case ACPI_TYPE_DEVICE:
2797851SDana.Myers@Sun.COM         case ACPI_TYPE_EVENT:
2807851SDana.Myers@Sun.COM         case ACPI_TYPE_MUTEX:
2817851SDana.Myers@Sun.COM         case ACPI_TYPE_REGION:
2827851SDana.Myers@Sun.COM         case ACPI_TYPE_THERMAL:
2837851SDana.Myers@Sun.COM         case ACPI_TYPE_LOCAL_SCOPE:
2847851SDana.Myers@Sun.COM 
2857851SDana.Myers@Sun.COM             ACPI_ERROR ((AE_INFO,
2867851SDana.Myers@Sun.COM                 "[%4.4s] Evaluation of object type [%s] is not supported",
2877851SDana.Myers@Sun.COM                 Info->ResolvedNode->Name.Ascii,
2887851SDana.Myers@Sun.COM                 AcpiUtGetTypeName (Info->ResolvedNode->Type)));
2897851SDana.Myers@Sun.COM 
2907851SDana.Myers@Sun.COM             return_ACPI_STATUS (AE_TYPE);
2917851SDana.Myers@Sun.COM 
2927851SDana.Myers@Sun.COM         default:
2937851SDana.Myers@Sun.COM             break;
2947851SDana.Myers@Sun.COM         }
2953446Smrj 
2963446Smrj         /*
2973446Smrj          * Objects require additional resolution steps (e.g., the Node may be
2983446Smrj          * a field that must be read, etc.) -- we can't just grab the object
2993446Smrj          * out of the node.
3003446Smrj          *
3013446Smrj          * Use ResolveNodeToValue() to get the associated value.
3023446Smrj          *
3033446Smrj          * NOTE: we can get away with passing in NULL for a walk state because
3043446Smrj          * ResolvedNode is guaranteed to not be a reference to either a method
3053446Smrj          * local or a method argument (because this interface is never called
3063446Smrj          * from a running method.)
3073446Smrj          *
3083446Smrj          * Even though we do not directly invoke the interpreter for object
3093446Smrj          * resolution, we must lock it because we could access an opregion.
3103446Smrj          * The opregion access code assumes that the interpreter is locked.
3113446Smrj          */
3127851SDana.Myers@Sun.COM         AcpiExEnterInterpreter ();
3133446Smrj 
3143446Smrj         /* Function has a strange interface */
3153446Smrj 
3163446Smrj         Status = AcpiExResolveNodeToValue (&Info->ResolvedNode, NULL);
3173446Smrj         AcpiExExitInterpreter ();
3183446Smrj 
3193446Smrj         /*
3203446Smrj          * If AcpiExResolveNodeToValue() succeeded, the return value was placed
3213446Smrj          * in ResolvedNode.
3223446Smrj          */
3233446Smrj         if (ACPI_SUCCESS (Status))
3243446Smrj         {
3253446Smrj             Status = AE_CTRL_RETURN_VALUE;
3263446Smrj             Info->ReturnObject =
3273446Smrj                 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->ResolvedNode);
3283446Smrj 
3293446Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
3303446Smrj                 Info->ReturnObject,
3313446Smrj                 AcpiUtGetObjectTypeName (Info->ReturnObject)));
3323446Smrj         }
3333446Smrj     }
3343446Smrj 
3353446Smrj     /*
3369980SDana.Myers@Sun.COM      * Check input argument count against the ASL-defined count for a method.
3379980SDana.Myers@Sun.COM      * Also check predefined names: argument count and return value against
3389980SDana.Myers@Sun.COM      * the ACPI specification. Some incorrect return value types are repaired.
3393446Smrj      */
3409980SDana.Myers@Sun.COM     (void) AcpiNsCheckPredefinedNames (Node, Info->ParamCount,
3419980SDana.Myers@Sun.COM                 Status, &Info->ReturnObject);
3429980SDana.Myers@Sun.COM 
3439980SDana.Myers@Sun.COM     /* Check if there is a return value that must be dealt with */
3449980SDana.Myers@Sun.COM 
3453446Smrj     if (Status == AE_CTRL_RETURN_VALUE)
3463446Smrj     {
3473446Smrj         /* If caller does not want the return value, delete it */
3483446Smrj 
3493446Smrj         if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
3503446Smrj         {
3513446Smrj             AcpiUtRemoveReference (Info->ReturnObject);
3523446Smrj             Info->ReturnObject = NULL;
3533446Smrj         }
3543446Smrj 
3553446Smrj         /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
3563446Smrj 
3573446Smrj         Status = AE_OK;
3583446Smrj     }
3593446Smrj 
3603446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
3613446Smrj         "*** Completed evaluation of object %s ***\n", Info->Pathname));
3623446Smrj 
3633446Smrj     /*
3643446Smrj      * Namespace was unlocked by the handling AcpiNs* function, so we
3653446Smrj      * just return
3663446Smrj      */
3673446Smrj     return_ACPI_STATUS (Status);
3683446Smrj }
3693446Smrj 
370*11225SDana.Myers@Sun.COM 
371*11225SDana.Myers@Sun.COM /*******************************************************************************
372*11225SDana.Myers@Sun.COM  *
373*11225SDana.Myers@Sun.COM  * FUNCTION:    AcpiNsExecModuleCodeList
374*11225SDana.Myers@Sun.COM  *
375*11225SDana.Myers@Sun.COM  * PARAMETERS:  None
376*11225SDana.Myers@Sun.COM  *
377*11225SDana.Myers@Sun.COM  * RETURN:      None. Exceptions during method execution are ignored, since
378*11225SDana.Myers@Sun.COM  *              we cannot abort a table load.
379*11225SDana.Myers@Sun.COM  *
380*11225SDana.Myers@Sun.COM  * DESCRIPTION: Execute all elements of the global module-level code list.
381*11225SDana.Myers@Sun.COM  *              Each element is executed as a single control method.
382*11225SDana.Myers@Sun.COM  *
383*11225SDana.Myers@Sun.COM  ******************************************************************************/
384*11225SDana.Myers@Sun.COM 
385*11225SDana.Myers@Sun.COM void
AcpiNsExecModuleCodeList(void)386*11225SDana.Myers@Sun.COM AcpiNsExecModuleCodeList (
387*11225SDana.Myers@Sun.COM     void)
388*11225SDana.Myers@Sun.COM {
389*11225SDana.Myers@Sun.COM     ACPI_OPERAND_OBJECT     *Prev;
390*11225SDana.Myers@Sun.COM     ACPI_OPERAND_OBJECT     *Next;
391*11225SDana.Myers@Sun.COM     ACPI_EVALUATE_INFO      *Info;
392*11225SDana.Myers@Sun.COM     UINT32                  MethodCount = 0;
393*11225SDana.Myers@Sun.COM 
394*11225SDana.Myers@Sun.COM 
395*11225SDana.Myers@Sun.COM     ACPI_FUNCTION_TRACE (NsExecModuleCodeList);
396*11225SDana.Myers@Sun.COM 
397*11225SDana.Myers@Sun.COM 
398*11225SDana.Myers@Sun.COM     /* Exit now if the list is empty */
399*11225SDana.Myers@Sun.COM 
400*11225SDana.Myers@Sun.COM     Next = AcpiGbl_ModuleCodeList;
401*11225SDana.Myers@Sun.COM     if (!Next)
402*11225SDana.Myers@Sun.COM     {
403*11225SDana.Myers@Sun.COM         return_VOID;
404*11225SDana.Myers@Sun.COM     }
405*11225SDana.Myers@Sun.COM 
406*11225SDana.Myers@Sun.COM     /* Allocate the evaluation information block */
407*11225SDana.Myers@Sun.COM 
408*11225SDana.Myers@Sun.COM     Info = ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO));
409*11225SDana.Myers@Sun.COM     if (!Info)
410*11225SDana.Myers@Sun.COM     {
411*11225SDana.Myers@Sun.COM         return_VOID;
412*11225SDana.Myers@Sun.COM     }
413*11225SDana.Myers@Sun.COM 
414*11225SDana.Myers@Sun.COM     /* Walk the list, executing each "method" */
415*11225SDana.Myers@Sun.COM 
416*11225SDana.Myers@Sun.COM     while (Next)
417*11225SDana.Myers@Sun.COM     {
418*11225SDana.Myers@Sun.COM         Prev = Next;
419*11225SDana.Myers@Sun.COM         Next = Next->Method.Mutex;
420*11225SDana.Myers@Sun.COM 
421*11225SDana.Myers@Sun.COM         /* Clear the link field and execute the method */
422*11225SDana.Myers@Sun.COM 
423*11225SDana.Myers@Sun.COM         Prev->Method.Mutex = NULL;
424*11225SDana.Myers@Sun.COM         AcpiNsExecModuleCode (Prev, Info);
425*11225SDana.Myers@Sun.COM         MethodCount++;
426*11225SDana.Myers@Sun.COM 
427*11225SDana.Myers@Sun.COM         /* Delete the (temporary) method object */
428*11225SDana.Myers@Sun.COM 
429*11225SDana.Myers@Sun.COM         AcpiUtRemoveReference (Prev);
430*11225SDana.Myers@Sun.COM     }
431*11225SDana.Myers@Sun.COM 
432*11225SDana.Myers@Sun.COM     ACPI_INFO ((AE_INFO,
433*11225SDana.Myers@Sun.COM         "Executed %u blocks of module-level executable AML code",
434*11225SDana.Myers@Sun.COM         MethodCount));
435*11225SDana.Myers@Sun.COM 
436*11225SDana.Myers@Sun.COM     ACPI_FREE (Info);
437*11225SDana.Myers@Sun.COM     AcpiGbl_ModuleCodeList = NULL;
438*11225SDana.Myers@Sun.COM     return_VOID;
439*11225SDana.Myers@Sun.COM }
440*11225SDana.Myers@Sun.COM 
441*11225SDana.Myers@Sun.COM 
442*11225SDana.Myers@Sun.COM /*******************************************************************************
443*11225SDana.Myers@Sun.COM  *
444*11225SDana.Myers@Sun.COM  * FUNCTION:    AcpiNsExecModuleCode
445*11225SDana.Myers@Sun.COM  *
446*11225SDana.Myers@Sun.COM  * PARAMETERS:  MethodObj           - Object container for the module-level code
447*11225SDana.Myers@Sun.COM  *              Info                - Info block for method evaluation
448*11225SDana.Myers@Sun.COM  *
449*11225SDana.Myers@Sun.COM  * RETURN:      None. Exceptions during method execution are ignored, since
450*11225SDana.Myers@Sun.COM  *              we cannot abort a table load.
451*11225SDana.Myers@Sun.COM  *
452*11225SDana.Myers@Sun.COM  * DESCRIPTION: Execute a control method containing a block of module-level
453*11225SDana.Myers@Sun.COM  *              executable AML code. The control method is temporarily
454*11225SDana.Myers@Sun.COM  *              installed to the root node, then evaluated.
455*11225SDana.Myers@Sun.COM  *
456*11225SDana.Myers@Sun.COM  ******************************************************************************/
457*11225SDana.Myers@Sun.COM 
458*11225SDana.Myers@Sun.COM static void
AcpiNsExecModuleCode(ACPI_OPERAND_OBJECT * MethodObj,ACPI_EVALUATE_INFO * Info)459*11225SDana.Myers@Sun.COM AcpiNsExecModuleCode (
460*11225SDana.Myers@Sun.COM     ACPI_OPERAND_OBJECT     *MethodObj,
461*11225SDana.Myers@Sun.COM     ACPI_EVALUATE_INFO      *Info)
462*11225SDana.Myers@Sun.COM {
463*11225SDana.Myers@Sun.COM     ACPI_OPERAND_OBJECT     *ParentObj;
464*11225SDana.Myers@Sun.COM     ACPI_NAMESPACE_NODE     *ParentNode;
465*11225SDana.Myers@Sun.COM     ACPI_OBJECT_TYPE        Type;
466*11225SDana.Myers@Sun.COM     ACPI_STATUS             Status;
467*11225SDana.Myers@Sun.COM 
468*11225SDana.Myers@Sun.COM 
469*11225SDana.Myers@Sun.COM     ACPI_FUNCTION_TRACE (NsExecModuleCode);
470*11225SDana.Myers@Sun.COM 
471*11225SDana.Myers@Sun.COM 
472*11225SDana.Myers@Sun.COM     /*
473*11225SDana.Myers@Sun.COM      * Get the parent node. We cheat by using the NextObject field
474*11225SDana.Myers@Sun.COM      * of the method object descriptor.
475*11225SDana.Myers@Sun.COM      */
476*11225SDana.Myers@Sun.COM     ParentNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
477*11225SDana.Myers@Sun.COM                     MethodObj->Method.NextObject);
478*11225SDana.Myers@Sun.COM     Type = AcpiNsGetType (ParentNode);
479*11225SDana.Myers@Sun.COM 
480*11225SDana.Myers@Sun.COM     /* Must clear NextObject (AcpiNsAttachObject needs the field) */
481*11225SDana.Myers@Sun.COM 
482*11225SDana.Myers@Sun.COM     MethodObj->Method.NextObject = NULL;
483*11225SDana.Myers@Sun.COM 
484*11225SDana.Myers@Sun.COM     /* Initialize the evaluation information block */
485*11225SDana.Myers@Sun.COM 
486*11225SDana.Myers@Sun.COM     ACPI_MEMSET (Info, 0, sizeof (ACPI_EVALUATE_INFO));
487*11225SDana.Myers@Sun.COM     Info->PrefixNode = ParentNode;
488*11225SDana.Myers@Sun.COM 
489*11225SDana.Myers@Sun.COM     /*
490*11225SDana.Myers@Sun.COM      * Get the currently attached parent object. Add a reference, because the
491*11225SDana.Myers@Sun.COM      * ref count will be decreased when the method object is installed to
492*11225SDana.Myers@Sun.COM      * the parent node.
493*11225SDana.Myers@Sun.COM      */
494*11225SDana.Myers@Sun.COM     ParentObj = AcpiNsGetAttachedObject (ParentNode);
495*11225SDana.Myers@Sun.COM     if (ParentObj)
496*11225SDana.Myers@Sun.COM     {
497*11225SDana.Myers@Sun.COM         AcpiUtAddReference (ParentObj);
498*11225SDana.Myers@Sun.COM     }
499*11225SDana.Myers@Sun.COM 
500*11225SDana.Myers@Sun.COM     /* Install the method (module-level code) in the parent node */
501*11225SDana.Myers@Sun.COM 
502*11225SDana.Myers@Sun.COM     Status = AcpiNsAttachObject (ParentNode, MethodObj,
503*11225SDana.Myers@Sun.COM                 ACPI_TYPE_METHOD);
504*11225SDana.Myers@Sun.COM     if (ACPI_FAILURE (Status))
505*11225SDana.Myers@Sun.COM     {
506*11225SDana.Myers@Sun.COM         goto Exit;
507*11225SDana.Myers@Sun.COM     }
508*11225SDana.Myers@Sun.COM 
509*11225SDana.Myers@Sun.COM     /* Execute the parent node as a control method */
510*11225SDana.Myers@Sun.COM 
511*11225SDana.Myers@Sun.COM     Status = AcpiNsEvaluate (Info);
512*11225SDana.Myers@Sun.COM 
513*11225SDana.Myers@Sun.COM     ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Executed module-level code at %p\n",
514*11225SDana.Myers@Sun.COM         MethodObj->Method.AmlStart));
515*11225SDana.Myers@Sun.COM 
516*11225SDana.Myers@Sun.COM     /* Delete a possible implicit return value (in slack mode) */
517*11225SDana.Myers@Sun.COM 
518*11225SDana.Myers@Sun.COM     if (Info->ReturnObject)
519*11225SDana.Myers@Sun.COM     {
520*11225SDana.Myers@Sun.COM 	AcpiUtRemoveReference (Info->ReturnObject);
521*11225SDana.Myers@Sun.COM     }
522*11225SDana.Myers@Sun.COM 
523*11225SDana.Myers@Sun.COM     /* Detach the temporary method object */
524*11225SDana.Myers@Sun.COM 
525*11225SDana.Myers@Sun.COM     AcpiNsDetachObject (ParentNode);
526*11225SDana.Myers@Sun.COM 
527*11225SDana.Myers@Sun.COM     /* Restore the original parent object */
528*11225SDana.Myers@Sun.COM 
529*11225SDana.Myers@Sun.COM     if (ParentObj)
530*11225SDana.Myers@Sun.COM     {
531*11225SDana.Myers@Sun.COM         Status = AcpiNsAttachObject (ParentNode, ParentObj, Type);
532*11225SDana.Myers@Sun.COM     }
533*11225SDana.Myers@Sun.COM     else
534*11225SDana.Myers@Sun.COM     {
535*11225SDana.Myers@Sun.COM         ParentNode->Type = (UINT8) Type;
536*11225SDana.Myers@Sun.COM     }
537*11225SDana.Myers@Sun.COM 
538*11225SDana.Myers@Sun.COM Exit:
539*11225SDana.Myers@Sun.COM     if (ParentObj)
540*11225SDana.Myers@Sun.COM     {
541*11225SDana.Myers@Sun.COM         AcpiUtRemoveReference (ParentObj);
542*11225SDana.Myers@Sun.COM     }
543*11225SDana.Myers@Sun.COM     return_VOID;
544*11225SDana.Myers@Sun.COM }
545*11225SDana.Myers@Sun.COM 
546