utcopy.c revision 126372
1/******************************************************************************
2 *
3 * Module Name: utcopy - Internal to external object translation utilities
4 *              $Revision: 114 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#define __UTCOPY_C__
118
119#include "acpi.h"
120#include "amlcode.h"
121
122
123#define _COMPONENT          ACPI_UTILITIES
124        ACPI_MODULE_NAME    ("utcopy")
125
126
127/*******************************************************************************
128 *
129 * FUNCTION:    AcpiUtCopyIsimpleToEsimple
130 *
131 * PARAMETERS:  *InternalObject     - Pointer to the object we are examining
132 *              *Buffer             - Where the object is returned
133 *              *SpaceUsed          - Where the data length is returned
134 *
135 * RETURN:      Status
136 *
137 * DESCRIPTION: This function is called to place a simple object in a user
138 *              buffer.
139 *
140 *              The buffer is assumed to have sufficient space for the object.
141 *
142 ******************************************************************************/
143
144static ACPI_STATUS
145AcpiUtCopyIsimpleToEsimple (
146    ACPI_OPERAND_OBJECT     *InternalObject,
147    ACPI_OBJECT             *ExternalObject,
148    UINT8                   *DataSpace,
149    ACPI_SIZE               *BufferSpaceUsed)
150{
151    ACPI_STATUS             Status = AE_OK;
152
153
154    ACPI_FUNCTION_TRACE ("UtCopyIsimpleToEsimple");
155
156
157    *BufferSpaceUsed = 0;
158
159    /*
160     * Check for NULL object case (could be an uninitialized
161     * package element)
162     */
163    if (!InternalObject)
164    {
165        return_ACPI_STATUS (AE_OK);
166    }
167
168    /* Always clear the external object */
169
170    ACPI_MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
171
172    /*
173     * In general, the external object will be the same type as
174     * the internal object
175     */
176    ExternalObject->Type = ACPI_GET_OBJECT_TYPE (InternalObject);
177
178    /* However, only a limited number of external types are supported */
179
180    switch (ACPI_GET_OBJECT_TYPE (InternalObject))
181    {
182    case ACPI_TYPE_STRING:
183
184        ExternalObject->String.Pointer = (char *) DataSpace;
185        ExternalObject->String.Length  = InternalObject->String.Length;
186        *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD ((ACPI_SIZE) InternalObject->String.Length + 1);
187
188        ACPI_MEMCPY ((void *) DataSpace, (void *) InternalObject->String.Pointer,
189                    (ACPI_SIZE) InternalObject->String.Length + 1);
190        break;
191
192
193    case ACPI_TYPE_BUFFER:
194
195        ExternalObject->Buffer.Pointer = DataSpace;
196        ExternalObject->Buffer.Length  = InternalObject->Buffer.Length;
197        *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (InternalObject->String.Length);
198
199        ACPI_MEMCPY ((void *) DataSpace, (void *) InternalObject->Buffer.Pointer,
200                    InternalObject->Buffer.Length);
201        break;
202
203
204    case ACPI_TYPE_INTEGER:
205
206        ExternalObject->Integer.Value = InternalObject->Integer.Value;
207        break;
208
209
210    case ACPI_TYPE_LOCAL_REFERENCE:
211
212        /*
213         * This is an object reference.  Attempt to dereference it.
214         */
215        switch (InternalObject->Reference.Opcode)
216        {
217        case AML_INT_NAMEPATH_OP:
218
219            /* For namepath, return the object handle ("reference") */
220
221        default:
222            /*
223             * Use the object type of "Any" to indicate a reference
224             * to object containing a handle to an ACPI named object.
225             */
226            ExternalObject->Type = ACPI_TYPE_ANY;
227            ExternalObject->Reference.Handle = InternalObject->Reference.Node;
228            break;
229        }
230        break;
231
232
233    case ACPI_TYPE_PROCESSOR:
234
235        ExternalObject->Processor.ProcId      = InternalObject->Processor.ProcId;
236        ExternalObject->Processor.PblkAddress = InternalObject->Processor.Address;
237        ExternalObject->Processor.PblkLength  = InternalObject->Processor.Length;
238        break;
239
240
241    case ACPI_TYPE_POWER:
242
243        ExternalObject->PowerResource.SystemLevel =
244                            InternalObject->PowerResource.SystemLevel;
245
246        ExternalObject->PowerResource.ResourceOrder =
247                            InternalObject->PowerResource.ResourceOrder;
248        break;
249
250
251    default:
252        /*
253         * There is no corresponding external object type
254         */
255        return_ACPI_STATUS (AE_SUPPORT);
256    }
257
258    return_ACPI_STATUS (Status);
259}
260
261
262/*******************************************************************************
263 *
264 * FUNCTION:    AcpiUtCopyIelementToEelement
265 *
266 * PARAMETERS:  ACPI_PKG_CALLBACK
267 *
268 * RETURN:      Status
269 *
270 * DESCRIPTION: Copy one package element to another package element
271 *
272 ******************************************************************************/
273
274ACPI_STATUS
275AcpiUtCopyIelementToEelement (
276    UINT8                   ObjectType,
277    ACPI_OPERAND_OBJECT     *SourceObject,
278    ACPI_GENERIC_STATE      *State,
279    void                    *Context)
280{
281    ACPI_STATUS             Status = AE_OK;
282    ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
283    ACPI_SIZE               ObjectSpace;
284    UINT32                  ThisIndex;
285    ACPI_OBJECT             *TargetObject;
286
287
288    ACPI_FUNCTION_ENTRY ();
289
290
291    ThisIndex    = State->Pkg.Index;
292    TargetObject = (ACPI_OBJECT *)
293                    &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
294
295    switch (ObjectType)
296    {
297    case ACPI_COPY_TYPE_SIMPLE:
298
299        /*
300         * This is a simple or null object
301         */
302        Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
303                        TargetObject, Info->FreeSpace, &ObjectSpace);
304        if (ACPI_FAILURE (Status))
305        {
306            return (Status);
307        }
308        break;
309
310
311    case ACPI_COPY_TYPE_PACKAGE:
312
313        /*
314         * Build the package object
315         */
316        TargetObject->Type              = ACPI_TYPE_PACKAGE;
317        TargetObject->Package.Count     = SourceObject->Package.Count;
318        TargetObject->Package.Elements  = ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);
319
320        /*
321         * Pass the new package object back to the package walk routine
322         */
323        State->Pkg.ThisTargetObj = TargetObject;
324
325        /*
326         * Save space for the array of objects (Package elements)
327         * update the buffer length counter
328         */
329        ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (
330                            (ACPI_SIZE) TargetObject->Package.Count * sizeof (ACPI_OBJECT));
331        break;
332
333
334    default:
335        return (AE_BAD_PARAMETER);
336    }
337
338    Info->FreeSpace   += ObjectSpace;
339    Info->Length      += ObjectSpace;
340    return (Status);
341}
342
343
344/*******************************************************************************
345 *
346 * FUNCTION:    AcpiUtCopyIpackageToEpackage
347 *
348 * PARAMETERS:  *InternalObject     - Pointer to the object we are returning
349 *              *Buffer             - Where the object is returned
350 *              *SpaceUsed          - Where the object length is returned
351 *
352 * RETURN:      Status
353 *
354 * DESCRIPTION: This function is called to place a package object in a user
355 *              buffer.  A package object by definition contains other objects.
356 *
357 *              The buffer is assumed to have sufficient space for the object.
358 *              The caller must have verified the buffer length needed using the
359 *              AcpiUtGetObjectSize function before calling this function.
360 *
361 ******************************************************************************/
362
363static ACPI_STATUS
364AcpiUtCopyIpackageToEpackage (
365    ACPI_OPERAND_OBJECT     *InternalObject,
366    UINT8                   *Buffer,
367    ACPI_SIZE               *SpaceUsed)
368{
369    ACPI_OBJECT             *ExternalObject;
370    ACPI_STATUS             Status;
371    ACPI_PKG_INFO           Info;
372
373
374    ACPI_FUNCTION_TRACE ("UtCopyIpackageToEpackage");
375
376
377    /*
378     * First package at head of the buffer
379     */
380    ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);
381
382    /*
383     * Free space begins right after the first package
384     */
385    Info.Length      = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
386    Info.FreeSpace   = Buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
387    Info.ObjectSpace = 0;
388    Info.NumPackages = 1;
389
390    ExternalObject->Type             = ACPI_GET_OBJECT_TYPE (InternalObject);
391    ExternalObject->Package.Count    = InternalObject->Package.Count;
392    ExternalObject->Package.Elements = ACPI_CAST_PTR (ACPI_OBJECT, Info.FreeSpace);
393
394    /*
395     * Leave room for an array of ACPI_OBJECTS in the buffer
396     * and move the free space past it
397     */
398    Info.Length    += (ACPI_SIZE) ExternalObject->Package.Count *
399                            ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
400    Info.FreeSpace += ExternalObject->Package.Count *
401                            ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
402
403    Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
404                            AcpiUtCopyIelementToEelement, &Info);
405
406    *SpaceUsed = Info.Length;
407    return_ACPI_STATUS (Status);
408}
409
410
411/*******************************************************************************
412 *
413 * FUNCTION:    AcpiUtCopyIobjectToEobject
414 *
415 * PARAMETERS:  *InternalObject     - The internal object to be converted
416 *              *BufferPtr          - Where the object is returned
417 *
418 * RETURN:      Status
419 *
420 * DESCRIPTION: This function is called to build an API object to be returned to
421 *              the caller.
422 *
423 ******************************************************************************/
424
425ACPI_STATUS
426AcpiUtCopyIobjectToEobject (
427    ACPI_OPERAND_OBJECT     *InternalObject,
428    ACPI_BUFFER             *RetBuffer)
429{
430    ACPI_STATUS             Status;
431
432
433    ACPI_FUNCTION_TRACE ("UtCopyIobjectToEobject");
434
435
436    if (ACPI_GET_OBJECT_TYPE (InternalObject) == ACPI_TYPE_PACKAGE)
437    {
438        /*
439         * Package object:  Copy all subobjects (including
440         * nested packages)
441         */
442        Status = AcpiUtCopyIpackageToEpackage (InternalObject,
443                        RetBuffer->Pointer, &RetBuffer->Length);
444    }
445    else
446    {
447        /*
448         * Build a simple object (no nested objects)
449         */
450        Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
451                        (ACPI_OBJECT *) RetBuffer->Pointer,
452                        ((UINT8 *) RetBuffer->Pointer +
453                        ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
454                        &RetBuffer->Length);
455        /*
456         * build simple does not include the object size in the length
457         * so we add it in here
458         */
459        RetBuffer->Length += sizeof (ACPI_OBJECT);
460    }
461
462    return_ACPI_STATUS (Status);
463}
464
465
466/*******************************************************************************
467 *
468 * FUNCTION:    AcpiUtCopyEsimpleToIsimple
469 *
470 * PARAMETERS:  *ExternalObject    - The external object to be converted
471 *              *InternalObject    - Where the internal object is returned
472 *
473 * RETURN:      Status
474 *
475 * DESCRIPTION: This function copies an external object to an internal one.
476 *              NOTE: Pointers can be copied, we don't need to copy data.
477 *              (The pointers have to be valid in our address space no matter
478 *              what we do with them!)
479 *
480 ******************************************************************************/
481
482ACPI_STATUS
483AcpiUtCopyEsimpleToIsimple (
484    ACPI_OBJECT             *ExternalObject,
485    ACPI_OPERAND_OBJECT     **RetInternalObject)
486{
487    ACPI_OPERAND_OBJECT     *InternalObject;
488
489
490    ACPI_FUNCTION_TRACE ("UtCopyEsimpleToIsimple");
491
492
493    /*
494     * Simple types supported are: String, Buffer, Integer
495     */
496    switch (ExternalObject->Type)
497    {
498    case ACPI_TYPE_STRING:
499    case ACPI_TYPE_BUFFER:
500    case ACPI_TYPE_INTEGER:
501
502        InternalObject = AcpiUtCreateInternalObject ((UINT8) ExternalObject->Type);
503        if (!InternalObject)
504        {
505            return_ACPI_STATUS (AE_NO_MEMORY);
506        }
507        break;
508
509    default:
510        /*
511         * Whatever other type -- it is not supported
512         */
513        return_ACPI_STATUS (AE_SUPPORT);
514    }
515
516
517    switch (ExternalObject->Type)
518    {
519
520    /* Must COPY string and buffer contents */
521
522    case ACPI_TYPE_STRING:
523
524        InternalObject->String.Pointer =
525            ACPI_MEM_CALLOCATE ((ACPI_SIZE) ExternalObject->String.Length + 1);
526        if (!InternalObject->String.Pointer)
527        {
528            return_ACPI_STATUS (AE_NO_MEMORY);
529        }
530
531        ACPI_MEMCPY (InternalObject->String.Pointer,
532                     ExternalObject->String.Pointer,
533                     ExternalObject->String.Length);
534
535        InternalObject->String.Length  = ExternalObject->String.Length;
536        break;
537
538
539    case ACPI_TYPE_BUFFER:
540
541        InternalObject->Buffer.Pointer =
542            ACPI_MEM_CALLOCATE (ExternalObject->Buffer.Length);
543        if (!InternalObject->Buffer.Pointer)
544        {
545            return_ACPI_STATUS (AE_NO_MEMORY);
546        }
547
548        ACPI_MEMCPY (InternalObject->Buffer.Pointer,
549                     ExternalObject->Buffer.Pointer,
550                     ExternalObject->Buffer.Length);
551
552        InternalObject->Buffer.Length  = ExternalObject->Buffer.Length;
553        break;
554
555
556    case ACPI_TYPE_INTEGER:
557
558        InternalObject->Integer.Value   = ExternalObject->Integer.Value;
559        break;
560
561    default:
562        /* Other types can't get here */
563        break;
564    }
565
566    *RetInternalObject = InternalObject;
567    return_ACPI_STATUS (AE_OK);
568}
569
570
571#ifdef ACPI_FUTURE_IMPLEMENTATION
572
573/* Code to convert packages that are parameters to control methods */
574
575/*******************************************************************************
576 *
577 * FUNCTION:    AcpiUtCopyEpackageToIpackage
578 *
579 * PARAMETERS:  *InternalObject    - Pointer to the object we are returning
580 *              *Buffer            - Where the object is returned
581 *              *SpaceUsed         - Where the length of the object is returned
582 *
583 * RETURN:      Status
584 *
585 * DESCRIPTION: This function is called to place a package object in a user
586 *              buffer.  A package object by definition contains other objects.
587 *
588 *              The buffer is assumed to have sufficient space for the object.
589 *              The caller must have verified the buffer length needed using the
590 *              AcpiUtGetObjectSize function before calling this function.
591 *
592 ******************************************************************************/
593
594static ACPI_STATUS
595AcpiUtCopyEpackageToIpackage (
596    ACPI_OPERAND_OBJECT     *InternalObject,
597    UINT8                   *Buffer,
598    UINT32                  *SpaceUsed)
599{
600    UINT8                   *FreeSpace;
601    ACPI_OBJECT             *ExternalObject;
602    UINT32                  Length = 0;
603    UINT32                  ThisIndex;
604    UINT32                  ObjectSpace = 0;
605    ACPI_OPERAND_OBJECT     *ThisInternalObj;
606    ACPI_OBJECT             *ThisExternalObj;
607
608
609    ACPI_FUNCTION_TRACE ("UtCopyEpackageToIpackage");
610
611
612    /*
613     * First package at head of the buffer
614     */
615    ExternalObject = (ACPI_OBJECT *)Buffer;
616
617    /*
618     * Free space begins right after the first package
619     */
620    FreeSpace = Buffer + sizeof(ACPI_OBJECT);
621
622
623    ExternalObject->Type               = ACPI_GET_OBJECT_TYPE (InternalObject);
624    ExternalObject->Package.Count      = InternalObject->Package.Count;
625    ExternalObject->Package.Elements   = (ACPI_OBJECT *)FreeSpace;
626
627    /*
628     * Build an array of ACPI_OBJECTS in the buffer
629     * and move the free space past it
630     */
631    FreeSpace += ExternalObject->Package.Count * sizeof(ACPI_OBJECT);
632
633
634    /* Call WalkPackage */
635
636}
637
638#endif /* Future implementation */
639
640
641/*******************************************************************************
642 *
643 * FUNCTION:    AcpiUtCopyEobjectToIobject
644 *
645 * PARAMETERS:  *InternalObject    - The external object to be converted
646 *              *BufferPtr      - Where the internal object is returned
647 *
648 * RETURN:      Status          - the status of the call
649 *
650 * DESCRIPTION: Converts an external object to an internal object.
651 *
652 ******************************************************************************/
653
654ACPI_STATUS
655AcpiUtCopyEobjectToIobject (
656    ACPI_OBJECT             *ExternalObject,
657    ACPI_OPERAND_OBJECT     **InternalObject)
658{
659    ACPI_STATUS             Status;
660
661
662    ACPI_FUNCTION_TRACE ("UtCopyEobjectToIobject");
663
664
665    if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
666    {
667        /*
668         * Packages as external input to control methods are not supported,
669         */
670        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
671            "Packages as parameters not implemented!\n"));
672
673        return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
674    }
675
676    else
677    {
678        /*
679         * Build a simple object (no nested objects)
680         */
681        Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject);
682    }
683
684    return_ACPI_STATUS (Status);
685}
686
687
688/*******************************************************************************
689 *
690 * FUNCTION:    AcpiUtCopySimpleObject
691 *
692 * PARAMETERS:  SourceDesc          - The internal object to be copied
693 *              DestDesc            - New target object
694 *
695 * RETURN:      Status
696 *
697 * DESCRIPTION: Simple copy of one internal object to another.  Reference count
698 *              of the destination object is preserved.
699 *
700 ******************************************************************************/
701
702ACPI_STATUS
703AcpiUtCopySimpleObject (
704    ACPI_OPERAND_OBJECT     *SourceDesc,
705    ACPI_OPERAND_OBJECT     *DestDesc)
706{
707    UINT16                  ReferenceCount;
708    ACPI_OPERAND_OBJECT     *NextObject;
709
710
711    /* Save fields from destination that we don't want to overwrite */
712
713    ReferenceCount = DestDesc->Common.ReferenceCount;
714    NextObject = DestDesc->Common.NextObject;
715
716    /* Copy the entire source object over the destination object*/
717
718    ACPI_MEMCPY ((char *) DestDesc, (char *) SourceDesc,
719                    sizeof (ACPI_OPERAND_OBJECT));
720
721    /* Restore the saved fields */
722
723    DestDesc->Common.ReferenceCount = ReferenceCount;
724    DestDesc->Common.NextObject = NextObject;
725
726    /* Handle the objects with extra data */
727
728    switch (ACPI_GET_OBJECT_TYPE (DestDesc))
729    {
730    case ACPI_TYPE_BUFFER:
731
732        DestDesc->Buffer.Node = NULL;
733        DestDesc->Common.Flags = SourceDesc->Common.Flags;
734
735        /*
736         * Allocate and copy the actual buffer if and only if:
737         * 1) There is a valid buffer pointer
738         * 2) The buffer is not static (not in an ACPI table) (in this case,
739         *    the actual pointer was already copied above)
740         */
741        if ((SourceDesc->Buffer.Pointer) &&
742            (!(SourceDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
743        {
744            DestDesc->Buffer.Pointer = NULL;
745
746            /* Create an actual buffer only if length > 0 */
747
748            if (SourceDesc->Buffer.Length)
749            {
750                DestDesc->Buffer.Pointer = ACPI_MEM_ALLOCATE (SourceDesc->Buffer.Length);
751                if (!DestDesc->Buffer.Pointer)
752                {
753                    return (AE_NO_MEMORY);
754                }
755
756                /* Copy the actual buffer data */
757
758                ACPI_MEMCPY (DestDesc->Buffer.Pointer, SourceDesc->Buffer.Pointer,
759                             SourceDesc->Buffer.Length);
760            }
761        }
762        break;
763
764    case ACPI_TYPE_STRING:
765
766        /*
767         * Allocate and copy the actual string if and only if:
768         * 1) There is a valid string pointer
769         * 2) The string is not static (not in an ACPI table) (in this case,
770         *    the actual pointer was already copied above)
771         */
772        if ((SourceDesc->String.Pointer) &&
773            (!(SourceDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
774        {
775            DestDesc->String.Pointer = ACPI_MEM_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1);
776            if (!DestDesc->String.Pointer)
777            {
778                return (AE_NO_MEMORY);
779            }
780
781            ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer,
782                         (ACPI_SIZE) SourceDesc->String.Length + 1);
783        }
784        break;
785
786    default:
787        /* Nothing to do for other simple objects */
788        break;
789    }
790
791    return (AE_OK);
792}
793
794
795/*******************************************************************************
796 *
797 * FUNCTION:    AcpiUtCopyIelementToIelement
798 *
799 * PARAMETERS:  ACPI_PKG_CALLBACK
800 *
801 * RETURN:      Status
802 *
803 * DESCRIPTION: Copy one package element to another package element
804 *
805 ******************************************************************************/
806
807ACPI_STATUS
808AcpiUtCopyIelementToIelement (
809    UINT8                   ObjectType,
810    ACPI_OPERAND_OBJECT     *SourceObject,
811    ACPI_GENERIC_STATE      *State,
812    void                    *Context)
813{
814    ACPI_STATUS             Status = AE_OK;
815    UINT32                  ThisIndex;
816    ACPI_OPERAND_OBJECT     **ThisTargetPtr;
817    ACPI_OPERAND_OBJECT     *TargetObject;
818
819
820    ACPI_FUNCTION_ENTRY ();
821
822
823    ThisIndex     = State->Pkg.Index;
824    ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
825                        &State->Pkg.DestObject->Package.Elements[ThisIndex];
826
827    switch (ObjectType)
828    {
829    case ACPI_COPY_TYPE_SIMPLE:
830
831        /* A null source object indicates a (legal) null package element */
832
833        if (SourceObject)
834        {
835            /*
836             * This is a simple object, just copy it
837             */
838            TargetObject = AcpiUtCreateInternalObject (
839                                ACPI_GET_OBJECT_TYPE (SourceObject));
840            if (!TargetObject)
841            {
842                return (AE_NO_MEMORY);
843            }
844
845            Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);
846            if (ACPI_FAILURE (Status))
847            {
848                return (Status);
849            }
850
851            *ThisTargetPtr = TargetObject;
852        }
853        else
854        {
855            /* Pass through a null element */
856
857            *ThisTargetPtr = NULL;
858        }
859        break;
860
861
862    case ACPI_COPY_TYPE_PACKAGE:
863
864        /*
865         * This object is a package - go down another nesting level
866         * Create and build the package object
867         */
868        TargetObject = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
869        if (!TargetObject)
870        {
871            return (AE_NO_MEMORY);
872        }
873
874        TargetObject->Package.Count = SourceObject->Package.Count;
875        TargetObject->Common.Flags  = SourceObject->Common.Flags;
876
877        /*
878         * Create the object array
879         */
880        TargetObject->Package.Elements =
881            ACPI_MEM_CALLOCATE (((ACPI_SIZE) SourceObject->Package.Count + 1) *
882                                    sizeof (void *));
883        if (!TargetObject->Package.Elements)
884        {
885            ACPI_MEM_FREE (TargetObject);
886            return (AE_NO_MEMORY);
887        }
888
889        /*
890         * Pass the new package object back to the package walk routine
891         */
892        State->Pkg.ThisTargetObj = TargetObject;
893
894        /*
895         * Store the object pointer in the parent package object
896         */
897        *ThisTargetPtr = TargetObject;
898        break;
899
900
901    default:
902        return (AE_BAD_PARAMETER);
903    }
904
905    return (Status);
906}
907
908
909/*******************************************************************************
910 *
911 * FUNCTION:    AcpiUtCopyIpackageToIpackage
912 *
913 * PARAMETERS:  *SourceObj      - Pointer to the source package object
914 *              *DestObj        - Where the internal object is returned
915 *
916 * RETURN:      Status          - the status of the call
917 *
918 * DESCRIPTION: This function is called to copy an internal package object
919 *              into another internal package object.
920 *
921 ******************************************************************************/
922
923ACPI_STATUS
924AcpiUtCopyIpackageToIpackage (
925    ACPI_OPERAND_OBJECT     *SourceObj,
926    ACPI_OPERAND_OBJECT     *DestObj,
927    ACPI_WALK_STATE         *WalkState)
928{
929    ACPI_STATUS             Status = AE_OK;
930
931
932    ACPI_FUNCTION_TRACE ("UtCopyIpackageToIpackage");
933
934
935    DestObj->Common.Type    = ACPI_GET_OBJECT_TYPE (SourceObj);
936    DestObj->Common.Flags   = SourceObj->Common.Flags;
937    DestObj->Package.Count  = SourceObj->Package.Count;
938
939    /*
940     * Create the object array and walk the source package tree
941     */
942    DestObj->Package.Elements = ACPI_MEM_CALLOCATE (
943                                    ((ACPI_SIZE) SourceObj->Package.Count + 1) *
944                                    sizeof (void *));
945    if (!DestObj->Package.Elements)
946    {
947        ACPI_REPORT_ERROR (
948            ("AmlBuildCopyInternalPackageObject: Package allocation failure\n"));
949        return_ACPI_STATUS (AE_NO_MEMORY);
950    }
951
952    /*
953     * Copy the package element-by-element by walking the package "tree".
954     * This handles nested packages of arbitrary depth.
955     */
956    Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
957                            AcpiUtCopyIelementToIelement, WalkState);
958    if (ACPI_FAILURE (Status))
959    {
960        /* On failure, delete the destination package object */
961
962        AcpiUtRemoveReference (DestObj);
963    }
964
965    return_ACPI_STATUS (Status);
966}
967
968
969/*******************************************************************************
970 *
971 * FUNCTION:    AcpiUtCopyIobjectToIobject
972 *
973 * PARAMETERS:  WalkState           - Current walk state
974 *              SourceDesc          - The internal object to be copied
975 *              DestDesc            - Where the copied object is returned
976 *
977 * RETURN:      Status
978 *
979 * DESCRIPTION: Copy an internal object to a new internal object
980 *
981 ******************************************************************************/
982
983ACPI_STATUS
984AcpiUtCopyIobjectToIobject (
985    ACPI_OPERAND_OBJECT     *SourceDesc,
986    ACPI_OPERAND_OBJECT     **DestDesc,
987    ACPI_WALK_STATE         *WalkState)
988{
989    ACPI_STATUS             Status = AE_OK;
990
991
992    ACPI_FUNCTION_TRACE ("UtCopyIobjectToIobject");
993
994
995    /* Create the top level object */
996
997    *DestDesc = AcpiUtCreateInternalObject (ACPI_GET_OBJECT_TYPE (SourceDesc));
998    if (!*DestDesc)
999    {
1000        return_ACPI_STATUS (AE_NO_MEMORY);
1001    }
1002
1003    /* Copy the object and possible subobjects */
1004
1005    if (ACPI_GET_OBJECT_TYPE (SourceDesc) == ACPI_TYPE_PACKAGE)
1006    {
1007        Status = AcpiUtCopyIpackageToIpackage (SourceDesc, *DestDesc,
1008                        WalkState);
1009    }
1010    else
1011    {
1012        Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);
1013    }
1014
1015    return_ACPI_STATUS (Status);
1016}
1017
1018
1019