utcopy.c revision 100966
1/******************************************************************************
2 *
3 * Module Name: utcopy - Internal to external object translation utilities
4 *              $Revision: 103 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, 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 "acnamesp.h"
121#include "amlcode.h"
122
123
124#define _COMPONENT          ACPI_UTILITIES
125        ACPI_MODULE_NAME    ("utcopy")
126
127
128/*******************************************************************************
129 *
130 * FUNCTION:    AcpiUtCopyIsimpleToEsimple
131 *
132 * PARAMETERS:  *InternalObject     - Pointer to the object we are examining
133 *              *Buffer             - Where the object is returned
134 *              *SpaceUsed          - Where the data length is returned
135 *
136 * RETURN:      Status
137 *
138 * DESCRIPTION: This function is called to place a simple object in a user
139 *              buffer.
140 *
141 *              The buffer is assumed to have sufficient space for the object.
142 *
143 ******************************************************************************/
144
145static ACPI_STATUS
146AcpiUtCopyIsimpleToEsimple (
147    ACPI_OPERAND_OBJECT     *InternalObject,
148    ACPI_OBJECT             *ExternalObject,
149    UINT8                   *DataSpace,
150    ACPI_SIZE               *BufferSpaceUsed)
151{
152    ACPI_STATUS             Status = AE_OK;
153
154
155    ACPI_FUNCTION_TRACE ("UtCopyIsimpleToEsimple");
156
157
158    *BufferSpaceUsed = 0;
159
160    /*
161     * Check for NULL object case (could be an uninitialized
162     * package element)
163     */
164    if (!InternalObject)
165    {
166        return_ACPI_STATUS (AE_OK);
167    }
168
169    /* Always clear the external object */
170
171    ACPI_MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
172
173    /*
174     * In general, the external object will be the same type as
175     * the internal object
176     */
177    ExternalObject->Type = ACPI_GET_OBJECT_TYPE (InternalObject);
178
179    /* However, only a limited number of external types are supported */
180
181    switch (ACPI_GET_OBJECT_TYPE (InternalObject))
182    {
183    case ACPI_TYPE_STRING:
184
185        ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace;
186        ExternalObject->String.Length  = InternalObject->String.Length;
187        *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD ((ACPI_SIZE) InternalObject->String.Length + 1);
188
189        ACPI_MEMCPY ((void *) DataSpace, (void *) InternalObject->String.Pointer,
190                    (ACPI_SIZE) InternalObject->String.Length + 1);
191        break;
192
193
194    case ACPI_TYPE_BUFFER:
195
196        ExternalObject->Buffer.Pointer = DataSpace;
197        ExternalObject->Buffer.Length  = InternalObject->Buffer.Length;
198        *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (InternalObject->String.Length);
199
200        ACPI_MEMCPY ((void *) DataSpace, (void *) InternalObject->Buffer.Pointer,
201                    InternalObject->Buffer.Length);
202        break;
203
204
205    case ACPI_TYPE_INTEGER:
206
207        ExternalObject->Integer.Value = InternalObject->Integer.Value;
208        break;
209
210
211    case INTERNAL_TYPE_REFERENCE:
212
213        /*
214         * This is an object reference.  Attempt to dereference it.
215         */
216        switch (InternalObject->Reference.Opcode)
217        {
218        case AML_INT_NAMEPATH_OP:
219
220            /* For namepath, return the object handle ("reference") */
221
222        default:
223            /*
224             * Use the object type of "Any" to indicate a reference
225             * to object containing a handle to an ACPI named object.
226             */
227            ExternalObject->Type = ACPI_TYPE_ANY;
228            ExternalObject->Reference.Handle = InternalObject->Reference.Node;
229            break;
230        }
231        break;
232
233
234    case ACPI_TYPE_PROCESSOR:
235
236        ExternalObject->Processor.ProcId      = InternalObject->Processor.ProcId;
237        ExternalObject->Processor.PblkAddress = InternalObject->Processor.Address;
238        ExternalObject->Processor.PblkLength  = InternalObject->Processor.Length;
239        break;
240
241
242    case ACPI_TYPE_POWER:
243
244        ExternalObject->PowerResource.SystemLevel =
245                            InternalObject->PowerResource.SystemLevel;
246
247        ExternalObject->PowerResource.ResourceOrder =
248                            InternalObject->PowerResource.ResourceOrder;
249        break;
250
251
252    default:
253        /*
254         * There is no corresponding external object type
255         */
256        return_ACPI_STATUS (AE_SUPPORT);
257    }
258
259    return_ACPI_STATUS (Status);
260}
261
262
263/*******************************************************************************
264 *
265 * FUNCTION:    AcpiUtCopyIelementToEelement
266 *
267 * PARAMETERS:  ACPI_PKG_CALLBACK
268 *
269 * RETURN:      Status
270 *
271 * DESCRIPTION: Copy one package element to another package element
272 *
273 ******************************************************************************/
274
275ACPI_STATUS
276AcpiUtCopyIelementToEelement (
277    UINT8                   ObjectType,
278    ACPI_OPERAND_OBJECT     *SourceObject,
279    ACPI_GENERIC_STATE      *State,
280    void                    *Context)
281{
282    ACPI_STATUS             Status = AE_OK;
283    ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
284    ACPI_SIZE               ObjectSpace;
285    UINT32                  ThisIndex;
286    ACPI_OBJECT             *TargetObject;
287
288
289    ACPI_FUNCTION_ENTRY ();
290
291
292    ThisIndex    = State->Pkg.Index;
293    TargetObject = (ACPI_OBJECT *)
294                    &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
295
296    switch (ObjectType)
297    {
298    case ACPI_COPY_TYPE_SIMPLE:
299
300        /*
301         * This is a simple or null object
302         */
303        Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
304                        TargetObject, Info->FreeSpace, &ObjectSpace);
305        if (ACPI_FAILURE (Status))
306        {
307            return (Status);
308        }
309        break;
310
311
312    case ACPI_COPY_TYPE_PACKAGE:
313
314        /*
315         * Build the package object
316         */
317        TargetObject->Type              = ACPI_TYPE_PACKAGE;
318        TargetObject->Package.Count     = SourceObject->Package.Count;
319        TargetObject->Package.Elements  = ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);
320
321        /*
322         * Pass the new package object back to the package walk routine
323         */
324        State->Pkg.ThisTargetObj = TargetObject;
325
326        /*
327         * Save space for the array of objects (Package elements)
328         * update the buffer length counter
329         */
330        ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (
331                            (ACPI_SIZE) TargetObject->Package.Count * sizeof (ACPI_OBJECT));
332        break;
333
334
335    default:
336        return (AE_BAD_PARAMETER);
337    }
338
339    Info->FreeSpace   += ObjectSpace;
340    Info->Length      += ObjectSpace;
341    return (Status);
342}
343
344
345/*******************************************************************************
346 *
347 * FUNCTION:    AcpiUtCopyIpackageToEpackage
348 *
349 * PARAMETERS:  *InternalObject     - Pointer to the object we are returning
350 *              *Buffer             - Where the object is returned
351 *              *SpaceUsed          - Where the object length is returned
352 *
353 * RETURN:      Status
354 *
355 * DESCRIPTION: This function is called to place a package object in a user
356 *              buffer.  A package object by definition contains other objects.
357 *
358 *              The buffer is assumed to have sufficient space for the object.
359 *              The caller must have verified the buffer length needed using the
360 *              AcpiUtGetObjectSize function before calling this function.
361 *
362 ******************************************************************************/
363
364static ACPI_STATUS
365AcpiUtCopyIpackageToEpackage (
366    ACPI_OPERAND_OBJECT     *InternalObject,
367    UINT8                   *Buffer,
368    ACPI_SIZE               *SpaceUsed)
369{
370    ACPI_OBJECT             *ExternalObject;
371    ACPI_STATUS             Status;
372    ACPI_PKG_INFO           Info;
373
374
375    ACPI_FUNCTION_TRACE ("UtCopyIpackageToEpackage");
376
377
378    /*
379     * First package at head of the buffer
380     */
381    ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);
382
383    /*
384     * Free space begins right after the first package
385     */
386    Info.Length      = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
387    Info.FreeSpace   = Buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
388    Info.ObjectSpace = 0;
389    Info.NumPackages = 1;
390
391    ExternalObject->Type             = ACPI_GET_OBJECT_TYPE (InternalObject);
392    ExternalObject->Package.Count    = InternalObject->Package.Count;
393    ExternalObject->Package.Elements = ACPI_CAST_PTR (ACPI_OBJECT, Info.FreeSpace);
394
395    /*
396     * Leave room for an array of ACPI_OBJECTS in the buffer
397     * and move the free space past it
398     */
399    Info.Length    += (ACPI_SIZE) ExternalObject->Package.Count *
400                            ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
401    Info.FreeSpace += ExternalObject->Package.Count *
402                            ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
403
404    Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
405                            AcpiUtCopyIelementToEelement, &Info);
406
407    *SpaceUsed = Info.Length;
408    return_ACPI_STATUS (Status);
409}
410
411
412/*******************************************************************************
413 *
414 * FUNCTION:    AcpiUtCopyIobjectToEobject
415 *
416 * PARAMETERS:  *InternalObject     - The internal object to be converted
417 *              *BufferPtr          - Where the object is returned
418 *
419 * RETURN:      Status
420 *
421 * DESCRIPTION: This function is called to build an API object to be returned to
422 *              the caller.
423 *
424 ******************************************************************************/
425
426ACPI_STATUS
427AcpiUtCopyIobjectToEobject (
428    ACPI_OPERAND_OBJECT     *InternalObject,
429    ACPI_BUFFER             *RetBuffer)
430{
431    ACPI_STATUS             Status;
432
433
434    ACPI_FUNCTION_TRACE ("UtCopyIobjectToEobject");
435
436
437    if (ACPI_GET_OBJECT_TYPE (InternalObject) == ACPI_TYPE_PACKAGE)
438    {
439        /*
440         * Package object:  Copy all subobjects (including
441         * nested packages)
442         */
443        Status = AcpiUtCopyIpackageToEpackage (InternalObject,
444                        RetBuffer->Pointer, &RetBuffer->Length);
445    }
446    else
447    {
448        /*
449         * Build a simple object (no nested objects)
450         */
451        Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
452                        (ACPI_OBJECT *) RetBuffer->Pointer,
453                        ((UINT8 *) RetBuffer->Pointer +
454                        ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
455                        &RetBuffer->Length);
456        /*
457         * build simple does not include the object size in the length
458         * so we add it in here
459         */
460        RetBuffer->Length += sizeof (ACPI_OBJECT);
461    }
462
463    return_ACPI_STATUS (Status);
464}
465
466
467/*******************************************************************************
468 *
469 * FUNCTION:    AcpiUtCopyEsimpleToIsimple
470 *
471 * PARAMETERS:  *ExternalObject    - The external object to be converted
472 *              *InternalObject    - Where the internal object is returned
473 *
474 * RETURN:      Status
475 *
476 * DESCRIPTION: This function copies an external object to an internal one.
477 *              NOTE: Pointers can be copied, we don't need to copy data.
478 *              (The pointers have to be valid in our address space no matter
479 *              what we do with them!)
480 *
481 ******************************************************************************/
482
483ACPI_STATUS
484AcpiUtCopyEsimpleToIsimple (
485    ACPI_OBJECT             *ExternalObject,
486    ACPI_OPERAND_OBJECT     **RetInternalObject)
487{
488    ACPI_OPERAND_OBJECT     *InternalObject;
489
490
491    ACPI_FUNCTION_TRACE ("UtCopyEsimpleToIsimple");
492
493
494    /*
495     * Simple types supported are: String, Buffer, Integer
496     */
497    switch (ExternalObject->Type)
498    {
499    case ACPI_TYPE_STRING:
500    case ACPI_TYPE_BUFFER:
501    case ACPI_TYPE_INTEGER:
502
503        InternalObject = AcpiUtCreateInternalObject ((UINT8) ExternalObject->Type);
504        if (!InternalObject)
505        {
506            return_ACPI_STATUS (AE_NO_MEMORY);
507        }
508        break;
509
510    default:
511        /*
512         * Whatever other type -- it is not supported
513         */
514        return_ACPI_STATUS (AE_SUPPORT);
515    }
516
517
518    switch (ExternalObject->Type)
519    {
520
521    /* Must COPY string and buffer contents */
522
523    case ACPI_TYPE_STRING:
524
525        InternalObject->String.Pointer = 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 = ACPI_MEM_CALLOCATE (ExternalObject->Buffer.Length);
542        if (!InternalObject->Buffer.Pointer)
543        {
544            return_ACPI_STATUS (AE_NO_MEMORY);
545        }
546
547        ACPI_MEMCPY (InternalObject->Buffer.Pointer,
548                     ExternalObject->Buffer.Pointer,
549                     ExternalObject->Buffer.Length);
550
551        InternalObject->Buffer.Length  = ExternalObject->Buffer.Length;
552        break;
553
554
555    case ACPI_TYPE_INTEGER:
556
557        InternalObject->Integer.Value   = ExternalObject->Integer.Value;
558        break;
559
560    default:
561        /* Other types can't get here */
562        break;
563    }
564
565    *RetInternalObject = InternalObject;
566    return_ACPI_STATUS (AE_OK);
567}
568
569
570#ifdef ACPI_FUTURE_IMPLEMENTATION
571
572/* Code to convert packages that are parameters to control methods */
573
574/*******************************************************************************
575 *
576 * FUNCTION:    AcpiUtCopyEpackageToIpackage
577 *
578 * PARAMETERS:  *InternalObject    - Pointer to the object we are returning
579 *              *Buffer         - Where the object is returned
580 *              *SpaceUsed      - Where the length of the object is returned
581 *
582 * RETURN:      Status          - the status of the call
583 *
584 * DESCRIPTION: This function is called to place a package object in a user
585 *              buffer.  A package object by definition contains other objects.
586 *
587 *              The buffer is assumed to have sufficient space for the object.
588 *              The caller must have verified the buffer length needed using the
589 *              AcpiUtGetObjectSize function before calling this function.
590 *
591 ******************************************************************************/
592
593static ACPI_STATUS
594AcpiUtCopyEpackageToIpackage (
595    ACPI_OPERAND_OBJECT     *InternalObject,
596    UINT8                   *Buffer,
597    UINT32                  *SpaceUsed)
598{
599    UINT8                   *FreeSpace;
600    ACPI_OBJECT             *ExternalObject;
601    UINT32                  Length = 0;
602    UINT32                  ThisIndex;
603    UINT32                  ObjectSpace = 0;
604    ACPI_OPERAND_OBJECT     *ThisInternalObj;
605    ACPI_OBJECT             *ThisExternalObj;
606
607
608    ACPI_FUNCTION_TRACE ("UtCopyEpackageToIpackage");
609
610
611    /*
612     * First package at head of the buffer
613     */
614    ExternalObject = (ACPI_OBJECT *)Buffer;
615
616    /*
617     * Free space begins right after the first package
618     */
619    FreeSpace = Buffer + sizeof(ACPI_OBJECT);
620
621
622    ExternalObject->Type               = ACPI_GET_OBJECT_TYPE (InternalObject);
623    ExternalObject->Package.Count      = InternalObject->Package.Count;
624    ExternalObject->Package.Elements   = (ACPI_OBJECT *)FreeSpace;
625
626    /*
627     * Build an array of ACPI_OBJECTS in the buffer
628     * and move the free space past it
629     */
630    FreeSpace += ExternalObject->Package.Count * sizeof(ACPI_OBJECT);
631
632
633    /* Call WalkPackage */
634
635}
636
637#endif /* Future implementation */
638
639
640/*******************************************************************************
641 *
642 * FUNCTION:    AcpiUtCopyEobjectToIobject
643 *
644 * PARAMETERS:  *InternalObject    - The external object to be converted
645 *              *BufferPtr      - Where the internal object is returned
646 *
647 * RETURN:      Status          - the status of the call
648 *
649 * DESCRIPTION: Converts an external object to an internal object.
650 *
651 ******************************************************************************/
652
653ACPI_STATUS
654AcpiUtCopyEobjectToIobject (
655    ACPI_OBJECT             *ExternalObject,
656    ACPI_OPERAND_OBJECT     **InternalObject)
657{
658    ACPI_STATUS             Status;
659
660
661    ACPI_FUNCTION_TRACE ("UtCopyEobjectToIobject");
662
663
664    if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
665    {
666        /*
667         * Packages as external input to control methods are not supported,
668         */
669        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
670            "Packages as parameters not implemented!\n"));
671
672        return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
673    }
674
675    else
676    {
677        /*
678         * Build a simple object (no nested objects)
679         */
680        Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject);
681    }
682
683    return_ACPI_STATUS (Status);
684}
685
686
687/*******************************************************************************
688 *
689 * FUNCTION:    AcpiUtCopySimpleObject
690 *
691 * PARAMETERS:  SourceDesc          - The internal object to be copied
692 *              DestDesc            - New target object
693 *
694 * RETURN:      Status
695 *
696 * DESCRIPTION: Simple copy of one internal object to another.  Reference count
697 *              of the destination object is preserved.
698 *
699 ******************************************************************************/
700
701ACPI_STATUS
702AcpiUtCopySimpleObject (
703    ACPI_OPERAND_OBJECT     *SourceDesc,
704    ACPI_OPERAND_OBJECT     *DestDesc)
705{
706    UINT16                  ReferenceCount;
707    ACPI_OPERAND_OBJECT     *NextObject;
708
709
710    /* Save fields from destination that we don't want to overwrite */
711
712    ReferenceCount = DestDesc->Common.ReferenceCount;
713    NextObject = DestDesc->Common.NextObject;
714
715    /* Copy the entire source object over the destination object*/
716
717    ACPI_MEMCPY ((char *) DestDesc, (char *) SourceDesc, sizeof (ACPI_OPERAND_OBJECT));
718
719    /* Restore the saved fields */
720
721    DestDesc->Common.ReferenceCount = ReferenceCount;
722    DestDesc->Common.NextObject = NextObject;
723
724    /* Handle the objects with extra data */
725
726    switch (ACPI_GET_OBJECT_TYPE (DestDesc))
727    {
728    case ACPI_TYPE_BUFFER:
729
730        DestDesc->Buffer.Node = NULL;
731        DestDesc->Common.Flags = SourceDesc->Common.Flags;
732
733        /* Fall through to common string/buffer case */
734        /*lint -fallthrough */
735
736    case ACPI_TYPE_STRING:
737
738        /*
739         * Allocate and copy the actual string if and only if:
740         * 1) There is a valid string (length > 0)
741         * 2) The string is not static (not in an ACPI table) (in this case,
742         *    the actual pointer was already copied above)
743         */
744        if ((SourceDesc->String.Length) &&
745            (!(SourceDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
746        {
747            DestDesc->String.Pointer = ACPI_MEM_ALLOCATE (SourceDesc->String.Length);
748            if (!DestDesc->String.Pointer)
749            {
750                return (AE_NO_MEMORY);
751            }
752
753            ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer,
754                         SourceDesc->String.Length);
755        }
756        break;
757
758    default:
759        /* Nothing to do for other simple objects */
760        break;
761    }
762
763    return (AE_OK);
764}
765
766
767/*******************************************************************************
768 *
769 * FUNCTION:    AcpiUtCopyIelementToIelement
770 *
771 * PARAMETERS:  ACPI_PKG_CALLBACK
772 *
773 * RETURN:      Status
774 *
775 * DESCRIPTION: Copy one package element to another package element
776 *
777 ******************************************************************************/
778
779ACPI_STATUS
780AcpiUtCopyIelementToIelement (
781    UINT8                   ObjectType,
782    ACPI_OPERAND_OBJECT     *SourceObject,
783    ACPI_GENERIC_STATE      *State,
784    void                    *Context)
785{
786    ACPI_STATUS             Status = AE_OK;
787    UINT32                  ThisIndex;
788    ACPI_OPERAND_OBJECT     **ThisTargetPtr;
789    ACPI_OPERAND_OBJECT     *TargetObject;
790
791
792    ACPI_FUNCTION_ENTRY ();
793
794
795    ThisIndex     = State->Pkg.Index;
796    ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
797                        &State->Pkg.DestObject->Package.Elements[ThisIndex];
798
799    switch (ObjectType)
800    {
801    case 0:
802
803        /*
804         * This is a simple object, just copy it
805         */
806        TargetObject = AcpiUtCreateInternalObject (ACPI_GET_OBJECT_TYPE (SourceObject));
807        if (!TargetObject)
808        {
809            return (AE_NO_MEMORY);
810        }
811
812        Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);
813        if (ACPI_FAILURE (Status))
814        {
815            return (Status);
816        }
817
818        *ThisTargetPtr = TargetObject;
819        break;
820
821
822    case 1:
823
824        /*
825         * This object is a package - go down another nesting level
826         * Create and build the package object
827         */
828        TargetObject = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
829        if (!TargetObject)
830        {
831            return (AE_NO_MEMORY);
832        }
833
834        TargetObject->Package.Count = SourceObject->Package.Count;
835        TargetObject->Common.Flags  = SourceObject->Common.Flags;
836
837        /*
838         * Pass the new package object back to the package walk routine
839         */
840        State->Pkg.ThisTargetObj = TargetObject;
841
842        /*
843         * Store the object pointer in the parent package object
844         */
845        *ThisTargetPtr = TargetObject;
846        break;
847
848
849    default:
850        return (AE_BAD_PARAMETER);
851    }
852
853    return (Status);
854}
855
856
857/*******************************************************************************
858 *
859 * FUNCTION:    AcpiUtCopyIpackageToIpackage
860 *
861 * PARAMETERS:  *SourceObj      - Pointer to the source package object
862 *              *DestObj        - Where the internal object is returned
863 *
864 * RETURN:      Status          - the status of the call
865 *
866 * DESCRIPTION: This function is called to copy an internal package object
867 *              into another internal package object.
868 *
869 ******************************************************************************/
870
871ACPI_STATUS
872AcpiUtCopyIpackageToIpackage (
873    ACPI_OPERAND_OBJECT     *SourceObj,
874    ACPI_OPERAND_OBJECT     *DestObj,
875    ACPI_WALK_STATE         *WalkState)
876{
877    ACPI_STATUS             Status = AE_OK;
878
879
880    ACPI_FUNCTION_TRACE ("UtCopyIpackageToIpackage");
881
882
883    DestObj->Common.Type    = ACPI_GET_OBJECT_TYPE (SourceObj);
884    DestObj->Common.Flags   = SourceObj->Common.Flags;
885    DestObj->Package.Count  = SourceObj->Package.Count;
886
887    /*
888     * Create the object array and walk the source package tree
889     */
890    DestObj->Package.Elements = ACPI_MEM_CALLOCATE (
891                                    ((ACPI_SIZE) SourceObj->Package.Count + 1) *
892                                    sizeof (void *));
893    if (!DestObj->Package.Elements)
894    {
895        ACPI_REPORT_ERROR (
896            ("AmlBuildCopyInternalPackageObject: Package allocation failure\n"));
897        return_ACPI_STATUS (AE_NO_MEMORY);
898    }
899
900    /*
901     * Copy the package element-by-element by walking the package "tree".
902     * This handles nested packages of arbitrary depth.
903     */
904    Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
905                            AcpiUtCopyIelementToIelement, WalkState);
906    if (ACPI_FAILURE (Status))
907    {
908        /* On failure, delete the destination package object */
909
910        AcpiUtRemoveReference (DestObj);
911    }
912
913    return_ACPI_STATUS (Status);
914}
915
916
917/*******************************************************************************
918 *
919 * FUNCTION:    AcpiUtCopyIobjectToIobject
920 *
921 * PARAMETERS:  WalkState           - Current walk state
922 *              SourceDesc          - The internal object to be copied
923 *              DestDesc            - Where the copied object is returned
924 *
925 * RETURN:      Status
926 *
927 * DESCRIPTION: Copy an internal object to a new internal object
928 *
929 ******************************************************************************/
930
931ACPI_STATUS
932AcpiUtCopyIobjectToIobject (
933    ACPI_OPERAND_OBJECT     *SourceDesc,
934    ACPI_OPERAND_OBJECT     **DestDesc,
935    ACPI_WALK_STATE         *WalkState)
936{
937    ACPI_STATUS             Status = AE_OK;
938
939
940    ACPI_FUNCTION_TRACE ("UtCopyIobjectToIobject");
941
942
943    /* Create the top level object */
944
945    *DestDesc = AcpiUtCreateInternalObject (ACPI_GET_OBJECT_TYPE (SourceDesc));
946    if (!*DestDesc)
947    {
948        return_ACPI_STATUS (AE_NO_MEMORY);
949    }
950
951    /* Copy the object and possible subobjects */
952
953    if (ACPI_GET_OBJECT_TYPE (SourceDesc) == ACPI_TYPE_PACKAGE)
954    {
955        Status = AcpiUtCopyIpackageToIpackage (SourceDesc, *DestDesc,
956                        WalkState);
957    }
958    else
959    {
960        Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);
961    }
962
963    return_ACPI_STATUS (Status);
964}
965
966
967