xref: /titanic_51/usr/src/uts/intel/io/acpica/namespace/nseval.c (revision 7ff836697c120cb94bd30d5c2204eb9b74718e4c)
1 /*******************************************************************************
2  *
3  * Module Name: nseval - Object evaluation, includes control method execution
4  *
5  ******************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights.  You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code.  No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision.  In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change.  Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee.  Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution.  In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65 
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 #define __NSEVAL_C__
118 
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acparser.h"
122 #include "acinterp.h"
123 #include "acnamesp.h"
124 
125 
126 #define _COMPONENT          ACPI_NAMESPACE
127         ACPI_MODULE_NAME    ("nseval")
128 
129 
130 /*******************************************************************************
131  *
132  * FUNCTION:    AcpiNsEvaluate
133  *
134  * PARAMETERS:  Info            - Evaluation info block, contains:
135  *                  PrefixNode      - Prefix or Method/Object Node to execute
136  *                  Pathname        - Name of method to execute, If NULL, the
137  *                                    Node is the object to execute
138  *                  Parameters      - List of parameters to pass to the method,
139  *                                    terminated by NULL. Params itself may be
140  *                                    NULL if no parameters are being passed.
141  *                  ReturnObject    - Where to put method's return value (if
142  *                                    any). If NULL, no value is returned.
143  *                  ParameterType   - Type of Parameter list
144  *                  ReturnObject    - Where to put method's return value (if
145  *                                    any). If NULL, no value is returned.
146  *                  Flags           - ACPI_IGNORE_RETURN_VALUE to delete return
147  *
148  * RETURN:      Status
149  *
150  * DESCRIPTION: Execute a control method or return the current value of an
151  *              ACPI namespace object.
152  *
153  * MUTEX:       Locks interpreter
154  *
155  ******************************************************************************/
156 
157 ACPI_STATUS
158 AcpiNsEvaluate (
159     ACPI_EVALUATE_INFO      *Info)
160 {
161     ACPI_STATUS             Status;
162     ACPI_NAMESPACE_NODE     *Node;
163 
164 
165     ACPI_FUNCTION_TRACE (NsEvaluate);
166 
167 
168     if (!Info)
169     {
170         return_ACPI_STATUS (AE_BAD_PARAMETER);
171     }
172 
173     /* Initialize the return value to an invalid object */
174 
175     Info->ReturnObject = NULL;
176     Info->ParamCount = 0;
177 
178     /*
179      * Get the actual namespace node for the target object. Handles these cases:
180      *
181      * 1) Null node, Pathname (absolute path)
182      * 2) Node, Pathname (path relative to Node)
183      * 3) Node, Null Pathname
184      */
185     Status = AcpiNsGetNode (Info->PrefixNode, Info->Pathname,
186                 ACPI_NS_NO_UPSEARCH, &Info->ResolvedNode);
187     if (ACPI_FAILURE (Status))
188     {
189         return_ACPI_STATUS (Status);
190     }
191 
192     /*
193      * For a method alias, we must grab the actual method node so that proper
194      * scoping context will be established before execution.
195      */
196     if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
197     {
198         Info->ResolvedNode =
199             ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->ResolvedNode->Object);
200     }
201 
202     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->Pathname,
203         Info->ResolvedNode, AcpiNsGetAttachedObject (Info->ResolvedNode)));
204 
205     Node = Info->ResolvedNode;
206 
207     /*
208      * Two major cases here:
209      *
210      * 1) The object is a control method -- execute it
211      * 2) The object is not a method -- just return it's current value
212      */
213     if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_METHOD)
214     {
215         /*
216          * 1) Object is a control method - execute it
217          */
218 
219         /* Verify that there is a method object associated with this node */
220 
221         Info->ObjDesc = AcpiNsGetAttachedObject (Info->ResolvedNode);
222         if (!Info->ObjDesc)
223         {
224             ACPI_ERROR ((AE_INFO, "Control method has no attached sub-object"));
225             return_ACPI_STATUS (AE_NULL_OBJECT);
226         }
227 
228         /* Count the number of arguments being passed to the method */
229 
230         if (Info->Parameters)
231         {
232             while (Info->Parameters[Info->ParamCount])
233             {
234                 if (Info->ParamCount > ACPI_METHOD_MAX_ARG)
235                 {
236                     return_ACPI_STATUS (AE_LIMIT);
237                 }
238                 Info->ParamCount++;
239             }
240         }
241 
242         ACPI_DUMP_PATHNAME (Info->ResolvedNode, "ACPI: Execute Method",
243             ACPI_LV_INFO, _COMPONENT);
244 
245         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
246             "Method at AML address %p Length %X\n",
247             Info->ObjDesc->Method.AmlStart + 1,
248             Info->ObjDesc->Method.AmlLength - 1));
249 
250         /*
251          * Any namespace deletion must acquire both the namespace and
252          * interpreter locks to ensure that no thread is using the portion of
253          * the namespace that is being deleted.
254          *
255          * Execute the method via the interpreter. The interpreter is locked
256          * here before calling into the AML parser
257          */
258         AcpiExEnterInterpreter ();
259         Status = AcpiPsExecuteMethod (Info);
260         AcpiExExitInterpreter ();
261     }
262     else
263     {
264         /*
265          * 2) Object is not a method, return its current value
266          *
267          * Disallow certain object types. For these, "evaluation" is undefined.
268          */
269         switch (Info->ResolvedNode->Type)
270         {
271         case ACPI_TYPE_DEVICE:
272         case ACPI_TYPE_EVENT:
273         case ACPI_TYPE_MUTEX:
274         case ACPI_TYPE_REGION:
275         case ACPI_TYPE_THERMAL:
276         case ACPI_TYPE_LOCAL_SCOPE:
277 
278             ACPI_ERROR ((AE_INFO,
279                 "[%4.4s] Evaluation of object type [%s] is not supported",
280                 Info->ResolvedNode->Name.Ascii,
281                 AcpiUtGetTypeName (Info->ResolvedNode->Type)));
282 
283             return_ACPI_STATUS (AE_TYPE);
284 
285         default:
286             break;
287         }
288 
289         /*
290          * Objects require additional resolution steps (e.g., the Node may be
291          * a field that must be read, etc.) -- we can't just grab the object
292          * out of the node.
293          *
294          * Use ResolveNodeToValue() to get the associated value.
295          *
296          * NOTE: we can get away with passing in NULL for a walk state because
297          * ResolvedNode is guaranteed to not be a reference to either a method
298          * local or a method argument (because this interface is never called
299          * from a running method.)
300          *
301          * Even though we do not directly invoke the interpreter for object
302          * resolution, we must lock it because we could access an opregion.
303          * The opregion access code assumes that the interpreter is locked.
304          */
305         AcpiExEnterInterpreter ();
306 
307         /* Function has a strange interface */
308 
309         Status = AcpiExResolveNodeToValue (&Info->ResolvedNode, NULL);
310         AcpiExExitInterpreter ();
311 
312         /*
313          * If AcpiExResolveNodeToValue() succeeded, the return value was placed
314          * in ResolvedNode.
315          */
316         if (ACPI_SUCCESS (Status))
317         {
318             Status = AE_CTRL_RETURN_VALUE;
319             Info->ReturnObject =
320                 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->ResolvedNode);
321 
322             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
323                 Info->ReturnObject,
324                 AcpiUtGetObjectTypeName (Info->ReturnObject)));
325         }
326     }
327 
328     /*
329      * Check input argument count against the ASL-defined count for a method.
330      * Also check predefined names: argument count and return value against
331      * the ACPI specification. Some incorrect return value types are repaired.
332      */
333     (void) AcpiNsCheckPredefinedNames (Node, Info->ParamCount,
334                 Status, &Info->ReturnObject);
335 
336     /* Check if there is a return value that must be dealt with */
337 
338     if (Status == AE_CTRL_RETURN_VALUE)
339     {
340         /* If caller does not want the return value, delete it */
341 
342         if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
343         {
344             AcpiUtRemoveReference (Info->ReturnObject);
345             Info->ReturnObject = NULL;
346         }
347 
348         /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
349 
350         Status = AE_OK;
351     }
352 
353     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
354         "*** Completed evaluation of object %s ***\n", Info->Pathname));
355 
356     /*
357      * Namespace was unlocked by the handling AcpiNs* function, so we
358      * just return
359      */
360     return_ACPI_STATUS (Status);
361 }
362 
363