Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / namespace / nseval.c
blobc92e6e7ec9eeb48c1776149e67aa857cbbbb0bd8
1 /*******************************************************************************
3 * Module Name: nseval - Object evaluation, includes control method execution
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __NSEVAL_C__
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acparser.h"
49 #include "acinterp.h"
50 #include "acnamesp.h"
53 #define _COMPONENT ACPI_NAMESPACE
54 ACPI_MODULE_NAME ("nseval")
56 /* Local prototypes */
58 static void
59 AcpiNsExecModuleCode (
60 ACPI_OPERAND_OBJECT *MethodObj,
61 ACPI_EVALUATE_INFO *Info);
64 /*******************************************************************************
66 * FUNCTION: AcpiNsEvaluate
68 * PARAMETERS: Info - Evaluation info block, contains:
69 * PrefixNode - Prefix or Method/Object Node to execute
70 * RelativePath - Name of method to execute, If NULL, the
71 * Node is the object to execute
72 * Parameters - List of parameters to pass to the method,
73 * terminated by NULL. Params itself may be
74 * NULL if no parameters are being passed.
75 * ReturnObject - Where to put method's return value (if
76 * any). If NULL, no value is returned.
77 * ParameterType - Type of Parameter list
78 * ReturnObject - Where to put method's return value (if
79 * any). If NULL, no value is returned.
80 * Flags - ACPI_IGNORE_RETURN_VALUE to delete return
82 * RETURN: Status
84 * DESCRIPTION: Execute a control method or return the current value of an
85 * ACPI namespace object.
87 * MUTEX: Locks interpreter
89 ******************************************************************************/
91 ACPI_STATUS
92 AcpiNsEvaluate (
93 ACPI_EVALUATE_INFO *Info)
95 ACPI_STATUS Status;
98 ACPI_FUNCTION_TRACE (NsEvaluate);
101 if (!Info)
103 return_ACPI_STATUS (AE_BAD_PARAMETER);
106 if (!Info->Node)
109 * Get the actual namespace node for the target object if we
110 * need to. Handles these cases:
112 * 1) Null node, valid pathname from root (absolute path)
113 * 2) Node and valid pathname (path relative to Node)
114 * 3) Node, Null pathname
116 Status = AcpiNsGetNode (Info->PrefixNode, Info->RelativePathname,
117 ACPI_NS_NO_UPSEARCH, &Info->Node);
118 if (ACPI_FAILURE (Status))
120 return_ACPI_STATUS (Status);
125 * For a method alias, we must grab the actual method node so that
126 * proper scoping context will be established before execution.
128 if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
130 Info->Node = ACPI_CAST_PTR (
131 ACPI_NAMESPACE_NODE, Info->Node->Object);
134 /* Complete the info block initialization */
136 Info->ReturnObject = NULL;
137 Info->NodeFlags = Info->Node->Flags;
138 Info->ObjDesc = AcpiNsGetAttachedObject (Info->Node);
140 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
141 Info->RelativePathname, Info->Node,
142 AcpiNsGetAttachedObject (Info->Node)));
144 /* Get info if we have a predefined name (_HID, etc.) */
146 Info->Predefined = AcpiUtMatchPredefinedMethod (Info->Node->Name.Ascii);
148 /* Get the full pathname to the object, for use in warning messages */
150 Info->FullPathname = AcpiNsGetExternalPathname (Info->Node);
151 if (!Info->FullPathname)
153 return_ACPI_STATUS (AE_NO_MEMORY);
156 /* Count the number of arguments being passed in */
158 Info->ParamCount = 0;
159 if (Info->Parameters)
161 while (Info->Parameters[Info->ParamCount])
163 Info->ParamCount++;
166 /* Warn on impossible argument count */
168 if (Info->ParamCount > ACPI_METHOD_NUM_ARGS)
170 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,
171 "Excess arguments (%u) - using only %u",
172 Info->ParamCount, ACPI_METHOD_NUM_ARGS));
174 Info->ParamCount = ACPI_METHOD_NUM_ARGS;
179 * For predefined names: Check that the declared argument count
180 * matches the ACPI spec -- otherwise this is a BIOS error.
182 AcpiNsCheckAcpiCompliance (Info->FullPathname, Info->Node,
183 Info->Predefined);
186 * For all names: Check that the incoming argument count for
187 * this method/object matches the actual ASL/AML definition.
189 AcpiNsCheckArgumentCount (Info->FullPathname, Info->Node,
190 Info->ParamCount, Info->Predefined);
192 /* For predefined names: Typecheck all incoming arguments */
194 AcpiNsCheckArgumentTypes (Info);
197 * Three major evaluation cases:
199 * 1) Object types that cannot be evaluated by definition
200 * 2) The object is a control method -- execute it
201 * 3) The object is not a method -- just return it's current value
203 switch (AcpiNsGetType (Info->Node))
205 case ACPI_TYPE_DEVICE:
206 case ACPI_TYPE_EVENT:
207 case ACPI_TYPE_MUTEX:
208 case ACPI_TYPE_REGION:
209 case ACPI_TYPE_THERMAL:
210 case ACPI_TYPE_LOCAL_SCOPE:
212 * 1) Disallow evaluation of certain object types. For these,
213 * object evaluation is undefined and not supported.
215 ACPI_ERROR ((AE_INFO,
216 "%s: Evaluation of object type [%s] is not supported",
217 Info->FullPathname,
218 AcpiUtGetTypeName (Info->Node->Type)));
220 Status = AE_TYPE;
221 goto Cleanup;
223 case ACPI_TYPE_METHOD:
225 * 2) Object is a control method - execute it
228 /* Verify that there is a method object associated with this node */
230 if (!Info->ObjDesc)
232 ACPI_ERROR ((AE_INFO, "%s: Method has no attached sub-object",
233 Info->FullPathname));
234 Status = AE_NULL_OBJECT;
235 goto Cleanup;
238 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
239 "**** Execute method [%s] at AML address %p length %X\n",
240 Info->FullPathname,
241 Info->ObjDesc->Method.AmlStart + 1,
242 Info->ObjDesc->Method.AmlLength - 1));
245 * Any namespace deletion must acquire both the namespace and
246 * interpreter locks to ensure that no thread is using the portion of
247 * the namespace that is being deleted.
249 * Execute the method via the interpreter. The interpreter is locked
250 * here before calling into the AML parser
252 AcpiExEnterInterpreter ();
253 Status = AcpiPsExecuteMethod (Info);
254 AcpiExExitInterpreter ();
255 break;
257 default:
259 * 3) All other non-method objects -- get the current object value
263 * Some objects require additional resolution steps (e.g., the Node
264 * may be a field that must be read, etc.) -- we can't just grab
265 * the object out of the node.
267 * Use ResolveNodeToValue() to get the associated value.
269 * NOTE: we can get away with passing in NULL for a walk state because
270 * the Node is guaranteed to not be a reference to either a method
271 * local or a method argument (because this interface is never called
272 * from a running method.)
274 * Even though we do not directly invoke the interpreter for object
275 * resolution, we must lock it because we could access an OpRegion.
276 * The OpRegion access code assumes that the interpreter is locked.
278 AcpiExEnterInterpreter ();
280 /* TBD: ResolveNodeToValue has a strange interface, fix */
282 Info->ReturnObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->Node);
284 Status = AcpiExResolveNodeToValue (ACPI_CAST_INDIRECT_PTR (
285 ACPI_NAMESPACE_NODE, &Info->ReturnObject), NULL);
286 AcpiExExitInterpreter ();
288 if (ACPI_FAILURE (Status))
290 goto Cleanup;
293 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returned object %p [%s]\n",
294 Info->ReturnObject,
295 AcpiUtGetObjectTypeName (Info->ReturnObject)));
297 Status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */
298 break;
302 * For predefined names, check the return value against the ACPI
303 * specification. Some incorrect return value types are repaired.
305 (void) AcpiNsCheckReturnValue (Info->Node, Info, Info->ParamCount,
306 Status, &Info->ReturnObject);
308 /* Check if there is a return value that must be dealt with */
310 if (Status == AE_CTRL_RETURN_VALUE)
312 /* If caller does not want the return value, delete it */
314 if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
316 AcpiUtRemoveReference (Info->ReturnObject);
317 Info->ReturnObject = NULL;
320 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
322 Status = AE_OK;
325 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
326 "*** Completed evaluation of object %s ***\n",
327 Info->RelativePathname));
329 Cleanup:
331 * Namespace was unlocked by the handling AcpiNs* function, so we
332 * just free the pathname and return
334 ACPI_FREE (Info->FullPathname);
335 Info->FullPathname = NULL;
336 return_ACPI_STATUS (Status);
340 /*******************************************************************************
342 * FUNCTION: AcpiNsExecModuleCodeList
344 * PARAMETERS: None
346 * RETURN: None. Exceptions during method execution are ignored, since
347 * we cannot abort a table load.
349 * DESCRIPTION: Execute all elements of the global module-level code list.
350 * Each element is executed as a single control method.
352 ******************************************************************************/
354 void
355 AcpiNsExecModuleCodeList (
356 void)
358 ACPI_OPERAND_OBJECT *Prev;
359 ACPI_OPERAND_OBJECT *Next;
360 ACPI_EVALUATE_INFO *Info;
361 UINT32 MethodCount = 0;
364 ACPI_FUNCTION_TRACE (NsExecModuleCodeList);
367 /* Exit now if the list is empty */
369 Next = AcpiGbl_ModuleCodeList;
370 if (!Next)
372 return_VOID;
375 /* Allocate the evaluation information block */
377 Info = ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO));
378 if (!Info)
380 return_VOID;
383 /* Walk the list, executing each "method" */
385 while (Next)
387 Prev = Next;
388 Next = Next->Method.Mutex;
390 /* Clear the link field and execute the method */
392 Prev->Method.Mutex = NULL;
393 AcpiNsExecModuleCode (Prev, Info);
394 MethodCount++;
396 /* Delete the (temporary) method object */
398 AcpiUtRemoveReference (Prev);
401 ACPI_INFO ((AE_INFO,
402 "Executed %u blocks of module-level executable AML code",
403 MethodCount));
405 ACPI_FREE (Info);
406 AcpiGbl_ModuleCodeList = NULL;
407 return_VOID;
411 /*******************************************************************************
413 * FUNCTION: AcpiNsExecModuleCode
415 * PARAMETERS: MethodObj - Object container for the module-level code
416 * Info - Info block for method evaluation
418 * RETURN: None. Exceptions during method execution are ignored, since
419 * we cannot abort a table load.
421 * DESCRIPTION: Execute a control method containing a block of module-level
422 * executable AML code. The control method is temporarily
423 * installed to the root node, then evaluated.
425 ******************************************************************************/
427 static void
428 AcpiNsExecModuleCode (
429 ACPI_OPERAND_OBJECT *MethodObj,
430 ACPI_EVALUATE_INFO *Info)
432 ACPI_OPERAND_OBJECT *ParentObj;
433 ACPI_NAMESPACE_NODE *ParentNode;
434 ACPI_OBJECT_TYPE Type;
435 ACPI_STATUS Status;
438 ACPI_FUNCTION_TRACE (NsExecModuleCode);
442 * Get the parent node. We cheat by using the NextObject field
443 * of the method object descriptor.
445 ParentNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
446 MethodObj->Method.NextObject);
447 Type = AcpiNsGetType (ParentNode);
450 * Get the region handler and save it in the method object. We may need
451 * this if an operation region declaration causes a _REG method to be run.
453 * We can't do this in AcpiPsLinkModuleCode because
454 * AcpiGbl_RootNode->Object is NULL at PASS1.
456 if ((Type == ACPI_TYPE_DEVICE) && ParentNode->Object)
458 MethodObj->Method.Dispatch.Handler =
459 ParentNode->Object->Device.Handler;
462 /* Must clear NextObject (AcpiNsAttachObject needs the field) */
464 MethodObj->Method.NextObject = NULL;
466 /* Initialize the evaluation information block */
468 ACPI_MEMSET (Info, 0, sizeof (ACPI_EVALUATE_INFO));
469 Info->PrefixNode = ParentNode;
472 * Get the currently attached parent object. Add a reference, because the
473 * ref count will be decreased when the method object is installed to
474 * the parent node.
476 ParentObj = AcpiNsGetAttachedObject (ParentNode);
477 if (ParentObj)
479 AcpiUtAddReference (ParentObj);
482 /* Install the method (module-level code) in the parent node */
484 Status = AcpiNsAttachObject (ParentNode, MethodObj,
485 ACPI_TYPE_METHOD);
486 if (ACPI_FAILURE (Status))
488 goto Exit;
491 /* Execute the parent node as a control method */
493 Status = AcpiNsEvaluate (Info);
495 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Executed module-level code at %p\n",
496 MethodObj->Method.AmlStart));
498 /* Delete a possible implicit return value (in slack mode) */
500 if (Info->ReturnObject)
502 AcpiUtRemoveReference (Info->ReturnObject);
505 /* Detach the temporary method object */
507 AcpiNsDetachObject (ParentNode);
509 /* Restore the original parent object */
511 if (ParentObj)
513 Status = AcpiNsAttachObject (ParentNode, ParentObj, Type);
515 else
517 ParentNode->Type = (UINT8) Type;
520 Exit:
521 if (ParentObj)
523 AcpiUtRemoveReference (ParentObj);
525 return_VOID;