1 /****************************************************************************** 2 * 3 * Module Name: utobject - ACPI object create/delete/size/cache routines 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/include/acpi.h> 153 #include <contrib/dev/acpica/include/accommon.h> 154 #include <contrib/dev/acpica/include/acnamesp.h> 155 156 157 #define _COMPONENT ACPI_UTILITIES 158 ACPI_MODULE_NAME ("utobject") 159 160 /* Local prototypes */ 161 162 static ACPI_STATUS 163 AcpiUtGetSimpleObjectSize ( 164 ACPI_OPERAND_OBJECT *Obj, 165 ACPI_SIZE *ObjLength); 166 167 static ACPI_STATUS 168 AcpiUtGetPackageObjectSize ( 169 ACPI_OPERAND_OBJECT *Obj, 170 ACPI_SIZE *ObjLength); 171 172 static ACPI_STATUS 173 AcpiUtGetElementLength ( 174 UINT8 ObjectType, 175 ACPI_OPERAND_OBJECT *SourceObject, 176 ACPI_GENERIC_STATE *State, 177 void *Context); 178 179 180 /******************************************************************************* 181 * 182 * FUNCTION: AcpiUtCreateInternalObjectDbg 183 * 184 * PARAMETERS: ModuleName - Source file name of caller 185 * LineNumber - Line number of caller 186 * ComponentId - Component type of caller 187 * Type - ACPI Type of the new object 188 * 189 * RETURN: A new internal object, null on failure 190 * 191 * DESCRIPTION: Create and initialize a new internal object. 192 * 193 * NOTE: We always allocate the worst-case object descriptor because 194 * these objects are cached, and we want them to be 195 * one-size-satisifies-any-request. This in itself may not be 196 * the most memory efficient, but the efficiency of the object 197 * cache should more than make up for this! 198 * 199 ******************************************************************************/ 200 201 ACPI_OPERAND_OBJECT * 202 AcpiUtCreateInternalObjectDbg ( 203 const char *ModuleName, 204 UINT32 LineNumber, 205 UINT32 ComponentId, 206 ACPI_OBJECT_TYPE Type) 207 { 208 ACPI_OPERAND_OBJECT *Object; 209 ACPI_OPERAND_OBJECT *SecondObject; 210 211 212 ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg, 213 AcpiUtGetTypeName (Type)); 214 215 216 /* Allocate the raw object descriptor */ 217 218 Object = AcpiUtAllocateObjectDescDbg ( 219 ModuleName, LineNumber, ComponentId); 220 if (!Object) 221 { 222 return_PTR (NULL); 223 } 224 225 switch (Type) 226 { 227 case ACPI_TYPE_REGION: 228 case ACPI_TYPE_BUFFER_FIELD: 229 case ACPI_TYPE_LOCAL_BANK_FIELD: 230 231 /* These types require a secondary object */ 232 233 SecondObject = AcpiUtAllocateObjectDescDbg ( 234 ModuleName, LineNumber, ComponentId); 235 if (!SecondObject) 236 { 237 AcpiUtDeleteObjectDesc (Object); 238 return_PTR (NULL); 239 } 240 241 SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA; 242 SecondObject->Common.ReferenceCount = 1; 243 244 /* Link the second object to the first */ 245 246 Object->Common.NextObject = SecondObject; 247 break; 248 249 default: 250 251 /* All others have no secondary object */ 252 break; 253 } 254 255 /* Save the object type in the object descriptor */ 256 257 Object->Common.Type = (UINT8) Type; 258 259 /* Init the reference count */ 260 261 Object->Common.ReferenceCount = 1; 262 263 /* Any per-type initialization should go here */ 264 265 return_PTR (Object); 266 } 267 268 269 /******************************************************************************* 270 * 271 * FUNCTION: AcpiUtCreatePackageObject 272 * 273 * PARAMETERS: Count - Number of package elements 274 * 275 * RETURN: Pointer to a new Package object, null on failure 276 * 277 * DESCRIPTION: Create a fully initialized package object 278 * 279 ******************************************************************************/ 280 281 ACPI_OPERAND_OBJECT * 282 AcpiUtCreatePackageObject ( 283 UINT32 Count) 284 { 285 ACPI_OPERAND_OBJECT *PackageDesc; 286 ACPI_OPERAND_OBJECT **PackageElements; 287 288 289 ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count); 290 291 292 /* Create a new Package object */ 293 294 PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE); 295 if (!PackageDesc) 296 { 297 return_PTR (NULL); 298 } 299 300 /* 301 * Create the element array. Count+1 allows the array to be null 302 * terminated. 303 */ 304 PackageElements = ACPI_ALLOCATE_ZEROED ( 305 ((ACPI_SIZE) Count + 1) * sizeof (void *)); 306 if (!PackageElements) 307 { 308 ACPI_FREE (PackageDesc); 309 return_PTR (NULL); 310 } 311 312 PackageDesc->Package.Count = Count; 313 PackageDesc->Package.Elements = PackageElements; 314 return_PTR (PackageDesc); 315 } 316 317 318 /******************************************************************************* 319 * 320 * FUNCTION: AcpiUtCreateIntegerObject 321 * 322 * PARAMETERS: InitialValue - Initial value for the integer 323 * 324 * RETURN: Pointer to a new Integer object, null on failure 325 * 326 * DESCRIPTION: Create an initialized integer object 327 * 328 ******************************************************************************/ 329 330 ACPI_OPERAND_OBJECT * 331 AcpiUtCreateIntegerObject ( 332 UINT64 InitialValue) 333 { 334 ACPI_OPERAND_OBJECT *IntegerDesc; 335 336 337 ACPI_FUNCTION_TRACE (UtCreateIntegerObject); 338 339 340 /* Create and initialize a new integer object */ 341 342 IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER); 343 if (!IntegerDesc) 344 { 345 return_PTR (NULL); 346 } 347 348 IntegerDesc->Integer.Value = InitialValue; 349 return_PTR (IntegerDesc); 350 } 351 352 353 /******************************************************************************* 354 * 355 * FUNCTION: AcpiUtCreateBufferObject 356 * 357 * PARAMETERS: BufferSize - Size of buffer to be created 358 * 359 * RETURN: Pointer to a new Buffer object, null on failure 360 * 361 * DESCRIPTION: Create a fully initialized buffer object 362 * 363 ******************************************************************************/ 364 365 ACPI_OPERAND_OBJECT * 366 AcpiUtCreateBufferObject ( 367 ACPI_SIZE BufferSize) 368 { 369 ACPI_OPERAND_OBJECT *BufferDesc; 370 UINT8 *Buffer = NULL; 371 372 373 ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize); 374 375 376 /* Create a new Buffer object */ 377 378 BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER); 379 if (!BufferDesc) 380 { 381 return_PTR (NULL); 382 } 383 384 /* Create an actual buffer only if size > 0 */ 385 386 if (BufferSize > 0) 387 { 388 /* Allocate the actual buffer */ 389 390 Buffer = ACPI_ALLOCATE_ZEROED (BufferSize); 391 if (!Buffer) 392 { 393 ACPI_ERROR ((AE_INFO, "Could not allocate size %u", 394 (UINT32) BufferSize)); 395 396 AcpiUtRemoveReference (BufferDesc); 397 return_PTR (NULL); 398 } 399 } 400 401 /* Complete buffer object initialization */ 402 403 BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID; 404 BufferDesc->Buffer.Pointer = Buffer; 405 BufferDesc->Buffer.Length = (UINT32) BufferSize; 406 407 /* Return the new buffer descriptor */ 408 409 return_PTR (BufferDesc); 410 } 411 412 413 /******************************************************************************* 414 * 415 * FUNCTION: AcpiUtCreateStringObject 416 * 417 * PARAMETERS: StringSize - Size of string to be created. Does not 418 * include NULL terminator, this is added 419 * automatically. 420 * 421 * RETURN: Pointer to a new String object 422 * 423 * DESCRIPTION: Create a fully initialized string object 424 * 425 ******************************************************************************/ 426 427 ACPI_OPERAND_OBJECT * 428 AcpiUtCreateStringObject ( 429 ACPI_SIZE StringSize) 430 { 431 ACPI_OPERAND_OBJECT *StringDesc; 432 char *String; 433 434 435 ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize); 436 437 438 /* Create a new String object */ 439 440 StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING); 441 if (!StringDesc) 442 { 443 return_PTR (NULL); 444 } 445 446 /* 447 * Allocate the actual string buffer -- (Size + 1) for NULL terminator. 448 * NOTE: Zero-length strings are NULL terminated 449 */ 450 String = ACPI_ALLOCATE_ZEROED (StringSize + 1); 451 if (!String) 452 { 453 ACPI_ERROR ((AE_INFO, "Could not allocate size %u", 454 (UINT32) StringSize)); 455 456 AcpiUtRemoveReference (StringDesc); 457 return_PTR (NULL); 458 } 459 460 /* Complete string object initialization */ 461 462 StringDesc->String.Pointer = String; 463 StringDesc->String.Length = (UINT32) StringSize; 464 465 /* Return the new string descriptor */ 466 467 return_PTR (StringDesc); 468 } 469 470 471 /******************************************************************************* 472 * 473 * FUNCTION: AcpiUtValidInternalObject 474 * 475 * PARAMETERS: Object - Object to be validated 476 * 477 * RETURN: TRUE if object is valid, FALSE otherwise 478 * 479 * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT 480 * 481 ******************************************************************************/ 482 483 BOOLEAN 484 AcpiUtValidInternalObject ( 485 void *Object) 486 { 487 488 ACPI_FUNCTION_NAME (UtValidInternalObject); 489 490 491 /* Check for a null pointer */ 492 493 if (!Object) 494 { 495 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n")); 496 return (FALSE); 497 } 498 499 /* Check the descriptor type field */ 500 501 switch (ACPI_GET_DESCRIPTOR_TYPE (Object)) 502 { 503 case ACPI_DESC_TYPE_OPERAND: 504 505 /* The object appears to be a valid ACPI_OPERAND_OBJECT */ 506 507 return (TRUE); 508 509 default: 510 511 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 512 "%p is not an ACPI operand obj [%s]\n", 513 Object, AcpiUtGetDescriptorName (Object))); 514 break; 515 } 516 517 return (FALSE); 518 } 519 520 521 /******************************************************************************* 522 * 523 * FUNCTION: AcpiUtAllocateObjectDescDbg 524 * 525 * PARAMETERS: ModuleName - Caller's module name (for error output) 526 * LineNumber - Caller's line number (for error output) 527 * ComponentId - Caller's component ID (for error output) 528 * 529 * RETURN: Pointer to newly allocated object descriptor. Null on error 530 * 531 * DESCRIPTION: Allocate a new object descriptor. Gracefully handle 532 * error conditions. 533 * 534 ******************************************************************************/ 535 536 void * 537 AcpiUtAllocateObjectDescDbg ( 538 const char *ModuleName, 539 UINT32 LineNumber, 540 UINT32 ComponentId) 541 { 542 ACPI_OPERAND_OBJECT *Object; 543 544 545 ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg); 546 547 548 Object = AcpiOsAcquireObject (AcpiGbl_OperandCache); 549 if (!Object) 550 { 551 ACPI_ERROR ((ModuleName, LineNumber, 552 "Could not allocate an object descriptor")); 553 554 return_PTR (NULL); 555 } 556 557 /* Mark the descriptor type */ 558 559 ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND); 560 561 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", 562 Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT))); 563 564 return_PTR (Object); 565 } 566 567 568 /******************************************************************************* 569 * 570 * FUNCTION: AcpiUtDeleteObjectDesc 571 * 572 * PARAMETERS: Object - An Acpi internal object to be deleted 573 * 574 * RETURN: None. 575 * 576 * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache 577 * 578 ******************************************************************************/ 579 580 void 581 AcpiUtDeleteObjectDesc ( 582 ACPI_OPERAND_OBJECT *Object) 583 { 584 ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object); 585 586 587 /* Object must be of type ACPI_OPERAND_OBJECT */ 588 589 if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND) 590 { 591 ACPI_ERROR ((AE_INFO, 592 "%p is not an ACPI Operand object [%s]", Object, 593 AcpiUtGetDescriptorName (Object))); 594 return_VOID; 595 } 596 597 (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object); 598 return_VOID; 599 } 600 601 602 /******************************************************************************* 603 * 604 * FUNCTION: AcpiUtGetSimpleObjectSize 605 * 606 * PARAMETERS: InternalObject - An ACPI operand object 607 * ObjLength - Where the length is returned 608 * 609 * RETURN: Status 610 * 611 * DESCRIPTION: This function is called to determine the space required to 612 * contain a simple object for return to an external user. 613 * 614 * The length includes the object structure plus any additional 615 * needed space. 616 * 617 ******************************************************************************/ 618 619 static ACPI_STATUS 620 AcpiUtGetSimpleObjectSize ( 621 ACPI_OPERAND_OBJECT *InternalObject, 622 ACPI_SIZE *ObjLength) 623 { 624 ACPI_SIZE Length; 625 ACPI_SIZE Size; 626 ACPI_STATUS Status = AE_OK; 627 628 629 ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject); 630 631 632 /* Start with the length of the (external) Acpi object */ 633 634 Length = sizeof (ACPI_OBJECT); 635 636 /* A NULL object is allowed, can be a legal uninitialized package element */ 637 638 if (!InternalObject) 639 { 640 /* 641 * Object is NULL, just return the length of ACPI_OBJECT 642 * (A NULL ACPI_OBJECT is an object of all zeroes.) 643 */ 644 *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length); 645 return_ACPI_STATUS (AE_OK); 646 } 647 648 /* A Namespace Node should never appear here */ 649 650 if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED) 651 { 652 /* A namespace node should never get here */ 653 654 ACPI_ERROR ((AE_INFO, 655 "Received a namespace node [%4.4s] " 656 "where an operand object is required", 657 ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, InternalObject)->Name.Ascii)); 658 return_ACPI_STATUS (AE_AML_INTERNAL); 659 } 660 661 /* 662 * The final length depends on the object type 663 * Strings and Buffers are packed right up against the parent object and 664 * must be accessed bytewise or there may be alignment problems on 665 * certain processors 666 */ 667 switch (InternalObject->Common.Type) 668 { 669 case ACPI_TYPE_STRING: 670 671 Length += (ACPI_SIZE) InternalObject->String.Length + 1; 672 break; 673 674 case ACPI_TYPE_BUFFER: 675 676 Length += (ACPI_SIZE) InternalObject->Buffer.Length; 677 break; 678 679 case ACPI_TYPE_INTEGER: 680 case ACPI_TYPE_PROCESSOR: 681 case ACPI_TYPE_POWER: 682 683 /* No extra data for these types */ 684 685 break; 686 687 case ACPI_TYPE_LOCAL_REFERENCE: 688 689 switch (InternalObject->Reference.Class) 690 { 691 case ACPI_REFCLASS_NAME: 692 /* 693 * Get the actual length of the full pathname to this object. 694 * The reference will be converted to the pathname to the object 695 */ 696 Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node); 697 if (!Size) 698 { 699 return_ACPI_STATUS (AE_BAD_PARAMETER); 700 } 701 702 Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size); 703 break; 704 705 default: 706 /* 707 * No other reference opcodes are supported. 708 * Notably, Locals and Args are not supported, but this may be 709 * required eventually. 710 */ 711 ACPI_ERROR ((AE_INFO, "Cannot convert to external object - " 712 "unsupported Reference Class [%s] 0x%X in object %p", 713 AcpiUtGetReferenceName (InternalObject), 714 InternalObject->Reference.Class, InternalObject)); 715 Status = AE_TYPE; 716 break; 717 } 718 break; 719 720 default: 721 722 ACPI_ERROR ((AE_INFO, "Cannot convert to external object - " 723 "unsupported type [%s] 0x%X in object %p", 724 AcpiUtGetObjectTypeName (InternalObject), 725 InternalObject->Common.Type, InternalObject)); 726 Status = AE_TYPE; 727 break; 728 } 729 730 /* 731 * Account for the space required by the object rounded up to the next 732 * multiple of the machine word size. This keeps each object aligned 733 * on a machine word boundary. (preventing alignment faults on some 734 * machines.) 735 */ 736 *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length); 737 return_ACPI_STATUS (Status); 738 } 739 740 741 /******************************************************************************* 742 * 743 * FUNCTION: AcpiUtGetElementLength 744 * 745 * PARAMETERS: ACPI_PKG_CALLBACK 746 * 747 * RETURN: Status 748 * 749 * DESCRIPTION: Get the length of one package element. 750 * 751 ******************************************************************************/ 752 753 static ACPI_STATUS 754 AcpiUtGetElementLength ( 755 UINT8 ObjectType, 756 ACPI_OPERAND_OBJECT *SourceObject, 757 ACPI_GENERIC_STATE *State, 758 void *Context) 759 { 760 ACPI_STATUS Status = AE_OK; 761 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context; 762 ACPI_SIZE ObjectSpace; 763 764 765 switch (ObjectType) 766 { 767 case ACPI_COPY_TYPE_SIMPLE: 768 /* 769 * Simple object - just get the size (Null object/entry is handled 770 * here also) and sum it into the running package length 771 */ 772 Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace); 773 if (ACPI_FAILURE (Status)) 774 { 775 return (Status); 776 } 777 778 Info->Length += ObjectSpace; 779 break; 780 781 case ACPI_COPY_TYPE_PACKAGE: 782 783 /* Package object - nothing much to do here, let the walk handle it */ 784 785 Info->NumPackages++; 786 State->Pkg.ThisTargetObj = NULL; 787 break; 788 789 default: 790 791 /* No other types allowed */ 792 793 return (AE_BAD_PARAMETER); 794 } 795 796 return (Status); 797 } 798 799 800 /******************************************************************************* 801 * 802 * FUNCTION: AcpiUtGetPackageObjectSize 803 * 804 * PARAMETERS: InternalObject - An ACPI internal object 805 * ObjLength - Where the length is returned 806 * 807 * RETURN: Status 808 * 809 * DESCRIPTION: This function is called to determine the space required to 810 * contain a package object for return to an external user. 811 * 812 * This is moderately complex since a package contains other 813 * objects including packages. 814 * 815 ******************************************************************************/ 816 817 static ACPI_STATUS 818 AcpiUtGetPackageObjectSize ( 819 ACPI_OPERAND_OBJECT *InternalObject, 820 ACPI_SIZE *ObjLength) 821 { 822 ACPI_STATUS Status; 823 ACPI_PKG_INFO Info; 824 825 826 ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject); 827 828 829 Info.Length = 0; 830 Info.ObjectSpace = 0; 831 Info.NumPackages = 1; 832 833 Status = AcpiUtWalkPackageTree ( 834 InternalObject, NULL, AcpiUtGetElementLength, &Info); 835 if (ACPI_FAILURE (Status)) 836 { 837 return_ACPI_STATUS (Status); 838 } 839 840 /* 841 * We have handled all of the objects in all levels of the package. 842 * just add the length of the package objects themselves. 843 * Round up to the next machine word. 844 */ 845 Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD ( 846 sizeof (ACPI_OBJECT)) * (ACPI_SIZE) Info.NumPackages; 847 848 /* Return the total package length */ 849 850 *ObjLength = Info.Length; 851 return_ACPI_STATUS (Status); 852 } 853 854 855 /******************************************************************************* 856 * 857 * FUNCTION: AcpiUtGetObjectSize 858 * 859 * PARAMETERS: InternalObject - An ACPI internal object 860 * ObjLength - Where the length will be returned 861 * 862 * RETURN: Status 863 * 864 * DESCRIPTION: This function is called to determine the space required to 865 * contain an object for return to an API user. 866 * 867 ******************************************************************************/ 868 869 ACPI_STATUS 870 AcpiUtGetObjectSize ( 871 ACPI_OPERAND_OBJECT *InternalObject, 872 ACPI_SIZE *ObjLength) 873 { 874 ACPI_STATUS Status; 875 876 877 ACPI_FUNCTION_ENTRY (); 878 879 880 if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == 881 ACPI_DESC_TYPE_OPERAND) && 882 (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)) 883 { 884 Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength); 885 } 886 else 887 { 888 Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength); 889 } 890 891 return (Status); 892 } 893