xref: /titanic_52/usr/src/uts/intel/io/acpica/utilities/utobject.c (revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4)
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 - 2009, 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 #define __UTOBJECT_C__
117 
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acnamesp.h"
121 
122 
123 #define _COMPONENT          ACPI_UTILITIES
124         ACPI_MODULE_NAME    ("utobject")
125 
126 /* Local prototypes */
127 
128 static ACPI_STATUS
129 AcpiUtGetSimpleObjectSize (
130     ACPI_OPERAND_OBJECT     *Obj,
131     ACPI_SIZE               *ObjLength);
132 
133 static ACPI_STATUS
134 AcpiUtGetPackageObjectSize (
135     ACPI_OPERAND_OBJECT     *Obj,
136     ACPI_SIZE               *ObjLength);
137 
138 static ACPI_STATUS
139 AcpiUtGetElementLength (
140     UINT8                   ObjectType,
141     ACPI_OPERAND_OBJECT     *SourceObject,
142     ACPI_GENERIC_STATE      *State,
143     void                    *Context);
144 
145 
146 /*******************************************************************************
147  *
148  * FUNCTION:    AcpiUtCreateInternalObjectDbg
149  *
150  * PARAMETERS:  ModuleName          - Source file name of caller
151  *              LineNumber          - Line number of caller
152  *              ComponentId         - Component type of caller
153  *              Type                - ACPI Type of the new object
154  *
155  * RETURN:      A new internal object, null on failure
156  *
157  * DESCRIPTION: Create and initialize a new internal object.
158  *
159  * NOTE:        We always allocate the worst-case object descriptor because
160  *              these objects are cached, and we want them to be
161  *              one-size-satisifies-any-request.  This in itself may not be
162  *              the most memory efficient, but the efficiency of the object
163  *              cache should more than make up for this!
164  *
165  ******************************************************************************/
166 
167 ACPI_OPERAND_OBJECT  *
168 AcpiUtCreateInternalObjectDbg (
169     const char              *ModuleName,
170     UINT32                  LineNumber,
171     UINT32                  ComponentId,
172     ACPI_OBJECT_TYPE        Type)
173 {
174     ACPI_OPERAND_OBJECT     *Object;
175     ACPI_OPERAND_OBJECT     *SecondObject;
176 
177 
178     ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
179         AcpiUtGetTypeName (Type));
180 
181 
182     /* Allocate the raw object descriptor */
183 
184     Object = AcpiUtAllocateObjectDescDbg (ModuleName, LineNumber, ComponentId);
185     if (!Object)
186     {
187         return_PTR (NULL);
188     }
189 
190     switch (Type)
191     {
192     case ACPI_TYPE_REGION:
193     case ACPI_TYPE_BUFFER_FIELD:
194     case ACPI_TYPE_LOCAL_BANK_FIELD:
195 
196         /* These types require a secondary object */
197 
198         SecondObject = AcpiUtAllocateObjectDescDbg (ModuleName,
199                             LineNumber, ComponentId);
200         if (!SecondObject)
201         {
202             AcpiUtDeleteObjectDesc (Object);
203             return_PTR (NULL);
204         }
205 
206         SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
207         SecondObject->Common.ReferenceCount = 1;
208 
209         /* Link the second object to the first */
210 
211         Object->Common.NextObject = SecondObject;
212         break;
213 
214     default:
215         /* All others have no secondary object */
216         break;
217     }
218 
219     /* Save the object type in the object descriptor */
220 
221     Object->Common.Type = (UINT8) Type;
222 
223     /* Init the reference count */
224 
225     Object->Common.ReferenceCount = 1;
226 
227     /* Any per-type initialization should go here */
228 
229     return_PTR (Object);
230 }
231 
232 
233 /*******************************************************************************
234  *
235  * FUNCTION:    AcpiUtCreatePackageObject
236  *
237  * PARAMETERS:  Count               - Number of package elements
238  *
239  * RETURN:      Pointer to a new Package object, null on failure
240  *
241  * DESCRIPTION: Create a fully initialized package object
242  *
243  ******************************************************************************/
244 
245 ACPI_OPERAND_OBJECT *
246 AcpiUtCreatePackageObject (
247     UINT32                  Count)
248 {
249     ACPI_OPERAND_OBJECT     *PackageDesc;
250     ACPI_OPERAND_OBJECT     **PackageElements;
251 
252 
253     ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
254 
255 
256     /* Create a new Package object */
257 
258     PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
259     if (!PackageDesc)
260     {
261         return_PTR (NULL);
262     }
263 
264     /*
265      * Create the element array. Count+1 allows the array to be null
266      * terminated.
267      */
268     PackageElements = ACPI_ALLOCATE_ZEROED (
269                         ((ACPI_SIZE) Count + 1) * sizeof (void *));
270     if (!PackageElements)
271     {
272         ACPI_FREE (PackageDesc);
273         return_PTR (NULL);
274     }
275 
276     PackageDesc->Package.Count = Count;
277     PackageDesc->Package.Elements = PackageElements;
278     return_PTR (PackageDesc);
279 }
280 
281 
282 /*******************************************************************************
283  *
284  * FUNCTION:    AcpiUtCreateBufferObject
285  *
286  * PARAMETERS:  BufferSize             - Size of buffer to be created
287  *
288  * RETURN:      Pointer to a new Buffer object, null on failure
289  *
290  * DESCRIPTION: Create a fully initialized buffer object
291  *
292  ******************************************************************************/
293 
294 ACPI_OPERAND_OBJECT *
295 AcpiUtCreateBufferObject (
296     ACPI_SIZE               BufferSize)
297 {
298     ACPI_OPERAND_OBJECT     *BufferDesc;
299     UINT8                   *Buffer = NULL;
300 
301 
302     ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
303 
304 
305     /* Create a new Buffer object */
306 
307     BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
308     if (!BufferDesc)
309     {
310         return_PTR (NULL);
311     }
312 
313     /* Create an actual buffer only if size > 0 */
314 
315     if (BufferSize > 0)
316     {
317         /* Allocate the actual buffer */
318 
319         Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
320         if (!Buffer)
321         {
322             ACPI_ERROR ((AE_INFO, "Could not allocate size %X",
323                 (UINT32) BufferSize));
324             AcpiUtRemoveReference (BufferDesc);
325             return_PTR (NULL);
326         }
327     }
328 
329     /* Complete buffer object initialization */
330 
331     BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
332     BufferDesc->Buffer.Pointer = Buffer;
333     BufferDesc->Buffer.Length = (UINT32) BufferSize;
334 
335     /* Return the new buffer descriptor */
336 
337     return_PTR (BufferDesc);
338 }
339 
340 
341 /*******************************************************************************
342  *
343  * FUNCTION:    AcpiUtCreateStringObject
344  *
345  * PARAMETERS:  StringSize          - Size of string to be created. Does not
346  *                                    include NULL terminator, this is added
347  *                                    automatically.
348  *
349  * RETURN:      Pointer to a new String object
350  *
351  * DESCRIPTION: Create a fully initialized string object
352  *
353  ******************************************************************************/
354 
355 ACPI_OPERAND_OBJECT *
356 AcpiUtCreateStringObject (
357     ACPI_SIZE               StringSize)
358 {
359     ACPI_OPERAND_OBJECT     *StringDesc;
360     char                    *String;
361 
362 
363     ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
364 
365 
366     /* Create a new String object */
367 
368     StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
369     if (!StringDesc)
370     {
371         return_PTR (NULL);
372     }
373 
374     /*
375      * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
376      * NOTE: Zero-length strings are NULL terminated
377      */
378     String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
379     if (!String)
380     {
381         ACPI_ERROR ((AE_INFO, "Could not allocate size %X",
382             (UINT32) StringSize));
383         AcpiUtRemoveReference (StringDesc);
384         return_PTR (NULL);
385     }
386 
387     /* Complete string object initialization */
388 
389     StringDesc->String.Pointer = String;
390     StringDesc->String.Length = (UINT32) StringSize;
391 
392     /* Return the new string descriptor */
393 
394     return_PTR (StringDesc);
395 }
396 
397 
398 /*******************************************************************************
399  *
400  * FUNCTION:    AcpiUtValidInternalObject
401  *
402  * PARAMETERS:  Object              - Object to be validated
403  *
404  * RETURN:      TRUE if object is valid, FALSE otherwise
405  *
406  * DESCRIPTION: Validate a pointer to be an ACPI_OPERAND_OBJECT
407  *
408  ******************************************************************************/
409 
410 BOOLEAN
411 AcpiUtValidInternalObject (
412     void                    *Object)
413 {
414 
415     ACPI_FUNCTION_NAME (UtValidInternalObject);
416 
417 
418     /* Check for a null pointer */
419 
420     if (!Object)
421     {
422         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
423         return (FALSE);
424     }
425 
426     /* Check the descriptor type field */
427 
428     switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
429     {
430     case ACPI_DESC_TYPE_OPERAND:
431 
432         /* The object appears to be a valid ACPI_OPERAND_OBJECT  */
433 
434         return (TRUE);
435 
436     default:
437         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
438                 "%p is not not an ACPI operand obj [%s]\n",
439                 Object, AcpiUtGetDescriptorName (Object)));
440         break;
441     }
442 
443     return (FALSE);
444 }
445 
446 
447 /*******************************************************************************
448  *
449  * FUNCTION:    AcpiUtAllocateObjectDescDbg
450  *
451  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
452  *              LineNumber          - Caller's line number (for error output)
453  *              ComponentId         - Caller's component ID (for error output)
454  *
455  * RETURN:      Pointer to newly allocated object descriptor.  Null on error
456  *
457  * DESCRIPTION: Allocate a new object descriptor.  Gracefully handle
458  *              error conditions.
459  *
460  ******************************************************************************/
461 
462 void *
463 AcpiUtAllocateObjectDescDbg (
464     const char              *ModuleName,
465     UINT32                  LineNumber,
466     UINT32                  ComponentId)
467 {
468     ACPI_OPERAND_OBJECT     *Object;
469 
470 
471     ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
472 
473 
474     Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
475     if (!Object)
476     {
477         ACPI_ERROR ((ModuleName, LineNumber,
478             "Could not allocate an object descriptor"));
479 
480         return_PTR (NULL);
481     }
482 
483     /* Mark the descriptor type */
484 
485     ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
486 
487     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
488             Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
489 
490     return_PTR (Object);
491 }
492 
493 
494 /*******************************************************************************
495  *
496  * FUNCTION:    AcpiUtDeleteObjectDesc
497  *
498  * PARAMETERS:  Object          - An Acpi internal object to be deleted
499  *
500  * RETURN:      None.
501  *
502  * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
503  *
504  ******************************************************************************/
505 
506 void
507 AcpiUtDeleteObjectDesc (
508     ACPI_OPERAND_OBJECT     *Object)
509 {
510     ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
511 
512 
513     /* Object must be an ACPI_OPERAND_OBJECT  */
514 
515     if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
516     {
517         ACPI_ERROR ((AE_INFO,
518             "%p is not an ACPI Operand object [%s]", Object,
519             AcpiUtGetDescriptorName (Object)));
520         return_VOID;
521     }
522 
523     (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
524     return_VOID;
525 }
526 
527 
528 /*******************************************************************************
529  *
530  * FUNCTION:    AcpiUtGetSimpleObjectSize
531  *
532  * PARAMETERS:  InternalObject     - An ACPI operand object
533  *              ObjLength          - Where the length is returned
534  *
535  * RETURN:      Status
536  *
537  * DESCRIPTION: This function is called to determine the space required to
538  *              contain a simple object for return to an external user.
539  *
540  *              The length includes the object structure plus any additional
541  *              needed space.
542  *
543  ******************************************************************************/
544 
545 static ACPI_STATUS
546 AcpiUtGetSimpleObjectSize (
547     ACPI_OPERAND_OBJECT     *InternalObject,
548     ACPI_SIZE               *ObjLength)
549 {
550     ACPI_SIZE               Length;
551     ACPI_SIZE               Size;
552     ACPI_STATUS             Status = AE_OK;
553 
554 
555     ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
556 
557 
558     /* Start with the length of the (external) Acpi object */
559 
560     Length = sizeof (ACPI_OBJECT);
561 
562     /* A NULL object is allowed, can be a legal uninitialized package element */
563 
564     if (!InternalObject)
565     {
566         /*
567          * Object is NULL, just return the length of ACPI_OBJECT
568          * (A NULL ACPI_OBJECT is an object of all zeroes.)
569          */
570         *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
571         return_ACPI_STATUS (AE_OK);
572     }
573 
574     /* A Namespace Node should never appear here */
575 
576     if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
577     {
578         /* A namespace node should never get here */
579 
580         return_ACPI_STATUS (AE_AML_INTERNAL);
581     }
582 
583     /*
584      * The final length depends on the object type
585      * Strings and Buffers are packed right up against the parent object and
586      * must be accessed bytewise or there may be alignment problems on
587      * certain processors
588      */
589     switch (InternalObject->Common.Type)
590     {
591     case ACPI_TYPE_STRING:
592 
593         Length += (ACPI_SIZE) InternalObject->String.Length + 1;
594         break;
595 
596 
597     case ACPI_TYPE_BUFFER:
598 
599         Length += (ACPI_SIZE) InternalObject->Buffer.Length;
600         break;
601 
602 
603     case ACPI_TYPE_INTEGER:
604     case ACPI_TYPE_PROCESSOR:
605     case ACPI_TYPE_POWER:
606 
607         /* No extra data for these types */
608 
609         break;
610 
611 
612     case ACPI_TYPE_LOCAL_REFERENCE:
613 
614         switch (InternalObject->Reference.Class)
615         {
616         case ACPI_REFCLASS_NAME:
617 
618             /*
619              * Get the actual length of the full pathname to this object.
620              * The reference will be converted to the pathname to the object
621              */
622             Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
623             if (!Size)
624             {
625                 return_ACPI_STATUS (AE_BAD_PARAMETER);
626             }
627 
628             Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
629             break;
630 
631         default:
632 
633             /*
634              * No other reference opcodes are supported.
635              * Notably, Locals and Args are not supported, but this may be
636              * required eventually.
637              */
638             ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
639                 "unsupported Reference Class [%s] %X in object %p",
640                 AcpiUtGetReferenceName (InternalObject),
641                 InternalObject->Reference.Class, InternalObject));
642             Status = AE_TYPE;
643             break;
644         }
645         break;
646 
647 
648     default:
649 
650         ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
651             "unsupported type [%s] %X in object %p",
652             AcpiUtGetObjectTypeName (InternalObject),
653             InternalObject->Common.Type, InternalObject));
654         Status = AE_TYPE;
655         break;
656     }
657 
658     /*
659      * Account for the space required by the object rounded up to the next
660      * multiple of the machine word size.  This keeps each object aligned
661      * on a machine word boundary. (preventing alignment faults on some
662      * machines.)
663      */
664     *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
665     return_ACPI_STATUS (Status);
666 }
667 
668 
669 /*******************************************************************************
670  *
671  * FUNCTION:    AcpiUtGetElementLength
672  *
673  * PARAMETERS:  ACPI_PKG_CALLBACK
674  *
675  * RETURN:      Status
676  *
677  * DESCRIPTION: Get the length of one package element.
678  *
679  ******************************************************************************/
680 
681 static ACPI_STATUS
682 AcpiUtGetElementLength (
683     UINT8                   ObjectType,
684     ACPI_OPERAND_OBJECT     *SourceObject,
685     ACPI_GENERIC_STATE      *State,
686     void                    *Context)
687 {
688     ACPI_STATUS             Status = AE_OK;
689     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
690     ACPI_SIZE               ObjectSpace;
691 
692 
693     switch (ObjectType)
694     {
695     case ACPI_COPY_TYPE_SIMPLE:
696 
697         /*
698          * Simple object - just get the size (Null object/entry is handled
699          * here also) and sum it into the running package length
700          */
701         Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
702         if (ACPI_FAILURE (Status))
703         {
704             return (Status);
705         }
706 
707         Info->Length += ObjectSpace;
708         break;
709 
710 
711     case ACPI_COPY_TYPE_PACKAGE:
712 
713         /* Package object - nothing much to do here, let the walk handle it */
714 
715         Info->NumPackages++;
716         State->Pkg.ThisTargetObj = NULL;
717         break;
718 
719 
720     default:
721 
722         /* No other types allowed */
723 
724         return (AE_BAD_PARAMETER);
725     }
726 
727     return (Status);
728 }
729 
730 
731 /*******************************************************************************
732  *
733  * FUNCTION:    AcpiUtGetPackageObjectSize
734  *
735  * PARAMETERS:  InternalObject      - An ACPI internal object
736  *              ObjLength           - Where the length is returned
737  *
738  * RETURN:      Status
739  *
740  * DESCRIPTION: This function is called to determine the space required to
741  *              contain a package object for return to an external user.
742  *
743  *              This is moderately complex since a package contains other
744  *              objects including packages.
745  *
746  ******************************************************************************/
747 
748 static ACPI_STATUS
749 AcpiUtGetPackageObjectSize (
750     ACPI_OPERAND_OBJECT     *InternalObject,
751     ACPI_SIZE               *ObjLength)
752 {
753     ACPI_STATUS             Status;
754     ACPI_PKG_INFO           Info;
755 
756 
757     ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
758 
759 
760     Info.Length      = 0;
761     Info.ObjectSpace = 0;
762     Info.NumPackages = 1;
763 
764     Status = AcpiUtWalkPackageTree (InternalObject, NULL,
765                             AcpiUtGetElementLength, &Info);
766     if (ACPI_FAILURE (Status))
767     {
768         return_ACPI_STATUS (Status);
769     }
770 
771     /*
772      * We have handled all of the objects in all levels of the package.
773      * just add the length of the package objects themselves.
774      * Round up to the next machine word.
775      */
776     Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)) *
777                     (ACPI_SIZE) Info.NumPackages;
778 
779     /* Return the total package length */
780 
781     *ObjLength = Info.Length;
782     return_ACPI_STATUS (Status);
783 }
784 
785 
786 /*******************************************************************************
787  *
788  * FUNCTION:    AcpiUtGetObjectSize
789  *
790  * PARAMETERS:  InternalObject      - An ACPI internal object
791  *              ObjLength           - Where the length will be returned
792  *
793  * RETURN:      Status
794  *
795  * DESCRIPTION: This function is called to determine the space required to
796  *              contain an object for return to an API user.
797  *
798  ******************************************************************************/
799 
800 ACPI_STATUS
801 AcpiUtGetObjectSize (
802     ACPI_OPERAND_OBJECT     *InternalObject,
803     ACPI_SIZE               *ObjLength)
804 {
805     ACPI_STATUS             Status;
806 
807 
808     ACPI_FUNCTION_ENTRY ();
809 
810 
811     if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_OPERAND) &&
812         (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
813     {
814         Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
815     }
816     else
817     {
818         Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
819     }
820 
821     return (Status);
822 }
823 
824 
825