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