checkdirs() was being passed the wrong mount point, resulting in a panic
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050309 / interpreter / dispatcher / dsopcode.c
blob43c794a26eb42d28307df7ae6ff93b4c77317969
1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
4 * "control" opcodes
5 * $Revision: 98 $
7 *****************************************************************************/
9 /******************************************************************************
11 * 1. Copyright Notice
13 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14 * All rights reserved.
16 * 2. License
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.
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
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;
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
42 * 3. Conditions
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.
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.
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
118 #define __DSOPCODE_C__
120 #include "acpi.h"
121 #include "acparser.h"
122 #include "amlcode.h"
123 #include "acdispat.h"
124 #include "acinterp.h"
125 #include "acnamesp.h"
126 #include "acevents.h"
128 #define _COMPONENT ACPI_DISPATCHER
129 ACPI_MODULE_NAME ("dsopcode")
132 /*****************************************************************************
134 * FUNCTION: AcpiDsExecuteArguments
136 * PARAMETERS: Node - Parent NS node
137 * AmlLength - Length of executable AML
138 * AmlStart - Pointer to the AML
140 * RETURN: Status.
142 * DESCRIPTION: Late (deferred) execution of region or field arguments
144 ****************************************************************************/
146 ACPI_STATUS
147 AcpiDsExecuteArguments (
148 ACPI_NAMESPACE_NODE *Node,
149 ACPI_NAMESPACE_NODE *ScopeNode,
150 UINT32 AmlLength,
151 UINT8 *AmlStart)
153 ACPI_STATUS Status;
154 ACPI_PARSE_OBJECT *Op;
155 ACPI_WALK_STATE *WalkState;
158 ACPI_FUNCTION_TRACE ("DsExecuteArguments");
162 * Allocate a new parser op to be the root of the parsed tree
164 Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
165 if (!Op)
167 return_ACPI_STATUS (AE_NO_MEMORY);
170 /* Save the Node for use in AcpiPsParseAml */
172 Op->Common.Node = ScopeNode;
174 /* Create and initialize a new parser state */
176 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
177 if (!WalkState)
179 return_ACPI_STATUS (AE_NO_MEMORY);
182 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
183 AmlLength, NULL, 1);
184 if (ACPI_FAILURE (Status))
186 AcpiDsDeleteWalkState (WalkState);
187 return_ACPI_STATUS (Status);
190 /* Mark this parse as a deferred opcode */
192 WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;
193 WalkState->DeferredNode = Node;
195 /* Pass1: Parse the entire declaration */
197 Status = AcpiPsParseAml (WalkState);
198 if (ACPI_FAILURE (Status))
200 AcpiPsDeleteParseTree (Op);
201 return_ACPI_STATUS (Status);
204 /* Get and init the Op created above */
206 Op->Common.Node = Node;
207 AcpiPsDeleteParseTree (Op);
209 /* Evaluate the deferred arguments */
211 Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
212 if (!Op)
214 return_ACPI_STATUS (AE_NO_MEMORY);
217 Op->Common.Node = ScopeNode;
219 /* Create and initialize a new parser state */
221 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
222 if (!WalkState)
224 return_ACPI_STATUS (AE_NO_MEMORY);
227 /* Execute the opcode and arguments */
229 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
230 AmlLength, NULL, 3);
231 if (ACPI_FAILURE (Status))
233 AcpiDsDeleteWalkState (WalkState);
234 return_ACPI_STATUS (Status);
237 /* Mark this execution as a deferred opcode */
239 WalkState->DeferredNode = Node;
240 Status = AcpiPsParseAml (WalkState);
241 AcpiPsDeleteParseTree (Op);
242 return_ACPI_STATUS (Status);
246 /*****************************************************************************
248 * FUNCTION: AcpiDsGetBufferFieldArguments
250 * PARAMETERS: ObjDesc - A valid BufferField object
252 * RETURN: Status.
254 * DESCRIPTION: Get BufferField Buffer and Index. This implements the late
255 * evaluation of these field attributes.
257 ****************************************************************************/
259 ACPI_STATUS
260 AcpiDsGetBufferFieldArguments (
261 ACPI_OPERAND_OBJECT *ObjDesc)
263 ACPI_OPERAND_OBJECT *ExtraDesc;
264 ACPI_NAMESPACE_NODE *Node;
265 ACPI_STATUS Status;
268 ACPI_FUNCTION_TRACE_PTR ("DsGetBufferFieldArguments", ObjDesc);
271 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
273 return_ACPI_STATUS (AE_OK);
276 /* Get the AML pointer (method object) and BufferField node */
278 ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
279 Node = ObjDesc->BufferField.Node;
281 ACPI_DEBUG_EXEC(AcpiUtDisplayInitPathname (ACPI_TYPE_BUFFER_FIELD, Node, NULL));
282 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
283 AcpiUtGetNodeName (Node)));
285 /* Execute the AML code for the TermArg arguments */
287 Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
288 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
289 return_ACPI_STATUS (Status);
293 /*****************************************************************************
295 * FUNCTION: AcpiDsGetBufferArguments
297 * PARAMETERS: ObjDesc - A valid Buffer object
299 * RETURN: Status.
301 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
302 * the late evaluation of these attributes.
304 ****************************************************************************/
306 ACPI_STATUS
307 AcpiDsGetBufferArguments (
308 ACPI_OPERAND_OBJECT *ObjDesc)
310 ACPI_NAMESPACE_NODE *Node;
311 ACPI_STATUS Status;
314 ACPI_FUNCTION_TRACE_PTR ("DsGetBufferArguments", ObjDesc);
317 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
319 return_ACPI_STATUS (AE_OK);
322 /* Get the Buffer node */
324 Node = ObjDesc->Buffer.Node;
325 if (!Node)
327 ACPI_REPORT_ERROR ((
328 "No pointer back to NS node in buffer obj %p\n", ObjDesc));
329 return_ACPI_STATUS (AE_AML_INTERNAL);
332 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
334 /* Execute the AML code for the TermArg arguments */
336 Status = AcpiDsExecuteArguments (Node, Node,
337 ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);
338 return_ACPI_STATUS (Status);
342 /*****************************************************************************
344 * FUNCTION: AcpiDsGetPackageArguments
346 * PARAMETERS: ObjDesc - A valid Package object
348 * RETURN: Status.
350 * DESCRIPTION: Get Package length and initializer byte list. This implements
351 * the late evaluation of these attributes.
353 ****************************************************************************/
355 ACPI_STATUS
356 AcpiDsGetPackageArguments (
357 ACPI_OPERAND_OBJECT *ObjDesc)
359 ACPI_NAMESPACE_NODE *Node;
360 ACPI_STATUS Status;
363 ACPI_FUNCTION_TRACE_PTR ("DsGetPackageArguments", ObjDesc);
366 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
368 return_ACPI_STATUS (AE_OK);
371 /* Get the Package node */
373 Node = ObjDesc->Package.Node;
374 if (!Node)
376 ACPI_REPORT_ERROR ((
377 "No pointer back to NS node in package %p\n", ObjDesc));
378 return_ACPI_STATUS (AE_AML_INTERNAL);
381 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
383 /* Execute the AML code for the TermArg arguments */
385 Status = AcpiDsExecuteArguments (Node, Node,
386 ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);
387 return_ACPI_STATUS (Status);
391 /*****************************************************************************
393 * FUNCTION: AcpiDsGetRegionArguments
395 * PARAMETERS: ObjDesc - A valid region object
397 * RETURN: Status.
399 * DESCRIPTION: Get region address and length. This implements the late
400 * evaluation of these region attributes.
402 ****************************************************************************/
404 ACPI_STATUS
405 AcpiDsGetRegionArguments (
406 ACPI_OPERAND_OBJECT *ObjDesc)
408 ACPI_NAMESPACE_NODE *Node;
409 ACPI_STATUS Status;
410 ACPI_OPERAND_OBJECT *ExtraDesc;
413 ACPI_FUNCTION_TRACE_PTR ("DsGetRegionArguments", ObjDesc);
416 if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
418 return_ACPI_STATUS (AE_OK);
421 ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
422 if (!ExtraDesc)
424 return_ACPI_STATUS (AE_NOT_EXIST);
427 /* Get the Region node */
429 Node = ObjDesc->Region.Node;
431 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (ACPI_TYPE_REGION, Node, NULL));
433 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
434 AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));
436 /* Execute the argument AML */
438 Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
439 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
440 return_ACPI_STATUS (Status);
444 /*****************************************************************************
446 * FUNCTION: AcpiDsInitializeRegion
448 * PARAMETERS: Op - A valid region Op object
450 * RETURN: Status
452 * DESCRIPTION: Front end to EvInitializeRegion
454 ****************************************************************************/
456 ACPI_STATUS
457 AcpiDsInitializeRegion (
458 ACPI_HANDLE ObjHandle)
460 ACPI_OPERAND_OBJECT *ObjDesc;
461 ACPI_STATUS Status;
464 ObjDesc = AcpiNsGetAttachedObject (ObjHandle);
466 /* Namespace is NOT locked */
468 Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
469 return (Status);
473 /*****************************************************************************
475 * FUNCTION: AcpiDsInitBufferField
477 * PARAMETERS: AmlOpcode - CreateXxxField
478 * ObjDesc - BufferField object
479 * BufferDesc - Host Buffer
480 * OffsetDesc - Offset into buffer
481 * Length - Length of field (CREATE_FIELD_OP only)
482 * Result - Where to store the result
484 * RETURN: Status
486 * DESCRIPTION: Perform actual initialization of a buffer field
488 ****************************************************************************/
490 ACPI_STATUS
491 AcpiDsInitBufferField (
492 UINT16 AmlOpcode,
493 ACPI_OPERAND_OBJECT *ObjDesc,
494 ACPI_OPERAND_OBJECT *BufferDesc,
495 ACPI_OPERAND_OBJECT *OffsetDesc,
496 ACPI_OPERAND_OBJECT *LengthDesc,
497 ACPI_OPERAND_OBJECT *ResultDesc)
499 UINT32 Offset;
500 UINT32 BitOffset;
501 UINT32 BitCount;
502 UINT8 FieldFlags;
503 ACPI_STATUS Status;
506 ACPI_FUNCTION_TRACE_PTR ("DsInitBufferField", ObjDesc);
509 /* Host object must be a Buffer */
511 if (ACPI_GET_OBJECT_TYPE (BufferDesc) != ACPI_TYPE_BUFFER)
513 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
514 "Target of Create Field is not a Buffer object - %s\n",
515 AcpiUtGetObjectTypeName (BufferDesc)));
517 Status = AE_AML_OPERAND_TYPE;
518 goto Cleanup;
522 * The last parameter to all of these opcodes (ResultDesc) started
523 * out as a NameString, and should therefore now be a NS node
524 * after resolution in AcpiExResolveOperands().
526 if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED)
528 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) destination not a NS Node [%s]\n",
529 AcpiPsGetOpcodeName (AmlOpcode), AcpiUtGetDescriptorName (ResultDesc)));
531 Status = AE_AML_OPERAND_TYPE;
532 goto Cleanup;
535 Offset = (UINT32) OffsetDesc->Integer.Value;
538 * Setup the Bit offsets and counts, according to the opcode
540 switch (AmlOpcode)
542 case AML_CREATE_FIELD_OP:
544 /* Offset is in bits, count is in bits */
546 BitOffset = Offset;
547 BitCount = (UINT32) LengthDesc->Integer.Value;
548 FieldFlags = AML_FIELD_ACCESS_BYTE;
549 break;
551 case AML_CREATE_BIT_FIELD_OP:
553 /* Offset is in bits, Field is one bit */
555 BitOffset = Offset;
556 BitCount = 1;
557 FieldFlags = AML_FIELD_ACCESS_BYTE;
558 break;
560 case AML_CREATE_BYTE_FIELD_OP:
562 /* Offset is in bytes, field is one byte */
564 BitOffset = 8 * Offset;
565 BitCount = 8;
566 FieldFlags = AML_FIELD_ACCESS_BYTE;
567 break;
569 case AML_CREATE_WORD_FIELD_OP:
571 /* Offset is in bytes, field is one word */
573 BitOffset = 8 * Offset;
574 BitCount = 16;
575 FieldFlags = AML_FIELD_ACCESS_WORD;
576 break;
578 case AML_CREATE_DWORD_FIELD_OP:
580 /* Offset is in bytes, field is one dword */
582 BitOffset = 8 * Offset;
583 BitCount = 32;
584 FieldFlags = AML_FIELD_ACCESS_DWORD;
585 break;
587 case AML_CREATE_QWORD_FIELD_OP:
589 /* Offset is in bytes, field is one qword */
591 BitOffset = 8 * Offset;
592 BitCount = 64;
593 FieldFlags = AML_FIELD_ACCESS_QWORD;
594 break;
596 default:
598 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
599 "Unknown field creation opcode %02x\n",
600 AmlOpcode));
601 Status = AE_AML_BAD_OPCODE;
602 goto Cleanup;
605 /* Entire field must fit within the current length of the buffer */
607 if ((BitOffset + BitCount) >
608 (8 * (UINT32) BufferDesc->Buffer.Length))
610 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
611 "Field [%4.4s] size %d exceeds Buffer [%4.4s] size %d (bits)\n",
612 AcpiUtGetNodeName (ResultDesc),
613 BitOffset + BitCount,
614 AcpiUtGetNodeName (BufferDesc->Buffer.Node),
615 8 * (UINT32) BufferDesc->Buffer.Length));
616 Status = AE_AML_BUFFER_LIMIT;
617 goto Cleanup;
621 * Initialize areas of the field object that are common to all fields
622 * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE)
624 Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags, 0,
625 BitOffset, BitCount);
626 if (ACPI_FAILURE (Status))
628 goto Cleanup;
631 ObjDesc->BufferField.BufferObj = BufferDesc;
633 /* Reference count for BufferDesc inherits ObjDesc count */
635 BufferDesc->Common.ReferenceCount = (UINT16) (BufferDesc->Common.ReferenceCount +
636 ObjDesc->Common.ReferenceCount);
639 Cleanup:
641 /* Always delete the operands */
643 AcpiUtRemoveReference (OffsetDesc);
644 AcpiUtRemoveReference (BufferDesc);
646 if (AmlOpcode == AML_CREATE_FIELD_OP)
648 AcpiUtRemoveReference (LengthDesc);
651 /* On failure, delete the result descriptor */
653 if (ACPI_FAILURE (Status))
655 AcpiUtRemoveReference (ResultDesc); /* Result descriptor */
657 else
659 /* Now the address and length are valid for this BufferField */
661 ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID;
664 return_ACPI_STATUS (Status);
668 /*****************************************************************************
670 * FUNCTION: AcpiDsEvalBufferFieldOperands
672 * PARAMETERS: WalkState - Current walk
673 * Op - A valid BufferField Op object
675 * RETURN: Status
677 * DESCRIPTION: Get BufferField Buffer and Index
678 * Called from AcpiDsExecEndOp during BufferField parse tree walk
680 ****************************************************************************/
682 ACPI_STATUS
683 AcpiDsEvalBufferFieldOperands (
684 ACPI_WALK_STATE *WalkState,
685 ACPI_PARSE_OBJECT *Op)
687 ACPI_STATUS Status;
688 ACPI_OPERAND_OBJECT *ObjDesc;
689 ACPI_NAMESPACE_NODE *Node;
690 ACPI_PARSE_OBJECT *NextOp;
693 ACPI_FUNCTION_TRACE_PTR ("DsEvalBufferFieldOperands", Op);
697 * This is where we evaluate the address and length fields of the
698 * CreateXxxField declaration
700 Node = Op->Common.Node;
702 /* NextOp points to the op that holds the Buffer */
704 NextOp = Op->Common.Value.Arg;
706 /* Evaluate/create the address and length operands */
708 Status = AcpiDsCreateOperands (WalkState, NextOp);
709 if (ACPI_FAILURE (Status))
711 return_ACPI_STATUS (Status);
714 ObjDesc = AcpiNsGetAttachedObject (Node);
715 if (!ObjDesc)
717 return_ACPI_STATUS (AE_NOT_EXIST);
720 /* Resolve the operands */
722 Status = AcpiExResolveOperands (Op->Common.AmlOpcode,
723 ACPI_WALK_OPERANDS, WalkState);
725 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
726 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
727 WalkState->NumOperands, "after AcpiExResolveOperands");
729 if (ACPI_FAILURE (Status))
731 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n",
732 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Status));
734 return_ACPI_STATUS (Status);
737 /* Initialize the Buffer Field */
739 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
741 /* NOTE: Slightly different operands for this opcode */
743 Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
744 WalkState->Operands[0], WalkState->Operands[1],
745 WalkState->Operands[2], WalkState->Operands[3]);
747 else
749 /* All other, CreateXxxField opcodes */
751 Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
752 WalkState->Operands[0], WalkState->Operands[1],
753 NULL, WalkState->Operands[2]);
756 return_ACPI_STATUS (Status);
760 /*****************************************************************************
762 * FUNCTION: AcpiDsEvalRegionOperands
764 * PARAMETERS: WalkState - Current walk
765 * Op - A valid region Op object
767 * RETURN: Status
769 * DESCRIPTION: Get region address and length
770 * Called from AcpiDsExecEndOp during OpRegion parse tree walk
772 ****************************************************************************/
774 ACPI_STATUS
775 AcpiDsEvalRegionOperands (
776 ACPI_WALK_STATE *WalkState,
777 ACPI_PARSE_OBJECT *Op)
779 ACPI_STATUS Status;
780 ACPI_OPERAND_OBJECT *ObjDesc;
781 ACPI_OPERAND_OBJECT *OperandDesc;
782 ACPI_NAMESPACE_NODE *Node;
783 ACPI_PARSE_OBJECT *NextOp;
786 ACPI_FUNCTION_TRACE_PTR ("DsEvalRegionOperands", Op);
790 * This is where we evaluate the address and length fields of the OpRegion declaration
792 Node = Op->Common.Node;
794 /* NextOp points to the op that holds the SpaceID */
796 NextOp = Op->Common.Value.Arg;
798 /* NextOp points to address op */
800 NextOp = NextOp->Common.Next;
802 /* Evaluate/create the address and length operands */
804 Status = AcpiDsCreateOperands (WalkState, NextOp);
805 if (ACPI_FAILURE (Status))
807 return_ACPI_STATUS (Status);
810 /* Resolve the length and address operands to numbers */
812 Status = AcpiExResolveOperands (Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
813 if (ACPI_FAILURE (Status))
815 return_ACPI_STATUS (Status);
818 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
819 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
820 1, "after AcpiExResolveOperands");
822 ObjDesc = AcpiNsGetAttachedObject (Node);
823 if (!ObjDesc)
825 return_ACPI_STATUS (AE_NOT_EXIST);
829 * Get the length operand and save it
830 * (at Top of stack)
832 OperandDesc = WalkState->Operands[WalkState->NumOperands - 1];
834 ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
835 AcpiUtRemoveReference (OperandDesc);
838 * Get the address and save it
839 * (at top of stack - 1)
841 OperandDesc = WalkState->Operands[WalkState->NumOperands - 2];
843 ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS) OperandDesc->Integer.Value;
844 AcpiUtRemoveReference (OperandDesc);
846 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
847 ObjDesc,
848 ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
849 ObjDesc->Region.Length));
851 /* Now the address and length are valid for this opregion */
853 ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
855 return_ACPI_STATUS (Status);
859 /*****************************************************************************
861 * FUNCTION: AcpiDsEvalDataObjectOperands
863 * PARAMETERS: WalkState - Current walk
864 * Op - A valid DataObject Op object
865 * ObjDesc - DataObject
867 * RETURN: Status
869 * DESCRIPTION: Get the operands and complete the following data object types:
870 * Buffer, Package.
872 ****************************************************************************/
874 ACPI_STATUS
875 AcpiDsEvalDataObjectOperands (
876 ACPI_WALK_STATE *WalkState,
877 ACPI_PARSE_OBJECT *Op,
878 ACPI_OPERAND_OBJECT *ObjDesc)
880 ACPI_STATUS Status;
881 ACPI_OPERAND_OBJECT *ArgDesc;
882 UINT32 Length;
885 ACPI_FUNCTION_TRACE ("DsEvalDataObjectOperands");
888 /* The first operand (for all of these data objects) is the length */
890 Status = AcpiDsCreateOperand (WalkState, Op->Common.Value.Arg, 1);
891 if (ACPI_FAILURE (Status))
893 return_ACPI_STATUS (Status);
896 Status = AcpiExResolveOperands (WalkState->Opcode,
897 &(WalkState->Operands [WalkState->NumOperands -1]),
898 WalkState);
899 if (ACPI_FAILURE (Status))
901 return_ACPI_STATUS (Status);
904 /* Extract length operand */
906 ArgDesc = WalkState->Operands [WalkState->NumOperands - 1];
907 Length = (UINT32) ArgDesc->Integer.Value;
909 /* Cleanup for length operand */
911 Status = AcpiDsObjStackPop (1, WalkState);
912 if (ACPI_FAILURE (Status))
914 return_ACPI_STATUS (Status);
917 AcpiUtRemoveReference (ArgDesc);
920 * Create the actual data object
922 switch (Op->Common.AmlOpcode)
924 case AML_BUFFER_OP:
926 Status = AcpiDsBuildInternalBufferObj (WalkState, Op, Length, &ObjDesc);
927 break;
929 case AML_PACKAGE_OP:
930 case AML_VAR_PACKAGE_OP:
932 Status = AcpiDsBuildInternalPackageObj (WalkState, Op, Length, &ObjDesc);
933 break;
935 default:
936 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
939 if (ACPI_SUCCESS (Status))
942 * Return the object in the WalkState, unless the parent is a package --
943 * in this case, the return object will be stored in the parse tree
944 * for the package.
946 if ((!Op->Common.Parent) ||
947 ((Op->Common.Parent->Common.AmlOpcode != AML_PACKAGE_OP) &&
948 (Op->Common.Parent->Common.AmlOpcode != AML_VAR_PACKAGE_OP) &&
949 (Op->Common.Parent->Common.AmlOpcode != AML_NAME_OP)))
951 WalkState->ResultObj = ObjDesc;
955 return_ACPI_STATUS (Status);
959 /*******************************************************************************
961 * FUNCTION: AcpiDsExecBeginControlOp
963 * PARAMETERS: WalkList - The list that owns the walk stack
964 * Op - The control Op
966 * RETURN: Status
968 * DESCRIPTION: Handles all control ops encountered during control method
969 * execution.
971 ******************************************************************************/
973 ACPI_STATUS
974 AcpiDsExecBeginControlOp (
975 ACPI_WALK_STATE *WalkState,
976 ACPI_PARSE_OBJECT *Op)
978 ACPI_STATUS Status = AE_OK;
979 ACPI_GENERIC_STATE *ControlState;
982 ACPI_FUNCTION_NAME ("DsExecBeginControlOp");
985 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", Op,
986 Op->Common.AmlOpcode, WalkState));
988 switch (Op->Common.AmlOpcode)
990 case AML_IF_OP:
991 case AML_WHILE_OP:
994 * IF/WHILE: Create a new control state to manage these
995 * constructs. We need to manage these as a stack, in order
996 * to handle nesting.
998 ControlState = AcpiUtCreateControlState ();
999 if (!ControlState)
1001 Status = AE_NO_MEMORY;
1002 break;
1005 * Save a pointer to the predicate for multiple executions
1006 * of a loop
1008 ControlState->Control.AmlPredicateStart = WalkState->ParserState.Aml - 1;
1009 ControlState->Control.PackageEnd = WalkState->ParserState.PkgEnd;
1010 ControlState->Control.Opcode = Op->Common.AmlOpcode;
1013 /* Push the control state on this walk's control stack */
1015 AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
1016 break;
1018 case AML_ELSE_OP:
1020 /* Predicate is in the state object */
1021 /* If predicate is true, the IF was executed, ignore ELSE part */
1023 if (WalkState->LastPredicate)
1025 Status = AE_CTRL_TRUE;
1028 break;
1030 case AML_RETURN_OP:
1032 break;
1034 default:
1035 break;
1038 return (Status);
1042 /*******************************************************************************
1044 * FUNCTION: AcpiDsExecEndControlOp
1046 * PARAMETERS: WalkList - The list that owns the walk stack
1047 * Op - The control Op
1049 * RETURN: Status
1051 * DESCRIPTION: Handles all control ops encountered during control method
1052 * execution.
1054 ******************************************************************************/
1056 ACPI_STATUS
1057 AcpiDsExecEndControlOp (
1058 ACPI_WALK_STATE *WalkState,
1059 ACPI_PARSE_OBJECT *Op)
1061 ACPI_STATUS Status = AE_OK;
1062 ACPI_GENERIC_STATE *ControlState;
1065 ACPI_FUNCTION_NAME ("DsExecEndControlOp");
1068 switch (Op->Common.AmlOpcode)
1070 case AML_IF_OP:
1072 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
1075 * Save the result of the predicate in case there is an
1076 * ELSE to come
1078 WalkState->LastPredicate =
1079 (BOOLEAN) WalkState->ControlState->Common.Value;
1082 * Pop the control state that was created at the start
1083 * of the IF and free it
1085 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1086 AcpiUtDeleteGenericState (ControlState);
1087 break;
1090 case AML_ELSE_OP:
1092 break;
1095 case AML_WHILE_OP:
1097 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
1099 if (WalkState->ControlState->Common.Value)
1101 /* Predicate was true, go back and evaluate it again! */
1103 Status = AE_CTRL_PENDING;
1106 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] termination! Op=%p\n", Op));
1108 /* Pop this control state and free it */
1110 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1112 WalkState->AmlLastWhile = ControlState->Control.AmlPredicateStart;
1113 AcpiUtDeleteGenericState (ControlState);
1114 break;
1117 case AML_RETURN_OP:
1119 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1120 "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
1123 * One optional operand -- the return value
1124 * It can be either an immediate operand or a result that
1125 * has been bubbled up the tree
1127 if (Op->Common.Value.Arg)
1129 /* Since we have a real Return(), delete any implicit return */
1131 AcpiDsClearImplicitReturn (WalkState);
1133 /* Return statement has an immediate operand */
1135 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
1136 if (ACPI_FAILURE (Status))
1138 return (Status);
1142 * If value being returned is a Reference (such as
1143 * an arg or local), resolve it now because it may
1144 * cease to exist at the end of the method.
1146 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
1147 if (ACPI_FAILURE (Status))
1149 return (Status);
1153 * Get the return value and save as the last result
1154 * value. This is the only place where WalkState->ReturnDesc
1155 * is set to anything other than zero!
1157 WalkState->ReturnDesc = WalkState->Operands[0];
1159 else if ((WalkState->Results) &&
1160 (WalkState->Results->Results.NumResults > 0))
1162 /* Since we have a real Return(), delete any implicit return */
1164 AcpiDsClearImplicitReturn (WalkState);
1167 * The return value has come from a previous calculation.
1169 * If value being returned is a Reference (such as
1170 * an arg or local), resolve it now because it may
1171 * cease to exist at the end of the method.
1173 * Allow references created by the Index operator to return unchanged.
1175 if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) == ACPI_DESC_TYPE_OPERAND) &&
1176 (ACPI_GET_OBJECT_TYPE (WalkState->Results->Results.ObjDesc [0]) == ACPI_TYPE_LOCAL_REFERENCE) &&
1177 ((WalkState->Results->Results.ObjDesc [0])->Reference.Opcode != AML_INDEX_OP))
1179 Status = AcpiExResolveToValue (&WalkState->Results->Results.ObjDesc [0], WalkState);
1180 if (ACPI_FAILURE (Status))
1182 return (Status);
1186 WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
1188 else
1190 /* No return operand */
1192 if (WalkState->NumOperands)
1194 AcpiUtRemoveReference (WalkState->Operands [0]);
1197 WalkState->Operands [0] = NULL;
1198 WalkState->NumOperands = 0;
1199 WalkState->ReturnDesc = NULL;
1203 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1204 "Completed RETURN_OP State=%p, RetVal=%p\n",
1205 WalkState, WalkState->ReturnDesc));
1207 /* End the control method execution right now */
1209 Status = AE_CTRL_TERMINATE;
1210 break;
1213 case AML_NOOP_OP:
1215 /* Just do nothing! */
1216 break;
1219 case AML_BREAK_POINT_OP:
1221 /* Call up to the OS service layer to handle this */
1223 Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode");
1225 /* If and when it returns, all done. */
1227 break;
1230 case AML_BREAK_OP:
1231 case AML_CONTINUE_OP: /* ACPI 2.0 */
1234 /* Pop and delete control states until we find a while */
1236 while (WalkState->ControlState &&
1237 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
1239 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1240 AcpiUtDeleteGenericState (ControlState);
1243 /* No while found? */
1245 if (!WalkState->ControlState)
1247 return (AE_AML_NO_WHILE);
1250 /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
1252 WalkState->AmlLastWhile = WalkState->ControlState->Control.PackageEnd;
1254 /* Return status depending on opcode */
1256 if (Op->Common.AmlOpcode == AML_BREAK_OP)
1258 Status = AE_CTRL_BREAK;
1260 else
1262 Status = AE_CTRL_CONTINUE;
1264 break;
1267 default:
1269 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown control opcode=%X Op=%p\n",
1270 Op->Common.AmlOpcode, Op));
1272 Status = AE_AML_BAD_OPCODE;
1273 break;
1276 return (Status);