xref: /minix3/minix/drivers/power/acpi/namespace/nseval.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: nseval - Object evaluation, includes control method execution
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  ******************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acparser.h"
47433d6423SLionel Sambuc #include "acinterp.h"
48433d6423SLionel Sambuc #include "acnamesp.h"
49433d6423SLionel Sambuc 
50433d6423SLionel Sambuc 
51433d6423SLionel Sambuc #define _COMPONENT          ACPI_NAMESPACE
52433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("nseval")
53433d6423SLionel Sambuc 
54433d6423SLionel Sambuc /* Local prototypes */
55433d6423SLionel Sambuc 
56433d6423SLionel Sambuc static void
57433d6423SLionel Sambuc AcpiNsExecModuleCode (
58433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *MethodObj,
59433d6423SLionel Sambuc     ACPI_EVALUATE_INFO      *Info);
60433d6423SLionel Sambuc 
61433d6423SLionel Sambuc 
62433d6423SLionel Sambuc /*******************************************************************************
63433d6423SLionel Sambuc  *
64433d6423SLionel Sambuc  * FUNCTION:    AcpiNsEvaluate
65433d6423SLionel Sambuc  *
66433d6423SLionel Sambuc  * PARAMETERS:  Info            - Evaluation info block, contains:
67433d6423SLionel Sambuc  *                  PrefixNode      - Prefix or Method/Object Node to execute
68*29492bb7SDavid van Moolenbroek  *                  RelativePath    - Name of method to execute, If NULL, the
69433d6423SLionel Sambuc  *                                    Node is the object to execute
70433d6423SLionel Sambuc  *                  Parameters      - List of parameters to pass to the method,
71433d6423SLionel Sambuc  *                                    terminated by NULL. Params itself may be
72433d6423SLionel Sambuc  *                                    NULL if no parameters are being passed.
73433d6423SLionel Sambuc  *                  ReturnObject    - Where to put method's return value (if
74433d6423SLionel Sambuc  *                                    any). If NULL, no value is returned.
75433d6423SLionel Sambuc  *                  ParameterType   - Type of Parameter list
76433d6423SLionel Sambuc  *                  ReturnObject    - Where to put method's return value (if
77433d6423SLionel Sambuc  *                                    any). If NULL, no value is returned.
78433d6423SLionel Sambuc  *                  Flags           - ACPI_IGNORE_RETURN_VALUE to delete return
79433d6423SLionel Sambuc  *
80433d6423SLionel Sambuc  * RETURN:      Status
81433d6423SLionel Sambuc  *
82433d6423SLionel Sambuc  * DESCRIPTION: Execute a control method or return the current value of an
83433d6423SLionel Sambuc  *              ACPI namespace object.
84433d6423SLionel Sambuc  *
85433d6423SLionel Sambuc  * MUTEX:       Locks interpreter
86433d6423SLionel Sambuc  *
87433d6423SLionel Sambuc  ******************************************************************************/
88433d6423SLionel Sambuc 
89433d6423SLionel Sambuc ACPI_STATUS
AcpiNsEvaluate(ACPI_EVALUATE_INFO * Info)90433d6423SLionel Sambuc AcpiNsEvaluate (
91433d6423SLionel Sambuc     ACPI_EVALUATE_INFO      *Info)
92433d6423SLionel Sambuc {
93433d6423SLionel Sambuc     ACPI_STATUS             Status;
94433d6423SLionel Sambuc 
95433d6423SLionel Sambuc 
96433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsEvaluate);
97433d6423SLionel Sambuc 
98433d6423SLionel Sambuc 
99433d6423SLionel Sambuc     if (!Info)
100433d6423SLionel Sambuc     {
101433d6423SLionel Sambuc         return_ACPI_STATUS (AE_BAD_PARAMETER);
102433d6423SLionel Sambuc     }
103433d6423SLionel Sambuc 
104*29492bb7SDavid van Moolenbroek     if (!Info->Node)
105*29492bb7SDavid van Moolenbroek     {
106433d6423SLionel Sambuc         /*
107*29492bb7SDavid van Moolenbroek          * Get the actual namespace node for the target object if we
108*29492bb7SDavid van Moolenbroek          * need to. Handles these cases:
109433d6423SLionel Sambuc          *
110*29492bb7SDavid van Moolenbroek          * 1) Null node, valid pathname from root (absolute path)
111*29492bb7SDavid van Moolenbroek          * 2) Node and valid pathname (path relative to Node)
112*29492bb7SDavid van Moolenbroek          * 3) Node, Null pathname
113433d6423SLionel Sambuc          */
114*29492bb7SDavid van Moolenbroek         Status = AcpiNsGetNode (Info->PrefixNode, Info->RelativePathname,
115*29492bb7SDavid van Moolenbroek             ACPI_NS_NO_UPSEARCH, &Info->Node);
116433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
117433d6423SLionel Sambuc         {
118433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
119433d6423SLionel Sambuc         }
120433d6423SLionel Sambuc     }
121433d6423SLionel Sambuc 
122433d6423SLionel Sambuc     /*
123*29492bb7SDavid van Moolenbroek      * For a method alias, we must grab the actual method node so that
124*29492bb7SDavid van Moolenbroek      * proper scoping context will be established before execution.
125433d6423SLionel Sambuc      */
126*29492bb7SDavid van Moolenbroek     if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
127433d6423SLionel Sambuc     {
128*29492bb7SDavid van Moolenbroek         Info->Node = ACPI_CAST_PTR (
129*29492bb7SDavid van Moolenbroek             ACPI_NAMESPACE_NODE, Info->Node->Object);
130433d6423SLionel Sambuc     }
131433d6423SLionel Sambuc 
132*29492bb7SDavid van Moolenbroek     /* Complete the info block initialization */
133433d6423SLionel Sambuc 
134*29492bb7SDavid van Moolenbroek     Info->ReturnObject = NULL;
135*29492bb7SDavid van Moolenbroek     Info->NodeFlags = Info->Node->Flags;
136*29492bb7SDavid van Moolenbroek     Info->ObjDesc = AcpiNsGetAttachedObject (Info->Node);
137*29492bb7SDavid van Moolenbroek 
138*29492bb7SDavid van Moolenbroek     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
139*29492bb7SDavid van Moolenbroek         Info->RelativePathname, Info->Node,
140*29492bb7SDavid van Moolenbroek         AcpiNsGetAttachedObject (Info->Node)));
141*29492bb7SDavid van Moolenbroek 
142*29492bb7SDavid van Moolenbroek     /* Get info if we have a predefined name (_HID, etc.) */
143*29492bb7SDavid van Moolenbroek 
144*29492bb7SDavid van Moolenbroek     Info->Predefined = AcpiUtMatchPredefinedMethod (Info->Node->Name.Ascii);
145*29492bb7SDavid van Moolenbroek 
146*29492bb7SDavid van Moolenbroek     /* Get the full pathname to the object, for use in warning messages */
147*29492bb7SDavid van Moolenbroek 
148*29492bb7SDavid van Moolenbroek     Info->FullPathname = AcpiNsGetExternalPathname (Info->Node);
149*29492bb7SDavid van Moolenbroek     if (!Info->FullPathname)
150*29492bb7SDavid van Moolenbroek     {
151*29492bb7SDavid van Moolenbroek         return_ACPI_STATUS (AE_NO_MEMORY);
152*29492bb7SDavid van Moolenbroek     }
153*29492bb7SDavid van Moolenbroek 
154*29492bb7SDavid van Moolenbroek     /* Count the number of arguments being passed in */
155*29492bb7SDavid van Moolenbroek 
156*29492bb7SDavid van Moolenbroek     Info->ParamCount = 0;
157433d6423SLionel Sambuc     if (Info->Parameters)
158433d6423SLionel Sambuc     {
159433d6423SLionel Sambuc         while (Info->Parameters[Info->ParamCount])
160433d6423SLionel Sambuc         {
161433d6423SLionel Sambuc             Info->ParamCount++;
162433d6423SLionel Sambuc         }
163*29492bb7SDavid van Moolenbroek 
164*29492bb7SDavid van Moolenbroek         /* Warn on impossible argument count */
165*29492bb7SDavid van Moolenbroek 
166*29492bb7SDavid van Moolenbroek         if (Info->ParamCount > ACPI_METHOD_NUM_ARGS)
167*29492bb7SDavid van Moolenbroek         {
168*29492bb7SDavid van Moolenbroek             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,
169*29492bb7SDavid van Moolenbroek                 "Excess arguments (%u) - using only %u",
170*29492bb7SDavid van Moolenbroek                 Info->ParamCount, ACPI_METHOD_NUM_ARGS));
171*29492bb7SDavid van Moolenbroek 
172*29492bb7SDavid van Moolenbroek             Info->ParamCount = ACPI_METHOD_NUM_ARGS;
173*29492bb7SDavid van Moolenbroek         }
174433d6423SLionel Sambuc     }
175433d6423SLionel Sambuc 
176*29492bb7SDavid van Moolenbroek     /*
177*29492bb7SDavid van Moolenbroek      * For predefined names: Check that the declared argument count
178*29492bb7SDavid van Moolenbroek      * matches the ACPI spec -- otherwise this is a BIOS error.
179*29492bb7SDavid van Moolenbroek      */
180*29492bb7SDavid van Moolenbroek     AcpiNsCheckAcpiCompliance (Info->FullPathname, Info->Node,
181*29492bb7SDavid van Moolenbroek         Info->Predefined);
182*29492bb7SDavid van Moolenbroek 
183*29492bb7SDavid van Moolenbroek     /*
184*29492bb7SDavid van Moolenbroek      * For all names: Check that the incoming argument count for
185*29492bb7SDavid van Moolenbroek      * this method/object matches the actual ASL/AML definition.
186*29492bb7SDavid van Moolenbroek      */
187*29492bb7SDavid van Moolenbroek     AcpiNsCheckArgumentCount (Info->FullPathname, Info->Node,
188*29492bb7SDavid van Moolenbroek         Info->ParamCount, Info->Predefined);
189*29492bb7SDavid van Moolenbroek 
190*29492bb7SDavid van Moolenbroek     /* For predefined names: Typecheck all incoming arguments */
191*29492bb7SDavid van Moolenbroek 
192*29492bb7SDavid van Moolenbroek     AcpiNsCheckArgumentTypes (Info);
193*29492bb7SDavid van Moolenbroek 
194*29492bb7SDavid van Moolenbroek     /*
195*29492bb7SDavid van Moolenbroek      * Three major evaluation cases:
196*29492bb7SDavid van Moolenbroek      *
197*29492bb7SDavid van Moolenbroek      * 1) Object types that cannot be evaluated by definition
198*29492bb7SDavid van Moolenbroek      * 2) The object is a control method -- execute it
199*29492bb7SDavid van Moolenbroek      * 3) The object is not a method -- just return it's current value
200*29492bb7SDavid van Moolenbroek      */
201*29492bb7SDavid van Moolenbroek     switch (AcpiNsGetType (Info->Node))
202*29492bb7SDavid van Moolenbroek     {
203*29492bb7SDavid van Moolenbroek     case ACPI_TYPE_DEVICE:
204*29492bb7SDavid van Moolenbroek     case ACPI_TYPE_EVENT:
205*29492bb7SDavid van Moolenbroek     case ACPI_TYPE_MUTEX:
206*29492bb7SDavid van Moolenbroek     case ACPI_TYPE_REGION:
207*29492bb7SDavid van Moolenbroek     case ACPI_TYPE_THERMAL:
208*29492bb7SDavid van Moolenbroek     case ACPI_TYPE_LOCAL_SCOPE:
209*29492bb7SDavid van Moolenbroek         /*
210*29492bb7SDavid van Moolenbroek          * 1) Disallow evaluation of certain object types. For these,
211*29492bb7SDavid van Moolenbroek          *    object evaluation is undefined and not supported.
212*29492bb7SDavid van Moolenbroek          */
213*29492bb7SDavid van Moolenbroek         ACPI_ERROR ((AE_INFO,
214*29492bb7SDavid van Moolenbroek             "%s: Evaluation of object type [%s] is not supported",
215*29492bb7SDavid van Moolenbroek             Info->FullPathname,
216*29492bb7SDavid van Moolenbroek             AcpiUtGetTypeName (Info->Node->Type)));
217*29492bb7SDavid van Moolenbroek 
218*29492bb7SDavid van Moolenbroek         Status = AE_TYPE;
219*29492bb7SDavid van Moolenbroek         goto Cleanup;
220*29492bb7SDavid van Moolenbroek 
221*29492bb7SDavid van Moolenbroek     case ACPI_TYPE_METHOD:
222*29492bb7SDavid van Moolenbroek         /*
223*29492bb7SDavid van Moolenbroek          * 2) Object is a control method - execute it
224*29492bb7SDavid van Moolenbroek          */
225*29492bb7SDavid van Moolenbroek 
226*29492bb7SDavid van Moolenbroek         /* Verify that there is a method object associated with this node */
227*29492bb7SDavid van Moolenbroek 
228*29492bb7SDavid van Moolenbroek         if (!Info->ObjDesc)
229*29492bb7SDavid van Moolenbroek         {
230*29492bb7SDavid van Moolenbroek             ACPI_ERROR ((AE_INFO, "%s: Method has no attached sub-object",
231*29492bb7SDavid van Moolenbroek                 Info->FullPathname));
232*29492bb7SDavid van Moolenbroek             Status = AE_NULL_OBJECT;
233*29492bb7SDavid van Moolenbroek             goto Cleanup;
234*29492bb7SDavid van Moolenbroek         }
235433d6423SLionel Sambuc 
236433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
237*29492bb7SDavid van Moolenbroek             "**** Execute method [%s] at AML address %p length %X\n",
238*29492bb7SDavid van Moolenbroek             Info->FullPathname,
239433d6423SLionel Sambuc             Info->ObjDesc->Method.AmlStart + 1,
240433d6423SLionel Sambuc             Info->ObjDesc->Method.AmlLength - 1));
241433d6423SLionel Sambuc 
242433d6423SLionel Sambuc         /*
243433d6423SLionel Sambuc          * Any namespace deletion must acquire both the namespace and
244433d6423SLionel Sambuc          * interpreter locks to ensure that no thread is using the portion of
245433d6423SLionel Sambuc          * the namespace that is being deleted.
246433d6423SLionel Sambuc          *
247433d6423SLionel Sambuc          * Execute the method via the interpreter. The interpreter is locked
248433d6423SLionel Sambuc          * here before calling into the AML parser
249433d6423SLionel Sambuc          */
250433d6423SLionel Sambuc         AcpiExEnterInterpreter ();
251433d6423SLionel Sambuc         Status = AcpiPsExecuteMethod (Info);
252433d6423SLionel Sambuc         AcpiExExitInterpreter ();
253*29492bb7SDavid van Moolenbroek         break;
254433d6423SLionel Sambuc 
255433d6423SLionel Sambuc     default:
256*29492bb7SDavid van Moolenbroek         /*
257*29492bb7SDavid van Moolenbroek          * 3) All other non-method objects -- get the current object value
258*29492bb7SDavid van Moolenbroek          */
259433d6423SLionel Sambuc 
260433d6423SLionel Sambuc         /*
261*29492bb7SDavid van Moolenbroek          * Some objects require additional resolution steps (e.g., the Node
262*29492bb7SDavid van Moolenbroek          * may be a field that must be read, etc.) -- we can't just grab
263*29492bb7SDavid van Moolenbroek          * the object out of the node.
264433d6423SLionel Sambuc          *
265433d6423SLionel Sambuc          * Use ResolveNodeToValue() to get the associated value.
266433d6423SLionel Sambuc          *
267433d6423SLionel Sambuc          * NOTE: we can get away with passing in NULL for a walk state because
268*29492bb7SDavid van Moolenbroek          * the Node is guaranteed to not be a reference to either a method
269433d6423SLionel Sambuc          * local or a method argument (because this interface is never called
270433d6423SLionel Sambuc          * from a running method.)
271433d6423SLionel Sambuc          *
272433d6423SLionel Sambuc          * Even though we do not directly invoke the interpreter for object
273*29492bb7SDavid van Moolenbroek          * resolution, we must lock it because we could access an OpRegion.
274*29492bb7SDavid van Moolenbroek          * The OpRegion access code assumes that the interpreter is locked.
275433d6423SLionel Sambuc          */
276433d6423SLionel Sambuc         AcpiExEnterInterpreter ();
277433d6423SLionel Sambuc 
278*29492bb7SDavid van Moolenbroek         /* TBD: ResolveNodeToValue has a strange interface, fix */
279433d6423SLionel Sambuc 
280*29492bb7SDavid van Moolenbroek         Info->ReturnObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->Node);
281*29492bb7SDavid van Moolenbroek 
282*29492bb7SDavid van Moolenbroek         Status = AcpiExResolveNodeToValue (ACPI_CAST_INDIRECT_PTR (
283*29492bb7SDavid van Moolenbroek             ACPI_NAMESPACE_NODE, &Info->ReturnObject), NULL);
284433d6423SLionel Sambuc         AcpiExExitInterpreter ();
285433d6423SLionel Sambuc 
286*29492bb7SDavid van Moolenbroek         if (ACPI_FAILURE (Status))
287433d6423SLionel Sambuc         {
288*29492bb7SDavid van Moolenbroek             goto Cleanup;
289*29492bb7SDavid van Moolenbroek         }
290433d6423SLionel Sambuc 
291*29492bb7SDavid van Moolenbroek         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returned object %p [%s]\n",
292433d6423SLionel Sambuc             Info->ReturnObject,
293433d6423SLionel Sambuc             AcpiUtGetObjectTypeName (Info->ReturnObject)));
294*29492bb7SDavid van Moolenbroek 
295*29492bb7SDavid van Moolenbroek         Status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */
296*29492bb7SDavid van Moolenbroek         break;
297433d6423SLionel Sambuc     }
298433d6423SLionel Sambuc 
299433d6423SLionel Sambuc     /*
300*29492bb7SDavid van Moolenbroek      * For predefined names, check the return value against the ACPI
301*29492bb7SDavid van Moolenbroek      * specification. Some incorrect return value types are repaired.
302433d6423SLionel Sambuc      */
303*29492bb7SDavid van Moolenbroek     (void) AcpiNsCheckReturnValue (Info->Node, Info, Info->ParamCount,
304433d6423SLionel Sambuc         Status, &Info->ReturnObject);
305433d6423SLionel Sambuc 
306433d6423SLionel Sambuc     /* Check if there is a return value that must be dealt with */
307433d6423SLionel Sambuc 
308433d6423SLionel Sambuc     if (Status == AE_CTRL_RETURN_VALUE)
309433d6423SLionel Sambuc     {
310433d6423SLionel Sambuc         /* If caller does not want the return value, delete it */
311433d6423SLionel Sambuc 
312433d6423SLionel Sambuc         if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
313433d6423SLionel Sambuc         {
314433d6423SLionel Sambuc             AcpiUtRemoveReference (Info->ReturnObject);
315433d6423SLionel Sambuc             Info->ReturnObject = NULL;
316433d6423SLionel Sambuc         }
317433d6423SLionel Sambuc 
318433d6423SLionel Sambuc         /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
319433d6423SLionel Sambuc 
320433d6423SLionel Sambuc         Status = AE_OK;
321433d6423SLionel Sambuc     }
322433d6423SLionel Sambuc 
323433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
324*29492bb7SDavid van Moolenbroek         "*** Completed evaluation of object %s ***\n",
325*29492bb7SDavid van Moolenbroek         Info->RelativePathname));
326433d6423SLionel Sambuc 
327*29492bb7SDavid van Moolenbroek Cleanup:
328433d6423SLionel Sambuc     /*
329433d6423SLionel Sambuc      * Namespace was unlocked by the handling AcpiNs* function, so we
330*29492bb7SDavid van Moolenbroek      * just free the pathname and return
331433d6423SLionel Sambuc      */
332*29492bb7SDavid van Moolenbroek     ACPI_FREE (Info->FullPathname);
333*29492bb7SDavid van Moolenbroek     Info->FullPathname = NULL;
334433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
335433d6423SLionel Sambuc }
336433d6423SLionel Sambuc 
337433d6423SLionel Sambuc 
338433d6423SLionel Sambuc /*******************************************************************************
339433d6423SLionel Sambuc  *
340433d6423SLionel Sambuc  * FUNCTION:    AcpiNsExecModuleCodeList
341433d6423SLionel Sambuc  *
342433d6423SLionel Sambuc  * PARAMETERS:  None
343433d6423SLionel Sambuc  *
344433d6423SLionel Sambuc  * RETURN:      None. Exceptions during method execution are ignored, since
345433d6423SLionel Sambuc  *              we cannot abort a table load.
346433d6423SLionel Sambuc  *
347433d6423SLionel Sambuc  * DESCRIPTION: Execute all elements of the global module-level code list.
348433d6423SLionel Sambuc  *              Each element is executed as a single control method.
349433d6423SLionel Sambuc  *
350433d6423SLionel Sambuc  ******************************************************************************/
351433d6423SLionel Sambuc 
352433d6423SLionel Sambuc void
AcpiNsExecModuleCodeList(void)353433d6423SLionel Sambuc AcpiNsExecModuleCodeList (
354433d6423SLionel Sambuc     void)
355433d6423SLionel Sambuc {
356433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Prev;
357433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Next;
358433d6423SLionel Sambuc     ACPI_EVALUATE_INFO      *Info;
359433d6423SLionel Sambuc     UINT32                  MethodCount = 0;
360433d6423SLionel Sambuc 
361433d6423SLionel Sambuc 
362433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsExecModuleCodeList);
363433d6423SLionel Sambuc 
364433d6423SLionel Sambuc 
365433d6423SLionel Sambuc     /* Exit now if the list is empty */
366433d6423SLionel Sambuc 
367433d6423SLionel Sambuc     Next = AcpiGbl_ModuleCodeList;
368433d6423SLionel Sambuc     if (!Next)
369433d6423SLionel Sambuc     {
370433d6423SLionel Sambuc         return_VOID;
371433d6423SLionel Sambuc     }
372433d6423SLionel Sambuc 
373433d6423SLionel Sambuc     /* Allocate the evaluation information block */
374433d6423SLionel Sambuc 
375433d6423SLionel Sambuc     Info = ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO));
376433d6423SLionel Sambuc     if (!Info)
377433d6423SLionel Sambuc     {
378433d6423SLionel Sambuc         return_VOID;
379433d6423SLionel Sambuc     }
380433d6423SLionel Sambuc 
381433d6423SLionel Sambuc     /* Walk the list, executing each "method" */
382433d6423SLionel Sambuc 
383433d6423SLionel Sambuc     while (Next)
384433d6423SLionel Sambuc     {
385433d6423SLionel Sambuc         Prev = Next;
386433d6423SLionel Sambuc         Next = Next->Method.Mutex;
387433d6423SLionel Sambuc 
388433d6423SLionel Sambuc         /* Clear the link field and execute the method */
389433d6423SLionel Sambuc 
390433d6423SLionel Sambuc         Prev->Method.Mutex = NULL;
391433d6423SLionel Sambuc         AcpiNsExecModuleCode (Prev, Info);
392433d6423SLionel Sambuc         MethodCount++;
393433d6423SLionel Sambuc 
394433d6423SLionel Sambuc         /* Delete the (temporary) method object */
395433d6423SLionel Sambuc 
396433d6423SLionel Sambuc         AcpiUtRemoveReference (Prev);
397433d6423SLionel Sambuc     }
398433d6423SLionel Sambuc 
399433d6423SLionel Sambuc     ACPI_INFO ((AE_INFO,
400433d6423SLionel Sambuc         "Executed %u blocks of module-level executable AML code",
401433d6423SLionel Sambuc         MethodCount));
402433d6423SLionel Sambuc 
403433d6423SLionel Sambuc     ACPI_FREE (Info);
404433d6423SLionel Sambuc     AcpiGbl_ModuleCodeList = NULL;
405433d6423SLionel Sambuc     return_VOID;
406433d6423SLionel Sambuc }
407433d6423SLionel Sambuc 
408433d6423SLionel Sambuc 
409433d6423SLionel Sambuc /*******************************************************************************
410433d6423SLionel Sambuc  *
411433d6423SLionel Sambuc  * FUNCTION:    AcpiNsExecModuleCode
412433d6423SLionel Sambuc  *
413433d6423SLionel Sambuc  * PARAMETERS:  MethodObj           - Object container for the module-level code
414433d6423SLionel Sambuc  *              Info                - Info block for method evaluation
415433d6423SLionel Sambuc  *
416433d6423SLionel Sambuc  * RETURN:      None. Exceptions during method execution are ignored, since
417433d6423SLionel Sambuc  *              we cannot abort a table load.
418433d6423SLionel Sambuc  *
419433d6423SLionel Sambuc  * DESCRIPTION: Execute a control method containing a block of module-level
420433d6423SLionel Sambuc  *              executable AML code. The control method is temporarily
421433d6423SLionel Sambuc  *              installed to the root node, then evaluated.
422433d6423SLionel Sambuc  *
423433d6423SLionel Sambuc  ******************************************************************************/
424433d6423SLionel Sambuc 
425433d6423SLionel Sambuc static void
AcpiNsExecModuleCode(ACPI_OPERAND_OBJECT * MethodObj,ACPI_EVALUATE_INFO * Info)426433d6423SLionel Sambuc AcpiNsExecModuleCode (
427433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *MethodObj,
428433d6423SLionel Sambuc     ACPI_EVALUATE_INFO      *Info)
429433d6423SLionel Sambuc {
430433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ParentObj;
431433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *ParentNode;
432433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type;
433433d6423SLionel Sambuc     ACPI_STATUS             Status;
434433d6423SLionel Sambuc 
435433d6423SLionel Sambuc 
436433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsExecModuleCode);
437433d6423SLionel Sambuc 
438433d6423SLionel Sambuc 
439433d6423SLionel Sambuc     /*
440433d6423SLionel Sambuc      * Get the parent node. We cheat by using the NextObject field
441433d6423SLionel Sambuc      * of the method object descriptor.
442433d6423SLionel Sambuc      */
443433d6423SLionel Sambuc     ParentNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
444433d6423SLionel Sambuc                     MethodObj->Method.NextObject);
445433d6423SLionel Sambuc     Type = AcpiNsGetType (ParentNode);
446433d6423SLionel Sambuc 
447433d6423SLionel Sambuc     /*
448433d6423SLionel Sambuc      * Get the region handler and save it in the method object. We may need
449433d6423SLionel Sambuc      * this if an operation region declaration causes a _REG method to be run.
450433d6423SLionel Sambuc      *
451433d6423SLionel Sambuc      * We can't do this in AcpiPsLinkModuleCode because
452433d6423SLionel Sambuc      * AcpiGbl_RootNode->Object is NULL at PASS1.
453433d6423SLionel Sambuc      */
454433d6423SLionel Sambuc     if ((Type == ACPI_TYPE_DEVICE) && ParentNode->Object)
455433d6423SLionel Sambuc     {
456*29492bb7SDavid van Moolenbroek         MethodObj->Method.Dispatch.Handler =
457433d6423SLionel Sambuc             ParentNode->Object->Device.Handler;
458433d6423SLionel Sambuc     }
459433d6423SLionel Sambuc 
460433d6423SLionel Sambuc     /* Must clear NextObject (AcpiNsAttachObject needs the field) */
461433d6423SLionel Sambuc 
462433d6423SLionel Sambuc     MethodObj->Method.NextObject = NULL;
463433d6423SLionel Sambuc 
464433d6423SLionel Sambuc     /* Initialize the evaluation information block */
465433d6423SLionel Sambuc 
466433d6423SLionel Sambuc     ACPI_MEMSET (Info, 0, sizeof (ACPI_EVALUATE_INFO));
467433d6423SLionel Sambuc     Info->PrefixNode = ParentNode;
468433d6423SLionel Sambuc 
469433d6423SLionel Sambuc     /*
470433d6423SLionel Sambuc      * Get the currently attached parent object. Add a reference, because the
471433d6423SLionel Sambuc      * ref count will be decreased when the method object is installed to
472433d6423SLionel Sambuc      * the parent node.
473433d6423SLionel Sambuc      */
474433d6423SLionel Sambuc     ParentObj = AcpiNsGetAttachedObject (ParentNode);
475433d6423SLionel Sambuc     if (ParentObj)
476433d6423SLionel Sambuc     {
477433d6423SLionel Sambuc         AcpiUtAddReference (ParentObj);
478433d6423SLionel Sambuc     }
479433d6423SLionel Sambuc 
480433d6423SLionel Sambuc     /* Install the method (module-level code) in the parent node */
481433d6423SLionel Sambuc 
482433d6423SLionel Sambuc     Status = AcpiNsAttachObject (ParentNode, MethodObj,
483433d6423SLionel Sambuc                 ACPI_TYPE_METHOD);
484433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
485433d6423SLionel Sambuc     {
486433d6423SLionel Sambuc         goto Exit;
487433d6423SLionel Sambuc     }
488433d6423SLionel Sambuc 
489433d6423SLionel Sambuc     /* Execute the parent node as a control method */
490433d6423SLionel Sambuc 
491433d6423SLionel Sambuc     Status = AcpiNsEvaluate (Info);
492433d6423SLionel Sambuc 
493433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Executed module-level code at %p\n",
494433d6423SLionel Sambuc         MethodObj->Method.AmlStart));
495433d6423SLionel Sambuc 
496433d6423SLionel Sambuc     /* Delete a possible implicit return value (in slack mode) */
497433d6423SLionel Sambuc 
498433d6423SLionel Sambuc     if (Info->ReturnObject)
499433d6423SLionel Sambuc     {
500433d6423SLionel Sambuc         AcpiUtRemoveReference (Info->ReturnObject);
501433d6423SLionel Sambuc     }
502433d6423SLionel Sambuc 
503433d6423SLionel Sambuc     /* Detach the temporary method object */
504433d6423SLionel Sambuc 
505433d6423SLionel Sambuc     AcpiNsDetachObject (ParentNode);
506433d6423SLionel Sambuc 
507433d6423SLionel Sambuc     /* Restore the original parent object */
508433d6423SLionel Sambuc 
509433d6423SLionel Sambuc     if (ParentObj)
510433d6423SLionel Sambuc     {
511433d6423SLionel Sambuc         Status = AcpiNsAttachObject (ParentNode, ParentObj, Type);
512433d6423SLionel Sambuc     }
513433d6423SLionel Sambuc     else
514433d6423SLionel Sambuc     {
515433d6423SLionel Sambuc         ParentNode->Type = (UINT8) Type;
516433d6423SLionel Sambuc     }
517433d6423SLionel Sambuc 
518433d6423SLionel Sambuc Exit:
519433d6423SLionel Sambuc     if (ParentObj)
520433d6423SLionel Sambuc     {
521433d6423SLionel Sambuc         AcpiUtRemoveReference (ParentObj);
522433d6423SLionel Sambuc     }
523433d6423SLionel Sambuc     return_VOID;
524433d6423SLionel Sambuc }
525