2 /******************************************************************************
4 * Module Name: exstore - AML Interpreter object store support
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2002, 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__
121 #include "acdispat.h"
122 #include "acinterp.h"
124 #include "acnamesp.h"
127 #define _COMPONENT ACPI_EXECUTER
128 ACPI_MODULE_NAME ("exstore")
131 /*******************************************************************************
133 * FUNCTION: AcpiExStore
135 * PARAMETERS: *SourceDesc - Value to be stored
136 * *DestDesc - Where to store it. Must be an NS node
137 * or an ACPI_OPERAND_OBJECT of type
139 * WalkState - Current walk state
143 * DESCRIPTION: Store the value described by SourceDesc into the location
144 * described by DestDesc. Called by various interpreter
145 * functions to store the result of an operation into
146 * the destination operand -- not just simply the actual "Store"
149 ******************************************************************************/
153 ACPI_OPERAND_OBJECT *SourceDesc,
154 ACPI_OPERAND_OBJECT *DestDesc,
155 ACPI_WALK_STATE *WalkState)
157 ACPI_STATUS Status = AE_OK;
158 ACPI_OPERAND_OBJECT *RefDesc = DestDesc;
161 ACPI_FUNCTION_TRACE_PTR ("ExStore", DestDesc);
164 /* Validate parameters */
166 if (!SourceDesc || !DestDesc)
168 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null parameter\n"));
169 return_ACPI_STATUS (AE_AML_NO_OPERAND);
172 /* DestDesc can be either a namespace node or an ACPI object */
174 if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED)
177 * Dest is a namespace node,
178 * Storing an object into a Name "container"
180 Status = AcpiExStoreObjectToNode (SourceDesc,
181 (ACPI_NAMESPACE_NODE *) DestDesc, WalkState);
183 return_ACPI_STATUS (Status);
186 /* Destination object must be a Reference or a Constant object */
188 switch (ACPI_GET_OBJECT_TYPE (DestDesc))
190 case INTERNAL_TYPE_REFERENCE:
193 case ACPI_TYPE_INTEGER:
195 /* Allow stores to Constants -- a Noop as per ACPI spec */
197 if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
199 return_ACPI_STATUS (AE_OK);
202 /*lint: -fallthrough */
206 /* Destination is not an Reference */
208 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
209 "Destination is not a Reference or Constant object [%p]\n", DestDesc));
211 ACPI_DUMP_STACK_ENTRY (SourceDesc);
212 ACPI_DUMP_STACK_ENTRY (DestDesc);
213 ACPI_DUMP_OPERANDS (&DestDesc, ACPI_IMODE_EXECUTE, "ExStore",
214 2, "Target is not a Reference or Constant object");
216 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
220 * Examine the Reference opcode. These cases are handled:
222 * 1) Store to Name (Change the object associated with a name)
223 * 2) Store to an indexed area of a Buffer or Package
224 * 3) Store to a Method Local or Arg
225 * 4) Store to the debug object
227 switch (RefDesc->Reference.Opcode)
232 /* Storing an object into a Name "container" */
234 Status = AcpiExStoreObjectToNode (SourceDesc, RefDesc->Reference.Object,
241 /* Storing to an Index (pointer into a packager or buffer) */
243 Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
250 /* Store to a method local/arg */
252 Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Opcode,
253 RefDesc->Reference.Offset, SourceDesc, WalkState);
260 * Storing to the Debug object causes the value stored to be
261 * displayed and otherwise has no effect -- see ACPI Specification
263 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Write to Debug Object: ****:\n\n"));
265 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %s: ",
266 AcpiUtGetObjectTypeName (SourceDesc)));
268 switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
270 case ACPI_TYPE_INTEGER:
272 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%8.8X%8.8X\n",
273 ACPI_HIWORD (SourceDesc->Integer.Value),
274 ACPI_LOWORD (SourceDesc->Integer.Value)));
278 case ACPI_TYPE_BUFFER:
280 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Length %.2X\n",
281 (UINT32) SourceDesc->Buffer.Length));
285 case ACPI_TYPE_STRING:
287 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s\n", SourceDesc->String.Pointer));
291 case ACPI_TYPE_PACKAGE:
293 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Elements Ptr - %p\n",
294 SourceDesc->Package.Elements));
300 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Type %s %p\n",
301 AcpiUtGetObjectTypeName (SourceDesc), SourceDesc));
305 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
311 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Reference opcode %X\n",
312 RefDesc->Reference.Opcode));
313 ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_ERROR);
315 Status = AE_AML_INTERNAL;
319 return_ACPI_STATUS (Status);
323 /*******************************************************************************
325 * FUNCTION: AcpiExStoreObjectToIndex
327 * PARAMETERS: *SourceDesc - Value to be stored
328 * *DestDesc - Named object to receive the value
329 * WalkState - Current walk state
333 * DESCRIPTION: Store the object to indexed Buffer or Package element
335 ******************************************************************************/
338 AcpiExStoreObjectToIndex (
339 ACPI_OPERAND_OBJECT *SourceDesc,
340 ACPI_OPERAND_OBJECT *IndexDesc,
341 ACPI_WALK_STATE *WalkState)
343 ACPI_STATUS Status = AE_OK;
344 ACPI_OPERAND_OBJECT *ObjDesc;
345 ACPI_OPERAND_OBJECT *NewDesc;
349 ACPI_FUNCTION_TRACE ("ExStoreObjectToIndex");
353 * Destination must be a reference pointer, and
354 * must point to either a buffer or a package
356 switch (IndexDesc->Reference.TargetType)
358 case ACPI_TYPE_PACKAGE:
360 * Storing to a package element is not simple. The source must be
361 * evaluated and converted to the type of the destination and then the
362 * source is copied into the destination - we can't just point to the
366 * The object at *(IndexDesc->Reference.Where) is the
367 * element within the package that is to be modified.
369 ObjDesc = *(IndexDesc->Reference.Where);
371 /* Do the conversion/store */
373 Status = AcpiExStoreObjectToObject (SourceDesc, ObjDesc, &NewDesc,
375 if (ACPI_FAILURE (Status))
377 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
378 "Could not store object to indexed package element\n"));
379 return_ACPI_STATUS (Status);
383 * If a new object was created, we must install it as the new
386 if (NewDesc != ObjDesc)
388 AcpiUtRemoveReference (ObjDesc);
389 *(IndexDesc->Reference.Where) = NewDesc;
394 case ACPI_TYPE_BUFFER_FIELD:
397 * Store into a Buffer (not actually a real BufferField) at a
398 * location defined by an Index.
400 * The first 8-bit element of the source object is written to the
401 * 8-bit Buffer location defined by the Index destination object,
402 * according to the ACPI 2.0 specification.
406 * Make sure the target is a Buffer
408 ObjDesc = IndexDesc->Reference.Object;
409 if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_BUFFER)
411 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
415 * The assignment of the individual elements will be slightly
416 * different for each source type.
418 switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
420 case ACPI_TYPE_INTEGER:
422 /* Use the least-significant byte of the integer */
424 Value = (UINT8) (SourceDesc->Integer.Value);
427 case ACPI_TYPE_BUFFER:
429 Value = SourceDesc->Buffer.Pointer[0];
432 case ACPI_TYPE_STRING:
434 Value = (UINT8) SourceDesc->String.Pointer[0];
439 /* All other types are invalid */
441 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
442 "Source must be Integer/Buffer/String type, not %s\n",
443 AcpiUtGetObjectTypeName (SourceDesc)));
444 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
447 /* Store the source value into the target buffer byte */
449 ObjDesc->Buffer.Pointer[IndexDesc->Reference.Offset] = Value;
454 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
455 "Target is not a Package or BufferField\n"));
456 Status = AE_AML_OPERAND_TYPE;
460 return_ACPI_STATUS (Status);
464 /*******************************************************************************
466 * FUNCTION: AcpiExStoreObjectToNode
468 * PARAMETERS: SourceDesc - Value to be stored
469 * Node - Named object to receive the value
470 * WalkState - Current walk state
474 * DESCRIPTION: Store the object to the named object.
476 * The Assignment of an object to a named object is handled here
477 * The value passed in will replace the current value (if any)
478 * with the input value.
480 * When storing into an object the data is converted to the
481 * target object type then stored in the object. This means
482 * that the target object type (for an initialized target) will
483 * not be changed by a store operation.
485 * Assumes parameters are already validated.
487 ******************************************************************************/
490 AcpiExStoreObjectToNode (
491 ACPI_OPERAND_OBJECT *SourceDesc,
492 ACPI_NAMESPACE_NODE *Node,
493 ACPI_WALK_STATE *WalkState)
495 ACPI_STATUS Status = AE_OK;
496 ACPI_OPERAND_OBJECT *TargetDesc;
497 ACPI_OPERAND_OBJECT *NewDesc;
498 ACPI_OBJECT_TYPE TargetType;
501 ACPI_FUNCTION_TRACE_PTR ("ExStoreObjectToNode", SourceDesc);
505 * Get current type of the node, and object attached to Node
507 TargetType = AcpiNsGetType (Node);
508 TargetDesc = AcpiNsGetAttachedObject (Node);
510 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
511 SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
512 Node, AcpiUtGetTypeName (TargetType)));
515 * Resolve the source object to an actual value
516 * (If it is a reference object)
518 Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
519 if (ACPI_FAILURE (Status))
521 return_ACPI_STATUS (Status);
525 * Do the actual store operation
529 case ACPI_TYPE_BUFFER_FIELD:
530 case INTERNAL_TYPE_REGION_FIELD:
531 case INTERNAL_TYPE_BANK_FIELD:
532 case INTERNAL_TYPE_INDEX_FIELD:
535 * For fields, copy the source data to the target field.
537 Status = AcpiExWriteDataToField (SourceDesc, TargetDesc);
541 case ACPI_TYPE_INTEGER:
542 case ACPI_TYPE_STRING:
543 case ACPI_TYPE_BUFFER:
546 * These target types are all of type Integer/String/Buffer, and
547 * therefore support implicit conversion before the store.
549 * Copy and/or convert the source object to a new target object
551 Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc, &NewDesc, WalkState);
552 if (ACPI_FAILURE (Status))
554 return_ACPI_STATUS (Status);
557 if (NewDesc != TargetDesc)
560 * Store the new NewDesc as the new value of the Name, and set
561 * the Name's type to that of the value being stored in it.
562 * SourceDesc reference count is incremented by AttachObject.
564 Status = AcpiNsAttachObject (Node, NewDesc, TargetType);
566 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
567 "Store %s into %s via Convert/Attach\n",
568 AcpiUtGetObjectTypeName (SourceDesc),
569 AcpiUtGetObjectTypeName (NewDesc)));
576 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
577 "Storing %s (%p) directly into node (%p), no implicit conversion\n",
578 AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node));
580 /* No conversions for all other types. Just attach the source object */
582 Status = AcpiNsAttachObject (Node, SourceDesc, ACPI_GET_OBJECT_TYPE (SourceDesc));
586 return_ACPI_STATUS (Status);