1ae115bc7Smrj /*******************************************************************************
2ae115bc7Smrj *
3ae115bc7Smrj * Module Name: nseval - Object evaluation, includes control method execution
4ae115bc7Smrj *
5ae115bc7Smrj ******************************************************************************/
6ae115bc7Smrj
726f3cdf0SGordon Ross /*
8*cb565728SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj * All rights reserved.
10ae115bc7Smrj *
1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross * are met:
1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross * without modification.
1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross * binary redistribution.
2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross * from this software without specific prior written permission.
25ae115bc7Smrj *
2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross * Software Foundation.
29ae115bc7Smrj *
3026f3cdf0SGordon Ross * NO WARRANTY
3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross */
43ae115bc7Smrj
44ae115bc7Smrj #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46ae115bc7Smrj #include "acparser.h"
47ae115bc7Smrj #include "acinterp.h"
48ae115bc7Smrj #include "acnamesp.h"
49ae115bc7Smrj
50ae115bc7Smrj
51ae115bc7Smrj #define _COMPONENT ACPI_NAMESPACE
52ae115bc7Smrj ACPI_MODULE_NAME ("nseval")
53ae115bc7Smrj
5457190917SDana Myers /* Local prototypes */
5557190917SDana Myers
5657190917SDana Myers static void
5757190917SDana Myers AcpiNsExecModuleCode (
5857190917SDana Myers ACPI_OPERAND_OBJECT *MethodObj,
5957190917SDana Myers ACPI_EVALUATE_INFO *Info);
6057190917SDana Myers
61ae115bc7Smrj
62ae115bc7Smrj /*******************************************************************************
63ae115bc7Smrj *
64ae115bc7Smrj * FUNCTION: AcpiNsEvaluate
65ae115bc7Smrj *
66*cb565728SJerry Jelinek * PARAMETERS: Info - Evaluation info block, contains these fields
67*cb565728SJerry Jelinek * and more:
68ae115bc7Smrj * PrefixNode - Prefix or Method/Object Node to execute
69*cb565728SJerry Jelinek * RelativePath - Name of method to execute, If NULL, the
70ae115bc7Smrj * Node is the object to execute
71ae115bc7Smrj * Parameters - List of parameters to pass to the method,
72ae115bc7Smrj * terminated by NULL. Params itself may be
73ae115bc7Smrj * NULL if no parameters are being passed.
74ae115bc7Smrj * ParameterType - Type of Parameter list
75ae115bc7Smrj * ReturnObject - Where to put method's return value (if
76ae115bc7Smrj * any). If NULL, no value is returned.
77ae115bc7Smrj * Flags - ACPI_IGNORE_RETURN_VALUE to delete return
78ae115bc7Smrj *
79ae115bc7Smrj * RETURN: Status
80ae115bc7Smrj *
81ae115bc7Smrj * DESCRIPTION: Execute a control method or return the current value of an
82ae115bc7Smrj * ACPI namespace object.
83ae115bc7Smrj *
84ae115bc7Smrj * MUTEX: Locks interpreter
85ae115bc7Smrj *
86ae115bc7Smrj ******************************************************************************/
87ae115bc7Smrj
88ae115bc7Smrj ACPI_STATUS
AcpiNsEvaluate(ACPI_EVALUATE_INFO * Info)89ae115bc7Smrj AcpiNsEvaluate (
90ae115bc7Smrj ACPI_EVALUATE_INFO *Info)
91ae115bc7Smrj {
92ae115bc7Smrj ACPI_STATUS Status;
93ae115bc7Smrj
94ae115bc7Smrj
95ae115bc7Smrj ACPI_FUNCTION_TRACE (NsEvaluate);
96ae115bc7Smrj
97ae115bc7Smrj
98ae115bc7Smrj if (!Info)
99ae115bc7Smrj {
100ae115bc7Smrj return_ACPI_STATUS (AE_BAD_PARAMETER);
101ae115bc7Smrj }
102ae115bc7Smrj
103*cb565728SJerry Jelinek if (!Info->Node)
104*cb565728SJerry Jelinek {
105ae115bc7Smrj /*
106*cb565728SJerry Jelinek * Get the actual namespace node for the target object if we
107*cb565728SJerry Jelinek * need to. Handles these cases:
108ae115bc7Smrj *
109*cb565728SJerry Jelinek * 1) Null node, valid pathname from root (absolute path)
110*cb565728SJerry Jelinek * 2) Node and valid pathname (path relative to Node)
111*cb565728SJerry Jelinek * 3) Node, Null pathname
112ae115bc7Smrj */
113*cb565728SJerry Jelinek Status = AcpiNsGetNode (Info->PrefixNode, Info->RelativePathname,
114*cb565728SJerry Jelinek ACPI_NS_NO_UPSEARCH, &Info->Node);
115ae115bc7Smrj if (ACPI_FAILURE (Status))
116ae115bc7Smrj {
117ae115bc7Smrj return_ACPI_STATUS (Status);
118ae115bc7Smrj }
119ae115bc7Smrj }
120ae115bc7Smrj
121ae115bc7Smrj /*
122*cb565728SJerry Jelinek * For a method alias, we must grab the actual method node so that
123*cb565728SJerry Jelinek * proper scoping context will be established before execution.
124ae115bc7Smrj */
125*cb565728SJerry Jelinek if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
126ae115bc7Smrj {
127*cb565728SJerry Jelinek Info->Node = ACPI_CAST_PTR (
128*cb565728SJerry Jelinek ACPI_NAMESPACE_NODE, Info->Node->Object);
129ae115bc7Smrj }
130ae115bc7Smrj
131*cb565728SJerry Jelinek /* Complete the info block initialization */
132db2bae30SDana Myers
133*cb565728SJerry Jelinek Info->ReturnObject = NULL;
134*cb565728SJerry Jelinek Info->NodeFlags = Info->Node->Flags;
135*cb565728SJerry Jelinek Info->ObjDesc = AcpiNsGetAttachedObject (Info->Node);
136*cb565728SJerry Jelinek
137*cb565728SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
138*cb565728SJerry Jelinek Info->RelativePathname, Info->Node,
139*cb565728SJerry Jelinek AcpiNsGetAttachedObject (Info->Node)));
140*cb565728SJerry Jelinek
141*cb565728SJerry Jelinek /* Get info if we have a predefined name (_HID, etc.) */
142*cb565728SJerry Jelinek
143*cb565728SJerry Jelinek Info->Predefined = AcpiUtMatchPredefinedMethod (Info->Node->Name.Ascii);
144*cb565728SJerry Jelinek
145*cb565728SJerry Jelinek /* Get the full pathname to the object, for use in warning messages */
146*cb565728SJerry Jelinek
147*cb565728SJerry Jelinek Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);
148*cb565728SJerry Jelinek if (!Info->FullPathname)
149*cb565728SJerry Jelinek {
150*cb565728SJerry Jelinek return_ACPI_STATUS (AE_NO_MEMORY);
151*cb565728SJerry Jelinek }
152*cb565728SJerry Jelinek
153*cb565728SJerry Jelinek /* Count the number of arguments being passed in */
154*cb565728SJerry Jelinek
155*cb565728SJerry Jelinek Info->ParamCount = 0;
156db2bae30SDana Myers if (Info->Parameters)
157db2bae30SDana Myers {
158db2bae30SDana Myers while (Info->Parameters[Info->ParamCount])
159db2bae30SDana Myers {
160db2bae30SDana Myers Info->ParamCount++;
161db2bae30SDana Myers }
162*cb565728SJerry Jelinek
163*cb565728SJerry Jelinek /* Warn on impossible argument count */
164*cb565728SJerry Jelinek
165*cb565728SJerry Jelinek if (Info->ParamCount > ACPI_METHOD_NUM_ARGS)
166*cb565728SJerry Jelinek {
167*cb565728SJerry Jelinek ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,
168*cb565728SJerry Jelinek "Excess arguments (%u) - using only %u",
169*cb565728SJerry Jelinek Info->ParamCount, ACPI_METHOD_NUM_ARGS));
170*cb565728SJerry Jelinek
171*cb565728SJerry Jelinek Info->ParamCount = ACPI_METHOD_NUM_ARGS;
172*cb565728SJerry Jelinek }
173db2bae30SDana Myers }
174db2bae30SDana Myers
175*cb565728SJerry Jelinek /*
176*cb565728SJerry Jelinek * For predefined names: Check that the declared argument count
177*cb565728SJerry Jelinek * matches the ACPI spec -- otherwise this is a BIOS error.
178*cb565728SJerry Jelinek */
179*cb565728SJerry Jelinek AcpiNsCheckAcpiCompliance (Info->FullPathname, Info->Node,
180*cb565728SJerry Jelinek Info->Predefined);
181*cb565728SJerry Jelinek
182*cb565728SJerry Jelinek /*
183*cb565728SJerry Jelinek * For all names: Check that the incoming argument count for
184*cb565728SJerry Jelinek * this method/object matches the actual ASL/AML definition.
185*cb565728SJerry Jelinek */
186*cb565728SJerry Jelinek AcpiNsCheckArgumentCount (Info->FullPathname, Info->Node,
187*cb565728SJerry Jelinek Info->ParamCount, Info->Predefined);
188*cb565728SJerry Jelinek
189*cb565728SJerry Jelinek /* For predefined names: Typecheck all incoming arguments */
190*cb565728SJerry Jelinek
191*cb565728SJerry Jelinek AcpiNsCheckArgumentTypes (Info);
192*cb565728SJerry Jelinek
193*cb565728SJerry Jelinek /*
194*cb565728SJerry Jelinek * Three major evaluation cases:
195*cb565728SJerry Jelinek *
196*cb565728SJerry Jelinek * 1) Object types that cannot be evaluated by definition
197*cb565728SJerry Jelinek * 2) The object is a control method -- execute it
198*cb565728SJerry Jelinek * 3) The object is not a method -- just return it's current value
199*cb565728SJerry Jelinek */
200*cb565728SJerry Jelinek switch (AcpiNsGetType (Info->Node))
201*cb565728SJerry Jelinek {
202*cb565728SJerry Jelinek case ACPI_TYPE_DEVICE:
203*cb565728SJerry Jelinek case ACPI_TYPE_EVENT:
204*cb565728SJerry Jelinek case ACPI_TYPE_MUTEX:
205*cb565728SJerry Jelinek case ACPI_TYPE_REGION:
206*cb565728SJerry Jelinek case ACPI_TYPE_THERMAL:
207*cb565728SJerry Jelinek case ACPI_TYPE_LOCAL_SCOPE:
208*cb565728SJerry Jelinek /*
209*cb565728SJerry Jelinek * 1) Disallow evaluation of certain object types. For these,
210*cb565728SJerry Jelinek * object evaluation is undefined and not supported.
211*cb565728SJerry Jelinek */
212*cb565728SJerry Jelinek ACPI_ERROR ((AE_INFO,
213*cb565728SJerry Jelinek "%s: Evaluation of object type [%s] is not supported",
214*cb565728SJerry Jelinek Info->FullPathname,
215*cb565728SJerry Jelinek AcpiUtGetTypeName (Info->Node->Type)));
216*cb565728SJerry Jelinek
217*cb565728SJerry Jelinek Status = AE_TYPE;
218*cb565728SJerry Jelinek goto Cleanup;
219*cb565728SJerry Jelinek
220*cb565728SJerry Jelinek case ACPI_TYPE_METHOD:
221*cb565728SJerry Jelinek /*
222*cb565728SJerry Jelinek * 2) Object is a control method - execute it
223*cb565728SJerry Jelinek */
224*cb565728SJerry Jelinek
225*cb565728SJerry Jelinek /* Verify that there is a method object associated with this node */
226*cb565728SJerry Jelinek
227*cb565728SJerry Jelinek if (!Info->ObjDesc)
228*cb565728SJerry Jelinek {
229*cb565728SJerry Jelinek ACPI_ERROR ((AE_INFO, "%s: Method has no attached sub-object",
230*cb565728SJerry Jelinek Info->FullPathname));
231*cb565728SJerry Jelinek Status = AE_NULL_OBJECT;
232*cb565728SJerry Jelinek goto Cleanup;
233*cb565728SJerry Jelinek }
234ae115bc7Smrj
235ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
236*cb565728SJerry Jelinek "**** Execute method [%s] at AML address %p length %X\n",
237*cb565728SJerry Jelinek Info->FullPathname,
238ae115bc7Smrj Info->ObjDesc->Method.AmlStart + 1,
239ae115bc7Smrj Info->ObjDesc->Method.AmlLength - 1));
240ae115bc7Smrj
241ae115bc7Smrj /*
242ae115bc7Smrj * Any namespace deletion must acquire both the namespace and
243ae115bc7Smrj * interpreter locks to ensure that no thread is using the portion of
244ae115bc7Smrj * the namespace that is being deleted.
245ae115bc7Smrj *
246ae115bc7Smrj * Execute the method via the interpreter. The interpreter is locked
247ae115bc7Smrj * here before calling into the AML parser
248ae115bc7Smrj */
249db2bae30SDana Myers AcpiExEnterInterpreter ();
250ae115bc7Smrj Status = AcpiPsExecuteMethod (Info);
251ae115bc7Smrj AcpiExExitInterpreter ();
252*cb565728SJerry Jelinek break;
253db2bae30SDana Myers
254db2bae30SDana Myers default:
255*cb565728SJerry Jelinek /*
256*cb565728SJerry Jelinek * 3) All other non-method objects -- get the current object value
257*cb565728SJerry Jelinek */
258ae115bc7Smrj
259ae115bc7Smrj /*
260*cb565728SJerry Jelinek * Some objects require additional resolution steps (e.g., the Node
261*cb565728SJerry Jelinek * may be a field that must be read, etc.) -- we can't just grab
262*cb565728SJerry Jelinek * the object out of the node.
263ae115bc7Smrj *
264ae115bc7Smrj * Use ResolveNodeToValue() to get the associated value.
265ae115bc7Smrj *
266ae115bc7Smrj * NOTE: we can get away with passing in NULL for a walk state because
267*cb565728SJerry Jelinek * the Node is guaranteed to not be a reference to either a method
268ae115bc7Smrj * local or a method argument (because this interface is never called
269ae115bc7Smrj * from a running method.)
270ae115bc7Smrj *
271ae115bc7Smrj * Even though we do not directly invoke the interpreter for object
272*cb565728SJerry Jelinek * resolution, we must lock it because we could access an OpRegion.
273*cb565728SJerry Jelinek * The OpRegion access code assumes that the interpreter is locked.
274ae115bc7Smrj */
275db2bae30SDana Myers AcpiExEnterInterpreter ();
276ae115bc7Smrj
277*cb565728SJerry Jelinek /* TBD: ResolveNodeToValue has a strange interface, fix */
278ae115bc7Smrj
279*cb565728SJerry Jelinek Info->ReturnObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->Node);
280*cb565728SJerry Jelinek
281*cb565728SJerry Jelinek Status = AcpiExResolveNodeToValue (ACPI_CAST_INDIRECT_PTR (
282*cb565728SJerry Jelinek ACPI_NAMESPACE_NODE, &Info->ReturnObject), NULL);
283ae115bc7Smrj AcpiExExitInterpreter ();
284ae115bc7Smrj
285*cb565728SJerry Jelinek if (ACPI_FAILURE (Status))
286ae115bc7Smrj {
287*cb565728SJerry Jelinek Info->ReturnObject = NULL;
288*cb565728SJerry Jelinek goto Cleanup;
289*cb565728SJerry Jelinek }
290ae115bc7Smrj
291*cb565728SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returned object %p [%s]\n",
292ae115bc7Smrj Info->ReturnObject,
293ae115bc7Smrj AcpiUtGetObjectTypeName (Info->ReturnObject)));
294*cb565728SJerry Jelinek
295*cb565728SJerry Jelinek Status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */
296*cb565728SJerry Jelinek break;
297ae115bc7Smrj }
298ae115bc7Smrj
299ae115bc7Smrj /*
300*cb565728SJerry Jelinek * For predefined names, check the return value against the ACPI
301*cb565728SJerry Jelinek * specification. Some incorrect return value types are repaired.
302ae115bc7Smrj */
303*cb565728SJerry Jelinek (void) AcpiNsCheckReturnValue (Info->Node, Info, Info->ParamCount,
304aa2aa9a6SDana Myers Status, &Info->ReturnObject);
305aa2aa9a6SDana Myers
306aa2aa9a6SDana Myers /* Check if there is a return value that must be dealt with */
307aa2aa9a6SDana Myers
308ae115bc7Smrj if (Status == AE_CTRL_RETURN_VALUE)
309ae115bc7Smrj {
310ae115bc7Smrj /* If caller does not want the return value, delete it */
311ae115bc7Smrj
312ae115bc7Smrj if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
313ae115bc7Smrj {
314ae115bc7Smrj AcpiUtRemoveReference (Info->ReturnObject);
315ae115bc7Smrj Info->ReturnObject = NULL;
316ae115bc7Smrj }
317ae115bc7Smrj
318ae115bc7Smrj /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
319ae115bc7Smrj
320ae115bc7Smrj Status = AE_OK;
321ae115bc7Smrj }
322ae115bc7Smrj
323ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
324*cb565728SJerry Jelinek "*** Completed evaluation of object %s ***\n",
325*cb565728SJerry Jelinek Info->RelativePathname));
326ae115bc7Smrj
327*cb565728SJerry Jelinek Cleanup:
328ae115bc7Smrj /*
329ae115bc7Smrj * Namespace was unlocked by the handling AcpiNs* function, so we
330*cb565728SJerry Jelinek * just free the pathname and return
331ae115bc7Smrj */
332*cb565728SJerry Jelinek ACPI_FREE (Info->FullPathname);
333*cb565728SJerry Jelinek Info->FullPathname = NULL;
334ae115bc7Smrj return_ACPI_STATUS (Status);
335ae115bc7Smrj }
336ae115bc7Smrj
33757190917SDana Myers
33857190917SDana Myers /*******************************************************************************
33957190917SDana Myers *
34057190917SDana Myers * FUNCTION: AcpiNsExecModuleCodeList
34157190917SDana Myers *
34257190917SDana Myers * PARAMETERS: None
34357190917SDana Myers *
34457190917SDana Myers * RETURN: None. Exceptions during method execution are ignored, since
34557190917SDana Myers * we cannot abort a table load.
34657190917SDana Myers *
34757190917SDana Myers * DESCRIPTION: Execute all elements of the global module-level code list.
34857190917SDana Myers * Each element is executed as a single control method.
34957190917SDana Myers *
35057190917SDana Myers ******************************************************************************/
35157190917SDana Myers
35257190917SDana Myers void
AcpiNsExecModuleCodeList(void)35357190917SDana Myers AcpiNsExecModuleCodeList (
35457190917SDana Myers void)
35557190917SDana Myers {
35657190917SDana Myers ACPI_OPERAND_OBJECT *Prev;
35757190917SDana Myers ACPI_OPERAND_OBJECT *Next;
35857190917SDana Myers ACPI_EVALUATE_INFO *Info;
35957190917SDana Myers UINT32 MethodCount = 0;
36057190917SDana Myers
36157190917SDana Myers
36257190917SDana Myers ACPI_FUNCTION_TRACE (NsExecModuleCodeList);
36357190917SDana Myers
36457190917SDana Myers
36557190917SDana Myers /* Exit now if the list is empty */
36657190917SDana Myers
36757190917SDana Myers Next = AcpiGbl_ModuleCodeList;
36857190917SDana Myers if (!Next)
36957190917SDana Myers {
37057190917SDana Myers return_VOID;
37157190917SDana Myers }
37257190917SDana Myers
37357190917SDana Myers /* Allocate the evaluation information block */
37457190917SDana Myers
37557190917SDana Myers Info = ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO));
37657190917SDana Myers if (!Info)
37757190917SDana Myers {
37857190917SDana Myers return_VOID;
37957190917SDana Myers }
38057190917SDana Myers
38157190917SDana Myers /* Walk the list, executing each "method" */
38257190917SDana Myers
38357190917SDana Myers while (Next)
38457190917SDana Myers {
38557190917SDana Myers Prev = Next;
38657190917SDana Myers Next = Next->Method.Mutex;
38757190917SDana Myers
38857190917SDana Myers /* Clear the link field and execute the method */
38957190917SDana Myers
39057190917SDana Myers Prev->Method.Mutex = NULL;
39157190917SDana Myers AcpiNsExecModuleCode (Prev, Info);
39257190917SDana Myers MethodCount++;
39357190917SDana Myers
39457190917SDana Myers /* Delete the (temporary) method object */
39557190917SDana Myers
39657190917SDana Myers AcpiUtRemoveReference (Prev);
39757190917SDana Myers }
39857190917SDana Myers
399*cb565728SJerry Jelinek ACPI_INFO ((
40057190917SDana Myers "Executed %u blocks of module-level executable AML code",
40157190917SDana Myers MethodCount));
40257190917SDana Myers
40357190917SDana Myers ACPI_FREE (Info);
40457190917SDana Myers AcpiGbl_ModuleCodeList = NULL;
40557190917SDana Myers return_VOID;
40657190917SDana Myers }
40757190917SDana Myers
40857190917SDana Myers
40957190917SDana Myers /*******************************************************************************
41057190917SDana Myers *
41157190917SDana Myers * FUNCTION: AcpiNsExecModuleCode
41257190917SDana Myers *
41357190917SDana Myers * PARAMETERS: MethodObj - Object container for the module-level code
41457190917SDana Myers * Info - Info block for method evaluation
41557190917SDana Myers *
41657190917SDana Myers * RETURN: None. Exceptions during method execution are ignored, since
41757190917SDana Myers * we cannot abort a table load.
41857190917SDana Myers *
41957190917SDana Myers * DESCRIPTION: Execute a control method containing a block of module-level
42057190917SDana Myers * executable AML code. The control method is temporarily
42157190917SDana Myers * installed to the root node, then evaluated.
42257190917SDana Myers *
42357190917SDana Myers ******************************************************************************/
42457190917SDana Myers
42557190917SDana Myers static void
AcpiNsExecModuleCode(ACPI_OPERAND_OBJECT * MethodObj,ACPI_EVALUATE_INFO * Info)42657190917SDana Myers AcpiNsExecModuleCode (
42757190917SDana Myers ACPI_OPERAND_OBJECT *MethodObj,
42857190917SDana Myers ACPI_EVALUATE_INFO *Info)
42957190917SDana Myers {
43057190917SDana Myers ACPI_OPERAND_OBJECT *ParentObj;
43157190917SDana Myers ACPI_NAMESPACE_NODE *ParentNode;
43257190917SDana Myers ACPI_OBJECT_TYPE Type;
43357190917SDana Myers ACPI_STATUS Status;
43457190917SDana Myers
43557190917SDana Myers
43657190917SDana Myers ACPI_FUNCTION_TRACE (NsExecModuleCode);
43757190917SDana Myers
43857190917SDana Myers
43957190917SDana Myers /*
44057190917SDana Myers * Get the parent node. We cheat by using the NextObject field
44157190917SDana Myers * of the method object descriptor.
44257190917SDana Myers */
443*cb565728SJerry Jelinek ParentNode = ACPI_CAST_PTR (
444*cb565728SJerry Jelinek ACPI_NAMESPACE_NODE, MethodObj->Method.NextObject);
44557190917SDana Myers Type = AcpiNsGetType (ParentNode);
44657190917SDana Myers
44726f3cdf0SGordon Ross /*
44826f3cdf0SGordon Ross * Get the region handler and save it in the method object. We may need
44926f3cdf0SGordon Ross * this if an operation region declaration causes a _REG method to be run.
45026f3cdf0SGordon Ross *
45126f3cdf0SGordon Ross * We can't do this in AcpiPsLinkModuleCode because
45226f3cdf0SGordon Ross * AcpiGbl_RootNode->Object is NULL at PASS1.
45326f3cdf0SGordon Ross */
45426f3cdf0SGordon Ross if ((Type == ACPI_TYPE_DEVICE) && ParentNode->Object)
45526f3cdf0SGordon Ross {
45626f3cdf0SGordon Ross MethodObj->Method.Dispatch.Handler =
45726f3cdf0SGordon Ross ParentNode->Object->Device.Handler;
45826f3cdf0SGordon Ross }
45926f3cdf0SGordon Ross
46057190917SDana Myers /* Must clear NextObject (AcpiNsAttachObject needs the field) */
46157190917SDana Myers
46257190917SDana Myers MethodObj->Method.NextObject = NULL;
46357190917SDana Myers
46457190917SDana Myers /* Initialize the evaluation information block */
46557190917SDana Myers
466*cb565728SJerry Jelinek memset (Info, 0, sizeof (ACPI_EVALUATE_INFO));
46757190917SDana Myers Info->PrefixNode = ParentNode;
46857190917SDana Myers
46957190917SDana Myers /*
470*cb565728SJerry Jelinek * Get the currently attached parent object. Add a reference,
471*cb565728SJerry Jelinek * because the ref count will be decreased when the method object
472*cb565728SJerry Jelinek * is installed to the parent node.
47357190917SDana Myers */
47457190917SDana Myers ParentObj = AcpiNsGetAttachedObject (ParentNode);
47557190917SDana Myers if (ParentObj)
47657190917SDana Myers {
47757190917SDana Myers AcpiUtAddReference (ParentObj);
47857190917SDana Myers }
47957190917SDana Myers
48057190917SDana Myers /* Install the method (module-level code) in the parent node */
48157190917SDana Myers
482*cb565728SJerry Jelinek Status = AcpiNsAttachObject (ParentNode, MethodObj, ACPI_TYPE_METHOD);
48357190917SDana Myers if (ACPI_FAILURE (Status))
48457190917SDana Myers {
48557190917SDana Myers goto Exit;
48657190917SDana Myers }
48757190917SDana Myers
48857190917SDana Myers /* Execute the parent node as a control method */
48957190917SDana Myers
49057190917SDana Myers Status = AcpiNsEvaluate (Info);
49157190917SDana Myers
492*cb565728SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_INIT_NAMES,
493*cb565728SJerry Jelinek "Executed module-level code at %p\n",
49457190917SDana Myers MethodObj->Method.AmlStart));
49557190917SDana Myers
49657190917SDana Myers /* Delete a possible implicit return value (in slack mode) */
49757190917SDana Myers
49857190917SDana Myers if (Info->ReturnObject)
49957190917SDana Myers {
50057190917SDana Myers AcpiUtRemoveReference (Info->ReturnObject);
50157190917SDana Myers }
50257190917SDana Myers
50357190917SDana Myers /* Detach the temporary method object */
50457190917SDana Myers
50557190917SDana Myers AcpiNsDetachObject (ParentNode);
50657190917SDana Myers
50757190917SDana Myers /* Restore the original parent object */
50857190917SDana Myers
50957190917SDana Myers if (ParentObj)
51057190917SDana Myers {
51157190917SDana Myers Status = AcpiNsAttachObject (ParentNode, ParentObj, Type);
51257190917SDana Myers }
51357190917SDana Myers else
51457190917SDana Myers {
51557190917SDana Myers ParentNode->Type = (UINT8) Type;
51657190917SDana Myers }
51757190917SDana Myers
51857190917SDana Myers Exit:
51957190917SDana Myers if (ParentObj)
52057190917SDana Myers {
52157190917SDana Myers AcpiUtRemoveReference (ParentObj);
52257190917SDana Myers }
52357190917SDana Myers return_VOID;
52457190917SDana Myers }
525