utcopy.c revision 73561
1/****************************************************************************** 2 * 3 * Module Name: cmcopy - Internal to external object translation utilities 4 * $Revision: 66 $ 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 __CMCOPY_C__ 118 119#include "acpi.h" 120#include "acinterp.h" 121#include "acnamesp.h" 122#include "amlcode.h" 123 124 125#define _COMPONENT MISCELLANEOUS 126 MODULE_NAME ("cmcopy") 127 128 129 130/******************************************************************************* 131 * 132 * FUNCTION: AcpiCmCopyIsimpleToEsimple 133 * 134 * PARAMETERS: *InternalObject - Pointer to the object we are examining 135 * *Buffer - Where the object is returned 136 * *SpaceUsed - Where the data length is returned 137 * 138 * RETURN: Status 139 * 140 * DESCRIPTION: This function is called to place a simple object in a user 141 * buffer. 142 * 143 * The buffer is assumed to have sufficient space for the object. 144 * 145 ******************************************************************************/ 146 147static ACPI_STATUS 148AcpiCmCopyIsimpleToEsimple ( 149 ACPI_OPERAND_OBJECT *InternalObject, 150 ACPI_OBJECT *ExternalObject, 151 UINT8 *DataSpace, 152 UINT32 *BufferSpaceUsed) 153{ 154 UINT32 Length = 0; 155 ACPI_STATUS Status = AE_OK; 156 157 158 FUNCTION_TRACE ("CmCopyIsimpleToEsimple"); 159 160 161 /* 162 * Check for NULL object case (could be an uninitialized 163 * package element 164 */ 165 166 if (!InternalObject) 167 { 168 *BufferSpaceUsed = 0; 169 return_ACPI_STATUS (AE_OK); 170 } 171 172 /* Always clear the external object */ 173 174 MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT)); 175 176 /* 177 * In general, the external object will be the same type as 178 * the internal object 179 */ 180 181 ExternalObject->Type = InternalObject->Common.Type; 182 183 /* However, only a limited number of external types are supported */ 184 185 switch (InternalObject->Common.Type) 186 { 187 188 case ACPI_TYPE_STRING: 189 190 Length = InternalObject->String.Length + 1; 191 ExternalObject->String.Length = InternalObject->String.Length; 192 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace; 193 MEMCPY ((void *) DataSpace, (void *) InternalObject->String.Pointer, Length); 194 break; 195 196 197 case ACPI_TYPE_BUFFER: 198 199 Length = InternalObject->Buffer.Length; 200 ExternalObject->Buffer.Length = InternalObject->Buffer.Length; 201 ExternalObject->Buffer.Pointer = DataSpace; 202 MEMCPY ((void *) DataSpace, (void *) InternalObject->Buffer.Pointer, Length); 203 break; 204 205 206 case ACPI_TYPE_INTEGER: 207 208 ExternalObject->Integer.Value= InternalObject->Integer.Value; 209 break; 210 211 212 case INTERNAL_TYPE_REFERENCE: 213 214 /* 215 * This is an object reference. Attempt to dereference it. 216 */ 217 218 switch (InternalObject->Reference.OpCode) 219 { 220 case AML_ZERO_OP: 221 ExternalObject->Type = ACPI_TYPE_INTEGER; 222 ExternalObject->Integer.Value = 0; 223 break; 224 225 case AML_ONE_OP: 226 ExternalObject->Type = ACPI_TYPE_INTEGER; 227 ExternalObject->Integer.Value = 1; 228 break; 229 230 case AML_ONES_OP: 231 ExternalObject->Type = ACPI_TYPE_INTEGER; 232 ExternalObject->Integer.Value = ACPI_INTEGER_MAX; 233 break; 234 235 case AML_NAMEPATH_OP: 236 /* 237 * This is a named reference, get the string. We already know that 238 * we have room for it, use max length 239 */ 240 Length = MAX_STRING_LENGTH; 241 ExternalObject->Type = ACPI_TYPE_STRING; 242 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace; 243 Status = AcpiNsHandleToPathname ((ACPI_HANDLE *) InternalObject->Reference.Node, 244 &Length, (char *) DataSpace); 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 287 *BufferSpaceUsed = (UINT32) ROUND_UP_TO_NATIVE_WORD (Length); 288 289 return_ACPI_STATUS (Status); 290} 291 292 293/******************************************************************************* 294 * 295 * FUNCTION: AcpiCmCopyIelementToEelement 296 * 297 * PARAMETERS: ACPI_PKG_CALLBACK 298 * 299 * RETURN: Status 300 * 301 * DESCRIPTION: Copy one package element to another package element 302 * 303 ******************************************************************************/ 304 305ACPI_STATUS 306AcpiCmCopyIelementToEelement ( 307 UINT8 ObjectType, 308 ACPI_OPERAND_OBJECT *SourceObject, 309 ACPI_GENERIC_STATE *State, 310 void *Context) 311{ 312 ACPI_STATUS Status = AE_OK; 313 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context; 314 UINT32 ObjectSpace; 315 UINT32 ThisIndex; 316 ACPI_OBJECT *TargetObject; 317 318 319 320 ThisIndex = State->Pkg.Index; 321 TargetObject = (ACPI_OBJECT *) 322 &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex]; 323 324 325 switch (ObjectType) 326 { 327 case 0: 328 329 /* 330 * This is a simple or null object -- get the size 331 */ 332 333 Status = AcpiCmCopyIsimpleToEsimple (SourceObject, 334 TargetObject, Info->FreeSpace, &ObjectSpace); 335 if (ACPI_FAILURE (Status)) 336 { 337 return (Status); 338 } 339 340 break; 341 342 case 1: 343 344 /* 345 * Build the package object 346 */ 347 TargetObject->Type = ACPI_TYPE_PACKAGE; 348 TargetObject->Package.Count = SourceObject->Package.Count; 349 TargetObject->Package.Elements = (ACPI_OBJECT *) Info->FreeSpace; 350 351 /* 352 * Pass the new package object back to the package walk routine 353 */ 354 State->Pkg.ThisTargetObj = TargetObject; 355 356 /* 357 * Save space for the array of objects (Package elements) 358 * update the buffer length counter 359 */ 360 ObjectSpace = (UINT32) ROUND_UP_TO_NATIVE_WORD ( 361 TargetObject->Package.Count * sizeof (ACPI_OBJECT)); 362 break; 363 364 default: 365 return (AE_BAD_PARAMETER); 366 } 367 368 369 Info->FreeSpace += ObjectSpace; 370 Info->Length += ObjectSpace; 371 372 return (Status); 373} 374 375 376/******************************************************************************* 377 * 378 * FUNCTION: AcpiCmCopyIpackageToEpackage 379 * 380 * PARAMETERS: *InternalObject - Pointer to the object we are returning 381 * *Buffer - Where the object is returned 382 * *SpaceUsed - Where the object length is returned 383 * 384 * RETURN: Status 385 * 386 * DESCRIPTION: This function is called to place a package object in a user 387 * buffer. A package object by definition contains other objects. 388 * 389 * The buffer is assumed to have sufficient space for the object. 390 * The caller must have verified the buffer length needed using the 391 * AcpiCmGetObjectSize function before calling this function. 392 * 393 ******************************************************************************/ 394 395static ACPI_STATUS 396AcpiCmCopyIpackageToEpackage ( 397 ACPI_OPERAND_OBJECT *InternalObject, 398 UINT8 *Buffer, 399 UINT32 *SpaceUsed) 400{ 401 ACPI_OBJECT *ExternalObject; 402 ACPI_STATUS Status; 403 ACPI_PKG_INFO Info; 404 405 406 FUNCTION_TRACE ("CmCopyIpackageToEpackage"); 407 408 409 /* 410 * First package at head of the buffer 411 */ 412 ExternalObject = (ACPI_OBJECT *) Buffer; 413 414 /* 415 * Free space begins right after the first package 416 */ 417 Info.Length = 0; 418 Info.ObjectSpace = 0; 419 Info.NumPackages = 1; 420 Info.FreeSpace = Buffer + ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 421 422 423 424 ExternalObject->Type = InternalObject->Common.Type; 425 ExternalObject->Package.Count = InternalObject->Package.Count; 426 ExternalObject->Package.Elements = (ACPI_OBJECT *) Info.FreeSpace; 427 428 429 /* 430 * Build an array of ACPI_OBJECTS in the buffer 431 * and move the free space past it 432 */ 433 434 Info.FreeSpace += ExternalObject->Package.Count * 435 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 436 437 438 Status = AcpiCmWalkPackageTree (InternalObject, ExternalObject, 439 AcpiCmCopyIelementToEelement, &Info); 440 441 *SpaceUsed = Info.Length; 442 443 return_ACPI_STATUS (Status); 444 445} 446 447/******************************************************************************* 448 * 449 * FUNCTION: AcpiCmCopyIobjectToEobject 450 * 451 * PARAMETERS: *InternalObject - The internal object to be converted 452 * *BufferPtr - Where the object is returned 453 * 454 * RETURN: Status 455 * 456 * DESCRIPTION: This function is called to build an API object to be returned to 457 * the caller. 458 * 459 ******************************************************************************/ 460 461ACPI_STATUS 462AcpiCmCopyIobjectToEobject ( 463 ACPI_OPERAND_OBJECT *InternalObject, 464 ACPI_BUFFER *RetBuffer) 465{ 466 ACPI_STATUS Status; 467 468 469 FUNCTION_TRACE ("CmCopyIobjectToEobject"); 470 471 472 if (IS_THIS_OBJECT_TYPE (InternalObject, ACPI_TYPE_PACKAGE)) 473 { 474 /* 475 * Package object: Copy all subobjects (including 476 * nested packages) 477 */ 478 Status = AcpiCmCopyIpackageToEpackage (InternalObject, 479 RetBuffer->Pointer, &RetBuffer->Length); 480 } 481 482 else 483 { 484 /* 485 * Build a simple object (no nested objects) 486 */ 487 Status = AcpiCmCopyIsimpleToEsimple (InternalObject, 488 (ACPI_OBJECT *) RetBuffer->Pointer, 489 ((UINT8 *) RetBuffer->Pointer + 490 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))), 491 &RetBuffer->Length); 492 /* 493 * build simple does not include the object size in the length 494 * so we add it in here 495 */ 496 RetBuffer->Length += sizeof (ACPI_OBJECT); 497 } 498 499 return_ACPI_STATUS (Status); 500} 501 502 503 504/******************************************************************************* 505 * 506 * FUNCTION: AcpiCmCopyEsimpleToIsimple 507 * 508 * PARAMETERS: *ExternalObject - The external object to be converted 509 * *InternalObject - Where the internal object is returned 510 * 511 * RETURN: Status 512 * 513 * DESCRIPTION: This function copies an external object to an internal one. 514 * NOTE: Pointers can be copied, we don't need to copy data. 515 * (The pointers have to be valid in our address space no matter 516 * what we do with them!) 517 * 518 ******************************************************************************/ 519 520ACPI_STATUS 521AcpiCmCopyEsimpleToIsimple ( 522 ACPI_OBJECT *ExternalObject, 523 ACPI_OPERAND_OBJECT *InternalObject) 524{ 525 526 FUNCTION_TRACE ("CmCopyEsimpleToIsimple"); 527 528 529 InternalObject->Common.Type = (UINT8) ExternalObject->Type; 530 531 switch (ExternalObject->Type) 532 { 533 534 case ACPI_TYPE_STRING: 535 536 InternalObject->String.Length = ExternalObject->String.Length; 537 InternalObject->String.Pointer = ExternalObject->String.Pointer; 538 break; 539 540 541 case ACPI_TYPE_BUFFER: 542 543 InternalObject->Buffer.Length = ExternalObject->Buffer.Length; 544 InternalObject->Buffer.Pointer = ExternalObject->Buffer.Pointer; 545 break; 546 547 548 case ACPI_TYPE_INTEGER: 549 /* 550 * Number is included in the object itself 551 */ 552 InternalObject->Integer.Value = ExternalObject->Integer.Value; 553 break; 554 555 556 default: 557 return_ACPI_STATUS (AE_CTRL_RETURN_VALUE); 558 break; 559 } 560 561 562 return_ACPI_STATUS (AE_OK); 563} 564 565 566#ifdef ACPI_FUTURE_IMPLEMENTATION 567 568/* Code to convert packages that are parameters to control methods */ 569 570/******************************************************************************* 571 * 572 * FUNCTION: AcpiCmCopyEpackageToIpackage 573 * 574 * PARAMETERS: *InternalObject - Pointer to the object we are returning 575 * *Buffer - Where the object is returned 576 * *SpaceUsed - Where the length of the object is returned 577 * 578 * RETURN: Status - the status of the call 579 * 580 * DESCRIPTION: This function is called to place a package object in a user 581 * buffer. A package object by definition contains other objects. 582 * 583 * The buffer is assumed to have sufficient space for the object. 584 * The caller must have verified the buffer length needed using the 585 * AcpiCmGetObjectSize function before calling this function. 586 * 587 ******************************************************************************/ 588 589static ACPI_STATUS 590AcpiCmCopyEpackageToIpackage ( 591 ACPI_OPERAND_OBJECT *InternalObject, 592 UINT8 *Buffer, 593 UINT32 *SpaceUsed) 594{ 595 UINT8 *FreeSpace; 596 ACPI_OBJECT *ExternalObject; 597 UINT32 Length = 0; 598 UINT32 ThisIndex; 599 UINT32 ObjectSpace = 0; 600 ACPI_OPERAND_OBJECT *ThisInternalObj; 601 ACPI_OBJECT *ThisExternalObj; 602 603 604 FUNCTION_TRACE ("CmCopyEpackageToIpackage"); 605 606 607 /* 608 * First package at head of the buffer 609 */ 610 ExternalObject = (ACPI_OBJECT *)Buffer; 611 612 /* 613 * Free space begins right after the first package 614 */ 615 FreeSpace = Buffer + sizeof(ACPI_OBJECT); 616 617 618 ExternalObject->Type = InternalObject->Common.Type; 619 ExternalObject->Package.Count = InternalObject->Package.Count; 620 ExternalObject->Package.Elements = (ACPI_OBJECT *)FreeSpace; 621 622 623 /* 624 * Build an array of ACPI_OBJECTS in the buffer 625 * and move the free space past it 626 */ 627 628 FreeSpace += ExternalObject->Package.Count * sizeof(ACPI_OBJECT); 629 630 631 /* Call WalkPackage */ 632 633} 634 635#endif /* Future implementation */ 636 637 638/******************************************************************************* 639 * 640 * FUNCTION: AcpiCmCopyEobjectToIobject 641 * 642 * PARAMETERS: *InternalObject - The external object to be converted 643 * *BufferPtr - Where the internal object is returned 644 * 645 * RETURN: Status - the status of the call 646 * 647 * DESCRIPTION: Converts an external object to an internal object. 648 * 649 ******************************************************************************/ 650 651ACPI_STATUS 652AcpiCmCopyEobjectToIobject ( 653 ACPI_OBJECT *ExternalObject, 654 ACPI_OPERAND_OBJECT *InternalObject) 655{ 656 ACPI_STATUS Status; 657 658 659 FUNCTION_TRACE ("AcpiCmCopyEobjectToIobject"); 660 661 662 if (ExternalObject->Type == ACPI_TYPE_PACKAGE) 663 { 664 /* 665 * Package objects contain other objects (which can be objects) 666 * buildpackage does it all 667 * 668 * TBD: Package conversion must be completed and tested 669 * NOTE: this code converts packages as input parameters to 670 * control methods only. This is a very, very rare case. 671 */ 672/* 673 Status = AcpiCmCopyEpackageToIpackage(InternalObject, 674 RetBuffer->Pointer, 675 &RetBuffer->Length); 676*/ 677 DEBUG_PRINT (ACPI_ERROR, 678 ("AcpiCmCopyEobjectToIobject: Packages as parameters not implemented!\n")); 679 680 return_ACPI_STATUS (AE_NOT_IMPLEMENTED); 681 } 682 683 else 684 { 685 /* 686 * Build a simple object (no nested objects) 687 */ 688 Status = AcpiCmCopyEsimpleToIsimple (ExternalObject, InternalObject); 689 /* 690 * build simple does not include the object size in the length 691 * so we add it in here 692 */ 693 } 694 695 return_ACPI_STATUS (Status); 696} 697 698 699 700/******************************************************************************* 701 * 702 * FUNCTION: AcpiCmCopyIelementToIelement 703 * 704 * PARAMETERS: ACPI_PKG_CALLBACK 705 * 706 * RETURN: Status - the status of the call 707 * 708 * DESCRIPTION: Copy one package element to another package element 709 * 710 ******************************************************************************/ 711 712ACPI_STATUS 713AcpiCmCopyIelementToIelement ( 714 UINT8 ObjectType, 715 ACPI_OPERAND_OBJECT *SourceObject, 716 ACPI_GENERIC_STATE *State, 717 void *Context) 718{ 719 ACPI_STATUS Status = AE_OK; 720 UINT32 ThisIndex; 721 ACPI_OPERAND_OBJECT **ThisTargetPtr; 722 ACPI_OPERAND_OBJECT *TargetObject; 723 724 725 726 ThisIndex = State->Pkg.Index; 727 ThisTargetPtr = (ACPI_OPERAND_OBJECT **) 728 &State->Pkg.DestObject->Package.Elements[ThisIndex]; 729 730 switch (ObjectType) 731 { 732 case 0: 733 734 /* 735 * This is a simple object, just copy it 736 */ 737 TargetObject = AcpiCmCreateInternalObject (SourceObject->Common.Type); 738 if (!TargetObject) 739 { 740 return (AE_NO_MEMORY); 741 } 742 743 Status = AcpiAmlStoreObjectToObject (SourceObject, TargetObject, 744 (ACPI_WALK_STATE *) Context); 745 if (ACPI_FAILURE (Status)) 746 { 747 return (Status); 748 } 749 750 *ThisTargetPtr = TargetObject; 751 break; 752 753 754 case 1: 755 /* 756 * This object is a package - go down another nesting level 757 * Create and build the package object 758 */ 759 TargetObject = AcpiCmCreateInternalObject (ACPI_TYPE_PACKAGE); 760 if (!TargetObject) 761 { 762 /* TBD: must delete package created up to this point */ 763 764 return (AE_NO_MEMORY); 765 } 766 767 TargetObject->Package.Count = SourceObject->Package.Count; 768 769 /* 770 * Pass the new package object back to the package walk routine 771 */ 772 State->Pkg.ThisTargetObj = TargetObject; 773 774 /* 775 * Store the object pointer in the parent package object 776 */ 777 *ThisTargetPtr = TargetObject; 778 break; 779 780 default: 781 return (AE_BAD_PARAMETER); 782 } 783 784 785 return (Status); 786} 787 788 789/******************************************************************************* 790 * 791 * FUNCTION: AcpiCmCopyIpackageToIpackage 792 * 793 * PARAMETERS: *SourceObj - Pointer to the source package object 794 * *DestObj - Where the internal object is returned 795 * 796 * RETURN: Status - the status of the call 797 * 798 * DESCRIPTION: This function is called to copy an internal package object 799 * into another internal package object. 800 * 801 ******************************************************************************/ 802 803ACPI_STATUS 804AcpiCmCopyIpackageToIpackage ( 805 ACPI_OPERAND_OBJECT *SourceObj, 806 ACPI_OPERAND_OBJECT *DestObj, 807 ACPI_WALK_STATE *WalkState) 808{ 809 ACPI_STATUS Status = AE_OK; 810 811 FUNCTION_TRACE ("CmCopyIpackageToIpackage"); 812 813 814 815 DestObj->Common.Type = SourceObj->Common.Type; 816 DestObj->Package.Count = SourceObj->Package.Count; 817 818 819 /* 820 * Create the object array and walk the source package tree 821 */ 822 823 DestObj->Package.Elements = AcpiCmCallocate ((SourceObj->Package.Count + 1) * 824 sizeof (void *)); 825 DestObj->Package.NextElement = DestObj->Package.Elements; 826 827 if (!DestObj->Package.Elements) 828 { 829 REPORT_ERROR ( 830 ("AmlBuildCopyInternalPackageObject: Package allocation failure\n")); 831 return_ACPI_STATUS (AE_NO_MEMORY); 832 } 833 834 835 Status = AcpiCmWalkPackageTree (SourceObj, DestObj, 836 AcpiCmCopyIelementToIelement, WalkState); 837 838 return_ACPI_STATUS (Status); 839} 840 841