2 /******************************************************************************
4 * Module Name: amstore - AML Interpreter object store support
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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 __AMSTORE_C__
121 #include "acparser.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
125 #include "acnamesp.h"
126 #include "actables.h"
129 #define _COMPONENT INTERPRETER
130 MODULE_NAME ("amstore")
137 /*******************************************************************************
139 * FUNCTION: AcpiAmlExecStore
141 * PARAMETERS: *ValDesc - Value to be stored
142 * *DestDesc - Where to store it 0 Must be (ACPI_HANDLE)
143 * or an ACPI_OPERAND_OBJECT of type
144 * Reference; if the latter the descriptor
145 * will be either reused or deleted.
149 * DESCRIPTION: Store the value described by ValDesc into the location
150 * described by DestDesc. Called by various interpreter
151 * functions to store the result of an operation into
152 * the destination operand.
154 ******************************************************************************/
158 ACPI_OPERAND_OBJECT *ValDesc,
159 ACPI_OPERAND_OBJECT *DestDesc,
160 ACPI_WALK_STATE *WalkState)
162 ACPI_STATUS Status = AE_OK;
163 ACPI_OPERAND_OBJECT *RefDesc = DestDesc;
166 FUNCTION_TRACE_PTR ("AmlExecStore", DestDesc);
169 /* Validate parameters */
171 if (!ValDesc || !DestDesc)
173 DEBUG_PRINT (ACPI_ERROR,
174 ("AmlExecStore: Internal error - null pointer\n"));
175 return_ACPI_STATUS (AE_AML_NO_OPERAND);
178 /* DestDesc can be either a namespace node or an ACPI object */
180 if (VALID_DESCRIPTOR_TYPE (DestDesc, ACPI_DESC_TYPE_NAMED))
183 * Dest is a namespace node,
184 * Storing an object into a Name "container"
186 Status = AcpiAmlStoreObjectToNode (ValDesc,
187 (ACPI_NAMESPACE_NODE *) DestDesc, WalkState);
189 /* All done, that's it */
191 return_ACPI_STATUS (Status);
195 /* Destination object must be an object of type Reference */
197 if (DestDesc->Common.Type != INTERNAL_TYPE_REFERENCE)
199 /* Destination is not an Reference */
201 DEBUG_PRINT (ACPI_ERROR,
202 ("AmlExecStore: Destination is not a ReferenceObj [%p]\n", DestDesc));
204 DUMP_STACK_ENTRY (ValDesc);
205 DUMP_STACK_ENTRY (DestDesc);
206 DUMP_OPERANDS (&DestDesc, IMODE_EXECUTE, "AmlExecStore",
207 2, "Target is not a ReferenceObj");
209 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
214 * Examine the Reference opcode. These cases are handled:
216 * 1) Store to Name (Change the object associated with a name)
217 * 2) Store to an indexed area of a Buffer or Package
218 * 3) Store to a Method Local or Arg
219 * 4) Store to the debug object
220 * 5) Store to a constant -- a noop
223 switch (RefDesc->Reference.OpCode)
228 /* Storing an object into a Name "container" */
230 Status = AcpiAmlStoreObjectToNode (ValDesc, RefDesc->Reference.Object,
237 /* Storing to an Index (pointer into a packager or buffer) */
239 Status = AcpiAmlStoreObjectToIndex (ValDesc, RefDesc, WalkState);
245 Status = AcpiDsMethodDataSetValue (MTH_TYPE_LOCAL,
246 (RefDesc->Reference.Offset), ValDesc, WalkState);
252 Status = AcpiDsMethodDataSetValue (MTH_TYPE_ARG,
253 (RefDesc->Reference.Offset), ValDesc, WalkState);
260 * Storing to the Debug object causes the value stored to be
261 * displayed and otherwise has no effect -- see ACPI Specification
263 * TBD: print known object types "prettier".
265 DEBUG_PRINT (ACPI_INFO, ("**** Write to Debug Object: ****: \n"));
267 if (ValDesc->Common.Type == ACPI_TYPE_STRING)
269 DEBUG_PRINT (ACPI_INFO, ("%s\n", ValDesc->String.Pointer));
273 DUMP_STACK_ENTRY (ValDesc);
284 * Storing to a constant is a no-op -- see ACPI Specification
285 * Delete the reference descriptor, however
292 DEBUG_PRINT (ACPI_ERROR,
293 ("AmlExecStore: Internal error - Unknown Reference subtype %02x\n",
294 RefDesc->Reference.OpCode));
296 /* TBD: [Restructure] use object dump routine !! */
298 DUMP_BUFFER (RefDesc, sizeof (ACPI_OPERAND_OBJECT));
300 Status = AE_AML_INTERNAL;
303 } /* switch (RefDesc->Reference.OpCode) */
307 /* Always delete the reference descriptor object */
311 AcpiCmRemoveReference (RefDesc);
314 return_ACPI_STATUS (Status);
318 /*******************************************************************************
320 * FUNCTION: AcpiAmlStoreObjectToIndex
322 * PARAMETERS: *ValDesc - Value to be stored
323 * *Node - Named object to recieve the value
327 * DESCRIPTION: Store the object to the named object.
329 ******************************************************************************/
332 AcpiAmlStoreObjectToIndex (
333 ACPI_OPERAND_OBJECT *ValDesc,
334 ACPI_OPERAND_OBJECT *DestDesc,
335 ACPI_WALK_STATE *WalkState)
337 ACPI_STATUS Status = AE_OK;
338 ACPI_OPERAND_OBJECT *ObjDesc;
344 FUNCTION_TRACE ("AcpiAmlStoreObjectToIndex");
348 * Destination must be a reference pointer, and
349 * must point to either a buffer or a package
352 switch (DestDesc->Reference.TargetType)
354 case ACPI_TYPE_PACKAGE:
356 * Storing to a package element is not simple. The source must be
357 * evaluated and converted to the type of the destination and then the
358 * source is copied into the destination - we can't just point to the
361 if (DestDesc->Reference.TargetType == ACPI_TYPE_PACKAGE)
364 * The object at *(DestDesc->Reference.Where) is the
365 * element within the package that is to be modified.
367 ObjDesc = *(DestDesc->Reference.Where);
371 * If the Destination element is a package, we will delete
372 * that object and construct a new one.
374 * TBD: [Investigate] Should both the src and dest be required
376 * && (ValDesc->Common.Type == ACPI_TYPE_PACKAGE)
378 if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
381 * Take away the reference for being part of a package and
384 AcpiCmRemoveReference (ObjDesc);
385 AcpiCmRemoveReference (ObjDesc);
394 * If the ObjDesc is NULL, it means that an uninitialized package
395 * element has been used as a destination (this is OK), therefore,
396 * we must create the destination element to match the type of the
397 * source element NOTE: ValDesc can be of any type.
399 ObjDesc = AcpiCmCreateInternalObject (ValDesc->Common.Type);
402 return_ACPI_STATUS (AE_NO_MEMORY);
406 * If the source is a package, copy the source to the new dest
408 if (ACPI_TYPE_PACKAGE == ObjDesc->Common.Type)
410 Status = AcpiCmCopyIpackageToIpackage (ValDesc, ObjDesc, WalkState);
411 if (ACPI_FAILURE (Status))
413 AcpiCmRemoveReference (ObjDesc);
414 return_ACPI_STATUS (Status);
419 * Install the new descriptor into the package and add a
420 * reference to the newly created descriptor for now being
421 * part of the parent package
424 *(DestDesc->Reference.Where) = ObjDesc;
425 AcpiCmAddReference (ObjDesc);
428 if (ACPI_TYPE_PACKAGE != ObjDesc->Common.Type)
431 * The destination element is not a package, so we need to
432 * convert the contents of the source (ValDesc) and copy into
433 * the destination (ObjDesc)
435 Status = AcpiAmlStoreObjectToObject (ValDesc, ObjDesc,
437 if (ACPI_FAILURE (Status))
440 * An error occurrered when copying the internal object
441 * so delete the reference.
443 DEBUG_PRINT (ACPI_ERROR,
444 ("AmlExecStore/Index: Unable to copy the internal object\n"));
445 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
452 case ACPI_TYPE_BUFFER_FIELD:
454 * Storing into a buffer at a location defined by an Index.
456 * Each 8-bit element of the source object is written to the
457 * 8-bit Buffer Field of the Index destination object.
461 * Set the ObjDesc to the destination object and type check.
463 ObjDesc = DestDesc->Reference.Object;
464 if (ObjDesc->Common.Type != ACPI_TYPE_BUFFER)
466 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
470 * The assignment of the individual elements will be slightly
471 * different for each source type.
474 switch (ValDesc->Common.Type)
477 * If the type is Integer, assign bytewise
478 * This loop to assign each of the elements is somewhat
479 * backward because of the Big Endian-ness of IA-64
481 case ACPI_TYPE_INTEGER:
482 Length = sizeof (ACPI_INTEGER);
483 for (i = Length; i != 0; i--)
485 Value = (UINT8)(ValDesc->Integer.Value >> (MUL_8 (i - 1)));
486 ObjDesc->Buffer.Pointer[DestDesc->Reference.Offset] = Value;
491 * If the type is Buffer, the Length is in the structure.
492 * Just loop through the elements and assign each one in turn.
494 case ACPI_TYPE_BUFFER:
495 Length = ValDesc->Buffer.Length;
496 for (i = 0; i < Length; i++)
498 Value = *(ValDesc->Buffer.Pointer + i);
499 ObjDesc->Buffer.Pointer[DestDesc->Reference.Offset] = Value;
504 * If the type is String, the Length is in the structure.
505 * Just loop through the elements and assign each one in turn.
507 case ACPI_TYPE_STRING:
508 Length = ValDesc->String.Length;
509 for (i = 0; i < Length; i++)
511 Value = *(ValDesc->String.Pointer + i);
512 ObjDesc->Buffer.Pointer[DestDesc->Reference.Offset] = Value;
517 * If source is not a valid type so return an error.
520 DEBUG_PRINT (ACPI_ERROR,
521 ("AmlExecStore/Index: Source must be Number/Buffer/String type, not %X\n",
522 ValDesc->Common.Type));
523 Status = AE_AML_OPERAND_TYPE;
530 DEBUG_PRINT (ACPI_ERROR,
531 ("AmlExecStoreIndex: Target is not a Package or BufferField\n"));
532 Status = AE_AML_OPERAND_TYPE;
537 return_ACPI_STATUS (Status);
544 /*******************************************************************************
546 * FUNCTION: AcpiAmlStoreObjectToNode
548 * PARAMETERS: *SourceDesc - Value to be stored
549 * *Node - Named object to recieve the value
553 * DESCRIPTION: Store the object to the named object.
555 * The Assignment of an object to a named object is handled here
556 * The val passed in will replace the current value (if any)
557 * with the input value.
559 * When storing into an object the data is converted to the
560 * target object type then stored in the object. This means
561 * that the target object type (for an initialized target) will
562 * not be changed by a store operation.
564 * NOTE: the global lock is acquired early. This will result
565 * in the global lock being held a bit longer. Also, if the
566 * function fails during set up we may get the lock when we
567 * don't really need it. I don't think we care.
569 ******************************************************************************/
572 AcpiAmlStoreObjectToNode (
573 ACPI_OPERAND_OBJECT *SourceDesc,
574 ACPI_NAMESPACE_NODE *Node,
575 ACPI_WALK_STATE *WalkState)
577 ACPI_STATUS Status = AE_OK;
578 ACPI_OPERAND_OBJECT *TargetDesc;
579 OBJECT_TYPE_INTERNAL TargetType = ACPI_TYPE_ANY;
582 FUNCTION_TRACE ("AmlStoreObjectToNode");
585 * Assuming the parameters were already validated
587 ACPI_ASSERT((Node) && (SourceDesc));
591 * Get current type of the node, and object attached to Node
593 TargetType = AcpiNsGetType (Node);
594 TargetDesc = AcpiNsGetAttachedObject (Node);
596 DEBUG_PRINT (ACPI_INFO, ("AmlStoreObjectToNode: Storing %p(%s) into node %p(%s)\n",
597 Node, AcpiCmGetTypeName (SourceDesc->Common.Type),
598 SourceDesc, AcpiCmGetTypeName (TargetType)));
602 * Resolve the source object to an actual value
603 * (If it is a reference object)
605 Status = AcpiAmlResolveObject (&SourceDesc, TargetType, WalkState);
606 if (ACPI_FAILURE (Status))
608 return_ACPI_STATUS (Status);
613 * Do the actual store operation
617 case INTERNAL_TYPE_DEF_FIELD:
619 /* Raw data copy for target types Integer/String/Buffer */
621 Status = AcpiAmlCopyDataToNamedField (SourceDesc, Node);
625 case ACPI_TYPE_INTEGER:
626 case ACPI_TYPE_STRING:
627 case ACPI_TYPE_BUFFER:
628 case INTERNAL_TYPE_BANK_FIELD:
629 case INTERNAL_TYPE_INDEX_FIELD:
630 case ACPI_TYPE_FIELD_UNIT:
633 * These target types are all of type Integer/String/Buffer, and
634 * therefore support implicit conversion before the store.
636 * Copy and/or convert the source object to a new target object
638 Status = AcpiAmlStoreObject (SourceDesc, TargetType, &TargetDesc, WalkState);
639 if (ACPI_FAILURE (Status))
641 return_ACPI_STATUS (Status);
645 * Store the new TargetDesc as the new value of the Name, and set
646 * the Name's type to that of the value being stored in it.
647 * SourceDesc reference count is incremented by AttachObject.
649 Status = AcpiNsAttachObject (Node, TargetDesc, TargetType);
650 DEBUG_PRINT (ACPI_INFO,
651 ("AmlStoreObjectToNode: Store %s into %s via Convert/Attach\n",
652 AcpiCmGetTypeName (TargetDesc->Common.Type),
653 AcpiCmGetTypeName (TargetType)));
659 /* No conversions for all other types. Just attach the source object */
661 Status = AcpiNsAttachObject (Node, SourceDesc, SourceDesc->Common.Type);
663 DEBUG_PRINT (ACPI_INFO,
664 ("AmlStoreObjectToNode: Store %s into %s via Attach only\n",
665 AcpiCmGetTypeName (SourceDesc->Common.Type),
666 AcpiCmGetTypeName (SourceDesc->Common.Type)));
671 return_ACPI_STATUS (Status);
676 /*******************************************************************************
678 * FUNCTION: AcpiAmlStoreObjectToObject
680 * PARAMETERS: *SourceDesc - Value to be stored
681 * *DestDesc - Object to receive the value
685 * DESCRIPTION: Store an object to another object.
687 * The Assignment of an object to another (not named) object
689 * The val passed in will replace the current value (if any)
690 * with the input value.
692 * When storing into an object the data is converted to the
693 * target object type then stored in the object. This means
694 * that the target object type (for an initialized target) will
695 * not be changed by a store operation.
697 * This module allows destination types of Number, String,
700 ******************************************************************************/
703 AcpiAmlStoreObjectToObject (
704 ACPI_OPERAND_OBJECT *SourceDesc,
705 ACPI_OPERAND_OBJECT *DestDesc,
706 ACPI_WALK_STATE *WalkState)
708 ACPI_STATUS Status = AE_OK;
709 OBJECT_TYPE_INTERNAL DestinationType = DestDesc->Common.Type;
712 FUNCTION_TRACE ("AmlStoreObjectToObject");
716 * Assuming the parameters are valid!
718 ACPI_ASSERT((DestDesc) && (SourceDesc));
720 DEBUG_PRINT (ACPI_INFO, ("AmlStoreObjectToObject: Storing %p(%s) to %p(%s)\n",
721 SourceDesc, AcpiCmGetTypeName (SourceDesc->Common.Type),
722 DestDesc, AcpiCmGetTypeName (DestDesc->Common.Type)));
726 * From this interface, we only support Integers/Strings/Buffers
728 switch (DestinationType)
730 case ACPI_TYPE_INTEGER:
731 case ACPI_TYPE_STRING:
732 case ACPI_TYPE_BUFFER:
736 DEBUG_PRINT (ACPI_WARN,
737 ("AmlStoreObjectToObject: Store into %s not implemented\n",
738 AcpiCmGetTypeName (DestDesc->Common.Type)));
740 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
746 * Resolve the source object to an actual value
747 * (If it is a reference object)
749 Status = AcpiAmlResolveObject (&SourceDesc, DestinationType, WalkState);
750 if (ACPI_FAILURE (Status))
752 return_ACPI_STATUS (Status);
757 * Copy and/or convert the source object to the destination object
759 Status = AcpiAmlStoreObject (SourceDesc, DestinationType, &DestDesc, WalkState);
762 return_ACPI_STATUS (Status);