utcopy.c revision 83174
1/****************************************************************************** 2 * 3 * Module Name: utcopy - Internal to external object translation utilities 4 * $Revision: 79 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117#define __UTCOPY_C__ 118 119#include "acpi.h" 120#include "acinterp.h" 121#include "acnamesp.h" 122#include "amlcode.h" 123 124 125#define _COMPONENT ACPI_UTILITIES 126 MODULE_NAME ("utcopy") 127 128 129/******************************************************************************* 130 * 131 * FUNCTION: AcpiUtCopyIsimpleToEsimple 132 * 133 * PARAMETERS: *InternalObject - Pointer to the object we are examining 134 * *Buffer - Where the object is returned 135 * *SpaceUsed - Where the data length is returned 136 * 137 * RETURN: Status 138 * 139 * DESCRIPTION: This function is called to place a simple object in a user 140 * buffer. 141 * 142 * The buffer is assumed to have sufficient space for the object. 143 * 144 ******************************************************************************/ 145 146static ACPI_STATUS 147AcpiUtCopyIsimpleToEsimple ( 148 ACPI_OPERAND_OBJECT *InternalObject, 149 ACPI_OBJECT *ExternalObject, 150 UINT8 *DataSpace, 151 UINT32 *BufferSpaceUsed) 152{ 153 UINT32 Length = 0; 154 ACPI_STATUS Status = AE_OK; 155 156 157 FUNCTION_TRACE ("UtCopyIsimpleToEsimple"); 158 159 160 /* 161 * Check for NULL object case (could be an uninitialized 162 * package element 163 */ 164 if (!InternalObject) 165 { 166 *BufferSpaceUsed = 0; 167 return_ACPI_STATUS (AE_OK); 168 } 169 170 /* Always clear the external object */ 171 172 MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT)); 173 174 /* 175 * In general, the external object will be the same type as 176 * the internal object 177 */ 178 ExternalObject->Type = InternalObject->Common.Type; 179 180 /* However, only a limited number of external types are supported */ 181 182 switch (InternalObject->Common.Type) 183 { 184 185 case ACPI_TYPE_STRING: 186 187 Length = InternalObject->String.Length + 1; 188 ExternalObject->String.Length = InternalObject->String.Length; 189 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace; 190 MEMCPY ((void *) DataSpace, (void *) InternalObject->String.Pointer, Length); 191 break; 192 193 194 case ACPI_TYPE_BUFFER: 195 196 Length = InternalObject->Buffer.Length; 197 ExternalObject->Buffer.Length = InternalObject->Buffer.Length; 198 ExternalObject->Buffer.Pointer = DataSpace; 199 MEMCPY ((void *) DataSpace, (void *) InternalObject->Buffer.Pointer, Length); 200 break; 201 202 203 case ACPI_TYPE_INTEGER: 204 205 ExternalObject->Integer.Value= InternalObject->Integer.Value; 206 break; 207 208 209 case INTERNAL_TYPE_REFERENCE: 210 211 /* 212 * This is an object reference. Attempt to dereference it. 213 */ 214 switch (InternalObject->Reference.Opcode) 215 { 216 case AML_ZERO_OP: 217 ExternalObject->Type = ACPI_TYPE_INTEGER; 218 ExternalObject->Integer.Value = 0; 219 break; 220 221 case AML_ONE_OP: 222 ExternalObject->Type = ACPI_TYPE_INTEGER; 223 ExternalObject->Integer.Value = 1; 224 break; 225 226 case AML_ONES_OP: 227 ExternalObject->Type = ACPI_TYPE_INTEGER; 228 ExternalObject->Integer.Value = ACPI_INTEGER_MAX; 229 break; 230 231 case AML_INT_NAMEPATH_OP: 232 /* 233 * This is a named reference, get the string. We already know that 234 * we have room for it, use max length 235 */ 236 Length = MAX_STRING_LENGTH; 237 ExternalObject->Type = ACPI_TYPE_STRING; 238 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace; 239 Status = AcpiNsHandleToPathname ((ACPI_HANDLE *) InternalObject->Reference.Node, 240 &Length, (char *) DataSpace); 241 242 /* Converted (external) string length is returned from above */ 243 244 ExternalObject->String.Length = Length; 245 break; 246 247 default: 248 /* 249 * Use the object type of "Any" to indicate a reference 250 * to object containing a handle to an ACPI named object. 251 */ 252 ExternalObject->Type = ACPI_TYPE_ANY; 253 ExternalObject->Reference.Handle = InternalObject->Reference.Node; 254 break; 255 } 256 break; 257 258 259 case ACPI_TYPE_PROCESSOR: 260 261 ExternalObject->Processor.ProcId = InternalObject->Processor.ProcId; 262 ExternalObject->Processor.PblkAddress = InternalObject->Processor.Address; 263 ExternalObject->Processor.PblkLength = InternalObject->Processor.Length; 264 break; 265 266 267 case ACPI_TYPE_POWER: 268 269 ExternalObject->PowerResource.SystemLevel = 270 InternalObject->PowerResource.SystemLevel; 271 272 ExternalObject->PowerResource.ResourceOrder = 273 InternalObject->PowerResource.ResourceOrder; 274 break; 275 276 277 default: 278 /* 279 * There is no corresponding external object type 280 */ 281 return_ACPI_STATUS (AE_SUPPORT); 282 break; 283 } 284 285 286 *BufferSpaceUsed = (UINT32) ROUND_UP_TO_NATIVE_WORD (Length); 287 288 return_ACPI_STATUS (Status); 289} 290 291 292/******************************************************************************* 293 * 294 * FUNCTION: AcpiUtCopyIelementToEelement 295 * 296 * PARAMETERS: ACPI_PKG_CALLBACK 297 * 298 * RETURN: Status 299 * 300 * DESCRIPTION: Copy one package element to another package element 301 * 302 ******************************************************************************/ 303 304ACPI_STATUS 305AcpiUtCopyIelementToEelement ( 306 UINT8 ObjectType, 307 ACPI_OPERAND_OBJECT *SourceObject, 308 ACPI_GENERIC_STATE *State, 309 void *Context) 310{ 311 ACPI_STATUS Status = AE_OK; 312 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context; 313 UINT32 ObjectSpace; 314 UINT32 ThisIndex; 315 ACPI_OBJECT *TargetObject; 316 317 318 FUNCTION_ENTRY (); 319 320 321 ThisIndex = State->Pkg.Index; 322 TargetObject = (ACPI_OBJECT *) 323 &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex]; 324 325 switch (ObjectType) 326 { 327 case ACPI_COPY_TYPE_SIMPLE: 328 329 /* 330 * This is a simple or null object -- get the size 331 */ 332 Status = AcpiUtCopyIsimpleToEsimple (SourceObject, 333 TargetObject, Info->FreeSpace, &ObjectSpace); 334 if (ACPI_FAILURE (Status)) 335 { 336 return (Status); 337 } 338 339 break; 340 341 case ACPI_COPY_TYPE_PACKAGE: 342 343 /* 344 * Build the package object 345 */ 346 TargetObject->Type = ACPI_TYPE_PACKAGE; 347 TargetObject->Package.Count = SourceObject->Package.Count; 348 TargetObject->Package.Elements = (ACPI_OBJECT *) Info->FreeSpace; 349 350 /* 351 * Pass the new package object back to the package walk routine 352 */ 353 State->Pkg.ThisTargetObj = TargetObject; 354 355 /* 356 * Save space for the array of objects (Package elements) 357 * update the buffer length counter 358 */ 359 ObjectSpace = (UINT32) ROUND_UP_TO_NATIVE_WORD ( 360 TargetObject->Package.Count * sizeof (ACPI_OBJECT)); 361 break; 362 363 default: 364 return (AE_BAD_PARAMETER); 365 } 366 367 368 Info->FreeSpace += ObjectSpace; 369 Info->Length += ObjectSpace; 370 371 return (Status); 372} 373 374 375/******************************************************************************* 376 * 377 * FUNCTION: AcpiUtCopyIpackageToEpackage 378 * 379 * PARAMETERS: *InternalObject - Pointer to the object we are returning 380 * *Buffer - Where the object is returned 381 * *SpaceUsed - Where the object length is returned 382 * 383 * RETURN: Status 384 * 385 * DESCRIPTION: This function is called to place a package object in a user 386 * buffer. A package object by definition contains other objects. 387 * 388 * The buffer is assumed to have sufficient space for the object. 389 * The caller must have verified the buffer length needed using the 390 * AcpiUtGetObjectSize function before calling this function. 391 * 392 ******************************************************************************/ 393 394static ACPI_STATUS 395AcpiUtCopyIpackageToEpackage ( 396 ACPI_OPERAND_OBJECT *InternalObject, 397 UINT8 *Buffer, 398 UINT32 *SpaceUsed) 399{ 400 ACPI_OBJECT *ExternalObject; 401 ACPI_STATUS Status; 402 ACPI_PKG_INFO Info; 403 404 405 FUNCTION_TRACE ("UtCopyIpackageToEpackage"); 406 407 408 /* 409 * First package at head of the buffer 410 */ 411 ExternalObject = (ACPI_OBJECT *) Buffer; 412 413 /* 414 * Free space begins right after the first package 415 */ 416 Info.Length = 0; 417 Info.ObjectSpace = 0; 418 Info.NumPackages = 1; 419 Info.FreeSpace = Buffer + ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 420 421 422 ExternalObject->Type = InternalObject->Common.Type; 423 ExternalObject->Package.Count = InternalObject->Package.Count; 424 ExternalObject->Package.Elements = (ACPI_OBJECT *) Info.FreeSpace; 425 426 427 /* 428 * Build an array of ACPI_OBJECTS in the buffer 429 * and move the free space past it 430 */ 431 Info.FreeSpace += ExternalObject->Package.Count * 432 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 433 434 435 Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject, 436 AcpiUtCopyIelementToEelement, &Info); 437 438 *SpaceUsed = Info.Length; 439 440 return_ACPI_STATUS (Status); 441 442} 443 444/******************************************************************************* 445 * 446 * FUNCTION: AcpiUtCopyIobjectToEobject 447 * 448 * PARAMETERS: *InternalObject - The internal object to be converted 449 * *BufferPtr - Where the object is returned 450 * 451 * RETURN: Status 452 * 453 * DESCRIPTION: This function is called to build an API object to be returned to 454 * the caller. 455 * 456 ******************************************************************************/ 457 458ACPI_STATUS 459AcpiUtCopyIobjectToEobject ( 460 ACPI_OPERAND_OBJECT *InternalObject, 461 ACPI_BUFFER *RetBuffer) 462{ 463 ACPI_STATUS Status; 464 465 466 FUNCTION_TRACE ("UtCopyIobjectToEobject"); 467 468 469 if (IS_THIS_OBJECT_TYPE (InternalObject, ACPI_TYPE_PACKAGE)) 470 { 471 /* 472 * Package object: Copy all subobjects (including 473 * nested packages) 474 */ 475 Status = AcpiUtCopyIpackageToEpackage (InternalObject, 476 RetBuffer->Pointer, &RetBuffer->Length); 477 } 478 479 else 480 { 481 /* 482 * Build a simple object (no nested objects) 483 */ 484 Status = AcpiUtCopyIsimpleToEsimple (InternalObject, 485 (ACPI_OBJECT *) RetBuffer->Pointer, 486 ((UINT8 *) RetBuffer->Pointer + 487 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))), 488 &RetBuffer->Length); 489 /* 490 * build simple does not include the object size in the length 491 * so we add it in here 492 */ 493 RetBuffer->Length += sizeof (ACPI_OBJECT); 494 } 495 496 return_ACPI_STATUS (Status); 497} 498 499 500/******************************************************************************* 501 * 502 * FUNCTION: AcpiUtCopyEsimpleToIsimple 503 * 504 * PARAMETERS: *ExternalObject - The external object to be converted 505 * *InternalObject - Where the internal object is returned 506 * 507 * RETURN: Status 508 * 509 * DESCRIPTION: This function copies an external object to an internal one. 510 * NOTE: Pointers can be copied, we don't need to copy data. 511 * (The pointers have to be valid in our address space no matter 512 * what we do with them!) 513 * 514 ******************************************************************************/ 515 516ACPI_STATUS 517AcpiUtCopyEsimpleToIsimple ( 518 ACPI_OBJECT *ExternalObject, 519 ACPI_OPERAND_OBJECT *InternalObject) 520{ 521 522 FUNCTION_TRACE ("UtCopyEsimpleToIsimple"); 523 524 525 InternalObject->Common.Type = (UINT8) ExternalObject->Type; 526 527 /* 528 * Simple types supported are: String, Buffer, Integer 529 */ 530 switch (ExternalObject->Type) 531 { 532 533 case ACPI_TYPE_STRING: 534 535 InternalObject->String.Length = ExternalObject->String.Length; 536 InternalObject->String.Pointer = ExternalObject->String.Pointer; 537 break; 538 539 540 case ACPI_TYPE_BUFFER: 541 542 InternalObject->Buffer.Length = ExternalObject->Buffer.Length; 543 InternalObject->Buffer.Pointer = ExternalObject->Buffer.Pointer; 544 break; 545 546 547 case ACPI_TYPE_INTEGER: 548 549 InternalObject->Integer.Value = ExternalObject->Integer.Value; 550 break; 551 552 default: 553 /* 554 * Whatever other type -- it is not supported 555 */ 556 return_ACPI_STATUS (AE_SUPPORT); 557 break; 558 } 559 560 561 return_ACPI_STATUS (AE_OK); 562} 563 564 565#ifdef ACPI_FUTURE_IMPLEMENTATION 566 567/* Code to convert packages that are parameters to control methods */ 568 569/******************************************************************************* 570 * 571 * FUNCTION: AcpiUtCopyEpackageToIpackage 572 * 573 * PARAMETERS: *InternalObject - Pointer to the object we are returning 574 * *Buffer - Where the object is returned 575 * *SpaceUsed - Where the length of the object is returned 576 * 577 * RETURN: Status - the status of the call 578 * 579 * DESCRIPTION: This function is called to place a package object in a user 580 * buffer. A package object by definition contains other objects. 581 * 582 * The buffer is assumed to have sufficient space for the object. 583 * The caller must have verified the buffer length needed using the 584 * AcpiUtGetObjectSize function before calling this function. 585 * 586 ******************************************************************************/ 587 588static ACPI_STATUS 589AcpiUtCopyEpackageToIpackage ( 590 ACPI_OPERAND_OBJECT *InternalObject, 591 UINT8 *Buffer, 592 UINT32 *SpaceUsed) 593{ 594 UINT8 *FreeSpace; 595 ACPI_OBJECT *ExternalObject; 596 UINT32 Length = 0; 597 UINT32 ThisIndex; 598 UINT32 ObjectSpace = 0; 599 ACPI_OPERAND_OBJECT *ThisInternalObj; 600 ACPI_OBJECT *ThisExternalObj; 601 602 603 FUNCTION_TRACE ("UtCopyEpackageToIpackage"); 604 605 606 /* 607 * First package at head of the buffer 608 */ 609 ExternalObject = (ACPI_OBJECT *)Buffer; 610 611 /* 612 * Free space begins right after the first package 613 */ 614 FreeSpace = Buffer + sizeof(ACPI_OBJECT); 615 616 617 ExternalObject->Type = InternalObject->Common.Type; 618 ExternalObject->Package.Count = InternalObject->Package.Count; 619 ExternalObject->Package.Elements = (ACPI_OBJECT *)FreeSpace; 620 621 622 /* 623 * Build an array of ACPI_OBJECTS in the buffer 624 * and move the free space past it 625 */ 626 FreeSpace += ExternalObject->Package.Count * sizeof(ACPI_OBJECT); 627 628 629 /* Call WalkPackage */ 630 631} 632 633#endif /* Future implementation */ 634 635 636/******************************************************************************* 637 * 638 * FUNCTION: AcpiUtCopyEobjectToIobject 639 * 640 * PARAMETERS: *InternalObject - The external object to be converted 641 * *BufferPtr - Where the internal object is returned 642 * 643 * RETURN: Status - the status of the call 644 * 645 * DESCRIPTION: Converts an external object to an internal object. 646 * 647 ******************************************************************************/ 648 649ACPI_STATUS 650AcpiUtCopyEobjectToIobject ( 651 ACPI_OBJECT *ExternalObject, 652 ACPI_OPERAND_OBJECT *InternalObject) 653{ 654 ACPI_STATUS Status; 655 656 657 FUNCTION_TRACE ("UtCopyEobjectToIobject"); 658 659 660 if (ExternalObject->Type == ACPI_TYPE_PACKAGE) 661 { 662 /* 663 * Package objects contain other objects (which can be objects) 664 * buildpackage does it all 665 * 666 * TBD: Package conversion must be completed and tested 667 * NOTE: this code converts packages as input parameters to 668 * control methods only. This is a very, very rare case. 669 */ 670/* 671 Status = AcpiUtCopyEpackageToIpackage(InternalObject, 672 RetBuffer->Pointer, 673 &RetBuffer->Length); 674*/ 675 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 676 "Packages as parameters not implemented!\n")); 677 678 return_ACPI_STATUS (AE_NOT_IMPLEMENTED); 679 } 680 681 else 682 { 683 /* 684 * Build a simple object (no nested objects) 685 */ 686 Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject); 687 /* 688 * build simple does not include the object size in the length 689 * so we add it in here 690 */ 691 } 692 693 return_ACPI_STATUS (Status); 694} 695 696 697/******************************************************************************* 698 * 699 * FUNCTION: AcpiUtCopyIelementToIelement 700 * 701 * PARAMETERS: ACPI_PKG_CALLBACK 702 * 703 * RETURN: Status - the status of the call 704 * 705 * DESCRIPTION: Copy one package element to another package element 706 * 707 ******************************************************************************/ 708 709ACPI_STATUS 710AcpiUtCopyIelementToIelement ( 711 UINT8 ObjectType, 712 ACPI_OPERAND_OBJECT *SourceObject, 713 ACPI_GENERIC_STATE *State, 714 void *Context) 715{ 716 ACPI_STATUS Status = AE_OK; 717 UINT32 ThisIndex; 718 ACPI_OPERAND_OBJECT **ThisTargetPtr; 719 ACPI_OPERAND_OBJECT *TargetObject; 720 721 722 FUNCTION_ENTRY (); 723 724 725 ThisIndex = State->Pkg.Index; 726 ThisTargetPtr = (ACPI_OPERAND_OBJECT **) 727 &State->Pkg.DestObject->Package.Elements[ThisIndex]; 728 729 switch (ObjectType) 730 { 731 case 0: 732 733 /* 734 * This is a simple object, just copy it 735 */ 736 TargetObject = AcpiUtCreateInternalObject (SourceObject->Common.Type); 737 if (!TargetObject) 738 { 739 return (AE_NO_MEMORY); 740 } 741 742 Status = AcpiExStoreObjectToObject (SourceObject, TargetObject, 743 (ACPI_WALK_STATE *) Context); 744 if (ACPI_FAILURE (Status)) 745 { 746 return (Status); 747 } 748 749 *ThisTargetPtr = TargetObject; 750 break; 751 752 753 case 1: 754 /* 755 * This object is a package - go down another nesting level 756 * Create and build the package object 757 */ 758 TargetObject = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE); 759 if (!TargetObject) 760 { 761 /* TBD: must delete package created up to this point */ 762 763 return (AE_NO_MEMORY); 764 } 765 766 TargetObject->Package.Count = SourceObject->Package.Count; 767 768 /* 769 * Pass the new package object back to the package walk routine 770 */ 771 State->Pkg.ThisTargetObj = TargetObject; 772 773 /* 774 * Store the object pointer in the parent package object 775 */ 776 *ThisTargetPtr = TargetObject; 777 break; 778 779 default: 780 return (AE_BAD_PARAMETER); 781 } 782 783 784 return (Status); 785} 786 787 788/******************************************************************************* 789 * 790 * FUNCTION: AcpiUtCopyIpackageToIpackage 791 * 792 * PARAMETERS: *SourceObj - Pointer to the source package object 793 * *DestObj - Where the internal object is returned 794 * 795 * RETURN: Status - the status of the call 796 * 797 * DESCRIPTION: This function is called to copy an internal package object 798 * into another internal package object. 799 * 800 ******************************************************************************/ 801 802ACPI_STATUS 803AcpiUtCopyIpackageToIpackage ( 804 ACPI_OPERAND_OBJECT *SourceObj, 805 ACPI_OPERAND_OBJECT *DestObj, 806 ACPI_WALK_STATE *WalkState) 807{ 808 ACPI_STATUS Status = AE_OK; 809 810 811 FUNCTION_TRACE ("UtCopyIpackageToIpackage"); 812 813 814 DestObj->Common.Type = SourceObj->Common.Type; 815 DestObj->Package.Count = SourceObj->Package.Count; 816 817 818 /* 819 * Create the object array and walk the source package tree 820 */ 821 DestObj->Package.Elements = ACPI_MEM_CALLOCATE ((SourceObj->Package.Count + 1) * 822 sizeof (void *)); 823 DestObj->Package.NextElement = DestObj->Package.Elements; 824 825 if (!DestObj->Package.Elements) 826 { 827 REPORT_ERROR ( 828 ("AmlBuildCopyInternalPackageObject: Package allocation failure\n")); 829 return_ACPI_STATUS (AE_NO_MEMORY); 830 } 831 832 833 Status = AcpiUtWalkPackageTree (SourceObj, DestObj, 834 AcpiUtCopyIelementToIelement, WalkState); 835 836 return_ACPI_STATUS (Status); 837} 838 839