1 /******************************************************************************
3 * Module Name: utcopy - Internal to external object translation utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
51 #define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utcopy")
54 /* Local prototypes */
57 AcpiUtCopyIsimpleToEsimple (
58 ACPI_OPERAND_OBJECT *InternalObject,
59 ACPI_OBJECT *ExternalObject,
61 ACPI_SIZE *BufferSpaceUsed);
64 AcpiUtCopyIelementToIelement (
66 ACPI_OPERAND_OBJECT *SourceObject,
67 ACPI_GENERIC_STATE *State,
71 AcpiUtCopyIpackageToEpackage (
72 ACPI_OPERAND_OBJECT *InternalObject,
74 ACPI_SIZE *SpaceUsed);
77 AcpiUtCopyEsimpleToIsimple(
79 ACPI_OPERAND_OBJECT **ReturnObj);
82 AcpiUtCopyEpackageToIpackage (
83 ACPI_OBJECT *ExternalObject,
84 ACPI_OPERAND_OBJECT **InternalObject);
87 AcpiUtCopySimpleObject (
88 ACPI_OPERAND_OBJECT *SourceDesc,
89 ACPI_OPERAND_OBJECT *DestDesc);
92 AcpiUtCopyIelementToEelement (
94 ACPI_OPERAND_OBJECT *SourceObject,
95 ACPI_GENERIC_STATE *State,
99 AcpiUtCopyIpackageToIpackage (
100 ACPI_OPERAND_OBJECT *SourceObj,
101 ACPI_OPERAND_OBJECT *DestObj,
102 ACPI_WALK_STATE *WalkState);
105 /*******************************************************************************
107 * FUNCTION: AcpiUtCopyIsimpleToEsimple
109 * PARAMETERS: InternalObject - Source object to be copied
110 * ExternalObject - Where to return the copied object
111 * DataSpace - Where object data is returned (such as
112 * buffer and string data)
113 * BufferSpaceUsed - Length of DataSpace that was used
117 * DESCRIPTION: This function is called to copy a simple internal object to
118 * an external object.
120 * The DataSpace buffer is assumed to have sufficient space for
123 ******************************************************************************/
126 AcpiUtCopyIsimpleToEsimple (
127 ACPI_OPERAND_OBJECT *InternalObject,
128 ACPI_OBJECT *ExternalObject,
130 ACPI_SIZE *BufferSpaceUsed)
132 ACPI_STATUS Status = AE_OK;
135 ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple);
138 *BufferSpaceUsed = 0;
141 * Check for NULL object case (could be an uninitialized
146 return_ACPI_STATUS (AE_OK);
149 /* Always clear the external object */
151 ACPI_MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
154 * In general, the external object will be the same type as
155 * the internal object
157 ExternalObject->Type = InternalObject->Common.Type;
159 /* However, only a limited number of external types are supported */
161 switch (InternalObject->Common.Type)
163 case ACPI_TYPE_STRING:
165 ExternalObject->String.Pointer = (char *) DataSpace;
166 ExternalObject->String.Length = InternalObject->String.Length;
167 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
168 (ACPI_SIZE) InternalObject->String.Length + 1);
170 ACPI_MEMCPY ((void *) DataSpace,
171 (void *) InternalObject->String.Pointer,
172 (ACPI_SIZE) InternalObject->String.Length + 1);
175 case ACPI_TYPE_BUFFER:
177 ExternalObject->Buffer.Pointer = DataSpace;
178 ExternalObject->Buffer.Length = InternalObject->Buffer.Length;
179 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
180 InternalObject->String.Length);
182 ACPI_MEMCPY ((void *) DataSpace,
183 (void *) InternalObject->Buffer.Pointer,
184 InternalObject->Buffer.Length);
187 case ACPI_TYPE_INTEGER:
189 ExternalObject->Integer.Value = InternalObject->Integer.Value;
192 case ACPI_TYPE_LOCAL_REFERENCE:
194 /* This is an object reference. */
196 switch (InternalObject->Reference.Class)
198 case ACPI_REFCLASS_NAME:
200 * For namepath, return the object handle ("reference")
201 * We are referring to the namespace node
203 ExternalObject->Reference.Handle =
204 InternalObject->Reference.Node;
205 ExternalObject->Reference.ActualType =
206 AcpiNsGetType (InternalObject->Reference.Node);
211 /* All other reference types are unsupported */
213 return_ACPI_STATUS (AE_TYPE);
217 case ACPI_TYPE_PROCESSOR:
219 ExternalObject->Processor.ProcId =
220 InternalObject->Processor.ProcId;
221 ExternalObject->Processor.PblkAddress =
222 InternalObject->Processor.Address;
223 ExternalObject->Processor.PblkLength =
224 InternalObject->Processor.Length;
227 case ACPI_TYPE_POWER:
229 ExternalObject->PowerResource.SystemLevel =
230 InternalObject->PowerResource.SystemLevel;
232 ExternalObject->PowerResource.ResourceOrder =
233 InternalObject->PowerResource.ResourceOrder;
238 * There is no corresponding external object type
240 ACPI_ERROR ((AE_INFO,
241 "Unsupported object type, cannot convert to external object: %s",
242 AcpiUtGetTypeName (InternalObject->Common.Type)));
244 return_ACPI_STATUS (AE_SUPPORT);
247 return_ACPI_STATUS (Status);
251 /*******************************************************************************
253 * FUNCTION: AcpiUtCopyIelementToEelement
255 * PARAMETERS: ACPI_PKG_CALLBACK
259 * DESCRIPTION: Copy one package element to another package element
261 ******************************************************************************/
264 AcpiUtCopyIelementToEelement (
266 ACPI_OPERAND_OBJECT *SourceObject,
267 ACPI_GENERIC_STATE *State,
270 ACPI_STATUS Status = AE_OK;
271 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
272 ACPI_SIZE ObjectSpace;
274 ACPI_OBJECT *TargetObject;
277 ACPI_FUNCTION_ENTRY ();
280 ThisIndex = State->Pkg.Index;
281 TargetObject = (ACPI_OBJECT *)
282 &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
286 case ACPI_COPY_TYPE_SIMPLE:
288 * This is a simple or null object
290 Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
291 TargetObject, Info->FreeSpace, &ObjectSpace);
292 if (ACPI_FAILURE (Status))
298 case ACPI_COPY_TYPE_PACKAGE:
300 * Build the package object
302 TargetObject->Type = ACPI_TYPE_PACKAGE;
303 TargetObject->Package.Count = SourceObject->Package.Count;
304 TargetObject->Package.Elements =
305 ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);
308 * Pass the new package object back to the package walk routine
310 State->Pkg.ThisTargetObj = TargetObject;
313 * Save space for the array of objects (Package elements)
314 * update the buffer length counter
316 ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (
317 (ACPI_SIZE) TargetObject->Package.Count *
318 sizeof (ACPI_OBJECT));
323 return (AE_BAD_PARAMETER);
326 Info->FreeSpace += ObjectSpace;
327 Info->Length += ObjectSpace;
332 /*******************************************************************************
334 * FUNCTION: AcpiUtCopyIpackageToEpackage
336 * PARAMETERS: InternalObject - Pointer to the object we are returning
337 * Buffer - Where the object is returned
338 * SpaceUsed - Where the object length is returned
342 * DESCRIPTION: This function is called to place a package object in a user
343 * buffer. A package object by definition contains other objects.
345 * The buffer is assumed to have sufficient space for the object.
346 * The caller must have verified the buffer length needed using
347 * the AcpiUtGetObjectSize function before calling this function.
349 ******************************************************************************/
352 AcpiUtCopyIpackageToEpackage (
353 ACPI_OPERAND_OBJECT *InternalObject,
355 ACPI_SIZE *SpaceUsed)
357 ACPI_OBJECT *ExternalObject;
362 ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage);
366 * First package at head of the buffer
368 ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);
371 * Free space begins right after the first package
373 Info.Length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
374 Info.FreeSpace = Buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
375 sizeof (ACPI_OBJECT));
376 Info.ObjectSpace = 0;
377 Info.NumPackages = 1;
379 ExternalObject->Type = InternalObject->Common.Type;
380 ExternalObject->Package.Count = InternalObject->Package.Count;
381 ExternalObject->Package.Elements = ACPI_CAST_PTR (ACPI_OBJECT,
385 * Leave room for an array of ACPI_OBJECTS in the buffer
386 * and move the free space past it
388 Info.Length += (ACPI_SIZE) ExternalObject->Package.Count *
389 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
390 Info.FreeSpace += ExternalObject->Package.Count *
391 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
393 Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
394 AcpiUtCopyIelementToEelement, &Info);
396 *SpaceUsed = Info.Length;
397 return_ACPI_STATUS (Status);
401 /*******************************************************************************
403 * FUNCTION: AcpiUtCopyIobjectToEobject
405 * PARAMETERS: InternalObject - The internal object to be converted
406 * RetBuffer - Where the object is returned
410 * DESCRIPTION: This function is called to build an API object to be returned
413 ******************************************************************************/
416 AcpiUtCopyIobjectToEobject (
417 ACPI_OPERAND_OBJECT *InternalObject,
418 ACPI_BUFFER *RetBuffer)
423 ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject);
426 if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)
429 * Package object: Copy all subobjects (including
432 Status = AcpiUtCopyIpackageToEpackage (InternalObject,
433 RetBuffer->Pointer, &RetBuffer->Length);
438 * Build a simple object (no nested objects)
440 Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
441 ACPI_CAST_PTR (ACPI_OBJECT, RetBuffer->Pointer),
442 ACPI_ADD_PTR (UINT8, RetBuffer->Pointer,
443 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
446 * build simple does not include the object size in the length
447 * so we add it in here
449 RetBuffer->Length += sizeof (ACPI_OBJECT);
452 return_ACPI_STATUS (Status);
456 /*******************************************************************************
458 * FUNCTION: AcpiUtCopyEsimpleToIsimple
460 * PARAMETERS: ExternalObject - The external object to be converted
461 * RetInternalObject - Where the internal object is returned
465 * DESCRIPTION: This function copies an external object to an internal one.
466 * NOTE: Pointers can be copied, we don't need to copy data.
467 * (The pointers have to be valid in our address space no matter
468 * what we do with them!)
470 ******************************************************************************/
473 AcpiUtCopyEsimpleToIsimple (
474 ACPI_OBJECT *ExternalObject,
475 ACPI_OPERAND_OBJECT **RetInternalObject)
477 ACPI_OPERAND_OBJECT *InternalObject;
480 ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple);
484 * Simple types supported are: String, Buffer, Integer
486 switch (ExternalObject->Type)
488 case ACPI_TYPE_STRING:
489 case ACPI_TYPE_BUFFER:
490 case ACPI_TYPE_INTEGER:
491 case ACPI_TYPE_LOCAL_REFERENCE:
493 InternalObject = AcpiUtCreateInternalObject (
494 (UINT8) ExternalObject->Type);
497 return_ACPI_STATUS (AE_NO_MEMORY);
501 case ACPI_TYPE_ANY: /* This is the case for a NULL object */
503 *RetInternalObject = NULL;
504 return_ACPI_STATUS (AE_OK);
508 /* All other types are not supported */
510 ACPI_ERROR ((AE_INFO,
511 "Unsupported object type, cannot convert to internal object: %s",
512 AcpiUtGetTypeName (ExternalObject->Type)));
514 return_ACPI_STATUS (AE_SUPPORT);
518 /* Must COPY string and buffer contents */
520 switch (ExternalObject->Type)
522 case ACPI_TYPE_STRING:
524 InternalObject->String.Pointer =
525 ACPI_ALLOCATE_ZEROED ((ACPI_SIZE)
526 ExternalObject->String.Length + 1);
528 if (!InternalObject->String.Pointer)
533 ACPI_MEMCPY (InternalObject->String.Pointer,
534 ExternalObject->String.Pointer,
535 ExternalObject->String.Length);
537 InternalObject->String.Length = ExternalObject->String.Length;
540 case ACPI_TYPE_BUFFER:
542 InternalObject->Buffer.Pointer =
543 ACPI_ALLOCATE_ZEROED (ExternalObject->Buffer.Length);
544 if (!InternalObject->Buffer.Pointer)
549 ACPI_MEMCPY (InternalObject->Buffer.Pointer,
550 ExternalObject->Buffer.Pointer,
551 ExternalObject->Buffer.Length);
553 InternalObject->Buffer.Length = ExternalObject->Buffer.Length;
555 /* Mark buffer data valid */
557 InternalObject->Buffer.Flags |= AOPOBJ_DATA_VALID;
560 case ACPI_TYPE_INTEGER:
562 InternalObject->Integer.Value = ExternalObject->Integer.Value;
565 case ACPI_TYPE_LOCAL_REFERENCE:
567 /* An incoming reference is defined to be a namespace node */
569 InternalObject->Reference.Class = ACPI_REFCLASS_REFOF;
570 InternalObject->Reference.Object = ExternalObject->Reference.Handle;
575 /* Other types can't get here */
580 *RetInternalObject = InternalObject;
581 return_ACPI_STATUS (AE_OK);
585 AcpiUtRemoveReference (InternalObject);
586 return_ACPI_STATUS (AE_NO_MEMORY);
590 /*******************************************************************************
592 * FUNCTION: AcpiUtCopyEpackageToIpackage
594 * PARAMETERS: ExternalObject - The external object to be converted
595 * InternalObject - Where the internal object is returned
599 * DESCRIPTION: Copy an external package object to an internal package.
600 * Handles nested packages.
602 ******************************************************************************/
605 AcpiUtCopyEpackageToIpackage (
606 ACPI_OBJECT *ExternalObject,
607 ACPI_OPERAND_OBJECT **InternalObject)
609 ACPI_STATUS Status = AE_OK;
610 ACPI_OPERAND_OBJECT *PackageObject;
611 ACPI_OPERAND_OBJECT **PackageElements;
615 ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage);
618 /* Create the package object */
620 PackageObject = AcpiUtCreatePackageObject (ExternalObject->Package.Count);
623 return_ACPI_STATUS (AE_NO_MEMORY);
626 PackageElements = PackageObject->Package.Elements;
629 * Recursive implementation. Probably ok, since nested external packages
630 * as parameters should be very rare.
632 for (i = 0; i < ExternalObject->Package.Count; i++)
634 Status = AcpiUtCopyEobjectToIobject (
635 &ExternalObject->Package.Elements[i],
636 &PackageElements[i]);
637 if (ACPI_FAILURE (Status))
639 /* Truncate package and delete it */
641 PackageObject->Package.Count = i;
642 PackageElements[i] = NULL;
643 AcpiUtRemoveReference (PackageObject);
644 return_ACPI_STATUS (Status);
648 /* Mark package data valid */
650 PackageObject->Package.Flags |= AOPOBJ_DATA_VALID;
652 *InternalObject = PackageObject;
653 return_ACPI_STATUS (Status);
657 /*******************************************************************************
659 * FUNCTION: AcpiUtCopyEobjectToIobject
661 * PARAMETERS: ExternalObject - The external object to be converted
662 * InternalObject - Where the internal object is returned
666 * DESCRIPTION: Converts an external object to an internal object.
668 ******************************************************************************/
671 AcpiUtCopyEobjectToIobject (
672 ACPI_OBJECT *ExternalObject,
673 ACPI_OPERAND_OBJECT **InternalObject)
678 ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject);
681 if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
683 Status = AcpiUtCopyEpackageToIpackage (ExternalObject, InternalObject);
688 * Build a simple object (no nested objects)
690 Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject);
693 return_ACPI_STATUS (Status);
697 /*******************************************************************************
699 * FUNCTION: AcpiUtCopySimpleObject
701 * PARAMETERS: SourceDesc - The internal object to be copied
702 * DestDesc - New target object
706 * DESCRIPTION: Simple copy of one internal object to another. Reference count
707 * of the destination object is preserved.
709 ******************************************************************************/
712 AcpiUtCopySimpleObject (
713 ACPI_OPERAND_OBJECT *SourceDesc,
714 ACPI_OPERAND_OBJECT *DestDesc)
716 UINT16 ReferenceCount;
717 ACPI_OPERAND_OBJECT *NextObject;
722 /* Save fields from destination that we don't want to overwrite */
724 ReferenceCount = DestDesc->Common.ReferenceCount;
725 NextObject = DestDesc->Common.NextObject;
728 * Copy the entire source object over the destination object.
729 * Note: Source can be either an operand object or namespace node.
731 CopySize = sizeof (ACPI_OPERAND_OBJECT);
732 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
734 CopySize = sizeof (ACPI_NAMESPACE_NODE);
737 ACPI_MEMCPY (ACPI_CAST_PTR (char, DestDesc),
738 ACPI_CAST_PTR (char, SourceDesc), CopySize);
740 /* Restore the saved fields */
742 DestDesc->Common.ReferenceCount = ReferenceCount;
743 DestDesc->Common.NextObject = NextObject;
745 /* New object is not static, regardless of source */
747 DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
749 /* Handle the objects with extra data */
751 switch (DestDesc->Common.Type)
753 case ACPI_TYPE_BUFFER:
755 * Allocate and copy the actual buffer if and only if:
756 * 1) There is a valid buffer pointer
757 * 2) The buffer has a length > 0
759 if ((SourceDesc->Buffer.Pointer) &&
760 (SourceDesc->Buffer.Length))
762 DestDesc->Buffer.Pointer =
763 ACPI_ALLOCATE (SourceDesc->Buffer.Length);
764 if (!DestDesc->Buffer.Pointer)
766 return (AE_NO_MEMORY);
769 /* Copy the actual buffer data */
771 ACPI_MEMCPY (DestDesc->Buffer.Pointer,
772 SourceDesc->Buffer.Pointer, SourceDesc->Buffer.Length);
776 case ACPI_TYPE_STRING:
778 * Allocate and copy the actual string if and only if:
779 * 1) There is a valid string pointer
780 * (Pointer to a NULL string is allowed)
782 if (SourceDesc->String.Pointer)
784 DestDesc->String.Pointer =
785 ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1);
786 if (!DestDesc->String.Pointer)
788 return (AE_NO_MEMORY);
791 /* Copy the actual string data */
793 ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer,
794 (ACPI_SIZE) SourceDesc->String.Length + 1);
798 case ACPI_TYPE_LOCAL_REFERENCE:
800 * We copied the reference object, so we now must add a reference
801 * to the object pointed to by the reference
803 * DDBHandle reference (from Load/LoadTable) is a special reference,
804 * it does not have a Reference.Object, so does not need to
805 * increase the reference count
807 if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
812 AcpiUtAddReference (SourceDesc->Reference.Object);
815 case ACPI_TYPE_REGION:
817 * We copied the Region Handler, so we now must add a reference
819 if (DestDesc->Region.Handler)
821 AcpiUtAddReference (DestDesc->Region.Handler);
826 * For Mutex and Event objects, we cannot simply copy the underlying
827 * OS object. We must create a new one.
829 case ACPI_TYPE_MUTEX:
831 Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex);
832 if (ACPI_FAILURE (Status))
838 case ACPI_TYPE_EVENT:
840 Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
841 &DestDesc->Event.OsSemaphore);
842 if (ACPI_FAILURE (Status))
850 /* Nothing to do for other simple objects */
859 /*******************************************************************************
861 * FUNCTION: AcpiUtCopyIelementToIelement
863 * PARAMETERS: ACPI_PKG_CALLBACK
867 * DESCRIPTION: Copy one package element to another package element
869 ******************************************************************************/
872 AcpiUtCopyIelementToIelement (
874 ACPI_OPERAND_OBJECT *SourceObject,
875 ACPI_GENERIC_STATE *State,
878 ACPI_STATUS Status = AE_OK;
880 ACPI_OPERAND_OBJECT **ThisTargetPtr;
881 ACPI_OPERAND_OBJECT *TargetObject;
884 ACPI_FUNCTION_ENTRY ();
887 ThisIndex = State->Pkg.Index;
888 ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
889 &State->Pkg.DestObject->Package.Elements[ThisIndex];
893 case ACPI_COPY_TYPE_SIMPLE:
895 /* A null source object indicates a (legal) null package element */
900 * This is a simple object, just copy it
902 TargetObject = AcpiUtCreateInternalObject (
903 SourceObject->Common.Type);
906 return (AE_NO_MEMORY);
909 Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);
910 if (ACPI_FAILURE (Status))
915 *ThisTargetPtr = TargetObject;
919 /* Pass through a null element */
921 *ThisTargetPtr = NULL;
925 case ACPI_COPY_TYPE_PACKAGE:
927 * This object is a package - go down another nesting level
928 * Create and build the package object
930 TargetObject = AcpiUtCreatePackageObject (SourceObject->Package.Count);
933 return (AE_NO_MEMORY);
936 TargetObject->Common.Flags = SourceObject->Common.Flags;
938 /* Pass the new package object back to the package walk routine */
940 State->Pkg.ThisTargetObj = TargetObject;
942 /* Store the object pointer in the parent package object */
944 *ThisTargetPtr = TargetObject;
949 return (AE_BAD_PARAMETER);
955 AcpiUtRemoveReference (TargetObject);
960 /*******************************************************************************
962 * FUNCTION: AcpiUtCopyIpackageToIpackage
964 * PARAMETERS: SourceObj - Pointer to the source package object
965 * DestObj - Where the internal object is returned
966 * WalkState - Current Walk state descriptor
970 * DESCRIPTION: This function is called to copy an internal package object
971 * into another internal package object.
973 ******************************************************************************/
976 AcpiUtCopyIpackageToIpackage (
977 ACPI_OPERAND_OBJECT *SourceObj,
978 ACPI_OPERAND_OBJECT *DestObj,
979 ACPI_WALK_STATE *WalkState)
981 ACPI_STATUS Status = AE_OK;
984 ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage);
987 DestObj->Common.Type = SourceObj->Common.Type;
988 DestObj->Common.Flags = SourceObj->Common.Flags;
989 DestObj->Package.Count = SourceObj->Package.Count;
992 * Create the object array and walk the source package tree
994 DestObj->Package.Elements = ACPI_ALLOCATE_ZEROED (
995 ((ACPI_SIZE) SourceObj->Package.Count + 1) *
997 if (!DestObj->Package.Elements)
999 ACPI_ERROR ((AE_INFO, "Package allocation failure"));
1000 return_ACPI_STATUS (AE_NO_MEMORY);
1004 * Copy the package element-by-element by walking the package "tree".
1005 * This handles nested packages of arbitrary depth.
1007 Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
1008 AcpiUtCopyIelementToIelement, WalkState);
1009 if (ACPI_FAILURE (Status))
1011 /* On failure, delete the destination package object */
1013 AcpiUtRemoveReference (DestObj);
1016 return_ACPI_STATUS (Status);
1020 /*******************************************************************************
1022 * FUNCTION: AcpiUtCopyIobjectToIobject
1024 * PARAMETERS: SourceDesc - The internal object to be copied
1025 * DestDesc - Where the copied object is returned
1026 * WalkState - Current walk state
1030 * DESCRIPTION: Copy an internal object to a new internal object
1032 ******************************************************************************/
1035 AcpiUtCopyIobjectToIobject (
1036 ACPI_OPERAND_OBJECT *SourceDesc,
1037 ACPI_OPERAND_OBJECT **DestDesc,
1038 ACPI_WALK_STATE *WalkState)
1040 ACPI_STATUS Status = AE_OK;
1043 ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject);
1046 /* Create the top level object */
1048 *DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type);
1051 return_ACPI_STATUS (AE_NO_MEMORY);
1054 /* Copy the object and possible subobjects */
1056 if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE)
1058 Status = AcpiUtCopyIpackageToIpackage (SourceDesc, *DestDesc,
1063 Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);
1066 /* Delete the allocated object if copy failed */
1068 if (ACPI_FAILURE (Status))
1070 AcpiUtRemoveReference(*DestDesc);
1073 return_ACPI_STATUS (Status);