1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher support for regions and fields
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __DSOPCODE_C__
56 #define _COMPONENT ACPI_DISPATCHER
57 ACPI_MODULE_NAME ("dsopcode")
59 /* Local prototypes */
62 AcpiDsInitBufferField (
64 ACPI_OPERAND_OBJECT
*ObjDesc
,
65 ACPI_OPERAND_OBJECT
*BufferDesc
,
66 ACPI_OPERAND_OBJECT
*OffsetDesc
,
67 ACPI_OPERAND_OBJECT
*LengthDesc
,
68 ACPI_OPERAND_OBJECT
*ResultDesc
);
71 /*******************************************************************************
73 * FUNCTION: AcpiDsInitializeRegion
75 * PARAMETERS: ObjHandle - Region namespace node
79 * DESCRIPTION: Front end to EvInitializeRegion
81 ******************************************************************************/
84 AcpiDsInitializeRegion (
85 ACPI_HANDLE ObjHandle
)
87 ACPI_OPERAND_OBJECT
*ObjDesc
;
91 ObjDesc
= AcpiNsGetAttachedObject (ObjHandle
);
93 /* Namespace is NOT locked */
95 Status
= AcpiEvInitializeRegion (ObjDesc
, FALSE
);
100 /*******************************************************************************
102 * FUNCTION: AcpiDsInitBufferField
104 * PARAMETERS: AmlOpcode - CreateXxxField
105 * ObjDesc - BufferField object
106 * BufferDesc - Host Buffer
107 * OffsetDesc - Offset into buffer
108 * LengthDesc - Length of field (CREATE_FIELD_OP only)
109 * ResultDesc - Where to store the result
113 * DESCRIPTION: Perform actual initialization of a buffer field
115 ******************************************************************************/
118 AcpiDsInitBufferField (
120 ACPI_OPERAND_OBJECT
*ObjDesc
,
121 ACPI_OPERAND_OBJECT
*BufferDesc
,
122 ACPI_OPERAND_OBJECT
*OffsetDesc
,
123 ACPI_OPERAND_OBJECT
*LengthDesc
,
124 ACPI_OPERAND_OBJECT
*ResultDesc
)
133 ACPI_FUNCTION_TRACE_PTR (DsInitBufferField
, ObjDesc
);
136 /* Host object must be a Buffer */
138 if (BufferDesc
->Common
.Type
!= ACPI_TYPE_BUFFER
)
140 ACPI_ERROR ((AE_INFO
,
141 "Target of Create Field is not a Buffer object - %s",
142 AcpiUtGetObjectTypeName (BufferDesc
)));
144 Status
= AE_AML_OPERAND_TYPE
;
149 * The last parameter to all of these opcodes (ResultDesc) started
150 * out as a NameString, and should therefore now be a NS node
151 * after resolution in AcpiExResolveOperands().
153 if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc
) != ACPI_DESC_TYPE_NAMED
)
155 ACPI_ERROR ((AE_INFO
,
156 "(%s) destination not a NS Node [%s]",
157 AcpiPsGetOpcodeName (AmlOpcode
),
158 AcpiUtGetDescriptorName (ResultDesc
)));
160 Status
= AE_AML_OPERAND_TYPE
;
164 Offset
= (UINT32
) OffsetDesc
->Integer
.Value
;
167 * Setup the Bit offsets and counts, according to the opcode
171 case AML_CREATE_FIELD_OP
:
173 /* Offset is in bits, count is in bits */
175 FieldFlags
= AML_FIELD_ACCESS_BYTE
;
177 BitCount
= (UINT32
) LengthDesc
->Integer
.Value
;
179 /* Must have a valid (>0) bit count */
183 ACPI_ERROR ((AE_INFO
,
184 "Attempt to CreateField of length zero"));
185 Status
= AE_AML_OPERAND_VALUE
;
190 case AML_CREATE_BIT_FIELD_OP
:
192 /* Offset is in bits, Field is one bit */
196 FieldFlags
= AML_FIELD_ACCESS_BYTE
;
199 case AML_CREATE_BYTE_FIELD_OP
:
201 /* Offset is in bytes, field is one byte */
203 BitOffset
= 8 * Offset
;
205 FieldFlags
= AML_FIELD_ACCESS_BYTE
;
208 case AML_CREATE_WORD_FIELD_OP
:
210 /* Offset is in bytes, field is one word */
212 BitOffset
= 8 * Offset
;
214 FieldFlags
= AML_FIELD_ACCESS_WORD
;
217 case AML_CREATE_DWORD_FIELD_OP
:
219 /* Offset is in bytes, field is one dword */
221 BitOffset
= 8 * Offset
;
223 FieldFlags
= AML_FIELD_ACCESS_DWORD
;
226 case AML_CREATE_QWORD_FIELD_OP
:
228 /* Offset is in bytes, field is one qword */
230 BitOffset
= 8 * Offset
;
232 FieldFlags
= AML_FIELD_ACCESS_QWORD
;
237 ACPI_ERROR ((AE_INFO
,
238 "Unknown field creation opcode 0x%02X",
240 Status
= AE_AML_BAD_OPCODE
;
244 /* Entire field must fit within the current length of the buffer */
246 if ((BitOffset
+ BitCount
) >
247 (8 * (UINT32
) BufferDesc
->Buffer
.Length
))
249 ACPI_ERROR ((AE_INFO
,
250 "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
251 AcpiUtGetNodeName (ResultDesc
),
252 BitOffset
+ BitCount
,
253 AcpiUtGetNodeName (BufferDesc
->Buffer
.Node
),
254 8 * (UINT32
) BufferDesc
->Buffer
.Length
));
255 Status
= AE_AML_BUFFER_LIMIT
;
260 * Initialize areas of the field object that are common to all fields
261 * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK),
262 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
264 Status
= AcpiExPrepCommonFieldObject (ObjDesc
, FieldFlags
, 0,
265 BitOffset
, BitCount
);
266 if (ACPI_FAILURE (Status
))
271 ObjDesc
->BufferField
.BufferObj
= BufferDesc
;
273 /* Reference count for BufferDesc inherits ObjDesc count */
275 BufferDesc
->Common
.ReferenceCount
= (UINT16
)
276 (BufferDesc
->Common
.ReferenceCount
+ ObjDesc
->Common
.ReferenceCount
);
281 /* Always delete the operands */
283 AcpiUtRemoveReference (OffsetDesc
);
284 AcpiUtRemoveReference (BufferDesc
);
286 if (AmlOpcode
== AML_CREATE_FIELD_OP
)
288 AcpiUtRemoveReference (LengthDesc
);
291 /* On failure, delete the result descriptor */
293 if (ACPI_FAILURE (Status
))
295 AcpiUtRemoveReference (ResultDesc
); /* Result descriptor */
299 /* Now the address and length are valid for this BufferField */
301 ObjDesc
->BufferField
.Flags
|= AOPOBJ_DATA_VALID
;
304 return_ACPI_STATUS (Status
);
308 /*******************************************************************************
310 * FUNCTION: AcpiDsEvalBufferFieldOperands
312 * PARAMETERS: WalkState - Current walk
313 * Op - A valid BufferField Op object
317 * DESCRIPTION: Get BufferField Buffer and Index
318 * Called from AcpiDsExecEndOp during BufferField parse tree walk
320 ******************************************************************************/
323 AcpiDsEvalBufferFieldOperands (
324 ACPI_WALK_STATE
*WalkState
,
325 ACPI_PARSE_OBJECT
*Op
)
328 ACPI_OPERAND_OBJECT
*ObjDesc
;
329 ACPI_NAMESPACE_NODE
*Node
;
330 ACPI_PARSE_OBJECT
*NextOp
;
333 ACPI_FUNCTION_TRACE_PTR (DsEvalBufferFieldOperands
, Op
);
337 * This is where we evaluate the address and length fields of the
338 * CreateXxxField declaration
340 Node
= Op
->Common
.Node
;
342 /* NextOp points to the op that holds the Buffer */
344 NextOp
= Op
->Common
.Value
.Arg
;
346 /* Evaluate/create the address and length operands */
348 Status
= AcpiDsCreateOperands (WalkState
, NextOp
);
349 if (ACPI_FAILURE (Status
))
351 return_ACPI_STATUS (Status
);
354 ObjDesc
= AcpiNsGetAttachedObject (Node
);
357 return_ACPI_STATUS (AE_NOT_EXIST
);
360 /* Resolve the operands */
362 Status
= AcpiExResolveOperands (Op
->Common
.AmlOpcode
,
363 ACPI_WALK_OPERANDS
, WalkState
);
364 if (ACPI_FAILURE (Status
))
366 ACPI_ERROR ((AE_INFO
, "(%s) bad operand(s), status 0x%X",
367 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
), Status
));
369 return_ACPI_STATUS (Status
);
372 /* Initialize the Buffer Field */
374 if (Op
->Common
.AmlOpcode
== AML_CREATE_FIELD_OP
)
376 /* NOTE: Slightly different operands for this opcode */
378 Status
= AcpiDsInitBufferField (Op
->Common
.AmlOpcode
, ObjDesc
,
379 WalkState
->Operands
[0], WalkState
->Operands
[1],
380 WalkState
->Operands
[2], WalkState
->Operands
[3]);
384 /* All other, CreateXxxField opcodes */
386 Status
= AcpiDsInitBufferField (Op
->Common
.AmlOpcode
, ObjDesc
,
387 WalkState
->Operands
[0], WalkState
->Operands
[1],
388 NULL
, WalkState
->Operands
[2]);
391 return_ACPI_STATUS (Status
);
395 /*******************************************************************************
397 * FUNCTION: AcpiDsEvalRegionOperands
399 * PARAMETERS: WalkState - Current walk
400 * Op - A valid region Op object
404 * DESCRIPTION: Get region address and length
405 * Called from AcpiDsExecEndOp during OpRegion parse tree walk
407 ******************************************************************************/
410 AcpiDsEvalRegionOperands (
411 ACPI_WALK_STATE
*WalkState
,
412 ACPI_PARSE_OBJECT
*Op
)
415 ACPI_OPERAND_OBJECT
*ObjDesc
;
416 ACPI_OPERAND_OBJECT
*OperandDesc
;
417 ACPI_NAMESPACE_NODE
*Node
;
418 ACPI_PARSE_OBJECT
*NextOp
;
421 ACPI_FUNCTION_TRACE_PTR (DsEvalRegionOperands
, Op
);
425 * This is where we evaluate the address and length fields of the
426 * OpRegion declaration
428 Node
= Op
->Common
.Node
;
430 /* NextOp points to the op that holds the SpaceID */
432 NextOp
= Op
->Common
.Value
.Arg
;
434 /* NextOp points to address op */
436 NextOp
= NextOp
->Common
.Next
;
438 /* Evaluate/create the address and length operands */
440 Status
= AcpiDsCreateOperands (WalkState
, NextOp
);
441 if (ACPI_FAILURE (Status
))
443 return_ACPI_STATUS (Status
);
446 /* Resolve the length and address operands to numbers */
448 Status
= AcpiExResolveOperands (Op
->Common
.AmlOpcode
,
449 ACPI_WALK_OPERANDS
, WalkState
);
450 if (ACPI_FAILURE (Status
))
452 return_ACPI_STATUS (Status
);
455 ObjDesc
= AcpiNsGetAttachedObject (Node
);
458 return_ACPI_STATUS (AE_NOT_EXIST
);
462 * Get the length operand and save it
465 OperandDesc
= WalkState
->Operands
[WalkState
->NumOperands
- 1];
467 ObjDesc
->Region
.Length
= (UINT32
) OperandDesc
->Integer
.Value
;
468 AcpiUtRemoveReference (OperandDesc
);
471 * Get the address and save it
472 * (at top of stack - 1)
474 OperandDesc
= WalkState
->Operands
[WalkState
->NumOperands
- 2];
476 ObjDesc
->Region
.Address
= (ACPI_PHYSICAL_ADDRESS
)
477 OperandDesc
->Integer
.Value
;
478 AcpiUtRemoveReference (OperandDesc
);
480 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
482 ACPI_FORMAT_NATIVE_UINT (ObjDesc
->Region
.Address
),
483 ObjDesc
->Region
.Length
));
485 /* Now the address and length are valid for this opregion */
487 ObjDesc
->Region
.Flags
|= AOPOBJ_DATA_VALID
;
489 return_ACPI_STATUS (Status
);
493 /*******************************************************************************
495 * FUNCTION: AcpiDsEvalTableRegionOperands
497 * PARAMETERS: WalkState - Current walk
498 * Op - A valid region Op object
502 * DESCRIPTION: Get region address and length.
503 * Called from AcpiDsExecEndOp during DataTableRegion parse
506 ******************************************************************************/
509 AcpiDsEvalTableRegionOperands (
510 ACPI_WALK_STATE
*WalkState
,
511 ACPI_PARSE_OBJECT
*Op
)
514 ACPI_OPERAND_OBJECT
*ObjDesc
;
515 ACPI_OPERAND_OBJECT
**Operand
;
516 ACPI_NAMESPACE_NODE
*Node
;
517 ACPI_PARSE_OBJECT
*NextOp
;
519 ACPI_TABLE_HEADER
*Table
;
522 ACPI_FUNCTION_TRACE_PTR (DsEvalTableRegionOperands
, Op
);
526 * This is where we evaluate the Signature string, OemId string,
527 * and OemTableId string of the Data Table Region declaration
529 Node
= Op
->Common
.Node
;
531 /* NextOp points to Signature string op */
533 NextOp
= Op
->Common
.Value
.Arg
;
536 * Evaluate/create the Signature string, OemId string,
537 * and OemTableId string operands
539 Status
= AcpiDsCreateOperands (WalkState
, NextOp
);
540 if (ACPI_FAILURE (Status
))
542 return_ACPI_STATUS (Status
);
546 * Resolve the Signature string, OemId string,
547 * and OemTableId string operands
549 Status
= AcpiExResolveOperands (Op
->Common
.AmlOpcode
,
550 ACPI_WALK_OPERANDS
, WalkState
);
551 if (ACPI_FAILURE (Status
))
553 return_ACPI_STATUS (Status
);
556 Operand
= &WalkState
->Operands
[0];
558 /* Find the ACPI table */
560 Status
= AcpiTbFindTable (Operand
[0]->String
.Pointer
,
561 Operand
[1]->String
.Pointer
, Operand
[2]->String
.Pointer
,
563 if (ACPI_FAILURE (Status
))
565 return_ACPI_STATUS (Status
);
568 AcpiUtRemoveReference (Operand
[0]);
569 AcpiUtRemoveReference (Operand
[1]);
570 AcpiUtRemoveReference (Operand
[2]);
572 Status
= AcpiGetTableByIndex (TableIndex
, &Table
);
573 if (ACPI_FAILURE (Status
))
575 return_ACPI_STATUS (Status
);
578 ObjDesc
= AcpiNsGetAttachedObject (Node
);
581 return_ACPI_STATUS (AE_NOT_EXIST
);
584 ObjDesc
->Region
.Address
= (ACPI_PHYSICAL_ADDRESS
) ACPI_TO_INTEGER (Table
);
585 ObjDesc
->Region
.Length
= Table
->Length
;
587 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
589 ACPI_FORMAT_NATIVE_UINT (ObjDesc
->Region
.Address
),
590 ObjDesc
->Region
.Length
));
592 /* Now the address and length are valid for this opregion */
594 ObjDesc
->Region
.Flags
|= AOPOBJ_DATA_VALID
;
596 return_ACPI_STATUS (Status
);
600 /*******************************************************************************
602 * FUNCTION: AcpiDsEvalDataObjectOperands
604 * PARAMETERS: WalkState - Current walk
605 * Op - A valid DataObject Op object
606 * ObjDesc - DataObject
610 * DESCRIPTION: Get the operands and complete the following data object types:
613 ******************************************************************************/
616 AcpiDsEvalDataObjectOperands (
617 ACPI_WALK_STATE
*WalkState
,
618 ACPI_PARSE_OBJECT
*Op
,
619 ACPI_OPERAND_OBJECT
*ObjDesc
)
622 ACPI_OPERAND_OBJECT
*ArgDesc
;
626 ACPI_FUNCTION_TRACE (DsEvalDataObjectOperands
);
629 /* The first operand (for all of these data objects) is the length */
632 * Set proper index into operand stack for AcpiDsObjStackPush
633 * invoked inside AcpiDsCreateOperand.
635 WalkState
->OperandIndex
= WalkState
->NumOperands
;
637 Status
= AcpiDsCreateOperand (WalkState
, Op
->Common
.Value
.Arg
, 1);
638 if (ACPI_FAILURE (Status
))
640 return_ACPI_STATUS (Status
);
643 Status
= AcpiExResolveOperands (WalkState
->Opcode
,
644 &(WalkState
->Operands
[WalkState
->NumOperands
-1]),
646 if (ACPI_FAILURE (Status
))
648 return_ACPI_STATUS (Status
);
651 /* Extract length operand */
653 ArgDesc
= WalkState
->Operands
[WalkState
->NumOperands
- 1];
654 Length
= (UINT32
) ArgDesc
->Integer
.Value
;
656 /* Cleanup for length operand */
658 Status
= AcpiDsObjStackPop (1, WalkState
);
659 if (ACPI_FAILURE (Status
))
661 return_ACPI_STATUS (Status
);
664 AcpiUtRemoveReference (ArgDesc
);
667 * Create the actual data object
669 switch (Op
->Common
.AmlOpcode
)
673 Status
= AcpiDsBuildInternalBufferObj (WalkState
, Op
, Length
, &ObjDesc
);
677 case AML_VAR_PACKAGE_OP
:
679 Status
= AcpiDsBuildInternalPackageObj (WalkState
, Op
, Length
, &ObjDesc
);
684 return_ACPI_STATUS (AE_AML_BAD_OPCODE
);
687 if (ACPI_SUCCESS (Status
))
690 * Return the object in the WalkState, unless the parent is a package -
691 * in this case, the return object will be stored in the parse tree
694 if ((!Op
->Common
.Parent
) ||
695 ((Op
->Common
.Parent
->Common
.AmlOpcode
!= AML_PACKAGE_OP
) &&
696 (Op
->Common
.Parent
->Common
.AmlOpcode
!= AML_VAR_PACKAGE_OP
) &&
697 (Op
->Common
.Parent
->Common
.AmlOpcode
!= AML_NAME_OP
)))
699 WalkState
->ResultObj
= ObjDesc
;
703 return_ACPI_STATUS (Status
);
707 /*******************************************************************************
709 * FUNCTION: AcpiDsEvalBankFieldOperands
711 * PARAMETERS: WalkState - Current walk
712 * Op - A valid BankField Op object
716 * DESCRIPTION: Get BankField BankValue
717 * Called from AcpiDsExecEndOp during BankField parse tree walk
719 ******************************************************************************/
722 AcpiDsEvalBankFieldOperands (
723 ACPI_WALK_STATE
*WalkState
,
724 ACPI_PARSE_OBJECT
*Op
)
727 ACPI_OPERAND_OBJECT
*ObjDesc
;
728 ACPI_OPERAND_OBJECT
*OperandDesc
;
729 ACPI_NAMESPACE_NODE
*Node
;
730 ACPI_PARSE_OBJECT
*NextOp
;
731 ACPI_PARSE_OBJECT
*Arg
;
734 ACPI_FUNCTION_TRACE_PTR (DsEvalBankFieldOperands
, Op
);
738 * This is where we evaluate the BankValue field of the
739 * BankField declaration
742 /* NextOp points to the op that holds the Region */
744 NextOp
= Op
->Common
.Value
.Arg
;
746 /* NextOp points to the op that holds the Bank Register */
748 NextOp
= NextOp
->Common
.Next
;
750 /* NextOp points to the op that holds the Bank Value */
752 NextOp
= NextOp
->Common
.Next
;
755 * Set proper index into operand stack for AcpiDsObjStackPush
756 * invoked inside AcpiDsCreateOperand.
758 * We use WalkState->Operands[0] to store the evaluated BankValue
760 WalkState
->OperandIndex
= 0;
762 Status
= AcpiDsCreateOperand (WalkState
, NextOp
, 0);
763 if (ACPI_FAILURE (Status
))
765 return_ACPI_STATUS (Status
);
768 Status
= AcpiExResolveToValue (&WalkState
->Operands
[0], WalkState
);
769 if (ACPI_FAILURE (Status
))
771 return_ACPI_STATUS (Status
);
774 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS
,
775 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
), 1);
777 * Get the BankValue operand and save it
780 OperandDesc
= WalkState
->Operands
[0];
782 /* Arg points to the start Bank Field */
784 Arg
= AcpiPsGetArg (Op
, 4);
787 /* Ignore OFFSET and ACCESSAS terms here */
789 if (Arg
->Common
.AmlOpcode
== AML_INT_NAMEDFIELD_OP
)
791 Node
= Arg
->Common
.Node
;
793 ObjDesc
= AcpiNsGetAttachedObject (Node
);
796 return_ACPI_STATUS (AE_NOT_EXIST
);
799 ObjDesc
->BankField
.Value
= (UINT32
) OperandDesc
->Integer
.Value
;
802 /* Move to next field in the list */
804 Arg
= Arg
->Common
.Next
;
807 AcpiUtRemoveReference (OperandDesc
);
808 return_ACPI_STATUS (Status
);