1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher support for regions and fields
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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.
54 #define _COMPONENT ACPI_DISPATCHER
55 ACPI_MODULE_NAME ("dsopcode")
57 /* Local prototypes */
60 AcpiDsInitBufferField (
62 ACPI_OPERAND_OBJECT
*ObjDesc
,
63 ACPI_OPERAND_OBJECT
*BufferDesc
,
64 ACPI_OPERAND_OBJECT
*OffsetDesc
,
65 ACPI_OPERAND_OBJECT
*LengthDesc
,
66 ACPI_OPERAND_OBJECT
*ResultDesc
);
69 /*******************************************************************************
71 * FUNCTION: AcpiDsInitializeRegion
73 * PARAMETERS: ObjHandle - Region namespace node
77 * DESCRIPTION: Front end to EvInitializeRegion
79 ******************************************************************************/
82 AcpiDsInitializeRegion (
83 ACPI_HANDLE ObjHandle
)
85 ACPI_OPERAND_OBJECT
*ObjDesc
;
89 ObjDesc
= AcpiNsGetAttachedObject (ObjHandle
);
91 /* Namespace is NOT locked */
93 Status
= AcpiEvInitializeRegion (ObjDesc
);
98 /*******************************************************************************
100 * FUNCTION: AcpiDsInitBufferField
102 * PARAMETERS: AmlOpcode - CreateXxxField
103 * ObjDesc - BufferField object
104 * BufferDesc - Host Buffer
105 * OffsetDesc - Offset into buffer
106 * LengthDesc - Length of field (CREATE_FIELD_OP only)
107 * ResultDesc - Where to store the result
111 * DESCRIPTION: Perform actual initialization of a buffer field
113 ******************************************************************************/
116 AcpiDsInitBufferField (
118 ACPI_OPERAND_OBJECT
*ObjDesc
,
119 ACPI_OPERAND_OBJECT
*BufferDesc
,
120 ACPI_OPERAND_OBJECT
*OffsetDesc
,
121 ACPI_OPERAND_OBJECT
*LengthDesc
,
122 ACPI_OPERAND_OBJECT
*ResultDesc
)
131 ACPI_FUNCTION_TRACE_PTR (DsInitBufferField
, ObjDesc
);
134 /* Host object must be a Buffer */
136 if (BufferDesc
->Common
.Type
!= ACPI_TYPE_BUFFER
)
138 ACPI_ERROR ((AE_INFO
,
139 "Target of Create Field is not a Buffer object - %s",
140 AcpiUtGetObjectTypeName (BufferDesc
)));
142 Status
= AE_AML_OPERAND_TYPE
;
147 * The last parameter to all of these opcodes (ResultDesc) started
148 * out as a NameString, and should therefore now be a NS node
149 * after resolution in AcpiExResolveOperands().
151 if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc
) != ACPI_DESC_TYPE_NAMED
)
153 ACPI_ERROR ((AE_INFO
,
154 "(%s) destination not a NS Node [%s]",
155 AcpiPsGetOpcodeName (AmlOpcode
),
156 AcpiUtGetDescriptorName (ResultDesc
)));
158 Status
= AE_AML_OPERAND_TYPE
;
162 Offset
= (UINT32
) OffsetDesc
->Integer
.Value
;
165 * Setup the Bit offsets and counts, according to the opcode
169 case AML_CREATE_FIELD_OP
:
171 /* Offset is in bits, count is in bits */
173 FieldFlags
= AML_FIELD_ACCESS_BYTE
;
175 BitCount
= (UINT32
) LengthDesc
->Integer
.Value
;
177 /* Must have a valid (>0) bit count */
181 ACPI_ERROR ((AE_INFO
,
182 "Attempt to CreateField of length zero"));
183 Status
= AE_AML_OPERAND_VALUE
;
188 case AML_CREATE_BIT_FIELD_OP
:
190 /* Offset is in bits, Field is one bit */
194 FieldFlags
= AML_FIELD_ACCESS_BYTE
;
197 case AML_CREATE_BYTE_FIELD_OP
:
199 /* Offset is in bytes, field is one byte */
201 BitOffset
= 8 * Offset
;
203 FieldFlags
= AML_FIELD_ACCESS_BYTE
;
206 case AML_CREATE_WORD_FIELD_OP
:
208 /* Offset is in bytes, field is one word */
210 BitOffset
= 8 * Offset
;
212 FieldFlags
= AML_FIELD_ACCESS_WORD
;
215 case AML_CREATE_DWORD_FIELD_OP
:
217 /* Offset is in bytes, field is one dword */
219 BitOffset
= 8 * Offset
;
221 FieldFlags
= AML_FIELD_ACCESS_DWORD
;
224 case AML_CREATE_QWORD_FIELD_OP
:
226 /* Offset is in bytes, field is one qword */
228 BitOffset
= 8 * Offset
;
230 FieldFlags
= AML_FIELD_ACCESS_QWORD
;
235 ACPI_ERROR ((AE_INFO
,
236 "Unknown field creation opcode 0x%02X",
238 Status
= AE_AML_BAD_OPCODE
;
242 /* Entire field must fit within the current length of the buffer */
244 if ((BitOffset
+ BitCount
) >
245 (8 * (UINT32
) BufferDesc
->Buffer
.Length
))
247 ACPI_ERROR ((AE_INFO
,
248 "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
249 AcpiUtGetNodeName (ResultDesc
),
250 BitOffset
+ BitCount
,
251 AcpiUtGetNodeName (BufferDesc
->Buffer
.Node
),
252 8 * (UINT32
) BufferDesc
->Buffer
.Length
));
253 Status
= AE_AML_BUFFER_LIMIT
;
258 * Initialize areas of the field object that are common to all fields
259 * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK),
260 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
262 Status
= AcpiExPrepCommonFieldObject (
263 ObjDesc
, FieldFlags
, 0, BitOffset
, BitCount
);
264 if (ACPI_FAILURE (Status
))
269 ObjDesc
->BufferField
.BufferObj
= BufferDesc
;
271 /* Reference count for BufferDesc inherits ObjDesc count */
273 BufferDesc
->Common
.ReferenceCount
= (UINT16
)
274 (BufferDesc
->Common
.ReferenceCount
+ ObjDesc
->Common
.ReferenceCount
);
279 /* Always delete the operands */
281 AcpiUtRemoveReference (OffsetDesc
);
282 AcpiUtRemoveReference (BufferDesc
);
284 if (AmlOpcode
== AML_CREATE_FIELD_OP
)
286 AcpiUtRemoveReference (LengthDesc
);
289 /* On failure, delete the result descriptor */
291 if (ACPI_FAILURE (Status
))
293 AcpiUtRemoveReference (ResultDesc
); /* Result descriptor */
297 /* Now the address and length are valid for this BufferField */
299 ObjDesc
->BufferField
.Flags
|= AOPOBJ_DATA_VALID
;
302 return_ACPI_STATUS (Status
);
306 /*******************************************************************************
308 * FUNCTION: AcpiDsEvalBufferFieldOperands
310 * PARAMETERS: WalkState - Current walk
311 * Op - A valid BufferField Op object
315 * DESCRIPTION: Get BufferField Buffer and Index
316 * Called from AcpiDsExecEndOp during BufferField parse tree walk
318 ******************************************************************************/
321 AcpiDsEvalBufferFieldOperands (
322 ACPI_WALK_STATE
*WalkState
,
323 ACPI_PARSE_OBJECT
*Op
)
326 ACPI_OPERAND_OBJECT
*ObjDesc
;
327 ACPI_NAMESPACE_NODE
*Node
;
328 ACPI_PARSE_OBJECT
*NextOp
;
331 ACPI_FUNCTION_TRACE_PTR (DsEvalBufferFieldOperands
, Op
);
335 * This is where we evaluate the address and length fields of the
336 * CreateXxxField declaration
338 Node
= Op
->Common
.Node
;
340 /* NextOp points to the op that holds the Buffer */
342 NextOp
= Op
->Common
.Value
.Arg
;
344 /* Evaluate/create the address and length operands */
346 Status
= AcpiDsCreateOperands (WalkState
, NextOp
);
347 if (ACPI_FAILURE (Status
))
349 return_ACPI_STATUS (Status
);
352 ObjDesc
= AcpiNsGetAttachedObject (Node
);
355 return_ACPI_STATUS (AE_NOT_EXIST
);
358 /* Resolve the operands */
360 Status
= AcpiExResolveOperands (
361 Op
->Common
.AmlOpcode
, ACPI_WALK_OPERANDS
, WalkState
);
362 if (ACPI_FAILURE (Status
))
364 ACPI_ERROR ((AE_INFO
, "(%s) bad operand(s), status 0x%X",
365 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
), Status
));
367 return_ACPI_STATUS (Status
);
370 /* Initialize the Buffer Field */
372 if (Op
->Common
.AmlOpcode
== AML_CREATE_FIELD_OP
)
374 /* NOTE: Slightly different operands for this opcode */
376 Status
= AcpiDsInitBufferField (Op
->Common
.AmlOpcode
, ObjDesc
,
377 WalkState
->Operands
[0], WalkState
->Operands
[1],
378 WalkState
->Operands
[2], WalkState
->Operands
[3]);
382 /* All other, CreateXxxField opcodes */
384 Status
= AcpiDsInitBufferField (Op
->Common
.AmlOpcode
, ObjDesc
,
385 WalkState
->Operands
[0], WalkState
->Operands
[1],
386 NULL
, WalkState
->Operands
[2]);
389 return_ACPI_STATUS (Status
);
393 /*******************************************************************************
395 * FUNCTION: AcpiDsEvalRegionOperands
397 * PARAMETERS: WalkState - Current walk
398 * Op - A valid region Op object
402 * DESCRIPTION: Get region address and length
403 * Called from AcpiDsExecEndOp during OpRegion parse tree walk
405 ******************************************************************************/
408 AcpiDsEvalRegionOperands (
409 ACPI_WALK_STATE
*WalkState
,
410 ACPI_PARSE_OBJECT
*Op
)
413 ACPI_OPERAND_OBJECT
*ObjDesc
;
414 ACPI_OPERAND_OBJECT
*OperandDesc
;
415 ACPI_NAMESPACE_NODE
*Node
;
416 ACPI_PARSE_OBJECT
*NextOp
;
419 ACPI_FUNCTION_TRACE_PTR (DsEvalRegionOperands
, Op
);
423 * This is where we evaluate the address and length fields of the
424 * OpRegion declaration
426 Node
= Op
->Common
.Node
;
428 /* NextOp points to the op that holds the SpaceID */
430 NextOp
= Op
->Common
.Value
.Arg
;
432 /* NextOp points to address op */
434 NextOp
= NextOp
->Common
.Next
;
436 /* Evaluate/create the address and length operands */
438 Status
= AcpiDsCreateOperands (WalkState
, NextOp
);
439 if (ACPI_FAILURE (Status
))
441 return_ACPI_STATUS (Status
);
444 /* Resolve the length and address operands to numbers */
446 Status
= AcpiExResolveOperands (
447 Op
->Common
.AmlOpcode
, ACPI_WALK_OPERANDS
, WalkState
);
448 if (ACPI_FAILURE (Status
))
450 return_ACPI_STATUS (Status
);
453 ObjDesc
= AcpiNsGetAttachedObject (Node
);
456 return_ACPI_STATUS (AE_NOT_EXIST
);
460 * Get the length operand and save it
463 OperandDesc
= WalkState
->Operands
[WalkState
->NumOperands
- 1];
465 ObjDesc
->Region
.Length
= (UINT32
) OperandDesc
->Integer
.Value
;
466 AcpiUtRemoveReference (OperandDesc
);
469 * Get the address and save it
470 * (at top of stack - 1)
472 OperandDesc
= WalkState
->Operands
[WalkState
->NumOperands
- 2];
474 ObjDesc
->Region
.Address
= (ACPI_PHYSICAL_ADDRESS
)
475 OperandDesc
->Integer
.Value
;
476 AcpiUtRemoveReference (OperandDesc
);
478 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
479 ObjDesc
, ACPI_FORMAT_UINT64 (ObjDesc
->Region
.Address
),
480 ObjDesc
->Region
.Length
));
482 /* Now the address and length are valid for this opregion */
484 ObjDesc
->Region
.Flags
|= AOPOBJ_DATA_VALID
;
485 return_ACPI_STATUS (Status
);
489 /*******************************************************************************
491 * FUNCTION: AcpiDsEvalTableRegionOperands
493 * PARAMETERS: WalkState - Current walk
494 * Op - A valid region Op object
498 * DESCRIPTION: Get region address and length.
499 * Called from AcpiDsExecEndOp during DataTableRegion parse
502 ******************************************************************************/
505 AcpiDsEvalTableRegionOperands (
506 ACPI_WALK_STATE
*WalkState
,
507 ACPI_PARSE_OBJECT
*Op
)
510 ACPI_OPERAND_OBJECT
*ObjDesc
;
511 ACPI_OPERAND_OBJECT
**Operand
;
512 ACPI_NAMESPACE_NODE
*Node
;
513 ACPI_PARSE_OBJECT
*NextOp
;
514 ACPI_TABLE_HEADER
*Table
;
518 ACPI_FUNCTION_TRACE_PTR (DsEvalTableRegionOperands
, Op
);
522 * This is where we evaluate the Signature string, OemId string,
523 * and OemTableId string of the Data Table Region declaration
525 Node
= Op
->Common
.Node
;
527 /* NextOp points to Signature string op */
529 NextOp
= Op
->Common
.Value
.Arg
;
532 * Evaluate/create the Signature string, OemId string,
533 * and OemTableId string operands
535 Status
= AcpiDsCreateOperands (WalkState
, NextOp
);
536 if (ACPI_FAILURE (Status
))
538 return_ACPI_STATUS (Status
);
541 Operand
= &WalkState
->Operands
[0];
544 * Resolve the Signature string, OemId string,
545 * and OemTableId string operands
547 Status
= AcpiExResolveOperands (
548 Op
->Common
.AmlOpcode
, ACPI_WALK_OPERANDS
, WalkState
);
549 if (ACPI_FAILURE (Status
))
554 /* Find the ACPI table */
556 Status
= AcpiTbFindTable (
557 Operand
[0]->String
.Pointer
,
558 Operand
[1]->String
.Pointer
,
559 Operand
[2]->String
.Pointer
, &TableIndex
);
560 if (ACPI_FAILURE (Status
))
562 if (Status
== AE_NOT_FOUND
)
564 ACPI_ERROR ((AE_INFO
,
565 "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
566 Operand
[0]->String
.Pointer
,
567 Operand
[1]->String
.Pointer
,
568 Operand
[2]->String
.Pointer
));
573 Status
= AcpiGetTableByIndex (TableIndex
, &Table
);
574 if (ACPI_FAILURE (Status
))
579 ObjDesc
= AcpiNsGetAttachedObject (Node
);
582 Status
= AE_NOT_EXIST
;
586 ObjDesc
->Region
.Address
= ACPI_PTR_TO_PHYSADDR (Table
);
587 ObjDesc
->Region
.Length
= Table
->Length
;
589 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
590 ObjDesc
, ACPI_FORMAT_UINT64 (ObjDesc
->Region
.Address
),
591 ObjDesc
->Region
.Length
));
593 /* Now the address and length are valid for this opregion */
595 ObjDesc
->Region
.Flags
|= AOPOBJ_DATA_VALID
;
598 AcpiUtRemoveReference (Operand
[0]);
599 AcpiUtRemoveReference (Operand
[1]);
600 AcpiUtRemoveReference (Operand
[2]);
602 return_ACPI_STATUS (Status
);
606 /*******************************************************************************
608 * FUNCTION: AcpiDsEvalDataObjectOperands
610 * PARAMETERS: WalkState - Current walk
611 * Op - A valid DataObject Op object
612 * ObjDesc - DataObject
616 * DESCRIPTION: Get the operands and complete the following data object types:
619 ******************************************************************************/
622 AcpiDsEvalDataObjectOperands (
623 ACPI_WALK_STATE
*WalkState
,
624 ACPI_PARSE_OBJECT
*Op
,
625 ACPI_OPERAND_OBJECT
*ObjDesc
)
628 ACPI_OPERAND_OBJECT
*ArgDesc
;
632 ACPI_FUNCTION_TRACE (DsEvalDataObjectOperands
);
635 /* The first operand (for all of these data objects) is the length */
638 * Set proper index into operand stack for AcpiDsObjStackPush
639 * invoked inside AcpiDsCreateOperand.
641 WalkState
->OperandIndex
= WalkState
->NumOperands
;
643 Status
= AcpiDsCreateOperand (WalkState
, Op
->Common
.Value
.Arg
, 1);
644 if (ACPI_FAILURE (Status
))
646 return_ACPI_STATUS (Status
);
649 Status
= AcpiExResolveOperands (WalkState
->Opcode
,
650 &(WalkState
->Operands
[WalkState
->NumOperands
-1]),
652 if (ACPI_FAILURE (Status
))
654 return_ACPI_STATUS (Status
);
657 /* Extract length operand */
659 ArgDesc
= WalkState
->Operands
[WalkState
->NumOperands
- 1];
660 Length
= (UINT32
) ArgDesc
->Integer
.Value
;
662 /* Cleanup for length operand */
664 Status
= AcpiDsObjStackPop (1, WalkState
);
665 if (ACPI_FAILURE (Status
))
667 return_ACPI_STATUS (Status
);
670 AcpiUtRemoveReference (ArgDesc
);
673 * Create the actual data object
675 switch (Op
->Common
.AmlOpcode
)
679 Status
= AcpiDsBuildInternalBufferObj (
680 WalkState
, Op
, Length
, &ObjDesc
);
684 case AML_VAR_PACKAGE_OP
:
686 Status
= AcpiDsBuildInternalPackageObj (
687 WalkState
, Op
, Length
, &ObjDesc
);
692 return_ACPI_STATUS (AE_AML_BAD_OPCODE
);
695 if (ACPI_SUCCESS (Status
))
698 * Return the object in the WalkState, unless the parent is a package -
699 * in this case, the return object will be stored in the parse tree
702 if ((!Op
->Common
.Parent
) ||
703 ((Op
->Common
.Parent
->Common
.AmlOpcode
!= AML_PACKAGE_OP
) &&
704 (Op
->Common
.Parent
->Common
.AmlOpcode
!= AML_VAR_PACKAGE_OP
) &&
705 (Op
->Common
.Parent
->Common
.AmlOpcode
!= AML_NAME_OP
)))
707 WalkState
->ResultObj
= ObjDesc
;
711 return_ACPI_STATUS (Status
);
715 /*******************************************************************************
717 * FUNCTION: AcpiDsEvalBankFieldOperands
719 * PARAMETERS: WalkState - Current walk
720 * Op - A valid BankField Op object
724 * DESCRIPTION: Get BankField BankValue
725 * Called from AcpiDsExecEndOp during BankField parse tree walk
727 ******************************************************************************/
730 AcpiDsEvalBankFieldOperands (
731 ACPI_WALK_STATE
*WalkState
,
732 ACPI_PARSE_OBJECT
*Op
)
735 ACPI_OPERAND_OBJECT
*ObjDesc
;
736 ACPI_OPERAND_OBJECT
*OperandDesc
;
737 ACPI_NAMESPACE_NODE
*Node
;
738 ACPI_PARSE_OBJECT
*NextOp
;
739 ACPI_PARSE_OBJECT
*Arg
;
742 ACPI_FUNCTION_TRACE_PTR (DsEvalBankFieldOperands
, Op
);
746 * This is where we evaluate the BankValue field of the
747 * BankField declaration
750 /* NextOp points to the op that holds the Region */
752 NextOp
= Op
->Common
.Value
.Arg
;
754 /* NextOp points to the op that holds the Bank Register */
756 NextOp
= NextOp
->Common
.Next
;
758 /* NextOp points to the op that holds the Bank Value */
760 NextOp
= NextOp
->Common
.Next
;
763 * Set proper index into operand stack for AcpiDsObjStackPush
764 * invoked inside AcpiDsCreateOperand.
766 * We use WalkState->Operands[0] to store the evaluated BankValue
768 WalkState
->OperandIndex
= 0;
770 Status
= AcpiDsCreateOperand (WalkState
, NextOp
, 0);
771 if (ACPI_FAILURE (Status
))
773 return_ACPI_STATUS (Status
);
776 Status
= AcpiExResolveToValue (&WalkState
->Operands
[0], WalkState
);
777 if (ACPI_FAILURE (Status
))
779 return_ACPI_STATUS (Status
);
782 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS
,
783 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
), 1);
785 * Get the BankValue operand and save it
788 OperandDesc
= WalkState
->Operands
[0];
790 /* Arg points to the start Bank Field */
792 Arg
= AcpiPsGetArg (Op
, 4);
795 /* Ignore OFFSET and ACCESSAS terms here */
797 if (Arg
->Common
.AmlOpcode
== AML_INT_NAMEDFIELD_OP
)
799 Node
= Arg
->Common
.Node
;
801 ObjDesc
= AcpiNsGetAttachedObject (Node
);
804 return_ACPI_STATUS (AE_NOT_EXIST
);
807 ObjDesc
->BankField
.Value
= (UINT32
) OperandDesc
->Integer
.Value
;
810 /* Move to next field in the list */
812 Arg
= Arg
->Common
.Next
;
815 AcpiUtRemoveReference (OperandDesc
);
816 return_ACPI_STATUS (Status
);