2 /******************************************************************************
4 * Module Name: exstore - AML Interpreter object store support
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
14 * All rights reserved.
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
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
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
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
74 * 3.4. Intel retains all right, title, and interest in and to the Original
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
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
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 __EXSTORE_C__
120 #include <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/acdispat.h>
122 #include <contrib/dev/acpica/acinterp.h>
123 #include <contrib/dev/acpica/amlcode.h>
124 #include <contrib/dev/acpica/acnamesp.h>
125 #include <contrib/dev/acpica/acparser.h>
128 #define _COMPONENT ACPI_EXECUTER
129 ACPI_MODULE_NAME ("exstore")
131 /* Local prototypes */
134 AcpiExDoDebugObject (
135 ACPI_OPERAND_OBJECT *SourceDesc,
140 AcpiExStoreObjectToIndex (
141 ACPI_OPERAND_OBJECT *ValDesc,
142 ACPI_OPERAND_OBJECT *DestDesc,
143 ACPI_WALK_STATE *WalkState);
146 /*******************************************************************************
148 * FUNCTION: AcpiExDoDebugObject
150 * PARAMETERS: SourceDesc - Value to be stored
151 * Level - Indentation level (used for packages)
152 * Index - Current package element, zero if not pkg
156 * DESCRIPTION: Handles stores to the Debug Object.
158 ******************************************************************************/
161 AcpiExDoDebugObject (
162 ACPI_OPERAND_OBJECT *SourceDesc,
169 ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
172 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
175 /* Display index for package output only */
179 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
180 "(%.2u) ", Index -1));
185 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "<Null Object>\n"));
189 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
191 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: ",
192 AcpiUtGetObjectTypeName (SourceDesc)));
194 if (!AcpiUtValidInternalObject (SourceDesc))
196 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
197 "%p, Invalid Internal Object!\n", SourceDesc));
201 else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
203 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: %p\n",
204 AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
213 switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
215 case ACPI_TYPE_INTEGER:
217 /* Output correct integer width */
219 if (AcpiGbl_IntegerByteWidth == 4)
221 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
222 (UINT32) SourceDesc->Integer.Value));
226 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
227 ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value)));
231 case ACPI_TYPE_BUFFER:
233 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n",
234 (UINT32) SourceDesc->Buffer.Length));
235 ACPI_DUMP_BUFFER (SourceDesc->Buffer.Pointer,
236 (SourceDesc->Buffer.Length < 256) ? SourceDesc->Buffer.Length : 256);
239 case ACPI_TYPE_STRING:
241 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
242 SourceDesc->String.Length, SourceDesc->String.Pointer));
245 case ACPI_TYPE_PACKAGE:
247 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X Elements]\n",
248 SourceDesc->Package.Count));
250 /* Output the entire contents of the package */
252 for (i = 0; i < SourceDesc->Package.Count; i++)
254 AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
259 case ACPI_TYPE_LOCAL_REFERENCE:
261 if (SourceDesc->Reference.Opcode == AML_INDEX_OP)
263 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s, 0x%X]\n",
264 AcpiPsGetOpcodeName (SourceDesc->Reference.Opcode),
265 SourceDesc->Reference.Offset));
269 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s]\n",
270 AcpiPsGetOpcodeName (SourceDesc->Reference.Opcode)));
274 if (SourceDesc->Reference.Object)
276 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
277 ACPI_DESC_TYPE_NAMED)
279 AcpiExDoDebugObject (((ACPI_NAMESPACE_NODE *)
280 SourceDesc->Reference.Object)->Object,
285 AcpiExDoDebugObject (SourceDesc->Reference.Object, Level+4, 0);
288 else if (SourceDesc->Reference.Node)
290 AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
297 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p %s\n",
298 SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
302 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
307 /*******************************************************************************
309 * FUNCTION: AcpiExStore
311 * PARAMETERS: *SourceDesc - Value to be stored
312 * *DestDesc - Where to store it. Must be an NS node
313 * or an ACPI_OPERAND_OBJECT of type
315 * WalkState - Current walk state
319 * DESCRIPTION: Store the value described by SourceDesc into the location
320 * described by DestDesc. Called by various interpreter
321 * functions to store the result of an operation into
322 * the destination operand -- not just simply the actual "Store"
325 ******************************************************************************/
329 ACPI_OPERAND_OBJECT *SourceDesc,
330 ACPI_OPERAND_OBJECT *DestDesc,
331 ACPI_WALK_STATE *WalkState)
333 ACPI_STATUS Status = AE_OK;
334 ACPI_OPERAND_OBJECT *RefDesc = DestDesc;
337 ACPI_FUNCTION_TRACE_PTR (ExStore, DestDesc);
340 /* Validate parameters */
342 if (!SourceDesc || !DestDesc)
344 ACPI_ERROR ((AE_INFO, "Null parameter"));
345 return_ACPI_STATUS (AE_AML_NO_OPERAND);
348 /* DestDesc can be either a namespace node or an ACPI object */
350 if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED)
353 * Dest is a namespace node,
354 * Storing an object into a Named node.
356 Status = AcpiExStoreObjectToNode (SourceDesc,
357 (ACPI_NAMESPACE_NODE *) DestDesc, WalkState,
358 ACPI_IMPLICIT_CONVERSION);
360 return_ACPI_STATUS (Status);
363 /* Destination object must be a Reference or a Constant object */
365 switch (ACPI_GET_OBJECT_TYPE (DestDesc))
367 case ACPI_TYPE_LOCAL_REFERENCE:
370 case ACPI_TYPE_INTEGER:
372 /* Allow stores to Constants -- a Noop as per ACPI spec */
374 if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
376 return_ACPI_STATUS (AE_OK);
379 /*lint -fallthrough */
383 /* Destination is not a Reference object */
385 ACPI_ERROR ((AE_INFO,
386 "Target is not a Reference or Constant object - %s [%p]",
387 AcpiUtGetObjectTypeName (DestDesc), DestDesc));
389 ACPI_DUMP_STACK_ENTRY (SourceDesc);
390 ACPI_DUMP_STACK_ENTRY (DestDesc);
391 ACPI_DUMP_OPERANDS (&DestDesc, ACPI_IMODE_EXECUTE, "ExStore",
392 2, "Target is not a Reference or Constant object");
394 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
398 * Examine the Reference opcode. These cases are handled:
400 * 1) Store to Name (Change the object associated with a name)
401 * 2) Store to an indexed area of a Buffer or Package
402 * 3) Store to a Method Local or Arg
403 * 4) Store to the debug object
405 switch (RefDesc->Reference.Opcode)
409 /* Storing an object into a Name "container" */
411 Status = AcpiExStoreObjectToNode (SourceDesc,
412 RefDesc->Reference.Object,
413 WalkState, ACPI_IMPLICIT_CONVERSION);
419 /* Storing to an Index (pointer into a packager or buffer) */
421 Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
428 /* Store to a method local/arg */
430 Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Opcode,
431 RefDesc->Reference.Offset, SourceDesc, WalkState);
438 * Storing to the Debug object causes the value stored to be
439 * displayed and otherwise has no effect -- see ACPI Specification
441 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
442 "**** Write to Debug Object: Object %p %s ****:\n\n",
443 SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
445 AcpiExDoDebugObject (SourceDesc, 0, 0);
451 ACPI_ERROR ((AE_INFO, "Unknown Reference opcode %X",
452 RefDesc->Reference.Opcode));
453 ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_ERROR);
455 Status = AE_AML_INTERNAL;
459 return_ACPI_STATUS (Status);
463 /*******************************************************************************
465 * FUNCTION: AcpiExStoreObjectToIndex
467 * PARAMETERS: *SourceDesc - Value to be stored
468 * *DestDesc - Named object to receive the value
469 * WalkState - Current walk state
473 * DESCRIPTION: Store the object to indexed Buffer or Package element
475 ******************************************************************************/
478 AcpiExStoreObjectToIndex (
479 ACPI_OPERAND_OBJECT *SourceDesc,
480 ACPI_OPERAND_OBJECT *IndexDesc,
481 ACPI_WALK_STATE *WalkState)
483 ACPI_STATUS Status = AE_OK;
484 ACPI_OPERAND_OBJECT *ObjDesc;
485 ACPI_OPERAND_OBJECT *NewDesc;
490 ACPI_FUNCTION_TRACE (ExStoreObjectToIndex);
494 * Destination must be a reference pointer, and
495 * must point to either a buffer or a package
497 switch (IndexDesc->Reference.TargetType)
499 case ACPI_TYPE_PACKAGE:
501 * Storing to a package element. Copy the object and replace
502 * any existing object with the new object. No implicit
503 * conversion is performed.
505 * The object at *(IndexDesc->Reference.Where) is the
506 * element within the package that is to be modified.
507 * The parent package object is at IndexDesc->Reference.Object
509 ObjDesc = *(IndexDesc->Reference.Where);
511 Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState);
512 if (ACPI_FAILURE (Status))
514 return_ACPI_STATUS (Status);
519 /* Decrement reference count by the ref count of the parent package */
522 i < ((ACPI_OPERAND_OBJECT *)
523 IndexDesc->Reference.Object)->Common.ReferenceCount;
526 AcpiUtRemoveReference (ObjDesc);
530 *(IndexDesc->Reference.Where) = NewDesc;
532 /* Increment ref count by the ref count of the parent package-1 */
535 i < ((ACPI_OPERAND_OBJECT *)
536 IndexDesc->Reference.Object)->Common.ReferenceCount;
539 AcpiUtAddReference (NewDesc);
545 case ACPI_TYPE_BUFFER_FIELD:
548 * Store into a Buffer or String (not actually a real BufferField)
549 * at a location defined by an Index.
551 * The first 8-bit element of the source object is written to the
552 * 8-bit Buffer location defined by the Index destination object,
553 * according to the ACPI 2.0 specification.
557 * Make sure the target is a Buffer or String. An error should
558 * not happen here, since the ReferenceObject was constructed
559 * by the INDEX_OP code.
561 ObjDesc = IndexDesc->Reference.Object;
562 if ((ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_BUFFER) &&
563 (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_STRING))
565 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
569 * The assignment of the individual elements will be slightly
570 * different for each source type.
572 switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
574 case ACPI_TYPE_INTEGER:
576 /* Use the least-significant byte of the integer */
578 Value = (UINT8) (SourceDesc->Integer.Value);
581 case ACPI_TYPE_BUFFER:
582 case ACPI_TYPE_STRING:
584 /* Note: Takes advantage of common string/buffer fields */
586 Value = SourceDesc->Buffer.Pointer[0];
591 /* All other types are invalid */
593 ACPI_ERROR ((AE_INFO,
594 "Source must be Integer/Buffer/String type, not %s",
595 AcpiUtGetObjectTypeName (SourceDesc)));
596 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
599 /* Store the source value into the target buffer byte */
601 ObjDesc->Buffer.Pointer[IndexDesc->Reference.Offset] = Value;
606 ACPI_ERROR ((AE_INFO,
607 "Target is not a Package or BufferField"));
608 Status = AE_AML_OPERAND_TYPE;
612 return_ACPI_STATUS (Status);
616 /*******************************************************************************
618 * FUNCTION: AcpiExStoreObjectToNode
620 * PARAMETERS: SourceDesc - Value to be stored
621 * Node - Named object to receive the value
622 * WalkState - Current walk state
623 * ImplicitConversion - Perform implicit conversion (yes/no)
627 * DESCRIPTION: Store the object to the named object.
629 * The Assignment of an object to a named object is handled here
630 * The value passed in will replace the current value (if any)
631 * with the input value.
633 * When storing into an object the data is converted to the
634 * target object type then stored in the object. This means
635 * that the target object type (for an initialized target) will
636 * not be changed by a store operation.
638 * Assumes parameters are already validated.
640 ******************************************************************************/
643 AcpiExStoreObjectToNode (
644 ACPI_OPERAND_OBJECT *SourceDesc,
645 ACPI_NAMESPACE_NODE *Node,
646 ACPI_WALK_STATE *WalkState,
647 UINT8 ImplicitConversion)
649 ACPI_STATUS Status = AE_OK;
650 ACPI_OPERAND_OBJECT *TargetDesc;
651 ACPI_OPERAND_OBJECT *NewDesc;
652 ACPI_OBJECT_TYPE TargetType;
655 ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc);
658 /* Get current type of the node, and object attached to Node */
660 TargetType = AcpiNsGetType (Node);
661 TargetDesc = AcpiNsGetAttachedObject (Node);
663 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
664 SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
665 Node, AcpiUtGetTypeName (TargetType)));
668 * Resolve the source object to an actual value
669 * (If it is a reference object)
671 Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
672 if (ACPI_FAILURE (Status))
674 return_ACPI_STATUS (Status);
677 /* If no implicit conversion, drop into the default case below */
679 if ((!ImplicitConversion) || (WalkState->Opcode == AML_COPY_OP))
681 /* Force execution of default (no implicit conversion) */
683 TargetType = ACPI_TYPE_ANY;
686 /* Do the actual store operation */
690 case ACPI_TYPE_BUFFER_FIELD:
691 case ACPI_TYPE_LOCAL_REGION_FIELD:
692 case ACPI_TYPE_LOCAL_BANK_FIELD:
693 case ACPI_TYPE_LOCAL_INDEX_FIELD:
695 /* For fields, copy the source data to the target field. */
697 Status = AcpiExWriteDataToField (SourceDesc, TargetDesc,
698 &WalkState->ResultObj);
702 case ACPI_TYPE_INTEGER:
703 case ACPI_TYPE_STRING:
704 case ACPI_TYPE_BUFFER:
707 * These target types are all of type Integer/String/Buffer, and
708 * therefore support implicit conversion before the store.
710 * Copy and/or convert the source object to a new target object
712 Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc,
713 &NewDesc, WalkState);
714 if (ACPI_FAILURE (Status))
716 return_ACPI_STATUS (Status);
719 if (NewDesc != TargetDesc)
722 * Store the new NewDesc as the new value of the Name, and set
723 * the Name's type to that of the value being stored in it.
724 * SourceDesc reference count is incremented by AttachObject.
726 * Note: This may change the type of the node if an explicit store
727 * has been performed such that the node/object type has been
730 Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type);
732 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
733 "Store %s into %s via Convert/Attach\n",
734 AcpiUtGetObjectTypeName (SourceDesc),
735 AcpiUtGetObjectTypeName (NewDesc)));
742 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
743 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
744 AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node));
746 /* No conversions for all other types. Just attach the source object */
748 Status = AcpiNsAttachObject (Node, SourceDesc,
749 ACPI_GET_OBJECT_TYPE (SourceDesc));
753 return_ACPI_STATUS (Status);