VM: munmap used by VM for itself is no longer used
[minix.git] / drivers / acpi / utilities / utcopy.c
blobc1fccaefe1ba3894296c01435e71d2de3895a276
1 /******************************************************************************
3 * Module Name: utcopy - Internal to external object translation utilities
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define __UTCOPY_C__
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acnamesp.h"
123 #define _COMPONENT ACPI_UTILITIES
124 ACPI_MODULE_NAME ("utcopy")
126 /* Local prototypes */
128 static ACPI_STATUS
129 AcpiUtCopyIsimpleToEsimple (
130 ACPI_OPERAND_OBJECT *InternalObject,
131 ACPI_OBJECT *ExternalObject,
132 UINT8 *DataSpace,
133 ACPI_SIZE *BufferSpaceUsed);
135 static ACPI_STATUS
136 AcpiUtCopyIelementToIelement (
137 UINT8 ObjectType,
138 ACPI_OPERAND_OBJECT *SourceObject,
139 ACPI_GENERIC_STATE *State,
140 void *Context);
142 static ACPI_STATUS
143 AcpiUtCopyIpackageToEpackage (
144 ACPI_OPERAND_OBJECT *InternalObject,
145 UINT8 *Buffer,
146 ACPI_SIZE *SpaceUsed);
148 static ACPI_STATUS
149 AcpiUtCopyEsimpleToIsimple(
150 ACPI_OBJECT *UserObj,
151 ACPI_OPERAND_OBJECT **ReturnObj);
153 static ACPI_STATUS
154 AcpiUtCopyEpackageToIpackage (
155 ACPI_OBJECT *ExternalObject,
156 ACPI_OPERAND_OBJECT **InternalObject);
158 static ACPI_STATUS
159 AcpiUtCopySimpleObject (
160 ACPI_OPERAND_OBJECT *SourceDesc,
161 ACPI_OPERAND_OBJECT *DestDesc);
163 static ACPI_STATUS
164 AcpiUtCopyIelementToEelement (
165 UINT8 ObjectType,
166 ACPI_OPERAND_OBJECT *SourceObject,
167 ACPI_GENERIC_STATE *State,
168 void *Context);
170 static ACPI_STATUS
171 AcpiUtCopyIpackageToIpackage (
172 ACPI_OPERAND_OBJECT *SourceObj,
173 ACPI_OPERAND_OBJECT *DestObj,
174 ACPI_WALK_STATE *WalkState);
177 /*******************************************************************************
179 * FUNCTION: AcpiUtCopyIsimpleToEsimple
181 * PARAMETERS: InternalObject - Source object to be copied
182 * ExternalObject - Where to return the copied object
183 * DataSpace - Where object data is returned (such as
184 * buffer and string data)
185 * BufferSpaceUsed - Length of DataSpace that was used
187 * RETURN: Status
189 * DESCRIPTION: This function is called to copy a simple internal object to
190 * an external object.
192 * The DataSpace buffer is assumed to have sufficient space for
193 * the object.
195 ******************************************************************************/
197 static ACPI_STATUS
198 AcpiUtCopyIsimpleToEsimple (
199 ACPI_OPERAND_OBJECT *InternalObject,
200 ACPI_OBJECT *ExternalObject,
201 UINT8 *DataSpace,
202 ACPI_SIZE *BufferSpaceUsed)
204 ACPI_STATUS Status = AE_OK;
207 ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple);
210 *BufferSpaceUsed = 0;
213 * Check for NULL object case (could be an uninitialized
214 * package element)
216 if (!InternalObject)
218 return_ACPI_STATUS (AE_OK);
221 /* Always clear the external object */
223 ACPI_MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
226 * In general, the external object will be the same type as
227 * the internal object
229 ExternalObject->Type = InternalObject->Common.Type;
231 /* However, only a limited number of external types are supported */
233 switch (InternalObject->Common.Type)
235 case ACPI_TYPE_STRING:
237 ExternalObject->String.Pointer = (char *) DataSpace;
238 ExternalObject->String.Length = InternalObject->String.Length;
239 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
240 (ACPI_SIZE) InternalObject->String.Length + 1);
242 ACPI_MEMCPY ((void *) DataSpace,
243 (void *) InternalObject->String.Pointer,
244 (ACPI_SIZE) InternalObject->String.Length + 1);
245 break;
248 case ACPI_TYPE_BUFFER:
250 ExternalObject->Buffer.Pointer = DataSpace;
251 ExternalObject->Buffer.Length = InternalObject->Buffer.Length;
252 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
253 InternalObject->String.Length);
255 ACPI_MEMCPY ((void *) DataSpace,
256 (void *) InternalObject->Buffer.Pointer,
257 InternalObject->Buffer.Length);
258 break;
261 case ACPI_TYPE_INTEGER:
263 ExternalObject->Integer.Value = InternalObject->Integer.Value;
264 break;
267 case ACPI_TYPE_LOCAL_REFERENCE:
269 /* This is an object reference. */
271 switch (InternalObject->Reference.Class)
273 case ACPI_REFCLASS_NAME:
276 * For namepath, return the object handle ("reference")
277 * We are referring to the namespace node
279 ExternalObject->Reference.Handle =
280 InternalObject->Reference.Node;
281 ExternalObject->Reference.ActualType =
282 AcpiNsGetType (InternalObject->Reference.Node);
283 break;
285 default:
287 /* All other reference types are unsupported */
289 return_ACPI_STATUS (AE_TYPE);
291 break;
294 case ACPI_TYPE_PROCESSOR:
296 ExternalObject->Processor.ProcId =
297 InternalObject->Processor.ProcId;
298 ExternalObject->Processor.PblkAddress =
299 InternalObject->Processor.Address;
300 ExternalObject->Processor.PblkLength =
301 InternalObject->Processor.Length;
302 break;
305 case ACPI_TYPE_POWER:
307 ExternalObject->PowerResource.SystemLevel =
308 InternalObject->PowerResource.SystemLevel;
310 ExternalObject->PowerResource.ResourceOrder =
311 InternalObject->PowerResource.ResourceOrder;
312 break;
315 default:
317 * There is no corresponding external object type
319 ACPI_ERROR ((AE_INFO,
320 "Unsupported object type, cannot convert to external object: %s",
321 AcpiUtGetTypeName (InternalObject->Common.Type)));
323 return_ACPI_STATUS (AE_SUPPORT);
326 return_ACPI_STATUS (Status);
330 /*******************************************************************************
332 * FUNCTION: AcpiUtCopyIelementToEelement
334 * PARAMETERS: ACPI_PKG_CALLBACK
336 * RETURN: Status
338 * DESCRIPTION: Copy one package element to another package element
340 ******************************************************************************/
342 static ACPI_STATUS
343 AcpiUtCopyIelementToEelement (
344 UINT8 ObjectType,
345 ACPI_OPERAND_OBJECT *SourceObject,
346 ACPI_GENERIC_STATE *State,
347 void *Context)
349 ACPI_STATUS Status = AE_OK;
350 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
351 ACPI_SIZE ObjectSpace;
352 UINT32 ThisIndex;
353 ACPI_OBJECT *TargetObject;
356 ACPI_FUNCTION_ENTRY ();
359 ThisIndex = State->Pkg.Index;
360 TargetObject = (ACPI_OBJECT *)
361 &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
363 switch (ObjectType)
365 case ACPI_COPY_TYPE_SIMPLE:
368 * This is a simple or null object
370 Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
371 TargetObject, Info->FreeSpace, &ObjectSpace);
372 if (ACPI_FAILURE (Status))
374 return (Status);
376 break;
379 case ACPI_COPY_TYPE_PACKAGE:
382 * Build the package object
384 TargetObject->Type = ACPI_TYPE_PACKAGE;
385 TargetObject->Package.Count = SourceObject->Package.Count;
386 TargetObject->Package.Elements =
387 ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);
390 * Pass the new package object back to the package walk routine
392 State->Pkg.ThisTargetObj = TargetObject;
395 * Save space for the array of objects (Package elements)
396 * update the buffer length counter
398 ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (
399 (ACPI_SIZE) TargetObject->Package.Count *
400 sizeof (ACPI_OBJECT));
401 break;
404 default:
405 return (AE_BAD_PARAMETER);
408 Info->FreeSpace += ObjectSpace;
409 Info->Length += ObjectSpace;
410 return (Status);
414 /*******************************************************************************
416 * FUNCTION: AcpiUtCopyIpackageToEpackage
418 * PARAMETERS: InternalObject - Pointer to the object we are returning
419 * Buffer - Where the object is returned
420 * SpaceUsed - Where the object length is returned
422 * RETURN: Status
424 * DESCRIPTION: This function is called to place a package object in a user
425 * buffer. A package object by definition contains other objects.
427 * The buffer is assumed to have sufficient space for the object.
428 * The caller must have verified the buffer length needed using
429 * the AcpiUtGetObjectSize function before calling this function.
431 ******************************************************************************/
433 static ACPI_STATUS
434 AcpiUtCopyIpackageToEpackage (
435 ACPI_OPERAND_OBJECT *InternalObject,
436 UINT8 *Buffer,
437 ACPI_SIZE *SpaceUsed)
439 ACPI_OBJECT *ExternalObject;
440 ACPI_STATUS Status;
441 ACPI_PKG_INFO Info;
444 ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage);
448 * First package at head of the buffer
450 ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);
453 * Free space begins right after the first package
455 Info.Length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
456 Info.FreeSpace = Buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
457 sizeof (ACPI_OBJECT));
458 Info.ObjectSpace = 0;
459 Info.NumPackages = 1;
461 ExternalObject->Type = InternalObject->Common.Type;
462 ExternalObject->Package.Count = InternalObject->Package.Count;
463 ExternalObject->Package.Elements = ACPI_CAST_PTR (ACPI_OBJECT,
464 Info.FreeSpace);
467 * Leave room for an array of ACPI_OBJECTS in the buffer
468 * and move the free space past it
470 Info.Length += (ACPI_SIZE) ExternalObject->Package.Count *
471 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
472 Info.FreeSpace += ExternalObject->Package.Count *
473 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
475 Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
476 AcpiUtCopyIelementToEelement, &Info);
478 *SpaceUsed = Info.Length;
479 return_ACPI_STATUS (Status);
483 /*******************************************************************************
485 * FUNCTION: AcpiUtCopyIobjectToEobject
487 * PARAMETERS: InternalObject - The internal object to be converted
488 * RetBuffer - Where the object is returned
490 * RETURN: Status
492 * DESCRIPTION: This function is called to build an API object to be returned
493 * to the caller.
495 ******************************************************************************/
497 ACPI_STATUS
498 AcpiUtCopyIobjectToEobject (
499 ACPI_OPERAND_OBJECT *InternalObject,
500 ACPI_BUFFER *RetBuffer)
502 ACPI_STATUS Status;
505 ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject);
508 if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)
511 * Package object: Copy all subobjects (including
512 * nested packages)
514 Status = AcpiUtCopyIpackageToEpackage (InternalObject,
515 RetBuffer->Pointer, &RetBuffer->Length);
517 else
520 * Build a simple object (no nested objects)
522 Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
523 ACPI_CAST_PTR (ACPI_OBJECT, RetBuffer->Pointer),
524 ACPI_ADD_PTR (UINT8, RetBuffer->Pointer,
525 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
526 &RetBuffer->Length);
528 * build simple does not include the object size in the length
529 * so we add it in here
531 RetBuffer->Length += sizeof (ACPI_OBJECT);
534 return_ACPI_STATUS (Status);
538 /*******************************************************************************
540 * FUNCTION: AcpiUtCopyEsimpleToIsimple
542 * PARAMETERS: ExternalObject - The external object to be converted
543 * RetInternalObject - Where the internal object is returned
545 * RETURN: Status
547 * DESCRIPTION: This function copies an external object to an internal one.
548 * NOTE: Pointers can be copied, we don't need to copy data.
549 * (The pointers have to be valid in our address space no matter
550 * what we do with them!)
552 ******************************************************************************/
554 static ACPI_STATUS
555 AcpiUtCopyEsimpleToIsimple (
556 ACPI_OBJECT *ExternalObject,
557 ACPI_OPERAND_OBJECT **RetInternalObject)
559 ACPI_OPERAND_OBJECT *InternalObject;
562 ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple);
566 * Simple types supported are: String, Buffer, Integer
568 switch (ExternalObject->Type)
570 case ACPI_TYPE_STRING:
571 case ACPI_TYPE_BUFFER:
572 case ACPI_TYPE_INTEGER:
573 case ACPI_TYPE_LOCAL_REFERENCE:
575 InternalObject = AcpiUtCreateInternalObject (
576 (UINT8) ExternalObject->Type);
577 if (!InternalObject)
579 return_ACPI_STATUS (AE_NO_MEMORY);
581 break;
583 case ACPI_TYPE_ANY: /* This is the case for a NULL object */
585 *RetInternalObject = NULL;
586 return_ACPI_STATUS (AE_OK);
588 default:
589 /* All other types are not supported */
591 ACPI_ERROR ((AE_INFO,
592 "Unsupported object type, cannot convert to internal object: %s",
593 AcpiUtGetTypeName (ExternalObject->Type)));
595 return_ACPI_STATUS (AE_SUPPORT);
599 /* Must COPY string and buffer contents */
601 switch (ExternalObject->Type)
603 case ACPI_TYPE_STRING:
605 InternalObject->String.Pointer =
606 ACPI_ALLOCATE_ZEROED ((ACPI_SIZE)
607 ExternalObject->String.Length + 1);
609 if (!InternalObject->String.Pointer)
611 goto ErrorExit;
614 ACPI_MEMCPY (InternalObject->String.Pointer,
615 ExternalObject->String.Pointer,
616 ExternalObject->String.Length);
618 InternalObject->String.Length = ExternalObject->String.Length;
619 break;
622 case ACPI_TYPE_BUFFER:
624 InternalObject->Buffer.Pointer =
625 ACPI_ALLOCATE_ZEROED (ExternalObject->Buffer.Length);
626 if (!InternalObject->Buffer.Pointer)
628 goto ErrorExit;
631 ACPI_MEMCPY (InternalObject->Buffer.Pointer,
632 ExternalObject->Buffer.Pointer,
633 ExternalObject->Buffer.Length);
635 InternalObject->Buffer.Length = ExternalObject->Buffer.Length;
637 /* Mark buffer data valid */
639 InternalObject->Buffer.Flags |= AOPOBJ_DATA_VALID;
640 break;
643 case ACPI_TYPE_INTEGER:
645 InternalObject->Integer.Value = ExternalObject->Integer.Value;
646 break;
648 case ACPI_TYPE_LOCAL_REFERENCE:
650 /* TBD: should validate incoming handle */
652 InternalObject->Reference.Class = ACPI_REFCLASS_NAME;
653 InternalObject->Reference.Node = ExternalObject->Reference.Handle;
654 break;
656 default:
657 /* Other types can't get here */
658 break;
661 *RetInternalObject = InternalObject;
662 return_ACPI_STATUS (AE_OK);
665 ErrorExit:
666 AcpiUtRemoveReference (InternalObject);
667 return_ACPI_STATUS (AE_NO_MEMORY);
671 /*******************************************************************************
673 * FUNCTION: AcpiUtCopyEpackageToIpackage
675 * PARAMETERS: ExternalObject - The external object to be converted
676 * InternalObject - Where the internal object is returned
678 * RETURN: Status
680 * DESCRIPTION: Copy an external package object to an internal package.
681 * Handles nested packages.
683 ******************************************************************************/
685 static ACPI_STATUS
686 AcpiUtCopyEpackageToIpackage (
687 ACPI_OBJECT *ExternalObject,
688 ACPI_OPERAND_OBJECT **InternalObject)
690 ACPI_STATUS Status = AE_OK;
691 ACPI_OPERAND_OBJECT *PackageObject;
692 ACPI_OPERAND_OBJECT **PackageElements;
693 UINT32 i;
696 ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage);
699 /* Create the package object */
701 PackageObject = AcpiUtCreatePackageObject (ExternalObject->Package.Count);
702 if (!PackageObject)
704 return_ACPI_STATUS (AE_NO_MEMORY);
707 PackageElements = PackageObject->Package.Elements;
710 * Recursive implementation. Probably ok, since nested external packages
711 * as parameters should be very rare.
713 for (i = 0; i < ExternalObject->Package.Count; i++)
715 Status = AcpiUtCopyEobjectToIobject (
716 &ExternalObject->Package.Elements[i],
717 &PackageElements[i]);
718 if (ACPI_FAILURE (Status))
720 /* Truncate package and delete it */
722 PackageObject->Package.Count = i;
723 PackageElements[i] = NULL;
724 AcpiUtRemoveReference (PackageObject);
725 return_ACPI_STATUS (Status);
729 /* Mark package data valid */
731 PackageObject->Package.Flags |= AOPOBJ_DATA_VALID;
733 *InternalObject = PackageObject;
734 return_ACPI_STATUS (Status);
738 /*******************************************************************************
740 * FUNCTION: AcpiUtCopyEobjectToIobject
742 * PARAMETERS: ExternalObject - The external object to be converted
743 * InternalObject - Where the internal object is returned
745 * RETURN: Status
747 * DESCRIPTION: Converts an external object to an internal object.
749 ******************************************************************************/
751 ACPI_STATUS
752 AcpiUtCopyEobjectToIobject (
753 ACPI_OBJECT *ExternalObject,
754 ACPI_OPERAND_OBJECT **InternalObject)
756 ACPI_STATUS Status;
759 ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject);
762 if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
764 Status = AcpiUtCopyEpackageToIpackage (ExternalObject, InternalObject);
766 else
769 * Build a simple object (no nested objects)
771 Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject);
774 return_ACPI_STATUS (Status);
778 /*******************************************************************************
780 * FUNCTION: AcpiUtCopySimpleObject
782 * PARAMETERS: SourceDesc - The internal object to be copied
783 * DestDesc - New target object
785 * RETURN: Status
787 * DESCRIPTION: Simple copy of one internal object to another. Reference count
788 * of the destination object is preserved.
790 ******************************************************************************/
792 static ACPI_STATUS
793 AcpiUtCopySimpleObject (
794 ACPI_OPERAND_OBJECT *SourceDesc,
795 ACPI_OPERAND_OBJECT *DestDesc)
797 UINT16 ReferenceCount;
798 ACPI_OPERAND_OBJECT *NextObject;
799 ACPI_STATUS Status;
800 ACPI_SIZE CopySize;
803 /* Save fields from destination that we don't want to overwrite */
805 ReferenceCount = DestDesc->Common.ReferenceCount;
806 NextObject = DestDesc->Common.NextObject;
809 * Copy the entire source object over the destination object.
810 * Note: Source can be either an operand object or namespace node.
812 CopySize = sizeof (ACPI_OPERAND_OBJECT);
813 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
815 CopySize = sizeof (ACPI_NAMESPACE_NODE);
818 ACPI_MEMCPY (ACPI_CAST_PTR (char, DestDesc),
819 ACPI_CAST_PTR (char, SourceDesc), CopySize);
821 /* Restore the saved fields */
823 DestDesc->Common.ReferenceCount = ReferenceCount;
824 DestDesc->Common.NextObject = NextObject;
826 /* New object is not static, regardless of source */
828 DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
830 /* Handle the objects with extra data */
832 switch (DestDesc->Common.Type)
834 case ACPI_TYPE_BUFFER:
836 * Allocate and copy the actual buffer if and only if:
837 * 1) There is a valid buffer pointer
838 * 2) The buffer has a length > 0
840 if ((SourceDesc->Buffer.Pointer) &&
841 (SourceDesc->Buffer.Length))
843 DestDesc->Buffer.Pointer =
844 ACPI_ALLOCATE (SourceDesc->Buffer.Length);
845 if (!DestDesc->Buffer.Pointer)
847 return (AE_NO_MEMORY);
850 /* Copy the actual buffer data */
852 ACPI_MEMCPY (DestDesc->Buffer.Pointer,
853 SourceDesc->Buffer.Pointer, SourceDesc->Buffer.Length);
855 break;
857 case ACPI_TYPE_STRING:
859 * Allocate and copy the actual string if and only if:
860 * 1) There is a valid string pointer
861 * (Pointer to a NULL string is allowed)
863 if (SourceDesc->String.Pointer)
865 DestDesc->String.Pointer =
866 ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1);
867 if (!DestDesc->String.Pointer)
869 return (AE_NO_MEMORY);
872 /* Copy the actual string data */
874 ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer,
875 (ACPI_SIZE) SourceDesc->String.Length + 1);
877 break;
879 case ACPI_TYPE_LOCAL_REFERENCE:
881 * We copied the reference object, so we now must add a reference
882 * to the object pointed to by the reference
884 * DDBHandle reference (from Load/LoadTable) is a special reference,
885 * it does not have a Reference.Object, so does not need to
886 * increase the reference count
888 if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
890 break;
893 AcpiUtAddReference (SourceDesc->Reference.Object);
894 break;
896 case ACPI_TYPE_REGION:
898 * We copied the Region Handler, so we now must add a reference
900 if (DestDesc->Region.Handler)
902 AcpiUtAddReference (DestDesc->Region.Handler);
904 break;
907 * For Mutex and Event objects, we cannot simply copy the underlying
908 * OS object. We must create a new one.
910 case ACPI_TYPE_MUTEX:
912 Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex);
913 if (ACPI_FAILURE (Status))
915 return (Status);
917 break;
919 case ACPI_TYPE_EVENT:
921 Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
922 &DestDesc->Event.OsSemaphore);
923 if (ACPI_FAILURE (Status))
925 return (Status);
927 break;
929 default:
930 /* Nothing to do for other simple objects */
931 break;
934 return (AE_OK);
938 /*******************************************************************************
940 * FUNCTION: AcpiUtCopyIelementToIelement
942 * PARAMETERS: ACPI_PKG_CALLBACK
944 * RETURN: Status
946 * DESCRIPTION: Copy one package element to another package element
948 ******************************************************************************/
950 static ACPI_STATUS
951 AcpiUtCopyIelementToIelement (
952 UINT8 ObjectType,
953 ACPI_OPERAND_OBJECT *SourceObject,
954 ACPI_GENERIC_STATE *State,
955 void *Context)
957 ACPI_STATUS Status = AE_OK;
958 UINT32 ThisIndex;
959 ACPI_OPERAND_OBJECT **ThisTargetPtr;
960 ACPI_OPERAND_OBJECT *TargetObject;
963 ACPI_FUNCTION_ENTRY ();
966 ThisIndex = State->Pkg.Index;
967 ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
968 &State->Pkg.DestObject->Package.Elements[ThisIndex];
970 switch (ObjectType)
972 case ACPI_COPY_TYPE_SIMPLE:
974 /* A null source object indicates a (legal) null package element */
976 if (SourceObject)
979 * This is a simple object, just copy it
981 TargetObject = AcpiUtCreateInternalObject (
982 SourceObject->Common.Type);
983 if (!TargetObject)
985 return (AE_NO_MEMORY);
988 Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);
989 if (ACPI_FAILURE (Status))
991 goto ErrorExit;
994 *ThisTargetPtr = TargetObject;
996 else
998 /* Pass through a null element */
1000 *ThisTargetPtr = NULL;
1002 break;
1005 case ACPI_COPY_TYPE_PACKAGE:
1008 * This object is a package - go down another nesting level
1009 * Create and build the package object
1011 TargetObject = AcpiUtCreatePackageObject (SourceObject->Package.Count);
1012 if (!TargetObject)
1014 return (AE_NO_MEMORY);
1017 TargetObject->Common.Flags = SourceObject->Common.Flags;
1019 /* Pass the new package object back to the package walk routine */
1021 State->Pkg.ThisTargetObj = TargetObject;
1023 /* Store the object pointer in the parent package object */
1025 *ThisTargetPtr = TargetObject;
1026 break;
1029 default:
1030 return (AE_BAD_PARAMETER);
1033 return (Status);
1035 ErrorExit:
1036 AcpiUtRemoveReference (TargetObject);
1037 return (Status);
1041 /*******************************************************************************
1043 * FUNCTION: AcpiUtCopyIpackageToIpackage
1045 * PARAMETERS: SourceObj - Pointer to the source package object
1046 * DestObj - Where the internal object is returned
1047 * WalkState - Current Walk state descriptor
1049 * RETURN: Status
1051 * DESCRIPTION: This function is called to copy an internal package object
1052 * into another internal package object.
1054 ******************************************************************************/
1056 static ACPI_STATUS
1057 AcpiUtCopyIpackageToIpackage (
1058 ACPI_OPERAND_OBJECT *SourceObj,
1059 ACPI_OPERAND_OBJECT *DestObj,
1060 ACPI_WALK_STATE *WalkState)
1062 ACPI_STATUS Status = AE_OK;
1065 ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage);
1068 DestObj->Common.Type = SourceObj->Common.Type;
1069 DestObj->Common.Flags = SourceObj->Common.Flags;
1070 DestObj->Package.Count = SourceObj->Package.Count;
1073 * Create the object array and walk the source package tree
1075 DestObj->Package.Elements = ACPI_ALLOCATE_ZEROED (
1076 ((ACPI_SIZE) SourceObj->Package.Count + 1) *
1077 sizeof (void *));
1078 if (!DestObj->Package.Elements)
1080 ACPI_ERROR ((AE_INFO, "Package allocation failure"));
1081 return_ACPI_STATUS (AE_NO_MEMORY);
1085 * Copy the package element-by-element by walking the package "tree".
1086 * This handles nested packages of arbitrary depth.
1088 Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
1089 AcpiUtCopyIelementToIelement, WalkState);
1090 if (ACPI_FAILURE (Status))
1092 /* On failure, delete the destination package object */
1094 AcpiUtRemoveReference (DestObj);
1097 return_ACPI_STATUS (Status);
1101 /*******************************************************************************
1103 * FUNCTION: AcpiUtCopyIobjectToIobject
1105 * PARAMETERS: SourceDesc - The internal object to be copied
1106 * DestDesc - Where the copied object is returned
1107 * WalkState - Current walk state
1109 * RETURN: Status
1111 * DESCRIPTION: Copy an internal object to a new internal object
1113 ******************************************************************************/
1115 ACPI_STATUS
1116 AcpiUtCopyIobjectToIobject (
1117 ACPI_OPERAND_OBJECT *SourceDesc,
1118 ACPI_OPERAND_OBJECT **DestDesc,
1119 ACPI_WALK_STATE *WalkState)
1121 ACPI_STATUS Status = AE_OK;
1124 ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject);
1127 /* Create the top level object */
1129 *DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type);
1130 if (!*DestDesc)
1132 return_ACPI_STATUS (AE_NO_MEMORY);
1135 /* Copy the object and possible subobjects */
1137 if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE)
1139 Status = AcpiUtCopyIpackageToIpackage (SourceDesc, *DestDesc,
1140 WalkState);
1142 else
1144 Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);
1147 return_ACPI_STATUS (Status);