Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / source / components / utilities / utobject.c
blob65ff9d1ba655a10edbea9864ae4d3602ba2f5df9
1 /******************************************************************************
3 * Module Name: utobject - ACPI object create/delete/size/cache routines
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
14 * 2. License
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.
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
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;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
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.
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.
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.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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.
80 * 4. Disclaimer and Export Compliance
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.
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.
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
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.
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.
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.
150 *****************************************************************************/
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acnamesp.h"
157 #define _COMPONENT ACPI_UTILITIES
158 ACPI_MODULE_NAME ("utobject")
160 /* Local prototypes */
162 static ACPI_STATUS
163 AcpiUtGetSimpleObjectSize (
164 ACPI_OPERAND_OBJECT *Obj,
165 ACPI_SIZE *ObjLength);
167 static ACPI_STATUS
168 AcpiUtGetPackageObjectSize (
169 ACPI_OPERAND_OBJECT *Obj,
170 ACPI_SIZE *ObjLength);
172 static ACPI_STATUS
173 AcpiUtGetElementLength (
174 UINT8 ObjectType,
175 ACPI_OPERAND_OBJECT *SourceObject,
176 ACPI_GENERIC_STATE *State,
177 void *Context);
180 /*******************************************************************************
182 * FUNCTION: AcpiUtCreateInternalObjectDbg
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
189 * RETURN: A new internal object, null on failure
191 * DESCRIPTION: Create and initialize a new internal object.
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!
199 ******************************************************************************/
201 ACPI_OPERAND_OBJECT *
202 AcpiUtCreateInternalObjectDbg (
203 const char *ModuleName,
204 UINT32 LineNumber,
205 UINT32 ComponentId,
206 ACPI_OBJECT_TYPE Type)
208 ACPI_OPERAND_OBJECT *Object;
209 ACPI_OPERAND_OBJECT *SecondObject;
212 ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
213 AcpiUtGetTypeName (Type));
216 /* Allocate the raw object descriptor */
218 Object = AcpiUtAllocateObjectDescDbg (
219 ModuleName, LineNumber, ComponentId);
220 if (!Object)
222 return_PTR (NULL);
225 switch (Type)
227 case ACPI_TYPE_REGION:
228 case ACPI_TYPE_BUFFER_FIELD:
229 case ACPI_TYPE_LOCAL_BANK_FIELD:
231 /* These types require a secondary object */
233 SecondObject = AcpiUtAllocateObjectDescDbg (
234 ModuleName, LineNumber, ComponentId);
235 if (!SecondObject)
237 AcpiUtDeleteObjectDesc (Object);
238 return_PTR (NULL);
241 SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
242 SecondObject->Common.ReferenceCount = 1;
244 /* Link the second object to the first */
246 Object->Common.NextObject = SecondObject;
247 break;
249 default:
251 /* All others have no secondary object */
252 break;
255 /* Save the object type in the object descriptor */
257 Object->Common.Type = (UINT8) Type;
259 /* Init the reference count */
261 Object->Common.ReferenceCount = 1;
263 /* Any per-type initialization should go here */
265 return_PTR (Object);
269 /*******************************************************************************
271 * FUNCTION: AcpiUtCreatePackageObject
273 * PARAMETERS: Count - Number of package elements
275 * RETURN: Pointer to a new Package object, null on failure
277 * DESCRIPTION: Create a fully initialized package object
279 ******************************************************************************/
281 ACPI_OPERAND_OBJECT *
282 AcpiUtCreatePackageObject (
283 UINT32 Count)
285 ACPI_OPERAND_OBJECT *PackageDesc;
286 ACPI_OPERAND_OBJECT **PackageElements;
289 ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
292 /* Create a new Package object */
294 PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
295 if (!PackageDesc)
297 return_PTR (NULL);
301 * Create the element array. Count+1 allows the array to be null
302 * terminated.
304 PackageElements = ACPI_ALLOCATE_ZEROED (
305 ((ACPI_SIZE) Count + 1) * sizeof (void *));
306 if (!PackageElements)
308 ACPI_FREE (PackageDesc);
309 return_PTR (NULL);
312 PackageDesc->Package.Count = Count;
313 PackageDesc->Package.Elements = PackageElements;
314 return_PTR (PackageDesc);
318 /*******************************************************************************
320 * FUNCTION: AcpiUtCreateIntegerObject
322 * PARAMETERS: InitialValue - Initial value for the integer
324 * RETURN: Pointer to a new Integer object, null on failure
326 * DESCRIPTION: Create an initialized integer object
328 ******************************************************************************/
330 ACPI_OPERAND_OBJECT *
331 AcpiUtCreateIntegerObject (
332 UINT64 InitialValue)
334 ACPI_OPERAND_OBJECT *IntegerDesc;
337 ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
340 /* Create and initialize a new integer object */
342 IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
343 if (!IntegerDesc)
345 return_PTR (NULL);
348 IntegerDesc->Integer.Value = InitialValue;
349 return_PTR (IntegerDesc);
353 /*******************************************************************************
355 * FUNCTION: AcpiUtCreateBufferObject
357 * PARAMETERS: BufferSize - Size of buffer to be created
359 * RETURN: Pointer to a new Buffer object, null on failure
361 * DESCRIPTION: Create a fully initialized buffer object
363 ******************************************************************************/
365 ACPI_OPERAND_OBJECT *
366 AcpiUtCreateBufferObject (
367 ACPI_SIZE BufferSize)
369 ACPI_OPERAND_OBJECT *BufferDesc;
370 UINT8 *Buffer = NULL;
373 ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
376 /* Create a new Buffer object */
378 BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
379 if (!BufferDesc)
381 return_PTR (NULL);
384 /* Create an actual buffer only if size > 0 */
386 if (BufferSize > 0)
388 /* Allocate the actual buffer */
390 Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
391 if (!Buffer)
393 ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
394 (UINT32) BufferSize));
396 AcpiUtRemoveReference (BufferDesc);
397 return_PTR (NULL);
401 /* Complete buffer object initialization */
403 BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
404 BufferDesc->Buffer.Pointer = Buffer;
405 BufferDesc->Buffer.Length = (UINT32) BufferSize;
407 /* Return the new buffer descriptor */
409 return_PTR (BufferDesc);
413 /*******************************************************************************
415 * FUNCTION: AcpiUtCreateStringObject
417 * PARAMETERS: StringSize - Size of string to be created. Does not
418 * include NULL terminator, this is added
419 * automatically.
421 * RETURN: Pointer to a new String object
423 * DESCRIPTION: Create a fully initialized string object
425 ******************************************************************************/
427 ACPI_OPERAND_OBJECT *
428 AcpiUtCreateStringObject (
429 ACPI_SIZE StringSize)
431 ACPI_OPERAND_OBJECT *StringDesc;
432 char *String;
435 ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
438 /* Create a new String object */
440 StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
441 if (!StringDesc)
443 return_PTR (NULL);
447 * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
448 * NOTE: Zero-length strings are NULL terminated
450 String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
451 if (!String)
453 ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
454 (UINT32) StringSize));
456 AcpiUtRemoveReference (StringDesc);
457 return_PTR (NULL);
460 /* Complete string object initialization */
462 StringDesc->String.Pointer = String;
463 StringDesc->String.Length = (UINT32) StringSize;
465 /* Return the new string descriptor */
467 return_PTR (StringDesc);
471 /*******************************************************************************
473 * FUNCTION: AcpiUtValidInternalObject
475 * PARAMETERS: Object - Object to be validated
477 * RETURN: TRUE if object is valid, FALSE otherwise
479 * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT
481 ******************************************************************************/
483 BOOLEAN
484 AcpiUtValidInternalObject (
485 void *Object)
488 ACPI_FUNCTION_NAME (UtValidInternalObject);
491 /* Check for a null pointer */
493 if (!Object)
495 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
496 return (FALSE);
499 /* Check the descriptor type field */
501 switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
503 case ACPI_DESC_TYPE_OPERAND:
505 /* The object appears to be a valid ACPI_OPERAND_OBJECT */
507 return (TRUE);
509 default:
511 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
512 "%p is not an ACPI operand obj [%s]\n",
513 Object, AcpiUtGetDescriptorName (Object)));
514 break;
517 return (FALSE);
521 /*******************************************************************************
523 * FUNCTION: AcpiUtAllocateObjectDescDbg
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)
529 * RETURN: Pointer to newly allocated object descriptor. Null on error
531 * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
532 * error conditions.
534 ******************************************************************************/
536 void *
537 AcpiUtAllocateObjectDescDbg (
538 const char *ModuleName,
539 UINT32 LineNumber,
540 UINT32 ComponentId)
542 ACPI_OPERAND_OBJECT *Object;
545 ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
548 Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
549 if (!Object)
551 ACPI_ERROR ((ModuleName, LineNumber,
552 "Could not allocate an object descriptor"));
554 return_PTR (NULL);
557 /* Mark the descriptor type */
559 ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
561 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
562 Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
564 return_PTR (Object);
568 /*******************************************************************************
570 * FUNCTION: AcpiUtDeleteObjectDesc
572 * PARAMETERS: Object - An Acpi internal object to be deleted
574 * RETURN: None.
576 * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
578 ******************************************************************************/
580 void
581 AcpiUtDeleteObjectDesc (
582 ACPI_OPERAND_OBJECT *Object)
584 ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
587 /* Object must be of type ACPI_OPERAND_OBJECT */
589 if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
591 ACPI_ERROR ((AE_INFO,
592 "%p is not an ACPI Operand object [%s]", Object,
593 AcpiUtGetDescriptorName (Object)));
594 return_VOID;
597 (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
598 return_VOID;
602 /*******************************************************************************
604 * FUNCTION: AcpiUtGetSimpleObjectSize
606 * PARAMETERS: InternalObject - An ACPI operand object
607 * ObjLength - Where the length is returned
609 * RETURN: Status
611 * DESCRIPTION: This function is called to determine the space required to
612 * contain a simple object for return to an external user.
614 * The length includes the object structure plus any additional
615 * needed space.
617 ******************************************************************************/
619 static ACPI_STATUS
620 AcpiUtGetSimpleObjectSize (
621 ACPI_OPERAND_OBJECT *InternalObject,
622 ACPI_SIZE *ObjLength)
624 ACPI_SIZE Length;
625 ACPI_SIZE Size;
626 ACPI_STATUS Status = AE_OK;
629 ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
632 /* Start with the length of the (external) Acpi object */
634 Length = sizeof (ACPI_OBJECT);
636 /* A NULL object is allowed, can be a legal uninitialized package element */
638 if (!InternalObject)
641 * Object is NULL, just return the length of ACPI_OBJECT
642 * (A NULL ACPI_OBJECT is an object of all zeroes.)
644 *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
645 return_ACPI_STATUS (AE_OK);
648 /* A Namespace Node should never appear here */
650 if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
652 /* A namespace node should never get here */
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);
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
667 switch (InternalObject->Common.Type)
669 case ACPI_TYPE_STRING:
671 Length += (ACPI_SIZE) InternalObject->String.Length + 1;
672 break;
674 case ACPI_TYPE_BUFFER:
676 Length += (ACPI_SIZE) InternalObject->Buffer.Length;
677 break;
679 case ACPI_TYPE_INTEGER:
680 case ACPI_TYPE_PROCESSOR:
681 case ACPI_TYPE_POWER:
683 /* No extra data for these types */
685 break;
687 case ACPI_TYPE_LOCAL_REFERENCE:
689 switch (InternalObject->Reference.Class)
691 case ACPI_REFCLASS_NAME:
693 * Get the actual length of the full pathname to this object.
694 * The reference will be converted to the pathname to the object
696 Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
697 if (!Size)
699 return_ACPI_STATUS (AE_BAD_PARAMETER);
702 Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
703 break;
705 default:
707 * No other reference opcodes are supported.
708 * Notably, Locals and Args are not supported, but this may be
709 * required eventually.
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;
718 break;
720 default:
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;
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.)
736 *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
737 return_ACPI_STATUS (Status);
741 /*******************************************************************************
743 * FUNCTION: AcpiUtGetElementLength
745 * PARAMETERS: ACPI_PKG_CALLBACK
747 * RETURN: Status
749 * DESCRIPTION: Get the length of one package element.
751 ******************************************************************************/
753 static ACPI_STATUS
754 AcpiUtGetElementLength (
755 UINT8 ObjectType,
756 ACPI_OPERAND_OBJECT *SourceObject,
757 ACPI_GENERIC_STATE *State,
758 void *Context)
760 ACPI_STATUS Status = AE_OK;
761 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
762 ACPI_SIZE ObjectSpace;
765 switch (ObjectType)
767 case ACPI_COPY_TYPE_SIMPLE:
769 * Simple object - just get the size (Null object/entry is handled
770 * here also) and sum it into the running package length
772 Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
773 if (ACPI_FAILURE (Status))
775 return (Status);
778 Info->Length += ObjectSpace;
779 break;
781 case ACPI_COPY_TYPE_PACKAGE:
783 /* Package object - nothing much to do here, let the walk handle it */
785 Info->NumPackages++;
786 State->Pkg.ThisTargetObj = NULL;
787 break;
789 default:
791 /* No other types allowed */
793 return (AE_BAD_PARAMETER);
796 return (Status);
800 /*******************************************************************************
802 * FUNCTION: AcpiUtGetPackageObjectSize
804 * PARAMETERS: InternalObject - An ACPI internal object
805 * ObjLength - Where the length is returned
807 * RETURN: Status
809 * DESCRIPTION: This function is called to determine the space required to
810 * contain a package object for return to an external user.
812 * This is moderately complex since a package contains other
813 * objects including packages.
815 ******************************************************************************/
817 static ACPI_STATUS
818 AcpiUtGetPackageObjectSize (
819 ACPI_OPERAND_OBJECT *InternalObject,
820 ACPI_SIZE *ObjLength)
822 ACPI_STATUS Status;
823 ACPI_PKG_INFO Info;
826 ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
829 Info.Length = 0;
830 Info.ObjectSpace = 0;
831 Info.NumPackages = 1;
833 Status = AcpiUtWalkPackageTree (
834 InternalObject, NULL, AcpiUtGetElementLength, &Info);
835 if (ACPI_FAILURE (Status))
837 return_ACPI_STATUS (Status);
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.
845 Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (
846 sizeof (ACPI_OBJECT)) * (ACPI_SIZE) Info.NumPackages;
848 /* Return the total package length */
850 *ObjLength = Info.Length;
851 return_ACPI_STATUS (Status);
855 /*******************************************************************************
857 * FUNCTION: AcpiUtGetObjectSize
859 * PARAMETERS: InternalObject - An ACPI internal object
860 * ObjLength - Where the length will be returned
862 * RETURN: Status
864 * DESCRIPTION: This function is called to determine the space required to
865 * contain an object for return to an API user.
867 ******************************************************************************/
869 ACPI_STATUS
870 AcpiUtGetObjectSize (
871 ACPI_OPERAND_OBJECT *InternalObject,
872 ACPI_SIZE *ObjLength)
874 ACPI_STATUS Status;
877 ACPI_FUNCTION_ENTRY ();
880 if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) ==
881 ACPI_DESC_TYPE_OPERAND) &&
882 (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
884 Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
886 else
888 Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
891 return (Status);