]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/contrib/dev/acpica/exstore.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / contrib / dev / acpica / exstore.c
1
2 /******************************************************************************
3  *
4  * Module Name: exstore - AML Interpreter object store support
5  *              $Revision: 1.203 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
14  * All rights reserved.
15  *
16  * 2. License
17  *
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
21  * property rights.
22  *
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
29  *
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;
38  *
39  * The above copyright and patent license is granted only if the following
40  * conditions are met:
41  *
42  * 3. Conditions
43  *
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.
55  *
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
66  * make.
67  *
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
72  * distribution.
73  *
74  * 3.4. Intel retains all right, title, and interest in and to the Original
75  * Intel Code.
76  *
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.
81  *
82  * 4. Disclaimer and Export Compliance
83  *
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
90  * PARTICULAR PURPOSE.
91  *
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
99  * LIMITED REMEDY.
100  *
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.
115  *
116  *****************************************************************************/
117
118 #define __EXSTORE_C__
119
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>
126
127
128 #define _COMPONENT          ACPI_EXECUTER
129         ACPI_MODULE_NAME    ("exstore")
130
131 /* Local prototypes */
132
133 static void
134 AcpiExDoDebugObject (
135     ACPI_OPERAND_OBJECT     *SourceDesc,
136     UINT32                  Level,
137     UINT32                  Index);
138
139 static ACPI_STATUS
140 AcpiExStoreObjectToIndex (
141     ACPI_OPERAND_OBJECT     *ValDesc,
142     ACPI_OPERAND_OBJECT     *DestDesc,
143     ACPI_WALK_STATE         *WalkState);
144
145
146 /*******************************************************************************
147  *
148  * FUNCTION:    AcpiExDoDebugObject
149  *
150  * PARAMETERS:  SourceDesc          - Value to be stored
151  *              Level               - Indentation level (used for packages)
152  *              Index               - Current package element, zero if not pkg
153  *
154  * RETURN:      None
155  *
156  * DESCRIPTION: Handles stores to the Debug Object.
157  *
158  ******************************************************************************/
159
160 static void
161 AcpiExDoDebugObject (
162     ACPI_OPERAND_OBJECT     *SourceDesc,
163     UINT32                  Level,
164     UINT32                  Index)
165 {
166     UINT32                  i;
167
168
169     ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
170
171
172     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
173         Level, " "));
174
175     /* Display index for package output only */
176
177     if (Index > 0)
178     {
179        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
180            "(%.2u) ", Index -1));
181     }
182
183     if (!SourceDesc)
184     {
185         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "<Null Object>\n"));
186         return_VOID;
187     }
188
189     if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
190     {
191         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: ",
192             AcpiUtGetObjectTypeName (SourceDesc)));
193
194         if (!AcpiUtValidInternalObject (SourceDesc))
195         {
196            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
197                "%p, Invalid Internal Object!\n", SourceDesc));
198            return_VOID;
199         }
200     }
201     else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
202     {
203         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: %p\n",
204             AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
205             SourceDesc));
206         return_VOID;
207     }
208     else
209     {
210         return_VOID;
211     }
212
213     switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
214     {
215     case ACPI_TYPE_INTEGER:
216
217         /* Output correct integer width */
218
219         if (AcpiGbl_IntegerByteWidth == 4)
220         {
221             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
222                 (UINT32) SourceDesc->Integer.Value));
223         }
224         else
225         {
226             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
227                 ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value)));
228         }
229         break;
230
231     case ACPI_TYPE_BUFFER:
232
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);
237         break;
238
239     case ACPI_TYPE_STRING:
240
241         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
242             SourceDesc->String.Length, SourceDesc->String.Pointer));
243         break;
244
245     case ACPI_TYPE_PACKAGE:
246
247         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X Elements]\n",
248             SourceDesc->Package.Count));
249
250         /* Output the entire contents of the package */
251
252         for (i = 0; i < SourceDesc->Package.Count; i++)
253         {
254             AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
255                 Level+4, i+1);
256         }
257         break;
258
259     case ACPI_TYPE_LOCAL_REFERENCE:
260
261         if (SourceDesc->Reference.Opcode == AML_INDEX_OP)
262         {
263             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s, 0x%X]\n",
264                 AcpiPsGetOpcodeName (SourceDesc->Reference.Opcode),
265                 SourceDesc->Reference.Offset));
266         }
267         else
268         {
269             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s]\n",
270                 AcpiPsGetOpcodeName (SourceDesc->Reference.Opcode)));
271         }
272
273
274         if (SourceDesc->Reference.Object)
275         {
276             if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
277                     ACPI_DESC_TYPE_NAMED)
278             {
279                 AcpiExDoDebugObject (((ACPI_NAMESPACE_NODE *)
280                     SourceDesc->Reference.Object)->Object,
281                     Level+4, 0);
282             }
283             else
284             {
285                 AcpiExDoDebugObject (SourceDesc->Reference.Object, Level+4, 0);
286             }
287         }
288         else if (SourceDesc->Reference.Node)
289         {
290             AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
291                 Level+4, 0);
292         }
293         break;
294
295     default:
296
297         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p %s\n",
298             SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
299         break;
300     }
301
302     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
303     return_VOID;
304 }
305
306
307 /*******************************************************************************
308  *
309  * FUNCTION:    AcpiExStore
310  *
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
314  *                                    Reference;
315  *              WalkState           - Current walk state
316  *
317  * RETURN:      Status
318  *
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"
323  *              ASL operator.
324  *
325  ******************************************************************************/
326
327 ACPI_STATUS
328 AcpiExStore (
329     ACPI_OPERAND_OBJECT     *SourceDesc,
330     ACPI_OPERAND_OBJECT     *DestDesc,
331     ACPI_WALK_STATE         *WalkState)
332 {
333     ACPI_STATUS             Status = AE_OK;
334     ACPI_OPERAND_OBJECT     *RefDesc = DestDesc;
335
336
337     ACPI_FUNCTION_TRACE_PTR (ExStore, DestDesc);
338
339
340     /* Validate parameters */
341
342     if (!SourceDesc || !DestDesc)
343     {
344         ACPI_ERROR ((AE_INFO, "Null parameter"));
345         return_ACPI_STATUS (AE_AML_NO_OPERAND);
346     }
347
348     /* DestDesc can be either a namespace node or an ACPI object */
349
350     if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED)
351     {
352         /*
353          * Dest is a namespace node,
354          * Storing an object into a Named node.
355          */
356         Status = AcpiExStoreObjectToNode (SourceDesc,
357                     (ACPI_NAMESPACE_NODE *) DestDesc, WalkState,
358                     ACPI_IMPLICIT_CONVERSION);
359
360         return_ACPI_STATUS (Status);
361     }
362
363     /* Destination object must be a Reference or a Constant object */
364
365     switch (ACPI_GET_OBJECT_TYPE (DestDesc))
366     {
367     case ACPI_TYPE_LOCAL_REFERENCE:
368         break;
369
370     case ACPI_TYPE_INTEGER:
371
372         /* Allow stores to Constants -- a Noop as per ACPI spec */
373
374         if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
375         {
376             return_ACPI_STATUS (AE_OK);
377         }
378
379         /*lint -fallthrough */
380
381     default:
382
383         /* Destination is not a Reference object */
384
385         ACPI_ERROR ((AE_INFO,
386             "Target is not a Reference or Constant object - %s [%p]",
387             AcpiUtGetObjectTypeName (DestDesc), DestDesc));
388
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");
393
394         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
395     }
396
397     /*
398      * Examine the Reference opcode.  These cases are handled:
399      *
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
404      */
405     switch (RefDesc->Reference.Opcode)
406     {
407     case AML_REF_OF_OP:
408
409         /* Storing an object into a Name "container" */
410
411         Status = AcpiExStoreObjectToNode (SourceDesc,
412                     RefDesc->Reference.Object,
413                     WalkState, ACPI_IMPLICIT_CONVERSION);
414         break;
415
416
417     case AML_INDEX_OP:
418
419         /* Storing to an Index (pointer into a packager or buffer) */
420
421         Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
422         break;
423
424
425     case AML_LOCAL_OP:
426     case AML_ARG_OP:
427
428         /* Store to a method local/arg  */
429
430         Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Opcode,
431                     RefDesc->Reference.Offset, SourceDesc, WalkState);
432         break;
433
434
435     case AML_DEBUG_OP:
436
437         /*
438          * Storing to the Debug object causes the value stored to be
439          * displayed and otherwise has no effect -- see ACPI Specification
440          */
441         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
442             "**** Write to Debug Object: Object %p %s ****:\n\n",
443             SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
444
445         AcpiExDoDebugObject (SourceDesc, 0, 0);
446         break;
447
448
449     default:
450
451         ACPI_ERROR ((AE_INFO, "Unknown Reference opcode %X",
452             RefDesc->Reference.Opcode));
453         ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_ERROR);
454
455         Status = AE_AML_INTERNAL;
456         break;
457     }
458
459     return_ACPI_STATUS (Status);
460 }
461
462
463 /*******************************************************************************
464  *
465  * FUNCTION:    AcpiExStoreObjectToIndex
466  *
467  * PARAMETERS:  *SourceDesc             - Value to be stored
468  *              *DestDesc               - Named object to receive the value
469  *              WalkState               - Current walk state
470  *
471  * RETURN:      Status
472  *
473  * DESCRIPTION: Store the object to indexed Buffer or Package element
474  *
475  ******************************************************************************/
476
477 static ACPI_STATUS
478 AcpiExStoreObjectToIndex (
479     ACPI_OPERAND_OBJECT     *SourceDesc,
480     ACPI_OPERAND_OBJECT     *IndexDesc,
481     ACPI_WALK_STATE         *WalkState)
482 {
483     ACPI_STATUS             Status = AE_OK;
484     ACPI_OPERAND_OBJECT     *ObjDesc;
485     ACPI_OPERAND_OBJECT     *NewDesc;
486     UINT8                   Value = 0;
487     UINT32                  i;
488
489
490     ACPI_FUNCTION_TRACE (ExStoreObjectToIndex);
491
492
493     /*
494      * Destination must be a reference pointer, and
495      * must point to either a buffer or a package
496      */
497     switch (IndexDesc->Reference.TargetType)
498     {
499     case ACPI_TYPE_PACKAGE:
500         /*
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.
504          *
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
508          */
509         ObjDesc = *(IndexDesc->Reference.Where);
510
511         Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState);
512         if (ACPI_FAILURE (Status))
513         {
514             return_ACPI_STATUS (Status);
515         }
516
517         if (ObjDesc)
518         {
519             /* Decrement reference count by the ref count of the parent package */
520
521             for (i = 0;
522                  i < ((ACPI_OPERAND_OBJECT *)
523                         IndexDesc->Reference.Object)->Common.ReferenceCount;
524                  i++)
525             {
526                 AcpiUtRemoveReference (ObjDesc);
527             }
528         }
529
530         *(IndexDesc->Reference.Where) = NewDesc;
531
532         /* Increment ref count by the ref count of the parent package-1 */
533
534         for (i = 1;
535              i < ((ACPI_OPERAND_OBJECT *)
536                     IndexDesc->Reference.Object)->Common.ReferenceCount;
537              i++)
538         {
539             AcpiUtAddReference (NewDesc);
540         }
541
542         break;
543
544
545     case ACPI_TYPE_BUFFER_FIELD:
546
547         /*
548          * Store into a Buffer or String (not actually a real BufferField)
549          * at a location defined by an Index.
550          *
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.
554          */
555
556         /*
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.
560          */
561         ObjDesc = IndexDesc->Reference.Object;
562         if ((ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_BUFFER) &&
563             (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_STRING))
564         {
565             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
566         }
567
568         /*
569          * The assignment of the individual elements will be slightly
570          * different for each source type.
571          */
572         switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
573         {
574         case ACPI_TYPE_INTEGER:
575
576             /* Use the least-significant byte of the integer */
577
578             Value = (UINT8) (SourceDesc->Integer.Value);
579             break;
580
581         case ACPI_TYPE_BUFFER:
582         case ACPI_TYPE_STRING:
583
584             /* Note: Takes advantage of common string/buffer fields */
585
586             Value = SourceDesc->Buffer.Pointer[0];
587             break;
588
589         default:
590
591             /* All other types are invalid */
592
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);
597         }
598
599         /* Store the source value into the target buffer byte */
600
601         ObjDesc->Buffer.Pointer[IndexDesc->Reference.Offset] = Value;
602         break;
603
604
605     default:
606         ACPI_ERROR ((AE_INFO,
607             "Target is not a Package or BufferField"));
608         Status = AE_AML_OPERAND_TYPE;
609         break;
610     }
611
612     return_ACPI_STATUS (Status);
613 }
614
615
616 /*******************************************************************************
617  *
618  * FUNCTION:    AcpiExStoreObjectToNode
619  *
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)
624  *
625  * RETURN:      Status
626  *
627  * DESCRIPTION: Store the object to the named object.
628  *
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.
632  *
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.
637  *
638  *              Assumes parameters are already validated.
639  *
640  ******************************************************************************/
641
642 ACPI_STATUS
643 AcpiExStoreObjectToNode (
644     ACPI_OPERAND_OBJECT     *SourceDesc,
645     ACPI_NAMESPACE_NODE     *Node,
646     ACPI_WALK_STATE         *WalkState,
647     UINT8                   ImplicitConversion)
648 {
649     ACPI_STATUS             Status = AE_OK;
650     ACPI_OPERAND_OBJECT     *TargetDesc;
651     ACPI_OPERAND_OBJECT     *NewDesc;
652     ACPI_OBJECT_TYPE        TargetType;
653
654
655     ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc);
656
657
658     /* Get current type of the node, and object attached to Node */
659
660     TargetType = AcpiNsGetType (Node);
661     TargetDesc = AcpiNsGetAttachedObject (Node);
662
663     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
664         SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
665               Node, AcpiUtGetTypeName (TargetType)));
666
667     /*
668      * Resolve the source object to an actual value
669      * (If it is a reference object)
670      */
671     Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
672     if (ACPI_FAILURE (Status))
673     {
674         return_ACPI_STATUS (Status);
675     }
676
677     /* If no implicit conversion, drop into the default case below */
678
679     if ((!ImplicitConversion) || (WalkState->Opcode == AML_COPY_OP))
680     {
681         /* Force execution of default (no implicit conversion) */
682
683         TargetType = ACPI_TYPE_ANY;
684     }
685
686     /* Do the actual store operation */
687
688     switch (TargetType)
689     {
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:
694
695         /* For fields, copy the source data to the target field. */
696
697         Status = AcpiExWriteDataToField (SourceDesc, TargetDesc,
698                     &WalkState->ResultObj);
699         break;
700
701
702     case ACPI_TYPE_INTEGER:
703     case ACPI_TYPE_STRING:
704     case ACPI_TYPE_BUFFER:
705
706         /*
707          * These target types are all of type Integer/String/Buffer, and
708          * therefore support implicit conversion before the store.
709          *
710          * Copy and/or convert the source object to a new target object
711          */
712         Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc,
713                     &NewDesc, WalkState);
714         if (ACPI_FAILURE (Status))
715         {
716             return_ACPI_STATUS (Status);
717         }
718
719         if (NewDesc != TargetDesc)
720         {
721             /*
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.
725              *
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
728              * changed.
729              */
730             Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type);
731
732             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
733                 "Store %s into %s via Convert/Attach\n",
734                 AcpiUtGetObjectTypeName (SourceDesc),
735                 AcpiUtGetObjectTypeName (NewDesc)));
736         }
737         break;
738
739
740     default:
741
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));
745
746         /* No conversions for all other types.  Just attach the source object */
747
748         Status = AcpiNsAttachObject (Node, SourceDesc,
749                     ACPI_GET_OBJECT_TYPE (SourceDesc));
750         break;
751     }
752
753     return_ACPI_STATUS (Status);
754 }
755
756