Import acpica-unix-20061109 from Intel.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / interpreter / dispatcher / dsopcode.c
blob06f725b7ba3bd2d99ba99aad4e32d3757e23288a
1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
4 * "control" opcodes
5 * $Revision: 1.109 $
7 *****************************************************************************/
9 /******************************************************************************
11 * 1. Copyright Notice
13 * Some or all of this work - Copyright (c) 1999 - 2006, 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")
131 /* Local prototypes */
133 static ACPI_STATUS
134 AcpiDsExecuteArguments (
135 ACPI_NAMESPACE_NODE *Node,
136 ACPI_NAMESPACE_NODE *ScopeNode,
137 UINT32 AmlLength,
138 UINT8 *AmlStart);
140 static ACPI_STATUS
141 AcpiDsInitBufferField (
142 UINT16 AmlOpcode,
143 ACPI_OPERAND_OBJECT *ObjDesc,
144 ACPI_OPERAND_OBJECT *BufferDesc,
145 ACPI_OPERAND_OBJECT *OffsetDesc,
146 ACPI_OPERAND_OBJECT *LengthDesc,
147 ACPI_OPERAND_OBJECT *ResultDesc);
150 /*******************************************************************************
152 * FUNCTION: AcpiDsExecuteArguments
154 * PARAMETERS: Node - Object NS node
155 * ScopeNode - Parent NS node
156 * AmlLength - Length of executable AML
157 * AmlStart - Pointer to the AML
159 * RETURN: Status.
161 * DESCRIPTION: Late (deferred) execution of region or field arguments
163 ******************************************************************************/
165 static ACPI_STATUS
166 AcpiDsExecuteArguments (
167 ACPI_NAMESPACE_NODE *Node,
168 ACPI_NAMESPACE_NODE *ScopeNode,
169 UINT32 AmlLength,
170 UINT8 *AmlStart)
172 ACPI_STATUS Status;
173 ACPI_PARSE_OBJECT *Op;
174 ACPI_WALK_STATE *WalkState;
177 ACPI_FUNCTION_TRACE (DsExecuteArguments);
181 * Allocate a new parser op to be the root of the parsed tree
183 Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
184 if (!Op)
186 return_ACPI_STATUS (AE_NO_MEMORY);
189 /* Save the Node for use in AcpiPsParseAml */
191 Op->Common.Node = ScopeNode;
193 /* Create and initialize a new parser state */
195 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
196 if (!WalkState)
198 Status = AE_NO_MEMORY;
199 goto Cleanup;
202 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
203 AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
204 if (ACPI_FAILURE (Status))
206 AcpiDsDeleteWalkState (WalkState);
207 goto Cleanup;
210 /* Mark this parse as a deferred opcode */
212 WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;
213 WalkState->DeferredNode = Node;
215 /* Pass1: Parse the entire declaration */
217 Status = AcpiPsParseAml (WalkState);
218 if (ACPI_FAILURE (Status))
220 goto Cleanup;
223 /* Get and init the Op created above */
225 Op->Common.Node = Node;
226 AcpiPsDeleteParseTree (Op);
228 /* Evaluate the deferred arguments */
230 Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
231 if (!Op)
233 return_ACPI_STATUS (AE_NO_MEMORY);
236 Op->Common.Node = ScopeNode;
238 /* Create and initialize a new parser state */
240 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
241 if (!WalkState)
243 Status = AE_NO_MEMORY;
244 goto Cleanup;
247 /* Execute the opcode and arguments */
249 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
250 AmlLength, NULL, ACPI_IMODE_EXECUTE);
251 if (ACPI_FAILURE (Status))
253 AcpiDsDeleteWalkState (WalkState);
254 goto Cleanup;
257 /* Mark this execution as a deferred opcode */
259 WalkState->DeferredNode = Node;
260 Status = AcpiPsParseAml (WalkState);
262 Cleanup:
263 AcpiPsDeleteParseTree (Op);
264 return_ACPI_STATUS (Status);
268 /*******************************************************************************
270 * FUNCTION: AcpiDsGetBufferFieldArguments
272 * PARAMETERS: ObjDesc - A valid BufferField object
274 * RETURN: Status.
276 * DESCRIPTION: Get BufferField Buffer and Index. This implements the late
277 * evaluation of these field attributes.
279 ******************************************************************************/
281 ACPI_STATUS
282 AcpiDsGetBufferFieldArguments (
283 ACPI_OPERAND_OBJECT *ObjDesc)
285 ACPI_OPERAND_OBJECT *ExtraDesc;
286 ACPI_NAMESPACE_NODE *Node;
287 ACPI_STATUS Status;
290 ACPI_FUNCTION_TRACE_PTR (DsGetBufferFieldArguments, ObjDesc);
293 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
295 return_ACPI_STATUS (AE_OK);
298 /* Get the AML pointer (method object) and BufferField node */
300 ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
301 Node = ObjDesc->BufferField.Node;
303 ACPI_DEBUG_EXEC(AcpiUtDisplayInitPathname (ACPI_TYPE_BUFFER_FIELD, Node, NULL));
304 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
305 AcpiUtGetNodeName (Node)));
307 /* Execute the AML code for the TermArg arguments */
309 Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
310 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
311 return_ACPI_STATUS (Status);
315 /*******************************************************************************
317 * FUNCTION: AcpiDsGetBufferArguments
319 * PARAMETERS: ObjDesc - A valid Buffer object
321 * RETURN: Status.
323 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
324 * the late evaluation of these attributes.
326 ******************************************************************************/
328 ACPI_STATUS
329 AcpiDsGetBufferArguments (
330 ACPI_OPERAND_OBJECT *ObjDesc)
332 ACPI_NAMESPACE_NODE *Node;
333 ACPI_STATUS Status;
336 ACPI_FUNCTION_TRACE_PTR (DsGetBufferArguments, ObjDesc);
339 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
341 return_ACPI_STATUS (AE_OK);
344 /* Get the Buffer node */
346 Node = ObjDesc->Buffer.Node;
347 if (!Node)
349 ACPI_ERROR ((AE_INFO,
350 "No pointer back to NS node in buffer obj %p", ObjDesc));
351 return_ACPI_STATUS (AE_AML_INTERNAL);
354 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
356 /* Execute the AML code for the TermArg arguments */
358 Status = AcpiDsExecuteArguments (Node, Node,
359 ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);
360 return_ACPI_STATUS (Status);
364 /*******************************************************************************
366 * FUNCTION: AcpiDsGetPackageArguments
368 * PARAMETERS: ObjDesc - A valid Package object
370 * RETURN: Status.
372 * DESCRIPTION: Get Package length and initializer byte list. This implements
373 * the late evaluation of these attributes.
375 ******************************************************************************/
377 ACPI_STATUS
378 AcpiDsGetPackageArguments (
379 ACPI_OPERAND_OBJECT *ObjDesc)
381 ACPI_NAMESPACE_NODE *Node;
382 ACPI_STATUS Status;
385 ACPI_FUNCTION_TRACE_PTR (DsGetPackageArguments, ObjDesc);
388 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
390 return_ACPI_STATUS (AE_OK);
393 /* Get the Package node */
395 Node = ObjDesc->Package.Node;
396 if (!Node)
398 ACPI_ERROR ((AE_INFO,
399 "No pointer back to NS node in package %p", ObjDesc));
400 return_ACPI_STATUS (AE_AML_INTERNAL);
403 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
405 /* Execute the AML code for the TermArg arguments */
407 Status = AcpiDsExecuteArguments (Node, Node,
408 ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);
409 return_ACPI_STATUS (Status);
413 /*****************************************************************************
415 * FUNCTION: AcpiDsGetRegionArguments
417 * PARAMETERS: ObjDesc - A valid region object
419 * RETURN: Status.
421 * DESCRIPTION: Get region address and length. This implements the late
422 * evaluation of these region attributes.
424 ****************************************************************************/
426 ACPI_STATUS
427 AcpiDsGetRegionArguments (
428 ACPI_OPERAND_OBJECT *ObjDesc)
430 ACPI_NAMESPACE_NODE *Node;
431 ACPI_STATUS Status;
432 ACPI_OPERAND_OBJECT *ExtraDesc;
435 ACPI_FUNCTION_TRACE_PTR (DsGetRegionArguments, ObjDesc);
438 if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
440 return_ACPI_STATUS (AE_OK);
443 ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
444 if (!ExtraDesc)
446 return_ACPI_STATUS (AE_NOT_EXIST);
449 /* Get the Region node */
451 Node = ObjDesc->Region.Node;
453 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (ACPI_TYPE_REGION, Node, NULL));
455 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
456 AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));
458 /* Execute the argument AML */
460 Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
461 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
462 if (ACPI_FAILURE (Status))
464 return_ACPI_STATUS (Status);
467 /* Validate the region address/length via the host OS */
469 Status = AcpiOsValidateAddress (ObjDesc->Region.SpaceId,
470 ObjDesc->Region.Address, (ACPI_SIZE) ObjDesc->Region.Length);
471 if (ACPI_FAILURE (Status))
474 * Invalid address/length. We will emit an error message and mark
475 * the region as invalid, so that it will cause an additional error if
476 * it is ever used. Then return AE_OK.
478 ACPI_EXCEPTION ((AE_INFO, Status,
479 "During address validation of OpRegion [%4.4s]", Node->Name.Ascii));
480 ObjDesc->Common.Flags |= AOPOBJ_INVALID;
481 Status = AE_OK;
484 return_ACPI_STATUS (Status);
488 /*******************************************************************************
490 * FUNCTION: AcpiDsInitializeRegion
492 * PARAMETERS: ObjHandle - Region namespace node
494 * RETURN: Status
496 * DESCRIPTION: Front end to EvInitializeRegion
498 ******************************************************************************/
500 ACPI_STATUS
501 AcpiDsInitializeRegion (
502 ACPI_HANDLE ObjHandle)
504 ACPI_OPERAND_OBJECT *ObjDesc;
505 ACPI_STATUS Status;
508 ObjDesc = AcpiNsGetAttachedObject (ObjHandle);
510 /* Namespace is NOT locked */
512 Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
513 return (Status);
517 /*******************************************************************************
519 * FUNCTION: AcpiDsInitBufferField
521 * PARAMETERS: AmlOpcode - CreateXxxField
522 * ObjDesc - BufferField object
523 * BufferDesc - Host Buffer
524 * OffsetDesc - Offset into buffer
525 * LengthDesc - Length of field (CREATE_FIELD_OP only)
526 * ResultDesc - Where to store the result
528 * RETURN: Status
530 * DESCRIPTION: Perform actual initialization of a buffer field
532 ******************************************************************************/
534 static ACPI_STATUS
535 AcpiDsInitBufferField (
536 UINT16 AmlOpcode,
537 ACPI_OPERAND_OBJECT *ObjDesc,
538 ACPI_OPERAND_OBJECT *BufferDesc,
539 ACPI_OPERAND_OBJECT *OffsetDesc,
540 ACPI_OPERAND_OBJECT *LengthDesc,
541 ACPI_OPERAND_OBJECT *ResultDesc)
543 UINT32 Offset;
544 UINT32 BitOffset;
545 UINT32 BitCount;
546 UINT8 FieldFlags;
547 ACPI_STATUS Status;
550 ACPI_FUNCTION_TRACE_PTR (DsInitBufferField, ObjDesc);
553 /* Host object must be a Buffer */
555 if (ACPI_GET_OBJECT_TYPE (BufferDesc) != ACPI_TYPE_BUFFER)
557 ACPI_ERROR ((AE_INFO,
558 "Target of Create Field is not a Buffer object - %s",
559 AcpiUtGetObjectTypeName (BufferDesc)));
561 Status = AE_AML_OPERAND_TYPE;
562 goto Cleanup;
566 * The last parameter to all of these opcodes (ResultDesc) started
567 * out as a NameString, and should therefore now be a NS node
568 * after resolution in AcpiExResolveOperands().
570 if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED)
572 ACPI_ERROR ((AE_INFO,
573 "(%s) destination not a NS Node [%s]",
574 AcpiPsGetOpcodeName (AmlOpcode),
575 AcpiUtGetDescriptorName (ResultDesc)));
577 Status = AE_AML_OPERAND_TYPE;
578 goto Cleanup;
581 Offset = (UINT32) OffsetDesc->Integer.Value;
584 * Setup the Bit offsets and counts, according to the opcode
586 switch (AmlOpcode)
588 case AML_CREATE_FIELD_OP:
590 /* Offset is in bits, count is in bits */
592 FieldFlags = AML_FIELD_ACCESS_BYTE;
593 BitOffset = Offset;
594 BitCount = (UINT32) LengthDesc->Integer.Value;
596 /* Must have a valid (>0) bit count */
598 if (BitCount == 0)
600 ACPI_ERROR ((AE_INFO,
601 "Attempt to CreateField of length zero"));
602 Status = AE_AML_OPERAND_VALUE;
603 goto Cleanup;
605 break;
607 case AML_CREATE_BIT_FIELD_OP:
609 /* Offset is in bits, Field is one bit */
611 BitOffset = Offset;
612 BitCount = 1;
613 FieldFlags = AML_FIELD_ACCESS_BYTE;
614 break;
616 case AML_CREATE_BYTE_FIELD_OP:
618 /* Offset is in bytes, field is one byte */
620 BitOffset = 8 * Offset;
621 BitCount = 8;
622 FieldFlags = AML_FIELD_ACCESS_BYTE;
623 break;
625 case AML_CREATE_WORD_FIELD_OP:
627 /* Offset is in bytes, field is one word */
629 BitOffset = 8 * Offset;
630 BitCount = 16;
631 FieldFlags = AML_FIELD_ACCESS_WORD;
632 break;
634 case AML_CREATE_DWORD_FIELD_OP:
636 /* Offset is in bytes, field is one dword */
638 BitOffset = 8 * Offset;
639 BitCount = 32;
640 FieldFlags = AML_FIELD_ACCESS_DWORD;
641 break;
643 case AML_CREATE_QWORD_FIELD_OP:
645 /* Offset is in bytes, field is one qword */
647 BitOffset = 8 * Offset;
648 BitCount = 64;
649 FieldFlags = AML_FIELD_ACCESS_QWORD;
650 break;
652 default:
654 ACPI_ERROR ((AE_INFO,
655 "Unknown field creation opcode %02x",
656 AmlOpcode));
657 Status = AE_AML_BAD_OPCODE;
658 goto Cleanup;
661 /* Entire field must fit within the current length of the buffer */
663 if ((BitOffset + BitCount) >
664 (8 * (UINT32) BufferDesc->Buffer.Length))
666 ACPI_ERROR ((AE_INFO,
667 "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
668 AcpiUtGetNodeName (ResultDesc),
669 BitOffset + BitCount,
670 AcpiUtGetNodeName (BufferDesc->Buffer.Node),
671 8 * (UINT32) BufferDesc->Buffer.Length));
672 Status = AE_AML_BUFFER_LIMIT;
673 goto Cleanup;
677 * Initialize areas of the field object that are common to all fields
678 * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK),
679 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
681 Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags, 0,
682 BitOffset, BitCount);
683 if (ACPI_FAILURE (Status))
685 goto Cleanup;
688 ObjDesc->BufferField.BufferObj = BufferDesc;
690 /* Reference count for BufferDesc inherits ObjDesc count */
692 BufferDesc->Common.ReferenceCount = (UINT16)
693 (BufferDesc->Common.ReferenceCount + ObjDesc->Common.ReferenceCount);
696 Cleanup:
698 /* Always delete the operands */
700 AcpiUtRemoveReference (OffsetDesc);
701 AcpiUtRemoveReference (BufferDesc);
703 if (AmlOpcode == AML_CREATE_FIELD_OP)
705 AcpiUtRemoveReference (LengthDesc);
708 /* On failure, delete the result descriptor */
710 if (ACPI_FAILURE (Status))
712 AcpiUtRemoveReference (ResultDesc); /* Result descriptor */
714 else
716 /* Now the address and length are valid for this BufferField */
718 ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID;
721 return_ACPI_STATUS (Status);
725 /*******************************************************************************
727 * FUNCTION: AcpiDsEvalBufferFieldOperands
729 * PARAMETERS: WalkState - Current walk
730 * Op - A valid BufferField Op object
732 * RETURN: Status
734 * DESCRIPTION: Get BufferField Buffer and Index
735 * Called from AcpiDsExecEndOp during BufferField parse tree walk
737 ******************************************************************************/
739 ACPI_STATUS
740 AcpiDsEvalBufferFieldOperands (
741 ACPI_WALK_STATE *WalkState,
742 ACPI_PARSE_OBJECT *Op)
744 ACPI_STATUS Status;
745 ACPI_OPERAND_OBJECT *ObjDesc;
746 ACPI_NAMESPACE_NODE *Node;
747 ACPI_PARSE_OBJECT *NextOp;
750 ACPI_FUNCTION_TRACE_PTR (DsEvalBufferFieldOperands, Op);
754 * This is where we evaluate the address and length fields of the
755 * CreateXxxField declaration
757 Node = Op->Common.Node;
759 /* NextOp points to the op that holds the Buffer */
761 NextOp = Op->Common.Value.Arg;
763 /* Evaluate/create the address and length operands */
765 Status = AcpiDsCreateOperands (WalkState, NextOp);
766 if (ACPI_FAILURE (Status))
768 return_ACPI_STATUS (Status);
771 ObjDesc = AcpiNsGetAttachedObject (Node);
772 if (!ObjDesc)
774 return_ACPI_STATUS (AE_NOT_EXIST);
777 /* Resolve the operands */
779 Status = AcpiExResolveOperands (Op->Common.AmlOpcode,
780 ACPI_WALK_OPERANDS, WalkState);
782 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
783 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
784 WalkState->NumOperands, "after AcpiExResolveOperands");
786 if (ACPI_FAILURE (Status))
788 ACPI_ERROR ((AE_INFO, "(%s) bad operand(s) (%X)",
789 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Status));
791 return_ACPI_STATUS (Status);
794 /* Initialize the Buffer Field */
796 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
798 /* NOTE: Slightly different operands for this opcode */
800 Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
801 WalkState->Operands[0], WalkState->Operands[1],
802 WalkState->Operands[2], WalkState->Operands[3]);
804 else
806 /* All other, CreateXxxField opcodes */
808 Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
809 WalkState->Operands[0], WalkState->Operands[1],
810 NULL, WalkState->Operands[2]);
813 return_ACPI_STATUS (Status);
817 /*******************************************************************************
819 * FUNCTION: AcpiDsEvalRegionOperands
821 * PARAMETERS: WalkState - Current walk
822 * Op - A valid region Op object
824 * RETURN: Status
826 * DESCRIPTION: Get region address and length
827 * Called from AcpiDsExecEndOp during OpRegion parse tree walk
829 ******************************************************************************/
831 ACPI_STATUS
832 AcpiDsEvalRegionOperands (
833 ACPI_WALK_STATE *WalkState,
834 ACPI_PARSE_OBJECT *Op)
836 ACPI_STATUS Status;
837 ACPI_OPERAND_OBJECT *ObjDesc;
838 ACPI_OPERAND_OBJECT *OperandDesc;
839 ACPI_NAMESPACE_NODE *Node;
840 ACPI_PARSE_OBJECT *NextOp;
843 ACPI_FUNCTION_TRACE_PTR (DsEvalRegionOperands, Op);
847 * This is where we evaluate the address and length fields of the
848 * OpRegion declaration
850 Node = Op->Common.Node;
852 /* NextOp points to the op that holds the SpaceID */
854 NextOp = Op->Common.Value.Arg;
856 /* NextOp points to address op */
858 NextOp = NextOp->Common.Next;
860 /* Evaluate/create the address and length operands */
862 Status = AcpiDsCreateOperands (WalkState, NextOp);
863 if (ACPI_FAILURE (Status))
865 return_ACPI_STATUS (Status);
868 /* Resolve the length and address operands to numbers */
870 Status = AcpiExResolveOperands (Op->Common.AmlOpcode,
871 ACPI_WALK_OPERANDS, WalkState);
872 if (ACPI_FAILURE (Status))
874 return_ACPI_STATUS (Status);
877 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
878 AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
879 1, "after AcpiExResolveOperands");
881 ObjDesc = AcpiNsGetAttachedObject (Node);
882 if (!ObjDesc)
884 return_ACPI_STATUS (AE_NOT_EXIST);
888 * Get the length operand and save it
889 * (at Top of stack)
891 OperandDesc = WalkState->Operands[WalkState->NumOperands - 1];
893 ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
894 AcpiUtRemoveReference (OperandDesc);
897 * Get the address and save it
898 * (at top of stack - 1)
900 OperandDesc = WalkState->Operands[WalkState->NumOperands - 2];
902 ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS)
903 OperandDesc->Integer.Value;
904 AcpiUtRemoveReference (OperandDesc);
906 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
907 ObjDesc,
908 ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
909 ObjDesc->Region.Length));
911 /* Now the address and length are valid for this opregion */
913 ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
915 return_ACPI_STATUS (Status);
919 /*******************************************************************************
921 * FUNCTION: AcpiDsEvalDataObjectOperands
923 * PARAMETERS: WalkState - Current walk
924 * Op - A valid DataObject Op object
925 * ObjDesc - DataObject
927 * RETURN: Status
929 * DESCRIPTION: Get the operands and complete the following data object types:
930 * Buffer, Package.
932 ******************************************************************************/
934 ACPI_STATUS
935 AcpiDsEvalDataObjectOperands (
936 ACPI_WALK_STATE *WalkState,
937 ACPI_PARSE_OBJECT *Op,
938 ACPI_OPERAND_OBJECT *ObjDesc)
940 ACPI_STATUS Status;
941 ACPI_OPERAND_OBJECT *ArgDesc;
942 UINT32 Length;
945 ACPI_FUNCTION_TRACE (DsEvalDataObjectOperands);
948 /* The first operand (for all of these data objects) is the length */
950 Status = AcpiDsCreateOperand (WalkState, Op->Common.Value.Arg, 1);
951 if (ACPI_FAILURE (Status))
953 return_ACPI_STATUS (Status);
956 Status = AcpiExResolveOperands (WalkState->Opcode,
957 &(WalkState->Operands [WalkState->NumOperands -1]),
958 WalkState);
959 if (ACPI_FAILURE (Status))
961 return_ACPI_STATUS (Status);
964 /* Extract length operand */
966 ArgDesc = WalkState->Operands [WalkState->NumOperands - 1];
967 Length = (UINT32) ArgDesc->Integer.Value;
969 /* Cleanup for length operand */
971 Status = AcpiDsObjStackPop (1, WalkState);
972 if (ACPI_FAILURE (Status))
974 return_ACPI_STATUS (Status);
977 AcpiUtRemoveReference (ArgDesc);
980 * Create the actual data object
982 switch (Op->Common.AmlOpcode)
984 case AML_BUFFER_OP:
986 Status = AcpiDsBuildInternalBufferObj (WalkState, Op, Length, &ObjDesc);
987 break;
989 case AML_PACKAGE_OP:
990 case AML_VAR_PACKAGE_OP:
992 Status = AcpiDsBuildInternalPackageObj (WalkState, Op, Length, &ObjDesc);
993 break;
995 default:
996 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
999 if (ACPI_SUCCESS (Status))
1002 * Return the object in the WalkState, unless the parent is a package -
1003 * in this case, the return object will be stored in the parse tree
1004 * for the package.
1006 if ((!Op->Common.Parent) ||
1007 ((Op->Common.Parent->Common.AmlOpcode != AML_PACKAGE_OP) &&
1008 (Op->Common.Parent->Common.AmlOpcode != AML_VAR_PACKAGE_OP) &&
1009 (Op->Common.Parent->Common.AmlOpcode != AML_NAME_OP)))
1011 WalkState->ResultObj = ObjDesc;
1015 return_ACPI_STATUS (Status);
1019 /*******************************************************************************
1021 * FUNCTION: AcpiDsExecBeginControlOp
1023 * PARAMETERS: WalkList - The list that owns the walk stack
1024 * Op - The control Op
1026 * RETURN: Status
1028 * DESCRIPTION: Handles all control ops encountered during control method
1029 * execution.
1031 ******************************************************************************/
1033 ACPI_STATUS
1034 AcpiDsExecBeginControlOp (
1035 ACPI_WALK_STATE *WalkState,
1036 ACPI_PARSE_OBJECT *Op)
1038 ACPI_STATUS Status = AE_OK;
1039 ACPI_GENERIC_STATE *ControlState;
1042 ACPI_FUNCTION_NAME (DsExecBeginControlOp);
1045 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", Op,
1046 Op->Common.AmlOpcode, WalkState));
1048 switch (Op->Common.AmlOpcode)
1050 case AML_IF_OP:
1051 case AML_WHILE_OP:
1054 * IF/WHILE: Create a new control state to manage these
1055 * constructs. We need to manage these as a stack, in order
1056 * to handle nesting.
1058 ControlState = AcpiUtCreateControlState ();
1059 if (!ControlState)
1061 Status = AE_NO_MEMORY;
1062 break;
1065 * Save a pointer to the predicate for multiple executions
1066 * of a loop
1068 ControlState->Control.AmlPredicateStart = WalkState->ParserState.Aml - 1;
1069 ControlState->Control.PackageEnd = WalkState->ParserState.PkgEnd;
1070 ControlState->Control.Opcode = Op->Common.AmlOpcode;
1073 /* Push the control state on this walk's control stack */
1075 AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
1076 break;
1078 case AML_ELSE_OP:
1080 /* Predicate is in the state object */
1081 /* If predicate is true, the IF was executed, ignore ELSE part */
1083 if (WalkState->LastPredicate)
1085 Status = AE_CTRL_TRUE;
1088 break;
1090 case AML_RETURN_OP:
1092 break;
1094 default:
1095 break;
1098 return (Status);
1102 /*******************************************************************************
1104 * FUNCTION: AcpiDsExecEndControlOp
1106 * PARAMETERS: WalkList - The list that owns the walk stack
1107 * Op - The control Op
1109 * RETURN: Status
1111 * DESCRIPTION: Handles all control ops encountered during control method
1112 * execution.
1114 ******************************************************************************/
1116 ACPI_STATUS
1117 AcpiDsExecEndControlOp (
1118 ACPI_WALK_STATE *WalkState,
1119 ACPI_PARSE_OBJECT *Op)
1121 ACPI_STATUS Status = AE_OK;
1122 ACPI_GENERIC_STATE *ControlState;
1125 ACPI_FUNCTION_NAME (DsExecEndControlOp);
1128 switch (Op->Common.AmlOpcode)
1130 case AML_IF_OP:
1132 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
1135 * Save the result of the predicate in case there is an
1136 * ELSE to come
1138 WalkState->LastPredicate =
1139 (BOOLEAN) WalkState->ControlState->Common.Value;
1142 * Pop the control state that was created at the start
1143 * of the IF and free it
1145 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1146 AcpiUtDeleteGenericState (ControlState);
1147 break;
1150 case AML_ELSE_OP:
1152 break;
1155 case AML_WHILE_OP:
1157 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
1159 if (WalkState->ControlState->Common.Value)
1161 /* Predicate was true, go back and evaluate it again! */
1163 Status = AE_CTRL_PENDING;
1166 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1167 "[WHILE_OP] termination! Op=%p\n",Op));
1169 /* Pop this control state and free it */
1171 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1173 WalkState->AmlLastWhile = ControlState->Control.AmlPredicateStart;
1174 AcpiUtDeleteGenericState (ControlState);
1175 break;
1178 case AML_RETURN_OP:
1180 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1181 "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
1184 * One optional operand -- the return value
1185 * It can be either an immediate operand or a result that
1186 * has been bubbled up the tree
1188 if (Op->Common.Value.Arg)
1190 /* Since we have a real Return(), delete any implicit return */
1192 AcpiDsClearImplicitReturn (WalkState);
1194 /* Return statement has an immediate operand */
1196 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
1197 if (ACPI_FAILURE (Status))
1199 return (Status);
1203 * If value being returned is a Reference (such as
1204 * an arg or local), resolve it now because it may
1205 * cease to exist at the end of the method.
1207 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
1208 if (ACPI_FAILURE (Status))
1210 return (Status);
1214 * Get the return value and save as the last result
1215 * value. This is the only place where WalkState->ReturnDesc
1216 * is set to anything other than zero!
1218 WalkState->ReturnDesc = WalkState->Operands[0];
1220 else if ((WalkState->Results) &&
1221 (WalkState->Results->Results.NumResults > 0))
1223 /* Since we have a real Return(), delete any implicit return */
1225 AcpiDsClearImplicitReturn (WalkState);
1228 * The return value has come from a previous calculation.
1230 * If value being returned is a Reference (such as
1231 * an arg or local), resolve it now because it may
1232 * cease to exist at the end of the method.
1234 * Allow references created by the Index operator to return unchanged.
1236 if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) == ACPI_DESC_TYPE_OPERAND) &&
1237 (ACPI_GET_OBJECT_TYPE (WalkState->Results->Results.ObjDesc [0]) == ACPI_TYPE_LOCAL_REFERENCE) &&
1238 ((WalkState->Results->Results.ObjDesc [0])->Reference.Opcode != AML_INDEX_OP))
1240 Status = AcpiExResolveToValue (&WalkState->Results->Results.ObjDesc [0], WalkState);
1241 if (ACPI_FAILURE (Status))
1243 return (Status);
1247 WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
1249 else
1251 /* No return operand */
1253 if (WalkState->NumOperands)
1255 AcpiUtRemoveReference (WalkState->Operands [0]);
1258 WalkState->Operands [0] = NULL;
1259 WalkState->NumOperands = 0;
1260 WalkState->ReturnDesc = NULL;
1264 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1265 "Completed RETURN_OP State=%p, RetVal=%p\n",
1266 WalkState, WalkState->ReturnDesc));
1268 /* End the control method execution right now */
1270 Status = AE_CTRL_TERMINATE;
1271 break;
1274 case AML_NOOP_OP:
1276 /* Just do nothing! */
1277 break;
1280 case AML_BREAK_POINT_OP:
1282 /* Call up to the OS service layer to handle this */
1284 Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode");
1286 /* If and when it returns, all done. */
1288 break;
1291 case AML_BREAK_OP:
1292 case AML_CONTINUE_OP: /* ACPI 2.0 */
1295 /* Pop and delete control states until we find a while */
1297 while (WalkState->ControlState &&
1298 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
1300 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1301 AcpiUtDeleteGenericState (ControlState);
1304 /* No while found? */
1306 if (!WalkState->ControlState)
1308 return (AE_AML_NO_WHILE);
1311 /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
1313 WalkState->AmlLastWhile = WalkState->ControlState->Control.PackageEnd;
1315 /* Return status depending on opcode */
1317 if (Op->Common.AmlOpcode == AML_BREAK_OP)
1319 Status = AE_CTRL_BREAK;
1321 else
1323 Status = AE_CTRL_CONTINUE;
1325 break;
1328 default:
1330 ACPI_ERROR ((AE_INFO, "Unknown control opcode=%X Op=%p",
1331 Op->Common.AmlOpcode, Op));
1333 Status = AE_AML_BAD_OPCODE;
1334 break;
1337 return (Status);