Path: blob/main/sys/contrib/dev/acpica/components/utilities/utcopy.c
48406 views
/******************************************************************************1*2* Module Name: utcopy - Internal to external object translation utilities3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acnamesp.h>154155156#define _COMPONENT ACPI_UTILITIES157ACPI_MODULE_NAME ("utcopy")158159/* Local prototypes */160161static ACPI_STATUS162AcpiUtCopyIsimpleToEsimple (163ACPI_OPERAND_OBJECT *InternalObject,164ACPI_OBJECT *ExternalObject,165UINT8 *DataSpace,166ACPI_SIZE *BufferSpaceUsed);167168static ACPI_STATUS169AcpiUtCopyIelementToIelement (170UINT8 ObjectType,171ACPI_OPERAND_OBJECT *SourceObject,172ACPI_GENERIC_STATE *State,173void *Context);174175static ACPI_STATUS176AcpiUtCopyIpackageToEpackage (177ACPI_OPERAND_OBJECT *InternalObject,178UINT8 *Buffer,179ACPI_SIZE *SpaceUsed);180181static ACPI_STATUS182AcpiUtCopyEsimpleToIsimple(183ACPI_OBJECT *UserObj,184ACPI_OPERAND_OBJECT **ReturnObj);185186static ACPI_STATUS187AcpiUtCopyEpackageToIpackage (188ACPI_OBJECT *ExternalObject,189ACPI_OPERAND_OBJECT **InternalObject);190191static ACPI_STATUS192AcpiUtCopySimpleObject (193ACPI_OPERAND_OBJECT *SourceDesc,194ACPI_OPERAND_OBJECT *DestDesc);195196static ACPI_STATUS197AcpiUtCopyIelementToEelement (198UINT8 ObjectType,199ACPI_OPERAND_OBJECT *SourceObject,200ACPI_GENERIC_STATE *State,201void *Context);202203static ACPI_STATUS204AcpiUtCopyIpackageToIpackage (205ACPI_OPERAND_OBJECT *SourceObj,206ACPI_OPERAND_OBJECT *DestObj,207ACPI_WALK_STATE *WalkState);208209210/*******************************************************************************211*212* FUNCTION: AcpiUtCopyIsimpleToEsimple213*214* PARAMETERS: InternalObject - Source object to be copied215* ExternalObject - Where to return the copied object216* DataSpace - Where object data is returned (such as217* buffer and string data)218* BufferSpaceUsed - Length of DataSpace that was used219*220* RETURN: Status221*222* DESCRIPTION: This function is called to copy a simple internal object to223* an external object.224*225* The DataSpace buffer is assumed to have sufficient space for226* the object.227*228******************************************************************************/229230static ACPI_STATUS231AcpiUtCopyIsimpleToEsimple (232ACPI_OPERAND_OBJECT *InternalObject,233ACPI_OBJECT *ExternalObject,234UINT8 *DataSpace,235ACPI_SIZE *BufferSpaceUsed)236{237ACPI_STATUS Status = AE_OK;238239240ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple);241242243*BufferSpaceUsed = 0;244245/*246* Check for NULL object case (could be an uninitialized247* package element)248*/249if (!InternalObject)250{251return_ACPI_STATUS (AE_OK);252}253254/* Always clear the external object */255256memset (ExternalObject, 0, sizeof (ACPI_OBJECT));257258/*259* In general, the external object will be the same type as260* the internal object261*/262ExternalObject->Type = InternalObject->Common.Type;263264/* However, only a limited number of external types are supported */265266switch (InternalObject->Common.Type)267{268case ACPI_TYPE_STRING:269270ExternalObject->String.Pointer = (char *) DataSpace;271ExternalObject->String.Length = InternalObject->String.Length;272*BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (273(ACPI_SIZE) InternalObject->String.Length + 1);274275memcpy ((void *) DataSpace,276(void *) InternalObject->String.Pointer,277(ACPI_SIZE) InternalObject->String.Length + 1);278break;279280case ACPI_TYPE_BUFFER:281282ExternalObject->Buffer.Pointer = DataSpace;283ExternalObject->Buffer.Length = InternalObject->Buffer.Length;284*BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (285InternalObject->String.Length);286287memcpy ((void *) DataSpace,288(void *) InternalObject->Buffer.Pointer,289InternalObject->Buffer.Length);290break;291292case ACPI_TYPE_INTEGER:293294ExternalObject->Integer.Value = InternalObject->Integer.Value;295break;296297case ACPI_TYPE_LOCAL_REFERENCE:298299/* This is an object reference. */300301switch (InternalObject->Reference.Class)302{303case ACPI_REFCLASS_NAME:304/*305* For namepath, return the object handle ("reference")306* We are referring to the namespace node307*/308ExternalObject->Reference.Handle =309InternalObject->Reference.Node;310ExternalObject->Reference.ActualType =311AcpiNsGetType (InternalObject->Reference.Node);312break;313314default:315316/* All other reference types are unsupported */317318return_ACPI_STATUS (AE_TYPE);319}320break;321322case ACPI_TYPE_PROCESSOR:323324ExternalObject->Processor.ProcId =325InternalObject->Processor.ProcId;326ExternalObject->Processor.PblkAddress =327InternalObject->Processor.Address;328ExternalObject->Processor.PblkLength =329InternalObject->Processor.Length;330break;331332case ACPI_TYPE_POWER:333334ExternalObject->PowerResource.SystemLevel =335InternalObject->PowerResource.SystemLevel;336337ExternalObject->PowerResource.ResourceOrder =338InternalObject->PowerResource.ResourceOrder;339break;340341default:342/*343* There is no corresponding external object type344*/345ACPI_ERROR ((AE_INFO,346"Unsupported object type, cannot convert to external object: %s",347AcpiUtGetTypeName (InternalObject->Common.Type)));348349return_ACPI_STATUS (AE_SUPPORT);350}351352return_ACPI_STATUS (Status);353}354355356/*******************************************************************************357*358* FUNCTION: AcpiUtCopyIelementToEelement359*360* PARAMETERS: ACPI_PKG_CALLBACK361*362* RETURN: Status363*364* DESCRIPTION: Copy one package element to another package element365*366******************************************************************************/367368static ACPI_STATUS369AcpiUtCopyIelementToEelement (370UINT8 ObjectType,371ACPI_OPERAND_OBJECT *SourceObject,372ACPI_GENERIC_STATE *State,373void *Context)374{375ACPI_STATUS Status = AE_OK;376ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;377ACPI_SIZE ObjectSpace;378UINT32 ThisIndex;379ACPI_OBJECT *TargetObject;380381382ACPI_FUNCTION_ENTRY ();383384385ThisIndex = State->Pkg.Index;386TargetObject = (ACPI_OBJECT *) &((ACPI_OBJECT *)387(State->Pkg.DestObject))->Package.Elements[ThisIndex];388389switch (ObjectType)390{391case ACPI_COPY_TYPE_SIMPLE:392/*393* This is a simple or null object394*/395Status = AcpiUtCopyIsimpleToEsimple (SourceObject,396TargetObject, Info->FreeSpace, &ObjectSpace);397if (ACPI_FAILURE (Status))398{399return (Status);400}401break;402403case ACPI_COPY_TYPE_PACKAGE:404/*405* Build the package object406*/407TargetObject->Type = ACPI_TYPE_PACKAGE;408TargetObject->Package.Count = SourceObject->Package.Count;409TargetObject->Package.Elements =410ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);411412/*413* Pass the new package object back to the package walk routine414*/415State->Pkg.ThisTargetObj = TargetObject;416417/*418* Save space for the array of objects (Package elements)419* update the buffer length counter420*/421ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (422(ACPI_SIZE) TargetObject->Package.Count *423sizeof (ACPI_OBJECT));424break;425426default:427428return (AE_BAD_PARAMETER);429}430431Info->FreeSpace += ObjectSpace;432Info->Length += ObjectSpace;433return (Status);434}435436437/*******************************************************************************438*439* FUNCTION: AcpiUtCopyIpackageToEpackage440*441* PARAMETERS: InternalObject - Pointer to the object we are returning442* Buffer - Where the object is returned443* SpaceUsed - Where the object length is returned444*445* RETURN: Status446*447* DESCRIPTION: This function is called to place a package object in a user448* buffer. A package object by definition contains other objects.449*450* The buffer is assumed to have sufficient space for the object.451* The caller must have verified the buffer length needed using452* the AcpiUtGetObjectSize function before calling this function.453*454******************************************************************************/455456static ACPI_STATUS457AcpiUtCopyIpackageToEpackage (458ACPI_OPERAND_OBJECT *InternalObject,459UINT8 *Buffer,460ACPI_SIZE *SpaceUsed)461{462ACPI_OBJECT *ExternalObject;463ACPI_STATUS Status;464ACPI_PKG_INFO Info;465466467ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage);468469470/*471* First package at head of the buffer472*/473ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);474475/*476* Free space begins right after the first package477*/478Info.Length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));479Info.FreeSpace = Buffer +480ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));481Info.ObjectSpace = 0;482Info.NumPackages = 1;483484ExternalObject->Type = InternalObject->Common.Type;485ExternalObject->Package.Count = InternalObject->Package.Count;486ExternalObject->Package.Elements =487ACPI_CAST_PTR (ACPI_OBJECT, Info.FreeSpace);488489/*490* Leave room for an array of ACPI_OBJECTS in the buffer491* and move the free space past it492*/493Info.Length += (ACPI_SIZE) ExternalObject->Package.Count *494ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));495Info.FreeSpace += ExternalObject->Package.Count *496ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));497498Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,499AcpiUtCopyIelementToEelement, &Info);500501*SpaceUsed = Info.Length;502return_ACPI_STATUS (Status);503}504505506/*******************************************************************************507*508* FUNCTION: AcpiUtCopyIobjectToEobject509*510* PARAMETERS: InternalObject - The internal object to be converted511* RetBuffer - Where the object is returned512*513* RETURN: Status514*515* DESCRIPTION: This function is called to build an API object to be returned516* to the caller.517*518******************************************************************************/519520ACPI_STATUS521AcpiUtCopyIobjectToEobject (522ACPI_OPERAND_OBJECT *InternalObject,523ACPI_BUFFER *RetBuffer)524{525ACPI_STATUS Status;526527528ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject);529530531if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)532{533/*534* Package object: Copy all subobjects (including535* nested packages)536*/537Status = AcpiUtCopyIpackageToEpackage (InternalObject,538RetBuffer->Pointer, &RetBuffer->Length);539}540else541{542/*543* Build a simple object (no nested objects)544*/545Status = AcpiUtCopyIsimpleToEsimple (InternalObject,546ACPI_CAST_PTR (ACPI_OBJECT, RetBuffer->Pointer),547ACPI_ADD_PTR (UINT8, RetBuffer->Pointer,548ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),549&RetBuffer->Length);550/*551* build simple does not include the object size in the length552* so we add it in here553*/554RetBuffer->Length += sizeof (ACPI_OBJECT);555}556557return_ACPI_STATUS (Status);558}559560561/*******************************************************************************562*563* FUNCTION: AcpiUtCopyEsimpleToIsimple564*565* PARAMETERS: ExternalObject - The external object to be converted566* RetInternalObject - Where the internal object is returned567*568* RETURN: Status569*570* DESCRIPTION: This function copies an external object to an internal one.571* NOTE: Pointers can be copied, we don't need to copy data.572* (The pointers have to be valid in our address space no matter573* what we do with them!)574*575******************************************************************************/576577static ACPI_STATUS578AcpiUtCopyEsimpleToIsimple (579ACPI_OBJECT *ExternalObject,580ACPI_OPERAND_OBJECT **RetInternalObject)581{582ACPI_OPERAND_OBJECT *InternalObject;583584585ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple);586587588/*589* Simple types supported are: String, Buffer, Integer590*/591switch (ExternalObject->Type)592{593case ACPI_TYPE_STRING:594case ACPI_TYPE_BUFFER:595case ACPI_TYPE_INTEGER:596case ACPI_TYPE_LOCAL_REFERENCE:597598InternalObject = AcpiUtCreateInternalObject (599(UINT8) ExternalObject->Type);600if (!InternalObject)601{602return_ACPI_STATUS (AE_NO_MEMORY);603}604break;605606case ACPI_TYPE_ANY: /* This is the case for a NULL object */607608*RetInternalObject = NULL;609return_ACPI_STATUS (AE_OK);610611default:612613/* All other types are not supported */614615ACPI_ERROR ((AE_INFO,616"Unsupported object type, cannot convert to internal object: %s",617AcpiUtGetTypeName (ExternalObject->Type)));618619return_ACPI_STATUS (AE_SUPPORT);620}621622623/* Must COPY string and buffer contents */624625switch (ExternalObject->Type)626{627case ACPI_TYPE_STRING:628629InternalObject->String.Pointer =630ACPI_ALLOCATE_ZEROED ((ACPI_SIZE)631ExternalObject->String.Length + 1);632633if (!InternalObject->String.Pointer)634{635goto ErrorExit;636}637638memcpy (InternalObject->String.Pointer,639ExternalObject->String.Pointer,640ExternalObject->String.Length);641642InternalObject->String.Length = ExternalObject->String.Length;643break;644645case ACPI_TYPE_BUFFER:646647InternalObject->Buffer.Pointer =648ACPI_ALLOCATE_ZEROED (ExternalObject->Buffer.Length);649if (!InternalObject->Buffer.Pointer)650{651goto ErrorExit;652}653654memcpy (InternalObject->Buffer.Pointer,655ExternalObject->Buffer.Pointer,656ExternalObject->Buffer.Length);657658InternalObject->Buffer.Length = ExternalObject->Buffer.Length;659660/* Mark buffer data valid */661662InternalObject->Buffer.Flags |= AOPOBJ_DATA_VALID;663break;664665case ACPI_TYPE_INTEGER:666667InternalObject->Integer.Value = ExternalObject->Integer.Value;668break;669670case ACPI_TYPE_LOCAL_REFERENCE:671672/* An incoming reference is defined to be a namespace node */673674InternalObject->Reference.Class = ACPI_REFCLASS_REFOF;675InternalObject->Reference.Object = ExternalObject->Reference.Handle;676break;677678default:679680/* Other types can't get here */681682break;683}684685*RetInternalObject = InternalObject;686return_ACPI_STATUS (AE_OK);687688689ErrorExit:690AcpiUtRemoveReference (InternalObject);691return_ACPI_STATUS (AE_NO_MEMORY);692}693694695/*******************************************************************************696*697* FUNCTION: AcpiUtCopyEpackageToIpackage698*699* PARAMETERS: ExternalObject - The external object to be converted700* InternalObject - Where the internal object is returned701*702* RETURN: Status703*704* DESCRIPTION: Copy an external package object to an internal package.705* Handles nested packages.706*707******************************************************************************/708709static ACPI_STATUS710AcpiUtCopyEpackageToIpackage (711ACPI_OBJECT *ExternalObject,712ACPI_OPERAND_OBJECT **InternalObject)713{714ACPI_STATUS Status = AE_OK;715ACPI_OPERAND_OBJECT *PackageObject;716ACPI_OPERAND_OBJECT **PackageElements;717UINT32 i;718719720ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage);721722723/* Create the package object */724725PackageObject = AcpiUtCreatePackageObject (726ExternalObject->Package.Count);727if (!PackageObject)728{729return_ACPI_STATUS (AE_NO_MEMORY);730}731732PackageElements = PackageObject->Package.Elements;733734/*735* Recursive implementation. Probably ok, since nested external736* packages as parameters should be very rare.737*/738for (i = 0; i < ExternalObject->Package.Count; i++)739{740Status = AcpiUtCopyEobjectToIobject (741&ExternalObject->Package.Elements[i],742&PackageElements[i]);743if (ACPI_FAILURE (Status))744{745/* Truncate package and delete it */746747PackageObject->Package.Count = i;748PackageElements[i] = NULL;749AcpiUtRemoveReference (PackageObject);750return_ACPI_STATUS (Status);751}752}753754/* Mark package data valid */755756PackageObject->Package.Flags |= AOPOBJ_DATA_VALID;757758*InternalObject = PackageObject;759return_ACPI_STATUS (Status);760}761762763/*******************************************************************************764*765* FUNCTION: AcpiUtCopyEobjectToIobject766*767* PARAMETERS: ExternalObject - The external object to be converted768* InternalObject - Where the internal object is returned769*770* RETURN: Status771*772* DESCRIPTION: Converts an external object to an internal object.773*774******************************************************************************/775776ACPI_STATUS777AcpiUtCopyEobjectToIobject (778ACPI_OBJECT *ExternalObject,779ACPI_OPERAND_OBJECT **InternalObject)780{781ACPI_STATUS Status;782783784ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject);785786787if (ExternalObject->Type == ACPI_TYPE_PACKAGE)788{789Status = AcpiUtCopyEpackageToIpackage (790ExternalObject, InternalObject);791}792else793{794/*795* Build a simple object (no nested objects)796*/797Status = AcpiUtCopyEsimpleToIsimple (ExternalObject,798InternalObject);799}800801return_ACPI_STATUS (Status);802}803804805/*******************************************************************************806*807* FUNCTION: AcpiUtCopySimpleObject808*809* PARAMETERS: SourceDesc - The internal object to be copied810* DestDesc - New target object811*812* RETURN: Status813*814* DESCRIPTION: Simple copy of one internal object to another. Reference count815* of the destination object is preserved.816*817******************************************************************************/818819static ACPI_STATUS820AcpiUtCopySimpleObject (821ACPI_OPERAND_OBJECT *SourceDesc,822ACPI_OPERAND_OBJECT *DestDesc)823{824UINT16 ReferenceCount;825ACPI_OPERAND_OBJECT *NextObject;826ACPI_STATUS Status;827ACPI_SIZE CopySize;828829830/* Save fields from destination that we don't want to overwrite */831832ReferenceCount = DestDesc->Common.ReferenceCount;833NextObject = DestDesc->Common.NextObject;834835/*836* Copy the entire source object over the destination object.837* Note: Source can be either an operand object or namespace node.838*/839CopySize = sizeof (ACPI_OPERAND_OBJECT);840if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)841{842CopySize = sizeof (ACPI_NAMESPACE_NODE);843}844845memcpy (ACPI_CAST_PTR (char, DestDesc),846ACPI_CAST_PTR (char, SourceDesc), CopySize);847848/* Restore the saved fields */849850DestDesc->Common.ReferenceCount = ReferenceCount;851DestDesc->Common.NextObject = NextObject;852853/* New object is not static, regardless of source */854855DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;856857/* Handle the objects with extra data */858859switch (DestDesc->Common.Type)860{861case ACPI_TYPE_BUFFER:862/*863* Allocate and copy the actual buffer if and only if:864* 1) There is a valid buffer pointer865* 2) The buffer has a length > 0866*/867if ((SourceDesc->Buffer.Pointer) &&868(SourceDesc->Buffer.Length))869{870DestDesc->Buffer.Pointer =871ACPI_ALLOCATE (SourceDesc->Buffer.Length);872if (!DestDesc->Buffer.Pointer)873{874return (AE_NO_MEMORY);875}876877/* Copy the actual buffer data */878879memcpy (DestDesc->Buffer.Pointer,880SourceDesc->Buffer.Pointer, SourceDesc->Buffer.Length);881}882break;883884case ACPI_TYPE_STRING:885/*886* Allocate and copy the actual string if and only if:887* 1) There is a valid string pointer888* (Pointer to a NULL string is allowed)889*/890if (SourceDesc->String.Pointer)891{892DestDesc->String.Pointer =893ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1);894if (!DestDesc->String.Pointer)895{896return (AE_NO_MEMORY);897}898899/* Copy the actual string data */900901memcpy (DestDesc->String.Pointer, SourceDesc->String.Pointer,902(ACPI_SIZE) SourceDesc->String.Length + 1);903}904break;905906case ACPI_TYPE_LOCAL_REFERENCE:907/*908* We copied the reference object, so we now must add a reference909* to the object pointed to by the reference910*911* DDBHandle reference (from Load/LoadTable) is a special reference,912* it does not have a Reference.Object, so does not need to913* increase the reference count914*/915if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)916{917break;918}919920AcpiUtAddReference (SourceDesc->Reference.Object);921break;922923case ACPI_TYPE_REGION:924/*925* We copied the Region Handler, so we now must add a reference926*/927if (DestDesc->Region.Handler)928{929AcpiUtAddReference (DestDesc->Region.Handler);930}931break;932933/*934* For Mutex and Event objects, we cannot simply copy the underlying935* OS object. We must create a new one.936*/937case ACPI_TYPE_MUTEX:938939Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex);940if (ACPI_FAILURE (Status))941{942return (Status);943}944break;945946case ACPI_TYPE_EVENT:947948Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,949&DestDesc->Event.OsSemaphore);950if (ACPI_FAILURE (Status))951{952return (Status);953}954break;955956default:957958/* Nothing to do for other simple objects */959960break;961}962963return (AE_OK);964}965966967/*******************************************************************************968*969* FUNCTION: AcpiUtCopyIelementToIelement970*971* PARAMETERS: ACPI_PKG_CALLBACK972*973* RETURN: Status974*975* DESCRIPTION: Copy one package element to another package element976*977******************************************************************************/978979static ACPI_STATUS980AcpiUtCopyIelementToIelement (981UINT8 ObjectType,982ACPI_OPERAND_OBJECT *SourceObject,983ACPI_GENERIC_STATE *State,984void *Context)985{986ACPI_STATUS Status = AE_OK;987UINT32 ThisIndex;988ACPI_OPERAND_OBJECT **ThisTargetPtr;989ACPI_OPERAND_OBJECT *TargetObject;990991992ACPI_FUNCTION_ENTRY ();993994995ThisIndex = State->Pkg.Index;996ThisTargetPtr = (ACPI_OPERAND_OBJECT **)997&State->Pkg.DestObject->Package.Elements[ThisIndex];998999switch (ObjectType)1000{1001case ACPI_COPY_TYPE_SIMPLE:10021003/* A null source object indicates a (legal) null package element */10041005if (SourceObject)1006{1007/*1008* This is a simple object, just copy it1009*/1010TargetObject = AcpiUtCreateInternalObject (1011SourceObject->Common.Type);1012if (!TargetObject)1013{1014return (AE_NO_MEMORY);1015}10161017Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);1018if (ACPI_FAILURE (Status))1019{1020goto ErrorExit;1021}10221023*ThisTargetPtr = TargetObject;1024}1025else1026{1027/* Pass through a null element */10281029*ThisTargetPtr = NULL;1030}1031break;10321033case ACPI_COPY_TYPE_PACKAGE:1034/*1035* This object is a package - go down another nesting level1036* Create and build the package object1037*/1038TargetObject = AcpiUtCreatePackageObject (1039SourceObject->Package.Count);1040if (!TargetObject)1041{1042return (AE_NO_MEMORY);1043}10441045TargetObject->Common.Flags = SourceObject->Common.Flags;10461047/* Pass the new package object back to the package walk routine */10481049State->Pkg.ThisTargetObj = TargetObject;10501051/* Store the object pointer in the parent package object */10521053*ThisTargetPtr = TargetObject;1054break;10551056default:10571058return (AE_BAD_PARAMETER);1059}10601061return (Status);10621063ErrorExit:1064AcpiUtRemoveReference (TargetObject);1065return (Status);1066}106710681069/*******************************************************************************1070*1071* FUNCTION: AcpiUtCopyIpackageToIpackage1072*1073* PARAMETERS: SourceObj - Pointer to the source package object1074* DestObj - Where the internal object is returned1075* WalkState - Current Walk state descriptor1076*1077* RETURN: Status1078*1079* DESCRIPTION: This function is called to copy an internal package object1080* into another internal package object.1081*1082******************************************************************************/10831084static ACPI_STATUS1085AcpiUtCopyIpackageToIpackage (1086ACPI_OPERAND_OBJECT *SourceObj,1087ACPI_OPERAND_OBJECT *DestObj,1088ACPI_WALK_STATE *WalkState)1089{1090ACPI_STATUS Status = AE_OK;109110921093ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage);109410951096DestObj->Common.Type = SourceObj->Common.Type;1097DestObj->Common.Flags = SourceObj->Common.Flags;1098DestObj->Package.Count = SourceObj->Package.Count;10991100/*1101* Create the object array and walk the source package tree1102*/1103DestObj->Package.Elements = ACPI_ALLOCATE_ZEROED (1104((ACPI_SIZE) SourceObj->Package.Count + 1) *1105sizeof (void *));1106if (!DestObj->Package.Elements)1107{1108ACPI_ERROR ((AE_INFO, "Package allocation failure"));1109return_ACPI_STATUS (AE_NO_MEMORY);1110}11111112/*1113* Copy the package element-by-element by walking the package "tree".1114* This handles nested packages of arbitrary depth.1115*/1116Status = AcpiUtWalkPackageTree (SourceObj, DestObj,1117AcpiUtCopyIelementToIelement, WalkState);1118if (ACPI_FAILURE (Status))1119{1120/* On failure, delete the destination package object */11211122AcpiUtRemoveReference (DestObj);1123}11241125return_ACPI_STATUS (Status);1126}112711281129/*******************************************************************************1130*1131* FUNCTION: AcpiUtCopyIobjectToIobject1132*1133* PARAMETERS: SourceDesc - The internal object to be copied1134* DestDesc - Where the copied object is returned1135* WalkState - Current walk state1136*1137* RETURN: Status1138*1139* DESCRIPTION: Copy an internal object to a new internal object1140*1141******************************************************************************/11421143ACPI_STATUS1144AcpiUtCopyIobjectToIobject (1145ACPI_OPERAND_OBJECT *SourceDesc,1146ACPI_OPERAND_OBJECT **DestDesc,1147ACPI_WALK_STATE *WalkState)1148{1149ACPI_STATUS Status = AE_OK;115011511152ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject);115311541155/* Create the top level object */11561157*DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type);1158if (!*DestDesc)1159{1160return_ACPI_STATUS (AE_NO_MEMORY);1161}11621163/* Copy the object and possible subobjects */11641165if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE)1166{1167Status = AcpiUtCopyIpackageToIpackage (1168SourceDesc, *DestDesc, WalkState);1169}1170else1171{1172Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);1173}11741175/* Delete the allocated object if copy failed */11761177if (ACPI_FAILURE (Status))1178{1179AcpiUtRemoveReference (*DestDesc);1180}11811182return_ACPI_STATUS (Status);1183}118411851186