utcopy.c revision 99146
1/****************************************************************************** 2 * 3 * Module Name: utcopy - Internal to external object translation utilities 4 * $Revision: 95 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2002, 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 ACPI_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 ACPI_SIZE *BufferSpaceUsed) 152{ 153 ACPI_BUFFER Buffer; 154 ACPI_STATUS Status = AE_OK; 155 156 157 ACPI_FUNCTION_TRACE ("UtCopyIsimpleToEsimple"); 158 159 160 *BufferSpaceUsed = 0; 161 162 /* 163 * Check for NULL object case (could be an uninitialized 164 * package element 165 */ 166 if (!InternalObject) 167 { 168 return_ACPI_STATUS (AE_OK); 169 } 170 171 /* Always clear the external object */ 172 173 ACPI_MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT)); 174 175 /* 176 * In general, the external object will be the same type as 177 * the internal object 178 */ 179 ExternalObject->Type = InternalObject->Common.Type; 180 181 /* However, only a limited number of external types are supported */ 182 183 switch (InternalObject->Common.Type) 184 { 185 case ACPI_TYPE_STRING: 186 187 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace; 188 ExternalObject->String.Length = InternalObject->String.Length; 189 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (InternalObject->String.Length + 1); 190 191 ACPI_MEMCPY ((void *) DataSpace, (void *) InternalObject->String.Pointer, 192 InternalObject->String.Length + 1); 193 break; 194 195 196 case ACPI_TYPE_BUFFER: 197 198 ExternalObject->Buffer.Pointer = DataSpace; 199 ExternalObject->Buffer.Length = InternalObject->Buffer.Length; 200 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (InternalObject->String.Length); 201 202 ACPI_MEMCPY ((void *) DataSpace, (void *) InternalObject->Buffer.Pointer, 203 InternalObject->Buffer.Length); 204 break; 205 206 207 case ACPI_TYPE_INTEGER: 208 209 ExternalObject->Integer.Value = InternalObject->Integer.Value; 210 break; 211 212 213 case INTERNAL_TYPE_REFERENCE: 214 215 /* 216 * This is an object reference. Attempt to dereference it. 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_REVISION_OP: 236 ExternalObject->Type = ACPI_TYPE_INTEGER; 237 ExternalObject->Integer.Value = ACPI_CA_SUPPORT_LEVEL; 238 break; 239 240 case AML_INT_NAMEPATH_OP: 241 /* 242 * This is a named reference, get the string. We already know that 243 * we have room for it, use max length 244 */ 245 ExternalObject->Type = ACPI_TYPE_STRING; 246 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace; 247 248 Buffer.Length = MAX_STRING_LENGTH; 249 Buffer.Pointer = DataSpace; 250 251 Status = AcpiNsHandleToPathname ((ACPI_HANDLE *) InternalObject->Reference.Node, 252 &Buffer); 253 254 /* Converted (external) string length is returned from above */ 255 256 ExternalObject->String.Length = Buffer.Length; 257 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (Buffer.Length); 258 break; 259 260 default: 261 /* 262 * Use the object type of "Any" to indicate a reference 263 * to object containing a handle to an ACPI named object. 264 */ 265 ExternalObject->Type = ACPI_TYPE_ANY; 266 ExternalObject->Reference.Handle = InternalObject->Reference.Node; 267 break; 268 } 269 break; 270 271 272 case ACPI_TYPE_PROCESSOR: 273 274 ExternalObject->Processor.ProcId = InternalObject->Processor.ProcId; 275 ExternalObject->Processor.PblkAddress = InternalObject->Processor.Address; 276 ExternalObject->Processor.PblkLength = InternalObject->Processor.Length; 277 break; 278 279 280 case ACPI_TYPE_POWER: 281 282 ExternalObject->PowerResource.SystemLevel = 283 InternalObject->PowerResource.SystemLevel; 284 285 ExternalObject->PowerResource.ResourceOrder = 286 InternalObject->PowerResource.ResourceOrder; 287 break; 288 289 290 default: 291 /* 292 * There is no corresponding external object type 293 */ 294 return_ACPI_STATUS (AE_SUPPORT); 295 } 296 297 return_ACPI_STATUS (Status); 298} 299 300 301/******************************************************************************* 302 * 303 * FUNCTION: AcpiUtCopyIelementToEelement 304 * 305 * PARAMETERS: ACPI_PKG_CALLBACK 306 * 307 * RETURN: Status 308 * 309 * DESCRIPTION: Copy one package element to another package element 310 * 311 ******************************************************************************/ 312 313ACPI_STATUS 314AcpiUtCopyIelementToEelement ( 315 UINT8 ObjectType, 316 ACPI_OPERAND_OBJECT *SourceObject, 317 ACPI_GENERIC_STATE *State, 318 void *Context) 319{ 320 ACPI_STATUS Status = AE_OK; 321 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context; 322 ACPI_SIZE ObjectSpace; 323 UINT32 ThisIndex; 324 ACPI_OBJECT *TargetObject; 325 326 327 ACPI_FUNCTION_ENTRY (); 328 329 330 ThisIndex = State->Pkg.Index; 331 TargetObject = (ACPI_OBJECT *) 332 &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex]; 333 334 switch (ObjectType) 335 { 336 case ACPI_COPY_TYPE_SIMPLE: 337 338 /* 339 * This is a simple or null object 340 */ 341 Status = AcpiUtCopyIsimpleToEsimple (SourceObject, 342 TargetObject, Info->FreeSpace, &ObjectSpace); 343 if (ACPI_FAILURE (Status)) 344 { 345 return (Status); 346 } 347 break; 348 349 350 case ACPI_COPY_TYPE_PACKAGE: 351 352 /* 353 * Build the package object 354 */ 355 TargetObject->Type = ACPI_TYPE_PACKAGE; 356 TargetObject->Package.Count = SourceObject->Package.Count; 357 TargetObject->Package.Elements = (ACPI_OBJECT *) Info->FreeSpace; 358 359 /* 360 * Pass the new package object back to the package walk routine 361 */ 362 State->Pkg.ThisTargetObj = TargetObject; 363 364 /* 365 * Save space for the array of objects (Package elements) 366 * update the buffer length counter 367 */ 368 ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD ( 369 TargetObject->Package.Count * sizeof (ACPI_OBJECT)); 370 break; 371 372 373 default: 374 return (AE_BAD_PARAMETER); 375 } 376 377 Info->FreeSpace += ObjectSpace; 378 Info->Length += ObjectSpace; 379 return (Status); 380} 381 382 383/******************************************************************************* 384 * 385 * FUNCTION: AcpiUtCopyIpackageToEpackage 386 * 387 * PARAMETERS: *InternalObject - Pointer to the object we are returning 388 * *Buffer - Where the object is returned 389 * *SpaceUsed - Where the object length is returned 390 * 391 * RETURN: Status 392 * 393 * DESCRIPTION: This function is called to place a package object in a user 394 * buffer. A package object by definition contains other objects. 395 * 396 * The buffer is assumed to have sufficient space for the object. 397 * The caller must have verified the buffer length needed using the 398 * AcpiUtGetObjectSize function before calling this function. 399 * 400 ******************************************************************************/ 401 402static ACPI_STATUS 403AcpiUtCopyIpackageToEpackage ( 404 ACPI_OPERAND_OBJECT *InternalObject, 405 UINT8 *Buffer, 406 ACPI_SIZE *SpaceUsed) 407{ 408 ACPI_OBJECT *ExternalObject; 409 ACPI_STATUS Status; 410 ACPI_PKG_INFO Info; 411 412 413 ACPI_FUNCTION_TRACE ("UtCopyIpackageToEpackage"); 414 415 416 /* 417 * First package at head of the buffer 418 */ 419 ExternalObject = (ACPI_OBJECT *) Buffer; 420 421 /* 422 * Free space begins right after the first package 423 */ 424 Info.Length = 0; 425 Info.ObjectSpace = 0; 426 Info.NumPackages = 1; 427 Info.FreeSpace = Buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 428 429 ExternalObject->Type = InternalObject->Common.Type; 430 ExternalObject->Package.Count = InternalObject->Package.Count; 431 ExternalObject->Package.Elements = (ACPI_OBJECT *) Info.FreeSpace; 432 433 /* 434 * Build an array of ACPI_OBJECTS in the buffer 435 * and move the free space past it 436 */ 437 Info.FreeSpace += ExternalObject->Package.Count * 438 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)); 439 440 Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject, 441 AcpiUtCopyIelementToEelement, &Info); 442 443 *SpaceUsed = Info.Length; 444 return_ACPI_STATUS (Status); 445} 446 447 448/******************************************************************************* 449 * 450 * FUNCTION: AcpiUtCopyIobjectToEobject 451 * 452 * PARAMETERS: *InternalObject - The internal object to be converted 453 * *BufferPtr - Where the object is returned 454 * 455 * RETURN: Status 456 * 457 * DESCRIPTION: This function is called to build an API object to be returned to 458 * the caller. 459 * 460 ******************************************************************************/ 461 462ACPI_STATUS 463AcpiUtCopyIobjectToEobject ( 464 ACPI_OPERAND_OBJECT *InternalObject, 465 ACPI_BUFFER *RetBuffer) 466{ 467 ACPI_STATUS Status; 468 469 470 ACPI_FUNCTION_TRACE ("UtCopyIobjectToEobject"); 471 472 473 if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE) 474 { 475 /* 476 * Package object: Copy all subobjects (including 477 * nested packages) 478 */ 479 Status = AcpiUtCopyIpackageToEpackage (InternalObject, 480 RetBuffer->Pointer, &RetBuffer->Length); 481 } 482 else 483 { 484 /* 485 * Build a simple object (no nested objects) 486 */ 487 Status = AcpiUtCopyIsimpleToEsimple (InternalObject, 488 (ACPI_OBJECT *) RetBuffer->Pointer, 489 ((UINT8 *) RetBuffer->Pointer + 490 ACPI_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 * FUNCTION: AcpiUtCopyEsimpleToIsimple 506 * 507 * PARAMETERS: *ExternalObject - The external object to be converted 508 * *InternalObject - Where the internal object is returned 509 * 510 * RETURN: Status 511 * 512 * DESCRIPTION: This function copies an external object to an internal one. 513 * NOTE: Pointers can be copied, we don't need to copy data. 514 * (The pointers have to be valid in our address space no matter 515 * what we do with them!) 516 * 517 ******************************************************************************/ 518 519ACPI_STATUS 520AcpiUtCopyEsimpleToIsimple ( 521 ACPI_OBJECT *ExternalObject, 522 ACPI_OPERAND_OBJECT **RetInternalObject) 523{ 524 ACPI_OPERAND_OBJECT *InternalObject; 525 526 527 ACPI_FUNCTION_TRACE ("UtCopyEsimpleToIsimple"); 528 529 530 /* 531 * Simple types supported are: String, Buffer, Integer 532 */ 533 switch (ExternalObject->Type) 534 { 535 case ACPI_TYPE_STRING: 536 case ACPI_TYPE_BUFFER: 537 case ACPI_TYPE_INTEGER: 538 539 InternalObject = AcpiUtCreateInternalObject ((UINT8) ExternalObject->Type); 540 if (!InternalObject) 541 { 542 return_ACPI_STATUS (AE_NO_MEMORY); 543 } 544 break; 545 546 default: 547 /* 548 * Whatever other type -- it is not supported 549 */ 550 return_ACPI_STATUS (AE_SUPPORT); 551 } 552 553 554 switch (ExternalObject->Type) 555 { 556 557 /* Must COPY string and buffer contents */ 558 559 case ACPI_TYPE_STRING: 560 561 InternalObject->String.Pointer = ACPI_MEM_CALLOCATE (ExternalObject->String.Length + 1); 562 if (!InternalObject->String.Pointer) 563 { 564 return_ACPI_STATUS (AE_NO_MEMORY); 565 } 566 567 ACPI_MEMCPY (InternalObject->String.Pointer, 568 ExternalObject->String.Pointer, 569 ExternalObject->String.Length); 570 571 InternalObject->String.Length = ExternalObject->String.Length; 572 break; 573 574 575 case ACPI_TYPE_BUFFER: 576 577 InternalObject->Buffer.Pointer = ACPI_MEM_CALLOCATE (ExternalObject->Buffer.Length); 578 if (!InternalObject->Buffer.Pointer) 579 { 580 return_ACPI_STATUS (AE_NO_MEMORY); 581 } 582 583 ACPI_MEMCPY (InternalObject->Buffer.Pointer, 584 ExternalObject->Buffer.Pointer, 585 ExternalObject->Buffer.Length); 586 587 InternalObject->Buffer.Length = ExternalObject->Buffer.Length; 588 break; 589 590 591 case ACPI_TYPE_INTEGER: 592 593 InternalObject->Integer.Value = ExternalObject->Integer.Value; 594 break; 595 } 596 597 *RetInternalObject = InternalObject; 598 return_ACPI_STATUS (AE_OK); 599} 600 601 602#ifdef ACPI_FUTURE_IMPLEMENTATION 603 604/* Code to convert packages that are parameters to control methods */ 605 606/******************************************************************************* 607 * 608 * FUNCTION: AcpiUtCopyEpackageToIpackage 609 * 610 * PARAMETERS: *InternalObject - Pointer to the object we are returning 611 * *Buffer - Where the object is returned 612 * *SpaceUsed - Where the length of the object is returned 613 * 614 * RETURN: Status - the status of the call 615 * 616 * DESCRIPTION: This function is called to place a package object in a user 617 * buffer. A package object by definition contains other objects. 618 * 619 * The buffer is assumed to have sufficient space for the object. 620 * The caller must have verified the buffer length needed using the 621 * AcpiUtGetObjectSize function before calling this function. 622 * 623 ******************************************************************************/ 624 625static ACPI_STATUS 626AcpiUtCopyEpackageToIpackage ( 627 ACPI_OPERAND_OBJECT *InternalObject, 628 UINT8 *Buffer, 629 UINT32 *SpaceUsed) 630{ 631 UINT8 *FreeSpace; 632 ACPI_OBJECT *ExternalObject; 633 UINT32 Length = 0; 634 UINT32 ThisIndex; 635 UINT32 ObjectSpace = 0; 636 ACPI_OPERAND_OBJECT *ThisInternalObj; 637 ACPI_OBJECT *ThisExternalObj; 638 639 640 ACPI_FUNCTION_TRACE ("UtCopyEpackageToIpackage"); 641 642 643 /* 644 * First package at head of the buffer 645 */ 646 ExternalObject = (ACPI_OBJECT *)Buffer; 647 648 /* 649 * Free space begins right after the first package 650 */ 651 FreeSpace = Buffer + sizeof(ACPI_OBJECT); 652 653 654 ExternalObject->Type = InternalObject->Common.Type; 655 ExternalObject->Package.Count = InternalObject->Package.Count; 656 ExternalObject->Package.Elements = (ACPI_OBJECT *)FreeSpace; 657 658 659 /* 660 * Build an array of ACPI_OBJECTS in the buffer 661 * and move the free space past it 662 */ 663 FreeSpace += ExternalObject->Package.Count * sizeof(ACPI_OBJECT); 664 665 666 /* Call WalkPackage */ 667 668} 669 670#endif /* Future implementation */ 671 672 673/******************************************************************************* 674 * 675 * FUNCTION: AcpiUtCopyEobjectToIobject 676 * 677 * PARAMETERS: *InternalObject - The external object to be converted 678 * *BufferPtr - Where the internal object is returned 679 * 680 * RETURN: Status - the status of the call 681 * 682 * DESCRIPTION: Converts an external object to an internal object. 683 * 684 ******************************************************************************/ 685 686ACPI_STATUS 687AcpiUtCopyEobjectToIobject ( 688 ACPI_OBJECT *ExternalObject, 689 ACPI_OPERAND_OBJECT **InternalObject) 690{ 691 ACPI_STATUS Status; 692 693 694 ACPI_FUNCTION_TRACE ("UtCopyEobjectToIobject"); 695 696 697 if (ExternalObject->Type == ACPI_TYPE_PACKAGE) 698 { 699 /* 700 * Packages as external input to control methods are not supported, 701 */ 702 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 703 "Packages as parameters not implemented!\n")); 704 705 return_ACPI_STATUS (AE_NOT_IMPLEMENTED); 706 } 707 708 else 709 { 710 /* 711 * Build a simple object (no nested objects) 712 */ 713 Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject); 714 } 715 716 return_ACPI_STATUS (Status); 717} 718 719 720/******************************************************************************* 721 * 722 * FUNCTION: AcpiUtCopySimpleObject 723 * 724 * PARAMETERS: SourceDesc - The internal object to be copied 725 * DestDesc - New target object 726 * 727 * RETURN: Status 728 * 729 * DESCRIPTION: Simple copy of one internal object to another. Reference count 730 * of the destination object is preserved. 731 * 732 ******************************************************************************/ 733 734ACPI_STATUS 735AcpiUtCopySimpleObject ( 736 ACPI_OPERAND_OBJECT *SourceDesc, 737 ACPI_OPERAND_OBJECT *DestDesc) 738{ 739 UINT16 ReferenceCount; 740 ACPI_OPERAND_OBJECT *NextObject; 741 742 743 /* Save fields from destination that we don't want to overwrite */ 744 745 ReferenceCount = DestDesc->Common.ReferenceCount; 746 NextObject = DestDesc->Common.NextObject; 747 748 /* Copy the entire source object over the destination object*/ 749 750 ACPI_MEMCPY ((char *) DestDesc, (char *) SourceDesc, sizeof (ACPI_OPERAND_OBJECT)); 751 752 /* Restore the saved fields */ 753 754 DestDesc->Common.ReferenceCount = ReferenceCount; 755 DestDesc->Common.NextObject = NextObject; 756 757 /* Handle the objects with extra data */ 758 759 switch (DestDesc->Common.Type) 760 { 761 case ACPI_TYPE_BUFFER: 762 763 DestDesc->Buffer.Node = NULL; 764 DestDesc->Common.Flags = SourceDesc->Common.Flags; 765 766 /* Fall through to common string/buffer case */ 767 768 case ACPI_TYPE_STRING: 769 770 /* 771 * Allocate and copy the actual string if and only if: 772 * 1) There is a valid string (length > 0) 773 * 2) The string is not static (not in an ACPI table) (in this case, 774 * the actual pointer was already copied above) 775 */ 776 if ((SourceDesc->String.Length) && 777 (!(SourceDesc->Common.Flags & AOPOBJ_STATIC_POINTER))) 778 { 779 DestDesc->String.Pointer = ACPI_MEM_ALLOCATE (SourceDesc->String.Length); 780 if (!DestDesc->String.Pointer) 781 { 782 return (AE_NO_MEMORY); 783 } 784 785 ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer, 786 SourceDesc->String.Length); 787 } 788 break; 789 } 790 791 return (AE_OK); 792} 793 794 795/******************************************************************************* 796 * 797 * FUNCTION: AcpiUtCopyIelementToIelement 798 * 799 * PARAMETERS: ACPI_PKG_CALLBACK 800 * 801 * RETURN: Status 802 * 803 * DESCRIPTION: Copy one package element to another package element 804 * 805 ******************************************************************************/ 806 807ACPI_STATUS 808AcpiUtCopyIelementToIelement ( 809 UINT8 ObjectType, 810 ACPI_OPERAND_OBJECT *SourceObject, 811 ACPI_GENERIC_STATE *State, 812 void *Context) 813{ 814 ACPI_STATUS Status = AE_OK; 815 UINT32 ThisIndex; 816 ACPI_OPERAND_OBJECT **ThisTargetPtr; 817 ACPI_OPERAND_OBJECT *TargetObject; 818 819 820 ACPI_FUNCTION_ENTRY (); 821 822 823 ThisIndex = State->Pkg.Index; 824 ThisTargetPtr = (ACPI_OPERAND_OBJECT **) 825 &State->Pkg.DestObject->Package.Elements[ThisIndex]; 826 827 switch (ObjectType) 828 { 829 case 0: 830 831 /* 832 * This is a simple object, just copy it 833 */ 834 TargetObject = AcpiUtCreateInternalObject (SourceObject->Common.Type); 835 if (!TargetObject) 836 { 837 return (AE_NO_MEMORY); 838 } 839 840 Status = AcpiUtCopySimpleObject (SourceObject, TargetObject); 841 if (ACPI_FAILURE (Status)) 842 { 843 return (Status); 844 } 845 846 *ThisTargetPtr = TargetObject; 847 break; 848 849 850 case 1: 851 852 /* 853 * This object is a package - go down another nesting level 854 * Create and build the package object 855 */ 856 TargetObject = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE); 857 if (!TargetObject) 858 { 859 return (AE_NO_MEMORY); 860 } 861 862 TargetObject->Package.Count = SourceObject->Package.Count; 863 TargetObject->Common.Flags = SourceObject->Common.Flags; 864 865 /* 866 * Pass the new package object back to the package walk routine 867 */ 868 State->Pkg.ThisTargetObj = TargetObject; 869 870 /* 871 * Store the object pointer in the parent package object 872 */ 873 *ThisTargetPtr = TargetObject; 874 break; 875 876 877 default: 878 return (AE_BAD_PARAMETER); 879 } 880 881 return (Status); 882} 883 884 885/******************************************************************************* 886 * 887 * FUNCTION: AcpiUtCopyIpackageToIpackage 888 * 889 * PARAMETERS: *SourceObj - Pointer to the source package object 890 * *DestObj - Where the internal object is returned 891 * 892 * RETURN: Status - the status of the call 893 * 894 * DESCRIPTION: This function is called to copy an internal package object 895 * into another internal package object. 896 * 897 ******************************************************************************/ 898 899ACPI_STATUS 900AcpiUtCopyIpackageToIpackage ( 901 ACPI_OPERAND_OBJECT *SourceObj, 902 ACPI_OPERAND_OBJECT *DestObj, 903 ACPI_WALK_STATE *WalkState) 904{ 905 ACPI_STATUS Status = AE_OK; 906 907 908 ACPI_FUNCTION_TRACE ("UtCopyIpackageToIpackage"); 909 910 911 DestObj->Common.Type = SourceObj->Common.Type; 912 DestObj->Common.Flags = SourceObj->Common.Flags; 913 DestObj->Package.Count = SourceObj->Package.Count; 914 915 916 /* 917 * Create the object array and walk the source package tree 918 */ 919 DestObj->Package.Elements = ACPI_MEM_CALLOCATE ((SourceObj->Package.Count + 1) * 920 sizeof (void *)); 921 if (!DestObj->Package.Elements) 922 { 923 ACPI_REPORT_ERROR ( 924 ("AmlBuildCopyInternalPackageObject: Package allocation failure\n")); 925 return_ACPI_STATUS (AE_NO_MEMORY); 926 } 927 928 /* 929 * Copy the package element-by-element by walking the package "tree". 930 * This handles nested packages of arbitrary depth. 931 */ 932 Status = AcpiUtWalkPackageTree (SourceObj, DestObj, 933 AcpiUtCopyIelementToIelement, WalkState); 934 if (ACPI_FAILURE (Status)) 935 { 936 /* On failure, delete the destination package object */ 937 938 AcpiUtRemoveReference (DestObj); 939 } 940 941 return_ACPI_STATUS (Status); 942} 943 944 945/******************************************************************************* 946 * 947 * FUNCTION: AcpiUtCopyIobjectToIobject 948 * 949 * PARAMETERS: WalkState - Current walk state 950 * SourceDesc - The internal object to be copied 951 * DestDesc - Where the copied object is returned 952 * 953 * RETURN: Status 954 * 955 * DESCRIPTION: Copy an internal object to a new internal object 956 * 957 ******************************************************************************/ 958 959ACPI_STATUS 960AcpiUtCopyIobjectToIobject ( 961 ACPI_OPERAND_OBJECT *SourceDesc, 962 ACPI_OPERAND_OBJECT **DestDesc, 963 ACPI_WALK_STATE *WalkState) 964{ 965 ACPI_STATUS Status = AE_OK; 966 967 968 ACPI_FUNCTION_TRACE ("UtCopyIobjectToIobject"); 969 970 971 /* Create the top level object */ 972 973 *DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type); 974 if (!*DestDesc) 975 { 976 return_ACPI_STATUS (AE_NO_MEMORY); 977 } 978 979 /* Copy the object and possible subobjects */ 980 981 if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE) 982 { 983 Status = AcpiUtCopyIpackageToIpackage (SourceDesc, *DestDesc, 984 WalkState); 985 } 986 else 987 { 988 Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc); 989 } 990 991 return_ACPI_STATUS (Status); 992} 993 994 995