Deleted Added
sdiff udiff text old ( 138287 ) new ( 151600 )
full compact
1/*******************************************************************************
2 *
3 * Module Name: nseval - Object evaluation interfaces -- includes control
4 * method lookup and execution.
5 * $Revision: 129 $
6 *
7 ******************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
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: Pathname - Name of method to execute, If NULL, the
136 * handle is the object to execute
137 * Info - Method info block
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: Find and execute the requested method using the handle as a
142 * scope
143 *
144 * MUTEX: Locks Namespace
145 *
146 ******************************************************************************/
147
148ACPI_STATUS
149AcpiNsEvaluateRelative (
150 char *Pathname,
151 ACPI_PARAMETER_INFO *Info)
152{
153 ACPI_STATUS Status;
154 ACPI_NAMESPACE_NODE *Node = NULL;
155 ACPI_GENERIC_STATE *ScopeInfo;
156 char *InternalPath = NULL;
157
158
159 ACPI_FUNCTION_TRACE ("NsEvaluateRelative");
160
161
162 /*
163 * Must have a valid object handle
164 */
165 if (!Info || !Info->Node)
166 {
167 return_ACPI_STATUS (AE_BAD_PARAMETER);
168 }
169
170 /* Build an internal name string for the method */
171
172 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
173 if (ACPI_FAILURE (Status))
174 {
175 return_ACPI_STATUS (Status);
176 }
177
178 ScopeInfo = AcpiUtCreateGenericState ();
179 if (!ScopeInfo)
180 {
181 goto Cleanup1;
182 }
183
184 /* Get the prefix handle and Node */
185
186 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
187 if (ACPI_FAILURE (Status))
188 {
189 goto Cleanup;
190 }
191
192 Info->Node = AcpiNsMapHandleToNode (Info->Node);
193 if (!Info->Node)
194 {
195 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
196 Status = AE_BAD_PARAMETER;
197 goto Cleanup;
198 }
199
200 /* Lookup the name in the namespace */
201
202 ScopeInfo->Scope.Node = Info->Node;
203 Status = AcpiNsLookup (ScopeInfo, InternalPath, ACPI_TYPE_ANY,
204 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
205 &Node);
206
207 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
208
209 if (ACPI_FAILURE (Status))
210 {
211 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object [%s] not found [%s]\n",
212 Pathname, AcpiFormatException (Status)));
213 goto Cleanup;
214 }
215
216 /*
217 * Now that we have a handle to the object, we can attempt to evaluate it.
218 */
219 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
220 Pathname, Node, AcpiNsGetAttachedObject (Node)));
221
222 Info->Node = Node;
223 Status = AcpiNsEvaluateByHandle (Info);
224
225 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
226 Pathname));
227
228Cleanup:
229 AcpiUtDeleteGenericState (ScopeInfo);
230
231Cleanup1:
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 * Info - Contains:
243 * ReturnObject - Where to put method's return value (if
244 * any). If NULL, no value is returned.
245 * Params - List of parameters to pass to the method,
246 * terminated by NULL. Params itself may be
247 * NULL if no parameters are being passed.
248 *
249 * RETURN: Status
250 *
251 * DESCRIPTION: Find and execute the requested method passing the given
252 * parameters
253 *
254 * MUTEX: Locks Namespace
255 *
256 ******************************************************************************/
257
258ACPI_STATUS
259AcpiNsEvaluateByName (
260 char *Pathname,
261 ACPI_PARAMETER_INFO *Info)
262{
263 ACPI_STATUS Status;
264 char *InternalPath = NULL;
265
266
267 ACPI_FUNCTION_TRACE ("NsEvaluateByName");
268
269
270 /* Build an internal name string for the method */
271
272 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
273 if (ACPI_FAILURE (Status))
274 {
275 return_ACPI_STATUS (Status);
276 }
277
278 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
279 if (ACPI_FAILURE (Status))
280 {
281 goto Cleanup;
282 }
283
284 /* Lookup the name in the namespace */
285
286 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY,
287 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
288 &Info->Node);
289
290 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
291
292 if (ACPI_FAILURE (Status))
293 {
294 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
295 "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 to evaluate it.
302 */
303 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
304 Pathname, Info->Node, AcpiNsGetAttachedObject (Info->Node)));
305
306 Status = AcpiNsEvaluateByHandle (Info);
307
308 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
309 Pathname));
310
311
312Cleanup:
313
314 /* Cleanup */
315
316 if (InternalPath)
317 {
318 ACPI_MEM_FREE (InternalPath);
319 }
320
321 return_ACPI_STATUS (Status);
322}
323
324
325/*******************************************************************************
326 *
327 * FUNCTION: AcpiNsEvaluateByHandle
328 *
329 * PARAMETERS: Handle - Method Node to execute
330 * Params - List of parameters to pass to the method,
331 * terminated by NULL. Params itself may be
332 * NULL if no parameters are being passed.
333 * ParamType - Type of Parameter list
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_PARAMETER_INFO *Info)
348{
349 ACPI_STATUS Status;
350
351
352 ACPI_FUNCTION_TRACE ("NsEvaluateByHandle");
353
354
355 /* Check if namespace has been initialized */
356
357 if (!AcpiGbl_RootNode)
358 {
359 return_ACPI_STATUS (AE_NO_NAMESPACE);
360 }
361
362 /* Parameter Validation */
363
364 if (!Info)
365 {
366 return_ACPI_STATUS (AE_BAD_PARAMETER);
367 }
368
369 /* Initialize the return value to an invalid object */
370
371 Info->ReturnObject = NULL;
372
373 /* Get the prefix handle and Node */
374
375 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
376 if (ACPI_FAILURE (Status))
377 {
378 return_ACPI_STATUS (Status);
379 }
380
381 Info->Node = AcpiNsMapHandleToNode (Info->Node);
382 if (!Info->Node)
383 {
384 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
385 return_ACPI_STATUS (AE_BAD_PARAMETER);
386 }
387
388 /*
389 * For a method alias, we must grab the actual method node so that proper
390 * scoping context will be established before execution.
391 */
392 if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
393 {
394 Info->Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->Node->Object);
395 }
396
397 /*
398 * Two major cases here:
399 * 1) The object is an actual control method -- execute it.
400 * 2) The object is not a method -- just return it's current value
401 *
402 * In both cases, the namespace is unlocked by the AcpiNs* procedure
403 */
404 if (AcpiNsGetType (Info->Node) == ACPI_TYPE_METHOD)
405 {
406 /*
407 * Case 1) We have an actual control method to execute
408 */
409 Status = AcpiNsExecuteControlMethod (Info);
410 }
411 else
412 {
413 /*
414 * Case 2) Object is NOT a method, just return its current value
415 */
416 Status = AcpiNsGetObjectValue (Info);
417 }
418
419 /*
420 * Check if there is a return value on the stack that must be dealt with
421 */
422 if (Status == AE_CTRL_RETURN_VALUE)
423 {
424 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
425
426 Status = AE_OK;
427 }
428
429 /*
430 * Namespace was unlocked by the handling AcpiNs* function, so we
431 * just return
432 */
433 return_ACPI_STATUS (Status);
434}
435
436
437/*******************************************************************************
438 *
439 * FUNCTION: AcpiNsExecuteControlMethod
440 *
441 * PARAMETERS: Info - Method info block (w/params)
442 *
443 * RETURN: Status
444 *
445 * DESCRIPTION: Execute the requested method passing the given parameters
446 *
447 * MUTEX: Assumes namespace is locked
448 *
449 ******************************************************************************/
450
451ACPI_STATUS
452AcpiNsExecuteControlMethod (
453 ACPI_PARAMETER_INFO *Info)
454{
455 ACPI_STATUS Status;
456 ACPI_OPERAND_OBJECT *ObjDesc;
457
458
459 ACPI_FUNCTION_TRACE ("NsExecuteControlMethod");
460
461
462 /* Verify that there is a method associated with this object */
463
464 ObjDesc = AcpiNsGetAttachedObject (Info->Node);
465 if (!ObjDesc)
466 {
467 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No attached method object\n"));
468
469 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
470 return_ACPI_STATUS (AE_NULL_OBJECT);
471 }
472
473 ACPI_DUMP_PATHNAME (Info->Node, "Execute Method:",
474 ACPI_LV_INFO, _COMPONENT);
475
476 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Method at AML address %p Length %X\n",
477 ObjDesc->Method.AmlStart + 1, ObjDesc->Method.AmlLength - 1));
478
479 /*
480 * Unlock the namespace before execution. This allows namespace access
481 * via the external Acpi* interfaces while a method is being executed.
482 * However, any namespace deletion must acquire both the namespace and
483 * interpreter locks to ensure that no thread is using the portion of the
484 * namespace that is being deleted.
485 */
486 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
487 if (ACPI_FAILURE (Status))
488 {
489 return_ACPI_STATUS (Status);
490 }
491
492 /*
493 * Execute the method via the interpreter. The interpreter is locked
494 * here before calling into the AML parser
495 */
496 Status = AcpiExEnterInterpreter ();
497 if (ACPI_FAILURE (Status))
498 {
499 return_ACPI_STATUS (Status);
500 }
501
502 Status = AcpiPsxExecute (Info);
503 AcpiExExitInterpreter ();
504
505 return_ACPI_STATUS (Status);
506}
507
508
509/*******************************************************************************
510 *
511 * FUNCTION: AcpiNsGetObjectValue
512 *
513 * PARAMETERS: Info - Method info block (w/params)
514 *
515 * RETURN: Status
516 *
517 * DESCRIPTION: Return the current value of the object
518 *
519 * MUTEX: Assumes namespace is locked, leaves namespace unlocked
520 *
521 ******************************************************************************/
522
523ACPI_STATUS
524AcpiNsGetObjectValue (
525 ACPI_PARAMETER_INFO *Info)
526{
527 ACPI_STATUS Status = AE_OK;
528 ACPI_NAMESPACE_NODE *ResolvedNode = Info->Node;
529
530
531 ACPI_FUNCTION_TRACE ("NsGetObjectValue");
532
533
534 /*
535 * Objects require additional resolution steps (e.g., the Node may be a
536 * field that must be read, etc.) -- we can't just grab the object out of
537 * the node.
538 */
539
540 /*
541 * Use ResolveNodeToValue() to get the associated value. This call always
542 * deletes ObjDesc (allocated above).
543 *
544 * NOTE: we can get away with passing in NULL for a walk state because
545 * ObjDesc is guaranteed to not be a reference to either a method local or
546 * a method argument (because this interface can only be called from the
547 * AcpiEvaluate external interface, never called from a running method.)
548 *
549 * Even though we do not directly invoke the interpreter for this, we must
550 * enter it because we could access an opregion. The opregion access code
551 * assumes that the interpreter is locked.
552 *
553 * We must release the namespace lock before entering the intepreter.
554 */
555 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
556 if (ACPI_FAILURE (Status))
557 {
558 return_ACPI_STATUS (Status);
559 }
560
561 Status = AcpiExEnterInterpreter ();
562 if (ACPI_SUCCESS (Status))
563 {
564 Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
565 /*
566 * If AcpiExResolveNodeToValue() succeeded, the return value was placed
567 * in ResolvedNode.
568 */
569 AcpiExExitInterpreter ();
570
571 if (ACPI_SUCCESS (Status))
572 {
573 Status = AE_CTRL_RETURN_VALUE;
574 Info->ReturnObject = ACPI_CAST_PTR
575 (ACPI_OPERAND_OBJECT, ResolvedNode);
576 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
577 Info->ReturnObject,
578 AcpiUtGetObjectTypeName (Info->ReturnObject)));
579 }
580 }
581
582 /* Namespace is unlocked */
583
584 return_ACPI_STATUS (Status);
585}
586