Deleted Added
sdiff udiff text old ( 100966 ) new ( 104470 )
full compact
1/*******************************************************************************
2 *
3 * Module Name: dsutils - Dispatcher utilities
4 * $Revision: 94 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
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 __DSUTILS_C__
118
119#include "acpi.h"
120#include "acparser.h"
121#include "amlcode.h"
122#include "acdispat.h"
123#include "acinterp.h"
124#include "acnamesp.h"
125#include "acdebug.h"
126
127#define _COMPONENT ACPI_DISPATCHER
128 ACPI_MODULE_NAME ("dsutils")
129
130#ifndef ACPI_NO_METHOD_EXECUTION
131
132/*******************************************************************************
133 *
134 * FUNCTION: AcpiDsIsResultUsed
135 *
136 * PARAMETERS: Op
137 * ResultObj
138 * WalkState
139 *
140 * RETURN: Status
141 *
142 * DESCRIPTION: Check if a result object will be used by the parent
143 *
144 ******************************************************************************/
145
146BOOLEAN
147AcpiDsIsResultUsed (
148 ACPI_PARSE_OBJECT *Op,
149 ACPI_WALK_STATE *WalkState)
150{
151 const ACPI_OPCODE_INFO *ParentInfo;
152
153
154 ACPI_FUNCTION_TRACE_PTR ("DsIsResultUsed", Op);
155
156
157 /* Must have both an Op and a Result Object */
158
159 if (!Op)
160 {
161 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Op\n"));
162 return_VALUE (TRUE);
163 }
164
165 /*
166 * If there is no parent, the result can't possibly be used!
167 * (An executing method typically has no parent, since each
168 * method is parsed separately) However, a method that is
169 * invoked from another method has a parent.
170 */
171 if (!Op->Common.Parent)
172 {
173 return_VALUE (FALSE);
174 }
175
176 /*
177 * Get info on the parent. The root Op is AML_SCOPE
178 */
179 ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
180 if (ParentInfo->Class == AML_CLASS_UNKNOWN)
181 {
182 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown parent opcode. Op=%p\n", Op));
183 return_VALUE (FALSE);
184 }
185
186 /*
187 * Decide what to do with the result based on the parent. If
188 * the parent opcode will not use the result, delete the object.
189 * Otherwise leave it as is, it will be deleted when it is used
190 * as an operand later.
191 */
192 switch (ParentInfo->Class)
193 {
194 case AML_CLASS_CONTROL:
195
196 switch (Op->Common.Parent->Common.AmlOpcode)
197 {
198 case AML_RETURN_OP:
199
200 /* Never delete the return value associated with a return opcode */
201
202 goto ResultUsed;
203
204 case AML_IF_OP:
205 case AML_WHILE_OP:
206
207 /*
208 * If we are executing the predicate AND this is the predicate op,
209 * we will use the return value
210 */
211 if ((WalkState->ControlState->Common.State == ACPI_CONTROL_PREDICATE_EXECUTING) &&
212 (WalkState->ControlState->Control.PredicateOp == Op))
213 {
214 goto ResultUsed;
215 }
216 break;
217
218 default:
219 /* Ignore other control opcodes */
220 break;
221 }
222
223 /* The general control opcode returns no result */
224
225 goto ResultNotUsed;
226
227
228 case AML_CLASS_CREATE:
229
230 /*
231 * These opcodes allow TermArg(s) as operands and therefore
232 * the operands can be method calls. The result is used.
233 */
234 goto ResultUsed;
235
236
237 case AML_CLASS_NAMED_OBJECT:
238
239 if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP) ||
240 (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP) ||
241 (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
242 (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP) ||
243 (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP) ||
244 (Op->Common.Parent->Common.AmlOpcode == AML_INT_EVAL_SUBTREE_OP))
245 {
246 /*
247 * These opcodes allow TermArg(s) as operands and therefore
248 * the operands can be method calls. The result is used.
249 */
250 goto ResultUsed;
251 }
252
253 goto ResultNotUsed;
254
255
256 default:
257
258 /*
259 * In all other cases. the parent will actually use the return
260 * object, so keep it.
261 */
262 goto ResultUsed;
263 }
264
265
266ResultUsed:
267 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Result of [%s] used by Parent [%s] Op=%p\n",
268 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
269 AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
270
271 return_VALUE (TRUE);
272
273
274ResultNotUsed:
275 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Result of [%s] not used by Parent [%s] Op=%p\n",
276 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
277 AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
278
279 return_VALUE (FALSE);
280
281}
282
283
284/*******************************************************************************
285 *
286 * FUNCTION: AcpiDsDeleteResultIfNotUsed
287 *
288 * PARAMETERS: Op
289 * ResultObj
290 * WalkState
291 *
292 * RETURN: Status
293 *
294 * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
295 * result descriptor, check if the parent opcode will actually use
296 * this result. If not, delete the result now so that it will
297 * not become orphaned.
298 *
299 ******************************************************************************/
300
301void
302AcpiDsDeleteResultIfNotUsed (
303 ACPI_PARSE_OBJECT *Op,
304 ACPI_OPERAND_OBJECT *ResultObj,
305 ACPI_WALK_STATE *WalkState)
306{
307 ACPI_OPERAND_OBJECT *ObjDesc;
308 ACPI_STATUS Status;
309
310
311 ACPI_FUNCTION_TRACE_PTR ("DsDeleteResultIfNotUsed", ResultObj);
312
313
314 if (!Op)
315 {
316 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Op\n"));
317 return_VOID;
318 }
319
320 if (!ResultObj)
321 {
322 return_VOID;
323 }
324
325
326 if (!AcpiDsIsResultUsed (Op, WalkState))
327 {
328 /*
329 * Must pop the result stack (ObjDesc should be equal to ResultObj)
330 */
331 Status = AcpiDsResultPop (&ObjDesc, WalkState);
332 if (ACPI_SUCCESS (Status))
333 {
334 AcpiUtRemoveReference (ResultObj);
335 }
336 }
337
338 return_VOID;
339}
340
341
342/*******************************************************************************
343 *
344 * FUNCTION: AcpiDsResolveOperands
345 *
346 * PARAMETERS: WalkState - Current walk state with operands on stack
347 *
348 * RETURN: Status
349 *
350 * DESCRIPTION: Resolve all operands to their values. Used to prepare
351 * arguments to a control method invocation (a call from one
352 * method to another.)
353 *
354 ******************************************************************************/
355
356ACPI_STATUS
357AcpiDsResolveOperands (
358 ACPI_WALK_STATE *WalkState)
359{
360 UINT32 i;
361 ACPI_STATUS Status = AE_OK;
362
363
364 ACPI_FUNCTION_TRACE_PTR ("DsResolveOperands", WalkState);
365
366
367 /*
368 * Attempt to resolve each of the valid operands
369 * Method arguments are passed by value, not by reference
370 */
371 for (i = 0; i < WalkState->NumOperands; i++)
372 {
373 Status = AcpiExResolveToValue (&WalkState->Operands[i], WalkState);
374 if (ACPI_FAILURE (Status))
375 {
376 break;
377 }
378 }
379
380 return_ACPI_STATUS (Status);
381}
382#endif
383
384
385/*******************************************************************************
386 *
387 * FUNCTION: AcpiDsCreateOperand
388 *
389 * PARAMETERS: WalkState
390 * Arg
391 *
392 * RETURN: Status
393 *
394 * DESCRIPTION: Translate a parse tree object that is an argument to an AML
395 * opcode to the equivalent interpreter object. This may include
396 * looking up a name or entering a new name into the internal
397 * namespace.
398 *
399 ******************************************************************************/
400
401ACPI_STATUS
402AcpiDsCreateOperand (
403 ACPI_WALK_STATE *WalkState,
404 ACPI_PARSE_OBJECT *Arg,
405 UINT32 ArgIndex)
406{
407 ACPI_STATUS Status = AE_OK;
408 ACPI_STATUS Status2;
409 NATIVE_CHAR *NameString;
410 UINT32 NameLength;
411 ACPI_OPERAND_OBJECT *ObjDesc;
412 ACPI_PARSE_OBJECT *ParentOp;
413 UINT16 Opcode;
414 ACPI_INTERPRETER_MODE InterpreterMode;
415 const ACPI_OPCODE_INFO *OpInfo;
416 char *Name;
417
418
419 ACPI_FUNCTION_TRACE_PTR ("DsCreateOperand", Arg);
420
421
422 /* A valid name must be looked up in the namespace */
423
424 if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
425 (Arg->Common.Value.String))
426 {
427 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg));
428
429 /* Get the entire name string from the AML stream */
430
431 Status = AcpiExGetNameString (ACPI_TYPE_ANY, Arg->Common.Value.Buffer,
432 &NameString, &NameLength);
433
434 if (ACPI_FAILURE (Status))
435 {
436 return_ACPI_STATUS (Status);
437 }
438
439 /*
440 * All prefixes have been handled, and the name is
441 * in NameString
442 */
443
444 /*
445 * Differentiate between a namespace "create" operation
446 * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
447 * IMODE_EXECUTE) in order to support the creation of
448 * namespace objects during the execution of control methods.
449 */
450 ParentOp = Arg->Common.Parent;
451 OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
452 if ((OpInfo->Flags & AML_NSNODE) &&
453 (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
454 (ParentOp->Common.AmlOpcode != AML_REGION_OP) &&
455 (ParentOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
456 {
457 /* Enter name into namespace if not found */
458
459 InterpreterMode = ACPI_IMODE_LOAD_PASS2;
460 }
461
462 else
463 {
464 /* Return a failure if name not found */
465
466 InterpreterMode = ACPI_IMODE_EXECUTE;
467 }
468
469 Status = AcpiNsLookup (WalkState->ScopeInfo, NameString,
470 ACPI_TYPE_ANY, InterpreterMode,
471 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
472 WalkState,
473 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc));
474 /*
475 * The only case where we pass through (ignore) a NOT_FOUND
476 * error is for the CondRefOf opcode.
477 */
478 if (Status == AE_NOT_FOUND)
479 {
480 if (ParentOp->Common.AmlOpcode == AML_COND_REF_OF_OP)
481 {
482 /*
483 * For the Conditional Reference op, it's OK if
484 * the name is not found; We just need a way to
485 * indicate this to the interpreter, set the
486 * object to the root
487 */
488 ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, AcpiGbl_RootNode);
489 Status = AE_OK;
490 }
491
492 else
493 {
494 /*
495 * We just plain didn't find it -- which is a
496 * very serious error at this point
497 */
498 Status = AE_AML_NAME_NOT_FOUND;
499
500 Name = NULL;
501 Status2 = AcpiNsExternalizeName (ACPI_UINT32_MAX, NameString, NULL, &Name);
502 if (ACPI_SUCCESS (Status2))
503 {
504 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
505 "Object name [%s] was not found in namespace\n", Name));
506 ACPI_MEM_FREE (Name);
507 }
508 }
509 }
510
511 /* Free the namestring created above */
512
513 ACPI_MEM_FREE (NameString);
514
515 /* Check status from the lookup */
516
517 if (ACPI_FAILURE (Status))
518 {
519 return_ACPI_STATUS (Status);
520 }
521
522 /* Put the resulting object onto the current object stack */
523
524 Status = AcpiDsObjStackPush (ObjDesc, WalkState);
525 if (ACPI_FAILURE (Status))
526 {
527 return_ACPI_STATUS (Status);
528 }
529 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState));
530 }
531
532
533 else
534 {
535 /* Check for null name case */
536
537 if (Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
538 {
539 /*
540 * If the name is null, this means that this is an
541 * optional result parameter that was not specified
542 * in the original ASL. Create a Zero Constant for a
543 * placeholder. (Store to a constant is a Noop.)
544 */
545 Opcode = AML_ZERO_OP; /* Has no arguments! */
546
547 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Null namepath: Arg=%p\n", Arg));
548 }
549
550 else
551 {
552 Opcode = Arg->Common.AmlOpcode;
553 }
554
555 /* Get the object type of the argument */
556
557 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
558 if (OpInfo->ObjectType == INTERNAL_TYPE_INVALID)
559 {
560 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
561 }
562
563 if (OpInfo->Flags & AML_HAS_RETVAL)
564 {
565 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
566 "Argument previously created, already stacked \n"));
567
568 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (
569 WalkState->Operands [WalkState->NumOperands - 1], WalkState));
570
571 /*
572 * Use value that was already previously returned
573 * by the evaluation of this argument
574 */
575 Status = AcpiDsResultPopFromBottom (&ObjDesc, WalkState);
576 if (ACPI_FAILURE (Status))
577 {
578 /*
579 * Only error is underflow, and this indicates
580 * a missing or null operand!
581 */
582 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Missing or null operand, %s\n",
583 AcpiFormatException (Status)));
584 return_ACPI_STATUS (Status);
585 }
586 }
587 else
588 {
589 /* Create an ACPI_INTERNAL_OBJECT for the argument */
590
591 ObjDesc = AcpiUtCreateInternalObject (OpInfo->ObjectType);
592 if (!ObjDesc)
593 {
594 return_ACPI_STATUS (AE_NO_MEMORY);
595 }
596
597 /* Initialize the new object */
598
599 Status = AcpiDsInitObjectFromOp (WalkState, Arg,
600 Opcode, &ObjDesc);
601 if (ACPI_FAILURE (Status))
602 {
603 AcpiUtDeleteObjectDesc (ObjDesc);
604 return_ACPI_STATUS (Status);
605 }
606 }
607
608 /* Put the operand object on the object stack */
609
610 Status = AcpiDsObjStackPush (ObjDesc, WalkState);
611 if (ACPI_FAILURE (Status))
612 {
613 return_ACPI_STATUS (Status);
614 }
615
616 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState));
617 }
618
619 return_ACPI_STATUS (AE_OK);
620}
621
622
623/*******************************************************************************
624 *
625 * FUNCTION: AcpiDsCreateOperands
626 *
627 * PARAMETERS: FirstArg - First argument of a parser argument tree
628 *
629 * RETURN: Status
630 *
631 * DESCRIPTION: Convert an operator's arguments from a parse tree format to
632 * namespace objects and place those argument object on the object
633 * stack in preparation for evaluation by the interpreter.
634 *
635 ******************************************************************************/
636
637ACPI_STATUS
638AcpiDsCreateOperands (
639 ACPI_WALK_STATE *WalkState,
640 ACPI_PARSE_OBJECT *FirstArg)
641{
642 ACPI_STATUS Status = AE_OK;
643 ACPI_PARSE_OBJECT *Arg;
644 UINT32 ArgCount = 0;
645
646
647 ACPI_FUNCTION_TRACE_PTR ("DsCreateOperands", FirstArg);
648
649
650 /* For all arguments in the list... */
651
652 Arg = FirstArg;
653 while (Arg)
654 {
655 Status = AcpiDsCreateOperand (WalkState, Arg, ArgCount);
656 if (ACPI_FAILURE (Status))
657 {
658 goto Cleanup;
659 }
660
661 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Arg #%d (%p) done, Arg1=%p\n",
662 ArgCount, Arg, FirstArg));
663
664 /* Move on to next argument, if any */
665
666 Arg = Arg->Common.Next;
667 ArgCount++;
668 }
669
670 return_ACPI_STATUS (Status);
671
672
673Cleanup:
674 /*
675 * We must undo everything done above; meaning that we must
676 * pop everything off of the operand stack and delete those
677 * objects
678 */
679 (void) AcpiDsObjStackPopAndDelete (ArgCount, WalkState);
680
681 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "While creating Arg %d - %s\n",
682 (ArgCount + 1), AcpiFormatException (Status)));
683 return_ACPI_STATUS (Status);
684}
685
686