1 /******************************************************************************
3 * Module Name: utcopy - Internal to external object translation utilities
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
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
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
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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
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
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 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
153 #include "accommon.h"
154 #include "acnamesp.h"
157 #define _COMPONENT ACPI_UTILITIES
158 ACPI_MODULE_NAME ("utcopy")
160 /* Local prototypes */
163 AcpiUtCopyIsimpleToEsimple (
164 ACPI_OPERAND_OBJECT
*InternalObject
,
165 ACPI_OBJECT
*ExternalObject
,
167 ACPI_SIZE
*BufferSpaceUsed
);
170 AcpiUtCopyIelementToIelement (
172 ACPI_OPERAND_OBJECT
*SourceObject
,
173 ACPI_GENERIC_STATE
*State
,
177 AcpiUtCopyIpackageToEpackage (
178 ACPI_OPERAND_OBJECT
*InternalObject
,
180 ACPI_SIZE
*SpaceUsed
);
183 AcpiUtCopyEsimpleToIsimple(
184 ACPI_OBJECT
*UserObj
,
185 ACPI_OPERAND_OBJECT
**ReturnObj
);
188 AcpiUtCopyEpackageToIpackage (
189 ACPI_OBJECT
*ExternalObject
,
190 ACPI_OPERAND_OBJECT
**InternalObject
);
193 AcpiUtCopySimpleObject (
194 ACPI_OPERAND_OBJECT
*SourceDesc
,
195 ACPI_OPERAND_OBJECT
*DestDesc
);
198 AcpiUtCopyIelementToEelement (
200 ACPI_OPERAND_OBJECT
*SourceObject
,
201 ACPI_GENERIC_STATE
*State
,
205 AcpiUtCopyIpackageToIpackage (
206 ACPI_OPERAND_OBJECT
*SourceObj
,
207 ACPI_OPERAND_OBJECT
*DestObj
,
208 ACPI_WALK_STATE
*WalkState
);
211 /*******************************************************************************
213 * FUNCTION: AcpiUtCopyIsimpleToEsimple
215 * PARAMETERS: InternalObject - Source object to be copied
216 * ExternalObject - Where to return the copied object
217 * DataSpace - Where object data is returned (such as
218 * buffer and string data)
219 * BufferSpaceUsed - Length of DataSpace that was used
223 * DESCRIPTION: This function is called to copy a simple internal object to
224 * an external object.
226 * The DataSpace buffer is assumed to have sufficient space for
229 ******************************************************************************/
232 AcpiUtCopyIsimpleToEsimple (
233 ACPI_OPERAND_OBJECT
*InternalObject
,
234 ACPI_OBJECT
*ExternalObject
,
236 ACPI_SIZE
*BufferSpaceUsed
)
238 ACPI_STATUS Status
= AE_OK
;
241 ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple
);
244 *BufferSpaceUsed
= 0;
247 * Check for NULL object case (could be an uninitialized
252 return_ACPI_STATUS (AE_OK
);
255 /* Always clear the external object */
257 memset (ExternalObject
, 0, sizeof (ACPI_OBJECT
));
260 * In general, the external object will be the same type as
261 * the internal object
263 ExternalObject
->Type
= InternalObject
->Common
.Type
;
265 /* However, only a limited number of external types are supported */
267 switch (InternalObject
->Common
.Type
)
269 case ACPI_TYPE_STRING
:
271 ExternalObject
->String
.Pointer
= (char *) DataSpace
;
272 ExternalObject
->String
.Length
= InternalObject
->String
.Length
;
273 *BufferSpaceUsed
= ACPI_ROUND_UP_TO_NATIVE_WORD (
274 (ACPI_SIZE
) InternalObject
->String
.Length
+ 1);
276 memcpy ((void *) DataSpace
,
277 (void *) InternalObject
->String
.Pointer
,
278 (ACPI_SIZE
) InternalObject
->String
.Length
+ 1);
281 case ACPI_TYPE_BUFFER
:
283 ExternalObject
->Buffer
.Pointer
= DataSpace
;
284 ExternalObject
->Buffer
.Length
= InternalObject
->Buffer
.Length
;
285 *BufferSpaceUsed
= ACPI_ROUND_UP_TO_NATIVE_WORD (
286 InternalObject
->String
.Length
);
288 memcpy ((void *) DataSpace
,
289 (void *) InternalObject
->Buffer
.Pointer
,
290 InternalObject
->Buffer
.Length
);
293 case ACPI_TYPE_INTEGER
:
295 ExternalObject
->Integer
.Value
= InternalObject
->Integer
.Value
;
298 case ACPI_TYPE_LOCAL_REFERENCE
:
300 /* This is an object reference. */
302 switch (InternalObject
->Reference
.Class
)
304 case ACPI_REFCLASS_NAME
:
306 * For namepath, return the object handle ("reference")
307 * We are referring to the namespace node
309 ExternalObject
->Reference
.Handle
=
310 InternalObject
->Reference
.Node
;
311 ExternalObject
->Reference
.ActualType
=
312 AcpiNsGetType (InternalObject
->Reference
.Node
);
317 /* All other reference types are unsupported */
319 return_ACPI_STATUS (AE_TYPE
);
323 case ACPI_TYPE_PROCESSOR
:
325 ExternalObject
->Processor
.ProcId
=
326 InternalObject
->Processor
.ProcId
;
327 ExternalObject
->Processor
.PblkAddress
=
328 InternalObject
->Processor
.Address
;
329 ExternalObject
->Processor
.PblkLength
=
330 InternalObject
->Processor
.Length
;
333 case ACPI_TYPE_POWER
:
335 ExternalObject
->PowerResource
.SystemLevel
=
336 InternalObject
->PowerResource
.SystemLevel
;
338 ExternalObject
->PowerResource
.ResourceOrder
=
339 InternalObject
->PowerResource
.ResourceOrder
;
344 * There is no corresponding external object type
346 ACPI_ERROR ((AE_INFO
,
347 "Unsupported object type, cannot convert to external object: %s",
348 AcpiUtGetTypeName (InternalObject
->Common
.Type
)));
350 return_ACPI_STATUS (AE_SUPPORT
);
353 return_ACPI_STATUS (Status
);
357 /*******************************************************************************
359 * FUNCTION: AcpiUtCopyIelementToEelement
361 * PARAMETERS: ACPI_PKG_CALLBACK
365 * DESCRIPTION: Copy one package element to another package element
367 ******************************************************************************/
370 AcpiUtCopyIelementToEelement (
372 ACPI_OPERAND_OBJECT
*SourceObject
,
373 ACPI_GENERIC_STATE
*State
,
376 ACPI_STATUS Status
= AE_OK
;
377 ACPI_PKG_INFO
*Info
= (ACPI_PKG_INFO
*) Context
;
378 ACPI_SIZE ObjectSpace
;
380 ACPI_OBJECT
*TargetObject
;
383 ACPI_FUNCTION_ENTRY ();
386 ThisIndex
= State
->Pkg
.Index
;
387 TargetObject
= (ACPI_OBJECT
*) &((ACPI_OBJECT
*)
388 (State
->Pkg
.DestObject
))->Package
.Elements
[ThisIndex
];
392 case ACPI_COPY_TYPE_SIMPLE
:
394 * This is a simple or null object
396 Status
= AcpiUtCopyIsimpleToEsimple (SourceObject
,
397 TargetObject
, Info
->FreeSpace
, &ObjectSpace
);
398 if (ACPI_FAILURE (Status
))
404 case ACPI_COPY_TYPE_PACKAGE
:
406 * Build the package object
408 TargetObject
->Type
= ACPI_TYPE_PACKAGE
;
409 TargetObject
->Package
.Count
= SourceObject
->Package
.Count
;
410 TargetObject
->Package
.Elements
=
411 ACPI_CAST_PTR (ACPI_OBJECT
, Info
->FreeSpace
);
414 * Pass the new package object back to the package walk routine
416 State
->Pkg
.ThisTargetObj
= TargetObject
;
419 * Save space for the array of objects (Package elements)
420 * update the buffer length counter
422 ObjectSpace
= ACPI_ROUND_UP_TO_NATIVE_WORD (
423 (ACPI_SIZE
) TargetObject
->Package
.Count
*
424 sizeof (ACPI_OBJECT
));
429 return (AE_BAD_PARAMETER
);
432 Info
->FreeSpace
+= ObjectSpace
;
433 Info
->Length
+= ObjectSpace
;
438 /*******************************************************************************
440 * FUNCTION: AcpiUtCopyIpackageToEpackage
442 * PARAMETERS: InternalObject - Pointer to the object we are returning
443 * Buffer - Where the object is returned
444 * SpaceUsed - Where the object length is returned
448 * DESCRIPTION: This function is called to place a package object in a user
449 * buffer. A package object by definition contains other objects.
451 * The buffer is assumed to have sufficient space for the object.
452 * The caller must have verified the buffer length needed using
453 * the AcpiUtGetObjectSize function before calling this function.
455 ******************************************************************************/
458 AcpiUtCopyIpackageToEpackage (
459 ACPI_OPERAND_OBJECT
*InternalObject
,
461 ACPI_SIZE
*SpaceUsed
)
463 ACPI_OBJECT
*ExternalObject
;
468 ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage
);
472 * First package at head of the buffer
474 ExternalObject
= ACPI_CAST_PTR (ACPI_OBJECT
, Buffer
);
477 * Free space begins right after the first package
479 Info
.Length
= ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT
));
480 Info
.FreeSpace
= Buffer
+
481 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT
));
482 Info
.ObjectSpace
= 0;
483 Info
.NumPackages
= 1;
485 ExternalObject
->Type
= InternalObject
->Common
.Type
;
486 ExternalObject
->Package
.Count
= InternalObject
->Package
.Count
;
487 ExternalObject
->Package
.Elements
=
488 ACPI_CAST_PTR (ACPI_OBJECT
, Info
.FreeSpace
);
491 * Leave room for an array of ACPI_OBJECTS in the buffer
492 * and move the free space past it
494 Info
.Length
+= (ACPI_SIZE
) ExternalObject
->Package
.Count
*
495 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT
));
496 Info
.FreeSpace
+= ExternalObject
->Package
.Count
*
497 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT
));
499 Status
= AcpiUtWalkPackageTree (InternalObject
, ExternalObject
,
500 AcpiUtCopyIelementToEelement
, &Info
);
502 *SpaceUsed
= Info
.Length
;
503 return_ACPI_STATUS (Status
);
507 /*******************************************************************************
509 * FUNCTION: AcpiUtCopyIobjectToEobject
511 * PARAMETERS: InternalObject - The internal object to be converted
512 * RetBuffer - Where the object is returned
516 * DESCRIPTION: This function is called to build an API object to be returned
519 ******************************************************************************/
522 AcpiUtCopyIobjectToEobject (
523 ACPI_OPERAND_OBJECT
*InternalObject
,
524 ACPI_BUFFER
*RetBuffer
)
529 ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject
);
532 if (InternalObject
->Common
.Type
== ACPI_TYPE_PACKAGE
)
535 * Package object: Copy all subobjects (including
538 Status
= AcpiUtCopyIpackageToEpackage (InternalObject
,
539 RetBuffer
->Pointer
, &RetBuffer
->Length
);
544 * Build a simple object (no nested objects)
546 Status
= AcpiUtCopyIsimpleToEsimple (InternalObject
,
547 ACPI_CAST_PTR (ACPI_OBJECT
, RetBuffer
->Pointer
),
548 ACPI_ADD_PTR (UINT8
, RetBuffer
->Pointer
,
549 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT
))),
552 * build simple does not include the object size in the length
553 * so we add it in here
555 RetBuffer
->Length
+= sizeof (ACPI_OBJECT
);
558 return_ACPI_STATUS (Status
);
562 /*******************************************************************************
564 * FUNCTION: AcpiUtCopyEsimpleToIsimple
566 * PARAMETERS: ExternalObject - The external object to be converted
567 * RetInternalObject - Where the internal object is returned
571 * DESCRIPTION: This function copies an external object to an internal one.
572 * NOTE: Pointers can be copied, we don't need to copy data.
573 * (The pointers have to be valid in our address space no matter
574 * what we do with them!)
576 ******************************************************************************/
579 AcpiUtCopyEsimpleToIsimple (
580 ACPI_OBJECT
*ExternalObject
,
581 ACPI_OPERAND_OBJECT
**RetInternalObject
)
583 ACPI_OPERAND_OBJECT
*InternalObject
;
586 ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple
);
590 * Simple types supported are: String, Buffer, Integer
592 switch (ExternalObject
->Type
)
594 case ACPI_TYPE_STRING
:
595 case ACPI_TYPE_BUFFER
:
596 case ACPI_TYPE_INTEGER
:
597 case ACPI_TYPE_LOCAL_REFERENCE
:
599 InternalObject
= AcpiUtCreateInternalObject (
600 (UINT8
) ExternalObject
->Type
);
603 return_ACPI_STATUS (AE_NO_MEMORY
);
607 case ACPI_TYPE_ANY
: /* This is the case for a NULL object */
609 *RetInternalObject
= NULL
;
610 return_ACPI_STATUS (AE_OK
);
614 /* All other types are not supported */
616 ACPI_ERROR ((AE_INFO
,
617 "Unsupported object type, cannot convert to internal object: %s",
618 AcpiUtGetTypeName (ExternalObject
->Type
)));
620 return_ACPI_STATUS (AE_SUPPORT
);
624 /* Must COPY string and buffer contents */
626 switch (ExternalObject
->Type
)
628 case ACPI_TYPE_STRING
:
630 InternalObject
->String
.Pointer
=
631 ACPI_ALLOCATE_ZEROED ((ACPI_SIZE
)
632 ExternalObject
->String
.Length
+ 1);
634 if (!InternalObject
->String
.Pointer
)
639 memcpy (InternalObject
->String
.Pointer
,
640 ExternalObject
->String
.Pointer
,
641 ExternalObject
->String
.Length
);
643 InternalObject
->String
.Length
= ExternalObject
->String
.Length
;
646 case ACPI_TYPE_BUFFER
:
648 InternalObject
->Buffer
.Pointer
=
649 ACPI_ALLOCATE_ZEROED (ExternalObject
->Buffer
.Length
);
650 if (!InternalObject
->Buffer
.Pointer
)
655 memcpy (InternalObject
->Buffer
.Pointer
,
656 ExternalObject
->Buffer
.Pointer
,
657 ExternalObject
->Buffer
.Length
);
659 InternalObject
->Buffer
.Length
= ExternalObject
->Buffer
.Length
;
661 /* Mark buffer data valid */
663 InternalObject
->Buffer
.Flags
|= AOPOBJ_DATA_VALID
;
666 case ACPI_TYPE_INTEGER
:
668 InternalObject
->Integer
.Value
= ExternalObject
->Integer
.Value
;
671 case ACPI_TYPE_LOCAL_REFERENCE
:
673 /* An incoming reference is defined to be a namespace node */
675 InternalObject
->Reference
.Class
= ACPI_REFCLASS_REFOF
;
676 InternalObject
->Reference
.Object
= ExternalObject
->Reference
.Handle
;
681 /* Other types can't get here */
686 *RetInternalObject
= InternalObject
;
687 return_ACPI_STATUS (AE_OK
);
691 AcpiUtRemoveReference (InternalObject
);
692 return_ACPI_STATUS (AE_NO_MEMORY
);
696 /*******************************************************************************
698 * FUNCTION: AcpiUtCopyEpackageToIpackage
700 * PARAMETERS: ExternalObject - The external object to be converted
701 * InternalObject - Where the internal object is returned
705 * DESCRIPTION: Copy an external package object to an internal package.
706 * Handles nested packages.
708 ******************************************************************************/
711 AcpiUtCopyEpackageToIpackage (
712 ACPI_OBJECT
*ExternalObject
,
713 ACPI_OPERAND_OBJECT
**InternalObject
)
715 ACPI_STATUS Status
= AE_OK
;
716 ACPI_OPERAND_OBJECT
*PackageObject
;
717 ACPI_OPERAND_OBJECT
**PackageElements
;
721 ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage
);
724 /* Create the package object */
726 PackageObject
= AcpiUtCreatePackageObject (
727 ExternalObject
->Package
.Count
);
730 return_ACPI_STATUS (AE_NO_MEMORY
);
733 PackageElements
= PackageObject
->Package
.Elements
;
736 * Recursive implementation. Probably ok, since nested external
737 * packages as parameters should be very rare.
739 for (i
= 0; i
< ExternalObject
->Package
.Count
; i
++)
741 Status
= AcpiUtCopyEobjectToIobject (
742 &ExternalObject
->Package
.Elements
[i
],
743 &PackageElements
[i
]);
744 if (ACPI_FAILURE (Status
))
746 /* Truncate package and delete it */
748 PackageObject
->Package
.Count
= i
;
749 PackageElements
[i
] = NULL
;
750 AcpiUtRemoveReference (PackageObject
);
751 return_ACPI_STATUS (Status
);
755 /* Mark package data valid */
757 PackageObject
->Package
.Flags
|= AOPOBJ_DATA_VALID
;
759 *InternalObject
= PackageObject
;
760 return_ACPI_STATUS (Status
);
764 /*******************************************************************************
766 * FUNCTION: AcpiUtCopyEobjectToIobject
768 * PARAMETERS: ExternalObject - The external object to be converted
769 * InternalObject - Where the internal object is returned
773 * DESCRIPTION: Converts an external object to an internal object.
775 ******************************************************************************/
778 AcpiUtCopyEobjectToIobject (
779 ACPI_OBJECT
*ExternalObject
,
780 ACPI_OPERAND_OBJECT
**InternalObject
)
785 ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject
);
788 if (ExternalObject
->Type
== ACPI_TYPE_PACKAGE
)
790 Status
= AcpiUtCopyEpackageToIpackage (
791 ExternalObject
, InternalObject
);
796 * Build a simple object (no nested objects)
798 Status
= AcpiUtCopyEsimpleToIsimple (ExternalObject
,
802 return_ACPI_STATUS (Status
);
806 /*******************************************************************************
808 * FUNCTION: AcpiUtCopySimpleObject
810 * PARAMETERS: SourceDesc - The internal object to be copied
811 * DestDesc - New target object
815 * DESCRIPTION: Simple copy of one internal object to another. Reference count
816 * of the destination object is preserved.
818 ******************************************************************************/
821 AcpiUtCopySimpleObject (
822 ACPI_OPERAND_OBJECT
*SourceDesc
,
823 ACPI_OPERAND_OBJECT
*DestDesc
)
825 UINT16 ReferenceCount
;
826 ACPI_OPERAND_OBJECT
*NextObject
;
831 /* Save fields from destination that we don't want to overwrite */
833 ReferenceCount
= DestDesc
->Common
.ReferenceCount
;
834 NextObject
= DestDesc
->Common
.NextObject
;
837 * Copy the entire source object over the destination object.
838 * Note: Source can be either an operand object or namespace node.
840 CopySize
= sizeof (ACPI_OPERAND_OBJECT
);
841 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc
) == ACPI_DESC_TYPE_NAMED
)
843 CopySize
= sizeof (ACPI_NAMESPACE_NODE
);
846 memcpy (ACPI_CAST_PTR (char, DestDesc
),
847 ACPI_CAST_PTR (char, SourceDesc
), CopySize
);
849 /* Restore the saved fields */
851 DestDesc
->Common
.ReferenceCount
= ReferenceCount
;
852 DestDesc
->Common
.NextObject
= NextObject
;
854 /* New object is not static, regardless of source */
856 DestDesc
->Common
.Flags
&= ~AOPOBJ_STATIC_POINTER
;
858 /* Handle the objects with extra data */
860 switch (DestDesc
->Common
.Type
)
862 case ACPI_TYPE_BUFFER
:
864 * Allocate and copy the actual buffer if and only if:
865 * 1) There is a valid buffer pointer
866 * 2) The buffer has a length > 0
868 if ((SourceDesc
->Buffer
.Pointer
) &&
869 (SourceDesc
->Buffer
.Length
))
871 DestDesc
->Buffer
.Pointer
=
872 ACPI_ALLOCATE (SourceDesc
->Buffer
.Length
);
873 if (!DestDesc
->Buffer
.Pointer
)
875 return (AE_NO_MEMORY
);
878 /* Copy the actual buffer data */
880 memcpy (DestDesc
->Buffer
.Pointer
,
881 SourceDesc
->Buffer
.Pointer
, SourceDesc
->Buffer
.Length
);
885 case ACPI_TYPE_STRING
:
887 * Allocate and copy the actual string if and only if:
888 * 1) There is a valid string pointer
889 * (Pointer to a NULL string is allowed)
891 if (SourceDesc
->String
.Pointer
)
893 DestDesc
->String
.Pointer
=
894 ACPI_ALLOCATE ((ACPI_SIZE
) SourceDesc
->String
.Length
+ 1);
895 if (!DestDesc
->String
.Pointer
)
897 return (AE_NO_MEMORY
);
900 /* Copy the actual string data */
902 memcpy (DestDesc
->String
.Pointer
, SourceDesc
->String
.Pointer
,
903 (ACPI_SIZE
) SourceDesc
->String
.Length
+ 1);
907 case ACPI_TYPE_LOCAL_REFERENCE
:
909 * We copied the reference object, so we now must add a reference
910 * to the object pointed to by the reference
912 * DDBHandle reference (from Load/LoadTable) is a special reference,
913 * it does not have a Reference.Object, so does not need to
914 * increase the reference count
916 if (SourceDesc
->Reference
.Class
== ACPI_REFCLASS_TABLE
)
921 AcpiUtAddReference (SourceDesc
->Reference
.Object
);
924 case ACPI_TYPE_REGION
:
926 * We copied the Region Handler, so we now must add a reference
928 if (DestDesc
->Region
.Handler
)
930 AcpiUtAddReference (DestDesc
->Region
.Handler
);
935 * For Mutex and Event objects, we cannot simply copy the underlying
936 * OS object. We must create a new one.
938 case ACPI_TYPE_MUTEX
:
940 Status
= AcpiOsCreateMutex (&DestDesc
->Mutex
.OsMutex
);
941 if (ACPI_FAILURE (Status
))
947 case ACPI_TYPE_EVENT
:
949 Status
= AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT
, 0,
950 &DestDesc
->Event
.OsSemaphore
);
951 if (ACPI_FAILURE (Status
))
959 /* Nothing to do for other simple objects */
968 /*******************************************************************************
970 * FUNCTION: AcpiUtCopyIelementToIelement
972 * PARAMETERS: ACPI_PKG_CALLBACK
976 * DESCRIPTION: Copy one package element to another package element
978 ******************************************************************************/
981 AcpiUtCopyIelementToIelement (
983 ACPI_OPERAND_OBJECT
*SourceObject
,
984 ACPI_GENERIC_STATE
*State
,
987 ACPI_STATUS Status
= AE_OK
;
989 ACPI_OPERAND_OBJECT
**ThisTargetPtr
;
990 ACPI_OPERAND_OBJECT
*TargetObject
;
993 ACPI_FUNCTION_ENTRY ();
996 ThisIndex
= State
->Pkg
.Index
;
997 ThisTargetPtr
= (ACPI_OPERAND_OBJECT
**)
998 &State
->Pkg
.DestObject
->Package
.Elements
[ThisIndex
];
1002 case ACPI_COPY_TYPE_SIMPLE
:
1004 /* A null source object indicates a (legal) null package element */
1009 * This is a simple object, just copy it
1011 TargetObject
= AcpiUtCreateInternalObject (
1012 SourceObject
->Common
.Type
);
1015 return (AE_NO_MEMORY
);
1018 Status
= AcpiUtCopySimpleObject (SourceObject
, TargetObject
);
1019 if (ACPI_FAILURE (Status
))
1024 *ThisTargetPtr
= TargetObject
;
1028 /* Pass through a null element */
1030 *ThisTargetPtr
= NULL
;
1034 case ACPI_COPY_TYPE_PACKAGE
:
1036 * This object is a package - go down another nesting level
1037 * Create and build the package object
1039 TargetObject
= AcpiUtCreatePackageObject (
1040 SourceObject
->Package
.Count
);
1043 return (AE_NO_MEMORY
);
1046 TargetObject
->Common
.Flags
= SourceObject
->Common
.Flags
;
1048 /* Pass the new package object back to the package walk routine */
1050 State
->Pkg
.ThisTargetObj
= TargetObject
;
1052 /* Store the object pointer in the parent package object */
1054 *ThisTargetPtr
= TargetObject
;
1059 return (AE_BAD_PARAMETER
);
1065 AcpiUtRemoveReference (TargetObject
);
1070 /*******************************************************************************
1072 * FUNCTION: AcpiUtCopyIpackageToIpackage
1074 * PARAMETERS: SourceObj - Pointer to the source package object
1075 * DestObj - Where the internal object is returned
1076 * WalkState - Current Walk state descriptor
1080 * DESCRIPTION: This function is called to copy an internal package object
1081 * into another internal package object.
1083 ******************************************************************************/
1086 AcpiUtCopyIpackageToIpackage (
1087 ACPI_OPERAND_OBJECT
*SourceObj
,
1088 ACPI_OPERAND_OBJECT
*DestObj
,
1089 ACPI_WALK_STATE
*WalkState
)
1091 ACPI_STATUS Status
= AE_OK
;
1094 ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage
);
1097 DestObj
->Common
.Type
= SourceObj
->Common
.Type
;
1098 DestObj
->Common
.Flags
= SourceObj
->Common
.Flags
;
1099 DestObj
->Package
.Count
= SourceObj
->Package
.Count
;
1102 * Create the object array and walk the source package tree
1104 DestObj
->Package
.Elements
= ACPI_ALLOCATE_ZEROED (
1105 ((ACPI_SIZE
) SourceObj
->Package
.Count
+ 1) *
1107 if (!DestObj
->Package
.Elements
)
1109 ACPI_ERROR ((AE_INFO
, "Package allocation failure"));
1110 return_ACPI_STATUS (AE_NO_MEMORY
);
1114 * Copy the package element-by-element by walking the package "tree".
1115 * This handles nested packages of arbitrary depth.
1117 Status
= AcpiUtWalkPackageTree (SourceObj
, DestObj
,
1118 AcpiUtCopyIelementToIelement
, WalkState
);
1119 if (ACPI_FAILURE (Status
))
1121 /* On failure, delete the destination package object */
1123 AcpiUtRemoveReference (DestObj
);
1126 return_ACPI_STATUS (Status
);
1130 /*******************************************************************************
1132 * FUNCTION: AcpiUtCopyIobjectToIobject
1134 * PARAMETERS: SourceDesc - The internal object to be copied
1135 * DestDesc - Where the copied object is returned
1136 * WalkState - Current walk state
1140 * DESCRIPTION: Copy an internal object to a new internal object
1142 ******************************************************************************/
1145 AcpiUtCopyIobjectToIobject (
1146 ACPI_OPERAND_OBJECT
*SourceDesc
,
1147 ACPI_OPERAND_OBJECT
**DestDesc
,
1148 ACPI_WALK_STATE
*WalkState
)
1150 ACPI_STATUS Status
= AE_OK
;
1153 ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject
);
1156 /* Create the top level object */
1158 *DestDesc
= AcpiUtCreateInternalObject (SourceDesc
->Common
.Type
);
1161 return_ACPI_STATUS (AE_NO_MEMORY
);
1164 /* Copy the object and possible subobjects */
1166 if (SourceDesc
->Common
.Type
== ACPI_TYPE_PACKAGE
)
1168 Status
= AcpiUtCopyIpackageToIpackage (
1169 SourceDesc
, *DestDesc
, WalkState
);
1173 Status
= AcpiUtCopySimpleObject (SourceDesc
, *DestDesc
);
1176 /* Delete the allocated object if copy failed */
1178 if (ACPI_FAILURE (Status
))
1180 AcpiUtRemoveReference (*DestDesc
);
1183 return_ACPI_STATUS (Status
);