Deleted Added
full compact
nseval.c (114237) nseval.c (126372)
1/*******************************************************************************
2 *
3 * Module Name: nseval - Object evaluation interfaces -- includes control
4 * method lookup and execution.
1/*******************************************************************************
2 *
3 * Module Name: nseval - Object evaluation interfaces -- includes control
4 * method lookup and execution.
5 * $Revision: 121 $
5 * $Revision: 123 $
6 *
7 ******************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
6 *
7 ******************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67
68 *
69 * 3.3. Redistribution of Executable. Redistribution in executable form of any
70 * substantial portion of the Covered Code or modification must reproduce the
71 * above Copyright Notice, and the following Disclaimer and Export Compliance
72 * provision in the documentation and/or other materials provided with the
73 * distribution.
74 *
75 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * Intel Code.
77 *
78 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
79 * Intel shall be used in advertising or otherwise to promote the sale, use or
80 * other dealings in products derived from or relating to the Covered Code
81 * without prior written authorization from Intel.
82 *
83 * 4. Disclaimer and Export Compliance
84 *
85 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
86 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
87 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
88 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
89 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
90 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * PARTICULAR PURPOSE.
92 *
93 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
94 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
95 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
96 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
97 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
98 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
99 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * LIMITED REMEDY.
101 *
102 * 4.3. Licensee shall not export, either directly or indirectly, any of this
103 * software or system incorporating such software without first obtaining any
104 * required license or other approval from the U. S. Department of Commerce or
105 * any other agency or department of the United States Government. In the
106 * event Licensee exports any such software from the United States or
107 * re-exports any such software from a foreign destination, Licensee shall
108 * ensure that the distribution and export/re-export of the software is in
109 * compliance with all laws, regulations, orders, or other restrictions of the
110 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
111 * any of its subsidiaries will export/re-export any technical data, process,
112 * software, or service, directly or indirectly, to any country for which the
113 * United States government or any agency thereof requires an export license,
114 * other governmental approval, or letter of assurance, without first obtaining
115 * such license, approval or letter.
116 *
117 *****************************************************************************/
118
119#define __NSEVAL_C__
120
121#include "acpi.h"
122#include "acparser.h"
123#include "acinterp.h"
124#include "acnamesp.h"
125
126
127#define _COMPONENT ACPI_NAMESPACE
128 ACPI_MODULE_NAME ("nseval")
129
130
131/*******************************************************************************
132 *
133 * FUNCTION: AcpiNsEvaluateRelative
134 *
135 * PARAMETERS: Handle - The relative containing object
136 * Pathname - Name of method to execute, If NULL, the
137 * handle is the object to execute
138 * Params - 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 *
144 * RETURN: Status
145 *
146 * DESCRIPTION: Find and execute the requested method using the handle as a
147 * scope
148 *
149 * MUTEX: Locks Namespace
150 *
151 ******************************************************************************/
152
153ACPI_STATUS
154AcpiNsEvaluateRelative (
155 ACPI_NAMESPACE_NODE *Handle,
156 char *Pathname,
157 ACPI_OPERAND_OBJECT **Params,
158 ACPI_OPERAND_OBJECT **ReturnObject)
159{
160 ACPI_NAMESPACE_NODE *PrefixNode;
161 ACPI_STATUS Status;
162 ACPI_NAMESPACE_NODE *Node = NULL;
163 char *InternalPath = NULL;
164 ACPI_GENERIC_STATE ScopeInfo;
165
166
167 ACPI_FUNCTION_TRACE ("NsEvaluateRelative");
168
169
170 /*
171 * Must have a valid object handle
172 */
173 if (!Handle)
174 {
175 return_ACPI_STATUS (AE_BAD_PARAMETER);
176 }
177
178 /* Build an internal name string for the method */
179
180 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
181 if (ACPI_FAILURE (Status))
182 {
183 return_ACPI_STATUS (Status);
184 }
185
186 /* Get the prefix handle and Node */
187
188 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
189 if (ACPI_FAILURE (Status))
190 {
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67
68 *
69 * 3.3. Redistribution of Executable. Redistribution in executable form of any
70 * substantial portion of the Covered Code or modification must reproduce the
71 * above Copyright Notice, and the following Disclaimer and Export Compliance
72 * provision in the documentation and/or other materials provided with the
73 * distribution.
74 *
75 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * Intel Code.
77 *
78 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
79 * Intel shall be used in advertising or otherwise to promote the sale, use or
80 * other dealings in products derived from or relating to the Covered Code
81 * without prior written authorization from Intel.
82 *
83 * 4. Disclaimer and Export Compliance
84 *
85 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
86 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
87 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
88 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
89 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
90 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * PARTICULAR PURPOSE.
92 *
93 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
94 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
95 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
96 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
97 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
98 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
99 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * LIMITED REMEDY.
101 *
102 * 4.3. Licensee shall not export, either directly or indirectly, any of this
103 * software or system incorporating such software without first obtaining any
104 * required license or other approval from the U. S. Department of Commerce or
105 * any other agency or department of the United States Government. In the
106 * event Licensee exports any such software from the United States or
107 * re-exports any such software from a foreign destination, Licensee shall
108 * ensure that the distribution and export/re-export of the software is in
109 * compliance with all laws, regulations, orders, or other restrictions of the
110 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
111 * any of its subsidiaries will export/re-export any technical data, process,
112 * software, or service, directly or indirectly, to any country for which the
113 * United States government or any agency thereof requires an export license,
114 * other governmental approval, or letter of assurance, without first obtaining
115 * such license, approval or letter.
116 *
117 *****************************************************************************/
118
119#define __NSEVAL_C__
120
121#include "acpi.h"
122#include "acparser.h"
123#include "acinterp.h"
124#include "acnamesp.h"
125
126
127#define _COMPONENT ACPI_NAMESPACE
128 ACPI_MODULE_NAME ("nseval")
129
130
131/*******************************************************************************
132 *
133 * FUNCTION: AcpiNsEvaluateRelative
134 *
135 * PARAMETERS: Handle - The relative containing object
136 * Pathname - Name of method to execute, If NULL, the
137 * handle is the object to execute
138 * Params - 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 *
144 * RETURN: Status
145 *
146 * DESCRIPTION: Find and execute the requested method using the handle as a
147 * scope
148 *
149 * MUTEX: Locks Namespace
150 *
151 ******************************************************************************/
152
153ACPI_STATUS
154AcpiNsEvaluateRelative (
155 ACPI_NAMESPACE_NODE *Handle,
156 char *Pathname,
157 ACPI_OPERAND_OBJECT **Params,
158 ACPI_OPERAND_OBJECT **ReturnObject)
159{
160 ACPI_NAMESPACE_NODE *PrefixNode;
161 ACPI_STATUS Status;
162 ACPI_NAMESPACE_NODE *Node = NULL;
163 char *InternalPath = NULL;
164 ACPI_GENERIC_STATE ScopeInfo;
165
166
167 ACPI_FUNCTION_TRACE ("NsEvaluateRelative");
168
169
170 /*
171 * Must have a valid object handle
172 */
173 if (!Handle)
174 {
175 return_ACPI_STATUS (AE_BAD_PARAMETER);
176 }
177
178 /* Build an internal name string for the method */
179
180 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
181 if (ACPI_FAILURE (Status))
182 {
183 return_ACPI_STATUS (Status);
184 }
185
186 /* Get the prefix handle and Node */
187
188 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
189 if (ACPI_FAILURE (Status))
190 {
191 return_ACPI_STATUS (Status);
191 goto Cleanup;
192 }
193
194 PrefixNode = AcpiNsMapHandleToNode (Handle);
195 if (!PrefixNode)
196 {
197 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
198 Status = AE_BAD_PARAMETER;
199 goto Cleanup;
200 }
201
202 /* Lookup the name in the namespace */
203
204 ScopeInfo.Scope.Node = PrefixNode;
205 Status = AcpiNsLookup (&ScopeInfo, InternalPath, ACPI_TYPE_ANY,
206 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
207 &Node);
208
209 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
210
211 if (ACPI_FAILURE (Status))
212 {
213 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object [%s] not found [%s]\n",
214 Pathname, AcpiFormatException (Status)));
215 goto Cleanup;
216 }
217
218 /*
219 * Now that we have a handle to the object, we can attempt
220 * to evaluate it.
221 */
222 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
223 Pathname, Node, AcpiNsGetAttachedObject (Node)));
224
225 Status = AcpiNsEvaluateByHandle (Node, Params, ReturnObject);
226
227 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
228 Pathname));
229
230Cleanup:
231
232 ACPI_MEM_FREE (InternalPath);
233 return_ACPI_STATUS (Status);
234}
235
236
237/*******************************************************************************
238 *
239 * FUNCTION: AcpiNsEvaluateByName
240 *
241 * PARAMETERS: Pathname - Fully qualified pathname to the object
242 * ReturnObject - Where to put method's return value (if
243 * any). If NULL, no value is returned.
244 * Params - List of parameters to pass to the method,
245 * terminated by NULL. Params itself may be
246 * NULL if no parameters are being passed.
247 *
248 * RETURN: Status
249 *
250 * DESCRIPTION: Find and execute the requested method passing the given
251 * parameters
252 *
253 * MUTEX: Locks Namespace
254 *
255 ******************************************************************************/
256
257ACPI_STATUS
258AcpiNsEvaluateByName (
259 char *Pathname,
260 ACPI_OPERAND_OBJECT **Params,
261 ACPI_OPERAND_OBJECT **ReturnObject)
262{
263 ACPI_STATUS Status;
264 ACPI_NAMESPACE_NODE *Node = NULL;
265 char *InternalPath = NULL;
266
267
268 ACPI_FUNCTION_TRACE ("NsEvaluateByName");
269
270
271 /* Build an internal name string for the method */
272
273 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
274 if (ACPI_FAILURE (Status))
275 {
276 return_ACPI_STATUS (Status);
277 }
278
279 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
280 if (ACPI_FAILURE (Status))
281 {
192 }
193
194 PrefixNode = AcpiNsMapHandleToNode (Handle);
195 if (!PrefixNode)
196 {
197 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
198 Status = AE_BAD_PARAMETER;
199 goto Cleanup;
200 }
201
202 /* Lookup the name in the namespace */
203
204 ScopeInfo.Scope.Node = PrefixNode;
205 Status = AcpiNsLookup (&ScopeInfo, InternalPath, ACPI_TYPE_ANY,
206 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
207 &Node);
208
209 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
210
211 if (ACPI_FAILURE (Status))
212 {
213 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object [%s] not found [%s]\n",
214 Pathname, AcpiFormatException (Status)));
215 goto Cleanup;
216 }
217
218 /*
219 * Now that we have a handle to the object, we can attempt
220 * to evaluate it.
221 */
222 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
223 Pathname, Node, AcpiNsGetAttachedObject (Node)));
224
225 Status = AcpiNsEvaluateByHandle (Node, Params, ReturnObject);
226
227 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
228 Pathname));
229
230Cleanup:
231
232 ACPI_MEM_FREE (InternalPath);
233 return_ACPI_STATUS (Status);
234}
235
236
237/*******************************************************************************
238 *
239 * FUNCTION: AcpiNsEvaluateByName
240 *
241 * PARAMETERS: Pathname - Fully qualified pathname to the object
242 * ReturnObject - Where to put method's return value (if
243 * any). If NULL, no value is returned.
244 * Params - List of parameters to pass to the method,
245 * terminated by NULL. Params itself may be
246 * NULL if no parameters are being passed.
247 *
248 * RETURN: Status
249 *
250 * DESCRIPTION: Find and execute the requested method passing the given
251 * parameters
252 *
253 * MUTEX: Locks Namespace
254 *
255 ******************************************************************************/
256
257ACPI_STATUS
258AcpiNsEvaluateByName (
259 char *Pathname,
260 ACPI_OPERAND_OBJECT **Params,
261 ACPI_OPERAND_OBJECT **ReturnObject)
262{
263 ACPI_STATUS Status;
264 ACPI_NAMESPACE_NODE *Node = NULL;
265 char *InternalPath = NULL;
266
267
268 ACPI_FUNCTION_TRACE ("NsEvaluateByName");
269
270
271 /* Build an internal name string for the method */
272
273 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
274 if (ACPI_FAILURE (Status))
275 {
276 return_ACPI_STATUS (Status);
277 }
278
279 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
280 if (ACPI_FAILURE (Status))
281 {
282 return_ACPI_STATUS (Status);
282 goto Cleanup;
283 }
284
285 /* Lookup the name in the namespace */
286
287 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY,
288 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
289 &Node);
290
291 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
292
293 if (ACPI_FAILURE (Status))
294 {
295 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object at [%s] was not found, status=%.4X\n",
296 Pathname, Status));
297 goto Cleanup;
298 }
299
300 /*
301 * Now that we have a handle to the object, we can attempt
302 * to evaluate it.
303 */
304 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
305 Pathname, Node, AcpiNsGetAttachedObject (Node)));
306
307 Status = AcpiNsEvaluateByHandle (Node, Params, ReturnObject);
308
309 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
310 Pathname));
311
312
313Cleanup:
314
315 /* Cleanup */
316
317 if (InternalPath)
318 {
319 ACPI_MEM_FREE (InternalPath);
320 }
321
322 return_ACPI_STATUS (Status);
323}
324
325
326/*******************************************************************************
327 *
328 * FUNCTION: AcpiNsEvaluateByHandle
329 *
330 * PARAMETERS: Handle - Method Node to execute
331 * Params - List of parameters to pass to the method,
332 * terminated by NULL. Params itself may be
333 * NULL if no parameters are being passed.
334 * ReturnObject - Where to put method's return value (if
335 * any). If NULL, no value is returned.
336 *
337 * RETURN: Status
338 *
339 * DESCRIPTION: Execute the requested method passing the given parameters
340 *
341 * MUTEX: Locks Namespace
342 *
343 ******************************************************************************/
344
345ACPI_STATUS
346AcpiNsEvaluateByHandle (
347 ACPI_NAMESPACE_NODE *Handle,
348 ACPI_OPERAND_OBJECT **Params,
349 ACPI_OPERAND_OBJECT **ReturnObject)
350{
351 ACPI_NAMESPACE_NODE *Node;
352 ACPI_STATUS Status;
353 ACPI_OPERAND_OBJECT *LocalReturnObject;
354
355
356 ACPI_FUNCTION_TRACE ("NsEvaluateByHandle");
357
358
359 /* Check if namespace has been initialized */
360
361 if (!AcpiGbl_RootNode)
362 {
363 return_ACPI_STATUS (AE_NO_NAMESPACE);
364 }
365
366 /* Parameter Validation */
367
368 if (!Handle)
369 {
370 return_ACPI_STATUS (AE_BAD_PARAMETER);
371 }
372
373 if (ReturnObject)
374 {
375 /* Initialize the return value to an invalid object */
376
377 *ReturnObject = NULL;
378 }
379
380 /* Get the prefix handle and Node */
381
382 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
383 if (ACPI_FAILURE (Status))
384 {
385 return_ACPI_STATUS (Status);
386 }
387
388 Node = AcpiNsMapHandleToNode (Handle);
389 if (!Node)
390 {
391 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
392 return_ACPI_STATUS (AE_BAD_PARAMETER);
393 }
394
395 /*
396 * Two major cases here:
397 * 1) The object is an actual control method -- execute it.
398 * 2) The object is not a method -- just return it's current
399 * value
400 *
401 * In both cases, the namespace is unlocked by the
402 * AcpiNs* procedure
403 */
404 if (AcpiNsGetType (Node) == ACPI_TYPE_METHOD)
405 {
406 /*
407 * Case 1) We have an actual control method to execute
408 */
409 Status = AcpiNsExecuteControlMethod (Node, Params,
410 &LocalReturnObject);
411 }
412 else
413 {
414 /*
415 * Case 2) Object is NOT a method, just return its
416 * current value
417 */
418 Status = AcpiNsGetObjectValue (Node, &LocalReturnObject);
419 }
420
421 /*
422 * Check if there is a return value on the stack that must
423 * be dealt with
424 */
425 if (Status == AE_CTRL_RETURN_VALUE)
426 {
427 /*
428 * If the Method returned a value and the caller
429 * provided a place to store a returned value, Copy
430 * the returned value to the object descriptor provided
431 * by the caller.
432 */
433 if (ReturnObject)
434 {
435 /*
436 * Valid return object, copy the pointer to
437 * the returned object
438 */
439 *ReturnObject = LocalReturnObject;
440 }
441
442 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
443
444 Status = AE_OK;
445 }
446
447 /*
448 * Namespace was unlocked by the handling AcpiNs* function,
449 * so we just return
450 */
451 return_ACPI_STATUS (Status);
452}
453
454
455/*******************************************************************************
456 *
457 * FUNCTION: AcpiNsExecuteControlMethod
458 *
459 * PARAMETERS: MethodNode - The method to execute
460 * Params - List of parameters to pass to the method,
461 * terminated by NULL. Params itself may be
462 * NULL if no parameters are being passed.
463 * ReturnObjDesc - List of result objects to be returned
464 * from the method.
465 *
466 * RETURN: Status
467 *
468 * DESCRIPTION: Execute the requested method passing the given parameters
469 *
470 * MUTEX: Assumes namespace is locked
471 *
472 ******************************************************************************/
473
474ACPI_STATUS
475AcpiNsExecuteControlMethod (
476 ACPI_NAMESPACE_NODE *MethodNode,
477 ACPI_OPERAND_OBJECT **Params,
478 ACPI_OPERAND_OBJECT **ReturnObjDesc)
479{
480 ACPI_STATUS Status;
481 ACPI_OPERAND_OBJECT *ObjDesc;
482
483
484 ACPI_FUNCTION_TRACE ("NsExecuteControlMethod");
485
486
487 /* Verify that there is a method associated with this object */
488
489 ObjDesc = AcpiNsGetAttachedObject (MethodNode);
490 if (!ObjDesc)
491 {
492 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No attached method object\n"));
493
494 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
495 return_ACPI_STATUS (AE_NULL_OBJECT);
496 }
497
498 ACPI_DUMP_PATHNAME (MethodNode, "Execute Method:",
499 ACPI_LV_INFO, _COMPONENT);
500
501 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Method at AML address %p Length %X\n",
502 ObjDesc->Method.AmlStart + 1, ObjDesc->Method.AmlLength - 1));
503
504 /*
505 * Unlock the namespace before execution. This allows namespace access
506 * via the external Acpi* interfaces while a method is being executed.
507 * However, any namespace deletion must acquire both the namespace and
508 * interpreter locks to ensure that no thread is using the portion of the
509 * namespace that is being deleted.
510 */
511 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
512 if (ACPI_FAILURE (Status))
513 {
514 return_ACPI_STATUS (Status);
515 }
516
517 /*
518 * Execute the method via the interpreter. The interpreter is locked
519 * here before calling into the AML parser
520 */
521 Status = AcpiExEnterInterpreter ();
522 if (ACPI_FAILURE (Status))
523 {
524 return_ACPI_STATUS (Status);
525 }
526
527 Status = AcpiPsxExecute (MethodNode, Params, ReturnObjDesc);
528 AcpiExExitInterpreter ();
529
530 return_ACPI_STATUS (Status);
531}
532
533
534/*******************************************************************************
535 *
536 * FUNCTION: AcpiNsGetObjectValue
537 *
538 * PARAMETERS: Node - The object
539 * ReturnObjDesc - Where the objects value is returned
540 *
541 * RETURN: Status
542 *
543 * DESCRIPTION: Return the current value of the object
544 *
545 * MUTEX: Assumes namespace is locked, leaves namespace unlocked
546 *
547 ******************************************************************************/
548
549ACPI_STATUS
550AcpiNsGetObjectValue (
551 ACPI_NAMESPACE_NODE *Node,
552 ACPI_OPERAND_OBJECT **ReturnObjDesc)
553{
554 ACPI_STATUS Status = AE_OK;
555 ACPI_NAMESPACE_NODE *ResolvedNode = Node;
556
557
558 ACPI_FUNCTION_TRACE ("NsGetObjectValue");
559
560
561 /*
562 * Objects require additional resolution steps (e.g., the
563 * Node may be a field that must be read, etc.) -- we can't just grab
564 * the object out of the node.
565 */
566
567 /*
568 * Use ResolveNodeToValue() to get the associated value. This call
569 * always deletes ObjDesc (allocated above).
570 *
571 * NOTE: we can get away with passing in NULL for a walk state
572 * because ObjDesc is guaranteed to not be a reference to either
573 * a method local or a method argument (because this interface can only be
574 * called from the AcpiEvaluate external interface, never called from
575 * a running control method.)
576 *
577 * Even though we do not directly invoke the interpreter
578 * for this, we must enter it because we could access an opregion.
579 * The opregion access code assumes that the interpreter
580 * is locked.
581 *
582 * We must release the namespace lock before entering the
583 * intepreter.
584 */
585 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
586 if (ACPI_FAILURE (Status))
587 {
588 return_ACPI_STATUS (Status);
589 }
590
591 Status = AcpiExEnterInterpreter ();
592 if (ACPI_SUCCESS (Status))
593 {
594 Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
595 /*
596 * If AcpiExResolveNodeToValue() succeeded, the return value was
597 * placed in ResolvedNode.
598 */
599 AcpiExExitInterpreter ();
600
601 if (ACPI_SUCCESS (Status))
602 {
603 Status = AE_CTRL_RETURN_VALUE;
604 *ReturnObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ResolvedNode);
605 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
606 *ReturnObjDesc, AcpiUtGetObjectTypeName (*ReturnObjDesc)));
607 }
608 }
609
610 /* Namespace is unlocked */
611
612 return_ACPI_STATUS (Status);
613}
614
283 }
284
285 /* Lookup the name in the namespace */
286
287 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY,
288 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
289 &Node);
290
291 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
292
293 if (ACPI_FAILURE (Status))
294 {
295 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object at [%s] was not found, status=%.4X\n",
296 Pathname, Status));
297 goto Cleanup;
298 }
299
300 /*
301 * Now that we have a handle to the object, we can attempt
302 * to evaluate it.
303 */
304 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
305 Pathname, Node, AcpiNsGetAttachedObject (Node)));
306
307 Status = AcpiNsEvaluateByHandle (Node, Params, ReturnObject);
308
309 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
310 Pathname));
311
312
313Cleanup:
314
315 /* Cleanup */
316
317 if (InternalPath)
318 {
319 ACPI_MEM_FREE (InternalPath);
320 }
321
322 return_ACPI_STATUS (Status);
323}
324
325
326/*******************************************************************************
327 *
328 * FUNCTION: AcpiNsEvaluateByHandle
329 *
330 * PARAMETERS: Handle - Method Node to execute
331 * Params - List of parameters to pass to the method,
332 * terminated by NULL. Params itself may be
333 * NULL if no parameters are being passed.
334 * ReturnObject - Where to put method's return value (if
335 * any). If NULL, no value is returned.
336 *
337 * RETURN: Status
338 *
339 * DESCRIPTION: Execute the requested method passing the given parameters
340 *
341 * MUTEX: Locks Namespace
342 *
343 ******************************************************************************/
344
345ACPI_STATUS
346AcpiNsEvaluateByHandle (
347 ACPI_NAMESPACE_NODE *Handle,
348 ACPI_OPERAND_OBJECT **Params,
349 ACPI_OPERAND_OBJECT **ReturnObject)
350{
351 ACPI_NAMESPACE_NODE *Node;
352 ACPI_STATUS Status;
353 ACPI_OPERAND_OBJECT *LocalReturnObject;
354
355
356 ACPI_FUNCTION_TRACE ("NsEvaluateByHandle");
357
358
359 /* Check if namespace has been initialized */
360
361 if (!AcpiGbl_RootNode)
362 {
363 return_ACPI_STATUS (AE_NO_NAMESPACE);
364 }
365
366 /* Parameter Validation */
367
368 if (!Handle)
369 {
370 return_ACPI_STATUS (AE_BAD_PARAMETER);
371 }
372
373 if (ReturnObject)
374 {
375 /* Initialize the return value to an invalid object */
376
377 *ReturnObject = NULL;
378 }
379
380 /* Get the prefix handle and Node */
381
382 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
383 if (ACPI_FAILURE (Status))
384 {
385 return_ACPI_STATUS (Status);
386 }
387
388 Node = AcpiNsMapHandleToNode (Handle);
389 if (!Node)
390 {
391 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
392 return_ACPI_STATUS (AE_BAD_PARAMETER);
393 }
394
395 /*
396 * Two major cases here:
397 * 1) The object is an actual control method -- execute it.
398 * 2) The object is not a method -- just return it's current
399 * value
400 *
401 * In both cases, the namespace is unlocked by the
402 * AcpiNs* procedure
403 */
404 if (AcpiNsGetType (Node) == ACPI_TYPE_METHOD)
405 {
406 /*
407 * Case 1) We have an actual control method to execute
408 */
409 Status = AcpiNsExecuteControlMethod (Node, Params,
410 &LocalReturnObject);
411 }
412 else
413 {
414 /*
415 * Case 2) Object is NOT a method, just return its
416 * current value
417 */
418 Status = AcpiNsGetObjectValue (Node, &LocalReturnObject);
419 }
420
421 /*
422 * Check if there is a return value on the stack that must
423 * be dealt with
424 */
425 if (Status == AE_CTRL_RETURN_VALUE)
426 {
427 /*
428 * If the Method returned a value and the caller
429 * provided a place to store a returned value, Copy
430 * the returned value to the object descriptor provided
431 * by the caller.
432 */
433 if (ReturnObject)
434 {
435 /*
436 * Valid return object, copy the pointer to
437 * the returned object
438 */
439 *ReturnObject = LocalReturnObject;
440 }
441
442 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
443
444 Status = AE_OK;
445 }
446
447 /*
448 * Namespace was unlocked by the handling AcpiNs* function,
449 * so we just return
450 */
451 return_ACPI_STATUS (Status);
452}
453
454
455/*******************************************************************************
456 *
457 * FUNCTION: AcpiNsExecuteControlMethod
458 *
459 * PARAMETERS: MethodNode - The method to execute
460 * Params - List of parameters to pass to the method,
461 * terminated by NULL. Params itself may be
462 * NULL if no parameters are being passed.
463 * ReturnObjDesc - List of result objects to be returned
464 * from the method.
465 *
466 * RETURN: Status
467 *
468 * DESCRIPTION: Execute the requested method passing the given parameters
469 *
470 * MUTEX: Assumes namespace is locked
471 *
472 ******************************************************************************/
473
474ACPI_STATUS
475AcpiNsExecuteControlMethod (
476 ACPI_NAMESPACE_NODE *MethodNode,
477 ACPI_OPERAND_OBJECT **Params,
478 ACPI_OPERAND_OBJECT **ReturnObjDesc)
479{
480 ACPI_STATUS Status;
481 ACPI_OPERAND_OBJECT *ObjDesc;
482
483
484 ACPI_FUNCTION_TRACE ("NsExecuteControlMethod");
485
486
487 /* Verify that there is a method associated with this object */
488
489 ObjDesc = AcpiNsGetAttachedObject (MethodNode);
490 if (!ObjDesc)
491 {
492 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No attached method object\n"));
493
494 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
495 return_ACPI_STATUS (AE_NULL_OBJECT);
496 }
497
498 ACPI_DUMP_PATHNAME (MethodNode, "Execute Method:",
499 ACPI_LV_INFO, _COMPONENT);
500
501 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Method at AML address %p Length %X\n",
502 ObjDesc->Method.AmlStart + 1, ObjDesc->Method.AmlLength - 1));
503
504 /*
505 * Unlock the namespace before execution. This allows namespace access
506 * via the external Acpi* interfaces while a method is being executed.
507 * However, any namespace deletion must acquire both the namespace and
508 * interpreter locks to ensure that no thread is using the portion of the
509 * namespace that is being deleted.
510 */
511 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
512 if (ACPI_FAILURE (Status))
513 {
514 return_ACPI_STATUS (Status);
515 }
516
517 /*
518 * Execute the method via the interpreter. The interpreter is locked
519 * here before calling into the AML parser
520 */
521 Status = AcpiExEnterInterpreter ();
522 if (ACPI_FAILURE (Status))
523 {
524 return_ACPI_STATUS (Status);
525 }
526
527 Status = AcpiPsxExecute (MethodNode, Params, ReturnObjDesc);
528 AcpiExExitInterpreter ();
529
530 return_ACPI_STATUS (Status);
531}
532
533
534/*******************************************************************************
535 *
536 * FUNCTION: AcpiNsGetObjectValue
537 *
538 * PARAMETERS: Node - The object
539 * ReturnObjDesc - Where the objects value is returned
540 *
541 * RETURN: Status
542 *
543 * DESCRIPTION: Return the current value of the object
544 *
545 * MUTEX: Assumes namespace is locked, leaves namespace unlocked
546 *
547 ******************************************************************************/
548
549ACPI_STATUS
550AcpiNsGetObjectValue (
551 ACPI_NAMESPACE_NODE *Node,
552 ACPI_OPERAND_OBJECT **ReturnObjDesc)
553{
554 ACPI_STATUS Status = AE_OK;
555 ACPI_NAMESPACE_NODE *ResolvedNode = Node;
556
557
558 ACPI_FUNCTION_TRACE ("NsGetObjectValue");
559
560
561 /*
562 * Objects require additional resolution steps (e.g., the
563 * Node may be a field that must be read, etc.) -- we can't just grab
564 * the object out of the node.
565 */
566
567 /*
568 * Use ResolveNodeToValue() to get the associated value. This call
569 * always deletes ObjDesc (allocated above).
570 *
571 * NOTE: we can get away with passing in NULL for a walk state
572 * because ObjDesc is guaranteed to not be a reference to either
573 * a method local or a method argument (because this interface can only be
574 * called from the AcpiEvaluate external interface, never called from
575 * a running control method.)
576 *
577 * Even though we do not directly invoke the interpreter
578 * for this, we must enter it because we could access an opregion.
579 * The opregion access code assumes that the interpreter
580 * is locked.
581 *
582 * We must release the namespace lock before entering the
583 * intepreter.
584 */
585 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
586 if (ACPI_FAILURE (Status))
587 {
588 return_ACPI_STATUS (Status);
589 }
590
591 Status = AcpiExEnterInterpreter ();
592 if (ACPI_SUCCESS (Status))
593 {
594 Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
595 /*
596 * If AcpiExResolveNodeToValue() succeeded, the return value was
597 * placed in ResolvedNode.
598 */
599 AcpiExExitInterpreter ();
600
601 if (ACPI_SUCCESS (Status))
602 {
603 Status = AE_CTRL_RETURN_VALUE;
604 *ReturnObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ResolvedNode);
605 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
606 *ReturnObjDesc, AcpiUtGetObjectTypeName (*ReturnObjDesc)));
607 }
608 }
609
610 /* Namespace is unlocked */
611
612 return_ACPI_STATUS (Status);
613}
614