Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/utcopy.c need to be fixed.

0001 /******************************************************************************
0002  *
0003  * Module Name: utcopy - Internal to external object translation utilities
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 #define __UTCOPY_C__
0117 
0118 #include "acpi.h"
0119 #include "accommon.h"
0120 #include "acnamesp.h"
0121 
0122 
0123 #define _COMPONENT          ACPI_UTILITIES
0124         ACPI_MODULE_NAME    ("utcopy")
0125 
0126 /* Local prototypes */
0127 
0128 static ACPI_STATUS
0129 AcpiUtCopyIsimpleToEsimple (
0130     ACPI_OPERAND_OBJECT     *InternalObject,
0131     ACPI_OBJECT             *ExternalObject,
0132     UINT8                   *DataSpace,
0133     ACPI_SIZE               *BufferSpaceUsed);
0134 
0135 static ACPI_STATUS
0136 AcpiUtCopyIelementToIelement (
0137     UINT8                   ObjectType,
0138     ACPI_OPERAND_OBJECT     *SourceObject,
0139     ACPI_GENERIC_STATE      *State,
0140     void                    *Context);
0141 
0142 static ACPI_STATUS
0143 AcpiUtCopyIpackageToEpackage (
0144     ACPI_OPERAND_OBJECT     *InternalObject,
0145     UINT8                   *Buffer,
0146     ACPI_SIZE               *SpaceUsed);
0147 
0148 static ACPI_STATUS
0149 AcpiUtCopyEsimpleToIsimple(
0150     ACPI_OBJECT             *UserObj,
0151     ACPI_OPERAND_OBJECT     **ReturnObj);
0152 
0153 static ACPI_STATUS
0154 AcpiUtCopyEpackageToIpackage (
0155     ACPI_OBJECT             *ExternalObject,
0156     ACPI_OPERAND_OBJECT     **InternalObject);
0157 
0158 static ACPI_STATUS
0159 AcpiUtCopySimpleObject (
0160     ACPI_OPERAND_OBJECT     *SourceDesc,
0161     ACPI_OPERAND_OBJECT     *DestDesc);
0162 
0163 static ACPI_STATUS
0164 AcpiUtCopyIelementToEelement (
0165     UINT8                   ObjectType,
0166     ACPI_OPERAND_OBJECT     *SourceObject,
0167     ACPI_GENERIC_STATE      *State,
0168     void                    *Context);
0169 
0170 static ACPI_STATUS
0171 AcpiUtCopyIpackageToIpackage (
0172     ACPI_OPERAND_OBJECT     *SourceObj,
0173     ACPI_OPERAND_OBJECT     *DestObj,
0174     ACPI_WALK_STATE         *WalkState);
0175 
0176 
0177 /*******************************************************************************
0178  *
0179  * FUNCTION:    AcpiUtCopyIsimpleToEsimple
0180  *
0181  * PARAMETERS:  InternalObject      - Source object to be copied
0182  *              ExternalObject      - Where to return the copied object
0183  *              DataSpace           - Where object data is returned (such as
0184  *                                    buffer and string data)
0185  *              BufferSpaceUsed     - Length of DataSpace that was used
0186  *
0187  * RETURN:      Status
0188  *
0189  * DESCRIPTION: This function is called to copy a simple internal object to
0190  *              an external object.
0191  *
0192  *              The DataSpace buffer is assumed to have sufficient space for
0193  *              the object.
0194  *
0195  ******************************************************************************/
0196 
0197 static ACPI_STATUS
0198 AcpiUtCopyIsimpleToEsimple (
0199     ACPI_OPERAND_OBJECT     *InternalObject,
0200     ACPI_OBJECT             *ExternalObject,
0201     UINT8                   *DataSpace,
0202     ACPI_SIZE               *BufferSpaceUsed)
0203 {
0204     ACPI_STATUS             Status = AE_OK;
0205 
0206 
0207     ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple);
0208 
0209 
0210     *BufferSpaceUsed = 0;
0211 
0212     /*
0213      * Check for NULL object case (could be an uninitialized
0214      * package element)
0215      */
0216     if (!InternalObject)
0217     {
0218         return_ACPI_STATUS (AE_OK);
0219     }
0220 
0221     /* Always clear the external object */
0222 
0223     ACPI_MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
0224 
0225     /*
0226      * In general, the external object will be the same type as
0227      * the internal object
0228      */
0229     ExternalObject->Type = InternalObject->Common.Type;
0230 
0231     /* However, only a limited number of external types are supported */
0232 
0233     switch (InternalObject->Common.Type)
0234     {
0235     case ACPI_TYPE_STRING:
0236 
0237         ExternalObject->String.Pointer = (char *) DataSpace;
0238         ExternalObject->String.Length  = InternalObject->String.Length;
0239         *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
0240                             (ACPI_SIZE) InternalObject->String.Length + 1);
0241 
0242         ACPI_MEMCPY ((void *) DataSpace,
0243             (void *) InternalObject->String.Pointer,
0244             (ACPI_SIZE) InternalObject->String.Length + 1);
0245         break;
0246 
0247 
0248     case ACPI_TYPE_BUFFER:
0249 
0250         ExternalObject->Buffer.Pointer = DataSpace;
0251         ExternalObject->Buffer.Length  = InternalObject->Buffer.Length;
0252         *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
0253                             InternalObject->String.Length);
0254 
0255         ACPI_MEMCPY ((void *) DataSpace,
0256             (void *) InternalObject->Buffer.Pointer,
0257             InternalObject->Buffer.Length);
0258         break;
0259 
0260 
0261     case ACPI_TYPE_INTEGER:
0262 
0263         ExternalObject->Integer.Value = InternalObject->Integer.Value;
0264         break;
0265 
0266 
0267     case ACPI_TYPE_LOCAL_REFERENCE:
0268 
0269         /* This is an object reference. */
0270 
0271         switch (InternalObject->Reference.Class)
0272         {
0273         case ACPI_REFCLASS_NAME:
0274 
0275             /*
0276              * For namepath, return the object handle ("reference")
0277              * We are referring to the namespace node
0278              */
0279             ExternalObject->Reference.Handle =
0280                 InternalObject->Reference.Node;
0281             ExternalObject->Reference.ActualType =
0282                 AcpiNsGetType (InternalObject->Reference.Node);
0283             break;
0284 
0285         default:
0286 
0287             /* All other reference types are unsupported */
0288 
0289             return_ACPI_STATUS (AE_TYPE);
0290         }
0291         break;
0292 
0293 
0294     case ACPI_TYPE_PROCESSOR:
0295 
0296         ExternalObject->Processor.ProcId =
0297             InternalObject->Processor.ProcId;
0298         ExternalObject->Processor.PblkAddress =
0299             InternalObject->Processor.Address;
0300         ExternalObject->Processor.PblkLength =
0301             InternalObject->Processor.Length;
0302         break;
0303 
0304 
0305     case ACPI_TYPE_POWER:
0306 
0307         ExternalObject->PowerResource.SystemLevel =
0308             InternalObject->PowerResource.SystemLevel;
0309 
0310         ExternalObject->PowerResource.ResourceOrder =
0311             InternalObject->PowerResource.ResourceOrder;
0312         break;
0313 
0314 
0315     default:
0316         /*
0317          * There is no corresponding external object type
0318          */
0319         ACPI_ERROR ((AE_INFO,
0320             "Unsupported object type, cannot convert to external object: %s",
0321             AcpiUtGetTypeName (InternalObject->Common.Type)));
0322 
0323         return_ACPI_STATUS (AE_SUPPORT);
0324     }
0325 
0326     return_ACPI_STATUS (Status);
0327 }
0328 
0329 
0330 /*******************************************************************************
0331  *
0332  * FUNCTION:    AcpiUtCopyIelementToEelement
0333  *
0334  * PARAMETERS:  ACPI_PKG_CALLBACK
0335  *
0336  * RETURN:      Status
0337  *
0338  * DESCRIPTION: Copy one package element to another package element
0339  *
0340  ******************************************************************************/
0341 
0342 static ACPI_STATUS
0343 AcpiUtCopyIelementToEelement (
0344     UINT8                   ObjectType,
0345     ACPI_OPERAND_OBJECT     *SourceObject,
0346     ACPI_GENERIC_STATE      *State,
0347     void                    *Context)
0348 {
0349     ACPI_STATUS             Status = AE_OK;
0350     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
0351     ACPI_SIZE               ObjectSpace;
0352     UINT32                  ThisIndex;
0353     ACPI_OBJECT             *TargetObject;
0354 
0355 
0356     ACPI_FUNCTION_ENTRY ();
0357 
0358 
0359     ThisIndex    = State->Pkg.Index;
0360     TargetObject = (ACPI_OBJECT *)
0361         &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
0362 
0363     switch (ObjectType)
0364     {
0365     case ACPI_COPY_TYPE_SIMPLE:
0366 
0367         /*
0368          * This is a simple or null object
0369          */
0370         Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
0371                         TargetObject, Info->FreeSpace, &ObjectSpace);
0372         if (ACPI_FAILURE (Status))
0373         {
0374             return (Status);
0375         }
0376         break;
0377 
0378 
0379     case ACPI_COPY_TYPE_PACKAGE:
0380 
0381         /*
0382          * Build the package object
0383          */
0384         TargetObject->Type              = ACPI_TYPE_PACKAGE;
0385         TargetObject->Package.Count     = SourceObject->Package.Count;
0386         TargetObject->Package.Elements  =
0387             ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);
0388 
0389         /*
0390          * Pass the new package object back to the package walk routine
0391          */
0392         State->Pkg.ThisTargetObj = TargetObject;
0393 
0394         /*
0395          * Save space for the array of objects (Package elements)
0396          * update the buffer length counter
0397          */
0398         ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (
0399                             (ACPI_SIZE) TargetObject->Package.Count *
0400                             sizeof (ACPI_OBJECT));
0401         break;
0402 
0403 
0404     default:
0405         return (AE_BAD_PARAMETER);
0406     }
0407 
0408     Info->FreeSpace   += ObjectSpace;
0409     Info->Length      += ObjectSpace;
0410     return (Status);
0411 }
0412 
0413 
0414 /*******************************************************************************
0415  *
0416  * FUNCTION:    AcpiUtCopyIpackageToEpackage
0417  *
0418  * PARAMETERS:  InternalObject      - Pointer to the object we are returning
0419  *              Buffer              - Where the object is returned
0420  *              SpaceUsed           - Where the object length is returned
0421  *
0422  * RETURN:      Status
0423  *
0424  * DESCRIPTION: This function is called to place a package object in a user
0425  *              buffer.  A package object by definition contains other objects.
0426  *
0427  *              The buffer is assumed to have sufficient space for the object.
0428  *              The caller must have verified the buffer length needed using the
0429  *              AcpiUtGetObjectSize function before calling this function.
0430  *
0431  ******************************************************************************/
0432 
0433 static ACPI_STATUS
0434 AcpiUtCopyIpackageToEpackage (
0435     ACPI_OPERAND_OBJECT     *InternalObject,
0436     UINT8                   *Buffer,
0437     ACPI_SIZE               *SpaceUsed)
0438 {
0439     ACPI_OBJECT             *ExternalObject;
0440     ACPI_STATUS             Status;
0441     ACPI_PKG_INFO           Info;
0442 
0443 
0444     ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage);
0445 
0446 
0447     /*
0448      * First package at head of the buffer
0449      */
0450     ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);
0451 
0452     /*
0453      * Free space begins right after the first package
0454      */
0455     Info.Length      = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
0456     Info.FreeSpace   = Buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
0457                                     sizeof (ACPI_OBJECT));
0458     Info.ObjectSpace = 0;
0459     Info.NumPackages = 1;
0460 
0461     ExternalObject->Type             = InternalObject->Common.Type;
0462     ExternalObject->Package.Count    = InternalObject->Package.Count;
0463     ExternalObject->Package.Elements = ACPI_CAST_PTR (ACPI_OBJECT,
0464                                             Info.FreeSpace);
0465 
0466     /*
0467      * Leave room for an array of ACPI_OBJECTS in the buffer
0468      * and move the free space past it
0469      */
0470     Info.Length    += (ACPI_SIZE) ExternalObject->Package.Count *
0471                             ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
0472     Info.FreeSpace += ExternalObject->Package.Count *
0473                             ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
0474 
0475     Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
0476                 AcpiUtCopyIelementToEelement, &Info);
0477 
0478     *SpaceUsed = Info.Length;
0479     return_ACPI_STATUS (Status);
0480 }
0481 
0482 
0483 /*******************************************************************************
0484  *
0485  * FUNCTION:    AcpiUtCopyIobjectToEobject
0486  *
0487  * PARAMETERS:  InternalObject      - The internal object to be converted
0488  *              BufferPtr           - Where the object is returned
0489  *
0490  * RETURN:      Status
0491  *
0492  * DESCRIPTION: This function is called to build an API object to be returned to
0493  *              the caller.
0494  *
0495  ******************************************************************************/
0496 
0497 ACPI_STATUS
0498 AcpiUtCopyIobjectToEobject (
0499     ACPI_OPERAND_OBJECT     *InternalObject,
0500     ACPI_BUFFER             *RetBuffer)
0501 {
0502     ACPI_STATUS             Status;
0503 
0504 
0505     ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject);
0506 
0507 
0508     if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)
0509     {
0510         /*
0511          * Package object:  Copy all subobjects (including
0512          * nested packages)
0513          */
0514         Status = AcpiUtCopyIpackageToEpackage (InternalObject,
0515                         RetBuffer->Pointer, &RetBuffer->Length);
0516     }
0517     else
0518     {
0519         /*
0520          * Build a simple object (no nested objects)
0521          */
0522         Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
0523                     ACPI_CAST_PTR (ACPI_OBJECT, RetBuffer->Pointer),
0524                     ACPI_ADD_PTR (UINT8, RetBuffer->Pointer,
0525                         ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
0526                     &RetBuffer->Length);
0527         /*
0528          * build simple does not include the object size in the length
0529          * so we add it in here
0530          */
0531         RetBuffer->Length += sizeof (ACPI_OBJECT);
0532     }
0533 
0534     return_ACPI_STATUS (Status);
0535 }
0536 
0537 
0538 /*******************************************************************************
0539  *
0540  * FUNCTION:    AcpiUtCopyEsimpleToIsimple
0541  *
0542  * PARAMETERS:  ExternalObject      - The external object to be converted
0543  *              RetInternalObject   - Where the internal object is returned
0544  *
0545  * RETURN:      Status
0546  *
0547  * DESCRIPTION: This function copies an external object to an internal one.
0548  *              NOTE: Pointers can be copied, we don't need to copy data.
0549  *              (The pointers have to be valid in our address space no matter
0550  *              what we do with them!)
0551  *
0552  ******************************************************************************/
0553 
0554 static ACPI_STATUS
0555 AcpiUtCopyEsimpleToIsimple (
0556     ACPI_OBJECT             *ExternalObject,
0557     ACPI_OPERAND_OBJECT     **RetInternalObject)
0558 {
0559     ACPI_OPERAND_OBJECT     *InternalObject;
0560 
0561 
0562     ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple);
0563 
0564 
0565     /*
0566      * Simple types supported are: String, Buffer, Integer
0567      */
0568     switch (ExternalObject->Type)
0569     {
0570     case ACPI_TYPE_STRING:
0571     case ACPI_TYPE_BUFFER:
0572     case ACPI_TYPE_INTEGER:
0573     case ACPI_TYPE_LOCAL_REFERENCE:
0574 
0575         InternalObject = AcpiUtCreateInternalObject (
0576                             (UINT8) ExternalObject->Type);
0577         if (!InternalObject)
0578         {
0579             return_ACPI_STATUS (AE_NO_MEMORY);
0580         }
0581         break;
0582 
0583     case ACPI_TYPE_ANY: /* This is the case for a NULL object */
0584 
0585         *RetInternalObject = NULL;
0586         return_ACPI_STATUS (AE_OK);
0587 
0588     default:
0589         /* All other types are not supported */
0590 
0591         ACPI_ERROR ((AE_INFO,
0592             "Unsupported object type, cannot convert to internal object: %s",
0593             AcpiUtGetTypeName (ExternalObject->Type)));
0594 
0595         return_ACPI_STATUS (AE_SUPPORT);
0596     }
0597 
0598 
0599     /* Must COPY string and buffer contents */
0600 
0601     switch (ExternalObject->Type)
0602     {
0603     case ACPI_TYPE_STRING:
0604 
0605         InternalObject->String.Pointer =
0606             ACPI_ALLOCATE_ZEROED ((ACPI_SIZE)
0607                 ExternalObject->String.Length + 1);
0608 
0609         if (!InternalObject->String.Pointer)
0610         {
0611             goto ErrorExit;
0612         }
0613 
0614         ACPI_MEMCPY (InternalObject->String.Pointer,
0615                      ExternalObject->String.Pointer,
0616                      ExternalObject->String.Length);
0617 
0618         InternalObject->String.Length  = ExternalObject->String.Length;
0619         break;
0620 
0621 
0622     case ACPI_TYPE_BUFFER:
0623 
0624         InternalObject->Buffer.Pointer =
0625             ACPI_ALLOCATE_ZEROED (ExternalObject->Buffer.Length);
0626         if (!InternalObject->Buffer.Pointer)
0627         {
0628             goto ErrorExit;
0629         }
0630 
0631         ACPI_MEMCPY (InternalObject->Buffer.Pointer,
0632                      ExternalObject->Buffer.Pointer,
0633                      ExternalObject->Buffer.Length);
0634 
0635         InternalObject->Buffer.Length  = ExternalObject->Buffer.Length;
0636 
0637         /* Mark buffer data valid */
0638 
0639         InternalObject->Buffer.Flags |= AOPOBJ_DATA_VALID;
0640         break;
0641 
0642 
0643     case ACPI_TYPE_INTEGER:
0644 
0645         InternalObject->Integer.Value   = ExternalObject->Integer.Value;
0646         break;
0647 
0648     case ACPI_TYPE_LOCAL_REFERENCE:
0649 
0650         /* TBD: should validate incoming handle */
0651 
0652         InternalObject->Reference.Class = ACPI_REFCLASS_NAME;
0653         InternalObject->Reference.Node = ExternalObject->Reference.Handle;
0654         break;
0655 
0656     default:
0657         /* Other types can't get here */
0658         break;
0659     }
0660 
0661     *RetInternalObject = InternalObject;
0662     return_ACPI_STATUS (AE_OK);
0663 
0664 
0665 ErrorExit:
0666     AcpiUtRemoveReference (InternalObject);
0667     return_ACPI_STATUS (AE_NO_MEMORY);
0668 }
0669 
0670 
0671 /*******************************************************************************
0672  *
0673  * FUNCTION:    AcpiUtCopyEpackageToIpackage
0674  *
0675  * PARAMETERS:  ExternalObject      - The external object to be converted
0676  *              InternalObject      - Where the internal object is returned
0677  *
0678  * RETURN:      Status
0679  *
0680  * DESCRIPTION: Copy an external package object to an internal package.
0681  *              Handles nested packages.
0682  *
0683  ******************************************************************************/
0684 
0685 static ACPI_STATUS
0686 AcpiUtCopyEpackageToIpackage (
0687     ACPI_OBJECT             *ExternalObject,
0688     ACPI_OPERAND_OBJECT     **InternalObject)
0689 {
0690     ACPI_STATUS             Status = AE_OK;
0691     ACPI_OPERAND_OBJECT     *PackageObject;
0692     ACPI_OPERAND_OBJECT     **PackageElements;
0693     UINT32                  i;
0694 
0695 
0696     ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage);
0697 
0698 
0699     /* Create the package object */
0700 
0701     PackageObject = AcpiUtCreatePackageObject (ExternalObject->Package.Count);
0702     if (!PackageObject)
0703     {
0704         return_ACPI_STATUS (AE_NO_MEMORY);
0705     }
0706 
0707     PackageElements = PackageObject->Package.Elements;
0708 
0709     /*
0710      * Recursive implementation. Probably ok, since nested external packages
0711      * as parameters should be very rare.
0712      */
0713     for (i = 0; i < ExternalObject->Package.Count; i++)
0714     {
0715         Status = AcpiUtCopyEobjectToIobject (
0716                     &ExternalObject->Package.Elements[i],
0717                     &PackageElements[i]);
0718         if (ACPI_FAILURE (Status))
0719         {
0720             /* Truncate package and delete it */
0721 
0722             PackageObject->Package.Count = i;
0723             PackageElements[i] = NULL;
0724             AcpiUtRemoveReference (PackageObject);
0725             return_ACPI_STATUS (Status);
0726         }
0727     }
0728 
0729     /* Mark package data valid */
0730 
0731     PackageObject->Package.Flags |= AOPOBJ_DATA_VALID;
0732 
0733     *InternalObject = PackageObject;
0734     return_ACPI_STATUS (Status);
0735 }
0736 
0737 
0738 /*******************************************************************************
0739  *
0740  * FUNCTION:    AcpiUtCopyEobjectToIobject
0741  *
0742  * PARAMETERS:  ExternalObject      - The external object to be converted
0743  *              InternalObject      - Where the internal object is returned
0744  *
0745  * RETURN:      Status              - the status of the call
0746  *
0747  * DESCRIPTION: Converts an external object to an internal object.
0748  *
0749  ******************************************************************************/
0750 
0751 ACPI_STATUS
0752 AcpiUtCopyEobjectToIobject (
0753     ACPI_OBJECT             *ExternalObject,
0754     ACPI_OPERAND_OBJECT     **InternalObject)
0755 {
0756     ACPI_STATUS             Status;
0757 
0758 
0759     ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject);
0760 
0761 
0762     if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
0763     {
0764         Status = AcpiUtCopyEpackageToIpackage (ExternalObject, InternalObject);
0765     }
0766     else
0767     {
0768         /*
0769          * Build a simple object (no nested objects)
0770          */
0771         Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject);
0772     }
0773 
0774     return_ACPI_STATUS (Status);
0775 }
0776 
0777 
0778 /*******************************************************************************
0779  *
0780  * FUNCTION:    AcpiUtCopySimpleObject
0781  *
0782  * PARAMETERS:  SourceDesc          - The internal object to be copied
0783  *              DestDesc            - New target object
0784  *
0785  * RETURN:      Status
0786  *
0787  * DESCRIPTION: Simple copy of one internal object to another.  Reference count
0788  *              of the destination object is preserved.
0789  *
0790  ******************************************************************************/
0791 
0792 static ACPI_STATUS
0793 AcpiUtCopySimpleObject (
0794     ACPI_OPERAND_OBJECT     *SourceDesc,
0795     ACPI_OPERAND_OBJECT     *DestDesc)
0796 {
0797     UINT16                  ReferenceCount;
0798     ACPI_OPERAND_OBJECT     *NextObject;
0799     ACPI_STATUS             Status;
0800 
0801 
0802     /* Save fields from destination that we don't want to overwrite */
0803 
0804     ReferenceCount = DestDesc->Common.ReferenceCount;
0805     NextObject = DestDesc->Common.NextObject;
0806 
0807     /* Copy the entire source object over the destination object*/
0808 
0809     ACPI_MEMCPY ((char *) DestDesc, (char *) SourceDesc,
0810                     sizeof (ACPI_OPERAND_OBJECT));
0811 
0812     /* Restore the saved fields */
0813 
0814     DestDesc->Common.ReferenceCount = ReferenceCount;
0815     DestDesc->Common.NextObject = NextObject;
0816 
0817     /* New object is not static, regardless of source */
0818 
0819     DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
0820 
0821     /* Handle the objects with extra data */
0822 
0823     switch (DestDesc->Common.Type)
0824     {
0825     case ACPI_TYPE_BUFFER:
0826         /*
0827          * Allocate and copy the actual buffer if and only if:
0828          * 1) There is a valid buffer pointer
0829          * 2) The buffer has a length > 0
0830          */
0831         if ((SourceDesc->Buffer.Pointer) &&
0832             (SourceDesc->Buffer.Length))
0833         {
0834             DestDesc->Buffer.Pointer =
0835                 ACPI_ALLOCATE (SourceDesc->Buffer.Length);
0836             if (!DestDesc->Buffer.Pointer)
0837             {
0838                 return (AE_NO_MEMORY);
0839             }
0840 
0841             /* Copy the actual buffer data */
0842 
0843             ACPI_MEMCPY (DestDesc->Buffer.Pointer,
0844                     SourceDesc->Buffer.Pointer,
0845                     SourceDesc->Buffer.Length);
0846         }
0847         break;
0848 
0849     case ACPI_TYPE_STRING:
0850         /*
0851          * Allocate and copy the actual string if and only if:
0852          * 1) There is a valid string pointer
0853          * (Pointer to a NULL string is allowed)
0854          */
0855         if (SourceDesc->String.Pointer)
0856         {
0857             DestDesc->String.Pointer =
0858                 ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1);
0859             if (!DestDesc->String.Pointer)
0860             {
0861                 return (AE_NO_MEMORY);
0862             }
0863 
0864             /* Copy the actual string data */
0865 
0866             ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer,
0867                          (ACPI_SIZE) SourceDesc->String.Length + 1);
0868         }
0869         break;
0870 
0871     case ACPI_TYPE_LOCAL_REFERENCE:
0872         /*
0873          * We copied the reference object, so we now must add a reference
0874          * to the object pointed to by the reference
0875          *
0876          * DDBHandle reference (from Load/LoadTable) is a special reference,
0877          * it does not have a Reference.Object, so does not need to
0878          * increase the reference count
0879          */
0880         if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
0881         {
0882             break;
0883         }
0884 
0885         AcpiUtAddReference (SourceDesc->Reference.Object);
0886         break;
0887 
0888     case ACPI_TYPE_REGION:
0889         /*
0890          * We copied the Region Handler, so we now must add a reference
0891          */
0892         if (DestDesc->Region.Handler)
0893         {
0894             AcpiUtAddReference (DestDesc->Region.Handler);
0895         }
0896         break;
0897 
0898     /*
0899      * For Mutex and Event objects, we cannot simply copy the underlying
0900      * OS object. We must create a new one.
0901      */
0902     case ACPI_TYPE_MUTEX:
0903 
0904         Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex);
0905         if (ACPI_FAILURE (Status))
0906         {
0907             return (Status);
0908         }
0909         break;
0910 
0911     case ACPI_TYPE_EVENT:
0912 
0913         Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
0914                     &DestDesc->Event.OsSemaphore);
0915         if (ACPI_FAILURE (Status))
0916         {
0917             return (Status);
0918         }
0919         break;
0920 
0921     default:
0922         /* Nothing to do for other simple objects */
0923         break;
0924     }
0925 
0926     return (AE_OK);
0927 }
0928 
0929 
0930 /*******************************************************************************
0931  *
0932  * FUNCTION:    AcpiUtCopyIelementToIelement
0933  *
0934  * PARAMETERS:  ACPI_PKG_CALLBACK
0935  *
0936  * RETURN:      Status
0937  *
0938  * DESCRIPTION: Copy one package element to another package element
0939  *
0940  ******************************************************************************/
0941 
0942 static ACPI_STATUS
0943 AcpiUtCopyIelementToIelement (
0944     UINT8                   ObjectType,
0945     ACPI_OPERAND_OBJECT     *SourceObject,
0946     ACPI_GENERIC_STATE      *State,
0947     void                    *Context)
0948 {
0949     ACPI_STATUS             Status = AE_OK;
0950     UINT32                  ThisIndex;
0951     ACPI_OPERAND_OBJECT     **ThisTargetPtr;
0952     ACPI_OPERAND_OBJECT     *TargetObject;
0953 
0954 
0955     ACPI_FUNCTION_ENTRY ();
0956 
0957 
0958     ThisIndex     = State->Pkg.Index;
0959     ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
0960                         &State->Pkg.DestObject->Package.Elements[ThisIndex];
0961 
0962     switch (ObjectType)
0963     {
0964     case ACPI_COPY_TYPE_SIMPLE:
0965 
0966         /* A null source object indicates a (legal) null package element */
0967 
0968         if (SourceObject)
0969         {
0970             /*
0971              * This is a simple object, just copy it
0972              */
0973             TargetObject = AcpiUtCreateInternalObject (
0974                                 SourceObject->Common.Type);
0975             if (!TargetObject)
0976             {
0977                 return (AE_NO_MEMORY);
0978             }
0979 
0980             Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);
0981             if (ACPI_FAILURE (Status))
0982             {
0983                 goto ErrorExit;
0984             }
0985 
0986             *ThisTargetPtr = TargetObject;
0987         }
0988         else
0989         {
0990             /* Pass through a null element */
0991 
0992             *ThisTargetPtr = NULL;
0993         }
0994         break;
0995 
0996 
0997     case ACPI_COPY_TYPE_PACKAGE:
0998 
0999         /*
1000          * This object is a package - go down another nesting level
1001          * Create and build the package object
1002          */
1003         TargetObject = AcpiUtCreatePackageObject (SourceObject->Package.Count);
1004         if (!TargetObject)
1005         {
1006             return (AE_NO_MEMORY);
1007         }
1008 
1009         TargetObject->Common.Flags = SourceObject->Common.Flags;
1010 
1011         /* Pass the new package object back to the package walk routine */
1012 
1013         State->Pkg.ThisTargetObj = TargetObject;
1014 
1015         /* Store the object pointer in the parent package object */
1016 
1017         *ThisTargetPtr = TargetObject;
1018         break;
1019 
1020 
1021     default:
1022         return (AE_BAD_PARAMETER);
1023     }
1024 
1025     return (Status);
1026 
1027 ErrorExit:
1028     AcpiUtRemoveReference (TargetObject);
1029     return (Status);
1030 }
1031 
1032 
1033 /*******************************************************************************
1034  *
1035  * FUNCTION:    AcpiUtCopyIpackageToIpackage
1036  *
1037  * PARAMETERS:  *SourceObj      - Pointer to the source package object
1038  *              *DestObj        - Where the internal object is returned
1039  *
1040  * RETURN:      Status          - the status of the call
1041  *
1042  * DESCRIPTION: This function is called to copy an internal package object
1043  *              into another internal package object.
1044  *
1045  ******************************************************************************/
1046 
1047 static ACPI_STATUS
1048 AcpiUtCopyIpackageToIpackage (
1049     ACPI_OPERAND_OBJECT     *SourceObj,
1050     ACPI_OPERAND_OBJECT     *DestObj,
1051     ACPI_WALK_STATE         *WalkState)
1052 {
1053     ACPI_STATUS             Status = AE_OK;
1054 
1055 
1056     ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage);
1057 
1058 
1059     DestObj->Common.Type    = SourceObj->Common.Type;
1060     DestObj->Common.Flags   = SourceObj->Common.Flags;
1061     DestObj->Package.Count  = SourceObj->Package.Count;
1062 
1063     /*
1064      * Create the object array and walk the source package tree
1065      */
1066     DestObj->Package.Elements = ACPI_ALLOCATE_ZEROED (
1067                                     ((ACPI_SIZE) SourceObj->Package.Count + 1) *
1068                                     sizeof (void *));
1069     if (!DestObj->Package.Elements)
1070     {
1071         ACPI_ERROR ((AE_INFO, "Package allocation failure"));
1072         return_ACPI_STATUS (AE_NO_MEMORY);
1073     }
1074 
1075     /*
1076      * Copy the package element-by-element by walking the package "tree".
1077      * This handles nested packages of arbitrary depth.
1078      */
1079     Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
1080                 AcpiUtCopyIelementToIelement, WalkState);
1081     if (ACPI_FAILURE (Status))
1082     {
1083         /* On failure, delete the destination package object */
1084 
1085         AcpiUtRemoveReference (DestObj);
1086     }
1087 
1088     return_ACPI_STATUS (Status);
1089 }
1090 
1091 
1092 /*******************************************************************************
1093  *
1094  * FUNCTION:    AcpiUtCopyIobjectToIobject
1095  *
1096  * PARAMETERS:  WalkState           - Current walk state
1097  *              SourceDesc          - The internal object to be copied
1098  *              DestDesc            - Where the copied object is returned
1099  *
1100  * RETURN:      Status
1101  *
1102  * DESCRIPTION: Copy an internal object to a new internal object
1103  *
1104  ******************************************************************************/
1105 
1106 ACPI_STATUS
1107 AcpiUtCopyIobjectToIobject (
1108     ACPI_OPERAND_OBJECT     *SourceDesc,
1109     ACPI_OPERAND_OBJECT     **DestDesc,
1110     ACPI_WALK_STATE         *WalkState)
1111 {
1112     ACPI_STATUS             Status = AE_OK;
1113 
1114 
1115     ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject);
1116 
1117 
1118     /* Create the top level object */
1119 
1120     *DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type);
1121     if (!*DestDesc)
1122     {
1123         return_ACPI_STATUS (AE_NO_MEMORY);
1124     }
1125 
1126     /* Copy the object and possible subobjects */
1127 
1128     if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE)
1129     {
1130         Status = AcpiUtCopyIpackageToIpackage (SourceDesc, *DestDesc,
1131                         WalkState);
1132     }
1133     else
1134     {
1135         Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);
1136     }
1137 
1138     return_ACPI_STATUS (Status);
1139 }
1140 
1141