1ae115bc7Smrj /****************************************************************************** 2ae115bc7Smrj * 3ae115bc7Smrj * Module Name: utcopy - Internal to external object translation utilities 4ae115bc7Smrj * 5ae115bc7Smrj *****************************************************************************/ 6ae115bc7Smrj 726f3cdf0SGordon Ross /* 8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp. 9ae115bc7Smrj * All rights reserved. 10ae115bc7Smrj * 1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without 1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions 1326f3cdf0SGordon Ross * are met: 1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright 1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer, 1626f3cdf0SGordon Ross * without modification. 1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below 1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon 2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further 2126f3cdf0SGordon Ross * binary redistribution. 2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names 2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived 2426f3cdf0SGordon Ross * from this software without specific prior written permission. 25ae115bc7Smrj * 2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the 2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free 2826f3cdf0SGordon Ross * Software Foundation. 29ae115bc7Smrj * 3026f3cdf0SGordon Ross * NO WARRANTY 3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES. 4226f3cdf0SGordon Ross */ 43ae115bc7Smrj 44ae115bc7Smrj #include "acpi.h" 45aa2aa9a6SDana Myers #include "accommon.h" 46db2bae30SDana Myers #include "acnamesp.h" 47ae115bc7Smrj 48ae115bc7Smrj 49ae115bc7Smrj #define _COMPONENT ACPI_UTILITIES 50ae115bc7Smrj ACPI_MODULE_NAME ("utcopy") 51ae115bc7Smrj 52ae115bc7Smrj /* Local prototypes */ 53ae115bc7Smrj 54ae115bc7Smrj static ACPI_STATUS 55ae115bc7Smrj AcpiUtCopyIsimpleToEsimple ( 56ae115bc7Smrj ACPI_OPERAND_OBJECT *InternalObject, 57ae115bc7Smrj ACPI_OBJECT *ExternalObject, 58ae115bc7Smrj UINT8 *DataSpace, 59ae115bc7Smrj ACPI_SIZE *BufferSpaceUsed); 60ae115bc7Smrj 61ae115bc7Smrj static ACPI_STATUS 62ae115bc7Smrj AcpiUtCopyIelementToIelement ( 63ae115bc7Smrj UINT8 ObjectType, 64ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceObject, 65ae115bc7Smrj ACPI_GENERIC_STATE *State, 66ae115bc7Smrj void *Context); 67ae115bc7Smrj 68ae115bc7Smrj static ACPI_STATUS 69ae115bc7Smrj AcpiUtCopyIpackageToEpackage ( 70ae115bc7Smrj ACPI_OPERAND_OBJECT *InternalObject, 71ae115bc7Smrj UINT8 *Buffer, 72ae115bc7Smrj ACPI_SIZE *SpaceUsed); 73ae115bc7Smrj 74ae115bc7Smrj static ACPI_STATUS 75ae115bc7Smrj AcpiUtCopyEsimpleToIsimple( 76ae115bc7Smrj ACPI_OBJECT *UserObj, 77ae115bc7Smrj ACPI_OPERAND_OBJECT **ReturnObj); 78ae115bc7Smrj 79ae115bc7Smrj static ACPI_STATUS 80db2bae30SDana Myers AcpiUtCopyEpackageToIpackage ( 81db2bae30SDana Myers ACPI_OBJECT *ExternalObject, 82db2bae30SDana Myers ACPI_OPERAND_OBJECT **InternalObject); 83db2bae30SDana Myers 84db2bae30SDana Myers static ACPI_STATUS 85ae115bc7Smrj AcpiUtCopySimpleObject ( 86ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceDesc, 87ae115bc7Smrj ACPI_OPERAND_OBJECT *DestDesc); 88ae115bc7Smrj 89ae115bc7Smrj static ACPI_STATUS 90ae115bc7Smrj AcpiUtCopyIelementToEelement ( 91ae115bc7Smrj UINT8 ObjectType, 92ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceObject, 93ae115bc7Smrj ACPI_GENERIC_STATE *State, 94ae115bc7Smrj void *Context); 95ae115bc7Smrj 96ae115bc7Smrj static ACPI_STATUS 97ae115bc7Smrj AcpiUtCopyIpackageToIpackage ( 98ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceObj, 99ae115bc7Smrj ACPI_OPERAND_OBJECT *DestObj, 100ae115bc7Smrj ACPI_WALK_STATE *WalkState); 101ae115bc7Smrj 102ae115bc7Smrj 103ae115bc7Smrj /******************************************************************************* 104ae115bc7Smrj * 105ae115bc7Smrj * FUNCTION: AcpiUtCopyIsimpleToEsimple 106ae115bc7Smrj * 107ae115bc7Smrj * PARAMETERS: InternalObject - Source object to be copied 108ae115bc7Smrj * ExternalObject - Where to return the copied object 109ae115bc7Smrj * DataSpace - Where object data is returned (such as 110ae115bc7Smrj * buffer and string data) 111ae115bc7Smrj * BufferSpaceUsed - Length of DataSpace that was used 112ae115bc7Smrj * 113ae115bc7Smrj * RETURN: Status 114ae115bc7Smrj * 115ae115bc7Smrj * DESCRIPTION: This function is called to copy a simple internal object to 116ae115bc7Smrj * an external object. 117ae115bc7Smrj * 118ae115bc7Smrj * The DataSpace buffer is assumed to have sufficient space for 119ae115bc7Smrj * the object. 120ae115bc7Smrj * 121ae115bc7Smrj ******************************************************************************/ 122ae115bc7Smrj 123ae115bc7Smrj static ACPI_STATUS 124ae115bc7Smrj AcpiUtCopyIsimpleToEsimple ( 125ae115bc7Smrj ACPI_OPERAND_OBJECT *InternalObject, 126ae115bc7Smrj ACPI_OBJECT *ExternalObject, 127ae115bc7Smrj UINT8 *DataSpace, 128ae115bc7Smrj ACPI_SIZE *BufferSpaceUsed) 129ae115bc7Smrj { 130ae115bc7Smrj ACPI_STATUS Status = AE_OK; 131ae115bc7Smrj 132ae115bc7Smrj 133ae115bc7Smrj ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple); 134ae115bc7Smrj 135ae115bc7Smrj 136ae115bc7Smrj *BufferSpaceUsed = 0; 137ae115bc7Smrj 138ae115bc7Smrj /* 139ae115bc7Smrj * Check for NULL object case (could be an uninitialized 140ae115bc7Smrj * package element) 141ae115bc7Smrj */ 142ae115bc7Smrj if (!InternalObject) 143ae115bc7Smrj { 144ae115bc7Smrj return_ACPI_STATUS (AE_OK); 145ae115bc7Smrj } 146ae115bc7Smrj 147ae115bc7Smrj /* Always clear the external object */ 148ae115bc7Smrj 149*385cc6b4SJerry Jelinek memset (ExternalObject, 0, sizeof (ACPI_OBJECT)); 150ae115bc7Smrj 151ae115bc7Smrj /* 152ae115bc7Smrj * In general, the external object will be the same type as 153ae115bc7Smrj * the internal object 154ae115bc7Smrj */ 155aa2aa9a6SDana Myers ExternalObject->Type = InternalObject->Common.Type; 156ae115bc7Smrj 157ae115bc7Smrj /* However, only a limited number of external types are supported */ 158ae115bc7Smrj 159aa2aa9a6SDana Myers switch (InternalObject->Common.Type) 160ae115bc7Smrj { 161ae115bc7Smrj case ACPI_TYPE_STRING: 162ae115bc7Smrj 163ae115bc7Smrj ExternalObject->String.Pointer = (char *) DataSpace; 164ae115bc7Smrj ExternalObject->String.Length = InternalObject->String.Length; 165ae115bc7Smrj *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD ( 166ae115bc7Smrj (ACPI_SIZE) InternalObject->String.Length + 1); 167ae115bc7Smrj 168*385cc6b4SJerry Jelinek memcpy ((void *) DataSpace, 169ae115bc7Smrj (void *) InternalObject->String.Pointer, 170ae115bc7Smrj (ACPI_SIZE) InternalObject->String.Length + 1); 171ae115bc7Smrj break; 172ae115bc7Smrj 173ae115bc7Smrj case ACPI_TYPE_BUFFER: 174ae115bc7Smrj 175ae115bc7Smrj ExternalObject->Buffer.Pointer = DataSpace; 176ae115bc7Smrj ExternalObject->Buffer.Length = InternalObject->Buffer.Length; 177ae115bc7Smrj *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD ( 178ae115bc7Smrj InternalObject->String.Length); 179ae115bc7Smrj 180*385cc6b4SJerry Jelinek memcpy ((void *) DataSpace, 181ae115bc7Smrj (void *) InternalObject->Buffer.Pointer, 182ae115bc7Smrj InternalObject->Buffer.Length); 183ae115bc7Smrj break; 184ae115bc7Smrj 185ae115bc7Smrj case ACPI_TYPE_INTEGER: 186ae115bc7Smrj 187ae115bc7Smrj ExternalObject->Integer.Value = InternalObject->Integer.Value; 188ae115bc7Smrj break; 189ae115bc7Smrj 190ae115bc7Smrj case ACPI_TYPE_LOCAL_REFERENCE: 191ae115bc7Smrj 192db2bae30SDana Myers /* This is an object reference. */ 193ae115bc7Smrj 194db2bae30SDana Myers switch (InternalObject->Reference.Class) 195db2bae30SDana Myers { 196db2bae30SDana Myers case ACPI_REFCLASS_NAME: 197db2bae30SDana Myers /* 198db2bae30SDana Myers * For namepath, return the object handle ("reference") 199db2bae30SDana Myers * We are referring to the namespace node 200db2bae30SDana Myers */ 201db2bae30SDana Myers ExternalObject->Reference.Handle = 202db2bae30SDana Myers InternalObject->Reference.Node; 203db2bae30SDana Myers ExternalObject->Reference.ActualType = 204db2bae30SDana Myers AcpiNsGetType (InternalObject->Reference.Node); 205db2bae30SDana Myers break; 206ae115bc7Smrj 207ae115bc7Smrj default: 208db2bae30SDana Myers 209db2bae30SDana Myers /* All other reference types are unsupported */ 210db2bae30SDana Myers 211db2bae30SDana Myers return_ACPI_STATUS (AE_TYPE); 212ae115bc7Smrj } 213ae115bc7Smrj break; 214ae115bc7Smrj 215ae115bc7Smrj case ACPI_TYPE_PROCESSOR: 216ae115bc7Smrj 217db2bae30SDana Myers ExternalObject->Processor.ProcId = 218db2bae30SDana Myers InternalObject->Processor.ProcId; 219db2bae30SDana Myers ExternalObject->Processor.PblkAddress = 220db2bae30SDana Myers InternalObject->Processor.Address; 221db2bae30SDana Myers ExternalObject->Processor.PblkLength = 222db2bae30SDana Myers InternalObject->Processor.Length; 223ae115bc7Smrj break; 224ae115bc7Smrj 225ae115bc7Smrj case ACPI_TYPE_POWER: 226ae115bc7Smrj 227ae115bc7Smrj ExternalObject->PowerResource.SystemLevel = 228ae115bc7Smrj InternalObject->PowerResource.SystemLevel; 229ae115bc7Smrj 230ae115bc7Smrj ExternalObject->PowerResource.ResourceOrder = 231ae115bc7Smrj InternalObject->PowerResource.ResourceOrder; 232ae115bc7Smrj break; 233ae115bc7Smrj 234ae115bc7Smrj default: 235ae115bc7Smrj /* 236ae115bc7Smrj * There is no corresponding external object type 237ae115bc7Smrj */ 238db2bae30SDana Myers ACPI_ERROR ((AE_INFO, 239db2bae30SDana Myers "Unsupported object type, cannot convert to external object: %s", 240aa2aa9a6SDana Myers AcpiUtGetTypeName (InternalObject->Common.Type))); 241db2bae30SDana Myers 242ae115bc7Smrj return_ACPI_STATUS (AE_SUPPORT); 243ae115bc7Smrj } 244ae115bc7Smrj 245ae115bc7Smrj return_ACPI_STATUS (Status); 246ae115bc7Smrj } 247ae115bc7Smrj 248ae115bc7Smrj 249ae115bc7Smrj /******************************************************************************* 250ae115bc7Smrj * 251ae115bc7Smrj * FUNCTION: AcpiUtCopyIelementToEelement 252ae115bc7Smrj * 253ae115bc7Smrj * PARAMETERS: ACPI_PKG_CALLBACK 254ae115bc7Smrj * 255ae115bc7Smrj * RETURN: Status 256ae115bc7Smrj * 257ae115bc7Smrj * DESCRIPTION: Copy one package element to another package element 258ae115bc7Smrj * 259ae115bc7Smrj ******************************************************************************/ 260ae115bc7Smrj 261ae115bc7Smrj static ACPI_STATUS 262ae115bc7Smrj AcpiUtCopyIelementToEelement ( 263ae115bc7Smrj UINT8 ObjectType, 264ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceObject, 265ae115bc7Smrj ACPI_GENERIC_STATE *State, 266ae115bc7Smrj void *Context) 267ae115bc7Smrj { 268ae115bc7Smrj ACPI_STATUS Status = AE_OK; 269ae115bc7Smrj ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context; 270ae115bc7Smrj ACPI_SIZE ObjectSpace; 271ae115bc7Smrj UINT32 ThisIndex; 272ae115bc7Smrj ACPI_OBJECT *TargetObject; 273ae115bc7Smrj 274ae115bc7Smrj 275ae115bc7Smrj ACPI_FUNCTION_ENTRY (); 276ae115bc7Smrj 277ae115bc7Smrj 278ae115bc7Smrj ThisIndex = State->Pkg.Index; 279*385cc6b4SJerry Jelinek TargetObject = (ACPI_OBJECT *) &((ACPI_OBJECT *) 280*385cc6b4SJerry Jelinek (State->Pkg.DestObject))->Package.Elements[ThisIndex]; 281ae115bc7Smrj 282ae115bc7Smrj switch (ObjectType) 283ae115bc7Smrj { 284ae115bc7Smrj case ACPI_COPY_TYPE_SIMPLE: 285ae115bc7Smrj /* 286ae115bc7Smrj * This is a simple or null object 287ae115bc7Smrj */ 288ae115bc7Smrj Status = AcpiUtCopyIsimpleToEsimple (SourceObject, 289ae115bc7Smrj TargetObject, Info->FreeSpace, &ObjectSpace); 290ae115bc7Smrj if (ACPI_FAILURE (Status)) 291ae115bc7Smrj { 292ae115bc7Smrj return (Status); 293ae115bc7Smrj } 294ae115bc7Smrj break; 295ae115bc7Smrj 296ae115bc7Smrj case ACPI_COPY_TYPE_PACKAGE: 297ae115bc7Smrj /* 298ae115bc7Smrj * Build the package object 299ae115bc7Smrj */ 300ae115bc7Smrj TargetObject->Type = ACPI_TYPE_PACKAGE; 301ae115bc7Smrj TargetObject->Package.Count = SourceObject->Package.Count; 302ae115bc7Smrj TargetObject->Package.Elements = 303ae115bc7Smrj ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace); 304ae115bc7Smrj 305ae115bc7Smrj /* 306ae115bc7Smrj * Pass the new package object back to the package walk routine 307ae115bc7Smrj */ 308ae115bc7Smrj State->Pkg.ThisTargetObj = TargetObject; 309ae115bc7Smrj 310ae115bc7Smrj /* 311ae115bc7Smrj * Save space for the array of objects (Package elements) 312ae115bc7Smrj * update the buffer length counter 313ae115bc7Smrj */ 314ae115bc7Smrj ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD ( 315ae115bc7Smrj (ACPI_SIZE) TargetObject->Package.Count * 316ae115bc7Smrj sizeof (ACPI_OBJECT)); 317ae115bc7Smrj break; 318ae115bc7Smrj 319ae115bc7Smrj default: 320*385cc6b4SJerry Jelinek 321ae115bc7Smrj return (AE_BAD_PARAMETER); 322ae115bc7Smrj } 323ae115bc7Smrj 324ae115bc7Smrj Info->FreeSpace += ObjectSpace; 325ae115bc7Smrj Info->Length += ObjectSpace; 326ae115bc7Smrj return (Status); 327ae115bc7Smrj } 328ae115bc7Smrj 329ae115bc7Smrj 330ae115bc7Smrj /******************************************************************************* 331ae115bc7Smrj * 332ae115bc7Smrj * FUNCTION: AcpiUtCopyIpackageToEpackage 333ae115bc7Smrj * 334ae115bc7Smrj * PARAMETERS: InternalObject - Pointer to the object we are returning 335ae115bc7Smrj * Buffer - Where the object is returned 336ae115bc7Smrj * SpaceUsed - Where the object length is returned 337ae115bc7Smrj * 338ae115bc7Smrj * RETURN: Status 339ae115bc7Smrj * 340ae115bc7Smrj * DESCRIPTION: This function is called to place a package object in a user 341ae115bc7Smrj * buffer. A package object by definition contains other objects. 342ae115bc7Smrj * 343ae115bc7Smrj * The buffer is assumed to have sufficient space for the object. 34426f3cdf0SGordon Ross * The caller must have verified the buffer length needed using 34526f3cdf0SGordon Ross * the AcpiUtGetObjectSize function before calling this function. 346ae115bc7Smrj * 347ae115bc7Smrj ******************************************************************************/ 348ae115bc7Smrj 349ae115bc7Smrj static ACPI_STATUS 350ae115bc7Smrj AcpiUtCopyIpackageToEpackage ( 351ae115bc7Smrj ACPI_OPERAND_OBJECT *InternalObject, 352ae115bc7Smrj UINT8 *Buffer, 353ae115bc7Smrj ACPI_SIZE *SpaceUsed) 354ae115bc7Smrj { 355ae115bc7Smrj ACPI_OBJECT *ExternalObject; 356ae115bc7Smrj ACPI_STATUS Status; 357ae115bc7Smrj ACPI_PKG_INFO Info; 358ae115bc7Smrj 359ae115bc7Smrj 360ae115bc7Smrj ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage); 361ae115bc7Smrj 362ae115bc7Smrj 363ae115bc7Smrj /* 364ae115bc7Smrj * First package at head of the buffer 365ae115bc7Smrj */ 366ae115bc7Smrj ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer); 367ae115bc7Smrj 368ae115bc7Smrj /* 369ae115bc7Smrj * Free space begins right after the first package 370ae115bc7Smrj */ 371ae115bc7Smrj Info.Length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 372*385cc6b4SJerry Jelinek Info.FreeSpace = Buffer + 373*385cc6b4SJerry Jelinek ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 374ae115bc7Smrj Info.ObjectSpace = 0; 375ae115bc7Smrj Info.NumPackages = 1; 376ae115bc7Smrj 377aa2aa9a6SDana Myers ExternalObject->Type = InternalObject->Common.Type; 378ae115bc7Smrj ExternalObject->Package.Count = InternalObject->Package.Count; 379*385cc6b4SJerry Jelinek ExternalObject->Package.Elements = 380*385cc6b4SJerry Jelinek ACPI_CAST_PTR (ACPI_OBJECT, Info.FreeSpace); 381ae115bc7Smrj 382ae115bc7Smrj /* 383ae115bc7Smrj * Leave room for an array of ACPI_OBJECTS in the buffer 384ae115bc7Smrj * and move the free space past it 385ae115bc7Smrj */ 386ae115bc7Smrj Info.Length += (ACPI_SIZE) ExternalObject->Package.Count * 387ae115bc7Smrj ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 388ae115bc7Smrj Info.FreeSpace += ExternalObject->Package.Count * 389ae115bc7Smrj ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 390ae115bc7Smrj 391ae115bc7Smrj Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject, 392ae115bc7Smrj AcpiUtCopyIelementToEelement, &Info); 393ae115bc7Smrj 394ae115bc7Smrj *SpaceUsed = Info.Length; 395ae115bc7Smrj return_ACPI_STATUS (Status); 396ae115bc7Smrj } 397ae115bc7Smrj 398ae115bc7Smrj 399ae115bc7Smrj /******************************************************************************* 400ae115bc7Smrj * 401ae115bc7Smrj * FUNCTION: AcpiUtCopyIobjectToEobject 402ae115bc7Smrj * 403ae115bc7Smrj * PARAMETERS: InternalObject - The internal object to be converted 40426f3cdf0SGordon Ross * RetBuffer - Where the object is returned 405ae115bc7Smrj * 406ae115bc7Smrj * RETURN: Status 407ae115bc7Smrj * 40826f3cdf0SGordon Ross * DESCRIPTION: This function is called to build an API object to be returned 40926f3cdf0SGordon Ross * to the caller. 410ae115bc7Smrj * 411ae115bc7Smrj ******************************************************************************/ 412ae115bc7Smrj 413ae115bc7Smrj ACPI_STATUS 414ae115bc7Smrj AcpiUtCopyIobjectToEobject ( 415ae115bc7Smrj ACPI_OPERAND_OBJECT *InternalObject, 416ae115bc7Smrj ACPI_BUFFER *RetBuffer) 417ae115bc7Smrj { 418ae115bc7Smrj ACPI_STATUS Status; 419ae115bc7Smrj 420ae115bc7Smrj 421ae115bc7Smrj ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject); 422ae115bc7Smrj 423ae115bc7Smrj 424aa2aa9a6SDana Myers if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE) 425ae115bc7Smrj { 426ae115bc7Smrj /* 427ae115bc7Smrj * Package object: Copy all subobjects (including 428ae115bc7Smrj * nested packages) 429ae115bc7Smrj */ 430ae115bc7Smrj Status = AcpiUtCopyIpackageToEpackage (InternalObject, 431ae115bc7Smrj RetBuffer->Pointer, &RetBuffer->Length); 432ae115bc7Smrj } 433ae115bc7Smrj else 434ae115bc7Smrj { 435ae115bc7Smrj /* 436ae115bc7Smrj * Build a simple object (no nested objects) 437ae115bc7Smrj */ 438ae115bc7Smrj Status = AcpiUtCopyIsimpleToEsimple (InternalObject, 439ae115bc7Smrj ACPI_CAST_PTR (ACPI_OBJECT, RetBuffer->Pointer), 440ae115bc7Smrj ACPI_ADD_PTR (UINT8, RetBuffer->Pointer, 441ae115bc7Smrj ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))), 442ae115bc7Smrj &RetBuffer->Length); 443ae115bc7Smrj /* 444ae115bc7Smrj * build simple does not include the object size in the length 445ae115bc7Smrj * so we add it in here 446ae115bc7Smrj */ 447ae115bc7Smrj RetBuffer->Length += sizeof (ACPI_OBJECT); 448ae115bc7Smrj } 449ae115bc7Smrj 450ae115bc7Smrj return_ACPI_STATUS (Status); 451ae115bc7Smrj } 452ae115bc7Smrj 453ae115bc7Smrj 454ae115bc7Smrj /******************************************************************************* 455ae115bc7Smrj * 456ae115bc7Smrj * FUNCTION: AcpiUtCopyEsimpleToIsimple 457ae115bc7Smrj * 458ae115bc7Smrj * PARAMETERS: ExternalObject - The external object to be converted 459ae115bc7Smrj * RetInternalObject - Where the internal object is returned 460ae115bc7Smrj * 461ae115bc7Smrj * RETURN: Status 462ae115bc7Smrj * 463ae115bc7Smrj * DESCRIPTION: This function copies an external object to an internal one. 464ae115bc7Smrj * NOTE: Pointers can be copied, we don't need to copy data. 465ae115bc7Smrj * (The pointers have to be valid in our address space no matter 466ae115bc7Smrj * what we do with them!) 467ae115bc7Smrj * 468ae115bc7Smrj ******************************************************************************/ 469ae115bc7Smrj 470ae115bc7Smrj static ACPI_STATUS 471ae115bc7Smrj AcpiUtCopyEsimpleToIsimple ( 472ae115bc7Smrj ACPI_OBJECT *ExternalObject, 473ae115bc7Smrj ACPI_OPERAND_OBJECT **RetInternalObject) 474ae115bc7Smrj { 475ae115bc7Smrj ACPI_OPERAND_OBJECT *InternalObject; 476ae115bc7Smrj 477ae115bc7Smrj 478ae115bc7Smrj ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple); 479ae115bc7Smrj 480ae115bc7Smrj 481ae115bc7Smrj /* 482ae115bc7Smrj * Simple types supported are: String, Buffer, Integer 483ae115bc7Smrj */ 484ae115bc7Smrj switch (ExternalObject->Type) 485ae115bc7Smrj { 486ae115bc7Smrj case ACPI_TYPE_STRING: 487ae115bc7Smrj case ACPI_TYPE_BUFFER: 488ae115bc7Smrj case ACPI_TYPE_INTEGER: 489db2bae30SDana Myers case ACPI_TYPE_LOCAL_REFERENCE: 490ae115bc7Smrj 491ae115bc7Smrj InternalObject = AcpiUtCreateInternalObject ( 492ae115bc7Smrj (UINT8) ExternalObject->Type); 493ae115bc7Smrj if (!InternalObject) 494ae115bc7Smrj { 495ae115bc7Smrj return_ACPI_STATUS (AE_NO_MEMORY); 496ae115bc7Smrj } 497ae115bc7Smrj break; 498ae115bc7Smrj 499db2bae30SDana Myers case ACPI_TYPE_ANY: /* This is the case for a NULL object */ 500db2bae30SDana Myers 501db2bae30SDana Myers *RetInternalObject = NULL; 502db2bae30SDana Myers return_ACPI_STATUS (AE_OK); 503db2bae30SDana Myers 504ae115bc7Smrj default: 505*385cc6b4SJerry Jelinek 506ae115bc7Smrj /* All other types are not supported */ 507ae115bc7Smrj 508aa2aa9a6SDana Myers ACPI_ERROR ((AE_INFO, 509aa2aa9a6SDana Myers "Unsupported object type, cannot convert to internal object: %s", 510db2bae30SDana Myers AcpiUtGetTypeName (ExternalObject->Type))); 511db2bae30SDana Myers 512ae115bc7Smrj return_ACPI_STATUS (AE_SUPPORT); 513ae115bc7Smrj } 514ae115bc7Smrj 515ae115bc7Smrj 516ae115bc7Smrj /* Must COPY string and buffer contents */ 517ae115bc7Smrj 518ae115bc7Smrj switch (ExternalObject->Type) 519ae115bc7Smrj { 520ae115bc7Smrj case ACPI_TYPE_STRING: 521ae115bc7Smrj 522ae115bc7Smrj InternalObject->String.Pointer = 523aa2aa9a6SDana Myers ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) 524aa2aa9a6SDana Myers ExternalObject->String.Length + 1); 525aa2aa9a6SDana Myers 526ae115bc7Smrj if (!InternalObject->String.Pointer) 527ae115bc7Smrj { 528ae115bc7Smrj goto ErrorExit; 529ae115bc7Smrj } 530ae115bc7Smrj 531*385cc6b4SJerry Jelinek memcpy (InternalObject->String.Pointer, 532ae115bc7Smrj ExternalObject->String.Pointer, 533ae115bc7Smrj ExternalObject->String.Length); 534ae115bc7Smrj 535ae115bc7Smrj InternalObject->String.Length = ExternalObject->String.Length; 536ae115bc7Smrj break; 537ae115bc7Smrj 538ae115bc7Smrj case ACPI_TYPE_BUFFER: 539ae115bc7Smrj 540ae115bc7Smrj InternalObject->Buffer.Pointer = 541ae115bc7Smrj ACPI_ALLOCATE_ZEROED (ExternalObject->Buffer.Length); 542ae115bc7Smrj if (!InternalObject->Buffer.Pointer) 543ae115bc7Smrj { 544ae115bc7Smrj goto ErrorExit; 545ae115bc7Smrj } 546ae115bc7Smrj 547*385cc6b4SJerry Jelinek memcpy (InternalObject->Buffer.Pointer, 548ae115bc7Smrj ExternalObject->Buffer.Pointer, 549ae115bc7Smrj ExternalObject->Buffer.Length); 550ae115bc7Smrj 551ae115bc7Smrj InternalObject->Buffer.Length = ExternalObject->Buffer.Length; 552db2bae30SDana Myers 553db2bae30SDana Myers /* Mark buffer data valid */ 554db2bae30SDana Myers 555db2bae30SDana Myers InternalObject->Buffer.Flags |= AOPOBJ_DATA_VALID; 556ae115bc7Smrj break; 557ae115bc7Smrj 558ae115bc7Smrj case ACPI_TYPE_INTEGER: 559ae115bc7Smrj 560ae115bc7Smrj InternalObject->Integer.Value = ExternalObject->Integer.Value; 561ae115bc7Smrj break; 562ae115bc7Smrj 563db2bae30SDana Myers case ACPI_TYPE_LOCAL_REFERENCE: 564db2bae30SDana Myers 565*385cc6b4SJerry Jelinek /* An incoming reference is defined to be a namespace node */ 566db2bae30SDana Myers 567*385cc6b4SJerry Jelinek InternalObject->Reference.Class = ACPI_REFCLASS_REFOF; 568*385cc6b4SJerry Jelinek InternalObject->Reference.Object = ExternalObject->Reference.Handle; 569db2bae30SDana Myers break; 570db2bae30SDana Myers 571ae115bc7Smrj default: 572*385cc6b4SJerry Jelinek 573ae115bc7Smrj /* Other types can't get here */ 574*385cc6b4SJerry Jelinek 575ae115bc7Smrj break; 576ae115bc7Smrj } 577ae115bc7Smrj 578ae115bc7Smrj *RetInternalObject = InternalObject; 579ae115bc7Smrj return_ACPI_STATUS (AE_OK); 580ae115bc7Smrj 581ae115bc7Smrj 582ae115bc7Smrj ErrorExit: 583ae115bc7Smrj AcpiUtRemoveReference (InternalObject); 584ae115bc7Smrj return_ACPI_STATUS (AE_NO_MEMORY); 585ae115bc7Smrj } 586ae115bc7Smrj 587ae115bc7Smrj 588ae115bc7Smrj /******************************************************************************* 589ae115bc7Smrj * 590ae115bc7Smrj * FUNCTION: AcpiUtCopyEpackageToIpackage 591ae115bc7Smrj * 592db2bae30SDana Myers * PARAMETERS: ExternalObject - The external object to be converted 593db2bae30SDana Myers * InternalObject - Where the internal object is returned 594ae115bc7Smrj * 595ae115bc7Smrj * RETURN: Status 596ae115bc7Smrj * 597db2bae30SDana Myers * DESCRIPTION: Copy an external package object to an internal package. 598db2bae30SDana Myers * Handles nested packages. 599ae115bc7Smrj * 600ae115bc7Smrj ******************************************************************************/ 601ae115bc7Smrj 602ae115bc7Smrj static ACPI_STATUS 603ae115bc7Smrj AcpiUtCopyEpackageToIpackage ( 604db2bae30SDana Myers ACPI_OBJECT *ExternalObject, 605db2bae30SDana Myers ACPI_OPERAND_OBJECT **InternalObject) 606ae115bc7Smrj { 607db2bae30SDana Myers ACPI_STATUS Status = AE_OK; 608db2bae30SDana Myers ACPI_OPERAND_OBJECT *PackageObject; 609db2bae30SDana Myers ACPI_OPERAND_OBJECT **PackageElements; 610db2bae30SDana Myers UINT32 i; 611ae115bc7Smrj 612ae115bc7Smrj 613ae115bc7Smrj ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage); 614ae115bc7Smrj 615ae115bc7Smrj 616db2bae30SDana Myers /* Create the package object */ 617ae115bc7Smrj 618*385cc6b4SJerry Jelinek PackageObject = AcpiUtCreatePackageObject ( 619*385cc6b4SJerry Jelinek ExternalObject->Package.Count); 620db2bae30SDana Myers if (!PackageObject) 621db2bae30SDana Myers { 622db2bae30SDana Myers return_ACPI_STATUS (AE_NO_MEMORY); 623ae115bc7Smrj } 624ae115bc7Smrj 625db2bae30SDana Myers PackageElements = PackageObject->Package.Elements; 626db2bae30SDana Myers 627db2bae30SDana Myers /* 628*385cc6b4SJerry Jelinek * Recursive implementation. Probably ok, since nested external 629*385cc6b4SJerry Jelinek * packages as parameters should be very rare. 630db2bae30SDana Myers */ 631db2bae30SDana Myers for (i = 0; i < ExternalObject->Package.Count; i++) 632db2bae30SDana Myers { 633db2bae30SDana Myers Status = AcpiUtCopyEobjectToIobject ( 634db2bae30SDana Myers &ExternalObject->Package.Elements[i], 635db2bae30SDana Myers &PackageElements[i]); 636db2bae30SDana Myers if (ACPI_FAILURE (Status)) 637db2bae30SDana Myers { 638db2bae30SDana Myers /* Truncate package and delete it */ 639db2bae30SDana Myers 640db2bae30SDana Myers PackageObject->Package.Count = i; 641db2bae30SDana Myers PackageElements[i] = NULL; 642db2bae30SDana Myers AcpiUtRemoveReference (PackageObject); 643db2bae30SDana Myers return_ACPI_STATUS (Status); 644db2bae30SDana Myers } 645db2bae30SDana Myers } 646db2bae30SDana Myers 647db2bae30SDana Myers /* Mark package data valid */ 648db2bae30SDana Myers 649db2bae30SDana Myers PackageObject->Package.Flags |= AOPOBJ_DATA_VALID; 650db2bae30SDana Myers 651db2bae30SDana Myers *InternalObject = PackageObject; 652db2bae30SDana Myers return_ACPI_STATUS (Status); 653db2bae30SDana Myers } 654ae115bc7Smrj 655ae115bc7Smrj 656ae115bc7Smrj /******************************************************************************* 657ae115bc7Smrj * 658ae115bc7Smrj * FUNCTION: AcpiUtCopyEobjectToIobject 659ae115bc7Smrj * 660db2bae30SDana Myers * PARAMETERS: ExternalObject - The external object to be converted 661db2bae30SDana Myers * InternalObject - Where the internal object is returned 662ae115bc7Smrj * 66326f3cdf0SGordon Ross * RETURN: Status 664ae115bc7Smrj * 665ae115bc7Smrj * DESCRIPTION: Converts an external object to an internal object. 666ae115bc7Smrj * 667ae115bc7Smrj ******************************************************************************/ 668ae115bc7Smrj 669ae115bc7Smrj ACPI_STATUS 670ae115bc7Smrj AcpiUtCopyEobjectToIobject ( 671ae115bc7Smrj ACPI_OBJECT *ExternalObject, 672ae115bc7Smrj ACPI_OPERAND_OBJECT **InternalObject) 673ae115bc7Smrj { 674ae115bc7Smrj ACPI_STATUS Status; 675ae115bc7Smrj 676ae115bc7Smrj 677ae115bc7Smrj ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject); 678ae115bc7Smrj 679ae115bc7Smrj 680ae115bc7Smrj if (ExternalObject->Type == ACPI_TYPE_PACKAGE) 681ae115bc7Smrj { 682*385cc6b4SJerry Jelinek Status = AcpiUtCopyEpackageToIpackage ( 683*385cc6b4SJerry Jelinek ExternalObject, InternalObject); 684ae115bc7Smrj } 685ae115bc7Smrj else 686ae115bc7Smrj { 687ae115bc7Smrj /* 688ae115bc7Smrj * Build a simple object (no nested objects) 689ae115bc7Smrj */ 690*385cc6b4SJerry Jelinek Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, 691*385cc6b4SJerry Jelinek InternalObject); 692ae115bc7Smrj } 693ae115bc7Smrj 694ae115bc7Smrj return_ACPI_STATUS (Status); 695ae115bc7Smrj } 696ae115bc7Smrj 697ae115bc7Smrj 698ae115bc7Smrj /******************************************************************************* 699ae115bc7Smrj * 700ae115bc7Smrj * FUNCTION: AcpiUtCopySimpleObject 701ae115bc7Smrj * 702ae115bc7Smrj * PARAMETERS: SourceDesc - The internal object to be copied 703ae115bc7Smrj * DestDesc - New target object 704ae115bc7Smrj * 705ae115bc7Smrj * RETURN: Status 706ae115bc7Smrj * 707ae115bc7Smrj * DESCRIPTION: Simple copy of one internal object to another. Reference count 708ae115bc7Smrj * of the destination object is preserved. 709ae115bc7Smrj * 710ae115bc7Smrj ******************************************************************************/ 711ae115bc7Smrj 712ae115bc7Smrj static ACPI_STATUS 713ae115bc7Smrj AcpiUtCopySimpleObject ( 714ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceDesc, 715ae115bc7Smrj ACPI_OPERAND_OBJECT *DestDesc) 716ae115bc7Smrj { 717ae115bc7Smrj UINT16 ReferenceCount; 718ae115bc7Smrj ACPI_OPERAND_OBJECT *NextObject; 719aa2aa9a6SDana Myers ACPI_STATUS Status; 72026f3cdf0SGordon Ross ACPI_SIZE CopySize; 721ae115bc7Smrj 722ae115bc7Smrj 723ae115bc7Smrj /* Save fields from destination that we don't want to overwrite */ 724ae115bc7Smrj 725ae115bc7Smrj ReferenceCount = DestDesc->Common.ReferenceCount; 726ae115bc7Smrj NextObject = DestDesc->Common.NextObject; 727ae115bc7Smrj 72826f3cdf0SGordon Ross /* 72926f3cdf0SGordon Ross * Copy the entire source object over the destination object. 73026f3cdf0SGordon Ross * Note: Source can be either an operand object or namespace node. 73126f3cdf0SGordon Ross */ 73226f3cdf0SGordon Ross CopySize = sizeof (ACPI_OPERAND_OBJECT); 73326f3cdf0SGordon Ross if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED) 73426f3cdf0SGordon Ross { 73526f3cdf0SGordon Ross CopySize = sizeof (ACPI_NAMESPACE_NODE); 73626f3cdf0SGordon Ross } 737ae115bc7Smrj 738*385cc6b4SJerry Jelinek memcpy (ACPI_CAST_PTR (char, DestDesc), 73926f3cdf0SGordon Ross ACPI_CAST_PTR (char, SourceDesc), CopySize); 740ae115bc7Smrj 741ae115bc7Smrj /* Restore the saved fields */ 742ae115bc7Smrj 743ae115bc7Smrj DestDesc->Common.ReferenceCount = ReferenceCount; 744ae115bc7Smrj DestDesc->Common.NextObject = NextObject; 745ae115bc7Smrj 746ae115bc7Smrj /* New object is not static, regardless of source */ 747ae115bc7Smrj 748ae115bc7Smrj DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER; 749ae115bc7Smrj 750ae115bc7Smrj /* Handle the objects with extra data */ 751ae115bc7Smrj 752aa2aa9a6SDana Myers switch (DestDesc->Common.Type) 753ae115bc7Smrj { 754ae115bc7Smrj case ACPI_TYPE_BUFFER: 755ae115bc7Smrj /* 756ae115bc7Smrj * Allocate and copy the actual buffer if and only if: 757ae115bc7Smrj * 1) There is a valid buffer pointer 758ae115bc7Smrj * 2) The buffer has a length > 0 759ae115bc7Smrj */ 760ae115bc7Smrj if ((SourceDesc->Buffer.Pointer) && 761ae115bc7Smrj (SourceDesc->Buffer.Length)) 762ae115bc7Smrj { 763ae115bc7Smrj DestDesc->Buffer.Pointer = 764ae115bc7Smrj ACPI_ALLOCATE (SourceDesc->Buffer.Length); 765ae115bc7Smrj if (!DestDesc->Buffer.Pointer) 766ae115bc7Smrj { 767ae115bc7Smrj return (AE_NO_MEMORY); 768ae115bc7Smrj } 769ae115bc7Smrj 770ae115bc7Smrj /* Copy the actual buffer data */ 771ae115bc7Smrj 772*385cc6b4SJerry Jelinek memcpy (DestDesc->Buffer.Pointer, 77326f3cdf0SGordon Ross SourceDesc->Buffer.Pointer, SourceDesc->Buffer.Length); 774ae115bc7Smrj } 775ae115bc7Smrj break; 776ae115bc7Smrj 777ae115bc7Smrj case ACPI_TYPE_STRING: 778ae115bc7Smrj /* 779ae115bc7Smrj * Allocate and copy the actual string if and only if: 780ae115bc7Smrj * 1) There is a valid string pointer 781ae115bc7Smrj * (Pointer to a NULL string is allowed) 782ae115bc7Smrj */ 783ae115bc7Smrj if (SourceDesc->String.Pointer) 784ae115bc7Smrj { 785ae115bc7Smrj DestDesc->String.Pointer = 786ae115bc7Smrj ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1); 787ae115bc7Smrj if (!DestDesc->String.Pointer) 788ae115bc7Smrj { 789ae115bc7Smrj return (AE_NO_MEMORY); 790ae115bc7Smrj } 791ae115bc7Smrj 792ae115bc7Smrj /* Copy the actual string data */ 793ae115bc7Smrj 794*385cc6b4SJerry Jelinek memcpy (DestDesc->String.Pointer, SourceDesc->String.Pointer, 795ae115bc7Smrj (ACPI_SIZE) SourceDesc->String.Length + 1); 796ae115bc7Smrj } 797ae115bc7Smrj break; 798ae115bc7Smrj 799ae115bc7Smrj case ACPI_TYPE_LOCAL_REFERENCE: 800ae115bc7Smrj /* 801ae115bc7Smrj * We copied the reference object, so we now must add a reference 802ae115bc7Smrj * to the object pointed to by the reference 803db2bae30SDana Myers * 804db2bae30SDana Myers * DDBHandle reference (from Load/LoadTable) is a special reference, 805db2bae30SDana Myers * it does not have a Reference.Object, so does not need to 806db2bae30SDana Myers * increase the reference count 807ae115bc7Smrj */ 808db2bae30SDana Myers if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE) 809db2bae30SDana Myers { 810db2bae30SDana Myers break; 811db2bae30SDana Myers } 812db2bae30SDana Myers 813ae115bc7Smrj AcpiUtAddReference (SourceDesc->Reference.Object); 814ae115bc7Smrj break; 815ae115bc7Smrj 816ae115bc7Smrj case ACPI_TYPE_REGION: 817ae115bc7Smrj /* 818ae115bc7Smrj * We copied the Region Handler, so we now must add a reference 819ae115bc7Smrj */ 820ae115bc7Smrj if (DestDesc->Region.Handler) 821ae115bc7Smrj { 822ae115bc7Smrj AcpiUtAddReference (DestDesc->Region.Handler); 823ae115bc7Smrj } 824ae115bc7Smrj break; 825ae115bc7Smrj 826aa2aa9a6SDana Myers /* 827aa2aa9a6SDana Myers * For Mutex and Event objects, we cannot simply copy the underlying 828aa2aa9a6SDana Myers * OS object. We must create a new one. 829aa2aa9a6SDana Myers */ 830aa2aa9a6SDana Myers case ACPI_TYPE_MUTEX: 831aa2aa9a6SDana Myers 832aa2aa9a6SDana Myers Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex); 833aa2aa9a6SDana Myers if (ACPI_FAILURE (Status)) 834aa2aa9a6SDana Myers { 835aa2aa9a6SDana Myers return (Status); 836aa2aa9a6SDana Myers } 837aa2aa9a6SDana Myers break; 838aa2aa9a6SDana Myers 839aa2aa9a6SDana Myers case ACPI_TYPE_EVENT: 840aa2aa9a6SDana Myers 841aa2aa9a6SDana Myers Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0, 842aa2aa9a6SDana Myers &DestDesc->Event.OsSemaphore); 843aa2aa9a6SDana Myers if (ACPI_FAILURE (Status)) 844aa2aa9a6SDana Myers { 845aa2aa9a6SDana Myers return (Status); 846aa2aa9a6SDana Myers } 847aa2aa9a6SDana Myers break; 848aa2aa9a6SDana Myers 849ae115bc7Smrj default: 850*385cc6b4SJerry Jelinek 851ae115bc7Smrj /* Nothing to do for other simple objects */ 852*385cc6b4SJerry Jelinek 853ae115bc7Smrj break; 854ae115bc7Smrj } 855ae115bc7Smrj 856ae115bc7Smrj return (AE_OK); 857ae115bc7Smrj } 858ae115bc7Smrj 859ae115bc7Smrj 860ae115bc7Smrj /******************************************************************************* 861ae115bc7Smrj * 862ae115bc7Smrj * FUNCTION: AcpiUtCopyIelementToIelement 863ae115bc7Smrj * 864ae115bc7Smrj * PARAMETERS: ACPI_PKG_CALLBACK 865ae115bc7Smrj * 866ae115bc7Smrj * RETURN: Status 867ae115bc7Smrj * 868ae115bc7Smrj * DESCRIPTION: Copy one package element to another package element 869ae115bc7Smrj * 870ae115bc7Smrj ******************************************************************************/ 871ae115bc7Smrj 872ae115bc7Smrj static ACPI_STATUS 873ae115bc7Smrj AcpiUtCopyIelementToIelement ( 874ae115bc7Smrj UINT8 ObjectType, 875ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceObject, 876ae115bc7Smrj ACPI_GENERIC_STATE *State, 877ae115bc7Smrj void *Context) 878ae115bc7Smrj { 879ae115bc7Smrj ACPI_STATUS Status = AE_OK; 880ae115bc7Smrj UINT32 ThisIndex; 881ae115bc7Smrj ACPI_OPERAND_OBJECT **ThisTargetPtr; 882ae115bc7Smrj ACPI_OPERAND_OBJECT *TargetObject; 883ae115bc7Smrj 884ae115bc7Smrj 885ae115bc7Smrj ACPI_FUNCTION_ENTRY (); 886ae115bc7Smrj 887ae115bc7Smrj 888ae115bc7Smrj ThisIndex = State->Pkg.Index; 889ae115bc7Smrj ThisTargetPtr = (ACPI_OPERAND_OBJECT **) 890ae115bc7Smrj &State->Pkg.DestObject->Package.Elements[ThisIndex]; 891ae115bc7Smrj 892ae115bc7Smrj switch (ObjectType) 893ae115bc7Smrj { 894ae115bc7Smrj case ACPI_COPY_TYPE_SIMPLE: 895ae115bc7Smrj 896ae115bc7Smrj /* A null source object indicates a (legal) null package element */ 897ae115bc7Smrj 898ae115bc7Smrj if (SourceObject) 899ae115bc7Smrj { 900ae115bc7Smrj /* 901ae115bc7Smrj * This is a simple object, just copy it 902ae115bc7Smrj */ 903ae115bc7Smrj TargetObject = AcpiUtCreateInternalObject ( 904aa2aa9a6SDana Myers SourceObject->Common.Type); 905ae115bc7Smrj if (!TargetObject) 906ae115bc7Smrj { 907ae115bc7Smrj return (AE_NO_MEMORY); 908ae115bc7Smrj } 909ae115bc7Smrj 910ae115bc7Smrj Status = AcpiUtCopySimpleObject (SourceObject, TargetObject); 911ae115bc7Smrj if (ACPI_FAILURE (Status)) 912ae115bc7Smrj { 913ae115bc7Smrj goto ErrorExit; 914ae115bc7Smrj } 915ae115bc7Smrj 916ae115bc7Smrj *ThisTargetPtr = TargetObject; 917ae115bc7Smrj } 918ae115bc7Smrj else 919ae115bc7Smrj { 920ae115bc7Smrj /* Pass through a null element */ 921ae115bc7Smrj 922ae115bc7Smrj *ThisTargetPtr = NULL; 923ae115bc7Smrj } 924ae115bc7Smrj break; 925ae115bc7Smrj 926ae115bc7Smrj case ACPI_COPY_TYPE_PACKAGE: 927ae115bc7Smrj /* 928ae115bc7Smrj * This object is a package - go down another nesting level 929ae115bc7Smrj * Create and build the package object 930ae115bc7Smrj */ 931*385cc6b4SJerry Jelinek TargetObject = AcpiUtCreatePackageObject ( 932*385cc6b4SJerry Jelinek SourceObject->Package.Count); 933ae115bc7Smrj if (!TargetObject) 934ae115bc7Smrj { 935ae115bc7Smrj return (AE_NO_MEMORY); 936ae115bc7Smrj } 937ae115bc7Smrj 938ae115bc7Smrj TargetObject->Common.Flags = SourceObject->Common.Flags; 939ae115bc7Smrj 940db2bae30SDana Myers /* Pass the new package object back to the package walk routine */ 941ae115bc7Smrj 942ae115bc7Smrj State->Pkg.ThisTargetObj = TargetObject; 943ae115bc7Smrj 944db2bae30SDana Myers /* Store the object pointer in the parent package object */ 945db2bae30SDana Myers 946ae115bc7Smrj *ThisTargetPtr = TargetObject; 947ae115bc7Smrj break; 948ae115bc7Smrj 949ae115bc7Smrj default: 950*385cc6b4SJerry Jelinek 951ae115bc7Smrj return (AE_BAD_PARAMETER); 952ae115bc7Smrj } 953ae115bc7Smrj 954ae115bc7Smrj return (Status); 955ae115bc7Smrj 956ae115bc7Smrj ErrorExit: 957ae115bc7Smrj AcpiUtRemoveReference (TargetObject); 958ae115bc7Smrj return (Status); 959ae115bc7Smrj } 960ae115bc7Smrj 961ae115bc7Smrj 962ae115bc7Smrj /******************************************************************************* 963ae115bc7Smrj * 964ae115bc7Smrj * FUNCTION: AcpiUtCopyIpackageToIpackage 965ae115bc7Smrj * 96626f3cdf0SGordon Ross * PARAMETERS: SourceObj - Pointer to the source package object 96726f3cdf0SGordon Ross * DestObj - Where the internal object is returned 96826f3cdf0SGordon Ross * WalkState - Current Walk state descriptor 969ae115bc7Smrj * 97026f3cdf0SGordon Ross * RETURN: Status 971ae115bc7Smrj * 972ae115bc7Smrj * DESCRIPTION: This function is called to copy an internal package object 973ae115bc7Smrj * into another internal package object. 974ae115bc7Smrj * 975ae115bc7Smrj ******************************************************************************/ 976ae115bc7Smrj 977ae115bc7Smrj static ACPI_STATUS 978ae115bc7Smrj AcpiUtCopyIpackageToIpackage ( 979ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceObj, 980ae115bc7Smrj ACPI_OPERAND_OBJECT *DestObj, 981ae115bc7Smrj ACPI_WALK_STATE *WalkState) 982ae115bc7Smrj { 983ae115bc7Smrj ACPI_STATUS Status = AE_OK; 984ae115bc7Smrj 985ae115bc7Smrj 986ae115bc7Smrj ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage); 987ae115bc7Smrj 988ae115bc7Smrj 989aa2aa9a6SDana Myers DestObj->Common.Type = SourceObj->Common.Type; 990ae115bc7Smrj DestObj->Common.Flags = SourceObj->Common.Flags; 991ae115bc7Smrj DestObj->Package.Count = SourceObj->Package.Count; 992ae115bc7Smrj 993ae115bc7Smrj /* 994ae115bc7Smrj * Create the object array and walk the source package tree 995ae115bc7Smrj */ 996ae115bc7Smrj DestObj->Package.Elements = ACPI_ALLOCATE_ZEROED ( 997ae115bc7Smrj ((ACPI_SIZE) SourceObj->Package.Count + 1) * 998ae115bc7Smrj sizeof (void *)); 999ae115bc7Smrj if (!DestObj->Package.Elements) 1000ae115bc7Smrj { 1001ae115bc7Smrj ACPI_ERROR ((AE_INFO, "Package allocation failure")); 1002ae115bc7Smrj return_ACPI_STATUS (AE_NO_MEMORY); 1003ae115bc7Smrj } 1004ae115bc7Smrj 1005ae115bc7Smrj /* 1006ae115bc7Smrj * Copy the package element-by-element by walking the package "tree". 1007ae115bc7Smrj * This handles nested packages of arbitrary depth. 1008ae115bc7Smrj */ 1009ae115bc7Smrj Status = AcpiUtWalkPackageTree (SourceObj, DestObj, 1010ae115bc7Smrj AcpiUtCopyIelementToIelement, WalkState); 1011ae115bc7Smrj if (ACPI_FAILURE (Status)) 1012ae115bc7Smrj { 1013ae115bc7Smrj /* On failure, delete the destination package object */ 1014ae115bc7Smrj 1015ae115bc7Smrj AcpiUtRemoveReference (DestObj); 1016ae115bc7Smrj } 1017ae115bc7Smrj 1018ae115bc7Smrj return_ACPI_STATUS (Status); 1019ae115bc7Smrj } 1020ae115bc7Smrj 1021ae115bc7Smrj 1022ae115bc7Smrj /******************************************************************************* 1023ae115bc7Smrj * 1024ae115bc7Smrj * FUNCTION: AcpiUtCopyIobjectToIobject 1025ae115bc7Smrj * 102626f3cdf0SGordon Ross * PARAMETERS: SourceDesc - The internal object to be copied 1027ae115bc7Smrj * DestDesc - Where the copied object is returned 102826f3cdf0SGordon Ross * WalkState - Current walk state 1029ae115bc7Smrj * 1030ae115bc7Smrj * RETURN: Status 1031ae115bc7Smrj * 1032ae115bc7Smrj * DESCRIPTION: Copy an internal object to a new internal object 1033ae115bc7Smrj * 1034ae115bc7Smrj ******************************************************************************/ 1035ae115bc7Smrj 1036ae115bc7Smrj ACPI_STATUS 1037ae115bc7Smrj AcpiUtCopyIobjectToIobject ( 1038ae115bc7Smrj ACPI_OPERAND_OBJECT *SourceDesc, 1039ae115bc7Smrj ACPI_OPERAND_OBJECT **DestDesc, 1040ae115bc7Smrj ACPI_WALK_STATE *WalkState) 1041ae115bc7Smrj { 1042ae115bc7Smrj ACPI_STATUS Status = AE_OK; 1043ae115bc7Smrj 1044ae115bc7Smrj 1045ae115bc7Smrj ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject); 1046ae115bc7Smrj 1047ae115bc7Smrj 1048ae115bc7Smrj /* Create the top level object */ 1049ae115bc7Smrj 1050aa2aa9a6SDana Myers *DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type); 1051ae115bc7Smrj if (!*DestDesc) 1052ae115bc7Smrj { 1053ae115bc7Smrj return_ACPI_STATUS (AE_NO_MEMORY); 1054ae115bc7Smrj } 1055ae115bc7Smrj 1056ae115bc7Smrj /* Copy the object and possible subobjects */ 1057ae115bc7Smrj 1058aa2aa9a6SDana Myers if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE) 1059ae115bc7Smrj { 1060*385cc6b4SJerry Jelinek Status = AcpiUtCopyIpackageToIpackage ( 1061*385cc6b4SJerry Jelinek SourceDesc, *DestDesc, WalkState); 1062ae115bc7Smrj } 1063ae115bc7Smrj else 1064ae115bc7Smrj { 1065ae115bc7Smrj Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc); 1066ae115bc7Smrj } 1067ae115bc7Smrj 1068*385cc6b4SJerry Jelinek /* Delete the allocated object if copy failed */ 1069*385cc6b4SJerry Jelinek 1070*385cc6b4SJerry Jelinek if (ACPI_FAILURE (Status)) 1071*385cc6b4SJerry Jelinek { 1072*385cc6b4SJerry Jelinek AcpiUtRemoveReference (*DestDesc); 1073ae115bc7Smrj } 1074ae115bc7Smrj 1075*385cc6b4SJerry Jelinek return_ACPI_STATUS (Status); 1076*385cc6b4SJerry Jelinek } 1077