OSDN Git Service

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