xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/utilities/utcopy.c (revision 6dde014f768e0ee49bae871ed857cf433837b9ff)
10174267aSFredrik Holmqvist /******************************************************************************
20174267aSFredrik Holmqvist  *
30174267aSFredrik Holmqvist  * Module Name: utcopy - Internal to external object translation utilities
40174267aSFredrik Holmqvist  *
50174267aSFredrik Holmqvist  *****************************************************************************/
60174267aSFredrik Holmqvist 
70174267aSFredrik Holmqvist /******************************************************************************
80174267aSFredrik Holmqvist  *
90174267aSFredrik Holmqvist  * 1. Copyright Notice
100174267aSFredrik Holmqvist  *
11*6dde014fSPulkoMandy  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
120174267aSFredrik Holmqvist  * All rights reserved.
130174267aSFredrik Holmqvist  *
140174267aSFredrik Holmqvist  * 2. License
150174267aSFredrik Holmqvist  *
160174267aSFredrik Holmqvist  * 2.1. This is your license from Intel Corp. under its intellectual property
170174267aSFredrik Holmqvist  * rights. You may have additional license terms from the party that provided
180174267aSFredrik Holmqvist  * you this software, covering your right to use that party's intellectual
190174267aSFredrik Holmqvist  * property rights.
200174267aSFredrik Holmqvist  *
210174267aSFredrik Holmqvist  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220174267aSFredrik Holmqvist  * copy of the source code appearing in this file ("Covered Code") an
230174267aSFredrik Holmqvist  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240174267aSFredrik Holmqvist  * base code distributed originally by Intel ("Original Intel Code") to copy,
250174267aSFredrik Holmqvist  * make derivatives, distribute, use and display any portion of the Covered
260174267aSFredrik Holmqvist  * Code in any form, with the right to sublicense such rights; and
270174267aSFredrik Holmqvist  *
280174267aSFredrik Holmqvist  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290174267aSFredrik Holmqvist  * license (with the right to sublicense), under only those claims of Intel
300174267aSFredrik Holmqvist  * patents that are infringed by the Original Intel Code, to make, use, sell,
310174267aSFredrik Holmqvist  * offer to sell, and import the Covered Code and derivative works thereof
320174267aSFredrik Holmqvist  * solely to the minimum extent necessary to exercise the above copyright
330174267aSFredrik Holmqvist  * license, and in no event shall the patent license extend to any additions
340174267aSFredrik Holmqvist  * to or modifications of the Original Intel Code. No other license or right
350174267aSFredrik Holmqvist  * is granted directly or by implication, estoppel or otherwise;
360174267aSFredrik Holmqvist  *
370174267aSFredrik Holmqvist  * The above copyright and patent license is granted only if the following
380174267aSFredrik Holmqvist  * conditions are met:
390174267aSFredrik Holmqvist  *
400174267aSFredrik Holmqvist  * 3. Conditions
410174267aSFredrik Holmqvist  *
420174267aSFredrik Holmqvist  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
440174267aSFredrik Holmqvist  * Code or modification with rights to further distribute source must include
450174267aSFredrik Holmqvist  * the above Copyright Notice, the above License, this list of Conditions,
460174267aSFredrik Holmqvist  * and the following Disclaimer and Export Compliance provision. In addition,
470174267aSFredrik Holmqvist  * Licensee must cause all Covered Code to which Licensee contributes to
480174267aSFredrik Holmqvist  * contain a file documenting the changes Licensee made to create that Covered
490174267aSFredrik Holmqvist  * Code and the date of any change. Licensee must include in that file the
500174267aSFredrik Holmqvist  * documentation of any changes made by any predecessor Licensee. Licensee
510174267aSFredrik Holmqvist  * must include a prominent statement that the modification is derived,
520174267aSFredrik Holmqvist  * directly or indirectly, from Original Intel Code.
530174267aSFredrik Holmqvist  *
540174267aSFredrik Holmqvist  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
560174267aSFredrik Holmqvist  * Code or modification without rights to further distribute source must
570174267aSFredrik Holmqvist  * include the following Disclaimer and Export Compliance provision in the
580174267aSFredrik Holmqvist  * documentation and/or other materials provided with distribution. In
590174267aSFredrik Holmqvist  * addition, Licensee may not authorize further sublicense of source of any
600174267aSFredrik Holmqvist  * portion of the Covered Code, and must include terms to the effect that the
610174267aSFredrik Holmqvist  * license from Licensee to its licensee is limited to the intellectual
620174267aSFredrik Holmqvist  * property embodied in the software Licensee provides to its licensee, and
630174267aSFredrik Holmqvist  * not to intellectual property embodied in modifications its licensee may
640174267aSFredrik Holmqvist  * make.
650174267aSFredrik Holmqvist  *
660174267aSFredrik Holmqvist  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670174267aSFredrik Holmqvist  * substantial portion of the Covered Code or modification must reproduce the
680174267aSFredrik Holmqvist  * above Copyright Notice, and the following Disclaimer and Export Compliance
690174267aSFredrik Holmqvist  * provision in the documentation and/or other materials provided with the
700174267aSFredrik Holmqvist  * distribution.
710174267aSFredrik Holmqvist  *
720174267aSFredrik Holmqvist  * 3.4. Intel retains all right, title, and interest in and to the Original
730174267aSFredrik Holmqvist  * Intel Code.
740174267aSFredrik Holmqvist  *
750174267aSFredrik Holmqvist  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760174267aSFredrik Holmqvist  * Intel shall be used in advertising or otherwise to promote the sale, use or
770174267aSFredrik Holmqvist  * other dealings in products derived from or relating to the Covered Code
780174267aSFredrik Holmqvist  * without prior written authorization from Intel.
790174267aSFredrik Holmqvist  *
800174267aSFredrik Holmqvist  * 4. Disclaimer and Export Compliance
810174267aSFredrik Holmqvist  *
820174267aSFredrik Holmqvist  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830174267aSFredrik Holmqvist  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840174267aSFredrik Holmqvist  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850174267aSFredrik Holmqvist  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860174267aSFredrik Holmqvist  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870174267aSFredrik Holmqvist  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880174267aSFredrik Holmqvist  * PARTICULAR PURPOSE.
890174267aSFredrik Holmqvist  *
900174267aSFredrik Holmqvist  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910174267aSFredrik Holmqvist  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920174267aSFredrik Holmqvist  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930174267aSFredrik Holmqvist  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940174267aSFredrik Holmqvist  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950174267aSFredrik Holmqvist  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960174267aSFredrik Holmqvist  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970174267aSFredrik Holmqvist  * LIMITED REMEDY.
980174267aSFredrik Holmqvist  *
990174267aSFredrik Holmqvist  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000174267aSFredrik Holmqvist  * software or system incorporating such software without first obtaining any
1010174267aSFredrik Holmqvist  * required license or other approval from the U. S. Department of Commerce or
1020174267aSFredrik Holmqvist  * any other agency or department of the United States Government. In the
1030174267aSFredrik Holmqvist  * event Licensee exports any such software from the United States or
1040174267aSFredrik Holmqvist  * re-exports any such software from a foreign destination, Licensee shall
1050174267aSFredrik Holmqvist  * ensure that the distribution and export/re-export of the software is in
1060174267aSFredrik Holmqvist  * compliance with all laws, regulations, orders, or other restrictions of the
1070174267aSFredrik Holmqvist  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080174267aSFredrik Holmqvist  * any of its subsidiaries will export/re-export any technical data, process,
1090174267aSFredrik Holmqvist  * software, or service, directly or indirectly, to any country for which the
1100174267aSFredrik Holmqvist  * United States government or any agency thereof requires an export license,
1110174267aSFredrik Holmqvist  * other governmental approval, or letter of assurance, without first obtaining
1120174267aSFredrik Holmqvist  * such license, approval or letter.
1130174267aSFredrik Holmqvist  *
114ff2e2f81SFredrik Holmqvist  *****************************************************************************
115ff2e2f81SFredrik Holmqvist  *
116ff2e2f81SFredrik Holmqvist  * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist  * following license:
118ff2e2f81SFredrik Holmqvist  *
119ff2e2f81SFredrik Holmqvist  * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist  * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist  * are met:
122ff2e2f81SFredrik Holmqvist  * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist  *    notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist  *    without modification.
125ff2e2f81SFredrik Holmqvist  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist  *    substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist  *    ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist  *    including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist  *    binary redistribution.
130ff2e2f81SFredrik Holmqvist  * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist  *    of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist  *    from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist  *
134ff2e2f81SFredrik Holmqvist  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist  *
146ff2e2f81SFredrik Holmqvist  * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist  * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist  * Software Foundation.
149ff2e2f81SFredrik Holmqvist  *
1500174267aSFredrik Holmqvist  *****************************************************************************/
1510174267aSFredrik Holmqvist 
1520174267aSFredrik Holmqvist #include "acpi.h"
1530174267aSFredrik Holmqvist #include "accommon.h"
1540174267aSFredrik Holmqvist #include "acnamesp.h"
1550174267aSFredrik Holmqvist 
1560174267aSFredrik Holmqvist 
1570174267aSFredrik Holmqvist #define _COMPONENT          ACPI_UTILITIES
1580174267aSFredrik Holmqvist         ACPI_MODULE_NAME    ("utcopy")
1590174267aSFredrik Holmqvist 
1600174267aSFredrik Holmqvist /* Local prototypes */
1610174267aSFredrik Holmqvist 
1620174267aSFredrik Holmqvist static ACPI_STATUS
1630174267aSFredrik Holmqvist AcpiUtCopyIsimpleToEsimple (
1640174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *InternalObject,
1650174267aSFredrik Holmqvist     ACPI_OBJECT             *ExternalObject,
1660174267aSFredrik Holmqvist     UINT8                   *DataSpace,
1670174267aSFredrik Holmqvist     ACPI_SIZE               *BufferSpaceUsed);
1680174267aSFredrik Holmqvist 
1690174267aSFredrik Holmqvist static ACPI_STATUS
1700174267aSFredrik Holmqvist AcpiUtCopyIelementToIelement (
1710174267aSFredrik Holmqvist     UINT8                   ObjectType,
1720174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceObject,
1730174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State,
1740174267aSFredrik Holmqvist     void                    *Context);
1750174267aSFredrik Holmqvist 
1760174267aSFredrik Holmqvist static ACPI_STATUS
1770174267aSFredrik Holmqvist AcpiUtCopyIpackageToEpackage (
1780174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *InternalObject,
1790174267aSFredrik Holmqvist     UINT8                   *Buffer,
1800174267aSFredrik Holmqvist     ACPI_SIZE               *SpaceUsed);
1810174267aSFredrik Holmqvist 
1820174267aSFredrik Holmqvist static ACPI_STATUS
1830174267aSFredrik Holmqvist AcpiUtCopyEsimpleToIsimple(
1840174267aSFredrik Holmqvist     ACPI_OBJECT             *UserObj,
1850174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **ReturnObj);
1860174267aSFredrik Holmqvist 
1870174267aSFredrik Holmqvist static ACPI_STATUS
1880174267aSFredrik Holmqvist AcpiUtCopyEpackageToIpackage (
1890174267aSFredrik Holmqvist     ACPI_OBJECT             *ExternalObject,
1900174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **InternalObject);
1910174267aSFredrik Holmqvist 
1920174267aSFredrik Holmqvist static ACPI_STATUS
1930174267aSFredrik Holmqvist AcpiUtCopySimpleObject (
1940174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceDesc,
1950174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *DestDesc);
1960174267aSFredrik Holmqvist 
1970174267aSFredrik Holmqvist static ACPI_STATUS
1980174267aSFredrik Holmqvist AcpiUtCopyIelementToEelement (
1990174267aSFredrik Holmqvist     UINT8                   ObjectType,
2000174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceObject,
2010174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State,
2020174267aSFredrik Holmqvist     void                    *Context);
2030174267aSFredrik Holmqvist 
2040174267aSFredrik Holmqvist static ACPI_STATUS
2050174267aSFredrik Holmqvist AcpiUtCopyIpackageToIpackage (
2060174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceObj,
2070174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *DestObj,
2080174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState);
2090174267aSFredrik Holmqvist 
2100174267aSFredrik Holmqvist 
2110174267aSFredrik Holmqvist /*******************************************************************************
2120174267aSFredrik Holmqvist  *
2130174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyIsimpleToEsimple
2140174267aSFredrik Holmqvist  *
2150174267aSFredrik Holmqvist  * PARAMETERS:  InternalObject      - Source object to be copied
2160174267aSFredrik Holmqvist  *              ExternalObject      - Where to return the copied object
2170174267aSFredrik Holmqvist  *              DataSpace           - Where object data is returned (such as
2180174267aSFredrik Holmqvist  *                                    buffer and string data)
2190174267aSFredrik Holmqvist  *              BufferSpaceUsed     - Length of DataSpace that was used
2200174267aSFredrik Holmqvist  *
2210174267aSFredrik Holmqvist  * RETURN:      Status
2220174267aSFredrik Holmqvist  *
2230174267aSFredrik Holmqvist  * DESCRIPTION: This function is called to copy a simple internal object to
2240174267aSFredrik Holmqvist  *              an external object.
2250174267aSFredrik Holmqvist  *
2260174267aSFredrik Holmqvist  *              The DataSpace buffer is assumed to have sufficient space for
2270174267aSFredrik Holmqvist  *              the object.
2280174267aSFredrik Holmqvist  *
2290174267aSFredrik Holmqvist  ******************************************************************************/
2300174267aSFredrik Holmqvist 
2310174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtCopyIsimpleToEsimple(ACPI_OPERAND_OBJECT * InternalObject,ACPI_OBJECT * ExternalObject,UINT8 * DataSpace,ACPI_SIZE * BufferSpaceUsed)2320174267aSFredrik Holmqvist AcpiUtCopyIsimpleToEsimple (
2330174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *InternalObject,
2340174267aSFredrik Holmqvist     ACPI_OBJECT             *ExternalObject,
2350174267aSFredrik Holmqvist     UINT8                   *DataSpace,
2360174267aSFredrik Holmqvist     ACPI_SIZE               *BufferSpaceUsed)
2370174267aSFredrik Holmqvist {
2380174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
2390174267aSFredrik Holmqvist 
2400174267aSFredrik Holmqvist 
2410174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple);
2420174267aSFredrik Holmqvist 
2430174267aSFredrik Holmqvist 
2440174267aSFredrik Holmqvist     *BufferSpaceUsed = 0;
2450174267aSFredrik Holmqvist 
2460174267aSFredrik Holmqvist     /*
2470174267aSFredrik Holmqvist      * Check for NULL object case (could be an uninitialized
2480174267aSFredrik Holmqvist      * package element)
2490174267aSFredrik Holmqvist      */
2500174267aSFredrik Holmqvist     if (!InternalObject)
2510174267aSFredrik Holmqvist     {
2520174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_OK);
2530174267aSFredrik Holmqvist     }
2540174267aSFredrik Holmqvist 
2550174267aSFredrik Holmqvist     /* Always clear the external object */
2560174267aSFredrik Holmqvist 
257e226d1d0SFredrik Holmqvist     memset (ExternalObject, 0, sizeof (ACPI_OBJECT));
2580174267aSFredrik Holmqvist 
2590174267aSFredrik Holmqvist     /*
2600174267aSFredrik Holmqvist      * In general, the external object will be the same type as
2610174267aSFredrik Holmqvist      * the internal object
2620174267aSFredrik Holmqvist      */
2630174267aSFredrik Holmqvist     ExternalObject->Type = InternalObject->Common.Type;
2640174267aSFredrik Holmqvist 
2650174267aSFredrik Holmqvist     /* However, only a limited number of external types are supported */
2660174267aSFredrik Holmqvist 
2670174267aSFredrik Holmqvist     switch (InternalObject->Common.Type)
2680174267aSFredrik Holmqvist     {
2690174267aSFredrik Holmqvist     case ACPI_TYPE_STRING:
2700174267aSFredrik Holmqvist 
2710174267aSFredrik Holmqvist         ExternalObject->String.Pointer = (char *) DataSpace;
2720174267aSFredrik Holmqvist         ExternalObject->String.Length  = InternalObject->String.Length;
2730174267aSFredrik Holmqvist         *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
2740174267aSFredrik Holmqvist             (ACPI_SIZE) InternalObject->String.Length + 1);
2750174267aSFredrik Holmqvist 
276e226d1d0SFredrik Holmqvist         memcpy ((void *) DataSpace,
2770174267aSFredrik Holmqvist             (void *) InternalObject->String.Pointer,
2780174267aSFredrik Holmqvist             (ACPI_SIZE) InternalObject->String.Length + 1);
2790174267aSFredrik Holmqvist         break;
2800174267aSFredrik Holmqvist 
2810174267aSFredrik Holmqvist     case ACPI_TYPE_BUFFER:
2820174267aSFredrik Holmqvist 
2830174267aSFredrik Holmqvist         ExternalObject->Buffer.Pointer = DataSpace;
2840174267aSFredrik Holmqvist         ExternalObject->Buffer.Length  = InternalObject->Buffer.Length;
2850174267aSFredrik Holmqvist         *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
2860174267aSFredrik Holmqvist             InternalObject->String.Length);
2870174267aSFredrik Holmqvist 
288e226d1d0SFredrik Holmqvist         memcpy ((void *) DataSpace,
2890174267aSFredrik Holmqvist             (void *) InternalObject->Buffer.Pointer,
2900174267aSFredrik Holmqvist             InternalObject->Buffer.Length);
2910174267aSFredrik Holmqvist         break;
2920174267aSFredrik Holmqvist 
2930174267aSFredrik Holmqvist     case ACPI_TYPE_INTEGER:
2940174267aSFredrik Holmqvist 
2950174267aSFredrik Holmqvist         ExternalObject->Integer.Value = InternalObject->Integer.Value;
2960174267aSFredrik Holmqvist         break;
2970174267aSFredrik Holmqvist 
2980174267aSFredrik Holmqvist     case ACPI_TYPE_LOCAL_REFERENCE:
2990174267aSFredrik Holmqvist 
3000174267aSFredrik Holmqvist         /* This is an object reference. */
3010174267aSFredrik Holmqvist 
3020174267aSFredrik Holmqvist         switch (InternalObject->Reference.Class)
3030174267aSFredrik Holmqvist         {
3040174267aSFredrik Holmqvist         case ACPI_REFCLASS_NAME:
3050174267aSFredrik Holmqvist             /*
3060174267aSFredrik Holmqvist              * For namepath, return the object handle ("reference")
3070174267aSFredrik Holmqvist              * We are referring to the namespace node
3080174267aSFredrik Holmqvist              */
3090174267aSFredrik Holmqvist             ExternalObject->Reference.Handle =
3100174267aSFredrik Holmqvist                 InternalObject->Reference.Node;
3110174267aSFredrik Holmqvist             ExternalObject->Reference.ActualType =
3120174267aSFredrik Holmqvist                 AcpiNsGetType (InternalObject->Reference.Node);
3130174267aSFredrik Holmqvist             break;
3140174267aSFredrik Holmqvist 
3150174267aSFredrik Holmqvist         default:
3160174267aSFredrik Holmqvist 
3170174267aSFredrik Holmqvist             /* All other reference types are unsupported */
3180174267aSFredrik Holmqvist 
3190174267aSFredrik Holmqvist             return_ACPI_STATUS (AE_TYPE);
3200174267aSFredrik Holmqvist         }
3210174267aSFredrik Holmqvist         break;
3220174267aSFredrik Holmqvist 
3230174267aSFredrik Holmqvist     case ACPI_TYPE_PROCESSOR:
3240174267aSFredrik Holmqvist 
3250174267aSFredrik Holmqvist         ExternalObject->Processor.ProcId =
3260174267aSFredrik Holmqvist             InternalObject->Processor.ProcId;
3270174267aSFredrik Holmqvist         ExternalObject->Processor.PblkAddress =
3280174267aSFredrik Holmqvist             InternalObject->Processor.Address;
3290174267aSFredrik Holmqvist         ExternalObject->Processor.PblkLength =
3300174267aSFredrik Holmqvist             InternalObject->Processor.Length;
3310174267aSFredrik Holmqvist         break;
3320174267aSFredrik Holmqvist 
3330174267aSFredrik Holmqvist     case ACPI_TYPE_POWER:
3340174267aSFredrik Holmqvist 
3350174267aSFredrik Holmqvist         ExternalObject->PowerResource.SystemLevel =
3360174267aSFredrik Holmqvist             InternalObject->PowerResource.SystemLevel;
3370174267aSFredrik Holmqvist 
3380174267aSFredrik Holmqvist         ExternalObject->PowerResource.ResourceOrder =
3390174267aSFredrik Holmqvist             InternalObject->PowerResource.ResourceOrder;
3400174267aSFredrik Holmqvist         break;
3410174267aSFredrik Holmqvist 
3420174267aSFredrik Holmqvist     default:
3430174267aSFredrik Holmqvist         /*
3440174267aSFredrik Holmqvist          * There is no corresponding external object type
3450174267aSFredrik Holmqvist          */
3460174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO,
3470174267aSFredrik Holmqvist             "Unsupported object type, cannot convert to external object: %s",
3480174267aSFredrik Holmqvist             AcpiUtGetTypeName (InternalObject->Common.Type)));
3490174267aSFredrik Holmqvist 
3500174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_SUPPORT);
3510174267aSFredrik Holmqvist     }
3520174267aSFredrik Holmqvist 
3530174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
3540174267aSFredrik Holmqvist }
3550174267aSFredrik Holmqvist 
3560174267aSFredrik Holmqvist 
3570174267aSFredrik Holmqvist /*******************************************************************************
3580174267aSFredrik Holmqvist  *
3590174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyIelementToEelement
3600174267aSFredrik Holmqvist  *
3610174267aSFredrik Holmqvist  * PARAMETERS:  ACPI_PKG_CALLBACK
3620174267aSFredrik Holmqvist  *
3630174267aSFredrik Holmqvist  * RETURN:      Status
3640174267aSFredrik Holmqvist  *
3650174267aSFredrik Holmqvist  * DESCRIPTION: Copy one package element to another package element
3660174267aSFredrik Holmqvist  *
3670174267aSFredrik Holmqvist  ******************************************************************************/
3680174267aSFredrik Holmqvist 
3690174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtCopyIelementToEelement(UINT8 ObjectType,ACPI_OPERAND_OBJECT * SourceObject,ACPI_GENERIC_STATE * State,void * Context)3700174267aSFredrik Holmqvist AcpiUtCopyIelementToEelement (
3710174267aSFredrik Holmqvist     UINT8                   ObjectType,
3720174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceObject,
3730174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State,
3740174267aSFredrik Holmqvist     void                    *Context)
3750174267aSFredrik Holmqvist {
3760174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
3770174267aSFredrik Holmqvist     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
3780174267aSFredrik Holmqvist     ACPI_SIZE               ObjectSpace;
3790174267aSFredrik Holmqvist     UINT32                  ThisIndex;
3800174267aSFredrik Holmqvist     ACPI_OBJECT             *TargetObject;
3810174267aSFredrik Holmqvist 
3820174267aSFredrik Holmqvist 
3830174267aSFredrik Holmqvist     ACPI_FUNCTION_ENTRY ();
3840174267aSFredrik Holmqvist 
3850174267aSFredrik Holmqvist 
3860174267aSFredrik Holmqvist     ThisIndex = State->Pkg.Index;
387b64e8511SFredrik Holmqvist     TargetObject = (ACPI_OBJECT *) &((ACPI_OBJECT *)
388b64e8511SFredrik Holmqvist         (State->Pkg.DestObject))->Package.Elements[ThisIndex];
3890174267aSFredrik Holmqvist 
3900174267aSFredrik Holmqvist     switch (ObjectType)
3910174267aSFredrik Holmqvist     {
3920174267aSFredrik Holmqvist     case ACPI_COPY_TYPE_SIMPLE:
3930174267aSFredrik Holmqvist         /*
3940174267aSFredrik Holmqvist          * This is a simple or null object
3950174267aSFredrik Holmqvist          */
3960174267aSFredrik Holmqvist         Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
3970174267aSFredrik Holmqvist             TargetObject, Info->FreeSpace, &ObjectSpace);
3980174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
3990174267aSFredrik Holmqvist         {
4000174267aSFredrik Holmqvist             return (Status);
4010174267aSFredrik Holmqvist         }
4020174267aSFredrik Holmqvist         break;
4030174267aSFredrik Holmqvist 
4040174267aSFredrik Holmqvist     case ACPI_COPY_TYPE_PACKAGE:
4050174267aSFredrik Holmqvist         /*
4060174267aSFredrik Holmqvist          * Build the package object
4070174267aSFredrik Holmqvist          */
4080174267aSFredrik Holmqvist         TargetObject->Type = ACPI_TYPE_PACKAGE;
4090174267aSFredrik Holmqvist         TargetObject->Package.Count = SourceObject->Package.Count;
4100174267aSFredrik Holmqvist         TargetObject->Package.Elements =
4110174267aSFredrik Holmqvist             ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);
4120174267aSFredrik Holmqvist 
4130174267aSFredrik Holmqvist         /*
4140174267aSFredrik Holmqvist          * Pass the new package object back to the package walk routine
4150174267aSFredrik Holmqvist          */
4160174267aSFredrik Holmqvist         State->Pkg.ThisTargetObj = TargetObject;
4170174267aSFredrik Holmqvist 
4180174267aSFredrik Holmqvist         /*
4190174267aSFredrik Holmqvist          * Save space for the array of objects (Package elements)
4200174267aSFredrik Holmqvist          * update the buffer length counter
4210174267aSFredrik Holmqvist          */
4220174267aSFredrik Holmqvist         ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (
4230174267aSFredrik Holmqvist             (ACPI_SIZE) TargetObject->Package.Count *
4240174267aSFredrik Holmqvist             sizeof (ACPI_OBJECT));
4250174267aSFredrik Holmqvist         break;
4260174267aSFredrik Holmqvist 
4270174267aSFredrik Holmqvist     default:
428c70258b7SJérôme Duval 
4290174267aSFredrik Holmqvist         return (AE_BAD_PARAMETER);
4300174267aSFredrik Holmqvist     }
4310174267aSFredrik Holmqvist 
4320174267aSFredrik Holmqvist     Info->FreeSpace += ObjectSpace;
4330174267aSFredrik Holmqvist     Info->Length += ObjectSpace;
4340174267aSFredrik Holmqvist     return (Status);
4350174267aSFredrik Holmqvist }
4360174267aSFredrik Holmqvist 
4370174267aSFredrik Holmqvist 
4380174267aSFredrik Holmqvist /*******************************************************************************
4390174267aSFredrik Holmqvist  *
4400174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyIpackageToEpackage
4410174267aSFredrik Holmqvist  *
4420174267aSFredrik Holmqvist  * PARAMETERS:  InternalObject      - Pointer to the object we are returning
4430174267aSFredrik Holmqvist  *              Buffer              - Where the object is returned
4440174267aSFredrik Holmqvist  *              SpaceUsed           - Where the object length is returned
4450174267aSFredrik Holmqvist  *
4460174267aSFredrik Holmqvist  * RETURN:      Status
4470174267aSFredrik Holmqvist  *
4480174267aSFredrik Holmqvist  * DESCRIPTION: This function is called to place a package object in a user
4490174267aSFredrik Holmqvist  *              buffer. A package object by definition contains other objects.
4500174267aSFredrik Holmqvist  *
4510174267aSFredrik Holmqvist  *              The buffer is assumed to have sufficient space for the object.
4520174267aSFredrik Holmqvist  *              The caller must have verified the buffer length needed using
4530174267aSFredrik Holmqvist  *              the AcpiUtGetObjectSize function before calling this function.
4540174267aSFredrik Holmqvist  *
4550174267aSFredrik Holmqvist  ******************************************************************************/
4560174267aSFredrik Holmqvist 
4570174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtCopyIpackageToEpackage(ACPI_OPERAND_OBJECT * InternalObject,UINT8 * Buffer,ACPI_SIZE * SpaceUsed)4580174267aSFredrik Holmqvist AcpiUtCopyIpackageToEpackage (
4590174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *InternalObject,
4600174267aSFredrik Holmqvist     UINT8                   *Buffer,
4610174267aSFredrik Holmqvist     ACPI_SIZE               *SpaceUsed)
4620174267aSFredrik Holmqvist {
4630174267aSFredrik Holmqvist     ACPI_OBJECT             *ExternalObject;
4640174267aSFredrik Holmqvist     ACPI_STATUS             Status;
4650174267aSFredrik Holmqvist     ACPI_PKG_INFO           Info;
4660174267aSFredrik Holmqvist 
4670174267aSFredrik Holmqvist 
4680174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage);
4690174267aSFredrik Holmqvist 
4700174267aSFredrik Holmqvist 
4710174267aSFredrik Holmqvist     /*
4720174267aSFredrik Holmqvist      * First package at head of the buffer
4730174267aSFredrik Holmqvist      */
4740174267aSFredrik Holmqvist     ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);
4750174267aSFredrik Holmqvist 
4760174267aSFredrik Holmqvist     /*
4770174267aSFredrik Holmqvist      * Free space begins right after the first package
4780174267aSFredrik Holmqvist      */
4790174267aSFredrik Holmqvist     Info.Length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
480b64e8511SFredrik Holmqvist     Info.FreeSpace = Buffer +
481b64e8511SFredrik Holmqvist         ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
4820174267aSFredrik Holmqvist     Info.ObjectSpace = 0;
4830174267aSFredrik Holmqvist     Info.NumPackages = 1;
4840174267aSFredrik Holmqvist 
4850174267aSFredrik Holmqvist     ExternalObject->Type = InternalObject->Common.Type;
4860174267aSFredrik Holmqvist     ExternalObject->Package.Count = InternalObject->Package.Count;
487b64e8511SFredrik Holmqvist     ExternalObject->Package.Elements =
488b64e8511SFredrik Holmqvist         ACPI_CAST_PTR (ACPI_OBJECT, Info.FreeSpace);
4890174267aSFredrik Holmqvist 
4900174267aSFredrik Holmqvist     /*
4910174267aSFredrik Holmqvist      * Leave room for an array of ACPI_OBJECTS in the buffer
4920174267aSFredrik Holmqvist      * and move the free space past it
4930174267aSFredrik Holmqvist      */
4940174267aSFredrik Holmqvist     Info.Length += (ACPI_SIZE) ExternalObject->Package.Count *
4950174267aSFredrik Holmqvist         ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
4960174267aSFredrik Holmqvist     Info.FreeSpace += ExternalObject->Package.Count *
4970174267aSFredrik Holmqvist         ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
4980174267aSFredrik Holmqvist 
4990174267aSFredrik Holmqvist     Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
5000174267aSFredrik Holmqvist         AcpiUtCopyIelementToEelement, &Info);
5010174267aSFredrik Holmqvist 
5020174267aSFredrik Holmqvist     *SpaceUsed = Info.Length;
5030174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
5040174267aSFredrik Holmqvist }
5050174267aSFredrik Holmqvist 
5060174267aSFredrik Holmqvist 
5070174267aSFredrik Holmqvist /*******************************************************************************
5080174267aSFredrik Holmqvist  *
5090174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyIobjectToEobject
5100174267aSFredrik Holmqvist  *
5110174267aSFredrik Holmqvist  * PARAMETERS:  InternalObject      - The internal object to be converted
5120174267aSFredrik Holmqvist  *              RetBuffer           - Where the object is returned
5130174267aSFredrik Holmqvist  *
5140174267aSFredrik Holmqvist  * RETURN:      Status
5150174267aSFredrik Holmqvist  *
5160174267aSFredrik Holmqvist  * DESCRIPTION: This function is called to build an API object to be returned
5170174267aSFredrik Holmqvist  *              to the caller.
5180174267aSFredrik Holmqvist  *
5190174267aSFredrik Holmqvist  ******************************************************************************/
5200174267aSFredrik Holmqvist 
5210174267aSFredrik Holmqvist ACPI_STATUS
AcpiUtCopyIobjectToEobject(ACPI_OPERAND_OBJECT * InternalObject,ACPI_BUFFER * RetBuffer)5220174267aSFredrik Holmqvist AcpiUtCopyIobjectToEobject (
5230174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *InternalObject,
5240174267aSFredrik Holmqvist     ACPI_BUFFER             *RetBuffer)
5250174267aSFredrik Holmqvist {
5260174267aSFredrik Holmqvist     ACPI_STATUS             Status;
5270174267aSFredrik Holmqvist 
5280174267aSFredrik Holmqvist 
5290174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject);
5300174267aSFredrik Holmqvist 
5310174267aSFredrik Holmqvist 
5320174267aSFredrik Holmqvist     if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)
5330174267aSFredrik Holmqvist     {
5340174267aSFredrik Holmqvist         /*
5350174267aSFredrik Holmqvist          * Package object:  Copy all subobjects (including
5360174267aSFredrik Holmqvist          * nested packages)
5370174267aSFredrik Holmqvist          */
5380174267aSFredrik Holmqvist         Status = AcpiUtCopyIpackageToEpackage (InternalObject,
5390174267aSFredrik Holmqvist             RetBuffer->Pointer, &RetBuffer->Length);
5400174267aSFredrik Holmqvist     }
5410174267aSFredrik Holmqvist     else
5420174267aSFredrik Holmqvist     {
5430174267aSFredrik Holmqvist         /*
5440174267aSFredrik Holmqvist          * Build a simple object (no nested objects)
5450174267aSFredrik Holmqvist          */
5460174267aSFredrik Holmqvist         Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
5470174267aSFredrik Holmqvist             ACPI_CAST_PTR (ACPI_OBJECT, RetBuffer->Pointer),
5480174267aSFredrik Holmqvist             ACPI_ADD_PTR (UINT8, RetBuffer->Pointer,
5490174267aSFredrik Holmqvist                 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
5500174267aSFredrik Holmqvist             &RetBuffer->Length);
5510174267aSFredrik Holmqvist         /*
5520174267aSFredrik Holmqvist          * build simple does not include the object size in the length
5530174267aSFredrik Holmqvist          * so we add it in here
5540174267aSFredrik Holmqvist          */
5550174267aSFredrik Holmqvist         RetBuffer->Length += sizeof (ACPI_OBJECT);
5560174267aSFredrik Holmqvist     }
5570174267aSFredrik Holmqvist 
5580174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
5590174267aSFredrik Holmqvist }
5600174267aSFredrik Holmqvist 
5610174267aSFredrik Holmqvist 
5620174267aSFredrik Holmqvist /*******************************************************************************
5630174267aSFredrik Holmqvist  *
5640174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyEsimpleToIsimple
5650174267aSFredrik Holmqvist  *
5660174267aSFredrik Holmqvist  * PARAMETERS:  ExternalObject      - The external object to be converted
5670174267aSFredrik Holmqvist  *              RetInternalObject   - Where the internal object is returned
5680174267aSFredrik Holmqvist  *
5690174267aSFredrik Holmqvist  * RETURN:      Status
5700174267aSFredrik Holmqvist  *
5710174267aSFredrik Holmqvist  * DESCRIPTION: This function copies an external object to an internal one.
5720174267aSFredrik Holmqvist  *              NOTE: Pointers can be copied, we don't need to copy data.
5730174267aSFredrik Holmqvist  *              (The pointers have to be valid in our address space no matter
5740174267aSFredrik Holmqvist  *              what we do with them!)
5750174267aSFredrik Holmqvist  *
5760174267aSFredrik Holmqvist  ******************************************************************************/
5770174267aSFredrik Holmqvist 
5780174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtCopyEsimpleToIsimple(ACPI_OBJECT * ExternalObject,ACPI_OPERAND_OBJECT ** RetInternalObject)5790174267aSFredrik Holmqvist AcpiUtCopyEsimpleToIsimple (
5800174267aSFredrik Holmqvist     ACPI_OBJECT             *ExternalObject,
5810174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **RetInternalObject)
5820174267aSFredrik Holmqvist {
5830174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *InternalObject;
5840174267aSFredrik Holmqvist 
5850174267aSFredrik Holmqvist 
5860174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple);
5870174267aSFredrik Holmqvist 
5880174267aSFredrik Holmqvist 
5890174267aSFredrik Holmqvist     /*
5900174267aSFredrik Holmqvist      * Simple types supported are: String, Buffer, Integer
5910174267aSFredrik Holmqvist      */
5920174267aSFredrik Holmqvist     switch (ExternalObject->Type)
5930174267aSFredrik Holmqvist     {
5940174267aSFredrik Holmqvist     case ACPI_TYPE_STRING:
5950174267aSFredrik Holmqvist     case ACPI_TYPE_BUFFER:
5960174267aSFredrik Holmqvist     case ACPI_TYPE_INTEGER:
5970174267aSFredrik Holmqvist     case ACPI_TYPE_LOCAL_REFERENCE:
5980174267aSFredrik Holmqvist 
5990174267aSFredrik Holmqvist         InternalObject = AcpiUtCreateInternalObject (
6000174267aSFredrik Holmqvist             (UINT8) ExternalObject->Type);
6010174267aSFredrik Holmqvist         if (!InternalObject)
6020174267aSFredrik Holmqvist         {
6030174267aSFredrik Holmqvist             return_ACPI_STATUS (AE_NO_MEMORY);
6040174267aSFredrik Holmqvist         }
6050174267aSFredrik Holmqvist         break;
6060174267aSFredrik Holmqvist 
6070174267aSFredrik Holmqvist     case ACPI_TYPE_ANY: /* This is the case for a NULL object */
6080174267aSFredrik Holmqvist 
6090174267aSFredrik Holmqvist         *RetInternalObject = NULL;
6100174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_OK);
6110174267aSFredrik Holmqvist 
6120174267aSFredrik Holmqvist     default:
613c70258b7SJérôme Duval 
6140174267aSFredrik Holmqvist         /* All other types are not supported */
6150174267aSFredrik Holmqvist 
6160174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO,
6170174267aSFredrik Holmqvist             "Unsupported object type, cannot convert to internal object: %s",
6180174267aSFredrik Holmqvist             AcpiUtGetTypeName (ExternalObject->Type)));
6190174267aSFredrik Holmqvist 
6200174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_SUPPORT);
6210174267aSFredrik Holmqvist     }
6220174267aSFredrik Holmqvist 
6230174267aSFredrik Holmqvist 
6240174267aSFredrik Holmqvist     /* Must COPY string and buffer contents */
6250174267aSFredrik Holmqvist 
6260174267aSFredrik Holmqvist     switch (ExternalObject->Type)
6270174267aSFredrik Holmqvist     {
6280174267aSFredrik Holmqvist     case ACPI_TYPE_STRING:
6290174267aSFredrik Holmqvist 
6300174267aSFredrik Holmqvist         InternalObject->String.Pointer =
6310174267aSFredrik Holmqvist             ACPI_ALLOCATE_ZEROED ((ACPI_SIZE)
6320174267aSFredrik Holmqvist                 ExternalObject->String.Length + 1);
6330174267aSFredrik Holmqvist 
6340174267aSFredrik Holmqvist         if (!InternalObject->String.Pointer)
6350174267aSFredrik Holmqvist         {
6360174267aSFredrik Holmqvist             goto ErrorExit;
6370174267aSFredrik Holmqvist         }
6380174267aSFredrik Holmqvist 
639e226d1d0SFredrik Holmqvist         memcpy (InternalObject->String.Pointer,
6400174267aSFredrik Holmqvist             ExternalObject->String.Pointer,
6410174267aSFredrik Holmqvist             ExternalObject->String.Length);
6420174267aSFredrik Holmqvist 
6430174267aSFredrik Holmqvist         InternalObject->String.Length = ExternalObject->String.Length;
6440174267aSFredrik Holmqvist         break;
6450174267aSFredrik Holmqvist 
6460174267aSFredrik Holmqvist     case ACPI_TYPE_BUFFER:
6470174267aSFredrik Holmqvist 
6480174267aSFredrik Holmqvist         InternalObject->Buffer.Pointer =
6490174267aSFredrik Holmqvist             ACPI_ALLOCATE_ZEROED (ExternalObject->Buffer.Length);
6500174267aSFredrik Holmqvist         if (!InternalObject->Buffer.Pointer)
6510174267aSFredrik Holmqvist         {
6520174267aSFredrik Holmqvist             goto ErrorExit;
6530174267aSFredrik Holmqvist         }
6540174267aSFredrik Holmqvist 
655e226d1d0SFredrik Holmqvist         memcpy (InternalObject->Buffer.Pointer,
6560174267aSFredrik Holmqvist             ExternalObject->Buffer.Pointer,
6570174267aSFredrik Holmqvist             ExternalObject->Buffer.Length);
6580174267aSFredrik Holmqvist 
6590174267aSFredrik Holmqvist         InternalObject->Buffer.Length = ExternalObject->Buffer.Length;
6600174267aSFredrik Holmqvist 
6610174267aSFredrik Holmqvist         /* Mark buffer data valid */
6620174267aSFredrik Holmqvist 
6630174267aSFredrik Holmqvist         InternalObject->Buffer.Flags |= AOPOBJ_DATA_VALID;
6640174267aSFredrik Holmqvist         break;
6650174267aSFredrik Holmqvist 
6660174267aSFredrik Holmqvist     case ACPI_TYPE_INTEGER:
6670174267aSFredrik Holmqvist 
6680174267aSFredrik Holmqvist         InternalObject->Integer.Value = ExternalObject->Integer.Value;
6690174267aSFredrik Holmqvist         break;
6700174267aSFredrik Holmqvist 
6710174267aSFredrik Holmqvist     case ACPI_TYPE_LOCAL_REFERENCE:
6720174267aSFredrik Holmqvist 
673ad5bbfb8SFredrik Holmqvist         /* An incoming reference is defined to be a namespace node */
6740174267aSFredrik Holmqvist 
675ad5bbfb8SFredrik Holmqvist         InternalObject->Reference.Class = ACPI_REFCLASS_REFOF;
676ad5bbfb8SFredrik Holmqvist         InternalObject->Reference.Object = ExternalObject->Reference.Handle;
6770174267aSFredrik Holmqvist         break;
6780174267aSFredrik Holmqvist 
6790174267aSFredrik Holmqvist     default:
680c70258b7SJérôme Duval 
6810174267aSFredrik Holmqvist         /* Other types can't get here */
682c70258b7SJérôme Duval 
6830174267aSFredrik Holmqvist         break;
6840174267aSFredrik Holmqvist     }
6850174267aSFredrik Holmqvist 
6860174267aSFredrik Holmqvist     *RetInternalObject = InternalObject;
6870174267aSFredrik Holmqvist     return_ACPI_STATUS (AE_OK);
6880174267aSFredrik Holmqvist 
6890174267aSFredrik Holmqvist 
6900174267aSFredrik Holmqvist ErrorExit:
6910174267aSFredrik Holmqvist     AcpiUtRemoveReference (InternalObject);
6920174267aSFredrik Holmqvist     return_ACPI_STATUS (AE_NO_MEMORY);
6930174267aSFredrik Holmqvist }
6940174267aSFredrik Holmqvist 
6950174267aSFredrik Holmqvist 
6960174267aSFredrik Holmqvist /*******************************************************************************
6970174267aSFredrik Holmqvist  *
6980174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyEpackageToIpackage
6990174267aSFredrik Holmqvist  *
7000174267aSFredrik Holmqvist  * PARAMETERS:  ExternalObject      - The external object to be converted
7010174267aSFredrik Holmqvist  *              InternalObject      - Where the internal object is returned
7020174267aSFredrik Holmqvist  *
7030174267aSFredrik Holmqvist  * RETURN:      Status
7040174267aSFredrik Holmqvist  *
7050174267aSFredrik Holmqvist  * DESCRIPTION: Copy an external package object to an internal package.
7060174267aSFredrik Holmqvist  *              Handles nested packages.
7070174267aSFredrik Holmqvist  *
7080174267aSFredrik Holmqvist  ******************************************************************************/
7090174267aSFredrik Holmqvist 
7100174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtCopyEpackageToIpackage(ACPI_OBJECT * ExternalObject,ACPI_OPERAND_OBJECT ** InternalObject)7110174267aSFredrik Holmqvist AcpiUtCopyEpackageToIpackage (
7120174267aSFredrik Holmqvist     ACPI_OBJECT             *ExternalObject,
7130174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **InternalObject)
7140174267aSFredrik Holmqvist {
7150174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
7160174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *PackageObject;
7170174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **PackageElements;
7180174267aSFredrik Holmqvist     UINT32                  i;
7190174267aSFredrik Holmqvist 
7200174267aSFredrik Holmqvist 
7210174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage);
7220174267aSFredrik Holmqvist 
7230174267aSFredrik Holmqvist 
7240174267aSFredrik Holmqvist     /* Create the package object */
7250174267aSFredrik Holmqvist 
726b64e8511SFredrik Holmqvist     PackageObject = AcpiUtCreatePackageObject (
727b64e8511SFredrik Holmqvist         ExternalObject->Package.Count);
7280174267aSFredrik Holmqvist     if (!PackageObject)
7290174267aSFredrik Holmqvist     {
7300174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_NO_MEMORY);
7310174267aSFredrik Holmqvist     }
7320174267aSFredrik Holmqvist 
7330174267aSFredrik Holmqvist     PackageElements = PackageObject->Package.Elements;
7340174267aSFredrik Holmqvist 
7350174267aSFredrik Holmqvist     /*
736b64e8511SFredrik Holmqvist      * Recursive implementation. Probably ok, since nested external
737b64e8511SFredrik Holmqvist      * packages as parameters should be very rare.
7380174267aSFredrik Holmqvist      */
7390174267aSFredrik Holmqvist     for (i = 0; i < ExternalObject->Package.Count; i++)
7400174267aSFredrik Holmqvist     {
7410174267aSFredrik Holmqvist         Status = AcpiUtCopyEobjectToIobject (
7420174267aSFredrik Holmqvist             &ExternalObject->Package.Elements[i],
7430174267aSFredrik Holmqvist             &PackageElements[i]);
7440174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
7450174267aSFredrik Holmqvist         {
7460174267aSFredrik Holmqvist             /* Truncate package and delete it */
7470174267aSFredrik Holmqvist 
7480174267aSFredrik Holmqvist             PackageObject->Package.Count = i;
7490174267aSFredrik Holmqvist             PackageElements[i] = NULL;
7500174267aSFredrik Holmqvist             AcpiUtRemoveReference (PackageObject);
7510174267aSFredrik Holmqvist             return_ACPI_STATUS (Status);
7520174267aSFredrik Holmqvist         }
7530174267aSFredrik Holmqvist     }
7540174267aSFredrik Holmqvist 
7550174267aSFredrik Holmqvist     /* Mark package data valid */
7560174267aSFredrik Holmqvist 
7570174267aSFredrik Holmqvist     PackageObject->Package.Flags |= AOPOBJ_DATA_VALID;
7580174267aSFredrik Holmqvist 
7590174267aSFredrik Holmqvist     *InternalObject = PackageObject;
7600174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
7610174267aSFredrik Holmqvist }
7620174267aSFredrik Holmqvist 
7630174267aSFredrik Holmqvist 
7640174267aSFredrik Holmqvist /*******************************************************************************
7650174267aSFredrik Holmqvist  *
7660174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyEobjectToIobject
7670174267aSFredrik Holmqvist  *
7680174267aSFredrik Holmqvist  * PARAMETERS:  ExternalObject      - The external object to be converted
7690174267aSFredrik Holmqvist  *              InternalObject      - Where the internal object is returned
7700174267aSFredrik Holmqvist  *
7710174267aSFredrik Holmqvist  * RETURN:      Status
7720174267aSFredrik Holmqvist  *
7730174267aSFredrik Holmqvist  * DESCRIPTION: Converts an external object to an internal object.
7740174267aSFredrik Holmqvist  *
7750174267aSFredrik Holmqvist  ******************************************************************************/
7760174267aSFredrik Holmqvist 
7770174267aSFredrik Holmqvist ACPI_STATUS
AcpiUtCopyEobjectToIobject(ACPI_OBJECT * ExternalObject,ACPI_OPERAND_OBJECT ** InternalObject)7780174267aSFredrik Holmqvist AcpiUtCopyEobjectToIobject (
7790174267aSFredrik Holmqvist     ACPI_OBJECT             *ExternalObject,
7800174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **InternalObject)
7810174267aSFredrik Holmqvist {
7820174267aSFredrik Holmqvist     ACPI_STATUS             Status;
7830174267aSFredrik Holmqvist 
7840174267aSFredrik Holmqvist 
7850174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject);
7860174267aSFredrik Holmqvist 
7870174267aSFredrik Holmqvist 
7880174267aSFredrik Holmqvist     if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
7890174267aSFredrik Holmqvist     {
790b64e8511SFredrik Holmqvist         Status = AcpiUtCopyEpackageToIpackage (
791b64e8511SFredrik Holmqvist             ExternalObject, InternalObject);
7920174267aSFredrik Holmqvist     }
7930174267aSFredrik Holmqvist     else
7940174267aSFredrik Holmqvist     {
7950174267aSFredrik Holmqvist         /*
7960174267aSFredrik Holmqvist          * Build a simple object (no nested objects)
7970174267aSFredrik Holmqvist          */
798b64e8511SFredrik Holmqvist         Status = AcpiUtCopyEsimpleToIsimple (ExternalObject,
799b64e8511SFredrik Holmqvist             InternalObject);
8000174267aSFredrik Holmqvist     }
8010174267aSFredrik Holmqvist 
8020174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
8030174267aSFredrik Holmqvist }
8040174267aSFredrik Holmqvist 
8050174267aSFredrik Holmqvist 
8060174267aSFredrik Holmqvist /*******************************************************************************
8070174267aSFredrik Holmqvist  *
8080174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopySimpleObject
8090174267aSFredrik Holmqvist  *
8100174267aSFredrik Holmqvist  * PARAMETERS:  SourceDesc          - The internal object to be copied
8110174267aSFredrik Holmqvist  *              DestDesc            - New target object
8120174267aSFredrik Holmqvist  *
8130174267aSFredrik Holmqvist  * RETURN:      Status
8140174267aSFredrik Holmqvist  *
8150174267aSFredrik Holmqvist  * DESCRIPTION: Simple copy of one internal object to another. Reference count
8160174267aSFredrik Holmqvist  *              of the destination object is preserved.
8170174267aSFredrik Holmqvist  *
8180174267aSFredrik Holmqvist  ******************************************************************************/
8190174267aSFredrik Holmqvist 
8200174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtCopySimpleObject(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_OPERAND_OBJECT * DestDesc)8210174267aSFredrik Holmqvist AcpiUtCopySimpleObject (
8220174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceDesc,
8230174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *DestDesc)
8240174267aSFredrik Holmqvist {
8250174267aSFredrik Holmqvist     UINT16                  ReferenceCount;
8260174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *NextObject;
8270174267aSFredrik Holmqvist     ACPI_STATUS             Status;
8280174267aSFredrik Holmqvist     ACPI_SIZE               CopySize;
8290174267aSFredrik Holmqvist 
8300174267aSFredrik Holmqvist 
8310174267aSFredrik Holmqvist     /* Save fields from destination that we don't want to overwrite */
8320174267aSFredrik Holmqvist 
8330174267aSFredrik Holmqvist     ReferenceCount = DestDesc->Common.ReferenceCount;
8340174267aSFredrik Holmqvist     NextObject = DestDesc->Common.NextObject;
8350174267aSFredrik Holmqvist 
8360174267aSFredrik Holmqvist     /*
8370174267aSFredrik Holmqvist      * Copy the entire source object over the destination object.
8380174267aSFredrik Holmqvist      * Note: Source can be either an operand object or namespace node.
8390174267aSFredrik Holmqvist      */
8400174267aSFredrik Holmqvist     CopySize = sizeof (ACPI_OPERAND_OBJECT);
8410174267aSFredrik Holmqvist     if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
8420174267aSFredrik Holmqvist     {
8430174267aSFredrik Holmqvist         CopySize = sizeof (ACPI_NAMESPACE_NODE);
8440174267aSFredrik Holmqvist     }
8450174267aSFredrik Holmqvist 
846e226d1d0SFredrik Holmqvist     memcpy (ACPI_CAST_PTR (char, DestDesc),
8470174267aSFredrik Holmqvist         ACPI_CAST_PTR (char, SourceDesc), CopySize);
8480174267aSFredrik Holmqvist 
8490174267aSFredrik Holmqvist     /* Restore the saved fields */
8500174267aSFredrik Holmqvist 
8510174267aSFredrik Holmqvist     DestDesc->Common.ReferenceCount = ReferenceCount;
8520174267aSFredrik Holmqvist     DestDesc->Common.NextObject = NextObject;
8530174267aSFredrik Holmqvist 
8540174267aSFredrik Holmqvist     /* New object is not static, regardless of source */
8550174267aSFredrik Holmqvist 
8560174267aSFredrik Holmqvist     DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
8570174267aSFredrik Holmqvist 
8580174267aSFredrik Holmqvist     /* Handle the objects with extra data */
8590174267aSFredrik Holmqvist 
8600174267aSFredrik Holmqvist     switch (DestDesc->Common.Type)
8610174267aSFredrik Holmqvist     {
8620174267aSFredrik Holmqvist     case ACPI_TYPE_BUFFER:
8630174267aSFredrik Holmqvist         /*
8640174267aSFredrik Holmqvist          * Allocate and copy the actual buffer if and only if:
8650174267aSFredrik Holmqvist          * 1) There is a valid buffer pointer
8660174267aSFredrik Holmqvist          * 2) The buffer has a length > 0
8670174267aSFredrik Holmqvist          */
8680174267aSFredrik Holmqvist         if ((SourceDesc->Buffer.Pointer) &&
8690174267aSFredrik Holmqvist             (SourceDesc->Buffer.Length))
8700174267aSFredrik Holmqvist         {
8710174267aSFredrik Holmqvist             DestDesc->Buffer.Pointer =
8720174267aSFredrik Holmqvist                 ACPI_ALLOCATE (SourceDesc->Buffer.Length);
8730174267aSFredrik Holmqvist             if (!DestDesc->Buffer.Pointer)
8740174267aSFredrik Holmqvist             {
8750174267aSFredrik Holmqvist                 return (AE_NO_MEMORY);
8760174267aSFredrik Holmqvist             }
8770174267aSFredrik Holmqvist 
8780174267aSFredrik Holmqvist             /* Copy the actual buffer data */
8790174267aSFredrik Holmqvist 
880e226d1d0SFredrik Holmqvist             memcpy (DestDesc->Buffer.Pointer,
8810174267aSFredrik Holmqvist                 SourceDesc->Buffer.Pointer, SourceDesc->Buffer.Length);
8820174267aSFredrik Holmqvist         }
8830174267aSFredrik Holmqvist         break;
8840174267aSFredrik Holmqvist 
8850174267aSFredrik Holmqvist     case ACPI_TYPE_STRING:
8860174267aSFredrik Holmqvist         /*
8870174267aSFredrik Holmqvist          * Allocate and copy the actual string if and only if:
8880174267aSFredrik Holmqvist          * 1) There is a valid string pointer
8890174267aSFredrik Holmqvist          * (Pointer to a NULL string is allowed)
8900174267aSFredrik Holmqvist          */
8910174267aSFredrik Holmqvist         if (SourceDesc->String.Pointer)
8920174267aSFredrik Holmqvist         {
8930174267aSFredrik Holmqvist             DestDesc->String.Pointer =
8940174267aSFredrik Holmqvist                 ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1);
8950174267aSFredrik Holmqvist             if (!DestDesc->String.Pointer)
8960174267aSFredrik Holmqvist             {
8970174267aSFredrik Holmqvist                 return (AE_NO_MEMORY);
8980174267aSFredrik Holmqvist             }
8990174267aSFredrik Holmqvist 
9000174267aSFredrik Holmqvist             /* Copy the actual string data */
9010174267aSFredrik Holmqvist 
902e226d1d0SFredrik Holmqvist             memcpy (DestDesc->String.Pointer, SourceDesc->String.Pointer,
9030174267aSFredrik Holmqvist                 (ACPI_SIZE) SourceDesc->String.Length + 1);
9040174267aSFredrik Holmqvist         }
9050174267aSFredrik Holmqvist         break;
9060174267aSFredrik Holmqvist 
9070174267aSFredrik Holmqvist     case ACPI_TYPE_LOCAL_REFERENCE:
9080174267aSFredrik Holmqvist         /*
9090174267aSFredrik Holmqvist          * We copied the reference object, so we now must add a reference
9100174267aSFredrik Holmqvist          * to the object pointed to by the reference
9110174267aSFredrik Holmqvist          *
9120174267aSFredrik Holmqvist          * DDBHandle reference (from Load/LoadTable) is a special reference,
9130174267aSFredrik Holmqvist          * it does not have a Reference.Object, so does not need to
9140174267aSFredrik Holmqvist          * increase the reference count
9150174267aSFredrik Holmqvist          */
9160174267aSFredrik Holmqvist         if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
9170174267aSFredrik Holmqvist         {
9180174267aSFredrik Holmqvist             break;
9190174267aSFredrik Holmqvist         }
9200174267aSFredrik Holmqvist 
9210174267aSFredrik Holmqvist         AcpiUtAddReference (SourceDesc->Reference.Object);
9220174267aSFredrik Holmqvist         break;
9230174267aSFredrik Holmqvist 
9240174267aSFredrik Holmqvist     case ACPI_TYPE_REGION:
9250174267aSFredrik Holmqvist         /*
9260174267aSFredrik Holmqvist          * We copied the Region Handler, so we now must add a reference
9270174267aSFredrik Holmqvist          */
9280174267aSFredrik Holmqvist         if (DestDesc->Region.Handler)
9290174267aSFredrik Holmqvist         {
9300174267aSFredrik Holmqvist             AcpiUtAddReference (DestDesc->Region.Handler);
9310174267aSFredrik Holmqvist         }
9320174267aSFredrik Holmqvist         break;
9330174267aSFredrik Holmqvist 
9340174267aSFredrik Holmqvist     /*
9350174267aSFredrik Holmqvist      * For Mutex and Event objects, we cannot simply copy the underlying
9360174267aSFredrik Holmqvist      * OS object. We must create a new one.
9370174267aSFredrik Holmqvist      */
9380174267aSFredrik Holmqvist     case ACPI_TYPE_MUTEX:
9390174267aSFredrik Holmqvist 
9400174267aSFredrik Holmqvist         Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex);
9410174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
9420174267aSFredrik Holmqvist         {
9430174267aSFredrik Holmqvist             return (Status);
9440174267aSFredrik Holmqvist         }
9450174267aSFredrik Holmqvist         break;
9460174267aSFredrik Holmqvist 
9470174267aSFredrik Holmqvist     case ACPI_TYPE_EVENT:
9480174267aSFredrik Holmqvist 
9490174267aSFredrik Holmqvist         Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
9500174267aSFredrik Holmqvist             &DestDesc->Event.OsSemaphore);
9510174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
9520174267aSFredrik Holmqvist         {
9530174267aSFredrik Holmqvist             return (Status);
9540174267aSFredrik Holmqvist         }
9550174267aSFredrik Holmqvist         break;
9560174267aSFredrik Holmqvist 
9570174267aSFredrik Holmqvist     default:
958c70258b7SJérôme Duval 
9590174267aSFredrik Holmqvist         /* Nothing to do for other simple objects */
960c70258b7SJérôme Duval 
9610174267aSFredrik Holmqvist         break;
9620174267aSFredrik Holmqvist     }
9630174267aSFredrik Holmqvist 
9640174267aSFredrik Holmqvist     return (AE_OK);
9650174267aSFredrik Holmqvist }
9660174267aSFredrik Holmqvist 
9670174267aSFredrik Holmqvist 
9680174267aSFredrik Holmqvist /*******************************************************************************
9690174267aSFredrik Holmqvist  *
9700174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyIelementToIelement
9710174267aSFredrik Holmqvist  *
9720174267aSFredrik Holmqvist  * PARAMETERS:  ACPI_PKG_CALLBACK
9730174267aSFredrik Holmqvist  *
9740174267aSFredrik Holmqvist  * RETURN:      Status
9750174267aSFredrik Holmqvist  *
9760174267aSFredrik Holmqvist  * DESCRIPTION: Copy one package element to another package element
9770174267aSFredrik Holmqvist  *
9780174267aSFredrik Holmqvist  ******************************************************************************/
9790174267aSFredrik Holmqvist 
9800174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtCopyIelementToIelement(UINT8 ObjectType,ACPI_OPERAND_OBJECT * SourceObject,ACPI_GENERIC_STATE * State,void * Context)9810174267aSFredrik Holmqvist AcpiUtCopyIelementToIelement (
9820174267aSFredrik Holmqvist     UINT8                   ObjectType,
9830174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceObject,
9840174267aSFredrik Holmqvist     ACPI_GENERIC_STATE      *State,
9850174267aSFredrik Holmqvist     void                    *Context)
9860174267aSFredrik Holmqvist {
9870174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
9880174267aSFredrik Holmqvist     UINT32                  ThisIndex;
9890174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **ThisTargetPtr;
9900174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *TargetObject;
9910174267aSFredrik Holmqvist 
9920174267aSFredrik Holmqvist 
9930174267aSFredrik Holmqvist     ACPI_FUNCTION_ENTRY ();
9940174267aSFredrik Holmqvist 
9950174267aSFredrik Holmqvist 
9960174267aSFredrik Holmqvist     ThisIndex = State->Pkg.Index;
9970174267aSFredrik Holmqvist     ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
9980174267aSFredrik Holmqvist         &State->Pkg.DestObject->Package.Elements[ThisIndex];
9990174267aSFredrik Holmqvist 
10000174267aSFredrik Holmqvist     switch (ObjectType)
10010174267aSFredrik Holmqvist     {
10020174267aSFredrik Holmqvist     case ACPI_COPY_TYPE_SIMPLE:
10030174267aSFredrik Holmqvist 
10040174267aSFredrik Holmqvist         /* A null source object indicates a (legal) null package element */
10050174267aSFredrik Holmqvist 
10060174267aSFredrik Holmqvist         if (SourceObject)
10070174267aSFredrik Holmqvist         {
10080174267aSFredrik Holmqvist             /*
10090174267aSFredrik Holmqvist              * This is a simple object, just copy it
10100174267aSFredrik Holmqvist              */
10110174267aSFredrik Holmqvist             TargetObject = AcpiUtCreateInternalObject (
10120174267aSFredrik Holmqvist                 SourceObject->Common.Type);
10130174267aSFredrik Holmqvist             if (!TargetObject)
10140174267aSFredrik Holmqvist             {
10150174267aSFredrik Holmqvist                 return (AE_NO_MEMORY);
10160174267aSFredrik Holmqvist             }
10170174267aSFredrik Holmqvist 
10180174267aSFredrik Holmqvist             Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);
10190174267aSFredrik Holmqvist             if (ACPI_FAILURE (Status))
10200174267aSFredrik Holmqvist             {
10210174267aSFredrik Holmqvist                 goto ErrorExit;
10220174267aSFredrik Holmqvist             }
10230174267aSFredrik Holmqvist 
10240174267aSFredrik Holmqvist             *ThisTargetPtr = TargetObject;
10250174267aSFredrik Holmqvist         }
10260174267aSFredrik Holmqvist         else
10270174267aSFredrik Holmqvist         {
10280174267aSFredrik Holmqvist             /* Pass through a null element */
10290174267aSFredrik Holmqvist 
10300174267aSFredrik Holmqvist             *ThisTargetPtr = NULL;
10310174267aSFredrik Holmqvist         }
10320174267aSFredrik Holmqvist         break;
10330174267aSFredrik Holmqvist 
10340174267aSFredrik Holmqvist     case ACPI_COPY_TYPE_PACKAGE:
10350174267aSFredrik Holmqvist         /*
10360174267aSFredrik Holmqvist          * This object is a package - go down another nesting level
10370174267aSFredrik Holmqvist          * Create and build the package object
10380174267aSFredrik Holmqvist          */
1039b64e8511SFredrik Holmqvist         TargetObject = AcpiUtCreatePackageObject (
1040b64e8511SFredrik Holmqvist             SourceObject->Package.Count);
10410174267aSFredrik Holmqvist         if (!TargetObject)
10420174267aSFredrik Holmqvist         {
10430174267aSFredrik Holmqvist             return (AE_NO_MEMORY);
10440174267aSFredrik Holmqvist         }
10450174267aSFredrik Holmqvist 
10460174267aSFredrik Holmqvist         TargetObject->Common.Flags = SourceObject->Common.Flags;
10470174267aSFredrik Holmqvist 
10480174267aSFredrik Holmqvist         /* Pass the new package object back to the package walk routine */
10490174267aSFredrik Holmqvist 
10500174267aSFredrik Holmqvist         State->Pkg.ThisTargetObj = TargetObject;
10510174267aSFredrik Holmqvist 
10520174267aSFredrik Holmqvist         /* Store the object pointer in the parent package object */
10530174267aSFredrik Holmqvist 
10540174267aSFredrik Holmqvist         *ThisTargetPtr = TargetObject;
10550174267aSFredrik Holmqvist         break;
10560174267aSFredrik Holmqvist 
10570174267aSFredrik Holmqvist     default:
1058c70258b7SJérôme Duval 
10590174267aSFredrik Holmqvist         return (AE_BAD_PARAMETER);
10600174267aSFredrik Holmqvist     }
10610174267aSFredrik Holmqvist 
10620174267aSFredrik Holmqvist     return (Status);
10630174267aSFredrik Holmqvist 
10640174267aSFredrik Holmqvist ErrorExit:
10650174267aSFredrik Holmqvist     AcpiUtRemoveReference (TargetObject);
10660174267aSFredrik Holmqvist     return (Status);
10670174267aSFredrik Holmqvist }
10680174267aSFredrik Holmqvist 
10690174267aSFredrik Holmqvist 
10700174267aSFredrik Holmqvist /*******************************************************************************
10710174267aSFredrik Holmqvist  *
10720174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyIpackageToIpackage
10730174267aSFredrik Holmqvist  *
10740174267aSFredrik Holmqvist  * PARAMETERS:  SourceObj       - Pointer to the source package object
10750174267aSFredrik Holmqvist  *              DestObj         - Where the internal object is returned
10760174267aSFredrik Holmqvist  *              WalkState       - Current Walk state descriptor
10770174267aSFredrik Holmqvist  *
10780174267aSFredrik Holmqvist  * RETURN:      Status
10790174267aSFredrik Holmqvist  *
10800174267aSFredrik Holmqvist  * DESCRIPTION: This function is called to copy an internal package object
10810174267aSFredrik Holmqvist  *              into another internal package object.
10820174267aSFredrik Holmqvist  *
10830174267aSFredrik Holmqvist  ******************************************************************************/
10840174267aSFredrik Holmqvist 
10850174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtCopyIpackageToIpackage(ACPI_OPERAND_OBJECT * SourceObj,ACPI_OPERAND_OBJECT * DestObj,ACPI_WALK_STATE * WalkState)10860174267aSFredrik Holmqvist AcpiUtCopyIpackageToIpackage (
10870174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceObj,
10880174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *DestObj,
10890174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
10900174267aSFredrik Holmqvist {
10910174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
10920174267aSFredrik Holmqvist 
10930174267aSFredrik Holmqvist 
10940174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage);
10950174267aSFredrik Holmqvist 
10960174267aSFredrik Holmqvist 
10970174267aSFredrik Holmqvist     DestObj->Common.Type = SourceObj->Common.Type;
10980174267aSFredrik Holmqvist     DestObj->Common.Flags = SourceObj->Common.Flags;
10990174267aSFredrik Holmqvist     DestObj->Package.Count = SourceObj->Package.Count;
11000174267aSFredrik Holmqvist 
11010174267aSFredrik Holmqvist     /*
11020174267aSFredrik Holmqvist      * Create the object array and walk the source package tree
11030174267aSFredrik Holmqvist      */
11040174267aSFredrik Holmqvist     DestObj->Package.Elements = ACPI_ALLOCATE_ZEROED (
11050174267aSFredrik Holmqvist         ((ACPI_SIZE) SourceObj->Package.Count + 1) *
11060174267aSFredrik Holmqvist         sizeof (void *));
11070174267aSFredrik Holmqvist     if (!DestObj->Package.Elements)
11080174267aSFredrik Holmqvist     {
11090174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Package allocation failure"));
11100174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_NO_MEMORY);
11110174267aSFredrik Holmqvist     }
11120174267aSFredrik Holmqvist 
11130174267aSFredrik Holmqvist     /*
11140174267aSFredrik Holmqvist      * Copy the package element-by-element by walking the package "tree".
11150174267aSFredrik Holmqvist      * This handles nested packages of arbitrary depth.
11160174267aSFredrik Holmqvist      */
11170174267aSFredrik Holmqvist     Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
11180174267aSFredrik Holmqvist         AcpiUtCopyIelementToIelement, WalkState);
11190174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
11200174267aSFredrik Holmqvist     {
11210174267aSFredrik Holmqvist         /* On failure, delete the destination package object */
11220174267aSFredrik Holmqvist 
11230174267aSFredrik Holmqvist         AcpiUtRemoveReference (DestObj);
11240174267aSFredrik Holmqvist     }
11250174267aSFredrik Holmqvist 
11260174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
11270174267aSFredrik Holmqvist }
11280174267aSFredrik Holmqvist 
11290174267aSFredrik Holmqvist 
11300174267aSFredrik Holmqvist /*******************************************************************************
11310174267aSFredrik Holmqvist  *
11320174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtCopyIobjectToIobject
11330174267aSFredrik Holmqvist  *
11340174267aSFredrik Holmqvist  * PARAMETERS:  SourceDesc          - The internal object to be copied
11350174267aSFredrik Holmqvist  *              DestDesc            - Where the copied object is returned
11360174267aSFredrik Holmqvist  *              WalkState           - Current walk state
11370174267aSFredrik Holmqvist  *
11380174267aSFredrik Holmqvist  * RETURN:      Status
11390174267aSFredrik Holmqvist  *
11400174267aSFredrik Holmqvist  * DESCRIPTION: Copy an internal object to a new internal object
11410174267aSFredrik Holmqvist  *
11420174267aSFredrik Holmqvist  ******************************************************************************/
11430174267aSFredrik Holmqvist 
11440174267aSFredrik Holmqvist ACPI_STATUS
AcpiUtCopyIobjectToIobject(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_OPERAND_OBJECT ** DestDesc,ACPI_WALK_STATE * WalkState)11450174267aSFredrik Holmqvist AcpiUtCopyIobjectToIobject (
11460174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *SourceDesc,
11470174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **DestDesc,
11480174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
11490174267aSFredrik Holmqvist {
11500174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
11510174267aSFredrik Holmqvist 
11520174267aSFredrik Holmqvist 
11530174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject);
11540174267aSFredrik Holmqvist 
11550174267aSFredrik Holmqvist 
11560174267aSFredrik Holmqvist     /* Create the top level object */
11570174267aSFredrik Holmqvist 
11580174267aSFredrik Holmqvist     *DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type);
11590174267aSFredrik Holmqvist     if (!*DestDesc)
11600174267aSFredrik Holmqvist     {
11610174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_NO_MEMORY);
11620174267aSFredrik Holmqvist     }
11630174267aSFredrik Holmqvist 
11640174267aSFredrik Holmqvist     /* Copy the object and possible subobjects */
11650174267aSFredrik Holmqvist 
11660174267aSFredrik Holmqvist     if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE)
11670174267aSFredrik Holmqvist     {
1168b64e8511SFredrik Holmqvist         Status = AcpiUtCopyIpackageToIpackage (
1169b64e8511SFredrik Holmqvist             SourceDesc, *DestDesc, WalkState);
11700174267aSFredrik Holmqvist     }
11710174267aSFredrik Holmqvist     else
11720174267aSFredrik Holmqvist     {
11730174267aSFredrik Holmqvist         Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);
11740174267aSFredrik Holmqvist     }
11750174267aSFredrik Holmqvist 
1176ad5bbfb8SFredrik Holmqvist     /* Delete the allocated object if copy failed */
1177ad5bbfb8SFredrik Holmqvist 
1178ad5bbfb8SFredrik Holmqvist     if (ACPI_FAILURE (Status))
1179ad5bbfb8SFredrik Holmqvist     {
1180ad5bbfb8SFredrik Holmqvist         AcpiUtRemoveReference (*DestDesc);
1181ad5bbfb8SFredrik Holmqvist     }
1182ad5bbfb8SFredrik Holmqvist 
11830174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
11840174267aSFredrik Holmqvist }
1185